Proof using.
unfold handleAppendEntries, haveNewEntries.
intros.
break_if; try find_inversion.
break_if.
- break_if; find_inversion; simpl;
repeat (do_bool; repeat break_and).
+ find_apply_lem_hyp not_empty_true_elim.
pose proof maxIndex_non_empty es ltac:(auto).
break_exists_exists. intuition.
+ break_or_hyp.
* find_apply_lem_hyp not_empty_false_elim. congruence.
* break_match; try discriminate.
do_bool. rewrite advanceCurrentTerm_log.
find_apply_lem_hyp findAtIndex_elim. break_and.
pose proof maxIndex_non_empty es ltac:(auto).
break_exists_name e'. break_and.
match goal with
| [ H : forall _ _ _, In _ _ -> _ |- _ ] =>
specialize (H e' e e')
end.
repeat find_rewrite. repeat concludes. intuition.
assert (e = e').
{ eapply uniqueIndices_elim_eq; eauto.
auto using sorted_uniqueIndices.
}
subst. eauto.
- break_match; try find_inversion.
break_if; try find_inversion.
break_if; find_inversion; simpl;
repeat (do_bool; repeat break_and).
+ find_apply_lem_hyp not_empty_true_elim.
pose proof maxIndex_non_empty es ltac:(auto).
break_exists_exists. intuition.
+ break_or_hyp.
* find_apply_lem_hyp not_empty_false_elim. congruence.
* break_match; try discriminate.
do_bool. rewrite advanceCurrentTerm_log.
find_apply_lem_hyp findAtIndex_elim. break_and.
pose proof maxIndex_non_empty es ltac:(auto).
break_exists_name e'. break_and.
match goal with
| [ H : forall _ _ _, In _ _ -> _ |- _ ] =>
specialize (H e' e0 e')
end.
repeat find_rewrite. repeat concludes. intuition.
assert (e0 = e').
{ eapply uniqueIndices_elim_eq; eauto.
auto using sorted_uniqueIndices.
}
subst. eauto.
Qed.

(* Specifications: *)
Lemma handleAppendEntries_success_term :
forall h st t n pli plt es ci st' t',
handleAppendEntries h st t n pli plt es ci = (st', AppendEntriesReply t' es true) ->
currentTerm st' = t.