from util import *


@apply
def apply(given, n=None, a=0):
    a = sympify(a)
    Zn1, rhs = given.of(Equal)
    r, Zn = rhs.of(Mul)
    if Zn._subs(n, n + 1) != Zn1:
        r, Zn = Zn, r

    assert Zn._subs(n, n + 1) == Zn1
    Za = Zn._subs(n, a)
    if n is None:
        n, *_ = Zn.free_symbols - r.free_symbols

    return Equal(Zn, Za * r ** (n - a))


@prove
def prove(Eq):
    from axiom import algebra
    n = Symbol(integer=True, nonnegative=True, given=False)
    r = Symbol(complex=True)
    f = Symbol(shape=(oo,), complex=True)

    Eq << apply(Equal(f[n + 1], r * f[n]), n=n)

    Eq << Eq[1].subs(n, 0)

    Eq.induct = Eq[1].subs(n, n + 1)

    Eq << Eq[1] * r

    Eq << Eq[-1].this.rhs.powsimp()

    Eq << algebra.eq.eq.imply.eq.transit.apply(Eq[0], Eq[-1])

    Eq << Infer(Eq[1], Eq.induct, plausible=True)

    Eq << algebra.infer.imply.eq.induct.apply(Eq[-1], n=n)


if __name__ == '__main__':
    run()

# created on 2019-04-05
