p3_uni_stark/
symbolic_variable.rs
1use core::marker::PhantomData;
2use core::ops::{Add, Mul, Sub};
3
4use p3_field::Field;
5
6use crate::symbolic_expression::SymbolicExpression;
7
8#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
9pub enum Entry {
10 Preprocessed { offset: usize },
11 Main { offset: usize },
12 Permutation { offset: usize },
13 Public,
14 Challenge,
15}
16
17#[derive(Copy, Clone, Debug)]
19pub struct SymbolicVariable<F> {
20 pub entry: Entry,
21 pub index: usize,
22 pub(crate) _phantom: PhantomData<F>,
23}
24
25impl<F> SymbolicVariable<F> {
26 pub const fn new(entry: Entry, index: usize) -> Self {
27 Self {
28 entry,
29 index,
30 _phantom: PhantomData,
31 }
32 }
33
34 pub const fn degree_multiple(&self) -> usize {
35 match self.entry {
36 Entry::Preprocessed { .. } | Entry::Main { .. } | Entry::Permutation { .. } => 1,
37 Entry::Public | Entry::Challenge => 0,
38 }
39 }
40}
41
42impl<F: Field> From<SymbolicVariable<F>> for SymbolicExpression<F> {
43 fn from(value: SymbolicVariable<F>) -> Self {
44 SymbolicExpression::Variable(value)
45 }
46}
47
48impl<F: Field, T> Add<T> for SymbolicVariable<F>
49where
50 T: Into<SymbolicExpression<F>>,
51{
52 type Output = SymbolicExpression<F>;
53
54 fn add(self, rhs: T) -> Self::Output {
55 SymbolicExpression::from(self) + rhs.into()
56 }
57}
58
59impl<F: Field, T> Sub<T> for SymbolicVariable<F>
60where
61 T: Into<SymbolicExpression<F>>,
62{
63 type Output = SymbolicExpression<F>;
64
65 fn sub(self, rhs: T) -> Self::Output {
66 SymbolicExpression::from(self) - rhs.into()
67 }
68}
69
70impl<F: Field, T> Mul<T> for SymbolicVariable<F>
71where
72 T: Into<SymbolicExpression<F>>,
73{
74 type Output = SymbolicExpression<F>;
75
76 fn mul(self, rhs: T) -> Self::Output {
77 SymbolicExpression::from(self) * rhs.into()
78 }
79}