Ask Your Question

.simplify_full() doesn't simplify an obvious trigonometric expression

asked 2018-11-23 02:50:56 -0600

sagenovice gravatar image

Hello, I'm trying to simplify a trigonometric expression, and it didn't work as I expected. The original example was larger, but I reproduced the issue with a smaller one:

sage: y = (sin(x)+2) * sqrt( sin(x) / (sin(x)^2 + 4*sin(x) + 4) )
sage: y.simplify_full()
sqrt(sin(x)/(sin(x)^2 + 4*sin(x) + 4))*(sin(x) + 2)

Why doesn't that turn into sqrt(sin(x))? What do I miss?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-11-23 08:02:54 -0600

slelievre gravatar image

This is because simplify_full does not attack square roots.

There is another method for doing that, which is called canonicalize_radical.

sage: y = (sin(x) + 2) * sqrt(sin(x) / (sin(x)^2 + 4 * sin(x) + 4))
sage: y.canonicalize_radical()
edit flag offensive delete link more


Ah, thank you! I've just read canonicalize_radical docs and it looks unsafe to use blindly. I experimented with it a little and reproduced a problem: ( (sin(x)-2) * sqrt( sin(x) / (sin(x)^2 - 4*sin(x) + 4) ) ).canonicalize_radical() becomes "sqrt(sin(x))" while it should be "-sqrt(sin(x))". I wonder if there's a way to tell it the sign to simplify sqrt()... But that should probably be another question. Thanks for your answer!

sagenovice gravatar imagesagenovice ( 2018-11-24 08:11:33 -0600 )edit

Yes, I think the "unsafe to use blindly" aspect was one reason for removing "canonicalize_radical" (which at the time was called "simplify_radical") from "simplify_full", in Sage Trac ticket 12737.

The sign issue is a recurring discussion which every time leads to a debate about what "sqrt" stands for: a multivalued function from the complex numbers to the complex numbers, or a single-valued function from the non-negative reals to the non-negative reals.

slelievre gravatar imageslelievre ( 2018-11-24 08:49:54 -0600 )edit

Thanks for the link and details! Personally I'd say sqrt() is a single-valued conditional function, and its symbolic representation depends on the sign of its argument, like, sqrt(x^2) = {x if x>=0; -x if x<0 }. It's just in my case the sign was known, so I hoped sage would guess that... Anyway, I posted that as a separate "canonicalize_radical produces incorrect result" question. I hope it makes sense.

sagenovice gravatar imagesagenovice ( 2018-11-24 09:32:05 -0600 )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


Asked: 2018-11-23 02:50:56 -0600

Seen: 48 times

Last updated: Nov 23 '18