Calculate pi using the Gregory-Leibniz algorithm