<jupyter_start><jupyter_text>Level spacing distribution for desymmetrized <NAME><jupyter_code>eigs = Flatten[Import["./data/eigenvals.dat"]];
levnum = Length[eigs]
(* dist funcs *)
Poisson[s_] := Exp[-s];
Wigner[s_] := (\[Pi]*s)/2*Exp[-(\[Pi]/4)*s^2];<jupyter_output><empty_output><jupyter_text>Naive method<jupyter_code>(* Parameter
----------
discardlevel : a number of discard eigenvalues from the ground state
*)

PlotNaivePDF[eigs_, discardlevel_]:=
    Module[
        {eigvals, \[CapitalDelta]E, mean\[CapitalDelta]E},
        eigvals = eigs[[discardlevel;;-1]];
        \[CapitalDelta]E = Table[0, {i, 1, levnum-discardlevel}];
        For[i = 1, i < levnum - discardlevel,  i++, \[CapitalDelta]E[[i]] = eigvals[[i + 1]] - eigvals[[i]]];
        mean\[CapitalDelta]E = Mean[\[CapitalDelta]E];
        dEbar = \[CapitalDelta]E/mean\[CapitalDelta]E;
        Show[
            Histogram[dEbar, Automatic, "PDF", PlotRange -> All, AxesLabel -> {"s", "P(s)"}],
            Plot[
                {Poisson[s], Wigner[s]},
                {s, 0, 3.}, 
                AxesLabel -> {"s", "P(s)"},
                PlotLegends -> {"Poisson", "Wigner"}, 
                PlotStyle -> {{Blue, Dashing[Medium]}, {Red,Dashing[Medium]}}
            ]
        ]
    ]
PlotNaivePDF[eigs, 200]<jupyter_output><empty_output><jupyter_text>Unfolding Procedure* Ref : 4.2.3 in http://www.is.ocha.ac.jp/~kudo/dron.pdf<jupyter_code>(* Parameter
----------
discardlevel : a number of discard eigenvalues from the ground state.
interval : interval between data points for interpolation.
*)

PlotLevelSP[eigs_, discardlevel_, interval_]:=
    Module[
        {eigvals},
        eigvals = eigs[[discardlevel;;-1]];
        set = {#[[1]], #[[2]]}& /@ Transpose[{eigvals, Range[discardlevel,levnum]}];
        spfun = Interpolation[set[[;; ;;interval]], Method -> {"Spline"}];
        Nbar = spfun[eigvals];
        s = Nbar[[2;;]]-Nbar[[;;-2]];
        Show[
            Histogram[s, {0.1}, "PDF", PlotRange -> All, AxesLabel -> {"s", "P(s)"}, PlotLabel -> "Level-spacing distribution"],
            Plot[
                {Poisson[s], Wigner[s]},
                {s, 0, 3.},
                PlotLegends -> {"Poisson", "Wigner"},
                PlotStyle -> {{Blue, Dashing[Medium]}, {Red,Dashing[Medium]}}
            ]
        ]        
    ]
PlotLevelSP[eigs, 200, 100]<jupyter_output><empty_output><jupyter_text>--- cf. <NAME>* Ref. [spectra finite systems](http://smallsystems.isn-oldenburg.de/Docs/THEO3/publications/spectra.finite.systems.pdf) (p.59~) \begin{eqnarray}-\Delta \psi_n(\mathbf{x}) = E_n \psi_n(\mathbf{x}) \quad \mathbf{x} \in\Omega \qquad \psi_n(\mathbf{x})=0 \ \ \text{for} \ \mathbf{x} \in \partial\Omega\end{eqnarray} Generalized Weyl formula (for the Laplace–Beltrami operator) :The average integrated level density $\langle N(E) \rangle$ is written by\begin{eqnarray}\langle N(E) \rangle = \frac{\mathcal{A}}{4\pi}E - \frac{\mathcal{L}}{4\pi}\sqrt{E} + \mathcal{C}, \qquad \mathcal{L} = \mathcal{L}^- -\mathcal{L}^+ \end{eqnarray}where $\mathcal{L}^-$ and $\mathcal{L}^+$ are the lengths of the pieces of the boundary $\partial\Omega$ with Dirichlet andNeumann boundary conditions, respectively.$\mathcal{C}$ is constant and depends on curvature.<jupyter_code>WaLL[{a_, \[Epsilon]_}, t_] := {a*(1 + \[Epsilon]*Cos[t])*Cos[t], a*(1 + \[Epsilon]*Cos[t])*Sin[t]};
ArcLength[WaLL[{a, eps}, \[Theta]], {\[Theta], 0, 2 Pi}]
(* In the case of desymmetrized calculation (orange region) *)

Weyllaw[eps_,E_]:=(
        a = Sqrt[3/(2+eps^2)];
        area = Pi*(a^2)*(2+eps^2)/4;
        If[eps==1,
           perimeter = 6*a, (* 8*a/2 + 2a *)
           perimeter = a*((1+eps)*EllipticE[4*eps/((1+eps)^2)]-(eps-1)*EllipticE[-4*eps/((eps-1)^2)]) + 2*a*eps
        ];
        Navg = area*E/(4*Pi) - perimeter*Sqrt[E]/(4*Pi);
        Return[Navg]
    )
eigs = eigs[[200;;-1]];
Plotcheck[start_, end_]:=
    Show[{
        ListPlot[
            set[[start;;end]], 
            PlotStyle -> {Blue}, 
            PlotRange -> All,
            AxesLabel -> {"E", "Level"},
            PlotLegends -> {"eigenval"},
            GridLines -> Automatic,
            ImageSize -> Large
        ],
        Plot[
            {spfun[x], Weyllaw[1,x]}, 
            {x, eigs[[start]], eigs[[end]]}, 
            PlotStyle -> {Red, Green}, 
            AxesLabel -> {"E", "spfun"},
            PlotLegends -> {"<N(E)>:spline", "Weyl Law"},
            GridLines -> Automatic
        ]
    }]
{Plotcheck[10, 40], Plotcheck[1000, 1100]}<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup