#24880 closed defect (fixed)

gcd is not commutative (on rationals)

Reported by: vdelecroix Owned by:
Priority: critical Milestone: sage-8.2
Component: basic arithmetic Keywords: days83, thursdaysbdx
Cc: rws Merged in:
Authors: Vincent Klein Reviewers: Jeroen Demeyer, Sébastien Labbé
Report Upstream: N/A Work issues:
Branch: ce541c3 (Commits) Commit: ce541c3ea6180b60cfa3f1c5e0b141e04e9955ee
Dependencies: Stopgaps:

Description

sage: gcd([1/1,1/2])
1
sage: gcd([1/2,1/1])
1/2

Though the gcd is perfectly well defined on rationals

sage: (1/1).gcd(1/2)
1/2
sage: (1/2).gcd(1/1)
1/2

Change History (11)

comment:1 Changed 22 months ago by rws

It's because the loop through the sequence is interrupted as soon as the partial GCD is one, which is only valid for integer GCD:

    for vi in v:
        g = vi.gcd(g, **kwargs)
        if g == one:
            return g
Last edited 22 months ago by rws (previous) (diff)

comment:2 Changed 21 months ago by vklein

  • Branch set to u/vklein/gcd_is_not_commutative__on_rationals_

comment:3 Changed 21 months ago by vklein

  • Commit set to 0a599ea4e1cf773578efe8ffec4d34d75ca7b081
  • Status changed from new to needs_review
if g == one:
            return g

has been removed.


New commits:

0a599eaTrac #24880: fix __GCD_sequence

comment:4 Changed 21 months ago by vklein

  • Authors set to Vincent Klein

comment:5 follow-up: Changed 21 months ago by slabbe

  • Status changed from needs_review to needs_work

Documentation won't build correctly as you need double :: before a doctest block of code (after TESTS).

Last edited 21 months ago by slabbe (previous) (diff)

comment:6 Changed 21 months ago by slabbe

  • Keywords thursdaysbdx added

comment:7 Changed 21 months ago by git

  • Commit changed from 0a599ea4e1cf773578efe8ffec4d34d75ca7b081 to ce541c3ea6180b60cfa3f1c5e0b141e04e9955ee

Branch pushed to git repo; I updated commit sha1. New commits:

ce541c3Trac #24880: TESTS: => TESTS::

comment:8 in reply to: ↑ 5 Changed 21 months ago by vklein

  • Status changed from needs_work to needs_review

Replying to slabbe:

Documentation won't build correctly as you need double :: after a doctest block of code (after TESTS).

Fixed

comment:9 Changed 21 months ago by jdemeyer

  • Reviewers set to Jeroen Demeyer
  • Status changed from needs_review to positive_review

comment:10 Changed 21 months ago by slabbe

  • Reviewers changed from Jeroen Demeyer to Jeroen Demeyer, Sébastien Labbé

comment:11 Changed 20 months ago by vbraun

  • Branch changed from u/vklein/gcd_is_not_commutative__on_rationals_ to ce541c3ea6180b60cfa3f1c5e0b141e04e9955ee
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.