1use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
6
7use super::types::{
8 AlphaEquivalenceChecker, BetaReducer, BinarySession, Context, LinearTypeChecker,
9 SessionTypeCompatibility, SimpleType, Strategy, Term, TypeInferenceSystem,
10};
11
12pub fn app(f: Expr, a: Expr) -> Expr {
13 Expr::App(Box::new(f), Box::new(a))
14}
15pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
16 app(app(f, a), b)
17}
18pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
19 app(app2(f, a, b), c)
20}
21pub fn cst(s: &str) -> Expr {
22 Expr::Const(Name::str(s), vec![])
23}
24pub fn prop() -> Expr {
25 Expr::Sort(Level::zero())
26}
27pub fn type0() -> Expr {
28 Expr::Sort(Level::succ(Level::zero()))
29}
30pub fn type1() -> Expr {
31 Expr::Sort(Level::succ(Level::succ(Level::zero())))
32}
33pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
34 Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
35}
36pub fn arrow(a: Expr, b: Expr) -> Expr {
37 pi(BinderInfo::Default, "_", a, b)
38}
39pub fn impl_pi(name: &str, dom: Expr, body: Expr) -> Expr {
40 pi(BinderInfo::Implicit, name, dom, body)
41}
42pub fn bvar(n: u32) -> Expr {
43 Expr::BVar(n)
44}
45pub fn nat_ty() -> Expr {
46 cst("Nat")
47}
48pub fn bool_ty() -> Expr {
49 cst("Bool")
50}
51pub fn list_ty(elem: Expr) -> Expr {
52 app(cst("List"), elem)
53}
54pub fn option_ty(elem: Expr) -> Expr {
55 app(cst("Option"), elem)
56}
57pub fn untyped_term_ty() -> Expr {
59 type0()
60}
61pub fn variable_ty() -> Expr {
63 arrow(nat_ty(), untyped_term_ty())
64}
65pub fn abstraction_ty() -> Expr {
67 arrow(untyped_term_ty(), untyped_term_ty())
68}
69pub fn application_ty() -> Expr {
71 arrow(
72 untyped_term_ty(),
73 arrow(untyped_term_ty(), untyped_term_ty()),
74 )
75}
76pub fn substitution_ty() -> Expr {
78 arrow(
79 untyped_term_ty(),
80 arrow(untyped_term_ty(), arrow(nat_ty(), untyped_term_ty())),
81 )
82}
83pub fn beta_redex_ty() -> Expr {
85 arrow(untyped_term_ty(), prop())
86}
87pub fn eta_redex_ty() -> Expr {
89 arrow(untyped_term_ty(), prop())
90}
91pub fn beta_step_ty() -> Expr {
93 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop()))
94}
95pub fn eta_step_ty() -> Expr {
97 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop()))
98}
99pub fn beta_reduction_ty() -> Expr {
101 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop()))
102}
103pub fn beta_equiv_ty() -> Expr {
105 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop()))
106}
107pub fn normal_form_ty() -> Expr {
109 arrow(untyped_term_ty(), prop())
110}
111pub fn weak_normal_form_ty() -> Expr {
113 arrow(untyped_term_ty(), prop())
114}
115pub fn head_normal_form_ty() -> Expr {
117 arrow(untyped_term_ty(), prop())
118}
119pub fn church_numeral_ty() -> Expr {
121 arrow(nat_ty(), untyped_term_ty())
122}
123pub fn church_succ_ty() -> Expr {
125 untyped_term_ty()
126}
127pub fn church_plus_ty() -> Expr {
129 untyped_term_ty()
130}
131pub fn church_mul_ty() -> Expr {
133 untyped_term_ty()
134}
135pub fn church_exp_ty() -> Expr {
137 untyped_term_ty()
138}
139pub fn church_pred_ty() -> Expr {
141 untyped_term_ty()
142}
143pub fn church_is_zero_ty() -> Expr {
145 arrow(untyped_term_ty(), bool_ty())
146}
147pub fn church_numeral_correct_ty() -> Expr {
149 arrow(nat_ty(), prop())
150}
151pub fn church_arith_correct_ty() -> Expr {
153 prop()
154}
155pub fn y_combinator_ty() -> Expr {
157 untyped_term_ty()
158}
159pub fn turing_combinator_ty() -> Expr {
161 untyped_term_ty()
162}
163pub fn recursion_theorem_ty() -> Expr {
165 arrow(arrow(untyped_term_ty(), untyped_term_ty()), prop())
166}
167pub fn y_fixed_point_ty() -> Expr {
169 arrow(untyped_term_ty(), prop())
170}
171pub fn omega_combinator_ty() -> Expr {
173 untyped_term_ty()
174}
175pub fn omega_diverges_ty() -> Expr {
177 prop()
178}
179pub fn normal_order_redex_ty() -> Expr {
181 arrow(untyped_term_ty(), option_ty(untyped_term_ty()))
182}
183pub fn applicative_order_redex_ty() -> Expr {
185 arrow(untyped_term_ty(), option_ty(untyped_term_ty()))
186}
187pub fn head_reduction_ty() -> Expr {
189 arrow(untyped_term_ty(), option_ty(untyped_term_ty()))
190}
191pub fn normal_order_strategy_ty() -> Expr {
193 prop()
194}
195pub fn standardization_theorem_ty() -> Expr {
197 prop()
198}
199pub fn cbv_reduction_ty() -> Expr {
201 arrow(untyped_term_ty(), option_ty(untyped_term_ty()))
202}
203pub fn cbn_reduction_ty() -> Expr {
205 arrow(untyped_term_ty(), option_ty(untyped_term_ty()))
206}
207pub fn diamond_property_ty() -> Expr {
209 pi(
210 BinderInfo::Default,
211 "t",
212 untyped_term_ty(),
213 pi(
214 BinderInfo::Default,
215 "u",
216 untyped_term_ty(),
217 pi(BinderInfo::Default, "v", untyped_term_ty(), prop()),
218 ),
219 )
220}
221pub fn church_rosser_theorem_ty() -> Expr {
223 prop()
224}
225pub fn confluence_ty() -> Expr {
227 prop()
228}
229pub fn parallel_reduction_ty() -> Expr {
231 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop()))
232}
233pub fn parallel_reduction_complete_ty() -> Expr {
235 prop()
236}
237pub fn parallel_max_reduct_ty() -> Expr {
239 arrow(untyped_term_ty(), untyped_term_ty())
240}
241pub fn parallel_max_reduct_property_ty() -> Expr {
243 prop()
244}
245pub fn bohm_tree_ty() -> Expr {
247 type0()
248}
249pub fn bohm_tree_of_ty() -> Expr {
251 arrow(untyped_term_ty(), bohm_tree_ty())
252}
253pub fn unsolvable_term_ty() -> Expr {
255 arrow(untyped_term_ty(), prop())
256}
257pub fn solvable_term_ty() -> Expr {
259 arrow(untyped_term_ty(), prop())
260}
261pub fn bohm_equiv_ty() -> Expr {
263 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop()))
264}
265pub fn observational_equiv_ty() -> Expr {
267 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop()))
268}
269pub fn bohm_theorem_ty() -> Expr {
271 prop()
272}
273pub fn simple_type_ty() -> Expr {
275 type0()
276}
277pub fn base_type_ty() -> Expr {
279 arrow(type0(), simple_type_ty())
280}
281pub fn arrow_type_ty() -> Expr {
283 arrow(simple_type_ty(), arrow(simple_type_ty(), simple_type_ty()))
284}
285pub fn typing_context_ty() -> Expr {
287 type0()
288}
289pub fn stlc_typing_ty() -> Expr {
291 arrow(
292 typing_context_ty(),
293 arrow(untyped_term_ty(), arrow(simple_type_ty(), prop())),
294 )
295}
296pub fn stlc_subject_reduction_ty() -> Expr {
298 prop()
299}
300pub fn stlc_strong_normalization_ty() -> Expr {
302 prop()
303}
304pub fn stlc_church_rosser_ty() -> Expr {
306 prop()
307}
308pub fn stlc_decidability_ty() -> Expr {
310 prop()
311}
312pub fn system_f_type_ty() -> Expr {
314 type0()
315}
316pub fn system_f_term_ty() -> Expr {
318 type0()
319}
320pub fn system_f_typing_ty() -> Expr {
322 arrow(
323 typing_context_ty(),
324 arrow(system_f_term_ty(), arrow(system_f_type_ty(), prop())),
325 )
326}
327pub fn system_f_sn_ty() -> Expr {
329 prop()
330}
331pub fn system_f_confluence_ty() -> Expr {
333 prop()
334}
335pub fn system_f_parametricity_ty() -> Expr {
337 prop()
338}
339pub fn system_f_undecidable_ty() -> Expr {
341 prop()
342}
343pub fn church_nat_f_ty() -> Expr {
346 system_f_type_ty()
347}
348pub fn church_bool_f_ty() -> Expr {
351 system_f_type_ty()
352}
353pub fn church_list_f_ty() -> Expr {
356 system_f_type_ty()
357}
358pub fn kind_ty() -> Expr {
360 type0()
361}
362pub fn star_kind_ty() -> Expr {
364 kind_ty()
365}
366pub fn kind_arrow_ty() -> Expr {
368 arrow(kind_ty(), arrow(kind_ty(), kind_ty()))
369}
370pub fn type_constructor_ty() -> Expr {
372 type0()
373}
374pub fn system_fomega_type_ty() -> Expr {
376 type0()
377}
378pub fn system_fomega_term_ty() -> Expr {
380 type0()
381}
382pub fn system_fomega_typing_ty() -> Expr {
384 arrow(
385 typing_context_ty(),
386 arrow(
387 system_fomega_term_ty(),
388 arrow(system_fomega_type_ty(), prop()),
389 ),
390 )
391}
392pub fn system_fomega_sn_ty() -> Expr {
394 prop()
395}
396pub fn system_fomega_kind_soundness_ty() -> Expr {
398 prop()
399}
400pub fn pts_axiom_ty() -> Expr {
402 type0()
403}
404pub fn pts_rule_ty() -> Expr {
406 type0()
407}
408pub fn pure_type_system_ty() -> Expr {
410 type0()
411}
412pub fn pts_typing_ty() -> Expr {
414 arrow(
415 pure_type_system_ty(),
416 arrow(
417 typing_context_ty(),
418 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop())),
419 ),
420 )
421}
422pub fn coc_ty() -> Expr {
424 pure_type_system_ty()
425}
426pub fn lambda_arrow_ty() -> Expr {
428 pure_type_system_ty()
429}
430pub fn lambda2_ty() -> Expr {
432 pure_type_system_ty()
433}
434pub fn lambda_omega_ty() -> Expr {
436 pure_type_system_ty()
437}
438pub fn lambda_p_ty() -> Expr {
440 pure_type_system_ty()
441}
442pub fn pts_subject_reduction_ty() -> Expr {
444 arrow(pure_type_system_ty(), prop())
445}
446pub fn pts_confluence_ty() -> Expr {
448 arrow(pure_type_system_ty(), prop())
449}
450pub fn coc_sn_ty() -> Expr {
452 prop()
453}
454pub fn pcf_type_ty() -> Expr {
457 type0()
458}
459pub fn pcf_term_ty() -> Expr {
461 type0()
462}
463pub fn pcf_fixpoint_ty() -> Expr {
465 pi(
466 BinderInfo::Default,
467 "tau",
468 simple_type_ty(),
469 arrow(arrow(bvar(0), bvar(1)), bvar(0)),
470 )
471}
472pub fn pcf_typing_ty() -> Expr {
474 arrow(
475 typing_context_ty(),
476 arrow(pcf_term_ty(), arrow(pcf_type_ty(), prop())),
477 )
478}
479pub fn pcf_denotational_semantics_ty() -> Expr {
481 prop()
482}
483pub fn pcf_adequacy_ty() -> Expr {
485 prop()
486}
487pub fn pcf_full_abstraction_ty() -> Expr {
489 prop()
490}
491pub fn subtype_relation_ty() -> Expr {
493 arrow(simple_type_ty(), arrow(simple_type_ty(), prop()))
494}
495pub fn subtyping_reflexivity_ty() -> Expr {
497 arrow(simple_type_ty(), prop())
498}
499pub fn subtyping_transitivity_ty() -> Expr {
501 arrow(
502 simple_type_ty(),
503 arrow(simple_type_ty(), arrow(simple_type_ty(), prop())),
504 )
505}
506pub fn bounded_quantification_ty() -> Expr {
508 arrow(
509 simple_type_ty(),
510 arrow(arrow(simple_type_ty(), simple_type_ty()), simple_type_ty()),
511 )
512}
513pub fn f_bounded_polymorphism_ty() -> Expr {
515 arrow(
516 arrow(simple_type_ty(), simple_type_ty()),
517 arrow(arrow(simple_type_ty(), simple_type_ty()), simple_type_ty()),
518 )
519}
520pub fn coercion_function_ty() -> Expr {
522 arrow(simple_type_ty(), arrow(simple_type_ty(), prop()))
523}
524pub fn subtyping_subject_reduction_ty() -> Expr {
526 prop()
527}
528pub fn effect_label_ty() -> Expr {
530 type0()
531}
532pub fn effect_set_ty() -> Expr {
534 type0()
535}
536pub fn effect_type_ty() -> Expr {
538 arrow(simple_type_ty(), arrow(effect_set_ty(), simple_type_ty()))
539}
540pub fn effect_typing_ty() -> Expr {
542 arrow(
543 typing_context_ty(),
544 arrow(
545 untyped_term_ty(),
546 arrow(simple_type_ty(), arrow(effect_set_ty(), prop())),
547 ),
548 )
549}
550pub fn region_type_ty() -> Expr {
552 type0()
553}
554pub fn region_inference_ty() -> Expr {
556 arrow(untyped_term_ty(), region_type_ty())
557}
558pub fn graded_type_ty() -> Expr {
560 type0()
561}
562pub fn coeffect_system_ty() -> Expr {
564 type0()
565}
566pub fn coeffect_typing_ty() -> Expr {
568 arrow(
569 typing_context_ty(),
570 arrow(untyped_term_ty(), arrow(graded_type_ty(), prop())),
571 )
572}
573pub fn linear_type_ty() -> Expr {
575 type0()
576}
577pub fn linear_context_ty() -> Expr {
579 type0()
580}
581pub fn linear_typing_ty() -> Expr {
583 arrow(
584 linear_context_ty(),
585 arrow(untyped_term_ty(), arrow(linear_type_ty(), prop())),
586 )
587}
588pub fn linear_arrow_ty() -> Expr {
590 arrow(linear_type_ty(), arrow(linear_type_ty(), linear_type_ty()))
591}
592pub fn linear_exchangeability_ty() -> Expr {
594 prop()
595}
596pub fn affine_type_ty() -> Expr {
598 type0()
599}
600pub fn affine_typing_ty() -> Expr {
602 arrow(
603 typing_context_ty(),
604 arrow(untyped_term_ty(), arrow(affine_type_ty(), prop())),
605 )
606}
607pub fn relevant_type_ty() -> Expr {
609 type0()
610}
611pub fn relevant_typing_ty() -> Expr {
613 arrow(
614 typing_context_ty(),
615 arrow(untyped_term_ty(), arrow(relevant_type_ty(), prop())),
616 )
617}
618pub fn bang_modality_ty() -> Expr {
620 arrow(linear_type_ty(), linear_type_ty())
621}
622pub fn lf_signature_ty() -> Expr {
624 type0()
625}
626pub fn lf_context_ty() -> Expr {
628 type0()
629}
630pub fn lf_typing_ty() -> Expr {
632 arrow(
633 lf_signature_ty(),
634 arrow(
635 lf_context_ty(),
636 arrow(untyped_term_ty(), arrow(untyped_term_ty(), prop())),
637 ),
638 )
639}
640pub fn lf_kind_validity_ty() -> Expr {
642 arrow(
643 lf_signature_ty(),
644 arrow(lf_context_ty(), arrow(kind_ty(), prop())),
645 )
646}
647pub fn utt_universe_ty() -> Expr {
649 type0()
650}
651pub fn utt_el_type_ty() -> Expr {
653 arrow(utt_universe_ty(), type0())
654}
655pub fn cic_inductive_type_ty() -> Expr {
657 type0()
658}
659pub fn cic_elimination_ty() -> Expr {
661 arrow(cic_inductive_type_ty(), untyped_term_ty())
662}
663pub fn cic_positivity_condition_ty() -> Expr {
665 arrow(cic_inductive_type_ty(), prop())
666}
667pub fn intersection_type_ty() -> Expr {
669 arrow(simple_type_ty(), arrow(simple_type_ty(), simple_type_ty()))
670}
671pub fn intersection_typing_ty() -> Expr {
673 arrow(
674 typing_context_ty(),
675 arrow(untyped_term_ty(), arrow(simple_type_ty(), prop())),
676 )
677}
678pub fn filter_model_ty() -> Expr {
680 type0()
681}
682pub fn intersection_type_completeness_ty() -> Expr {
684 prop()
685}
686pub fn principal_typing_ty() -> Expr {
688 arrow(untyped_term_ty(), prop())
689}
690pub fn union_type_ty() -> Expr {
692 arrow(simple_type_ty(), arrow(simple_type_ty(), simple_type_ty()))
693}
694pub fn occurrence_typing_ty() -> Expr {
696 arrow(
697 typing_context_ty(),
698 arrow(untyped_term_ty(), arrow(simple_type_ty(), prop())),
699 )
700}
701pub fn flow_analysis_ty() -> Expr {
703 arrow(untyped_term_ty(), type0())
704}
705pub fn gradual_type_ty() -> Expr {
707 type0()
708}
709pub fn dyn_type_ty() -> Expr {
711 gradual_type_ty()
712}
713pub fn type_consistency_ty() -> Expr {
715 arrow(gradual_type_ty(), arrow(gradual_type_ty(), prop()))
716}
717pub fn gradual_typing_ty() -> Expr {
719 arrow(
720 typing_context_ty(),
721 arrow(untyped_term_ty(), arrow(gradual_type_ty(), prop())),
722 )
723}
724pub fn blame_label_ty() -> Expr {
726 type0()
727}
728pub fn blame_calculus_term_ty() -> Expr {
730 type0()
731}
732pub fn blame_theorem_ty() -> Expr {
734 prop()
735}
736pub fn abstracting_gradual_typing_ty() -> Expr {
738 prop()
739}
740pub fn session_type_ty() -> Expr {
742 type0()
743}
744pub fn send_type_ty() -> Expr {
746 arrow(
747 simple_type_ty(),
748 arrow(session_type_ty(), session_type_ty()),
749 )
750}
751pub fn recv_type_ty() -> Expr {
753 arrow(
754 simple_type_ty(),
755 arrow(session_type_ty(), session_type_ty()),
756 )
757}
758pub fn end_type_ty() -> Expr {
760 session_type_ty()
761}
762pub fn dual_session_ty() -> Expr {
764 arrow(session_type_ty(), session_type_ty())
765}
766pub fn binary_session_typing_ty() -> Expr {
768 arrow(
769 typing_context_ty(),
770 arrow(untyped_term_ty(), arrow(session_type_ty(), prop())),
771 )
772}
773pub fn multiparty_session_type_ty() -> Expr {
775 type0()
776}
777pub fn global_to_local_ty() -> Expr {
779 arrow(
780 multiparty_session_type_ty(),
781 arrow(nat_ty(), session_type_ty()),
782 )
783}
784pub fn deadlock_freedom_ty() -> Expr {
786 prop()
787}
788pub fn session_type_completeness_ty() -> Expr {
790 prop()
791}
792pub fn recursive_type_ty() -> Expr {
794 arrow(arrow(simple_type_ty(), simple_type_ty()), simple_type_ty())
795}
796pub fn iso_recursive_fold_ty() -> Expr {
798 arrow(
799 arrow(simple_type_ty(), simple_type_ty()),
800 arrow(simple_type_ty(), simple_type_ty()),
801 )
802}
803pub fn iso_recursive_unfold_ty() -> Expr {
805 arrow(
806 arrow(simple_type_ty(), simple_type_ty()),
807 arrow(simple_type_ty(), simple_type_ty()),
808 )
809}
810pub fn equi_recursive_type_ty() -> Expr {
812 arrow(arrow(simple_type_ty(), simple_type_ty()), simple_type_ty())
813}
814pub fn type_unrolling_ty() -> Expr {
816 arrow(arrow(simple_type_ty(), simple_type_ty()), prop())
817}
818pub fn recursive_type_contraction_ty() -> Expr {
820 prop()
821}
822pub fn kind_polymorphism_ty() -> Expr {
824 arrow(arrow(kind_ty(), kind_ty()), kind_ty())
825}
826pub fn higher_kinded_type_ty() -> Expr {
828 arrow(kind_ty(), arrow(kind_ty(), type0()))
829}
830pub fn kind_inference_ty() -> Expr {
832 arrow(system_fomega_type_ty(), option_ty(kind_ty()))
833}
834pub fn kind_soundness_ty() -> Expr {
836 prop()
837}
838pub fn kind_completeness_ty() -> Expr {
840 prop()
841}
842pub fn row_type_ty() -> Expr {
844 type0()
845}
846pub fn extend_row_ty() -> Expr {
848 arrow(
849 nat_ty(),
850 arrow(simple_type_ty(), arrow(row_type_ty(), row_type_ty())),
851 )
852}
853pub fn empty_row_ty() -> Expr {
855 row_type_ty()
856}
857pub fn record_type_ty() -> Expr {
859 arrow(row_type_ty(), simple_type_ty())
860}
861pub fn variant_type_ty() -> Expr {
863 arrow(row_type_ty(), simple_type_ty())
864}
865pub fn row_polymorphic_typing_ty() -> Expr {
867 arrow(
868 typing_context_ty(),
869 arrow(untyped_term_ty(), arrow(row_type_ty(), prop())),
870 )
871}
872pub fn structural_subtyping_ty() -> Expr {
874 arrow(row_type_ty(), arrow(row_type_ty(), prop()))
875}
876pub fn setoid_carrier_ty() -> Expr {
878 type0()
879}
880pub fn setoid_relation_ty() -> Expr {
882 arrow(setoid_carrier_ty(), arrow(setoid_carrier_ty(), prop()))
883}
884pub fn setoid_ty() -> Expr {
886 type0()
887}
888pub fn quotient_type_ty() -> Expr {
890 arrow(setoid_ty(), type0())
891}
892pub fn quotient_intro_ty() -> Expr {
894 arrow(setoid_ty(), arrow(setoid_carrier_ty(), quotient_type_ty()))
895}
896pub fn quotient_elim_ty() -> Expr {
898 arrow(
899 setoid_ty(),
900 arrow(
901 arrow(setoid_carrier_ty(), type0()),
902 arrow(quotient_type_ty(), type0()),
903 ),
904 )
905}
906pub fn quotient_computation_ty() -> Expr {
908 arrow(setoid_ty(), prop())
909}
910pub fn proof_irrelevance_ty() -> Expr {
912 pi(
913 BinderInfo::Default,
914 "P",
915 prop(),
916 pi(
917 BinderInfo::Default,
918 "p",
919 bvar(0),
920 pi(BinderInfo::Default, "q", bvar(1), prop()),
921 ),
922 )
923}
924pub fn irrelevant_argument_ty() -> Expr {
926 arrow(prop(), prop())
927}
928pub fn squash_type_ty() -> Expr {
930 arrow(type0(), prop())
931}
932pub fn squash_intro_ty() -> Expr {
934 arrow(type0(), arrow(type0(), prop()))
935}
936pub fn squash_elim_ty() -> Expr {
938 arrow(prop(), arrow(arrow(type0(), prop()), prop()))
939}
940pub fn universe_level_ty() -> Expr {
942 nat_ty()
943}
944pub fn russell_universe_ty() -> Expr {
946 arrow(universe_level_ty(), type1())
947}
948pub fn tarski_universe_ty() -> Expr {
950 type0()
951}
952pub fn tarski_decode_ty() -> Expr {
954 arrow(tarski_universe_ty(), type0())
955}
956pub fn cumulative_hierarchy_ty() -> Expr {
958 arrow(
959 universe_level_ty(),
960 arrow(tarski_universe_ty(), tarski_universe_ty()),
961 )
962}
963pub fn universe_polymorphism_ty() -> Expr {
965 arrow(arrow(universe_level_ty(), type1()), type1())
966}
967pub fn resizing_axiom_ty() -> Expr {
969 prop()
970}
971pub fn delimited_continuation_ty() -> Expr {
973 arrow(simple_type_ty(), arrow(simple_type_ty(), simple_type_ty()))
974}
975pub fn monadic_type_ty() -> Expr {
977 arrow(
978 arrow(simple_type_ty(), simple_type_ty()),
979 arrow(simple_type_ty(), simple_type_ty()),
980 )
981}
982pub fn monadic_typing_ty() -> Expr {
984 arrow(
985 typing_context_ty(),
986 arrow(
987 untyped_term_ty(),
988 arrow(
989 arrow(simple_type_ty(), simple_type_ty()),
990 arrow(simple_type_ty(), prop()),
991 ),
992 ),
993 )
994}
995pub fn algebraic_effect_type_ty() -> Expr {
997 type0()
998}
999pub fn handler_type_ty() -> Expr {
1001 arrow(
1002 algebraic_effect_type_ty(),
1003 arrow(simple_type_ty(), simple_type_ty()),
1004 )
1005}
1006pub fn dependent_session_type_ty() -> Expr {
1008 type0()
1009}
1010pub fn refinement_type_ty() -> Expr {
1012 arrow(
1013 simple_type_ty(),
1014 arrow(arrow(simple_type_ty(), prop()), simple_type_ty()),
1015 )
1016}
1017pub fn liquid_type_ty() -> Expr {
1019 arrow(
1020 simple_type_ty(),
1021 arrow(arrow(simple_type_ty(), bool_ty()), simple_type_ty()),
1022 )
1023}
1024pub fn nominal_type_ty() -> Expr {
1026 type0()
1027}
1028pub fn freshness_predicate_ty() -> Expr {
1030 arrow(nat_ty(), arrow(untyped_term_ty(), prop()))
1031}
1032pub fn abstraction_nominal_ty() -> Expr {
1034 arrow(nat_ty(), arrow(untyped_term_ty(), nominal_type_ty()))
1035}
1036pub fn build_lambda_calculus_env() -> Environment {
1038 let mut env = Environment::new();
1039 let axioms: &[(&str, Expr)] = &[
1040 ("UntypedTerm", untyped_term_ty()),
1041 ("LcVariable", variable_ty()),
1042 ("LcAbstraction", abstraction_ty()),
1043 ("LcApplication", application_ty()),
1044 ("LcSubstitution", substitution_ty()),
1045 ("BetaRedex", beta_redex_ty()),
1046 ("EtaRedex", eta_redex_ty()),
1047 ("BetaStep", beta_step_ty()),
1048 ("EtaStep", eta_step_ty()),
1049 ("BetaReduction", beta_reduction_ty()),
1050 ("BetaEquiv", beta_equiv_ty()),
1051 ("NormalForm", normal_form_ty()),
1052 ("WeakNormalForm", weak_normal_form_ty()),
1053 ("HeadNormalForm", head_normal_form_ty()),
1054 ("ChurchNumeral", church_numeral_ty()),
1055 ("ChurchSucc", church_succ_ty()),
1056 ("ChurchPlus", church_plus_ty()),
1057 ("ChurchMul", church_mul_ty()),
1058 ("ChurchExp", church_exp_ty()),
1059 ("ChurchPred", church_pred_ty()),
1060 ("ChurchIsZero", church_is_zero_ty()),
1061 ("ChurchNumeralCorrect", church_numeral_correct_ty()),
1062 ("ChurchArithCorrect", church_arith_correct_ty()),
1063 ("YCombinator", y_combinator_ty()),
1064 ("TuringCombinator", turing_combinator_ty()),
1065 ("RecursionTheorem", recursion_theorem_ty()),
1066 ("YFixedPoint", y_fixed_point_ty()),
1067 ("OmegaCombinator", omega_combinator_ty()),
1068 ("OmegaDiverges", omega_diverges_ty()),
1069 ("NormalOrderRedex", normal_order_redex_ty()),
1070 ("ApplicativeOrderRedex", applicative_order_redex_ty()),
1071 ("HeadReduction", head_reduction_ty()),
1072 ("NormalOrderStrategy", normal_order_strategy_ty()),
1073 ("StandardizationTheorem", standardization_theorem_ty()),
1074 ("CallByValueReduction", cbv_reduction_ty()),
1075 ("CallByNeedReduction", cbn_reduction_ty()),
1076 ("DiamondProperty", diamond_property_ty()),
1077 ("ChurchRosserTheorem", church_rosser_theorem_ty()),
1078 ("Confluence", confluence_ty()),
1079 ("ParallelReduction", parallel_reduction_ty()),
1080 (
1081 "ParallelReductionComplete",
1082 parallel_reduction_complete_ty(),
1083 ),
1084 ("ParallelMaxReduct", parallel_max_reduct_ty()),
1085 (
1086 "ParallelMaxReductProperty",
1087 parallel_max_reduct_property_ty(),
1088 ),
1089 ("BohmTree", bohm_tree_ty()),
1090 ("BohmTreeOf", bohm_tree_of_ty()),
1091 ("UnsolvableTerm", unsolvable_term_ty()),
1092 ("SolvableTerm", solvable_term_ty()),
1093 ("BohmEquiv", bohm_equiv_ty()),
1094 ("ObservationalEquiv", observational_equiv_ty()),
1095 ("BohmTheorem", bohm_theorem_ty()),
1096 ("SimpleType", simple_type_ty()),
1097 ("BaseType", base_type_ty()),
1098 ("ArrowType", arrow_type_ty()),
1099 ("TypingContext", typing_context_ty()),
1100 ("STLCTyping", stlc_typing_ty()),
1101 ("STLCSubjectReduction", stlc_subject_reduction_ty()),
1102 ("STLCStrongNormalization", stlc_strong_normalization_ty()),
1103 ("STLCChurchRosser", stlc_church_rosser_ty()),
1104 ("STLCDecidability", stlc_decidability_ty()),
1105 ("SystemFType", system_f_type_ty()),
1106 ("SystemFTerm", system_f_term_ty()),
1107 ("SystemFTyping", system_f_typing_ty()),
1108 ("SystemFStrongNormalization", system_f_sn_ty()),
1109 ("SystemFConfluence", system_f_confluence_ty()),
1110 ("SystemFParametricity", system_f_parametricity_ty()),
1111 ("SystemFUndecidableTyping", system_f_undecidable_ty()),
1112 ("ChurchNatF", church_nat_f_ty()),
1113 ("ChurchBoolF", church_bool_f_ty()),
1114 ("ChurchListF", church_list_f_ty()),
1115 ("Kind", kind_ty()),
1116 ("StarKind", star_kind_ty()),
1117 ("KindArrow", kind_arrow_ty()),
1118 ("TypeConstructor", type_constructor_ty()),
1119 ("SystemFOmegaType", system_fomega_type_ty()),
1120 ("SystemFOmegaTerm", system_fomega_term_ty()),
1121 ("SystemFOmegaTyping", system_fomega_typing_ty()),
1122 ("SystemFOmegaSN", system_fomega_sn_ty()),
1123 (
1124 "SystemFOmegaKindSoundness",
1125 system_fomega_kind_soundness_ty(),
1126 ),
1127 ("PTSAxiom", pts_axiom_ty()),
1128 ("PTSRule", pts_rule_ty()),
1129 ("PureTypeSystem", pure_type_system_ty()),
1130 ("PTSTyping", pts_typing_ty()),
1131 ("CoC", coc_ty()),
1132 ("LambdaArrow", lambda_arrow_ty()),
1133 ("Lambda2", lambda2_ty()),
1134 ("LambdaOmega", lambda_omega_ty()),
1135 ("LambdaP", lambda_p_ty()),
1136 ("PTSSubjectReduction", pts_subject_reduction_ty()),
1137 ("PTSConfluence", pts_confluence_ty()),
1138 ("CoCStrongNormalization", coc_sn_ty()),
1139 ("PCFType", pcf_type_ty()),
1140 ("PCFTerm", pcf_term_ty()),
1141 ("PCFFixpoint", pcf_fixpoint_ty()),
1142 ("PCFTyping", pcf_typing_ty()),
1143 ("PCFDenotationalSemantics", pcf_denotational_semantics_ty()),
1144 ("PCFAdequacy", pcf_adequacy_ty()),
1145 ("PCFFullAbstraction", pcf_full_abstraction_ty()),
1146 ("SubtypeRelation", subtype_relation_ty()),
1147 ("SubtypingReflexivity", subtyping_reflexivity_ty()),
1148 ("SubtypingTransitivity", subtyping_transitivity_ty()),
1149 ("BoundedQuantification", bounded_quantification_ty()),
1150 ("FBoundedPolymorphism", f_bounded_polymorphism_ty()),
1151 ("CoercionFunction", coercion_function_ty()),
1152 (
1153 "SubtypingSubjectReduction",
1154 subtyping_subject_reduction_ty(),
1155 ),
1156 ("EffectLabel", effect_label_ty()),
1157 ("EffectSet", effect_set_ty()),
1158 ("EffectType", effect_type_ty()),
1159 ("EffectTyping", effect_typing_ty()),
1160 ("RegionType", region_type_ty()),
1161 ("RegionInference", region_inference_ty()),
1162 ("GradedType", graded_type_ty()),
1163 ("CoeffectSystem", coeffect_system_ty()),
1164 ("CoeffectTyping", coeffect_typing_ty()),
1165 ("LinearType", linear_type_ty()),
1166 ("LinearContext", linear_context_ty()),
1167 ("LinearTyping", linear_typing_ty()),
1168 ("LinearArrow", linear_arrow_ty()),
1169 ("LinearExchangeability", linear_exchangeability_ty()),
1170 ("AffineType", affine_type_ty()),
1171 ("AffineTyping", affine_typing_ty()),
1172 ("RelevantType", relevant_type_ty()),
1173 ("RelevantTyping", relevant_typing_ty()),
1174 ("BangModality", bang_modality_ty()),
1175 ("LFSignature", lf_signature_ty()),
1176 ("LFContext", lf_context_ty()),
1177 ("LFTyping", lf_typing_ty()),
1178 ("LFKindValidity", lf_kind_validity_ty()),
1179 ("UTTUniverse", utt_universe_ty()),
1180 ("UTTELType", utt_el_type_ty()),
1181 ("CICInductiveType", cic_inductive_type_ty()),
1182 ("CICElimination", cic_elimination_ty()),
1183 ("CICPositivityCondition", cic_positivity_condition_ty()),
1184 ("IntersectionType", intersection_type_ty()),
1185 ("IntersectionTyping", intersection_typing_ty()),
1186 ("FilterModel", filter_model_ty()),
1187 (
1188 "IntersectionTypeCompleteness",
1189 intersection_type_completeness_ty(),
1190 ),
1191 ("PrincipalTyping", principal_typing_ty()),
1192 ("UnionType", union_type_ty()),
1193 ("OccurrenceTyping", occurrence_typing_ty()),
1194 ("FlowAnalysis", flow_analysis_ty()),
1195 ("GradualType", gradual_type_ty()),
1196 ("DynType", dyn_type_ty()),
1197 ("TypeConsistency", type_consistency_ty()),
1198 ("GradualTyping", gradual_typing_ty()),
1199 ("BlameLabel", blame_label_ty()),
1200 ("BlameCalculusTerm", blame_calculus_term_ty()),
1201 ("BlameTheorem", blame_theorem_ty()),
1202 ("AbstractingGradualTyping", abstracting_gradual_typing_ty()),
1203 ("SessionType", session_type_ty()),
1204 ("SendType", send_type_ty()),
1205 ("RecvType", recv_type_ty()),
1206 ("EndType", end_type_ty()),
1207 ("DualSession", dual_session_ty()),
1208 ("BinarySessionTyping", binary_session_typing_ty()),
1209 ("MultipartySessionType", multiparty_session_type_ty()),
1210 ("GlobalToLocal", global_to_local_ty()),
1211 ("DeadlockFreedom", deadlock_freedom_ty()),
1212 ("SessionTypeCompleteness", session_type_completeness_ty()),
1213 ("RecursiveType", recursive_type_ty()),
1214 ("IsoRecursiveFold", iso_recursive_fold_ty()),
1215 ("IsoRecursiveUnfold", iso_recursive_unfold_ty()),
1216 ("EquiRecursiveType", equi_recursive_type_ty()),
1217 ("TypeUnrolling", type_unrolling_ty()),
1218 ("RecursiveTypeContraction", recursive_type_contraction_ty()),
1219 ("KindPolymorphism", kind_polymorphism_ty()),
1220 ("HigherKindedType", higher_kinded_type_ty()),
1221 ("KindInference", kind_inference_ty()),
1222 ("KindSoundness", kind_soundness_ty()),
1223 ("KindCompleteness", kind_completeness_ty()),
1224 ("RowType", row_type_ty()),
1225 ("ExtendRow", extend_row_ty()),
1226 ("EmptyRow", empty_row_ty()),
1227 ("RecordType", record_type_ty()),
1228 ("VariantType", variant_type_ty()),
1229 ("RowPolymorphicTyping", row_polymorphic_typing_ty()),
1230 ("StructuralSubtyping", structural_subtyping_ty()),
1231 ("SetoidCarrier", setoid_carrier_ty()),
1232 ("SetoidRelation", setoid_relation_ty()),
1233 ("Setoid", setoid_ty()),
1234 ("QuotientType", quotient_type_ty()),
1235 ("QuotientIntro", quotient_intro_ty()),
1236 ("QuotientElim", quotient_elim_ty()),
1237 ("QuotientComputation", quotient_computation_ty()),
1238 ("ProofIrrelevance", proof_irrelevance_ty()),
1239 ("IrrelevantArgument", irrelevant_argument_ty()),
1240 ("SquashType", squash_type_ty()),
1241 ("SquashIntro", squash_intro_ty()),
1242 ("SquashElim", squash_elim_ty()),
1243 ("UniverseLevel", universe_level_ty()),
1244 ("RussellUniverse", russell_universe_ty()),
1245 ("TarskiUniverse", tarski_universe_ty()),
1246 ("TarskiDecode", tarski_decode_ty()),
1247 ("CumulativeHierarchy", cumulative_hierarchy_ty()),
1248 ("UniversePolymorphism", universe_polymorphism_ty()),
1249 ("ResizingAxiom", resizing_axiom_ty()),
1250 ("DelimitedContinuation", delimited_continuation_ty()),
1251 ("MonadicType", monadic_type_ty()),
1252 ("MonadicTyping", monadic_typing_ty()),
1253 ("AlgebraicEffectType", algebraic_effect_type_ty()),
1254 ("HandlerType", handler_type_ty()),
1255 ("DependentSessionType", dependent_session_type_ty()),
1256 ("RefinementType", refinement_type_ty()),
1257 ("LiquidType", liquid_type_ty()),
1258 ("NominalType", nominal_type_ty()),
1259 ("FreshnessPredicate", freshness_predicate_ty()),
1260 ("AbstractionNominal", abstraction_nominal_ty()),
1261 ];
1262 for (name, ty) in axioms {
1263 env.add(Declaration::Axiom {
1264 name: Name::str(*name),
1265 univ_params: vec![],
1266 ty: ty.clone(),
1267 })
1268 .ok();
1269 }
1270 env
1271}
1272pub fn church(n: usize) -> Term {
1275 let x = Term::Var(0);
1276 let f = Term::Var(1);
1277 let mut body = x;
1278 for _ in 0..n {
1279 body = Term::App(Box::new(f.clone()), Box::new(body));
1280 }
1281 Term::Lam(Box::new(Term::Lam(Box::new(body))))
1282}
1283pub fn church_succ() -> Term {
1285 let n = Term::Var(2);
1286 let f = Term::Var(1);
1287 let x = Term::Var(0);
1288 let nfx = Term::App(
1289 Box::new(Term::App(Box::new(n), Box::new(f.clone()))),
1290 Box::new(x),
1291 );
1292 let body = Term::App(Box::new(f), Box::new(nfx));
1293 Term::Lam(Box::new(Term::Lam(Box::new(Term::Lam(Box::new(body))))))
1294}
1295pub fn church_plus() -> Term {
1297 let m = Term::Var(3);
1298 let n = Term::Var(2);
1299 let f = Term::Var(1);
1300 let x = Term::Var(0);
1301 let nfx = Term::App(
1302 Box::new(Term::App(Box::new(n), Box::new(f.clone()))),
1303 Box::new(x),
1304 );
1305 let body = Term::App(Box::new(Term::App(Box::new(m), Box::new(f))), Box::new(nfx));
1306 Term::Lam(Box::new(Term::Lam(Box::new(Term::Lam(Box::new(
1307 Term::Lam(Box::new(body)),
1308 ))))))
1309}
1310pub fn church_mul() -> Term {
1312 let m = Term::Var(2);
1313 let n = Term::Var(1);
1314 let f = Term::Var(0);
1315 let nf = Term::App(Box::new(n), Box::new(f));
1316 let body = Term::App(Box::new(m), Box::new(nf));
1317 Term::Lam(Box::new(Term::Lam(Box::new(Term::Lam(Box::new(body))))))
1318}
1319pub fn church_add(m: usize, n: usize) -> Term {
1321 let plus = church_plus();
1322 let cm = church(m);
1323 let cn = church(n);
1324 let applied = Term::App(
1325 Box::new(Term::App(Box::new(plus), Box::new(cm))),
1326 Box::new(cn),
1327 );
1328 let (result, _) = applied.normalize(10000);
1329 result
1330}
1331pub fn infer_type(ctx: &Context, term: &Term) -> Option<SimpleType> {
1334 match term {
1335 Term::Var(k) => ctx.get(*k).cloned(),
1336 Term::Lam(body) => {
1337 let _ = body;
1338 None
1339 }
1340 Term::App(f, a) => match infer_type(ctx, f)? {
1341 SimpleType::Arrow(dom, cod) => {
1342 if check_type(ctx, a, &dom) {
1343 Some(*cod)
1344 } else {
1345 None
1346 }
1347 }
1348 _ => None,
1349 },
1350 }
1351}
1352pub fn check_type(ctx: &Context, term: &Term, ty: &SimpleType) -> bool {
1355 match (term, ty) {
1356 (Term::Lam(body), SimpleType::Arrow(dom, cod)) => {
1357 let ctx2 = ctx.extend(*dom.clone());
1358 check_type(&ctx2, body, cod)
1359 }
1360 (Term::App(f, a), _) => {
1361 if let Some(ft) = infer_type(ctx, f) {
1362 match ft {
1363 SimpleType::Arrow(dom, cod) => *cod == *ty && check_type(ctx, a, &dom),
1364 _ => false,
1365 }
1366 } else {
1367 false
1368 }
1369 }
1370 (Term::Var(k), _) => ctx.get(*k).map(|t| t == ty).unwrap_or(false),
1371 _ => false,
1372 }
1373}
1374pub fn beta_step(term: &Term, strategy: Strategy) -> Option<Term> {
1376 match strategy {
1377 Strategy::NormalOrder => term.beta_step_normal(),
1378 Strategy::ApplicativeOrder => beta_step_applicative(term),
1379 Strategy::HeadReduction => beta_step_head(term),
1380 }
1381}
1382pub fn beta_step_applicative(term: &Term) -> Option<Term> {
1383 match term {
1384 Term::App(f, a) => {
1385 if let Some(a2) = beta_step_applicative(a) {
1386 return Some(Term::App(f.clone(), Box::new(a2)));
1387 }
1388 if let Some(f2) = beta_step_applicative(f) {
1389 return Some(Term::App(Box::new(f2), a.clone()));
1390 }
1391 if let Term::Lam(body) = f.as_ref() {
1392 return Some(body.subst(0, a));
1393 }
1394 None
1395 }
1396 Term::Lam(body) => beta_step_applicative(body).map(|b2| Term::Lam(Box::new(b2))),
1397 Term::Var(_) => None,
1398 }
1399}
1400pub fn beta_step_head(term: &Term) -> Option<Term> {
1401 match term {
1402 Term::App(f, a) => {
1403 if let Term::Lam(body) = f.as_ref() {
1404 return Some(body.subst(0, a));
1405 }
1406 beta_step_head(f).map(|f2| Term::App(Box::new(f2), a.clone()))
1407 }
1408 Term::Lam(body) => beta_step_head(body).map(|b2| Term::Lam(Box::new(b2))),
1409 Term::Var(_) => None,
1410 }
1411}
1412#[allow(dead_code)]
1414pub type UsageMap = Vec<usize>;
1415#[cfg(test)]
1416mod tests {
1417 use super::*;
1418 #[test]
1420 fn test_build_lambda_calculus_env() {
1421 let env = build_lambda_calculus_env();
1422 assert!(env.get(&Name::str("UntypedTerm")).is_some());
1423 assert!(env.get(&Name::str("YCombinator")).is_some());
1424 assert!(env.get(&Name::str("ChurchRosserTheorem")).is_some());
1425 assert!(env.get(&Name::str("SystemFStrongNormalization")).is_some());
1426 assert!(env.get(&Name::str("CoC")).is_some());
1427 assert!(env.get(&Name::str("BohmTheorem")).is_some());
1428 }
1429 #[test]
1431 fn test_church_numerals() {
1432 let c0 = church(0);
1433 assert_eq!(c0, Term::Lam(Box::new(Term::Lam(Box::new(Term::Var(0))))));
1434 let c1 = church(1);
1435 assert_eq!(
1436 c1,
1437 Term::Lam(Box::new(Term::Lam(Box::new(Term::App(
1438 Box::new(Term::Var(1)),
1439 Box::new(Term::Var(0))
1440 )))))
1441 );
1442 let c2 = church(2);
1443 assert!(c2.is_normal());
1444 }
1445 #[test]
1447 fn test_church_addition() {
1448 let result = church_add(2, 3);
1449 let expected = church(5);
1450 let (rn, _) = result.normalize(10000);
1451 let (en, _) = expected.normalize(10000);
1452 assert_eq!(rn, en);
1453 }
1454 #[test]
1456 fn test_identity_reduction() {
1457 let id = Term::Lam(Box::new(Term::Var(0)));
1458 let arg = Term::Var(0);
1459 let redex = Term::App(Box::new(id), Box::new(arg.clone()));
1460 let (result, steps) = redex.normalize(100);
1461 assert!(steps > 0);
1462 assert!(result.is_normal());
1463 }
1464 #[test]
1466 fn test_is_normal() {
1467 assert!(Term::Var(0).is_normal());
1468 assert!(Term::Lam(Box::new(Term::Var(0))).is_normal());
1469 let redex = Term::App(
1470 Box::new(Term::Lam(Box::new(Term::Var(0)))),
1471 Box::new(Term::Var(1)),
1472 );
1473 assert!(!redex.is_normal());
1474 }
1475 #[test]
1477 fn test_stlc_identity() {
1478 let alpha = SimpleType::Base("α".into());
1479 let id = Term::Lam(Box::new(Term::Var(0)));
1480 let arrow_ty = SimpleType::arr(alpha.clone(), alpha.clone());
1481 let ctx = Context::empty();
1482 assert!(check_type(&ctx, &id, &arrow_ty));
1483 }
1484 #[test]
1486 fn test_stlc_k_combinator() {
1487 let alpha = SimpleType::Base("α".into());
1488 let beta = SimpleType::Base("β".into());
1489 let k = Term::Lam(Box::new(Term::Lam(Box::new(Term::Var(1)))));
1490 let ty = SimpleType::arr(alpha.clone(), SimpleType::arr(beta.clone(), alpha.clone()));
1491 let ctx = Context::empty();
1492 assert!(check_type(&ctx, &k, &ty));
1493 }
1494 #[test]
1496 fn test_reduction_strategies() {
1497 let id = || Term::Lam(Box::new(Term::Var(0)));
1498 let t = Term::App(
1499 Box::new(id()),
1500 Box::new(Term::App(Box::new(id()), Box::new(Term::Var(1)))),
1501 );
1502 assert!(!t.is_normal());
1503 let step_no = beta_step(&t, Strategy::NormalOrder);
1504 assert!(step_no.is_some());
1505 let step_ao = beta_step(&t, Strategy::ApplicativeOrder);
1506 assert!(step_ao.is_some());
1507 }
1508 #[test]
1510 fn test_church_size() {
1511 assert_eq!(church(0).size(), 3);
1512 assert_eq!(church(1).size(), 5);
1513 let c3 = church(3);
1514 assert_eq!(c3.size(), 2 * 3 + 3);
1515 }
1516 #[test]
1518 fn test_new_axioms_registered() {
1519 let env = build_lambda_calculus_env();
1520 assert!(env.get(&Name::str("PCFFixpoint")).is_some());
1521 assert!(env.get(&Name::str("PCFAdequacy")).is_some());
1522 assert!(env.get(&Name::str("BoundedQuantification")).is_some());
1523 assert!(env.get(&Name::str("FBoundedPolymorphism")).is_some());
1524 assert!(env.get(&Name::str("CoeffectSystem")).is_some());
1525 assert!(env.get(&Name::str("RegionInference")).is_some());
1526 assert!(env.get(&Name::str("LinearTyping")).is_some());
1527 assert!(env.get(&Name::str("BangModality")).is_some());
1528 assert!(env.get(&Name::str("AffineTyping")).is_some());
1529 assert!(env.get(&Name::str("LFTyping")).is_some());
1530 assert!(env.get(&Name::str("CICInductiveType")).is_some());
1531 assert!(env.get(&Name::str("FilterModel")).is_some());
1532 assert!(env.get(&Name::str("PrincipalTyping")).is_some());
1533 assert!(env.get(&Name::str("FlowAnalysis")).is_some());
1534 assert!(env.get(&Name::str("TypeConsistency")).is_some());
1535 assert!(env.get(&Name::str("BlameTheorem")).is_some());
1536 assert!(env.get(&Name::str("DualSession")).is_some());
1537 assert!(env.get(&Name::str("DeadlockFreedom")).is_some());
1538 assert!(env.get(&Name::str("MultipartySessionType")).is_some());
1539 assert!(env.get(&Name::str("IsoRecursiveFold")).is_some());
1540 assert!(env.get(&Name::str("TypeUnrolling")).is_some());
1541 assert!(env.get(&Name::str("KindPolymorphism")).is_some());
1542 assert!(env.get(&Name::str("HigherKindedType")).is_some());
1543 assert!(env.get(&Name::str("RecordType")).is_some());
1544 assert!(env.get(&Name::str("StructuralSubtyping")).is_some());
1545 assert!(env.get(&Name::str("QuotientType")).is_some());
1546 assert!(env.get(&Name::str("QuotientElim")).is_some());
1547 assert!(env.get(&Name::str("ProofIrrelevance")).is_some());
1548 assert!(env.get(&Name::str("SquashType")).is_some());
1549 assert!(env.get(&Name::str("RussellUniverse")).is_some());
1550 assert!(env.get(&Name::str("CumulativeHierarchy")).is_some());
1551 assert!(env.get(&Name::str("RefinementType")).is_some());
1552 assert!(env.get(&Name::str("NominalType")).is_some());
1553 assert!(env.get(&Name::str("AlgebraicEffectType")).is_some());
1554 }
1555 #[test]
1556 fn test_beta_reducer_converges() {
1557 let reducer = BetaReducer::new(Strategy::NormalOrder, 1000);
1558 let id = Term::Lam(Box::new(Term::Var(0)));
1559 let t = Term::App(Box::new(id), Box::new(Term::Var(0)));
1560 let (result, steps, converged) = reducer.reduce(&t);
1561 assert!(converged);
1562 assert!(steps >= 1);
1563 assert!(reducer.is_normal_form(&result));
1564 }
1565 #[test]
1566 fn test_beta_reducer_step_count() {
1567 let reducer = BetaReducer::new(Strategy::NormalOrder, 10000);
1568 let one_plus_one = church_add(1, 1);
1569 let steps_opt = reducer.count_steps(&one_plus_one);
1570 assert!(steps_opt.is_some());
1571 }
1572 #[test]
1573 fn test_alpha_equiv_identical() {
1574 let checker = AlphaEquivalenceChecker::new();
1575 let t = Term::Lam(Box::new(Term::Var(0)));
1576 assert!(checker.alpha_equiv(&t, &t));
1577 }
1578 #[test]
1579 fn test_alpha_equiv_different() {
1580 let checker = AlphaEquivalenceChecker::new();
1581 let t1 = Term::Lam(Box::new(Term::Var(0)));
1582 let t2 = Term::Lam(Box::new(Term::Var(1)));
1583 assert!(!checker.alpha_equiv(&t1, &t2));
1584 }
1585 #[test]
1586 fn test_alpha_equiv_normalized() {
1587 let checker = AlphaEquivalenceChecker::new();
1588 let id = Term::Lam(Box::new(Term::Var(0)));
1589 let t = Term::App(Box::new(id), Box::new(Term::Var(1)));
1590 let expected = Term::Var(1);
1591 assert!(checker.alpha_equiv_normalized(&t, &expected, 100));
1592 }
1593 #[test]
1594 fn test_type_inference_var() {
1595 let system = TypeInferenceSystem::new();
1596 let alpha = SimpleType::Base("α".into());
1597 let ctx = Context(vec![alpha.clone()]);
1598 assert_eq!(system.synthesize(&ctx, &Term::Var(0)), Some(alpha));
1599 }
1600 #[test]
1601 fn test_type_inference_app() {
1602 let system = TypeInferenceSystem::new();
1603 let alpha = SimpleType::Base("α".into());
1604 let beta = SimpleType::Base("β".into());
1605 let ctx = Context(vec![
1606 alpha.clone(),
1607 SimpleType::arr(alpha.clone(), beta.clone()),
1608 ]);
1609 let term = Term::App(Box::new(Term::Var(1)), Box::new(Term::Var(0)));
1610 assert_eq!(system.synthesize(&ctx, &term), Some(beta));
1611 }
1612 #[test]
1613 fn test_type_check_identity() {
1614 let system = TypeInferenceSystem::new();
1615 let alpha = SimpleType::Base("α".into());
1616 let id = Term::Lam(Box::new(Term::Var(0)));
1617 let ctx = Context::empty();
1618 assert!(system.check(&ctx, &id, &SimpleType::arr(alpha.clone(), alpha)));
1619 }
1620 #[test]
1621 fn test_type_inference_with_hint() {
1622 let system = TypeInferenceSystem::new();
1623 let alpha = SimpleType::Base("α".into());
1624 let id = Term::Lam(Box::new(Term::Var(0)));
1625 let ty = SimpleType::arr(alpha.clone(), alpha);
1626 let ctx = Context::empty();
1627 let result = system.infer_with_annotation(&ctx, &id, Some(&ty));
1628 assert!(result.is_some());
1629 }
1630 #[test]
1631 fn test_linear_identity_is_linear() {
1632 let checker = LinearTypeChecker::new();
1633 let id = Term::Lam(Box::new(Term::Var(0)));
1634 let uses = checker.count_uses(&id, 0);
1635 assert!(uses.is_empty());
1636 let uses_body = checker.count_uses(&Term::Var(0), 1);
1637 assert_eq!(uses_body, vec![1]);
1638 }
1639 #[test]
1640 fn test_linear_k_combinator_is_not_linear() {
1641 let checker = LinearTypeChecker::new();
1642 let body = Term::Var(1);
1643 let uses = checker.count_uses(&body, 2);
1644 assert_eq!(uses, vec![0, 1]);
1645 assert!(!checker.is_linear(&body, 2));
1646 assert!(checker.is_affine(&body, 2));
1647 }
1648 #[test]
1649 fn test_affine_vs_relevant() {
1650 let checker = LinearTypeChecker::new();
1651 let body = Term::App(
1652 Box::new(Term::App(Box::new(Term::Var(1)), Box::new(Term::Var(0)))),
1653 Box::new(Term::Var(0)),
1654 );
1655 let uses = checker.count_uses(&body, 2);
1656 assert_eq!(uses, vec![2, 1]);
1657 assert!(!checker.is_linear(&body, 2));
1658 assert!(!checker.is_affine(&body, 2));
1659 assert!(checker.is_relevant(&body, 2));
1660 }
1661 #[test]
1662 fn test_session_dual_send_recv() {
1663 let compat = SessionTypeCompatibility::new();
1664 let s = BinarySession::Send("Int".into(), Box::new(BinarySession::End));
1665 let dual = compat.dual(&s);
1666 assert_eq!(
1667 dual,
1668 BinarySession::Recv("Int".into(), Box::new(BinarySession::End))
1669 );
1670 }
1671 #[test]
1672 fn test_session_dual_involutive() {
1673 let compat = SessionTypeCompatibility::new();
1674 let s = BinarySession::Send(
1675 "Bool".into(),
1676 Box::new(BinarySession::Recv(
1677 "Int".into(),
1678 Box::new(BinarySession::End),
1679 )),
1680 );
1681 let d = compat.dual(&compat.dual(&s));
1682 assert_eq!(d, s);
1683 }
1684 #[test]
1685 fn test_session_compatible_send_recv() {
1686 let compat = SessionTypeCompatibility::new();
1687 let s1 = BinarySession::Send("Int".into(), Box::new(BinarySession::End));
1688 let s2 = BinarySession::Recv("Int".into(), Box::new(BinarySession::End));
1689 assert!(compat.compatible(&s1, &s2));
1690 assert!(compat.compatible(&s2, &s1));
1691 }
1692 #[test]
1693 fn test_session_incompatible_type_mismatch() {
1694 let compat = SessionTypeCompatibility::new();
1695 let s1 = BinarySession::Send("Int".into(), Box::new(BinarySession::End));
1696 let s2 = BinarySession::Recv("Bool".into(), Box::new(BinarySession::End));
1697 assert!(!compat.compatible(&s1, &s2));
1698 }
1699 #[test]
1700 fn test_session_compatible_end_end() {
1701 let compat = SessionTypeCompatibility::new();
1702 assert!(compat.compatible(&BinarySession::End, &BinarySession::End));
1703 }
1704 #[test]
1705 fn test_session_are_dual() {
1706 let compat = SessionTypeCompatibility::new();
1707 let s1 = BinarySession::Send("Nat".into(), Box::new(BinarySession::End));
1708 let s2 = BinarySession::Recv("Nat".into(), Box::new(BinarySession::End));
1709 assert!(compat.are_dual(&s1, &s2));
1710 assert!(compat.are_dual(&s2, &s1));
1711 assert!(!compat.are_dual(&s1, &s1));
1712 }
1713 #[test]
1714 fn test_session_select_offer_compatible() {
1715 let compat = SessionTypeCompatibility::new();
1716 let s1 = BinarySession::Select(vec![
1717 ("ok".into(), BinarySession::End),
1718 ("err".into(), BinarySession::End),
1719 ]);
1720 let s2 = BinarySession::Offer(vec![
1721 ("ok".into(), BinarySession::End),
1722 ("err".into(), BinarySession::End),
1723 ]);
1724 assert!(compat.compatible(&s1, &s2));
1725 }
1726}