Skip to content

Commit c90bc99

Browse files
committed
Brief pass over documentation
1 parent 0ffde6b commit c90bc99

18 files changed

Lines changed: 111 additions & 95 deletions

File tree

src/error.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66
// the terms of the Mozilla Public License Version 2.0 as published by the
77
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
88

9+
//! Contains our central error enum for easy error propagation.
10+
//!
911
//! This module contains this crate's error enum. This enum can hold all sorts
1012
//! of errors occurring in this crate s.t. error propagation is simple for
1113
//! developers of this crate and all sorts of thrown errors and error types can
1214
//! be easily found and accessed by developers using this crate. Furthermore,
1315
//! the actual errors are wrapped s.t. all information about the error can be
1416
//! unwrapped again.
15-
//!
16-
//! **For developers:**
17-
//! - How to add an error to an `enum`? First of all, find a name
18-
//! that is not too specific for your current case s.t. it could be used in other
19-
//! contexts afterwards as well. Then, find the spot according to your chosen error
20-
//! name in a alphanumerically sorted way in the list of supported errors in the doc
21-
//! comment and inside the `enum` itself.
22-
//! Afterwards, add the error to the list of implemented error
23-
//! types in the doc comment of the `enum` with a short description when it is thrown.
24-
//! Probably use this description for the doc comment above the implementation of
25-
//! error in the `enum`. Then, add `#[error(<error msg>)]` to define the error message
26-
//! output once your error is thrown. Below, write down `<error name>(<input>),` to
27-
//! define the error with its name and possibly some inputs. The input can be of the
28-
//! form [`String`], but also another error, whose conversion must be declared via
29-
//! `#[from] OtherError`. It is best to use the existing structure as a guide. For any
30-
//! further information, check out the here used [`thiserror`]-crate.
17+
18+
// **For developers:**
19+
// - How to add an error to an `enum`? First of all, find a name
20+
// that is not too specific for your current case s.t. it could be used in other
21+
// contexts afterwards as well. Then, find the spot according to your chosen error
22+
// name in a alphanumerically sorted way in the list of supported errors in the doc
23+
// comment and inside the `enum` itself.
24+
// Afterwards, add the error to the list of implemented error
25+
// types in the doc comment of the `enum` with a short description when it is thrown.
26+
// Probably use this description for the doc comment above the implementation of
27+
// error in the `enum`. Then, add `#[error(<error msg>)]` to define the error message
28+
// output once your error is thrown. Below, write down `<error name>(<input>),` to
29+
// define the error with its name and possibly some inputs. The input can be of the
30+
// form [`String`], but also another error, whose conversion must be declared via
31+
// `#[from] OtherError`. It is best to use the existing structure as a guide. For any
32+
// further information, check out the here used [`thiserror`]-crate.
3133

3234
use std::ffi::NulError;
3335
use thiserror::Error;

src/integer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// the terms of the Mozilla Public License Version 2.0 as published by the
77
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
88

9+
//! Integer-based types with arbitrary length based on [`Z`].
10+
//!
911
//! This module contains the type [`Z`] for integers with arbitrary length and
1012
//! constructions over it.
1113
//! Each struct provides examples regarding usage.

src/integer_mod_q.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// the terms of the Mozilla Public License Version 2.0 as published by the
77
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
88

9+
//! Types for residue classes over integers with arbitrary length based on [`Zq`].
10+
//!
911
//! This module contains the type [`Zq`] for integers with arbitrary length
1012
//! modulus `q` and constructions over it.
1113
//! Each struct provides examples regarding usage.
@@ -14,10 +16,6 @@
1416
//! e.g. the standard rust integers.
1517
//! The [`Modulus`] is constructed as an explicit struct and can be shared across several
1618
//! [`Zq`], [`MatZq`] and [`PolyOverZq`] instances with efficient memory usage.
17-
//!
18-
//! - \[1\] John D. Dixon.
19-
//! "Exact Solution of Linear Equations Using P-Adic Expansions"
20-
//! <https://link.springer.com/article/10.1007/BF01459082>
2119
2220
mod mat_ntt_polynomial_ring_zq;
2321
mod mat_polynomial_ring_zq;

src/integer_mod_q/mat_polynomial_ring_zq/reduce.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
//! Implementations to reduce a [`MatPolynomialRingZq`] with the
1010
//! [`ModulusPolynomialRingZq`](crate::integer_mod_q::ModulusPolynomialRingZq).
11-
//!
12-
//! **For Developers** note: The [`ModulusPolynomialRingZq`](crate::integer_mod_q::ModulusPolynomialRingZq)
13-
//! is not applied automatically, and has to be called in the functions individually.
14-
//! Additionally the comparisons assume that the entries are reduced,
15-
//! hence no reduction is performed in the check.
11+
12+
// **For Developers** note: The [`ModulusPolynomialRingZq`](crate::integer_mod_q::ModulusPolynomialRingZq)
13+
// is not applied automatically, and has to be called in the functions individually.
14+
// Additionally the comparisons assume that the entries are reduced,
15+
// hence no reduction is performed in the check.
1616

1717
use super::MatPolynomialRingZq;
1818
use crate::traits::MatrixDimensions;

src/integer_mod_q/mat_zq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
//! [`MatZq`] is a type of matrix with integer entries of arbitrary length modulo `q`.
1010
//! This implementation uses the [FLINT](https://flintlib.org/) library.
11-
//!
12-
//! For **DEVELOPERS**: Many functions assume that the [`MatZq`] instances are reduced.
13-
//! To avoid unnecessary checks and reductions, always return canonical/reduced
14-
//! values. The end-user should be unable to obtain a non-reduced value.
11+
12+
// For **DEVELOPERS**: Many functions assume that the [`MatZq`] instances are reduced.
13+
// To avoid unnecessary checks and reductions, always return canonical/reduced
14+
// values. The end-user should be unable to obtain a non-reduced value.
1515

1616
use crate::{integer_mod_q::Modulus, utils::parse::partial_string};
1717
use flint_sys::fmpz_mod_mat::fmpz_mod_mat_struct;

src/integer_mod_q/mat_zq/solve.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl MatZq {
1919
/// The function uses Gaussian elimination together with Factor refinement
2020
/// to split the modulus and the Chinese remainder theorem and Hensel lifting
2121
/// to combine solutions under the split modulus.
22-
/// For Hensel lifting we use the method from [\[1\]](<index.html#:~:text=[1]>).
22+
/// For Hensel lifting we use the method from [\[1\]].
2323
///
2424
/// Note that this function does not compute a solution whenever there is one.
2525
/// If the matrix has not full rank under a modulus that divides the given one,
@@ -48,6 +48,11 @@ impl MatZq {
4848
/// - if the the number of rows of the matrix and the syndrome are different.
4949
/// - if the syndrome is not a column vector.
5050
/// - if the moduli mismatch.
51+
///
52+
/// # Reference
53+
/// - \[1\] John D. Dixon.
54+
/// "Exact Solution of Linear Equations Using P-Adic Expansions"
55+
/// <https://link.springer.com/article/10.1007/BF01459082>
5156
pub fn solve_gaussian_elimination(&self, y: &MatZq) -> Option<MatZq> {
5257
assert!(y.is_column_vector(), "The syndrome is not a column vector.");
5358
assert_eq!(
@@ -217,7 +222,7 @@ impl MatZq {
217222
}
218223

219224
/// Computes a solution for a system of linear equations under a modulus
220-
/// of the form `z^a` with the help of [\[1\]](<index.html#:~:text=[1]>).
225+
/// of the form `z^a` with the help of [\[1\]].
221226
/// It solves `Ax = y` for `x` with `A` being a [`MatZq`] value.
222227
/// If no solution is found, `None` is returned.
223228
///
@@ -339,7 +344,7 @@ impl MatZq {
339344
};
340345
}
341346

342-
// Use the method from [\[1\]](<index.html#:~:text=[1]>)
347+
// Use the method from [\[1\]]
343348
// to compute a solution for the original system.
344349
let mut b_i = y.clone();
345350
let mut x_i = &matrix_base_inv * &b_i;

src/integer_mod_q/poly_over_zq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
//! [`PolyOverZq`] is a type of polynomial with arbitrarily many coefficients of type
1010
//! [`Zq`](crate::integer_mod_q::Zq).
1111
//! This implementation uses the [FLINT](https://flintlib.org/) library.
12-
//!
13-
//! For **DEVELOPERS**: Many functions assume that the [`PolyOverZq`] instances are reduced.
14-
//! To avoid unnecessary checks and reductions, always return canonical/reduced
15-
//! values. The end-user should be unable to obtain a non-reduced value.
12+
13+
// For **DEVELOPERS**: Many functions assume that the [`PolyOverZq`] instances are reduced.
14+
// To avoid unnecessary checks and reductions, always return canonical/reduced
15+
// values. The end-user should be unable to obtain a non-reduced value.
1616

1717
use super::modulus::Modulus;
1818
use flint_sys::fmpz_mod_poly::fmpz_mod_poly_struct;

src/integer_mod_q/polynomial_ring_zq.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
//! [`PolynomialRingZq`] is a type of ring over PolyOverZq/f(X).
1010
//! Where f(X) is a [`PolyOverZq`](crate::integer_mod_q::PolyOverZq).
1111
//! This implementation uses the [FLINT](https://flintlib.org/) library.
12-
//!
13-
//! For **DEVELOPERS**: Many functions assume that the [`PolynomialRingZq`] instances are reduced.
14-
//! To avoid unnecessary checks and reductions, always return canonical/reduced
15-
//! values. The end-user should be unable to obtain a non-reduced value.
16-
//! Therefore, the DEVELOPER has to call the [`PolynomialRingZq::reduce`], whenever
17-
//! a computation may exceed the modulus, because it is not reduced automatically
12+
13+
// For **DEVELOPERS**: Many functions assume that the [`PolynomialRingZq`] instances are reduced.
14+
// To avoid unnecessary checks and reductions, always return canonical/reduced
15+
// values. The end-user should be unable to obtain a non-reduced value.
16+
// Therefore, the DEVELOPER has to call the [`PolynomialRingZq::reduce`], whenever
17+
// a computation may exceed the modulus, because it is not reduced automatically
1818

1919
use super::ModulusPolynomialRingZq;
2020
use crate::integer::PolyOverZ;

src/integer_mod_q/polynomial_ring_zq/reduce.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
//! Implementations to reduce a [`PolynomialRingZq`] with the
1010
//! [`ModulusPolynomialRingZq`](crate::integer_mod_q::ModulusPolynomialRingZq).
11-
//!
12-
//! **For Developers** note: The [`ModulusPolynomialRingZq`](crate::integer_mod_q::ModulusPolynomialRingZq)
13-
//! is not applied automatically, and has to be called in the functions individually.
14-
//! Additionally the comparisons assume that the entries are reduced,
15-
//! hence no reduction is performed in the check.
11+
12+
// **For Developers** note: The [`ModulusPolynomialRingZq`](crate::integer_mod_q::ModulusPolynomialRingZq)
13+
// is not applied automatically, and has to be called in the functions individually.
14+
// Additionally the comparisons assume that the entries are reduced,
15+
// hence no reduction is performed in the check.
1616

1717
use super::PolynomialRingZq;
1818
use flint_sys::fq::fq_reduce;

src/integer_mod_q/z_q.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
//! FLINT uses a `fmpz_mod_ctx_struct` to store functions and data used for
1414
//! optimizing modulo operations.
1515
//! This struct is wrapped in [`Modulus`] for easy use.
16-
//!
17-
//! For **DEVELOPERS**: Many functions assume that the [`Zq`] instances are reduced.
18-
//! To avoid unnecessary checks and reductions, always return canonical/reduced
19-
//! values. The end-user should be unable to obtain a non-reduced value.
16+
17+
// For **DEVELOPERS**: Many functions assume that the [`Zq`] instances are reduced.
18+
// To avoid unnecessary checks and reductions, always return canonical/reduced
19+
// values. The end-user should be unable to obtain a non-reduced value.
2020

2121
use super::Modulus;
2222
use crate::integer::Z;

0 commit comments

Comments
 (0)