Welcome to Fractal Forums

Fractal Math, Chaos Theory & Research => (new) Theories & Research => Topic started by: stigomaster on December 16, 2009, 08:09:23 PM




Title: "Modular" complex arithmetic
Post by: stigomaster on December 16, 2009, 08:09:23 PM
i somehow got the idea that I should try to make a "mod" function for complex numbers. I figured I might not let the magnitude of the number exceed a certain value. So what I'm trying to do right now is to plot a Mandelbrot set where the iterated point zn never goes outside the disc defined by the initial c value. I imagine that the plot would look very different for different iteration values. Moreover, because you won't be able to say that a point bails out, I would like to colour the points based on angle and magnitude.

I'm attaching a picture, although the program still has big flaws and the result is therefore far from what it is supposed to be.


Title: Re: "Modular" complex arithmetic
Post by: kram1032 on December 16, 2009, 08:17:36 PM
complex mod is usually defined as mod(abs(z),a)*sign(z)

though, both terms modulo might be a bit more complicate

mod(abs(z),abs(c))*sign(z) (*sign(c)?)


Title: Re: "Modular" complex arithmetic
Post by: stigomaster on December 16, 2009, 10:38:09 PM
I think I got the program to work as I wanted to now, at least it produces some satisfying output :) I'll just put up some pics now, maybe I'll write some more later. Comments are fun!


Title: Re: "Modular" complex arithmetic
Post by: kram1032 on December 16, 2009, 10:59:58 PM
which values did you use? :)

What happens for mod(z,2)?

nice wave patterns :)


Title: Re: "Modular" complex arithmetic
Post by: stigomaster on December 18, 2009, 03:54:52 PM
Turns out there was a little bug in the colouring algorithm, but I fixed it. To clear up my mod algorithm, I will now simply post the source code for the funtion :) I call this function at every iteration.
Code:
void modCplx(double *r, double *i, double mod) {
double magn = sqrt(*r * *r + *i * *i);
double phase = (*r >= 0) ? asin(*i / magn) : 0.0 - asin(*i / magn) + 3.14159265359;

while(magn > mod) magn -= mod;

*r = cos(phase) * magn;
*i = sin(phase) * magn;
}

Quote
What happens for mod(z,2)?
Well, it certainly does not look too bad! I attach a series of renders at iteration values from 1 to 10. Coordinates are (-8, -6), (8, 6). The colouring algorithm is pretty simple; It's HSL where hue is the phase of z_n, saturation is 1 and light is abs(z_n)/abs(c).


Title: Re: "Modular" complex arithmetic
Post by: stigomaster on December 18, 2009, 03:59:05 PM
And hey, I'll put up some zooms too. The first is into my original function ("mod" (z_n, abs c ) ) and the second into the mod 2 version.


Title: Re: "Modular" complex arithmetic
Post by: kram1032 on December 18, 2009, 04:47:02 PM
very psychedelic :)


Title: Re: "Modular" complex arithmetic
Post by: TimGolden on December 19, 2009, 04:02:50 PM
Great Experiment stigomaster.

Seems to me the challenge will be to get a function that has low populations in some regions. If a wrapping distance does not mesh with these low populations then there is bound to be a flooding of the space; essentially a loss of detail. Still you've got graphics! Do they stabilize? I'm guessing not.

 - Tim


Title: Re: "Modular" complex arithmetic
Post by: Timeroot on March 27, 2010, 07:34:11 AM
^necro

I was looking back over this, and I'm not satisfied with the definition of mod. mod(z,a)=mod(abs(z),a)*sign(z) doesn't even hold for real negative values. If you want something along these lines, the best definitions would be:

mod(z,a)=mod(abs(z),a)
mod(z,a)=mod(abs(z),a)*sign(z) - (sign(z)-1)/2

I think maybe the most correct version, extended more or less analytically, uses Fourier series. The Fourier series for z mod 2pi is:

pi - 2(sin(z)/1 + sin(2z)/2 + sin(3z)/3 ...)

To convert to another mod, we use the simple formula mod(z,a)=mod(z*2*pi/a,2*pi)*a/(2*pi) - at least, I think that's it, someone check my maths - and then we've got a complex definition of sine!  O0

Thoughts on this?


Title: Re: "Modular" complex arithmetic
Post by: stigomaster on March 27, 2010, 11:44:28 AM
My mod function goes like this: First I convert to polar coordinates, and if the magnitude is greater than a given value I subtract that value from the magnitude until it is within the bounds. Then I convert back into cartesian and do another iteration. Thus, the angle remains the same. As far as I can see, this algorithm works for all complex numbers, even negative real numbers.


Title: Re: "Modular" complex arithmetic
Post by: kram1032 on March 27, 2010, 11:48:23 AM
How did you get that result, Timeroot? :)
I mean, the fourier of z mod 2pi....


Wolfram Alpha can solve it :)
the formula without that sum is:
\pi-i (\log(1-e^{i z})-\log(e^{-i z} (-1+e^{i z})))

if I put in your formula to get to a general mod, I get
a (i \log(1-e^{-{2 i \pi z\over a}}-i \log(1-e^{{2 i \pi z\over a}})+\pi)\over2 \pi

however, log()-log() can be rewritten as log( / ), if I'm not mistaken.
If you do this, the whole formula simplifys to
a (i log(-e^{-{2 i \pi z\over a}})+\pi)\over 2 \pi

Further simplifications can only be done if you assume a and z to be positive, according to Wolfram Alpha... in that case, the ultimatedly simplified formula would be:
a (\pi+i (i \pi-{2 i \pi z\over a})) \over 2 \pi

Nice other aproach but I don't see, how the definition given further above doesn't hold for negative values.
In case of z being real and negative, the definition simplifies to common mod just as usual...


Title: Re: "Modular" complex arithmetic
Post by: stigomaster on March 27, 2010, 12:37:16 PM
My approach was purely geometrical, I just got the idea of holding points back kind of like a mod function.


Title: Re: "Modular" complex arithmetic
Post by: Timeroot on March 27, 2010, 06:37:42 PM
kram, when you're dealing with multivalued functions like log, simplifying sometimes doesn't always make it quite clear, what with different branches and all. I think it's perfectly fine to simplify further - W|A just couldn't tell the "history" at that step, so it didn't know what acceptable, exactly. If we take the other branch of log(z), with -i*pi instead of i*pi, we have:

\frac{a(\pi + i(- i \pi - \frac{2 i \pi z}{a}))}{2 \pi} = \frac{a (\pi - \pi + \frac{2 \pi z}{a}}{2 \pi} = \frac{2 \pi z}{2 pi} = z

This is correct, when you think that the log function can add or subtract 2 pi, in a sense, whenever it wants. I'm worried that your expression would not always give the right branch, especially if UF tried to simplify it or something wonky like that.

The reason mod(abs(z),a)*sign(z) doesn't work, shall be illustrated with an example: mod(-1.6,1). This should end up being 0.4, because the next smallest integer is -2, and -1.6 - (-2) = 0.4.

mod(abs(-1.6),1)*sign(-1.6) = mod(1.6,1)*-1 = -0.6

See? It's one less than it should be! For all negative numbers, it will be exactly one less than the correct value!  ^-^


Title: Re: "Modular" complex arithmetic
Post by: David Makin on March 27, 2010, 07:43:47 PM
The reason mod(abs(z),a)*sign(z) doesn't work, shall be illustrated with an example: mod(-1.6,1). This should end up being 0.6, because the next smallest integer is -2, and -1.6 - (-2) = 0.6.

Last time I looked -1.6-(-2) was 0.4 :)


Title: Re: "Modular" complex arithmetic
Post by: Timeroot on March 27, 2010, 10:09:22 PM
^fixed. But in any case, do you see my point as to why it's wrong?


Title: Re: "Modular" complex arithmetic
Post by: David Makin on March 27, 2010, 11:26:57 PM
^fixed. But in any case, do you see my point as to why it's wrong?

Not really as I haven't studied what's being done in this thread in detail.

In case it's relevant I think UF's mod function maybe slightly different from the norm - in UF:

  -1.6%1.0  ->   -0.6
  1.6%1.0   ->   0.6


Title: Re: "Modular" complex arithmetic
Post by: jehovajah on March 28, 2010, 10:51:00 AM
just a quick question: are you referring to mod or modulo or some combination of the two?


Title: Re: "Modular" complex arithmetic
Post by: jehovajah on March 28, 2010, 11:04:15 AM
The hangups we "mathematicians" have are due to us being taught to be hypercritical,usually by some sadist who delighted in pointing out our mistakes! Any way having got that off my chest i think playfulness means lots of wrong turns down the road to interesting stuff and your colour algorithm is veeeery interesting! ;D


Title: Re: "Modular" complex arithmetic
Post by: kram1032 on March 28, 2010, 12:31:17 PM
yup, the simplification seemingly doesn't even hold for the -1.6 example...

the sum-free formula returns 0.4, so it seems correct, the simplified formula some complex number and the log and exp free one actually even totally simplifys to -z, which makes it totally useless, of course...

a (i log(1-e^{-(2 \pi i z)/a})-i log(1-e^{(2 \pi i z)/a})+\pi)\over 2 \pi

if that formula indeed is the correct one, the cool thing about it would be, that a complex a also is defined that way. :)


Title: Re: "Modular" complex arithmetic
Post by: Timeroot on March 29, 2010, 01:56:29 AM
Hmm, yeah, I tried the exp/log formula, it doesn't seem to work for me...   :sad1:

I actually got that fourier series from a math book my dad gave me, but now I see if you type "-1.6 mod 1" into W|A you get the same thing under series representations.

When you say "the simplified formula", what do you mean? You'll see that both of the closed form formulas I gave give a final result of 0.4...


Title: Re: "Modular" complex arithmetic
Post by: kram1032 on March 30, 2010, 02:45:18 PM
EDIT!
Since LaTex apparently is (or at some point was) broken, all the results are lost...
Here is the final Complex Mod Function with z and a being complex numbers:

z mod a = CMod(z,a)=π+ i (e2 i π z/a Log(1-e-2 i π z/a)-e-2 i π z/a Log(1-e2 i π z/a))
_____________________________________________________________________________________________

the simplified formula was meant to be the one where I converted log()-log() to log(/).
That one somehow does not return correct results.

but if we stick to log()-log(), everything seems to work nicely.
Now I'd like to see an Mset with that formula rather than the symmetric approach.
Reading about mod, I found out that both variants are kind of valid. One, however, is called "mathematical" and the other one "symmetrical"

The symmetrical one is mod(|z|,a)*sign(z) and doesn't really allow for a complex a.
The mathematical one is the more complicated one...
(http://www.forkosh.dreamhost.com/mimetex.cgi?a%20(i%20log(1-e^{-(2%20\pi%20i%20z)/a})-i%20log(1-e^{(2%20\pi%20i%20z)/a})+\pi)\over%202%20\pi), which has the big advantage to even work in case of a complex a. No idea if that would make any sense, though :)