Skip to content

Commit 9c47fb2

Browse files
author
Kasper Peeters
committed
Add limit and series. Improve web docs.
1 parent 82ec5aa commit 9c47fb2

File tree

6 files changed

+153
-2
lines changed

6 files changed

+153
-2
lines changed

client_server/notebook.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
%\makeatletter\def\old@comma{,}\catcode`\,=13 \def,{%
3333
%\ifmmode\old@comma\discretionary{}{}{}\else\old@comma\fi}\makeatother
3434

35+
\newcommand{\bigO}{{\cal O}}
36+
3537
% Math expressions wrapped in \brwrap will get typeset with
3638
% round brackets around them, which have the appropriate size.
3739
% The expression itself can still be broken over multiple lines.

core/DisplaySympy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ DisplaySympy::DisplaySympy(const Kernel& kernel, const Ex& e)
4141
{"\\sqrt", "sqrt" },
4242
{"\\equals", "Eq" },
4343

44-
{"\\infty", "sympy.oo"},
44+
{"\\infty", "oo"},
4545
{"\\hbar", "hbar"},
4646

4747
{"\\alpha", "alpha" },

core/packages/cdb/sympy/calculus.cnb

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"source": "\\begin{dmath*}{}-\\sin{y} \\cos{x}\\end{dmath*}"
8181
}
8282
],
83+
"ignore_on_import": true,
8384
"source": "diff($\\sin(x)\\cos(y)$, $x$, $y$);"
8485
},
8586
{
@@ -176,6 +177,7 @@
176177
"source": "\\begin{dmath*}{}\\frac{1}{3}{x}^{3} y\\end{dmath*}"
177178
}
178179
],
180+
"ignore_on_import": true,
179181
"source": "integrate($x**2$, $x$, $y$);"
180182
},
181183
{
@@ -213,12 +215,146 @@
213215
"source": "\\begin{dmath*}{}\\frac{1}{4}{y}^{2}\\end{dmath*}"
214216
}
215217
],
218+
"ignore_on_import": true,
216219
"source": "integrate($x y$, ($x$, 0, 1), $y$);"
217220
},
221+
{
222+
"cell_id": 15496749977354253222,
223+
"cell_origin": "client",
224+
"cell_type": "latex",
225+
"cells": [
226+
{
227+
"cell_id": 11565454487843639642,
228+
"cell_origin": "client",
229+
"cell_type": "latex_view",
230+
"source": "\\algorithm{limit}{Take the limit of an expression.}\n\nThis function mimics the SymPy \\verb|limit| function, except that all\nmathematical expressions need to be Cadabra expressions."
231+
}
232+
],
233+
"source": "\\algorithm{limit}{Take the limit of an expression.}\n\nThis function mimics the SymPy \\verb|limit| function, except that all\nmathematical expressions need to be Cadabra expressions."
234+
},
218235
{
219236
"cell_id": 14261374590043911759,
220237
"cell_origin": "client",
221238
"cell_type": "input",
239+
"source": "def limit(ex, v, loc, *args):\n ret = $@(ex)$\n sbex = SympyBridge(ret)\n sbvar = SympyBridge(v).to_sympy()\n sbloc = SympyBridge(loc).to_sympy() if isinstance(loc, Ex) else loc\n sbex.from_sympy( str(sympy.limit( sbex.to_sympy(), sbvar, sbloc ) ) )\n return ret"
240+
},
241+
{
242+
"cell_id": 15671206733202710229,
243+
"cell_origin": "client",
244+
"cell_type": "input",
245+
"cells": [
246+
{
247+
"cell_id": 8723327984628819396,
248+
"cell_origin": "server",
249+
"cell_type": "latex_view",
250+
"cells": [
251+
{
252+
"cell_id": 3839762579849277582,
253+
"cell_origin": "server",
254+
"cell_type": "input_form",
255+
"source": "1"
256+
}
257+
],
258+
"source": "\\begin{dmath*}{}1\\end{dmath*}"
259+
}
260+
],
261+
"ignore_on_import": true,
262+
"source": "limit($\\sin(x)/x$, $x$, 0);"
263+
},
264+
{
265+
"cell_id": 4403018984250840411,
266+
"cell_origin": "client",
267+
"cell_type": "latex",
268+
"cells": [
269+
{
270+
"cell_id": 11512538112824887976,
271+
"cell_origin": "client",
272+
"cell_type": "latex_view",
273+
"source": "\\algorithm{series}{Construct a Taylor series.}\n\nThis function mimics the SymPy \\verb|series| function, except that all\nmathematical expressions need to be Cadabra expressions."
274+
}
275+
],
276+
"hidden": true,
277+
"source": "\\algorithm{series}{Construct a Taylor series.}\n\nThis function mimics the SymPy \\verb|series| function, except that all\nmathematical expressions need to be Cadabra expressions."
278+
},
279+
{
280+
"cell_id": 1152336426546868041,
281+
"cell_origin": "client",
282+
"cell_type": "input",
283+
"source": "def series(ex, v, loc, order_, *args):\n ret = $@(ex)$\n sbex = SympyBridge(ret)\n sbvar = SympyBridge(v).to_sympy()\n sbloc = SympyBridge(loc).to_sympy() if isinstance(loc, Ex) else loc\n tmp = str(sympy.series( sbex.to_sympy(), sbvar, sbloc, order_ ) )\n tmp = tmp.replace(\"O(\", r\"\\bigO(\")\n sbex.from_sympy( tmp )\n return ret"
284+
},
285+
{
286+
"cell_id": 796023660136979964,
287+
"cell_origin": "client",
288+
"cell_type": "input",
289+
"cells": [
290+
{
291+
"cell_id": 3415134206898553614,
292+
"cell_origin": "server",
293+
"cell_type": "latex_view",
294+
"cells": [
295+
{
296+
"cell_id": 17449491732516654073,
297+
"cell_origin": "server",
298+
"cell_type": "input_form",
299+
"source": "1 - 1/6 (x)**2 + \\bigO((x)**4)"
300+
}
301+
],
302+
"source": "\\begin{dmath*}{}1 - \\frac{1}{6}{x}^{2}+\\bigO\\left({x}^{4}\\right)\\end{dmath*}"
303+
}
304+
],
305+
"ignore_on_import": true,
306+
"source": "q=series($\\sin(x)/x$, $x$, 0, 4);"
307+
},
308+
{
309+
"cell_id": 12877610158835516880,
310+
"cell_origin": "client",
311+
"cell_type": "input",
312+
"cells": [
313+
{
314+
"cell_id": 16889301844141721001,
315+
"cell_origin": "server",
316+
"cell_type": "latex_view",
317+
"cells": [
318+
{
319+
"cell_id": 15333461881261583200,
320+
"cell_origin": "server",
321+
"cell_type": "input_form",
322+
"source": "1 - 1/6 (x)**2"
323+
}
324+
],
325+
"source": "\\begin{dmath*}{}1 - \\frac{1}{6}{x}^{2}\\end{dmath*}"
326+
}
327+
],
328+
"ignore_on_import": true,
329+
"source": "substitute(q, $\\bigO(A??) ->0$);"
330+
},
331+
{
332+
"cell_id": 6061726248509003999,
333+
"cell_origin": "client",
334+
"cell_type": "input",
335+
"cells": [
336+
{
337+
"cell_id": 8301222040948595643,
338+
"cell_origin": "server",
339+
"cell_type": "latex_view",
340+
"cells": [
341+
{
342+
"cell_id": 6578198996268257631,
343+
"cell_origin": "server",
344+
"cell_type": "input_form",
345+
"source": " 1/2 \\sqrt(2)-\\sqrt(2) ( 1/2 x - 1/8 \\pi) + \\bigO((x - 1/4 \\pi)**2 , {x, 1/4 \\pi})"
346+
}
347+
],
348+
"source": "\\begin{dmath*}{}\\frac{1}{2}\\sqrt{2}-\\sqrt{2} \\left(\\frac{1}{2}x - \\frac{1}{8}\\pi\\right)+\\bigO\\left({\\left(x - \\frac{1}{4}\\pi\\right)}^{2} , \\discretionary{}{}{}\\left[x,~\\discretionary{}{}{} \\frac{1}{4}\\pi\\right]\\right)\\end{dmath*}"
349+
}
350+
],
351+
"ignore_on_import": true,
352+
"source": "series($\\cos(x)$, $x$, $\\pi/4$, 2);"
353+
},
354+
{
355+
"cell_id": 16349293761953373413,
356+
"cell_origin": "client",
357+
"cell_type": "input",
222358
"source": ""
223359
}
224360
],

frontend/common/preamble.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
\renewcommand{\author}[1]{{\bfseries \detokenize{#1}}}
4040
\newcommand{\email}[1]{, {\tt \detokenize{#1}}}
4141

42+
\newcommand{\bigO}{{\cal O}}
43+
4244
% \newcommand{\sequence}[2]{{#1}\ldots{#2}}
4345

4446
% Math expressions wrapped in \brwrap will get typeset with

tests/sympy_cdb.cdb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,15 @@ def test04():
5555
print("Test 04 passed")
5656

5757
test04()
58+
59+
from cdb.sympy.calculus import integrate
60+
61+
def test05():
62+
__cdbkernel__=create_scope()
63+
ex:= \exp(-x);
64+
tst = integrate(ex, ($x$, 0, $\infty$))
65+
assert(tst==1)
66+
print("Test 05 passed")
67+
68+
test05()
5869

web2/cadabra2/source/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
</div>
197197

198198
<div id="bottombar">
199-
<div id="bottomleft">Copyright &copy; 2001-2021 Kasper Peeters</div>
199+
<div id="bottomleft">Copyright &copy; 2001-2022 Kasper Peeters</div>
200200
<div id="bottomright">Questions? <a href="mailto:[email protected]">[email protected]</a></div>
201201
</div>
202202

0 commit comments

Comments
 (0)