Skip to main content

zinc_uair/
ideal.rs

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