S(casp) help

Considering the following code

opera(D) :- not home(D).              % A day D, Bob either goes to the opera...
home(D) :- not opera(D).              %                       ... or stays home.
home(monday).                         % On Monday, Bob stays at home.

false :- baby(D), opera(D).           % When Bob's best friend comes with her baby, it is
                                      % not a good idea to take the baby to the opera.  
baby(tuesday).                        % They come on Tuesday.```

and the answer to the following query:


Model = [
not baby(_16270),
not home(D),
not opera(tuesday)
D∉[monday, tuesday],

I do not understand why we have _16270 and _15292. Why don’t we have the same variable?

FWIW, when I run this in swipl (version 9.0.4, with the swipl fork of scasp) I get:

?- scasp(opera(D), [model(Model)])
|    .
Model = [not baby(_A), baby(tuesday), not home(D), home(tuesday), opera(D), not opera(tuesday)],
D ∉ [monday,tuesday],
_A ∉ [tuesday] ;

Where _A obviously matches. Running it in ciao prolog with that version of scasp I get:

{ opera(D | {D \= monday}),  not home(D | {D \= monday}) }
D \= monday ? ;

Which seems even more reasonable.

Sorry if that’s not helpful!

Thank you for your answer. It could help but unfortunately I failed to install scasp under swipl on my windows computer.

PS C:\Program Files\swipl\sCASP> swipl -g "pack_install(.)" -t halt
% Contacting server at https://www.swi-prolog.org/pack/query ... done
Warning: No registered pack matches "."
ERROR: -g pack_install(.): false

Unfortunately I’m not the one to help debug Windows issues! I’m guessing you’ve already installed as per this page, and were able to create scasp.exe? I guess I would attempt to follow the directions exactly, by starting swipl interactively, and running pack_install(.) at the prompt.

Again I don’t know anything about Windows installation, but the "." issue looks like it could easily be caused by some setup that happens when swipl is run interactively, but not the way you’ve done it above. That could also be a complete red herring.

I’m guessing you’ve already installed as per this page,

Yes I managed to do it after updating swipl which was simply outdated.

Thank you

Looks like an old version of SWI-Prolog that doesn’t yet give variables names before printing the answer.

You get the same if you use the scasp application. When embedding into Prolog you end up with a model in Prolog where variable may have constraints. These are represented and printed following the normal Prolog toplevel conventions.

Interesting, thanks. I’ve always been a bit confused about the interaction between these pieces of software. Are my two outputs above just two different representations of the same result? Or are they actually derived differently? The way _A ∉ [tuesday] and D \= monday complement each other makes me think one is using the “dual program”?

I think both are represented by the somewhat (too) simple s(CASP) inequality constraint. Embedded into Prolog the toplevel prints the constraint such that it can be executed as a goal. s(CASP) defines ∉/2. \=/2 is an existing Prolog builtin predicate, so we cannot use that.

Just noted that ∉/2 is not exported from library(scasp). Pushed a patch to export this. So, now we can do this, making it all consistent.

?- [library(scasp)].

?- A ∉ [2].
A ∉ [2].

?- A ∉ [2], A = 2.
1 Like

Cool, thanks! Now to figure out how to type that on my keyboard…

I normally use copy/paste :slight_smile: Depends on your environment whether there is something smarter. Alternatively, use a quoted atom:

?- '\u2209'(Var, [2]).
Var ∉ [2].
1 Like

Looks like an old version of SWI-Prolog that doesn’t yet give variables names before printing the answer.

I use the lastest docker image of swipl/swish (updated 6 months ago): swipl/swish