home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #23 / NN_1992_23.iso / spool / sci / math / 13299 < prev    next >
Encoding:
Text File  |  1992-10-16  |  11.6 KB  |  237 lines

  1. Newsgroups: sci.math
  2. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!agate!stanford.edu!CSD-NewsHost.Stanford.EDU!Sunburn.Stanford.EDU!pratt
  3. From: pratt@Sunburn.Stanford.EDU (Vaughan R. Pratt)
  4. Subject: Re: Looking for fast methods of computing PI
  5. Message-ID: <1992Oct16.111222.4303@CSD-NewsHost.Stanford.EDU>
  6. Sender: news@CSD-NewsHost.Stanford.EDU
  7. Organization: Computer Science Department,  Stanford University.
  8. References: <1992Oct13.025820.4593@eecs.nwu.edu> <-g1zrgc@rpi.edu>
  9. Date: Fri, 16 Oct 1992 11:12:22 GMT
  10. Lines: 225
  11.  
  12. In article <-g1zrgc@rpi.edu> fokp@rpi.edu writes:
  13. >I don't know what method you are talking about but I have been
  14. >thinking this problem for a long time and I found a way(the hard way)
  15. >to find PI.  I use the idea of polygon in a circle.  I first use 
  16. >a square to start with.  Then I turn the square into a octagon and find
  17. >the length of the side in terms of square root of 2. And then I 
  18. >double the number of side again and again and again.....
  19. >It works fine but the algebra is heavy.  I figure square root of 2
  20. >is easier to find than PI.  A friend of mine used taylor's series
  21. >to find Pi up to 5000 digit.
  22.  
  23. I'd like to take this opportunity to publicize some little-known
  24. aspects of this method.  What is well-known is that this is Archimedes'
  25. half-angle method, starting with a square rather than a hexagon.
  26. Archimedes' method yields exactly one bit of precision per "major"
  27. operation (= multiplication or square root), in contrast to Gene
  28. Salamin's early-1970's application of the Lagrange-Gauss
  29. arithmetic-geometric-mean method, which doubles the number of bits of
  30. precision at each iteration.
  31.  
  32. Before Lagrange-Gauss-Salamin, all improvements over Archimedes were
  33. mere constant factors, as follows.
  34.  
  35.     Inventor      Speed in bits/op     Method
  36.  
  37.         Archimedes, c.250 BC    1       half-angle method
  38.     Vieta, 1593        1    product(r=sqrt((r+1)/2))
  39.     Descartes, < 1650       1       constant perimeter method
  40.         Newton, 1666            2       series related to arcsin x
  41.         Sharp, 1705             1.585   Gregory(sqrt(3))
  42.         Machin, 1706            3.589   Gregory(5, 239)
  43.         Stoermer, 1896          3.168   Gregory(8, 57, 239)
  44.  
  45. Here Gregory(a1,a2,...,an) is the formula pi/4 = a linear integer
  46. combination of the arctan(1/ai)'s, e.g.  pi/4 = 6 arctan(1/8) + 2
  47. arctan(1/57) + 4 arctan(1/239).  Note that both Sharp's and Stoermer's
  48. "improvements" weren't, showing what happens when you don't do an
  49. explicit complexity analysis.  Both Sharp's and Machin's methods were
  50. used in early computer evaluations of pi.  For some reason Stoermer's
  51. method was later chosen by Shanks and Wrench over Machin's, perhaps due
  52. to inappropriate focus on the dominant arctan: arctan(1/8) must have
  53. seemed more promising than arctan(1/5).
  54.  
  55. What I want to do here is tie together the first three of these
  56. methods, and connect them up with the quadratrix of Hippias, in a
  57. strikingly simple way.  Oddly enough none of the extant treatments of
  58. pi seem to be aware of this unification, leading one to speculate that
  59. any previous discoverers must have decided it was too simple to bother
  60. mentioning.
  61.  
  62. The essence of all three methods resides in the following succinctly
  63. stated process step for turning one isosceles triangle into another.
  64.  
  65.     Make one half of an isosceles triangle isosceles by shortening
  66.     its hypotenuse.
  67.  
  68. In more detail, in the following figure the initial isosceles triangle
  69. is ROZ, with |OR| = |OZ|.  Take Z' to be the midpoint of RZ, and choose
  70. R' on OR (the hypotenuse of ORZ') so that |OR'| = |OZ'|, yielding a new
  71. isosceles triangle R'OZ'.
  72.  
  73.           O
  74.              /|\  
  75.             / | \ 
  76.            /  |  \
  77.           /   |   \       Isosceles triangle ROZ becomes isosceles
  78.          /    |    \      triangle R'OZ'.
  79.         R'    |     \
  80.        R------Z'-----Z
  81.  
  82. Now here's the beautiful part.  This step clearly halves the altitude
  83. from Z to OR, call it y, and also the angle ROZ, call it t, making the
  84. ratio y/t an invariant of the process.  But if we now iterate the
  85. process, in the limit y/t must equal the limiting length of OR, call it
  86. r.  Hence from the initial altitude y0 and the limit r of |OR| we may
  87. recover the initial angle t0 as y0/r.  In particular if we start with
  88. t0 = pi/2, and y0 = 1, then in the limit r = 2/pi.
  89.  
  90. This is the heart of Archimedes' method of computing pi.
  91.  
  92. Before getting into any more detail let's rotate the diagram 3/8 of a
  93. turn counterclockwise and coordinatize with X and Y axes thus.
  94.  
  95.         Y-----Z
  96.             |    /|\
  97.             |  r/ | \
  98.             Y'-/--+--Z'
  99.             | /\  |  |\
  100.             |/ t| |  | \
  101.     --------O-----X--X'LR
  102.         |\_x_/  / e' \___ |z|
  103.         | \_x'_/
  104.  
  105. So the essence of the process becomes a pair of points X,R moving
  106. respectively right and left, without ever passing.  Furthermore the
  107. line ZR gets steeper at each step, and the length |ZX| halves at each
  108. step, whence the triangle ZXR shrinks to a point, call this the
  109. limiting point L.  This makes it easy to see that the method
  110. converges.
  111.  
  112. If we regard the point Z as the complex number z then our basic process
  113. step can be described even more succinctly as z := (z + |z|)/2, call
  114. this ALGORITHM A.
  115.  
  116. Both rectangular coordinates, z = x+iy and polar, z = r exp(it), will
  117. come in handy.  That is, x=Re(z), y=Im(z), r=|z|, t=atan(y/x) (see
  118. diagram).  Primes x',y', etc. denote the corresponding values after the
  119. step.
  120.  
  121. Precision.  Set e' = r-x' = |X'R|, the *error*, in the sense of a
  122. (weak) upper bound on |X'L|, the remaining distance X has to travel
  123. after the current step taking it to X'.  Since OZ'R is a right-angled
  124. triangle with altitude y', we have x'e' = y'^2, so at the previous
  125. stage xe = y^2.  It follows that as x converges to its limit and y
  126. continues to halve, e must be reduced by a factor of 4 at each step.
  127. Hence as it approaches the limit the method contributes two bits of
  128. precision to the answer at each iteration.
  129.  
  130. Cost.  Each iteration can be implemented with real arithmetic via
  131. ALGORITHM B:  x := (x + sqrt(x^2+yy))/2, yy := yy/4; where z = x+iy and
  132. yy is a variable doing the job of y^2.  This costs one multiplication
  133. and one square root, i.e. two "major" operations (we will count
  134. division by 4 as an inexpensive shift).  Hence the method obtains one
  135. bit of precision per major operation.
  136.  
  137. Initializing z to i (t = 90 degrees, r = 1) corresponds to starting
  138. Archimedes' method with a square.  Archimedes actually started with a
  139. hexagon, for which the appropriate initialization is "1 o'clock" (t =
  140. 60 degrees, r = 1).
  141.  
  142. The points visited by z lie on the *quadratrix*, a curve generally
  143. attributed to Hippias, c. 525 BC, and studied in detail two centuries
  144. later by Deinostratos in its role as a device for squaring the circle.
  145. The quadratrix is given by r sin(t) = at  where a is a suitable
  146. constant, e.g. 2/pi when z is initially i.  That the process tracks the
  147. quadratrix follows very easily from r sin(t) = y, which along with t is
  148. halved at each step.  (Neat, eh?)
  149.  
  150. In Archimedes' construction two parallel series of progressively finer
  151. polygons converge on a circle from both sides.  We may obtain this
  152. effect by modifying the method to renormalize z at each step, scaling
  153. it by an appropriate real so as to keep |z| constant.  This causes z to
  154. now follow a circle instead of a quadratrix.   This entails rewriting
  155. the basic step as ALGORITHM C: z := (z + r)/2; z := z*r/|z|, where r is
  156. now constant, namely the initial value of |z|.  R no longer moves
  157. inward since the scaling keeps resetting it, whence the common limit L
  158. of X and Z must be R.
  159.  
  160. The points Z and R in this modified construction correspond to two
  161. consecutive vertices of the inside polygon in Archimedes'
  162. construction.  Scaling those two points by the above scaling factor
  163. (that put Z' back on the circle) yields two consecutive vertices of the
  164. outside polygon, with Z' (as scaled) at their midpoint.
  165.  
  166. We now kill two birds with the one stone: we give Archimedes' analysis
  167. and Vieta's formula using the same reasoning.
  168.  
  169. Since R goes nowhere it follows that the cumulative effect of all these
  170. scalings, an infinite product, is to stretch the old OL out to the new
  171. (fixed) OR.  If z is initially i then this stretch must be pi/2.
  172. Vieta's formula expresses 2/pi as sqrt(1/2) * sqrt((sqrt(1/2)+1)/2) *
  173. ... where the factor following factor x is sqrt((x+1)/2).  We derive
  174. this by showing that these factors are the reciprocals of the scale
  175. factors at each step.
  176.  
  177. Let z" denote (z+r)/2, the value of z halfway through the step from z
  178. to z'.  Let the line OZ"Z' meet the vertical line x=r (the tangent to
  179. the circle at R) at Q (so the line is OZ"Z'Q in that order).  Q is
  180. called the *inverse* of Z" in the circle and satisfies |OZ"|*|OQ| =
  181. |OZ'|^2 (see e.g. Coxeter, "Intro. to Geometry", section 6.1 on
  182. inversion, or prove it from scratch using the similarity of the
  183. triangles OZ"R and ORQ, and |OR|=|OZ'|).  That is, Z' is at the
  184. geometric mean of Z" and Q; algebraically, z' = sqrt(z"*q).  By
  185. proportionality this relationship must also hold of their x
  186. coordinates, that is, x' = sqrt(((x+1)/2)*r), which when r=1 becomes
  187. sqrt((x+1)/2).  This can be seen to also be the reciprocal of the
  188. desired scaling factor, giving us Vieta's formula for 2/pi as
  189. promised.  Note that Vieta's factors are exactly the values of x we
  190. encounter as we run Algorithm C.  This suggests
  191. ALGORITHM D: x := sqrt((x+1)/2), y := y/(2*x), as the real-valued
  192. version of Algorithm C in the case r=1.
  193.  
  194. But this same picture can now be used to understand Archimedes' inner
  195. and outer polygons.  Each factor of Vieta's product shrinks the outer
  196. bounding polygon down to the inner one.  The first factor, sqrt(1/2),
  197. shrinks the square, the next the octagon, etc.  (The factors are larger
  198. (closer to 1) if we start from a hexagon instead of a square, with
  199. their product yielding 3/pi instead of 2/pi.)
  200.  
  201. Archimedes used the perimeter of each polygon to bound the
  202. circumference above and below.  Since OZ"R is congruent to OX'Z', y
  203. gives half the length of one side of the inner polygon, whence y/x (for
  204. r=1) gives the corresponding distance for the outer one.  These values
  205. can be extracted from Algorithm D and multiplied by twice the number of
  206. sides to give the perimeter.  But this multiplication simply undoes the
  207. division of y by 2 at each step of D.  Hence Archimedes' method has for
  208. its sequence of lower bounds on pi (upper bounds on 2/pi) initial
  209. segments of Vieta's product.  For its upper bounds on pi (lower bounds
  210. on 2/pi) it has the same thing but with the sqrt omitted from the last
  211. factor of that segment, since dividing y by x has the effect of
  212. supplying a second copy of the last factor.  (So this also tells us how
  213. to use Vieta's formula directly to bound pi from above and below using
  214. any given initial segment: the segment itself gives the lower bound
  215. while dropping its last sqrt gives the upper.)
  216.  
  217. Descartes' method.  The term "half-angle" reminds one of the half-angle
  218. formulas for tan(2t) = 2 tan(t)/(1-tan^2(t)), call this H =
  219. 2h/(1-h^2).  This inverts as h = (sqrt(1+H^2)-1)/H.  Initializing h to
  220. 1, corresponding to t = pi/4, and iterating h := (sqrt(1+h^2)-1)/h  for
  221. k steps, yields t = pi/2^(k+2).  Since tan(t)/t tends to 1 as t tends
  222. to 0 we may approximate pi by h 2^(k+2) after k steps of this process.
  223. This is essentially Descartes' method of computing pi.
  224.  
  225. But tan(t) is simply y/x, the value we used in conjunction with
  226. Algorithm D for half a side of the outer polygon.  Hence Descartes'
  227. method yields exactly the same values as Archimedes' method for the
  228. outer polygon (so Descartes produces only upper bounds on pi).
  229.  
  230. (This account of Descartes' isn't as nice as I'd intended; I'd hoped to
  231. equal the standards of the preceding methods by omitting all
  232. trigonometric identities.  I would be very grateful if someone would do
  233. Descartes "right".)
  234.  
  235. -- 
  236. Vaughan Pratt   pratt@cs.Stanford.EDU     exp(n pi sqrt(163)/3) for n=1..30
  237.