Definition inter' (s1 s2: tree) : tree :=
   match compare_height s1 s1 s2 s2 with
      | Lt => filter' (fun k => member k s2) s1
      | Gt => filter' (fun k => member k s1) s2
      | Eq => linear_inter s1 s2
    end.

Lemma inter_valid: forall s1 s2, valid s1 -> valid s2 -> valid (inter' s1 s2).