openvm_stark_backend/interaction/
utils.rsuse p3_air::VirtualPairCol;
use p3_field::{ExtensionField, Field, FieldAlgebra, Powers};
use super::Interaction;
pub fn generate_rlc_elements<AF: FieldAlgebra, E>(
random_element: AF,
all_interactions: &[Interaction<E>],
) -> Vec<AF> {
let max_bus_index = all_interactions
.iter()
.map(|interaction| interaction.bus_index)
.max()
.unwrap_or(0);
random_element
.powers()
.skip(1)
.take(max_bus_index + 1)
.collect()
}
pub fn generate_betas<AF: FieldAlgebra, E>(
beta: AF,
all_interactions: &[Interaction<E>],
) -> Vec<AF> {
let max_fields_len = all_interactions
.iter()
.map(|interaction| interaction.fields.len())
.max()
.unwrap_or(0);
beta.powers().take(max_fields_len).collect()
}
#[allow(dead_code)]
pub fn reduce_row<F, EF>(
preprocessed_row: &[F],
main_row: &[F],
fields: &[VirtualPairCol<F>],
alpha: EF,
betas: Powers<EF>,
) -> EF
where
F: Field,
EF: ExtensionField<F>,
{
let mut rlc = EF::ZERO;
for (columns, beta) in fields.iter().zip(betas) {
rlc += beta * columns.apply::<F, F>(preprocessed_row, main_row)
}
rlc += alpha;
rlc
}