Dif/2 call as implication premiss: is the implication's else part run? Should it be?

No. That is precisely my point, you never know whether a constraint succeeds with pending constraints that can either never be satisfied or that can already be resolved to a single solution. The only way to know is to label the result.

1 Like

This construct implements the so-called‘soft-cut’. T

That’s the wrong manual page, namely this one:

https://eu.swi-prolog.org/pldoc/doc_for?object=(*->)/2

instead of this

https://eu.swi-prolog.org/pldoc/doc_for?object=(->)/2

But I get it now! Simply

?- (writeln("It begins"); (writeln("Backtracked to before ->"),fail)),
|    (dif(X,Y) -> writeln("YES") ; writeln("NO")), 
|    X=1,
|    (writeln("Past X=1"); (writeln("Backtracked to before Y=1"),fail)),
|    (Y=1 ; (writeln("Y=1 failed"),fail)),  % because the constraint fails
|    writeln("END").

It begins
YES
Past X=1
Y=1 failed
Backtracked to before Y=1
Backtracked to before ->
false.

That’s actually pretty simple.

I agree with this. The remaining constraints applied to unbound variables in answers are part of the answer, i.e., the query is true iff the constraints are satisfied. So if the constraints are mutually inconsistent, i.e. unsatisfiable, and the constraint “engine” does not detect this, labelling is required to prove that no solution is possible. Similarly labelling is necessary to produce actual answers if that is a requirement of the program.

My only point is that applying a constraint via dif, a clp(fd) expression, …, does not change how the control predicates (cuts, if-then-else, or) work.

And perhaps the intent of your original example could be expressed by:

((dif(A,B), proceed_hoping_that_dif_will_turn_true(A,B,W)) ; try_again(A,B))

Thanks Jan.

Actually, the state diagram was very wrong because I misjudged how dif/2 works. Burned the afternoon to think this through again.

New diagram!

https://raw.githubusercontent.com/dtonhofer/prolog_notes/855e7a3954e2512d2efb9766c35f3f9f9f70062b/swipl_notes/about_dif/about_dif_states.svg

Still too complex. Better next time.

Agree with everything. The diagram copies the attempt at ensuring “dif(A,B)” as it tries to show what happens when you go “down the search tree”. I need to make it simpler then.