diff options
| author | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-07-28 19:55:39 +0200 |
|---|---|---|
| committer | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-07-28 19:55:39 +0200 |
| commit | f1da89b4cb5afd413aae8cd61fa31b3d45dcd18b (patch) | |
| tree | 1767cd8fec35b55ab4a87cc7ab300a934e4c5339 | |
| parent | a0ce28f32a7ae3db7e430090c9b79b3acd6e4af9 (diff) | |
Simplify contr
| -rw-r--r-- | tensors.mac | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/tensors.mac b/tensors.mac index 6d7248a..e8e5a4f 100644 --- a/tensors.mac +++ b/tensors.mac @@ -3,19 +3,15 @@ /* NOTE: buildq works like splicing a list with quasiquote in lisp; escaped items are defined at start of quote */ contr(expr, var) ::= ( - if listp(var) and length(var) > 1 then - block([head, tail], - head : first(var), - tail : rest(var), - buildq([expr, head, tail], sum(contr(expr, tail), head, 1, 4))) - elseif listp(var) and length(var) = 1 then - block([head], - head : first(var), - buildq([expr, head], sum(expr, head, 1, 4))) - elseif listp(var) then - expr - else - buildq([expr, var], sum(expr, var, 1, 4)))$ + if listp(var) and length(var) > 1 then buildq( + [expr, head : first(var), tail : rest(var)], + sum(contr(expr, tail), head, 1, 4)) + elseif listp(var) and length(var) = 1 then buildq( + [expr, head : first(var)], sum(expr, head, 1, 4)) + elseif listp(var) then ( + expr) + else buildq([expr, var], + sum(expr, var, 1, 4))); /* Differentiate with respect to nth coordinate */ cdiff(func, coord) := diff(func, ct_coords[coord])$ |
