LCM: Difference between revisions

Jump to navigation Jump to search
80 bytes added ,  21:28, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
(Separate from And)
Tag: Removed redirect
m (Text replacement - "</source>" to "</syntaxhighlight>")
Tags: Mobile edit Mobile web edit
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Built-in|LCM|∧}} is a [[dyadic]] [[scalar function]] which returns the '''[[wikipedia:Least common multiple|Least Common Multiple]]''' of two integer arguments. It is an extension of [[And]] which maintains the same results on [[Boolean]] arguments and the same [[identity element]] 1, in the same way that [[GCD]] extends [[Or]].
{{Built-in|LCM|∧}} is a [[dyadic]] [[scalar function]] which returns the '''[[wikipedia:Least common multiple|Least Common Multiple]]''' of two integer arguments. It is an extension of [[And]] which maintains the same results on [[Boolean]] arguments and the same [[identity element]] 1, in the same way that [[GCD]] extends [[Or]].


== Extended definition ==
== Examples ==


For positive integer arguments, the least common multiple is the smallest positive number which is divisible by both numbers. If one of the arguments is zero, the LCM function returns zero.
For positive integer arguments, the least common multiple is the smallest positive number which is divisible by both numbers. If one of the arguments is zero, the LCM function returns zero.


<source lang=apl>
<syntaxhighlight lang=apl>
       ∘.∧⍨ 0,⍳10
       ∘.∧⍨ 0,⍳10
0  0  0  0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  0  0
Line 18: Line 18:
0  9 18  9 36 45 18 63 72  9 90
0  9 18  9 36 45 18 63 72  9 90
0 10 10 30 20 10 30 70 40 90 10
0 10 10 30 20 10 30 70 40 90 10
</source>{{Works in|[[Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[Dyalog APL]]}}


While the mathematical definition of LCM does not cover non-integers, some implementations accept them as arguments. In this case, the return value of <source lang=apl inline>R←X∧Y</source> is chosen so that both <source lang=apl inline>R÷X</source> and <source lang=apl inline>R÷Y</source> are integers (or [[wikipedia:Gaussian integer|Gaussian integers]], when X and/or Y are [[complex]] numbers).
While the mathematical definition of LCM does not cover non-integers, some implementations accept them as arguments. In this case, the return value of <syntaxhighlight lang=apl inline>R←X∧Y</syntaxhighlight> is chosen so that both <syntaxhighlight lang=apl inline>R÷X</syntaxhighlight> and <syntaxhighlight lang=apl inline>R÷Y</syntaxhighlight> are integers (or [[wikipedia:Gaussian integer|Gaussian integers]], when X and/or Y are [[complex]] numbers).


<source lang=apl>
<syntaxhighlight lang=apl>
       0.9∧25÷6
       0.9∧25÷6
112.5
112.5
Line 31: Line 31:
       6J2÷2J2 3J1
       6J2÷2J2 3J1
2J¯1 2
2J¯1 2
</source>{{Works in|[[Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[Dyalog APL]]}}


== Description ==
== Description ==
Line 41: Line 41:
=== Documentation ===
=== Documentation ===


* [http://help.dyalog.com/17.1/#Language/Primitive%20Functions/And%20Lowest%20Common%20Multiple.htm Dyalog]
* [https://help.dyalog.com/17.1/#Language/Primitive%20Functions/And%20Lowest%20Common%20Multiple.htm Dyalog]
* J [https://www.jsoftware.com/help/dictionary/d111.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/stardot#dyadic NuVoc]
* J [https://www.jsoftware.com/help/dictionary/d111.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/stardot#dyadic NuVoc]
{{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar dyadic functions]]
{{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar dyadic functions]]

Navigation menu