File: subsumption-subst.lisp

package info (click to toggle)
acl2 8.3dfsg-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 309,408 kB
  • sloc: lisp: 3,311,842; javascript: 22,569; cpp: 9,029; ansic: 7,872; perl: 6,501; xml: 3,838; java: 3,738; makefile: 3,383; ruby: 2,633; sh: 2,489; ml: 763; python: 741; yacc: 721; awk: 260; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (748 lines) | stat: -rw-r--r-- 23,289 bytes parent folder | download | duplicates (6)
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
;;; subsumption-subst.lisp
;;; The subsumption relation between substitutions
;;; Created 13-10-99. Last revision: 09-01-2001
;;; =================================================================


#| To certify this book:

(in-package "ACL2")

(certify-book "subsumption-subst")

|#

(in-package "ACL2")
(include-book "subsumption")




;;; *******************************************************************
;;; THE SUBSUMPTION RELATION BETWEEN SUBSTITUTIONS.
;;; DEFINITION AND PROPERTIES.
;;; *******************************************************************

;;; Our goal is to define the subsumption relation between
;;; substitutions. In the literature, this relation is defined in this
;;; way:
;;;     sigma <= delta iff (exists gamma) gamma·sigma = delta
;;; where "·" stands for composition.

;;; Note that equality between substitutions is functional equality (we cannot
;;; use equal), so we reformulate this property as:

;;; (*) sigma <= delta iff (exists gamma)
;;;                        s.t. for all term
;;;                        gamma·sigma(term) = delta(term)


;;; Our goal in this book is to define the subsumption relation between
;;; substitutions as a function, subs-subst. We will define that
;;; function paying attention only to a restricted list of
;;; variables. Then will prove (*) in the ACL2 logic. As subsumption
;;; between terms (due to existential quantification) we have to give
;;; the substitution gamma in a constructive way, so our definition of
;;; the subsumption relation will be based on a algorithm that finds
;;; such substitution gamma, whenever it exists.


;;; That is to say, we are going to:

;;; 1) Define the subsumption relation, (subs-subst sigma delta) as a
;;;    function and the witness matching substitution, called
;;;    (matching-subst-r sigma delta). Both functions will be based on a
;;;    matching algorithm called subs-subst-mv.

;;; 2) Prove that if (subs-subst sigma delta), then
;;;    (matching-subst-r sigma delta) applied to sigma(term) is equal to
;;;    delta(term), with the same matching substitution, for all
;;;    term. The reverse implication is trivial.


;;; ============================================================================
;;; 1. Definition of subs-subst
;;; ============================================================================

;;; ----------------------------------------------------------------------------
;;; 1.1. Some previous definitions and lemmas
;;; ----------------------------------------------------------------------------

;;; ===== TRUE-LIST-OF-VARIABLES
(local
 (defun true-list-of-variables (l)
   (if (atom l)
       (equal l nil)
     (and (variable-p (car l))
	  (true-list-of-variables (cdr l))))))

(local
 (defthm true-list-of-variables-append
   (implies (and (true-list-of-variables l)
		 (true-list-of-variables m))
	    (true-list-of-variables (append l m)))))

(local
 (defthm true-list-of-variables-variables
   (true-list-of-variables (variables flg term))))


;;; ===== TRUE-LIST-OF-EQLABLEP (needed for guard verification)
(local
 (defun true-list-of-eqlablep (l)
   (if (atom l)
       (equal l nil)
     (and (eqlablep (car l))
	  (true-list-of-eqlablep (cdr l))))))

(local
 (defthm true-list-of-eqlablep-append
   (implies (and (true-list-of-eqlablep l)
		 (true-list-of-eqlablep m))
	    (true-list-of-eqlablep (append l m)))))

(local
 (defthm true-list-of-eqlablep-variables
   (implies (term-s-p-aux flg term)
	    (true-list-of-eqlablep (variables flg term)))))



;;; ===== DOMAIN-VAR
;;; The variables of the domain (to remove anomalies).

(defun domain-var (sigma)
  (if (endp sigma)
      nil
    (if (variable-p (caar sigma))
	(cons (caar sigma) (domain-var (cdr sigma)))
      (domain-var (cdr sigma)))))



;;; Its main properties

(local
 (defthm domain-var-main-property
   (iff (member x (domain-var sigma))
	(and (member x (domain sigma))
	     (variable-p x)))))

;;; Needed for guard verification
(local
 (defthm true-list-of-variables-domain-var
   (true-list-of-variables (domain-var sigma))))

(local
 (defthm true-list-of-eqlablep-domain-var
   (implies (substitution-s-p sigma)
	    (true-list-of-eqlablep (domain-var sigma)))))


(local (in-theory (disable domain-var)))




;;; ====== CO-DOMAIN-VAR
;;; The "values" of the variables in domain-var


(defun co-domain-var (sigma)
  (if (endp sigma)
      nil
    (if (variable-p (caar sigma))
	(cons (cdar sigma) (co-domain-var (cdr sigma)))
      (co-domain-var (cdr sigma)))))

;;; Needed for guard verification
(local
 (defthm term-s-p-aux-co-domain-var
   (implies (substitution-s-p sigma)
	    (term-s-p-aux nil (co-domain-var sigma)))))



;;; ====== IMPORTANT-VARIABLES
;;; For subsumption of substitutions, we only pay atention to these
;;; variables

(defun important-variables (sigma delta)
  (append (domain-var sigma)
	  (append (domain-var delta)
		  (variables nil (co-domain-var sigma)))))



;;; ===== SYSTEM-SUBS-SUBST.
;;; A technical macro definition
;;; We will prove below that two substitutions are related by
;;; subsumption iff the following system of equations is matchable.

(local
 (defmacro system-subs-subst (sigma delta)
   `(first
     (pair-args
      (apply-subst nil ,sigma (important-variables ,sigma ,delta))
      (apply-subst nil ,delta (important-variables ,sigma ,delta))))))


;;; ----------------------------------------------------------------------------
;;; 1.2. Definition of subs-subst
;;; ----------------------------------------------------------------------------


;;;; NOTATION:
;;;; ^^^^^^^^^
;;;; In the followin comments, V will be
;;;; (important-variables sigma delta))

;;; ===== SUBS-SUBST-MV
;;; Subsumption between substitutions.
;;; To decide wether sigma subsumes delta, then we take the list of
;;; variables of the domain of sigma, the domain of delta and the
;;; variables of the terms in the co-domain of sigma (i.e, the list V), and
;;; test if the list of terms sigma(V) subsumes the list of terms
;;; delta(V).

(defun subs-subst-mv (sigma delta)
  (let ((V (important-variables sigma delta)))
    (mv-let (system bool)
	    (pair-args (apply-subst nil sigma V)
		       (apply-subst nil delta V))
	    (declare (ignore bool))
	    (match-mv system))))

;;; ====== SUBS-SUBST
;;; The subsumption relation between substitutions:


(defun subs-subst (sigma delta)
  (mv-let (match bool)
	  (subs-subst-mv sigma delta)
	  (declare (ignore match))
	  bool))


;;; ===== MATCHING-SUBST
;;; An important auxiliary definition: when
;;; (subs-subst sigma delta) returns t, this is the substitution that
;;; applied to the list (apply-subst nil sigma V) returns
;;; (apply-subst nil delta V)

(defun matching-subst (sigma delta)
  (mv-let (match bool)
	  (subs-subst-mv sigma delta)
	  (declare (ignore bool))
	  match))

;;; ====== MATCHING-SUBST-R
;;; Restriction of (subs-sust sigma delta) to V.

(defun matching-subst-r (sigma delta)
  (restriction (matching-subst sigma delta)
	       (important-variables sigma delta)))


;;; REMARKS:
;;;
;;; 1) The substitution subs-sust-r is the witness substitution to prove
;;; subsumption between sigma(term) and delta(term), for all terms, as
;;; we will prove.

;;; 2) For our particular implementation of subsumption between terms,
;;; subs-sust and subs-sust-r are exactly the same (from a functional
;;; pont of view) (when subs-sust is not nil). But we have to define
;;; subs-sust-r to assure explicitly that outside V, the substitution is
;;; the identity, because this is not derived from the soundness and
;;; completeness theorems of and we forbid ourselves to use particular
;;; properties of a particular matching algorithms.

;;; 3) Note that subst-sust-r probably has many repetitions in his
;;; domain, but this is not a problem for us. We will not use
;;; subs-sust-r to compute, only as a tool to deduce properties.


;;; ============================================================================
;;; 2. Soundness theorem
;;; ============================================================================

;;; We want to prove: if (subs-sust sigma delta), then
;;; the substitutions
;;; delta
;;; and
;;; (composition (subs-subst-r sigma delta) sigma)
;;; are functionally equal.

;;; ----------------------------------------------------------------------------
;;; 3.1 The main lemma needed for the soundness theorem
;;; ----------------------------------------------------------------------------


;;; The main goal here is to prove that:
;;; For all variable x,
;;; (val x (composition (subs-subst-r sigma delta) sigma)) = (val x delta)
;;; if (subs-sust sigma delta)
;;; WE DISTINGUISH THREE CASES.

;;; ············································································
;;; 3.1.1 Case 1: x is a variable outside V
;;; ············································································



(local
 (defthm subs-subst-main-property-variable-x-not-in-V
   (let ((V (important-variables sigma delta)))
     (implies (and
	       (variable-p x)
	       (not (member x V))
	       (subs-subst sigma delta))
	      (equal (instance (val x sigma) (matching-subst-r sigma delta))
		     (val x delta))))
   :hints (("Goal" :in-theory (enable x-not-in-domain-remains-the-same)))))


;;; ············································································
;;; 3.1.2. Case 2: x is a variable of (domain-var sigma)
;;; ············································································


;;; 3.1.2.1 A lemma for this case 2:
;;; subs-subst composed with sigma is equal to delta in V.
;;; ······················································

(local
 (encapsulate
  ()

;;; Two  previous lemmas:
  (local
   (defthm pair-args-success
     (second (pair-args (apply-subst nil sigma l)
			(apply-subst nil delta l)))))

  (local
   (defthm apply-nil-apply-t
     (implies (and (equal (apply-subst nil sigma1 l)
			  (apply-subst nil sigma2 l))
		   (member x l))
	      (equal (instance x sigma1)
		     (instance x sigma2)))
     :rule-classes nil))

;;; A technical lemma:

  (local
   (defthm apply-subst-from-matchers-to-lists-of-terms
     (implies (and
	       (second (pair-args l m))
	       (matcher sigma (first (pair-args l m))))
	      (equal (equal (apply-subst nil sigma l) m) t))
     :hints (("Goal" :induct (pair-args l m)))))

;;; And the intended lemma:

  (defthm matching-subst-composed-sigma-coincide-with-delta-in-V
    (let ((V (important-variables sigma delta)))
      (implies (and
		(variable-p x)
		(member x V)
		(subs-subst sigma delta))
	       (equal (instance (val x sigma) (matching-subst sigma delta))
		      (val x delta))))
    :hints (("Goal" :in-theory (disable important-variables)
	     :use (:instance apply-nil-apply-t
			     (l (important-variables sigma delta))
			     (sigma1 (composition
				      (matching-subst sigma delta) sigma))
			     (sigma2 delta)))))))



;;; REMARKS:
;;; 1) If we not disable important-variables the proof is longer.
;;; 2) The condition (variable-p x) is not necessary, but the proof is
;;; shorter.


;;; The above lemma gives the fundamental property of subs-subst and
;;; matching-subst . We can forget its definition, so we disable their
;;; definitions:

(local (in-theory (disable subs-subst matching-subst)))

;;; 3.1.2.2 Another lemma for case 2:
;;; ·······························

(local
 (defthm variables-co-domain-var
  (implies (member x (domain-var sigma))
	   (subsetp (variables t (val x sigma))
		    (variables nil (co-domain-var sigma))))))


;;; 3.1.2.3 The main result for Case 2
;;; ································

(local
 (defthm
   subs-subst-main-property-variable-x-in-domain-var-sigma
   (implies (and
	     (variable-p x)
	     (member x (domain-var sigma))
	     (subs-subst sigma delta))
	    (equal (apply-subst t (matching-subst-r sigma delta) (val x sigma))
		   (val x delta)))))


;;; ············································································
;;; 3.1.3. Case 3: x in V but not in (domain-var sigma)
;;; ············································································


;;; 3.1.3.1 A lemma for Case 3
;;; In this case, matching and matching-subst-r take the same values.
;;; ·································································

(local
 (defthm
   subsumption-subst-main-property-variable-in-V-not-in-domain-var-sigma-lemma
   (let ((V (important-variables sigma delta)))
     (implies (and
	       (variable-p x)
	       (not (member x (domain-var sigma)))
	       (member x V)
	       (subs-subst sigma delta))
	      (equal (apply-subst t (matching-subst-r sigma delta) (val x sigma))
		     (apply-subst t (matching-subst sigma delta)
				  (val x sigma)))))
   :hints (("Goal" :in-theory (enable x-not-in-domain-remains-the-same)))))


;;; We disable important-variables and matching-subst-r since we do not
;;; need to "extract" more properties from the definitions.

(local (in-theory (disable important-variables matching-subst-r)))


;;; 3.1.3.2 The main result for this case.
;;; This result is not strictly needed, bu we include in favour of
;;; clarity.

(local
 (defthm
   subs-subst-main-property-variable-x-in-V-not-in-domain-var-sigma
   (let ((V (important-variables sigma delta)))
     (implies (and
	       (variable-p x)
	       (not (member x (domain-var sigma)))
	       (member x V)
	       (subs-subst sigma delta))
	      (equal (apply-subst t (matching-subst-r sigma delta) (val x sigma))
		     (val x delta))))))



;;; ----------------------------------------------------------------------------
;;; 3.2 Statements of the soundness theorem
;;; ----------------------------------------------------------------------------

;;; Joining the three cases together, we prove
;;; functional equality between
;;; (composition (matching-subst-r sigma delta) sigma) and delta.


(local
 (defthm
   equal-composition-matching-subst-with-sigma-to-delta-variable
   (implies (and (variable-p x)
		 (subs-subst sigma delta))
	    (equal (val x (composition (matching-subst-r sigma delta) sigma))
		   (val x delta)))
   :hints
   (("Goal"
     :cases ((not (member x (important-variables sigma delta)))
	     (member x (domain-var sigma)))))))




;;; DIFFERENT VERSIONS OF THE SOUNDNESS THEOREM


;;; With terms and list of terms (not only with variables)
;;; ······················································

(local
 (defthm
   equal-composition-subs-subst-with-sigma-to-delta
   (implies (subs-subst sigma delta)
	    (equal (apply-subst
		    flg
		    (composition (matching-subst-r sigma delta) sigma)
		    term)
		   (apply-subst flg delta term)))
   :hints (("Goal" :in-theory (disable
			       composition-of-substitutions-apply)))
   :rule-classes nil))

;;; We prefer this formulation to be called the soundness theorem of
;;; subs-subst

(defthm
  subs-subst-soundness
  (implies (subs-subst sigma delta)
	   (equal
	    (instance term (composition (matching-subst-r sigma delta)
					sigma))

	    (instance term delta)))
   :rule-classes nil
   :hints (("Goal" :use
	    (:instance
	     equal-composition-subs-subst-with-sigma-to-delta
	     (flg t)))))




;;; REMARK: we do not use the two above lemmas as a rewrite rule to avoid
;;; conflicts with composition-of-substitutions-appply. Instead, the
;;; following version will be used as a rewrite rule.

;;; With terms but without using composition
;;; ········································

(defthm
  subs-subst-implies-matching-subst-r-appplied-to-sigma-term-is-delta-term
  (implies (subs-subst sigma delta)
	   (equal (apply-subst flg (matching-subst-r sigma delta)
			 (apply-subst flg sigma term))
		  (apply-subst flg delta term)))
  :hints
  (("Goal" :use
    (:instance equal-composition-subs-subst-with-sigma-to-delta))))


;;; With respect to subsumption between terms
;;; ·········································


;;; Trivial consequence of completeness of subsumption and the previous
;;; lemma:


(defthm
  subs-subst-main-property
  (implies (subs-subst sigma delta)
	   (subs (instance term sigma) (instance term delta)))
  :hints (("Goal" :use
	   ((:instance subs-completeness
		       (t1 (instance term sigma))
		       (t2 (instance term delta))
		       (sigma (matching-subst-r sigma delta)))))))




;;; ============================================================================
;;; 3. Completeness theorem
;;; ============================================================================

(local (in-theory (enable subs-subst)))


;;; We want to prove the following:
;;; If sigma <= delta, then (subs-subst sigma delta).
;;; In fact, it will be more useful to prove


;;; The theorem is very easy to prove, but the problem is how we
;;; formulate the hypothesis sigma <= delta.  We will assume the
;;; existence of two substitutions, called sigma-w and delta-w and the
;;; only property we will assume about them is that sigma-w <=
;;; delta-w. That is, exists another substitution gamma-w such that
;;; delta-w = gamma-w·sigma-w.

;;; We will use encapsulate for that purpose. Let sigma-w, delta-w and
;;; gamma-w three susbtitutions such that delta-w is functionally equal
;;; to (composition gamma-w sigma-w)

;;; HYPOTHESIS:

(encapsulate
 (((sigma-w) => *)
  ((delta-w) => *)
  ((gamma-w) => *))

 (local (defun sigma-w () nil))
 (local (defun delta-w () nil))
 (local (defun gamma-w () nil))

 (defthm sigma-w-delta-w-subsumption-hypothesis
   (equal (instance term (composition (gamma-w) (sigma-w)))
	  (instance term (delta-w)))
   :rule-classes nil))

;;; Now our goal is to prove (subs-subst (sigma-w) (delta-w)).

;;; The assumption as a rewrite rule:
(local
 (defthm sigma-w-delta-w-subsumption-hypothesis-rewrite-rule
   (equal (instance (instance term (sigma-w)) (gamma-w))
	  (instance term (delta-w)))
   :hints (("Goal" :use sigma-w-delta-w-subsumption-hypothesis))))

;;; The main lemma
(defthm gamma-w-matcher
  (matcher (gamma-w)
	   (first (pair-args (apply-subst nil (sigma-w) l)
			     (apply-subst nil (delta-w) l)))))

;;; And the completeness theorem:

(defthm subs-subst-completeness
  (subs-subst (sigma-w) (delta-w))
  :rule-classes nil
  :hints (("Goal" :use
	   (:instance match-mv-completeness
		      (sigma (gamma-w))
		      (S (system-subs-subst (sigma-w) (delta-w)))))))

;;; REMARK: Note that this result can be easily used by functional
;;; instantiation (see for example unification-definition.lisp).


;;; ============================================================================
;;; 4. Closure properties of subs-subst
;;; ============================================================================

(local (in-theory (enable matching-subst matching-subst-r
		   important-variables)))

;;; ============================================================================
;;; 4.1 Closure properties for the soundness theorem
;;; ============================================================================


;;; We are going to prove that, provided the two substitutions are in a
;;; given signature, the witness substitution used for the soundness
;;; proof above, is also in the given signature.

(encapsulate
 ()

 (local
  (defthm substitution-s-p--apply-subst-nil-term-s-p-aux
    (implies (and (substitution-s-p sigma)
		  (true-list-of-eqlablep l))
	     (term-s-p-aux nil (apply-subst nil sigma l)))))

 (local
  (defthm pair-args-system-p
    (implies (and (term-s-p-aux nil l)
		  (term-s-p-aux nil m))
	     (system-s-p (first (pair-args l m))))))

 (defthm matching-subst-substitution-s-p
   (implies (and (substitution-s-p sigma)
		 (substitution-s-p delta))
	    (substitution-s-p (matching-subst sigma delta))))

 (local
  (defthm restriction-substitution-s-p
    (implies (and (substitution-s-p sigma)
		  (true-list-of-eqlablep l))
	     (substitution-s-p (restriction sigma l)))))

 (defthm matching-subst-r-substitution-s-p
   (implies (and (substitution-s-p sigma)
		 (substitution-s-p delta))
	    (substitution-s-p (matching-subst-r sigma delta)))))





;;; ----------------------------------------------------------------------------
;;; 4.2 Closure property for the completeness theorem
;;; ----------------------------------------------------------------------------

;;; We can prove a slightly different version of the completeness
;;; theorem: the closure property of the completeness theorem
;;;

;;; We want to prove the following:
;;; let us suppose that sigma and gamma are two substitutions IN A GIVEN
;;; SIGNATURE. Suppose that sigma <= delta, i.e., there exists a
;;; substitution gamma IN THE SAME SIGNATURE such that sigma(term) =
;;; gamma.sigma(term), FOR ALL TERM IN THE SIGNATURE.
;;; Then (subs-subst sigma delta).

;;; Let us formulate the hypothesis using encapsulate:


(encapsulate
 (((sigma-w-s) => *)
  ((delta-w-s) => *)
  ((gamma-w-s) => *))

 (local (defun sigma-w-s () nil))
 (local (defun delta-w-s () nil))
 (local (defun gamma-w-s () nil))

 (defthm sigma-w-s-substitution-s-p (substitution-s-p (sigma-w-s)))
 (defthm delta-w-s-substitution-s-p (substitution-s-p (delta-w-s)))
 (defthm gamma-w-s-substitution-s-p (substitution-s-p (gamma-w-s)))

 (defthm sigma-w-s-delta-w-s-subsumption-hypothesis
   (implies (term-s-p term)
	    (equal (instance term (composition (gamma-w-s) (sigma-w-s)))
		   (instance term (delta-w-s))))
   :rule-classes nil))

;;; Now our goal is to prove (subs-subst (sigma-w-s) (delta-w-s)).


;;; The assumption as a rewrite rule:
(local
 (defthm sigma-w-s-delta-w-s-subsumption-hypothesis-rewrite-rule
   (implies (variable-s-p x)
	    (equal (instance (val x (sigma-w-s)) (gamma-w-s))
		   (val x (delta-w-s))))
   :hints (("Goal"
	    :use (:instance
		  sigma-w-s-delta-w-s-subsumption-hypothesis
		  (term x))))))

;;; The main lemma
(local
 (defthm gamma-w-s-matcher
   (implies (true-list-of-eqlablep l)
	    (matcher (gamma-w-s)
		     (first (pair-args (apply-subst nil (sigma-w-s) l)
				       (apply-subst nil (delta-w-s)
						    l)))))))
;;; And the closure property for the completeness theorem

(defthm subs-subst-completeness-closure
  (subs-subst (sigma-w-s) (delta-w-s))
  :rule-classes nil
  :hints (("Goal" :use
	   (:instance match-mv-completeness
		      (sigma (gamma-w-s))
		      (S (system-subs-subst (sigma-w-s) (delta-w-s)))))))

;;; REMARK: Note that this result can be easily used by functional
;;; instantiation.

;;; We disable the defintions of subs-subst (the subsumption relation)
;;; and matching-subst-r (the witness substitution)

(in-theory (disable subs-subst matching-subst-r))