Library Rustre.Correctness.IsPresent

Require Import Rustre.Common.
Require Import Rustre.Memory.
Require Import Rustre.Dataflow.
Require Import Rustre.Minimp.Syntax.
Require Import Rustre.Minimp.Semantics.
Require Import Rustre.Translation.

Tying clock semantics and imperative semantics

The translation of equations is always guarded by a Control ck. When ck is false, the equation is not executed. It is therefore crucial to tie the result of Control ck with the dataflow semantics of ck. This is achieved by the following inductive relation.
Assumption: the base clock is true

Inductive Is_present_in (mems: PS.t) heap stack
  : clockProp :=
| IsCbase: Is_present_in mems heap stack Cbase
| IsCon:
     ck c v,
      Is_present_in mems heap stack ck
      → exp_eval heap stack (tovar mems c) (Cbool v)
      → Is_present_in mems heap stack (Con ck c v).

Inductive Is_absent_in (mems: PS.t) heap stack: clockProp :=
| IsAbs1:
     ck c v,
      Is_absent_in mems heap stack ck
      → Is_absent_in mems heap stack (Con ck c v)
| IsAbs2:
     ck c v1 v2,
         Is_present_in mems heap stack ck
      → exp_eval heap stack (tovar mems c) (Cbool v1)
      → v2 v1
      → Is_absent_in mems heap stack (Con ck c v2).

Properties


Lemma exp_eval_tovar_Cbool_dec:
   menv env mems c v,
    {exp_eval menv env (tovar mems c) (Cbool v)}
    + {¬exp_eval menv env (tovar mems c) (Cbool v)}.
Proof.
  Ltac no_match := right; inversion_clear 1; try unfold mfind_mem in *;
                   match goal with
                   | H: PM.find _ _ = _ |- _rewrite H in *; discriminate
                   end.
  intros menv env mems c v.
  unfold tovar.
  destruct (PS.mem c mems).
  - case_eq (mfind_mem c menv).
    + intro c0; destruct c0.
      × no_match.
      × destruct b; destruct v; (left; apply estate; assumption) || no_match.
    + no_match.
  - case_eq (PM.find c env).
    + intro c0; destruct c0.
      × no_match.
      × destruct b; destruct v; (left; apply evar; assumption) || no_match.
    + no_match.
Qed.

Lemma Is_present_in_dec:
   mems menv env ck,
    {Is_present_in mems menv env ck}+{¬Is_present_in mems menv env ck}.
Proof.
  intros.
  induction ck.
  - left; constructor.
  - destruct IHck.
    + destruct (exp_eval_tovar_Cbool_dec menv env mems i b); destruct b;
      (left; constructor; assumption) || right; inversion_clear 1; auto.
    + right; inversion_clear 1; auto.
Qed.

Lemma Is_absent_in_disj:
   mems menv env ck c v,
    Is_absent_in mems menv env (Con ck c v)
    → (Is_absent_in mems menv env ck
         ( , exp_eval menv env (tovar mems c) (Cbool )
                       → v)).
Proof.
  intros until c.
  inversion_clear 1 as [ | ? ? ? ? Hp Hexp Hneq]; intuition.
  right; intros Hexp´.
  intro HR; rewrite <-HR in *; clear HR.
  apply Hneq.
  pose proof (exp_eval_det _ _ _ _ _ Hexp Hexp´) as Heq.
  injection Heq; intuition.
Qed.