Trait halo2_base::gates::flex_gate::GateInstructions
source · [−]pub trait GateInstructions<F: ScalarField> {
Show 35 methods
fn strategy(&self) -> GateStrategy;
fn pow_of_two(&self) -> &[F]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8];
fn get_field_element(&self, n: u64) -> F;
fn inner_product<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> AssignedValue<F>
where
QA: Into<QuantumCell<F>>;
fn inner_product_left_last<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> (AssignedValue<F>, AssignedValue<F>)
where
QA: Into<QuantumCell<F>>;
fn inner_product_with_sums<'thread, QA>(
&self,
ctx: &'thread mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> Box<dyn Iterator<Item = AssignedValue<F>> + 'thread>
where
QA: Into<QuantumCell<F>>;
fn sum_products_with_coeff_and_var(
&self,
ctx: &mut Context<F>,
values: impl IntoIterator<Item = (F, QuantumCell<F>, QuantumCell<F>)>,
var: QuantumCell<F>
) -> AssignedValue<F>;
fn select(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
sel: impl Into<QuantumCell<F>>
) -> AssignedValue<F>;
fn or_and(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
c: impl Into<QuantumCell<F>>
) -> AssignedValue<F>;
fn num_to_bits(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>,
range_bits: usize
) -> Vec<AssignedValue<F>>;
fn const_right_rotate_unsafe<const BIT: usize, const NUM_BITS: usize>(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>
) -> AssignedValue<F>;
fn const_left_rotate_unsafe<const BIT: usize, const NUM_BITS: usize>(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>
) -> AssignedValue<F>;
fn add(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn sub(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn neg(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn mul(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn mul_add(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
c: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn mul_not(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn assert_bit(&self, ctx: &mut Context<F>, x: AssignedValue<F>) { ... }
fn div_unsafe(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn assert_is_const(
&self,
ctx: &mut Context<F>,
a: &AssignedValue<F>,
constant: &F
) { ... }
fn sum<Q>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = Q>
) -> AssignedValue<F>
where
Q: Into<QuantumCell<F>>,
{ ... }
fn partial_sums<'thread, Q>(
&self,
ctx: &'thread mut Context<F>,
a: impl IntoIterator<Item = Q>
) -> Box<dyn Iterator<Item = AssignedValue<F>> + 'thread>
where
Q: Into<QuantumCell<F>>,
{ ... }
fn accumulated_product<QA, QB>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QB>
) -> Vec<AssignedValue<F>>
where
QA: Into<QuantumCell<F>>,
QB: Into<QuantumCell<F>>,
{ ... }
fn or(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn and(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn xor(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn not(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn bits_to_indicator(
&self,
ctx: &mut Context<F>,
bits: &[AssignedValue<F>]
) -> Vec<AssignedValue<F>> { ... }
fn idx_to_indicator(
&self,
ctx: &mut Context<F>,
idx: impl Into<QuantumCell<F>>,
len: usize
) -> Vec<AssignedValue<F>> { ... }
fn select_by_indicator<Q>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = Q>,
indicator: impl IntoIterator<Item = AssignedValue<F>>
) -> AssignedValue<F>
where
Q: Into<QuantumCell<F>>,
{ ... }
fn select_from_idx<Q>(
&self,
ctx: &mut Context<F>,
cells: impl IntoIterator<Item = Q>,
idx: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
where
Q: Into<QuantumCell<F>>,
{ ... }
fn is_zero(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>
) -> AssignedValue<F> { ... }
fn is_equal(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F> { ... }
fn lagrange_and_eval(
&self,
ctx: &mut Context<F>,
coords: &[(AssignedValue<F>, AssignedValue<F>)],
x: AssignedValue<F>
) -> (AssignedValue<F>, AssignedValue<F>) { ... }
}Expand description
Trait that defines basic arithmetic operations for a gate.
Required Methods
sourcefn strategy(&self) -> GateStrategy
fn strategy(&self) -> GateStrategy
Returns the GateStrategy for the gate.
sourcefn pow_of_two(&self) -> &[F]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
fn pow_of_two(&self) -> &[F]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
Returns a slice of the ScalarField field elements 2^i for i in 0..F::NUM_BITS.
sourcefn get_field_element(&self, n: u64) -> F
fn get_field_element(&self, n: u64) -> F
Converts a u64 into a scalar field element ScalarField.
sourcefn inner_product<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> AssignedValue<F>where
QA: Into<QuantumCell<F>>,
fn inner_product<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> AssignedValue<F>where
QA: Into<QuantumCell<F>>,
Constrains and returns the inner product of <a, b>.
Assumes ‘a’ and ‘b’ are the same length.
ctx: Context to add the constraints toa: Iterator of QuantumCell valuesb: Iterator of QuantumCell values to take inner product ofaby
sourcefn inner_product_left_last<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> (AssignedValue<F>, AssignedValue<F>)where
QA: Into<QuantumCell<F>>,
fn inner_product_left_last<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> (AssignedValue<F>, AssignedValue<F>)where
QA: Into<QuantumCell<F>>,
Returns the inner product of <a, b> and the last element of a now assigned, i.e. (inner_product_<a, b>, last_element_a).
Assumes ‘a’ and ‘b’ are the same length.
ctx: Context of the circuita: Iterator of QuantumCellsb: Iterator of QuantumCells to take inner product ofaby
sourcefn inner_product_with_sums<'thread, QA>(
&self,
ctx: &'thread mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> Box<dyn Iterator<Item = AssignedValue<F>> + 'thread>where
QA: Into<QuantumCell<F>>,
fn inner_product_with_sums<'thread, QA>(
&self,
ctx: &'thread mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>
) -> Box<dyn Iterator<Item = AssignedValue<F>> + 'thread>where
QA: Into<QuantumCell<F>>,
Calculates and constrains the inner product.
Returns the assignment trace where output[i] has the running sum sum_{j=0..=i} a[j] * b[j].
Assumes ‘a’ and ‘b’ are the same length.
ctx: Context to add the constraints toa: Iterator of QuantumCell valuesb: Iterator of QuantumCell values to calculate the partial sums of the inner product ofaby.
sourcefn sum_products_with_coeff_and_var(
&self,
ctx: &mut Context<F>,
values: impl IntoIterator<Item = (F, QuantumCell<F>, QuantumCell<F>)>,
var: QuantumCell<F>
) -> AssignedValue<F>
fn sum_products_with_coeff_and_var(
&self,
ctx: &mut Context<F>,
values: impl IntoIterator<Item = (F, QuantumCell<F>, QuantumCell<F>)>,
var: QuantumCell<F>
) -> AssignedValue<F>
Constrains and returns the sum of products of coeff * (a * b) defined in values plus a variable var e.g.
x = var + values[0].0 * (values[0].1 * values[0].2) + values[1].0 * (values[1].1 * values[1].2) + ... + values[n].0 * (values[n].1 * values[n].2).
ctx: Context to add the constraints to.values: Iterator of tuples(coeff, a, b)wherecoeffis a field element,aandbare QuantumCell’s.var: QuantumCell that represents the value of a variable added to the sum.
sourcefn select(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
sel: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn select(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
sel: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns sel ? a : b assuming sel is boolean.
Defines a vertical gate of form | 1 - sel | sel | 1 | a | 1 - sel | sel | 1 | b | out |, where out = sel * a + (1 - sel) * b.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.sel: QuantumCell that contains a boolean value.
sourcefn or_and(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
c: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn or_and(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
c: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constains and returns a || (b && c), assuming a, b and c are boolean.
Defines a vertical gate of form | 1 - b c | b | c | 1 | a - 1 | 1 - b c | out | a - 1 | 1 | 1 | a |, where out = a + b * c - a * b * c.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.c: QuantumCell that contains a boolean value.
sourcefn num_to_bits(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>,
range_bits: usize
) -> Vec<AssignedValue<F>>
fn num_to_bits(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>,
range_bits: usize
) -> Vec<AssignedValue<F>>
Constrains and returns little-endian bit vector representation of a.
Assumes range_bits <= number of bits in a.
a: QuantumCell of the value to convertrange_bits: range of bits needed to representa
sourcefn const_right_rotate_unsafe<const BIT: usize, const NUM_BITS: usize>(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>
) -> AssignedValue<F>
fn const_right_rotate_unsafe<const BIT: usize, const NUM_BITS: usize>(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>
) -> AssignedValue<F>
Bitwise right rotate a by BIT bits. BIT and NUM_BITS must be determined at compile time.
Assumes ‘a’ is a NUM_BITS bit integer and NUM_BITS <= 128.
ctx: Context to add the constraints toa: a AssignedValue value.
sourcefn const_left_rotate_unsafe<const BIT: usize, const NUM_BITS: usize>(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>
) -> AssignedValue<F>
fn const_left_rotate_unsafe<const BIT: usize, const NUM_BITS: usize>(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>
) -> AssignedValue<F>
Bitwise left rotate a by BIT bits. BIT and NUM_BITS must be determined at compile time.
Assumes ‘a’ is a NUM_BITS bit integer and NUM_BITS <= 128.
ctx: Context to add the constraints toa: a AssignedValue value.
Provided Methods
sourcefn add(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn add(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns a + b * 1 = out.
Defines a vertical gate of form | a | b | 1 | a + b | where (a + b) = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to add to ’a`
sourcefn sub(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn sub(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns a + b * (-1) = out.
Defines a vertical gate of form | a - b | b | 1 | a |, where (a - b) = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to subtract from ‘a’
sourcefn neg(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn neg(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns a * (-1) = out.
Defines a vertical gate of form | a | -a | 1 | 0 |, where (-a) = out.
ctx: the Context to add the constraints toa: QuantumCell value to negate
sourcefn mul(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn mul(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns 0 + a * b = out.
Defines a vertical gate of form | 0 | a | b | a * b |, where (a * b) = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to multiply ‘a’ by
sourcefn mul_add(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
c: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn mul_add(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
c: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns a * b + c = out.
Defines a vertical gate of form | c | a | b | a * b + c |, where (a * b + c) = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to multiply ‘a’ byc: QuantumCell value to add to ‘a * b’
sourcefn mul_not(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn mul_not(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns (1 - a) * b = b - a * b.
Defines a vertical gate of form | (1 - a) * b | a | b | b |, where (1 - a) * b = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to multiply ‘a’ by
sourcefn assert_bit(&self, ctx: &mut Context<F>, x: AssignedValue<F>)
fn assert_bit(&self, ctx: &mut Context<F>, x: AssignedValue<F>)
Constrains that x is boolean (e.g. 0 or 1).
Defines a vertical gate of form | 0 | x | x | x |.
ctx: Context to add the constraints tox: QuantumCell value to constrain
sourcefn div_unsafe(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn div_unsafe(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns a / b = 0.
Defines a vertical gate of form | 0 | b^1 * a | b | a |, where b^1 * a = out.
Assumes b != 0.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to divide ‘a’ by
sourcefn assert_is_const(&self, ctx: &mut Context<F>, a: &AssignedValue<F>, constant: &F)
fn assert_is_const(&self, ctx: &mut Context<F>, a: &AssignedValue<F>, constant: &F)
Constrains that a is equal to constant value.
ctx: Context to add the constraints toa: QuantumCell valueconstant: constant value to constrainato be equal to
sourcefn sum<Q>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = Q>
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
fn sum<Q>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = Q>
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
Constrains and returns the sum of QuantumCell’s in iterator a.
ctx: Context to add the constraints toa: Iterator of QuantumCell values to sum
sourcefn partial_sums<'thread, Q>(
&self,
ctx: &'thread mut Context<F>,
a: impl IntoIterator<Item = Q>
) -> Box<dyn Iterator<Item = AssignedValue<F>> + 'thread>where
Q: Into<QuantumCell<F>>,
fn partial_sums<'thread, Q>(
&self,
ctx: &'thread mut Context<F>,
a: impl IntoIterator<Item = Q>
) -> Box<dyn Iterator<Item = AssignedValue<F>> + 'thread>where
Q: Into<QuantumCell<F>>,
Calculates and constrains the sum of the elements of a.
Returns the assignment trace where output[i] has the running sum sum_{j=0..=i} a[j].
ctx: Context to add the constraints toa: Iterator of QuantumCell values to sum
sourcefn accumulated_product<QA, QB>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QB>
) -> Vec<AssignedValue<F>>where
QA: Into<QuantumCell<F>>,
QB: Into<QuantumCell<F>>,
fn accumulated_product<QA, QB>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QB>
) -> Vec<AssignedValue<F>>where
QA: Into<QuantumCell<F>>,
QB: Into<QuantumCell<F>>,
Calculates and constrains the accumulated product of ‘a’ and ‘b’ i.e. x_i = b_1 * (a_1...a_{i - 1}) + b_2 * (a_2...a_{i - 1}) + ... + b_i
Returns the assignment trace where output[i] is the running accumulated product x_i.
Assumes ‘a’ and ‘b’ are the same length.
ctx: Context to add the constraints toa: Iterator of QuantumCell valuesb: Iterator of QuantumCell values to take the accumulated product ofaby
sourcefn or(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn or(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns a || b, assuming a and b are boolean.
Defines a vertical gate of form | 1 - b | 1 | b | 1 | b | a | 1 - b | out |, where out = a + b - a * b.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.
sourcefn and(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn and(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns a & b, assumeing a and b are boolean.
Defines a vertical gate of form | 0 | a | b | out |, where out = a * b.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.
sourcefn xor(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn xor(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns a ^ b, assuming a and b are boolean.
Defines a vertical gate of form | 1 - 2 * b | 2 | b | 1 | b | a | 1 - 2 * b | out |, where out = a + b - 2 * a * b.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.
sourcefn not(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn not(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains and returns !a assumeing a is boolean.
Defines a vertical gate of form | 1 - a | a | 1 | 1 |, where 1 - a = out.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.
sourcefn bits_to_indicator(
&self,
ctx: &mut Context<F>,
bits: &[AssignedValue<F>]
) -> Vec<AssignedValue<F>>
fn bits_to_indicator(
&self,
ctx: &mut Context<F>,
bits: &[AssignedValue<F>]
) -> Vec<AssignedValue<F>>
Constrains and returns an indicator vector from a slice of boolean values, where output[idx] = 1 iff idx = (the number represented by bits in binary little endian), otherwise output[idx] = 0.
ctx: Context to add the constraints tobits: slice of QuantumCell’s that contains boolean values
Assumptions
bitsis non-empty
sourcefn idx_to_indicator(
&self,
ctx: &mut Context<F>,
idx: impl Into<QuantumCell<F>>,
len: usize
) -> Vec<AssignedValue<F>>
fn idx_to_indicator(
&self,
ctx: &mut Context<F>,
idx: impl Into<QuantumCell<F>>,
len: usize
) -> Vec<AssignedValue<F>>
Constrains and returns a Vec indicator of length len, where indicator[i] == 1 if i == idx otherwise 0, if idx >= len then indicator is all zeros.
Assumes len is greater than 0.
ctx: Context to add the constraints toidx: QuantumCell index of the indicator vector to be set to 1len: length of theindicatorvector
sourcefn select_by_indicator<Q>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = Q>,
indicator: impl IntoIterator<Item = AssignedValue<F>>
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
fn select_by_indicator<Q>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = Q>,
indicator: impl IntoIterator<Item = AssignedValue<F>>
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
Constrains the inner product of a and indicator and returns a[idx] (e.g. the value of a at idx).
Assumes that a and indicator are non-empty iterators of the same length, the values of indicator are boolean,
and that indicator has at most one 1 bit.
ctx: Context to add the constraints toa: Iterator of QuantumCell’s that contains field elementsindicator: Iterator of AssignedValue’s where indicator[i] == 1 if i ==idx, otherwise 0
sourcefn select_from_idx<Q>(
&self,
ctx: &mut Context<F>,
cells: impl IntoIterator<Item = Q>,
idx: impl Into<QuantumCell<F>>
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
fn select_from_idx<Q>(
&self,
ctx: &mut Context<F>,
cells: impl IntoIterator<Item = Q>,
idx: impl Into<QuantumCell<F>>
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
Constrains and returns cells[idx] if idx < cells.len(), otherwise return 0.
Assumes that cells and idx are non-empty iterators of the same length.
ctx: Context to add the constraints tocells: Iterator of QuantumCells to select fromidx: QuantumCell with valueidxwhereidxis the index of the cell to be selected
sourcefn is_zero(&self, ctx: &mut Context<F>, a: AssignedValue<F>) -> AssignedValue<F>
fn is_zero(&self, ctx: &mut Context<F>, a: AssignedValue<F>) -> AssignedValue<F>
Constrains that a cell is equal to 0 and returns 1 if a = 0, otherwise 0.
Defines a vertical gate of form | out | a | inv | 1 | 0 | a | out | 0 |, where out = 1 if a = 0, otherwise out = 0.
ctx: Context to add the constraints toa: QuantumCell value to be constrained
sourcefn is_equal(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
fn is_equal(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>
) -> AssignedValue<F>
Constrains that the value of two cells are equal: b - a = 0, returns 1 if a = b, otherwise 0.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to compare toa
sourcefn lagrange_and_eval(
&self,
ctx: &mut Context<F>,
coords: &[(AssignedValue<F>, AssignedValue<F>)],
x: AssignedValue<F>
) -> (AssignedValue<F>, AssignedValue<F>)
fn lagrange_and_eval(
&self,
ctx: &mut Context<F>,
coords: &[(AssignedValue<F>, AssignedValue<F>)],
x: AssignedValue<F>
) -> (AssignedValue<F>, AssignedValue<F>)
Performs and constrains Lagrange interpolation on coords and evaluates the resulting polynomial at x.
Given pairs coords[i] = (x_i, y_i), let f be the unique degree len(coords) - 1 polynomial such that f(x_i) = y_i for all i.
Returns: (f(x), Prod_i(x - x_i))
ctx: Context to add the constraints tocoords: immutable reference to a slice of tuples of AssignedValues representing the points to interpolate over such thatcoords[i] = (x_i, y_i)x: x-coordinate of the point to evaluatefat
Assumptions
coordsis non-empty