geomech
A Python library for the symbolic derivation of equations of motion and their variation-based linearization on smooth manifolds: $R$, $R^3$, $S^2$, $SO(3)$ and their products (e.g. $SE(3)$ as $R^3 \times SO(3)$).
This work builds on the methods and math described in
- Global Formulations of Lagrangian and Hamiltonian Dynamics on Manifolds
- Symbolic Computation of Dynamics on Smooth Manifolds and its Scala implementation.
Documentation: https://geomech.readthedocs.io
What it does
Given a Lagrangian and virtual work, geomech automatically derives
globally valid, singularity-free equations of motion on smooth manifolds
(SO(3), S2) using Hamilton's principle and variational calculus --
no Euler angles or quaternions required.
The pipeline:
- Define symbolic scalars, vectors, and matrices
- Build kinetic/potential energy and virtual work expressions
- Call
compute_eom()-- the library takes the variation of the action, applies the manifold kinematics, simplifies, integrates by parts and extracts the equations (pipeline, stage by stage) - Optionally call
to_standard_form()forM(q) a + f + G u = 0, orlinearize()for the variation-based linearizationM δẋ = A δx + B δualong a trajectory - Optionally generate NumPy (or CasADi) code for the result with
geomech.codegen(generate_module,lambdify,energy_function; code generation);examples/generated/holds the modules of nine systems - Optionally simulate a generated model on its manifold with
geomech.simulation(simulatewith a Lie-group RK4 integrator orsolve_ivp, energy checks, andlqrfrom the linearization; simulation,examples/inverted_rigid_pendulum_lqr.py) - Optionally draw the simulated system in 3-D and write one self-contained HTML report
(animation, equations, standard form, verification numbers) with
geomech.viz(visualization,examples/report_*.py); an agent skill that follows this whole procedure is inskills/geomech/
How it works
Expressions are symbolic trees. Python operators (*, +, etc.) build
the tree; transformations rewrite it using match/case pattern matching.
Node arity:
| Arity | Nodes | Example |
|---|---|---|
| N-ary | Add, VAdd, MAdd |
a + b + c → one node, three children |
| Binary | Mul, Dot, Cross, SVMul, MVMul, ... |
Dot(x, y) → two children |
| Unary | Hat, Vee, Transpose, TimeDerivative, Variation |
Hat(x) → one child |
Sample trees:
M * (x + y + Cross(m, n)) -- matrix-vector multiply with N-ary addition:
MVMul ← Binary (matrix × vector → vector)
╱ ╲
M VAdd ← N-ary (3 children)
╱ | ╲
x y Cross ← Binary (vector × vector)
╱ ╲
m n
KE = m * Dot(ẋ, ẋ) * 0.5 -- kinetic energy:
Mul ← Binary (scalar × scalar)
╱ ╲
Mul 0.5
╱ ╲
m Dot ← Binary (vector · vector → scalar)
╱ ╲
d/dt d/dt ← Unary (time derivative)
| |
x x ← Vector leaves
Tree rewrites -- one function per node class, picked by the class of the node
(match/case inside a handler where a rule depends on the operands' classes):
def _elim_dot(expr): # binary
l, r = _eliminate(expr.left), _eliminate(expr.right)
if _is_zero(l) or _is_zero(r):
return rule("simplify.dot_zero", expr, Zero)
return Dot(l, r)
def _elim_hat(expr): # unary
inner = _eliminate(expr.expr)
if isinstance(inner, Vee) and _is_skew_symmetric(inner.expr):
return rule("simplify.hat_vee_skew", expr, inner.expr) # Hat(Vee(X)) = X
return Hat(inner)
_ELIMINATE = {Dot: _elim_dot, Hat: _elim_hat, Add: _elim_add, ...} # a leaf has none
def _eliminate(expr):
handler = _ELIMINATE.get(type(expr))
return _canonical_literal(expr) if handler is None else handler(expr)
Nodes are frozen: a rewrite always builds new nodes, and a subtree can be shared by several trees.
Every rewrite is logged through rule(name, before, after); the names, with the hypothesis
each rule needs, are listed in the module docstrings, and GEOMECH_TRACE=1 logs every
firing.
The full pipeline (compute_eom), each stage a recursive tree rewrite:
δS = δL + δW → manifold rules (δω, δΩ) → full_simplify → integration by parts
(expand, full_simplify, then per variation vector: collect → IBP → full_simplify) →
expand → extract the coefficient of each variation vector → full_simplify.
Deriving equations has one paragraph per stage;
compute_eom(..., trace=EOMTrace()) keeps every stage, GEOMECH_DEBUG=1 logs them, and
GEOMECH_TRACE=1 logs every named rewrite rule that fires
(Troubleshooting).
Installation
Requires Python >= 3.10.
pip install geomech
pip install "geomech[casadi]" # optional: the CasADi code generation target
pip install "geomech[sim]" # optional: scipy, for solve_ivp and lqr in geomech.simulation
From a clone, for development: pip install -e ".[dev]".
Quick start
Point mass -- derives m * ddot_x = f - m*g*e3:
from geomech import *
import numpy as np
m, g = getScalars('m g', attr=['Constant'])
e3 = Vector('e3', attr=['Constant'], value=np.array([0., 0., 1]))
x, f = getVectors(['x', 'f'])
v = x.t_diff()
KE = m * Dot(v, v) * 0.5
PE = m * x.dot(g * e3)
L = KE - PE
dW = Dot(x.delta(), f)
eqs = compute_eom(L, dW, SystemVariables(vectors=[x]))
print_eom(eqs)
Spherical pendulum on S2:
m, g, l = getScalars('m g l', attr=['Constant'])
e3 = Vector('e3', attr=['Constant'], value=np.array([0., 0., 1]))
q = S2('q') # attitude on the 2-sphere
f = Vector('f')
x = l * q
v = x.t_diff()
KE = m * Dot(v, v) * 0.5
PE = m * x.dot(g * e3)
L = KE - PE
dW = Dot(q.delta(), f)
eqs = compute_eom(L, dW, SystemVariables(vectors=[q]))
print_eom(eqs)
Rigid body on SO(3):
J = Matrix('J', attr=['Constant', 'SymmetricMatrix'])
rho = Vector('\\rho', attr=['Constant'])
m, g = getScalars('m g', attr=['Constant'])
e3 = Vector('e_3', attr=['Constant'], value=np.array([0., 0., 1]))
R = SO3('R') # rotation matrix on SO(3)
Om = R.get_tangent_vector()
eta = R.get_variation_vector()
M = Vector('M') # external torque
x = R * rho
v = x.t_diff()
KE = Dot(Om, J * Om) * 0.5 + Dot(v, v) * m * 0.5
PE = m * g * Dot(x, e3)
L = KE - PE
dW = Dot(eta, M)
eqs = compute_eom(L, dW, SystemVariables(matrices=[R]))
print_eom(eqs)
More examples in examples/.
Expression types
| Type | Description | Constructor |
|---|---|---|
Scalar |
Symbolic scalar | Scalar('m', attr=['Constant']) |
Vector |
Column vector (default 3x1) | Vector('x') |
Matrix |
Square matrix (default 3x3) | Matrix('J', attr=['Constant']) |
S2 |
Unit vector on the 2-sphere | S2('q') |
SO3 |
Rotation matrix on SO(3) | SO3('R') |
Batch constructors: getScalars('a b c'), getVectors(['x', 'y']), getMatrices('M N').
Operations
Arithmetic -- natural Python operators build expression trees:
a * b # scalar multiplication
a * x # scalar-vector multiplication
M * x # matrix-vector multiplication
x + y # vector addition
Dot(x, y) # dot product
Cross(x, y) # cross product
Hat(x) # hat map (R^3 -> so(3))
Vee(M) # vee map (so(3) -> R^3)
Transpose(x) # transpose (x.T() is the same; Transpose(Transpose(x)) is x)
R.T() * x # a transposed matrix multiplies like a matrix: R^T x
x.T() * y # row times column: the inner product x^T y; x * y.T() is the outer product
x.T() * K * x # a row times a matrix is a row: the quadratic form x^T K x
# (also in a kinetic energy, v.T() * K * v: collect turns it into Dot(v, K * v) for integration by parts)
2 * x, a + 1, 1 - a, -x, x / 2 # numbers on either side (a number adds only to a scalar); / divides by a number only
A mistyped operand raises ExpressionMismatchError naming both operands, e.g.
Dot cannot combine SCALAR 'm' and VECTOR 'x'.
Calculus:
x.t_diff() # time derivative
x.t_integrate() # time integral
x.delta() # variation (delta)
Transformations:
expand(expr) # distribute products over sums
simplify(expr) # pull scalars, apply identities, eliminate zeros
full_simplify(expr) # expand + simplify until convergence
Printing -- str(expr) is the internal form and the equality key (products print
* between their factors: m*g*Dot(e3,x)); for reading:
to_latex(expr) # LaTeX, parenthesised where juxtaposition would be ambiguous
print_eom(eqs) # one LaTeX integral equation per variable (via to_latex)
repr(expr) # compact: v:x vector, M:J matrix, S2:q, SO3:R; trailing * = constant;
# products joined by ·, e.g. m*·g*·<v:e3*, v:x>
print_tree(expr) # one node per line with every leaf's flags (style="topdown" for a sketch)
Package structure
geomech/
core/
base/ # Expr types, flags, scalars/vectors/matrices, manifolds
operations/ # Add, Mul, Dot, Cross, Hat, Variation, TimeDerivative, ...
transformations/# expand, simplify, pull, vector_rules
math/ # extract_linear_coeff, collect, integrate_by_parts
dynamics/ # compute_eom, to_standard_form, linearize, SystemVariables
codegen/ # StateLayout, to_source, lambdify, generate_module, energy_function
simulation/ # accelerations, simulate (RKMK4, solve_ivp), Trajectory, lqr
viz/ # Scene (3-D bodies from expressions), Report (HTML), latex_names
numeric.py # evaluate, check_eom, finite_difference_check
utils/ # print_eom, print_tree, render_eom
Running tests
pip install -e ".[dev]"
pytest
Citation
If you use geomech in your research, please cite this package along with corresponding original work, Global Formulations of Lagrangian and Hamiltonian Dynamics on Manifolds and Symbolic Computation of Dynamics on Smooth Manifolds.
@software{kotaru2026geomech,
title={geomech: Symbolic toolbox for geometric mechanics on smooth manifolds},
author={Kotaru, Prasanth},
url={https://github.com/vkotaru/geomech},
year={2026}
}
License
BSD 3-Clause. See LICENSE.
Metadata
Release files for geomech 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| geomech-0.2.0.tar.gz | 447.5 kB | With provenance | Details for geomech-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| geomech-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for geomech-0.2.0-py3-none-any.whl |
Total release size: 666.8 kB
Release files / geomech-0.2.0.tar.gz
| Download URL | geomech-0.2.0.tar.gz |
|---|---|
| Size | 447.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f0d69da2adcdb96376a5479c1e2f4184bdbde7303cccb0452e5b85e470e5faef
|
|
BLAKE2b-256 checksum How to use checksums |
2cc3b1c578ba60eec2da34c7ab4fd53a4914173cf05f398dd39f0c2f292b9b3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / geomech-0.2.0-py3-none-any.whl
| Download URL | geomech-0.2.0-py3-none-any.whl |
|---|---|
| Size | 219.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1f7b42c4aea89126e32319bbd6d6c40fc70f213f6a6ad94c3e2e304023109cc
|
|
BLAKE2b-256 checksum How to use checksums |
0082e2f6ad34ae1d67cc7485849342461ebaf3b7128194fa296da01f0ce59d78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logSecurity for geomech 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for geomech-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.