MCPcopy Create free account
hub / github.com/TRIQS/triqs / test_algebra

Method test_algebra

test/python/operators.py:117–175  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

115 self.assertEqual(len({a, b, c}), 2)
116
117 def test_algebra(self):
118
119 with capture_stdout() as output:
120 C_list = [c(1,0),c(2,0),c(3,0)]
121 Cd_list = [c_dag(1,0), c_dag(2,0), c_dag(3,0)]
122
123 print("Anticommutators:")
124 for Cd,C in itertools.product(Cd_list,C_list):
125 print("{", Cd, ",", C, "} =", Cd*C + C*Cd)
126
127 print("Commutators:")
128 for Cd,C in itertools.product(Cd_list,C_list):
129 print("[", Cd, ",", C, "] =", Cd*C - C*Cd)
130
131 x = c(0,0)
132 y = c_dag(1,0)
133
134 print()
135 print("Algebra:")
136 print("x =", x)
137 print("y =", y)
138
139 print("-x =", -x)
140 print("x + 2.0 =", x + 2.0)
141 print("2.0 + x =", 2.0 + x)
142 print("x - 2.0 =", x - 2.0)
143 print("2.0 - x =", 2.0 - x)
144 print("3.0*y =", 3.0*y)
145 print("y*3.0 =", y*3.0)
146 print("x + y =", x + y)
147 print("x - y =", x - y)
148 print("(x + y)*(x - y) =", (x + y)*(x - y))
149 print("Operator(3.14) =", Operator(3.14))
150
151 # N^3
152 print()
153 print("N^3:")
154 N = n(0,'up') + n(0,'dn')
155 N3 = N*N*N
156 print("N =", N)
157 print("N^3 =", N3)
158
159 print("Monomials of N^3:")
160 for monomial, coef in N3: print(monomial, coef)
161
162 # Dagger, real & imag
163 X = (1+2j)*c_dag('a',1)*c_dag('a',2)*c('a',3)*c('a',4);
164
165 print()
166 print("X =", X)
167 print("dagger(X) =", dagger(X))
168 print("X.real =", X.real)
169 print("X.imag =", X.imag)
170
171 self.assertEqual(output, ref_output.splitlines())
172
173 # Test Operator comparison
174 anti_comm_ccdag = c(0,0) * c_dag(0,0) + c_dag(0,0) * c(0,0)

Callers

nothing calls this directly

Calls 4

capture_stdoutClass · 0.90
c_dagFunction · 0.85
nFunction · 0.85
cFunction · 0.50

Tested by

no test coverage detected