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.NumOf.
Require Import counting_sort_vcg.counting_sort.Spec.
Require Import Why3.array.IntArraySorted.
Open Scope Z_scope.
Theorem counting_sort'vc (a : list Z) (b : list Z) (fact0 : k_values a) (fact1 : length a = length b) : let o1 : Z := k in 0%Z ≤ o1 ∧ (∀(c : list Z), (∀(i : Z), 0%Z ≤ i ∧ i < o1 -> nth (Z.to_nat i) c inhabitant = 0%Z) ∧ Z.of_nat (length c) = o1 -> (let o2 : Z := Z.of_nat (length a) - 1%Z in (0%Z ≤ o2 + 1%Z -> (∀(v : Z), 0%Z ≤ v ∧ v < k -> nth (Z.to_nat v) c inhabitant = numeq a v 0%Z 0%Z) ∧ (∀(c1 : list Z), length c1 = length c -> (∀(i : Z), (0%Z ≤ i ∧ i ≤ o2) ∧ (∀(v : Z), 0%Z ≤ v ∧ v < k -> nth (Z.to_nat v) c1 inhabitant = numeq a v 0%Z i) -> (0%Z ≤ i ∧ i < Z.of_nat (length a)) ∧ (let v : Z := nth (Z.to_nat i) a inhabitant in (0%Z ≤ v ∧ v < Z.of_nat (length c1)) ∧ (let o3 : Z := nth (Z.to_nat v) c1 inhabitant + 1%Z in (0%Z ≤ v ∧ v < Z.of_nat (length c1)) ∧ (length (set_list c1 (Z.to_nat v) o3) = length c1 -> nth_i (set_list c1 (Z.to_nat v) o3) = fun_updt (nth_i c1) v o3 -> (∀(v1 : Z), 0%Z ≤ v1 ∧ v1 < k -> nth (Z.to_nat v1) (set_list c1 (Z.to_nat v) o3) inhabitant = numeq a v1 0%Z (i + 1%Z)))))) ∧ ((∀(v : Z), 0%Z ≤ v ∧ v < k -> nth (Z.to_nat v) c1 inhabitant = numeq a v 0%Z (o2 + 1%Z)) -> (let o3 : Z := k - 1%Z in (0%Z ≤ o3 + 1%Z -> (0%Z = numlt a 0%Z 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b 0%Z 0%Z ∧ (∀(e : Z), 0%Z ≤ e ∧ e < 0%Z -> 0%Z ≤ nth (Z.to_nat e) b inhabitant ∧ nth (Z.to_nat e) b inhabitant < 0%Z) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < 0%Z -> numeq b f 0%Z 0%Z = numeq a f 0%Z (Z.of_nat (length a)))) ∧ (∀(j : Z) (b1 : list Z), length b1 = length b -> (∀(v : Z), (0%Z ≤ v ∧ v ≤ o3) ∧ j = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b1 0%Z j ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j -> 0%Z ≤ nth (Z.to_nat e) b1 inhabitant ∧ nth (Z.to_nat e) b1 inhabitant < v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq b1 f 0%Z j = numeq a f 0%Z (Z.of_nat (length a))) -> (0%Z ≤ v ∧ v < Z.of_nat (length c1)) ∧ (let o4 : Z := nth (Z.to_nat v) c1 inhabitant in (1%Z ≤ o4 + 1%Z -> (j - 1%Z + 1%Z = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b1 0%Z j ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j -> 0%Z ≤ nth (Z.to_nat e) b1 inhabitant ∧ nth (Z.to_nat e) b1 inhabitant ≤ v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq b1 f 0%Z j = numeq a f 0%Z (Z.of_nat (length a))) ∧ numeq b1 v 0%Z j = 1%Z - 1%Z) ∧ (∀(j1 : Z) (b2 : list Z), length b2 = length b1 -> (∀(i : Z), (1%Z ≤ i ∧ i ≤ o4) ∧ j1 - i + 1%Z = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b2 0%Z j1 ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j1 -> 0%Z ≤ nth (Z.to_nat e) b2 inhabitant ∧ nth (Z.to_nat e) b2 inhabitant ≤ v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq b2 f 0%Z j1 = numeq a f 0%Z (Z.of_nat (length a))) ∧ numeq b2 v 0%Z j1 = i - 1%Z -> (0%Z ≤ j1 ∧ j1 < Z.of_nat (length b2)) ∧ (length (set_list b2 (Z.to_nat j1) v) = length b2 -> nth_i (set_list b2 (Z.to_nat j1) v) = fun_updt (nth_i b2) j1 v -> j1 + 1%Z - (i + 1%Z) + 1%Z = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 (set_list b2 (Z.to_nat j1) v) 0%Z (j1 + 1%Z) ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j1 + 1%Z -> 0%Z ≤ nth (Z.to_nat e) (set_list b2 (Z.to_nat j1) v) inhabitant ∧ nth (Z.to_nat e) (set_list b2 (Z.to_nat j1) v) inhabitant ≤ v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq (set_list b2 (Z.to_nat j1) v) f 0%Z (j1 + 1%Z) = numeq a f 0%Z (Z.of_nat (length a))) ∧ numeq (set_list b2 (Z.to_nat j1) v) v 0%Z (j1 + 1%Z) = i + 1%Z - 1%Z)) ∧ (j1 - (o4 + 1%Z) + 1%Z = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b2 0%Z j1 ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j1 -> 0%Z ≤ nth (Z.to_nat e) b2 inhabitant ∧ nth (Z.to_nat e) b2 inhabitant ≤ v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq b2 f 0%Z j1 = numeq a f 0%Z (Z.of_nat (length a))) ∧ numeq b2 v 0%Z j1 = o4 + 1%Z - 1%Z -> j1 = numlt a (v + 1%Z) 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b2 0%Z j1 ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j1 -> 0%Z ≤ nth (Z.to_nat e) b2 inhabitant ∧ nth (Z.to_nat e) b2 inhabitant < v + 1%Z) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v + 1%Z -> numeq b2 f 0%Z j1 = numeq a f 0%Z (Z.of_nat (length a)))))) ∧ (o4 + 1%Z < 1%Z -> j = numlt a (v + 1%Z) 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b1 0%Z j ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j -> 0%Z ≤ nth (Z.to_nat e) b1 inhabitant ∧ nth (Z.to_nat e) b1 inhabitant < v + 1%Z) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v + 1%Z -> numeq b1 f 0%Z j = numeq a f 0%Z (Z.of_nat (length a)))))) ∧ (j = numlt a (o3 + 1%Z) 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b1 0%Z j ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j -> 0%Z ≤ nth (Z.to_nat e) b1 inhabitant ∧ nth (Z.to_nat e) b1 inhabitant < o3 + 1%Z) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < o3 + 1%Z -> numeq b1 f 0%Z j = numeq a f 0%Z (Z.of_nat (length a))) -> sorted b1 ∧ permut a b1))) ∧ (o3 + 1%Z < 0%Z -> sorted b ∧ permut a b))))) ∧ (o2 + 1%Z < 0%Z -> (let o3 : Z := k - 1%Z in (0%Z ≤ o3 + 1%Z -> (0%Z = numlt a 0%Z 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b 0%Z 0%Z ∧ (∀(e : Z), 0%Z ≤ e ∧ e < 0%Z -> 0%Z ≤ nth (Z.to_nat e) b inhabitant ∧ nth (Z.to_nat e) b inhabitant < 0%Z) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < 0%Z -> numeq b f 0%Z 0%Z = numeq a f 0%Z (Z.of_nat (length a)))) ∧ (∀(j : Z) (b1 : list Z), length b1 = length b -> (∀(v : Z), (0%Z ≤ v ∧ v ≤ o3) ∧ j = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b1 0%Z j ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j -> 0%Z ≤ nth (Z.to_nat e) b1 inhabitant ∧ nth (Z.to_nat e) b1 inhabitant < v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq b1 f 0%Z j = numeq a f 0%Z (Z.of_nat (length a))) -> (0%Z ≤ v ∧ v < Z.of_nat (length c)) ∧ (let o4 : Z := nth (Z.to_nat v) c inhabitant in (1%Z ≤ o4 + 1%Z -> (j - 1%Z + 1%Z = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b1 0%Z j ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j -> 0%Z ≤ nth (Z.to_nat e) b1 inhabitant ∧ nth (Z.to_nat e) b1 inhabitant ≤ v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq b1 f 0%Z j = numeq a f 0%Z (Z.of_nat (length a))) ∧ numeq b1 v 0%Z j = 1%Z - 1%Z) ∧ (∀(j1 : Z) (b2 : list Z), length b2 = length b1 -> (∀(i : Z), (1%Z ≤ i ∧ i ≤ o4) ∧ j1 - i + 1%Z = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b2 0%Z j1 ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j1 -> 0%Z ≤ nth (Z.to_nat e) b2 inhabitant ∧ nth (Z.to_nat e) b2 inhabitant ≤ v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq b2 f 0%Z j1 = numeq a f 0%Z (Z.of_nat (length a))) ∧ numeq b2 v 0%Z j1 = i - 1%Z -> (0%Z ≤ j1 ∧ j1 < Z.of_nat (length b2)) ∧ (length (set_list b2 (Z.to_nat j1) v) = length b2 -> nth_i (set_list b2 (Z.to_nat j1) v) = fun_updt (nth_i b2) j1 v -> j1 + 1%Z - (i + 1%Z) + 1%Z = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 (set_list b2 (Z.to_nat j1) v) 0%Z (j1 + 1%Z) ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j1 + 1%Z -> 0%Z ≤ nth (Z.to_nat e) (set_list b2 (Z.to_nat j1) v) inhabitant ∧ nth (Z.to_nat e) (set_list b2 (Z.to_nat j1) v) inhabitant ≤ v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq (set_list b2 (Z.to_nat j1) v) f 0%Z (j1 + 1%Z) = numeq a f 0%Z (Z.of_nat (length a))) ∧ numeq (set_list b2 (Z.to_nat j1) v) v 0%Z (j1 + 1%Z) = i + 1%Z - 1%Z)) ∧ (j1 - (o4 + 1%Z) + 1%Z = numlt a v 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b2 0%Z j1 ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j1 -> 0%Z ≤ nth (Z.to_nat e) b2 inhabitant ∧ nth (Z.to_nat e) b2 inhabitant ≤ v) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v -> numeq b2 f 0%Z j1 = numeq a f 0%Z (Z.of_nat (length a))) ∧ numeq b2 v 0%Z j1 = o4 + 1%Z - 1%Z -> j1 = numlt a (v + 1%Z) 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b2 0%Z j1 ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j1 -> 0%Z ≤ nth (Z.to_nat e) b2 inhabitant ∧ nth (Z.to_nat e) b2 inhabitant < v + 1%Z) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v + 1%Z -> numeq b2 f 0%Z j1 = numeq a f 0%Z (Z.of_nat (length a)))))) ∧ (o4 + 1%Z < 1%Z -> j = numlt a (v + 1%Z) 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b1 0%Z j ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j -> 0%Z ≤ nth (Z.to_nat e) b1 inhabitant ∧ nth (Z.to_nat e) b1 inhabitant < v + 1%Z) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < v + 1%Z -> numeq b1 f 0%Z j = numeq a f 0%Z (Z.of_nat (length a)))))) ∧ (j = numlt a (o3 + 1%Z) 0%Z (Z.of_nat (length a)) ∧ sorted_sub1 b1 0%Z j ∧ (∀(e : Z), 0%Z ≤ e ∧ e < j -> 0%Z ≤ nth (Z.to_nat e) b1 inhabitant ∧ nth (Z.to_nat e) b1 inhabitant < o3 + 1%Z) ∧ (∀(f : Z), 0%Z ≤ f ∧ f < o3 + 1%Z -> numeq b1 f 0%Z j = numeq a f 0%Z (Z.of_nat (length a))) -> sorted b1 ∧ permut a b1))) ∧ (o3 + 1%Z < 0%Z -> sorted b ∧ permut a b))))).
Admitted.
