167 |
167 |
168 (*Maps fully-typed metis terms to isabelle terms*) |
168 (*Maps fully-typed metis terms to isabelle terms*) |
169 fun hol_term_from_metis_FT ctxt new_skolem_var_count fol_tm = |
169 fun hol_term_from_metis_FT ctxt new_skolem_var_count fol_tm = |
170 let val _ = trace_msg ctxt (fn () => "hol_term_from_metis_FT: " ^ |
170 let val _ = trace_msg ctxt (fn () => "hol_term_from_metis_FT: " ^ |
171 Metis_Term.toString fol_tm) |
171 Metis_Term.toString fol_tm) |
|
172 fun do_const c = |
|
173 let val c = c |> invert_const in |
|
174 if String.isPrefix new_skolem_const_prefix c then |
|
175 Var ((new_skolem_var_name_from_const c, 1), dummyT) |
|
176 else |
|
177 Const (c, dummyT) |
|
178 end |
172 fun cvt (Metis_Term.Fn ("ti", [Metis_Term.Var v, _])) = |
179 fun cvt (Metis_Term.Fn ("ti", [Metis_Term.Var v, _])) = |
173 (case strip_prefix_and_unascii schematic_var_prefix v of |
180 (case strip_prefix_and_unascii schematic_var_prefix v of |
174 SOME w => mk_var(w, dummyT) |
181 SOME w => mk_var(w, dummyT) |
175 | NONE => mk_var(v, dummyT)) |
182 | NONE => mk_var(v, dummyT)) |
176 | cvt (Metis_Term.Fn ("ti", [Metis_Term.Fn ("=",[]), _])) = |
183 | cvt (Metis_Term.Fn ("ti", [Metis_Term.Fn ("=",[]), _])) = |
177 Const (@{const_name HOL.eq}, HOLogic.typeT) |
184 Const (@{const_name HOL.eq}, HOLogic.typeT) |
178 | cvt (Metis_Term.Fn ("ti", [Metis_Term.Fn (x,[]), ty])) = |
185 | cvt (Metis_Term.Fn ("ti", [Metis_Term.Fn (x,[]), ty])) = |
179 (case strip_prefix_and_unascii const_prefix x of |
186 (case strip_prefix_and_unascii const_prefix x of |
180 SOME c => Const (invert_const c, dummyT) |
187 SOME c => do_const c |
181 | NONE => (*Not a constant. Is it a fixed variable??*) |
188 | NONE => (*Not a constant. Is it a fixed variable??*) |
182 case strip_prefix_and_unascii fixed_var_prefix x of |
189 case strip_prefix_and_unascii fixed_var_prefix x of |
183 SOME v => Free (v, hol_type_from_metis_term ctxt ty) |
190 SOME v => Free (v, hol_type_from_metis_term ctxt ty) |
184 | NONE => raise Fail ("hol_term_from_metis_FT bad constant: " ^ x)) |
191 | NONE => raise Fail ("hol_term_from_metis_FT bad constant: " ^ x)) |
185 | cvt (Metis_Term.Fn ("ti", [Metis_Term.Fn (".",[tm1,tm2]), _])) = |
192 | cvt (Metis_Term.Fn ("ti", [Metis_Term.Fn (".",[tm1,tm2]), _])) = |
189 | cvt (Metis_Term.Fn ("{}", [arg])) = cvt arg (*hBOOL*) |
196 | cvt (Metis_Term.Fn ("{}", [arg])) = cvt arg (*hBOOL*) |
190 | cvt (Metis_Term.Fn ("=", [tm1,tm2])) = |
197 | cvt (Metis_Term.Fn ("=", [tm1,tm2])) = |
191 list_comb(Const (@{const_name HOL.eq}, HOLogic.typeT), map cvt [tm1,tm2]) |
198 list_comb(Const (@{const_name HOL.eq}, HOLogic.typeT), map cvt [tm1,tm2]) |
192 | cvt (t as Metis_Term.Fn (x, [])) = |
199 | cvt (t as Metis_Term.Fn (x, [])) = |
193 (case strip_prefix_and_unascii const_prefix x of |
200 (case strip_prefix_and_unascii const_prefix x of |
194 SOME c => Const (invert_const c, dummyT) |
201 SOME c => do_const c |
195 | NONE => (*Not a constant. Is it a fixed variable??*) |
202 | NONE => (*Not a constant. Is it a fixed variable??*) |
196 case strip_prefix_and_unascii fixed_var_prefix x of |
203 case strip_prefix_and_unascii fixed_var_prefix x of |
197 SOME v => Free (v, dummyT) |
204 SOME v => Free (v, dummyT) |
198 | NONE => (trace_msg ctxt (fn () => |
205 | NONE => (trace_msg ctxt (fn () => |
199 "hol_term_from_metis_FT bad const: " ^ x); |
206 "hol_term_from_metis_FT bad const: " ^ x); |