def pa(i, n, g=None):
    """If the geometric gradient rate is supplied, calculates the geometric gradient to present worth conversion factor.
       Otherwise, calculates the series present worth factor.

    :param i: The interest rate.
    :param n: The number of periods.
    :param g: The optional geometric gradient rate.
    :return: The calculated factor.
    """
    if g is None:
        return ((1 + i) ** n - 1) / (i * (1 + i) ** n)
    else:
        return pa((1 + i) / (1 + g) - 1, n) / (1 + g)