97 val add_term_syntax: string -> declaration -> Proof.context -> Proof.context |
97 val add_term_syntax: string -> declaration -> Proof.context -> Proof.context |
98 val add_declaration: string -> declaration -> Proof.context -> Proof.context |
98 val add_declaration: string -> declaration -> Proof.context -> Proof.context |
99 |
99 |
100 val interpretation_i: (Proof.context -> Proof.context) -> |
100 val interpretation_i: (Proof.context -> Proof.context) -> |
101 (bool * string) * Attrib.src list -> expr -> |
101 (bool * string) * Attrib.src list -> expr -> |
102 (typ Symtab.table * term Symtab.table) * term list -> |
102 term option list * term list -> |
103 theory -> Proof.state |
103 theory -> Proof.state |
104 val interpretation: (Proof.context -> Proof.context) -> |
104 val interpretation: (Proof.context -> Proof.context) -> |
105 (bool * string) * Attrib.src list -> expr -> |
105 (bool * string) * Attrib.src list -> expr -> |
106 string option list * string list -> |
106 string option list * string list -> |
107 theory -> Proof.state |
107 theory -> Proof.state |
108 val interpretation_in_locale: (Proof.context -> Proof.context) -> |
108 val interpretation_in_locale: (Proof.context -> Proof.context) -> |
109 xstring * expr -> theory -> Proof.state |
109 xstring * expr -> theory -> Proof.state |
110 val interpret_i: (Proof.state -> Proof.state Seq.seq) -> |
110 val interpret_i: (Proof.state -> Proof.state Seq.seq) -> |
111 (bool * string) * Attrib.src list -> expr -> |
111 (bool * string) * Attrib.src list -> expr -> |
112 (typ Symtab.table * term Symtab.table) * term list -> |
112 term option list * term list -> |
113 bool -> Proof.state -> Proof.state |
113 bool -> Proof.state -> Proof.state |
114 val interpret: (Proof.state -> Proof.state Seq.seq) -> |
114 val interpret: (Proof.state -> Proof.state Seq.seq) -> |
115 (bool * string) * Attrib.src list -> expr -> |
115 (bool * string) * Attrib.src list -> expr -> |
116 string option list * string list -> |
116 string option list * string list -> |
117 bool -> Proof.state -> Proof.state |
117 bool -> Proof.state -> Proof.state |
2075 put_local_registration |
2075 put_local_registration |
2076 add_local_witness |
2076 add_local_witness |
2077 add_local_equation |
2077 add_local_equation |
2078 x; |
2078 x; |
2079 |
2079 |
2080 fun prep_instantiations parse_term parse_prop ctxt parms (insts, eqns) = |
2080 fun prep_instantiations prep_term prep_prop ctxt parms (insts, eqns) = |
2081 let |
2081 let |
2082 (* parameters *) |
2082 (* parameters *) |
2083 val (parm_names, parm_types) = parms |> split_list |
2083 val (parm_names, parm_types) = parms |> split_list |
2084 ||> map (TypeInfer.paramify_vars o Logic.varifyT); |
2084 ||> map (TypeInfer.paramify_vars o Logic.varifyT); |
2085 val type_parms = fold Term.add_tvarsT parm_types [] |> map TVar; |
2085 val type_parms = fold Term.add_tvarsT parm_types [] |> map (Logic.mk_type o TVar); |
2086 val type_parm_names = fold Term.add_tfreesT (map snd parms) [] |> map fst; |
2086 val type_parm_names = fold Term.add_tfreesT (map snd parms) [] |> map fst; |
|
2087 |
|
2088 (*(* type instantiations *) |
|
2089 val dT = length type_parms - length instsT; |
|
2090 val instsT = |
|
2091 if dT < 0 then error "More type arguments than type parameters in instantiation." |
|
2092 else instsT @ replicate dT NONE; |
|
2093 val type_terms = map2 (fn t => fn SOME T => TypeInfer.constrain (Term.itselfT T) t |
|
2094 | NONE => t) type_parms instsT;*) |
2087 |
2095 |
2088 (* parameter instantiations *) |
2096 (* parameter instantiations *) |
2089 val d = length parms - length insts; |
2097 val d = length parms - length insts; |
2090 val insts = |
2098 val insts = |
2091 if d < 0 then error "More arguments than parameters in instantiation." |
2099 if d < 0 then error "More arguments than parameters in instantiation." |
2096 | ((n, T), SOME inst) => SOME ((n, T), inst)) |
2104 | ((n, T), SOME inst) => SOME ((n, T), inst)) |
2097 |> split_list; |
2105 |> split_list; |
2098 val (given_parm_names, given_parm_types) = given_ps |> split_list; |
2106 val (given_parm_names, given_parm_types) = given_ps |> split_list; |
2099 |
2107 |
2100 (* prepare insts / eqns *) |
2108 (* prepare insts / eqns *) |
2101 val given_insts' = map (parse_term ctxt) given_insts; |
2109 val given_insts' = map (prep_term ctxt) given_insts; |
2102 val eqns' = map (parse_prop ctxt) eqns; |
2110 val eqns' = map (prep_prop ctxt) eqns; |
2103 |
2111 |
2104 (* infer types *) |
2112 (* infer types *) |
2105 val res = Syntax.check_terms ctxt |
2113 val res = Syntax.check_terms ctxt |
2106 (map Logic.mk_type type_parms @ |
2114 (type_parms @ |
2107 map2 TypeInfer.constrain given_parm_types given_insts' @ |
2115 map2 TypeInfer.constrain given_parm_types given_insts' @ |
2108 eqns'); |
2116 eqns'); |
2109 val ctxt' = ctxt |> fold Variable.auto_fixes res; |
2117 val ctxt' = ctxt |> fold Variable.auto_fixes res; |
2110 |
2118 |
2111 (* results *) |
2119 (* results *) |
2114 val instT = Symtab.make (type_parm_names ~~ map Logic.dest_type type_parms''); |
2122 val instT = Symtab.make (type_parm_names ~~ map Logic.dest_type type_parms''); |
2115 val inst = Symtab.make (given_parm_names ~~ given_insts''); |
2123 val inst = Symtab.make (given_parm_names ~~ given_insts''); |
2116 val standard = Variable.export_morphism ctxt' ctxt; |
2124 val standard = Variable.export_morphism ctxt' ctxt; |
2117 in ((instT, inst), eqns'') end; |
2125 in ((instT, inst), eqns'') end; |
2118 |
2126 |
2119 |
|
2120 val read_instantiations = prep_instantiations Syntax.parse_term Syntax.parse_prop; |
2127 val read_instantiations = prep_instantiations Syntax.parse_term Syntax.parse_prop; |
2121 val check_instantiations = prep_instantiations (K I) (K I); |
2128 val cert_instantiations = prep_instantiations (K I) (K I); |
2122 |
2129 |
2123 fun gen_prep_registration mk_ctxt test_reg activate |
2130 fun gen_prep_registration mk_ctxt test_reg activate |
2124 prep_attr prep_expr prep_insts |
2131 prep_attr prep_expr prep_insts |
2125 thy_ctxt raw_attn raw_expr raw_insts = |
2132 thy_ctxt raw_attn raw_expr raw_insts = |
2126 let |
2133 let |
2198 test_local_registration |
2205 test_local_registration |
2199 local_activate_facts_elemss mk_ctxt; |
2206 local_activate_facts_elemss mk_ctxt; |
2200 |
2207 |
2201 val prep_global_registration = gen_prep_global_registration |
2208 val prep_global_registration = gen_prep_global_registration |
2202 Attrib.intern_src intern_expr read_instantiations; |
2209 Attrib.intern_src intern_expr read_instantiations; |
2203 (* FIXME: NEW |
|
2204 val prep_global_registration_i = gen_prep_global_registration |
2210 val prep_global_registration_i = gen_prep_global_registration |
2205 (K I) (K I) check_instantiations; |
2211 (K I) (K I) cert_instantiations; |
2206 *) |
|
2207 val prep_global_registration_i = gen_prep_global_registration |
|
2208 (K I) (K I) ((K o K) I); |
|
2209 |
2212 |
2210 val prep_local_registration = gen_prep_local_registration |
2213 val prep_local_registration = gen_prep_local_registration |
2211 Attrib.intern_src intern_expr read_instantiations; |
2214 Attrib.intern_src intern_expr read_instantiations; |
2212 (* FIXME: NEW |
|
2213 val prep_local_registration_i = gen_prep_local_registration |
2215 val prep_local_registration_i = gen_prep_local_registration |
2214 (K I) (K I) check_instantiations; |
2216 (K I) (K I) cert_instantiations; |
2215 *) |
|
2216 val prep_local_registration_i = gen_prep_local_registration |
|
2217 (K I) (K I) ((K o K) I); |
|
2218 |
2217 |
2219 fun prep_registration_in_locale target expr thy = |
2218 fun prep_registration_in_locale target expr thy = |
2220 (* target already in internal form *) |
2219 (* target already in internal form *) |
2221 let |
2220 let |
2222 val ctxt = ProofContext.init thy; |
2221 val ctxt = ProofContext.init thy; |