A controlled identity pass
This tutorial uses Idenso’s methods on Spenso TensorExpression to contract one four-dimensional Minkowski metric tensor with a vector. It is intentionally small: the point is to establish the registered tensor syntax and observe one algebra pass before composing a larger Dirac or color pipeline.
For the shortest installation and first-run path, begin with Using Idenso from Python. Then return here to inspect the identity pass and extend it into an algebra pipeline.
Prerequisites
Idenso algebra is exposed by symbolica.community.tensor; it is not installed by pip install idenso. Install a Symbolica community build with the unified spynso3 bindings, then verify the environment:
python -m pip install --upgrade symbolica
python -c "import symbolica.community.tensor"If that fails, check the installed Symbolica version before continuing. Generating a .pyi file does not mount the native module. Source embedders can build a custom community assembly.
Simplify one metric contraction
Save the following as metric_first.py:
from symbolica.community.tensor import Representation, TensorExpression, TensorName
rep = Representation.mink(4)
mu = rep("mu")
nu = rep("nu")
g = TensorExpression.g(rep)
q = TensorName.vector("q")
expression = g(mu, nu) * q(mu)
free_before = expression.list_dangling()
reduced = expression.contract()
free_after = reduced.list_dangling()
assert len(free_before) == 1
assert len(free_after) == 1
assert reduced == q(nu)
print("reduced:", reduced)The typed product carries a bracket contraction. contract() handles that structure and ordinary indexed products through the same shared contractor. to_expression() returns the ordinary Symbolica expression; expand() is a separate, explicit materialization operation.
Run python metric_first.py. Success means both rank assertions pass, the metric is removed from the reduced expression, and the result is a rank-one expression carrying nu. The rewrite is abstract: the registered Minkowski metric supplies index compatibility, but this example does not substitute a numerical signature. Printed output can vary with the installed Symbolica version; inspect the expression structure instead of comparing exact text.
Use Run example to execute
metric_first.py in your browser and check the rank-one invariant. To run it locally, first install a Symbolica build containing the tensor community module, then run the environment probe and script above. The script should take seconds after startup; building or installing Symbolica community modules is the expensive prerequisite and may take substantially longer.Importing
symbolica.community.tensor registers Idenso’s representation and tensor symbols. Construct the Spenso-compatible expression after that import so Idenso’s matchers see the intended slots and tensor names.Grow this into an algebra pipeline
Keep transformations observable while developing:
- call
list_danglingbefore and after a pass to catch accidental contractions; - use
wrap_indices(scope, dummies_only=True)before multiplying expressions built in independent index namespaces; - use
contractfor structural work alone, or select the required families together insimplify_algebra; the latter includes their necessary contractions; - canonicalize only after the physics-specific identities required by the calculation are explicit.
Troubleshooting and next steps
ModuleNotFoundErrorforsymbolica.community.tensormeans the installed Symbolica build does not include the native module; a.pyitype stub or source checkout alone is not enough.- If the metric remains unchanged, construct its slots with the same
Representationand abstract index objects as the vector. Plain Symbolica functions do not automatically carry Spenso tensor structure. - If a free index disappears unexpectedly, inspect repeated names and use
wrap_indices(scope, dummies_only=True)before combining separately constructed expressions. - Continue with the syntax-and-algebra manual, then use the Python and Rust API references for signatures and feature gates.