summaryrefslogtreecommitdiff
path: root/lists/perm.lisp
blob: e1d8c77adc4f8ebe3fbbeed00288470abd0a8d9d (plain)
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
(in-package "ACL2")

(defun perm (x y)
  (cond
    ((atom x) (atom y))
    ((member-equal (car x) y)
     (perm (cdr x) (remove1-equal (car x) y)))
    (t nil)))

(local
 (defthm perm-reflexive
   (perm x x)))

(local
 (encapsulate
   ()
   (local
    (defthm perm-member
      (implies (and (consp y)
                    (perm x y))
               (member (car y) x))))

   (local
    (defthm perm-remove1
      (implies (and (consp y) (perm x y))
               (perm (remove1 (car y) x)
                     (cdr y)))))

   (defthm perm-symmetric
     (implies (perm x y)
              (perm y x))
     :hints (("Goal" :induct (perm y x))))))

(local
 (encapsulate
   ()

   (local
    (defthm remove1-remove1
      (equal (remove1 x (remove1 y z))
             (remove1 y (remove1 x z)))))

   (local
    (defthm member-remove1
      (implies (not (equal x y))
               (iff (member x (remove1 y z))
                    (member x z)))))

   (local
    (defthm perm-remove1
      (implies (perm x y)
               (perm (remove1 e x)
                     (remove1 e y)))))

   (local
    (defthm perm-not-member
      (implies (and (member e x)
                    (not (member e y)))
               (not (perm x y)))
      :hints (("Subgoal *1/3" :cases ((equal (car x) e))))))

   (defthm perm-transitive
     (implies (and (perm x y)
                   (perm y z))
              (perm x z)))))

(defequiv perm)