SetDirectory["c:\\myDirectory"]

<< discrete1DHomotopyOperator.m

Expression to be written as a total difference:

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]

Mathematica has no function to do this!

Computed by hand, myfn:

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}

expression - ( myfnplusone - myfn ) should be zero... test myfn:

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

Application of Homotopy Operator

Format: 
     discreteHomotopyOperator[expression, head of dependent variables, number of dependent variables]

Note: t is a parameter in this computation. t is time in my application:computation of
      densities and fluxes of differential-difference equations

homfn = discreteHomotopyOperator[expression,u,2]

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

expression - ( homfnplusone - homfn ) should be zero... (test homfn)

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

Difference of myfn and homfn should be zero... (testdiff):

testdiff = Factor[myfn-homfn]