Esempio n. 1
0
 def test_fourth(self):
     " 1/4 is exact."
     from operator import truediv
     assert  1 / 4.0 == fpu.down(lambda: truediv(1.0,  4.0))
     assert  1 / 4.0 == fpu.up  (lambda: truediv(1.0,  4.0))
     assert -1 / 4.0 == fpu.up  (lambda: truediv(1.0, -4.0))
     assert -1 / 4.0 == fpu.down(lambda: truediv(1.0, -4.0))
Esempio n. 2
0
 def test_third(self):
     "Nearest rounding of 1/3 is downwards."
     from operator import truediv
     assert  1 / 3.0 == fpu.down(lambda: truediv(1.0,  3.0))
     assert  1 / 3.0 <  fpu.up  (lambda: truediv(1.0,  3.0))
     assert -1 / 3.0 == fpu.up  (lambda: truediv(1.0, -3.0))
     assert -1 / 3.0 >  fpu.down(lambda: truediv(1.0, -3.0))
Esempio n. 3
0
 def test_fifth(self):
     "Nearest rounding of 1/5 is upwards."
     from operator import truediv
     assert  1 / 5.0 == fpu.up  (lambda: truediv(1.0,  5.0))
     assert  1 / 5.0 >  fpu.down(lambda: truediv(1.0,  5.0))
     assert -1 / 5.0 == fpu.down(lambda: truediv(1.0, -5.0))
     assert -1 / 5.0 <  fpu.up  (lambda: truediv(1.0, -5.0))
Esempio n. 4
0
 def test_fifth(self):
     "Nearest rounding of 1/5 is upwards."
     from operator import truediv
     assert  1 / 5.0 == fpu.up  (lambda: truediv(1.0,  5.0))
     assert  1 / 5.0 >  fpu.down(lambda: truediv(1.0,  5.0))
     assert -1 / 5.0 == fpu.down(lambda: truediv(1.0, -5.0))
     assert -1 / 5.0 <  fpu.up  (lambda: truediv(1.0, -5.0))
Esempio n. 5
0
 def test_fourth(self):
     " 1/4 is exact."
     from operator import truediv
     assert  1 / 4.0 == fpu.down(lambda: truediv(1.0,  4.0))
     assert  1 / 4.0 == fpu.up  (lambda: truediv(1.0,  4.0))
     assert -1 / 4.0 == fpu.up  (lambda: truediv(1.0, -4.0))
     assert -1 / 4.0 == fpu.down(lambda: truediv(1.0, -4.0))
Esempio n. 6
0
	def ATANPIItv( self, a):
		aa=str(a)		
		if (aa=="nan;nan"):
			return "nan;nan"
		elif aa.count(";")==0:
			b1=down(lambda: float(a))
			b2=up(lambda: float(a))
			res1=atanpi(interval([b1,b2]))
			res2=str(interval.hull([res1]))
			aa=res2.split("[")[1]
			bb=aa.split(",")[0]
			cc=aa.split(" ")[1]
			dd=cc.split("]")[0]
			return bb +";"+dd
		else:
			a1=down(lambda: float(a.split(";")[0]))
			a2=up(lambda: float(a.split(";")[1]))
			c=interval([a1,a2])	
			res=atanpi(c)
			res1=str(interval.hull([res]))
			aa=res1.split("[")[1]
			bb=aa.split(",")[0]
			cc=aa.split(" ")[1]
			dd=cc.split("]")[0]
			return bb +";"+dd
Esempio n. 7
0
 def test_third(self):
     "Nearest rounding of 1/3 is downwards."
     from operator import truediv
     assert  1 / 3.0 == fpu.down(lambda: truediv(1.0,  3.0))
     assert  1 / 3.0 <  fpu.up  (lambda: truediv(1.0,  3.0))
     assert -1 / 3.0 == fpu.up  (lambda: truediv(1.0, -3.0))
     assert -1 / 3.0 >  fpu.down(lambda: truediv(1.0, -3.0))
Esempio n. 8
0
	def INItv( self, a, b ):
		a1=down(lambda: float(a.split(";")[0]))
		b1=down(lambda: float(b.split(";")[0]))
		a2=up(lambda: float(a.split(";")[1]))
		b2=up(lambda: float(b.split(";")[1]))
		from interval import interval
		x=interval([a1,a2])
		y=interval([b1,b2])
		if (x.__rand__(y)==x):		
			return True
		else:		
			return False	
Esempio n. 9
0
    def test_power(self):
        x = 1 / 3.0
        # The cube of one third should depend on the rounding mode
        assert fpu.down(lambda: x * x * x) < fpu.up(lambda: x * x * x)
        # But using the built-in power operator, it doesn't necessarily do it
        # fpu.down(lambda: x ** 3) < fpu.up(lambda: x ** 3))
        # So we define an integer power methods that does
        assert fpu.power_rd( x, 3) < fpu.power_ru( x, 3)
        assert fpu.power_rd(-x, 3) < fpu.power_ru(-x, 3)
        assert fpu.power_rd( x, 4) < fpu.power_ru( x, 4)
        assert fpu.power_rd(-x, 4) < fpu.power_ru(-x, 4)

        assert (fpu.down(lambda: x * x * x), fpu.up(lambda: x * x * x)) == (fpu.power_rd(x, 3), fpu.power_ru(x, 3))
Esempio n. 10
0
    def test_power(self):
        x = 1 / 3.0
        # The cube of one third should depend on the rounding mode
        assert fpu.down(lambda: x * x * x) < fpu.up(lambda: x * x * x)
        # But using the built-in power operator, it doesn't necessarily do it
        # fpu.down(lambda: x ** 3) < fpu.up(lambda: x ** 3))
        # So we define an integer power methods that does
        assert fpu.power_rd( x, 3) < fpu.power_ru( x, 3)
        assert fpu.power_rd(-x, 3) < fpu.power_ru(-x, 3)
        assert fpu.power_rd( x, 4) < fpu.power_ru( x, 4)
        assert fpu.power_rd(-x, 4) < fpu.power_ru(-x, 4)

        assert (fpu.down(lambda: x * x * x), fpu.up(lambda: x * x * x)) == (fpu.power_rd(x, 3), fpu.power_ru(x, 3))
Esempio n. 11
0
	def INTERItv( self, a, b ):
		if a.count(";")==0 and b.count(";")==0:
			a1=down(lambda: float(a))
			b1=down(lambda: float(b))
			a2=up(lambda: float(a))
			b2=up(lambda: float(b))
		elif a.count(";")==0:
			a1=down(lambda: float(a))
			a2=up(lambda: float(a))		
			b1=down(lambda: float(b.split(";")[0]))
			b2=up(lambda: float(b.split(";")[1]))
		elif b.count(";")==0:
			a1=down(lambda: float(a.split(";")[0]))
			b1=down(lambda: float(b))
			a2=up(lambda: float(a.split(";")[1]))
			b2=up(lambda: float(b))
		else:
			a1=down(lambda: float(a.split(";")[0]))
			b1=down(lambda: float(b.split(";")[0]))
			a2=up(lambda: float(a.split(";")[1]))
			b2=up(lambda: float(b.split(";")[1]))
		from interval import interval		
		p=str(interval([a1,a2]) & interval([b1,b2]))
		if (p=="interval()"):
			return "nan;nan"
		if p.count(",")==0:
			aa=p.split("[")[1]
			dd=aa.split("]")[0]
			return dd
		aa=p.split("[")[1]
		bb=aa.split(",")[0]
		cc=aa.split(" ")[1]
		dd=cc.split("]")[0]
		return bb +";"+dd
Esempio n. 12
0
    def test_power(self):
        self.assertRaises(TypeError, lambda: interval[1, 2] ** (1.3))
        self.assertEqual((-interval[1, 2]).inverse(), (-interval[1, 2]) ** -1)
        self.assertEqual(interval[0, 4], interval[-1, 2] ** 2)
        self.assertEqual(interval[-27, 8], interval[-3, 2] ** 3)
        self.assertEqual(interval[-1, 2], (interval[-1,2]**-1)**-1)
        self.assertEqual(interval([-0.38712442133802405]) ** 3, interval([-0.058016524353106828, -0.058016524353106808]))

        self.assertEqual(
            interval[fpu.down(lambda: (1/3.0)*(1/3.0)), fpu.up(lambda: (1/3.0)*(1/3.0))],
            (interval[1]/3.0) ** 2)

        self.assertEqual(
            interval[fpu.down(lambda: (1/3.0)*(1/3.0)*(1/3.0)), fpu.up(lambda: (1/3.0)*(1/3.0)*(1/3.0))],
            (interval[1]/3.0) ** 3)
Esempio n. 13
0
	def UNIONItv( self, *args ):
		from interval import interval
		somme=interval()		
		c=str(args)
		c=c.replace(",,",",")
		c=c.replace(")","")
		c=c.replace("(","")
		c=c.replace(",,",",")
		c=c.replace("'","")
		c=c.replace(" ","")
		c=c.replace("''","")
		c=c.replace(",,",",")		
		mm=c.split(",")	
		i=0					
		while (i<len(mm)): #< len(mm)					
			cour=str(mm[i])
			if cour != "None" and cour !="":
				cour=cour.replace("'","")
				cour=cour.replace(" ","")
				cour=cour.replace(",","")			
				if cour=="nan;nan":
					somme=somme				
				elif cour.count(";")==0:				
					b1=down(lambda: float(cour))
					b2=up(lambda: float(cour))
					from interval import interval, inf, imath
					somme=somme|interval([b1,b2])
				else:							
					a1=down(lambda:float(cour.split(";")[0]))
					a2=up(lambda:float(cour.split(";")[1]))
					#from interval import interval
					somme=somme|interval([a1,a2])
			somme=interval.hull([somme])
			i+=1	
		res=str(somme)		
		if res.count(",")==0:
			res1=res.split("[")[1]
			res2=res1.split("]")[0]
			return str(res2	)	
		else:		
			aa=res.split("[")[1]
			bb=aa.split(",")[0]
			cc=aa.split(" ")[1]
			dd=cc.split("]")[0]
			return bb +";"+dd
Esempio n. 14
0
    def test_power(self):
        self.assertRaises(TypeError, lambda: interval[1, 2]**(1.3))
        self.assertEqual((-interval[1, 2]).inverse(), (-interval[1, 2])**-1)
        self.assertEqual(interval[0, 4], interval[-1, 2]**2)
        self.assertEqual(interval[-27, 8], interval[-3, 2]**3)
        self.assertEqual(interval[-1, 2], (interval[-1, 2]**-1)**-1)
        self.assertEqual(
            interval([-0.38712442133802405])**3,
            interval([-0.058016524353106828, -0.058016524353106808]))

        self.assertEqual(
            interval[fpu.down(lambda: (1 / 3.0) * (1 / 3.0)),
                     fpu.up(lambda: (1 / 3.0) * (1 / 3.0))],
            (interval[1] / 3.0)**2)

        self.assertEqual(
            interval[fpu.down(lambda: (1 / 3.0) * (1 / 3.0) * (1 / 3.0)),
                     fpu.up(lambda: (1 / 3.0) * (1 / 3.0) * (1 / 3.0))],
            (interval[1] / 3.0)**3)
Esempio n. 15
0
    def test_power(self):
        self.assertRaises(TypeError, lambda: interval[1, 2] ** (1.3))
        assert (-interval[1, 2]).inverse()           == (-interval[1, 2]) ** -1
        assert interval[0, 4]                        == interval[-1, 2] ** 2
        assert interval[-27, 8]                      == interval[-3, 2] ** 3
        assert interval[-1, 2]                       == (interval[-1, 2] ** -1) ** -1
        assert interval([-0.38712442133802405]) ** 3 == interval([-0.058016524353106828, -0.058016524353106808])

        from operator import truediv
        assert (
            interval[
                fpu.down(lambda: truediv(1, 3.0) * truediv(1, 3.0)),
                fpu.up  (lambda: truediv(1, 3.0) * truediv(1, 3.0))] ==
            (interval[1] / 3.0) ** 2)

        assert (
            interval[
                fpu.down(lambda: truediv(1, 3.0) * truediv(1, 3.0) * truediv(1, 3.0)),
                fpu.up(lambda: truediv(1, 3.0) * truediv(1, 3.0) * truediv(1, 3.0))] ==
            (interval[1] / 3.0) ** 3)
Esempio n. 16
0
    def test_power(self):
        self.assertRaises(TypeError, lambda: interval[1, 2] ** (1.3))
        assert (-interval[1, 2]).inverse()           == (-interval[1, 2]) ** -1
        assert interval[0, 4]                        == interval[-1, 2] ** 2
        assert interval[-27, 8]                      == interval[-3, 2] ** 3
        assert interval[-1, 2]                       == (interval[-1, 2] ** -1) ** -1
        assert interval([-0.38712442133802405]) ** 3 == interval([-0.058016524353106828, -0.058016524353106808])

        from operator import truediv
        assert (
            interval[
                fpu.down(lambda: truediv(1, 3.0) * truediv(1, 3.0)),
                fpu.up  (lambda: truediv(1, 3.0) * truediv(1, 3.0))] ==
            (interval[1] / 3.0) ** 2)

        assert (
            interval[
                fpu.down(lambda: truediv(1, 3.0) * truediv(1, 3.0) * truediv(1, 3.0)),
                fpu.up(lambda: truediv(1, 3.0) * truediv(1, 3.0) * truediv(1, 3.0))] ==
            (interval[1] / 3.0) ** 3)
Esempio n. 17
0
	def ABSItv( self, a):
		aa=str(a)		
		if (aa=="nan;nan"):
			return "nan;nan"
		elif aa.count(";")==0:	
			a1=down(lambda: float(aa))
			a2=up(lambda: float(aa))
		else:			
			a1=down(lambda: float(a.split(";")[0]))
			a2=up(lambda: float(a.split(";")[1]))
		c=interval([a1,a2])	
		res=c.__abs__()
		res1=str(interval.hull([res]))
		if res1.count(" ")==0:
			aa=res1.split("[")[1]
			dd=aa.split("]")[0]
			return dd +";"+dd
		else:
			aa=res1.split("[")[1]
			bb=aa.split(",")[0]
			cc=aa.split(" ")[1]
			dd=cc.split("]")[0]
			return bb +";"+dd
Esempio n. 18
0
	def COMPItv( self, a, b ):
		if a==b:
			return "3"		
		elif a.count(";")==0 and b.count(";")==0:
			a1=down(lambda: float(a))
			b1=down(lambda: float(b))
			a2=up(lambda: float(a))
			b2=up(lambda: float(b))
		elif a.count(";")==0:
			a1=down(lambda: float(a))
			a2=up(lambda: float(a))		
			b1=down(lambda: float(b.split(";")[0]))
			b2=up(lambda: float(b.split(";")[1]))
		elif b.count(";")==0:
			a1=down(lambda: float(a.split(";")[0]))
			b1=down(lambda: float(b))
			a2=up(lambda: float(a.split(";")[1]))
			b2=up(lambda: float(b))
		else:
			a1=down(lambda: float(a.split(";")[0]))
			b1=down(lambda: float(b.split(";")[0]))
			a2=up(lambda: float(a.split(";")[1]))
			b2=up(lambda: float(b.split(";")[1]))
		from interval import interval

		if a1>b2:
			return "1"
		elif a1>=b1 and a1<=b2 and a2>b2:
			return "2"
		elif a1>=b1 and a1<=b2 and a2<=b2:
			return "5"
		elif a==b:
			return "3"
		elif b1>a2:
			return "4"
		elif b1>=a1 and b1<=a2 and b2>a2:
			return "5"
		elif b1>=a1 and b1<=a2 and b2<=a2:
			return "2"
Esempio n. 19
0
	def DIVItv( self, a, b ):
		if a=="nan;nan" or b=="nan;nan":
			return "nan;nan"
		else:		
			if a.count(";")==0 and b.count(";")==0:
				a1=down(lambda: float(a))
				b1=down(lambda: float(b))
				a2=up(lambda: float(a))
				b2=up(lambda: float(b))
			elif a.count(";")==0:
				a1=down(lambda: float(a))
				a2=up(lambda: float(a))		
				b1=down(lambda: float(b.split(";")[0]))
				b2=up(lambda: float(b.split(";")[1]))
			elif b.count(";")==0:
				a1=down(lambda: float(a.split(";")[0]))
				b1=down(lambda: float(b))
				a2=up(lambda: float(a.split(";")[1]))
				b2=up(lambda: float(b))
			else:
				a1=down(lambda: float(a.split(";")[0]))
				b1=down(lambda: float(b.split(";")[0]))
				a2=up(lambda: float(a.split(";")[1]))
				b2=up(lambda: float(b.split(";")[1]))
		from interval import interval
		inv=interval([b1,b2])
		invcomplet=inv.inverse()		
		res=interval([a1,a2])*invcomplet
		res1=str(interval.hull([res]))
		if res1.count(" ")==0:
			aa=res1.split("[")[1]
			dd=aa.split("]")[0]
			return dd +";"+dd
		else:
			aa=res1.split("[")[1]
			bb=aa.split(",")[0]
			cc=aa.split(" ")[1]
			dd=cc.split("]")[0]
			return bb +";"+dd
Esempio n. 20
0
	def DIFFItv( self, a, b ):
		if a=="nan;nan" or b=="nan;nan":
			return "nan;nan"
		else:		
			if a.count(";")==0 and b.count(";")==0:
				a1=down(lambda: float(a))
				b1=down(lambda: float(b))
				a2=up(lambda: float(a))
				b2=up(lambda: float(b))
			elif a.count(";")==0:
				a1=down(lambda: float(a))
				a2=up(lambda: float(a))		
				b1=down(lambda: float(b.split(";")[0]))
				b2=up(lambda: float(b.split(";")[1]))
			elif b.count(";")==0:
				a1=down(lambda: float(a.split(";")[0]))
				b1=down(lambda: float(b))
				a2=up(lambda: float(a.split(";")[1]))
				b2=up(lambda: float(b))
			else:
				a1=down(lambda: float(a.split(";")[0]))
				b1=down(lambda: float(b.split(";")[0]))
				a2=up(lambda: float(a.split(";")[1]))
				b2=up(lambda: float(b.split(";")[1]))
		from interval import interval
		res=str(interval([a1,a2])-interval([b1,b2]))
		if res.count(" ")==0:
			aa=res.split("[")[1]
			dd=aa.split("]")[0]
			return dd +";"+dd
		else:		
			aa=res.split("[")[1]
			bb=aa.split(",")[0]
			cc=aa.split(" ")[1]
			dd=cc.split("]")[0]
			return bb +";"+dd
Esempio n. 21
0
 def test_third(self):
     "Nearest rounding of 1/3 is downwards."
     self.assertEqual(1/3.0, fpu.down(lambda: 1.0 / 3.0))
     self.assertTrue(1/3.0 < fpu.up(lambda: 1.0 / 3.0))
     self.assertEqual(-1/3.0, fpu.up(lambda: 1.0 / -3.0))
     self.assertTrue(-1/3.0 > fpu.down(lambda: 1.0 / -3.0))
Esempio n. 22
0
 def test_fourth(self):
     " 1/4 is exact."
     self.assertEqual(1/4.0, fpu.down(lambda: 1.0 / 4.0))
     self.assertEqual(1/4.0, fpu.up(lambda: 1.0 / 4.0))
     self.assertEqual(-1/4.0, fpu.up(lambda: 1.0 / -4.0))
     self.assertEqual(-1/4.0, fpu.down(lambda: 1.0 / -4.0))
Esempio n. 23
0
 def test_third(self):
     "Nearest rounding of 1/3 is downwards."
     self.assertEqual(1 / 3.0, fpu.down(lambda: 1.0 / 3.0))
     self.assertTrue(1 / 3.0 < fpu.up(lambda: 1.0 / 3.0))
     self.assertEqual(-1 / 3.0, fpu.up(lambda: 1.0 / -3.0))
     self.assertTrue(-1 / 3.0 > fpu.down(lambda: 1.0 / -3.0))
Esempio n. 24
0
 def test_fifth(self):
     "Nearest rounding of 1/5 is upwards."
     self.assertEqual(1 / 5.0, fpu.up(lambda: 1.0 / 5.0))
     self.assertTrue(1 / 5.0 > fpu.down(lambda: 1.0 / 5.0))
     self.assertEqual(-1 / 5.0, fpu.down(lambda: 1.0 / -5.0))
     self.assertTrue(-1 / 5.0 < fpu.up(lambda: 1.0 / -5.0))
Esempio n. 25
0
 def test_fourth(self):
     " 1/4 is exact."
     self.assertEqual(1 / 4.0, fpu.down(lambda: 1.0 / 4.0))
     self.assertEqual(1 / 4.0, fpu.up(lambda: 1.0 / 4.0))
     self.assertEqual(-1 / 4.0, fpu.up(lambda: 1.0 / -4.0))
     self.assertEqual(-1 / 4.0, fpu.down(lambda: 1.0 / -4.0))
Esempio n. 26
0
 def test_fifth(self):
     "Nearest rounding of 1/5 is upwards."
     self.assertEqual(1/5.0, fpu.up(lambda: 1.0 / 5.0))
     self.assertTrue(1/5.0 > fpu.down(lambda: 1.0 / 5.0))
     self.assertEqual(-1/5.0, fpu.down(lambda: 1.0 / -5.0))
     self.assertTrue(-1/5.0 < fpu.up(lambda: 1.0 / -5.0))