SymPy engine: the finiteness check in the constructor fully cancels large rational functions on every intermediate result
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
- Domain
- performance
Research direction
Start by reading SympyPGF.__init__ and expressions._is_finite_function, especially the call to value_at_one._cancel described in the issue. Profile the rw_counter_23 Ψ loop on its sub-invariant before and after the change, then run make golden. Done means the constructor hot path avoids full cancellation and the golden results are unchanged.
Written by the indexing model from the issue text.
Description
Found while profiling the engine check of rule PR 3b (#552); exists on main.
SympyPGF.__init__ calls expressions._is_finite_function, which calls value_at_one._cancel: a full cancellation in a FracField (gcd with heugcd) of the whole closed form. This happens for every intermediate result. For the sub-invariant of rw_counter_23 (numerator of 1268 terms, about 80 kB, denominator 1 − 421/500·C²) that is 41 constructor calls and 220 s of 296 s spent in the loop step Ψ. The arithmetic itself (substitution, addition) is cheap.
The cost is not specific to the sandwich. Every analysis on SymPy with large closed forms pays it.
Proposal
- Decide finiteness without cancelling. A closed form whose denominator after
as_numer_denomis a non-constant product form is not finite unless it cancels, so test that cheaply first. - Or compute the flag lazily, only when it is needed.
Done when
- No full cancellation in the constructor on the hot path. The flag is computed only when needed, or by a cheap sufficient test.
- The profile of
rw_counter_23(Ψ on the sub-invariant, SymPy) is measured before and after. -
make goldenchanges no result.
- Dominant language
- Python
- Stars
- 6
- Forks
- 2
- Avg merge
- 1h 52m
- Merged PRs (30d)
- 187
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from LKlinke/Prodigy
-
area: engines bug priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
area: gui bug priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
area: gui bug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
area: engines bug priority: medium
Maintainers usually reply within 1 day
-
area: maintenance priority: low
Maintainers usually reply within 1 day
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day