Skip to main content

NativeProver

Struct NativeProver 

Source
pub struct NativeProver { /* private fields */ }
Expand description

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.

Work is counted in node evaluations against MbaBudget::steps, the symbolic comparison at 256 per monomial operation (what one costs) and within what is left; a certificate over the budget is not run, and one stopped by it is not finished (Unknown). Refuted comes with a concrete counterexample.

use bitwright::mba::{EquivalenceProver, MOp, MbaBudget, MbaExpr, NativeProver, Verdict};
use bitwright::Width;

// (x & y)·(x | y) + (x & ~y)·(~x & y) == x·y, a degree-2 identity, at 64 bits: the same
// polynomial over x, y and x & y, so it takes none of the degree-2 test's 18,337 points.
let w = Width::W64;
let mut a = MbaExpr::new(vec![w, w]);
let (x, y) = (a.push(MOp::Var(0), &[])?, a.push(MOp::Var(1), &[])?);
let (and, or) = (a.push(MOp::And, &[x, y])?, a.push(MOp::Or, &[x, y])?);
let p = a.push(MOp::Mul, &[and, or])?;
let (nx, ny) = (a.push(MOp::Not, &[x])?, a.push(MOp::Not, &[y])?);
let (l, r) = (a.push(MOp::And, &[x, ny])?, a.push(MOp::And, &[nx, y])?);
let q = a.push(MOp::Mul, &[l, r])?;
a.push(MOp::Add, &[p, q])?;
let mut b = MbaExpr::new(vec![w, w]);
let (x, y) = (b.push(MOp::Var(0), &[])?, b.push(MOp::Var(1), &[])?);
b.push(MOp::Mul, &[x, y])?;
let prover = NativeProver::default();
assert_eq!(prover.prove_equal(&a, &b, &MbaBudget::default()), Verdict::Proved);
assert_eq!((prover.stats().symbolic, prover.stats().sparse), (1, 0));

Implementations§

Source§

impl NativeProver

Source

pub fn new() -> NativeProver

A prover with zeroed counters.

Source

pub fn stats(&self) -> CertStats

What it has decided so far, and how.

Trait Implementations§

Source§

impl Debug for NativeProver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NativeProver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl EquivalenceProver for NativeProver

Source§

fn id(&self) -> &str

A stable name (it keys the caches).
Source§

fn prove_equal(&self, a: &MbaExpr, b: &MbaExpr, budget: &MbaBudget) -> Verdict

Decides whether a and b are equal on every input.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.