Yang–Mills: the 2026 Lean construction, rerun and read; the mass gap still open
OpenAI's 2026 Lean construction of 4D Yang–Mills as the expert group keeps it: settle what it proves, rerun it, read it; uniqueness and the mass gap are open, and Clay's problem unsolved

Add independent SU(2) heat-bath simulation
Browse files+370 −0 examples/plaquette-2.2986/heatbath.cpp added View file
| @@ -0,0 +1,370 @@ | ||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | +using Quaternion = std::array<double, 4>; | |
| 16 | + | |
| 17 | +Quaternion operator+(const Quaternion &a, const Quaternion &b) { | |
| 18 | + return {a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]}; | |
| 19 | +} | |
| 20 | + | |
| 21 | +Quaternion operator*(const Quaternion &a, const Quaternion &b) { | |
| 22 | + return { | |
| 23 | + a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3], | |
| 24 | + a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2], | |
| 25 | + a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1], | |
| 26 | + a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0] | |
| 27 | + }; | |
| 28 | +} | |
| 29 | + | |
| 30 | +Quaternion conjugate(const Quaternion &a) { | |
| 31 | + return {a[0], -a[1], -a[2], -a[3]}; | |
| 32 | +} | |
| 33 | + | |
| 34 | +Quaternion scaled(const Quaternion &a, double scale) { | |
| 35 | + return {a[0] * scale, a[1] * scale, a[2] * scale, a[3] * scale}; | |
| 36 | +} | |
| 37 | + | |
| 38 | +double norm(const Quaternion &a) { | |
| 39 | + return std::sqrt(std::inner_product(a.begin(), a.end(), a.begin(), 0.0)); | |
| 40 | +} | |
| 41 | + | |
| 42 | +class Random { | |
| 43 | +public: | |
| 44 | + explicit Random(std::uint64_t seed) { | |
| 45 | + for (auto &word : state) { | |
| 46 | + seed += 0x9e3779b97f4a7c15ULL; | |
| 47 | + std::uint64_t z = seed; | |
| 48 | + z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL; | |
| 49 | + z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL; | |
| 50 | + word = z ^ (z >> 31); | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + double uniform() { | |
| 55 | + return static_cast<double>(next() >> 11) * 0x1.0p-53; | |
| 56 | + } | |
| 57 | + | |
| 58 | + double open() { | |
| 59 | + return (static_cast<double>(next() >> 11) + 0.5) * 0x1.0p-53; | |
| 60 | + } | |
| 61 | + | |
| 62 | +private: | |
| 63 | + std::array<std::uint64_t, 4> state{}; | |
| 64 | + | |
| 65 | + static std::uint64_t rotate(std::uint64_t x, int bits) { | |
| 66 | + return (x << bits) | (x >> (64 - bits)); | |
| 67 | + } | |
| 68 | + | |
| 69 | + std::uint64_t next() { | |
| 70 | + const std::uint64_t result = rotate(state[1] * 5, 7) * 9; | |
| 71 | + const std::uint64_t t = state[1] << 17; | |
| 72 | + state[2] ^= state[0]; | |
| 73 | + state[3] ^= state[1]; | |
| 74 | + state[1] ^= state[2]; | |
| 75 | + state[0] ^= state[3]; | |
| 76 | + state[2] ^= t; | |
| 77 | + state[3] = rotate(state[3], 45); | |
| 78 | + return result; | |
| 79 | + } | |
| 80 | +}; | |
| 81 | + | |
| 82 | +class Lattice { | |
| 83 | +public: | |
| 84 | + Lattice(int size, double beta, std::uint64_t seed, bool cold) | |
| 85 | + : size(size), beta(beta), volume(size * size * size * size), random(seed), | |
| 86 | + links(volume * 4), plus(volume * 4), minus(volume * 4) { | |
| 87 | + for (int x = 0; x < volume; ++x) { | |
| 88 | + for (int mu = 0; mu < 4; ++mu) { | |
| 89 | + links[index(x, mu)] = cold ? Quaternion{1, 0, 0, 0} : random_su2(); | |
| 90 | + plus[index(x, mu)] = shift(x, mu, 1); | |
| 91 | + minus[index(x, mu)] = shift(x, mu, -1); | |
| 92 | + } | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + void sweep() { | |
| 97 | + for (int x = 0; x < volume; ++x) { | |
| 98 | + for (int mu = 0; mu < 4; ++mu) { | |
| 99 | + update(x, mu); | |
| 100 | + } | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + double max_link_norm_error() const { | |
| 105 | + double result = 0; | |
| 106 | + for (const Quaternion &link : links) { | |
| 107 | + result = std::max(result, std::abs(norm(link) - 1)); | |
| 108 | + } | |
| 109 | + return result; | |
| 110 | + } | |
| 111 | + | |
| 112 | + double average_plaquette() const { | |
| 113 | + double total = 0; | |
| 114 | + for (int x = 0; x < volume; ++x) { | |
| 115 | + for (int mu = 0; mu < 4; ++mu) { | |
| 116 | + for (int nu = mu + 1; nu < 4; ++nu) { | |
| 117 | + const Quaternion p = links[index(x, mu)] | |
| 118 | + * links[index(plus[index(x, mu)], nu)] | |
| 119 | + * conjugate(links[index(plus[index(x, nu)], mu)]) | |
| 120 | + * conjugate(links[index(x, nu)]); | |
| 121 | + total += p[0]; | |
| 122 | + } | |
| 123 | + } | |
| 124 | + } | |
| 125 | + return total / (6.0 * volume); | |
| 126 | + } | |
| 127 | + | |
| 128 | + Quaternion sample(double coupling) { | |
| 129 | + if (coupling < 1e-12) { | |
| 130 | + return random_su2(); | |
| 131 | + } | |
| 132 | + const double tail = std::exp(-2 * coupling); | |
| 133 | + double a0; | |
| 134 | + do { | |
| 135 | + const double u = random.open(); | |
| 136 | + a0 = 1 + std::log(tail + u * (1 - tail)) / coupling; | |
| 137 | + } while (random.uniform() > std::sqrt(std::max(0.0, 1 - a0 * a0))); | |
| 138 | + const double z = 2 * random.uniform() - 1; | |
| 139 | + const double phi = 2 * pi * random.uniform(); | |
| 140 | + const double circle_radius = std::sqrt(std::max(0.0, 1 - z * z)); | |
| 141 | + const double vector_radius = std::sqrt(std::max(0.0, 1 - a0 * a0)); | |
| 142 | + return {a0, vector_radius * circle_radius * std::cos(phi), | |
| 143 | + vector_radius * circle_radius * std::sin(phi), vector_radius * z}; | |
| 144 | + } | |
| 145 | + | |
| 146 | +private: | |
| 147 | + static constexpr double pi = 3.141592653589793238462643383279502884; | |
| 148 | + int size; | |
| 149 | + double beta; | |
| 150 | + int volume; | |
| 151 | + Random random; | |
| 152 | + std::vector<Quaternion> links; | |
| 153 | + std::vector<int> plus; | |
| 154 | + std::vector<int> minus; | |
| 155 | + | |
| 156 | + int index(int x, int mu) const { | |
| 157 | + return 4 * x + mu; | |
| 158 | + } | |
| 159 | + | |
| 160 | + int shift(int x, int mu, int amount) const { | |
| 161 | + std::array<int, 4> coordinates{}; | |
| 162 | + int remainder = x; | |
| 163 | + for (int direction = 0; direction < 4; ++direction) { | |
| 164 | + coordinates[direction] = remainder % size; | |
| 165 | + remainder /= size; | |
| 166 | + } | |
| 167 | + coordinates[mu] = (coordinates[mu] + amount + size) % size; | |
| 168 | + int result = 0; | |
| 169 | + for (int direction = 3; direction >= 0; --direction) { | |
| 170 | + result = size * result + coordinates[direction]; | |
| 171 | + } | |
| 172 | + return result; | |
| 173 | + } | |
| 174 | + | |
| 175 | + Quaternion random_su2() { | |
| 176 | + const double a0 = 2 * random.uniform() - 1; | |
| 177 | + const double z = 2 * random.uniform() - 1; | |
| 178 | + const double phi = 2 * pi * random.uniform(); | |
| 179 | + const double vector_radius = std::sqrt(std::max(0.0, 1 - a0 * a0)); | |
| 180 | + const double circle_radius = std::sqrt(std::max(0.0, 1 - z * z)); | |
| 181 | + return {a0, vector_radius * circle_radius * std::cos(phi), | |
| 182 | + vector_radius * circle_radius * std::sin(phi), vector_radius * z}; | |
| 183 | + } | |
| 184 | + | |
| 185 | + Quaternion staple(int x, int mu) const { | |
| 186 | + Quaternion sum{0, 0, 0, 0}; | |
| 187 | + for (int nu = 0; nu < 4; ++nu) { | |
| 188 | + if (nu == mu) { | |
| 189 | + continue; | |
| 190 | + } | |
| 191 | + const int x_plus_mu = plus[index(x, mu)]; | |
| 192 | + const int x_plus_nu = plus[index(x, nu)]; | |
| 193 | + const Quaternion forward = links[index(x_plus_mu, nu)] | |
| 194 | + * conjugate(links[index(x_plus_nu, mu)]) | |
| 195 | + * conjugate(links[index(x, nu)]); | |
| 196 | + const int x_minus_nu = minus[index(x, nu)]; | |
| 197 | + const int x_minus_nu_plus_mu = plus[index(x_minus_nu, mu)]; | |
| 198 | + const Quaternion backward = conjugate(links[index(x_minus_nu_plus_mu, nu)]) | |
| 199 | + * conjugate(links[index(x_minus_nu, mu)]) | |
| 200 | + * links[index(x_minus_nu, nu)]; | |
| 201 | + sum = sum + forward + backward; | |
| 202 | + } | |
| 203 | + return sum; | |
| 204 | + } | |
| 205 | + | |
| 206 | + void update(int x, int mu) { | |
| 207 | + const Quaternion s = staple(x, mu); | |
| 208 | + const double magnitude = norm(s); | |
| 209 | + if (magnitude < 1e-14) { | |
| 210 | + links[index(x, mu)] = random_su2(); | |
| 211 | + return; | |
| 212 | + } | |
| 213 | + const Quaternion a = sample(beta * magnitude); | |
| 214 | + links[index(x, mu)] = a * scaled(conjugate(s), 1 / magnitude); | |
| 215 | + } | |
| 216 | +}; | |
| 217 | + | |
| 218 | +struct Statistics { | |
| 219 | + double mean; | |
| 220 | + double naive_error; | |
| 221 | + double autocorrelation_error; | |
| 222 | + double integrated_time; | |
| 223 | + double blocking_error; | |
| 224 | + int block_size; | |
| 225 | +}; | |
| 226 | + | |
| 227 | +Statistics analyze(const std::vector<double> &values) { | |
| 228 | + const int n = static_cast<int>(values.size()); | |
| 229 | + const double mean = std::accumulate(values.begin(), values.end(), 0.0) / n; | |
| 230 | + double variance = 0; | |
| 231 | + for (double value : values) { | |
| 232 | + variance += (value - mean) * (value - mean); | |
| 233 | + } | |
| 234 | + variance /= n - 1; | |
| 235 | + const double naive_error = std::sqrt(variance / n); | |
| 236 | + double integrated_time = 0.5; | |
| 237 | + const int max_lag = std::min(2000, n / 10); | |
| 238 | + int lag = 1; | |
| 239 | + for (; lag <= max_lag; ++lag) { | |
| 240 | + double covariance = 0; | |
| 241 | + for (int i = 0; i + lag < n; ++i) { | |
| 242 | + covariance += (values[i] - mean) * (values[i + lag] - mean); | |
| 243 | + } | |
| 244 | + covariance /= (n - lag) * variance; | |
| 245 | + integrated_time += covariance; | |
| 246 | + if (lag >= 5 * integrated_time) { | |
| 247 | + break; | |
| 248 | + } | |
| 249 | + } | |
| 250 | + integrated_time = std::max(0.5, integrated_time); | |
| 251 | + const double autocorrelation_error = std::sqrt(2 * integrated_time * variance / n); | |
| 252 | + const int block_size = std::max(1, static_cast<int>(std::ceil(40 * integrated_time))); | |
| 253 | + const int blocks = n / block_size; | |
| 254 | + double blocking_error = naive_error; | |
| 255 | + if (blocks >= 2) { | |
| 256 | + std::vector<double> means(blocks, 0); | |
| 257 | + for (int block = 0; block < blocks; ++block) { | |
| 258 | + means[block] = std::accumulate(values.begin() + block * block_size, | |
| 259 | + values.begin() + (block + 1) * block_size, 0.0) / block_size; | |
| 260 | + } | |
| 261 | + const double block_mean = std::accumulate(means.begin(), means.end(), 0.0) / blocks; | |
| 262 | + double block_variance = 0; | |
| 263 | + for (double value : means) { | |
| 264 | + block_variance += (value - block_mean) * (value - block_mean); | |
| 265 | + } | |
| 266 | + block_variance /= blocks - 1; | |
| 267 | + blocking_error = std::sqrt(block_variance / blocks); | |
| 268 | + } | |
| 269 | + return {mean, naive_error, autocorrelation_error, integrated_time, blocking_error, block_size}; | |
| 270 | +} | |
| 271 | + | |
| 272 | +std::uint64_t parse_seed(const std::string &text) { | |
| 273 | + return std::stoull(text); | |
| 274 | +} | |
| 275 | + | |
| 276 | +int parse_int(const std::string &text) { | |
| 277 | + return std::stoi(text); | |
| 278 | +} | |
| 279 | + | |
| 280 | +int main(int argc, char **argv) { | |
| 281 | + int size = 8; | |
| 282 | + double beta = 2.2986; | |
| 283 | + std::uint64_t seed = 20261202; | |
| 284 | + int thermalization = 2000; | |
| 285 | + int sweeps = 20000; | |
| 286 | + bool cold = true; | |
| 287 | + std::string history_path; | |
| 288 | + for (int i = 1; i < argc; ++i) { | |
| 289 | + const std::string argument = argv[i]; | |
| 290 | + if (i + 1 >= argc) { | |
| 291 | + std::cerr << "missing value after " << argument << '\n'; | |
| 292 | + return 2; | |
| 293 | + } | |
| 294 | + const std::string value = argv[++i]; | |
| 295 | + if (argument == "--size") size = parse_int(value); | |
| 296 | + else if (argument == "--beta") beta = std::stod(value); | |
| 297 | + else if (argument == "--seed") seed = parse_seed(value); | |
| 298 | + else if (argument == "--thermalization") thermalization = parse_int(value); | |
| 299 | + else if (argument == "--sweeps") sweeps = parse_int(value); | |
| 300 | + else if (argument == "--start") cold = value == "cold"; | |
| 301 | + else if (argument == "--history") history_path = value; | |
| 302 | + else { | |
| 303 | + std::cerr << "unknown option: " << argument << '\n'; | |
| 304 | + return 2; | |
| 305 | + } | |
| 306 | + } | |
| 307 | + if (size < 2 || beta < 0 || thermalization < 0 || sweeps < 2) { | |
| 308 | + std::cerr << "require size >= 2, beta >= 0, thermalization >= 0 and sweeps >= 2\n"; | |
| 309 | + return 2; | |
| 310 | + } | |
| 311 | + if (!cold) { | |
| 312 | + bool valid_start = false; | |
| 313 | + for (int i = 1; i + 1 < argc; ++i) { | |
| 314 | + if (std::string(argv[i]) == "--start") { | |
| 315 | + valid_start = std::string(argv[i + 1]) == "hot"; | |
| 316 | + } | |
| 317 | + } | |
| 318 | + if (!valid_start) { | |
| 319 | + std::cerr << "--start must be cold or hot\n"; | |
| 320 | + return 2; | |
| 321 | + } | |
| 322 | + } | |
| 323 | + const auto started = std::chrono::steady_clock::now(); | |
| 324 | + Lattice lattice(size, beta, seed, cold); | |
| 325 | + const double initial_plaquette = lattice.average_plaquette(); | |
| 326 | + for (int sweep = 0; sweep < thermalization; ++sweep) { | |
| 327 | + lattice.sweep(); | |
| 328 | + } | |
| 329 | + const double thermalized_plaquette = lattice.average_plaquette(); | |
| 330 | + std::vector<double> values; | |
| 331 | + values.reserve(sweeps); | |
| 332 | + std::ofstream history; | |
| 333 | + if (!history_path.empty()) { | |
| 334 | + history.open(history_path); | |
| 335 | + history << std::setprecision(17); | |
| 336 | + } | |
| 337 | + for (int sweep = 0; sweep < sweeps; ++sweep) { | |
| 338 | + lattice.sweep(); | |
| 339 | + const double value = lattice.average_plaquette(); | |
| 340 | + values.push_back(value); | |
| 341 | + if (history.is_open()) { | |
| 342 | + history << sweep + 1 << ' ' << value << '\n'; | |
| 343 | + } | |
| 344 | + } | |
| 345 | + const Statistics statistics = analyze(values); | |
| 346 | + const double error = std::max({statistics.naive_error, statistics.autocorrelation_error, | |
| 347 | + statistics.blocking_error}); | |
| 348 | + const double seconds = std::chrono::duration<double>(std::chrono::steady_clock::now() - started).count(); | |
| 349 | + std::cout << std::setprecision(17) | |
| 350 | + << "{\n" | |
| 351 | + << " \"group\": \"SU(2)\",\n" | |
| 352 | + << " \"beta\": " << beta << ",\n" | |
| 353 | + << " \"lattice\": [" << size << ", " << size << ", " << size << ", " << size << "],\n" | |
| 354 | + << " \"start\": \"" << (cold ? "cold" : "hot") << "\",\n" | |
| 355 | + << " \"seed\": " << seed << ",\n" | |
| 356 | + << " \"thermalization_sweeps\": " << thermalization << ",\n" | |
| 357 | + << " \"measurement_sweeps\": " << sweeps << ",\n" | |
| 358 | + << " \"initial_plaquette\": " << initial_plaquette << ",\n" | |
| 359 | + << " \"thermalized_plaquette\": " << thermalized_plaquette << ",\n" | |
| 360 | + << " \"max_link_norm_error\": " << lattice.max_link_norm_error() << ",\n" | |
| 361 | + << " \"plaquette\": " << statistics.mean << ",\n" | |
| 362 | + << " \"error\": " << error << ",\n" | |
| 363 | + << " \"naive_error\": " << statistics.naive_error << ",\n" | |
| 364 | + << " \"autocorrelation_error\": " << statistics.autocorrelation_error << ",\n" | |
| 365 | + << " \"integrated_autocorrelation_time\": " << statistics.integrated_time << ",\n" | |
| 366 | + << " \"blocking_error\": " << statistics.blocking_error << ",\n" | |
| 367 | + << " \"block_size\": " << statistics.block_size << ",\n" | |
| 368 | + << " \"seconds\": " << seconds << "\n" | |
| 369 | + << "}\n"; | |
| 370 | +} | |