Example #1
0
 def check(x):
     x = interval(x)
     z = tanh(x)
     assert z in imath.sinh(x)/imath.cosh(x)
Example #2
0
 def test_cosh(self):
     self.assertEqual(imath.cosh(0), interval[1])
     assert imath.cosh(2) in (imath.exp(2) + imath.exp(-2))/2
     assert imath.cosh(interval[1, 2]) == interval.hull((imath.cosh(1), imath.cosh(2)))
     assert imath.cosh(interval[-2, -1])  == imath.cosh(interval[1, 2])
     assert imath.cosh(interval[-2, 1]) == interval.hull((interval[1], imath.cosh(2)))
     assert imath.cosh(interval[-1, 2]) == interval.hull((interval[1], imath.cosh(2)))
Example #3
0
 def test_cosh(self):
     self.assertEqual(imath.cosh(0), interval[1])
     assert imath.cosh(2) in (imath.exp(2) + imath.exp(-2)) / 2
     assert imath.cosh(interval[1, 2]) == interval.hull(
         (imath.cosh(1), imath.cosh(2)))
     assert imath.cosh(interval[-2, -1]) == imath.cosh(interval[1, 2])
     assert imath.cosh(interval[-2, 1]) == interval.hull(
         (interval[1], imath.cosh(2)))
     assert imath.cosh(interval[-1, 2]) == interval.hull(
         (interval[1], imath.cosh(2)))
Example #4
0
 def check(x):
     x = interval(x)
     z = tanh(x)
     assert z in imath.sinh(x) / imath.cosh(x)
Example #5
0
    def __eval(self, n_id, box):
        n = self.__dag[n_id]

        rec = self.__eval

        if n[0] == '+':
            v1 = rec(n[1], box)
            v2 = rec(n[2], box)
            return v1 + v2
        elif n[0] == '-':
            v1 = rec(n[1], box)
            v2 = rec(n[2], box)
            return v1 - v2
        elif n[0] == '*':
            v1 = rec(n[1], box)
            v2 = rec(n[2], box)
            return v1 * v2
        elif n[0] == '/':
            v1 = rec(n[1], box)
            v2 = rec(n[2], box)
            return v1 / v2

        elif n[0] == '^':
            v = rec(n[1], box)
            i = self.__dag[n[2]][1]
            return v**i

        elif n[0] == 'exp':
            v = rec(n[1], box)
            return imath.exp(v)

        elif n[0] == 'log':
            v = rec(n[1], box)
            return imath.log(v)

        elif n[0] == 'sqrt':
            v = rec(n[1], box)
            return imath.sqrt(v)

        elif n[0] == 'sin':
            v = rec(n[1], box)
            return imath.sin(v)

        elif n[0] == 'cos':
            v = rec(n[1], box)
            return imath.cos(v)

        elif n[0] == 'tan':
            v = rec(n[1], box)
            return imath.tan(v)

        elif n[0] == 'asin':
            v = rec(n[1], box)
            return imath.asin(v)

        elif n[0] == 'acos':
            v = rec(n[1], box)
            return imath.acos(v)

        elif n[0] == 'atan':
            v = rec(n[1], box)
            return imath.atan(v)

        elif n[0] == 'sinh':
            v = rec(n[1], box)
            return imath.sinh(v)

        elif n[0] == 'cosh':
            v = rec(n[1], box)
            return imath.cosh(v)

        elif n[0] == 'tanh':
            v = rec(n[1], box)
            return imath.tanh(v)

        elif n[0] == 'C':
            return interval[n[1]]
        elif n[0] == 'V':
            return box[n[1]]
        else:
            print('unsupported node: ' + str(n))
            assert (False)