Skip to content

Commit 1bfb692

Browse files
author
Kasper Peeters
committed
Use a notation which is closer to what SymPy uses.
1 parent b3d83ea commit 1bfb692

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

core/packages/cdb/sympy/calculus.cnb

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
"cell_type": "latex",
88
"cells": [
99
{
10-
"cell_id": 7825517350706958358,
10+
"cell_id": 9687610247019435570,
1111
"cell_origin": "client",
1212
"cell_type": "latex_view",
13-
"source": "\\package{cdb.sympy.calculus}{Use SymPy calculus functionality on Cadabra expressions.}\n\nA lot of functionality in SymPy can be used on Cadabra expressions, but in order to correctly\nconvert from and to the SymPy expression form, we need a bridge. This package contains such\nbridging fuctions, which will ensure that e.g. tensor indices are handled correctly when\nfed through SymPy's scalar algebra algorithms.\n\n\\algorithm{diff}{Differentiate an expression with respect to a variable.}"
13+
"source": "\\package{cdb.sympy.calculus}{Use SymPy calculus functionality on Cadabra expressions.}\n\nA lot of functionality in SymPy can be used on Cadabra expressions, but in order to correctly\nconvert from and to the SymPy expression form, we need a bridge. This package contains such\nbridging fuctions, which will ensure that e.g. tensor indices are handled correctly when\nfed through SymPy's scalar algebra algorithms.\n\n\\algorithm{diff}{Differentiate an expression with respect to one or more variables.}\n\nThis function mimics the SymPy \\verb|diff| function, except that all expressions need\nto be Cadabra expressions. The function takes an expression and an arbitrary number\nof variables with respect to which to differentiate it."
1414
}
1515
],
1616
"hidden": true,
17-
"source": "\\package{cdb.sympy.calculus}{Use SymPy calculus functionality on Cadabra expressions.}\n\nA lot of functionality in SymPy can be used on Cadabra expressions, but in order to correctly\nconvert from and to the SymPy expression form, we need a bridge. This package contains such\nbridging fuctions, which will ensure that e.g. tensor indices are handled correctly when\nfed through SymPy's scalar algebra algorithms.\n\n\\algorithm{diff}{Differentiate an expression with respect to a variable.}"
17+
"source": "\\package{cdb.sympy.calculus}{Use SymPy calculus functionality on Cadabra expressions.}\n\nA lot of functionality in SymPy can be used on Cadabra expressions, but in order to correctly\nconvert from and to the SymPy expression form, we need a bridge. This package contains such\nbridging fuctions, which will ensure that e.g. tensor indices are handled correctly when\nfed through SymPy's scalar algebra algorithms.\n\n\\algorithm{diff}{Differentiate an expression with respect to one or more variables.}\n\nThis function mimics the SymPy \\verb|diff| function, except that all expressions need\nto be Cadabra expressions. The function takes an expression and an arbitrary number\nof variables with respect to which to differentiate it."
1818
},
1919
{
2020
"cell_id": 3804610120254550473,
2121
"cell_origin": "client",
2222
"cell_type": "input",
23-
"source": "def diff(ex1, ex2):\n ret = $@(ex1)$\n sb = SympyBridge(ret)\n sb.from_sympy( str(sympy.diff( sb.to_sympy(), ex2 ) ) )\n return ret"
23+
"source": "def diff(ex, *args):\n ret = $@(ex)$\n sb = SympyBridge(ret)\n dvars = []\n for arg in args:\n sbtmp = SympyBridge(arg)\n dvars.append( sbtmp.to_sympy() )\n sb.from_sympy( str(sympy.diff( sb.to_sympy(), *dvars ) ) )\n return ret"
2424
},
2525
{
2626
"cell_id": 12308609622224851480,
@@ -43,36 +43,44 @@
4343
"cell_type": "input",
4444
"cells": [
4545
{
46-
"cell_id": 12523925591190418952,
46+
"cell_id": 1348085833411850626,
4747
"cell_origin": "server",
4848
"cell_type": "latex_view",
4949
"cells": [
5050
{
51-
"cell_id": 1379197150120835065,
51+
"cell_id": 16874039423838371410,
5252
"cell_origin": "server",
5353
"cell_type": "input_form",
54-
"source": "\\sin(x) A_{\\mu}(x)"
54+
"source": "A_{\\mu}(x) \\cos(x) + \\sin(x) \\partial_{x}(A_{\\mu}(x))"
5555
}
5656
],
57-
"source": "\\begin{dmath*}{}\\sin{x} A_{\\mu}\\left(x\\right)\\end{dmath*}"
58-
},
57+
"source": "\\begin{dmath*}{}A_{\\mu}\\left(x\\right) \\cos{x}+\\sin{x} \\partial_{x}\\left(A_{\\mu}\\left(x\\right)\\right)\\end{dmath*}"
58+
}
59+
],
60+
"ignore_on_import": true,
61+
"source": "diff($\\sin(x) A_{\\mu}(x)$, $x$);"
62+
},
63+
{
64+
"cell_id": 549591636986061462,
65+
"cell_origin": "client",
66+
"cell_type": "input",
67+
"cells": [
5968
{
60-
"cell_id": 7634624450130909684,
69+
"cell_id": 8841772239434008615,
6170
"cell_origin": "server",
6271
"cell_type": "latex_view",
6372
"cells": [
6473
{
65-
"cell_id": 1252059972554683227,
74+
"cell_id": 4066297813555277329,
6675
"cell_origin": "server",
6776
"cell_type": "input_form",
68-
"source": "A_{\\mu}(x) \\cos(x) + \\sin(x) \\partial_{x}(A_{\\mu}(x))"
77+
"source": "-\\sin(y) \\cos(x)"
6978
}
7079
],
71-
"source": "\\begin{dmath*}{}A_{\\mu}\\left(x\\right) \\cos{x}+\\sin{x} \\partial_{x}\\left(A_{\\mu}\\left(x\\right)\\right)\\end{dmath*}"
80+
"source": "\\begin{dmath*}{}-\\sin{y} \\cos{x}\\end{dmath*}"
7281
}
7382
],
74-
"ignore_on_import": true,
75-
"source": "ex:=\\sin(x) A_{\\mu}(x);\ndiff(ex, $x$);"
83+
"source": "diff($\\sin(x)\\cos(y)$, $x$, $y$);"
7684
},
7785
{
7886
"cell_id": 6234003092100779795,
@@ -116,12 +124,12 @@
116124
"cell_type": "input",
117125
"cells": [
118126
{
119-
"cell_id": 12012117006062441490,
127+
"cell_id": 17063052500213847361,
120128
"cell_origin": "server",
121129
"cell_type": "latex_view",
122130
"cells": [
123131
{
124-
"cell_id": 316157390348515815,
132+
"cell_id": 7172967486322218859,
125133
"cell_origin": "server",
126134
"cell_type": "input_form",
127135
"source": " 27/2 "
@@ -154,12 +162,12 @@
154162
"cell_type": "input",
155163
"cells": [
156164
{
157-
"cell_id": 15728598564050855914,
165+
"cell_id": 5978718279542050921,
158166
"cell_origin": "server",
159167
"cell_type": "latex_view",
160168
"cells": [
161169
{
162-
"cell_id": 13682162971051715272,
170+
"cell_id": 4267217324248610000,
163171
"cell_origin": "server",
164172
"cell_type": "input_form",
165173
"source": " 1/3 (x)**3 y"
@@ -191,12 +199,12 @@
191199
"cell_type": "input",
192200
"cells": [
193201
{
194-
"cell_id": 4095815210246821736,
202+
"cell_id": 9023252122610197719,
195203
"cell_origin": "server",
196204
"cell_type": "latex_view",
197205
"cells": [
198206
{
199-
"cell_id": 13733098240311066994,
207+
"cell_id": 2730904024514227788,
200208
"cell_origin": "server",
201209
"cell_type": "input_form",
202210
"source": " 1/4 (y)**2"

0 commit comments

Comments
 (0)