@@ -61,6 +61,39 @@ SymbolicUtils.@number_methods(Num,
61
61
Num (f (value (a))),
62
62
Num (f (value (a), value (b))))
63
63
64
+ for C in [Complex, Complex{Bool}]
65
+ @eval begin
66
+ Base.:* (x:: Num , z:: $C ) = Complex (x * real (z), x * imag (z))
67
+ Base.:* (z:: $C , x:: Num ) = Complex (real (z) * x, imag (z) * x)
68
+ end
69
+ end
70
+
71
+ Base.:+ (x:: Num , z:: Complex ) = Complex (x + real (z), imag (z))
72
+ Base.:+ (z:: Complex , x:: Num ) = Complex (real (z) + x, imag (z))
73
+ Base.:- (x:: Num , z:: Complex ) = Complex (x - real (z), - imag (z))
74
+ Base.:- (z:: Complex , x:: Num ) = Complex (real (z) - x, imag (z))
75
+
76
+ function Base. inv (z:: Complex{Num} )
77
+ a, b = reim (z)
78
+ den = a^ 2 + b^ 2
79
+ Complex (a/ den, - b/ den)
80
+ end
81
+ function Base.:/ (x:: Complex{Num} , y:: Complex{Num} )
82
+ a, b = reim (x)
83
+ c, d = reim (y)
84
+ den = c^ 2 + d^ 2
85
+ Complex ((a* c + b* d)/ den, (b* c - a* d)/ den)
86
+ end
87
+
88
+ function Base. show (io:: IO , z:: Complex{<:Num} )
89
+ r, i = reim (z)
90
+ compact = get (io, :compact , false )
91
+ show (io, r)
92
+ print (io, (compact ? " +" : " + " ) * " (" )
93
+ show (io, i)
94
+ print (io, " )*im" )
95
+ end
96
+
64
97
SymbolicUtils. simplify (n:: Num ; kw... ) = Num (SymbolicUtils. simplify (value (n); kw... ))
65
98
66
99
SymbolicUtils. symtype (n:: Num ) = symtype (n. val)
0 commit comments