FancyArithmetic

Trait FancyArithmetic 

Source
pub trait FancyArithmetic: Fancy {
    // Required methods
    fn add(&mut self, x: &Self::Item, y: &Self::Item) -> Self::Item;
    fn sub(&mut self, x: &Self::Item, y: &Self::Item) -> Self::Item;
    fn cmul(&mut self, x: &Self::Item, c: u16) -> Self::Item;
    fn mul(
        &mut self,
        x: &Self::Item,
        y: &Self::Item,
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item>;
    fn proj(
        &mut self,
        x: &Self::Item,
        q: u16,
        tt: Option<Vec<u16>>,
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item>;

    // Provided methods
    fn add_many(&mut self, args: &[Self::Item]) -> Self::Item { ... }
    fn mod_change(
        &mut self,
        x: &Self::Item,
        to_modulus: u16,
        channel: &mut Channel<'_>,
    ) -> Result<Self::Item> { ... }
}
Expand description

DSL for arithmetic computation.

Required Methods§

Source

fn add(&mut self, x: &Self::Item, y: &Self::Item) -> Self::Item

Add x and y.

§Panics

This panics if x and y do not have equal moduli.

Source

fn sub(&mut self, x: &Self::Item, y: &Self::Item) -> Self::Item

Subtract x and y.

§Panics

This panics if x and y do not have equal moduli.

Source

fn cmul(&mut self, x: &Self::Item, c: u16) -> Self::Item

Multiply x times the constant c.

Source

fn mul( &mut self, x: &Self::Item, y: &Self::Item, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Multiply x and y.

Source

fn proj( &mut self, x: &Self::Item, q: u16, tt: Option<Vec<u16>>, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Project x according to the truth table tt. Resulting wire has modulus q.

Optional tt is useful for hiding the gate from the evaluator.

§Panics

This may panic in certain implementations if tt is None when it should be Some. In addition, it may panic if tt is improperly formed: either the length of tt is smaller than xs modulus, or the values in tt are larger than q.

Provided Methods§

Source

fn add_many(&mut self, args: &[Self::Item]) -> Self::Item

Sum up a slice of wires.

§Panics

Panics if args.len() < 2.

Source

fn mod_change( &mut self, x: &Self::Item, to_modulus: u16, channel: &mut Channel<'_>, ) -> Result<Self::Item>

Change the modulus of x to to_modulus using a projection gate.

Implementors§