# [Maxima] continued fractions for nth degree roots

Stavros Macrakis macrakis at alum.mit.edu
Fri Feb 23 10:23:43 CST 2007

```On 2/23/07, Robert Dodier <robert.dodier at gmail.com> wrote:
>
> On 2/19/07, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>
> > Here's the code for continued fraction expansion of *arbitrary*
> > numerical-valued expressions, including transcendental functions. It is
> > pretty robust even for rational results, e.g. sin(2)^2+cos(2)^2 or
> > asin(1/sqrt(2))/%pi, and gives a warning when the result might look more
> > precise than it is.
>
> Thanks for posting the cf-bigfloat code. How does this fit into the
> existing cf stuff? Or is it a replacement?
>

As it stands right now, it is a prototype.  I posted it as Maxima code to
see what problems people could find with it, or ideas they had for improving
it.

It does not replace the basic rational-number or square-root functionality
of cf, though it could -- it is pretty simple.  It also does not replace the
code for arithmetic on *finite* continued fractions, e.g.
cf([1,2,2,2]*[1,2,2,2]) => [2, 144].
On the other hand, as I documented in a previous email, the current code is
grossly wrong for composed expressions.  For example:

cf(sqrt(2)*sqrt(3)), cflength=3 => [2,2,4,1,5,1,1,3]
cf(sqrt(6)), cflength=3 =>               [2,2,4,2,4,2,4]

This is because it first calculates the truncated cf of the parts, and
multiplies them. There is no way a priori of knowing which terms in the
result are correct. There also seem to be some egregious bugs (which aren't
worth fixing because of the above problem):

expr: sqrt(3)-sqrt(2)\$
float(expr) =>  0.318...
cf(expr),cflength=5 => [3, 6, 1, 5, 7, ...
cf(float(expr)) => [0,3,6,1,5...]
float(cfdisrep(cf(expr))), cflength=5 => 3.146...
float(cfdisrep(cf(expr))), cflength=100 => 3.146...

I do not see the usefulness of calculating cf(sqrt(2)*sqrt(3)) as
cf(sqrt(2))*cf(sqrt(3)), but perhaps someone else does.  I also don't see
the usefulness of the cflength parameter as currently defined.

If the prototype proves useful, I will be happy to reimplement it in Lisp to
replace the existing cf package.

-s
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.math.utexas.edu/pipermail/maxima/attachments/20070223/190ccd71/attachment.htm
```