RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Raya docs · Exact and higher mathematics

Lattice gauge theory

U(1) gauge symmetry as code, and lattice gauge theory for U(1), SU(2) and SU(3) with the Wilson action.

import 'package:riptide_lattice/riptide_lattice.ray';
3 classes48 functions and methods49 of 71 documented50 runnable examples

Overview

  • u1.ray: electromagnetism from local phase symmetry. U1Field2D (link variables, covariant derivative, field strength, gauge transformations, Wilson action \to \tfrac{1}{2}\int F^{2}, minimally coupled Schrödinger evolution and its conserved current), ringSpectrum and aharonovBohmScreen (Aharonov–Bohm), and the exact 2-D U(1)/SU(2) plaquettes.
  • gauge_lattice.ray: GaugeLattice for U(1), SU(2), SU(3) in any dimension with the Wilson action; checkerboard heat-bath (von Mises, Kennedy–Pendleton, Cabibbo–Marinari), overrelaxation, HMC; plaquettes, Wilson loops, Polyakov loops, random gauge transformations.
  • sun.ray: flat, allocation-free SU(N) kernels (the layout the GPU kernels in riptide_quantum_gpu share), checked against riptide_algebra's CMatrix.

Functions and constants

Functions

vonMisesfunction
double vonMises(double kappa, math.Random r)

A von Mises variate on (-\pi, \pi] with concentration kappa (Best & Fisher, Appl. Stat. 28, 152 (1979)).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final r = math.Random(7);
  final xs = [for (var i = 0; i < 5; i++) vonMises(4, r)];
  print(fl(xs));
}
Output
[-0.087367, 0.466075, 0.061557, 0.004117, -0.615878]
suMulfunction
void suMul(int n, Float64List a, int ao, Float64List b, int bo, Float64List c, int co)

c = a \cdot b for N \times N complex blocks at offsets.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final a = Float64List(8), b = Float64List(8), c = Float64List(8);
  su2FromQuaternion([0.6, 0.8, 0, 0], a, 0);
  su2FromQuaternion([0.6, 0, 0.8, 0], b, 0);
  suMul(2, a, 0, b, 0, c, 0);
  print('Re tr(ab) = ${f6(suReTrace(2, c, 0))}');
}
Output
Re tr(ab) = 0.720000
suMulDagfunction
void suMulDag(int n, Float64List a, int ao, Float64List b, int bo, Float64List c, int co)

c = a \cdot b^{\dagger}.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final a = Float64List(8), b = Float64List(8), c = Float64List(8);
  su2FromQuaternion([0.6, 0.8, 0, 0], a, 0);
  su2FromQuaternion([0.6, 0, 0.8, 0], b, 0);
  suMulDag(2, a, 0, a, 0, c, 0);
  print('a·a† = 1: Re tr = ${f6(suReTrace(2, c, 0))}');
}
Output
a·a† = 1: Re tr = 2.000000
suDagMulfunction
void suDagMul(int n, Float64List a, int ao, Float64List b, int bo, Float64List c, int co)

c = a^{\dagger} \cdot b.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final a = Float64List(8), b = Float64List(8), c = Float64List(8);
  su2FromQuaternion([0.6, 0.8, 0, 0], a, 0);
  su2FromQuaternion([0.6, 0, 0.8, 0], b, 0);
  suDagMul(2, a, 0, a, 0, c, 0);
  print(fl(c));
}
Output
[1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]
suReTracefunction
double suReTrace(int n, Float64List a, int ao)

Re \operatorname{tr}(a).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final a = Float64List(8), b = Float64List(8), c = Float64List(8);
  su2FromQuaternion([0.6, 0.8, 0, 0], a, 0);
  su2FromQuaternion([0.6, 0, 0.8, 0], b, 0);
  print('Re tr a = 2·a0 = ${f6(suReTrace(2, a, 0))}');
}
Output
Re tr a = 2·a0 = 1.200000
suIdentityfunction
void suIdentity(int n, Float64List a, int ao)

Writes the identity.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = Float64List(18);
  suIdentity(3, m, 0);
  print(fl(m));
}
Output
[1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]
List<double> randomSu2Quaternion(math.Random r)

A uniformly (Haar) distributed SU(2) quaternion (a_{0}, a_{1}, a_{2}, a_{3}).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final q = randomSu2Quaternion(math.Random(1));
  print('${fl(q)}, |q|² = ${f6(q.fold(0.0, (s, x) => s + x * x))}');
}
Output
[0.157003, -0.488731, -0.245789, -0.822240], |q|² = 1.000000
void su2FromQuaternion(List<double> q, Float64List m, int o)

The 2 \times 2 matrix a_{0} + i(a1σ1 + a2σ2 + a3σ3) written at o of m (row-major complex).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = Float64List(8);
  su2FromQuaternion([0, 1, 0, 0], m, 0);
  print('i·σ1 = ${fl(m)}');
}
Output
i·σ1 = [0.000000, 0.000000, 0.000000, 1.000000, -0.000000, 1.000000, 0.000000, -0.000000]
List<double> kennedyPendleton(double a, math.Random r)

Kennedy–Pendleton: x_{0} \in [-1, 1] with density \propto \sqrt{1 - x_{0}^{2}} e^{a \cdot x_{0}} (a = \beta_{\mathrm{eff}} \cdot k > 0), then a uniform direction.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(kennedyPendleton(2.0, math.Random(3))));
}
Output
[0.743392, 0.574212, -0.300404, -0.165549]
su2Projectfunction
List<double> su2Project(int n, Float64List w, int o, int i, int j)

The SU(2) projection of the 2 \times 2 block (i, j rows/cols of an N \times N matrix w): quaternion q with Re \operatorname{tr}(r \cdot w_{\mathrm{block}}) = 2 \sum r_{\mu} q_{\mu} for r ∈ SU(2) (r as quaternion, with the sign convention of su2FromQuaternion).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final m = Float64List(8);
  su2FromQuaternion([0.6, 0.8, 0, 0], m, 0);
  print(fl(su2Project(2, m, 0, 0, 1)));
}
Output
[0.600000, -0.800000, -0.000000, -0.000000]
quatMulfunction
List<double> quatMul(List<double> p, List<double> q)

Quaternion product (as SU(2) matrices): p \cdot q.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(quatMul([0, 1, 0, 0], [0, 0, 1, 0])));
}
Output
[0.000000, 0.000000, 0.000000, -1.000000]
quatDagfunction
List<double> quatDag(List<double> q)

The adjoint (inverse) quaternion.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(fl(quatDag([0.6, 0.8, 0, 0])));
}
Output
[0.600000, -0.800000, -0.000000, -0.000000]
void su2LeftMultiplySubgroup(int n, List<double> q, Float64List u, int o, int i, int j)

Left-multiplies rows i, j of the N \times N matrix u (at o) by the SU(2) element q embedded in that subgroup.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final u = Float64List(18);
  suIdentity(3, u, 0);
  su2LeftMultiplySubgroup(3, [0, 1, 0, 0], u, 0, 0, 1);
  print('Re tr = ${f6(suReTrace(3, u, 0))}');
}
Output
Re tr = 1.000000
void suReunitarise(int n, Float64List u, int o)

Projects the N \times N block at o back onto SU(N) (Gram–Schmidt on rows; for N = 3 the third row is the conjugate cross product of the first two, fixing \det = 1).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final u = Float64List(8);
  su2FromQuaternion([0.6, 0.8, 0, 0], u, 0);
  u[0] += 1e-3;
  suReunitarise(2, u, 0);
  final c = Float64List(8);
  suMulDag(2, u, 0, u, 0, c, 0);
  print('u·u† trace ${f6(suReTrace(2, c, 0))}');
}
Output
u·u† trace 2.000000
suRandomfunction
void suRandom(int n, Float64List u, int o, math.Random r)

A Haar-random SU(N) element at o (N = 2 from a uniform quaternion, N = 3 from products of random subgroup rotations, which is Haar after enough factors; ten suffice for tests and hot starts).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final u = Float64List(18);
  suRandom(3, u, 0, math.Random(5));
  final c = Float64List(18);
  suMulDag(3, u, 0, u, 0, c, 0);
  print('unitary: Re tr(u u†) = ${f6(suReTrace(3, c, 0))}');
}
Output
unitary: Re tr(u u†) = 3.000000
suExpIfunction
void suExpI(int n, Float64List p, int po, double eps, Float64List out, int oo)

\exp(i \cdot \varepsilon \cdot P) for Hermitian traceless N \times N p (at po) into out (at oo), by scaling and squaring of the Taylor series; unitary to round-off for HMC step sizes.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // exp(i·ε·σ3/2) for ε = π: a half turn.
  final p = Float64List.fromList([0.5, 0, 0, 0, 0, 0, -0.5, 0]);
  final out = Float64List(8);
  suExpI(2, p, 0, math.pi, out, 0);
  print(fl(out));
}
Output
[0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -1.000000]
besselIfunction
double besselI(int n, double x)

Modified Bessel function I_{n}(x) (riptide_numerics_special).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('I₀(1) = ${f6(besselI(0, 1))}, I₁(2) = ${f6(besselI(1, 2))}');
}
Output
I₀(1) = 1.266066, I₁(2) = 1.590637
double u1PlaquetteTwoDimensions(double beta, {int? plaquettes})

Exact \langle\cos \theta_{P}\rangle of 2-D U(1) Wilson lattice gauge theory on a periodic lattice with plaquettes plaquettes: Z = \sum_{n} I_{n}(\beta)^{V}, so \langle\cos \theta_{P}\rangle = \sum_{n} I_{n}'(\beta) I_{n}(\beta)^{V - 1} / \sum_{n} I_{n}(\beta)^{V} (I_{n}' = \frac{I_{n - 1} + I_{n + 1}}{2}). Infinite volume: \frac{I_{1}(\beta)}{I_{0}(\beta)} (Balian, Drouffe & Itzykson, Phys. Rev. D 11, 2098 (1975)).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('⟨cos θ_P⟩ at β = 2: ${f6(u1PlaquetteTwoDimensions(2))}');
}
Output
⟨cos θ_P⟩ at β = 2: 0.697775
double su2PlaquetteTwoDimensions(double beta)

Exact infinite-volume \langle\tfrac{1}{2} \operatorname{tr} U_{P}\rangle of 2-D SU(2) Wilson lattice gauge theory: \frac{I_{2}(\beta)}{I_{1}(\beta)} (Gross & Witten, Phys. Rev. D 21, 446 (1980) for U(N); the SU(2) character expansion in Drouffe & Zuber, Phys. Rep. 102, 1 (1983)).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print('⟨½ tr U_P⟩ at β = 2: ${f6(su2PlaquetteTwoDimensions(2))}');
}
Output
⟨½ tr U_P⟩ at β = 2: 0.433127
ringSpectrumfunction
Float64List ringSpectrum(int sites, double flux, {bool singularGauge = false})

The spectrum of a tight-binding ring of sites sites (hopping 1) threaded by flux flux (in units of the flux quantum \frac{h}{q}), with the whole Peierls phase on one link (singularGauge) or spread evenly. Exact: E_{m} = -2 \cos(\frac{2\pi(m - \Phi)}{N}). Diagonalised as the real 2N \times 2N embedding of the Hermitian matrix.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  for (final phi in [0.0, 0.25, 0.5]) print('flux $phi: lowest ${f6(ringSpectrum(8, phi).reduce(math.min))}');
}
Output
flux 0.0: lowest -2.000000
flux 0.25: lowest -1.961571
flux 0.5: lowest -1.847759
Float64List aharonovBohmScreen({required double flux, int nx = 160, int ny = 96, int steps = 560, double dt = 0.2, int screenX = 130})

The Aharonov–Bohm double-path experiment on a tight-binding grid: a wave packet from the left meets a square obstacle (sites with a high potential) that hides a solenoid of flux flux (units of \frac{h}{q}) at its centre; the Peierls phase lives on the x-links of a string from the solenoid to the top edge. Returns |\psi|^{2} along a screen column behind the obstacle after steps RK4 steps.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final s = aharonovBohmScreen(flux: 0.5, nx: 60, ny: 40, steps: 120, screenX: 50);
  print('${s.length} screen samples, max ${f6(s.reduce(math.max))}');
}
Output
40 screen samples, max 0.001146

Classes

enum GaugeGroup

The gauge group of a lattice.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  for (final g in GaugeGroup.values) print('$g: N = ${g.n}');
}
Output
GaugeGroup.u1: N = 1
GaugeGroup.su2: N = 2
GaugeGroup.su3: N = 3

Values

u1value
u1(1)
su2value
su2(2)
su3value
su3(3)

Constructors

GaugeGroupconstructor
const GaugeGroup(this.n)
Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(GaugeGroup.su3.n);
}
Output
3

Properties

nfield
final int n

N of U(N)/SU(N); 1 for U(1).

final class GaugeLattice

A gauge field on a periodic lattice with extents dims (the last one is Euclidean time).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // SU(2) on 4⁴: heat-bath to equilibrium at β = 2.3 and measure the plaquette.
  final l = GaugeLattice(GaugeGroup.su2, [4, 4, 4, 4], seed: 1)..hotStart();
  for (var i = 0; i < 10; i++) l.heatBathSweep(2.3);
  print('plaquette ${l.plaquette().toStringAsFixed(2)}');
}
Output
plaquette 0.62

Constructors

GaugeLatticeconstructor
GaugeLattice(this.group, this.dims, {int seed = 1})
Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.u1, [6, 6]);
  print('volume ${l.volume}, links ${l.volume * 2}');
}
Output
volume 36, links 72

Properties

groupfield
final GaugeGroup group
dimsfield
final List<int> dims
dfield
final int d
volumefield
final int volume
esizefield
final int esize
rndfield
final math.Random rnd
upfield
late final List<Int32List> up
dnfield
late final List<Int32List> dn
parityfield
late final Uint8List parity
ngetter
int get n

Methods

offsetmethod
int offset(int site, int mu)

Offset of link (site, \mu) in links.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(GaugeLattice(GaugeGroup.su2, [4, 4]).offset(3, 1));
}
Output
56
coldStartmethod
void coldStart()

Every link = 1.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su3, [4, 4, 4, 4])..coldStart();
  print('plaquette ${f6(l.plaquette())} (every link = 1)');
}
Output
plaquette 1.000000 (every link = 1)
hotStartmethod
void hotStart()

Every link Haar-random.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4, 4, 4], seed: 2)..hotStart();
  print('random plaquette ≈ ${l.plaquette().toStringAsFixed(1)}');
}
Output
random plaquette ≈ 0.0
staplemethod
void staple(int x, int mu, Float64List v, int vo)

The sum of staples V of link (x, \mu), so the local action is -(\frac{\beta}{N}) Re \operatorname{tr}(U_{\mu}(x) \cdot V), written to v at vo.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4])..coldStart();
  final v = Float64List(8);
  l.staple(0, 0, v, 0);
  print('cold staple sum: Re tr = ${f6(suReTrace(2, v, 0))}');
}
Output
cold staple sum: Re tr = 4.000000
plaquettemethod
double plaquette()

⟨Re \operatorname{tr} U_{P}⟩/N over every plaquette.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.u1, [8, 8], seed: 3)..coldStart();
  for (var i = 0; i < 20; i++) l.heatBathSweep(2);
  print('2-D U(1) at β = 2, one configuration: ${l.plaquette().toStringAsFixed(2)}; the exact average ${f6(u1PlaquetteTwoDimensions(2, plaquettes: 64))}');
}
Output
2-D U(1) at β = 2, one configuration: 0.65; the exact average 0.697775
double plaquetteAt(int x, int mu, int nu)

Re \operatorname{tr} U_{P} / N of the plaquette at x in the (\mu, \nu) plane.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(f6((GaugeLattice(GaugeGroup.su2, [4, 4])..coldStart()).plaquetteAt(0, 0, 1)));
}
Output
1.000000
actionmethod
double action(double beta)

The Wilson action S = \beta \sum_{P} (1 - \operatorname{Re} \operatorname{tr} U_{P} / N).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4])..coldStart();
  print('cold action ${f6(l.action(2))}');
}
Output
cold action 0.000000
double wilsonLoop(int r, int t)

⟨Re \operatorname{tr} W(R, T)⟩/N: rectangular loops of R links along each spatial axis and T along the last axis.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4, 4, 4], seed: 4)..hotStart();
  for (var i = 0; i < 8; i++) l.heatBathSweep(2.3);
  print('W(1,1) ${l.wilsonLoop(1, 1).toStringAsFixed(2)}, W(2,2) ${l.wilsonLoop(2, 2).toStringAsFixed(2)} (area law)');
}
Output
W(1,1) 0.59, W(2,2) 0.13 (area law)
(double, double) polyakovLoop()

The Polyakov loop ⟨tr \prod_{t} U_{\mathrm{time}}(x, t)⟩/N averaged over spatial sites, as (re, im).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4, 4, 2])..coldStart();
  print(l.polyakovLoop());
}
Output
(1.0, 0.0)
void randomGaugeTransform()

Applies the gauge transformation U_{\mu}(x) \to G(x) U_{\mu}(x) G(x + \mu)^{\dagger} with Haar-random G (observables are invariant).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4], seed: 5)..hotStart();
  final before = l.plaquette();
  l.randomGaugeTransform();
  print('plaquette unchanged: ${(l.plaquette() - before).abs() < 1e-12}');
}
Output
plaquette unchanged: true
void heatBathSweep(double beta)

One checkerboard heat-bath sweep at coupling beta.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4], seed: 6)..coldStart();
  l.heatBathSweep(3);
  print('after one sweep: ${l.plaquette().toStringAsFixed(1)}');
}
Output
after one sweep: 0.7
void overrelaxSweep()

One checkerboard overrelaxation sweep (microcanonical: leaves S unchanged).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4], seed: 7)..hotStart();
  final s = l.action(2);
  l.overrelaxSweep();
  print('action conserved: ${((l.action(2) - s) / s).abs() < 1e-9}');
}
Output
action conserved: true
(double, bool) hmcTrajectory(double beta, {required int steps, required double eps, bool metropolis = true})

One HMC trajectory of steps leapfrog steps of size eps; returns (\Delta H, accepted).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.u1, [6, 6], seed: 8)..coldStart();
  final (dh, acc) = l.hmcTrajectory(1.5, steps: 10, eps: 0.05);
  print('accepted $acc, |ΔH| < 0.1: ${dh.abs() < 0.1}');
}
Output
accepted true, |ΔH| < 0.1: true
double hmcReversibility(double beta, {required int steps, required double eps})

Runs the leapfrog forward then, with momenta reversed, backward; returns the max link change (reversibility).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final l = GaugeLattice(GaugeGroup.su2, [4, 4], seed: 9)..hotStart();
  print('reversibility error < 1e-9: ${l.hmcReversibility(2, steps: 10, eps: 0.05) < 1e-9}');
}
Output
reversibility error < 1e-9: true
final class U1Field2D

A charged scalar field \psi on a periodic 2-D lattice with U(1) links: the gauge principle made concrete.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  // A uniform magnetic field: every plaquette carries the same angle.
  final f = U1Field2D(8, 8)..setVectorPotential((x, y) => (-0.05 * y, 0.05 * x));
  print('plaquette angle ${f6(f.plaquetteAngle(3, 3))}');
}
Output
plaquette angle 0.100000

Constructors

U1Field2Dconstructor
U1Field2D(this.nx, this.ny, {this.a = 1, this.charge = 1})
Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(4, 4, a: 0.5, charge: 2);
  print('${f.psi.length ~/ 2} sites, ${f.theta.length} links');
}
Output
16 sites, 32 links

Properties

nxfield
final int nx
nyfield
final int ny
afield
final double a
chargefield
final double charge
psifield
final Float64List psi

Interleaved complex \psi(x, y), x fastest.

thetafield
final Float64List theta

Link angles \theta_{\mu}(x, y) = q \cdot a \cdot A_{\mu}, index 2 \cdot \mathrm{site} + \mu (\mu = 0 for x, 1 for y).

Methods

sitemethod
int site(int x, int y)
Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  print(U1Field2D(4, 4).site(-1, 5));
}
Output
7
void setVectorPotential((double, double) Function(double x, double y) aField)

Sets the links from a continuum vector potential A(x, y) sampled at link midpoints.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(4, 4)..setVectorPotential((x, y) => (0.1, 0));
  print(f6(f.theta[0]));
}
Output
0.100000
(double, double) covariantDerivative(int x, int y, int mu)

D_{\mu}\psi at (x, y) as (re, im).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(4, 4);
  for (var i = 0; i < 16; i++) f.psi[2 * i] = 1;
  print(f.covariantDerivative(1, 1, 0));
}
Output
(0.0, 0.0)
double plaquetteAngle(int x, int y)

The plaquette angle \theta_{P} at (x, y), wrapped to (-\pi, \pi]: q \cdot a^{2} \cdot F_{xy}.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(6, 6)..setVectorPotential((x, y) => (0, 0.2 * x));
  print(f6(f.plaquetteAngle(2, 2)));
}
Output
0.200000
double wilsonAction()

The Wilson gauge action \beta \sum_{P} (1 - \cos \theta_{P}) with \beta = \frac{1}{q^{2}a^{4 - d}}, d = 2 here, so it tends to \tfrac{1}{2}\int F_{xy}^{2} dxdy.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(6, 6)..setVectorPotential((x, y) => (0, 0.2 * x));
  print(f6(f.wilsonAction()));
}
Output
3.356189
void gaugeTransform(double Function(int x, int y) alpha)

Applies the local gauge transformation \alpha(x, y): \psi \to e^{i\alpha}\psi, \theta_{\mu}(x) \to \theta_{\mu}(x) + \alpha(x) - \alpha(x + \hat{\mu}).

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(6, 6)..setVectorPotential((x, y) => (0, 0.2 * x));
  final s = f.wilsonAction();
  f.gaugeTransform((x, y) => 0.3 * x * y);
  print('action unchanged: ${(f.wilsonAction() - s).abs() < 1e-9}');
}
Output
action unchanged: false
void applyHamiltonian(Float64List p, Float64List out, {Float64List? potential})

H\psi for the minimally coupled lattice Schrödinger operator H = -(\frac{1}{2m})\sum_{\mu} D_{\mu}^{\dagger}D_{\mu} (mass 1): the hopping form (\frac{2d}{2a^{2}})\psi(x) - (\frac{1}{2a^{2}}) \sum_{\mu} [U_{\mu}(x)\psi(x + \hat{\mu}) + U_{\mu}(x - \hat{\mu})^{\dagger}\psi(x - \hat{\mu})].

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(4, 4);
  for (var i = 0; i < 16; i++) f.psi[2 * i] = 1;
  final out = Float64List(32);
  f.applyHamiltonian(f.psi, out);
  print('H·constant = ${f6(out[0])} (zero kinetic energy)');
}
Output
H·constant = 0.000000 (zero kinetic energy)
stepRk4method
void stepRk4(double dt, {Float64List? potential})

One RK4 step of i\dot{\psi} = H\psi.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(8, 8);
  f.psi[2 * f.site(4, 4)] = 1;
  f.stepRk4(0.05);
  var n = 0.0;
  for (var i = 0; i < 64; i++) n += f.psi[2 * i] * f.psi[2 * i] + f.psi[2 * i + 1] * f.psi[2 * i + 1];
  print('norm after a step ${f6(n)}');
}
Output
norm after a step 1.000000
currentmethod
double current(Float64List p, int x, int y, int mu)

The probability current on link (x, \mu): j_{\mu}(x) = \frac{\operatorname{Im}(\psi \cdot (x) U_{\mu}(x) \psi(x + \hat{\mu}))}{a} (mass 1), the gauge-invariant Noether current of the phase symmetry. With \rho = |\psi|^{2}, \frac{\partial\rho}{\partial t} + \sum_{\mu} \frac{j_{\mu}(x) - j_{\mu}(x - \hat{\mu})}{a} = 0 exactly.

Example
import 'package:riptide_lattice/riptide_lattice.ray';
import 'raya:convert';
import 'raya:math' as math;
import 'raya:typed_data';

String f6(num x) => x.toStringAsFixed(6);
String fl(Iterable<num> xs) => '[${xs.map(f6).join(', ')}]';

void main() {
  final f = U1Field2D(8, 4);
  for (var x = 0; x < 8; x++) {
    for (var y = 0; y < 4; y++) {
      f.psi[2 * f.site(x, y)] = math.cos(2 * math.pi * x / 8);
      f.psi[2 * f.site(x, y) + 1] = math.sin(2 * math.pi * x / 8);
    }
  }
  print('j_x = ${f6(f.current(f.psi, 0, 0, 0))} (a plane wave carries current)');
}
Output
j_x = 0.707107 (a plane wave carries current)