Skip to content

Commit 211b3f5

Browse files
committed
docs:Better examples.
1 parent 53d09f4 commit 211b3f5

1 file changed

Lines changed: 90 additions & 32 deletions

File tree

docs/Basic-usage.ipynb

Lines changed: 90 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
{
2525
"cell_type": "code",
26-
"execution_count": 22,
26+
"execution_count": 1,
2727
"id": "9d5fa8a4",
2828
"metadata": {},
2929
"outputs": [],
@@ -52,7 +52,7 @@
5252
},
5353
{
5454
"cell_type": "code",
55-
"execution_count": 23,
55+
"execution_count": 2,
5656
"id": "77a819d7",
5757
"metadata": {},
5858
"outputs": [
@@ -62,7 +62,7 @@
6262
"[\"Root\",[\"Add\",[\"Add\",[\"Multiply\",4,[\"Power\",\"x\",2]],[\"Multiply\",12,\"x\"]],9],2]"
6363
]
6464
},
65-
"execution_count": 23,
65+
"execution_count": 2,
6666
"metadata": {},
6767
"output_type": "execute_result"
6868
}
@@ -81,17 +81,17 @@
8181
},
8282
{
8383
"cell_type": "code",
84-
"execution_count": 24,
85-
"id": "9807bee7",
84+
"execution_count": 36,
85+
"id": "7a12674f",
8686
"metadata": {},
8787
"outputs": [
8888
{
8989
"data": {
9090
"text/html": [
91-
"<table border=\"1\"><thead><tr><th>expr</th><th>Cortex-JS</th><th>LaTeX::Grammar</th></tr></thead><tbody><tr><td align=left>4 x^2 + 12 x + 9</td><td align=left>$[&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]</td><td align=left>[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Power&quot;,&quot;4 x&quot;,2],&quot;12 x&quot;],9]</td></tr><tr><td align=left>4 \\times x^2 + 12 \\times x + 9</td><td align=left>$[&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]</td><td align=left>[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Multiply&quot;,4,[&quot;Power&quot;,&quot;x&quot;,2]],[&quot;Multiply&quot;,12,&quot;x&quot;]],9]</td></tr><tr><td align=left>4 * x^2 + 12 * x + 9</td><td align=left>$[&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]</td><td align=left>[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Multiply&quot;,4,[&quot;Power&quot;,&quot;x&quot;,2]],[&quot;Multiply&quot;,12,&quot;x&quot;]],9]</td></tr><tr><td align=left>\\sqrt{4 * x^2 + 12 * x + 9}</td><td align=left>$[&quot;Sqrt&quot;, [&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]]</td><td align=left>[&quot;Root&quot;,[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Multiply&quot;,4,[&quot;Power&quot;,&quot;x&quot;,2]],[&quot;Multiply&quot;,12,&quot;x&quot;]],9],2]</td></tr></tbody></table>"
91+
"<table border=\"1\"><thead><tr><th>expr</th><th>Cortex-JS</th><th>LaTeX::Grammar</th></tr></thead><tbody><tr><td align=left><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><mrow><msup><mi>4 x</mi><mn>2</mn></msup><mo>+</mo><mi>12 x</mi></mrow><mo>+</mo><mn>9</mn></mrow></math></td><td align=left>$[&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]</td><td align=left>[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Power&quot;,&quot;4 x&quot;,2],&quot;12 x&quot;],9]</td></tr><tr><td align=left><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><mrow><mrow><mn>4</mn><mo>&#xD7;</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>+</mo><mrow><mn>12</mn><mo>&#xD7;</mo><mi>x</mi></mrow></mrow><mo>+</mo><mn>9</mn></mrow></math></td><td align=left>$[&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]</td><td align=left>[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Multiply&quot;,4,[&quot;Power&quot;,&quot;x&quot;,2]],[&quot;Multiply&quot;,12,&quot;x&quot;]],9]</td></tr><tr><td align=left><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><mrow><mrow><mn>4</mn><mo>&#xD7;</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>+</mo><mrow><mn>12</mn><mo>&#xD7;</mo><mi>x</mi></mrow></mrow><mo>+</mo><mn>9</mn></mrow></math></td><td align=left>$[&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]</td><td align=left>[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Multiply&quot;,4,[&quot;Power&quot;,&quot;x&quot;,2]],[&quot;Multiply&quot;,12,&quot;x&quot;]],9]</td></tr><tr><td align=left><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><msqrt><mrow><mrow><msup><mi>4x</mi><mn>2</mn></msup><mo>+</mo><mi>12x</mi></mrow><mo>+</mo><mn>9</mn></mrow></msqrt></math></td><td align=left>$[&quot;Sqrt&quot;, [&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]]</td><td align=left>[&quot;Root&quot;,[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Power&quot;,&quot;4x&quot;,2],&quot;12x&quot;],9],2]</td></tr><tr><td align=left><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><msqrt><mrow><mrow><mrow><mn>4</mn><mo>&#xD7;</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>+</mo><mrow><mn>12</mn><mo>&#xD7;</mo><mi>x</mi></mrow></mrow><mo>+</mo><mn>9</mn></mrow></msqrt></math></td><td align=left>$[&quot;Sqrt&quot;, [&quot;Add&quot;, [&quot;Multiply&quot;, 4, [&quot;Power&quot;, &quot;x&quot;, 2]], [&quot;Multiply&quot;, 12, &quot;x&quot;], 9]]</td><td align=left>[&quot;Root&quot;,[&quot;Add&quot;,[&quot;Add&quot;,[&quot;Multiply&quot;,4,[&quot;Power&quot;,&quot;x&quot;,2]],[&quot;Multiply&quot;,12,&quot;x&quot;]],9],2]</td></tr></tbody></table>"
9292
]
9393
},
94-
"execution_count": 24,
94+
"execution_count": 36,
9595
"metadata": {},
9696
"output_type": "execute_result"
9797
}
@@ -102,10 +102,12 @@
102102
" '4 x^2 + 12 x + 9',\n",
103103
" '4 \\times x^2 + 12 \\times x + 9',\n",
104104
" '4 * x^2 + 12 * x + 9',\n",
105-
" '\\sqrt{4 * x^2 + 12 * x + 9}'\n",
105+
" '\\sqrt{4x^2 + 12x + 9}',\n",
106+
" '\\sqrt{4 * x^2 + 12 * x + 9}',\n",
106107
"]\n",
107-
"andthen $_.map({ %(expr => $_, Cortex-JS => parse-latex($_).raku, 'LaTeX::Grammar' => latex-interpret($_)) })\n",
108-
"andthen .&to-html(field-names => <expr Cortex-JS LaTeX::Grammar>, align => 'left')"
108+
"andthen $_.map({ %(expr => \"latex«$_»\", Cortex-JS => parse-latex($_).raku, 'LaTeX::Grammar' => latex-interpret($_)) })\n",
109+
"andthen .&to-html(field-names => <expr Cortex-JS LaTeX::Grammar>, align => 'left')\n",
110+
"andthen .subst(/ 'latex«' (.*?) '»' /, { latex-interpret($0.Str, actions => 'MathML')}, :g)"
109111
]
110112
},
111113
{
@@ -120,7 +122,7 @@
120122
},
121123
{
122124
"cell_type": "code",
123-
"execution_count": 25,
125+
"execution_count": 4,
124126
"id": "20cb12fa",
125127
"metadata": {},
126128
"outputs": [
@@ -130,7 +132,7 @@
130132
"-1"
131133
]
132134
},
133-
"execution_count": 25,
135+
"execution_count": 4,
134136
"metadata": {},
135137
"output_type": "execute_result"
136138
}
@@ -143,7 +145,7 @@
143145
},
144146
{
145147
"cell_type": "code",
146-
"execution_count": 42,
148+
"execution_count": 5,
147149
"id": "2904bf39",
148150
"metadata": {},
149151
"outputs": [
@@ -153,7 +155,7 @@
153155
"a^2+b^2+2ab"
154156
]
155157
},
156-
"execution_count": 42,
158+
"execution_count": 5,
157159
"metadata": {},
158160
"output_type": "execute_result"
159161
}
@@ -175,7 +177,7 @@
175177
},
176178
{
177179
"cell_type": "code",
178-
"execution_count": 41,
180+
"execution_count": 6,
179181
"id": "71b73b96",
180182
"metadata": {},
181183
"outputs": [
@@ -185,7 +187,7 @@
185187
"$2x^2+3x^2+x+5$ = $5x^2+x+5$"
186188
]
187189
},
188-
"execution_count": 41,
190+
"execution_count": 6,
189191
"metadata": {},
190192
"output_type": "execute_result"
191193
}
@@ -206,7 +208,7 @@
206208
},
207209
{
208210
"cell_type": "code",
209-
"execution_count": 40,
211+
"execution_count": 7,
210212
"id": "779d56cf",
211213
"metadata": {},
212214
"outputs": [
@@ -216,7 +218,7 @@
216218
"$\\sqrt{5x^2+x+5}$"
217219
]
218220
},
219-
"execution_count": 40,
221+
"execution_count": 7,
220222
"metadata": {},
221223
"output_type": "execute_result"
222224
}
@@ -241,7 +243,7 @@
241243
},
242244
{
243245
"cell_type": "code",
244-
"execution_count": 29,
246+
"execution_count": 8,
245247
"id": "de5cb448",
246248
"metadata": {},
247249
"outputs": [
@@ -251,7 +253,7 @@
251253
"[3 2]"
252254
]
253255
},
254-
"execution_count": 29,
256+
"execution_count": 8,
255257
"metadata": {},
256258
"output_type": "execute_result"
257259
}
@@ -264,7 +266,7 @@
264266
},
265267
{
266268
"cell_type": "code",
267-
"execution_count": 30,
269+
"execution_count": 9,
268270
"id": "d1b1cc90",
269271
"metadata": {},
270272
"outputs": [
@@ -274,7 +276,7 @@
274276
"$3+2\\sqrt{2}, \\: 3-2\\sqrt{2}$"
275277
]
276278
},
277-
"execution_count": 30,
279+
"execution_count": 9,
278280
"metadata": {},
279281
"output_type": "execute_result"
280282
}
@@ -289,7 +291,7 @@
289291
},
290292
{
291293
"cell_type": "code",
292-
"execution_count": 31,
294+
"execution_count": 10,
293295
"id": "2d11e132",
294296
"metadata": {},
295297
"outputs": [
@@ -299,7 +301,7 @@
299301
"$x+\\frac{1}{x}$"
300302
]
301303
},
302-
"execution_count": 31,
304+
"execution_count": 10,
303305
"metadata": {},
304306
"output_type": "execute_result"
305307
}
@@ -322,9 +324,17 @@
322324
"## Calculus"
323325
]
324326
},
327+
{
328+
"cell_type": "markdown",
329+
"id": "7a7310a7",
330+
"metadata": {},
331+
"source": [
332+
"Derivate of expression over the variable $x$:"
333+
]
334+
},
325335
{
326336
"cell_type": "code",
327-
"execution_count": 38,
337+
"execution_count": 11,
328338
"id": "5bde1c7c",
329339
"metadata": {},
330340
"outputs": [
@@ -334,7 +344,7 @@
334344
"$2x$"
335345
]
336346
},
337-
"execution_count": 38,
347+
"execution_count": 11,
338348
"metadata": {},
339349
"output_type": "execute_result"
340350
}
@@ -347,9 +357,17 @@
347357
"==> to-latex()"
348358
]
349359
},
360+
{
361+
"cell_type": "markdown",
362+
"id": "541568a1",
363+
"metadata": {},
364+
"source": [
365+
"Evaluate the undefined integral $\\int x^2 dx$:"
366+
]
367+
},
350368
{
351369
"cell_type": "code",
352-
"execution_count": 33,
370+
"execution_count": 12,
353371
"id": "9ee1cb09",
354372
"metadata": {},
355373
"outputs": [
@@ -359,7 +377,7 @@
359377
"$\\frac{x^3}{3}$"
360378
]
361379
},
362-
"execution_count": 33,
380+
"execution_count": 12,
363381
"metadata": {},
364382
"output_type": "execute_result"
365383
}
@@ -372,9 +390,17 @@
372390
"==> to-latex()"
373391
]
374392
},
393+
{
394+
"cell_type": "markdown",
395+
"id": "d8ffd0d5",
396+
"metadata": {},
397+
"source": [
398+
"Evaluate the defined integral $\\int_{0}^{1} x^2 dx$:"
399+
]
400+
},
375401
{
376402
"cell_type": "code",
377-
"execution_count": 34,
403+
"execution_count": 13,
378404
"id": "65a03919",
379405
"metadata": {},
380406
"outputs": [
@@ -384,7 +410,7 @@
384410
"$\\frac{1}{3}$"
385411
]
386412
},
387-
"execution_count": 34,
413+
"execution_count": 13,
388414
"metadata": {},
389415
"output_type": "execute_result"
390416
}
@@ -397,6 +423,38 @@
397423
"==> to-latex()"
398424
]
399425
},
426+
{
427+
"cell_type": "markdown",
428+
"id": "b3c7af81",
429+
"metadata": {},
430+
"source": [
431+
"Evaluate the limit $\\lim_{x \\to 0} \\frac{\\sin(x)}{x}$:"
432+
]
433+
},
434+
{
435+
"cell_type": "code",
436+
"execution_count": 42,
437+
"id": "ff3d7e9d",
438+
"metadata": {},
439+
"outputs": [
440+
{
441+
"data": {
442+
"text/plain": [
443+
"1"
444+
]
445+
},
446+
"execution_count": 42,
447+
"metadata": {},
448+
"output_type": "execute_result"
449+
}
450+
],
451+
"source": [
452+
"'\\lim_{x \\to 0} \\frac{\\sin(x)}{x}'\n",
453+
"==> parse-latex()\n",
454+
"==> evaluate()\n",
455+
"==> N()"
456+
]
457+
},
400458
{
401459
"cell_type": "markdown",
402460
"id": "6866a00b",
@@ -417,7 +475,7 @@
417475
},
418476
{
419477
"cell_type": "code",
420-
"execution_count": 35,
478+
"execution_count": 14,
421479
"id": "6662e6ef",
422480
"metadata": {},
423481
"outputs": [
@@ -427,7 +485,7 @@
427485
"6"
428486
]
429487
},
430-
"execution_count": 35,
488+
"execution_count": 14,
431489
"metadata": {},
432490
"output_type": "execute_result"
433491
}

0 commit comments

Comments
 (0)