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.
Open Scope Z_scope.
Definition appear_twice (a : list Z) (v : Z) (u : Z) := ∃(i : Z), (0%Z ≤ i ∧ i < u) ∧ nth (Z.to_nat i) a inhabitant = v ∧ (∃(j : Z), (0%Z ≤ j ∧ j < u) ∧ ¬ j = i ∧ nth (Z.to_nat j) a inhabitant = v).
Theorem two_equal_elements'vc (a : list Z) (n : Z) (fact0 : Z.of_nat (length a) = n + 2%Z) (fact1 : 2%Z ≤ n) (fact2 : ∀(i : Z), 0%Z ≤ i ∧ i < Z.of_nat (length a) -> 0%Z ≤ nth (Z.to_nat i) a inhabitant ∧ nth (Z.to_nat i) a inhabitant < n) (fact3 : ∃(v1 : Z), appear_twice a v1 (n + 2%Z) ∧ (∃(v2 : Z), appear_twice a v2 (n + 2%Z) ∧ ¬ v2 = v1)) : 0%Z ≤ n ∧ (∀(deja_vu : list bool), (∀(i : Z), 0%Z ≤ i ∧ i < n -> nth (Z.to_nat i) deja_vu inhabitant = false) ∧ Z.of_nat (length deja_vu) = n -> (let o1 : Z := n + 1%Z in (0%Z ≤ o1 + 1%Z -> ((∀(v : Z), 0%Z ≤ v ∧ v < n -> (if decide (nth (Z.to_nat v) deja_vu inhabitant = true) then ∃(j : Z), (0%Z ≤ j ∧ j < 0%Z) ∧ nth (Z.to_nat j) a inhabitant = v else ∀(j : Z), 0%Z ≤ j ∧ j < 0%Z -> ¬ nth (Z.to_nat j) a inhabitant = v)) ∧ (∀(v : Z), 0%Z ≤ v ∧ v < n -> ¬ appear_twice a v 0%Z) ∧ (∀(v : Z), 0%Z ≤ v ∧ v < n -> ¬ v = - 1%Z -> ¬ appear_twice a v 0%Z)) ∧ (∀(v2 : Z) (v1 : Z) (deja_vu1 : list bool), length deja_vu1 = length deja_vu -> (∀(i : Z), (0%Z ≤ i ∧ i ≤ o1) ∧ (v1 = - 1%Z -> v2 = - 1%Z) ∧ (¬ v1 = - 1%Z -> appear_twice a v1 i) ∧ (¬ v2 = - 1%Z -> appear_twice a v2 i ∧ ¬ v2 = v1) ∧ (∀(v : Z), 0%Z ≤ v ∧ v < n -> (if decide (nth (Z.to_nat v) deja_vu1 inhabitant = true) then ∃(j : Z), (0%Z ≤ j ∧ j < i) ∧ nth (Z.to_nat j) a inhabitant = v else ∀(j : Z), 0%Z ≤ j ∧ j < i -> ¬ nth (Z.to_nat j) a inhabitant = v)) ∧ (v1 = - 1%Z -> (∀(v : Z), 0%Z ≤ v ∧ v < n -> ¬ appear_twice a v i)) ∧ (v2 = - 1%Z -> (∀(v : Z), 0%Z ≤ v ∧ v < n -> ¬ v = v1 -> ¬ appear_twice a v 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 deja_vu1)) ∧ (if decide (nth (Z.to_nat v) deja_vu1 inhabitant = true) then if decide (v1 = - 1%Z) then (v = - 1%Z -> v2 = - 1%Z) ∧ (¬ v = - 1%Z -> appear_twice a v (i + 1%Z)) ∧ (¬ v2 = - 1%Z -> appear_twice a v2 (i + 1%Z) ∧ ¬ v2 = v) ∧ (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> (if decide (nth (Z.to_nat v3) deja_vu1 inhabitant = true) then ∃(j : Z), (0%Z ≤ j ∧ j < i + 1%Z) ∧ nth (Z.to_nat j) a inhabitant = v3 else ∀(j : Z), 0%Z ≤ j ∧ j < i + 1%Z -> ¬ nth (Z.to_nat j) a inhabitant = v3)) ∧ (v = - 1%Z -> (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> ¬ appear_twice a v3 (i + 1%Z))) ∧ (v2 = - 1%Z -> (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> ¬ v3 = v -> ¬ appear_twice a v3 (i + 1%Z))) else ∀(o2 : bool), (if decide (v2 = - 1%Z) then o2 = (if decide (v = v1) then false else true) else o2 = false) -> (if decide (o2 = true) then (v1 = - 1%Z -> v = - 1%Z) ∧ (¬ v1 = - 1%Z -> appear_twice a v1 (i + 1%Z)) ∧ (¬ v = - 1%Z -> appear_twice a v (i + 1%Z) ∧ ¬ v = v1) ∧ (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> (if decide (nth (Z.to_nat v3) deja_vu1 inhabitant = true) then ∃(j : Z), (0%Z ≤ j ∧ j < i + 1%Z) ∧ nth (Z.to_nat j) a inhabitant = v3 else ∀(j : Z), 0%Z ≤ j ∧ j < i + 1%Z -> ¬ nth (Z.to_nat j) a inhabitant = v3)) ∧ (v1 = - 1%Z -> (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> ¬ appear_twice a v3 (i + 1%Z))) ∧ (v = - 1%Z -> (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> ¬ v3 = v1 -> ¬ appear_twice a v3 (i + 1%Z))) else (v1 = - 1%Z -> v2 = - 1%Z) ∧ (¬ v1 = - 1%Z -> appear_twice a v1 (i + 1%Z)) ∧ (¬ v2 = - 1%Z -> appear_twice a v2 (i + 1%Z) ∧ ¬ v2 = v1) ∧ (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> (if decide (nth (Z.to_nat v3) deja_vu1 inhabitant = true) then ∃(j : Z), (0%Z ≤ j ∧ j < i + 1%Z) ∧ nth (Z.to_nat j) a inhabitant = v3 else ∀(j : Z), 0%Z ≤ j ∧ j < i + 1%Z -> ¬ nth (Z.to_nat j) a inhabitant = v3)) ∧ (v1 = - 1%Z -> (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> ¬ appear_twice a v3 (i + 1%Z))) ∧ (v2 = - 1%Z -> (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> ¬ v3 = v1 -> ¬ appear_twice a v3 (i + 1%Z)))) else let o2 : bool := true in (0%Z ≤ v ∧ v < Z.of_nat (length deja_vu1)) ∧ (length (set_list deja_vu1 (Z.to_nat v) o2) = length deja_vu1 -> nth_i (set_list deja_vu1 (Z.to_nat v) o2) = fun_updt (nth_i deja_vu1) v o2 -> (v1 = - 1%Z -> v2 = - 1%Z) ∧ (¬ v1 = - 1%Z -> appear_twice a v1 (i + 1%Z)) ∧ (¬ v2 = - 1%Z -> appear_twice a v2 (i + 1%Z) ∧ ¬ v2 = v1) ∧ (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> (if decide (nth (Z.to_nat v3) (set_list deja_vu1 (Z.to_nat v) o2) inhabitant = true) then ∃(j : Z), (0%Z ≤ j ∧ j < i + 1%Z) ∧ nth (Z.to_nat j) a inhabitant = v3 else ∀(j : Z), 0%Z ≤ j ∧ j < i + 1%Z -> ¬ nth (Z.to_nat j) a inhabitant = v3)) ∧ (v1 = - 1%Z -> (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> ¬ appear_twice a v3 (i + 1%Z))) ∧ (v2 = - 1%Z -> (∀(v3 : Z), 0%Z ≤ v3 ∧ v3 < n -> ¬ v3 = v1 -> ¬ appear_twice a v3 (i + 1%Z))))))) ∧ ((v1 = - 1%Z -> v2 = - 1%Z) ∧ (¬ v1 = - 1%Z -> appear_twice a v1 (o1 + 1%Z)) ∧ (¬ v2 = - 1%Z -> appear_twice a v2 (o1 + 1%Z) ∧ ¬ v2 = v1) ∧ (∀(v : Z), 0%Z ≤ v ∧ v < n -> (if decide (nth (Z.to_nat v) deja_vu1 inhabitant = true) then ∃(j : Z), (0%Z ≤ j ∧ j < o1 + 1%Z) ∧ nth (Z.to_nat j) a inhabitant = v else ∀(j : Z), 0%Z ≤ j ∧ j < o1 + 1%Z -> ¬ nth (Z.to_nat j) a inhabitant = v)) ∧ (v1 = - 1%Z -> (∀(v : Z), 0%Z ≤ v ∧ v < n -> ¬ appear_twice a v (o1 + 1%Z))) ∧ (v2 = - 1%Z -> (∀(v : Z), 0%Z ≤ v ∧ v < n -> ¬ v = v1 -> ¬ appear_twice a v (o1 + 1%Z))) -> appear_twice a v1 (n + 2%Z) ∧ appear_twice a v2 (n + 2%Z) ∧ ¬ v1 = v2))) ∧ ¬ o1 + 1%Z < 0%Z)).
Admitted.
