Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7416
| From | "David Park" <djmpark@comcast.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Continued Fraction Form With Negative Numbers |
| Date | 2011-12-23 12:17 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jd1rgq$1sb$1@smc.vnet.net> (permalink) |
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@comcast.net
http://home.comcast.net/~djmpark/index.html
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Continued Fraction Form With Negative Numbers "David Park" <djmpark@comcast.net> - 2011-12-23 12:17 +0000
csiph-web