canonicalize_under_variable_permutation#

canonicalize_under_variable_permutation(expr, variables=None, allow_sign_change=False)#

Canonicalize an expression up to permutations of variables (and optionally sign).

For all permutations of the selected variables, compute the permuted polynomial and choose the lexicographically minimal representation of (exponent-vector → coefficient) pairs (optionally also considering the negated polynomial).

Parameters:
  • expr (Expr) – SymPy expression.

  • variables (Sequence[Symbol] | None) – Sequence of variables to permute. If None, attempts to detect with extract_variables() and then sorts them.

  • allow_sign_change (bool) – If True, also consider -f under permutations and pick the best.

Returns:

Expr – Canonical representative under variable permutations (and ±1 if enabled).

Return type:

Expr