induction ls1; intuition; simpl in *.
inversion H; clear H; subst.
f_equal.
eapply IHls1; eauto.
eapply removeFirst_NoDup; eauto.
intuition.
destruct (eqd a0 a); subst; intuition.
eapply removeFirst_in.
eapply H1.
intuition.
intuition.
Qed.

(* Specifications: *)
Lemma fold_add_matchOrder : forall (A : Set)(ls : list A)(f : A -> Rat) n init1 init2,
init1 == init2 ->
NoDup ls ->
(forall a, In a ls -> (~In a (firstn n ls)) -> (f a) == 0) ->
fold_left (fun r a => r + (f a)) (firstn n ls) init1 == fold_left (fun r a => r + (f a)) ls init2.