Re: "frac2" button


[Prev][Next][Index][Thread]

Re: "frac2" button



For anybody interested, here is the basic algorithm of the Hp-48 program
that does the Frac->2 function so well.  Hopefully it could be ported to
the Ti's.  The source code unfortunately is in SYSRpl, so it can't be
directly converted to a Ti.  And yes, it works darn well and fast.

                        QPI v4.2                        Mika Heiskanen
                        --------
mheiskan@delta.hut.fi

        Based on QPirac by A.Coulom and MuPAD rationalize command.

QPI approximates any floating point numbers by a rational number, square
root, multiple of PI, exponential or a logarithm depending on which
approximation seems best.

QPI should work in all ports of any HP48 SX/GX model.

Allowed argument types are

        real number             --> symbolic / real number
        complex number          --> symbolic / real number
        identifier              --> identifier
        local name              --> local name
        symbolic                --> symbolic
        array of real/complex   --> list of symbolic/real
        constants (PI,e)        --> constant
        list of above           --> list of above

The rational approximation algorithm is taken from MuPAD, and works
quite
well for numbers of any scale. The decision procedure for the minimal
approximation of real numbers is as follows

        If x=zero then return (x)
        nom,den=approximate(x)
        If den < 100 then return (nom/den)              % Early abort
        nom2,den2=approximate(x*x)
        If (x*x<5E5) & (den2<1000) & (den2<den) then    % Choose
'smaller'
                nom,den=sign(x)*nom2,den2
                If nom<10 then return (sqrt(nom,den))   % Early abort
        nom2,den2=approximate(x/pi)
        If (|x/pi<100) & (den2<1000) & (den2<den) then  % Choose
'smaller'
                nom,den=nom2,den2
                If nom<10 then return (nom/den*pi)      % Early abort
        nom2,den2=approximate(exp(x))
        If (den2<50) & (den2<den) then                  % Choose
'smaller'
                nom,den=nom2,den2
                If nom<10 then return (ln(nom/den))     % Early abort
        nom2,den2=approximate(ln(x))
        If (x>0) & (den2<50) & (den2<den) then          % Choose
'smaller'
                nom,den=nom2,den2
                If nom<10 then return (exp(nom/den))    % Early abort
        Return (nom/den) in the found minimal form

The rational approximation algorithm itself uses 9-digit accuracy in
the approximation by default. The accuracy can be overridden by using
the FIX/SCI/ENG modes where the accuracy is taken to be the accuracy
of the display (1-11).

Example:

        [ -.714285714286  -1.41421356237  ]
        [ -.405465108108   1.11751906874  ]
        [ -2.44346095279    .657047293577 ]

        ==>

        { {   '-5/7'      '-SQRT(2)'    }
          { 'LN(2/3)'     'EXP(1/9)'    }
          { '-7/9*PI'  '5/7*SQRT(11/13' } }



Mark P. Wilson
E-mail:  im1077@exmail.usma.edu



> ----------
> From:         David Starr[SMTP:burke@THERAMP.NET]
> Reply To:     burke@TheRamp.net
> Sent:         Tuesday, January 27, 1998 11:05 PM
> To:   CALC-TI@LISTS.PPP.TI.COM
> Subject:      Re: "frac2" button
>
> I hate to do this, but there is a wonderful library for the HP (only
> about 1.5 kb) that does what this guy is looking for.  It's called
> QPI.
> It can't give the result you want all the time (since it only handles
> a
> finite number of representations and is limited by the input as well
> as
> some other things) but it converts numbers to fractions, multiples of
> pi, exponential form, logarithmic form, or square roots.  Here are
> some
> examples:
>
> .6123724356 -> 1/2*sqrt(3/2)
> .3737373737 -> 37/99
> 4.71238898  -> 3/2*pi
> 12.18249396 -> e^(5/2)
> .2876820724 -> ln(4/3)
>
> I just thought I should mention this since the discussion seemed to be
> drifting along the lines of feasibility.  So I thought you should
> know.
>
> -David-
>
>
>
>
> Blakely wrote:
> >
> > I hear roumers of ppl working on a symbolic manipulation for the
> ti-86!
> > does anyone have any further info on how or where i can get this
> > invofmatin?
> >
> > Tavis Segura <tsegura@rice.edu> wrote in article
> > <34CD5CB0.1C4C@rice.edu>...
> > > First of all, the TI-92 does symbolic math, but once you
> approximate
> > > your numbers, you are not much better off than you are on the '85.
> The
> > > "exact()" command is not foolproof: do divination there.  Take a
> look.
> > > The function
> > >
> > > approx(sqrt(2)/2)
> > >
> > > will return .70710678118655 for an answer.  In that case,
> > >
> > > exact(.70710678118655)
> > >
> > > would return sqrt(2)/2, wouldn't it?  Not a chance.  All it gives
> you is
> > > a large fraction:
> > >
> > > 14142135623731
> > > --------------
> > > 20000000000000
> > >
> > > Adjusting the tolerance (a second parameter to adjust for roundoff
> > > errors) does not do any better:
> > >
> > > exact(.70710678118655,1*10^-13)
> > >
> > >  =   2744210
> > >      -------
> > >      3880899
> > >
> > > In short, The TI-92 cannot do this "frac2" stuff.  It is a truly
> amazing
> > > machine, but don't expect too many miracles.  (Sigh) I guess you
> have to
> > > figure out the numbers yourself (like multiplying by sqrt(2) in
> this
> > > example to get approximately 1.) or using better judgement about
> what
> > > you want your calculator to approximate.
> > >
> > > Tavis
> > >
> > > Chopps wrote:
> > > >
> > > > then how do you explain how the ti-92 does it?  I want some kind
> of
> > > > symbolic manipulation, that i hear ppl are working on!!!
> > > >
> > > > RWW Taylor <RWTNTS@RITVAX.ISC.RIT.EDU> wrote in article
> > > > <01ISU8F74CAUCIRDY1@ritvax.isc.rit.edu>...
> > > >
> > > >
> > > > > As soon as you can input a decimal that is _exactly_ equal to
> half
> > > > > the square root of 3, then you can start thinking about how to
> create
> >
> > > > > a "frac2" button that will report this.  But that will be a
> very long
> > > > > time!
> > > > >
> > > > > The best you can possibly do is make a _guess_ or a _bet_ that
> the
> > > > > decimal value in your hands was really meant to be an
> approximation
> > > > > of some particular easily-described irrational value.  If you
> have
> > > > > some 12- or 13-place representation stored in memory W, for
> example,
> > > > > you might try using Frac on W^2 and decide whether you like
> what you
> > > > > see.  Another plausible effort might be to divide W by pi (and
> try
> > > > > Frac again, maybe).  Of course, what you have might just be a
> > > > > representation of 2 minus the square root of 3, or the
> > > > > cube root of 5 plus the cube root of 7, or pi^2, or some
> weirder
> > > > > number that you will never guess the secret of.  Calculators
> are
> > > > > wonderful, but they have no supernatural powers of divination
> (as far
> > > > > as I know, anyway).  :-)}
> > > > >
> > >
>