19 fun subsets i j = |
19 fun subsets i j = |
20 if i <= j then |
20 if i <= j then |
21 let val is = subsets (i+1) j |
21 let val is = subsets (i+1) j |
22 in map (fn ks => i::ks) is @ is end |
22 in map (fn ks => i::ks) is @ is end |
23 else [[]]; |
23 else [[]]; |
24 |
|
25 fun forall_intr_prf (t, prf) = |
|
26 let val (a, T) = (case t of Var ((a, _), T) => (a, T) | Free p => p) |
|
27 in Abst (a, SOME T, Proofterm.prf_abstract_over t prf) end; |
|
28 |
24 |
29 fun prf_of thm = |
25 fun prf_of thm = |
30 Reconstruct.reconstruct_proof (Thm.theory_of_thm thm) (Thm.prop_of thm) (Thm.proof_of thm); |
26 Reconstruct.reconstruct_proof (Thm.theory_of_thm thm) (Thm.prop_of thm) (Thm.proof_of thm); |
31 |
27 |
32 fun is_unit t = snd (strip_type (fastype_of t)) = HOLogic.unitT; |
28 fun is_unit t = snd (strip_type (fastype_of t)) = HOLogic.unitT; |
128 (Binding.qualified_name (space_implode "_" (ind_name :: vs @ ["correctness"])), thm) |
124 (Binding.qualified_name (space_implode "_" (ind_name :: vs @ ["correctness"])), thm) |
129 ||> Sign.restore_naming thy; |
125 ||> Sign.restore_naming thy; |
130 |
126 |
131 val ivs = rev (Term.add_vars (Logic.varify_global (Datatype_Prop.make_ind [descr] sorts)) []); |
127 val ivs = rev (Term.add_vars (Logic.varify_global (Datatype_Prop.make_ind [descr] sorts)) []); |
132 val rvs = rev (Thm.fold_terms Term.add_vars thm' []); |
128 val rvs = rev (Thm.fold_terms Term.add_vars thm' []); |
133 val ivs1 = map Var (filter_out (fn (_, T) => (* FIXME set (!??) *) |
129 val ivs1 = map Var (filter_out (fn (_, T) => |
134 member (op =) [@{type_abbrev set}, @{type_name bool}] (tname_of (body_type T))) ivs); |
130 @{type_name bool} = tname_of (body_type T)) ivs); |
135 val ivs2 = map (fn (ixn, _) => Var (ixn, the (AList.lookup (op =) rvs ixn))) ivs; |
131 val ivs2 = map (fn (ixn, _) => Var (ixn, the (AList.lookup (op =) rvs ixn))) ivs; |
136 |
132 |
137 val prf = |
133 val prf = |
138 List.foldr forall_intr_prf |
134 Extraction.abs_corr_shyps thy' induct vs ivs2 |
139 (fold_rev (fn (f, p) => fn prf => |
135 (fold_rev (fn (f, p) => fn prf => |
140 (case head_of (strip_abs_body f) of |
136 (case head_of (strip_abs_body f) of |
141 Free (s, T) => |
137 Free (s, T) => |
142 let val T' = Logic.varifyT_global T |
138 let val T' = Logic.varifyT_global T |
143 in Abst (s, SOME T', Proofterm.prf_abstract_over |
139 in Abst (s, SOME T', Proofterm.prf_abstract_over |
144 (Var ((s, 0), T')) (AbsP ("H", SOME p, prf))) |
140 (Var ((s, 0), T')) (AbsP ("H", SOME p, prf))) |
145 end |
141 end |
146 | _ => AbsP ("H", SOME p, prf))) |
142 | _ => AbsP ("H", SOME p, prf))) |
147 (rec_fns ~~ prems_of thm) |
143 (rec_fns ~~ prems_of thm) |
148 (Proofterm.proof_combP (prf_of thm', map PBound (length prems - 1 downto 0)))) ivs2; |
144 (Proofterm.proof_combP (prf_of thm', map PBound (length prems - 1 downto 0)))); |
149 |
145 |
150 val r' = |
146 val r' = |
151 if null is then r |
147 if null is then r |
152 else Logic.varify_global (fold_rev lambda |
148 else Logic.varify_global (fold_rev lambda |
153 (map Logic.unvarify_global ivs1 @ filter_out is_unit |
149 (map Logic.unvarify_global ivs1 @ filter_out is_unit |
196 |> Sign.root_path |
192 |> Sign.root_path |
197 |> PureThy.store_thm (Binding.qualified_name (exh_name ^ "_P_correctness"), thm) |
193 |> PureThy.store_thm (Binding.qualified_name (exh_name ^ "_P_correctness"), thm) |
198 ||> Sign.restore_naming thy; |
194 ||> Sign.restore_naming thy; |
199 |
195 |
200 val P = Var (("P", 0), rT' --> HOLogic.boolT); |
196 val P = Var (("P", 0), rT' --> HOLogic.boolT); |
201 val prf = forall_intr_prf (y, forall_intr_prf (P, |
197 val prf = Extraction.abs_corr_shyps thy' exhaust ["P"] [y, P] |
202 fold_rev (fn (p, r) => fn prf => |
198 (fold_rev (fn (p, r) => fn prf => |
203 forall_intr_prf (Logic.varify_global r, AbsP ("H", SOME (Logic.varify_global p), prf))) |
199 Proofterm.forall_intr_proof' (Logic.varify_global r) |
|
200 (AbsP ("H", SOME (Logic.varify_global p), prf))) |
204 (prems ~~ rs) |
201 (prems ~~ rs) |
205 (Proofterm.proof_combP (prf_of thm', map PBound (length prems - 1 downto 0))))); |
202 (Proofterm.proof_combP (prf_of thm', map PBound (length prems - 1 downto 0)))); |
|
203 val prf' = Extraction.abs_corr_shyps thy' exhaust [] |
|
204 (map Var (Term.add_vars (prop_of exhaust) [])) (prf_of exhaust); |
206 val r' = Logic.varify_global (Abs ("y", T, |
205 val r' = Logic.varify_global (Abs ("y", T, |
207 list_abs (map dest_Free rs, list_comb (r, |
206 list_abs (map dest_Free rs, list_comb (r, |
208 map Bound ((length rs - 1 downto 0) @ [length rs]))))); |
207 map Bound ((length rs - 1 downto 0) @ [length rs]))))); |
209 |
208 |
210 in Extraction.add_realizers_i |
209 in Extraction.add_realizers_i |
211 [(exh_name, (["P"], r', prf)), |
210 [(exh_name, (["P"], r', prf)), |
212 (exh_name, ([], Extraction.nullt, prf_of exhaust))] thy' |
211 (exh_name, ([], Extraction.nullt, prf'))] thy' |
213 end; |
212 end; |
214 |
213 |
215 fun add_dt_realizers config names thy = |
214 fun add_dt_realizers config names thy = |
216 if ! Proofterm.proofs < 2 then thy |
215 if ! Proofterm.proofs < 2 then thy |
217 else let |
216 else let |