Have a go at it. The editor and the docs panel are open, and your code is saved as you type. Running it needs a free account — you’ll come back to exactly what you wrote.

The Chain Rule

~12 mincode completion

The chain rule is the single most important fact in this curriculum. Backpropagation is nothing else.

If , then

In words: the outer derivative evaluated at the inner value, times the inner derivative. Rates multiply along a chain. If moves 3× as fast as , and moves 2× as fast as , then moves 6× as fast as .

Take at :

inner  u = 3x + 1 = 7          du/dx = 3
outer  y = u^2                 dy/du = 2u = 14
                               dy/dx = 14 * 3 = 42

That two-step structure — evaluate forward, then multiply derivatives backward — is exactly the forward and backward pass of a neural network. A three-layer network is this rule applied three times.

Your task:

Implement chain_rule_derivative(a, b, x) for

returning at x, computed as outer times inner rather than by expanding the square first. The answer is .

Example Tests

(3x + 1)^2 at x = 2: inner is 7, outer derivative 14, times 3

Input: {"a":3,"b":1,"x":2}

Expected: 42

At the point where the inner function is zero the whole derivative vanishes

Input: {"a":2,"b":-4,"x":2}

Expected: 0

A negative inner slope flips the sign

Input: {"a":-1,"b":5,"x":1}

Expected: -8

Python
def chain_rule_derivative(a, b, x):
    """
    dy/dx for y = (a*x + b)^2, via the chain rule.

    Args:
        a: inner slope
        b: inner offset
        x: the point to differentiate at

    Returns:
        float: 2*(a*x + b) * a
    """
    # YOUR CODE HERE
    pass
Loading docs…