Skip to content

Translate std::pow and std::max in emitted observables - #36

Merged
jeliason merged 1 commit into
mainfrom
feature/observables-pow-max
Aug 4, 2026
Merged

Translate std::pow and std::max in emitted observables#36
jeliason merged 1 commit into
mainfrom
feature/observables-pow-max

Conversation

@jeliason

@jeliason jeliason commented Aug 4, 2026

Copy link
Copy Markdown
Member

The PDAC assignment rules use both: 16 of 105 are Hill functions and two clamp with std::max. The emitter refused any non-arithmetic operator, so the Python readouts an inference run composes could not be generated at all.

_rewrite_calls normalises them once when rules are read, so the dependency walk, translation and emit all continue to see plain infix arithmetic:

  • std::pow(a, b) -> ((a) ** (b))
  • std::max(a, b) -> _maximum(a, b), emitted as (a + b + abs(a - b)) / 2

Neither form needs an import, preserving the property that one generated module works on floats, numpy arrays and JAX tracers. Arguments split on the top-level comma rather than by regex, since a Hill exponent is routinely itself a std::pow.

Genuinely untranslatable operators (comparisons, logical operators) are still refused; the existing test now covers one of those instead of std::max.

The PDAC rules use both: 16 of 105 are Hill functions and two clamp with
std::max. The emitter refused them, so the readouts a fit composes could not be
generated at all.

Both translate without an import, which is what lets one generated module serve
floats, numpy and JAX tracers alike: pow becomes **, and max becomes
(a + b + abs(a - b)) / 2. Arguments split on the top-level comma rather than by
regex, since a Hill exponent is routinely itself a pow.
@jeliason
jeliason merged commit d0e5e18 into main Aug 4, 2026
2 checks passed
@jeliason
jeliason deleted the feature/observables-pow-max branch August 4, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant