Unexpected result for cos(a)^2 + sin(a)^2, question about variables

28 views
Skip to first unread message

erentar

unread,
Apr 29, 2022, 5:09:56 AM4/29/22
to sage-support
I would expect the following expression to evaluate to 1 but it does not.

```
var("a",domain="real")
simplify(cos(a)^2 + sin(a)^2)
```

How can i define a variable in this fashion that will result in the code evaluating to 1?

Maxime Bombar

unread,
Apr 29, 2022, 5:59:50 AM4/29/22
to sage-s...@googlegroups.com, erentar
Hi,

you can use the "full_simplify" method for that:


```
sage: var("a", domain="real")
a
sage: b = cos(a)^2+sin(a)^2
sage: b.simplify()
cos(a)^2 + sin(a)^2
sage: b.full_simplify()
1
```

Best,

--
Maxime

OpenPGP_signature

Emmanuel Charpentier

unread,
Apr 30, 2022, 3:09:33 AM4/30/22
to sage-support

Also :

sage: b.simplify_trig()
1

Using specific simplifications in a specific order is often the key to get interesting results that the brute-force simplify_full cannot. Such simplifications are :

sage: import re
sage: print(", ".join([v[0] for v in list(map(lambda u:re.findall(".*simplify.*", u), dir(x))) if len(v)>0]))
factorial_simplify, full_simplify, hypergeometric_simplify, log_simplify, rational_simplify, simplify, simplify_factorial, simplify_full, simplify_hypergeometric, simplify_log, simplify_rational, simplify_real, simplify_rectform, simplify_trig, trig_simplify

to which you should add canonicalize_radical (with caution ! See this for example), and the x._sympy_().simplify()._sage_() idiom, extremely interesting alternative to full_simplify.

HTH,

erentar2002

unread,
Apr 30, 2022, 3:58:40 AM4/30/22
to sage-s...@googlegroups.com

Thank you!

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/51209438-c1d5-4d8f-81a1-54491b338aean%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages