Struct Expression
An expression that can be the left hand or right hand side of a constraint equation. It is a linear combination of variables, i.e. a sum of variables weighted by coefficients, plus an optional constant.
public readonly struct Expression : IEquatable<Expression>
- Implements
- Inherited Members
Constructors
Expression()
Initializes a new instance of the Expression struct.
public Expression()
Expression(ImmutableArray<Term>, double)
Initializes a new instance of the Expression struct.
public Expression(ImmutableArray<Term> terms, double constant)
Parameters
termsImmutableArray<Term>Terms of the expression.
constantdoubleConstant value.
Properties
Constant
Gets the constant value of the expression.
public double Constant { get; init; }
Property Value
Terms
Gets the terms of the expression.
public ImmutableArray<Term> Terms { get; init; }
Property Value
Methods
Deconstruct(out ImmutableArray<Term>, out double)
Deconstructs the expression into terms and constant.
public void Deconstruct(out ImmutableArray<Term> terms, out double constant)
Parameters
termsImmutableArray<Term>constantdouble
Equals(Expression)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Expression other)
Parameters
otherExpressionAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
From(Term)
Constructs an expression from a single term. Forms an expression of the form n x where n is the coefficient, and x is the variable.
public static Expression From(Term term)
Parameters
Returns
- Expression
New instance of Expression.
From(Variable)
Constructs an expression from a single variable. Forms an expression of the form x
public static Expression From(Variable variable)
Parameters
Returns
- Expression
New instance of Expression.
From(double)
Constructs an expression of the form n, where n is a constant real number, not a variable.
public static Expression From(double constant)
Parameters
constantdoubleThe constant value.
Returns
- Expression
New instance of Expression.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Operators
operator +(Expression, Expression)
Sum two Expression.
public static Expression operator +(Expression expression, Expression other)
Parameters
expressionExpressionThe Expression.
otherExpressionThe Expression.
Returns
- Expression
New Expression instance with a joins terms and constant sum.
operator +(Expression, Term)
Sum two Expression.
public static Expression operator +(Expression expression, Term other)
Parameters
expressionExpressionThe Expression.
otherTermThe Term.
Returns
- Expression
New Expression instance with a joins terms and constant sum.
operator +(Expression, Variable)
Sum Expression with a Variable.
public static Expression operator +(Expression expression, Variable variable)
Parameters
expressionExpressionThe Expression.
variableVariableThe Variable.
Returns
- Expression
New Expression instance with a Term with a coefficient value as -1.
operator +(Expression, double)
Sum Expression with a float value.
public static Expression operator +(Expression expression, double value)
Parameters
expressionExpressionThe Expression.
valuedoubleThe value.
Returns
- Expression
New Expression instance with a constant sum.
operator +(Expression, float)
Sum Expression with a float value.
public static Expression operator +(Expression expression, float value)
Parameters
expressionExpressionThe Expression.
valuefloatThe value.
Returns
- Expression
New Expression instance with a constant sum.
operator +(double, Expression)
Sum Expression with a float value.
public static Expression operator +(double value, Expression expression)
Parameters
valuedoubleThe value.
expressionExpressionThe Expression.
Returns
- Expression
New Expression instance with a constant sum.
operator +(float, Expression)
Sum Expression with a float value.
public static Expression operator +(float value, Expression expression)
Parameters
valuefloatThe value.
expressionExpressionThe Expression.
Returns
- Expression
New Expression instance with a constant sum.
operator |(Expression, WeightedRelation)
OR Expression with WeightedRelation.
public static PartialConstraint operator |(Expression expression, WeightedRelation relation)
Parameters
expressionExpressionThe Expression.
relationWeightedRelationThe WeightedRelation.
Returns
- PartialConstraint
New PartialConstraint instance.
operator /(Expression, double)
Divide Expression by float value.
public static Expression operator /(Expression expression, double value)
Parameters
expressionExpressionThe Expression.
valuedoubleThe value
Returns
- Expression
New Expression instance with Term and Constant dividing by
value.
operator /(Expression, float)
Divide Expression by float value.
public static Expression operator /(Expression expression, float value)
Parameters
expressionExpressionThe Expression.
valuefloatThe value
Returns
- Expression
New Expression instance with Term and Constant dividing by
value.
operator ==(Expression, Expression)
Checks if two Expression are equal.
public static bool operator ==(Expression left, Expression right)
Parameters
leftExpressionLeft Expression.
rightExpressionRight Expression.
Returns
operator !=(Expression, Expression)
Checks if two Expression are not equal.
public static bool operator !=(Expression left, Expression right)
Parameters
leftExpressionLeft Expression.
rightExpressionRight Expression.
Returns
operator *(Expression, double)
Multiply Expression by float value.
public static Expression operator *(Expression expression, double value)
Parameters
expressionExpressionThe Expression.
valuedoubleThe value
Returns
- Expression
New Expression instance with Term and Constant multiply by
value.
operator *(Expression, float)
Multiply Expression by float value.
public static Expression operator *(Expression expression, float value)
Parameters
expressionExpressionThe Expression.
valuefloatThe value
Returns
- Expression
New Expression instance with Term and Constant multiply by
value.
operator *(double, Expression)
Multiply Expression by float value.
public static Expression operator *(double value, Expression expression)
Parameters
valuedoubleThe value
expressionExpressionThe Expression.
Returns
- Expression
New Expression instance with Term and Constant multiply by
value.
operator *(float, Expression)
Multiply Expression by float value.
public static Expression operator *(float value, Expression expression)
Parameters
valuefloatThe value
expressionExpressionThe Expression.
Returns
- Expression
New Expression instance with Term and Constant multiply by
value.
operator -(Expression, Expression)
Subtract Expression from Expression.
public static Expression operator -(Expression expression, Expression other)
Parameters
expressionExpressionThe Expression.
otherExpressionThe Expression.
Returns
- Expression
New Expression instance by negative of
otherand add terms and sum Constant.
operator -(Expression, Term)
Subtract Term from Expression.
public static Expression operator -(Expression expression, Term term)
Parameters
expressionExpressionThe Expression.
termTermThe Term.
Returns
- Expression
New Expression with a negative Term.
operator -(Expression, Variable)
Subtract Variable from Expression.
public static Expression operator -(Expression expression, Variable variable)
Parameters
expressionExpressionThe Expression.
variableVariableThe Variable.
Returns
- Expression
New Expression instance with a Term with a coefficient value as -1.
operator -(Expression, double)
Subtract float value from Expression.
public static Expression operator -(Expression expression, double value)
Parameters
expressionExpressionThe Expression.
valuedoubleThe float.
Returns
- Expression
New Expression instance with a constant sub.
operator -(Expression, float)
Subtract float value from Expression.
public static Expression operator -(Expression expression, float value)
Parameters
expressionExpressionThe Expression.
valuefloatThe float.
Returns
- Expression
New Expression instance with a constant sub.
operator -(double, Expression)
Subtract float value from Expression.
public static Expression operator -(double value, Expression expression)
Parameters
valuedoubleThe float.
expressionExpressionThe Expression.
Returns
- Expression
New Expression instance with a constant sub.
operator -(float, Expression)
Subtract float value from Expression.
public static Expression operator -(float value, Expression expression)
Parameters
valuefloatThe float.
expressionExpressionThe Expression.
Returns
- Expression
New Expression instance with a constant sub.
operator -(Expression)
Negate Expression.
public static Expression operator -(Expression expression)
Parameters
expressionExpressionThe Expression.
Returns
- Expression
New instance of Expression with negative Term and constant.