Opened 7 years ago

# CombinatorialFreeModule: fix comparison with zero — at Version 12

Reported by: Owned by: tscrim tscrim critical sage-7.4 coercion zero nthiery, darij, nbruin, robertwb, chapoton, vdelecroix N/A u/jdemeyer/combinatorialfreemodule_should_use_coercion_for_comparisons 3aa0ccae4e5c42359636afd5b77a504388e26928 #21128

Currently we have the following in Sage:

```sage: C = CombinatorialFreeModule(QQ, ['a','b'])
sage: C.zero() == ZZ(0)
True
sage: C.zero() == QQ(0)
False
```

The problem is that there is no coercion `QQ -> C`. The coercion model special-cases `ZZ(0)` but not other kinds of zero.

### comment:1 Changed 6 years ago by jdemeyer

• Description modified (diff)
• Summary changed from Equality comparison with 0 is not consistant to CombinatorialFreeModule should use coercion for comparisons

### comment:2 Changed 6 years ago by jdemeyer

• Description modified (diff)

### comment:3 Changed 6 years ago by jdemeyer

• Description modified (diff)
• Milestone changed from sage-6.7 to sage-7.4

### comment:5 Changed 6 years ago by jdemeyer

• Description modified (diff)

### comment:6 Changed 6 years ago by jdemeyer

Part of the problem is that there is no coercion defined anyway:

```sage: C = CombinatorialFreeModule(QQ, ['a','b'])
sage: C.coerce(QQ(0))
TypeError: no canonical coercion from Rational Field to Free module generated by {'a', 'b'} over Rational Field
```

This makes sense, but it means that the problem is different from what I originally thought.

### comment:7 Changed 6 years ago by jdemeyer

• Description modified (diff)

### comment:8 Changed 6 years ago by jdemeyer

And the coercion model has an explicit special case for `ZZ(0)`.

### comment:9 Changed 6 years ago by jdemeyer

• Dependencies set to #21128
• Description modified (diff)

### comment:10 Changed 6 years ago by jdemeyer

I am going to attach my branch anyway, which does coercion but doesn't actually fix the problem.

### comment:11 Changed 6 years ago by jdemeyer

• Branch set to u/jdemeyer/combinatorialfreemodule_should_use_coercion_for_comparisons

### comment:12 Changed 6 years ago by jdemeyer

• Commit set to 3aa0ccae4e5c42359636afd5b77a504388e26928
• Description modified (diff)
• Summary changed from CombinatorialFreeModule should use coercion for comparisons to CombinatorialFreeModule: fix comparison with zero

New commits:

 ​f9db843 `Improve support for comparisons in plain Python modules` ​3aa0cca `CombinatorialFreeModule: use coercion for comparisons`
Note: See TracTickets for help on using tickets.