Skip to content

Commit

Permalink
Merge pull request #3 from HungryCatsStudio/cesar/non-reference-polyn…
Browse files Browse the repository at this point in the history
…omial-arithmetic

Impl sub, mul and div for actual objects
  • Loading branch information
Antonio95 committed Jun 26, 2024
2 parents 5a781ae + 399264e commit c2fc330
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions poly/src/polynomial/univariate/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,15 @@ impl<'a, 'b, F: Field> Sub<&'a DensePolynomial<F>> for &'b DensePolynomial<F> {
}
}

impl<F: Field> Sub<DensePolynomial<F>> for DensePolynomial<F> {
type Output = DensePolynomial<F>;

#[inline]
fn sub(self, other: DensePolynomial<F>) -> DensePolynomial<F> {
&self - &other
}
}

impl<'a, 'b, F: Field> Sub<&'a SparsePolynomial<F>> for &'b DensePolynomial<F> {
type Output = DensePolynomial<F>;

Expand Down Expand Up @@ -584,6 +593,15 @@ impl<'a, 'b, F: Field> Div<&'a DensePolynomial<F>> for &'b DensePolynomial<F> {
}
}

impl<F: Field> Div<DensePolynomial<F>> for DensePolynomial<F> {
type Output = DensePolynomial<F>;

#[inline]
fn div(self, divisor: DensePolynomial<F>) -> DensePolynomial<F> {
&self / &divisor
}
}

impl<'b, F: Field> Mul<F> for &'b DensePolynomial<F> {
type Output = DensePolynomial<F>;

Expand All @@ -601,6 +619,15 @@ impl<'b, F: Field> Mul<F> for &'b DensePolynomial<F> {
}
}

impl<F: Field> Mul<F> for DensePolynomial<F> {
type Output = DensePolynomial<F>;

#[inline]
fn mul(self, elem: F) -> DensePolynomial<F> {
&self * elem
}
}

/// Performs O(nlogn) multiplication of polynomials if F is smooth.
impl<'a, 'b, F: FftField> Mul<&'a DensePolynomial<F>> for &'b DensePolynomial<F> {
type Output = DensePolynomial<F>;
Expand All @@ -620,6 +647,15 @@ impl<'a, 'b, F: FftField> Mul<&'a DensePolynomial<F>> for &'b DensePolynomial<F>
}
}

impl<F: FftField> Mul<DensePolynomial<F>> for DensePolynomial<F> {
type Output = DensePolynomial<F>;

#[inline]
fn mul(self, other: DensePolynomial<F>) -> DensePolynomial<F> {
&self * &other
}
}

impl<F: Field> Zero for DensePolynomial<F> {
/// Returns the zero polynomial.
fn zero() -> Self {
Expand Down

0 comments on commit c2fc330

Please sign in to comment.