Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion petab/v1/math/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ def _print_BooleanFalse(self, expr):
def _print_Pow(self, expr: sp.Pow):
"""Custom printing for the power operator"""
base, exp = expr.as_base_exp()
return f"{self._print(base)} ^ {self._print(exp)}"
str_base = self._print(base)
str_exp = self._print(exp)
if not base.is_Atom:
str_base = f"({str_base})"
if not exp.is_Atom:
str_exp = f"({str_exp})"
return f"{str_base} ^ {str_exp}"

def _print_Infinity(self, expr):
"""Custom printing for infinity"""
Expand Down
2 changes: 2 additions & 0 deletions tests/v1/math/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def test_assumptions():


def test_printer():
a, b, c, d = sp.symbols("a b c d", real=True)
assert petab_math_str(None) == ""
assert petab_math_str(BooleanTrue()) == "true"
assert petab_math_str(BooleanFalse()) == "false"
assert petab_math_str((a + b) ** (c + d)) == "(a + b) ^ (c + d)"


def read_cases():
Expand Down
Loading