Definition  binary_operation_to_comparison (op: Cop.binary_operation) :=
match op with
| Cop.Oeq => Some (@eq Z)
| Cop.One => Some Zne
| Cop.Olt => Some Z.lt
| Cop.Ole => Some Z.le
| Cop.Ogt => Some Z.gt
| Cop.Oge => Some Z.ge
| _ => None
end.
(* Lemma typed_true_binop_int: forall op op' e1 e2 Espec  {cs: compspecs} Delta P Q R c Post, binary_operation_to_comparison op = Some op' -> typeof e1 = tint -> typeof e2 = tint -> (PROPx P (LOCALx (tc_env Delta :: Q) (SEPx R))) |--  tc_expr Delta e1 -> (PROPx P (LOCALx (tc_env Delta :: Q) (SEPx R))) |-- tc_expr Delta e2 -> @semax cs Espec Delta (PROPx P (LOCALx (`op' (`force_signed_int (eval_expr e1)) (`force_signed_int (eval_expr e2)) :: Q) (SEPx R))) c Post -> @semax cs Espec Delta (PROPx P (LOCALx (`(typed_true (typeof (Ebinop op e1 e2 tint))) (eval_expr (Ebinop op e1 e2 tint)) :: Q) (SEPx R))) c Post. *)
Definition  binary_operation_to_opp_comparison (op: Cop.binary_operation) :=
match op with
| Cop.Oeq => Some Zne
| Cop.One => Some (@eq Z)
| Cop.Olt => Some Z.ge
| Cop.Ole => Some Z.gt
| Cop.Ogt => Some Z.le
| Cop.Oge => Some Z.lt
| _ => None
end.
(* Lemma typed_false_binop_int: forall op op' e1 e2 Espec  {cs: compspecs} Delta P Q R c Post, binary_operation_to_opp_comparison op = Some op' -> typeof e1 = tint -> typeof e2 = tint -> (PROPx P (LOCALx (tc_environ Delta :: Q) (SEPx R))) |-- (tc_expr Delta e1) -> (PROPx P (LOCALx (tc_environ Delta :: Q) (SEPx R))) |-- (tc_expr Delta e2) -> @semax cs Espec Delta (PROPx P (LOCALx (`op' (`force_signed_int (eval_expr e1)) (`force_signed_int (eval_expr e2)) :: Q) (SEPx R))) c Post -> @semax cs Espec Delta (PROPx P (LOCALx (`(typed_false (typeof (Ebinop op e1 e2 tint))) (eval_expr (Ebinop op e1 e2 tint)) :: Q) (SEPx R))) c Post. *)

Lemma local_entail_at:
forall n S T (H: local (locald_denote S) |-- local (locald_denote T))
P Q R,
nth_error Q n = Some S ->
PROPx P (LOCALx Q (SEPx R)) |--
PROPx P (LOCALx (replace_nth n Q T) (SEPx R)).