From iris.base_logic Require Import iprop.
From iris.proofmode Require Import proofmode.
From iris.heap_lang Require Import lang proofmode notation par.
Set Default Goal Selector "!".

Section hw5.

Context `{!heapGS Σ}.

Lemma sep_assoc_1 (P Q R : iProp Σ) : P ∗ (Q ∗ R) ⊢ (P ∗ Q) ∗ R.
Proof.
Admitted.

Lemma sep_ex_distr {A} (P : iProp Σ) (Φ : A → iProp Σ) :
  (P ∗ ∃ x, Φ x) ⊣⊢ ∃ x, P ∗ Φ x.
Proof.
Admitted.

(* added *)
Definition arith2 : expr :=
  let: "x" := #1 + #2 * #3 in
  let: "y" := #4 * #5 in
  "y" - "x".

Lemma arith2_spec : ⊢ WP arith2 {{ v, ⌜v = #13⌝ }}.
Proof.
  (* exercise *)
Admitted.

Definition double : val :=
  λ: "x",
  let: "v" := !"x" in
  "x" <- #2 * "v".

Lemma double_spec (l : loc) (v : Z) :
  {{{ l ↦ #v }}}
    double #l
  {{{ RET #(); l ↦ #(2 * v) }}}.
  (* exercise *)
Admitted.

(* grad exercise *)
(** Write and prove a specification for the following program: *)
Definition alloc_sum : val :=
  λ: "x" "y",
  let: "r" := ref (!"x" + !"y") in
  "r".

End hw5.
