Inductive bin : Type :=
| Z
| B0 (n : bin)
| B1 (n : bin).
Fixpoint incr (m:bin) : bin :=
match m with
| Z => B1 Z
| B0 m' => B1 m'
| B1 m' => B0 (incr m')
end.
Fixpoint bin_to_nat (m:bin) : nat :=
match m with
| Z => O
| B0 m' => 2 * (bin_to_nat m')
| B1 m' => 1 + 2 * (bin_to_nat m')
end.
(*  Prove that the following diagram commutes: incr bin ----------------------> bin |                           | bin_to_nat |                           |  bin_to_nat |                           | v                           v nat ----------------------> nat  *)
Fixpoint nat_to_bin (n:nat) : bin :=
match n with
| O => Z
| S n' => incr (nat_to_bin n')
end.
Fixpoint double (n:nat) :=
match n with
| O => O
| S n' => S (S (double n'))
end.

Lemma double_plus : forall n, double n = n + n .