author  lcp 
Tue, 18 Jan 1994 15:57:40 +0100  
changeset 230  ec8a2b6aa8a7 
parent 229  4002c4cd450c 
child 252  7532f95d7f44 
permissions  rwrr 
199  1 
(* Title: Pure/drule.ML 
0  2 
ID: $Id$ 
3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 

4 
Copyright 1993 University of Cambridge 

5 

6 
Derived rules and other operations on theorems and theories 

7 
*) 

8 

11
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

9 
infix 0 RS RSN RL RLN MRS MRL COMP; 
0  10 

11 
signature DRULE = 

12 
sig 

13 
structure Thm : THM 

14 
local open Thm in 

15 
val asm_rl: thm 

16 
val assume_ax: theory > string > thm 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

17 
val cterm_fun: (term > term) > (cterm > cterm) 
0  18 
val COMP: thm * thm > thm 
19 
val compose: thm * int * thm > thm list 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

20 
val cterm_instantiate: (cterm*cterm)list > thm > thm 
0  21 
val cut_rl: thm 
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

22 
val equal_abs_elim: cterm > thm > thm 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

23 
val equal_abs_elim_list: cterm list > thm > thm 
0  24 
val eq_sg: Sign.sg * Sign.sg > bool 
25 
val eq_thm: thm * thm > bool 

26 
val eq_thm_sg: thm * thm > bool 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

27 
val flexpair_abs_elim_list: cterm list > thm > thm 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

28 
val forall_intr_list: cterm list > thm > thm 
0  29 
val forall_intr_frees: thm > thm 
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

30 
val forall_elim_list: cterm list > thm > thm 
0  31 
val forall_elim_var: int > thm > thm 
32 
val forall_elim_vars: int > thm > thm 

33 
val implies_elim_list: thm > thm list > thm 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

34 
val implies_intr_list: cterm list > thm > thm 
11
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

35 
val MRL: thm list list * thm list > thm list 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

36 
val MRS: thm list * thm > thm 
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

37 
val pprint_cterm: cterm > pprint_args > unit 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

38 
val pprint_ctyp: ctyp > pprint_args > unit 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

39 
val pprint_sg: Sign.sg > pprint_args > unit 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

40 
val pprint_theory: theory > pprint_args > unit 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

41 
val pprint_thm: thm > pprint_args > unit 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

42 
val pretty_thm: thm > Sign.Syntax.Pretty.T 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

43 
val print_cterm: cterm > unit 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

44 
val print_ctyp: ctyp > unit 
0  45 
val print_goals: int > thm > unit 
67  46 
val print_goals_ref: (int > thm > unit) ref 
0  47 
val print_sg: Sign.sg > unit 
48 
val print_theory: theory > unit 

49 
val print_thm: thm > unit 

50 
val prth: thm > thm 

51 
val prthq: thm Sequence.seq > thm Sequence.seq 

52 
val prths: thm list > thm list 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

53 
val read_ctyp: Sign.sg > string > ctyp 
0  54 
val read_instantiate: (string*string)list > thm > thm 
55 
val read_instantiate_sg: Sign.sg > (string*string)list > thm > thm 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

56 
val read_insts: 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

57 
Sign.sg > (indexname > typ option) * (indexname > sort option) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

58 
> (indexname > typ option) * (indexname > sort option) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

59 
> (string*string)list 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

60 
> (indexname*ctyp)list * (cterm*cterm)list 
0  61 
val reflexive_thm: thm 
62 
val revcut_rl: thm 

214
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

63 
val rewrite_goal_rule: bool*bool > (meta_simpset > thm > thm option) 
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

64 
> meta_simpset > int > thm > thm 
0  65 
val rewrite_goals_rule: thm list > thm > thm 
66 
val rewrite_rule: thm list > thm > thm 

67 
val RS: thm * thm > thm 

68 
val RSN: thm * (int * thm) > thm 

69 
val RL: thm list * thm list > thm list 

70 
val RLN: thm list * (int * thm list) > thm list 

71 
val show_hyps: bool ref 

72 
val size_of_thm: thm > int 

73 
val standard: thm > thm 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

74 
val string_of_cterm: cterm > string 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

75 
val string_of_ctyp: ctyp > string 
0  76 
val string_of_thm: thm > string 
77 
val symmetric_thm: thm 

78 
val transitive_thm: thm 

79 
val triv_forall_equality: thm 

80 
val types_sorts: thm > (indexname> typ option) * (indexname> sort option) 

81 
val zero_var_indexes: thm > thm 

82 
end 

83 
end; 

84 

210
49497bdf573e
commented out sig constraint of functor (for debugging purposes);
wenzelm
parents:
199
diff
changeset

85 
functor DruleFun (structure Logic: LOGIC and Thm: THM)(* : DRULE *) = (* FIXME *) 
0  86 
struct 
87 
structure Thm = Thm; 

88 
structure Sign = Thm.Sign; 

89 
structure Type = Sign.Type; 

90 
structure Pretty = Sign.Syntax.Pretty 

91 
local open Thm 

92 
in 

93 

94 
(**** More derived rules and operations on theorems ****) 

95 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

96 
fun cterm_fun f ct = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

97 
let val {sign,t,...} = rep_cterm ct in cterm_of sign (f t) end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

98 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

99 
fun read_ctyp sign = ctyp_of sign o Sign.read_typ(sign, K None); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

100 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

101 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

102 
(** reading of instantiations **) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

103 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

104 
fun indexname cs = case Syntax.scan_varname cs of (v,[]) => v 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

105 
 _ => error("Lexical error in variable name " ^ quote (implode cs)); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

106 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

107 
fun absent ixn = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

108 
error("No such variable in term: " ^ Syntax.string_of_vname ixn); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

109 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

110 
fun inst_failure ixn = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

111 
error("Instantiation of " ^ Syntax.string_of_vname ixn ^ " fails"); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

112 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

113 
fun read_insts sign (rtypes,rsorts) (types,sorts) insts = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

114 
let val {tsig,...} = Sign.rep_sg sign 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

115 
fun split([],tvs,vs) = (tvs,vs) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

116 
 split((sv,st)::l,tvs,vs) = (case explode sv of 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

117 
"'"::cs => split(l,(indexname cs,st)::tvs,vs) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

118 
 cs => split(l,tvs,(indexname cs,st)::vs)); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

119 
val (tvs,vs) = split(insts,[],[]); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

120 
fun readT((a,i),st) = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

121 
let val ixn = ("'" ^ a,i); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

122 
val S = case rsorts ixn of Some S => S  None => absent ixn; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

123 
val T = Sign.read_typ (sign,sorts) st; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

124 
in if Type.typ_instance(tsig,T,TVar(ixn,S)) then (ixn,T) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

125 
else inst_failure ixn 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

126 
end 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

127 
val tye = map readT tvs; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

128 
fun add_cterm ((cts,tye), (ixn,st)) = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

129 
let val T = case rtypes ixn of 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

130 
Some T => typ_subst_TVars tye T 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

131 
 None => absent ixn; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

132 
val (ct,tye2) = read_def_cterm (sign,types,sorts) (st,T); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

133 
val cv = cterm_of sign (Var(ixn,typ_subst_TVars tye2 T)) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

134 
in ((cv,ct)::cts,tye2 @ tye) end 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

135 
val (cterms,tye') = foldl add_cterm (([],tye), vs); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

136 
in (map (fn (ixn,T) => (ixn,ctyp_of sign T)) tye', cterms) end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

137 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

138 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

139 
(*** Printing of theorems ***) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

140 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

141 
(*If false, hypotheses are printed as dots*) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

142 
val show_hyps = ref true; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

143 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

144 
fun pretty_thm th = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

145 
let val {sign, hyps, prop,...} = rep_thm th 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

146 
val hsymbs = if null hyps then [] 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

147 
else if !show_hyps then 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

148 
[Pretty.brk 2, 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

149 
Pretty.lst("[","]") (map (Sign.pretty_term sign) hyps)] 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

150 
else Pretty.str" [" :: map (fn _ => Pretty.str".") hyps @ 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

151 
[Pretty.str"]"]; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

152 
in Pretty.blk(0, Sign.pretty_term sign prop :: hsymbs) end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

153 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

154 
val string_of_thm = Pretty.string_of o pretty_thm; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

155 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

156 
val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

157 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

158 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

159 
(** Toplevel commands for printing theorems **) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

160 
val print_thm = writeln o string_of_thm; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

161 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

162 
fun prth th = (print_thm th; th); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

163 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

164 
(*Print and return a sequence of theorems, separated by blank lines. *) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

165 
fun prthq thseq = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

166 
(Sequence.prints (fn _ => print_thm) 100000 thseq; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

167 
thseq); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

168 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

169 
(*Print and return a list of theorems, separated by blank lines. *) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

170 
fun prths ths = (print_list_ln print_thm ths; ths); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

171 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

172 
(*Other printing commands*) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

173 
fun pprint_ctyp cT = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

174 
let val {sign,T} = rep_ctyp cT in Sign.pprint_typ sign T end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

175 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

176 
fun string_of_ctyp cT = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

177 
let val {sign,T} = rep_ctyp cT in Sign.string_of_typ sign T end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

178 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

179 
val print_ctyp = writeln o string_of_ctyp; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

180 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

181 
fun pprint_cterm ct = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

182 
let val {sign,t,...} = rep_cterm ct in Sign.pprint_term sign t end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

183 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

184 
fun string_of_cterm ct = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

185 
let val {sign,t,...} = rep_cterm ct in Sign.string_of_term sign t end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

186 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

187 
val print_cterm = writeln o string_of_cterm; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

188 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

189 
fun pretty_sg sg = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

190 
Pretty.lst ("{", "}") (map (Pretty.str o !) (#stamps (Sign.rep_sg sg))); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

191 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

192 
val pprint_sg = Pretty.pprint o pretty_sg; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

193 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

194 
val pprint_theory = pprint_sg o sign_of; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

195 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

196 
val print_sg = writeln o Pretty.string_of o pretty_sg; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

197 
val print_theory = print_sg o sign_of; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

198 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

199 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

200 
(** Print thm A1,...,An/B in "goal style"  premises as numbered subgoals **) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

201 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

202 
fun prettyprints es = writeln(Pretty.string_of(Pretty.blk(0,es))); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

203 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

204 
fun print_goals maxgoals th : unit = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

205 
let val {sign, hyps, prop,...} = rep_thm th; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

206 
fun printgoals (_, []) = () 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

207 
 printgoals (n, A::As) = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

208 
let val prettyn = Pretty.str(" " ^ string_of_int n ^ ". "); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

209 
val prettyA = Sign.pretty_term sign A 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

210 
in prettyprints[prettyn,prettyA]; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

211 
printgoals (n+1,As) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

212 
end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

213 
fun prettypair(t,u) = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

214 
Pretty.blk(0, [Sign.pretty_term sign t, Pretty.str" =?=", Pretty.brk 1, 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

215 
Sign.pretty_term sign u]); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

216 
fun printff [] = () 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

217 
 printff tpairs = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

218 
writeln("\nFlexflex pairs:\n" ^ 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

219 
Pretty.string_of(Pretty.lst("","") (map prettypair tpairs))) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

220 
val (tpairs,As,B) = Logic.strip_horn(prop); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

221 
val ngoals = length As 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

222 
in 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

223 
writeln (Sign.string_of_term sign B); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

224 
if ngoals=0 then writeln"No subgoals!" 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

225 
else if ngoals>maxgoals 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

226 
then (printgoals (1, take(maxgoals,As)); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

227 
writeln("A total of " ^ string_of_int ngoals ^ " subgoals...")) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

228 
else printgoals (1, As); 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

229 
printff tpairs 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

230 
end; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

231 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

232 
(*"hook" for user interfaces: allows print_goals to be replaced*) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

233 
val print_goals_ref = ref print_goals; 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

234 

0  235 
(*** Find the type (sort) associated with a (T)Var or (T)Free in a term 
236 
Used for establishing default types (of variables) and sorts (of 

237 
type variables) when reading another term. 

238 
Index 1 indicates that a (T)Free rather than a (T)Var is wanted. 

239 
***) 

240 

241 
fun types_sorts thm = 

242 
let val {prop,hyps,...} = rep_thm thm; 

243 
val big = list_comb(prop,hyps); (* bogus term! *) 

244 
val vars = map dest_Var (term_vars big); 

245 
val frees = map dest_Free (term_frees big); 

246 
val tvars = term_tvars big; 

247 
val tfrees = term_tfrees big; 

248 
fun typ(a,i) = if i<0 then assoc(frees,a) else assoc(vars,(a,i)); 

249 
fun sort(a,i) = if i<0 then assoc(tfrees,a) else assoc(tvars,(a,i)); 

250 
in (typ,sort) end; 

251 

252 
(** Standardization of rules **) 

253 

254 
(*Generalization over a list of variables, IGNORING bad ones*) 

255 
fun forall_intr_list [] th = th 

256 
 forall_intr_list (y::ys) th = 

257 
let val gth = forall_intr_list ys th 

258 
in forall_intr y gth handle THM _ => gth end; 

259 

260 
(*Generalization over all suitable Free variables*) 

261 
fun forall_intr_frees th = 

262 
let val {prop,sign,...} = rep_thm th 

263 
in forall_intr_list 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

264 
(map (cterm_of sign) (sort atless (term_frees prop))) 
0  265 
th 
266 
end; 

267 

268 
(*Replace outermost quantified variable by Var of given index. 

269 
Could clash with Vars already present.*) 

270 
fun forall_elim_var i th = 

271 
let val {prop,sign,...} = rep_thm th 

272 
in case prop of 

273 
Const("all",_) $ Abs(a,T,_) => 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

274 
forall_elim (cterm_of sign (Var((a,i), T))) th 
0  275 
 _ => raise THM("forall_elim_var", i, [th]) 
276 
end; 

277 

278 
(*Repeat forall_elim_var until all outer quantifiers are removed*) 

279 
fun forall_elim_vars i th = 

280 
forall_elim_vars i (forall_elim_var i th) 

281 
handle THM _ => th; 

282 

283 
(*Specialization over a list of cterms*) 

284 
fun forall_elim_list cts th = foldr (uncurry forall_elim) (rev cts, th); 

285 

286 
(* maps [A1,...,An], B to [ A1;...;An ] ==> B *) 

287 
fun implies_intr_list cAs th = foldr (uncurry implies_intr) (cAs,th); 

288 

289 
(* maps [ A1;...;An ] ==> B and [A1,...,An] to B *) 

290 
fun implies_elim_list impth ths = foldl (uncurry implies_elim) (impth,ths); 

291 

292 
(*Reset Var indexes to zero, renaming to preserve distinctness*) 

293 
fun zero_var_indexes th = 

294 
let val {prop,sign,...} = rep_thm th; 

295 
val vars = term_vars prop 

296 
val bs = foldl add_new_id ([], map (fn Var((a,_),_)=>a) vars) 

297 
val inrs = add_term_tvars(prop,[]); 

298 
val nms' = rev(foldl add_new_id ([], map (#1 o #1) inrs)); 

299 
val tye = map (fn ((v,rs),a) => (v, TVar((a,0),rs))) (inrs ~~ nms') 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

300 
val ctye = map (fn (v,T) => (v,ctyp_of sign T)) tye; 
0  301 
fun varpairs([],[]) = [] 
302 
 varpairs((var as Var(v,T)) :: vars, b::bs) = 

303 
let val T' = typ_subst_TVars tye T 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

304 
in (cterm_of sign (Var(v,T')), 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

305 
cterm_of sign (Var((b,0),T'))) :: varpairs(vars,bs) 
0  306 
end 
307 
 varpairs _ = raise TERM("varpairs", []); 

308 
in instantiate (ctye, varpairs(vars,rev bs)) th end; 

309 

310 

311 
(*Standard form of objectrule: no hypotheses, Frees, or outer quantifiers; 

312 
all generality expressed by Vars having index 0.*) 

313 
fun standard th = 

314 
let val {maxidx,...} = rep_thm th 

315 
in varifyT (zero_var_indexes (forall_elim_vars(maxidx+1) 

316 
(forall_intr_frees(implies_intr_hyps th)))) 

317 
end; 

318 

319 
(*Assume a new formula, read following the same conventions as axioms. 

320 
Generalizes over Free variables, 

321 
creates the assumption, and then strips quantifiers. 

322 
Example is [ ALL x:?A. ?P(x) ] ==> [ ?P(?a) ] 

323 
[ !(A,P,a)[ ALL x:A. P(x) ] ==> [ P(a) ] ] *) 

324 
fun assume_ax thy sP = 

325 
let val sign = sign_of thy 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

326 
val prop = Logic.close_form (term_of (read_cterm sign 
0  327 
(sP, propT))) 
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

328 
in forall_elim_vars 0 (assume (cterm_of sign prop)) end; 
0  329 

330 
(*Resolution: exactly one resolvent must be produced.*) 

331 
fun tha RSN (i,thb) = 

332 
case Sequence.chop (2, biresolution false [(false,tha)] i thb) of 

333 
([th],_) => th 

334 
 ([],_) => raise THM("RSN: no unifiers", i, [tha,thb]) 

335 
 _ => raise THM("RSN: multiple unifiers", i, [tha,thb]); 

336 

337 
(*resolution: P==>Q, Q==>R gives P==>R. *) 

338 
fun tha RS thb = tha RSN (1,thb); 

339 

340 
(*For joining lists of rules*) 

341 
fun thas RLN (i,thbs) = 

342 
let val resolve = biresolution false (map (pair false) thas) i 

343 
fun resb thb = Sequence.list_of_s (resolve thb) handle THM _ => [] 

344 
in flat (map resb thbs) end; 

345 

346 
fun thas RL thbs = thas RLN (1,thbs); 

347 

11
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

348 
(*Resolve a list of rules against bottom_rl from right to left; 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

349 
makes proof trees*) 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

350 
fun rls MRS bottom_rl = 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

351 
let fun rs_aux i [] = bottom_rl 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

352 
 rs_aux i (rl::rls) = rl RSN (i, rs_aux (i+1) rls) 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

353 
in rs_aux 1 rls end; 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

354 

d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

355 
(*As above, but for rule lists*) 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

356 
fun rlss MRL bottom_rls = 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

357 
let fun rs_aux i [] = bottom_rls 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

358 
 rs_aux i (rls::rlss) = rls RLN (i, rs_aux (i+1) rlss) 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

359 
in rs_aux 1 rlss end; 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

360 

0  361 
(*compose Q and [...,Qi,Q(i+1),...]==>R to [...,Q(i+1),...]==>R 
362 
with no lifting or renaming! Q may contain ==> or metaquants 

363 
ALWAYS deletes premise i *) 

364 
fun compose(tha,i,thb) = 

365 
Sequence.list_of_s (bicompose false (false,tha,0) i thb); 

366 

367 
(*compose Q and [Q1,Q2,...,Qk]==>R to [Q2,...,Qk]==>R getting unique result*) 

368 
fun tha COMP thb = 

369 
case compose(tha,1,thb) of 

370 
[th] => th 

371 
 _ => raise THM("COMP", 1, [tha,thb]); 

372 

373 
(*Instantiate theorem th, reading instantiations under signature sg*) 

374 
fun read_instantiate_sg sg sinsts th = 

375 
let val ts = types_sorts th; 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

376 
in instantiate (read_insts sg ts ts sinsts) th end; 
0  377 

378 
(*Instantiate theorem th, reading instantiations under theory of th*) 

379 
fun read_instantiate sinsts th = 

380 
read_instantiate_sg (#sign (rep_thm th)) sinsts th; 

381 

382 

383 
(*Lefttoright replacements: tpairs = [...,(vi,ti),...]. 

384 
Instantiates distinct Vars by terms, inferring type instantiations. *) 

385 
local 

386 
fun add_types ((ct,cu), (sign,tye)) = 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

387 
let val {sign=signt, t=t, T= T, ...} = rep_cterm ct 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

388 
and {sign=signu, t=u, T= U, ...} = rep_cterm cu 
0  389 
val sign' = Sign.merge(sign, Sign.merge(signt, signu)) 
390 
val tye' = Type.unify (#tsig(Sign.rep_sg sign')) ((T,U), tye) 

391 
handle Type.TUNIFY => raise TYPE("add_types", [T,U], [t,u]) 

392 
in (sign', tye') end; 

393 
in 

394 
fun cterm_instantiate ctpairs0 th = 

395 
let val (sign,tye) = foldr add_types (ctpairs0, (#sign(rep_thm th),[])) 

396 
val tsig = #tsig(Sign.rep_sg sign); 

397 
fun instT(ct,cu) = let val inst = subst_TVars tye 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

398 
in (cterm_fun inst ct, cterm_fun inst cu) end 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

399 
fun ctyp2 (ix,T) = (ix, ctyp_of sign T) 
0  400 
in instantiate (map ctyp2 tye, map instT ctpairs0) th end 
401 
handle TERM _ => 

402 
raise THM("cterm_instantiate: incompatible signatures",0,[th]) 

403 
 TYPE _ => raise THM("cterm_instantiate: types", 0, [th]) 

404 
end; 

405 

406 

407 
(** theorem equality test is exported and used by BEST_FIRST **) 

408 

409 
(*equality of signatures means exact identity  by ref equality*) 

410 
fun eq_sg (sg1,sg2) = (#stamps(Sign.rep_sg sg1) = #stamps(Sign.rep_sg sg2)); 

411 

412 
(*equality of theorems uses equality of signatures and 

413 
the aconvertible test for terms*) 

414 
fun eq_thm (th1,th2) = 

415 
let val {sign=sg1, hyps=hyps1, prop=prop1, ...} = rep_thm th1 

416 
and {sign=sg2, hyps=hyps2, prop=prop2, ...} = rep_thm th2 

417 
in eq_sg (sg1,sg2) andalso 

418 
aconvs(hyps1,hyps2) andalso 

419 
prop1 aconv prop2 

420 
end; 

421 

422 
(*Do the two theorems have the same signature?*) 

423 
fun eq_thm_sg (th1,th2) = eq_sg(#sign(rep_thm th1), #sign(rep_thm th2)); 

424 

425 
(*Useful "distance" function for BEST_FIRST*) 

426 
val size_of_thm = size_of_term o #prop o rep_thm; 

427 

428 

429 
(*** MetaRewriting Rules ***) 

430 

431 

432 
val reflexive_thm = 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

433 
let val cx = cterm_of Sign.pure (Var(("x",0),TVar(("'a",0),["logic"]))) 
0  434 
in Thm.reflexive cx end; 
435 

436 
val symmetric_thm = 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

437 
let val xy = read_cterm Sign.pure ("x::'a::logic == y",propT) 
0  438 
in standard(Thm.implies_intr_hyps(Thm.symmetric(Thm.assume xy))) end; 
439 

440 
val transitive_thm = 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

441 
let val xy = read_cterm Sign.pure ("x::'a::logic == y",propT) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

442 
val yz = read_cterm Sign.pure ("y::'a::logic == z",propT) 
0  443 
val xythm = Thm.assume xy and yzthm = Thm.assume yz 
444 
in standard(Thm.implies_intr yz (Thm.transitive xythm yzthm)) end; 

445 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

446 
(** Below, a "conversion" has type cterm > thm **) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

447 

4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

448 
val refl_cimplies = reflexive (cterm_of Sign.pure implies); 
0  449 

450 
(*In [A1,...,An]==>B, rewrite the selected A's only  for rewrite_goals_tac*) 

214
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

451 
(*Do not rewrite flexflex pairs*) 
229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

452 
fun goals_conv pred cv = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

453 
let fun gconv i ct = 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

454 
let val (A,B) = Thm.dest_cimplies ct 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

455 
val (thA,j) = case term_of A of 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

456 
Const("=?=",_)$_$_ => (reflexive A, i) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

457 
 _ => (if pred i then cv A else reflexive A, i+1) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

458 
in combination (combination refl_cimplies thA) (gconv j B) end 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

459 
handle TERM _ => reflexive ct 
0  460 
in gconv 1 end; 
461 

462 
(*Use a conversion to transform a theorem*) 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

463 
fun fconv_rule cv th = equal_elim (cv (cprop_of th)) th; 
0  464 

465 
(*rewriting conversion*) 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

466 
fun rew_conv mode prover mss = rewrite_cterm mode mss prover; 
0  467 

468 
(*Rewrite a theorem*) 

214
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

469 
fun rewrite_rule thms = 
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

470 
fconv_rule (rew_conv (true,false) (K(K None)) (Thm.mss_of thms)); 
0  471 

472 
(*Rewrite the subgoals of a proof state (represented by a theorem) *) 

473 
fun rewrite_goals_rule thms = 

214
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

474 
fconv_rule (goals_conv (K true) (rew_conv (true,false) (K(K None)) 
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

475 
(Thm.mss_of thms))); 
0  476 

477 
(*Rewrite the subgoal of a proof state (represented by a theorem) *) 

214
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

478 
fun rewrite_goal_rule mode prover mss i thm = 
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

479 
if 0 < i andalso i <= nprems_of thm 
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

480 
then fconv_rule (goals_conv (fn j => j=i) (rew_conv mode prover mss)) thm 
ed6a3e2b1a33
added new parameter to the simplification tactics which indicates if
nipkow
parents:
211
diff
changeset

481 
else raise THM("rewrite_goal_rule",i,[thm]); 
0  482 

483 

484 
(** Derived rules mainly for METAHYPS **) 

485 

486 
(*Given the term "a", takes (%x.t)==(%x.u) to t[a/x]==u[a/x]*) 

487 
fun equal_abs_elim ca eqth = 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

488 
let val {sign=signa, t=a, ...} = rep_cterm ca 
0  489 
and combth = combination eqth (reflexive ca) 
490 
val {sign,prop,...} = rep_thm eqth 

491 
val (abst,absu) = Logic.dest_equals prop 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

492 
val cterm = cterm_of (Sign.merge (sign,signa)) 
0  493 
in transitive (symmetric (beta_conversion (cterm (abst$a)))) 
494 
(transitive combth (beta_conversion (cterm (absu$a)))) 

495 
end 

496 
handle THM _ => raise THM("equal_abs_elim", 0, [eqth]); 

497 

498 
(*Calling equal_abs_elim with multiple terms*) 

499 
fun equal_abs_elim_list cts th = foldr (uncurry equal_abs_elim) (rev cts, th); 

500 

501 
local 

502 
open Logic 

503 
val alpha = TVar(("'a",0), []) (* type ?'a::{} *) 

504 
fun err th = raise THM("flexpair_inst: ", 0, [th]) 

505 
fun flexpair_inst def th = 

506 
let val {prop = Const _ $ t $ u, sign,...} = rep_thm th 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

507 
val cterm = cterm_of sign 
0  508 
fun cvar a = cterm(Var((a,0),alpha)) 
509 
val def' = cterm_instantiate [(cvar"t", cterm t), (cvar"u", cterm u)] 

510 
def 

511 
in equal_elim def' th 

512 
end 

513 
handle THM _ => err th  bind => err th 

514 
in 

515 
val flexpair_intr = flexpair_inst (symmetric flexpair_def) 

516 
and flexpair_elim = flexpair_inst flexpair_def 

517 
end; 

518 

519 
(*Version for flexflex pairs  this supports lifting.*) 

520 
fun flexpair_abs_elim_list cts = 

521 
flexpair_intr o equal_abs_elim_list cts o flexpair_elim; 

522 

523 

524 
(*** Some useful metatheorems ***) 

525 

526 
(*The rule V/V, obtains assumption solving for eresolve_tac*) 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

527 
val asm_rl = trivial(read_cterm Sign.pure ("PROP ?psi",propT)); 
0  528 

529 
(*Metalevel cut rule: [ V==>W; V ] ==> W *) 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

530 
val cut_rl = trivial(read_cterm Sign.pure 
0  531 
("PROP ?psi ==> PROP ?theta", propT)); 
532 

533 
(*Generalized elim rule for one conclusion; cut_rl with reversed premises: 

534 
[ PROP V; PROP V ==> PROP W ] ==> PROP W *) 

535 
val revcut_rl = 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

536 
let val V = read_cterm Sign.pure ("PROP V", propT) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

537 
and VW = read_cterm Sign.pure ("PROP V ==> PROP W", propT); 
0  538 
in standard (implies_intr V 
539 
(implies_intr VW 

540 
(implies_elim (assume VW) (assume V)))) 

541 
end; 

542 

543 
(* (!!x. PROP ?V) == PROP ?V Allows removal of redundant parameters*) 

544 
val triv_forall_equality = 

229
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

545 
let val V = read_cterm Sign.pure ("PROP V", propT) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

546 
and QV = read_cterm Sign.pure ("!!x::'a. PROP V", propT) 
4002c4cd450c
Pure: MAJOR CHANGE. Moved ML types ctyp and cterm and their associated
lcp
parents:
214
diff
changeset

547 
and x = read_cterm Sign.pure ("x", TFree("'a",["logic"])); 
0  548 
in standard (equal_intr (implies_intr QV (forall_elim x (assume QV))) 
549 
(implies_intr V (forall_intr x (assume V)))) 

550 
end; 

551 

552 
end 

553 
end; 