Skip to content

gcd for fractions works only with reduced fractions. Implementation differs from the description #2349

@alexey-orlov-math

Description

@alexey-orlov-math

First of all, the description says: N.B: we define the GCD of $a/b$ and $c/d$ to be gcd$(ad, bc)/bd$, reduced to lowest terms.

While the implementation does essentially $gcd(a,c) / lcm(b,d)$ with lcm being computed like $lcm(d1, d2) = (d1/gcd(d1,d2)) * d2$.
This only works if the fractions are already reduced. For example:

julia> S, x = polynomial_ring(QQ, "x");

julia> F = fraction_field(S);

julia> gcd( F((x+1)*(x+2), (x+2)^2), F((x+1)^3, (x+1)*(x+2)) )
(x + 1)//(x^3 + 5*x^2 + 8*x + 4)

julia> gcd( (x+1)*(x+2) //  (x+2)^2 , (x+1)^3 // ((x+1)*(x+2)) )
(x + 1)//(x + 2)

EDIT: note that the algorithm described in the comment would work

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions