extensions icon indicating copy to clipboard operation
extensions copied to clipboard

Complex Numbers Extension

Open BonesYT opened this issue 11 months ago • 3 comments

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

  1. Mandelbrot Set image
  2. Julia Set image

BonesYT avatar Jan 11 '25 15:01 BonesYT

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.

penta-quark-neutro avatar Jan 12 '25 21:01 penta-quark-neutro

Hi @BonesYT ! I may or may not made something similar (like, with more blocks and such...) see #2113 for more :D Anyways, I'm working on updating my extension, because it's wierd with every letter. Plus, I found how to implement Quaternions, and maybe have more optimization ideas for it, maybe too many... I liked how you tackled some problems in the file. But that's not why I am here.

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? image

(or maybe we should call @penta-quark-neutro to see what optimizations he used!)

Kenay555 avatar Sep 19 '25 21:09 Kenay555

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.

penta-quark-neutro avatar Sep 19 '25 23:09 penta-quark-neutro