4,494
edits
(→Documentation: BQN) |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
Line 1: | Line 1: | ||
{{Built-in|Add|+}}, '''Plus''', '''Addition''', or '''Sum''', is a [[dyadic]] [[scalar function]] that [[wikipedia:Addition|adds]] numbers together. As a basic arithmetic operation, Add is subject to the language's [[number]] specification. Add shares the glyph <source lang=apl inline>+</ | {{Built-in|Add|+}}, '''Plus''', '''Addition''', or '''Sum''', is a [[dyadic]] [[scalar function]] that [[wikipedia:Addition|adds]] numbers together. As a basic arithmetic operation, Add is subject to the language's [[number]] specification. Add shares the glyph <source lang=apl inline>+</syntaxhighlight> with the [[monadic]] function [[Conjugate]], and is closely related to [[Subtract]] (<source lang=apl inline>-</syntaxhighlight>). | ||
== Examples == | == Examples == | ||
Line 8: | Line 8: | ||
0.1 + 3 4 5 | 0.1 + 3 4 5 | ||
3.1 4.1 5.1 | 3.1 4.1 5.1 | ||
</ | </syntaxhighlight> | ||
== Properties == | == Properties == | ||
Line 14: | Line 14: | ||
Addition is [[wikipedia:Commutative property|commutative]] in almost all number systems. It is [[wikipedia:Associative property|associative]] when performed with no rounding, but is unlikely to be associative when rounded to an inexact precision (see [[#Floating point error|Floating point error]]). | Addition is [[wikipedia:Commutative property|commutative]] in almost all number systems. It is [[wikipedia:Associative property|associative]] when performed with no rounding, but is unlikely to be associative when rounded to an inexact precision (see [[#Floating point error|Floating point error]]). | ||
The [[identity element]] for Add is <source lang=apl inline>0</ | The [[identity element]] for Add is <source lang=apl inline>0</syntaxhighlight>. The [[inverse]] of the function <source lang=apl inline>n∘+</syntaxhighlight> or the equivalent function <source lang=apl inline>+∘n</syntaxhighlight> is <source lang=apl inline>-∘n</syntaxhighlight>. Using [[Commute]] (<source lang=apl inline>⍨</syntaxhighlight>), we can write <source lang=apl inline>+⍣¯1</syntaxhighlight> {{←→}} <source lang=apl inline>-⍨</syntaxhighlight>. | ||
Since adding a number to itself is equivalent to doubling that number, we can express the ''double'' function as <source lang=apl inline>+⍨</ | Since adding a number to itself is equivalent to doubling that number, we can express the ''double'' function as <source lang=apl inline>+⍨</syntaxhighlight>. | ||
=== Reduction === | === Reduction === | ||
Line 40: | Line 40: | ||
(1e20 + ¯1e20) + 1 ⍝ Not equivalent | (1e20 + ¯1e20) + 1 ⍝ Not equivalent | ||
1 | 1 | ||
</ | </syntaxhighlight> | ||
Addition of floating-point numbers may also be subject to [[overflow]], resulting in a [[DOMAIN ERROR]] or an [[infinite]] result. | Addition of floating-point numbers may also be subject to [[overflow]], resulting in a [[DOMAIN ERROR]] or an [[infinite]] result. |