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.
Require Import maximum_subarray_vcg.maximum_subarray.Spec.
Open Scope Z_scope.
Theorem maximum_subarray_rec'vc (l : Z) (h : Z) (a : list Z) (fact0 : 0%Z ≤ l) (fact1 : l ≤ h) (fact2 : h ≤ Z.of_nat (length a)) : if decide (h = l) then ((l ≤ l ∧ l ≤ h ∧ h ≤ h) ∧ 0%Z = list_sum (drop (Z.to_nat l) (take (Z.to_nat h - Z.to_nat l) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ 0%Z) else ¬ 2%Z = 0%Z ∧ (let mid : Z := l + Z.rem (h - l) 2%Z in let o1 : Z := mid - 1%Z in (l - 1%Z ≤ o1 -> (((l ≤ mid ∧ mid ≤ mid) ∧ 0%Z = list_sum (drop (Z.to_nat mid) (take (Z.to_nat mid - Z.to_nat mid) a))) ∧ (∀(l' : Z), o1 < l' ∧ l' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat mid - Z.to_nat l') a)) ≤ 0%Z) ∧ 0%Z = list_sum (drop (Z.to_nat (o1 + 1%Z)) (take (Z.to_nat mid - Z.to_nat (o1 + 1%Z)) a))) ∧ (∀(s : Z) (ms : Z) (lo : Z), (∀(i : Z), (i ≤ o1 ∧ l ≤ i) ∧ ((l ≤ lo ∧ lo ≤ mid) ∧ ms = list_sum (drop (Z.to_nat lo) (take (Z.to_nat mid - Z.to_nat lo) a))) ∧ (∀(l' : Z), i < l' ∧ l' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat mid - Z.to_nat l') a)) ≤ ms) ∧ s = list_sum (drop (Z.to_nat (i + 1%Z)) (take (Z.to_nat mid - Z.to_nat (i + 1%Z)) a)) -> (0%Z ≤ i ∧ i < Z.of_nat (length a)) ∧ (if decide (ms < s + nth (Z.to_nat i) a inhabitant) then ((l ≤ i ∧ i ≤ mid) ∧ s + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat i) (take (Z.to_nat mid - Z.to_nat i) a))) ∧ (∀(l' : Z), i - 1%Z < l' ∧ l' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat mid - Z.to_nat l') a)) ≤ s + nth (Z.to_nat i) a inhabitant) ∧ s + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat (i - 1%Z + 1%Z)) (take (Z.to_nat mid - Z.to_nat (i - 1%Z + 1%Z)) a)) else ((l ≤ lo ∧ lo ≤ mid) ∧ ms = list_sum (drop (Z.to_nat lo) (take (Z.to_nat mid - Z.to_nat lo) a))) ∧ (∀(l' : Z), i - 1%Z < l' ∧ l' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat mid - Z.to_nat l') a)) ≤ ms) ∧ s + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat (i - 1%Z + 1%Z)) (take (Z.to_nat mid - Z.to_nat (i - 1%Z + 1%Z)) a)))) ∧ (((l ≤ lo ∧ lo ≤ mid) ∧ ms = list_sum (drop (Z.to_nat lo) (take (Z.to_nat mid - Z.to_nat lo) a))) ∧ (∀(l' : Z), l - 1%Z < l' ∧ l' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat mid - Z.to_nat l') a)) ≤ ms) ∧ s = list_sum (drop (Z.to_nat (l - 1%Z + 1%Z)) (take (Z.to_nat mid - Z.to_nat (l - 1%Z + 1%Z)) a)) -> (let o2 : Z := h - 1%Z in (mid ≤ o2 + 1%Z -> (((l ≤ lo ∧ lo ≤ mid ∧ mid ≤ mid ∧ mid ≤ h) ∧ ms = list_sum (drop (Z.to_nat lo) (take (Z.to_nat mid - Z.to_nat lo) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms) ∧ ms = list_sum (drop (Z.to_nat lo) (take (Z.to_nat mid - Z.to_nat lo) a))) ∧ (∀(s1 : Z) (ms1 : Z) (hi : Z), (∀(i : Z), (mid ≤ i ∧ i ≤ o2) ∧ ((l ≤ lo ∧ lo ≤ mid ∧ mid ≤ hi ∧ hi ≤ h) ∧ ms1 = list_sum (drop (Z.to_nat lo) (take (Z.to_nat hi - Z.to_nat lo) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ i -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms1) ∧ s1 = list_sum (drop (Z.to_nat lo) (take (Z.to_nat i - Z.to_nat lo) a)) -> (0%Z ≤ i ∧ i < Z.of_nat (length a)) ∧ (if decide (ms1 < s1 + nth (Z.to_nat i) a inhabitant) then ((l ≤ lo ∧ lo ≤ mid ∧ mid ≤ i + 1%Z ∧ i + 1%Z ≤ h) ∧ s1 + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat lo) (take (Z.to_nat (i + 1%Z) - Z.to_nat lo) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ i + 1%Z -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ s1 + nth (Z.to_nat i) a inhabitant) ∧ s1 + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat lo) (take (Z.to_nat (i + 1%Z) - Z.to_nat lo) a)) else ((l ≤ lo ∧ lo ≤ mid ∧ mid ≤ hi ∧ hi ≤ h) ∧ ms1 = list_sum (drop (Z.to_nat lo) (take (Z.to_nat hi - Z.to_nat lo) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ i + 1%Z -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms1) ∧ s1 + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat lo) (take (Z.to_nat (i + 1%Z) - Z.to_nat lo) a)))) ∧ (((l ≤ lo ∧ lo ≤ mid ∧ mid ≤ hi ∧ hi ≤ h) ∧ ms1 = list_sum (drop (Z.to_nat lo) (take (Z.to_nat hi - Z.to_nat lo) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ o2 + 1%Z -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms1) ∧ s1 = list_sum (drop (Z.to_nat lo) (take (Z.to_nat (o2 + 1%Z) - Z.to_nat lo) a)) -> ((0%Z ≤ h - l ∧ mid - l < h - l) ∧ 0%Z ≤ l ∧ l ≤ mid ∧ mid ≤ Z.of_nat (length a)) ∧ (∀(hi' : Z) (lo' : Z), (l ≤ lo' ∧ lo' ≤ hi' ∧ hi' ≤ mid) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))) -> (if decide (ms1 < list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))) then let o3 : Z := mid + 1%Z in ((0%Z ≤ h - l ∧ h - o3 < h - l) ∧ 0%Z ≤ o3 ∧ o3 ≤ h ∧ h ≤ Z.of_nat (length a)) ∧ (∀(hi'1 : Z) (lo'1 : Z), (o3 ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), o3 ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) -> (if decide (list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a)) < list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) then (l ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) else (l ≤ lo' ∧ lo' ≤ hi' ∧ hi' ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))))) else let o3 : Z := mid + 1%Z in ((0%Z ≤ h - l ∧ h - o3 < h - l) ∧ 0%Z ≤ o3 ∧ o3 ≤ h ∧ h ≤ Z.of_nat (length a)) ∧ (∀(hi'1 : Z) (lo'1 : Z), (o3 ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), o3 ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) -> (if decide (ms1 < list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) then (l ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) else ((l ≤ lo ∧ lo ≤ hi ∧ hi ≤ h) ∧ ms1 = list_sum (drop (Z.to_nat lo) (take (Z.to_nat hi - Z.to_nat lo) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms1)))))))) ∧ (o2 + 1%Z < mid -> ((0%Z ≤ h - l ∧ mid - l < h - l) ∧ 0%Z ≤ l ∧ l ≤ mid ∧ mid ≤ Z.of_nat (length a)) ∧ (∀(hi' : Z) (lo' : Z), (l ≤ lo' ∧ lo' ≤ hi' ∧ hi' ≤ mid) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))) -> (if decide (ms < list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))) then let o3 : Z := mid + 1%Z in ((0%Z ≤ h - l ∧ h - o3 < h - l) ∧ 0%Z ≤ o3 ∧ o3 ≤ h ∧ h ≤ Z.of_nat (length a)) ∧ (∀(hi'1 : Z) (lo'1 : Z), (o3 ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), o3 ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) -> (if decide (list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a)) < list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) then (l ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) else (l ≤ lo' ∧ lo' ≤ hi' ∧ hi' ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))))) else let o3 : Z := mid + 1%Z in ((0%Z ≤ h - l ∧ h - o3 < h - l) ∧ 0%Z ≤ o3 ∧ o3 ≤ h ∧ h ≤ Z.of_nat (length a)) ∧ (∀(hi'1 : Z) (lo'1 : Z), (o3 ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), o3 ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) -> (if decide (ms < list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) then (l ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) else ((l ≤ lo ∧ lo ≤ mid ∧ mid ≤ h) ∧ ms = list_sum (drop (Z.to_nat lo) (take (Z.to_nat mid - Z.to_nat lo) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms)))))))))) ∧ (o1 < l - 1%Z -> (let o2 : Z := h - 1%Z in (mid ≤ o2 + 1%Z -> (((l ≤ mid ∧ mid ≤ mid ∧ mid ≤ mid ∧ mid ≤ h) ∧ 0%Z = list_sum (drop (Z.to_nat mid) (take (Z.to_nat mid - Z.to_nat mid) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ 0%Z) ∧ 0%Z = list_sum (drop (Z.to_nat mid) (take (Z.to_nat mid - Z.to_nat mid) a))) ∧ (∀(s : Z) (ms : Z) (hi : Z), (∀(i : Z), (mid ≤ i ∧ i ≤ o2) ∧ ((l ≤ mid ∧ mid ≤ mid ∧ mid ≤ hi ∧ hi ≤ h) ∧ ms = list_sum (drop (Z.to_nat mid) (take (Z.to_nat hi - Z.to_nat mid) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ i -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms) ∧ s = list_sum (drop (Z.to_nat mid) (take (Z.to_nat i - Z.to_nat mid) a)) -> (0%Z ≤ i ∧ i < Z.of_nat (length a)) ∧ (if decide (ms < s + nth (Z.to_nat i) a inhabitant) then ((l ≤ mid ∧ mid ≤ mid ∧ mid ≤ i + 1%Z ∧ i + 1%Z ≤ h) ∧ s + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat mid) (take (Z.to_nat (i + 1%Z) - Z.to_nat mid) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ i + 1%Z -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ s + nth (Z.to_nat i) a inhabitant) ∧ s + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat mid) (take (Z.to_nat (i + 1%Z) - Z.to_nat mid) a)) else ((l ≤ mid ∧ mid ≤ mid ∧ mid ≤ hi ∧ hi ≤ h) ∧ ms = list_sum (drop (Z.to_nat mid) (take (Z.to_nat hi - Z.to_nat mid) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ i + 1%Z -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms) ∧ s + nth (Z.to_nat i) a inhabitant = list_sum (drop (Z.to_nat mid) (take (Z.to_nat (i + 1%Z) - Z.to_nat mid) a)))) ∧ (((l ≤ mid ∧ mid ≤ mid ∧ mid ≤ hi ∧ hi ≤ h) ∧ ms = list_sum (drop (Z.to_nat mid) (take (Z.to_nat hi - Z.to_nat mid) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ mid ∧ mid ≤ h' ∧ h' ≤ o2 + 1%Z -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms) ∧ s = list_sum (drop (Z.to_nat mid) (take (Z.to_nat (o2 + 1%Z) - Z.to_nat mid) a)) -> ((0%Z ≤ h - l ∧ mid - l < h - l) ∧ 0%Z ≤ l ∧ l ≤ mid ∧ mid ≤ Z.of_nat (length a)) ∧ (∀(hi' : Z) (lo' : Z), (l ≤ lo' ∧ lo' ≤ hi' ∧ hi' ≤ mid) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))) -> (if decide (ms < list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))) then let o3 : Z := mid + 1%Z in ((0%Z ≤ h - l ∧ h - o3 < h - l) ∧ 0%Z ≤ o3 ∧ o3 ≤ h ∧ h ≤ Z.of_nat (length a)) ∧ (∀(hi'1 : Z) (lo'1 : Z), (o3 ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), o3 ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) -> (if decide (list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a)) < list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) then (l ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) else (l ≤ lo' ∧ lo' ≤ hi' ∧ hi' ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))))) else let o3 : Z := mid + 1%Z in ((0%Z ≤ h - l ∧ h - o3 < h - l) ∧ 0%Z ≤ o3 ∧ o3 ≤ h ∧ h ≤ Z.of_nat (length a)) ∧ (∀(hi'1 : Z) (lo'1 : Z), (o3 ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), o3 ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) -> (if decide (ms < list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) then (l ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) else ((l ≤ mid ∧ mid ≤ hi ∧ hi ≤ h) ∧ ms = list_sum (drop (Z.to_nat mid) (take (Z.to_nat hi - Z.to_nat mid) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ ms)))))))) ∧ (o2 + 1%Z < mid -> ((0%Z ≤ h - l ∧ mid - l < h - l) ∧ 0%Z ≤ l ∧ l ≤ mid ∧ mid ≤ Z.of_nat (length a)) ∧ (∀(hi' : Z) (lo' : Z), (l ≤ lo' ∧ lo' ≤ hi' ∧ hi' ≤ mid) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ mid -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))) -> (if decide (0%Z < list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))) then let o3 : Z := mid + 1%Z in ((0%Z ≤ h - l ∧ h - o3 < h - l) ∧ 0%Z ≤ o3 ∧ o3 ≤ h ∧ h ≤ Z.of_nat (length a)) ∧ (∀(hi'1 : Z) (lo'1 : Z), (o3 ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), o3 ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) -> (if decide (list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a)) < list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) then (l ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) else (l ≤ lo' ∧ lo' ≤ hi' ∧ hi' ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo') (take (Z.to_nat hi' - Z.to_nat lo') a))))) else let o3 : Z := mid + 1%Z in ((0%Z ≤ h - l ∧ h - o3 < h - l) ∧ 0%Z ≤ o3 ∧ o3 ≤ h ∧ h ≤ Z.of_nat (length a)) ∧ (∀(hi'1 : Z) (lo'1 : Z), (o3 ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), o3 ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) -> (if decide (0%Z < list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) then (l ≤ lo'1 ∧ lo'1 ≤ hi'1 ∧ hi'1 ≤ h) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ list_sum (drop (Z.to_nat lo'1) (take (Z.to_nat hi'1 - Z.to_nat lo'1) a))) else ((l ≤ mid ∧ mid ≤ mid ∧ mid ≤ h) ∧ 0%Z = list_sum (drop (Z.to_nat mid) (take (Z.to_nat mid - Z.to_nat mid) a))) ∧ (∀(l' : Z) (h' : Z), l ≤ l' ∧ l' ≤ h' ∧ h' ≤ h -> list_sum (drop (Z.to_nat l') (take (Z.to_nat h' - Z.to_nat l') a)) ≤ 0%Z))))))))).
Admitted.
