1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
<head>
<link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link href="../style.css" rel="stylesheet"/>
<title>BQN Logic functions: And, Or, Not (also Span)</title>
</head>
<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">doc</a></div>
<h1 id="logic-functions-and-or-not-also-span"><a class="header" href="#logic-functions-and-or-not-also-span">Logic functions: And, Or, Not (also Span)</a></h1>
<p>BQN uses the mathematical symbols <code><span class='Function'>∧</span></code> for logical <em>and</em>, <code><span class='Function'>∨</span></code> for <em>or</em>, and <code><span class='Function'>¬</span></code> for <em>not</em>. That is, on booleans the result of <code><span class='Function'>∧</span></code> is 1 if both arguments are 1, and <code><span class='Function'>∨</span></code> is 1 if any argument is 1. <code><span class='Function'>¬</span></code> flips its argument, returning 1 if the argument is 0 and 0 if it's 1. The logic functions are also considered <a href="arithmetic.html">arithmetic</a> and thus are <a href="arithmetic.html#pervasion">pervasive</a>.</p>
<table>
<thead>
<tr>
<th align="center"><code><span class='Value'>𝕨</span></code></th>
<th align="center"><code><span class='Value'>𝕩</span></code></th>
<th align="center"><code><span class='Value'>𝕨</span><span class='Function'>∧</span><span class='Value'>𝕩</span></code></th>
<th align="center"><code><span class='Value'>𝕨</span><span class='Function'>∨</span><span class='Value'>𝕩</span></code></th>
<th align="center"><code><span class='Function'>¬</span><span class='Value'>𝕩</span></code></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">0</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center"></td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center"></td>
</tr>
</tbody>
</table>
<p>The three logic functions are extended linearly to apply to all numbers. This means Not returns <code><span class='Number'>1</span><span class='Function'>-</span><span class='Value'>𝕩</span></code>, and And returns <code><span class='Value'>𝕨</span><span class='Function'>×</span><span class='Value'>𝕩</span></code>. Or does a more complicated computation <code><span class='Value'>𝕨</span><span class='Function'>×</span><span class='Modifier2'>⌾</span><span class='Function'>¬</span><span class='Value'>𝕩</span></code> or <code><span class='Value'>𝕨</span><span class='Paren'>(</span><span class='Function'>+-×</span><span class='Paren'>)</span><span class='Value'>𝕩</span></code>.</p>
<p>Both valences of <code><span class='Function'>¬</span></code> can be written as a <a href="train.html">fork</a> <code><span class='Number'>1</span><span class='Function'>+-</span></code>. The dyadic one, Span, computes the number of integers in the range from <code><span class='Value'>𝕩</span></code> to <code><span class='Value'>𝕨</span></code>, inclusive, when both arguments are integers and <code><span class='Value'>𝕩</span><span class='Function'>≤</span><span class='Value'>𝕨</span></code> (the reversed order is used for consistency with subtraction). It often shows up in connection with the <a href="windows.html">Windows</a> function.</p>
<h2 id="examples"><a class="header" href="#examples">Examples</a></h2>
<p>And, Or, and Not can often be thought of as connecting logical statements together. So <code><span class='Paren'>(</span><span class='Value'>n</span><span class='Function'><</span><span class='Number'>1</span><span class='Paren'>)</span> <span class='Function'>∨</span> <span class='Value'>n</span><span class='Function'>></span><span class='Number'>3</span></code> tests whether one of the two statements <code><span class='Value'>n</span><span class='Function'><</span><span class='Number'>1</span></code> or <code><span class='Value'>n</span><span class='Function'>></span><span class='Number'>3</span></code> holds.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=biDihpAgNAoKKG48MSkg4ouIIG4+MyAgIyBPbmUgZmFsc2UsIG9uZSB0cnVlCgoobjwxKSDiiKggbj4z">↗️</a><pre> <span class='Value'>n</span> <span class='Gets'>←</span> <span class='Number'>4</span>
<span class='Paren'>(</span><span class='Value'>n</span><span class='Function'><</span><span class='Number'>1</span><span class='Paren'>)</span> <span class='Function'>⋈</span> <span class='Value'>n</span><span class='Function'>></span><span class='Number'>3</span> <span class='Comment'># One false, one true
</span>⟨ 0 1 ⟩
<span class='Paren'>(</span><span class='Value'>n</span><span class='Function'><</span><span class='Number'>1</span><span class='Paren'>)</span> <span class='Function'>∨</span> <span class='Value'>n</span><span class='Function'>></span><span class='Number'>3</span>
1
</pre>
<p>Of course, what actually happens is that those expressions are evaluated and the primitive acts on the results (both sides are always evaluated: there's nothing like the shortcutting of <code><span class='Value'>&&</span></code> in some languages). Functions can be used more flexibly: for example, the <a href="fold.html">fold</a> <code><span class='Function'>∧</span><span class='Modifier'>´</span></code> indicates whether all values in a list are true, while <code><span class='Function'>∨</span><span class='Modifier'>´</span></code> indicates if any is true.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oinwrQgMeKAvzHigL8x4oC/MeKAvzEK4oinwrQgMeKAvzHigL8x4oC/MOKAvzE=">↗️</a><pre> <span class='Function'>∧</span><span class='Modifier'>´</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span>
1
<span class='Function'>∧</span><span class='Modifier'>´</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span>
0
</pre>
<p>And the <a href="scan.html">scans</a> <code><span class='Function'>∧</span><span class='Modifier'>`</span></code> and <code><span class='Function'>∨</span><span class='Modifier'>`</span></code> extend this notion to prefixes, switching permanently off at the first 0, or on at the first 1.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oinYCAx4oC/MeKAvzDigL8w4oC/MeKAvzDigL8xCgriiKhgIDDigL8x4oC/MOKAvzDigL8x4oC/MOKAvzE=">↗️</a><pre> <span class='Function'>∧</span><span class='Modifier'>`</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span>
⟨ 1 1 0 0 0 0 0 ⟩
<span class='Function'>∨</span><span class='Modifier'>`</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span>
⟨ 0 1 1 1 1 1 1 ⟩
</pre>
<p>Not (<code><span class='Function'>¬</span></code>) isn't complicated: for example <code><span class='Function'>¬</span><span class='Value'>a</span><span class='Function'>=</span><span class='Value'>b</span></code> indicates that <code><span class='Value'>a</span></code> is <em>not</em> equal to <code><span class='Value'>b</span></code>. Or <code><span class='Value'>a</span><span class='Function'>≠</span><span class='Value'>b</span></code>, but you can't just put a slash through every symbol. One less obvious use is to convert a boolean to plus or minus 1, using the <a href="hook.html">hook</a> modifiers. <code><span class='Value'>b</span><span class='Function'>-¬</span><span class='Value'>b</span></code> leaves 1 unchanged but subtracts 1 from 0, while <code><span class='Paren'>(</span><span class='Function'>¬</span><span class='Value'>b</span><span class='Paren'>)</span><span class='Function'>-</span><span class='Value'>b</span></code> is the negation, converting 0 to 1 and 1 to ¯1.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LeKfnMKsIDDigL8xCgrCrOKKuC0gMOKAvzE=">↗️</a><pre> <span class='Function'>-</span><span class='Modifier2'>⟜</span><span class='Function'>¬</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span>
⟨ ¯1 1 ⟩
<span class='Function'>¬</span><span class='Modifier2'>⊸</span><span class='Function'>-</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span>
⟨ 1 ¯1 ⟩
</pre>
<h3 id="span"><a class="header" href="#span">Span</a></h3>
<p>Span isn't a logic function, given that <code><span class='Number'>1</span><span class='Function'>¬</span><span class='Number'>0</span></code> is <code><span class='Number'>2</span></code>, not a boolean. It's defined to be <code><span class='Number'>1</span><span class='Function'>+</span><span class='Value'>𝕨</span><span class='Function'>-</span><span class='Value'>𝕩</span></code> (I like to think of the line hanging off the right side as the 1 to be added). The reason it's called Span is that if the arguments are whole numbers with <code><span class='Value'>𝕩</span><span class='Function'>≤</span><span class='Value'>𝕨</span></code>, this is the length of the sequence <code><span class='Value'>𝕩</span><span class='Separator'>,</span> <span class='Value'>𝕩</span><span class='Function'>+</span><span class='Number'>1</span><span class='Separator'>,</span><span class='Value'>…</span> <span class='Value'>𝕨</span></code>.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=NCDCrCAxICAgIyAxLCAyLCAzLCA0Cgo5IMKsIDcgICAjIDcsIDgsIDk=">↗️</a><pre> <span class='Number'>4</span> <span class='Function'>¬</span> <span class='Number'>1</span> <span class='Comment'># 1, 2, 3, 4
</span>4
<span class='Number'>9</span> <span class='Function'>¬</span> <span class='Number'>7</span> <span class='Comment'># 7, 8, 9
</span>3
</pre>
<p>The fact that Not and Span share a glyph is no coincidence. <code><span class='Function'>¬</span><span class='Value'>𝕩</span></code> is <code><span class='Number'>0</span><span class='Function'>¬</span><span class='Value'>𝕩</span></code>, because this is equal to <code><span class='Number'>1</span><span class='Function'>-</span><span class='Value'>𝕩</span></code> and <code><span class='Number'>1</span><span class='Function'>-</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span></code> is <code><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span></code>. And because <code><span class='Function'>¬</span><span class='Value'>𝕩</span></code> is defined to be <code><span class='Number'>1</span><span class='Function'>-</span><span class='Value'>𝕩</span></code> not just for booleans but for all numbers, it's also true that <code><span class='Value'>𝕨</span><span class='Function'>¬</span><span class='Value'>𝕩</span></code> is <code><span class='Value'>𝕨</span><span class='Function'>+¬</span><span class='Value'>𝕩</span></code>.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=NSArIMKsIDDigL8x4oC/MQoKNSDCrCAw4oC/MeKAvzE=">↗️</a><pre> <span class='Number'>5</span> <span class='Function'>+</span> <span class='Function'>¬</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span>
⟨ 6 5 5 ⟩
<span class='Number'>5</span> <span class='Function'>¬</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span>
⟨ 6 5 5 ⟩
</pre>
<p>The identities <code><span class='Function'>¬</span><span class='Value'>𝕩</span> <span class='Gets'>←→</span> <span class='Number'>0</span><span class='Function'>¬</span><span class='Value'>𝕩</span></code> and <code><span class='Value'>𝕨</span><span class='Function'>¬</span><span class='Value'>𝕩</span> <span class='Gets'>←→</span> <span class='Value'>𝕨</span><span class='Function'>+¬</span><span class='Value'>𝕩</span></code> are also true with <code><span class='Function'>-</span></code> in place of <code><span class='Function'>¬</span></code>! That's because <code><span class='Function'>¬</span></code> is <code><span class='Brace'>{</span><span class='Number'>1</span><span class='Function'>+</span><span class='Value'>𝕨</span><span class='Function'>-</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code>, or <code><span class='Number'>1</span><span class='Function'>+-</span></code>, in either case. Changing between <code><span class='Function'>-</span></code> and <code><span class='Function'>¬</span></code> only adds or subtracts 1 from both sides of the identities.</p>
<h2 id="definitions"><a class="header" href="#definitions">Definitions</a></h2>
<p>The three logic functions can be defined easily in terms of other arithmetic. They're convenience functions in that sense.</p>
<pre><span class='Function'>Not</span> <span class='Gets'>←</span> <span class='Number'>1</span><span class='Function'>+-</span> <span class='Comment'># also Span
</span><span class='Function'>And</span> <span class='Gets'>←</span> <span class='Function'>×</span>
<span class='Function'>Or</span> <span class='Gets'>←</span> <span class='Function'>×</span><span class='Modifier2'>⌾</span><span class='Function'>¬</span>
</pre>
<p>using a <a href="train.html">train</a> for Not and <a href="under.html">Under</a> for Or. The latter expands to <code><span class='Function'>Or</span> <span class='Gets'>←</span> <span class='Function'>¬</span><span class='Modifier2'>∘</span><span class='Function'>×</span><span class='Modifier2'>○</span><span class='Function'>¬</span></code>, since Not is a self-inverse <code><span class='Function'>¬</span><span class='Modifier'>⁼</span> <span class='Gets'>←→</span> <span class='Function'>¬</span></code>: when applying <code><span class='Function'>¬</span></code> twice, the first added 1 will be negated but the second won't; the two 1s cancel leaving two subtractions, and <code><span class='Function'>-</span><span class='Modifier'>⁼</span> <span class='Gets'>←→</span> <span class='Function'>-</span></code>. An alternate definition of Or that matches the typical formula from probability theory is</p>
<pre><span class='Function'>Or</span> <span class='Gets'>←</span> <span class='Function'>+-×</span>
</pre>
<p>Building these definitions from arithmetic components makes it look like they should apply to any numbers, not just booleans. Well, they do.</p>
<h2 id="extension"><a class="header" href="#extension">Extension</a></h2>
<p>The logic functions are extended to all numbers by making them linear in every argument. In the case of Not, that means the linear function <code><span class='Number'>1</span><span class='Modifier2'>⊸</span><span class='Function'>-</span></code>. The two-argument functions have bilinear extensions: And is identical to Times (<code><span class='Function'>×</span></code>), while Or is <code><span class='Function'>×</span><span class='Modifier2'>⌾</span><span class='Function'>¬</span></code>, following De Morgan's laws (other ways of obtaining a function for Or give an equivalent result—there is only one bilinear extension).</p>
<p>Here are truth <a href="map.html#table">tables</a> of these extensions including the non-integer value one-half:</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=wqwgMOKAvzAuNeKAvzEKCuKIp+KMnMucIDDigL8wLjXigL8xCgriiKjijJzLnCAw4oC/MC414oC/MQ==">↗️</a><pre> <span class='Function'>¬</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>0.5</span><span class='Ligature'>‿</span><span class='Number'>1</span>
⟨ 1 0.5 0 ⟩
<span class='Function'>∧</span><span class='Modifier'>⌜˜</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>0.5</span><span class='Ligature'>‿</span><span class='Number'>1</span>
┌─
╵ 0 0 0
0 0.25 0.5
0 0.5 1
┘
<span class='Function'>∨</span><span class='Modifier'>⌜˜</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>0.5</span><span class='Ligature'>‿</span><span class='Number'>1</span>
┌─
╵ 0 0.5 1
0.5 0.75 1
1 1 1
┘
</pre>
<p>As in logic, any value And 0 is 0, while any value Or 1 is 1. The other boolean values give the identity values for the two functions: 1 and any value gives that value, as does 0 or the value.</p>
<p>If the arguments are probabilities of independent events, then an extended function gives the probability of the boolean function on their outcomes. For example, if <em>A</em> occurs with probability <code><span class='Value'>a</span></code> and <em>B</em> with probability <code><span class='Value'>b</span></code> independent of <em>A</em>, then at least one of <em>A</em> or <em>B</em> occurs with probability <code><span class='Value'>a</span><span class='Function'>∨</span><span class='Value'>b</span></code>. These extensions have also been used in complexity theory, because they allow mathematicians to transfer a logical circuit from the discrete to the continuous domain in order to use calculus on it.</p>
<h3 id="identity-values"><a class="header" href="#identity-values">Identity values</a></h3>
<p>The <a href="fold.html">folds</a> <code><span class='Function'>∧</span><span class='Modifier'>´</span></code> or <code><span class='Function'>∨</span><span class='Modifier'>´</span></code> ought to work on empty lists, so And and Or should have the expected <a href="fold.html#identity-values">identity</a> values 1 (an empty list <em>is</em> all 1s) and 0 (and yet has no 1s). <a href="arithmetic.html#additional-arithmetic">Minimum and Maximum</a> do match And and Or when restricted to booleans, but they have different identity values. It would be dangerous to use Maximum to check whether any element of a list is true because <code><span class='Function'>⌈</span><span class='Modifier'>´</span><span class='Bracket'>⟨⟩</span></code> yields <code><span class='Number'>¯∞</span></code> instead of <code><span class='Number'>0</span></code>—a bug waiting to happen. To avoid this you'd have to always use an initial value <code><span class='Value'>𝕨</span></code> of <code><span class='Number'>0</span></code>, which is easy to forget.</p>
<p>It's not hard to prove that the bilinear extensions have these identity values. Of course <code><span class='Number'>1</span><span class='Function'>∧</span><span class='Value'>x</span></code> is <code><span class='Number'>1</span><span class='Function'>×</span><span class='Value'>x</span></code>, or <code><span class='Value'>x</span></code>, and <code><span class='Number'>0</span><span class='Function'>∨</span><span class='Value'>x</span></code> is <code><span class='Number'>0</span><span class='Function'>×</span><span class='Modifier2'>⌾</span><span class='Function'>¬</span><span class='Value'>x</span></code>, or <code><span class='Function'>¬</span><span class='Number'>1</span><span class='Function'>׬</span><span class='Value'>x</span></code>, giving <code><span class='Function'>¬¬</span><span class='Value'>x</span></code> or <code><span class='Value'>x</span></code> again. Both functions are commutative, so these values are identities on the right as well.</p>
<p>Some other logical identities don't always hold. For example, in boolean logic And distributes over Or and vice-versa: <code><span class='Value'>a</span><span class='Function'>∧</span><span class='Value'>b</span><span class='Function'>∨</span><span class='Value'>c</span> <span class='Gets'>←→</span> <span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>∧</span><span class='Value'>b</span><span class='Paren'>)</span><span class='Function'>∨</span><span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>∧</span><span class='Value'>c</span><span class='Paren'>)</span></code>. But substituting <code><span class='Function'>×</span></code> for <code><span class='Function'>∧</span></code> and <code><span class='Function'>+-×</span></code> for <code><span class='Function'>∨</span></code> we find that the left hand side is <code><span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>×</span><span class='Value'>b</span><span class='Paren'>)</span><span class='Function'>+</span><span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>×</span><span class='Value'>c</span><span class='Paren'>)</span><span class='Function'>+</span><span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>×</span><span class='Value'>b</span><span class='Function'>×</span><span class='Value'>c</span><span class='Paren'>)</span></code> while the right gives <code><span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>×</span><span class='Value'>b</span><span class='Paren'>)</span><span class='Function'>+</span><span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>×</span><span class='Value'>c</span><span class='Paren'>)</span><span class='Function'>+</span><span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>×</span><span class='Value'>b</span><span class='Function'>×</span><span class='Value'>a</span><span class='Function'>×</span><span class='Value'>c</span><span class='Paren'>)</span></code>. These are equivalent for arbitrary <code><span class='Value'>b</span></code> and <code><span class='Value'>c</span></code> only if <code><span class='Value'>a</span><span class='Function'>=</span><span class='Value'>a</span><span class='Function'>×</span><span class='Value'>a</span></code>, that is, <code><span class='Value'>a</span></code> is 0 or 1. In terms of probabilities the difference when <code><span class='Value'>a</span></code> is not boolean is caused by failure of independence. On the left hand side, the two arguments of every logical function are independent. On the right hand side, each pair of arguments to <code><span class='Function'>∧</span></code> are independent, but the two arguments to <code><span class='Function'>∨</span></code>, <code><span class='Value'>a</span><span class='Function'>∧</span><span class='Value'>b</span></code> and <code><span class='Value'>a</span><span class='Function'>∧</span><span class='Value'>c</span></code>, are not. The relationship between these arguments means that logical equivalences no longer apply.</p>
<h3 id="why-not-gcd-and-lcm"><a class="header" href="#why-not-gcd-and-lcm">Why not GCD and LCM?</a></h3>
<p>APL provides <a href="https://aplwiki.com/wiki/GCD">GCD</a> and <a href="https://aplwiki.com/wiki/LCM">LCM</a> as extensions of And and Or, while BQN doesn't make these functions primitives. The main reason for omitting them functions is that they are complicated and, when applied to real or complex numbers, require a significant number of design decisions where there's no obvious choice (for example, whether to use comparison tolerance). On the other hand, these functions are fairly easy to implement, which allows the programmer to control the details, and also add functionality such as the extended GCD. Possible implementations for GCD and LCM are shown in <a href="https://mlochbaum.github.io/bqncrate">bqncrate</a> (<a href="https://mlochbaum.github.io/bqncrate/?q=gcd">GCD</a>, <a href="https://mlochbaum.github.io/bqncrate/?q=lcm">LCM</a>), and <code><span class='Value'>•math.</span><span class='Function'>GCD</span></code> and <code><span class='Value'>•math.</span><span class='Function'>LCM</span></code> are also supported.</p>
<p>A secondary reason is that the GCD falls short as an extension of Or, because its identity value 0 is not total. <code><span class='Number'>0</span><span class='Function'>∨</span><span class='Value'>x</span></code>, for a real number <code><span class='Value'>x</span></code>, is actually equal to <code><span class='Function'>|</span><span class='Value'>x</span></code> and not <code><span class='Value'>x</span></code>: for example, <code><span class='Number'>0</span><span class='Function'>∨</span><span class='Number'>¯2</span></code> is <code><span class='Number'>2</span></code> in APL. This means the identity <code><span class='Number'>0</span><span class='Function'>∨</span><span class='Value'>x</span> <span class='Gets'>←→</span> <span class='Value'>x</span></code> isn't reliable in APL.</p>
<p>Unrelatedly, the reason BQN discards APL's <code><span class='Value'>~</span></code> for negation is that it looks like <code><span class='Modifier'>˜</span></code>, and is less common in mathematics today.</p>
|