home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / hp48 / 6560 < prev    next >
Encoding:
Internet Message Format  |  1992-12-29  |  2.7 KB

  1. From: akcs.joehorn@hpcvbbs.cv.hp.com (Joseph K. Horn)
  2. Date: Tue, 29 Dec 1992 06:40:02 GMT
  3. Subject: Continued Fractions of Square Roots
  4. Message-ID: <2b3fee71.2531comp.sys.hp48@hpcvbbs.cv.hp.com>
  5. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!hp-cv!hp-pcd!hpcvra!rnews!hpcvbbs!akcs.joehorn
  6. Newsgroups: comp.sys.hp48
  7. Keywords: continued fractions square roots partial quotients
  8. Lines: 67
  9.  
  10. SQPQ - Square Root's Partial Quotients, by Joe Horn, 12/28/92
  11.  
  12. Turning square roots of integers into continued fractions via the
  13. usual FP INV method rapidly introduces round-off errors, and does not
  14. help in determining where the continued fraction begins to repeat.
  15.  
  16. The following program, SQPQ, uses a method which neatly avoids all
  17. round-off errors and automatically detects where the repetition
  18. begins.
  19.  
  20. INSTRUCTIONS: SQPQ takes the integer (not its square root!) as its
  21. input, and returns a list of the partial quotients of the continued
  22. fraction equal to the square root of the input.  The list terminates
  23. immediately after the last term of the repeating sequence.  Therefore
  24. the entire list, except for the first element, repeats.
  25.  
  26. EXAMPLE: What is the continued fraction for the square root of 18?
  27. 18  SQPQ  -->  { 4 4 8 }  which means
  28. SQRT(18) = 4+1/(4+1/(8+1/(4+1/(8+...  with 4 8 repeating.
  29.  
  30. EXAMPLE: 28  SQPQ  -->  { 5 3 2 3 10 }  which means
  31. SQRT(28) = 5+1/(3+1/(2+1/(3+1/(10+1/(3+1/(2+1/(3+1/(10+...
  32. with 3 2 3 10 repeating.
  33.  
  34. EXAMPLE: 16  SQPQ  -->  { 4 }  which means it's exactly 4.
  35.  
  36. %%HP: T(3)A(D)F(.);
  37. @ SQPQ, Square Root's Partial Quotients, by Joe Horn, 12/28/92
  38. \<< DUP \v/
  39.   IF DUP FP
  40.   THEN 0 1 1 \-> N S A B L
  41.     \<<
  42.       DO S A + B / IP DUP B * A - 'A' STO
  43.         N A SQ - B / 'B' STO
  44.         'L' 1 STO+
  45.       UNTIL B 1 ==
  46.       END A DUP + L \->LIST
  47.     \>>
  48.   ELSE SWAP DROP 1 \->LIST
  49.   END
  50. \>>
  51.  
  52. %%HP: T(1)A(R)F(.); @ SQPQ -jkh- 12/28/92
  53. "D9D20E163278BF1473B13CE2278BF13ABB1AFE22D9D204B2A29C2A29C2A21C43
  54. 2D6E2010E4D6E201035D6E201014D6E201024D6E2010C4E16323C032D6E20103
  55. 5D6E20101476BA1D6E20102450FA1D6BB178BF1D6E201024EEDA1D6E20101490
  56. DA145632D6E20101497632DCC02D6E2010E4D6E201014624B190DA1D6E201024
  57. 50FA145632D6E20102497632DCC0245632D6E2010C4976329C2A2B4402DE032D
  58. 6E2010249C2A2279E19B632D6E20101478BF176BA1D6E2010C4387C1EF532B21
  59. 305BF22D9D20DBBF18DBF19C2A2387C1B21305DF2293632B2130494F"
  60.  
  61. BYTES: #F494h 218
  62.  
  63. BEGIN--cut here--CUT HERE--
  64. begin 600 sqpq
  65. M2%!(4#0X+46=+>!A(X?[03<;PRYRN!^CNZ'O(ITM0"LJR:*2+"K!--+F`@%.
  66. M;2X0,-7F`@%!;2X0(-3F`@%,'C8R#"-M+A`PU>8"`4%GJ]'F`@%"!:_1MAN'
  67. M^]'F`@%"[JW1Y@(!00FM064C;2X0$)1G(\T,TN8"`4YM+A`09$(;":W1Y@(!
  68. M0@6O064C;2X0()1G(\T,0F4C;2X0P)1G(\FBLD0@[3#2Y@(!0LFB(I<>N3;2
  69. MY@(!08?[<;8:;2X0P#1X'/XULA(#M2_2V0*]^X&]'\FB,G@<*S%0_2(Y-K(2
  70. !`_\`
  71. `
  72. end
  73. END--cut here--CUT HERE--
  74.  
  75. -Joseph K. Horn-   -Peripheral Vision, Ltd.-
  76. akcs.joehorn@hpcvbbs.cv.hp.com
  77.  
  78.