My DotNET application has a limited scripting language build in (modelled loosely on VBScript) mainly for post-processing numbers, points and vectors. I've just added support for complex numbers, but I'm struggling with the notation.
I don't want to use the A + Bi notation, since it is not a clear division if A or B are defined as equations already:
31 * 5 + 6 + -5i
This could be interpreted as:
A = 31 * 5 + 6 B = -5i
and:
A = 31 * 5 B = 6 + -5i
None of the programming languages I know have native support for complex numbers. I'm thinking something like the following might work, but I'd appreciate any input on this:
{31 * 5} + {6 + -5}i
complex(31 * 5, 6 + -5)
r{31 * 5} i{6 + -5}
It seems you are using explicit multiplication in your examples (i.e. you require A * B, rather than A B ).
In that case why not simply use the i suffix directly following the value as in
myComplex = 12 + 6i
or
myOtherComplex = 12/7 + (6 * pi)i
Then you may need to decide about i or j, I've seen both...
This i-suffix trick is not unlike the scientific notication and is e (3.1415e7 for example)
Edit (following David's comments)
The format above can become confusing, depending on the audience, one way to clarify this may be to only allow for imaginary literals, and to include these into a complex notation derived from your existing vector notation. When imaginary numbers or complex number require an expression to designate them, the syntax would require the explicit "function-looking" syntax such as Imaginary(i) and Complex(r, i).
Parsing rules:
In short:
That's seems consistent and simple enough, but then again, only the true end-users can tell.