Continued Fraction Form With Negative Numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg123859] Continued Fraction Form With Negative Numbers
- From: "David Park" <djmpark at comcast.net>
- Date: Fri, 23 Dec 2011 07:14:58 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
It is customary in generating continued fractions to allow negative integers for the first item but generate all the other quotients as positive integers. For instance, here is the article in Wikipedia that describes this form. http://en.wikipedia.org/wiki/Continued_fraction However, the Mathematica ContinuedFraction routine does not follow this convention with negative numbers. For example, ContinuedFraction[-16/7] FromContinuedFraction[%] {-2, -3, -2} -(16/7) The normal form of this would be: {-3, 1, 2, 2}; % // FromContinuedFraction -(16/7) The following is a recursive routine that follows the normal procedure - in case you want to experiment. continuedFractionR[x_, i_] := Module[{cflist = {}, gencf, a, b}, b = x; a = Floor[b]; cflist = {}; gencf[iter_][xnum_] := (AppendTo[cflist, a]; If[b == a || iter == 1, Return[cflist]]; b = 1/(b - a); a = Floor[b]; gencf[iter - 1][b]); gencf[i][x] ] Is there a reason that Mathematica doesn't follow the standard form with all positive quotients? Of course, the routine above doesn't handle quadratic irrationals with repeated quotient sequences and there may be theoretical reasons for not following the customary form. Nevertheless, I would still prefer positive quotients. David Park djmpark at comcast.net http://home.comcast.net/~djmpark/index.html