https://github.com/helehex/moplex
Generalized complex numbers
https://github.com/helehex/moplex
complex dual hybrid mojo numbers perplex
Last synced: 3 months ago
JSON representation
Generalized complex numbers
- Host: GitHub
- URL: https://github.com/helehex/moplex
- Owner: helehex
- License: mit
- Created: 2023-11-27T06:12:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-13T01:36:46.000Z (7 months ago)
- Last Synced: 2024-09-24T16:22:46.357Z (7 months ago)
- Topics: complex, dual, hybrid, mojo, numbers, perplex
- Language: Mojo
- Homepage:
- Size: 6.73 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mojo-max-mlir - helehex/moplex
- awesome-mojo-max-mlir - helehex/moplex
README
# Moplex🔥
Generalized Complex Numbers for Mojo🔥Mojo version: `24.5.0`
Moplex provides generalized complex numbers for the mojo programming language.
Complex numbers have a real and imaginary part which can be added, multiplied, exponentiated, and more.
`5 + 4i`
The imaginary part multiplied by itself is -1
`i*i = -1`
# Generalized Complex
Moplex also has **Dualplex** numbers (also called dual numbers), and **Hyperplex** numbers (also called split numbers)
In Moplex, all three of these type are considered the `unital hybrids`, and the imaginary part is considered the `antiox`
They are similar to complex, in that the antiox also squares to a real number:
Dualplex numbers, written like `3+1o`, has an antiox that squares to zero -> `o*o = 0`
Hyperplex numbers, written like `1+2x`, have an antiox that squares to one -> `x*x = 1`
You can even make a number with an antiox that squares to any real by parameterizing the `Hybrid` type.
This looks like: `HybridInt[-2](0,1)`, which squares to `-2`
# Multiplex
When adding two HybridSIMD types with differing antiox squares, it will result in a **Multiplex** type
Example: `(1 + 1i) + (2 + 2o) = (3 + 1i + 2o)`
# Using in Mojo
to import and use a type, you can do:
```mojo
from moplex import *
from moplex import i, o, xprint(Complex64(-1,-2) ** i)
print(Dualplex64(1,1) + o)
print(Hyperplex64(8,6) * x)
print(Complex64(-1,-2) + Dualplex64(1,1) + Hyperplex64(8,6))
```You can also import just the antiox parts, but this is not ideal as some people like using single letter variables for other things.
Also, they dont sum together yet due to them being HybridIntLiteral type. (only MultiplexSIMD for now)
This may change with future updates.