(* ::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:: *)
SetDirectory["C:\\drorbn\\AcademicPensieve\\Projects\\SL2Portfolio2"];
(*Once[<< KnotTheory`];*)
Once[<<"../Profile/Profile.m";];
<<"Engine-Speedy.m";
<<"Objects.m";
$k=3;
HL[\[ScriptCapitalE]_] := Style[\[ScriptCapitalE], Background -> Green];


(* ::Input::Initialization:: *)
(* Bug: The first line is valid only if \[DoubleStruckCapitalO](\[ExponentialE]^Subscript[P, 0])\[Equal](\[ExponentialE]^(\[DoubleStruckCapitalO](Subscript[P, 0]))). *)
Subscript[Exp, mm_,i_,0][P_]:=Module[{LQ=Normal@P /. \[Epsilon]->0},
\[DoubleStruckCapitalE][LQ/.Subscript[(x|y), i]->0, LQ/.Subscript[(b|a|t), i]->0,1] ];


(* ::Input::Initialization:: *)
Subscript[Exp, mm_,i_,k_][P_]:=Block[{$k=k},
Module[{P0,\[Lambda],\[CurlyPhi],F,j,rhs,err=0,pows,at0,at\[Lambda]},
P0=Normal@P /. \[Epsilon]->0;
F=Normal@Last@Subscript[Exp, mm,i,k-1][\[Lambda] P];
(*Unary*)While[
If[err=!=0,
pows=Echo[First/@CoefficientRules[err,{Subscript[y, i],Subscript[b, i],Subscript[a, i],Subscript[x, i]}]];
F+=Sum[\[Epsilon]^k Subscript[\[CurlyPhi], js][\[Lambda]]Times@@({Subscript[y, i],Subscript[b, i],Subscript[a, i],Subscript[x, i]}^js),{js,pows}];
rhs=Normal@Last@Subscript[mm, i,j->i][Subscript[\!\(\*SubscriptBox[\(\[DoubleStruckCapitalE]\), \({} \[Rule] {i}\)]\)[\[Lambda] P0/.Subscript[(x|y), i]->0,\[Lambda] P0/.Subscript[(b|a|t), i]->0, F], k]Subscript[s\[Sigma], i->j]@Subscript[\!\(\*SubscriptBox[\(\[DoubleStruckCapitalE]\), \({} \[Rule] {i}\)]\)[0,0,P], k]];
err=CF[(\!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Lambda]\)]F\))+P0 F-rhs];
at0=Table[Subscript[\[CurlyPhi], js][0]==0,{js,pows}];
at\[Lambda]=(#==0)&/@(pows/.CoefficientRules[err,{Subscript[y, i],Subscript[b, i],Subscript[a, i],Subscript[x, i]}]);
F=F/. DSolve[And@@(at0\[Union]at\[Lambda]),Table[Subscript[\[CurlyPhi], js][\[Lambda]],{js,pows}],\[Lambda]][[1]]
];
rhs=Normal@Last@Subscript[mm, i,j->i][Subscript[\!\(\*SubscriptBox[\(\[DoubleStruckCapitalE]\), \({} \[Rule] {i}\)]\)[\[Lambda] P0/.Subscript[(x|y), i]->0,\[Lambda] P0/.Subscript[(b|a|t), i]->0, F], k]Subscript[s\[Sigma], i->j]@Subscript[\!\(\*SubscriptBox[\(\[DoubleStruckCapitalE]\), \({} \[Rule] {i}\)]\)[0,0,P], k]];
err=CF[(\!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Lambda]\)]F\))+P0 F-rhs];
err=!=0
];
\!\(\*SubscriptBox[\(\[DoubleStruckCapitalE]\), \({} \[Rule] {i}\)]\)[P0/.Subscript[(x|y), i]->0,P0/.Subscript[(b|a|t), i]->0, F+O[\[Epsilon]]^(k+1)/.\[Lambda]->1]]
]



