Ask Your Question
1

how to best simplify product of square roots

asked 2020-01-12 11:17:34 +0100

rue82 gravatar image

updated 2020-01-13 11:25:29 +0100

I'd like to simplify expressions like

p1,p2,p3 = var('p1 p2 p3')
assume(p1>0,p2>0,p3>0)
R = p1*p2*sqrt(p3)*sqrt(p3/p1)*sqrt(p3/p2)
R

without using R.canonicalize_radical(), which unfortunately messes up other factors. I understand there are some options using R.simplify_chain_real(), but what else can I try?

Let us see an example where also R.simplify_chain_real() messes things up:

p1,p2,p3 = var('p1 p2 p3')
assume(p1>0,p2>0,p3>0)
# R = p1*p2*sqrt(p3)*sqrt(p3/p1)*sqrt(p3/p2)
R = p1*p2*sqrt(p3)*sqrt(p3/p1)*sqrt(p3/p2)/((p1 - p3)*(p2 - p3)*(p3 - 1))
%display latex
from sage.manifolds.utilities import simplify_chain_real
simplify_chain_real(R)
#R
edit retag flag offensive close merge delete

Comments

what is simplify_chain_real ? Not in Sagemath 9.1.beta0...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-01-12 11:56:27 +0100 )edit

One has to import it:

sage: from sage.manifolds.utilities import simplify_chain_real

It is documented here

eric_g gravatar imageeric_g ( 2020-01-12 18:05:43 +0100 )edit

Indeed, simplify_chain_real does the job here:

sage: simplify_chain_real(R)
sqrt(p1)*sqrt(p2)*p3^(3/2)
eric_g gravatar imageeric_g ( 2020-01-12 18:12:09 +0100 )edit

On general grounds, for real expressions, simplify_chain_real is safer than canonicalize_radical (see the doc examples for a case where canonicalize_radical yields a wrong result).

eric_g gravatar imageeric_g ( 2020-01-12 18:15:33 +0100 )edit

@eric_g I understand, but still simplify_chain_real messes things up, look at the second example I added.

rue82 gravatar imagerue82 ( 2020-01-13 11:24:02 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-01-13 14:30:13 +0100

Emmanuel Charpentier gravatar image

Possible workarounds:

  • Substitute what you want to be simplified in the original (larger) expression containing the (unspecified) pther factors (not shown in your exemples...), possibly helped by use of wildcard patterns.

Examples

sage: reset()
sage: from sage.manifolds.utilities import simplify_chain_real
sage: w0, w1=(SR.wild(u) for u in (0, 1))
sage: p1,p2,p3 = var('p1 p2 p3', domain="positive")
sage: ER = p1*p2*sqrt(p3)*sqrt(p3/p1)*sqrt(p3/p2)/((p1 - p3)*(p2 - p3)*(p3 - 1))
sage: E1, E2=var("E1, E2")
sage: E=E1*(E2+ER)
sage: E.subs(ER==simplify_chain_real(ER))
-(sqrt(p1)*sqrt(p2)*p3^(3/2)/((p1 + p2 + 1)*p3^2 - p3^3 + p1*p2 - ((p1 + 1)*p2 + p1)*p3) - E2)*E1
sage: E.subs(w0*(w1+ER)==w0*(w1+simplify_chain_real(ER)))
-(sqrt(p1)*sqrt(p2)*p3^(3/2)/((p1 + p2 + 1)*p3^2 - p3^3 + p1*p2 - ((p1 + 1)*p2 + p1)*p3) - E2)*E1
  • Specify exactly the subexpression(s) you want simplified via Maxima's part and subspart functions (available via the maxima_methods() objects).

@eric_g: shouldn't simplify_chain_real (and, better, a similarly named method for SR elements) be part of the standard code of SR ?

edit flag offensive delete link more

Comments

1

Yes one could imagine that. Probably, the best way would to put the simplify_chain_real code into the existing method simplify_real, thereby avoiding to create a new method in SR elements.

eric_g gravatar imageeric_g ( 2020-01-13 19:38:49 +0100 )edit

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: 2020-01-12 11:17:34 +0100

Seen: 509 times

Last updated: Jan 13 '20