BendMlAutograd.nbwd: def of bend-ml-autograd@0.1.1.0 Import: import bend-ml-autograd@0.1.1.0/main.bend as BendMlAutograd Lines 53-65 of bend-ml-autograd@0.1.1.0/main.bend: https://jend.leeeet.dev/read.txt?path=bend-ml-autograd@0.1.1.0/main.bend&start_line=53&end_line=65 import Base # REVERSE-mode derivative: g is the gradient arriving from the output; each node passes on # g (sum) or g * value-of-the-other-factor (product) to its children and adds up what # arrives at NX. def nbwd(e: NE, +x: Nat, +g: Nat) -> Nat: match e: case NCst{n}: 0n case NX{}: g case NAdd{a, b}: Nat.add(nbwd(a, x, g), nbwd(b, x, g)) case NMul{+a, +b}: Nat.add(nbwd(a, x, Nat.mul(g, nval(b, x))), nbwd(b, x, Nat.mul(g, nval(a, x)))) Uses (5): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.mul https://jend.leeeet.dev/definition.txt?path=bend-ml-autograd@0.1.1.0/main.bend&name=NE https://jend.leeeet.dev/definition.txt?path=bend-ml-autograd@0.1.1.0/main.bend&name=nval