Skip to content

Commit

Permalink
refactor: add iterable context
Browse files Browse the repository at this point in the history
  • Loading branch information
tohrnii committed Feb 16, 2023
1 parent 088e73a commit 4d01e75
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 178 deletions.
35 changes: 12 additions & 23 deletions ir/src/constraints/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,35 +171,24 @@ impl AlgebraicGraph {
))
}
Expression::ListFolding(lf_type) => match lf_type {
ListFoldingType::Sum(lc) => {
ListFoldingType::Sum(lc) | ListFoldingType::Prod(lc) => {
let list = unfold_lc(lc, symbol_table)?;
let mut sum =
let mut acc =
self.insert_expr(symbol_table, &list[0], variable_roots, default_domain)?;
for elem in list.iter().skip(1) {
let expr =
self.insert_expr(symbol_table, elem, variable_roots, default_domain)?;
sum = self.insert_bin_op(
&sum,
&expr,
Operation::Add(sum.root_idx(), expr.root_idx()),
)?;
let op = match lf_type {
ListFoldingType::Sum(_) => {
Operation::Add(acc.root_idx(), expr.root_idx())
}
ListFoldingType::Prod(_) => {
Operation::Mul(acc.root_idx(), expr.root_idx())
}
};
acc = self.insert_bin_op(&acc, &expr, op)?;
}
Ok(sum)
}
ListFoldingType::Prod(lc) => {
let list = unfold_lc(lc, symbol_table)?;
let mut prod =
self.insert_expr(symbol_table, &list[0], variable_roots, default_domain)?;
for elem in list.iter().skip(1) {
let expr =
self.insert_expr(symbol_table, elem, variable_roots, default_domain)?;
prod = self.insert_bin_op(
&prod,
&expr,
Operation::Mul(prod.root_idx(), expr.root_idx()),
)?;
}
Ok(prod)
Ok(acc)
}
},
}
Expand Down
Loading

0 comments on commit 4d01e75

Please sign in to comment.