Opened 7 years ago
Last modified 5 years ago
#18251 new defect
CombinatorialFreeModule: fix arithmetic/comparison with base ring zero
Reported by: | tscrim | Owned by: | tscrim |
---|---|---|---|
Priority: | critical | Milestone: | sage-7.4 |
Component: | coercion | Keywords: | zero |
Cc: | nthiery, darij, nbruin, robertwb, chapoton, vdelecroix | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | u/jdemeyer/combinatorialfreemodule_should_use_coercion_for_comparisons (Commits, GitHub, GitLab) | Commit: | 3aa0ccae4e5c42359636afd5b77a504388e26928 |
Dependencies: | #21128 | Stopgaps: |
Description (last modified by )
Currently we have the following in Sage:
sage: C = CombinatorialFreeModule(QQ, ['a','b']) sage: C(0) + ZZ(0) 0 sage: C(0) + QQ(0) TypeError: unsupported operand parent(s) for '+': 'Free module generated by {'a', 'b'} over Rational Field' and 'Rational Field'
and also
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.
Change History (14)
comment:1 Changed 5 years ago by
- Description modified (diff)
- Summary changed from Equality comparison with 0 is not consistant to CombinatorialFreeModule should use coercion for comparisons
comment:2 Changed 5 years ago by
- Cc chapoton added
- Description modified (diff)
comment:3 Changed 5 years ago by
- Description modified (diff)
- Milestone changed from sage-6.7 to sage-7.4
comment:4 Changed 5 years ago by
- Cc vdelecroix added
comment:5 Changed 5 years ago by
- Description modified (diff)
comment:6 Changed 5 years ago by
comment:7 Changed 5 years ago by
- Description modified (diff)
comment:8 Changed 5 years ago by
And the coercion model has an explicit special case for ZZ(0)
.
comment:9 Changed 5 years ago by
- Dependencies set to #21128
- Description modified (diff)
comment:10 Changed 5 years ago by
I am going to attach my branch anyway, which does coercion but doesn't actually fix the problem.
comment:11 Changed 5 years ago by
- Branch set to u/jdemeyer/combinatorialfreemodule_should_use_coercion_for_comparisons
comment:12 Changed 5 years ago by
- Commit set to 3aa0ccae4e5c42359636afd5b77a504388e26928
- Description modified (diff)
- Summary changed from CombinatorialFreeModule should use coercion for comparisons to CombinatorialFreeModule: fix comparison with zero
comment:13 Changed 5 years ago by
- Description modified (diff)
- Summary changed from CombinatorialFreeModule: fix comparison with zero to CombinatorialFreeModule: fix arithmetic/comparison with base ring zero
comment:14 Changed 5 years ago by
The current behavior of CFM agrees with that of the usual modules:
sage: V = QQ^3 sage: V.coerce(ZZ(0)) (0, 0, 0) sage: V.coerce(QQ(0)) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) ... TypeError: no canonical coercion from Rational Field to Vector space of dimension 3 over Rational Field sage: V.zero() == QQ(0) False sage: V.zero() == ZZ(0) True
I'm thinking a better and more general solution would be to special case the zero of the base ring or possibly just QQ
.
Note: See
TracTickets for help on using
tickets.
Part of the problem is that there is no coercion defined anyway:
This makes sense, but it means that the problem is different from what I originally thought.