Skip to main content

ConstraintSystem

Struct ConstraintSystem 

Source
pub struct ConstraintSystem<F: TowerField> { /* private fields */ }
Expand description

Builder context for algebraic constraints.

Implementations§

Source§

impl<F: TowerField> ConstraintSystem<F>

Source

pub fn new() -> Self

Create a new constraint system.

Source

pub fn from_ast(ast: ConstraintAst<F>) -> Self

Create a builder from an existing AST.

Source

pub fn col(&self, idx: usize) -> Expr<'_, F>

Reference to a column in the current row.

Source

pub fn next(&self, idx: usize) -> Expr<'_, F>

Reference to a column in the next row.

Source

pub fn constant(&self, val: F) -> Expr<'_, F>

Field constant.

Source

pub fn one(&self) -> Expr<'_, F>

The multiplicative identity.

Source

pub fn scale(&self, coeff: F, expr: Expr<'_, F>) -> Expr<'_, F>

Scalar multiplication: coeff * expr.

Use this for powers of 2, coefficients, etc. Orphan rules prevent implementing F * Expr via operator overloading.

Source

pub fn sum(&self, children: &[Expr<'_, F>]) -> Expr<'_, F>

N-ary sum. More efficient than chaining binary + for linear combinations (avoids deep Add chains).

Source

pub fn constrain(&self, expr: Expr<'_, F>)

Register a constraint: expr = 0.

The expression must evaluate to zero for every valid row in the execution trace.

Source

pub fn constrain_named(&self, label: &'static str, expr: Expr<'_, F>)

Source

pub fn assert_boolean(&self, s: Expr<'_, F>)

Assert that s is boolean: s * (s + 1) = 0.

In GF(2^k), s + 1 equals s - 1. Enforces s ∈ {0, 1}.

Source

pub fn assert_zero_when(&self, sel: Expr<'_, F>, body: Expr<'_, F>)

Assert that body = 0 whenever sel = 1.

Registers sel * body = 0. When sel = 0, the constraint is trivially satisfied.

Source

pub fn assert_one_hot(&self, selectors: &[Expr<'_, F>])

Assert that exactly one selector is active. Enforces: sum(selectors) = 1.

In GF(2^k): sum(s_i) + 1 = 0.

Source

pub fn assert_paired_bus_mutex(&self, s_send: usize, s_recv: usize)

Emit the s_send · s_recv = 0 mutex root plus boolean checks on both selectors.

Source

pub fn build(self) -> ConstraintAst<F>

Consume the builder and produce a ConstraintAst.

All Expr handles must be dropped before calling this (enforced by the borrow checker, build takes self).

Trait Implementations§

Source§

impl<F: TowerField> Default for ConstraintSystem<F>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<F> !Freeze for ConstraintSystem<F>

§

impl<F> !RefUnwindSafe for ConstraintSystem<F>

§

impl<F> Send for ConstraintSystem<F>

§

impl<F> !Sync for ConstraintSystem<F>

§

impl<F> Unpin for ConstraintSystem<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for ConstraintSystem<F>

§

impl<F> UnwindSafe for ConstraintSystem<F>
where F: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more