Skip to content

Commit

Permalink
Implement add operator between lc and lc
Browse files Browse the repository at this point in the history
  • Loading branch information
osuketh committed May 25, 2019
1 parent 2385322 commit 27eb38d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 12 additions & 0 deletions core/sonic/src/cs/lc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ impl<E: Engine> LinearCombination<E> {
}
}

impl<E: Engine> Add<LinearCombination<E>> for LinearCombination<E> {
type Output = LinearCombination<E>;

fn add(mut self, lc: LinearCombination<E>) -> LinearCombination<E> {
for (var, coeff) in lc.as_ref() {
self.0.push((*var, *coeff));
}

self
}
}

/// Operetor overloading for linear combination
/// `LinearCombination` + `(Coeff, Variable)` = `LinearCombination`
impl<E: Engine> Add<(Coeff<E>, Variable)> for LinearCombination<E> {
Expand Down
7 changes: 4 additions & 3 deletions core/sonic/src/helped/adaptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ impl <'a, E: Engine, CS: SonicCS<E> + 'a> ConstraintSystem<E>
.unwrap();

// Ensure each linear conbination is equal to evaluated value
self.cs.enforce_zero(a_lc - a);
self.cs.enforce_zero(b_lc - b);
self.cs.enforce_zero(c_lc - c);
self.cs.enforce_zero(a_lc + b_lc + c_lc - a - b - c);
// self.cs.enforce_zero(a_lc - a);
// self.cs.enforce_zero(b_lc - b);
// self.cs.enforce_zero(c_lc - c);
}

fn push_namespace<NR, N>(&mut self, _: N)
Expand Down

0 comments on commit 27eb38d

Please sign in to comment.