You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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.
As an example, for commutative operators such as
Add
andMul
, but also for the logicalAnd
, we could change theequals()
implementations to also state that x + y equals y + x.The text was updated successfully, but these errors were encountered: