nc_setup({k,n,nn,kk},{nn*n-n*nn=nn,kk*k-k*kk=kk},left);



 p1 := (n-k+1)*nn - (n+1);


p1 :=  - k*nn + n*nn - n + nn - 1

 p2 := (k+1)*kk -(n-k);


p2 := k*kk + k - n + kk

 l_g:=nc_groebner ({p1,p2});


l_g := {k*nn - n*nn + n - nn + 1,

        k*kk + k - n + kk,

        n*nn*kk - n*kk - n + nn*kk - kk - 1}


 nc_preduce(p1+p2,l_g);


0


 nc_divide  (k*p1+p2,p1);


{k,k*kk + k - n + kk}

 nc_divide  (k*p1+p2,2*p1);


{k,2*k*kk + 2*k - 2*n + 2*kk}

 nc_divide  (2*k*k*p1 + k*p1 + p2,2*p1);


    2
{2*k  + k,

 2*k*kk + 2*k - 2*n + 2*kk}

 
 nc_factorize (p1*p2);


{ - k*nn + n*nn - n + nn - 1,

 k*kk + k - n + kk}


nc_setup({k,n,nn,kk},{nn*n-n*nn=nn,kk*k-k*kk=kk},right);


nc_factorize (p1*p2);


{ - k*nn + n*nn - n + nn - 1,

 k*kk + k - n + kk}


% applications to shift operators

nc_setup({n,nn},{nn*n-n*nn=1},left);


n*nn;


n*nn

nc_factorize(ws);


{n,nn}

nc_setup({n,nn},{nn*n-n*nn=1},right);


n*nn;


n*nn

nc_factorize(ws);


{n,nn}

nc_setup({nn,n},{nn*n-n*nn=1},right);


n*nn;


nn*n - 1

nc_factorize(ws);


{n,nn}

nc_setup({nn,n},{nn*n-n*nn=1},left);


n*nn;


nn*n - 1

nc_factorize(ws);


{n,nn}


% Applications to partial differential equations

nc_setup({x,dx},{dx*x-x*dx=1});



p:= 2*dx^2 + x* dx^3 + 3*x*dx + x^2*dx^2 + 14 + 7*x*dx;


      2   2       3                 2
p := x *dx  + x*dx  + 10*x*dx + 2*dx  + 14

nc_factorize p;


                   2
{x*dx + 2,x*dx + dx  + 7}

right_factor(p,1);


 2   2       3                 2
x *dx  + x*dx  + 10*x*dx + 2*dx  + 14
 % no factor of degr 1
right_factor(p,2);


         2
x*dx + dx  + 7

left_factor(p,2);


x*dx + 2


nc_setup({x,dx},{dx*x-x*dx=1});



q := x**2*dx**2 + 2*x**2*dx + x*dx**3 + 2*x*dx**2 
    + 8*x*dx + 16*x + 2*dx**2 + 4*dx$



nc_factorize q;


          2
{x*dx + dx  + 7,

 x,

 dx + 2}

right_factor(q,1);


dx + 2

right_factor(q,1,{x});


 2   2      2          3         2                       2
x *dx  + 2*x *dx + x*dx  + 2*x*dx  + 8*x*dx + 16*x + 2*dx  + 4*dx
  % no such right factor
right_factor(q,1,{dx});


dx + 2


% looking for factor with degree bound for an individual variable

q := x**6*dx + x**5*dx**2 + 12*x**5 + 10*x**4*dx + 20*x**3 
+ x**2*dx**3 - x**2*dx**2 + x*dx**4 - x*dx**3 + 8*x*dx**2 
- 8*x*dx + 2*dx**3 - 2*dx**2$



right_factor(q,dx);


 6       5   2       5       4          3    2   3    2   2       4       3
x *dx + x *dx  + 12*x  + 10*x *dx + 20*x  + x *dx  - x *dx  + x*dx  - x*dx

         2                3       2
 + 8*x*dx  - 8*x*dx + 2*dx  - 2*dx

right_factor(q,dx^2);


 4     2
x  + dx  - dx


% some coefficient sports
nc_setup({nn,n},{nn*n-n*nn=1},left);


q:=(n*nn)^2;


       2  2
q := nn *n  - 3*nn*n + 1

nc_factorize q;


{n,

 nn,

 n,

 nn}

nc_preduce(q,{c1+c2*n + c3*nn + c4*n*nn});


   2       2                        2        2          2      2
(c3 *c4)*nn  + (2*c1*c3*c4 - 2*c2*c3  + c3*c4 )*nn + (c2 *c4)*n

                     2           2         2
 + (2*c1*c2*c4 - 2*c2 *c3 - c2*c4 )*n + (c1 *c4 - 2*c1*c2*c3 + c2*c3*c4)

nc_divide(q,n);


   2
{nn *n - 3*nn,1}


nc_cleanup;



end;

Tested on x86_64-pc-windows CSL
Time (counter 1): 641 ms  plus GC time: 15 ms

End of Lisp run after 0.64+0.07 seconds
real 0.93
user 0.00
sys 0.06
