Skip to content

Commit 0da6b31

Browse files
authored
#2075: Remove symmetry assumption from lexicographic well-foundedness (#2077)
1 parent c6804f0 commit 0da6b31

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

CHANGELOG.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,12 @@ Non-backwards compatible changes
781781
properties about the orderings themselves the second index must be provided
782782
explicitly.
783783

784+
* Issue #2075 (Johannes Waldmann): wellfoundedness of the lexicographic ordering
785+
on products, defined in `Data.Product.Relation.Binary.Lex.Strict`, no longer
786+
requires the assumption of symmetry for the first equality relation `_≈₁_`,
787+
leading to a new lemma `Induction.WellFounded.Acc-resp-flip-≈`, and refactoring
788+
of the previous proof `Induction.WellFounded.Acc-resp-≈`.
789+
784790
* The operation `SymClosure` on relations in
785791
`Relation.Binary.Construct.Closure.Symmetric` has been reimplemented
786792
as a data type `SymClosure _⟶_ a b` that is parameterized by the
@@ -2515,13 +2521,13 @@ Other minor changes
25152521
×-≡,≡←≡ : p₁ ≡ p₂ → (proj₁ p₁ ≡ proj₁ p₂ × proj₂ p₁ ≡ proj₂ p₂)
25162522
```
25172523

2518-
* Added new proof to `Data.Product.Relation.Binary.Lex.Strict`
2524+
* Added new proofs to `Data.Product.Relation.Binary.Lex.Strict`
25192525
```agda
25202526
×-respectsʳ : Transitive _≈₁_ →
25212527
_<₁_ Respectsʳ _≈₁_ → _<₂_ Respectsʳ _≈₂_ → _<ₗₑₓ_ Respectsʳ _≋_
25222528
×-respectsˡ : Symmetric _≈₁_ → Transitive _≈₁_ →
25232529
_<₁_ Respectsˡ _≈₁_ → _<₂_ Respectsˡ _≈₂_ → _<ₗₑₓ_ Respectsˡ _≋_
2524-
×-wellFounded' : Symmetric _≈₁_ → Transitive _≈₁_ → _<₁_ Respectsʳ _≈₁_ →
2530+
×-wellFounded' : Transitive _≈₁_ → _<₁_ Respectsʳ _≈₁_ →
25252531
WellFounded _<₁_ → WellFounded _<₂_ → WellFounded _<ₗₑₓ_
25262532
```
25272533

@@ -2686,7 +2692,7 @@ Other minor changes
26862692
∀ {m n} → _Respectsˡ_ (_<_ {m} {n}) _≋_
26872693
<-respectsʳ : IsPartialEquivalence _≈_ → _≺_ Respectsʳ _≈_ →
26882694
∀ {m n} → _Respectsʳ_ (_<_ {m} {n}) _≋_
2689-
<-wellFounded : Symmetric _≈_ → Transitive _≈_ → _≺_ Respectsʳ _≈_ → WellFounded _≺_ →
2695+
<-wellFounded : Transitive _≈_ → _≺_ Respectsʳ _≈_ → WellFounded _≺_ →
26902696
∀ {n} → WellFounded (_<_ {n})
26912697
```
26922698

@@ -3356,6 +3362,11 @@ This is a full list of proofs that have changed form to use irrelevant instance
33563362
⊆-mergeʳ : ∀ xs ys → ys ⊆ merge _≤?_ xs ys
33573363
```
33583364

3365+
* Added new proof to `Induction.WellFounded`
3366+
```agda
3367+
Acc-resp-flip-≈ : _<_ Respectsʳ (flip _≈_) → (Acc _<_) Respects _≈_
3368+
```
3369+
33593370
* Added new file `Relation.Binary.Reasoning.Base.Apartness`
33603371

33613372
This is how to use it:

src/Data/Product/Relation/Binary/Lex/Strict.agda

+10-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open import Relation.Binary.Structures
2828
open import Relation.Binary.Definitions
2929
using (Transitive; Symmetric; Irreflexive; Asymmetric; Total; Decidable; Antisymmetric; Trichotomous; _Respects₂_; _Respectsʳ_; _Respectsˡ_; tri<; tri>; tri≈)
3030
open import Relation.Binary.Consequences
31-
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_; refl)
31+
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
3232

3333
private
3434
variable
@@ -192,23 +192,24 @@ module _ {_≈₁_ : Rel A ℓ₁} {_<₁_ : Rel A ℓ₂} {_<₂_ : Rel B ℓ
192192
private
193193
_<ₗₑₓ_ = ×-Lex _≈₁_ _<₁_ _<₂_
194194

195-
×-wellFounded' : Symmetric _≈₁_ Transitive _≈₁_
195+
×-wellFounded' : Transitive _≈₁_
196196
_<₁_ Respectsʳ _≈₁_
197197
WellFounded _<₁_
198198
WellFounded _<₂_
199199
WellFounded _<ₗₑₓ_
200-
×-wellFounded' sym trans resp wf₁ wf₂ (x , y) = acc (×-acc (wf₁ x) (wf₂ y))
200+
×-wellFounded' trans resp wf₁ wf₂ (x , y) = acc (×-acc (wf₁ x) (wf₂ y))
201201
where
202202
×-acc : {x y}
203203
Acc _<₁_ x Acc _<₂_ y
204204
WfRec _<ₗₑₓ_ (Acc _<ₗₑₓ_) (x , y)
205205
×-acc (acc rec₁) acc₂ (u , v) (inj₁ u<x)
206206
= acc (×-acc (rec₁ u u<x) (wf₂ v))
207-
×-acc {x₁} acc₁ (acc rec₂) (u , v) (inj₂ (u≈x , v<y))
208-
= Acc-resp-≈ (Pointwise.×-symmetric {_∼₁_ = _≈₁_} {_∼₂_ = _≡_ } sym ≡.sym)
209-
(×-respectsʳ {_<₁_ = _<₁_} {_<₂_ = _<₂_} trans resp (≡.respʳ _<₂_))
210-
(sym u≈x , _≡_.refl)
211-
(acc (×-acc acc₁ (rec₂ v v<y)))
207+
×-acc acc₁ (acc rec₂) (u , v) (inj₂ (u≈x , v<y))
208+
= Acc-resp-flip-≈
209+
(×-respectsʳ {_<₁_ = _<₁_} {_<₂_ = _<₂_} trans resp (≡.respʳ _<₂_))
210+
(u≈x , ≡.refl)
211+
(acc (×-acc acc₁ (rec₂ v v<y)))
212+
212213

213214
module _ {_<₁_ : Rel A ℓ₁} {_<₂_ : Rel B ℓ₂} where
214215

@@ -218,7 +219,7 @@ module _ {_<₁_ : Rel A ℓ₁} {_<₂_ : Rel B ℓ₂} where
218219
×-wellFounded : WellFounded _<₁_
219220
WellFounded _<₂_
220221
WellFounded _<ₗₑₓ_
221-
×-wellFounded = ×-wellFounded' ≡.sym ≡.trans (≡.respʳ _<₁_)
222+
×-wellFounded = ×-wellFounded' ≡.trans (≡.respʳ _<₁_)
222223

223224
------------------------------------------------------------------------
224225
-- Collections of properties which are preserved by ×-Lex.

src/Data/Vec/Relation/Binary/Lex/Strict.agda

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module _ {_≈_ : Rel A ℓ₁} {_≺_ : Rel A ℓ₂} where
130130
{m n} Irrelevant (_<_ {m} {n})
131131
<-irrelevant = Core.irrelevant (λ ())
132132

133-
module _ (≈-sym : Symmetric _≈_) (≈-trans : Transitive _≈_) (≺-respʳ : _≺_ Respectsʳ _≈_ ) (≺-wf : WellFounded _≺_)
133+
module _ (≈-trans : Transitive _≈_) (≺-respʳ : _≺_ Respectsʳ _≈_ ) (≺-wf : WellFounded _≺_)
134134
where
135135

136136
<-wellFounded : {n} WellFounded (_<_ {n})
@@ -142,7 +142,7 @@ module _ {_≈_ : Rel A ℓ₁} {_≺_ : Rel A ℓ₂} where
142142
<⇒uncons-Lex {x ∷ xs} {y ∷ ys} (next x≈y xs<ys) = inj₂ (x≈y , xs<ys)
143143

144144
uncons-Lex-wellFounded : WellFounded (×-Lex _≈_ _≺_ _<_ on uncons)
145-
uncons-Lex-wellFounded = On.wellFounded uncons (×-wellFounded' ≈-sym ≈-trans ≺-respʳ ≺-wf <-wellFounded)
145+
uncons-Lex-wellFounded = On.wellFounded uncons (×-wellFounded' ≈-trans ≺-respʳ ≺-wf <-wellFounded)
146146

147147
------------------------------------------------------------------------
148148
-- Structures

src/Induction/WellFounded.agda

+11-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
module Induction.WellFounded where
1010

1111
open import Data.Product.Base using (Σ; _,_; proj₁)
12-
open import Function.Base using (_on_)
12+
open import Function.Base using (_∘_; flip; _on_)
1313
open import Induction
1414
open import Level using (Level; _⊔_)
1515
open import Relation.Binary.Core using (Rel)
@@ -54,10 +54,13 @@ acc-inverse : ∀ {_<_ : Rel A ℓ} {x : A} (q : Acc _<_ x) →
5454
(y : A) y < x Acc _<_ y
5555
acc-inverse (acc rs) y y<x = rs y y<x
5656

57-
Acc-resp-≈ : {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} Symmetric _≈_
58-
_<_ Respectsʳ _≈_ (Acc _<_) Respects _≈_
59-
Acc-resp-≈ sym respʳ x≈y (acc rec) =
60-
acc (λ z z<y rec z (respʳ (sym x≈y) z<y))
57+
module _ {_≈_ : Rel A ℓ₁} {_<_ : Rel A ℓ₂} where
58+
59+
Acc-resp-flip-≈ : _<_ Respectsʳ (flip _≈_) (Acc _<_) Respects _≈_
60+
Acc-resp-flip-≈ respʳ x≈y (acc rec) = acc λ z z<y rec z (respʳ x≈y z<y)
61+
62+
Acc-resp-≈ : Symmetric _≈_ _<_ Respectsʳ _≈_ (Acc _<_) Respects _≈_
63+
Acc-resp-≈ sym respʳ x≈y wf = Acc-resp-flip-≈ (respʳ ∘ sym) x≈y wf
6164

6265
------------------------------------------------------------------------
6366
-- Well-founded induction for the subset of accessible elements:
@@ -120,7 +123,7 @@ module Subrelation {_<₁_ : Rel A ℓ₁} {_<₂_ : Rel A ℓ₂}
120123
(<₁⇒<₂ : {x y} x <₁ y x <₂ y) where
121124

122125
accessible : Acc _<₂_ ⊆ Acc _<₁_
123-
accessible (acc rs) = acc (λ y y<x accessible (rs y (<₁⇒<₂ y<x)))
126+
accessible (acc rs) = acc λ y y<x accessible (rs y (<₁⇒<₂ y<x))
124127

125128
wellFounded : WellFounded _<₂_ WellFounded _<₁_
126129
wellFounded wf = λ x accessible (wf x)
@@ -131,7 +134,7 @@ module Subrelation {_<₁_ : Rel A ℓ₁} {_<₂_ : Rel A ℓ₂}
131134
module InverseImage {_<_ : Rel B ℓ} (f : A B) where
132135

133136
accessible : {x} Acc _<_ (f x) Acc (_<_ on f) x
134-
accessible (acc rs) = acc (λ y fy<fx accessible (rs (f y) fy<fx))
137+
accessible (acc rs) = acc λ y fy<fx accessible (rs (f y) fy<fx)
135138

136139
wellFounded : WellFounded _<_ WellFounded (_<_ on f)
137140
wellFounded wf = λ x accessible (wf (f x))
@@ -158,7 +161,7 @@ module TransitiveClosure {A : Set a} (_<_ : Rel A ℓ) where
158161
trans : {x y z} (x<y : x <⁺ y) (y<z : y <⁺ z) x <⁺ z
159162

160163
downwardsClosed : {x y} Acc _<⁺_ y x <⁺ y Acc _<⁺_ x
161-
downwardsClosed (acc rs) x<y = acc (λ z z<x rs z (trans z<x x<y))
164+
downwardsClosed (acc rs) x<y = acc λ z z<x rs z (trans z<x x<y)
162165

163166
mutual
164167

0 commit comments

Comments
 (0)