Skip to content

Commit 4b32ab4

Browse files
Add begin-irrefl reasoning combinator (#1470)
1 parent bf825e7 commit 4b32ab4

File tree

13 files changed

+76
-23
lines changed

13 files changed

+76
-23
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,30 @@ Non-backwards compatible changes
769769
IO.Instances
770770
```
771771

772+
### Changes to triple reasoning interface
773+
774+
* The module `Relation.Binary.Reasoning.Base.Triple` now takes an extra proof that the strict
775+
relation is irreflexive.
776+
777+
* This allows the following new proof combinator:
778+
```agda
779+
begin-contradiction : (r : x IsRelatedTo x) → {s : True (IsStrict? r)} → A
780+
```
781+
that takes a proof that a value is strictly less than itself and then applies the principle of explosion.
782+
783+
* Specialised versions of this combinator are available in the following derived modules:
784+
```
785+
Data.Nat.Properties
786+
Data.Nat.Binary.Properties
787+
Data.Integer.Properties
788+
Data.Rational.Unnormalised.Properties
789+
Data.Rational.Properties
790+
Data.Vec.Relation.Binary.Lex.Strict
791+
Data.Vec.Relation.Binary.Lex.NonStrict
792+
Relation.Binary.Reasoning.StrictPartialOrder
793+
Relation.Binary.Reasoning.PartialOrder
794+
```
795+
772796
### Other
773797

774798
* In accordance with changes to the flags in Agda 2.6.3, all modules that previously used
@@ -992,6 +1016,8 @@ Major improvements
9921016
* A new module `Algebra.Lattice.Bundles.Raw` is also introduced.
9931017
* `RawLattice` has been moved from `Algebra.Lattice.Bundles` to this new module.
9941018
1019+
* In `Relation.Binary.Reasoning.Base.Triple`, added a new parameter `<-irrefl : Irreflexive _≈_ _<_`
1020+
9951021
Deprecated modules
9961022
------------------
9971023

src/Data/Integer/Properties.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ i≮i = <-irrefl refl
365365
module ≤-Reasoning where
366366
open import Relation.Binary.Reasoning.Base.Triple
367367
≤-isPreorder
368+
<-irrefl
368369
<-trans
369370
(resp₂ _<_)
370371
<⇒≤

src/Data/List/Relation/Unary/Any/Properties.agda

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ Any-×⁻ pq with Prod.map₂ (Prod.map₂ find) (find pq)
254254

255255
(p , q) ∎
256256

257-
258257
to∘from : pq Any-×⁺ {xs = xs} (Any-×⁻ pq) ≡ pq
259258
to∘from pq with find pq
260259
| (λ (f : (proj₁ (find pq) ≡_) ⋐ _) map∘find pq {f})

src/Data/Nat/Binary/Properties.agda

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ open import Relation.Binary.Consequences
3838
open import Relation.Binary.Morphism
3939
import Relation.Binary.Morphism.OrderMonomorphism as OrderMonomorphism
4040
open import Relation.Binary.PropositionalEquality
41-
import Relation.Binary.Reasoning.Base.Triple as InequalityReasoning
4241
open import Relation.Nullary using (¬_; yes; no)
4342
import Relation.Nullary.Decidable as Dec
4443
open import Relation.Nullary.Negation using (contradiction)
@@ -607,12 +606,18 @@ x ≤? y with <-cmp x y
607606
------------------------------------------------------------------------
608607
-- Equational reasoning for _≤_ and _<_
609608

610-
module ≤-Reasoning = InequalityReasoning
611-
≤-isPreorder
612-
<-trans
613-
(resp₂ _<_) <⇒≤
614-
<-≤-trans ≤-<-trans
615-
hiding (step-≈; step-≈˘)
609+
module ≤-Reasoning where
610+
611+
open import Relation.Binary.Reasoning.Base.Triple
612+
≤-isPreorder
613+
<-irrefl
614+
<-trans
615+
(resp₂ _<_)
616+
<⇒≤
617+
<-≤-trans
618+
≤-<-trans
619+
public
620+
hiding (step-≈; step-≈˘)
616621

617622
------------------------------------------------------------------------
618623
-- Properties of _<ℕ_

src/Data/Nat/Properties.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ m<1+n⇒m≤n (s≤s m≤n) = m≤n
495495
module ≤-Reasoning where
496496
open import Relation.Binary.Reasoning.Base.Triple
497497
≤-isPreorder
498+
<-irrefl
498499
<-trans
499500
(resp₂ _<_)
500501
<⇒≤

src/Data/Rational/Properties.agda

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,16 @@ _>?_ = flip _<?_
713713
module ≤-Reasoning where
714714
import Relation.Binary.Reasoning.Base.Triple
715715
≤-isPreorder
716+
<-irrefl
716717
<-trans
717718
(resp₂ _<_)
718719
<⇒≤
719720
<-≤-trans
720721
≤-<-trans
721722
as Triple
722-
open Triple public hiding (step-≈; step-≈˘)
723+
724+
open Triple public
725+
hiding (step-≈; step-≈˘)
723726

724727
infixr 2 step-≃ step-≃˘
725728

@@ -729,7 +732,6 @@ module ≤-Reasoning where
729732
syntax step-≃ x y∼z x≃y = x ≃⟨ x≃y ⟩ y∼z
730733
syntax step-≃˘ x y∼z y≃x = x ≃˘⟨ y≃x ⟩ y∼z
731734

732-
733735
------------------------------------------------------------------------
734736
-- Properties of Positive/NonPositive/Negative/NonNegative and _≤_/_<_
735737

src/Data/Rational/Unnormalised/Properties.agda

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,13 +542,16 @@ _>?_ = flip _<?_
542542
module ≤-Reasoning where
543543
import Relation.Binary.Reasoning.Base.Triple
544544
≤-isPreorder
545+
<-irrefl
545546
<-trans
546547
<-resp-≃
547548
<⇒≤
548549
<-≤-trans
549550
≤-<-trans
550551
as Triple
551-
open Triple public hiding (step-≈; step-≈˘)
552+
553+
open Triple public
554+
hiding (step-≈; step-≈˘)
552555

553556
infixr 2 step-≃ step-≃˘
554557

@@ -558,7 +561,6 @@ module ≤-Reasoning where
558561
syntax step-≃ x y∼z x≃y = x ≃⟨ x≃y ⟩ y∼z
559562
syntax step-≃˘ x y∼z y≃x = x ≃˘⟨ y≃x ⟩ y∼z
560563

561-
562564
------------------------------------------------------------------------
563565
-- Properties of ↥_/↧_
564566

src/Data/Tree/AVL/Indexed/Relation/Unary/Any/Properties.agda

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ open import Relation.Binary.Construct.Add.Extrema.Strict _<_ using ([<]-injectiv
3535

3636
import Relation.Binary.Reasoning.StrictPartialOrder as <-Reasoning
3737

38-
3938
private
4039
variable
4140
v p q : Level
@@ -278,33 +277,33 @@ module _ {V : Value v} where
278277
joinʳ⁺-right⁺ kv lk ku′ bal (Any-insertWith-just ku seg′ pr rp)
279278

280279
-- impossible cases
281-
... | here eq | tri< k<k′ _ _ = flip contradiction (irrefl⁺ [ k ]) $ begin-strict
280+
... | here eq | tri< k<k′ _ _ = begin-contradiction
282281
[ k ] <⟨ [ k<k′ ]ᴿ ⟩
283282
[ k′ ] ≈⟨ [ sym eq ]ᴱ ⟩
284283
[ k ] ∎
285-
... | here eq | tri> _ _ k>k′ = flip contradiction (irrefl⁺ [ k ]) $ begin-strict
284+
... | here eq | tri> _ _ k>k′ = begin-contradiction
286285
[ k ] ≈⟨ [ eq ]ᴱ ⟩
287286
[ k′ ] <⟨ [ k>k′ ]ᴿ ⟩
288287
[ k ] ∎
289-
... | left lp | tri≈ _ k≈k′ _ = flip contradiction (irrefl⁺ [ k ]) $ begin-strict
288+
... | left lp | tri≈ _ k≈k′ _ = begin-contradiction
290289
let k″ = Any.lookup lp .key; k≈k″ = lookup-result lp; (_ , k″<k′) = lookup-bounded lp in
291290
[ k ] ≈⟨ [ k≈k″ ]ᴱ ⟩
292291
[ k″ ] <⟨ k″<k′ ⟩
293292
[ k′ ] ≈⟨ [ sym k≈k′ ]ᴱ ⟩
294293
[ k ] ∎
295-
... | left lp | tri> _ _ k>k′ = flip contradiction (irrefl⁺ [ k ]) $ begin-strict
294+
... | left lp | tri> _ _ k>k′ = begin-contradiction
296295
let k″ = Any.lookup lp .key; k≈k″ = lookup-result lp; (_ , k″<k′) = lookup-bounded lp in
297296
[ k ] ≈⟨ [ k≈k″ ]ᴱ ⟩
298297
[ k″ ] <⟨ k″<k′ ⟩
299298
[ k′ ] <⟨ [ k>k′ ]ᴿ ⟩
300299
[ k ] ∎
301-
... | right rp | tri< k<k′ _ _ = flip contradiction (irrefl⁺ [ k ]) $ begin-strict
300+
... | right rp | tri< k<k′ _ _ = begin-contradiction
302301
let k″ = Any.lookup rp .key; k≈k″ = lookup-result rp; (k′<k″ , _) = lookup-bounded rp in
303302
[ k ] <⟨ [ k<k′ ]ᴿ ⟩
304303
[ k′ ] <⟨ k′<k″ ⟩
305304
[ k″ ] ≈⟨ [ sym k≈k″ ]ᴱ ⟩
306305
[ k ] ∎
307-
... | right rp | tri≈ _ k≈k′ _ = flip contradiction (irrefl⁺ [ k ]) $ begin-strict
306+
... | right rp | tri≈ _ k≈k′ _ = begin-contradiction
308307
let k″ = Any.lookup rp .key; k≈k″ = lookup-result rp; (k′<k″ , _) = lookup-bounded rp in
309308
[ k ] ≈⟨ [ k≈k′ ]ᴱ ⟩
310309
[ k′ ] <⟨ k′<k″ ⟩

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ module ≤-Reasoning {_≈_ : Rel A ℓ₁} {_≼_ : Rel A ℓ₂}
261261

262262
open import Relation.Binary.Reasoning.Base.Triple
263263
(≤-isPreorder ≼-po {n})
264+
<-irrefl
264265
(<-trans ≼-po)
265266
(<-resp₂ isEquivalence ≤-resp-≈)
266267
<⇒≤

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ module _ {_≈_ : Rel A ℓ₁} {_≺_ : Rel A ℓ₂} where
326326

327327
module ≤-Reasoning {_≈_ : Rel A ℓ₁} {_≺_ : Rel A ℓ₂}
328328
(≈-isEquivalence : IsEquivalence _≈_)
329+
(≺-irrefl : Irreflexive _≈_ _≺_)
329330
(≺-trans : Transitive _≺_)
330331
(≺-resp-≈ : _≺_ Respects₂ _≈_)
331332
(n : ℕ)
@@ -336,6 +337,7 @@ module ≤-Reasoning {_≈_ : Rel A ℓ₁} {_≺_ : Rel A ℓ₂}
336337

337338
open import Relation.Binary.Reasoning.Base.Triple
338339
(≤-isPreorder ≈-isEquivalence ≺-trans ≺-resp-≈)
340+
(<-irrefl ≺-irrefl)
339341
(<-trans ≈-isPartialEquivalence ≺-resp-≈ ≺-trans)
340342
(<-respects₂ ≈-isPartialEquivalence ≺-resp-≈)
341343
(<⇒≤ {m = n})

src/Relation/Binary/Reasoning/Base/Triple.agda

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
open import Relation.Binary.Core using (Rel; _⇒_)
1414
open import Relation.Binary.Structures using (IsPreorder)
1515
open import Relation.Binary.Definitions
16-
using (Transitive; _Respects₂_; Trans)
16+
using (Transitive; _Respects₂_; Trans; Irreflexive)
1717

1818
module Relation.Binary.Reasoning.Base.Triple {a ℓ₁ ℓ₂ ℓ₃} {A : Set a}
1919
{_≈_ : Rel A ℓ₁} {_≤_ : Rel A ℓ₂} {_<_ : Rel A ℓ₃}
2020
(isPreorder : IsPreorder _≈_ _≤_)
21-
(<-trans : Transitive _<_) (<-resp-≈ : _<_ Respects₂ _≈_) (<⇒≤ : _<_ ⇒ _≤_)
21+
(<-irrefl : Irreflexive _≈_ _<_) (<-trans : Transitive _<_) (<-resp-≈ : _<_ Respects₂ _≈_)
22+
(<⇒≤ : _<_ ⇒ _≤_)
2223
(<-≤-trans : Trans _<_ _≤_ _<_) (≤-<-trans : Trans _≤_ _<_ _<_)
2324
where
2425

@@ -27,6 +28,8 @@ open import Function.Base using (case_of_; id)
2728
open import Level using (Level; _⊔_; Lift; lift)
2829
open import Relation.Binary.PropositionalEquality.Core
2930
using (_≡_; refl; sym)
31+
open import Relation.Nullary using (¬_)
32+
open import Relation.Nullary.Negation using (contradiction)
3033
open import Relation.Nullary.Decidable.Core
3134
using (Dec; yes; no; True; toWitness)
3235

@@ -79,7 +82,7 @@ extractEquality (isEquality x≈y) = x≈y
7982
-- See `Relation.Binary.Reasoning.Base.Partial` for the design decisions
8083
-- behind these combinators.
8184

82-
infix 1 begin_ begin-strict_ begin-equality_
85+
infix 1 begin_ begin-strict_ begin-equality_ begin-contradiction_
8386
infixr 2 step-< step-≤ step-≈ step-≈˘ step-≡ step-≡˘ _≡⟨⟩_
8487
infix 3 _∎
8588

@@ -96,6 +99,13 @@ begin-strict_ r {s} = extractStrict (toWitness s)
9699
begin-equality_ : {x y} (r : x IsRelatedTo y) {s : True (IsEquality? r)} x ≈ y
97100
begin-equality_ r {s} = extractEquality (toWitness s)
98101

102+
begin-contradiction_ : {x} (r : x IsRelatedTo x) {s : True (IsStrict? r)}
103+
{a} {A : Set a} A
104+
begin-contradiction_ {x} r {s} = contradiction x<x (<-irrefl Eq.refl)
105+
where
106+
x<x : x < x
107+
x<x = extractStrict (toWitness s)
108+
99109
-- Step with the strict relation
100110

101111
step-< : (x : A) {y z} y IsRelatedTo z x < y x IsRelatedTo z

src/Relation/Binary/Reasoning/PartialOrder.agda

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ module Relation.Binary.Reasoning.PartialOrder
4545
{p₁ p₂ p₃} (P : Poset p₁ p₂ p₃) where
4646

4747
open Poset P
48-
import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_ as Strict
48+
open import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_
49+
as Strict
50+
using (_<_)
4951

5052
------------------------------------------------------------------------
5153
-- Re-export contents of base module
5254

5355
open import Relation.Binary.Reasoning.Base.Triple
5456
isPreorder
57+
Strict.<-irrefl
5558
(Strict.<-trans isPartialOrder)
5659
(Strict.<-resp-≈ isEquivalence ≤-resp-≈)
5760
Strict.<⇒≤

src/Relation/Binary/Reasoning/StrictPartialOrder.agda

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ import Relation.Binary.Construct.StrictToNonStrict _≈_ _<_ as NonStrict
5353

5454
open import Relation.Binary.Reasoning.Base.Triple
5555
(NonStrict.isPreorder₂ isStrictPartialOrder)
56+
irrefl
5657
trans
5758
<-resp-≈
5859
NonStrict.<⇒≤
5960
(NonStrict.<-≤-trans trans <-respʳ-≈)
6061
(NonStrict.≤-<-trans Eq.sym trans <-respˡ-≈)
6162
public
63+

0 commit comments

Comments
 (0)