Replacement

Symbolica documentation for getting started, symbolic expressions, numerical evaluation, pattern matching, and APIs in Python and Rust.

Replacement

Replacement()

A replacement of a pattern by a right-hand side.

Methods

Name Description
__new__ Create a new replacement

__new__

Replacement.__new__(
    pattern: Expression | int | float | complex | Decimal,
    rhs: HeldExpression | Expression | Callable[[dict[Expression, Expression]], Expression] | int | float | complex | Decimal,
    cond: PatternRestriction | Condition | None = None,
    non_greedy_wildcards: Sequence[Expression] | None = None,
    min_level: int = 0,
    max_level: int | None = None,
    level_range: tuple[int, int | None] | None = None,
    level_is_tree_depth: bool = False,
    partial: bool = True,
    allow_new_wildcards_on_rhs: bool = False,
    rhs_cache_size: int | None = None,
) -> Replacement

Create a new replacement. See replace for more information.

Parameters

  • pattern (Expression | int | float | complex | Decimal) The left-hand-side pattern to match.
  • rhs (HeldExpression | Expression | Callable[[dict[Expression, Expression]], Expression] | int | float | complex | Decimal) The right-hand-side operand.
  • cond (PatternRestriction | Condition | None) An additional restriction that a match or replacement must satisfy.
  • non_greedy_wildcards (Sequence[Expression] | None) Wildcards that should be matched non-greedily.
  • min_level (int) The minimum level at which a match is allowed.
  • max_level (int | None) The maximum level at which a match is allowed.
  • level_range (tuple[int, int | None] | None) The (min_level, max_level) range in which matches are allowed.
  • level_is_tree_depth (bool) Whether levels should be measured by tree depth instead of function nesting.
  • partial (bool) Whether matches are allowed inside larger expressions instead of only at the top level.
  • allow_new_wildcards_on_rhs (bool) Whether wildcards that appear only on the right-hand side are allowed.
  • rhs_cache_size (int | None) The cache size for memoizing right-hand-side evaluations.