Homogen.v 18.2 KB
Newer Older
Guillaume Melquiond's avatar
Guillaume Melquiond committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
(**
This example is part of the Flocq formalization of floating-point
arithmetic in Coq: http://flocq.gforge.inria.fr/

Copyright (C) 2016-2018 Guillaume Melquiond

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
COPYING file for more details.
*)

Guillaume Melquiond's avatar
Guillaume Melquiond committed
18 19
Require Import Reals Psatz.
From Flocq Require Import Core Operations Relative Plus_error.
20 21 22 23 24 25 26 27 28

Section Theory.

Variable emin : Z.
Variable prec : Z.
Context {Hprec : Prec_gt_0 prec}.

Notation fexp := (FLT_exp emin prec).

29
Definition Bmin := bpow radix2 (emin + prec - 1).
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

Definition hombnd (m M u v : R) (b B : float radix2) :=
  (0 <= F2R b)%R /\ (1 <= F2R B)%R /\
  ((Bmin <= m)%R -> (Rabs (u - v) <= F2R b * M)%R /\ (Rabs v <= F2R B * M)%R).

Lemma hombnd_fact :
  forall m M1 M2 u v b B,
  (M1 <= M2)%R ->
  hombnd m M1 u v b B ->
  hombnd m M2 u v b B.
Proof.
intros m M1 M2 u v b B HM [H1 [H2 H]].
refine (conj H1 (conj H2 _)).
intros H0.
destruct (H H0) as [H3 H4].
split.
apply Rle_trans with (1 := H3).
now apply Rmult_le_compat_l.
apply Rle_trans with (1 := H4).
apply Rmult_le_compat_l with (2 := HM).
now apply Rle_trans with (1 := Rle_0_1).
Qed.

Lemma hombnd_cond :
  forall m1 m2 M u v b B,
  (m2 <= m1)%R ->
  hombnd m1 M u v b B ->
  hombnd m2 M u v b B.
Proof.
intros m1 m2 M u v b B Hm [H1 [H2 H]].
refine (conj H1 (conj H2 _)).
intros H0.
apply H.
now apply Rle_trans with (2 := Hm).
Qed.

Lemma hombnd_cond' :
  forall m M u v b B,
  hombnd (Rmin Bmin m) M u v b B ->
  hombnd m M u v b B.
Proof.
intros m M u v b B [H1 [H2 H]].
refine (conj H1 (conj H2 _)).
intros H0.
apply H.
apply Rmin_glb with (2 := H0).
apply Rle_refl.
Qed.

Lemma hombnd_plus :
  forall m M u1 v1 b1 B1 u2 v2 b2 B2,
  hombnd m M u1 v1 b1 B1 ->
  hombnd m M u2 v2 b2 B2 ->
83
  hombnd m M (u1 + u2) (v1 + v2) (Fplus b1 b2) (Fplus B1 B2).
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
Proof.
intros m M u1 v1 b1 B1 u2 v2 b2 B2 [H11 [H12 H1]] [H21 [H22 H2]].
unfold hombnd.
rewrite F2R_plus.
split.
now apply Rplus_le_le_0_compat.
rewrite F2R_plus.
split.
clear -H12 H22 ; lra.
intros H.
destruct (H1 H) as [H13 H14].
destruct (H2 H) as [H23 H24].
rewrite 2!Rmult_plus_distr_r.
replace ((u1 + u2) - (v1 + v2))%R with ((u1 - v1) + (u2 - v2))%R by ring.
split ;
  apply Rle_trans with (1 := Rabs_triang _ _) ;
  now apply Rplus_le_compat.
Qed.

Lemma hombnd_minus :
  forall m M u1 v1 b1 B1 u2 v2 b2 B2,
  hombnd m M u1 v1 b1 B1 ->
  hombnd m M u2 v2 b2 B2 ->
107
  hombnd m M (u1 - u2) (v1 - v2) (Fplus b1 b2) (Fplus B1 B2).
108 109 110 111 112 113 114 115 116 117 118 119
Proof.
intros m M u1 v1 b1 B1 u2 v2 b2 B2 H1 [H21 [H22 H2]].
apply hombnd_plus with (1 := H1).
refine (conj H21 (conj H22 _)).
intros H.
destruct (H2 H) as [H23 H24].
replace (- u2 - - v2)%R with (- (u2 - v2))%R by ring.
rewrite 2!Rabs_Ropp.
now split.
Qed.

Definition mult_err b1 B1 b2 B2 :=
120
  Fplus (Fplus (Fmult b1 B2) (Fmult B1 b2)) (@Fmult radix2 b1 b2).
121 122 123 124 125

Lemma hombnd_mult :
  forall m M1 u1 v1 b1 B1 M2 u2 v2 b2 B2,
  hombnd m M1 u1 v1 b1 B1 ->
  hombnd m M2 u2 v2 b2 B2 ->
126
  hombnd m (M1 * M2) (u1 * u2) (v1 * v2) (mult_err b1 B1 b2 B2) (Fmult B1 B2).
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
Proof.
intros m M1 u1 v1 b1 B1 M2 u2 v2 b2 B2 [H11 [H12 H1]] [H21 [H22 H2]].
unfold hombnd, mult_err.
rewrite 2!F2R_plus, 4!F2R_mult.
split.
apply Rplus_le_le_0_compat.
apply Rplus_le_le_0_compat.
apply Rmult_le_pos with (1 := H11).
now apply Rle_trans with (1 := Rle_0_1).
apply Rmult_le_pos with (2 := H21).
now apply Rle_trans with (1 := Rle_0_1).
now apply Rmult_le_pos.
split.
rewrite <- (Rmult_1_r 1).
now apply Rmult_le_compat ; try apply Rle_0_1.
intros H.
destruct (H1 H) as [H13 H14].
destruct (H2 H) as [H23 H24].
assert (H0: forall u v, ((u * v) * (M1 * M2) = (u * M1) * (v * M2))%R).
  intros u v ; ring.
split.
replace (u1 * u2 - v1 * v2)%R
  with ((u1 - v1) * v2 + v1 * (u2 - v2) + (u1 - v1) * (u2 - v2))%R by ring.
rewrite 2!Rmult_plus_distr_r.
rewrite 3!H0.
apply Rle_trans with (1 := Rabs_triang _ _).
apply Rplus_le_compat.
apply Rle_trans with (1 := Rabs_triang _ _).
apply Rplus_le_compat.
rewrite Rabs_mult.
now apply Rmult_le_compat ; try apply Rabs_pos.
rewrite Rabs_mult.
now apply Rmult_le_compat ; try apply Rabs_pos.
rewrite Rabs_mult.
now apply Rmult_le_compat ; try apply Rabs_pos.
rewrite H0, Rabs_mult.
now apply Rmult_le_compat ; try apply Rabs_pos.
Qed.

Definition round_err b B :=
167
  Fplus (Fmult (Fplus b B) (Float radix2 1 (- prec))) b.
168 169 170 171 172 173 174 175 176 177 178 179 180 181

Lemma hombnd_rnd :
  forall m M u v b B,
  hombnd m M u v b B ->
  hombnd (Rmin m M) M (round radix2 fexp ZnearestE u) v (round_err b B) B.
Proof with auto with typeclass_instances.
intros m M u v b B [Ho1 [Ho2 Ho]].
unfold hombnd, round_err.
rewrite F2R_plus, F2R_mult, F2R_plus.
split.
apply Rplus_le_le_0_compat with (2 := Ho1).
apply Rmult_le_pos.
apply Rplus_le_le_0_compat with (1 := Ho1).
now apply Rle_trans with (1 := Rle_0_1).
182
now apply F2R_ge_0.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
apply (conj Ho2).
intros H.
specialize (Ho (Rle_trans _ _ _ H (Rmin_l _ _))).
destruct Ho as [Ho3 Ho4].
refine (conj _ Ho4).
replace (round radix2 fexp ZnearestE u - v)%R
  with ((round radix2 fexp ZnearestE u - u) + (u - v))%R by ring.
rewrite Rmult_plus_distr_r.
apply Rle_trans with (1 := Rabs_triang _ _).
apply Rplus_le_compat with (2 := Ho3).
apply Rle_trans with (1 := error_le_half_ulp _ _ _ _).
apply Rmult_le_reg_l with 2%R.
apply Rlt_0_2.
rewrite <- (Rmult_assoc 2), Rinv_r, Rmult_1_l by apply Rgt_not_eq, Rlt_0_2.
assert (HM : (0 <= M)%R).
  apply Rle_trans with (2 := Rmin_r m M).
  apply Rle_trans with (2 := H).
  apply bpow_ge_0.
assert (H' : (0 <= (F2R b + F2R B) * M)%R).
  apply Rmult_le_pos with (2 := HM).
  apply Rplus_le_le_0_compat with (1 := Ho1).
  now apply Rle_trans with (1 := Rle_0_1).
apply Rle_trans with (ulp radix2 fexp ((F2R b + F2R B) * M)).
apply ulp_le...
rewrite Rabs_pos_eq with (1 := H').
rewrite Rmult_plus_distr_r.
replace u with (u - v + v)%R by ring.
apply Rle_trans with (1 := Rabs_triang _ _).
now apply Rplus_le_compat.
replace (2 * ((F2R b + F2R B) * F2R {| Fnum := 1; Fexp := - prec |} * M))%R
  with ((F2R b + F2R B) * M * bpow radix2 (1 - prec))%R.
214
rewrite <- (Rabs_pos_eq _ H') at 2.
215 216 217 218 219 220 221 222 223 224
apply ulp_FLT_le.
rewrite Rabs_pos_eq with (1 := H').
apply Rle_trans with (1 := H).
apply Rle_trans with (1 := Rmin_r _ _).
rewrite <- (Rmult_1_l M) at 1.
rewrite <- (Rplus_0_l 1).
apply Rmult_le_compat_r with (1 := HM).
now apply Rplus_le_compat.
unfold Zminus.
rewrite bpow_plus.
Guillaume Melquiond's avatar
Guillaume Melquiond committed
225
change (bpow radix2 1) with 2%R.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
rewrite F2R_bpow.
ring.
Qed.

End Theory.

Section Example.

Definition fxp := FLT_exp (-1074) 53.
Definition add x y := round radix2 fxp ZnearestE (x + y).
Definition sub x y := round radix2 fxp ZnearestE (x - y).
Definition mul x y := round radix2 fxp ZnearestE (x * y).

Definition hombnd' := hombnd (-1074) 53.

Lemma hombnd_sub_init :
  forall u v,
  generic_format radix2 fxp u ->
  generic_format radix2 fxp v ->
  hombnd' (Bmin (-1074) 53) (Rabs (u - v)) (sub u v) (u - v) (Float radix2 1 (-53)) (Float radix2 1 0).
Proof.
intros u v Fu Fv.
split.
249
now apply F2R_ge_0.
250 251 252 253 254 255 256 257 258
unfold F2R at 1 3 ; simpl.
rewrite 2!Rmult_1_l.
repeat split ; try apply Rle_refl.
unfold sub.
destruct (Rle_or_lt (Rabs (u - v)) (bpow radix2 (53 + -1074))) as [S|S].
rewrite round_generic.
unfold Rminus at 1.
rewrite Rplus_opp_r, Rabs_R0.
apply Rmult_le_pos.
259
now apply F2R_ge_0.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
apply Rabs_pos.
apply valid_rnd_N.
apply FLT_format_plus_small ; try easy.
now apply generic_format_opp.
replace (F2R (Float radix2 1 (-53))) with (bpow radix2 (-1) * bpow radix2 (-53 + 1))%R.
apply relative_error_N_FLT.
easy.
apply Rlt_le.
apply Rle_lt_trans with (2 := S).
now apply bpow_le.
rewrite <- bpow_plus.
unfold F2R.
rewrite Rmult_1_l.
now apply f_equal.
Qed.

Lemma hombnd_fact' :
  forall {m M1 M2 u v b B},
  (M1 <= M2)%R ->
  hombnd' m M1 u v b B ->
  hombnd' m M2 u v b B.
Proof.
apply hombnd_fact.
Qed.

Lemma hombnd_cond'' :
  forall {m1 m2 M u v b B},
  (m2 <= m1)%R ->
  hombnd' m1 M u v b B ->
  hombnd' m2 M u v b B.
Proof.
apply hombnd_cond.
Qed.

Lemma hombnd_add :
  forall {m M u1 v1 b1 B1 u2 v2 b2 B2},
  hombnd' m M u1 v1 b1 B1 ->
  hombnd' m M u2 v2 b2 B2 ->
298
  hombnd' m M (u1 + u2) (v1 + v2) (Fplus b1 b2) (Fplus B1 B2).
299 300 301 302 303 304 305 306
Proof.
apply hombnd_plus.
Qed.

Lemma hombnd_sub :
  forall {m M u1 v1 b1 B1 u2 v2 b2 B2},
  hombnd' m M u1 v1 b1 B1 ->
  hombnd' m M u2 v2 b2 B2 ->
307
  hombnd' m M (u1 - u2) (v1 - v2) (Fplus b1 b2) (Fplus B1 B2).
308 309 310 311 312 313 314 315
Proof.
apply hombnd_minus.
Qed.

Lemma hombnd_mul :
  forall {m M1 u1 v1 b1 B1 M2 u2 v2 b2 B2},
  hombnd' m M1 u1 v1 b1 B1 ->
  hombnd' m M2 u2 v2 b2 B2 ->
316
  hombnd' m (M1 * M2) (u1 * u2) (v1 * v2) (mult_err b1 B1 b2 B2) (Fmult B1 B2).
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
Proof.
apply hombnd_mult.
Qed.

Lemma hombnd_rnd' :
  forall {m M u v b B},
  hombnd' m M u v b B ->
  hombnd' (Rmin m M) M (round radix2 fxp ZnearestE u) v (round_err 53 b B) B.
Proof.
now apply hombnd_rnd.
Qed.

Lemma hombnd_rnd'' :
  forall {M u v b B},
  hombnd' (Bmin (-1074) 53) M u v b B ->
  hombnd' M M (round radix2 fxp ZnearestE u) v (round_err 53 b B) B.
Proof.
intros M u v b B H.
apply hombnd_cond'.
now apply hombnd_rnd'.
Qed.

Definition orient2d x1 y1 x2 y2 x3 y3 :=
  sub (mul (sub x1 x3) (sub y2 y3)) (mul (sub x2 x3) (sub y1 y3)).

Definition orient2d_exact x1 y1 x2 y2 x3 y3 :=
  ((x1 - x3) * (y2 - y3) - (x2 - x3) * (y1 - y3))%R.

Definition norm2d x y := Rmax (Rabs x) (Rabs y).

Lemma orient2d_spec :
  forall x1 y1 x2 y2 x3 y3,
  generic_format radix2 fxp x1 ->
  generic_format radix2 fxp y1 ->
  generic_format radix2 fxp x2 ->
  generic_format radix2 fxp y2 ->
  generic_format radix2 fxp x3 ->
  generic_format radix2 fxp y3 ->
  let M := (norm2d (x1 - x3) (x2 - x3) * norm2d (y1 - y3) (y2 - y3))%R in
  hombnd' M M (orient2d x1 y1 x2 y2 x3 y3) (orient2d_exact x1 y1 x2 y2 x3 y3)
    (Float radix2 5846006549323612646370400306145384485685829828610 (-212)) (Float radix2 2 0).
Proof.
intros x1 y1 x2 y2 x3 y3 Fx1 Fy1 Fx2 Fy2 Fx3 Fy3.
assert (Sx13 := hombnd_sub_init x1 x3 Fx1 Fx3).
assert (Sy13 := hombnd_sub_init y1 y3 Fy1 Fy3).
assert (Sx23 := hombnd_sub_init x2 x3 Fx2 Fx3).
assert (Sy23 := hombnd_sub_init y2 y3 Fy2 Fy3).
apply (hombnd_fact' (Rmax_l _ (Rabs (x2 - x3)))) in Sx13.
apply (hombnd_fact' (Rmax_l _ (Rabs (y2 - y3)))) in Sy13.
apply (hombnd_fact' (Rmax_r (Rabs (x1 - x3)) _)) in Sx23.
apply (hombnd_fact' (Rmax_r (Rabs (y1 - y3)) _)) in Sy23.
assert (M1 := hombnd_mul Sx13 Sy23).
assert (M2 := hombnd_mul Sx23 Sy13).
clear Sx13 Sy23 Sx23 Sy13.
apply hombnd_rnd'' in M1.
apply hombnd_rnd'' in M2.
assert (D := hombnd_sub M1 M2).
clear M1 M2.
apply hombnd_rnd' in D.
rewrite Rmin_left in D by apply Rle_refl.
(*
match goal with
| H: hombnd' _ _ _ _ ?err _ |- _ => let e := eval vm_compute in err in idtac e
end.
*)
exact D.
Qed.

Lemma Rmax_assoc :
  forall x y z,
  Rmax x (Rmax y z) = Rmax (Rmax x y) z.
Proof.
intros x y z.
unfold Rmax.
destruct (Rle_dec x y) as [Hxy|Hxy].
destruct (Rle_dec y) as [Hyz|Hyz].
assert (Hxz := Rle_trans _ _ _ Hxy Hyz).
now case Rle_dec.
now case Rle_dec.
destruct (Rle_dec y) as [Hyz|Hyz].
easy.
case Rle_dec ; try easy.
intros _.
case Rle_dec ; try easy.
intros Hxz.
elim Hxy.
apply Rle_trans with (1 := Hxz).
apply Rlt_le.
now apply Rnot_le_lt.
Qed.

Lemma Rmin_max :
  forall x y,
  Rmin (Rmin x y) (Rmax x y) = Rmin x y.
Proof.
intros x y.
apply Rmin_left.
apply Rle_trans with x.
apply Rmin_l.
apply Rmax_l.
Qed.

Lemma Rmin_min :
  forall x y,
  Rmin (Rmin x y) y = Rmin x y.
Proof.
intros x y.
apply Rmin_left.
apply Rmin_r.
Qed.

Definition incircle2d x1 y1 x2 y2 x3 y3 x4 y4 :=
  let X1 := sub x1 x4 in
  let X2 := sub x2 x4 in
  let X3 := sub x3 x4 in
  let Y1 := sub y1 y4 in
  let Y2 := sub y2 y4 in
  let Y3 := sub y3 y4 in
  let Z1 := add (mul X1 X1) (mul Y1 Y1) in
  let Z2 := add (mul X2 X2) (mul Y2 Y2) in
  let Z3 := add (mul X3 X3) (mul Y3 Y3) in
  add (add
    (mul (sub (mul X1 Y2) (mul X2 Y1)) Z3)
    (mul (sub (mul X2 Y3) (mul X3 Y2)) Z1))
    (mul (sub (mul X3 Y1) (mul X1 Y3)) Z2).

Definition incircle2d_exact x1 y1 x2 y2 x3 y3 x4 y4 :=
 (let X1 := x1 - x4 in
  let X2 := x2 - x4 in
  let X3 := x3 - x4 in
  let Y1 := y1 - y4 in
  let Y2 := y2 - y4 in
  let Y3 := y3 - y4 in
  let Z1 := X1 * X1 + Y1 * Y1 in
  let Z2 := X2 * X2 + Y2 * Y2 in
  let Z3 := X3 * X3 + Y3 * Y3 in
  (X1 * Y2 - X2 * Y1) * Z3 +
  (X2 * Y3 - X3 * Y2) * Z1 +
  (X3 * Y1 - X1 * Y3) * Z2)%R.

Definition norm3d x y z := Rmax (Rmax (Rabs x) (Rabs y)) (Rabs z).

Lemma incircle2d_spec :
  forall x1 y1 x2 y2 x3 y3 x4 y4,
  generic_format radix2 fxp x1 ->
  generic_format radix2 fxp y1 ->
  generic_format radix2 fxp x2 ->
  generic_format radix2 fxp y2 ->
  generic_format radix2 fxp x3 ->
  generic_format radix2 fxp y3 ->
  generic_format radix2 fxp x4 ->
  generic_format radix2 fxp y4 ->
  let Nx := norm3d (x1 - x4) (x2 - x4) (x3 - x4) in
  let Ny := norm3d (y1 - y4) (y2 - y4) (y3 - y4) in
  let M := (Nx * Ny * Rmax (Rsqr Nx) (Rsqr Ny))%R in
  let m := Rmin (Rmin (Rsqr Nx) (Rsqr Ny)) M in
  hombnd' m M (incircle2d x1 y1 x2 y2 x3 y3 x4 y4) (incircle2d_exact x1 y1 x2 y2 x3 y3 x4 y4)
    (Float radix2 449891379454319880216566500258074099295902168735244158654493060906025297480090105222776999487941175938788545391377857876066937154874210214115994952429543498973192 (-583)) (Float radix2 12 0).
Proof.
intros x1 y1 x2 y2 x3 y3 x4 y4 Fx1 Fy1 Fx2 Fy2 Fx3 Fy3 Fx4 Fy4.
assert (X1 := hombnd_sub_init x1 x4 Fx1 Fx4).
assert (Y1 := hombnd_sub_init y1 y4 Fy1 Fy4).
assert (X2 := hombnd_sub_init x2 x4 Fx2 Fx4).
assert (Y2 := hombnd_sub_init y2 y4 Fy2 Fy4).
assert (X3 := hombnd_sub_init x3 x4 Fx3 Fx4).
assert (Y3 := hombnd_sub_init y3 y4 Fy3 Fy4).
apply (hombnd_fact' (Rmax_l _ (Rabs (x2 - x4)))) in X1.
apply (hombnd_fact' (Rmax_l _ (Rabs (x3 - x4)))) in X1.
apply (hombnd_fact' (Rmax_l _ (Rabs (y2 - y4)))) in Y1.
apply (hombnd_fact' (Rmax_l _ (Rabs (y3 - y4)))) in Y1.
apply (hombnd_fact' (Rmax_r (Rabs (x1 - x4)) _)) in X2.
apply (hombnd_fact' (Rmax_l _ (Rabs (x3 - x4)))) in X2.
apply (hombnd_fact' (Rmax_r (Rabs (y1 - y4)) _)) in Y2.
apply (hombnd_fact' (Rmax_l _ (Rabs (y3 - y4)))) in Y2.
apply (hombnd_fact' (Rmax_r (Rabs (x2 - x4)) _)) in X3.
apply (hombnd_fact' (Rmax_r (Rabs (x1 - x4)) _)) in X3.
apply (hombnd_fact' (Rmax_r (Rabs (y2 - y4)) _)) in Y3.
apply (hombnd_fact' (Rmax_r (Rabs (y1 - y4)) _)) in Y3.
rewrite Rmax_assoc in X3.
rewrite Rmax_assoc in Y3.
assert (M12 := hombnd_mul X1 Y2).
assert (M21 := hombnd_mul X2 Y1).
assert (M23 := hombnd_mul X2 Y3).
assert (M32 := hombnd_mul X3 Y2).
assert (M31 := hombnd_mul X3 Y1).
assert (M13 := hombnd_mul X1 Y3).
apply hombnd_rnd'' in M12.
apply hombnd_rnd'' in M21.
apply hombnd_rnd'' in M23.
apply hombnd_rnd'' in M32.
apply hombnd_rnd'' in M31.
apply hombnd_rnd'' in M13.
assert (D12 := hombnd_sub M12 M21).
assert (D23 := hombnd_sub M23 M32).
assert (D31 := hombnd_sub M31 M13).
apply hombnd_rnd' in D12.
apply hombnd_rnd' in D23.
apply hombnd_rnd' in D31.
rewrite Rmin_left in D12 by apply Rle_refl.
rewrite Rmin_left in D23 by apply Rle_refl.
rewrite Rmin_left in D31 by apply Rle_refl.
clear M12 M21 M23 M32 M31 M13.
assert (M1x := hombnd_mul X1 X1).
assert (M1y := hombnd_mul Y1 Y1).
assert (M2x := hombnd_mul X2 X2).
assert (M2y := hombnd_mul Y2 Y2).
assert (M3x := hombnd_mul X3 X3).
assert (M3y := hombnd_mul Y3 Y3).
clear X1 Y1 X2 Y2 X3 Y3.
apply hombnd_rnd'' in M1x.
apply hombnd_rnd'' in M1y.
apply hombnd_rnd'' in M2x.
apply hombnd_rnd'' in M2y.
apply hombnd_rnd'' in M3x.
apply hombnd_rnd'' in M3y.
apply (hombnd_cond'' (Rmin_l _ (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4))))) in M1x.
apply (hombnd_cond'' (Rmin_r (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) _)) in M1y.
apply (hombnd_fact' (Rmax_l _ (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4))))) in M1x.
apply (hombnd_fact' (Rmax_r (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) _)) in M1y.
apply (hombnd_cond'' (Rmin_l _ (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4))))) in M2x.
apply (hombnd_cond'' (Rmin_r (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) _)) in M2y.
apply (hombnd_fact' (Rmax_l _ (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4))))) in M2x.
apply (hombnd_fact' (Rmax_r (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) _)) in M2y.
apply (hombnd_cond'' (Rmin_l _ (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4))))) in M3x.
apply (hombnd_cond'' (Rmin_r (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) _)) in M3y.
apply (hombnd_fact' (Rmax_l _ (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4))))) in M3x.
apply (hombnd_fact' (Rmax_r (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) _)) in M3y.
assert (Z1 := hombnd_add M1x M1y).
assert (Z2 := hombnd_add M2x M2y).
assert (Z3 := hombnd_add M3x M3y).
clear M1x M1y M2x M2y M3x M3y.
apply hombnd_rnd' in Z1.
apply hombnd_rnd' in Z2.
apply hombnd_rnd' in Z3.
rewrite Rmin_max in Z1.
rewrite Rmin_max in Z2.
rewrite Rmin_max in Z3.
apply (hombnd_cond'' (Rmin_l _ (Rmin (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4)))))) in D12.
apply (hombnd_cond'' (Rmin_l _ (Rmin (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4)))))) in D23.
apply (hombnd_cond'' (Rmin_l _ (Rmin (Rsqr (norm3d (x1 - x4) (x2 - x4) (x3 - x4))) (Rsqr (norm3d (y1 - y4) (y2 - y4) (y3 - y4)))))) in D31.
apply (hombnd_cond'' (Rmin_r (norm3d (x1 - x4) (x2 - x4) (x3 - x4) * norm3d (y1 - y4) (y2 - y4) (y3 - y4)) _)) in Z1.
apply (hombnd_cond'' (Rmin_r (norm3d (x1 - x4) (x2 - x4) (x3 - x4) * norm3d (y1 - y4) (y2 - y4) (y3 - y4)) _)) in Z2.
apply (hombnd_cond'' (Rmin_r (norm3d (x1 - x4) (x2 - x4) (x3 - x4) * norm3d (y1 - y4) (y2 - y4) (y3 - y4)) _)) in Z3.
assert (M1 := hombnd_mul D12 Z3).
assert (M2 := hombnd_mul D23 Z1).
assert (M3 := hombnd_mul D31 Z2).
clear D12 D23 D31 Z1 Z2 Z3.
apply hombnd_rnd' in M1.
apply hombnd_rnd' in M2.
apply hombnd_rnd' in M3.
assert (A1 := hombnd_add M1 M2).
clear M1 M2.
apply hombnd_rnd' in A1.
rewrite Rmin_min in A1.
assert (A2 := hombnd_add A1 M3).
apply hombnd_rnd' in A2.
clear A1 M3.
rewrite Rmin_min in A2.
rewrite (Rmin_right (Rmult _ _)) in A2.
exact A2.
clear.
unfold Rmin.
destruct Rle_dec as [H|H].
apply Rsqr_incr_0 in H.
apply Rmult_le_compat_l with (2 := H).
repeat apply Rmax_case ; apply Rabs_pos.
unfold norm3d ; repeat apply Rmax_case ; apply Rabs_pos.
unfold norm3d ; repeat apply Rmax_case ; apply Rabs_pos.
apply Rnot_le_lt in H.
apply Rlt_le in H.
apply Rsqr_incr_0 in H.
apply Rmult_le_compat_r with (2 := H).
repeat apply Rmax_case ; apply Rabs_pos.
unfold norm3d ; repeat apply Rmax_case ; apply Rabs_pos.
unfold norm3d ; repeat apply Rmax_case ; apply Rabs_pos.
Qed.

End Example.