Skip to content

Instantly share code, notes, and snippets.

@gallais
Created November 13, 2016 17:47
Show Gist options
  • Save gallais/cf3c3aa240518e9822e33e40804fbd08 to your computer and use it in GitHub Desktop.
Save gallais/cf3c3aa240518e9822e33e40804fbd08 to your computer and use it in GitHub Desktop.
Fibonacci cooked 2 ways
Require Import NArith.
Fixpoint fac_v1 (n : nat) : nat :=
match n with
| 0 => 1
| S n' => n * (fac_v1 n')
end.
Fixpoint visit_fac_v2 (n a : nat) : nat :=
match n with
| 0 => a
| S n' => visit_fac_v2 n' (n * a)
end.
Definition fac_v2 (n : nat) : nat :=
visit_fac_v2 n 1.
Require Import ArithRing.
Theorem general_equivalence_of_fac_v1_and_fac_v2 :
forall n a : nat,
a * fac_v1 n = visit_fac_v2 n a.
Proof.
intros n; induction n; intro a.
- simpl ; ring.
- simpl ; rewrite <- IHn ; ring.
Qed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment