Skip to content

Commit 1695680

Browse files
Cleaning up Data.Integer.Properties (#146)
* Moved properties from `Data.Integer.Addition.Properties` and `Data.Integer.Multiplication.Properties` to `Data.Integer.Properties` and deprivatised `Data.Integer.Properties` * Added some additional properties from mechvel to Data.Integer.Properties * Added Sergei Meshveliani to README.agda
1 parent ebea5cc commit 1695680

File tree

7 files changed

+521
-318
lines changed

7 files changed

+521
-318
lines changed

CHANGELOG.md

+72-7
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,31 @@ but they may be removed in some future release of the library.
8080
have been deprecated in favour of `+-mono-≤` and `*-mono-≤` which better
8181
follow the library's naming conventions.
8282

83+
* The module `Data.Nat.Properties.Simple` is now deprecated. All proofs
84+
have been moved to `Data.Nat.Properties` where they should be used directly.
85+
The `Simple` file still exists for backwards compatability reasons and
86+
re-exports the proofs from `Data.Nat.Properties` but will be removed in some
87+
future release.
88+
89+
* The module `Data.Integer.Addition.Properties` is now deprecated. All proofs
90+
have been moved to `Data.Integer.Properties` where they should be used
91+
directly. The `Addition.Properties` file still exists for backwards
92+
compatability reasons and re-exports the proofs from `Data.Integer.Properties`
93+
but will be removed in some future release.
94+
95+
* The module `Data.Integer.Multiplication.Properties` is now deprecated. All
96+
proofs have been moved to `Data.Integer.Properties` where they should be used
97+
directly. The `Multiplication.Properties` file still exists for backwards
98+
compatability reasons and re-exports the proofs from `Data.Integer.Properties`
99+
but will be removed in some future release.
100+
83101
Backwards compatible changes
84102
----------------------------
85103

86104
* Added support for GHC 8.0.2.
87105

88106
* Added `Category.Functor.Morphism` and module `Category.Functor.Identity`.
89107

90-
* The module `Data.Nat.Properties.Simple` is now deprecated. All proofs
91-
have been moved to `Data.Nat.Properties` where they should be used directly.
92-
The `Simple` file still exists for backwards compatability reasons and
93-
re-exports the proofs from `Data.Nat.Properties` but will be removed in some
94-
future release.
95-
96108
* `Data.Container` and `Data.Container.Indexed` now allow for different
97109
levels in the container and in the data it contains.
98110

@@ -221,7 +233,46 @@ Backwards compatible changes
221233
∩⇔× : x ∈ p ∩ q ⇔ (x ∈ p × x ∈ q)
222234
```
223235

224-
* Added additional proofs to `Data.Nat.Properties`:
236+
* Added proofs to `Data.Integer.Properties`
237+
```agda
238+
+-injective : + m ≡ + n → m ≡ n
239+
-[1+-injective : -[1+ m ] ≡ -[1+ n ] → m ≡ n
240+
241+
doubleNeg : - - n ≡ n
242+
neg-injective : - m ≡ - n → m ≡ n
243+
244+
∣n∣≡0⇒n≡0 : ∀ {n} → ∣ n ∣ ≡ 0 → n ≡ + 0
245+
∣-n∣≡∣n∣ : ∀ n → ∣ - n ∣ ≡ ∣ n ∣
246+
247+
+◃n≡+n : Sign.+ ◃ n ≡ + n
248+
-◃n≡-n : Sign.- ◃ n ≡ - + n
249+
signₙ◃∣n∣≡n : sign n ◃ ∣ n ∣ ≡ n
250+
251+
⊖-≰ : n ≰ m → m ⊖ n ≡ - + (n ∸ m)
252+
∣⊖∣-≰ : n ≰ m → ∣ m ⊖ n ∣ ≡ n ∸ m
253+
sign-⊖-≰ : n ≰ m → sign (m ⊖ n) ≡ Sign.-
254+
-[n⊖m]≡-m+n : - (m ⊖ n) ≡ (- (+ m)) + (+ n)
255+
256+
+-identity : Identity (+ 0) _+_
257+
+-inverse : Inverse (+ 0) -_ _+_
258+
+-0-isMonoid : IsMonoid _≡_ _+_ (+ 0)
259+
+-0-isGroup : IsGroup _≡_ _+_ (+ 0) (-_)
260+
neg-distrib-+ : - (m + n) ≡ (- m) + (- n)
261+
◃-distrib-+ : s ◃ (m + n) ≡ (s ◃ m) + (s ◃ n)
262+
263+
*-identityʳ : RightIdentity (+ 1) _*_
264+
*-identity : Identity (+ 1) _*_
265+
*-zeroˡ : LeftZero (+ 0) _*_
266+
*-zeroʳ : RightZero (+ 0) _*_
267+
*-zero : Zero (+ 0) _*_
268+
*-1-isMonoid : IsMonoid _≡_ _*_ (+ 1)
269+
-1*n≡-n : -[1+ 0 ] * n ≡ - n
270+
271+
+-*-isRing : IsRing _≡_ _+_ _*_ -_ (+ 0) (+ 1)
272+
+-*-isCommutativeRing : IsCommutativeRing _≡_ _+_ _*_ -_ (+ 0) (+ 1)
273+
```
274+
275+
* Added proofs to `Data.Nat.Properties`:
225276
```agda
226277
suc-injective : suc m ≡ suc n → m ≡ n
227278
≡-isDecEquivalence : IsDecEquivalence (_≡_ {A = ℕ})
@@ -374,6 +425,20 @@ Backwards compatible changes
374425
zipWith-map₂ : zipWith _⊕_ xs (map f ys) ≡ zipWith (λ x y → x ⊕ f y) xs ys
375426
```
376427

428+
* Added proofs to `Data.Sign.Properties`:
429+
```agda
430+
opposite-cong : opposite s ≡ opposite t → s ≡ t
431+
432+
*-identityˡ : LeftIdentity + _*_
433+
*-identityʳ : RightIdentity + _*_
434+
*-identity : Identity + _*_
435+
*-comm : Commutative _*_
436+
*-assoc : Associative _*_
437+
cancel-*-left : LeftCancellative _*_
438+
*-cancellative : Cancellative _*_
439+
s*s≡+ : s * s ≡ +
440+
```
441+
377442
* Added proofs to `Data.Vec.All.Properties`
378443
```agda
379444
All-++⁺ : All P xs → All P ys → All P (xs ++ ys)

README.agda

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ module README where
88
-- Joachim Breitner, Samuel Bronson, Daniel Brown, James Chapman,
99
-- Liang-Ting Chen, Matthew Daggitt, Dominique Devriese, Dan Doel,
1010
-- Érdi Gergő, Helmut Grohne, Simon Foster, Liyang Hu, Patrik Jansson,
11-
-- Alan Jeffrey, Pepijn Kokke, Evgeny Kotelnikov, Eric Mertens, Darin
12-
-- Morrison, Guilhem Moulin, Shin-Cheng Mu, Ulf Norell, Noriyuki
13-
-- OHKAWA, Nicolas Pouillard, Andrés Sicard-Ramírez, Noam Zeilberger
14-
-- and some anonymous contributors.
11+
-- Alan Jeffrey, Pepijn Kokke, Evgeny Kotelnikov, Sergei Meshveliani
12+
-- Eric Mertens, Darin Morrison, Guilhem Moulin, Shin-Cheng Mu,
13+
-- Ulf Norell, Noriyuki OHKAWA, Nicolas Pouillard, Andrés Sicard-Ramírez,
14+
-- Noam Zeilberger and some anonymous contributors.
1515
-- ----------------------------------------------------------------------
1616

1717
-- The development version of the library often requires the latest

src/Data/Integer/Addition/Properties.agda

+19-103
Original file line numberDiff line numberDiff line change
@@ -2,110 +2,26 @@
22
-- The Agda standard library
33
--
44
-- Properties related to addition of integers
5+
--
6+
-- This module is DEPRECATED. Please use the corresponding properties in
7+
-- Data.Integer.Properties directly.
58
------------------------------------------------------------------------
69

710
module Data.Integer.Addition.Properties where
811

9-
open import Algebra
10-
open import Algebra.Structures
11-
open import Data.Integer hiding (suc)
12-
open import Data.Nat.Base using (suc; zero) renaming (_+_ to _ℕ+_)
13-
import Data.Nat.Properties as ℕ
14-
open import Relation.Binary.PropositionalEquality
15-
open import Algebra.FunctionProperties (_≡_ {A = ℤ})
16-
17-
------------------------------------------------------------------------
18-
-- Addition and zero form a commutative monoid
19-
20-
comm : Commutative _+_
21-
comm -[1+ a ] -[1+ b ] rewrite ℕ.+-comm a b = refl
22-
comm (+ a ) (+ b ) rewrite ℕ.+-comm a b = refl
23-
comm -[1+ _ ] (+ _ ) = refl
24-
comm (+ _ ) -[1+ _ ] = refl
25-
26-
identityˡ : LeftIdentity (+ 0) _+_
27-
identityˡ -[1+ _ ] = refl
28-
identityˡ (+ _ ) = refl
29-
30-
identityʳ : RightIdentity (+ 0) _+_
31-
identityʳ x rewrite comm x (+ 0) = identityˡ x
32-
33-
distribˡ-⊖-+-neg : a b c b ⊖ c + -[1+ a ] ≡ b ⊖ (suc c ℕ+ a)
34-
distribˡ-⊖-+-neg _ zero zero = refl
35-
distribˡ-⊖-+-neg _ zero (suc _) = refl
36-
distribˡ-⊖-+-neg _ (suc _) zero = refl
37-
distribˡ-⊖-+-neg a (suc b) (suc c) = distribˡ-⊖-+-neg a b c
38-
39-
distribʳ-⊖-+-neg : a b c -[1+ a ] + (b ⊖ c) ≡ b ⊖ (suc a ℕ+ c)
40-
distribʳ-⊖-+-neg a b c
41-
rewrite comm -[1+ a ] (b ⊖ c)
42-
| distribˡ-⊖-+-neg a b c
43-
| ℕ.+-comm a c
44-
= refl
45-
46-
distribˡ-⊖-+-pos : a b c b ⊖ c + + a ≡ b ℕ+ a ⊖ c
47-
distribˡ-⊖-+-pos _ zero zero = refl
48-
distribˡ-⊖-+-pos _ zero (suc _) = refl
49-
distribˡ-⊖-+-pos _ (suc _) zero = refl
50-
distribˡ-⊖-+-pos a (suc b) (suc c) = distribˡ-⊖-+-pos a b c
51-
52-
distribʳ-⊖-+-pos : a b c + a + (b ⊖ c) ≡ a ℕ+ b ⊖ c
53-
distribʳ-⊖-+-pos a b c
54-
rewrite comm (+ a) (b ⊖ c)
55-
| distribˡ-⊖-+-pos a b c
56-
| ℕ.+-comm a b
57-
= refl
58-
59-
assoc : Associative _+_
60-
assoc (+ zero) y z rewrite identityˡ y | identityˡ (y + z) = refl
61-
assoc x (+ zero) z rewrite identityʳ x | identityˡ z = refl
62-
assoc x y (+ zero) rewrite identityʳ (x + y) | identityʳ y = refl
63-
assoc -[1+ a ] -[1+ b ] (+ suc c) = sym (distribʳ-⊖-+-neg a c b)
64-
assoc -[1+ a ] (+ suc b) (+ suc c) = distribˡ-⊖-+-pos (suc c) b a
65-
assoc (+ suc a) -[1+ b ] -[1+ c ] = distribˡ-⊖-+-neg c a b
66-
assoc (+ suc a) -[1+ b ] (+ suc c)
67-
rewrite distribˡ-⊖-+-pos (suc c) a b
68-
| distribʳ-⊖-+-pos (suc a) c b
69-
| sym (ℕ.+-assoc a 1 c)
70-
| ℕ.+-comm a 1
71-
= refl
72-
assoc (+ suc a) (+ suc b) -[1+ c ]
73-
rewrite distribʳ-⊖-+-pos (suc a) b c
74-
| sym (ℕ.+-assoc a 1 b)
75-
| ℕ.+-comm a 1
76-
= refl
77-
assoc -[1+ a ] -[1+ b ] -[1+ c ]
78-
rewrite sym (ℕ.+-assoc a 1 (b ℕ+ c))
79-
| ℕ.+-comm a 1
80-
| ℕ.+-assoc a b c
81-
= refl
82-
assoc -[1+ a ] (+ suc b) -[1+ c ]
83-
rewrite distribʳ-⊖-+-neg a b c
84-
| distribˡ-⊖-+-neg c b a
85-
= refl
86-
assoc (+ suc a) (+ suc b) (+ suc c)
87-
rewrite ℕ.+-assoc (suc a) (suc b) (suc c)
88-
= refl
89-
90-
isSemigroup : IsSemigroup _≡_ _+_
91-
isSemigroup = record
92-
{ isEquivalence = isEquivalence
93-
; assoc = assoc
94-
; ∙-cong = cong₂ _+_
95-
}
96-
97-
isCommutativeMonoid : IsCommutativeMonoid _≡_ _+_ (+ 0)
98-
isCommutativeMonoid = record
99-
{ isSemigroup = isSemigroup
100-
; identityˡ = identityˡ
101-
; comm = comm
102-
}
103-
104-
commutativeMonoid : CommutativeMonoid _ _
105-
commutativeMonoid = record
106-
{ Carrier =
107-
; _≈_ = _≡_
108-
; _∙_ = _+_
109-
; ε = + 0
110-
; isCommutativeMonoid = isCommutativeMonoid
111-
}
12+
open import Data.Integer.Properties public
13+
using
14+
( distribˡ-⊖-+-neg
15+
; distribʳ-⊖-+-neg
16+
; distribˡ-⊖-+-pos
17+
; distribʳ-⊖-+-pos
18+
)
19+
renaming
20+
( +-comm to comm
21+
; +-identityˡ to identityˡ
22+
; +-identityʳ to identityʳ
23+
; +-assoc to assoc
24+
; +-isSemigroup to isSemigroup
25+
; +-0-isCommutativeMonoid to isCommutativeMonoid
26+
; +-0-commutativeMonoid to commutativeMonoid
27+
)

src/Data/Integer/Base.agda

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ _⊓_ : ℤ → ℤ → ℤ
146146

147147
data _≤_ : Set where
148148
-≤+ : {m n} -[1+ m ] ≤ + n
149-
-≤- : {m n} (n≤m : ℕ._≤_ n m) -[1+ m ] ≤ -[1+ n ]
150-
+≤+ : {m n} (m≤n : ℕ._≤_ m n) + m ≤ + n
149+
-≤- : {m n} (n≤m : n ℕ.≤ m) -[1+ m ] ≤ -[1+ n ]
150+
+≤+ : {m n} (m≤n : m ℕ.≤ n) + m ≤ + n
151151

152152
drop‿+≤+ : {m n} + m ≤ + n ℕ._≤_ m n
153153
drop‿+≤+ (+≤+ m≤n) = m≤n

src/Data/Integer/Multiplication/Properties.agda

+13-79
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,20 @@
22
-- The Agda standard library
33
--
44
-- Properties related to multiplication of integers
5+
--
6+
-- This module is DEPRECATED. Please use the corresponding properties in
7+
-- Data.Integer.Properties directly.
58
------------------------------------------------------------------------
69

710
module Data.Integer.Multiplication.Properties where
811

9-
open import Algebra using (CommutativeMonoid)
10-
open import Algebra.Structures using (IsSemigroup; IsCommutativeMonoid)
11-
open import Data.Integer
12-
using (ℤ; -[1+_]; +_; ∣_∣; sign; _◃_) renaming (_*_ to ℤ*)
13-
open import Data.Nat
14-
using (suc; zero) renaming (_+_ to _ℕ+_; _*_ to _ℕ*_)
15-
open import Data.Product using (proj₂)
16-
import Data.Nat.Properties as ℕ
17-
open import Data.Sign using () renaming (_*_ to _S*_)
18-
open import Function using (_∘_)
19-
open import Relation.Binary.PropositionalEquality
20-
using (_≡_; refl; cong; cong₂; isEquivalence)
21-
22-
open import Algebra.FunctionProperties (_≡_ {A = ℤ})
23-
24-
------------------------------------------------------------------------
25-
-- Multiplication and one form a commutative monoid
26-
27-
private
28-
lemma : a b c c ℕ+ (b ℕ+ a ℕ* suc b) ℕ* suc c
29-
≡ c ℕ+ b ℕ* suc c ℕ+ a ℕ* suc (c ℕ+ b ℕ* suc c)
30-
lemma =
31-
solve 3 (λ a b c c :+ (b :+ a :* (con 1 :+ b)) :* (con 1 :+ c)
32-
:= c :+ b :* (con 1 :+ c) :+
33-
a :* (con 1 :+ (c :+ b :* (con 1 :+ c))))
34-
refl
35-
where open ℕ.SemiringSolver
36-
37-
38-
identityˡ : LeftIdentity (+ 1) ℤ*
39-
identityˡ (+ zero ) = refl
40-
identityˡ -[1+ n ] rewrite ℕ.+-right-identity n = refl
41-
identityˡ (+ suc n) rewrite ℕ.+-right-identity n = refl
42-
43-
comm : Commutative ℤ*
44-
comm -[1+ a ] -[1+ b ] rewrite ℕ.*-comm (suc a) (suc b) = refl
45-
comm -[1+ a ] (+ b ) rewrite ℕ.*-comm (suc a) b = refl
46-
comm (+ a ) -[1+ b ] rewrite ℕ.*-comm a (suc b) = refl
47-
comm (+ a ) (+ b ) rewrite ℕ.*-comm a b = refl
48-
49-
assoc : Associative ℤ*
50-
assoc (+ zero) _ _ = refl
51-
assoc x (+ zero) _ rewrite ℕ.*-right-zero ∣ x ∣ = refl
52-
assoc x y (+ zero) rewrite
53-
ℕ.*-right-zero ∣ y ∣
54-
| ℕ.*-right-zero ∣ x ∣
55-
| ℕ.*-right-zero ∣ sign x S* sign y ◃ ∣ x ∣ ℕ* ∣ y ∣ ∣
56-
= refl
57-
assoc -[1+ a ] -[1+ b ] (+ suc c) = cong (+_ ∘ suc) (lemma a b c)
58-
assoc -[1+ a ] (+ suc b) -[1+ c ] = cong (+_ ∘ suc) (lemma a b c)
59-
assoc (+ suc a) (+ suc b) (+ suc c) = cong (+_ ∘ suc) (lemma a b c)
60-
assoc (+ suc a) -[1+ b ] -[1+ c ] = cong (+_ ∘ suc) (lemma a b c)
61-
assoc -[1+ a ] -[1+ b ] -[1+ c ] = cong -[1+_] (lemma a b c)
62-
assoc -[1+ a ] (+ suc b) (+ suc c) = cong -[1+_] (lemma a b c)
63-
assoc (+ suc a) -[1+ b ] (+ suc c) = cong -[1+_] (lemma a b c)
64-
assoc (+ suc a) (+ suc b) -[1+ c ] = cong -[1+_] (lemma a b c)
65-
66-
isSemigroup : IsSemigroup _ _
67-
isSemigroup = record
68-
{ isEquivalence = isEquivalence
69-
; assoc = assoc
70-
; ∙-cong = cong₂ ℤ*
71-
}
72-
73-
isCommutativeMonoid : IsCommutativeMonoid _≡_ ℤ* (+ 1)
74-
isCommutativeMonoid = record
75-
{ isSemigroup = isSemigroup
76-
; identityˡ = identityˡ
77-
; comm = comm
78-
}
79-
80-
commutativeMonoid : CommutativeMonoid _ _
81-
commutativeMonoid = record
82-
{ Carrier =
83-
; _≈_ = _≡_
84-
; _∙_ = ℤ*
85-
; ε = + 1
86-
; isCommutativeMonoid = isCommutativeMonoid
87-
}
12+
open import Data.Integer.Properties public
13+
using ()
14+
renaming
15+
( *-comm to comm
16+
; *-identityˡ to identityˡ
17+
; *-assoc to assoc
18+
; *-isSemigroup to isSemigroup
19+
; *-1-isCommutativeMonoid to isCommutativeMonoid
20+
; *-1-commutativeMonoid to commutativeMonoid
21+
)

0 commit comments

Comments
 (0)