src/HOL/Tools/Function/function_context_tree.ML
changeset 65418 c821f1f3d92d
parent 61112 e966c311e9a7
child 67649 1e1782c1aedf
equal deleted inserted replaced
65417:fc41a5650fb1 65418:c821f1f3d92d
    14   val add_function_cong : thm -> Context.generic -> Context.generic
    14   val add_function_cong : thm -> Context.generic -> Context.generic
    15 
    15 
    16   val cong_add: attribute
    16   val cong_add: attribute
    17   val cong_del: attribute
    17   val cong_del: attribute
    18 
    18 
    19   val mk_tree: (string * typ) -> term -> Proof.context -> term -> ctx_tree
    19   val mk_tree: term -> term -> Proof.context -> term -> ctx_tree
    20 
    20 
    21   val inst_tree: Proof.context -> term -> term -> ctx_tree -> ctx_tree
    21   val inst_tree: Proof.context -> term -> term -> ctx_tree -> ctx_tree
    22 
    22 
    23   val export_term : ctxt -> term -> term
    23   val export_term : ctxt -> term -> term
    24   val export_thm : Proof.context -> ctxt -> thm -> thm
    24   val export_thm : Proof.context -> ctxt -> thm -> thm
   112 
   112 
   113 fun find_cong_rule ctxt fvar h ((r,dep)::rs) t =
   113 fun find_cong_rule ctxt fvar h ((r,dep)::rs) t =
   114      (let
   114      (let
   115         val thy = Proof_Context.theory_of ctxt
   115         val thy = Proof_Context.theory_of ctxt
   116 
   116 
   117         val tt' = Logic.mk_equals (Pattern.rewrite_term thy [(Free fvar, h)] [] t, t)
   117         val tt' = Logic.mk_equals (Pattern.rewrite_term thy [(fvar, h)] [] t, t)
   118         val (c, subs) = (Thm.concl_of r, Thm.prems_of r)
   118         val (c, subs) = (Thm.concl_of r, Thm.prems_of r)
   119 
   119 
   120         val subst = Pattern.match thy (c, tt') (Vartab.empty, Vartab.empty)
   120         val subst = Pattern.match thy (c, tt') (Vartab.empty, Vartab.empty)
   121         val branches = map (mk_branch ctxt o Envir.beta_norm o Envir.subst_term subst) subs
   121         val branches = map (mk_branch ctxt o Envir.beta_norm o Envir.subst_term subst) subs
   122         val inst =
   122         val inst =
   133     val congs = get_function_congs ctxt
   133     val congs = get_function_congs ctxt
   134 
   134 
   135     (* FIXME: Save in theory: *)
   135     (* FIXME: Save in theory: *)
   136     val congs_deps = map (fn c => (c, cong_deps c)) (congs @ default_congs)
   136     val congs_deps = map (fn c => (c, cong_deps c)) (congs @ default_congs)
   137 
   137 
   138     fun matchcall (a $ b) = if a = Free fvar then SOME b else NONE
   138     fun matchcall (a $ b) = if a = fvar then SOME b else NONE
   139       | matchcall _ = NONE
   139       | matchcall _ = NONE
   140 
   140 
   141     fun mk_tree' ctxt t =
   141     fun mk_tree' ctxt t =
   142       case matchcall t of
   142       case matchcall t of
   143         SOME arg => RCall (t, mk_tree' ctxt arg)
   143         SOME arg => RCall (t, mk_tree' ctxt arg)
   144       | NONE =>
   144       | NONE =>
   145         if not (exists_subterm (fn Free v => v = fvar | _ => false) t) then Leaf t
   145         if not (exists_subterm (fn v => v = fvar) t) then Leaf t
   146         else
   146         else
   147           let
   147           let
   148             val (r, dep, branches) = find_cong_rule ctxt fvar h congs_deps t
   148             val (r, dep, branches) = find_cong_rule ctxt fvar h congs_deps t
   149             fun subtree (ctxt', fixes, assumes, st) =
   149             fun subtree (ctxt', fixes, assumes, st) =
   150               ((fixes,
   150               ((fixes,