Skip to content

Commit 3bdeba4

Browse files
committed
Add option 'redundant' to eliminate_metric (David).
1 parent 6b9c46f commit 3bdeba4

File tree

8 files changed

+219
-77
lines changed

8 files changed

+219
-77
lines changed

core/algorithms/eliminate_metric.cc

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
using namespace cadabra;
1010

11-
eliminate_metric::eliminate_metric(const Kernel& k, Ex& e, Ex& pref)
12-
: eliminate_converter(k, e, pref)
11+
eliminate_metric::eliminate_metric(const Kernel& k, Ex& e, Ex& pref, bool redundant)
12+
: eliminate_converter(k, e, pref, redundant)
1313
{
1414
}
1515

@@ -22,8 +22,8 @@ bool eliminate_metric::is_conversion_object(iterator fit) const
2222
else return false;
2323
}
2424

25-
eliminate_converter::eliminate_converter(const Kernel& k, Ex& e, Ex& pref)
26-
: Algorithm(k, e), preferred(pref)
25+
eliminate_converter::eliminate_converter(const Kernel& k, Ex& e, Ex& pref, bool redun)
26+
: Algorithm(k, e), preferred(pref), redundant(redun)
2727
{
2828
}
2929

@@ -128,19 +128,23 @@ Algorithm::result_t eliminate_converter::apply(iterator& it)
128128
if(is_conversion_object(fit)) {
129129
index_iterator ind1=index_iterator::begin(kernel.properties, fit), ind2=ind1;
130130
++ind2;
131+
132+
if (!redundant || (ind_free.find(Ex(ind1)) == ind_free.end() &&
133+
ind_free.find(Ex(ind2)) == ind_free.end())) {
134+
// 1st index to 2nd index conversion?
135+
if(handle_one_index(ind1, ind2, fit, objs)) {
136+
res=result_t::l_applied;
137+
break;
138+
}
139+
140+
// 2nd index to 1st index conversion?
141+
if(handle_one_index(ind2, ind1, fit, objs)) {
142+
res=result_t::l_applied;
143+
break;
144+
}
145+
}
146+
}
131147

132-
// 1st index to 2nd index conversion?
133-
if(handle_one_index(ind1, ind2, fit, objs)) {
134-
res=result_t::l_applied;
135-
break;
136-
}
137-
138-
// 2nd index to 1st index conversion?
139-
if(handle_one_index(ind2, ind1, fit, objs)) {
140-
res=result_t::l_applied;
141-
break;
142-
}
143-
}
144148
++fit;
145149
}
146150

Lines changed: 158 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,185 @@
11
{
2-
"cells" :
3-
[
2+
"cell_id": 12201017813844474228,
3+
"cells": [
44
{
5-
"cell_origin" : "client",
6-
"cell_type" : "latex",
7-
"cells" :
8-
[
5+
"cell_id": 11200548926868858386,
6+
"cell_origin": "client",
7+
"cell_type": "latex",
8+
"cells": [
99
{
10-
"cell_origin" : "client",
11-
"cell_type" : "latex_view",
12-
"source" : "\\algorithm{eliminate_metric}{Eliminate metrics by raising or lowering indices.}\n\nEliminate metric and inverse metric objects by raising or lowering indices."
10+
"cell_id": 706940583944905291,
11+
"cell_origin": "client",
12+
"cell_type": "latex_view",
13+
"source": "\\algorithm{eliminate_metric}{Eliminate metrics by raising or lowering indices.}\n\nEliminate metric and inverse metric objects by raising or lowering indices."
1314
}
1415
],
15-
"hidden" : true,
16-
"source" : "\\algorithm{eliminate_metric}{Eliminate metrics by raising or lowering indices.}\n\nEliminate metric and inverse metric objects by raising or lowering indices."
16+
"hidden": true,
17+
"source": "\\algorithm{eliminate_metric}{Eliminate metrics by raising or lowering indices.}\n\nEliminate metric and inverse metric objects by raising or lowering indices."
1718
},
1819
{
19-
"cell_origin" : "client",
20-
"cell_type" : "input",
21-
"cells" :
22-
[
20+
"cell_id": 9501239282791426272,
21+
"cell_origin": "client",
22+
"cell_type": "input",
23+
"cells": [
2324
{
24-
"cell_origin" : "server",
25-
"cell_type" : "latex_view",
26-
"source" : "\\begin{dmath*}{}g_{m p} g^{p m}\\end{dmath*}"
25+
"cell_id": 13340122236411534882,
26+
"cell_origin": "server",
27+
"cell_type": "latex_view",
28+
"cells": [
29+
{
30+
"cell_id": 11333410999712696013,
31+
"cell_origin": "server",
32+
"cell_type": "input_form",
33+
"source": "g_{m p} g^{p m}"
34+
}
35+
],
36+
"source": "\\begin{dmath*}{}g_{m p} g^{p m}\\end{dmath*}"
2737
},
2838
{
29-
"cell_origin" : "server",
30-
"cell_type" : "latex_view",
31-
"source" : "\\begin{dmath*}{}g^{p}\\,_{p}\\end{dmath*}"
39+
"cell_id": 17894985963178002384,
40+
"cell_origin": "server",
41+
"cell_type": "latex_view",
42+
"cells": [
43+
{
44+
"cell_id": 5593101152482251246,
45+
"cell_origin": "server",
46+
"cell_type": "input_form",
47+
"source": "g^{p}_{p}"
48+
}
49+
],
50+
"source": "\\begin{dmath*}{}g^{p}\\,_{p}\\end{dmath*}"
3251
}
3352
],
34-
"source" : "{m, n, p, q, r}::Indices(vector, position=fixed).\n{m, n, p, q, r}::Integer(0..9).\ng_{m n}::Metric.\ng^{m n}::InverseMetric.\ng_{m}^{n}::KroneckerDelta.\ng^{m}_{n}::KroneckerDelta.\nex:=g_{m p} g^{p m};\neliminate_metric(_);"
53+
"source": "{m, n, p, q, r}::Indices(vector, position=fixed).\n{m, n, p, q, r}::Integer(0..9).\ng_{m n}::Metric.\ng^{m n}::InverseMetric.\ng_{m}^{n}::KroneckerDelta.\ng^{m}_{n}::KroneckerDelta.\nex:=g_{m p} g^{p m};\neliminate_metric(_);"
3554
},
3655
{
37-
"cell_origin" : "client",
38-
"cell_type" : "input",
39-
"cells" :
40-
[
56+
"cell_id": 7815987119515900884,
57+
"cell_origin": "client",
58+
"cell_type": "input",
59+
"cells": [
4160
{
42-
"cell_origin" : "server",
43-
"cell_type" : "latex_view",
44-
"source" : "\\begin{dmath*}{}10\\end{dmath*}"
61+
"cell_id": 11832355180757837612,
62+
"cell_origin": "server",
63+
"cell_type": "latex_view",
64+
"cells": [
65+
{
66+
"cell_id": 1419432383822709486,
67+
"cell_origin": "server",
68+
"cell_type": "input_form",
69+
"source": "10"
70+
}
71+
],
72+
"source": "\\begin{dmath*}{}10\\end{dmath*}"
4573
}
4674
],
47-
"source" : "eliminate_kronecker(_);"
75+
"source": "eliminate_kronecker(_);"
4876
},
4977
{
50-
"cell_origin" : "client",
51-
"cell_type" : "latex",
52-
"cells" :
53-
[
78+
"cell_id": 11136087069753532813,
79+
"cell_origin": "client",
80+
"cell_type": "latex",
81+
"cells": [
5482
{
55-
"cell_origin" : "client",
56-
"cell_type" : "latex_view",
57-
"source" : "Related algorithms are \\algo{eliminate_kronecker} and \\algo{eliminate_vielbein}."
83+
"cell_id": 10975080456446455892,
84+
"cell_origin": "client",
85+
"cell_type": "latex_view",
86+
"source": "Related algorithms are \\algo{eliminate_kronecker} and \\algo{eliminate_vielbein}."
5887
}
5988
],
60-
"hidden" : true,
61-
"source" : "Related algorithms are \\algo{eliminate_kronecker} and \\algo{eliminate_vielbein}."
89+
"hidden": true,
90+
"source": "Related algorithms are \\algo{eliminate_kronecker} and \\algo{eliminate_vielbein}."
6291
},
6392
{
64-
"cell_origin" : "client",
65-
"cell_type" : "input",
66-
"source" : ""
93+
"cell_id": 668070063135773764,
94+
"cell_origin": "client",
95+
"cell_type": "latex",
96+
"cells": [
97+
{
98+
"cell_id": 2955225009111573646,
99+
"cell_origin": "client",
100+
"cell_type": "latex_view",
101+
"source": "It is sometimes useful to eliminate only those metrics which have two\ndummy indices (so as to avoid changing indices on non-metric factors),\nas in the following example:"
102+
}
103+
],
104+
"hidden": true,
105+
"source": "It is sometimes useful to eliminate only those metrics which have two\ndummy indices (so as to avoid changing indices on non-metric factors),\nas in the following example:"
106+
},
107+
{
108+
"cell_id": 7674476649362588094,
109+
"cell_origin": "client",
110+
"cell_type": "input",
111+
"cells": [
112+
{
113+
"cell_id": 2830738818925621002,
114+
"cell_origin": "server",
115+
"cell_type": "latex_view",
116+
"source": "\\begin{dmath*}{}\\text{Property Indices(position=fixed) attached to~}\\left[a,~\\discretionary{}{}{} b,~\\discretionary{}{}{} c,~\\discretionary{}{}{} d,~\\discretionary{}{}{} e,~\\discretionary{}{}{} f\\right].\\end{dmath*}"
117+
},
118+
{
119+
"cell_id": 9384043968720976150,
120+
"cell_origin": "server",
121+
"cell_type": "latex_view",
122+
"source": "\\begin{dmath*}{}\\text{Property Metric attached to~}g_{a b}.\\end{dmath*}"
123+
},
124+
{
125+
"cell_id": 3632907748806720927,
126+
"cell_origin": "server",
127+
"cell_type": "latex_view",
128+
"source": "\\begin{dmath*}{}\\text{Property TableauSymmetry attached to~}g^{a b}.\\end{dmath*}"
129+
},
130+
{
131+
"cell_id": 14029841914135557336,
132+
"cell_origin": "server",
133+
"cell_type": "latex_view",
134+
"cells": [
135+
{
136+
"cell_id": 16107652404209191630,
137+
"cell_origin": "server",
138+
"cell_type": "input_form",
139+
"source": "X_{a} g^{a b} g_{b c} g^{c d} g_{d e} g^{e f}"
140+
}
141+
],
142+
"source": "\\begin{dmath*}{}X_{a} g^{a b} g_{b c} g^{c d} g_{d e} g^{e f}\\end{dmath*}"
143+
},
144+
{
145+
"cell_id": 11123767540161473056,
146+
"cell_origin": "server",
147+
"cell_type": "latex_view",
148+
"cells": [
149+
{
150+
"cell_id": 10523281001881141507,
151+
"cell_origin": "server",
152+
"cell_type": "input_form",
153+
"source": "X_{e} g^{e f}"
154+
}
155+
],
156+
"source": "\\begin{dmath*}{}X_{e} g^{e f}\\end{dmath*}"
157+
}
158+
],
159+
"source": "{a,b,c,d,e,f}::Indices(position=fixed);\ng_{a b}::Metric;\ng^{a b}::InverseMetric;\nex:=X_{a} g^{a b} g_{b c} g^{c d} g_{d e} g^{e f};\neliminate_metric(ex, repeat=True, redundant=True);"
160+
},
161+
{
162+
"cell_id": 10177437379030071371,
163+
"cell_origin": "client",
164+
"cell_type": "latex",
165+
"cells": [
166+
{
167+
"cell_id": 1237014864296849726,
168+
"cell_origin": "client",
169+
"cell_type": "latex_view",
170+
"source": "Without the \\verb|redundant=True| option, this would have reduced the \nexpression to $X^{f}$."
171+
}
172+
],
173+
"hidden": true,
174+
"source": "Without the \\verb|redundant=True| option, this would have reduced the \nexpression to $X^{f}$."
175+
},
176+
{
177+
"cell_id": 8153574234349350675,
178+
"cell_origin": "client",
179+
"cell_type": "input",
180+
"source": ""
67181
}
68182
],
69-
"description" : "Cadabra JSON notebook format",
70-
"version" : 1
183+
"description": "Cadabra JSON notebook format",
184+
"version": 1.0
71185
}

core/algorithms/eliminate_metric.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace cadabra {
88

99
class eliminate_converter : public Algorithm {
1010
public:
11-
eliminate_converter(const Kernel&, Ex&, Ex&);
11+
eliminate_converter(const Kernel&, Ex&, Ex&, bool);
1212

1313
virtual bool can_apply(iterator) override;
1414
virtual result_t apply(iterator&) override;
@@ -19,6 +19,7 @@ namespace cadabra {
1919
private:
2020
Ex preferred;
2121
index_map_t ind_dummy, ind_free;
22+
bool redundant;
2223

2324
/// See if the conversion which turns index 'i1' into index
2425
/// 'i2' can be applied on the expression, so that it gets a
@@ -33,7 +34,7 @@ namespace cadabra {
3334

3435
class eliminate_metric : public eliminate_converter {
3536
public:
36-
eliminate_metric(const Kernel&, Ex&, Ex&);
37+
eliminate_metric(const Kernel&, Ex&, Ex&, bool);
3738

3839
protected:
3940
virtual bool is_conversion_object(iterator) const override;

core/algorithms/eliminate_vielbein.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
using namespace cadabra;
66

7-
eliminate_vielbein::eliminate_vielbein(const Kernel& k, Ex& e, Ex& pref)
8-
: eliminate_converter(k, e, pref)
7+
eliminate_vielbein::eliminate_vielbein(const Kernel& k, Ex& e, Ex& pref, bool redundant)
8+
: eliminate_converter(k, e, pref, redundant)
99
{
1010
}
1111

core/algorithms/eliminate_vielbein.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace cadabra {
77

88
class eliminate_vielbein : public eliminate_converter {
99
public:
10-
eliminate_vielbein(const Kernel&, Ex&, Ex&);
10+
eliminate_vielbein(const Kernel&, Ex&, Ex&, bool);
1111

1212
protected:
1313
virtual bool is_conversion_object(iterator) const override;

core/pythoncdb/py_algorithms.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ namespace cadabra {
103103
def_algo<complete, Ex>(m, "complete", false, false, 0, py::arg("add"));
104104
def_algo<decompose, Ex>(m, "decompose", false, false, 0, py::arg("basis"));
105105
def_algo<drop_weight, Ex>(m, "drop_weight", false, false, 0, py::arg("condition") = Ex{});
106-
def_algo<eliminate_metric, Ex>(m, "eliminate_metric", true, false, 0, py::arg("preferred") = Ex{});
107-
def_algo<eliminate_vielbein, Ex>(m, "eliminate_vielbein", true, false, 0, py::arg("preferred") = Ex{});
106+
def_algo<eliminate_metric, Ex,bool>(m, "eliminate_metric", true, false, 0, py::arg("preferred") = Ex{}, py::arg("redundant") = false);
107+
def_algo<eliminate_vielbein, Ex,bool>(m, "eliminate_vielbein", true, false, 0, py::arg("preferred") = Ex{},py::arg("redundant")= false);
108108
def_algo<keep_weight, Ex>(m, "keep_weight", false, false, 0, py::arg("condition"));
109109
def_algo<lower_free_indices, bool>(m, "lower_free_indices", true, false, 0, py::arg("lower") = true);
110110
def_algo<lower_free_indices, bool>(m, "raise_free_indices", true, false, 0, py::arg("lower") = false);

tests/relativity.cdb

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ def test13():
167167

168168
test13()
169169

170+
def test14():
171+
__cdbkernel__=create_scope()
172+
{a,b,c,d,e,f}::Indices(position=fixed);
173+
g_{a b}::Metric().
174+
g^{a b}::InverseMetric().
175+
A:=X_{a} g^{a b} g_{b c} g^{c d} g_{d e} g^{e f};
176+
eliminate_metric(_, repeat=True)
177+
tst:= X^{f} - @(A);
178+
assert(tst==0)
179+
print("Test 14a passed")
180+
A:=X_{a} g^{a b} g_{b c} g^{c d} g_{d e} g^{e f};
181+
eliminate_metric(_, repeat=True, redundant=True)
182+
tst:= X_{e} g^{e f} - @(A);
183+
assert(tst==0)
184+
print("Test 14b passed")
185+
186+
test14()
187+
188+
170189

171190
# { m, n, p }::Indices(flat).
172191
# { \mu, \nu, \rho }::Indices(curved).
@@ -175,15 +194,17 @@ test13()
175194
# ex:= e_{m}^{\mu} e^{m}_{\nu};
176195
# eliminate_vielbein(_);
177196

178-
def post_process(ex):
179-
substitute(ex, $\delta^{0}_{\alpha} -> 0$)
180-
return ex
197+
# def post_process(ex):
198+
# substitute(ex, $\delta^{0}_{\alpha} -> 0$)
199+
# return ex
200+
#
201+
# {a,b,c,d,e}::Indices(fourD, position=independent);
202+
# {a,b,c,d,e}::Integer(0..4);
203+
# {\alpha,\beta,\gamma,\delta,\epsilon}::Indices(threeD, position=independent, parent=fourD);
204+
# {\alpha,\beta,\gamma,\delta,\epsilon}::Integer(1..3);
205+
# \delta{#}::KroneckerDelta();
206+
# ex := \gamma^{\alpha \beta} \delta^{0}_{d} \delta^{d}_{\alpha};
207+
# eliminate_kronecker(ex, repeat=False);
208+
181209

182-
{a,b,c,d,e}::Indices(fourD, position=independent);
183-
{a,b,c,d,e}::Integer(0..4);
184-
{\alpha,\beta,\gamma,\delta,\epsilon}::Indices(threeD, position=independent, parent=fourD);
185-
{\alpha,\beta,\gamma,\delta,\epsilon}::Integer(1..3);
186-
\delta{#}::KroneckerDelta();
187-
ex := \gamma^{\alpha \beta} \delta^{0}_{d} \delta^{d}_{\alpha};
188-
eliminate_kronecker(ex, repeat=False);
189210

0 commit comments

Comments
 (0)