diff --git a/README.md b/README.md index fc021a6..3e325af 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,11 @@ with Claude (Anthropic), for [Foundation0](https://github.com/Foundation-0/f0). scales, but beyond about 80 to 300 million parsecs (h⁻¹ Mpc, 80 to 300) they are spread almost evenly (Scrimgeour et al., 2012). The nesting stops, the way a coastline's roughness stops at the size of molecules. +Some repetition across scales has to be tuned, and some sets its own range. At a critical point, such as water's +liquid-vapour critical point or the Curie temperature of a magnet whose spins point only up or down, fluctuations +of every size appear, but only while the system is held at that point. Turbulent cascades and gravitational +clustering are scale-free over a range the system sets itself ([third study](#third-study-the-critical-point)). + ## First study: the Witness Map Why do electrons act as waves and planets do not? Ask any object one question: can it be in two places @@ -192,11 +197,14 @@ npm test # checks the model against published nu node witness-map/table.mjs # every object at a 250 nm gap, then the crowd node witness-map/table.mjs 1e-6 cryo # 1 µm gap, everything in a 4 K vacuum node notes/bh-lensing.mjs # every number in the black hole note +node critical/table.mjs # the critical-point study's numbers (about 65 s) ``` `witness-map/model.js` is the whole model, including `gravAtom` for the black hole note. It loads in Node (`require`) and in a browser (`window.WM`). `npm test` also checks `gravitational-atom/atom.js` (second study, -below). +below). The third study's checks, `tests/critical.mjs`, add about 65 s of seeded Monte Carlo runs, most of it +percolation with nine seeds. CI runs every line above except the `critical/table.mjs` line: it repeats the tests' +seeded runs and prints the results without checking them. ## Checks @@ -232,7 +240,8 @@ can go. The tolerance is ×5: half a power of ten for rounding, and a little mor state. The crowd rows compare formulas and fits, so they agree more closely; the core is solved here from first principles (the ground state of the Schrödinger–Poisson equations), not taken from the fits. Through gravity alone, the electron of the electric row would wait 5×10¹²⁴ years. The black hole note's checks are listed in -[notes/bh-lensing.md](notes/bh-lensing.md), the gravitational atom's below. +[notes/bh-lensing.md](notes/bh-lensing.md), the gravitational atom's below, and the critical point's in +[critical/README.md](critical/README.md#what-it-reproduces). What the re-check found (issue #5, details in CORRECTIONS.md): two coefficient errors, now fixed; a molecule's glow that is fitted, and gets the onset of decoherence right but the light wrong; and four places where the @@ -308,6 +317,36 @@ Huang 2015, eq. 6). What the gravitational-atom model leaves out: everything past leading order in α; the cloud's own gravity and the hole's loss of mass; interactions between the particles; anything else near the hole. +## Third study: the critical point + +Why does anything repeat across scales at all? At a critical point, such as water at 647 K and 22 MPa or a magnet +at its Curie temperature, fluctuations of every size appear, from the size of a molecule up to a correlation length +ξ that grows without limit as the temperature approaches T_c. A 2D Ising lattice and site percolation, run with +seeded random numbers in `critical/model.js`, come out at or close to the exact answers: the Ising results within +1.5 standard deviations, the percolation threshold within one standard error once open edges are allowed for, and +the spanning cluster's dimension 0.8% low (details in +[critical/README.md](critical/README.md#what-it-reproduces), issue #20): + +- T_c from where the Binder cumulants of two lattice sizes cross: 2.2704 ± 0.0017 J/k_B, against Onsager's + 2/ln(1 + √2) = 2.2692. Yang's spontaneous magnetisation within 0.21%. +- The exponents β/ν = 0.1245 ± 0.0026, γ/ν = 1.751 ± 0.004 and η = 0.250 ± 0.005, against 1/8, 7/4 and 1/4. +- Percolation, averaged over nine seeds: p_c = 0.59292 ± 0.00023, against 0.592746 (Newman and Ziff 2000), 0.00017 + high, of which open edges account for 0.00012 (Ziff and Newman 2002). A spanning cluster of fractal dimension + 1.880 ± 0.002, 0.8% below 91/48 = 1.896: a finite-size shortfall, as the effective exponent rises with L over + these sizes. +- Where the nesting stops: at the lattice spacing below, and at ξ above. The measured ξ falls from 9.9 lattice + spacings 6% above T_c to 1.1 at 76% above, within 3% of the exact value. At T_c the size of the box is the only + limit. + +Here the scale-free range has to be tuned: the temperature to T_c and the magnetic field to zero. Turbulent +cascades, and gravitational clustering grown from a nearly scale-invariant start, are scale-free over a range that +nobody tunes: the flow's Reynolds number, or the time gravity has had to act, sets it (sources in +[critical/README.md](critical/README.md#tuned-scale-invariance-against-self-organised-ranges); the clustering turns +smooth on the largest scales, as the [opening section](#where-the-intuition-holds-and-where-it-breaks) describes). +Real fluids have the same mechanism with three-dimensional exponents: ξ grows 4.27-fold for each tenfold approach +to T_c (ν = 0.630; Kos, Poland, Simmons-Duffin and Vichi 2016), against tenfold for the 2D lattice. `npm test` +checks the study against the exact results (`tests/critical.mjs`). + Mistakes found along the way are in [CORRECTIONS.md](CORRECTIONS.md). Open questions are the [issues](https://github.com/Foundation-0/fractals/issues). @@ -359,6 +398,17 @@ The crowd wave: - A.-C. Eilers, D. W. Hogg, H.-W. Rix and M. K. Ness, *The circular velocity curve of the Milky Way from 5 to 25 kpc*, ApJ 871, 120 (2019). https://doi.org/10.3847/1538-4357/aaf648 (https://arxiv.org/abs/1810.09466) - GRAVITY Collaboration, *A geometric distance measurement to the Galactic Center black hole with 0.3% uncertainty*, A&A 625, L10 (2019). https://doi.org/10.1051/0004-6361/201935656 (https://arxiv.org/abs/1904.05721) +The critical point (the full list is in [critical/README.md](critical/README.md#sources)): + +- L. Onsager, *Crystal statistics. I. A two-dimensional model with an order-disorder transition*, Phys. Rev. 65, 117 (1944). Not consulted directly; T_c and the energy are checked against Caselle et al. (2002). https://doi.org/10.1103/PhysRev.65.117 +- C. N. Yang, *The spontaneous magnetization of a two-dimensional Ising model*, Phys. Rev. 85, 808 (1952). Not consulted directly; the formula is checked against Caselle et al. (2002). https://doi.org/10.1103/PhysRev.85.808 +- M. Caselle, M. Hasenbusch, A. Pelissetto and E. Vicari, *Irrelevant operators in the two-dimensional Ising model*, J. Phys. A 35, 4861 (2002). https://doi.org/10.1088/0305-4470/35/23/305 (https://arxiv.org/abs/cond-mat/0106372) +- M. E. J. Newman and R. M. Ziff, *Efficient Monte Carlo algorithm and high-precision results for percolation*, Phys. Rev. Lett. 85, 4104 (2000). https://doi.org/10.1103/PhysRevLett.85.4104 (https://arxiv.org/abs/cond-mat/0005264) +- R. M. Ziff and M. E. J. Newman, *Convergence of threshold estimates for two-dimensional percolation*, Phys. Rev. E 66, 016129 (2002). https://doi.org/10.1103/PhysRevE.66.016129 (https://arxiv.org/abs/cond-mat/0203496) +- F. Kos, D. Poland, D. Simmons-Duffin and A. Vichi, *Precision islands in the Ising and O(N) models*, JHEP 08, 036 (2016). https://doi.org/10.1007/JHEP08(2016)036 (https://arxiv.org/abs/1603.04436) +- P. J. Linstrom and W. G. Mallard (eds.), *NIST Chemistry WebBook, NIST Standard Reference Database 69* (retrieved 18 October 2026), water, phase change data: critical point 647 ± 2 K and 220.64 bar. https://doi.org/10.18434/T4D303 +- A. Alexakis and L. Biferale, *Cascades and transitions in turbulent flows*, Phys. Rep. 767–769, 1 (2018). https://doi.org/10.1016/j.physrep.2018.08.001 (https://arxiv.org/abs/1808.06186) + ## Licence Apache License 2.0. diff --git a/critical/README.md b/critical/README.md new file mode 100644 index 0000000..4d72ded --- /dev/null +++ b/critical/README.md @@ -0,0 +1,288 @@ +# The critical point: why a lattice repeats itself across scales, and where it stops + +Notes for [issue #20](https://github.com/Foundation-0/fractals/issues/20). Exploration, not peer reviewed, no new +result claimed. `node critical/table.mjs` (about 65 s) prints the Monte Carlo numbers below, the percolation ones +for each of nine seeds and as their mean. No script prints three kinds of number: the results of a one-off repeat +of the checks with 120 other sets of seeds, described under [What it reproduces](#what-it-reproduces); γ/ν's +finite-size bias of +0.0012, worked out from a published formula; and the 11% and 25% uncertainties of an error +bar. `npm test` (`tests/critical.mjs`) checks the numbers compared with an exact value: the table under "What it +reproduces", the ξ table, the measurement-trap cumulants and the same numbers in the short answer. The rest are +printed but not checked: the slopes over other ranges of L, the cluster shares, the size ratios and each +percolation seed's results. Exact values are quoted from the sources named beside them. Started 18 October 2026. + +The other studies find self-similarity over a range of scales and ask where it stops. This one asks why it appears +at all, in the one case where the exact answers are known and both ends of the range can be moved at will. + +## Short answer + +- **Here, repetition across scales has to be tuned.** An Ising magnet, whose spins can point only up or down along + one axis (the case modelled here), repeats itself across scales only at its critical temperature T_c, and only in + zero field. There, patches of aligned spins come in every size from the lattice spacing to the size of the + sample, nested inside one another. Away from T_c the nesting stops at the correlation length ξ, which in the + two-dimensional model grows as 1/|T − T_c| (exponent ν = 1). +- **A small model lands on or near the exact numbers.** A 2D Ising lattice with seeded random numbers places T_c at + 2.2704 ± 0.0017 J/k_B, where the Binder cumulants of two sizes cross, against Onsager's 2/ln(1 + √2) = 2.2692. It + reproduces Yang's spontaneous magnetisation within 0.21%, and gives β/ν = 0.1245 ± 0.0026, γ/ν = 1.751 ± 0.004 + and η = 0.250 ± 0.005, against 1/8, 7/4 and 1/4. Site percolation on a square lattice, averaged over nine + seeds, gives p_c = 0.59292 ± 0.00023 where the spanning probabilities of L = 64 and 256 cross, against 0.592746 + (Newman and Ziff 2000): 0.00017 high, of which open edges account for 0.00012 (Ziff and Newman 2002). Its + spanning cluster has fractal dimension 1.880 ± 0.002, 0.8% below 91/48 = 1.896: a finite-size shortfall, as the + effective exponent rises with L over these sizes. Both are explained [below](#what-it-reproduces). +- **The nesting stops where the exact solution says.** Below, at the lattice spacing. Above, at ξ: the measured + correlation length falls from 9.9 ± 0.2 lattice spacings 6% above T_c to 1.11 ± 0.02 at 76% above, within 3% of + the exact values, 10.2 and 1.10. At T_c the size of the box is the only upper limit: in boxes from 8 to 128 + lattice spacings across, the magnetisation, susceptibility and spin-spin correlation follow their exact power + laws within their statistical errors, 0.9% to 1.6%. +- **Tuned against self-organised.** Heat the lattice 6% above T_c and the nesting ends at ten lattice spacings; + below T_c it ends sooner, at nine lattice spacings only 3% below. Turbulence and cosmic structure are scale-free + over a range that nobody tunes: the flow or the universe sets it, through the Reynolds number or the time gravity + has had to act. + +## Why a critical point has no scale + +In the Ising model each site of a square lattice holds a spin, up or down, and neighbouring spins prefer to align +(coupling J). Heat disorders them. At high temperature the aligned patches are small. As the temperature falls they +grow, and at T_c = 2/ln(1 + √2) = 2.2692 J/k_B (Onsager 1944) their typical size, the correlation length ξ, becomes +infinite. Below T_c one direction wins and the lattice is magnetised. + +Away from T_c the model has two lengths, the lattice spacing and ξ. At T_c only the lattice spacing is left, and it +is too small to set the size of anything large. With no length to fix it, the pattern is the same at every scale +between the lattice spacing and the size of the sample: the correlation between two spins r apart falls as +r^(−1/4), a power law, which looks the same at any magnification. Patches contain smaller patches, which contain +smaller ones. + +The renormalisation group gives the reason and its consequences (for a review, Pelissetto and Vicari 2002). Replace +each block of spins by one spin, and the lattice looks coarser. At T_c the coarse lattice has the same statistics +as the fine one: the critical point is a fixed point of this zooming out. Away from T_c each step of zooming out +carries the effective temperature further from T_c, so a small mistuning t = (T − T_c)/T_c is invisible on short +scales and takes over at ξ ∝ |t|^(−ν). The lattice's details fade with every step. That is why the exponents are +universal: they are the same for every model with short-range forces, the same symmetry and the same number of +dimensions. + +An Ising magnet has two settings to tune: the temperature, to T_c, and the magnetic field, to zero. Percolation has +one: the fraction p of occupied sites, to p_c = 0.592746 on the square lattice (Newman and Ziff 2000). At p_c the +first cluster to span the box is a fractal. The chance that a site connects to distance R falls as R^(−5/48), so +the spanning cluster's mass in a box of side L grows as L^(2 − 5/48) = L^(91/48). The exponent 5/48 follows, +through scaling relations, from exponents predicted by den Nijs (1979) and Nienhuis, Riedel and Schick (1980). It +was proved for site percolation on the triangular lattice by Lawler, Schramm and Werner (2002; see also Smirnov and +Werner 2001). The square lattice is expected to share it, by universality. + +## The model + +`critical/model.js` is the whole model (`window.CRIT` in a browser, `require` in Node; no dependencies). + +- **Ising.** An L × L lattice with periodic edges, J = k_B = 1, so temperatures are in units of J/k_B and lengths + in lattice spacings. Wolff cluster updates (Wolff 1989): grow a cluster from a random spin, adding each aligned + neighbour with probability 1 − e^(−2J/k_BT) (the bond probability of the cluster representation, as in Fujimoto + and Otsuka 2020, appendix B), then flip it. A sweep is a fixed number of cluster flips, set during thermalisation + so that about L² spins turn over. After every sweep the model records the magnetisation per spin m, the energy, + and either the correlation G(L/2) between spins half a box apart or the row-summed correlation, whose decay gives + ξ directly. From these: ⟨|m|⟩, the susceptibility χ = L²⟨m²⟩ and the Binder cumulant U = 1 − ⟨m⁴⟩/(3⟨m²⟩²) + (Binder 1981). The runs at the critical point are made at T = 2.27, a round number 0.04% above T_c, and + reweighted to Onsager's T_c and to nearby temperatures (Ferrenberg and Swendsen 1988): each measurement counts + with the ratio of the two Boltzmann weights, exp(−(1/T − 1/T_run)E), E the energy of the lattice. +- **Percolation.** An L × L lattice with open edges. Newman and Ziff's algorithm (2000): occupy sites one at a time + in random order, join each to its occupied neighbours with union-find, and note when a cluster first touches both + the top and the bottom row. Averages at any p follow by weighting each number of occupied sites binomially. The + runs are made with nine independent seeds, and the checks use their mean. +- **Random numbers.** `xoshiro128**`, seeded, integer arithmetic only. The same seed gives the same numbers on + every engine; the checks print identical values on Node 18 and 22, so they cannot flake. +- **Error bars.** One standard deviation, from a jackknife over 40 blocks of each run. Error bars of this kind are + themselves uncertain by about 1/√(2 × 39) = 11%. For a mean over the nine percolation seeds the error bar is the + standard error of the mean, the scatter between seeds over 3, uncertain by about 1/√(2 × 8) = 25%. +- **A trap in measuring cluster runs.** Measuring each time the flipped clusters add up to L² spins, instead of + after a fixed number of flips, over-weights ordered states: it stops more often just after a large cluster has + flipped, when the lattice holds a large aligned domain. At T_c and L = 16 the Binder cumulant comes out + 0.6289 ± 0.0004 that way, against 0.6100 ± 0.0008 with a fixed count. The model uses a fixed count. + +## What it reproduces + +| Check | Exact | Model | +|---|---|---| +| Spontaneous magnetisation ⟨\|m\|⟩ at T = 2.0, 2.1, 2.2, L = 64 (Yang 1952) | 0.91132, 0.86875, 0.78476 | 0.91129 ± 0.00035, 0.86913 ± 0.00060, 0.78314 ± 0.00163 | +| Energy per spin, same runs (Onsager 1944) | −1.74556, −1.66208, −1.54649 | −1.74536 ± 0.00066, −1.66253 ± 0.00096, −1.54527 ± 0.00129 | +| T_c from Binder cumulant crossings, L = 32 and 64; 64 and 128 (Onsager 1944) | 2.2692 | 2.2683 ± 0.0022; 2.2704 ± 0.0017 | +| Binder cumulant at T_c, mean of L = 16 to 128 (Salas and Sokal 2000) | 0.61069 | 0.6101 ± 0.0011 | +| β/ν from ⟨\|m\|⟩ ∝ L^(−β/ν) at T_c, L = 8 to 128 | 1/8 = 0.125 | 0.1245 ± 0.0026 | +| γ/ν from χ ∝ L^(γ/ν), same runs | 7/4 = 1.75 | 1.7510 ± 0.0040 | +| η from G(L/2) ∝ L^(−η), same runs | 1/4 = 0.25 | 0.2503 ± 0.0047 | +| 1/ν from the slope of U at T_c, ∝ L^(1/ν), same runs | 1 | 1.021 ± 0.032 | +| ξ at T = 2.4, 2.5, 2.75, 3, 4 (closed form below) | 10.23, 5.96, 3.06, 2.14, 1.10 | 9.93 ± 0.21, 5.90 ± 0.10, 3.05 ± 0.06, 2.17 ± 0.04, 1.11 ± 0.02 | +| Energy per spin at the same five temperatures (Onsager 1944) | −1.2040 to −0.5573 | all within 1.4 standard deviations | +| p_c from crossings of the spanning probabilities, L = 32 and 128; 64 and 256, mean of nine seeds (Newman and Ziff 2000) | 0.59275 | 0.59335 ± 0.00024; 0.59292 ± 0.00023 | +| Fractal dimension of the spanning cluster at p_c, mass ∝ L^D, L = 64 to 256, mean of nine seeds | 91/48 = 1.8958 | 1.8798 ± 0.0020 | + +The exponents come from least-squares slopes of logarithms over L = 8, 16, 32, 64 and 128. They are the 2D Ising +values of Pelissetto and Vicari (2002, sec. 3.5). The Binder cumulant at T_c tends to 1 − V₄/3 with +V₄ = 1.1679229(47) on a periodic square (Salas and Sokal 2000). + +Each tolerance is a fixed number, 3 to 5 standard deviations of the noisiest estimate it covers, plus any +finite-size shift: worked out from published results, except for D, whose shortfall is measured from these runs. +For D, for the two p_c crossings and for the Binder cumulant at L = 16, the two sides are bounded separately, so +the shift widens one side only. Every other check has one tolerance for both sides. Runs at several temperatures +share one tolerance, so the quieter runs are held to it more loosely: ⟨|m|⟩ at T = 2.0 and 2.1 to 17 and 10 +standard deviations, the energy at T = 2.0, 2.1, 2.4 and 2.5 to between 5 and 8. For the Ising runs the standard +deviation is the jackknife error. Over the 120-seed repeat below it matches the scatter between seeds within about +10% on average, but this seed's errors from the runs reweighted to T_c (L = 8 to 128) come out 6% to 17% below that +scatter, so the checks quote both. For percolation it is the standard error of the nine-seed mean. It comes out 9% +above the repeat's scatter of a nine-seed mean (its scatter between seeds over 3) for the crossing of L = 32 and +128, 44% above for 64 and 256 and 20% below for D, so those checks quote both too. `tests/critical.mjs` prints how +far inside its tolerance each result falls. + +Counting standard deviations of the scatter between seeds, beyond any shift, the tightest checks are three. γ/ν +comes to 3.0 after a finite-size bias of +0.0012: over these sizes the slope of the susceptibility on a periodic +square exceeds 7/4 by that much (Caselle, Hasenbusch, Pelissetto and Vicari 2002, sec. 7.2, exact up to L = 17 and +from their expansion beyond). The percolation dimension D comes to 3.1 on each side, beyond its measured shortfall +on the low side (below), against the repeat's scatter of a nine-seed mean, 0.0026. The T_c crossing of L = 64 and +128 comes to 3.5. In a one-off repeat at these tolerances with 120 other sets of seeds (each study seed plus +10000k, k = 1 to 120; not one of the repository's scripts), 119 passed every Ising check and the other missed the +crossing of L = 64 and 128 by 0.0003. The repeat predates the pooled percolation checks, but it saved each seed's +percolation crossings and D. Split into 13 sets of nine seeds, all 13 pass the pooled checks; of 200,000 sets of +nine drawn at random from the 120 seeds, 3 fail, all on D. The closed forms are checked too: the energy against the +derivative of the published free energy (Caselle et al. 2002), to 10⁻⁷; Yang's formula against the same paper's +form, to rounding; the open-edge shift of a crossing, below, against the coefficient Ziff and Newman (2002) give +for sizes L/2 and L, 1.04. + +The two percolation results need a word each, and neither is a disagreement: + +- The crossings sit above p_c, as open edges make them. On a square with open edges, the point where two sizes give + the same spanning probability approaches p_c as L^(−1−1/ν) = L^(−7/4), with ν = 4/3 for percolation (Ziff and + Newman 2002). Their expansion, with the coefficients they use (b₀ = 0.322, a₁ = 0.765), puts the crossing of + L = 32 and 128 0.00040 above p_c and that of L = 64 and 256 0.00012 above. Averaged over nine seeds, the + crossings sit 0.00060 ± 0.00024 and 0.00017 ± 0.00023 above p_c, 0.8 and 0.2 standard errors beyond those shifts. + The study seed alone sits 0.0012 and 0.0013 high, which one seed cannot tell from a fluctuation: single seeds + scatter by 0.0007. The mean of nine can. At L = 64 and 256 it rules out an offset of 0.0012 by more than 4 + standard errors, and the check fails any mean more than 0.0010 above p_c (the shift plus 3.8 standard errors) or + 0.0009 below (3.9). Against the repeat's scatter of a nine-seed mean, 0.00016, those bounds are 5.5 and 5.6 + standard deviations: these nine seeds scatter more than the repeat's 120. The crossing of L = 32 and 128 is + checked more loosely, failing beyond +0.0013 or −0.0009 (3.8 standard errors each way, beyond its shift on the + high side; 4.1 of the repeat's scatter, 0.00022), because its shift is more than three times larger: an offset of + 0.0012 would pass it. The point where the spanning probability at L = 256 is one half, printed but not checked, + averages 0.59277 ± 0.00013. +- The spanning cluster's dimension comes out 1.880, 0.8% low. Single seeds scatter by 0.006 about that, so the + shortfall, 0.016 ± 0.002, is systematic. Averaged over the nine seeds, the slope between successive sizes rises + from 1.861 ± 0.002 (L = 32 to 64) to 1.876 ± 0.003 (64 to 128) and 1.884 ± 0.005 (128 to 256), as corrections to + scaling fade. The first rise, 0.014 ± 0.004, is clear; the second, 0.008 ± 0.008, is one standard error, so nine + seeds do not resolve it. Leaving out L = 32 raises the fitted slope by 0.006 ± 0.001, in all nine seeds. The + shortfall is measured from these runs, not predicted (the 120-seed repeat gives 0.014 ± 0.001), so the check does + not test it. It accepts D from 0.024 below 91/48, the shortfall plus 4.0 standard errors, to 0.008 above, 4.0 + standard errors with no shift, and passes with 0.0079 to spare. Against the repeat's scatter of a nine-seed mean, + 0.0026, each side is 3.1 standard deviations, which makes it one of the three tightest checks. + +## Where the repetition stops + +**Below: the lattice spacing.** Nothing in the model is smaller than one lattice spacing, as nothing in a fluid is +smaller than a molecule. At T_c the power laws are measured from 4 to 64 lattice spacings (G at half the box, for +L = 8 to 128). Over that factor of 16, ⟨|m|⟩ falls by 1.416 ± 0.013 (exact power law 1.414), χ grows by 128 ± 2 +(128) and G(L/2) falls by 2.01 ± 0.03 (2.00). + +**Above: the correlation length.** Off T_c the correlations die exponentially beyond ξ. Above T_c the exact +correlation length along a lattice axis is + + 1/ξ = ln coth K − 2K = 2(K* − K), with K = J/k_BT and the dual coupling K* given by tanh K* = e^(−2K). + +This is the exponential ("true") correlation length, which sets the decay of the spin-spin correlation at large +distance. It is the pole of the large-distance two-point function of Cheng and Wu (1967) along an axis, as written +by Caselle et al. (2002, eqs. 5.1 to 5.4); `tests/critical.mjs` checks the two forms agree. Near T_c it becomes +1/(4(K_c − K)), the amplitude 1/(4K_c) = 0.5673 of Caselle, Hasenbusch, Pelissetto and Vicari (2000). The model +measures ξ from the row-summed correlation, which at large distance falls as cosh((L/2 − r)/ξ) on a ring of L +sites, fitted from r = 1 out to where it has fallen by e². Terms that fall faster add a little at short distance; +they shorten a fit from r = 1 by far less than the error bars here: + +| T (J/k_B) | (T − T_c)/T_c | L | ξ measured | ξ exact | near-T_c form 1/(4(K_c − K)) | +|---|---|---|---|---|---| +| 2.40 | 0.058 | 64 | 9.93 ± 0.21 | 10.23 | 10.41 | +| 2.50 | 0.102 | 64 | 5.90 ± 0.10 | 5.96 | 6.14 | +| 2.75 | 0.212 | 32 | 3.05 ± 0.06 | 3.06 | 3.24 | +| 3.00 | 0.322 | 32 | 2.17 ± 0.04 | 2.14 | 2.33 | +| 4.00 | 0.763 | 16 | 1.11 ± 0.02 | 1.10 | 1.31 | + +At 76% above T_c the nesting has shrunk to about one lattice spacing: there is nothing left to repeat. Below T_c +the correlation length is finite too: exactly 2.19, 3.61 and 9.11 lattice spacings at T = 2.0, 2.1 and 2.2, half +the high-temperature value at the dual coupling (Fujimoto and Otsuka 2020, appendix A). Those runs use L = 64, at +least seven correlation lengths, so finite-size effects are far below the error bars. + +**At T_c: the box.** With ξ infinite, the box is the only upper cutoff, which is why the power laws are measured +against L. The percolation cluster at p_c is self-similar up to the box too, so it fills a shrinking share of it: +in the study seed's runs, 38.9% of the sites at L = 32, 29.8% at L = 256 (an exact L^(−5/48) fall would give +31.3%). + +## Tuned scale invariance against self-organised ranges + +A critical point like this one gives an unlimited scale-free range, but only at one point: the temperature at T_c +and the field at zero, or p at p_c. The range then runs from the lattice spacing to the size of the sample. Heat +the lattice 6% above T_c and the range ends at ten lattice spacings, 76% above at one; below T_c it ends sooner, at +nine lattice spacings only 3% below. Two other scale-free ranges in this repository's subject need no tuning. + +- *Turbulent cascades.* A stirred fluid passes energy from the scale at which it is stirred down to the scale at + which viscosity removes it. In between, only the rate of energy flow matters, and the velocity spectrum falls as + k^(−5/3) (Kolmogorov 1941). The flow sets the range itself: its width grows as the Reynolds number to the power + 3/4 (as reviewed by Alexakis and Biferale 2018). This repository does not yet discuss turbulence elsewhere. +- *Gravitational clustering.* The density ripples of the early universe were close to scale-invariant: their + spectrum is a power law in scale, k^(n_s − 1), with n_s = 0.965 ± 0.004, where n_s = 1 would give ripples of + equal amplitude on every scale (Planck Collaboration 2020). Gravity has grown them into clustering that is + fractal-like on small scales and turns smooth on large ones, as the opening section of the + [README](../README.md#where-the-intuition-holds-and-where-it-breaks) describes (Scrimgeour et al. 2012). + +In both, the range is set by the system's own numbers, not by a dial held at one value. A third possibility, a +system that drives itself to a critical point ("self-organised criticality", Bak, Tang and Wiesenfeld 1987), is not +modelled here. + +Magnets whose spins can turn freely, in a plane or in space, are different again. In three dimensions, below T_c +and in zero field, spin waves (Goldstone modes) keep the transverse spin correlation falling as a power law, 1/r, +at every temperature, so ξ is infinite throughout the ordered phase (Pelissetto and Vicari 2002, secs. 1.3 and +1.6.2): a scale-free range that needs only the zero field, not a tuned temperature. In two dimensions the XY model, +whose spins turn in a plane, has a whole line of critical points below its Kosterlitz-Thouless temperature +(sec. 7.1). In three dimensions, real crystals have lattice anisotropy, which the isotropic models leave out +(sec. 5). It picks out easy directions and, much as a weak field does (sec. 1.6.2), removes the Goldstone +divergence: the transverse susceptibility below T_c becomes finite (sec. 11.3), so there the range is long but +finite. + +## Real fluids + +Water's liquid-vapour critical point is at 647 ± 2 K and 220.64 bar, 22.064 MPa (NIST Chemistry WebBook). +Liquid-vapour critical points belong to the universality class of the three-dimensional Ising model (Pelissetto and +Vicari 2002, sec. 3.1), whose exponents are known from the conformal bootstrap: ν = 0.629971(4) and +η = 0.0362978(20) (Kos, Poland, Simmons-Duffin and Vichi 2016). So a fluid's correlation length grows by +10^0.63 = 4.27 for each tenfold approach to T_c, against 10 for the 2D lattice here. The 2D exponents do not carry +over to fluids. The mechanism does: a correlation length that diverges at one tuned point, cut off below by the +size of a molecule. + +## What the model leaves out + +- Only two dimensions. The 3D exponents that describe real fluids and uniaxial magnets differ (above). +- Only small lattices: up to 128 × 128 for the Ising model and 256 × 256 for percolation. Finite size shows in the + percolation dimension, rising with L, and in the open-edge percolation crossings. +- The correlation length is measured above T_c only, and along the lattice axes only. The exact correlation length + depends on direction (Fujimoto and Otsuka 2020); the axis value is the one checked. +- Wolff clusters are a computational device. Only equilibrium averages are physical, not the sequence of states. +- Runtime is kept near 65 s for each of `npm test`'s critical checks and `critical/table.mjs`, most of it the nine + percolation seeds, which limits the statistics: errors of 0.2% to 3% on the Ising exponents and ξ. + +## Sources + +- A. Alexakis and L. Biferale, *Cascades and transitions in turbulent flows*, Phys. Rep. 767–769, 1 (2018). https://doi.org/10.1016/j.physrep.2018.08.001 (https://arxiv.org/abs/1808.06186) +- P. Bak, C. Tang and K. Wiesenfeld, *Self-organized criticality: an explanation of the 1/f noise*, Phys. Rev. Lett. 59, 381 (1987). Not consulted directly. https://doi.org/10.1103/PhysRevLett.59.381 +- K. Binder, *Finite size scaling analysis of Ising model block distribution functions*, Z. Phys. B 43, 119 (1981). Not consulted directly; the cumulant's definition is as quoted by Salas and Sokal (2000). https://doi.org/10.1007/BF01293604 +- M. Caselle, M. Hasenbusch, A. Pelissetto and E. Vicari, *High-precision estimate of g4 in the 2D Ising model*, J. Phys. A 33, 8171 (2000), sec. 2. https://doi.org/10.1088/0305-4470/33/46/302 (https://arxiv.org/abs/hep-th/0003049) +- M. Caselle, M. Hasenbusch, A. Pelissetto and E. Vicari, *Irrelevant operators in the two-dimensional Ising model*, J. Phys. A 35, 4861 (2002), secs. 2.1, 5.1 and 7.2. https://doi.org/10.1088/0305-4470/35/23/305 (https://arxiv.org/abs/cond-mat/0106372) +- H. Cheng and T. T. Wu, *Theory of Toeplitz determinants and the spin correlations of the two-dimensional Ising model. III*, Phys. Rev. 164, 719 (1967). Not consulted directly; quoted through Caselle et al. (2002). https://doi.org/10.1103/PhysRev.164.719 +- M. P. M. den Nijs, *A relation between the temperature exponents of the eight-vertex and q-state Potts model*, J. Phys. A 12, 1857 (1979). Not consulted directly; credited as in Lawler, Schramm and Werner (2002). https://doi.org/10.1088/0305-4470/12/10/030 +- A. M. Ferrenberg and R. H. Swendsen, *New Monte Carlo technique for studying phase transitions*, Phys. Rev. Lett. 61, 2635 (1988). Not consulted directly; the weight is as written by Ferrenberg, Xu and Landau (2018). https://doi.org/10.1103/PhysRevLett.61.2635 +- A. M. Ferrenberg, J. Xu and D. P. Landau, *Pushing the limits of Monte Carlo simulations for the three-dimensional Ising model*, Phys. Rev. E 97, 043301 (2018), sec. II C. https://doi.org/10.1103/PhysRevE.97.043301 (https://arxiv.org/abs/1806.03558) +- M. Fujimoto and H. Otsuka, *Asymptotic correlation functions in the Q-state Potts model: a universal form for point group C4v*, Phys. Rev. E 102, 032141 (2020), appendices A and B. https://doi.org/10.1103/PhysRevE.102.032141 (https://arxiv.org/abs/1906.01925) +- A. N. Kolmogorov, *The local structure of turbulence in incompressible viscous fluid for very large Reynolds numbers*, Proc. R. Soc. Lond. A 434, 9 (1991), English translation of the 1941 paper in Dokl. Akad. Nauk SSSR 30. Not consulted directly; see Alexakis and Biferale (2018). https://doi.org/10.1098/rspa.1991.0075 +- F. Kos, D. Poland, D. Simmons-Duffin and A. Vichi, *Precision islands in the Ising and O(N) models*, JHEP 08, 036 (2016). https://doi.org/10.1007/JHEP08(2016)036 (https://arxiv.org/abs/1603.04436) +- G. F. Lawler, O. Schramm and W. Werner, *One-arm exponent for critical 2D percolation*, Electron. J. Probab. 7, paper 2 (2002). https://doi.org/10.1214/EJP.v7-101 (https://arxiv.org/abs/math/0108211) +- P. J. Linstrom and W. G. Mallard (eds.), *NIST Chemistry WebBook, NIST Standard Reference Database 69* (retrieved 18 October 2026), water, phase change data. https://doi.org/10.18434/T4D303 +- M. E. J. Newman and R. M. Ziff, *Efficient Monte Carlo algorithm and high-precision results for percolation*, Phys. Rev. Lett. 85, 4104 (2000). https://doi.org/10.1103/PhysRevLett.85.4104 (https://arxiv.org/abs/cond-mat/0005264) +- B. Nienhuis, E. K. Riedel and M. Schick, *Magnetic exponents of the two-dimensional q-state Potts model*, J. Phys. A 13, L189 (1980). Not consulted directly; credited as in Lawler, Schramm and Werner (2002). https://doi.org/10.1088/0305-4470/13/6/005 +- L. Onsager, *Crystal statistics. I. A two-dimensional model with an order-disorder transition*, Phys. Rev. 65, 117 (1944). Not consulted directly; T_c and the energy are checked against Caselle et al. (2002). https://doi.org/10.1103/PhysRev.65.117 +- A. Pelissetto and E. Vicari, *Critical phenomena and renormalization-group theory*, Phys. Rep. 368, 549 (2002), secs. 1.3, 1.6.2, 3.1, 3.5, 5, 7.1 and 11.3. https://doi.org/10.1016/S0370-1573(02)00219-3 (https://arxiv.org/abs/cond-mat/0012164) +- Planck Collaboration, *Planck 2018 results. VI. Cosmological parameters*, A&A 641, A6 (2020). https://doi.org/10.1051/0004-6361/201833910 (https://arxiv.org/abs/1807.06209) +- J. Salas and A. D. Sokal, *Universal amplitude ratios in the critical two-dimensional Ising model on a torus*, J. Stat. Phys. 98, 551 (2000). https://doi.org/10.1023/A:1018611122166 (https://arxiv.org/abs/cond-mat/9904038) +- M. Scrimgeour et al., *The WiggleZ Dark Energy Survey: the transition to large-scale cosmic homogeneity*, MNRAS 425, 116–134 (2012). https://doi.org/10.1111/j.1365-2966.2012.21402.x (https://arxiv.org/abs/1205.6812) +- S. Smirnov and W. Werner, *Critical exponents for two-dimensional percolation*, Math. Res. Lett. 8, 729 (2001). https://doi.org/10.4310/MRL.2001.v8.n6.a4 (https://arxiv.org/abs/math/0109120) +- U. Wolff, *Collective Monte Carlo updating for spin systems*, Phys. Rev. Lett. 62, 361 (1989). Not consulted directly; the add probability is as in Fujimoto and Otsuka (2020, appendix B). https://doi.org/10.1103/PhysRevLett.62.361 +- C. N. Yang, *The spontaneous magnetization of a two-dimensional Ising model*, Phys. Rev. 85, 808 (1952). Not consulted directly; the formula is checked against Caselle et al. (2002). https://doi.org/10.1103/PhysRev.85.808 +- R. M. Ziff and M. E. J. Newman, *Convergence of threshold estimates for two-dimensional percolation*, Phys. Rev. E 66, 016129 (2002). https://doi.org/10.1103/PhysRevE.66.016129 (https://arxiv.org/abs/cond-mat/0203496) diff --git a/critical/model.js b/critical/model.js new file mode 100644 index 0000000..b4579fc --- /dev/null +++ b/critical/model.js @@ -0,0 +1,461 @@ +/* Critical point: a lattice that repeats itself across scales at one temperature, and where the repetition stops. + * Part of https://github.com/Foundation-0/fractals (issue #20). No dependencies. Loads in Node (require) and in a + * browser (window.CRIT). + * + * Ising model: spins s = +-1 on an L x L square lattice with periodic edges, H = -J sum over neighbour pairs s_i s_j, + * J = k_B = 1, so temperatures are in units of J/k_B and lengths in lattice spacings. Updates are Wolff single-cluster + * flips (Wolff 1989): grow a cluster from a random site, adding each aligned neighbour with probability 1 - e^(-2/T), + * the bond probability of the cluster representation (Fujimoto & Otsuka 2020, appendix B), then flip it. Exact + * results for the infinite lattice, with K = 1/T: + * T_c = 2 / ln(1 + sqrt 2) = 2.2692, where sinh 2K = 1 (Onsager 1944). + * Spontaneous magnetisation below T_c: M = (1 - sinh(2K)^-4)^(1/8) (Yang 1952). + * Energy per spin: u = -coth 2K [1 + (2/pi)(2 tanh^2 2K - 1) K1(k)], k = 2 sinh 2K / cosh^2 2K (Onsager 1944); the + * tests check it against the free energy as written by Caselle, Hasenbusch, Pelissetto & Vicari 2002, sec. 2.1. + * Correlation length above T_c, the exponential (true) one along a lattice axis: 1/xi = ln coth K - 2K = 2(K* - K), + * with K* the dual coupling, tanh K* = e^(-2K). It is the decay rate along an axis of the large-distance two-point + * function of Cheng & Wu (1967), as written by Caselle et al. 2002 (eqs. 5.1-5.4): 1/xi = 2 asinh(M_s / 2), + * M_s^2 = 4 (sqrt(1 + tau^2) - 1), tau = (1/sinh 2K - sinh 2K) / 2. Near T_c, xi = A / t with t = (K_c - K) / K_c + * and A = 1/(4 K_c) = 0.5673 (Caselle, Hasenbusch, Pelissetto & Vicari 2000, sec. 2). Below T_c the exponential + * correlation length is 1/(4(K - K*)), half the high-temperature one at the dual coupling (Fujimoto & Otsuka 2020, + * appendix A; near T_c the amplitude ratio 2 is in Pelissetto & Vicari 2002, sec. 3.5). + * Exponents beta = 1/8, nu = 1, eta = 1/4, gamma = 7/4 (Pelissetto & Vicari 2002, sec. 3.5). On a periodic L x L + * lattice at T_c the Binder cumulant 1 - /(3^2) tends to 1 - V4/3 = 0.61069, V4 = 1.1679229(47) + * (Salas & Sokal 2000). + * Site percolation: an L x L square lattice with open edges, each site occupied with probability p. Newman & Ziff's + * (2000) algorithm: occupy sites one at a time in random order, join each to its occupied neighbours with weighted + * union-find, and note when a cluster first touches both the top and the bottom row (spans). Averages at a given p + * follow by weighting each number of occupied sites n with the binomial probability C(N, n) p^n (1 - p)^(N - n). + * p_c = 0.59274621(13) (Newman & Ziff 2000). The incipient spanning cluster has fractal dimension D = 2 - 5/48 = 91/48: + * at p_c the chance that a site connects to distance R falls as R^(-5/48) (proved on the triangular lattice by + * Lawler, Schramm & Werner 2002; it follows, through scaling relations, from exponents predicted by den Nijs 1979 + * and Nienhuis, Riedel & Schick 1980). + * Open edges: R_L(p) = 1/2 + a1 (p - p_c) L^(1/nu) + b0 / L + ..., nu = 4/3 (Ziff & Newman 2002, sec. I), with + * b0 = 0.322 and a1 = 0.765 (their sec. IV). As in their sec. II, the p where R_L1 and R_L2 cross then sits above + * p_c by (b0/a1)(1/L1 - 1/L2) / (L2^(3/4) - L1^(3/4)): +0.00040 for L = 32 and 128, +0.00012 for 64 and 256. + * Random numbers: xoshiro128** seeded through splitmix32, integer arithmetic only, so a seed gives the same run on + * every JavaScript engine. + */ +(function (root) { + 'use strict'; + const TC = 2 / Math.log(1 + Math.SQRT2); + const KC = 1 / TC; + const EXP = { beta: 1 / 8, nu: 1, eta: 1 / 4, gamma: 7 / 4 }; + const PERC = { pc: 0.59274621, D: 91 / 48, oneArm: 5 / 48, nu: 4 / 3, b0: 0.322, a1: 0.765 }; + const TWO32 = 4294967296; + + // ---------- random numbers ---------- + function rng(seed) { + let s = seed >>> 0; + const split = () => { // splitmix32, only to fill the state + s = (s + 0x9e3779b9) >>> 0; + let z = s; + z = Math.imul(z ^ (z >>> 16), 0x85ebca6b); + z = Math.imul(z ^ (z >>> 13), 0xc2b2ae35); + return (z ^ (z >>> 16)) >>> 0; + }; + let a = split(), b = split(), c = split(), d = split(); + if ((a | b | c | d) === 0) a = 1; + return function next() { // xoshiro128**: a uniform integer in [0, 2^32) + const r0 = Math.imul(b, 5), r = Math.imul((r0 << 7) | (r0 >>> 25), 9) >>> 0, t = b << 9; + c ^= a; d ^= b; b ^= c; a ^= d; c ^= t; d = (d << 11) | (d >>> 21); + return r; + }; + } + const below = (next, n) => Math.floor(next() / TWO32 * n); // uniform integer in [0, n), n < 2^21 + + // ---------- exact results ---------- + const yangM = T => (T >= TC ? 0 : Math.pow(1 - Math.pow(Math.sinh(2 / T), -4), 1 / 8)); + // Complete elliptic integral of the first kind, K(k) = pi / (2 AGM(1, sqrt(1 - k^2))). + function ellipticK(k) { + let a = 1, b = Math.sqrt(1 - k * k); + for (let i = 0; i < 40 && Math.abs(a - b) > 1e-16 * a; i++) { const m = (a + b) / 2; b = Math.sqrt(a * b); a = m; } + return Math.PI / (2 * a); + } + function energyExact(T) { // energy per spin, J = 1; at T_c it is -sqrt 2 + const K = 1 / T, s = Math.sinh(2 * K), c = Math.cosh(2 * K), k = 2 * s / (c * c), th = Math.tanh(2 * K); + if (Math.abs(k - 1) < 1e-12) return -Math.SQRT2; + return -(c / s) * (1 + (2 / Math.PI) * (2 * th * th - 1) * ellipticK(k)); + } + const dualK = K => -0.5 * Math.log(Math.tanh(K)); // tanh K* = e^(-2K) + // Exponential correlation length along a lattice axis, above T_c (lattice spacings). + const xiExact = T => { const K = 1 / T; return K >= KC ? Infinity : 1 / (Math.log(1 / Math.tanh(K)) - 2 * K); }; + // The same from Caselle et al. 2002, eqs. 5.1-5.4: the pole of the large-distance two-point function along an axis, + // where 4 sinh^2(1/(2 xi)) = M_s^2. + function xiCaselle(T) { + const s = Math.sinh(2 / T), tau = (1 / s - s) / 2, Ms = Math.sqrt(4 * (Math.sqrt(1 + tau * tau) - 1)); + return 1 / (2 * Math.asinh(Ms / 2)); + } + + // ---------- Ising lattice and Wolff updates ---------- + function neighbours(L) { // right, left, up, down, with periodic edges + const N = L * L, nb = new Int32Array(4 * N); + for (let y = 0; y < L; y++) for (let x = 0; x < L; x++) { + const i = y * L + x; + nb[4 * i] = y * L + (x + 1) % L; nb[4 * i + 1] = y * L + (x + L - 1) % L; + nb[4 * i + 2] = ((y + 1) % L) * L + x; nb[4 * i + 3] = ((y + L - 1) % L) * L + x; + } + return nb; + } + function ising(L, T, seed) { // starts with every spin up + const N = L * L; + return { L, N, T, s: new Int8Array(N).fill(1), nb: neighbours(L), stack: new Int32Array(N), next: rng(seed), + thr: Math.floor((1 - Math.exp(-2 / T)) * TWO32), M: N }; + } + function wolff(sys) { // one cluster flip; returns the cluster's size + const s = sys.s, nb = sys.nb, stack = sys.stack, next = sys.next, thr = sys.thr; + const i = below(next, sys.N), s0 = s[i]; + s[i] = -s0; stack[0] = i; + let top = 1, size = 1; + while (top > 0) { + const j = 4 * stack[--top]; + for (let k = 0; k < 4; k++) { + const n = nb[j + k]; + if (s[n] === s0 && next() < thr) { s[n] = -s0; stack[top++] = n; size++; } + } + } + sys.M -= 2 * s0 * size; + return size; + } + // k cluster flips. The count must be fixed in advance: flipping clusters until N spins have turned over, and measuring + // then, stops more often just after a large cluster and over-weights ordered states (at T_c, L = 16, the Binder + // cumulant comes out 0.629 that way, against 0.610 with a fixed count: studyTrap below, printed by + // critical/table.mjs and checked by tests/critical.mjs). + function flips(sys, k) { for (let i = 0; i < k; i++) wolff(sys); } + function energy(sys) { // total energy + const s = sys.s, nb = sys.nb; let e = 0; + for (let i = 0; i < sys.N; i++) e -= s[i] * (s[nb[4 * i]] + s[nb[4 * i + 2]]); + return e; + } + // Spin-spin correlation G(r) = at distance r along either axis, from one configuration. + function correlation(sys, r) { + const s = sys.s, L = sys.L; let c = 0; + for (let y = 0; y < L; y++) { + const row = y * L, row2 = ((y + r) % L) * L; + for (let x = 0; x < L; x++) c += s[row + x] * (s[row + (x + r) % L] + s[row2 + x]); + } + return c / (2 * sys.N); + } + // Row-summed correlation C(r) = sum over y of G(r, y), r = 0..L/2, from one configuration, added into out. At large r + // it falls as cosh((L/2 - r)/xi) with the exponential correlation length itself, without the 1/sqrt(r) of G(r). At + // small r, states of three or more particles add terms that fall at least three times as fast, which shorten a fit + // from r = 1 by far less than the statistical errors here. + function projected(sys, out) { + const s = sys.s, L = sys.L, col = new Float64Array(L), row = new Float64Array(L); + for (let y = 0; y < L; y++) for (let x = 0; x < L; x++) { const v = s[y * L + x]; col[x] += v; row[y] += v; } + for (let r = 0; r <= L / 2; r++) { + let c = 0; + for (let x = 0; x < L; x++) c += col[x] * col[(x + r) % L] + row[x] * row[(x + r) % L]; + out[r] += c / (2 * L * L); + } + } + // A run: thermalise for `therm` sweeps, then take `sweeps` measurements, one per sweep. A sweep is a fixed number of + // cluster flips, k = N / (mean cluster size during thermalisation), so that about N spins turn over per sweep. + // Per measurement: m = magnetisation per spin (signed), e = energy per spin; with half: G(L/2), L even; with proj: the + // row-summed correlation, summed in `blocks` blocks. + function simulate(L, T, opts) { + const o = Object.assign({ seed: 1, therm: 200, sweeps: 1000, half: false, proj: false, blocks: 20 }, opts); + if (o.half && L % 2) throw new RangeError('simulate: half: true needs an even L'); + const sys = ising(L, T, o.seed); + let flipped = 0, count = 0; + for (let i = 0; i < o.therm; i++) while (flipped < (i + 1) * sys.N) { flipped += wolff(sys); count++; } + const k = Math.max(1, Math.round(count * sys.N / flipped)); + const n = o.sweeps, m = new Float64Array(n), e = new Float64Array(n), g = o.half ? new Float64Array(n) : null; + const proj = o.proj ? Array.from({ length: o.blocks }, () => new Float64Array(L / 2 + 1)) : null; + for (let t = 0; t < n; t++) { + flips(sys, k); + m[t] = sys.M / sys.N; e[t] = energy(sys) / sys.N; + if (g) g[t] = correlation(sys, L / 2); + if (proj) projected(sys, proj[Math.floor(t * o.blocks / n)]); + } + return { L, T, N: sys.N, n, k, m, e, g, proj, blocks: o.blocks, seed: o.seed }; + } + + + // ---------- statistics ---------- + const avg = a => a.reduce((x, y) => x + y, 0) / a.length; + // Jackknife over B blocks: f(b) is the estimate with block b left out of every run (b = -1: nothing left out). + function jackknife(B, f) { + const value = f(-1), part = []; + for (let b = 0; b < B; b++) part.push(f(b)); + const mu = avg(part); + return { value, err: Math.sqrt((B - 1) / B * part.reduce((a, x) => a + (x - mu) * (x - mu), 0)) }; + } + // Samples [lo, hi) of n in block b of B: sample t is in block floor(t B / n), the rule simulate, spanningGrid and + // massSums use to fill their blocks (b = -1: no samples). + const block = (n, b, B) => (b < 0 ? [0, 0] : [Math.ceil(b * n / B), Math.ceil((b + 1) * n / B)]); + // Averages of |m|, m^2, m^4, G(L/2) and e in a run, without block b, reweighted from the run's temperature to T + // (Ferrenberg & Swendsen 1988): each measurement counts with weight exp(-(1/T - 1/T_run) E), the ratio of the two + // Boltzmann weights (as written by Ferrenberg, Xu & Landau 2018, sec. II C). + function moments(run, T, b) { + const [lo, hi] = block(run.n, b === undefined ? -1 : b, run.blocks); + const db = 1 / T - 1 / run.T, N = run.N, m = run.m, e = run.e, g = run.g; + let ebar = 0; + for (let i = 0; i < run.n; i++) if (i < lo || i >= hi) ebar += e[i]; + ebar /= run.n - (hi - lo); + let w0 = 0, wa = 0, w2 = 0, w4 = 0, wg = 0, we = 0; + for (let i = 0; i < run.n; i++) { + if (i >= lo && i < hi) continue; + const w = db === 0 ? 1 : Math.exp(-db * N * (e[i] - ebar)), x = m[i], x2 = x * x; + w0 += w; wa += w * Math.abs(x); w2 += w * x2; w4 += w * x2 * x2; we += w * e[i]; + if (g) wg += w * g[i]; + } + const m2 = w2 / w0, m4 = w4 / w0; + return { abs: wa / w0, m2, m4, chi: N * m2, binder: 1 - m4 / (3 * m2 * m2), g: g ? wg / w0 : NaN, e: we / w0 }; + } + // Root of f between lo and hi by bisection (NaN if f does not change sign). + function bisect(f, lo, hi, steps) { + let flo = f(lo); + if (!(flo * f(hi) < 0)) return NaN; + for (let i = 0; i < (steps || 30); i++) { + const mid = (lo + hi) / 2, fm = f(mid); + if (fm * flo > 0) { lo = mid; flo = fm; } else hi = mid; + } + return (lo + hi) / 2; + } + // Temperature where the Binder cumulants of two runs (a smaller, b larger) cross, without block k. + const binderCrossing = (a, b, lo, hi, k) => + bisect(T => moments(b, T, k).binder - moments(a, T, k).binder, lo, hi, 24); + // Least-squares slope of ln y against ln x. + function logSlope(xs, ys) { + const lx = xs.map(Math.log), ly = ys.map(Math.log), mx = avg(lx), my = avg(ly); + let sxy = 0, sxx = 0; + for (let i = 0; i < lx.length; i++) { sxy += (lx[i] - mx) * (ly[i] - my); sxx += (lx[i] - mx) * (lx[i] - mx); } + return sxy / sxx; + } + // Exponential correlation length from the row-summed correlation at r1 < r2 on a ring of L sites: + // C(r1)/C(r2) = cosh((L/2 - r1)/xi) / cosh((L/2 - r2)/xi), solved for xi by bisection on 1/xi. ln cosh is written + // so that it cannot overflow, as cosh does past 710 (in large boxes, at the top of the bracket). + const lnCosh = y => Math.abs(y) + Math.log1p(Math.exp(-2 * Math.abs(y))) - Math.LN2; + function xiFromProjected(C, L, r1, r2) { + const lr = Math.log(C[r1] / C[r2]), a = L / 2 - r1, b = L / 2 - r2; + if (!(lr > 0)) return NaN; + return 1 / bisect(x => lnCosh(x * a) - lnCosh(x * b) - lr, 1e-6, 20, 60); + } + // Correlation length of a run made with proj: fitted from r1 = 1 out to r2, the last distance at which the row-summed + // correlation is still above e^-2 of its value at r = 1 (about two correlation lengths). Jackknife over its blocks. + function correlationLength(run) { + const L = run.L, tot = new Float64Array(L / 2 + 1); + for (const blk of run.proj) for (let r = 0; r <= L / 2; r++) tot[r] += blk[r]; + let r2 = 2; + while (r2 + 1 < L / 2 && tot[r2 + 1] >= tot[1] * Math.exp(-2)) r2++; + const C = b => (b < 0 ? tot : tot.map((v, r) => v - run.proj[b][r])); + const res = jackknife(run.blocks, b => xiFromProjected(C(b), L, 1, r2)); + return Object.assign(res, { r1: 1, r2, C: Array.from(tot, v => v / run.n) }); + } + + // ---------- site percolation ---------- + // Binomial probabilities C(N, n) p^n (1 - p)^(N - n), n = 0..N, built outward from the most likely n. + function binomial(N, p) { + const pmf = new Float64Array(N + 1), mode = Math.min(N, Math.floor((N + 1) * p)), q = p / (1 - p); + pmf[mode] = 1; + for (let n = mode; n < N; n++) { pmf[n + 1] = pmf[n] * (N - n) / (n + 1) * q; if (pmf[n + 1] < 1e-300) break; } + for (let n = mode; n > 0; n--) { pmf[n - 1] = pmf[n] * n / ((N - n + 1) * q); if (pmf[n - 1] < 1e-300) break; } + let sum = 0; + for (let n = 0; n <= N; n++) sum += pmf[n]; + for (let n = 0; n <= N; n++) pmf[n] /= sum; + return pmf; + } + // `samples` runs on an L x L lattice with open edges. For each: nSpan, the number of occupied sites at which a cluster + // first touches both the top and the bottom row; and, for every n in a window of +-7 standard deviations around p N, + // the mass of the largest spanning cluster (0 if none) and of the largest cluster. + function percolation(L, opts) { + const o = Object.assign({ seed: 1, samples: 100, p: PERC.pc, blocks: 20 }, opts); + const N = L * L, next = rng(o.seed), sd = Math.sqrt(N * o.p * (1 - o.p)); + const n0 = Math.max(1, Math.floor(N * o.p - 7 * sd)), n1 = Math.min(N, Math.ceil(N * o.p + 7 * sd)), w = n1 - n0 + 1; + const nSpan = new Int32Array(o.samples), span = new Float64Array(o.samples * w), big = new Float64Array(o.samples * w); + const order = new Int32Array(N), parent = new Int32Array(N), size = new Int32Array(N), flag = new Uint8Array(N); + const find = x => { while (parent[x] !== x) { parent[x] = parent[parent[x]]; x = parent[x]; } return x; }; + const join = (r, j) => { // merge the cluster of occupied site j into root r (smaller under larger); returns the root + if (parent[j] < 0) return r; + const rj = find(j); + if (rj === r) return r; + if (size[rj] > size[r]) { parent[r] = rj; size[rj] += size[r]; flag[rj] |= flag[r]; return rj; } + parent[rj] = r; size[r] += size[rj]; flag[r] |= flag[rj]; + return r; + }; + for (let t = 0; t < o.samples; t++) { + for (let i = 0; i < N; i++) order[i] = i; + for (let i = N - 1; i > 0; i--) { const j = below(next, i + 1), v = order[i]; order[i] = order[j]; order[j] = v; } + parent.fill(-1); + let spanAt = 0, spanMax = 0, largest = 0; + for (let k = 0; k < N; k++) { + const i = order[k], x = i % L, y = (i - x) / L; + parent[i] = i; size[i] = 1; flag[i] = (y === 0 ? 1 : 0) | (y === L - 1 ? 2 : 0); + let r = i; + if (x > 0) r = join(r, i - 1); + if (x < L - 1) r = join(r, i + 1); + if (y > 0) r = join(r, i - L); + if (y < L - 1) r = join(r, i + L); + if (size[r] > largest) largest = size[r]; + if (flag[r] === 3) { if (!spanAt) spanAt = k + 1; if (size[r] > spanMax) spanMax = size[r]; } + const n = k + 1; + if (n >= n0 && n <= n1) { span[t * w + n - n0] = spanMax; big[t * w + n - n0] = largest; } + if (spanAt && n >= n1) break; + } + nSpan[t] = spanAt; + } + return { L, N, samples: o.samples, p: o.p, n0, n1, w, nSpan, span, big, blocks: o.blocks, seed: o.seed }; + } + // Spanning probability R(p) on a grid of p, per block of samples: R[j][b] for p = ps[j]. A jackknife replicate is the + // total less one block, so every replicate comes from the same arrays. + function spanningGrid(perc, ps) { + const B = perc.blocks; + return ps.map(p => { + const pmf = binomial(perc.N, p), cum = new Float64Array(perc.N + 2); // cum[n] = P(at least n occupied) + for (let n = perc.N; n >= 0; n--) cum[n] = cum[n + 1] + pmf[n]; + const sums = new Float64Array(B); + for (let t = 0; t < perc.samples; t++) sums[Math.floor(t * B / perc.samples)] += cum[perc.nSpan[t]]; + return sums; + }); + } + function gridValue(perc, sums, b) { // spanning probability from block sums, block b left out + const tot = sums.reduce((x, y) => x + y, 0), [lo, hi] = block(perc.samples, b, perc.blocks); + return b < 0 ? tot / perc.samples : (tot - sums[b]) / (perc.samples - (hi - lo)); + } + // How far above p_c open edges put the crossing of R_L1 and R_L2, to leading order (Ziff & Newman 2002; header). + const edgeShift = (L1, L2) => PERC.b0 / PERC.a1 * (1 / L1 - 1 / L2) / + (Math.pow(L2, 1 / PERC.nu) - Math.pow(L1, 1 / PERC.nu)); + // Where f (sampled on the grid ps) changes sign, by linear interpolation between grid points. + function gridRoot(ps, f) { + for (let j = 0; j + 1 < ps.length; j++) { + const a = f(j), c = f(j + 1); + if (a === 0) return ps[j]; + if (a * c < 0) return ps[j] + (ps[j + 1] - ps[j]) * a / (a - c); + } + return NaN; + } + // Mean mass of the largest spanning cluster, given that one spans, and of the largest cluster, at perc.p (canonical: + // the window of occupied-site numbers weighted binomially), with block b of samples left out. + function massSums(perc) { + const P = binomial(perc.N, perc.p), w = perc.w, B = perc.blocks; + const s = { ws: new Float64Array(B), wm: new Float64Array(B), wb: new Float64Array(B), cnt: new Float64Array(B) }; + for (let t = 0; t < perc.samples; t++) { + const k = Math.floor(t * B / perc.samples); + s.cnt[k]++; + for (let j = 0; j < w; j++) { + const pr = P[perc.n0 + j], ms = perc.span[t * w + j]; + if (ms > 0) { s.ws[k] += pr; s.wm[k] += pr * ms; } + s.wb[k] += pr * perc.big[t * w + j]; + } + } + return s; + } + function masses(sums, b) { + const tot = a => a.reduce((x, y) => x + y, 0) - (b < 0 ? 0 : a[b]); + return { span: tot(sums.wm) / tot(sums.ws), big: tot(sums.wb) / tot(sums.cnt) }; + } + + // ---------- the runs the study quotes: tests/critical.mjs checks them, critical/table.mjs prints them ---------- + // Seeds are fixed; each run's seed is the listed seed plus its index. Percolation runs once with each of nine seeds, + // perc.seed and the eight of perc.pool, and the checks use the nine seeds' mean (studyPooled). + const STUDY = { + therm: 200, blocks: 40, + ordered: { L: 64, temps: [2.0, 2.1, 2.2], sweeps: 3000, seed: 101 }, + critical: { T: 2.27, sizes: [[8, 8000], [16, 8000], [32, 8000], [64, 6000], [128, 3000]], dT: 0.003, seed: 201 }, + hot: { runs: [[2.4, 64, 6000], [2.5, 64, 4000], [2.75, 32, 4000], [3.0, 32, 4000], [4.0, 16, 8000]], seed: 301 }, + perc: { sizes: [[32, 4000], [64, 4000], [128, 2000], [256, 800]], seed: 401, + pool: [5010, 5020, 5030, 5040, 5050, 5060, 5070, 5080] }, + trap: { L: 16, sweeps: 40000, seed: 77 }, + }; + // Below T_c: |m| against Yang and e against Onsager. + function studyOrdered() { + const o = STUDY.ordered, B = STUDY.blocks; + return o.temps.map((T, i) => { + const r = simulate(o.L, T, { seed: o.seed + i, therm: STUDY.therm, sweeps: o.sweeps, blocks: B }); + const K = 1 / T; // xiBelow: exponential correlation length, half the high-temperature one at the dual coupling K* + return { T, L: o.L, n: o.sweeps, M: jackknife(B, b => moments(r, T, b).abs), Mexact: yangM(T), + e: jackknife(B, b => moments(r, T, b).e), eExact: energyExact(T), xiBelow: 1 / (4 * (K - dualK(K))) }; + }); + } + // At the critical point: runs at T = 2.27, a round number 0.04% above T_c, reweighted to Onsager's T_c and nearby. + function studyCritical() { + const c = STUDY.critical, B = STUDY.blocks; + const runs = c.sizes.map(([L, n], i) => simulate(L, c.T, { seed: c.seed + i, therm: STUDY.therm, sweeps: n, half: true, blocks: B })); + const Ls = runs.map(r => r.L), at = []; + runs.forEach((r, i) => { at[i] = []; for (let b = -1; b < B; b++) at[i][b + 1] = moments(r, TC, b); }); + const q = (name, b) => runs.map((r, i) => at[i][b + 1][name]); + const per = name => runs.map((r, i) => jackknife(B, b => at[i][b + 1][name])); + const dU = (r, b) => (moments(r, TC - c.dT, b).binder - moments(r, TC + c.dT, b).binder) / (2 * c.dT); // -dU/dT + // Crossings are searched within +-0.6/L of 2.27 (L the smaller size), where reweighting stays within about one + // standard deviation of the sampled energies. + const crossings = runs.slice(1).map((r, i) => ({ L1: runs[i].L, L2: r.L, + T: jackknife(B, b => binderCrossing(runs[i], r, c.T - 0.6 / runs[i].L, c.T + 0.6 / runs[i].L, b)) })); + return { T0: c.T, Ls, n: runs.map(r => r.n), abs: per('abs'), chi: per('chi'), g: per('g'), binder: per('binder'), + betaNu: jackknife(B, b => -logSlope(Ls, q('abs', b))), + gammaNu: jackknife(B, b => logSlope(Ls, q('chi', b))), + eta: jackknife(B, b => -logSlope(Ls, q('g', b))), + invNu: jackknife(B, b => logSlope(Ls, runs.map(r => dU(r, b)))), + binderMean: jackknife(B, b => avg(q('binder', b).slice(1))), // L = 16 and up + crossings }; + } + // Above T_c: the correlation length, and the energy, at five temperatures. + function studyHot() { + const h = STUDY.hot, B = STUDY.blocks; + return h.runs.map(([T, L, n], i) => { + const r = simulate(L, T, { seed: h.seed + i, therm: STUDY.therm, sweeps: n, proj: true, blocks: B }); + return { T, L, n, t: (T - TC) / TC, xi: correlationLength(r), exact: xiExact(T), + e: jackknife(B, b => moments(r, T, b).e), eExact: energyExact(T) }; + }); + } + // Percolation with one seed (the study seed if none is given): spanning probabilities, their crossings, and the + // masses at p_c. + function studyPercolation(seed) { + const P = STUDY.perc, B = STUDY.blocks, ps = [], s0 = seed === undefined ? P.seed : seed; + for (let p = 0.57; p <= 0.615 + 1e-9; p += 0.00025) ps.push(Math.round(p * 1e5) / 1e5); + const runs = P.sizes.map(([L, S], i) => percolation(L, { seed: s0 + i, samples: S, blocks: B })); + const grids = runs.map(r => spanningGrid(r, ps)), sums = runs.map(massSums); + const R = (i, j, b) => gridValue(runs[i], grids[i][j], b); + const cross = (i, k) => ({ L1: runs[i].L, L2: runs[k].L, p: jackknife(B, b => gridRoot(ps, j => R(k, j, b) - R(i, j, b))) }); + const Ls = runs.map(r => r.L), idx = L => Ls.indexOf(L); + return { Ls, samples: runs.map(r => r.samples), ps, + atPc: runs.map(r => { const g = spanningGrid(r, [PERC.pc])[0]; return jackknife(B, b => gridValue(r, g, b)); }), + half: runs.map((r, i) => jackknife(B, b => gridRoot(ps, j => R(i, j, b) - 0.5))), + adjacent: runs.slice(1).map((r, i) => cross(i, i + 1)), + wide: [cross(idx(32), idx(128)), cross(idx(64), idx(256))], + span: sums.map(s => jackknife(B, b => masses(s, b).span)), + big: sums.map(s => jackknife(B, b => masses(s, b).big)), + D: jackknife(B, b => logSlope(Ls.slice(1), sums.slice(1).map(s => masses(s, b).span))), + Dall: jackknife(B, b => logSlope(Ls, sums.map(s => masses(s, b).span))), + Dbig: jackknife(B, b => logSlope(Ls.slice(1), sums.slice(1).map(s => masses(s, b).big))) }; + } + // Percolation pooled over nine independent seeds, the study seed and the eight of STUDY.perc.pool. Each estimate is + // the nine seeds' mean; its error is the standard error of that mean, the scatter between seeds (sd) over 3. Also: + // the slope of ln(mass) against ln L between successive sizes, the change from one of those slopes to the next, and + // how much leaving out L = 32 raises the fit. + function studyPooled() { + const P = STUDY.perc, seeds = [P.seed].concat(P.pool), each = seeds.map(s => studyPercolation(s)), Ls = each[0].Ls; + const pool = f => { + const v = each.map(f), m = avg(v), sd = Math.sqrt(v.reduce((a, x) => a + (x - m) * (x - m), 0) / (v.length - 1)); + return { value: m, err: sd / Math.sqrt(v.length), sd, v }; + }; + // The slope of ln(mass) against ln L from Ls[i] to Ls[i + 1]. + const slope = (r, i) => Math.log(r.span[i + 1].value / r.span[i].value) / Math.log(Ls[i + 1] / Ls[i]); + return { seeds, Ls, each, + wide: each[0].wide.map((c, k) => ({ L1: c.L1, L2: c.L2, p: pool(r => r.wide[k].p.value) })), + half: pool(r => r.half[r.half.length - 1].value), // p where R = 1/2 at the largest L + D: pool(r => r.D.value), Dall: pool(r => r.Dall.value), + local: Ls.slice(1).map((L, i) => ({ L1: Ls[i], L2: L, D: pool(r => slope(r, i)) })), + change: Ls.slice(2).map((L, i) => ({ L1: Ls[i], L2: Ls[i + 1], L3: L, + D: pool(r => slope(r, i + 1) - slope(r, i)) })), + rise: pool(r => r.D.value - r.Dall.value) }; + } + + // The measurement trap: the Binder cumulant at T_c, L = 16, measured after a fixed number of cluster flips (as every + // run above is), against measuring each time the flipped clusters add up to N spins (seed + 1). + function studyTrap() { + const o = STUDY.trap, B = STUDY.blocks, n = o.sweeps; + const fixed = simulate(o.L, TC, { seed: o.seed, therm: STUDY.therm, sweeps: n, blocks: B }); + const sys = ising(o.L, TC, o.seed + 1), m = new Float64Array(n); + for (let i = 0; i < STUDY.therm; i++) { let f = 0; while (f < sys.N) f += wolff(sys); } + for (let t = 0; t < n; t++) { let f = 0; while (f < sys.N) f += wolff(sys); m[t] = sys.M / sys.N; } + const until = { n, N: sys.N, T: TC, m, e: new Float64Array(n), g: null, blocks: B }; + const U = r => jackknife(B, b => moments(r, TC, b).binder); + return { L: o.L, n, fixed: U(fixed), until: U(until) }; + } + + const api = { TC, KC, EXP, PERC, STUDY, rng, yangM, ellipticK, energyExact, dualK, xiExact, xiCaselle, ising, wolff, + flips, energy, correlation, projected, simulate, jackknife, moments, bisect, binderCrossing, logSlope, + xiFromProjected, correlationLength, binomial, percolation, spanningGrid, gridValue, edgeShift, gridRoot, massSums, + masses, studyOrdered, studyCritical, studyHot, studyPercolation, studyPooled, studyTrap }; + if (typeof module !== 'undefined' && module.exports) module.exports = api; else root.CRIT = api; +})(typeof window !== 'undefined' ? window : globalThis); diff --git a/critical/table.mjs b/critical/table.mjs new file mode 100644 index 0000000..73052a9 --- /dev/null +++ b/critical/table.mjs @@ -0,0 +1,107 @@ +// Prints the Monte Carlo numbers quoted in critical/README.md (issue #20) and the exact values beside them. Usage: node +// critical/table.mjs (about 65 s). The runs are the same fixed-seed runs that tests/critical.mjs makes, so the numbers +// match; not every number printed here is checked (critical/README.md says which are). Percolation runs with nine +// seeds, and its checks use their mean: printed here with each seed's values, the standard error of the mean, the +// slopes of the spanning cluster's mass between successive sizes, and how much leaving out L = 32 raises its fit. +// (node critical/table.mjs scatter, which used to print eight of those seeds on their own, now prints the same.) +// No script prints the numbers critical/README.md takes from the one-off repeat with 120 other sets of seeds, or the +// finite-size shifts it works out from published formulas other than the open-edge shifts printed below; the README +// names them. +import { createRequire } from 'node:module'; +const CR = createRequire(import.meta.url)('./model.js'); +const { TC, KC, EXP, PERC } = CR; +const start = Date.now(); +const pm = (j, d) => `${j.value.toFixed(d)} ± ${j.err.toFixed(d)}`; +const col = (s, w) => String(s).padStart(w); + +console.log('Critical point study (issue #20). J = k_B = 1: temperatures in J/k_B, lengths in lattice spacings.\n'); +console.log('Exact values (infinite lattice)'); +console.log(` T_c = 2/ln(1 + sqrt 2) = ${TC.toFixed(6)}, K_c = 1/T_c = ${KC.toFixed(7)}; energy per spin at T_c ${CR.energyExact(TC).toFixed(6)} (-sqrt 2)`); +console.log(` Ising exponents: beta = ${EXP.beta}, nu = ${EXP.nu}, eta = ${EXP.eta}, gamma = ${EXP.gamma}; ` + + `beta/nu = ${EXP.beta / EXP.nu}, gamma/nu = ${EXP.gamma / EXP.nu}`); +console.log(` correlation length above T_c 1/(ln coth K - 2K); near T_c 1/(4(K_c - K)) = ${(1 / (4 * KC)).toFixed(4)}/t, t = (K_c - K)/K_c; ` + + `below T_c 1/(4(K - K*)), K* the dual coupling`); +console.log(` Binder cumulant at T_c on a periodic square, L -> infinity: 1 - 1.1679229/3 = ${(1 - 1.1679229 / 3).toFixed(5)}`); +console.log(` percolation: p_c = ${PERC.pc}, D = 91/48 = ${PERC.D.toFixed(4)} (2 - 5/48); open edges put the crossing of ` + + `R_L1(p) and R_L2(p) above p_c by (b0/a1)(1/L1 - 1/L2)/(L2^(3/4) - L1^(3/4)), b0 = ${PERC.b0}, a1 = ${PERC.a1}: ` + + `+${CR.edgeShift(32, 128).toFixed(5)} for L = 32/128, +${CR.edgeShift(64, 256).toFixed(5)} for 64/256`); +const nu3 = 0.629971; +console.log(` 3D Ising (liquid-vapour critical points): nu = ${nu3}, eta = 0.0362978; a tenfold approach to T_c multiplies xi by ` + + `10^nu = ${Math.pow(10, nu3).toFixed(2)} in 3D, ${Math.pow(10, EXP.nu).toFixed(0)} in 2D`); + +console.log('\nBelow T_c (Wolff clusters, L = 64, 3000 measurements each)'); +console.log(col('T', 6) + col('<|m|>', 22) + col('Yang', 10) + col('energy', 22) + col('Onsager', 11) + col('xi (exact)', 12)); +for (const r of CR.studyOrdered()) { + console.log(col(r.T.toFixed(2), 6) + col(pm(r.M, 5), 22) + col(r.Mexact.toFixed(5), 10) + col(pm(r.e, 5), 22) + + col(r.eExact.toFixed(5), 11) + col(r.xiBelow.toFixed(2), 12)); +} + +const c = CR.studyCritical(); +console.log(`\nAt T_c (runs at T = ${c.T0}, reweighted to T_c)`); +console.log(col('L', 5) + col('measurements', 14) + col('<|m|>', 18) + col('chi = N', 18) + col('G(L/2)', 18) + col('Binder U', 18)); +c.Ls.forEach((L, i) => console.log(col(L, 5) + col(c.n[i], 14) + col(pm(c.abs[i], 4), 18) + col(pm(c.chi[i], c.chi[i].value > 1000 ? 0 : 1), 18) + + col(pm(c.g[i], 4), 18) + col(pm(c.binder[i], 4), 18))); +console.log(` slopes over L = ${c.Ls.join(', ')}: beta/nu = ${pm(c.betaNu, 4)}, gamma/nu = ${pm(c.gammaNu, 4)}, eta = ${pm(c.eta, 4)}, ` + + `1/nu = ${pm(c.invNu, 3)}`); +console.log(` Binder cumulant at T_c, mean of L = 16 to 128: ${pm(c.binderMean, 4)}`); +console.log(' Binder crossings: ' + c.crossings.map(x => `L = ${x.L1} and ${x.L2}: T = ${pm(x.T, 4)}`).join('; ')); +const span = c.Ls[c.Ls.length - 1] / c.Ls[0]; +// Ratio of two sizes' values, with the two runs' independent errors added in quadrature. +const ratio = (a, b) => { const value = a.value / b.value; return { value, err: value * Math.hypot(a.err / a.value, b.err / b.value) }; }; +const top = c.Ls.length - 1, rm = ratio(c.abs[0], c.abs[top]), rc = ratio(c.chi[top], c.chi[0]), rg = ratio(c.g[0], c.g[top]); +const rel = r => (r.err / r.value * 100).toFixed(1) + '%'; +console.log(` from L = ${c.Ls[0]} to ${c.Ls[top]} (x${span}): <|m|> falls x${pm(rm, 3)}, chi grows x${pm(rc, 0)}, G(L/2) falls x${pm(rg, 2)} ` + + `(exact power laws: x${Math.pow(span, 1 / 8).toFixed(3)}, x${Math.pow(span, 7 / 4).toFixed(0)}, x${Math.pow(span, 1 / 4).toFixed(2)}; ` + + `statistical errors ${rel(rm)}, ${rel(rc)}, ${rel(rg)})`); + +// The trap in measuring Wolff runs: a fixed number of cluster flips per measurement (as the model does), against +// flipping clusters until they add up to L^2 spins and measuring then. L = 16 at T_c, 40000 measurements each. +const trap = CR.studyTrap(); +console.log(` measuring after a fixed number of cluster flips (the model), L = ${trap.L}: U = ${pm(trap.fixed, 4)}; ` + + `after flips adding up to L^2 spins: U = ${pm(trap.until, 4)}`); + +console.log('\nAbove T_c: the correlation length (row-summed correlation, fitted from r = 1 to where it has fallen by e^2)'); +console.log(col('T', 6) + col('t', 7) + col('L', 5) + col('fit r', 8) + col('xi measured', 16) + col('exact', 8) + col('off', 8) + + col('1/4(Kc-K)', 11) + col('energy', 20) + col('Onsager', 10)); +for (const r of CR.studyHot()) { + console.log(col(r.T.toFixed(2), 6) + col(r.t.toFixed(3), 7) + col(r.L, 5) + col(`${r.xi.r1}-${r.xi.r2}`, 8) + col(pm(r.xi, 2), 16) + + col(r.exact.toFixed(2), 8) + col(((r.xi.value / r.exact - 1) * 100).toFixed(1) + '%', 8) + + col((1 / (4 * (KC - 1 / r.T))).toFixed(2), 11) + col(pm(r.e, 4), 20) + col(r.eExact.toFixed(4), 10)); +} + +const pool = CR.studyPooled(), p = pool.each[0], seeds = pool.seeds; +console.log(`\nSite percolation, open edges, spanning top to bottom (Newman-Ziff runs; masses at p_c), study seed ${seeds[0]}`); +console.log(col('L', 5) + col('samples', 9) + col('R(p_c)', 18) + col('p where R = 1/2', 20) + col('spanning cluster', 20) + col('largest cluster', 20)); +p.Ls.forEach((L, i) => console.log(col(L, 5) + col(p.samples[i], 9) + col(pm(p.atPc[i], 3), 18) + col(pm(p.half[i], 5), 20) + + col(pm(p.span[i], 0), 20) + col(pm(p.big[i], 0), 20))); +console.log(' crossings of R_L(p): ' + [...p.adjacent, ...p.wide].map(x => `${x.L1}/${x.L2}: ${pm(x.p, 5)}`).join('; ')); +console.log(` spanning-cluster mass ~ L^D: D = ${pm(p.D, 4)} over L = ${p.Ls.slice(1).join(', ')}, ${pm(p.Dall, 4)} over L = ${p.Ls.join(', ')}; ` + + `largest cluster ${pm(p.Dbig, 4)} over L = ${p.Ls.slice(1).join(', ')}`); +const share = i => p.span[i].value / (p.Ls[i] * p.Ls[i]) * 100, last = p.Ls.length - 1; +console.log(` share of the sites in the spanning cluster: ${share(0).toFixed(1)}% at L = ${p.Ls[0]}, ${share(last).toFixed(1)}% at ` + + `L = ${p.Ls[last]} (an exact L^-5/48 fall would give ${(share(0) * Math.pow(p.Ls[last] / p.Ls[0], -PERC.oneArm)).toFixed(1)}%)`); + +// The same runs with nine seeds (each seed's runs use it plus 0 to 3). The checks use the mean over the nine seeds, +// with the standard error of that mean: the scatter between seeds (standard deviation) over 3. +console.log(`\nPercolation pooled over nine seeds (${seeds[0]}, then ${seeds.slice(1, 3).join(', ')}, ..., ${seeds[seeds.length - 1]}); ` + + 'each seed with its jackknife error, then the mean with its standard error'); +const cols = [['p_c, L = 32/128', r => r.wide[0].p, pool.wide[0].p, PERC.pc, 5, CR.edgeShift(32, 128)], + ['p_c, L = 64/256', r => r.wide[1].p, pool.wide[1].p, PERC.pc, 5, CR.edgeShift(64, 256)], + ['D, L = 64-256', r => r.D, pool.D, PERC.D, 4], ['p(R = 1/2), L = 256', r => r.half[last], pool.half, PERC.pc, 5], + ['D, L = 32-256', r => r.Dall, pool.Dall, PERC.D, 4]]; +console.log(col('seed', 6) + cols.map(c => col(c[0], 22)).join('')); +pool.each.forEach((r, i) => console.log(col(seeds[i], 6) + cols.map(c => col(pm(c[1](r), c[4]), 22)).join(''))); +console.log(col('mean', 6) + cols.map(c => col(pm(c[2], c[4]), 22)).join('') + '\n'); +for (const [name, f, m, exact, d, shift] of cols) { + const jk = pool.each.reduce((a, r) => a + f(r).err, 0) / pool.each.length; + console.log(` ${name}: mean ${pm(m, d)}, exact ${exact.toFixed(d)}, mean - exact ${(m.value - exact).toFixed(d)}` + + (shift ? ` (open-edge shift +${shift.toFixed(d)})` : '') + `; scatter between seeds ${m.sd.toFixed(d)}, mean jackknife error ${jk.toFixed(d)}`); +} +// How the slope of ln(mass) against ln L changes with L: slopes between successive sizes, and how much leaving out +// L = 32 raises the fitted slope, seed by seed (mean ± standard error over the nine seeds). +console.log('\n spanning-cluster mass, slopes between successive sizes: ' + pool.local.map(x => `L = ${x.L1}-${x.L2}: ${pm(x.D, 3)}`).join(', ')); +console.log(' change from one of those slopes to the next, seed by seed: ' + pool.change.map(x => + `L = ${x.L1}-${x.L2} to ${x.L2}-${x.L3}: ${pm(x.D, 3)}`).join(', ')); +console.log(` D over L = 64-256 less D over L = 32-256: ${pm(pool.rise, 3)}, positive for ${pool.rise.v.filter(x => x > 0).length} of ` + + `${pool.rise.v.length} seeds`); +console.log(`\nruntime ${((Date.now() - start) / 1000).toFixed(1)} s on Node ${process.versions.node}`); diff --git a/tests/critical.mjs b/tests/critical.mjs new file mode 100644 index 0000000..1b09d67 --- /dev/null +++ b/tests/critical.mjs @@ -0,0 +1,194 @@ +// Checks the critical-point study (critical/model.js, issue #20) against exact results: Onsager's T_c and energy, +// Yang's magnetisation, the exact correlation length, the 2D Ising exponents, the Binder cumulant at T_c, the +// measurement trap in cluster runs, Newman and Ziff's percolation threshold and the 91/48 dimension. Run: npm test (or +// node tests/critical.mjs). +// Each check states the source, the exact value, the model's value and the tolerance. The Monte Carlo runs use fixed +// seeds and integer-only random numbers, so every run, on every Node version, prints the same numbers. Ising error +// bars are jackknife estimates over 40 blocks. The percolation checks use the mean over nine seeds, the study seed and +// eight others, with the standard error of that mean as error bar: the scatter between the nine seeds over 3. Each +// tolerance is a fixed number, 3 to 5 standard deviations of the noisiest estimate it covers, plus any finite-size +// shift: worked out from published results, except for D, whose shortfall is measured from these runs. For D, the two +// p_c crossings and the Binder cumulant at L = 16 the two sides are bounded separately, so the shift widens one side +// only; every other check has one tolerance for both sides. A sigma count below is (tolerance - shift) / sigma, with +// sigma and shift as quoted, on the side the shift points to; on the other side it is tolerance / sigma and allows no +// shift. Runs at several temperatures share one tolerance, so the quieter runs are held to it more loosely: |m| at +// T = 2.0 and 2.1 to 17 and 10 sigma, the energy at T = 2.0, 2.1, 2.4 and 2.5 to between 5 and 8 sigma. For the Ising +// runs the standard deviation is the jackknife error. Over the 120 repeat seeds below it matches the scatter between +// seeds within about 10% on average, but this seed's errors from the runs reweighted to T_c (L = 8 to 128) come out 6% +// to 17% below that scatter, so those checks also quote the scatter. For percolation it is the standard error of the +// nine-seed mean. It comes out 9% above the repeat's scatter of a nine-seed mean (its scatter between seeds over 3) +// for the crossing of L = 32 and 128, 44% above for 64 and 256 and 20% below for D, so those checks also quote that +// scatter. Against the seed-to-seed scatter the tightest checks are gamma/nu (3.0 sigma after its +0.0012 finite-size +// bias), D (3.1 sigma on each side, beyond its measured shortfall on the low side) and the Binder crossing of L = 64 +// and 128 (3.5 sigma). In a one-off repeat at these tolerances with 120 other sets of seeds (each study seed plus +// 10000k, k = 1 to 120; not one of the repository's scripts), 119 passed every Ising check; the other missed the +// crossing of L = 64 and 128 by 0.0003. The repeat predates the pooled percolation checks, but it saved each seed's +// percolation crossings and D: split into 13 sets of nine seeds, all 13 pass the pooled checks, and of 200000 sets of +// nine drawn at random from the 120, 3 fail, all on D. Each line prints the margin it passes by. +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); +const CR = require('../critical/model.js'); +const { TC, KC, EXP, PERC } = CR; +const start = Date.now(); + +let fails = 0; +const fmt = (x, d) => x.toFixed(d === undefined ? 4 : d); +const sci = x => x.toExponential(1); +function check(name, ok, detail, src) { + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}\n ${detail} ${src}`); + if (!ok) fails++; +} +// A Monte Carlo estimate {value, err} against an exact value: passes if exact - lo <= model <= exact + hi, where tol is +// one number (lo = hi = tol) or [lo, hi], and the error bar is finite (a jackknife replicate can fail and give NaN). +function near(name, est, want, tol, src, why, d) { + const [lo, hi] = Array.isArray(tol) ? tol : [tol, tol], dev = est.value - want; + const finite = Number.isFinite(est.err), ok = finite && dev >= -lo && dev <= hi; + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}\n model ${fmt(est.value, d)} ± ${fmt(est.err, d)} exact ${fmt(want, d)} ` + + `(within ${lo === hi ? fmt(hi, d) : `-${fmt(lo, d)}/+${fmt(hi, d)}`}; off by ${fmt(dev, d)} = ${(dev / est.err).toFixed(1)} sigma; ` + + `margin ${fmt(Math.min(hi - dev, dev + lo), d)}) ${src}` + (finite ? '' : '\n the error bar is not finite') + (why ? `\n ${why}` : '')); + if (!ok) fails++; +} +// The same with a relative tolerance. +function nearRel(name, est, want, rel, src, why) { + const dev = est.value / want - 1, finite = Number.isFinite(est.err), ok = finite && Math.abs(dev) <= rel; + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}\n model ${est.value.toFixed(3)} ± ${est.err.toFixed(3)} exact ${want.toFixed(3)} ` + + `(within ${(rel * 100).toFixed(0)}%; off by ${(dev * 100).toFixed(1)}% = ${((est.value - want) / est.err).toFixed(1)} sigma; ` + + `margin ${((rel - Math.abs(dev)) * 100).toFixed(1)} points) ${src}` + (finite ? '' : '\n the error bar is not finite') + + (why ? `\n ${why}` : '')); + if (!ok) fails++; +} + +// 1. The closed forms themselves (no Monte Carlo): these test the code against the published formulas. +const ONS = 'Onsager 1944', YANG = 'Yang 1952', CHPV = 'Caselle, Hasenbusch, Pelissetto & Vicari 2002 (arXiv:cond-mat/0106372)'; +check('Critical temperature: sinh(2/T_c) = 1, T_c = 2/ln(1 + sqrt 2)', Math.abs(Math.sinh(2 / TC) - 1) < 1e-14 && Math.abs(KC - 0.4406868) < 1e-7, + `T_c = ${TC.toFixed(6)}, 1/T_c = ${KC.toFixed(7)} (published 0.4406868...)`, `${ONS}; ${CHPV} sec. 2.1`); +// Energy per spin u = -dF/dK from the free energy F(K) = (1/2) ln(2 cosh^2 2K) + int_0^pi dtheta/(2 pi) +// ln[1 + (1 - cos^2 theta / (1 + tau^2))^(1/2)], tau = (1/sinh 2K - sinh 2K)/2, integrated and differentiated numerically. +function freeEnergy(K) { + const s = Math.sinh(2 * K), tau = (1 / s - s) / 2, n = 20000; let I = 0; + for (let i = 0; i < n; i++) { const c = Math.cos((i + 0.5) * Math.PI / n); I += Math.log(1 + Math.sqrt(1 - c * c / (1 + tau * tau))); } + return 0.5 * Math.log(2 * Math.cosh(2 * K) ** 2) + I / (2 * n); +} +const uDiff = [2.0, 2.5, 3.0, 4.0].map(T => { const K = 1 / T, h = 1e-4; return Math.abs(-(freeEnergy(K + h) - freeEnergy(K - h)) / (2 * h) - CR.energyExact(T)); }); +check("Onsager's energy (elliptic-integral form) equals -dF/dK of the published free energy", Math.max(...uDiff) < 1e-6, + `largest difference ${sci(Math.max(...uDiff))} at T = 2, 2.5, 3, 4 (numerical derivative); at T_c u = ${CR.energyExact(TC).toFixed(6)} = -sqrt 2`, `${ONS}; ${CHPV} sec. 2.1`); +const mDiff = [1.5, 2.0, 2.2, 2.26].map(T => { const s = Math.sinh(2 / T), tau = (1 / s - s) / 2, k = (Math.sqrt(1 + tau * tau) + tau) ** 2; + return Math.abs(CR.yangM(T) / Math.pow(1 - k * k, 1 / 8) - 1); }); +check("Yang's magnetisation (1 - sinh(2/T)^-4)^(1/8) equals the published (1 - k^2)^(1/8)", Math.max(...mDiff) < 1e-12, + `largest relative difference ${sci(Math.max(...mDiff))} at T = 1.5, 2, 2.2, 2.26`, `${YANG}; ${CHPV} sec. 2.1`); +const xDiff = [2.3, 2.4, 2.5, 3, 4, 10].map(T => Math.abs(CR.xiExact(T) / CR.xiCaselle(T) - 1)); +check('Correlation length 1/(ln coth K - 2K) equals the pole of the large-distance two-point function along an axis', Math.max(...xDiff) < 1e-10, + `largest relative difference ${sci(Math.max(...xDiff))} at T = 2.3 to 10 (4 sinh^2(1/2 xi) = M_s^2)`, `Cheng & Wu 1967, as written in ${CHPV} eqs. 5.1-5.4`); +const t6 = 1e-6, amp = t6 * CR.xiExact(1 / (KC * (1 - t6))); +check('Near T_c the same correlation length is A/t with A = 1/(4 K_c) = 0.56729632855 (t = (K_c - K)/K_c)', Math.abs(amp / 0.56729632855 - 1) < 1e-5, + `t xi = ${amp.toFixed(8)} at t = 1e-6: it is the exponential correlation length, not the second-moment one (A = 0.5670683)`, + 'Caselle, Hasenbusch, Pelissetto & Vicari 2000 (arXiv:hep-th/0003049), sec. 2'); +// Percolation on a square with open edges: where the spanning probabilities of two sizes cross, from Ziff & Newman's +// expansion of R_L(p) (critical/model.js header), against the coefficient they quote for sizes L/2 and L. +const ZN = 'Ziff & Newman 2002 (arXiv:cond-mat/0203496)', coef = CR.edgeShift(32, 64) * Math.pow(64, 7 / 4); +check('Open edges shift the crossing of R_L1(p) and R_L2(p) above p_c by (b0/a1)(1/L1 - 1/L2)/(L2^(3/4) - L1^(3/4)); for ' + + "L1 = L/2 and L2 = L that is Ziff & Newman's 1.04 L^-7/4", Math.abs(coef - 1.04) < 0.005, + `coefficient ${coef.toFixed(3)} from their b0 = ${PERC.b0} and a1 = ${PERC.a1}; the shifts used in section 6 below: ` + + `+${fmt(CR.edgeShift(32, 128), 5)} for L = 32 and 128, +${fmt(CR.edgeShift(64, 256), 5)} for 64 and 256`, `${ZN}, secs. I, II and IV`); +const r1 = CR.rng(1); +check('Random numbers are integer-only xoshiro128**: seed 1 starts 2442144158, 3238099751, 3819917871', + [2442144158, 3238099751, 3819917871].every(v => r1() === v), 'same on every engine, so every run below is reproducible', 'model'); + +// 2. Below T_c: magnetisation and energy (L = 64; the correlation length is at most 9.1 lattice spacings, so finite-size +// effects, of relative order exp(-L/xi) < 1e-3, stay below the statistical errors). Tolerances: 0.006 in |m| is +// 3.8 sigma of the noisiest run (T = 2.2, sigma = 0.0016); 0.005 in energy is 3.8 sigma of the noisiest (sigma = 0.0013). +// The quieter runs are held to them more loosely: |m| at T = 2.0 and 2.1 to 17 and 10 sigma (sigma = 0.00035 and +// 0.00060), the energy to 7.6 and 5.2 (0.00066 and 0.00096). +const ordered = CR.studyOrdered(); +for (const r of ordered) near(`Spontaneous magnetisation <|m|> at T = ${r.T} (L = ${r.L}, ${r.n} measurements)`, r.M, r.Mexact, 0.006, YANG, '', 5); +for (const r of ordered) near(`Energy per spin at T = ${r.T}`, r.e, r.eExact, 0.005, ONS, '', 5); + +// 3-4. At the critical point: L = 8 to 128, runs at T = 2.27 reweighted to T_c (Ferrenberg & Swendsen 1988). +const crit = CR.studyCritical(); +const cross = (L1) => crit.crossings.find(c => c.L1 === L1); +near(`T_c from the crossing of the Binder cumulants of L = 32 and 64`, cross(32).T, TC, 0.010, ONS, + 'tolerance 4.5 sigma (sigma = 0.0022), 3.8 sigma of the seed-to-seed scatter (0.0026). The leading correction to U at T_c is ' + + 'the L^-7/4 analytic background of chi (Salas & Sokal 2000, sec. 4.1; Caselle et al. 2002, sec. 7.2, D0 = -0.104), so the ' + + 'crossing approaches T_c as L^-(1/nu + 7/4) = L^-11/4: about 1.3e-4 below T_c here, from the slope -dU/dT = 0.035 L of these ' + + 'runs and an L^-7/4 amplitude set by Salas & Sokal\'s measured V4(16) = 1.16586(38), which puts U(16) 0.0007 above its limit ' + + '(their fit with the exponent free, Delta = 2.01 +- 0.22 and B4 = -0.48 +- 0.23, gives 1.0e-4); at most about 6e-4 scaling ' + + 'the noisier L = 8/16 shift (-0.026 +- 0.008) the same way; far inside sigma', 4); +near(`T_c from the crossing of the Binder cumulants of L = 64 and 128`, cross(64).T, TC, 0.007, ONS, + 'tolerance 4.1 sigma (sigma = 0.0017), 3.5 sigma of the seed-to-seed scatter (0.0020); the L^-11/4 shift above is about 2e-5 here, ' + + 'at most 1e-4', 4); +near('Binder cumulant at T_c, mean of L = 16 to 128', crit.binderMean, 1 - 1.1679229 / 3, 0.005, + 'Salas & Sokal 2000: 1 - V4/3, V4 = 1.1679229(47)', 'tolerance 4.5 sigma (sigma = 0.0011), 4.2 sigma of the seed-to-seed scatter ' + + '(0.0012); 4.3 and 4.0 after the mean\'s +0.00024 finite-size shift, most of it from L = 16, which sits 0.0007 above its limit ' + + '(Salas & Sokal\'s V4(L); the 120 repeat seeds average +0.0002 +- 0.0001); the sizes agree with each other within their errors'); +const Ls = crit.Ls.join(', '); +near(`beta/nu from <|m|> ~ L^(-beta/nu) at T_c, least squares over L = ${Ls}`, crit.betaNu, EXP.beta / EXP.nu, 0.012, + 'Pelissetto & Vicari 2002, sec. 3.5: beta = 1/8, nu = 1', 'tolerance 4.6 sigma (sigma = 0.0026), 3.9 sigma of the seed-to-seed scatter (0.0031)'); +near(`gamma/nu from chi = N ~ L^(gamma/nu) at T_c, same sizes`, crit.gammaNu, EXP.gamma / EXP.nu, 0.016, + 'Pelissetto & Vicari 2002, sec. 3.5: gamma = 7/4', 'tolerance 4 sigma (sigma = 0.0040), 3.3 sigma of the seed-to-seed scatter (0.0049); ' + + '3.7 and 3.0 after its +0.0012 finite-size bias, the slope of the torus chi_L over these sizes less 7/4 (Caselle et al. 2002, ' + + 'sec. 7.2: exact up to L = 17, their expansion beyond, with corrections of relative order L^-7/4; the 120 repeat seeds average ' + + '+0.0015 +- 0.0004)'); +near(`eta from G(L/2) ~ L^-eta at T_c, same sizes`, crit.eta, EXP.eta, 0.020, + 'Pelissetto & Vicari 2002, sec. 3.5: eta = 1/4', 'tolerance 4.3 sigma (sigma = 0.0047), 3.7 sigma of the seed-to-seed scatter (0.0054); ' + + 'G(L/2) is the spin-spin correlation at half the box, along either axis'); +near(`1/nu from the slope of the Binder cumulant, -dU/dT ~ L^(1/nu), at T_c`, crit.invNu, 1 / EXP.nu, 0.13, + 'Pelissetto & Vicari 2002, sec. 3.5: nu = 1', 'tolerance 4.1 sigma (sigma = 0.032), 3.7 sigma of the seed-to-seed scatter (0.035); ' + + 'slope from reweighting to T_c -+ 0.003'); + +// 4b. The measurement trap (critical/README.md, "A trap in measuring cluster runs"): L = 16 at T_c, 40000 measurements, +// measured after a fixed number of cluster flips (as every run here is), against each time the flipped clusters add +// up to L^2 spins. +const trap = CR.studyTrap(); +near(`Binder cumulant at T_c, L = ${trap.L}, measured after a fixed number of cluster flips (${trap.n} measurements)`, trap.fixed, + 1 - 1.1679229 / 3, [0.0035, 0.004], 'Salas & Sokal 2000: 1 - V4/3', 'tolerance: at L = 16 U sits +0.0007 above its limit ' + + '(Salas & Sokal\'s measured V4(16) = 1.16586(38)), so the high side is 4.1 sigma (sigma = 0.0008) above that shift and the low ' + + 'side, 4.4 sigma, allows none; 4.4 and 4.7 sigma of the seed-to-seed scatter (0.00075)'); +const gap = trap.until.value - trap.fixed.value, gapErr = Math.hypot(trap.until.err, trap.fixed.err); +check('Measuring each time the flipped clusters add up to L^2 spins over-weights ordered states: the Binder cumulant comes out higher', + gap / gapErr > 10, `U = ${fmt(trap.until.value)} ± ${fmt(trap.until.err)} that way, against ${fmt(trap.fixed.value)} ± ` + + `${fmt(trap.fixed.err)} with a fixed count: ${(gap / gapErr).toFixed(1)} combined sigma apart (must exceed 10)`, 'model'); + +// 5. Above T_c: the correlation length falls to about one lattice spacing as the temperature rises. Each run is at least +// six correlation lengths across. Tolerance 8%: 3.5 sigma of the noisiest run (T = 4, sigma = 2.3%), 3.8 sigma of +// its seed-to-seed scatter (2.1%). The energy's 0.005 holds the quieter runs at T = 2.4 and 2.5 to about 7 and 6 +// sigma (sigma = 0.0007 and 0.0008). +const hot = CR.studyHot(); +for (const r of hot) nearRel(`Correlation length at T = ${r.T}, (T - T_c)/T_c = ${r.t.toFixed(3)} (L = ${r.L}, fitted from r = ${r.xi.r1} to ${r.xi.r2})`, + r.xi, r.exact, 0.08, `1/xi = ln coth(1/T) - 2/T: ${CHPV} eqs. 5.1-5.4`); +const eHot = hot.map(r => ({ T: r.T, dev: r.e.value - r.eExact, err: r.e.err })); +check('Energy per spin at the same five temperatures, within 0.005 (3.7 sigma of the noisiest, T = 4, sigma = 0.00136; ' + + '3.6 sigma of the seed-to-seed scatter at T = 2.75, 0.0014)', eHot.every(x => Number.isFinite(x.err) && Math.abs(x.dev) <= 0.005), + eHot.map(x => `T = ${x.T}: ${(x.dev + hot.find(r => r.T === x.T).eExact).toFixed(4)}, exact ${hot.find(r => r.T === x.T).eExact.toFixed(4)}, ` + + `off by ${x.dev.toFixed(4)} (${(x.dev / x.err).toFixed(1)} sigma)`).join('; ') + + `; margin ${(0.005 - Math.max(...eHot.map(x => Math.abs(x.dev)))).toFixed(4)}`, ONS); + +// 6. Site percolation, open edges, spanning top to bottom. The crossings and D are means over nine independent seeds +// (the study seed and the eight of STUDY.perc.pool), and sigma is the standard error of the mean: the scatter +// between the nine seeds over 3. The tolerances are fixed numbers, set once from that scatter. The open-edge shifts +// are the ones checked in section 1. The details also quote the scatter of a nine-seed mean in the 120-seed repeat. +const NZ = 'Newman & Ziff 2000: p_c = 0.59274621(13)'; +const pool = CR.studyPooled(), n = pool.seeds.length; +for (const c of pool.wide) near(`p_c from the crossing of the spanning probabilities of L = ${c.L1} and ${c.L2}, mean of ${n} seeds`, c.p, + PERC.pc, c.L1 === 32 ? [0.0009, 0.0013] : [0.0009, 0.0010], NZ, c.L1 === 32 + ? 'tolerance: sigma = 0.00024; the low side is 3.8 sigma and allows no shift, the high side 3.8 sigma above the ' + + 'open-edge shift, +0.00040, more than three times that of L = 64 and 256. Each side is 4.1 sigma of the ' + + 'seed-to-seed scatter of a nine-seed mean (0.00022). A mean more than 0.0013 above p_c or 0.0009 below fails, so ' + + 'an offset of 0.0012 would pass here: with its larger shift this crossing is checked more loosely, and the ' + + 'crossing of L = 64 and 256 is the check that rules such an offset out. The mean sits 0.8 sigma above the shift' + : 'tolerance: sigma = 0.00023; the low side is 3.9 sigma and allows no shift, the high side 3.8 sigma above the ' + + 'open-edge shift, +0.00012; 5.6 and 5.5 sigma of the seed-to-seed scatter of a nine-seed mean (0.00016), as these ' + + 'nine seeds scatter more than the repeat\'s 120. A mean more than 0.0010 above p_c or 0.0009 below fails, so an ' + + 'offset of 0.0012 fails (the study seed alone sits 0.0013 high). The mean sits 0.2 sigma above the shift', 5); +near(`Fractal dimension of the spanning cluster at p_c: mass ~ L^D, least squares over L = ${pool.Ls.slice(1).join(', ')}, mean of ${n} seeds`, + pool.D, PERC.D, [0.024, 0.008], 'D = 2 - 5/48 = 91/48: Lawler, Schramm & Werner 2002 (one-arm exponent 5/48)', + 'tolerance: the slope between successive sizes rises with L (1.861, 1.876 and 1.884 from L = 32 to 256, means of the ' + + 'nine seeds), so a fit over L = 64 to 256 falls short of 91/48. The shortfall, 0.016, is measured from these runs, not ' + + 'predicted (the 120-seed repeat in the header gives 0.014 +- 0.001), so this check does not test it. The low side ' + + 'allows it plus 4.0 sigma (sigma = 0.0020): a D more than 0.024 (1.3%) below 91/48 fails. The high side, 4.0 sigma, ' + + 'allows no shift: more than 0.008 above fails. Each side is 3.1 sigma of the seed-to-seed scatter of a nine-seed ' + + 'mean (0.0026), one of the tightest checks', 4); + +const secs = (Date.now() - start) / 1000; +console.log(`\nruntime ${secs.toFixed(1)} s on Node ${process.versions.node}`); +console.log(fails ? `\n${fails} check(s) failed` : '\nall checks pass'); +process.exit(fails ? 1 : 0);