Re: Program:Simplifying radicals
[Prev][Next][Index][Thread]
> "Harry Elam" <hbe@way.com> writes:
> > jk@westnet.com (Jeff Kalikstein) writes:
> > Here is a nice, small, fast program to simplify a radical.
> [snip]
> > That's it! I would love to hear any feedback.
> >
> > Jeff
> >
> >>>>
> Your program seems to work beautifully on the TI-83.
>
> The program itself can be simplified a bit by eliminating
> Goto statements. Here's the TI-83 version in standard
> ASCII form, where symbols between backslashes
> represent single keystrokes:
>
> Ans\->\Q
> int(round(Q\^2\,5))\->\R
> 1\->\N
> For(B,int(Q),2,\(-)\1)
> B\^2\\->\S
> If R/S=int(R/S)
> Then
> NB\->\N
> R/S\->\R
> End
> End
> Disp N,R
>
> \->\ is STO->, \(-)\ is negate (-), and \^2\ is square.
>
> Harry
>
>
>>>>
After a little thinking, I realized that once the program has
found the *largest* perfect square which is a factor of R,
it is finished, since any other square factors of R must also
be factors of the largest square.
Here is a simpler version. It stops as soon as it is able to
simplify, and runs faster even when it can't, since it uses
only one test each time around the loop:
Ans\->\Q
int(round(Q\^2\,5))\->\R
int(Q)+1\->\N
Repeat Sint(R/S)=R
N-1\->\N
N\^2\\->\S
End
R/S\->\R
Disp N,R
Harry
References: