1use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
6
7use super::types::{
8 AdditiveConj, AlgebraicDomain, BanachFixedPoint, BifiniteApproximation, CoherenceSpace,
9 ContinuousDomain, ContinuousLattice, Denotation, DenotationalSoundness, DomainEqn,
10 DomainEquation, EnvironmentModel, ExponentialModality, IdealCompletion, InformationSystem,
11 KleeneFixedPoint, LinearArrow, LinearType, MultiplicativeConj, OperationalEquivalence,
12 Powerdomain, PrimeEventStructure, ProofNet, ScottContinuousFunction, ScottDomain, ScottOpenSet,
13 SemanticDomain, StableFunction, DCPO,
14};
15
16pub fn app(f: Expr, a: Expr) -> Expr {
17 Expr::App(Box::new(f), Box::new(a))
18}
19pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
20 app(app(f, a), b)
21}
22pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
23 app(app2(f, a, b), c)
24}
25pub fn app4(f: Expr, a: Expr, b: Expr, c: Expr, d: Expr) -> Expr {
26 app(app3(f, a, b, c), d)
27}
28pub fn cst(s: &str) -> Expr {
29 Expr::Const(Name::str(s), vec![])
30}
31pub fn prop() -> Expr {
32 Expr::Sort(Level::zero())
33}
34pub fn type0() -> Expr {
35 Expr::Sort(Level::succ(Level::zero()))
36}
37pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
38 Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
39}
40pub fn arrow(a: Expr, b: Expr) -> Expr {
41 pi(BinderInfo::Default, "_", a, b)
42}
43pub fn bvar(n: u32) -> Expr {
44 Expr::BVar(n)
45}
46pub fn nat_ty() -> Expr {
47 cst("Nat")
48}
49pub fn bool_ty() -> Expr {
50 cst("Bool")
51}
52pub fn list_ty(elem: Expr) -> Expr {
53 app(cst("List"), elem)
54}
55pub fn string_ty() -> Expr {
56 cst("String")
57}
58pub fn dcpo_ty() -> Expr {
61 arrow(type0(), prop())
62}
63pub fn scott_domain_ty() -> Expr {
65 arrow(type0(), prop())
66}
67pub fn algebraic_domain_ty() -> Expr {
69 arrow(type0(), prop())
70}
71pub fn continuous_domain_ty() -> Expr {
73 arrow(type0(), prop())
74}
75pub fn way_below_ty() -> Expr {
78 pi(
79 BinderInfo::Default,
80 "D",
81 type0(),
82 pi(
83 BinderInfo::Default,
84 "x",
85 bvar(0),
86 pi(BinderInfo::Default, "y", bvar(1), prop()),
87 ),
88 )
89}
90pub fn directed_sup_ty() -> Expr {
92 prop()
93}
94pub fn scott_open_set_ty() -> Expr {
96 pi(
97 BinderInfo::Default,
98 "D",
99 type0(),
100 arrow(arrow(bvar(0), prop()), prop()),
101 )
102}
103pub fn scott_continuous_fn_ty() -> Expr {
105 pi(
106 BinderInfo::Default,
107 "D",
108 type0(),
109 pi(
110 BinderInfo::Default,
111 "E",
112 type0(),
113 arrow(arrow(bvar(1), bvar(1)), prop()),
114 ),
115 )
116}
117pub fn lawson_topology_ty() -> Expr {
119 arrow(type0(), prop())
120}
121pub fn spectral_space_ty() -> Expr {
123 arrow(type0(), prop())
124}
125pub fn kleene_fixed_point_ty() -> Expr {
127 prop()
128}
129pub fn banach_fixed_point_ty() -> Expr {
131 prop()
132}
133pub fn domain_equation_ty() -> Expr {
135 prop()
136}
137pub fn solution_by_pointed_ty() -> Expr {
139 prop()
140}
141pub fn scott_continuous_functor_ty() -> Expr {
143 prop()
144}
145pub fn semantic_domain_ty() -> Expr {
147 arrow(type0(), type0())
148}
149pub fn denotation_ty() -> Expr {
151 prop()
152}
153pub fn environment_model_ty() -> Expr {
155 prop()
156}
157pub fn operational_equivalence_ty() -> Expr {
159 prop()
160}
161pub fn denotational_soundness_ty() -> Expr {
163 prop()
164}
165pub fn linear_type_ty() -> Expr {
167 arrow(type0(), prop())
168}
169pub fn exponential_modality_ty() -> Expr {
171 arrow(type0(), type0())
172}
173pub fn multiplicative_conj_ty() -> Expr {
175 arrow(type0(), arrow(type0(), type0()))
176}
177pub fn additive_conj_ty() -> Expr {
179 arrow(type0(), arrow(type0(), type0()))
180}
181pub fn linear_arrow_ty() -> Expr {
183 arrow(type0(), arrow(type0(), type0()))
184}
185pub fn proof_net_ty() -> Expr {
187 prop()
188}
189pub fn cpo_ty() -> Expr {
191 arrow(type0(), prop())
192}
193pub fn directed_set_ty() -> Expr {
195 pi(
196 BinderInfo::Default,
197 "D",
198 type0(),
199 arrow(arrow(bvar(0), prop()), prop()),
200 )
201}
202pub fn is_directed_ty() -> Expr {
204 pi(
205 BinderInfo::Default,
206 "D",
207 type0(),
208 arrow(arrow(bvar(0), prop()), prop()),
209 )
210}
211pub fn upper_bound_ty() -> Expr {
213 pi(
214 BinderInfo::Default,
215 "D",
216 type0(),
217 pi(
218 BinderInfo::Default,
219 "x",
220 bvar(0),
221 arrow(arrow(bvar(1), prop()), prop()),
222 ),
223 )
224}
225pub fn is_lub_ty() -> Expr {
227 pi(
228 BinderInfo::Default,
229 "D",
230 type0(),
231 pi(
232 BinderInfo::Default,
233 "x",
234 bvar(0),
235 arrow(arrow(bvar(1), prop()), prop()),
236 ),
237 )
238}
239pub fn omega_cpo_ty() -> Expr {
241 arrow(type0(), prop())
242}
243pub fn chain_complete_ty() -> Expr {
245 arrow(type0(), prop())
246}
247pub fn tarski_fixed_point_ty() -> Expr {
249 prop()
250}
251pub fn knaster_tarski_lfp_ty() -> Expr {
253 pi(
254 BinderInfo::Default,
255 "D",
256 type0(),
257 arrow(arrow(bvar(0), bvar(0)), bvar(0)),
258 )
259}
260pub fn knaster_tarski_gfp_ty() -> Expr {
262 pi(
263 BinderInfo::Default,
264 "D",
265 type0(),
266 arrow(arrow(bvar(0), bvar(0)), bvar(0)),
267 )
268}
269pub fn pre_fixed_point_ty() -> Expr {
271 pi(
272 BinderInfo::Default,
273 "D",
274 type0(),
275 pi(
276 BinderInfo::Default,
277 "f",
278 arrow(bvar(0), bvar(0)),
279 arrow(bvar(1), prop()),
280 ),
281 )
282}
283pub fn post_fixed_point_ty() -> Expr {
285 pi(
286 BinderInfo::Default,
287 "D",
288 type0(),
289 pi(
290 BinderInfo::Default,
291 "f",
292 arrow(bvar(0), bvar(0)),
293 arrow(bvar(1), prop()),
294 ),
295 )
296}
297pub fn lifted_domain_ty() -> Expr {
299 arrow(type0(), type0())
300}
301pub fn product_domain_ty() -> Expr {
303 arrow(type0(), arrow(type0(), type0()))
304}
305pub fn function_space_domain_ty() -> Expr {
307 arrow(type0(), arrow(type0(), type0()))
308}
309pub fn sum_domain_ty() -> Expr {
311 arrow(type0(), arrow(type0(), type0()))
312}
313pub fn pointed_domain_ty() -> Expr {
315 arrow(type0(), prop())
316}
317pub fn information_system_ty() -> Expr {
320 prop()
321}
322pub fn ideal_completion_ty() -> Expr {
324 arrow(type0(), type0())
325}
326pub fn is_ideal_ty() -> Expr {
328 pi(
329 BinderInfo::Default,
330 "P",
331 type0(),
332 arrow(arrow(bvar(0), prop()), prop()),
333 )
334}
335pub fn consistent_subset_ty() -> Expr {
337 pi(
338 BinderInfo::Default,
339 "A",
340 type0(),
341 arrow(arrow(bvar(0), prop()), prop()),
342 )
343}
344pub fn entailment_relation_ty() -> Expr {
346 prop()
347}
348pub fn plotkin_powerdomain_ty() -> Expr {
350 arrow(type0(), type0())
351}
352pub fn smyth_powerdomain_ty() -> Expr {
354 arrow(type0(), type0())
355}
356pub fn hoare_powerdomain_ty() -> Expr {
358 arrow(type0(), type0())
359}
360pub fn powerdomain_inclusion_ty() -> Expr {
362 prop()
363}
364pub fn angular_bisimulation_ty() -> Expr {
366 prop()
367}
368pub fn sfp_domain_ty() -> Expr {
370 arrow(type0(), prop())
371}
372pub fn bif_domain_ty() -> Expr {
374 arrow(type0(), prop())
375}
376pub fn stable_function_ty() -> Expr {
379 pi(
380 BinderInfo::Default,
381 "D",
382 type0(),
383 pi(
384 BinderInfo::Default,
385 "E",
386 type0(),
387 arrow(arrow(bvar(1), bvar(1)), prop()),
388 ),
389 )
390}
391pub fn berry_order_ty() -> Expr {
393 pi(
394 BinderInfo::Default,
395 "D",
396 type0(),
397 pi(
398 BinderInfo::Default,
399 "E",
400 type0(),
401 pi(
402 BinderInfo::Default,
403 "f",
404 arrow(bvar(1), bvar(1)),
405 pi(BinderInfo::Default, "g", arrow(bvar(2), bvar(2)), prop()),
406 ),
407 ),
408 )
409}
410pub fn strongly_stable_function_ty() -> Expr {
412 pi(
413 BinderInfo::Default,
414 "D",
415 type0(),
416 pi(
417 BinderInfo::Default,
418 "E",
419 type0(),
420 arrow(arrow(bvar(1), bvar(1)), prop()),
421 ),
422 )
423}
424pub fn sequential_algorithm_ty() -> Expr {
426 prop()
427}
428pub fn event_structure_ty() -> Expr {
430 prop()
431}
432pub fn stable_event_structure_ty() -> Expr {
434 prop()
435}
436pub fn prime_event_structure_ty() -> Expr {
438 prop()
439}
440pub fn conflict_relation_ty() -> Expr {
442 pi(
443 BinderInfo::Default,
444 "E",
445 type0(),
446 arrow(bvar(0), arrow(bvar(1), prop())),
447 )
448}
449pub fn coherence_space_ty() -> Expr {
451 prop()
452}
453pub fn web_of_coherence_space_ty() -> Expr {
455 arrow(type0(), type0())
456}
457pub fn clique_function_space_ty() -> Expr {
459 arrow(type0(), arrow(type0(), type0()))
460}
461pub fn game_arena_ty() -> Expr {
463 prop()
464}
465pub fn game_strategy_ty() -> Expr {
467 prop()
468}
469pub fn innocent_strategy_ty() -> Expr {
471 prop()
472}
473pub fn well_bracketed_strategy_ty() -> Expr {
475 prop()
476}
477pub fn pcf_type_ty() -> Expr {
479 arrow(nat_ty(), prop())
480}
481pub fn pcf_denotation_ty() -> Expr {
483 prop()
484}
485pub fn full_abstraction_pcf_ty() -> Expr {
487 prop()
488}
489pub fn universal_domain_ty() -> Expr {
491 prop()
492}
493pub fn computability_in_domains_ty() -> Expr {
495 prop()
496}
497pub fn quasimetric_space_ty() -> Expr {
499 arrow(type0(), prop())
500}
501pub fn per_ty() -> Expr {
503 pi(
504 BinderInfo::Default,
505 "D",
506 type0(),
507 arrow(bvar(0), arrow(bvar(1), prop())),
508 )
509}
510pub fn sober_space_ty() -> Expr {
512 arrow(type0(), prop())
513}
514pub fn topological_domain_ty() -> Expr {
516 arrow(type0(), prop())
517}
518pub fn domain_retract_ty() -> Expr {
520 pi(BinderInfo::Default, "D", type0(), arrow(type0(), prop()))
521}
522pub fn embedding_projection_pair_ty() -> Expr {
524 pi(
525 BinderInfo::Default,
526 "D",
527 type0(),
528 pi(
529 BinderInfo::Default,
530 "E",
531 type0(),
532 arrow(
533 arrow(bvar(1), bvar(1)),
534 arrow(arrow(bvar(2), bvar(2)), prop()),
535 ),
536 ),
537 )
538}
539pub fn domain_inverse_limit_ty() -> Expr {
541 prop()
542}
543pub fn build_domain_theory_env(env: &mut Environment) -> Result<(), String> {
545 let axioms: &[(&str, Expr)] = &[
546 ("DCPO", dcpo_ty()),
547 ("ScottDomain", scott_domain_ty()),
548 ("AlgebraicDomain", algebraic_domain_ty()),
549 ("ContinuousDomain", continuous_domain_ty()),
550 ("WayBelow", way_below_ty()),
551 ("DirectedSup", directed_sup_ty()),
552 ("IsCompactElement", arrow(type0(), arrow(type0(), prop()))),
553 ("HasBottom", arrow(type0(), prop())),
554 ("HasTop", arrow(type0(), prop())),
555 ("Sup", arrow(list_ty(type0()), type0())),
556 ("ScottOpenSet", scott_open_set_ty()),
557 ("ScottContinuousFunction", scott_continuous_fn_ty()),
558 ("LawsonTopology", lawson_topology_ty()),
559 ("SpectralSpace", spectral_space_ty()),
560 ("IsScottOpen", prop()),
561 ("IsScottClosed", prop()),
562 ("KleeneFixedPoint", kleene_fixed_point_ty()),
563 ("BanachFixedPoint", banach_fixed_point_ty()),
564 ("DomainEquation", domain_equation_ty()),
565 ("SolutionByPointed", solution_by_pointed_ty()),
566 ("ScottContinuousFunctor", scott_continuous_functor_ty()),
567 ("KleeneChain", prop()),
568 ("DomainIsomorphism", prop()),
569 ("SemanticDomain", semantic_domain_ty()),
570 ("Denotation", denotation_ty()),
571 ("EnvironmentModel", environment_model_ty()),
572 ("OperationalEquivalence", operational_equivalence_ty()),
573 ("DenotationalSoundness", denotational_soundness_ty()),
574 ("DenotationalAdequacy", prop()),
575 ("FullAbstraction", prop()),
576 ("LinearType", linear_type_ty()),
577 ("ExponentialModality", exponential_modality_ty()),
578 ("MultiplicativeConj", multiplicative_conj_ty()),
579 ("AdditiveConj", additive_conj_ty()),
580 ("LinearArrow", linear_arrow_ty()),
581 ("ProofNet", proof_net_ty()),
582 (
583 "MultiplicativeDisj",
584 arrow(type0(), arrow(type0(), type0())),
585 ),
586 ("AdditiveDisj", arrow(type0(), arrow(type0(), type0()))),
587 ("LinearNeg", arrow(type0(), type0())),
588 ("CutElimination", prop()),
589 ("CPO", cpo_ty()),
590 ("DirectedSet", directed_set_ty()),
591 ("IsDirected", is_directed_ty()),
592 ("UpperBound", upper_bound_ty()),
593 ("IsLeastUpperBound", is_lub_ty()),
594 ("OmegaCPO", omega_cpo_ty()),
595 ("ChainComplete", chain_complete_ty()),
596 ("TarskiFixedPoint", tarski_fixed_point_ty()),
597 ("KnasterTarskiLFP", knaster_tarski_lfp_ty()),
598 ("KnasterTarskiGFP", knaster_tarski_gfp_ty()),
599 ("PreFixedPoint", pre_fixed_point_ty()),
600 ("PostFixedPoint", post_fixed_point_ty()),
601 ("LiftedDomain", lifted_domain_ty()),
602 ("ProductDomain", product_domain_ty()),
603 ("FunctionSpaceDomain", function_space_domain_ty()),
604 ("SumDomain", sum_domain_ty()),
605 ("PointedDomain", pointed_domain_ty()),
606 ("InformationSystem", information_system_ty()),
607 ("IdealCompletion", ideal_completion_ty()),
608 ("IsIdeal", is_ideal_ty()),
609 ("ConsistentSubset", consistent_subset_ty()),
610 ("EntailmentRelation", entailment_relation_ty()),
611 ("PlotkinPowerdomain", plotkin_powerdomain_ty()),
612 ("SmythPowerdomain", smyth_powerdomain_ty()),
613 ("HoarePowerdomain", hoare_powerdomain_ty()),
614 ("PowerdomainInclusion", powerdomain_inclusion_ty()),
615 ("AngularBisimulation", angular_bisimulation_ty()),
616 ("SFPDomain", sfp_domain_ty()),
617 ("BifDomain", bif_domain_ty()),
618 ("StableFunction", stable_function_ty()),
619 ("BerryOrder", berry_order_ty()),
620 ("StronglyStableFunction", strongly_stable_function_ty()),
621 ("SequentialAlgorithm", sequential_algorithm_ty()),
622 ("EventStructure", event_structure_ty()),
623 ("StableEventStructure", stable_event_structure_ty()),
624 ("PrimeEventStructure", prime_event_structure_ty()),
625 ("ConflictRelation", conflict_relation_ty()),
626 ("CoherenceSpace", coherence_space_ty()),
627 ("WebOfCoherenceSpace", web_of_coherence_space_ty()),
628 ("CliqueFunctionSpace", clique_function_space_ty()),
629 ("GameArena", game_arena_ty()),
630 ("GameStrategy", game_strategy_ty()),
631 ("InnocentStrategy", innocent_strategy_ty()),
632 ("WellBracketedStrategy", well_bracketed_strategy_ty()),
633 ("PCFType", pcf_type_ty()),
634 ("PCFDenotation", pcf_denotation_ty()),
635 ("FullAbstractionPCF", full_abstraction_pcf_ty()),
636 ("UniversalDomain", universal_domain_ty()),
637 ("ComputabilityInDomains", computability_in_domains_ty()),
638 ("QuasimetricSpace", quasimetric_space_ty()),
639 ("PartialEquivalenceRelation", per_ty()),
640 ("SoberSpace", sober_space_ty()),
641 ("TopologicalDomain", topological_domain_ty()),
642 ("DomainRetract", domain_retract_ty()),
643 ("EmbeddingProjectionPair", embedding_projection_pair_ty()),
644 ("DomainInverseLimit", domain_inverse_limit_ty()),
645 ];
646 for (name, ty) in axioms {
647 env.add(Declaration::Axiom {
648 name: Name::str(*name),
649 univ_params: vec![],
650 ty: ty.clone(),
651 })
652 .ok();
653 }
654 Ok(())
655}
656#[cfg(test)]
657mod tests_domain_theory_ext {
658 use super::*;
659 #[test]
660 fn test_continuous_lattice() {
661 let cl = ContinuousLattice::new("L", true);
662 assert!(cl.is_algebraic);
663 assert!(cl.interpolation_property());
664 let desc = cl.way_below_description();
665 assert!(desc.contains("≪"));
666 let ir = ContinuousLattice::real_interval_domain();
667 assert!(!ir.is_algebraic);
668 let scott = ir.scott_topology_description();
669 assert!(scott.contains("Scott"));
670 }
671 #[test]
672 fn test_information_system() {
673 let mut is =
674 InformationSystem::new(vec!["a".to_string(), "b".to_string(), "c".to_string()]);
675 is.add_consistent(0, 1);
676 is.add_consistent(1, 2);
677 is.add_entailment(vec![0, 1], 2);
678 assert!(is.is_consistent_set(&[0, 1]));
679 assert!(!is.is_consistent_set(&[0, 2]));
680 let desc = is.scott_domain_from_is();
681 assert!(desc.contains("consistent"));
682 }
683 #[test]
684 fn test_powerdomains() {
685 let plotkin = Powerdomain::plotkin("D");
686 let sem = plotkin.semantics_for();
687 assert!(sem.contains("nondeterminism"));
688 let smyth = Powerdomain::smyth("D");
689 let ord = smyth.order_description();
690 assert!(ord.contains("Smyth"));
691 let hoare = Powerdomain::hoare("D");
692 let hord = hoare.order_description();
693 assert!(hord.contains("Hoare"));
694 }
695 #[test]
696 fn test_domain_equation() {
697 let uc = DomainEqn::untyped_lambda_calculus();
698 assert!(uc.solution_name.contains("Scott"));
699 let desc = uc.banach_iteration_description();
700 assert!(desc.contains("Banach"));
701 let stream = DomainEqn::recursive_stream();
702 assert!(stream.variable == "S");
703 let pitts = stream.pitts_theorem();
704 assert!(pitts.contains("Pitts"));
705 }
706 #[test]
707 fn test_bifinite_approximation() {
708 let mut ba = BifiniteApproximation::new("D∞");
709 ba.add_level("D0");
710 ba.add_level("D1");
711 ba.add_level("D2");
712 assert!(ba.is_sfp_domain());
713 let col = ba.colimit_description();
714 assert!(col.contains("D0 → D1 → D2"));
715 }
716}