-
Notifications
You must be signed in to change notification settings - Fork 1
/
lurch-parser-docs.html
502 lines (466 loc) · 15.5 KB
/
lurch-parser-docs.html
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<!doctype html>
<html lang=en-US>
<head>
<meta charset=UTF-8>
<title>LurchMath</title>
<script type="module">
import { parse as lurch2putdown } from './lurch-to-putdown.js'
import { parse as lurch2tex } from './lurch-to-tex.js'
window.onload = function() {
const textarea = document.getElementById('source')
const update = () => {
const text = textarea.value
let tex,putdown
try {
const isBlank = /^\s*$/.test(text)
// console.log(`The text input is blank: ${isBlank}`)
tex = (!isBlank) ? `$${lurch2tex(text,{enableSets:true})}$` : ''
putdown = (!isBlank) ? lurch2putdown(text,{enableSets:true}) : ''
// console.log(
// `changing render from ${text} to ${tex} with meaning ${putdown}` )
const meaningDiv = document.getElementById('meaning')
meaningDiv.innerHTML = putdown
const renderDiv = document.getElementById('rendered')
renderDiv.innerHTML = tex
try { MathJax.typeset([renderDiv]) } catch (e) { }
} catch (e) { }
}
update()
textarea.addEventListener('input', update)
}
</script>
<script>
window.MathJax = {
tex: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
};
</script>
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>
<link rel="shortcut icon" href="favicon.svg">
<link href=https://fonts.googleapis.com/css?family=Quicksand
rel=stylesheet type=text/css>
<link rel=stylesheet href=lurch-parser-docs.css>
<meta name=viewport
content="width=device-width, initial-scale=0.8,
minimum-scale=0.8, maximum-scale=10">
</head>
<body>
<div id="wrapper">
<nav>
<h1>LurchMath</h1>
<div id="links">
<a href="#about">about</a>
<a href="#features">features</a>
<a href="#examples">examples</a>
<a href="#precedence">precedence</a>
</div>
</nav>
<article>
<section id="about">
<h2>About</h2>
<p>LurchMath is an easy-to-write markup language for mathematics.<br/>
It extends a proper subset of <a href="https://asciimath.org" target="_blank">AsciiMath</a>, $\LaTeX$, and CAS software in natural ways.<br/>
It is currently under development, and more features will be added in the future.
</p>
<div class="leftColumn">
<label for="source">Input:</label>
<br/>
<textarea class="ioArea" id="source" onchange="()=>{
// console.log('changed!')
updateRender(this.value) }">Let x be such that x leq 10</textarea>
</div>
<div class="rightColumn">
<label for="rendered">Rendering:</label>
<br/>
<div class="ioArea" id="rendered">
</div>
</div>
<div class="fullColumn">
<label for="meaning">Meaning:</label>
<br/>
<div class="ioArea" id="meaning">
</div>
</div>
</section>
<section id="features">
<h2>Features</h2>
<p>LurchMath currently supports a small subset of AsciiMath, $\LaTeX$, and notation found in CAS software. Many symbols can be displayed using a TeX command but a preceeding backslash is not required.</p>
<p>Symbols can be more than one character long, are case sensitive, contain only letters and digits, cannot start with a digit, and cannot be a reserved term. Multiplication must be explicitly entered with <code>⋅</code>, <code>cdot</code> or <code>*</code>.</p>
<p>English phrases such as <code>Given</code> or <code>declare</code> are case sensitive and will produce LaTeX with the same phrase in the same case. Spaces within an expression are usually ignored and can be used for legibility. The main exception is that there cannot be any spaces between a function and the parentheses containing its arguments in a function application expression.</p>
<p>A comma separated sequence preceeded by one of the <code>Given</code> keywords has the same effect as saying that each of them is a <code>Given</code> individually. The shortcut declaration <code>Let x in A</code> has the same meaning as <code>Let x be such that x in A</code>. The shortcut declaration <code>P(x) for some x in A</code> has the same meaning as <code>P(x) and x in A for some x</code>.</p>
<p>To declared the set operator $\{\ \}$ as a global constant use <code>Declare set</code>. To declare the ordered pair, triple, or tuple operator $\langle\ \rangle$ as a constant use <code>Declare tuple</code>.</p>
</section>
<section id="examples"></section>
<h2>Examples</h2>
<table>
<thead>
<tr>
<th>If you type any of these</th>
<th>it renders as this</th>
</tr>
</thead>
<tbody>
<tr><td colspan="2" class="subheader">Logic</td></tr>
<tr>
<td>P and Q<br/>P∧Q</td>
<td>$P\text{ and }Q$</td>
</tr>
<tr>
<td>P or Q<br/>P∨Q</td>
<td>$P\text{ or }Q$</td>
</tr>
<tr>
<td>not P<br/>¬P</td>
<td>$\text{not } P$</td>
</tr>
<tr>
<td>P implies Q<br/>P⇒Q</td>
<td>$P\Rightarrow Q$</td>
</tr>
<tr>
<td>P iff Q<br/>P⇔Q</td>
<td>$P\Leftrightarrow Q$</td>
</tr>
<tr>
<td>contradiction<br/>→←</td>
<td>$\rightarrow\leftarrow$</td>
</tr>
<tr><td colspan="2" class="subheader">Quantifiers and bindings</td></tr>
<tr>
<td>forall x.x leq x+1<br/>for all x.x leq x+1<br/>∀x.x leq x+1</td>
<td>$\forall x.\, x\leq x+1$</td>
</tr>
<tr>
<td>exists x.x=2 cdot x<br/>∃x.x=2⋅x</td>
<td>$\exists x.\, x=2\cdot x$</td>
</tr>
<tr>
<td>exists unique x.x=2*x<br/>∃!x.x=2⋅x</td>
<td>$\exists! x.\, x=2\cdot x$</td>
</tr>
<tr>
<td>x.x+2<br/>x mapsto x+2<br/>x↦x+2</td>
<td>$x.\, x+2$</td>
</tr>
<tr><td colspan="2" class="subheader">Algebraic expressions</td></tr>
<tr>
<td>(x)</td>
<td>$\left(x\right)$</td>
</tr>
<tr>
<td>x+y</td>
<td>$x+y$</td>
</tr>
<tr>
<td>2+x+y</td>
<td>$2+x+y$</td>
</tr>
<tr>
<td>-x</td>
<td>$-x$</td>
</tr>
<tr>
<td>1-x</td>
<td>$1-x$</td>
</tr>
<tr>
<td>x*y<br/>x cdot y<br/>x⋅y</td>
<td>$x\cdot y$</td>
</tr>
<tr>
<td>2*x*y<br/>2 cdot x cdot y<br/>2⋅x⋅y</td>
<td>$2\cdot x\cdot y$</td>
</tr>
<tr>
<td>2*3*x<br/>2 cdot 3 cdot x<br/>2⋅3⋅x</td>
<td>$2\cdot 3\cdot x$</td>
</tr>
<tr>
<td>1/x</td>
<td>$\frac{1}{x}$</td>
</tr>
<tr>
<td>2*1/x*y</td>
<td>$2\cdot \frac{1}{x}\cdot y$</td>
</tr>
<tr>
<td>(2*1)/(x*y)</td>
<td>$\frac{2\cdot 1}{x\cdot y}$</td>
</tr>
<tr>
<td>x^2</td>
<td>${x}^{2}$</td>
</tr>
<tr>
<td>x factorial<br/>x!</td>
<td>$x!$</td>
</tr>
<tr>
<td>(n+1) choose (k-1)</td>
<td>$\binom{n+1}{k-1}$</td>
</tr>
<tr>
<td>multinomial(m,n)</td>
<td>$\left(m,n\right)$</td>
</tr>
<tr>
<td>sum k=0 to n of k^2<br/>sum k from 0 to n of k^2<br/>sum k to n of k^2<br/>sum of k^2 as k goes from 0 to n<br/>sum k^2 as k goes from 0 to n<br/>sum k^2 as k from 0 to n<br/>sum k^2 for k from 0 to n<br/>sum k^2 for k to n<br/>sum of k^2 as k to n<br/>sum of k^2 for k to n<br/>sum( k^2 , k , 0 , n )<br/>sum(k^2,k,0,n)<br/>sum(k^2,k,n)</td>
<td>$\displaystyle\sum_{k=0}^{n} {k}^{2}$</td>
</tr>
<tr>
<td>Fib_(n+2)</td>
<td>$F_{n+2}$</td>
</tr>
<tr><td colspan="2" class="subheader">Set Theory</td></tr>
<tr>
<td>x in A<br/>x∈A</td>
<td>$x\in A$</td>
</tr>
<tr>
<td>x notin A<br/>x∉A</td>
<td>$x\notin A$</td>
</tr>
<tr>
<td>{a,b,c}<br/>set(a,b,c)</td>
<td>$\left\{\,a,b,c\,\right\}$</td>
</tr>
<tr>
<td>{ p:p is prime}<br/>set(p:p is prime)</td>
<td>$\left\{\,p:\,p\text{ is }\text{prime}\right\}$</td>
</tr>
<tr>
<td>A subset B<br/>A subseteq B<br/>A⊆B</td>
<td>$A\subseteq B$</td>
</tr>
<tr>
<td>A cup B<br/>A union B<br/>A∪B</td>
<td>$A\cup B$</td>
</tr>
<tr>
<td>A cap B<br/>A intersect B<br/>A∩B</td>
<td>$A\cap B$</td>
</tr>
<tr>
<td>A setminus B<br/>A∖B</td>
<td>$A\setminus B$</td>
</tr>
<tr>
<td>A'<br/>A complement<br/>A°</td>
<td>${A}'$</td>
</tr>
<tr>
<td>powerset(A)<br/>𝒫(A)</td>
<td>$\mathscr{P}\left(A\right)$</td>
</tr>
<tr>
<td>f:A to B<br/>f:A→B</td>
<td>$f\colon A\to B$</td>
</tr>
<tr>
<td>f(x)</td>
<td>$f\left(x\right)$</td>
</tr>
<tr>
<td>f_(x)</td>
<td>$f_{x}$</td>
</tr>
<tr>
<td>f_(0)(x)_(n+1)</td>
<td>$f_{0}\left(x\right)_{n+1}$</td>
</tr>
<tr>
<td>g circ f<br/>g comp f<br/>g∘f</td>
<td>$g\circ f$</td>
</tr>
<tr>
<td>A times B<br/>A cross B<br/>A×B</td>
<td>$A\times B$</td>
</tr>
<tr>
<td>pair(x,y)<br/>tuple(x,y)<br/>⟨x,y⟩</td>
<td>$\left\langle\,x,y\,\right\rangle$</td>
</tr>
<tr>
<td>triple(x,y,z)<br/>tuple(x,y,z)<br/>⟨x,y,z⟩</td>
<td>$\left\langle\,x,y,z\,\right\rangle$</td>
</tr>
<tr>
<td>tuple(w,x,y,z)<br/>⟨w,x,y,z⟩</td>
<td>$\left\langle\,w,x,y,z\,\right\rangle$</td>
</tr>
<tr>
<td>Union i in I of A_(i)<br/>Union of A_(i) for i in I<br/>Union(A_(i),i,I)<br/>Cup i in I of A_(i)<br/>bigcup i in I of A_(i)</td>
<td>$\displaystyle\bigcup_{i\in I} A_{i}$</td>
</tr>
<tr>
<td>Intersect i in I of A_(i)<br/>Intersect of A_(i) for i in I<br/>Intersect(A_(i),i,I)<br/>Cap i in I of A_(i)<br/>bigcap i in I of A_(i)</td>
<td>$\displaystyle\bigcap_{i\in I} A_{i}$</td>
</tr>
<tr><td colspan="2" class="subheader">Relations</td></tr>
<tr>
<td>x lt 0<br/>x < 0</td>
<td>$x\lt 0$</td>
</tr>
<tr>
<td>x leq 0<br/>x ≤ 0</td>
<td>$x\leq 0$</td>
</tr>
<tr>
<td>x neq 0<br/>x ne 0<br/>x≠0</td>
<td>$x\neq 0$</td>
</tr>
<tr>
<td>m | n<br/>m divides n</td>
<td>$m\mid n$</td>
</tr>
<tr>
<td>a cong b mod m<br/>a cong mod m to b</td>
<td>$a\underset{m}{\equiv}b$</td>
</tr>
<tr>
<td>x~y</td>
<td>$x\sim y$</td>
</tr>
<tr>
<td>x~y~z</td>
<td>$x\sim y\sim z$</td>
</tr>
<tr>
<td>x=y</td>
<td>$x=y$</td>
</tr>
<tr>
<td>x=y=z</td>
<td>$\begin{align*}
x &= y \\
&= z
\end{align*}$</td>
</tr>
<tr>
<td>X loves Y</td>
<td>$X\text{ loves }Y$</td>
</tr>
<tr>
<td>X is Y<br/>X is an Y<br/>X is a Y<br/>X are Y</td>
<td>$X\text{ is }Y$</td>
</tr>
<tr>
<td>P is a partition of A</td>
<td>$P\text{ is a partition of }A$</td>
</tr>
<tr>
<td>'~' is an equivalence relation</td>
<td>$\sim\text{ is }\text{an }\text{equivalence relation}$</td>
</tr>
<tr>
<td>[a]</td>
<td>$\left[a\right]$</td>
</tr>
<tr>
<td>[a,~]</td>
<td>$\left[a\right]_\sim$</td>
</tr>
<tr>
<td>'~' is a strict partial order</td>
<td>$\sim\text{ is }\text{a }\text{strict partial order}$</td>
</tr>
<tr>
<td>'~' is a partial order</td>
<td>$\sim\text{ is }\text{a }\text{partial order}$</td>
</tr>
<tr>
<td>'~' is a total order</td>
<td>$\sim\text{ is }\text{a }\text{total order}$</td>
</tr>
<tr><td colspan="2" class="subheader">Assumptions and Declarations (case insensitive, phrase is echoed)</td></tr>
<tr>
<td>Assume P<br/>Given P<br/>From P<br/>Suppose P<br/>If P<br/>:P</td>
<td>$\text{Assume } P$</td>
</tr>
<tr>
<td>Let x</td>
<td>$\text{Let }x$</td>
</tr>
<tr>
<td>Let x in A</td>
<td>$\text{Let }x\in A$</td>
</tr>
<tr>
<td>Let x be such that x in RR<br/>Let x such that x in RR</td>
<td>$\text{Let }x\text{ be such that }x\in \mathbb{R}$</td>
</tr>
<tr>
<td>f(c)=0 for some c</td>
<td>$f\left(c\right)=0\text{ for some }c$</td>
</tr>
<tr>
<td>f(c)=0 for some c in A</td>
<td>$f\left(c\right)=0\text{ for some }c\in A$</td>
</tr>
<tr>
<td>Declare is, 0, +, cos</td>
<td>$\text{Declare } \text{is}\text{, }0\text{, }+\text{, and }\text{cos}$</td>
</tr>
<tr><td colspan="2" class="subheader">Miscellaneous</td></tr>
<tr>
<td>x^-<br/>x⁻</td>
<td>${x}^{-}$</td>
</tr>
<tr>
<td>@P(k)<br/>λP(k)</td>
<td>$\mathcal{P}\left(k\right)$</td>
</tr>
</tbody>
</table>
</section>
<section id="precedence"></section>
<h2>Precedence</h2>
<p>The precedence of operations from highest to lowest are given in the following table. There are a few fine points to be aware of.</p>
<ul>
<li>Exponentiation has higher precedence than function application. That is normally what is expected for something like $f^2(x)$ or $f^\text{inv}(S)$ but might not be what is expected for something like $z^{\sigma(n)}$. The first two can be typed as you would expect <code>f^2(S)</code> and <code>f^inv(x)</code> while the latter would be entered as <br/><code>z^(sigma(x))</code>.</li>
<li>Summation has precedence higher than addition but lower than multiplication. Thus, <br/><code>sum k to n f(k) + 2</code> is interpreted as $\left(\sum_{k=0}^n f(k)\right)+2$, whereas <code>sum k to n (f(k) + 2)</code> is interpreted as $\sum_{k=0}^n \left(f(k)+2\right)$.
</li>
</ul>
<table id="precedence">
<thead>
<tr>
<th>Precedence (high to low)</th>
</tr>
</thead>
<tbody>
<tr><td>parentheses $(~~)$, tuples $\langle~~\rangle$, equivalence classes $[~~]$, symbols, numbers</td></tr>
<tr><td>exponentials $\left(x^2\right)$</td></tr>
<tr><td>function application $\left(f_0(x,y)(z)\right)$</td></tr>
<tr><td>postfix ($n!$, $f'$)</td></tr>
<tr><td>negation ($-x$), reciprocal ($1/2$)</td></tr>
<tr><td>product ($2\cdot x$)</td></tr>
<tr><td>summation $\left(\sum_{k=0}^n f(k)\right)$</td></tr>
<tr><td>indexed union and intersection $\left(\bigcup_{i \in \mathbb{N}} A_{i}\right)$</td></tr>
<tr><td>sum ($x+y-1$)</td></tr>
<tr><td>choose $\binom{m+n}{m}$</td></tr>
<tr><td>composition $\left(g\circ f\right)$</td></tr>
<tr><td>intersection ($A\cap B$)</td></tr>
<tr><td>union ($A\cup B$)</td></tr>
<tr><td>cartesian product ($A\times B$)</td></tr>
<tr><td>relative complement ($A\setminus B$)</td></tr>
<tr><td>relations ($f:A\to B$, $\underset{m}{\equiv}$, $\subseteq$, $\in$, $\notin$, $\mid$, $\leq$, $\lt$, $=$, $\neq$, $\sim$, 'is', 'loves')</td></tr>
<tr><td>not ($\neg$)</td></tr>
<tr><td>and ($\wedge$)</td></tr>
<tr><td>or ($\vee$)</td></tr>
<tr><td>implies ($\Rightarrow$)</td></tr>
<tr><td>iff ($\Leftrightarrow$)</td></tr>
<tr><td>binding ($x.P(x)$)</td></tr>
<tr><td>quantified ($\forall x.P(x)$)</td></tr>
<tr><td>declarations ('Declare', 'Let', 'for some')</td></tr>
<tr><td>environment $\{~\}$</td></tr>
</tbody>
</table>
</section>
</article>
</div>
</body>
</html>