Combinatorial ising.py

From Werner KRAUTH

(Difference between revisions)
Jump to: navigation, search
Revision as of 19:49, 19 October 2015
Werner (Talk | contribs)

← Previous diff
Current revision
Werner (Talk | contribs)

Line 1: Line 1:
-This page presents the program combinatorial_ising.py, naively implemented for the 2x2 lattice and the 4x4 lattice+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.
__FORCETOC__ __FORCETOC__
=Reference= =Reference=
-[[Krauth_2006|W. Krauth ''Statistical Mechanics: Algorithms and Computations'' Oxford University Press (2006)]]+[[SMAC|W. Krauth ''Statistical Mechanics: Algorithms and Computations'' Oxford University Press (2006)]]
 +This matrix is discussed in [[ICFP_Stat_Physics_2018#Week_7_.2822_October_2018.29:_Two-dimensional_Ising_model:_From_Kramers_.26_Wannier_to_Kac_.26_Ward_.28Low-_and_high-temperature_expansions.29|Lecture 07]]
 +of my 2019 ICFP course on Statistical physics.
=Description= =Description=
-This is a Python implementation of the Kac-Ward matrix that allows to compute the partition function of the two-dimensional Ising model without periodic boundary conditions.+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= =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) alphabar = numpy.exp(-comp_i * math.pi / 4.0) * math.tanh(beta)
- +
# 4x4 matrices 'right', 'up', 'left', 'down', 'one', 'zero' # 4x4 matrices 'right', 'up', 'left', 'down', 'one', 'zero'
- +
r = numpy.mat([ r = numpy.mat([
[nu, alpha, 0.0, alphabar], [nu, alpha, 0.0, alphabar],
Line 17: Line 26:
[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) [0.0, 0.0, 0.0, 0.0]], dtype=complex)
- +
u = numpy.mat([ u = numpy.mat([
[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0],
Line 23: Line 32:
[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) [0.0, 0.0, 0.0, 0.0]], dtype=complex)
- +
l = numpy.mat([ l = numpy.mat([
[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0],
Line 29: Line 38:
[0.0, alphabar, nu, alpha], [0.0, alphabar, nu, alpha],
[0.0, 0.0, 0.0, 0.0]], dtype=complex) [0.0, 0.0, 0.0, 0.0]], dtype=complex)
- +
d = numpy.mat([ d = numpy.mat([
[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0],
Line 35: Line 44:
[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0],
[alpha, 0.0, alphabar, nu]], dtype=complex) [alpha, 0.0, alphabar, nu]], dtype=complex)
- +
o = numpy.mat([ o = numpy.mat([
[1.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0],
Line 41: Line 50:
[0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0]], dtype=complex) [0.0, 0.0, 0.0, 1.0]], dtype=complex)
- +
z = numpy.mat([ z = numpy.mat([
[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0],
Line 47: Line 56:
[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) [0.0, 0.0, 0.0, 0.0]], dtype=complex)
- +
U2x2 = numpy.bmat([ U2x2 = numpy.bmat([
[o, r, u, z], [o, r, u, z],
Line 53: Line 62:
[d, z, o, r], [d, z, o, r],
[z, d, l, o]]) [z, d, l, o]])
- +
L = 2 L = 2
n_edge = 2 * L * (L - 1) n_edge = 2 * L * (L - 1)
N = L ** 2 N = L ** 2
- +
print 2 ** N * math.cosh(beta) ** n_edge * \ print 2 ** N * math.cosh(beta) ** n_edge * \
numpy.sqrt(numpy.real(numpy.linalg.det(U2x2))), ' Z_2x2 from Kac-Ward' 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), \ print 2 ** 4 * math.cosh(beta) ** 4 * (1.0 + math.tanh(beta) ** 4), \
' Z_2x2 from SMAC eq. (5.11)' ' Z_2x2 from SMAC eq. (5.11)'
- +
U4x4 = numpy.bmat([ U4x4 = numpy.bmat([
#0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Line 81: Line 90:
[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, 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 [z, z, z, z, z, z, z, z, z, z, z, d, z, z, l, o]]) # line 15
- +
L = 4 L = 4
n_edge = 2 * L * (L - 1) n_edge = 2 * L * (L - 1)
Line 100: Line 109:
1 * math.tanh(beta) ** 20), ' Z_4x4 from SMAC eq. (5.10)' 1 * math.tanh(beta) ** 20), ' Z_4x4 from SMAC eq. (5.10)'
-  
=Version= =Version=
See history for version information. See history for version information.
-[[Category:Python]] [[Category:Honnef_2015]]+[[Category:Python]] [[Category:ICFP]]

Current revision

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.