human
I am working on the file "Learning_Cython_video/Chapter06/opoverload/opoverload.ipynb".
The first task is:
2. Interval Arithmetic (found online)
In interval arithmetic, each number is really an interval with an upper and lower bound.  When calculations with such numbers are performed, we always make sure the answer retains the correct upper and lower bound.
For example, if 
$$
x = \left[ x_{min} \;\;, x_{max} \;\.
\right]
$$
And similar for $y$, then
$$
x + y = [ x_{min} \;\.
+ y_{min} \;\;, x_{max} \;\.
+ y_{max} \;\;]
$$
Can you write Python code for it?
assistant
#Here is the Python code you requested.

%%cython
cimport cython

@cython.freelist(10)
cdef class Interval:
    cdef double vmin, vmax
    def __init__(self, double vmin, double vmax):
        self.vmin = vmin
        self.vmax = vmax
        
    def __add__(x, y):
        if not isinstance(x, Interval) or not isinstance(y, Interval):
            raise Exception('Bad Types')
    
        cdef Interval px = <Interval>x
        cdef Interval py = <Interval>y
        
        cdef Interval result = Interval(0, 0)
        result.vmin = px.vmin + py.vmin
        result.vmax = px.vmax + py.vmax
        return result
    
    def __repr__(self):
        return '[{:.6g}, {:.6g}]'.format(self.vmin, self.vmax)

x = Interval(21.0, 22.0)
print(x)

y = Interval(47.0, 48.0)
print(y)

def my_calculation(a, b):
    return a + b

print(my_calculation(x, y))
print(my_calculation(10, 20))