init repo

This commit is contained in:
Jan-Niclas Loosen
2025-05-07 10:48:37 +02:00
parent 17875d57cb
commit 719f5816e9
11 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
class REAL: # nested.py
def __init__(self, l, u):
self.lower = l
self.upper = u
def asString(self, n):
l = self.lower(n)
u = self.upper(n)
return ("[ " + l.numerator.digits() + "/" + l.denominator.digits() +
", " + u.numerator.digits() + "/" + u.denominator.digits() + "]")
def __add__(self, y):
return REAL_add(self, y)
class REAL_add(REAL):
def __init__(self, x, y):
self.x = x
self.y = y
def lower(self, n):
return self.x.lower(n) + self.y.lower(n)
def upper(self, n):
return self.x.upper(n) + self.y.upper(n)

View File

@@ -0,0 +1,17 @@
from interval import REAL
from gmpy2 import mpq # rationale Zahlen
def lower_one(n):
return mpq(1,1)-mpq(1,n)
def upper_one(n):
return mpq(1,1)+mpq(1,n)
x = REAL(lower_one,upper_one); y = x + x
print ("x: "+x.asString(10))
print ("y: "+y.asString(10))
print ("x: "+x.asString(10000))
print ("y: "+y.asString(10000))