simplifying radicals

Started by
16 comments, last by sofsenint 20 years, 5 months ago
I have been writing a program for my TI-83 that simplifies radicals. For example, if you enter 512, it tells you that that is 16 * radical(2). I simply take the square root of the number entered and start at the largest integer not more than that square root, and decrease the number by one in each iteration. For each number, I square it, and if the square divides evenly into the original number (ex. 512), you factor that number out, and you are done. However, this is very slow when you start working with large numbers. Does anyone know of an algorithm or equation that is more efficient? Thanks! ----------------------------- Weeks of programming can save you hours of planning. There are 10 kinds of people in this world-- those who understand binary and those who don''t.
-----------------------------Weeks of programming can save you hours of planning.There are 10 kinds of people in this world-- those who understand binary and those who don't.
Advertisement
What is this for?

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
This is not homework. I''m trying to make a program on my calculator to do this so I can compare the speed of an algorithm that evaluates, say, the square root of 162 compared to one that evaluates nine times the square root of two. I''m trying a few different approaches to a fast square root- I know that this has been done millions of times before, but I get a lot of satisfaction from figuring these things out myself.

-----------------------------
Weeks of programming can save you hours of planning.

There are 10 kinds of people in this world-- those who understand binary and those who don''t.
-----------------------------Weeks of programming can save you hours of planning.There are 10 kinds of people in this world-- those who understand binary and those who don't.
I''ve got an idea. Say you have a "large" number like 5,012. First bitshift all the way to the right to isolate digit 5. Now, since this is base 10, you know that 5,000 equals 5 * 10 * 10 * 10. And you know you had to bitshift 3 times (ie 10 ^<b>3</b> by previously taking the length of the integer. So on the outside of the radical you already have 10*radical(10*5). Well, is that a start?

-leinad (my acct has been banned for some reason)
That''s an interesting idea. One question, though- if I understand you right, you would end up with an answer like 50 radical(2) + 2 radical(3), correct? This is not actually what I was going for (I meant simplest radical form), but I''ll try it out for efficiency anyway!

-----------------------------
Weeks of programming can save you hours of planning.

There are 10 kinds of people in this world-- those who understand binary and those who don''t.
-----------------------------Weeks of programming can save you hours of planning.There are 10 kinds of people in this world-- those who understand binary and those who don't.
no, (a + b) ^ .5 != a^.5 + b^.5. I just didn''t finish the algorithm. That would be a problem. It could even be a bad approach.
Oh, of course. I wasn''t thinking that through. So how would your algorithm work?
-----------------------------Weeks of programming can save you hours of planning.There are 10 kinds of people in this world-- those who understand binary and those who don't.
I don''t know it was a guess.
Perhaps it would be better to start at the bottom - since, for example, it''s very likely to have a sqrt(2) in it. You could go from 2 to sqrt of your number, checking if you get a perfect square when you divide your number by it.
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson
BTW, you''re not really simplifying radicals in general - you''re only doing square roots. Perhaps there is a way to optimize it for square roots...
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson

This topic is closed to new replies.

Advertisement