ham/ham.mac

16 lines
465 B
Plaintext

/*
* Copyright (c) Camden Dixie O'Brien
* SPDX-License-Identifier: AGPL-3.0-only
*/
ham(L, qs) := block([ps, qdots, H],
ps: maplist(lambda([q], concat(p_, q)), qs),
qdots: maplist(lambda([q], 'diff(q, t)), qs),
H: subst(solve(maplist(lambda([p,qdot], p = diff(L, qdot)), ps, qdots),
qdots),
apply("+", maplist("*", ps, qdots)) - L),
maplist(trigsimp, maplist(lambda([q], [
diff(H, concat(p_, q)),
-diff(H, q)
]), qs)));