Source: https://www-fourier.ujf-grenoble.fr/~parisse/giac/algo.pdf