p3_uni_stark/
symbolic_variable.rsuse core::marker::PhantomData;
use core::ops::{Add, Mul, Sub};
use p3_field::Field;
use crate::symbolic_expression::SymbolicExpression;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Entry {
Preprocessed { offset: usize },
Main { offset: usize },
Permutation { offset: usize },
Public,
Challenge,
}
#[derive(Copy, Clone, Debug)]
pub struct SymbolicVariable<F> {
pub entry: Entry,
pub index: usize,
pub(crate) _phantom: PhantomData<F>,
}
impl<F> SymbolicVariable<F> {
pub const fn new(entry: Entry, index: usize) -> Self {
Self {
entry,
index,
_phantom: PhantomData,
}
}
pub const fn degree_multiple(&self) -> usize {
match self.entry {
Entry::Preprocessed { .. } | Entry::Main { .. } | Entry::Permutation { .. } => 1,
Entry::Public | Entry::Challenge => 0,
}
}
}
impl<F: Field> From<SymbolicVariable<F>> for SymbolicExpression<F> {
fn from(value: SymbolicVariable<F>) -> Self {
SymbolicExpression::Variable(value)
}
}
impl<F: Field, T> Add<T> for SymbolicVariable<F>
where
T: Into<SymbolicExpression<F>>,
{
type Output = SymbolicExpression<F>;
fn add(self, rhs: T) -> Self::Output {
SymbolicExpression::from(self) + rhs.into()
}
}
impl<F: Field, T> Sub<T> for SymbolicVariable<F>
where
T: Into<SymbolicExpression<F>>,
{
type Output = SymbolicExpression<F>;
fn sub(self, rhs: T) -> Self::Output {
SymbolicExpression::from(self) - rhs.into()
}
}
impl<F: Field, T> Mul<T> for SymbolicVariable<F>
where
T: Into<SymbolicExpression<F>>,
{
type Output = SymbolicExpression<F>;
fn mul(self, rhs: T) -> Self::Output {
SymbolicExpression::from(self) * rhs.into()
}
}