79 fun is_rigid_elem (Const(@{const_name Trueprop},_) $ (Const(@{const_name mem},_) $ a $ _)) = |
79 fun is_rigid_elem (Const(@{const_name Trueprop},_) $ (Const(@{const_name mem},_) $ a $ _)) = |
80 not (is_Var (head_of a)) |
80 not (is_Var (head_of a)) |
81 | is_rigid_elem _ = false; |
81 | is_rigid_elem _ = false; |
82 |
82 |
83 (*Try solving a:A by assumption provided a is rigid!*) |
83 (*Try solving a:A by assumption provided a is rigid!*) |
84 val test_assume_tac = SUBGOAL(fn (prem,i) => |
84 fun test_assume_tac ctxt = SUBGOAL(fn (prem,i) => |
85 if is_rigid_elem (Logic.strip_assums_concl prem) |
85 if is_rigid_elem (Logic.strip_assums_concl prem) |
86 then assume_tac i else eq_assume_tac i); |
86 then assume_tac ctxt i else eq_assume_tac i); |
87 |
87 |
88 (*Type checking solves a:?A (a rigid, ?A maybe flexible). |
88 (*Type checking solves a:?A (a rigid, ?A maybe flexible). |
89 match_tac is too strict; would refuse to instantiate ?A*) |
89 match_tac is too strict; would refuse to instantiate ?A*) |
90 fun typecheck_step_tac (TC{net,...}) = |
90 fun typecheck_step_tac ctxt = |
91 FIRSTGOAL (test_assume_tac ORELSE' net_res_tac 3 net); |
91 let val TC {net, ...} = tcset_of ctxt |
|
92 in FIRSTGOAL (test_assume_tac ctxt ORELSE' net_res_tac 3 net) end; |
92 |
93 |
93 fun typecheck_tac ctxt = REPEAT (typecheck_step_tac (tcset_of ctxt)); |
94 fun typecheck_tac ctxt = REPEAT (typecheck_step_tac ctxt); |
94 |
95 |
95 (*Compiles a term-net for speed*) |
96 (*Compiles a term-net for speed*) |
96 val basic_res_tac = net_resolve_tac [@{thm TrueI}, @{thm refl}, reflexive_thm, @{thm iff_refl}, |
97 val basic_res_tac = net_resolve_tac [@{thm TrueI}, @{thm refl}, reflexive_thm, @{thm iff_refl}, |
97 @{thm ballI}, @{thm allI}, @{thm conjI}, @{thm impI}]; |
98 @{thm ballI}, @{thm allI}, @{thm conjI}, @{thm impI}]; |
98 |
99 |
100 drawback: does not simplify conjunctions*) |
101 drawback: does not simplify conjunctions*) |
101 fun type_solver_tac ctxt hyps = SELECT_GOAL |
102 fun type_solver_tac ctxt hyps = SELECT_GOAL |
102 (DEPTH_SOLVE (eresolve_tac @{thms FalseE} 1 |
103 (DEPTH_SOLVE (eresolve_tac @{thms FalseE} 1 |
103 ORELSE basic_res_tac 1 |
104 ORELSE basic_res_tac 1 |
104 ORELSE (ares_tac hyps 1 |
105 ORELSE (ares_tac hyps 1 |
105 APPEND typecheck_step_tac (tcset_of ctxt)))); |
106 APPEND typecheck_step_tac ctxt))); |
106 |
107 |
107 val type_solver = |
108 val type_solver = |
108 Simplifier.mk_solver "ZF typecheck" (fn ctxt => |
109 Simplifier.mk_solver "ZF typecheck" (fn ctxt => |
109 type_solver_tac ctxt (Simplifier.prems_of ctxt)); |
110 type_solver_tac ctxt (Simplifier.prems_of ctxt)); |
110 |
111 |