lemma_impl_rmat_quat.v 25.3 KB
Newer Older
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
(* This file is generated by Why3's Coq driver *)
(* Beware! Only edit allowed sections below    *)
Require Import BuiltIn.
Require Reals.Rbasic_fun.
Require Reals.R_sqrt.
Require BuiltIn.
Require HighOrd.
Require bool.Bool.
Require int.Int.
Require int.Abs.
Require int.ComputerDivision.
Require real.Real.
Require real.RealInfix.
Require real.Abs.
Require real.FromInt.
Require real.Square.
Require map.Map.

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
19 20
Local Open Scope R_scope.

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
21 22 23 24 25 26 27 28 29 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
Parameter eqb:
  forall {a:Type} {a_WT:WhyType a}, a -> a -> Init.Datatypes.bool.

Axiom eqb1 :
  forall {a:Type} {a_WT:WhyType a},
  forall (x:a) (y:a), ((eqb x y) = Init.Datatypes.true) <-> (x = y).

Axiom eqb_false :
  forall {a:Type} {a_WT:WhyType a},
  forall (x:a) (y:a), ((eqb x y) = Init.Datatypes.false) <-> ~ (x = y).

Parameter neqb:
  forall {a:Type} {a_WT:WhyType a}, a -> a -> Init.Datatypes.bool.

Axiom neqb1 :
  forall {a:Type} {a_WT:WhyType a},
  forall (x:a) (y:a), ((neqb x y) = Init.Datatypes.true) <-> ~ (x = y).

Parameter zlt: Numbers.BinNums.Z -> Numbers.BinNums.Z -> Init.Datatypes.bool.

Parameter zleq:
  Numbers.BinNums.Z -> Numbers.BinNums.Z -> Init.Datatypes.bool.

Axiom zlt1 :
  forall (x:Numbers.BinNums.Z) (y:Numbers.BinNums.Z),
  ((zlt x y) = Init.Datatypes.true) <-> (x < y)%Z.

Axiom zleq1 :
  forall (x:Numbers.BinNums.Z) (y:Numbers.BinNums.Z),
  ((zleq x y) = Init.Datatypes.true) <-> (x <= y)%Z.

Parameter rlt:
  Reals.Rdefinitions.R -> Reals.Rdefinitions.R -> Init.Datatypes.bool.

Parameter rleq:
  Reals.Rdefinitions.R -> Reals.Rdefinitions.R -> Init.Datatypes.bool.

Axiom rlt1 :
  forall (x:Reals.Rdefinitions.R) (y:Reals.Rdefinitions.R),
  ((rlt x y) = Init.Datatypes.true) <-> (x < y)%R.

Axiom rleq1 :
  forall (x:Reals.Rdefinitions.R) (y:Reals.Rdefinitions.R),
  ((rleq x y) = Init.Datatypes.true) <-> (x <= y)%R.

(* Why3 assumption *)
Definition real_of_int (x:Numbers.BinNums.Z) : Reals.Rdefinitions.R :=
  BuiltIn.IZR x.

Axiom c_euclidian :
  forall (n:Numbers.BinNums.Z) (d:Numbers.BinNums.Z), ~ (d = 0%Z) ->
  (n = (((ZArith.BinInt.Z.quot n d) * d)%Z + (ZArith.BinInt.Z.rem n d))%Z).

Axiom cmod_remainder :
  forall (n:Numbers.BinNums.Z) (d:Numbers.BinNums.Z),
  ((0%Z <= n)%Z -> (0%Z < d)%Z ->
   (0%Z <= (ZArith.BinInt.Z.rem n d))%Z /\ ((ZArith.BinInt.Z.rem n d) < d)%Z) /\
  ((n <= 0%Z)%Z -> (0%Z < d)%Z ->
   ((-d)%Z < (ZArith.BinInt.Z.rem n d))%Z /\
   ((ZArith.BinInt.Z.rem n d) <= 0%Z)%Z) /\
  ((0%Z <= n)%Z -> (d < 0%Z)%Z ->
   (0%Z <= (ZArith.BinInt.Z.rem n d))%Z /\
   ((ZArith.BinInt.Z.rem n d) < (-d)%Z)%Z) /\
  ((n <= 0%Z)%Z -> (d < 0%Z)%Z ->
   (d < (ZArith.BinInt.Z.rem n d))%Z /\ ((ZArith.BinInt.Z.rem n d) <= 0%Z)%Z).

Axiom cdiv_neutral :
  forall (a:Numbers.BinNums.Z), ((ZArith.BinInt.Z.quot a 1%Z) = a).

Axiom cdiv_inv :
  forall (a:Numbers.BinNums.Z), ~ (a = 0%Z) ->
  ((ZArith.BinInt.Z.quot a a) = 1%Z).

Axiom cdiv_closed_remainder :
  forall (a:Numbers.BinNums.Z) (b:Numbers.BinNums.Z) (n:Numbers.BinNums.Z),
  (0%Z <= a)%Z -> (0%Z <= b)%Z ->
  (0%Z <= (b - a)%Z)%Z /\ ((b - a)%Z < n)%Z ->
  ((ZArith.BinInt.Z.rem a n) = (ZArith.BinInt.Z.rem b n)) -> (a = b).

(* Why3 assumption *)
Inductive addr :=
  | addr'mk : Numbers.BinNums.Z -> Numbers.BinNums.Z -> addr.
Axiom addr_WhyType : WhyType addr.
Existing Instance addr_WhyType.

(* Why3 assumption *)
Definition offset (v:addr) : Numbers.BinNums.Z :=
  match v with
  | addr'mk x x1 => x1
  end.

(* Why3 assumption *)
Definition base (v:addr) : Numbers.BinNums.Z :=
  match v with
  | addr'mk x x1 => x
  end.

Parameter addr_le: addr -> addr -> Prop.

Parameter addr_lt: addr -> addr -> Prop.

Parameter addr_le_bool: addr -> addr -> Init.Datatypes.bool.

Parameter addr_lt_bool: addr -> addr -> Init.Datatypes.bool.

Axiom addr_le_def :
  forall (p:addr) (q:addr), ((base p) = (base q)) ->
  addr_le p q <-> ((offset p) <= (offset q))%Z.

Axiom addr_lt_def :
  forall (p:addr) (q:addr), ((base p) = (base q)) ->
  addr_lt p q <-> ((offset p) < (offset q))%Z.

Axiom addr_le_bool_def :
  forall (p:addr) (q:addr),
  addr_le p q <-> ((addr_le_bool p q) = Init.Datatypes.true).

Axiom addr_lt_bool_def :
  forall (p:addr) (q:addr),
  addr_lt p q <-> ((addr_lt_bool p q) = Init.Datatypes.true).

(* Why3 assumption *)
Definition null : addr := addr'mk 0%Z 0%Z.

(* Why3 assumption *)
Definition global (b:Numbers.BinNums.Z) : addr := addr'mk b 0%Z.

(* Why3 assumption *)
Definition shift (p:addr) (k:Numbers.BinNums.Z) : addr :=
  addr'mk (base p) ((offset p) + k)%Z.

(* Why3 assumption *)
Definition included (p:addr) (a:Numbers.BinNums.Z) (q:addr)
    (b:Numbers.BinNums.Z) : Prop :=
  (0%Z < a)%Z ->
  (0%Z <= b)%Z /\
  ((base p) = (base q)) /\
  ((offset q) <= (offset p))%Z /\
  (((offset p) + a)%Z <= ((offset q) + b)%Z)%Z.

(* Why3 assumption *)
Definition separated (p:addr) (a:Numbers.BinNums.Z) (q:addr)
    (b:Numbers.BinNums.Z) : Prop :=
  (a <= 0%Z)%Z \/
  (b <= 0%Z)%Z \/
  ~ ((base p) = (base q)) \/
  (((offset q) + b)%Z <= (offset p))%Z \/
  (((offset p) + a)%Z <= (offset q))%Z.

(* Why3 assumption *)
Definition eqmem {a:Type} {a_WT:WhyType a} (m1:addr -> a) (m2:addr -> a)
    (p:addr) (a1:Numbers.BinNums.Z) : Prop :=
  forall (q:addr), included q 1%Z p a1 -> ((m1 q) = (m2 q)).

Parameter havoc:
  forall {a:Type} {a_WT:WhyType a}, (addr -> a) -> (addr -> a) -> addr ->
  Numbers.BinNums.Z -> addr -> a.

(* Why3 assumption *)
Definition valid_rw (m:Numbers.BinNums.Z -> Numbers.BinNums.Z) (p:addr)
    (n:Numbers.BinNums.Z) : Prop :=
  (0%Z < n)%Z ->
  (0%Z < (base p))%Z /\
  (0%Z <= (offset p))%Z /\ (((offset p) + n)%Z <= (m (base p)))%Z.

(* Why3 assumption *)
Definition valid_rd (m:Numbers.BinNums.Z -> Numbers.BinNums.Z) (p:addr)
    (n:Numbers.BinNums.Z) : Prop :=
  (0%Z < n)%Z ->
  ~ (0%Z = (base p)) /\
  (0%Z <= (offset p))%Z /\ (((offset p) + n)%Z <= (m (base p)))%Z.

(* Why3 assumption *)
Definition valid_obj (m:Numbers.BinNums.Z -> Numbers.BinNums.Z) (p:addr)
    (n:Numbers.BinNums.Z) : Prop :=
  (0%Z < n)%Z ->
  (p = null) \/
  ~ (0%Z = (base p)) /\
  (0%Z <= (offset p))%Z /\ (((offset p) + n)%Z <= (1%Z + (m (base p)))%Z)%Z.

(* Why3 assumption *)
Definition invalid (m:Numbers.BinNums.Z -> Numbers.BinNums.Z) (p:addr)
    (n:Numbers.BinNums.Z) : Prop :=
  (n <= 0%Z)%Z \/
  ((base p) = 0%Z) \/
  ((m (base p)) <= (offset p))%Z \/ (((offset p) + n)%Z <= 0%Z)%Z.

Axiom valid_rw_rd :
  forall (m:Numbers.BinNums.Z -> Numbers.BinNums.Z), forall (p:addr),
  forall (n:Numbers.BinNums.Z), valid_rw m p n -> valid_rd m p n.

Axiom valid_string :
  forall (m:Numbers.BinNums.Z -> Numbers.BinNums.Z), forall (p:addr),
  ((base p) < 0%Z)%Z ->
  (0%Z <= (offset p))%Z /\ ((offset p) < (m (base p)))%Z ->
  valid_rd m p 1%Z /\ ~ valid_rw m p 1%Z.

Axiom separated_1 :
  forall (p:addr) (q:addr),
  forall (a:Numbers.BinNums.Z) (b:Numbers.BinNums.Z) (i:Numbers.BinNums.Z)
    (j:Numbers.BinNums.Z),
  separated p a q b -> ((offset p) <= i)%Z /\ (i < ((offset p) + a)%Z)%Z ->
  ((offset q) <= j)%Z /\ (j < ((offset q) + b)%Z)%Z ->
  ~ ((addr'mk (base p) i) = (addr'mk (base q) j)).

Parameter region: Numbers.BinNums.Z -> Numbers.BinNums.Z.

Parameter linked: (Numbers.BinNums.Z -> Numbers.BinNums.Z) -> Prop.

Parameter sconst: (addr -> Numbers.BinNums.Z) -> Prop.

(* Why3 assumption *)
Definition framed (m:addr -> addr) : Prop :=
  forall (p:addr), ((region (base (m p))) <= 0%Z)%Z.

Axiom separated_included :
  forall (p:addr) (q:addr),
  forall (a:Numbers.BinNums.Z) (b:Numbers.BinNums.Z), (0%Z < a)%Z ->
  (0%Z < b)%Z -> separated p a q b -> ~ included p a q b.

Axiom included_trans :
  forall (p:addr) (q:addr) (r:addr),
  forall (a:Numbers.BinNums.Z) (b:Numbers.BinNums.Z) (c:Numbers.BinNums.Z),
  included p a q b -> included q b r c -> included p a r c.

Axiom separated_trans :
  forall (p:addr) (q:addr) (r:addr),
  forall (a:Numbers.BinNums.Z) (b:Numbers.BinNums.Z) (c:Numbers.BinNums.Z),
  included p a q b -> separated q b r c -> separated p a r c.

Axiom separated_sym :
  forall (p:addr) (q:addr),
  forall (a:Numbers.BinNums.Z) (b:Numbers.BinNums.Z),
  separated p a q b <-> separated q b p a.

Axiom eqmem_included :
  forall {a:Type} {a_WT:WhyType a},
  forall (m1:addr -> a) (m2:addr -> a), forall (p:addr) (q:addr),
  forall (a1:Numbers.BinNums.Z) (b:Numbers.BinNums.Z), included p a1 q b ->
  eqmem m1 m2 q b -> eqmem m1 m2 p a1.

Axiom eqmem_sym :
  forall {a:Type} {a_WT:WhyType a},
  forall (m1:addr -> a) (m2:addr -> a), forall (p:addr),
  forall (a1:Numbers.BinNums.Z), eqmem m1 m2 p a1 -> eqmem m2 m1 p a1.

Axiom havoc_access :
  forall {a:Type} {a_WT:WhyType a},
  forall (m0:addr -> a) (m1:addr -> a), forall (q:addr) (p:addr),
  forall (a1:Numbers.BinNums.Z),
  (separated q 1%Z p a1 -> ((havoc m0 m1 p a1 q) = (m1 q))) /\
  (~ separated q 1%Z p a1 -> ((havoc m0 m1 p a1 q) = (m0 q))).

Parameter cinits: (addr -> Init.Datatypes.bool) -> Prop.

(* Why3 assumption *)
Definition is_init_range (m:addr -> Init.Datatypes.bool) (p:addr)
    (l:Numbers.BinNums.Z) : Prop :=
  forall (i:Numbers.BinNums.Z), (0%Z <= i)%Z /\ (i < l)%Z ->
  ((m (shift p i)) = Init.Datatypes.true).

Parameter set_init:
  (addr -> Init.Datatypes.bool) -> addr -> Numbers.BinNums.Z ->
  addr -> Init.Datatypes.bool.

Axiom set_init_access :
  forall (m:addr -> Init.Datatypes.bool), forall (q:addr) (p:addr),
  forall (a:Numbers.BinNums.Z),
  (separated q 1%Z p a -> ((set_init m p a q) = (m q))) /\
  (~ separated q 1%Z p a -> ((set_init m p a q) = Init.Datatypes.true)).

(* Why3 assumption *)
Definition monotonic_init (m1:addr -> Init.Datatypes.bool)
    (m2:addr -> Init.Datatypes.bool) : Prop :=
  forall (p:addr), ((m1 p) = Init.Datatypes.true) ->
  ((m2 p) = Init.Datatypes.true).

Parameter int_of_addr: addr -> Numbers.BinNums.Z.

Parameter addr_of_int: Numbers.BinNums.Z -> addr.

Axiom table : Type.
Parameter table_WhyType : WhyType table.
Existing Instance table_WhyType.

Parameter table_of_base: Numbers.BinNums.Z -> table.

Parameter table_to_offset: table -> Numbers.BinNums.Z -> Numbers.BinNums.Z.

Axiom table_to_offset_zero :
  forall (t:table), ((table_to_offset t 0%Z) = 0%Z).

Axiom table_to_offset_monotonic :
  forall (t:table), forall (o1:Numbers.BinNums.Z) (o2:Numbers.BinNums.Z),
  (o1 <= o2)%Z <-> ((table_to_offset t o1) <= (table_to_offset t o2))%Z.

Axiom int_of_addr_bijection :
  forall (a:Numbers.BinNums.Z), ((int_of_addr (addr_of_int a)) = a).

Axiom addr_of_int_bijection :
  forall (p:addr), ((addr_of_int (int_of_addr p)) = p).

Axiom addr_of_null : ((int_of_addr null) = 0%Z).

(* Why3 assumption *)
Definition P_unary_quaternion_1_ (Mf32:addr -> Reals.Rdefinitions.R)
    (q:addr) : Prop :=
  let r := Mf32 (shift q 0%Z) in
  let r1 := Mf32 (shift q 1%Z) in
  let r2 := Mf32 (shift q 2%Z) in
  let r3 := Mf32 (shift q 3%Z) in
  (((((r * r)%R + (r1 * r1)%R)%R + (r2 * r2)%R)%R + (r3 * r3)%R)%R = 1%R).

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
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
(* Why3 assumption *)
Inductive S12_RealRMat_s :=
  | S12_RealRMat_s1 : Reals.Rdefinitions.R -> Reals.Rdefinitions.R ->
      Reals.Rdefinitions.R -> Reals.Rdefinitions.R -> Reals.Rdefinitions.R ->
      Reals.Rdefinitions.R -> Reals.Rdefinitions.R -> Reals.Rdefinitions.R ->
      Reals.Rdefinitions.R -> S12_RealRMat_s.
Axiom S12_RealRMat_s_WhyType : WhyType S12_RealRMat_s.
Existing Instance S12_RealRMat_s_WhyType.

(* Why3 assumption *)
Definition F12_RealRMat_s_a22 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x8
  end.

(* Why3 assumption *)
Definition F12_RealRMat_s_a21 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x7
  end.

(* Why3 assumption *)
Definition F12_RealRMat_s_a20 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x6
  end.

(* Why3 assumption *)
Definition F12_RealRMat_s_a12 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x5
  end.

(* Why3 assumption *)
Definition F12_RealRMat_s_a11 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x4
  end.

(* Why3 assumption *)
Definition F12_RealRMat_s_a10 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x3
  end.

(* Why3 assumption *)
Definition F12_RealRMat_s_a02 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x2
  end.

(* Why3 assumption *)
Definition F12_RealRMat_s_a01 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x1
  end.

(* Why3 assumption *)
Definition F12_RealRMat_s_a00 (v:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  match v with
  | S12_RealRMat_s1 x x1 x2 x3 x4 x5 x6 x7 x8 => x
  end.

(* Why3 assumption *)
Definition EqS12_RealRMat_s (S:S12_RealRMat_s) (S1:S12_RealRMat_s) : Prop :=
  (((((((((F12_RealRMat_s_a00 S1) = (F12_RealRMat_s_a00 S)) /\
         ((F12_RealRMat_s_a01 S1) = (F12_RealRMat_s_a01 S))) /\
        ((F12_RealRMat_s_a02 S1) = (F12_RealRMat_s_a02 S))) /\
       ((F12_RealRMat_s_a10 S1) = (F12_RealRMat_s_a10 S))) /\
      ((F12_RealRMat_s_a11 S1) = (F12_RealRMat_s_a11 S))) /\
     ((F12_RealRMat_s_a12 S1) = (F12_RealRMat_s_a12 S))) /\
    ((F12_RealRMat_s_a20 S1) = (F12_RealRMat_s_a20 S))) /\
   ((F12_RealRMat_s_a21 S1) = (F12_RealRMat_s_a21 S))) /\
  ((F12_RealRMat_s_a22 S1) = (F12_RealRMat_s_a22 S)).

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
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
(* Why3 assumption *)
Definition L_mult_RealRMat (rmat1:S12_RealRMat_s) (rmat2:S12_RealRMat_s) :
    S12_RealRMat_s :=
  let r := F12_RealRMat_s_a00 rmat1 in
  let r1 := F12_RealRMat_s_a00 rmat2 in
  let r2 := F12_RealRMat_s_a01 rmat1 in
  let r3 := F12_RealRMat_s_a10 rmat2 in
  let r4 := F12_RealRMat_s_a02 rmat1 in
  let r5 := F12_RealRMat_s_a20 rmat2 in
  let r6 := F12_RealRMat_s_a01 rmat2 in
  let r7 := F12_RealRMat_s_a11 rmat2 in
  let r8 := F12_RealRMat_s_a21 rmat2 in
  let r9 := F12_RealRMat_s_a02 rmat2 in
  let r10 := F12_RealRMat_s_a12 rmat2 in
  let r11 := F12_RealRMat_s_a22 rmat2 in
  let r12 := F12_RealRMat_s_a10 rmat1 in
  let r13 := F12_RealRMat_s_a11 rmat1 in
  let r14 := F12_RealRMat_s_a12 rmat1 in
  let r15 := F12_RealRMat_s_a20 rmat1 in
  let r16 := F12_RealRMat_s_a21 rmat1 in
  let r17 := F12_RealRMat_s_a22 rmat1 in
  S12_RealRMat_s1 (((r * r1)%R + (r2 * r3)%R)%R + (r4 * r5)%R)%R
  (((r * r6)%R + (r2 * r7)%R)%R + (r4 * r8)%R)%R
  (((r * r9)%R + (r2 * r10)%R)%R + (r4 * r11)%R)%R
  (((r12 * r1)%R + (r13 * r3)%R)%R + (r14 * r5)%R)%R
  (((r12 * r6)%R + (r13 * r7)%R)%R + (r14 * r8)%R)%R
  (((r12 * r9)%R + (r13 * r10)%R)%R + (r14 * r11)%R)%R
  (((r15 * r1)%R + (r16 * r3)%R)%R + (r17 * r5)%R)%R
  (((r15 * r6)%R + (r16 * r7)%R)%R + (r17 * r8)%R)%R
  (((r15 * r9)%R + (r16 * r10)%R)%R + (r17 * r11)%R)%R.

(* Why3 assumption *)
Definition L_transpose (rmat:S12_RealRMat_s) : S12_RealRMat_s :=
  S12_RealRMat_s1 (F12_RealRMat_s_a00 rmat) (F12_RealRMat_s_a10 rmat)
  (F12_RealRMat_s_a20 rmat) (F12_RealRMat_s_a01 rmat)
  (F12_RealRMat_s_a11 rmat) (F12_RealRMat_s_a21 rmat)
  (F12_RealRMat_s_a02 rmat) (F12_RealRMat_s_a12 rmat)
  (F12_RealRMat_s_a22 rmat).

(* Why3 assumption *)
Definition P_rotation_matrix (rmat:S12_RealRMat_s) : Prop :=
  EqS12_RealRMat_s (L_mult_RealRMat rmat (L_transpose rmat))
  (S12_RealRMat_s1 1%R 0%R 0%R 0%R 1%R 0%R 0%R 0%R 1%R).

(* Why3 assumption *)
Definition L_mult_scalar (rmat:S12_RealRMat_s) (a:Numbers.BinNums.Z) :
    S12_RealRMat_s :=
  let r := real_of_int a in
  S12_RealRMat_s1 (r * (F12_RealRMat_s_a00 rmat))%R
  (r * (F12_RealRMat_s_a01 rmat))%R (r * (F12_RealRMat_s_a02 rmat))%R
  (r * (F12_RealRMat_s_a10 rmat))%R (r * (F12_RealRMat_s_a11 rmat))%R
  (r * (F12_RealRMat_s_a12 rmat))%R (r * (F12_RealRMat_s_a20 rmat))%R
  (r * (F12_RealRMat_s_a21 rmat))%R (r * (F12_RealRMat_s_a22 rmat))%R.

Axiom Q_mult_id_rmat_neutral :
  forall (rmat:S12_RealRMat_s),
  EqS12_RealRMat_s
  (L_mult_RealRMat rmat
   (S12_RealRMat_s1 1%R 0%R 0%R 0%R 1%R 0%R 0%R 0%R 1%R))
  rmat.

Axiom Q_mult_rmat_id_neutral :
  forall (rmat:S12_RealRMat_s),
  EqS12_RealRMat_s
  (L_mult_RealRMat (S12_RealRMat_s1 1%R 0%R 0%R 0%R 1%R 0%R 0%R 0%R 1%R)
   rmat)
  rmat.

Axiom Q_transpose_id :
  forall (a:Numbers.BinNums.Z),
  let a1 :=
  L_mult_scalar (S12_RealRMat_s1 1%R 0%R 0%R 0%R 1%R 0%R 0%R 0%R 1%R) a in
  EqS12_RealRMat_s (L_transpose a1) a1.

Axiom Q_transpose_transpose_rmat :
  forall (rmat:S12_RealRMat_s),
  EqS12_RealRMat_s (L_transpose (L_transpose rmat)) rmat.

(* Why3 assumption *)
Definition L_l_RMat_of_FloatQuat_1_ (Mf32:addr -> Reals.Rdefinitions.R)
    (q:addr) : S12_RealRMat_s :=
  let r := Mf32 (shift q 2%Z) in
  let r1 := (r * r)%R in
  let r2 := ((-1%R)%R * r1)%R in
  let r3 := Mf32 (shift q 3%Z) in
  let r4 := (r3 * r3)%R in
  let r5 := ((-1%R)%R * r4)%R in
  let r6 := Mf32 (shift q 0%Z) in
  let r7 := (r6 * r6)%R in
  let r8 := Mf32 (shift q 1%Z) in
  let r9 := (r8 * r8)%R in
  let r10 := (r6 * r3)%R in
  let r11 := (r8 * r)%R in
  let r12 := (r6 * r)%R in
  let r13 := (r8 * r3)%R in
  let r14 := ((-1%R)%R * r9)%R in
  let r15 := (r6 * r8)%R in
  let r16 := (r * r3)%R in
  S12_RealRMat_s1 (((r2 + r5)%R + r7)%R + r9)%R
  (2%R * (((-1%R)%R * r10)%R + r11)%R)%R (2%R * (r12 + r13)%R)%R
  (2%R * (r10 + r11)%R)%R (((r14 + r5)%R + r7)%R + r1)%R
  (2%R * (((-1%R)%R * r15)%R + r16)%R)%R
  (2%R * (((-1%R)%R * r12)%R + r13)%R)%R (2%R * (r15 + r16)%R)%R
  (((r14 + r2)%R + r7)%R + r4)%R.

Axiom Q_quat_of_rmat_ortho :
  forall (Mf32:addr -> Reals.Rdefinitions.R) (q:addr),
  P_unary_quaternion_1_ Mf32 q ->
  P_rotation_matrix (L_l_RMat_of_FloatQuat_1_ Mf32 q).

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
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
(* Why3 assumption *)
Inductive S13_RealQuat_s :=
  | S13_RealQuat_s1 : Reals.Rdefinitions.R -> Reals.Rdefinitions.R ->
      Reals.Rdefinitions.R -> Reals.Rdefinitions.R -> S13_RealQuat_s.
Axiom S13_RealQuat_s_WhyType : WhyType S13_RealQuat_s.
Existing Instance S13_RealQuat_s_WhyType.

(* Why3 assumption *)
Definition F13_RealQuat_s_qz (v:S13_RealQuat_s) : Reals.Rdefinitions.R :=
  match v with
  | S13_RealQuat_s1 x x1 x2 x3 => x3
  end.

(* Why3 assumption *)
Definition F13_RealQuat_s_qy (v:S13_RealQuat_s) : Reals.Rdefinitions.R :=
  match v with
  | S13_RealQuat_s1 x x1 x2 x3 => x2
  end.

(* Why3 assumption *)
Definition F13_RealQuat_s_qx (v:S13_RealQuat_s) : Reals.Rdefinitions.R :=
  match v with
  | S13_RealQuat_s1 x x1 x2 x3 => x1
  end.

(* Why3 assumption *)
Definition F13_RealQuat_s_qi (v:S13_RealQuat_s) : Reals.Rdefinitions.R :=
  match v with
  | S13_RealQuat_s1 x x1 x2 x3 => x
  end.

(* Why3 assumption *)
Definition EqS13_RealQuat_s (S:S13_RealQuat_s) (S1:S13_RealQuat_s) : Prop :=
  ((((F13_RealQuat_s_qi S1) = (F13_RealQuat_s_qi S)) /\
    ((F13_RealQuat_s_qx S1) = (F13_RealQuat_s_qx S))) /\
   ((F13_RealQuat_s_qy S1) = (F13_RealQuat_s_qy S))) /\
  ((F13_RealQuat_s_qz S1) = (F13_RealQuat_s_qz S)).

(* Why3 assumption *)
Definition L_l_RMat_of_FloatQuat_2_ (q:S13_RealQuat_s) : S12_RealRMat_s :=
  let r := F13_RealQuat_s_qy q in
  let r1 := (r * r)%R in
  let r2 := ((-1%R)%R * r1)%R in
  let r3 := F13_RealQuat_s_qz q in
  let r4 := (r3 * r3)%R in
  let r5 := ((-1%R)%R * r4)%R in
  let r6 := F13_RealQuat_s_qi q in
  let r7 := (r6 * r6)%R in
  let r8 := F13_RealQuat_s_qx q in
  let r9 := (r8 * r8)%R in
  let r10 := (r6 * r3)%R in
  let r11 := (r8 * r)%R in
  let r12 := (r6 * r)%R in
  let r13 := (r8 * r3)%R in
  let r14 := ((-1%R)%R * r9)%R in
  let r15 := (r6 * r8)%R in
  let r16 := (r * r3)%R in
  S12_RealRMat_s1 (((r2 + r5)%R + r7)%R + r9)%R
  (2%R * (((-1%R)%R * r10)%R + r11)%R)%R (2%R * (r12 + r13)%R)%R
  (2%R * (r10 + r11)%R)%R (((r14 + r5)%R + r7)%R + r1)%R
  (2%R * (((-1%R)%R * r15)%R + r16)%R)%R
  (2%R * (((-1%R)%R * r12)%R + r13)%R)%R (2%R * (r15 + r16)%R)%R
  (((r14 + r2)%R + r7)%R + r4)%R.

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
(* Why3 assumption *)
Definition L_l_Quat_of_FloatQuat (Mf32:addr -> Reals.Rdefinitions.R)
    (q:addr) : S13_RealQuat_s :=
  S13_RealQuat_s1 (Mf32 (shift q 0%Z)) (Mf32 (shift q 1%Z))
  (Mf32 (shift q 2%Z)) (Mf32 (shift q 3%Z)).

Axiom Q_mutliple_def_rmat_of_quat_4 :
  forall (Malloc:Numbers.BinNums.Z -> Numbers.BinNums.Z)
    (Mf32:addr -> Reals.Rdefinitions.R) (q:addr),
  P_unary_quaternion_1_ Mf32 q -> valid_rd Malloc q 4%Z ->
  EqS12_RealRMat_s (L_l_RMat_of_FloatQuat_1_ Mf32 q)
  (L_l_RMat_of_FloatQuat_2_ (L_l_Quat_of_FloatQuat Mf32 q)).

(* Why3 assumption *)
Definition L_l_RMat_of_FloatQuat_bis_1 (Mf32:addr -> Reals.Rdefinitions.R)
    (q:addr) : S12_RealRMat_s :=
  let r := Mf32 (shift q 2%Z) in
  let r1 := (r * r)%R in
  let r2 := Mf32 (shift q 3%Z) in
  let r3 := (r2 * r2)%R in
  let r4 := Mf32 (shift q 0%Z) in
  let r5 := (r4 * r2)%R in
  let r6 := Mf32 (shift q 1%Z) in
  let r7 := (r6 * r)%R in
  let r8 := (r4 * r)%R in
  let r9 := (r6 * r2)%R in
  let r10 := (r6 * r6)%R in
  let r11 := (r4 * r6)%R in
  let r12 := (r * r2)%R in
  S12_RealRMat_s1 (1%R + ((-1%R)%R * (2%R * (r1 + r3)%R)%R)%R)%R
  (2%R * (((-1%R)%R * r5)%R + r7)%R)%R (2%R * (r8 + r9)%R)%R
  (2%R * (r5 + r7)%R)%R (1%R + ((-1%R)%R * (2%R * (r10 + r3)%R)%R)%R)%R
  (2%R * (((-1%R)%R * r11)%R + r12)%R)%R (2%R * (((-1%R)%R * r8)%R + r9)%R)%R
  (2%R * (r11 + r12)%R)%R (1%R + ((-1%R)%R * (2%R * (r10 + r1)%R)%R)%R)%R.

(* Why3 assumption *)
Definition L_l_RMat_of_FloatQuat_bis_2 (Mf32:addr -> Reals.Rdefinitions.R)
    (q:addr) : S12_RealRMat_s :=
  let r := Mf32 (shift q 0%Z) in
  let r1 := (r * r)%R in
  let r2 := Mf32 (shift q 1%Z) in
  let r3 := Mf32 (shift q 3%Z) in
  let r4 := (r * r3)%R in
  let r5 := Mf32 (shift q 2%Z) in
  let r6 := (r2 * r5)%R in
  let r7 := (r * r5)%R in
  let r8 := (r2 * r3)%R in
  let r9 := (r * r2)%R in
  let r10 := (r5 * r3)%R in
  S12_RealRMat_s1 ((-1%R)%R + (2%R * (r1 + (r2 * r2)%R)%R)%R)%R
  (2%R * (((-1%R)%R * r4)%R + r6)%R)%R (2%R * (r7 + r8)%R)%R
  (2%R * (r4 + r6)%R)%R ((-1%R)%R + (2%R * (r1 + (r5 * r5)%R)%R)%R)%R
  (2%R * (((-1%R)%R * r9)%R + r10)%R)%R (2%R * (((-1%R)%R * r7)%R + r8)%R)%R
  (2%R * (r9 + r10)%R)%R ((-1%R)%R + (2%R * (r1 + (r3 * r3)%R)%R)%R)%R.

Axiom Q_mutliple_def_rmat_of_quat_3 :
  forall (Malloc:Numbers.BinNums.Z -> Numbers.BinNums.Z)
    (Mf32:addr -> Reals.Rdefinitions.R) (q:addr),
  P_unary_quaternion_1_ Mf32 q -> valid_rd Malloc q 4%Z ->
  EqS12_RealRMat_s (L_l_RMat_of_FloatQuat_bis_1 Mf32 q)
  (L_l_RMat_of_FloatQuat_bis_2 Mf32 q).

Axiom Q_mutliple_def_rmat_of_quat_2 :
  forall (Malloc:Numbers.BinNums.Z -> Numbers.BinNums.Z)
    (Mf32:addr -> Reals.Rdefinitions.R) (q:addr),
  P_unary_quaternion_1_ Mf32 q -> valid_rd Malloc q 4%Z ->
  EqS12_RealRMat_s (L_l_RMat_of_FloatQuat_1_ Mf32 q)
  (L_l_RMat_of_FloatQuat_bis_2 Mf32 q).

Axiom Q_mutliple_def_rmat_of_quat_1 :
  forall (Malloc:Numbers.BinNums.Z -> Numbers.BinNums.Z)
    (Mf32:addr -> Reals.Rdefinitions.R) (q:addr),
  P_unary_quaternion_1_ Mf32 q -> valid_rd Malloc q 4%Z ->
  EqS12_RealRMat_s (L_l_RMat_of_FloatQuat_1_ Mf32 q)
  (L_l_RMat_of_FloatQuat_bis_1 Mf32 q).

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
659 660 661 662 663 664 665 666
(* Why3 assumption *)
Definition P_unary_quaternion_2_ (q:S13_RealQuat_s) : Prop :=
  let r := F13_RealQuat_s_qi q in
  let r1 := F13_RealQuat_s_qx q in
  let r2 := F13_RealQuat_s_qy q in
  let r3 := F13_RealQuat_s_qz q in
  (((((r * r)%R + (r1 * r1)%R)%R + (r2 * r2)%R)%R + (r3 * r3)%R)%R = 1%R).

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
667 668 669 670 671
Axiom Q_equivalence_unary_pred :
  forall (Mf32:addr -> Reals.Rdefinitions.R) (q:addr),
  P_unary_quaternion_2_ (L_l_Quat_of_FloatQuat Mf32 q) <->
  P_unary_quaternion_1_ Mf32 q.

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
Axiom abs_def :
  forall (x:Numbers.BinNums.Z),
  ((0%Z <= x)%Z -> ((ZArith.BinInt.Z.abs x) = x)) /\
  (~ (0%Z <= x)%Z -> ((ZArith.BinInt.Z.abs x) = (-x)%Z)).

Axiom sqrt_lin1 :
  forall (x:Reals.Rdefinitions.R), (1%R < x)%R ->
  ((Reals.R_sqrt.sqrt x) < x)%R.

Axiom sqrt_lin0 :
  forall (x:Reals.Rdefinitions.R), (0%R < x)%R /\ (x < 1%R)%R ->
  (x < (Reals.R_sqrt.sqrt x))%R.

Axiom sqrt_0 : ((Reals.R_sqrt.sqrt 0%R) = 0%R).

Axiom sqrt_1 : ((Reals.R_sqrt.sqrt 1%R) = 1%R).

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
689 690 691 692 693 694 695 696
Axiom Q_mul_sqrt_4 :
  forall (x:Reals.Rdefinitions.R), (0%R <= x)%R ->
  ((2%R * x)%R = (Reals.R_sqrt.sqrt ((4%R * x)%R * x)%R)).

Axiom Q_mul_sqrt_float :
  forall (x:Reals.Rdefinitions.R),
  let r := Reals.R_sqrt.sqrt x in (0%R <= x)%R -> ((r * r)%R = x).

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
(* Why3 assumption *)
Definition L_trace_1_ (rmat:S12_RealRMat_s) : Reals.Rdefinitions.R :=
  (((F12_RealRMat_s_a00 rmat) + (F12_RealRMat_s_a11 rmat))%R +
   (F12_RealRMat_s_a22 rmat))%R.

(* Why3 assumption *)
Definition L_l_FloatQuat_of_RMat_trace_pos_1_ (rmat:S12_RealRMat_s) :
    S13_RealQuat_s :=
  let r :=
  ((1%R / 2%R)%R / (Reals.R_sqrt.sqrt (1%R + (L_trace_1_ rmat))%R))%R in
  S13_RealQuat_s1 ((1%R / 4%R)%R / r)%R
  ((((-1%R)%R * (F12_RealRMat_s_a12 rmat))%R + (F12_RealRMat_s_a21 rmat))%R *
   r)%R
  ((((-1%R)%R * (F12_RealRMat_s_a20 rmat))%R + (F12_RealRMat_s_a02 rmat))%R *
   r)%R
  ((((-1%R)%R * (F12_RealRMat_s_a01 rmat))%R + (F12_RealRMat_s_a10 rmat))%R *
   r)%R.

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
715 716 717 718
Require Import Lra.

Local Open Scope R_scope.

POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
719 720 721 722 723 724 725 726 727
(* Why3 goal *)
Theorem wp_goal :
  forall (R:S12_RealRMat_s) (R1:S13_RealQuat_s),
  ((L_l_RMat_of_FloatQuat_2_ R1) = R) -> (0%R <= (F13_RealQuat_s_qi R1))%R ->
  (0%R < (L_trace_1_ R))%R -> P_unary_quaternion_2_ R1 ->
  EqS13_RealQuat_s R1 (L_l_FloatQuat_of_RMat_trace_pos_1_ R).
(* Why3 intros R R1 h1 h2 h3 h4. *)
Proof.
intros Rm Q H1 H2 H3 H4.
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
728 729
destruct Rm as [a0 a1 a2 a3 a4 a5 a6 a7 a8].
destruct Q as[q1 q2 q3 q4].
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
730 731 732 733 734
unfold L_l_RMat_of_FloatQuat_2_ in H1; simpl in H1.
unfold F13_RealQuat_s_qi in H2; simpl in H2.
unfold L_trace_1_ in H3; simpl in H3.
unfold P_unary_quaternion_2_ in H4; simpl in H4.
unfold L_l_FloatQuat_of_RMat_trace_pos_1_; simpl.
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
735
assert (1 + L_trace_1_ (S12_RealRMat_s1 a0 a1 a2 a3 a4 a5 a6 a7 a8) = 4 * q1 * q1).
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
736 737 738 739
{
  unfold L_trace_1_; simpl.
  rewrite <- H4.
  inversion H1.
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
740
  lra.
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
741 742
}
rewrite H.
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
743
assert (H0 : q1 <> 0).
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
744
{
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
745 746 747 748 749
  unfold L_trace_1_ in H; simpl in H.
  assert (H0 : 1 + (a0+ a4 + a8) > 0) by lra.
  intro H5.
  rewrite H, H5 in H0.
  lra.
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
750
}
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
751
assert (H5 : (1 / 2 / R_sqrt.sqrt (4 * q1 * q1))= 1 / (4 * q1)).
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
752
{
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
753 754
  unfold Rdiv; rewrite <- Q_mul_sqrt_4; auto.
  now field.
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
755
}
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
756 757
rewrite H5; unfold EqS13_RealQuat_s; simpl.
now inversion H1; repeat split; field.
POLLIEN Baptiste's avatar
POLLIEN Baptiste committed
758 759
Qed.