diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index 21879cb..3e74d7d 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -1,10 +1,13 @@ use core::cmp::max; use core::ops::{Add, Mul}; use ff::Field; -use std::convert::TryFrom; +use std::{ + convert::TryFrom, + ops::{Neg, Sub}, +}; use super::{lookup, permutation, Error}; -use crate::poly::Rotation; +use crate::{arithmetic::FieldExt, poly::Rotation}; /// A column type pub trait ColumnType: 'static + Sized {} @@ -316,6 +319,13 @@ impl Expression { } } +impl Neg for Expression { + type Output = Expression; + fn neg(self) -> Self::Output { + Expression::Scaled(Box::new(self), -F::one()) + } +} + impl Add for Expression { type Output = Expression; fn add(self, rhs: Expression) -> Expression { @@ -323,6 +333,13 @@ impl Add for Expression { } } +impl Sub for Expression { + type Output = Expression; + fn sub(self, rhs: Expression) -> Expression { + Expression::Sum(Box::new(self), Box::new(-rhs)) + } +} + impl Mul for Expression { type Output = Expression; fn mul(self, rhs: Expression) -> Expression {