106 val export: Proof.context -> Proof.context -> thm list -> thm list |
106 val export: Proof.context -> Proof.context -> thm list -> thm list |
107 val export_morphism: Proof.context -> Proof.context -> morphism |
107 val export_morphism: Proof.context -> Proof.context -> morphism |
108 val norm_export_morphism: Proof.context -> Proof.context -> morphism |
108 val norm_export_morphism: Proof.context -> Proof.context -> morphism |
109 val auto_bind_goal: term list -> Proof.context -> Proof.context |
109 val auto_bind_goal: term list -> Proof.context -> Proof.context |
110 val auto_bind_facts: term list -> Proof.context -> Proof.context |
110 val auto_bind_facts: term list -> Proof.context -> Proof.context |
111 val match_bind: (term list * term) list -> Proof.context -> term list * Proof.context |
111 val simult_matches: Proof.context -> term * term list -> (indexname * term) list |
112 val match_bind_cmd: (string list * string) list -> Proof.context -> term list * Proof.context |
112 val maybe_bind_term: indexname * term option -> Proof.context -> Proof.context |
|
113 val bind_term: indexname * term -> Proof.context -> Proof.context |
113 val cert_propp: Proof.context -> (term * term list) list list -> |
114 val cert_propp: Proof.context -> (term * term list) list list -> |
114 (term list list * (indexname * term) list) |
115 (term list list * (indexname * term) list) |
115 val read_propp: Proof.context -> (string * string list) list list -> |
116 val read_propp: Proof.context -> (string * string list) list list -> |
116 (term list list * (indexname * term) list) |
117 (term list list * (indexname * term) list) |
117 val fact_tac: Proof.context -> thm list -> int -> tactic |
118 val fact_tac: Proof.context -> thm list -> int -> tactic |
845 |
846 |
846 |
847 |
847 |
848 |
848 (** term bindings **) |
849 (** term bindings **) |
849 |
850 |
850 (* simult_matches *) |
851 (* auto bindings *) |
|
852 |
|
853 fun auto_bind f props ctxt = fold Variable.maybe_bind_term (f ctxt props) ctxt; |
|
854 |
|
855 val auto_bind_goal = auto_bind Auto_Bind.goal; |
|
856 val auto_bind_facts = auto_bind Auto_Bind.facts; |
|
857 |
|
858 |
|
859 (* match bindings *) |
851 |
860 |
852 fun simult_matches ctxt (t, pats) = |
861 fun simult_matches ctxt (t, pats) = |
853 (case Seq.pull (Unify.matchers (Context.Proof ctxt) (map (rpair t) pats)) of |
862 (case Seq.pull (Unify.matchers (Context.Proof ctxt) (map (rpair t) pats)) of |
854 NONE => error "Pattern match failed!" |
863 NONE => error "Pattern match failed!" |
855 | SOME (env, _) => Vartab.fold (fn (v, (_, t)) => cons (v, t)) (Envir.term_env env) []); |
864 | SOME (env, _) => Vartab.fold (fn (v, (_, t)) => cons (v, t)) (Envir.term_env env) []); |
856 |
865 |
857 |
866 fun maybe_bind_term (xi, t) ctxt = |
858 (* auto_bind *) |
|
859 |
|
860 fun auto_bind f props ctxt = fold Variable.maybe_bind_term (f ctxt props) ctxt; |
|
861 |
|
862 val auto_bind_goal = auto_bind Auto_Bind.goal; |
|
863 val auto_bind_facts = auto_bind Auto_Bind.facts; |
|
864 |
|
865 |
|
866 (* bind terms (non-schematic) *) |
|
867 |
|
868 fun cert_maybe_bind_term (xi, t) ctxt = |
|
869 ctxt |
867 ctxt |
870 |> Variable.maybe_bind_term (xi, Option.map (cert_term (set_mode mode_default ctxt)) t); |
868 |> Variable.maybe_bind_term (xi, Option.map (cert_term (set_mode mode_default ctxt)) t); |
871 |
869 |
872 val cert_bind_term = cert_maybe_bind_term o apsnd SOME; |
870 val bind_term = maybe_bind_term o apsnd SOME; |
873 |
|
874 |
|
875 (* match_bind *) |
|
876 |
|
877 local |
|
878 |
|
879 fun gen_bind prep_terms raw_binds ctxt = |
|
880 let |
|
881 fun prep_bind (raw_pats, t) ctxt1 = |
|
882 let |
|
883 val T = Term.fastype_of t; |
|
884 val ctxt2 = Variable.declare_term t ctxt1; |
|
885 val pats = prep_terms (set_mode mode_pattern ctxt2) T raw_pats; |
|
886 val binds = simult_matches ctxt2 (t, pats); |
|
887 in (binds, ctxt2) end; |
|
888 |
|
889 val ts = prep_terms ctxt dummyT (map snd raw_binds); |
|
890 val (binds, ctxt') = apfst flat (fold_map prep_bind (map fst raw_binds ~~ ts) ctxt); |
|
891 val binds' = map #1 binds ~~ Variable.exportT_terms ctxt' ctxt (map #2 binds); |
|
892 |
|
893 val ctxt'' = |
|
894 ctxt |
|
895 |> fold Variable.declare_term (map #2 binds') |
|
896 |> fold cert_bind_term binds'; |
|
897 val _ = Variable.warn_extra_tfrees ctxt ctxt''; |
|
898 in (ts, ctxt'') end; |
|
899 |
|
900 fun read_terms ctxt T = |
|
901 map (Syntax.parse_term ctxt #> Type.constraint T) #> Syntax.check_terms ctxt; |
|
902 |
|
903 in |
|
904 |
|
905 val match_bind = gen_bind (fn ctxt => fn _ => map (cert_term ctxt)); |
|
906 val match_bind_cmd = gen_bind read_terms; |
|
907 |
|
908 end; |
|
909 |
871 |
910 |
872 |
911 (* propositions with patterns *) |
873 (* propositions with patterns *) |
912 |
874 |
913 local |
875 local |
1340 val Rule_Cases.Case {fixes, ...} = c; |
1302 val Rule_Cases.Case {fixes, ...} = c; |
1341 val (ts, ctxt') = ctxt |> fold_map fix fixes; |
1303 val (ts, ctxt') = ctxt |> fold_map fix fixes; |
1342 val Rule_Cases.Case {assumes, binds, cases, ...} = Rule_Cases.apply ts c; |
1304 val Rule_Cases.Case {assumes, binds, cases, ...} = Rule_Cases.apply ts c; |
1343 in |
1305 in |
1344 ctxt' |
1306 ctxt' |
1345 |> fold (cert_maybe_bind_term o drop_schematic) binds |
1307 |> fold (maybe_bind_term o drop_schematic) binds |
1346 |> update_cases (map (apsnd SOME) cases) |
1308 |> update_cases (map (apsnd SOME) cases) |
1347 |> pair (assumes, (binds, cases)) |
1309 |> pair (assumes, (binds, cases)) |
1348 end; |
1310 end; |
1349 |
1311 |
1350 val apply_case = apfst fst oo case_result; |
1312 val apply_case = apfst fst oo case_result; |