Is there an equivalent to the expr
command which works for complex numbers (represented lists of two doubles)?
This library provides functions for complex number arithmetic, and this seems to be a useful utility to define the required cexpr
function, but it doesn't work well.
E.g. it doesn't handle properly the brackets.
ParseExpressions::ParseExpr { (1) + ((2) + (3)) } { }
returns
+ [+ 1 ((2)] (3))
while it should return
+ [+ 1 2] 3
Also ParseExpressions::ParseExpr { {1 2} + {3 4} } {}
returns
+ 1 2 3 4
while it should return
+ {1 2} {3 4}
So basically I am asking for a robust version of this utility.
Technically, the only arithmetic operations that are defined on complex numbers are addition and multiplication. This means that both subtraction and division will, in some way, need to be defined in terms of these two operations.
Answer: Following are the arithmetic rules for complex numbers, Addition: For addition of complex numbers, one can write (a + ib) + (c + id) = (a + c) + i(b + d). Subtraction: For subtraction of complex numbers, one can write (a + ib) – (c + id) = (a – c) + i(b – d).
The Tcl command for doing math type operations is expr .
Why don't you try this: http://wiki.tcl.tk/11415 or something like this too: http://wiki.tcl.tk/13885
I hope these are easy to use alternatives for the mentioned utility.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With