friendlysam.opt.Sum¶
-
class
friendlysam.opt.
Sum
¶ A sum of items.
See the base class
Operation
for a basic description of attributes and methods.Examples
Note that the constructor takes an iterable of arguments, just like the built-in
sum()
function, but the classmethodcreate()
takes a list of arguments, as follows.>>> x = VariableCollection('x') >>> terms = [x(i) for i in range(4)] >>> Sum(terms) == Sum.create(*terms) True
>>> s = Sum(terms) >>> s.evaluate(evaluators={Sum: sum}) Traceback (most recent call last): ... TypeError: sum expected at most 2 arguments, got 4
>>> s.evaluate(evaluators={Sum: lambda *args: sum(args)}) <friendlysam.opt.Add at 0x...>
Sum.create (*args) |
Classmethod to create a new Sum object. |
Sum.evaluate ([replace, evaluators]) |
Evaluate the expression recursively. |
Sum.args |
This property holds the arguments of the operation. |
Sum.leaves |
The leaves of the expression tree. |
Sum.value |
The concrete value of the expression, if possible. |
Sum.variables |
This property gives all leaves which are instances of Variable . |