Add a first-class configurational expression system - #10
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Replaces string handling of QCA notation with a typed tree: tokenizer, recursive-descent parser, AST, canonical form and evaluation.
Design
Built on the existing
sets.pynodes rather than beside them, soCondition/Negation/Intersection/Unionremain the node types and nothing is duplicated.ConjunctionandDisjunctionare exported as the names the configurational literature uses. New nodes:ImplicationandConfiguration.Two things worth review
A real bug fixed. The old printer dropped grouping:
(A+B)*Crendered asA+B*C, which re-parses asA+(B*C)— a different set. The printer now re-inserts parentheses by precedence, and round-tripping is property-tested.The complement laws are deliberately not applied. In Boolean algebra
A*~Ais empty; for fuzzy sets it is not — atA = 0.5,min(A, 1-A) = 0.5. Simplification is restricted to laws that hold for min/max/1−x: associativity, commutativity, idempotence, double negation and absorption. A test pinsA*~AandA+~Aas irreducible, and a property test asserts simplification never changes membership on real data.Safety
Parsing is structural — no
eval, noexec. An expression from a config file or user input cannot execute anything; there is a test asserting that an__import__payload is a syntax error. Errors carry the offending position.Tests
45 new tests: tokenizer, precedence, parenthesisation, implications, malformed input, canonical form, absorption, configurations and minterm round-trips, plus two Hypothesis properties —
text → tree → text → treestays semantically identical, and simplification preserves membership.225 tests pass at 100% coverage; mypy strict and docs build clean.
Summary by cubic
Adds a first-class configurational expression system that parses QCA notation into a typed tree with evaluation, simplification, and safe, correct printing. This replaces string handling, improves safety, and makes expressions comparable and testable.
New Features
*,+,~,->), reusingCondition/Negation/Intersection/Union; new nodes:Implication,Configuration(also exportConjunction/Disjunction).evaluate_expression(...); evaluate sufficiency claims viaImplication.evaluate_relation(...).simplify_expression(...); provide canonical form andequivalent(...). Complement laws are intentionally not applied.eval. Errors raiseExpressionSyntaxErrorwith precise positions.Configuration.from_minterm(...),.to_expression(), big-endian minterm mapping.setqca(parse_expression,evaluate_expression,simplify_expression,Implication,Configuration, etc.). Added guide atdocs/guide/expressions.mdand extensive property tests.Bug Fixes
(A+B)*Cno longer renders asA+B*C. Printing now respects precedence and round-trips correctly.Written for commit 7478c9e. Summary will update on new commits.