15 """ complex multiplication """
17 self.
imag * right.real + self.
real * right.imag)
20 return Complex(elf.real + right.real, self.
imag + right.imag)
26 """ scalar division """
30 return "( " + repr(self.
real) +
" + " + repr(self.
imag) +
"i )"
33 """ We use the following convention [real, imag] """
40 """ squared norm when considering the complex number as tuple """
44 """ complex conjugate """
48 """ complex inverse """
60 if isinstance(self, other.__class__):
61 return self.
real == other.real
and self.
imag == other.imag
69 sympy.simplify(self.
imag))
73 """ derivatice of complex muliplication wrt left multiplier a """
74 return sympy.Matrix([[b.real, -b.imag],
79 """ derivatice of complex muliplication wrt right multiplicand b """
80 return sympy.Matrix([[a.real, -a.imag],
86 x, y = sympy.symbols(
'x y', real=
True)
87 u, v = sympy.symbols(
'u v', real=
True)
92 product = self.
a * self.
a.inv()
93 self.assertEqual(product.simplify(),
95 product = self.
a.inv() * self.
a
96 self.assertEqual(product.simplify(),
100 d = sympy.Matrix(2, 2,
lambda r, c: sympy.diff(
101 (self.
a * self.
b)[r], self.
a[c]))
103 Complex.Da_a_mul_b(self.
a, self.
b))
104 d = sympy.Matrix(2, 2,
lambda r, c: sympy.diff(
105 (self.
a * self.
b)[r], self.
b[c]))
107 Complex.Db_a_mul_b(self.
a, self.
b))
110 if __name__ ==
'__main__':