Skip to content

Element class

Bases: ABC

Base class representing a mathematical element.

The Element class serves as the global interface for mathematical entities. Subclasses should inherit from this class and implement the required methods.

Note: The supported mathematical operations on an Element instance depend on the specific entity being represented. These operations can include arithmetic operations, functions, and any other operations defined by the underlying mathematical element.

Source code in pyorlib/algebra/element.py
class Element(ABC):
    """
    Base class representing a mathematical element.

    The `Element` class serves as the global interface for mathematical entities.
    Subclasses should inherit from this class and implement the required methods.

    **Note**: The supported mathematical operations on an `Element` instance depend on the
    specific entity being represented. These operations can include arithmetic operations,
    functions, and any other operations defined by the underlying mathematical element.
    """

    @property
    @abstractmethod
    def raw(self) -> Any:
        """
        Returns the raw representation of the mathematical element.

        The `raw` method, when implemented by subclasses, returns the mathematical element in its raw format.
        The raw format can take various forms, such as an expression used by solvers or engines, or a
        mathematical expression that represents the entity itself.
        :return: The raw representation of the mathematical element.
        """
        pass

    @abstractmethod
    def _build_expression(self, expression: Any) -> "Element":
        """
        Abstract method to build an Element object based on the given expression.

        This method is used to implement how an `Element` object is built based on the result of a Python magic
        method operation. It handles the construction of a new `Element` instance using the given expression,
        which represents the result of the operation. This method is used in the normal magic methods for
        mathematical operations, as well as the `right` methods and comparison methods. However, it
        excludes the in-place methods, as their behavior depends on whether they build another
        expression or modify the same expression.

        :param expression: The expression representing the result of the Python magic method operation.
        :return: A new `Element` instance representing the built expression.
        """
        pass

    @abstractmethod
    def __str__(self) -> str:
        """
        Return a string representation of the element.
        :return: A string representation of the element.
        """
        pass

    # Addition
    def __add__(self, other: Any) -> "Element":
        """
        Addition operation.
        :param other: The `number` or `Element` instance to be added.
        :return: A new `Element` instance representing the addition.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw + other.raw)
        else:
            return self._build_expression(expression=self.raw + other)

    def __radd__(self, other: Any) -> "Element":
        """
        Right addition operation.
        :param other: The `number` or `Element` instance to be added.
        :return: A new `Element` instance representing the addition.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=other.raw + self.raw)
        else:
            return self._build_expression(expression=other + self.raw)

    @abstractmethod
    def __iadd__(self, other: Any) -> "Element":
        """
        In-place addition operation.
        :param other: The `number` or `Element` instance to be added.
        :return: The updated Element instance after addition.
        """
        pass

    # Subtraction
    def __sub__(self, other: Any) -> "Element":
        """
        Subtraction operation.
        :param other: The `number` or `Element` instance to be subtracted.
        :return: A new `Element` instance representing the subtraction.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw - other.raw)
        else:
            return self._build_expression(expression=self.raw - other)

    def __rsub__(self, other: Any) -> "Element":
        """
        Right subtraction operation.
        :param other: The `number` or `Element` instance to be subtracted.
        :return: A new `Element` instance representing the subtraction.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=other.raw - self.raw)
        else:
            return self._build_expression(expression=other - self.raw)

    @abstractmethod
    def __isub__(self, other: Any) -> "Element":
        """
        In-place subtraction operation.
        :param other: The `number` or `Element` instance to be subtracted.
        :return: The new/updated `Element` instance after subtraction.
        """
        pass

    # Multiplication
    def __mul__(self, other: Any) -> "Element":
        """
        Multiplication operation.
        :param other: The `number` or `Element` instance to be multiplied.
        :return: A new `Element` instance representing the multiplication.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw * other.raw)
        else:
            return self._build_expression(expression=self.raw * other)

    def __rmul__(self, other: Any) -> "Element":
        """
        Right multiplication operation.
        :param other: The `number` or `Element` instance to be multiplied.
        :return: A new `Element` instance representing the multiplication.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=other.raw * self.raw)
        else:
            return self._build_expression(expression=other * self.raw)

    @abstractmethod
    def __imul__(self, other: Any) -> "Element":
        """
        In-place multiplication operation.
        :param other: The `number` or `Element` instance to be multiplied.
        :return: The new/updated `Element` instance after multiplication.
        """
        pass

    # Division
    def __truediv__(self, other: Any) -> "Element":
        """
        Division operation.
        :param other: The `number` or `Element` instance to be divided.
        :return: A new `Element` instance representing the division.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw / other.raw)
        else:
            return self._build_expression(expression=self.raw / other)

    def __rtruediv__(self, other: Any) -> "Element":
        """
        Right division operation.
        :param other: The `number` or `Element` instance to be divided.
        :return: A new `Element` instance representing the division.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=other.raw / self.raw)
        else:
            return self._build_expression(expression=other / self.raw)

    @abstractmethod
    def __itruediv__(self, other: Any) -> "Element":
        """
        In-place division operation.
        :param other: The `number` or `Element` instance to be divided.
        :return: The new/updated `Element` instance after division.
        """
        pass

    # Floor Division
    def __floordiv__(self, other: Any) -> "Element":
        """
        Floor division operation.
        :param other: The `number` or `Element` instance to be floor divided.
        :return: A new `Element` instance representing the floor division.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw // other.raw)
        else:
            return self._build_expression(expression=self.raw // other)

    def __rfloordiv__(self, other: Any) -> "Element":
        """
        Right floor division operation.
        :param other: The `number` or `Element` instance to be floor divided.
        :return: A new `Element` instance representing the floor division.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=other.raw // self.raw)
        else:
            return self._build_expression(expression=other // self.raw)

    @abstractmethod
    def __ifloordiv__(self, other: Any) -> "Element":
        """
        In-place floor division operation.
        :param other: The `number` or `Element` instance to be floor divided.
        :return: The new/updated `Element` instance after floor division.
        """
        pass

    # Modulo
    def __mod__(self, other: Any) -> "Element":
        """
        Modulo operation.
        :param other: The `number` or `Element` instance to be used for modulo.
        :return: A new `Element` instance representing the modulo operation.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw % other.raw)
        else:
            return self._build_expression(expression=self.raw % other)

    def __rmod__(self, other: Any) -> "Element":
        """
        Right modulo operation.
        :param other: The `number` or `Element` instance to be used for modulo.
        :return: A new `Element` instance representing the modulo operation.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=other.raw % self.raw)
        else:
            return self._build_expression(expression=other % self.raw)

    @abstractmethod
    def __imod__(self, other: Any) -> "Element":
        """
        In-place modulo operation.
        :param other: The `number` or `Element` instance to be used for modulo.
        :return: The new/updated `Element` instance after modulo operation.
        """
        pass

    # Exponentiation
    def __pow__(self, other: Any) -> "Element":
        """
        Exponentiation operation.
        :param other: The `number` or `Element` instance to be used as the exponent.
        :return: A new `Element` instance representing the exponentiation.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw**other.raw)
        else:
            return self._build_expression(expression=self.raw**other)

    def __rpow__(self, other: Any) -> "Element":
        """
        Right exponentiation operation.
        :param other: The `number` or `Element` instance to be used as the base.
        :return: A new `Element` instance representing the exponentiation.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=other.raw**self.raw)
        else:
            return self._build_expression(expression=other**self.raw)

    @abstractmethod
    def __ipow__(self, other: Any) -> "Element":
        """
        In-place exponentiation operation.
        :param other: The `number` or `Element` instance to be used as the exponent.
        :return: The new/updated `Element` instance after exponentiation.
        """
        pass

    # Unary Operators
    def __neg__(self) -> "Element":
        """
        Negation operation.
        :return: A new `Element` instance representing the negation.
        """
        return self._build_expression(expression=-self.raw)

    def __pos__(self) -> "Element":
        """
        Positive operation.
        :return: A new `Element` instance representing the positive value.
        """
        return self._build_expression(expression=+self.raw)

    def __abs__(self) -> "Element":
        """
        Absolute value operation.
        :return: A new `Element` instance representing the absolute value.
        """
        return self._build_expression(expression=abs(self.raw))

    # Comparison Methods
    def __eq__(self, other: Any) -> "Element":  # type: ignore[override]
        """
        Equal to comparison.
        :param other: The `number` or `Element` instance to be compared.
        :return: A new `Element` instance representing the comparison result.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw == other.raw)
        else:
            return self._build_expression(expression=self.raw == other)

    def __ne__(self, other: Any) -> "Element":  # type: ignore[override]
        """
        Not equal to comparison.
        :param other: The `number` or `Element` instance to be compared.
        :return: A new `Element` instance representing the comparison result.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw != other.raw)
        else:
            return self._build_expression(expression=self.raw != other)

    def __lt__(self, other: Any) -> "Element":
        """
        Less than comparison.
        :param other: The `number` or `Element` instance to be compared.
        :return: A new `Element` instance representing the comparison result.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw < other.raw)
        else:
            return self._build_expression(expression=self.raw < other)

    def __le__(self, other: Any) -> "Element":
        """
        Less than or equal to comparison.
        :param other: The `number` or `Element` instance to be compared.
        :return: A new `Element` instance representing the comparison result.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw <= other.raw)
        else:
            return self._build_expression(expression=self.raw <= other)

    def __gt__(self, other: Any) -> "Element":
        """
        Greater than comparison.
        :param other: The `number` or `Element` instance to be compared.
        :return: A new `Element` instance representing the comparison result.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw > other.raw)
        else:
            return self._build_expression(expression=self.raw > other)

    def __ge__(self, other: Any) -> "Element":
        """
        Greater than or equal to comparison.
        :param other: The `number` or `Element` instance to be compared.
        :return: A new `Element` instance representing the comparison result.
        """
        if isinstance(other, Element):
            return self._build_expression(expression=self.raw >= other.raw)
        else:
            return self._build_expression(expression=self.raw >= other)

Attributes

raw abstractmethod property

raw: Any

Returns the raw representation of the mathematical element.

The raw method, when implemented by subclasses, returns the mathematical element in its raw format. The raw format can take various forms, such as an expression used by solvers or engines, or a mathematical expression that represents the entity itself.

RETURNS DESCRIPTION
Any

The raw representation of the mathematical element.

Functions

__add__

__add__(other: Any) -> Element

Addition operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be added.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the addition.

Source code in pyorlib/algebra/element.py
def __add__(self, other: Any) -> "Element":
    """
    Addition operation.
    :param other: The `number` or `Element` instance to be added.
    :return: A new `Element` instance representing the addition.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw + other.raw)
    else:
        return self._build_expression(expression=self.raw + other)

__radd__

__radd__(other: Any) -> Element

Right addition operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be added.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the addition.

Source code in pyorlib/algebra/element.py
def __radd__(self, other: Any) -> "Element":
    """
    Right addition operation.
    :param other: The `number` or `Element` instance to be added.
    :return: A new `Element` instance representing the addition.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=other.raw + self.raw)
    else:
        return self._build_expression(expression=other + self.raw)

__iadd__ abstractmethod

__iadd__(other: Any) -> Element

In-place addition operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be added.

TYPE: Any

RETURNS DESCRIPTION
Element

The updated Element instance after addition.

Source code in pyorlib/algebra/element.py
@abstractmethod
def __iadd__(self, other: Any) -> "Element":
    """
    In-place addition operation.
    :param other: The `number` or `Element` instance to be added.
    :return: The updated Element instance after addition.
    """
    pass

__sub__

__sub__(other: Any) -> Element

Subtraction operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be subtracted.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the subtraction.

Source code in pyorlib/algebra/element.py
def __sub__(self, other: Any) -> "Element":
    """
    Subtraction operation.
    :param other: The `number` or `Element` instance to be subtracted.
    :return: A new `Element` instance representing the subtraction.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw - other.raw)
    else:
        return self._build_expression(expression=self.raw - other)

__rsub__

__rsub__(other: Any) -> Element

Right subtraction operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be subtracted.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the subtraction.

Source code in pyorlib/algebra/element.py
def __rsub__(self, other: Any) -> "Element":
    """
    Right subtraction operation.
    :param other: The `number` or `Element` instance to be subtracted.
    :return: A new `Element` instance representing the subtraction.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=other.raw - self.raw)
    else:
        return self._build_expression(expression=other - self.raw)

__isub__ abstractmethod

__isub__(other: Any) -> Element

In-place subtraction operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be subtracted.

TYPE: Any

RETURNS DESCRIPTION
Element

The new/updated Element instance after subtraction.

Source code in pyorlib/algebra/element.py
@abstractmethod
def __isub__(self, other: Any) -> "Element":
    """
    In-place subtraction operation.
    :param other: The `number` or `Element` instance to be subtracted.
    :return: The new/updated `Element` instance after subtraction.
    """
    pass

__mul__

__mul__(other: Any) -> Element

Multiplication operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be multiplied.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the multiplication.

Source code in pyorlib/algebra/element.py
def __mul__(self, other: Any) -> "Element":
    """
    Multiplication operation.
    :param other: The `number` or `Element` instance to be multiplied.
    :return: A new `Element` instance representing the multiplication.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw * other.raw)
    else:
        return self._build_expression(expression=self.raw * other)

__rmul__

__rmul__(other: Any) -> Element

Right multiplication operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be multiplied.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the multiplication.

Source code in pyorlib/algebra/element.py
def __rmul__(self, other: Any) -> "Element":
    """
    Right multiplication operation.
    :param other: The `number` or `Element` instance to be multiplied.
    :return: A new `Element` instance representing the multiplication.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=other.raw * self.raw)
    else:
        return self._build_expression(expression=other * self.raw)

__imul__ abstractmethod

__imul__(other: Any) -> Element

In-place multiplication operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be multiplied.

TYPE: Any

RETURNS DESCRIPTION
Element

The new/updated Element instance after multiplication.

Source code in pyorlib/algebra/element.py
@abstractmethod
def __imul__(self, other: Any) -> "Element":
    """
    In-place multiplication operation.
    :param other: The `number` or `Element` instance to be multiplied.
    :return: The new/updated `Element` instance after multiplication.
    """
    pass

__truediv__

__truediv__(other: Any) -> Element

Division operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be divided.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the division.

Source code in pyorlib/algebra/element.py
def __truediv__(self, other: Any) -> "Element":
    """
    Division operation.
    :param other: The `number` or `Element` instance to be divided.
    :return: A new `Element` instance representing the division.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw / other.raw)
    else:
        return self._build_expression(expression=self.raw / other)

__rtruediv__

__rtruediv__(other: Any) -> Element

Right division operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be divided.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the division.

Source code in pyorlib/algebra/element.py
def __rtruediv__(self, other: Any) -> "Element":
    """
    Right division operation.
    :param other: The `number` or `Element` instance to be divided.
    :return: A new `Element` instance representing the division.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=other.raw / self.raw)
    else:
        return self._build_expression(expression=other / self.raw)

__itruediv__ abstractmethod

__itruediv__(other: Any) -> Element

In-place division operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be divided.

TYPE: Any

RETURNS DESCRIPTION
Element

The new/updated Element instance after division.

Source code in pyorlib/algebra/element.py
@abstractmethod
def __itruediv__(self, other: Any) -> "Element":
    """
    In-place division operation.
    :param other: The `number` or `Element` instance to be divided.
    :return: The new/updated `Element` instance after division.
    """
    pass

__floordiv__

__floordiv__(other: Any) -> Element

Floor division operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be floor divided.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the floor division.

Source code in pyorlib/algebra/element.py
def __floordiv__(self, other: Any) -> "Element":
    """
    Floor division operation.
    :param other: The `number` or `Element` instance to be floor divided.
    :return: A new `Element` instance representing the floor division.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw // other.raw)
    else:
        return self._build_expression(expression=self.raw // other)

__rfloordiv__

__rfloordiv__(other: Any) -> Element

Right floor division operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be floor divided.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the floor division.

Source code in pyorlib/algebra/element.py
def __rfloordiv__(self, other: Any) -> "Element":
    """
    Right floor division operation.
    :param other: The `number` or `Element` instance to be floor divided.
    :return: A new `Element` instance representing the floor division.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=other.raw // self.raw)
    else:
        return self._build_expression(expression=other // self.raw)

__ifloordiv__ abstractmethod

__ifloordiv__(other: Any) -> Element

In-place floor division operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be floor divided.

TYPE: Any

RETURNS DESCRIPTION
Element

The new/updated Element instance after floor division.

Source code in pyorlib/algebra/element.py
@abstractmethod
def __ifloordiv__(self, other: Any) -> "Element":
    """
    In-place floor division operation.
    :param other: The `number` or `Element` instance to be floor divided.
    :return: The new/updated `Element` instance after floor division.
    """
    pass

__mod__

__mod__(other: Any) -> Element

Modulo operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be used for modulo.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the modulo operation.

Source code in pyorlib/algebra/element.py
def __mod__(self, other: Any) -> "Element":
    """
    Modulo operation.
    :param other: The `number` or `Element` instance to be used for modulo.
    :return: A new `Element` instance representing the modulo operation.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw % other.raw)
    else:
        return self._build_expression(expression=self.raw % other)

__rmod__

__rmod__(other: Any) -> Element

Right modulo operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be used for modulo.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the modulo operation.

Source code in pyorlib/algebra/element.py
def __rmod__(self, other: Any) -> "Element":
    """
    Right modulo operation.
    :param other: The `number` or `Element` instance to be used for modulo.
    :return: A new `Element` instance representing the modulo operation.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=other.raw % self.raw)
    else:
        return self._build_expression(expression=other % self.raw)

__imod__ abstractmethod

__imod__(other: Any) -> Element

In-place modulo operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be used for modulo.

TYPE: Any

RETURNS DESCRIPTION
Element

The new/updated Element instance after modulo operation.

Source code in pyorlib/algebra/element.py
@abstractmethod
def __imod__(self, other: Any) -> "Element":
    """
    In-place modulo operation.
    :param other: The `number` or `Element` instance to be used for modulo.
    :return: The new/updated `Element` instance after modulo operation.
    """
    pass

__pow__

__pow__(other: Any) -> Element

Exponentiation operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be used as the exponent.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the exponentiation.

Source code in pyorlib/algebra/element.py
def __pow__(self, other: Any) -> "Element":
    """
    Exponentiation operation.
    :param other: The `number` or `Element` instance to be used as the exponent.
    :return: A new `Element` instance representing the exponentiation.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw**other.raw)
    else:
        return self._build_expression(expression=self.raw**other)

__rpow__

__rpow__(other: Any) -> Element

Right exponentiation operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be used as the base.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the exponentiation.

Source code in pyorlib/algebra/element.py
def __rpow__(self, other: Any) -> "Element":
    """
    Right exponentiation operation.
    :param other: The `number` or `Element` instance to be used as the base.
    :return: A new `Element` instance representing the exponentiation.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=other.raw**self.raw)
    else:
        return self._build_expression(expression=other**self.raw)

__ipow__ abstractmethod

__ipow__(other: Any) -> Element

In-place exponentiation operation.

PARAMETER DESCRIPTION
other

The number or Element instance to be used as the exponent.

TYPE: Any

RETURNS DESCRIPTION
Element

The new/updated Element instance after exponentiation.

Source code in pyorlib/algebra/element.py
@abstractmethod
def __ipow__(self, other: Any) -> "Element":
    """
    In-place exponentiation operation.
    :param other: The `number` or `Element` instance to be used as the exponent.
    :return: The new/updated `Element` instance after exponentiation.
    """
    pass

__neg__

__neg__() -> Element

Negation operation.

RETURNS DESCRIPTION
Element

A new Element instance representing the negation.

Source code in pyorlib/algebra/element.py
def __neg__(self) -> "Element":
    """
    Negation operation.
    :return: A new `Element` instance representing the negation.
    """
    return self._build_expression(expression=-self.raw)

__pos__

__pos__() -> Element

Positive operation.

RETURNS DESCRIPTION
Element

A new Element instance representing the positive value.

Source code in pyorlib/algebra/element.py
def __pos__(self) -> "Element":
    """
    Positive operation.
    :return: A new `Element` instance representing the positive value.
    """
    return self._build_expression(expression=+self.raw)

__abs__

__abs__() -> Element

Absolute value operation.

RETURNS DESCRIPTION
Element

A new Element instance representing the absolute value.

Source code in pyorlib/algebra/element.py
def __abs__(self) -> "Element":
    """
    Absolute value operation.
    :return: A new `Element` instance representing the absolute value.
    """
    return self._build_expression(expression=abs(self.raw))

__eq__

__eq__(other: Any) -> Element

Equal to comparison.

PARAMETER DESCRIPTION
other

The number or Element instance to be compared.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the comparison result.

Source code in pyorlib/algebra/element.py
def __eq__(self, other: Any) -> "Element":  # type: ignore[override]
    """
    Equal to comparison.
    :param other: The `number` or `Element` instance to be compared.
    :return: A new `Element` instance representing the comparison result.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw == other.raw)
    else:
        return self._build_expression(expression=self.raw == other)

__ne__

__ne__(other: Any) -> Element

Not equal to comparison.

PARAMETER DESCRIPTION
other

The number or Element instance to be compared.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the comparison result.

Source code in pyorlib/algebra/element.py
def __ne__(self, other: Any) -> "Element":  # type: ignore[override]
    """
    Not equal to comparison.
    :param other: The `number` or `Element` instance to be compared.
    :return: A new `Element` instance representing the comparison result.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw != other.raw)
    else:
        return self._build_expression(expression=self.raw != other)

__lt__

__lt__(other: Any) -> Element

Less than comparison.

PARAMETER DESCRIPTION
other

The number or Element instance to be compared.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the comparison result.

Source code in pyorlib/algebra/element.py
def __lt__(self, other: Any) -> "Element":
    """
    Less than comparison.
    :param other: The `number` or `Element` instance to be compared.
    :return: A new `Element` instance representing the comparison result.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw < other.raw)
    else:
        return self._build_expression(expression=self.raw < other)

__le__

__le__(other: Any) -> Element

Less than or equal to comparison.

PARAMETER DESCRIPTION
other

The number or Element instance to be compared.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the comparison result.

Source code in pyorlib/algebra/element.py
def __le__(self, other: Any) -> "Element":
    """
    Less than or equal to comparison.
    :param other: The `number` or `Element` instance to be compared.
    :return: A new `Element` instance representing the comparison result.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw <= other.raw)
    else:
        return self._build_expression(expression=self.raw <= other)

__gt__

__gt__(other: Any) -> Element

Greater than comparison.

PARAMETER DESCRIPTION
other

The number or Element instance to be compared.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the comparison result.

Source code in pyorlib/algebra/element.py
def __gt__(self, other: Any) -> "Element":
    """
    Greater than comparison.
    :param other: The `number` or `Element` instance to be compared.
    :return: A new `Element` instance representing the comparison result.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw > other.raw)
    else:
        return self._build_expression(expression=self.raw > other)

__ge__

__ge__(other: Any) -> Element

Greater than or equal to comparison.

PARAMETER DESCRIPTION
other

The number or Element instance to be compared.

TYPE: Any

RETURNS DESCRIPTION
Element

A new Element instance representing the comparison result.

Source code in pyorlib/algebra/element.py
def __ge__(self, other: Any) -> "Element":
    """
    Greater than or equal to comparison.
    :param other: The `number` or `Element` instance to be compared.
    :return: A new `Element` instance representing the comparison result.
    """
    if isinstance(other, Element):
        return self._build_expression(expression=self.raw >= other.raw)
    else:
        return self._build_expression(expression=self.raw >= other)