Struct HypercubeStructure

Source
pub struct HypercubeStructure { /* private fields */ }
Expand description

Represents a hypercube, which is a map

  h: { 0, ..., m1 - 1 } x ... x { 0, ..., mr - 1 } -> (Z/nZ)^*
                     a1,  ...,  ar                 -> prod_i gi^ai

such that the composition (mod <p>) ∘ h is a bijection.

We use the following notation:

  • n and p as above
  • d is the order of <p> as subgroup of (Z/nZ)*
  • mi is the length of the i-th “hypercube dimension” as above
  • gi is the generator of the i-th hypercube dimension

Implementations§

Source§

impl HypercubeStructure

Source

pub fn new( galois_group: CyclotomicGaloisGroup, p: CyclotomicGaloisGroupEl, d: usize, ms: Vec<usize>, gs: Vec<CyclotomicGaloisGroupEl>, ) -> Self

Source

pub fn halevi_shoup_hypercube( galois_group: CyclotomicGaloisGroup, p: i64, ) -> Self

Computes “the” Halevi-Shoup hypercube as described in https://ia.cr/2014/873.

Note that the Halevi-Shoup hypercube is unique except for the ordering of prime factors of n. This function uses a deterministic but unspecified ordering.

Source

pub fn map_1d(&self, dim_idx: usize, steps: i64) -> CyclotomicGaloisGroupEl

Applies the hypercube structure map to the unit vector multiple steps * e_(dim_idx), i.e. computes the galois automorphism corresponding to the shift by steps steps along the dim_idx-th hypercube dimension.

Source

pub fn map(&self, idxs: &[i64]) -> CyclotomicGaloisGroupEl

Applies the hypercube structure map to the given vector.

It is not enforced that the entries of the vector are contained in { 0, ..., m1 - 1 } x ... x { 0, ..., mr - 1 }, for values outside this range the natural extension of h to Z^r is used, i.e.

  h:       Z^r      ->   (Z/nZ)^*
     a1,  ...,  ar  -> prod_i gi^ai
Source

pub fn map_usize(&self, idxs: &[usize]) -> CyclotomicGaloisGroupEl

Same as HypercubeStructure::map(), but for a vector with unsigned entries.

Source

pub fn std_preimage(&self, g: CyclotomicGaloisGroupEl) -> &[usize]

Computes the “standard preimage” of the given g under h.

This is the vector (a0, a1, ..., ar) such that g = p^a0 h(a1, ..., ar) and each ai is within { 0, ..., mi - 1 }.

Source

pub fn is_tensor_product_compatible(&self) -> bool

Returns whether each dimension of the hypercube corresponds to a factor ni of n (with ni coprime to n/ni). This is the case for the Halevi-Shoup hypercube, and very useful in some situations. If this is the case, you can query the factor of n corresponding to some dimension by HypercubeStructure::factor_of_n().

Source

pub fn factor_of_n(&self, dim_idx: usize) -> Option<i64>

Returns the factor ni of n (coprime to n/ni) which the i-th hypercube dimension corresponds to. This is only applicable if the hypercube was constructed from a (partial) factorization of n, i.e. HypercubeStructure::is_tensor_product_compatible() returns true. Otherwise, this function will return None.

Source

pub fn p(&self) -> CyclotomicGaloisGroupEl

Returns p as an element of (Z/nZ)*.

Source

pub fn frobenius(&self, power: i64) -> CyclotomicGaloisGroupEl

Returns the Galois automorphism corresponding to the power-of-p^power frobenius automorphism of the slot ring.

Source

pub fn d(&self) -> usize

Returns the rank d of the slot ring.

Source

pub fn m(&self, i: usize) -> usize

Returns the length mi of the i-th hypercube dimension.

Source

pub fn g(&self, i: usize) -> CyclotomicGaloisGroupEl

Returns the generator gi corresponding to the i-th hypercube dimension.

Source

pub fn ord_g(&self, i: usize) -> usize

Returns the order of gi in the group (Z/nZ)*.

Source

pub fn n(&self) -> usize

Returns n, i.e. the multiplicative order of the root of unity of the main ring.

Source

pub fn dim_count(&self) -> usize

Returns the number of dimensions in the hypercube.

Source

pub fn galois_group(&self) -> &CyclotomicGaloisGroup

Returns the Galois group isomorphic to (Z/nZ)* that this hypercube describes.

Source

pub fn element_count(&self) -> usize

Returns the number of elements of { 0, ..., m1 - 1 } x ... x { 0, ..., mr - 1 } or equivalently (Z/nZ)*/<p>, which is equal to the to the number of slots of Fp[X]/(Phi_n(X)).

Source

pub fn hypercube_iter<'b, G, T>( &'b self, for_slot: G, ) -> impl ExactSizeIterator<Item = T> + use<'b, G, T>
where G: 'b + Clone + FnMut(&[usize]) -> T, T: 'b,

Creates an iterator that yields a value for each element of { 0, ..., m1 - 1 } x ... x { 0, ..., mr - 1 } resp. (Z/nZ)*/<p>. Hence, these elements correspond to the slots of Fp[X]/(Phi_n(X)).

The given closure will be called on each element of { 0, ..., m1 - 1 } x ... x { 0, ..., mr - 1 }. The returned iterator will iterate over the results of the closure.

Source

pub fn element_iter<'b>( &'b self, ) -> impl ExactSizeIterator<Item = CyclotomicGaloisGroupEl> + use<'b>

Creates an iterator that one representative of each element of (Z/nZ)*/<p>, which also is in the image of this hypercube structure.

The order is compatible with HypercubeStructure::hypercube_iter().

Trait Implementations§

Source§

impl Clone for HypercubeStructure

Source§

fn clone(&self) -> HypercubeStructure

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'de> Deserialize<'de> for HypercubeStructure

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for HypercubeStructure

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for HypercubeStructure

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,