wp_tactics.v 2.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
From heap_lang Require Export tactics substitution.
Import uPred.

Ltac wp_strip_later :=
  match goal with
  | |-  _, _ => let H := fresh in intro H; wp_strip_later; revert H
  | |- _   _ => etransitivity; [|apply later_intro]
  end.
Ltac wp_bind K :=
  lazymatch eval hnf in K with
  | [] => idtac
  | _ => etransitivity; [|apply (wp_bind K)]; simpl
  end.

Tactic Notation "wp_value" :=
  match goal with
  | |- _  wp ?E ?e ?Q => etransitivity; [|by eapply wp_value]; simpl
  end.
Tactic Notation "wp_rec" "!" :=
  repeat wp_value;
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
    | App (Rec _ _ _) _ => wp_bind K; etransitivity; [|by eapply wp_rec]; simpl
    end)
  end.
Tactic Notation "wp_rec" := wp_rec!; wp_strip_later.
Tactic Notation "wp_bin_op" "!" :=
  repeat wp_value;
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
    | BinOp LtOp _ _ => wp_bind K; apply wp_lt; [|]
    | BinOp LeOp _ _ => wp_bind K; apply wp_le; [|]
    | BinOp EqOp _ _ => wp_bind K; apply wp_eq; [|]
    | BinOp _ _ _ => wp_bind K; etransitivity; [|by eapply wp_bin_op]; simpl
    end)
  end.

Tactic Notation "wp_bin_op" := wp_bin_op!; wp_strip_later.
Tactic Notation "wp_un_op" "!" :=
  repeat wp_value;
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
    | UnOp _ _ => wp_bind K; etransitivity; [|by eapply wp_un_op]; simpl
    end)
  end.
Tactic Notation "wp_un_op" := wp_un_op!; wp_strip_later.
Tactic Notation "wp_if" "!" :=
  repeat wp_value;
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match eval cbv in e' with
    | If _ _ _ =>
       wp_bind K; etransitivity; [|by apply wp_if_true || by apply wp_if_false]
    end)
  end.
Tactic Notation "wp_if" := wp_if!; wp_strip_later.
Tactic Notation "wp_focus" open_constr(efoc) :=
  match goal with
  | |- _  wp ?E ?e ?Q => reshape_expr e ltac:(fun K e' =>
    match e' with efoc => unify e' efoc; wp_bind K end)
  end.