Library LangAlg.sp_terms_graphs
This module is devoted to the translation from series-parallel
terms to graphs.
Variable X : Set.
Variable ฮ : decidable_set X.
Notation grph := (graph nat X).
Notation edg := (@edge nat X).
Variable ฮ : decidable_set X.
Notation grph := (graph nat X).
Notation edg := (@edge nat X).
The length of a term is defined inductively as follows.
Fixpoint ln (u : ๐๐ X) :=
match u with
| ๐๐_var _ โ S O
| u โจพ v | u โฅ v โ ln u + ln v
end.
match u with
| ๐๐_var _ โ S O
| u โจพ v | u โฅ v โ ln u + ln v
end.
In fact, it coincides with the length of the list of variables.
As such, it is smaller that the size of the term.
A term always has strictly positive length.
We associate to every term a graph as follows:
Fixpoint ๐ฒ (u : ๐๐ X) : grph :=
match u with
| ๐๐_var a โ (0,[(0,a,S 0)],S 0)
| uโจพv โ ๐ฒ u โ graph_map (โจฅ (ln u)) (๐ฒ v)
| uโฅv โ
(graph_map {|ln u\ln u+ln v|} (๐ฒ u))
โ graph_map ({|ln u \ 0|} โ โจฅ (ln u)) (๐ฒ v)
end.
match u with
| ๐๐_var a โ (0,[(0,a,S 0)],S 0)
| uโจพv โ ๐ฒ u โ graph_map (โจฅ (ln u)) (๐ฒ v)
| uโฅv โ
(graph_map {|ln u\ln u+ln v|} (๐ฒ u))
โ graph_map ({|ln u \ 0|} โ โจฅ (ln u)) (๐ฒ v)
end.
The list of labels of the graph of a term is exactly its list of
variables.
The input of the graph of a term is always 0, and its output is
equal to the length of the term.
The length of a term is also its greatest vertex.
We give an inductive definition of the set of vertices of the
graph of a term, which will we show to be equivalent to the real
thing.
Fixpoint vertices u :=
match u with
| ๐๐_var _ โ (S O)::O::[]
| uโจพv โ vertices u++(List.map (โจฅ (ln u)) (vertices v))
| uโฅv โ rm (ln u) (vertices u++(List.map (โจฅ (ln u)) (vertices v)))
end.
match u with
| ๐๐_var _ โ (S O)::O::[]
| uโจพv โ vertices u++(List.map (โจฅ (ln u)) (vertices v))
| uโฅv โ rm (ln u) (vertices u++(List.map (โจฅ (ln u)) (vertices v)))
end.
The graph of uโจพv is the sequential product of the graphs of
u and v (modulo a translation of the graph of v to avoid
vertex capture).
The graph of uโฅv is the parallel product of the graphs of u
and v (modulo two translations to avoid vertex capture).
Lemma good_for_par_๐ฒ u v:
good_for_par (graph_map {|ln u\ln u+ln v|} (๐ฒ u))
(graph_map ({|ln u\0|}โโจฅ(ln u)) (๐ฒ v)).
good_for_par (graph_map {|ln u\ln u+ln v|} (๐ฒ u))
(graph_map ({|ln u\0|}โโจฅ(ln u)) (๐ฒ v)).
The path relation in term-graphs is contained in the
smaller-or-equal relation of natural numbers.
Hence we get that the path relation is a partial order, thus
proving that the graph of a term is always acyclic.
Is it not hard to show that it is also connected, thus making it
a good graph.
The length of a term and 0 are vertices.
The extremities of every edge in ๐ฒ u are vertices.
Lemma In_vertices u i ฮฑ j :
(i,ฮฑ,j) โ (edges (๐ฒ u)) โ i โ (vertices u) โง j โ (vertices u).
(i,ฮฑ,j) โ (edges (๐ฒ u)) โ i โ (vertices u) โง j โ (vertices u).
If there is a path from i to j in ๐ฒ u, then either both of
them are vertices of u or none of them are.
If ฯ is a morphism from the graph of u to that of v, and
if i is a vertex of u, then its image is a vertex of v.
Lemma is_morphism_vertices ฯ u v:
[] โจ ๐ฒ u -{ฯ}โ ๐ฒ v โ โ i, i โ (vertices u) โ (ฯ i) โ (vertices v).
[] โจ ๐ฒ u -{ฯ}โ ๐ฒ v โ โ i, i โ (vertices u) โ (ฯ i) โ (vertices v).
The next few lemma extract from a path in either ๐ฒ (u1 โจพ u2)
or ๐ฒ (u1 โฅ u2) paths in either ๐ฒ u1 or ๐ฒ u2.
Lemma path_seq_left u1 u2 i k :
k โ (vertices u1) โ i -[๐ฒ (u1 โจพ u2)]โ k โ i -[๐ฒ u1]โ k.
Lemma path_seq_right u1 u2 i k :
ln u1 โค i โ i -[๐ฒ (u1 โจพ u2)]โ k โ i - ln u1 -[๐ฒ u2]โ k - ln u1.
Lemma path_par u1 u2 i k :
i -[๐ฒ (u1 โฅ u2)]โ k โ
{|ln u1 + ln u2\ln u1|} i -[ ๐ฒ u1]โ {|ln u1 + ln u2\ln u1|} k
โจ (โจช (ln u1)โ{|0\ln u1|}) i -[๐ฒ u2 ]โ (โจช (ln u1)โ{|0\ln u1|}) k.
Lemma path_par_cross u1 u2 i k :
i < ln u1 < k โ i -[๐ฒ (u1โฅu2)]โ k โ i = 0 โจ k = ln (u1โฅu2).
Lemma path_par_left u1 u2 i k :
k < ln u1 โ i -[๐ฒ (u1โฅu2)]โ k โ i -[๐ฒ u1]โ k.
Lemma path_par_right u1 u2 i k :
ln u1 < i โ i -[๐ฒ (u1โฅu2)]โ k โ i - ln u1 -[๐ฒ u2]โ k - ln u1.
k โ (vertices u1) โ i -[๐ฒ (u1 โจพ u2)]โ k โ i -[๐ฒ u1]โ k.
Lemma path_seq_right u1 u2 i k :
ln u1 โค i โ i -[๐ฒ (u1 โจพ u2)]โ k โ i - ln u1 -[๐ฒ u2]โ k - ln u1.
Lemma path_par u1 u2 i k :
i -[๐ฒ (u1 โฅ u2)]โ k โ
{|ln u1 + ln u2\ln u1|} i -[ ๐ฒ u1]โ {|ln u1 + ln u2\ln u1|} k
โจ (โจช (ln u1)โ{|0\ln u1|}) i -[๐ฒ u2 ]โ (โจช (ln u1)โ{|0\ln u1|}) k.
Lemma path_par_cross u1 u2 i k :
i < ln u1 < k โ i -[๐ฒ (u1โฅu2)]โ k โ i = 0 โจ k = ln (u1โฅu2).
Lemma path_par_left u1 u2 i k :
k < ln u1 โ i -[๐ฒ (u1โฅu2)]โ k โ i -[๐ฒ u1]โ k.
Lemma path_par_right u1 u2 i k :
ln u1 < i โ i -[๐ฒ (u1โฅu2)]โ k โ i - ln u1 -[๐ฒ u2]โ k - ln u1.
From axiomatic containment to graph ordering
The graph of a term e is greater than the point graph
(0,[],0) if and only if all of its variables are tests.
The parametric ordering of series-parallel terms is contained
in the graph ordering with the same parameter.
From graph ordering to axiomatic containment
Variables
If the graph of u is smaller than the graph of a variable, then u is provably smaller than this variable.
Lemma morph_var A u a ฯ :
A โจ (๐ฒ (๐๐_var a))-{ฯ}โ (๐ฒ u) โ [] โจ u << ๐๐_var a.
A โจ (๐ฒ (๐๐_var a))-{ฯ}โ (๐ฒ u) โ [] โจ u << ๐๐_var a.
We fix a term u, and an integer k, such that k is an
interior vertex of ๐ฒ u (that is a vertex different from both 0
and ln u.
Fixpoint pref u k :=
match u with
| u โจพ v โ
if eqX k (ln u)
then u
else
if Nat.ltb k (ln u)
then pref u k
else u โจพ (pref v (k - ln u))
| u โฅ v โ
if Nat.ltb k (ln u)
then pref u k
else (pref v (k - ln u))
| _ โ u
end.
Fixpoint suf u k :=
match u with
| u โจพ v โ
if eqX k (ln u)
then v
else
if Nat.ltb k (ln u)
then (suf u k) โจพ v
else suf v (k - ln u)
| u โฅ v โ
if Nat.ltb k (ln u)
then suf u k
else (suf v (k - ln u))
| _ โ u
end.
Fixpoint moustache u k :=
match u with
| u โจพ v โ
if eqX k (ln u)
then u โจพ v
else
if Nat.ltb k (ln u)
then moustache u k โจพ v
else u โจพ (moustache v (k - ln u))
| u โฅ v โ
if Nat.ltb k (ln u)
then moustache u k
else moustache v (k - ln u)
| _ โ u
end.
match u with
| u โจพ v โ
if eqX k (ln u)
then u
else
if Nat.ltb k (ln u)
then pref u k
else u โจพ (pref v (k - ln u))
| u โฅ v โ
if Nat.ltb k (ln u)
then pref u k
else (pref v (k - ln u))
| _ โ u
end.
Fixpoint suf u k :=
match u with
| u โจพ v โ
if eqX k (ln u)
then v
else
if Nat.ltb k (ln u)
then (suf u k) โจพ v
else suf v (k - ln u)
| u โฅ v โ
if Nat.ltb k (ln u)
then suf u k
else (suf v (k - ln u))
| _ โ u
end.
Fixpoint moustache u k :=
match u with
| u โจพ v โ
if eqX k (ln u)
then u โจพ v
else
if Nat.ltb k (ln u)
then moustache u k โจพ v
else u โจพ (moustache v (k - ln u))
| u โฅ v โ
if Nat.ltb k (ln u)
then moustache u k
else moustache v (k - ln u)
| _ โ u
end.
Fixpoint split_point u k :=
match u with
| u โจพ v โ
if eqX k (ln u)
then k
else
if Nat.ltb k (ln u)
then split_point u k
else ln u + split_point v (k - ln u)
| u โฅ v โ
if Nat.ltb k (ln u)
then split_point u k
else split_point v (k - ln u)
| _ โ k
end.
match u with
| u โจพ v โ
if eqX k (ln u)
then k
else
if Nat.ltb k (ln u)
then split_point u k
else ln u + split_point v (k - ln u)
| u โฅ v โ
if Nat.ltb k (ln u)
then split_point u k
else split_point v (k - ln u)
| _ โ k
end.
u is provably smaller than its moustache.
If ฯ is a morphism from u1โจพu2 to v1โจพv2, and if the image
of the output of u1 is the output of v1, then the graph of u1
is greater than that of v1 and the graph of u2 is greater than
the graph of v2.
Lemma morphism_seq_split u1 u2 v1 v2 ฯ A :
A โจ ๐ฒ (u1โจพu2) -{ฯ}โ ๐ฒ (v1โจพv2) โ ฯ (ln u1) = ln v1 โ
A โจ ๐ฒ v1 โฒ ๐ฒ u1 โง A โจ ๐ฒ v2 โฒ ๐ฒ u2.
A โจ ๐ฒ (u1โจพu2) -{ฯ}โ ๐ฒ (v1โจพv2) โ ฯ (ln u1) = ln v1 โ
A โจ ๐ฒ v1 โฒ ๐ฒ u1 โง A โจ ๐ฒ v2 โฒ ๐ฒ u2.
ฮผ u k is a function mapping the vertices of u that are
visible from k to vertices in moustache u k.
Fixpoint ฮผ u k i :=
match u with
| ๐๐_var _ โ 0
| u โจพ v โ
if eqX k (ln u)
then i
else
if Nat.ltb k (ln u)
then
if Nat.leb i (ln u)
then ฮผ u k i
else ln (moustache u k) + i - ln u
else
if Nat.leb i (ln u)
then i
else ln u + ฮผ v (k - ln u)
(i - ln u)
| u โฅ v โ
if Nat.ltb k (ln u)
then (ฮผ u k ({|ln (uโฅv)\ln u|} i))
else (ฮผ v (k - ln u) (i - ln u))
end.
match u with
| ๐๐_var _ โ 0
| u โจพ v โ
if eqX k (ln u)
then i
else
if Nat.ltb k (ln u)
then
if Nat.leb i (ln u)
then ฮผ u k i
else ln (moustache u k) + i - ln u
else
if Nat.leb i (ln u)
then i
else ln u + ฮผ v (k - ln u)
(i - ln u)
| u โฅ v โ
if Nat.ltb k (ln u)
then (ฮผ u k ({|ln (uโฅv)\ln u|} i))
else (ฮผ v (k - ln u) (i - ln u))
end.
The image of 0 by ยต is 0.
The image of the length of u by ยต is the length of
its moustache.
This lemma could be restated as the statement that in the
graph of moustache u k, every vertex is either reachable or
co-reachable from split_point u k.
Lemma visible_moustache :
vertices (moustache u k) โ visible (๐ฒ (moustache u k))
(split_point u k).
vertices (moustache u k) โ visible (๐ฒ (moustache u k))
(split_point u k).
If a vertex in u is either reachable or co-reachable from
k, then ฮผ sends it to a vertex of the moustache.
Lemma ฮผ_internal u k :
0 < k < ln u โ k โ (vertices u) โ
internal_map (ฮผ u k)
(filter_graph (fun i โ k -[ ๐ฒ u ]?โ i)
(fun j โ j -[ ๐ฒ u ]?โ k)
(๐ฒ u))
(๐ฒ (moustache u k)).
0 < k < ln u โ k โ (vertices u) โ
internal_map (ฮผ u k)
(filter_graph (fun i โ k -[ ๐ฒ u ]?โ i)
(fun j โ j -[ ๐ฒ u ]?โ k)
(๐ฒ u))
(๐ฒ (moustache u k)).
Lemma ฮผ_morph u k :
0 < k < ln u โ k โ (vertices u) โ
([] โจ (filter_graph (fun i : nat โ k -[ ๐ฒ u ]?โ i)
(fun j : nat โ j -[ ๐ฒ u ]?โ k)
(๐ฒ u))
-{ฮผ u k}โ ๐ฒ (moustache u k)).
0 < k < ln u โ k โ (vertices u) โ
([] โจ (filter_graph (fun i : nat โ k -[ ๐ฒ u ]?โ i)
(fun j : nat โ j -[ ๐ฒ u ]?โ k)
(๐ฒ u))
-{ฮผ u k}โ ๐ฒ (moustache u k)).
We are now equipped to prove the lemma necessary for the
induction step corresponding to the sequential product: assuming
there is a morphism from v1โจพv2 to u, then one of three
things happen:
Lemma morphism_seq_step (u v1 v2 : ๐๐ X) A :
A โจ ๐ฒ u โฒ ๐ฒ (v1 โจพ v2) โ
(โv1โโ A โง A โจ ๐ฒ u โฒ ๐ฒ v2)
โจ (โv2โโ A โง A โจ ๐ฒ u โฒ ๐ฒ v1)
โจ (โ k, 0 < k < ln u โง k โ (vertices u)
โง A โจ ๐ฒ (pref u k) โฒ ๐ฒ v1
โง A โจ ๐ฒ (suf u k) โฒ ๐ฒ v2).
A โจ ๐ฒ u โฒ ๐ฒ (v1 โจพ v2) โ
(โv1โโ A โง A โจ ๐ฒ u โฒ ๐ฒ v2)
โจ (โv2โโ A โง A โจ ๐ฒ u โฒ ๐ฒ v1)
โจ (โ k, 0 < k < ln u โง k โ (vertices u)
โง A โจ ๐ฒ (pref u k) โฒ ๐ฒ v1
โง A โจ ๐ฒ (suf u k) โฒ ๐ฒ v2).