Skip to content

Commit

Permalink
Define gcd & lcm of single element
Browse files Browse the repository at this point in the history
  • Loading branch information
d-torrance committed Nov 27, 2024
1 parent 9487393 commit b986570
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions M2/Macaulay2/m2/factor.m2
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ gcd(RingElement,RingElement) := RingElement => (r,s) -> (
if s%a != 0 then error "can't find gcd in this ring";
s // a))
else notImplemented()))
gcd RingElement := identity

gcdCoefficients(RingElement,RingElement) := (f,g) -> ( -- ??
R := ring f;
Expand All @@ -52,6 +53,7 @@ lcm(RingElement,RingElement) := (f,g) -> (
d := gcd(f, g);
if d == 0 then d
else f * (g // d))
lcm RingElement := identity

-----------------------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions M2/Macaulay2/m2/integers.m2
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ gcd(QQ,ZZ) := QQ => (y,x) -> gcd(x * denominator y, numerator y) / denominator y
gcd(QQ,QQ) := QQ => (x,y) -> (
d := denominator x * (denominator y // gcd(denominator x, denominator y));
gcd(numerator (x * d), numerator (y * d)) / d)
gcd ZZ := gcd QQ := identity

abs = method()
abs ZZ := abs RR := abs RRi := abs CC := abs QQ := abs0
Expand All @@ -68,6 +69,7 @@ lcm(QQ,QQ) := (f,g) -> (
d := gcd(f, g);
if d == 0 then 0_QQ
else abs f * (abs g / d))
lcm ZZ := lcm QQ := identity

odd = x -> 1 === x%2
even = x -> 0 === x%2
Expand Down
9 changes: 8 additions & 1 deletion M2/Macaulay2/packages/Macaulay2Doc/operators.m2
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ document {
(gcd, QQ, ZZ),
(gcd, ZZ, ZZ),
(gcd,RingElement,ZZ),
(gcd,ZZ,RingElement)},
(gcd,ZZ,RingElement),
(gcd, ZZ),
(gcd, QQ),
(gcd, RingElement)
},
Headline => "greatest common divisor",
Usage => "gcd(x,y,...)",
Inputs => { "x" => ZZ, ", or ", ofClass QQ, ", or ",ofClass RingElement },
Expand All @@ -175,6 +179,9 @@ doc ///
(lcm, ZZ, ZZ)
(lcm,RingElement,ZZ)
(lcm,ZZ,RingElement)
(lcm, ZZ)
(lcm, QQ)
(lcm, RingElement)
Headline
least common multiple
Usage
Expand Down

0 comments on commit b986570

Please sign in to comment.