On Apr 24, 5:50 pm, "William Stein" <[EMAIL PROTECTED]> wrote:
> On Thu, Apr 24, 2008 at 9:47 AM, John Cremona <[EMAIL PROTECTED]> wrote:
>
> > 2008/4/24 William Stein <[EMAIL PROTECTED]>:
>
> > > On Thu, Apr 24, 2008 at 7:35 AM, bill.p <[EMAIL PROTECTED]> wrote:
>
> > > > I needed to derive some continued fractions and a quick search of the
> > > > index suggests that the Pari-GP function 'contfrac' might be what I
> > > > needed.
> > > > A simple test in the notebook:
>
> > > > gp('contfrac(sqrt(6))')
>
> > > > produced
>
> > > > [2, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4,
> > 2, 4,
> > > > 2, 4, 2, 4, 2,
> > > > 4, 2, 4, 2, 4, 2]
>
> > > > which is not exactly what I expected. I'd expect either:
>
> > > > [2;2,4]
> > > > or
> > > > [2,2,4,2,4,2,4,2,4,....]
>
> > > > the latter implying that the expansion continues. Does the result
> > > > given mean that
> > > > Pari is using a limited precision evaluation of sqrt(6)?
>
> > > Yes.
>
> > > > I'd prefer
> > > > the first of my expected
> > > > results, giving a simple infinite continued fraction.
>
> > > There is no such functionality in pari or as far as I know in Sage.
>
> > > By the way, Sage also has a continued_fraction command.
>
> > > sage: a = continued_fraction(sqrt(6),200); a
>
> > > [2, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4,
> > > 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2,
> > > 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4]
> > > [2, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 2, 1]
>
> > In fact there is a whole "continued fraction field" implemented in
> > sage.rings.contfrac.py, with a lot of clever looking code in it, but
> > it does not (as far as I could see) implement the construction which
> > bill.p wanted from a quadratic surd. That file seems to have no
> > Author listed, so I don't know who wrote it!
>
> I wrote it. It indeed doesn't have any notion of infinite
> continued fraction.
>
> -- William
I now have some code for computing recurrent infinite continued
fractions and was thinking about
how I could fit this in with the existing CFF stuff. I've had a brief
look at contfrac.py and it would
seem that I will need to re-implement the whole lot as it needs more
than just a simple vector
of integers to express the repetition. I am willing to have a go at
this if there is a reasonable
probability that it would be useful. Can I request some feedback on
this?
My present thought is that I'd need a list of integers plus another
integer - the integer could either be the
number of non-recurring terms, or it could be the number of recurring
terms. Given the way that
Python handles negative indices I guess the second option could amount
to the same thing by
making it negative. Again, feedback welcomed.
Bill
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---