Make == a symmetric method
Nobody has claimed this yet.
- Dominant language
- Macaulay2
- Stars
- 435
- Forks
- 297
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 11
Description
Equality is always a symmetric relation, and I think we should implement an exception for == so that for instance the method `Vector == ZZ` will automatically also be used if `ZZ == Vector` is called.
Here is a potential implementation:
```m2
eq0 = lookup(symbol==, Thing, Thing)
Thing == Thing := (a,b) -> (
if lookup(symbol==, class b, class a)
=!= lookup(symbol==, class a, class b)
then b == a else eq0(a,b))
```
I don't like it very much, but it works:
```m2
i1 : eq0 = lookup(symbol==, Thing, Thing);
i2 : Thing == Thing := (a,b) -> (
if lookup(symbol==, class b, class a)
=!= lookup(symbol==, class a, class b)
then b == a else eq0(a,b));
i3 : 1 == vector {1,2}
stdio:2:149:(3):[1]: error: no method for binary operator == applied to objects:
1 (of class ZZ)
2
== | 1 | (of class ZZ )
| 2 |
i4 : Vector == ZZ := (v,f) -> matrix v == f;
i5 : 1 == vector {1,2}
stdio:4:34:(3):[2]: error: matrices have different shapes
i6 : 1 == vector {1}
o6 = true
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files or tests are named in the issue. Start by tracing the `==` method lookup and the proposed `Thing == Thing` implementation, then reproduce the examples involving `1 == vector {1,2}` in the Macaulay2 interpreter. Done means the requested symmetric dispatch works without breaking existing equality behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100