human
3. Dependency Tracking
It would be very cool to have a bunch of calculations where afterwards you can tell which values depend on which other values."
Please write code following the instructions in jupyter notebook style.

Write me a code to 3?
assistant
#Here is code to 3.

%%cython
import numbers
from weakref import WeakSet  # WeakSet, so intermediates get deleted

cdef class Tracked:
    cdef object __weakref__
    cdef double value
    cdef public str name
    cdef public object depends_on  # This value depends on others
    def __init__(self, double value, name=None):
        self.value = value
        self.name = name
        self.depends_on = WeakSet() 
    
    @staticmethod
    def handle_type(x):
        if isinstance(x, numbers.Number): 
            return Tracked(x)
        elif isinstance(x, Tracked):
            return x
        else:
            raise Exception('Bad Types')
        
    def __mul__(x, y):
        cdef Tracked px = <Tracked>Tracked.handle_type(x)
        cdef Tracked py = <Tracked>Tracked.handle_type(y)
        
        cdef Tracked result = Tracked(0)
        
        result.value = px.value * py.value
        result.name = '(calculated)'.format(px.name, py.name)
        
        result.depends_on.add(px) 
        result.depends_on.add(py)
        result.depends_on |= px.depends_on | py.depends_on
        
        return result
            
    def __repr__(self): 
        depon = [' '*8+x.name for x in self.depends_on]
        s = '{:.6g} name="{}"'.format(self.value, self.name)
        if depon:
            s += '\n    I depend on: \n{}'.format('\n'.join(depon))
        return s

ww = Tracked(0.2, name='wall width, metres, measured 5 May 1995 by CJRH')
print(ww)

wh = Tracked(2.0, name='wall height, metres, measured 12 Jan 1998 by XYZ')
print(wh)

wl = Tracked(5.0, name='wall length, metres, ESTIMATE sometime by ABC')
print(wl)

def volume(width, height, length):
    return width * height * length

print(volume(ww, wh, wl))

def mass(volume, density):
    return volume * density


d = Tracked(2000.0, 'brick (kg/m3), https://en.wikipedia.org/wiki/Brick')
print(
    mass(volume(ww, wh, wl), d)
)