diff options
| author | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-07-28 19:59:23 +0200 |
|---|---|---|
| committer | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-07-28 19:59:23 +0200 |
| commit | b764fb1b1dd84a285f370b81b3307f6af59f1e87 (patch) | |
| tree | b5eece0b9e9a1e90531cde9c52a5e1bf97fd23c6 | |
| parent | 15008182250908f6a60e537826e9872b44446dd1 (diff) | |
Add cov_diff
| -rw-r--r-- | tensors.mac | 34 |
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))); |
