-
Notifications
You must be signed in to change notification settings - Fork 2
/
cstrterm.maude
874 lines (743 loc) · 39.1 KB
/
cstrterm.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
--- file: cstrterm.maude
--- reqs: foform.maude
--- info: this file introduces constrained terms and operations on constrained
--- terms---standard formula operations are also lifted into constrained terms
fmod CONSTRAINED-TERM is pr FOFORM .
sort WTerm CCTerm QFCTerm QFCTerm? CTerm CTerm? .
subsort WTerm < CCTerm < QFCTerm < CTerm < CTerm? .
subsort WTerm < CCTerm < QFCTerm < QFCTerm? < CTerm? .
op ((_|_)) : Term TrueAtom -> WTerm [ctor] .
op ((_|_)) : Term Conj? -> CCTerm [ctor] .
op ((_|_)) : Term QFForm? -> QFCTerm [ctor] .
op ((_|_)) : Term FOForm? -> CTerm [ctor] .
op noterm : -> QFCTerm? [ctor] .
endfm
fmod CONSTRAINED-TERM-PROJECTIONS is pr CONSTRAINED-TERM .
op term : CTerm -> Term .
op cond : CTerm -> FOForm? .
op cond : QFCTerm -> QFForm? .
---
op conj : CTerm FOForm? -> CTerm .
op conj : QFCTerm QFForm? -> QFCTerm .
op conj : CTerm CTerm -> CTerm .
op conj : QFCTerm QFCTerm -> QFCTerm .
var T T' : Term . var F F' : FOForm? .
eq term((T | F)) = T .
eq cond((T | F)) = F .
eq conj((T | F),F') = (T | (F /\ F')) .
eq conj((T | F),(T' | F')) = (T | (F /\ F')) .
endfm
fmod CONSTRAINED-TERMPAIR is pr CONSTRAINED-TERM .
sort QFCTermPair CTermPair .
subsort QFCTermPair < CTermPair .
op ((_,_)) : QFCTerm QFCTerm -> QFCTermPair [ctor] .
op ((_,_)) : CTerm CTerm -> CTermPair [ctor] .
endfm
fmod CONSTRAINED-TERMSET is pr CONSTRAINED-TERM .
sort QFCTermSet CTermSet NeQFCTermSet NeCTermSet .
--- elt into set
subsort QFCTerm < NeQFCTermSet .
subsort CTerm < NeCTermSet .
subsort QFCTerm? < QFCTermSet .
subsort CTerm? < CTermSet .
--- neset into set
subsort NeQFCTermSet < QFCTermSet .
subsort NeCTermSet < CTermSet .
--- subsort into supersort
subsort NeQFCTermSet < NeCTermSet .
subsort QFCTermSet < CTermSet .
op _|_ : CTermSet CTermSet -> CTermSet [ctor assoc comm id: noterm] .
op _|_ : QFCTermSet QFCTermSet -> QFCTermSet [ctor ditto] .
op _|_ : CTermSet NeCTermSet -> NeCTermSet [ctor ditto] .
op _|_ : QFCTermSet NeQFCTermSet -> NeQFCTermSet [ctor ditto] .
endfm
fmod CONSTRAINED-TERMSET-PROJECTIONS is
pr CONSTRAINED-TERM-PROJECTIONS .
pr CONSTRAINED-TERMSET .
pr TERMSET-FM .
var CT CT' : CTerm . var CTS : CTermSet . var F : FOForm? .
op term : CTermSet -> TermSet .
eq term(CT | CT' | CTS) = term(CT) | term(CT' | CTS) .
eq term(noterm) = emptyTermSet .
op cond : CTermSet -> FOForm? .
op cond : QFCTermSet -> QFForm? .
eq cond(CT | CT' | CTS) = cond(CT) \/ cond(CT' | CTS) .
eq cond(noterm) = mtForm .
op conj : CTermSet FOForm? -> CTermSet .
eq conj(CT | CT' | CTS,F) = conj(CT,F) | conj(CT' | CTS,F) .
eq conj(noterm,F) = noterm .
endfm
fmod CONSTRAINED-TERMSETPAIR is
pr CONSTRAINED-TERMPAIR .
pr CONSTRAINED-TERMSET .
sort QFCTermSetPair CTermSetPair .
subsort QFCTermSetPair < CTermSetPair .
subsort QFCTermPair < QFCTermSetPair .
subsort CTermPair < CTermSetPair .
op ((_,_)) : QFCTermSet QFCTermSet -> QFCTermSetPair [ctor] .
op ((_,_)) : CTermSet CTermSet -> CTermSetPair [ctor] .
endfm
fmod CONSTRAINED-TERM-FQF is pr CONSTRAINED-TERM . pr FQF .
op toFQF : Module CTerm? -> CTerm? .
var M : Module . var T : Term . var F : FOForm? .
eq toFQF(M,(T | F)) = (T | toFQF(M,F)) .
eq toFQF(M,noterm) = noterm .
endfm
fmod CONSTRAINED-TERM-NNF is pr CONSTRAINED-TERM . pr NNF .
op toNNF : CTerm? -> CTerm? .
op nnf? : CTerm? -> Bool .
var T : Term . var F : FOForm? .
eq toNNF((T | F)) = (T | toNNF(F)) .
eq toNNF(noterm) = noterm .
eq nnf?((T | F)) = nnf?(F) .
eq nnf?(noterm) = true .
endfm
fmod CONSTRAINED-TERM-PNF is pr CONSTRAINED-TERM . pr PNF .
op toPNF : Module CTerm? -> CTerm? .
op pnf? : CTerm? -> Bool .
var M : Module . var T : Term . var F : FOForm? .
eq toPNF(M,(T | F)) = (T | toPNF(M,F)) .
eq toPNF(M,noterm) = noterm .
eq pnf?((T | F)) = pnf?(F) .
eq pnf?(noterm) = true .
endfm
fmod CONSTRAINED-TERM-CNF is pr CONSTRAINED-TERM . pr CNF .
op toCNF : QFCTerm? -> QFCTerm? .
op toCNF : Module CTerm? -> CTerm? .
op qcnf? : CTerm? -> Bool .
op cnf? : CTerm? -> Bool .
var M : Module . var T : Term . var F : FOForm? . var Q : QFForm? .
eq toCNF((T | Q)) = (T | toCNF(Q)) .
eq toCNF(noterm) = noterm .
eq toCNF(M,(T | F)) = (T | toCNF(M,F)) .
eq toCNF(M,noterm) = noterm .
eq qcnf?((T | F)) = qcnf?(F) .
eq qcnf?(noterm) = true .
eq cnf?((T | F)) = cnf?(F) .
eq cnf?(noterm) = true .
endfm
fmod CONSTRAINED-TERM-DNF is pr CONSTRAINED-TERM . pr DNF .
op toDNF : QFCTerm? -> QFCTerm? .
op toDNF : Module CTerm? -> CTerm? .
op qdnf? : CTerm? -> Bool .
op dnf? : CTerm? -> Bool .
var M : Module . var T : Term . var F : FOForm? . var Q : QFForm? .
eq toDNF((T | Q)) = (T | toDNF(Q)) .
eq toDNF(noterm) = noterm .
eq toDNF(M,(T | F)) = (T | toDNF(M,F)) .
eq toDNF(M,noterm) = noterm .
eq qdnf?((T | F)) = qdnf?(F) .
eq qdnf?(noterm) = true .
eq dnf?((T | F)) = dnf?(F) .
eq dnf?(noterm) = true .
endfm
fmod CONSTRAINED-TERM-OPERATIONS is
pr CONSTRAINED-TERM .
pr FOFORM-OPERATIONS .
op wellFormed : Module CTerm? -> Bool .
op wellFormed : Module Type CTerm? -> Bool .
op normalize : Module CTerm? -> CTerm? .
op vars : CTerm? -> QidSet .
op termVars : CTerm? -> QidSet .
op formVars : CTerm? -> QidSet .
op setCond : CTerm? FOForm? -> CTerm? .
var M : Module . var T : Term . var Y : Type . var F F' : FOForm? .
eq wellFormed(M,(T | F)) = wellFormed(M,T) == true and-then wellFormed(M,F) == true .
eq wellFormed(M,noterm) = true .
eq wellFormed(M,Y,(T | F)) = wellFormed(M,(T | F)) == true and-then sameKind(M,Y,leastSort(M,T)) .
eq wellFormed(M,Y,noterm) = true .
eq normalize(M,(T | F)) = (getTerm(metaNormalize(M,T)) | normalize(M,F)) .
eq normalize(M,noterm) = noterm .
eq vars((T | F)) = vars(T) ; vars(F) .
eq vars(noterm) = none .
eq termVars((T | F)) = vars(T) .
eq termVars(noterm) = none .
eq formVars((T | F)) = vars(F) .
eq formVars(noterm) = none .
eq setCond((T | F),F') = (T | F') .
eq setCond(noterm,F') = noterm .
endfm
--- legacy names: vars, head-vars
fmod CONSTRAINED-TERMSET-OPERATIONS is
pr CONSTRAINED-TERM-OPERATIONS .
pr CONSTRAINED-TERMSET .
pr CONSTRAINED-TERM-NNF . --- needed for nnf conversion
var M : Module . var CT CT' : CTerm . var CTS CTS' : CTermSet . var Y : Type .
var T : Term . var F : FOForm . var QS : QidSet . var N : Nat .
--- OUT: true iff this constrained term set is wellformed
op wellFormed : Module CTermSet -> Bool .
op wellFormed : Module Type CTermSet -> Bool .
eq wellFormed(M,CT | CT' | CTS) = wellFormed(M,CT) and-then wellFormed(M,CT' | CTS) .
eq wellFormed(M,Y,CT | CT' | CTS) = wellFormed(M,Y,CT) and-then wellFormed(M,Y,CT' | CTS) .
--- OUT: a meta-normalized constrained term set
op normalize : Module CTermSet -> CTermSet .
eq normalize(M,CT | CT' | CTS) = normalize(M,CT) | normalize(M,CT' | CTS) .
--- OUT: constraint negation/normalization
op negateCond : CTermSet -> CTermSet .
eq negateCond(CT | CT' | CTS) = negateCond(CT) | negateCond(CT' | CTS) .
eq negateCond(noterm) = noterm .
eq negateCond((T | F)) = (T | ~ F) .
--- OUT: apply NNF transformation to constraint
op toNNF : CTermSet -> CTermSet .
eq toNNF(CT | CT' | CTS) = toNNF(CT) | toNNF(CT' | CTS) .
--- OUT: variables in each constrained term in set
op vars : CTermSet -> QidSet .
eq vars(CT | CT' | CTS) = vars(CT) ; vars(CT' | CTS) .
--- OUT: variables in term part of each constrained term in set
op termVars : CTermSet -> QidSet .
eq termVars(CT | CT' | CTS) = termVars(CT) ; termVars(CT' | CTS) .
--- OUT: variables in constraint part of each constrained term in set
op formVars : CTermSet -> QidSet .
eq formVars(CT | CT' | CTS) = formVars(CT) ; formVars(CT' | CTS) .
--- OUT: shared variables in each constrained term of a constrained term set
op sharedVars : CTermSet -> QidSet .
eq sharedVars(CT | CTS) = sharedVars(vars(CT),CTS) .
eq sharedVars(noterm) = none .
op sharedVars : QidSet CTermSet -> QidSet .
eq sharedVars(QS,CT | CTS) = sharedVars(intersection(QS,vars(CT)),CTS) .
eq sharedVars(QS,noterm) = QS .
--- OUT: shared variables of two constrained term sets
op sharedVars : CTermSet CTermSet -> QidSet .
eq sharedVars(CTS,CTS') = intersection(vars(CTS),vars(CTS')) .
op size : CTermSet -> Nat .
op size : CTermSet Nat -> Nat .
eq size(CTS) = size(CTS,0) .
eq size(CT | CTS,N) = size(CTS,s(N)) .
eq size(noterm, N) = N .
endfm
fmod CONSTRAINED-TERM-SUBSTITUTION is
pr CONSTRAINED-TERM .
pr FOFORM-SUBSTITUTION .
op _<<_ : CTerm? Substitution -> CTerm? .
op _<<Term_ : CTerm? Substitution -> CTerm? .
op _<<Form_ : CTerm? Substitution -> CTerm? .
var T : Term . var F : FOForm? . var S : Substitution .
eq (T | F) << S = (T << S | (F << S)) .
eq noterm << S = noterm .
eq (T | F) <<Term S = (T << S | F) .
eq noterm <<Term S = noterm .
eq (T | F) <<Form S = (T | (F << S)) .
eq noterm <<Form S = noterm .
endfm
fmod CONSTRAINED-TEMRSET-SUBSTITUTION is
pr CONSTRAINED-TERMSET .
pr CONSTRAINED-TERM-SUBSTITUTION .
op _<<_ : CTermSet Substitution -> CTermSet .
op _<<Term_ : CTermSet Substitution -> CTermSet .
op _<<Form_ : CTermSet Substitution -> CTermSet .
var CT : CTerm . var CTS : CTermSet . var S : Substitution .
eq (CT | CTS) << S = (CT << S) | (CTS << S) .
eq (CT | CTS) <<Term S = (CT <<Term S) | (CTS <<Term S) .
eq (CT | CTS) <<Form S = (CT <<Form S) | (CTS <<Form S) .
endfm
--- legacy names: applySub, applySubToCond
fmod CONSTRAINED-TERM-SUBSTITUTIONSET is
pr CONSTRAINED-TERM-SUBSTITUTION .
pr CONSTRAINED-TERMSET .
pr SUBSTITUTIONSET .
op _<<_ : CTerm? SubstitutionSet -> CTermSet .
op _<<Term_ : CTerm? SubstitutionSet -> CTermSet .
op _<<Form_ : CTerm? SubstitutionSet -> CTermSet .
var S S' : Substitution . var SS : SubstitutionSet . var CT : CTerm? .
eq CT << (S | S' | SS) = (CT << S) | (CT << (S' | SS)) .
eq CT << empty = noterm .
eq CT <<Term (S | S' | SS) = (CT <<Term S) | (CT <<Term (S' | SS)) .
eq CT <<Term empty = noterm .
eq CT <<Form (S | S' | SS) = (CT <<Form S) | (CT <<Form (S' | SS)) .
eq CT <<Form empty = noterm .
endfm
fmod CONSTRAINED-TERMSET-SUBSTITUTIONSET is
pr CONSTRAINED-TEMRSET-SUBSTITUTION .
pr SUBSTITUTIONSET .
op _<<_ : CTermSet SubstitutionSet -> CTermSet .
op _<<Term_ : CTermSet SubstitutionSet -> CTermSet .
op _<<Form_ : CTermSet SubstitutionSet -> CTermSet .
var CTS : CTermSet . var S S' : Substitution . var SS : SubstitutionSet .
eq CTS << (S | S' | SS) = (CTS << S) | (CTS << (S' | SS)) .
eq CTS <<Term (S | S' | SS) = (CTS <<Term S) | (CTS <<Term (S' | SS)) .
eq CTS <<Form (S | S' | SS) = (CTS <<Form S) | (CTS <<Form (S' | SS)) .
endfm
fmod CONSTRAINED-TERM-RENAME is pr CONSTRAINED-TERM . pr RENAME-METAVARS .
op renameAllVar : Module FindResult CTerm -> CTerm .
op renameTmpVar : Module FindResult CTerm -> CTerm .
op unwrapCTerm : TermData -> CTerm .
var U : Module . var CT : CTerm . var N : FindResult . var T : Term .
eq renameAllVar(U,N,CT) = unwrapCTerm(#renameAllVar(U,N,upTerm(CT))) .
eq renameTmpVar(U,N,CT) = unwrapCTerm(#renameTmpVar(U,N,upTerm(CT))) .
eq unwrapCTerm(termdata(T,N)) = downTerm(T,noterm) .
endfm
fmod CONSTRAINED-TERMSET-RENAME is pr CONSTRAINED-TERMSET . pr CONSTRAINED-TERM-RENAME .
op renameAllVar : Module FindResult CTermSet -> CTermSet .
op renameTmpVar : Module FindResult CTermSet -> CTermSet .
op unwrapCTermSet : TermData -> CTermSet .
var U : Module . var CTS : CTermSet . var N : FindResult . var T : Term .
eq renameAllVar(U,N,CTS) = unwrapCTermSet(#renameAllVar(U,N,upTerm(CTS))) .
eq renameTmpVar(U,N,CTS) = unwrapCTermSet(#renameTmpVar(U,N,upTerm(CTS))) .
eq unwrapCTermSet(termdata(T,N)) = downTerm(T,noterm) .
endfm
--- This module defines a meta-level constrained term functor. As with all meta-level functor,
--- the functor exists in two parts:
--- [1] the lifting of the input module signature into the functorized signatures
--- [2] the lifting of data structures into meta-terms well-defined in the functorized signature
fmod CONSTRAINED-TERM-FUNCTOR is
pr CONSTRAINED-TERM . --- constrained terms
pr QID-JOIN . --- join() functions
pr UNIQUE-PREFIX . --- sortPrefix()/opPrefix() functions
pr UNIT-FM . --- addXXX() functions
var U : Module .
var CT : QFCTerm . var T T' : Term . var TL : TermList . var C : Constant .
var F F' : QFForm . var F? : QFForm? .
var X Y : Sort . var XS : SortSet .
var N O S : Qid . --- the operator prefix O and sort prefix S
--- The module (signature) functor lifting
op cterm-func : Module -> Module [memo] .
eq cterm-func(U) = cterm-func(U,qid(opPrefix(U)),qid(sortPrefix(U))) .
op cterm-func : Module Qid Qid -> Module .
eq cterm-func(U,O,S) = addSorts(join(S 'Form) ; join(S 'CTerm), addOps(literal-ops(O,S,getSorts(U)) nonliteral-ops(S),U)) .
op nonliteral-ops : Qid -> OpDeclSet .
eq nonliteral-ops(S) = (op '/\ : join(S 'Form) join(S 'Form) -> join(S 'Form) [assoc comm id(join('tt. S 'Form))].
op '\/ : join(S 'Form) join(S 'Form) -> join(S 'Form) [assoc comm].
op 'tt : nil -> join(S 'Form) [none].) .
op literal-ops : Qid Qid Sort -> OpDeclSet .
eq literal-ops(O,S,X ; Y ; XS) = literal-ops(O,S,X) literal-ops(O,S,Y ; XS) .
eq literal-ops(O,S,none) = none .
eq literal-ops(O,S,X) = (op '| : X join(S 'Form) -> join(S 'CTerm) [none].
op eq-literal (O) : X X -> join(S 'Form ) [none].
op neq-literal(O) : X X -> join(S 'Form ) [none].) .
--- Lifting constrained terms into terms in the functor meta-module
--- OUT: A CTerm with a conjunction free formula variable
op cterm-func-ext : Module Qid QFCTerm -> Term .
eq cterm-func-ext(U,N,CT) = cterm-func-ext(N,qid(opPrefix(U)),qid(sortPrefix(U)),CT) .
op cterm-func-ext : Qid Qid Qid QFCTerm -> Term .
eq cterm-func-ext(N,O,S,(T | mtForm)) = '|[T,'/\[tt-literal(S),form-variable(S)]] .
eq cterm-func-ext(N,O,S,(T | tt)) = '|[T,'/\[tt-literal(S),form-variable(S)]] .
eq cterm-func-ext(N,O,S,(T | F)) = '|[T,'/\[eqform-func(O,S,F),form-variable(S)]] .
--- OUT: An exact lifting of a CTerm
op cterm-func : Module QFCTerm -> Term .
eq cterm-func(U,CT) = cterm-func(qid(opPrefix(U)),qid(sortPrefix(U)),CT) .
op cterm-func : Qid Qid QFCTerm -> Term .
eq cterm-func(O,S,(T | mtForm)) = '|[T,tt-literal(S)] .
eq cterm-func(O,S,(T | tt)) = '|[T,tt-literal(S)] .
eq cterm-func(O,S,(T | F)) = '|[T,eqform-func(O,S,F)] .
--- Lifting quantifier-free formulas into terms in the functor meta-module
op eqform-func : Module QFForm? -> Term .
eq eqform-func(U,F?) = eqform-func(qid(opPrefix(U)),qid(sortPrefix(U)),F?) .
op eqform-func : Qid Qid QFForm? -> Term .
eq eqform-func(O,S,F /\ F') = '/\[eqform-func(O,S,F),eqform-func(O,S,F')] .
eq eqform-func(O,S,F \/ F') = '\/[eqform-func(O,S,F),eqform-func(O,S,F')] .
eq eqform-func(O,S,T ?= T') = eq-literal(O) [T,T'] .
eq eqform-func(O,S,T != T') = neq-literal(O)[T,T'] .
eq eqform-func(O,S,mtForm) = tt-literal(S) .
eq eqform-func(O,S,tt) = tt-literal(S) .
--- Base cases for building meta-terms in functor meta-module
op form-variable : Qid -> Variable .
eq form-variable(S) = join('F: S 'Form) .
op eq-literal : Qid -> Qid .
eq eq-literal(O) = join(O '?=) .
op neq-literal : Qid -> Qid .
eq neq-literal(O) = join(O '!=) .
op tt-literal : Qid -> TermQid .
eq tt-literal(O) = join('tt. O 'Form) .
--- Inverse functor
op eqform-func-op : Module Term -> [QFForm?] .
eq eqform-func-op(U,T) = eqform-func-op(qid(opPrefix(U)),qid(sortPrefix(U)),T) .
op eqform-func-op : Qid Qid Term -> [QFForm?] .
eq eqform-func-op(O,S,'/\[T,T',TL]) = and-eqform-func-op(O,S,(T,T',TL)) .
eq eqform-func-op(O,S,'\/[T,T',TL]) = or-eqform-func-op(O,S,(T,T',TL)) .
ceq eqform-func-op(O,S, N[T,T']) =
if N == eq-literal(O) then T ?= T' else T != T' fi
if N in (eq-literal(O) ; neq-literal(O)) .
ceq eqform-func-op(O,S,C) = tt
if C == tt-literal(S) .
op and-eqform-func-op : Qid Qid NeTermList -> [QFForm?] .
eq and-eqform-func-op(O,S,(T,T',TL)) = eqform-func-op(O,S,T) /\ and-eqform-func-op(O,S,(T',TL)) .
eq and-eqform-func-op(O,S,T) = eqform-func-op(O,S,T) .
op or-eqform-func-op : Qid Qid NeTermList -> [QFForm?] .
eq or-eqform-func-op(O,S,(T,T',TL)) = eqform-func-op(O,S,T) \/ or-eqform-func-op(O,S,(T',TL)) .
eq or-eqform-func-op(O,S,T) = eqform-func-op(O,S,T) .
endfm
fmod CONSTRAINED-TERMSET-MATCH is
pr CONSTRAINED-TERM-FUNCTOR . --- cterm-func()/eqform-func()
pr CONSTRAINED-TERMSET . --- sets of contrained terms
pr FOFORMSUBSTITUTION-PAIRSET . --- collect the intermediate results
pr UNIFIERS . --- matches() function
pr SUBSTITUTION-AUX . --- remove() function for substitutions
var C C' : QFCTerm . var CS CS' : QFCTermSet .
var U : Module . var T T' : Term .
var F G : QFForm? . var FS GS : QFForm?Set . var O S : Qid .
var V : Variable .
var SUB : Substitution .
var Safe? : Bool . var N : Nat .
op subsumeByMatch : Module QFCTermSet QFCTermSet -> Bool .
eq subsumeByMatch(U,CS,CS') = matches#(U,CS',CS) =/= empty .
--- Return all matches for sets of constrained terms
op matches : Module QFCTermSet QFCTermSet -> FOFormSubstPairSet .
eq matches(U,CS,CS') = idem(tt Pair<< matches#(U,CS,CS')) .
op matches# : Module QFCTermSet QFCTermSet -> SubstitutionSet .
eq matches#(U,CS,CS') = matches#(U,qid(opPrefix(U)),qid(sortPrefix(U)),CS,CS') .
op matches# : Module Qid Qid QFCTermSet QFCTermSet -> SubstitutionSet .
eq matches#(U,O,S,noterm,C) = empty .
eq matches#(U,O,S,CS,CS') = empty [owise] .
eq matches#(U,O,S,C' | CS,C) =
remove(safeMatch(cterm-func(U),cterm-func-ext(U,'X,C'),cterm-func(U,C)),form-variable(S) <- tt-literal(O)) |
matches#(U,O,S,CS,C) .
--- Return all matches for two formulas
op matches : Module QFForm? QFForm? -> FOFormSubstPairSet .
eq matches(U,F,G) = idem(tt Pair<< matches#(U,F,G)) .
op matches# : Module QFForm? QFForm? -> SubstitutionSet .
eq matches#(U,F,G) = matches#(U,qid(opPrefix(U)),qid(sortPrefix(U)),F,G) .
op matches# : Module Qid Qid QFForm? QFForm? -> SubstitutionSet .
eq matches#(U,O,S,F,G) =
remove(safeMatch(cterm-func(U),'/\[eqform-func(U,F),form-variable(S)],eqform-func(U,G)),form-variable(S) <- tt-literal(O)) .
--- Return given match number for two constrained terms (with optionally safe match)
op match# : Module Bool QFCTerm QFCTerm Nat -> Substitution? .
op match# : Module Bool Qid Qid QFCTerm QFCTerm Nat -> Substitution? .
----------------------------------------------------------------------
eq match#(U,Safe?,C,C',N) = match#(U,Safe?,qid(opPrefix(U)),qid(sortPrefix(U)),C,C',N) .
eq match#(U,true, O,S,C,C',N) = remove(safeMatch(cterm-func(U),cterm-func-ext(U,'X,C),cterm-func(U,C'),N),form-variable(S) <- tt-literal(O)) .
eq match#(U,false,O,S,C,C',N) = remove(metaMatch(cterm-func(U),cterm-func-ext(U,'X,C),cterm-func(U,C'),N),form-variable(S) <- tt-literal(O)) .
--- Return given match number for two formulas (with optionally safe match)
op match# : Module Bool QFForm? QFForm? Nat -> Substitution? .
op match# : Module Bool Qid Qid QFForm? QFForm? Nat -> Substitution? .
----------------------------------------------------------------------
eq match#(U,Safe?,F,G,N) = match#(U,Safe?,qid(opPrefix(U)),qid(sortPrefix(U)),F,G,N) .
eq match#(U,true, O,S,F,G,N) = remove(safeMatch(cterm-func(U),'/\[eqform-func(U,F),form-variable(S)],eqform-func(U,G),N),form-variable(S) <- tt-literal(O)) .
eq match#(U,false,O,S,F,G,N) = remove(metaMatch(cterm-func(U),'/\[eqform-func(U,F),form-variable(S)],eqform-func(U,G),N),form-variable(S) <- tt-literal(O)) .
op getFormValue : Module Substitution -> FOFormSubstPair .
eq getFormValue(U,SUB) = getFormValue(U,form-variable(qid(sortPrefix(U))),SUB) .
op getFormValue : Module Qid Substitution -> FOFormSubstPair .
eq getFormValue(U,V,V <- T ; SUB) = (eqform-func-op(U,T),SUB) .
eq getFormValue(U,V,SUB) = (mtForm,SUB) [owise] .
op maximalTermSet : Module QFCTermSet -> QFCTermSet .
op maximalTermSet : Module QFCTermSet QFCTermSet -> QFCTermSet .
op maximalTermSet1 : Module QFCTermSet QFCTerm QFCTermSet -> QFCTermSet .
-------------------------------------------------------------------------
eq maximalTermSet(U,CS) = maximalTermSet(U,CS,noterm) .
eq maximalTermSet(U,C | CS, CS') = maximalTermSet(U,CS,maximalTermSet1(U,C,CS',noterm)) .
eq maximalTermSet(U,noterm,CS') = CS' .
eq maximalTermSet1(U,C,C' | CS',CS) =
if match#(U,false,C,C',0) :: Substitution
then maximalTermSet1(U,C,CS',CS)
else if match#(U,false,C',C,0) :: Substitution
then C' | CS' | CS
else maximalTermSet1(U,C,CS',CS | C')
fi fi .
eq maximalTermSet1(U,C,noterm,CS) = C | CS .
op maximalFormSet : Module QFForm?Set -> QFForm?Set .
op maximalFormSet : Module QFForm?Set QFForm?Set -> QFForm?Set .
op maximalFormSet1 : Module QFForm?Set QFForm? QFForm?Set -> QFForm?Set .
-------------------------------------------------------------------------
eq maximalFormSet(U,FS) = maximalFormSet(U,FS,mtFormSet) .
eq maximalFormSet(U,F | FS, GS) = maximalFormSet(U,FS,maximalFormSet1(U,F,GS,mtFormSet)) .
eq maximalFormSet(U,mtFormSet,GS) = GS .
eq maximalFormSet1(U,F,G | GS,FS) =
if match#(U,false,F,G,0) :: Substitution
then maximalFormSet1(U,F,GS,FS)
else if match#(U,false,G,F,0) :: Substitution
then G | GS | FS
else maximalFormSet1(U,F,GS,FS | G)
fi fi .
eq maximalFormSet1(U,F,mtFormSet,FS) = F | FS .
endfm
--- This module defines a semantic pattern formula matcher that
--- match the head of one pattern to the other and then check the that the
--- formula where the condition of the first implies the matched condition of the second
--- is logically valid
fmod PATTERN-OPS is
pr CONSTRAINED-TERMSET-PROJECTIONS . --- basic projectionss over QFCTermSet
pr CONSTRAINED-TERMSET-OPERATIONS . --- basic operations over QFCTermSet
pr FOFORM-DEFINEDOPS . --- defined formula operators
pr FOFORM-OPERATIONS . --- basic operations over FOForm
pr FOFORMSET-OPERATIONS . --- basic operations over FOFormSet
pr FOFORMSUBSTITUTION-PAIRSET . --- collect the intermediate results
pr FOFORMSIMPLIFY . --- basic simplification operations
pr FOFORMREDUCE .
pr VARIABLES-TO-CONSTANTS . --- convert variables in a module to constants
pr UNIFIERS . --- operations to generate all unifiers/matches
pr RENAME-METAVARS . --- #renameAllVars
pr CONSTRAINED-TERM-SUBSTITUTIONSET .
pr CONSTRAINED-TERM-DNF .
pr RENAME-TERM .
pr VAR-UNIF-PARTIAL-FVP .
var U : Module . var MS : [ModuleSubstPair] . var S S' : Substitution .
var VS : VariableSet . var B : Bool .
var C C' C'' C1 C2 : QFCTerm . var CS CS' CS1 CS2 : QFCTermSet .
var N N' : Nat . var T T' : Term . var F F' : QFForm . var F? F'? : QFForm? .
var FS : QFForm?Set . var FSS : FOFormSubstPairSet .
var SPS : SubstitutionPairSet .
******************************************************************************
*** NOTE:
*** These functions are used for both goal antecedent/succedent subsumption
*** checking [in which case CS may be a non-singleton] or in the case of
*** checking if the antecedent of an axiom subsumes the antecedent of a goal
*** [in which case CS will always be a singleton, unless that we generalize
*** our procedure to allow axioms with disjunctive antecedents]
******************************************************************************
--- PRE: QFCTerm/Set are well-defined in the module
--- OUT: Bool is true means parameterized; otherwise unparameterized
--- If this formula is valid, then (T | F) is an instance of CS;
--- i.e. this computes (~ F) \/ T(CS) where T() computes all of
--- CS's T-instances
op subsumeIfValid : Module VariableSet QFCTermSet QFCTermSet ~> QFForm? .
eq subsumeIfValid(U,VS,C | C' | CS,CS') = subsumeIfValid(U,VS,C,CS') /\ subsumeIfValid(U,VS,C' | CS,CS') .
eq subsumeIfValid(U,VS,noterm,CS') = tt .
op subsumeIfValid : Module VariableSet QFCTerm QFCTermSet ~> QFForm? .
eq subsumeIfValid(U,VS,C,CS) = trueId(cond(C)) ==> disj-join(getForm(applyMatchToCond(U,intersection(VS,sharedVars(C,CS)),C,CS))) .
--- INP: Module VariableSet Term QFCTermSet
--- PRE: QFCTerm/Set well-defined in Module; VariableSet contains shared variables between QFCTerm/Form
--- OUT: A set of formulas/substitutions where:
--- [1] each formula is obtaining by applying the substitution to a condition in the QFCTermSet
--- [2] each substitution is obtained by matching a term in the QFCTermSet to the Term in all possible ways
--- [3] substitutions are identity on each variable in VariableSet
op applyMatchToCond : Module VariableSet QFCTerm QFCTermSet ~> FOFormSubstPairSet .
op applyMatchToCond : ModuleSubstPair QFCTerm QFCTermSet ~> FOFormSubstPairSet .
eq applyMatchToCond(U,VS,C,CS) = applyMatchToCond(varsToConsts#(U,full,VS),C,CS) .
eq applyMatchToCond((U,S),C,C' | CS) =
(trueId(cond(C')) Pair<< sharedMatch((U,S),term(C'),term(C))) | applyMatchToCond((U,S),C,CS) .
eq applyMatchToCond((U,S),C,noterm) = mtFSPS .
--- OUT: Same as above, but directly compute shared variables
op applyMatchToCond : Module Bool QFCTerm QFCTermSet ~> FOFormSubstPairSet .
eq applyMatchToCond(U,B,C,CS) = applyMatchToCond(U,if B then sharedVars(C,CS) else none fi,C,CS) .
--- OUT: overapproximate difference of C - CS
op overapproximateDiff : Module QFCTerm QFCTermSet ~> QFCTerm .
eq overapproximateDiff(U,C,CS) = overapproximateDiff(U,intersection(vars(C),vars(CS)),C,CS) .
op overapproximateDiff : Module VariableSet QFCTerm QFCTermSet ~> QFCTerm .
eq overapproximateDiff(U,VS,C,CS) = conj(C,conj-join(getForm(applyMatchToCond(U,VS,C,toNNF(negateCond(CS)))))) .
op intersect : Module QFCTermSet QFCTermSet -> QFCTermSet .
eq intersect(U,C | C' | CS,CS') = intersect(U,C,CS' ) | intersect(U,C' | CS,CS') .
eq intersect(U,C,C' | C'' | CS) = intersect(U,C,C') | intersect(U,C,C'' | CS) .
eq intersect(U,(T | F?),(T' | F'?)) = (T | F? /\ F'?) << safeUnify(U,T,T') .
op disjIntersect : Module QFCTermSet QFCTermSet -> QFCTermSet .
eq disjIntersect(U,C | C' | CS,CS') = disjIntersect(U,C,CS' ) | disjIntersect(U,C' | CS,CS') .
eq disjIntersect(U,C,C' | C'' | CS) = disjIntersect(U,C,C') | disjIntersect(U,C,C'' | CS) .
eq disjIntersect(U,(T | F?),(T' | F'?)) = disjIntersect(T,F?,F'?,disjUnifiers(U,false,T,T')) .
op disjIntersect : Term QFForm? QFForm? SubstitutionPairSet -> QFCTermSet .
eq disjIntersect(T,F?,F'?,(S,S') | SPS) = (T << S | (F? << S) /\ (F'? << S')) | disjIntersect(T,F?,F'?,SPS) .
eq disjIntersect(T,F?,F'?,empty) = noterm .
--- PRE: QFCTerm and QFCTermSet have no shared variables
--- OUT: Pairs of Formulas/Substitutions that represent the intersections of
--- the first QFCTerm with each QFCTerm in the QFCTermSet, including the
--- instantiated Formulas of each QFCTerm in the QFCTermSet
op #intersect : Module QFCTerm QFCTermSet -> FOFormSubstPairSet .
eq #intersect(U,C,C' | C'' | CS) = #intersect(U,C,C') | #intersect(U,C,C'' | CS) .
eq #intersect(U,(T | F?),(T' | F'?)) = (F? /\ F'?) Pair<< safeUnify(U,T,T') .
op #disjIntersect : Module QFCTerm QFCTerm -> FOFormSubstPairSet .
ceq #disjIntersect(U,C,C') = #intersect(U,C1,C2)
if (S, T ,N ) := #renameAllVar(U,none, upTerm(C ))
/\ (S',T',N') := #renameAllVar(U,none,N,upTerm(C'))
/\ C1 := downTerm(T ,noterm)
/\ C2 := downTerm(T',noterm) .
op toCCTermSet : QFCTermSet -> QFCTermSet .
op toCCTermSet : QFCTermSet QFCTermSet -> QFCTermSet .
op toCCTermSet1 : Term QFForm?Set QFCTermSet -> QFCTermSet .
------------------------------------------------------------
eq toCCTermSet(CS) = toCCTermSet(CS,noterm) .
eq toCCTermSet((T | F?) | CS,CS') = toCCTermSet(CS,CS' | toCCTermSet1(T,disjToSet(toDNF(F?)),noterm)) .
eq toCCTermSet(noterm,CS') = CS' .
eq toCCTermSet1(T,F | FS, CS) = toCCTermSet1(T,FS,CS | (T | F)) .
eq toCCTermSet1(T,mtFormSet,CS) = CS .
op renameVars : QFCTermSet -> QFCTermSet .
op renameVars : Nat QFCTermSet -> QFCTermSet .
op renameVars : Nat QFCTermSet QFCTermSet -> QFCTermSet .
---------------------------------------------------------
eq renameVars(CS) = renameVars(0,CS) .
eq renameVars(N,CS) = renameVars(N,CS,noterm) .
eq renameVars(N,C | CS,CS') = renameVars(N,CS,CS' | (C << freshifyVars(N,vars(C)))) .
eq renameVars(N,noterm,CS') = CS' .
op varUnifSimp : Module QFCTermSet -> QFCTermSet .
op varUnifSimp : Module QFCTermSet QFCTermSet -> QFCTermSet .
op varUnifSimp1 : Module Term FOFormSubstPairSet QFCTermSet -> QFCTermSet .
---------------------------------------------------------------------------
eq varUnifSimp(U,CS) = varUnifSimp(U,CS,noterm) .
eq varUnifSimp(U,C | CS,CS') = varUnifSimp(U,CS,CS' | varUnifSimp1(U,term(C),#varunif-simp(U,cond(C)),noterm)) .
eq varUnifSimp(U,noterm,CS') = CS' .
eq varUnifSimp1(U,T,(F,S) | FSS,CS) = varUnifSimp1(U,T,FSS,(T << S | F) | CS) .
eq varUnifSimp1(U,T,mtFSPS, CS) = CS .
op basicSimplify : Module QFCTermSet -> QFCTermSet .
op basicSimplify : Module QFCTermSet QFCTermSet -> QFCTermSet .
---------------------------------------------------------------
eq basicSimplify(U,CS) = basicSimplify(U,CS,noterm) .
eq basicSimplify(U,(T | F?) | CS,CS') = basicSimplify(U,CS,CS' | delUnsat((T | simplify(reduce(U,F?))))) .
eq basicSimplify(U,noterm,CS') = CS' .
op delUnsat : QFCTerm -> QFCTerm? .
eq delUnsat((T | ff)) = noterm .
eq delUnsat((T | 'false.Bool ?= 'true.Bool /\ F?)) = noterm .
eq delUnsat((T | F?)) = (T | F?) [owise] .
endfm
fmod CONSTRAINED-TERM-INVARIANT is
pr CONSTRAINED-TERMSETPAIR .
pr RENAME-METAVARS .
pr TERM-EXTRA .
pr SUBSTITUTION-HANDLING .
op mk-pair : Module QidSet QFCTermSet -> QFCTermSetPair .
op mk-pair : Module QidSet Substitution Nat QFCTermSet QFCTermSet -> RenameData .
op wrap-term : Module QFCTermSetPair Qid -> [QFCTermSetPair] .
op wrap-term : Module QFCTermSet Qid -> [QFCTermSet] .
op wrap-term : Module Term Qid -> [Term] .
var M : Module . var VS : QidSet . var N N' : Nat . var T T' : Term . var TL : NeTermList .
var CT CT' : QFCTerm . var D D' : QFCTermSet . var Q Q' : Qid . var S S' : Substitution .
var C : QFForm? .
--- INP: Module QidSet QFCTermSet
--- PRE: QFCTermSet is well-defined with respect to Module
--- OUT: A ReachFormEx where D => D with all variables except VS renamed
ceq mk-pair(M,VS,D) = (downTerm(T,noterm),downTerm(T',noterm))
if (S, T, N ) := mk-pair(M,VS,none,0,D,noterm)
/\ (S',T',N') := mk-pair(M,VS,S, N,D,noterm) .
--- INP: Module QidSet S:Substitution N:Nat QFCTermSet QFCTermSet
--- PRE: Arguments are well-defined with respect to Module
--- OUT: Renamed QFCTermSet where variables in VS inherit their value from
--- the substitution S and all other variables have values generated
--- to be fresh with respect to S and Nat N
ceq mk-pair(M,VS,S,N,CT | D,D') = mk-pair(M,VS,S',N',D,CT' | D')
if (S',T,N') := #renameAllVar(M,S |>* varsToTermList(VS),N,upTerm(CT))
/\ CT' := downTerm(T,noterm)
/\ CT' =/= noterm .
eq mk-pair(M,VS,S,N,noterm,CT | D') = (S,upTerm(CT | D'),N) .
eq wrap-term(M,(D,D'),Q) = (D,wrap-term(M,D',Q)) .
eq wrap-term(M,(T | C) | D,Q) = (wrap-term(M,T,Q) | C) | wrap-term(M,D,Q) .
eq wrap-term(M,noterm,Q) = noterm .
ceq wrap-term(M,Q[TL],Q') = Q'[TL] if wellFormed(M,Q'[TL]) .
endfm
fmod CONSTRAINED-TERM-PRINTER is pr CONSTRAINED-TERM . pr FOFORM-PRINTER . pr CONSTRAINED-TERM-OPERATIONS .
var M : Module . var T : Term . var F : FOForm? .
op print : Module CTerm? -> QidList .
ceq print(M,(T | F)) = printTerm(M,T) &sp '\r '||| '\y &sp print(M,F) '\o
if wellFormed(M,(T | F)) .
eq print(M,noterm) = nil .
eq print(MK:[Module],CK:[CTerm?]) = 'print 'error: 'unable 'to 'print 'constrained 'term [owise] .
op printMeta : CTerm? -> QidList .
eq printMeta((T | F)) = '`( printMeta(T) &sp '| printMeta(F) '`) .
eq printMeta(noterm) = 'noterm .
endfm
fmod CONSTRAINED-TERMSET-PRINTER is pr CONSTRAINED-TERMSET . pr CONSTRAINED-TERM-PRINTER .
var M : Module . var CT CT' : CTerm . var CTS : CTermSet . var Q : Qid .
op print : Module Qid CTermSet -> QidList .
eq print(M,CTS) = print(M,'\/,CTS) .
eq print(M,Q,CT | CT' | CTS) = print(M,CT) Q print(M,Q,CT' | CTS) .
eq print(M,Q,CT) = print(M,CT) .
eq print(M,Q,noterm) = 'none .
op printMeta : CTermSet -> QidList .
eq printMeta(CT | CT' | CTS) = printMeta(CT) &sp '| &sp printMeta(CT' | CTS) .
endfm
fmod CONSTRAINED-TERM-CONSTS-TO-VARS is pr CONSTRAINED-TERM . pr FOFORM-CONSTS-TO-VARS .
op constsToVars : Substitution CTerm? -> CTerm? .
var T : Term . var C : FOForm? . var S : Substitution .
eq constsToVars(S,(T | C)) = (constsToVars(S,T) | constsToVars(S,C)) .
eq constsToVars(S,noterm) = noterm .
endfm
fmod CONSTRAINED-TERMSET-CONSTS-TO-VARS is pr CONSTRAINED-TERM-CONSTS-TO-VARS . pr CONSTRAINED-TERMSET .
op constsToVars : Substitution CTermSet -> CTermSet .
var CT CT' : CTerm . var CTS : CTermSet . var S : Substitution .
eq constsToVars(S,CT | CT' | CTS) = constsToVars(S,CT) | constsToVars(S,CT' | CTS) .
endfm
fmod CONSTRAINED-TERM-TRANSFORM is
pr CONSTRAINED-TERMSET-OPERATIONS .
pr CONSTRAINED-TERMSET-PROJECTIONS .
pr CONSTRAINED-TERMSET-MATCH .
pr CONSTRAINED-TERM-SUBSTITUTIONSET .
pr FOFORMSIMPLIFY .
pr RENAME-TERM-AUX .
var T : Term .
var F F' : FOForm? .
var CT CT' : CTerm .
var CTS : CTermSet .
var U : Module .
var VS : VariableSet .
var SS : SubstitutionSet .
var VSub : VarSubstitution .
op simplify : CTermSet -> CTermSet .
ceq simplify((T | F) | (T | F') | CTS) = simplify((T | tt) | CTS) if simplify(F \/ F') == tt .
eq simplify( CTS) = CTS [owise] .
--- PRE: All variables should be standard variables
--- OUT: Apply transformation
op transform : Module CTerm SubstitutionSet CTermSet ~> CTermSet .
op transform : Module CTerm VariableSet SubstitutionSet CTermSet -> CTermSet .
op transform : Module Substitution SubstitutionSet CTerm -> CTerm .
ceq transform(U,CT,SS,CTS) = transform(U,CT,domain(SS),SS,CTS) if domain(SS) subset vars(CT) .
eq transform(U,CT,VS,SS,CT' | CTS) =
if matches#(U,CT,CT') :: NeSubstitutionSet then
transform(U,filterIn(anySub(matches#(U,CT,CT')),VS),SS,CT')
else
CT
fi | transform(U,CT,VS,SS,CTS) .
eq transform(U,CT,VS,SS,noterm) = noterm .
eq transform(U,VSub,SS,CT) = CT << (invert(VSub) << renameVars(nameData(maxVar(vars(CT))),SS)) .
---op transform : CTerm FOForm?Set CTermSet -> CTermSet .
endfm
fmod CONSTRAINED-TERM-SPLIT is
pr CONSTRAINED-TERM-PROJECTIONS .
pr CONSTRAINED-TERM-OPERATIONS .
pr FOFORM-SPLIT .
pr FOFORMSET-OPERATIONS .
pr CONSTRAINED-TERMSET-MATCH .
pr SUBSTITUTIONSET-AUX .
var F : FOForm .
var FS : FOFormSet .
var CT PT : CTerm .
var T : Term .
var TS : TermSet .
var CTS CTS' : CTermSet .
var U : Module .
var VS : VariableSet .
--- split an individual constrained term
op join : Term FOFormSet -> CTermSet .
op join : Term QFFormSet -> QFCTermSet .
op join : Term FOFormSet CTermSet -> CTermSet .
op join : Term QFFormSet QFCTermSet -> QFCTermSet .
---------------------------------------------------
eq join(T,FS) = join(T,FS,noterm) .
eq join(T,F | FS, CTS) = join(T,FS,CTS | (T | F)) .
eq join(T,mtFormSet,CTS) = CTS .
op split-by-form : CTerm FOFormSet -> CTermSet .
op split-by-form : QFCTerm QFFormSet -> QFCTermSet .
----------------------------------------------------
eq split-by-form(CT,FS) = join(term(CT),split-by-form(cond(CT),FS)) .
op split-by-cover : CTerm Term TermSet -> CTermSet .
op split-by-cover : QFCTerm Term TermSet -> QFCTermSet .
--------------------------------------------------------
eq split-by-cover(CT,T,TS) = join(term(CT),split-by-cover(cond(CT),T,TS)) .
op split-by-neg : CTerm FOForm -> CTermSet .
op split-by-neg : QFCTerm QFForm -> QFCTermSet .
------------------------------------------------
eq split-by-form(CT,F) = join(term(CT),split-by-neg(cond(CT),F)) .
--- lift individual operations to sets
op split-by-form : Module CTermSet CTerm FOFormSet -> CTermSet .
op split-by-form : Module QFCTermSet CTerm QFFormSet -> QFCTermSet .
op split-by-form : Module CTermSet CTerm FOFormSet VariableSet CTermSet -> CTermSet .
op split-by-form : Module QFCTermSet CTerm QFFormSet VariableSet QFCTermSet -> QFCTermSet .
-------------------------------------------------------------------------------------------
eq split-by-form(U,CTS,PT,FS) = split-by-form(U,CTS,PT,FS,vars(conj-join(FS)) \ vars(PT),noterm) .
eq split-by-form(U,CT | CTS,PT,FS,VS,CTS') = split-by-form(U,CTS,PT,FS,VS,CTS' |
if match#(U,false,PT,CT,0) :: Substitution
then split-by-form(CT,FS << (match#(U,false,PT,CT,0) ; freshifyVars(maxVar(vars(CT)),VS)))
else CT
fi) .
eq split-by-form(U,noterm,PT,FS,VS,CTS') = CTS' .
op split-by-cover : Module CTermSet CTerm Term TermSet -> CTermSet .
op split-by-cover : Module QFCTermSet CTerm Term TermSet -> QFCTermSet .
op split-by-cover : Module CTermSet CTerm Term TermSet VariableSet CTermSet -> CTermSet .
op split-by-cover : Module QFCTermSet CTerm Term TermSet VariableSet QFCTermSet -> QFCTermSet .
-----------------------------------------------------------------------------------------------
eq split-by-cover(U,CTS,PT,T,TS) = split-by-cover(U,CTS,PT,T,TS,vars(T | TS) \ vars(PT),noterm) .
eq split-by-cover(U,CT | CTS,PT,T,TS,VS,CTS') = split-by-cover(U,CTS,PT,T,TS,VS,CTS' |
if debugPrintBool(match#(U,false,PT,CT,0) :: Substitution)
then split-by-cover(CT,T << (match#(U,false,PT,CT,0) ; freshifyVars(maxVar(vars(CT)),VS)),
TS << (match#(U,false,PT,CT,0) ; freshifyVars(maxVar(vars(CT)),VS)))
else CT
fi) .
eq split-by-cover(U,noterm,PT,T,TS,VS,CTS') = CTS' .
op split-by-neg : Module CTermSet CTerm FOForm -> CTermSet .
op split-by-neg : Module QFCTermSet CTerm QFForm -> QFCTermSet .
op split-by-neg : Module CTermSet CTerm FOForm VariableSet CTermSet -> CTermSet .
op split-by-neg : Module QFCTermSet CTerm QFForm VariableSet QFCTermSet -> QFCTermSet .
---------------------------------------------------------------------------------------
eq split-by-neg(U,CTS,PT,F) = split-by-neg(U,CTS,PT,F,vars(F) \ vars(PT),noterm) .
eq split-by-neg(U,CT | CTS,PT,F,VS,CTS') = split-by-neg(U,CTS,PT,F,VS,CTS' |
if match#(U,false,PT,CT,0) :: Substitution
then split-by-neg(CT,F << (match#(U,false,PT,CT,0) ; freshifyVars(maxVar(vars(CT)),VS)))
else CT
fi) .
eq split-by-neg(U,noterm,PT,F,VS,CTS') = CTS' .
op debugPrintBool : Bool -> Bool .
eq debugPrintBool(B:Bool) = B:Bool [print "Match result: " B:Bool] .
endfm