Skip to content

Commit e3e94c8

Browse files
authored
[ refactor ] Data.Fin.Properties following #2746 (#2782)
* refactor: following #2746 * refactor: deploy the `flip contradiction` workaround * refactor: prefer `<⇒notInjective` over `injective⇒≤` * fix: whitespace * fix: DRY with `private` specialisation * refactor: use flipped contradiction
1 parent ea2a7ce commit e3e94c8

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/Data/Fin/Properties.agda

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ open import Relation.Binary.PropositionalEquality as ≡
4949
using (≡-≟-identity; ≢-≟-identity)
5050
open import Relation.Nullary.Decidable as Dec
5151
using (Dec; _because_; yes; no; _×-dec_; _⊎-dec_; map′)
52-
open import Relation.Nullary.Negation.Core using (¬_; contradiction)
52+
open import Relation.Nullary.Negation.Core
53+
using (¬_; contradiction; contradiction′)
5354
open import Relation.Nullary.Reflects using (invert)
5455
open import Relation.Unary as U
5556
using (U; Pred; Decidable; _⊆_; Satisfiable; Universal)
@@ -1076,24 +1077,26 @@ pigeonhole : m ℕ.< n → (f : Fin n → Fin m) → ∃₂ λ i j → i < j ×
10761077
pigeonhole z<s f = contradiction (f zero) λ()
10771078
pigeonhole (s<s m<n@(s≤s _)) f with any? (λ k f zero ≟ f (suc k))
10781079
... | yes (j , f₀≡fⱼ) = zero , suc j , z<s , f₀≡fⱼ
1079-
... | no f₀≢fₖ
1080-
with i , j , i<j , fᵢ≡fⱼ pigeonhole m<n (λ j punchOut (f₀≢fₖ ∘ (j ,_ )))
1081-
= suc i , suc j , s<s i<j , punchOut-injective (f₀≢fₖ ∘ (i ,_)) _ fᵢ≡fⱼ
1082-
1083-
injective⇒≤ : {f : Fin m Fin n} Injective _≡_ _≡_ f m ℕ.≤ n
1084-
injective⇒≤ {zero} {_} {f} _ = z≤n
1085-
injective⇒≤ {suc _} {zero} {f} _ = contradiction (f zero) ¬Fin0
1086-
injective⇒≤ {suc _} {suc _} {f} inj = s≤s (injective⇒≤ (λ eq
1087-
suc-injective (inj (punchOut-injective
1088-
(contraInjective inj 0≢1+n)
1089-
(contraInjective inj 0≢1+n) eq))))
1080+
... | no f₀≢fₖ =
1081+
let i , j , i<j , fᵢ≡fⱼ = pigeonhole m<n (λ j punchOut (f₀≢fₖ ∘ (j ,_ )))
1082+
in suc i , suc j , s<s i<j , punchOut-injective (f₀≢fₖ ∘ (i ,_)) _ fᵢ≡fⱼ
10901083

10911084
<⇒notInjective : {f : Fin m Fin n} n ℕ.< m ¬ (Injective _≡_ _≡_ f)
1092-
<⇒notInjective n<m inj = ℕ.≤⇒≯ (injective⇒≤ inj) n<m
1085+
<⇒notInjective {f = f} n<m inj =
1086+
let i , j , i<j , fᵢ≡fⱼ = pigeonhole n<m f in <-irrefl (inj fᵢ≡fⱼ) i<j
1087+
1088+
-- specialised to m = suc n
1089+
1090+
private
1091+
notInjective-Fin[1+n]→Fin[n] : {f : Fin (suc n) Fin n} ¬ (Injective _≡_ _≡_ f)
1092+
notInjective-Fin[1+n]→Fin[n] {n = n} = <⇒notInjective (ℕ.n<1+n n)
1093+
1094+
injective⇒≤ : {f : Fin m Fin n} Injective _≡_ _≡_ f m ℕ.≤ n
1095+
injective⇒≤ = ℕ.≮⇒≥ ∘ flip <⇒notInjective
10931096

10941097
ℕ→Fin-notInjective : (f : Fin n) ¬ (Injective _≡_ _≡_ f)
1095-
ℕ→Fin-notInjective f inj = ℕ.<-irrefl refl
1096-
(injective⇒≤ (Comp.injective _≡_ _≡_ _≡_ toℕ-injective inj))
1098+
ℕ→Fin-notInjective f =
1099+
notInjective-Fin[1+n]→Fin[n] ∘ Comp.injective _≡_ _≡_ _≡_ toℕ-injective
10971100

10981101
-- Cantor-Schröder-Bernstein for finite sets
10991102

@@ -1108,7 +1111,7 @@ injective⇒existsPivot : ∀ {f : Fin n → Fin m} → Injective _≡_ _≡_ f
11081111
injective⇒existsPivot {f = f} f-injective i
11091112
with any? (λ j j ≤? i ×-dec i ≤? f j)
11101113
... | yes result = result
1111-
... | no ¬result = contradiction (injective⇒≤ f∘inject!-injective) ℕ.1+n≰n
1114+
... | no ¬result = contradiction′ notInjective-Fin[1+n]→Fin[n] f∘inject!-injective
11121115
where
11131116
fj<i : (j : Fin′ (suc i)) f (inject! j) < i
11141117
fj<i j with f (inject! j) <? i

0 commit comments

Comments
 (0)