Skip to content

Commit 6b9aacf

Browse files
committed
Missing files
1 parent 535f630 commit 6b9aacf

File tree

4 files changed

+221
-0
lines changed

4 files changed

+221
-0
lines changed

core/algorithms/map_sympy.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
#include "algorithms/map_sympy.hh"
3+
#include "properties/Coordinate.hh"
4+
#include "properties/Symbol.hh"
5+
#include "SympyCdb.hh"
6+
7+
using namespace cadabra;
8+
9+
map_sympy::map_sympy(const Kernel& k, Ex& tr, const std::string& head)
10+
: Algorithm(k, tr), head_(head)
11+
{
12+
}
13+
14+
bool map_sympy::can_apply(iterator st)
15+
{
16+
index_map_t ind_free, ind_dummy;
17+
classify_indices(st, ind_free, ind_dummy);
18+
for(auto& ind: ind_free) {
19+
const Coordinate *cdn=kernel.properties.get_composite<Coordinate>(ind.second, true);
20+
const Symbol *smb=kernel.properties.get_composite<Symbol>(ind.second, true);
21+
if(cdn==false && smb==false)
22+
return false;
23+
}
24+
return (ind_dummy.size()==0);
25+
}
26+
27+
Algorithm::result_t map_sympy::apply(iterator& it)
28+
{
29+
std::vector<std::string> wrap;
30+
wrap.push_back(head_);
31+
sympy::apply(kernel, tr, it, wrap, "", "");
32+
it.skip_children();
33+
return result_t::l_applied;
34+
}

core/algorithms/map_sympy.hh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
#pragma once
3+
4+
#include "Algorithm.hh"
5+
6+
namespace cadabra {
7+
8+
/// \ingroup algorithms
9+
///
10+
/// Functionality to act with Sympy on all scalar parts of an expression, and
11+
/// keep the result in-place. This is a higher-level thing than
12+
/// 'sympy::apply' in the SympyCdb.cc module.
13+
14+
class map_sympy : public Algorithm {
15+
public:
16+
map_sympy(const Kernel&, Ex&, const std::string& head);
17+
18+
virtual bool can_apply(iterator);
19+
virtual result_t apply(iterator&);
20+
21+
private:
22+
std::string head_;
23+
};
24+
25+
}
26+

frontend/gtkmm/Preferences.hh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
#pragma once
3+
4+
#include <gtkmm/window.h>
5+
#include <gtkmm/box.h>
6+
7+
class PreferencesWindow : public class Gtk::Window {
8+
public:
9+
private:
10+
Gtk::VBox mainbox;
11+
Gtk::
12+
};

tests/display.cnb

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cells" :
3+
[
4+
{
5+
"cell_origin" : "client",
6+
"cell_type" : "input",
7+
"cells" :
8+
[
9+
{
10+
"cell_origin" : "server",
11+
"cell_type" : "latex_view",
12+
"source" : "\\begin{dmath*}{}\\text{Attached property PartialDerivative to~}\\partial{\\#}.\\end{dmath*}"
13+
},
14+
{
15+
"cell_origin" : "server",
16+
"cell_type" : "latex_view",
17+
"source" : "\\begin{dmath*}{}\\text{Attached property Depends to~}A.\\end{dmath*}"
18+
},
19+
{
20+
"cell_origin" : "server",
21+
"cell_type" : "latex_view",
22+
"source" : "\\begin{dmath*}{}\\text{Attached property Coordinate to~}r.\\end{dmath*}"
23+
}
24+
],
25+
"source" : "\\partial{#}::PartialDerivative;\nA::Depends(r);\nr::Coordinate;"
26+
},
27+
{
28+
"cell_origin" : "client",
29+
"cell_type" : "input",
30+
"cells" :
31+
[
32+
{
33+
"cell_origin" : "server",
34+
"cell_type" : "latex_view",
35+
"source" : "\\begin{dmath*}{}{\\left(\\partial_{r}{{\\left(\\sin{A}\\right)}^{2}}\\right)}^{2}+{\\left(\\partial_{r}{{A}^{2}}\\right)}^{2}+{\\left(\\partial_{r}{{r}^{2}}\\right)}^{2}\\end{dmath*}"
36+
}
37+
],
38+
"source" : "ex:= \\partial_{r}{\\sin{A}**2}**2 +\\partial_{r}{A**2}**2 + \\partial_{r}{ r**2 }**2;"
39+
},
40+
{
41+
"cell_origin" : "client",
42+
"cell_type" : "input",
43+
"cells" :
44+
[
45+
{
46+
"cell_origin" : "server",
47+
"cell_type" : "latex_view",
48+
"source" : "\\begin{dmath*}{}4{r}^{2}+\\frac{1}{2}\\left(-\\cos{4A}+1\\right) {\\left(\\partial_{r}{A}\\right)}^{2}+4{A}^{2} {\\left(\\partial_{r}{A}\\right)}^{2}\\end{dmath*}"
49+
}
50+
],
51+
"source" : "scas(ex,\"simplify\");"
52+
},
53+
{
54+
"cell_origin" : "client",
55+
"cell_type" : "input",
56+
"cells" :
57+
[
58+
{
59+
"cell_origin" : "server",
60+
"cell_type" : "output",
61+
"source" : "\\begin{verbatim}{\\sum} (0x7f26d4029738)\n 1:{\\pow} (0x7f26d401f8d8)\n 2: {\\partial} (0x7f26d4021e78)\n 3: _{r} (0x7f26d4033008)\n 4: {\\pow} (0x7f26d4033058)\n 5: {\\sin} (0x7f26d40341c8)\n 6: {A} (0x7f26d400b148)\n 7: {1} 2 (0x7f26d4034218)\n 8: {1} 2 (0x7f26d4044828)\n 9:{\\pow} (0x7f26d4044878)\n 10: {\\partial} (0x7f26d4027ca8)\n 11: _{r} (0x7f26d4027cf8)\n 12: {\\pow} (0x7f26d4031228)\n 13: {A} (0x7f26d4031278)\n 14: {1} 2 (0x7f26d40344b8)\n 15: {1} 2 (0x7f26d4034508)\n 16:{\\pow} (0x7f26d4027e88)\n 17: {\\partial} (0x7f26d4027ed8)\n 18: _{r} (0x7f26d4046c18)\n 19: {\\pow} (0x7f26d4046c68)\n 20: {r} (0x7f26d4036bf8)\n 21: {1} 2 (0x7f26d4036c48)\n 22: {1} 2 (0x7f26d4036c98)\n\n\\end{verbatim}"
62+
}
63+
],
64+
"source" : "print(tree(ex))"
65+
},
66+
{
67+
"cell_origin" : "client",
68+
"cell_type" : "input",
69+
"cells" :
70+
[
71+
{
72+
"cell_origin" : "server",
73+
"cell_type" : "latex_view",
74+
"source" : "\\begin{dmath*}{}\\partial_{r}{{r}^{2}}\\end{dmath*}"
75+
}
76+
],
77+
"source" : "ex2:= \\partial_{r}{r**2};"
78+
},
79+
{
80+
"cell_origin" : "client",
81+
"cell_type" : "input",
82+
"cells" :
83+
[
84+
{
85+
"cell_origin" : "server",
86+
"cell_type" : "latex_view",
87+
"source" : "\\begin{dmath*}{}2r\\end{dmath*}"
88+
}
89+
],
90+
"source" : "ex3=scas(ex2, \"simplify\");"
91+
},
92+
{
93+
"cell_origin" : "client",
94+
"cell_type" : "input",
95+
"cells" :
96+
[
97+
{
98+
"cell_origin" : "server",
99+
"cell_type" : "latex_view",
100+
"source" : "\\begin{dmath*}{}\\partial_{r}{{r}^{2}}\\end{dmath*}"
101+
},
102+
{
103+
"cell_origin" : "server",
104+
"cell_type" : "latex_view",
105+
"source" : "\\begin{dmath*}{}2r\\end{dmath*}"
106+
}
107+
],
108+
"source" : "ex2;\nex3;"
109+
},
110+
{
111+
"cell_origin" : "client",
112+
"cell_type" : "input",
113+
"cells" :
114+
[
115+
{
116+
"cell_origin" : "server",
117+
"cell_type" : "latex_view",
118+
"source" : "\\begin{dmath*}{}4 r^{2} + 4 A^{2}{\\left (r \\right )} \\frac{d}{d r} A{\\left (r \\right )}^{2} + 4 \\sin^{2}{\\left (A{\\left (r \\right )} \\right )} \\cos^{2}{\\left (A{\\left (r \\right )} \\right )} \\frac{d}{d r} A{\\left (r \\right )}^{2}\\end{dmath*}"
119+
},
120+
{
121+
"cell_origin" : "server",
122+
"cell_type" : "output",
123+
"source" : "\\begin{verbatim}<class 'sympy.core.add.Add'>\n\\end{verbatim}"
124+
}
125+
],
126+
"source" : "s = ex._sympy_();\nprint(type(s))"
127+
},
128+
{
129+
"cell_origin" : "client",
130+
"cell_type" : "input",
131+
"cells" :
132+
[
133+
{
134+
"cell_origin" : "server",
135+
"cell_type" : "latex_view",
136+
"source" : "\\begin{dmath*}{}{\\left(\\partial_{r}{{\\left(\\sin{A}\\right)}^{2}}\\right)}^{2}+{\\left(\\partial_{r}{{A}^{2}}\\right)}^{2}+{\\left(\\partial_{r}{{r}^{2}}\\right)}^{2}\\end{dmath*}"
137+
}
138+
],
139+
"source" : "ex;"
140+
},
141+
{
142+
"cell_origin" : "client",
143+
"cell_type" : "input",
144+
"source" : ""
145+
}
146+
],
147+
"description" : "Cadabra JSON notebook format",
148+
"version" : 1
149+
}

0 commit comments

Comments
 (0)