diff --git a/CHANGELOG.md b/CHANGELOG.md index 4448791d5a..43031ac590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1139,6 +1139,31 @@ Deprecated names map-++-commute ↦ map-++ ``` +* In `Data.Vec.Relation.Unary.All`: + for `{{NonZero n}}`, as per issue #1686 + + ```agda + head′ : All P xs → P (Vec.head′ {n = n} xs) + tail′ : All P xs → All P (Vec.tail′ {n = n} xs) + uncons′ : All P xs → P (Vec.head′ {n = n} xs) × All P (Vec.tail′ {n = n} xs) + ``` + +* In `Data.Vec.Relation.Unary.Any`: + for `{{NonZero n}}`, as per issue #1686 + + ```agda + head′ : ¬ Any P (Vec.tail′ {n = n} xs) → Any P xs → P (Vec.head′ {n = n} xs) + tail′ : ¬ P (Vec.head′ {n = n} xs) → Any P xs → Any P (Vec.tail′ {n = n} xs) + ``` + +* In `Data.Vec.Relation.Unary.Linked.Properties`: + for `{{NonZero n}}`, as per issue #1686 + + ```agda + Linked⇒All′ : ∀ {v} {xs : Vec _ n} → R v (head′ xs) → + Linked R xs → All (R v) xs + ``` + * In `Function.Construct.Composition`: ``` _∘-⟶_ ↦ _⟶-∘_ @@ -1557,6 +1582,8 @@ Other minor changes leftSemimedial : LeftSemimedial _∙_ rightSemimedial : RightSemimedial _∙_ middleSemimedial : ∀ x y z → (x ∙ y) ∙ (z ∙ x) ≈ (x ∙ z) ∙ (y ∙ x) + + sum-remove′ : ∀ {n} {{_ : NonZero n}} {i : Fin n} t → sum t ≈ t i + sum (remove′ i t) ``` * Added new proofs to `Algebra.Properties.Semigroup`: @@ -1627,6 +1654,21 @@ Other minor changes quotient : Fin (m * n) → Fin m remainder : Fin (m * n) → Fin n ``` + + Additionally, as per issue #1686, primed functionality in cases + where the `Fin` index `n` is `NonZero`: + ``` + zero′ : Fin n + suc' : Fin (ℕ.pred n) → Fin n + inject!′ : {i : Fin n} → Fin′ i → Fin (ℕ.pred n) + inject₁′ : Fin (ℕ.pred n) → Fin n + lower₁′ : (i : Fin n) → n ≢ suc (toℕ i) → Fin (ℕ.pred n) + _ℕ-′_ : (j : Fin n) → Fin (n ℕ.∸ toℕ j) + _ℕ-ℕ′_ : Fin n → ℕ + punchOut′ : {i j : Fin n} → i ≢ j → Fin (ℕ.pred n) + punchIn′ : Fin n → Fin (ℕ.pred n) → Fin n + pinch′ : Fin (ℕ.pred n) → Fin n → Fin (ℕ.pred n) + ``` * Added new proofs in `Data.Fin.Induction`: every (strict) partial order is well-founded and Noetherian. @@ -1691,6 +1733,29 @@ Other minor changes cast-trans : cast eq₂ (cast eq₁ k) ≡ cast (trans eq₁ eq₂) k ``` + Additionally properties of the primed functionality as in `Data.Fin.Base`: + ``` + inject₁-lower₁′ : (n≢i+1 : n ≢ suc (toℕ i)) → + inject₁′ (lower₁′ i n≢i+1) ≡ i + lower₁-irrelevant′ : (n≢i₁+1 n≢i₂+1 : n ≢ suc (toℕ i)) → + lower₁′ i n≢i₁+1 ≡ lower₁′ i n≢i₂+1 + inject₁≡⇒lower₁≡′ : (n≢j+1 : n ≢ suc (toℕ j)) → inject₁′ i ≡ j → lower₁′ j n≢j+1 ≡ i + pred<′ : (i : Fin n) → i ≢ zero′ → pred i < i + punchOut-cong′ : {i≢j : i ≢ j} {i≢k : i ≢ k} → + j ≡ k → punchOut′ i≢j ≡ punchOut′ i≢k + punchOut-injective′ : (i≢j : i ≢ j) (i≢k : i ≢ k) → + punchOut′ i≢j ≡ punchOut′ i≢k → j ≡ k + punchIn-punchOut′ : {i j : Fin n} (i≢j : i ≢ j) → + punchIn′ i (punchOut′ i≢j) ≡ j + + pinch-injective′ : {i : Fin (ℕ.pred n)} {j k : Fin n} → + suc′ i ≢ j → suc′ i ≢ k → pinch′ i j ≡ pinch′ i k → j ≡ k + ``` + + NB Adding `punchOut-cong′` for the sake of uniformity with the 'primed' naming scheme + for `NonZero` instances, entailed renaming the old `punchOut-cong′` to `punchOut-cong-eq`, + with knock-on effect in two places in `Data.Fin.Permutation` + * Added new functions in `Data.Integer.Base`: ``` _^_ : ℤ → ℕ → ℤ @@ -2044,12 +2109,33 @@ Other minor changes cast : .(eq : m ≡ n) → Vec A m → Vec A n ``` + And for `{{NonZero n}}` as per issue 1686 + ``` + head′ : Vec A n → A + tail′ : Vec A n → A ^ (pred n) + uncons′ : Vec A n → A × Vec A (pred n) + insert′ : Vec A (pred n) → Fin n → A → Vec A n + remove′ : Vec A n → Fin n → Vec A (pred n) + init′ : (xs : Vec A n) → Vec A (pred n) + last′ : (xs : Vec A n) → A + ``` * Added new instance in `Data.Vec.Categorical`: ```agda monad : RawMonad (λ (A : Set a) → Vec A n) ``` +* Added new functions in `Data.Vec.Functional` for `{{NonZero n}}`: + ``` + head′ : Vector A n → A + tail′ : Vector A n → A ^ (pred n) + uncons′ : Vector A n → A × Vector A (pred n) + insert′ : Vector A (pred n) → Fin n → A → Vector A n + remove′ : Vector A n → Fin n → Vector A (pred n) + init′ : (xs : Vector A n) → Vector A (pred n) + last′ : (xs : Vector A n) → A + ``` + * Added new proofs in `Data.Vec.Properties`: ```agda padRight-refl : padRight ≤-refl a xs ≡ xs @@ -2111,6 +2197,20 @@ Other minor changes lookup-cast₁ : lookup (cast eq xs) i ≡ lookup xs (Fin.cast (sym eq) i) lookup-cast₂ : lookup xs (Fin.cast eq i) ≡ lookup (cast (sym eq) xs) i ``` + And for `{{NonZero n}}`: + ``` + insert-lookup′ : (xs : Vec A (pred n)) (i : Fin n) (v : A) → + lookup (insert′ xs i v) i ≡ v + insert-punchIn′ : (xs : Vec A (pred n)) (i : Fin n) (v : A) (j : Fin (pred n)) → + lookup (insert′ xs i v) (Fin.punchIn′ i j) ≡ lookup xs j + + ``` +* Added new functions in `Data.Vec.Recursive` for `{{NonZero n}}`: + ``` + uncons′ : A ^ n → A × A ^ (pred n) + head′ : A ^ n → A + tail′ : A ^ n → A ^ (pred n) + ``` * Added new proofs in `Data.Vec.Functional.Properties`: ``` diff --git a/src/Algebra/Properties/CommutativeMonoid/Sum.agda b/src/Algebra/Properties/CommutativeMonoid/Sum.agda index 54731cfb5b..c4bf6e45c0 100644 --- a/src/Algebra/Properties/CommutativeMonoid/Sum.agda +++ b/src/Algebra/Properties/CommutativeMonoid/Sum.agda @@ -59,6 +59,9 @@ sum-remove {suc n} {suc i} xs = begin ∑t = sum t ∑t′ = sum (remove i t) +sum-remove′ : ∀ {n} {{_ : NonZero n}} {i : Fin n} t → sum t ≈ t i + sum (remove′ i t) +sum-remove′ {n = suc n} = sum-remove + -- The '∑' operator distributes over addition. ∑-distrib-+ : ∀ {n} (f g : Vector Carrier n) → ∑[ i < n ] (f i + g i) ≈ ∑[ i < n ] f i + ∑[ i < n ] g i ∑-distrib-+ {zero} f g = sym (+-identityˡ _) diff --git a/src/Data/Fin/Base.agda b/src/Data/Fin/Base.agda index 06c4581337..d5918912e6 100644 --- a/src/Data/Fin/Base.agda +++ b/src/Data/Fin/Base.agda @@ -7,13 +7,14 @@ -- Note that elements of Fin n can be seen as natural numbers in the -- set {m | m < n}. The notation "m" in comments below refers to this -- natural number view. + {-# OPTIONS --without-K --safe #-} module Data.Fin.Base where open import Data.Bool.Base using (Bool; true; false; T; not) open import Data.Empty using (⊥-elim) -open import Data.Nat.Base as ℕ using (ℕ; zero; suc; z≤n; s≤s; z +uncons′ : .{{_ : NonZero n}} → + All P xs → P (Vec.head′ {n = n} xs) × All P (Vec.tail′ {n = n} xs) +uncons′ = < head′ , tail′ > + map : P ⊆ Q → All P ⊆ All Q {n} map g [] = [] map g (px ∷ pxs) = g px ∷ map g pxs diff --git a/src/Data/Vec/Relation/Unary/Any.agda b/src/Data/Vec/Relation/Unary/Any.agda index a54991976f..831df9f08d 100644 --- a/src/Data/Vec/Relation/Unary/Any.agda +++ b/src/Data/Vec/Relation/Unary/Any.agda @@ -44,11 +44,19 @@ head : ∀ {x} → ¬ Any P xs → Any P (x ∷ xs) → P x head ¬pxs (here px) = px head ¬pxs (there pxs) = contradiction pxs ¬pxs +head′ : .{{_ : NonZero n}} → + ¬ Any P (Vec.tail′ {n = n} xs) → Any P xs → P (Vec.head′ {n = n} xs) +head′ {n = suc _} {xs = _ ∷ _} ¬pxs = head ¬pxs + -- If the head does not satisfy the predicate, then the tail will. tail : ∀ {x} → ¬ P x → Any P (x ∷ xs) → Any P xs tail ¬px (here px) = ⊥-elim (¬px px) tail ¬px (there pxs) = pxs +tail′ : .{{_ : NonZero n}} → + ¬ P (Vec.head′ {n = n} xs) → Any P xs → Any P (Vec.tail′ {n = n} xs) +tail′ {n = suc _} {xs = _ ∷ _} ¬px = tail ¬px + -- Convert back and forth with sum toSum : ∀ {x} → Any P (x ∷ xs) → P x ⊎ Any P xs toSum (here px) = inj₁ px diff --git a/src/Data/Vec/Relation/Unary/Linked/Properties.agda b/src/Data/Vec/Relation/Unary/Linked/Properties.agda index 3935a263c4..3ebe0eb19f 100644 --- a/src/Data/Vec/Relation/Unary/Linked/Properties.agda +++ b/src/Data/Vec/Relation/Unary/Linked/Properties.agda @@ -43,6 +43,11 @@ module _ (trans : Transitive R) where Linked⇒All Rvx [-] = Rvx ∷ [] Linked⇒All Rvx (Rxy ∷ Rxs) = Rvx ∷ Linked⇒All (trans Rvx Rxy) Rxs + Linked⇒All′ : .{{_ : NonZero n}} → + ∀ {v} {xs : Vec _ n} → R v (head′ xs) → + Linked R xs → All (R v) xs + Linked⇒All′ {n = suc n} = Linked⇒All {n = n} + lookup⁺ : ∀ {i j} {xs : Vec _ n} → Linked R xs → i < j → R (lookup xs i) (lookup xs j)