Skip to content
DeepForgeby svx
All problems
MediumCalculusca-204

Forward-Mode AD Chain

Problem

Propagate dual numbers through the composite h(g(f(x))) with f(x) = x^2, g(u) = u + 1, and h(v) = v^3.

By the chain rule the derivative is 3 * (x^2 + 1)^2 * 2x. Return the derivative at x.

Hint

Forward mode carries the derivative along with each intermediate value.

Test cases

case 1
in: [1]
expected: 24
case 2
in: [0]
expected: 0
case 3
in: [2]
expected: 300
case 4
in: [-1]
expected: -24
Starter codePython
def forward_ad_chain(x):
    # Your code here
    pass

4 test cases · run your code against them in the editor