Library LangAlg.sp_terms
This module deals with series-parallel terms.
Unsurprisingly, here terms are built out of variables and two
binary operations.
Inductive ๐๐ : Set :=
| ๐๐_var : X โ ๐๐
| ๐๐_seq : ๐๐ โ ๐๐ โ ๐๐
| ๐๐_par : ๐๐ โ ๐๐ โ ๐๐.
End s0.
| ๐๐_var : X โ ๐๐
| ๐๐_seq : ๐๐ โ ๐๐ โ ๐๐
| ๐๐_par : ๐๐ โ ๐๐ โ ๐๐.
End s0.
In the following, โจพ denotes the sequential composition, and โฅ
the parallel composition.
Infix " โจพ " := ๐๐_seq (at level 40).
Infix " โฅ " := ๐๐_par (at level 50).
Section s.
Context {X : Set}.
Infix " โฅ " := ๐๐_par (at level 50).
Section s.
Context {X : Set}.
Set of variables of a term. Being associated with the class
Alphabet, we can write the set of variables of a term e as
โeโ.
Global Instance ๐๐_variables : Alphabet ๐๐ X :=
fix ๐๐_variables e :=
match e with
| ๐๐_var a โ [a]
| e โจพ f | e โฅ f โ ๐๐_variables e ++ ๐๐_variables f
end.
We define the size of a term as the number of nodes in its
syntax tree.
Global Instance ๐๐_size : Size (๐๐ X) :=
fix ๐๐_size (u : ๐๐ X) : nat :=
match u with
| ๐๐_var _ โ S O
| u โจพ v | u โฅ v โ S (๐๐_size u + ๐๐_size v)
end.
fix ๐๐_size (u : ๐๐ X) : nat :=
match u with
| ๐๐_var _ โ S O
| u โจพ v | u โฅ v โ S (๐๐_size u + ๐๐_size v)
end.
The length of the list of variables of a term is smaller than
its size.
In fact, because the length of the list of variables is the
number of leaves of the syntax tree of the term, and because that
tree is binary, we have the following identity:
Parametric axiomatization
Inductive ๐๐_ax : ๐๐ X โ ๐๐ X โ Prop :=
| ๐๐_seq_assoc e f g : ๐๐_ax (eโจพ(f โจพ g)) ((eโจพf)โจพg)
| ๐๐_par_assoc e f g : ๐๐_ax (eโฅ(f โฅ g)) ((eโฅf)โฅg)
| ๐๐_par_comm e f : ๐๐_ax (eโฅf) (fโฅe)
| ๐๐_par_idem e : ๐๐_ax (e โฅ e) e.
| ๐๐_seq_assoc e f g : ๐๐_ax (eโจพ(f โจพ g)) ((eโจพf)โจพg)
| ๐๐_par_assoc e f g : ๐๐_ax (eโฅ(f โฅ g)) ((eโฅf)โฅg)
| ๐๐_par_comm e f : ๐๐_ax (eโฅf) (fโฅe)
| ๐๐_par_idem e : ๐๐_ax (e โฅ e) e.
The containment axioms state that โฅ is a deceasing operation
(it is in fact the greatest lower bound), and that is a term is only
composed of tests, then it is a super-unit.
Inductive ๐๐_axinf (A : list X) : ๐๐ X โ ๐๐ X โ Prop :=
| ๐๐_axinf_weak e f : ๐๐_axinf A (e โฅ f) e
| ๐๐_axinf_1_seql e f : โeโ โ A โ ๐๐_axinf A f (e โจพ f)
| ๐๐_axinf_1_seqr e f : โeโ โ A โ ๐๐_axinf A f (f โจพ e).
Reserved Notation " A โจ e << f " (at level 80).
| ๐๐_axinf_weak e f : ๐๐_axinf A (e โฅ f) e
| ๐๐_axinf_1_seql e f : โeโ โ A โ ๐๐_axinf A f (e โจพ f)
| ๐๐_axinf_1_seqr e f : โeโ โ A โ ๐๐_axinf A f (f โจพ e).
Reserved Notation " A โจ e << f " (at level 80).
The relation Aโจ e << f is then the smallest order relation
(that is reflexive and transitive) containing both sets of axioms,
and such that โจพ and โฅ are monotone operations.
Inductive ๐๐_inf (A : list X) : ๐๐ X โ ๐๐ X โ Prop :=
| ๐๐_inf_re e : A โจ e << e
| ๐๐_inf_trans e f g : A โจ e << f โ A โจ f << g โ A โจ e << g
| ๐๐_inf_ax e f : ๐๐_ax e f โจ ๐๐_ax f e โ A โจ e << f
| ๐๐_inf_axinf e f: ๐๐_axinf A e f โ A โจ e << f
| ๐๐_inf_seq e f g h :
A โจ e << g โ A โจ f << h โ A โจ e โจพ f << g โจพ h
| ๐๐_inf_par e f g h :
A โจ e << g โ A โจ f << h โ A โจ e โฅ f << g โฅ h
where " A โจ e << f " := (๐๐_inf A e f).
Hint Constructors ๐๐_inf ๐๐_ax ๐๐_axinf.
Global Instance ๐๐_inf_PreOrder A : PreOrder (๐๐_inf A).
Global Instance par_๐๐_inf A :
Proper ((๐๐_inf A) ==> (๐๐_inf A) ==> (๐๐_inf A))
(@๐๐_par X).
Global Instance seq_๐๐_inf A :
Proper ((๐๐_inf A) ==> (๐๐_inf A) ==> (๐๐_inf A))
(@๐๐_seq X).
| ๐๐_inf_re e : A โจ e << e
| ๐๐_inf_trans e f g : A โจ e << f โ A โจ f << g โ A โจ e << g
| ๐๐_inf_ax e f : ๐๐_ax e f โจ ๐๐_ax f e โ A โจ e << f
| ๐๐_inf_axinf e f: ๐๐_axinf A e f โ A โจ e << f
| ๐๐_inf_seq e f g h :
A โจ e << g โ A โจ f << h โ A โจ e โจพ f << g โจพ h
| ๐๐_inf_par e f g h :
A โจ e << g โ A โจ f << h โ A โจ e โฅ f << g โฅ h
where " A โจ e << f " := (๐๐_inf A e f).
Hint Constructors ๐๐_inf ๐๐_ax ๐๐_axinf.
Global Instance ๐๐_inf_PreOrder A : PreOrder (๐๐_inf A).
Global Instance par_๐๐_inf A :
Proper ((๐๐_inf A) ==> (๐๐_inf A) ==> (๐๐_inf A))
(@๐๐_par X).
Global Instance seq_๐๐_inf A :
Proper ((๐๐_inf A) ==> (๐๐_inf A) ==> (๐๐_inf A))
(@๐๐_seq X).
Adding tests only makes the relation grow.
This relation has a very useful property: if e is smaller than
f with tests A, then the variables in f all appear either as
variables of e of as tests.
Lemma ๐๐_inf_variables (A : list X) e f :
A โจ e << f โ โ f โ โ โ e โ ++ A.
End s.
A โจ e << f โ โ f โ โ โ e โ ++ A.
End s.
We define the primed variables of a term e as follows:
Fixpoint ๐๐'_variables (e : ๐๐ X') : list (@X' X) :=
match e with
| ๐๐_var (a,_) โ [(a,true);(a,false)]
| e โจพ f | e โฅ f โ ๐๐'_variables e ++ ๐๐'_variables f
end.
match e with
| ๐๐_var (a,_) โ [(a,true);(a,false)]
| e โจพ f | e โฅ f โ ๐๐'_variables e ++ ๐๐'_variables f
end.
By construction this function generates balanced sets.
The result of this function is always a superset of the set of
variables of the term.
The primed variable (a,b) is in ๐๐'_variables u exactly when
either (a,true) or (a,false) appears in โuโ.
Lemma ๐๐_variables_๐๐'_variables_iff u a b :
(a,b) โ (๐๐'_variables u) โ (a,true) โ โuโ โจ (a,false) โ โuโ.
(a,b) โ (๐๐'_variables u) โ (a,true) โ โuโ โจ (a,false) โ โuโ.
This is another formulation of the same result.
Lemma fst_๐๐_variables (u : ๐๐ (@X' X)) : map fst โuโ โ map fst (๐๐'_variables u).
The length of the result of this function is the size of the
term plus one.
Lemma ๐๐_size_๐๐'_variables u :
length (๐๐'_variables u) = S โฆuโฆ.
End primed.
Section language.
length (๐๐'_variables u) = S โฆuโฆ.
End primed.
Section language.
Context { X : Set }.
Open Scope lang.
Open Scope lang.
We interpret the sequential product by concatenation and the
parallel product by intersection.
Global Instance to_lang_๐๐ {ฮฃ} : semantics ๐๐ language X ฮฃ :=
fix to_lang_๐๐ ฯ e:=
match e with
| ๐๐_var a โ (ฯ a)
| e โจพ f โ (to_lang_๐๐ ฯ e) โ (to_lang_๐๐ ฯ f)
| e โฅ f โ (to_lang_๐๐ ฯ e) โฉ (to_lang_๐๐ ฯ f)
end.
fix to_lang_๐๐ ฯ e:=
match e with
| ๐๐_var a โ (ฯ a)
| e โจพ f โ (to_lang_๐๐ ฯ e) โ (to_lang_๐๐ ฯ f)
| e โฅ f โ (to_lang_๐๐ ฯ e) โฉ (to_lang_๐๐ ฯ f)
end.
We define semantic equality and containment of series parallel
from those of languages.
Global Instance semSmaller_๐๐ : SemSmaller (๐๐ X) :=
(@semantic_containment _ _ _ _ _).
Global Instance ๐๐_sem_PreOrder : PreOrder (fun e f : ๐๐ X โ e โฒ f).
Global Instance semEquiv_๐๐ : SemEquiv (๐๐ X) :=
(@semantic_equality _ _ _ _ _).
Global Instance ๐๐_sem_equiv : Equivalence (fun e f : ๐๐ X โ e โ f).
Global Instance ๐๐_sem_PartialOrder :
PartialOrder (fun e f : ๐๐ X โ e โ f) (fun e f : ๐๐ X โ e โฒ f).
(@semantic_containment _ _ _ _ _).
Global Instance ๐๐_sem_PreOrder : PreOrder (fun e f : ๐๐ X โ e โฒ f).
Global Instance semEquiv_๐๐ : SemEquiv (๐๐ X) :=
(@semantic_equality _ _ _ _ _).
Global Instance ๐๐_sem_equiv : Equivalence (fun e f : ๐๐ X โ e โ f).
Global Instance ๐๐_sem_PartialOrder :
PartialOrder (fun e f : ๐๐ X โ e โ f) (fun e f : ๐๐ X โ e โฒ f).
Both products are monotone.
Global Instance sem_incl_๐๐_seq :
Proper (ssmaller ==> ssmaller ==> ssmaller) (@๐๐_seq X).
Global Instance sem_incl_๐๐_inter :
Proper (ssmaller ==> ssmaller ==> ssmaller) (@๐๐_par X).
Global Instance sem_eq_๐๐_seq :
Proper (sequiv ==> sequiv ==> sequiv) (@๐๐_seq X).
Global Instance sem_eq_๐๐_inter :
Proper (sequiv ==> sequiv ==> sequiv) (@๐๐_par X).
Proper (ssmaller ==> ssmaller ==> ssmaller) (@๐๐_seq X).
Global Instance sem_incl_๐๐_inter :
Proper (ssmaller ==> ssmaller ==> ssmaller) (@๐๐_par X).
Global Instance sem_eq_๐๐_seq :
Proper (sequiv ==> sequiv ==> sequiv) (@๐๐_seq X).
Global Instance sem_eq_๐๐_inter :
Proper (sequiv ==> sequiv ==> sequiv) (@๐๐_par X).