Skip to content
DeepForgeby svx
All problems
HardCalculusca-050

Differentiability Check

Problem

Check whether the piecewise function f(x) = P(x) for x < a and f(x) = Q(x) for x >= a is differentiable at a, where P and Q are polynomials given by coefficient lists.

Estimate the left derivative with (f(a) - f(a - h)) / h and the right derivative with (f(a + h) - f(a)) / h using h = 1e-6. Return True when the two one-sided derivatives differ by less than tol (default 1e-4).

Hint

The function must be continuous and the left and right slopes must agree at a.

Test cases

case 1
in: [[0,0,1],[-1,2],1]
expected: true
case 2
in: [[0,0,1],[0,1,0],0]
expected: false
case 3
in: [[1],[2],0]
expected: false
case 4
in: [[0,3],[0,3],2]
expected: true
case 5
in: [[0,0,0,1],[0,0,1,0],0]
expected: true
Starter codePython
def is_differentiable(p_coeffs, q_coeffs, a, tol=1e-4):
    # Your code here
    pass

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