SetDirectory["c:\\myDirectory"]

<< discrete1DHomotopyOperator.m

Print["START OF DEMO 2"];

expression = -u[1][n,t]*u[1][n+1,t]*u[2][n,t] - u[2][n,t]^2 + 
              u[1][n+1,t]*u[1][n+2,t]*u[2][n+1,t] + u[2][n+1,t]^2 +
              u[1][n+3,t]*u[2][n+2,t] - u[1][n+1,t]*u[2][n,t]

Print["Expression to be written as a total difference: "];

Print[expression];

myfn = u[1][n,t]*u[1][n+1,t]*u[2][n,t] + u[2][n,t]^2 +
       u[1][n+2,t]*u[2][n+1,t] + u[1][n+1,t]*u[2][n,t]

myfnplusone = myfn /. {n -> n+1}

Print["Mathematica has no function to do this!"];

Print["Computed by hand, myfn: "]

Print[myfn];

testmyfn = Factor[expression - ( myfnplusone -myfn ) ];

Print["expression - ( myfnplusone - myfn ) should be zero... test myfn:"];

Print[testmyfn];

(* Application of Homotopy Operator *)

homfn = discreteHomotopyOperator[expression,u,2]

homfnplusone = homfn /. {n -> n+1}

testhomfn = Factor[expression - ( homfnplusone - homfn ) ];

Print["expression - ( homfnplusone - homfn ) should be zero... (test homfn):"];

Print[testhomfn];

testdiff = Factor[myfn-homfn];

Print["Difference of myfn and homfn should be zero... (testdiff):"];

Print[testdiff];

Print["END OF DEMO 2"]