-
Notifications
You must be signed in to change notification settings - Fork 2
/
full-maude-removeids.maude
21199 lines (18701 loc) · 863 KB
/
full-maude-removeids.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
---- To be run on Maude 2.7 (alpha 106)
---- author: Francisco Duran
---- printSyntaxError functionality by Peter Olveczky
---- narrowing search by Santiago Escobar
set show loop stats off .
set show loop timing off .
set show advisories off .
fmod BANNER is
pr STRING .
op banner : -> String .
eq banner = "Full Maude 2.7 March 10th 2015" .
endfm
***(
This file is part of the Maude 2 interpreter.
Copyright 1997-2003 SRI International, Menlo Park, CA 94025, USA.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 inclof the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNSS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public Leicense
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
)
---- to do:
---- - continue .
---- - show search graph .
---- - show path <number> .
---- - show path labels <number> .
---- - show components .
---- Main changes and bugs fixed:
----
---- - May 17th, 2016
---- - Changed all functions that play with variants to use the new syntax
---- - Feb 4th, 2016
---- - The MOD-EXPRS module is renamed to FM-MOD-EXPRS, and a MOD-EXPRS is later
---- introduced. Now, new module expressions can be used anywhere by redefining
---- this new MOD-EXPRS module. Although FM could be extended to handle new
---- module expressions, these were not supported inside "in" sections of
---- commands.
---- - Oct 19th, 2015
---- - bug in the search command on OO modules (reported by Pete Olveczky)
---- - Oct 12th, 2015
---- - iter supported by built-in unification, checks adjusted accordingly
---- - Feb 18th, 2015
---- - An operator <_[,_]*> was added to the modules for narrowing. It has been
---- renamed as @<@_[,_]*@>@ to avoid clashes with user-defined operators.
---- - acu coherence completion has been renamed to ax coherence completion.
---- This applies to the acu coherence completion [<module-name>] ., to the
---- metalevel operation axCohComplete and to the module AX-COHERENCE-COMPLETION.
---- The completion was already performed for the different combinations of
---- attributes, but the name was the original one.
---- - Nov 12th, 2014
---- - Classes without attributes may be defined as class Foo . or class Foo | .
---- Requested by A. Riesco.
---- - Parameter sorts used in sort constraints were not appropriately instantiated.
---- Reported by A. Riesco.
---- - July 14th, 2014
---- - Fixed bug in the parsing of terms with operators '=' or '=>'. Although the first-level
---- parsing was done correctly, to solve bubbles an operator = (resp. =>) was introduced
---- to handle equations (resp. rules). Reported by Adrian Riesco.
---- - Fixed bug on the pretty printing of views. Typical error on structures with id elements.
---- Probably due to changes in the definion of map sets. Reported by Adrian Riesco.
---- - September 12th, 2013
---- - Bug in ACU completion when handling modules with explicit use of kinds. Reported
---- by Luis Aguirre
---- - December 12th, 2013
---- - Bug in the renaming of operators with explicit arity where parameterized sorts
---- are used.
---- - Bug in the renaming of ac operators fixed. Given an acu operator __, a term
---- card(E E S, C) was not renamed.
---- - July 24th, 2012
---- - commands remove ids and remove non-handled ids available
---- - July 7th, 2012
---- - A bug in the removal of identity attributes has been fixed. A metadata("variant")
---- was expected in all equations to be used to generate the variants. To be consistent
---- to the new built-in getVariants function I'm using the attribute variant instead
---- of the metadata.
---- - March 20th, 2012
---- - Core Maude views are now accessible from Full Maude. Full Maude do not require
---- explicit sort maps any more.
---- - The set of more general eqs and rls (moreGeneralEqs and moreGeneralRls ops)
---- is now correctly calculated. These functions are used in several places, for
---- example, in the functions and commands to eliminate identity attributes and in
---- the completion procedures.
---- Reported by Santiago Escobar.
---- - October 24th, 2011
---- - format attribute was not correctly handled. Equation missing in the downAttr op.
---- - July 13th, 2011
---- - A bug on the load metamodule command making it fail when loading a metamodule
---- with a metadata attribute has been fixed.
---- Reported by Tobias Muhlbauer and Jonas Eckhardt.
---- - December 5th, 2009
---- - New command (remove id attributes [<module-expr.>] .) that shows the
---- module with the id attributes removed using variants.
---- - New command (remove assoc attributes [<module-expr.>] .) that shows the
---- module with the assoc (if not with comm) attributes removed using variants.
---- - November 22nd, 2009
---- - A new version of the narrowing/unification stuff by S. Escobar fixing a bug in the
---- getVariants function and incorporating some other changes.
---- To integrate it into Full Maude:
---- - The TERMSET module is moved, so that now Full Maude uses it instead of its
---- definition of term sets. In the original module by Santiago this module imported
---- the SUBSTITUTION-HANDLING module; this importation is now commented out.
---- - October 4th, 2009
---- - New (acu coherence completion .) / (acu coherence completion <Module> .) command.
---- It shows result of completing the flatten version of the module for acu coherence.
---- - Setember 11th, 2009
---- - sort Set<List<Type>> replaced by the TypeListSet sort from META-MODULE
---- - sort List<Set<Type>> renamed as TypeSetList
---- - MAYBE removed, DEFAULT-VALUE used instead. MAYBE{TERM} replaced by DEFAULT-VALUE{Term}
---- - July 28th, 2009
---- - Some cleaning up. Some of the changes may break other applications.
---- - April 18th, 2009
---- - The metadata attribute is now available for operation declarations. Reported by A. Riesco.
---- - Fixed bug in the handling of ditto. ctor and metadata attributes were copied.
---- - March 9th, 2009
---- - Bug in the search command. The number of solutions argument was used as depth bound. Reported by P. Olveczky.
---- - New (remove id attributes .) / (remove id attributes <Module> .) command
---- It shows an equivalent version of the flatten module without ids using variants.
---- - March 9th, 2009
---- - Bug in the handling of mbs/cmbs. Sorts in bubbles were not handled correctly. Reported by T. Serbanuta.
---- - February 12th, 2009
---- - The summation module expression now generates a module
---- fmod A + B + C is
---- inc A .
---- inc B .
---- inc C .
---- endfm
---- for a module expression A + B + C.
---- - February 6th, 2009
---- - Fixed a bug in the id-unify command. Fixed by Santiago Escobar
---- - February 3rd, 2009
---- - Missing equation for downAttr, for the case of nonexec
---- - Missing declaration in the CONFIGURATION+ module to handle class declarations with no attributes
---- - January 29th, 2009
---- - The downModule operation has been extended to be able to handle oo metamodules.
---- Note that omod metamodules are defined in the UNIT Full Maude module. Therefore,
---- to be able to do things like
---- (load omod ... endm .)
---- the current module must be the FM UNIT module or one extending it.
---- - January 28th, 2009
---- - A bug in downAttr. Found thanks to a problem with metamodule load. Reported by Peter Olveczky.
---- - January 8th, 2009
---- - A bug in the narrowing functionality. It was narrowing on frozen positions.
---- (fixed by Santiago Escobar)
---- - December 20th, 2008
---- - Fixed a bug in the handling of the such-that part of search commands.
---- Reported by Enrique Martin.
---- - December 17th, 2008
---- - A new search_~>_ family of commands (as for search_=>_) is now available.
---- The commands are implemented by Santiago Escobar.
---- - December 8th, 2008
---- - A new meta-module load command is available.
---- It enters a metamodule into Full Maude's database of modules.
---- Asked by Peter Olveczky and Jose Meseguer.
---- The syntax for the new command is (load <meta-module> .), where <meta-module is any term of sort
---- Module, either a term of the form fmod...endfm or any other expression reducing to a module.
---- Thus, you can write things like
----
---- (select META-LEVEL .)
----
---- (load fmod 'FOO is
---- including 'BOOL .
---- sorts 'Foo .
---- none
---- op 'f : nil -> 'Foo [none] .
---- op 'g : nil -> 'Foo [none] .
---- none
---- eq 'f.Foo = 'g.Foo [none] .
---- endfm .)
----
---- or
----
---- (load upModule('NAT, true) .)
----
---- - September 18th, 2008
---- The search command now supports its complete generality (maximum depth couln't be given). Bug reported by Zhang Min.
---- The unify command is now supported.
---- Bug in the renaming of partial operations fixed. Reported by Edu Rivera.
---- - April 2nd, 2008
---- Bug in the application of views (and renamings) with kinds in the specification
---- of op renamings. It appears in an example in which the sort was coming from a theory.
---- Reported by A. Boronat.
---- - March 24th, 2008
---- Bug in the application of renamings to op hooks. Reported by A. Boronat
---- - March 17th, 2008
---- Bug in the instantiation of parameterized sorts in sort memberships.
---- Reported by A. Boronat
---- - March 14th, 2008
---- Bug in the handling of parameterized module expressions. When the parameterers
---- are not right, the system hangs. Reported by A. Verdejo.
---- - March 9th, 2008
---- Statement attributes of membership axioms were not correctly handled.
---- Reported by A. Riesco & A. Verdejo
---- - Feb 18th, 2008
---- Bug in the renaming of operators
---- - Feb 14th, 2008
---- Statement attributes of membership axioms were not correctly handled.
---- Reported by A. Riesco & A. Verdejo
---- - Dec 17th, 2007
---- Rule in CONFIGURATION+ was causing non-termination
---- - Dec 13th, 2007
---- Change in the specification of the transform function to allow new types of modules
---- - Nov 23rd, 2007
---- Bug in the evaluation of expressions in commands (red in FOO + BAR : ...)
---- - Oct 5th, 2007
---- Bug in down of modules (reported by Pedro Ojeda)
---- - July 31st, 2007
---- bug in the application of maps to terms
---- - July 31st, 2007
---- bug in getThClasses
---- (reported by Marisol)
---- - (october 17th, 2006)
---- Changes in Alpha88a's prelude are now correctly handled
---- - (july 22nd, 2006)
---- Bug in the meta-pretty-print of types.
---- - (july 21st, 2006)
---- Object-oriented messages where not given the attribute msg
---- (from a comment by Peter).
---- - (reported by Radestock)
---- getSort was not handling parameterized sorts appropriately.
---- - the set protect/extend/include off commands didn't work if the
---- module not importing was not among the imported ones
----
---- Last changes:
----
---- - May 21st, 2007
---- GRAMMAR now extends a module BUBBLES with all bubble delcarations.
---- This BUBBLES module is also used to define the GRAMMAR-RED, GRAMMAR-REW, ...
---- modules.
----
---- - May 19th, 2007
---- procCommand changed. It now returns a Tuple{Database, QidList} instead of
---- just a QidList. Since some modules may need to be compiled for the
---- execution of a command, the resulting database is returned and used as
---- new database.
----
---- - May 19th, 2007
---- proRew takes now one argument less. The Bound (4th arg.) was unnecessary.
----
---- - BOOL is included, instead of protected, into any entered module.
----
---- - A new module expression POWER[n] is now available. A module expression
---- POWER[n]{Nat} produces a module
----
---- fmod POWER[n]{X :: TRIV} is
---- inc TUPLE[n]{X, X, ..., X} .
---- endfm
----
---- which is then instantiated by the Nat view.
---- - (July 18th, 2006)
---- The summation module expression now generates a module
---- that includes (instead of protect) its summands.
----
---- - All sorts declared in modules used for parsing have been renamed.
---- Any sort S in one of these modules is nos called @S@.
---- Since some of these modules where added to the user defined modules
---- for dealing with ups, conditions, etc., he was getting error when
---- using sorts like Token or OpDecl in his specs.
----
---- - Syntax for parameterization has been changed (again) !!! :
---- - module definition: FOO{X :: TRIV, Y :: TRIV}
---- - module instantiation: FOO{Bar,Baz}
---- - parameterized sorts: Foo{Bar,Baz}
----
---- - Any module loaded in Core Maude can be used in Full Maude.
---- This may be particularly useful in the case of using the model checker.
----
---- (mod CHECK-RESP is
---- protecting MODEL-CHECKER .
---- ...
---- endm)
----
---- (red p(0) |= (<> Qstate) .)
----
---- - Module renaming and summation consistent with Core Maude's. Built-ins
---- are now handled at the metalevel, instead of leaving the inclusions to
---- Core Maude. In this way, they can be renamed and redefined, as in
---- Core Maude. This makes Full Maude slower.
----
---- - The lazy evaluation of modules is working. When a module is redefined
---- its dependent modules are removed only if generated internally. Those
---- introduced by the user save their term representation, from which the
---- whole processing can take place. They will be recompiled by need.
----
---- - The form of qualifying sorts coming from the parameters in
---- parameterized modules has changed AGAIN: The sort Elt coming from
---- X :: TRIV is now written as X$Elt (Note that sort names cannot contain
---- dots anymore).
----
---- - Tuples are built with the syntax
---- TUPLE[size]{comma_separated_list_of_views}
---- For example, given a view Nat from TRIV to NAT we can define pairs of
---- nats with TUPLE[2]{Nat, Nat}.
----
---- - The model-checker is loaded before the full maude modules, so that
---- it can be used.
----
---- - Object-oriented modules include a module CONFIGURATION+, which
---- imports CONFIGURATION, defines a function
---- op class : Object -> Cid .
---- returning the actual class of the given object, and add syntax
---- for objects with no attributes <_:_| >. Classes without attributes
---- are defined with syntax class CLASS-NAME .
----
---- Things to come:
----
---- - Commands missing: continue ...
----
---- - On parameterized theories and views: linked parameters, composed and
---- lifted views, and default views.
----
---- - ops names in op declarations
----
---- known bugs:
----
---- - error messages could be given in down commands
----
---- - Check: perhaps we need to convert constants back into vbles in
---- procViewAux
----
---- - Parameterized sorts don't work in sort constraints (nor by themselves,
---- nor in the conditions of axioms. They are accepted in their equivalent
---- single token form but do not get instantiated
---- cmb (A, B) S : PFun(X, Y) if not(A in dom(S)) /\ S : PFun`(X`,Y`) .
----
set include BOOL off .
set include TRUTH-VALUE on .
set show advisories off .
mod CONFIGURATION is
sorts Attribute AttributeSet .
subsort Attribute < AttributeSet .
op none : -> AttributeSet [ctor] .
op _,_ : AttributeSet AttributeSet -> AttributeSet [ctor assoc comm id: none] .
sorts Oid Cid Object Msg Portal Configuration .
subsort Object Msg Portal < Configuration .
op <_:_|_> : Oid Cid AttributeSet -> Object [ctor object] .
op none : -> Configuration [ctor] .
op __ : Configuration Configuration -> Configuration [ctor config assoc comm id: none] .
op <> : -> Portal [ctor] .
endm
mod CONFIGURATION+ is
including CONFIGURATION .
op <_:_|`> : Oid Cid -> Object .
op class : Object -> Cid .
---- eq < O:Oid : C:Cid | > = < O:Oid : C:Cid | none > .
eq class(< O:Oid : C:Cid | A:AttributeSet >) = C:Cid .
endm
set include BOOL on .
set include TRUTH-VALUE off .
*******************************************************************************
*******************************************************************************
***
*** Narrowing and Equational Unification
*** by Santiago Escobar
***
fmod META-LEVEL-MNPA is
pr META-LEVEL * (op `{_`,_`} : Term Nat -> SmtResult to `{_`,_`}Smt ) .
endfm
fmod UNIFICATIONTRIPLE is
protecting META-LEVEL-MNPA .
protecting INT .
--- UnificationPair --------------------------------------------
---sorts UnificationPair UnificationPair? .
---op {_,_} : Substitution Nat -> UnificationPair [ctor] .
---subsort UnificationPair < UnificationPair? .
---op noUnifier : -> UnificationPair? [ctor] .
op getSubst : UnificationPair -> Substitution .
eq getSubst({S1:Substitution, N:Nat}) = S1:Substitution .
op getNextVar : UnificationPair -> Nat .
eq getNextVar({S1:Substitution, N:Nat}) = N:Nat .
--- UnificationTriple --------------------------------------------
---sorts UnificationTriple UnificationTriple? .
---op {_,_,_} : Substitution Substitution Nat -> UnificationTriple [ctor] .
---subsort UnificationTriple < UnificationTriple? .
---op noUnifier : -> UnificationTriple? [ctor] .
op getLSubst : UnificationTriple -> Substitution .
eq getLSubst({S1:Substitution, S2:Substitution, N:Nat}) = S1:Substitution .
op getRSubst : UnificationTriple -> Substitution .
eq getRSubst({S1:Substitution, S2:Substitution, N:Nat}) = S2:Substitution .
op getNextVar : UnificationTriple -> Nat .
eq getNextVar({S1:Substitution, S2:Substitution, N:Nat}) = N:Nat .
endfm
fmod TERM-HANDLING is
protecting META-TERM .
protecting META-LEVEL-MNPA .
protecting EXT-BOOL . *** For and-then
var T T' T'' : Term .
var C C' : Constant .
var QIL : QidList .
var N N' : Nat .
var NL NL' : NatList .
var Q F F' : Qid .
var AtS : AttrSet .
var EqS : EquationSet .
var Eq : Equation .
var Cond : Condition .
var TP : Type .
var TPL TPL' : TypeList .
var TL TL' TL'' : TermList .
var B : Bool .
var V V' : Variable .
var Ct : Context .
var CtL : NeCTermList .
var NeTL : NeTermList .
var M : Module .
*** root ******************************
op root : Term -> Qid .
eq root(V) = V .
eq root(C) = C .
eq root(F[TL]) = F .
*** size ******************************
op size : TermList -> Nat .
eq size(empty) = 0 .
eq size((T,TL)) = s(size(TL)) .
*** elem_of_ *****************************************************
op elem_of_ : Nat TermList ~> Term .
eq elem 1 of (T,TL) = T .
eq elem s(s(N)) of (T,TL) = elem s(N) of TL .
*** subTerm_of_ *****************************************************
op subTerm_of_ : NatList Term ~> Term .
eq subTerm NL of T = subTerm* NL of T .
op subTerm*_of_ : NatList Term ~> Term .
eq subTerm* nil of T = T .
eq subTerm* N NL of (F[TL]) = subTerm* NL of (elem N of TL) .
*** ToDo: UPGRADE THIS NOTION TO MODULO AC *********************
*** is_subTermOf_ *****************************************************
op is_subTermOf_ : Term TermList -> Bool .
eq is T subTermOf (T',NeTL) = is T subTermOf T'
or-else is T subTermOf NeTL .
eq is T subTermOf T = true .
eq is T subTermOf T' = is T subTermOf* T' [owise] .
op is_subTermOf*_ : Term TermList -> Bool .
eq is T subTermOf* (F[TL]) = is T subTermOf TL .
eq is T subTermOf* T' = false [owise] .
*** noVarOfSort_In_ *****************************************************
op noVarOfSort_In_ : Type TermList -> Bool .
eq noVarOfSort T:Type In V = getType(V) =/= T:Type .
eq noVarOfSort T:Type In (F[TL]) = noVarOfSort T:Type In TL .
eq noVarOfSort T:Type In (T',NeTL)
= noVarOfSort T:Type In T' and noVarOfSort T:Type In NeTL .
eq noVarOfSort T:Type In X:TermList = true [owise] .
*** findSubTermOf_In_ ***********************************************
op findSubTermOf_In_ : NeCTermList TermList ~> Term .
eq findSubTermOf (TL, [], TL') In (TL, T, TL') = T .
eq findSubTermOf (TL, F[CtL], TL'') In (TL, F[TL'], TL'')
= findSubTermOf CtL In TL' .
*** replaceElem_of_by_ ****************************************************
op replaceElem_of_by_ : Nat TermList Term ~> TermList .
eq replaceElem 1 of (T,TL) by T' = (T',TL) .
eq replaceElem s(s(N)) of (T,TL) by T' = (T,replaceElem s(N) of TL by T') .
*** replaceSubTerm_of_by_ *************************************************
op replaceSubTerm_of_by_ : NatList TermList Term ~> TermList .
eq replaceSubTerm nil of T by T' = T' .
eq replaceSubTerm N NL of (F[TL]) by T'
= F[replaceSubTermL N NL of TL by T'] .
op replaceSubTermL_of_by_ : NatList TermList Term ~> TermList .
eq replaceSubTermL 1 NL of (T,TL) by T'
= (replaceSubTerm NL of T by T', TL) .
eq replaceSubTermL s(s(N)) NL of (T,TL) by T'
= (T,replaceSubTermL s(N) NL of TL by T') .
op replaceTerm_by_in_ : Term Term TermList ~> TermList .
eq replaceTerm T by T' in T = T' .
eq replaceTerm T by T' in (F[TL]) = F[replaceTerm T by T' in TL] .
eq replaceTerm T by T' in T'' = T'' [owise] .
eq replaceTerm T by T' in (T'',NeTL)
= (replaceTerm T by T' in T'',replaceTerm T by T' in NeTL) .
*** context replacement **************************************************
op _[_] : Context Context -> Context .
op _[_] : NeCTermList Context -> NeCTermList .
eq [] [ Ct ] = Ct .
eq (F[CtL])[ Ct ] = F[ CtL [ Ct ] ] .
eq (CtL,NeTL) [Ct] = (CtL [Ct] ), NeTL .
eq (NeTL,CtL) [Ct] = NeTL, (CtL [Ct] ) .
op _[_] : Context Term -> Term .
op _[_] : NeCTermList Term -> TermList .
eq [] [ T ] = T .
eq (F[CtL])[ T ] = F[ CtL [ T ] ] .
eq (CtL,NeTL) [T] = (CtL [T] ), NeTL .
eq (NeTL,CtL) [T] = NeTL, (CtL [T] ) .
*** is_substring_ *****************************************
op is_substring_ : Qid Qid -> Bool [memo] .
eq is F:Qid substring F':Qid
= rfind(string(F':Qid), string(F:Qid), length(string(F':Qid))) =/= notFound .
*** addprefix_To_ addsufix_To_ *****************************************
op addprefix_To_ : Qid Variable -> Variable [memo] .
eq addprefix Q To V
= qid(string(Q) + string(getName(V)) + ":" + string(getType(V))) .
op addprefix_To_ : Qid Constant -> Constant [ditto] .
eq addprefix Q To F
= if noUnderBar(F) and getName(F) :: Qid then
if getType(F) :: Type then
qid(string(Q) + string(getName(F)) + "." + string(getType(F)))
else
qid(string(Q) + string(getName(F)))
fi
else
qid(string(Q) + string(F))
fi .
op addsufix_To_ : Qid Variable -> Variable [memo] .
eq addsufix Q To V
= qid(string(getName(V)) + string(Q) + ":" + string(getType(V))) .
op addsufix_To_ : Qid Constant -> Constant [ditto] .
eq addsufix Q To F
= if noUnderBar(F) and getName(F) :: Qid then
if getType(F) :: Type then
qid(string(getName(F)) + string(Q) + "." + string(getType(F)))
else
qid(string(getName(F)) + string(Q))
fi
else
qid(string(F) + string(Q))
fi .
op addType_ToVar_ : Type Qid -> Variable [memo] .
eq addType TP:Qid ToVar V:Qid
= qid(string(V:Qid) + ":" + string(TP:Qid)) .
*** noUnderBar (auxiliary) ****************************
op noUnderBar : Qid -> Bool .
eq noUnderBar(F)
= rfind(string(F), "_", length(string(F))) == notFound .
*** addType ******************************
op addType : Qid Type -> Qid .
eq addType(F,TP)
= if noUnderBar(F) and getName(F) :: Qid then
qid( string(getName(F)) + "." + string(TP) )
else
qid( string(F) + "." + string(TP) )
fi .
*** addTypeVar ******************************
op addTypeVar : Qid Type -> Qid .
eq addTypeVar(F,TP)
= qid( string(F) + ":" + string(TP) ) .
endfm
fmod SUBSTITUTION-HANDLING is
protecting META-TERM .
protecting META-LEVEL-MNPA .
protecting TERM-HANDLING .
var S S' Subst Subst' : Substitution .
var V V' : Variable .
var C C' : Constant .
var Ct : Context .
var T T' T1 T2 T1' T2' T1'' T2'' : Term .
var F F' : Qid .
var TL TL' TL1 TL2 TL1' TL2' : TermList .
var Att : AttrSet .
var RLS : RuleSet .
var Rl : Rule .
var TP : Type .
var N : Nat .
var NeTL : NeTermList .
var CtL : NeCTermList .
--- Apply Substitution to Term --------------------------------------------
op _<<_ : Term Substitution -> Term .
eq TL << none = TL .
eq C << Subst = C .
eq V << ((V <- T) ; Subst) = T .
eq V << Subst = V [owise] .
eq F[TL] << Subst = F[TL << Subst] .
op _<<_ : TermList Substitution -> TermList .
eq (T, NeTL) << Subst = (T << Subst, NeTL << Subst) .
eq empty << Subst = empty .
op _<<_ : Context Substitution -> Context .
eq Ct << none = Ct .
eq [] << Subst = [] .
eq F[CtL,NeTL] << Subst = F[CtL << Subst,NeTL << Subst] .
eq F[NeTL,CtL] << Subst = F[NeTL << Subst, CtL << Subst] .
eq F[Ct] << Subst = F[Ct << Subst] .
op _<<_ : Substitution Substitution -> Substitution .
eq S << (none).Substitution = S .
eq (none).Substitution << S = (none).Substitution .
eq ((V' <- T) ; S') << S
= (V' <- (T << S))
;
(S' << S) .
--- Combine Substitutions -------------------------------------------------
op _.._ : Substitution Substitution -> Substitution .
eq S .. S' = (S << S') ; S' .
--- Restrict Assignments to Variables in a Term ----------------------
op _|>_ : Substitution TermList -> Substitution .
eq Subst |> TL = Subst |>* Vars(TL) .
op _|>*_ : Substitution TermList -> Substitution .
--- eq noMatch |>* TL = noMatch .
eq Subst |>* TL = Subst |>** TL [none] .
op _|>**_[_] : Substitution TermList
Substitution -> Substitution .
eq none |>** TL [Subst']
= Subst' .
eq ((V <- V) ; Subst) |>** TL [Subst']
= Subst |>** TL [Subst'] .
eq ((V <- T') ; Subst) |>** TL [Subst']
= Subst |>** TL
[Subst' ; if any V in TL then (V <- T') else none fi] .
--- Remove Variables from list ----------------------
op _intersect_ : TermList TermList -> TermList .
eq (TL1,T,TL2) intersect (TL1',T,TL2')
= (T,((TL1,TL2) intersect (TL1',TL2'))) .
eq TL intersect TL' = empty [owise] .
op _intersectVar_ : TermList TermList -> TermList .
eq TL1 intersectVar TL2
= TL1 intersectVar* Vars(TL2) .
op _intersectVar*_ : TermList TermList -> TermList .
eq (T,TL1) intersectVar* TL2
= (if any Vars(T) in TL2 then T else empty fi,TL1 intersectVar* TL2) .
eq empty intersectVar* TL2
= empty .
--- Remove Variables from list ----------------------
op _setMinus_ : TermList TermList -> TermList .
eq (TL1,T,TL2) setMinus (TL1',T,TL2')
= (TL1,TL2) setMinus (TL1',T,TL2') .
eq TL setMinus TL' = TL [owise] .
--- Variables ---
op Vars : GTermList -> TermList .
eq Vars((T,TL:GTermList)) = VarsTerm(T),Vars(TL:GTermList) .
eq Vars((Ct,TL:GTermList)) = VarsTerm(Ct),Vars(TL:GTermList) .
eq Vars(empty) = empty .
op VarsTerm : Term -> TermList . ---warning memo
eq VarsTerm(V) = V .
eq VarsTerm(F[TL:TermList]) = Vars(TL:TermList) .
eq VarsTerm(C) = empty .
op VarsTerm : Context -> TermList . ---warning memo
eq VarsTerm(F[TL:GTermList]) = Vars(TL:GTermList) .
--- membership ---
op _in_ : Term TermList -> Bool .
eq T in (TL,T,TL') = true .
eq T in TL = false [owise] .
--- membership ---
op any_in_ : TermList TermList -> Bool . --- [memo] .
eq any empty in TL = false .
eq any (TL1,T,TL2) in (TL1',T,TL2') = true .
eq any TL in TL' = false [owise] .
--- membership ---
op all_in_ : TermList TermList -> Bool . --- [memo] .
eq all empty in TL = true .
eq all (TL1,T,TL2) in (TL1',T,TL2') = all (TL1,TL2) in (TL1',T,TL2') .
eq all TL in TL' = false [owise] .
--- Occur check ---
op allVars_inVars_ : GTermList GTermList -> Bool .
eq allVars TL:GTermList inVars TL':GTermList
= all Vars(TL:GTermList) in Vars(TL':GTermList) .
op anyVars_inVars_ : GTermList GTermList -> Bool .
eq anyVars TL:GTermList inVars TL':GTermList
= any Vars(TL:GTermList) in Vars(TL':GTermList) .
op rangeVars : Substitution -> TermList .
eq rangeVars(V <- T ; Subst) = (Vars(T),rangeVars(Subst)) .
eq rangeVars(none) = empty .
op dom_inVars_ : Substitution TermList -> Bool .
eq dom Subst inVars TL = dom Subst in Vars(TL) .
op dom_in_ : Substitution TermList -> Bool .
eq dom (V <- T ; Subst) in (TL1,V,TL2) = true .
eq dom Subst in TL = false [owise] .
op dom_notInVars_ : Substitution TermList -> Bool .
eq dom Subst notInVars TL = dom Subst notIn Vars(TL) .
op dom_notIn_ : Substitution TermList -> Bool .
eq dom none notIn TL = true .
ceq dom (V <- T ; Subst) notIn TL = true if not (V in TL) .
eq dom Subst notIn TL = false [owise] .
op range_inVars_ : Substitution TermList -> Bool .
eq range Subst inVars TL = range Subst in Vars(TL) .
op range_in_ : Substitution TermList -> Bool .
eq range (V <- T ; Subst) in TL
= any Vars(T) in TL or-else range Subst in TL .
eq range none in TL
= false .
op valid-occur-check? : Substitution -> Bool .
eq valid-occur-check?(Subst)
= not (dom Subst inVars (rangeVars(Subst))) .
op extract-bindings : Substitution -> TermList .
eq extract-bindings(none) = empty .
eq extract-bindings(V <- T ; Subst) = (T,extract-bindings(Subst)) .
endfm
fmod TERMSET is
protecting META-LEVEL-MNPA .
protecting SUBSTITUTION-HANDLING .
sort TermSet .
subsort Term < TermSet .
op emptyTermSet : -> TermSet [ctor] .
op _|_ : TermSet TermSet -> TermSet
[ctor assoc comm id: emptyTermSet format (d n d d)] .
eq X:Term | X:Term = X:Term .
op _in_ : Term TermSet -> Bool .
eq T:Term in (T:Term | TS:TermSet) = true .
eq T:Term in TS:TermSet = false [owise] .
op TermSet : TermList -> TermSet .
eq TermSet(empty)
= emptyTermSet .
eq TermSet((T:Term,TL:TermList))
= T:Term | TermSet(TL:TermList) .
endfm
fmod RENAMING is
protecting META-TERM .
protecting META-LEVEL-MNPA .
protecting TERM-HANDLING .
protecting SUBSTITUTION-HANDLING .
protecting TERMSET .
protecting CONVERSION .
protecting QID .
protecting INT .
protecting UNIFICATIONTRIPLE .
var S S' Subst Subst' : Substitution .
var V V' : Variable .
var C C' : Constant .
var CtL : NeCTermList .
var Ct : Context .
var T T' T1 T2 T1' T2' T1'' T2'' : Term .
var F F' : Qid .
var TL TL' TL'' TL''' : TermList .
var Att : AttrSet .
var RLS : RuleSet .
var Rl : Rule .
var TP : Type .
var N N' : Nat .
var NeTL : NeTermList .
var Q Q' : Qid .
var IL : ImportList .
var SS : SortSet .
var SSDS : SubsortDeclSet .
var OPDS : OpDeclSet .
var MAS : MembAxSet .
var EQS : EquationSet .
var TPL : TypeList .
--- Extra filter for substitutions ------
op _|>_ : Substitution Nat -> Substitution .
eq Subst |> N
= Subst |>* N [none] .
op _|>*_[_] : Substitution Nat Substitution -> Substitution .
eq none |>* N [Subst']
= Subst' .
eq ((V <- T') ; Subst) |>* N [Subst']
= Subst |>* N
[Subst' ; if highestVar(V) < N then (V <- T') else none fi ] .
--- instantiatesAbove -----------------------------------
op _instantiatesAbove_ : Substitution Nat -> Bool .
eq none instantiatesAbove N = false .
eq ((V <- T') ; Subst) instantiatesAbove N
= highestVar(V) >= N
or-else
Subst instantiatesAbove N .
----------------------------------------------
--- New Renaming Utilities -------------------
op highestVar : GTermList -> Nat .
eq highestVar(TL:GTermList)
= highestVar(TL:GTermList,0) .
op highestVarTerm : Term -> Nat . ---warning memo
op highestVarTerm : Context -> Nat . ---warning memo
eq highestVarTerm([]) = 0 .
eq highestVarTerm(C) = 0 .
eq highestVarTerm(V)
= if rfind(string(V), "#", length(string(V))) =/= notFound
and
rfind(string(V), ":", length(string(V))) =/= notFound
and
rat(substr(string(V),
rfind(string(V), "#", length(string(V))) + 1,
rfind(string(V), ":", length(string(V))) + (- 1))
,10)
:: Nat
then rat(substr(string(V),
rfind(string(V), "#", length(string(V))) + 1,
rfind(string(V), ":", length(string(V))) + (- 1))
,10)
else
if rfind(string(V), "%", length(string(V))) =/= notFound
and
rfind(string(V), ":", length(string(V))) =/= notFound
and
rat(substr(string(V),
rfind(string(V), "%", length(string(V))) + 1,
rfind(string(V), ":", length(string(V))) + (- 1))
,10)
:: Nat
then rat(substr(string(V),
rfind(string(V), "%", length(string(V))) + 1,
rfind(string(V), ":", length(string(V))) + (- 1))
,10)
else 0
fi
fi .
eq highestVarTerm(F[TL:GTermList])
= highestVar(TL:GTermList,0) .
op highestVar : GTermList Nat -> Nat .
eq highestVar(empty,N)
= N .
eq highestVar((Ct,TL:GTermList),N)
= highestVar(TL:GTermList,
if highestVarTerm(Ct) > N then highestVarTerm(Ct) else N fi
) .
eq highestVar((T,TL:GTermList),N)
= highestVar(TL:GTermList,
if highestVarTerm(T) > N then highestVarTerm(T) else N fi
) .
--- For substitutions
op highestVar : Substitution -> Nat . --- [memo] .
eq highestVar(Subst)
= highestVar(Subst,0) .
op highestVar : Substitution Nat -> Nat .
eq highestVar((none).Substitution,N) = N .
eq highestVar(V <- T ; Subst,N)
= highestVar(Subst,highestVar((T,V),N)) .
--- Renaming ------------------------------------------------------
op newVar : Nat TypeList -> TermList .
eq newVar(N,nil) = empty .
eq newVar(N,TP TPL) = (newVar*(N,TP),newVar(s(N),TPL)) .
op newVar* : Nat Type -> Variable .
eq newVar*(N,TP)
= qid("#" + string(N,10) + ":" + string(TP)) .
op simplifyVars : TermList -> TermList .
eq simplifyVars(TL) = TL << 0 < .
op _<<`(_`)< : TermList GTermList -> TermList .
eq X:TermList <<(TL:GTermList)<
= X:TermList << highestVar(TL:GTermList) + 1 < .
op _<<_ : TermList UnificationPair -> TermList .
eq TL << {Subst,N} = TL << Subst .
op _<<_ : TermList UnificationTriple -> TermList .
eq TL << {Subst,Subst',N} = TL << (Subst ; Subst') .
op _<<_ : Substitution UnificationTriple -> Substitution .
eq S:Substitution << {Subst,Subst',N} = S:Substitution << (Subst ; Subst') .
op _<<_< : TermList Nat -> TermList .
eq TL << N < = TL << (TL << { none, N } <) .
op _<<_< : TermList UnificationPair -> UnificationPair . ***Huge [memo] .
eq C << {S,N} < = {S,N} .
eq F[TL] << {S,N} < = TL << {S,N} < .
eq V << {S,N} <
= if not (dom S inVars V)
then {S ; V <- newVar(N,getType(V)), N + 1}
else {S,N}
fi .
eq (T,TL:NeTermList) << {S,N} <
= TL:NeTermList << (T << {S,N} < ) < .
eq empty << {S,N} <
= {S,N} .
endfm
fmod SUBSTITUTIONSET is
protecting SUBSTITUTION-HANDLING .
protecting META-LEVEL-MNPA .
protecting TERMSET .
protecting RENAMING .
sort SubstitutionSet NeSubstitutionSet .
subsort Substitution < NeSubstitutionSet < SubstitutionSet .
op empty : -> SubstitutionSet [ctor] .
op _|_ : SubstitutionSet SubstitutionSet -> SubstitutionSet
[ctor assoc comm id: empty format (d n d d)] .
op _|_ : NeSubstitutionSet SubstitutionSet -> NeSubstitutionSet
[ctor ditto] .
eq X:Substitution | X:Substitution = X:Substitution .
vars SS SS' : SubstitutionSet .
vars S S' Subst : Substitution .
vars T T' : Term .
vars TL TL' : TermList .
vars N N' : Nat .
var V : Variable .
op _<<_ : Substitution SubstitutionSet -> SubstitutionSet .
eq S << empty = empty .
ceq S << (S' | SS') = (S << S') | (S << SS') if SS' =/= empty .
op _..._ : SubstitutionSet [SubstitutionSet]
-> SubstitutionSet [strat (1) gather (e E)] .
eq empty ... SS':[SubstitutionSet] = empty .
eq (S | SS) ... SS':[SubstitutionSet]
= (S ...' SS':[SubstitutionSet])
|
(SS ... SS':[SubstitutionSet]) .
op _...'_ : Substitution SubstitutionSet -> SubstitutionSet .
eq S ...' empty
= empty .
eq S ...' (S' | SS')
= (S .. S')
|
(S ...' SS') .
op _|>_ : SubstitutionSet TermList -> SubstitutionSet .
eq (empty).SubstitutionSet |> TL = empty .
eq (S | SS:NeSubstitutionSet) |> TL
= (S |> TL) | (SS:NeSubstitutionSet |> TL) .
op _|>_ : SubstitutionSet Nat -> SubstitutionSet .
eq SS:NeSubstitutionSet |> N
= SS:NeSubstitutionSet |> (0,N) .