Computing vector-Jacobian and Jacobian-vector product efficiently

Thank you @Tidan
Can you also tell me the mathematical background behind calculating the (vjp_val - jvp_val).norm(1) as loss. Somehow, I am not able to get my head around this

An external link etc would also suffice