22 val cont_A = @{thm cont2cont_APP} |
22 val cont_A = @{thm cont2cont_APP} |
23 val cont_L = @{thm cont2cont_LAM} |
23 val cont_L = @{thm cont2cont_LAM} |
24 val cont_R = @{thm cont_Rep_cfun2} |
24 val cont_R = @{thm cont_Rep_cfun2} |
25 |
25 |
26 (* checks whether a term is written entirely in the LCF sublanguage *) |
26 (* checks whether a term is written entirely in the LCF sublanguage *) |
27 fun is_lcf_term (Const (@{const_name Rep_cfun}, _) $ t $ u) = |
27 fun is_lcf_term (Const (\<^const_name>\<open>Rep_cfun\<close>, _) $ t $ u) = |
28 is_lcf_term t andalso is_lcf_term u |
28 is_lcf_term t andalso is_lcf_term u |
29 | is_lcf_term (Const (@{const_name Abs_cfun}, _) $ Abs (_, _, t)) = |
29 | is_lcf_term (Const (\<^const_name>\<open>Abs_cfun\<close>, _) $ Abs (_, _, t)) = |
30 is_lcf_term t |
30 is_lcf_term t |
31 | is_lcf_term (Const (@{const_name Abs_cfun}, _) $ t) = |
31 | is_lcf_term (Const (\<^const_name>\<open>Abs_cfun\<close>, _) $ t) = |
32 is_lcf_term (Term.incr_boundvars 1 t $ Bound 0) |
32 is_lcf_term (Term.incr_boundvars 1 t $ Bound 0) |
33 | is_lcf_term (Bound _) = true |
33 | is_lcf_term (Bound _) = true |
34 | is_lcf_term t = not (Term.is_open t) |
34 | is_lcf_term t = not (Term.is_open t) |
35 |
35 |
36 (* |
36 (* |
62 in (map (fn y => SOME (k y RS Lx)) ys, x') end |
62 in (map (fn y => SOME (k y RS Lx)) ys, x') end |
63 |
63 |
64 (* first list: cont thm for each dangling bound variable *) |
64 (* first list: cont thm for each dangling bound variable *) |
65 (* second list: cont thm for each LAM in t *) |
65 (* second list: cont thm for each LAM in t *) |
66 (* if b = false, only return cont thm for outermost LAMs *) |
66 (* if b = false, only return cont thm for outermost LAMs *) |
67 fun cont_thms1 b (Const (@{const_name Rep_cfun}, _) $ f $ t) = |
67 fun cont_thms1 b (Const (\<^const_name>\<open>Rep_cfun\<close>, _) $ f $ t) = |
68 let |
68 let |
69 val (cs1,ls1) = cont_thms1 b f |
69 val (cs1,ls1) = cont_thms1 b f |
70 val (cs2,ls2) = cont_thms1 b t |
70 val (cs2,ls2) = cont_thms1 b t |
71 in (zip cs1 cs2, if b then ls1 @ ls2 else []) end |
71 in (zip cs1 cs2, if b then ls1 @ ls2 else []) end |
72 | cont_thms1 b (Const (@{const_name Abs_cfun}, _) $ Abs (_, _, t)) = |
72 | cont_thms1 b (Const (\<^const_name>\<open>Abs_cfun\<close>, _) $ Abs (_, _, t)) = |
73 let |
73 let |
74 val (cs, ls) = cont_thms1 b t |
74 val (cs, ls) = cont_thms1 b t |
75 val (cs', l) = lam cs |
75 val (cs', l) = lam cs |
76 in (cs', l::ls) end |
76 in (cs', l::ls) end |
77 | cont_thms1 b (Const (@{const_name Abs_cfun}, _) $ t) = |
77 | cont_thms1 b (Const (\<^const_name>\<open>Abs_cfun\<close>, _) $ t) = |
78 let |
78 let |
79 val t' = Term.incr_boundvars 1 t $ Bound 0 |
79 val t' = Term.incr_boundvars 1 t $ Bound 0 |
80 val (cs, ls) = cont_thms1 b t' |
80 val (cs, ls) = cont_thms1 b t' |
81 val (cs', l) = lam cs |
81 val (cs', l) = lam cs |
82 in (cs', l::ls) end |
82 in (cs', l::ls) end |
102 fun new_cont_tac f' i = |
102 fun new_cont_tac f' i = |
103 case all_cont_thms f' of |
103 case all_cont_thms f' of |
104 [] => no_tac |
104 [] => no_tac |
105 | (c::_) => resolve_tac ctxt [c] i |
105 | (c::_) => resolve_tac ctxt [c] i |
106 |
106 |
107 fun cont_tac_of_term (Const (@{const_name cont}, _) $ f) = |
107 fun cont_tac_of_term (Const (\<^const_name>\<open>cont\<close>, _) $ f) = |
108 let |
108 let |
109 val f' = Const (@{const_name Abs_cfun}, dummyT) $ f |
109 val f' = Const (\<^const_name>\<open>Abs_cfun\<close>, dummyT) $ f |
110 in |
110 in |
111 if is_lcf_term f' |
111 if is_lcf_term f' |
112 then new_cont_tac f' |
112 then new_cont_tac f' |
113 else REPEAT_ALL_NEW (resolve_tac ctxt rules) |
113 else REPEAT_ALL_NEW (resolve_tac ctxt rules) |
114 end |
114 end |
124 val t = Thm.term_of ct |
124 val t = Thm.term_of ct |
125 val tr = Thm.instantiate' [] [SOME (Thm.cterm_of ctxt t)] @{thm Eq_TrueI} |
125 val tr = Thm.instantiate' [] [SOME (Thm.cterm_of ctxt t)] @{thm Eq_TrueI} |
126 in Option.map fst (Seq.pull (cont_tac ctxt 1 tr)) end |
126 in Option.map fst (Seq.pull (cont_tac ctxt 1 tr)) end |
127 in |
127 in |
128 val cont_proc = |
128 val cont_proc = |
129 Simplifier.make_simproc @{context} "cont_proc" |
129 Simplifier.make_simproc \<^context> "cont_proc" |
130 {lhss = [@{term "cont f"}], proc = K solve_cont} |
130 {lhss = [\<^term>\<open>cont f\<close>], proc = K solve_cont} |
131 end |
131 end |
132 |
132 |
133 val setup = map_theory_simpset (fn ctxt => ctxt addsimprocs [cont_proc]) |
133 val setup = map_theory_simpset (fn ctxt => ctxt addsimprocs [cont_proc]) |
134 |
134 |
135 end |
135 end |