Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stdpp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thibaut Pérami
stdpp
Commits
87b2fe62
Commit
87b2fe62
authored
6 years ago
by
Robbert Krebbers
Browse files
Options
Downloads
Plain Diff
Merge branch 'robbert/relations' into 'master'
Confluent relations See merge request
!53
parents
824e9723
89454051
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theories/relations.v
+116
-8
116 additions, 8 deletions
theories/relations.v
with
116 additions
and
8 deletions
theories/relations.v
+
116
−
8
View file @
87b2fe62
...
@@ -2,8 +2,7 @@
...
@@ -2,8 +2,7 @@
(* This file is distributed under the terms of the BSD license. *)
(* This file is distributed under the terms of the BSD license. *)
(** This file collects definitions and theorems on abstract rewriting systems.
(** This file collects definitions and theorems on abstract rewriting systems.
These are particularly useful as we define the operational semantics as a
These are particularly useful as we define the operational semantics as a
small step semantics. This file defines a hint database [ars] containing
small step semantics. *)
some theorems on abstract rewriting systems. *)
From
Coq
Require
Import
Wf_nat
.
From
Coq
Require
Import
Wf_nat
.
From
stdpp
Require
Export
tactics
base
.
From
stdpp
Require
Export
tactics
base
.
Set
Default
Proof
Using
"Type"
.
Set
Default
Proof
Using
"Type"
.
...
@@ -18,6 +17,9 @@ Section definitions.
...
@@ -18,6 +17,9 @@ Section definitions.
(** An element is in normal form if no further steps are possible. *)
(** An element is in normal form if no further steps are possible. *)
Definition
nf
(
x
:
A
)
:=
¬
red
x
.
Definition
nf
(
x
:
A
)
:=
¬
red
x
.
(** The symmetric closure. *)
Definition
sc
:
relation
A
:=
λ
x
y
,
R
x
y
∨
R
y
x
.
(** The reflexive transitive closure. *)
(** The reflexive transitive closure. *)
Inductive
rtc
:
relation
A
:=
Inductive
rtc
:
relation
A
:=
|
rtc_refl
x
:
rtc
x
x
|
rtc_refl
x
:
rtc
x
x
...
@@ -54,13 +56,29 @@ Section definitions.
...
@@ -54,13 +56,29 @@ Section definitions.
|
ex_loop_do_step
x
y
:
R
x
y
→
ex_loop
y
→
ex_loop
x
.
|
ex_loop_do_step
x
y
:
R
x
y
→
ex_loop
y
→
ex_loop
x
.
End
definitions
.
End
definitions
.
(* Strongly normalizing elements *)
(** The reflexive transitive symmetric closure. *)
Definition
rtsc
{
A
}
(
R
:
relation
A
)
:=
rtc
(
sc
R
)
.
(** Strongly normalizing elements. *)
Notation
sn
R
:=
(
Acc
(
flip
R
))
.
Notation
sn
R
:=
(
Acc
(
flip
R
))
.
(** The various kinds of "confluence" properties. Any relation that has the
diamond property is confluent, and any confluent relation is locally confluent.
The naming convention are taken from "Term Rewriting and All That" by Baader and
Nipkow. *)
Definition
diamond
{
A
}
(
R
:
relation
A
)
:=
∀
x
y1
y2
,
R
x
y1
→
R
x
y2
→
∃
z
,
R
y1
z
∧
R
y2
z
.
Definition
confluent
{
A
}
(
R
:
relation
A
)
:=
diamond
(
rtc
R
)
.
Definition
locally_confluent
{
A
}
(
R
:
relation
A
)
:=
∀
x
y1
y2
,
R
x
y1
→
R
x
y2
→
∃
z
,
rtc
R
y1
z
∧
rtc
R
y2
z
.
Hint
Unfold
nf
red
:
core
.
Hint
Unfold
nf
red
:
core
.
(** * General theorems *)
(** * General theorems *)
Section
rtc
.
Section
closure
.
Context
`{
R
:
relation
A
}
.
Context
`{
R
:
relation
A
}
.
Hint
Constructors
rtc
nsteps
bsteps
tc
:
core
.
Hint
Constructors
rtc
nsteps
bsteps
tc
:
core
.
...
@@ -79,6 +97,14 @@ Section rtc.
...
@@ -79,6 +97,14 @@ Section rtc.
Global
Instance
rtc_po
:
PreOrder
(
rtc
R
)
|
10
.
Global
Instance
rtc_po
:
PreOrder
(
rtc
R
)
|
10
.
Proof
.
split
.
exact
(
@
rtc_refl
A
R
)
.
exact
rtc_transitive
.
Qed
.
Proof
.
split
.
exact
(
@
rtc_refl
A
R
)
.
exact
rtc_transitive
.
Qed
.
(* Not an instance, related to the issue described above, this sometimes makes
[setoid_rewrite] queries loop. *)
Lemma
rtc_equivalence
:
Symmetric
R
→
Equivalence
(
rtc
R
)
.
Proof
.
split
;
try
apply
_
.
intros
x
y
.
induction
1
as
[|
x1
x2
x3
];
[
done
|
trans
x2
;
eauto
]
.
Qed
.
Lemma
rtc_once
x
y
:
R
x
y
→
rtc
R
x
y
.
Lemma
rtc_once
x
y
:
R
x
y
→
rtc
R
x
y
.
Proof
.
eauto
.
Qed
.
Proof
.
eauto
.
Qed
.
Lemma
rtc_r
x
y
z
:
rtc
R
x
y
→
R
y
z
→
rtc
R
x
z
.
Lemma
rtc_r
x
y
z
:
rtc
R
x
y
→
R
y
z
→
rtc
R
x
z
.
...
@@ -106,6 +132,9 @@ Section rtc.
...
@@ -106,6 +132,9 @@ Section rtc.
Lemma
rtc_inv_r
x
z
:
rtc
R
x
z
→
x
=
z
∨
∃
y
,
rtc
R
x
y
∧
R
y
z
.
Lemma
rtc_inv_r
x
z
:
rtc
R
x
z
→
x
=
z
∨
∃
y
,
rtc
R
x
y
∧
R
y
z
.
Proof
.
revert
z
.
apply
rtc_ind_r
;
eauto
.
Qed
.
Proof
.
revert
z
.
apply
rtc_ind_r
;
eauto
.
Qed
.
Lemma
rtc_nf
x
y
:
rtc
R
x
y
→
nf
R
x
→
x
=
y
.
Proof
.
destruct
1
as
[
x
|
x
y1
y2
]
.
done
.
intros
[];
eauto
.
Qed
.
Lemma
nsteps_once
x
y
:
R
x
y
→
nsteps
R
1
x
y
.
Lemma
nsteps_once
x
y
:
R
x
y
→
nsteps
R
1
x
y
.
Proof
.
eauto
.
Qed
.
Proof
.
eauto
.
Qed
.
Lemma
nsteps_trans
n
m
x
y
z
:
Lemma
nsteps_trans
n
m
x
y
z
:
...
@@ -172,6 +201,36 @@ Section rtc.
...
@@ -172,6 +201,36 @@ Section rtc.
Lemma
tc_rtc
x
y
:
tc
R
x
y
→
rtc
R
x
y
.
Lemma
tc_rtc
x
y
:
tc
R
x
y
→
rtc
R
x
y
.
Proof
.
induction
1
;
eauto
.
Qed
.
Proof
.
induction
1
;
eauto
.
Qed
.
Global
Instance
sc_symmetric
:
Symmetric
(
sc
R
)
.
Proof
.
unfold
Symmetric
,
sc
.
naive_solver
.
Qed
.
Lemma
sc_lr
x
y
:
R
x
y
→
sc
R
x
y
.
Proof
.
by
left
.
Qed
.
Lemma
sc_rl
x
y
:
R
y
x
→
sc
R
x
y
.
Proof
.
by
right
.
Qed
.
End
closure
.
Section
more_closure
.
Context
`{
R
:
relation
A
}
.
Global
Instance
rtsc_equivalence
:
Equivalence
(
rtsc
R
)
|
10
.
Proof
.
apply
rtc_equivalence
,
_
.
Qed
.
Lemma
rtsc_lr
x
y
:
R
x
y
→
rtsc
R
x
y
.
Proof
.
unfold
rtsc
.
eauto
using
sc_lr
,
rtc_once
.
Qed
.
Lemma
rtsc_rl
x
y
:
R
y
x
→
rtsc
R
x
y
.
Proof
.
unfold
rtsc
.
eauto
using
sc_rl
,
rtc_once
.
Qed
.
Lemma
rtc_rtsc_rl
x
y
:
rtc
R
x
y
→
rtsc
R
x
y
.
Proof
.
induction
1
;
econstructor
;
eauto
using
sc_lr
.
Qed
.
Lemma
rtc_rtsc_lr
x
y
:
rtc
R
y
x
→
rtsc
R
x
y
.
Proof
.
intros
.
symmetry
.
eauto
using
rtc_rtsc_rl
.
Qed
.
End
more_closure
.
Section
properties
.
Context
`{
R
:
relation
A
}
.
Hint
Constructors
rtc
nsteps
bsteps
tc
:
core
.
Lemma
acc_not_ex_loop
x
:
Acc
(
flip
R
)
x
→
¬
ex_loop
R
x
.
Lemma
acc_not_ex_loop
x
:
Acc
(
flip
R
)
x
→
¬
ex_loop
R
x
.
Proof
.
unfold
not
.
induction
1
;
destruct
1
;
eauto
.
Qed
.
Proof
.
unfold
not
.
induction
1
;
destruct
1
;
eauto
.
Qed
.
...
@@ -188,11 +247,60 @@ Section rtc.
...
@@ -188,11 +247,60 @@ Section rtc.
intros
H
.
cut
(
∀
z
,
rtc
R
x
z
→
all_loop
R
z
);
[
eauto
|]
.
intros
H
.
cut
(
∀
z
,
rtc
R
x
z
→
all_loop
R
z
);
[
eauto
|]
.
cofix
FIX
.
constructor
;
eauto
using
rtc_r
.
cofix
FIX
.
constructor
;
eauto
using
rtc_r
.
Qed
.
Qed
.
End
rtc
.
Hint
Constructors
rtc
nsteps
bsteps
tc
:
ars
.
(** An alternative definition of confluence; also known as the Church-Rosser
Hint
Resolve
rtc_once
rtc_r
tc_r
rtc_transitive
tc_rtc_l
tc_rtc_r
property. *)
tc_rtc
bsteps_once
bsteps_r
bsteps_refl
bsteps_trans
:
ars
.
Lemma
confluent_alt
:
confluent
R
↔
(
∀
x
y
,
rtsc
R
x
y
→
∃
z
,
rtc
R
x
z
∧
rtc
R
y
z
)
.
Proof
.
split
.
-
intros
Hcr
.
induction
1
as
[
x
|
x
y1
y1'
[
Hy1
|
Hy1
]
Hy1'
(
z
&
IH1
&
IH2
)];
eauto
.
destruct
(
Hcr
y1
x
z
)
as
(
z'
&
?
&
?);
eauto
using
rtc_transitive
.
-
intros
Hcr
x
y1
y2
Hy1
Hy2
.
apply
Hcr
;
trans
x
;
eauto
using
rtc_rtsc_rl
,
rtc_rtsc_lr
.
Qed
.
Lemma
confluent_nf_r
x
y
:
confluent
R
→
rtsc
R
x
y
→
nf
R
y
→
rtc
R
x
y
.
Proof
.
rewrite
confluent_alt
.
intros
Hcr
??
.
destruct
(
Hcr
x
y
)
as
(
z
&
Hx
&
Hy
);
auto
.
by
apply
rtc_nf
in
Hy
as
->
.
Qed
.
Lemma
confluent_nf_l
x
y
:
confluent
R
→
rtsc
R
x
y
→
nf
R
x
→
rtc
R
y
x
.
Proof
.
intros
.
by
apply
(
confluent_nf_r
y
x
)
.
Qed
.
Lemma
diamond_confluent
:
diamond
R
→
confluent
R
.
Proof
.
intros
Hdiam
.
assert
(
∀
x
y1
y2
,
rtc
R
x
y1
→
R
x
y2
→
∃
z
,
rtc
R
y1
z
∧
rtc
R
y2
z
)
as
Hstrip
.
{
intros
x
y1
y2
Hy1
;
revert
y2
.
induction
Hy1
as
[
x
|
x
y1
y1'
Hy1
Hy1'
IH
];
[
by
eauto
|];
intros
y2
Hy2
.
destruct
(
Hdiam
x
y1
y2
)
as
(
z
&
Hy1z
&
Hy2z
);
auto
.
destruct
(
IH
z
)
as
(
z'
&
?
&
?);
eauto
.
}
intros
x
y1
y2
Hy1
;
revert
y2
.
induction
Hy1
as
[
x
|
x
y1
y1'
Hy1
Hy1'
IH
];
[
by
eauto
|];
intros
y2
Hy2
.
destruct
(
Hstrip
x
y2
y1
)
as
(
z
&
?
&
?);
eauto
.
destruct
(
IH
z
)
as
(
z'
&
?
&
?);
eauto
using
rtc_transitive
.
Qed
.
Lemma
confluent_locally_confluent
:
confluent
R
→
locally_confluent
R
.
Proof
.
unfold
confluent
,
locally_confluent
;
eauto
.
Qed
.
(** The following is also known as Newman's lemma *)
Lemma
locally_confluent_confluent
:
(
∀
x
,
sn
R
x
)
→
locally_confluent
R
→
confluent
R
.
Proof
.
intros
Hsn
Hcr
x
.
induction
(
Hsn
x
)
as
[
x
_
IH
]
.
intros
y1
y2
Hy1
Hy2
.
destruct
Hy1
as
[
x
|
x
y1
y1'
Hy1
Hy1'
];
[
by
eauto
|]
.
destruct
Hy2
as
[
x
|
x
y2
y2'
Hy2
Hy2'
];
[
by
eauto
|]
.
destruct
(
Hcr
x
y1
y2
)
as
(
z
&
Hy1z
&
Hy2z
);
auto
.
destruct
(
IH
_
Hy1
y1'
z
)
as
(
z1
&
?
&
?);
auto
.
destruct
(
IH
_
Hy2
y2'
z1
)
as
(
z2
&
?
&
?);
eauto
using
rtc_transitive
.
Qed
.
End
properties
.
(** * Theorems on sub relations *)
(** * Theorems on sub relations *)
Section
subrel
.
Section
subrel
.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment