oxilean-std 0.1.2

OxiLean standard library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
//! Auto-generated module
//!
//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)

use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
use std::collections::{HashMap, HashSet};

use super::types::{
    BeliefRevisionOp, Bisimulation, CanonicalModel, EpistemicModel, FiniteTrace, GradedModel,
    KripkeFrame, KripkeModel, MaximalConsistentSet, ModalFormula, ModalSystem, MuCalculusEval,
    PdlModel, PdlProgram, PublicAnnouncement, SahlqvistClass,
};

pub fn app(f: Expr, a: Expr) -> Expr {
    Expr::App(Box::new(f), Box::new(a))
}
pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
    app(app(f, a), b)
}
pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
    app(app2(f, a, b), c)
}
pub fn cst(s: &str) -> Expr {
    Expr::Const(Name::str(s), vec![])
}
pub fn prop() -> Expr {
    Expr::Sort(Level::zero())
}
pub fn type0() -> Expr {
    Expr::Sort(Level::succ(Level::zero()))
}
pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
    Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
}
pub fn arrow(a: Expr, b: Expr) -> Expr {
    pi(BinderInfo::Default, "_", a, b)
}
pub fn bvar(n: u32) -> Expr {
    Expr::BVar(n)
}
pub fn nat_ty() -> Expr {
    cst("Nat")
}
pub fn bool_ty() -> Expr {
    cst("Bool")
}
/// KripkeFrame: (W, R) — a set of worlds with an accessibility relation.
pub fn kripke_frame_ty() -> Expr {
    type0()
}
/// KripkeModel: (W, R, V) — frame + valuation of propositions.
pub fn kripke_model_ty() -> Expr {
    type0()
}
/// World: an element of the set of possible worlds.
pub fn world_ty() -> Expr {
    type0()
}
/// AccessibilityRelation: W → W → Prop
pub fn accessibility_relation_ty() -> Expr {
    arrow(cst("World"), arrow(cst("World"), prop()))
}
/// Valuation: propositional variable → world → Bool
pub fn valuation_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("World"), bool_ty()))
}
/// ModalFormula: syntax of modal propositional logic.
pub fn modal_formula_ty() -> Expr {
    type0()
}
/// Satisfaction: M, w ⊨ φ
pub fn modal_satisfaction_ty() -> Expr {
    arrow(
        cst("KripkeModel"),
        arrow(cst("World"), arrow(cst("ModalFormula"), prop())),
    )
}
/// FrameValidity: φ valid in frame F — for all valuations and all worlds
pub fn frame_validity_ty() -> Expr {
    arrow(cst("KripkeFrame"), arrow(cst("ModalFormula"), prop()))
}
/// ClassValidity: φ valid in a class of frames
pub fn class_validity_ty() -> Expr {
    arrow(
        arrow(cst("KripkeFrame"), prop()),
        arrow(cst("ModalFormula"), prop()),
    )
}
/// Reflexive frame: ∀w, wRw
pub fn reflexive_frame_ty() -> Expr {
    arrow(cst("KripkeFrame"), prop())
}
/// Transitive frame: ∀w v u, wRv → vRu → wRu
pub fn transitive_frame_ty() -> Expr {
    arrow(cst("KripkeFrame"), prop())
}
/// Symmetric frame: ∀w v, wRv → vRw
pub fn symmetric_frame_ty() -> Expr {
    arrow(cst("KripkeFrame"), prop())
}
/// Serial frame: ∀w, ∃v, wRv
pub fn serial_frame_ty() -> Expr {
    arrow(cst("KripkeFrame"), prop())
}
/// Euclidean frame: ∀w v u, wRv → wRu → vRu
pub fn euclidean_frame_ty() -> Expr {
    arrow(cst("KripkeFrame"), prop())
}
/// Confluent frame: ∀w v u, wRv → wRu → ∃z, vRz ∧ uRz (Church-Rosser)
pub fn confluent_frame_ty() -> Expr {
    arrow(cst("KripkeFrame"), prop())
}
/// Dense frame: ∀w u, wRu → ∃v, wRv ∧ vRu
pub fn dense_frame_ty() -> Expr {
    arrow(cst("KripkeFrame"), prop())
}
/// Directed frame: ∀w v u, wRv → wRu → ∃z, vRz ∧ uRz ∧ wRz
pub fn directed_frame_ty() -> Expr {
    arrow(cst("KripkeFrame"), prop())
}
/// AxiomK: □(φ → ψ) → □φ → □ψ (distribution)
pub fn axiom_k_ty() -> Expr {
    arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
/// AxiomT: □φ → φ (reflexivity)
pub fn axiom_t_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Axiom4: □φ → □□φ (transitivity / positive introspection)
pub fn axiom4_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// AxiomB: φ → □◇φ (symmetry / Brouwer)
pub fn axiom_b_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Axiom5: ◇φ → □◇φ (Euclidean / negative introspection)
pub fn axiom5_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// AxiomD: □φ → ◇φ (seriality / deontic)
pub fn axiom_d_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// AxiomLöb (GL): □(□φ → φ) → □φ (provability logic)
pub fn axiom_lob_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// NecRule: if ⊢ φ then ⊢ □φ (necessitation)
pub fn nec_rule_ty() -> Expr {
    arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
/// Soundness: K is sound with respect to all Kripke frames
pub fn soundness_k_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Completeness: K is complete with respect to all Kripke frames
pub fn completeness_k_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Soundness T: T is sound with respect to reflexive frames
pub fn soundness_t_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Completeness T: T is complete with respect to reflexive frames
pub fn completeness_t_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Soundness S4: S4 is sound with respect to reflexive-transitive frames
pub fn soundness_s4_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Completeness S4: S4 is complete with respect to reflexive-transitive frames
pub fn completeness_s4_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Soundness S5: S5 is sound with respect to equivalence-relation frames
pub fn soundness_s5_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Completeness S5: S5 is complete with respect to equivalence-relation frames
pub fn completeness_s5_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// CanonicalFrame: the canonical frame for a normal modal logic L
pub fn canonical_frame_ty() -> Expr {
    arrow(cst("ModalLogic"), cst("KripkeFrame"))
}
/// CanonicalModel: the canonical model for a normal modal logic L
pub fn canonical_model_ty() -> Expr {
    arrow(cst("ModalLogic"), cst("KripkeModel"))
}
/// CanonicalTruthLemma: φ ∈ w ↔ M^L, w ⊨ φ (truth lemma for canonical model)
pub fn canonical_truth_lemma_ty() -> Expr {
    arrow(cst("ModalLogic"), arrow(cst("ModalFormula"), prop()))
}
/// MaximalConsistentSet: a maximal L-consistent set of formulas
pub fn maximal_consistent_set_ty() -> Expr {
    arrow(cst("ModalLogic"), type0())
}
/// LindenBaum lemma: every consistent set extends to a maximal consistent set
pub fn lindenbaum_ty() -> Expr {
    arrow(cst("ModalLogic"), prop())
}
/// FrameCorrespondence: an axiom corresponds to a frame property
pub fn frame_correspondence_ty() -> Expr {
    arrow(
        cst("ModalFormula"),
        arrow(arrow(cst("KripkeFrame"), prop()), prop()),
    )
}
/// SahlqvistFormula: syntactic class of formulas with effective correspondence
pub fn sahlqvist_formula_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// SahlqvistCorrespondence: Sahlqvist formulas have first-order frame correspondents
pub fn sahlqvist_correspondence_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// SahlqvistCompleteness: every Sahlqvist logic is Kripke complete
pub fn sahlqvist_completeness_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// EpistemicLogic S5: knowledge operator K_i for agent i
pub fn epistemic_knowledge_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// CommonKnowledge: C_G φ — all agents in group G know φ, know that they know it, …
pub fn common_knowledge_ty() -> Expr {
    arrow(
        cst("AgentGroup"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// DistributedKnowledge: D_G φ — what is implicit in the combined knowledge of G
pub fn distributed_knowledge_ty() -> Expr {
    arrow(
        cst("AgentGroup"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// DoxasticLogic KD45: belief operator B_i for agent i
pub fn doxastic_belief_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// PositiveIntrospection (axiom 4): K_i φ → K_i K_i φ
pub fn positive_introspection_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("ModalFormula"), prop()))
}
/// NegativeIntrospection (axiom 5): ¬K_i φ → K_i ¬K_i φ
pub fn negative_introspection_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("ModalFormula"), prop()))
}
/// ObligationOp: O φ — it is obligatory that φ
pub fn obligation_op_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// PermissionOp: P φ — it is permitted that φ
pub fn permission_op_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// ProhibitionOp: F φ — it is forbidden that φ
pub fn prohibition_op_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// DeonticConflict: O φ ∧ O ¬φ (normative inconsistency)
pub fn deontic_conflict_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// RossCurse: the paradox O(φ) → O(φ ∨ ψ) in SDL
pub fn ross_paradox_ty() -> Expr {
    arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
/// ProvabilityLogic GL: â–¡ interpreted as provability in PA
pub fn gl_provability_ty() -> Expr {
    type0()
}
/// SolovayCompleteness: GL is arithmetically complete
pub fn solovay_completeness_ty() -> Expr {
    prop()
}
/// GödelDiagonalLemma: ∃ φ, PA ⊢ φ ↔ ¬Provable(φ)
pub fn godel_diagonal_ty() -> Expr {
    prop()
}
/// FixedPointTheorem (GL): for every modalized φ(p), there is a fixed point
pub fn gl_fixed_point_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// TransitiveIrreflexiveFrame: GL validates exactly the class of transitive irreflexive frames
pub fn gl_frame_class_ty() -> Expr {
    prop()
}
/// PublicAnnouncement: \[!φ\] ψ — after public announcement of φ, ψ holds
pub fn public_announcement_ty() -> Expr {
    arrow(
        cst("ModalFormula"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// AnnouncementLaw: \[!φ\] K_i ψ ↔ (φ → K_i (φ → \[!φ\] ψ))
pub fn announcement_knowledge_law_ty() -> Expr {
    arrow(
        nat_ty(),
        arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop())),
    )
}
/// ActionModel: a multi-agent action model (Baltag-Moss-Solecki)
pub fn action_model_ty() -> Expr {
    type0()
}
/// ProductUpdate: M ⊗ A — update a model M with action model A
pub fn product_update_ty() -> Expr {
    arrow(
        cst("KripkeModel"),
        arrow(cst("ActionModel"), cst("KripkeModel")),
    )
}
/// MudPuzzle: the classical DEL example — common knowledge via announcements
pub fn mud_puzzle_ty() -> Expr {
    arrow(nat_ty(), prop())
}
/// MultimodalFormula: formulas with indexed modalities â–¡_i, â—‡_i
pub fn multimodal_formula_ty() -> Expr {
    type0()
}
/// ProductFrame: F × G — two frames combined
pub fn product_frame_ty() -> Expr {
    arrow(
        cst("KripkeFrame"),
        arrow(cst("KripkeFrame"), cst("KripkeFrame")),
    )
}
/// FusionLogic: the fusion L_1 ⊕ L_2 of two modal logics
pub fn fusion_logic_ty() -> Expr {
    arrow(
        cst("ModalLogic"),
        arrow(cst("ModalLogic"), cst("ModalLogic")),
    )
}
/// InteractionAxiom: an axiom relating different modalities
pub fn interaction_axiom_ty() -> Expr {
    type0()
}
/// TenseLogic: bimodal logic with future G/F and past H/P operators
pub fn tense_logic_ty() -> Expr {
    type0()
}
/// Filtration: a technique for proving finite model property
pub fn filtration_ty() -> Expr {
    arrow(
        cst("KripkeModel"),
        arrow(cst("ModalFormula"), cst("KripkeModel")),
    )
}
/// FiniteModelProperty: L has FMP iff valid = finitely valid
pub fn finite_model_property_ty() -> Expr {
    arrow(cst("ModalLogic"), prop())
}
/// Decidability: L is decidable via FMP + finite checking
pub fn modal_decidability_ty() -> Expr {
    arrow(cst("ModalLogic"), prop())
}
/// SubformulaProperty: subformulas of φ suffice for a filtration
pub fn subformula_property_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// K_FMP: logic K has the finite model property
pub fn k_fmp_ty() -> Expr {
    prop()
}
/// S4_FMP: logic S4 has the finite model property
pub fn s4_fmp_ty() -> Expr {
    prop()
}
/// PDL Program type: regular programs (test, choice, sequence, iteration)
pub fn pdl_program_ty() -> Expr {
    type0()
}
/// PDL Box: \[α\]φ — after every execution of program α, φ holds
pub fn pdl_box_ty() -> Expr {
    arrow(
        cst("PDLProgram"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// PDL Diamond: ⟨α⟩φ — there exists an execution of α after which φ holds
pub fn pdl_diamond_ty() -> Expr {
    arrow(
        cst("PDLProgram"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// PDL test program: φ? — succeeds iff φ holds, proceeds to same state
pub fn pdl_test_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("PDLProgram"))
}
/// PDL axiom: \[α;β\]φ ↔ \[α\]\[β\]φ (sequence)
pub fn pdl_sequence_axiom_ty() -> Expr {
    arrow(
        cst("PDLProgram"),
        arrow(cst("PDLProgram"), arrow(cst("ModalFormula"), prop())),
    )
}
/// PDL axiom: \[α∪β\]φ ↔ \[α\]φ ∧ \[β\]φ (choice)
pub fn pdl_choice_axiom_ty() -> Expr {
    arrow(
        cst("PDLProgram"),
        arrow(cst("PDLProgram"), arrow(cst("ModalFormula"), prop())),
    )
}
/// PDL iteration axiom: \[α*\]φ ↔ φ ∧ \[α\]\[α*\]φ
pub fn pdl_iteration_axiom_ty() -> Expr {
    arrow(cst("PDLProgram"), arrow(cst("ModalFormula"), prop()))
}
/// Game Logic: ⟨γ⟩φ — player I has a strategy in game γ to ensure φ
pub fn game_logic_diamond_ty() -> Expr {
    arrow(cst("Game"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// Game Logic: \[γ\]φ — player II has a strategy in game γ to ensure φ
pub fn game_logic_box_ty() -> Expr {
    arrow(cst("Game"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// Game type: represents a two-player game
pub fn game_ty() -> Expr {
    type0()
}
/// LTL Next: Xφ — φ holds at the next time step
pub fn ltl_next_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// LTL Until: φ U ψ — φ holds until ψ becomes true
pub fn ltl_until_ty() -> Expr {
    arrow(
        cst("ModalFormula"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// LTL Globally: Gφ — φ holds at all future times
pub fn ltl_globally_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// LTL Finally: Fφ — φ holds at some future time
pub fn ltl_finally_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// CTL State path quantifier: EXφ — exists a path where next φ
pub fn ctl_ex_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// CTL: AXφ — all paths, next φ
pub fn ctl_ax_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// CTL: E\[φ U ψ\] — exists a path where φ until ψ
pub fn ctl_eu_ty() -> Expr {
    arrow(
        cst("ModalFormula"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// CTL: A\[φ U ψ\] — all paths, φ until ψ
pub fn ctl_au_ty() -> Expr {
    arrow(
        cst("ModalFormula"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// ATL: ⟨⟨A⟩⟩φ — coalition A has a strategy to ensure φ
pub fn atl_coalition_ty() -> Expr {
    arrow(
        cst("AgentGroup"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// ATL concurrent game structure type
pub fn concurrent_game_structure_ty() -> Expr {
    type0()
}
/// Nominal type: a rigid designator for a world
pub fn nominal_ty() -> Expr {
    type0()
}
/// Hybrid satisfaction: @_i φ — φ holds at the world named by nominal i
pub fn hybrid_at_ty() -> Expr {
    arrow(
        cst("Nominal"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// Hybrid binder: ↓x. φ — bind current world to nominal x in φ
pub fn hybrid_binder_ty() -> Expr {
    arrow(
        cst("Nominal"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// H(@): hybrid logic axiom @_i φ ↔ (i → φ) for nominals
pub fn hybrid_axiom_at_ty() -> Expr {
    arrow(cst("Nominal"), arrow(cst("ModalFormula"), prop()))
}
/// Hybrid paste axiom: ◇i → (@_i φ → ◇φ)
pub fn hybrid_paste_axiom_ty() -> Expr {
    arrow(cst("Nominal"), arrow(cst("ModalFormula"), prop()))
}
/// Neighborhood function: W → 2^{2^W}
pub fn neighborhood_fn_ty() -> Expr {
    arrow(cst("World"), type0())
}
/// Classical modal logic: □φ valid iff [\[φ\]] is in the neighborhood
pub fn classical_modal_box_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// Monotone modal logic: if X ∈ N(w) and X ⊆ Y then Y ∈ N(w)
pub fn monotone_neighborhood_ty() -> Expr {
    arrow(cst("World"), prop())
}
/// AxiomM (monotonicity): □φ ∧ □ψ → □(φ ∧ ψ)
pub fn axiom_m_ty() -> Expr {
    arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
/// AxiomC (supplementation): □φ → □(φ ∨ ψ)
pub fn axiom_c_ty() -> Expr {
    arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
/// AxiomN (normality): □⊤
pub fn axiom_n_ty() -> Expr {
    prop()
}
/// JustificationTerm: a term t witnessing a justification for φ
pub fn justification_term_ty() -> Expr {
    type0()
}
/// JustificationOp: t:φ — term t is a justification for φ
pub fn justification_op_ty() -> Expr {
    arrow(cst("JustificationTerm"), arrow(cst("ModalFormula"), prop()))
}
/// Application axiom (LP): s:(φ→ψ) → t:φ → (s⋅t):ψ
pub fn justification_app_axiom_ty() -> Expr {
    arrow(
        cst("JustificationTerm"),
        arrow(cst("JustificationTerm"), arrow(cst("ModalFormula"), prop())),
    )
}
/// Sum axiom (LP): t:φ → (t+s):φ
pub fn justification_sum_axiom_ty() -> Expr {
    arrow(
        cst("JustificationTerm"),
        arrow(cst("JustificationTerm"), arrow(cst("ModalFormula"), prop())),
    )
}
/// Verification axiom (LP): t:φ → !t:(t:φ)
pub fn justification_verification_ty() -> Expr {
    arrow(cst("JustificationTerm"), arrow(cst("ModalFormula"), prop()))
}
/// Realization theorem: every theorem of S4 has a justification logic realization
pub fn realization_theorem_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// GLS: GL + □(□φ → φ) — the stable provability logic
pub fn gls_axiom_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Arithmetical soundness: GL is sound for the standard interpretation
pub fn arithmetical_soundness_ty() -> Expr {
    prop()
}
/// Arithmetical interpretation function: modal formulas → arithmetic sentences
pub fn arithmetical_interp_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ArithSentence"))
}
/// Solovay's second completeness
pub fn solovay_second_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Mu formula type: supports least/greatest fixed points
pub fn mu_formula_ty() -> Expr {
    type0()
}
/// Least fixed point: μX.φ(X)
pub fn mu_least_fp_ty() -> Expr {
    arrow(
        cst("PropVar"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// Greatest fixed point: νX.φ(X)
pub fn nu_greatest_fp_ty() -> Expr {
    arrow(
        cst("PropVar"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// Knaster-Tarski for modal operators
pub fn knaster_tarski_modal_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// Model checking problem: M, w ⊨ φ decidable for μ-calculus
pub fn mu_calculus_decidable_ty() -> Expr {
    prop()
}
/// Alternation hierarchy: μ-calculus has strict alternation hierarchy
pub fn alternation_hierarchy_ty() -> Expr {
    prop()
}
/// Context of utterance type (for two-dimensional semantics)
pub fn context_ty() -> Expr {
    type0()
}
/// Two-dimensional evaluation: M, c, w ⊨ φ
pub fn two_dim_satisfaction_ty() -> Expr {
    arrow(
        cst("KripkeModel"),
        arrow(
            cst("Context"),
            arrow(cst("World"), arrow(cst("ModalFormula"), prop())),
        ),
    )
}
/// Kaplan's dthat: [\[dthat φ\]]^{c,w} = [\[φ\]]^{c,c}
pub fn kaplan_dthat_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// Double indexing: actually(φ)
pub fn actually_op_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// Fixedly: fixedly(φ) — φ is true at every context
pub fn fixedly_op_ty() -> Expr {
    arrow(cst("ModalFormula"), cst("ModalFormula"))
}
/// Necessity type: â–¡A
pub fn necessity_type_ty() -> Expr {
    arrow(type0(), type0())
}
/// Box introduction
pub fn box_intro_ty() -> Expr {
    arrow(type0(), type0())
}
/// Box elimination
pub fn box_elim_ty() -> Expr {
    arrow(type0(), arrow(type0(), type0()))
}
/// Pfenning-Davies locked contexts
pub fn locked_context_ty() -> Expr {
    type0()
}
/// TopologicalSpace: (X, Ï„)
pub fn topological_space_ty() -> Expr {
    type0()
}
/// Interior operator: Int(A)
pub fn interior_op_ty() -> Expr {
    arrow(
        cst("TopologicalSpace"),
        arrow(cst("ModalFormula"), cst("ModalFormula")),
    )
}
/// McKinsey-Tarski: S4 is complete for topological semantics on R^n
pub fn mckinsey_tarski_ty() -> Expr {
    prop()
}
/// Dense-in-itself: every point is a limit point
pub fn dense_in_itself_ty() -> Expr {
    arrow(cst("TopologicalSpace"), prop())
}
/// Topological validity: φ valid in all topological spaces
pub fn topological_validity_ty() -> Expr {
    arrow(cst("ModalFormula"), prop())
}
/// FOML formula type
pub fn foml_formula_ty() -> Expr {
    type0()
}
/// Barcan formula: ∀x □φ(x) → □∀x φ(x)
pub fn barcan_formula_ty() -> Expr {
    arrow(cst("FOMLFormula"), prop())
}
/// Converse Barcan: □∀x φ(x) → ∀x □φ(x)
pub fn converse_barcan_ty() -> Expr {
    arrow(cst("FOMLFormula"), prop())
}
/// Varying domain semantics
pub fn varying_domain_ty() -> Expr {
    arrow(cst("KripkeFrame"), type0())
}
/// Constant domain semantics
pub fn constant_domain_ty() -> Expr {
    arrow(cst("KripkeFrame"), type0())
}
/// Existence predicate: E(x)
pub fn existence_predicate_ty() -> Expr {
    arrow(cst("World"), prop())
}
/// Minimal modal logic E
pub fn minimal_modal_logic_e_ty() -> Expr {
    type0()
}
/// AxiomE: if ⊢ φ ↔ ψ then ⊢ □φ ↔ □ψ
pub fn axiom_e_ty() -> Expr {
    arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
/// Monotonic modal logic: E + M
pub fn monotonic_modal_logic_ty() -> Expr {
    type0()
}
/// Regular modal logic: E + C + M
pub fn regular_modal_logic_ty() -> Expr {
    type0()
}
/// Congruence rule: φ ↔ ψ implies □φ ↔ □ψ
pub fn congruence_rule_ty() -> Expr {
    arrow(cst("ModalFormula"), arrow(cst("ModalFormula"), prop()))
}
/// STIT operator: \[i stit: φ\]
pub fn stit_op_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// Deliberative STIT: \[i dstit: φ\]
pub fn deliberative_stit_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// Achievement STIT: \[i astit: φ\]
pub fn achievement_stit_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// Deontic STIT: obligatory stit
pub fn deontic_stit_ty() -> Expr {
    arrow(nat_ty(), arrow(cst("ModalFormula"), prop()))
}
/// Graded modality: ◇^≥n φ
pub fn graded_diamond_ty() -> Expr {
    arrow(cst("Nat"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// Graded box: □^≤n φ
pub fn graded_box_ty() -> Expr {
    arrow(cst("Nat"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// Probabilistic modality: P_{≥r}(φ)
pub fn probabilistic_modality_ty() -> Expr {
    arrow(cst("Real"), arrow(cst("ModalFormula"), cst("ModalFormula")))
}
/// Coalgebraic functor type
pub fn coalgebra_functor_ty() -> Expr {
    arrow(type0(), type0())
}
/// Coalgebra type: T-coalgebra
pub fn modal_coalgebra_ty() -> Expr {
    arrow(cst("CoalgebraFunctor"), arrow(type0(), type0()))
}
/// Belief set type
pub fn belief_set_ty() -> Expr {
    type0()
}
/// Revision operator: K * φ
pub fn belief_revision_ty() -> Expr {
    arrow(
        cst("BeliefSet"),
        arrow(cst("ModalFormula"), cst("BeliefSet")),
    )
}
/// Contraction operator: K ÷ φ
pub fn belief_contraction_ty() -> Expr {
    arrow(
        cst("BeliefSet"),
        arrow(cst("ModalFormula"), cst("BeliefSet")),
    )
}
/// AGM success postulate: φ ∈ K * φ
pub fn agm_success_ty() -> Expr {
    arrow(cst("BeliefSet"), arrow(cst("ModalFormula"), prop()))
}
/// AGM consistency postulate
pub fn agm_consistency_ty() -> Expr {
    arrow(cst("BeliefSet"), arrow(cst("ModalFormula"), prop()))
}
/// Populate an `Environment` with all modal logic axioms and theorems.
pub fn build_modal_logic_env(env: &mut Environment) {
    let axioms: &[(&str, Expr)] = &[
        ("KripkeFrame", kripke_frame_ty()),
        ("KripkeModel", kripke_model_ty()),
        ("World", world_ty()),
        ("AccessibilityRelation", accessibility_relation_ty()),
        ("Valuation", valuation_ty()),
        ("ModalFormula", modal_formula_ty()),
        ("ModalLogic", type0()),
        ("Agent", nat_ty()),
        ("AgentGroup", type0()),
        ("ModalSat", modal_satisfaction_ty()),
        ("FrameValid", frame_validity_ty()),
        ("ClassValid", class_validity_ty()),
        ("ReflexiveFrame", reflexive_frame_ty()),
        ("TransitiveFrame", transitive_frame_ty()),
        ("SymmetricFrame", symmetric_frame_ty()),
        ("SerialFrame", serial_frame_ty()),
        ("EuclideanFrame", euclidean_frame_ty()),
        ("ConfluentFrame", confluent_frame_ty()),
        ("DenseFrame", dense_frame_ty()),
        ("DirectedFrame", directed_frame_ty()),
        ("AxiomK", axiom_k_ty()),
        ("AxiomT", axiom_t_ty()),
        ("Axiom4", axiom4_ty()),
        ("AxiomB", axiom_b_ty()),
        ("Axiom5", axiom5_ty()),
        ("AxiomD", axiom_d_ty()),
        ("AxiomLob", axiom_lob_ty()),
        ("NecRule", nec_rule_ty()),
        ("soundness_k", soundness_k_ty()),
        ("completeness_k", completeness_k_ty()),
        ("soundness_t", soundness_t_ty()),
        ("completeness_t", completeness_t_ty()),
        ("soundness_s4", soundness_s4_ty()),
        ("completeness_s4", completeness_s4_ty()),
        ("soundness_s5", soundness_s5_ty()),
        ("completeness_s5", completeness_s5_ty()),
        ("CanonicalFrame", canonical_frame_ty()),
        ("CanonicalModel", canonical_model_ty()),
        ("canonical_truth_lemma", canonical_truth_lemma_ty()),
        ("MaximalConsistentSet", maximal_consistent_set_ty()),
        ("lindenbaum", lindenbaum_ty()),
        ("FrameCorrespondence", frame_correspondence_ty()),
        ("SahlqvistFormula", sahlqvist_formula_ty()),
        ("sahlqvist_correspondence", sahlqvist_correspondence_ty()),
        ("sahlqvist_completeness", sahlqvist_completeness_ty()),
        ("EpistemicK", epistemic_knowledge_ty()),
        ("CommonKnowledge", common_knowledge_ty()),
        ("DistributedKnowledge", distributed_knowledge_ty()),
        ("DoxasticB", doxastic_belief_ty()),
        ("positive_introspection", positive_introspection_ty()),
        ("negative_introspection", negative_introspection_ty()),
        ("ObligationOp", obligation_op_ty()),
        ("PermissionOp", permission_op_ty()),
        ("ProhibitionOp", prohibition_op_ty()),
        ("DeonticConflict", deontic_conflict_ty()),
        ("RossParadox", ross_paradox_ty()),
        ("GLProvability", gl_provability_ty()),
        ("solovay_completeness", solovay_completeness_ty()),
        ("godel_diagonal", godel_diagonal_ty()),
        ("gl_fixed_point", gl_fixed_point_ty()),
        ("gl_frame_class", gl_frame_class_ty()),
        ("PublicAnnouncement", public_announcement_ty()),
        (
            "announcement_knowledge_law",
            announcement_knowledge_law_ty(),
        ),
        ("ActionModel", action_model_ty()),
        ("ProductUpdate", product_update_ty()),
        ("MudPuzzle", mud_puzzle_ty()),
        ("MultimodalFormula", multimodal_formula_ty()),
        ("ProductFrame", product_frame_ty()),
        ("FusionLogic", fusion_logic_ty()),
        ("InteractionAxiom", interaction_axiom_ty()),
        ("TenseLogic", tense_logic_ty()),
        ("Filtration", filtration_ty()),
        ("FiniteModelProperty", finite_model_property_ty()),
        ("ModalDecidability", modal_decidability_ty()),
        ("SubformulaProperty", subformula_property_ty()),
        ("k_fmp", k_fmp_ty()),
        ("s4_fmp", s4_fmp_ty()),
        ("PDLProgram", pdl_program_ty()),
        ("PDLBox", pdl_box_ty()),
        ("PDLDiamond", pdl_diamond_ty()),
        ("PDLTest", pdl_test_ty()),
        ("pdl_sequence_axiom", pdl_sequence_axiom_ty()),
        ("pdl_choice_axiom", pdl_choice_axiom_ty()),
        ("pdl_iteration_axiom", pdl_iteration_axiom_ty()),
        ("GameLogicDiamond", game_logic_diamond_ty()),
        ("GameLogicBox", game_logic_box_ty()),
        ("Game", game_ty()),
        ("LTLNext", ltl_next_ty()),
        ("LTLUntil", ltl_until_ty()),
        ("LTLGlobally", ltl_globally_ty()),
        ("LTLFinally", ltl_finally_ty()),
        ("CTLEX", ctl_ex_ty()),
        ("CTLAX", ctl_ax_ty()),
        ("CTLEU", ctl_eu_ty()),
        ("CTLAU", ctl_au_ty()),
        ("ATLCoalition", atl_coalition_ty()),
        ("ConcurrentGameStructure", concurrent_game_structure_ty()),
        ("Nominal", nominal_ty()),
        ("HybridAt", hybrid_at_ty()),
        ("HybridBinder", hybrid_binder_ty()),
        ("hybrid_axiom_at", hybrid_axiom_at_ty()),
        ("hybrid_paste_axiom", hybrid_paste_axiom_ty()),
        ("NeighborhoodFn", neighborhood_fn_ty()),
        ("ClassicalModalBox", classical_modal_box_ty()),
        ("MonotoneNeighborhood", monotone_neighborhood_ty()),
        ("AxiomM", axiom_m_ty()),
        ("AxiomC", axiom_c_ty()),
        ("AxiomN", axiom_n_ty()),
        ("JustificationTerm", justification_term_ty()),
        ("JustificationOp", justification_op_ty()),
        ("justification_app_axiom", justification_app_axiom_ty()),
        ("justification_sum_axiom", justification_sum_axiom_ty()),
        (
            "justification_verification",
            justification_verification_ty(),
        ),
        ("realization_theorem", realization_theorem_ty()),
        ("gls_axiom", gls_axiom_ty()),
        ("arithmetical_soundness", arithmetical_soundness_ty()),
        ("ArithSentence", type0()),
        ("arithmetical_interp", arithmetical_interp_ty()),
        ("solovay_second", solovay_second_ty()),
        ("MuFormula", mu_formula_ty()),
        ("PropVar", nat_ty()),
        ("mu_least_fp", mu_least_fp_ty()),
        ("nu_greatest_fp", nu_greatest_fp_ty()),
        ("knaster_tarski_modal", knaster_tarski_modal_ty()),
        ("mu_calculus_decidable", mu_calculus_decidable_ty()),
        ("alternation_hierarchy", alternation_hierarchy_ty()),
        ("Context", context_ty()),
        ("two_dim_satisfaction", two_dim_satisfaction_ty()),
        ("kaplan_dthat", kaplan_dthat_ty()),
        ("actually_op", actually_op_ty()),
        ("fixedly_op", fixedly_op_ty()),
        ("necessity_type", necessity_type_ty()),
        ("box_intro", box_intro_ty()),
        ("box_elim", box_elim_ty()),
        ("LockedContext", locked_context_ty()),
        ("TopologicalSpace", topological_space_ty()),
        ("InteriorOp", interior_op_ty()),
        ("mckinsey_tarski", mckinsey_tarski_ty()),
        ("dense_in_itself", dense_in_itself_ty()),
        ("topological_validity", topological_validity_ty()),
        ("FOMLFormula", foml_formula_ty()),
        ("barcan_formula", barcan_formula_ty()),
        ("converse_barcan", converse_barcan_ty()),
        ("varying_domain", varying_domain_ty()),
        ("constant_domain", constant_domain_ty()),
        ("existence_predicate", existence_predicate_ty()),
        ("MinimalModalLogicE", minimal_modal_logic_e_ty()),
        ("AxiomE", axiom_e_ty()),
        ("MonotonicModalLogic", monotonic_modal_logic_ty()),
        ("RegularModalLogic", regular_modal_logic_ty()),
        ("congruence_rule", congruence_rule_ty()),
        ("STITOp", stit_op_ty()),
        ("DeliberativeSTIT", deliberative_stit_ty()),
        ("AchievementSTIT", achievement_stit_ty()),
        ("DeonticSTIT", deontic_stit_ty()),
        ("GradedDiamond", graded_diamond_ty()),
        ("GradedBox", graded_box_ty()),
        ("ProbabilisticModality", probabilistic_modality_ty()),
        ("CoalgebraFunctor", coalgebra_functor_ty()),
        ("ModalCoalgebra", modal_coalgebra_ty()),
        ("Real", type0()),
        ("BeliefSet", belief_set_ty()),
        ("belief_revision", belief_revision_ty()),
        ("belief_contraction", belief_contraction_ty()),
        ("agm_success", agm_success_ty()),
        ("agm_consistency", agm_consistency_ty()),
    ];
    for (name, ty) in axioms {
        env.add(Declaration::Axiom {
            name: Name::str(*name),
            univ_params: vec![],
            ty: ty.clone(),
        })
        .ok();
    }
}
/// Propositional variable identifier.
pub type PropVar = u32;
/// Check if a formula belongs to the Sahlqvist class (simplified syntactic check).
pub fn classify_sahlqvist(phi: &ModalFormula) -> SahlqvistClass {
    match phi {
        ModalFormula::Implies(ant, cons) => {
            if is_sahlqvist_antecedent(ant) && is_positive(cons) {
                SahlqvistClass::Full
            } else {
                SahlqvistClass::NotSahlqvist
            }
        }
        _ if is_positive(phi) => SahlqvistClass::Consequent,
        _ => SahlqvistClass::NotSahlqvist,
    }
}
/// Check if a formula is a Sahlqvist antecedent (negative formulas under diamonds).
pub fn is_sahlqvist_antecedent(phi: &ModalFormula) -> bool {
    match phi {
        ModalFormula::Atom(_) | ModalFormula::Top | ModalFormula::Bot => true,
        ModalFormula::Not(psi) => is_positive(psi),
        ModalFormula::And(a, b) => is_sahlqvist_antecedent(a) && is_sahlqvist_antecedent(b),
        ModalFormula::Diamond(_, psi) => is_sahlqvist_antecedent(psi),
        ModalFormula::Box(_, psi) => is_sahlqvist_antecedent(psi),
        _ => false,
    }
}
/// Check if a formula is positive (no negations except at atoms).
pub fn is_positive(phi: &ModalFormula) -> bool {
    match phi {
        ModalFormula::Atom(_) | ModalFormula::Top | ModalFormula::Bot => true,
        ModalFormula::Not(_) => false,
        ModalFormula::And(a, b) | ModalFormula::Or(a, b) | ModalFormula::Implies(a, b) => {
            is_positive(a) && is_positive(b)
        }
        ModalFormula::Box(_, psi) | ModalFormula::Diamond(_, psi) => is_positive(psi),
    }
}
/// Compute the largest bisimulation between two models using the partition refinement algorithm.
pub fn compute_bisimulation(m1: &KripkeModel, m2: &KripkeModel) -> Bisimulation {
    let mut bisim = Bisimulation::new();
    for w in 0..m1.frame.n_worlds {
        for v in 0..m2.frame.n_worlds {
            let agree = m1
                .valuation
                .keys()
                .all(|&p| m1.prop_true(p, w) == m2.prop_true(p, v));
            if agree {
                bisim.add_pair(w, v);
            }
        }
    }
    bisim
}
#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_kripke_frame_reflexive() {
        let mut frame = KripkeFrame::new(3, 1);
        frame.make_reflexive(0);
        assert!(frame.is_reflexive(0));
        assert!(frame.is_symmetric(0));
        frame.add_edge(0, 0, 1);
        assert!(!frame.is_symmetric(0));
    }
    #[test]
    fn test_kripke_frame_transitive() {
        let mut frame = KripkeFrame::new(3, 1);
        frame.add_edge(0, 0, 1);
        frame.add_edge(0, 1, 2);
        assert!(!frame.is_transitive(0));
        frame.make_transitive(0);
        assert!(frame.is_transitive(0));
        assert!(frame.accessible(0, 0, 2));
    }
    #[test]
    fn test_kripke_model_satisfaction() {
        let mut frame = KripkeFrame::new(2, 1);
        frame.add_edge(0, 0, 1);
        let mut model = KripkeModel::new(frame);
        model.set_true(0, 1);
        let box_p = ModalFormula::necessity(ModalFormula::atom(0));
        assert!(model.satisfies(0, &box_p));
        let dia_p = ModalFormula::possibility(ModalFormula::atom(0));
        assert!(!model.satisfies(1, &dia_p));
    }
    #[test]
    fn test_s4_frame_validation() {
        let mut frame = KripkeFrame::new(3, 1);
        frame.make_reflexive(0);
        frame.add_edge(0, 0, 1);
        frame.add_edge(0, 1, 2);
        frame.make_transitive(0);
        assert!(ModalSystem::S4.frame_validates(&frame, 0));
        assert!(!ModalSystem::S5.frame_validates(&frame, 0));
    }
    #[test]
    fn test_modal_formula_depth() {
        let p = ModalFormula::atom(0);
        let box_p = ModalFormula::necessity(p.clone());
        let box_box_p = ModalFormula::necessity(box_p.clone());
        assert_eq!(p.modal_depth(), 0);
        assert_eq!(box_p.modal_depth(), 1);
        assert_eq!(box_box_p.modal_depth(), 2);
    }
    #[test]
    fn test_canonical_model_construction() {
        let mut canon = CanonicalModel::new();
        let mcs0 = MaximalConsistentSet::new(
            0,
            vec![
                ModalFormula::atom(0),
                ModalFormula::necessity(ModalFormula::atom(1)),
            ],
        );
        let mcs1 = MaximalConsistentSet::new(1, vec![ModalFormula::atom(1)]);
        canon.add_world(mcs0);
        canon.add_world(mcs1);
        canon.build_accessibility();
        assert_eq!(canon.size(), 2);
        assert!(canon.accessibility.contains(&(0, 1)));
    }
    #[test]
    fn test_epistemic_model_knows() {
        let mut model = EpistemicModel::new(3, 1);
        model.add_edge(0, 0, 0);
        model.add_edge(0, 0, 1);
        model.valuation.entry(0).or_default().insert(0);
        model.valuation.entry(0).or_default().insert(1);
        let p = ModalFormula::atom(0);
        assert!(model.knows(0, 0, &p));
    }
    #[test]
    fn test_public_announcement_update() {
        let mut model = EpistemicModel::new(3, 1);
        model.make_equivalence_relations();
        model.valuation.entry(0).or_default().insert(0);
        model.valuation.entry(0).or_default().insert(1);
        let ann = PublicAnnouncement::new(ModalFormula::atom(0));
        let updated = ann.update(&model);
        assert_eq!(updated.n_worlds, 2);
    }
    #[test]
    fn test_build_modal_logic_env() {
        let mut env = Environment::new();
        build_modal_logic_env(&mut env);
        assert!(env.get(&Name::str("KripkeFrame")).is_some());
        assert!(env.get(&Name::str("AxiomLob")).is_some());
        assert!(env.get(&Name::str("sahlqvist_completeness")).is_some());
        assert!(env.get(&Name::str("ProductUpdate")).is_some());
        assert!(env.get(&Name::str("PDLBox")).is_some());
        assert!(env.get(&Name::str("LTLUntil")).is_some());
        assert!(env.get(&Name::str("ATLCoalition")).is_some());
        assert!(env.get(&Name::str("HybridAt")).is_some());
        assert!(env.get(&Name::str("AxiomM")).is_some());
        assert!(env.get(&Name::str("JustificationOp")).is_some());
        assert!(env.get(&Name::str("mu_least_fp")).is_some());
        assert!(env.get(&Name::str("barcan_formula")).is_some());
        assert!(env.get(&Name::str("GradedDiamond")).is_some());
        assert!(env.get(&Name::str("belief_revision")).is_some());
    }
    #[test]
    fn test_pdl_model_sequence() {
        let mut frame = KripkeFrame::new(3, 2);
        frame.add_edge(0, 0, 1);
        frame.add_edge(1, 1, 2);
        let mut kripke = KripkeModel::new(frame);
        kripke.set_true(0, 2);
        let pdl = PdlModel::new(kripke, 2);
        let alpha = PdlProgram::Atomic(0);
        let beta = PdlProgram::Atomic(1);
        let seq = PdlProgram::Sequence(Box::new(alpha), Box::new(beta));
        let reachable = pdl.reachable(0, &seq);
        assert!(reachable.contains(&2));
        assert_eq!(reachable.len(), 1);
        let p = ModalFormula::atom(0);
        assert!(pdl.box_program(0, &seq, &p));
    }
    #[test]
    fn test_pdl_model_star() {
        let mut frame = KripkeFrame::new(4, 1);
        frame.add_edge(0, 0, 1);
        frame.add_edge(0, 1, 2);
        frame.add_edge(0, 2, 3);
        let kripke = KripkeModel::new(frame);
        let pdl = PdlModel::new(kripke, 1);
        let alpha = PdlProgram::Atomic(0);
        let star = PdlProgram::Star(Box::new(alpha));
        let reachable = pdl.reachable(0, &star);
        assert_eq!(reachable.len(), 4);
        for w in 0..4 {
            assert!(reachable.contains(&w));
        }
    }
    #[test]
    fn test_finite_trace_ltl() {
        let mut trace = FiniteTrace::new();
        let mut s0 = HashMap::new();
        s0.insert(0u32, true);
        trace.push(s0);
        let mut s1 = HashMap::new();
        s1.insert(0u32, false);
        trace.push(s1);
        let mut s2 = HashMap::new();
        s2.insert(0u32, true);
        trace.push(s2);
        let p = ModalFormula::atom(0);
        let finally_p = ModalFormula::Diamond(0, Box::new(p.clone()));
        assert!(trace.check(&finally_p));
        let globally_p = ModalFormula::Box(0, Box::new(p.clone()));
        assert!(!trace.check(&globally_p));
        let next_p = ModalFormula::Box(1, Box::new(p.clone()));
        assert!(!trace.check(&next_p));
        assert!(trace.satisfies(2, &globally_p));
    }
    #[test]
    fn test_graded_model() {
        let mut frame = KripkeFrame::new(5, 1);
        for v in 1..=4 {
            frame.add_edge(0, 0, v);
        }
        let mut kripke = KripkeModel::new(frame);
        for w in 1..=3 {
            kripke.set_true(0, w);
        }
        let model = GradedModel::new(kripke);
        let p = ModalFormula::atom(0);
        assert!(model.graded_diamond(0, 3, &p));
        assert!(!model.graded_diamond(0, 4, &p));
        assert!(model.graded_box(0, 1, &p));
        assert!(!model.graded_box(0, 0, &p));
        assert_eq!(model.count_satisfying(0, &p), 3);
    }
    #[test]
    fn test_belief_revision_agm() {
        let mut bro = BeliefRevisionOp::new();
        let p = ModalFormula::atom(0);
        let q = ModalFormula::atom(1);
        let neg_p = ModalFormula::not(p.clone());
        bro.add_belief(p.clone(), 5);
        bro.add_belief(q.clone(), 3);
        bro.add_belief(neg_p.clone(), 1);
        assert!(bro.believes(&p));
        assert_eq!(bro.size(), 3);
        let revised = bro.revise(&p);
        assert!(revised.believes(&p));
        assert!(!revised.believes(&neg_p));
        let contracted = bro.contract(&p);
        assert!(!contracted.believes(&p));
        assert!(contracted.believes(&q));
    }
    #[test]
    fn test_mu_calculus_reachability() {
        let mut frame = KripkeFrame::new(3, 1);
        frame.add_edge(0, 0, 1);
        frame.add_edge(0, 1, 2);
        let mut kripke = KripkeModel::new(frame);
        kripke.set_true(0, 2);
        let eval = MuCalculusEval::new(kripke);
        let goal = ModalFormula::atom(0);
        let reachable = eval.reachability(&goal);
        assert!(reachable.contains(&0));
        assert!(reachable.contains(&1));
        assert!(reachable.contains(&2));
    }
    #[test]
    fn test_mu_calculus_safety() {
        let mut frame = KripkeFrame::new(3, 1);
        frame.add_edge(0, 0, 1);
        frame.add_edge(0, 0, 2);
        let mut kripke = KripkeModel::new(frame);
        kripke.set_true(0, 0);
        kripke.set_true(0, 1);
        let eval = MuCalculusEval::new(kripke);
        let safe = ModalFormula::atom(0);
        let safe_worlds = eval.safety(&safe);
        assert!(!safe_worlds.contains(&0));
        assert!(safe_worlds.contains(&1));
        assert!(!safe_worlds.contains(&2));
    }
}