Skip to content

Commit 6d05b37

Browse files
committed
Fixes for evaluate
1 parent 34aab1f commit 6d05b37

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

core/SympyCdb.cc

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

1212
using namespace cadabra;
1313

14-
#define DEBUG
14+
//#define DEBUG
1515

1616
Ex::iterator sympy::apply(const Kernel& kernel, Ex& ex, Ex::iterator& it, const std::vector<std::string>& wrap, const std::string& args,
1717
const std::string& method)

tests/components.cdb

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ def test22():
418418
test22()
419419

420420
def test23():
421+
__cdbkernel__=create_scope()
421422
{r,t}::Coordinate;
422423
{a,b,c}::Indices(values={r,t}, position=fixed);
423424
\partial{#}::PartialDerivative;
@@ -453,33 +454,42 @@ test23()
453454
# rl:= \partial_{r}{ A_{t} } = 1;
454455
# evaluate(ex, rl);
455456

456-
{\theta, \varphi}::Coordinate;
457-
{\alpha, \beta, \gamma, \delta, \rho, \sigma, \mu, \nu, \lambda}::Indices(values={\varphi, \theta}, position=fixed);
458-
\partial{#}::PartialDerivative;
459-
g_{\alpha\beta}::Metric.
460-
g^{\alpha\beta}::InverseMetric.
457+
def test24():
458+
__cdbkernel__=create_scope()
459+
{\theta, \varphi}::Coordinate;
460+
{\alpha, \beta, \gamma, \delta, \rho, \sigma, \mu, \nu, \lambda}::Indices(values={\varphi, \theta}, position=fixed);
461+
\partial{#}::PartialDerivative;
462+
g_{\alpha\beta}::Metric.
463+
g^{\alpha\beta}::InverseMetric.
461464

462-
sphe:={ g_{\theta\theta} = r**2,
463-
g_{\varphi\varphi} = r**2 \sin(\theta)**2 }.
464-
complete(sphe, $g^{\alpha\beta}$);
465+
sphe:={ g_{\theta\theta} = r**2,
466+
g_{\varphi\varphi} = r**2 \sin(\theta)**2 }.
467+
complete(sphe, $g^{\alpha\beta}$)
465468

466-
ch:= \Gamma^{\alpha}_{\mu\nu} = 1/2 g^{\alpha\beta} ( \partial_{\nu}{g_{\beta\mu}}
467-
+\partial_{\mu}{g_{\beta\nu}}
468-
-\partial_{\beta}{g_{\mu\nu}} );
469+
ch:= \Gamma^{\alpha}_{\mu\nu} = 1/2 g^{\alpha\beta} ( \partial_{\nu}{g_{\beta\mu}}
470+
+\partial_{\mu}{g_{\beta\nu}}
471+
-\partial_{\beta}{g_{\mu\nu}} );
469472

470-
evaluate(ch, sphe, rhsonly=True);
471-
rm:= R^{\rho}_{\sigma\mu\nu} = +\partial_{\mu}{\Gamma^{\rho}_{\sigma\nu}}
472-
-\partial_{\nu}{\Gamma^{\rho}_{\sigma\mu}}
473-
+\Gamma^{\rho}_{\beta\mu} \Gamma^{\beta}_{\sigma\nu}
474-
-\Gamma^{\rho}_{\beta\nu} \Gamma^{\beta}_{\sigma\mu};
473+
evaluate(ch, sphe, rhsonly=True)
475474

476-
substitute(rm, ch);
477-
evaluate(rm, sphe, rhsonly=True);
475+
rm:= R^{\rho}_{\sigma\mu\nu} = +\partial_{\mu}{\Gamma^{\rho}_{\sigma\nu}}
476+
-\partial_{\nu}{\Gamma^{\rho}_{\sigma\mu}}
477+
+\Gamma^{\rho}_{\beta\mu} \Gamma^{\beta}_{\sigma\nu}
478+
-\Gamma^{\rho}_{\beta\nu} \Gamma^{\beta}_{\sigma\mu};
478479

479-
ricci:= R_{\sigma\nu} = R^{\rho}_{\sigma\rho\nu};
480-
substitute(ricci, rm);
481-
evaluate(ricci, sphe, rhsonly=True);
480+
substitute(rm, ch)
481+
evaluate(rm, sphe, rhsonly=True)
482482

483-
R:= R = R_{\sigma\nu} g^{\sigma\nu};
484-
substitute(R, ricci);
485-
evaluate(R, sphe, rhsonly=True);
483+
ricci:= R_{\sigma\nu} = R^{\rho}_{\sigma\rho\nu};
484+
substitute(ricci, rm)
485+
evaluate(ricci, sphe, rhsonly=True)
486+
487+
R:= R = R_{\sigma\nu} g^{\sigma\nu};
488+
substitute(R, ricci)
489+
evaluate(R, sphe, rhsonly=True)
490+
val = rhs(R)
491+
tst:= @(val) - 2/r**2;
492+
assert(tst==0)
493+
print("Test 24 passed")
494+
495+
test24()

0 commit comments

Comments
 (0)