The Chain Rule

~12 mincode completion

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 .

Examples

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

Input
chain_rule_derivative(3, 1, 2)
Output
42

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

Input
chain_rule_derivative(2, -4, 2)
Output
0

A negative inner slope flips the sign

Input
chain_rule_derivative(-1, 5, 1)
Output
-8

Hints

Hint 1

Work directly with the arguments a, b, x and return the result rather than printing it.

Hint 2

Watch for this: forgets to multiply by the inner derivative.

Requirements

  • a: inner slope

  • b: inner offset

  • x: the point to differentiate at

  • Return float: 2(ax + b) * a

Constraints

  • Standard library only, no imports required

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~12 min

4 employers weight this skill

4 quant funds. Top match scores 93.

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…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.