Difference between revisions of "Or"

From APL Wiki
Jump to navigation Jump to search
(Created page with "{{Built-in|Or|∨}} is a dyadic scalar boolean function which tests if at least one of the two arguments is true: it returns 1 if at least one side...")
 
(→‎Extended definition: Split the description for integers and non-integers)
Line 31: Line 31:
 
== Extended definition ==
 
== Extended definition ==
  
Many APL implementations extend this function to non-Boolean arguments. In this case, this function behaves as '''[[wikipedia:Greatest common divisor|Greatest Common Divisor]]''' or '''GCD'''. For positive integer arguments, it is defined as the largest positive number which divides both numbers. If one of the arguments is zero, the GCD function returns the other number. While the mathematical definition of GCD does not cover non-integers, some implementations accept them as arguments, returning a value which, when dividing both arguments, gives integers (or [[wikipedia:Gaussian integer|Gaussian integers]], when given [[complex]] numbers).
+
Many APL implementations extend this function to non-Boolean arguments. In this case, this function behaves as '''[[wikipedia:Greatest common divisor|Greatest Common Divisor]]''' or '''GCD'''. For positive integer arguments, it is defined as the largest positive number which divides both numbers. If one of the arguments is zero, the GCD function returns the other number.
  
 
<source lang=apl>
 
<source lang=apl>
Line 46: Line 46:
 
  9 1 1 3 1 1 3 1 1 9  1
 
  9 1 1 3 1 1 3 1 1 9  1
 
10 1 2 1 2 5 2 1 2 1 10
 
10 1 2 1 2 5 2 1 2 1 10
 +
</source>{{Works in|[[Dyalog APL]]}}
  
 +
While the mathematical definition of GCD 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>X÷R</source> and <source lang=apl inline>Y÷R</source> are integers (or [[wikipedia:Gaussian integer|Gaussian integers]], when X and/or Y are [[complex]] numbers).
 +
 +
<source lang=apl>
 
       0.6∨13÷3
 
       0.6∨13÷3
 
0.06666666667
 
0.06666666667

Revision as of 04:29, 1 June 2020

Or () is a dyadic scalar boolean function which tests if at least one of the two arguments is true: it returns 1 if at least one side is 1 and 0 if both are 0. It represents the logical disjunction in Boolean logic.

0 1
0 0 1
1 1 1

Examples

The following shows all possible combinations of inputs as a Boolean function.

      0 0 1 1  0 1 0 1
0 1 1 1

When combined with Reduce, Or can be used to test if some value in a Boolean vector is true.

      / 0 0 1 0 1
1
      / 0 0 0 0 0
0

Extended definition

Many APL implementations extend this function to non-Boolean arguments. In this case, this function behaves as Greatest Common Divisor or GCD. For positive integer arguments, it is defined as the largest positive number which divides both numbers. If one of the arguments is zero, the GCD function returns the other number.

      ∘. 0,⍳10
 0 1 2 3 4 5 6 7 8 9 10
 1 1 1 1 1 1 1 1 1 1  1
 2 1 2 1 2 1 2 1 2 1  2
 3 1 1 3 1 1 3 1 1 3  1
 4 1 2 1 4 1 2 1 4 1  2
 5 1 1 1 1 5 1 1 1 1  5
 6 1 2 3 2 1 6 1 2 3  2
 7 1 1 1 1 1 1 7 1 1  1
 8 1 2 1 4 1 2 1 8 1  2
 9 1 1 3 1 1 3 1 1 9  1
10 1 2 1 2 5 2 1 2 1 10
Works in: Dyalog APL

While the mathematical definition of GCD does not cover non-integers, some implementations accept them as arguments. In this case, the return value of RXY is chosen so that both X÷R and Y÷R are integers (or Gaussian integers, when X and/or Y are complex numbers).

      0.613÷3
0.06666666667
      0.6(13÷3)÷0.613÷3
9 65
      2J23J1
1J1
      2J2 3J1÷1J1
2 2J¯1
Works in: Dyalog APL

External links

Documentation

APL built-ins [edit]
Primitive functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialise
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencil
Quad names
Arrays Index originMigration level
Functions Case convert
Operators SearchReplace