def testConjugation(self): self.assertEqual(Complex(), Complex().conjugate()) self.assertEqual(Complex(3), Complex(3).conjugate()) self.assertEqual(Complex(4, -3), Complex(4, 3).conjugate()) self.assertEqual(Complex(-2, 3), Complex(-2, -3).conjugate()) a = Complex(1, 2) self.assertEqual(a, a.conjugate().conjugate())
def testVectorinner_product(self): v1 = ComplexM(3, 1, [[(2, -5)], [(1, 0)], [(3, 1)]]) v2 = ComplexM(3, 1, [[(2, 1)], [(2, 3)], [(4, 14)]]) v3 = ComplexM(3, 1, [[(0, -2)], [(-1, 0)], [(2, -3)]]) c = Complex(3, 3) vz = ComplexM(3, 1, [[0], [0], [0]]) self.assertIsInstance(v1.inner_product(v2), Complex) # v ≠ 0 → ⟨v, v⟩ > 0 self.assertGreater(v1.inner_product(v1).real_value, 0) self.assertEqual(v1.inner_product(v1).imaginary_value, 0) # ⟨v1, v2⟩ = 0 ↔ v = 0 self.assertEqual(vz.inner_product(vz), Complex(0)) # ⟨v1+v2, v3⟩ = ⟨v1, v3⟩ + ⟨v2, v3⟩ self.assertEqual((v1 + v2).inner_product(v3), v1.inner_product(v3) + v2.inner_product(v3)) # ⟨v1, v2+v3⟩ = ⟨v1, v2⟩ + ⟨v1, v3⟩ self.assertEqual(v1.inner_product(v2 + v3), v1.inner_product(v2) + v1.inner_product(v3)) # ⟨c v1, v2⟩ = conj(c) ⟨v1, v2⟩ self.assertEqual((v1 * c).inner_product(v2), c.conjugate() * v1.inner_product(v2)) # ⟨v1, c v2⟩ = c ⟨v2, v1⟩ self.assertEqual(v1.inner_product(c * v2), c * v1.inner_product(v2)) # ⟨v1, v2⟩ = conj(⟨v2, v1⟩) self.assertEqual(v1.inner_product(v2), v2.inner_product(v1).conjugate())