I noticed that Weregoose created an algorithm to simplify a radical, but I found that using brute force is actually much more successful. This program will take a number or a square root as input, and will simplify it, for example, √(200, will simplify to 10√(2, all in easily less than a second. This program accepts both square roots as input, and the actually squared number, so 14.14213562 (√(200)) is valid input and so is just the number 200. They will both output 10√(2. But it gets better. Not only can this program handle square roots, it can handle cubed roots or any root you can think of just by storing the value to L1 as a one dimensional list. For example,
Code:
Right now the program is mildly buggy, but works very well otherwise. If something doesn't simplify that should, try putting it under the square root sign instead (or cubed root or whatever). While the calculator should be evaluating this in it's code, I find that doing this helps a lot for some reason. Anyway, here's the code:
The little x followed by the square root sign is the root sign under [MATH][5]
Code:
{3→L,,1,,:prgmSQUARE
Input =54
Output=3√2
Right now the program is mildly buggy, but works very well otherwise. If something doesn't simplify that should, try putting it under the square root sign instead (or cubed root or whatever). While the calculator should be evaluating this in it's code, I find that doing this helps a lot for some reason. Anyway, here's the code:
BASIC Code wrote:
:Full
:If 1≠dim(L1
:Then
:2→Z
:Else
:Disp "Root set to:",L1(1
:L1(1→Z
:End
:Input "Input =",A
:Lbl θ0
:If 0≠fPart(A
:A^Z→A
:If not(fPart(Z^x^√(A
:Then
:Disp "Perfect square:",Z^x^√(A
:Stop
:End
:round(A,0→A
:For(θ,1,int(Z^x^√(A
:If not(fPart(A/θ^Z
:Then
:Disp θ
:θ→B
:End
:End
:ClrHome
:Output(7,4,A/B^Z
:Output(8,4,B^Z
:(A/B^Z)►Dec
:Output(1,1,B
:Output(1,int(log(B))+2,"√(
:Output(1,int(log(B))+3,Ans
:Pause
:Return
Generated by SourceCoder, © 2005-2012 Cemetech
:If 1≠dim(L1
:Then
:2→Z
:Else
:Disp "Root set to:",L1(1
:L1(1→Z
:End
:Input "Input =",A
:Lbl θ0
:If 0≠fPart(A
:A^Z→A
:If not(fPart(Z^x^√(A
:Then
:Disp "Perfect square:",Z^x^√(A
:Stop
:End
:round(A,0→A
:For(θ,1,int(Z^x^√(A
:If not(fPart(A/θ^Z
:Then
:Disp θ
:θ→B
:End
:End
:ClrHome
:Output(7,4,A/B^Z
:Output(8,4,B^Z
:(A/B^Z)►Dec
:Output(1,1,B
:Output(1,int(log(B))+2,"√(
:Output(1,int(log(B))+3,Ans
:Pause
:Return
Generated by SourceCoder, © 2005-2012 Cemetech
The little x followed by the square root sign is the root sign under [MATH][5]