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

Axiom mod_div_unique : forall (x:Z) (y:Z) (q:Z) (r:Z), ((0%Z <= x)%Z /\
  ((0%Z < y)%Z /\ ((x = ((q * y)%Z + r)%Z) /\ ((0%Z <= r)%Z /\
  (r < y)%Z)))) -> ((q = (ZOdiv x y)) /\ (r = (ZOmod x y))).

Axiom mod_succ_1 : forall (x:Z) (y:Z), ((0%Z <= x)%Z /\ (0%Z < y)%Z) ->
  ((~ ((ZOmod (x + 1%Z)%Z y) = 0%Z)) ->
  ((ZOmod (x + 1%Z)%Z y) = ((ZOmod x y) + 1%Z)%Z)).

Axiom mod_succ_2 : forall (x:Z) (y:Z), ((0%Z <= x)%Z /\ (0%Z < y)%Z) ->
  (((ZOmod (x + 1%Z)%Z y) = 0%Z) -> ((ZOmod x y) = (y - 1%Z)%Z)).

Axiom div_succ_1 : forall (x:Z) (y:Z), ((0%Z <= x)%Z /\ (0%Z < y)%Z) ->
  (((ZOmod (x + 1%Z)%Z y) = 0%Z) ->
  ((ZOdiv (x + 1%Z)%Z y) = ((ZOdiv x y) + 1%Z)%Z)).

Axiom div_succ_2 : forall (x:Z) (y:Z), ((0%Z <= x)%Z /\ (0%Z < y)%Z) ->
  ((~ ((ZOmod (x + 1%Z)%Z y) = 0%Z)) ->
  ((ZOdiv (x + 1%Z)%Z y) = (ZOdiv x y))).

Axiom mod2_mul2 : forall (x:Z), ((ZOmod (2%Z * x)%Z 2%Z) = 0%Z).

Axiom mod2_mul2_aux : forall (x:Z) (y:Z),
  ((ZOmod (y * (2%Z * x)%Z)%Z 2%Z) = 0%Z).

Axiom mod2_mul2_aux2 : forall (x:Z) (y:Z) (z:Z) (t:Z),
  ((ZOmod ((y * (2%Z * x)%Z)%Z + (z * (2%Z * t)%Z)%Z)%Z 2%Z) = 0%Z).

Axiom div2_mul2 : forall (x:Z), ((ZOdiv (2%Z * x)%Z 2%Z) = x).

Axiom div2_mul2_aux : forall (x:Z) (y:Z),
  ((ZOdiv (y * (2%Z * x)%Z)%Z 2%Z) = (y * x)%Z).

Axiom div2_add : forall (x:Z) (y:Z), (((ZOmod x 2%Z) = 0%Z) /\
  ((ZOmod y 2%Z) = 0%Z)) ->
  ((ZOdiv (x + y)%Z 2%Z) = ((ZOdiv x 2%Z) + (ZOdiv y 2%Z))%Z).

Axiom div2_sub : forall (x:Z) (y:Z), (((ZOmod x 2%Z) = 0%Z) /\
  ((ZOmod y 2%Z) = 0%Z)) ->
  ((ZOdiv (x - y)%Z 2%Z) = ((ZOdiv x 2%Z) - (ZOdiv y 2%Z))%Z).

(* Why3 goal *)
Theorem tr_mod_2 : forall (n:Z), (0%Z <= n)%Z ->
  ((ZOmod (n * (n + 1%Z)%Z)%Z 2%Z) = 0%Z).
(* Why3 intros n h1. *)
intros n Hn.
destruct (Div2.div2 n) as (x,[h1|h2]).
rewrite h1.
replace (2 * x * (2 * x + 1))%Z with 
   (2 * (x * (2 * x + 1)))%Z by ring.
apply mod2_mul2.
rewrite h2.
replace ((2 * x + 1) * (2 * x + 1 + 1))%Z with 
    (2* ((2 * x + 1) * (x + 1)))%Z by ring.
apply mod2_mul2.
Qed.


