1

I want to simplify this Latex equation in sympy

\tan{\left(x \right)} \sec{\left(\frac{\pi x}{180} \right)} So I write this code to simplify this

import sympy as sp
expr = r"\tan{\left(x \right)} \sec{\left(\frac{\pi x}{180} \right)}"
expr = parse_latex(expr)

# Simplifying the expression
simplified_expr = sp.simplify(expr)
print(simplified_expr)

but the result is still like the input equation which was actually tan(x)*sec(pi*x/180).So nothing changed by the simplify method !

I tried searching stack overflow and ChatGpt but everywhere I got only simplify method, which did not satisfies me. The simplified version of the expression should be tan(x)*sec(x) this. But the simplify method returns tan(x)*sec(pi*x/180) this.

Tried Sources:

  1. Expression simplification in SymPy
  2. Constant simplification in Sympy and many others.

Any help regarding this will be appreciated :)

  • 3
    *"The simplified version of the expression should be tan(x)*sec(x)"* <<< No, this is wrong. These two expressions are not equal at all. – Stef Jul 26 '23 at 06:28
  • SymPy's trig functions all take arguments in radians. You can use `pi/180` if `x` is in degrees but whatever definition is used for `sec` there is no way that `sec(pi*x/180)` would be equivalent to `sec(x)` so `simplify` will not make that replacement (and neither will any of the other simplification functions in SymPy). – Oscar Benjamin Jul 26 '23 at 10:23
  • Okay, I understand this. But what about this `- \frac{16 x \left(2 x^{2} - 1\right)}{\sqrt{1 - \left(8 x^{4} - 8 x^{2} + 1\right)^{2}}}` even this equation is not simplified in sympy `simplify ` its simplified version should be `\frac{-4}{\sqrt{(1-x^2})}` but simplify didn't do that ! – koushik mondal Jul 26 '23 at 12:24
  • 1
    If you substitute x = 1/2, the two expressions differ in sign (and are both real) so they can't be the same (everywhere). – smichr Jul 26 '23 at 14:20

0 Answers0