def __init__(self, low, high, leaf=None): """*low* is the Function giving the lower boundary, *high* gives the upper boundary, and *leaf* is the Function to be clipped.""" self.low = asfunction(low) self.high = asfunction(high) self.leaf = asfunction(leaf)
def compound(obj): """Replaces lists, tuples, dicts, constants in *obj* by corresponding Functions. * lists are replaced by :class:`_List` instances. * tuples are replaced by :class:`_Tuple` instances. * dicts are replaced by :class:`_Dict` instances. * Other objects are passed through :func:`asfunction`. Use this method to generate Functions out of lists, tuples, or dictionary composed of other Functions.""" if isinstance(obj, list): return _List([compound(element) for element in obj]) elif isinstance(obj, tuple): return _Tuple([compound(element) for element in obj]) elif isinstance(obj, dict): keys = [compound(key) for key in obj.keys()] values = [compound(value) for value in obj.values()] return _Dict(dict(zip(keys, values))) else: return asfunction(obj)
def __rpow__(self, base): """Raises the other Function to the power of ``self``.""" base = asfunction(base) return Power(base=base, exponent=self)
def __pow__(self, exponent): """Raises ``self`` to the power of the other Function.""" exponent = asfunction(exponent) return Power(base=self, exponent=exponent)
def __rdiv__(self, other): """Returns the :class:`Quotient` of the other Function with ``self``.""" other = asfunction(other) return Quotient(other, self)
def __div__(self, other): """Returns the :class:`Quotient` with the other Function.""" other = asfunction(other) return Quotient(self, other)
def __rmul__(self, other): """Returns the :class:`Product` of the other Function with ``self``.""" other = asfunction(other) return Product(other, self)
def __init__(self, base, exponent): self.base = asfunction(base) self.exponent = asfunction(exponent)
def __mul__(self, other): """Returns the :class:`Product` with the other Function.""" other = asfunction(other) return Product(self, other)
def __init__(self, value, low, high): self.value = asfunction(value) self.low = asfunction(low) self.high = asfunction(high)
def __init__(self, A, B): self.A = asfunction(A) self.B = asfunction(B)
def __rsub__(self, other): """Returns the :class:`Sum` of the other Function with the negative of ``self``.""" other = asfunction(other) return Sum(other, -self)
def __init__(self, one, two): self.one = asfunction(one) self.two = asfunction(two)
def __sub__(self, other): """Returns the :class:`Sum` with the negative of the other Function.""" other = asfunction(other) return Sum(self, Neg(other))
def __radd__(self, other): """Returns the :class:`Sum` with another Function.""" other = asfunction(other) return Sum(other, self)
def __init__(self, a, b): """*b* will be executed with the output of *a* as input.""" self.a = asfunction(a) self.b = asfunction(b)