# S(casp) help

**URL:** <https://swi-prolog.discourse.group/t/s-casp-help/6575>\
**Category:** Help!\
**Tags:** swish\
**Created:** [May 26, 2023, 10:45pm UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575 "2023-05-26T22:45:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![albangabillon](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/albangabillon/32/3689_2.png) [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Post date:** [May 26, 2023, 10:45pm UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/1 "2023-05-26T22:45:55Z")

</div>

Considering the following code

````prolog
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:

scasp(opera(D),[model(Model)])

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

````

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

---

<div class="post-metadata">

**Author:** ![girzel](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@girzel](https://swi-prolog.discourse.group/u/girzel)\
**Post date:** [May 27, 2023, 9:51pm UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/2 "2023-05-27T21:51:23Z")

</div>

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

```prolog
?- 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:

```prolog
MODEL:
{ opera(D | {D \= monday}), not home(D | {D \= monday}) }
BINDINGS:
D \= monday ? ;

```

Which seems even more reasonable.

Sorry if that’s not helpful!

---

<div class="post-metadata">

**Author:** ![albangabillon](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/albangabillon/32/3689_2.png) [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Post date:** [May 28, 2023, 1:37am UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/3 "2023-05-28T01:37:08Z")

</div>

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

```prolog
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

```

---

<div class="post-metadata">

**Author:** ![girzel](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@girzel](https://swi-prolog.discourse.group/u/girzel)\
**Post date:** [May 28, 2023, 6:00pm UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/4 "2023-05-28T18:00:03Z")

</div>

Unfortunately I’m not the one to help debug Windows issues! I’m guessing you’ve already installed as per [this page](https://github.com/SWI-Prolog/sCASP), 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.

---

<div class="post-metadata">

**Author:** ![albangabillon](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/albangabillon/32/3689_2.png) [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Post date:** [May 28, 2023, 7:46pm UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/5 "2023-05-28T19:46:29Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 30, 2023, 8:23am UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/6 "2023-05-30T08:23:34Z")

</div>

> [@albangabillon](#):
>
> \_16270 and \_15292

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

> [@girzel](#):
>
> Which seems even more reasonable.

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.

---

<div class="post-metadata">

**Author:** ![girzel](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@girzel](https://swi-prolog.discourse.group/u/girzel)\
**Post date:** [May 30, 2023, 3:44pm UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/7 "2023-05-30T15:44:56Z")

</div>

> [@jan](#):
>
> > [@girzel](#):
> >
> > Which seems even more reasonable.
> 
> 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”?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 31, 2023, 8:16am UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/8 "2023-05-31T08:16:02Z")

</div>

> [@girzel](#):
>
> Are my two outputs above just two different representations of the same result? Or are they actually derived differently?

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.

```prolog
?- [library(scasp)].
true.

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

?- A ∉ [2], A = 2.
false.

```

---

<div class="post-metadata">

**Author:** ![girzel](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@girzel](https://swi-prolog.discourse.group/u/girzel)\
**Post date:** [May 31, 2023, 3:33pm UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/9 "2023-05-31T15:33:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 31, 2023, 3:51pm UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/10 "2023-05-31T15:51:17Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![albangabillon](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/albangabillon/32/3689_2.png) [@albangabillon](https://swi-prolog.discourse.group/u/albangabillon)\
**Post date:** [June 1, 2023, 3:50am UTC](https://swi-prolog.discourse.group/t/s-casp-help/6575/11 "2023-06-01T03:50:37Z")

</div>

> Looks like an old version of [SWI-Prolog](https://www.swi-prolog.org/pldoc/doc_for?object=manual) 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](https://hub.docker.com/search?q=swipl%2Fswish)
