with(LinearAlgebra): applygauge := proc(trec,trel) # input rec in terms of _u and _n and relation in form v(_n)=a1(_n)_u(_n+1) + a0(_n)_u(_n) local rel, rec, a, b, s, ShouldBeZero, temp1, temp2, temp3, d; rel := eval(trel, {_c[1]=1, _c[2]=1}); rec := trec; s := v(_n+2) + a(_n)*v(_n+1) + b(_n)*v(_n); ShouldBeZero := eval(s, {rel, subs(_n=_n+1, rel), subs(_n=_n+2, rel)}); temp1 := solve(rec, _u(_n+2)); temp2 := solve( eval(rec, _n=_n+1), _u(_n+3)); temp3 := subs(_u(_n+3)=temp2, _u(_n+2) = temp1, ShouldBeZero); temp3 := collect(temp3, {_u(_n), _u(_n+1)}, factor); ShouldBeZero := { coeffs(temp3, {_u(_n), _u(_n+1)}) }; d := solve(ShouldBeZero, {a(_n), b(_n)}); subs(d, s); end: