(* Complete, standalone examples for Lumen Math. Coq 8.20 / Rocq syntax. *)
Inductive Vec (A : Type) : nat -> Type :=
| vnil : Vec A 0
| vcons : forall n, A -> Vec A n -> Vec A (S n).
Arguments vnil {A}.
Arguments vcons {A n} _ _.

Definition two : Vec nat 2 := vcons 7 (vcons 9 vnil).
Definition one : Vec nat 1 := vcons 5 vnil.

Fixpoint append {A : Type} {m : nat} (xs : Vec A m)
    {n : nat} (ys : Vec A n) {struct xs} : Vec A (m + n) :=
  match xs in Vec _ k return Vec A (k + n) with
  | vnil => ys
  | vcons x rest => vcons x (append rest ys)
  end.

Example append_two_one : append two one = vcons 7 (vcons 9 (vcons 5 vnil)).
Proof. reflexivity. Qed.

Fail Definition too_short : Vec nat 2 := append two one.
Definition right_length : Vec nat (1 + 2) := append two one.

Definition head {A : Type} {n : nat} (xs : Vec A (S n)) : A :=
  match xs in Vec _ k return
    match k with 0 => unit | S _ => A end
  with
  | vnil => tt
  | vcons x _ => x
  end.
Example head_two : head two = 7.
Proof. reflexivity. Qed.
Fail Definition head_empty := @head nat 0 (@vnil nat).

Definition zero_left (n : nat) : 0 + n = n := eq_refl.
Fail Definition zero_right_refl (n : nat) : n + 0 = n := eq_refl.

Fixpoint right_zero (n : nat) : n + 0 = n :=
  match n as k return k + 0 = k with
  | 0 => eq_refl
  | S k => f_equal S (right_zero k)
  end.

Fail Definition bare_step (k : nat) (IH : k + 0 = k) :
    S k + 0 = S k := IH.
Fail Fixpoint cyclic_zero (n : nat) : n + 0 = n :=
  match n as k return k + 0 = k with
  | 0 => eq_refl
  | S k => cyclic_zero (S k)
  end.

Theorem right_zero_tactic : forall n : nat, n + 0 = n.
Proof.
  intro n. induction n as [| k IH].
  - reflexivity.
  - simpl. rewrite IH. reflexivity.
Qed.

Definition castVec {A : Type} {m n : nat}
    (p : m = n) (xs : Vec A m) : Vec A n :=
  match p in _ = k return Vec A k with
  | eq_refl => xs
  end.

Fail Definition append_empty_uncast {A : Type} {m : nat}
    (xs : Vec A m) : Vec A m := append xs vnil.

Definition append_empty {A : Type} {m : nat}
    (xs : Vec A m) : Vec A m :=
  castVec (right_zero m) (append xs vnil).

Lemma castVec_cons {A : Type} {m n : nat} (p : m = n)
    (x : A) (xs : Vec A m) :
  castVec (f_equal S p) (vcons x xs) = vcons x (castVec p xs).
Proof. destruct p. reflexivity. Qed.

Theorem append_empty_same {A : Type} {m : nat} (xs : Vec A m) :
  append_empty xs = xs.
Proof.
  unfold append_empty. induction xs as [| k x rest IH].
  - reflexivity.
  - cbn. rewrite castVec_cons. rewrite IH. reflexivity.
Qed.

Fail Fixpoint fake_proof (n : nat) : False := fake_proof n.
Fail Inductive Bad : Type := wrap : (Bad -> False) -> Bad.
Fail Definition extract_exists (P : nat -> Prop)
    (h : exists n, P n) : nat :=
  match h with ex_intro _ n _ => n end.

Definition extract_pair (P : nat -> Prop)
    (h : {n : nat | P n}) : nat := proj1_sig h.
Print Assumptions append_empty_same.
