MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Alternative cf format.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21573] Re: Alternative cf format.
  • From: Tobias Oed <tobias at physics.odu.edu>
  • Date: Sat, 15 Jan 2000 02:04:16 -0500 (EST)
  • Organization: Old Dominion University
  • References: <85ml1f$1ql@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Alan W.Hopper" wrote:
> 
> Dear Math group,
> 
> A message I meant to go to mathworld at wolfram.com  i.e. Eric Weisstein's
> encyclopedia project at Wolfram ,  http://mathworld.wolfram.com was
> posted
> inadvertantly as [mg21478] , I apologize for this, but if anyone has
> some
> comments to make about that CyclicDecimals notebook  of mine, I would be
> 
> interested to know about it.
> 
> But here is a separate little question for the mathgroup.
> 
> with Mathematica 3.0 ;
> 
> In[1]:=  <<NumberTheory`ContinuedFractions`
> 
> In[2]:=  cf = ContinuedFraction[87 / 37]
> 
>                               1
> Out[2]:=     2 + ---------
>                                    1
>                          2 + -------
>                                           1
>                                  1 + -------
>                                                   1
>                                          5 + -------
>                                                    2
> 
> In[3]:=  Normal[cf]
> 
> Out[3]=  87 / 33
> 
> Or has Mathematica 4 gone back to the old list format of Mathematica 2,
> (much more convenient for long periods),
> 
> as ;
> 
> In[4]:=  List @@ cf
> 
> Out[4]=  {{2,2,1,5,2}}
> 
> Now an alternative way of representing continued fractions is with the
> nested form ;
> 
> In[5]:=  2+1/(2+1/(1+1/(5+1/2)))
> 
> Out[5]=  87 / 33
> 
> My HP-48SX calculator can convert from the 'standard' to the nested
> formats (for short cont. frs) at the press of a key, and I imagine it
> would
> be straightforward to compose some Mathematica code, for the same
> purpose.
> Does anyone know a way to convert from the standard to the nested form,
> via the list form ?
> 
> Best wishes to all for the new year/decade/millenium ,
> 
> Alan W. Hopper
> 
> Katoomba, Australia.
> 
> awhopper at hermes.net.au

I think this does what you want

last/: Power[last,-1]=last
last/: Hold[last]=0

Fold[(#2+Hold[Evaluate[1/#1]] /. HoldForm[x_]:>x /.
Hold->HoldForm)&,last,Reverse[First[cf]]]

enjoy, Tobias


  • Prev by Date: Re: Q: NDSolve
  • Next by Date: Re: NDSolve
  • Previous by thread: Alternative cf format.
  • Next by thread: Problem with evaluation of delayed rules