Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b2e66e7
Add design spec for expression-based rules engine rearchitecture
discreteds Apr 3, 2026
5ae9afb
docs: add implementation plan for expression-based rules engine
discreteds Apr 3, 2026
17fa599
Task 1: clean slate — remove old engine code and update dependencies
discreteds Apr 3, 2026
9e4a970
feat: replace constants and dimension models with ibis-free implement…
discreteds Apr 3, 2026
00752e7
feat(context): replace ContextHelper class with extract_context_value…
discreteds Apr 6, 2026
c2eac0a
feat(compiler): add DimensionCompiler with EXACT strategy
discreteds Apr 6, 2026
95a1d5d
feat(compiler): implement RANGE and REGEX dimension strategies
discreteds Apr 6, 2026
9ea6773
feat(result): add RuleResult wrapper with convenience accessors for e…
discreteds Apr 6, 2026
61a96dd
feat(engine): replace RulesEngine with ExpressionRulesEngine for sing…
discreteds Apr 6, 2026
9433f8a
test(engine): add Tasks 9 and 10 — advanced features and custom expre…
discreteds Apr 6, 2026
609f46d
test(integration): add end-to-end hierarchical rules scenarios
discreteds Apr 6, 2026
36f2a40
feat: update public API, fixtures, and remove leftover old test files
discreteds Apr 6, 2026
8990411
style: fix unused imports in compiler.py and context.py
discreteds Apr 6, 2026
82f8906
docs: add design spec for extended match strategies
discreteds Apr 7, 2026
d3e1d9a
docs: add implementation plan for extended match strategies
discreteds Apr 7, 2026
48ff4d6
feat(constants): add 8 new MatchStrategy enum values
discreteds Apr 7, 2026
475f8ba
feat(dimension): add validation for new match strategies (Task 2)
discreteds Apr 7, 2026
1e5ebc7
feat(compiler): add NOT_EQUAL, GREATER_THAN, LESS_THAN match strategi…
discreteds Apr 7, 2026
9816f80
feat: add PREFIX strategy with shared _compile_string_match helper
discreteds Apr 7, 2026
03875a4
feat: add SUFFIX and CONTAINS match strategies
discreteds Apr 7, 2026
848cdd3
docs: add accumulator engine architecture analysis
discreteds Apr 7, 2026
625d801
test: add per-row regex test to TestRegexCompilation
discreteds Apr 7, 2026
10505a1
docs: add rules engine landscape & roadmap analysis
discreteds Apr 7, 2026
e24c69b
refactor(compiler): use clean string-match helper for CONTAINS and REGEX
discreteds Apr 7, 2026
e621b09
docs: correct additive rules engine analysis after PMX_DB review
discreteds Apr 7, 2026
e3dba06
docs: add Big 4 mortgage pricing engine case study
discreteds Apr 7, 2026
f01d644
Task 8: Add SET_MEMBERSHIP and SET_EXCLUSION match strategies
discreteds Apr 7, 2026
0e381b7
Task 9: Add fraud detection integration test for mixed strategies
discreteds Apr 7, 2026
6309620
Add backend agnosticism smoke tests for compiler strategies
discreteds Apr 7, 2026
7e65ced
docs: add match strategies catalog to CLAUDE.md
discreteds Apr 7, 2026
d300d56
docs: add design spec for backend-agnostic engine and result
discreteds Apr 8, 2026
748f5a7
docs: add implementation plan for backend-agnostic engine and result
discreteds Apr 8, 2026
915abe4
test(backend-purity): add import-check test + tag SET_MEMBERSHIP exce…
discreteds Apr 8, 2026
d45e242
refactor(engine): rewrite engine.py to be backend-agnostic via mounta…
discreteds Apr 8, 2026
e33e202
refactor(result): use mountainash.relations for all RuleResult accessors
discreteds Apr 8, 2026
296d0ac
docs: spec for cross-backend test parameterisation
discreteds Apr 8, 2026
d83fc74
docs: implementation plan for cross-backend test parameterisation
discreteds Apr 8, 2026
5845023
test: rewrite conftest for cross-backend parameterisation
discreteds Apr 8, 2026
a5348fd
fix: REGEX as one-hot; cast specificity; drop double collect
discreteds Apr 8, 2026
9c8683a
test(result): parametrize across all 7 backends
discreteds Apr 8, 2026
21d2af2
test(integration): parametrize all classes across backends
discreteds Apr 8, 2026
8ccf0d6
test(compiler): extend backend agnosticism smoke tests to 7 backends
discreteds Apr 8, 2026
45a83b7
test: link upstream-broken backend xfails to issues
discreteds Apr 8, 2026
10dc7c8
refactor: remove SET_MEMBERSHIP Polars workaround
discreteds Apr 8, 2026
7a0f32c
test: add #77 regression test, restore pandas/narwhals-pandas xfails
discreteds Apr 11, 2026
400915a
refactor: replace blanket backend xfails with surgical per-test markers
discreteds Apr 11, 2026
33ad540
fix: remove #77 xfails after upstream fix, restore #78 ibis-polars xf…
discreteds Apr 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .hiivmind/github
58 changes: 43 additions & 15 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

## Project Overview

Mountain Ash Utils Rules is a high-performance Python package that provides revolutionary rule-based systems with multiple engine architectures. It features prime-based ternary logic, vectorized processing, and multiple performance-optimized engines including hybrid numpy/ibis processing and pure vectorized polars processing. The system achieves up to 93.9% performance improvements (16.40x speedup) through advanced mathematical optimization.
Mountain Ash Utils Rules is a high-performance Python package that provides revolutionary rule-based systems with multiple engine architectures. It features signed-integer ternary logic (-1/0/1), vectorized processing, and multiple performance-optimized engines including hybrid numpy/ibis processing and pure vectorized polars processing. The system achieves up to 93.9% performance improvements (16.40x speedup) through advanced mathematical optimization.

## Architecture

Expand All @@ -25,17 +25,44 @@ Mountain Ash Utils Rules is a high-performance Python package that provides revo
- **VectorizedRulesEngine**: Revolutionary polars-based engine achieving 93.9% performance improvement
- **PolarsRuleProcessor**: Pure vectorized polars processor with lazy evaluation

#### Prime-Based Ternary Logic System
- **RuleTrinaryFlags**: Mathematical prime-based flags (PRIME_TRUE=2, PRIME_FALSE=3, PRIME_UNKNOWN=5)
- Enables mathematical precision and vectorization optimization
#### Ternary Logic Encoding
- Per-dimension match values use signed-integer ternary encoding: **1 = match, 0 = unknown, −1 = non-match**
- Defined and consumed in `constants.py`, `compiler.py`, and `result.py` (search for "ternary")
- Enables vectorized arithmetic combination of dimension match results across rules

## Match Strategies

The rules engine supports 11 match strategies via the `MatchStrategy` enum, compiled in `src/mountainash_utils_rules/compiler.py`:

| Strategy | Rule Column Format | Data Type | Description |
|----------|-------------------|-----------|-------------|
| `EXACT` | Scalar value | any | Rule value equals context value |
| `NOT_EQUAL` | Scalar value | any | Rule value does not equal context value |
| `RANGE` | Two columns (min/max) | int, float | Context value within [min, max] |
| `GREATER_THAN` | Threshold value | int, float | Context value > rule threshold |
| `LESS_THAN` | Threshold value | int, float | Context value < rule threshold |
| `PREFIX` | Prefix string | str | Context value starts with rule |
| `SUFFIX` | Suffix string | str | Context value ends with rule |
| `CONTAINS` | Substring | str | Context value contains rule |
| `REGEX` | Regex pattern | str | Context value matches rule pattern (search semantics) |
| `SET_MEMBERSHIP` | List column | any | Context value is in rule's list |
| `SET_EXCLUSION` | List column | any | Context value is not in rule's list |

**Backend support:**
- 9 strategies (EXACT, NOT_EQUAL, RANGE, GREATER_THAN, LESS_THAN, PREFIX, SUFFIX, CONTAINS, REGEX) compile cleanly on Polars, Ibis, and Narwhals backends — all support per-row patterns/thresholds via column references
- `SET_MEMBERSHIP` and `SET_EXCLUSION` currently use a Polars-native workaround (`ma.native(pl.col(...).list.contains(...))`) pending upstream `t_is_in`/`t_is_not_in` support for list-column references in mountainash-expressions

**Unknown handling:** Sentinel values (`<NA>` for strings, `-999999999` for numerics) in either rule or context columns produce UNKNOWN (0) ternary results, which count as wildcards in ranking but do not eliminate the rule.

**Adding strategies:** The process is documented in `docs/superpowers/specs/2026-04-07-extended-match-strategies-design.md`. Pattern: add enum value, add validation rule in `dimension.py`, add `_compile_<strategy>` method in `compiler.py`, add test class in `tests/test_compiler.py`.

### Package Structure

```
src/mountainash_utils_rules/
├── __init__.py # Package exports and public API
├── __version__.py # Version information
├── constants.py # Constants, enums, and prime-based ternary flags
├── constants.py # Constants, enums, and ternary value definitions
├── context.py # Context handling utilities with batch optimization
├── dimension.py # Dimension metadata and management
├── engine.py # Original RulesEngine implementation
Expand Down Expand Up @@ -153,7 +180,7 @@ docs/
- **Organization**: Follow modular design with clear separation of concerns
- **Testing**: Create unit tests with appropriate markers (unit, integration, performance, benchmark)
- **Performance**: Maintain mathematical precision while optimizing for speed
- **Prime-based logic**: Use RuleTrinaryFlags (2, 3, 5) for ternary operations
- **Ternary logic**: Use the signed-integer encoding (1 match, 0 unknown, −1 non-match) for per-dimension match values

## Development Environments

Expand Down Expand Up @@ -250,18 +277,19 @@ benchmarker.test_backend_initialization()
benchmarker.test_performance_comparison()
```

## Key Innovation: Prime-Based Ternary Logic
## Key Innovation: Ternary Match Logic

The system uses mathematical prime numbers for ternary logic operations:
- **PRIME_TRUE = 2**: Condition matches
- **PRIME_FALSE = 3**: Condition doesn't match
- **PRIME_UNKNOWN = 5**: Condition unknown/unset
The system encodes per-dimension match results using a signed-integer ternary scheme:
- **1**: Condition matches
- **0**: Condition unknown / dimension absent from rule
- **−1**: Condition does not match

This enables:
- Mathematical precision in rule combinations
- Vectorization optimization
- Perfect audit trails through prime factorization
- Up to 16.40x performance improvements
- Vectorized arithmetic combination of dimension results across rules
- Cheap aggregation (sum/min) for whole-rule match decisions
- Up to 16.40x performance improvements via the polars/ibis backends

> **Historical note:** earlier planning documents describe a prime-based encoding (PRIME_TRUE=2, PRIME_FALSE=3, PRIME_UNKNOWN=5). That scheme was never implemented in the source — the actual encoding is the signed-integer one above. A separate prime-product mechanism is proposed for the *additive/accumulator* engine described in `docs/superpowers/specs/`, but it is unrelated to per-dimension ternary values: it identifies *combinations of rules*, not match outcomes.

## Performance Architecture Evolution

Expand Down
Loading
Loading