From Stdlib Require Import Strings.String.
From Stdlib Require Import String Ascii.
From Stdlib Require Arith.
From stdpp Require Import base.
From stdpp Require Import fin_maps.
From stdpp Require Import gmap.
From stdpp Require Import base gmultiset.
From Stdlib Require Classical.
From Stdlib Require Import ZArith.
From stdpp.bitvector Require Import definitions tactics.
From Stdlib Require Import Sorting.Sorted.
From Stdlib Require Import Reals.Rbasic_fun.
From Stdlib Require Import Reals.Abstract.ConstructiveAbs.
From Stdlib Require Import Reals.Rdefinitions.
From stdpp Require Import list_relations.
From stdpp Require Import list_numbers.
From stdpp Require Import functions.
From Stdlib Require Import ClassicalEpsilon.
From stdpp Require Import base decidable.
From Stdlib Require Import ZArith.Zeuclid.
From Stdlib Require Import ZArith.Znumtheory.
From stdpp Require Import propset.
From Stdlib Require Import Reals.
Require Import Why3.Base.
Require Import Why3.why3.Ref.Ref.
Require Import Why3.int.Sum.
Open Scope Z_scope.
Axiom big : Type.
Axiom big_inhabited : Inhabited big.
Global Existing Instance big_inhabited.
Axiom big_countable : Countable big.
Global Existing Instance big_countable.
Axiom q : big -> bv 32%N.
Axiom r : big -> bv 32%N.
Axiom v : big -> Z.
Axiom big'invariant : forall  (self : big), - (2147483647%Z + 1%Z) ≤ bv_signed (q self) ∧ bv_signed (q self) ≤ 2147483647%Z + 1%Z - 1%Z ∧ 0%Z ≤ bv_signed (r self) ∧ bv_signed (r self) ≤ 2147483647%Z + 1%Z - 1%Z ∧ v self = bv_signed (q self) * (2147483647%Z + 1%Z) + bv_signed (r self).
Definition big'eq (a : big) (b : big) := q a = q b ∧ r a = r b ∧ v a = v b.
Axiom big'inj : forall  (a : big) (b : big) (fact0 : big'eq a b), a = b.
Axiom big_zero : unit -> big.
Axiom big_zero'def : forall  (x : unit), q (big_zero x) = (0%bv : bv 32%N) ∧ r (big_zero x) = (0%bv : bv 32%N) ∧ v (big_zero x) = 0%Z.
Axiom fc : array32 (bv 32%N) -> Z -> Z.
Axiom fc'def : forall  (a : array32 (bv 32%N)) (i : Z), fc a i = bv_signed (array32_elts a i).
Definition sum (a : array32 (bv 32%N)) (l : Z) (u : Z) : Z := int.Sum.sum (fc a) l u.
Definition diff (a : array32 (bv 32%N)) (i : Z) : Z := Z.abs (sum a 0%Z i - sum a i (bv_signed (array32_length a))).
Theorem fulcrum'vc (a : array32 (bv 32%N)) (fact0 : bv_signed (array32_length a) < bv_signed (2147483647%bv : bv 32%N)) : let n : bv 32%N := array32_length a in let right1 : big := big_zero () in int'32_in_bounds (bv_signed n - 1%Z) ∧ (∀(o1 : bv 32%N), bv_signed o1 = bv_signed n - 1%Z -> (0%Z ≤ bv_signed o1 + 1%Z -> (55%Z < 89%Z ∧ v right1 = sum a 0%Z 0%Z) ∧ (∀(right2 : big), (∀(i : bv 32%N), let i1 : Z := bv_signed i in (0%Z ≤ i1 ∧ i1 ≤ bv_signed o1) ∧ 55%Z < 89%Z ∧ v right2 = sum a 0%Z i1 -> (0%Z ≤ bv_signed i ∧ bv_signed i < bv_signed (array32_length a)) ∧ (let o2 : bv 32%N := array32_elts a (bv_signed i) in (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ v right2 + bv_signed o2 ∧ v right2 + bv_signed o2 ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(right3 : big), v right3 = v right2 + bv_signed o2 -> 55%Z < 89%Z ∧ v right3 = sum a 0%Z (i1 + 1%Z)))) ∧ (55%Z < 89%Z ∧ v right2 = sum a 0%Z (bv_signed o1 + 1%Z) -> (let left1 : big := big_zero () in (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ Z.abs (v left1 - v right2) ∧ Z.abs (v left1 - v right2) ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(bestd : big), v bestd = Z.abs (v left1 - v right2) -> int'32_in_bounds (bv_signed n - 1%Z) ∧ (∀(o2 : bv 32%N), bv_signed o2 = bv_signed n - 1%Z -> (0%Z ≤ bv_signed o2 + 1%Z -> (55%Z < 89%Z ∧ v left1 = sum a 0%Z 0%Z ∧ v right2 = sum a 0%Z (bv_signed n) ∧ 0%Z ≤ 0%Z ∧ v bestd = diff a 0%Z ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ 0%Z -> v bestd ≤ diff a j)) ∧ (∀(bestd1 : big) (besti : bv 32%N) (left2 : big) (right3 : big), (∀(i : bv 32%N), let i1 : Z := bv_signed i in (0%Z ≤ i1 ∧ i1 ≤ bv_signed o2) ∧ 55%Z < 89%Z ∧ v left2 = sum a 0%Z i1 ∧ v right3 = sum a i1 (bv_signed n) ∧ (0%Z ≤ bv_signed besti ∧ bv_signed besti ≤ i1) ∧ v bestd1 = diff a (bv_signed besti) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ i1 -> v bestd1 ≤ diff a j) -> (0%Z ≤ bv_signed i ∧ bv_signed i < bv_signed (array32_length a)) ∧ (let o3 : bv 32%N := array32_elts a (bv_signed i) in (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ v left2 + bv_signed o3 ∧ v left2 + bv_signed o3 ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(left3 : big), v left3 = v left2 + bv_signed o3 -> (0%Z ≤ bv_signed i ∧ bv_signed i < bv_signed (array32_length a)) ∧ (let o4 : bv 32%N := array32_elts a (bv_signed i) in (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ v right3 - bv_signed o4 ∧ v right3 - bv_signed o4 ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(right4 : big), v right4 = v right3 - bv_signed o4 -> (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ Z.abs (v left3 - v right4) ∧ Z.abs (v left3 - v right4) ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(d : big), v d = Z.abs (v left3 - v right4) -> (0%Z ≤ v d ∧ 0%Z ≤ v bestd1) ∧ (if decide (v d < v bestd1) then ∀(bestd2 : big), int'32_in_bounds (bv_signed i + 1%Z) ∧ (∀(o5 : bv 32%N), bv_signed o5 = bv_signed i + 1%Z -> ((- (2147483647%Z + 1%Z) ≤ bv_signed (q d) ∧ bv_signed (q d) ≤ 2147483647%Z + 1%Z - 1%Z) ∧ (0%Z ≤ bv_signed (r d) ∧ bv_signed (r d) ≤ 2147483647%Z + 1%Z - 1%Z) ∧ v d = bv_signed (q d) * (2147483647%Z + 1%Z) + bv_signed (r d)) ∧ (v d = v bestd2 ∧ r d = r bestd2 ∧ q d = q bestd2 -> 55%Z < 89%Z ∧ v left3 = sum a 0%Z (i1 + 1%Z) ∧ v right4 = sum a (i1 + 1%Z) (bv_signed n) ∧ (0%Z ≤ bv_signed o5 ∧ bv_signed o5 ≤ i1 + 1%Z) ∧ v bestd2 = diff a (bv_signed o5) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ i1 + 1%Z -> v bestd2 ≤ diff a j))) else 55%Z < 89%Z ∧ v left3 = sum a 0%Z (i1 + 1%Z) ∧ v right4 = sum a (i1 + 1%Z) (bv_signed n) ∧ (0%Z ≤ bv_signed besti ∧ bv_signed besti ≤ i1 + 1%Z) ∧ v bestd1 = diff a (bv_signed besti) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ i1 + 1%Z -> v bestd1 ≤ diff a j)))))))) ∧ (55%Z < 89%Z ∧ v left2 = sum a 0%Z (bv_signed o2 + 1%Z) ∧ v right3 = sum a (bv_signed o2 + 1%Z) (bv_signed n) ∧ (0%Z ≤ bv_signed besti ∧ bv_signed besti ≤ bv_signed o2 + 1%Z) ∧ v bestd1 = diff a (bv_signed besti) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ bv_signed o2 + 1%Z -> v bestd1 ≤ diff a j) -> (0%Z ≤ bv_signed besti ∧ bv_signed besti ≤ bv_signed (array32_length a)) ∧ (∀(i : Z), 0%Z ≤ i ∧ i ≤ bv_signed (array32_length a) -> diff a (bv_signed besti) ≤ diff a i)))) ∧ (bv_signed o2 + 1%Z < 0%Z -> (0%Z ≤ 0%Z ∧ 0%Z ≤ bv_signed (array32_length a)) ∧ (∀(i : Z), 0%Z ≤ i ∧ i ≤ bv_signed (array32_length a) -> diff a 0%Z ≤ diff a i)))))))) ∧ (bv_signed o1 + 1%Z < 0%Z -> (let left1 : big := big_zero () in (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ Z.abs (v left1 - v right1) ∧ Z.abs (v left1 - v right1) ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(bestd : big), v bestd = Z.abs (v left1 - v right1) -> int'32_in_bounds (bv_signed n - 1%Z) ∧ (∀(o2 : bv 32%N), bv_signed o2 = bv_signed n - 1%Z -> (0%Z ≤ bv_signed o2 + 1%Z -> (55%Z < 89%Z ∧ v left1 = sum a 0%Z 0%Z ∧ v right1 = sum a 0%Z (bv_signed n) ∧ 0%Z ≤ 0%Z ∧ v bestd = diff a 0%Z ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ 0%Z -> v bestd ≤ diff a j)) ∧ (∀(bestd1 : big) (besti : bv 32%N) (left2 : big) (right2 : big), (∀(i : bv 32%N), let i1 : Z := bv_signed i in (0%Z ≤ i1 ∧ i1 ≤ bv_signed o2) ∧ 55%Z < 89%Z ∧ v left2 = sum a 0%Z i1 ∧ v right2 = sum a i1 (bv_signed n) ∧ (0%Z ≤ bv_signed besti ∧ bv_signed besti ≤ i1) ∧ v bestd1 = diff a (bv_signed besti) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ i1 -> v bestd1 ≤ diff a j) -> (0%Z ≤ bv_signed i ∧ bv_signed i < bv_signed (array32_length a)) ∧ (let o3 : bv 32%N := array32_elts a (bv_signed i) in (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ v left2 + bv_signed o3 ∧ v left2 + bv_signed o3 ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(left3 : big), v left3 = v left2 + bv_signed o3 -> (0%Z ≤ bv_signed i ∧ bv_signed i < bv_signed (array32_length a)) ∧ (let o4 : bv 32%N := array32_elts a (bv_signed i) in (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ v right2 - bv_signed o4 ∧ v right2 - bv_signed o4 ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(right3 : big), v right3 = v right2 - bv_signed o4 -> (- (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) ≤ Z.abs (v left3 - v right3) ∧ Z.abs (v left3 - v right3) ≤ (2147483647%Z + 1%Z) * (2147483647%Z + 1%Z) - 1%Z) ∧ (∀(d : big), v d = Z.abs (v left3 - v right3) -> (0%Z ≤ v d ∧ 0%Z ≤ v bestd1) ∧ (if decide (v d < v bestd1) then ∀(bestd2 : big), int'32_in_bounds (bv_signed i + 1%Z) ∧ (∀(o5 : bv 32%N), bv_signed o5 = bv_signed i + 1%Z -> ((- (2147483647%Z + 1%Z) ≤ bv_signed (q d) ∧ bv_signed (q d) ≤ 2147483647%Z + 1%Z - 1%Z) ∧ (0%Z ≤ bv_signed (r d) ∧ bv_signed (r d) ≤ 2147483647%Z + 1%Z - 1%Z) ∧ v d = bv_signed (q d) * (2147483647%Z + 1%Z) + bv_signed (r d)) ∧ (v d = v bestd2 ∧ r d = r bestd2 ∧ q d = q bestd2 -> 55%Z < 89%Z ∧ v left3 = sum a 0%Z (i1 + 1%Z) ∧ v right3 = sum a (i1 + 1%Z) (bv_signed n) ∧ (0%Z ≤ bv_signed o5 ∧ bv_signed o5 ≤ i1 + 1%Z) ∧ v bestd2 = diff a (bv_signed o5) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ i1 + 1%Z -> v bestd2 ≤ diff a j))) else 55%Z < 89%Z ∧ v left3 = sum a 0%Z (i1 + 1%Z) ∧ v right3 = sum a (i1 + 1%Z) (bv_signed n) ∧ (0%Z ≤ bv_signed besti ∧ bv_signed besti ≤ i1 + 1%Z) ∧ v bestd1 = diff a (bv_signed besti) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ i1 + 1%Z -> v bestd1 ≤ diff a j)))))))) ∧ (55%Z < 89%Z ∧ v left2 = sum a 0%Z (bv_signed o2 + 1%Z) ∧ v right2 = sum a (bv_signed o2 + 1%Z) (bv_signed n) ∧ (0%Z ≤ bv_signed besti ∧ bv_signed besti ≤ bv_signed o2 + 1%Z) ∧ v bestd1 = diff a (bv_signed besti) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ bv_signed o2 + 1%Z -> v bestd1 ≤ diff a j) -> (0%Z ≤ bv_signed besti ∧ bv_signed besti ≤ bv_signed (array32_length a)) ∧ (∀(i : Z), 0%Z ≤ i ∧ i ≤ bv_signed (array32_length a) -> diff a (bv_signed besti) ≤ diff a i)))) ∧ (bv_signed o2 + 1%Z < 0%Z -> (0%Z ≤ 0%Z ∧ 0%Z ≤ bv_signed (array32_length a)) ∧ (∀(i : Z), 0%Z ≤ i ∧ i ≤ bv_signed (array32_length a) -> diff a 0%Z ≤ diff a i))))))).
Admitted.
