src/HOL/Tools/Function/function_core.ML
changeset 33348 bb65583ab70d
parent 33278 ba9f52f56356
child 33349 634376549164
equal deleted inserted replaced
33347:6748bd742d7a 33348:bb65583ab70d
   449                           |> implies_intr (cprop_of complete)
   449                           |> implies_intr (cprop_of complete)
   450     in
   450     in
   451       (goalstate, values)
   451       (goalstate, values)
   452     end
   452     end
   453 
   453 
       
   454 (* wrapper -- restores quantifiers in rule specifications *)
       
   455 fun inductive_def (binding as ((R, T), _)) intrs lthy =
       
   456   let
       
   457     val ({intrs = intrs_gen, elims = [elim_gen], preds = [ Rdef ], induct, ...}, lthy) =
       
   458       lthy
       
   459       |> LocalTheory.conceal
       
   460       |> Inductive.add_inductive_i
       
   461           {quiet_mode = false,
       
   462             verbose = ! Toplevel.debug,
       
   463             kind = Thm.internalK,
       
   464             alt_name = Binding.empty,
       
   465             coind = false,
       
   466             no_elim = false,
       
   467             no_ind = false,
       
   468             skip_mono = true,
       
   469             fork_mono = false}
       
   470           [binding] (* relation *)
       
   471           [] (* no parameters *)
       
   472           (map (fn t => (Attrib.empty_binding, t)) intrs) (* intro rules *)
       
   473           [] (* no special monos *)
       
   474       ||> LocalTheory.restore_naming lthy
       
   475 
       
   476     val cert = cterm_of (ProofContext.theory_of lthy)
       
   477     fun requantify orig_intro thm =
       
   478       let
       
   479         val (qs, t) = dest_all_all orig_intro
       
   480         val frees = frees_in_term lthy t |> remove (op =) (Binding.name_of R, T)
       
   481         val vars = Term.add_vars (prop_of thm) [] |> rev
       
   482         val varmap = AList.lookup (op =) (frees ~~ map fst vars)
       
   483           #> the_default ("",0)
       
   484       in
       
   485         fold_rev (fn Free (n, T) =>
       
   486           forall_intr_rename (n, cert (Var (varmap (n, T), T)))) qs thm
       
   487       end
       
   488   in
       
   489       ((map2 requantify intrs intrs_gen, Rdef, forall_intr_vars elim_gen, induct), lthy)
       
   490   end
       
   491 
   454 
   492 
   455 fun define_graph Gname fvar domT ranT clauses RCss lthy =
   493 fun define_graph Gname fvar domT ranT clauses RCss lthy =
   456     let
   494     let
   457       val GT = domT --> ranT --> boolT
   495       val GT = domT --> ranT --> boolT
   458       val Gvar = Free (the_single (Variable.variant_frees lthy [] [(Gname, GT)]))
   496       val (Gvar as (n, T)) = the_single (Variable.variant_frees lthy [] [(Gname, GT)])
   459 
   497 
   460       fun mk_GIntro (ClauseContext {qs, gs, lhs, rhs, ...}) RCs =
   498       fun mk_GIntro (ClauseContext {qs, gs, lhs, rhs, ...}) RCs =
   461           let
   499           let
   462             fun mk_h_assm (rcfix, rcassm, rcarg) =
   500             fun mk_h_assm (rcfix, rcassm, rcarg) =
   463                 HOLogic.mk_Trueprop (Gvar $ rcarg $ (fvar $ rcarg))
   501                 HOLogic.mk_Trueprop (Free Gvar $ rcarg $ (fvar $ rcarg))
   464                           |> fold_rev (curry Logic.mk_implies o prop_of) rcassm
   502                           |> fold_rev (curry Logic.mk_implies o prop_of) rcassm
   465                           |> fold_rev (Logic.all o Free) rcfix
   503                           |> fold_rev (Logic.all o Free) rcfix
   466           in
   504           in
   467             HOLogic.mk_Trueprop (Gvar $ lhs $ rhs)
   505             HOLogic.mk_Trueprop (Free Gvar $ lhs $ rhs)
   468                       |> fold_rev (curry Logic.mk_implies o mk_h_assm) RCs
   506                       |> fold_rev (curry Logic.mk_implies o mk_h_assm) RCs
   469                       |> fold_rev (curry Logic.mk_implies) gs
   507                       |> fold_rev (curry Logic.mk_implies) gs
   470                       |> fold_rev Logic.all (fvar :: qs)
   508                       |> fold_rev Logic.all (fvar :: qs)
   471           end
   509           end
   472 
   510 
   473       val G_intros = map2 mk_GIntro clauses RCss
   511       val G_intros = map2 mk_GIntro clauses RCss
   474 
   512 
   475       val (GIntro_thms, (G, G_elim, G_induct, lthy)) =
   513       val ((GIntro_thms, G, G_elim, G_induct), lthy) =
   476           Function_Inductive_Wrap.inductive_def G_intros ((dest_Free Gvar, NoSyn), lthy)
   514         inductive_def ((Binding.name n, T), NoSyn) G_intros lthy
   477     in
   515     in
   478       ((G, GIntro_thms, G_elim, G_induct), lthy)
   516       ((G, GIntro_thms, G_elim, G_induct), lthy)
   479     end
   517     end
   480 
   518 
   481 
   519 
   498 
   536 
   499 fun define_recursion_relation Rname domT ranT fvar f qglrs clauses RCss lthy =
   537 fun define_recursion_relation Rname domT ranT fvar f qglrs clauses RCss lthy =
   500     let
   538     let
   501 
   539 
   502       val RT = domT --> domT --> boolT
   540       val RT = domT --> domT --> boolT
   503       val Rvar = Free (the_single (Variable.variant_frees lthy [] [(Rname, RT)]))
   541       val (Rvar as (n, T)) = the_single (Variable.variant_frees lthy [] [(Rname, RT)])
   504 
   542 
   505       fun mk_RIntro (ClauseContext {qs, gs, lhs, ...}, (oqs, _, _, _)) (rcfix, rcassm, rcarg) =
   543       fun mk_RIntro (ClauseContext {qs, gs, lhs, ...}, (oqs, _, _, _)) (rcfix, rcassm, rcarg) =
   506           HOLogic.mk_Trueprop (Rvar $ rcarg $ lhs)
   544           HOLogic.mk_Trueprop (Free Rvar $ rcarg $ lhs)
   507                     |> fold_rev (curry Logic.mk_implies o prop_of) rcassm
   545                     |> fold_rev (curry Logic.mk_implies o prop_of) rcassm
   508                     |> fold_rev (curry Logic.mk_implies) gs
   546                     |> fold_rev (curry Logic.mk_implies) gs
   509                     |> fold_rev (Logic.all o Free) rcfix
   547                     |> fold_rev (Logic.all o Free) rcfix
   510                     |> fold_rev mk_forall_rename (map fst oqs ~~ qs)
   548                     |> fold_rev mk_forall_rename (map fst oqs ~~ qs)
   511                     (* "!!qs xs. CS ==> G => (r, lhs) : R" *)
   549                     (* "!!qs xs. CS ==> G => (r, lhs) : R" *)
   512 
   550 
   513       val R_intross = map2 (map o mk_RIntro) (clauses ~~ qglrs) RCss
   551       val R_intross = map2 (map o mk_RIntro) (clauses ~~ qglrs) RCss
   514 
   552 
   515       val (RIntro_thmss, (R, R_elim, _, lthy)) =
   553       val ((RIntro_thms, R, R_elim, _), lthy) =
   516           fold_burrow Function_Inductive_Wrap.inductive_def R_intross ((dest_Free Rvar, NoSyn), lthy)
   554         inductive_def ((Binding.name n, T), NoSyn) (flat R_intross) lthy
   517     in
   555     in
   518       ((R, RIntro_thmss, R_elim), lthy)
   556       ((R, Library.unflat R_intross RIntro_thms, R_elim), lthy)
   519     end
   557     end
   520 
   558 
   521 
   559 
   522 fun fix_globals domT ranT fvar ctxt =
   560 fun fix_globals domT ranT fvar ctxt =
   523     let
   561     let