author | wenzelm |
Sat, 15 Feb 2014 18:48:43 +0100 | |
changeset 55506 | 46f3e31c5a87 |
parent 54742 | 7a86358a3c0b |
child 56245 | 84fc7dfa3cd4 |
permissions | -rw-r--r-- |
30439 | 1 |
(* Title: HOL/Decision_Procs/mir_tac.ML |
23858 | 2 |
Author: Amine Chaieb, TU Muenchen |
3 |
*) |
|
4 |
||
31240 | 5 |
signature MIR_TAC = |
6 |
sig |
|
7 |
val mir_tac: Proof.context -> bool -> int -> tactic |
|
8 |
end |
|
9 |
||
55506 | 10 |
structure Mir_Tac: MIR_TAC = |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
11 |
struct |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
12 |
|
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
13 |
val mir_ss = |
39159 | 14 |
let val ths = [@{thm "real_of_int_inject"}, @{thm "real_of_int_less_iff"}, @{thm "real_of_int_le_iff"}] |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
15 |
in simpset_of (@{context} delsimps ths addsimps (map (fn th => th RS sym) ths)) |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
16 |
end; |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
17 |
|
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
18 |
val nT = HOLogic.natT; |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45654
diff
changeset
|
19 |
val nat_arith = [@{thm diff_nat_numeral}]; |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
20 |
|
39159 | 21 |
val comp_arith = [@{thm "Let_def"}, @{thm "if_False"}, @{thm "if_True"}, @{thm "add_0"}, |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45654
diff
changeset
|
22 |
@{thm "add_Suc"}, @{thm add_numeral_left}, @{thm mult_numeral_left(1)}, |
39159 | 23 |
@{thm "Suc_eq_plus1"}] @ |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45654
diff
changeset
|
24 |
(map (fn th => th RS sym) [@{thm "numeral_1_eq_1"}]) |
25481 | 25 |
@ @{thms arith_simps} @ nat_arith @ @{thms rel_simps} |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
26 |
val ths = [@{thm "mult_numeral_1"}, @{thm "mult_numeral_1_right"}, |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45654
diff
changeset
|
27 |
@{thm real_of_nat_numeral}, |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
28 |
@{thm "real_of_nat_Suc"}, @{thm "real_of_nat_one"}, @{thm "real_of_one"}, |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
29 |
@{thm "real_of_int_zero"}, @{thm "real_of_nat_zero"}, |
36308 | 30 |
@{thm "divide_zero"}, |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
31 |
@{thm "divide_divide_eq_left"}, @{thm "times_divide_eq_right"}, |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
32 |
@{thm "times_divide_eq_left"}, @{thm "divide_divide_eq_right"}, |
54230
b1d955791529
more simplification rules on unary and binary minus
haftmann
parents:
52131
diff
changeset
|
33 |
@{thm uminus_add_conv_diff [symmetric]}, @{thm "minus_divide_left"}] |
45654 | 34 |
val comp_ths = ths @ comp_arith @ @{thms simp_thms}; |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
35 |
|
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
36 |
|
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
37 |
val mod_div_equality' = @{thm "mod_div_equality'"}; |
30224 | 38 |
val mod_add_eq = @{thm "mod_add_eq"} RS sym; |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
39 |
|
51369 | 40 |
fun prepare_for_mir q fm = |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
41 |
let |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
42 |
val ps = Logic.strip_params fm |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
43 |
val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
44 |
val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
45 |
fun mk_all ((s, T), (P,n)) = |
42083
e1209fc7ecdc
added Term.is_open and Term.is_dependent convenience, to cover common situations of loose bounds;
wenzelm
parents:
39159
diff
changeset
|
46 |
if Term.is_dependent P then |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
47 |
(HOLogic.all_const T $ Abs (s, T, P), n) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
48 |
else (incr_boundvars ~1 P, n-1) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
49 |
fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t; |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
50 |
val rhs = hs |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
51 |
(* val (rhs,irhs) = List.partition (relevant (rev ps)) hs *) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
52 |
val np = length ps |
33004
715566791eb0
always qualify NJ's old List.foldl/foldr in Isabelle/ML;
wenzelm
parents:
32740
diff
changeset
|
53 |
val (fm',np) = List.foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n))) |
715566791eb0
always qualify NJ's old List.foldl/foldr in Isabelle/ML;
wenzelm
parents:
32740
diff
changeset
|
54 |
(List.foldr HOLogic.mk_imp c rhs, np) ps |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
55 |
val (vs, _) = List.partition (fn t => q orelse (type_of t) = nT) |
44121 | 56 |
(Misc_Legacy.term_frees fm' @ Misc_Legacy.term_vars fm'); |
33004
715566791eb0
always qualify NJ's old List.foldl/foldr in Isabelle/ML;
wenzelm
parents:
32740
diff
changeset
|
57 |
val fm2 = List.foldr mk_all2 fm' vs |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
58 |
in (fm2, np + length vs, length rhs) end; |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
59 |
|
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
60 |
(*Object quantifier to meta --*) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
61 |
fun spec_step n th = if (n=0) then th else (spec_step (n-1) th) RS spec ; |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
62 |
|
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
63 |
(* object implication to meta---*) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
64 |
fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp; |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
65 |
|
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
66 |
|
42368
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
67 |
fun mir_tac ctxt q = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54230
diff
changeset
|
68 |
Object_Logic.atomize_prems_tac ctxt |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
69 |
THEN' simp_tac (put_simpset HOL_basic_ss ctxt |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
70 |
addsimps [@{thm "abs_ge_zero"}] addsimps @{thms simp_thms}) |
42368
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
71 |
THEN' (REPEAT_DETERM o split_tac [@{thm "split_min"}, @{thm "split_max"}, @{thm "abs_split"}]) |
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
72 |
THEN' SUBGOAL (fn (g, i) => |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
73 |
let |
42361 | 74 |
val thy = Proof_Context.theory_of ctxt |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
75 |
(* Transform the term*) |
51369 | 76 |
val (t,np,nh) = prepare_for_mir q g |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
77 |
(* Some simpsets for dealing with mod div abs and nat*) |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
78 |
val mod_div_simpset = put_simpset HOL_basic_ss ctxt |
30224 | 79 |
addsimps [refl, mod_add_eq, |
47142 | 80 |
@{thm mod_self}, |
81 |
@{thm div_0}, @{thm mod_0}, |
|
30031 | 82 |
@{thm "div_by_1"}, @{thm "mod_by_1"}, @{thm "div_1"}, @{thm "mod_1"}, |
31790 | 83 |
@{thm "Suc_eq_plus1"}] |
28290 | 84 |
addsimps @{thms add_ac} |
43594 | 85 |
addsimprocs [@{simproc cancel_div_mod_nat}, @{simproc cancel_div_mod_int}] |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
86 |
val simpset0 = put_simpset HOL_basic_ss ctxt |
31790 | 87 |
addsimps [mod_div_equality', @{thm Suc_eq_plus1}] |
23318 | 88 |
addsimps comp_ths |
45620
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
44121
diff
changeset
|
89 |
|> fold Splitter.add_split |
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
44121
diff
changeset
|
90 |
[@{thm "split_zdiv"}, @{thm "split_zmod"}, @{thm "split_div'"}, |
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
44121
diff
changeset
|
91 |
@{thm "split_min"}, @{thm "split_max"}] |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
92 |
(* Simp rules for changing (n::int) to int n *) |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
93 |
val simpset1 = put_simpset HOL_basic_ss ctxt |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45654
diff
changeset
|
94 |
addsimps [@{thm "zdvd_int"}] @ map (fn r => r RS sym) |
23381 | 95 |
[@{thm "int_int_eq"}, @{thm "zle_int"}, @{thm "zless_int"}, @{thm "zadd_int"}, |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45654
diff
changeset
|
96 |
@{thm nat_numeral}, @{thm "zmult_int"}] |
45620
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
44121
diff
changeset
|
97 |
|> Splitter.add_split @{thm "zdiff_int_split"} |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
98 |
(*simp rules for elimination of int n*) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
99 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
100 |
val simpset2 = put_simpset HOL_basic_ss ctxt |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45654
diff
changeset
|
101 |
addsimps [@{thm "nat_0_le"}, @{thm "all_nat"}, @{thm "ex_nat"}, @{thm zero_le_numeral}, |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45654
diff
changeset
|
102 |
@{thm "int_0"}, @{thm "int_1"}] |
45620
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
44121
diff
changeset
|
103 |
|> fold Simplifier.add_cong [@{thm "conj_le_cong"}, @{thm "imp_le_cong"}] |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
104 |
(* simp rules for elimination of abs *) |
27456 | 105 |
val ct = cterm_of thy (HOLogic.mk_Trueprop t) |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
106 |
(* Theorem for the nat --> int transformation *) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
107 |
val pre_thm = Seq.hd (EVERY |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
108 |
[simp_tac mod_div_simpset 1, simp_tac simpset0 1, |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
109 |
TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1), |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51369
diff
changeset
|
110 |
TRY (simp_tac (put_simpset mir_ss ctxt) 1)] |
36945 | 111 |
(Thm.trivial ct)) |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
112 |
fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
113 |
(* The result of the quantifier elimination *) |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
114 |
val (th, tac) = case (prop_of pre_thm) of |
38558 | 115 |
Const ("==>", _) $ (Const (@{const_name Trueprop}, _) $ t1) $ _ => |
28290 | 116 |
let val pth = |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
117 |
(* If quick_and_dirty then run without proof generation as oracle*) |
52059 | 118 |
if Config.get ctxt quick_and_dirty |
52131 | 119 |
then mirfr_oracle (false, cterm_of thy (Envir.eta_long [] t1)) |
120 |
else mirfr_oracle (true, cterm_of thy (Envir.eta_long [] t1)) |
|
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
121 |
in |
55506 | 122 |
((pth RS iffD2) RS pre_thm, |
123 |
assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i)) |
|
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
124 |
end |
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
125 |
| _ => (pre_thm, assm_tac i) |
42368
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
126 |
in rtac (((mp_step nh) o (spec_step np)) th) i THEN tac end); |
23264
324622260d29
Added twe Examples for Quantifier elimination ofer linear real arithmetic and over the mixed theory of linear real artihmetic with integers
chaieb
parents:
diff
changeset
|
127 |
|
23590
ad95084a5c63
renamed ObjectLogic.atomize_tac to ObjectLogic.atomize_prems_tac;
wenzelm
parents:
23381
diff
changeset
|
128 |
end |