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  *)

Theorem bin_to_nat_preserves_incr : forall b : bin,
bin_to_nat (incr b) = 1 + bin_to_nat b.