Replies: 3 comments 2 replies
-
|
I deleted a comment because I have done a rookie mistake in the example which would never succeed and was only adding noise. I think I might have found the cause. This code: a(X) :-
member(A, X),
write(a(A)), nl,
sat(card([1], [A])),
write(a(A)), nl.
b(X) :-
member(A, X),
write(b(A)), nl,
sat(card([0], [A])),
write(b(A)), nl.
foo :-
X = [_],
write(X), nl,
a(X),
write(X), nl,
b(X),
write(X), nl.fails as expected: but this other code, succeeds: a(X) :-
forall(
member(A, X),
( write(a(A)), nl,
sat(card([1], [A])),
write(a(A)), nl
)
).
b(X) :-
forall(
member(A, X),
( write(b(A)), nl,
sat(card([0], [A])),
write(b(A)), nl
)
).
foo :-
X = [_],
write(X), nl,
a(X),
write(X), nl,
b(X),
write(X), nl.And it seems like it would be unifying I can concieve that |
Beta Was this translation helpful? Give feedback.
-
|
I think there are two separate questions: First, why does the character sequence representing the variable change? We have: 7.10.5 Writing a term When a term Term is output using write_term/3 (8.14.2) the action which is taken is defined by the rules below: a) If Term is a variable, a character sequence repre- senting that variable is output. The sequence begins with _ (underscore) and the remaining characters are implementation dependent. The same character sequence is used for each occurrence of a particular variable in Term. A different character sequence is used for each distinct variable in Term. So, it is perfectly conforming behaviour to print a different sequence, even for the same variable, every time ?- write(A), clpb:put_visited(A), write(A). _95_477 clpb:put_atts(A,clpb_visited(true)). Where put_visited(V) :- put_attr(V, clpb_visited, true). In this case, a so-called attribute was attached to the variable, and that apparently had an effect on the output. Perfectly OK, ?- write_term(A, [variable_names(['A'=A])]), clpb:put_visited(A), write_term(A, [variable_names(['A'=A])]). AA clpb:put_atts(A,clpb_visited(true)). |
Beta Was this translation helpful? Give feedback.
-
|
The second question pertains to In my opinion, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been some time trying to solve the last problem in Advent of Code, and after a lot of debugging I came across this behavior of CLPB which I find extremely surprising.
First of all, this works as expected, A is unified with 1.
Now if I print the variable A before and after the call to sat, it seems correct too:
But if A is not fully constrained by the call to sat, I get the following response:
Notice how the variable for A before and after the call to sat is a different variable.
In my attempt to solve the puzzle, I have a set of variables on which I assert constraints using sat on them, but the reality is that whatever I assert does not make the list of variables I carry around unify with anything. Fresh variables are using for the results of the sat calls.
I tried using
portray_clause/1to see if the variable names before and after were rewritten to different names, and they are not, although it rewritesXtoA:I defined this as a predicate and asked for the
listing/1of it:and it still refers to the same variable name
A.The code in my solution looks for example like this:
and I get this:
Beta Was this translation helpful? Give feedback.
All reactions