Not: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
No edit summary
m (typo)
 
(17 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Built-in|Not|~}} is a [[Primitive function|primitive]] [[monadic]] [[scalar function]] that returns the [https://en.wikipedia.org/wiki/Negation logical negation] of a [[Boolean]] argument—that is, 0 if the argument is 1 and 1 if it is 0. In some languages, such as [[J]], it is extended so that Not <source lang=apl inline>x</source> is equivalent to <source lang=apl inline>1-x</source> while in others, such as [[K]], it is extended so that Not <source lang=apl inline>x</source> is equivalent to <source lang=apl inline>0=x</source>.
{{Built-in|Not|~}} is a [[monadic]] [[scalar function]] that returns the [[wikipedia:Negation|logical negation]] of a [[Boolean]] argument—that is, 0 if the argument is 1 and 1 if it is 0. In some languages, such as [[J]], it is extended so that Not <syntaxhighlight lang=apl inline>x</syntaxhighlight> is equivalent to <syntaxhighlight lang=apl inline>1-x</syntaxhighlight> while in others, such as [[K]], it is extended so that Not <syntaxhighlight lang=apl inline>x</syntaxhighlight> is equivalent to <syntaxhighlight lang=apl inline>0=x</syntaxhighlight>.


== Examples ==
== Examples ==


<source lang=apl>
<syntaxhighlight lang=apl>
       ~ 0 1 1 0 1
       ~ 0 1 1 0 1
1 0 0 1 0
1 0 0 1 0
</source>
</syntaxhighlight>
Attempting to negate a non-[[Boolean]] argument usually results in a [[DOMAIN ERROR]]. In some languages it may instead [[subtract]] the argument from one.
Attempting to negate a non-[[Boolean]] argument usually results in a [[DOMAIN ERROR]]. In some languages it may instead [[subtract]] the argument from one.
<source lang=apl>
<syntaxhighlight lang=apl>
       ~ 0 0.5 1
       ~ 0 0.5 1
DOMAIN ERROR
DOMAIN ERROR
       ~0 0.5 1
       ~0 0.5 1
       ∧
       ∧
</source>
</syntaxhighlight>


== Properties ==
== Properties ==
Line 21: Line 21:
== History ==
== History ==


[[A Programming Language]] negates arrays using an overbar symbol like <math>\overline{p}</math>, matching a convention sometimes used in mathematics. In [[APL\360]] the current symbol <source lang=apl inline>~</source> was chosen, also due to its use in mathematics. Mathematical usage has arguably diverged from APL in this respect, as the negation of a variable <math>p</math> is now more often written <math>\neg p</math>, using the symbol <math>¬</math>, when a prefix operator is desired.
[[A Programming Language]] negates arrays using an overbar symbol like <math>\overline{p}</math>, matching a convention sometimes used in mathematics. In [[APL\360]] the current symbol <syntaxhighlight lang=apl inline>~</syntaxhighlight> was chosen, also due to its use in mathematics. Mathematical usage has arguably diverged from APL in this respect, as the negation of a variable <math>p</math> is now more often written <math>\neg p</math> when a prefix operator is desired.


The arithmetic extension <source lang=apl inline>~x</source> {{←→}} <source lang=apl inline>1-x</source> was introduced to the array langauge family by [[J]]. For arguments in the interval <math>[0,1]</math> this extension may be seen as a probabilistic interpretation of negation.
The arithmetic extension <syntaxhighlight lang=apl inline>~x</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>1-x</syntaxhighlight> was introduced to the array language family by [[J]]. For arguments in the interval <math>[0,1]</math> this extension may be seen as a probabilistic interpretation of negation.
 
== Extensions ==
 
{| class=wikitable
! Extension                            !! Languages
|-
| None                                || [[APL\360]], [[APL2]], [[APLX]], [[SHARP APL]], [[Dyalog APL]], [[GNU APL]], [[ngn/apl]], [[dzaima/APL]]
|-
| <syntaxhighlight lang=apl inline>1-⍵</syntaxhighlight> || [[J]], [[BQN]], [[Extended Dyalog APL]]
|-
| <syntaxhighlight lang=apl inline>0=⍵</syntaxhighlight> || [[K]]
|}
 
== See also ==
* [[Negate]]
* [[Nor]]
* [[Nand]]
* [[Not Equal to]]
* [[Not Match]]


== External links ==
== External links ==
Line 33: Line 52:
=== Documentation ===
=== Documentation ===


* [http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Not.htm Dyalog]
* [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Not.htm Dyalog]
* [http://microapl.com/apl_help/ch_020_020_400.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_400.htm APLX]
* J [https://www.jsoftware.com/help/dictionary/d121.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/minusdot NuVoc]
* J [https://www.jsoftware.com/help/dictionary/d121.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/minusdot NuVoc]
* [https://mlochbaum.github.io/BQN/doc/logic.html BQN]


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

Latest revision as of 06:58, 26 August 2024

~

Not (~) is a monadic scalar function that returns the logical negation of a Boolean argument—that is, 0 if the argument is 1 and 1 if it is 0. In some languages, such as J, it is extended so that Not x is equivalent to 1-x while in others, such as K, it is extended so that Not x is equivalent to 0=x.

Examples

      ~ 0 1 1 0 1
1 0 0 1 0

Attempting to negate a non-Boolean argument usually results in a DOMAIN ERROR. In some languages it may instead subtract the argument from one.

      ~ 0 0.5 1
DOMAIN ERROR
      ~0 0.5 1
      ∧

Properties

Not is the only Boolean function of a single argument which depends on that argument (it is not constant) and is not trivial (the same as Identity). Not is its own Inverse.

History

A Programming Language negates arrays using an overbar symbol like , matching a convention sometimes used in mathematics. In APL\360 the current symbol ~ was chosen, also due to its use in mathematics. Mathematical usage has arguably diverged from APL in this respect, as the negation of a variable is now more often written when a prefix operator is desired.

The arithmetic extension ~x 1-x was introduced to the array language family by J. For arguments in the interval this extension may be seen as a probabilistic interpretation of negation.

Extensions

Extension Languages
None APL\360, APL2, APLX, SHARP APL, Dyalog APL, GNU APL, ngn/apl, dzaima/APL
1-⍵ J, BQN, Extended Dyalog APL
0=⍵ K

See also

External links

Lessons

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