Order Theory
Introduction
- The Mathcomp library is just not understandable from my point of view (mathlib from lean is infinetly better).
- My goal while doing this was to learn my course. So recreating everything from scratch is not a that bad idea.
Partial orders
We have partial orders defined in Stdlib. This allow us to use pre defined tactics on them, such as reflexivity. CF Relation (Rocq Stdlib) Basically, they are juste relations on a set with the following properties : One of the main thing you want to define once you have these, are (least) upper bound of two elements, because they allow to define interesting structures, such as lattices and complete partial orders, and functions properties, such as continuity. We will then use these definitions for some fixpoints theorems, which are themselves usefull to define concrete semantics. Then, we can abstract these concrete semantics, using what we call concretisation to link the abstract and concrete sets, and also abstract functions and their fixpoints (or at least approximate them). This give us a general framework to work with, which we can reuse to abstract in different ways various concrete semantics.
From Stdlib Require Import Relations.
From Stdlib Require Import RelationClasses.
From Stdlib Require Import RelationClasses.
We need the ability to use classical reasoning to show that a non empty set contains at least one element.
From Stdlib Require Import Classical.
We will also use the Set Extensionnality axiom for double inclusion proofs.
We will represent subsets of X as they do, by the type X->Prop.
From Stdlib Require Import Sets.Ensembles.
We don't redefine composition.
From Stdlib Require Import Program.Basics.
And we will use some lemmas about natural numbers.
From Stdlib Require Import PeanoNat.
Needed for bijectivity caracterisation
We will use composition quite often to compose abstraction.
Let define a classical notation for it.
(Least/Greatest) Upper/Lower bounds
Definition UpperBound
{X : Type} {r : Relation X}
`{PartialOrder X eq r} (a b : X) (c : X) : Prop :=
r a c ∧ r b c.
Definition LowerBound
{X : Type} {r : Relation X}
`{PartialOrder X eq r} (a b : X) (c : X) : Prop :=
r c a ∧ r c b.
Definition LeastUpperBound
{X : Type} {r : Relation X}
`{PartialOrder X eq r} (a b : X) (c : X) : Prop :=
UpperBound a b c
∧ (∀ d : X, UpperBound a b d → r c d).
Definition GreatestLowerBound
{X : Type} {r : Relation X}
`{PartialOrder X eq r} (a b : X) (c : X) : Prop :=
LowerBound a b c
∧ (∀ d : X, LowerBound a b d → r d c).
{X : Type} {r : Relation X}
`{PartialOrder X eq r} (a b : X) (c : X) : Prop :=
r a c ∧ r b c.
Definition LowerBound
{X : Type} {r : Relation X}
`{PartialOrder X eq r} (a b : X) (c : X) : Prop :=
r c a ∧ r c b.
Definition LeastUpperBound
{X : Type} {r : Relation X}
`{PartialOrder X eq r} (a b : X) (c : X) : Prop :=
UpperBound a b c
∧ (∀ d : X, UpperBound a b d → r c d).
Definition GreatestLowerBound
{X : Type} {r : Relation X}
`{PartialOrder X eq r} (a b : X) (c : X) : Prop :=
LowerBound a b c
∧ (∀ d : X, LowerBound a b d → r d c).
I say that LUB were unique. Let prove it.
Theorem lub_unicity :
∀ {X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r} (a b c d : X),
LeastUpperBound a b c → LeastUpperBound a b d → c = d.
∀ {X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r} (a b c d : X),
LeastUpperBound a b c → LeastUpperBound a b d → c = d.
Proof.
intros X r equ preo Hpartialorder.
intros a b c d HLUBc HLUBd.
destruct HLUBc as [HUBc HsUBc].
destruct HLUBd as [HUBd HsUBd].
apply HsUBc in HUBd.
apply HsUBd in HUBc.
apply antisymmetry; assumption.
Qed.
intros X r equ preo Hpartialorder.
intros a b c d HLUBc HLUBd.
destruct HLUBc as [HUBc HsUBc].
destruct HLUBd as [HUBd HsUBd].
apply HsUBc in HUBd.
apply HsUBd in HUBc.
apply antisymmetry; assumption.
Qed.
The proof is the same for GLB.
Theorem glb_unicity :
∀ {X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r} (a b c d : X),
GreatestLowerBound a b c → GreatestLowerBound a b d → c = d.
∀ {X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r} (a b c d : X),
GreatestLowerBound a b c → GreatestLowerBound a b d → c = d.
If two element are in relation, one is the lub of both.
Lemma rel_eq_lub
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(a b : X) :
r a b ↔ LeastUpperBound a b b.
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(a b : X) :
r a b ↔ LeastUpperBound a b b.
Proof.
split. {
intro Hr.
split.
- split.
× assumption.
× reflexivity.
- intros y HUBy.
apply HUBy.
}
{
intros [[Hab _] _].
assumption.
}
Qed.
split. {
intro Hr.
split.
- split.
× assumption.
× reflexivity.
- intros y HUBy.
apply HUBy.
}
{
intros [[Hab _] _].
assumption.
}
Qed.
Lemma rel_eq_glb
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(a b : X) :
r a b ↔ GreatestLowerBound a b a.
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(a b : X) :
r a b ↔ GreatestLowerBound a b a.
We can also define total order, e.g partial order were every elements are in relation.
It is an usefull property when we have it.
Class TotalOrder (X : Type) (r : Relation X)
`{Hpartial : PartialOrder X eq r} : Prop := {
totality : ∀ x y : X, r x y ∨ r y x;
}.
`{Hpartial : PartialOrder X eq r} : Prop := {
totality : ∀ x y : X, r x y ∨ r y x;
}.
For instance, natural numbers are totally ordered. We will use it in kleene_fixpoint.
A chain C is totally ordered subset of a set X.
Definition Chain
{X : Type} {r : Relation X} `{PartialOrder X eq r}
(C : X → Prop) : Prop :=
∀ x y : X, C x → C y → r x y ∨ r y x.
{X : Type} {r : Relation X} `{PartialOrder X eq r}
(C : X → Prop) : Prop :=
∀ x y : X, C x → C y → r x y ∨ r y x.
Some usefull definitions about (sub)sets
Definition Subset {X : Type} (A : X→Prop) (B : X→Prop) : Prop :=
∀ x : X, A x → B x.
Definition Empty {X : Type} (A : X→Prop): Prop :=
∀ x : X, ¬A x.
Definition empty {X : Type} : X→Prop := fun x ⇒ False.
∀ x : X, A x → B x.
Definition Empty {X : Type} (A : X→Prop): Prop :=
∀ x : X, ¬A x.
Definition empty {X : Type} : X→Prop := fun x ⇒ False.
By the way, a non empty set contains at least one element.
This one need classical reasoning.
Proof.
split.
-
unfold empty.
intro Hempty.
apply not_all_ex_not in Hempty.
destruct Hempty as [x Hnnx].
∃ x.
apply NNPP.
assumption.
- intros [x Hx].
intro Hfalse.
apply Hfalse in Hx.
assumption.
Qed.
split.
-
unfold empty.
intro Hempty.
apply not_all_ex_not in Hempty.
destruct Hempty as [x Hnnx].
∃ x.
apply NNPP.
assumption.
- intros [x Hx].
intro Hfalse.
apply Hfalse in Hx.
assumption.
Qed.
We will need, more generally, LUB and GLB of subsets, not only of two elements.
You can define it using this inductive definition :
Inductive SubsetLUB {X : Type} {r : Relation X} `{PartialOrder X eq r}
(C: X→Prop) (lub : X) :=
∀ x y : X, C x → C y → r
Which is similar to the minimum element of a list :
Inductive min_list {X : Type} {r : Relation X} `{PartialOrder X eq r} :
list X → X → Prop :=
| nil_min : ∀ m : X, min_list nil m
| cons_min : ∀ (x m : X) (ls : list X),
min_list ls m → r x m → min_list (cons x ls) x.
However, here, I will define it similarly to the LUB of two elements.
Inductive SubsetLUB {X : Type} {r : Relation X} `{PartialOrder X eq r}
(C: X→Prop) (lub : X) :=
∀ x y : X, C x → C y → r
Inductive min_list {X : Type} {r : Relation X} `{PartialOrder X eq r} :
list X → X → Prop :=
| nil_min : ∀ m : X, min_list nil m
| cons_min : ∀ (x m : X) (ls : list X),
min_list ls m → r x m → min_list (cons x ls) x.
Definition SetUpperBound
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (a : X) : Prop :=
∀ x : X, A x → r x a.
Definition SetLowerBound
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (a : X) : Prop :=
∀ x : X, A x → r a x.
Definition SetLeastUpperBound
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (a : X) : Prop :=
SetUpperBound A a
∧ (∀ b : X, SetUpperBound A b → r a b).
Definition SetGreatestLowerBound
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (a : X) : Prop :=
SetLowerBound A a
∧ (∀ b : X, SetLowerBound A b → r b a).
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (a : X) : Prop :=
∀ x : X, A x → r x a.
Definition SetLowerBound
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (a : X) : Prop :=
∀ x : X, A x → r a x.
Definition SetLeastUpperBound
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (a : X) : Prop :=
SetUpperBound A a
∧ (∀ b : X, SetUpperBound A b → r a b).
Definition SetGreatestLowerBound
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (a : X) : Prop :=
SetLowerBound A a
∧ (∀ b : X, SetLowerBound A b → r b a).
Of course, when a set has two elements,
these notions are completely equivalent,
and can be use at the convenience of the user.
Then, unicity and other properties are exactly the same as for two elements upper bound.
Theorem slub_unicity
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(A : X→Prop) (a b : X) :
SetLeastUpperBound A a → SetLeastUpperBound A b → a = b.
Theorem sglb_unicity
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(A : X→Prop) (a b : X) :
SetGreatestLowerBound A a → SetGreatestLowerBound A b → a = b.
Lemma rel_eq_slub
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(a b : X) :
r a b ↔ SetLeastUpperBound (fun x ⇒ x = a ∨ x = b) b.
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(A : X→Prop) (a b : X) :
SetLeastUpperBound A a → SetLeastUpperBound A b → a = b.
Theorem sglb_unicity
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(A : X→Prop) (a b : X) :
SetGreatestLowerBound A a → SetGreatestLowerBound A b → a = b.
Lemma rel_eq_slub
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(a b : X) :
r a b ↔ SetLeastUpperBound (fun x ⇒ x = a ∨ x = b) b.
Proof.
split. {
intro Hr.
split.
- intros x [Hxa|Hxb].
× rewrite Hxa. assumption.
× rewrite Hxb. reflexivity.
- intros y HUBy.
apply HUBy.
right. reflexivity.
}
{
intros [HUB _].
unfold SetUpperBound in HUB.
specialize HUB with (x := a).
apply HUB.
left. reflexivity.
}
Qed.
split. {
intro Hr.
split.
- intros x [Hxa|Hxb].
× rewrite Hxa. assumption.
× rewrite Hxb. reflexivity.
- intros y HUBy.
apply HUBy.
right. reflexivity.
}
{
intros [HUB _].
unfold SetUpperBound in HUB.
specialize HUB with (x := a).
apply HUB.
left. reflexivity.
}
Qed.
Lemma rel_eq_sglb
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(a b : X) :
r a b ↔ SetGreatestLowerBound(fun x ⇒ x = a ∨ x = b) a.
{X : Type} {r : Relation X} `{Hpartial : PartialOrder X eq r}
(a b : X) :
r a b ↔ SetGreatestLowerBound(fun x ⇒ x = a ∨ x = b) a.
To define continuous functions, we will need complete partial order.
That is, partial order were all chains are totally ordered.
Class CompletePartialOrder (X : Type) (r : Relation X)
`{Hpartial : PartialOrder X eq r} : Prop := {
chain_ordering : ∀ C : X→Prop, Chain C → ∃ x, SetLeastUpperBound C x;
}.
`{Hpartial : PartialOrder X eq r} : Prop := {
chain_ordering : ∀ C : X→Prop, Chain C → ∃ x, SetLeastUpperBound C x;
}.
Let define min and max for cpo, set and subset.
Here we define min_cpo as the LUB of Empty.
We will verify that it is indeed a caracterization of the minimum (if it exists).
By the way, since we are in a CPO and that Empty is a chain, a CPO admit a minimum, hence the name.
Definition MinCPO
{X : Type} {r : Relation X}
`{HCPO : CompletePartialOrder X r} (x : X) : Prop :=
SetLeastUpperBound empty x.
Definition Min {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (m : X) :=
∀ x : X, r m x.
{X : Type} {r : Relation X}
`{HCPO : CompletePartialOrder X r} (x : X) : Prop :=
SetLeastUpperBound empty x.
Definition Min {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (m : X) :=
∀ x : X, r m x.
The min_cpo we defined is of course the min of the CPO.
Theorem min_cpo_eq_min
{X : Type} {r : Relation X}
`{HCPO : CompletePartialOrder X r}
(x : X) :
MinCPO x ↔ Min x.
{X : Type} {r : Relation X}
`{HCPO : CompletePartialOrder X r}
(x : X) :
MinCPO x ↔ Min x.
Proof.
split.
- intros Hmincpo y.
destruct Hmincpo as [_ HLUB].
apply HLUB.
intros z Hfalse.
exfalso.
assumption.
- intro Hmin.
split.
× intros y Hfalse.
exfalso.
assumption.
× intros y HUB.
apply Hmin.
Qed.
split.
- intros Hmincpo y.
destruct Hmincpo as [_ HLUB].
apply HLUB.
intros z Hfalse.
exfalso.
assumption.
- intro Hmin.
split.
× intros y Hfalse.
exfalso.
assumption.
× intros y HUB.
apply Hmin.
Qed.
Definition Max {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (m : X) :=
∀ x : X, r x m.
Definition SubsetMin {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (m : X) :=
A m ∧ (∀ x : X, A x → r m x).
Definition SubsetMax {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (m : X) :=
A m ∧ (∀ x : X, A x → r x m).
`{Hpartial : PartialOrder X eq r} (m : X) :=
∀ x : X, r x m.
Definition SubsetMin {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (m : X) :=
A m ∧ (∀ x : X, A x → r m x).
Definition SubsetMax {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} (A : X→Prop) (m : X) :=
A m ∧ (∀ x : X, A x → r x m).
Another interesting structure type are lattices.
That is, structures were all pairs of elements have a LUB and a GLB.
Class Lattice (X : Type) (r : Relation X)
`{Hpartial : PartialOrder X eq r} : Prop := {
lub2_existence : ∀ a b : X, ∃ x : X, LeastUpperBound a b x;
glb2_existence : ∀ a b : X, ∃ x : X, GreatestLowerBound a b x;
}.
`{Hpartial : PartialOrder X eq r} : Prop := {
lub2_existence : ∀ a b : X, ∃ x : X, LeastUpperBound a b x;
glb2_existence : ∀ a b : X, ∃ x : X, GreatestLowerBound a b x;
}.
And again, we need completeness to prove some things.
Of course a complete lattice is a lattice.
And a complete lattice is a complete partial order.
I won't prove it here since it's useless and trivial.
However, note that we define completeness here a bit differently.
We say that a lattice is complete if all its subsets admit a LUB and a GLB,
and if it has a minimum and a maximum.
Please note that the first property is sufficient.
But defining it this way is simpler for proof on it.
Class CompleteLattice (X : Type) (r : Relation X) (min_e max_e : X)
`{Hpartial : PartialOrder X eq r} : Prop := {
lub_existence : ∀ C: X→Prop, ∃ x : X, SetLeastUpperBound C x;
glb_existence : ∀ C: X→Prop, ∃ x : X, SetGreatestLowerBound C x;
min_existence : Min min_e;
max_existence : Max max_e;
}.
`{Hpartial : PartialOrder X eq r} : Prop := {
lub_existence : ∀ C: X→Prop, ∃ x : X, SetLeastUpperBound C x;
glb_existence : ∀ C: X→Prop, ∃ x : X, SetGreatestLowerBound C x;
min_existence : Min min_e;
max_existence : Max max_e;
}.
Forall subset of a complete lattice, the minimum element of this lattice is
a lower bound of this subset.
Lemma lb_subset_complete_lattice
{X : Type} {r : Relation X} {min_e max_e : X}
`{Hcompletelattice : CompleteLattice X r min_e max_e}
(S : X→Prop) :
SetLowerBound S min_e.
{X : Type} {r : Relation X} {min_e max_e : X}
`{Hcompletelattice : CompleteLattice X r min_e max_e}
(S : X→Prop) :
SetLowerBound S min_e.
Functions properties, fixpoints
We then define fixpoints, which are essential to the semantics we will define later (for loops)- Fixpoint is already used by rocq, so we fallback to fixpoint.
- In the course, we use FP and LFP as common notations.
Definition fixpoint {X : Type} (f : X → X) (x : X) : Prop :=
f x = x.
Definition PreFixpoint {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (x : X) : Prop :=
r x (f x).
Definition PostFixpoint {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (x : X) : Prop :=
r (f x) x.
Definition FP {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) : X → Prop :=
fun x:X ⇒ fixpoint f x.
Definition LFP {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (a : X) (lfpa : X) : Prop :=
SubsetMin (fun x:X ⇒ fixpoint f x ∧ r a x) lfpa.
Definition LFP' {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (lfp_all : X) : Prop :=
SubsetMin (fun x:X ⇒ fixpoint f x) lfp_all.
Definition GFP {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (a : X) (gfpa : X) : Prop :=
SubsetMax (fun x:X ⇒ fixpoint f x ∧ r x a) gfpa.
Definition GFP' {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (gfp_all : X) : Prop :=
SubsetMax (fun x:X ⇒ fixpoint f x) gfp_all.
f x = x.
Definition PreFixpoint {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (x : X) : Prop :=
r x (f x).
Definition PostFixpoint {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (x : X) : Prop :=
r (f x) x.
Definition FP {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) : X → Prop :=
fun x:X ⇒ fixpoint f x.
Definition LFP {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (a : X) (lfpa : X) : Prop :=
SubsetMin (fun x:X ⇒ fixpoint f x ∧ r a x) lfpa.
Definition LFP' {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (lfp_all : X) : Prop :=
SubsetMin (fun x:X ⇒ fixpoint f x) lfp_all.
Definition GFP {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (a : X) (gfpa : X) : Prop :=
SubsetMax (fun x:X ⇒ fixpoint f x ∧ r x a) gfpa.
Definition GFP' {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X → X) (gfp_all : X) : Prop :=
SubsetMax (fun x:X ⇒ fixpoint f x) gfp_all.
Unicity of differents fixpoint theorems.
TODO Remove this awfull quantity of duplicated code.
Theorem lfp_unicity {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} :
∀ (a x y : X) (f : X→X), LFP f a x → LFP f a y → x = y.
`{Hpartial : PartialOrder X eq r} :
∀ (a x y : X) (f : X→X), LFP f a x → LFP f a y → x = y.
Proof.
intros a x y f [Hfpx Hlfpx] [Hfpy Hlfpy].
apply Hlfpx in Hfpy.
apply Hlfpy in Hfpx.
apply antisymmetry; assumption.
Qed.
intros a x y f [Hfpx Hlfpx] [Hfpy Hlfpy].
apply Hlfpx in Hfpy.
apply Hlfpy in Hfpx.
apply antisymmetry; assumption.
Qed.
Theorem gfp_unicity {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} :
∀ (a x y : X) (f : X→X), GFP f a x → GFP f a y → x = y.
Theorem lfp'_unicity {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} :
∀ (x y : X) (f : X→X), LFP' f x → LFP' f y → x = y.
Theorem gfp'_unicity {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} :
∀ (x y : X) (f : X→X), GFP' f x → GFP' f y → x = y.
`{Hpartial : PartialOrder X eq r} :
∀ (a x y : X) (f : X→X), GFP f a x → GFP f a y → x = y.
Theorem lfp'_unicity {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} :
∀ (x y : X) (f : X→X), LFP' f x → LFP' f y → x = y.
Theorem gfp'_unicity {X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r} :
∀ (x y : X) (f : X→X), GFP' f x → GFP' f y → x = y.
Of course, lfp' f = lfp f min_e in a complete partial order.
Theorem lfp'_eq_lfp_min
{X : Type} {r : Relation X}
`{HCPO : CompletePartialOrder X r} :
∀ (x min_X: X) (f : X→X), MinCPO min_X →
(LFP' f x ↔ LFP f min_X x).
{X : Type} {r : Relation X}
`{HCPO : CompletePartialOrder X r} :
∀ (x min_X: X) (f : X→X), MinCPO min_X →
(LFP' f x ↔ LFP f min_X x).
Let also define some function properties.
First, classical function properties.
Definition Injective
{X Y : Type}
(f : X→Y): Prop :=
∀ x y : X, f x = f y → x = y.
Definition Surjective
{X Y : Type}
(f : X→Y): Prop :=
∀ y : Y, ∃ x : X, f x = y.
Definition Bijective
{X Y : Type}
(f : X→Y): Prop :=
Injective f ∧ Surjective f.
Theorem bijective_eq_id
{X Y : Type} (f : X→Y):
Bijective f ↔
∃ (g : Y → X), (
(∀ x : X, g (f x) = x)
∧ (∀ y : Y, f (g y) = y)).
{X Y : Type}
(f : X→Y): Prop :=
∀ x y : X, f x = f y → x = y.
Definition Surjective
{X Y : Type}
(f : X→Y): Prop :=
∀ y : Y, ∃ x : X, f x = y.
Definition Bijective
{X Y : Type}
(f : X→Y): Prop :=
Injective f ∧ Surjective f.
Theorem bijective_eq_id
{X Y : Type} (f : X→Y):
Bijective f ↔
∃ (g : Y → X), (
(∀ x : X, g (f x) = x)
∧ (∀ y : Y, f (g y) = y)).
Need choice
apply choice with (R := fun y x ⇒ f x = y).
intro x.
apply Hsurjective.
}
destruct Hfg as [g Hfg].
∃ g.
split.
× intro x.
apply Hinjective.
rewrite Hfg.
reflexivity.
× assumption.
- intros [g [Hid Hid']].
split.
× unfold Injective.
intros x y Hfeq.
specialize Hid with (x := x) as Hidx.
specialize Hid with (x := y) as Hidy.
rewrite <- Hidx.
rewrite <- Hidy.
f_equal.
assumption.
× unfold Surjective.
intro y.
∃ (g y).
rewrite Hid'.
reflexivity.
Qed.
intro x.
apply Hsurjective.
}
destruct Hfg as [g Hfg].
∃ g.
split.
× intro x.
apply Hinjective.
rewrite Hfg.
reflexivity.
× assumption.
- intros [g [Hid Hid']].
split.
× unfold Injective.
intros x y Hfeq.
specialize Hid with (x := x) as Hidx.
specialize Hid with (x := y) as Hidy.
rewrite <- Hidx.
rewrite <- Hidy.
f_equal.
assumption.
× unfold Surjective.
intro y.
∃ (g y).
rewrite Hid'.
reflexivity.
Qed.
Then, functions on partial order properties.
Definition Extensive
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X→X): Prop :=
∀ x : X, r x (f x).
Definition Reductive
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X→X): Prop :=
∀ x : X, r (f x) x.
Definition Monotone {X Y : Type} {rx : Relation X} {ry : Relation Y}
`{HpartialX : PartialOrder X eq rx} `{HpartialY : PartialOrder Y eq ry}
(f : X → Y) :=
∀ x y : X, rx x y → ry (f x) (f y).
Definition Continuous
{X Y : Type} {rx : Relation X} {ry : Relation Y}
`{HCPOX : CompletePartialOrder X rx} `{HpartialY : PartialOrder Y eq ry}
(f : X → Y) :=
∀ C : X→Prop,
let fC := (fun y:Y ⇒ ∃ x : X, C x ∧ f x = y) in
Chain fC
∧ ∀ (UC : X), SetLeastUpperBound C UC ↔ SetLeastUpperBound fC (f UC).
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X→X): Prop :=
∀ x : X, r x (f x).
Definition Reductive
{X : Type} {r : Relation X}
`{Hpartial : PartialOrder X eq r}
(f : X→X): Prop :=
∀ x : X, r (f x) x.
Definition Monotone {X Y : Type} {rx : Relation X} {ry : Relation Y}
`{HpartialX : PartialOrder X eq rx} `{HpartialY : PartialOrder Y eq ry}
(f : X → Y) :=
∀ x y : X, rx x y → ry (f x) (f y).
Definition Continuous
{X Y : Type} {rx : Relation X} {ry : Relation Y}
`{HCPOX : CompletePartialOrder X rx} `{HpartialY : PartialOrder Y eq ry}
(f : X → Y) :=
∀ C : X→Prop,
let fC := (fun y:Y ⇒ ∃ x : X, C x ∧ f x = y) in
Chain fC
∧ ∀ (UC : X), SetLeastUpperBound C UC ↔ SetLeastUpperBound fC (f UC).
Interestingly, continuous functions are monotone.
Theorem continuous_imp_monotone
{X Y : Type} {rx : Relation X} {ry : Relation Y}
`{HCPOX : CompletePartialOrder X rx} `{HpartialY : PartialOrder Y eq ry}
(f : X → Y) :
Continuous f → Monotone f.
{X Y : Type} {rx : Relation X} {ry : Relation Y}
`{HCPOX : CompletePartialOrder X rx} `{HpartialY : PartialOrder Y eq ry}
(f : X → Y) :
Continuous f → Monotone f.
We will apply Hcontinuous,
on a chain of two elements, x and y
First, we want to simplify Hcontinuous,
because f C can be rewritten in a simpler way
assert (H :
(fun y0 : Y ⇒ ∃ x0 : X, (x0 = x ∨ x0 = y) ∧ f x0 = y0)
= (fun a ⇒ a = f x ∨ a = f y)). {
apply Extensionality_Ensembles.
split.
- intros x' Hin.
unfold In in Hin.
destruct Hin as [x0 [[Hx0eqx | Hx0eqy] Hfxeqx]].
unfold In.
× left.
rewrite <- Hx0eqx.
rewrite Hfxeqx.
reflexivity.
× right.
rewrite <- Hx0eqy.
rewrite Hfxeqx.
reflexivity.
- intros x' Hin.
unfold In in Hin.
unfold In.
destruct Hin as [Hxeqfx|Hxeqfy].
× ∃ x.
split.
** left. reflexivity.
** rewrite Hxeqfx. reflexivity.
× ∃ y.
split.
** right. reflexivity.
** rewrite Hxeqfy. reflexivity.
}
rewrite H in Hcontinuous.
destruct Hcontinuous as [_ Hlub].
(fun y0 : Y ⇒ ∃ x0 : X, (x0 = x ∨ x0 = y) ∧ f x0 = y0)
= (fun a ⇒ a = f x ∨ a = f y)). {
apply Extensionality_Ensembles.
split.
- intros x' Hin.
unfold In in Hin.
destruct Hin as [x0 [[Hx0eqx | Hx0eqy] Hfxeqx]].
unfold In.
× left.
rewrite <- Hx0eqx.
rewrite Hfxeqx.
reflexivity.
× right.
rewrite <- Hx0eqy.
rewrite Hfxeqx.
reflexivity.
- intros x' Hin.
unfold In in Hin.
unfold In.
destruct Hin as [Hxeqfx|Hxeqfy].
× ∃ x.
split.
** left. reflexivity.
** rewrite Hxeqfx. reflexivity.
× ∃ y.
split.
** right. reflexivity.
** rewrite Hxeqfy. reflexivity.
}
rewrite H in Hcontinuous.
destruct Hcontinuous as [_ Hlub].
Let show that f x <= f y, because of lub hypothesis :
This is the same as showing that lub {(f x) (f y)} = f y
By lub hypothesis (continuity), we have to show that
lub { x y } = y, e.g. r x y. Which is our hypothesis.
We can also define the notion of join morphism,
which does not require completeness.
A continuous application is a join morphism, which is itself monotone.
TODO : Prove it (I did the proof of mononicity of continuous app before,
which basically combine both proof).
Definition JoinMorphism
{X Y : Type} {rx : Relation X} {ry : Relation Y}
`{HpartialX : PartialOrder X eq rx} `{HpartialY : PartialOrder Y eq ry}
(f : X→Y) : Prop :=
∀ a b : X,
∀ (Ufab : Y) (Uab : X),
LeastUpperBound a b Uab → LeastUpperBound (f a) (f b) Ufab
→ f Uab = Ufab.
{X Y : Type} {rx : Relation X} {ry : Relation Y}
`{HpartialX : PartialOrder X eq rx} `{HpartialY : PartialOrder Y eq ry}
(f : X→Y) : Prop :=
∀ a b : X,
∀ (Ufab : Y) (Uab : X),
LeastUpperBound a b Uab → LeastUpperBound (f a) (f b) Ufab
→ f Uab = Ufab.
Now,
we will prove two theorems stating the existence of fixpoints for monotone/continuous functions,
and caracterizing them.
These are the tarski (for monotone functions on complete lattices)
and kleene (for continuous functions on CPO) theorems.
The proof are a bit long.
Let begin with the tarski theorem.
Theorem tarski_fixpoint
{X : Type} {rx : Relation X} {min_e : X} {max_e : X}
`{Hcompletelattice : CompleteLattice X rx min_e max_e}
(f : X→X) :
Monotone f →
(∃ (x : X), (FP f) x)
∧ ∀ Ux : X,
SetGreatestLowerBound (fun x : X ⇒ PostFixpoint f x) Ux ↔ LFP' f Ux.
{X : Type} {rx : Relation X} {min_e : X} {max_e : X}
`{Hcompletelattice : CompleteLattice X rx min_e max_e}
(f : X→X) :
Monotone f →
(∃ (x : X), (FP f) x)
∧ ∀ Ux : X,
SetGreatestLowerBound (fun x : X ⇒ PostFixpoint f x) Ux ↔ LFP' f Ux.
Proof.
intro Hmonotone.
intro Hmonotone.
In order to prove existence, we need to construct the fixpoint,
eg to use the second point
assert (
HGLBimpLFP : ∀ Ux : X,
SetGreatestLowerBound (fun x : X ⇒ PostFixpoint f x) Ux → LFP' f Ux
). {
intros Ux [HLBUx HGLBUx].
split.
- unfold fixpoint.
assert (HUxpostfixpoint : PostFixpoint f Ux). {
HGLBimpLFP : ∀ Ux : X,
SetGreatestLowerBound (fun x : X ⇒ PostFixpoint f x) Ux → LFP' f Ux
). {
intros Ux [HLBUx HGLBUx].
split.
- unfold fixpoint.
assert (HUxpostfixpoint : PostFixpoint f Ux). {
First, we show that f Ux is a lower bound of postfixpoint
assert (HUxLBpostfixpoints : SetLowerBound (fun x ⇒ PostFixpoint f x) (f Ux)). {
intros x Hpostfixpointx.
apply transitivity with (y := f x).
- apply Hmonotone.
apply HLBUx in Hpostfixpointx.
assumption.
- assumption.
}
intros x Hpostfixpointx.
apply transitivity with (y := f x).
- apply Hmonotone.
apply HLBUx in Hpostfixpointx.
assumption.
- assumption.
}
Thus, since Ux is the greatest lower bound, f Ux <= Ux
apply HGLBUx in HUxLBpostfixpoints.
assumption.
}
apply antisymmetry.
× assumption.
× apply Hmonotone in HUxpostfixpoint.
assumption.
}
apply antisymmetry.
× assumption.
× apply Hmonotone in HUxpostfixpoint.
f Ux is a postfixpoint
apply HLBUx in HUxpostfixpoint.
Thus Ux is lower than f Ux
assumption.
- intros x Hfixpointx.
assert (Hpostfixpointx : PostFixpoint f x). {
unfold PostFixpoint.
rewrite Hfixpointx.
reflexivity.
}
apply HLBUx in Hpostfixpointx.
assumption.
}
- intros x Hfixpointx.
assert (Hpostfixpointx : PostFixpoint f x). {
unfold PostFixpoint.
rewrite Hfixpointx.
reflexivity.
}
apply HLBUx in Hpostfixpointx.
assumption.
}
It's almost enough to prove everything,
but we first need to construct the lfp as the join of the GLB.
destruct glb_existence with (C := (fun x ⇒ PostFixpoint f x)) as [x HGLBx].
split.
- ∃ x.
apply HGLBimpLFP in HGLBx.
destruct HGLBx as [Hfp _].
assumption.
- split.
× apply HGLBimpLFP.
× intro Hlfp.
apply HGLBimpLFP in HGLBx as Hlfpx.
assert (HxUx : Ux = x). {
apply lfp'_unicity with (f := f); assumption.
}
rewrite HxUx.
destruct HGLBx as [HLBx HGLBx].
split.
+ intros y Hpostfixpoint.
apply HLBx.
assumption.
+ intros y HLBy.
apply HGLBx.
assumption.
Qed.
split.
- ∃ x.
apply HGLBimpLFP in HGLBx.
destruct HGLBx as [Hfp _].
assumption.
- split.
× apply HGLBimpLFP.
× intro Hlfp.
apply HGLBimpLFP in HGLBx as Hlfpx.
assert (HxUx : Ux = x). {
apply lfp'_unicity with (f := f); assumption.
}
rewrite HxUx.
destruct HGLBx as [HLBx HGLBx].
split.
+ intros y Hpostfixpoint.
apply HLBx.
assumption.
+ intros y HLBy.
apply HGLBx.
assumption.
Qed.
We will need the following Lemma about LUB composition :
Lemma lub_composition
{X : Type} {rx : Relation X}
`{Hpartial : PartialOrder X eq rx}
(A : X→Prop) (B : X→Prop) (a b c : X) :
SetLeastUpperBound A a →
SetLeastUpperBound B b →
LeastUpperBound a b c →
SetLeastUpperBound (union A B) c.
{X : Type} {rx : Relation X}
`{Hpartial : PartialOrder X eq rx}
(A : X→Prop) (B : X→Prop) (a b c : X) :
SetLeastUpperBound A a →
SetLeastUpperBound B b →
LeastUpperBound a b c →
SetLeastUpperBound (union A B) c.
Now, we can prove kleene theorem.
Theorem kleene_fixpoint
{X : Type} {rx : Relation X}
`{HCPO : CompletePartialOrder X rx}
(f : X→X) :
Continuous f →
∀ a : X, PreFixpoint f a →
let fa_iterate := (fun x : X ⇒ ∃ n : nat, x = iter f n a) in
(∃ Ux : X, SetLeastUpperBound fa_iterate Ux)
∧ (∀ Ux : X, SetLeastUpperBound fa_iterate Ux ↔ LFP f a Ux).
{X : Type} {rx : Relation X}
`{HCPO : CompletePartialOrder X rx}
(f : X→X) :
Continuous f →
∀ a : X, PreFixpoint f a →
let fa_iterate := (fun x : X ⇒ ∃ n : nat, x = iter f n a) in
(∃ Ux : X, SetLeastUpperBound fa_iterate Ux)
∧ (∀ Ux : X, SetLeastUpperBound fa_iterate Ux ↔ LFP f a Ux).
Proof.
intros Hcontinuous a Hprefixpoint fa_iterate.
intros Hcontinuous a Hprefixpoint fa_iterate.
Remark that since f is continuous, it is monotone
Remark that, forall n1 n2, n1 <= n2 -> f^n1 a <= f^n2 a.
assert (Hiterorder : ∀ n1 n2 : nat, n1 ≤ n2 → rx (iter f n1 a) (iter f n2 a)). {
assert (Hdecreasing : ∀ n1 : nat, rx (iter f n1 a) (iter f (S n1) a)). {
induction n1 as [|n1 IHn].
- simpl.
assumption.
- simpl.
apply Hmonotone.
assumption.
}
intros n1 n2 Hn1n2.
apply Nat.le_exists_sub in Hn1n2.
destruct Hn1n2 as [m [Hadd _]].
generalize dependent n2.
induction m as [| m IHm]; intros n2 Hadd.
- rewrite Hadd. reflexivity.
- rewrite Hadd.
apply transitivity with (y := iter f (m + n1) a).
× apply IHm.
reflexivity.
× apply Hdecreasing.
}
assert (Hdecreasing : ∀ n1 : nat, rx (iter f n1 a) (iter f (S n1) a)). {
induction n1 as [|n1 IHn].
- simpl.
assumption.
- simpl.
apply Hmonotone.
assumption.
}
intros n1 n2 Hn1n2.
apply Nat.le_exists_sub in Hn1n2.
destruct Hn1n2 as [m [Hadd _]].
generalize dependent n2.
induction m as [| m IHm]; intros n2 Hadd.
- rewrite Hadd. reflexivity.
- rewrite Hadd.
apply transitivity with (y := iter f (m + n1) a).
× apply IHm.
reflexivity.
× apply Hdecreasing.
}
Now, we prove existence since we will use it for caracterization.
In order to prove existence, we can prove that the set of iterates is a chain,
because we are in a CPO
apply chain_ordering.
unfold Chain.
intros x y [nx Hiterx] [ny Hitery].
rewrite Hiterx. rewrite Hitery.
unfold Chain.
intros x y [nx Hiterx] [ny Hitery].
rewrite Hiterx. rewrite Hitery.
For this, we can apply the fact that iterates are ordered,
along with the fact that natural are totally ordered.
destruct nat_total_order with (x := nx) (y := ny) as [Hxy|Hyx].
× left.
apply Hiterorder.
assumption.
× right.
apply Hiterorder.
assumption.
}
× left.
apply Hiterorder.
assumption.
× right.
apply Hiterorder.
assumption.
}
And then, we prove that if it is the LUB, it is the LFP because we need it for the other way of the proof.
assert (lub_imp_lfp : ∀ Ux : X, SetLeastUpperBound fa_iterate Ux → LFP f a Ux). {
intro Ux.
intro HLUBUx.
unfold SubsetMin.
split.
× split.
+
intro Ux.
intro HLUBUx.
unfold SubsetMin.
split.
× split.
+
To show that Ux is a fixpoint, let show that f Ux is also a LUB
Since f Ux is the least upper bound of f fa_iterate because f is continuous,
and that a <= Ux <= f Ux, f Ux is the lub of a \/ f fa_iterate.
Thus we first show that fa_iterate = a \/ f fa_iterate.
assert (Hafeqf : (fun x ⇒ x = a ∨ (∃ y, fa_iterate y ∧ f y = x))
= fa_iterate). {
apply Extensionality_Ensembles.
split.
- intros x Haf.
unfold In.
unfold fa_iterate.
destruct Haf as [Ha | Hf].
× rewrite Ha.
∃ 0.
reflexivity.
× destruct Hf as [y [[n Hfa] Hxeqfy]].
rewrite <- Hxeqfy.
∃ (S n).
simpl.
rewrite Hfa.
reflexivity.
- intros x [n Hfa].
unfold In.
destruct n.
× left. rewrite Hfa. reflexivity.
× right.
∃ (iter f n a).
split.
** ∃ n. reflexivity.
** rewrite Hfa. reflexivity.
}
rewrite <- Hafeqf.
= fa_iterate). {
apply Extensionality_Ensembles.
split.
- intros x Haf.
unfold In.
unfold fa_iterate.
destruct Haf as [Ha | Hf].
× rewrite Ha.
∃ 0.
reflexivity.
× destruct Hf as [y [[n Hfa] Hxeqfy]].
rewrite <- Hxeqfy.
∃ (S n).
simpl.
rewrite Hfa.
reflexivity.
- intros x [n Hfa].
unfold In.
destruct n.
× left. rewrite Hfa. reflexivity.
× right.
∃ (iter f n a).
split.
** ∃ n. reflexivity.
** rewrite Hfa. reflexivity.
}
rewrite <- Hafeqf.
Now we can prove what we stated above
apply lub_composition with (a := a) (b := f Ux).
× split.
+ intros x Hx.
rewrite Hx. reflexivity.
+ intros b HUBb.
apply HUBb. reflexivity.
× destruct Hcontinuous with (C := fa_iterate) as [_ HLUBeq].
apply HLUBeq in HLUBUx.
assumption.
× destruct HLUBUx as [HUBUx HLUBUx].
split.
+ split.
- rewrite Hprefixpoint.
apply Hmonotone.
apply HUBUx.
∃ 0. reflexivity.
- reflexivity.
+ intros x HUBx.
destruct HUBx as [_ HUBx].
assumption.
}
× split.
+ intros x Hx.
rewrite Hx. reflexivity.
+ intros b HUBb.
apply HUBb. reflexivity.
× destruct Hcontinuous with (C := fa_iterate) as [_ HLUBeq].
apply HLUBeq in HLUBUx.
assumption.
× destruct HLUBUx as [HUBUx HLUBUx].
split.
+ split.
- rewrite Hprefixpoint.
apply Hmonotone.
apply HUBUx.
∃ 0. reflexivity.
- reflexivity.
+ intros x HUBx.
destruct HUBx as [_ HUBx].
assumption.
}
Then we can conclude by unicity
By the way, it is greater than a, since a is an iterate,
and it is an upper bound of iterates.
destruct HLUBUx as [HLUB _].
apply HLUB.
∃ 0. reflexivity.
×
apply HLUB.
∃ 0. reflexivity.
×
It is also the least fixpoint greater than a :
intros x [Hfixpoint Hax].
destruct HLUBUx as [_ HLUBUx].
destruct HLUBUx as [_ HLUBUx].
We use the fact that Ux is the lub. It remains to prove that x is an upper bound.
apply HLUBUx.
intros y [n Hin].
rewrite Hin.
generalize dependent y.
intros y [n Hin].
rewrite Hin.
generalize dependent y.
We prove by induction that forall n, iter f n a <= x
induction n as [|n IHn]; intros y Hy.
+ assumption.
+ simpl.
specialize IHn with (y := iter f n a).
rewrite <- Hfixpoint.
apply Hmonotone.
apply IHn.
reflexivity.
}
+ assumption.
+ simpl.
specialize IHn with (y := iter f n a).
rewrite <- Hfixpoint.
apply Hmonotone.
apply IHn.
reflexivity.
}
Now, let do the main proof.
split.
- assumption.
- split.
× apply lub_imp_lfp.
×
- assumption.
- split.
× apply lub_imp_lfp.
×
Secondly, if it is the lfp, it is the lub.
intro Hlfp.
destruct Hexists as [Ux' HLUB].
apply lub_imp_lfp in HLUB as Hlfp'.
assert (Ux = Ux'). {
apply lfp_unicity with (a := a) (f := f); assumption.
}
rewrite H.
assumption.
Qed.
destruct Hexists as [Ux' HLUB].
apply lub_imp_lfp in HLUB as Hlfp'.
assert (Ux = Ux'). {
apply lfp_unicity with (a := a) (f := f); assumption.
}
rewrite H.
assumption.
Qed.
Concretisation & Galois connections.
Definition Concretisation
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A → C) : Prop := Monotone gamma.
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A → C) : Prop := Monotone gamma.
If we also have an abstraction function, we can define Galois Connections, which benefits from some interesting properties stated afterwise.
Definition GaloisConnection
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(alpha : C→A) (gamma : A→C) : Prop :=
∀ (a : A) (c : C),
ra (alpha c) a ↔ rc c (gamma a).
Notation " alpha 'a<->c' gamma" := (GaloisConnection alpha gamma)
(at level 50, left associativity).
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(alpha : C→A) (gamma : A→C) : Prop :=
∀ (a : A) (c : C),
ra (alpha c) a ↔ rc c (gamma a).
Notation " alpha 'a<->c' gamma" := (GaloisConnection alpha gamma)
(at level 50, left associativity).
We can caracterize galois connections by properties on the abstraction/concretisation functions, which is usefull for some theorems.
Theorem galois_caracterisation
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(alpha : C→A) (gamma : A→C) :
alpha a↔c gamma
↔
( Monotone alpha
∧ Monotone gamma
∧ Extensive (gamma o alpha)
∧ Reductive (alpha o gamma)).
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(alpha : C→A) (gamma : A→C) :
alpha a↔c gamma
↔
( Monotone alpha
∧ Monotone gamma
∧ Extensive (gamma o alpha)
∧ Reductive (alpha o gamma)).
split.
- intro Hgalois.
assert (ga_extensive : Extensive (gamma o alpha)). {
intros x.
apply Hgalois.
reflexivity.
}
assert (ag_reductive : Reductive (alpha o gamma)). {
intros x.
apply Hgalois.
reflexivity.
}
split. {
intros x y Hxy.
apply Hgalois.
apply transitivity with (y := y).
+ assumption.
+ apply ga_extensive.
}
split. {
intros x y Hxy.
apply Hgalois.
apply transitivity with (y := x).
+ apply ag_reductive.
+ assumption.
}
split; assumption.
- intros [monotone_alpha [monotone_gamma [extensive_ga reductive_ag]]].
intros a c.
split.
× intro Haca.
apply monotone_gamma in Haca.
apply transitivity with (y := gamma (alpha c)).
+ apply extensive_ga.
+ assumption.
× intro Hcga.
apply monotone_alpha in Hcga.
apply transitivity with (y := alpha (gamma a)).
+ assumption.
+ apply reductive_ag.
Qed.
- intro Hgalois.
assert (ga_extensive : Extensive (gamma o alpha)). {
intros x.
apply Hgalois.
reflexivity.
}
assert (ag_reductive : Reductive (alpha o gamma)). {
intros x.
apply Hgalois.
reflexivity.
}
split. {
intros x y Hxy.
apply Hgalois.
apply transitivity with (y := y).
+ assumption.
+ apply ga_extensive.
}
split. {
intros x y Hxy.
apply Hgalois.
apply transitivity with (y := x).
+ apply ag_reductive.
+ assumption.
}
split; assumption.
- intros [monotone_alpha [monotone_gamma [extensive_ga reductive_ag]]].
intros a c.
split.
× intro Haca.
apply monotone_gamma in Haca.
apply transitivity with (y := gamma (alpha c)).
+ apply extensive_ga.
+ assumption.
× intro Hcga.
apply monotone_alpha in Hcga.
apply transitivity with (y := alpha (gamma a)).
+ assumption.
+ apply reductive_ag.
Qed.
Definition GaloisEmbedding
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(alpha : C→A) (gamma : A→C) : Prop :=
alpha a↔c gamma ∧ Injective gamma.
Notation " alpha 'a<<->c' gamma" := (GaloisEmbedding alpha gamma)
(at level 50, left associativity).
Definition GaloisBijection
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(alpha : C→A) (gamma : A→C) : Prop :=
alpha a↔c gamma ∧ Bijective gamma.
Notation " alpha 'a<<->>c' gamma" := (GaloisBijection alpha gamma)
(at level 50, left associativity).
Sound, exact & best abstractions
Definition Sound
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (a : A) (c : C) : Prop :=
Concretisation gamma → rc c (gamma a).
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (a : A) (c : C) : Prop :=
Concretisation gamma → rc c (gamma a).
We say that g is a sound abstraction of f if, given a concretization gamma :
Definition SoundAbstraction
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f : C→C) (g : A→A) : Prop :=
Concretisation gamma →
∀ a : A, rc (f (gamma a)) (gamma (g a)).
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f : C→C) (g : A→A) : Prop :=
Concretisation gamma →
∀ a : A, rc (f (gamma a)) (gamma (g a)).
We can also define exact and bests abstractions.
Definition ExactAbstraction
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f : C→C) (g : A→A) : Prop :=
Concretisation gamma →
∀ a : A, f (gamma a) = gamma (g a).
Definition BestAbstraction
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f : C→C) (g : A→A) : Prop :=
SoundAbstraction gamma f g
∧ ∀ g' : A→A, SoundAbstraction gamma f g' →
∀ a : A, ra (g a) (g' a).
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f : C→C) (g : A→A) : Prop :=
Concretisation gamma →
∀ a : A, f (gamma a) = gamma (g a).
Definition BestAbstraction
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f : C→C) (g : A→A) : Prop :=
SoundAbstraction gamma f g
∧ ∀ g' : A→A, SoundAbstraction gamma f g' →
∀ a : A, ra (g a) (g' a).
A very interesting thing is that we can create a best abstraction for a function,
from a galois connection.
It is one of the main interest of galois connections for our purpose.
Theorem galois_connection_imp_best_abstraction
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(alpha : C→ A) (gamma : A→C) (f : C→C) :
alpha a↔c gamma →
BestAbstraction gamma f (alpha o f o gamma).
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(alpha : C→ A) (gamma : A→C) (f : C→C) :
alpha a↔c gamma →
BestAbstraction gamma f (alpha o f o gamma).
Proof.
intro Hgalois.
split.
× intros Hconcrete a.
apply Hgalois.
reflexivity.
× intros g' Hsoundg' a.
unfold SoundAbstraction in Hsoundg'.
apply galois_caracterisation in Hgalois.
destruct Hgalois as [monotone_alpha [ monotone_gamma [extensive_ga reductive_ag]]].
specialize Hsoundg' with (a := a).
apply monotone_alpha in Hsoundg'.
- apply transitivity with (y := alpha (gamma (g' a))).
+ assumption.
+ apply reductive_ag.
- apply monotone_gamma.
Qed.
intro Hgalois.
split.
× intros Hconcrete a.
apply Hgalois.
reflexivity.
× intros g' Hsoundg' a.
unfold SoundAbstraction in Hsoundg'.
apply galois_caracterisation in Hgalois.
destruct Hgalois as [monotone_alpha [ monotone_gamma [extensive_ga reductive_ag]]].
specialize Hsoundg' with (a := a).
apply monotone_alpha in Hsoundg'.
- apply transitivity with (y := alpha (gamma (g' a))).
+ assumption.
+ apply reductive_ag.
- apply monotone_gamma.
Qed.
We can soundly compose abstractions, given that the concrete functions are monotones.
Theorem sound_composition
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f f' : C→C) (g g' : A→A) :
Concretisation gamma →
SoundAbstraction gamma f g →
SoundAbstraction gamma f' g' →
Monotone f →
SoundAbstraction gamma (f o f') (g o g').
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f f' : C→C) (g g' : A→A) :
Concretisation gamma →
SoundAbstraction gamma f g →
SoundAbstraction gamma f' g' →
Monotone f →
SoundAbstraction gamma (f o f') (g o g').
Proof.
intros Hconcrete Hgsound Hg'sound Hfmonotone.
intros _ a.
apply transitivity with (y := f (gamma (g' a))).
× apply Hfmonotone.
apply Hg'sound.
assumption.
× apply Hgsound.
assumption.
Qed.
intros Hconcrete Hgsound Hg'sound Hfmonotone.
intros _ a.
apply transitivity with (y := f (gamma (g' a))).
× apply Hfmonotone.
apply Hg'sound.
assumption.
× apply Hgsound.
assumption.
Qed.
Composition of exact abstractions also remains exact.
But beware that it is not the case for best abstractions !
Theorem exact_composition
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f f' : C→C) (g g' : A→A) :
Concretisation gamma →
ExactAbstraction gamma f g →
ExactAbstraction gamma f' g' →
ExactAbstraction gamma (f o f') (g o g').
{A C : Type} {ra : Relation A} {rc : Relation C}
`{HpartialA : PartialOrder A eq ra} `{HpartialC : PartialOrder C eq rc}
(gamma : A→C) (f f' : C→C) (g g' : A→A) :
Concretisation gamma →
ExactAbstraction gamma f g →
ExactAbstraction gamma f' g' →
ExactAbstraction gamma (f o f') (g o g').
intros Hconcrete Hgexact Hg'exact.
intros _ a.
apply transitivity with (y := f (gamma (g' a))).
× unfold "o".
f_equal.
apply Hg'exact.
assumption.
× apply Hgexact.
assumption.
Qed.
intros _ a.
apply transitivity with (y := f (gamma (g' a))).
× unfold "o".
f_equal.
apply Hg'exact.
assumption.
× apply Hgexact.
assumption.
Qed.
And finally, we can soundly approximate fixpoint of abstractions, using the two fixpoints theorem we saw earlier, which will allow us to find postfixpoint for our abstract semantics and to prove that they are sound.
Theorem tarski_approximation
{A C : Type} {ra : Relation A} {min_a max_a : A} {rc : Relation C} {min_c max_c : C}
`{HCLA : CompleteLattice A ra min_a max_a}
`{HCLC : CompleteLattice C rc min_c max_c}
(gamma : A→C) (f : C→C) (g : A→A) :
Concretisation gamma →
Monotone f →
SoundAbstraction gamma f g →
∀ a,
PostFixpoint g a →
∀ lfp_all, LFP' f lfp_all → rc lfp_all (gamma a).
{A C : Type} {ra : Relation A} {min_a max_a : A} {rc : Relation C} {min_c max_c : C}
`{HCLA : CompleteLattice A ra min_a max_a}
`{HCLC : CompleteLattice C rc min_c max_c}
(gamma : A→C) (f : C→C) (g : A→A) :
Concretisation gamma →
Monotone f →
SoundAbstraction gamma f g →
∀ a,
PostFixpoint g a →
∀ lfp_all, LFP' f lfp_all → rc lfp_all (gamma a).
Proof.
intros Hconcrete Hfmonotone Hsoundg a Hpostfixpointa lfp_all Hlfp.
apply tarski_fixpoint in Hlfp.
- apply Hlfp.
unfold PostFixpoint.
unfold SoundAbstraction in Hsoundg.
apply transitivity with (y := gamma (g a)).
× apply Hsoundg.
assumption.
× apply Hconcrete.
apply Hpostfixpointa.
- assumption.
Qed.
intros Hconcrete Hfmonotone Hsoundg a Hpostfixpointa lfp_all Hlfp.
apply tarski_fixpoint in Hlfp.
- apply Hlfp.
unfold PostFixpoint.
unfold SoundAbstraction in Hsoundg.
apply transitivity with (y := gamma (g a)).
× apply Hsoundg.
assumption.
× apply Hconcrete.
apply Hpostfixpointa.
- assumption.
Qed.
Theorem kleene_approximation
{A C : Type} {ra : Relation A} {min_e max_e : A} {rc : Relation C}
`{HCLA : CompleteLattice A ra min_e max_e}
`{HCPOC : CompletePartialOrder C rc}
(gamma : A→C) (f : C→C) (g : A→A) :
Concretisation gamma →
Continuous f →
SoundAbstraction gamma f g →
∀ x,
SetLeastUpperBound (fun x ⇒ ∃ i, iter g i min_e = x) x →
∀ lfp_all, LFP' f lfp_all → rc lfp_all (gamma x).
{A C : Type} {ra : Relation A} {min_e max_e : A} {rc : Relation C}
`{HCLA : CompleteLattice A ra min_e max_e}
`{HCPOC : CompletePartialOrder C rc}
(gamma : A→C) (f : C→C) (g : A→A) :
Concretisation gamma →
Continuous f →
SoundAbstraction gamma f g →
∀ x,
SetLeastUpperBound (fun x ⇒ ∃ i, iter g i min_e = x) x →
∀ lfp_all, LFP' f lfp_all → rc lfp_all (gamma x).
Proof.
intros Hconcrete Hfcontinuous Hgsound x HLUBx lfp_all Hlfp_all.
assert (HminCexists : ∃ min_C : C, MinCPO min_C). {
apply chain_ordering.
intros x' y _ Hfalse.
exfalso.
apply Hfalse.
}
destruct HminCexists as [min_C HminC].
apply lfp'_eq_lfp_min with (min_X := min_C)
in Hlfp_all.
× apply kleene_fixpoint in Hlfp_all.
+
intros Hconcrete Hfcontinuous Hgsound x HLUBx lfp_all Hlfp_all.
assert (HminCexists : ∃ min_C : C, MinCPO min_C). {
apply chain_ordering.
intros x' y _ Hfalse.
exfalso.
apply Hfalse.
}
destruct HminCexists as [min_C HminC].
apply lfp'_eq_lfp_min with (min_X := min_C)
in Hlfp_all.
× apply kleene_fixpoint in Hlfp_all.
+
lfp <= gamma x
<- forall i, f^i (gamma min_e) <= gamma g^i min_e <= gamma x
apply Hlfp_all.
intros y [n Hy].
rewrite Hy.
apply transitivity with (y := gamma (iter g n min_e)).
- generalize dependent y.
induction n; intros y Hy.
** simpl.
apply min_cpo_eq_min in HminC.
apply HminC.
** simpl.
apply transitivity with (y := f (gamma (iter g n min_e))).
++ apply continuous_imp_monotone in Hfcontinuous.
apply Hfcontinuous.
apply IHn with (y := iter f n min_C). reflexivity.
++ apply Hgsound.
apply Hconcrete.
- apply Hconcrete.
apply HLUBx.
∃ n. reflexivity.
+ assumption.
+ apply min_cpo_eq_min in HminC.
apply HminC.
× assumption.
Qed.
intros y [n Hy].
rewrite Hy.
apply transitivity with (y := gamma (iter g n min_e)).
- generalize dependent y.
induction n; intros y Hy.
** simpl.
apply min_cpo_eq_min in HminC.
apply HminC.
** simpl.
apply transitivity with (y := f (gamma (iter g n min_e))).
++ apply continuous_imp_monotone in Hfcontinuous.
apply Hfcontinuous.
apply IHn with (y := iter f n min_C). reflexivity.
++ apply Hgsound.
apply Hconcrete.
- apply Hconcrete.
apply HLUBx.
∃ n. reflexivity.
+ assumption.
+ apply min_cpo_eq_min in HminC.
apply HminC.
× assumption.
Qed.