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 edit_distance_vcg.edit_distance.MyWord.
Open Scope Z_scope.
Axiom suffix : list char -> Z -> list char.
Axiom suffix_nil : forall  (a : list char), suffix a (Z.of_nat (length a)) = ([] : list char).
Axiom suffix_cons : forall  (i : Z) (a : list char) (fact0 : 0%Z ≤ i) (fact1 : i < Z.of_nat (length a)), suffix a i = cons (nth (Z.to_nat i) a inhabitant) (suffix a (i + 1%Z)).
Definition min_suffix (a1 : list char) (a2 : list char) (i : Z) (j : Z) (n : Z) := min_dist (suffix a1 i) (suffix a2 j) n.
Theorem distance'vc (w1 : list char) (w2 : list char) : let n1 : Z := Z.of_nat (length w1) in let n2 : Z := Z.of_nat (length w2) in let o1 : Z := n2 + 1%Z in 0%Z ≤ o1 ∧ (∀(t : list Z), (∀(i : Z), 0%Z ≤ i ∧ i < o1 -> nth (Z.to_nat i) t inhabitant = 0%Z) ∧ Z.of_nat (length t) = o1 -> (0%Z ≤ n2 + 1%Z -> (∀(j : Z), 0%Z ≤ j ∧ j < 0%Z -> nth (Z.to_nat j) t inhabitant = n2 - j) ∧ (∀(t1 : list Z), length t1 = length t -> (∀(i : Z), (0%Z ≤ i ∧ i ≤ n2) ∧ (∀(j : Z), 0%Z ≤ j ∧ j < i -> nth (Z.to_nat j) t1 inhabitant = n2 - j) -> (let o2 : Z := n2 - i in (0%Z ≤ i ∧ i < Z.of_nat (length t1)) ∧ (length (set_list t1 (Z.to_nat i) o2) = length t1 -> nth_i (set_list t1 (Z.to_nat i) o2) = fun_updt (nth_i t1) i o2 -> (∀(j : Z), 0%Z ≤ j ∧ j < i + 1%Z -> nth (Z.to_nat j) (set_list t1 (Z.to_nat i) o2) inhabitant = n2 - j)))) ∧ ((∀(j : Z), 0%Z ≤ j ∧ j < n2 + 1%Z -> nth (Z.to_nat j) t1 inhabitant = n2 - j) -> (let o2 : Z := n1 - 1%Z in (0%Z - 1%Z ≤ o2 -> (∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (o2 + 1%Z) j (nth (Z.to_nat j) t1 inhabitant)) ∧ (∀(t2 : list Z), length t2 = length t1 -> (∀(i : Z), (i ≤ o2 ∧ 0%Z ≤ i) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (i + 1%Z) j (nth (Z.to_nat j) t2 inhabitant)) -> (0%Z ≤ n2 ∧ n2 < Z.of_nat (length t2)) ∧ (0%Z ≤ n2 ∧ n2 < Z.of_nat (length t2)) ∧ (let o3 : Z := nth (Z.to_nat n2) t2 inhabitant + 1%Z in (0%Z ≤ n2 ∧ n2 < Z.of_nat (length t2)) ∧ (length (set_list t2 (Z.to_nat n2) o3) = length t2 -> nth_i (set_list t2 (Z.to_nat n2) o3) = fun_updt (nth_i t2) n2 o3 -> (let o4 : Z := n2 - 1%Z in (0%Z - 1%Z ≤ o4 -> ((∀(k : Z), o4 < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) (set_list t2 (Z.to_nat n2) o3) inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ o4 -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) (set_list t2 (Z.to_nat n2) o3) inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (o4 + 1%Z) (nth (Z.to_nat n2) t2 inhabitant)) ∧ (∀(oldt : Z) (t3 : list Z), length t3 = length (set_list t2 (Z.to_nat n2) o3) -> (∀(j : Z), (j ≤ o4 ∧ 0%Z ≤ j) ∧ (∀(k : Z), j < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) t3 inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ j -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) t3 inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (j + 1%Z) oldt -> (0%Z ≤ j ∧ j < Z.of_nat (length t3)) ∧ (0%Z ≤ j ∧ j < Z.of_nat (length w2)) ∧ (0%Z ≤ i ∧ i < Z.of_nat (length w1)) ∧ (if decide (nth (Z.to_nat i) w1 inhabitant = nth (Z.to_nat j) w2 inhabitant) then (0%Z ≤ j ∧ j < Z.of_nat (length t3)) ∧ (length (set_list t3 (Z.to_nat j) oldt) = length t3 -> nth_i (set_list t3 (Z.to_nat j) oldt) = fun_updt (nth_i t3) j oldt -> (∀(k : Z), j - 1%Z < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) (set_list t3 (Z.to_nat j) oldt) inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ j - 1%Z -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) (set_list t3 (Z.to_nat j) oldt) inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (j - 1%Z + 1%Z) (nth (Z.to_nat j) t3 inhabitant)) else let o5 : Z := j + 1%Z in (0%Z ≤ o5 ∧ o5 < Z.of_nat (length t3)) ∧ (0%Z ≤ j ∧ j < Z.of_nat (length t3)) ∧ (let o6 : Z := Z.min (nth (Z.to_nat j) t3 inhabitant) (nth (Z.to_nat o5) t3 inhabitant) + 1%Z in (0%Z ≤ j ∧ j < Z.of_nat (length t3)) ∧ (length (set_list t3 (Z.to_nat j) o6) = length t3 -> nth_i (set_list t3 (Z.to_nat j) o6) = fun_updt (nth_i t3) j o6 -> (∀(k : Z), j - 1%Z < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) (set_list t3 (Z.to_nat j) o6) inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ j - 1%Z -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) (set_list t3 (Z.to_nat j) o6) inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (j - 1%Z + 1%Z) (nth (Z.to_nat j) t3 inhabitant))))) ∧ ((∀(k : Z), 0%Z - 1%Z < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) t3 inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ 0%Z - 1%Z -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) t3 inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (0%Z - 1%Z + 1%Z) oldt -> (∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (i - 1%Z + 1%Z) j (nth (Z.to_nat j) t3 inhabitant))))) ∧ (o4 < 0%Z - 1%Z -> (∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (i - 1%Z + 1%Z) j (nth (Z.to_nat j) (set_list t2 (Z.to_nat n2) o3) inhabitant))))))) ∧ ((∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (0%Z - 1%Z + 1%Z) j (nth (Z.to_nat j) t2 inhabitant)) -> (0%Z ≤ 0%Z ∧ 0%Z < Z.of_nat (length t2)) ∧ min_dist (suffix w1 0%Z) (suffix w2 0%Z) (nth 0%nat t2 inhabitant)))) ∧ (o2 < 0%Z - 1%Z -> (0%Z ≤ 0%Z ∧ 0%Z < Z.of_nat (length t1)) ∧ min_dist (suffix w1 0%Z) (suffix w2 0%Z) (nth 0%nat t1 inhabitant)))))) ∧ (n2 + 1%Z < 0%Z -> (let o2 : Z := n1 - 1%Z in (0%Z - 1%Z ≤ o2 -> (∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (o2 + 1%Z) j (nth (Z.to_nat j) t inhabitant)) ∧ (∀(t1 : list Z), length t1 = length t -> (∀(i : Z), (i ≤ o2 ∧ 0%Z ≤ i) ∧ (∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (i + 1%Z) j (nth (Z.to_nat j) t1 inhabitant)) -> (0%Z ≤ n2 ∧ n2 < Z.of_nat (length t1)) ∧ (0%Z ≤ n2 ∧ n2 < Z.of_nat (length t1)) ∧ (let o3 : Z := nth (Z.to_nat n2) t1 inhabitant + 1%Z in (0%Z ≤ n2 ∧ n2 < Z.of_nat (length t1)) ∧ (length (set_list t1 (Z.to_nat n2) o3) = length t1 -> nth_i (set_list t1 (Z.to_nat n2) o3) = fun_updt (nth_i t1) n2 o3 -> (let o4 : Z := n2 - 1%Z in (0%Z - 1%Z ≤ o4 -> ((∀(k : Z), o4 < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) (set_list t1 (Z.to_nat n2) o3) inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ o4 -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) (set_list t1 (Z.to_nat n2) o3) inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (o4 + 1%Z) (nth (Z.to_nat n2) t1 inhabitant)) ∧ (∀(oldt : Z) (t2 : list Z), length t2 = length (set_list t1 (Z.to_nat n2) o3) -> (∀(j : Z), (j ≤ o4 ∧ 0%Z ≤ j) ∧ (∀(k : Z), j < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) t2 inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ j -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) t2 inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (j + 1%Z) oldt -> (0%Z ≤ j ∧ j < Z.of_nat (length t2)) ∧ (0%Z ≤ j ∧ j < Z.of_nat (length w2)) ∧ (0%Z ≤ i ∧ i < Z.of_nat (length w1)) ∧ (if decide (nth (Z.to_nat i) w1 inhabitant = nth (Z.to_nat j) w2 inhabitant) then (0%Z ≤ j ∧ j < Z.of_nat (length t2)) ∧ (length (set_list t2 (Z.to_nat j) oldt) = length t2 -> nth_i (set_list t2 (Z.to_nat j) oldt) = fun_updt (nth_i t2) j oldt -> (∀(k : Z), j - 1%Z < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) (set_list t2 (Z.to_nat j) oldt) inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ j - 1%Z -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) (set_list t2 (Z.to_nat j) oldt) inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (j - 1%Z + 1%Z) (nth (Z.to_nat j) t2 inhabitant)) else let o5 : Z := j + 1%Z in (0%Z ≤ o5 ∧ o5 < Z.of_nat (length t2)) ∧ (0%Z ≤ j ∧ j < Z.of_nat (length t2)) ∧ (let o6 : Z := Z.min (nth (Z.to_nat j) t2 inhabitant) (nth (Z.to_nat o5) t2 inhabitant) + 1%Z in (0%Z ≤ j ∧ j < Z.of_nat (length t2)) ∧ (length (set_list t2 (Z.to_nat j) o6) = length t2 -> nth_i (set_list t2 (Z.to_nat j) o6) = fun_updt (nth_i t2) j o6 -> (∀(k : Z), j - 1%Z < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) (set_list t2 (Z.to_nat j) o6) inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ j - 1%Z -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) (set_list t2 (Z.to_nat j) o6) inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (j - 1%Z + 1%Z) (nth (Z.to_nat j) t2 inhabitant))))) ∧ ((∀(k : Z), 0%Z - 1%Z < k ∧ k ≤ n2 -> min_suffix w1 w2 i k (nth (Z.to_nat k) t2 inhabitant)) ∧ (∀(k : Z), 0%Z ≤ k ∧ k ≤ 0%Z - 1%Z -> min_suffix w1 w2 (i + 1%Z) k (nth (Z.to_nat k) t2 inhabitant)) ∧ min_suffix w1 w2 (i + 1%Z) (0%Z - 1%Z + 1%Z) oldt -> (∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (i - 1%Z + 1%Z) j (nth (Z.to_nat j) t2 inhabitant))))) ∧ (o4 < 0%Z - 1%Z -> (∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (i - 1%Z + 1%Z) j (nth (Z.to_nat j) (set_list t1 (Z.to_nat n2) o3) inhabitant))))))) ∧ ((∀(j : Z), 0%Z ≤ j ∧ j ≤ n2 -> min_suffix w1 w2 (0%Z - 1%Z + 1%Z) j (nth (Z.to_nat j) t1 inhabitant)) -> (0%Z ≤ 0%Z ∧ 0%Z < Z.of_nat (length t1)) ∧ min_dist (suffix w1 0%Z) (suffix w2 0%Z) (nth 0%nat t1 inhabitant)))) ∧ (o2 < 0%Z - 1%Z -> (0%Z ≤ 0%Z ∧ 0%Z < Z.of_nat (length t)) ∧ min_dist (suffix w1 0%Z) (suffix w2 0%Z) (nth 0%nat t inhabitant))))).
Admitted.
