author  huffman 
Thu, 17 May 2007 08:41:23 +0200  
changeset 22986  d21d3539f6bb 
parent 22548  6ce4bddf3bcb 
child 22997  d4f3b015b50b 
permissions  rwrr 
14770  1 
(* Title: HOL/OrderedGroup.thy 
14738  2 
ID: $Id$ 
16775
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

3 
Author: Gertrud Bauer, Steven Obua, Lawrence C Paulson, and Markus Wenzel, 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

4 
with contributions by Jeremy Avigad 
14738  5 
*) 
6 

7 
header {* Ordered Groups *} 

8 

15131  9 
theory OrderedGroup 
22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

10 
imports Lattices 
19798  11 
uses "~~/src/Provers/Arith/abel_cancel.ML" 
15131  12 
begin 
14738  13 

14 
text {* 

15 
The theory of partially ordered groups is taken from the books: 

16 
\begin{itemize} 

17 
\item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 

18 
\item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963 

19 
\end{itemize} 

20 
Most of the used notions can also be looked up in 

21 
\begin{itemize} 

14770  22 
\item \url{http://www.mathworld.com} by Eric Weisstein et. al. 
14738  23 
\item \emph{Algebra I} by van der Waerden, Springer. 
24 
\end{itemize} 

25 
*} 

26 

27 
subsection {* Semigroups, Groups *} 

28 

22390  29 
class semigroup_add = plus + 
30 
assumes add_assoc: "(a \<^loc>+ b) \<^loc>+ c = a \<^loc>+ (b \<^loc>+ c)" 

31 

32 
class ab_semigroup_add = semigroup_add + 

33 
assumes add_commute: "a \<^loc>+ b = b \<^loc>+ a" 

14738  34 

35 
lemma add_left_commute: "a + (b + c) = b + (a + (c::'a::ab_semigroup_add))" 

36 
by (rule mk_left_commute [of "op +", OF add_assoc add_commute]) 

37 

38 
theorems add_ac = add_assoc add_commute add_left_commute 

39 

22390  40 
class semigroup_mult = times + 
41 
assumes mult_assoc: "(a \<^loc>* b) \<^loc>* c = a \<^loc>* (b \<^loc>* c)" 

14738  42 

22390  43 
class ab_semigroup_mult = semigroup_mult + 
44 
assumes mult_commute: "a \<^loc>* b = b \<^loc>* a" 

14738  45 

46 
lemma mult_left_commute: "a * (b * c) = b * (a * (c::'a::ab_semigroup_mult))" 

47 
by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute]) 

48 

49 
theorems mult_ac = mult_assoc mult_commute mult_left_commute 

50 

22390  51 
class comm_monoid_add = zero + ab_semigroup_add + 
52 
assumes add_0 [simp]: "\<^loc>0 \<^loc>+ a = a" 

14738  53 

22390  54 
class monoid_mult = one + semigroup_mult + 
55 
assumes mult_1_left [simp]: "\<^loc>1 \<^loc>* a = a" 

56 
assumes mult_1_right [simp]: "a \<^loc>* \<^loc>1 = a" 

14738  57 

22390  58 
class comm_monoid_mult = one + ab_semigroup_mult + 
59 
assumes mult_1: "\<^loc>1 \<^loc>* a = a" 

14738  60 

61 
instance comm_monoid_mult \<subseteq> monoid_mult 

22390  62 
by intro_classes (insert mult_1, simp_all add: mult_commute, auto) 
14738  63 

22390  64 
class cancel_semigroup_add = semigroup_add + 
65 
assumes add_left_imp_eq: "a \<^loc>+ b = a \<^loc>+ c \<Longrightarrow> b = c" 

66 
assumes add_right_imp_eq: "b \<^loc>+ a = c \<^loc>+ a \<Longrightarrow> b = c" 

14738  67 

22390  68 
class cancel_ab_semigroup_add = ab_semigroup_add + 
69 
assumes add_imp_eq: "a \<^loc>+ b = a \<^loc>+ c \<Longrightarrow> b = c" 

14738  70 

71 
instance cancel_ab_semigroup_add \<subseteq> cancel_semigroup_add 

22390  72 
proof intro_classes 
73 
fix a b c :: 'a 

74 
assume "a + b = a + c" 

75 
then show "b = c" by (rule add_imp_eq) 

76 
next 

14738  77 
fix a b c :: 'a 
78 
assume "b + a = c + a" 

22390  79 
then have "a + b = a + c" by (simp only: add_commute) 
80 
then show "b = c" by (rule add_imp_eq) 

14738  81 
qed 
82 

22390  83 
class ab_group_add = minus + comm_monoid_add + 
84 
assumes left_minus [simp]: "uminus a \<^loc>+ a = \<^loc>0" 

85 
assumes diff_minus: "a \<^loc> b = a \<^loc>+ (uminus b)" 

14738  86 

87 
instance ab_group_add \<subseteq> cancel_ab_semigroup_add 

22390  88 
proof intro_classes 
14738  89 
fix a b c :: 'a 
90 
assume "a + b = a + c" 

22390  91 
then have "uminus a + a + b = uminus a + a + c" unfolding add_assoc by simp 
92 
then show "b = c" by simp 

14738  93 
qed 
94 

95 
lemma add_0_right [simp]: "a + 0 = (a::'a::comm_monoid_add)" 

96 
proof  

97 
have "a + 0 = 0 + a" by (simp only: add_commute) 

98 
also have "... = a" by simp 

99 
finally show ?thesis . 

100 
qed 

101 

21245  102 
lemmas add_zero_left = add_0 
103 
and add_zero_right = add_0_right 

104 

14738  105 
lemma add_left_cancel [simp]: 
22390  106 
"a + b = a + c \<longleftrightarrow> b = (c \<Colon> 'a\<Colon>cancel_semigroup_add)" 
107 
by (blast dest: add_left_imp_eq) 

14738  108 

109 
lemma add_right_cancel [simp]: 

22390  110 
"b + a = c + a \<longleftrightarrow> b = (c \<Colon> 'a\<Colon>cancel_semigroup_add)" 
14738  111 
by (blast dest: add_right_imp_eq) 
112 

113 
lemma right_minus [simp]: "a + (a::'a::ab_group_add) = 0" 

114 
proof  

115 
have "a + a = a + a" by (simp add: add_ac) 

116 
also have "... = 0" by simp 

117 
finally show ?thesis . 

118 
qed 

119 

120 
lemma right_minus_eq: "(a  b = 0) = (a = (b::'a::ab_group_add))" 

121 
proof 

122 
have "a = a  b + b" by (simp add: diff_minus add_ac) 

123 
also assume "a  b = 0" 

124 
finally show "a = b" by simp 

125 
next 

126 
assume "a = b" 

127 
thus "a  b = 0" by (simp add: diff_minus) 

128 
qed 

129 

130 
lemma minus_minus [simp]: " ( (a::'a::ab_group_add)) = a" 

131 
proof (rule add_left_cancel [of "a", THEN iffD1]) 

132 
show "(a + (a) = a + a)" 

133 
by simp 

134 
qed 

135 

136 
lemma equals_zero_I: "a+b = 0 ==> a = (b::'a::ab_group_add)" 

137 
apply (rule right_minus_eq [THEN iffD1, symmetric]) 

138 
apply (simp add: diff_minus add_commute) 

139 
done 

140 

141 
lemma minus_zero [simp]: " 0 = (0::'a::ab_group_add)" 

142 
by (simp add: equals_zero_I) 

143 

144 
lemma diff_self [simp]: "a  (a::'a::ab_group_add) = 0" 

145 
by (simp add: diff_minus) 

146 

147 
lemma diff_0 [simp]: "(0::'a::ab_group_add)  a = a" 

148 
by (simp add: diff_minus) 

149 

150 
lemma diff_0_right [simp]: "a  (0::'a::ab_group_add) = a" 

151 
by (simp add: diff_minus) 

152 

153 
lemma diff_minus_eq_add [simp]: "a   b = a + (b::'a::ab_group_add)" 

154 
by (simp add: diff_minus) 

155 

156 
lemma neg_equal_iff_equal [simp]: "(a = b) = (a = (b::'a::ab_group_add))" 

157 
proof 

158 
assume " a =  b" 

159 
hence " ( a) =  ( b)" 

160 
by simp 

161 
thus "a=b" by simp 

162 
next 

163 
assume "a=b" 

164 
thus "a = b" by simp 

165 
qed 

166 

167 
lemma neg_equal_0_iff_equal [simp]: "(a = 0) = (a = (0::'a::ab_group_add))" 

168 
by (subst neg_equal_iff_equal [symmetric], simp) 

169 

170 
lemma neg_0_equal_iff_equal [simp]: "(0 = a) = (0 = (a::'a::ab_group_add))" 

171 
by (subst neg_equal_iff_equal [symmetric], simp) 

172 

173 
text{*The next two equations can make the simplifier loop!*} 

174 

175 
lemma equation_minus_iff: "(a =  b) = (b =  (a::'a::ab_group_add))" 

176 
proof  

177 
have "( (a) =  b) = ( a = b)" by (rule neg_equal_iff_equal) 

178 
thus ?thesis by (simp add: eq_commute) 

179 
qed 

180 

181 
lemma minus_equation_iff: "( a = b) = ( (b::'a::ab_group_add) = a)" 

182 
proof  

183 
have "( a =  (b)) = (a = b)" by (rule neg_equal_iff_equal) 

184 
thus ?thesis by (simp add: eq_commute) 

185 
qed 

186 

187 
lemma minus_add_distrib [simp]: " (a + b) = a + (b::'a::ab_group_add)" 

188 
apply (rule equals_zero_I) 

189 
apply (simp add: add_ac) 

190 
done 

191 

192 
lemma minus_diff_eq [simp]: " (a  b) = b  (a::'a::ab_group_add)" 

193 
by (simp add: diff_minus add_commute) 

194 

195 
subsection {* (Partially) Ordered Groups *} 

196 

22390  197 
class pordered_ab_semigroup_add = order + ab_semigroup_add + 
198 
assumes add_left_mono: "a \<sqsubseteq> b \<Longrightarrow> c \<^loc>+ a \<sqsubseteq> c \<^loc>+ b" 

14738  199 

22390  200 
class pordered_cancel_ab_semigroup_add = 
201 
pordered_ab_semigroup_add + cancel_ab_semigroup_add 

14738  202 

22390  203 
class pordered_ab_semigroup_add_imp_le = pordered_cancel_ab_semigroup_add + 
22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

204 
assumes add_le_imp_le_left: "c \<^loc>+ a \<sqsubseteq> c \<^loc>+ b \<Longrightarrow> a \<sqsubseteq> b" 
14738  205 

22390  206 
class pordered_ab_group_add = ab_group_add + pordered_ab_semigroup_add 
14738  207 

208 
instance pordered_ab_group_add \<subseteq> pordered_ab_semigroup_add_imp_le 

209 
proof 

210 
fix a b c :: 'a 

211 
assume "c + a \<le> c + b" 

212 
hence "(c) + (c + a) \<le> (c) + (c + b)" by (rule add_left_mono) 

213 
hence "((c) + c) + a \<le> ((c) + c) + b" by (simp only: add_assoc) 

214 
thus "a \<le> b" by simp 

215 
qed 

216 

22390  217 
class ordered_cancel_ab_semigroup_add = pordered_cancel_ab_semigroup_add + linorder 
14738  218 

219 
instance ordered_cancel_ab_semigroup_add \<subseteq> pordered_ab_semigroup_add_imp_le 

220 
proof 

221 
fix a b c :: 'a 

222 
assume le: "c + a <= c + b" 

223 
show "a <= b" 

224 
proof (rule ccontr) 

225 
assume w: "~ a \<le> b" 

226 
hence "b <= a" by (simp add: linorder_not_le) 

227 
hence le2: "c+b <= c+a" by (rule add_left_mono) 

228 
have "a = b" 

229 
apply (insert le) 

230 
apply (insert le2) 

231 
apply (drule order_antisym, simp_all) 

232 
done 

233 
with w show False 

234 
by (simp add: linorder_not_le [symmetric]) 

235 
qed 

236 
qed 

237 

238 
lemma add_right_mono: "a \<le> (b::'a::pordered_ab_semigroup_add) ==> a + c \<le> b + c" 

22390  239 
by (simp add: add_commute [of _ c] add_left_mono) 
14738  240 

241 
text {* nonstrict, in both arguments *} 

242 
lemma add_mono: 

243 
"[a \<le> b; c \<le> d] ==> a + c \<le> b + (d::'a::pordered_ab_semigroup_add)" 

244 
apply (erule add_right_mono [THEN order_trans]) 

245 
apply (simp add: add_commute add_left_mono) 

246 
done 

247 

248 
lemma add_strict_left_mono: 

249 
"a < b ==> c + a < c + (b::'a::pordered_cancel_ab_semigroup_add)" 

250 
by (simp add: order_less_le add_left_mono) 

251 

252 
lemma add_strict_right_mono: 

253 
"a < b ==> a + c < b + (c::'a::pordered_cancel_ab_semigroup_add)" 

254 
by (simp add: add_commute [of _ c] add_strict_left_mono) 

255 

256 
text{*Strict monotonicity in both arguments*} 

257 
lemma add_strict_mono: "[a<b; c<d] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)" 

258 
apply (erule add_strict_right_mono [THEN order_less_trans]) 

259 
apply (erule add_strict_left_mono) 

260 
done 

261 

262 
lemma add_less_le_mono: 

263 
"[ a<b; c\<le>d ] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)" 

264 
apply (erule add_strict_right_mono [THEN order_less_le_trans]) 

265 
apply (erule add_left_mono) 

266 
done 

267 

268 
lemma add_le_less_mono: 

269 
"[ a\<le>b; c<d ] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)" 

270 
apply (erule add_right_mono [THEN order_le_less_trans]) 

271 
apply (erule add_strict_left_mono) 

272 
done 

273 

274 
lemma add_less_imp_less_left: 

275 
assumes less: "c + a < c + b" shows "a < (b::'a::pordered_ab_semigroup_add_imp_le)" 

276 
proof  

277 
from less have le: "c + a <= c + b" by (simp add: order_le_less) 

278 
have "a <= b" 

279 
apply (insert le) 

280 
apply (drule add_le_imp_le_left) 

281 
by (insert le, drule add_le_imp_le_left, assumption) 

282 
moreover have "a \<noteq> b" 

283 
proof (rule ccontr) 

284 
assume "~(a \<noteq> b)" 

285 
then have "a = b" by simp 

286 
then have "c + a = c + b" by simp 

287 
with less show "False"by simp 

288 
qed 

289 
ultimately show "a < b" by (simp add: order_le_less) 

290 
qed 

291 

292 
lemma add_less_imp_less_right: 

293 
"a + c < b + c ==> a < (b::'a::pordered_ab_semigroup_add_imp_le)" 

294 
apply (rule add_less_imp_less_left [of c]) 

295 
apply (simp add: add_commute) 

296 
done 

297 

298 
lemma add_less_cancel_left [simp]: 

299 
"(c+a < c+b) = (a < (b::'a::pordered_ab_semigroup_add_imp_le))" 

300 
by (blast intro: add_less_imp_less_left add_strict_left_mono) 

301 

302 
lemma add_less_cancel_right [simp]: 

303 
"(a+c < b+c) = (a < (b::'a::pordered_ab_semigroup_add_imp_le))" 

304 
by (blast intro: add_less_imp_less_right add_strict_right_mono) 

305 

306 
lemma add_le_cancel_left [simp]: 

307 
"(c+a \<le> c+b) = (a \<le> (b::'a::pordered_ab_semigroup_add_imp_le))" 

308 
by (auto, drule add_le_imp_le_left, simp_all add: add_left_mono) 

309 

310 
lemma add_le_cancel_right [simp]: 

311 
"(a+c \<le> b+c) = (a \<le> (b::'a::pordered_ab_semigroup_add_imp_le))" 

312 
by (simp add: add_commute[of a c] add_commute[of b c]) 

313 

314 
lemma add_le_imp_le_right: 

315 
"a + c \<le> b + c ==> a \<le> (b::'a::pordered_ab_semigroup_add_imp_le)" 

316 
by simp 

317 

15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

318 
lemma add_increasing: 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

319 
fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}" 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

320 
shows "[0\<le>a; b\<le>c] ==> b \<le> a + c" 
14738  321 
by (insert add_mono [of 0 a b c], simp) 
322 

15539  323 
lemma add_increasing2: 
324 
fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}" 

325 
shows "[0\<le>c; b\<le>a] ==> b \<le> a + c" 

326 
by (simp add:add_increasing add_commute[of a]) 

327 

15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

328 
lemma add_strict_increasing: 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

329 
fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}" 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

330 
shows "[0<a; b\<le>c] ==> b < a + c" 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

331 
by (insert add_less_le_mono [of 0 a b c], simp) 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

332 

ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

333 
lemma add_strict_increasing2: 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

334 
fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}" 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

335 
shows "[0\<le>a; b<c] ==> b < a + c" 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

336 
by (insert add_le_less_mono [of 0 a b c], simp) 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

337 

19527  338 
lemma max_add_distrib_left: 
339 
fixes z :: "'a::pordered_ab_semigroup_add_imp_le" 

340 
shows "(max x y) + z = max (x+z) (y+z)" 

341 
by (rule max_of_mono [THEN sym], rule add_le_cancel_right) 

342 

343 
lemma min_add_distrib_left: 

344 
fixes z :: "'a::pordered_ab_semigroup_add_imp_le" 

345 
shows "(min x y) + z = min (x+z) (y+z)" 

346 
by (rule min_of_mono [THEN sym], rule add_le_cancel_right) 

347 

348 
lemma max_diff_distrib_left: 

349 
fixes z :: "'a::pordered_ab_group_add" 

350 
shows "(max x y)  z = max (xz) (yz)" 

351 
by (simp add: diff_minus, rule max_add_distrib_left) 

352 

353 
lemma min_diff_distrib_left: 

354 
fixes z :: "'a::pordered_ab_group_add" 

355 
shows "(min x y)  z = min (xz) (yz)" 

356 
by (simp add: diff_minus, rule min_add_distrib_left) 

357 

15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15229
diff
changeset

358 

14738  359 
subsection {* Ordering Rules for Unary Minus *} 
360 

361 
lemma le_imp_neg_le: 

362 
assumes "a \<le> (b::'a::{pordered_ab_semigroup_add_imp_le, ab_group_add})" shows "b \<le> a" 

363 
proof  

364 
have "a+a \<le> a+b" 

365 
by (rule add_left_mono) 

366 
hence "0 \<le> a+b" 

367 
by simp 

368 
hence "0 + (b) \<le> (a + b) + (b)" 

369 
by (rule add_right_mono) 

370 
thus ?thesis 

371 
by (simp add: add_assoc) 

372 
qed 

373 

374 
lemma neg_le_iff_le [simp]: "(b \<le> a) = (a \<le> (b::'a::pordered_ab_group_add))" 

375 
proof 

376 
assume " b \<le>  a" 

377 
hence " ( a) \<le>  ( b)" 

378 
by (rule le_imp_neg_le) 

379 
thus "a\<le>b" by simp 

380 
next 

381 
assume "a\<le>b" 

382 
thus "b \<le> a" by (rule le_imp_neg_le) 

383 
qed 

384 

385 
lemma neg_le_0_iff_le [simp]: "(a \<le> 0) = (0 \<le> (a::'a::pordered_ab_group_add))" 

386 
by (subst neg_le_iff_le [symmetric], simp) 

387 

388 
lemma neg_0_le_iff_le [simp]: "(0 \<le> a) = (a \<le> (0::'a::pordered_ab_group_add))" 

389 
by (subst neg_le_iff_le [symmetric], simp) 

390 

391 
lemma neg_less_iff_less [simp]: "(b < a) = (a < (b::'a::pordered_ab_group_add))" 

392 
by (force simp add: order_less_le) 

393 

394 
lemma neg_less_0_iff_less [simp]: "(a < 0) = (0 < (a::'a::pordered_ab_group_add))" 

395 
by (subst neg_less_iff_less [symmetric], simp) 

396 

397 
lemma neg_0_less_iff_less [simp]: "(0 < a) = (a < (0::'a::pordered_ab_group_add))" 

398 
by (subst neg_less_iff_less [symmetric], simp) 

399 

400 
text{*The next several equations can make the simplifier loop!*} 

401 

402 
lemma less_minus_iff: "(a <  b) = (b <  (a::'a::pordered_ab_group_add))" 

403 
proof  

404 
have "( (a) <  b) = (b <  a)" by (rule neg_less_iff_less) 

405 
thus ?thesis by simp 

406 
qed 

407 

408 
lemma minus_less_iff: "( a < b) = ( b < (a::'a::pordered_ab_group_add))" 

409 
proof  

410 
have "( a <  (b)) = ( b < a)" by (rule neg_less_iff_less) 

411 
thus ?thesis by simp 

412 
qed 

413 

414 
lemma le_minus_iff: "(a \<le>  b) = (b \<le>  (a::'a::pordered_ab_group_add))" 

415 
proof  

416 
have mm: "!! a (b::'a). ((a)) < b \<Longrightarrow> (b) < a" by (simp only: minus_less_iff) 

417 
have "( ( a) <= b) = (b <=  a)" 

418 
apply (auto simp only: order_le_less) 

419 
apply (drule mm) 

420 
apply (simp_all) 

421 
apply (drule mm[simplified], assumption) 

422 
done 

423 
then show ?thesis by simp 

424 
qed 

425 

426 
lemma minus_le_iff: "( a \<le> b) = ( b \<le> (a::'a::pordered_ab_group_add))" 

427 
by (auto simp add: order_le_less minus_less_iff) 

428 

429 
lemma add_diff_eq: "a + (b  c) = (a + b)  (c::'a::ab_group_add)" 

430 
by (simp add: diff_minus add_ac) 

431 

432 
lemma diff_add_eq: "(a  b) + c = (a + c)  (b::'a::ab_group_add)" 

433 
by (simp add: diff_minus add_ac) 

434 

435 
lemma diff_eq_eq: "(ab = c) = (a = c + (b::'a::ab_group_add))" 

436 
by (auto simp add: diff_minus add_assoc) 

437 

438 
lemma eq_diff_eq: "(a = cb) = (a + (b::'a::ab_group_add) = c)" 

439 
by (auto simp add: diff_minus add_assoc) 

440 

441 
lemma diff_diff_eq: "(a  b)  c = a  (b + (c::'a::ab_group_add))" 

442 
by (simp add: diff_minus add_ac) 

443 

444 
lemma diff_diff_eq2: "a  (b  c) = (a + c)  (b::'a::ab_group_add)" 

445 
by (simp add: diff_minus add_ac) 

446 

447 
lemma diff_add_cancel: "a  b + b = (a::'a::ab_group_add)" 

448 
by (simp add: diff_minus add_ac) 

449 

450 
lemma add_diff_cancel: "a + b  b = (a::'a::ab_group_add)" 

451 
by (simp add: diff_minus add_ac) 

452 

14754
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

453 
text{*Further subtraction laws*} 
14738  454 

455 
lemma less_iff_diff_less_0: "(a < b) = (a  b < (0::'a::pordered_ab_group_add))" 

456 
proof  

457 
have "(a < b) = (a + ( b) < b + (b))" 

458 
by (simp only: add_less_cancel_right) 

459 
also have "... = (a  b < 0)" by (simp add: diff_minus) 

460 
finally show ?thesis . 

461 
qed 

462 

463 
lemma diff_less_eq: "(ab < c) = (a < c + (b::'a::pordered_ab_group_add))" 

15481  464 
apply (subst less_iff_diff_less_0 [of a]) 
14738  465 
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst]) 
466 
apply (simp add: diff_minus add_ac) 

467 
done 

468 

469 
lemma less_diff_eq: "(a < cb) = (a + (b::'a::pordered_ab_group_add) < c)" 

15481  470 
apply (subst less_iff_diff_less_0 [of "a+b"]) 
471 
apply (subst less_iff_diff_less_0 [of a]) 

14738  472 
apply (simp add: diff_minus add_ac) 
473 
done 

474 

475 
lemma diff_le_eq: "(ab \<le> c) = (a \<le> c + (b::'a::pordered_ab_group_add))" 

476 
by (auto simp add: order_le_less diff_less_eq diff_add_cancel add_diff_cancel) 

477 

478 
lemma le_diff_eq: "(a \<le> cb) = (a + (b::'a::pordered_ab_group_add) \<le> c)" 

479 
by (auto simp add: order_le_less less_diff_eq diff_add_cancel add_diff_cancel) 

480 

481 
text{*This list of rewrites simplifies (in)equalities by bringing subtractions 

482 
to the top and then moving negative terms to the other side. 

483 
Use with @{text add_ac}*} 

484 
lemmas compare_rls = 

485 
diff_minus [symmetric] 

486 
add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2 

487 
diff_less_eq less_diff_eq diff_le_eq le_diff_eq 

488 
diff_eq_eq eq_diff_eq 

489 

16775
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

490 
subsection {* Support for reasoning about signs *} 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

491 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

492 
lemma add_pos_pos: "0 < 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

493 
(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

494 
==> 0 < y ==> 0 < x + y" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

495 
apply (subgoal_tac "0 + 0 < x + y") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

496 
apply simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

497 
apply (erule add_less_le_mono) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

498 
apply (erule order_less_imp_le) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

499 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

500 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

501 
lemma add_pos_nonneg: "0 < 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

502 
(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

503 
==> 0 <= y ==> 0 < x + y" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

504 
apply (subgoal_tac "0 + 0 < x + y") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

505 
apply simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

506 
apply (erule add_less_le_mono, assumption) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

507 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

508 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

509 
lemma add_nonneg_pos: "0 <= 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

510 
(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

511 
==> 0 < y ==> 0 < x + y" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

512 
apply (subgoal_tac "0 + 0 < x + y") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

513 
apply simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

514 
apply (erule add_le_less_mono, assumption) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

515 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

516 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

517 
lemma add_nonneg_nonneg: "0 <= 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

518 
(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

519 
==> 0 <= y ==> 0 <= x + y" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

520 
apply (subgoal_tac "0 + 0 <= x + y") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

521 
apply simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

522 
apply (erule add_mono, assumption) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

523 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

524 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

525 
lemma add_neg_neg: "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

526 
< 0 ==> y < 0 ==> x + y < 0" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

527 
apply (subgoal_tac "x + y < 0 + 0") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

528 
apply simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

529 
apply (erule add_less_le_mono) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

530 
apply (erule order_less_imp_le) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

531 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

532 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

533 
lemma add_neg_nonpos: 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

534 
"(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) < 0 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

535 
==> y <= 0 ==> x + y < 0" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

536 
apply (subgoal_tac "x + y < 0 + 0") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

537 
apply simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

538 
apply (erule add_less_le_mono, assumption) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

539 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

540 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

541 
lemma add_nonpos_neg: 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

542 
"(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) <= 0 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

543 
==> y < 0 ==> x + y < 0" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

544 
apply (subgoal_tac "x + y < 0 + 0") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

545 
apply simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

546 
apply (erule add_le_less_mono, assumption) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

547 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

548 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

549 
lemma add_nonpos_nonpos: 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

550 
"(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) <= 0 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

551 
==> y <= 0 ==> x + y <= 0" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

552 
apply (subgoal_tac "x + y <= 0 + 0") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

553 
apply simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

554 
apply (erule add_mono, assumption) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

555 
done 
14738  556 

557 
subsection{*Lemmas for the @{text cancel_numerals} simproc*} 

558 

559 
lemma eq_iff_diff_eq_0: "(a = b) = (ab = (0::'a::ab_group_add))" 

560 
by (simp add: compare_rls) 

561 

562 
lemma le_iff_diff_le_0: "(a \<le> b) = (ab \<le> (0::'a::pordered_ab_group_add))" 

563 
by (simp add: compare_rls) 

564 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

565 

14738  566 
subsection {* Lattice Ordered (Abelian) Groups *} 
567 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

568 
class lordered_ab_group_meet = pordered_ab_group_add + lower_semilattice 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

569 

8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

570 
class lordered_ab_group_join = pordered_ab_group_add + upper_semilattice 
14738  571 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

572 
class lordered_ab_group = pordered_ab_group_add + lattice 
14738  573 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

574 
instance lordered_ab_group \<subseteq> lordered_ab_group_meet by default 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

575 
instance lordered_ab_group \<subseteq> lordered_ab_group_join by default 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

576 

8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

577 
lemma add_inf_distrib_left: "a + inf b c = inf (a + b) (a + (c::'a::{pordered_ab_group_add, lower_semilattice}))" 
14738  578 
apply (rule order_antisym) 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

579 
apply (simp_all add: le_infI) 
14738  580 
apply (rule add_le_imp_le_left [of "a"]) 
581 
apply (simp only: add_assoc[symmetric], simp) 

21312  582 
apply rule 
583 
apply (rule add_le_imp_le_left[of "a"], simp only: add_assoc[symmetric], simp)+ 

14738  584 
done 
585 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

586 
lemma add_sup_distrib_left: "a + sup b c = sup (a + b) (a+ (c::'a::{pordered_ab_group_add, upper_semilattice}))" 
14738  587 
apply (rule order_antisym) 
588 
apply (rule add_le_imp_le_left [of "a"]) 

589 
apply (simp only: add_assoc[symmetric], simp) 

21312  590 
apply rule 
591 
apply (rule add_le_imp_le_left [of "a"], simp only: add_assoc[symmetric], simp)+ 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

592 
apply (rule le_supI) 
21312  593 
apply (simp_all) 
14738  594 
done 
595 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

596 
lemma add_inf_distrib_right: "inf a b + (c::'a::lordered_ab_group) = inf (a+c) (b+c)" 
14738  597 
proof  
22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

598 
have "c + inf a b = inf (c+a) (c+b)" by (simp add: add_inf_distrib_left) 
14738  599 
thus ?thesis by (simp add: add_commute) 
600 
qed 

601 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

602 
lemma add_sup_distrib_right: "sup a b + (c::'a::lordered_ab_group) = sup (a+c) (b+c)" 
14738  603 
proof  
22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

604 
have "c + sup a b = sup (c+a) (c+b)" by (simp add: add_sup_distrib_left) 
14738  605 
thus ?thesis by (simp add: add_commute) 
606 
qed 

607 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

608 
lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left 
14738  609 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

610 
lemma inf_eq_neg_sup: "inf a (b\<Colon>'a\<Colon>lordered_ab_group) =  sup (a) (b)" 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

611 
proof (rule inf_unique) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

612 
fix a b :: 'a 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

613 
show " sup (a) (b) \<le> a" by (rule add_le_imp_le_right [of _ "sup (a) (b)"]) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

614 
(simp, simp add: add_sup_distrib_left) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

615 
next 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

616 
fix a b :: 'a 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

617 
show " sup (a) (b) \<le> b" by (rule add_le_imp_le_right [of _ "sup (a) (b)"]) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

618 
(simp, simp add: add_sup_distrib_left) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

619 
next 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

620 
fix a b c :: 'a 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

621 
assume "a \<le> b" "a \<le> c" 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

622 
then show "a \<le>  sup (b) (c)" by (subst neg_le_iff_le [symmetric]) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

623 
(simp add: le_supI) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

624 
qed 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

625 

8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

626 
lemma sup_eq_neg_inf: "sup a (b\<Colon>'a\<Colon>lordered_ab_group) =  inf (a) (b)" 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

627 
proof (rule sup_unique) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

628 
fix a b :: 'a 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

629 
show "a \<le>  inf (a) (b)" by (rule add_le_imp_le_right [of _ "inf (a) (b)"]) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

630 
(simp, simp add: add_inf_distrib_left) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

631 
next 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

632 
fix a b :: 'a 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

633 
show "b \<le>  inf (a) (b)" by (rule add_le_imp_le_right [of _ "inf (a) (b)"]) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

634 
(simp, simp add: add_inf_distrib_left) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

635 
next 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

636 
fix a b c :: 'a 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

637 
assume "a \<le> c" "b \<le> c" 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

638 
then show " inf (a) (b) \<le> c" by (subst neg_le_iff_le [symmetric]) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

639 
(simp add: le_infI) 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

640 
qed 
14738  641 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

642 
lemma add_eq_inf_sup: "a + b = sup a b + inf a (b\<Colon>'a\<Colon>lordered_ab_group)" 
14738  643 
proof  
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

644 
have "0 =  inf 0 (ab) + inf (ab) 0" by (simp add: inf_commute) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

645 
hence "0 = sup 0 (ba) + inf (ab) 0" by (simp add: inf_eq_neg_sup) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

646 
hence "0 = (a + sup a b) + (inf a b + (b))" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

647 
apply (simp add: add_sup_distrib_left add_inf_distrib_right) 
14738  648 
by (simp add: diff_minus add_commute) 
649 
thus ?thesis 

650 
apply (simp add: compare_rls) 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

651 
apply (subst add_left_cancel[symmetric, of "a+b" "sup a b + inf a b" "a"]) 
14738  652 
apply (simp only: add_assoc, simp add: add_assoc[symmetric]) 
653 
done 

654 
qed 

655 

656 
subsection {* Positive Part, Negative Part, Absolute Value *} 

657 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

658 
definition 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

659 
nprt :: "'a \<Rightarrow> ('a::lordered_ab_group)" where 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

660 
"nprt x = inf x 0" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

661 

ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

662 
definition 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

663 
pprt :: "'a \<Rightarrow> ('a::lordered_ab_group)" where 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

664 
"pprt x = sup x 0" 
14738  665 

666 
lemma prts: "a = pprt a + nprt a" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

667 
by (simp add: pprt_def nprt_def add_eq_inf_sup[symmetric]) 
14738  668 

669 
lemma zero_le_pprt[simp]: "0 \<le> pprt a" 

21312  670 
by (simp add: pprt_def) 
14738  671 

672 
lemma nprt_le_zero[simp]: "nprt a \<le> 0" 

21312  673 
by (simp add: nprt_def) 
14738  674 

675 
lemma le_eq_neg: "(a \<le> b) = (a + b \<le> (0::_::lordered_ab_group))" (is "?l = ?r") 

676 
proof  

677 
have a: "?l \<longrightarrow> ?r" 

678 
apply (auto) 

679 
apply (rule add_le_imp_le_right[of _ "b" _]) 

680 
apply (simp add: add_assoc) 

681 
done 

682 
have b: "?r \<longrightarrow> ?l" 

683 
apply (auto) 

684 
apply (rule add_le_imp_le_right[of _ "b" _]) 

685 
apply (simp) 

686 
done 

687 
from a b show ?thesis by blast 

688 
qed 

689 

15580  690 
lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def) 
691 
lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def) 

692 

693 
lemma pprt_eq_id[simp]: "0 <= x \<Longrightarrow> pprt x = x" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

694 
by (simp add: pprt_def le_iff_sup sup_aci) 
15580  695 

696 
lemma nprt_eq_id[simp]: "x <= 0 \<Longrightarrow> nprt x = x" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

697 
by (simp add: nprt_def le_iff_inf inf_aci) 
15580  698 

699 
lemma pprt_eq_0[simp]: "x <= 0 \<Longrightarrow> pprt x = 0" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

700 
by (simp add: pprt_def le_iff_sup sup_aci) 
15580  701 

702 
lemma nprt_eq_0[simp]: "0 <= x \<Longrightarrow> nprt x = 0" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

703 
by (simp add: nprt_def le_iff_inf inf_aci) 
15580  704 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

705 
lemma sup_0_imp_0: "sup a (a) = 0 \<Longrightarrow> a = (0::'a::lordered_ab_group)" 
14738  706 
proof  
707 
{ 

708 
fix a::'a 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

709 
assume hyp: "sup a (a) = 0" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

710 
hence "sup a (a) + a = a" by (simp) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

711 
hence "sup (a+a) 0 = a" by (simp add: add_sup_distrib_right) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

712 
hence "sup (a+a) 0 <= a" by (simp) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

713 
hence "0 <= a" by (blast intro: order_trans inf_sup_ord) 
14738  714 
} 
715 
note p = this 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

716 
assume hyp:"sup a (a) = 0" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

717 
hence hyp2:"sup (a) ((a)) = 0" by (simp add: sup_commute) 
14738  718 
from p[OF hyp] p[OF hyp2] show "a = 0" by simp 
719 
qed 

720 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

721 
lemma inf_0_imp_0: "inf a (a) = 0 \<Longrightarrow> a = (0::'a::lordered_ab_group)" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

722 
apply (simp add: inf_eq_neg_sup) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

723 
apply (simp add: sup_commute) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

724 
apply (erule sup_0_imp_0) 
15481  725 
done 
14738  726 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

727 
lemma inf_0_eq_0[simp]: "(inf a (a) = 0) = (a = (0::'a::lordered_ab_group))" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

728 
by (auto, erule inf_0_imp_0) 
14738  729 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

730 
lemma sup_0_eq_0[simp]: "(sup a (a) = 0) = (a = (0::'a::lordered_ab_group))" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

731 
by (auto, erule sup_0_imp_0) 
14738  732 

733 
lemma zero_le_double_add_iff_zero_le_single_add[simp]: "(0 \<le> a + a) = (0 \<le> (a::'a::lordered_ab_group))" 

734 
proof 

735 
assume "0 <= a + a" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

736 
hence a:"inf (a+a) 0 = 0" by (simp add: le_iff_inf inf_commute) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

737 
have "(inf a 0)+(inf a 0) = inf (inf (a+a) 0) a" (is "?l=_") by (simp add: add_sup_inf_distribs inf_aci) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

738 
hence "?l = 0 + inf a 0" by (simp add: a, simp add: inf_commute) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

739 
hence "inf a 0 = 0" by (simp only: add_right_cancel) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

740 
then show "0 <= a" by (simp add: le_iff_inf inf_commute) 
14738  741 
next 
742 
assume a: "0 <= a" 

743 
show "0 <= a + a" by (simp add: add_mono[OF a a, simplified]) 

744 
qed 

745 

746 
lemma double_add_le_zero_iff_single_add_le_zero[simp]: "(a + a <= 0) = ((a::'a::lordered_ab_group) <= 0)" 

747 
proof  

748 
have "(a + a <= 0) = (0 <= (a+a))" by (subst le_minus_iff, simp) 

749 
moreover have "\<dots> = (a <= 0)" by (simp add: zero_le_double_add_iff_zero_le_single_add) 

750 
ultimately show ?thesis by blast 

751 
qed 

752 

753 
lemma double_add_less_zero_iff_single_less_zero[simp]: "(a+a<0) = ((a::'a::{pordered_ab_group_add,linorder}) < 0)" (is ?s) 

754 
proof cases 

755 
assume a: "a < 0" 

756 
thus ?s by (simp add: add_strict_mono[OF a a, simplified]) 

757 
next 

758 
assume "~(a < 0)" 

759 
hence a:"0 <= a" by (simp) 

760 
hence "0 <= a+a" by (simp add: add_mono[OF a a, simplified]) 

761 
hence "~(a+a < 0)" by simp 

762 
with a show ?thesis by simp 

763 
qed 

764 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

765 
class lordered_ab_group_abs = lordered_ab_group + 
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

766 
assumes abs_lattice: "abs x = sup x (uminus x)" 
14738  767 

768 
lemma abs_zero[simp]: "abs 0 = (0::'a::lordered_ab_group_abs)" 

769 
by (simp add: abs_lattice) 

770 

771 
lemma abs_eq_0[simp]: "(abs a = 0) = (a = (0::'a::lordered_ab_group_abs))" 

772 
by (simp add: abs_lattice) 

773 

774 
lemma abs_0_eq[simp]: "(0 = abs a) = (a = (0::'a::lordered_ab_group_abs))" 

775 
proof  

776 
have "(0 = abs a) = (abs a = 0)" by (simp only: eq_ac) 

777 
thus ?thesis by simp 

778 
qed 

779 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

780 
lemma neg_inf_eq_sup[simp]: " inf a (b::_::lordered_ab_group) = sup (a) (b)" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

781 
by (simp add: inf_eq_neg_sup) 
14738  782 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

783 
lemma neg_sup_eq_inf[simp]: " sup a (b::_::lordered_ab_group) = inf (a) (b)" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

784 
by (simp del: neg_inf_eq_sup add: sup_eq_neg_inf) 
14738  785 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

786 
lemma sup_eq_if: "sup a (a) = (if a < 0 then a else (a::'a::{lordered_ab_group, linorder}))" 
14738  787 
proof  
788 
note b = add_le_cancel_right[of a a "a",symmetric,simplified] 

789 
have c: "a + a = 0 \<Longrightarrow> a = a" by (rule add_right_imp_eq[of _ a], simp) 

22452
8a86fd2a1bf0
adjusted to new lattice theory developement in Lattices.thy / FixedPoint.thy
haftmann
parents:
22422
diff
changeset

790 
show ?thesis by (auto simp add: max_def b linorder_not_less sup_max) 
14738  791 
qed 
792 

793 
lemma abs_if_lattice: "\<bar>a\<bar> = (if a < 0 then a else (a::'a::{lordered_ab_group_abs, linorder}))" 

794 
proof  

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

795 
show ?thesis by (simp add: abs_lattice sup_eq_if) 
14738  796 
qed 
797 

798 
lemma abs_ge_zero[simp]: "0 \<le> abs (a::'a::lordered_ab_group_abs)" 

799 
proof  

21312  800 
have a:"a <= abs a" and b:"a <= abs a" by (auto simp add: abs_lattice) 
14738  801 
show ?thesis by (rule add_mono[OF a b, simplified]) 
802 
qed 

803 

804 
lemma abs_le_zero_iff [simp]: "(abs a \<le> (0::'a::lordered_ab_group_abs)) = (a = 0)" 

805 
proof 

806 
assume "abs a <= 0" 

807 
hence "abs a = 0" by (auto dest: order_antisym) 

808 
thus "a = 0" by simp 

809 
next 

810 
assume "a = 0" 

811 
thus "abs a <= 0" by simp 

812 
qed 

813 

814 
lemma zero_less_abs_iff [simp]: "(0 < abs a) = (a \<noteq> (0::'a::lordered_ab_group_abs))" 

815 
by (simp add: order_less_le) 

816 

817 
lemma abs_not_less_zero [simp]: "~ abs a < (0::'a::lordered_ab_group_abs)" 

818 
proof  

819 
have a:"!! x (y::_::order). x <= y \<Longrightarrow> ~(y < x)" by auto 

820 
show ?thesis by (simp add: a) 

821 
qed 

822 

823 
lemma abs_ge_self: "a \<le> abs (a::'a::lordered_ab_group_abs)" 

21312  824 
by (simp add: abs_lattice) 
14738  825 

826 
lemma abs_ge_minus_self: "a \<le> abs (a::'a::lordered_ab_group_abs)" 

21312  827 
by (simp add: abs_lattice) 
14738  828 

829 
lemma abs_prts: "abs (a::_::lordered_ab_group_abs) = pprt a  nprt a" 

830 
apply (simp add: pprt_def nprt_def diff_minus) 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

831 
apply (simp add: add_sup_inf_distribs sup_aci abs_lattice[symmetric]) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

832 
apply (subst sup_absorb2, auto) 
14738  833 
done 
834 

835 
lemma abs_minus_cancel [simp]: "abs (a) = abs(a::'a::lordered_ab_group_abs)" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

836 
by (simp add: abs_lattice sup_commute) 
14738  837 

838 
lemma abs_idempotent [simp]: "abs (abs a) = abs (a::'a::lordered_ab_group_abs)" 

839 
apply (simp add: abs_lattice[of "abs a"]) 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

840 
apply (subst sup_absorb1) 
14738  841 
apply (rule order_trans[of _ 0]) 
842 
by auto 

843 

15093
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

844 
lemma abs_minus_commute: 
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

845 
fixes a :: "'a::lordered_ab_group_abs" 
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

846 
shows "abs (ab) = abs(ba)" 
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

847 
proof  
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

848 
have "abs (ab) = abs ( (ab))" by (simp only: abs_minus_cancel) 
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

849 
also have "... = abs(ba)" by simp 
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

850 
finally show ?thesis . 
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

851 
qed 
49ede01e9ee6
conversion of Integration and NSPrimes to Isar scripts
paulson
parents:
15010
diff
changeset

852 

14738  853 
lemma zero_le_iff_zero_nprt: "(0 \<le> a) = (nprt a = 0)" 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

854 
by (simp add: le_iff_inf nprt_def inf_commute) 
14738  855 

856 
lemma le_zero_iff_zero_pprt: "(a \<le> 0) = (pprt a = 0)" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

857 
by (simp add: le_iff_sup pprt_def sup_commute) 
14738  858 

859 
lemma le_zero_iff_pprt_id: "(0 \<le> a) = (pprt a = a)" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

860 
by (simp add: le_iff_sup pprt_def sup_commute) 
14738  861 

862 
lemma zero_le_iff_nprt_id: "(a \<le> 0) = (nprt a = a)" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

863 
by (simp add: le_iff_inf nprt_def inf_commute) 
14738  864 

15580  865 
lemma pprt_mono[simp]: "(a::_::lordered_ab_group) <= b \<Longrightarrow> pprt a <= pprt b" 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

866 
by (simp add: le_iff_sup pprt_def sup_aci) 
15580  867 

868 
lemma nprt_mono[simp]: "(a::_::lordered_ab_group) <= b \<Longrightarrow> nprt a <= nprt b" 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

869 
by (simp add: le_iff_inf nprt_def inf_aci) 
15580  870 

19404  871 
lemma pprt_neg: "pprt (x) =  nprt x" 
872 
by (simp add: pprt_def nprt_def) 

873 

874 
lemma nprt_neg: "nprt (x) =  pprt x" 

875 
by (simp add: pprt_def nprt_def) 

876 

14738  877 
lemma iff2imp: "(A=B) \<Longrightarrow> (A \<Longrightarrow> B)" 
878 
by (simp) 

879 

16775
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

880 
lemma abs_of_nonneg [simp]: "0 \<le> a \<Longrightarrow> abs a = (a::'a::lordered_ab_group_abs)" 
14738  881 
by (simp add: iff2imp[OF zero_le_iff_zero_nprt] iff2imp[OF le_zero_iff_pprt_id] abs_prts) 
882 

16775
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

883 
lemma abs_of_pos: "0 < (x::'a::lordered_ab_group_abs) ==> abs x = x"; 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

884 
by (rule abs_of_nonneg, rule order_less_imp_le); 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

885 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

886 
lemma abs_of_nonpos [simp]: "a \<le> 0 \<Longrightarrow> abs a = (a::'a::lordered_ab_group_abs)" 
14738  887 
by (simp add: iff2imp[OF le_zero_iff_zero_pprt] iff2imp[OF zero_le_iff_nprt_id] abs_prts) 
888 

16775
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

889 
lemma abs_of_neg: "(x::'a::lordered_ab_group_abs) < 0 ==> 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

890 
abs x =  x" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

891 
by (rule abs_of_nonpos, rule order_less_imp_le) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

892 

14738  893 
lemma abs_leI: "[a \<le> b; a \<le> b] ==> abs a \<le> (b::'a::lordered_ab_group_abs)" 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

894 
by (simp add: abs_lattice le_supI) 
14738  895 

896 
lemma le_minus_self_iff: "(a \<le> a) = (a \<le> (0::'a::lordered_ab_group))" 

897 
proof  

898 
from add_le_cancel_left[of "a" "a+a" "0"] have "(a <= a) = (a+a <= 0)" 

899 
by (simp add: add_assoc[symmetric]) 

900 
thus ?thesis by simp 

901 
qed 

902 

903 
lemma minus_le_self_iff: "(a \<le> a) = (0 \<le> (a::'a::lordered_ab_group))" 

904 
proof  

905 
from add_le_cancel_left[of "a" "0" "a+a"] have "(a <= a) = (0 <= a+a)" 

906 
by (simp add: add_assoc[symmetric]) 

907 
thus ?thesis by simp 

908 
qed 

909 

910 
lemma abs_le_D1: "abs a \<le> b ==> a \<le> (b::'a::lordered_ab_group_abs)" 

911 
by (insert abs_ge_self, blast intro: order_trans) 

912 

913 
lemma abs_le_D2: "abs a \<le> b ==> a \<le> (b::'a::lordered_ab_group_abs)" 

914 
by (insert abs_le_D1 [of "a"], simp) 

915 

916 
lemma abs_le_iff: "(abs a \<le> b) = (a \<le> b & a \<le> (b::'a::lordered_ab_group_abs))" 

917 
by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2) 

918 

15539  919 
lemma abs_triangle_ineq: "abs(a+b) \<le> abs a + abs(b::'a::lordered_ab_group_abs)" 
14738  920 
proof  
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

921 
have g:"abs a + abs b = sup (a+b) (sup (ab) (sup (a+b) (a + (b))))" (is "_=sup ?m ?n") 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

922 
by (simp add: abs_lattice add_sup_inf_distribs sup_aci diff_minus) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

923 
have a:"a+b <= sup ?m ?n" by (simp) 
21312  924 
have b:"ab <= ?n" by (simp) 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

925 
have c:"?n <= sup ?m ?n" by (simp) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

926 
from b c have d: "ab <= sup ?m ?n" by(rule order_trans) 
14738  927 
have e:"ab = (a+b)" by (simp add: diff_minus) 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22390
diff
changeset

928 
from a d e have "abs(a+b) <= sup ?m ?n" 
14738  929 
by (drule_tac abs_leI, auto) 
930 
with g[symmetric] show ?thesis by simp 

931 
qed 

932 

16775
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

933 
lemma abs_triangle_ineq2: "abs (a::'a::lordered_ab_group_abs)  
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

934 
abs b <= abs (a  b)" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

935 
apply (simp add: compare_rls) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

936 
apply (subgoal_tac "abs a = abs (a  b + b)") 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

937 
apply (erule ssubst) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

938 
apply (rule abs_triangle_ineq) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

939 
apply (rule arg_cong);back; 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

940 
apply (simp add: compare_rls) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

941 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

942 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

943 
lemma abs_triangle_ineq3: 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

944 
"abs(abs (a::'a::lordered_ab_group_abs)  abs b) <= abs (a  b)" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

945 
apply (subst abs_le_iff) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

946 
apply auto 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

947 
apply (rule abs_triangle_ineq2) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

948 
apply (subst abs_minus_commute) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

949 
apply (rule abs_triangle_ineq2) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

950 
done 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

951 

c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

952 
lemma abs_triangle_ineq4: "abs ((a::'a::lordered_ab_group_abs)  b) <= 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

953 
abs a + abs b" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

954 
proof ; 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

955 
have "abs(a  b) = abs(a +  b)" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

956 
by (subst diff_minus, rule refl) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

957 
also have "... <= abs a + abs ( b)" 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

958 
by (rule abs_triangle_ineq) 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

959 
finally show ?thesis 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

960 
by simp 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

961 
qed 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16417
diff
changeset

962 

14738  963 
lemma abs_diff_triangle_ineq: 
964 
"\<bar>(a::'a::lordered_ab_group_abs) + b  (c+d)\<bar> \<le> \<bar>ac\<bar> + \<bar>bd\<bar>" 

965 
proof  

966 
have "\<bar>a + b  (c+d)\<bar> = \<bar>(ac) + (bd)\<bar>" by (simp add: diff_minus add_ac) 

967 
also have "... \<le> \<bar>ac\<bar> + \<bar>bd\<bar>" by (rule abs_triangle_ineq) 

968 
finally show ?thesis . 

969 
qed 

970 

15539  971 
lemma abs_add_abs[simp]: 
972 
fixes a:: "'a::{lordered_ab_group_abs}" 

973 
shows "abs(abs a + abs b) = abs a + abs b" (is "?L = ?R") 

974 
proof (rule order_antisym) 

975 
show "?L \<ge> ?R" by(rule abs_ge_self) 

976 
next 

977 
have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by(rule abs_triangle_ineq) 

978 
also have "\<dots> = ?R" by simp 

979 
finally show "?L \<le> ?R" . 

980 
qed 

981 

14754
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

982 
text {* Needed for abelian cancellation simprocs: *} 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

983 

a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

984 
lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)" 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

985 
apply (subst add_left_commute) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

986 
apply (subst add_left_cancel) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

987 
apply simp 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

988 
done 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

989 

a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

990 
lemma add_cancel_end: "(x + (y + z) = y) = (x =  (z::'a::ab_group_add))" 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

991 
apply (subst add_cancel_21[of _ _ _ 0, simplified]) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

992 
apply (simp add: add_right_cancel[symmetric, of "x" "z" "z", simplified]) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

993 
done 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

994 

a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

995 
lemma less_eqI: "(x::'a::pordered_ab_group_add)  y = x'  y' \<Longrightarrow> (x < y) = (x' < y')" 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

996 
by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y']) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

997 

a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

998 
lemma le_eqI: "(x::'a::pordered_ab_group_add)  y = x'  y' \<Longrightarrow> (y <= x) = (y' <= x')" 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

999 
apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of y' x']) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1000 
apply (simp add: neg_le_iff_le[symmetric, of "yx" 0] neg_le_iff_le[symmetric, of "y'x'" 0]) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1001 
done 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1002 

a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1003 
lemma eq_eqI: "(x::'a::ab_group_add)  y = x'  y' \<Longrightarrow> (x = y) = (x' = y')" 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1004 
by (simp add: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y']) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1005 

a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1006 
lemma diff_def: "(x::'a::ab_group_add)  y == x + (y)" 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1007 
by (simp add: diff_minus) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1008 

a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1009 
lemma add_minus_cancel: "(a::'a::ab_group_add) + (a + b) = b" 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1010 
by (simp add: add_assoc[symmetric]) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1011 

a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1012 
lemma minus_add_cancel: "(a::'a::ab_group_add) + (a + b) = b" 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1013 
by (simp add: add_assoc[symmetric]) 
a080eeeaec14
Modification / Installation of Provers/Arith/abel_cancel.ML for OrderedGroup.thy
obua
parents:
14738
diff
changeset

1014 

15178  1015 
lemma le_add_right_mono: 
1016 
assumes 

1017 
"a <= b + (c::'a::pordered_ab_group_add)" 

1018 
"c <= d" 

1019 
shows "a <= b + d" 

1020 
apply (rule_tac order_trans[where y = "b+c"]) 

1021 
apply (simp_all add: prems) 

1022 
done 

1023 

1024 
lemmas group_eq_simps = 

1025 
mult_ac 

1026 
add_ac 

1027 
add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2 

1028 
diff_eq_eq eq_diff_eq 

1029 

1030 
lemma estimate_by_abs: 

1031 
"a + b <= (c::'a::lordered_ab_group_abs) \<Longrightarrow> a <= c + abs b" 

1032 
proof  

1033 
assume 1: "a+b <= c" 

1034 
have 2: "a <= c+(b)" 

1035 
apply (insert 1) 

1036 
apply (drule_tac add_right_mono[where c="b"]) 

1037 
apply (simp add: group_eq_simps) 

1038 
done 

1039 
have 3: "(b) <= abs b" by (rule abs_ge_minus_self) 

1040 
show ?thesis by (rule le_add_right_mono[OF 2 3]) 

1041 
qed 

1042 

22482  1043 

1044 
subsection {* Tools setup *} 

1045 

17085  1046 
text{*Simplification of @{term "xy < 0"}, etc.*} 
1047 
lemmas diff_less_0_iff_less = less_iff_diff_less_0 [symmetric] 

1048 
lemmas diff_eq_0_iff_eq = eq_iff_diff_eq_0 [symmetric] 

1049 
lemmas diff_le_0_iff_le = le_iff_diff_le_0 [symmetric] 

1050 
declare diff_less_0_iff_less [simp] 

1051 
declare diff_eq_0_iff_eq [simp] 

1052 
declare diff_le_0_iff_le [simp] 

1053 

22482  1054 
ML {* 
1055 
structure ab_group_add_cancel = Abel_Cancel( 

1056 
struct 

1057 

1058 
(* term order for abelian groups *) 

1059 

1060 
fun agrp_ord (Const (a, _)) = find_index (fn a' => a = a') 

1061 
["HOL.zero", "HOL.plus", "HOL.uminus", "HOL.minus"] 

1062 
 agrp_ord _ = ~1; 

1063 

1064 
fun termless_agrp (a, b) = (Term.term_lpo agrp_ord (a, b) = LESS); 

1065 

1066 
local 

1067 
val ac1 = mk_meta_eq @{thm add_assoc}; 

1068 
val ac2 = mk_meta_eq @{thm add_commute}; 

1069 
val ac3 = mk_meta_eq @{thm add_left_commute}; 

1070 
fun solve_add_ac thy _ (_ $ (Const ("HOL.plus",_) $ _ $ _) $ _) = 

1071 
SOME ac1 

1072 
 solve_add_ac thy _ (_ $ x $ (Const ("HOL.plus",_) $ y $ z)) = 

1073 
if termless_agrp (y, x) then SOME ac3 else NONE 

1074 
 solve_add_ac thy _ (_ $ x $ y) = 

1075 
if termless_agrp (y, x) then SOME ac2 else NONE 

1076 
 solve_add_ac thy _ _ = NONE 

1077 
in 

1078 
val add_ac_proc = Simplifier.simproc @{theory} 

1079 
"add_ac_proc" ["x + y::'a::ab_semigroup_add"] solve_add_ac; 

1080 
end; 

1081 

1082 
val cancel_ss = HOL_basic_ss settermless termless_agrp 

1083 
addsimprocs [add_ac_proc] addsimps 

1084 
[@{thm add_0}, @{thm add_0_right}, @{thm diff_def}, 

1085 
@{thm minus_add_distrib}, @{thm minus_minus}, @{thm minus_zero}, 

1086 
@{thm right_minus}, @{thm left_minus}, @{thm add_minus_cancel}, 

1087 
@{thm minus_add_cancel}]; 

1088 

22548  1089 
val eq_reflection = @{thm eq_reflection}; 
22482  1090 

22548  1091 
val thy_ref = Theory.self_ref @{theory}; 
22482  1092 

22548  1093 
val T = TFree("'a", ["OrderedGroup.ab_group_add"]); 
22482  1094 

22548  1095 
val eqI_rules = [@{thm less_eqI}, @{thm le_eqI}, @{thm eq_eqI}]; 
22482  1096 

1097 
val dest_eqI = 

1098 
fst o HOLogic.dest_bin "op =" HOLogic.boolT o HOLogic.dest_Trueprop o concl_of; 

1099 

1100 
end); 

1101 
*} 

1102 

1103 
ML_setup {* 

1104 
Addsimprocs [ab_group_add_cancel.sum_conv, ab_group_add_cancel.rel_conv]; 

1105 
*} 

17085  1106 

14738  1107 
end 