Minimum: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "http://help.dyalog.com" to "https://help.dyalog.com")
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Built-in|Minimum|⌊}}, '''Min''', or '''Lesser of''' is a [[dyadic]] [[scalar function]] which returns the [[Less than|smaller]] of its two [[argument]]s. The name "Minimum" is sometimes also used for the Minimum [[Reduce]] <source lang=apl inline>⌊/</source>, which returns the smallest element of a [[vector]] (this usage is related to the [[wikipedia:minimum|minimum]] of a function). Minimum is paired with [[Maximum]], which returns the greater argument rather than the smaller, and shares the glyph <source lang=apl inline>⌊</source> with the [[Floor]] function. It is not subject to [[comparison tolerance]], since the result will be exactly equal to one argument, and there is no reason to choose a larger argument even if the two arguments are [[tolerant comparison|tolerantly]] equal. As a [[Boolean function]], Minimum is identical to [[And]].
{{Built-in|Minimum|⌊}}, '''Min''', or '''Lesser of''' is a [[dyadic]] [[scalar function]] which returns the [[Less than|smaller]] of its two [[argument]]s. The name "Minimum" is sometimes also used for the Minimum [[Reduce]] <syntaxhighlight lang=apl inline>⌊/</syntaxhighlight>, which returns the smallest element of a [[vector]] (this usage is related to the [[wikipedia:minimum|minimum]] of a function). Minimum is paired with [[Maximum]], which returns the greater argument rather than the smaller, and shares the glyph <syntaxhighlight lang=apl inline>⌊</syntaxhighlight> with the [[Floor]] function. It is not subject to [[comparison tolerance]], since the result will be exactly equal to one argument, and there is no reason to choose a larger argument even if the two arguments are [[tolerant comparison|tolerantly]] equal. As a [[Boolean function]], Minimum is identical to [[And]].


== Examples ==
== Examples ==


Minimum finds the smaller of two numbers:
Minimum finds the smaller of two numbers:
<source lang=apl>
<syntaxhighlight lang=apl>
       2.4 ⌊ 1.9
       2.4 ⌊ 1.9
1.9
1.9
</source>
</syntaxhighlight>
Together with [[Maximum]], it can clamp an array of numbers to a range (closed interval), here from 0 to 1:
Together with [[Maximum]], it can clamp an array of numbers to a range (closed interval), here from 0 to 1:
<source lang=apl>
<syntaxhighlight lang=apl>
       0 ⌈ 1 ⌊ ¯0.2 ¯0.1 0.3 0.8 1 1.3
       0 ⌈ 1 ⌊ ¯0.2 ¯0.1 0.3 0.8 1 1.3
0 0 0.3 0.8 1 1
0 0 0.3 0.8 1 1
</source>
</syntaxhighlight>
Because the [[complex number]]s do not form an [[wikipedia:ordered field|ordered field]], attempting to take the minimum with a complex argument yields a [[DOMAIN ERROR]].
Because the [[complex number]]s do not form an [[wikipedia:ordered field|ordered field]], attempting to take the minimum with a complex argument yields a [[DOMAIN ERROR]].
<source lang=apl>
<syntaxhighlight lang=apl>
       3 ⌊ 3j1
       3 ⌊ 3j1
DOMAIN ERROR
DOMAIN ERROR
       3⌊3J1
       3⌊3J1
       ∧
       ∧
</source>
</syntaxhighlight>


=== Reduction ===
=== Reduction ===


Minimum [[Reduce]] finds the smallest [[element]] in an entire [[vector]]:
Minimum [[Reduce]] finds the smallest [[element]] in an entire [[vector]]:
<source lang=apl>
<syntaxhighlight lang=apl>
       ⌊/ 4 3 2 3 1 5 7
       ⌊/ 4 3 2 3 1 5 7
1
1
</source>
</syntaxhighlight>
To find the [[index]] of the minimum, [[Index Of]] can be used to search for it. A shorter, but usually slower, method is to take the [[First]] of the vector's [[Grade]].
To find the [[index]] of the minimum, [[Index Of]] can be used to search for it. A shorter, but usually slower, method is to take the [[First]] of the vector's [[Grade]].
<source lang=apl>
<syntaxhighlight lang=apl>
       {⍵⍳⌊/⍵} 4 3 2 3 1 5 7
       {⍵⍳⌊/⍵} 4 3 2 3 1 5 7
5
5
       ⊃⍋ 4 3 2 3 1 5 7
       ⊃⍋ 4 3 2 3 1 5 7
5
5
</source>
</syntaxhighlight>
The two solutions may differ when [[comparison tolerance]] is not zero, because Index Of uses tolerant comparison but Grade does not. The first solution will return a smaller index if an element that is tolerantly but not exactly equal to the minimum is found at that index.
The two solutions may differ when [[comparison tolerance]] is not zero, because Index Of uses tolerant comparison but Grade does not. The first solution will return a smaller index if an element that is tolerantly but not exactly equal to the minimum is found at that index.


Reducing over an empty axis yields the largest representable number, as that is the identity element for Minimum. This value is usually <source lang=apl inline>∞</source> (for dialects that support [[infinity|infinities]]) or <source lang=apl inline>1.797693135E308</source> (with 64-bit [[float]]s) or <source lang=apl inline>1E6145</source> (with 128-bit [[decimal float]]s).
Reducing over an empty axis yields the largest representable number, as that is the identity element for Minimum. This value is usually <syntaxhighlight lang=apl inline>∞</syntaxhighlight> (for dialects that support [[infinity|infinities]]) or <syntaxhighlight lang=apl inline>1.797693135E308</syntaxhighlight> (with 64-bit [[float]]s) or <syntaxhighlight lang=apl inline>1E6145</syntaxhighlight> (with 128-bit [[decimal float]]s).


== External links ==
== External links ==
Line 46: Line 46:
* [http://microapl.com/apl_help/ch_020_020_120.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_120.htm APLX]
* J [https://www.jsoftware.com/help/dictionary/d011.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/ltdot#dyadic NuVoc]
* J [https://www.jsoftware.com/help/dictionary/d011.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/ltdot#dyadic NuVoc]
* [https://mlochbaum.github.io/BQN/doc/arithmetic.html#additional-arithmetic BQN]


{{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar dyadic functions]]
{{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar dyadic functions]]

Latest revision as of 22:23, 10 September 2022

Minimum (), Min, or Lesser of is a dyadic scalar function which returns the smaller of its two arguments. The name "Minimum" is sometimes also used for the Minimum Reduce ⌊/, which returns the smallest element of a vector (this usage is related to the minimum of a function). Minimum is paired with Maximum, which returns the greater argument rather than the smaller, and shares the glyph with the Floor function. It is not subject to comparison tolerance, since the result will be exactly equal to one argument, and there is no reason to choose a larger argument even if the two arguments are tolerantly equal. As a Boolean function, Minimum is identical to And.

Examples

Minimum finds the smaller of two numbers:

      2.4 ⌊ 1.9
1.9

Together with Maximum, it can clamp an array of numbers to a range (closed interval), here from 0 to 1:

      0 ⌈ 1 ⌊ ¯0.2 ¯0.1 0.3 0.8 1 1.3
0 0 0.3 0.8 1 1

Because the complex numbers do not form an ordered field, attempting to take the minimum with a complex argument yields a DOMAIN ERROR.

      3 ⌊ 3j1
DOMAIN ERROR
      3⌊3J1
       ∧

Reduction

Minimum Reduce finds the smallest element in an entire vector:

      ⌊/ 4 3 2 3 1 5 7
1

To find the index of the minimum, Index Of can be used to search for it. A shorter, but usually slower, method is to take the First of the vector's Grade.

      {⍵⍳⌊/⍵} 4 3 2 3 1 5 7
5
      ⊃⍋ 4 3 2 3 1 5 7
5

The two solutions may differ when comparison tolerance is not zero, because Index Of uses tolerant comparison but Grade does not. The first solution will return a smaller index if an element that is tolerantly but not exactly equal to the minimum is found at that index.

Reducing over an empty axis yields the largest representable number, as that is the identity element for Minimum. This value is usually (for dialects that support infinities) or 1.797693135E308 (with 64-bit floats) or 1E6145 (with 128-bit decimal floats).

External links

Documentation


APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector