(* :Title: Boltzmann *) (* :Context: "Boltzmann`" *) (* :Author: P.H. Lundow Bug reports to phl@kth.se *) (* :Summary: Functions for converting between the list of K-values and the Boltzmann distribution of energies. Functions that return the traditional quantities of statistical physics. *) (* :History: 031107 Created. 031119 Much changed, added Susceptibility, deleted UC and UCM. 040302 New normalisation of InternalEnergy and SpecificHeat. 040512 Added Expectation, Moment, Entropy. 040602 Expectation overloaded. 040603 Expectation and Moment. 041015 Clean-up. Improved listIntegrate. Deleted InternalEnergy, SpecificHeat, Magnetisation. 041216 Added some comments. 050404 listIntegrate0, BoltzmannDistribution0. 071010 BoltzmannDistribution for a partition function. 071015 NormalList01, NormalFunction01. 100505 Added Cumulant. 110902 Adapted to version 8: Renamed Cumulant, Expectation, Moment, Fractile. *) (* :Mathematica Version: 4.0 *) (* :Keywords: *) (* :Limitations: *) (* :Discussion: *) BeginPackage["Boltzmann`"] BoltzmannDistribution::usage = "BoltzmannDistribution[K, listK, m] returns the probability for each energy in listK at coupling K for a graph with m edges. The argument listK is on the form {{e1,K1},..,{en,Kn}} where Ki is the coupling at relative energy ei. NOTE: e1Exp[K]}, Map[ {#/m, Coefficient[z, x, #]*Exp[#*K]/zz}&, Sort[Exponent[z, x, List]] ] ] BoltzmannDistribution0[K_, listK_List, m_, r_:False]:= Module[{sum, list}, list = Map[{#[[1]], m*(K - #[[2]])}&, listK]; list = listIntegrate0[list, r]; list = Map[{#[[1]], Exp[#[[2]]]}&, list]; sum = Apply[Plus, Map[Last, list]]; Map[{#[[1]], #[[2]]/sum}&, list] ] BoltzmannDistribution1[K_, listK_List, m_]:= Module[{sum, list}, list = Map[{#[[1]], m*(K - #[[2]])}&, listK]; list = listIntegrate1[list]; list = Map[{#[[1]], Exp[#[[2]]]}&, list]; sum = Apply[Plus, Map[Last, list]]; Map[{#[[1]], #[[2]]/sum}&, list] ] CouplingList[K_, dist_List, m_]:= Module[{list1, list2}, list1 = listDerivative[dist]; list2 = listAverage[dist]; MapThread[ {#1[[1]], K - #1[[2]]/#2[[2]]/m}&, {list1, list2} ] ] CumulantD[dist_, 1] := ExpectationD[dist] CumulantD[dist_, k_] := Module[{c, m, n, z}, c = D[Log[z[x]], {x, k}]; c = c/.Derivative[n_][z][x] -> m[n]*z[x]; c = c/.m[1] -> 0; Do[m[n] = CentralMomentD[dist, n], {n, 1, k}]; c ] EntropyD[dist:{__List}] := -Apply[Plus, Map[(#[[2]]*Log[#[[2]]])&, dist]] ExpectationD[dist:{__List}] := Apply[Plus, Apply[Times, dist, {1}]] ExpectationD[dist:{__List}, k_Integer]:= Apply[Plus, Map[(#[[2]] * #[[1]]^k)&, dist]] ExpectationD[dist:{__List}, func_]:= Apply[Plus, Map[(#[[2]] * func[#[[1]]])&, dist]] FractileD[dist:{__List}, frac_] := Module[{sum, pos}, sum = Rest[FoldList[Plus, 0, Map[Last, dist]]]; pos = Position[sum, x_/;x>=frac, Infinity, 1][[1, 1]]; dist[[pos, 1]] ] CentralMomentD[dist:{__List}, 0] := 1 CentralMomentD[dist:{__List}, 1] := 0 CentralMomentD[dist:{__List}, k_Integer] := Dot[ (Map[First, dist] - ExpectationD[dist])^k, Map[Last, dist] ] Normal01[dist:{__List}] := NormalFunction01[dist] NormalFunction01[dist:{__List}] := Interpolation[NormalList01[dist]] NormalList01[dist:{__List}] := Module[{a, d, n, s, tmp}, tmp = Map[First, dist]; d = Min[Drop[tmp, 1] - Drop[tmp, -1]]; n = Apply[Plus, Map[Last, dist]]; tmp = Map[{#[[1]], #[[2]]/n}&, dist]; a = ExpectationD[tmp]; s = Sqrt[CentralMomentD[tmp,2]]; Map[{(#[[1]]-a)/s, s*#[[2]]/d}&, tmp] ] Scan[Protect, definitions] End[] EndPackage[]