Expression

com.phasmidsoftware.number.expression.expr.Expression
See theExpression companion trait
object Expression

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 Object
trait Matchable
class Any
Self type
Expression.type

Members list

Type members

Classlikes

implicit class ExpressionOps(x: Expression)

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 Object
trait Matchable
class Any
object given_Ordering_Expression extends Ordering[Expression]

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 Serializable
trait Comparator[Expression]
class Object
trait Matchable
class Any
Show 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 Field instance to be converted into an Expression

Attributes

Returns

an Expression representing the input Field, either as a predefined constant or a wrapped literal

def apply(x: Int): Expression

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 Expression and returns true if the expression is an identity element for the binary function f, otherwise false.

def matchSimpler: em.ExpressionTransformer

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 ExpressionTransformer that matches and applies the appropriate simplifications or transformations to the provided expression.

def parse(x: String): Option[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

def simplifyByEvaluation: em.AutoMatcher[Expression]

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.

def simplifyExpand: em.AutoMatcher[Expression]

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.

def simplifyIdentities: em.AutoMatcher[Expression]

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.

def simplifyOperands: em.AutoMatcher[Expression]

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

def simplifyParity: em.AutoMatcher[Expression]

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.

def simplifyStructural: em.AutoMatcher[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 AutoMatcher for Expression that matches and simplifies composite expressions, or returns the input expression unchanged if no simplifications are applicable.

Deprecated methods

def apply(w: String): Expression

Attributes

Deprecated
[Since version 1.6.5] Use puremath or lazymath string interpolators instead

Concrete fields

val e: Expression
lazy val matchLogLevel: LogLevel
val pi: Expression

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 Show instance for the Expression type.

Implicits

Implicits

final implicit def ExpressionOps(x: Expression): ExpressionOps

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 Field to be converted into an Expression

Attributes

Returns

an Expression instance representing the input Field

implicit def convertIntToExpression(x: Int): Expression

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 Expression that represents the given integer

implicit def convertNumber(x: Number): Expression

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 Rational number to be converted.

Attributes

Returns

an Expression representing the input Rational number.

implicit val em: ExpressionMatchers
implicit def fromString(w: String): Expression

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 Valuable instance parsed from the provided string.

implicit val logger: MatchLogger