(* Chaotic inflation *)

(* Define a potential *)
V[ϕ_]:=((Λ )^(4-n))ϕ^n

(* These are the slow roll paramters *)
ϵ=(1/(2κ^2))(((V'[ϕ])/(V[ϕ])))^2;
η=(1/(κ^2))(((V''[ϕ])/(V[ϕ])));

{ϵ,η}

(* The field at the end of inflation *)
ϕend=ϕ/.Solve[ϵ==1,ϕ][[2]]

(* The number of e-folds *)
int=(1/(Sqrt[2ϵ]))//PowerExpand;
Ninf=Integrate[κ int,{ϕ,ϕend,ϕ}]//Expand

(* The field after N efolds *)
solf=Solve[Ninf==Nf,ϕ][[2]]//FullSimplify

{ϵ,η}/.solf

(* The spectral index *)
ns=1-6ϵ+2η/.solf//FullSimplify

(* The ratio of scalar to tensor *)
r=16ϵ/.solf

(* Find the allowed region from Planck *)
RegionPlot[{r<0.10,0.968-0.006<ns<0.968+0.006},{n,0,4},{Nf,60,65},PlotLegends->{"r<0.10","(Subscript[n, s])=0.968±0.006"},Epilog->{Dashed,Line[{{1,60},{1,70}}],Line[{{2,60},{2,70}}],Line[{{3,60},{3,70}}]},FrameLabel->{"n","(Subscript[N, inf])"},FrameStyle->Black]

(* end *)

(* Example exponential *)

(* Define a potential *)
V[ϕ_]:=V0 Exp[λ (((ϕ κ))^2)]

(* These are the slow roll paramters *)
ϵ=(1/(2κ^2))(((V'[ϕ])/(V[ϕ])))^2;
η=(1/(κ^2))(((V''[ϕ])/(V[ϕ])));

ϵ//FullSimplify
η//FullSimplify

(* The field at the end of inflation *)
ϕend=ϕ/.Solve[ϵ==1,ϕ][[2]]

(* The number of e-folds *)
int=(1/(Sqrt[2ϵ]))//PowerExpand;
Ninf=Integrate[κ int,{ϕ,ϕend,ϕ},GenerateConditions->False]

(* The field after N efolds *)
solf=Solve[Ninf==Nf,ϕ][[1]]/.Im[x_]->0//FullSimplify

{ϵ,η}/.solf//FullSimplify

(* The spectral index *)
ns=1-6ϵ+2η/.solf//FullSimplify

(* The ratio of scalar to tensor *)
r=16ϵ/.solf

sol=Solve[r==(1/10),λ][[1]]/.C[1]->0
%/.Nf->{60,65,70}//N
ns/.sol//N
%/.Nf->{60,65,70}//N

(* Find the allowed region from Planck *)
RegionPlot[{r<0.1,0.968-0.006<ns<0.968+0.006},{λ,-5,5},{Nf,60,65},PlotLegends->{"r<0.11","(Subscript[n, s])=0.968±0.006"},Epilog->{Dashed,Line[{{1,60},{1,70}}],Line[{{2,60},{2,70}}],Line[{{3,60},{3,70}}]},FrameLabel->{"λ","Ninf"}]

(* end *)

(* Plateau models *)

(* Define a potential *)
V[ϕ_]:=((Λ )^4)(1-Exp[-γ κ ϕ])^2

(* These are the slow roll paramters *)
ϵ=(1/(2κ^2))(((V'[ϕ])/(V[ϕ])))^2;
η=(1/(κ^2))(((V''[ϕ])/(V[ϕ])));

{ϵ,η}//FullSimplify

(* The field at the end of inflation *)
ϕend=ϕ/.Solve[ϵ==1,ϕ][[2]]/.C[1]->0

(* The number of e-folds *)
int=(1/(Sqrt[2ϵ]))//PowerExpand;
Ninf=Integrate[κ int,{ϕ,ϕend,ϕ}]//Expand

(* Approximation *)
Ninf=((E^(γ κ ϕ))/(2 (γ^2)));

(* The field after N efolds *)
solf=Solve[Ninf==Nf,ϕ][[1]]/.C[1]->0//FullSimplify

(* The spectral index *)
ns=1-6ϵ+2η/.solf//FullSimplify
Series[ns,{Nf,∞,1}]//FullSimplify

(* The ratio of scalar to tensor *)
r=16ϵ/.solf//FullSimplify
Series[r,{Nf,∞,2}]//FullSimplify

(* end *)

(* Natural inflation *)

(* Define a potential *)
V[ϕ_]:=((Λ )^4)(1+Cos[ϕ/v])

(* These are the slow roll paramters *)
ϵ=(1/(2κ^2))(((V'[ϕ])/(V[ϕ])))^2;
η=(1/(κ^2))(((V''[ϕ])/(V[ϕ])));

{ϵ,η}//FullSimplify

(* The field at the end of inflation *)
ϕend=ϕ/.Solve[ϵ==1,ϕ][[1]]/.C[1]->0//PowerExpand

(* The number of e-folds *)
int=(1/(Sqrt[2ϵ]))//PowerExpand;
int0=Integrate[κ int,ϕ];
Ninf=int0-(int0/.ϕ->ϕend)//Expand//PowerExpand//FullSimplify

(* Approximation *)
Ninf=2 (v^2) (κ^2) Log[Sin[(ϕ/(2 v))]];

(* The field after N efolds *)
solf=Solve[Ninf==Nf,ϕ][[2]]/.Im[(Nf/((v^2) (κ^2)))]->0/.C[1]->0

{ϵ,η}/.solf//PowerExpand//FullSimplify

(* The spectral index *)
ns=1-6ϵ+2η/.solf//FullSimplify
Series[ns,{N,∞,2}]//FullSimplify

(* The ratio of scalar to tensor *)
r=16ϵ/.solf//FullSimplify
Series[r,{N,∞,2}]//FullSimplify

(* end *)

(* Power law inflation *)

(* Define a potential *)
V[ϕ_]:=((Λ )^4)Exp[-λ κ ϕ]

(* These are the slow roll paramters *)
ϵ=(1/(2κ^2))(((V'[ϕ])/(V[ϕ])))^2;
η=(1/(κ^2))(((V''[ϕ])/(V[ϕ])));

{ϵ,η}

(* The spectral index *)
ns=1-6ϵ+2η//FullSimplify

(* The ratio of scalar to tensor *)
r=16ϵ

(* end *)