Skip to main content

use_eigen/
multiplicity.rs

1/// Algebraic and geometric multiplicity for one eigenvalue.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub struct EigenMultiplicity {
4    algebraic: usize,
5    geometric: usize,
6}
7
8impl EigenMultiplicity {
9    /// Creates a new multiplicity pair.
10    #[must_use]
11    pub const fn new(algebraic: usize, geometric: usize) -> Self {
12        Self {
13            algebraic,
14            geometric,
15        }
16    }
17
18    /// Returns the algebraic multiplicity.
19    #[must_use]
20    pub const fn algebraic(self) -> usize {
21        self.algebraic
22    }
23
24    /// Returns the geometric multiplicity.
25    #[must_use]
26    pub const fn geometric(self) -> usize {
27        self.geometric
28    }
29
30    /// Returns whether both multiplicities are equal to one.
31    #[must_use]
32    pub const fn is_simple(self) -> bool {
33        self.algebraic == 1 && self.geometric == 1
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::EigenMultiplicity;
40
41    #[test]
42    fn exposes_algebraic_and_geometric_multiplicity() {
43        let multiplicity = EigenMultiplicity::new(3, 2);
44
45        assert_eq!(multiplicity.algebraic(), 3);
46        assert_eq!(multiplicity.geometric(), 2);
47        assert!(!multiplicity.is_simple());
48        assert!(EigenMultiplicity::new(1, 1).is_simple());
49    }
50}