import math


def geometric(a, r, index_range=None, seq_range=None):
    """
        Generates the geometric sequence with a first term of 'a' and a common
        ratio of 'r':

            a, ar, ar^2, ...
    """
    def t(n):
        return a * r ** (n - 1)

    if index_range:
        for n in index_range:
            yield t(n)
        return
    elif seq_range:
        u = math.ceil(1 + math.log(seq_range.start / a, r))
        v = math.floor(1 + math.log((seq_range.stop - 1) / a, r))
        for n in range(u, v + 1):
            yield t(n)
        return
    k = 0
    while True:
        yield t(k)
        k += 1