(* week-03_the-exists-tactic.v *)
(* LPP 2024 - CS3234 2023-2024, Sem2 *)
(* Olivier Danvy <danvy@yale-nus.edu.sg> *)
(* Version of 01 Feb 2024 *)

(* ********** *)

(* Paraphernalia: *)

Require Import Arith.

(* ********** *)

Lemma proving_an_existential_example_0 :
  exists n : nat,
    n = 0.
Proof.
  exists 0.
  reflexivity.
Qed.

(* ********** *)

Lemma proving_an_existential_example_1 :
  forall n : nat,
  exists m : nat,
    S m = n + 1.
Proof.
  intros n.
  exists n.
  Search (_ + S _).
  Check (plus_n_Sm n 0).
  rewrite <- (plus_n_Sm n 0).
  Check Nat.add_0_r.
  rewrite -> (Nat.add_0_r n).
  reflexivity.
Qed.

(* ********** *)

Lemma proving_an_existential_example_2 :
  forall n : nat,
  exists f : nat -> nat,
    f n = n + 1.
Proof.
  intro n.
  exists S.
  rewrite <- (plus_n_Sm n 0).
  rewrite -> (Nat.add_0_r n).
  reflexivity.

  Restart.

  intro n.
  exists (fun n => S n).
  rewrite <- (plus_n_Sm n 0).
  rewrite -> (Nat.add_0_r n).
  reflexivity.

  Restart.

  intro n.
  exists (fun n => n + 1).
  reflexivity.
Qed.

Lemma proving_an_existential_example_3:
  forall n : nat,
  exists f : nat -> nat,
    f n = n + 2.
Proof.
  intro n.
  exists (fun n => n + 2).
  reflexivity.
  Qed.

(* ********** *)

(* end of week-03_the-exists-tactic.v *)
