(* ::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\\2016-11"];


(* ::Input::Initialization:: *)
CF[expr_] := (expr /. E^x_:>E^Simplify[x /. Subscript[b, i_]:>2Log[Subscript[t, i]]])// Together // ExpandNumerator // ExpandDenominator;
\[DoubleStruckCapitalE] /: CF[\[DoubleStruckCapitalE][\[Omega]_,Q_]] := \[DoubleStruckCapitalE][CF[\[Omega]], CF[Q]];
\[DoubleStruckCapitalE] /: \[DoubleStruckCapitalE][\[Omega]1_, Q1_]\[DoubleStruckCapitalE][\[Omega]2_, Q2_] := CF@\[DoubleStruckCapitalE][\[Omega]1 \[Omega]2, Q1+Q2];
\[DoubleStruckCapitalE][\[Omega]1_,Q1_] \[Congruent] \[DoubleStruckCapitalE][\[Omega]2_, Q2_] := CF[\[Omega]1==\[Omega]2\[And]Q1==Q2];


(* ::Input::Initialization:: *)
Subscript[N, Subscript[u, i_] Subscript[c, j_]->k_][\[DoubleStruckCapitalE][\[Omega]_, Q_]] := CF[
\[DoubleStruckCapitalE][\[Omega],E^-\[Gamma] \[Beta] Subscript[u, k]+\[Gamma] Subscript[c, k]+(Q/.Subscript[c, j]|Subscript[u, i]->0)]/.{\[Gamma]->\!\(
\*SubscriptBox[\(\[PartialD]\), 
SubscriptBox[\(c\), \(j\)]]Q\),\[Beta]->\!\(
\*SubscriptBox[\(\[PartialD]\), 
SubscriptBox[\(u\), \(i\)]]Q\)}];
Subscript[N, Subscript[w, i_] Subscript[c, j_]->k_][\[DoubleStruckCapitalE][\[Omega]_, Q_]] := CF[
\[DoubleStruckCapitalE][\[Omega], E^\[Gamma] \[Alpha] Subscript[w, k]+\[Gamma] Subscript[c, k]+(Q/.Subscript[c, j]|Subscript[w, i]->0)]/.{\[Gamma]->\!\(
\*SubscriptBox[\(\[PartialD]\), 
SubscriptBox[\(c\), \(j\)]]Q\),\[Alpha]->\!\(
\*SubscriptBox[\(\[PartialD]\), 
SubscriptBox[\(w\), \(i\)]]Q\)}];
Subscript[N, Subscript[w, i_] Subscript[u, j_]->k_][\[DoubleStruckCapitalE][\[Omega]_,Q_]] := CF[
\[DoubleStruckCapitalE][\[Nu] \[Omega] , -Subscript[b, k]\[Nu] \[Alpha] \[Beta]+\[Nu] \[Beta] Subscript[u, k]+\[Nu] \[Delta] Subscript[u, k] Subscript[w, k]+\[Nu] \[Alpha] Subscript[w, k] +(Q/.Subscript[w, i]|Subscript[u, j]->0)] /. \[Nu]-> (1+Subscript[b, k] \[Delta])^-1 /. {\[Alpha]->\!\(
\*SubscriptBox[\(\[PartialD]\), 
SubscriptBox[\(w\), \(i\)]]Q\)/.Subscript[u, j]->0, \[Beta]->\!\(
\*SubscriptBox[\(\[PartialD]\), 
SubscriptBox[\(u\), \(j\)]]Q\)/.Subscript[w, i]->0, \[Delta]->\!\(
\*SubscriptBox[\(\[PartialD]\), \(
\*SubscriptBox[\(w\), \(i\)], 
\*SubscriptBox[\(u\), \(j\)]\)]Q\)}];


(* ::Input::Initialization:: *)
Subscript[m, i_,j_->k_][\[DoubleStruckCapitalE][\[Omega]_, Q_]] :=CF[Module[{x},
(\[DoubleStruckCapitalE][\[Omega], Q] /. {Subscript[b, i|j]->Subscript[b, k], Subscript[t, i|j]->Subscript[t, k]} // Subscript[N, Subscript[w, i] Subscript[c, j]->x]//Subscript[N, Subscript[u, i] Subscript[c, x]->x]//Subscript[N, Subscript[w, x] Subscript[u, j]->x]) /. {Subscript[c, i]->Subscript[c, k],Subscript[w, j]->Subscript[w, k],Subscript[y_, x]:>Subscript[y, k]}]]


(* ::Input::Initialization:: *)
Subscript[R, i_,j_][p_]:=\[DoubleStruckCapitalE][1, p Subscript[b, i] Subscript[c, j]+\!\(
\*SubsuperscriptBox[\(b\), \(i\), \(-1\)] \((
\*SuperscriptBox[\(E\), \(p\ 
\*SubscriptBox[\(b\), \(i\)]\)] - 1)\) 
\*SubscriptBox[\(u\), \(i\)] 
\*SubscriptBox[\(w\), \(j\)]\)]//CF;
\!\(
\*SubsuperscriptBox[\(R\), \(i_, j_\), \(+\)] := \(
\(\*SubscriptBox[\(R\), \(i, j\)]\)[1]\)\); \!\(
\*SubsuperscriptBox[\(R\), \(i_, j_\), \(-\)] := \(
\(\*SubscriptBox[\(R\), \(i, j\)]\)[\(-1\)]\)\);


(* ::Input::Initialization:: *)
\[DoubleStruckCapitalE] /: (e_\[DoubleStruckCapitalE])^\[Sigma][s___List]:=CF[e /. Flatten@Table[{
Subscript[b, k]->Total[Subscript[b, #]&/@{s}[[k]]], Subscript[c, k]->Total[Subscript[c, #]&/@{s}[[k]]],Subscript[u, k]->Total[Subscript[u, #]&/@{s}[[k]]],Subscript[w, k]->Total[Subscript[w, #]&/@{s}[[k]]],Subscript[t, k]->Times@@(Subscript[t, #]&/@{s}[[k]])
},{k,1,Length@{s}}]];
\[Sigma][l___,k_Integer,r___]:=\[Sigma][l,{k},r];


(* ::Input::Initialization:: *)
\[DoubleStruckCapitalE]/: e1_\[DoubleStruckCapitalE]**e2_\[DoubleStruckCapitalE] := Module[{\[Lambda],\[Nu],e},
\[Lambda]=(Union@Cases[e1,Subscript[(b|t|c|u|w), k_]:>k,\[Infinity]])\[Intersection](Union@Cases[e2,Subscript[(b|t|c|u|w), k_]:>k,\[Infinity]]);
\[Nu]=Table[Unique[], {Length@\[Lambda]}];
e=e1(e2/.Flatten@Table[{Subscript[b, \[Lambda][[k]]]->Subscript[b, \[Nu][[k]]],Subscript[t, \[Lambda][[k]]]->Subscript[t, \[Nu][[k]]],Subscript[c, \[Lambda][[k]]]->Subscript[c, \[Nu][[k]]],Subscript[u, \[Lambda][[k]]]->Subscript[u, \[Nu][[k]]],Subscript[w, \[Lambda][[k]]]->Subscript[w, \[Nu][[k]]]}, {k,Length@\[Lambda]}]);
Do[e=Subscript[m, \[Lambda][[k]],\[Nu][[k]]->\[Lambda][[k]]][e], {k,Length@\[Lambda]}];
e
]


(* ::Input::Initialization:: *)
A[n_][e_\[DoubleStruckCapitalE]]:=(e/.{Subscript[c, n]-> -Subscript[c, n],Subscript[w, n]->-Subscript[w, n]})//Subscript[N, Subscript[u, n] Subscript[c, n]->n]//Subscript[N, Subscript[w, n] Subscript[c, n]->n]//Subscript[N, Subscript[w, n] Subscript[u, n]->n];
A[][e_\[DoubleStruckCapitalE]] := e;
A[n_,r___][e_\[DoubleStruckCapitalE]] := e // A[n] // A[r];


(* ::Input::Initialization:: *)
\[Theta][i_][e_\[DoubleStruckCapitalE]]:=(e/.{Subscript[b, i]:>-Subscript[b, i],Subscript[c, i]:>-Subscript[c, i],Subscript[u, i]:>Subscript[w, i],Subscript[w, i]:>Subscript[u, i],Subscript[t, i]:>
\!\(\*SubsuperscriptBox[\(t\), \(i\), \(-1\)]\)})//CF//Subscript[N, Subscript[w, i] Subscript[u, i]->i];
\[Theta][][e_\[DoubleStruckCapitalE]] := e;
\[Theta][n_,r___][e_\[DoubleStruckCapitalE]] := e // \[Theta][n] // \[Theta][r];



