Example #1
0
    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)
Example #2
0
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)
Example #3
0
    def __rpow__(self, base):
        """Raises the other Function to the power of ``self``."""

        base = asfunction(base)
        return Power(base=base, exponent=self)
Example #4
0
    def __pow__(self, exponent):
        """Raises ``self`` to the power of the other Function."""

        exponent = asfunction(exponent)
        return Power(base=self, exponent=exponent)
Example #5
0
    def __rdiv__(self, other):
        """Returns the :class:`Quotient` of the other Function with 
        ``self``."""

        other = asfunction(other)
        return Quotient(other, self)
Example #6
0
    def __div__(self, other):
        """Returns the :class:`Quotient` with the other Function."""

        other = asfunction(other)
        return Quotient(self, other)
Example #7
0
    def __rmul__(self, other):
        """Returns the :class:`Product` of the other Function with 
        ``self``."""

        other = asfunction(other)
        return Product(other, self)
Example #8
0
 def __init__(self, base, exponent):
     
     self.base = asfunction(base)
     self.exponent = asfunction(exponent)
Example #9
0
    def __mul__(self, other):
        """Returns the :class:`Product` with the other Function."""

        other = asfunction(other)
        return Product(self, other)
Example #10
0
 def __init__(self, value, low, high):
     
     self.value = asfunction(value)
     self.low = asfunction(low)
     self.high = asfunction(high)
Example #11
0
 def __init__(self, A, B):
     
     self.A = asfunction(A)
     self.B = asfunction(B)
Example #12
0
    def __rsub__(self, other):
        """Returns the :class:`Sum` of the other Function with the negative of
        ``self``."""

        other = asfunction(other)
        return Sum(other, -self)
Example #13
0
 def __init__(self, one, two):
     
     self.one = asfunction(one)
     self.two = asfunction(two)
Example #14
0
    def __sub__(self, other):
        """Returns the :class:`Sum` with the negative of the other 
        Function."""

        other = asfunction(other)
        return Sum(self, Neg(other))
Example #15
0
    def __radd__(self, other):
        """Returns the :class:`Sum` with another Function."""

        other = asfunction(other)
        return Sum(other, self)
Example #16
0
    def __init__(self, a, b):
        """*b* will be executed with the output of *a* as input."""

        self.a = asfunction(a)
        self.b = asfunction(b)