On this page

wrap_dummies

symbolica.community.idenso Function

wrap_dummies(expression: Expression, header: Expression) -> Expression

Wraps only the dummy (contracted) indices within the expression using a header symbol.

Similar to wrap_indices, but selectively identifies and wraps only contracted indices (those appearing once upstairs and once downstairs, or twice in a self-dual representation), leaving external (dangling) indices untouched. This is crucial for proper index management in tensor calculations.

Contracted indices are those that:

  • Appear in both upper and lower positions (for dualizable reps)
  • Appear twice in the same position (for self-dual reps)
  • Are summed over (Einstein summation convention)

Arguments

  • expression: input expression containing both dummy and free indices
  • header: symbol to use as wrapper function name for dummy indices only

Returns

A new expression with only contracted indices wrapped.

Raises

ValueError when the expression cannot be parsed as a tensor network.

Examples

from symbolica.community.spenso import TensorName, Slot, Representation
import symbolica as sp
from symbolica.community.idenso import simplify_metrics, wrap_dummies

T = TensorName("T")
rep = Representation.euc(3)
# With slots (creates TensorExpression)
mu = rep("mu")
nu = rep("nu")
x = sp.S("x")
tensor_with_args = T(x, mu, nu, nu)  # T(x; mu, nu, nu)
# print(tensor_with_args)
print(wrap_dummies(tensor_with_args.to_expression(), sp.S("wrap")))