Skip to main content

Module mba

Module mba 

Source
Expand description

The MBA service (feature mba): simplification of mixed Boolean-arithmetic expressions by a pluggable solver, behind an evidence gate. See docs/design.md §9.

The engine lowers a fragment of the arena (+ − * neg & | ^ ~, constant shifts, casts) into an MbaExpr over its atoms, asks the configured MbaSolver, and accepts an answer only with exact evidence: the linear-MBA signature (complete for linear MBA), exhaustive evaluation for small inputs, an EquivalenceProver, or, if the configuration trusts them, the backend’s certificate or sampling. The lifted result must also agree with the original expression at seeded points, and it replaces the node only when the DAG gets smaller.

use bitwright::engine::{Engine, Phase, Strategy};
use bitwright::mba::MbaConfig;
use bitwright::{Context, ParseOptions, Width};

let engine = Engine::builder()
    .builtin()
    .strategy(Strategy::new("mba", vec![Phase::Mba(MbaConfig::default())]))
    .build()?;
let mut cx = Context::new();
let e = cx.parse("(x ^ y) + 2 * (x & y) + ((x | y) - (x & y) - (x ^ y))", &ParseOptions::width(Width::W64))?;
let out = engine.simplify(&mut cx, e)?;
let want = cx.parse("x + y", &ParseOptions::width(Width::W64))?;
assert_eq!(out.expr, want);

Re-exports§

pub use crate::engine::CertStats;

Structs§

Bindings
The expressions the variables of a lowered MbaExpr stand for.
CacheKey
A cache key: the input’s content hash, the solver and prover ids, and the lowering version.
MNode
A node: operator, result width, operand indices (earlier nodes).
MbaBudget
What a solver may spend on one question. Solvers treat it as a hint; the engine enforces its own budget on calls.
MbaConfig
The configuration of a Phase::Mba.
MbaExpr
A DAG in the MBA fragment over declared variables. The last node is the root. Nodes refer only to earlier nodes, so evaluation and every traversal are single forward passes.
MbaLimits
Caps on what is lowered and asked of a solver.
MbaTrust
Which evidence beyond bitwright’s own checks is accepted.
MemoryCache
A bounded in-memory cache (oldest entries evicted first).
NativeProver
bitwright’s own exact equivalence checks as an EquivalenceProver: the refutation sample, then the cheapest certificate that applies (the corner signature, single bit positions, at most d bit positions for degree d, the pure-polynomial grid, exhaustive evaluation; equal polynomials over symbols first where that test would take far longer), over abstracted atoms when a side leaves the polynomial fragment. The same checks are the evidence gate’s own, so an engine needs this prover only when its host uses the MBA module directly.
NfOptions
What the normal-form solver takes on. Every limit is checked before the work it bounds.
NfStats
What the normal-form solver has done (telemetry; never affects answers).
NoCache
A cache that keeps nothing.
NormalFormSolver
The native solver for linear, semi-linear and polynomial MBA, from exact normal forms at full width; other subterms are atoms. A normal form over at most three atoms is also looked up in a table of small expressions (NfOptions::synthesis). Every answer is certified against its input by bitwright’s own certificates before it is returned (Claim::Proved), or, when no certificate fits, checked at the refutation sample (Claim::Sampled, which the evidence gate re-checks): exact by construction, except a table hit no certificate could decide. Work is counted in MbaBudget::steps: one step per node visited, table word combined, monomial product, term or table entry rendered, and one per 32 node evaluations of a certificate. Answers are deterministic; recent ones are remembered (NfOptions::memo).
Shape
Structural properties used to decide whether a solver is worth asking.
SignatureSolver
The native solver: complete for linear MBA (arithmetic over bitwise functions of the variables), from the values at the all-zero/all-ones corners. It answers with the affine form when there is one, or the combination of the variables’ conjunctions, and “no simpler” when that is not smaller; other inputs are unsupported.
ThreadedSolver
Runs each question on its own thread and waits at most timeout: an answer that is late is abandoned and reported as MbaAnswer::Exhausted (never cached, so a later call may try again). While max_abandoned abandoned questions are still running, new ones are refused as exhausted, which bounds the threads left behind. The only threads are the ones this instance starts; nothing is global.

Enums§

CacheEntry
A durable cache entry: only verified results and complete “no simpler” answers.
Claim
The evidence a solver attaches to an answer.
Decided
What decide makes of two expressions.
MOp
An operator of the MBA fragment.
MbaAnswer
A solver’s answer.
MbaError
Why a node could not be added.
Refusal
Why an expression was not lowered or not solved.
Verdict
The outcome of an equivalence proof attempt.

Traits§

EquivalenceProver
A backend that proves two MBA expressions equal.
MbaCacheStore
Where the MBA service keeps answers across calls. bitwright performs no IO: persistent stores belong to the host.
MbaSolver
A backend that simplifies MBA expressions.

Functions§

decide
equal as a decision procedure: with facts, and with a witness.
equal
Whether a and b are equal for every value of their symbols, by the MBA procedures alone: no engine, no circuit, no search. Their difference is lowered to an MBA expression (sums, products and bitwise operations over atoms: every other subterm is a variable) and tested against zero by the native prover, which decides linear and semi-linear MBA and polynomials of low degree completely within budget.
lift
Builds m in the arena through the canonicalizing constructors, each variable bound to the subterm it stands for.
lower
Lowers the fragment rooted at e into an MbaExpr: + − * neg & | ^ ~, shifts by constants below the width, extensions and truncation; every other subterm becomes a variable, bound in the returned Bindings. Fails with Error::Unsupported (the refusal) when e is not in the fragment or is over a limit.