(* A set of tactics to count the number of exists in the goal. This requires
   crazy tricks, but surprisingly, works. *)
Local Ltac count_exists_loop H k :=
  let ty := type of H in
  match ty with
  | @ex _ _ => count_exists_loop_aux H k
  | @sig _ _ => count_exists_loop_aux H k
  | @sigT _ _ => count_exists_loop_aux H k
  | _ => k O
  end

with count_exists_loop_aux H k :=
  let x := fresh in
  destruct H as [x H];
  count_exists_loop H ltac:(fun res => k (S res)).

(* Specifications: *)
Local Lemma count_exists_helper : forall G, (G -> True) -> nat -> nat.