# François Viète's approximation to π

How do I program the approximation to π devised by François Viète, which is given by

2 * 2/Sqrt[2] * 2/Sqrt[2 + Sqrt[2]] * 2/Sqrt[2 + Sqrt[2 + Sqrt[2]]] * ...


using some of these functions: Nest, For, Module, Product, Do?

• I appreciate all of your answers, but these commands are not in the list I posted... Right now, I have come to this: PieApprox[n_] := 2/Nest[Sqrt[# + 2] &, Sqrt[2], n]. So I was thinking if someone could help me plug in the Product fonction to finish it, because I can't figure out how to do it. – Xavier Apr 18 '18 at 16:33
• @Xavier please see mathematica.stackexchange.com/help/merging-accounts – Kuba Apr 18 '18 at 18:44

You could use

VietePiApprox[n_] := (Times @@ NestList[Sqrt[2 + #] &, Sqrt[2], n])/ 2^(n + 1)
SetAttributes[VietePiApprox, Listable]


which approximates Pi as follows.

N[VietePiApprox[Range[5]] - 2/\[Pi]]


{0.0166617, 0.00410909, 0.0010238, 0.000255735, 0.0000639204}

Well, FoldList also can finish this job:

2/Times @@ (1/2 FoldList[Sqrt[2 + #] &, ConstantArray[Sqrt[2.], 10]])


By the way, by putting the one half just before NestList, FoldList can save one's effort for counting the number of twos in the denominators.

Clear[VietePiApprox];
VietePiApprox[n_] := Product[FunctionExpand[Cos[Pi/2^(i + 1)]], {i, 1, n}];
Table[VietePiApprox[i], {i, 1, 10}]
% - 2.0/Pi


{0.070487, 0.0166617, 0.00410909, 0.0010238, 0.000255735, \ 0.0000639204, 0.0000159792, 3.99476*10^-6, 9.98687*10^-7, 2.49671*10^-7}