home *** CD-ROM | disk | FTP | other *** search
- From: akcs.joehorn@hpcvbbs.cv.hp.com (Joseph K. Horn)
- Date: Tue, 29 Dec 1992 06:40:02 GMT
- Subject: Continued Fractions of Square Roots
- Message-ID: <2b3fee71.2531comp.sys.hp48@hpcvbbs.cv.hp.com>
- Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!hp-cv!hp-pcd!hpcvra!rnews!hpcvbbs!akcs.joehorn
- Newsgroups: comp.sys.hp48
- Keywords: continued fractions square roots partial quotients
- Lines: 67
-
- SQPQ - Square Root's Partial Quotients, by Joe Horn, 12/28/92
-
- Turning square roots of integers into continued fractions via the
- usual FP INV method rapidly introduces round-off errors, and does not
- help in determining where the continued fraction begins to repeat.
-
- The following program, SQPQ, uses a method which neatly avoids all
- round-off errors and automatically detects where the repetition
- begins.
-
- INSTRUCTIONS: SQPQ takes the integer (not its square root!) as its
- input, and returns a list of the partial quotients of the continued
- fraction equal to the square root of the input. The list terminates
- immediately after the last term of the repeating sequence. Therefore
- the entire list, except for the first element, repeats.
-
- EXAMPLE: What is the continued fraction for the square root of 18?
- 18 SQPQ --> { 4 4 8 } which means
- SQRT(18) = 4+1/(4+1/(8+1/(4+1/(8+... with 4 8 repeating.
-
- EXAMPLE: 28 SQPQ --> { 5 3 2 3 10 } which means
- SQRT(28) = 5+1/(3+1/(2+1/(3+1/(10+1/(3+1/(2+1/(3+1/(10+...
- with 3 2 3 10 repeating.
-
- EXAMPLE: 16 SQPQ --> { 4 } which means it's exactly 4.
-
- %%HP: T(3)A(D)F(.);
- @ SQPQ, Square Root's Partial Quotients, by Joe Horn, 12/28/92
- \<< DUP \v/
- IF DUP FP
- THEN 0 1 1 \-> N S A B L
- \<<
- DO S A + B / IP DUP B * A - 'A' STO
- N A SQ - B / 'B' STO
- 'L' 1 STO+
- UNTIL B 1 ==
- END A DUP + L \->LIST
- \>>
- ELSE SWAP DROP 1 \->LIST
- END
- \>>
-
- %%HP: T(1)A(R)F(.); @ SQPQ -jkh- 12/28/92
- "D9D20E163278BF1473B13CE2278BF13ABB1AFE22D9D204B2A29C2A29C2A21C43
- 2D6E2010E4D6E201035D6E201014D6E201024D6E2010C4E16323C032D6E20103
- 5D6E20101476BA1D6E20102450FA1D6BB178BF1D6E201024EEDA1D6E20101490
- DA145632D6E20101497632DCC02D6E2010E4D6E201014624B190DA1D6E201024
- 50FA145632D6E20102497632DCC0245632D6E2010C4976329C2A2B4402DE032D
- 6E2010249C2A2279E19B632D6E20101478BF176BA1D6E2010C4387C1EF532B21
- 305BF22D9D20DBBF18DBF19C2A2387C1B21305DF2293632B2130494F"
-
- BYTES: #F494h 218
-
- BEGIN--cut here--CUT HERE--
- begin 600 sqpq
- M2%!(4#0X+46=+>!A(X?[03<;PRYRN!^CNZ'O(ITM0"LJR:*2+"K!--+F`@%.
- M;2X0,-7F`@%!;2X0(-3F`@%,'C8R#"-M+A`PU>8"`4%GJ]'F`@%"!:_1MAN'
- M^]'F`@%"[JW1Y@(!00FM064C;2X0$)1G(\T,TN8"`4YM+A`09$(;":W1Y@(!
- M0@6O064C;2X0()1G(\T,0F4C;2X0P)1G(\FBLD0@[3#2Y@(!0LFB(I<>N3;2
- MY@(!08?[<;8:;2X0P#1X'/XULA(#M2_2V0*]^X&]'\FB,G@<*S%0_2(Y-K(2
- !`_\`
- `
- end
- END--cut here--CUT HERE--
-
- -Joseph K. Horn- -Peripheral Vision, Ltd.-
- akcs.joehorn@hpcvbbs.cv.hp.com
-
-