Message Boards Message Boards

Formula for computing sqrt(2) of binary numbers

Attachments:
POSTED BY: Mariusz Iwaniuk
13 Replies
Posted 4 months ago

Hello, here is one I have found recently:

The n'th binary digit of sqrt(2) is given by

floor(Sum_{n>=1} A005875(n)/exp(Pi*n/(2^((2/3)*k+(1/3))))) mod 2

Will give the k-th binary digit of sqrt(2), where A005875 is the number of ways to write n as sum of 3 squares. See image of the formula : r_3(n) is A005875.
enter image description here

NOTE : there is one for sqrt(10) also which is

enter image description here

NOTE 2: The series converge quite slowly but there is a marker for the decimal point which enables to get the n'th. The actual precision is very high when k >> 1.

POSTED BY: Simon Plouffe

Yes, I found this formula.Is it new? Probably so. I searched in the web, but did not find a similar formula.

I tried to simplify, but I have not yet succeeded.

POSTED BY: Mariusz Iwaniuk

No is not algorithm, it's better than that. It simple, it's a formula, or function.

An example:

To start calculating binary digits from, say, the 8th place only need substitute for n=8,9,10,11,12,13,14,15....That it's all.

formula =1/2 - (2 ArcTan[Cot[2^(-(3/2) + n) \[Pi]]])/\[Pi] + ArcTan[Cot[2^(-(1/2) + n) \[Pi]]]/\[Pi]

sol = Table[formula, {n, 8, 15}] // N // Round

${1, 0, 0, 0, 0, 0, 1, 0}$

and say from n=1....15:

 sol2 = Table[formula, {n, 1, 15}] // N // Round

${1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0}$

POSTED BY: Mariusz Iwaniuk
POSTED BY: Mariusz Iwaniuk
POSTED BY: Sander Huisman

Finding formula for the n-th digit in the binary representation of Sqrt[2] using Floor function.

 sol = RSolve[{b[n + 2] == a[n + 1] - 2*a[n], a[n] == Floor[Sqrt[2]*2^n], b[0] == 1, b[1] == 0}, {b[n], a[n]}, n]
 sol2 = FullSimplify[b[n] /. sol[[1]], Assumptions -> {n > 0, n \[Element] Integers}]

$$B_n=-2 \left\lfloor 2^{-\frac{3}{2}+n}\right\rfloor +\left\lfloor 2^{-\frac{1}{2}+n}\right\rfloor$$

This is formula for the n-th digit in the binary representation of $\sqrt{2}$ for $n > 0$ and $n\in \mathbb{Z}$ using Floor function.

 Table[sol22 /. n -> m, {m,}] 

$ {1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, \ 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, \ 1, 0, 0, 1} $

POSTED BY: Mariusz Iwaniuk

I am interested in proving that the proportion of binary digits of $\sqrt{2}$ is exactly $\frac{1}{2}$, and I have worked on this for a long time. You wrote a great article using the Fourier series expansion for the fractional part function. I am looking at a simpler formula (I have yet to find one!) but have asked my question on StackExchange, here. For your convenience, my question is posted below:

Is it possible to find an expression of the form $$\lfloor 2^n \sqrt{2}\rfloor = \sum_{k=1}^r (\alpha_k + \beta_ki)\cdot\Big(a_k+b_k i\Big)^n, $$ where $i^2 = -1$ and $\alpha_k, \beta_k, a_k, b_k$ real numbers? Maybe with $r< 5$ if possible. I am trying to compute the mean value (average) of $\{ 2^n \sqrt{2}\}= 2^n \sqrt{2} - \lfloor 2^n \sqrt{2}\rfloor$ over $n=0, 1,2, \cdots$. Let us denote as $p$ this mean value: $p$ is the proportion of binary digits of $\sqrt{2}$ equal to one, and $p$ is widely believed to be equal to $\frac{1}{2}$.

Note that $$p=\lim_{n\rightarrow\infty} p_n, \mbox{ with } p_n = \frac{1}{n}\sum_{k=1}^n \Big( 2^k \sqrt{2} - \lfloor 2^k \sqrt{2}\rfloor\Big).$$ Assuming we have a simple closed form for $\lfloor 2^k \sqrt{2}\rfloor$ as suggested in the first formula, then we can have a closed form for $p_n$, involving a finite number of terms. I don't expect this to be true if you replace $\sqrt{2}$ by (say) $\pi$ or $\log 2$, but I would expect this to work with any quadratic irrational.

Of course you can always use the Fourrier series to represent the fractional part function, but I don't think it would be easy to handle: it involves an infinite number of terms ( $r=\infty$.)

Neat! Is it your result and is it new? Do you think expression can be simplified? This does not work

$$\arctan{u}+\arctan{v}=\arctan\left(\frac{u+v}{1-uv}\right)$$

but maybe similar trigonometry.

POSTED BY: Sam Carrettie

I think it is then a spigot algorithm, because you have extensions, like the famous one for Pi in base 16 which calculates the nth digit directly... Algorithm here can be read as function:

> A further refinement is an algorithm which can compute a single arbitrary digit, without first computing the preceding digits: an example is the Bailey-Borwein-Plouffe formula, a digit extraction algorithm for ? which produces hexadecimal digits.

https://en.wikipedia.org/wiki/Spigot_algorithm

POSTED BY: Sander Huisman

You're right.So let it be.

Have a nice day. :)

Mariusz.

POSTED BY: Mariusz Iwaniuk

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: Moderation Team

Try, where u is Pi:

F[n_, b_, u_] := Floor[b^(-1 + n) *u] - b*Floor[b^(-2 + n) *u] ;

{Table[F[n, 10, ((2^(2 + 4 n) (1 - 3^(-1 - 4 n)) (4 n)!)/
EulerE[4 n])^(1/(1 + 4 n))], {n, 1, 50}], mm = N[Pi, 50];  
RealDigits[mm, 10][[1]]} // MatrixForm
(*Pi for base = 10 *)

{Table[F[n, 2, ((2^(2 + 4 n) (1 - 3^(-1 - 4 n)) (4 n)!)/
EulerE[4 n])^(1/(1 + 4 n))], {n, 0, 55}], mm = N[Pi, 17]; 
RealDigits[mm, 2][[1]]} // MatrixForm 
(*Pi for  base = 2 *)

Formula the n-th digit off Pi for base=b:

$B_b(n)=\left\lfloor b^{-1+n} \left(\frac{2^{2+4 n} \left(1-3^{-1-4 n}\right) (4 n)!}{E_{4 n}}\right){}^{\frac{1}{1+4 n}}\right\rfloor -b \left\lfloor b^{-2+n} \left(\frac{2^{2+4 n} \left(1-3^{-1-4 n}\right) (4 n)!}{E_{4 n}}\right){}^{\frac{1}{1+4 n}}\right\rfloor$

Where: EulerE[4 n] are Euler numbers.

   f[n_] := I Sum[Binomial[k, l] ((-1)^l*(k - 2 l)^(4 n + 1))/(2^k*I^k*k), {k, 1,4 n + 1}, {l, 0, k}]
   Table[{EulerE[4*n], f[n]}, {n, 1, 5}] // MatrixForm

Regards M.I

POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract