Skip to content

fix(trxf): preserve numeric operand grouping in feature evaluation - #213

Open
Hanabi9248 wants to merge 1 commit into
Trusted-AI:masterfrom
Hanabi9248:codex/trxf-numeric-operand-grouping-oct25
Open

Hanabi9248 wants to merge 1 commit into
Trusted-AI:masterfrom
Hanabi9248:codex/trxf-numeric-operand-grouping-oct25

Conversation

@Hanabi9248

Copy link
Copy Markdown

Feature.evaluate accepts numeric assignment operands, including fractions.Fraction, but serializes each binary operation without grouping the operands. For Feature('x/y') with x=Fraction(1, 2) and y=Fraction(1, 3), this builds 1/2/1/3 and returns 1/6 instead of 1.5. The wrong value also changes real Predicate decisions.

Parenthesize each serialized operand before the existing evaluation. This preserves operand order and the existing validation, categorical features, Decimal/constant compatibility and final float conversion. It does not change the unary grammar or claim exact rational arithmetic or complete arbitrary Number support.

Validation against master 0ce916f:

  • Python 3.11.16: nine new real Feature/Predicate regression methods produce four assertion failures and five passing controls on the baseline; all nine pass with this one-line change.
  • The separate, unchanged upstream tests/rule_induction/trxf/core/test_feature.py suite passes all eight methods on Python 3.11.16.
  • Python 3.14.1: the new nine-method regression has the same baseline/fixed result. The separate existing eight-method Feature suite has seven passes and one error: its malformed-parenthesis case expects tokenize.TokenError but reaches IndexError in the unchanged parser. That failure is retained and is outside this arithmetic fix.
  • The tests execute complete real Feature, Predicate and BooleanEvaluator modules. Namespace-only package containers avoid unrelated optional top-level imports; no numeric operations, tokenizer, eval or predicate results are mocked. Full installed-package imports and the full repository suite were not run.
  • Native Windows execution used one CPU, 768 MiB aggregate memory, 16-process limit, private temporary files and single-threaded BLAS settings. No dependencies were installed. Source and added-test whitespace checks passed.

Run the added regression with: python tests/rule_induction/trxf/core/test_feature_numeric_operands.py -v

This is separate from #155's operand-pop order correction and #211's metrics changes. AI assistance was used to prepare and review the patch; the reported test results come from actual local runs.

Parenthesize each serialized operand before evaluating a binary operation,
so accepted Fraction values do not alter operator precedence.

Signed-off-by: Hanabi <317387557+Hanabi9248@users.noreply.github.com>
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