summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tensors.mac34
1 files changed, 34 insertions, 0 deletions
diff --git a/tensors.mac b/tensors.mac
index 2249b0d..b396991 100644
--- a/tensors.mac
+++ b/tensors.mac
@@ -24,3 +24,37 @@ box_op(func) := (
mappend(f, list) := apply(append, map(f, list));
ensure_list(x) := if listp(x) then x else [x];
+
+/*
+WARNING: Preppended "-" means covariant index *not* contravariant like in
+ itensor package
+
+TODO: Handle sums
+NOTE: Does not work on complex expressions, just indexed arrays
+*/
+cov_diff(sim,i) ::= (
+ if atom(sim) then (
+ buildq([sim, i], cdiff(sim, i)))
+ elseif op(sim) = "+" then (
+ buildq([terms : args(sim), i],
+ apply("+", map(lambda([x], cov_diff(x, i)), terms))))
+ else block(
+ [ten : op(sim), inds : args(sim), covp, terms],
+ if not listp(inds) then (
+ error(printf(false, "Expected indexed object, got ~a", inds))),
+ covp : map(lambda([x], not atom(x) and op(x)="-"), inds),
+ inds : map(lambda([x], if atom(x) then x else first(args(x))), inds),
+ terms : map(lambda([sgn,index],
+ block([k : gensym()],
+ /* Covariant */
+ if sgn then buildq(
+ [ten, inds : subst(index=k, inds), i, index, k],
+ - sum(mcs[i, index, k] * ten[splice(inds)],k,1,4))
+ /* Contravariant */
+ else buildq(
+ [ten, inds : subst(index=k, inds), i, index, k],
+ sum(mcs[i, k, index] * ten[splice(inds)],k,1,4)))),
+ covp, inds),
+ buildq(
+ [i, ten, inds, terms : apply("+", terms)],
+ cdiff(ten[splice(inds)], i) + terms)));