Complex Numbers Extension
I couldn't find an extension dedicated to complex numbers, you know... sqrt(-1) and stuff like that, so I made one. This is also my first extension, and it kinda works pretty well!
All features:
-
Construct a complex number with real and/or imaginary component
-
Get the real and imaginary components of that value
-
Boolean to check if a number is real or not
-
Addition, subtraction, multiplication, division and exponentiation. And modulo.
-
Functions with single input, with extra: conjugate, flip, sign, atan2.
-
Toggle between simple and advanced syntax, for perfomance reasons. Maybe simple mode is at least slightly faster.
Examples
- Mandelbrot Set
- Julia Set
Interesting, I also made one of the same thing, but for personal use. Your extension is quite good, but slow. It takes almost 2.57 seconds to exponentiate 1000000 complex numbers. Approximately 4 times slower than mine. I think you should optimize it.
I was recently told about your existence, and looks like your extension has more power than mine (altho I have more blocks >:D but that's not the point either). From mathematician to cool guy, wanna work together?
(or maybe we should call @penta-quark-neutro to see what optimizations he used!)
There are fairly simple ways to get better performance. In the case of my extension, I simply rewrote the operations to avoid classes or calling functions. Using vectors is very efficient, but I imagine that your extension should return a string. This is an example of a way to implement octonions and have them calculate quickly: "octa3(ar){const v1=ar.a,v2=ar.b;return [(v1[0]*v2[0])-(v1[1]*v2[1])-(v1[2]*v2[2])-(v1[3]*v2[3])-(v1[4]*v2[4])-(v1[5]*v2[5])-(v1[6]*v2[6])-(v1[7]*v2[7]) ,(v1[0]*v2[1])+(v1[1]*v2[0])-(v1[2]*v2[3])+(v1[3]*v2[2])-(v1[4]*v2[5])+(v1[5]*v2[4])+(v1[6]*v2[7])-(v1[7]*v2[6]) ,(v1[0]*v2[2])+(v1[1]*v2[3])+(v1[2]*v2[0])-(v1[3]*v2[1])-(v1[4]*v2[6])-(v1[5]*v2[7])+(v1[6]*v2[4])+(v1[7]*v2[5]) ,(v1[0]*v2[3])-(v1[1]*v2[2])+(v1[2]*v2[1])+(v1[3]*v2[0])-(v1[4]*v2[7])+(v1[5]*v2[6])-(v1[6]*v2[5])+(v1[7]*v2[4]), (v1[0]*v2[4])+(v1[1]*v2[5])+(v1[2]*v2[6])+(v1[3]*v2[7])+(v1[4]*v2[0])-(v1[5]*v2[1])-(v1[6]*v2[2])-(v1[7]*v2[3]), (v1[0]*v2[5])-(v1[1]*v2[4])+(v1[2]*v2[7])-(v1[3]*v2[6])+(v1[4]*v2[1])+(v1[5]*v2[0])+(v1[6]*v2[3])-(v1[7]*v2[2]),( v1[0]*v2[6])-(v1[1]*v2[7])-(v1[2]*v2[4])+(v1[3]*v2[5])+(v1[4]*v2[2])-(v1[5]*v2[3])+(v1[6]*v2[0])+(v1[7]*v2[1]),( v1[0]*v2[7])+(v1[1]*v2[6])-(v1[2]*v2[5])-(v1[3]*v2[4])+(v1[4]*v2[3])+(v1[5]*v2[2])-(v1[6]*v2[1])+(v1[7]*v2[0])]}" Avoid calling functions and creating intermediate steps, avoid creating more variables than necessary, and chaining uses more resources and should be minimized. Even the example I provided could be optimized further, but I'm currently working on an object extension and adding sedenions to my vector extension. Good luck.