Skip to content

Commit

Permalink
Clarify mathematical definition of lcm (#56992)
Browse files Browse the repository at this point in the history
Some folks define `lcm(x::T,y::T)` as any `z::T` such that there exists
`a::T, b::T` with `a*x==z` and `b*y==z` and for all `zʹ::T` such that
there exist `a::T, b::T` with `a*x==zʹ` and `b*y==zʹ`, there also exists
`c::T` with `z*c==zʹ`. This is a reasonable definition, but not what we
use. Notably, it makes `lcm(x::Rational, y::Rational) = z::Rational`
true for all finite, nonzero `x`, `y`, and `z`.

The definition we use requires `a`, `b`, and `c` to all be _integers_,
not rationals in the case of `lcm(x::Rational, y::Rational)`. This
clarifies what we mean when we define `lcm(x::Rational, y::Rational)`
and also how the generic function should be extended.

See [this
thread](#56423 (comment))
for more discussion
  • Loading branch information
LilithHafner authored Jan 8, 2025
1 parent 75cdffe commit 64d4c6b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ end
Least common (positive) multiple (or zero if any argument is zero).
The arguments may be integer and rational numbers.
``a`` is a multiple of ``b`` if there exists an integer ``m`` such
that ``a=mb``.
!!! compat "Julia 1.4"
Rational arguments require Julia 1.4 or later.
Expand Down

0 comments on commit 64d4c6b

Please sign in to comment.