Skip to content

Commit

Permalink
docs: Add AIR circuit node count to arithmetization overview
Browse files Browse the repository at this point in the history
  • Loading branch information
aszepieniec authored and jan-ferdinand committed Aug 12, 2024
1 parent 3b5bc12 commit c843694
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions specification/src/arithmetization-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ After automatically lowering degree to 4:
| [U32Table](u32-table.md) | 1 | 26 | 34 | 2 |
| [Grand Cross-Table Argument](table-linking.md) | 0 | 0 | 0 | 14 |
| **TOTAL** | **81** | **94** | **369** | **23** |
| (# nodes) | (538) | (676) | (6557) | (213) |
<!-- auto-gen info stop constraints_overview -->


Expand Down
10 changes: 10 additions & 0 deletions triton-vm/src/table/constraint_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,16 @@ impl<II: InputIndicator> ConstraintCircuitMonad<II> {
all_nodes
}

/// Counts the number of nodes in this multicircuit. Only counts nodes that
/// are used; not nodes that have been forgotten.
pub fn num_nodes(constraints: &[Self]) -> usize {
constraints
.iter()
.flat_map(|ccm| Self::all_nodes_in_circuit(&ccm.circuit.borrow()).into_iter())
.unique()
.count()
}

/// Returns the maximum degree of all circuits in the multicircuit.
pub(crate) fn multicircuit_degree(multicircuit: &[ConstraintCircuitMonad<II>]) -> isize {
multicircuit
Expand Down
49 changes: 41 additions & 8 deletions triton-vm/src/table/master_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,10 @@ mod tests {
// an `expr` cannot be followed up with `and`. Instead, declare this `const` to
// have an `ident`, which _can_ be followed up with `and`.
const ZERO: usize = 0;
let mut total_initial = 0usize;
let mut total_consistency = 0usize;
let mut total_transition = 0usize;
let mut total_terminal = 0usize;
let mut tables = constraint_overview_rows!(
ExtProgramTable ends at PROGRAM_TABLE_END and EXT_PROGRAM_TABLE_END.
Spec: ["ProgramTable"]("program-table.md"),
Expand Down Expand Up @@ -1652,10 +1656,6 @@ mod tests {
ft = format!("{ft}|-{:-<9}:", "-");
ft = format!("{ft}|-{:-<10}:|\n", "-");

let mut total_initial = 0;
let mut total_consistency = 0;
let mut total_transition = 0;
let mut total_terminal = 0;
let mut total_max_degree = 0;
for table in &tables {
let table_max_degree = [
Expand All @@ -1672,6 +1672,7 @@ mod tests {
let num_cons = table.consistency_constraints.len();
let num_tran = table.transition_constraints.len();
let num_term = table.terminal_constraints.len();

ft = format!(
"{ft}| {:<46} | {:>8} | {:12} | {:>11} | {:>9} | {:>10} |\n",
table.name, num_init, num_cons, num_tran, num_term, table_max_degree,
Expand Down Expand Up @@ -1704,10 +1705,14 @@ mod tests {
ft = format!("{ft}|-{:-<11}:", "-");
ft = format!("{ft}|-{:-<9}:|\n", "-");

let mut total_initial = 0;
let mut total_consistency = 0;
let mut total_transition = 0;
let mut total_terminal = 0;
total_initial = 0;
total_consistency = 0;
total_transition = 0;
total_terminal = 0;
let mut all_initial_constraints = vec![];
let mut all_consistency_constraints = vec![];
let mut all_transition_constraints = vec![];
let mut all_terminal_constraints = vec![];
for table in &mut tables {
let (new_base_initial, new_ext_initial) = ConstraintCircuitMonad::lower_to_degree(
&mut table.initial_constraints,
Expand Down Expand Up @@ -1752,6 +1757,18 @@ mod tests {
total_consistency += num_cons;
total_transition += num_tran;
total_terminal += num_term;
all_initial_constraints.extend(table.initial_constraints.iter().cloned());
all_initial_constraints.extend(new_base_initial.into_iter());
all_initial_constraints.extend(new_ext_initial.into_iter());
all_consistency_constraints.extend(table.consistency_constraints.iter().cloned());
all_consistency_constraints.extend(new_base_consistency.into_iter());
all_consistency_constraints.extend(new_ext_consistency.into_iter());
all_transition_constraints.extend(table.transition_constraints.iter().cloned());
all_transition_constraints.extend(new_base_transition.into_iter());
all_transition_constraints.extend(new_ext_transition.into_iter());
all_terminal_constraints.extend(table.terminal_constraints.iter().cloned());
all_terminal_constraints.extend(new_base_terminal.into_iter());
all_terminal_constraints.extend(new_ext_terminal.into_iter());
}
ft = format!(
"{ft}| {:<46} | {:>8} | {:>12} | {:>11} | {:>9} |\n",
Expand All @@ -1761,6 +1778,22 @@ mod tests {
format!("**{total_transition}**"),
format!("**{total_terminal}**"),
);
let num_nodes_in_all_initial_constraints =
ConstraintCircuitMonad::num_nodes(&all_initial_constraints);
let num_nodes_in_all_consistency_constraints =
ConstraintCircuitMonad::num_nodes(&all_consistency_constraints);
let num_nodes_in_all_transition_constraints =
ConstraintCircuitMonad::num_nodes(&all_transition_constraints);
let num_nodes_in_all_terminal_constraints =
ConstraintCircuitMonad::num_nodes(&all_terminal_constraints);
ft = format!(
"{ft}| {:<46} | {:>8} | {:>12} | {:>11} | {:>9} |\n",
"(# nodes)",
format!("({})", num_nodes_in_all_initial_constraints),
format!("({})", num_nodes_in_all_consistency_constraints),
format!("({})", num_nodes_in_all_transition_constraints),
format!("({})", num_nodes_in_all_terminal_constraints),
);

let how_to_update = "<!-- To update, please run `cargo test`. -->";
SpecSnippet {
Expand Down

0 comments on commit c843694

Please sign in to comment.