(* ::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.                                                         *)
(************************************************************************)



(* ::Input::Initialization:: *)
RowRed[Subspace[vs_,gens_]]:=RowReduce[Join[Table[Coefficient[g,v],{g,gens},{v,Sort[vs]}], IdentityMatrix[Length@gens], 2]];


(* ::Input::Initialization:: *)
CF[Subspace[{},{0...}]]:=Subspace[{},{}];
CF[Subspace[vs_,{}]]:=Subspace[Sort[vs],{}];
CF[Subspace[vs_,gens_]]:=Module[{cvs=Sort[vs]},
Subspace[cvs,
DeleteCases[(RowRed[Subspace[vs, gens]][[All,;;Length@vs]]) . cvs,0]
]];
CF[lt_LT]:=Sort/@lt
CFSteps[Subspace[{},{0...}]]:={};
CFSteps[Subspace[vs_,{}]]:={};
CFSteps[sub_]:=RowRed[sub][[All,-Length@RowRed[sub];;]];


(* ::Input::Initialization:: *)
Eval[Q_,v_,w_]:=Expand[Q v w]//. {Subscript[\[Eta], i__] Subscript[y, i__]:>1,\!\(
\*SubsuperscriptBox[\(\[Eta]\), \(i__\), \(2\)] 
\*SubsuperscriptBox[\(y\), \(i__\), \(2\)]\):>2}/.Subscript[(\[Eta]|y), __]->0;
Eval[\[Phi]_,v_]:=Expand[\[Phi] v]/.{Subscript[\[Eta], i__] Subscript[y, i__]:>1, \!\(
\*SubsuperscriptBox[\(\[Eta]\), \(i__\), \(2\)] 
\*SubscriptBox[\(y\), \(i__\)]\):>2Subscript[\[Eta], i]}/.Subscript[y, __]->0;


(* ::Input::Initialization:: *)
Pivot[v_Plus]:=v[[1]]; Pivot[v_]:=v;
\!\(
\*SubsuperscriptBox[\(y\), \(i__\), \(*\)] := 
\*SubscriptBox[\(\[Eta]\), \(i\)]\); \!\(
\*SubsuperscriptBox[\(\[Eta]\), \(i__\), \(*\)] := 
\*SubscriptBox[\(y\), \(i\)]\); SuperStar[(vs_List)]:=Table[SuperStar[v],{v,vs}];


(* ::Input::Initialization:: *)
CF[PQ[sub_Subspace,Q_]]:=Module[{csub,cvs,cgens},
{cvs,cgens}=List@@(csub=CF[sub]);
PQ[csub,Sum[Eval[Q,v,w]SuperStar[Pivot[v]] SuperStar[Pivot[w]]/2,{v,cgens},{w,cgens}]]
]


(* ::Input::Initialization:: *)
Perp[Subsp_]:=Module[{pp, cvs, cgens},
{cvs, cgens}=List@@CF@Subsp;
pp=SuperStar[Complement[cvs,Pivot/@cgens]];
CF@Subspace[SuperStar[cvs],
Table[p-Sum[Coefficient[g,SuperStar[p]]SuperStar[Pivot[g]],{g,cgens}],{p,pp}]
]
]


(* ::Input::Initialization:: *)
Id[vs_]:=LT[vs,vs,Table[v->v,{v,vs}]]


(* ::Input::Initialization:: *)
SuperStar[LT[dom_,ran_,rs_]][Subspace[ran_,gens_]]:= Perp@CF@Subspace[SuperStar[dom],Table[
Sum[Eval[p,v/.rs]SuperStar[v],{v,dom}],
{p,Perp[Subspace[ran,gens]][[2]]}
]]


(* ::Input::Initialization:: *)
SuperStar[LT[dom_,ran_,rs_]][PQ[sub_,Q_]]:= CF@PQ[
SuperStar[LT[dom,ran,rs]][sub],
Sum[Eval[Q,v1/.rs,v2/.rs]SuperStar[v1] SuperStar[v2]/2,{v1,dom},{v2,dom}]
]


(* ::Input::Initialization:: *)
Subspace/:Subspace[v1s_, gen1s_]\[CirclePlus]Subspace[v2s_, gen2s_]:=CF@Subspace[v1s \[Union]v2s,gen1s \[Union]gen2s];
Subspace/:Subspace[vs_,gen1s_]+Subspace[vs_,gen2s_]:=CF@Subspace[vs,gen1s \[Union]gen2s];
Subspace/:sub1_Subspace\[Intersection]sub2_Subspace:=Perp[Perp[sub1]+Perp[sub2]];
Subspace/:v_\[Element]Subspace[vs_, gens_]:=(Subspace[vs, gens]\[Intersection]Subspace[vs, {v}])[[2]]=!={};


(* ::Input::Initialization:: *)
PQ/:PQ[sub1_, Q1_]\[CirclePlus]PQ[sub2_, Q2_]:=CF@PQ[sub1\[CirclePlus]sub2, Q1+Q2];
PQ/:CirclePlus[PQ1_PQ, PQs__PQ]:=CirclePlus@@Join[{PQ1\[CirclePlus]First[{PQs}]}, {PQs}[[2;;]]];


(* ::Input::Initialization:: *)
Subscript[Ann, PQ[\[ScriptCapitalD]_Subspace,Q_]][Subspace[vs_,gens_]]:=\[ScriptCapitalD]\[Intersection]Perp@Subspace[SuperStar[vs],Table[Eval[Q,g],{g,gens}]]


(* ::Input::Initialization:: *)
Ker[LT[{},_,_]]:=Subspace[{},{}];
Ker[LT[dom_,{},_]]:=Subspace[dom,dom];
Ker[LT[dom_,ran_,rs_]]:=Module[{ns},
ns=NullSpace[Table[Coefficient[d/.rs,r],{r,ran},{d,dom}]];
If[Length@ns>0,CF@Subspace[dom,ns . dom],Subspace[dom,{}]]
]


(* ::Input::Initialization:: *)
(*will return a LT that is a section on the image*)
Section[LT[dom_,ran_,rs_]]:=Module[{im=Subspace[ran,dom/.rs],newrs={}},
newrs=Thread[Pivot/@(CF[im][[2]])->(CFSteps[im] . dom)[[;;Length@CF[im][[2]]]]];
LT[ran, dom, Join[newrs, Thread[Complement[ran,Pivot/@(CF[im][[2]])]->0]]]
]


(* ::Input::Initialization:: *)
Section[LT[Subspace[vs_, gens_],ran_,rs_]]:= Section[LT[gens, ran, rs]];


(* ::Input::Initialization:: *)
SubStar[(LT[dom_,ran_,rs_])][Subspace[dom_,gens_]]:= CF@Subspace[ran,gens/.rs]


(* ::Input::Initialization:: *)
SubStar[lt_LT][PQ[sub_,Q_]]:=CF@SuperStar[Section[CF[lt]]][CF@PQ[Subscript[Ann, PQ[sub,Q]][Ker[CF[lt]]],Q]];


(* ::Input::Initialization:: *)
Sig[PQ[Subspace[vs_, gens_], Q_]]:=Plus@@Sign@Eigenvalues[Table[Eval[Q, v, w], {v, gens}, {w, gens}]];



