friendlysam.opt.Operation

class friendlysam.opt.Operation

An operation on some arguments.

This is a base class. Concrete examples:

Arithmetic operations:

  • Addition: Add
  • Subtraction: Sub
  • Multiplication: Mul
  • Summation: Sum

Relations:

Note

The Variable class and the arithmetic operation classes have overloaded operators which create Operation instances. For example:

>>> x = Variable('x')
>>> isinstance(x * 2, Operation)
True
>>> x + 1
<friendlysam.opt.Add at 0x...>
Operation.create(*args) Classmethod to create a new object.
Operation.evaluate([replace, evaluators]) Evaluate the expression recursively.
Operation.args This property holds the arguments of the operation.
Operation.leaves The leaves of the expression tree.
Operation.value The concrete value of the expression, if possible.
Operation.variables This property gives all leaves which are instances of Variable.