Skip to content

Commit bfd7a7b

Browse files
Decidable Setoid -> Apartness Relation and Rational Heyting Field (#2194)
* new stuff * forgot to add bundles for rational instance of Heyting* * one more (obvious) simplification * a few more simplifications * comments on DecSetoid properties from jamesmckinna * not working, but partially there * woo! * fix anonymous instance * fix errant whitespace * `fix-whitespace` * rectified wrt `contradiction` * rectified `DecSetoid` properties * rectified `Group` properties * inlined lemma; tidied up --------- Co-authored-by: jamesmckinna <[email protected]> Co-authored-by: James McKinna <[email protected]>
1 parent c5255d0 commit bfd7a7b

File tree

5 files changed

+139
-6
lines changed

5 files changed

+139
-6
lines changed

CHANGELOG.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ New modules
145145
Relation.Binary.Construct.Interior.Symmetric
146146
```
147147

148+
* Properties of `Setoid`s with decidable equality relation:
149+
```
150+
Relation.Binary.Properties.DecSetoid
151+
```
152+
148153
* Pointwise and equality relations over indexed containers:
149154
```agda
150155
Data.Container.Indexed.Relation.Binary.Pointwise
@@ -262,6 +267,8 @@ Additions to existing modules
262267
//-rightDivides : RightDivides _∙_ _//_
263268
264269
⁻¹-selfInverse : SelfInverse _⁻¹
270+
x∙y⁻¹≈ε⇒x≈y : ∀ x y → (x ∙ y ⁻¹) ≈ ε → x ≈ y
271+
x≈y⇒x∙y⁻¹≈ε : ∀ {x y} → x ≈ y → (x ∙ y ⁻¹) ≈ ε
265272
\\≗flip-//⇒comm : (∀ x y → x \\ y ≈ y // x) → Commutative _∙_
266273
comm⇒\\≗flip-// : Commutative _∙_ → ∀ x y → x \\ y ≈ y // x
267274
⁻¹-anti-homo-// : (x // y) ⁻¹ ≈ y // x
@@ -499,9 +506,22 @@ Additions to existing modules
499506
product-↭ : product Preserves _↭_ ⟶ _≡_
500507
```
501508

509+
* In `Data.Rational.Properties`:
510+
```agda
511+
1≢0 : 1ℚ ≢ 0ℚ
512+
513+
#⇒invertible : p ≢ q → Invertible 1ℚ _*_ (p - q)
514+
invertible⇒# : Invertible 1ℚ _*_ (p - q) → p ≢ q
515+
516+
isHeytingCommutativeRing : IsHeytingCommutativeRing _≡_ _≢_ _+_ _*_ -_ 0ℚ 1ℚ
517+
isHeytingField : IsHeytingField _≡_ _≢_ _+_ _*_ -_ 0ℚ 1ℚ
518+
heytingCommutativeRing : HeytingCommutativeRing 0ℓ 0ℓ 0ℓ
519+
heytingField : HeytingField 0ℓ 0ℓ 0ℓ
520+
```
521+
502522
* Added new functions in `Data.String.Base`:
503523
```agda
504-
map : (Char → Char) → String → String
524+
map : (Char → Char) → String → String
505525
between : String → String → String → String
506526
```
507527

@@ -562,6 +582,7 @@ Additions to existing modules
562582

563583
* Added new proofs in `Relation.Binary.Properties.Setoid`:
564584
```agda
585+
≉-irrefl : Irreflexive _≈_ _≉_
565586
≈;≈⇒≈ : _≈_ ; _≈_ ⇒ _≈_
566587
≈⇒≈;≈ : _≈_ ⇒ _≈_ ; _≈_
567588
```

src/Algebra/Properties/Group.agda

+12
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ inverseʳ-unique x y eq = trans (y≈x\\z x y ε eq) (identityʳ _)
115115
⁻¹-involutive : Involutive _⁻¹
116116
⁻¹-involutive = selfInverse⇒involutive ⁻¹-selfInverse
117117

118+
x∙y⁻¹≈ε⇒x≈y : x y (x ∙ y ⁻¹) ≈ ε x ≈ y
119+
x∙y⁻¹≈ε⇒x≈y x y x∙y⁻¹≈ε = begin
120+
x ≈⟨ inverseˡ-unique x (y ⁻¹) x∙y⁻¹≈ε ⟩
121+
y ⁻¹ ⁻¹ ≈⟨ ⁻¹-involutive y ⟩
122+
y ∎
123+
124+
x≈y⇒x∙y⁻¹≈ε : {x y} x ≈ y (x ∙ y ⁻¹) ≈ ε
125+
x≈y⇒x∙y⁻¹≈ε {x} {y} x≈y = begin
126+
x ∙ y ⁻¹ ≈⟨ ∙-congʳ x≈y ⟩
127+
y ∙ y ⁻¹ ≈⟨ inverseʳ y ⟩
128+
ε ∎
129+
118130
⁻¹-injective : Injective _≈_ _≈_ _⁻¹
119131
⁻¹-injective = selfInverse⇒injective ⁻¹-selfInverse
120132

src/Data/Rational/Properties.agda

+57-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
module Data.Rational.Properties where
1111

12+
open import Algebra.Apartness
1213
open import Algebra.Construct.NaturalChoice.Base
1314
import Algebra.Construct.NaturalChoice.MinMaxOp as MinMaxOp
1415
import Algebra.Lattice.Construct.NaturalChoice.MinMaxOp as LatticeMinMaxOp
@@ -21,6 +22,7 @@ import Algebra.Morphism.GroupMonomorphism as GroupMonomorphisms
2122
import Algebra.Morphism.RingMonomorphism as RingMonomorphisms
2223
import Algebra.Lattice.Morphism.LatticeMonomorphism as LatticeMonomorphisms
2324
import Algebra.Properties.CommutativeSemigroup as CommSemigroupProperties
25+
import Algebra.Properties.Group as GroupProperties
2426
open import Data.Bool.Base using (T; true; false)
2527
open import Data.Integer.Base as ℤ using (ℤ; +_; -[1+_]; +[1+_]; +0; 0ℤ; 1ℤ; _◃_)
2628
open import Data.Integer.Coprimality using (coprime-divisor)
@@ -49,16 +51,18 @@ open import Function.Base using (_∘_; _∘′_; _∘₂_; _$_; flip)
4951
open import Function.Definitions using (Injective)
5052
open import Level using (0ℓ)
5153
open import Relation.Binary
54+
open import Relation.Binary.Morphism.Structures
55+
import Relation.Binary.Morphism.OrderMonomorphism as OrderMonomorphisms
56+
import Relation.Binary.Properties.DecSetoid as DecSetoidProperties
5257
open import Relation.Binary.PropositionalEquality.Core
5358
using (_≡_; refl; cong; cong₂; sym; trans; _≢_; subst; subst₂; resp₂)
5459
open import Relation.Binary.PropositionalEquality.Properties
5560
using (setoid; decSetoid; module ≡-Reasoning; isEquivalence)
56-
open import Relation.Binary.Morphism.Structures
57-
import Relation.Binary.Morphism.OrderMonomorphism as OrderMonomorphisms
61+
import Relation.Binary.Reasoning.Setoid as ≈-Reasoning
62+
open import Relation.Binary.Reasoning.Syntax using (module ≃-syntax)
5863
open import Relation.Nullary.Decidable.Core as Dec
5964
using (yes; no; recompute; map′; _×-dec_)
6065
open import Relation.Nullary.Negation.Core using (¬_; contradiction)
61-
open import Relation.Binary.Reasoning.Syntax using (module ≃-syntax)
6266

6367
open import Algebra.Definitions {A = ℚ} _≡_
6468
open import Algebra.Structures {A = ℚ} _≡_
@@ -97,6 +101,9 @@ mkℚ n₁ d₁ _ ≟ mkℚ n₂ d₂ _ = map′
97101
≡-decSetoid : DecSetoid 0ℓ 0ℓ
98102
≡-decSetoid = decSetoid _≟_
99103

104+
1≢0 : 1ℚ ≢ 0ℚ
105+
1≢0 = λ ()
106+
100107
------------------------------------------------------------------------
101108
-- mkℚ+
102109
------------------------------------------------------------------------
@@ -1239,6 +1246,53 @@ neg-distribʳ-* = +-*-Monomorphism.neg-distribʳ-* ℚᵘ.+-0-isGroup ℚᵘ.*-i
12391246
{ isCommutativeRing = +-*-isCommutativeRing
12401247
}
12411248

1249+
1250+
------------------------------------------------------------------------
1251+
-- HeytingField structures and bundles
1252+
1253+
module _ where
1254+
open CommutativeRing +-*-commutativeRing
1255+
using (+-group; zeroˡ; *-congʳ; isCommutativeRing)
1256+
1257+
open GroupProperties +-group
1258+
open DecSetoidProperties ≡-decSetoid
1259+
1260+
#⇒invertible : p ≢ q Invertible 1ℚ _*_ (p - q)
1261+
#⇒invertible {p} {q} p≢q = let r = p - q in 1/ r , *-inverseˡ r , *-inverseʳ r
1262+
where instance _ = ≢-nonZero (p≢q ∘ (x∙y⁻¹≈ε⇒x≈y p q))
1263+
1264+
invertible⇒# : Invertible 1ℚ _*_ (p - q) p ≢ q
1265+
invertible⇒# {p} {q} (1/[p-q] , _ , [p-q]/[p-q]≡1) p≡q = contradiction 1≡0 1≢0
1266+
where
1267+
open ≈-Reasoning ≡-setoid
1268+
1≡0 : 1ℚ ≡ 0ℚ
1269+
1≡0 = begin
1270+
1ℚ ≈⟨ [p-q]/[p-q]≡1 ⟨
1271+
(p - q) * 1/[p-q] ≈⟨ *-congʳ (x≈y⇒x∙y⁻¹≈ε p≡q) ⟩
1272+
0ℚ * 1/[p-q] ≈⟨ zeroˡ 1/[p-q] ⟩
1273+
0ℚ ∎
1274+
1275+
isHeytingCommutativeRing : IsHeytingCommutativeRing _≡_ _≢_ _+_ _*_ -_ 0ℚ 1ℚ
1276+
isHeytingCommutativeRing = record
1277+
{ isCommutativeRing = isCommutativeRing
1278+
; isApartnessRelation = ≉-isApartnessRelation
1279+
; #⇒invertible = #⇒invertible
1280+
; invertible⇒# = invertible⇒#
1281+
}
1282+
1283+
isHeytingField : IsHeytingField _≡_ _≢_ _+_ _*_ -_ 0ℚ 1ℚ
1284+
isHeytingField = record
1285+
{ isHeytingCommutativeRing = isHeytingCommutativeRing
1286+
; tight = ≉-tight
1287+
}
1288+
1289+
heytingCommutativeRing : HeytingCommutativeRing 0ℓ 0ℓ 0ℓ
1290+
heytingCommutativeRing = record { isHeytingCommutativeRing = isHeytingCommutativeRing }
1291+
1292+
heytingField : HeytingField 0ℓ 0ℓ 0ℓ
1293+
heytingField = record { isHeytingField = isHeytingField }
1294+
1295+
12421296
------------------------------------------------------------------------
12431297
-- Properties of _*_ and _≤_
12441298

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Every decidable setoid induces tight apartness relation.
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible --safe #-}
8+
9+
open import Relation.Binary.Bundles using (DecSetoid; ApartnessRelation)
10+
11+
module Relation.Binary.Properties.DecSetoid {c ℓ} (S : DecSetoid c ℓ) where
12+
13+
open import Data.Product using (_,_)
14+
open import Data.Sum using (inj₁; inj₂)
15+
open import Relation.Binary.Definitions
16+
using (Cotransitive; Tight)
17+
import Relation.Binary.Properties.Setoid as SetoidProperties
18+
open import Relation.Binary.Structures
19+
using (IsApartnessRelation; IsDecEquivalence)
20+
open import Relation.Nullary.Decidable.Core
21+
using (yes; no; decidable-stable)
22+
23+
open DecSetoid S using (_≈_; _≉_; _≟_; setoid; trans)
24+
open SetoidProperties setoid
25+
26+
≉-cotrans : Cotransitive _≉_
27+
≉-cotrans {x} {y} x≉y z with x ≟ z | z ≟ y
28+
... | _ | no z≉y = inj₂ z≉y
29+
... | no x≉z | _ = inj₁ x≉z
30+
... | yes x≈z | yes z≈y = inj₁ λ _ x≉y (trans x≈z z≈y)
31+
32+
≉-isApartnessRelation : IsApartnessRelation _≈_ _≉_
33+
≉-isApartnessRelation = record
34+
{ irrefl = ≉-irrefl
35+
; sym = ≉-sym
36+
; cotrans = ≉-cotrans
37+
}
38+
39+
≉-apartnessRelation : ApartnessRelation c ℓ ℓ
40+
≉-apartnessRelation = record { isApartnessRelation = ≉-isApartnessRelation }
41+
42+
≉-tight : Tight _≈_ _≉_
43+
≉-tight x y = decidable-stable (x ≟ y) , ≉-irrefl

src/Relation/Binary/Properties/Setoid.agda

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
open import Data.Product.Base using (_,_)
1010
open import Function.Base using (_∘_; id; _$_; flip)
11-
open import Relation.Nullary.Negation.Core using (¬_)
11+
open import Relation.Nullary.Negation.Core using (¬_; contradiction)
1212
open import Relation.Binary.Core using (_⇒_)
1313
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
1414
open import Relation.Binary.Bundles using (Setoid; Preorder; Poset)
1515
open import Relation.Binary.Definitions
16-
using (Symmetric; _Respectsˡ_; _Respectsʳ_; _Respects₂_)
16+
using (Symmetric; _Respectsˡ_; _Respectsʳ_; _Respects₂_; Irreflexive)
1717
open import Relation.Binary.Structures using (IsPreorder; IsPartialOrder)
1818
open import Relation.Binary.Construct.Composition
1919
using (_;_; impliesˡ; transitive⇒≈;≈⊆≈)
@@ -80,6 +80,9 @@ preorder = record
8080
≉-resp₂ : _≉_ Respects₂ _≈_
8181
≉-resp₂ = ≉-respʳ , ≉-respˡ
8282

83+
≉-irrefl : Irreflexive _≈_ _≉_
84+
≉-irrefl x≈y x≉y = contradiction x≈y x≉y
85+
8386
------------------------------------------------------------------------
8487
-- Equality is closed under composition
8588

0 commit comments

Comments
 (0)