Debian Codegraph @

src/Function/Nary/NonDependent.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Heterogeneous N-ary Functions
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Function.Nary.NonDependent where
10
11 ------------------------------------------------------------------------
12 -- Concrete examples can be found in README.Nary. This file's comments
13 -- are more focused on the implementation details and the motivations
14 -- behind the design decisions.
15 ------------------------------------------------------------------------
16
17 open import Level using (Level; 0ℓ; _⊔_; Lift)
18 open import Data.Nat.Base using (ℕ; zero; suc)
19 open import Data.Fin.Base using (Fin; zero; suc)
20 open import Data.Product.Base using (_×_; _,_)
21 open import Data.Product.Nary.NonDependent
22 using (Product; uncurryₙ; Equalₙ; curryₙ; fromEqualₙ; toEqualₙ)
23 open import Function.Base using (_∘′_; _$′_; const; flip)
24 open import Relation.Unary using (IUniversal)
25 open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; subst; cong)
26
27 private
28 variable
29 a b r : Level
30 A : Set a
31 B : Set b
32
33 ------------------------------------------------------------------------
34 -- Re-exporting the basic operations
35
36 open import Function.Nary.NonDependent.Base public
37
38 ------------------------------------------------------------------------
39 -- Congruence
40
41 module _ n {ls} {as : Sets n ls} {R : Set r} (f : as ⇉ R) where
42
43 private
44 g : Product n as → R
45 g = uncurryₙ n f
46
47 -- Congruentₙ : ∀ n. ∀ a₁₁ a₁₂ ⋯ aₙ₁ aₙ₂ →
48 -- a₁₁ ≡ a₁₂ → ⋯ → aₙ₁ ≡ aₙ₂ →
49 -- f a₁₁ ⋯ aₙ₁ ≡ f a₁₂ ⋯ aₙ₂
50
51 Congruentₙ : Set (r Level.⊔ ⨆ n ls)
52 Congruentₙ = ∀ {l r} → Equalₙ n l r ⇉ (g l ≡ g r)
53
54 congₙ : Congruentₙ
55 congₙ = curryₙ n (cong g ∘′ fromEqualₙ n)
56
57 -- Congruence at a specific location
58
59 module _ m n {ls ls′} {as : Sets m ls} {bs : Sets n ls′}
60 (f : as ⇉ (A → bs ⇉ B)) where
61
62 private
63 g : Product m as → A → Product n bs → B
64 g vs a ws = uncurryₙ n (uncurryₙ m f vs a) ws
65
66 congAt : ∀ {vs ws a₁ a₂} → a₁ ≡ a₂ → g vs a₁ ws ≡ g vs a₂ ws
67 congAt {vs} {ws} = cong (λ a → g vs a ws)
68
69 ------------------------------------------------------------------------
70 -- Injectivity
71
72 module _ n {ls} {as : Sets n ls} {R : Set r} (con : as ⇉ R) where
73
74 -- Injectiveₙ : ∀ n. ∀ a₁₁ a₁₂ ⋯ aₙ₁ aₙ₂ →
75 -- con a₁₁ ⋯ aₙ₁ ≡ con a₁₂ ⋯ aₙ₂ →
76 -- a₁₁ ≡ a₁₂ × ⋯ × aₙ₁ ≡ aₙ₂
77
78 private
79 c : Product n as → R
80 c = uncurryₙ n con
81
82 Injectiveₙ : Set (r Level.⊔ ⨆ n ls)
83 Injectiveₙ = ∀ {l r} → c l ≡ c r → Product n (Equalₙ n l r)
84
85 injectiveₙ : (∀ {l r} → c l ≡ c r → l ≡ r) → Injectiveₙ
86 injectiveₙ con-inj eq = toEqualₙ n (con-inj eq)