Specialized canonical forms
These transformations have a fixed normal-form contract: each one produces a
determined shape and never runs the heuristic search used by
simplify. Use them when the output
shape matters more than minimal size.
Related rewrites are on algebraic transforms and trigonometric and complex rewrites.
Canonical presentation passes#
piecewise_fold#
Default context
piecewise_fold(input_expression: ExpressionLike) -> ExpressionCalling forms
Explicit context: Context.piecewise_fold
piecewise_fold(input_expression: ExpressionLike) -> ExpressionExpression method: Expression.piecewise_fold
piecewise_fold() -> ExpressionExpand abs, signum, and heaviside_step definitions recursively and fold
piecewise operands of sums, products, powers, factorials, and ordinary function
calls into one top-level piecewise expression. For example, x*abs(x - 1)
becomes the exact two-branch definition with values x*(x - 1) and
-x*(x - 1). Branch combinations retain first-match order and conditions are
conjoined exactly.
Each structural fold is limited to 16 branches and 128 stored nodes, with a per-input growth limit of eight times the source node count. A node that would exceed a limit remains unfolded; the operation still returns an exact, equality-preserving expression and may therefore return the input unchanged.
rewrite_special_functions#
Default context
rewrite_special_functions(
input_expression: ExpressionLike,
basis: str,
) -> ExpressionCalling forms
Explicit context: Context.rewrite_special_functions
rewrite_special_functions(
input_expression: ExpressionLike,
basis: str,
) -> ExpressionExpression method: Expression.rewrite_special_functions
rewrite_special_functions(basis: str) -> ExpressionRewrite beta, gamma, binomial, factorial, and rising-factorial representations
into the requested "gamma", "factorial", "binomial", or
"rising_factorial" basis. The exact identities are applied only when their
domain gates are proven: factorial and binomial conversions require the
relevant non-negative integers, rising-factorial conversions additionally
require a positive base, and beta-to-gamma requires two positive arguments.
For example, with n declared a positive integer, n! may be rewritten into
the gamma basis and gamma(n) into the factorial basis. A site with
unconstrained arguments is returned unchanged. Gamma ratios with a literal
non-negative argument offset are minimized to their exact shifted product.
The context method, expression convenience method, and module function have the same behavior. An unknown basis name raises an explicit error; there is no force mode.
presentation_normal_form#
Default context
presentation_normal_form(input_expression: ExpressionLike) -> ExpressionCalling forms
Explicit context: Context.presentation_normal_form
presentation_normal_form(input_expression: ExpressionLike) -> ExpressionExpression method: Expression.presentation_normal_form
presentation_normal_form() -> ExpressionThe cheap, bounded display-oriented pass run at solver output seams: rational
normal form only, kept only when the weighted complexity does not grow.
Unlike simplify it never runs the full heuristic ladder, so it is fast and
deterministic in shape.
Example#
Each pass produces a determined shape rather than a smallest form.
import symi
x = symi.symbol("x")
n = symi.symbol("n", integer=True, positive=True)
branches = symi.piecewise([
(symi.less_than(x, 0), -x),
(symi.logical_true, x),
])
print(symi.piecewise_fold(branches))
print(symi.presentation_normal_form(1 / x + 1 / (x + 1)))
print(symi.rewrite_special_functions(symi.gamma(n), "factorial"))