Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Any way of adding these numbers together in pure math? #1

Open
alex-polosky opened this issue Aug 20, 2024 · 2 comments
Open

Comments

@alex-polosky
Copy link

Hey there! Recently got into complex bases, and began to find (-1 + i) fascinating since it can be represented in binary.

I was curious if you have an implementation for adding numbers together? I've got Python code that allows me to go back and forth between CBNS and base10 representations, but I'm having trouble adding numbers together. So far, I can do trivial additions (such as 1 + 1; 1+1j + -1j, etc) but am struggling when I end up with several overflow carries.

If you're curious, my python code is as follows:

def _cdiv(a: complex) -> tuple[complex, int]:
    n = a.real
    m = a.imag
    oddity = n % 2 + m % 2
    if oddity != 1:
        return (
            ((m - n) / 2) - ((n + m) / 2) * 1j,
            0
        )
    else:
        return (
            ((m - n + 1) / 2) - ((n + m - 1) / 2) * 1j,
            1
        )

def to_cbns(n: complex) -> int:
    result = 0
    i = 0
    while n!= 0:
        quotient, remainder = _cdiv(n)
        result |= remainder << i
        n = quotient
        i += 1
    return result

def to_b10(n: int) -> complex:
    r = 0
    i = 0
    while n:
        if (n & 1):
            r += (-1 + 1j) ** i
        i += 1
        n >>= 1

    return r

And here's the specific issue I'm having. I thought I had it figured out, but then immediately came up with a counter example.

What I thought worked great:

001010111       (4 + 2j)
------------------------
1111            (2 + 1j)
1111            (2 + 1j)
-----------------------------
001010111                  
-----------------------------
 011                   
  011                  
   011                 
    111                 
      011

What immediately broke the thought process:

1001                    (+3 + 3j)
---------------------------------
111010111               (+4 - 1j)
0110111                 (-1 + 3j)
---------------------------------
100101111...                    
---------------------------------
  011                    
   011                   
     111       
      011              
       011             
        011

Any thoughts you have would be greatly appreciated.

@Q1CHENL
Copy link
Owner

Q1CHENL commented Aug 21, 2024

Hi Alex!
A pure math version (arithmetics) was also one of the important stuffs we wanted to have during the project but we got no luck. We didn't have time to figure it out ourselves, and unfortunately, there were too little relevant info/literature about this topic. Maybe you can refer to the last 2 literatures we cited in our paper. Those are very short papers but that's what we could find and maybe you will get some ideas from them.
I wish you good luck! Thanks for reaching out and I would like to know if you have any progress or updates on this :)

P.S Our paper is Ausarbeitung/Ausarbeitung.pdf

@alex-polosky
Copy link
Author

Ah, no worries! I'll take a look at the citations and see if I can glean anything. I'll let you know if I figure anything out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants