Re: [math-fun] "Dedecision"
(A) "Dedecision" is a Dedekind cut or the process of "making" one. The nice thing is that -cision means (making of) a cut. As in, well, decision, and also precision, concision, incision, excision, etc. I hope Dedekind doesn't mind. So, I wanted to get the *exact* value of round((j + 1/2) sqrt(2)) where j is an int. Um in Python. I have a floor-sqrt for arbitrarily big ints. And I know that I'll never have an exact halfway case to round because sqrt(2) is irrational. "All I have to do is" guess low by less than one, then see whether that's too low. The code is... well the derivation is ugly but what falls out looks sort of nice... and it has intermediate values like 8 j^2, but the thing I retained from what I read about Dedekind is that as long as you have a test for all the rationals, you've "captured" the real number. --Steve def round_j_plus_half_sqrt_2(j): """ Given int j, return *the exact* round((j + 1/2) * sqrt(2)). """ # round((j + 1/2) * sqrt(2)) # = round(sqrt((j + 1/2)**2 * 2)) # = round(sqrt((j**2+j+1/4))*2) # = round(sqrt((2*j*(j+1)+1/2))) # STEP 1: Take the floor rather than round. # k = floor(sqrt( 2*j*(j+1)+1/2) ) # = floor(sqrt(floor(2*j*(j+1)+1/2))) # = floor(sqrt( 2*j*(j+1) ) ) k = isqrt(2 * j * (j + 1)) # STEP 2: If k + 1/2 is too small, round it up. # test whether (k + 1/2)**2 < 2 * j * (j + 1) + 1/2 too_small = bool(4 * k * (k + 1) + 1 < 8 * j * (j + 1) + 2 ) return k + too_small -fin-
participants (1)
-
Steve Witham