File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,9 +41,9 @@ def _print_Pow(self, expr: sp.Pow):
4141 str_exp = self ._print (exp )
4242 if not base .is_Atom :
4343 str_base = f"({ str_base } )"
44- # A non-integer Rational exponent (e.g. sqrt -> 1/2) is an Atom but prints as the
45- # multi-token "1/2", so without parentheses "x ^ 1/2" re-parses as (x^1)/2. The
46- # `not exp.is_Atom` check above (#421) misses it; parenthesize it explicitly.
44+ # A non-integer Rational exponent (e.g. sqrt -> 1/2) is an Atom but
45+ # prints as the multi-token "1/2", so without parentheses "x ^ 1/2"
46+ # re-parses as (x^1)/2. Parenthesize it explicitly.
4747 if not exp .is_Atom or (exp .is_Rational and not exp .is_Integer ):
4848 str_exp = f"({ str_exp } )"
4949 return f"{ str_base } ^ { str_exp } "
Original file line number Diff line number Diff line change @@ -43,8 +43,8 @@ def test_printer():
4343 assert petab_math_str (BooleanTrue ()) == "true"
4444 assert petab_math_str (BooleanFalse ()) == "false"
4545 assert petab_math_str ((a + b ) ** (c + d )) == "(a + b) ^ (c + d)"
46- # A non-integer rational exponent must be parenthesized, else "a ^ 1/2" re-parses as
47- # (a^1)/2 (i.e. sqrt(a) would round-trip to a/2). See #421 for the base/exponent case .
46+ # A non-integer rational exponent must be parenthesized, else "a ^ 1/2"
47+ # re-parses as (a^1)/2 (i.e. sqrt(a) would round-trip to a/2).
4848 assert petab_math_str (sp .sqrt (a )) == "a ^ (1/2)"
4949 assert petab_math_str (a ** sp .Rational (2 , 3 )) == "a ^ (2/3)"
5050
You can’t perform that action at this time.
0 commit comments