Module Argument.
Fixpoint term_to_tree (t: mset_term) : tree :=
match t with
| mset_term_zero => node 0 leaf leaf
| mset_term_var x => node 1 (node x leaf leaf) leaf
| mset_term_plus t u => node 2 (term_to_tree t) (term_to_tree u)
| mset_term_h t => node 3 (term_to_tree t) leaf
end.
Fixpoint tree_to_term (t: tree) : mset_term :=
match t with
| node 0 leaf leaf => mset_term_zero
| node 1 (node x leaf leaf) leaf => mset_term_var x
| node 2 t u => mset_term_plus (tree_to_term t) (tree_to_term u)
| node 3 t leaf => mset_term_h (tree_to_term t)
| _ => mset_term_zero
end.
Definition term_to_nat (t: mset_term) : nat :=
tree_to_nat (term_to_tree t).
Definition nat_to_term (n: nat) : mset_term :=
tree_to_term (nat_to_tree n).

Lemma nat_term_cancel {t} : nat_to_term (term_to_nat t) = t.