Praseodymium-141
Praseodymium-141

Reputation: 125

Finding square roots in surd form

I'm trying to build a program that let's you multiply two square roots and display the answer in surd form if the answer isn't an integer.

I've seen answers here and here, although I don't understand C++ and C#, so I don't have a clue on what to do. The first thing I've done is multiply the two numbers inside the square roots together, then I can display the answer if it is an integer, but if it isn't it completely messes up.

Upvotes: 1

Views: 363

Answers (2)

user1196549
user1196549

Reputation:

I don't see a better way than by factoring the given numbers, summing the multiplicities of the prime factors, extracting the even parts of the multiplicities and forming the square root of the products.

E.g.

√(84.375)=√(2²3.7.3.5³)=√(2²3²5³7)=2.3.5√(5.7)=30√35

Upvotes: 2

isaa_ctaylor
isaa_ctaylor

Reputation: 331

Try using SymPy:

>>>import sympy
>>>sympy.sqrt(8)
2*sqrt(2)

Upvotes: 2

Related Questions