Periodic continued fractions -- suggestions wanted

• To: mathgroup at smc.vnet.net
• Subject: [mg23242] Periodic continued fractions -- suggestions wanted
• From: "Matthew Herman" <Henayni at hotmail.com>
• Date: Sat, 29 Apr 2000 22:04:50 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Here it is.

I would like some suggestions to make it more efficient

period::usage = "period[a,b] returns the period length of the reduced
irrational a, after iterating b times; if period[a,b] returns 0, it
means
that the pre-periodic part is the same as the periodic part. For
instance
period[2+Sqrt[5],10] returns 0 because the CF expansion is [4]"

period[a_, b_] :=
If[IntegerQ[a^2], Part[Part[Position[contfrac[a, Floor[4 a Log[a]]], 2
Floor[a]] - 1,1], 1], Part[Part[Position[FullSimplify[
FullSimplify[NestList[r, a, b - 1]] - Part[FullSimplify[NestList[r, a, b
- 1]], 2]], 0], 2] - 2, 1]]

r[x_] := 1\(x - Floor[x])

contfrac[a_, b_] :=  If[IntegerQ[a b], Part[FullExtendedGCD[a, b], 2],
Floor[NestList[r, a, b - 1]]]

Thanks,

Matt

```

• Prev by Date: FindRoot inside a loop
• Next by Date: Re: Applying position-dependent functions on lists.
• Previous by thread: FindRoot inside a loop
• Next by thread: Re:SPlus-like Dataframe-IO/UpValue for lists