add tail recursion

Signed-off-by: Sébastien Boisvert <sebastien.boisvert.3@ulaval.ca>