mirror of
https://github.com/Smaug123/agdaproofs
synced 2025-10-10 22:28:40 +00:00
Cantor pairing function is bijective (#42)
This commit is contained in:
@@ -7,6 +7,9 @@ open import Functions
|
||||
open import Numbers.Naturals.Naturals
|
||||
open import Sets.FinSet
|
||||
open import Semirings.Definition
|
||||
open import Orders
|
||||
open import WellFoundedInduction
|
||||
open import Sets.CantorBijection.CantorBijection
|
||||
|
||||
module Sets.Cardinality where
|
||||
record CountablyInfiniteSet {a : _} (A : Set a) : Set a where
|
||||
@@ -61,121 +64,6 @@ module Sets.Cardinality where
|
||||
q : succ ((a +N a *N succ a) +N 0) ≡ succ n
|
||||
q rewrite Semiring.commutative ℕSemiring (a +N a *N succ a) 0 = applyEquality succ p
|
||||
|
||||
{-
|
||||
triangle : (a : ℕ) → ℕ
|
||||
triangle zero = 0
|
||||
triangle (succ a) = succ a +N triangle a
|
||||
|
||||
cantorPairing' : (a : ℕ) → (b : ℕ) → (s : ℕ) → (s ≡ a +N b) → ℕ
|
||||
cantorPairing' a b zero pr = 0
|
||||
cantorPairing' zero zero (succ s) ()
|
||||
cantorPairing' zero (succ b) (succ s) pr = succ (cantorPairing' 1 b (succ s) pr)
|
||||
cantorPairing' (succ a) zero (succ s) pr = succ (cantorPairing' 0 a s (succInjective (identityOfIndiscernablesRight _ _ _ _≡_ pr (applyEquality (λ i → succ i) (identityOfIndiscernablesLeft _ _ _ _≡_ (Semiring.commutative ℕSemiring a 0) refl)))))
|
||||
cantorPairing' (succ a) (succ b) (succ zero) pr = naughtE f
|
||||
where
|
||||
f : 0 ≡ succ b +N a
|
||||
f rewrite Semiring.commutative ℕSemiring (succ b) a = succInjective pr
|
||||
cantorPairing' (succ a) (succ b) (succ (succ s)) pr = succ (cantorPairing' (succ (succ a)) b (succ (succ s)) (identityOfIndiscernablesRight _ _ _ _≡_ pr (applyEquality succ (succExtracts a b))))
|
||||
|
||||
cantorPairing'Zero : (x y s : ℕ) → (pr : s ≡ x +N y) → cantorPairing' x y s pr ≡ 0 → (x ≡ 0) && (y ≡ 0)
|
||||
cantorPairing'Zero x y zero pr pr' = sumZeroImpliesSummandsZero (equalityCommutative pr)
|
||||
cantorPairing'Zero zero zero (succ s) () pr'
|
||||
cantorPairing'Zero zero (succ y) (succ s) pr ()
|
||||
cantorPairing'Zero (succ x) zero (succ s) pr ()
|
||||
cantorPairing'Zero (succ x) (succ y) (succ zero) pr pr' = naughtE (identityOfIndiscernablesRight _ _ _ _≡_ (succInjective pr) (Semiring.commutative ℕSemiring x (succ y)))
|
||||
cantorPairing'Zero (succ x) (succ y) (succ (succ s)) pr ()
|
||||
|
||||
cantorPairingInj' : (s1 s2 : ℕ) → (x1 x2 y1 y2 : ℕ) → (pr1 : s1 ≡ x1 +N y1) → (pr2 : s2 ≡ x2 +N y2) → (cantorPairing' x1 y1 s1 pr1) ≡ (cantorPairing' x2 y2 s2 pr2) → (x1 ≡ x2) && (y1 ≡ y2)
|
||||
cantorPairingInj' zero zero x1 x2 y1 y2 pr1 pr2 injF = transitivity (_&&_.fst x1y1) (equalityCommutative (_&&_.fst x2y2)) ,, transitivity (_&&_.snd x1y1) (equalityCommutative (_&&_.snd x2y2))
|
||||
where
|
||||
x2y2 : (x2 ≡ 0) && (y2 ≡ 0)
|
||||
x2y2 = sumZeroImpliesSummandsZero (equalityCommutative pr2)
|
||||
x1y1 : (x1 ≡ 0) && (y1 ≡ 0)
|
||||
x1y1 = sumZeroImpliesSummandsZero (equalityCommutative pr1)
|
||||
cantorPairingInj' zero (succ s2) x1 x2 y1 y2 pr1 pr2 injF = naughtE (equalityCommutative bad2)
|
||||
where
|
||||
x2y2 : (x2 ≡ 0) && (y2 ≡ 0)
|
||||
x2y2 = cantorPairing'Zero x2 y2 (succ s2) pr2 (equalityCommutative injF)
|
||||
bad : succ s2 ≡ y2
|
||||
bad = identityOfIndiscernablesRight _ _ _ _≡_ pr2 ((applyEquality (λ i → i +N y2) (_&&_.fst x2y2)))
|
||||
bad2 : succ s2 ≡ 0
|
||||
bad2 = transitivity bad (_&&_.snd x2y2)
|
||||
cantorPairingInj' (succ s1) zero x1 x2 y1 y2 pr1 pr2 injF = naughtE (equalityCommutative bad2)
|
||||
where
|
||||
x1y1 : (x1 ≡ 0) && (y1 ≡ 0)
|
||||
x1y1 = cantorPairing'Zero x1 y1 (succ s1) pr1 injF
|
||||
bad : succ s1 ≡ y1
|
||||
bad = identityOfIndiscernablesRight _ _ _ _≡_ pr1 ((applyEquality (λ i → i +N y1) (_&&_.fst x1y1)))
|
||||
bad2 : succ s1 ≡ 0
|
||||
bad2 = transitivity bad (_&&_.snd x1y1)
|
||||
cantorPairingInj' (succ s1) (succ s2) zero x2 zero y2 () pr2 injF
|
||||
cantorPairingInj' (succ s1) (succ s2) zero zero (succ .s1) zero refl () injF
|
||||
cantorPairingInj' (succ zero) (succ zero) zero zero (succ .0) (succ .0) refl refl injF = refl ,, refl
|
||||
cantorPairingInj' (succ zero) (succ (succ s2)) zero zero (succ .0) (succ .(succ s2)) refl refl injF = naughtE (equalityCommutative bad)
|
||||
where
|
||||
bad : 2 ≡ 0
|
||||
bad = _&&_.fst (cantorPairing'Zero 2 s2 (succ (succ s2)) refl (equalityCommutative (succInjective (succInjective injF))))
|
||||
cantorPairingInj' (succ (succ s1)) (succ zero) zero zero (succ .(succ s1)) (succ .0) refl refl injF = naughtE (equalityCommutative bad)
|
||||
where
|
||||
bad : 2 ≡ 0
|
||||
bad = _&&_.fst (cantorPairing'Zero 2 s1 (succ (succ s1)) refl (succInjective (succInjective injF)))
|
||||
cantorPairingInj' (succ (succ s1)) (succ (succ s2)) zero zero (succ .(succ s1)) (succ .(succ s2)) refl refl injF = refl ,, (applyEquality (λ i → succ (succ i)) rec')
|
||||
where
|
||||
rec : cantorPairing' 2 s1 (succ (succ s1)) refl ≡ cantorPairing' 2 s2 (succ (succ s2)) refl
|
||||
rec = succInjective (succInjective injF)
|
||||
rec' : (s1 ≡ s2)
|
||||
rec' = _&&_.snd (cantorPairingInj' (succ (succ s1)) (succ (succ s2)) 2 2 s1 s2 refl refl rec)
|
||||
cantorPairingInj' (succ s1) (succ s2) zero (succ x2) (succ .s1) zero refl pr2 injF = naughtE (equalityCommutative rec')
|
||||
where
|
||||
rec : cantorPairing' 1 s1 (succ s1) refl ≡ cantorPairing' 0 x2 s2 _
|
||||
rec = succInjective injF
|
||||
rec' : (1 ≡ zero)
|
||||
rec' = _&&_.fst (cantorPairingInj' (succ s1) s2 1 zero s1 x2 refl _ rec)
|
||||
cantorPairingInj' (succ s1) (succ zero) zero (succ x2) (succ .s1) (succ y2) refl pr2 injF = naughtE (identityOfIndiscernablesRight _ _ _ _≡_ (succInjective pr2) (Semiring.commutative ℕSemiring x2 (succ y2)))
|
||||
cantorPairingInj' (succ s1) (succ (succ s2)) zero (succ x2) (succ .s1) (succ y2) refl pr2 injF = naughtE (succInjective rec')
|
||||
where
|
||||
rec : cantorPairing' 1 s1 (succ s1) refl ≡ cantorPairing' (succ (succ x2)) y2 (succ (succ s2)) _
|
||||
rec = succInjective injF
|
||||
rec' : (1 ≡ succ (succ x2))
|
||||
rec' = _&&_.fst (cantorPairingInj' (succ s1) (succ (succ s2)) 1 (succ (succ x2)) s1 y2 refl _ rec)
|
||||
cantorPairingInj' (succ s1) (succ s2) (succ x1) zero y1 zero pr1 () injF
|
||||
cantorPairingInj' (succ s1) (succ s2) (succ zero) zero .s1 (succ .s2) refl refl injF = {!!}
|
||||
cantorPairingInj' (succ s1) (succ s2) (succ (succ x1)) zero zero (succ .s2) pr1 refl injF = {!!}
|
||||
where
|
||||
false : {!!}
|
||||
false = {!!}
|
||||
cantorPairingInj' (succ s1) (succ s2) (succ (succ x1)) zero (succ y1) (succ .s2) pr1 refl injF = {!!}
|
||||
cantorPairingInj' (succ s1) (succ s2) (succ x1) (succ x2) y1 y2 pr1 pr2 injF = {!!}
|
||||
|
||||
cantorPairingInj : Injection cantorPairing
|
||||
Injection.property cantorPairingInj {zero ,, zero} {zero ,, zero} pr = refl
|
||||
Injection.property cantorPairingInj {zero ,, zero} {zero ,, succ snd} pr = exFalso {!!}
|
||||
Injection.property cantorPairingInj {zero ,, zero} {succ fst ,, snd} pr = {!!}
|
||||
Injection.property cantorPairingInj {zero ,, succ snd} {y} pr = {!!}
|
||||
Injection.property cantorPairingInj {succ fst ,, snd} {y} pr = {!!}
|
||||
|
||||
cantorInverse : ℕ → (ℕ && ℕ)
|
||||
cantorInverse zero = (0 ,, 0)
|
||||
cantorInverse (succ z) = f (cantorInverse z)
|
||||
where
|
||||
f : (ℕ && ℕ) → (ℕ && ℕ)
|
||||
f (0 ,, s) = (succ s) ,, 0
|
||||
f (succ r ,, 0) = r ,, 1
|
||||
f (succ r ,, succ s) = (r ,, succ (succ s))
|
||||
|
||||
cantorInvertible : Invertible cantorPairing
|
||||
Invertible.inverse cantorInvertible = cantorInverse
|
||||
Invertible.isLeft cantorInvertible zero = refl
|
||||
Invertible.isLeft cantorInvertible (succ b) with inspect (cantorInverse b)
|
||||
Invertible.isLeft cantorInvertible (succ b) | (zero ,, zero) with≡ x = {!!}
|
||||
Invertible.isLeft cantorInvertible (succ b) | (zero ,, succ snd) with≡ x = {!!}
|
||||
Invertible.isLeft cantorInvertible (succ b) | (succ fst ,, snd) with≡ x = {!!}
|
||||
Invertible.isRight cantorInvertible (a ,, b) = {!!}
|
||||
|
||||
cantorBijection : Bijection cantorPairing
|
||||
cantorBijection = invertibleImpliesBijection cantorInvertible
|
||||
-}
|
||||
|
||||
pairUnionIsCountable : {a b : _} {A : Set a} {B : Set b} → (X : CountablyInfiniteSet A) → (Y : CountablyInfiniteSet B) → CountablyInfiniteSet (A || B)
|
||||
CountablyInfiniteSet.counting (pairUnionIsCountable X Y) (inl r) = 2 *N (CountablyInfiniteSet.counting X r)
|
||||
CountablyInfiniteSet.counting (pairUnionIsCountable X Y) (inr s) = succ (2 *N (CountablyInfiniteSet.counting Y s))
|
||||
|
Reference in New Issue
Block a user