src/HOL/Tools/TFL/post.ML
changeset 49340 25fc6e0da459
parent 44890 22f665a2e91c
child 51717 9e7d1c139569
equal deleted inserted replaced
49339:d1fcb4de8349 49340:25fc6e0da459
   164 users specification of the recursive function. *)
   164 users specification of the recursive function. *)
   165 local
   165 local
   166   fun get_related_thms i = 
   166   fun get_related_thms i = 
   167       map_filter ((fn (r,x) => if x = i then SOME r else NONE));
   167       map_filter ((fn (r,x) => if x = i then SOME r else NONE));
   168 
   168 
   169   fun solve_eq (th, [], i) =  error "derive_init_eqs: missing rules"
   169   fun solve_eq _ (th, [], i) =  error "derive_init_eqs: missing rules"
   170     | solve_eq (th, [a], i) = [(a, i)]
   170     | solve_eq _ (th, [a], i) = [(a, i)]
   171     | solve_eq (th, splitths, i) =
   171     | solve_eq ctxt (th, splitths, i) =
   172       (writeln "Proving unsplit equation...";
   172       (writeln "Proving unsplit equation...";
   173       [((Drule.export_without_context o Object_Logic.rulify_no_asm)
   173       [((Drule.export_without_context o Object_Logic.rulify_no_asm)
   174           (CaseSplit.splitto splitths th), i)])
   174           (CaseSplit.splitto ctxt splitths th), i)])
   175       handle ERROR s => 
   175       handle ERROR s => 
   176              (warning ("recdef (solve_eq): " ^ s); map (fn x => (x,i)) splitths);
   176              (warning ("recdef (solve_eq): " ^ s); map (fn x => (x,i)) splitths);
   177 in
   177 in
   178 fun derive_init_eqs thy rules eqs =
   178 fun derive_init_eqs ctxt rules eqs =
   179   map (Thm.trivial o Thm.cterm_of thy o HOLogic.mk_Trueprop) eqs
   179   map (Thm.trivial o Thm.cterm_of (Proof_Context.theory_of ctxt) o HOLogic.mk_Trueprop) eqs
   180   |> map_index (fn (i, e) => solve_eq (e, (get_related_thms i rules), i))
   180   |> map_index (fn (i, e) => solve_eq ctxt (e, (get_related_thms i rules), i))
   181   |> flat;
   181   |> flat;
   182 end;
   182 end;
   183 
   183 
   184 
   184 
   185 (*---------------------------------------------------------------------------
   185 (*---------------------------------------------------------------------------
   190       val (thy, def) = Prim.wfrec_definition0 thy fid R functional
   190       val (thy, def) = Prim.wfrec_definition0 thy fid R functional
   191       val ctxt' = Proof_Context.transfer thy ctxt
   191       val ctxt' = Proof_Context.transfer thy ctxt
   192       val (lhs, _) = Logic.dest_equals (prop_of def)
   192       val (lhs, _) = Logic.dest_equals (prop_of def)
   193       val {induct, rules, tcs} = simplify_defn strict thy ctxt' congs wfs fid pats def
   193       val {induct, rules, tcs} = simplify_defn strict thy ctxt' congs wfs fid pats def
   194       val rules' = 
   194       val rules' = 
   195           if strict then derive_init_eqs thy rules eqs
   195           if strict then derive_init_eqs ctxt rules eqs
   196           else rules
   196           else rules
   197   in ({lhs = lhs, rules = rules', induct = induct, tcs = tcs}, thy) end;
   197   in ({lhs = lhs, rules = rules', induct = induct, tcs = tcs}, thy) end;
   198 
   198 
   199 fun define strict ctxt congs wfs fid R seqs thy =
   199 fun define strict ctxt congs wfs fid R seqs thy =
   200   define_i strict ctxt congs wfs fid
   200   define_i strict ctxt congs wfs fid