Proof using lacimi smci si lmi.
intros.
find_copy_apply_lem_hyp logs_sorted_invariant.
pose proof entries_contiguous.
match goal with
| H : context [contiguous_range_exact_lo] |- _ =>
specialize (H net)
end.
concludes. simpl in *.
find_copy_apply_lem_hyp state_machine_correct_invariant.
unfold state_machine_correct in *. intuition.
unfold logs_sorted in *. intuition.
unfold key_in_output_list in *.
match goal with | H : exists _, _ |- _ => destruct H as [o] end.
unfold doGenericServer in *. break_let. simpl in *.
find_inversion. simpl in *.
pose proof Heqp as Heqp'.
eapply applyEntries_before in Heqp; eauto.
match goal with
| H : before_func _ _ ?l |- _=>
eapply before_func_prepend with
(l' := (rev (removeAfterIndex (log (nwState net h))
(lastApplied (nwState net h)))))
in H
end; eauto;
[|intros;
find_apply_lem_hyp In_rev;
apply Bool.not_true_iff_false;
intuition; unfold has_key in *;
break_match; break_if; repeat (do_bool; intuition); simpl in *;
eapply_prop_hyp client_cache_complete In; eauto;
break_exists; intuition; simpl in *;
subst;
match goal with
| Ha : context [applyEntries], Hg : getLastId _ _ = Some (?x, _) |- _ =>
eapply applyEntries_cache with (id' := x) in Ha
end; eauto; omega;
intuition; find_rewrite; repeat find_rewrite].
rewrite <- rev_app_distr in *.
eapply before_func_prefix; eauto.
use_applyEntries_spec. subst. simpl in *.
break_if.
- do_bool.
erewrite findGtIndex_removeAfterIndex_i_lt_i' in *; eauto.
match goal with
| |- context [applied_entries (update _ ?sigma ?h ?st)] =>
pose proof applied_entries_update sigma h st
end. conclude_using intuition.
intuition; simpl in *;
unfold raft_data in *; simpl in *; find_rewrite; auto using Prefix_refl.
unfold applied_entries in *.
break_exists. intuition. repeat find_rewrite.
eapply contiguous_sorted_subset_prefix; eauto using removeAfterIndex_contiguous, removeAfterIndex_sorted.
intros.
find_copy_apply_lem_hyp removeAfterIndex_In_le; eauto.
find_apply_lem_hyp removeAfterIndex_in.
apply removeAfterIndex_le_In; eauto; try omega.
find_copy_apply_lem_hyp commitIndex_lastApplied_match_invariant.
unfold commitIndex_lastApplied_match in *. simpl in *.
match goal with
| _ : ?x >= ?y |- _ =>
assert (y <= x) by omega
end.
eapply_prop_hyp le le; eauto. intuition.
- do_bool.
erewrite findGtIndex_removeAfterIndex_i'_le_i in *; eauto.
match goal with
| |- context [applied_entries (update _ ?sigma ?h ?st)] =>
pose proof applied_entries_update sigma h st
end. conclude_using intuition.
intuition; simpl in *;
unfold raft_data in *; simpl in *; find_rewrite; auto using Prefix_refl.
unfold applied_entries in *.
break_exists. intuition. repeat find_rewrite.
eapply contiguous_sorted_subset_prefix; eauto using removeAfterIndex_contiguous, removeAfterIndex_sorted.
intros.
find_copy_apply_lem_hyp removeAfterIndex_In_le; eauto.
find_apply_lem_hyp removeAfterIndex_in.
apply removeAfterIndex_le_In; eauto; try omega.
find_copy_apply_lem_hyp lastApplied_lastApplied_match_invariant.
unfold lastApplied_lastApplied_match in *. simpl in *.
match goal with
| _ : ?x >= ?y |- _ =>
assert (y <= x) by omega
end.
eapply_prop_hyp le le; eauto. intuition.
Qed.

(* Specifications: *)
Lemma output_implies_greatest :
forall failed net failed' net' o client id id',
raft_intermediate_reachable net ->
@step_failure _ _ failure_params (failed, net) (failed', net') o ->
key_in_output_trace client id o ->
id < id' ->
before_func (has_key client id) (has_key client id') (applied_entries (nwState net')).