Skip to main content

Discover the conservation/balance rules a set of numbers must satisfy, find where they break, and honest-stop when there is no such structure.

Project description

Numeric Rule Finder

An exact, dependency-light library that discovers the conservation laws latent in structured movement/transaction data, instead of making you declare one.

You declare nothing. It recovers the complete lattice of independent conservation laws the data actually obeys — including laws nobody wrote down — finds where they break, types each break (a re-attributable slip vs. a genuine hole), and honest-stops when there is no structure to exploit.

📖 There's a book. Read the ebook → — what it is, how it works, runnable worked examples (with real output), three machine-learning head-to-heads, a raw-XML showcase, and a mathematics appendix.

Two front doors

Just want answers? (no maths).

  • See it in action — the headline walkthrough, Closing the month at Northwind Retail, in BUSINESS_GUIDE.md: six plain-English checks, each ending in an action (run it: examples/northwind_close/).
  • On your own datapython -m numeric_rule_finder.cli (or from numeric_rule_finder import Reconciler); hand it a CSV and two column names.
  • What you get — what balances, where it breaks and probably why, and any hidden separate sub-systems.
  • It's intelligent — when ordinary balancing finds nothing, it silently escalates to the deeper maths (e.g. modular/parity structure) and reports it in plain words.
  • Across domains — accounting, energy, supply chain, ETL, clinical trials, elections, …: python examples/gamut/gamut_demo.py.

Want the mathematics? — read the ebook Appendix — The mathematics. The engine lives in the numeric_rule_finder/ package.

How it works (in brief)

Numeric Rule Finder treats your data as signed movements — a group, a bucket, an amount — and finds the weighted combinations of buckets that every movement leaves unchanged (the conservation laws), then measures exactly where they break. It climbs only as far as it needs:

  • balance & structure — which groups don't net out; which buckets form hidden separate books;
  • modular laws — patterns invisible to ordinary arithmetic ("moves only in cases of 12", parity), via Smith Normal Form;
  • typed residuals — is a break re-attributable (a coboundary) or a genuine hole (an obstruction that names the violated law)?
  • multi-source consistency — whether independent reconciliations can all be true at once (an obstruction);
  • substrate generality — the same engine over ℤ, ℚ, 𝔽ₚ, and ℚ[t] (parametric, rate-dependent laws).

Everything is exact (integer/rational arithmetic, never floating point). The actual mathematics — definitions, theorems, the coker(S) / residual typing, Smith Normal Form, and a map of the code — is in the ebook Appendix — The mathematics.

Real data carries more than one law

Point it at a dataset and it reports how many independent conservation laws hold. Real data routinely has several — separate books, conserved moieties, per-SKU stock — not just the one obvious balance:

the data laws found what that means
a clean double-entry ledger 1 every transaction nets to zero
two ledgers that never share a transaction 2 they are really separate books — nobody had declared that
a stock network with two products 2 each product's stock is conserved on its own
an enzyme reaction network 2 two conserved quantities (the enzyme, and total substrate)
a shared-resource / mutex process 3 each client's work-item plus the resource invariant
data with no balancing structure 0 honest stop — it refuses to invent a reconciliation

With and against machine learning

Where the signal is an exact law this beats statistical anomaly detection; where the job is partly fuzzy, it makes the model's job easier; and where the answer is an exact structure, it replaces a slow unsupervised job outright. Three reproducible head-to-heads (all walked through in Chapter 7 of the ebook):

  • it beats an Isolation Forest outright on skim fraud — examples/fraud_vs_ml/;
  • it feeds a Random Forest as an exact pre-filter + feature, lifting its score — examples/ml_assist/;
  • it finds the exact groups in one pass — Reconciler.independent_groups — where a clustering k-sweep is thousands of times slower and wrong — examples/grouping_vs_ml/.

Run

numeric_rule_finder has no third-party dependencies; petra_adapter uses petra-nn only to read Petri nets, and the ML examples use scikit-learn.

pip install -e .                                      # optional (pure-stdlib core)
python -m numeric_rule_finder.cli check data.csv --group txn_id --amount amount
python examples/northwind_close/close_the_books.py    # a worked example
python examples/gamut/gamut_demo.py                   # the same engine across domains
python -m pytest tests examples -q                    # the suite

License

MIT-with-attribution — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numeric_rule_finder-0.1.1.tar.gz (39.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numeric_rule_finder-0.1.1-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file numeric_rule_finder-0.1.1.tar.gz.

File metadata

  • Download URL: numeric_rule_finder-0.1.1.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for numeric_rule_finder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6741746b9581fabc1bf56611bac1cd797407f201b86b292e2f7ec24d2753dcda
MD5 1cba739bc6a9743952d9ee553c3590c5
BLAKE2b-256 a08a6854b7ba3d4c73c605fd0af396182edd98bfac16f62f6cbd8141ed8b87a8

See more details on using hashes here.

File details

Details for the file numeric_rule_finder-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for numeric_rule_finder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ecc5b4468522d3af1880d234e9052dcac58e65e52544ab548a9e8e20f399377
MD5 2ca7dbe647ca2bea3b07def7e2a152be
BLAKE2b-256 3f1fb04d68e0f07722b8d007e5c056c04db3b769a1d95be14d0458a9c951b2bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page