<<  NCGB.m;
<<  NCXMakeRelations.m;

SetNonCommutative[A, B, Pinv[A], Pinv[B], Pinv[A + B], 
        Pinv[A ** B] ];

relations  =  
        NCMakeRelations[{Pinv, A}]  //.  
          Tp  ->  tp;

ClearMonomialOrderAll[];
SetMonomialOrder[ {A, tp[A], Pinv[A], Pinv[tp[A]], 
          tp[Pinv[A]] } ];
PrintMonomialOrder[];

NCProcess[ relations,  6,  0,  0,  0,  "PinvA",  
        SBByCat  -> False,  RR ->  False,  
        NCCV  ->  False ];

relations  =  
        NCMakeRelations[{Pinv, A, B, A + B}]  //.  
          Tp  ->  tp;

ClearMonomialOrderAll[];
SetMonomialOrder[ {A, B, tp[A], tp[B], Pinv[A], Pinv[B], 
          Pinv[tp[A]], Pinv[tp[B]], tp[Pinv[A]], tp[Pinv[B]], Pinv[A + B], 
          Pinv[tp[A + B]], 
          tp[Pinv[A + B]] } ];
PrintMonomialOrder[];

NCProcess[ relations,  6,  0,  0,  0,  "PinvAPlusB",  
        SBByCat  -> False,  RR ->  False,  
        NCCV  ->  False ];

relations  =  
        NCMakeRelations[{Pinv, A, B, A ** B}]  //.  
          Tp  ->  tp;

ClearMonomialOrderAll[];
SetMonomialOrder[ {A, B, tp[A], tp[B], Pinv[A], Pinv[B], 
          Pinv[tp[A]], Pinv[tp[B]], tp[Pinv[A]], 
          tp[Pinv[B]] }, {Pinv[A ** B], Pinv[tp[A ** B]], 
          tp[Pinv[A ** B]] } ];
PrintMonomialOrder[];

NCProcess[ relations,  3,  0,  0,  0,  "PinvAB-3iters",  
        SBByCat  -> False,  RR ->  False,  
        NCCV  ->  False ];
NCProcess[ relations,  4,  0,  0,  0,  "PinvAB-4iters",  
        SBByCat  -> False,  RR ->  False,  
        NCCV  ->  False ];
NCProcess[ relations,  5,  0,  0,  0,  "PinvAB-5iters",  
        SBByCat  -> False,  RR ->  False,  
        NCCV  ->  
          False ];

(* Run for Pinv[
          A ** Pinv[A] + 
            B ** Pinv[
                B]] *) 

relations  =  NCMakeRelations[{Pinv, A, B, A ** Pinv[A] + B ** Pinv[B]}]  //.  
          Tp  ->  tp;

ClearMonomialOrderAll[];
SetMonomialOrder[ {A, B, tp[A], tp[B], Pinv[A], Pinv[B], 
          Pinv[tp[A]], Pinv[tp[B]], tp[Pinv[A]], tp[Pinv[B]], 
          Pinv[A ** Pinv[A] + B ** Pinv[B]], 
          Pinv[tp[A ** Pinv[A] + B ** Pinv[B]]], 
          tp[Pinv[A ** Pinv[A] + 
                B ** Pinv[B]]] } ];
PrintMonomialOrder[];

NCProcess[ relations,  6,  0,  0,  
        0,  "APinvAPlusBPinvB",  SBByCat  -> False,  
        RR ->  False,  
        NCCV  ->  
          False ];

NCMakeGB[ relations, 10 ];
If[ FinishedComputingBasisQ[]  ==  1,  
        Print[ "Finite Basis." ],  
        Print[ "NOT Finite Basis." ] ];

relations  =  
        NCMakeRelations[{Pinv, A, B, A ** Pinv[A] + Pinv[B] ** B}]  //.  
          Tp  ->  tp;

ClearMonomialOrderAll[];
SetMonomialOrder[ {A, B, tp[A], tp[B], Pinv[A], Pinv[B], 
          Pinv[tp[A]], Pinv[tp[B]], tp[Pinv[A]], tp[Pinv[B]], 
          Pinv[A ** Pinv[A] + Pinv[B] ** B], 
          Pinv[tp[A ** Pinv[A] + Pinv[B] ** B]], 
          tp[Pinv[A ** Pinv[A] + 
                Pinv[B] ** B]] } ];
PrintMonomialOrder[];

NCProcess[ relations,  6,  0,  0,  
        0,  "APinvAPlusPinvBB",  SBByCat  -> False,  
        RR ->  False,  
        NCCV  ->  
          False ];

NCMakeGB[ relations, 10 ];
If[ FinishedComputingBasisQ[]  ==  1,  
        Print[ "Finite Basis." ],  
        Print[ "NOT Finite Basis." ] ];

(* Run for Pinv[(1 - Pinv[B] ** B) ** A ** 
            Pinv[A]] *) 

relations  =  NCMakeRelations[{Pinv, A, B, 
              A ** Pinv[A] - Pinv[B] ** B ** A ** Pinv[A]}]  //.  
          Tp  ->  tp;

ClearMonomialOrderAll[];
SetMonomialOrder[ {A, B, tp[A], tp[B], Pinv[A], Pinv[B], 
          Pinv[tp[A]], Pinv[tp[B]], tp[Pinv[A]], tp[Pinv[B]], 
          Pinv[A ** Pinv[A] - Pinv[B] ** B ** A ** Pinv[A]], 
          Pinv[tp[A ** Pinv[A] - Pinv[B] ** B ** A ** Pinv[A]]], 
          tp[Pinv[A ** Pinv[A] - 
                Pinv[B] ** B ** A ** 
                  Pinv[A]]] } ];
PrintMonomialOrder[];

NCProcess[ relations,  6,  0,  0,  
        0,  "APinvAMinusPinvBBAPinvA",  SBByCat  -> False,  
        RR ->  False,  
        NCCV  ->  
          False ];

NCMakeGB[ relations, 10 ];
If[ FinishedComputingBasisQ[]  ==  1,  
        Print[ "Finite Basis." ],  
        Print[ "NOT Finite Basis." ] ];

relations  =  
        NCMakeRelations[{Pinv, A, B, A ** Pinv[A] + Pinv[B] ** B, 
              A ** Pinv[A] - Pinv[B] ** B ** A ** Pinv[A]}]  //.  
          Tp  ->  tp;

ClearMonomialOrderAll[];
SetMonomialOrder[ {A, B, tp[A], tp[B], Pinv[A], Pinv[B], 
          Pinv[tp[A]], Pinv[tp[B]], tp[Pinv[A]], tp[Pinv[B]], 
          Pinv[A ** Pinv[A] + Pinv[B] ** B], 
          Pinv[tp[A ** Pinv[A] + Pinv[B] ** B]], 
          tp[Pinv[A ** Pinv[A] + Pinv[B] ** B]], 
Pinv[
            A ** Pinv[A] - Pinv[B] ** B ** A ** Pinv[A]], 
          Pinv[tp[A ** Pinv[A] - Pinv[B] ** B ** A ** Pinv[A]]], 
          tp[Pinv[A ** Pinv[A] - 
                Pinv[B] ** B ** A ** 
                  Pinv[A]]] } ];
PrintMonomialOrder[];

NCProcess[ relations, 5,  0,  0,  0,  "BothTogether",  
        SBByCat  -> False,  RR ->  False,  
        NCCV  ->  
          False ];

NCMakeGB[ relations, 6 ];
If[ FinishedComputingBasisQ[]  ==  1,  
        Print[ "Finite Basis." ],  
        Print[ "NOT Finite Basis." ] ];