ExpressionBiFunction

com.phasmidsoftware.number.expression.expr.ExpressionBiFunction
See theExpressionBiFunction companion object
sealed abstract class ExpressionBiFunction(val name: String, val f: (Eager, Eager) => Eager, val isExact: Boolean, val maybeIdentityL: Option[Eager], val maybeIdentityR: Option[Eager]) extends ExpressionFunction[(Eager, Eager)]

Represents a binary function used in expression evaluation. This abstraction encapsulates the logic for applying a binary operation to two Eager objects while supporting features such as exactness, commutativity, and optional identity elements.

Value parameters

f

the underlying binary function to be applied to the Eager inputs.

isExact

a flag indicating whether the function is strictly exact (producing precise results).

maybeIdentityL

an optional identity element for the left-hand operand; if defined, evaluation recognizes and simplifies the operation when this value is encountered.

maybeIdentityR

an optional identity element for the right-hand operand; if defined, evaluation recognizes and simplifies the operation when this value is encountered.

name

the unique name identifying the binary function.

Attributes

Companion
object
Graph
Supertypes
trait ((Eager, Eager)) => Valuable
class Object
trait Matchable
class Any
Known subtypes
object Atan
object Log
object Power
object Product
object Sum

Members list

Value members

Abstract methods

def applyExact(a: Eager, b: Eager): Option[Eager]

Applies a binary operation to the provided Valuable elements a and b, with stricter evaluation rules, and returns an optional result. The evaluation succeeds only if the operation satisfies specific conditions (e.g., exact representations or mathematical constraints).

Applies a binary operation to the provided Valuable elements a and b, with stricter evaluation rules, and returns an optional result. The evaluation succeeds only if the operation satisfies specific conditions (e.g., exact representations or mathematical constraints).

Value parameters

a

the first operand, a Valuable instance.

b

the second operand, a Valuable instance.

Attributes

Returns

an Option[Valuable] containing the result of the operation if it can be computed exactly, or None if the operation fails to meet exactness requirements.

def leftContext(context: Context): Context

Defines the Context appropriate for evaluating the left-hand parameter of this function.

Defines the Context appropriate for evaluating the left-hand parameter of this function.

Value parameters

context

the Context typically based on the context for the evaluation of the whole function.

Attributes

Returns

the left-hand Context of the binary function.

def rightContext(factor: Factor)(context: Context): Context

Defines the Context appropriate for evaluating the right-hand parameter of this function based on the provided Factor.

Defines the Context appropriate for evaluating the right-hand parameter of this function based on the provided Factor.

CONSIDER eliminating context as a parameter, or maybe changing it to the overall context as used by leftContext.

Value parameters

context

the initial Context typically derived from the evaluation of the left-hand parameter.

factor

the Factor used to determine the specific right-hand Context.

Attributes

Returns

the updated right-hand Context for use in further evaluations.

Concrete methods

def apply(a: Eager, b: Eager): Eager

Evaluate this function on x.

Evaluate this function on x.

Value parameters

a

the first parameter to the function.

b

the second parameter to the function.

Attributes

Returns

the result of f(x).

def apply(ff: (Eager, Eager)): Eager

Alternative apply method which satisfies the type declaration. Applies the binary function f to the given tuple of Eager elements.

Alternative apply method which satisfies the type declaration. Applies the binary function f to the given tuple of Eager elements.

Value parameters

ff

a tuple containing two Eager elements, representing the inputs to the binary function.

Attributes

Returns

a Eager that is the result of applying the binary function to the input tuple.

def applyExact(p: (Eager, Eager)): Option[Eager]

Applies the function exactly to the given input of type P, returning an Option of type Valuable if the application is successful.

Applies the function exactly to the given input of type P, returning an Option of type Valuable if the application is successful.

If defined, the output is guaranteed to be exact.

Value parameters

p

the input parameter of type P to which the function is applied

Attributes

Returns

an Option containing a Valuable result if the function executes successfully, or None if the operation cannot produce a valid result

def evaluate(a: Expression, b: Expression)(context: Context): Option[Eager]

Evaluates two expressions x and y in a given context and determines the resulting Valuable based on specific identity and evaluation rules. Trivial identities are recognized and evaluated appropriately.

Evaluates two expressions x and y in a given context and determines the resulting Valuable based on specific identity and evaluation rules. Trivial identities are recognized and evaluated appropriately.

Value parameters

a

the first expression to be evaluated.

b

the second expression to be evaluated.

context

the evaluation context providing the necessary environment for resolving expressions.

Attributes

Returns

an Option[Valuable] containing the result of the evaluation if successful, or None if evaluation fails.

def evaluateAsIs(x: Expression, y: Expression): Option[Eager]

Evaluates two expressions as-is (without any simplification or conversion) and applies the function f to the results if both evaluations are successful.

Evaluates two expressions as-is (without any simplification or conversion) and applies the function f to the results if both evaluations are successful.

Value parameters

x

the first expression to be evaluated.

y

the second expression to be evaluated.

Attributes

Returns

an Option[Valuable] containing the result of applying the binary function to the evaluated results of x and y, or None if either evaluation fails.

override def toString: String

Generate helpful debugging information about this ExpressionMonoFunction.

Generate helpful debugging information about this ExpressionMonoFunction.

Attributes

Returns

a String.

Definition Classes
Function1 -> Any

Inherited methods

def andThen[A](g: Valuable => A): (Eager, Eager) => A

Composes two instances of Function1 in a new Function1, with this function applied first.

Composes two instances of Function1 in a new Function1, with this function applied first.

Type parameters

A

the result type of function g

Value parameters

g

a function R => A

Attributes

Returns

a new function f such that f(x) == g(apply(x))

Inherited from:
Function1
def compose[A](g: A => (Eager, Eager)): A => Valuable

Composes two instances of Function1 in a new Function1, with this function applied last.

Composes two instances of Function1 in a new Function1, with this function applied last.

Type parameters

A

the type to which function g can be applied

Value parameters

g

a function A => T1

Attributes

Returns

a new function f such that f(x) == apply(g(x))

Inherited from:
Function1

Concrete fields

lazy val commutes: Boolean

Indicates whether the binary operation represented by this instance commutes, meaning the result remains unchanged for arbitrary swapping of inputs. This is determined based on the absence of a right-hand identity (maybeIdentityR).

Indicates whether the binary operation represented by this instance commutes, meaning the result remains unchanged for arbitrary swapping of inputs. This is determined based on the absence of a right-hand identity (maybeIdentityR).

Attributes

val f: (Eager, Eager) => Eager
val isExact: Boolean
val maybeIdentityL: Option[Eager]
val maybeIdentityR: Option[Eager]
val name: String

Returns the name of the expression function.

Returns the name of the expression function.

Attributes

Returns

a string representing the name of the function