question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unification not commutative

See original GitHub issue
?- X = s(1), X = s(X).
false.
?- X = s(X), X = s(1).
X = 1 ; 

Expected: While the second is STO (subject to occurs check) and thus undefined, it is still highly desirable if this fails. Either,

  1. because X = s(X) fails due to the occurs check, or

  2. because X = s(X) creates an “infinite term” and X = s(1) fails thereafter, or finally

  3. because X = s(X) produces an error - well that’s not failure …

I have never seen a system with this behavior, but very strictly speaking, that is still conforming. But I really cringe: “Why??”. I very much suspect that this is not intended.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
ghostcommented, Mar 7, 2019

I don’t know. I didn’t implement rational term unification in my system. But algorithms for this problem should be around. Like for example Colmerauer was writing about them:

P R O L O G IN 10 F I G U R E S - Alain Colmerauer 4. INFINITE T R E E S https://www.ijcai.org/Proceedings/83-1/Papers/117a.pdf

SWI-Prolog has implemented such an algorithm. I guess if you do something along bisimulation, you might develop also such an algorithm. You need bisimulation for cases like this:

?- A = s(s(A)), B = s(B), A = B.
true

But making it efficient and not using a lot of extra data structures is the challenge here. SWI-Prolog has not only treated predicates such as (=)/2, but also predicate such as ground/1 and (==)/2.

I did recently something for term_variables/2, by a simple visited list:

public void safeVars(Object t, Display d) { https://github.com/jburse/jekejeke-devel/blob/master/jekrun/headless/jekpro/reference/structure/EngineVars.java#L299

I started using a separate name space, like safe_term_variables/2. I needed this to make the top-level a little safer, like GNU Prolog, I wanted to display <cyclic term> for cyclic terms and not crash.

0reactions
jariazavalverdecommented, Mar 7, 2019

Interesting. And how do you avoid the infinite loop in case Y = s(s(Y)), Y = s(Y).?

<(Y = s(s(Y)), Y = s(Y)), id> =>
<s(s(Y)) = s(s(s(Y))), {Y/s(s(Y))}> =>
<s(Y) = s(s(Y)), {Y/s(s(Y))}> =>
<Y = s(Y), {Y/s(s(Y))}> =>
<s(s(Y)) = s(Y), {Y/s(s(Y))}> =>
<s(Y) = Y, {Y/s(s(Y))}> =>
<Y = s(Y), {Y/s(s(Y))}> =>
<s(s(Y)) = s(Y), {Y/s(s(Y))}> =>
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Commutative Unification - Matthew Rocklin
This doesn't unify. While the first ( add , add ) and second ( x , 1 ) elements can match (if {x:...
Read more >
The Exact Unification Type of Commutative Theories
The exact unification type of an equational theory is based on a new preorder on substitutions, called the exactness preorder, which is tailored ......
Read more >
Unification not commutative · Issue #5 · tau-prolog/tau ... - GitHub
If f(X,X) unifies with another term, a substitution {X/something} is generated. Then, this substitution is applied to the rest of the goal, and ......
Read more >
Unification Substitutions
Unification is a “mutual pattern matching" procedure that takes two terms (or atoms) as input, and returns "failure" if they do not match...
Read more >
E-unification
Matijasevic, building on the work of Davis, Putnam, and Robinson, proved that there is no algorithm to determine if a finite system of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found