Thanks to all for your comments.

The motivation for my approach is that in calculations with continued
fractions, you frequently want to keep going until some condition is
satisfied, and so you want to be able to get just one more convergent.

With (+%)/ , you cannot usefully reuse prior calculations.

The matrix approach uses the minimum state (the last 2 convergents)
and regards the next term of the expansion as specifying a transition.

The Haskell approach is doing the same thing, only in a scalar way.
It retains the full set of denominators or numerators, and perhaps
could be speeded up along the lines (for denominators).

fd=:3 : 0
d=.0 1
for_a. y do.
d=.({:,{.+a*{:) d
end.
)

One aim with the matrix approach for periodic continued fractions is
to calculate large convergents by using multiples of the period.  If
the periodic part is a1,...,an, you can form the matrix and calculate
high convergents using repeated squaring.

As a final note, J's normally useful rational numbers are less so
here: denominators and numerators of convergents are always coprime,
and so it suffices to deal with them separately.  This may have no
effect on performance.


Best wishes,

John



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to