Skip to content

Commit

Permalink
impl<F: FieldExt> {Neg, Sub} for Expression<F>
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d authored and therealyingtong committed Feb 11, 2021
1 parent 86dbd4c commit 1a9fa98
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/plonk/circuit.rs
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down Expand Up @@ -316,13 +319,27 @@ impl<F: Field> Expression<F> {
}
}

impl<F: FieldExt> Neg for Expression<F> {
type Output = Expression<F>;
fn neg(self) -> Self::Output {
Expression::Scaled(Box::new(self), -F::one())
}
}

impl<F> Add for Expression<F> {
type Output = Expression<F>;
fn add(self, rhs: Expression<F>) -> Expression<F> {
Expression::Sum(Box::new(self), Box::new(rhs))
}
}

impl<F: FieldExt> Sub for Expression<F> {
type Output = Expression<F>;
fn sub(self, rhs: Expression<F>) -> Expression<F> {
Expression::Sum(Box::new(self), Box::new(-rhs))
}
}

impl<F> Mul for Expression<F> {
type Output = Expression<F>;
fn mul(self, rhs: Expression<F>) -> Expression<F> {
Expand Down

0 comments on commit 1a9fa98

Please sign in to comment.