4,494
edits
m (Text replacement - "</source>" to "</syntaxhighlight>") |
m (Text replacement - "<source" to "<syntaxhighlight") Tags: Mobile edit Mobile web edit |
||
Line 1: | Line 1: | ||
{{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 < | {{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 == | ||
< | <syntaxhighlight lang=apl> | ||
~ 0 1 1 0 1 | ~ 0 1 1 0 1 | ||
1 0 0 1 0 | 1 0 0 1 0 | ||
</syntaxhighlight> | </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. | ||
< | <syntaxhighlight lang=apl> | ||
~ 0 0.5 1 | ~ 0 0.5 1 | ||
DOMAIN ERROR | DOMAIN ERROR | ||
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 < | [[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 < | The arithmetic extension <syntaxhighlight lang=apl inline>~x</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>1-x</syntaxhighlight> 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. | ||
== Extensions == | == Extensions == | ||
Line 32: | Line 32: | ||
| None || [[APL\360]], [[APL2]], [[APLX]], [[SHARP APL]], [[Dyalog APL]], [[GNU APL]], [[ngn/apl]], [[dzaima/APL]] | | 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]] | ||
|} | |} | ||