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:

Status badges

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 slelievre

  • Cc slelievre added

Setting gcd(0, z) to abs(z) when z is complex with nonzero real and imaginary parts is indeed erroneous. Using max(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) and lcm(r, 5) with r = sqrt(5), one would need to decide in what ring one is working. The ring of integers of QQ(r) is ZZ[a] where a is the golden ratio (the positive root of a^2 = a + 1; the units are powers of a and their negatives; r equals 2*a - 1 so it is an integer, so ZZ[a] seems a good place to compute the gcd. Then it seems natural to write:

gcd(r, 5) = gcd(r, 5 - r*r) = gcd(r, 0) = r

Or one could write:

gcd(2*a - 1, 5) = gcd(2*a - 1, 5 - a*(2*a - 1)
                = gcd(2*a - 1, 3 - a)
                = gcd((2*a - 1) - a*(3 - a), 3 - a)
                = gcd(0, 3 - a)
                = 3 - a

which is r/a (but remember a is a unit).

comment:2 Changed 11 months ago by mkoeppe

  • Milestone changed from sage-9.4 to sage-9.5

comment:3 Changed 7 months ago by mkoeppe

  • Milestone changed from sage-9.5 to sage-9.6

comment:4 Changed 2 months ago by mkoeppe

  • Milestone changed from sage-9.6 to sage-9.7
Note: See TracTickets for help on using tickets.