Skip to content

Commit 64d4c6b

Browse files
authored
Clarify mathematical definition of lcm (#56992)
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
1 parent 75cdffe commit 64d4c6b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

base/intfuncs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ end
9797
Least common (positive) multiple (or zero if any argument is zero).
9898
The arguments may be integer and rational numbers.
9999
100+
``a`` is a multiple of ``b`` if there exists an integer ``m`` such
101+
that ``a=mb``.
102+
100103
!!! compat "Julia 1.4"
101104
Rational arguments require Julia 1.4 or later.
102105

0 commit comments

Comments
 (0)