Definition even (n : nat) := exists m, n = 2 * m.

Definition odd (n : nat) := exists m, n = 2 * m + 1.

(* Every natural number is either even or odd. *)
Theorem even_or_odd : forall n : nat, even n \/ odd n.
Proof.
  induction n as [|k]. (* by induction on the number n *)
  - (* base case: 0 is even or odd *)
    left. (* I will show that 0 is even *)
    unfold even. (* What does that mean? *)
    exists 0. (* 0 is 2 * 0. *)
    auto.
  - (* inductive case: assume k is even or odd, prove that k + 1 ("S k") is even or odd *)
    destruct IHk as [Heven | Hodd]. (* Is k even, or odd? *)
    + (* k is even *)
      right. (* so I will show that k + 1 is odd *)
      unfold even in Heven. unfold odd. (* What does that mean? *)
      destruct Heven as [j Heven]. (* k is 2 * something, so call that something "j" *)
      exists j. (* then k + 1 is 2j + 1 *)
      rewrite Heven. simpl. rewrite <- plus_n_Sm. auto. (* some simple arithmetic, still takes a few steps in Coq *)
    + (* k is odd *)
      left. (* so I will show that k + 1 is even *)
      unfold odd in Hodd. unfold even. (* What does that mean? *)
      destruct Hodd as [j Hodd]. (* k is 2 * something + 1, so call that something "j" *)
      exists (j + 1). (* then k + 1 is 2(j + 1) *)
      rewrite Hodd. simpl. rewrite <- !plus_n_Sm. rewrite <- !plus_n_O. rewrite <- !plus_n_Sm. auto. (* more arithmetic *)
Qed.
