Skip to content

Commit 09b71ba

Browse files
committed
Manual and fixes for map_sympy
1 parent 8221b02 commit 09b71ba

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed

core/algorithms/map_sympy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
using namespace cadabra;
88

9-
#define DEBUG 1
9+
//#define DEBUG 1
1010

1111
map_sympy::map_sympy(const Kernel& k, Ex& tr, const std::string& head)
1212
: Algorithm(k, tr), head_(head)

core/algorithms/map_sympy.cnb

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
"cells" :
3+
[
4+
{
5+
"cell_origin" : "client",
6+
"cell_type" : "latex",
7+
"cells" :
8+
[
9+
{
10+
"cell_origin" : "client",
11+
"cell_type" : "latex_view",
12+
"source" : "\\algorithm{map_sympy}{Map Sympy algorithms to Cadabra expressions}\n\nCadabra expressions are typically tensor expressions, which you cannot feed directly\ninto Sympy. With the \\algo{map_sympy} function you can recursively apply Sympy algorithms\nto the scalar parts of Cadabra expressions.\n\nThe simplest example is when you have a scalar expression in Cadabra, for instance"
13+
}
14+
],
15+
"hidden" : true,
16+
"source" : "\\algorithm{map_sympy}{Map Sympy algorithms to Cadabra expressions}\n\nCadabra expressions are typically tensor expressions, which you cannot feed directly\ninto Sympy. With the \\algo{map_sympy} function you can recursively apply Sympy algorithms\nto the scalar parts of Cadabra expressions.\n\nThe simplest example is when you have a scalar expression in Cadabra, for instance"
17+
},
18+
{
19+
"cell_origin" : "client",
20+
"cell_type" : "input",
21+
"cells" :
22+
[
23+
{
24+
"cell_origin" : "server",
25+
"cell_type" : "latex_view",
26+
"source" : "\\begin{dmath*}{}\\int \\sin{x}\\,\\,{\\rm d}x\\end{dmath*}"
27+
}
28+
],
29+
"source" : "ex:= \\int{\\sin(x)}{x};"
30+
},
31+
{
32+
"cell_origin" : "client",
33+
"cell_type" : "input",
34+
"cells" :
35+
[
36+
{
37+
"cell_origin" : "server",
38+
"cell_type" : "latex_view",
39+
"source" : "\\begin{dmath*}{}-\\cos{x}\\end{dmath*}"
40+
}
41+
],
42+
"source" : "map_sympy(ex);"
43+
},
44+
{
45+
"cell_origin" : "client",
46+
"cell_type" : "latex",
47+
"cells" :
48+
[
49+
{
50+
"cell_origin" : "client",
51+
"cell_type" : "latex_view",
52+
"source" : "The inert Cadabra expression gets evaluated by Sympy and then stored again in the `ex` object,"
53+
}
54+
],
55+
"hidden" : true,
56+
"source" : "The inert Cadabra expression gets evaluated by Sympy and then stored again in the `ex` object,"
57+
},
58+
{
59+
"cell_origin" : "client",
60+
"cell_type" : "input",
61+
"cells" :
62+
[
63+
{
64+
"cell_origin" : "server",
65+
"cell_type" : "latex_view",
66+
"source" : "\\begin{dmath*}{}-\\cos{x}\\end{dmath*}"
67+
}
68+
],
69+
"source" : "ex;"
70+
},
71+
{
72+
"cell_origin" : "client",
73+
"cell_type" : "latex",
74+
"cells" :
75+
[
76+
{
77+
"cell_origin" : "client",
78+
"cell_type" : "latex_view",
79+
"source" : "In more complicated cases you may have a tensorial expression which you would like to \nsimplify using Sympy, for instance"
80+
}
81+
],
82+
"hidden" : true,
83+
"source" : "In more complicated cases you may have a tensorial expression which you would like to \nsimplify using Sympy, for instance"
84+
},
85+
{
86+
"cell_origin" : "client",
87+
"cell_type" : "input",
88+
"cells" :
89+
[
90+
{
91+
"cell_origin" : "server",
92+
"cell_type" : "latex_view",
93+
"source" : "\\begin{dmath*}{}\\left({\\left(\\sin{x}\\right)}^{2}+{\\left(\\cos{x}\\right)}^{2}\\right) A_{m}-A_{m}\\end{dmath*}"
94+
}
95+
],
96+
"source" : "ex:= (\\sin(x)**2 + \\cos(x)**2) A_{m} - A_{m};"
97+
},
98+
{
99+
"cell_origin" : "client",
100+
"cell_type" : "input",
101+
"cells" :
102+
[
103+
{
104+
"cell_origin" : "server",
105+
"cell_type" : "latex_view",
106+
"source" : "\\begin{dmath*}{}0\\end{dmath*}"
107+
}
108+
],
109+
"source" : "map_sympy(ex, \"simplify\");"
110+
},
111+
{
112+
"cell_origin" : "client",
113+
"cell_type" : "input",
114+
"source" : ""
115+
}
116+
],
117+
"description" : "Cadabra JSON notebook format",
118+
"version" : 1
119+
}

web2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ set(ALGOS
5454
join_gamma
5555
keep_weight
5656
lr_tensor
57+
map_sympy
5758
product_rule
5859
reduce_delta
5960
rename_dummies

0 commit comments

Comments
 (0)