(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



RowOp[i_, j_, mat_] := Module[{TT=II},
TT[[{i,j},{i,j}]] = mat;
NN=Simplify[TT.NN]; PP=Simplify[TT.PP];
];
ColOp[i_, j_, mat_] := Module[{TT=II},
TT[[{i,j},{i,j}]] = mat;
NN=Simplify[NN.TT]; QQ=Simplify[QQ.TT];
];


SwapRows[i_,j_] := RowOp[i,j,({
 {0, 1},
 {1, 0}
})];
SwapColumns[i_,j_] := ColOp[i,j,({
 {0, 1},
 {1, 0}
})];
SwapBoth[i_,j_] := (SwapRows[i,j]; SwapColumns[i,j];)


GCDTrick[{i_,j_}, k_] := Module[{a,b,q,s,t},
{q,{s,t}} = PolynomialExtendedGCD[a=NN[[i,k]], b=NN[[j,k]],x];
RowOp[i,j,({
 {s, t},
 {-b/q, a/q}
})]
];
GCDTrick[k_, {i_,j_}] := Module[{a,b,q,s,t},
{q,{s,t}} = PolynomialExtendedGCD[a=NN[[k,i]], b=NN[[k,j]],x];
ColOp[i,j,({
 {s, -b/q},
 {t, a/q}
})]
];


SplitToSum[i_,j_, a_, b_] := Module[
{q,s,t, T1, T2},
{q,{s,t}} = PolynomialExtendedGCD[a, b, x];
If[q==1,
RowOp[i,j,({
 {s a, 1},
 {-t b, 1}
})]; ColOp[i,j,({
 {a, -b},
 {t, s}
})];
]
];


JordanTrick[i_, j_, p_, s_] := (RowOp[i,j,({
 {p^(s-1), -1},
 {1, 0}
})]; ColOp[i,j,({
 {1, p},
 {0, 1}
})]);
