Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
4

Continued fraction expansion of quadratic irrationals

asked 13 years ago

Menny gravatar image

updated 13 years ago

Let me emphasize that I am very new to sage and to computing in general, but I did research as much as I could before asking this question.

It is well know that that quadratic irrationals has eventuallyperiodic continued fraction expansion. I really tried to find a function that gives me the period of a given quadratic irrational. The best I could find was in this forum: http://www.mail-archive.com/sage-supp...

It explains that you can get using GAP the PrePeriod+Period. It has two disadvantages: the first, you can't get the pure period, i.e., without the preperiod, and the second is that it is the input is not the number itself but the polynomial it solve. If this polynomial has many positive roots it is a problem...

I tried to look also in PARI and didn't find anything. I did see that it is written that sage itself does not have this function.

Let me also remark that such algorithm exist. My question: Is there a way (via packages that are contained in sage) to find the period of a given quadratic irrational?

Thanks a lot! Menny

Preview: (hide)

Comments

It seems that you are correct that this is not the case - yet. In fact, see http://groups.google.com/group/sage-support/tree/browse_frm/month/2008-05?_done=%2Fgroup%2Fsage-support%2Fbrowse_frm%2Fmonth%2F2008-05%3F& for something related. Can you point us to some of the algorithms? Also, the current expansion is in pure Python, so rather slow.

kcrisman gravatar imagekcrisman ( 13 years ago )

I didn't find the algorithm yet, but you can see that it is implemented in maple: http://www.maplesoft.com/support/help/Maple/view.aspx?path=numtheory/cfrac I'll go hunting for the algorithms.

Menny gravatar imageMenny ( 13 years ago )

It's also implemented (for some quadratic irrationals) in Mathematica / Wolfram|Alpha. See: http://www.wolframalpha.com/input/?i=continued+fraction+sqrt%2817%29%2F12 (period is 6) and http://www.wolframalpha.com/input/?i=continued+fraction+sqrt%28100027%29%2F12 (period is large, you'd have to count it yourself I guess after clicking "more terms" a bunch of times).

benjaminfjones gravatar imagebenjaminfjones ( 13 years ago )

I think what @Menny wanted was something that gives the period without having to count and click more terms :)

kcrisman gravatar imagekcrisman ( 13 years ago )

I mainly want to be able to work with it through sage and manipulate the results I'm getting. I can seems to find the algorithms.... I looked in Cohen books, and asked for the help of google and didn't find anything yet. Is there a generic references of Number theory algorithms?

Menny gravatar imageMenny ( 13 years ago )

4 Answers

Sort by » oldest newest most voted
3

answered 13 years ago

benjaminfjones gravatar image

As far as I can tell, there aren't any packages available in Sage beyond the GAP package you mention above. There is a relatively simple algorithm for finding the period and I think it would be worth implementing this in the continued fractions module in Sage.

I created a trac ticket for this enhancement: Trac #11345

A colleague of mine who works on diophantine approximation communicated an algorithm to me which I'll paraphrase below. The algorithm takes a specific quadratic irrational and would determine the pre-period (if desired), the periodic sequence, and the length of the period. The algorithm makes use of the following classical results (which I don't have specific references for yet).

Theorem(Galois): Let ζQ(D) be a positive quadratic irrational. Then ζ has a purely periodic continued fraction iff ζ>1 and the conjugate of ζ under the map DD is between -1 and 0.

Theorem(Lagrange?): The period of a purely periodic quadratic irrational ζ as above has length at most 2D (and this upper bound is sharp?). I'll need to find a reference for that.

Algorithm: (to determine the period of a quadratic irrational number)

INPUT: ζ, a positive quadratic irrational in the form ζ=q+rD for rational numbers q,r.

  1. Check if ζ is purely periodic (using the theorem above).
  2. If so, we know that the period has length at most 2D. We then determine the period by listing enough terms in the continued fraction approximation.
  3. If ζ isn’t purely periodic, replace ζ with 1ζfloor(1ζ) and go to step 1.

We get the length of the pre-period by counting the number of iterations above and we have an immediate upper bound on how much farther we have to search for the length of the period 2D.

Preview: (hide)
link

Comments

I've already said this on the Trac ticket, but it might be worth seeing if there is any code from GAP we could use, at least as pseudo-code. Also, how would we check for this being a quadratic surd? Sometimes very complicated things (think Cardano's formula-type stuff) end up being surds upon clever manipulation.

kcrisman gravatar imagekcrisman ( 13 years ago )

Just as a note, http://trac.sagemath.org/ticket/14567 seems to be almost ready...

kcrisman gravatar imagekcrisman ( 11 years ago )
2

answered 11 years ago

rws gravatar image

updated 11 years ago

The issue (among other things) is addressed in Sage by ticket 14567, after implementation of which you will be able to say:

sage: K.<sqrt11> = QuadraticField(11)
sage: cf = CFF(sqrt11); cf
[3; (3, 6)*]
sage: len(cf.period())
2

For literature, see also the OEIS database entry:

http://oeis.org/A003285

Preview: (hide)
link
0

answered 13 years ago

Menny gravatar image

Via the reference within this page: http://www.numbertheory.org/php/surd....

I found a more elegant algorithm than the one sketched above:

Algorithm for finding the period of a quadratic irrational

  1. Input: (a,b,c)Z×N×Z and b not a perfect square. This triple represents a+bc.

  2. If c does not divide ba2 then multiply everything by |c||c| , and get new triple that we call (a,b,c)

  3. Set P0=a , Q0=c, d=c.

  4. For k0 set

(a) αk=Pk+dQk

(b) ak=αk

(c) Pk+1=akQkPk

(d) Qk+1=dP2k+1Qk

  1. Then α0=a+bc=[a0,a1,a2,...]

  2. Let k<l be the first pair of integers which satisfy that (Pk,Qk)=(Pl,Ql) then the period of α0 is (ak,,al1) .

Hopefully this will help implementing it...

Preview: (hide)
link

Comments

That's very helpful. Thanks for the reference. I had already implemented a first draft of the algorithm I described above, but I think what you've described here is going to be much faster. If you want to look at what I've got so far, email me.

benjaminfjones gravatar imagebenjaminfjones ( 13 years ago )
0

answered 13 years ago

Menny gravatar image

As a continuation of the reply by Benjamin, Let me give some references and give more information.

Both Theorems appear in the book "Continued Fractions" By Andrew Mansfield Rockett and Peter Szüsz. The first is Theorem 3 on page 45, and the second is a remark before Theorem 1 on page 50. The second is not stated correctly (there should not be any coeffiecient before the square root):

Theorem(Lagrange Estimate): Let t=P0+DQ0 with D not a perfect square and P0,Q0 are integers. Then the length of the period of t is at most 2D.

A better asymptotics is given by the following (which is Theorem 1 of page 50):

Theorem: Let t be as above with the addtional assumption that Q0 divide DP20. Then if L(t) denoted the length of the period of t then L(t)=O(Dlog(D))

I'm not sure what the constant is (it is related to the divisor function)... I didn't read the proof yet!

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 13 years ago

Seen: 2,180 times

Last updated: Feb 20 '14