-2
$\begingroup$

I want to provide software to compute with "integer complex numbers", that live in $\mathbb{Z}\times i \mathbb{Z}$, rather than the $\mathbb{C}$. Some operations are going to give results that are outside of $\mathbb{Z}\times i \mathbb{Z}$. What should I do with those? I see at least two options: 1. disallow them as making no sense for this restriction of $\mathbb{C}$, 2. allow the operation, but round automatically to the closest element of $\mathbb{Z}\times i \mathbb{Z}$, giving some well-defined meaning to "closest". What would be the most usual approach in mathematical software?

$\endgroup$
4
  • 1
    $\begingroup$ This question is unanswerable in my mind unless you are far more precise about what you mean by "some operations". Magma, sage, pari etc all implement number fields and there Z[i] is implemented exactly; some operations take you into Q(i) which is also implemented exactly; others, like transcendental operations, take you into the complexes so then you just round. This is not really a site for computer software either; try stackoverflow? But people won't know what software to suggest until they know more precisely what you want to do. $\endgroup$
    – eric
    Commented Jan 5, 2016 at 23:21
  • $\begingroup$ OK - I'll retire my question... or maybe not. Mark is getting me the kind of answer I was looking for. $\endgroup$
    – user26415
    Commented Jan 5, 2016 at 23:26
  • $\begingroup$ @eric - I am not looking for software to use: I am writing a new software library to compute with those numbers. That library with have +, -, *, /, but also transcendentals. "take you into" would mean that the type coming out of some functions would depend on the arguments of the functions, which could be problematic. Hence my question: if the user uses my library to calculate exp(2+3i), for example, what would be reasonable to return? Or what do other existing software, like pari, ... do? $\endgroup$
    – user26415
    Commented Jan 5, 2016 at 23:41
  • $\begingroup$ exp(2+3i) is a complex number in all the existing software I've used; a complex number is a pair of reals; a real number is the usual PITA if you want more accuracy than double/long etc. If you're writing a new software library then it might be a good idea to spend some time playing with existing libraries to see what they do? $\endgroup$
    – eric
    Commented Jan 6, 2016 at 7:24

1 Answer 1

1
$\begingroup$

Mathematical software almost never defines the result of integer operations in terms of "round to nearest". For example, in C, C++, Fortran, etc. the result of dividing a positive integer by another positive integer always rounds downward. (IN general, the rule in those languages is "round toward zero."

If forced to provide a complex template specialization in C++, I would hold my nose and stick with that convention, rounding both the real and imaginary parts toward zero. Thus $$\frac{4-11i}{3-2i} "=" 2-i$$ because $\frac{34}{13}$ "rounds" to $2$ and $-25/13$ "rounds" to $-1$.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .