author | wenzelm |
Tue, 24 Jan 2006 00:43:31 +0100 | |
changeset 18768 | 6e97b57cdcba |
parent 17456 | bcf7544875b2 |
permissions | -rw-r--r-- |
17456 | 1 |
(* Title: CCL/Hered.ML |
0 | 2 |
ID: $Id$ |
1459 | 3 |
Author: Martin Coen, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1993 University of Cambridge |
5 |
*) |
|
6 |
||
7 |
fun type_of_terms (Const("Trueprop",_) $ (Const("op =",(Type ("fun", [t,_])))$_$_)) = t; |
|
8 |
||
9 |
(*** Hereditary Termination ***) |
|
10 |
||
5062 | 11 |
Goalw [HTTgen_def] "mono(%X. HTTgen(X))"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
12 |
by (rtac monoI 1); |
0 | 13 |
by (fast_tac set_cs 1); |
757 | 14 |
qed "HTTgen_mono"; |
0 | 15 |
|
5062 | 16 |
Goalw [HTTgen_def] |
3837 | 17 |
"t : HTTgen(A) <-> t=true | t=false | (EX a b. t=<a,b> & a : A & b : A) | \ |
18 |
\ (EX f. t=lam x. f(x) & (ALL x. f(x) : A))"; |
|
0 | 19 |
by (fast_tac set_cs 1); |
757 | 20 |
qed "HTTgenXH"; |
0 | 21 |
|
5062 | 22 |
Goal |
3837 | 23 |
"t : HTT <-> t=true | t=false | (EX a b. t=<a,b> & a : HTT & b : HTT) | \ |
24 |
\ (EX f. t=lam x. f(x) & (ALL x. f(x) : HTT))"; |
|
17456 | 25 |
by (rtac (rewrite_rule [HTTgen_def] |
4423 | 26 |
(HTTgen_mono RS (HTT_def RS def_gfp_Tarski) RS XHlemma1)) 1); |
0 | 27 |
by (fast_tac set_cs 1); |
757 | 28 |
qed "HTTXH"; |
0 | 29 |
|
30 |
(*** Introduction Rules for HTT ***) |
|
31 |
||
5062 | 32 |
Goal "~ bot : HTT"; |
0 | 33 |
by (fast_tac (term_cs addDs [XH_to_D HTTXH]) 1); |
757 | 34 |
qed "HTT_bot"; |
0 | 35 |
|
5062 | 36 |
Goal "true : HTT"; |
0 | 37 |
by (fast_tac (term_cs addIs [XH_to_I HTTXH]) 1); |
757 | 38 |
qed "HTT_true"; |
0 | 39 |
|
5062 | 40 |
Goal "false : HTT"; |
0 | 41 |
by (fast_tac (term_cs addIs [XH_to_I HTTXH]) 1); |
757 | 42 |
qed "HTT_false"; |
0 | 43 |
|
5062 | 44 |
Goal "<a,b> : HTT <-> a : HTT & b : HTT"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
45 |
by (rtac (HTTXH RS iff_trans) 1); |
0 | 46 |
by (fast_tac term_cs 1); |
757 | 47 |
qed "HTT_pair"; |
0 | 48 |
|
5062 | 49 |
Goal "lam x. f(x) : HTT <-> (ALL x. f(x) : HTT)"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
50 |
by (rtac (HTTXH RS iff_trans) 1); |
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
51 |
by (simp_tac term_ss 1); |
0 | 52 |
by (safe_tac term_cs); |
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
53 |
by (asm_simp_tac term_ss 1); |
0 | 54 |
by (fast_tac term_cs 1); |
757 | 55 |
qed "HTT_lam"; |
0 | 56 |
|
57 |
local |
|
58 |
val raw_HTTrews = [HTT_bot,HTT_true,HTT_false,HTT_pair,HTT_lam]; |
|
17456 | 59 |
fun mk_thm s = prove_goalw (the_context ()) data_defs s (fn _ => |
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
60 |
[simp_tac (term_ss addsimps raw_HTTrews) 1]); |
0 | 61 |
in |
62 |
val HTT_rews = raw_HTTrews @ |
|
63 |
map mk_thm ["one : HTT", |
|
64 |
"inl(a) : HTT <-> a : HTT", |
|
65 |
"inr(b) : HTT <-> b : HTT", |
|
66 |
"zero : HTT", |
|
67 |
"succ(n) : HTT <-> n : HTT", |
|
68 |
"[] : HTT", |
|
289 | 69 |
"x$xs : HTT <-> x : HTT & xs : HTT"]; |
0 | 70 |
end; |
71 |
||
72 |
val HTT_Is = HTT_rews @ (HTT_rews RL [iffD2]); |
|
73 |
||
74 |
(*** Coinduction for HTT ***) |
|
75 |
||
17456 | 76 |
val prems = goal (the_context ()) "[| t : R; R <= HTTgen(R) |] ==> t : HTT"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
77 |
by (rtac (HTT_def RS def_coinduct) 1); |
0 | 78 |
by (REPEAT (ares_tac prems 1)); |
757 | 79 |
qed "HTT_coinduct"; |
0 | 80 |
|
81 |
fun HTT_coinduct_tac s i = res_inst_tac [("R",s)] HTT_coinduct i; |
|
82 |
||
17456 | 83 |
val prems = goal (the_context ()) |
0 | 84 |
"[| t : R; R <= HTTgen(lfp(%x. HTTgen(x) Un R Un HTT)) |] ==> t : HTT"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
85 |
by (rtac (HTTgen_mono RSN(3,HTT_def RS def_coinduct3)) 1); |
0 | 86 |
by (REPEAT (ares_tac prems 1)); |
757 | 87 |
qed "HTT_coinduct3"; |
0 | 88 |
val HTT_coinduct3_raw = rewrite_rule [HTTgen_def] HTT_coinduct3; |
89 |
||
90 |
fun HTT_coinduct3_tac s i = res_inst_tac [("R",s)] HTT_coinduct3 i; |
|
91 |
||
17456 | 92 |
val HTTgenIs = map (mk_genIs (the_context ()) data_defs HTTgenXH HTTgen_mono) |
0 | 93 |
["true : HTTgen(R)", |
94 |
"false : HTTgen(R)", |
|
95 |
"[| a : R; b : R |] ==> <a,b> : HTTgen(R)", |
|
3837 | 96 |
"[| !!x. b(x) : R |] ==> lam x. b(x) : HTTgen(R)", |
0 | 97 |
"one : HTTgen(R)", |
98 |
"a : lfp(%x. HTTgen(x) Un R Un HTT) ==> \ |
|
99 |
\ inl(a) : HTTgen(lfp(%x. HTTgen(x) Un R Un HTT))", |
|
100 |
"b : lfp(%x. HTTgen(x) Un R Un HTT) ==> \ |
|
101 |
\ inr(b) : HTTgen(lfp(%x. HTTgen(x) Un R Un HTT))", |
|
102 |
"zero : HTTgen(lfp(%x. HTTgen(x) Un R Un HTT))", |
|
103 |
"n : lfp(%x. HTTgen(x) Un R Un HTT) ==> \ |
|
104 |
\ succ(n) : HTTgen(lfp(%x. HTTgen(x) Un R Un HTT))", |
|
105 |
"[] : HTTgen(lfp(%x. HTTgen(x) Un R Un HTT))", |
|
106 |
"[| h : lfp(%x. HTTgen(x) Un R Un HTT); t : lfp(%x. HTTgen(x) Un R Un HTT) |] ==>\ |
|
289 | 107 |
\ h$t : HTTgen(lfp(%x. HTTgen(x) Un R Un HTT))"]; |
0 | 108 |
|
109 |
(*** Formation Rules for Types ***) |
|
110 |
||
5062 | 111 |
Goal "Unit <= HTT"; |
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
112 |
by (simp_tac (CCL_ss addsimps ([subsetXH,UnitXH] @ HTT_rews)) 1); |
757 | 113 |
qed "UnitF"; |
0 | 114 |
|
5062 | 115 |
Goal "Bool <= HTT"; |
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
116 |
by (simp_tac (CCL_ss addsimps ([subsetXH,BoolXH] @ HTT_rews)) 1); |
0 | 117 |
by (fast_tac (set_cs addIs HTT_Is @ (prems RL [subsetD])) 1); |
757 | 118 |
qed "BoolF"; |
0 | 119 |
|
17456 | 120 |
val prems = goal (the_context ()) "[| A <= HTT; B <= HTT |] ==> A + B <= HTT"; |
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
121 |
by (simp_tac (CCL_ss addsimps ([subsetXH,PlusXH] @ HTT_rews)) 1); |
0 | 122 |
by (fast_tac (set_cs addIs HTT_Is @ (prems RL [subsetD])) 1); |
757 | 123 |
qed "PlusF"; |
0 | 124 |
|
17456 | 125 |
val prems = goal (the_context ()) |
3837 | 126 |
"[| A <= HTT; !!x. x:A ==> B(x) <= HTT |] ==> SUM x:A. B(x) <= HTT"; |
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
127 |
by (simp_tac (CCL_ss addsimps ([subsetXH,SgXH] @ HTT_rews)) 1); |
0 | 128 |
by (fast_tac (set_cs addIs HTT_Is @ (prems RL [subsetD])) 1); |
757 | 129 |
qed "SigmaF"; |
0 | 130 |
|
131 |
(*** Formation Rules for Recursive types - using coinduction these only need ***) |
|
132 |
(*** exhaution rule for type-former ***) |
|
133 |
||
134 |
(*Proof by induction - needs induction rule for type*) |
|
5062 | 135 |
Goal "Nat <= HTT"; |
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
136 |
by (simp_tac (term_ss addsimps [subsetXH]) 1); |
0 | 137 |
by (safe_tac set_cs); |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
138 |
by (etac Nat_ind 1); |
0 | 139 |
by (ALLGOALS (fast_tac (set_cs addIs HTT_Is @ (prems RL [subsetD])))); |
140 |
val NatF = result(); |
|
141 |
||
5062 | 142 |
Goal "Nat <= HTT"; |
0 | 143 |
by (safe_tac set_cs); |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
144 |
by (etac HTT_coinduct3 1); |
17456 | 145 |
by (fast_tac (set_cs addIs HTTgenIs |
0 | 146 |
addSEs [HTTgen_mono RS ci3_RI] addEs [XH_to_E NatXH]) 1); |
757 | 147 |
qed "NatF"; |
0 | 148 |
|
17456 | 149 |
val [prem] = goal (the_context ()) "A <= HTT ==> List(A) <= HTT"; |
0 | 150 |
by (safe_tac set_cs); |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
151 |
by (etac HTT_coinduct3 1); |
17456 | 152 |
by (fast_tac (set_cs addSIs HTTgenIs |
153 |
addSEs [HTTgen_mono RS ci3_RI,prem RS subsetD RS (HTTgen_mono RS ci3_AI)] |
|
0 | 154 |
addEs [XH_to_E ListXH]) 1); |
757 | 155 |
qed "ListF"; |
0 | 156 |
|
17456 | 157 |
val [prem] = goal (the_context ()) "A <= HTT ==> Lists(A) <= HTT"; |
0 | 158 |
by (safe_tac set_cs); |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
159 |
by (etac HTT_coinduct3 1); |
17456 | 160 |
by (fast_tac (set_cs addSIs HTTgenIs |
161 |
addSEs [HTTgen_mono RS ci3_RI,prem RS subsetD RS (HTTgen_mono RS ci3_AI)] |
|
0 | 162 |
addEs [XH_to_E ListsXH]) 1); |
757 | 163 |
qed "ListsF"; |
0 | 164 |
|
17456 | 165 |
val [prem] = goal (the_context ()) "A <= HTT ==> ILists(A) <= HTT"; |
0 | 166 |
by (safe_tac set_cs); |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
167 |
by (etac HTT_coinduct3 1); |
17456 | 168 |
by (fast_tac (set_cs addSIs HTTgenIs |
169 |
addSEs [HTTgen_mono RS ci3_RI,prem RS subsetD RS (HTTgen_mono RS ci3_AI)] |
|
0 | 170 |
addEs [XH_to_E IListsXH]) 1); |
757 | 171 |
qed "IListsF"; |
0 | 172 |
|
173 |
(*** A possible use for this predicate is proving equality from pre-order ***) |
|
174 |
(*** but it seems as easy (and more general) to do this directly by coinduction ***) |
|
175 |
(* |
|
17456 | 176 |
val prems = goal (the_context ()) "[| t : HTT; t [= u |] ==> u [= t"; |
3837 | 177 |
by (po_coinduct_tac "{p. EX a b. p=<a,b> & b : HTT & b [= a}" 1); |
0 | 178 |
by (fast_tac (ccl_cs addIs prems) 1); |
179 |
by (safe_tac ccl_cs); |
|
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
289
diff
changeset
|
180 |
by (dtac (poXH RS iffD1) 1); |
0 | 181 |
by (safe_tac (set_cs addSEs [HTT_bot RS notE])); |
182 |
by (REPEAT_SOME (rtac (POgenXH RS iffD2) ORELSE' etac rev_mp)); |
|
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
183 |
by (ALLGOALS (simp_tac (term_ss addsimps HTT_rews))); |
0 | 184 |
by (ALLGOALS (fast_tac ccl_cs)); |
757 | 185 |
qed "HTT_po_op"; |
0 | 186 |
|
17456 | 187 |
val prems = goal (the_context ()) "[| t : HTT; t [= u |] ==> t = u"; |
0 | 188 |
by (REPEAT (ares_tac (prems @ [conjI RS (eq_iff RS iffD2),HTT_po_op]) 1)); |
757 | 189 |
qed "HTT_po_eq"; |
0 | 190 |
*) |