author | huffman |
Mon, 24 May 2010 11:29:49 -0700 | |
changeset 37109 | e67760c1b851 |
parent 37082 | a1fb7947dc2b |
child 37145 | 01aa36932739 |
permissions | -rw-r--r-- |
32126 | 1 |
(* Title: HOLCF/Tools/Domain/domain_theorems.ML |
23152 | 2 |
Author: David von Oheimb |
32740 | 3 |
Author: Brian Huffman |
23152 | 4 |
|
5 |
Proof generator for domain command. |
|
6 |
*) |
|
7 |
||
26342 | 8 |
val HOLCF_ss = @{simpset}; |
23152 | 9 |
|
31005 | 10 |
signature DOMAIN_THEOREMS = |
11 |
sig |
|
35444 | 12 |
val theorems: |
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
13 |
Domain_Library.eq * Domain_Library.eq list -> |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
14 |
binding -> |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
15 |
(binding * (bool * binding option * typ) list * mixfix) list -> |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
16 |
Domain_Take_Proofs.iso_info -> |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
17 |
Domain_Take_Proofs.take_induct_info -> |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
18 |
theory -> thm list * theory; |
35444 | 19 |
|
35657
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
20 |
val comp_theorems : |
35774 | 21 |
binding * Domain_Library.eq list -> |
35657
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
22 |
Domain_Take_Proofs.take_induct_info -> |
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
23 |
theory -> thm list * theory |
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
24 |
|
32740 | 25 |
val quiet_mode: bool Unsynchronized.ref; |
26 |
val trace_domain: bool Unsynchronized.ref; |
|
31005 | 27 |
end; |
28 |
||
31023 | 29 |
structure Domain_Theorems :> DOMAIN_THEOREMS = |
31005 | 30 |
struct |
23152 | 31 |
|
32740 | 32 |
val quiet_mode = Unsynchronized.ref false; |
33 |
val trace_domain = Unsynchronized.ref false; |
|
29402 | 34 |
|
35 |
fun message s = if !quiet_mode then () else writeln s; |
|
36 |
fun trace s = if !trace_domain then tracing s else (); |
|
37 |
||
23152 | 38 |
open Domain_Library; |
39 |
infixr 0 ===>; |
|
40 |
infixr 0 ==>; |
|
41 |
infix 0 == ; |
|
42 |
infix 1 ===; |
|
43 |
infix 1 ~= ; |
|
44 |
infix 1 <<; |
|
45 |
infix 1 ~<<; |
|
46 |
infix 9 ` ; |
|
47 |
infix 9 `% ; |
|
48 |
infix 9 `%%; |
|
49 |
infixr 9 oo; |
|
50 |
||
51 |
(* ----- general proof facilities ------------------------------------------- *) |
|
52 |
||
35800
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
53 |
local |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
54 |
|
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
55 |
fun map_typ f g (Type (c, Ts)) = Type (g c, map (map_typ f g) Ts) |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
56 |
| map_typ f _ (TFree (x, S)) = TFree (x, map f S) |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
57 |
| map_typ f _ (TVar (xi, S)) = TVar (xi, map f S); |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
58 |
|
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
59 |
fun map_term f g h (Const (c, T)) = Const (h c, map_typ f g T) |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
60 |
| map_term f g _ (Free (x, T)) = Free (x, map_typ f g T) |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
61 |
| map_term f g _ (Var (xi, T)) = Var (xi, map_typ f g T) |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
62 |
| map_term _ _ _ (t as Bound _) = t |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
63 |
| map_term f g h (Abs (x, T, t)) = Abs (x, map_typ f g T, map_term f g h t) |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
64 |
| map_term f g h (t $ u) = map_term f g h t $ map_term f g h u; |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
65 |
|
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
66 |
in |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
67 |
|
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
68 |
fun intern_term thy = |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
69 |
map_term (Sign.intern_class thy) (Sign.intern_type thy) (Sign.intern_const thy); |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
70 |
|
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
71 |
end; |
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
72 |
|
24503 | 73 |
fun legacy_infer_term thy t = |
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36160
diff
changeset
|
74 |
let val ctxt = ProofContext.set_mode ProofContext.mode_schematic (ProofContext.init_global thy) |
35800
76b2a53a199d
moved old Sign.intern_term to the place where it is still used;
wenzelm
parents:
35782
diff
changeset
|
75 |
in singleton (Syntax.check_terms ctxt) (intern_term thy t) end; |
24503 | 76 |
|
23152 | 77 |
fun pg'' thy defs t tacs = |
78 |
let |
|
24503 | 79 |
val t' = legacy_infer_term thy t; |
23152 | 80 |
val asms = Logic.strip_imp_prems t'; |
81 |
val prop = Logic.strip_imp_concl t'; |
|
26711 | 82 |
fun tac {prems, context} = |
23152 | 83 |
rewrite_goals_tac defs THEN |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
84 |
EVERY (tacs {prems = map (rewrite_rule defs) prems, context = context}) |
23152 | 85 |
in Goal.prove_global thy [] asms prop tac end; |
86 |
||
87 |
fun pg' thy defs t tacsf = |
|
88 |
let |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
89 |
fun tacs {prems, context} = |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
90 |
if null prems then tacsf context |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
91 |
else cut_facts_tac prems 1 :: tacsf context; |
23152 | 92 |
in pg'' thy defs t tacs end; |
93 |
||
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
94 |
(* FIXME!!!!!!!!! *) |
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
95 |
(* We should NEVER re-parse variable names as strings! *) |
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
96 |
(* The names can conflict with existing constants or other syntax! *) |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
97 |
fun case_UU_tac ctxt rews i v = |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
98 |
InductTacs.case_tac ctxt (v^"=UU") i THEN |
23152 | 99 |
asm_simp_tac (HOLCF_ss addsimps rews) i; |
100 |
||
101 |
(* ----- general proofs ----------------------------------------------------- *) |
|
102 |
||
29064 | 103 |
val all2E = @{lemma "!x y . P x y ==> (P x y ==> R) ==> R" by simp} |
23152 | 104 |
|
35444 | 105 |
fun theorems |
106 |
(((dname, _), cons) : eq, eqs : eq list) |
|
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
107 |
(dbind : binding) |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
108 |
(spec : (binding * (bool * binding option * typ) list * mixfix) list) |
35558
bb088a6fafbc
add_axioms returns an iso_info; add_theorems takes an iso_info as an argument
huffman
parents:
35557
diff
changeset
|
109 |
(iso_info : Domain_Take_Proofs.iso_info) |
35775
9b7e2e17be69
pass take_info as argument to Domain_Theorems.theorems
huffman
parents:
35774
diff
changeset
|
110 |
(take_info : Domain_Take_Proofs.take_induct_info) |
35444 | 111 |
(thy : theory) = |
23152 | 112 |
let |
113 |
||
29402 | 114 |
val _ = message ("Proving isomorphism properties of domain "^dname^" ..."); |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35512
diff
changeset
|
115 |
val map_tab = Domain_Take_Proofs.get_map_tab thy; |
33801 | 116 |
|
23152 | 117 |
|
118 |
(* ----- getting the axioms and definitions --------------------------------- *) |
|
119 |
||
35558
bb088a6fafbc
add_axioms returns an iso_info; add_theorems takes an iso_info as an argument
huffman
parents:
35557
diff
changeset
|
120 |
val ax_abs_iso = #abs_inverse iso_info; |
bb088a6fafbc
add_axioms returns an iso_info; add_theorems takes an iso_info as an argument
huffman
parents:
35557
diff
changeset
|
121 |
val ax_rep_iso = #rep_inverse iso_info; |
bb088a6fafbc
add_axioms returns an iso_info; add_theorems takes an iso_info as an argument
huffman
parents:
35557
diff
changeset
|
122 |
|
bb088a6fafbc
add_axioms returns an iso_info; add_theorems takes an iso_info as an argument
huffman
parents:
35557
diff
changeset
|
123 |
val abs_const = #abs_const iso_info; |
bb088a6fafbc
add_axioms returns an iso_info; add_theorems takes an iso_info as an argument
huffman
parents:
35557
diff
changeset
|
124 |
val rep_const = #rep_const iso_info; |
bb088a6fafbc
add_axioms returns an iso_info; add_theorems takes an iso_info as an argument
huffman
parents:
35557
diff
changeset
|
125 |
|
23152 | 126 |
local |
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26342
diff
changeset
|
127 |
fun ga s dn = PureThy.get_thm thy (dn ^ "." ^ s); |
23152 | 128 |
in |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
129 |
val ax_take_0 = ga "take_0" dname; |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
130 |
val ax_take_strict = ga "take_strict" dname; |
23152 | 131 |
end; (* local *) |
132 |
||
35775
9b7e2e17be69
pass take_info as argument to Domain_Theorems.theorems
huffman
parents:
35774
diff
changeset
|
133 |
val {take_Suc_thms, deflation_take_thms, ...} = take_info; |
9b7e2e17be69
pass take_info as argument to Domain_Theorems.theorems
huffman
parents:
35774
diff
changeset
|
134 |
|
35444 | 135 |
(* ----- define constructors ------------------------------------------------ *) |
136 |
||
137 |
val (result, thy) = |
|
35777
bcc77916b7b9
pass binding as argument to add_domain_constructors; proper binding for case combinator
huffman
parents:
35776
diff
changeset
|
138 |
Domain_Constructors.add_domain_constructors dbind spec iso_info thy; |
35444 | 139 |
|
35451 | 140 |
val con_appls = #con_betas result; |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
141 |
val {nchotomy, exhaust, ...} = result; |
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
142 |
val {compacts, con_rews, inverts, injects, dist_les, dist_eqs, ...} = result; |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
143 |
val {sel_rews, ...} = result; |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
144 |
val when_rews = #cases result; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
145 |
val when_strict = hd when_rews; |
35461
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
146 |
val dis_rews = #dis_rews result; |
35466
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35464
diff
changeset
|
147 |
val mat_rews = #match_rews result; |
35444 | 148 |
|
23152 | 149 |
(* ----- theorems concerning the isomorphism -------------------------------- *) |
150 |
||
35444 | 151 |
val pg = pg' thy; |
152 |
||
35560 | 153 |
val retraction_strict = @{thm retraction_strict}; |
23152 | 154 |
val abs_strict = ax_rep_iso RS (allI RS retraction_strict); |
155 |
val rep_strict = ax_abs_iso RS (allI RS retraction_strict); |
|
36837 | 156 |
val iso_rews = [ax_abs_iso, ax_rep_iso, abs_strict, rep_strict]; |
23152 | 157 |
|
158 |
(* ----- theorems concerning one induction step ----------------------------- *) |
|
159 |
||
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
160 |
local |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
161 |
fun dc_take dn = %%:(dn^"_take"); |
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
162 |
val dnames = map (fst o fst) eqs; |
35523
cc57f4a274a3
fix proof script for take_apps so it works with indirect recursion
huffman
parents:
35521
diff
changeset
|
163 |
val deflation_thms = Domain_Take_Proofs.get_deflation_thms thy; |
23152 | 164 |
|
35559 | 165 |
fun copy_of_dtyp tab r dt = |
166 |
if Datatype_Aux.is_rec_type dt then copy tab r dt else ID |
|
167 |
and copy tab r (Datatype_Aux.DtRec i) = r i |
|
168 |
| copy tab r (Datatype_Aux.DtTFree a) = ID |
|
169 |
| copy tab r (Datatype_Aux.DtType (c, ds)) = |
|
170 |
case Symtab.lookup tab c of |
|
171 |
SOME f => list_ccomb (%%:f, map (copy_of_dtyp tab r) ds) |
|
172 |
| NONE => (warning ("copy_of_dtyp: unknown type constructor " ^ c); ID); |
|
173 |
||
35521 | 174 |
fun one_take_app (con, args) = |
23152 | 175 |
let |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
176 |
fun mk_take n = dc_take (List.nth (dnames, n)) $ %:"n"; |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
177 |
fun one_rhs arg = |
33971 | 178 |
if Datatype_Aux.is_rec_type (dtyp_of arg) |
35559 | 179 |
then copy_of_dtyp map_tab |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
180 |
mk_take (dtyp_of arg) ` (%# arg) |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
181 |
else (%# arg); |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
182 |
val lhs = (dc_take dname $ (%%:"Suc" $ %:"n"))`(con_app con args); |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
183 |
val rhs = con_app2 con one_rhs args; |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
184 |
val goal = mk_trp (lhs === rhs); |
35590 | 185 |
val rules = |
36160
f84fa49a0b69
add rule deflation_ID to proof script for take + constructor rules
huffman
parents:
35800
diff
changeset
|
186 |
[ax_abs_iso] @ @{thms take_con_rules} |
35775
9b7e2e17be69
pass take_info as argument to Domain_Theorems.theorems
huffman
parents:
35774
diff
changeset
|
187 |
@ take_Suc_thms @ deflation_thms @ deflation_take_thms; |
35590 | 188 |
val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1]; |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
189 |
in pg con_appls goal (K tacs) end; |
35557
5da670d57118
uniformly use variable names m and n in take-related lemmas; use export_without_context where appropriate
huffman
parents:
35528
diff
changeset
|
190 |
val take_apps = map one_take_app cons; |
23152 | 191 |
in |
35494
45c9a8278faf
domain package no longer generates copy functions; all proofs use take functions instead
huffman
parents:
35486
diff
changeset
|
192 |
val take_rews = ax_take_0 :: ax_take_strict :: take_apps; |
23152 | 193 |
end; |
194 |
||
35630
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
195 |
val case_ns = |
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
196 |
"bottom" :: map (fn (b,_,_) => Binding.name_of b) spec; |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
197 |
|
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
198 |
fun qualified name = Binding.qualified true name dbind; |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
199 |
val simp = Simplifier.simp_add; |
35630
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
200 |
|
23152 | 201 |
in |
202 |
thy |
|
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
203 |
|> PureThy.add_thmss [ |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
204 |
((qualified "iso_rews" , iso_rews ), [simp]), |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
205 |
((qualified "nchotomy" , [nchotomy] ), []), |
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
206 |
((qualified "exhaust" , [exhaust] ), |
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
207 |
[Rule_Cases.case_names case_ns, Induct.cases_type dname]), |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
208 |
((qualified "when_rews" , when_rews ), [simp]), |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
209 |
((qualified "compacts" , compacts ), [simp]), |
37082 | 210 |
((qualified "con_rews" , con_rews ), [simp]), |
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
211 |
((qualified "sel_rews" , sel_rews ), [simp]), |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
212 |
((qualified "dis_rews" , dis_rews ), [simp]), |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
213 |
((qualified "dist_les" , dist_les ), [simp]), |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
214 |
((qualified "dist_eqs" , dist_eqs ), [simp]), |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
215 |
((qualified "inverts" , inverts ), [simp]), |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
216 |
((qualified "injects" , injects ), [simp]), |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
217 |
((qualified "take_rews" , take_rews ), [simp]), |
37082 | 218 |
((qualified "match_rews", mat_rews ), [simp])] |
35776
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
219 |
|> snd |
b0bc15d8ad3b
pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents:
35775
diff
changeset
|
220 |
|> pair (iso_rews @ when_rews @ con_rews @ sel_rews @ dis_rews @ |
37109
e67760c1b851
move unused pattern match syntax stuff into HOLCF/ex
huffman
parents:
37082
diff
changeset
|
221 |
dist_les @ dist_eqs) |
23152 | 222 |
end; (* let *) |
223 |
||
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
224 |
(******************************************************************************) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
225 |
(****************************** induction rules *******************************) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
226 |
(******************************************************************************) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
227 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
228 |
fun prove_induction |
35774 | 229 |
(comp_dbind : binding, eqs : eq list) |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
230 |
(take_rews : thm list) |
35659 | 231 |
(take_info : Domain_Take_Proofs.take_induct_info) |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
232 |
(thy : theory) = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
233 |
let |
35774 | 234 |
val comp_dname = Sign.full_name thy comp_dbind; |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
235 |
val dnames = map (fst o fst) eqs; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
236 |
val conss = map snd eqs; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
237 |
fun dc_take dn = %%:(dn^"_take"); |
35662
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
238 |
val x_name = idx_name dnames "x"; |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
239 |
val P_name = idx_name dnames "P"; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
240 |
val pg = pg' thy; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
241 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
242 |
local |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
243 |
fun ga s dn = PureThy.get_thm thy (dn ^ "." ^ s); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
244 |
fun gts s dn = PureThy.get_thms thy (dn ^ "." ^ s); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
245 |
in |
35597
e4331b99b03f
introduce notion of 'decisive' deflations; use them to simplify proof script for rule 'finites'
huffman
parents:
35590
diff
changeset
|
246 |
val axs_rep_iso = map (ga "rep_iso") dnames; |
e4331b99b03f
introduce notion of 'decisive' deflations; use them to simplify proof script for rule 'finites'
huffman
parents:
35590
diff
changeset
|
247 |
val axs_abs_iso = map (ga "abs_iso") dnames; |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
248 |
val exhausts = map (ga "exhaust" ) dnames; |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
249 |
val con_rews = maps (gts "con_rews" ) dnames; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
250 |
end; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
251 |
|
35662
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
252 |
val {take_consts, ...} = take_info; |
35659 | 253 |
val {take_0_thms, take_Suc_thms, chain_take_thms, ...} = take_info; |
35660 | 254 |
val {lub_take_thms, finite_defs, reach_thms, ...} = take_info; |
35661
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
255 |
val {take_induct_thms, ...} = take_info; |
35658 | 256 |
|
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
257 |
fun one_con p (con, args) = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
258 |
let |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
259 |
val P_names = map P_name (1 upto (length dnames)); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
260 |
val vns = Name.variant_list P_names (map vname args); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
261 |
val nonlazy_vns = map snd (filter_out (is_lazy o fst) (args ~~ vns)); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
262 |
fun ind_hyp arg = %:(P_name (1 + rec_of arg)) $ bound_arg args arg; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
263 |
val t1 = mk_trp (%:p $ con_app2 con (bound_arg args) args); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
264 |
val t2 = lift ind_hyp (filter is_rec args, t1); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
265 |
val t3 = lift_defined (bound_arg vns) (nonlazy_vns, t2); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
266 |
in Library.foldr mk_All (vns, t3) end; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
267 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
268 |
fun one_eq ((p, cons), concl) = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
269 |
mk_trp (%:p $ UU) ===> Logic.list_implies (map (one_con p) cons, concl); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
270 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
271 |
fun ind_term concf = Library.foldr one_eq |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
272 |
(mapn (fn n => fn x => (P_name n, x)) 1 conss, |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
273 |
mk_trp (foldr1 mk_conj (mapn concf 1 dnames))); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
274 |
val take_ss = HOL_ss addsimps (@{thm Rep_CFun_strict1} :: take_rews); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
275 |
fun quant_tac ctxt i = EVERY |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
276 |
(mapn (fn n => fn _ => res_inst_tac ctxt [(("x", 0), x_name n)] spec i) 1 dnames); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
277 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
278 |
fun ind_prems_tac prems = EVERY |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
279 |
(maps (fn cons => |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
280 |
(resolve_tac prems 1 :: |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
281 |
maps (fn (_,args) => |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
282 |
resolve_tac prems 1 :: |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
283 |
map (K(atac 1)) (nonlazy args) @ |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
284 |
map (K(atac 1)) (filter is_rec args)) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
285 |
cons)) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
286 |
conss); |
36837 | 287 |
local |
288 |
fun rec_to ns lazy_rec (n,cons) = forall (exists (fn arg => |
|
36692
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents:
36610
diff
changeset
|
289 |
is_rec arg andalso not (member (op =) ns (rec_of arg)) andalso |
36837 | 290 |
((rec_of arg = n andalso not (lazy_rec orelse is_lazy arg)) orelse |
291 |
rec_of arg <> n andalso rec_to (rec_of arg::ns) |
|
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
292 |
(lazy_rec orelse is_lazy arg) (n, (List.nth(conss,rec_of arg)))) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
293 |
) o snd) cons; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
294 |
fun warn (n,cons) = |
36837 | 295 |
if rec_to [] false (n,cons) |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
296 |
then (warning ("domain "^List.nth(dnames,n)^" is empty!"); true) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
297 |
else false; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
298 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
299 |
in |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
300 |
val n__eqs = mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
301 |
val is_emptys = map warn n__eqs; |
35661
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
302 |
val is_finite = #is_finite take_info; |
35601
50ba5010b876
print message when finiteness of domain definition is detected
huffman
parents:
35599
diff
changeset
|
303 |
val _ = if is_finite |
35774 | 304 |
then message ("Proving finiteness rule for domain "^comp_dname^" ...") |
35601
50ba5010b876
print message when finiteness of domain definition is detected
huffman
parents:
35599
diff
changeset
|
305 |
else (); |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
306 |
end; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
307 |
val _ = trace " Proving finite_ind..."; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
308 |
val finite_ind = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
309 |
let |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
310 |
fun concf n dn = %:(P_name n) $ (dc_take dn $ %:"n" `%(x_name n)); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
311 |
val goal = ind_term concf; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
312 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
313 |
fun tacf {prems, context} = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
314 |
let |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
315 |
val tacs1 = [ |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
316 |
quant_tac context 1, |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
317 |
simp_tac HOL_ss 1, |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
318 |
InductTacs.induct_tac context [[SOME "n"]] 1, |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
319 |
simp_tac (take_ss addsimps prems) 1, |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
320 |
TRY (safe_tac HOL_cs)]; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
321 |
fun arg_tac arg = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
322 |
(* FIXME! case_UU_tac *) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
323 |
case_UU_tac context (prems @ con_rews) 1 |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
324 |
(List.nth (dnames, rec_of arg) ^ "_take n$" ^ vname arg); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
325 |
fun con_tacs (con, args) = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
326 |
asm_simp_tac take_ss 1 :: |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
327 |
map arg_tac (filter is_nonlazy_rec args) @ |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
328 |
[resolve_tac prems 1] @ |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
329 |
map (K (atac 1)) (nonlazy args) @ |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
330 |
map (K (etac spec 1)) (filter is_rec args); |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
331 |
fun cases_tacs (cons, exhaust) = |
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
332 |
res_inst_tac context [(("y", 0), "x")] exhaust 1 :: |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
333 |
asm_simp_tac (take_ss addsimps prems) 1 :: |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
334 |
maps con_tacs cons; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
335 |
in |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
336 |
tacs1 @ maps cases_tacs (conss ~~ exhausts) |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
337 |
end; |
35663 | 338 |
in pg'' thy [] goal tacf end; |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
339 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
340 |
(* ----- theorems concerning finiteness and induction ----------------------- *) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
341 |
|
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36160
diff
changeset
|
342 |
val global_ctxt = ProofContext.init_global thy; |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
343 |
|
35661
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
344 |
val _ = trace " Proving ind..."; |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
345 |
val ind = |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
346 |
if is_finite |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
347 |
then (* finite case *) |
35597
e4331b99b03f
introduce notion of 'decisive' deflations; use them to simplify proof script for rule 'finites'
huffman
parents:
35590
diff
changeset
|
348 |
let |
35661
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
349 |
fun concf n dn = %:(P_name n) $ %:(x_name n); |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
350 |
fun tacf {prems, context} = |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
351 |
let |
35661
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
352 |
fun finite_tacs (take_induct, fin_ind) = [ |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
353 |
rtac take_induct 1, |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
354 |
rtac fin_ind 1, |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
355 |
ind_prems_tac prems]; |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
356 |
in |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
357 |
TRY (safe_tac HOL_cs) :: |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
358 |
maps finite_tacs (take_induct_thms ~~ atomize global_ctxt finite_ind) |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
359 |
end; |
ede27eb8e94b
don't generate rule foo.finites for non-flat domains; use take_induct rule to prove induction rule
huffman
parents:
35660
diff
changeset
|
360 |
in pg'' thy [] (ind_term concf) tacf end |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
361 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
362 |
else (* infinite case *) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
363 |
let |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
364 |
val goal = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
365 |
let |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
366 |
fun one_adm n _ = mk_trp (mk_adm (%:(P_name n))); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
367 |
fun concf n dn = %:(P_name n) $ %:(x_name n); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
368 |
in Logic.list_implies (mapn one_adm 1 dnames, ind_term concf) end; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
369 |
val cont_rules = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
370 |
@{thms cont_id cont_const cont2cont_Rep_CFun |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
371 |
cont2cont_fst cont2cont_snd}; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
372 |
val subgoal = |
35662
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
373 |
let |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
374 |
val Ts = map (Type o fst) eqs; |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
375 |
val P_names = Datatype_Prop.indexify_names (map (K "P") dnames); |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
376 |
val x_names = Datatype_Prop.indexify_names (map (K "x") dnames); |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
377 |
val P_types = map (fn T => T --> HOLogic.boolT) Ts; |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
378 |
val Ps = map Free (P_names ~~ P_types); |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
379 |
val xs = map Free (x_names ~~ Ts); |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
380 |
val n = Free ("n", HOLogic.natT); |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
381 |
val goals = |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
382 |
map (fn ((P,t),x) => P $ HOLCF_Library.mk_capply (t $ n, x)) |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
383 |
(Ps ~~ take_consts ~~ xs); |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
384 |
in |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
385 |
HOLogic.mk_Trueprop |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
386 |
(HOLogic.mk_all ("n", HOLogic.natT, foldr1 HOLogic.mk_conj goals)) |
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
387 |
end; |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
388 |
fun tacf {prems, context} = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
389 |
let |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
390 |
val subtac = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
391 |
EVERY [rtac allI 1, rtac finite_ind 1, ind_prems_tac prems]; |
35662
44d7aafdddb9
construct fully typed goal in proof of induction rule
huffman
parents:
35661
diff
changeset
|
392 |
val subthm = Goal.prove context [] [] subgoal (K subtac); |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
393 |
in |
35660 | 394 |
map (fn ax_reach => rtac (ax_reach RS subst) 1) reach_thms @ [ |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
395 |
cut_facts_tac (subthm :: take (length dnames) prems) 1, |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
396 |
REPEAT (rtac @{thm conjI} 1 ORELSE |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
397 |
EVERY [etac @{thm admD [OF _ ch2ch_Rep_CFunL]} 1, |
35659 | 398 |
resolve_tac chain_take_thms 1, |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
399 |
asm_simp_tac HOL_basic_ss 1]) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
400 |
] |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
401 |
end; |
35663 | 402 |
in pg'' thy [] goal tacf end; |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
403 |
|
35630
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
404 |
val case_ns = |
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
405 |
let |
35782 | 406 |
val adms = |
407 |
if is_finite then [] else |
|
408 |
if length dnames = 1 then ["adm"] else |
|
409 |
map (fn s => "adm_" ^ Long_Name.base_name s) dnames; |
|
35630
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
410 |
val bottoms = |
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
411 |
if length dnames = 1 then ["bottom"] else |
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
412 |
map (fn s => "bottom_" ^ Long_Name.base_name s) dnames; |
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
413 |
fun one_eq bot (_,cons) = |
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
414 |
bot :: map (fn (c,_) => Long_Name.base_name c) cons; |
35782 | 415 |
in adms @ flat (map2 one_eq bottoms eqs) end; |
35630
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
416 |
|
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36160
diff
changeset
|
417 |
val inducts = Project_Rule.projections (ProofContext.init_global thy) ind; |
35630
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
418 |
fun ind_rule (dname, rule) = |
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
419 |
((Binding.empty, [rule]), |
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
420 |
[Rule_Cases.case_names case_ns, Induct.induct_type dname]); |
8e562d56d404
add case_names attribute to casedist and ind rules
huffman
parents:
35601
diff
changeset
|
421 |
|
35774 | 422 |
in |
423 |
thy |
|
424 |
|> snd o PureThy.add_thmss [ |
|
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
425 |
((Binding.qualified true "finite_induct" comp_dbind, [finite_ind]), []), |
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
426 |
((Binding.qualified true "induct" comp_dbind, [ind] ), [])] |
35774 | 427 |
|> (snd o PureThy.add_thmss (map ind_rule (dnames ~~ inducts))) |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
428 |
end; (* prove_induction *) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
429 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
430 |
(******************************************************************************) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
431 |
(************************ bisimulation and coinduction ************************) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
432 |
(******************************************************************************) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
433 |
|
35574
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
434 |
fun prove_coinduction |
35774 | 435 |
(comp_dbind : binding, eqs : eq list) |
35574
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
436 |
(take_lemmas : thm list) |
35599
20670f5564e9
skip coinduction proofs for indirect-recursive domain definitions
huffman
parents:
35597
diff
changeset
|
437 |
(thy : theory) : theory = |
23152 | 438 |
let |
27232 | 439 |
|
23152 | 440 |
val dnames = map (fst o fst) eqs; |
35774 | 441 |
val comp_dname = Sign.full_name thy comp_dbind; |
35574
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
442 |
fun dc_take dn = %%:(dn^"_take"); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
443 |
val x_name = idx_name dnames "x"; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
444 |
val n_eqs = length eqs; |
23152 | 445 |
|
35574
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
446 |
val take_rews = |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
447 |
maps (fn dn => PureThy.get_thms thy (dn ^ ".take_rews")) dnames; |
35497 | 448 |
|
449 |
(* ----- define bisimulation predicate -------------------------------------- *) |
|
450 |
||
451 |
local |
|
452 |
open HOLCF_Library |
|
453 |
val dtypes = map (Type o fst) eqs; |
|
454 |
val relprod = mk_tupleT (map (fn tp => tp --> tp --> boolT) dtypes); |
|
35774 | 455 |
val bisim_bind = Binding.suffix_name "_bisim" comp_dbind; |
35497 | 456 |
val bisim_type = relprod --> boolT; |
457 |
in |
|
458 |
val (bisim_const, thy) = |
|
459 |
Sign.declare_const ((bisim_bind, bisim_type), NoSyn) thy; |
|
460 |
end; |
|
461 |
||
462 |
local |
|
463 |
||
464 |
fun legacy_infer_term thy t = |
|
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36160
diff
changeset
|
465 |
singleton (Syntax.check_terms (ProofContext.init_global thy)) (intern_term thy t); |
35497 | 466 |
fun legacy_infer_prop thy t = legacy_infer_term thy (TypeInfer.constrain propT t); |
467 |
fun infer_props thy = map (apsnd (legacy_infer_prop thy)); |
|
468 |
fun add_defs_i x = PureThy.add_defs false (map Thm.no_attributes x); |
|
469 |
fun add_defs_infer defs thy = add_defs_i (infer_props thy defs) thy; |
|
470 |
||
35521 | 471 |
fun one_con (con, args) = |
35497 | 472 |
let |
473 |
val nonrec_args = filter_out is_rec args; |
|
474 |
val rec_args = filter is_rec args; |
|
475 |
val recs_cnt = length rec_args; |
|
476 |
val allargs = nonrec_args @ rec_args |
|
477 |
@ map (upd_vname (fn s=> s^"'")) rec_args; |
|
478 |
val allvns = map vname allargs; |
|
479 |
fun vname_arg s arg = if is_rec arg then vname arg^s else vname arg; |
|
480 |
val vns1 = map (vname_arg "" ) args; |
|
481 |
val vns2 = map (vname_arg "'") args; |
|
482 |
val allargs_cnt = length nonrec_args + 2*recs_cnt; |
|
483 |
val rec_idxs = (recs_cnt-1) downto 0; |
|
484 |
val nonlazy_idxs = map snd (filter_out (fn (arg,_) => is_lazy arg) |
|
485 |
(allargs~~((allargs_cnt-1) downto 0))); |
|
486 |
fun rel_app i ra = proj (Bound(allargs_cnt+2)) eqs (rec_of ra) $ |
|
487 |
Bound (2*recs_cnt-i) $ Bound (recs_cnt-i); |
|
488 |
val capps = |
|
489 |
List.foldr |
|
490 |
mk_conj |
|
491 |
(mk_conj( |
|
492 |
Bound(allargs_cnt+1)===list_ccomb(%%:con,map (bound_arg allvns) vns1), |
|
493 |
Bound(allargs_cnt+0)===list_ccomb(%%:con,map (bound_arg allvns) vns2))) |
|
494 |
(mapn rel_app 1 rec_args); |
|
495 |
in |
|
496 |
List.foldr |
|
497 |
mk_ex |
|
498 |
(Library.foldr mk_conj |
|
499 |
(map (defined o Bound) nonlazy_idxs,capps)) allvns |
|
500 |
end; |
|
501 |
fun one_comp n (_,cons) = |
|
502 |
mk_all (x_name(n+1), |
|
503 |
mk_all (x_name(n+1)^"'", |
|
504 |
mk_imp (proj (Bound 2) eqs n $ Bound 1 $ Bound 0, |
|
505 |
foldr1 mk_disj (mk_conj(Bound 1 === UU,Bound 0 === UU) |
|
506 |
::map one_con cons)))); |
|
507 |
val bisim_eqn = |
|
508 |
%%:(comp_dname^"_bisim") == |
|
509 |
mk_lam("R", foldr1 mk_conj (mapn one_comp 0 eqs)); |
|
510 |
||
511 |
in |
|
35774 | 512 |
val (ax_bisim_def, thy) = |
513 |
yield_singleton add_defs_infer |
|
514 |
(Binding.qualified true "bisim_def" comp_dbind, bisim_eqn) thy; |
|
35497 | 515 |
end; (* local *) |
516 |
||
35574
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
517 |
(* ----- theorem concerning coinduction ------------------------------------- *) |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
518 |
|
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
519 |
local |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
520 |
val pg = pg' thy; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
521 |
val xs = mapn (fn n => K (x_name n)) 1 dnames; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
522 |
fun bnd_arg n i = Bound(2*(n_eqs - n)-i-1); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
523 |
val take_ss = HOL_ss addsimps (@{thm Rep_CFun_strict1} :: take_rews); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
524 |
val sproj = prj (fn s => K("fst("^s^")")) (fn s => K("snd("^s^")")); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
525 |
val _ = trace " Proving coind_lemma..."; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
526 |
val coind_lemma = |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
527 |
let |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
528 |
fun mk_prj n _ = proj (%:"R") eqs n $ bnd_arg n 0 $ bnd_arg n 1; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
529 |
fun mk_eqn n dn = |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
530 |
(dc_take dn $ %:"n" ` bnd_arg n 0) === |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
531 |
(dc_take dn $ %:"n" ` bnd_arg n 1); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
532 |
fun mk_all2 (x,t) = mk_all (x, mk_all (x^"'", t)); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
533 |
val goal = |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
534 |
mk_trp (mk_imp (%%:(comp_dname^"_bisim") $ %:"R", |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
535 |
Library.foldr mk_all2 (xs, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
536 |
Library.foldr mk_imp (mapn mk_prj 0 dnames, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
537 |
foldr1 mk_conj (mapn mk_eqn 0 dnames))))); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
538 |
fun x_tacs ctxt n x = [ |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
539 |
rotate_tac (n+1) 1, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
540 |
etac all2E 1, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
541 |
eres_inst_tac ctxt [(("P", 1), sproj "R" eqs n^" "^x^" "^x^"'")] (mp RS disjE) 1, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
542 |
TRY (safe_tac HOL_cs), |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
543 |
REPEAT (CHANGED (asm_simp_tac take_ss 1))]; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
544 |
fun tacs ctxt = [ |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
545 |
rtac impI 1, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
546 |
InductTacs.induct_tac ctxt [[SOME "n"]] 1, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
547 |
simp_tac take_ss 1, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
548 |
safe_tac HOL_cs] @ |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
549 |
flat (mapn (x_tacs ctxt) 0 xs); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
550 |
in pg [ax_bisim_def] goal tacs end; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
551 |
in |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
552 |
val _ = trace " Proving coind..."; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
553 |
val coind = |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
554 |
let |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
555 |
fun mk_prj n x = mk_trp (proj (%:"R") eqs n $ %:x $ %:(x^"'")); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
556 |
fun mk_eqn x = %:x === %:(x^"'"); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
557 |
val goal = |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
558 |
mk_trp (%%:(comp_dname^"_bisim") $ %:"R") ===> |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
559 |
Logic.list_implies (mapn mk_prj 0 xs, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
560 |
mk_trp (foldr1 mk_conj (map mk_eqn xs))); |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
561 |
val tacs = |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
562 |
TRY (safe_tac HOL_cs) :: |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
563 |
maps (fn take_lemma => [ |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
564 |
rtac take_lemma 1, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
565 |
cut_facts_tac [coind_lemma] 1, |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
566 |
fast_tac HOL_cs 1]) |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
567 |
take_lemmas; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
568 |
in pg [] goal (K tacs) end; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
569 |
end; (* local *) |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
570 |
|
35774 | 571 |
in thy |> snd o PureThy.add_thmss |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
572 |
[((Binding.qualified true "coinduct" comp_dbind, [coind]), [])] |
35599
20670f5564e9
skip coinduction proofs for indirect-recursive domain definitions
huffman
parents:
35597
diff
changeset
|
573 |
end; (* let *) |
35574
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
574 |
|
35657
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
575 |
fun comp_theorems |
35774 | 576 |
(comp_dbind : binding, eqs : eq list) |
35659 | 577 |
(take_info : Domain_Take_Proofs.take_induct_info) |
35657
0537c34c6067
pass take_induct_info as an argument to comp_theorems
huffman
parents:
35654
diff
changeset
|
578 |
(thy : theory) = |
35574
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
579 |
let |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
580 |
val map_tab = Domain_Take_Proofs.get_map_tab thy; |
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
581 |
|
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
582 |
val dnames = map (fst o fst) eqs; |
35774 | 583 |
val comp_dname = Sign.full_name thy comp_dbind; |
35574
ee5df989b7c4
move coinduction-related stuff into function prove_coindunction
huffman
parents:
35560
diff
changeset
|
584 |
|
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
585 |
(* ----- getting the composite axiom and definitions ------------------------ *) |
23152 | 586 |
|
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
587 |
(* Test for indirect recursion *) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
588 |
local |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
589 |
fun indirect_arg arg = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
590 |
rec_of arg = ~1 andalso Datatype_Aux.is_rec_type (dtyp_of arg); |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
591 |
fun indirect_con (_, args) = exists indirect_arg args; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
592 |
fun indirect_eq (_, cons) = exists indirect_con cons; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
593 |
in |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
594 |
val is_indirect = exists indirect_eq eqs; |
35599
20670f5564e9
skip coinduction proofs for indirect-recursive domain definitions
huffman
parents:
35597
diff
changeset
|
595 |
val _ = |
20670f5564e9
skip coinduction proofs for indirect-recursive domain definitions
huffman
parents:
35597
diff
changeset
|
596 |
if is_indirect |
20670f5564e9
skip coinduction proofs for indirect-recursive domain definitions
huffman
parents:
35597
diff
changeset
|
597 |
then message "Indirect recursion detected, skipping proofs of (co)induction rules" |
20670f5564e9
skip coinduction proofs for indirect-recursive domain definitions
huffman
parents:
35597
diff
changeset
|
598 |
else message ("Proving induction properties of domain "^comp_dname^" ..."); |
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
599 |
end; |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
600 |
|
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
601 |
(* theorems about take *) |
23152 | 602 |
|
35659 | 603 |
val take_lemmas = #take_lemma_thms take_info; |
23152 | 604 |
|
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
605 |
val take_rews = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
606 |
maps (fn dn => PureThy.get_thms thy (dn ^ ".take_rews")) dnames; |
23152 | 607 |
|
35585
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
608 |
(* prove induction rules, unless definition is indirect recursive *) |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
609 |
val thy = |
555f26f00e47
skip proof of induction rule for indirect-recursive domain definitions
huffman
parents:
35574
diff
changeset
|
610 |
if is_indirect then thy else |
35774 | 611 |
prove_induction (comp_dbind, eqs) take_rews take_info thy; |
23152 | 612 |
|
35599
20670f5564e9
skip coinduction proofs for indirect-recursive domain definitions
huffman
parents:
35597
diff
changeset
|
613 |
val thy = |
20670f5564e9
skip coinduction proofs for indirect-recursive domain definitions
huffman
parents:
35597
diff
changeset
|
614 |
if is_indirect then thy else |
35774 | 615 |
prove_coinduction (comp_dbind, eqs) take_lemmas thy; |
23152 | 616 |
|
35642
f478d5a9d238
generate separate qualified theorem name for each type's reach and take_lemma
huffman
parents:
35630
diff
changeset
|
617 |
in |
f478d5a9d238
generate separate qualified theorem name for each type's reach and take_lemma
huffman
parents:
35630
diff
changeset
|
618 |
(take_rews, thy) |
23152 | 619 |
end; (* let *) |
620 |
end; (* struct *) |