Commit 4bbffd0
authored
Fix PetabStrPrinter for non-integer rational exponents (#489)
A non-integer Rational exponent (e.g. a square root, exponent 1/2) is a sympy
Atom but prints as the multi-token "1/2", so PetabStrPrinter emitted
`sqrt(a)` as the unparenthesized `a ^ 1/2`. Since `^` binds tighter than `/`,
that re-parses as `(a^1)/2 = a/2` -- a silent round-trip corruption
(`petab_math_str(sympify_petab(...))` is not the identity for square roots).
The `not exp.is_Atom` guard added in #421 covers non-atomic exponents but not
this atomic-yet-multi-token case; parenthesize a non-integer rational exponent
explicitly, so `petab_math_str(sqrt(a)) == "a ^ (1/2)"`, which re-parses
correctly. Integer powers and the #421 cases are unchanged.1 parent 17a70e8 commit 4bbffd0
2 files changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
0 commit comments