Opened 13 months ago
Last modified 2 months ago
#31884 new defect
gcd(0, z) should not be abs(z) when z is a symbolic complex number
Reported by: | gh-DaveWitteMorris | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | sage-9.7 |
Component: | symbolics | Keywords: | gcd, complex number |
Cc: | slelievre | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
Sage assumes that gcd(0,z)
is abs(z)
when z
is a symbolic numeric. That seems ok for real numbers, but I don't think it makes sense when z
is complex:
sage: gcd(0, SR(2 + 3*I)) sqrt(13)
PS Probably unrelated, but these seem backwards to me:
sage: gcd(sqrt(5), 5) 5 sage: lcm(sqrt(5), 5) sqrt(5)
Change History (4)
comment:1 Changed 13 months ago by
- Cc slelievre added
comment:2 Changed 11 months ago by
- Milestone changed from sage-9.4 to sage-9.5
comment:3 Changed 7 months ago by
- Milestone changed from sage-9.5 to sage-9.6
comment:4 Changed 2 months ago by
- Milestone changed from sage-9.6 to sage-9.7
Note: See
TracTickets for help on using
tickets.
Setting
gcd(0, z)
toabs(z)
whenz
is complex with nonzero real and imaginary parts is indeed erroneous. Usingmax(z, -z)
could work around this problem, even though there's no good order on complex numbers.If, as often, we define the
gcd
up to a unit, then for any pair of nonzero elements in the symbolic ring, any nonzero element can be considered their gcd.To compute
gcd(r, 5)
andlcm(r, 5)
withr = sqrt(5)
, one would need to decide in what ring one is working. The ring of integers ofQQ(r)
isZZ[a]
wherea
is the golden ratio (the positive root ofa^2 = a + 1
; the units are powers ofa
and their negatives;r
equals2*a - 1
so it is an integer, soZZ[a]
seems a good place to compute the gcd. Then it seems natural to write:Or one could write:
which is
r/a
(but remembera
is a unit).