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 get_closure : forall {α : Type} `{Inhabited α}, list α -> Z -> α.
Axiom get_closure_def : forall  {α : Type} `{Inhabited α} (y : list α) (y1 : Z), get_closure y y1 = nth (Z.to_nat y1) y inhabitant.
Definition last (s : list Z) : Z := nth (Z.to_nat (Z.of_nat (length s) - 1%Z)) s inhabitant.
Theorem huffman_coding'vc (s : list Z) (fact0 : 0%Z < Z.of_nat (length s)) (fact1 : Sorted Z.le s) : 0%Z < Z.of_nat (length s) + Z.of_nat (length ([] : list Z)) ∧ list_sum s + list_sum ([] : list Z) = list_sum s ∧ Sorted Z.le s ∧ Sorted Z.le ([] : list Z) ∧ (2%Z ≤ Z.of_nat (length s) -> 1%Z ≤ Z.of_nat (length ([] : list Z)) -> last ([] : list Z) ≤ nth 0%nat s inhabitant + nth 1%nat s inhabitant) ∧ (1%Z ≤ Z.of_nat (length s) -> 2%Z ≤ Z.of_nat (length ([] : list Z)) -> last ([] : list Z) ≤ nth 0%nat s inhabitant + nth 0%nat ([] : list Z) inhabitant) ∧ (2%Z ≤ Z.of_nat (length ([] : list Z)) -> last ([] : list Z) ≤ nth 0%nat ([] : list Z) inhabitant + nth 1%nat ([] : list Z) inhabitant) ∧ (∀(y : list Z) (x : list Z), 0%Z < Z.of_nat (length x) + Z.of_nat (length y) ∧ list_sum x + list_sum y = list_sum s ∧ Sorted Z.le x ∧ Sorted Z.le y ∧ (2%Z ≤ Z.of_nat (length x) -> 1%Z ≤ Z.of_nat (length y) -> last y ≤ nth 0%nat x inhabitant + nth 1%nat x inhabitant) ∧ (1%Z ≤ Z.of_nat (length x) -> 2%Z ≤ Z.of_nat (length y) -> last y ≤ nth 0%nat x inhabitant + nth 0%nat y inhabitant) ∧ (2%Z ≤ Z.of_nat (length y) -> last y ≤ nth 0%nat y inhabitant + nth 1%nat y inhabitant) -> (if decide (2%Z ≤ Z.of_nat (length x) + Z.of_nat (length y)) then if decide (Z.of_nat (length y) = 0%Z) then let o1 : Z := nth 0%nat x inhabitant + nth 1%nat x inhabitant in let o2 : list Z := y ++ [o1] in Z.of_nat (length o2) = 1%Z + Z.of_nat (length y) ∧ nth (length y) o2 inhabitant = o1 ∧ (∀(i : Z), 0%Z ≤ i ∧ i < Z.of_nat (length y) -> nth (Z.to_nat i) o2 inhabitant = nth (Z.to_nat i) y inhabitant) -> (0%Z ≤ 2%Z ∧ 2%Z ≤ Z.of_nat (length x)) ∧ (0%Z ≤ Z.of_nat (length x) + Z.of_nat (length y) ∧ Z.of_nat (length (drop 2%nat x)) + Z.of_nat (length o2) < Z.of_nat (length x) + Z.of_nat (length y)) ∧ 0%Z < Z.of_nat (length (drop 2%nat x)) + Z.of_nat (length o2) ∧ list_sum (drop 2%nat x) + list_sum o2 = list_sum s ∧ Sorted Z.le (drop 2%nat x) ∧ Sorted Z.le o2 ∧ (2%Z ≤ Z.of_nat (length (drop 2%nat x)) -> 1%Z ≤ Z.of_nat (length o2) -> last o2 ≤ nth 0%nat (drop 2%nat x) inhabitant + nth 1%nat (drop 2%nat x) inhabitant) ∧ (1%Z ≤ Z.of_nat (length (drop 2%nat x)) -> 2%Z ≤ Z.of_nat (length o2) -> last o2 ≤ nth 0%nat (drop 2%nat x) inhabitant + nth 0%nat o2 inhabitant) ∧ (2%Z ≤ Z.of_nat (length o2) -> last o2 ≤ nth 0%nat o2 inhabitant + nth 1%nat o2 inhabitant) else if decide (Z.of_nat (length x) = 0%Z) then let o1 : Z := nth 0%nat y inhabitant + nth 1%nat y inhabitant in (0%Z ≤ 2%Z ∧ 2%Z ≤ Z.of_nat (length y)) ∧ (let o2 : list Z := drop 2%nat y in let o3 : list Z := o2 ++ [o1] in Z.of_nat (length o3) = 1%Z + Z.of_nat (length o2) ∧ nth (length o2) o3 inhabitant = o1 ∧ (∀(i : Z), 0%Z ≤ i ∧ i < Z.of_nat (length o2) -> nth (Z.to_nat i) o3 inhabitant = nth (Z.to_nat i) o2 inhabitant) -> (0%Z ≤ Z.of_nat (length x) + Z.of_nat (length y) ∧ Z.of_nat (length x) + Z.of_nat (length o3) < Z.of_nat (length x) + Z.of_nat (length y)) ∧ 0%Z < Z.of_nat (length x) + Z.of_nat (length o3) ∧ list_sum x + list_sum o3 = list_sum s ∧ Sorted Z.le x ∧ Sorted Z.le o3 ∧ (2%Z ≤ Z.of_nat (length x) -> 1%Z ≤ Z.of_nat (length o3) -> last o3 ≤ nth 0%nat x inhabitant + nth 1%nat x inhabitant) ∧ (1%Z ≤ Z.of_nat (length x) -> 2%Z ≤ Z.of_nat (length o3) -> last o3 ≤ nth 0%nat x inhabitant + nth 0%nat o3 inhabitant) ∧ (2%Z ≤ Z.of_nat (length o3) -> last o3 ≤ nth 0%nat o3 inhabitant + nth 1%nat o3 inhabitant)) else if decide (nth 0%nat x inhabitant ≤ nth 0%nat y inhabitant) then ∀(o1 : bool), (if decide (2%Z ≤ Z.of_nat (length x)) then o1 = (if decide (nth 1%nat x inhabitant ≤ nth 0%nat y inhabitant) then true else false) else o1 = false) -> (if decide (o1 = true) then let o2 : Z := nth 0%nat x inhabitant + nth 1%nat x inhabitant in let o3 : list Z := y ++ [o2] in Z.of_nat (length o3) = 1%Z + Z.of_nat (length y) ∧ nth (length y) o3 inhabitant = o2 ∧ (∀(i : Z), 0%Z ≤ i ∧ i < Z.of_nat (length y) -> nth (Z.to_nat i) o3 inhabitant = nth (Z.to_nat i) y inhabitant) -> (0%Z ≤ 2%Z ∧ 2%Z ≤ Z.of_nat (length x)) ∧ (0%Z ≤ Z.of_nat (length x) + Z.of_nat (length y) ∧ Z.of_nat (length (drop 2%nat x)) + Z.of_nat (length o3) < Z.of_nat (length x) + Z.of_nat (length y)) ∧ 0%Z < Z.of_nat (length (drop 2%nat x)) + Z.of_nat (length o3) ∧ list_sum (drop 2%nat x) + list_sum o3 = list_sum s ∧ Sorted Z.le (drop 2%nat x) ∧ Sorted Z.le o3 ∧ (2%Z ≤ Z.of_nat (length (drop 2%nat x)) -> 1%Z ≤ Z.of_nat (length o3) -> last o3 ≤ nth 0%nat (drop 2%nat x) inhabitant + nth 1%nat (drop 2%nat x) inhabitant) ∧ (1%Z ≤ Z.of_nat (length (drop 2%nat x)) -> 2%Z ≤ Z.of_nat (length o3) -> last o3 ≤ nth 0%nat (drop 2%nat x) inhabitant + nth 0%nat o3 inhabitant) ∧ (2%Z ≤ Z.of_nat (length o3) -> last o3 ≤ nth 0%nat o3 inhabitant + nth 1%nat o3 inhabitant) else let o2 : Z := nth 0%nat x inhabitant + nth 0%nat y inhabitant in (0%Z ≤ 1%Z ∧ 1%Z ≤ Z.of_nat (length y)) ∧ (let o3 : list Z := drop 1%nat y in let o4 : list Z := o3 ++ [o2] in Z.of_nat (length o4) = 1%Z + Z.of_nat (length o3) ∧ nth (length o3) o4 inhabitant = o2 ∧ (∀(i : Z), 0%Z ≤ i ∧ i < Z.of_nat (length o3) -> nth (Z.to_nat i) o4 inhabitant = nth (Z.to_nat i) o3 inhabitant) -> (0%Z ≤ 1%Z ∧ 1%Z ≤ Z.of_nat (length x)) ∧ (0%Z ≤ Z.of_nat (length x) + Z.of_nat (length y) ∧ Z.of_nat (length (drop 1%nat x)) + Z.of_nat (length o4) < Z.of_nat (length x) + Z.of_nat (length y)) ∧ 0%Z < Z.of_nat (length (drop 1%nat x)) + Z.of_nat (length o4) ∧ list_sum (drop 1%nat x) + list_sum o4 = list_sum s ∧ Sorted Z.le (drop 1%nat x) ∧ Sorted Z.le o4 ∧ (2%Z ≤ Z.of_nat (length (drop 1%nat x)) -> 1%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat (drop 1%nat x) inhabitant + nth 1%nat (drop 1%nat x) inhabitant) ∧ (1%Z ≤ Z.of_nat (length (drop 1%nat x)) -> 2%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat (drop 1%nat x) inhabitant + nth 0%nat o4 inhabitant) ∧ (2%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat o4 inhabitant + nth 1%nat o4 inhabitant))) else ∀(o1 : bool), (if decide (2%Z ≤ Z.of_nat (length y)) then o1 = (if decide (nth 1%nat y inhabitant ≤ nth 0%nat x inhabitant) then true else false) else o1 = false) -> (if decide (o1 = true) then let o2 : Z := nth 0%nat y inhabitant + nth 1%nat y inhabitant in (0%Z ≤ 2%Z ∧ 2%Z ≤ Z.of_nat (length y)) ∧ (let o3 : list Z := drop 2%nat y in let o4 : list Z := o3 ++ [o2] in Z.of_nat (length o4) = 1%Z + Z.of_nat (length o3) ∧ nth (length o3) o4 inhabitant = o2 ∧ (∀(i : Z), 0%Z ≤ i ∧ i < Z.of_nat (length o3) -> nth (Z.to_nat i) o4 inhabitant = nth (Z.to_nat i) o3 inhabitant) -> (0%Z ≤ Z.of_nat (length x) + Z.of_nat (length y) ∧ Z.of_nat (length x) + Z.of_nat (length o4) < Z.of_nat (length x) + Z.of_nat (length y)) ∧ 0%Z < Z.of_nat (length x) + Z.of_nat (length o4) ∧ list_sum x + list_sum o4 = list_sum s ∧ Sorted Z.le x ∧ Sorted Z.le o4 ∧ (2%Z ≤ Z.of_nat (length x) -> 1%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat x inhabitant + nth 1%nat x inhabitant) ∧ (1%Z ≤ Z.of_nat (length x) -> 2%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat x inhabitant + nth 0%nat o4 inhabitant) ∧ (2%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat o4 inhabitant + nth 1%nat o4 inhabitant)) else let o2 : Z := nth 0%nat x inhabitant + nth 0%nat y inhabitant in (0%Z ≤ 1%Z ∧ 1%Z ≤ Z.of_nat (length y)) ∧ (let o3 : list Z := drop 1%nat y in let o4 : list Z := o3 ++ [o2] in Z.of_nat (length o4) = 1%Z + Z.of_nat (length o3) ∧ nth (length o3) o4 inhabitant = o2 ∧ (∀(i : Z), 0%Z ≤ i ∧ i < Z.of_nat (length o3) -> nth (Z.to_nat i) o4 inhabitant = nth (Z.to_nat i) o3 inhabitant) -> (0%Z ≤ 1%Z ∧ 1%Z ≤ Z.of_nat (length x)) ∧ (0%Z ≤ Z.of_nat (length x) + Z.of_nat (length y) ∧ Z.of_nat (length (drop 1%nat x)) + Z.of_nat (length o4) < Z.of_nat (length x) + Z.of_nat (length y)) ∧ 0%Z < Z.of_nat (length (drop 1%nat x)) + Z.of_nat (length o4) ∧ list_sum (drop 1%nat x) + list_sum o4 = list_sum s ∧ Sorted Z.le (drop 1%nat x) ∧ Sorted Z.le o4 ∧ (2%Z ≤ Z.of_nat (length (drop 1%nat x)) -> 1%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat (drop 1%nat x) inhabitant + nth 1%nat (drop 1%nat x) inhabitant) ∧ (1%Z ≤ Z.of_nat (length (drop 1%nat x)) -> 2%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat (drop 1%nat x) inhabitant + nth 0%nat o4 inhabitant) ∧ (2%Z ≤ Z.of_nat (length o4) -> last o4 ≤ nth 0%nat o4 inhabitant + nth 1%nat o4 inhabitant))) else ∀(result : Z), (if decide (0%Z < Z.of_nat (length x)) then result = nth 0%nat x inhabitant else result = nth 0%nat y inhabitant) -> result = list_sum s)).
Admitted.
