-
Notifications
You must be signed in to change notification settings - Fork 2
/
foform.maude
1665 lines (1506 loc) · 77.9 KB
/
foform.maude
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
--- name: foform.maude
--- reqs: prelude.maude (META-LEVEL), full-maude.maude (SUBSTITUTION-HANDLING), metafresh.maude (RENAME-METAVARS), prelude-aux (VARIABLES-TO-CONSTANTS,BOOL-ERR)
--- note: This file implements a first-order logic formula datatype. The main
--- datatype is defined in FOFORM. Various functionalities are provided
--- to compute normal forms: NNF, PNF, DNF, and CNF or simplify/rename
--- formulas. These functions are stored in separate modules from FOFORM
--- and are called through META-LEVEL reflection. This isolates the
--- modules from one another and simplifies the algorithm design.
fmod REFLECT is
pr META-LEVEL .
pr UNIT-FM .
op modReduce : Module Term -> [Term] .
op redReflect : Qid Term -> [Term] .
op sortReflect : Qid Term Type -> [Bool] .
var Mod : Module .
var M : Qid .
var T : Term .
var TY : Type .
eq modReduce(Mod,T) = if Mod =/= noModule then getTerm(metaReduce(Mod,T)) else T fi .
eq redReflect(M,T) = getTerm(metaReduce(upModule(M,false),T)) .
eq sortReflect(M,T,TY) = sortLeq(upModule(M,false),leastSort(upModule(M,false),T),TY) .
endfm
fmod FOFORM is
pr META-LEVEL .
--- NOTE: This sort structure is complicated. Edit at your own risk (unless you want to simplify it).
--- Sort Declarations
--- Non-Empty/Possibly Empty Forms
sort TrueAtom FalseAtom TruthAtom PosEqAtom NegEqAtom Truth+PosEqAtom Truth+NegEqAtom EqAtom Atom .
sort ConstConj PosEqConj NegEqConj EqConj PosConj NegConj Conj .
sort ConstDisj PosEqDisj NegEqDisj EqDisj PosDisj NegDisj Disj .
sort PosEqQFForm NegEqQFForm EqQFForm QFForm AEQForm FOForm .
sort EmptyForm TruthAtom? PosEqAtom? NegEqAtom? Truth+NegEqAtom? Truth+PosEqAtom? EqAtom? Atom? .
sort ConstConj? PosEqConj? NegEqConj? EqConj? PosConj? NegConj? Conj? .
sort ConstDisj? PosEqDisj? NegEqDisj? EqDisj? PosDisj? NegDisj? Disj? .
sort PosEqQFForm? NegEqQFForm? EqQFForm? QFForm? AEQForm? FOForm? .
--- Subsorting
--- Atoms
subsort TrueAtom FalseAtom < TruthAtom .
subsort PosEqAtom NegEqAtom < EqAtom < Atom .
subsort TruthAtom PosEqAtom < Truth+PosEqAtom < Atom .
subsort TruthAtom NegEqAtom < Truth+NegEqAtom < Atom .
--- Non-Atoms
subsort PosEqConj PosEqDisj < PosEqQFForm < EqQFForm .
subsort NegEqConj NegEqDisj < NegEqQFForm < EqQFForm .
subsort EqConj EqDisj EqAtom < EqQFForm < QFForm .
subsort Atom < Conj Disj < QFForm < FOForm .
subsort AEQForm < FOForm .
--- Conjunctions/Disjunctions
subsort PosEqAtom < PosEqConj < PosConj .
subsort NegEqAtom < NegEqConj < NegConj .
subsort PosEqAtom < PosEqDisj < PosDisj .
subsort NegEqAtom < NegEqDisj < NegDisj .
subsort PosEqConj NegEqConj EqAtom < EqConj < Conj .
subsort PosEqDisj NegEqDisj EqAtom < EqDisj < Disj .
subsort TruthAtom < ConstConj < PosConj NegConj < Conj .
subsort TruthAtom < ConstDisj < PosDisj NegDisj < Disj .
subsort Truth+PosEqAtom < PosConj PosDisj .
subsort Truth+NegEqAtom < NegConj NegDisj .
--- Link Non-Empty/Possibly Empty Forms
subsort TruthAtom < TruthAtom? . subsort PosEqAtom < PosEqAtom? .
subsort Truth+PosEqAtom < Truth+PosEqAtom? . subsort NegEqAtom < NegEqAtom? .
subsort EqAtom < EqAtom? . subsort Atom < Atom? .
subsort Truth+NegEqAtom < Truth+NegEqAtom? . subsort PosEqConj < PosEqConj? .
subsort ConstConj < ConstConj? . subsort NegEqConj < NegEqConj? .
subsort EqConj < EqConj? . subsort Conj < Conj? .
subsort PosConj < PosConj? . subsort PosEqDisj < PosEqDisj? .
subsort NegConj < NegConj? . subsort NegEqDisj < NegEqDisj? .
subsort ConstDisj < ConstDisj? . subsort PosDisj < PosDisj? .
subsort NegDisj < NegDisj? . subsort EqDisj < EqDisj? .
subsort QFForm < QFForm? . subsort Disj < Disj? .
subsort FOForm < FOForm? . subsort AEQForm < AEQForm? .
subsort EqQFForm < EqQFForm? . subsort PosEqQFForm < PosEqQFForm? .
subsort NegEqQFForm < NegEqQFForm? .
--- Possibly Empty Atoms
subsort EmptyForm < TruthAtom? < Truth+PosEqAtom? Truth+NegEqAtom? < Atom? .
subsort EmptyForm < PosEqAtom? NegEqAtom? < EqAtom? < Atom? .
subsort EmptyForm < TruthAtom? PosEqAtom? < Truth+PosEqAtom? .
subsort EmptyForm < TruthAtom? NegEqAtom? < Truth+NegEqAtom? .
--- Possibly Empty Non-Atoms
subsort EmptyForm < PosEqConj? PosEqDisj? < PosEqQFForm? < EqQFForm? .
subsort EmptyForm < NegEqConj? NegEqDisj? < NegEqQFForm? < EqQFForm? .
subsort EmptyForm < EqConj? EqDisj? EqAtom? < EqQFForm? < QFForm? .
subsort EmptyForm < Atom? < Conj? Disj? < QFForm? < FOForm? .
subsort EmptyForm < AEQForm? < FOForm? .
--- Possibly Empty Conjunctions/Disjunctions
subsort EmptyForm < PosEqAtom? < PosEqConj? < PosConj? .
subsort EmptyForm < NegEqAtom? < NegEqConj? < NegConj? .
subsort EmptyForm < PosEqAtom? < PosEqDisj? < PosDisj? .
subsort EmptyForm < NegEqAtom? < NegEqDisj? < NegDisj? .
subsort EmptyForm < PosEqConj? NegEqConj? EqAtom? < EqConj? < Conj? .
subsort EmptyForm < PosEqDisj? NegEqDisj? EqAtom? < EqDisj? < Disj? .
subsort EmptyForm < TruthAtom? < ConstConj? < PosConj? NegConj? < Conj? .
subsort EmptyForm < TruthAtom? < ConstDisj? < PosDisj? NegDisj? < Disj? .
subsort EmptyForm < Truth+PosEqAtom? < PosConj? PosDisj? .
subsort EmptyForm < Truth+NegEqAtom? < NegConj? NegDisj? .
--- Atomic Formulas
op mtForm : -> EmptyForm [ctor] .
op tt : -> TrueAtom [ctor] .
op ff : -> FalseAtom [ctor] .
op _?=_ : Term Term -> PosEqAtom [ctor comm prec 50] .
op _!=_ : Term Term -> NegEqAtom [ctor comm prec 50] .
--- Non-empty Conjunctions/Disjunctions (NeSets)
op _/\_ : ConstConj? ConstConj -> ConstConj [ctor assoc comm id: mtForm prec 51] .
op _/\_ : PosEqConj? PosEqConj -> PosEqConj [ctor ditto] .
op _/\_ : NegEqConj? NegEqConj -> NegEqConj [ctor ditto] .
op _/\_ : EqConj? EqConj -> EqConj [ctor ditto] .
op _/\_ : PosConj? PosConj -> PosConj [ctor ditto] .
op _/\_ : NegConj? NegConj -> NegConj [ctor ditto] .
op _/\_ : Conj? Conj -> Conj [ctor ditto] .
op _/\_ : PosEqQFForm? PosEqQFForm -> PosEqQFForm [ctor ditto] .
op _/\_ : NegEqQFForm? NegEqQFForm -> NegEqQFForm [ctor ditto] .
op _/\_ : EqQFForm? EqQFForm -> EqQFForm [ctor ditto] .
op _/\_ : QFForm? QFForm -> QFForm [ctor ditto] .
op _/\_ : AEQForm? AEQForm -> AEQForm [ctor ditto] .
op _/\_ : FOForm? FOForm -> FOForm [ctor ditto] .
op _\/_ : ConstDisj? ConstDisj -> ConstDisj [ctor assoc comm id: mtForm prec 51] .
op _\/_ : PosEqDisj? PosEqDisj -> PosEqDisj [ctor ditto] .
op _\/_ : NegEqDisj? NegEqDisj -> NegEqDisj [ctor ditto] .
op _\/_ : EqDisj? EqDisj -> EqDisj [ctor ditto] .
op _\/_ : PosDisj? PosDisj -> PosDisj [ctor ditto] .
op _\/_ : NegDisj? NegDisj -> NegDisj [ctor ditto] .
op _\/_ : Disj? Disj -> Disj [ctor ditto] .
op _\/_ : PosEqQFForm? PosEqQFForm -> PosEqQFForm [ctor ditto] .
op _\/_ : NegEqQFForm? NegEqQFForm -> NegEqQFForm [ctor ditto] .
op _\/_ : EqQFForm? EqQFForm -> EqQFForm [ctor ditto] .
op _\/_ : QFForm? QFForm -> QFForm [ctor ditto] .
op _\/_ : AEQForm? AEQForm -> AEQForm [ctor ditto] .
op _\/_ : FOForm? FOForm -> FOForm [ctor ditto] .
--- Possibly Empty Conjunctions/Disjunctions (Sets)
op _/\_ : PosEqConj? PosEqConj? -> PosEqConj? [ctor ditto] .
op _/\_ : NegEqConj? NegEqConj? -> NegEqConj? [ctor ditto] .
op _/\_ : EqConj? EqConj? -> EqConj? [ctor ditto] .
op _/\_ : EmptyForm EmptyForm -> EmptyForm [ctor ditto] .
op _/\_ : ConstConj? ConstConj? -> ConstConj? [ctor ditto] .
op _/\_ : PosConj? PosConj? -> PosConj? [ctor ditto] .
op _/\_ : NegConj? NegConj? -> NegConj? [ctor ditto] .
op _/\_ : Conj? Conj? -> Conj? [ctor ditto] .
op _/\_ : PosEqQFForm? PosEqQFForm? -> PosEqQFForm? [ctor ditto] .
op _/\_ : NegEqQFForm? NegEqQFForm? -> NegEqQFForm? [ctor ditto] .
op _/\_ : EqQFForm? EqQFForm? -> EqQFForm? [ctor ditto] .
op _/\_ : QFForm? QFForm? -> QFForm? [ctor ditto] .
op _/\_ : AEQForm? AEQForm? -> AEQForm? [ctor ditto] .
op _/\_ : FOForm? FOForm? -> FOForm? [ctor ditto] .
op _\/_ : EmptyForm EmptyForm -> EmptyForm [ctor ditto] .
op _\/_ : ConstDisj? ConstDisj? -> ConstDisj? [ctor ditto] .
op _\/_ : PosEqDisj? PosEqDisj? -> PosEqDisj? [ctor ditto] .
op _\/_ : NegEqDisj? NegEqDisj? -> NegEqDisj? [ctor ditto] .
op _\/_ : EqDisj? EqDisj? -> EqDisj? [ctor ditto] .
op _\/_ : PosDisj? PosDisj? -> PosDisj? [ctor ditto] .
op _\/_ : NegDisj? NegDisj? -> NegDisj? [ctor ditto] .
op _\/_ : Disj? Disj? -> Disj? [ctor ditto] .
op _\/_ : PosEqQFForm? PosEqQFForm? -> PosEqQFForm? [ctor ditto] .
op _\/_ : NegEqQFForm? NegEqQFForm? -> NegEqQFForm? [ctor ditto] .
op _\/_ : EqQFForm? EqQFForm? -> EqQFForm? [ctor ditto] .
op _\/_ : QFForm? QFForm? -> QFForm? [ctor ditto] .
op _\/_ : AEQForm? AEQForm? -> AEQForm? [ctor ditto] .
op _\/_ : FOForm? FOForm? -> FOForm? [ctor ditto] .
--- Negations and Quantifiers
op ~_ : Atom -> Atom [ctor prec 49] .
op ~_ : QFForm -> QFForm [ctor ditto] .
op ~_ : AEQForm -> AEQForm [ctor ditto] .
op ~_ : FOForm -> FOForm [ctor ditto] .
op A[_]_ : NeQidSet QFForm -> AEQForm [ctor prec 52] .
op E[_]_ : NeQidSet QFForm -> AEQForm [ctor prec 52] .
op A[_]_ : NeQidSet AEQForm -> AEQForm [ctor ditto] .
op E[_]_ : NeQidSet AEQForm -> AEQForm [ctor ditto] .
op A[_]_ : NeQidSet FOForm -> FOForm [ctor ditto] .
op E[_]_ : NeQidSet FOForm -> FOForm [ctor ditto] .
op A[_]_ : QidSet QFForm -> AEQForm [ditto] .
op E[_]_ : QidSet QFForm -> AEQForm [ditto] .
op A[_]_ : QidSet AEQForm -> AEQForm [ditto] .
op E[_]_ : QidSet AEQForm -> AEQForm [ditto] .
op A[_]_ : QidSet FOForm -> FOForm [ditto] .
op E[_]_ : QidSet FOForm -> FOForm [ditto] .
--- Error Terms
op error : String -> [FOForm] [ctor] .
--- Remove useless quantifiers
eq A[none] F:AEQForm = F:AEQForm .
eq E[none] F:AEQForm = F:AEQForm .
var S : String . var FK FK' : [FOForm] . var QS : QidSet .
op getFOFormErrMsg : [FOForm] -> String .
ceq getFOFormErrMsg(FK /\ FK') = getFOFormErrMsg(FK) + getFOFormErrMsg(FK') if FK =/= mtForm and FK' =/= mtForm .
ceq getFOFormErrMsg(FK \/ FK') = getFOFormErrMsg(FK) + getFOFormErrMsg(FK') if FK =/= mtForm and FK' =/= mtForm .
eq getFOFormErrMsg(A[QS] FK) = getFOFormErrMsg(FK) .
eq getFOFormErrMsg(E[QS] FK) = getFOFormErrMsg(FK) .
eq getFOFormErrMsg(~ FK) = getFOFormErrMsg(FK) .
eq getFOFormErrMsg(error(S)) = S .
eq getFOFormErrMsg(FK) = "" [owise] .
endfm
fmod FOFORMSET is
pr FOFORM .
sort FormEmptySet .
sort TruthAtomSet PosEqAtomSet NegEqAtomSet Truth+PosEqAtomSet Truth+NegEqAtomSet EqAtomSet AtomSet .
sort ConstConjSet PosEqConjSet NegEqConjSet EqConjSet PosConjSet NegConjSet ConjSet .
sort ConstDisjSet PosEqDisjSet NegEqDisjSet EqDisjSet PosDisjSet NegDisjSet DisjSet .
sort PosEqQFFormSet NegEqQFFormSet EqQFFormSet QFFormSet AEQFormSet FOFormSet .
sort EmptyFormSet PosEqAtom?Set NegEqAtom?Set TruthAtom?Set Truth+NegEqAtom?Set Truth+PosEqAtom?Set EqAtom?Set Atom?Set .
sort ConstConj?Set PosEqConj?Set NegEqConj?Set EqConj?Set PosConj?Set NegConj?Set Conj?Set .
sort ConstDisj?Set PosEqDisj?Set NegEqDisj?Set EqDisj?Set PosDisj?Set NegDisj?Set Disj?Set .
sort PosEqQFForm?Set NegEqQFForm?Set EqQFForm?Set QFForm?Set AEQForm?Set FOForm?Set .
--- Subsorting
subsort EmptyForm < EmptyFormSet .
subsort TruthAtom < TruthAtomSet . subsort TruthAtom? < TruthAtom?Set .
subsort PosEqAtom < PosEqAtomSet . subsort PosEqAtom? < PosEqAtom?Set .
subsort NegEqAtom < NegEqAtomSet . subsort NegEqAtom? < NegEqAtom?Set .
subsort Truth+PosEqAtom < Truth+PosEqAtomSet . subsort Truth+PosEqAtom? < Truth+PosEqAtom?Set .
subsort Truth+NegEqAtom < Truth+NegEqAtomSet . subsort Truth+NegEqAtom? < Truth+NegEqAtom?Set .
subsort EqAtom < EqAtomSet . subsort EqAtom? < EqAtom?Set .
subsort Atom < AtomSet . subsort Atom? < Atom?Set .
subsort ConstConj < ConstConjSet . subsort ConstConj? < ConstConj?Set .
subsort PosEqConj < PosEqConjSet . subsort PosEqConj? < PosEqConj?Set .
subsort NegEqConj < NegEqConjSet . subsort NegEqConj? < NegEqConj?Set .
subsort EqConj < EqConjSet . subsort EqConj? < EqConj?Set .
subsort PosConj < PosConjSet . subsort PosConj? < PosConj?Set .
subsort NegConj < NegConjSet . subsort NegConj? < NegConj?Set .
subsort Conj < ConjSet . subsort Conj? < Conj?Set .
subsort ConstDisj < ConstDisjSet . subsort ConstDisj? < ConstDisj?Set .
subsort PosEqDisj < PosEqDisjSet . subsort PosEqDisj? < PosEqDisj?Set .
subsort NegEqDisj < NegEqDisjSet . subsort NegEqDisj? < NegEqDisj?Set .
subsort EqDisj < EqDisjSet . subsort EqDisj? < EqDisj?Set .
subsort PosDisj < PosDisjSet . subsort PosDisj? < PosDisj?Set .
subsort NegDisj < NegDisjSet . subsort NegDisj? < NegDisj?Set .
subsort Disj < DisjSet . subsort Disj? < Disj?Set .
subsort PosEqQFForm < PosEqQFFormSet . subsort PosEqQFForm? < PosEqQFForm?Set .
subsort NegEqQFForm < NegEqQFFormSet . subsort NegEqQFForm? < NegEqQFForm?Set .
subsort EqQFForm < EqQFFormSet . subsort EqQFForm? < EqQFForm?Set .
subsort QFForm < QFFormSet . subsort QFForm? < QFForm?Set .
subsort AEQForm < AEQFormSet . subsort AEQForm? < AEQForm?Set .
subsort FOForm < FOFormSet . subsort FOForm? < FOForm?Set .
--- Atoms Sets
subsort FormEmptySet < PosEqAtomSet NegEqAtomSet < EqAtomSet < AtomSet .
subsort FormEmptySet < TruthAtomSet PosEqAtomSet < Truth+PosEqAtomSet < AtomSet .
subsort FormEmptySet < TruthAtomSet NegEqAtomSet < Truth+NegEqAtomSet < AtomSet .
--- Non-Atom Sets
subsort PosEqConjSet PosEqDisjSet < PosEqQFFormSet < EqQFFormSet .
subsort NegEqConjSet NegEqDisjSet < NegEqQFFormSet < EqQFFormSet .
subsort EqConjSet EqDisjSet EqAtomSet < EqQFFormSet < QFFormSet .
subsort AtomSet < ConjSet DisjSet < QFFormSet < FOFormSet .
subsort FormEmptySet < AEQFormSet < FOFormSet .
--- Conjunctions/Disjunctions Sets
subsort PosEqAtomSet < PosEqConjSet < PosConjSet .
subsort NegEqAtomSet < NegEqConjSet < NegConjSet .
subsort PosEqAtomSet < PosEqDisjSet < PosDisjSet .
subsort NegEqAtomSet < NegEqDisjSet < NegDisjSet .
subsort PosEqConjSet NegEqConjSet EqAtomSet < EqConjSet < ConjSet .
subsort PosEqDisjSet NegEqDisjSet EqAtomSet < EqDisjSet < DisjSet .
subsort TruthAtomSet < ConstConjSet < PosConjSet NegConjSet < ConjSet .
subsort TruthAtomSet < ConstDisjSet < PosDisjSet NegDisjSet < DisjSet .
subsort Truth+PosEqAtomSet < PosConjSet PosDisjSet .
subsort Truth+NegEqAtomSet < NegConjSet NegDisjSet .
--- Link Non-Empty/Possibly Empty Forms
subsort TruthAtomSet < TruthAtom?Set . subsort PosEqAtomSet < PosEqAtom?Set .
subsort NegEqAtomSet < NegEqAtom?Set . subsort EqAtomSet < EqAtom?Set .
subsort Truth+PosEqAtomSet < Truth+PosEqAtom?Set . subsort Truth+NegEqAtomSet < Truth+NegEqAtom?Set .
subsort AtomSet < Atom?Set . subsort NegEqConjSet < NegEqConj?Set .
subsort PosEqConjSet < PosEqConj?Set . subsort EqConjSet < EqConj?Set .
subsort ConstConjSet < ConstConj?Set . subsort ConjSet < Conj?Set .
subsort PosConjSet < PosConj?Set . subsort PosEqDisjSet < PosEqDisj?Set .
subsort NegConjSet < NegConj?Set . subsort NegEqDisjSet < NegEqDisj?Set .
subsort ConstDisjSet < ConstDisj?Set . subsort EqDisjSet < EqDisj?Set .
subsort PosDisjSet < PosDisj?Set . subsort DisjSet < Disj?Set .
subsort NegDisjSet < NegDisj?Set . subsort AEQFormSet < AEQForm?Set .
subsort PosEqQFFormSet < PosEqQFForm?Set . subsort NegEqQFFormSet < NegEqQFForm?Set .
subsort EqQFFormSet < EqQFForm?Set . subsort QFFormSet < QFForm?Set .
subsort FOFormSet < FOForm?Set .
--- Possibly Empty Atoms Sets
subsort FormEmptySet < EmptyFormSet .
subsort EmptyFormSet < PosEqAtom?Set NegEqAtom?Set < EqAtom?Set < Atom?Set .
subsort EmptyFormSet < TruthAtom?Set PosEqAtom?Set < Truth+PosEqAtom?Set < Atom?Set .
subsort EmptyFormSet < TruthAtom?Set NegEqAtom?Set < Truth+NegEqAtom?Set < Atom?Set .
--- Possibly Empty Non-Atom Sets
subsort PosEqConj?Set PosEqDisj?Set < PosEqQFForm?Set < EqQFForm?Set .
subsort NegEqConj?Set NegEqDisj?Set < NegEqQFForm?Set < EqQFForm?Set .
subsort EqConj?Set EqDisj?Set EqAtom?Set < EqQFForm?Set < QFForm?Set .
subsort Atom?Set < Conj?Set Disj?Set < QFForm?Set < FOForm?Set .
subsort EmptyFormSet < AEQForm?Set < FOForm?Set .
--- Possibly Empty Conjunctions/Disjunctions
subsort EmptyFormSet < PosEqAtom?Set < PosEqConj?Set < PosConj?Set .
subsort EmptyFormSet < NegEqAtom?Set < NegEqConj?Set < NegConj?Set .
subsort EmptyFormSet < PosEqAtom?Set < PosEqDisj?Set < PosDisj?Set .
subsort EmptyFormSet < NegEqAtom?Set < NegEqDisj?Set < NegDisj?Set .
subsort EmptyFormSet < PosEqConj?Set NegEqConj?Set EqAtom?Set < EqConj?Set < Conj?Set .
subsort EmptyFormSet < PosEqDisj?Set NegEqDisj?Set EqAtom?Set < EqDisj?Set < Disj?Set .
subsort EmptyFormSet < TruthAtom?Set < ConstConj?Set < PosConj?Set NegConj?Set < Conj?Set .
subsort EmptyFormSet < TruthAtom?Set < ConstDisj?Set < PosDisj?Set NegDisj?Set < Disj?Set .
subsort EmptyFormSet < Truth+PosEqAtom?Set < PosConj?Set PosDisj?Set .
subsort EmptyFormSet < Truth+NegEqAtom?Set < NegConj?Set NegDisj?Set .
--- Empty [Formula Sets]
op mtFormSet : -> FormEmptySet [ctor] .
op _|_ : FormEmptySet FormEmptySet -> FormEmptySet [ctor assoc comm id: mtFormSet prec 53] .
--- [Non-Empty Formula] Sets
op _|_ : PosEqAtomSet PosEqAtomSet -> PosEqAtomSet [ctor ditto] .
op _|_ : NegEqAtomSet NegEqAtomSet -> NegEqAtomSet [ctor ditto] .
op _|_ : TruthAtomSet TruthAtomSet -> TruthAtomSet [ctor ditto] .
op _|_ : Truth+PosEqAtomSet Truth+PosEqAtomSet -> Truth+PosEqAtomSet [ctor ditto] .
op _|_ : Truth+NegEqAtomSet Truth+NegEqAtomSet -> Truth+NegEqAtomSet [ctor ditto] .
op _|_ : EqAtomSet EqAtomSet -> EqAtomSet [ctor ditto] .
op _|_ : AtomSet AtomSet -> AtomSet [ctor ditto] .
op _|_ : ConstConjSet ConstConjSet -> ConstConjSet [ctor ditto] .
op _|_ : PosEqConjSet PosEqConjSet -> PosEqConjSet [ctor ditto] .
op _|_ : NegEqConjSet NegEqConjSet -> NegEqConjSet [ctor ditto] .
op _|_ : EqConjSet EqConjSet -> EqConjSet [ctor ditto] .
op _|_ : PosConjSet PosConjSet -> PosConjSet [ctor ditto] .
op _|_ : NegConjSet NegConjSet -> NegConjSet [ctor ditto] .
op _|_ : ConjSet ConjSet -> ConjSet [ctor ditto] .
op _|_ : ConstDisjSet ConstDisjSet -> ConstDisjSet [ctor ditto] .
op _|_ : PosEqDisjSet PosEqDisjSet -> PosEqDisjSet [ctor ditto] .
op _|_ : NegEqDisjSet NegEqDisjSet -> NegEqDisjSet [ctor ditto] .
op _|_ : EqDisjSet EqDisjSet -> EqDisjSet [ctor ditto] .
op _|_ : PosDisjSet PosDisjSet -> PosDisjSet [ctor ditto] .
op _|_ : NegDisjSet NegDisjSet -> NegDisjSet [ctor ditto] .
op _|_ : DisjSet DisjSet -> DisjSet [ctor ditto] .
op _|_ : NegEqQFFormSet NegEqQFFormSet -> NegEqQFFormSet [ctor ditto] .
op _|_ : PosEqQFFormSet PosEqQFFormSet -> PosEqQFFormSet [ctor ditto] .
op _|_ : EqQFFormSet EqQFFormSet -> EqQFFormSet [ctor ditto] .
op _|_ : QFFormSet QFFormSet -> QFFormSet [ctor ditto] .
op _|_ : AEQFormSet AEQFormSet -> AEQFormSet [ctor ditto] .
op _|_ : FOFormSet FOFormSet -> FOFormSet [ctor ditto] .
--- [Possibly Empty Formula] Sets
op _|_ : EmptyFormSet EmptyFormSet -> EmptyFormSet [ctor ditto] .
op _|_ : PosEqAtom?Set PosEqAtom?Set -> PosEqAtom?Set [ctor ditto] .
op _|_ : NegEqAtom?Set NegEqAtom?Set -> NegEqAtom?Set [ctor ditto] .
op _|_ : TruthAtom?Set TruthAtom?Set -> TruthAtom?Set [ctor ditto] .
op _|_ : Truth+PosEqAtom?Set Truth+PosEqAtom?Set -> Truth+PosEqAtom?Set [ctor ditto] .
op _|_ : Truth+NegEqAtom?Set Truth+NegEqAtom?Set -> Truth+NegEqAtom?Set [ctor ditto] .
op _|_ : EqAtom?Set EqAtom?Set -> EqAtom?Set [ctor ditto] .
op _|_ : Atom?Set Atom?Set -> Atom?Set [ctor ditto] .
op _|_ : ConstConj?Set ConstConj?Set -> ConstConj?Set [ctor ditto] .
op _|_ : PosEqConj?Set PosEqConj?Set -> PosEqConj?Set [ctor ditto] .
op _|_ : NegEqConj?Set NegEqConj?Set -> NegEqConj?Set [ctor ditto] .
op _|_ : EqConj?Set EqConj?Set -> EqConj?Set [ctor ditto] .
op _|_ : PosConj?Set PosConj?Set -> PosConj?Set [ctor ditto] .
op _|_ : NegConj?Set NegConj?Set -> NegConj?Set [ctor ditto] .
op _|_ : Conj?Set Conj?Set -> Conj?Set [ctor ditto] .
op _|_ : ConstDisj?Set ConstDisj?Set -> ConstDisj?Set [ctor ditto] .
op _|_ : PosEqDisj?Set PosEqDisj?Set -> PosEqDisj?Set [ctor ditto] .
op _|_ : NegEqDisj?Set NegEqDisj?Set -> NegEqDisj?Set [ctor ditto] .
op _|_ : EqDisj?Set EqDisj?Set -> EqDisj?Set [ctor ditto] .
op _|_ : PosDisj?Set PosDisj?Set -> PosDisj?Set [ctor ditto] .
op _|_ : NegDisj?Set NegDisj?Set -> NegDisj?Set [ctor ditto] .
op _|_ : Disj?Set Disj?Set -> Disj?Set [ctor ditto] .
op _|_ : NegEqQFForm?Set NegEqQFForm?Set -> NegEqQFForm?Set [ctor ditto] .
op _|_ : PosEqQFForm?Set PosEqQFForm?Set -> PosEqQFForm?Set [ctor ditto] .
op _|_ : EqQFForm?Set EqQFForm?Set -> EqQFForm?Set [ctor ditto] .
op _|_ : QFForm?Set QFForm?Set -> QFForm?Set [ctor ditto] .
op _|_ : AEQForm?Set AEQForm?Set -> AEQForm?Set [ctor ditto] .
op _|_ : FOForm?Set FOForm?Set -> FOForm?Set [ctor ditto] .
endfm
fmod FOFORMBASICLIST is
pr FOFORM .
sort FormEmptyList .
sort QFForm?List FOForm?List .
subsort FormEmptyList QFForm? < QFForm?List .
subsort FormEmptyList FOForm? < FOForm?List .
subsort QFForm?List < FOForm?List .
op nilFormList : -> FormEmptyList [ctor] .
op _;_ : FormEmptyList FormEmptyList -> FormEmptyList [ctor assoc id: nilFormList] .
op _;_ : FOForm?List FOForm?List -> FOForm?List [ctor ditto] .
op _;_ : QFForm?List QFForm?List -> QFForm?List [ctor ditto] .
endfm
fmod FOFORM-CONVERSION is
pr FOFORMSET .
pr FOFORMBASICLIST .
op set2list : FOForm?Set -> FOForm?List .
op list2set : FOForm?List -> FOForm?Set .
var F : FOForm? . var FS : FOForm?Set . var FL : FOForm?List .
eq set2list(F | FS) = F ; set2list(FS) .
eq set2list(mtFormSet) = nilFormList .
eq list2set(F ; FL) = F | list2set(FL) .
eq list2set(nilFormList) = mtFormSet .
endfm
fmod FOFORM-DEFINEDOPS is
pr FOFORM .
op _==>_ : FOForm FOForm -> FOForm [ctor] .
op _<==>_ : FOForm FOForm -> FOForm [ctor] .
var F1 F2 : FOForm .
eq F1 ==> F2 = (~ F1) \/ F2 .
eq F1 <==> F2 = (F1 ==> F2) /\ (F2 ==> F1) .
endfm
fmod FOFORMSIMPLIFY-IMPL is
pr FOFORM .
var F G H K : FOForm . var K? : FOForm? .
var C : Conj . var D : Disj . var T T' : Term . var NTL : NeTermList .
eq ~ (T ?= T') = T != T' .
eq ~ (T != T') = T ?= T' .
eq ~ tt = ff .
eq ~ ff = tt .
eq F /\ F = F .
eq F \/ F = F .
eq tt /\ F = F .
eq ff \/ F = F .
eq ff /\ F = ff .
eq tt \/ F = tt .
eq F \/ ~ F = tt .
eq F /\ ~ F = ff .
eq (T ?= T' /\ T != T') = ff .
eq (T ?= T' \/ T != T') = tt .
eq T ?= T = tt .
eq T != T = ff .
endfm
fmod FOFORMSIMPLIFY-IMP-IMPL is
pr FOFORM .
var F G H K : FOForm . var K? : FOForm? .
var C : Conj . var D : Disj . var T T' : Term .
eq ~ tt = ff .
eq ~ ff = tt .
eq F /\ F = F .
eq F \/ F = F .
eq tt /\ F = F .
eq ff \/ F = F .
eq ff /\ F = ff .
eq tt \/ F = tt .
eq F \/ ~ F = tt .
eq F /\ ~ F = ff .
eq (T ?= T' /\ T != T') = ff .
eq (T ?= T' \/ T != T') = tt .
eq T ?= T = tt .
eq T != T = ff .
--- Implication
eq (~ (F /\ G)) \/ F = tt .
eq (~ F ) \/ ((F \/ K?) /\ H) = (~ F) \/ H .
eq (~ (F /\ G)) \/ ((F \/ K?) /\ H) = (~ G) \/ H .
--- Break up implication into clauses
eq (~ (F /\ (G \/ H)) ) \/ K = ((~ (F /\ G)) \/ K) /\ ((~ (F /\ H)) \/ K) .
endfm
fmod FOFORMSIMPLIFY is
pr FOFORM .
pr REFLECT .
op simplify : FOForm? ~> FOForm? .
op simplify-imp : FOForm ~> FOForm .
var F : FOForm .
eq simplify(F) = downTerm(redReflect('FOFORMSIMPLIFY-IMPL,upTerm(F)),error("FOForm Simplify Failed")) .
eq simplify(mtForm) = mtForm .
eq simplify-imp(F) = downTerm(redReflect('FOFORMSIMPLIFY-IMP-IMPL,upTerm(F)),error("FOForm Simplify Failed")) .
endfm
fmod FOFORMREDUCE is
pr FOFORM .
pr TERM-EXTRA . --- vars/groundLeastSortGreater function
pr CTOR-SIG . --- ctor-signautre
var F F' : FOForm . var T T' : Term . var M : Module . var A A' : Atom .
var Q : NeQidSet . var AT AF : TruthAtom . var B : Bool .
op reduce : Module FOForm? ~> FOForm? .
eq reduce(M,F) = reduce(M,true,F) .
op reduce : Module Bool FOForm? ~> FOForm? .
eq reduce(M,B,F /\ F') = reduce(M,B,F) /\ reduce(M,B,F') .
eq reduce(M,B,F \/ F') = reduce(M,B,F) \/ reduce(M,B,F') .
eq reduce(M,B,mtForm) = mtForm .
eq reduce(M,B,A[Q] F) = A[Q] reduce(M,B,F) .
eq reduce(M,B,E[Q] F) = E[Q] reduce(M,B,F) .
eq reduce(M,B,~ F) = ~ reduce(M,B,F) .
eq reduce(M,B,AT) = AT .
eq reduce(M,true, T ?= T') = reduceDebugPrint(T ?= T',reduce(M,tt,ff,metaReduce2(M,T),metaReduce2(M,T'))) .
eq reduce(M,true, T != T') = reduce(M,ff,tt,metaReduce2(M,T),metaReduce2(M,T')) .
eq reduce(M,false,T ?= T') = reduceDebugPrint(T ?= T',metaReduce2(M,T) ?= metaReduce2(M,T')) .
eq reduce(M,false,T != T') = metaReduce2(M,T) != metaReduce2(M,T') .
op reduce : Module Atom Atom Term Term ~> Atom .
eq reduce(M,AT,AF,T,T') =
if T == T'
then AT
else if groundLeastSortGreater(ctor-sig(M),T,T')
then AF
else if AT == tt
then T ?= T'
else T != T'
fi fi fi .
op reduceDebugPrint : Atom Atom -> Atom .
eq reduceDebugPrint(A,'false.Bool ?= 'true.Bool) = 'false.Bool ?= 'true.Bool [print "Atom Reduced to Contradiction: " A] .
eq reduceDebugPrint(A,A') = A' [owise] .
endfm
fmod FOFORM-OPERATIONS is
pr FOFORM .
pr TERM-EXTRA . --- defines vars() : Term -> QidSet
op size : FOForm? -> Nat .
op depth : FOForm? -> Nat .
op wellFormed : Module FOForm? -> Bool .
op $wellFormed : Module FOForm? -> Bool .
op normalize : Module FOForm? -> FOForm? .
op toUnifProb : PosConj -> UnificationProblem .
op $toUnifProb : PosConj -> UnificationProblem .
op trueId : FOForm? -> FOForm .
op falseId : FOForm? -> FOForm .
op true2mt : FOForm? -> FOForm? .
op false2mt : FOForm? -> FOForm? .
op vars : FOForm? -> QidSet .
var M : Module . var F? : FOForm? . var F1 F2 : FOForm . var QS : NeQidSet .
var TA : TruthAtom . var T T' : Term . var PC : PosConj . var C : Conj .
--- get the size/depth of a formula
eq size(A[QS] F1) = s(size(F1)) .
eq size(E[QS] F1) = s(size(F1)) .
eq size(F1 /\ F2) = s(size(F1) + size(F2)) .
eq size(F1 \/ F2) = s(size(F1) + size(F2)) .
eq size(~ F1) = s(size(F1)) .
eq size(A:Atom) = 1 .
eq size(mtForm) = 0 .
eq depth(A[QS] F1) = s(depth(F1)) .
eq depth(E[QS] F1) = s(depth(F1)) .
eq depth(F1 /\ F2) = s(max(depth(F1),depth(F2))) .
eq depth(F1 \/ F2) = s(max(depth(F1),depth(F2))) .
eq depth(~ F1) = s(depth(F1)) .
eq depth(A:Atom) = 1 .
eq depth(mtForm) = 0 .
--- INP: Module FOForm?
--- PRE: N/A
--- OUT: true iff FOForm? is a wellFormed formula over module M
--- non-lits
ceq wellFormed(M,F?) = $wellFormed(M,F?) if wellFormed(M) .
eq $wellFormed(M,F1 /\ F2) = $wellFormed(M,F1) and-then $wellFormed(M,F2) .
eq $wellFormed(M,F1 \/ F2) = $wellFormed(M,F1) and-then $wellFormed(M,F2) .
eq $wellFormed(M,~ F1) = $wellFormed(M,F1) .
eq $wellFormed(M,A[QS] F1) = $wellFormed(M,F1) .
eq $wellFormed(M,E[QS] F1) = $wellFormed(M,F1) .
--- eq lit
eq $wellFormed(M,T ?= T') = wellFormed(M,T) and-then wellFormed(M,T') and-then sameKind(M,leastSort(M,T),leastSort(M,T')) .
eq $wellFormed(M,T != T') = wellFormed(M,T) and-then wellFormed(M,T') and-then sameKind(M,leastSort(M,T),leastSort(M,T')) .
--- true/false lit or mtForm
eq $wellFormed(M,TA) = true .
eq $wellFormed(M,mtForm) = true .
--- PRE: FOForm is well-formed in Module
--- OUT: A metanormalized formula
--- INP: FOForm?
eq normalize(M,F1 /\ F2) = normalize(M,F1) /\ normalize(M,F2) .
eq normalize(M,F1 \/ F2) = normalize(M,F1) \/ normalize(M,F2) .
eq normalize(M,~ F1) = ~ normalize(M,F1) .
eq normalize(M,A[QS] F1) = A[QS] normalize(M,F1) .
eq normalize(M,E[QS] F1) = E[QS] normalize(M,F1) .
eq normalize(M,T ?= T') = getTerm(metaNormalize(M,T)) ?= getTerm(metaNormalize(M,T')) .
eq normalize(M,T != T') = getTerm(metaNormalize(M,T)) != getTerm(metaNormalize(M,T')) .
eq normalize(M,TA) = TA .
eq normalize(M,mtForm) = mtForm .
--- PRE: N/A
--- OUT: QidSet of all MetaVariables in the FOForm?
eq vars(F1 /\ F2) = vars(F1) ; vars(F2) .
eq vars(F1 \/ F2) = vars(F1) ; vars(F2) .
eq vars(A[QS] F1) = vars(F1) .
eq vars(E[QS] F1) = vars(F1) .
eq vars(~ F1) = vars(F1) .
eq vars(TA) = none .
eq vars(mtForm) = none .
eq vars(T ?= T') = vars(T) ; vars(T') .
eq vars(T != T') = vars(T) ; vars(T') .
--- INP: PosConj
--- PRE: N/A
--- OUT: UnificationProblem if PosConj has no ff literals;
--- Otherwise, fail to reduce
ceq toUnifProb(PC) = $toUnifProb(PC) if not PC :: ConstConj .
eq $toUnifProb(TA /\ PC) = $toUnifProb(PC) .
eq $toUnifProb((T ?= T') /\ PC) = T =? T' /\ $toUnifProb(PC) .
eq $toUnifProb(T ?= T') = T =? T' .
--- INP: FOForm?
--- PRE: N/A
--- OUT: obvious from definition
eq trueId (mtForm) = tt .
eq trueId (F1) = F1 [owise] .
eq falseId (mtForm) = ff .
eq falseId (F1) = F1 [owise] .
eq true2mt (tt) = mtForm .
eq true2mt (F?) = F? [owise] .
eq false2mt(ff) = mtForm .
eq false2mt(F?) = F? [owise] .
--- OUT: flip atom polarities
op flip : Atom -> Atom .
op flip : EqAtom -> EqAtom .
eq flip(T ?= T') = T != T' .
eq flip(T != T') = T ?= T' .
op flip : TruthAtom -> TruthAtom .
eq flip(tt) = ff .
eq flip(ff) = tt .
op flip : FOForm? -> FOForm? .
eq flip(mtForm) = mtForm .
eq flip(F1 /\ F2) = flip(F1) \/ flip(F2) .
eq flip(F1 \/ F2) = flip(F1) /\ flip(F2) .
eq flip(~ F1) = flip(flip(F1)) .
eq flip(A[QS] F1) = E[QS] flip(F1) .
eq flip(E[QS] F1) = A[QS] flip(F1) .
endfm
fmod FOFORM-QUANTIFIERS is
pr META-LEVEL .
pr FOFORM .
--- Sort Declarations
sort Quantifier UniQuantifier ExiQuantifier .
sort QuantifierList EmptyQuantifierList UniQuantifierList ExiQuantifierList QLFormPair .
--- Subsorting Declarations
subsort UniQuantifier ExiQuantifier < Quantifier < QuantifierList .
subsort EmptyQuantifierList < UniQuantifierList ExiQuantifierList < QuantifierList .
subsort UniQuantifier < UniQuantifierList .
subsort ExiQuantifier < ExiQuantifierList .
--- Quantifier Lists
op A[_] : QidSet -> UniQuantifier [ctor] .
op E[_] : QidSet -> ExiQuantifier [ctor] .
op none : -> EmptyQuantifierList [ctor] .
op __ : EmptyQuantifierList EmptyQuantifierList -> EmptyQuantifierList [ctor assoc id: none] .
op __ : UniQuantifierList UniQuantifierList -> UniQuantifierList [ctor ditto] .
op __ : ExiQuantifierList ExiQuantifierList -> ExiQuantifierList [ctor ditto] .
op __ : QuantifierList QuantifierList -> QuantifierList [ctor ditto] .
op ((_,_)) : QuantifierList FOForm -> QLFormPair [ctor] .
--- Defined Symbols
op getForm : QLFormPair -> FOForm .
op getQuantifierList : QLFormPair -> QuantifierList .
op stripQuantifiers : FOForm -> QLFormPair .
op stripQuantifiers : QuantifierList FOForm -> QLFormPair .
op appendQuantifiers : QuantifierList FOForm -> FOForm .
---
var F : FOForm . var QL : QuantifierList . var Q : QidSet .
--- projections
eq getForm((QL,F)) = F .
eq getQuantifierList((QL,F)) = QL .
--- strip/append quantifiers
eq stripQuantifiers (F) = stripQuantifiers(none,F) .
eq stripQuantifiers (QL,A[Q] F) = stripQuantifiers(QL A[Q],F) .
eq stripQuantifiers (QL,E[Q] F) = stripQuantifiers(QL E[Q],F) .
eq stripQuantifiers (QL,F) = (QL,F) [otherwise] .
eq appendQuantifiers(QL A[Q],F) = appendQuantifiers(QL, A[Q] F) .
eq appendQuantifiers(QL E[Q],F) = appendQuantifiers(QL, E[Q] F) .
eq appendQuantifiers(none,F) = F .
endfm
fmod FOFORM-TUPLES is
pr FOFORM .
pr MODULE-LIST .
sort FOFormNatPair FOFormPair ModFOFormPair NeModListFOFormPair .
subsort ModFOFormPair < NeModListFOFormPair .
op ((_,_)) : NeModuleList FOForm? -> NeModListFOFormPair [ctor] .
op ((_,_)) : Module FOForm? -> ModFOFormPair [ctor] .
op ((_,_)) : FOForm? Nat -> FOFormNatPair [ctor] .
op ((_,_)) : FOForm? FOForm? -> FOFormPair [ctor] .
var ML : NeModuleList . var F G : FOForm? .
op getForm : NeModListFOFormPair ~> FOForm? .
eq getForm((ML,F)) = F .
op FormPairP1 : FOFormPair -> FOForm? .
eq FormPairP1((F,G)) = F .
op FormPairP2 : FOFormPair -> FOForm? .
eq FormPairP2((F,G)) = G .
endfm
fmod FOFORM-SUBSTITUTION is
pr META-LEVEL .
pr SUBSTITUTION-HANDLING . --- from full-maude
pr FOFORM .
op _<<_ : FOForm? Substitution -> FOForm? .
op toConj? : Substitution -> Conj? .
---
var U V : Term . var X Y : Variable . var S : Substitution .
var F G : FOForm . var Q Q' : QidSet . var I : Qid . var N : Nat .
--- base case
eq F << none = F .
--- quantifiers
eq (A[X ; Q] F) << (X <- Y ; S) = (A[X ; Q] F) << S .
eq (E[X ; Q] F) << (X <- Y ; S) = (E[X ; Q] F) << S .
eq (A[Q] F) << S = A[Q] (F << S) [owise] .
eq (E[Q] F) << S = E[Q] (F << S) [owise] .
--- other symbols
eq (F \/ G) << S = (F << S) \/ (G << S) .
eq (F /\ G) << S = (F << S) /\ (G << S) .
eq (~ F) << S = ~ (F << S) .
eq (U ?= V) << S = (U << S) ?= (V << S) .
eq (U != V) << S = (U << S) != (V << S) .
eq tt << S = tt .
eq ff << S = ff .
eq mtForm << S = mtForm .
--- INP: Substitution
--- PRE: None
--- OUT: Conj?
eq toConj?(X <- U ; S) = X ?= U /\ toConj?(S) .
eq toConj?(none) = mtForm .
endfm
fmod FOFORM-CONSTS-TO-VARS is
pr VARIABLES-TO-CONSTANTS .
pr FOFORM .
pr FOFORM-SUBSTITUTION .
op constsToVars : Substitution QFForm? -> QFForm? .
var S : Substitution . var F1 F2 : QFForm . var T T' : Term . var TA : TruthAtom .
eq constsToVars(S,mtForm) = mtForm .
eq constsToVars(S,F1 /\ F2) = constsToVars(S,F1) /\ constsToVars(S,F2) .
eq constsToVars(S,F1 \/ F2) = constsToVars(S,F1) \/ constsToVars(S,F2) .
eq constsToVars(S,~ F1) = ~ constsToVars(S,F1) .
eq constsToVars(S,T ?= T') = constsToVars(S,T) ?= constsToVars(S,T') .
eq constsToVars(S,T != T') = constsToVars(S,T) != constsToVars(S,T') .
eq constsToVars(S,TA) = TA .
endfm
fmod FOFORMSET-CONSTS-TO-VARS is
pr FOFORM-CONSTS-TO-VARS .
pr FOFORMSET .
op constsToVars : Substitution QFForm?Set -> QFForm?Set .
var S : Substitution . var F F' : QFForm? . var FS : QFForm?Set .
eq constsToVars(S,F | F' | FS) = constsToVars(S,F) | constsToVars(S,F' | FS) .
eq constsToVars(S,mtFormSet) = mtFormSet .
endfm
fmod FOFORMSUBSTITUTION-PAIR is
pr FOFORM-SUBSTITUTION . --- substitution application
pr SUBSTITUTION-AUX . --- id
pr FOFORM-OPERATIONS . --- vars
pr FOFORMSET .
sort FOFormSubstPair FOFormSetSubstPair .
subsort FOFormSubstPair < FOFormSetSubstPair .
op ((_,_)) : FOForm? Substitution -> FOFormSubstPair [ctor] .
op ((_,_)) : FOForm?Set Substitution -> FOFormSetSubstPair [ctor] .
op errFOFormSubstPair : QidList -> [FOFormSubstPair] [ctor] .
op errFOFormSubstPairMsg : [FOFormSubstPair] -> QidList [ctor] .
op idpair : FOForm? -> FOFormSubstPair .
op getForm : FOFormSubstPair -> FOForm? .
op getSub : FOFormSubstPair -> Substitution .
op _Pair<<_ : FOForm? Substitution -> FOFormSubstPair .
op _<<_ : FOFormSubstPair Substitution -> FOFormSubstPair .
---
var F : FOForm? . var S S' : Substitution .
var QL : QidList . var FK : [FOFormSubstPair] .
var FS : FOForm?Set .
eq errFOFormSubstPairMsg(errFOFormSubstPair(QL)) = QL .
eq errFOFormSubstPairMsg(FK) = nil [owise] .
eq idpair(F) = (F,idsub(vars(F))) .
---
eq getForm((FS,S)) = FS .
eq getSub ((F,S)) = S .
---
eq FS Pair<< S = (FS << S,S) .
eq (FS,S) << S' = (FS << S,S << S') .
endfm
fmod FOFORM-SUBSTITUTIONSET is
pr META-LEVEL .
pr SUBSTITUTIONSET . --- from full-maude
pr FOFORMSET .
pr FOFORM-SUBSTITUTION .
op _<<_ : FOForm?Set SubstitutionSet -> FOForm?Set .
---
var S S' : Substitution . var SS : SubstitutionSet . var F F' : FOForm? .
var FS : FOForm?Set .
--- base case
eq F << empty = mtFormSet .
eq F << (S | S' | SS) = (F << S) | (F << S' | SS) .
eq (F | F' | FS) << SS = (F << SS) | ((F' | FS) << SS) .
eq mtFormSet << SS = mtFormSet .
endfm
fmod FOFORMSUBSTITUTION-PAIRSET is
pr FOFORMSUBSTITUTION-PAIR .
pr FOFORM-SUBSTITUTIONSET .
sort FOFormSubstPairSet .
subsort FOFormSubstPair < FOFormSubstPairSet .
op _|_ : FOFormSubstPairSet FOFormSubstPairSet -> FOFormSubstPairSet [ctor assoc comm id: mtFSPS] .
op mtFSPS : -> FOFormSubstPairSet [ctor] .
---
op idpair : FOForm?Set -> FOFormSubstPairSet .
op build : FOForm? SubstitutionSet -> FOFormSubstPairSet .
---
op getForm : FOFormSubstPairSet -> FOForm?Set .
op getSub : FOFormSubstPairSet -> SubstitutionSet .
---
op dnf-join : FOFormSubstPairSet -> QFForm? .
op _Pair<<_ : FOForm? SubstitutionSet -> FOFormSubstPairSet .
op _<<_ : FOFormSubstPairSet SubstitutionSet -> FOFormSubstPairSet .
op idem : FOFormSubstPairSet -> FOFormSubstPairSet .
---
var F F' : FOForm? . var FS : FOForm?Set . var C? : Conj? . var S S' : Substitution . var SS : SubstitutionSet .
var FP FP' : FOFormSubstPair . var FPS : FOFormSubstPairSet .
var QL : QidList . var FK : [FOFormSubstPair] . var SK : [Substitution] .
eq errFOFormSubstPairMsg(errFOFormSubstPair(QL) | FK) = QL .
eq idpair(F | F' | FS) = idpair(F) | idpair(F' | FS) .
eq idpair(mtFormSet) = mtFSPS .
--- INP: FOForm? SubstitutionSet
--- PRE: None
--- OUT: An FOFormSubstPairSet built by pairing FOForm? with each Substitution
eq build(F,S | SS) = (F,S) | build(F,SS) .
eq build(F,empty) = mtFSPS .
--- projections
eq getForm((F,S) | FPS) = F | getForm(FPS) .
eq getForm(mtFSPS) = mtFormSet .
eq getSub((F,S) | FPS) = S | getSub(FPS) .
eq getSub(mtFSPS) = empty .
--- INP: FOFormSubstPairSet
--- PRE: Each FOForm in the argument is also a Conj?
--- OUT: A DNF?
eq dnf-join((C?,S) | FPS) = (C? /\ toConj?(S)) \/ dnf-join(FPS) .
eq dnf-join(mtFSPS) = mtForm .
--- Substitution Functions
eq (FP | FP' | FPS) << SS = (FP << SS) | ((FP' | FPS) << SS) .
eq mtFSPS << SS = mtFSPS .
eq FPS << empty = mtFSPS .
eq FP << (S | S' | SS) = (FP << S) | (FP << (S' | SS)) .
--- Construct pairs from one side
eq F Pair<< (S | S' | SS) = (F Pair<< S) | (F Pair<< (S' | SS)) .
eq F Pair<< empty = mtFSPS .
eq F Pair<< errsub(QL) | SK = errFOFormSubstPair(QL) [owise] .
--- Apply the idempotency equation
eq idem(FP | FP | FPS) = idem(FP | FPS) .
eq idem(FPS) = FPS [owise] .
eq idem(errFOFormSubstPair(QL) | FK) = errFOFormSubstPair(QL) .
endfm
fmod FOFORM-RENAME is
pr FOFORM .
pr RENAME-METAVARS .
op renameAllVar : Module FindResult FOForm? -> FOForm? .
op renameTmpVar : Module FindResult FOForm? -> FOForm? .
op unwrapFOForm : TermData -> FOForm? .
var U : Module . var F : FOForm? . var N : FindResult . var T : Term .
eq renameAllVar(U,N,F) = unwrapFOForm(#renameAllVar(U,N,upTerm(F))) .
eq renameTmpVar(U,N,F) = unwrapFOForm(#renameTmpVar(U,N,upTerm(F))) .
eq unwrapFOForm(termdata(T,N)) = downTerm(T,error("Rename failed")) .
endfm
fmod FOFORMSET-RENAME is
pr FOFORMSET .
pr FOFORM-RENAME .
op renameAllVar : Module FindResult FOForm?Set -> FOForm?Set .
op renameTmpVar : Module FindResult FOForm?Set -> FOForm?Set .
op unwrapFOFormSet : TermData -> FOForm?Set .
var U : Module . var F : FOForm?Set . var N : FindResult . var T : Term .
eq renameAllVar(U,N,F) = unwrapFOFormSet(#renameAllVar(U,N,upTerm(F))) .
eq renameTmpVar(U,N,F) = unwrapFOFormSet(#renameTmpVar(U,N,upTerm(F))) .
eq unwrapFOFormSet(termdata(T,N)) = downTerm(T,error("Rename failed")) .
endfm
fmod FOFORMBASICLIST-RENAME is
pr FOFORMBASICLIST .
pr FOFORM-RENAME .
op renameAllVar : Module FindResult FOForm?List -> FOForm?List .
op renameTmpVar : Module FindResult FOForm?List -> FOForm?List .
op unwrapFOFormList : TermData -> FOForm?List .
var U : Module . var F : FOForm?List . var N : FindResult . var T : Term .
eq renameAllVar(U,N,F) = unwrapFOFormList(#renameAllVar(U,N,upTerm(F))) .
eq renameTmpVar(U,N,F) = unwrapFOFormList(#renameTmpVar(U,N,upTerm(F))) .
eq unwrapFOFormList(termdata(T,N)) = downTerm(T,error("Rename failed")) .
endfm
fmod FQF-IMPL is
pr FOFORM-SUBSTITUTION .
pr FOFORM-TUPLES .
pr FOFORM-RENAME .
op renameQuantifiers : Module FOForm? -> FOForm? .
op $rq : FOFormNatPair -> FOForm? .
op $rq : Nat FOForm? -> FOFormNatPair .
op $rq2 : Qid FOFormNatPair FOForm? -> FOFormNatPair .
op $rq2 : Qid FOForm? FOFormNatPair -> FOFormNatPair .
op $rq1 : Qid FOFormNatPair -> FOFormNatPair .
op $rqQ : Qid FOFormNatPair QidSet -> FOFormNatPair .
op $rqQ : Qid Nat FOForm? QidSet QidSet -> FOFormNatPair .
---
var Q : Qid . var F G : FOForm . var X : Variable . var K : [FOForm] .
var N : Nat . var S S' : QidSet . var P : QFForm? . var M : Module .
--- entry point
eq renameQuantifiers(M,P) = P .
eq renameQuantifiers(M,F) = $rq($rq(0,renameAllVar(M,notFound,F))) [owise] .
--- dispatch handlers for different cases
eq $rq((F,N)) = F .
eq $rq(N,P:QFForm?) = (P:QFForm?,N) .
eq $rq(N,F /\ G) = $rq2('/\,$rq(N,F),G) [owise] .
eq $rq(N,F \/ G) = $rq2('\/,$rq(N,F),G) [owise] .
eq $rq(N,~ F) = $rq1('~ ,$rq(N,F)) [owise] .
eq $rq(N,A[Q] F) = $rqQ('A ,$rq(N,F),Q) [owise] .
eq $rq(N,E[Q] F) = $rqQ('E ,$rq(N,F),Q) [owise] .
eq $rq(N,K) = (K,N) [owise] .
--- and/or
eq $rq2(Q,(F,N),G) = $rq2(Q,F,$rq(N,G)) .
eq $rq2('/\,F,(G,N)) = (F /\ G,N) .
eq $rq2('\/,F,(G,N)) = (F \/ G,N) .
--- not
eq $rq1('~,(F,N)) = (~ F,N) .
--- quantifiers
eq $rqQ(Q,(F,N),S) = $rqQ(Q,N,F,S,none) .
eq $rqQ(Q, N,F,X ; S,S') = $rqQ(Q,s(N),F << (X <- tmpvar(N,X)),S,S' ; tmpvar(N,X)) .
eq $rqQ('A,N,F,none, S') = (A[S'] F,N) .
eq $rqQ('E,N,F,none, S') = (E[S'] F,N) .
endfm
fmod FQF is
pr META-LEVEL .
pr REFLECT .
pr FOFORM .
--- convert to fresh quantifier form
op toFQF : Module FOForm -> FOForm .
var M : Module . var F : FOForm .
--- perform conversion and validation
eq toFQF(M,F) = downTerm(redReflect('FQF-IMPL,'renameQuantifiers[upTerm(M),upTerm(F)]),error("FQF failed")) .
endfm
fmod NNF-IMPL is
pr META-LEVEL .
sort EmptyForm TrueAtom FalseAtom NNF Form .
subsort EmptyForm TrueAtom FalseAtom < NNF < Form .
--- Negation Normal Forms
op mtForm : -> EmptyForm [ctor] .
op tt : -> TrueAtom [ctor] .
op ff : -> FalseAtom [ctor] .
op _?=_ : Term Term -> NNF [ctor comm] .
op _!=_ : Term Term -> NNF [ctor comm] .
op _/\_ : NNF NNF -> NNF [ctor assoc comm prec 51] .
op _\/_ : NNF NNF -> NNF [ctor assoc comm prec 51] .
op A[_]_ : QidSet NNF -> NNF [ctor prec 52] .
op E[_]_ : QidSet NNF -> NNF [ctor prec 52] .
--- General Formulas
op ~_ : Form -> Form [prec 50] .
op _/\_ : Form Form -> Form [ctor ditto] .
op _\/_ : Form Form -> Form [ctor ditto] .
op A[_]_ : QidSet Form -> Form [ctor ditto] .
op E[_]_ : QidSet Form -> Form [ctor ditto] .
var T T' : Term . var F F' : Form . var Q : QidSet .
--- Push negations down everywhere --- flip sign accordingly
eq ~ tt = ff .
eq ~ ff = tt .
eq ~ T ?= T' = T != T' .
eq ~ T != T' = T ?= T' .
eq ~ (A[Q] F) = E[Q] ~ F .
eq ~ (E[Q] F) = A[Q] ~ F .
eq ~ (F /\ F') = ~ F \/ ~ F' .
eq ~ (F \/ F') = ~ F /\ ~ F' .
endfm
fmod NNF is
pr META-LEVEL .
pr REFLECT .
pr FOFORM .
op toNNF : FOForm? -> FOForm? .
op nnf? : FOForm? -> Bool .
var F : FOForm? .
eq toNNF(F) = downTerm(redReflect('NNF-IMPL,upTerm(F)),error("NNF failed")) .
eq nnf?(F) = sortReflect('NNF-IMPL,upTerm(F),'NNF) .
endfm
fmod PNF-IMPL is
pr META-LEVEL .
sort EmptyForm TrueAtom FalseAtom QFF EPNF APNF PNF Form .
subsort EmptyForm TrueAtom FalseAtom < QFF < PNF < Form .
--- Quantifier Free Formulas
op mtForm : -> EmptyForm [ctor] .
op tt : -> TrueAtom [ctor] .
op ff : -> FalseAtom [ctor] .
op _?=_ : Term Term -> QFF [ctor comm] .
op _!=_ : Term Term -> QFF [ctor comm] .
op _/\_ : QFF QFF -> QFF [ctor assoc comm prec 50] .
op _\/_ : QFF QFF -> QFF [ctor assoc comm prec 50] .
op ~_ : QFF -> QFF [ctor prec 51] .
--- Prenex Normal Forms
op A[_]_ : QidSet PNF -> PNF [ctor prec 51] .
op E[_]_ : QidSet PNF -> PNF [ctor prec 51] .
--- General Formulas
op _/\_ : Form Form -> Form [ctor ditto] .
op _\/_ : Form Form -> Form [ctor ditto] .
op ~_ : Form -> Form [ctor ditto] .
op A[_]_ : QidSet Form -> Form [ctor ditto] .
op E[_]_ : QidSet Form -> Form [ctor ditto] .
--- Bubble Quantifiers Up