Expand description
Many questions at once (feature prove): simplifications, constants and validity proofs,
answered in the order asked, on as many threads as the caller gives, with the work that
questions share done once. See docs/proposals/parallel-proofs.md.
A Session owns what outlives a call: its engines, its solver and a store of answers.
Session::run takes questions about expressions of one context (Ask) and returns a
Reply for each. A question is copied into a context of its own and decided there, so
what it costs and what it answers depend on the question and the session’s Config
alone: not on the other questions, their order, the number of threads, what the store
already holds, or what was cancelled.
With Split, a question is cut where its noise cancels. Every node is evaluated at a
few assignments of the symbols; a node with one value at all of them, over something that
varies, is a hub, and is asked on its own: “is this the constant it looks like?”. Hubs
proved are replaced by their constants, in the hubs above them first and in the question
last. Sampling only chooses where to cut: a constant is substituted when the engine folded
the hub to it or the search proved the equality, never because the samples agreed. A hub
is one task however many questions contain it, and its answer is kept in the store.
A question asked under assumptions is sampled where they hold. Where no
point satisfies them (a symbol held below a bound, say) an assignment that does is
searched for, and the question’s value read there; the search only chooses where to
look, as the samples do. A node with one value wherever the assumptions hold, which
moves where they do not, is a hub of those assumptions (Split::assumed): it is asked
under them, and replaced only in questions and hubs asked under the same.
use bitwright::batch::{Answer, Ask, Config, Session};
use bitwright::{BitVec, Context, ParseOptions, Width};
let mut cx = Context::new();
let o = ParseOptions::width(Width::W64);
// An address with a block of noise that cancels, and an identity.
let address = cx.parse("0x1000 + ((x ^ y) + 2 * (x & y) - x - y) * z", &o)?;
let identity = cx.parse("(x | y) + (x & y) == x + y", &o)?;
let session = Session::new(Config::default().with_threads(2));
let replies = session.run(&mut cx, &[Ask::constant(address), Ask::valid(identity)])?;
assert_eq!(replies[0].answer, Answer::Constant(BitVec::from_u64(Width::W64, 0x1000).unwrap()));
assert_eq!(replies[1].answer, Answer::Proved);
// Asked again, both are answered from the store, at the cost they had.
let again = session.run(&mut cx, &[Ask::valid(identity)])?;
assert_eq!(again[0].cost, replies[1].cost);Structs§
- Ask
- A question about expressions of the context given to
Session::run. - Cancel
- Stops the questions it was given to (
Ask::cancellable) oncecancelis called, from any thread. Clones are one flag. - Config
- A session’s configuration, fixed when it is made: every answer and cost is a function of the question and of this.
- Cost
- The work a question took, in counts and never in time: the same for a question whenever
and however it is asked of a session with the same
Config. WithSplitit is the work of the question’s own tasks and of every hub below it, each counted once. - Reply
- The reply to an
Ask. - Session
- Questions answered in batches, on the caller’s threads, with a store of what was proved. See the module.
- Split
- Where questions are cut (
Config::split). - Stats
- What a session has done, for its caller’s accounting (hit rates, memory). Counts of events, which depend on the order of calls: no answer does.