Ask Your Question
1

How to get multiplication of square roots to simplify?

asked 2023-03-17 19:54:15 +0100

ZakEspley gravatar image

updated 2023-03-30 20:01:52 +0100

FrédéricC gravatar image

All I want is for Sage to take the sqrt(3)*sqrt(2) and show me it is sqrt(6). I have looked through the forums and found a few solutions but they are all from 5+ years ago and don't seem to do anything any more. Here is an example:

from sage.manifolds.utilities import simplify_chain_real
a = var("a")
assume(a>0)
a = sqrt(2)*sqrt(3)+6
show(a)
show(simplify_chain_real(a))
show(a.simplify_real())
show(a.canonicalize_radical())

My output is the following for all of these: sqrt(3)*sqrt(2)+6

What do I need to do to get the output to display sqrt(6)+6? I am sure there is some really advanced mathematical reason for this not to work, but I just dealing with fairly standard stuff.

I am using the following version of Sage:

SageMath version 9.8, Release Date: 2023-02-11

edit retag flag offensive close merge delete

Comments

Please link to the solutions from years ago, so that updated versions can be posted.

rburing gravatar imagerburing ( 2023-03-30 15:39:56 +0100 )edit

This answer still works: a.maxima_methods().rootscontract()

rburing gravatar imagerburing ( 2023-03-30 15:51:06 +0100 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2023-03-30 16:27:42 +0100

Emmanuel Charpentier gravatar image

Well...

sage: (sqrt(3)*sqrt(2)+6)._sympy_().simplify()._sage_()
sqrt(6) + 6

HTH,

edit flag offensive delete link more
0

answered 2023-03-30 15:48:52 +0100

rburing gravatar image

One possible trick is to replace sqrt(2) by a variable t and sqrt(3) by a variable d, so you get a polynomial in t and d, and introduce a variable z for sqrt(6), and then reduce the polynomial in t and d by t*d - z using some monomial ordering where t*d > z, e.g. the lexicographic ordering with t > d > z, so that all instances of t*d are replaced by z, and then you can substitute z by sqrt(6):

def collect_sqrt2sqrt3_to_sqrt6(expr):
    expr_poly = expr.subs({sqrt(2) : var('t'), sqrt(3) : var('d')})
    R = PolynomialRing(SR, names=['t', 'd', 'z'], order='lex')
    t, d, z = R.gens()
    poly = expr_poly.polynomial(ring=R)
    poly_collected = poly.reduce([t*d - z])
    return SR(poly_collected.subs({z : sqrt(6), t : sqrt(2), d : sqrt(3)}))

Example:

sage: a = sqrt(2)*sqrt(3)+6
sage: collect_sqrt2sqrt3_to_sqrt6(a)
sqrt(6) + 6

With some more effort this could be generalized to detect which square roots appear in the expression, etc.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-03-17 19:54:15 +0100

Seen: 235 times

Last updated: Mar 30 '23