From Velus Require Import Common.
From Velus Require Import Operators.
From Velus Require Import Clocks.
From Velus Require Import CoreExpr.CESyntax.
From Coq Require Import List.
Free variables
Module Type CEISFREE
(
Ids :
IDS)
(
Op :
OPERATORS)
(
Import Syn :
CESYNTAX Op).
Inductive Is_free_in_exp :
ident ->
exp ->
Prop :=
|
FreeEvar:
forall x ty,
Is_free_in_exp x (
Evar x ty)
|
FreeEwhen1:
forall e c cv x,
Is_free_in_exp x e ->
Is_free_in_exp x (
Ewhen e c cv)
|
FreeEwhen2:
forall e c cv,
Is_free_in_exp c (
Ewhen e c cv)
|
FreeEunop :
forall c op e ty,
Is_free_in_exp c e ->
Is_free_in_exp c (
Eunop op e ty)
|
FreeEbinop :
forall c op e1 e2 ty,
Is_free_in_exp c e1 \/
Is_free_in_exp c e2 ->
Is_free_in_exp c (
Ebinop op e1 e2 ty).
Inductive Is_free_in_aexp :
ident ->
clock ->
exp ->
Prop :=
|
freeAexp1:
forall ck e x,
Is_free_in_exp x e ->
Is_free_in_aexp x ck e
|
freeAexp2:
forall ck e x,
Is_free_in_clock x ck ->
Is_free_in_aexp x ck e.
Inductive Is_free_in_aexps :
ident ->
clock ->
list exp ->
Prop :=
|
freeAexps1:
forall ck les x,
Exists (
Is_free_in_exp x)
les ->
Is_free_in_aexps x ck les
|
freeAexps2:
forall ck les x,
Is_free_in_clock x ck ->
Is_free_in_aexps x ck les.
Inductive Is_free_in_cexp :
ident ->
cexp ->
Prop :=
|
FreeEmerge_cond:
forall i t f,
Is_free_in_cexp i (
Emerge i t f)
|
FreeEmerge_true:
forall i t f x,
Is_free_in_cexp x t ->
Is_free_in_cexp x (
Emerge i t f)
|
FreeEmerge_false:
forall i t f x,
Is_free_in_cexp x f ->
Is_free_in_cexp x (
Emerge i t f)
|
FreeEite_cond:
forall x b t f,
Is_free_in_exp x b ->
Is_free_in_cexp x (
Eite b t f)
|
FreeEite_true:
forall x b t f,
Is_free_in_cexp x t ->
Is_free_in_cexp x (
Eite b t f)
|
FreeEite_false:
forall x b t f,
Is_free_in_cexp x f ->
Is_free_in_cexp x (
Eite b t f)
|
FreeEexp:
forall e x,
Is_free_in_exp x e ->
Is_free_in_cexp x (
Eexp e).
Inductive Is_free_in_caexp :
ident ->
clock ->
cexp ->
Prop :=
|
FreeCAexp1:
forall ck ce x,
Is_free_in_cexp x ce ->
Is_free_in_caexp x ck ce
|
FreeCAexp2:
forall ck ce x,
Is_free_in_clock x ck ->
Is_free_in_caexp x ck ce.
Hint Constructors Is_free_in_clock Is_free_in_exp
Is_free_in_aexp Is_free_in_aexps Is_free_in_cexp
Is_free_in_caexp.
Decision procedure
Lemma Is_free_in_clock_disj:
forall y ck x c,
Is_free_in_clock y (
Con ck x c)
<->
y =
x \/
Is_free_in_clock y ck.
Proof.
intros y ck x c; split; intro HH.
inversion_clear HH; [left; reflexivity|right; assumption].
destruct HH as [HH|HH].
rewrite HH; constructor.
now constructor 2.
Qed.
Lemma Is_free_in_when_disj:
forall y e x c,
Is_free_in_exp y (
Ewhen e x c)
<->
y =
x \/
Is_free_in_exp y e.
Proof.
intros y e x c;
split;
intro HH.
inversion_clear HH;
auto.
destruct HH as [
HH|
HH];
try rewrite HH;
auto using Is_free_in_exp.
Qed.
Fixpoint free_in_clock_dec (
ck :
clock) (
T:
PS.t)
: {
S |
forall x,
PS.In x S <-> (
Is_free_in_clock x ck \/
PS.In x T) }.
refine (
match ck with
|
Cbase =>
exist _ T _
|
Con ck'
x c =>
match free_in_clock_dec ck'
T with
|
exist _ S'
HF =>
exist _ (
PS.add x S')
_
end
end).
-
intro x;
split;
intro HH.
right;
exact HH.
destruct HH as [
HH|
HH]; [
inversion HH|
exact HH].
-
intro y;
split;
intro HH.
+
rewrite PS.add_spec in HH.
destruct HH as [
HH|
HH].
rewrite HH;
left;
constructor.
apply HF in HH.
destruct HH as [
HH|
HH]; [
left|
right];
auto using Is_free_in_clock.
+
rewrite Is_free_in_clock_disj in HH.
apply or_assoc in HH.
destruct HH as [
HH|
HH].
rewrite HH;
apply PS.add_spec;
left;
reflexivity.
apply HF in HH;
apply PS.add_spec;
right;
assumption.
Defined.
Proof.
Proof.
Proof.
Proof.
Proof.
Proof.
Proof.
Proof.
Proof.
Proof.
Proof.
Proof.
Proof.