diff --git a/Cubical/Data/Nat/Count.agda b/Cubical/Data/Nat/Count.agda new file mode 100644 index 0000000000..45644c9a39 --- /dev/null +++ b/Cubical/Data/Nat/Count.agda @@ -0,0 +1,255 @@ +{-# OPTIONS --safe #-} + +module Cubical.Data.Nat.Count where + +open import Cubical.Foundations.Prelude +open import Cubical.Foundations.Function +open import Cubical.Data.Nat +open import Cubical.Data.Nat.Order +open import Cubical.Data.Sigma +open import Cubical.Data.Sum hiding (elim ; rec ; map) +open import Cubical.Data.List hiding (elim ; rec ; map) + +open import Cubical.Relation.Nullary +open import Cubical.Data.Empty as ⊥ hiding (elim) + + +private + variable + ℓ ℓ' ℓ'' : Level + + -- some definitions and lemmas + + decToN : {A : Type ℓ} → Dec A → ℕ + decToN (yes _) = 1 + decToN (no _) = 0 + + data All {A : Type ℓ} (P : A → Type ℓ') : List A → Type (ℓ-max ℓ ℓ') where + [] : All P [] + _∷_ : ∀ {x xs} → P x → All P xs → All P (x ∷ xs) + + mapAll : {A : Type ℓ} {P Q : A → Type ℓ'} {xs : List A} → (∀ {a} → P a → Q a) → All P xs → All Q xs + mapAll f [] = [] + mapAll f (Px ∷ Pxs) = f Px ∷ mapAll f Pxs + + add-equations : ∀ {a} {b} {c} {d} → a ≡ b → c ≡ d → a + c ≡ b + d + add-equations {b = b} {c = c} a=b c=d = cong (_+ c) a=b ∙ cong (b +_) c=d + + <≠ : forall {m} {n} → m < n → ¬ m ≡ n + <≠ {m = m} m suc (suc (b + a · suc (suc b))) ≡ suc n + ⇒⟨ injSuc ⟩ suc (b + a · suc (suc b)) ≡ n + ⇒⟨ 0 ,_ ⟩ b + a · suc (suc b) < n + ⇒⟨ +a q · n ≡ a + b + ⇒⟨ subst (λ x → q · n ≡ a + x) (sym pn=b) ⟩ q · n ≡ a + p · n + ⇒⟨ (λ x → cong (_∸ (p · n)) x ∙ +∸ a (p · n)) ⟩ q · n ∸ p · n ≡ a + ⇒⟨ (∸-distribʳ q p n) ∙_ ⟩ (q ∸ p) · n ≡ a ) + ∣₁ + + +ab=1→1 : ∀ a b → a · b ≡ 1 → b ≡ 1 +ab=1→1 0 0 ab=1 = ab=1 +ab=1→1 0 (suc b) ab=1 = ⊥.rec (znots ab=1) +ab=1→1 (suc a) 0 ab=1 = ·-comm 0 a ∙ ab=1 +ab=1→1 (suc a) 1 _ = refl +ab=1→1 (suc a) (suc (suc b)) ab=1 = ⊥.rec (snotz (injSuc ab=1)) + +div1→1 : ∀ n → n ∣ 1 → n ≡ 1 +div1→1 n ∣n∣1∣ = ab=1→1 k n kn=1 where + n∣1 : Σ[ k ∈ ℕ ] k · n ≡ 1 + n∣1 = ∣-untrunc ∣n∣1∣ + k = n∣1 .fst + kn=1 = n∣1 .snd + +-- decidability lemmas + +Dec-1