Skip to content
Symi Docs
Python
On this page

Relations and predicates

Relations construct symbolic formulas. They are distinct from host-language truth queries.

Relations#

Relation nodes are used as equations for solve/solveset, as piecewise conditions, and as boolean-valued results.

Each relation is also a method of the left operand: x.less_than(1) builds the same node as context.less_than(x, 1). In Python, <, <=, >, and >= build the strict and non-strict order relations, so x < 1 is the relation x < 1. == and != are deliberately not relation builders: they compare two expressions structurally, which keeps expressions usable as dictionary keys and set members; build an equation value with equation. A relation has no Python truth value — its truth is three-valued, so bool(x < 1) raises, and so does a chained comparison such as 0 < x < 1. Ask for the verdict with evaluate_truth.

equal#

Default context

equal(left: Any, right: Any) -> Expression
Calling forms

Explicit context: Context.equal

equal(left: Any, right: Any) -> Expression

Expression method: Expression.equal

equal(other: ExpressionLike) -> Expression

equation#

Default context

equation(left: Any, right: Any) -> Expression
Calling forms

Explicit context: Context.equation

equation(left: Any, right: Any) -> Expression

Expression method: Expression.equation

equation(other: ExpressionLike) -> Expression

Constructs an equation value without evaluating it as a Boolean relation. Its two sides remain available for sidewise arithmetic and exact source-preserving solving.

transform_equation#

Default context

transform_equation(
    left: ExpressionLike,
    right: ExpressionLike,
    operation: str,
) -> EquationTransformation
Calling forms

Explicit context: Context.transform_equation

transform_equation(
    left: ExpressionLike,
    right: ExpressionLike,
    operation: str,
) -> EquationTransformation

Applies operation — "add", "subtract", "multiply", or "divide" — to an equation and a scalar, or adds or subtracts two equations, threading the operation over both sides. At least one operand must be an equation; two equations cannot be multiplied or divided, an equation cannot be a divisor, and a truth value beside an equation is refused.

The result says how the new equation relates to the old one, because not every side-wise operation preserves solutions. Adding or subtracting a scalar, multiplying by a factor proved nonzero, and dividing are equivalences: the new equation holds exactly where the old one does. Multiplying by a factor not proved nonzero, and combining two equations, give only a consequence: every solution of the input solves the result, but x(x−1)=0x(x - 1) = 0 also holds at x=0x = 0, where x−1=0x - 1 = 0 does not.

The relation is claimed under a condition on the free symbols. It records where a scalar operand is defined, because automatic simplification can cancel a pole out of the result — multiplying x=0x = 0 by 1/x1/x builds 1=01 = 0, and only the condition x≠0x \ne 0 still shows the lost point — and, for a divisor not proved nonzero, that the divisor is nonzero: dividing x2=xx^2 = x by xx gives x=1x = 1 under x≠0x \ne 0. A condition of true admits every point; false means the operand's domain could not be described and no claim is made.

The arithmetic operators and the add, subtract, multiply, and divide operations thread over equations the same way but return only the equation, so they refuse a multiplication or division that would need a guard to stay honest.

EquationTransformation#

What transform_equation returns:

Member Meaning
equation The transformed equation
relation equivalence or consequence
condition The Boolean condition under which the relation is claimed

Type

class EquationTransformation

An equation produced by side-wise arithmetic, with how it relates to its input.

transformation_equation#

EquationTransformation property

equation: Expression

Getter on EquationTransformation: the transformed equation.

transformation_relation#

EquationTransformation property

relation: str

Getter on EquationTransformation: whether the transformed equation is equivalent to its input or only implied by it.

transformation_condition#

EquationTransformation property

condition: Expression

Getter on EquationTransformation: the Boolean condition on the free symbols under which the relation is claimed.

not_equal#

Default context

not_equal(left: Any, right: Any) -> Expression
Calling forms

Explicit context: Context.not_equal

not_equal(left: Any, right: Any) -> Expression

Expression method: Expression.not_equal

not_equal(other: ExpressionLike) -> Expression

less_than#

Default context

less_than(left: Any, right: Any) -> Expression
Calling forms

Explicit context: Context.less_than

less_than(left: Any, right: Any) -> Expression

Expression method: Expression.__lt__

__lt__(other: ExpressionLike) -> Expression

Expression method: Expression.less_than

less_than(other: ExpressionLike) -> Expression

less_than_or_equal#

Default context

less_than_or_equal(left: Any, right: Any) -> Expression
Calling forms

Explicit context: Context.less_than_or_equal

less_than_or_equal(left: Any, right: Any) -> Expression

Expression method: Expression.__le__

__le__(other: ExpressionLike) -> Expression

Expression method: Expression.less_than_or_equal

less_than_or_equal(other: ExpressionLike) -> Expression

greater_than#

Default context

greater_than(left: Any, right: Any) -> Expression
Calling forms

Explicit context: Context.greater_than

greater_than(left: Any, right: Any) -> Expression

Expression method: Expression.__gt__

__gt__(other: ExpressionLike) -> Expression

Expression method: Expression.greater_than

greater_than(other: ExpressionLike) -> Expression

greater_than_or_equal#

Default context

greater_than_or_equal(left: Any, right: Any) -> Expression
Calling forms

Explicit context: Context.greater_than_or_equal

greater_than_or_equal(left: Any, right: Any) -> Expression

Expression method: Expression.__ge__

__ge__(other: ExpressionLike) -> Expression

Expression method: Expression.greater_than_or_equal

greater_than_or_equal(other: ExpressionLike) -> Expression

Example#

Relations are symbolic expressions until they are evaluated.

Python
import symi

x = symi.symbol("x")
relation = symi.less_than(x, 1)

print(relation)
print(symi.evaluate_truth(relation))
print(symi.evaluate_truth(symi.equal(symi.rational(2, 4), symi.rational(1, 2))))

Symi documentation · Python