And: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Built-in|And|∧}} is a [[dyadic]] [[scalar function|scalar]] [[boolean function]] which tests if both arguments are true: it returns 1 if both are 1 and 0 if one or both are 0. It represents the [[wikipedia:logical conjunction|logical conjunction]] in Boolean logic.
{{Built-in|And|∧}} is a [[dyadic]] [[scalar function|scalar]] [[boolean function]] which tests if both arguments are true: it returns 1 if both are 1 and 0 if one or both are 0. It represents the [[wikipedia:logical conjunction|logical conjunction]] in Boolean logic. In many APLs, And is a special case of the [[LCM]] 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>0</source>
|<syntaxhighlight lang=apl inline>0</syntaxhighlight>||<syntaxhighlight lang=apl inline>0</syntaxhighlight>
|-
|-
!<source lang=apl inline>1</source>
!<syntaxhighlight lang=apl inline>1</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>
|}
|}


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 0 0 1
0 0 0 1
</source>
</syntaxhighlight>


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


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


== Extended definition ==
== See also ==
 
* [[Times]]
Many APL implementations extend this function to non-Boolean arguments. In this case, this function behaves as '''[[wikipedia:Least common multiple|Least Common Multiple]]''' or '''LCM'''. For positive integer arguments, it is defined as the smallest positive number which is divisible by both numbers. If one of the arguments is zero, the LCM function returns zero. While the mathematical definition of LCM does not cover non-integers, some implementations accept them as arguments, returning a value which, when divided by both arguments, gives integers (or [[wikipedia:Gaussian integer|Gaussian integers]], when given [[complex]] numbers).
* [[Minimum]]
 
* [[Intersection]]
<source lang=apl>
* [[Nand]]
      ∘.∧⍨ 0,⍳10
* [[Or]]
0  0  0  0  0  0  0  0  0  0  0
0  1  2  3  4  5  6  7  8  9 10
0  2  2  6  4 10  6 14  8 18 10
0  3  6  3 12 15  6 21 24  9 30
0  4  4 12  4 20 12 28  8 36 20
0  5 10 15 20  5 30 35 40 45 10
0  6  6  6 12 30  6 42 24 18 30
0  7 14 21 28 35 42  7 56 63 70
0  8  8 24  8 40 24 56  8 72 40
0  9 18  9 36 45 18 63 72  9 90
0 10 10 30 20 10 30 70 40 90 10
 
      0.9∧25÷6
112.5
      112.5÷0.9(25÷6)
125 27
      2J2∧3J1
6J2
      6J2÷2J2 3J1
2J¯1 2
</source>{{Works in|[[Dyalog APL]]}}


== External links ==
== External links ==
Line 61: Line 40:
=== 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]
* [http://microapl.com/apl_help/ch_020_020_430.htm APLX]
* 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]
* [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:08, 10 September 2022

And () is a dyadic scalar boolean function which tests if both arguments are true: it returns 1 if both are 1 and 0 if one or both are 0. It represents the logical conjunction in Boolean logic. In many APLs, And is a special case of the LCM function.

0 1
0 0 0
1 0 1

Examples

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

      0 0 1 1 ∧ 0 1 0 1
0 0 0 1

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

      ∧/ 1 1 1 1 1
1
      ∧/ 1 0 0 1 1
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