Fixpoint ptree_cmp {T : Type} (p1 p2: Maps.PTree.tree T)
(e : T -> T -> bool) :=
match p1, p2 with
| Maps.PTree.Leaf, Maps.PTree.Leaf => true
| Maps.PTree.Node l1 i1 r1, Maps.PTree.Node l2 i2 r2 =>
match i1, i2 with
| Some v1, Some v2 => andb (e v1 v2)
(andb (ptree_cmp l1 l2 e)
(ptree_cmp r1 r2 e))
| None, None => (andb (ptree_cmp l1 l2 e)
(ptree_cmp r1 r2 e))
| _, _ => false
end
| _, _ => false
end.
Definition const_beq a b :=
match a, b with
| fN c1, fN c2 => beq_nat c1 c2
| fZ c1, fZ c2 => Zbool.Zeq_bool c1 c2
| fPos c1, fPos c2 =>  BinPos.Pos.eqb c1 c2
| fCtype c1, fCtype c2 => expr.eqb_type c1 c2
| fCexpr c1, fCexpr c2 => expr_beq c1 c2
| fenv c1, fenv c2 => ptree_cmp c1 c2 expr.eqb_type
| fllrr c1, fllrr c2 => match c1, c2 with | efield_lemmas.LLLL, efield_lemmas.LLLL | efield_lemmas.RRRR, efield_lemmas.RRRR => true | _, _ => false end
| _, _ => false
end.
Instance const_rel_dec : RelDec (@eq const) := { rel_dec := const_beq }.
Definition beq_z_true : forall a b, Zbool.Zeq_bool a b = true -> a = b.
Hint Resolve beq_nat_true : expr_beq.
Hint Resolve beq_z_true : expr_beq.

Lemma const_beq_sound : forall a b, const_beq a b = true -> a = b.