haloumi_core/
expressions.rs1use crate::{
4 info_traits::{ChallengeInfo, CreateQuery, QueryInfo, SelectorInfo},
5 query::{Advice, Fixed, Instance},
6};
7
8pub trait ExpressionTypes: Sized {
10 type Selector: SelectorInfo + Copy + std::fmt::Debug;
12 type FixedQuery: QueryInfo<Kind = Fixed> + CreateQuery<Self> + Copy + std::fmt::Debug;
14 type AdviceQuery: QueryInfo<Kind = Advice> + CreateQuery<Self> + Copy + std::fmt::Debug;
16 type InstanceQuery: QueryInfo<Kind = Instance> + CreateQuery<Self> + Copy + std::fmt::Debug;
18 type Challenge: ChallengeInfo + Copy + std::fmt::Debug;
20}
21
22pub trait ExpressionInfo: ExpressionTypes {
24 fn as_negation(&self) -> Option<&Self>;
27
28 fn as_fixed_query(&self) -> Option<&Self::FixedQuery>;
31}
32
33pub trait ExprBuilder<F>: ExpressionTypes {
35 fn constant(f: F) -> Self;
37
38 fn selector(selector: Self::Selector) -> Self;
40
41 fn fixed(fixed_query: Self::FixedQuery) -> Self;
43
44 fn advice(advice_query: Self::AdviceQuery) -> Self;
46
47 fn instance(instance_query: Self::InstanceQuery) -> Self;
49
50 fn challenge(challenge: Self::Challenge) -> Self;
52
53 fn negated(expr: Self) -> Self;
55
56 fn sum(lhs: Self, rhs: Self) -> Self;
58
59 fn product(lhs: Self, rhs: Self) -> Self;
61
62 fn scaled(lhs: Self, rhs: F) -> Self;
64}
65
66pub trait EvaluableExpr<F>: ExpressionTypes {
68 fn evaluate<E: EvalExpression<F, Self>>(&self, evaluator: &E) -> E::Output;
70}
71
72pub trait EvalExpression<F, E>
74where
75 E: ExpressionTypes,
76{
77 type Output;
79
80 fn constant(&self, f: &F) -> Self::Output;
82
83 fn selector(&self, selector: &E::Selector) -> Self::Output;
85
86 fn fixed(&self, fixed_query: &E::FixedQuery) -> Self::Output;
88
89 fn advice(&self, advice_query: &E::AdviceQuery) -> Self::Output;
91
92 fn instance(&self, instance_query: &E::InstanceQuery) -> Self::Output;
94
95 fn challenge(&self, challenge: &E::Challenge) -> Self::Output;
97
98 fn negated(&self, expr: Self::Output) -> Self::Output;
100
101 fn sum(&self, lhs: Self::Output, rhs: Self::Output) -> Self::Output;
103
104 fn product(&self, lhs: Self::Output, rhs: Self::Output) -> Self::Output;
106
107 fn scaled(&self, lhs: Self::Output, rhs: &F) -> Self::Output;
109}