induction n2; induction t2; intuition.
inversion H2; clear H2; subst.
inversion H1; clear H1; subst.
econstructor.
inversion H1; clear H1; subst.
inversion H; clear H; subst.
econstructor.
congruence.
congruence.
econstructor.
inversion H2; clear H2; subst.
inversion H1; clear H1; subst.
inversion H; clear H; subst.
simpl in *.
rewrite mult_0_r in *.
simpl in *.
assert (depth0  >= (max (datDepth t2_1) (datDepth t2_2))).
omega.
econstructor.
eapply IHt2_1.
eauto.
omega.
eauto.
eauto.
rewrite mult_0_r; simpl.
eapply Max.max_lub_l.
eauto.
trivial.
trivial.
trivial.
trivial.
eapply IHt2_2.
eauto.
omega.
eauto.
trivial.
rewrite mult_0_r; simpl.
eapply Max.max_lub_r.
eauto.
trivial.
trivial.
trivial.
trivial.
inversion H2; clear H2; subst.
inversion H1; clear H1; subst.
econstructor.
inversion H1; clear H1; subst.
inversion H; clear H; subst.
econstructor.
congruence.
congruence.
inversion H; clear H; subst.
congruence.
omega.
rewrite mult_comm in H3.
simpl in *.
eapply IHn2.
eauto.
omega.
eauto.
eapply H4; eauto.
remember (n2 * n1)%nat as x.
omega.
eapply le_trans.
2:{
eapply H3.
}
rewrite plus_0_r.
rewrite plus_comm.
eapply plus_le_compat.
eauto.
rewrite mult_comm.
trivial.
trivial.
trivial.
trivial.
inversion H2; clear H2; subst.
inversion H1; clear H1; subst.
inversion H; clear H; subst.
simpl in *.
econstructor.
eapply IHt2_1.
eauto.
trivial.
eauto.
trivial.
eapply le_trans.
eapply plus_le_compat.
eapply le_refl.
eapply (Max.max_lub_l (datDepth t2_1) (datDepth t2_2)).
eapply le_refl.
omega.
trivial.
trivial.
trivial.
eapply IHt2_2.
eauto.
trivial.
eauto.
trivial.
eapply le_trans.
eapply plus_le_compat.
eapply le_refl.
eapply (Max.max_lub_r (datDepth t2_1) (datDepth t2_2)).
eapply le_refl.
omega.
trivial.
trivial.
trivial.
Qed.

Lemma dat_better_repeat_sqrt : forall (A : Set) (c : Comp A)(P : A -> bool)(n : nat) (t1 t2 : DistApproxTree A),
(exists a, In a (filter P (getSupport c))) ->
dat_correct_repeat c P n t1 ->
dat_correct_repeat2 c P (Nat.sqrt (div2 n)) t2 ->
well_formed_comp c ->
dat_better t1 t2.