diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c3357348..d56c3d4af4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,11 @@ Deprecated names truncate-irrelevant ↦ Relation.Binary.PropositionalEquality.Core.refl ``` +* In `Function.Base`: + ```agda + λ∙ : (.(x : A) → B x) → ((x : A) → B x) + ``` + * In `Relation.Binary.Construct.Intersection`: ```agda decidable ↦ _∩?_ @@ -163,6 +168,11 @@ New modules * `Algebra.Properties.Semiring`. +* A variation on `Fin` seen as a `Nat` refinement, with better runtime representation and performance. + ``` + Data.Nat.Bounded.Base + ``` + * `Data.List.Fresh.Membership.DecSetoid`. * Various additions over non-empty lists: @@ -278,6 +288,12 @@ Additions to existing modules ``` NB. the latter is based on `IsCommutativeRing`, with the former on `IsSemiring`. + +* In `Data.Bool.Properties`: + ```agda + ¬T-≡ : (¬ T x) ⇔ x ≡ false + ``` + * In `Data.Fin.Permutation.Components`: ```agda transpose[i,i,j]≡j : (i j : Fin n) → transpose i i j ≡ j @@ -392,6 +408,7 @@ Additions to existing modules m⊔n∸[m∸n]≡n : ∀ m n → m ⊔ n ∸ (m ∸ n) ≡ n m⊔n≡m∸n+n : ∀ m n → m ⊔ n ≡ m ∸ n + n ∣m-n∣≡m⊔n∸m⊓n : ∀ m n → ∣ m - n ∣ ≡ m ⊔ n ∸ m ⊓ n + <″⇒< : _<″_ ⇒ _<_ ``` * In `Data.Product.Properties`: diff --git a/src/Data/Bool/Properties.agda b/src/Data/Bool/Properties.agda index 53b4a1f4a7..1ad1b61767 100644 --- a/src/Data/Bool/Properties.agda +++ b/src/Data/Bool/Properties.agda @@ -41,7 +41,7 @@ open import Relation.Binary.PropositionalEquality.Properties using (module ≡-Reasoning; setoid; decSetoid; isEquivalence) open import Relation.Nullary.Decidable.Core using (True; yes; no; fromWitness ; toWitness) -open import Relation.Nullary.Negation.Core using (contradiction) +open import Relation.Nullary.Negation.Core using (¬_; contradiction) import Relation.Unary as U open import Algebra.Definitions {A = Bool} _≡_ @@ -835,6 +835,10 @@ if-cong₂ _ refl refl = refl open Relation.Nullary.Decidable.Core public using (T?) +¬T-≡ : ∀ {x} → (¬ T x) ⇔ x ≡ false +¬T-≡ {false} = mk⇔ (const refl) (const id) +¬T-≡ {true} = mk⇔ (contradiction _) (λ ()) + T-≡ : ∀ {x} → T x ⇔ x ≡ true T-≡ {false} = mk⇔ (λ ()) (λ ()) T-≡ {true} = mk⇔ (const refl) (const _) diff --git a/src/Data/Fin/Base.agda b/src/Data/Fin/Base.agda index cc3c325a64..a837d6c564 100644 --- a/src/Data/Fin/Base.agda +++ b/src/Data/Fin/Base.agda @@ -54,6 +54,17 @@ cast {zero} {zero} eq k = k cast {suc m} {suc n} eq zero = zero cast {suc m} {suc n} eq (suc k) = suc (cast (cong ℕ.pred eq) k) +-- Tests showing that cast does compute on constructors + +module _ .(eqs : suc m ≡ suc n) where + + _ : cast eqs zero ≡ zero + _ = refl + + _ : .(eq : m ≡ n) (k : Fin m) → + cast eqs (suc k) ≡ suc (cast eq k) + _ = λ eq k → refl + ------------------------------------------------------------------------ -- Conversions @@ -77,7 +88,7 @@ fromℕ<″ : ∀ m {n} → .(m ℕ.<″ n) → Fin n fromℕ<″ zero {suc _} _ = zero fromℕ<″ (suc m) {suc _} m<″n = suc (fromℕ<″ m (ℕ.s<″s⁻¹ m<″n)) --- canonical liftings of i:Fin m to larger index +-- Canonical liftings of i:Fin m to larger index -- injection on the left: "i" ↑ˡ n = "i" in Fin (m + n) infixl 5 _↑ˡ_ @@ -91,6 +102,7 @@ _↑ʳ_ : ∀ {m} n → Fin m → Fin (n ℕ.+ m) zero ↑ʳ i = i (suc n) ↑ʳ i = suc (n ↑ʳ i) + -- reduce≥ "m + i" _ = "i". reduce≥ : ∀ (i : Fin (m ℕ.+ n)) → .(m ℕ.≤ toℕ i) → Fin n diff --git a/src/Data/Nat/Bounded/Base.agda b/src/Data/Nat/Bounded/Base.agda new file mode 100644 index 0000000000..b35b02ffbc --- /dev/null +++ b/src/Data/Nat/Bounded/Base.agda @@ -0,0 +1,374 @@ +------------------------------------------------------------------------ +-- The Agda standard library +-- +-- Bounded Natural numbers (Fin, without the runtime overhead) +------------------------------------------------------------------------ + +{-# OPTIONS --cubical-compatible --safe #-} + +module Data.Nat.Bounded.Base where + +open import Data.Bool.Base using (T; true; false; if_then_else_) +import Data.Bool.Properties as Boolₚ +open import Data.Empty using (⊥-elim) +open import Data.Irrelevant as Irrelevant using (Irrelevant; [_]; pure; _<*>_) +open import Data.Nat.Base as ℕ using (ℕ; zero; suc; z≤n; zi then j-1 else j +punchOut : ∀ {i j : Fin (suc n)} → i ≢ j → Fin n +punchOut {n = n} {i = i , i<1+n} {j = j , j<1+n} i≢j + = value , (| prf i<1+n (| ℕ.s≤s⁻¹ j<1+n |) |) + where + value = if i ℕ.<ᵇ j then ℕ.pred j else j + + prf : i ℕ.< suc n → j ℕ.≤ n → value ℕ.< n + prf i<1+n j≤n with T? (i ℕ.<ᵇ j) + ... | yes i_ _≰_ _≮_ + +_≤_ : IRel Fin 0ℓ +i ≤ j = toℕ i ℕ.≤ toℕ j + +_≥_ : IRel Fin 0ℓ +i ≥ j = toℕ i ℕ.≥ toℕ j + +_<_ : IRel Fin 0ℓ +i < j = toℕ i ℕ.< toℕ j + +_>_ : IRel Fin 0ℓ +i > j = toℕ i ℕ.> toℕ j + +_≰_ : ∀ {n} → Rel (Fin n) 0ℓ +i ≰ j = ¬ (i ≤ j) + +_≮_ : ∀ {n} → Rel (Fin n) 0ℓ +i ≮ j = ¬ (i < j) diff --git a/src/Data/Nat/Properties.agda b/src/Data/Nat/Properties.agda index 0fe5b9dba9..6f8b85e38f 100644 --- a/src/Data/Nat/Properties.agda +++ b/src/Data/Nat/Properties.agda @@ -2187,6 +2187,9 @@ n≤′m+n (suc m) n = ≤′-step (n≤′m+n m n) ≤″⇒≤ : _≤″_ ⇒ _≤_ ≤″⇒≤ (k , refl) = m≤m+n _ k +<″⇒< : _<″_ ⇒ _<_ +<″⇒< = ≤″⇒≤ + -- equivalence to the old definition of _≤″_ ≤″-proof : (le : m ≤″ n) → let k , _ = le in m + k ≡ n diff --git a/src/Function/Base.agda b/src/Function/Base.agda index 1f8f3f0b18..9affb90225 100644 --- a/src/Function/Base.agda +++ b/src/Function/Base.agda @@ -107,6 +107,10 @@ f $- = f _ λ- f = λ x → f {-# INLINE λ- #-} +λ∙ : ∀ {A : Set a} {B : .A → Set b} → (.(x : A) → B x) → ((x : A) → B x) +λ∙ f = λ x → f x +{-# INLINE λ∙ #-} + -- Case expressions (to be used with pattern-matching lambdas, see -- README.Case). @@ -267,4 +271,3 @@ case_return_of_ = case_returning_of_ "case_return_of_ was deprecated in v2.0. Please use case_returning_of_ instead." #-} -