Skip to content

Commit

Permalink
docs: Add column counts for various degree lowering targets
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 f8178df commit c26cf9c
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 35 deletions.
28 changes: 14 additions & 14 deletions specification/src/arithmetization-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

<!-- auto-gen info start table_overview -->
<!-- To update, please run `cargo test`. -->
| table name | #main cols | #aux cols | total width |
|:-------------------------------------------|-----------:|----------:|------------:|
| [ProgramTable](program-table.md) | 7 | 3 | 16 |
| [ProcessorTable](processor-table.md) | 39 | 11 | 72 |
| [OpStackTable](operational-stack-table.md) | 4 | 2 | 10 |
| [RamTable](random-access-memory-table.md) | 7 | 6 | 25 |
| [JumpStackTable](jump-stack-table.md) | 5 | 2 | 11 |
| [HashTable](hash-table.md) | 67 | 20 | 127 |
| [CascadeTable](cascade-table.md) | 6 | 2 | 12 |
| [LookupTable](lookup-table.md) | 4 | 2 | 10 |
| [U32Table](u32-table.md) | 10 | 1 | 13 |
| DegreeLowering | 203 | 36 | 311 |
| Randomizers | 0 | 1 | 3 |
| **TOTAL** | **352** | **86** | **610** |
| table name | #main cols | #aux cols | total width |
|:-------------------------------------------|----------------:|-----------------:|----------------:|
| [ProgramTable](program-table.md) | 7 | 3 | 16 |
| [ProcessorTable](processor-table.md) | 39 | 11 | 72 |
| [OpStackTable](operational-stack-table.md) | 4 | 2 | 10 |
| [RamTable](random-access-memory-table.md) | 7 | 6 | 25 |
| [JumpStackTable](jump-stack-table.md) | 5 | 2 | 11 |
| [HashTable](hash-table.md) | 67 | 20 | 127 |
| [CascadeTable](cascade-table.md) | 6 | 2 | 12 |
| [LookupTable](lookup-table.md) | 4 | 2 | 10 |
| [U32Table](u32-table.md) | 10 | 1 | 13 |
| DegreeLowering (-/8/4) | 0/111/203 | 0/14/36 | 0/153/311 |
| Randomizers | 0 | 1 | 3 |
| **TOTAL** | **149/260/352** | **50/64/86** | **299/452/610** |
<!-- auto-gen info stop table_overview -->

## Constraints
Expand Down
225 changes: 204 additions & 21 deletions triton-vm/src/table/master_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,74 @@ mod tests {
.is_zero());
}

fn initial_constraints() -> Vec<ConstraintCircuitMonad<SingleRowIndicator>> {
let circuit_builder = ConstraintCircuitBuilder::new();
vec![
ExtProgramTable::initial_constraints(&circuit_builder),
ExtProcessorTable::initial_constraints(&circuit_builder),
ExtOpStackTable::initial_constraints(&circuit_builder),
ExtRamTable::initial_constraints(&circuit_builder),
ExtJumpStackTable::initial_constraints(&circuit_builder),
ExtHashTable::initial_constraints(&circuit_builder),
ExtCascadeTable::initial_constraints(&circuit_builder),
ExtLookupTable::initial_constraints(&circuit_builder),
ExtU32Table::initial_constraints(&circuit_builder),
GrandCrossTableArg::initial_constraints(&circuit_builder),
]
.concat()
}

fn consistency_constraints() -> Vec<ConstraintCircuitMonad<SingleRowIndicator>> {
let circuit_builder = ConstraintCircuitBuilder::new();
vec![
ExtProgramTable::consistency_constraints(&circuit_builder),
ExtProcessorTable::consistency_constraints(&circuit_builder),
ExtOpStackTable::consistency_constraints(&circuit_builder),
ExtRamTable::consistency_constraints(&circuit_builder),
ExtJumpStackTable::consistency_constraints(&circuit_builder),
ExtHashTable::consistency_constraints(&circuit_builder),
ExtCascadeTable::consistency_constraints(&circuit_builder),
ExtLookupTable::consistency_constraints(&circuit_builder),
ExtU32Table::consistency_constraints(&circuit_builder),
GrandCrossTableArg::consistency_constraints(&circuit_builder),
]
.concat()
}

fn transition_constraints() -> Vec<ConstraintCircuitMonad<DualRowIndicator>> {
let circuit_builder = ConstraintCircuitBuilder::new();
vec![
ExtProgramTable::transition_constraints(&circuit_builder),
ExtProcessorTable::transition_constraints(&circuit_builder),
ExtOpStackTable::transition_constraints(&circuit_builder),
ExtRamTable::transition_constraints(&circuit_builder),
ExtJumpStackTable::transition_constraints(&circuit_builder),
ExtHashTable::transition_constraints(&circuit_builder),
ExtCascadeTable::transition_constraints(&circuit_builder),
ExtLookupTable::transition_constraints(&circuit_builder),
ExtU32Table::transition_constraints(&circuit_builder),
GrandCrossTableArg::transition_constraints(&circuit_builder),
]
.concat()
}

fn terminal_constraints() -> Vec<ConstraintCircuitMonad<SingleRowIndicator>> {
let circuit_builder = ConstraintCircuitBuilder::new();
vec![
ExtProgramTable::terminal_constraints(&circuit_builder),
ExtProcessorTable::terminal_constraints(&circuit_builder),
ExtOpStackTable::terminal_constraints(&circuit_builder),
ExtRamTable::terminal_constraints(&circuit_builder),
ExtJumpStackTable::terminal_constraints(&circuit_builder),
ExtHashTable::terminal_constraints(&circuit_builder),
ExtCascadeTable::terminal_constraints(&circuit_builder),
ExtLookupTable::terminal_constraints(&circuit_builder),
ExtU32Table::terminal_constraints(&circuit_builder),
GrandCrossTableArg::terminal_constraints(&circuit_builder),
]
.concat()
}

struct SpecSnippet {
pub start_marker: &'static str,
pub stop_marker: &'static str,
Expand Down Expand Up @@ -1520,12 +1588,21 @@ mod tests {
}

fn generate_table_overview() -> SpecSnippet {
const DEGREE_LOWERING_TARGETS: [Option<isize>; 3] = [None, Some(8), Some(4)];
assert!(DEGREE_LOWERING_TARGETS.contains(&Some(AIR_TARGET_DEGREE)));

macro_rules! table_info {
($($module:ident: $name:literal at $location:literal),* $(,)?) => {{
let mut info = vec![];
$(
let name = format!("[{}]({})", $name, $location);
info.push((name, $module::BASE_WIDTH, $module::EXT_WIDTH));
info.push(
(
name,
[$module::BASE_WIDTH; DEGREE_LOWERING_TARGETS.len()],
[$module::EXT_WIDTH; DEGREE_LOWERING_TARGETS.len()]
)
);
)*
info
}};
Expand All @@ -1543,37 +1620,143 @@ mod tests {
u32_table: "U32Table" at "u32-table.md",
];

let deg_low_base = degree_lowering_table::BASE_WIDTH;
let deg_low_ext = degree_lowering_table::EXT_WIDTH;
all_table_info.push(("DegreeLowering".to_string(), deg_low_base, deg_low_ext));
all_table_info.push(("Randomizers".to_string(), 0, NUM_RANDOMIZER_POLYNOMIALS));
let mut deg_low_base = vec![];
let mut deg_low_ext = vec![];
for maybe_target_degree in DEGREE_LOWERING_TARGETS {
if let Some(target_degree) = maybe_target_degree {
let mut initial_constraints = initial_constraints();
let mut consistency_constraints = consistency_constraints();
let mut transition_constraints = transition_constraints();
let mut terminal_constraints = terminal_constraints();

let (new_initial_constraints_main, new_initial_constraints_aux) =
ConstraintCircuitMonad::lower_to_degree(
&mut initial_constraints,
target_degree,
1000,
2000,
);
let (new_consistency_constraints_main, new_consistency_constraints_aux) =
ConstraintCircuitMonad::lower_to_degree(
&mut consistency_constraints,
target_degree,
1000,
2000,
);
let (new_transition_constraints_main, new_transition_constraints_aux) =
ConstraintCircuitMonad::lower_to_degree(
&mut transition_constraints,
target_degree,
1000,
2000,
);
let (new_terminal_constraints_main, new_terminal_constraints_aux) =
ConstraintCircuitMonad::lower_to_degree(
&mut terminal_constraints,
target_degree,
1000,
2000,
);

deg_low_base.push(
new_initial_constraints_main.len()
+ new_consistency_constraints_main.len()
+ new_transition_constraints_main.len()
+ new_terminal_constraints_main.len(),
);
deg_low_ext.push(
new_initial_constraints_aux.len()
+ new_consistency_constraints_aux.len()
+ new_transition_constraints_aux.len()
+ new_terminal_constraints_aux.len(),
);
} else {
deg_low_base.push(0);
deg_low_ext.push(0);
}
}
all_table_info.push((
format!(
"DegreeLowering ({})",
DEGREE_LOWERING_TARGETS
.iter()
.map(|maybe_target| if let Some(target) = maybe_target {
target.to_string()
} else {
"-".to_string()
})
.join("/")
),
deg_low_base.try_into().unwrap(),
deg_low_ext.try_into().unwrap(),
));
all_table_info.push((
"Randomizers".to_string(),
[0; DEGREE_LOWERING_TARGETS.len()],
[NUM_RANDOMIZER_POLYNOMIALS; DEGREE_LOWERING_TARGETS.len()],
));
let all_table_info = all_table_info;

// produce table code
let mut ft = format!("| {:<42} ", "table name");
ft = format!("{ft}| {:<10} ", "#main cols");
ft = format!("{ft}| {:<9} ", "#aux cols");
ft = format!("{ft}| {:<11} |\n", "total width");
ft = format!("{ft}| {:<15} ", "#main cols");
ft = format!("{ft}| {:<16} ", "#aux cols");
ft = format!("{ft}| {:<15} |\n", "total width");

ft = format!("{ft}|:{:-<42}-", "-");
ft = format!("{ft}|-{:-<10}:", "-");
ft = format!("{ft}|-{:-<9}:", "-");
ft = format!("{ft}|-{:-<11}:|\n", "-");
ft = format!("{ft}|-{:-<15}:", "-");
ft = format!("{ft}|-{:-<16}:", "-");
ft = format!("{ft}|-{:-<15}:|\n", "-");

let mut total_main = 0;
let mut total_aux = 0;
let mut total_main = [0; 3];
let mut total_aux = [0; 3];
for (name, num_main, num_aux) in all_table_info {
let num_total = num_main + EXTENSION_DEGREE * num_aux;
ft = format!("{ft}| {name:<42} | {num_main:>10} | {num_aux:9} | {num_total:>11} |\n");
total_main += num_main;
total_aux += num_aux;
let num_total = num_main
.iter()
.zip(num_aux.iter())
.map(|(&m, &a)| m + EXTENSION_DEGREE * a)
.collect_vec();
ft = format!(
"{ft}| {name:<42} | {:>15} | {:>16} | {:>15} |\n",
if num_main.iter().all(|n| *n == num_main[0]) {
format!("{}", num_main[0])
} else {
num_main.iter().join("/").to_string()
},
if num_aux.iter().all(|n| *n == num_aux[0]) {
format!("{}", num_aux[0])
} else {
num_aux.iter().join("/").to_string()
},
if num_total.iter().all(|n| *n == num_total[0]) {
format!("{}", num_total[0])
} else {
num_total.iter().join("/").to_string()
}
);
total_main
.iter_mut()
.zip(num_main.iter())
.for_each(|(t, n)| {
*t += *n;
});
total_aux.iter_mut().zip(num_aux.iter()).for_each(|(t, n)| {
*t += *n;
});
}
ft = format!(
"{ft}| {:<42} | {:>10} | {:>9} | {:>11} |\n",
"{ft}| {:<42} | {:>15} | {:>16} | {:>15} |\n",
"**TOTAL**",
format!("**{total_main}**"),
format!("**{total_aux}**"),
format!("**{}**", total_main + EXTENSION_DEGREE * total_aux)
format!("**{}**", total_main.iter().join("/")),
format!("**{}**", total_aux.iter().join("/")),
format!(
"**{}**",
total_main
.iter()
.zip(total_aux.iter())
.map(|(m, a)| *m + EXTENSION_DEGREE * *a)
.join("/")
)
);

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

0 comments on commit c26cf9c

Please sign in to comment.