author  wenzelm 
Sun, 11 Jan 2009 21:49:59 +0100  
changeset 29450  ac7f67be7f1f 
parent 28262  aa7ca36d67fd 
child 30609  983e8b6e4e69 
permissions  rwrr 
9889  1 
(* Title: FOL/simpdata.ML 
0  2 
ID: $Id$ 
1459  3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 
282  4 
Copyright 1994 University of Cambridge 
0  5 

9889  6 
Simplification data for FOL. 
0  7 
*) 
8 

282  9 
(*Make metaequalities. The operator below is Trueprop*) 
5555  10 

282  11 
fun mk_meta_eq th = case concl_of th of 
26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

12 
_ $ (Const("op =",_)$_$_) => th RS @{thm eq_reflection} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

13 
 _ $ (Const("op <>",_)$_$_) => th RS @{thm iff_reflection} 
10431  14 
 _ => 
5555  15 
error("conclusion must be a =equality or <>");; 
16 

17 
fun mk_eq th = case concl_of th of 

394
432bb9995893
Modified mk_meta_eq to leave metaequlities on unchanged.
nipkow
parents:
371
diff
changeset

18 
Const("==",_)$_$_ => th 
5555  19 
 _ $ (Const("op =",_)$_$_) => mk_meta_eq th 
20 
 _ $ (Const("op <>",_)$_$_) => mk_meta_eq th 

26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

21 
 _ $ (Const("Not",_)$_) => th RS @{thm iff_reflection_F} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

22 
 _ => th RS @{thm iff_reflection_T}; 
0  23 

6114
45958e54d72e
congruence rules finally use == instead of = and <>
paulson
parents:
5555
diff
changeset

24 
(*Replace premises x=y, X<>Y by X==Y*) 
10431  25 
val mk_meta_prems = 
26 
rule_by_tactic 

26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

27 
(REPEAT_FIRST (resolve_tac [@{thm meta_eq_to_obj_eq}, @{thm def_imp_iff}])); 
6114
45958e54d72e
congruence rules finally use == instead of = and <>
paulson
parents:
5555
diff
changeset

28 

9713  29 
(*Congruence rules for = or <> (instead of ==)*) 
6114
45958e54d72e
congruence rules finally use == instead of = and <>
paulson
parents:
5555
diff
changeset

30 
fun mk_meta_cong rl = 
45958e54d72e
congruence rules finally use == instead of = and <>
paulson
parents:
5555
diff
changeset

31 
standard(mk_meta_eq (mk_meta_prems rl)) 
45958e54d72e
congruence rules finally use == instead of = and <>
paulson
parents:
5555
diff
changeset

32 
handle THM _ => 
45958e54d72e
congruence rules finally use == instead of = and <>
paulson
parents:
5555
diff
changeset

33 
error("Premises and conclusion of congruence rules must use =equality or <>"); 
5555  34 

5304  35 
val mksimps_pairs = 
26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

36 
[("op >", [@{thm mp}]), ("op &", [@{thm conjunct1}, @{thm conjunct2}]), 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

37 
("All", [@{thm spec}]), ("True", []), ("False", [])]; 
5304  38 

16019  39 
(* ###FIXME: move to simplifier.ML 
5304  40 
val mk_atomize: (string * thm list) list > thm > thm list 
41 
*) 

16019  42 
(* ###FIXME: move to simplifier.ML *) 
5304  43 
fun mk_atomize pairs = 
44 
let fun atoms th = 

45 
(case concl_of th of 

46 
Const("Trueprop",_) $ p => 

47 
(case head_of p of 

48 
Const(a,_) => 

17325  49 
(case AList.lookup (op =) pairs a of 
15570  50 
SOME(rls) => List.concat (map atoms ([th] RL rls)) 
15531  51 
 NONE => [th]) 
5304  52 
 _ => [th]) 
53 
 _ => [th]) 

54 
in atoms end; 

55 

12725  56 
fun mksimps pairs = (map mk_eq o mk_atomize pairs o gen_all); 
981  57 

1914  58 

4349
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

59 
(** make simplification procedures for quantifier elimination **) 
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

60 
structure Quantifier1 = Quantifier1Fun( 
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

61 
struct 
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

62 
(*abstract syntax*) 
15531  63 
fun dest_eq((c as Const("op =",_)) $ s $ t) = SOME(c,s,t) 
64 
 dest_eq _ = NONE; 

65 
fun dest_conj((c as Const("op &",_)) $ s $ t) = SOME(c,s,t) 

66 
 dest_conj _ = NONE; 

67 
fun dest_imp((c as Const("op >",_)) $ s $ t) = SOME(c,s,t) 

68 
 dest_imp _ = NONE; 

4349
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

69 
val conj = FOLogic.conj 
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

70 
val imp = FOLogic.imp 
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

71 
(*rules*) 
26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

72 
val iff_reflection = @{thm iff_reflection} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

73 
val iffI = @{thm iffI} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

74 
val iff_trans = @{thm iff_trans} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

75 
val conjI= @{thm conjI} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

76 
val conjE= @{thm conjE} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

77 
val impI = @{thm impI} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

78 
val mp = @{thm mp} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

79 
val uncurry = @{thm uncurry} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

80 
val exI = @{thm exI} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

81 
val exE = @{thm exE} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

82 
val iff_allI = @{thm iff_allI} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

83 
val iff_exI = @{thm iff_exI} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

84 
val all_comm = @{thm all_comm} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

85 
val ex_comm = @{thm ex_comm} 
4349
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

86 
end); 
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

87 

13462  88 
val defEX_regroup = 
17002  89 
Simplifier.simproc (the_context ()) 
13462  90 
"defined EX" ["EX x. P(x)"] Quantifier1.rearrange_ex; 
4349
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

91 

50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

92 
val defALL_regroup = 
17002  93 
Simplifier.simproc (the_context ()) 
13462  94 
"defined ALL" ["ALL x. P(x)"] Quantifier1.rearrange_all; 
4349
50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

95 

50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

96 

50403e5a44c0
Instantiated the onepointrule quantifier simpprocs for FOL
paulson
parents:
4325
diff
changeset

97 
(*** Case splitting ***) 
0  98 

5304  99 
structure SplitterData = 
100 
struct 

101 
structure Simplifier = Simplifier 

5555  102 
val mk_eq = mk_eq 
26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

103 
val meta_eq_to_iff = @{thm meta_eq_to_iff} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

104 
val iffD = @{thm iffD2} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

105 
val disjE = @{thm disjE} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

106 
val conjE = @{thm conjE} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

107 
val exE = @{thm exE} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

108 
val contrapos = @{thm contrapos} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

109 
val contrapos2 = @{thm contrapos2} 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

110 
val notnotD = @{thm notnotD} 
5304  111 
end; 
1722  112 

5304  113 
structure Splitter = SplitterFun(SplitterData); 
1722  114 

5304  115 
val split_tac = Splitter.split_tac; 
116 
val split_inside_tac = Splitter.split_inside_tac; 

117 
val split_asm_tac = Splitter.split_asm_tac; 

5307  118 
val op addsplits = Splitter.addsplits; 
119 
val op delsplits = Splitter.delsplits; 

5304  120 
val Addsplits = Splitter.Addsplits; 
121 
val Delsplits = Splitter.Delsplits; 

4325  122 

123 

2074
30a65172e003
Added the de Morgan laws (incl quantifier versions) to basic simpset
paulson
parents:
2065
diff
changeset

124 
(*** Standard simpsets ***) 
30a65172e003
Added the de Morgan laws (incl quantifier versions) to basic simpset
paulson
parents:
2065
diff
changeset

125 

26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

126 
val triv_rls = [@{thm TrueI}, @{thm refl}, reflexive_thm, @{thm iff_refl}, @{thm notFalseI}]; 
2074
30a65172e003
Added the de Morgan laws (incl quantifier versions) to basic simpset
paulson
parents:
2065
diff
changeset

127 

26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

128 
fun unsafe_solver prems = FIRST'[resolve_tac (triv_rls @ prems), 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

129 
atac, etac @{thm FalseE}]; 
2633
37c0b5a7ee5d
added delcongs, Delcongs, unsafe_solver, safe_solver, FOL_basic_ss,
oheimb
parents:
2601
diff
changeset

130 
(*No premature instantiation of variables during simplification*) 
26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

131 
fun safe_solver prems = FIRST'[match_tac (triv_rls @ prems), 
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

132 
eq_assume_tac, ematch_tac [@{thm FalseE}]]; 
2633
37c0b5a7ee5d
added delcongs, Delcongs, unsafe_solver, safe_solver, FOL_basic_ss,
oheimb
parents:
2601
diff
changeset

133 

3910  134 
(*No simprules, but basic infastructure for simplification*) 
17892  135 
val FOL_basic_ss = 
28262
aa7ca36d67fd
back to dynamic the_context(), because static @{theory} is invalidated if ML environment changes within the same code block;
wenzelm
parents:
27338
diff
changeset

136 
Simplifier.theory_context (the_context ()) empty_ss 
10431  137 
setsubgoaler asm_simp_tac 
138 
setSSolver (mk_solver "FOL safe" safe_solver) 

139 
setSolver (mk_solver "FOL unsafe" unsafe_solver) 

140 
setmksimps (mksimps mksimps_pairs) 

141 
setmkcong mk_meta_cong; 

5304  142 

18324  143 
fun unfold_tac ths = 
144 
let val ss0 = Simplifier.clear_ss FOL_basic_ss addsimps ths 

145 
in fn ss => ALLGOALS (full_simp_tac (Simplifier.inherit_context ss ss0)) end; 

17002  146 

2633
37c0b5a7ee5d
added delcongs, Delcongs, unsafe_solver, safe_solver, FOL_basic_ss,
oheimb
parents:
2601
diff
changeset

147 

3910  148 
(*intuitionistic simprules only*) 
21539  149 
val IFOL_ss = 
150 
FOL_basic_ss 

26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

151 
addsimps (@{thms meta_simps} @ @{thms IFOL_simps} @ @{thms int_ex_simps} @ @{thms int_all_simps}) 
10431  152 
addsimprocs [defALL_regroup, defEX_regroup] 
26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

153 
addcongs [@{thm imp_cong}]; 
2074
30a65172e003
Added the de Morgan laws (incl quantifier versions) to basic simpset
paulson
parents:
2065
diff
changeset

154 

3910  155 
(*classical simprules too*) 
26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

156 
val FOL_ss = IFOL_ss addsimps (@{thms cla_simps} @ @{thms cla_ex_simps} @ @{thms cla_all_simps}); 
2074
30a65172e003
Added the de Morgan laws (incl quantifier versions) to basic simpset
paulson
parents:
2065
diff
changeset

157 

26496
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26288
diff
changeset

158 
val simpsetup = Simplifier.map_simpset (K FOL_ss); 
2633
37c0b5a7ee5d
added delcongs, Delcongs, unsafe_solver, safe_solver, FOL_basic_ss,
oheimb
parents:
2601
diff
changeset

159 

37c0b5a7ee5d
added delcongs, Delcongs, unsafe_solver, safe_solver, FOL_basic_ss,
oheimb
parents:
2601
diff
changeset

160 

5219  161 
(*** integration of simplifier with classical reasoner ***) 
2633
37c0b5a7ee5d
added delcongs, Delcongs, unsafe_solver, safe_solver, FOL_basic_ss,
oheimb
parents:
2601
diff
changeset

162 

5219  163 
structure Clasimp = ClasimpFun 
8472  164 
(structure Simplifier = Simplifier and Splitter = Splitter 
9851  165 
and Classical = Cla and Blast = Blast 
26288
89b9f7c18631
eliminated outofscope proofs (cf. theory IFOL and FOL);
wenzelm
parents:
22822
diff
changeset

166 
val iffD1 = @{thm iffD1} val iffD2 = @{thm iffD2} val notE = @{thm notE}); 
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
4649
diff
changeset

167 
open Clasimp; 
2633
37c0b5a7ee5d
added delcongs, Delcongs, unsafe_solver, safe_solver, FOL_basic_ss,
oheimb
parents:
2601
diff
changeset

168 

27338  169 
ML_Antiquote.value "clasimpset" 
170 
(Scan.succeed "Clasimp.local_clasimpset_of (ML_Context.the_local_context ())"); 

22128  171 

2633
37c0b5a7ee5d
added delcongs, Delcongs, unsafe_solver, safe_solver, FOL_basic_ss,
oheimb
parents:
2601
diff
changeset

172 
val FOL_css = (FOL_cs, FOL_ss); 