def total_of_regular_investment(reg_invest_value, rate, n_periods):
    """
    A special case of total_of_series_of_invest, when the investements are constant and the rate
    remains constant. Uses math formula instead of recursion. Not super useful except may be to
    keep track of the formula for other usage, may be where performance would matter (unlikely)

    >>> total_of_regular_investment(10, 0, 5)
    50

    The investment is applied at the END of the period and thus does not benefit from its growth

    >>> total_of_regular_investment(10, 0.01, 1)
    10.0
    >>> total_of_regular_investment(10, 0.01, 2)
    20.099999999999987
    >>> total_of_regular_investment(10, 0.01, 5)
    51.0100501000001
    """

    if rate == 0:
        return reg_invest_value * n_periods
    else:
        factor = 1 + rate
        return reg_invest_value + reg_invest_value * (factor - factor ** n_periods) / (
            1 - factor
        )