On this page

cook_indices

symbolica.community.idenso Function

cook_indices(self_: Expression) -> Expression

Convert complex nested index structures into flattened symbolic names.

Transforms hierarchical index expressions within tensor function arguments into simplified, flat symbolic representations. This "cooking" process is essential for pattern matching, simplification, and computational efficiency when dealing with complex tensor expressions.

Index Cooking Transformation:

  • Nested structure: mink(4, f(g(h(μ))))mink(4, f_g_h_mu)
  • Function chains: lorentz(up(mu))lorentz(up_mu)
  • Complex arguments: tensor(rep(dim,type(idx)))tensor(rep(dim,type_idx))

Scope:

  • Only affects indices appearing as function arguments
  • Preserves top-level function structure

Arguments

  • self_: expression containing complex nested index structures

Returns

Expression with flattened, simplified index names.

Examples

from symbolica.community.spenso import TensorName, Slot, Representation
import symbolica as sp
from symbolica.community.idenso import wrap_indices, cook_indices

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