Using different foralls with s(CASP)

I have a piece of code that works properly in s(CASP) when using the prev_forall forall algorithm, and doesn’t work in the c_forall algorithm, which I think is the default.

If you’re interested in seeing the specific code, there is an example here. If you un-comment the last line (which should be irrelevant), the query ? legally_holds(A,B). no longer works.

As a workaround I could change the flag to use prev_forall for everything, but I’m worried that’s going to cause unpredictable problems, and I understand from @Xuaco that it will likely also not work if the code uses constraints. Is that so in the SWI-Prolog version, also?

I could just detect if the query I’m executing is with regard to the effected code, and if so change the options in the scasp call, but that would change the forall used for both the particular goal and all the sub-goals in the rest of the code.

I’m using s(CASP) as a library inside SWI-Prolog, and I know that the forall option exists for calling s(CASP), so I’m thinking there might be some way that I could use prev_forall for one portion of my code, and use the default algorithm for the rest. My current use-case is with regard to this bug, but I anticipate there might be other reasons I want to use particular algorithms with particular modules in future, too.

Is this something that I could accomplish by pre-compiling a file with the relevant code, and then integrating that with the rest of my s(CASP) source? Would it be possible to have a compiler directive that sets the forall algorithm by file, or by predicate?

Is there some other approach I could try?

Thanks very much.

There is no fundamental difference in the forall implementation, so I guess yes.

You can change the forall behavior using some Prolog flag (scasp_forall I’d guess). That is for the whole program though. You can change it between calls to scasp/2, but a single scasp query is solved with a specific implementation of the forall algorithm. I only understand roughly the issues around forall. You need @Xuaco for that :slight_smile:

No. The gathering of the sCASP program and compilation happens inside the scasp/2 call.

I don’t know. My first suggestion would be to understand why the code goes wrong with the default forall implementation and fix that (either by changing your program or, if there appears to be a bug in the forall implementation, in sCASP). Otherwise, I guess we’d need some way to specify for individual predicates what findall implementation should be used. That sounds dubious.

1 Like

Dear @Jan and @Gauntlet173,
Improving the forall is on the TODO list. I hope to have something soon.