Or: Difference between revisions

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...")
 
m (Text replacement - "<source" to "<syntaxhighlight")
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Built-in|Or|∨}} is a [[dyadic]] [[scalar function|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 [[wikipedia:logical disjunction|logical disjunction]] in Boolean logic.
{{Built-in|Or|∨}} is a [[dyadic]] [[scalar function|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 [[wikipedia:logical disjunction|logical disjunction]] in Boolean logic. In many APLs, Or is a special case of the [[GCD]] function.


{|class=wikitable
{|class=wikitable
!<source lang=apl inline>∨</source>!!<source lang=apl inline>0</source>!!<source lang=apl inline>1</source>
!<syntaxhighlight lang=apl inline>∨</syntaxhighlight>!!<syntaxhighlight lang=apl inline>0</syntaxhighlight>!!<syntaxhighlight lang=apl inline>1</syntaxhighlight>
|-
|-
!<source lang=apl inline>0</source>
!<syntaxhighlight lang=apl inline>0</syntaxhighlight>
|<source lang=apl inline>0</source>||<source lang=apl inline>1</source>
|<syntaxhighlight lang=apl inline>0</syntaxhighlight>||<syntaxhighlight lang=apl inline>1</syntaxhighlight>
|-
|-
!<source lang=apl inline>1</source>
!<syntaxhighlight lang=apl inline>1</syntaxhighlight>
|<source lang=apl inline>1</source>||<source lang=apl inline>1</source>
|<syntaxhighlight lang=apl inline>1</syntaxhighlight>||<syntaxhighlight lang=apl inline>1</syntaxhighlight>
|}
|}


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


<source lang=apl>
<syntaxhighlight lang=apl>
       0 0 1 1 ∨ 0 1 0 1
       0 0 1 1 ∨ 0 1 0 1
0 1 1 1
0 1 1 1
</source>
</syntaxhighlight>


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


<source lang=apl>
<syntaxhighlight lang=apl>
       ∨/ 0 0 1 0 1
       ∨/ 0 0 1 0 1
1
1
       ∨/ 0 0 0 0 0
       ∨/ 0 0 0 0 0
0
0
</source>
</syntaxhighlight>


== Extended definition ==
== See also ==
 
* [[Add]]
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).
* [[Maximum]]
 
* [[Union]]
<source lang=apl>
* [[Nor]]
      ∘.∨⍨ 0,⍳10
* [[And]]
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
 
      0.6∨13÷3
0.06666666667
      0.6(13÷3)÷0.6∨13÷3
9 65
      2J2∨3J1
1J1
      2J2 3J1÷1J1
2 2J¯1
</source>{{Works in|[[Dyalog APL]]}}


== External links ==
== External links ==
Line 61: Line 40:
=== Documentation ===
=== Documentation ===


* [http://help.dyalog.com/17.1/#Language/Primitive%20Functions/Or%20Greatest%20Common%20Divisor.htm Dyalog]
* [https://help.dyalog.com/17.1/#Language/Primitive%20Functions/Or%20Greatest%20Common%20Divisor.htm Dyalog]
* [http://microapl.com/apl_help/ch_020_020_420.htm APLX]
* J [https://www.jsoftware.com/help/dictionary/d101.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/plusdot#dyadic NuVoc]
* J [https://www.jsoftware.com/help/dictionary/d101.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/plusdot#dyadic NuVoc]
* [https://mlochbaum.github.io/BQN/doc/logic.html 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:25, 10 September 2022

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. In many APLs, Or is a special case of the GCD function.

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

See also

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