       Re: How to do Continued fraction of polynomials

• To: mathgroup at smc.vnet.net
• Subject: [mg53206] Re: [mg53052] How to do Continued fraction of polynomials
• From: Daniel Lichtblau <danl at wolfram.com>
• Date: Tue, 28 Dec 2004 23:12:43 -0500 (EST)
• References: <200412220952.EAA04405@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Milind Gupta wrote:
> How can we do a continued fraction expansion in Mathematica.
>
>    Suppose we have
>              x^3 + 2x
>              ------------
>               x^2 + 1
>
> and we want:
>
>      x  +       1
>              -------------
>               x   +    1
>                         ----
>                           x
>
>      Can we get this by using some function or some technique in Mathematica??
>
> Regards,

One method is to iterate taking a quotient and remainder, keeping the
quotients and dividing previous remainders by new ones.

polynomialContinuedFraction[p1_,p2_,x_] := Module[{quot,rem,res},
Reap[NestWhileList[
({quot,rem} = Developer`PolynomialDivision[#[],#[],x];
Sow[quot,res];
{#[],rem})&,
{p1,p2},
!Developer`ZeroQ[#[]]&]][[2,1]]
]

In:= convergents = polynomialContinuedFraction[x^3+2*x, x^2+1, x]
Out= {x, x, x}

To change to the customary format you can use

pcfForm[{l1_}] := l1
pcfForm[ll_List] := First[ll] + 1/pcfForm[Rest[ll]]

In:= InputForm[pcfForm[convergents]]
Out//InputForm= x + (x^(-1) + x)^(-1)

Daniel Lichtblau
Wolfram Research

```

• Prev by Date: Re: including files
• Next by Date: Re: including files
• Previous by thread: How to do Continued fraction of polynomials
• Next by thread: Re: How to do Continued fraction of polynomials