1173
|
1 |
(* Title: HOL/ex/Perm.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
4 |
Copyright 1995 University of Cambridge
|
|
5 |
|
|
6 |
Permutations: example of an inductive definition
|
|
7 |
*)
|
|
8 |
|
|
9 |
(*It would be nice to prove
|
|
10 |
xs <~~> ys = (!x. count xs x = count ys x)
|
|
11 |
See mset on HOL/ex/Sorting.thy
|
|
12 |
*)
|
|
13 |
|
|
14 |
open Perm;
|
|
15 |
|
|
16 |
goal Perm.thy "l <~~> l";
|
|
17 |
by (list.induct_tac "l" 1);
|
|
18 |
by (REPEAT (ares_tac perm.intrs 1));
|
|
19 |
qed "perm_refl";
|
|
20 |
|
|
21 |
val perm_induct = standard (perm.mutual_induct RS spec RS spec RSN (2,rev_mp));
|
|
22 |
|
|
23 |
|
1192
|
24 |
(** Some examples of rule induction on permutations **)
|
|
25 |
|
|
26 |
(*The form of the premise lets the induction bind xs and ys.*)
|
|
27 |
goal Perm.thy "!!xs. xs <~~> ys ==> xs=[] --> ys=[]";
|
|
28 |
by (etac perm_induct 1);
|
|
29 |
by (ALLGOALS (asm_simp_tac (HOL_ss addsimps list.simps)));
|
|
30 |
qed "perm_Nil_lemma";
|
|
31 |
|
|
32 |
(*A more general version is actually easier to understand!*)
|
|
33 |
goal Perm.thy "!!xs. xs <~~> ys ==> length(xs) = length(ys)";
|
|
34 |
by (etac perm_induct 1);
|
|
35 |
by (ALLGOALS (asm_simp_tac list_ss));
|
|
36 |
qed "perm_length";
|
1173
|
37 |
|
|
38 |
goal Perm.thy "!!xs. xs <~~> ys ==> ys <~~> xs";
|
|
39 |
by (etac perm_induct 1);
|
|
40 |
by (REPEAT (ares_tac perm.intrs 1));
|
|
41 |
qed "perm_sym";
|
|
42 |
|
|
43 |
goal Perm.thy "!!xs. [| xs <~~> ys |] ==> x mem xs --> x mem ys";
|
|
44 |
by (etac perm_induct 1);
|
|
45 |
by (fast_tac HOL_cs 4);
|
|
46 |
by (ALLGOALS (asm_simp_tac (list_ss setloop split_tac [expand_if])));
|
|
47 |
val perm_mem_lemma = result();
|
|
48 |
|
|
49 |
bind_thm ("perm_mem", perm_mem_lemma RS mp);
|
|
50 |
|
|
51 |
(** Ways of making new permutations **)
|
|
52 |
|
|
53 |
(*We can insert the head anywhere in the list*)
|
|
54 |
goal Perm.thy "a # xs @ ys <~~> xs @ a # ys";
|
|
55 |
by (list.induct_tac "xs" 1);
|
|
56 |
by (simp_tac (list_ss addsimps [perm_refl]) 1);
|
|
57 |
by (simp_tac list_ss 1);
|
|
58 |
by (etac ([perm.swap, perm.Cons] MRS perm.trans) 1);
|
|
59 |
qed "perm_append_Cons";
|
|
60 |
|
|
61 |
(*single steps
|
|
62 |
by (rtac perm.trans 1);
|
|
63 |
by (rtac perm.swap 1);
|
|
64 |
by (rtac perm.Cons 1);
|
|
65 |
*)
|
|
66 |
|
|
67 |
goal Perm.thy "xs@ys <~~> ys@xs";
|
|
68 |
by (list.induct_tac "xs" 1);
|
|
69 |
by (simp_tac (list_ss addsimps [perm_refl]) 1);
|
|
70 |
by (simp_tac list_ss 1);
|
|
71 |
by (etac ([perm.Cons, perm_append_Cons] MRS perm.trans) 1);
|
|
72 |
qed "perm_append_swap";
|
|
73 |
|
|
74 |
|
|
75 |
goal Perm.thy "a # xs <~~> xs @ [a]";
|
|
76 |
by (rtac perm.trans 1);
|
|
77 |
br perm_append_swap 2;
|
|
78 |
by (simp_tac (list_ss addsimps [perm_refl]) 1);
|
|
79 |
qed "perm_append_single";
|
|
80 |
|
|
81 |
goal Perm.thy "rev xs <~~> xs";
|
|
82 |
by (list.induct_tac "xs" 1);
|
|
83 |
by (simp_tac (list_ss addsimps [perm_refl]) 1);
|
|
84 |
by (simp_tac list_ss 1);
|
|
85 |
by (rtac (perm_append_single RS perm_sym RS perm.trans) 1);
|
|
86 |
by (etac perm.Cons 1);
|
|
87 |
qed "perm_rev";
|
|
88 |
|
|
89 |
goal Perm.thy "!!xs. xs <~~> ys ==> l@xs <~~> l@ys";
|
|
90 |
by (list.induct_tac "l" 1);
|
|
91 |
by (simp_tac list_ss 1);
|
|
92 |
by (asm_simp_tac (list_ss addsimps [perm.Cons]) 1);
|
|
93 |
qed "perm_append1";
|
|
94 |
|
|
95 |
goal Perm.thy "!!xs. xs <~~> ys ==> xs@l <~~> ys@l";
|
|
96 |
by (rtac (perm_append_swap RS perm.trans) 1);
|
|
97 |
by (etac (perm_append1 RS perm.trans) 1);
|
|
98 |
by (rtac perm_append_swap 1);
|
|
99 |
qed "perm_append2";
|
|
100 |
|