Skip to content

Instantly share code, notes, and snippets.

@MiyamonY
Created June 22, 2014 12:25
Show Gist options
  • Save MiyamonY/9e89b8166a4d6f51fea3 to your computer and use it in GitHub Desktop.
Save MiyamonY/9e89b8166a4d6f51fea3 to your computer and use it in GitHub Desktop.
define plus using nat_rec
Definition Plus: nat -> nat -> nat.
intros x.
elim x using nat_rec.
- intros y. apply y.
- intros x' plus_x' y. apply (S (plus_x' y)).
Defined.
Print Plus.
(* Plus = *)
(* fun x : nat => *)
(* nat_rec (fun _ : nat => nat -> nat) (fun y : nat => y) *)
(* (fun (_ : nat) (plus_x' : nat -> nat) (y : nat) => S (plus_x' y)) x *)
(* : nat -> nat -> nat *)
Print nat_rec.
(* nat_rec = *)
(* fun P : nat -> Set => nat_rect P *)
(* : forall P : nat -> Set, *)
(* P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n *)
Eval compute in Plus 0 1.
Eval compute in Plus 1 1.
Eval compute in Plus 2 0.
Eval compute in Plus 10 3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment