Пример #1
0
 def test_split(self):
     # If this ever breaks, we should solve the problem by writing a
     # new kind of Function that turns a lambda expression into a
     # Function.  That way, it will never be simplified.
     # f = x^2 + x
     f = Function.sum(Function.power(Function.identity(),
                                     Function.constant(2)),
                      Function.identity())
     # f(-1) = 0, f(0) = 0, f(-.5) = -.25
     # The range of f on [-1,0] is [-.25,0]
     # f([-1,0]) = [-1,1]
     # f([-1,-.5]) = [-.75,.5]
     # f([-.5,0]) = [-.5,.25]
     # This will never finish, since it asks for the exact bounds
     self.assertTrue(is_bounded(f, Interval(-1,0), Interval(-1/4,0))
                     is None)
     # g = 1/2*x^3-3/2*x
     g = Function.sum(Function.product(
             Function.constant(.5),
             Function.power(Function.identity(),
                            Function.constant(3))),
         Function.product(Function.constant(-1.5),
                          Function.identity()))
     self.assertEqual(is_bounded(g, Interval(-1.5,1.5), Interval(-.9,1)),
                      False)
     # This encounters a ValueError on the first split so should
     # return None
     h = Function.quotient(Function.constant(1), Function.identity())
     self.assertTrue(is_bounded(h, Interval(-1,1), Interval(-5,5)) is None)