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 euler_sieve_vcg.euler_sieve.ArithmeticResults.
Require Import euler_sieve_vcg.euler_sieve.DivisibilityResults.
Require Import euler_sieve_vcg.euler_sieve.EulerSieveSpec.
Open Scope Z_scope.
Axiom t : Type.
Axiom t_inhabited : Inhabited t.
Global Existing Instance t_inhabited.
Axiom t_countable : Countable t.
Global Existing Instance t_countable.
Axiom nexts : t -> list Z.
Axiom marked : t -> list bool.
Axiom max : t -> bv 63%N.
Axiom t'invariant : forall  (self : t), bv_signed (max self) < bv_signed int'63_max ∧ 3%Z ≤ bv_signed (max self) ∧ length (nexts self) = length (marked self) ∧ Z.of_nat (length (marked self)) = bv_signed (max self) + 1%Z ∧ inv_nexts (nexts self) (Z.of_nat (length (nexts self))) ∧ all_eliminated_marked (marked self) (nexts self) ∧ (∀(i : Z), 3%Z ≤ i ∧ i ≤ bv_signed (max self) -> ZEuclid.modulo i 2%Z = 0%Z -> nth (Z.to_nat i) (marked self) inhabitant = true) ∧ (∀(i : Z), 3%Z ≤ i ∧ i < bv_signed (max self) - 1%Z -> ZEuclid.modulo i 2%Z = 1%Z -> ZEuclid.modulo (nth (Z.to_nat i) (nexts self) inhabitant) 2%Z = 1%Z ∨ nth (Z.to_nat i) (nexts self) inhabitant = bv_signed (max self) + 1%Z) ∧ nth (Z.to_nat (bv_signed (max self))) (nexts self) inhabitant = bv_signed (max self) + 1%Z ∧ (ZEuclid.modulo (bv_signed (max self) - 1%Z) 2%Z = 0%Z -> nth (Z.to_nat (bv_signed (max self) - 1%Z)) (nexts self) inhabitant = bv_signed (max self)) ∧ (ZEuclid.modulo (bv_signed (max self) - 1%Z) 2%Z = 1%Z -> nth (Z.to_nat (bv_signed (max self) - 1%Z)) (nexts self) inhabitant = bv_signed (max self) + 1%Z).
Theorem remove_products'vc (n : bv 63%N) (t1 : t) (fact0 : 3%Z ≤ bv_signed n) (fact1 : bv_signed n ≤ bv_signed (max t1)) (fact2 : bv_signed n * bv_signed n ≤ bv_signed (max t1)) (fact3 : inv_remove_products (nexts t1) (marked t1) (bv_signed n)) (fact4 : previously_marked_multiples (marked t1) (bv_signed n)) (fact5 : only_multiples_marked (marked t1) (bv_signed n)) (fact6 : not_marked_impl_next_not_marked (marked t1) (nexts t1) (bv_signed n)) : let o1 : bv 63%N := max t1 in 2%Z ≤ bv_signed o1 -> (¬ bv_signed n = 0%Z ∧ int'63_in_bounds (Z.rem (bv_signed o1) (bv_signed n))) ∧ (∀(d : bv 63%N), bv_signed d = Z.rem (bv_signed o1) (bv_signed n) -> (let max1 : bv 63%N := max t1 in let marked_old : list bool := marked t1 in (∀(t2 : t), max t2 = max t1 -> (∀(p : bv 63%N) (x : Z), ((bv_signed n ≤ bv_signed p ∧ bv_signed p ≤ bv_signed max1) ∧ (3%Z ≤ bv_signed n ∧ bv_signed n ≤ bv_signed max1) ∧ ZEuclid.modulo (bv_signed p) 2%Z = 1%Z ∧ (bv_signed p ≤ x ∧ x < nth (Z.to_nat (bv_signed p)) (nexts t2) inhabitant) ∧ nth (Z.to_nat x) (nexts t2) inhabitant = nth (Z.to_nat (bv_signed p)) (nexts t2) inhabitant ∧ nth (Z.to_nat (bv_signed n * bv_signed n)) (marked t2) inhabitant = true) ∧ inv_remove_products (nexts t2) (marked t2) (bv_signed n) ∧ previously_marked_multiples (marked t2) (bv_signed n) ∧ ¬ nth (Z.to_nat (bv_signed p)) (marked t2) inhabitant = true ∧ is_copy (marked t2) marked_old ∧ all_eliminated_marked_partial marked_old (nexts t2) x ∧ not_marked_impl_next_not_marked marked_old (nexts t2) (bv_signed n) ∧ prime_multiples_marked marked_old (marked t2) (bv_signed n) (nth (Z.to_nat x) (nexts t2) inhabitant) ∧ not_marked_impl_next_not_marked_partial (marked t2) (nexts t2) (bv_signed n) (bv_signed p) ∧ only_multiples_marked (marked t2) (bv_signed n + 1%Z) -> ((3%Z ≤ bv_signed p ∧ bv_signed p ≤ bv_signed (max t2)) ∧ ZEuclid.modulo (bv_signed p) 2%Z = 1%Z) ∧ (∀(next : bv 63%N), (3%Z ≤ bv_signed next ∧ bv_signed next ≤ bv_signed (max t2) + 1%Z) ∧ bv_signed next = nth (Z.to_nat (bv_signed p)) (nexts t2) inhabitant ∧ (ZEuclid.modulo (bv_signed next) 2%Z = 1%Z ∨ bv_signed next = bv_signed (max t2) + 1%Z) -> (∀(o2 : bool), (if decide (0%Z ≤ bv_signed next) then let o3 : bv 63%N := max t2 in 2%Z ≤ bv_signed o3 ∧ o2 = (if decide (bv_signed next ≤ bv_signed o3) then true else false) else o2 = false) -> (if decide (o2 = true) then if decide (bv_signed next ≤ bv_signed d) then int'63_in_bounds (bv_signed n * bv_signed next) ∧ (∀(o3 : bv 63%N), bv_signed o3 = bv_signed n * bv_signed next -> ((0%Z ≤ bv_signed o3 ∧ bv_signed o3 ≤ bv_signed (max t2)) ∧ ZEuclid.modulo (bv_signed o3) 2%Z = 1%Z) ∧ (∀(t3 : t), nexts t3 = nexts t2 ∧ max t3 = max t2 -> marked t3 = set_list (marked t2) (Z.to_nat (bv_signed o3)) true -> ((0%Z ≤ bv_signed next ∧ bv_signed next ≤ bv_signed (max t3)) ∧ ZEuclid.modulo (bv_signed next) 2%Z = 1%Z) ∧ (if decide (nth (Z.to_nat (bv_signed next)) (marked t3) inhabitant = true) then ((3%Z ≤ bv_signed next ∧ bv_signed next ≤ bv_signed (max t3)) ∧ ZEuclid.modulo (bv_signed next) 2%Z = 1%Z) ∧ (∀(o4 : bv 63%N), (3%Z ≤ bv_signed o4 ∧ bv_signed o4 ≤ bv_signed (max t3) + 1%Z) ∧ bv_signed o4 = nth (Z.to_nat (bv_signed next)) (nexts t3) inhabitant ∧ (ZEuclid.modulo (bv_signed o4) 2%Z = 1%Z ∨ bv_signed o4 = bv_signed (max t3) + 1%Z) -> (((0%Z ≤ bv_signed p ∧ bv_signed p ≤ bv_signed (max t3)) ∧ bv_signed p < bv_signed o4 ∧ bv_signed o4 ≤ bv_signed (max t3) + 1%Z) ∧ ZEuclid.modulo (bv_signed p) 2%Z = 1%Z ∧ (∀(j : Z), bv_signed p < j ∧ j < bv_signed o4 -> nth (Z.to_nat j) (marked t3) inhabitant = true) ∧ ¬ nth (Z.to_nat (bv_signed p)) (marked t3) inhabitant = true ∧ (ZEuclid.modulo (bv_signed o4) 2%Z = 1%Z ∨ bv_signed o4 = bv_signed (max t3) + 1%Z)) ∧ (∀(t4 : t), marked t4 = marked t3 ∧ max t4 = max t3 -> nexts t4 = set_list (nexts t3) (Z.to_nat (bv_signed p)) (bv_signed o4) -> (let o5 : Z := bv_signed next in (0%Z ≤ bv_signed max1 - nth (Z.to_nat (bv_signed p)) (nexts t2) inhabitant ∧ bv_signed max1 - nth (Z.to_nat (bv_signed p)) (nexts t4) inhabitant < bv_signed max1 - nth (Z.to_nat (bv_signed p)) (nexts t2) inhabitant) ∧ ((bv_signed n ≤ bv_signed p ∧ bv_signed p ≤ bv_signed max1) ∧ (3%Z ≤ bv_signed n ∧ bv_signed n ≤ bv_signed max1) ∧ ZEuclid.modulo (bv_signed p) 2%Z = 1%Z ∧ (bv_signed p ≤ o5 ∧ o5 < nth (Z.to_nat (bv_signed p)) (nexts t4) inhabitant) ∧ nth (Z.to_nat o5) (nexts t4) inhabitant = nth (Z.to_nat (bv_signed p)) (nexts t4) inhabitant ∧ nth (Z.to_nat (bv_signed n * bv_signed n)) (marked t4) inhabitant = true) ∧ inv_remove_products (nexts t4) (marked t4) (bv_signed n) ∧ previously_marked_multiples (marked t4) (bv_signed n) ∧ ¬ nth (Z.to_nat (bv_signed p)) (marked t4) inhabitant = true ∧ is_copy (marked t4) marked_old ∧ all_eliminated_marked_partial marked_old (nexts t4) o5 ∧ not_marked_impl_next_not_marked marked_old (nexts t4) (bv_signed n) ∧ prime_multiples_marked marked_old (marked t4) (bv_signed n) (nth (Z.to_nat o5) (nexts t4) inhabitant) ∧ not_marked_impl_next_not_marked_partial (marked t4) (nexts t4) (bv_signed n) (bv_signed p) ∧ only_multiples_marked (marked t4) (bv_signed n + 1%Z)))) else let o4 : Z := bv_signed next in (0%Z ≤ bv_signed max1 - nth (Z.to_nat (bv_signed p)) (nexts t2) inhabitant ∧ bv_signed max1 - nth (Z.to_nat (bv_signed next)) (nexts t3) inhabitant < bv_signed max1 - nth (Z.to_nat (bv_signed p)) (nexts t2) inhabitant) ∧ ((bv_signed n ≤ bv_signed next ∧ bv_signed next ≤ bv_signed max1) ∧ (3%Z ≤ bv_signed n ∧ bv_signed n ≤ bv_signed max1) ∧ ZEuclid.modulo (bv_signed next) 2%Z = 1%Z ∧ (bv_signed next ≤ o4 ∧ o4 < nth (Z.to_nat (bv_signed next)) (nexts t3) inhabitant) ∧ nth (Z.to_nat o4) (nexts t3) inhabitant = nth (Z.to_nat (bv_signed next)) (nexts t3) inhabitant ∧ nth (Z.to_nat (bv_signed n * bv_signed n)) (marked t3) inhabitant = true) ∧ inv_remove_products (nexts t3) (marked t3) (bv_signed n) ∧ previously_marked_multiples (marked t3) (bv_signed n) ∧ ¬ nth (Z.to_nat (bv_signed next)) (marked t3) inhabitant = true ∧ is_copy (marked t3) marked_old ∧ all_eliminated_marked_partial marked_old (nexts t3) o4 ∧ not_marked_impl_next_not_marked marked_old (nexts t3) (bv_signed n) ∧ prime_multiples_marked marked_old (marked t3) (bv_signed n) (nth (Z.to_nat o4) (nexts t3) inhabitant) ∧ not_marked_impl_next_not_marked_partial (marked t3) (nexts t3) (bv_signed n) (bv_signed next) ∧ only_multiples_marked (marked t3) (bv_signed n + 1%Z)))) else inv_remove_products (nexts t2) (marked t2) (bv_signed n) ∧ not_marked_impl_next_not_marked (marked t2) (nexts t2) (nth (Z.to_nat (bv_signed n)) (nexts t2) inhabitant) ∧ is_copy (marked t2) marked_old ∧ previously_marked_multiples (marked t2) (bv_signed n) ∧ prime_multiples_marked marked_old (marked t2) (bv_signed n) (Z.of_nat (length (marked t2))) ∧ only_multiples_marked (marked t2) (bv_signed n + 1%Z) else inv_remove_products (nexts t2) (marked t2) (bv_signed n) ∧ not_marked_impl_next_not_marked (marked t2) (nexts t2) (nth (Z.to_nat (bv_signed n)) (nexts t2) inhabitant) ∧ is_copy (marked t2) marked_old ∧ previously_marked_multiples (marked t2) (bv_signed n) ∧ prime_multiples_marked marked_old (marked t2) (bv_signed n) (Z.of_nat (length (marked t2))) ∧ only_multiples_marked (marked t2) (bv_signed n + 1%Z)))))) ∧ int'63_in_bounds (bv_signed n * bv_signed n) ∧ (∀(o2 : bv 63%N), bv_signed o2 = bv_signed n * bv_signed n -> ((0%Z ≤ bv_signed o2 ∧ bv_signed o2 ≤ bv_signed (max t1)) ∧ ZEuclid.modulo (bv_signed o2) 2%Z = 1%Z) ∧ (∀(t2 : t), nexts t2 = nexts t1 ∧ max t2 = max t1 -> marked t2 = set_list (marked t1) (Z.to_nat (bv_signed o2)) true -> (let o3 : Z := bv_signed n in (((bv_signed n ≤ bv_signed n ∧ bv_signed n ≤ bv_signed max1) ∧ (3%Z ≤ bv_signed n ∧ bv_signed n ≤ bv_signed max1) ∧ ZEuclid.modulo (bv_signed n) 2%Z = 1%Z ∧ (bv_signed n ≤ o3 ∧ o3 < nth (Z.to_nat (bv_signed n)) (nexts t2) inhabitant) ∧ nth (Z.to_nat o3) (nexts t2) inhabitant = nth (Z.to_nat (bv_signed n)) (nexts t2) inhabitant ∧ nth (Z.to_nat (bv_signed n * bv_signed n)) (marked t2) inhabitant = true) ∧ inv_remove_products (nexts t2) (marked t2) (bv_signed n) ∧ previously_marked_multiples (marked t2) (bv_signed n) ∧ ¬ nth (Z.to_nat (bv_signed n)) (marked t2) inhabitant = true ∧ is_copy (marked t2) marked_old ∧ all_eliminated_marked_partial marked_old (nexts t2) o3 ∧ not_marked_impl_next_not_marked marked_old (nexts t2) (bv_signed n) ∧ prime_multiples_marked marked_old (marked t2) (bv_signed n) (nth (Z.to_nat o3) (nexts t2) inhabitant) ∧ not_marked_impl_next_not_marked_partial (marked t2) (nexts t2) (bv_signed n) (bv_signed n) ∧ only_multiples_marked (marked t2) (bv_signed n + 1%Z)) ∧ (∀(t3 : t), max t3 = max t2 -> inv_remove_products (nexts t3) (marked t3) (bv_signed n) ∧ not_marked_impl_next_not_marked (marked t3) (nexts t3) (nth (Z.to_nat (bv_signed n)) (nexts t3) inhabitant) ∧ is_copy (marked t3) marked_old ∧ previously_marked_multiples (marked t3) (bv_signed n) ∧ prime_multiples_marked marked_old (marked t3) (bv_signed n) (Z.of_nat (length (marked t3))) ∧ only_multiples_marked (marked t3) (bv_signed n + 1%Z) -> inv_remove_products (nexts t3) (marked t3) (bv_signed n) ∧ not_marked_impl_next_not_marked (marked t3) (nexts t3) (nth (Z.to_nat (bv_signed n)) (nexts t3) inhabitant) ∧ previously_marked_multiples (marked t3) (nth (Z.to_nat (bv_signed n)) (nexts t3) inhabitant) ∧ only_multiples_marked (marked t3) (nth (Z.to_nat (bv_signed n)) (nexts t3) inhabitant))))))).
Admitted.
