Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of Sub operation #80

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions codegen/winterfell/src/air/transition_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ impl Codegen for Operation {
}
Operation::Add(l_idx, r_idx) => {
let lhs = l_idx.to_string(graph);
let rhs = r_idx.to_string(graph);

format!("{} + {}", lhs, rhs)
}
Operation::Sub(l_idx, r_idx) => {
let lhs = l_idx.to_string(graph);
let rhs = r_idx.to_string(graph);

// output Add followed by Neg as "-"
let rhs = if let Operation::Neg(n_idx) = graph.node(r_idx).op() {
format!("- ({})", n_idx.to_string(graph))
} else {
format!("+ {}", r_idx.to_string(graph))
};
format!("{} {}", lhs, rhs)
format!("{} - ({})", lhs, rhs)
}
Operation::Mul(l_idx, r_idx) => {
let lhs = l_idx.to_string(graph);
Expand Down
11 changes: 8 additions & 3 deletions ir/src/transition_constraints/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ impl AlgebraicGraph {
let rhs_base = self.accumulate_degree(cycles, rhs);
lhs_base.max(rhs_base)
}
Operation::Sub(lhs, rhs) => {
let lhs_base = self.accumulate_degree(cycles, lhs);
let rhs_base = self.accumulate_degree(cycles, rhs);
lhs_base.max(rhs_base)
}
Operation::Mul(lhs, rhs) => {
let lhs_base = self.accumulate_degree(cycles, lhs);
let rhs_base = self.accumulate_degree(cycles, rhs);
Expand Down Expand Up @@ -113,11 +118,9 @@ impl AlgebraicGraph {
// add both subexpressions.
let (lhs_type, lhs) = self.insert_expr(symbol_table, *lhs)?;
let (rhs_type, rhs) = self.insert_expr(symbol_table, *rhs)?;
// negate the right hand side.
let rhs = self.insert_op(Operation::Neg(rhs));
// add the expression.
let constraint_type = get_binop_constraint_type(lhs_type, rhs_type);
let node_index = self.insert_op(Operation::Add(lhs, rhs));
let node_index = self.insert_op(Operation::Sub(lhs, rhs));
Ok((constraint_type, node_index))
}
TransitionExpr::Mul(lhs, rhs) => {
Expand Down Expand Up @@ -268,6 +271,8 @@ pub enum Operation {
Neg(NodeIndex),
/// Addition operation applied to the nodes with the specified indices.
Add(NodeIndex, NodeIndex),
/// Subtraction operation applied to the nodes with the specified indices.
Sub(NodeIndex, NodeIndex),
/// Multiplication operation applied to the nodes with the specified indices.
Mul(NodeIndex, NodeIndex),
/// Exponentiation operation applied to the node with the specified index, using the provided
Expand Down