Esempio n. 1
0
 def test_bound_variable(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     man: PyManager = PyBoxMPQManager()
     variables = [PyVar('x0'), PyVar('y')]
     intervals = [PyMPQInterval(-3, 2), PyMPQInterval(-2, 2, 1, 1)]
     b = PyBox(man, e, variables=variables, intervals=intervals)
     self.assertEqual(str(b.bound_variable(PyVar('y'))), '[-2,2]')
Esempio n. 2
0
 def test_forget(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     man: PyManager = PyBoxMPQManager()
     variables = [PyVar('x0'), PyVar('y')]
     intervals = [PyMPQInterval(-3, 2), PyMPQInterval(-2, 2, 1, 1)]
     b = PyBox(man, e, variables=variables, intervals=intervals)
     self.assertEqual(str(b.forget([PyVar('y')])),
                      '1·x0 + 3 >= 0 ∧ -1·x0 + 2 >= 0')
Esempio n. 3
0
 def test_bound_texpr(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     man: PyManager = PyBoxMPQManager()
     variables = [PyVar('x0'), PyVar('y')]
     intervals = [PyMPQInterval(-3, 2), PyMPQInterval(-2, 2, 1, 1)]
     b = PyBox(man, e, variables=variables, intervals=intervals)
     x0 = PyTexpr1.var(e, PyVar('x0'))
     x1 = PyTexpr1.var(e, PyVar('y'))
     add = PyTexpr1.binop(TexprOp.AP_TEXPR_ADD, x0, x1,
                          TexprRtype.AP_RTYPE_REAL, TexprRdir.AP_RDIR_RND)
     self.assertEqual(str(b.bound_texpr(add)), '[-5,4]')
Esempio n. 4
0
 def test_is_top(self):
     self.assertFalse(PyMPQInterval().is_top())
     self.assertFalse(PyMPQInterval(0, 0).is_top())
     self.assertFalse(PyMPQInterval(0, 0, 1, 1).is_top())
     self.assertFalse(
         PyMPQInterval(PyMPQScalar(0), PyMPQScalar(0)).is_top())
     self.assertFalse(
         PyMPQInterval(PyMPQScalar(0, 1), PyMPQScalar(0, 1)).is_top())
     self.assertFalse(PyMPQInterval(-1, 1, 2, 2).is_top())
     self.assertFalse(PyMPQInterval(PyMPQ(-1, 2), PyMPQ(1, 2)).is_top())
     self.assertFalse(
         PyMPQInterval(PyMPQScalar(-1, 2), PyMPQScalar(1, 2)).is_top())
     self.assertTrue(PyMPQInterval.top().is_top())
     self.assertFalse(PyMPQInterval.bottom().is_top())
Esempio n. 5
0
 def test_init(self):
     self.assertEqual(str(PyMPQInterval()), '[0,0]')
     self.assertEqual(str(PyMPQInterval(0, 0)), '[0,0]')
     self.assertEqual(str(PyMPQInterval(0, 0, 1, 1)), '[0,0]')
     self.assertEqual(str(PyMPQInterval(PyMPQScalar(0), PyMPQScalar(0))),
                      '[0,0]')
     self.assertEqual(
         str(PyMPQInterval(PyMPQScalar(0, 1), PyMPQScalar(0, 1))), '[0,0]')
     self.assertEqual(str(PyMPQInterval(-1, 1, 2, 2)), '[-1/2,1/2]')
     self.assertEqual(str(PyMPQInterval(PyMPQ(-1, 2), PyMPQ(1, 2))),
                      '[-1/2,1/2]')
     self.assertEqual(
         str(PyMPQInterval(PyMPQScalar(-1, 2), PyMPQScalar(1, 2))),
         '[-1/2,1/2]')
     self.assertEqual(str(PyMPQInterval.top()), '[-1/0,1/0]')
     self.assertEqual(str(PyMPQInterval.bottom()), '[1,-1]')
Esempio n. 6
0
 def visit_LengthIdentifier(self,
                            expr: 'LengthIdentifier',
                            environment=None,
                            usub=False):
     assert not usub
     return PyTexpr1.cst(environment,
                         PyMPQIntervalCoeff(PyMPQInterval.top()))
Esempio n. 7
0
 def test_top(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     man: PyManager = PyBoxDManager()
     self.assertFalse(PyBox.bottom(man, e).is_top())
     b1 = PyBox(man,
                e,
                variables=[PyVar('x0')],
                intervals=[PyDoubleInterval(-2.5, 2.5)])
     self.assertFalse(b1.is_bottom())
     b2 = PyBox(man,
                e,
                variables=[PyVar('y')],
                intervals=[PyMPQInterval(-5, 5, 2, 2)])
     self.assertFalse(b2.is_bottom())
     b3 = PyBox(man,
                e,
                variables=[PyVar('z')],
                intervals=[PyMPFRInterval(-2.5, 2.5)])
     self.assertFalse(b3.is_bottom())
     self.assertTrue(PyBox.top(man, e).is_top())
Esempio n. 8
0
 def test_neg(self):
     self.assertEqual(-PyMPQInterval.bottom(), PyMPQInterval.bottom())
     self.assertEqual(-PyMPQInterval(-1, 2), PyMPQInterval(-2, 1))
     self.assertEqual(-PyMPQInterval(), PyMPQInterval(0, 0))
     self.assertEqual(-PyMPQInterval(-1, 1, 2, 2),
                      PyMPQInterval(-PyMPQ(1, 2), PyMPQ(1, 2)))
     self.assertEqual(-PyMPQInterval(1, 1, 2, 2),
                      PyMPQInterval(-PyMPQ(1, 2), -PyMPQ(1, 2)))
     self.assertEqual(-PyMPQInterval(1, 1, 2, 2),
                      PyMPQInterval(PyMPQ(-1, 2), PyMPQ(-1, 2)))
     self.assertEqual(-PyMPQInterval(1, 2), PyMPQInterval(-2, -1))
     self.assertEqual(-PyMPQInterval.top(), PyMPQInterval.top())
Esempio n. 9
0
 def test_cmp(self):
     self.assertTrue(PyMPQInterval.bottom() < PyMPQInterval())
     self.assertFalse(PyMPQInterval() < PyMPQInterval.bottom())
     self.assertTrue(PyMPQInterval() < PyMPQInterval(-1, 1, 2, 2))
     self.assertFalse(PyMPQInterval(-1, 1, 2, 2) < PyMPQInterval())
     self.assertTrue(PyMPQInterval(-1, 1, 2, 2) < PyMPQInterval.top())
     self.assertFalse(PyMPQInterval.top() < PyMPQInterval(-1, 1, 2, 2))
     self.assertFalse(PyMPQInterval.bottom() == PyMPQInterval())
     self.assertTrue(PyMPQInterval() == PyMPQInterval(0, 0))
     self.assertFalse(PyMPQInterval() == PyMPQInterval(-1, 1, 2, 2))
     self.assertTrue(
         PyMPQInterval(-1, 1, 2, 2) == PyMPQInterval(
             PyMPQ(-1, 2), PyMPQ(1, 2)))
     self.assertFalse(PyMPQInterval(-1, 1, 2, 2) == PyMPQInterval.top())
     self.assertFalse(PyMPQInterval.bottom() > PyMPQInterval())
     self.assertTrue(PyMPQInterval() > PyMPQInterval.bottom())
     self.assertFalse(PyMPQInterval() > PyMPQInterval(-1, 1, 2, 2))
     self.assertTrue(PyMPQInterval(-1, 1, 2, 2) > PyMPQInterval())
     self.assertFalse(PyMPQInterval(-1, 1, 2, 2) > PyMPQInterval.top())
     self.assertTrue(PyMPQInterval.top() > PyMPQInterval(-1, 1, 2, 2))
     self.assertTrue(
         PyMPQInterval(-3, -1) <= PyMPQInterval(PyMPQScalar.init_infty(-1),
                                                PyMPQScalar(-1)))
Esempio n. 10
0
 def test_deepcopy(self):
     i0 = PyMPQInterval(0, 0)
     i1 = deepcopy(i0)
     i2 = i0
     self.assertNotEqual(id(i0), id(i1))
     self.assertEqual(id(i0), id(i2))
Esempio n. 11
0
 def visit_Input(self, expr, environment=None, usub=False) -> PyTexpr1:
     assert not usub
     return PyTexpr1.cst(environment, PyMPQIntervalCoeff(PyMPQInterval.top()))
Esempio n. 12
0
 def __init__(self, value_or_inf_num=0, sup_num=0, inf_den=1, sup_den=1):
     if isinstance(value_or_inf_num, (Coeff, PyMPQInterval)):
         super().__init__(value_or_inf_num)
     else:
         super().__init__(
             PyMPQInterval(value_or_inf_num, sup_num, inf_den, sup_den))
Esempio n. 13
0
 def test_meet(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     man: PyManager = PyBoxDManager()
     b0 = PyBox.bottom(man, e)
     b1d = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyDoubleInterval(-2.5, 0.0)])
     b1q = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPQInterval(-5, 0, 2, 1)])
     b1f = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPFRInterval(-2.5, 0.0)])
     b2d = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyDoubleInterval(0.0, 2.5)])
     b2q = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPQInterval(0, 5, 1, 2)])
     b2f = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPFRInterval(0.0, 2.5)])
     b3d = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyDoubleInterval(0.0, 0.0)])
     b3q = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPQInterval(0, 0, 1, 1)])
     b3f = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPFRInterval(0.0, 0.0)])
     b4 = PyBox.top(man, e)
     self.assertTrue(b0.meet(b1d) == b0)
     self.assertTrue(b0.meet(b1q) == b0)
     self.assertTrue(b0.meet(b1f) == b0)
     self.assertTrue(b0.meet(b2d) == b0)
     self.assertTrue(b0.meet(b2q) == b0)
     self.assertTrue(b0.meet(b2f) == b0)
     self.assertTrue(b0.meet(b3d) == b0)
     self.assertTrue(b0.meet(b3q) == b0)
     self.assertTrue(b0.meet(b3f) == b0)
     self.assertTrue(b1d.meet(b2d) == b3d)
     self.assertTrue(b1d.meet(b3d) == b3d)
     self.assertTrue(b2d.meet(b3d) == b3d)
     self.assertTrue(b1q.meet(b2q) == b3q)
     self.assertTrue(b1q.meet(b3q) == b3q)
     self.assertTrue(b2q.meet(b3q) == b3q)
     self.assertTrue(b1f.meet(b2f) == b3f)
     self.assertTrue(b1f.meet(b3f) == b3f)
     self.assertTrue(b2f.meet(b3f) == b3f)
     self.assertTrue(b1d.meet(b4) == b1d)
     self.assertTrue(b1q.meet(b4) == b1q)
     self.assertTrue(b1f.meet(b4) == b1f)
     self.assertTrue(b2d.meet(b4) == b2d)
     self.assertTrue(b2q.meet(b4) == b2q)
     self.assertTrue(b2f.meet(b4) == b2f)
     self.assertTrue(b3d.meet(b4) == b3d)
     self.assertTrue(b3q.meet(b4) == b3q)
     self.assertTrue(b3f.meet(b4) == b3f)