Opened 2 years ago

Closed 21 months ago

# gcd is not commutative (on rationals)

Reported by: Owned by: vdelecroix critical sage-8.2 basic arithmetic days83, thursdaysbdx rws Vincent Klein Jeroen Demeyer, Sébastien Labbé N/A ce541c3 (Commits) ce541c3ea6180b60cfa3f1c5e0b141e04e9955ee

### 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
```

### comment:1 Changed 2 years 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 2 years ago by rws (previous) (diff)

### comment:2 Changed 22 months ago by vklein

• Branch set to u/vklein/gcd_is_not_commutative__on_rationals_

### comment:3 Changed 22 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:

 ​0a599ea `Trac #24880: fix __GCD_sequence`

### comment:4 Changed 22 months ago by vklein

• Authors set to Vincent Klein

### comment:5 follow-up: ↓ 8 Changed 22 months ago by slabbe

• Status changed from needs_review to needs_work

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

Version 1, edited 22 months ago by slabbe (previous) (next) (diff)

### comment:6 Changed 22 months ago by slabbe

• Keywords thursdaysbdx added

### comment:7 Changed 22 months ago by git

• Commit changed from 0a599ea4e1cf773578efe8ffec4d34d75ca7b081 to ce541c3ea6180b60cfa3f1c5e0b141e04e9955ee

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

 ​ce541c3 `Trac #24880: TESTS: => TESTS::`

### comment:8 in reply to: ↑ 5 Changed 22 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 22 months ago by jdemeyer

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

### comment:10 Changed 22 months ago by slabbe

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

### comment:11 Changed 21 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.