The Expression companion object provides utilities for creating, manipulating, and parsing expressions.
Methods and values within this object help in constructing expressions from various types like Field or Int, perform conversions, parse string representations of expressions, define constants, and offer implicit operators for working with expressions.
It offers functionalities for mathematical operations, common constants, and extensions to manipulate operations in a lazy manner.
Attributes
- Companion
- trait
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Expression.type
Members list
Type members
Classlikes
Implicit class to allow various operations to be performed on an Expression.
Implicit class to allow various operations to be performed on an Expression.
Value parameters
- x
-
an Expression.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Canonical ordering for Expressions, used to normalise commutative BiFunction operands. Primary key: AtomicExpression < CompositeExpression. Secondary key (atoms): by type rank (see atomRank). Tertiary key (composites): by structural depth.
Canonical ordering for Expressions, used to normalise commutative BiFunction operands. Primary key: AtomicExpression < CompositeExpression. Secondary key (atoms): by type rank (see atomRank). Tertiary key (composites): by structural depth.
Attributes
- Supertypes
-
trait Ordering[Expression]trait PartialOrdering[Expression]trait Equiv[Expression]trait Serializabletrait Comparator[Expression]class Objecttrait Matchableclass AnyShow all
- Self type
Value members
Concrete methods
Transforms a given Field instance into an Expression by matching predefined constants or wrapping the input Field when no match is found.
Transforms a given Field instance into an Expression by matching predefined constants or wrapping the input Field when no match is found.
Value parameters
- x
-
the
Fieldinstance to be converted into anExpression
Attributes
- Returns
-
an
Expressionrepresenting the inputField, either as a predefined constant or a wrapped literal
The following method is helpful in getting an expression started (i.e., used as the leftmost operand).
The following method is helpful in getting an expression started (i.e., used as the leftmost operand).
Attributes
Method to yield a function which can determine if a given expression is an identity for the provided binary function.
Method to yield a function which can determine if a given expression is an identity for the provided binary function.
Value parameters
- f
-
the binary function for which the identity property is to be checked.
Attributes
- Returns
-
a function that takes an
Expressionand returns true if the expression is an identity element for the binary functionf, otherwise false.
Matches and simplifies expressions based on their type. For AtomicExpression instances, it applies simplifyAtomic specific to the atomic expression. For CompositeExpression, it uses a compound matcher that attempts simplifications in the following order: simplifyOperands, simplifyStructural, simplifyIdentities, simplifyParity, simplifyExpand, and simplifyByEvaluation. For unsupported expression types, it returns an error message.
Matches and simplifies expressions based on their type. For AtomicExpression instances, it applies simplifyAtomic specific to the atomic expression. For CompositeExpression, it uses a compound matcher that attempts simplifications in the following order: simplifyOperands, simplifyStructural, simplifyIdentities, simplifyParity, simplifyExpand, and simplifyByEvaluation. For unsupported expression types, it returns an error message.
Attributes
- Returns
-
an
ExpressionTransformerthat matches and applies the appropriate simplifications or transformations to the provided expression.
Method to parse a String as an Expression.
Method to parse a String as an Expression.
NOTE while not deprecated, this method should normally be rejected in favor of puremath, lazymath, etc.
NOTE that, in particular, this parser fails when the string includes signed numbers. For example, the string "3 ∧ ( 2 ∧ -1 )" includes a signed value (-1). You can parse the following equivalent string: "3 ∧ ( 2 ∧ (1 chs) )"
Attributes
Phase 6 of the 6-phase simplification pipeline: attempts to simplify an expression by evaluating it if possible. If the expression is a composite expression and can be evaluated, the method returns a simplified version of the evaluated result. If the expression cannot be evaluated or is already an atomic expression, the simplification operation is skipped. This is the last resort for simplification and is typically used when no other simplification is possible.
Phase 6 of the 6-phase simplification pipeline: attempts to simplify an expression by evaluating it if possible. If the expression is a composite expression and can be evaluated, the method returns a simplified version of the evaluated result. If the expression cannot be evaluated or is already an atomic expression, the simplification operation is skipped. This is the last resort for simplification and is typically used when no other simplification is possible.
Attributes
- Returns
-
An instance of
em.AutoMatcher[Expression]that performs matching and optionally simplifies an expression by evaluating it.
Phase 5 of the 6-phase simplification pipeline: attempts to simplify an Expression exactly based on specific rules for composite expressions. If the expression is of type CompositeExpression, it applies the simplifyExpand method specific to that type. For other expression types, it returns a miss, indicating that simplification is not applicable for the given type.
Phase 5 of the 6-phase simplification pipeline: attempts to simplify an Expression exactly based on specific rules for composite expressions. If the expression is of type CompositeExpression, it applies the simplifyExpand method specific to that type. For other expression types, it returns a miss, indicating that simplification is not applicable for the given type.
Attributes
- Returns
-
an
em.AutoMatcher[Expression]that matches and simplifies exact cases for composite expressions or signals when simplification is not applicable to non-composite expressions.
Phase 3 of the 6-phase simplification pipeline: attempts to simplify trivial cases within a CompositeExpression. This method patterns matches on CompositeExpression instances and applies trivial simplifications specific to such expressions.
Phase 3 of the 6-phase simplification pipeline: attempts to simplify trivial cases within a CompositeExpression. This method patterns matches on CompositeExpression instances and applies trivial simplifications specific to such expressions.
Attributes
- Returns
-
an instance of
em.AutoMatcher[Expression]that identifies and simplifies trivial cases in composite expressions.
Phase 1 of the 6-phase simplification pipeline: Simplify all operands before applying transformations.
Phase 1 of the 6-phase simplification pipeline: Simplify all operands before applying transformations.
Recursively calls .simplify() on each operand of composite expressions, ensuring bottom-up simplification where nested expressions are fully simplified before outer operations are applied.
Attributes
- See also
-
docs/SimplificationPipeline.md for complete pipeline documentation
Phase 4 of the 6-phase simplification pipeline: attempts to simplify expressions involving parity (odd/even functions) within binary operations such as summation. If specific patterns matching the parity rules are found, it produces a simplified result. Otherwise, no change is applied.
Phase 4 of the 6-phase simplification pipeline: attempts to simplify expressions involving parity (odd/even functions) within binary operations such as summation. If specific patterns matching the parity rules are found, it produces a simplified result. Otherwise, no change is applied.
Attributes
- Returns
-
An AutoMatcher that applies parity simplifications to expressions. Returns a simplified expression if a match is found, or a miss with a message indicating no simplification was possible for the provided expression.
Phase 2 of the 6-phase simplification pipeline. Attempts to simplify CompositeExpression instances by applying pattern-based rewrites that change expression structure. This matcher targets expressions of type CompositeExpression and invokes the structuralMatcher method to generate a simplified form of the expression based on its internal structure.
Phase 2 of the 6-phase simplification pipeline. Attempts to simplify CompositeExpression instances by applying pattern-based rewrites that change expression structure. This matcher targets expressions of type CompositeExpression and invokes the structuralMatcher method to generate a simplified form of the expression based on its internal structure.
Attributes
- Returns
-
an
AutoMatcherforExpressionthat matches and simplifies composite expressions, or returns the input expression unchanged if no simplifications are applicable.
Deprecated methods
Attributes
- Deprecated
-
[Since version 1.6.5]Use puremath or lazymath string interpolators instead
Concrete fields
The following constants are helpful in getting an expression started.
The following constants are helpful in getting an expression started.
Attributes
Givens
Givens
LatexRenderer for Expression - delegates to specific implementations.
LatexRenderer for Expression - delegates to specific implementations.
Attributes
Canonical ordering for Expressions, used to normalise commutative BiFunction operands. Primary key: AtomicExpression < CompositeExpression. Secondary key (atoms): by type rank (see atomRank). Tertiary key (composites): by structural depth.
Canonical ordering for Expressions, used to normalise commutative BiFunction operands. Primary key: AtomicExpression < CompositeExpression. Secondary key (atoms): by type rank (see atomRank). Tertiary key (composites): by structural depth.
Attributes
Provides a given instance of the Show type class for the Expression type. This enables rendering of an Expression instance to a String representation using the render method of the Expression.
Provides a given instance of the Show type class for the Expression type. This enables rendering of an Expression instance to a String representation using the render method of the Expression.
Attributes
- Returns
-
A
Showinstance for theExpressiontype.
Implicits
Implicits
Implicit class to allow various operations to be performed on an Expression.
Implicit class to allow various operations to be performed on an Expression.
Value parameters
- x
-
an Expression.
Attributes
Converts a Field instance into an Expression.
Converts a Field instance into an Expression.
Value parameters
- f
-
the
Fieldto be converted into anExpression
Attributes
- Returns
-
an
Expressioninstance representing the inputField
Implicitly converts an integer into an Expression by wrapping it, facilitating seamless conversions in mathematical operations. TODO have a cache of existing values
Implicitly converts an integer into an Expression by wrapping it, facilitating seamless conversions in mathematical operations. TODO have a cache of existing values
Value parameters
- x
-
the integer to be converted into an
Expression
Attributes
- Returns
-
an
Expressionthat represents the given integer
Converts a given number into an Expression by wrapping it as a Real.
Converts a given number into an Expression by wrapping it as a Real.
Value parameters
- x
-
the number to be converted into an Expression
Attributes
- Returns
-
an Expression representing the input number
Converts a Rational number into an Expression.
Converts a Rational number into an Expression.
Value parameters
- x
-
the
Rationalnumber to be converted.
Attributes
- Returns
-
an
Expressionrepresenting the inputRationalnumber.
Converts a given string into a Valuable representation. This method allows implicit conversion from String to Valuable.
Converts a given string into a Valuable representation. This method allows implicit conversion from String to Valuable.
Value parameters
- w
-
the input string to be converted into a
Valuable.
Attributes
- Returns
-
a
Valuableinstance parsed from the provided string.