The Pythagorean theorem and Leibniz’s rule
The Pythagorean theorem
In a right triangle, the square of the hypotenuse equals the sum of the squares of the other two sides. If the legs have lengths a and b, and the hypotenuse has length c, then
Take the positive square root to find the hypotenuse. For example, legs of length 3 and 4 give a hypotenuse of length 5.
Computing the hypotenuse in C
The standard library function hypot(a, b) computes the square root of the sum of the squares without explicitly squaring either input.
#include <math.h>
#include <stdio.h>
int main(void)
{
const double a = 3.0;
const double b = 4.0;
const double c = hypot(a, b);
printf("Hypotenuse: %.2f\n", c);
return 0;
}
Save the example as pythagoras.c, compile it with cc pythagoras.c -o pythagoras -lm, and run ./pythagoras. It prints Hypotenuse: 5.00.
Leibniz’s rule (the product rule)
For two differentiable functions f and g, the derivative of their product is the derivative of each factor multiplied by the other factor, with the two terms added together.
For example, differentiating gives .