Comparison with traditional mathematics: Difference between revisions

Jump to navigation Jump to search
m
Text replacement - "</source>" to "</syntaxhighlight>"
Miraheze>Adám Brudzewsky
No edit summary
 
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
APL unifies certain notation for some mathematical constructs, and has a more consistent syntax. Below are some examples comparing traditional mathematical notation (denoted TMN in this article) with equivalent APL. Note that some of these examples only work in certain APL [[dialect]]s.
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 [[dialect]]s.


== Similarities ==
== Similarities ==


APL [[Iverson notation|developed from TMN]], and much of APL will be immediately recognised by a mathematician. Interestingly, it seems that look of the typeface and identifiers (names of variables etc.) used in APL makes a big difference in the perception of the reader. 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">
<source lang=apl inline>((x + y) × (x - y)) = (f ∘ g)(x, y)</source>
<syntaxhighlight lang=apl inline>((x + y) × (x - y)) = (f ∘ g)(x, y)</syntaxhighlight>


<math>((x + y) × (x - y)) = (f g)(x, y)</math>
<math>((x + y) \times (x - y)) = (f \circ g)(x, y)</math>
</div>
</div>
Now note that they are identical, letter for letter. In fact, even the MediaWiki markup code (the language used to define [[APL Wiki]] pages) is identical for the two lines identical, except one is tagged as "source" while the other is tagged as "math". 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.
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]]:
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]]:
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> || <source lang="apl" inline>~ q</source>  || [[Not]]
| <math>\sim q</math>     || <syntaxhighlight lang="apl" inline>~ q</syntaxhighlight>  || [[Not]]
|-
|-
| <math>p∨q</math>     || <source lang="apl" inline>p ∨ q</source> || [[Or]]
| <math>p \vee q</math> || <syntaxhighlight lang="apl" inline>p ∨ q</syntaxhighlight> || [[Or]]
|-
|-
| <math>p∧q</math>     || <source lang="apl" inline>p ∧ q</source> || [[And]]
| <math>p \wedge q</math>   || <syntaxhighlight lang="apl" inline>p ∧ q</syntaxhighlight> || [[And]]
|-
|-
| <math>a×b</math>     || <source lang="apl" inline>a × b</source> || [[Multiply]]
| <math>a \times b</math> || <syntaxhighlight lang="apl" inline>a × b</syntaxhighlight> || [[Multiply]]
|-
|-
| <math>a÷b</math>     || <source lang="apl" inline>a ÷ b</source> || [[Divide]]
| <math>a \div b</math>   || <syntaxhighlight lang="apl" inline>a ÷ b</syntaxhighlight> || [[Divide]]
|-
|-
| <math>a \in S</math> || <source lang="apl" inline>a ∊ S</source> || [[Membership]]
| <math>a \in S</math>   || <syntaxhighlight lang="apl" inline>a ∊ S</syntaxhighlight> || [[Membership]]
|-
|-
| <math>A B</math>  || <source lang="apl" inline>A ∪ B</source> || [[Union]]
| <math>A \cup B</math>  || <syntaxhighlight lang="apl" inline>A ∪ B</syntaxhighlight> || [[Union]]
|-
|-
| <math>A B</math>  || <source lang="apl" inline>A ∩ B</source> || [[Intersection]]
| <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≡b]</math>   || <source lang="apl" inline>(a ≡ b)</source>    || <source lang="apl" inline>a ≡ b</source>  || [[Match]]
| <math>[a \equiv b]</math>   || <syntaxhighlight lang="apl" inline>(a ≡ b)</syntaxhighlight>    || <syntaxhighlight lang="apl" inline>a ≡ b</syntaxhighlight>  || [[Match]]
|-
|-
| <math>[a=b]</math>   || <source lang="apl" inline>(a = b)</source>    || <source lang="apl" inline>a = b</source>  || [[Equal]]
| <math>[a=b]</math>         || <syntaxhighlight lang="apl" inline>(a = b)</syntaxhighlight>    || <syntaxhighlight lang="apl" inline>a = b</syntaxhighlight>  || [[Equal]]
|-
|-
| <math>[a≠b]</math>   || <source lang="apl" inline>(a ≠ b)</source>    || <source lang="apl" inline>a ≠ b</source>  || [[Not Equal]]
| <math>[a \ne b]</math>     || <syntaxhighlight lang="apl" inline>(a ≠ b)</syntaxhighlight>    || <syntaxhighlight lang="apl" inline>a ≠ b</syntaxhighlight>  || [[Not Equal]]
|-
|-
| <math>[a≤b]</math>   || <source lang="apl" inline>(a ≤ b)</source>    || <source lang="apl" inline>a ≤ b</source>  || [[Less Than or Equal]]
| <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∘g)(x)</math> || <source lang="apl" inline>(f ∘ g)(x)</source> || <source lang="apl" inline>f ∘ g x</source> || [[Bind]]
| <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> || <source lang="apl" inline>f(g(x))</source>    || <source lang="apl" inline>f g x</source>  ||
| <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> || <source lang="apl" inline>(f+g)(x)</source>  || <source lang="apl" inline>(f+g) x</source> || [[Train]]s
| <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> || <source lang="apl" inline>○n</source> || [[Pi Times]]
| <math>n \pi</math>             || <syntaxhighlight lang="apl" inline>○n</syntaxhighlight> || [[Pi Times]]
|-
|-
| <math>x!</math>   || <source lang="apl" inline>!x</source> || [[Factorial]]
| <math>x!</math>               || <syntaxhighlight lang="apl" inline>!x</syntaxhighlight> || [[Factorial]]
|-
|-
| <math>|x|</math>   || <source lang="apl" inline>|x</source> || [[Magnitude]]
| <math>|x|</math>               || <syntaxhighlight lang="apl" inline>|x</syntaxhighlight> || [[Magnitude]]
|-
|-
| <math>⌈x⌉</math>  || <source lang="apl" inline>⌈x</source> || [[Ceiling]]
| <math>\lceil x \rceil</math>  || <syntaxhighlight lang="apl" inline>⌈x</syntaxhighlight> || [[Ceiling]]
|-
|-
| <math>⌊x⌋</math>   || <source lang="apl" inline>⌊x</source> || [[Floor]]
| <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>            || <source lang="apl" inline>a×b</source>    || [[Multiply]]
| <math>ab</math>            || <syntaxhighlight lang="apl" inline>a×b</syntaxhighlight>    || [[Multiply]]
|-
|-
| <math>e^x</math>          || <source lang="apl" inline> *x</source>    || [[Exponential]]
| <math>e^x</math>          || <syntaxhighlight lang="apl" inline> *x</syntaxhighlight>    || [[Exponential]]
|-
|-
| <math>a^b</math>          || <source lang="apl" inline>a*b</source>    || [[Power]]
| <math>a^b</math>          || <syntaxhighlight lang="apl" inline>a*b</syntaxhighlight>    || [[Power]]
|-
|-
| <math>\sqrt[a]{b}</math>  || <source lang="apl" inline>a√b</source>    || [[Root]]
| <math>\sqrt[a]{b}</math>  || <syntaxhighlight lang="apl" inline>a√b</syntaxhighlight>    || [[Root]]
|-
|-
| <math>\tbinom{n}{k}</math> || <source lang="apl" inline>k!n</source>    || [[Binomial]]
| <math>\tbinom{n}{k}</math> || <syntaxhighlight lang="apl" inline>k!n</syntaxhighlight>    || [[Binomial]]
|-
|-
| <math>f^n(x)</math>        || <source lang="apl" inline>(f⍣a) x</source> || [[Power operator]]
| <math>f^n(x)</math>        || <syntaxhighlight lang="apl" inline>(f⍣n) x</syntaxhighlight> || [[Power operator]]
|-
|-
| <math>\sin^n(x)</math>    || <source lang="apl" inline>(1○x)*n</source> || [[Circle function]]
| <math>\sin^n(x)</math>    || <syntaxhighlight lang="apl" inline>(1○x)*n</syntaxhighlight> || [[Circle function]]
|-
| <math>a\cdot b</math>      || <syntaxhighlight lang="apl" inline>a+.×b</syntaxhighlight>  || [[Inner product]]
|}
|}


Line 106: 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>            || <source lang="apl" inline>(f⍣a) x</source>          || [[Power operator]]
| <math>f^n(x)</math>            || <syntaxhighlight lang="apl" inline>(f⍣n) x</syntaxhighlight>          || [[Power operator]]
|-
|-
| <math>\sin^n(x)</math>          || <source lang="apl" inline>(1○x)*n</source>          || [[Circle function]]
| <math>\sin^n(x)</math>          || <syntaxhighlight lang="apl" inline>(1○x)*n</syntaxhighlight>          || [[Circle function]]
|-
|-
| <math>a\pm b</math>            || <source lang="apl" inline>a(+,-)b</source>          || [[Train]]s
| <math>a\pm b</math>            || <syntaxhighlight lang="apl" inline>a(+,-)b</syntaxhighlight>          || [[Train]]s
|-
|-
| <math>a\mp b</math>            || <source lang="apl" inline>a(-,+)b</source>          || [[Train]]s
| <math>a\mp b</math>            || <syntaxhighlight lang="apl" inline>a(-,+)b</syntaxhighlight>          || [[Train]]s
|-
|-
| <math>\frac{a}{b}</math>        || <source lang="apl" inline>a÷b</source>              || [[Divide]]
| <math>\frac{a}{b}</math>        || <syntaxhighlight lang="apl" inline>a÷b</syntaxhighlight>              || [[Divide]]
|-
|-
| <math>e^x</math>                || <source lang="apl" inline> *x</source>              || [[Exponential]]
| <math>e^x</math>                || <syntaxhighlight lang="apl" inline> *x</syntaxhighlight>              || [[Exponential]]
|-
|-
| <math>a^b</math>                || <source lang="apl" inline>a*b</source>              || [[Power function]]
| <math>a^b</math>                || <syntaxhighlight lang="apl" inline>a*b</syntaxhighlight>              || [[Power function]]
|-
|-
| <math>\log_a{b}</math>          || <source lang="apl" inline>a⍟b</source>              || [[Logarithm]]
| <math>\log_a{b}</math>          || <syntaxhighlight lang="apl" inline>a⍟b</syntaxhighlight>              || [[Logarithm]]
|-
|-
| <math>\sqrt[a]{b}</math>        || <source lang="apl" inline>a√b</source>              || [[Root]]
| <math>\sqrt[a]{b}</math>        || <syntaxhighlight lang="apl" inline>a√b</syntaxhighlight>              || [[Root]]
|-
|-
| <math>\tbinom{n}{k}</math>      || <source lang="apl" inline>k!n</source>              || [[Binomial]]
| <math>\tbinom{n}{k}</math>      || <syntaxhighlight lang="apl" inline>k!n</syntaxhighlight>              || [[Binomial]]
|-
|-
| <math>\left\{
| <math>\left\{
Line 130: 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>      || <source lang="apl">{p x: a  
   \end{array}\right.</math>      || <syntaxhighlight lang="apl">{p x: a  
  q x: b}</source> || [[dfn]]s
  q x: b}</syntaxhighlight> || [[dfn]]s
|-
|-
| <math>\sum_{i=1}^{N} v_i</math> || <source lang="apl" inline>+/v</source>              || [[Reduce]]
| <math>\sum_{i=1}^{N} v_i</math> || <syntaxhighlight lang="apl" inline>+/v</syntaxhighlight>              || [[Reduce]]
|-
|-
| <math>\sum_{n=1}^{N} n</math>  || <source lang="apl" inline>+/⍳N</source>              || [[Reduce]], [[Iota]]
| <math>\sum_{n=1}^{N} n</math>  || <syntaxhighlight lang="apl" inline>+/⍳N</syntaxhighlight>              || [[Reduce]], [[Iota]]
|-
|-
| <math>\prod_{n=1}^{N} n</math>  || <source lang="apl" inline>×/⍳N</source>              || [[Reduce]], [[Iota]]
| <math>\prod_{n=1}^{N} n</math>  || <syntaxhighlight lang="apl" inline>×/⍳N</syntaxhighlight>              || [[Reduce]], [[Iota]]
|}
|}


Line 147: 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>                || <source lang="apl" inline> *x</source>              || [[Exponential]]
| <math>e^x</math>                || <syntaxhighlight lang="apl" inline> *x</syntaxhighlight>              || [[Exponential]]
|-
|-
| <math>\ln{x}</math>            || <source lang="apl" inline> ⍟b</source>              || [[Natural Logarithm]]
| <math>\ln{x}</math>            || <syntaxhighlight lang="apl" inline> ⍟b</syntaxhighlight>              || [[Natural Logarithm]]
|-
|-
| <math>\log_a{b}</math>          || <source lang="apl" inline>a⍟b</source>              || [[Logarithm]]
| <math>\log_a{b}</math>          || <syntaxhighlight lang="apl" inline>a⍟b</syntaxhighlight>              || [[Logarithm]]
|-
|-
| <math>a \mod b</math>          || <source lang="apl" inline>b|a</source>              || [[Modulus]]
| <math>a \bmod b</math>          || <syntaxhighlight lang="apl" inline>b|a</syntaxhighlight>              || [[Modulus]]
|-
|-
| <math>\left\{
| <math>\left\{
Line 159: 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>      || <source lang="apl">{p x: a  
   \end{array}\right.</math>      || <syntaxhighlight lang="apl">{p x: a  
  q x: b}</source> || [[dfn]]s
  q x: b}</syntaxhighlight> || [[dfn]]s
|-
|-
| <math>\text{let } n=42</math>  || <source lang="apl" inline>n←42</source>              || [[Assignment]]
| <math>\text{let } n=42</math>  || <syntaxhighlight lang="apl" inline>n←42</syntaxhighlight>              || [[Assignment]]
|}
|}


Line 172: Line 174:
! style="width:50%" | Traditional notation !! APL
! style="width:50%" | Traditional notation !! APL
|-
|-
| <math>\sum_{i=1}^{N} v_i</math> || <source lang="apl" inline>+/ v  </source>
| <math>\sum_{i=1}^{N} v_i</math> || <syntaxhighlight lang="apl" inline>+/ v  </syntaxhighlight>
|-
|-
| <math>\sum_{n=1}^{N} n</math>  || <source lang="apl" inline>+/ ⍳N </source>
| <math>\sum_{n=1}^{N} n</math>  || <syntaxhighlight lang="apl" inline>+/ ⍳N </syntaxhighlight>
|-
|-
| <math>\prod_{n=1}^{N} n</math>  || <source lang="apl" inline>×/ ⍳N </source>
| <math>\prod_{n=1}^{N} n</math>  || <syntaxhighlight lang="apl" inline>×/ ⍳N </syntaxhighlight>
|-
|-
| <math>x, P(x)</math>         || <source lang="apl" inline>∧/P(x)</source>
| <math>\forall x, P(x)</math>   || <syntaxhighlight lang="apl" inline>∧/P(x)</syntaxhighlight>
|-
|-
| <math>x, P(x)</math>         || <source lang="apl" inline>∨/P(x)</source>
| <math>\exists x, P(x)</math>   || <syntaxhighlight lang="apl" inline>∨/P(x)</syntaxhighlight>
|}
|}
 
== Practical example ==
{{APL syntax}}
The steps to produce the component of a vector <math>\textbf{a}</math> in the direction of another vector <math>\textbf{b}</math> go as follows:
<div style="text-align:center">
{| class="wikitable c" style="margin: 1em auto 1em auto"
! style="width:50%" | Traditional notation !! APL
|-
| <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>  ||  <syntaxhighlight lang=apl>bHat ← b ÷ bNorm</syntaxhighlight>
|-
| <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>
{{APL syntax}}[[Category:Essays]]

Navigation menu