Skip to main content

oxilean_std/constructive_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::{ConstructiveReal, MarkovPrinciple, PowerSetHeyting};
8
9pub fn app(f: Expr, a: Expr) -> Expr {
10    Expr::App(Box::new(f), Box::new(a))
11}
12pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
13    app(app(f, a), b)
14}
15pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
16    app(app2(f, a, b), c)
17}
18pub fn cst(s: &str) -> Expr {
19    Expr::Const(Name::str(s), vec![])
20}
21pub fn prop() -> Expr {
22    Expr::Sort(Level::zero())
23}
24pub fn type0() -> Expr {
25    Expr::Sort(Level::succ(Level::zero()))
26}
27pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
28    Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
29}
30pub fn arrow(a: Expr, b: Expr) -> Expr {
31    pi(BinderInfo::Default, "_", a, b)
32}
33pub fn bvar(n: u32) -> Expr {
34    Expr::BVar(n)
35}
36pub fn nat_ty() -> Expr {
37    cst("Nat")
38}
39pub fn bool_ty() -> Expr {
40    cst("Bool")
41}
42pub fn real_ty() -> Expr {
43    cst("Real")
44}
45pub fn list_ty(elem: Expr) -> Expr {
46    app(cst("List"), elem)
47}
48pub fn option_ty(a: Expr) -> Expr {
49    app(cst("Option"), a)
50}
51pub fn pair_ty(a: Expr, b: Expr) -> Expr {
52    app2(cst("Prod"), a, b)
53}
54/// `IProp : Type` β€” intuitionistic proposition (proof-relevant).
55pub fn iprop_ty() -> Expr {
56    type0()
57}
58/// `IProof : IProp β†’ Type` β€” the type of proofs of an intuitionistic proposition.
59pub fn iproof_ty() -> Expr {
60    arrow(iprop_ty(), type0())
61}
62/// `BHK_And : IProp β†’ IProp β†’ IProp` β€” conjunction: proof is a pair.
63pub fn bhk_and_ty() -> Expr {
64    arrow(iprop_ty(), arrow(iprop_ty(), iprop_ty()))
65}
66/// `BHK_Or : IProp β†’ IProp β†’ IProp` β€” disjunction: proof is a tagged element.
67pub fn bhk_or_ty() -> Expr {
68    arrow(iprop_ty(), arrow(iprop_ty(), iprop_ty()))
69}
70/// `BHK_Impl : IProp β†’ IProp β†’ IProp` β€” implication: proof is a function.
71pub fn bhk_impl_ty() -> Expr {
72    arrow(iprop_ty(), arrow(iprop_ty(), iprop_ty()))
73}
74/// `BHK_Not : IProp β†’ IProp` β€” negation: proof is a function to βŠ₯.
75pub fn bhk_not_ty() -> Expr {
76    arrow(iprop_ty(), iprop_ty())
77}
78/// `BHK_Forall : (Nat β†’ IProp) β†’ IProp` β€” universal: proof is a function.
79pub fn bhk_forall_ty() -> Expr {
80    arrow(arrow(nat_ty(), iprop_ty()), iprop_ty())
81}
82/// `BHK_Exists : (Nat β†’ IProp) β†’ IProp` β€” existential: proof is a witness-proof pair.
83pub fn bhk_exists_ty() -> Expr {
84    arrow(arrow(nat_ty(), iprop_ty()), iprop_ty())
85}
86/// `IBot : IProp` β€” intuitionistic falsity (empty type).
87pub fn ibot_ty() -> Expr {
88    iprop_ty()
89}
90/// `ITop : IProp` β€” intuitionistic truth (unit type).
91pub fn itop_ty() -> Expr {
92    iprop_ty()
93}
94/// `HeytingAlgebra : Type` β€” a Heyting algebra (bounded lattice with implication).
95pub fn heyting_algebra_ty() -> Expr {
96    type0()
97}
98/// `HeytingMeet : HeytingAlgebra β†’ HeytingAlgebra β†’ HeytingAlgebra` β€” meet (∧).
99pub fn heyting_meet_ty() -> Expr {
100    arrow(
101        heyting_algebra_ty(),
102        arrow(heyting_algebra_ty(), heyting_algebra_ty()),
103    )
104}
105/// `HeytingJoin : HeytingAlgebra β†’ HeytingAlgebra β†’ HeytingAlgebra` β€” join (∨).
106pub fn heyting_join_ty() -> Expr {
107    arrow(
108        heyting_algebra_ty(),
109        arrow(heyting_algebra_ty(), heyting_algebra_ty()),
110    )
111}
112/// `HeytingImpl : HeytingAlgebra β†’ HeytingAlgebra β†’ HeytingAlgebra` β€” implication (β†’).
113pub fn heyting_impl_ty() -> Expr {
114    arrow(
115        heyting_algebra_ty(),
116        arrow(heyting_algebra_ty(), heyting_algebra_ty()),
117    )
118}
119/// `HeytingNeg : HeytingAlgebra β†’ HeytingAlgebra` β€” pseudo-complement Β¬a = a β†’ βŠ₯.
120pub fn heyting_neg_ty() -> Expr {
121    arrow(heyting_algebra_ty(), heyting_algebra_ty())
122}
123/// `HeytingBot : HeytingAlgebra` β€” bottom element βŠ₯.
124pub fn heyting_bot_ty() -> Expr {
125    heyting_algebra_ty()
126}
127/// `HeytingTop : HeytingAlgebra` β€” top element ⊀.
128pub fn heyting_top_ty() -> Expr {
129    heyting_algebra_ty()
130}
131/// `HeytingLe : HeytingAlgebra β†’ HeytingAlgebra β†’ Prop` β€” partial order.
132pub fn heyting_le_ty() -> Expr {
133    arrow(heyting_algebra_ty(), arrow(heyting_algebra_ty(), prop()))
134}
135/// `HeytingImplAdjunction : a ∧ b ≀ c ↔ a ≀ b β†’ c.`
136pub fn heyting_impl_adjunction_ty() -> Expr {
137    pi(
138        BinderInfo::Default,
139        "H",
140        heyting_algebra_ty(),
141        pi(
142            BinderInfo::Default,
143            "a",
144            heyting_algebra_ty(),
145            pi(
146                BinderInfo::Default,
147                "b",
148                heyting_algebra_ty(),
149                pi(
150                    BinderInfo::Default,
151                    "c",
152                    heyting_algebra_ty(),
153                    app2(
154                        cst("Iff"),
155                        app2(
156                            cst("HeytingLe"),
157                            app2(cst("HeytingMeet"), bvar(2), bvar(1)),
158                            bvar(0),
159                        ),
160                        app2(
161                            cst("HeytingLe"),
162                            bvar(2),
163                            app2(cst("HeytingImpl"), bvar(1), bvar(0)),
164                        ),
165                    ),
166                ),
167            ),
168        ),
169    )
170}
171/// `DoubleNegationLaw : ¬¬a ≀ a fails in general, but ¬¬¬a = Β¬a holds.`
172pub fn double_negation_law_ty() -> Expr {
173    pi(
174        BinderInfo::Default,
175        "a",
176        heyting_algebra_ty(),
177        app2(
178            cst("Eq"),
179            app(
180                cst("HeytingNeg"),
181                app(cst("HeytingNeg"), app(cst("HeytingNeg"), bvar(0))),
182            ),
183            app(cst("HeytingNeg"), bvar(0)),
184        ),
185    )
186}
187/// `BooleanAlgebra : Type` β€” Boolean algebra (Heyting algebra satisfying a ∨ Β¬a = ⊀).
188pub fn boolean_algebra_ty() -> Expr {
189    type0()
190}
191/// `ExcludedMiddleFails : Β¬ (βˆ€ a, a ∨ Β¬a = ⊀) in Heyting algebras.`
192pub fn excluded_middle_fails_ty() -> Expr {
193    prop()
194}
195/// `CauchySeq : (Nat β†’ Real) β†’ Prop` β€” a Cauchy sequence with explicit modulus.
196pub fn cauchy_seq_ty() -> Expr {
197    arrow(arrow(nat_ty(), real_ty()), prop())
198}
199/// `CauchyModulus : (Nat β†’ Real) β†’ (Nat β†’ Nat) β†’ Prop` β€” modulus of Cauchy convergence.
200pub fn cauchy_modulus_ty() -> Expr {
201    arrow(
202        arrow(nat_ty(), real_ty()),
203        arrow(arrow(nat_ty(), nat_ty()), prop()),
204    )
205}
206/// `BishopReal : Type` β€” Bishop real: Cauchy sequence with explicit modulus.
207pub fn bishop_real_ty() -> Expr {
208    type0()
209}
210/// `BishopRealAdd : BishopReal β†’ BishopReal β†’ BishopReal`
211pub fn bishop_real_add_ty() -> Expr {
212    arrow(bishop_real_ty(), arrow(bishop_real_ty(), bishop_real_ty()))
213}
214/// `BishopRealMul : BishopReal β†’ BishopReal β†’ BishopReal`
215pub fn bishop_real_mul_ty() -> Expr {
216    arrow(bishop_real_ty(), arrow(bishop_real_ty(), bishop_real_ty()))
217}
218/// `BishopRealEq : BishopReal β†’ BishopReal β†’ Prop` β€” constructive equality (coincidence).
219pub fn bishop_real_eq_ty() -> Expr {
220    arrow(bishop_real_ty(), arrow(bishop_real_ty(), prop()))
221}
222/// `BishopRealLt : BishopReal β†’ BishopReal β†’ Prop` β€” constructive strict order.
223pub fn bishop_real_lt_ty() -> Expr {
224    arrow(bishop_real_ty(), arrow(bishop_real_ty(), prop()))
225}
226/// `BishopRealApart : BishopReal β†’ BishopReal β†’ Prop` β€” apartness relation #.
227pub fn bishop_real_apart_ty() -> Expr {
228    arrow(bishop_real_ty(), arrow(bishop_real_ty(), prop()))
229}
230/// `BishopRealField : BishopReal forms a constructive field.`
231pub fn bishop_real_field_ty() -> Expr {
232    prop()
233}
234/// `ConstructiveIVT : constructive intermediate value theorem (requires apartness).`
235pub fn constructive_ivt_ty() -> Expr {
236    pi(
237        BinderInfo::Default,
238        "f",
239        arrow(bishop_real_ty(), bishop_real_ty()),
240        pi(
241            BinderInfo::Default,
242            "a",
243            bishop_real_ty(),
244            pi(
245                BinderInfo::Default,
246                "b",
247                bishop_real_ty(),
248                arrow(
249                    app2(cst("BishopRealLt"), bvar(1), bvar(0)),
250                    arrow(
251                        app2(
252                            cst("SignChanges"),
253                            app(bvar(2), bvar(1)),
254                            app(bvar(2), bvar(0)),
255                        ),
256                        app2(
257                            cst("BishopExists"),
258                            bvar(2),
259                            app2(cst("mk_interval"), bvar(1), bvar(0)),
260                        ),
261                    ),
262                ),
263            ),
264        ),
265    )
266}
267/// `PartialRecursive : (Nat β†’ Option Nat) β†’ Prop` β€” partial recursive (computable) function.
268pub fn partial_recursive_ty() -> Expr {
269    arrow(arrow(nat_ty(), option_ty(nat_ty())), prop())
270}
271/// `TuringMachine : Type` β€” a Turing machine description.
272pub fn turing_machine_ty() -> Expr {
273    type0()
274}
275/// `TMComputes : TuringMachine β†’ (Nat β†’ Option Nat) β†’ Prop` β€” TM computes a function.
276pub fn tm_computes_ty() -> Expr {
277    arrow(
278        turing_machine_ty(),
279        arrow(arrow(nat_ty(), option_ty(nat_ty())), prop()),
280    )
281}
282/// `ChurchTuringThesis : every computable function is partial recursive.`
283pub fn church_turing_thesis_ty() -> Expr {
284    pi(
285        BinderInfo::Default,
286        "f",
287        arrow(nat_ty(), option_ty(nat_ty())),
288        arrow(
289            app(cst("Computable"), bvar(0)),
290            app(cst("PartialRecursive"), bvar(0)),
291        ),
292    )
293}
294/// `HaltingProblemUndecidable : the halting problem is not computable.`
295pub fn halting_problem_undecidable_ty() -> Expr {
296    prop()
297}
298/// `UniversalTuringMachine : Type` β€” a universal Turing machine.
299pub fn utm_ty() -> Expr {
300    turing_machine_ty()
301}
302/// `SmNTheorem : the s-m-n theorem (parametric recursion).`
303pub fn smn_theorem_ty() -> Expr {
304    pi(
305        BinderInfo::Default,
306        "m",
307        nat_ty(),
308        pi(BinderInfo::Default, "n", nat_ty(), prop()),
309    )
310}
311/// `RecursionTheorem : Kleene's recursion theorem (fixed-point theorem for programs).`
312pub fn recursion_theorem_ty() -> Expr {
313    pi(
314        BinderInfo::Default,
315        "f",
316        arrow(nat_ty(), nat_ty()),
317        app(cst("HasFixedPointIndex"), bvar(0)),
318    )
319}
320/// `DecidablePred : (Nat β†’ Prop) β†’ Prop` β€” decidable predicate on Nat.
321pub fn decidable_pred_ty() -> Expr {
322    arrow(arrow(nat_ty(), prop()), prop())
323}
324/// `MarkovPrinciple : if P is decidable and Β¬Β¬βˆƒn, Pn then βˆƒn, Pn.`
325pub fn markov_principle_ty() -> Expr {
326    pi(
327        BinderInfo::Default,
328        "P",
329        arrow(nat_ty(), prop()),
330        arrow(
331            app(cst("DecidablePred"), bvar(0)),
332            arrow(
333                app(cst("Not"), app(cst("Not"), app(cst("Exists"), bvar(0)))),
334                app(cst("Exists"), bvar(0)),
335            ),
336        ),
337    )
338}
339/// `MarkovRule : the rule form of Markov's principle (weaker).`
340pub fn markov_rule_ty() -> Expr {
341    pi(
342        BinderInfo::Default,
343        "P",
344        arrow(nat_ty(), bool_ty()),
345        arrow(
346            app(cst("Not"), app(cst("Not"), app(cst("ExistsBool"), bvar(0)))),
347            app(cst("ExistsBool"), bvar(0)),
348        ),
349    )
350}
351/// `UnboundedSearch : (Nat β†’ Bool) β†’ Nat` β€” unbounded search (ΞΌ-operator).
352pub fn unbounded_search_ty() -> Expr {
353    arrow(arrow(nat_ty(), bool_ty()), option_ty(nat_ty()))
354}
355/// `UnboundedSearchCorrect : if P n holds for some n, unbounded_search P returns Some n.`
356pub fn unbounded_search_correct_ty() -> Expr {
357    pi(
358        BinderInfo::Default,
359        "P",
360        arrow(nat_ty(), bool_ty()),
361        pi(
362            BinderInfo::Default,
363            "n",
364            nat_ty(),
365            arrow(
366                app2(cst("Eq"), app(bvar(1), bvar(0)), cst("Bool.true")),
367                app2(
368                    cst("Ne"),
369                    app(cst("UnboundedSearch"), bvar(1)),
370                    cst("Option.none"),
371                ),
372            ),
373        ),
374    )
375}
376/// `BinaryTree : Type` β€” infinite binary tree (Baire space β„•^β„• paths).
377pub fn binary_tree_ty() -> Expr {
378    type0()
379}
380/// `Spread : (List Nat β†’ Prop) β†’ Prop` β€” spread (closed subset of Baire space).
381pub fn spread_ty() -> Expr {
382    arrow(arrow(list_ty(nat_ty()), prop()), prop())
383}
384/// `Bar : (List Nat β†’ Prop) β†’ Prop` β€” a bar (every infinite path hits it).
385pub fn bar_ty() -> Expr {
386    arrow(arrow(list_ty(nat_ty()), prop()), prop())
387}
388/// `DecidableBar : (List Nat β†’ Prop) β†’ Prop` β€” a decidable bar.
389pub fn decidable_bar_ty() -> Expr {
390    arrow(arrow(list_ty(nat_ty()), prop()), prop())
391}
392/// `FanTheorem : every decidable bar is uniform (has finite bound).`
393pub fn fan_theorem_ty() -> Expr {
394    pi(
395        BinderInfo::Default,
396        "B",
397        arrow(list_ty(nat_ty()), prop()),
398        arrow(
399            app(cst("DecidableBar"), bvar(0)),
400            app(cst("UniformBar"), bvar(0)),
401        ),
402    )
403}
404/// `BarInduction : monotone bar induction principle.`
405pub fn bar_induction_ty() -> Expr {
406    pi(
407        BinderInfo::Default,
408        "B",
409        arrow(list_ty(nat_ty()), prop()),
410        pi(
411            BinderInfo::Default,
412            "A",
413            arrow(list_ty(nat_ty()), prop()),
414            arrow(
415                app2(cst("BarInductionPremises"), bvar(1), bvar(0)),
416                app(bvar(0), list_ty(nat_ty())),
417            ),
418        ),
419    )
420}
421/// `KripkesSchema : Kripke's schema for choice sequences.`
422pub fn kripkes_schema_ty() -> Expr {
423    pi(
424        BinderInfo::Default,
425        "P",
426        prop(),
427        app(cst("ExistsAlpha"), app(cst("KripkeBool"), bvar(0))),
428    )
429}
430/// `Realizer : Nat β†’ IProp β†’ Prop` β€” Kleene realizability: n realizes P.
431pub fn realizer_ty() -> Expr {
432    arrow(nat_ty(), arrow(iprop_ty(), prop()))
433}
434/// `KleeneRealizes : Nat β†’ IProp β†’ Prop` β€” n |= P in Kleene realizability.
435pub fn kleene_realizes_ty() -> Expr {
436    arrow(nat_ty(), arrow(iprop_ty(), prop()))
437}
438/// `ModifiedRealizability : (Nat β†’ IProp) β†’ IProp` β€” modified realizability (Kreisel).
439pub fn modified_realizability_ty() -> Expr {
440    arrow(arrow(nat_ty(), iprop_ty()), iprop_ty())
441}
442/// `DisjunctionProperty : if P ∨ Q is realizable then P or Q is realizable.`
443pub fn disjunction_property_ty() -> Expr {
444    pi(
445        BinderInfo::Default,
446        "P",
447        iprop_ty(),
448        pi(
449            BinderInfo::Default,
450            "Q",
451            iprop_ty(),
452            arrow(
453                app(cst("Realizable"), app2(cst("BHK_Or"), bvar(1), bvar(0))),
454                app2(
455                    cst("Or"),
456                    app(cst("Realizable"), bvar(1)),
457                    app(cst("Realizable"), bvar(0)),
458                ),
459            ),
460        ),
461    )
462}
463/// `ExistenceProperty : if βˆƒx.Px is realizable then some specific n satisfies Pn.`
464pub fn existence_property_ty() -> Expr {
465    pi(
466        BinderInfo::Default,
467        "P",
468        arrow(nat_ty(), iprop_ty()),
469        arrow(
470            app(cst("Realizable"), app(cst("BHK_Exists"), bvar(0))),
471            app2(cst("Sigma"), nat_ty(), bvar(0)),
472        ),
473    )
474}
475/// `PcaRealizability : partial combinatory algebra realizability.`
476pub fn pca_realizability_ty() -> Expr {
477    type0()
478}
479/// `IdType : βˆ€ {A : Type}, A β†’ A β†’ Type` β€” Martin-LΓΆf identity type.
480pub fn id_type_ty() -> Expr {
481    pi(
482        BinderInfo::Implicit,
483        "A",
484        type0(),
485        arrow(bvar(0), arrow(bvar(1), type0())),
486    )
487}
488/// `IdRefl : βˆ€ {A : Type} (a : A), Id a a` β€” reflexivity constructor.
489pub fn id_refl_ty() -> Expr {
490    pi(
491        BinderInfo::Implicit,
492        "A",
493        type0(),
494        pi(
495            BinderInfo::Default,
496            "a",
497            bvar(0),
498            app2(cst("Id"), bvar(0), bvar(0)),
499        ),
500    )
501}
502/// `PathInduction : βˆ€ {A} (C : βˆ€ x y, Id x y β†’ Type), (βˆ€ a, C a a (refl a)) β†’ βˆ€ x y (p: Id x y), C x y p.`
503pub fn path_induction_ty() -> Expr {
504    pi(
505        BinderInfo::Implicit,
506        "A",
507        type0(),
508        pi(
509            BinderInfo::Default,
510            "C",
511            arrow(
512                bvar(0),
513                arrow(bvar(1), arrow(app2(cst("Id"), bvar(1), bvar(0)), type0())),
514            ),
515            arrow(
516                pi(
517                    BinderInfo::Default,
518                    "a",
519                    bvar(1),
520                    app3(bvar(1), bvar(0), bvar(0), app(cst("IdRefl"), bvar(0))),
521                ),
522                prop(),
523            ),
524        ),
525    )
526}
527/// `HomotopyType : Type` β€” homotopy of paths.
528pub fn homotopy_type_ty() -> Expr {
529    type0()
530}
531/// `FunExtConstructive : constructive function extensionality.`
532pub fn fun_ext_constructive_ty() -> Expr {
533    pi(
534        BinderInfo::Implicit,
535        "A",
536        type0(),
537        pi(
538            BinderInfo::Implicit,
539            "B",
540            type0(),
541            pi(
542                BinderInfo::Default,
543                "f",
544                arrow(bvar(1), bvar(1)),
545                pi(
546                    BinderInfo::Default,
547                    "g",
548                    arrow(bvar(2), bvar(2)),
549                    arrow(
550                        pi(
551                            BinderInfo::Default,
552                            "x",
553                            bvar(3),
554                            app2(cst("Id"), app(bvar(2), bvar(0)), app(bvar(1), bvar(0))),
555                        ),
556                        app2(cst("Id"), bvar(1), bvar(0)),
557                    ),
558                ),
559            ),
560        ),
561    )
562}
563/// `ContinuousFunctionNat : (Nat^Nat β†’ Nat) β†’ Prop` β€” every function is continuous.
564pub fn continuous_function_nat_ty() -> Expr {
565    arrow(arrow(arrow(nat_ty(), nat_ty()), nat_ty()), prop())
566}
567/// `BrouwerContinuity : every function β„•^β„• β†’ β„• is pointwise continuous.`
568pub fn brouwer_continuity_ty() -> Expr {
569    pi(
570        BinderInfo::Default,
571        "F",
572        arrow(arrow(nat_ty(), nat_ty()), nat_ty()),
573        pi(
574            BinderInfo::Default,
575            "alpha",
576            arrow(nat_ty(), nat_ty()),
577            app2(cst("IsContinuousAt"), bvar(1), bvar(0)),
578        ),
579    )
580}
581/// `BrouwerCreateChoice : every sequence of inhabited sets has a choice function.`
582pub fn brouwer_choice_ty() -> Expr {
583    pi(
584        BinderInfo::Default,
585        "A",
586        arrow(nat_ty(), type0()),
587        arrow(
588            pi(
589                BinderInfo::Default,
590                "n",
591                nat_ty(),
592                app(cst("Inhabited"), app(bvar(1), bvar(0))),
593            ),
594            pi(BinderInfo::Default, "n", nat_ty(), app(bvar(1), bvar(0))),
595        ),
596    )
597}
598/// `UniformContinuityTheorem : every total function on Cantor space is uniformly continuous.`
599pub fn uniform_continuity_theorem_ty() -> Expr {
600    pi(
601        BinderInfo::Default,
602        "f",
603        arrow(arrow(nat_ty(), bool_ty()), nat_ty()),
604        app(cst("IsUniformlyContinuous"), bvar(0)),
605    )
606}
607/// `HAAxioms : Heyting Arithmetic axioms.`
608pub fn ha_axioms_ty() -> Expr {
609    prop()
610}
611/// `MLTTAxioms : Martin-LΓΆf type theory axioms.`
612pub fn mltt_axioms_ty() -> Expr {
613    prop()
614}
615/// `CZFAxioms : Constructive Zermelo-Fraenkel set theory axioms.`
616pub fn czf_axioms_ty() -> Expr {
617    prop()
618}
619/// `IZFAxioms : Intuitionistic Zermelo-Fraenkel axioms.`
620pub fn izf_axioms_ty() -> Expr {
621    prop()
622}
623/// `AxiomOfChoice : the full axiom of choice (non-constructive).`
624pub fn axiom_of_choice_ty() -> Expr {
625    pi(
626        BinderInfo::Implicit,
627        "A",
628        type0(),
629        pi(
630            BinderInfo::Implicit,
631            "B",
632            arrow(bvar(0), type0()),
633            arrow(
634                pi(
635                    BinderInfo::Default,
636                    "x",
637                    bvar(1),
638                    app(cst("Inhabited"), app(bvar(1), bvar(0))),
639                ),
640                app2(cst("Sigma"), arrow(bvar(1), bvar(1)), prop()),
641            ),
642        ),
643    )
644}
645/// `AxiomOfDependentChoice : dependent choice (weaker than full AC, constructive).`
646pub fn dependent_choice_ty() -> Expr {
647    pi(
648        BinderInfo::Implicit,
649        "A",
650        type0(),
651        pi(
652            BinderInfo::Default,
653            "R",
654            arrow(bvar(0), arrow(bvar(1), prop())),
655            arrow(
656                app(cst("Serial"), bvar(0)),
657                app2(cst("Sigma"), arrow(nat_ty(), bvar(1)), prop()),
658            ),
659        ),
660    )
661}
662/// `CHA : Prop` β€” Constructive Heyting Arithmetic as a formal system.
663pub fn cha_axioms_ty() -> Expr {
664    prop()
665}
666/// `CHA_Succ : Nat β†’ Nat` β€” successor function in CHA.
667pub fn cha_succ_ty() -> Expr {
668    arrow(nat_ty(), nat_ty())
669}
670/// `CHA_Add : Nat β†’ Nat β†’ Nat` β€” addition in CHA.
671pub fn cha_add_ty() -> Expr {
672    arrow(nat_ty(), arrow(nat_ty(), nat_ty()))
673}
674/// `CHA_Mul : Nat β†’ Nat β†’ Nat` β€” multiplication in CHA.
675pub fn cha_mul_ty() -> Expr {
676    arrow(nat_ty(), arrow(nat_ty(), nat_ty()))
677}
678/// `CHA_Induction : standard induction schema for CHA.`
679pub fn cha_induction_ty() -> Expr {
680    pi(
681        BinderInfo::Default,
682        "P",
683        arrow(nat_ty(), prop()),
684        arrow(
685            app(bvar(0), cst("CHA_Zero")),
686            arrow(
687                pi(
688                    BinderInfo::Default,
689                    "n",
690                    nat_ty(),
691                    arrow(
692                        app(bvar(1), bvar(0)),
693                        app(bvar(1), app(cst("CHA_Succ"), bvar(0))),
694                    ),
695                ),
696                pi(BinderInfo::Default, "n", nat_ty(), app(bvar(1), bvar(0))),
697            ),
698        ),
699    )
700}
701/// `CHA_LessEq : Nat β†’ Nat β†’ Prop` β€” constructive ≀ on Nat.
702pub fn cha_less_eq_ty() -> Expr {
703    arrow(nat_ty(), arrow(nat_ty(), prop()))
704}
705/// `EffectiveTopos : Type` β€” the effective topos (Hyland, 1982).
706pub fn effective_topos_ty() -> Expr {
707    type0()
708}
709/// `RealizabilityTopos : Type` β€” a general realizability topos.
710pub fn realizability_topos_ty() -> Expr {
711    type0()
712}
713/// `PCA : Type` β€” partial combinatory algebra (the base of realizability).
714pub fn pca_ty() -> Expr {
715    type0()
716}
717/// `PCAApp : PCA β†’ PCA β†’ Option PCA` β€” partial application in a PCA.
718pub fn pca_app_ty() -> Expr {
719    arrow(pca_ty(), arrow(pca_ty(), option_ty(pca_ty())))
720}
721/// `KleeneFirst : PCA` β€” Kleene's first algebra (partial recursive functions).
722pub fn kleene_first_ty() -> Expr {
723    pca_ty()
724}
725/// `KleeneSecond : PCA` β€” Kleene's second algebra (total continuous functions).
726pub fn kleene_second_ty() -> Expr {
727    pca_ty()
728}
729/// `EffectiveToposInternalLogic : the internal logic of Eff is IZF.`
730pub fn effective_topos_internal_logic_ty() -> Expr {
731    prop()
732}
733/// `AssemblyCategory : PCA β†’ Type` β€” category of assemblies over a PCA.
734pub fn assembly_category_ty() -> Expr {
735    arrow(pca_ty(), type0())
736}
737/// `CZFSet : Type` β€” a set in Constructive Zermelo-Fraenkel set theory.
738pub fn czf_set_ty() -> Expr {
739    type0()
740}
741/// `CZF_Member : CZFSet β†’ CZFSet β†’ Prop` β€” membership relation in CZF.
742pub fn czf_member_ty() -> Expr {
743    arrow(czf_set_ty(), arrow(czf_set_ty(), prop()))
744}
745/// `CZF_Extensionality : two sets with same members are equal.`
746pub fn czf_extensionality_ty() -> Expr {
747    pi(
748        BinderInfo::Default,
749        "a",
750        czf_set_ty(),
751        pi(
752            BinderInfo::Default,
753            "b",
754            czf_set_ty(),
755            arrow(
756                pi(
757                    BinderInfo::Default,
758                    "x",
759                    czf_set_ty(),
760                    app2(
761                        cst("Iff"),
762                        app2(cst("CZF_Member"), bvar(0), bvar(2)),
763                        app2(cst("CZF_Member"), bvar(0), bvar(1)),
764                    ),
765                ),
766                app2(cst("Eq"), bvar(1), bvar(0)),
767            ),
768        ),
769    )
770}
771/// `CZF_Subset : CZFSet β†’ CZFSet β†’ Prop` β€” subset relation.
772pub fn czf_subset_ty() -> Expr {
773    arrow(czf_set_ty(), arrow(czf_set_ty(), prop()))
774}
775/// `CZF_StrongCollection : strong collection axiom schema (replaces replacement).`
776pub fn czf_strong_collection_ty() -> Expr {
777    pi(
778        BinderInfo::Default,
779        "R",
780        arrow(czf_set_ty(), arrow(czf_set_ty(), prop())),
781        pi(
782            BinderInfo::Default,
783            "a",
784            czf_set_ty(),
785            arrow(
786                pi(
787                    BinderInfo::Default,
788                    "x",
789                    czf_set_ty(),
790                    arrow(
791                        app2(cst("CZF_Member"), bvar(0), bvar(1)),
792                        app(cst("CZF_Exists"), app(bvar(2), bvar(0))),
793                    ),
794                ),
795                app(
796                    cst("CZF_Exists"),
797                    app(cst("CZF_Collection"), app(bvar(1), bvar(0))),
798                ),
799            ),
800        ),
801    )
802}
803/// `CZF_SubsetCollection : subset collection axiom (for power-set replacement).`
804pub fn czf_subset_collection_ty() -> Expr {
805    pi(
806        BinderInfo::Default,
807        "a",
808        czf_set_ty(),
809        pi(
810            BinderInfo::Default,
811            "b",
812            czf_set_ty(),
813            app(
814                cst("CZF_Exists"),
815                app2(cst("CZF_SubColl"), bvar(1), bvar(0)),
816            ),
817        ),
818    )
819}
820/// `AntiFoundation : Aczel's anti-foundation axiom (AFA).`
821pub fn anti_foundation_ty() -> Expr {
822    pi(
823        BinderInfo::Default,
824        "G",
825        arrow(czf_set_ty(), czf_set_ty()),
826        app(cst("CZF_Exists"), app(cst("AFA_Solution"), bvar(0))),
827    )
828}
829/// `IZF_Regularity : every non-empty set has an ∈-minimal element.`
830pub fn izf_regularity_ty() -> Expr {
831    pi(
832        BinderInfo::Default,
833        "a",
834        czf_set_ty(),
835        arrow(
836            app(cst("CZF_Nonempty"), bvar(0)),
837            app2(cst("CZF_HasMinimalElement"), bvar(0), cst("CZF_Member")),
838        ),
839    )
840}
841/// `BarRecursor : ((Nat β†’ Nat) β†’ Nat) β†’ (Nat β†’ Nat) β†’ Nat` β€” Spector's bar recursion.
842pub fn bar_recursor_ty() -> Expr {
843    arrow(
844        arrow(arrow(nat_ty(), nat_ty()), nat_ty()),
845        arrow(arrow(nat_ty(), nat_ty()), nat_ty()),
846    )
847}
848/// `BarRecursionAxiom : the axiom governing bar recursion (Spector 1962).`
849pub fn bar_recursion_axiom_ty() -> Expr {
850    pi(
851        BinderInfo::Default,
852        "Y",
853        arrow(arrow(nat_ty(), nat_ty()), nat_ty()),
854        pi(
855            BinderInfo::Default,
856            "G",
857            arrow(arrow(nat_ty(), nat_ty()), nat_ty()),
858            pi(
859                BinderInfo::Default,
860                "H",
861                arrow(
862                    list_ty(nat_ty()),
863                    arrow(arrow(nat_ty(), nat_ty()), nat_ty()),
864                ),
865                prop(),
866            ),
867        ),
868    )
869}
870/// `UniformModulus : (Nat^Nat β†’ Nat) β†’ Nat` β€” uniform modulus of continuity.
871pub fn uniform_modulus_ty() -> Expr {
872    arrow(arrow(arrow(nat_ty(), nat_ty()), nat_ty()), nat_ty())
873}
874/// `SpectorTranslation : double-negation shift for bar recursion.`
875pub fn spector_translation_ty() -> Expr {
876    pi(
877        BinderInfo::Default,
878        "A",
879        prop(),
880        arrow(app(cst("Not"), app(cst("Not"), bvar(0))), bvar(0)),
881    )
882}
883/// `FiniteFan : (List Nat β†’ Prop) β†’ Prop` β€” a finitely branching spread.
884pub fn finite_fan_ty() -> Expr {
885    arrow(arrow(list_ty(nat_ty()), prop()), prop())
886}
887/// `FanTheoremStrong : strong fan theorem (every bar on a fan has a finite sub-bar).`
888pub fn fan_theorem_strong_ty() -> Expr {
889    pi(
890        BinderInfo::Default,
891        "F",
892        arrow(list_ty(nat_ty()), prop()),
893        pi(
894            BinderInfo::Default,
895            "B",
896            arrow(list_ty(nat_ty()), prop()),
897            arrow(
898                app(cst("FiniteFan"), bvar(1)),
899                arrow(app(cst("Bar"), bvar(0)), app(cst("FiniteBar"), bvar(0))),
900            ),
901        ),
902    )
903}
904/// `BarTheoremAnalytic : analytic bar induction on the Baire space.`
905pub fn bar_theorem_analytic_ty() -> Expr {
906    pi(
907        BinderInfo::Default,
908        "B",
909        arrow(list_ty(nat_ty()), prop()),
910        arrow(
911            app2(cst("AnalyticBar"), bvar(0), cst("BaireSpace")),
912            app(cst("MonotoneInduction"), bvar(0)),
913        ),
914    )
915}
916/// `KleeneBrouwerOrdering : well-founded ordering on finite sequences.`
917pub fn kleene_brouwer_ordering_ty() -> Expr {
918    arrow(list_ty(nat_ty()), arrow(list_ty(nat_ty()), prop()))
919}
920/// `ConstructiveHeineBorel : the unit interval [0,1] is compact for lawful sequences.`
921pub fn constructive_heine_borel_ty() -> Expr {
922    pi(
923        BinderInfo::Default,
924        "cover",
925        arrow(bishop_real_ty(), prop()),
926        arrow(
927            app(
928                cst("OpenCover"),
929                app2(cst("UnitInterval"), cst("BishopZero"), cst("BishopOne")),
930            ),
931            app(cst("FiniteSubcover"), bvar(0)),
932        ),
933    )
934}
935/// `LawfulSequence : (Nat β†’ BishopReal) β†’ Prop` β€” a sequence with computable modulus.
936pub fn lawful_sequence_ty() -> Expr {
937    arrow(arrow(nat_ty(), bishop_real_ty()), prop())
938}
939/// `SequentialCompactness : [0,1] is sequentially compact for lawful sequences.`
940pub fn sequential_compactness_ty() -> Expr {
941    pi(
942        BinderInfo::Default,
943        "s",
944        arrow(nat_ty(), bishop_real_ty()),
945        arrow(
946            app(cst("LawfulSequence"), bvar(0)),
947            app(cst("HasConvergentSubsequence"), bvar(0)),
948        ),
949    )
950}
951/// `MP_PR : Markov's principle for primitive recursive predicates.`
952pub fn mp_pr_ty() -> Expr {
953    pi(
954        BinderInfo::Default,
955        "P",
956        arrow(nat_ty(), bool_ty()),
957        arrow(
958            app(cst("IsPrimRec"), bvar(0)),
959            arrow(
960                app(cst("Not"), app(cst("Not"), app(cst("ExistsBool"), bvar(1)))),
961                app(cst("ExistsBool"), bvar(1)),
962            ),
963        ),
964    )
965}
966/// `MP_Semi : semi-Markov principle (for Σ₁ predicates).`
967pub fn mp_semi_ty() -> Expr {
968    pi(
969        BinderInfo::Default,
970        "P",
971        arrow(nat_ty(), prop()),
972        arrow(
973            app(cst("IsSigma1"), bvar(0)),
974            arrow(
975                app(cst("Not"), app(cst("Not"), app(cst("Exists"), bvar(1)))),
976                app(cst("Exists"), bvar(1)),
977            ),
978        ),
979    )
980}
981/// `MP_Weak : weak Markov's principle (Ξ β‚‚ form).`
982pub fn mp_weak_ty() -> Expr {
983    pi(
984        BinderInfo::Default,
985        "alpha",
986        arrow(nat_ty(), nat_ty()),
987        arrow(
988            app(
989                cst("Not"),
990                app(cst("Not"), app(cst("ExistsAlphaZero"), bvar(0))),
991            ),
992            app(cst("ExistsAlphaZero"), bvar(0)),
993        ),
994    )
995}
996/// `CT0 : Church's thesis β€” every function Nat β†’ Nat is recursive.`
997pub fn ct0_ty() -> Expr {
998    pi(
999        BinderInfo::Default,
1000        "f",
1001        arrow(nat_ty(), nat_ty()),
1002        app(cst("IsRecursive"), bvar(0)),
1003    )
1004}
1005/// `CT0_Consequence_NoContinuousAll : CTβ‚€ contradicts all-functions-continuous.`
1006pub fn ct0_consequence_no_continuous_all_ty() -> Expr {
1007    arrow(
1008        ct0_ty(),
1009        app(
1010            cst("Not"),
1011            pi(
1012                BinderInfo::Default,
1013                "f",
1014                arrow(nat_ty(), nat_ty()),
1015                app(cst("IsContinuous"), bvar(0)),
1016            ),
1017        ),
1018    )
1019}
1020/// `CT0_Enumerable : CTβ‚€ implies Nat β†’ Nat is effectively enumerable.`
1021pub fn ct0_enumerable_ty() -> Expr {
1022    arrow(
1023        ct0_ty(),
1024        app(cst("EffectivelyEnumerable"), arrow(nat_ty(), nat_ty())),
1025    )
1026}
1027/// `CT0_Diagonalization : CTβ‚€ plus diagonalisation yields undecidable problems.`
1028pub fn ct0_diagonalization_ty() -> Expr {
1029    arrow(
1030        ct0_ty(),
1031        app(
1032            cst("Exists"),
1033            app(cst("Undecidable"), cst("TotalRecursiveFns")),
1034        ),
1035    )
1036}
1037/// `CoherentRing : Type` β€” a coherent ring (finitely generated submodules are finitely related).
1038pub fn coherent_ring_ty() -> Expr {
1039    type0()
1040}
1041/// `CoherentRing_Ideal : CoherentRing β†’ Type` β€” ideals in a coherent ring.
1042pub fn coherent_ring_ideal_ty() -> Expr {
1043    arrow(coherent_ring_ty(), type0())
1044}
1045/// `ExplicitField : Type` β€” a field with decidable equality.
1046pub fn explicit_field_ty() -> Expr {
1047    type0()
1048}
1049/// `ExplicitField_Inv : ExplicitField β†’ ExplicitField β†’ ExplicitField` β€” division.
1050pub fn explicit_field_inv_ty() -> Expr {
1051    arrow(
1052        explicit_field_ty(),
1053        arrow(explicit_field_ty(), explicit_field_ty()),
1054    )
1055}
1056/// `CoherentRing_SyzygyModule : every submodule of a free coherent module has a syzygy.`
1057pub fn coherent_ring_syzygy_ty() -> Expr {
1058    pi(
1059        BinderInfo::Default,
1060        "R",
1061        coherent_ring_ty(),
1062        pi(
1063            BinderInfo::Default,
1064            "M",
1065            app(cst("FreeModule"), bvar(0)),
1066            pi(
1067                BinderInfo::Default,
1068                "N",
1069                app(cst("Submodule"), bvar(0)),
1070                app(cst("HasFiniteSyzygy"), bvar(0)),
1071            ),
1072        ),
1073    )
1074}
1075/// `GCDDomain : Type` β€” constructive GCD domain (Bezout domain with algorithm).
1076pub fn gcd_domain_ty() -> Expr {
1077    type0()
1078}
1079/// `GCDDomain_Gcd : GCDDomain β†’ GCDDomain β†’ GCDDomain` β€” gcd of two elements.
1080pub fn gcd_domain_gcd_ty() -> Expr {
1081    arrow(gcd_domain_ty(), arrow(gcd_domain_ty(), gcd_domain_ty()))
1082}
1083/// `Numbering : (Nat β†’ Option A) β†’ Prop` β€” a numbering of a set A.
1084pub fn numbering_ty() -> Expr {
1085    arrow(arrow(nat_ty(), option_ty(type0())), prop())
1086}
1087/// `RecursiveNumbering : Type` β€” a recursively enumerable numbering.
1088pub fn recursive_numbering_ty() -> Expr {
1089    type0()
1090}
1091/// `GoedelNumbering : a GΓΆdel numbering of partial recursive functions.`
1092pub fn goedel_numbering_ty() -> Expr {
1093    arrow(arrow(nat_ty(), option_ty(nat_ty())), nat_ty())
1094}
1095/// `GrzegorczykHierarchy : Nat β†’ Type` β€” the Grzegorczyk hierarchy E_n.
1096pub fn grzegorczyk_hierarchy_ty() -> Expr {
1097    arrow(nat_ty(), type0())
1098}
1099/// `GrzegorczykUnion : ⋃_n E_n = primitive recursive functions.`
1100pub fn grzegorczyk_union_ty() -> Expr {
1101    app2(
1102        cst("Eq"),
1103        app(cst("Union"), cst("GrzegorczykHierarchy")),
1104        cst("PrimRecFns"),
1105    )
1106}
1107/// `TTERepresentation : Type` β€” a representation in TTE (Weihrauch 2000).
1108pub fn tte_representation_ty() -> Expr {
1109    type0()
1110}
1111/// `TTEComputable : TTERepresentation β†’ TTERepresentation β†’ Prop` β€” computable map.
1112pub fn tte_computable_ty() -> Expr {
1113    arrow(
1114        tte_representation_ty(),
1115        arrow(tte_representation_ty(), prop()),
1116    )
1117}
1118/// `CauchyRepresentation : TTERepresentation` β€” standard Cauchy representation of ℝ.
1119pub fn cauchy_representation_ty() -> Expr {
1120    tte_representation_ty()
1121}
1122/// `SignedDigitRepresentation : TTERepresentation` β€” signed digit representation.
1123pub fn signed_digit_representation_ty() -> Expr {
1124    tte_representation_ty()
1125}
1126/// `TTEAdditionComputable : addition of reals is TTE-computable.`
1127pub fn tte_addition_computable_ty() -> Expr {
1128    app2(
1129        cst("TTEComputable"),
1130        app2(
1131            cst("ProductRep"),
1132            cst("CauchyRepresentation"),
1133            cst("CauchyRepresentation"),
1134        ),
1135        cst("CauchyRepresentation"),
1136    )
1137}
1138/// `WeihrauchDegree : Type` β€” Weihrauch degree of a multi-valued function.
1139pub fn weihrauch_degree_ty() -> Expr {
1140    type0()
1141}
1142/// `LPO_Weihrauch : WeihrauchDegree` β€” degree of the Limited Principle of Omniscience.
1143pub fn lpo_weihrauch_ty() -> Expr {
1144    weihrauch_degree_ty()
1145}
1146/// `CountableChoice : CC β€” countable choice axiom.`
1147pub fn countable_choice_ty() -> Expr {
1148    pi(
1149        BinderInfo::Implicit,
1150        "A",
1151        type0(),
1152        pi(
1153            BinderInfo::Default,
1154            "f",
1155            arrow(nat_ty(), arrow(bvar(0), prop())),
1156            arrow(
1157                pi(
1158                    BinderInfo::Default,
1159                    "n",
1160                    nat_ty(),
1161                    app(cst("Inhabited"), app(bvar(1), bvar(0))),
1162                ),
1163                app2(cst("Sigma"), arrow(nat_ty(), bvar(1)), prop()),
1164            ),
1165        ),
1166    )
1167}
1168/// `DC_Relation : a relation that admits DC.`
1169pub fn dc_relation_ty() -> Expr {
1170    arrow(type0(), arrow(type0(), prop()))
1171}
1172/// `DependentChoiceScheme : DC scheme β€” a strengthening of CC.`
1173pub fn dependent_choice_scheme_ty() -> Expr {
1174    pi(
1175        BinderInfo::Implicit,
1176        "A",
1177        type0(),
1178        pi(
1179            BinderInfo::Default,
1180            "R",
1181            arrow(bvar(0), arrow(bvar(1), prop())),
1182            pi(
1183                BinderInfo::Default,
1184                "a0",
1185                bvar(1),
1186                arrow(
1187                    pi(
1188                        BinderInfo::Default,
1189                        "x",
1190                        bvar(2),
1191                        app(
1192                            cst("Inhabited"),
1193                            app(cst("R_Image"), app2(bvar(2), bvar(0), bvar(3))),
1194                        ),
1195                    ),
1196                    app2(cst("Sigma"), arrow(nat_ty(), bvar(3)), prop()),
1197                ),
1198            ),
1199        ),
1200    )
1201}
1202/// `ConstructiveMeasure : Type` β€” a constructive (Bishop-style) measure.
1203pub fn constructive_measure_ty() -> Expr {
1204    type0()
1205}
1206/// `ConstructiveIntegral : (BishopReal β†’ BishopReal) β†’ ConstructiveMeasure β†’ BishopReal`
1207pub fn constructive_integral_ty() -> Expr {
1208    arrow(
1209        arrow(bishop_real_ty(), bishop_real_ty()),
1210        arrow(constructive_measure_ty(), bishop_real_ty()),
1211    )
1212}
1213/// `ConstructiveLebesgue : the constructive Lebesgue integral is well-defined.`
1214pub fn constructive_lebesgue_ty() -> Expr {
1215    pi(
1216        BinderInfo::Default,
1217        "f",
1218        arrow(bishop_real_ty(), bishop_real_ty()),
1219        pi(
1220            BinderInfo::Default,
1221            "mu",
1222            constructive_measure_ty(),
1223            arrow(
1224                app(cst("IntegrableConstructive"), bvar(1)),
1225                app2(
1226                    cst("WellDefined"),
1227                    app(cst("ConstructiveIntegral"), bvar(1)),
1228                    bvar(0),
1229                ),
1230            ),
1231        ),
1232    )
1233}
1234/// `ConstructiveMonotoneConvergence : constructive monotone convergence theorem.`
1235pub fn constructive_monotone_convergence_ty() -> Expr {
1236    pi(
1237        BinderInfo::Default,
1238        "fseq",
1239        arrow(nat_ty(), arrow(bishop_real_ty(), bishop_real_ty())),
1240        pi(
1241            BinderInfo::Default,
1242            "mu",
1243            constructive_measure_ty(),
1244            arrow(
1245                app2(cst("MonotoneBounded"), bvar(1), bvar(0)),
1246                app(
1247                    cst("HasConstructiveLimit"),
1248                    app2(cst("IntegralSequence"), bvar(1), bvar(0)),
1249                ),
1250            ),
1251        ),
1252    )
1253}
1254/// `NilSquare : Type` β€” the object of nilsquare infinitesimals D = {d : R | dΒ² = 0}.`
1255pub fn nil_square_ty() -> Expr {
1256    type0()
1257}
1258/// `SDG_Kock_Lawvere : the Kock-Lawvere axiom: every function D β†’ R is linear.`
1259pub fn sdg_kock_lawvere_ty() -> Expr {
1260    pi(
1261        BinderInfo::Default,
1262        "f",
1263        arrow(nil_square_ty(), real_ty()),
1264        app(cst("ExistsUnique"), app(cst("SDG_LinearFactor"), bvar(0))),
1265    )
1266}
1267/// `SDG_TangentBundle : TangentBundle R^n as a microlinear space.`
1268pub fn sdg_tangent_bundle_ty() -> Expr {
1269    arrow(type0(), type0())
1270}
1271/// `SDG_VectorField : a vector field is a section of the tangent bundle.`
1272pub fn sdg_vector_field_ty() -> Expr {
1273    pi(
1274        BinderInfo::Implicit,
1275        "M",
1276        type0(),
1277        arrow(app(cst("SDG_TangentBundle"), bvar(0)), bvar(1)),
1278    )
1279}
1280/// `SDG_Integration : integration as left inverse to differentiation in SDG.`
1281pub fn sdg_integration_ty() -> Expr {
1282    pi(
1283        BinderInfo::Default,
1284        "f",
1285        arrow(real_ty(), real_ty()),
1286        pi(
1287            BinderInfo::Default,
1288            "a",
1289            real_ty(),
1290            pi(
1291                BinderInfo::Default,
1292                "b",
1293                real_ty(),
1294                app2(
1295                    cst("Eq"),
1296                    app(
1297                        cst("SDG_Derivative"),
1298                        app2(cst("SDG_Integral"), bvar(2), bvar(1)),
1299                    ),
1300                    app(bvar(2), bvar(0)),
1301                ),
1302            ),
1303        ),
1304    )
1305}
1306/// `SDG_MicrolinearSpace : a space where infinitesimal figures are affine.`
1307pub fn sdg_microlinear_ty() -> Expr {
1308    arrow(type0(), prop())
1309}
1310/// Register all constructive mathematics axioms into the kernel environment.
1311pub fn build_constructive_mathematics_env(env: &mut Environment) -> Result<(), String> {
1312    let axioms: &[(&str, Expr)] = &[
1313        ("IProp", iprop_ty()),
1314        ("IProof", iproof_ty()),
1315        ("BHK_And", bhk_and_ty()),
1316        ("BHK_Or", bhk_or_ty()),
1317        ("BHK_Impl", bhk_impl_ty()),
1318        ("BHK_Not", bhk_not_ty()),
1319        ("BHK_Forall", bhk_forall_ty()),
1320        ("BHK_Exists", bhk_exists_ty()),
1321        ("IBot", ibot_ty()),
1322        ("ITop", itop_ty()),
1323        ("Not", arrow(prop(), prop())),
1324        ("Exists", arrow(arrow(nat_ty(), prop()), prop())),
1325        ("ExistsBool", arrow(arrow(nat_ty(), bool_ty()), prop())),
1326        ("Realizable", arrow(iprop_ty(), prop())),
1327        ("HeytingAlgebra", heyting_algebra_ty()),
1328        ("HeytingMeet", heyting_meet_ty()),
1329        ("HeytingJoin", heyting_join_ty()),
1330        ("HeytingImpl", heyting_impl_ty()),
1331        ("HeytingNeg", heyting_neg_ty()),
1332        ("HeytingBot", heyting_bot_ty()),
1333        ("HeytingTop", heyting_top_ty()),
1334        ("HeytingLe", heyting_le_ty()),
1335        ("BooleanAlgebra", boolean_algebra_ty()),
1336        ("ExcludedMiddleFails", excluded_middle_fails_ty()),
1337        ("heyting_impl_adjunction", heyting_impl_adjunction_ty()),
1338        ("double_negation_law", double_negation_law_ty()),
1339        ("CauchySeq", cauchy_seq_ty()),
1340        ("CauchyModulus", cauchy_modulus_ty()),
1341        ("BishopReal", bishop_real_ty()),
1342        ("BishopRealAdd", bishop_real_add_ty()),
1343        ("BishopRealMul", bishop_real_mul_ty()),
1344        ("BishopRealEq", bishop_real_eq_ty()),
1345        ("BishopRealLt", bishop_real_lt_ty()),
1346        ("BishopRealApart", bishop_real_apart_ty()),
1347        ("BishopRealField", bishop_real_field_ty()),
1348        ("SignChanges", arrow(real_ty(), arrow(real_ty(), prop()))),
1349        (
1350            "BishopExists",
1351            arrow(
1352                arrow(bishop_real_ty(), bishop_real_ty()),
1353                arrow(pair_ty(bishop_real_ty(), bishop_real_ty()), prop()),
1354            ),
1355        ),
1356        (
1357            "mk_interval",
1358            arrow(
1359                bishop_real_ty(),
1360                arrow(
1361                    bishop_real_ty(),
1362                    pair_ty(bishop_real_ty(), bishop_real_ty()),
1363                ),
1364            ),
1365        ),
1366        ("constructive_ivt", constructive_ivt_ty()),
1367        ("PartialRecursive", partial_recursive_ty()),
1368        ("TuringMachine", turing_machine_ty()),
1369        ("TMComputes", tm_computes_ty()),
1370        (
1371            "Computable",
1372            arrow(arrow(nat_ty(), option_ty(nat_ty())), prop()),
1373        ),
1374        (
1375            "HaltingProblemUndecidable",
1376            halting_problem_undecidable_ty(),
1377        ),
1378        ("UTM", utm_ty()),
1379        (
1380            "HasFixedPointIndex",
1381            arrow(arrow(nat_ty(), nat_ty()), prop()),
1382        ),
1383        ("church_turing_thesis", church_turing_thesis_ty()),
1384        (
1385            "halting_problem_undecidable",
1386            halting_problem_undecidable_ty(),
1387        ),
1388        ("smn_theorem", smn_theorem_ty()),
1389        ("recursion_theorem", recursion_theorem_ty()),
1390        ("DecidablePred", decidable_pred_ty()),
1391        ("UnboundedSearch", unbounded_search_ty()),
1392        ("markov_principle", markov_principle_ty()),
1393        ("markov_rule", markov_rule_ty()),
1394        ("unbounded_search_correct", unbounded_search_correct_ty()),
1395        ("BinaryTree", binary_tree_ty()),
1396        ("Spread", spread_ty()),
1397        ("Bar", bar_ty()),
1398        ("DecidableBar", decidable_bar_ty()),
1399        (
1400            "UniformBar",
1401            arrow(arrow(list_ty(nat_ty()), prop()), prop()),
1402        ),
1403        (
1404            "BarInductionPremises",
1405            arrow(
1406                arrow(list_ty(nat_ty()), prop()),
1407                arrow(arrow(list_ty(nat_ty()), prop()), prop()),
1408            ),
1409        ),
1410        (
1411            "ExistsAlpha",
1412            arrow(arrow(arrow(nat_ty(), nat_ty()), bool_ty()), prop()),
1413        ),
1414        (
1415            "KripkeBool",
1416            arrow(prop(), arrow(arrow(nat_ty(), nat_ty()), bool_ty())),
1417        ),
1418        ("fan_theorem", fan_theorem_ty()),
1419        ("bar_induction", bar_induction_ty()),
1420        ("kripkes_schema", kripkes_schema_ty()),
1421        ("Realizer", realizer_ty()),
1422        ("KleeneRealizes", kleene_realizes_ty()),
1423        ("ModifiedRealizability", modified_realizability_ty()),
1424        ("PcaRealizability", pca_realizability_ty()),
1425        ("Or", arrow(prop(), arrow(prop(), prop()))),
1426        (
1427            "Sigma",
1428            arrow(type0(), arrow(arrow(nat_ty(), type0()), type0())),
1429        ),
1430        ("disjunction_property", disjunction_property_ty()),
1431        ("existence_property", existence_property_ty()),
1432        ("Id", id_type_ty()),
1433        ("IdRefl", id_refl_ty()),
1434        ("HomotopyType", homotopy_type_ty()),
1435        ("path_induction", path_induction_ty()),
1436        ("fun_ext_constructive", fun_ext_constructive_ty()),
1437        (
1438            "IsContinuousAt",
1439            arrow(
1440                arrow(arrow(nat_ty(), nat_ty()), nat_ty()),
1441                arrow(arrow(nat_ty(), nat_ty()), prop()),
1442            ),
1443        ),
1444        (
1445            "IsUniformlyContinuous",
1446            arrow(arrow(arrow(nat_ty(), bool_ty()), nat_ty()), prop()),
1447        ),
1448        ("Inhabited", arrow(type0(), prop())),
1449        ("Serial", arrow(type0(), prop())),
1450        ("brouwer_continuity", brouwer_continuity_ty()),
1451        ("brouwer_choice", brouwer_choice_ty()),
1452        (
1453            "uniform_continuity_theorem",
1454            uniform_continuity_theorem_ty(),
1455        ),
1456        ("HAAxioms", ha_axioms_ty()),
1457        ("MLTTAxioms", mltt_axioms_ty()),
1458        ("CZFAxioms", czf_axioms_ty()),
1459        ("IZFAxioms", izf_axioms_ty()),
1460        ("axiom_of_choice", axiom_of_choice_ty()),
1461        ("dependent_choice", dependent_choice_ty()),
1462        ("LEM", prop()),
1463        ("DNE", prop()),
1464        ("Peirce", prop()),
1465        ("Bool.true", bool_ty()),
1466        ("Option.none", option_ty(nat_ty())),
1467        ("CHA", cha_axioms_ty()),
1468        ("CHA_Zero", nat_ty()),
1469        ("CHA_Succ", cha_succ_ty()),
1470        ("CHA_Add", cha_add_ty()),
1471        ("CHA_Mul", cha_mul_ty()),
1472        ("cha_induction", cha_induction_ty()),
1473        ("CHA_LessEq", cha_less_eq_ty()),
1474        ("Iff", arrow(prop(), arrow(prop(), prop()))),
1475        ("EffectiveTopos", effective_topos_ty()),
1476        ("RealizabilityTopos", realizability_topos_ty()),
1477        ("PCA", pca_ty()),
1478        ("PCAApp", pca_app_ty()),
1479        ("KleeneFirst", kleene_first_ty()),
1480        ("KleeneSecond", kleene_second_ty()),
1481        (
1482            "EffectiveToposInternalLogic",
1483            effective_topos_internal_logic_ty(),
1484        ),
1485        ("AssemblyCategory", assembly_category_ty()),
1486        ("CZFSet", czf_set_ty()),
1487        ("CZF_Member", czf_member_ty()),
1488        ("czf_extensionality", czf_extensionality_ty()),
1489        ("CZF_Subset", czf_subset_ty()),
1490        ("CZF_Exists", arrow(arrow(czf_set_ty(), prop()), prop())),
1491        (
1492            "CZF_Collection",
1493            arrow(
1494                arrow(czf_set_ty(), arrow(czf_set_ty(), prop())),
1495                arrow(czf_set_ty(), czf_set_ty()),
1496            ),
1497        ),
1498        ("czf_strong_collection", czf_strong_collection_ty()),
1499        ("czf_subset_collection", czf_subset_collection_ty()),
1500        (
1501            "AFA_Solution",
1502            arrow(arrow(czf_set_ty(), czf_set_ty()), czf_set_ty()),
1503        ),
1504        ("anti_foundation", anti_foundation_ty()),
1505        ("CZF_Nonempty", arrow(czf_set_ty(), prop())),
1506        (
1507            "CZF_HasMinimalElement",
1508            arrow(
1509                czf_set_ty(),
1510                arrow(arrow(czf_set_ty(), arrow(czf_set_ty(), prop())), prop()),
1511            ),
1512        ),
1513        ("izf_regularity", izf_regularity_ty()),
1514        ("BarRecursor", bar_recursor_ty()),
1515        ("bar_recursion_axiom", bar_recursion_axiom_ty()),
1516        ("UniformModulus", uniform_modulus_ty()),
1517        ("spector_translation", spector_translation_ty()),
1518        ("FiniteFan", finite_fan_ty()),
1519        ("FiniteBar", arrow(arrow(list_ty(nat_ty()), prop()), prop())),
1520        ("fan_theorem_strong", fan_theorem_strong_ty()),
1521        (
1522            "AnalyticBar",
1523            arrow(arrow(list_ty(nat_ty()), prop()), arrow(type0(), prop())),
1524        ),
1525        ("BaireSpace", type0()),
1526        (
1527            "MonotoneInduction",
1528            arrow(arrow(list_ty(nat_ty()), prop()), prop()),
1529        ),
1530        ("bar_theorem_analytic", bar_theorem_analytic_ty()),
1531        ("KleeneBrouwerOrdering", kleene_brouwer_ordering_ty()),
1532        (
1533            "OpenCover",
1534            arrow(pair_ty(bishop_real_ty(), bishop_real_ty()), prop()),
1535        ),
1536        ("BishopZero", bishop_real_ty()),
1537        ("BishopOne", bishop_real_ty()),
1538        (
1539            "UnitInterval",
1540            arrow(
1541                bishop_real_ty(),
1542                arrow(
1543                    bishop_real_ty(),
1544                    pair_ty(bishop_real_ty(), bishop_real_ty()),
1545                ),
1546            ),
1547        ),
1548        (
1549            "FiniteSubcover",
1550            arrow(arrow(bishop_real_ty(), prop()), prop()),
1551        ),
1552        ("constructive_heine_borel", constructive_heine_borel_ty()),
1553        ("LawfulSequence", lawful_sequence_ty()),
1554        (
1555            "HasConvergentSubsequence",
1556            arrow(arrow(nat_ty(), bishop_real_ty()), prop()),
1557        ),
1558        ("sequential_compactness", sequential_compactness_ty()),
1559        ("IsPrimRec", arrow(arrow(nat_ty(), bool_ty()), prop())),
1560        ("mp_pr", mp_pr_ty()),
1561        ("IsSigma1", arrow(arrow(nat_ty(), prop()), prop())),
1562        ("mp_semi", mp_semi_ty()),
1563        ("ExistsAlphaZero", arrow(arrow(nat_ty(), nat_ty()), prop())),
1564        ("mp_weak", mp_weak_ty()),
1565        ("IsRecursive", arrow(arrow(nat_ty(), nat_ty()), prop())),
1566        ("ct0", ct0_ty()),
1567        ("IsContinuous", arrow(arrow(nat_ty(), nat_ty()), prop())),
1568        (
1569            "ct0_consequence_no_continuous_all",
1570            ct0_consequence_no_continuous_all_ty(),
1571        ),
1572        ("EffectivelyEnumerable", arrow(type0(), prop())),
1573        ("ct0_enumerable", ct0_enumerable_ty()),
1574        ("TotalRecursiveFns", type0()),
1575        ("Undecidable", arrow(type0(), prop())),
1576        ("ct0_diagonalization", ct0_diagonalization_ty()),
1577        ("CoherentRing", coherent_ring_ty()),
1578        ("CoherentRing_Ideal", coherent_ring_ideal_ty()),
1579        ("ExplicitField", explicit_field_ty()),
1580        ("ExplicitField_Inv", explicit_field_inv_ty()),
1581        ("FreeModule", arrow(coherent_ring_ty(), type0())),
1582        ("Submodule", arrow(coherent_ring_ty(), type0())),
1583        ("HasFiniteSyzygy", arrow(coherent_ring_ty(), prop())),
1584        ("coherent_ring_syzygy", coherent_ring_syzygy_ty()),
1585        ("GCDDomain", gcd_domain_ty()),
1586        ("GCDDomain_Gcd", gcd_domain_gcd_ty()),
1587        ("Numbering", numbering_ty()),
1588        ("RecursiveNumbering", recursive_numbering_ty()),
1589        ("GoedelNumbering", goedel_numbering_ty()),
1590        ("GrzegorczykHierarchy", grzegorczyk_hierarchy_ty()),
1591        ("Union", arrow(arrow(nat_ty(), type0()), type0())),
1592        ("PrimRecFns", type0()),
1593        ("grzegorczyk_union", grzegorczyk_union_ty()),
1594        ("TTERepresentation", tte_representation_ty()),
1595        ("TTEComputable", tte_computable_ty()),
1596        ("CauchyRepresentation", cauchy_representation_ty()),
1597        (
1598            "SignedDigitRepresentation",
1599            signed_digit_representation_ty(),
1600        ),
1601        (
1602            "ProductRep",
1603            arrow(
1604                tte_representation_ty(),
1605                arrow(tte_representation_ty(), tte_representation_ty()),
1606            ),
1607        ),
1608        ("tte_addition_computable", tte_addition_computable_ty()),
1609        ("WeihrauchDegree", weihrauch_degree_ty()),
1610        ("LPO_Weihrauch", lpo_weihrauch_ty()),
1611        ("countable_choice", countable_choice_ty()),
1612        ("DC_Relation", dc_relation_ty()),
1613        (
1614            "R_Image",
1615            arrow(
1616                arrow(type0(), arrow(type0(), prop())),
1617                arrow(type0(), type0()),
1618            ),
1619        ),
1620        ("dependent_choice_scheme", dependent_choice_scheme_ty()),
1621        ("ConstructiveMeasure", constructive_measure_ty()),
1622        ("ConstructiveIntegral", constructive_integral_ty()),
1623        (
1624            "IntegrableConstructive",
1625            arrow(arrow(bishop_real_ty(), bishop_real_ty()), prop()),
1626        ),
1627        (
1628            "WellDefined",
1629            arrow(bishop_real_ty(), arrow(constructive_measure_ty(), prop())),
1630        ),
1631        ("constructive_lebesgue", constructive_lebesgue_ty()),
1632        (
1633            "MonotoneBounded",
1634            arrow(
1635                arrow(nat_ty(), arrow(bishop_real_ty(), bishop_real_ty())),
1636                arrow(constructive_measure_ty(), prop()),
1637            ),
1638        ),
1639        (
1640            "IntegralSequence",
1641            arrow(
1642                arrow(nat_ty(), arrow(bishop_real_ty(), bishop_real_ty())),
1643                arrow(constructive_measure_ty(), arrow(nat_ty(), bishop_real_ty())),
1644            ),
1645        ),
1646        (
1647            "HasConstructiveLimit",
1648            arrow(arrow(nat_ty(), bishop_real_ty()), prop()),
1649        ),
1650        (
1651            "constructive_monotone_convergence",
1652            constructive_monotone_convergence_ty(),
1653        ),
1654        ("NilSquare", nil_square_ty()),
1655        ("ExistsUnique", arrow(prop(), prop())),
1656        (
1657            "SDG_LinearFactor",
1658            arrow(arrow(nil_square_ty(), real_ty()), prop()),
1659        ),
1660        ("sdg_kock_lawvere", sdg_kock_lawvere_ty()),
1661        ("SDG_TangentBundle", sdg_tangent_bundle_ty()),
1662        ("SDG_VectorField", sdg_vector_field_ty()),
1663        (
1664            "SDG_Derivative",
1665            arrow(arrow(real_ty(), real_ty()), arrow(real_ty(), real_ty())),
1666        ),
1667        (
1668            "SDG_Integral",
1669            arrow(
1670                arrow(real_ty(), real_ty()),
1671                arrow(real_ty(), arrow(real_ty(), real_ty())),
1672            ),
1673        ),
1674        ("sdg_integration", sdg_integration_ty()),
1675        ("SDG_Microlinear", sdg_microlinear_ty()),
1676    ];
1677    for (name, ty) in axioms {
1678        env.add(Declaration::Axiom {
1679            name: Name::str(*name),
1680            univ_params: vec![],
1681            ty: ty.clone(),
1682        })
1683        .ok();
1684    }
1685    Ok(())
1686}
1687/// Bounded ΞΌ-operator: find the smallest n < bound such that f(n) = 0.
1688pub fn bounded_mu(f: impl Fn(u64) -> Option<u64>, bound: u64) -> Option<u64> {
1689    (0..bound).find(|&n| f(n) == Some(0))
1690}
1691/// Primitive recursive function: Ackermann function.
1692pub fn ackermann(m: u64, n: u64) -> u64 {
1693    match (m, n) {
1694        (0, n) => n + 1,
1695        (m, 0) => ackermann(m - 1, 1),
1696        (m, n) => ackermann(m - 1, ackermann(m, n - 1)),
1697    }
1698}
1699/// Check if a predicate P (given as a function) satisfies Markov's principle
1700/// on [0, bound): if not all values are false (within bound), find one.
1701pub fn markov_search(p: impl Fn(u64) -> bool, bound: u64) -> Option<u64> {
1702    (0..bound).find(|&n| p(n))
1703}
1704/// Church numeral: a function that applies f n times to x.
1705/// We represent it as a Rust closure factory.
1706pub fn church_numeral(n: u64) -> impl Fn(u64) -> u64 {
1707    move |x| {
1708        let mut result = x;
1709        for _ in 0..n {
1710            result = result.wrapping_add(1);
1711        }
1712        result
1713    }
1714}
1715/// Church addition: add two Church numerals.
1716pub fn church_add(m: u64, n: u64) -> u64 {
1717    m + n
1718}
1719/// Church multiplication.
1720pub fn church_mul(m: u64, n: u64) -> u64 {
1721    m * n
1722}
1723/// Check whether a bounded arithmetic formula βˆ€ x < bound, P(x) is decidable.
1724pub fn decide_bounded_forall(p: impl Fn(u64) -> bool, bound: u64) -> bool {
1725    (0..bound).all(p)
1726}
1727/// Check whether βˆƒ x < bound, P(x) holds.
1728pub fn decide_bounded_exists(p: impl Fn(u64) -> bool, bound: u64) -> bool {
1729    (0..bound).any(p)
1730}
1731/// In Kleene realizability, a natural number n realizes P ∧ Q if
1732/// the left projection realizes P and the right projection realizes Q.
1733/// We use Cantor pairing to encode pairs.
1734pub fn cantor_pair(a: u64, b: u64) -> u64 {
1735    (a + b) * (a + b + 1) / 2 + b
1736}
1737pub fn cantor_unpair(n: u64) -> (u64, u64) {
1738    let w = ((((8 * n + 1) as f64).sqrt() - 1.0) / 2.0) as u64;
1739    let t = w * (w + 1) / 2;
1740    let b = n - t;
1741    let a = w - b;
1742    (a, b)
1743}
1744#[cfg(test)]
1745mod tests {
1746    use super::*;
1747    #[test]
1748    fn test_heyting_algebra_laws() {
1749        let h = PowerSetHeyting::new(3);
1750        let top = h.top();
1751        let bot = h.bot();
1752        let a = 0b101u64;
1753        assert_eq!(h.meet(a, top), a);
1754        assert_eq!(h.join(a, bot), a);
1755        assert_eq!(h.neg(top), bot);
1756        assert_eq!(h.neg(bot), top);
1757        let b = 0b011u64;
1758        assert_eq!(h.double_neg(b), b);
1759        let c = 0b110u64;
1760        let lhs = h.le(h.meet(a, b), c);
1761        let rhs = h.le(a, h.implication(b, c));
1762        assert_eq!(lhs, rhs);
1763    }
1764    #[test]
1765    fn test_constructive_real_addition() {
1766        let one_third = ConstructiveReal::from_rational(1, 3, 10);
1767        let two_thirds = ConstructiveReal::from_rational(2, 3, 10);
1768        let sum = one_third.add(&two_thirds);
1769        let one = ConstructiveReal::from_rational(1, 1, 10);
1770        assert!(sum.approx_eq(&one, 5), "1/3 + 2/3 should approximate 1");
1771    }
1772    #[test]
1773    fn test_constructive_real_from_rational() {
1774        let half = ConstructiveReal::from_rational(1, 2, 8);
1775        let (m, k) = half.get_approx(4);
1776        assert_eq!(m, 8);
1777        assert_eq!(k, 4);
1778    }
1779    #[test]
1780    fn test_bounded_mu_operator() {
1781        let result = bounded_mu(
1782            |n| {
1783                if n > 0 && n % 7 == 0 {
1784                    Some(0)
1785                } else {
1786                    Some(1)
1787                }
1788            },
1789            100,
1790        );
1791        assert_eq!(result, Some(7));
1792    }
1793    #[test]
1794    fn test_markov_search() {
1795        let result = markov_search(|n| n * n > 50, 20);
1796        assert_eq!(result, Some(8));
1797    }
1798    #[test]
1799    fn test_cantor_pairing() {
1800        for a in 0..10u64 {
1801            for b in 0..10u64 {
1802                let n = cantor_pair(a, b);
1803                let (ra, rb) = cantor_unpair(n);
1804                assert_eq!((ra, rb), (a, b), "Cantor pairing failed for ({}, {})", a, b);
1805            }
1806        }
1807    }
1808    #[test]
1809    fn test_decide_bounded_forall_exists() {
1810        assert!(decide_bounded_forall(|x| x + 1 > 0, 10));
1811        assert!(!decide_bounded_forall(|x| x > 5, 10));
1812        assert!(decide_bounded_exists(|x| x * x == 49, 10));
1813        assert!(!decide_bounded_exists(|x| x * x == 49, 5));
1814    }
1815    #[test]
1816    fn test_build_constructive_mathematics_env() {
1817        let mut env = Environment::new();
1818        let result = build_constructive_mathematics_env(&mut env);
1819        assert!(
1820            result.is_ok(),
1821            "build_constructive_mathematics_env failed: {:?}",
1822            result.err()
1823        );
1824    }
1825}