Comparison with traditional mathematics: Difference between revisions
(+.×) |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
APL [[Iverson notation|developed from TMN]], and much of APL will be immediately recognised by a mathematician. Interestingly, it seems that the look of the typeface and identifiers (names of variables etc.) used in APL makes a big difference in the reader's perception. A fixed-width typewriter-style font with long identifiers gives the impression of computer source code, while an italic serif typeface and single-letter identifiers gives the impression of scientific formulae. Compare the impression you get when reading the following two expressions which is both valid APL (though it has superfluous parentheses) and traditional mathematics: | APL [[Iverson notation|developed from TMN]], and much of APL will be immediately recognised by a mathematician. Interestingly, it seems that the look of the typeface and identifiers (names of variables etc.) used in APL makes a big difference in the reader's perception. A fixed-width typewriter-style font with long identifiers gives the impression of computer source code, while an italic serif typeface and single-letter identifiers gives the impression of scientific formulae. Compare the impression you get when reading the following two expressions which is both valid APL (though it has superfluous parentheses) and traditional mathematics: | ||
<div style="text-align:center"> | <div style="text-align:center"> | ||
< | <syntaxhighlight lang=apl inline>((x + y) × (x - y)) = (f ∘ g)(x, y)</syntaxhighlight> | ||
<math>((x + y) \times (x - y)) = (f \circ g)(x, y)</math> | <math>((x + y) \times (x - y)) = (f \circ g)(x, y)</math> | ||
Line 18: | Line 18: | ||
! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ||
|- | |- | ||
| <math>\sim q</math> || < | | <math>\sim q</math> || <syntaxhighlight lang="apl" inline>~ q</syntaxhighlight> || [[Not]] | ||
|- | |- | ||
| <math>p \vee q</math> || < | | <math>p \vee q</math> || <syntaxhighlight lang="apl" inline>p ∨ q</syntaxhighlight> || [[Or]] | ||
|- | |- | ||
| <math>p \wedge q</math> || < | | <math>p \wedge q</math> || <syntaxhighlight lang="apl" inline>p ∧ q</syntaxhighlight> || [[And]] | ||
|- | |- | ||
| <math>a \times b</math> || < | | <math>a \times b</math> || <syntaxhighlight lang="apl" inline>a × b</syntaxhighlight> || [[Multiply]] | ||
|- | |- | ||
| <math>a \div b</math> || < | | <math>a \div b</math> || <syntaxhighlight lang="apl" inline>a ÷ b</syntaxhighlight> || [[Divide]] | ||
|- | |- | ||
| <math>a \in S</math> || < | | <math>a \in S</math> || <syntaxhighlight lang="apl" inline>a ∊ S</syntaxhighlight> || [[Membership]] | ||
|- | |- | ||
| <math>A \cup B</math> || < | | <math>A \cup B</math> || <syntaxhighlight lang="apl" inline>A ∪ B</syntaxhighlight> || [[Union]] | ||
|- | |- | ||
| <math>A \cap B</math> || < | | <math>A \cap B</math> || <syntaxhighlight lang="apl" inline>A ∩ B</syntaxhighlight> || [[Intersection]] | ||
|} | |} | ||
Line 42: | Line 42: | ||
! style="width:25%" | Traditional notation !! style="width:25%" | <small>Parenthesised<br></small>APL !! style="width:25%" | <small>Normal<br></small>APL !! Article | ! style="width:25%" | Traditional notation !! style="width:25%" | <small>Parenthesised<br></small>APL !! style="width:25%" | <small>Normal<br></small>APL !! Article | ||
|- | |- | ||
| <math>[a \equiv b]</math> || < | | <math>[a \equiv b]</math> || <syntaxhighlight lang="apl" inline>(a ≡ b)</syntaxhighlight> || <syntaxhighlight lang="apl" inline>a ≡ b</syntaxhighlight> || [[Match]] | ||
|- | |- | ||
| <math>[a=b]</math> || < | | <math>[a=b]</math> || <syntaxhighlight lang="apl" inline>(a = b)</syntaxhighlight> || <syntaxhighlight lang="apl" inline>a = b</syntaxhighlight> || [[Equal]] | ||
|- | |- | ||
| <math>[a \ne b]</math> || < | | <math>[a \ne b]</math> || <syntaxhighlight lang="apl" inline>(a ≠ b)</syntaxhighlight> || <syntaxhighlight lang="apl" inline>a ≠ b</syntaxhighlight> || [[Not Equal]] | ||
|- | |- | ||
| <math>[a \le b]</math> || < | | <math>[a \le b]</math> || <syntaxhighlight lang="apl" inline>(a ≤ b)</syntaxhighlight> || <syntaxhighlight lang="apl" inline>a ≤ b</syntaxhighlight> || [[Less Than or Equal]] | ||
|- | |- | ||
| <math>(f \circ g)(x)</math> || < | | <math>(f \circ g)(x)</math> || <syntaxhighlight lang="apl" inline>(f ∘ g)(x)</syntaxhighlight> || <syntaxhighlight lang="apl" inline>f ∘ g x</syntaxhighlight> || [[Bind]] | ||
|- | |- | ||
| <math>f(g(x))</math> || < | | <math>f(g(x))</math> || <syntaxhighlight lang="apl" inline>f(g(x))</syntaxhighlight> || <syntaxhighlight lang="apl" inline>f g x</syntaxhighlight> || | ||
|- | |- | ||
| <math>(f+g)(x)</math> || < | | <math>(f+g)(x)</math> || <syntaxhighlight lang="apl" inline>(f+g)(x)</syntaxhighlight> || <syntaxhighlight lang="apl" inline>(f+g) x</syntaxhighlight> || [[Train]]s | ||
|} | |} | ||
Line 68: | Line 68: | ||
! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ||
|- | |- | ||
| <math>n \pi</math> || < | | <math>n \pi</math> || <syntaxhighlight lang="apl" inline>○n</syntaxhighlight> || [[Pi Times]] | ||
|- | |- | ||
| <math>x!</math> || < | | <math>x!</math> || <syntaxhighlight lang="apl" inline>!x</syntaxhighlight> || [[Factorial]] | ||
|- | |- | ||
| <math>|x|</math> || < | | <math>|x|</math> || <syntaxhighlight lang="apl" inline>|x</syntaxhighlight> || [[Magnitude]] | ||
|- | |- | ||
| <math>\lceil x \rceil</math> || < | | <math>\lceil x \rceil</math> || <syntaxhighlight lang="apl" inline>⌈x</syntaxhighlight> || [[Ceiling]] | ||
|- | |- | ||
| <math>\lfloor x \rfloor</math> || < | | <math>\lfloor x \rfloor</math> || <syntaxhighlight lang="apl" inline>⌊x</syntaxhighlight> || [[Floor]] | ||
|} | |} | ||
Line 85: | Line 85: | ||
! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ||
|- | |- | ||
| <math>ab</math> || < | | <math>ab</math> || <syntaxhighlight lang="apl" inline>a×b</syntaxhighlight> || [[Multiply]] | ||
|- | |- | ||
| <math>e^x</math> || < | | <math>e^x</math> || <syntaxhighlight lang="apl" inline> *x</syntaxhighlight> || [[Exponential]] | ||
|- | |- | ||
| <math>a^b</math> || < | | <math>a^b</math> || <syntaxhighlight lang="apl" inline>a*b</syntaxhighlight> || [[Power]] | ||
|- | |- | ||
| <math>\sqrt[a]{b}</math> || < | | <math>\sqrt[a]{b}</math> || <syntaxhighlight lang="apl" inline>a√b</syntaxhighlight> || [[Root]] | ||
|- | |- | ||
| <math>\tbinom{n}{k}</math> || < | | <math>\tbinom{n}{k}</math> || <syntaxhighlight lang="apl" inline>k!n</syntaxhighlight> || [[Binomial]] | ||
|- | |- | ||
| <math>f^n(x)</math> || < | | <math>f^n(x)</math> || <syntaxhighlight lang="apl" inline>(f⍣n) x</syntaxhighlight> || [[Power operator]] | ||
|- | |- | ||
| <math>\sin^n(x)</math> || < | | <math>\sin^n(x)</math> || <syntaxhighlight lang="apl" inline>(1○x)*n</syntaxhighlight> || [[Circle function]] | ||
|- | |- | ||
| <math>a\cdot b</math> || < | | <math>a\cdot b</math> || <syntaxhighlight lang="apl" inline>a+.×b</syntaxhighlight> || [[Inner product]] | ||
|} | |} | ||
Line 108: | Line 108: | ||
! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ||
|- | |- | ||
| <math>f^n(x)</math> || < | | <math>f^n(x)</math> || <syntaxhighlight lang="apl" inline>(f⍣n) x</syntaxhighlight> || [[Power operator]] | ||
|- | |- | ||
| <math>\sin^n(x)</math> || < | | <math>\sin^n(x)</math> || <syntaxhighlight lang="apl" inline>(1○x)*n</syntaxhighlight> || [[Circle function]] | ||
|- | |- | ||
| <math>a\pm b</math> || < | | <math>a\pm b</math> || <syntaxhighlight lang="apl" inline>a(+,-)b</syntaxhighlight> || [[Train]]s | ||
|- | |- | ||
| <math>a\mp b</math> || < | | <math>a\mp b</math> || <syntaxhighlight lang="apl" inline>a(-,+)b</syntaxhighlight> || [[Train]]s | ||
|- | |- | ||
| <math>\frac{a}{b}</math> || < | | <math>\frac{a}{b}</math> || <syntaxhighlight lang="apl" inline>a÷b</syntaxhighlight> || [[Divide]] | ||
|- | |- | ||
| <math>e^x</math> || < | | <math>e^x</math> || <syntaxhighlight lang="apl" inline> *x</syntaxhighlight> || [[Exponential]] | ||
|- | |- | ||
| <math>a^b</math> || < | | <math>a^b</math> || <syntaxhighlight lang="apl" inline>a*b</syntaxhighlight> || [[Power function]] | ||
|- | |- | ||
| <math>\log_a{b}</math> || < | | <math>\log_a{b}</math> || <syntaxhighlight lang="apl" inline>a⍟b</syntaxhighlight> || [[Logarithm]] | ||
|- | |- | ||
| <math>\sqrt[a]{b}</math> || < | | <math>\sqrt[a]{b}</math> || <syntaxhighlight lang="apl" inline>a√b</syntaxhighlight> || [[Root]] | ||
|- | |- | ||
| <math>\tbinom{n}{k}</math> || < | | <math>\tbinom{n}{k}</math> || <syntaxhighlight lang="apl" inline>k!n</syntaxhighlight> || [[Binomial]] | ||
|- | |- | ||
| <math>\left\{ | | <math>\left\{ | ||
Line 132: | Line 132: | ||
a, & \text{if } p(x) \\ | a, & \text{if } p(x) \\ | ||
b, & \text{if } q(x) | b, & \text{if } q(x) | ||
\end{array}\right.</math> || < | \end{array}\right.</math> || <syntaxhighlight lang="apl">{p x: a | ||
q x: b}</ | q x: b}</syntaxhighlight> || [[dfn]]s | ||
|- | |- | ||
| <math>\sum_{i=1}^{N} v_i</math> || < | | <math>\sum_{i=1}^{N} v_i</math> || <syntaxhighlight lang="apl" inline>+/v</syntaxhighlight> || [[Reduce]] | ||
|- | |- | ||
| <math>\sum_{n=1}^{N} n</math> || < | | <math>\sum_{n=1}^{N} n</math> || <syntaxhighlight lang="apl" inline>+/⍳N</syntaxhighlight> || [[Reduce]], [[Iota]] | ||
|- | |- | ||
| <math>\prod_{n=1}^{N} n</math> || < | | <math>\prod_{n=1}^{N} n</math> || <syntaxhighlight lang="apl" inline>×/⍳N</syntaxhighlight> || [[Reduce]], [[Iota]] | ||
|} | |} | ||
Line 149: | Line 149: | ||
! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ! style="width:33%" | Traditional notation !! style="width:33%" | APL !! Article | ||
|- | |- | ||
| <math>e^x</math> || < | | <math>e^x</math> || <syntaxhighlight lang="apl" inline> *x</syntaxhighlight> || [[Exponential]] | ||
|- | |- | ||
| <math>\ln{x}</math> || < | | <math>\ln{x}</math> || <syntaxhighlight lang="apl" inline> ⍟b</syntaxhighlight> || [[Natural Logarithm]] | ||
|- | |- | ||
| <math>\log_a{b}</math> || < | | <math>\log_a{b}</math> || <syntaxhighlight lang="apl" inline>a⍟b</syntaxhighlight> || [[Logarithm]] | ||
|- | |- | ||
| <math>a \bmod b</math> || < | | <math>a \bmod b</math> || <syntaxhighlight lang="apl" inline>b|a</syntaxhighlight> || [[Modulus]] | ||
|- | |- | ||
| <math>\left\{ | | <math>\left\{ | ||
Line 161: | Line 161: | ||
a, & \text{if } p(x) \\ | a, & \text{if } p(x) \\ | ||
b, & \text{if } q(x) | b, & \text{if } q(x) | ||
\end{array}\right.</math> || < | \end{array}\right.</math> || <syntaxhighlight lang="apl">{p x: a | ||
q x: b}</ | q x: b}</syntaxhighlight> || [[dfn]]s | ||
|- | |- | ||
| <math>\text{let } n=42</math> || < | | <math>\text{let } n=42</math> || <syntaxhighlight lang="apl" inline>n←42</syntaxhighlight> || [[Assignment]] | ||
|} | |} | ||
Line 174: | Line 174: | ||
! style="width:50%" | Traditional notation !! APL | ! style="width:50%" | Traditional notation !! APL | ||
|- | |- | ||
| <math>\sum_{i=1}^{N} v_i</math> || < | | <math>\sum_{i=1}^{N} v_i</math> || <syntaxhighlight lang="apl" inline>+/ v </syntaxhighlight> | ||
|- | |- | ||
| <math>\sum_{n=1}^{N} n</math> || < | | <math>\sum_{n=1}^{N} n</math> || <syntaxhighlight lang="apl" inline>+/ ⍳N </syntaxhighlight> | ||
|- | |- | ||
| <math>\prod_{n=1}^{N} n</math> || < | | <math>\prod_{n=1}^{N} n</math> || <syntaxhighlight lang="apl" inline>×/ ⍳N </syntaxhighlight> | ||
|- | |- | ||
| <math>\forall x, P(x)</math> || < | | <math>\forall x, P(x)</math> || <syntaxhighlight lang="apl" inline>∧/P(x)</syntaxhighlight> | ||
|- | |- | ||
| <math>\exists x, P(x)</math> || < | | <math>\exists x, P(x)</math> || <syntaxhighlight lang="apl" inline>∨/P(x)</syntaxhighlight> | ||
|} | |} | ||
== Practical example == | == Practical example == | ||
Line 190: | Line 190: | ||
! style="width:50%" | Traditional notation !! APL | ! style="width:50%" | Traditional notation !! APL | ||
|- | |- | ||
| <math>|\textbf{b}|=\sqrt[2]{\textbf{b}\cdot\textbf{b}}</math> || < | | <math>|\textbf{b}|=\sqrt[2]{\textbf{b}\cdot\textbf{b}}</math> || <syntaxhighlight lang=apl>bNorm ← 2 Root b +.× b</syntaxhighlight> | ||
|- | |- | ||
| <math>\hat{\textbf{b}} = \textbf{b}\div|\textbf{b}|</math> || < | | <math>\hat{\textbf{b}} = \textbf{b}\div|\textbf{b}|</math> || <syntaxhighlight lang=apl>bHat ← b ÷ bNorm</syntaxhighlight> | ||
|- | |- | ||
| <math>\textbf{a}_\textbf{b}=(\textbf{a}\cdot\hat{\textbf{b}})\hat{\textbf{b}}</math> || < | | <math>\textbf{a}_\textbf{b}=(\textbf{a}\cdot\hat{\textbf{b}})\hat{\textbf{b}}</math> || <syntaxhighlight lang=apl>a_b ← (a +.× bHat) × bHat</syntaxhighlight> | ||
|} | |} | ||
</div> | </div> | ||
{{APL syntax}}[[Category:Essays]] | {{APL syntax}}[[Category:Essays]] |
Latest revision as of 22:22, 10 September 2022
APL unifies the notations for certain mathematical constructs, while having a more consistent syntax. Below are some examples comparing traditional mathematical notation (denoted TMN in this article) with the equivalent APL. Note that some of these examples only work in certain APL dialects.
Similarities
APL developed from TMN, and much of APL will be immediately recognised by a mathematician. Interestingly, it seems that the look of the typeface and identifiers (names of variables etc.) used in APL makes a big difference in the reader's perception. A fixed-width typewriter-style font with long identifiers gives the impression of computer source code, while an italic serif typeface and single-letter identifiers gives the impression of scientific formulae. Compare the impression you get when reading the following two expressions which is both valid APL (though it has superfluous parentheses) and traditional mathematics:
((x + y) × (x - y)) = (f ∘ g)(x, y)
Now note that they are identical, letter for letter. Computer Scientists tend to have great difficulty in approaching APL until they let go of the notion that APL is just another programming language (despite its name!) and instead look at it as an executable mathematical notation.
It is notable that APL traditionally was written with a font wherein letters were always italicised, while everything else wasn't. Here is how it looks in the default font for SAX:
Identical
For many basic operations, APL is identical to TMN:
Traditional notation | APL | Article |
---|---|---|
~ q |
Not | |
p ∨ q |
Or | |
p ∧ q |
And | |
a × b |
Multiply | |
a ÷ b |
Divide | |
a ∊ S |
Membership | |
A ∪ B |
Union | |
A ∩ B |
Intersection |
Redundant brackets and parentheses
Often, the only difference is that APL allows omitting brackets or parenthesis. This is because the Iverson bracket is implied and functions have long right scope.
Traditional notation | Parenthesised APL |
Normal APL |
Article |
---|---|---|---|
(a ≡ b) |
a ≡ b |
Match | |
(a = b) |
a = b |
Equal | |
(a ≠ b) |
a ≠ b |
Not Equal | |
(a ≤ b) |
a ≤ b |
Less Than or Equal | |
(f ∘ g)(x) |
f ∘ g x |
Bind | |
f(g(x)) |
f g x |
||
(f+g)(x) |
(f+g) x |
Trains |
Differences
While based on TMN, APL goes a long way to harmonise and generalise its notation.
Prefix
In APL, all functions that only take a single argument are placed to the immediate left of their argument. TMN uses prefix, omnifix, and suffix notations.
Traditional notation | APL | Article |
---|---|---|
○n |
Pi Times | |
!x |
Factorial | |
|x |
Magnitude | |
⌈x |
Ceiling | |
⌊x |
Floor |
Explicitness
APL writes out all functions explicitly while TMN often implies functions by argument positioning without giving the function an explicit symbol.
Traditional notation | APL | Article |
---|---|---|
a×b |
Multiply | |
*x |
Exponential | |
a*b |
Power | |
a√b |
Root | |
k!n |
Binomial | |
(f⍣n) x |
Power operator | |
(1○x)*n |
Circle function | |
a+.×b |
Inner product |
Linearity
APL is strictly linear in the sense that it is written as single lines of uniformly sized and positioned characters, as opposed to TMN which often uses font size and/or position to give meaning.
Traditional notation | APL | Article |
---|---|---|
(f⍣n) x |
Power operator | |
(1○x)*n |
Circle function | |
a(+,-)b |
Trains | |
a(-,+)b |
Trains | |
a÷b |
Divide | |
*x |
Exponential | |
a*b |
Power function | |
a⍟b |
Logarithm | |
a√b |
Root | |
k!n |
Binomial | |
{p x: a q x: b} |
dfns | |
+/v |
Reduce | |
+/⍳N |
Reduce, Iota | |
×/⍳N |
Reduce, Iota |
Named functions
APL has no reserved words, and user defined names can have multiple characters. TMN uses multi-character names for many functions and uses many ad-hoc control words.
Traditional notation | APL | Article |
---|---|---|
*x |
Exponential | |
⍟b |
Natural Logarithm | |
a⍟b |
Logarithm | |
b|a |
Modulus | |
{p x: a q x: b} |
dfns | |
n←42 |
Assignment |
Other differences
APL harmonises and generalises all folding and dispenses with TMN's counting variables. Every one of the following calculations is a reduction.
Traditional notation | APL |
---|---|
+/ v
| |
+/ ⍳N
| |
×/ ⍳N
| |
∧/P(x)
| |
∨/P(x)
|
Practical example
The steps to produce the component of a vector in the direction of another vector go as follows:
Traditional notation | APL |
---|---|
bNorm ← 2 Root b +.× b | |
bHat ← b ÷ bNorm | |
a_b ← (a +.× bHat) × bHat |