(* This file was originally generated by why.
   It can be modified; only the generated parts will be overwritten. *)

Require Export binary_search_spec_why.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 14, characters 6-147: *)
(*Why goal*) Lemma binary_search_impl_po_1 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  (* CADUCEUS_4 *) ((((0 <= 0 /\ (n - 1) <= (n - 1)) /\ (-1) <= (-1) /\
  (-1) <= (n - 1)) /\
  (((-1) = (-1) ->
    (forall (k:Z),
     (0 <= k /\ k < n ->
      ((acc intM_global (shift t k)) = v -> 0 <= k /\ k <= (n - 1))))))) /\
  (((-1) >= 0 -> (acc intM_global (shift t (-1))) = v))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 20, characters 12-23: *)
(*Why goal*) Lemma binary_search_impl_po_2 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  2 <> 0.
Proof.
intuition.
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 21, characters 15-26: *)
(*Why goal*) Lemma binary_search_impl_po_3 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  forall (HW_4: 2 <> 0),
  forall (result: Z),
  forall (HW_5: result = ((Zdiv (l + u) 2))),
  (* CADUCEUS_9 *) (* CADUCEUS_9 *) (l <= result /\ result <= u).
Proof.
intros.
generalize (mean_1 l u); intuition.
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 22, characters 8-12: *)
(*Why goal*) Lemma binary_search_impl_po_4 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  forall (HW_4: 2 <> 0),
  forall (result: Z),
  forall (HW_5: result = ((Zdiv (l + u) 2))),
  forall (HW_6: (* CADUCEUS_9 *) (l <= result /\ result <= u)),
  forall (result0: (pointer global)),
  forall (HW_7: result0 = (shift t result)),
  (valid alloc result0).
Proof.
intuition.
subst.
apply valid_range_valid_shift with 0 (n-1); intuition.
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 14, characters 6-147: *)
(*Why goal*) Lemma binary_search_impl_po_5 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  forall (HW_4: 2 <> 0),
  forall (result: Z),
  forall (HW_5: result = ((Zdiv (l + u) 2))),
  forall (HW_6: (* CADUCEUS_9 *) (l <= result /\ result <= u)),
  forall (result0: (pointer global)),
  forall (HW_7: result0 = (shift t result)),
  forall (HW_8: (valid alloc result0)),
  forall (result1: Z),
  forall (HW_9: result1 = (acc intM_global result0)),
  forall (HW_10: result1 < v),
  forall (l0: Z),
  forall (HW_11: l0 = (result + 1)),
  (* CADUCEUS_4 *) ((((0 <= l0 /\ u <= (n - 1)) /\ (-1) <= p /\ p <=
  (n - 1)) /\
  ((p = (-1) ->
    (forall (k:Z),
     (0 <= k /\ k < n ->
      ((acc intM_global (shift t k)) = v -> l0 <= k /\ k <= u)))))) /\
  ((p >= 0 -> (acc intM_global (shift t p)) = v))).
Proof.
intros; subst.
generalize (mean_1 l u); intuition.
assert (h: k <= (l+u)/2 \/ (l + u) / 2 + 1 <= k). omega. destruct h.
assert (shift t k # intM_global <= shift t ((l+u)/2) # intM_global).
apply H1; intuition.
absurd (shift t k # intM_global = v); omega.
assumption.
admit. (*TODO*)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 17, characters 14-17: *)
(*Why goal*) Lemma binary_search_impl_po_6 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  forall (HW_4: 2 <> 0),
  forall (result: Z),
  forall (HW_5: result = ((Zdiv (l + u) 2))),
  forall (HW_6: (* CADUCEUS_9 *) (l <= result /\ result <= u)),
  forall (result0: (pointer global)),
  forall (HW_7: result0 = (shift t result)),
  forall (HW_8: (valid alloc result0)),
  forall (result1: Z),
  forall (HW_9: result1 = (acc intM_global result0)),
  forall (HW_10: result1 < v),
  forall (l0: Z),
  forall (HW_11: l0 = (result + 1)),
  (Zwf 0 ((* CADUCEUS_5 *) (u - l0)) ((* CADUCEUS_5 *) (u - l))).
Proof.
intuition.
subst.
apply valid_range_valid_shift with 0 (n-1); intuition.
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 24, characters 13-17: *)
(*Why goal*) Lemma binary_search_impl_po_7 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  forall (HW_4: 2 <> 0),
  forall (result: Z),
  forall (HW_5: result = ((Zdiv (l + u) 2))),
  forall (HW_6: (* CADUCEUS_9 *) (l <= result /\ result <= u)),
  forall (result0: (pointer global)),
  forall (HW_7: result0 = (shift t result)),
  forall (HW_8: (valid alloc result0)),
  forall (result1: Z),
  forall (HW_9: result1 = (acc intM_global result0)),
  forall (HW_12: result1 >= v),
  forall (result2: (pointer global)),
  forall (HW_13: result2 = (shift t result)),
  (valid alloc result2).
Proof.
admit. (*TODO*)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 14, characters 6-147: *)
(*Why goal*) Lemma binary_search_impl_po_8 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  forall (HW_4: 2 <> 0),
  forall (result: Z),
  forall (HW_5: result = ((Zdiv (l + u) 2))),
  forall (HW_6: (* CADUCEUS_9 *) (l <= result /\ result <= u)),
  forall (result0: (pointer global)),
  forall (HW_7: result0 = (shift t result)),
  forall (HW_8: (valid alloc result0)),
  forall (result1: Z),
  forall (HW_9: result1 = (acc intM_global result0)),
  forall (HW_12: result1 >= v),
  forall (result2: (pointer global)),
  forall (HW_13: result2 = (shift t result)),
  forall (HW_14: (valid alloc result2)),
  forall (result3: Z),
  forall (HW_15: result3 = (acc intM_global result2)),
  forall (HW_16: result3 > v),
  forall (u0: Z),
  forall (HW_17: u0 = (result - 1)),
  (* CADUCEUS_4 *) ((((0 <= l /\ u0 <= (n - 1)) /\ (-1) <= p /\ p <=
  (n - 1)) /\
  ((p = (-1) ->
    (forall (k:Z),
     (0 <= k /\ k < n ->
      ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u0)))))) /\
  ((p >= 0 -> (acc intM_global (shift t p)) = v))).
Proof.
intuition.
admit. (*TODO*)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 17, characters 14-17: *)
(*Why goal*) Lemma binary_search_impl_po_9 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  forall (HW_4: 2 <> 0),
  forall (result: Z),
  forall (HW_5: result = ((Zdiv (l + u) 2))),
  forall (HW_6: (* CADUCEUS_9 *) (l <= result /\ result <= u)),
  forall (result0: (pointer global)),
  forall (HW_7: result0 = (shift t result)),
  forall (HW_8: (valid alloc result0)),
  forall (result1: Z),
  forall (HW_9: result1 = (acc intM_global result0)),
  forall (HW_12: result1 >= v),
  forall (result2: (pointer global)),
  forall (HW_13: result2 = (shift t result)),
  forall (HW_14: (valid alloc result2)),
  forall (result3: Z),
  forall (HW_15: result3 = (acc intM_global result2)),
  forall (HW_16: result3 > v),
  forall (u0: Z),
  forall (HW_17: u0 = (result - 1)),
  (Zwf 0 ((* CADUCEUS_5 *) (u0 - l)) ((* CADUCEUS_5 *) (u - l))).
Proof.
intuition.
admit. (*TODO*)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 8, characters 4-102: *)
(*Why goal*) Lemma binary_search_impl_po_10 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_3: l <= u),
  forall (HW_4: 2 <> 0),
  forall (result: Z),
  forall (HW_5: result = ((Zdiv (l + u) 2))),
  forall (HW_6: (* CADUCEUS_9 *) (l <= result /\ result <= u)),
  forall (result0: (pointer global)),
  forall (HW_7: result0 = (shift t result)),
  forall (HW_8: (valid alloc result0)),
  forall (result1: Z),
  forall (HW_9: result1 = (acc intM_global result0)),
  forall (HW_12: result1 >= v),
  forall (result2: (pointer global)),
  forall (HW_13: result2 = (shift t result)),
  forall (HW_14: (valid alloc result2)),
  forall (result3: Z),
  forall (HW_15: result3 = (acc intM_global result2)),
  forall (HW_18: result3 <= v),
  forall (p0: Z),
  forall (HW_19: p0 = result),
  (* CADUCEUS_3 *) (p0 >= 0 /\ (acc intM_global (shift t p0)) = v \/ p0 =
  (-1) /\
  (forall (k:Z), (0 <= k /\ k < n -> (acc intM_global (shift t k)) <> v))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "/home/cmarche/recherche/why/examples-c/tutorial/binary_search.c", line 8, characters 4-102: *)
(*Why goal*) Lemma binary_search_impl_po_11 : 
  forall (t: (pointer global)),
  forall (n: Z),
  forall (v: Z),
  forall (alloc: alloc_table),
  forall (intM_global: (memory Z global)),
  forall (HW_1: (* CADUCEUS_2 *) ((n >= 0 /\
                (valid_range alloc t 0 (n - 1))) /\
                (forall (k1:Z),
                 (forall (k2:Z),
                  ((0 <= k1 /\ k1 <= k2) /\ k2 <= (n - 1) ->
                   (acc intM_global (shift t k1)) <=
                   (acc intM_global (shift t k2))))))),
  forall (l: Z),
  forall (p: Z),
  forall (u: Z),
  forall (HW_2: (* CADUCEUS_4 *) ((((0 <= l /\ u <= (n - 1)) /\ (-1) <= p /\
                p <= (n - 1)) /\
                ((p = (-1) ->
                  (forall (k:Z),
                   (0 <= k /\ k < n ->
                    ((acc intM_global (shift t k)) = v -> l <= k /\ k <= u)))))) /\
                ((p >= 0 -> (acc intM_global (shift t p)) = v)))),
  forall (HW_20: l > u),
  (* CADUCEUS_3 *) (p >= 0 /\ (acc intM_global (shift t p)) = v \/ p =
  (-1) /\
  (forall (k:Z), (0 <= k /\ k < n -> (acc intM_global (shift t k)) <> v))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

