auslander 0.10.0

Computational representation theory of finite-dimensional bound quiver algebras
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
//! Monomial ideals: their combinatorial data, and their field-free analysis.
//!
//! A monomial ideal of `kQ` is generated by paths. Its data is the quiver and
//! the forbidden words, and nothing about it depends on the field.
//! [`MonomialIdeal`] carries that data, validated and reduced to the minimal
//! generators. [`MonomialPresentation`] adds the analysis: the standard-path
//! basis, the exact finiteness decision, and the Cartan matrix, all before a
//! field is chosen.
//!
//! Neither type builds a runtime algebra. Building one goes through
//! [`crate::algebra::monomial_presentation`], which turns a
//! [`MonomialIdeal`] into a [`crate::relation::Presentation`] over a field,
//! and then through the one completion and verification pipeline. For a
//! monomial ideal the standard paths are the normal words, so the basis this
//! module computes and the pipeline's normal-word basis agree word for word.
//!
//! The named families live here: linearly oriented `A_n`, Kronecker,
//! `k[x]/(xⁿ)`, linear and cyclic Nakayama, the radical-square-zero cycle,
//! and `A_n` with zero relations. Each returns a [`MonomialIdeal`].
//! [`crate::algebra`] has the matching runtime constructor.

use crate::completion::normal_word_transitions;
use crate::quiver::{ArrowId, PathWord, Quiver, QuiverError};

/// Rejected input to a monomial constructor.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MonomialError {
    /// Forbidden word `index` has length < 2. Admissibility needs `I ⊆ J²`.
    ForbiddenWordTooShort { index: usize, len: usize },
    /// Forbidden word `index` is not a path in the quiver.
    ForbiddenWordInvalid { index: usize, error: QuiverError },
    /// The standard-path language is infinite; this crate supports
    /// finite-dimensional algebras only.
    InfiniteDimensional,
    /// The Kupisch series breaks a condition of [`linear_nakayama_ideal`] or
    /// [`cyclic_nakayama_ideal`]; `reason` names the condition.
    InvalidKupisch { reason: String },
    /// No path with this start and length exists in the linear quiver.
    ZeroPathOutOfRange { start: usize, len: usize },
}

display_error! { MonomialError {
    Self::ForbiddenWordTooShort { index, len } => "forbidden word {index} has length {len}; admissibility needs length >= 2";
    Self::ForbiddenWordInvalid { index, error } => "forbidden word {index} is not a path: {error}";
    Self::InfiniteDimensional => "the standard-path language is infinite; this crate supports finite-dimensional algebras only";
    Self::InvalidKupisch { reason } => "invalid Kupisch series: {reason}";
    Self::ZeroPathOutOfRange { start, len } => "no path of length {len} starting at vertex {start} in the linear quiver";
} }

error_source! { MonomialError {
    Self::ForbiddenWordInvalid { error, .. } => Some(error),
    _ => None,
} }

/// A monomial ideal as field-free data: the quiver and the minimal forbidden
/// words.
///
/// The words are composable paths of length >= 2, sorted by length then
/// lexicographically, with duplicates and words containing another forbidden
/// word dropped. That reduction leaves the generated ideal unchanged, and it
/// fixes the relation order every downstream construction sees.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MonomialIdeal {
    quiver: Quiver,
    forbidden: Vec<Vec<ArrowId>>,
}

impl MonomialIdeal {
    /// Validates `forbidden` against `quiver` and reduces it to the minimal
    /// generators.
    ///
    /// Errors with [`MonomialError::ForbiddenWordTooShort`] for a word of
    /// length < 2 and [`MonomialError::ForbiddenWordInvalid`] for a word that
    /// does not compose in `quiver`. Both name the index in the input list,
    /// before the reduction reorders anything.
    pub fn new(
        quiver: Quiver,
        forbidden: Vec<Vec<ArrowId>>,
    ) -> Result<MonomialIdeal, MonomialError> {
        for (index, word) in forbidden.iter().enumerate() {
            if word.len() < 2 {
                return Err(MonomialError::ForbiddenWordTooShort {
                    index,
                    len: word.len(),
                });
            }
            PathWord::from_arrows(&quiver, word)
                .map_err(|error| MonomialError::ForbiddenWordInvalid { index, error })?;
        }
        Ok(MonomialIdeal {
            quiver,
            forbidden: minimal_words(forbidden),
        })
    }

    accessor_methods! {
        pub quiver() -> &Quiver = |this| &this.quiver;
        /// The minimal forbidden words, sorted by length then arrow word.
        pub forbidden() -> &[Vec<ArrowId>] = |this| &this.forbidden;
    }
}

/// The field-free combinatorics of a [`MonomialIdeal`]: the standard-path
/// basis of `kQ/I` and the Cartan matrix, before a field is chosen.
///
/// A standard path is a path containing no forbidden word as a contiguous
/// factor. Construction either certifies that the standard-path language is
/// finite or fails. The basis order matches the normal-word order of
/// [`crate::algebra::Algebra`]: `basis[v]` is the trivial path `e_v` for
/// `v < num_vertices`. Remaining entries are sorted by length, then source
/// vertex, then lexicographic arrow word.
///
/// This type analyzes; it does not construct. Build the runtime algebra over
/// a field from the [`MonomialIdeal`] with
/// [`crate::algebra::monomial_presentation`] and
/// [`crate::algebra::Algebra::new`].
///
/// ```
/// use auslander::monomial::{MonomialIdeal, MonomialPresentation};
/// use auslander::quiver::{ArrowId, Quiver};
/// let loop_x = Quiver::new(1, &[(0, 0)]).unwrap();
/// let ideal = MonomialIdeal::new(loop_x, vec![vec![ArrowId(0); 2]]).unwrap();
/// let m = MonomialPresentation::new(ideal).unwrap();
/// assert_eq!(m.dim(), 2); // k[x]/(x²): basis e, x
/// ```
#[derive(Clone, Debug)]
pub struct MonomialPresentation {
    ideal: MonomialIdeal,
    basis: Vec<PathWord>,
}

impl MonomialPresentation {
    /// Enumerates the standard-path basis of `kQ/ideal`.
    ///
    /// Errors with [`MonomialError::InfiniteDimensional`] when the
    /// standard-path language is infinite. Cycle detection on the
    /// forbidden-prefix automaton decides this exactly.
    pub fn new(ideal: MonomialIdeal) -> Result<MonomialPresentation, MonomialError> {
        let automaton = Automaton::build(&ideal.quiver, &ideal.forbidden);
        if automaton.has_cycle() {
            return Err(MonomialError::InfiniteDimensional);
        }
        let quiver = &ideal.quiver;
        let n = quiver.num_vertices() as usize;
        let mut basis: Vec<PathWord> = (0..quiver.num_vertices())
            .map(PathWord::trivial_unchecked)
            .collect();
        let mut state: Vec<usize> = (0..n).collect();
        let mut level_start = 0;
        while level_start < basis.len() {
            let level_end = basis.len();
            for i in level_start..level_end {
                let word = basis[i].arrows().to_vec();
                let target = basis[i].target();
                let s = state[i];
                for &a in quiver.arrows_from(target) {
                    if let Some(next) = automaton.step(s, a) {
                        let mut extended = word.clone();
                        extended.push(a);
                        basis.push(PathWord::from_arrows_unchecked(quiver, extended));
                        state.push(next);
                    }
                }
            }
            level_start = level_end;
        }
        Ok(MonomialPresentation { ideal, basis })
    }

    accessor_methods! {
        /// The ideal this presentation analyzes.
        pub ideal() -> &MonomialIdeal = |this| &this.ideal;
        pub quiver() -> &Quiver = |this| this.ideal.quiver();
        /// The minimal forbidden words, sorted by length then arrow word.
        pub forbidden() -> &[Vec<ArrowId>] = |this| this.ideal.forbidden();
        /// `dim_k A` = number of standard paths, the same over every field.
        pub dim() -> usize = |this| this.basis.len();
        /// The standard-path basis, in the order documented on the type.
        pub basis() -> &[PathWord] = |this| &this.basis;
    }

    /// Cartan matrix: `c[i][j] = dim e_i A e_j`, the number of standard
    /// paths from `i` to `j`; row `i` is the dimension vector of the
    /// projective `P_i = e_i A`.
    pub fn cartan_matrix(&self) -> Vec<Vec<usize>> {
        let n = self.quiver().num_vertices() as usize;
        let mut cartan = vec![vec![0usize; n]; n];
        for path in &self.basis {
            cartan[path.source() as usize][path.target() as usize] += 1;
        }
        cartan
    }
}

/// Drops duplicate words and words containing another as a contiguous factor;
/// the generated ideal is unchanged. The result is sorted by length, then
/// lexicographically.
fn minimal_words(mut words: Vec<Vec<ArrowId>>) -> Vec<Vec<ArrowId>> {
    words.sort();
    words.dedup();
    words.sort_by_key(Vec::len);
    let mut minimal: Vec<Vec<ArrowId>> = Vec::new();
    for word in words {
        let contains_kept = minimal
            .iter()
            .any(|v| word.windows(v.len()).any(|w| w == v.as_slice()));
        if !contains_kept {
            minimal.push(word);
        }
    }
    minimal
}

/// Deterministic automaton recognizing standard paths.
///
/// States `v < num_vertices`: "at vertex `v`, no forbidden-word progress".
/// Remaining states: the nonempty proper prefixes of the (minimal) forbidden
/// words. The state after reading a standard path is its longest suffix that
/// is such a prefix. A transition is absent exactly when the arrow does not
/// start at the state's vertex, or when appending it completes a forbidden
/// word. Minimality of the forbidden set guarantees that no prefix state
/// contains a forbidden factor, so every state is reachable from a start
/// state. Any cycle then proves the standard-path language infinite.
struct Automaton {
    trans: Vec<Vec<Option<usize>>>,
}

impl Automaton {
    fn build(quiver: &Quiver, forbidden: &[Vec<ArrowId>]) -> Automaton {
        let (_, trans) = normal_word_transitions(quiver, forbidden);
        Automaton { trans }
    }

    /// Kahn's algorithm. Every state is reachable, so a cycle means
    /// infinitely many standard paths.
    fn has_cycle(&self) -> bool {
        let m = self.trans.len();
        let mut indegree = vec![0usize; m];
        for row in &self.trans {
            for &t in row.iter().flatten() {
                indegree[t] += 1;
            }
        }
        let mut stack: Vec<usize> = (0..m).filter(|&s| indegree[s] == 0).collect();
        let mut visited = 0;
        while let Some(s) = stack.pop() {
            visited += 1;
            for &t in self.trans[s].iter().flatten() {
                indegree[t] -= 1;
                if indegree[t] == 0 {
                    stack.push(t);
                }
            }
        }
        visited < m
    }

    #[inline]
    fn step(&self, s: usize, a: ArrowId) -> Option<usize> {
        self.trans[s][a.index()]
    }
}

/// Linearly oriented `A_n`: vertices `0..n`, arrows `i → i+1`.
pub fn linear_quiver(n: usize) -> Quiver {
    let n = u32::try_from(n).expect("vertex count fits in u32");
    let arrows: Vec<(u32, u32)> = (0..n.saturating_sub(1)).map(|i| (i, i + 1)).collect();
    Quiver::new(n, &arrows).expect("endpoints in range by construction")
}

/// The cycle `0 → 1 → … → n-1 → 0`.
pub fn cyclic_quiver(n: usize) -> Quiver {
    let arrows: Vec<(u32, u32)> = (0..n).map(|i| (i as u32, ((i + 1) % n) as u32)).collect();
    Quiver::new(u32::try_from(n).expect("vertex count fits in u32"), &arrows)
        .expect("endpoints in range by construction")
}

/// Linearly oriented `A_n` with no relations. Runtime form:
/// [`crate::algebra::linear_an`].
pub fn linear_an_ideal(n: usize) -> MonomialIdeal {
    MonomialIdeal::new(linear_quiver(n), Vec::new()).expect("there is no forbidden word to reject")
}

/// Vertices `0, 1` and `m` parallel arrows `0 → 1`, no relations. Runtime
/// form: [`crate::algebra::kronecker`].
pub fn kronecker_ideal(m: usize) -> MonomialIdeal {
    let arrows = vec![(0u32, 1u32); m];
    let quiver = Quiver::new(2, &arrows).expect("endpoints in range by construction");
    MonomialIdeal::new(quiver, Vec::new()).expect("there is no forbidden word to reject")
}

/// `k[x]/(xⁿ)`: one vertex, one loop `x`, forbidden word `xⁿ`. Errors for
/// `n < 2` (the ideal would not be admissible). Runtime form:
/// [`crate::algebra::truncated_poly`].
pub fn truncated_poly_ideal(n: usize) -> Result<MonomialIdeal, MonomialError> {
    let quiver = Quiver::new(1, &[(0, 0)]).expect("endpoints in range by construction");
    MonomialIdeal::new(quiver, vec![vec![ArrowId(0); n]])
}

fn invalid_kupisch(reason: impl Into<String>) -> MonomialError {
    MonomialError::InvalidKupisch {
        reason: reason.into(),
    }
}

/// The linear Nakayama ideal over linearly oriented `A_n` with
/// `dim P_i = kupisch[i]`.
///
/// Valid series `c`: nonempty; `c[n-1] == 1`; `c[i] >= 2` for `i < n-1`
/// (admissibility); `c[i+1] >= c[i] - 1` (rad `P_i` is a quotient of
/// `P_{i+1}`). Anything else errors. `[3, 3, 2]` is an example: no
/// admissible ideal gives those projective dimensions. Runtime form:
/// [`crate::algebra::linear_nakayama`].
pub fn linear_nakayama_ideal(kupisch: &[usize]) -> Result<MonomialIdeal, MonomialError> {
    let n = kupisch.len();
    if n == 0 {
        return Err(invalid_kupisch("series is empty"));
    }
    if kupisch[n - 1] != 1 {
        return Err(invalid_kupisch(format!(
            "linear series must end with 1, got c[{}] = {}",
            n - 1,
            kupisch[n - 1]
        )));
    }
    for i in 0..n - 1 {
        if kupisch[i] < 2 {
            return Err(invalid_kupisch(format!(
                "c[{i}] = {} but interior entries need c >= 2",
                kupisch[i]
            )));
        }
        if kupisch[i + 1] < kupisch[i] - 1 {
            return Err(invalid_kupisch(format!(
                "c[{}] = {} violates c[i+1] >= c[i] - 1 = {}",
                i + 1,
                kupisch[i + 1],
                kupisch[i] - 1
            )));
        }
    }
    // Forbid the path from i of length c; it exists only when i + c <= n - 1.
    let forbidden = kupisch
        .iter()
        .enumerate()
        .filter(|&(i, &c)| i + c <= n - 1)
        .map(|(i, &c)| (i..i + c).map(|j| ArrowId(j as u32)).collect())
        .collect();
    MonomialIdeal::new(linear_quiver(n), forbidden)
}

/// The cyclic Nakayama ideal over the cycle `0 → 1 → … → n-1 → 0` with
/// `dim P_i = kupisch[i]`.
///
/// Valid series `c`: nonempty; `c[i] >= 2` for all `i` (admissibility);
/// cyclically `c[(i+1) % n] >= c[i] - 1`. Anything else errors. Runtime form:
/// [`crate::algebra::cyclic_nakayama`].
pub fn cyclic_nakayama_ideal(kupisch: &[usize]) -> Result<MonomialIdeal, MonomialError> {
    let n = kupisch.len();
    if n == 0 {
        return Err(invalid_kupisch("series is empty"));
    }
    for (i, &c) in kupisch.iter().enumerate() {
        if c < 2 {
            return Err(invalid_kupisch(format!(
                "c[{i}] = {c} but cyclic entries need c >= 2"
            )));
        }
        if kupisch[(i + 1) % n] < c - 1 {
            return Err(invalid_kupisch(format!(
                "c[{}] = {} violates cyclic c[i+1] >= c[i] - 1 = {}",
                (i + 1) % n,
                kupisch[(i + 1) % n],
                c - 1
            )));
        }
    }
    let forbidden: Vec<Vec<ArrowId>> = (0..n)
        .map(|i| {
            (0..kupisch[i])
                .map(|j| ArrowId(((i + j) % n) as u32))
                .collect()
        })
        .collect();
    MonomialIdeal::new(cyclic_quiver(n), forbidden)
}

/// The cyclic quiver on `n` vertices with `rad² = 0`: every length-2 path
/// forbidden. `dim = 2n`. Runtime form:
/// [`crate::algebra::radical_square_zero_cycle`].
pub fn radical_square_zero_cycle_ideal(n: usize) -> MonomialIdeal {
    let forbidden: Vec<Vec<ArrowId>> = (0..n)
        .map(|i| vec![ArrowId(i as u32), ArrowId(((i + 1) % n) as u32)])
        .collect();
    MonomialIdeal::new(cyclic_quiver(n), forbidden).expect("a length-2 path is a valid word")
}

/// Linearly oriented `A_n` with zero relations: each `(start, len)` in
/// `zero_paths` kills the unique path of length `len` from vertex `start`
/// (arrows `start, …, start + len - 1`). `kA_3/(ab)` is
/// `an_with_relations_ideal(3, &[(0, 2)])`.
///
/// Errors when a zero path runs past vertex `n - 1` or has length < 2.
/// Runtime form: [`crate::algebra::an_with_relations`].
pub fn an_with_relations_ideal(
    n: usize,
    zero_paths: &[(usize, usize)],
) -> Result<MonomialIdeal, MonomialError> {
    for &(start, len) in zero_paths {
        if n == 0 || start + len > n - 1 {
            return Err(MonomialError::ZeroPathOutOfRange { start, len });
        }
    }
    let forbidden = zero_paths
        .iter()
        .map(|&(start, len)| (start..start + len).map(|j| ArrowId(j as u32)).collect())
        .collect();
    MonomialIdeal::new(linear_quiver(n), forbidden)
}

#[cfg(test)]
mod tests {
    use super::*;

    fn present(quiver: Quiver, forbidden: Vec<Vec<ArrowId>>) -> MonomialPresentation {
        MonomialPresentation::new(MonomialIdeal::new(quiver, forbidden).unwrap()).unwrap()
    }

    #[test]
    fn loop_without_relations_is_infinite_dimensional() {
        let quiver = Quiver::new(1, &[(0, 0)]).unwrap();
        let ideal = MonomialIdeal::new(quiver, Vec::new()).unwrap();
        assert_eq!(
            MonomialPresentation::new(ideal).unwrap_err(),
            MonomialError::InfiniteDimensional
        );
    }

    #[test]
    fn cycle_without_relations_is_infinite_dimensional() {
        let quiver = Quiver::new(3, &[(0, 1), (1, 2), (2, 0)]).unwrap();
        let ideal = MonomialIdeal::new(quiver, Vec::new()).unwrap();
        assert_eq!(
            MonomialPresentation::new(ideal).unwrap_err(),
            MonomialError::InfiniteDimensional
        );
    }

    #[test]
    fn two_loops_with_xx_yy_forbidden_is_infinite() {
        // xyxyxy… never contains xx or yy, so the automaton must find the cycle.
        let quiver = Quiver::new(1, &[(0, 0), (0, 0)]).unwrap();
        let ideal = MonomialIdeal::new(
            quiver,
            vec![vec![ArrowId(0), ArrowId(0)], vec![ArrowId(1), ArrowId(1)]],
        )
        .unwrap();
        assert_eq!(
            MonomialPresentation::new(ideal).unwrap_err(),
            MonomialError::InfiniteDimensional
        );
    }

    #[test]
    fn two_loops_with_rad_square_zero_has_dim_3() {
        let quiver = Quiver::new(1, &[(0, 0), (0, 0)]).unwrap();
        let forbidden = vec![
            vec![ArrowId(0), ArrowId(0)],
            vec![ArrowId(0), ArrowId(1)],
            vec![ArrowId(1), ArrowId(0)],
            vec![ArrowId(1), ArrowId(1)],
        ];
        assert_eq!(present(quiver, forbidden).dim(), 3);
    }

    #[test]
    fn forbidden_words_reduced_to_minimal() {
        // A4 with both ab and abc: abc contains ab, so only ab survives.
        let quiver = Quiver::new(4, &[(0, 1), (1, 2), (2, 3)]).unwrap();
        let m = present(
            quiver,
            vec![
                vec![ArrowId(0), ArrowId(1), ArrowId(2)],
                vec![ArrowId(0), ArrowId(1)],
            ],
        );
        assert_eq!(m.forbidden(), &[vec![ArrowId(0), ArrowId(1)]]);
        assert_eq!(m.dim(), 8); // e0..e3, a, b, c, bc
    }

    #[test]
    fn forbidden_word_too_short_rejected() {
        let quiver = Quiver::new(2, &[(0, 1)]).unwrap();
        assert_eq!(
            MonomialIdeal::new(quiver, vec![vec![ArrowId(0)]]).unwrap_err(),
            MonomialError::ForbiddenWordTooShort { index: 0, len: 1 }
        );
    }

    #[test]
    fn forbidden_word_not_composable_rejected() {
        let quiver = Quiver::new(3, &[(0, 1), (1, 2)]).unwrap();
        assert_eq!(
            MonomialIdeal::new(quiver, vec![vec![ArrowId(1), ArrowId(0)]]).unwrap_err(),
            MonomialError::ForbiddenWordInvalid {
                index: 0,
                error: QuiverError::NotComposable { position: 0 },
            }
        );
    }

    #[test]
    fn linear_a3_basis_and_cartan() {
        let m = MonomialPresentation::new(linear_an_ideal(3)).unwrap();
        assert_eq!(m.dim(), 6);
        assert_eq!(
            m.cartan_matrix(),
            vec![vec![1, 1, 1], vec![0, 1, 1], vec![0, 0, 1]]
        );
        let lengths: Vec<usize> = m.basis().iter().map(PathWord::len).collect();
        assert_eq!(lengths, vec![0, 0, 0, 1, 1, 2]);
    }

    #[test]
    fn named_family_dimensions() {
        let dim = |ideal| MonomialPresentation::new(ideal).unwrap().dim();
        assert_eq!(dim(kronecker_ideal(2)), 4);
        assert_eq!(dim(truncated_poly_ideal(3).unwrap()), 3);
        assert_eq!(dim(linear_nakayama_ideal(&[2, 2, 1]).unwrap()), 5);
        assert_eq!(dim(cyclic_nakayama_ideal(&[3, 3, 3]).unwrap()), 9);
        assert_eq!(dim(radical_square_zero_cycle_ideal(3)), 6);
        assert_eq!(dim(an_with_relations_ideal(3, &[(0, 2)]).unwrap()), 5);
    }

    #[test]
    fn invalid_family_parameters_rejected() {
        assert!(matches!(
            truncated_poly_ideal(1),
            Err(MonomialError::ForbiddenWordTooShort { index: 0, len: 1 })
        ));
        for kupisch in [&[3, 3, 2][..], &[4, 2, 1][..]] {
            assert!(matches!(
                linear_nakayama_ideal(kupisch),
                Err(MonomialError::InvalidKupisch { .. })
            ));
        }
        for kupisch in [&[2, 1, 2][..], &[4, 2, 2][..]] {
            assert!(matches!(
                cyclic_nakayama_ideal(kupisch),
                Err(MonomialError::InvalidKupisch { .. })
            ));
        }
        assert_eq!(
            an_with_relations_ideal(3, &[(1, 2)]).unwrap_err(),
            MonomialError::ZeroPathOutOfRange { start: 1, len: 2 }
        );
    }
}