Repository navigation
Faster affects_comparison with an exact numeric check - #65
prawalpokharel wants to merge 3 commits into
Conversation
|
Thanks for the PR (both this and the other already-merged one!) While this may work in practice, it can only prove desired properties of the relational at specific sampled points. Any solutions must be proven to work generally, which is why we perform all of the reasoning symbolically rather than doing any sampling. |
|
Thanks! Agreed that it has to hold for every input, including the ones I didn't test. I think it does, but I explained it badly by leading with the benchmark numbers. The fast path only ever answers True. If it can't show that
It skips points where f is undefined or not rational (e.g. a pole inside True is also the safe direction. Both callers replace I want to be upfront about one case where it isn't identical to main: Float coefficients. Main expands them as floats, so a term in Is a check like this OK with you? If you'd rather not have any numeric evaluation in the mapper, I understand. I can close this and look for a symbolic way to speed it up. |
|
OK, that idea sounds good in principle. The current code and docstring is not descriptive of the meaning however. PRs should consist of good human-written code and docstrings that clearly explain what the code is doing. |
|
Thanks, and sorry about the docstrings. You're right that they didn't explain what the code does. To be upfront about how this was written: I used Claude Code for the first version and again for this revision. I went through the argument and the code myself and checked both, and I can explain every line. What changed in the new commit:
I kept the Float behaviour. All 102 formulas in that case have Float coefficients, so skipping the fast path for Floats would remove most of the speedup. I can change it if you'd rather it match main exactly. How I checked it: in regression cases 1, 3 and 25, every |
Rename _provably_changes_with to _has_witness_that_s_affects_comparison and document what a True and a False mean and why a witness proves the result for every input. Replace the seeded random values with a fixed list of primes, giving s one small and one large value, and name the variables after what they hold. Name the tests after what they check, and add tests for an enumerated symbol and for _exact_value.
42cfa05 to
85d3548
Compare
|
Rebased onto current main, including 8acf39e. I switched the new tests to positive-only symbols to match, and re-ran the full check on the result: all 46 regression cases give identical pmapping tables and joined mappings, and none of the 15,735 witness answers disagree with the symbolic check. The description has the updated numbers. |
Refs #46.
affects_comparisondecides whether a symbol can change a comparison (the "dropping symbols" step in section 5.4.1 of the TCM paper). It does this by expanding f(E_2) - f(E) > 0 and f(E_2) / f(E) > 1 and checking whether s survives. When I profiled the 46 regression cases, this expansion was the largest single cost in building the pruning criteria, and most calls ended up True.This PR looks for a witness before expanding.
_has_witness_that_s_affects_comparisonevaluates f exactly at a few sets of prime values, with Floats read as exact rationals. It checks whether changing only s changes f(E_2) - f(E), and whether it changes f(E_2) / f(E). If both change, s has to survive both expansions, and neither relational can reduce to True or False. So the answer is True for every input, not just the values tried. The docstring gives the full argument. If no witness turns up, the existing symbolic check runs unchanged, so the search never decides False.Results against main at 8acf39e (serial mapper, all 46 regression cases, 4 runs per case with main and this branch back to back in the same container, alternating which goes first):
tests/test_affects_comparison.pyandtests/test_mapper.pypass on this branch on top of current main.Caveats:
expandrounds a term in s to exactly zero, the witness search keeps s where the full check would drop it. That means less pruning, not a wrong comparison, and it never came up on the regression suite.Evidence and scripts: https://gist.github.com/prawalpokharel/98b478447332b06e067227c67973f62b
(I used Claude Code for the profiling and the implementation, and I've checked and can explain every line.)