Skip to content

Commit c03b4b4

Browse files
author
Mathieu Montin
authored
Additional compositions with binary functions (#1259)
1 parent 20e9d7a commit c03b4b4

File tree

8 files changed

+134
-57
lines changed

8 files changed

+134
-57
lines changed

CHANGELOG.md

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ Deprecated names
9494
*-+-commutativeSemiring ↦ +-*-commutativeSemiring
9595
*-+-isSemiringWithoutAnnihilatingZero ↦ +-*-isSemiringWithoutAnnihilatingZero
9696
```
97+
* In ̀Function.Basè:
98+
```
99+
*_-[_]-_ ↦ _-⟪_⟫-_
100+
```
97101

98102
* `Data.List.Relation.Unary.Any.any` to `Data.List.Relation.Unary.Any.any?`
99103
* `Data.List.Relation.Unary.All.all` to `Data.List.Relation.Unary.All.all?`
@@ -243,17 +247,17 @@ Other minor additions
243247
244248
* Added new properties to `Data.Fin.Properties`:
245249
```agda
246-
toℕ≤n : (i : Fin n) → toℕ i ℕ.≤ n
247-
≤fromℕ : (i : Fin (ℕ.suc n)) → i ≤ fromℕ n
250+
toℕ≤n : (i : Fin n) → toℕ i ℕ.≤ n
251+
≤fromℕ : (i : Fin (ℕ.suc n)) → i ≤ fromℕ n
248252
fromℕ<-irrelevant : m ≡ n → (m<o : m ℕ.< o) → (n<o : n ℕ.< o) → fromℕ< m<o ≡ fromℕ< n<o
249-
fromℕ<-injective : fromℕ< m<o ≡ fromℕ< n<o → m ≡ n
250-
inject₁ℕ< : (i : Fin n) → toℕ (inject₁ i) ℕ.< n
251-
inject₁ℕ≤ : (i : Fin n) → toℕ (inject₁ i) ℕ.≤ n
252-
≤̄⇒inject₁< : i' ≤ i → inject₁ i' < suc i
253-
ℕ<⇒inject₁< : toℕ i' ℕ.< toℕ i → inject₁ i' < i
254-
toℕ-lower₁ : (p : m ≢ toℕ x) → toℕ (lower₁ x p) ≡ toℕ x
253+
fromℕ<-injective : fromℕ< m<o ≡ fromℕ< n<o → m ≡ n
254+
inject₁ℕ< : (i : Fin n) → toℕ (inject₁ i) ℕ.< n
255+
inject₁ℕ≤ : (i : Fin n) → toℕ (inject₁ i) ℕ.≤ n
256+
≤̄⇒inject₁< : i' ≤ i → inject₁ i' < suc i
257+
ℕ<⇒inject₁< : toℕ i' ℕ.< toℕ i → inject₁ i' < i
258+
toℕ-lower₁ : (p : m ≢ toℕ x) → toℕ (lower₁ x p) ≡ toℕ x
255259
inject₁≡⇒lower₁≡ : (≢p : n ≢ (toℕ i')) → inject₁ i ≡ i' → lower₁ i' ≢p ≡ i
256-
pred< : pred i < i
260+
pred< : pred i < i
257261
```
258262

259263
* Added new types and constructors to `Data.Integer.Base`:
@@ -356,10 +360,10 @@ Other minor additions
356360
cartesianProductWith⁻ : (∀ {x y} → R (f x y) → P x × Q y) → Any R (cartesianProductWith f xs ys) → Any P xs × Any Q ys
357361
cartesianProduct⁺ : Any P xs → Any Q ys → Any (P ⟨×⟩ Q) (cartesianProduct xs ys)
358362
cartesianProduct⁻ : Any (P ⟨×⟩ Q) (cartesianProduct xs ys) → Any P xs × Any Q ys
359-
reverseAcc⁺ : ∀ acc xs → Any P acc ⊎ Any P xs → Any P (reverseAcc acc xs)
360-
reverseAcc⁻ : ∀ acc xs → Any P (reverseAcc acc xs) -> Any P acc ⊎ Any P xs
361-
reverse⁺ : Any P xs → Any P (reverse xs)
362-
reverse⁻ : Any P (reverse xs) → Any P xs
363+
reverseAcc⁺ : ∀ acc xs → Any P acc ⊎ Any P xs → Any P (reverseAcc acc xs)
364+
reverseAcc⁻ : ∀ acc xs → Any P (reverseAcc acc xs) -> Any P acc ⊎ Any P xs
365+
reverse⁺ : Any P xs → Any P (reverse xs)
366+
reverse⁻ : Any P (reverse xs) → Any P xs
363367
```
364368

365369
* Added new proofs to `Data.List.Relation.Unary.Unique.Propositional.Properties`:
@@ -410,7 +414,7 @@ Other minor additions
410414
* Added new functions to `Data.String.Base`:
411415
```agda
412416
wordsBy : Decidable P → String → List String
413-
words : String → List String
417+
words : String → List String
414418
```
415419

416420
* Added new types and constructors to `Data.Nat.Base`:
@@ -485,9 +489,9 @@ Other minor additions
485489

486490
* Added new functions to `Function.Base`:
487491
```agda
488-
_∘₂_ : (f : {x : A₁} → {y : A₂ x} → (z : B x y) → C z)
489-
→ (g : (x : A₁) → (y : A₂ x) → B x y)
490-
→ ((x : A₁) → (y : A₂ x) → C (g x y))
492+
_∘₂_ : (f : {x : A₁} → {y : A₂ x} → (z : B x y) → C z)
493+
→ (g : (x : A₁) → (y : A₂ x) → B x y)
494+
→ ((x : A₁) → (y : A₂ x) → C (g x y))
491495
492496
_∘₂′_ : (C → D) → (A → B → C) → (A → B → D)
493497
```
@@ -499,55 +503,72 @@ Other minor additions
499503

500504
* Added new functions to `Data.Fin.Base`:
501505
```agda
502-
quotRem : ∀ {n} k → Fin (n ℕ.* k) → Fin k × Fin n
506+
quotRem : ∀ {n} k → Fin (n ℕ.* k) → Fin k × Fin n
503507
opposite : ∀ {n} → Fin n → Fin n
504508
```
505509

506510
* Added new proofs to `Data.Fin.Properties`:
507511
```agda
508-
splitAt-< : ∀ m {n} i → (i<m : toℕ i ℕ.< m) → splitAt m {n} i ≡ inj₁ (fromℕ< i<m)
509-
splitAt-≥ : ∀ m {n} i → (i≥m : toℕ i ℕ.≥ m) → splitAt m {n} i ≡ inj₂ (reduce≥ i i≥m)
512+
splitAt-< : ∀ m {n} i → (i<m : toℕ i ℕ.< m) → splitAt m {n} i ≡ inj₁ (fromℕ< i<m)
513+
splitAt-≥ : ∀ m {n} i → (i≥m : toℕ i ℕ.≥ m) → splitAt m {n} i ≡ inj₂ (reduce≥ i i≥m)
510514
inject≤-injective : ∀ (n≤m n≤m′ : n ℕ.≤ m) x y → inject≤ x n≤m ≡ inject≤ y n≤m′ → x ≡ y
511515
```
512516

513517
* Added new proofs to `Data.Vec.Properties`:
514518
```agda
515-
unfold-take : ∀ n {m} x (xs : Vec A (n + m)) → take (suc n) (x ∷ xs) ≡ x ∷ take n xs
516-
unfold-drop : ∀ n {m} x (xs : Vec A (n + m)) → drop (suc n) (x ∷ xs) ≡ drop n xs
519+
unfold-take : ∀ n {m} x (xs : Vec A (n + m)) → take (suc n) (x ∷ xs) ≡ x ∷ take n xs
520+
unfold-drop : ∀ n {m} x (xs : Vec A (n + m)) → drop (suc n) (x ∷ xs) ≡ drop n xs
517521
lookup-inject≤-take : ∀ m {n} (m≤m+n : m ≤ m + n) (i : Fin m) (xs : Vec A (m + n)) →
518522
lookup xs (Fin.inject≤ i m≤m+n) ≡ lookup (take m xs) i
519523
```
520524

521525
* Added new functions to `Data.Vec.Functional`:
522526
```agda
523-
length : ∀ {n} → Vector A n → ℕ
524-
insert : ∀ {n} → Vector A n → Fin (suc n) → A → Vector A (suc n)
525-
updateAt : ∀ {n} → Fin n → (A → A) → Vector A n → Vector A n
526-
_++_ : ∀ {m n} → Vector A m → Vector A n → Vector A (m ℕ.+ n)
527-
concat : ∀ {m n} → Vector (Vector A m) n → Vector A (n ℕ.* m)
528-
_>>=_ : ∀ {m n} → Vector A m → (A → Vector B n) → Vector B (m ℕ.* n)
527+
length : ∀ {n} → Vector A n → ℕ
528+
insert : ∀ {n} → Vector A n → Fin (suc n) → A → Vector A (suc n)
529+
updateAt : ∀ {n} → Fin n → (A → A) → Vector A n → Vector A n
530+
_++_ : ∀ {m n} → Vector A m → Vector A n → Vector A (m ℕ.+ n)
531+
concat : ∀ {m n} → Vector (Vector A m) n → Vector A (n ℕ.* m)
532+
_>>=_ : ∀ {m n} → Vector A m → (A → Vector B n) → Vector B (m ℕ.* n)
529533
unzipWith : ∀ {n} → (A → B × C) → Vector A n → Vector B n × Vector C n
530-
unzip : ∀ {n} → Vector (A × B) n → Vector A n × Vector B n
531-
take : ∀ m {n} → Vector A (m ℕ.+ n) → Vector A m
532-
drop : ∀ m {n} → Vector A (m ℕ.+ n) → Vector A n
533-
reverse : ∀ {n} → Vector A n → Vector A n
534-
init : ∀ {n} → Vector A (suc n) → Vector A n
535-
last : ∀ {n} → Vector A (suc n) → A
534+
unzip : ∀ {n} → Vector (A × B) n → Vector A n × Vector B n
535+
take : ∀ m {n} → Vector A (m ℕ.+ n) → Vector A m
536+
drop : ∀ m {n} → Vector A (m ℕ.+ n) → Vector A n
537+
reverse : ∀ {n} → Vector A n → Vector A n
538+
init : ∀ {n} → Vector A (suc n) → Vector A n
539+
last : ∀ {n} → Vector A (suc n) → A
536540
transpose : ∀ {m n} → Vector (Vector A n) m → Vector (Vector A m) n
537541
```
538542

543+
* Added a new simple function in `Function.Base`:
544+
```agda
545+
constᵣ : A → B → B
546+
```
547+
548+
* Added new compositions with a binary function in `Function.Base`:
549+
```agda
550+
_-⟪_∣ : (A → B → C) → (C → B → D) → (A → B → D)
551+
∣_⟫-_ : (A → C → D) → (A → B → C) → (A → B → D)
552+
_-⟨_∣ : (A → C) → (C → B → D) → (A → B → D)
553+
∣_⟩-_ : (A → C → D) → (B → C) → (A → B → D)
554+
_-⟪_⟩-_ : (A → B → C) → (C → D → E) → (B → D) → (A → B → E)
555+
_-⟨_⟫-_ : (A → C) → (C → D → E) → (A → B → D) → (A → B → E)
556+
_-⟨_⟩-_ : (A → C) → (C → D → E) → (B → D) → (A → B → E)
557+
_on₂_ : (C → C → D) → (A → B → C) → (A → B → D)
558+
```
559+
539560
* Added new functions to `Data.Vec.Relation.Unary.All`:
540561
```agda
541562
reduce : (f : ∀ {x} → P x → B) → All P xs → Vec B n
542563
```
543564

544565
* Added new proofs to `Data.Vec.Relation.Unary.All.Properties`:
545566
```agda
546-
All-swap : ∀ {xs ys} → All (λ x → All (x ~_) ys) xs → All (λ y → All (_~ y) xs) ys
567+
All-swap : ∀ {xs ys} → All (λ x → All (x ~_) ys) xs → All (λ y → All (_~ y) xs) ys
547568
tabulate⁺ : ∀ {f : Fin n → A} → (∀ i → P (f i)) → All P (tabulate f)
548569
tabulate⁻ : ∀ {f : Fin n → A} → All P (tabulate f) → (∀ i → P (f i))
549-
drop⁺ : ∀ {n} m {xs} → All P {m + n} xs → All P {n} (drop m xs)
550-
take⁺ : ∀ {n} m {xs} → All P {m + n} xs → All P {m} (take m xs)
570+
drop⁺ : ∀ {n} m {xs} → All P {m + n} xs → All P {n} (drop m xs)
571+
take⁺ : ∀ {n} m {xs} → All P {m + n} xs → All P {m} (take m xs)
551572
```
552573

553574
* Added new proofs to `Data.Vec.Membership.Propositional.Properties`:

src/Category/Applicative/Indexed.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ record RawIApplicative {I : Set i} (F : IFun I f) :
5353
x <⊛ y = const <$> x ⊛ y
5454

5555
_⊛>_ : {i j k} F i j A F j k B F i k B
56-
x ⊛> y = flip const <$> x ⊛ y
56+
x ⊛> y = constᵣ <$> x ⊛ y
5757

5858
_⊗_ : {i j k} F i j A F j k B F i k (A × B)
5959
x ⊗ y = (_,_) <$> x ⊛ y

src/Category/Applicative/Predicate.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ record RawPApplicative {I : Set i} (F : Pt I ℓ) :
4545
x <⊛ y = const <$> x ⊛ y
4646

4747
_⊛>_ : {P Q} const ( {i} F P i) ⊆ F Q ⇒ F Q
48-
x ⊛> y = flip const <$> x ⊛ y
48+
x ⊛> y = constᵣ <$> x ⊛ y
4949

5050
_⊗_ : {P Q} F P ⊆ F Q ⇒ F (P ∩ Q)
5151
x ⊗ y = (_,_) <$> x ⊛ y

src/Data/Product.agda

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ swap : A × B → B × A
153153
swap (x , y) = (y , x)
154154

155155
_-×-_ : (A B Set p) (A B Set q) (A B Set _)
156-
f -×- g = f -[ _×_ ]- g
156+
f -×- g = f - _×_ - g
157157

158158
_-,-_ : (A B C) (A B D) (A B C × D)
159-
f -,- g = f -[ _,_ ]- g
159+
f -,- g = f - _,_ - g

src/Data/Sum/Base.agda

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
module Data.Sum.Base where
1010

1111
open import Data.Bool.Base using (true; false)
12-
open import Function.Base using (_∘_; _-[_]-_ ; id)
12+
open import Function.Base using (_∘_; _-⟪_⟫-_ ; id)
1313
open import Relation.Nullary.Reflects using (invert)
1414
open import Relation.Nullary using (Dec; yes; no; _because_; ¬_)
1515
open import Level using (Level; _⊔_)
@@ -64,7 +64,7 @@ map₂ = map id
6464

6565
infixr 1 _-⊎-_
6666
_-⊎-_ : (A B Set c) (A B Set d) (A B Set (c ⊔ d))
67-
f -⊎- g = f -[ _⊎_ ]- g
67+
f -⊎- g = f - _⊎_ - g
6868

6969
-- Conversion back and forth with Dec
7070

src/Data/These.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ leftMost : These A A → A
4040
leftMost = fold id id const
4141

4242
rightMost : These A A A
43-
rightMost = fold id id (flip const)
43+
rightMost = fold id id constᵣ
4444

4545
mergeThese : (A A A) These A A A
4646
mergeThese = fold id id

src/Function/Base.agda

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ id x = x
3131
const : A B A
3232
const x = λ _ x
3333

34+
constᵣ : A B B
35+
constᵣ _ = id
36+
3437
------------------------------------------------------------------------
3538
-- Operations on dependent functions
3639

@@ -164,8 +167,6 @@ case x of f = case x return _ of f
164167
------------------------------------------------------------------------
165168
-- Operations that are only defined for non-dependent functions
166169

167-
infixr 0 _-[_]-_
168-
infixl 1 _on_
169170
infixl 1 _⟨_⟩_
170171
infixl 0 _∋_
171172

@@ -174,16 +175,6 @@ infixl 0 _∋_
174175
_⟨_⟩_ : A (A B C) B C
175176
x ⟨ f ⟩ y = f x y
176177

177-
-- Composition of a binary function with a unary function
178-
179-
_on_ : (B B C) (A B) (A A C)
180-
_*_ on f = λ x y f x * f y
181-
182-
-- Composition of three binary functions
183-
184-
_-[_]-_ : (A B C) (C D E) (A B D) (A B E)
185-
f -[ _*_ ]- g = λ x y f x y * g x y
186-
187178
-- In Agda you cannot annotate every subexpression with a type
188179
-- signature. This function can be used instead.
189180

@@ -200,3 +191,67 @@ typeOf {A = A} _ = A
200191

201192
it : {A : Set a} {{A}} A
202193
it {{x}} = x
194+
195+
------------------------------------------------------------------------
196+
-- Composition of a binary function with other functions
197+
198+
infixr 0 _-⟪_⟫-_ _-⟨_⟫-_
199+
infixl 0 _-⟪_⟩-_
200+
infixr 1 _-⟨_⟩-_ ∣_⟫-_ ∣_⟩-_
201+
infixl 1 _on_ _on₂_ _-⟪_∣ _-⟨_∣
202+
203+
-- Two binary functions
204+
205+
_-⟪_⟫-_ : (A B C) (C D E) (A B D) (A B E)
206+
f -⟪ _*_ ⟫- g = λ x y f x y * g x y
207+
208+
-- A single binary function on the left
209+
210+
_-⟪_∣ : (A B C) (C B D) (A B D)
211+
f -⟪ _*_ ∣ = f -⟪ _*_ ⟫- constᵣ
212+
213+
-- A single binary function on the right
214+
215+
∣_⟫-_ : (A C D) (A B C) (A B D)
216+
∣ _*_ ⟫- g = const -⟪ _*_ ⟫- g
217+
218+
-- A single unary function on the left
219+
220+
_-⟨_∣ : (A C) (C B D) (A B D)
221+
f -⟨ _*_ ∣ = f ∘₂ const -⟪ _*_ ∣
222+
223+
-- A single unary function on the right
224+
225+
∣_⟩-_ : (A C D) (B C) (A B D)
226+
∣ _*_ ⟩- g = ∣ _*_ ⟫- g ∘₂ constᵣ
227+
228+
-- A binary function and a unary function
229+
230+
_-⟪_⟩-_ : (A B C) (C D E) (B D) (A B E)
231+
f -⟪ _*_ ⟩- g = f -⟪ _*_ ⟫- ∣ constᵣ ⟩- g
232+
233+
-- A unary function and a binary function
234+
235+
_-⟨_⟫-_ : (A C) (C D E) (A B D) (A B E)
236+
f -⟨ _*_ ⟫- g = f -⟨ const ∣ -⟪ _*_ ⟫- g
237+
238+
-- Two unary functions
239+
240+
_-⟨_⟩-_ : (A C) (C D E) (B D) (A B E)
241+
f -⟨ _*_ ⟩- g = f -⟨ const ∣ -⟪ _*_ ⟫- ∣ constᵣ ⟩- g
242+
243+
-- A single binary function on both sides
244+
245+
_on₂_ : (C C D) (A B C) (A B D)
246+
_*_ on₂ f = f -⟪ _*_ ⟫- f
247+
248+
-- A single unary function on both sides
249+
250+
_on_ : (B B C) (A B) (A A C)
251+
_*_ on f = f -⟨ _*_ ⟩- f
252+
253+
_-[_]-_ = _-⟪_⟫-_
254+
{-# WARNING_ON_USAGE _-[_]-_
255+
"Warning: Function._-[_]-_ was deprecated in v1.4.
256+
Please use _-⟪_⟫-_ instead."
257+
#-}

src/Function/Definitions.agda

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ module Function.Definitions
1919
open import Data.Product using (∃; _×_)
2020
import Function.Definitions.Core1 as Core₁
2121
import Function.Definitions.Core2 as Core₂
22+
open import Function.Base
2223
open import Level using (_⊔_)
2324

2425
------------------------------------------------------------------------
2526
-- Definitions
2627

2728
Congruent : (A B) Set (a ⊔ ℓ₁ ⊔ ℓ₂)
28-
Congruent f = {x y} x ≈₁ y f x ≈₂ f y
29+
Congruent f = {x y} x ≈₁ y f x ≈₂ f y
2930

3031
Injective : (A B) Set (a ⊔ ℓ₁ ⊔ ℓ₂)
3132
Injective f = {x y} f x ≈₂ f y x ≈₁ y

0 commit comments

Comments
 (0)