Skip to main content

oxilean_std/reverse_mathematics/
functions.rs

1//! Auto-generated module
2//!
3//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
4
5use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
6
7use super::types::{
8    BigFiveStats, BigFiveSystem, ComputableFunction, ConservationResult, ConstructivePrinciple,
9    IndependenceResult, OmegaModel, Pi11Sentence, ProofSystem, RCA0AxiomKind, RMA0System,
10    RMHierarchy, RMPrinciple, RMScoreboard, RMStrength, RMTheorem, RamseyColoringFinder,
11    WeakKonigTree,
12};
13
14pub fn app(f: Expr, a: Expr) -> Expr {
15    Expr::App(Box::new(f), Box::new(a))
16}
17pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
18    app(app(f, a), b)
19}
20pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
21    app(app2(f, a, b), c)
22}
23pub fn cst(s: &str) -> Expr {
24    Expr::Const(Name::str(s), vec![])
25}
26pub fn prop() -> Expr {
27    Expr::Sort(Level::zero())
28}
29pub fn type0() -> Expr {
30    Expr::Sort(Level::succ(Level::zero()))
31}
32pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
33    Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
34}
35pub fn arrow(a: Expr, b: Expr) -> Expr {
36    pi(BinderInfo::Default, "_", a, b)
37}
38pub fn impl_pi(name: &str, dom: Expr, body: Expr) -> Expr {
39    pi(BinderInfo::Implicit, name, dom, body)
40}
41pub fn bvar(n: u32) -> Expr {
42    Expr::BVar(n)
43}
44pub fn nat_ty() -> Expr {
45    cst("Nat")
46}
47pub fn bool_ty() -> Expr {
48    cst("Bool")
49}
50/// SecondOrderArithmetic: the ambient formal system (ℕ + set variables).
51/// SecondOrderArithmetic : Type
52pub fn second_order_arithmetic_ty() -> Expr {
53    type0()
54}
55/// ArithmeticalFormula: a formula with only numeric (first-order) quantifiers.
56/// ArithmeticalFormula : Prop
57pub fn arithmetical_formula_ty() -> Expr {
58    prop()
59}
60/// Sigma01Formula: bounded existential formula.
61pub fn sigma01_formula_ty() -> Expr {
62    prop()
63}
64/// Pi01Formula: bounded universal formula.
65pub fn pi01_formula_ty() -> Expr {
66    prop()
67}
68/// Delta01Formula: both Σ⁰_1 and Π⁰_1 (recursive / decidable).
69pub fn delta01_formula_ty() -> Expr {
70    prop()
71}
72/// Sigma11Formula: formula with a leading existential set quantifier.
73pub fn sigma11_formula_ty() -> Expr {
74    prop()
75}
76/// Pi11Formula: formula with a leading universal set quantifier.
77pub fn pi11_formula_ty() -> Expr {
78    prop()
79}
80/// RCA0: Recursive Comprehension Axiom (base system).
81/// RCA0 : Prop  (provable sentences in the system)
82pub fn rca0_ty() -> Expr {
83    prop()
84}
85/// Provable_RCA0: a sentence φ is provable in RCA₀.
86/// Provable_RCA0 : ArithmeticalFormula → Prop
87pub fn provable_rca0_ty() -> Expr {
88    arrow(arithmetical_formula_ty(), prop())
89}
90/// WKL0: Weak König's Lemma (over RCA₀).
91/// WKL0 : Prop
92pub fn wkl0_ty() -> Expr {
93    prop()
94}
95/// WeakKonigsLemma: every infinite binary tree has an infinite path.
96/// WeakKonigsLemma : BinaryTree → Prop → Prop
97pub fn weak_konigs_lemma_ty() -> Expr {
98    arrow(
99        cst("BinaryTree"),
100        arrow(app(cst("IsInfinite"), cst("BinaryTree")), prop()),
101    )
102}
103/// ACA0: Arithmetical Comprehension Axiom.
104/// ACA0 : Prop
105pub fn aca0_ty() -> Expr {
106    prop()
107}
108/// ArithmeticalComprehension: ∀ arithmetical φ, the set {n | φ(n)} exists.
109/// ArithmeticalComprehension : ArithmeticalFormula → Prop
110pub fn arithmetical_comprehension_ty() -> Expr {
111    arrow(arithmetical_formula_ty(), prop())
112}
113/// ATR0: Arithmetical Transfinite Recursion.
114/// ATR0 : Prop
115pub fn atr0_ty() -> Expr {
116    prop()
117}
118/// ArithmeticalTransfiniteRecursion:
119///   for any well-ordering ≺ and arithmetical operation φ,
120///   the hierarchy indexed by ≺ exists.
121pub fn arithmetical_transfinite_recursion_ty() -> Expr {
122    arrow(
123        cst("WellOrdering"),
124        arrow(arithmetical_formula_ty(), prop()),
125    )
126}
127/// Pi11CA0: Π¹_1 Comprehension Axiom.
128/// Pi11CA0 : Prop
129pub fn pi11_ca0_ty() -> Expr {
130    prop()
131}
132/// Pi11Comprehension: ∀ Π¹_1 formula φ, the set {n | φ(n)} exists.
133pub fn pi11_comprehension_ty() -> Expr {
134    arrow(pi11_formula_ty(), prop())
135}
136/// Conservative: system S₁ is conservative over S₂ for class Γ.
137/// Conservative : System → System → FormulaClass → Prop
138pub fn conservative_ty() -> Expr {
139    arrow(
140        cst("System"),
141        arrow(cst("System"), arrow(cst("FormulaClass"), prop())),
142    )
143}
144/// WKL0ConservativeOverRCA0:
145///   WKL₀ is Π¹_1-conservative over RCA₀.
146///   (Any Π¹_1 sentence provable in WKL₀ is already provable in RCA₀.)
147pub fn wkl0_conservative_over_rca0_ty() -> Expr {
148    app3(
149        cst("Conservative"),
150        cst("WKL0"),
151        cst("RCA0"),
152        cst("Pi11FormulasClass"),
153    )
154}
155/// ACA0EquivalentToPA:
156///   ACA₀ is conservative over first-order Peano Arithmetic (PA).
157///   For every first-order sentence φ: ACA₀ ⊢ φ ↔ PA ⊢ φ.
158pub fn aca0_conservative_over_pa_ty() -> Expr {
159    app3(
160        cst("Conservative"),
161        cst("ACA0"),
162        cst("PeanoArithmetic"),
163        cst("FirstOrderFormulas"),
164    )
165}
166/// ATR0ConservativeOverRCA0ForPi12:
167///   ATR₀ is Π¹_2-conservative over ACA₀.
168pub fn atr0_conservative_ty() -> Expr {
169    app3(
170        cst("Conservative"),
171        cst("ATR0"),
172        cst("ACA0"),
173        cst("Pi12FormulasClass"),
174    )
175}
176/// OmegaModelWKL0:
177///   Every countable coded ω-model of RCA₀ embeds into a model of WKL₀.
178pub fn omega_model_wkl0_ty() -> Expr {
179    arrow(
180        app(cst("OmegaModel"), cst("RCA0")),
181        app(cst("OmegaModel"), cst("WKL0")),
182    )
183}
184/// OrderTypeEquivalence: the subsystems form a linear order under provability.
185/// RCA₀ < WKL₀ < ACA₀ < ATR₀ < Π¹_1-CA₀
186pub fn subsystem_linear_order_ty() -> Expr {
187    arrow(cst("System"), arrow(cst("System"), prop()))
188}
189/// BolzanoWeierstrass: every bounded sequence of reals has a convergent subsequence.
190/// Equivalent to ACA₀ over RCA₀.
191pub fn bolzano_weierstrass_ty() -> Expr {
192    arrow(
193        app(cst("BoundedSequence"), cst("Real")),
194        app(cst("HasConvergentSubsequence"), bvar(0)),
195    )
196}
197/// HahnBanachTheorem: over WKL₀.
198pub fn hahn_banach_ty() -> Expr {
199    arrow(cst("NormedSpace"), arrow(cst("LinearFunctional"), prop()))
200}
201/// BrouwerFixedPoint: every continuous function from disk to disk has a fixed point.
202/// Equivalent to WKL₀ over RCA₀.
203pub fn brouwer_fixed_point_ty() -> Expr {
204    impl_pi(
205        "f",
206        arrow(cst("Disk"), cst("Disk")),
207        arrow(
208            app(cst("Continuous"), bvar(0)),
209            app(cst("HasFixedPoint"), bvar(1)),
210        ),
211    )
212}
213/// MaximalIdealTheorem: every commutative ring has a maximal ideal.
214/// Equivalent to WKL₀ over RCA₀.
215pub fn maximal_ideal_theorem_ty() -> Expr {
216    impl_pi("R", cst("CommRing"), app(cst("HasMaximalIdeal"), bvar(0)))
217}
218/// CompletenessTheorem: Gödel completeness for countable languages.
219/// Equivalent to WKL₀ over RCA₀.
220pub fn completeness_theorem_ty() -> Expr {
221    impl_pi(
222        "L",
223        cst("CountableLanguage"),
224        arrow(
225            app(cst("Consistent"), bvar(0)),
226            app(cst("HasModel"), bvar(1)),
227        ),
228    )
229}
230/// KonigLemma: every infinite, finitely-branching tree has an infinite path.
231/// Equivalent to WKL₀ over RCA₀ for binary trees (the full Königs lemma is ACA₀).
232pub fn konig_lemma_ty() -> Expr {
233    arrow(
234        cst("FinBranchingTree"),
235        arrow(
236            app(cst("IsInfiniteTree"), bvar(0)),
237            app(cst("HasInfinitePath"), bvar(1)),
238        ),
239    )
240}
241/// RamseyN2K: Ramsey's theorem for n-tuples with k colors.
242/// Ramsey(n, k) : Prop — every k-coloring of [ℕ]^n has an infinite homogeneous set.
243pub fn ramsey_ty() -> Expr {
244    arrow(nat_ty(), arrow(nat_ty(), prop()))
245}
246/// RT22: Ramsey's theorem for pairs with 2 colors (Ramsey(2, 2)).
247/// This is the most-studied case; its exact strength is between RCA₀ and ACA₀.
248pub fn rt22_ty() -> Expr {
249    prop()
250}
251/// RT21: Ramsey's theorem for pairs, stable version (Σ⁰_2-conservative over RCA₀).
252pub fn rt21_ty() -> Expr {
253    prop()
254}
255/// SRT22: Stable Ramsey's theorem for pairs (Cholak–Jockusch–Slaman).
256pub fn srt22_ty() -> Expr {
257    prop()
258}
259/// CAC: Chain-Antichain principle (Dilworth).
260/// Every partial order on ℕ has an infinite chain or antichain.
261/// CAC ↔ ACA₀ over RCA₀ (Hirschfeldt–Shore).
262pub fn cac_ty() -> Expr {
263    impl_pi(
264        "P",
265        cst("PartialOrder"),
266        arrow(
267            app(cst("IsInfinitePoset"), bvar(0)),
268            app2(cst("ChainOrAntichain"), bvar(1), bvar(0)),
269        ),
270    )
271}
272/// ADS: Ascending / Descending Sequence principle.
273/// Every infinite linear order has an infinite ascending or descending sequence.
274pub fn ads_ty() -> Expr {
275    impl_pi(
276        "L",
277        cst("LinearOrder"),
278        arrow(
279            app(cst("IsInfiniteOrder"), bvar(0)),
280            app2(cst("AscOrDescSeq"), bvar(1), bvar(0)),
281        ),
282    )
283}
284/// SADS: Stable Ascending/Descending Sequence.
285pub fn sads_ty() -> Expr {
286    impl_pi(
287        "L",
288        cst("LinearOrder"),
289        arrow(
290            app(cst("IsStableOrder"), bvar(0)),
291            app2(cst("AscOrDescSeq"), bvar(1), bvar(0)),
292        ),
293    )
294}
295/// DNR: Diagonally Non-recursive functions exist.
296/// Strictly between RCA₀ and WKL₀.
297pub fn dnr_ty() -> Expr {
298    app(cst("Exists"), cst("DiagonallyNonRecursive"))
299}
300/// FSSets: the set of finite sums of an infinite sequence.
301/// FSSets : (Nat → Nat) → Set Nat
302pub fn fssets_ty() -> Expr {
303    arrow(arrow(nat_ty(), nat_ty()), app(cst("Set"), nat_ty()))
304}
305/// HindmanTheorem: for any finite coloring of ℕ there is an infinite set
306/// whose finite sum set is monochromatic.
307/// HindmanTheorem : Nat → Prop
308///   (parameterized by number of colors)
309pub fn hindman_theorem_ty() -> Expr {
310    arrow(nat_ty(), prop())
311}
312/// IdempotentUltrafilter: an ultrafilter p such that p + p = p (in βℕ).
313/// IdempotentUltrafilter : Type
314pub fn idempotent_ultrafilter_ty() -> Expr {
315    type0()
316}
317/// HindmanFromIdempotent: Hindman's theorem follows from the existence of
318/// idempotent ultrafilters.
319pub fn hindman_from_idempotent_ty() -> Expr {
320    arrow(cst("IdempotentUltrafilter"), hindman_theorem_ty())
321}
322/// HindmanStrength: Hindman's theorem is provable in ACA₀⁺ but not in ACA₀.
323/// (Blass–Hirst–Simpson)
324pub fn hindman_strength_ty() -> Expr {
325    app2(cst("ProvableIn"), cst("HindmanTheorem"), cst("ACA0Plus"))
326}
327/// Compute a lower bound on the Ramsey number R(s, t) using the inequality
328/// R(s, t) ≥ R(s-1, t) + R(s, t-1) (Erdős–Szekeres recursion lower bound).
329/// Returns exact values for small cases.
330pub fn ramsey_number_lower_bound(s: u32, t: u32) -> u32 {
331    match (s, t) {
332        (1, _) => 1,
333        (_, 1) => 1,
334        (2, k) | (k, 2) => k,
335        (3, 3) => 6,
336        (3, 4) | (4, 3) => 9,
337        (3, 5) | (5, 3) => 14,
338        (3, 6) | (6, 3) => 18,
339        (3, 7) | (7, 3) => 23,
340        (3, 8) | (8, 3) => 28,
341        (3, 9) | (9, 3) => 36,
342        (4, 4) => 18,
343        (4, 5) | (5, 4) => 25,
344        _ => {
345            let n = (s + t - 2) as u64;
346            let k = (s - 1) as u64;
347            let mut binom: u64 = 1;
348            for i in 0..k {
349                binom = binom.saturating_mul(n - i).saturating_div(i + 1);
350            }
351            binom.min(u32::MAX as u64) as u32
352        }
353    }
354}
355/// Check whether a coloring of pairs from {0..n} is a valid k-coloring
356/// (all values are < k).
357pub fn is_valid_coloring(n: usize, coloring: &[Vec<u32>], k: u32) -> bool {
358    for i in 0..n {
359        if coloring.len() <= i {
360            return false;
361        }
362        for j in (i + 1)..n {
363            if coloring[i].len() <= j {
364                return false;
365            }
366            if coloring[i][j] >= k {
367                return false;
368            }
369        }
370    }
371    true
372}
373/// Find the largest monochromatic clique in a 2-coloring of pairs.
374/// Returns (color, set of vertices forming an approximately maximal monochromatic set).
375/// Uses a greedy approach for tractability.
376pub fn greedy_homogeneous_set(n: usize, coloring: &[Vec<u32>]) -> (u32, Vec<usize>) {
377    let mut best: (u32, Vec<usize>) = (0, vec![]);
378    for start_color in 0..2u32 {
379        let mut hom_set = vec![0usize];
380        for v in 1..n {
381            let monochromatic = hom_set.iter().all(|&u| {
382                let (i, j) = (u.min(v), u.max(v));
383                coloring
384                    .get(i)
385                    .and_then(|row| row.get(j))
386                    .copied()
387                    .unwrap_or(2)
388                    == start_color
389            });
390            if monochromatic {
391                hom_set.push(v);
392            }
393        }
394        if hom_set.len() > best.1.len() {
395            best = (start_color, hom_set);
396        }
397    }
398    best
399}
400/// ComputableFunction: a (partial) function ℕ → ℕ computed by a Turing machine.
401/// ComputableFunction : Type
402pub fn computable_function_ty() -> Expr {
403    type0()
404}
405/// TuringDegree: an equivalence class of sets under Turing reducibility.
406/// TuringDegree : Type
407pub fn turing_degree_ty() -> Expr {
408    type0()
409}
410/// TuringReducible: A is Turing-reducible to B (A ≤_T B).
411/// TuringReducible : Set Nat → Set Nat → Prop
412pub fn turing_reducible_ty() -> Expr {
413    arrow(
414        app(cst("Set"), nat_ty()),
415        arrow(app(cst("Set"), nat_ty()), prop()),
416    )
417}
418/// ComputablelyEnumerable: X is computably enumerable (Σ⁰_1 set).
419/// ComputablelyEnumerable : Set Nat → Prop
420pub fn computably_enumerable_ty() -> Expr {
421    arrow(app(cst("Set"), nat_ty()), prop())
422}
423/// HaltingProblem: the set K = {e | φ_e(e) ↓} is c.e. but not computable.
424/// HaltingProblem : Set Nat
425pub fn halting_problem_ty() -> Expr {
426    app(cst("Set"), nat_ty())
427}
428/// HaltingProblemIsCE: K is computably enumerable (provable in RCA₀).
429pub fn halting_problem_is_ce_ty() -> Expr {
430    app(cst("ComputablelyEnumerable"), cst("HaltingProblem"))
431}
432/// HaltingProblemNotComputable: K is not computable (provable in RCA₀ via diagonalisation).
433pub fn halting_problem_not_computable_ty() -> Expr {
434    app(cst("Not"), app(cst("Computable"), cst("HaltingProblem")))
435}
436/// PostTheorem: X is c.e. iff X is Σ⁰_1-definable (provable in RCA₀).
437/// PostTheorem : Set Nat → Prop
438pub fn post_theorem_ty() -> Expr {
439    arrow(
440        app(cst("Set"), nat_ty()),
441        arrow(
442            app(cst("ComputablelyEnumerable"), bvar(0)),
443            app(cst("Sigma01Definable"), bvar(1)),
444        ),
445    )
446}
447/// RecursiveSeparation: two disjoint c.e. sets can be separated by a computable set
448/// iff one reduces to the other — the c.e. non-computable separation.
449pub fn recursive_separation_ty() -> Expr {
450    arrow(
451        app(cst("Set"), nat_ty()),
452        arrow(
453            app(cst("Set"), nat_ty()),
454            arrow(
455                app(cst("Disjoint"), bvar(0)),
456                app2(cst("HasComputableSeparation"), bvar(2), bvar(1)),
457            ),
458        ),
459    )
460}
461/// OracleComputable: f is computable relative to oracle X.
462/// OracleComputable : (Set Nat) → (Nat → Nat) → Prop
463pub fn oracle_computable_ty() -> Expr {
464    arrow(
465        app(cst("Set"), nat_ty()),
466        arrow(arrow(nat_ty(), nat_ty()), prop()),
467    )
468}
469/// InfiniteBinaryTree: a subtree of 2^{<ω} with no infinite path.
470/// InfiniteBinaryTree : Type
471pub fn infinite_binary_tree_ty() -> Expr {
472    type0()
473}
474/// KonigsLemmaForBinaryTrees: every infinite binary tree has an infinite branch.
475/// This is exactly WKL₀ (over RCA₀).
476pub fn konigs_lemma_binary_ty() -> Expr {
477    impl_pi(
478        "T",
479        cst("InfiniteBinaryTree"),
480        app(cst("HasInfiniteBranch"), bvar(0)),
481    )
482}
483/// HasInfiniteBranch: an infinite binary tree T has an infinite branch.
484/// HasInfiniteBranch : InfiniteBinaryTree → Prop
485pub fn has_infinite_branch_ty() -> Expr {
486    arrow(cst("InfiniteBinaryTree"), prop())
487}
488/// BinaryTreePath: a path (branch) through a binary tree up to length n.
489/// BinaryTreePath : Nat → Type
490pub fn binary_tree_path_ty() -> Expr {
491    arrow(nat_ty(), type0())
492}
493/// WKL0EquivalentToKonigsLemma: the two formulations are interderivable over RCA₀.
494pub fn wkl0_equiv_konig_ty() -> Expr {
495    app2(cst("Iff"), cst("WKL0"), cst("KonigsLemmaForBinaryTrees"))
496}
497/// HyperArithmetical: a set X ⊆ ℕ is hyperarithmetical (in Δ¹_1).
498/// HyperArithmetical : Set Nat → Prop
499pub fn hyperarithmetical_ty() -> Expr {
500    arrow(app(cst("Set"), nat_ty()), prop())
501}
502/// HyperArithmeticalHierarchy: the hierarchy indexed by recursive ordinals.
503/// HyperArithmeticalHierarchy : RecursiveOrdinal → Set Nat → Prop
504pub fn hyperarithmetical_hierarchy_ty() -> Expr {
505    arrow(
506        cst("RecursiveOrdinal"),
507        arrow(app(cst("Set"), nat_ty()), prop()),
508    )
509}
510/// Pi11Comprehension0: Π¹_1-CA₀ directly asserts set existence for Π¹_1 formulas.
511/// Equivalent to: every Π¹_1 set exists.
512pub fn pi11_ca0_set_existence_ty() -> Expr {
513    impl_pi(
514        "phi",
515        pi11_formula_ty(),
516        app(cst("Exists"), app(cst("SetOf"), bvar(0))),
517    )
518}
519/// BarInduction: Brouwer's bar induction principle.
520/// Equivalent to ATR₀ over RCA₀ (in the linear-order formulation).
521/// BarInduction : WellFoundedTree → Prop
522pub fn bar_induction_ty() -> Expr {
523    arrow(cst("WellFoundedTree"), prop())
524}
525/// OpenDeterminacy: every open game on ℕ is determined.
526/// Equivalent to ATR₀ over RCA₀ (Steel 1976).
527pub fn open_determinacy_ty() -> Expr {
528    impl_pi("G", cst("OpenGame"), app(cst("IsDetermined"), bvar(0)))
529}
530/// BorelDeterminacy: every Borel game on ℕ is determined (Martin 1975).
531/// Requires at least Σ¹_1 sets; not provable in second-order arithmetic.
532pub fn borel_determinacy_ty() -> Expr {
533    impl_pi("G", cst("BorelGame"), app(cst("IsDetermined"), bvar(0)))
534}
535/// ProjectiveDeterminacy: every projective game is determined.
536/// Follows from large cardinal axioms (Woodin cardinals).
537pub fn projective_determinacy_ty() -> Expr {
538    impl_pi(
539        "G",
540        cst("ProjectiveGame"),
541        app(cst("IsDetermined"), bvar(0)),
542    )
543}
544/// Sigma11Determinacy: every Σ¹_1 (analytic) game is determined.
545/// Equivalent to Π¹_1-CA₀ over ATR₀ (Tanaka 1990).
546pub fn sigma11_determinacy_ty() -> Expr {
547    impl_pi("G", cst("Sigma11Game"), app(cst("IsDetermined"), bvar(0)))
548}
549/// WellOrderingTheorem: every set can be well-ordered.
550/// Equivalent to ATR₀ over RCA₀ (for countable sets, Friedman).
551pub fn well_ordering_theorem_ty() -> Expr {
552    impl_pi("S", type0(), app(cst("CanBeWellOrdered"), bvar(0)))
553}
554/// ComparisonOfWellOrderings: any two well-orderings are comparable.
555/// Equivalent to ATR₀ over RCA₀.
556pub fn comparison_of_well_orderings_ty() -> Expr {
557    arrow(
558        cst("WellOrdering"),
559        arrow(
560            cst("WellOrdering"),
561            app2(cst("ComparableOrders"), bvar(0), bvar(0)),
562        ),
563    )
564}
565/// WellOrderingIsLinear: every well-ordering is a linear ordering.
566/// Provable in RCA₀.
567pub fn well_ordering_is_linear_ty() -> Expr {
568    impl_pi("W", cst("WellOrdering"), app(cst("IsLinearOrder"), bvar(0)))
569}
570/// InfiniteLinearOrderHasOmegaOrOmegaStar:
571///   Every countably infinite linear ordering contains a copy of ω or ω*.
572///   Equivalent to ACA₀ over RCA₀.
573pub fn linear_order_omega_ty() -> Expr {
574    impl_pi(
575        "L",
576        cst("LinearOrder"),
577        arrow(
578            app(cst("IsInfiniteOrder"), bvar(0)),
579            app2(cst("ContainsOmegaOrOmegaStar"), bvar(1), bvar(0)),
580        ),
581    )
582}
583/// ScattereredLinearOrdering: L has no dense sub-ordering.
584/// ScatteredLinearOrdering : LinearOrder → Prop
585pub fn scattered_linear_ordering_ty() -> Expr {
586    arrow(cst("LinearOrder"), prop())
587}
588/// HausdorffScatteredCharacterization: L is scattered iff it embeds no η-type ordering.
589/// Equivalent to ATR₀ over RCA₀.
590pub fn hausdorff_scattered_ty() -> Expr {
591    impl_pi(
592        "L",
593        cst("LinearOrder"),
594        arrow(
595            app(cst("ScatteredLinearOrdering"), bvar(0)),
596            app(cst("EmbedsFreeOfEta"), bvar(1)),
597        ),
598    )
599}
600/// ThinSetTheorem: for every f : [ℕ]² → k, there is an infinite set S
601/// such that f omits at least one color on [S]².
602/// Strength: strictly between SRT²_2 and RT²_2.
603pub fn thin_set_theorem_ty() -> Expr {
604    arrow(
605        nat_ty(),
606        impl_pi(
607            "f",
608            arrow(app(cst("Pairs"), nat_ty()), bvar(1)),
609            app(cst("HasThinInfiniteSet"), bvar(0)),
610        ),
611    )
612}
613/// FreeSetTheorem: for every f : [ℕ]² → ℕ, there is an infinite set S
614/// such that f(x,y) ∉ S for all x,y ∈ S with x ≠ y.
615/// Equivalent to RT²_2 over RCA₀ (Cholak–Giusto–Hirst–Jockusch).
616pub fn free_set_theorem_ty() -> Expr {
617    impl_pi(
618        "f",
619        arrow(app(cst("Pairs"), nat_ty()), nat_ty()),
620        app(cst("HasFreeInfiniteSet"), bvar(0)),
621    )
622}
623/// CohesivenessTheorem: for every sequence of sets (X_i), there is an infinite
624/// set S almost contained in each X_i or its complement.
625/// COH: strictly between RCA₀ and RT²_2 (Jockusch–Lempp–Slaman).
626pub fn cohesiveness_theorem_ty() -> Expr {
627    impl_pi(
628        "seq",
629        arrow(nat_ty(), app(cst("Set"), nat_ty())),
630        app(cst("HasCohesiveSet"), bvar(0)),
631    )
632}
633/// OmittingTypesTheorem: every consistent theory omits a non-principal type
634/// unless it has a prime model.
635/// Equivalent to ACA₀ over RCA₀ (Hirschfeldt–Shore).
636pub fn omitting_types_theorem_ty() -> Expr {
637    impl_pi(
638        "T",
639        cst("ConsistentTheory"),
640        arrow(
641            app(cst("HasNonPrincipalType"), bvar(0)),
642            app(cst("HasOmittingModel"), bvar(1)),
643        ),
644    )
645}
646/// LowBasisTheorem: every infinite binary tree has an infinite branch of low degree.
647/// Provable in RCA₀ (Jockusch–Soare 1972).
648pub fn low_basis_theorem_ty() -> Expr {
649    impl_pi(
650        "T",
651        cst("InfiniteBinaryTree"),
652        app(cst("HasLowBranch"), bvar(0)),
653    )
654}
655/// DecidabilityOfRCA0: it is decidable whether a given sentence is provable in RCA₀.
656/// This is a meta-level Π⁰_1 statement.
657pub fn decidability_rca0_ty() -> Expr {
658    app(cst("IsDecidable"), cst("RCA0Provability"))
659}
660/// Sigma0nFormula: a Σ⁰_n formula (bounded quantifier alternations, n many).
661/// Sigma0nFormula : Nat → Type
662pub fn sigma0n_formula_ty() -> Expr {
663    arrow(nat_ty(), type0())
664}
665/// Pi0nFormula: a Π⁰_n formula.
666pub fn pi0n_formula_ty() -> Expr {
667    arrow(nat_ty(), type0())
668}
669/// Delta11Formula: both Σ¹_1 and Π¹_1 (hyperarithmetical).
670pub fn delta11_formula_ty() -> Expr {
671    prop()
672}
673/// Sigma0nInduction: Σ⁰_n-induction axiom scheme.
674/// Sigma0nInduction : Nat → Prop
675pub fn sigma0n_induction_ty() -> Expr {
676    arrow(nat_ty(), prop())
677}
678/// Sigma01Comprehension: RCA₀'s comprehension scheme — sets exist for Σ⁰_1 formulas.
679/// This is the comprehension half of RCA₀.
680pub fn sigma01_comprehension_ty() -> Expr {
681    arrow(sigma01_formula_ty(), prop())
682}
683/// Delta01Comprehension: sets exist for Δ⁰_1 (recursive) predicates.
684/// Also called primitive recursive comprehension.
685pub fn delta01_comprehension_ty() -> Expr {
686    arrow(delta01_formula_ty(), prop())
687}
688/// Register all reverse-mathematics axioms into a fresh kernel environment.
689pub fn build_reverse_mathematics_env() -> Environment {
690    let mut env = Environment::new();
691    let axioms: &[(&str, Expr)] = &[
692        ("SecondOrderArithmetic", second_order_arithmetic_ty()),
693        ("ArithmeticalFormula", arithmetical_formula_ty()),
694        ("Sigma01Formula", sigma01_formula_ty()),
695        ("Pi01Formula", pi01_formula_ty()),
696        ("Delta01Formula", delta01_formula_ty()),
697        ("Sigma11Formula", sigma11_formula_ty()),
698        ("Pi11Formula", pi11_formula_ty()),
699        ("RCA0", rca0_ty()),
700        ("Provable_RCA0", provable_rca0_ty()),
701        ("WKL0", wkl0_ty()),
702        ("WeakKonigsLemma", weak_konigs_lemma_ty()),
703        ("ACA0", aca0_ty()),
704        ("ArithmeticalComprehension", arithmetical_comprehension_ty()),
705        ("ATR0", atr0_ty()),
706        (
707            "ArithmeticalTransfiniteRecursion",
708            arithmetical_transfinite_recursion_ty(),
709        ),
710        ("Pi11CA0", pi11_ca0_ty()),
711        ("Pi11Comprehension", pi11_comprehension_ty()),
712        ("Conservative", conservative_ty()),
713        ("WKL0ConservativeOverRCA0", wkl0_conservative_over_rca0_ty()),
714        ("ACA0ConservativeOverPA", aca0_conservative_over_pa_ty()),
715        ("ATR0ConservativeResult", atr0_conservative_ty()),
716        ("OmegaModelWKL0", omega_model_wkl0_ty()),
717        ("SubsystemLinearOrder", subsystem_linear_order_ty()),
718        ("BolzanoWeierstrass", bolzano_weierstrass_ty()),
719        ("HahnBanachTheorem", hahn_banach_ty()),
720        ("BrouwerFixedPoint", brouwer_fixed_point_ty()),
721        ("MaximalIdealTheorem", maximal_ideal_theorem_ty()),
722        ("CompletenessTheorem", completeness_theorem_ty()),
723        ("KonigLemma", konig_lemma_ty()),
724        ("Ramsey", ramsey_ty()),
725        ("RT22", rt22_ty()),
726        ("RT21", rt21_ty()),
727        ("SRT22", srt22_ty()),
728        ("CAC", cac_ty()),
729        ("ADS", ads_ty()),
730        ("SADS", sads_ty()),
731        ("DNR", dnr_ty()),
732        ("FSSets", fssets_ty()),
733        ("HindmanTheorem", hindman_theorem_ty()),
734        ("IdempotentUltrafilter", idempotent_ultrafilter_ty()),
735        ("HindmanFromIdempotent", hindman_from_idempotent_ty()),
736        ("HindmanStrength", hindman_strength_ty()),
737        ("ComputableFunction", computable_function_ty()),
738        ("TuringDegree", turing_degree_ty()),
739        ("TuringReducible", turing_reducible_ty()),
740        ("ComputablelyEnumerable", computably_enumerable_ty()),
741        ("HaltingProblem", halting_problem_ty()),
742        ("HaltingProblemIsCE", halting_problem_is_ce_ty()),
743        (
744            "HaltingProblemNotComputable",
745            halting_problem_not_computable_ty(),
746        ),
747        ("PostTheorem", post_theorem_ty()),
748        ("RecursiveSeparation", recursive_separation_ty()),
749        ("OracleComputable", oracle_computable_ty()),
750        ("InfiniteBinaryTree", infinite_binary_tree_ty()),
751        ("KonigsLemmaForBinaryTrees", konigs_lemma_binary_ty()),
752        ("HasInfiniteBranch", has_infinite_branch_ty()),
753        ("BinaryTreePath", binary_tree_path_ty()),
754        ("WKL0EquivalentToKonigsLemma", wkl0_equiv_konig_ty()),
755        ("HyperArithmetical", hyperarithmetical_ty()),
756        (
757            "HyperArithmeticalHierarchy",
758            hyperarithmetical_hierarchy_ty(),
759        ),
760        ("Pi11CA0SetExistence", pi11_ca0_set_existence_ty()),
761        ("BarInduction", bar_induction_ty()),
762        ("OpenDeterminacy", open_determinacy_ty()),
763        ("BorelDeterminacy", borel_determinacy_ty()),
764        ("ProjectiveDeterminacy", projective_determinacy_ty()),
765        ("Sigma11Determinacy", sigma11_determinacy_ty()),
766        ("WellOrderingTheorem", well_ordering_theorem_ty()),
767        (
768            "ComparisonOfWellOrderings",
769            comparison_of_well_orderings_ty(),
770        ),
771        ("WellOrderingIsLinear", well_ordering_is_linear_ty()),
772        (
773            "InfiniteLinearOrderHasOmegaOrOmegaStar",
774            linear_order_omega_ty(),
775        ),
776        ("ScatteredLinearOrdering", scattered_linear_ordering_ty()),
777        ("HausdorffScattered", hausdorff_scattered_ty()),
778        ("ThinSetTheorem", thin_set_theorem_ty()),
779        ("FreeSetTheorem", free_set_theorem_ty()),
780        ("CohesivenessTheorem", cohesiveness_theorem_ty()),
781        ("OmittingTypesTheorem", omitting_types_theorem_ty()),
782        ("LowBasisTheorem", low_basis_theorem_ty()),
783        ("DecidabilityOfRCA0", decidability_rca0_ty()),
784        ("Sigma0nFormula", sigma0n_formula_ty()),
785        ("Pi0nFormula", pi0n_formula_ty()),
786        ("Delta11Formula", delta11_formula_ty()),
787        ("Sigma0nInduction", sigma0n_induction_ty()),
788        ("Sigma01Comprehension", sigma01_comprehension_ty()),
789        ("Delta01Comprehension", delta01_comprehension_ty()),
790        ("System", type0()),
791        ("FormulaClass", type0()),
792        ("WellOrdering", type0()),
793        ("BinaryTree", type0()),
794        ("FinBranchingTree", type0()),
795        ("PartialOrder", type0()),
796        ("LinearOrder", type0()),
797        ("OmegaModel", arrow(type0(), type0())),
798        ("IsInfinite", arrow(type0(), prop())),
799        ("IsInfiniteTree", arrow(cst("BinaryTree"), prop())),
800        ("HasInfinitePath", arrow(cst("BinaryTree"), prop())),
801        ("IsInfinitePoset", arrow(cst("PartialOrder"), prop())),
802        ("IsInfiniteOrder", arrow(cst("LinearOrder"), prop())),
803        ("IsStableOrder", arrow(cst("LinearOrder"), prop())),
804        (
805            "ChainOrAntichain",
806            arrow(cst("PartialOrder"), arrow(type0(), prop())),
807        ),
808        (
809            "AscOrDescSeq",
810            arrow(cst("LinearOrder"), arrow(type0(), prop())),
811        ),
812        ("DiagonallyNonRecursive", type0()),
813        ("PeanoArithmetic", type0()),
814        ("FirstOrderFormulas", type0()),
815        ("Pi11FormulasClass", type0()),
816        ("Pi12FormulasClass", type0()),
817        ("ACA0Plus", type0()),
818        ("ProvableIn", arrow(type0(), arrow(type0(), prop()))),
819        ("Real", type0()),
820        ("BoundedSequence", arrow(type0(), type0())),
821        ("HasConvergentSubsequence", arrow(type0(), prop())),
822        ("NormedSpace", type0()),
823        ("LinearFunctional", type0()),
824        ("Disk", type0()),
825        ("CommRing", type0()),
826        ("CountableLanguage", type0()),
827        ("Continuous", arrow(arrow(cst("Disk"), cst("Disk")), prop())),
828        (
829            "HasFixedPoint",
830            arrow(arrow(cst("Disk"), cst("Disk")), prop()),
831        ),
832        ("HasMaximalIdeal", arrow(cst("CommRing"), prop())),
833        ("Consistent", arrow(cst("CountableLanguage"), prop())),
834        ("HasModel", arrow(cst("CountableLanguage"), prop())),
835        ("Set", arrow(type0(), type0())),
836        ("Not", arrow(prop(), prop())),
837        ("Computable", arrow(app(cst("Set"), nat_ty()), prop())),
838        ("Sigma01Definable", arrow(app(cst("Set"), nat_ty()), prop())),
839        ("Disjoint", arrow(app(cst("Set"), nat_ty()), prop())),
840        (
841            "HasComputableSeparation",
842            arrow(
843                app(cst("Set"), nat_ty()),
844                arrow(app(cst("Set"), nat_ty()), prop()),
845            ),
846        ),
847        ("RecursiveOrdinal", type0()),
848        ("WellFoundedTree", type0()),
849        ("OpenGame", type0()),
850        ("BorelGame", type0()),
851        ("ProjectiveGame", type0()),
852        ("Sigma11Game", type0()),
853        ("IsDetermined", arrow(type0(), prop())),
854        ("CanBeWellOrdered", arrow(type0(), prop())),
855        (
856            "ComparableOrders",
857            arrow(cst("WellOrdering"), arrow(cst("WellOrdering"), prop())),
858        ),
859        ("IsLinearOrder", arrow(cst("WellOrdering"), prop())),
860        (
861            "ContainsOmegaOrOmegaStar",
862            arrow(cst("LinearOrder"), arrow(type0(), prop())),
863        ),
864        ("EmbedsFreeOfEta", arrow(cst("LinearOrder"), prop())),
865        ("Pairs", arrow(type0(), type0())),
866        (
867            "HasThinInfiniteSet",
868            arrow(arrow(app(cst("Pairs"), nat_ty()), nat_ty()), prop()),
869        ),
870        (
871            "HasFreeInfiniteSet",
872            arrow(arrow(app(cst("Pairs"), nat_ty()), nat_ty()), prop()),
873        ),
874        (
875            "HasCohesiveSet",
876            arrow(arrow(nat_ty(), app(cst("Set"), nat_ty())), prop()),
877        ),
878        ("ConsistentTheory", type0()),
879        (
880            "HasNonPrincipalType",
881            arrow(cst("ConsistentTheory"), prop()),
882        ),
883        ("HasOmittingModel", arrow(cst("ConsistentTheory"), prop())),
884        ("HasLowBranch", arrow(cst("InfiniteBinaryTree"), prop())),
885        ("IsDecidable", arrow(prop(), prop())),
886        ("RCA0Provability", prop()),
887        ("Exists", arrow(type0(), prop())),
888        ("SetOf", arrow(type0(), type0())),
889        ("Iff", arrow(prop(), arrow(prop(), prop()))),
890    ];
891    for (name, ty) in axioms {
892        let _ = env.add(Declaration::Axiom {
893            name: Name::str(*name),
894            univ_params: vec![],
895            ty: ty.clone(),
896        });
897    }
898    env
899}
900#[cfg(test)]
901mod tests {
902    use super::*;
903    #[test]
904    fn test_build_reverse_mathematics_env() {
905        let env = build_reverse_mathematics_env();
906        assert!(env.get(&Name::str("RCA0")).is_some());
907        assert!(env.get(&Name::str("WKL0")).is_some());
908        assert!(env.get(&Name::str("ACA0")).is_some());
909        assert!(env.get(&Name::str("ATR0")).is_some());
910        assert!(env.get(&Name::str("Pi11CA0")).is_some());
911        assert!(env.get(&Name::str("WKL0ConservativeOverRCA0")).is_some());
912        assert!(env.get(&Name::str("RT22")).is_some());
913        assert!(env.get(&Name::str("HindmanTheorem")).is_some());
914        assert!(env.get(&Name::str("IdempotentUltrafilter")).is_some());
915    }
916    #[test]
917    fn test_big_five_ordering() {
918        assert!(BigFiveSystem::RCA0 < BigFiveSystem::WKL0);
919        assert!(BigFiveSystem::WKL0 < BigFiveSystem::ACA0);
920        assert!(BigFiveSystem::ACA0 < BigFiveSystem::ATR0);
921        assert!(BigFiveSystem::ATR0 < BigFiveSystem::Pi11CA0);
922        assert!(BigFiveSystem::Pi11CA0.at_least_as_strong_as(&BigFiveSystem::RCA0));
923    }
924    #[test]
925    fn test_big_five_names() {
926        assert_eq!(BigFiveSystem::RCA0.name(), "RCA₀");
927        assert_eq!(BigFiveSystem::WKL0.name(), "WKL₀");
928        assert_eq!(BigFiveSystem::ACA0.name(), "ACA₀");
929        assert_eq!(BigFiveSystem::ATR0.name(), "ATR₀");
930        assert_eq!(BigFiveSystem::Pi11CA0.name(), "Π¹₁-CA₀");
931    }
932    #[test]
933    fn test_proof_theoretic_ordinals() {
934        assert_eq!(BigFiveSystem::ACA0.proof_theoretic_ordinal(), "ε₀");
935        assert_eq!(BigFiveSystem::ATR0.proof_theoretic_ordinal(), "Γ₀");
936    }
937    #[test]
938    fn test_conservation_results() {
939        let c = ConservationResult::wkl0_over_rca0();
940        assert!(c.is_valid_direction());
941        assert_eq!(c.stronger, BigFiveSystem::WKL0);
942        assert_eq!(c.weaker, BigFiveSystem::RCA0);
943        let c2 = ConservationResult::atr0_over_aca0();
944        assert!(c2.is_valid_direction());
945    }
946    #[test]
947    fn test_rm_principles() {
948        let rt22 = RMPrinciple::rt22();
949        assert_eq!(rt22.strength, RMStrength::BetweenWKL0AndACA0);
950        assert!(!rt22.equivalent_to(&BigFiveSystem::ACA0));
951        let bw = RMPrinciple::bolzano_weierstrass();
952        assert!(bw.equivalent_to(&BigFiveSystem::ACA0));
953        let brouwer = RMPrinciple::brouwer();
954        assert!(brouwer.equivalent_to(&BigFiveSystem::WKL0));
955    }
956    #[test]
957    fn test_ramsey_number_lower_bound() {
958        assert_eq!(ramsey_number_lower_bound(2, 5), 5);
959        assert_eq!(ramsey_number_lower_bound(3, 3), 6);
960        assert_eq!(ramsey_number_lower_bound(3, 4), 9);
961        assert_eq!(ramsey_number_lower_bound(4, 4), 18);
962        assert_eq!(
963            ramsey_number_lower_bound(3, 5),
964            ramsey_number_lower_bound(5, 3)
965        );
966    }
967    #[test]
968    fn test_greedy_homogeneous_set() {
969        let n = 4;
970        let coloring = vec![
971            vec![0, 0, 0, 0],
972            vec![0, 0, 0, 0],
973            vec![0, 0, 0, 0],
974            vec![0, 0, 0, 0],
975        ];
976        let (color, set) = greedy_homogeneous_set(n, &coloring);
977        assert_eq!(color, 0);
978        assert_eq!(set.len(), 4);
979    }
980    #[test]
981    fn test_new_axioms_in_env() {
982        let env = build_reverse_mathematics_env();
983        assert!(env.get(&Name::str("ComputableFunction")).is_some());
984        assert!(env.get(&Name::str("TuringDegree")).is_some());
985        assert!(env.get(&Name::str("TuringReducible")).is_some());
986        assert!(env.get(&Name::str("ComputablelyEnumerable")).is_some());
987        assert!(env.get(&Name::str("HaltingProblem")).is_some());
988        assert!(env.get(&Name::str("HaltingProblemIsCE")).is_some());
989        assert!(env.get(&Name::str("HaltingProblemNotComputable")).is_some());
990        assert!(env.get(&Name::str("PostTheorem")).is_some());
991        assert!(env.get(&Name::str("OracleComputable")).is_some());
992        assert!(env.get(&Name::str("InfiniteBinaryTree")).is_some());
993        assert!(env.get(&Name::str("KonigsLemmaForBinaryTrees")).is_some());
994        assert!(env.get(&Name::str("HasInfiniteBranch")).is_some());
995        assert!(env.get(&Name::str("WKL0EquivalentToKonigsLemma")).is_some());
996        assert!(env.get(&Name::str("HyperArithmetical")).is_some());
997        assert!(env.get(&Name::str("BarInduction")).is_some());
998        assert!(env.get(&Name::str("OpenDeterminacy")).is_some());
999        assert!(env.get(&Name::str("BorelDeterminacy")).is_some());
1000        assert!(env.get(&Name::str("ProjectiveDeterminacy")).is_some());
1001        assert!(env.get(&Name::str("Sigma11Determinacy")).is_some());
1002        assert!(env.get(&Name::str("WellOrderingTheorem")).is_some());
1003        assert!(env.get(&Name::str("ComparisonOfWellOrderings")).is_some());
1004        assert!(env
1005            .get(&Name::str("InfiniteLinearOrderHasOmegaOrOmegaStar"))
1006            .is_some());
1007        assert!(env.get(&Name::str("HausdorffScattered")).is_some());
1008        assert!(env.get(&Name::str("ThinSetTheorem")).is_some());
1009        assert!(env.get(&Name::str("FreeSetTheorem")).is_some());
1010        assert!(env.get(&Name::str("CohesivenessTheorem")).is_some());
1011        assert!(env.get(&Name::str("OmittingTypesTheorem")).is_some());
1012        assert!(env.get(&Name::str("LowBasisTheorem")).is_some());
1013        assert!(env.get(&Name::str("Sigma0nFormula")).is_some());
1014        assert!(env.get(&Name::str("Delta11Formula")).is_some());
1015        assert!(env.get(&Name::str("Sigma0nInduction")).is_some());
1016        assert!(env.get(&Name::str("Delta01Comprehension")).is_some());
1017    }
1018    #[test]
1019    fn test_computable_function() {
1020        let f = ComputableFunction::indicator_below(5);
1021        assert_eq!(f.eval(0), Some(1));
1022        assert_eq!(f.eval(4), Some(1));
1023        assert_eq!(f.eval(5), Some(0));
1024        assert!(f.is_total_up_to(8));
1025        assert_eq!(f.oracle_query(3, 100), Some(1));
1026    }
1027    #[test]
1028    fn test_weak_konig_tree_complete() {
1029        let t = WeakKonigTree::complete(3);
1030        assert!(t.is_infinite());
1031        assert_eq!(t.count_at_depth(3), 8);
1032        let path = t.greedy_path();
1033        assert_eq!(path.len(), 3);
1034        assert_eq!(path, vec![0u8, 0u8, 0u8]);
1035    }
1036    #[test]
1037    fn test_weak_konig_tree_with_only_one_branch() {
1038        let mut t = WeakKonigTree {
1039            max_depth: 3,
1040            nodes: vec![],
1041            depths: vec![],
1042        };
1043        t.nodes.push(0);
1044        t.depths.push(0);
1045        t.nodes.push(1);
1046        t.depths.push(1);
1047        t.nodes.push(3);
1048        t.depths.push(2);
1049        t.nodes.push(7);
1050        t.depths.push(3);
1051        assert!(t.is_infinite());
1052        let path = t.greedy_path();
1053        assert_eq!(path, vec![1u8, 1u8, 1u8]);
1054    }
1055    #[test]
1056    fn test_ramsey_coloring_finder_uniform() {
1057        let mut finder = RamseyColoringFinder::new_uniform(5, 2);
1058        let (c, clique) = finder.best_monochromatic_clique();
1059        assert_eq!(c, 0);
1060        assert_eq!(clique.len(), 5);
1061        finder.set_color(0, 1, 1);
1062        finder.set_color(0, 2, 1);
1063        finder.set_color(1, 2, 1);
1064        let (c2, clique2) = finder.best_monochromatic_clique();
1065        assert!(clique2.len() >= 2);
1066        assert!(c2 < 2);
1067    }
1068    #[test]
1069    fn test_rma0_system() {
1070        let inst = RMA0System::sigma01_comprehension_for("phi_halting");
1071        assert!(inst.verify());
1072        assert_eq!(inst.kind, RCA0AxiomKind::Sigma01Comprehension);
1073        let summary = inst.summary();
1074        assert!(summary.contains("VALID"));
1075        assert!(summary.contains("phi_halting"));
1076    }
1077    #[test]
1078    fn test_rm_hierarchy_display() {
1079        let h = RMHierarchy::standard();
1080        let out = h.display();
1081        assert!(out.contains("RCA₀"));
1082        assert!(out.contains("WKL₀"));
1083        assert!(out.contains("ACA₀"));
1084        assert!(out.contains("ATR₀"));
1085        assert!(out.contains("Π¹₁-CA₀"));
1086        assert!(out.contains("König"));
1087        assert!(out.contains("Bolzano"));
1088    }
1089    #[test]
1090    fn test_rm_hierarchy_entry_lookup() {
1091        let h = RMHierarchy::standard();
1092        let entry = h
1093            .entry_for(&BigFiveSystem::ATR0)
1094            .expect("entry_for should succeed");
1095        assert_eq!(entry.system, BigFiveSystem::ATR0);
1096        assert!(entry.equivalents.contains(&"Open determinacy"));
1097    }
1098}
1099/// Standard library of RM theorems from classical analysis.
1100#[allow(dead_code)]
1101pub fn standard_rm_theorems() -> Vec<RMTheorem> {
1102    vec![
1103        RMTheorem::new(
1104            "BolzanoWeierstrass",
1105            "Every bounded sequence in ℝ has a convergent subsequence.",
1106            "ACA₀",
1107            vec![
1108                "Sequential compactness of [0,1]",
1109                "Monotone convergence theorem",
1110            ],
1111            false,
1112        ),
1113        RMTheorem::new(
1114            "HeineCantorUniformContinuity",
1115            "Every continuous function on a closed bounded interval is uniformly continuous.",
1116            "WKL₀",
1117            vec!["Heine-Borel theorem", "Fan theorem"],
1118            false,
1119        ),
1120        RMTheorem::new(
1121            "IntermediateValueTheorem",
1122            "If f: [0,1] → ℝ is continuous and f(0) < 0 < f(1), then ∃x, f(x) = 0.",
1123            "WKL₀",
1124            vec!["Brouwer's fixed point theorem (1D)"],
1125            false,
1126        ),
1127        RMTheorem::new(
1128            "MaximumMinimumTheorem",
1129            "Every continuous real function on [0,1] attains its maximum and minimum.",
1130            "WKL₀",
1131            vec!["Compact implies sequentially compact (metric)"],
1132            false,
1133        ),
1134        RMTheorem::new(
1135            "MonotoneConvergence",
1136            "Every bounded monotone sequence of reals converges.",
1137            "ACA₀",
1138            vec!["Bolzano-Weierstrass", "Sequential compactness"],
1139            false,
1140        ),
1141        RMTheorem::new(
1142            "CauchyCharacterization",
1143            "A sequence is convergent iff it is a Cauchy sequence.",
1144            "ACA₀",
1145            vec!["Completeness of ℝ"],
1146            false,
1147        ),
1148        RMTheorem::new(
1149            "KonigLemma",
1150            "Every infinite, finitely-branching tree has an infinite path.",
1151            "WKL₀",
1152            vec!["Heine-Borel theorem", "Weak König's Lemma"],
1153            false,
1154        ),
1155        RMTheorem::new(
1156            "RamseyFinite",
1157            "For all k, m, every k-coloring of [N]^2 has a monochromatic set of size m.",
1158            "RCA₀",
1159            Vec::<&str>::new(),
1160            true,
1161        ),
1162        RMTheorem::new(
1163            "RamseyInfinite",
1164            "For all k, every k-coloring of [N]^2 has an infinite monochromatic set.",
1165            "ACA₀",
1166            vec!["Ascending/Descending Sequence principle"],
1167            false,
1168        ),
1169        RMTheorem::new(
1170            "HilbertBasisTheorem",
1171            "Every ideal in a polynomial ring over a field is finitely generated.",
1172            "ATR₀",
1173            vec!["Open determinacy", "Comparability of well-orderings"],
1174            false,
1175        ),
1176        RMTheorem::new(
1177            "SilverTheorem",
1178            "Every Borel graph on a Polish space satisfies the Galvin-Prikry property.",
1179            "Π¹₁-CA₀",
1180            vec!["Analytic determinacy (weaker form)"],
1181            false,
1182        ),
1183        RMTheorem::new(
1184            "LindelofTheorem",
1185            "Every open cover of a separable metric space has a countable subcover.",
1186            "RCA₀",
1187            Vec::<&str>::new(),
1188            true,
1189        ),
1190    ]
1191}
1192/// Known Π¹₁ sentences and their proof-theoretic strengths.
1193#[allow(dead_code)]
1194pub fn known_pi11_sentences() -> Vec<Pi11Sentence> {
1195    vec![
1196        Pi11Sentence::new("Con(PA)", "Consistency of Peano Arithmetic", Some("ε₀")),
1197        Pi11Sentence::new("WO(ε₀)", "ε₀ is a well-ordering", Some("ε₀")),
1198        Pi11Sentence::new("Con(ATR₀)", "Consistency of ATR₀", Some("Γ₀")),
1199        Pi11Sentence::new("GoodmanTheorem", "The Goodman theorem for HA", Some("ε₀")),
1200        Pi11Sentence::new("Con(Z₂)", "Consistency of Z₂", Some("φ_ω(0)")),
1201        Pi11Sentence::new(
1202            "ParisHarrington",
1203            "The Paris-Harrington principle",
1204            Some("ε₀"),
1205        ),
1206        Pi11Sentence::new(
1207            "GoodsteinSeq",
1208            "Every Goodstein sequence terminates",
1209            Some("ε₀"),
1210        ),
1211        Pi11Sentence::new("KirbyParis", "Kirby-Paris Hydra theorem", Some("ε₀")),
1212    ]
1213}
1214/// Checks whether `system_a` is (weakly) contained in `system_b` by subsystem strength.
1215#[allow(dead_code)]
1216pub fn subsystem_le(system_a: &str, system_b: &str) -> bool {
1217    let order = ["RCA₀", "WKL₀", "ACA₀", "ATR₀", "Π¹₁-CA₀"];
1218    let pos_a = order.iter().position(|&s| s == system_a);
1219    let pos_b = order.iter().position(|&s| s == system_b);
1220    match (pos_a, pos_b) {
1221        (Some(a), Some(b)) => a <= b,
1222        _ => false,
1223    }
1224}
1225/// Known standard ω-models.
1226#[allow(dead_code)]
1227pub fn standard_omega_models() -> Vec<OmegaModel> {
1228    vec![
1229        OmegaModel::rec_sets(),
1230        OmegaModel::standard_aca0(),
1231        OmegaModel::new("HYP", "ATR₀", false, "Hyperarithmetical sets: Δ¹₁ sets"),
1232        OmegaModel::new("∆¹₂", "Π¹₁-CA₀", false, "Second-order definable sets: ∆¹₂"),
1233        OmegaModel::new(
1234            "L_ω₁ᶜᵏ",
1235            "Π¹₁-CA₀",
1236            false,
1237            "Gödel's L up to the Church-Kleene ordinal",
1238        ),
1239    ]
1240}
1241#[cfg(test)]
1242mod rm_extended_tests {
1243    use super::*;
1244    #[test]
1245    fn test_proof_system_name() {
1246        assert_eq!(ProofSystem::PRA.name(), "PRA");
1247        assert_eq!(ProofSystem::Z2.name(), "Z₂");
1248        assert_eq!(ProofSystem::Custom("ZFC".into()).name(), "ZFC");
1249    }
1250    #[test]
1251    fn test_is_conservative_over() {
1252        assert!(ProofSystem::Z2.is_conservative_over(&ProofSystem::PeanoPA));
1253        assert!(ProofSystem::PeanoPA.is_conservative_over(&ProofSystem::RobinsonQ));
1254        assert!(!ProofSystem::PRA.is_conservative_over(&ProofSystem::Z2));
1255    }
1256    #[test]
1257    fn test_stronger_systems() {
1258        let s = ProofSystem::PRA.stronger_systems();
1259        assert_eq!(s.len(), 5);
1260        assert!(s.contains(&ProofSystem::Z2));
1261    }
1262    #[test]
1263    fn test_rm_theorem_summary() {
1264        let thm = RMTheorem::new("Test", "Some theorem", "ACA₀", vec!["Equiv1"], false);
1265        let s = thm.summary();
1266        assert!(s.contains("Test"));
1267        assert!(s.contains("ACA₀"));
1268        assert!(s.contains("Equiv1"));
1269    }
1270    #[test]
1271    fn test_standard_rm_theorems() {
1272        let thms = standard_rm_theorems();
1273        assert!(!thms.is_empty());
1274        assert!(thms.iter().any(|t| t.name == "BolzanoWeierstrass"));
1275        assert!(thms.iter().any(|t| t.name == "KonigLemma"));
1276    }
1277    #[test]
1278    fn test_subsystem_le() {
1279        assert!(subsystem_le("RCA₀", "ACA₀"));
1280        assert!(subsystem_le("ACA₀", "ACA₀"));
1281        assert!(!subsystem_le("ACA₀", "WKL₀"));
1282        assert!(subsystem_le("WKL₀", "Π¹₁-CA₀"));
1283    }
1284    #[test]
1285    fn test_pi11_sentences() {
1286        let sents = known_pi11_sentences();
1287        assert!(!sents.is_empty());
1288        assert!(sents.iter().any(|s| s.name == "Con(PA)"));
1289        let disp = sents[0].display();
1290        assert!(disp.contains("Con(PA)"));
1291    }
1292    #[test]
1293    fn test_omega_models() {
1294        let rec = OmegaModel::rec_sets();
1295        assert!(rec.is_minimal);
1296        assert_eq!(rec.satisfies, "RCA₀");
1297        let models = standard_omega_models();
1298        assert_eq!(models.len(), 5);
1299        assert!(models.iter().any(|m| m.name == "REC"));
1300    }
1301    #[test]
1302    fn test_rm_scoreboard() {
1303        let sb = RMScoreboard::standard();
1304        assert!(!sb.theorems.is_empty());
1305        let aca0_count = sb.count_in("ACA₀");
1306        assert!(aca0_count > 0);
1307    }
1308}
1309/// Library of constructive principles.
1310#[allow(dead_code)]
1311pub fn constructive_principles() -> Vec<ConstructivePrinciple> {
1312    vec![
1313        ConstructivePrinciple::new("MarkovPrinciple", "LLPO", false, Some("Markov's principle")),
1314        ConstructivePrinciple::new("LLPO", "Law of Excluded Middle", false, Some("LPO")),
1315        ConstructivePrinciple::new("LPO", "Law of Excluded Middle", false, Some("LEM")),
1316        ConstructivePrinciple::new("WLPO", "Weak LPO", false, Some("LPO")),
1317        ConstructivePrinciple::new("BishopFan", "Fan Theorem", true, None::<&str>),
1318        ConstructivePrinciple::new(
1319            "ChoiceSequences",
1320            "Axiom of Choice (Countable)",
1321            false,
1322            Some("Countable choice"),
1323        ),
1324        ConstructivePrinciple::new("DependentChoice", "Dependent Choice", false, Some("DC")),
1325        ConstructivePrinciple::new(
1326            "UniformContinuity",
1327            "Uniform Continuity on Cantor Space",
1328            true,
1329            None::<&str>,
1330        ),
1331        ConstructivePrinciple::new(
1332            "ContBar",
1333            "Continuous Functions on Baire Space",
1334            false,
1335            Some("Bar Induction"),
1336        ),
1337    ]
1338}
1339/// Standard independence results.
1340#[allow(dead_code)]
1341pub fn standard_independence_results() -> Vec<IndependenceResult> {
1342    vec![
1343        IndependenceResult::new("ContinuumHypothesis", "ZFC", true, "Cohen 1963"),
1344        IndependenceResult::new("GeneralizedContinuumHypothesis", "ZFC", true, "Cohen 1963"),
1345        IndependenceResult::new("AxiomOfChoice", "ZF", true, "Cohen 1963"),
1346        IndependenceResult::new("SuslinHypothesis", "ZFC", true, "Solovay-Tennenbaum 1971"),
1347        IndependenceResult::new("BorelConjecture", "ZFC", true, "Laver 1976"),
1348        IndependenceResult::new("MartinAxiom", "ZFC", true, "Independent from ZFC+¬CH"),
1349        IndependenceResult::new("WhiteheadProblem", "ZFC", true, "Shelah 1974"),
1350        IndependenceResult::new("KaplanProblem", "ZFC", true, "Independent from ZFC"),
1351        IndependenceResult::new("ProperForcingAxiom", "ZFC", true, "Baumgartner 1984"),
1352        IndependenceResult::new("VopenkaPrinciple", "ZFC", true, "Requires a large cardinal"),
1353        IndependenceResult::new("Goodstein", "PA", true, "Kirby-Paris 1982"),
1354        IndependenceResult::new("ParisHarrington", "PA", true, "Paris-Harrington 1977"),
1355        IndependenceResult::new("Consistency(PA)", "PA", true, "Gödel 1931"),
1356    ]
1357}
1358#[cfg(test)]
1359mod rm_extended2_tests {
1360    use super::*;
1361    #[test]
1362    fn test_constructive_principles() {
1363        let ps = constructive_principles();
1364        assert!(!ps.is_empty());
1365        let mp = ps
1366            .iter()
1367            .find(|p| p.name == "MarkovPrinciple")
1368            .expect("find should succeed");
1369        assert!(!mp.constructively_provable);
1370        assert!(mp.required_axiom.is_some());
1371    }
1372    #[test]
1373    fn test_independence_results() {
1374        let irs = standard_independence_results();
1375        assert!(!irs.is_empty());
1376        let ch = irs
1377            .iter()
1378            .find(|r| r.statement == "ContinuumHypothesis")
1379            .expect("find should succeed");
1380        assert!(ch.is_independent);
1381        assert_eq!(ch.base_theory, "ZFC");
1382        let disp = ch.display();
1383        assert!(disp.contains("INDEPENDENT"));
1384    }
1385    #[test]
1386    fn test_big_five_stats() {
1387        let sb = RMScoreboard::standard();
1388        let stats = BigFiveStats::from_scoreboard(&sb);
1389        assert!(stats.total() > 0);
1390        let disp = stats.display();
1391        assert!(disp.contains("RCA₀"));
1392        assert!(disp.contains("ACA₀"));
1393    }
1394    #[test]
1395    fn test_constructive_principle_display() {
1396        let p = ConstructivePrinciple::new("TestPrinciple", "LEM", false, Some("MP"));
1397        let d = p.display();
1398        assert!(d.contains("TestPrinciple"));
1399        assert!(d.contains("constructive=false"));
1400    }
1401}