domain(100..999).
digit(0..9).
% Variation w/ prime factors
prime(P) :- domain(P), { domain(F) : F < P, P \ F == 0 } 0.
prod(P1 * P2) :- prime(P1;P2).
% Palindrome
pd(X) :- prod(X), X = 100000*A + 10000*B + 1000*C + 100*C + 10*B + A,
digit(A;B;C).
pdMax(M) :- M = #max { X : pd(X) }.
#show pdMax/1.
Superficially it resembles Prolog, but brings "true" declarativity to the table, i.e., the order of rules and the order of atoms in the body is negligible. Various notions of safety and the prohibition of nested complex terms (e.g. `f(f(x))') guarantee termination. Most importantly though, solutions to an answer set program are not proofs (as in Prolog) but truth-assignments of atoms ("answer sets"). In this specific encoding there's no significant difference though, as we're only computing a single answer set containing an atom "pdMax(X)" with the maximum palindrome X.Solving answer set programs usually involves heuristics and much work along the lines of SAT solving. Recent solvers such as clasp [1] are surprising efficient though and rival state of the art SAT solvers.
However, Maude can go further than other rewrite languages since it is also a model checker: if A rewrites to B, we can supply A and get back B; or we can supply B and have Maude search for an A. If A and B are DSL terms, we can derive terms from their properties, as is being discussed here.
We can also have Maude show that some terms are unreachable, for example that there is no input which rewrites to an Error symbol.
Of course the advantage to Z3 is that it's hooked up to fast domain-specific solvers (SAT, SMT, arithmetic, etc.), whilst Maude's search is general-purpose and therefore slower.
Why did you need to change "(assert (and (>= a 1) (<= a 9)))" with "(assert (= a 9))"?
Turns out that the former doesn’t find the correct solution, instead it yields 137*803=110011.
Whatever the reason I think it’s worth mentioning in the article.The Lara team at EPFL seems to be doing lots of research in this area: http://lara.epfl.ch/w/Start
Believe it or not, a very good example of such a language which you might be familiar with is SQL.
SQL is declarative only when you don't care about data integrity and performance.
Maybe a bit better example for this kind of behavior are compilers. They're pretty "declarative" these days. You write what code you want to compile, and the compiler will pass it through a thousand transformation stages, deciding which trick to apply at every instruction, which code isn't really needed and so on.
Of course, then you also need to deal with compilers getting it wrong too, so you start tweaking your code with special words like "volatile" and "restricted", mess with compiler options, and sometimes even disassemble code to see why turning the "fast" options makes your code slow. But in general, high quality compilers do this dance way better than SQL.
So what's the moral here? Two things.
First, calling something "declarative" doesn't really mean anything. It means the language is built on a very thick abstraction that lets the computer do more work than usual, so you can do less work.
Second, thick abstractions are leaky. Works for basic cases, past that you'll still end up doing a lot of work, but now you have to fight your computer while doing it, as well.
The Z3 Theorem Prover is an interesting toy, but I wouldn't trust it to do anything right in the real world. Much like most Microsoft Research projects, unfortunately.
If you have never tried it out you should, maybe you will like declarative languages a little bit more afterwards.
Also I wasn't suggesting that declarative languages are broadly useful (in fact I'd suggest quite the opposite), just that they are very interesting.
Granted I've only used it in one university course (and only half of that course).
- I write the tests - I run the compiler which transforms the tests into implementation - Run the implementation
Is this even possible at all in meaningful time?
That said, I think the same was true for functional languages before the folks behind GHC came along. I'd be curious to see what could happen if some substantial resources (and a few heaps of modern optimisation knowledge) were poured into this sort of language.
You can only break it if your problem domain was never NP-hard in the first place (e.g. sparse or some other exploitable structural features). Very very fast means nothing on a true NP-hard problem for quite modest n.
Note the author had to include a spurious constraint to get his system to converge, despite it being quite a small task in the first place. My point was that this approach has fundamental reasons why it won't scale to real programming tasks, of which the interesting ones that programmers get wrong all the time are likely to be the true NP-complete type.
is this feasible?
From http://research.microsoft.com/en-us/um/redmond/projects/z3/z...
1 - http://en.wikipedia.org/wiki/Boolean_satisfiability_problem#...