scryer-prolog: dif/2 incorrect

?- A=[A],C=[D|E],B=[D],D=[C|F], dif_si(A,B).
   error(instantiation_error,dif_si/2).
?- A=[A],C=[D|E],B=[D],D=[C|F], dif(A,B).
   A = [A], C = [[C|F]|E], D = [[D|E]|F], B = [[C|F]], dif:dif([...],[[[...|_A]|F]]).
?- dif(A,B),A=[A],C=[D|E],B=[D],D=[C|F].
   A = [A], B = [[C|F]], C = [[C|F]|E], D = [[D|E]|F], unexpected.

(ediftcrvl-nth(5:4254341554)

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 18 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I think I’ve fixed the iterator used by term_variables/2. This should also address the other issues you recently opened @bakaq.

I haven’t pushed anything to master yet.

Is this a bug in term_variables/2?

I think so, yes.

The reason for this seems to be that dif/2 isn’t putting attributes in any variables (and especially not in E which is relevant in this case) here:

?- C=[D|E],D=[C],A=[A], dif_si(A,[D]).
   error(instantiation_error,dif_si/2).
?- C=[D|E],D=[C],A=[A], dif(A,[D]).
   % Needed a residual constraint, and in particular for E
   % to be attributed so that it can "watch" it's instantiation later
   C = [[C]|E], D = [[D|E]], A = [A].

Apparently the terms_variables/2 in dif/2 doesn’t find E, or any other variables in the case above:

?- C=[D|E],D=[C],A=[A], dif(A,[D]).
call:term_variables(dif([...],[[...]]),A).
exit:term_variables(dif([...],[[...]]),[]).
   C = [[C]|E], D = [[D|E]], A = [A].
?- C=[D|E], D=[C], A=[A], term_variables(A-[D], Vars).
   C = [[C]|E], D = [[D|E]], A = [A], Vars = [].

Is this a bug in term_variables/2?

This may also be the cause for #2057.

A is bound to a list so it’s not a variable, same for C and D. That leaves E as a variable.