use std::collections::HashMap;
use folding::expressions::FoldingColumnTrait;
use kimchi::circuits::expr::{CacheId, FormattedOutput};
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
pub enum Column {
Relation(usize),
DynamicSelector(usize),
FixedSelector(usize),
LookupPartialSum((u32, usize)),
LookupMultiplicity((u32, usize)),
LookupAggregation,
LookupFixedTable(u32),
}
impl Column {
pub fn add_rel_offset(self, offset: usize) -> Column {
let Column::Relation(i) = self else {
todo!("add_rel_offset is only implemented for the relation columns")
};
Column::Relation(offset + i)
}
}
impl FormattedOutput for Column {
fn latex(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
match self {
Column::Relation(i) => format!("x_{{{i}}}"),
Column::FixedSelector(i) => format!("fs_{{{i}}}"),
Column::DynamicSelector(i) => format!("ds_{{{i}}}"),
Column::LookupPartialSum((table_id, i)) => format!("h_{{{table_id}, {i}}}"),
Column::LookupMultiplicity((table_id, i)) => format!("m_{{{table_id}, {i}}}"),
Column::LookupFixedTable(i) => format!("t_{{{i}}}"),
Column::LookupAggregation => String::from("φ"),
}
}
fn text(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
match self {
Column::Relation(i) => format!("x[{i}]"),
Column::FixedSelector(i) => format!("fs[{i}]"),
Column::DynamicSelector(i) => format!("ds[{i}]"),
Column::LookupPartialSum((table_id, i)) => format!("h[{table_id}, {i}]"),
Column::LookupMultiplicity((table_id, i)) => format!("m[{table_id}, {i}]"),
Column::LookupFixedTable(i) => format!("t[{i}]"),
Column::LookupAggregation => String::from("φ"),
}
}
fn ocaml(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
unimplemented!("Not used at the moment")
}
fn is_alpha(&self) -> bool {
unimplemented!("Not used at the moment")
}
}
pub trait ColumnIndexer: core::fmt::Debug + Copy + Eq + Ord {
const N_COL: usize;
fn to_column(self) -> Column;
}
impl FoldingColumnTrait for Column {
fn is_witness(&self) -> bool {
match self {
Column::Relation(_) => true,
Column::DynamicSelector(_) => true,
Column::LookupPartialSum(_) => true,
Column::LookupMultiplicity(_) => true,
Column::LookupAggregation => true,
Column::FixedSelector(_) => false,
Column::LookupFixedTable(_) => false,
}
}
}