The continued fractions I want to work with are infinite repeating, so converting to rational doesn't help. The products will also be infinite repeating, though. If we can come up with a finite cf-product, I could adapt it to my uses.
Henry Rich Dan Bron wrote: > Henry wrote: >> Does anyone have J code for multiplying two numbers expressed as >> simple continued fractions, producing a continued-fraction result? > > Roger responded: >> As a first approximation, convert to two single (rational) numbers; >> mutliply; convert back. *&.conv > > Here's one way to do that: > > NB. Continued fraction to decimal > cf2d =: (+%)/ > > NB. Decimal to continued fraction > d2cf =: }:@:<.@:(%@:(-<.)^:(_&>)^:a:&.x:) > > NB. continued fraction <-> decimal > cf =: cf2d :. d2cf > > NB. Multiply continued fractions > cfM =: *&.cf > > I'm sure there are superior algorithms, in particular for d2cf . I'm > thinking along the line of Euler's GCD algorithm. There's a lot of depth > hidden in J's rational numbers and the relevant primitives (e.g. +. | > #: ). > > There might also be a direct way (without the intermediate conversion to > decimal), but no ideas occur to me, personally. > > -Dan > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
