Repository navigation
Monomial hashes again, so stored values are found through their index - #2104
Merged
Merged
Conversation
Stored values such as f[1] = a are found through an index (LiteralRuleIndex, #2013), which keeps the sort keys of the rules in a set. Since #2073 those keys can hold a Monomial, which defines __eq__ and so lost its default __hash__: building the index raised TypeError, which it takes to mean "can not be indexed", and every lookup went through all the rules again. Monomial now hashes the pairs of variables and exponents it compares. 100 lookups among 400 stored values: 5050 SameQ on master, now 200. Combinatorica's SetGraphOptions, with a table of the edges' option groups, depends on this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
LGTM. Very good catch in finding the subtle bug here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stored values such as
f[1] = aare meant to be found through an index (LiteralRuleIndex, #2013). The index keeps the sort keys (pattern_precedence) of the rules in a set.Since #2073 those keys can contain a
Monomial.Monomialdefines__eq__, so Python dropped its default__hash__. As a result:TypeError.No test caught it, because #2013's tests did not come along with it.
Change:
Monomial.__hash__hashes the (variable, exponent) pairs that__eq__compares, so equal monomials hash equally (1and1.0included).Measurements
SameQcalls on master, now 200.SetGraphOptions, rewritten to look options up in such a table (Mathics3-Package-Combinatorica,set-graph-options-index), becomes linear in the number of edges with this fix.Tests:
test/core/test_literal_rule_index.py. Both tests fail on master.The full pytest run and the doctests pass.
🤖 Generated with Claude Code