Skip to content

Instantly share code, notes, and snippets.

@endobson
Created April 30, 2012 00:46
Show Gist options
  • Save endobson/2554495 to your computer and use it in GitHub Desktop.
Save endobson/2554495 to your computer and use it in GitHub Desktop.
Tree Identities in Coq
Require Import List.
Inductive btree : Set :=
| bleaf : btree
| bbranch : btree -> btree -> btree.
Fixpoint btree_id(x : btree) : btree :=
match x with
| bleaf => bleaf
| bbranch l r => bbranch (btree_id l) (btree_id r)
end.
Theorem btree_id_is_id: forall b, btree_id(b) = b.
Proof.
intros.
induction b.
simpl.
reflexivity.
simpl.
f_equal.
assumption.
assumption.
Qed.
Inductive mtree : Set :=
| mleaf : mtree
| mbranch : list mtree -> mtree.
Fixpoint mtree_id(x : mtree) : mtree :=
match x with
| mleaf => mleaf
| mbranch xs => mbranch (map mtree_id xs)
end.
Theorem mtree_id_is_id: forall m, mtree_id(m) = m.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment