Add complex literals? (original) (raw)

September 27, 2023, 4:51pm 43

Ok, sorry. I’ll try to write out here all cases for addition.

I’m suggesting to represent the set of complexes, C, as a disjoint union of the set I = {complex(0, x)}, “imaginary numbers”, and it’s complement C\I = {complex(a, b) | a!=0}, “the rest” (a can be here -0.0!). When both operands are from “the rest” - usual addition rules work. For “imaginary numbers” we have:

(1)  complex(0, x) + complex(0, y) = complex(0, x + y)

Now mixed cases:

(2) real + complex(0, x) = complex(real, x)
(3) real + complex(a, b) = complex(real + a, b) (where a!=0)
(4) complex(0, x) + complex(a, b) = complex(a, x + b) (where a!=0)

(plus same rules for changed order of operands on lhs). I hope now it’s clear enough for addition and it also clear how to deduce similar rules for subtraction and multiplication from the annex G.

Sure, I have example (complex(-0.0, 1) + complex(0, 1) = complex(-0.0, 2)) above. More generally: complex(-0.0, x) + complex(0, y) = complex(-0.0, x+y) (rule 4) seems to be only exception from rules of usual complex arithmetics (wrt to addition). On a pro: this proposal should fix some other identities, that we have in docs (e.g. variants of complex(real, imag)==real+imag*1j).