Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

beginner question

52 views
Skip to first unread message

C. G.

unread,
Aug 21, 2024, 4:53:11 PM8/21/24
to Picat
Hello,

I have a hard time understanding why this works as I expect:
import cp.
main=> Z::1..10,
Y=[1,Z,3],
% the only difference is here
element(2,Y,8), solve([Z]), println([Y,Z]).

printing: [[1,8,3],8] ,

whereas this one leaves the Z inside Y uninstantiated although it finds the same correct assignment for it:

import cp.
main=> Z::1..10,
Y=[1,2,3], Y[2]:=Z, % the only difference is here
element(2,Y,8), solve([Z]), println([Y,Z]).

which prints:
[[1,_01490::[1 ..10],3],8] instead.

I am of course grateful for any hint.

best regards,
Cristian

Nartoo Meon

unread,
Aug 21, 2024, 7:27:31 PM8/21/24
to Picat
I'm not very good at picat, but I'll try to help. Hmmm...
If I not lie, the Guide says: index notations can't be used in constraints..
But wait, I see the answer!
element(2,Y,8) constraint is true, if second element of a list Y equals to 8. But Z can be equal to 8 or equal to every value in domain at the same time(like something non-deterministic),
then solve() find this value and stop.

Why print() writes Z inside Y in the way you wrote it in the code? Probably, this behavior depends on inner implementation.
Perhaps, you forced the system to add a constraint into a list... and then print() just wrote it!
But if you use Y=[1,Z,3] , it interprets as list of domain variables.
So, Y become a domain variable itself with list values in domain, like [1,1,3], [1,5,3]..  I don't know if that's right or not, but it nicely explains what's going on.
But that makes sense: Y only depends on Z. If Z instantiated, then Y too.. 


середа, 21 серпня 2024 р. о 23:53:11 UTC+3 C. G. пише:

Neng-Fa Zhou

unread,
Aug 26, 2024, 2:58:17 PM8/26/24
to Picat
Actually this reveals a bug in the Picat interpreter, which occurs when the right-hand side of := is a domain variable. This bug has been fixed in version 3.7.

Thank you for reporting,
NF

Nartoo Meon

unread,
Aug 26, 2024, 11:04:00 PM8/26/24
to Picat
WOW.. Do we need an update?

понеділок, 26 серпня 2024 р. о 21:58:17 UTC+3 Neng-Fa Zhou пише:

C. G.

unread,
Aug 27, 2024, 8:48:36 AM8/27/24
to Picat

Hello,

Many thanks, I can confirm it works in 3.7 for me as well.

I have tried and succeeded to compile picat for FreeBSD. There was very little to change for this to work. Are you interested in supporting this platform as well? If so, I could try again and document the few changes needed.

best regards,
Cristian
Reply all
Reply to author
Forward
0 new messages