On Monday, June 13, 2016 at 6:52:28 PM UTC+2, Markus Triska wrote:
In the meantime, if you like, try and fix this:8 ?- between(1,inf,X).
X = 1 ;
X = 2 ;
X = 3 .
?- length([_|_], X).
X = 1 ;X = 2 ;X = 3 .
Hi Julio,
On Monday, June 13, 2016 at 8:38:14 PM UTC+2, Julio Di Egidio wrote:In the meantime, if you like, try and fix this:8 ?- between(1,inf,X).
X = 1 ;
X = 2 ;
X = 3 .OK. I strongly recommend you use instead:
?- length([_|_], X).X = 1 ;X = 2 ;X = 3 .It is much more portable!
*Plonk*
:- use_module(library(term/shuffel)).
is_tree(leaf).
is_tree(node(X,Y)) ;- >>-(is_tree(X), is_tree(Y)).?- is_tree(X).
X = leaf ;
X = node(leaf,leaf) ;
X = node(node(leaf,leaf),leaf) ;
X = node(leaf,node(leaf,leaf)) ;
X = node(node(node(leaf,leaf),leaf),leaf) ;
X = node(leaf,node(node(leaf,leaf),leaf)) ;
X = node(node(node(leaf,leaf),leaf),node(leaf,leaf)) ;
X = node(leaf,node(leaf,node(leaf,leaf)))
Erc..( A, B ) and
( B, A ) describe the same relation. The only differences - New developments such as CLP(FD).
- New developments such as tabling
- New developments such as module system (asked here recently)
- Maybe even object oriented extensions
- What else?
- Would be better elaborated concerning its claims.
- Would use established subclasses of Prolog programs.
- Would maybe also elaborate on CWA.
- What else?
Actually I have not yet found any open source java API that mangaes the module clp(fd).
For example I've tried to use open source solutions like jpl (http://www.swi-prolog.org/packages/jpl/java_api/) or prolog development tool PDT (https://sewiki.iai.uni-bonn.de/research/pdt/docs/start), but neither of them are able to handle in java the result of the clp(fd) module.
However it's quite good for me just handling the result of a constraint logic progrmming problem, I don't need a java implementation.
Therefore even though jacop-solver could be the best open source java solution to constraint programming, I think EclipSe is better for me, because it provides the java API (http://eclipseclp.org/doc/javadoc/JavaEclipseInterface/index.html) as well as interfaces with other languages.
The agenda definitely needs also the following topics:
One might chose a Prolog based CLP(FD) library because of big nums.
But I think using Prolog is also apealing because it so easy to define
predicates that make use of CLP(FD).
That most of these Java solvers dont support big nums is a shame.
On this agenda we find the following item:
Use clpfd for arithmetics. Don't use (is)/2, it makes your code much too moded.
For me, at the moment, its not clear whether this is a good advice. Especially
when is/2 is used inside heavy search. I know about a study that shows that
attribute variables used in freeze/2 are automatically reclaimed, when unreachable.
The study even only holds for SWI-Prolog in some simple cases, other systems have
more problems.
Whether this also holds for attribute variables occuring in CLP(FD) I don't know
at the moment. I am not aware of some studies on this topic. The problem is
easily shown in the tree test/generate example. We will have a predicate:
tree(X) :- var(X), !, freeze(X, tree(X)).
tree(...) :- rest of tree code
The freeze X is a cyclic structure, since the frozen goal contains X again. Very
difficult for example for Jekejeke Prolog to reclaim such stuff (*). Usually if a variable
is instantiated with a constant or another variable GC is much easier.
Bye
tree(X) :- var(X), !, freeze_closure(X, tree).
Typical test example:
sum([], 0).
sum([X|Y], S) :- sum(Y, T), S #= T+X.
How many constraints will this generate?
?- sum([1,2,3,4,A,B],S).
B+A#=_G472,
_G472+4#=_G484,
_G484+3#=_G496,
_G496+2#=_G508,
_G508+1#=S.
For example I get the following blow-up of constraints in this
trivial example:
Hi Jan,Typical test example:
sum([], 0).
sum([X|Y], S) :- sum(Y, T), S #= T+X.
How many constraints will this generate?
Very good question, and I applaud you for actually inquiring this. To my knowledge, it is the first time that such a question is asked on this mailing list.
The answer is: When CLP(FD) arithmetic constraints are used in modes that can also be handled by built-in arithmetic, zero pending constraints are generated. That is not a typo. No pending constraints at all are generated when (#=)/2 is used in modes that can also be handled by (is)/2 and (=:=)/2. You can look at the listing with ?- listing(sum/2), and see that only lower level predicates are used in such cases.
In a very real sense, the only thing that users have to change to pave at least a small path for more general programs while retaining everything they like about their existing code (including acceptable performance) is a textual replacement of (is)/2, (>)/2, ... by (#=)/2, (#>)/2 etc. All existing properties (except for the limited generality, which increases) are preserved, and you can discuss and teach all features like accumulators, tail calls etc. also and equally well with (#=)/2.
The fallacy I often see on this list is that users change more than that,
I did nothing else.
Code before:
sum([], 0).
sum([X|Y], S) :- sum(Y, T), S is T+X.
Code after:
sum([], 0).
sum([X|Y], S) :- sum(Y, T), S #= T+X.
The code is conservative for ground input lists. Works the
same as before. But I didn't do some time/space measurents,
might be slower.
On 06/16/2016 04:30 PM, Julio Di Egidio wrote:
> But, besides the caution expressed above, what is the point of changing
> that stuff at all? Indeed, what would be the "path to more general
> programs"?
Have a fish for the sin herring: ><((((*>
For everyone else: Markus already ansered that multiple times. Replace
integer reasoning by clpfd, since it has the same behaviour on the modes
supported by is. Already now, clpfd is more general than is, improving
it will introduce more generality.
?- model(X), labeling([X]).
X = 58 More? (;)
X = 118 More? (;)
X = 178 More? (;)
Simplified story IMO:
- You can replace classical Prolog arithmetic with clp(fd), provided
you only deal with integers and (most) integer arithmetic. The
semantics will remain the same. You'll loose some performance,
in particular when compared to using -O on tight arithmetic loops.
- You don't really gain anything, unless your multi-moded operation
is a clear win and you don't use any choice commitment (->, or !).
But currently (#=)/2 has a much smaller scope than (is)/2.
For example bitwise operations are not supported. I get the
following error:
?- X #= 12 \/ 14.
ERROR: Domain error: `clpfd_expression' expected, found `12\/14'
But you find tons of Prolog code that uses bitwise operations.
I see people on purpose for efficiency using 0 =:= N /\ 1 to check for
an even number or M is N>>1 to divide by two. (Old and new Prolog code)
Further a lot of (is)/2 operations are across float and integers. For
example min/2 can work on both integer and float. You also find tons
of Prolog code that needs this.
Further a lot of (is)/2 operations are across float and integers. For
example min/2 can work on both integer and float. You also find tons
of Prolog code that needs this.Overall, we will comparatively soon move away from floats altogether.
you include functions that have values in $R$, rationals only give you
an expensive false feeling of correctness. In other words, pi/0, sin/1,
etc. require floats.
Further a speciality of SWI-Prolog the (**)/2 operator returns
integer instead of float. But not supported by (#=)/2:
I am on purpose never writing "Hi Markus, please add this and that feature" here. Since
this is a discussion forum.
Interval consistency for bitwise operations is not extremely good. For example from
X #= Y /\ C you cannot bound Y, if X is bound. Not sure whether providing a CLP(FD)
wrapper is nothing more than rushing into writing such wrappers.
This only means that nothing more is derived in such cases. Next, we wait for user input. I mean not in the form of "CLP(FD) is teh suck", but in the form of "Could you please add propagation for the following situation: I have a CLP(FD) expression of the form ... etc.". Let's see if that happens. Next, I will add it, and you will have a more useful system.
You wouldn't need CLP(FD) for that. Thats only freeze/2 or when/2.
?- X #= (Y >> (Z mod D)) #<==> T, D = 0.
D = T, T = 0,
X in inf..sup,
Z in inf..sup,
Y in inf..sup.
/**
* C (finite):
* A callable C is also a value expression.
*/
sys_value_expr(C, L, A) :-
sys_callable(C), !,
call(C, X),
sys_value_expr(X, L, A).An important experiment could be whether its possible
to bootstrap CLP(FD) capable functions by such a mechanism.