(* This file is generated by Why3's Coq 8.4 driver *)
(* Beware! Only edit allowed sections below    *)
Require Import BuiltIn.
Require BuiltIn.
Require int.Int.
Require int.Abs.

(* Why3 assumption *)
Definition unit := unit.

(* Why3 assumption *)
Inductive ref (a:Type) {a_WT:WhyType a} :=
  | mk_ref : a -> ref a.
Axiom ref_WhyType : forall (a:Type) {a_WT:WhyType a}, WhyType (ref a).
Existing Instance ref_WhyType.
Implicit Arguments mk_ref [[a] [a_WT]].

(* Why3 assumption *)
Definition contents {a:Type} {a_WT:WhyType a} (v:(@ref a a_WT)): a :=
  match v with
  | (mk_ref x) => x
  end.

Parameter x2: Z.

Parameter y2: Z.

Axiom first_octant : (0%Z <= y2)%Z /\ (y2 <= x2)%Z.

(* Why3 assumption *)
Definition best (x:Z) (y:Z): Prop := forall (y':Z),
  ((Zabs ((x2 * y)%Z - (x * y2)%Z)%Z) <= (Zabs ((x2 * y')%Z - (x * y2)%Z)%Z))%Z.

(* The following short and nice proof is due to Laurent Théry *)
Require Import Psatz.

(* Why3 goal *)
Theorem closest : forall (a:Z) (b:Z) (c:Z),
  ((Zabs (((2%Z * a)%Z * b)%Z - (2%Z * c)%Z)%Z) <= a)%Z -> forall (b':Z),
  ((Zabs ((a * b)%Z - c)%Z) <= (Zabs ((a * b')%Z - c)%Z))%Z.
intros a b c H b'.
assert (H1:  b = b' \/ b <> b') by nia.
nia.
Qed.

