103 val standard_term_uncheck: Proof.context -> term list -> term list |
103 val standard_term_uncheck: Proof.context -> term list -> term list |
104 val goal_export: Proof.context -> Proof.context -> thm list -> thm list |
104 val goal_export: Proof.context -> Proof.context -> thm list -> thm list |
105 val export: Proof.context -> Proof.context -> thm list -> thm list |
105 val export: Proof.context -> Proof.context -> thm list -> thm list |
106 val export_morphism: Proof.context -> Proof.context -> morphism |
106 val export_morphism: Proof.context -> Proof.context -> morphism |
107 val norm_export_morphism: Proof.context -> Proof.context -> morphism |
107 val norm_export_morphism: Proof.context -> Proof.context -> morphism |
108 val maybe_bind_terms: (indexname * term option) list -> Proof.context -> Proof.context |
|
109 val bind_terms: (indexname * term) list -> Proof.context -> Proof.context |
|
110 val auto_bind_goal: term list -> Proof.context -> Proof.context |
108 val auto_bind_goal: term list -> Proof.context -> Proof.context |
111 val auto_bind_facts: term list -> Proof.context -> Proof.context |
109 val auto_bind_facts: term list -> Proof.context -> Proof.context |
112 val match_bind: bool -> (term list * term) list -> Proof.context -> |
110 val match_bind: bool -> (term list * term) list -> Proof.context -> |
113 term list * Proof.context |
111 term list * Proof.context |
114 val match_bind_cmd: bool -> (string list * string) list -> Proof.context -> |
112 val match_bind_cmd: bool -> (string list * string) list -> Proof.context -> |
813 (case Seq.pull (Unify.matchers (Context.Proof ctxt) (map (rpair t) pats)) of |
811 (case Seq.pull (Unify.matchers (Context.Proof ctxt) (map (rpair t) pats)) of |
814 NONE => error "Pattern match failed!" |
812 NONE => error "Pattern match failed!" |
815 | SOME (env, _) => Vartab.fold (fn (v, (_, t)) => cons (v, t)) (Envir.term_env env) []); |
813 | SOME (env, _) => Vartab.fold (fn (v, (_, t)) => cons (v, t)) (Envir.term_env env) []); |
816 |
814 |
817 |
815 |
818 (* bind_terms *) |
|
819 |
|
820 val maybe_bind_terms = fold (fn (xi, t) => fn ctxt => |
|
821 ctxt |
|
822 |> Variable.maybe_bind_term (xi, Option.map (cert_term (set_mode mode_default ctxt)) t)); |
|
823 |
|
824 val bind_terms = maybe_bind_terms o map (apsnd SOME); |
|
825 |
|
826 |
|
827 (* auto_bind *) |
816 (* auto_bind *) |
828 |
817 |
829 fun drop_schematic (b as (xi, SOME t)) = if Term.exists_subterm is_Var t then (xi, NONE) else b |
818 fun auto_bind f props ctxt = fold Variable.maybe_bind_term (f ctxt props) ctxt; |
830 | drop_schematic b = b; |
|
831 |
|
832 fun auto_bind f ts ctxt = ctxt |> maybe_bind_terms (map drop_schematic (f ctxt ts)); |
|
833 |
819 |
834 val auto_bind_goal = auto_bind Auto_Bind.goal; |
820 val auto_bind_goal = auto_bind Auto_Bind.goal; |
835 val auto_bind_facts = auto_bind Auto_Bind.facts; |
821 val auto_bind_facts = auto_bind Auto_Bind.facts; |
|
822 |
|
823 |
|
824 (* bind terms (non-schematic) *) |
|
825 |
|
826 fun cert_maybe_bind_term (xi, t) ctxt = |
|
827 ctxt |
|
828 |> Variable.maybe_bind_term (xi, Option.map (cert_term (set_mode mode_default ctxt)) t); |
|
829 |
|
830 val cert_bind_term = cert_maybe_bind_term o apsnd SOME; |
836 |
831 |
837 |
832 |
838 (* match_bind *) |
833 (* match_bind *) |
839 |
834 |
840 local |
835 local |
855 if gen then map #1 binds ~~ Variable.exportT_terms ctxt' ctxt (map #2 binds) |
850 if gen then map #1 binds ~~ Variable.exportT_terms ctxt' ctxt (map #2 binds) |
856 else binds; |
851 else binds; |
857 val ctxt'' = |
852 val ctxt'' = |
858 tap (Variable.warn_extra_tfrees ctxt) |
853 tap (Variable.warn_extra_tfrees ctxt) |
859 (if gen then |
854 (if gen then |
860 ctxt (*sic!*) |> fold Variable.declare_term (map #2 binds') |> bind_terms binds' |
855 ctxt (*sic!*) |
861 else ctxt' |> bind_terms binds'); |
856 |> fold Variable.declare_term (map #2 binds') |
|
857 |> fold cert_bind_term binds' |
|
858 else ctxt' |> fold cert_bind_term binds'); |
862 in (ts, ctxt'') end; |
859 in (ts, ctxt'') end; |
863 |
860 |
864 in |
861 in |
865 |
862 |
866 fun read_terms ctxt T = |
863 fun read_terms ctxt T = |
1159 |> fold Variable.declare_term props |
1156 |> fold Variable.declare_term props |
1160 |> tap (Variable.warn_extra_tfrees ctxt) |
1157 |> tap (Variable.warn_extra_tfrees ctxt) |
1161 |> fold_burrow (Assumption.add_assms exp o map (Thm.cterm_of ctxt)) propss |
1158 |> fold_burrow (Assumption.add_assms exp o map (Thm.cterm_of ctxt)) propss |
1162 |-> (fn premss => |
1159 |-> (fn premss => |
1163 auto_bind_facts props |
1160 auto_bind_facts props |
1164 #> bind_terms binds |
1161 #> fold Variable.bind_term binds |
1165 #> note_thmss "" (map fst args ~~ map (map (fn th => ([th], []))) premss)) |
1162 #> note_thmss "" (map fst args ~~ map (map (fn th => ([th], []))) premss)) |
1166 end; |
1163 end; |
1167 |
1164 |
1168 in |
1165 in |
1169 |
1166 |
1179 fun dest_cases ctxt = |
1176 fun dest_cases ctxt = |
1180 Name_Space.fold_table (fn (a, (c, i)) => cons (i, (a, c))) (cases_of ctxt) [] |
1177 Name_Space.fold_table (fn (a, (c, i)) => cons (i, (a, c))) (cases_of ctxt) [] |
1181 |> sort (int_ord o apply2 #1) |> map #2; |
1178 |> sort (int_ord o apply2 #1) |> map #2; |
1182 |
1179 |
1183 local |
1180 local |
|
1181 |
|
1182 fun drop_schematic (b as (xi, SOME t)) = if Term.exists_subterm is_Var t then (xi, NONE) else b |
|
1183 | drop_schematic b = b; |
1184 |
1184 |
1185 fun update_case _ _ ("", _) res = res |
1185 fun update_case _ _ ("", _) res = res |
1186 | update_case _ _ (name, NONE) (cases, index) = |
1186 | update_case _ _ (name, NONE) (cases, index) = |
1187 (Name_Space.del_table name cases, index) |
1187 (Name_Space.del_table name cases, index) |
1188 | update_case context is_proper (name, SOME c) (cases, index) = |
1188 | update_case context is_proper (name, SOME c) (cases, index) = |
1211 val Rule_Cases.Case {fixes, ...} = c; |
1211 val Rule_Cases.Case {fixes, ...} = c; |
1212 val (ts, ctxt') = ctxt |> fold_map fix fixes; |
1212 val (ts, ctxt') = ctxt |> fold_map fix fixes; |
1213 val Rule_Cases.Case {assumes, binds, cases, ...} = Rule_Cases.apply ts c; |
1213 val Rule_Cases.Case {assumes, binds, cases, ...} = Rule_Cases.apply ts c; |
1214 in |
1214 in |
1215 ctxt' |
1215 ctxt' |
1216 |> maybe_bind_terms (map drop_schematic binds) |
1216 |> fold (cert_maybe_bind_term o drop_schematic) binds |
1217 |> update_cases true (map (apsnd SOME) cases) |
1217 |> update_cases true (map (apsnd SOME) cases) |
1218 |> pair (assumes, (binds, cases)) |
1218 |> pair (assumes, (binds, cases)) |
1219 end; |
1219 end; |
1220 |
1220 |
1221 val apply_case = apfst fst oo case_result; |
1221 val apply_case = apfst fst oo case_result; |