Ask Your Question

sagenovice's profile - activity

2019-05-24 10:34:40 +0100 received badge  Nice Question (source)
2018-12-03 18:08:12 +0100 received badge  Good Question (source)
2018-12-03 13:29:55 +0100 received badge  Nice Question (source)
2018-12-03 04:22:20 +0100 asked a question Sage doesn't simplify a fraction if it's multiplied by 2

Hello, for some reason sage doesn't simplify a trigonometric expression:

sage: ( 2 * (1-cos(x)) / sqrt(1-cos(x)) ).simplify_full()
-2*(cos(x) - 1)/sqrt(-cos(x) + 1)

while I'd expect sqrt(1-cos(x)).

I also tried a nice simplify_chain_real function (thanks eric_g for the hint) but I've got the same result:

sage: from sage.manifolds.utilities import simplify_chain_real
sage: simplify_chain_real( 2 * (1-cos(x)) / sqrt(1-cos(x)) )
-2*(cos(x) - 1)/sqrt(-cos(x) + 1)

The weird thing is that it works without the 2* part:

sage: ( (1-cos(x)) / sqrt(1-cos(x)) ).simplify_full()
sqrt(-cos(x) + 1)

And even replacing - with + makes it working:

sage: ( 2*(1+cos(x))/sqrt(1+cos(x)) ).simplify_full()
2*sqrt(cos(x) + 1)

I mean, obviously, it can do that kind of simplification. But I can't make it simplify the 2*(1-cos(x))/sqrt(1-cos(x)) expression. What do I miss?

2018-11-25 18:45:19 +0100 received badge  Good Question (source)
2018-11-25 17:53:23 +0100 received badge  Supporter (source)
2018-11-25 17:53:20 +0100 commented answer .canonicalize_radical() produces incorrect result

Thank you! I've experimented with simplify_chain_real a little, and sometimes it produces a result that's bigger and more complex than the source, but it's definitely a good thing to try! Thanks! Also, according to simplify_chain_real docs, it still uses canonicalize_radical() internally, however I could not reproduce any issues with simplify_chain_real yet. Is it considered "safe to use"? Or is it better to use simplify_sqrt_real and simplify_abs_trig and use simplify_chain_real only as a hint, or verify the result by hand?

2018-11-24 23:59:17 +0100 received badge  Nice Question (source)
2018-11-24 16:32:05 +0100 commented answer .simplify_full() doesn't simplify an obvious trigonometric expression

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.

2018-11-24 16:08:48 +0100 received badge  Editor (source)
2018-11-24 16:01:17 +0100 asked a question .canonicalize_radical() produces incorrect result

I'm trying to simplify some trigonometric expressions using sage, and I noticed that .simplify_full() doesn't optimize those, unless a .canonicalize_radical() is used (thanks slelievre for the hint). But that yields incorrect results for some expressions. For example:

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

.canonicalize_radical() simplifies it further:

sage: y.canonicalize_radical()
4

But that is wrong! The answer should be 2*sin(x). Obviously it selected an incorrect sign for the second sqrt(...).

Is there a way to make .canonicalize_radical() smarter? Or any other way to simplify an expression like this correctly?

2018-11-24 15:50:03 +0100 received badge  Student (source)
2018-11-24 15:11:33 +0100 commented answer .simplify_full() doesn't simplify an obvious trigonometric expression

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!

2018-11-24 15:10:37 +0100 received badge  Scholar (source)
2018-11-23 14:57:04 +0100 asked a question .simplify_full() doesn't simplify an obvious trigonometric expression

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?