-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFixedPoint.agda
152 lines (123 loc) · 5.43 KB
/
FixedPoint.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
module FixedPoint where
open import Level renaming (_⊔_ to _⊔ℓ_)
open import Relation.Binary
open import Data.Product
open import AlgebraicReasoning.Implications
-- LowerBound P _≼_ lb : lb is a lowerbound for elements
-- satsifying P.
LowerBound : ∀ {i j} {A : Set i}
→ (P : A → Set j)
→ (_≼_ : A → A → Set j)
→ A → Set (i ⊔ℓ j)
LowerBound P _≼_ lb = ∀ {x} → P x → lb ≼ x
-- Least P _≼_ x : x is a least element that satisfies P.
Least : ∀ {i j} {A : Set i}
→ (P : A → Set j)
→ (_≼_ : A → A → Set j)
→ A → Set (i ⊔ℓ j)
Least P _≼_ x = (P x × LowerBound P _≼_ x)
-- Least prefixed-point.
PrefixP : ∀ {i j} {A : Set i}
→ (_≼_ : A → A → Set j)
→ (f : A → A) → (μf : A)
→ Set j
PrefixP _≼_ f x = f x ≼ x
LeastPrefixedPoint : ∀ {i j} {A : Set i}
→ (_≼_ : A → A → Set j)
→ (f : A → A) → (μf : A) → Set (i ⊔ℓ j)
LeastPrefixedPoint _≼_ f = Least (PrefixP _≼_ f) _≼_
-- Least fixed-point.
-- FixP has the same definition as PrefixP. Anyway,
-- repeated for clarity.
FixP : ∀ {i j} {A : Set i}
→ (_≈_ : A → A → Set j) → (f : A → A)
→ (μf : A) → Set j
FixP _≈_ f x = f x ≈ x
LeastFixedPoint : ∀ {i j} {A : Set i}
→ (_≈_ _≼_ : A → A → Set j) → (f : A → A)
→ (μf : A) → Set (i ⊔ℓ j)
LeastFixedPoint _≈_ _≼_ f = Least (FixP _≈_ f) _≼_
-- Properties
-- least fixed-points are unique --- up to _≈_.
lpfp-unique : ∀ {i j} {A : Set i}
→ (_≈_ _≼_ : A → A → Set j)
→ IsPartialOrder _≈_ _≼_
→ (f : A → A)
→ (μf₁ : A) → LeastPrefixedPoint _≼_ f μf₁
→ (μf₂ : A) → LeastPrefixedPoint _≼_ f μf₂
→ μf₁ ≈ μf₂
lpfp-unique _≈_ _≼_ partial f μf₁ (pfp₁ , lb₁) μf₂ (pfp₂ , lb₂) =
antisym (lb₁ pfp₂) (lb₂ pfp₁)
where open IsPartialOrder partial
-- least fixed-points are also unique up to _≈_, for similar reasons.
lfp-unique : ∀ {i j} {A : Set i}
→ (_≈_ _≼_ : A → A → Set j)
→ IsPartialOrder _≈_ _≼_
→ (f : A → A)
→ (μf₁ : A) → LeastFixedPoint _≈_ _≼_ f μf₁
→ (μf₂ : A) → LeastFixedPoint _≈_ _≼_ f μf₂
→ μf₁ ≈ μf₂
lfp-unique _≈_ _≼_ partial f μf₁ (fp₁ , lb₁) μf₂ (fp₂ , lb₂) =
antisym (lb₁ fp₂) (lb₂ fp₁)
where open IsPartialOrder partial
-- least prefixed-point μf of a monotonic function f
-- satisfies μf ≼ f μf.
lpfp⇒≽ : ∀ {i j} {A : Set i}
→ (_≼_ : A → A → Set j) (f : A → A)
→ (∀ {x y} → x ≼ y → f x ≼ f y)
→ (μf : A)
→ LeastPrefixedPoint _≼_ f μf → μf ≼ f μf
lpfp⇒≽ _≼_ f f-mono μf (fμf≼μf , least) =
(⇐-begin
μf ≼ f μf
⇐⟨ least ⟩
f (f μf) ≼ f μf
⇐⟨ f-mono ⟩
f μf ≼ μf
⇐∎) fμf≼μf
-- least prefixed-point μf of a monotonic function f
-- is also a fixed point.
lpfp⇒fixp : ∀ {i j} {A : Set i}
→ (_≈_ _≼_ : A → A → Set j)
→ IsPartialOrder _≈_ _≼_
→ (f : A → A) → (∀ {x y} → x ≼ y → f x ≼ f y)
→ (μf : A)
→ LeastPrefixedPoint _≼_ f μf → FixP _≈_ f μf
lpfp⇒fixp _≈_ _≼_ partial f f-mono μf (fμf≼μf , least) =
antisym fμf≼μf (lpfp⇒≽ _≼_ f f-mono μf (fμf≼μf , least))
where open IsPartialOrder partial
-- and μf is also a lower bound for fixed points.
lpfp⇒lb : ∀ {i j} {A : Set i}
→ (_≈_ _≼_ : A → A → Set j)
→ IsPartialOrder _≈_ _≼_
→ (f : A → A)
→ (μf : A)
→ LeastPrefixedPoint _≼_ f μf → LowerBound (FixP _≈_ f) _≼_ μf
lpfp⇒lb _≈_ _≼_ partial f μf (fμf≼μf , least) fx≈x = least (reflexive fx≈x)
where open IsPartialOrder partial
-- Thus a least prefixed point is also a least fixed point.
lpfp⇒lfp : ∀ {i j} {A : Set i}
→ (_≈_ _≼_ : A → A → Set j)
→ IsPartialOrder _≈_ _≼_
→ (f : A → A) → (∀ {x y} → x ≼ y → f x ≼ f y)
→ (μf : A)
→ LeastPrefixedPoint _≼_ f μf → LeastFixedPoint _≈_ _≼_ f μf
lpfp⇒lfp _≈_ _≼_ partial f f-mono μf lpfp =
lpfp⇒fixp _≈_ _≼_ partial f f-mono μf lpfp ,
lpfp⇒lb _≈_ _≼_ partial f μf lpfp
{- The situation with the other direction is a bit awkward.
Given a least fixed-point φf, we cannot prove that it is also
a least prefixed-point. We may only prove that φf equals any
least fixed point up to _≈_.
-}
lfp⇒lpfp≈ : ∀ {i j} {A : Set i}
→ (_≈_ _≼_ : A → A → Set j)
→ IsPartialOrder _≈_ _≼_
→ (f : A → A) → (∀ {x y} → x ≼ y → f x ≼ f y)
→ (μf : A) → LeastPrefixedPoint _≼_ f μf
→ (φf : A) → LeastFixedPoint _≈_ _≼_ f φf
→ μf ≈ φf
lfp⇒lpfp≈ _≈_ _≼_ partial f f-mono μf lpfp φf lfp =
lfp-unique _≈_ _≼_ partial f μf
(lpfp⇒lfp _≈_ _≼_ partial f f-mono μf lpfp) φf lfp
where open IsPartialOrder partial