use alloc::{vec, vec::Vec};
use miden_core::{
field::{ExtensionField, Field},
utils::{Matrix, RowMajorMatrix},
};
use miden_lifted_air::LiftedAir;
use super::{Challenges, LookupAir, ProverLookupBuilder, accumulate, build_lookup_fractions};
pub fn build_logup_aux_trace<A, F, EF>(
air: &A,
main: &RowMajorMatrix<F>,
challenges: &[EF],
) -> (RowMajorMatrix<EF>, Vec<EF>)
where
F: Field,
EF: ExtensionField<F>,
A: LiftedAir<F, EF>,
for<'a> A: LookupAir<ProverLookupBuilder<'a, F, EF>>,
{
let alpha = challenges[0];
let beta = challenges[1];
let lookup_challenges =
Challenges::<EF>::new(alpha, beta, air.max_message_width(), air.num_bus_ids());
let periodic = air.periodic_columns();
let fractions = build_lookup_fractions(air, main, &periodic, &lookup_challenges);
let (mut aux_trace, sigma_prime) = accumulate(&fractions);
let num_cols = aux_trace.width;
let num_rows = main.height();
debug_assert_eq!(aux_trace.height(), num_rows);
let mut drift = EF::ZERO;
for row in 0..num_rows {
aux_trace.values[row * num_cols] += drift;
drift += sigma_prime;
}
(aux_trace, vec![drift])
}