Skip to content

Commit 3b72c75

Browse files
committed
docs:More (and prettier) examples.
1 parent c38aa36 commit 3b72c75

1 file changed

Lines changed: 189 additions & 24 deletions

File tree

docs/Basic-usage.ipynb

Lines changed: 189 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
{
2525
"cell_type": "code",
26-
"execution_count": 32,
26+
"execution_count": 22,
2727
"id": "9d5fa8a4",
2828
"metadata": {},
2929
"outputs": [],
@@ -52,7 +52,7 @@
5252
},
5353
{
5454
"cell_type": "code",
55-
"execution_count": 33,
55+
"execution_count": 23,
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": 33,
65+
"execution_count": 23,
6666
"metadata": {},
6767
"output_type": "execute_result"
6868
}
@@ -81,7 +81,7 @@
8181
},
8282
{
8383
"cell_type": "code",
84-
"execution_count": 34,
84+
"execution_count": 24,
8585
"id": "9807bee7",
8686
"metadata": {},
8787
"outputs": [
@@ -91,7 +91,7 @@
9191
"<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>"
9292
]
9393
},
94-
"execution_count": 34,
94+
"execution_count": 24,
9595
"metadata": {},
9696
"output_type": "execute_result"
9797
}
@@ -120,7 +120,7 @@
120120
},
121121
{
122122
"cell_type": "code",
123-
"execution_count": 35,
123+
"execution_count": 25,
124124
"id": "20cb12fa",
125125
"metadata": {},
126126
"outputs": [
@@ -130,7 +130,7 @@
130130
"-1"
131131
]
132132
},
133-
"execution_count": 35,
133+
"execution_count": 25,
134134
"metadata": {},
135135
"output_type": "execute_result"
136136
}
@@ -143,17 +143,17 @@
143143
},
144144
{
145145
"cell_type": "code",
146-
"execution_count": 36,
146+
"execution_count": 26,
147147
"id": "2904bf39",
148148
"metadata": {},
149149
"outputs": [
150150
{
151151
"data": {
152152
"text/plain": [
153-
"a^2+b^2+2ab"
153+
"$a^2+b^2+2ab$"
154154
]
155155
},
156-
"execution_count": 36,
156+
"execution_count": 26,
157157
"metadata": {},
158158
"output_type": "execute_result"
159159
}
@@ -175,22 +175,23 @@
175175
},
176176
{
177177
"cell_type": "code",
178-
"execution_count": 37,
178+
"execution_count": 41,
179179
"id": "71b73b96",
180180
"metadata": {},
181181
"outputs": [
182182
{
183183
"data": {
184-
"text/plain": [
185-
"2x^2+3x^2+x+5 = 5x^2+x+5"
184+
"text/markdown": [
185+
"$2x^2+3x^2+x+5$ = $5x^2+x+5$"
186186
]
187187
},
188-
"execution_count": 37,
188+
"execution_count": 41,
189189
"metadata": {},
190190
"output_type": "execute_result"
191191
}
192192
],
193193
"source": [
194+
"#%markdown\n",
194195
"my $expr = parse-latex('3x^2 + 2x^2 + x + 5');\n",
195196
"\"{to-latex($expr)} = {to-latex(simplify($expr))}\";"
196197
]
@@ -205,19 +206,17 @@
205206
},
206207
{
207208
"cell_type": "code",
208-
"execution_count": 42,
209+
"execution_count": 40,
209210
"id": "779d56cf",
210211
"metadata": {},
211212
"outputs": [
212213
{
213214
"data": {
214215
"text/markdown": [
215-
"$$\n",
216-
"\\sqrt{5x^2+x+5}\n",
217-
"$$"
216+
"$\\sqrt{5x^2+x+5}$"
218217
]
219218
},
220-
"execution_count": 42,
219+
"execution_count": 40,
221220
"metadata": {},
222221
"output_type": "execute_result"
223222
}
@@ -227,9 +226,175 @@
227226
"'\\sqrt{3x^2 + 2x^2 + x + 5}'\n",
228227
"==> parse-latex()\n",
229228
"==> simplify()\n",
230-
"==> to-latex()\n",
231-
"==> { $_.subst(/ '\\text{\\text{' (.*) '}}' $ /, {$0.Str}) }()\n",
232-
"==> { \"\\$\\$\\n$_\\n\\$\\$\" }()"
229+
"==> to-latex()"
230+
]
231+
},
232+
{
233+
"cell_type": "markdown",
234+
"id": "63c7bf3d",
235+
"metadata": {},
236+
"source": [
237+
"----\n",
238+
"\n",
239+
"## Solve equations"
240+
]
241+
},
242+
{
243+
"cell_type": "code",
244+
"execution_count": 29,
245+
"id": "de5cb448",
246+
"metadata": {},
247+
"outputs": [
248+
{
249+
"data": {
250+
"text/plain": [
251+
"[3 2]"
252+
]
253+
},
254+
"execution_count": 29,
255+
"metadata": {},
256+
"output_type": "execute_result"
257+
}
258+
],
259+
"source": [
260+
"'x^2 - 5 x + 6 = 0'\n",
261+
"==> parse-latex() \n",
262+
"==> solve()"
263+
]
264+
},
265+
{
266+
"cell_type": "code",
267+
"execution_count": 30,
268+
"id": "d1b1cc90",
269+
"metadata": {},
270+
"outputs": [
271+
{
272+
"data": {
273+
"text/markdown": [
274+
"$3+2\\sqrt{2}, \\: 3-2\\sqrt{2}$"
275+
]
276+
},
277+
"execution_count": 30,
278+
"metadata": {},
279+
"output_type": "execute_result"
280+
}
281+
],
282+
"source": [
283+
"#%markdown\n",
284+
"'x^2 - 6 x + 1 = 0'\n",
285+
"==> parse-latex() \n",
286+
"==> solve()\n",
287+
"==> to-latex()"
288+
]
289+
},
290+
{
291+
"cell_type": "code",
292+
"execution_count": 31,
293+
"id": "2d11e132",
294+
"metadata": {},
295+
"outputs": [
296+
{
297+
"data": {
298+
"text/markdown": [
299+
"$x+\\frac{1}{x}$"
300+
]
301+
},
302+
"execution_count": 31,
303+
"metadata": {},
304+
"output_type": "execute_result"
305+
}
306+
],
307+
"source": [
308+
"#% markdown\n",
309+
"'x^2 - a x + 1 = 0'\n",
310+
"==> parse-latex() \n",
311+
"==> solve(vars => 'a')\n",
312+
"==> to-latex()"
313+
]
314+
},
315+
{
316+
"cell_type": "markdown",
317+
"id": "42ba6296",
318+
"metadata": {},
319+
"source": [
320+
"---\n",
321+
"\n",
322+
"## Calculus"
323+
]
324+
},
325+
{
326+
"cell_type": "code",
327+
"execution_count": 38,
328+
"id": "5bde1c7c",
329+
"metadata": {},
330+
"outputs": [
331+
{
332+
"data": {
333+
"text/markdown": [
334+
"$2x$"
335+
]
336+
},
337+
"execution_count": 38,
338+
"metadata": {},
339+
"output_type": "execute_result"
340+
}
341+
],
342+
"source": [
343+
"#%markdown\n",
344+
"'D_x (x^2 + 1)'\n",
345+
"==> parse-latex()\n",
346+
"==> evaluate()\n",
347+
"==> to-latex()"
348+
]
349+
},
350+
{
351+
"cell_type": "code",
352+
"execution_count": 33,
353+
"id": "9ee1cb09",
354+
"metadata": {},
355+
"outputs": [
356+
{
357+
"data": {
358+
"text/markdown": [
359+
"$\\frac{x^3}{3}$"
360+
]
361+
},
362+
"execution_count": 33,
363+
"metadata": {},
364+
"output_type": "execute_result"
365+
}
366+
],
367+
"source": [
368+
"#%markdown\n",
369+
"'\\int x^2 dx'\n",
370+
"==> parse-latex()\n",
371+
"==> evaluate()\n",
372+
"==> to-latex()"
373+
]
374+
},
375+
{
376+
"cell_type": "code",
377+
"execution_count": 34,
378+
"id": "65a03919",
379+
"metadata": {},
380+
"outputs": [
381+
{
382+
"data": {
383+
"text/markdown": [
384+
"$\\frac{1}{3}$"
385+
]
386+
},
387+
"execution_count": 34,
388+
"metadata": {},
389+
"output_type": "execute_result"
390+
}
391+
],
392+
"source": [
393+
"#%markdown\n",
394+
"'\\int_{0}^{1} x^2 dx'\n",
395+
"==> parse-latex()\n",
396+
"==> evaluate()\n",
397+
"==> to-latex()"
233398
]
234399
},
235400
{
@@ -252,7 +417,7 @@
252417
},
253418
{
254419
"cell_type": "code",
255-
"execution_count": 44,
420+
"execution_count": 35,
256421
"id": "6662e6ef",
257422
"metadata": {},
258423
"outputs": [
@@ -262,7 +427,7 @@
262427
"6"
263428
]
264429
},
265-
"execution_count": 44,
430+
"execution_count": 35,
266431
"metadata": {},
267432
"output_type": "execute_result"
268433
}

0 commit comments

Comments
 (0)