Equal to: Difference between revisions

Jump to navigation Jump to search
171 bytes added ,  22:14, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source" to "<syntaxhighlight")
m (Text replacement - "</source>" to "</syntaxhighlight>")
Tags: Mobile edit Mobile web edit
Line 1: Line 1:
{{Built-in|Equal to|<nowiki>=</nowiki>}} is a [[comparison function]] which tests whether argument elements are [[Tolerant comparison|tolerantly]] equal to each other: it returns 1 if the [[element]]s being compared [[match]] and 0 if they do not. It is the [[Not|negation]] of [[Not Equal to]] (<syntaxhighlight lang=apl inline>≠</source>).
{{Built-in|Equal to|<nowiki>=</nowiki>}} is a [[comparison function]] which tests whether argument elements are [[Tolerant comparison|tolerantly]] equal to each other: it returns 1 if the [[element]]s being compared [[match]] and 0 if they do not. It is the [[Not|negation]] of [[Not Equal to]] (<syntaxhighlight lang=apl inline>≠</syntaxhighlight>).


APL's <syntaxhighlight lang=apl inline>=</source> differs from the usage of <math>=</math> in [[Comparison with traditional mathematics|traditional mathematical notation]] by having an implied [[Ken_Iverson#Iverson_bracket|Iverson bracket]]. Thus, <syntaxhighlight lang=apl inline>i=j</source> is APL is equivalent to <math>[i=j]</math> or <math>\delta_{ij}</math> ([[wikipedia:Kronecker delta|Kronecker delta]]) in mathematics.
APL's <syntaxhighlight lang=apl inline>=</syntaxhighlight> differs from the usage of <math>=</math> in [[Comparison with traditional mathematics|traditional mathematical notation]] by having an implied [[Ken_Iverson#Iverson_bracket|Iverson bracket]]. Thus, <syntaxhighlight lang=apl inline>i=j</syntaxhighlight> is APL is equivalent to <math>[i=j]</math> or <math>\delta_{ij}</math> ([[wikipedia:Kronecker delta|Kronecker delta]]) in mathematics.


== Examples ==
== Examples ==
Line 13: Line 13:
       3j2 2j2 1j2 = 2j2
       3j2 2j2 1j2 = 2j2
0 1 0
0 1 0
</source>
</syntaxhighlight>
It is subject to [[comparison tolerance]]: floating-point numbers which are very close together are considered equal, even though they are slightly different:
It is subject to [[comparison tolerance]]: floating-point numbers which are very close together are considered equal, even though they are slightly different:
<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
Line 25: Line 25:
       1 {⎕CT←0⋄⍺=⍵} x                  ⍝ Overriding ⎕CT within a dfn
       1 {⎕CT←0⋄⍺=⍵} x                  ⍝ Overriding ⎕CT within a dfn
0 0 1 0 0
0 0 1 0 0
</source>
</syntaxhighlight>
In a [[Nested array model|nested]] APL, Equal to is pervasive, and compares all [[simple scalar]]s found in a [[nested array]].
In a [[Nested array model|nested]] APL, Equal to is pervasive, and compares all [[simple scalar]]s found in a [[nested array]].
<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
Line 40: Line 40:
│└───┴─┘│    │  │
│└───┴─┘│    │  │
└───────┴─────┴───┘
└───────┴─────┴───┘
</source>
</syntaxhighlight>
In a [[Flat array model|flat]] array language such as [[J]], it instead compares [[Box]]es directly, since they are the [[element]]s of a boxed array.
In a [[Flat array model|flat]] array language such as [[J]], it instead compares [[Box]]es directly, since they are the [[element]]s of a boxed array.
<syntaxhighlight lang=j>
<syntaxhighlight lang=j>
   (<'string') = 'which';'is';'string';'?'
   (<'string') = 'which';'is';'string';'?'
0 0 1 0
0 0 1 0
</source>
</syntaxhighlight>


== Boolean function ==
== Boolean function ==
Line 51: Line 51:
When the arguments to Equal to are [[Boolean]], it is the [[wikipedia:Logical biconditional|Logical biconditional]] function, or the [[Not|negation]] of the [[xor]] function (which is [[Not Equal to]] restricted to Boolean arguments):
When the arguments to Equal to are [[Boolean]], it is the [[wikipedia:Logical biconditional|Logical biconditional]] function, or the [[Not|negation]] of the [[xor]] function (which is [[Not Equal to]] restricted to Boolean arguments):
{|class=wikitable
{|class=wikitable
!<syntaxhighlight lang=apl inline>=</source>!!<syntaxhighlight lang=apl inline>0</source>!!<syntaxhighlight lang=apl inline>1</source>
!<syntaxhighlight lang=apl inline>=</syntaxhighlight>!!<syntaxhighlight lang=apl inline>0</syntaxhighlight>!!<syntaxhighlight lang=apl inline>1</syntaxhighlight>
|-
|-
!<syntaxhighlight lang=apl inline>0</source>
!<syntaxhighlight lang=apl inline>0</syntaxhighlight>
|<syntaxhighlight lang=apl inline>1</source>||<syntaxhighlight lang=apl inline>0</source>
|<syntaxhighlight lang=apl inline>1</syntaxhighlight>||<syntaxhighlight lang=apl inline>0</syntaxhighlight>
|-
|-
!<syntaxhighlight lang=apl inline>1</source>
!<syntaxhighlight lang=apl inline>1</syntaxhighlight>
|<syntaxhighlight lang=apl inline>0</source>||<syntaxhighlight lang=apl inline>1</source>
|<syntaxhighlight lang=apl inline>0</syntaxhighlight>||<syntaxhighlight lang=apl inline>1</syntaxhighlight>
|}
|}
In the context of logic, it can be read as ''if and only if''. This function is also known as xnor or the Kronecker delta.
In the context of logic, it can be read as ''if and only if''. This function is also known as xnor or the Kronecker delta.


[[Reduction]] with <syntaxhighlight lang=apl inline>=</source> is the same as reduction with xor (<syntaxhighlight lang=apl inline>≠</source>), but [[Not|inverted]] if the number of reduced elements is even. The left and right [[identity element]] for Boolean <syntaxhighlight lang=apl inline>=</source> is 1.
[[Reduction]] with <syntaxhighlight lang=apl inline>=</syntaxhighlight> is the same as reduction with xor (<syntaxhighlight lang=apl inline>≠</syntaxhighlight>), but [[Not|inverted]] if the number of reduced elements is even. The left and right [[identity element]] for Boolean <syntaxhighlight lang=apl inline>=</syntaxhighlight> is 1.


== External links ==
== External links ==

Navigation menu