def test_srepl_macro(self): Parser.clear_namespace() parse(r""" % srepl "<1>'" -> "\text{<1>prime}" % srepl "\text{<1..>}_<2>" -> "\text{(<1..>)<2>}" % srepl "<1>_{<2>}" -> "<1>_<2>", "<1>_<2>" -> "\text{<1>_<2>}" % srepl "\text{(<1..>)<2>}" -> "\text{<1..>_<2>}" % srepl "<1>^{<2>}" -> "<1>^<2>", "<1>^<2>" -> "<1>^{{<2>}}" """) expr = r"x_n^4 + x'_n \exp(x_n y_n^2)" self.assertEqual(str(parse_expr(expr)), "x_n**4 + xprime_n*exp(x_n*y_n**2)") Parser.clear_namespace() parse(r""" % srepl "<1>'^{<2..>}" -> "\text{<1>prime}" """) expr = r"v'^{label}" self.assertEqual(str(parse_expr(expr)), "vprime")
def test_expression_2(self): expr = r'e^{{\ln x}} + \sin(\sin^{-1} y) - \tanh(xy)' self.assertEqual(str(parse_expr(expr)), 'x + y - tanh(x*y)')
def test_expression_3(self): expr = r'\partial_x (x^{{2}} + 2x)' self.assertEqual(str(parse_expr(expr).doit()), '2*x + 2')
def test_expression_1(self): expr = r'-(\frac{2}{3} + 2\sqrt[5]{x + 3})' self.assertEqual(str(parse_expr(expr)), '-2*(x + 3)**(1/5) - 2/3')