Combinatorial ising.py

From Werner KRAUTH

Jump to: navigation, search

This page presents the program combinatorial_ising.py, in other words the Kac-Ward matrix for the two-dimensional Ising model, naively implemented for the 2x2 lattice and the 4x4 lattice.


Contents

Reference

W. Krauth Statistical Mechanics: Algorithms and Computations Oxford University Press (2006) This matrix is discussed in Lecture 07 of my 2019 ICFP course on Statistical physics.

Description

This is a Python implementation of the Kac-Ward matrix that computes the partition function of the two-dimensional Ising model without periodic boundary conditions.

Program

import numpy, math

beta = 1.0
print beta, ' beta'
comp_i = complex(0.0, 1.0)
nu = math.tanh(beta)
alpha = numpy.exp(comp_i * math.pi / 4.0) * math.tanh(beta)
alphabar = numpy.exp(-comp_i * math.pi / 4.0) * math.tanh(beta)

# 4x4 matrices 'right', 'up', 'left', 'down', 'one', 'zero'

r = numpy.mat([
[nu, alpha, 0.0, alphabar],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0]], dtype=complex)

u = numpy.mat([
[0.0, 0.0, 0.0, 0.0],
[alphabar, nu, alpha, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0]], dtype=complex)

l = numpy.mat([
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, alphabar, nu, alpha],
[0.0, 0.0, 0.0, 0.0]], dtype=complex)

d = numpy.mat([
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[alpha, 0.0, alphabar, nu]], dtype=complex)

o = numpy.mat([
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0]], dtype=complex)

z = numpy.mat([
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0]], dtype=complex)

U2x2 = numpy.bmat([
[o, r, u, z],
[l, o, z, u],
[d, z, o, r],
[z, d, l, o]])

L = 2
n_edge = 2 * L * (L - 1)
N = L ** 2

print 2 ** N * math.cosh(beta) ** n_edge * \
numpy.sqrt(numpy.real(numpy.linalg.det(U2x2))), ' Z_2x2 from Kac-Ward'
print 2 ** 4 * math.cosh(beta) ** 4 * (1.0 + math.tanh(beta) ** 4), \
' Z_2x2 from SMAC eq. (5.11)'

U4x4 = numpy.bmat([
#0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
[o, r, z, z, u, z, z, z, z, z, z, z, z, z, z, z],   # line 0
[l, o, r, z, z, u, z, z, z, z, z, z, z, z, z, z],   # line 1
[z, l, o, r, z, z, u, z, z, z, z, z, z, z, z, z],   # line 2
[z, z, l, o, z, z, z, u, z, z, z, z, z, z, z, z],   # line 3
[d, z, z, z, o, r, z, z, u, z, z, z, z, z, z, z],   # line 4
[z, d, z, z, l, o, r, z, z, u, z, z, z, z, z, z],   # line 5
[z, z, d, z, z, l, o, r, z, z, u, z, z, z, z, z],   # line 6
[z, z, z, d, z, z, l, o, z, z, z, u, z, z, z, z],   # line 7
[z, z, z, z, d, z, z, z, o, r, z, z, u, z, z, z],   # line 8
[z, z, z, z, z, d, z, z, l, o, r, z, z, u, z, z],   # line 9
[z, z, z, z, z, z, d, z, z, l, o, r, z, z, u, z],   # line 10
[z, z, z, z, z, z, z, d, z, z, l, o, z, z, z, u],   # line 11
[z, z, z, z, z, z, z, z, d, z, z, z, o, r, z, z],   # line 12
[z, z, z, z, z, z, z, z, z, d, z, z, l, o, r, z],   # line 13
[z, z, z, z, z, z, z, z, z, z, d, z, z, l, o, r],   # line 14
[z, z, z, z, z, z, z, z, z, z, z, d, z, z, l, o]])  # line 15

L = 4
n_edge = 2 * L * (L - 1)
N = L ** 2
print 2 ** N * math.cosh(beta) ** n_edge * \
math.sqrt(numpy.real(numpy.linalg.det(U4x4))), \
' Z_4x4 from Kac-Ward'
print 2 ** N * math.cosh(beta) ** n_edge * (
1 +
  9 * math.tanh(beta) ** 4 +
 12 * math.tanh(beta) ** 6 +
 50 * math.tanh(beta) ** 8 +
 92 * math.tanh(beta) ** 10 +
158 * math.tanh(beta) ** 12 +
116 * math.tanh(beta) ** 14 +
 69 * math.tanh(beta) ** 16 +
  4 * math.tanh(beta) ** 18 +
  1 * math.tanh(beta) ** 20), ' Z_4x4 from SMAC eq. (5.10)'

Version

See history for version information.

Personal tools