#๐Ÿ”’ Help with mandelbrot set calculation

28 messages ยท Page 1 of 1 (latest)

fathom relic
#

!paste

halcyon mulchBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

#

@fathom relic

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fathom relic
#

i am trying to make the mandelbrot set using a custom arbitrary floating point arithmetic c extension i wrote

drifting scarab
#

Just from the shape, it looks like you're giving up waiting for inifinity too early.

fathom relic
#

here is the main loop```py
cdef unsigned int mandelbrot( _cydecimal creal, _cydecimal cimag, const unsigned int maxiter, unsigned int testi, unsigned int testj) except *:
cdef _cydecimal temp1, real = creal, imag = cimag, real2, imag2
cdef unsigned int n
for n in range(maxiter):

    real2 = _square_decimal(real) # x^2 + y^2

    imag2 = _square_decimal(imag)

    temp1 = _add_decimals(real2, imag2) # x^2 + y^2 > 4

    if _true_greater_than(temp1,FOUR):
        return n


    imag = _add_decimals(_mult_decimals(TWO, _mult_decimals(real, imag)), cimag) # y = (2*x*y)+cimag
    real = _add_decimals(_subtract_decimals(real2, imag2), creal) # x = (x^2 - y^2) + creal

    #if _true_eq(real, creal):
    #    if _true_eq(imag, cimag):
    #        return maxiter
return maxiter```
drifting scarab
#

That's a shape you tend to get if you assume a number won't go off into infinity iirc.

fathom relic
#

huh

drifting scarab
#

maxiter in this case.

#

What value is being used for maxiter?

fathom relic
#

just 100 for now

#

well, 200 for the image

drifting scarab
#

That should give a better shape. I use 200.

fathom relic
#

and sometimes the image just doesnt show up??

#

after the calculations are done, the data is fine but plt doesnt show it

drifting scarab
#

I have no experience with plt, so I can't help with that unfortunately.

fathom relic
#

its alr

drifting scarab
#

test_point is comparable to your mandelbrot function.

fathom relic
#

i think i may have found the issue?

#
static inline char _close_zero(const _cydecimal_ptr first){
    exponent_t temp;
    if (first->exp < -(MAX_INDICE)){ // may lose a digit of precision :/
        return 1;  // if the exponent is super slow i.e practically zero
    } // 1 means YES - NUMBER IS ZERO
    else if (first->exp < -(N_DIGITS)){
        _normalize_digits(first, false);
        temp = ((first->exp)-_n_whole_digits(first)); // this is ignoring the decimal portion of the array - will check later
        if (temp < -(N_DIGITS)){ 
            return 0; // YES - NUMBER CLOSE TO ZERO, NO CALCULATIONS CAN BE FURTHER PERFORMED BUT THERE MAY STILL BE SPACE TO THE RIGHT
        }
        else{
            _normalize_digits(first, true); // maybe pushy (i.e removing beginning digits)
            temp = ((first->exp)-_n_precision(first));
            if (temp < -(N_PRECISION)){ 
                return 0; // YES - NUMBER CLOSE TO ZERO, NO CALCULATIONS CAN BE FURTHER PERFORMED BUT THERE MAY STILL BE SPACE TO THE RIGHT
            }
        }
    }
    return -1;  // NO - NUMBER DID NOT FILL UP ENTIRELY OR THE N_DIGITS SPACE
}```
#

this _close_zero function approximates if a number is close to zero (because if it is and i keep doing math on it, the exponent goes crazy)

#

this is probably rounding too much

halcyon mulchBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.