91 val (trm', ctxt2', var) = skolem_var ctxt2 x |
91 val (trm', ctxt2', var) = skolem_var ctxt2 x |
92 in |
92 in |
93 (ctxt1, ctxt2', spets, trm', var :: vars) |
93 (ctxt1, ctxt2', spets, trm', var :: vars) |
94 end |
94 end |
95 |
95 |
96 fun skolemize' pos ctxt1 ctxt2 spets vars (Const (@{const_name Not}, _) $ trm') = |
96 fun skolemize' pos ctxt1 ctxt2 spets vars (Const (\<^const_name>\<open>Not\<close>, _) $ trm') = |
97 let |
97 let |
98 val (ctxt1', ctxt2', spets', trm'') = skolemize' (not pos) ctxt1 ctxt2 spets vars trm' |
98 val (ctxt1', ctxt2', spets', trm'') = skolemize' (not pos) ctxt1 ctxt2 spets vars trm' |
99 in |
99 in |
100 (ctxt1', ctxt2', map mk_not spets', mk_not trm'') |
100 (ctxt1', ctxt2', map mk_not spets', mk_not trm'') |
101 end |
101 end |
102 | skolemize' pos ctxt1 ctxt2 spets vars (trm as (Const (@{const_name HOL.eq}, t) $ a $ b)) = |
102 | skolemize' pos ctxt1 ctxt2 spets vars (trm as (Const (\<^const_name>\<open>HOL.eq\<close>, t) $ a $ b)) = |
103 if t = @{typ "bool \<Rightarrow> bool \<Rightarrow> bool"} andalso contains_quantor trm then |
103 if t = \<^typ>\<open>bool \<Rightarrow> bool \<Rightarrow> bool\<close> andalso contains_quantor trm then |
104 skolemize' pos ctxt1 ctxt2 (trm :: spets) vars (mk_conj (mk_imp (a, b), mk_imp (b, a))) |
104 skolemize' pos ctxt1 ctxt2 (trm :: spets) vars (mk_conj (mk_imp (a, b), mk_imp (b, a))) |
105 else |
105 else |
106 (ctxt1, ctxt2, spets, trm) |
106 (ctxt1, ctxt2, spets, trm) |
107 | skolemize' pos ctxt1 ctxt2 spets vars (trm as (Const (name, _) $ Abs x)) = |
107 | skolemize' pos ctxt1 ctxt2 spets vars (trm as (Const (name, _) $ Abs x)) = |
108 if name = @{const_name Ex} orelse name = @{const_name All} then |
108 if name = \<^const_name>\<open>Ex\<close> orelse name = \<^const_name>\<open>All\<close> then |
109 let |
109 let |
110 val is_free = (name = @{const_name Ex} andalso pos) |
110 val is_free = (name = \<^const_name>\<open>Ex\<close> andalso pos) |
111 orelse (name = @{const_name All} andalso not pos) |
111 orelse (name = \<^const_name>\<open>All\<close> andalso not pos) |
112 val (ctxt1', ctxt2', spets', trm', vars') = |
112 val (ctxt1', ctxt2', spets', trm', vars') = |
113 skolem_bound is_free ctxt1 ctxt2 (if is_free then trm :: spets else spets) vars x |
113 skolem_bound is_free ctxt1 ctxt2 (if is_free then trm :: spets else spets) vars x |
114 in |
114 in |
115 skolemize' pos ctxt1' ctxt2' spets' vars' trm' |
115 skolemize' pos ctxt1' ctxt2' spets' vars' trm' |
116 end |
116 end |
117 else |
117 else |
118 (ctxt1, ctxt2, spets, trm) |
118 (ctxt1, ctxt2, spets, trm) |
119 | skolemize' pos ctxt1 ctxt2 spets vars ((c as Const (name, _)) $ a $ b) = |
119 | skolemize' pos ctxt1 ctxt2 spets vars ((c as Const (name, _)) $ a $ b) = |
120 if name = @{const_name conj} orelse name = @{const_name disj} orelse |
120 if name = \<^const_name>\<open>conj\<close> orelse name = \<^const_name>\<open>disj\<close> orelse |
121 name = @{const_name implies} then |
121 name = \<^const_name>\<open>implies\<close> then |
122 let |
122 let |
123 val pos_a = if name = @{const_name implies} then not pos else pos |
123 val pos_a = if name = \<^const_name>\<open>implies\<close> then not pos else pos |
124 val (ctxt1', ctxt2', spets', a') = skolemize' pos_a ctxt1 ctxt2 [] vars a |
124 val (ctxt1', ctxt2', spets', a') = skolemize' pos_a ctxt1 ctxt2 [] vars a |
125 val (ctxt1'', ctxt2'', spets'', b') = skolemize' pos ctxt1' ctxt2' [] vars b |
125 val (ctxt1'', ctxt2'', spets'', b') = skolemize' pos ctxt1' ctxt2' [] vars b |
126 in |
126 in |
127 (ctxt1'', ctxt2'', |
127 (ctxt1'', ctxt2'', |
128 map (fn trm => c $ a' $ trm) spets'' @ map (fn trm => c $ trm $ b) spets' @ spets, |
128 map (fn trm => c $ a' $ trm) spets'' @ map (fn trm => c $ trm $ b) spets' @ spets, |
246 Some utilitary functions for translation. |
246 Some utilitary functions for translation. |
247 *) |
247 *) |
248 |
248 |
249 fun gen_ascii_tuple str = (str, ascii_of str) |
249 fun gen_ascii_tuple str = (str, ascii_of str) |
250 |
250 |
251 fun mk_eq_true (trm as (Const (@{const_name HOL.eq}, _) $ _ $ _)) = (NONE,trm) |
251 fun mk_eq_true (trm as (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $ _)) = (NONE,trm) |
252 | mk_eq_true trm = (SOME trm,HOLogic.mk_eq (trm, @{term True})) |
252 | mk_eq_true trm = (SOME trm,HOLogic.mk_eq (trm, \<^term>\<open>True\<close>)) |
253 |
253 |
254 val is_lambda_name = String.isPrefix lam_lifted_poly_prefix |
254 val is_lambda_name = String.isPrefix lam_lifted_poly_prefix |
255 |
255 |
256 fun lookup table k = |
256 fun lookup table k = |
257 List.find (fn (key, _) => key = k) table |
257 List.find (fn (key, _) => key = k) table |
356 | trm_to_atp'' thy (trm1 $ trm2) args = trm_to_atp'' thy trm1 (trm_to_atp'' thy trm2 [] @ args) |
356 | trm_to_atp'' thy (trm1 $ trm2) args = trm_to_atp'' thy trm1 (trm_to_atp'' thy trm2 [] @ args) |
357 | trm_to_atp'' _ _ _ = raise FailureMessage (WM_ERROR_MSG ^ "Unexpected term") |
357 | trm_to_atp'' _ _ _ = raise FailureMessage (WM_ERROR_MSG ^ "Unexpected term") |
358 |
358 |
359 fun trm_to_atp' thy trm = trm_to_atp'' thy trm [] |> hd |
359 fun trm_to_atp' thy trm = trm_to_atp'' thy trm [] |> hd |
360 |
360 |
361 fun eq_trm_to_atp thy (Const (@{const_name HOL.eq}, _) $ lhs $ rhs) = |
361 fun eq_trm_to_atp thy (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ lhs $ rhs) = |
362 ATerm ((("equal", "equal"), []), [trm_to_atp' thy lhs, trm_to_atp' thy rhs]) |
362 ATerm ((("equal", "equal"), []), [trm_to_atp' thy lhs, trm_to_atp' thy rhs]) |
363 | eq_trm_to_atp _ _ = raise FailureMessage (WM_ERROR_MSG ^ "Non-eq term") |
363 | eq_trm_to_atp _ _ = raise FailureMessage (WM_ERROR_MSG ^ "Non-eq term") |
364 |
364 |
365 (* Translation from ATP terms to Isabelle terms. *) |
365 (* Translation from ATP terms to Isabelle terms. *) |
366 |
366 |
413 | _ => Term.list_comb (construct_term thy (name, args), map (atp_to_trm' thy) args)) |
413 | _ => Term.list_comb (construct_term thy (name, args), map (atp_to_trm' thy) args)) |
414 | atp_to_trm' _ _ = raise FailureMessage (WM_ERROR_MSG ^ "atp_to_trm' expects ATerm") |
414 | atp_to_trm' _ _ = raise FailureMessage (WM_ERROR_MSG ^ "atp_to_trm' expects ATerm") |
415 |
415 |
416 fun atp_to_trm thy (ATerm (("equal", _), [lhs, rhs])) = |
416 fun atp_to_trm thy (ATerm (("equal", _), [lhs, rhs])) = |
417 mk_eq (atp_to_trm' thy lhs, atp_to_trm' thy rhs) |
417 mk_eq (atp_to_trm' thy lhs, atp_to_trm' thy rhs) |
418 | atp_to_trm _ (ATerm (("$true", _), _)) = @{term True} |
418 | atp_to_trm _ (ATerm (("$true", _), _)) = \<^term>\<open>True\<close> |
419 | atp_to_trm _ _ = raise FailureMessage (WM_ERROR_MSG ^ "atp_to_trm expects ATerm") |
419 | atp_to_trm _ _ = raise FailureMessage (WM_ERROR_MSG ^ "atp_to_trm expects ATerm") |
420 |
420 |
421 fun formula_to_trm thy (AAtom aterm) = aterm |> atp_to_trm thy |
421 fun formula_to_trm thy (AAtom aterm) = aterm |> atp_to_trm thy |
422 | formula_to_trm thy (AConn (ANot, [aterm])) = |
422 | formula_to_trm thy (AConn (ANot, [aterm])) = |
423 mk_not (formula_to_trm thy aterm) |
423 mk_not (formula_to_trm thy aterm) |