(** Bijections between [nat * nat] and [nat] *)

(** Cantor pairing [to_nat] *)

Definition to_nat '(x, y) : nat :=
  y + (nat_rec _ 0 (fun i m => (S i) + m) (y + x)).(** Cantor pairing inverse [of_nat] *)

Definition of_nat (n : nat) : nat * nat :=
  nat_rec _ (0, 0) (fun _ '(x, y) =>
    match x with | S x => (x, S y) | _ => (S y, 0) end) n.

(* Specifications: *)
Lemma cancel_of_to p : of_nat (to_nat p) = p.