-
Notifications
You must be signed in to change notification settings - Fork 2
/
proofstate.maude
1255 lines (1062 loc) · 52.2 KB
/
proofstate.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
--- file: proofstate.maude
--- reqs: prelude, full-maude, prelude-aux, var-sat (plus dependencies), reachform (plus dependencies)
--- info: models the state of a reachability logic proof
fmod REACH-PROOF-STRATEGY is
pr LABEL-TRANSITION-LIST .
pr TERMSET-FM .
var AX : LabelReachForm .
var AXL AXL' : LabelReachFormList .
var CN CN' CN'' : ProofStrat .
var PA : ProofRuleAction .
var B : Bool .
sort ProofRuleAction ProofRuleActionList ProofStrat .
subsort ProofRuleAction < ProofStrat .
subsort ProofRuleAction < ProofRuleActionList .
--- basic proof rule actions
op subsume : -> ProofRuleAction [ctor] .
op simplify : Bool -> ProofRuleAction [ctor] .
op termcheck : -> ProofRuleAction [ctor] .
op step : -> ProofRuleAction [ctor] .
op axiom : LabelReachForm -> ProofRuleAction [ctor] .
op case : Variable TermSet -> ProofRuleAction [ctor] .
op split : Bool QFForm QFForm -> ProofRuleAction [ctor] .
op pause : -> ProofRuleAction [ctor] .
op giveup : -> ProofRuleAction [ctor] .
op result : Bool -> ProofStrat [ctor] .
--- lists
op __ : ProofRuleActionList ProofRuleActionList -> ProofRuleActionList [ctor assoc] .
--- sequencing
op _;;_ : ProofStrat ProofStrat -> ProofStrat [ctor strat (1 0) gather (e E)] .
--- short-circuited choice (pick the first one that succeeds)
op _|_ : ProofStrat ProofStrat -> ProofStrat [ctor strat (1 0) gather (e E)] .
--- evaluate result of proof steps
eq result(true) | CN = result(true) .
eq result(false) | CN = CN .
eq result(true) ;; CN = CN .
eq result(false) ;; CN = giveup .
op update : Bool ProofStrat -> ProofStrat .
eq update(B,CN) = update2(update1(B,CN)) .
op update1 : Bool ProofStrat -> ProofStrat .
eq update1(B,CN ;; CN') = update1(B,CN) ;; CN' .
eq update1(B,CN | CN') = update1(B,CN) | CN' .
eq update1(B,PA) = result(B) .
op update2 : ProofStrat -> ProofStrat .
eq update2(result(B)) = giveup .
eq update2(CN) = CN [owise] .
--- loop over axioms
op loop-axioms : LabelReachFormList ProofStrat -> ProofStrat [strat (1 0)] .
eq loop-axioms(AX ; AXL,CN) = axiom(AX) | loop-axioms(AXL,CN) .
eq loop-axioms(nil,CN) = CN .
--- the default proof strategy
op default : LabelReachFormList -> ProofStrat .
eq default(AXL) = simplify(true) ;;
subsume ;;
termcheck ;;
step ;;
simplify(true) ;;
subsume ;;
termcheck ;;
pause ;;
default-loop(AXL) .
op default-loop : LabelReachFormList -> ProofStrat .
eq default-loop(AXL) = loop-axioms(AXL,step) ;;
simplify(true) ;;
subsume ;;
termcheck ;;
pause ;;
default-loop(AXL) .
--- the default proof strategy with (assumed) axioms
op default : LabelReachFormList LabelReachFormList -> ProofStrat .
eq default(AXL,AX ; AXL') = simplify(true) ;;
subsume ;;
termcheck ;;
loop-axioms(AXL,step) ;;
simplify(true) ;;
subsume ;;
termcheck ;;
pause ;;
default-loop(AX ; AXL') .
eq default(AXL,nil) = default(AXL) .
--- make a proof action come first
eq (CN | CN') | CN'' = CN | (CN' | CN'') .
eq (CN ;; CN') ;; CN'' = CN ;; (CN' ;; CN'') .
--- OUT: get head item
op nextaction : ProofStrat -> ProofRuleAction .
eq nextaction(CN ;; CN') = nextaction(CN) .
eq nextaction(CN | CN') = nextaction(CN) .
eq nextaction(PA) = PA .
--- OUT: get tail of list
op tail : ProofRuleActionList -> ProofRuleAction .
eq tail(PRL:ProofRuleActionList PA) = PA .
eq tail(PA) = PA .
endfm
fmod REACH-PROOF-GOAL is
pr TRANSITION-PROJECTIONS .
pr TRANSITIONSET-OPERATIONS .
pr CONSTRAINED-TERM-OPERATIONS .
pr SET{Nat} .
pr TRANSITIONSET-RENAME .
pr REACH-PROOF-STRATEGY .
pr TRANSITION-SUBSTITUTION .
var N N' : Nat .
var P : Parent .
var PS PS' : ProofGoalStatus .
var CN CN' : ProofStrat .
var VS VS' : VariableSet .
var F F' : ReachForm .
sort ProofGoalStatus .
op active : -> ProofGoalStatus [ctor] .
op paused : -> ProofGoalStatus [ctor] .
op inactive : -> ProofGoalStatus [ctor] .
sort ProofGoal .
op [_,_,_,_,_,_] : Parent Nat ProofStrat ProofGoalStatus VariableSet ReachForm -> ProofGoal
[ctor format (g! o d d d d d d d d d d g! o)] .
---# Parents
op getparent : ProofGoal -> Parent .
eq getparent([P,N,CN,PS,VS,F]) = P .
---# Id
op getid : ProofGoal -> Nat .
eq getid([P,N,CN,PS,VS,F]) = N .
op setid : ProofGoal Nat -> ProofGoal .
eq setid([P,N,CN,PS,VS,F],N') = [P,N',CN,PS,VS,F] .
op addid : ProofGoal Nat -> ProofGoal .
eq addid([P,N,CN,PS,VS,F],N') = [P,N + N',CN,PS,VS,F] .
---# Strategies
op getstrat : ProofGoal -> ProofStrat .
eq getstrat([P,N,CN,PS,VS,F]) = CN .
op setstrat : ProofGoal ProofStrat -> ProofGoal .
eq setstrat ([P,N,CN,PS,VS,F],CN') = [P,N,CN',PS,VS,F] .
op prestrat : ProofGoal ProofStrat -> ProofGoal .
eq prestrat([P,N,CN,PS,VS,F],CN') = [P,N,CN' ;; CN,PS,VS,F] .
---# Status
op getstatus : ProofGoal -> ProofGoalStatus .
eq getstatus([P,N,CN,PS,VS,F]) = PS .
op setstatus : ProofGoalStatus ProofGoal -> ProofGoal .
eq setstatus(PS',[P,N,CN,PS,VS,F]) = [P,N,CN,PS',VS,F] .
op flipPaused : ProofGoal -> ProofGoal .
eq flipPaused([P,N,CN,PS,VS,F]) = [P,N,CN,if PS == paused then active else PS fi,VS,F] .
---# Variables
op getvars : ProofGoal -> QidSet .
eq getvars([P,N,CN,PS,VS,F]) = VS .
op getpvars : ProofGoal -> QidSet .
eq getpvars([P,N,CN,PS,VS,F]) = vars(antc(F)) .
op getallvars : ProofGoal -> QidSet .
eq getallvars([P,N,CN,PS,VS,F]) = vars(F) ; VS .
op setvars : ProofGoal VariableSet -> ProofGoal .
eq setvars([P,N,CN,PS,VS,F],VS') = [P,N,CN,PS,VS',F] .
---# Body
op getbody : ProofGoal -> ReachForm .
eq getbody([P,N,CN,PS,VS,F]) = F .
op setbody : ProofGoal ReachForm -> ProofGoal .
eq setbody([P,N,CN,PS,VS,F],F') = [P,N,CN,PS,VS,F'] .
endfm
fmod REACH-PROOF-GOALSET is
pr REACH-PROOF-GOAL .
pr SUBSTITUTIONSET .
pr SUBSTITUTION-AUX .
pr TRANSITION-TUPLES .
pr TRANSITION-MATCH .
pr TRANSITIONSET-PROJECTIONS .
pr FOFORMSET-OPERATIONS .
pr CONSTRAINED-TERMSET-MATCH .
pr FINDRESULT-AUX .
var P P' : Parent .
var N N' M : Nat .
var CN CN' : ProofStrat .
var PS PS' : ProofGoalStatus .
var VS VS' : VariableSet .
var F F' : ReachForm .
var G G' : ProofGoal .
var GS GS' : ProofGoalSet .
var U : Module .
var Idx Idx2 : FindResult .
var NS : Set{Nat} .
var FS : ReachFormSet .
var RSS : ReachFormSubstPairSet .
var T : Term .
var D : NeQFCTermSet .
var S : Substitution .
var SS : SubstitutionSet .
var GSS : ProofGoalSubstPairSet .
var C! : QFForm .
var C C' : QFForm? .
var B : Bool .
sort NeProofGoalSet MaybeProofGoal ProofGoalSet .
subsort ProofGoal < MaybeProofGoal NeProofGoalSet < ProofGoalSet .
op _&&_ : ProofGoalSet ProofGoalSet -> ProofGoalSet [ctor assoc comm id: mt format (d d nn d)] .
op _&&_ : ProofGoalSet NeProofGoalSet -> NeProofGoalSet [ctor ditto] .
op mt : -> MaybeProofGoal [ctor] .
sort ProofGoalSubstPair NeProofGoalSubstPairSet ProofGoalSubstPairSet .
subsort ProofGoalSubstPair < NeProofGoalSubstPairSet < ProofGoalSubstPairSet .
op ((_,_)) : ProofGoal Substitution -> ProofGoalSubstPair [ctor] .
op _&&_ : ProofGoalSubstPairSet ProofGoalSubstPairSet -> ProofGoalSubstPairSet [ctor assoc comm id: .ProofGoalSubstPairSet] .
op _&&_ : NeProofGoalSubstPairSet ProofGoalSubstPairSet -> NeProofGoalSubstPairSet [ctor ditto] .
op .ProofGoalSubstPairSet : -> ProofGoalSubstPairSet [ctor] .
---# extract goals out
op toGoalSet : ProofGoalSubstPairSet ~> ProofGoalSet .
eq toGoalSet((G,S) && GSS) = G && toGoalSet(GSS) .
eq toGoalSet(.ProofGoalSubstPairSet) = mt .
---# Parents
op getparents : ProofGoalSet -> Set{Nat} .
eq getparents(G && GS) = if getparent(G) :: Nat
then getparent(G)
else empty
fi , getparents(GS) .
eq getparents(mt) = empty .
op getparentsOrSelf : ProofGoalSet -> Set{Nat} .
eq getparentsOrSelf(G && GS) = if getparent(G) :: Nat
then getparent(G)
else getid(G)
fi , getparentsOrSelf(GS) .
eq getparentsOrSelf(mt) = empty .
--- OUT: applies getparents recursively
op getparentsR : ProofGoalSet Set{Nat} Bound -> Set{Nat} .
eq getparentsR(GS,NS,s(N)) = getparentsR(GS,getparentsOrSelf(getgl!(GS,NS)),N) .
eq getparentsR(GS,NS,0) = NS .
eq getparentsR(GS,NS,unbounded) =
if NS == getparentsOrSelf(getgl!(GS,NS))
then NS
else getparentsR(GS,getparentsOrSelf(getgl!(GS,NS)),unbounded)
fi .
op getdescendants : Set{Nat} ProofGoalSet -> ProofGoalSet .
eq getdescendants(NS,GS) = getdescendants(NS,GS,mt) .
op getdescendants : Set{Nat} ProofGoalSet ProofGoalSet -> ProofGoalSet .
eq getdescendants((N,NS),[N,M,CN,PS,VS,F] && GS,GS') =
getdescendants((N,M,NS),GS,[N,M,CN,PS,VS,F] && GS') .
eq getdescendants(NS,GS,GS') = GS' [owise] .
op getleaves : ProofGoalSet -> ProofGoalSet .
eq getleaves([N',N,CN,PS,VS,F] && [N,M,CN',PS',VS',F'] && GS) = getleaves([N,M,CN',PS',VS',F'] && GS) .
eq getleaves(GS) = GS [owise] .
---# Id
op getid : ProofGoalSet -> Set{Nat} .
eq getid(G && G' && GS) = getid(G), getid(G' && GS) .
eq getid(mt) = empty .
---# Proof Strategy
op setstrat : ProofGoalSet ProofStrat -> ProofGoalSet .
eq setstrat(G && G' && GS,CN) = setstrat(G,CN) && setstrat(G' && GS,CN) .
eq setstrat(mt,CN) = mt .
op prestrat : ProofGoalSet ProofStrat -> ProofGoalSet .
eq prestrat(G && G' && GS,CN) = prestrat(G,CN) && prestrat(G' && GS,CN) .
eq prestrat(mt,CN) = mt .
---# Status
op setstatus : ProofGoalStatus ProofGoalSet -> ProofGoalSet .
eq setstatus(PS,G && G' && GS) = setstatus(PS,G) && setstatus(PS,G' && GS) .
eq setstatus(PS,mt) = mt .
op flipPaused : ProofGoalSet -> ProofGoalSet .
eq flipPaused(G && G' && GS) = flipPaused(G) && flipPaused(G' && GS) .
eq flipPaused(mt) = mt .
---# Body
op getbody : ProofGoalSet -> ReachFormSet .
eq getbody(G && G' && GS) = getbody(G) & getbody(G' && GS) .
eq getbody(mt) = mt .
---# General Functions and Predicates
--- OUT: size of the given ProofGoalSet
op size : ProofGoalSet -> Nat .
eq size(G && GS) = s(size(GS)) .
eq size((mt).ProofGoalSet) = 0 .
--- OUT: true iff the one set/two sets have have a shared duplicate
op duplIdGoal? : ProofGoalSet -> Bool .
eq duplIdGoal?([P,N,CN,PS,VS,F] && [P',N,CN',PS',VS',F'] && GS') = true .
eq duplIdGoal?(GS) = false [owise] .
op duplIdGoal? : ProofGoalSet ProofGoalSet -> Bool .
eq duplIdGoal?([P,N,CN,PS,VS,F] && GS,[P',N,CN',PS',VS',F'] && GS') = true .
eq duplIdGoal?(GS,GS') = false [owise] .
--- PRE: Goals are well-formed in module
--- OUT: Consistently renamed and ACU-normalized goals
--- NB: Parameter field and body variables are consistently renamed
--- because they are part of the same metaterm that is renamed
op renameNormalizeGoal : Module FindResult ProofGoalSet -> ProofGoalSet .
eq renameNormalizeGoal(U,Idx,G && GS) =
renameNormalizeGoal2(U,Idx,freshifyVars(toNat(Idx,0),getallvars(G)),G) &&
renameNormalizeGoal(U,Idx,GS) .
eq renameNormalizeGoal(U,Idx,mt) = (mt).ProofGoalSet .
op renameNormalizeGoal2 : Module FindResult Substitution ProofGoal -> ProofGoal .
eq renameNormalizeGoal2(U,Idx,S,G) =
setvars(
setbody(G,normalize(U,getbody(G) << S)),
captureNewVars(getvars(G),S)) .
--- OUT: deletes duplicate goals in a set and renumbers them starting from given value
op deleteDuplGoals : Nat ProofGoalSet -> ProofGoalSet .
eq deleteDuplGoals(M,[P,N,CN,PS,VS,F] && [P',N',CN',PS',VS',F] && GS) =
deleteDuplGoals(M,if N < N' then [P,N,CN,PS,VS,F] else [P',N',CN',PS',VS',F] fi && GS) .
eq deleteDuplGoals(M,GS) = renumberGoals(M,GS) [owise] .
--- OUT: delete goals that are subsumed by matching
op deleteGoalsByMatch : Module ProofGoalSet -> ProofGoalSet .
eq deleteGoalsByMatch(U,GS) = deleteGoalsByMatch(U,GS,mt) .
op deleteGoalsByMatch : Module ProofGoalSet ProofGoalSet -> ProofGoalSet .
eq deleteGoalsByMatch(U,G && GS,GS') = deleteGoalsByMatch(U,deleteGoalByMatch(U,G,GS),G && deleteGoalByMatch(U,G,GS')) .
eq deleteGoalsByMatch(U,mt,GS') = GS' .
--- NB: check that the body of goal G matches that of G'
op deleteGoalByMatch : Module ProofGoal ProofGoalSet -> ProofGoalSet .
eq deleteGoalByMatch(U,G,G' && GS') =
deleteGoalByMatch(matches(U,getbody(G),getbody(G')),G,G') &&
deleteGoalByMatch(U,G,GS') .
eq deleteGoalByMatch(U,G,mt) = mt .
--- NB: check that the parameters of goal G cover those of G'
op deleteGoalByMatch : SubstitutionSet ProofGoal ProofGoal -> MaybeProofGoal .
eq deleteGoalByMatch(S | SS,G,G') =
if getvars(G') subset captureNewVars(getvars(G),S)
then mt
else deleteGoalByMatch(SS,G,G')
fi .
eq deleteGoalByMatch(empty,G,G') = G' .
--- OUT: Extracts a subset of ProofGoals whose IDs match those in the NatListSet
--- The function getgl!() is strict; it will error out when it cannot find
--- all specified ProofGoals where getgl() will return a subset of those
--- matched without error
op getgl! : ProofGoalSet Set{Nat} -> [ProofGoalSet] .
eq getgl!([P,N,CN,PS,VS,F] && GS,(N,NS)) = [P,N,CN,PS,VS,F] && getgl!(GS,NS) .
eq getgl!(GS,empty) = mt .
op getgl : ProofGoalSet Set{Nat} -> ProofGoalSet .
eq getgl([P,N,CN,PS,VS,F] && GS,(N,NS)) = [P,N,CN,PS,VS,F] && getgl(GS,NS) .
eq getgl(mt,NS) = mt .
eq getgl(GS,NS) = mt [owise] .
--- OUT: Finds the goals with the same id in the set;
--- sets its state to match this goal
op setgl! : ProofGoalSet ProofGoalSet ~> ProofGoalSet .
eq setgl!([P,N,CN,PS,VS,F] && GS,[P',N,CN',PS',VS',F'] && GS') = [P',N,CN',PS',VS',F'] && setgl!(GS,GS') .
eq setgl!(GS,mt) = GS .
op setgl : ProofGoalSet ProofGoalSet -> ProofGoalSet .
eq setgl([P,N,CN,PS,VS,F] && GS,[P',N,CN',PS',VS',F'] && GS') = [P',N,CN',PS',VS',F'] && setgl(GS,GS') .
eq setgl(GS,GS') = GS [owise] .
--- OUT: Finds the goals with the same id in the set and deletes them
op delgl : ProofGoalSet ProofGoalSet -> ProofGoalSet .
eq delgl([P,N,CN,PS,VS,F] && GS,[P',N,CN',PS',VS',F'] && GS') = delgl(GS,[P',N,CN',PS',VS',F'] && GS') .
eq delgl(GS,GS') = GS [owise] .
--- OUT: Get the set of active goals
op goalsByStatus : ProofGoalStatus ProofGoalSet -> ProofGoalSet .
op goalsByStatus : ProofGoalStatus ProofGoalSet ProofGoalSet -> ProofGoalSet .
------------------------------------------------------------------------------
eq goalsByStatus(PS,GS) = goalsByStatus(PS,GS,mt) .
eq goalsByStatus(PS,[P,N,CN,PS',VS,F] && GS,GS') =
goalsByStatus(PS,GS,if PS == PS' then [P,N,CN,PS',VS,F] && GS' else GS' fi) .
eq goalsByStatus(PS,mt,GS') = GS' .
op !goalsByStatus : ProofGoalStatus ProofGoalSet -> ProofGoalSet .
op !goalsByStatus : ProofGoalStatus ProofGoalSet ProofGoalSet -> ProofGoalSet .
-------------------------------------------------------------------------------
eq !goalsByStatus(PS,GS) = !goalsByStatus(PS,GS,mt) .
eq !goalsByStatus(PS,[P,N,CN,PS',VS,F] && GS,GS') =
!goalsByStatus(PS,GS,if PS =/= PS' then [P,N,CN,PS',VS,F] && GS' else GS' fi) .
eq !goalsByStatus(PS,mt,GS') = GS' .
op readyGoals : ProofGoalSet -> ProofGoalSet .
op readyGoals : ProofGoalSet ProofGoalSet -> ProofGoalSet .
-----------------------------------------------------------
eq readyGoals(GS) = readyGoals(GS,mt) .
eq readyGoals([P,N,CN,PS,VS,F] && GS,GS') =
readyGoals(GS,if PS == active or PS == paused then [P,N,CN,PS,VS,F] && GS' else GS' fi) .
eq readyGoals(mt,GS') = GS' .
--- OUT: Get an active goal if it exists
op getActiveGoal : ProofGoalSet ~> ProofGoal .
eq getActiveGoal([P,N,CN,active,VS,F] && GS) = [P,N,CN,active,VS,F] .
--- PRE: Term and VariableSet have no shared variables
--- OUT: A set of goals whose LHS matches the pattern plus witnessing substitutions
--- such that witnessing substitutions remap all variables in VariableSet to be
--- fresh with respect to the ProofGoal that they match
op #goalsByMatch : Module Term ProofGoalSet ~> ProofGoalSubstPairSet .
op #goalsByMatch : Module QFCTerm ProofGoalSet ~> ProofGoalSubstPairSet .
op #goalsByMatch : Module VariableSet Term ProofGoalSet ~> ProofGoalSubstPairSet .
op #goalsByMatch : Module VariableSet QFCTerm ProofGoalSet ~> ProofGoalSubstPairSet .
-------------------------------------------------------------------------------------
eq #goalsByMatch(U, T, GS) = #goalsByMatch(U,none,T, GS) .
eq #goalsByMatch(U, (T | C),GS) = #goalsByMatch(U,none,(T | C),GS) .
ceq #goalsByMatch(U,VS,T, GS) = #goalsByMatchImpl(U,VS,(T | mtForm), GS,.ProofGoalSubstPairSet) if intersection(vars(T), VS) == none .
ceq #goalsByMatch(U,VS,(T | C),GS) = #goalsByMatchImpl(U,VS,(T | true2mt(C)),GS,.ProofGoalSubstPairSet) if intersection(vars((T | C)),VS) == none .
op #goalsByMatchImpl : Module VariableSet QFCTerm ProofGoalSet ProofGoalSubstPairSet ~> ProofGoalSubstPairSet .
---------------------------------------------------------------------------------------------------------------
eq #goalsByMatchImpl(U,VS,(T | mtForm),G && GS,GSS) = #goalsByMatchImpl(U,VS,(T | mtForm),GS,if metaMatch(U,T,lhs(getbody(G)),0) :: Substitution then (G,metaMatch(U,T,lhs(getbody(G)),0) ; freshifyVars(maxVar(getallvars(G)),VS)) && GSS else GSS fi) .
eq #goalsByMatchImpl(U,VS,(T | C!), G && GS,GSS) = #goalsByMatchImpl(U,VS,(T | C!), GS,if match#(U,false,(T | C!),antc(getbody(G)),0) :: Substitution then (G,match#(U,false,(T | C!),antc(getbody(G)),0) ; freshifyVars(maxVar(getallvars(G)),VS)) && GSS else GSS fi) .
eq #goalsByMatchImpl(U,VS,(T | C), mt, GSS) = GSS .
--- OUT: Goalset whose LHS does matches OR does NOT match the pattern
op goalsByMatch : Module Term ProofGoalSet ~> ProofGoalSet .
op goalsByMatch : Module QFCTerm ProofGoalSet ~> ProofGoalSet .
op !goalsByMatch : Module Term ProofGoalSet ~> ProofGoalSet .
op !goalsByMatch : Module QFCTerm ProofGoalSet ~> ProofGoalSet .
----------------------------------------------------------------
eq goalsByMatch(U,T, GS) = goalsByMatchImpl(U,true, (T | mtForm), GS,mt) .
eq goalsByMatch(U,(T | C),GS) = goalsByMatchImpl(U,true, (T | true2mt(C)),GS,mt) .
eq !goalsByMatch(U,T, GS) = goalsByMatchImpl(U,false,(T | mtForm), GS,mt) .
eq !goalsByMatch(U,(T | C),GS) = goalsByMatchImpl(U,false,(T | true2mt(C)),GS,mt) .
op goalsByMatchImpl : Module Bool QFCTerm ProofGoalSet ProofGoalSet ~> ProofGoalSet .
-------------------------------------------------------------------------------------
eq goalsByMatchImpl(U,B,(T | mtForm),G && GS,GS') = goalsByMatchImpl(U,B,(T | mtForm),GS,if B == metaMatch(U,T,lhs(getbody(G)),0) :: Substitution then GS' && G else GS' fi) .
eq goalsByMatchImpl(U,B,(T | C!), G && GS,GS') = goalsByMatchImpl(U,B,(T | C!), GS,if B == match#(U,false,(T | C!),antc(getbody(G)),0) :: Substitution then GS' && G else GS' fi) .
eq goalsByMatchImpl(U,B,(T | C), mt, GS') = GS' .
--- OUT: Replace as many goals as possible by their generalizations
--- specified by the given pattern
op generalizeGoals : Module Term ProofGoalSet -> ProofGoalSet .
eq generalizeGoals(U,T,GS) = generalizeGoals2(T,#goalsByMatch(U,T,GS)) .
op generalizeGoals2 : Term ProofGoalSubstPairSet -> ProofGoalSet .
eq generalizeGoals2(T,(G,S) && GSS) =
setbody(G,set-conj-antc(getbody(G),(T | conj-join(toPosEqAtoms(S))))) &&
generalizeGoals2(T,GSS) .
eq generalizeGoals2(T,.ProofGoalSubstPairSet) = mt .
--- OUT: Replace as many goals as possible by their generalizations
--- specified by the given pattern with terms and conditions
op generalizeGoals : Module QFCTerm ProofGoalSet -> ProofGoalSet .
eq generalizeGoals(U,(T | C),GS) = generalizeGoals2(U,(T | C),#goalsByMatch(U,(T | C),GS)) .
op generalizeGoals2 : Module QFCTerm ProofGoalSubstPairSet -> ProofGoalSet .
eq generalizeGoals2(U,(T | C),(G,S) && GSS) =
generalizeGoals3((T | C),G,getFormValue(U,S)) && generalizeGoals2(U,(T | C),GSS) .
eq generalizeGoals2(U,(T | C),.ProofGoalSubstPairSet) = mt .
op generalizeGoals3 : QFCTerm ProofGoal FOFormSubstPair -> ProofGoal .
eq generalizeGoals3((T | C),G,(C',S)) =
setbody(G,(T | trueId(C /\ C' /\ conj-join(toPosEqAtoms(S)))) => succ(getbody(G))) .
---# Goal set creation
--- OUT: build a set of goals using the supplied set of sequents;
--- increment the goal number starting from Nat and with the
--- Parent as first argument
op mkGoals : Parent Nat ProofStrat ProofGoalStatus VariableSet ReachFormSubstPairSet -> ProofGoalSet .
eq mkGoals(P,N,CN,PS,VS,(F,S) & RSS) = [P,N,CN,PS,captureNewVars(VS,S),F] && mkGoals(P,s(N),CN,PS,VS,RSS) .
eq mkGoals(P,N,CN,PS,VS,mtRFSS) = mt .
--- OUT: build a set of goals as above but add vars from ReachFormSet
--- to marked variable set of ProofGoal instead of applying a mapping
op mkGoalsAddVars : Parent Nat ProofStrat ProofGoalStatus VariableSet ReachFormSet -> ProofGoalSet .
eq mkGoalsAddVars(P,N,CN,PS,VS,F & FS) = [P,N,CN,PS,VS ; vars(antc(F)),F] && mkGoalsAddVars(P,s(N),CN,PS,VS,FS) .
eq mkGoalsAddVars(P,N,CN,PS,VS,mt) = mt .
--- OUT: build child goals based on a parent goal
op newChildGoalWithStrat : ProofGoal ProofStrat ProofGoalStatus ReachForm -> ProofGoalSet .
eq newChildGoalWithStrat(G,CN,PS,F) = mkGoals(getid(G),0,CN,PS,getvars(G),liftRFSS(F)) .
--- OUT: copy a goal to become a child of itself
op copyGoalToChild : ProofGoal -> ProofGoal .
eq copyGoalToChild(G) = mkGoals(getid(G),0,getstrat(G),active,getvars(G),liftRFSS(getbody(G))) .
--- OUT: creates new child goals with ReachFormSubstPairSet
op newChildGoals : ProofGoal ReachFormSubstPairSet -> ProofGoalSet .
eq newChildGoals([P,N,CN,PS,VS,F'],RSS) = mkGoals(N,0,CN,PS,VS,RSS) .
--- OUT: creates new child goals and takes as their marked variables
--- the union of the parent goal and the children
op newChildGoalsAddVars : ProofGoal ReachFormSet -> ProofGoalSet .
eq newChildGoalsAddVars([P,N,CN,PS,VS,F'],FS) = mkGoalsAddVars(N,0,CN,PS,VS,FS) .
--- OUT: renumbers goals so that there are id numbers are in sequence
--- starting from the given number
op renumberGoals : Nat ProofGoalSet -> ProofGoalSet .
eq renumberGoals(N,G && GS) = setid(G,N) && renumberGoals(s(N),GS) .
eq renumberGoals(N,mt) = mt .
--- OUT: add Nat to each goal number
op renumberPlusGoals : Nat ProofGoalSet -> ProofGoalSet .
eq renumberPlusGoals(N,G && GS) = addid(G,N) && renumberPlusGoals(N,GS) .
eq renumberPlusGoals(N,mt) = mt .
--- OUT: Number of goals in the set
op numGoals : ProofGoalSet -> Nat .
eq numGoals(G && GS) = s(numGoals(GS)) .
eq numGoals(mt) = 0 .
endfm
fmod AXIOM-RESULT is
pr FOFORM .
pr TRANSITIONSET .
pr LABEL-TRANSITION .
var AX : LabelReachForm .
var S : Substitution .
var QF : QFForm? .
var FS : ReachFormSet .
var AR AR' : AxiomResult .
var ARL : AxiomResultList .
sort AxiomResult AxiomResultList .
subsort AxiomResult < AxiomResultList .
op axrule : LabelReachForm Substitution FOForm? ReachFormSet -> AxiomResult [ctor] .
op __ : AxiomResultList AxiomResultList -> AxiomResultList [ctor assoc id: nilax] .
op nilax : -> AxiomResultList [ctor] .
op errAxiomResult : QidList -> [AxiomResult] [ctor] .
op arAx : AxiomResultList -> LabelReachForm .
eq arAx(axrule(AX,S,QF,FS) ARL) = AX .
op arCond : AxiomResultList -> QFForm? .
eq arCond(axrule(AX,S,QF,FS) ARL) = QF .
op arRes : AxiomResultList -> ReachFormSet .
eq arRes(axrule(AX,S,QF,FS) ARL) = FS .
op head : AxiomResultList -> AxiomResult .
eq head(AR ARL) = AR .
op tail : AxiomResultList -> AxiomResultList .
eq tail(AR ARL) = ARL .
op delete : AxiomResult AxiomResultList -> AxiomResultList .
eq delete(AR,AR' ARL) = if AR == AR' then nilax else AR' fi delete(AR,ARL) .
eq delete(AR,nilax) = nilax .
op errAxiomResultMsg : [AxiomResult] -> QidList .
eq errAxiomResultMsg(A:[AxiomResult] errAxiomResult(QL:QidList) B:[AxiomResult]) = QL:QidList .
eq errAxiomResultMsg(A:[AxiomResult]) = nil .
endfm
fmod AXIOM-RECORD is
pr AXIOM-RESULT .
sort AxiomRecord .
op axrec : AxiomResultList -> AxiomRecord .
op axrec : AxiomResult AxiomResultList -> AxiomRecord .
endfm
view AxiomRecord from TRIV to AXIOM-RECORD is sort Elt to AxiomRecord . endv
fmod REACH-PROOF-STATUS is
var X : ProofStatusCode .
sort ProofStatusCode .
op err : -> ProofStatusCode [ctor] .
op done : -> ProofStatusCode [ctor] .
sort NormalStatus ExceptionalStatus ProofStatus .
subsort NormalStatus ExceptionalStatus < ProofStatus .
subsort ProofStatusCode < ProofStatus .
op __ : NormalStatus NormalStatus -> NormalStatus [ctor assoc comm id: noStatus] .
op __ : ExceptionalStatus NormalStatus -> ExceptionalStatus [ctor ditto] .
op __ : ExceptionalStatus ExceptionalStatus -> ExceptionalStatus [ctor ditto] .
op __ : ProofStatus ProofStatus -> ProofStatus [ctor ditto] .
op noStatus : -> NormalStatus [ctor] .
eq X X = X .
endfm
fmod REACH-PROOF-STATE is
pr REACH-PROOF-STATUS .
pr REACH-PROOF-GOALSET .
pr LABEL-TRANSITION-SET .
pr LABEL-TRANSITION-LIST .
pr SCOPED-REGISTRY .
pr MAP{Nat,AxiomRecord} .
sort ProofMetadatum .
op mod : Module -> ProofMetadatum [ctor format(g! o)] . --- narrowing module
op dcl : QidSet -> ProofMetadatum [ctor format(g! o)] . --- variables to be added to module for parsing
op reg : ScopedRegistry -> ProofMetadatum [ctor format(g! o)] . --- solver backend registry
op cnt : Nat -> ProofMetadatum [ctor format(g! o)] . --- next free variable
op axs : LabelReachFormList -> ProofMetadatum [ctor format(g! o)] . --- axioms
op rls : LabelLCCRuleSet -> ProofMetadatum [ctor format(g! o)] . --- abstracted rewrite rules
op tst : QFCTermSet -> ProofMetadatum [ctor format(g! o)] . --- terminating state set
op gn : Nat -> ProofMetadatum [ctor format(g! o)] . --- next fresh goal number
op his : Map{Nat,AxiomRecord} -> ProofMetadatum [ctor format(g! o)] . --- history of tried axiom attempts
op out : QidList -> ProofMetadatum [ctor format(g! o)] . --- output messages
op prf : ProofGoalSet -> ProofMetadatum [ctor format(g! o)] . --- the proof goals
op st : ProofStatus -> ProofMetadatum [ctor format(g! o)] . --- indicates an exceptional state
sort ProofMetadata ProofMetadata? .
subsort ProofMetadatum < ProofMetadata < ProofMetadata? .
op _;_ : ProofMetadata ProofMetadata -> ProofMetadata [ctor assoc comm id: none] .
op none : -> ProofMetadata [ctor] .
--- successful/failed proof updates
--- NB: failed updates have no resulting sequents;
--- resulting sequent set may be empty
sort ProofUpdate .
op ((_||_)) : ProofMetadata ProofGoalSet -> ProofUpdate [ctor] .
op ((_)) : ProofMetadata -> ProofUpdate [ctor] .
--- active/stopped proofs
sort Proof Proof? .
subsort Proof < Proof? .
op {_} : ProofMetadata -> Proof [ctor] .
op [_] : ProofMetadata -> Proof [ctor] .
op data : Proof -> ProofMetadata .
eq data({PM:[ProofMetadata]}) = PM:[ProofMetadata] .
eq data([PM:[ProofMetadata]]) = PM:[ProofMetadata] .
endfm
fmod REACH-PROOF-STATE-PRINTER is
pr CONSTRAINED-TERMSET-PRINTER .
pr LABEL-TRANSITIONSET-PRINTER .
pr REACH-PROOF-STATE .
var B : Bool .
var M : Module .
var N N' : Nat .
var P : Parent .
var G G' : ProofGoal .
var GS GS' : ProofGoalSet .
var NGS : NeProofGoalSet .
var D : ProofMetadata .
var QL : QidList .
var RF : ReachFormEx .
var SN : Set{Nat} .
var PRF : Proof .
var RK : [ReachFormEx] .
var DK : [ProofMetadata] .
var GK : [ProofGoal] .
var MK : [Module] .
--- OUT: print out the a Parent data structure
op printPar : Parent -> QidList .
eq printPar(none) = 'none .
eq printPar(N) = qid(string(N,10)) .
--- OUT: print out the status of this goal
op printStatus : ProofGoalStatus -> Qid .
eq printStatus(active) = 'active .
eq printStatus(paused) = 'paused .
eq printStatus(inactive) = 'inactive .
--- OUT: print out the next action that this goal will take
op printNext : ProofRuleAction -> Qid .
eq printNext(subsume) = 'subsume .
eq printNext(simplify(B)) = 'simplify .
eq printNext(termcheck) = 'termcheck .
eq printNext(step) = 'step .
eq printNext(axiom(L:LabelReachForm)) = 'axiom .
eq printNext(case(V:Variable,T:TermSet)) = 'case .
eq printNext(split(B:Bool,F:QFForm?,F':QFForm?)) = 'split .
eq printNext(giveup) = 'giveup .
eq printNext(result(B:Bool)) = 'result .
eq printNext(pause) = 'pause .
eq printNext(PS:ProofStrat) =
if PS:ProofStrat :: ProofRuleAction then 'Error: 'printnext 'ProofRuleAction
else 'Error: 'printnext 'ProofStrat fi .
--- OUT: given the parent formula and the child, print out the differences
--- between the two
op printDifferences : Module ReachFormEx ReachFormEx ~> QidList .
eq printDifferences(M,RK,RF) =
if RK == RF then 'id else if succ(RK) == succ(RF) then print(M,'\/,antc(RF)) &sp '=> &sp 'id else print(M,RF) fi fi .
--- OUT: given the set of all the goals in memory, print out the full history,
--- sorted first by parent id and then by child id, but collapsing redundant goal
--- pieces shared between parents and children
op printStatusGoals : Module ProofGoalSet ~> QidList .
eq printStatusGoals(M,GS) = printStatusGoals(M,GS,GS) .
eq printStatusGoals(MK:[Module],GK:[ProofGoal]) = 'Internal 'Error: 'printStatusGoals [owise] .
op printStatusGoals : Module ProofGoalSet ProofGoalSet ~> QidList .
eq printStatusGoals(M,G && NGS,GS) = printStatusGoals(M,G,GS) '\n printSpaces(8) printStatusGoals(M,NGS,GS) .
eq printStatusGoals(M,G,GS) = '`[ printPad(printStatus(getstatus(G)),8)
'| printPad(printPar(getparent(G)),5)
'| printPad(if getparent(G) :: Nat then if nextaction(getstrat(getgl!(GS,getparent(G)))) :: ProofRuleAction
then printNext(nextaction(getstrat(getgl!(GS,getparent(G)))))
else 'unknown
fi else 'init fi,9)
'| printPad(printPar(getid(G)),5)
'| &sp printDifferences(M,getbody(getgl!(GS,getparent(G))),getbody(G)) '`] .
eq printStatusGoals(M,(mt).ProofGoalSet,GS) = &mt .
--- OUT: print out all goals without status information
op printGoals : Module ProofGoalSet ~> QidList .
eq printGoals(M,G && NGS) = printGoals(M,G) '\n printSpaces(8) printGoals(M,NGS) .
eq printGoals(M,G) = '\r '`[ '\o printPad(printPar(getid(G)),5)
'\r '| '\o &sp print(M,getbody(G)) '\r '`] '\o .
eq printGoals(M,(mt).ProofGoalSet) = &mt .
eq printGoals(MK:[Module],GK:[ProofGoal]) = 'Internal 'Error: 'printGoals [owise] .
--- OUT: print out the set of all ids of all current goals
op printGoalIds : ProofGoalSet ~> QidList .
eq printGoalIds(G) = printPar(getid(G)) .
eq printGoalIds(G && NGS) = printGoalIds(G) &sp '`, &sp printGoalIds(NGS) .
eq printGoalIds(mt) = &mt .
eq printGoalIds(GK:[ProofGoal]) = 'Internal 'Error: 'printGoalIds [owise] .
--- OUT: print out a set of natural numbers
op printNatSet : Set{Nat} -> QidList .
eq printNatSet((N,N',SN)) = printPar(N) '; printNatSet((N',SN)) .
eq printNatSet(N) = printPar(N) .
eq printNatSet(empty) = 'empty .
eq printNatSet(NK:[Set{Nat}]) = 'Internal 'Error: 'printNatSet [owise] .
endfm
fmod REACH-PROOF-STATE-VALIDATION is
pr ABSTRACT-RULES . --- defines abstract-rules()
pr RULES-SHARE-KIND . --- defines rules-share-kind()
pr MOD-EXTRA . --- defines protecting?()
pr UNIT-FM . --- defines noModule
pr RLTOOL-SWITCHES . --- defines tool switches
pr REACH-PROOF-STATE .
pr REACH-PROOF-STATE-PRINTER .
pr LABEL-TRANSITION-CONVERSIONS .
var AX : LabelReachFormList .
var CT : QFCTermSet .
var G : ProofGoal .
var GS : ProofGoalSet .
var D : ProofMetadata .
var QL : QidList .
var QS : QidSet .
var Reg : ScopedRegistry .
var RF : ReachForm .
var MRF : MaybeReachFormEx .
var RFS : ReachFormSet .
var RL : LabelLCCRuleSet .
var U U' : Module .
--- OUT: if metadata is usable, return metadata;
--- for any unusable metadata, return an error message
--- embedded in an out() datum
--- PRE: [1] no mod() datum should appaar
--- [2] all items should have no constantized variables in them
op validate : Module ProofMetadata -> ProofMetadata .
eq validate(U,D ; dcl(QS)) =
if U =/= noModule
then if uniqueNames(QS) and-then
wellFormedSet(U,termQidsToSet(QS)) == true and-then
varsToConsts#(U,simple,QS) :: ModuleSubstPair
then dcl(QS)
else st(err) ; out('Error: 'added 'variable 'declarations 'are 'not 'usable;
'check 'for 'mistyped 'sort 'names 'and 'conflicting 'constant
'operators '\n)
fi else st(err) ; out('Error: 'set 'module 'before 'declaring 'variables '\n)
fi ; validate(U,D) .
eq validate(U,D ; reg(Reg)) =
if U =/= noModule then
if protecting?(getmodules(Reg),U) == true
then none
else out('Warning: 'tool 'backend 'modules 'may 'not 'be 'submodules 'of 'primary 'module '\n)
fi else st(err) ; out('Error: 'set 'module 'before 'loading 'backends '\n)
fi ; reg(Reg) ; validate(U,D) .
eq validate(U,D ; axs(AX)) =
if form-check(U,'axiom,AX) == nil
then if not sameName(toset(AX))
then axs(AX)
else st(err) ; out('Error: 'axiom 'names 'are 'not 'unique '\n)
fi else st(err) ; out(form-check(U,'axiom,AX))
fi ; validate(U,D) .
eq validate(U,D ; rls(RL)) =
if form-check(U,'rule,trans(RL)) == nil
then if not sameName(RL)
then rls(RL)
else out('Notice: 'rewrite 'theory 'rule 'names 'are 'not 'unique '\n) ; rls(RL)
fi else st(err) ; out(form-check(U,'rule,trans(RL)))
fi ; validate(U,D) [label foo] .
eq validate(U,D ; tst(CT)) =
if form-check(U,'terminating 'state,CT) == nil
then tst(CT)
else st(err) ; out(form-check(U,'terminating 'state,CT))
fi ; validate(U,D) .
--- NB: it would be nice to check that goal numbering is consecutive
--- or at least check in some other way that goal numbering is
--- sane to prevent bad errors from creeping in when we delete
--- generated goals for any reason
eq validate(U,D ; prf(GS)) =
if form-check(U,'goal,getbody(GS)) == nil
then if duplIdGoal?(GS) == false
then if skipQuantifierCheck or-else unsafeVarGoalSet(GS) == mt then prf(GS)
else st(err) ; out('Error: 'some 'goals 'have 'free 'variables 'in 'rhs
'condition: printGoals(U,unsafeVarGoalSet(GS)))
fi else st(err) ; out('Internal 'Error: 'some 'goals 'have 'duplicate 'ids '\n)
fi else st(err) ; out(form-check(U,'goal,getbody(GS)))
fi ; validate(U,D) .
eq validate(U,D ; mod(U')) =
st(err) ; out('Interal 'Error: 'Unexpected 'module 'at 'validation 'time '\n) ;
validate(U,D) .
eq validate(U,D) = D [owise] .
--- OUT: return the set of goals that have unsafe variables
op unsafeVarGoalSet : ProofGoalSet -> ProofGoalSet .
eq unsafeVarGoalSet(G && GS) =
if safeVars(getvars(G),getbody(G)) then mt else G fi &&
unsafeVarGoalSet(GS) .
eq unsafeVarGoalSet(mt) = mt .
--- OUT: return nil iff formulas are well-formed
--- otherwise, return an error list
op form-check : Module QidList LabelReachFormList -> QidList .
eq form-check(U,QL,AX) = form-check(U,QL,trans(toset(AX))) .
op form-check : Module QidList ReachFormSet -> QidList .
eq form-check(U,QL,RFS) =
if U == noModule
then 'Error: 'set 'module 'before 'adding QL '`( 's '`) '\n
else if wellFormed(U,getRuleType(U),RFS)
then nil
else 'Error: QL '`(s`) 'are 'not 'well-formed:
print(U,illFormedGoalSet(U,RFS))
fi fi .
op form-check : Module QidList QFCTermSet -> QidList .
eq form-check(U,QL,CT) =
if U =/= noModule
then if wellFormed(U,getRuleType(U),CT)
then nil
else 'Error: QL '`( 's '`) 'are 'not 'well-defined: print(U,CT)
fi else 'Error: 'set 'module 'before 'adding QL '`( 's '`)
fi .
--- OUT: nil iff module is usable
--- otherwise, return an error message
op mod-check : Module -> QidList .
eq mod-check(U) =
if wellFormed(U)
then if rules-share-kind(U) == true
then if kinds?(true,U) == false
then if abstract-rules(U,abstractRules) :: LabelReachFormSet
then nil
else 'Error: 'Module 'rule 'abstraction 'encountered 'an 'error '\n
fi else 'Error: 'Module 'has 'ill-formed 'or 'kind-valued 'expressions '\n
fi else 'Error: 'Module 'has 'no 'or 'ill-formed 'rules '\n
fi else 'Error: 'Module 'not 'well-formed '\n
fi .
--- PFE: M is head of original goal, F is a new goal generated after applying a rule
--- OUT: checks if implicit quantification was preserved during goal application
--- The first argument is the source goal and the second argument is the generated goals
op quant-check : MaybeReachForm ReachFormSet -> QidList .
eq quant-check(MRF,RFS) =
if (not MRF :: ReachForm) or-else quant-check(antc(MRF),RFS) == mt
then nil
else 'Internal 'Error: 'Quantifier 'Check 'Failed '\n
fi .
op quant-check : QFCTermSet ReachFormSet -> ReachFormSet .
eq quant-check(CT,RF & RFS) = if not intersection(vars(CT),vars(succ(RF))) subset vars(antc(RF)) then RF else mt fi & quant-check(CT,RFS) .
eq quant-check(CT,mt) = mt .
--- OUT: check if two variables (minus type) have the same name
op overlappingVarNames : ReachFormSet -> QidSet .
eq overlappingVarNames(RF & RFS) = overlappingVarNames(vars(RF)) ; overlappingVarNames(RFS) .
eq overlappingVarNames(mt) = none .
endfm
fmod REACH-PROOF-STATE-OPS is
pr REACH-PROOF-STATE-VALIDATION .
var B B' : Bool .
var D D' D'' : ProofMetadata .
var QS QS' : QidSet .
var N N' : Nat .
var Reg Reg' : ScopedRegistry .
var AX AX' : LabelReachFormList .
var RL RL' : LabelLCCRuleSet .
var G : ProofGoal .
var MG : MaybeProofGoal .
var GS GS' : ProofGoalSet .
var PS PS' : ProofStatus .
var EXPS : ExceptionalStatus .
var CT CT' : QFCTermSet .
var QL QL' : QidList .
var NQL : NeQidList .
var U U' : Module .
var AH AH' : Map{Nat,AxiomRecord} .
var Q Q' : Qid .
--- OUT: empty proof metadata
op emptyData : -> ProofMetadata .
eq emptyData = mod(noModule) ;
dcl(none) ;
reg(empty) ;
cnt(0) ;
gn(1) ;
axs(nil) ;
rls(empty) ;
tst(noterm) ;
prf(mt) ;
his(empty) ;
out(nil) ;
st(noStatus) .
--- OUT: get specified attribute
op get-mod : ProofMetadata ~> Module .
op get-dcl : ProofMetadata ~> QidSet .
op get-reg : ProofMetadata ~> ScopedRegistry .
op get-cnt : ProofMetadata ~> Nat .
op get-gn : ProofMetadata ~> Nat .
op get-axs : ProofMetadata ~> LabelReachFormList .
op get-rls : ProofMetadata ~> LabelLCCRuleSet .
op get-tst : ProofMetadata ~> QFCTermSet .
op get-prf : ProofMetadata ~> ProofGoalSet .
op get-his : ProofMetadata ~> Map{Nat,AxiomRecord} .
op get-out : ProofMetadata ~> QidList .
op get-st : ProofMetadata ~> ProofStatus .
op get-err : ProofMetadata ~> Bool .
eq get-mod(mod(U) ; D) = U .
eq get-dcl(dcl(QS) ; D) = QS .
eq get-reg(reg(Reg) ; D) = Reg .
eq get-cnt(cnt(N) ; D) = N .
eq get-gn (gn(N) ; D) = N .
eq get-axs(axs(AX) ; D) = AX .
eq get-rls(rls(RL) ; D) = RL .
eq get-tst(tst(CT) ; D) = CT .
eq get-prf(prf(GS) ; D) = GS .
eq get-his(his(AH) ; D) = AH .
eq get-out(out(QL) ; D) = QL .
eq get-out( D) = nil [owise] .
eq get-st (st(PS) ; D) = PS .
eq get-err(st(err PS) ; D) = true .
eq get-err( D) = false [owise] .
--- OUT: get special attributes
op getModByImpl : ProofMetadata Qid -> Module .
eq getModByImpl(reg(Reg) ; D,Q) = getModByImpl(Q,Reg) .
eq getModByImpl(D,Q) = noModule [owise] .
op getgl! : ProofMetadata Nat ~> ProofGoal .
eq getgl!(D,N) = getgl!(get-prf(D),N) .
--- OUT: true iff the metadata has a duplicated item
op duplMetadata? : ProofMetadata ~> Bool .
eq duplMetadata?(mod(U) ; mod(U') ; D) = true .
eq duplMetadata?(reg(Reg) ; reg(Reg') ; D) = true .
eq duplMetadata?(dcl(QS) ; dcl(QS') ; D) = true .
eq duplMetadata?(cnt(N) ; cnt(N') ; D) = true .
eq duplMetadata?(gn(N) ; gn(N') ; D) = true .
eq duplMetadata?(axs(AX) ; axs(AX') ; D) = true .
eq duplMetadata?(rls(RL) ; rls(RL') ; D) = true .
eq duplMetadata?(tst(CT) ; tst(CT') ; D) = true .
eq duplMetadata?(prf(GS) ; prf(GS') ; D) = true .
eq duplMetadata?(his(AH) ; his(AH') ; D) = true .
eq duplMetadata?(out(QL) ; out(QL') ; D) = true .
eq duplMetadata?(st(PS) ; st(PS') ; D) = true .
eq duplMetadata?(D) = false [owise] .