qilisdk.core.comparison

Comparisons between expressions.

A Comparison relates two Expression operands with one of the six ComparisonOperation relations. It is not an Expression itself: it is the relation type that Constraint is built from. Build one with the LT()/LEQ()/EQ()/NEQ()/GT()/GEQ() helpers rather than by hand.

Attributes

LessThan

LessThanOrEqual

Equal

NotEqual

GreaterThan

GreaterThanOrEqual

Classes

ComparisonOperation

str(object='') -> str

Comparison

A comparison (equality or inequality) between two Expression operands.

Functions

LT(→ Comparison)

'Less Than' mathematical operation.

LEQ(→ Comparison)

'Less Than or equal to' mathematical operation.

EQ(→ Comparison)

'Equal to' mathematical operation.

NEQ(→ Comparison)

'Not Equal to' mathematical operation.

GT(→ Comparison)

'Greater Than' mathematical operation.

GEQ(→ Comparison)

'Greater Than or equal to' mathematical operation.

Module Contents

class ComparisonOperation[font]

Bases: qilisdk.core.types.QiliEnum

str(object=””) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to “utf-8”. errors defaults to “strict”.

Initialize self. See help(type(self)) for accurate signature.

LT = '<'[font]
LEQ = '<='[font]
EQ = '=='[font]
NEQ = '!='[font]
GT = '>'[font]
GEQ = '>='[font]
LT(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]

“Less Than” mathematical operation.

Paràmetres:
  • lhs (RealNumber | Expression) – the left hand side of the comparison term.

  • rhs (RealNumber | Expression) – the right hand side of the comparison term.

Retorna:

a comparison term with the structure lhs < rhs.

Tipus de retorn:

Comparison

LessThan[font]
LEQ(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]

“Less Than or equal to” mathematical operation.

Paràmetres:
  • lhs (RealNumber | Expression) – the left hand side of the comparison term.

  • rhs (RealNumber | Expression) – the right hand side of the comparison term.

Retorna:

a comparison term with the structure lhs <= rhs.

Tipus de retorn:

Comparison

LessThanOrEqual[font]
EQ(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]

“Equal to” mathematical operation.

Paràmetres:
  • lhs (RealNumber | Expression) – the left hand side of the comparison term.

  • rhs (RealNumber | Expression) – the right hand side of the comparison term.

Retorna:

a comparison term with the structure lhs == rhs.

Tipus de retorn:

Comparison

Equal[font]
NEQ(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]

“Not Equal to” mathematical operation.

Paràmetres:
  • lhs (RealNumber | Expression) – the left hand side of the comparison term.

  • rhs (RealNumber | Expression) – the right hand side of the comparison term.

Retorna:

a comparison term with the structure lhs != rhs.

Tipus de retorn:

Comparison

NotEqual[font]
GT(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]

“Greater Than” mathematical operation.

Paràmetres:
  • lhs (RealNumber | Expression) – the left hand side of the comparison term.

  • rhs (RealNumber | Expression) – the right hand side of the comparison term.

Retorna:

a comparison term with the structure lhs > rhs.

Tipus de retorn:

Comparison

GreaterThan[font]
GEQ(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]

“Greater Than or equal to” mathematical operation.

Paràmetres:
  • lhs (RealNumber | Expression) – the left hand side of the comparison term.

  • rhs (RealNumber | Expression) – the right hand side of the comparison term.

Retorna:

a comparison term with the structure lhs >= rhs.

Tipus de retorn:

Comparison

GreaterThanOrEqual[font]
class Comparison(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, operation: ComparisonOperation)[font]

A comparison (equality or inequality) between two Expression operands.

The relation is normalized at construction to lhs - rhs <op> 0 with the additive constant moved to the right-hand side (so lhs carries no constant and rhs is that constant).

Initialize a new comparison term.

Paràmetres:
  • lhs (RealNumber | Expression) – the left hand side of the comparison.

  • rhs (RealNumber | Expression) – the right hand side of the comparison.

  • operation (ComparisonOperation) – the comparison operation.

Llença:

TypeError – if an operand is neither a number nor an Expression.

property operation: ComparisonOperation[font]

The comparison operation.

property lhs: qilisdk.core.expression.Expression[font]

The left hand side of the comparison term.

property rhs: qilisdk.core.expression.Expression[font]

The right hand side of the comparison term.

variables() list[qilisdk.core.variables.BaseVariable][font]

Collect the unique variables in the comparison term.

Retorna:

the variables, sorted by label.

Tipus de retorn:

list[BaseVariable]

property degree: int[font]

The maximum degree of the two sides of the comparison term.

to_binary() Comparison[font]

Encode the continuous variables of both sides into binary.

Retorna:

the comparison term with both sides encoded into binary.

Tipus de retorn:

Comparison

evaluate(var_values: collections.abc.Mapping[qilisdk.core.variables.BaseVariable, qilisdk.core.types.RealNumber | list[int]]) bool[font]

Evaluate the comparison given a set of variable values.

Paràmetres:

var_values (Mapping[BaseVariable, RealNumber | list[int]]) – the variable assignment.

Retorna:

the result of the comparison.

Tipus de retorn:

bool

Llença:

ValueError – if evaluation yields a complex value.