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

Require Export average_spec_why.

(* Why obligation from file "why/average.why", characters 488-489 *)
Lemma average_impl_po_1 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre7: (valid_range alloc t 0 n) /\ n > 0),
  forall (sum: Z),
  forall (Post6: sum = 0),
  forall (i1: Z),
  forall (Post1: i1 = 0),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (sum1: Z),
  forall (Pre5: Variant1 = (n - i2)),
  forall (Pre4: (0 <= i2 /\ i2 <= n) /\ (i2 * (min alloc intP t i2)) <= sum1),
  forall (Test2: i2 < n),
  (forall (result:pointer),
   (result = (shift t i2) ->
    (forall (result0:Z),
     (result0 = (acc intP result) -> (sum1 + result0) =
      (sum1 + (acc intP (shift t i2))))) /\
    (valid alloc result))).
Proof.
intuition.
subst; auto.
Save.

(* Why obligation from file "why/average.why", characters 464-595 *)
Lemma average_impl_po_2 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre7: (valid_range alloc t 0 n) /\ n > 0),
  forall (sum: Z),
  forall (Post6: sum = 0),
  forall (i1: Z),
  forall (Post1: i1 = 0),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (sum1: Z),
  forall (Pre5: Variant1 = (n - i2)),
  forall (Pre4: (0 <= i2 /\ i2 <= n) /\ (i2 * (min alloc intP t i2)) <= sum1),
  forall (Test2: i2 < n),
  forall (sum2: Z),
  forall (Post3: sum2 = (sum1 + (acc intP (shift t i2)))),
  forall (i3: Z),
  forall (Post4: i3 = (i2 + 1)),
  ((0 <= i3 /\ i3 <= n) /\ (i3 * (min alloc intP t i3)) <= sum2) /\
  (Zwf 0 (n - i3) (n - i2)).
Proof.
intuition; subst; auto.
Qed.

(* Why obligation from file "why/average.why", characters 266-605 *)
Lemma average_impl_po_3 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre7: (valid_range alloc t 0 n) /\ n > 0),
  forall (sum: Z),
  forall (Post6: sum = 0),
  forall (i1: Z),
  forall (Post1: i1 = 0),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (sum1: Z),
  forall (Pre5: Variant1 = (n - i2)),
  forall (Pre4: (0 <= i2 /\ i2 <= n) /\ (i2 * (min alloc intP t i2)) <= sum1),
  forall (Test1: i2 >= n),
  (forall (result:Z),
   (result = ((Zdiv sum1 n)) -> (min alloc intP t n) <= result)) /\
  ~(n = 0).
Proof.
intuition.
subst.




assert (i2 = n). omega. subst.
replace (min intP t n) with ((0 + min intP t n * n) / n).
apply Zge_le.
apply Z_div_ge; auto.
rewrite Zmult_comm.
omega.
rewrite Z_div_plus; auto.
Save.

(* Why obligation from file "why/average.why", characters 323-419 *)
Lemma average_impl_po_4 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre7: (valid_range alloc t 0 n) /\ n > 0),
  forall (sum: Z),
  forall (Post6: sum = 0),
  forall (i1: Z),
  forall (Post1: i1 = 0),
  (0 <= i1 /\ i1 <= n) /\ (i1 * (min alloc intP t i1)) <= sum.
Proof.
intuition.
subst; omega.
Qed.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "why/average.why", characters 902-916 *)
Lemma min_impl_po_1 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (Pre9: n > 0 /\ (valid_range alloc t 0 n)),
  (valid alloc t).
Proof.
intuition.
subst; auto.
Save.

(* Why obligation from file "why/average.why", characters 1177-1264 *)
Lemma min_impl_po_2 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre9: n > 0 /\ (valid_range alloc t 0 n)),
  forall (Pre8: (valid alloc t)),
  forall (tmp: Z),
  forall (Post8: tmp = (acc intP t)),
  forall (i1: Z),
  forall (Post1: i1 = 1),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (tmp1: Z),
  forall (Pre7: Variant1 = (n - i2)),
  forall (Pre6: (1 <= i2 /\ i2 <= n) /\ (is_min alloc intP t i2 tmp1)),
  forall (Test4: i2 < n),
  (valid alloc (shift t i2)).
Proof.
unfold is_min; intuition; subst; auto with *.
assert (i1=0). omega.
subst; intuition.
exists 0; intuition.
assert (i3<i1 \/ i3=i1). omega. intuition.
generalize (H3 i3); intuition.
subst; omega.
exists i1; intuition.
assert (i3<i1 \/ i3=i1). omega. intuition.
subst; omega.
elim H6; intros i2 Hi2; exists i2; intuition.
assert (i1=n). omega. subst; trivial.
Save.

Proof.
intuition.
(* FILL PROOF HERE *)
assert (i2=0 \/ i2>0). omega. intuition.
subst; ring (0+1).
assert (min intP t 1 = shift t 0 # intP).
generalize (min_is_min alloc intP t 1).
assert (1>0). omega. unfold is_min in *|-*. intuition.
elim H7; intros i Hi. assert (i=0). omega.
subst; intuition.
omega.
replace ((i2 + 1) * min intP t (i2 + 1)) with ((i2 * min intP t (i2+1)) + min intP t (i2+1)).
2:ring.
assert (min intP t (i2 + 1) <= min intP t i2).
generalize (min_is_min alloc intP t i2).
assert (i2+1>0). omega.
generalize (min_is_min alloc intP t (i2+1)).
unfold is_min; intuition.
elim H9; intros i Hi.
intuition.
rewrite H11.
intuition.
assert (i2 * min intP t (i2 + 1) <= i2 * min intP t i2).
apply Zmult_le_compat_l; auto with *.
assert (min intP t (i2 + 1) <= shift t i2 # intP).
assert (i2+1>0). omega.
generalize (min_is_min alloc intP t (i2+1)).
unfold is_min; intuition.
omega.
Save.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "why/average.why", characters 1287-1315 *)
Lemma min_impl_po_3 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre9: n > 0 /\ (valid_range alloc t 0 n)),
  forall (Pre8: (valid alloc t)),
  forall (tmp: Z),
  forall (Post8: tmp = (acc intP t)),
  forall (i1: Z),
  forall (Post1: i1 = 1),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (tmp1: Z),
  forall (Pre7: Variant1 = (n - i2)),
  forall (Pre6: (1 <= i2 /\ i2 <= n) /\ (is_min alloc intP t i2 tmp1)),
  forall (Test4: i2 < n),
  forall (Pre5: (valid alloc (shift t i2))),
  forall (Test3: (acc intP (shift t i2)) < tmp1),
  forall (aux_2: pointer),
  forall (Post18: aux_2 = (shift t i2)),
  (valid alloc aux_2).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "why/average.why", characters 1287-1315 *)
Lemma min_impl_po_4 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre9: n > 0 /\ (valid_range alloc t 0 n)),
  forall (Pre8: (valid alloc t)),
  forall (tmp: Z),
  forall (Post8: tmp = (acc intP t)),
  forall (i1: Z),
  forall (Post1: i1 = 1),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (tmp1: Z),
  forall (Pre7: Variant1 = (n - i2)),
  forall (Pre6: (1 <= i2 /\ i2 <= n) /\ (is_min alloc intP t i2 tmp1)),
  forall (Test4: i2 < n),
  forall (Pre5: (valid alloc (shift t i2))),
  forall (Test3: (acc intP (shift t i2)) < tmp1),
  forall (aux_2: pointer),
  forall (Post18: aux_2 = (shift t i2)),
  forall (Pre2: (valid alloc aux_2)),
  forall (result2: Z),
  forall (Post20: result2 = (acc intP aux_2)),
  result2 = (acc intP (shift t i2)).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "why/average.why", characters 1280-1315 *)
Lemma min_impl_po_5 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre9: n > 0 /\ (valid_range alloc t 0 n)),
  forall (Pre8: (valid alloc t)),
  forall (tmp: Z),
  forall (Post8: tmp = (acc intP t)),
  forall (i1: Z),
  forall (Post1: i1 = 1),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (tmp1: Z),
  forall (Pre7: Variant1 = (n - i2)),
  forall (Pre6: (1 <= i2 /\ i2 <= n) /\ (is_min alloc intP t i2 tmp1)),
  forall (Test4: i2 < n),
  forall (Pre5: (valid alloc (shift t i2))),
  forall (Test3: (acc intP (shift t i2)) < tmp1),
  forall (tmp2: Z),
  forall (Post4: tmp2 = (acc intP (shift t i2))),
  (forall (i:Z),
   (i = (i2 + 1) -> ((1 <= i /\ i <= n) /\ (is_min alloc intP t i tmp2)) /\
    (Zwf 0 (n - i) (n - i2)))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "why/average.why", characters 1331-1331 *)
Lemma min_impl_po_6 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre9: n > 0 /\ (valid_range alloc t 0 n)),
  forall (Pre8: (valid alloc t)),
  forall (tmp: Z),
  forall (Post8: tmp = (acc intP t)),
  forall (i1: Z),
  forall (Post1: i1 = 1),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (tmp1: Z),
  forall (Pre7: Variant1 = (n - i2)),
  forall (Pre6: (1 <= i2 /\ i2 <= n) /\ (is_min alloc intP t i2 tmp1)),
  forall (Test4: i2 < n),
  forall (Pre5: (valid alloc (shift t i2))),
  forall (Test2: (acc intP (shift t i2)) >= tmp1),
  forall (result2: unit),
  forall (Post3: result2 = tt),
  (forall (i:Z),
   (i = (i2 + 1) -> ((1 <= i /\ i <= n) /\ (is_min alloc intP t i tmp1)) /\
    (Zwf 0 (n - i) (n - i2)))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "why/average.why", characters 993-1376 *)
Lemma min_impl_po_7 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre9: n > 0 /\ (valid_range alloc t 0 n)),
  forall (Pre8: (valid alloc t)),
  forall (tmp: Z),
  forall (Post8: tmp = (acc intP t)),
  forall (i1: Z),
  forall (Post1: i1 = 1),
  forall (Variant1: Z),
  forall (i2: Z),
  forall (tmp1: Z),
  forall (Pre7: Variant1 = (n - i2)),
  forall (Pre6: (1 <= i2 /\ i2 <= n) /\ (is_min alloc intP t i2 tmp1)),
  forall (Test1: i2 >= n),
  (forall (result:Z), (result = tmp1 -> (is_min alloc intP t n result))).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

(* Why obligation from file "why/average.why", characters 1050-1129 *)
Lemma min_impl_po_8 : 
  forall (t: pointer),
  forall (n: Z),
  forall (alloc: alloc_table),
  forall (intP: ((memory) Z)),
  forall (Pre9: n > 0 /\ (valid_range alloc t 0 n)),
  forall (Pre8: (valid alloc t)),
  forall (tmp: Z),
  forall (Post8: tmp = (acc intP t)),
  forall (i1: Z),
  forall (Post1: i1 = 1),
  (1 <= i1 /\ i1 <= n) /\ (is_min alloc intP t i1 tmp).
Proof.
intuition.
(* FILL PROOF HERE *)
Save.

