CHR output doesn't reflect propagation rule

View: New views
6 Messages — Rating Filter:   Alert me  

CHR output doesn't reflect propagation rule

by Jean-Marc Vanel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
With the leq example in paragraph "7.5 Examples" in the online help, I get this (with the latest sources from GIT) :

?- leq(A,B), leq(B,C).
leq(_G61928, _G61932)
leq(_G61929, _G61932)
leq(_G61928, _G61929)
put_attr(B, leq, [suspension(2238, active, t(t(4, suspension(2237, active, t, 0, leq:leq___2__0(A, B, **), leq, A, B), **), x, -, t, t), 0, leq:leq___2__0(B, C, **), leq, B, C), suspension(2237, active, t, 0, leq:leq___2__0(A, B, **), leq, A, B)]),
put_attr(C, leq, [suspension(2239, active, t, 0, leq:leq___2__0(A, C, **), leq, A, C), suspension(2238, active, t(t(4, suspension(2237, active, t, 0, leq:leq___2__0(A, B, **), leq, A, B), **), x, -, t, t), 0, leq:leq___2__0(B, C, **), leq, B, C)]),
put_attr(A, leq, [suspension(2239, active, t, 0, leq:leq___2__0(A, C, **), leq, A, C), suspension(2237, active, t, 0, leq:leq___2__0(A, B, **), leq, A, B)]) ;
fail.

From this answer nothing tells me that _G61928 is bound to A, etc, contray to what the online help prints as the answer.

On this Web interface http://chr.informatik.uni-ulm.de/~webchr/?load=solvers/leq.pl , one obtains the more satisfactory answer:

?- leq(A,B), leq(B,C) .
leq(A,C),
leq(B,C),
leq(A,B)
yes [0.006 seconds]

This Web CHR site apparently uses Sicstus Prolog 4.

So, is this a bug or a feature ?


Related this is this question: how can one get the content of the constraint store back into the Prolog stack or database ?

This doesn't work:
?- find_chr_constraint(Constraint).
fail.

I tried this too :
ANS = ( leq(A,B), leq(B,C) ).


--
Jean-Marc Vanel
http://jmvanel.free.fr/

Re: CHR output doesn't reflect propagation rule

by Jean-Marc Vanel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

1. Concerning the different behiavior of CHR compared to the documentation, I have a version 5.6.3X on Fedora, and it has the right behavior.

I also found this in the sources in pl/packages/chr/ChangeLog :

[Feb 27 2008]
 * ENHANCED: CHR performance of find_chr_constraint when called with nonvar argument

This change might be related.

2. Concerning the way to recover the content of the constraint store back into the Prolog, I tried several variants of find_chr_constraint, none of which work:

?- find_chr_constraint(Constraint ).
 fail.

?- ANS = ( leq(A,B), leq(B,C) ).

?- find_chr_constraint(leq).

?- find_chr_constraint( leq:leq).

?- find_chr_constraint( leq:leq(_,_) ).

--
Jean-Marc Vanel
http://jmvanel.free.fr/

Re: Re: CHR output doesn't reflect propagation rule

by Tom Schrijvers-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>
> 2. Concerning the way to recover the content of the constraint store back
> into the Prolog, I tried several variants of find_chr_constraint, none of
> which work:
>
> ?- find_chr_constraint(Constraint ).
> fail.
>
> ?- ANS = ( leq(A,B), leq(B,C) ).
>
> ?- find_chr_constraint(leq).
>
> ?- find_chr_constraint( leq:leq).
>
> ?- find_chr_constraint( leq:leq(_,_) ).
>
> --
> Jean-Marc Vanel
> http://jmvanel.free.fr/

As far as I can tell, it does work. In your above queries there are no
constraints to be found, so find_chr_constraint/1 fails.

Try this:

  ?- leq(X,Y), find_chr_constraint(C).
  leq(_G30038, _G30039)
  C = leq(X, Y),
  put_attr(Y, user, [suspension(53, active, _G30344, 0, user:leq___2__0(X, Y, **), leq, X, Y)]),
  put_attr(X, user, [suspension(53, active, _G30344, 0, user:leq___2__0(X, Y, **), leq, X, Y)]) .

Tom
--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: tom.schrijvers@...
url: http://www.cs.kuleuven.be/~toms/

------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

Re: Re: CHR output doesn't reflect propagation rule

by Jean-Marc Vanel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


2008/5/14 Tom Schrijvers <Tom.Schrijvers@...>:

As far as I can tell, it does work. In your above queries there are no constraints to be found, so find_chr_constraint/1 fails.
Try this:

       ?- leq(X,Y), find_chr_constraint(C).
       leq(_G30038, _G30039)
       C = leq(X, Y),
       put_attr(Y, user, [suspension(53, active, _G30344, 0, user:leq___2__0(X, Y, **), leq, X, Y)]),
       put_attr(X, user, [suspension(53, active, _G30344, 0, user:leq___2__0(X, Y, **), leq, X, Y)]) .

Tom

Shame on me, I didn't try this. I probably had the wrong idea that the constraint store is persistant.

Moreover, if one types this before, it removes the first line leq(_G30038, _G30039) :
set_prolog_flag( chr_toplevel_show_store, true ).

But how can I remove the 2 lines with put_attr(...) ?


Other insatisfactions:

1. If I try to make a printing loop this way, I loose the "real" variable names :

leq(X,Y), ( find_chr_constraint( CC), writeln( CC ), fail ; true ).
leq(_G14710, _G14711)
put_attr(Y, leq, [suspension(2289, active, t, 0, leq:leq___2__0(X, Y, **), leq, X, Y)]),
put_attr(X, leq, [suspension(2289, active, t, 0, leq:leq___2__0(X, Y, **), leq, X, Y)]) .

2. The same thing happens when I get the results as a list:

leq(A,B), setof( CC, find_chr_constraint( CC), List ).
List = [leq(_G15335, _G15336)],
put_attr(B, leq, [suspension(2291, active, t, 0, leq:leq___2__0(A, B, **), leq, A, B)]),
.......


--
Jean-Marc Vanel
http://jmvanel.free.fr/

Re: Re: CHR output doesn't reflect propagation rule

by Jean-Marc Vanel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I answer to my own question; see below.

2008/5/14 Jean-Marc Vanel <jeanmarc.vanel@...>:

2008/5/14 Tom Schrijvers <Tom.Schrijvers@...>:


As far as I can tell, it does work. In your above queries there are no constraints to be found, so find_chr_constraint/1 fails.
....

But how can I remove the 2 lines with put_attr(...) ?

Other insatisfactions:

1. If I try to make a printing loop this way, I loose the "real" variable names :

leq(X,Y), ( find_chr_constraint( CC), writeln( CC ), fail ; true ).
leq(_G14710, _G14711)
put_attr(Y, leq, [suspension(2289, active, t, 0, leq:leq___2__0(X, Y, **), leq, X, Y)]),
put_attr(X, leq, [suspension(2289, active, t, 0, leq:leq___2__0(X, Y, **), leq, X, Y)]) .

2. The same thing happens when I get the results as a list:

leq(A,B), setof( CC, find_chr_constraint( CC), List ).
List = [leq(_G15335, _G15336)],
put_attr(B, leq, [suspension(2291, active, t, 0, leq:leq___2__0(A, B, **), leq, A, B)]),
.......

In fact, all works perfectly with atoms instead of variables. By the way, using atoms instead of variables for specifying CHR problems makes more sense I think. But most of the CHR examples available use variables for rules AND for the query.

?- leq(a,b), leq(b,c), setof( CC, find_chr_constraint( CC), List ).
List = [leq(a, b), leq(a, c), leq(b, c)] ;
fail.

?- leq(a,b), leq(b,c), ( find_chr_constraint( CC), writeln( CC ), fail ; true ).
leq(a, c)
leq(b, c)
leq(a, b)
true          




--
Jean-Marc Vanel
http://jmvanel.free.fr/



--
Jean-Marc Vanel
http://jmvanel.free.fr/
06 89 16 29 52

Re: Re: CHR output doesn't reflect propagation rule

by Tom Schrijvers-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>> But how can I remove the 2 lines with put_attr(...) ?

I 've just pushed a patch for this.

> In fact, all works perfectly with atoms instead of variables. By the way,
> using atoms instead of variables for specifying CHR problems makes more
> sense I think. But most of the CHR examples available use variables for
> rules AND for the query.

Not using variables is certainly an established CHR practice. Sometimes
using variables is more convenient, sometimes it isn't.

Tom

--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: tom.schrijvers@...
url: http://www.cs.kuleuven.be/~toms/

------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...