Skip to content

Lower fractional and integer powers correctly in symstr and interstate edges - #2764

Draft
ThrudPrimrose wants to merge 7 commits into
mainfrom
fix-sympy-cpp-rational-power
Draft

ThrudPrimrose wants to merge 7 commits into
mainfrom
fix-sympy-cpp-rational-power

Conversation

@ThrudPrimrose

@ThrudPrimrose ThrudPrimrose commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

sqrt(M), M**(1/3) and M**(N/3) printed C++ integer-division exponents (pow(M, 1/2) is pow(M, 0)), in symstr and in interstate assignments through cppunparse, and x / N**2 printed as x/(N) * (N). Fractional exponents now lower to dace::math::pow(base, p, q), which divides in float for a half base, double for an integer base and the base's own type otherwise and returns the base's type (double for an integer base), while equal quotients outside the exponent stay floored, with printer, compile and end-to-end tests.

ThrudPrimrose and others added 4 commits October 28, 2026 17:01
sqrt(M) printed as pow(M, 1/2), which is pow(M, 0) in C++: the square-root check parsed the printed
exponent. A rational exponent now prints as a floating quotient, and an integer power's product is
parenthesized, since x / N**2 printed as x/(N) * (N), i.e. x. Ported from extended.
A float or half base keeps a float pow instead of promoting to double; an integer base gets a float
exponent and std::pow's double result.
… integral base

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lic exponents

A p/q exponent is C++ integer division in symstr (M**(N/3), M**(1/N)) and in
interstate assignments lowered by cppunparse (M**(1/3) ran as M**0). Both now
emit dace::math::pow(base, p, q), which divides in the base's floating type
(double for an integral base) and returns that type. sympy_divide_fix leaves
non-integer exponents alone, and cppunparse no longer calls float(None) on a
negated non-constant exponent.
@ThrudPrimrose ThrudPrimrose changed the title symstr: lower fractional and integer powers correctly Lower fractional and integer powers correctly in symstr and interstate edges Oct 28, 2026
@ThrudPrimrose
ThrudPrimrose requested a review from tbennun October 29, 2026 07:17
@ThrudPrimrose
ThrudPrimrose marked this pull request as draft October 29, 2026 07:26
…des in the computation type

sympy_divide_fix replaced every quotient equal to one inside a fractional exponent, so in
M**(N/3) + N/3 the outer N/3 lost its floor. It now rewrites bottom-up, one occurrence at a time.
dace::math::pow(a, p, q) divided p and q in the base's type, so a half base overflowed
(pow(h, 100000, 100000) was NaN); the quotient is now computed in float for a half.
…to fix-sympy-cpp-rational-power

# Conflicts:
#	dace/runtime/include/dace/math.h
#	dace/symbolic.py
#	tests/runtime_math_test.py
#	tests/symbolic_roundtrip_test.py
ThrudPrimrose added a commit that referenced this pull request Oct 29, 2026
Extended's own rational-power lowering stays; the PR's denominator-power test joins it.

This branch has not been deployed

No deployments
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