Library Rustre.Dataflow.Memories
Require Import Rustre.Common.
Require Import PArith.
Import List.ListNotations.
Open Scope list_scope.
Require Import Rustre.Dataflow.Syntax.
Require Import PArith.
Import List.ListNotations.
Open Scope list_scope.
Require Import Rustre.Dataflow.Syntax.
Collecting memory cells
Fixpoint memory_eq (mems: PS.t) (eq: equation) {struct eq} : PS.t :=
match eq with
| EqFby x _ _ _ ⇒ PS.add x mems
| _ ⇒ mems
end.
Definition memories (eqs: list equation) : PS.t :=
List.fold_left memory_eq eqs PS.empty.
Lemma In_fold_left_memory_eq:
∀ x eqs m,
PS.In x (List.fold_left memory_eq eqs m)
↔ PS.In x (List.fold_left memory_eq eqs PS.empty) ∨ PS.In x m.
Proof.
induction eqs as [|eq].
- split; auto.
destruct 1 as [H|].
apply not_In_empty in H; contradiction.
auto.
- split.
+ intro H.
simpl; rewrite IHeqs.
simpl in H; apply IHeqs in H; destruct H; auto.
destruct eq; auto.
apply PS.add_spec in H.
destruct H.
rewrite H; left; right; apply PS.add_spec; intuition.
intuition.
+ destruct 1 as [H|H].
× simpl in H; rewrite IHeqs in H; apply IHeqs; destruct H; auto.
right.
destruct eq; try (apply not_In_empty in H; contradiction).
simpl; apply PS.add_spec.
apply PS.add_spec in H; destruct H;
try apply not_In_empty in H; intuition.
× apply IHeqs; right; destruct eq; auto.
apply PS.add_spec; auto.
Qed.