From 1a9fa9899b257437d818f1c16a3b3aeb2f0421a7 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 29 Jan 2021 00:45:48 +0000 Subject: [PATCH] impl {Neg, Sub} for Expression --- src/plonk/circuit.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index d74277701c..67e750cdf7 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 {