Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance equals() with semantic equivalence #151

Open
jvdb opened this issue Feb 10, 2017 · 2 comments
Open

Enhance equals() with semantic equivalence #151

jvdb opened this issue Feb 10, 2017 · 2 comments

Comments

@jvdb
Copy link
Contributor

jvdb commented Feb 10, 2017

As an example, for commutative operators such as Add and Mul, but also for the logical And, we could change the equals() implementations to also state that x + y equals y + x.

@jvdb
Copy link
Contributor Author

jvdb commented Feb 23, 2017

A problem here is with the contract for Object.hashCode() in Java, which has as second clause:

If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

Which will not be satisfied since two semantically equal objects will typically have a different hashcode if they were determined equal based on reordering operands. E.g., x+y and y+x would then be determined equal, but have a different hashcode.

A solution for this would be to keep the current implementations of equals()/hashCode(), but add another method (e.g., semanticEquals()) to determine this kind of equality. This implementation could then be used selectively for some specific operations such as cycle detection in Sub.

@jvdb
Copy link
Contributor Author

jvdb commented Oct 10, 2017

Another solution is to use rewriting to normalize expressions. This could then lead to full equality of originally different expressions. Only thing to consider then is origin tracking so that the rewritten expressions can be traced back to their original form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant