1use std::collections::HashMap;
2
3use folding::expressions::FoldingColumnTrait;
4use kimchi::circuits::expr::{CacheId, FormattedOutput};
5
6#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
8pub enum Column<T> {
9 Relation(T),
11 DynamicSelector(usize),
13 FixedSelector(usize),
15 LookupPartialSum((u32, usize)),
19 LookupMultiplicity((u32, usize)),
22 LookupAggregation,
24 LookupFixedTable(u32),
26}
27
28impl Column<usize> {
29 pub fn add_rel_offset(self, offset: usize) -> Column<usize> {
31 let Column::Relation(i) = self else {
32 todo!("add_rel_offset is only implemented for the relation columns")
33 };
34 Column::Relation(offset + i)
35 }
36}
37
38impl FormattedOutput for Column<usize> {
39 fn latex(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
40 match self {
41 Column::Relation(i) => format!("x_{{{i}}}"),
42 Column::FixedSelector(i) => format!("fs_{{{i}}}"),
43 Column::DynamicSelector(i) => format!("ds_{{{i}}}"),
44 Column::LookupPartialSum((table_id, i)) => format!("h_{{{table_id}, {i}}}"),
45 Column::LookupMultiplicity((table_id, i)) => format!("m_{{{table_id}, {i}}}"),
46 Column::LookupFixedTable(i) => format!("t_{{{i}}}"),
47 Column::LookupAggregation => String::from("φ"),
48 }
49 }
50
51 fn text(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
52 match self {
53 Column::Relation(i) => format!("x[{i}]"),
54 Column::FixedSelector(i) => format!("fs[{i}]"),
55 Column::DynamicSelector(i) => format!("ds[{i}]"),
56 Column::LookupPartialSum((table_id, i)) => format!("h[{table_id}, {i}]"),
57 Column::LookupMultiplicity((table_id, i)) => format!("m[{table_id}, {i}]"),
58 Column::LookupFixedTable(i) => format!("t[{i}]"),
59 Column::LookupAggregation => String::from("φ"),
60 }
61 }
62
63 fn ocaml(&self, _cache: &mut HashMap<CacheId, Self>) -> String {
64 unimplemented!("Not used at the moment")
66 }
67
68 fn is_alpha(&self) -> bool {
69 unimplemented!("Not used at the moment")
71 }
72}
73
74pub trait ColumnIndexer<T>: core::fmt::Debug + Copy + Eq + Ord {
77 const N_COL: usize;
79
80 fn to_column(self) -> Column<T>;
82}
83
84impl<T: Copy> FoldingColumnTrait for Column<T> {
87 fn is_witness(&self) -> bool {
88 match self {
89 Column::Relation(_) => true,
91 Column::DynamicSelector(_) => true,
92 Column::LookupPartialSum(_) => true,
94 Column::LookupMultiplicity(_) => true,
95 Column::LookupAggregation => true,
96 Column::FixedSelector(_) => false,
98 Column::LookupFixedTable(_) => false,
99 }
100 }
101}