Skip to main content

zinc_uair/
ideal.rs

1pub mod rotation;
2
3use crypto_primitives::SetConfig;
4use std::fmt::{Debug, Display, Formatter};
5use thiserror::Error;
6use zinc_utils::from_ref::FromRef;
7
8/// A trait for types describing ideals.
9pub trait Ideal: FromRef<Self> + Clone + Debug + Display + Send + Sync {}
10
11/// A trait for ideals that implement membership check for the algebraic
12/// structure configured by `C`.
13pub trait IdealCheck<C: SetConfig> {
14    /// Returns true if the element belongs to this ideal.
15    fn contains(&self, cfg: &C, value: &C::Element) -> Result<bool, IdealCheckError>;
16}
17
18/// A dummy ideal. Convenient when ideal checks
19/// have to be ignored.
20#[derive(Clone, Copy, Debug)]
21pub struct ImpossibleIdeal;
22
23impl Ideal for ImpossibleIdeal {}
24
25impl Display for ImpossibleIdeal {
26    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27        write!(f, "ImpossibleIdeal")
28    }
29}
30
31impl<C: SetConfig> IdealCheck<C> for ImpossibleIdeal {
32    #[inline(always)]
33    fn contains(&self, _cfg: &C, _value: &C::Element) -> Result<bool, IdealCheckError> {
34        Ok(false)
35    }
36}
37
38impl<I: Ideal> FromRef<I> for ImpossibleIdeal {
39    #[inline(always)]
40    fn from_ref(_ideal: &I) -> Self {
41        ImpossibleIdeal
42    }
43}
44
45/// A type alias for [`RotationIdeal`][`rotation::RotationIdeal`] with `W = 1`,
46/// i.e. ideals of the form `(X - a)`.
47pub type DegreeOneIdeal<F> = rotation::RotationIdeal<F, 1>;
48
49#[derive(Clone, Debug, Error)]
50#[error("Ideal check failed: {0}")]
51pub struct IdealCheckError(String);