0

Note: I don't know if this belongs here or on the math exchange, but I'll start here because I'm shooting for numerical solutions.

I need to convert complex numbers of the generic form $x+yi$ into base $2i$ (the Quater-Imaginary Base), preferably without radix (decimal points / fractions in that base).

  • Are there any libraries that do such a conversion?
  • Is there no way to express all complex numbers (with integer coefficients) in base $2i$ without radix?
  • Is the euclidean division algorithm the only conversion algorithm?
opticaliqlusion
  • 327
  • 2
  • 13

1 Answers1

1

Ok, this has been here for a full day and no one answered. So I'll try my best to answer despite my lack of knowledge in this field. After a lot of googling I found the following:

Are there any libraries that do such a conversion?

I found nothing that allows this type of conversion, the best I found was this: https://codereview.stackexchange.com/questions/78514/all-in-one-number-base-converter
this guy wrote some code to convert between bases, and it seems quite good except it doesn't work for imaginary bases.-keep this thing in mind because you can still use it-.

Is there no way to express all complex numbers (with integer coefficients) in base $2i$ without radix?

No, any complex number with odd imaginary coefficient will require the use of one digit after the point (since the only way to represent 1i is 10.2 in quarter-imaginary).

Is the euclidean division algorithm the only conversion algorithm?

I'm not sure Euclidean division actually works here, -not in it's simple form-.

However, after some searching I found this question: https://codegolf.stackexchange.com/questions/69112/output-quater-imaginary-base-numbers-in-binary
This is a code golfing question, you can use the code in the first answer if you don't mind Javascript, and code that no one can understand.

However, the idea behind the code is that you can convert the real part of the complex number, let's call it r to base -4. And then interlace 0s between them to convert the real part to base 2i.

1-e.g. 7 in base -4 is 133, in base 2i it is 10303 this is because the powers corresponding to the odd positions in 2i are the same powers of -4 i.e. [1,-4,16,-32,.....]

As for the imaginary part, you can divide the imaginary coefficient by 2, and then convert it to -4 base, then you can insert those into the odd position of the base 2i number to get the imaginary part. The idea is that the odd 2i powers are [2i,-8i,16i,.....], and dividing those by 2i (dividing the complex coefficient by 2) gets you the base -4 coefficients [1,-4,8,.....]

2-e.g. to convert 7i to 2i base, first divide the coefficient by 2, to get 3.5, which is 130.2 in base -4, if you just insert those digits into the odd positions of base 2i number you get 103000.2 which is 7i.

finally, you just add the two parts (imaginary and real) to get the complex number as a whole in base 2i
e.g. 7+7i in base 2i is equal to: 7 in base 2i which is 10303 -from 1-e.g. and 7i in base 2i which is 103000.2 -from 2-e.g.- the result of which is 113303.2 which is the base 2i representation of 7+7i.

Please keep in mind that yesterday was the first time I heard of imaginary base numbers, so I might not be entirely correct.

hassan arafat
  • 657
  • 5
  • 15
  • Thanks for the answer! To give you a better idea, I took the "brute force" approach with Knuth's Quater-Imaginary base ([implementation](https://gist.github.com/opticaliqlusion/f81c750608c0f4203a8b44df8deb55b9)). Because I conjecture that a solution always exists for the 2i base, I can faithfully search. The big problem? It's slow as all hell. The upside? If the conjecture is true, I don't seem to need a radix point! – opticaliqlusion Sep 21 '17 at 04:16
  • I'm glad to hear that. However, I'm a little curious about how you can represent complex numbers with odd imaginary coefficients without a radix point. Can you give me an example? – hassan arafat Sep 21 '17 at 04:21
  • Sure! I basically implemented the example [on the wikipedia page](https://en.wikipedia.org/wiki/Quater-imaginary_base#Converting_into_quater-imaginary), where you assume your real part is the sum of every other digit, and the imaginary part is made up of the rest. In the example, -1+4i is broken into -1 == 103 and 4i == 020 so when you add them together you get 123 (base 2i). The only problem with this is that there's no straightforward way to calculate those sums -- you kind of just have to guess. So I enumerate all the base 4 numbers from zeroes, turn them into base 2i, and test them :) – opticaliqlusion Sep 21 '17 at 04:44
  • That doesn't sound very dependable -or very efficient for that matter-. Can you try to input 7+7i into your algorithm and see the output? – hassan arafat Sep 21 '17 at 04:50
  • [sure thing!](https://gist.github.com/opticaliqlusion/6e22512edfd41be7a7f849805a6d9231) Like I said -- there's a lot of guesses. – opticaliqlusion Sep 21 '17 at 04:54
  • Thank you, but the output for `7+7i` is `113303` which is not the right output. `113303`is equal to` 7+8i` – hassan arafat Sep 21 '17 at 05:06
  • HMMmmmmmMMMMmmmm – opticaliqlusion Sep 21 '17 at 05:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/154950/discussion-between-hassan-arafat-and-opticaliqlusion). – hassan arafat Sep 21 '17 at 05:09