hexsha
stringlengths
40
40
size
int64
3
1.05M
ext
stringclasses
163 values
lang
stringclasses
53 values
max_stars_repo_path
stringlengths
3
945
max_stars_repo_name
stringlengths
4
112
max_stars_repo_head_hexsha
stringlengths
40
78
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
3
945
max_issues_repo_name
stringlengths
4
113
max_issues_repo_head_hexsha
stringlengths
40
78
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
116k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
945
max_forks_repo_name
stringlengths
4
113
max_forks_repo_head_hexsha
stringlengths
40
78
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
3
1.05M
avg_line_length
float64
1
966k
max_line_length
int64
1
977k
alphanum_fraction
float64
0
1
1c63aa1489bf037972fb4ad77ef350639fce94f1
14,931
agda
Agda
extra/extra/Value.agda
krzygorz/plfa.github.io
10a3203624f2ea937b3892176db5de825d0c46b4
[ "CC-BY-4.0" ]
1,003
2018-07-05T18:15:14.000Z
2022-03-27T07:03:28.000Z
extra/extra/Value.agda
krzygorz/plfa.github.io
10a3203624f2ea937b3892176db5de825d0c46b4
[ "CC-BY-4.0" ]
323
2018-07-05T22:34:34.000Z
2022-03-30T07:42:57.000Z
extra/extra/Value.agda
krzygorz/plfa.github.io
10a3203624f2ea937b3892176db5de825d0c46b4
[ "CC-BY-4.0" ]
304
2018-07-16T18:24:59.000Z
2022-03-28T11:35:02.000Z
open import Data.Nat using (ℕ; suc ; zero; _+_; _≤′_; _<′_; _<_; _≤_; z≤n; s≤s; ≤′-refl; ≤′-step; _≟_) renaming (_⊔_ to max) open import Data.Nat.Properties using (n≤0⇒n≡0; ≤-refl; ≤-trans; m≤m⊔n; n≤m⊔n; ≤-step; ⊔-mono-≤; +-mono-≤; +-mono-≤-<; +-mono-<-≤; +-comm; +-assoc; n≤1+n; ≤-pred; m≤m+n; n≤m+n; ≤-reflexive; ≤′⇒≤; ≤⇒≤′; +-suc) open Data.Nat.Properties.≤-Reasoning using (begin_; _≤⟨_⟩_; _∎) open import Data.Bool using (Bool) renaming (_≟_ to _=?_) open import Data.Product using (_×_; Σ; Σ-syntax; ∃; ∃-syntax; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Empty using (⊥-elim) renaming (⊥ to Bot) open import Data.Unit using (⊤; tt) open import Data.Maybe open import Data.List using (List ; _∷_ ; []; _++_) open import Relation.Nullary using (¬_) open import Relation.Nullary using (Dec; yes; no) open import Relation.Nullary.Negation using (contradiction) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong) open Relation.Binary.PropositionalEquality.≡-Reasoning renaming (begin_ to start_; _∎ to _□) module extra.Value where data Base : Set where Nat : Base 𝔹 : Base data Prim : Set where base : Base → Prim _⇒_ : Base → Prim → Prim base-rep : Base → Set base-rep Nat = ℕ base-rep 𝔹 = Bool rep : Prim → Set rep (base b) = base-rep b rep (b ⇒ p) = base-rep b → rep p base-eq? : (B : Base) → (B' : Base) → Dec (B ≡ B') base-eq? Nat Nat = yes refl base-eq? Nat 𝔹 = no (λ ()) base-eq? 𝔹 Nat = no (λ ()) base-eq? 𝔹 𝔹 = yes refl base-rep-eq? : ∀{B} → (k : base-rep B) (k′ : base-rep B) → Dec (k ≡ k′) base-rep-eq? {Nat} k k′ = k ≟ k′ base-rep-eq? {𝔹} k k′ = k =? k′ infixr 7 _↦_ infixl 6 _⊔_ data Value : Set data Value where ⊥ : Value const : {b : Base} → base-rep b → Value _↦_ : Value → Value → Value _⊔_ : (u : Value) → (v : Value) → Value infix 5 _∈_ _∈_ : Value → Value → Set u ∈ ⊥ = u ≡ ⊥ u ∈ const {B} k = u ≡ const {B} k u ∈ v ↦ w = u ≡ v ↦ w u ∈ (v ⊔ w) = u ∈ v ⊎ u ∈ w infix 5 _⊆_ _⊆_ : Value → Value → Set v ⊆ w = ∀{u} → u ∈ v → u ∈ w AllFun : (u : Value) → Set AllFun ⊥ = Bot AllFun (const x) = Bot AllFun (v ↦ w) = ⊤ AllFun (u ⊔ v) = AllFun u × AllFun v dom : (u : Value) → Value dom ⊥ = ⊥ dom (const k) = ⊥ dom (v ↦ w) = v dom (u ⊔ v) = dom u ⊔ dom v cod : (u : Value) → Value cod ⊥ = ⊥ cod (const k) = ⊥ cod (v ↦ w) = w cod (u ⊔ v) = cod u ⊔ cod v infix 4 _⊑_ data _⊑_ : Value → Value → Set where ⊑-⊥ : ∀ {v} → ⊥ ⊑ v ⊑-const : ∀ {B}{k} → const {B} k ⊑ const {B} k ⊑-conj-L : ∀ {u v w} → v ⊑ u → w ⊑ u ----------- → v ⊔ w ⊑ u ⊑-conj-R1 : ∀ {u v w} → u ⊑ v ------------------ → u ⊑ v ⊔ w ⊑-conj-R2 : ∀ {u v w} → u ⊑ w ----------- → u ⊑ v ⊔ w ⊑-fun : ∀ {u u′ v w} → u′ ⊆ u → AllFun u′ → dom u′ ⊑ v → w ⊑ cod u′ ------------------- → v ↦ w ⊑ u ⊑-refl : ∀{v} → v ⊑ v ⊑-refl {⊥} = ⊑-⊥ ⊑-refl {const k} = ⊑-const ⊑-refl {v ↦ w} = ⊑-fun{v ↦ w}{v ↦ w} (λ {u} z → z) tt (⊑-refl{v}) ⊑-refl ⊑-refl {v₁ ⊔ v₂} = ⊑-conj-L (⊑-conj-R1 ⊑-refl) (⊑-conj-R2 ⊑-refl) factor : (u : Value) → (u′ : Value) → (v : Value) → (w : Value) → Set factor u u′ v w = AllFun u′ × u′ ⊆ u × dom u′ ⊑ v × w ⊑ cod u′ ⊑-fun-inv : ∀{u₁ u₂ v w} → u₁ ⊑ u₂ → v ↦ w ∈ u₁ → Σ[ u₃ ∈ Value ] factor u₂ u₃ v w ⊑-fun-inv {.⊥} {u₂} {v} {w} ⊑-⊥ () ⊑-fun-inv {.(const _)} {.(const _)} {v} {w} ⊑-const () ⊑-fun-inv {u11 ⊔ u12} {u₂} {v} {w} (⊑-conj-L u₁⊑u₂ u₁⊑u₃) (inj₁ x) = ⊑-fun-inv u₁⊑u₂ x ⊑-fun-inv {u11 ⊔ u12} {u₂} {v} {w} (⊑-conj-L u₁⊑u₂ u₁⊑u₃) (inj₂ y) = ⊑-fun-inv u₁⊑u₃ y ⊑-fun-inv {u₁} {u21 ⊔ u22} {v} {w} (⊑-conj-R1 u₁⊑u₂) v↦w∈u₁ with ⊑-fun-inv {u₁} {u21} {v} {w} u₁⊑u₂ v↦w∈u₁ ... | ⟨ u₃ , ⟨ afu₃ , ⟨ u3⊆u₁ , ⟨ du₃⊑v , w⊑codu₃ ⟩ ⟩ ⟩ ⟩ = ⟨ u₃ , ⟨ afu₃ , ⟨ (λ {x} x₁ → inj₁ (u3⊆u₁ x₁)) , ⟨ du₃⊑v , w⊑codu₃ ⟩ ⟩ ⟩ ⟩ ⊑-fun-inv {u₁} {u21 ⊔ u22} {v} {w} (⊑-conj-R2 u₁⊑u₂) v↦w∈u₁ with ⊑-fun-inv {u₁} {u22} {v} {w} u₁⊑u₂ v↦w∈u₁ ... | ⟨ u₃ , ⟨ afu₃ , ⟨ u3⊆u₁ , ⟨ du₃⊑v , w⊑codu₃ ⟩ ⟩ ⟩ ⟩ = ⟨ u₃ , ⟨ afu₃ , ⟨ (λ {x} x₁ → inj₂ (u3⊆u₁ x₁)) , ⟨ du₃⊑v , w⊑codu₃ ⟩ ⟩ ⟩ ⟩ ⊑-fun-inv {u11 ↦ u21} {u₂} {v} {w} (⊑-fun{u′ = u′} u′⊆u₂ afu′ du′⊑u11 u21⊑cu′) refl = ⟨ u′ , ⟨ afu′ , ⟨ u′⊆u₂ , ⟨ du′⊑u11 , u21⊑cu′ ⟩ ⟩ ⟩ ⟩ sub-inv-trans : ∀{u′ u₂ u : Value} → AllFun u′ → u′ ⊆ u → (∀{v′ w′} → v′ ↦ w′ ∈ u′ → Σ[ u₃ ∈ Value ] factor u₂ u₃ v′ w′) --------------------------------------------------------------- → Σ[ u₃ ∈ Value ] factor u₂ u₃ (dom u′) (cod u′) sub-inv-trans {⊥} {u₂} {u} () u′⊆u IH sub-inv-trans {const k} {u₂} {u} () u′⊆u IH sub-inv-trans {u₁′ ↦ u₂′} {u₂} {u} fu′ u′⊆u IH = IH refl sub-inv-trans {u₁′ ⊔ u₂′} {u₂} {u} ⟨ afu₁′ , afu₂′ ⟩ u′⊆u IH with sub-inv-trans {u₁′} {u₂} {u} afu₁′ (λ {u₁} z → u′⊆u (inj₁ z)) (λ {v′} {w′} z → IH (inj₁ z)) | sub-inv-trans {u₂′} {u₂} {u} afu₂′ (λ {u₁} z → u′⊆u (inj₂ z)) (λ {v′} {w′} z → IH (inj₂ z)) ... | ⟨ u₃ , ⟨ afu₃ , ⟨ u₃⊆ , ⟨ du₃⊑ , ⊑cu₃ ⟩ ⟩ ⟩ ⟩ | ⟨ u₄ , ⟨ afu₄ , ⟨ u₄⊆ , ⟨ du₄⊑ , ⊑cu₄ ⟩ ⟩ ⟩ ⟩ = ⟨ (u₃ ⊔ u₄) , ⟨ ⟨ afu₃ , afu₄ ⟩ , ⟨ G , ⟨ H , I ⟩ ⟩ ⟩ ⟩ where G : ∀ {u₁} → u₁ ∈ u₃ ⊎ u₁ ∈ u₄ → u₁ ∈ u₂ G {u₁} (inj₁ x) = u₃⊆ x G {u₁} (inj₂ y) = u₄⊆ y H : dom u₃ ⊔ dom u₄ ⊑ dom u₁′ ⊔ dom u₂′ H = ⊑-conj-L (⊑-conj-R1 du₃⊑) (⊑-conj-R2 du₄⊑) I : cod u₁′ ⊔ cod u₂′ ⊑ cod u₃ ⊔ cod u₄ I = ⊑-conj-L (⊑-conj-R1 ⊑cu₃) (⊑-conj-R2 ⊑cu₄) ⊔⊑R : ∀{B C A} → B ⊔ C ⊑ A → B ⊑ A ⊔⊑R (⊑-conj-L B⊔C⊑A B⊔C⊑A₁) = B⊔C⊑A ⊔⊑R (⊑-conj-R1 B⊔C⊑A) = ⊑-conj-R1 (⊔⊑R B⊔C⊑A) ⊔⊑R (⊑-conj-R2 B⊔C⊑A) = ⊑-conj-R2 (⊔⊑R B⊔C⊑A) ⊔⊑L : ∀{B C A} → B ⊔ C ⊑ A → C ⊑ A ⊔⊑L (⊑-conj-L B⊔C⊑A B⊔C⊑A₁) = B⊔C⊑A₁ ⊔⊑L (⊑-conj-R1 B⊔C⊑A) = ⊑-conj-R1 (⊔⊑L B⊔C⊑A) ⊔⊑L (⊑-conj-R2 B⊔C⊑A) = ⊑-conj-R2 (⊔⊑L B⊔C⊑A) u∈v⊑w→u⊑w : ∀{B A C} → C ∈ B → B ⊑ A → C ⊑ A u∈v⊑w→u⊑w {⊥} C∈B B⊑A rewrite C∈B = B⊑A u∈v⊑w→u⊑w {const k} C∈B B⊑A rewrite C∈B = B⊑A u∈v⊑w→u⊑w {B₁ ↦ B₂} C∈B B⊑A rewrite C∈B = B⊑A u∈v⊑w→u⊑w {B₁ ⊔ B₂}{A}{C} (inj₁ C∈B₁) B⊑A = u∈v⊑w→u⊑w {B₁}{A}{C} C∈B₁ (⊔⊑R B⊑A) u∈v⊑w→u⊑w {B₁ ⊔ B₂}{A}{C} (inj₂ C∈B₂) B⊑A = u∈v⊑w→u⊑w {B₂}{A}{C} C∈B₂ (⊔⊑L B⊑A) u⊆v⊑w→u⊑w : ∀{u v w} → u ⊆ v → v ⊑ w → u ⊑ w u⊆v⊑w→u⊑w {⊥} {v} {w} u⊆v v⊑w = ⊑-⊥ u⊆v⊑w→u⊑w {const k} {v} {w} u⊆v v⊑w with u⊆v refl ... | k∈v = u∈v⊑w→u⊑w k∈v v⊑w u⊆v⊑w→u⊑w {u₁ ↦ u₂} {v} {w} u⊆v v⊑w with u⊆v refl ... | u₁↦u₂∈v = u∈v⊑w→u⊑w u₁↦u₂∈v v⊑w u⊆v⊑w→u⊑w {u₁ ⊔ u₂} {v} {w} u⊆v v⊑w = ⊑-conj-L (u⊆v⊑w→u⊑w u₁⊆v v⊑w) (u⊆v⊑w→u⊑w u₂⊆v v⊑w) where u₁⊆v : u₁ ⊆ v u₁⊆v {u′} u′∈u₁ = u⊆v (inj₁ u′∈u₁) u₂⊆v : u₂ ⊆ v u₂⊆v {u′} u′∈u₂ = u⊆v (inj₂ u′∈u₂) depth : (v : Value) → ℕ depth ⊥ = zero depth (const k) = zero depth (v ↦ w) = suc (max (depth v) (depth w)) depth (v₁ ⊔ v₂) = max (depth v₁) (depth v₂) size : (v : Value) → ℕ size ⊥ = zero size (const k) = zero size (v ↦ w) = suc (size v + size w) size (v₁ ⊔ v₂) = suc (size v₁ + size v₂) ∈→depth≤ : ∀{v u : Value} → u ∈ v → depth u ≤ depth v ∈→depth≤ {⊥} {u} u∈v rewrite u∈v = _≤_.z≤n ∈→depth≤ {const x} {u} u∈v rewrite u∈v = _≤_.z≤n ∈→depth≤ {v ↦ w} {u} u∈v rewrite u∈v = ≤-refl ∈→depth≤ {v₁ ⊔ v₂} {u} (inj₁ x) = ≤-trans (∈→depth≤ {v₁} {u} x) (m≤m⊔n (depth v₁) (depth v₂)) ∈→depth≤ {v₁ ⊔ v₂} {u} (inj₂ y) = ≤-trans (∈→depth≤ {v₂} {u} y) (n≤m⊔n (depth v₁) (depth v₂)) max-lub : ∀{x y z : ℕ} → x ≤ z → y ≤ z → max x y ≤ z max-lub {.0} {y} {z} _≤_.z≤n y≤z = y≤z max-lub {suc x} {.0} {suc z} (_≤_.s≤s x≤z) _≤_.z≤n = _≤_.s≤s x≤z max-lub {suc x} {suc y} {suc z} (_≤_.s≤s x≤z) (_≤_.s≤s y≤z) = let max-xy≤z = max-lub {x}{y}{z} x≤z y≤z in _≤_.s≤s max-xy≤z ⊔⊆-inv : ∀{u v w : Value} → (u ⊔ v) ⊆ w --------------- → u ⊆ w × v ⊆ w ⊔⊆-inv uvw = ⟨ (λ x → uvw (inj₁ x)) , (λ x → uvw (inj₂ x)) ⟩ ⊆→depth≤ : ∀{u v : Value} → u ⊆ v → depth u ≤ depth v ⊆→depth≤ {⊥} {v} u⊆v = _≤_.z≤n ⊆→depth≤ {const x} {v} u⊆v = _≤_.z≤n ⊆→depth≤ {u₁ ↦ u₂} {v} u⊆v = ∈→depth≤ (u⊆v refl) ⊆→depth≤ {u₁ ⊔ u₂} {v} u⊆v with ⊔⊆-inv u⊆v ... | ⟨ u₁⊆v , u₂⊆v ⟩ = let u₁≤v = ⊆→depth≤ u₁⊆v in let u₂≤v = ⊆→depth≤ u₂⊆v in max-lub u₁≤v u₂≤v dom-depth-≤ : ∀{u : Value} → depth (dom u) ≤ depth u dom-depth-≤ {⊥} = _≤_.z≤n dom-depth-≤ {const k} = _≤_.z≤n dom-depth-≤ {v ↦ w} = ≤-step (m≤m⊔n (depth v) (depth w)) dom-depth-≤ {u ⊔ v} = let ih1 = dom-depth-≤ {u} in let ih2 = dom-depth-≤ {v} in ⊔-mono-≤ ih1 ih2 cod-depth-≤ : ∀{u : Value} → depth (cod u) ≤ depth u cod-depth-≤ {⊥} = _≤_.z≤n cod-depth-≤ {const k} = _≤_.z≤n cod-depth-≤ {v ↦ w} = ≤-step (n≤m⊔n (depth v) (depth w)) cod-depth-≤ {u ⊔ v} = let ih1 = cod-depth-≤ {u} in let ih2 = cod-depth-≤ {v} in ⊔-mono-≤ ih1 ih2 ≤′-trans : ∀{x y z} → x ≤′ y → y ≤′ z → x ≤′ z ≤′-trans x≤′y y≤′z = ≤⇒≤′ (≤-trans (≤′⇒≤ x≤′y) (≤′⇒≤ y≤′z)) data _<<_ : ℕ × ℕ → ℕ × ℕ → Set where fst : ∀{x x' y y'} → x <′ x' → ⟨ x , y ⟩ << ⟨ x' , y' ⟩ snd : ∀{x x' y y'} → x ≤′ x' → y <′ y' → ⟨ x , y ⟩ << ⟨ x' , y' ⟩ <<-nat-wf : (P : ℕ → ℕ → Set) → (∀ x y → (∀ {x' y'} → ⟨ x' , y' ⟩ << ⟨ x , y ⟩ → P x' y') → P x y) → ∀ x y → P x y <<-nat-wf P ih x y = ih x y (help x y) where help : (x y : ℕ) → ∀{ x' y'} → ⟨ x' , y' ⟩ << ⟨ x , y ⟩ → P x' y' help .(suc x') y {x'}{y'} (fst ≤′-refl) = ih x' y' (help x' y') help .(suc x) y {x'}{y'} (fst (≤′-step {x} q)) = help x y {x'}{y'} (fst q) help x .(suc y) {x'}{y} (snd x'≤x ≤′-refl) = let h : ∀ {x₁} {x₂} → (⟨ x₁ , x₂ ⟩ << ⟨ x , y ⟩) → P x₁ x₂ h = help x y in ih x' y G where G : ∀ {x'' y'} → ⟨ x'' , y' ⟩ << ⟨ x' , y ⟩ → P x'' y' G {x''} {y'} (fst x''<x') = help x y (fst {y = y'}{y' = y} (≤′-trans x''<x' x'≤x)) G {x''} {y'} (snd x''≤x' y'<y) = help x y {x''}{y'} (snd (≤′-trans x''≤x' x'≤x) y'<y) help x .(suc y) {x'}{y'} (snd x′≤x (≤′-step {y} q)) = help x y {x'}{y'} (snd x′≤x q) ⊑-trans-P : ℕ → ℕ → Set ⊑-trans-P d s = ∀{u v w} → d ≡ depth u + depth w → s ≡ size u + size v → u ⊑ v → v ⊑ w → u ⊑ w ⊑-trans-rec : ∀ d s → ⊑-trans-P d s ⊑-trans-rec = <<-nat-wf ⊑-trans-P helper where helper : ∀ x y → (∀ {x' y'} → ⟨ x' , y' ⟩ << ⟨ x , y ⟩ → ⊑-trans-P x' y') → ⊑-trans-P x y helper d s IH {.⊥} {v} {w} d≡ s≡ ⊑-⊥ v⊑w = ⊑-⊥ helper d s IH {.(const _)} {.(const _)} {w} d≡ s≡ ⊑-const v⊑w = v⊑w helper d s IH {u₁ ⊔ u₂} {v} {w} d≡ s≡ (⊑-conj-L u₁⊑v u₂⊑v) v⊑w rewrite d≡ | s≡ = let u₁⊑w = IH M1 {u₁}{v}{w} refl refl u₁⊑v v⊑w in let u₂⊑w = IH M2 {u₂}{v}{w} refl refl u₂⊑v v⊑w in ⊑-conj-L u₁⊑w u₂⊑w where M1a = begin depth u₁ + depth w ≤⟨ +-mono-≤ (m≤m⊔n (depth u₁) (depth u₂)) ≤-refl ⟩ max (depth u₁) (depth u₂) + depth w ∎ M1b = begin suc (size u₁ + size v) ≤⟨ s≤s (+-mono-≤ ≤-refl (n≤m+n (size u₂) (size v))) ⟩ suc (size u₁ + (size u₂ + size v)) ≤⟨ s≤s (≤-reflexive (sym (+-assoc (size u₁) (size u₂) (size v)))) ⟩ suc (size u₁ + size u₂ + size v) ∎ M1 : ⟨ depth u₁ + depth w , size u₁ + size v ⟩ << ⟨ max (depth u₁) (depth u₂) + depth w , suc (size u₁ + size u₂ + size v) ⟩ M1 = snd (≤⇒≤′ M1a) (≤⇒≤′ M1b) M2a = begin depth u₂ + depth w ≤⟨ +-mono-≤ (n≤m⊔n (depth u₁) (depth u₂)) ≤-refl ⟩ max (depth u₁) (depth u₂) + depth w ∎ M2b = begin suc (size u₂ + size v) ≤⟨ s≤s (+-mono-≤ (n≤m+n (size u₁) (size u₂)) ≤-refl) ⟩ suc ((size u₁ + size u₂) + size v) ∎ M2 : ⟨ depth u₂ + depth w , size u₂ + size v ⟩ << ⟨ max (depth u₁) (depth u₂) + depth w , suc (size u₁ + size u₂ + size v) ⟩ M2 = snd (≤⇒≤′ M2a) (≤⇒≤′ M2b) helper d s IH {u} {v₁ ⊔ v₂} {w} d≡ s≡ (⊑-conj-R1 u⊑v₁) v₁⊔v₂⊑w rewrite d≡ | s≡ = let v₁⊑w = ⊔⊑R v₁⊔v₂⊑w in IH M {u}{v₁}{w} refl refl u⊑v₁ v₁⊑w where Ma = begin suc (size u + size v₁) ≤⟨ ≤-reflexive (sym (+-suc (size u) (size v₁))) ⟩ size u + suc (size v₁) ≤⟨ +-mono-≤ ≤-refl (s≤s (m≤m+n (size v₁) (size v₂))) ⟩ size u + suc (size v₁ + size v₂) ∎ M : ⟨ depth u + depth w , size u + size v₁ ⟩ << ⟨ depth u + depth w , size u + suc (size v₁ + size v₂) ⟩ M = snd (≤⇒≤′ ≤-refl) (≤⇒≤′ Ma) helper d s IH {u} {v₁ ⊔ v₂} {w} d≡ s≡ (⊑-conj-R2 u⊑v₂) v₁⊔v₂⊑w rewrite d≡ | s≡ = let v₂⊑w = ⊔⊑L v₁⊔v₂⊑w in IH M {u}{v₂}{w} refl refl u⊑v₂ v₂⊑w where Ma = begin suc (size u + size v₂) ≤⟨ ≤-reflexive (sym (+-suc (size u) (size v₂))) ⟩ size u + suc (size v₂) ≤⟨ +-mono-≤ ≤-refl (s≤s (n≤m+n (size v₁) (size v₂))) ⟩ size u + suc (size v₁ + size v₂) ∎ M : ⟨ depth u + depth w , size u + size v₂ ⟩ << ⟨ depth u + depth w , size u + suc (size v₁ + size v₂) ⟩ M = snd (≤⇒≤′ ≤-refl) (≤⇒≤′ Ma) helper d s IH {u₁ ↦ u₂}{v}{w}d≡ s≡ (⊑-fun{u′ = v′}v′⊆v afv′ dv′⊑u₁ u₂⊑cv′) v⊑w rewrite d≡ | s≡ with sub-inv-trans afv′ v′⊆v (λ {v₁}{v₂} v₁↦v₂∈v′ → ⊑-fun-inv {v′} {w} (u⊆v⊑w→u⊑w v′⊆v v⊑w) v₁↦v₂∈v′) ... | ⟨ w′ , ⟨ afw′ , ⟨ w′⊆w , ⟨ dw′⊑dv′ , cv′⊑cw′ ⟩ ⟩ ⟩ ⟩ = let dw′⊑u₁ = IH M1 {dom w′}{dom v′}{u₁} refl refl dw′⊑dv′ dv′⊑u₁ in let u₂⊑cw′ = IH M2 {u₂}{cod v′}{cod w′} refl refl u₂⊑cv′ cv′⊑cw′ in ⊑-fun{u′ = w′} w′⊆w afw′ dw′⊑u₁ u₂⊑cw′ where dw′≤w : depth (dom w′) ≤ depth w dw′≤w = ≤-trans (dom-depth-≤{w′}) (⊆→depth≤ w′⊆w) cw′≤w : depth (cod w′) ≤ depth w cw′≤w = ≤-trans (cod-depth-≤{w′}) (⊆→depth≤ w′⊆w) M1a = begin suc (depth (dom w′) + depth u₁) ≤⟨ s≤s (≤-reflexive (+-comm (depth (dom w′)) (depth u₁))) ⟩ suc (depth u₁ + depth (dom w′)) ≤⟨ s≤s (+-mono-≤ (m≤m⊔n (depth u₁) (depth u₂)) dw′≤w) ⟩ suc (max (depth u₁) (depth u₂) + depth w) ∎ M1 : ⟨ depth (dom w′) + depth u₁ , size (dom w′) + size (dom v′) ⟩ << ⟨ suc (max (depth u₁) (depth u₂) + depth w) , suc (size u₁ + size u₂ + size v) ⟩ M1 = fst (≤⇒≤′ M1a) M2a = begin suc (depth u₂ + depth (cod w′)) ≤⟨ s≤s (+-mono-≤ (n≤m⊔n (depth u₁) (depth u₂)) cw′≤w) ⟩ suc (max (depth u₁) (depth u₂) + depth w) ∎ M2 : ⟨ depth u₂ + depth (cod w′) , size u₂ + size (cod v′) ⟩ << ⟨ suc (max (depth u₁) (depth u₂) + depth w) , suc (size u₁ + size u₂ + size v) ⟩ M2 = fst (≤⇒≤′ M2a) ⊑-trans : ∀{u v w} → u ⊑ v → v ⊑ w → u ⊑ w ⊑-trans {u} {v} {w} u⊑v v⊑w = ⊑-trans-rec (depth u + depth w) (size u + size v) refl refl u⊑v v⊑w
34.01139
92
0.428705
0bfba2fba888a23b282ecce7f8e107b78509390d
2,448
agda
Agda
test/Succeed/AbstractCoinduction.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
1
2021-07-07T10:49:57.000Z
2021-07-07T10:49:57.000Z
test/Succeed/AbstractCoinduction.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/AbstractCoinduction.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
-- Andreas, 2016-10-03, re issue #2231 -- Testing whether the musical coinduction works fine in abstract blocks module AbstractCoinduction where {-# BUILTIN INFINITY ∞_ #-} {-# BUILTIN SHARP ♯_ #-} {-# BUILTIN FLAT ♭ #-} infixr 5 _≺_ abstract ------------------------------------------------------------------------ -- Streams data Stream (A : Set) : Set where _≺_ : (x : A) (xs : ∞ (Stream A)) -> Stream A head : ∀ {A} -> Stream A -> A head (x ≺ xs) = x tail : ∀ {A} -> Stream A -> Stream A tail (x ≺ xs) = ♭ xs ------------------------------------------------------------------------ -- Stream programs infix 8 _∞ infixr 5 _⋎_ infix 4 ↓_ mutual data Stream′ (A : Set) : Set1 where _≺_ : (x : A) (xs : ∞ (StreamProg A)) -> Stream′ A data StreamProg (A : Set) : Set1 where ↓_ : (xs : Stream′ A) -> StreamProg A _∞' : (x : A) -> StreamProg A _⋎'_ : (xs ys : StreamProg A) -> StreamProg A _∞ : ∀ {A : Set} (x : A) -> StreamProg A _∞ = _∞' _⋎_ : ∀ {A : Set} (xs ys : StreamProg A) -> StreamProg A _⋎_ = _⋎'_ head′ : ∀ {A} → Stream′ A → A head′ (x ≺ xs) = x tail′ : ∀ {A} → Stream′ A → StreamProg A tail′ (x ≺ xs) = ♭ xs P⇒′ : ∀ {A} -> StreamProg A -> Stream′ A P⇒′ (↓ xs) = xs P⇒′ (x ∞') = x ≺ ♯ (x ∞) P⇒′ (xs ⋎' ys) with P⇒′ xs P⇒′ (xs ⋎' ys) | xs′ = head′ xs′ ≺ ♯ (ys ⋎ tail′ xs′) mutual ′⇒ : ∀ {A} -> Stream′ A -> Stream A ′⇒ (x ≺ xs) = x ≺ ♯ P⇒ (♭ xs) P⇒ : ∀ {A} -> StreamProg A -> Stream A P⇒ xs = ′⇒ (P⇒′ xs) ------------------------------------------------------------------------ -- Stream equality infix 4 _≡_ _≈_ _≊_ data _≡_ {a : Set} (x : a) : a -> Set where ≡-refl : x ≡ x data _≈_ {A} (xs ys : Stream A) : Set where _≺_ : (x≡ : head xs ≡ head ys) (xs≈ : ∞ (tail xs ≈ tail ys)) -> xs ≈ ys _≊_ : ∀ {A} (xs ys : StreamProg A) -> Set xs ≊ ys = P⇒ xs ≈ P⇒ ys foo : ∀ {A : Set} (x : A) -> x ∞ ⋎ x ∞ ≊ x ∞ foo x = ≡-refl ≺ ♯ foo x -- The first goal has goal type -- head (′⇒ (x ≺ x ∞ ⋎ x ∞)) ≡ head (′⇒ (x ≺ x ∞)). -- The normal form of the left-hand side is x, and the normal form of -- the right-hand side is x (both according to Agda), but ≡-refl is -- not accepted by the type checker: -- x != head (′⇒ (P⇒′ (x ∞))) of type .A -- when checking that the expression ≡-refl has type -- (head (P⇒ (x ∞ ⋎ x ∞)) ≡ head (P⇒ (x ∞)))
25.5
74
0.4375
4dafe24d626379cda66d4c38bd7f8897416ce5da
1,653
agda
Agda
BasicIPC/Metatheory/Gentzen-BasicTarski.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicIPC/Metatheory/Gentzen-BasicTarski.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicIPC/Metatheory/Gentzen-BasicTarski.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
module BasicIPC.Metatheory.Gentzen-BasicTarski where open import BasicIPC.Syntax.Gentzen public open import BasicIPC.Semantics.BasicTarski public -- Soundness with respect to all models, or evaluation. eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A eval (var i) γ = lookup i γ eval (lam t) γ = λ a → eval t (γ , a) eval (app t u) γ = eval t γ $ eval u γ eval (pair t u) γ = eval t γ , eval u γ eval (fst t) γ = π₁ (eval t γ) eval (snd t) γ = π₂ (eval t γ) eval unit γ = ∙ -- Correctness of evaluation with respect to conversion. -- FIXME: How to show this? postulate oops₁ : ∀ {{_ : Model}} {A B Γ} {t : Γ , A ⊢ B} {u : Γ ⊢ A} → eval ([ top ≔ u ] t) ≡ (λ γ → eval t (γ , eval u γ)) oops₂ : ∀ {{_ : Model}} {A B Γ} {t : Γ ⊢ A ▻ B} → eval t ≡ (λ γ a → eval (mono⊢ (weak⊆ {A = A}) t) (γ , a) a) eval✓ : ∀ {{_ : Model}} {A Γ} {t t′ : Γ ⊢ A} → t ⋙ t′ → eval t ≡ eval t′ eval✓ refl⋙ = refl eval✓ (trans⋙ p q) = trans (eval✓ p) (eval✓ q) eval✓ (sym⋙ p) = sym (eval✓ p) eval✓ (conglam⋙ {A} {B} p) = cong (⟦λ⟧ {A} {B}) (eval✓ p) eval✓ (congapp⋙ {A} {B} p q) = cong² (_⟦$⟧_ {A} {B}) (eval✓ p) (eval✓ q) eval✓ (congpair⋙ {A} {B} p q) = cong² (_⟦,⟧_ {A} {B}) (eval✓ p) (eval✓ q) eval✓ (congfst⋙ {A} {B} p) = cong (⟦π₁⟧ {A} {B}) (eval✓ p) eval✓ (congsnd⋙ {A} {B} p) = cong (⟦π₂⟧ {A} {B}) (eval✓ p) eval✓ (beta▻⋙ {A} {B} {t} {u}) = sym (oops₁ {A} {B} {_} {t} {u}) eval✓ (eta▻⋙ {A} {B} {t}) = oops₂ {A} {B} {_} {t} eval✓ beta∧₁⋙ = refl eval✓ beta∧₂⋙ = refl eval✓ eta∧⋙ = refl eval✓ eta⊤⋙ = refl
38.44186
74
0.476709
230e88b314c32d4d85b4f98f7fb1bdb80597591a
13,051
agda
Agda
Cubical/Foundations/Univalence.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
null
null
null
Cubical/Foundations/Univalence.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
null
null
null
Cubical/Foundations/Univalence.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
null
null
null
{- Proof of the standard formulation of the univalence theorem and various consequences of univalence - Re-exports Glue types from Cubical.Core.Glue - The ua constant and its computation rule (up to a path) - Proof of univalence using that unglue is an equivalence ([EquivContr]) - Equivalence induction ([EquivJ], [elimEquiv]) - Univalence theorem ([univalence]) - The computation rule for ua ([uaβ]) - Isomorphism induction ([elimIso]) -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.Univalence where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.GroupoidLaws open import Cubical.Data.Sigma.Base open import Cubical.Core.Glue public using ( Glue ; glue ; unglue ; lineToEquiv ) private variable ℓ ℓ' : Level -- The ua constant ua : ∀ {A B : Type ℓ} → A ≃ B → A ≡ B ua {A = A} {B = B} e i = Glue B (λ { (i = i0) → (A , e) ; (i = i1) → (B , idEquiv B) }) uaIdEquiv : {A : Type ℓ} → ua (idEquiv A) ≡ refl uaIdEquiv {A = A} i j = Glue A {φ = i ∨ ~ j ∨ j} (λ _ → A , idEquiv A) -- Propositional extensionality hPropExt : {A B : Type ℓ} → isProp A → isProp B → (A → B) → (B → A) → A ≡ B hPropExt Aprop Bprop f g = ua (isPropEquiv→Equiv Aprop Bprop f g) -- the unglue and glue primitives specialized to the case of ua ua-unglue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : ua e i) → B {- [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → x }) ] -} ua-unglue e i x = unglue (i ∨ ~ i) x ua-glue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : Partial (~ i) A) (y : B [ _ ↦ (λ { (i = i0) → e .fst (x 1=1) }) ]) → ua e i {- [ _ ↦ (λ { (i = i0) → x 1=1 ; (i = i1) → outS y }) ] -} ua-glue e i x y = glue {φ = i ∨ ~ i} (λ { (i = i0) → x 1=1 ; (i = i1) → outS y }) (outS y) -- sometimes more useful are versions of these functions with the (i : I) factored in ua-ungluePath : ∀ {A B : Type ℓ} (e : A ≃ B) {x : A} {y : B} → PathP (λ i → ua e i) x y → e .fst x ≡ y ua-ungluePath e p i = ua-unglue e i (p i) ua-gluePath : ∀ {A B : Type ℓ} (e : A ≃ B) {x : A} {y : B} → e .fst x ≡ y → PathP (λ i → ua e i) x y ua-gluePath e {x} p i = ua-glue e i (λ { (i = i0) → x }) (inS (p i)) -- ua-ungluePath and ua-gluePath are definitional inverses ua-ungluePath-Equiv : ∀ {A B : Type ℓ} (e : A ≃ B) {x : A} {y : B} → (PathP (λ i → ua e i) x y) ≃ (e .fst x ≡ y) ua-ungluePath-Equiv e = isoToEquiv (iso (ua-ungluePath e) (ua-gluePath e) (λ _ → refl) (λ _ → refl)) -- ua-unglue and ua-glue are also definitional inverses, in a way -- strengthening the types of ua-unglue and ua-glue gives a nicer formulation of this, see below ua-unglue-glue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : Partial (~ i) A) (y : B [ _ ↦ _ ]) → ua-unglue e i (ua-glue e i x y) ≡ outS y ua-unglue-glue _ _ _ _ = refl ua-glue-unglue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : ua e i) → ua-glue e i (λ { (i = i0) → x }) (inS (ua-unglue e i x)) ≡ x ua-glue-unglue _ _ _ = refl -- mainly for documentation purposes, ua-unglue and ua-glue wrapped in cubical subtypes ua-unglueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B) → ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ] → B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ] ua-unglueS e i x y s = inS (ua-unglue e i (outS s)) ua-glueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B) → B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ] → ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ] ua-glueS e i x y s = inS (ua-glue e i (λ { (i = i0) → x }) (inS (outS s))) ua-unglueS-glueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B) (s : B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ]) → outS (ua-unglueS e i x y (ua-glueS e i x y s)) ≡ outS s ua-unglueS-glueS _ _ _ _ _ = refl ua-glueS-unglueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B) (s : ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ]) → outS (ua-glueS e i x y (ua-unglueS e i x y s)) ≡ outS s ua-glueS-unglueS _ _ _ _ _ = refl -- a version of ua-glue with a single endpoint, identical to `ua-gluePath e {x} refl i` ua-gluePt : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) → ua e i {- [ _ ↦ (λ { (i = i0) → x ; (i = i1) → e .fst x }) ] -} ua-gluePt e i x = ua-glue e i (λ { (i = i0) → x }) (inS (e .fst x)) -- Proof of univalence using that unglue is an equivalence: -- unglue is an equivalence unglueIsEquiv : ∀ (A : Type ℓ) (φ : I) (f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] T ≃ A)) → isEquiv {A = Glue A f} (unglue φ) equiv-proof (unglueIsEquiv A φ f) = λ (b : A) → let u : I → Partial φ A u i = λ{ (φ = i1) → equivCtr (f 1=1 .snd) b .snd (~ i) } ctr : fiber (unglue φ) b ctr = ( glue (λ { (φ = i1) → equivCtr (f 1=1 .snd) b .fst }) (hcomp u b) , λ j → hfill u (inS b) (~ j)) in ( ctr , λ (v : fiber (unglue φ) b) i → let u' : I → Partial (φ ∨ ~ i ∨ i) A u' j = λ { (φ = i1) → equivCtrPath (f 1=1 .snd) b v i .snd (~ j) ; (i = i0) → hfill u (inS b) j ; (i = i1) → v .snd (~ j) } in ( glue (λ { (φ = i1) → equivCtrPath (f 1=1 .snd) b v i .fst }) (hcomp u' b) , λ j → hfill u' (inS b) (~ j))) -- Any partial family of equivalences can be extended to a total one -- from Glue [ φ ↦ (T,f) ] A to A unglueEquiv : ∀ (A : Type ℓ) (φ : I) (f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] T ≃ A)) → (Glue A f) ≃ A unglueEquiv A φ f = ( unglue φ , unglueIsEquiv A φ f ) -- The following is a formulation of univalence proposed by Martín Escardó: -- https://groups.google.com/forum/#!msg/homotopytypetheory/HfCB_b-PNEU/Ibb48LvUMeUJ -- See also Theorem 5.8.4 of the HoTT Book. -- -- The reason we have this formulation in the core library and not the -- standard one is that this one is more direct to prove using that -- unglue is an equivalence. The standard formulation can be found in -- Cubical/Basics/Univalence. -- EquivContr : ∀ (A : Type ℓ) → ∃![ T ∈ Type ℓ ] (T ≃ A) EquivContr {ℓ = ℓ} A = ( (A , idEquiv A) , idEquiv≡ ) where idEquiv≡ : (y : Σ (Type ℓ) (λ T → T ≃ A)) → (A , idEquiv A) ≡ y idEquiv≡ w = \ { i .fst → Glue A (f i) ; i .snd .fst → unglueEquiv _ _ (f i) .fst ; i .snd .snd .equiv-proof → unglueEquiv _ _ (f i) .snd .equiv-proof } where f : ∀ i → PartialP (~ i ∨ i) (λ x → Σ[ T ∈ Type ℓ ] T ≃ A) f i = λ { (i = i0) → A , idEquiv A ; (i = i1) → w } contrSinglEquiv : {A B : Type ℓ} (e : A ≃ B) → (B , idEquiv B) ≡ (A , e) contrSinglEquiv {A = A} {B = B} e = isContr→isProp (EquivContr B) (B , idEquiv B) (A , e) -- Equivalence induction EquivJ : {A B : Type ℓ} (P : (A : Type ℓ) → (e : A ≃ B) → Type ℓ') → (r : P B (idEquiv B)) → (e : A ≃ B) → P A e EquivJ P r e = subst (λ x → P (x .fst) (x .snd)) (contrSinglEquiv e) r -- Assuming that we have an inverse to ua we can easily prove univalence module Univalence (au : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → A ≃ B) (aurefl : ∀ {ℓ} {A B : Type ℓ} → au refl ≡ idEquiv A) where ua-au : {A B : Type ℓ} (p : A ≡ B) → ua (au p) ≡ p ua-au {B = B} = J (λ _ p → ua (au p) ≡ p) (cong ua (aurefl {B = B}) ∙ uaIdEquiv) au-ua : {A B : Type ℓ} (e : A ≃ B) → au (ua e) ≡ e au-ua {B = B} = EquivJ (λ _ f → au (ua f) ≡ f) (subst (λ r → au r ≡ idEquiv _) (sym uaIdEquiv) (aurefl {B = B})) isoThm : ∀ {ℓ} {A B : Type ℓ} → Iso (A ≡ B) (A ≃ B) isoThm .Iso.fun = au isoThm .Iso.inv = ua isoThm .Iso.rightInv = au-ua isoThm .Iso.leftInv = ua-au thm : ∀ {ℓ} {A B : Type ℓ} → isEquiv au thm {A = A} {B = B} = isoToIsEquiv {B = A ≃ B} isoThm pathToEquiv : {A B : Type ℓ} → A ≡ B → A ≃ B pathToEquiv p = lineToEquiv (λ i → p i) pathToEquivRefl : {A : Type ℓ} → pathToEquiv refl ≡ idEquiv A pathToEquivRefl {A = A} = equivEq (λ i x → transp (λ _ → A) i x) pathToEquiv-ua : {A B : Type ℓ} (e : A ≃ B) → pathToEquiv (ua e) ≡ e pathToEquiv-ua = Univalence.au-ua pathToEquiv pathToEquivRefl ua-pathToEquiv : {A B : Type ℓ} (p : A ≡ B) → ua (pathToEquiv p) ≡ p ua-pathToEquiv = Univalence.ua-au pathToEquiv pathToEquivRefl -- Univalence univalenceIso : {A B : Type ℓ} → Iso (A ≡ B) (A ≃ B) univalenceIso = Univalence.isoThm pathToEquiv pathToEquivRefl univalence : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B) univalence = ( pathToEquiv , Univalence.thm pathToEquiv pathToEquivRefl ) -- The original map from UniMath/Foundations eqweqmap : {A B : Type ℓ} → A ≡ B → A ≃ B eqweqmap {A = A} e = J (λ X _ → A ≃ X) (idEquiv A) e eqweqmapid : {A : Type ℓ} → eqweqmap refl ≡ idEquiv A eqweqmapid {A = A} = JRefl (λ X _ → A ≃ X) (idEquiv A) univalenceStatement : {A B : Type ℓ} → isEquiv (eqweqmap {ℓ} {A} {B}) univalenceStatement = Univalence.thm eqweqmap eqweqmapid univalenceUAH : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B) univalenceUAH = ( _ , univalenceStatement ) univalencePath : {A B : Type ℓ} → (A ≡ B) ≡ Lift (A ≃ B) univalencePath = ua (compEquiv univalence LiftEquiv) -- The computation rule for ua. Because of "ghcomp" it is now very -- simple compared to cubicaltt: -- https://github.com/mortberg/cubicaltt/blob/master/examples/univalence.ctt#L202 uaβ : {A B : Type ℓ} (e : A ≃ B) (x : A) → transport (ua e) x ≡ equivFun e x uaβ e x = transportRefl (equivFun e x) uaη : ∀ {A B : Type ℓ} → (P : A ≡ B) → ua (pathToEquiv P) ≡ P uaη = J (λ _ q → ua (pathToEquiv q) ≡ q) (cong ua pathToEquivRefl ∙ uaIdEquiv) -- Lemmas for constructing and destructing dependent paths in a function type where the domain is ua. ua→ : ∀ {ℓ ℓ'} {A₀ A₁ : Type ℓ} {e : A₀ ≃ A₁} {B : (i : I) → Type ℓ'} {f₀ : A₀ → B i0} {f₁ : A₁ → B i1} → ((a : A₀) → PathP B (f₀ a) (f₁ (e .fst a))) → PathP (λ i → ua e i → B i) f₀ f₁ ua→ {e = e} {f₀ = f₀} {f₁} h i a = hcomp (λ j → λ { (i = i0) → f₀ a ; (i = i1) → f₁ (lem a j) }) (h (transp (λ j → ua e (~ j ∧ i)) (~ i) a) i) where lem : ∀ a₁ → e .fst (transport (sym (ua e)) a₁) ≡ a₁ lem a₁ = retEq e _ ∙ transportRefl _ ua→⁻ : ∀ {ℓ ℓ'} {A₀ A₁ : Type ℓ} {e : A₀ ≃ A₁} {B : (i : I) → Type ℓ'} {f₀ : A₀ → B i0} {f₁ : A₁ → B i1} → PathP (λ i → ua e i → B i) f₀ f₁ → ((a : A₀) → PathP B (f₀ a) (f₁ (e .fst a))) ua→⁻ {e = e} {f₀ = f₀} {f₁} p a i = hcomp (λ k → λ { (i = i0) → f₀ a ; (i = i1) → f₁ (uaβ e a k) }) (p i (transp (λ j → ua e (j ∧ i)) (~ i) a)) -- Useful lemma for unfolding a transported function over ua -- If we would have regularity this would be refl transportUAop₁ : ∀ {A B : Type ℓ} → (e : A ≃ B) (f : A → A) (x : B) → transport (λ i → ua e i → ua e i) f x ≡ equivFun e (f (invEq e x)) transportUAop₁ e f x i = transportRefl (equivFun e (f (invEq e (transportRefl x i)))) i -- Binary version transportUAop₂ : ∀ {ℓ} {A B : Type ℓ} → (e : A ≃ B) (f : A → A → A) (x y : B) → transport (λ i → ua e i → ua e i → ua e i) f x y ≡ equivFun e (f (invEq e x) (invEq e y)) transportUAop₂ e f x y i = transportRefl (equivFun e (f (invEq e (transportRefl x i)) (invEq e (transportRefl y i)))) i -- Alternative version of EquivJ that only requires a predicate on functions elimEquivFun : {A B : Type ℓ} (P : (A : Type ℓ) → (A → B) → Type ℓ') → (r : P B (idfun B)) → (e : A ≃ B) → P A (e .fst) elimEquivFun P r e = subst (λ x → P (x .fst) (x .snd .fst)) (contrSinglEquiv e) r -- Isomorphism induction elimIso : {B : Type ℓ} → (Q : {A : Type ℓ} → (A → B) → (B → A) → Type ℓ') → (h : Q (idfun B) (idfun B)) → {A : Type ℓ} → (f : A → B) → (g : B → A) → section f g → retract f g → Q f g elimIso {ℓ} {ℓ'} {B} Q h {A} f g sfg rfg = rem1 f g sfg rfg where P : (A : Type ℓ) → (f : A → B) → Type (ℓ-max ℓ' ℓ) P A f = (g : B → A) → section f g → retract f g → Q f g rem : P B (idfun B) rem g sfg rfg = subst (Q (idfun B)) (λ i b → (sfg b) (~ i)) h rem1 : {A : Type ℓ} → (f : A → B) → P A f rem1 f g sfg rfg = elimEquivFun P rem (f , isoToIsEquiv (iso f g sfg rfg)) g sfg rfg uaInvEquiv : ∀ {A B : Type ℓ} → (e : A ≃ B) → ua (invEquiv e) ≡ sym (ua e) uaInvEquiv {B = B} = EquivJ (λ _ e → ua (invEquiv e) ≡ sym (ua e)) (cong ua (invEquivIdEquiv B)) uaCompEquiv : ∀ {A B C : Type ℓ} → (e : A ≃ B) (f : B ≃ C) → ua (compEquiv e f) ≡ ua e ∙ ua f uaCompEquiv {B = B} {C} = EquivJ (λ _ e → (f : B ≃ C) → ua (compEquiv e f) ≡ ua e ∙ ua f) (λ f → cong ua (compEquivIdEquiv f) ∙ sym (cong (λ x → x ∙ ua f) uaIdEquiv ∙ sym (lUnit (ua f))))
41.96463
101
0.517968
4d4a582aaa8ba1d1e9bf9e4b44b6305cd2b69ce8
551
agda
Agda
Cats/End.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
Cats/End.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
Cats/End.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
module Cats.End where open import Level using (_⊔_) open import Cats.Category open import Cats.Category.Wedges using (Wedge ; Wedges) open import Cats.Profunctor module _ {lo la l≈ lo′ la′ l≈′} {C : Category lo la l≈} {D : Category lo′ la′ l≈′} where IsEnd : {F : Profunctor C C D} → Wedge F → Set (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′) IsEnd {F} = Wdg.IsTerminal where module Wdg = Category (Wedges F) record End (F : Profunctor C C D) : Set (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′) where field wedge : Wedge F isEnd : IsEnd wedge
22.958333
76
0.6098
0e36c66f7be1245dba73d51adc91f3ed56c2098e
458
agda
Agda
Numbers/Modulo/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Numbers/Modulo/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Numbers/Modulo/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order module Numbers.Modulo.Definition where record ℤn (n : ℕ) .(pr : 0 <N n) : Set where field x : ℕ .xLess : x <N n equalityZn : {n : ℕ} .{pr : 0 <N n} → {a b : ℤn n pr} → (ℤn.x a ≡ ℤn.x b) → a ≡ b equalityZn {a = record { x = a ; xLess = aLess }} {record { x = .a ; xLess = bLess }} refl = refl
28.625
97
0.611354
fb29ad119fb915c1ed8587646d3834897111c9cc
23,024
agda
Agda
Definition/LogicalRelation/ShapeView.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2018-06-21T08:39:01.000Z
2022-01-17T16:13:53.000Z
Definition/LogicalRelation/ShapeView.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
null
null
null
Definition/LogicalRelation/ShapeView.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2022-01-26T14:55:51.000Z
2022-02-15T19:42:19.000Z
{-# OPTIONS --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.ShapeView {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped as U open import Definition.Typed open import Definition.Typed.Weakening open import Definition.Typed.Properties open import Definition.LogicalRelation open import Definition.LogicalRelation.Properties.Escape open import Definition.LogicalRelation.Properties.Reflexivity open import Tools.Product open import Tools.Empty using (⊥; ⊥-elim) import Tools.PropositionalEquality as PE import Data.Fin as Fin import Data.Nat as Nat -- Type for maybe embeddings of reducible types data MaybeEmb (l : TypeLevel) (⊩⟨_⟩ : TypeLevel → Set) : Set where noemb : ⊩⟨ l ⟩ → MaybeEmb l ⊩⟨_⟩ emb : ∀ {l′} → l′ <∞ l → MaybeEmb l′ ⊩⟨_⟩ → MaybeEmb l ⊩⟨_⟩ -- Specific reducible types with possible embedding _⊩⟨_⟩U_^_ : (Γ : Con Term) (l : TypeLevel) (A : Term) (ll : TypeLevel) → Set Γ ⊩⟨ l ⟩U A ^ ll = MaybeEmb l (λ l′ → Γ ⊩′⟨ l′ ⟩U A ^ ll) _⊩⟨_⟩ℕ_ : (Γ : Con Term) (l : TypeLevel) (A : Term) → Set Γ ⊩⟨ l ⟩ℕ A = MaybeEmb l (λ l′ → Γ ⊩ℕ A) _⊩⟨_⟩Empty_^_ : (Γ : Con Term) (l : TypeLevel) (A : Term) (ll : Level) → Set Γ ⊩⟨ l ⟩Empty A ^ ll = MaybeEmb l (λ l′ → Γ ⊩Empty A ^ ll) _⊩⟨_⟩ne_^[_,_] : (Γ : Con Term) (l : TypeLevel) (A : Term) (r : Relevance) (ll : Level) → Set Γ ⊩⟨ l ⟩ne A ^[ r , ll ] = MaybeEmb l (λ l′ → Γ ⊩ne A ^[ r , ll ]) _⊩⟨_⟩Π_^[_,_] : (Γ : Con Term) (l : TypeLevel) (A : Term) → Relevance → Level → Set Γ ⊩⟨ l ⟩Π A ^[ r , lΠ ] = MaybeEmb l (λ l′ → Γ ⊩′⟨ l′ ⟩Π A ^[ r , lΠ ]) _⊩⟨_⟩∃_^_ : (Γ : Con Term) (l : TypeLevel) (A : Term) (ll : Level) → Set Γ ⊩⟨ l ⟩∃ A ^ ll = MaybeEmb l (λ l′ → Γ ⊩′⟨ l′ ⟩∃ A ^ ll) -- Construct a general reducible type from a specific U-intr : ∀ {l Γ A ll } → (UA : Γ ⊩⟨ l ⟩U A ^ ll) → Γ ⊩⟨ l ⟩ A ^ [ ! , ll ] U-intr (noemb UA) = Uᵣ UA U-intr {l = ι ¹} (emb emb< x) = emb emb< (U-intr x) U-intr {l = ∞} (emb ∞< x) = emb ∞< (U-intr x) ℕ-intr : ∀ {l A Γ} → Γ ⊩⟨ l ⟩ℕ A → Γ ⊩⟨ l ⟩ A ^ [ ! , ι ⁰ ] ℕ-intr (noemb x) = ℕᵣ x ℕ-intr {l = ι ¹} (emb emb< x) = emb emb< (ℕ-intr x) ℕ-intr {l = ∞} (emb ∞< x) = emb ∞< (ℕ-intr x) Empty-intr : ∀ {l A Γ ll} → Γ ⊩⟨ l ⟩Empty A ^ ll → Γ ⊩⟨ l ⟩ A ^ [ % , ι ll ] Empty-intr (noemb x) = Emptyᵣ x Empty-intr {l = ι ¹} (emb emb< x) = emb emb< (Empty-intr x) Empty-intr {l = ∞} (emb ∞< x) = emb ∞< (Empty-intr x) ne-intr : ∀ {l A Γ r ll} → Γ ⊩⟨ l ⟩ne A ^[ r , ll ] → Γ ⊩⟨ l ⟩ A ^ [ r , ι ll ] ne-intr (noemb x) = ne x ne-intr {l = ι ¹} (emb emb< x) = emb emb< (ne-intr x) ne-intr {l = ∞} (emb ∞< x) = emb ∞< (ne-intr x) Π-intr : ∀ {l A Γ r ll} → Γ ⊩⟨ l ⟩Π A ^[ r , ll ] → Γ ⊩⟨ l ⟩ A ^ [ r , ι ll ] Π-intr (noemb x) = Πᵣ x Π-intr {l = ι ¹} (emb emb< x) = emb emb< (Π-intr x) Π-intr {l = ∞} (emb ∞< x) = emb ∞< (Π-intr x) ∃-intr : ∀ {l A Γ ll} → Γ ⊩⟨ l ⟩∃ A ^ ll → Γ ⊩⟨ l ⟩ A ^ [ % , ι ll ] ∃-intr (noemb x) = ∃ᵣ x ∃-intr {l = ι ¹} (emb emb< x) = emb emb< (∃-intr x) ∃-intr {l = ∞} (emb ∞< x) = emb ∞< (∃-intr x) -- Construct a specific reducible type from a general with some criterion U-elim′ : ∀ {l Γ A r l′ ll} → Γ ⊢ A ⇒* Univ r l′ ^ [ ! , ll ] → Γ ⊩⟨ l ⟩ A ^ [ ! , ll ] → Γ ⊩⟨ l ⟩U A ^ ll U-elim′ D (Uᵣ′ A ll r l l< e D') = noemb (Uᵣ r l l< e D') U-elim′ D (ℕᵣ D') = ⊥-elim (U≢ℕ (whrDet* (D , Uₙ) (red D' , ℕₙ))) U-elim′ D (ne′ K D' neK K≡K) = ⊥-elim (U≢ne neK (whrDet* (D , Uₙ) (red D' , ne neK))) U-elim′ D (Πᵣ′ rF lF lG _ _ F G D' ⊢F ⊢G A≡A [F] [G] G-ext) = ⊥-elim (U≢Π (whrDet* (D , Uₙ) (red D' , Πₙ))) U-elim′ {ι ¹} D (emb emb< x) with U-elim′ D x U-elim′ {ι ¹} D (emb emb< x) | noemb x₁ = emb emb< (noemb x₁) U-elim′ {ι ¹} D (emb emb< x) | emb () x₁ U-elim′ {∞} D (emb ∞< x) with U-elim′ D x U-elim′ {∞} D (emb ∞< x) | noemb x₁ = emb ∞< (noemb x₁) U-elim′ {∞} D (emb ∞< x) | emb <l x₁ = emb {l′ = ι ¹} ∞< (emb <l x₁) U-elim : ∀ {l Γ r l′ ll′} → Γ ⊩⟨ l ⟩ Univ r l′ ^ [ ! , ll′ ] → Γ ⊩⟨ l ⟩U Univ r l′ ^ ll′ U-elim [U] = U-elim′ (id (escape [U])) [U] ℕ-elim′ : ∀ {l A Γ ll} → Γ ⊢ A ⇒* ℕ ^ [ ! , ll ] → Γ ⊩⟨ l ⟩ A ^ [ ! , ll ] → Γ ⊩⟨ l ⟩ℕ A ℕ-elim′ D (Uᵣ′ _ _ _ _ l< PE.refl [[ _ , _ , d ]]) = ⊥-elim (U≢ℕ (whrDet* (d , Uₙ) (D , ℕₙ))) ℕ-elim′ D (ℕᵣ D′) = noemb D′ ℕ-elim′ D (ne′ K D′ neK K≡K) = ⊥-elim (ℕ≢ne neK (whrDet* (D , ℕₙ) (red D′ , ne neK))) ℕ-elim′ D (Πᵣ′ rF lF lG _ _ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) = ⊥-elim (ℕ≢Π (whrDet* (D , ℕₙ) (red D′ , Πₙ))) ℕ-elim′ {ι ¹} D (emb emb< x) with ℕ-elim′ D x ℕ-elim′ {ι ¹} D (emb emb< x) | noemb x₁ = emb emb< (noemb x₁) ℕ-elim′ {ι ¹} D (emb emb< x) | emb () x₁ ℕ-elim′ {∞} D (emb ∞< x) with ℕ-elim′ D x ℕ-elim′ {∞} D (emb ∞< x) | noemb x₁ = emb ∞< (noemb x₁) ℕ-elim′ {∞} D (emb ∞< x) | emb <l x₁ = emb {l′ = ι ¹} ∞< (emb <l x₁) ℕ-elim : ∀ {Γ l ll } → Γ ⊩⟨ l ⟩ ℕ ^ [ ! , ll ] → Γ ⊩⟨ l ⟩ℕ ℕ ℕ-elim [ℕ] = ℕ-elim′ (id (escape [ℕ])) [ℕ] Empty-elim′ : ∀ {l A ll Γ} → Γ ⊢ A ⇒* Empty ll ^ [ % , ι ll ] → Γ ⊩⟨ l ⟩ A ^ [ % , ι ll ] → Γ ⊩⟨ l ⟩Empty A ^ ll Empty-elim′ D (Emptyᵣ D′) = noemb D′ Empty-elim′ D (ne′ K D′ neK K≡K) = ⊥-elim (Empty≢ne neK (whrDet* (D , Emptyₙ) (red D′ , ne neK))) Empty-elim′ D (Πᵣ′ rF lF lG _ _ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) = ⊥-elim (Empty≢Π (whrDet* (D , Emptyₙ) (red D′ , Πₙ))) Empty-elim′ D (∃ᵣ′ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) = ⊥-elim (Empty≢∃ (whrDet* (D , Emptyₙ) (red D′ , ∃ₙ))) Empty-elim′ {ι ¹} D (emb emb< x) with Empty-elim′ D x Empty-elim′ {ι ¹} D (emb emb< x) | noemb x₁ = emb emb< (noemb x₁) Empty-elim′ {ι ¹} D (emb emb< x) | emb () x₁ Empty-elim′ {∞} D (emb ∞< x) with Empty-elim′ D x Empty-elim′ {∞} D (emb ∞< x) | noemb x₁ = emb ∞< (noemb x₁) Empty-elim′ {∞} D (emb ∞< x) | emb <l x₁ = emb {l′ = ι ¹} ∞< (emb <l x₁) Empty-elim : ∀ {Γ l ll } → Γ ⊩⟨ l ⟩ Empty ll ^ [ % , ι ll ] → Γ ⊩⟨ l ⟩Empty Empty ll ^ ll Empty-elim [Empty] = Empty-elim′ (id (escape [Empty])) [Empty] ne-elim′ : ∀ {l A Γ K r ll ll'} → Γ ⊢ A ⇒* K ^ [ r , ι ll ] → Neutral K → Γ ⊩⟨ l ⟩ A ^ [ r , ll' ] → ι ll PE.≡ ll' → Γ ⊩⟨ l ⟩ne A ^[ r , ll ] ne-elim′ D neK (Uᵣ′ _ _ _ _ l< PE.refl [[ _ , _ , d ]]) e = ⊥-elim (U≢ne neK (whrDet* (d , Uₙ) (D , ne neK))) ne-elim′ D neK (ℕᵣ D′) e = ⊥-elim (ℕ≢ne neK (whrDet* (red D′ , ℕₙ) (D , ne neK))) ne-elim′ D neK (ne (ne K D′ neK′ K≡K)) PE.refl = noemb (ne K D′ neK′ K≡K) ne-elim′ D neK (Πᵣ′ rF lF lG _ _ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) e = ⊥-elim (Π≢ne neK (whrDet* (red D′ , Πₙ) (D , ne neK))) ne-elim′ D neK (∃ᵣ′ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) e = ⊥-elim (∃≢ne neK (whrDet* (red D′ , ∃ₙ) (D , ne neK))) ne-elim′ D neK (Emptyᵣ D′) e = ⊥-elim (Empty≢ne neK (whrDet* (red D′ , Emptyₙ) (D , ne neK))) ne-elim′ {ι ¹} D neK (emb emb< x) e with ne-elim′ D neK x e ne-elim′ {ι ¹} D neK (emb emb< x) e | noemb x₁ = emb emb< (noemb x₁) ne-elim′ {ι ¹} D neK (emb emb< x) e | emb () x₁ ne-elim′ {∞} D neK (emb ∞< x) e with ne-elim′ D neK x e ne-elim′ {∞} D _ (emb ∞< x) e | noemb x₁ = emb ∞< (noemb x₁) ne-elim′ {∞} D _ (emb ∞< x) e | emb <l x₁ = emb {l′ = ι ¹} ∞< (emb <l x₁) ne-elim : ∀ {Γ l K r ll} → Neutral K → Γ ⊩⟨ l ⟩ K ^ [ r , ι ll ] → Γ ⊩⟨ l ⟩ne K ^[ r , ll ] ne-elim neK [K] = ne-elim′ (id (escape [K])) neK [K] PE.refl Π-elim′ : ∀ {l A Γ F G rF lF lG r lΠ} → Γ ⊢ A ⇒* Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ r , ι lΠ ] → Γ ⊩⟨ l ⟩ A ^ [ r , ι lΠ ] → Γ ⊩⟨ l ⟩Π A ^[ r , lΠ ] Π-elim′ D (Uᵣ′ _ _ _ _ l< X [[ _ , _ , d ]]) = ⊥-elim (U≢Π (whrDet* (d , Uₙ) (D , Πₙ))) Π-elim′ D (ℕᵣ D′) = ⊥-elim (ℕ≢Π (whrDet* (red D′ , ℕₙ) (D , Πₙ))) Π-elim′ D (Emptyᵣ D′) = ⊥-elim (Empty≢Π (whrDet* (red D′ , Emptyₙ) (D , Πₙ))) Π-elim′ D (ne′ K D′ neK K≡K) = ⊥-elim (Π≢ne neK (whrDet* (D , Πₙ) (red D′ , ne neK))) Π-elim′ D (Πᵣ′ rF lF lG lF≤ lG≤ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) = noemb (Πᵣ rF lF lG lF≤ lG≤ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) Π-elim′ D (∃ᵣ′ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) = ⊥-elim (Π≢∃ (whrDet* (D , Πₙ) (red D′ , ∃ₙ))) Π-elim′ {ι ¹} D (emb emb< x) with Π-elim′ D x Π-elim′ {ι ¹} D (emb emb< x) | noemb x₁ = emb emb< (noemb x₁) Π-elim′ {ι ¹} D (emb emb< x) | emb () x₁ Π-elim′ {∞} D (emb ∞< x) with Π-elim′ D x Π-elim′ {∞} D (emb ∞< x) | noemb x₁ = emb ∞< (noemb x₁) Π-elim′ {∞} D (emb ∞< x) | emb <l x₁ = emb {l′ = ι ¹} ∞< (emb <l x₁) Π-elim : ∀ {Γ F G rF lF lG r lΠ l} → Γ ⊩⟨ l ⟩ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ r , ι lΠ ] → Γ ⊩⟨ l ⟩Π Π F ^ rF ° lF ▹ G ° lG ° lΠ ^[ r , lΠ ] Π-elim [Π] = Π-elim′ (id (escape [Π])) [Π] ∃-elim′ : ∀ {l A Γ F G ll} → Γ ⊢ A ⇒* ∃ F ▹ G ^ [ % , ι ll ] → Γ ⊩⟨ l ⟩ A ^ [ % , ι ll ] → Γ ⊩⟨ l ⟩∃ A ^ ll ∃-elim′ D (Emptyᵣ D′) = ⊥-elim (Empty≢∃ (whrDet* (red D′ , Emptyₙ) (D , ∃ₙ))) ∃-elim′ D (ne′ K D′ neK K≡K) = ⊥-elim (∃≢ne neK (whrDet* (D , ∃ₙ) (red D′ , ne neK))) ∃-elim′ D (Πᵣ′ rF lF lG _ _ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) = ⊥-elim (Π≢∃ (whrDet* (red D′ , Πₙ) (D , ∃ₙ))) ∃-elim′ D (∃ᵣ′ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) = noemb (∃ᵣ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) ∃-elim′ {ι ¹} D (emb emb< x) with ∃-elim′ D x ∃-elim′ {ι ¹} D (emb emb< x) | noemb x₁ = emb emb< (noemb x₁) ∃-elim′ {ι ¹} D (emb emb< x) | emb () x₁ ∃-elim′ {∞} D (emb ∞< x) with ∃-elim′ D x ∃-elim′ {∞} D (emb ∞< x) | noemb x₁ = emb ∞< (noemb x₁) ∃-elim′ {∞} D (emb ∞< x) | emb <l x₁ = emb {l′ = ι ¹} ∞< (emb <l x₁) ∃-elim : ∀ {Γ F G l ll} → Γ ⊩⟨ l ⟩ ∃ F ▹ G ^ [ % , ι ll ] → Γ ⊩⟨ l ⟩∃ (∃ F ▹ G) ^ ll ∃-elim [∃] = ∃-elim′ (id (escape [∃])) [∃] -- Extract a type and a level from a maybe embedding extractMaybeEmb : ∀ {l ⊩⟨_⟩} → MaybeEmb l ⊩⟨_⟩ → ∃ λ l′ → ⊩⟨ l′ ⟩ extractMaybeEmb (noemb x) = _ , x extractMaybeEmb (emb <l x) = extractMaybeEmb x -- A view for constructor equality of types where embeddings are ignored data ShapeView Γ : ∀ l l′ A B r r' (p : Γ ⊩⟨ l ⟩ A ^ r) (q : Γ ⊩⟨ l′ ⟩ B ^ r') → Set where Uᵥ : ∀ {A B l l′ ll ll′} UA UB → ShapeView Γ l l′ A B [ ! , ll ] [ ! , ll′ ] (Uᵣ UA) (Uᵣ UB) ℕᵥ : ∀ {A B l l′} ℕA ℕB → ShapeView Γ l l′ A B [ ! , ι ⁰ ] [ ! , ι ⁰ ] (ℕᵣ ℕA) (ℕᵣ ℕB) Emptyᵥ : ∀ {A B l l′ ll ll'} EmptyA EmptyB → ShapeView Γ l l′ A B [ % , ι ll ] [ % , ι ll' ] (Emptyᵣ EmptyA) (Emptyᵣ EmptyB) ne : ∀ {A B l l′ r lr r' lr'} neA neB → ShapeView Γ l l′ A B [ r , ι lr ] [ r' , ι lr' ] (ne neA) (ne neB) Πᵥ : ∀ {A B l l′ r r' lΠ lΠ' } ΠA ΠB → ShapeView Γ l l′ A B [ r , ι lΠ ] [ r' , ι lΠ' ] (Πᵣ ΠA) (Πᵣ ΠB) ∃ᵥ : ∀ {A B l l′ ll ll'} ∃A ∃B → ShapeView Γ l l′ A B [ % , ι ll ] [ % , ι ll' ] (∃ᵣ ∃A) (∃ᵣ ∃B) emb⁰¹ : ∀ {A B r r' l p q} → ShapeView Γ (ι ⁰) l A B r r' p q → ShapeView Γ (ι ¹) l A B r r' (emb emb< p) q emb¹⁰ : ∀ {A B r r' l p q} → ShapeView Γ l (ι ⁰) A B r r' p q → ShapeView Γ l (ι ¹) A B r r' p (emb emb< q) emb¹∞ : ∀ {A B r r' l p q} → ShapeView Γ (ι ¹) l A B r r' p q → ShapeView Γ ∞ l A B r r' (emb ∞< p) q emb∞¹ : ∀ {A B r r' l p q} → ShapeView Γ l (ι ¹) A B r r' p q → ShapeView Γ l ∞ A B r r' p (emb ∞< q) -- Construct a shape view from an equality goodCases : ∀ {l l′ Γ A B r r'} ([A] : Γ ⊩⟨ l ⟩ A ^ r) ([B] : Γ ⊩⟨ l′ ⟩ B ^ r') → Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A] → ShapeView Γ l l′ A B r r' [A] [B] goodCases (Uᵣ UA) (Uᵣ UB) A≡B = Uᵥ UA UB goodCases (Uᵣ′ _ _ _ _ _ _ ⊢Γ) (ℕᵣ D) D' = ⊥-elim (U≢ℕ (whrDet* (D' , Uₙ) (red D , ℕₙ))) goodCases (Uᵣ′ _ _ _ _ _ _ ⊢Γ) (Emptyᵣ D) D' = ⊥-elim (U≢Empty (whrDet* (D' , Uₙ) (red D , Emptyₙ))) goodCases (Uᵣ′ _ _ _ _ _ _ ⊢Γ) (ne′ K D neK K≡K) D' = ⊥-elim (U≢ne neK (whrDet* (D' , Uₙ) (red D , ne neK))) goodCases (Uᵣ′ _ _ _ _ _ _ ⊢Γ) (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) D' = ⊥-elim (U≢Π (whrDet* (D' , Uₙ) (red D , Πₙ))) goodCases (Uᵣ′ _ _ _ _ _ _ ⊢Γ) (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) D' = ⊥-elim (U≢∃ (whrDet* (D' , Uₙ) (red D , ∃ₙ))) goodCases (ℕᵣ D) (Uᵣ′ _ _ _ _ _ _ D') A≡B = ⊥-elim (U≢ℕ (whrDet* (red D' , Uₙ) (A≡B , ℕₙ))) goodCases (ℕᵣ _) (Emptyᵣ D') D = ⊥-elim (ℕ≢Empty (whrDet* (D , ℕₙ) (red D' , Emptyₙ))) goodCases (ℕᵣ ℕA) (ℕᵣ ℕB) A≡B = ℕᵥ ℕA ℕB goodCases (ℕᵣ D) (ne′ K D₁ neK K≡K) A≡B = ⊥-elim (ℕ≢ne neK (whrDet* (A≡B , ℕₙ) (red D₁ , ne neK))) goodCases (ℕᵣ D) (Πᵣ′ rF lF lG _ _ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext) A≡B = ⊥-elim (ℕ≢Π (whrDet* (A≡B , ℕₙ) (red D₁ , Πₙ))) goodCases (ℕᵣ D) (∃ᵣ′ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext) A≡B = ⊥-elim (ℕ≢∃ (whrDet* (A≡B , ℕₙ) (red D₁ , ∃ₙ))) goodCases (Emptyᵣ D) (Uᵣ′ _ _ _ _ _ _ D') A≡B = ⊥-elim (U≢Empty (whrDet* (red D' , Uₙ) (A≡B , Emptyₙ))) goodCases (Emptyᵣ _) (ℕᵣ D') D = ⊥-elim (ℕ≢Empty (whrDet* (red D' , ℕₙ) (D , Emptyₙ))) goodCases (Emptyᵣ EmptyA) (Emptyᵣ EmptyB) A≡B = Emptyᵥ EmptyA EmptyB goodCases (Emptyᵣ D) (ne′ K D₁ neK K≡K) A≡B = ⊥-elim (Empty≢ne neK (whrDet* (A≡B , Emptyₙ) (red D₁ , ne neK))) goodCases (Emptyᵣ D) (Πᵣ′ rF lF lG _ _ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext) A≡B = ⊥-elim (Empty≢Π (whrDet* (A≡B , Emptyₙ) (red D₁ , Πₙ))) goodCases (Emptyᵣ D) (∃ᵣ′ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext) A≡B = ⊥-elim (Empty≢∃ (whrDet* (A≡B , Emptyₙ) (red D₁ , ∃ₙ))) goodCases (ne′ K D neK K≡K) (Uᵣ′ _ _ _ _ _ _ D') (ne₌ M D'' neM K≡M) = ⊥-elim (U≢ne neM (whrDet* (red D' , Uₙ) (red D'' , ne neM))) goodCases (ne′ K D neK K≡K) (ℕᵣ D₁) (ne₌ M D′ neM K≡M) = ⊥-elim (ℕ≢ne neM (whrDet* (red D₁ , ℕₙ) (red D′ , ne neM))) goodCases (ne′ K D neK K≡K) (Emptyᵣ D₁) (ne₌ M D′ neM K≡M) = ⊥-elim (Empty≢ne neM (whrDet* (red D₁ , Emptyₙ) (red D′ , ne neM))) goodCases (ne neA) (ne neB) A≡B = ne neA neB goodCases (ne′ K D neK K≡K) (Πᵣ′ rF lF lG _ _ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext) (ne₌ M D′ neM K≡M) = ⊥-elim (Π≢ne neM (whrDet* (red D₁ , Πₙ) (red D′ , ne neM))) goodCases (ne′ K D neK K≡K) (∃ᵣ′ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext) (ne₌ M D′ neM K≡M) = ⊥-elim (∃≢ne neM (whrDet* (red D₁ , ∃ₙ) (red D′ , ne neM))) goodCases (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Uᵣ′ _ _ _ _ _ _ D') (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (U≢Π (whrDet* (red D' , Uₙ) (D′ , Πₙ))) goodCases (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (ℕᵣ D₁) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (ℕ≢Π (whrDet* (red D₁ , ℕₙ) (D′ , Πₙ))) goodCases (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Emptyᵣ D₁) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (Empty≢Π (whrDet* (red D₁ , Emptyₙ) (D′ , Πₙ))) goodCases (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (ne′ K D₁ neK K≡K) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (Π≢ne neK (whrDet* (D′ , Πₙ) (red D₁ , ne neK))) goodCases (Πᵣ ΠA) (Πᵣ ΠB) A≡B = Πᵥ ΠA ΠB goodCases (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (∃ᵣ′ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (Π≢∃ (whrDet* (D′ , Πₙ) (red D₁ , ∃ₙ))) goodCases (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Uᵣ′ _ _ _ _ _ _ D') (∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (U≢∃ (whrDet* (red D' , Uₙ) (D′ , ∃ₙ))) goodCases (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (ℕᵣ D₁) (∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (ℕ≢∃ (whrDet* (red D₁ , ℕₙ) (D′ , ∃ₙ))) goodCases (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Emptyᵣ D₁) (∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (Empty≢∃ (whrDet* (red D₁ , Emptyₙ) (D′ , ∃ₙ))) goodCases (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (ne′ K D₁ neK K≡K) (∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (∃≢ne neK (whrDet* (D′ , ∃ₙ) (red D₁ , ne neK))) goodCases (∃ᵣ′ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁) (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) = ⊥-elim (Π≢∃ (whrDet* (red D , Πₙ) (D′ , ∃ₙ))) goodCases (∃ᵣ ∃A) (∃ᵣ ∃B) A≡B = ∃ᵥ ∃A ∃B goodCases {l} {ι ¹} [A] (emb emb< x) A≡B = emb¹⁰ (goodCases {l} {ι ⁰} [A] x A≡B) goodCases {l} {∞} [A] (emb ∞< x) A≡B = emb∞¹ (goodCases {l} {ι ¹} [A] x A≡B) goodCases {ι ¹} {l} (emb emb< x) [B] A≡B = emb⁰¹ (goodCases {ι ⁰} {l} x [B] A≡B) goodCases {∞} {l} (emb ∞< x) [B] A≡B = emb¹∞ (goodCases {ι ¹} {l} x [B] A≡B) -- Construct an shape view between two derivations of the same type goodCasesRefl : ∀ {l l′ Γ A r r'} ([A] : Γ ⊩⟨ l ⟩ A ^ r) ([A′] : Γ ⊩⟨ l′ ⟩ A ^ r') → ShapeView Γ l l′ A A r r' [A] [A′] goodCasesRefl [A] [A′] = goodCases [A] [A′] (reflEq [A]) -- A view for constructor equality between three types data ShapeView₃ Γ : ∀ l l′ l″ A B C r1 r2 r3 (p : Γ ⊩⟨ l ⟩ A ^ r1) (q : Γ ⊩⟨ l′ ⟩ B ^ r2) (r : Γ ⊩⟨ l″ ⟩ C ^ r3) → Set where Uᵥ : ∀ {A B C l l′ l″ ll ll′ ll″ } UA UB UC → ShapeView₃ Γ l l′ l″ A B C [ ! , ll ] [ ! , ll′ ] [ ! , ll″ ] (Uᵣ UA) (Uᵣ UB) (Uᵣ UC) ℕᵥ : ∀ {A B C l l′ l″} ℕA ℕB ℕC → ShapeView₃ Γ l l′ l″ A B C [ ! , ι ⁰ ] [ ! , ι ⁰ ] [ ! , ι ⁰ ] (ℕᵣ ℕA) (ℕᵣ ℕB) (ℕᵣ ℕC) Emptyᵥ : ∀ {A B C l l′ l″ ll ll′ ll″} EmptyA EmptyB EmptyC → ShapeView₃ Γ l l′ l″ A B C [ % , ι ll ] [ % , ι ll′ ] [ % , ι ll″ ] (Emptyᵣ EmptyA) (Emptyᵣ EmptyB) (Emptyᵣ EmptyC) ne : ∀ {A B C r1 r2 r3 l1 l2 l3 l l′ l″} neA neB neC → ShapeView₃ Γ l l′ l″ A B C [ r1 , ι l1 ] [ r2 , ι l2 ] [ r3 , ι l3 ] (ne neA) (ne neB) (ne neC) Πᵥ : ∀ {A B C r1 r2 r3 lΠ1 lΠ2 lΠ3 l l′ l″} ΠA ΠB ΠC → ShapeView₃ Γ l l′ l″ A B C [ r1 , ι lΠ1 ] [ r2 , ι lΠ2 ] [ r3 , ι lΠ3 ] (Πᵣ ΠA) (Πᵣ ΠB) (Πᵣ ΠC) ∃ᵥ : ∀ {A B C l l′ l″ ll ll' ll''} ΠA ΠB ΠC → ShapeView₃ Γ l l′ l″ A B C [ % , ι ll ] [ % , ι ll' ] [ % , ι ll'' ] (∃ᵣ ΠA) (∃ᵣ ΠB) (∃ᵣ ΠC) emb⁰¹¹ : ∀ {A B C l l′ r1 r2 r3 p q r} → ShapeView₃ Γ (ι ⁰) l l′ A B C r1 r2 r3 p q r → ShapeView₃ Γ (ι ¹) l l′ A B C r1 r2 r3 (emb emb< p) q r emb¹⁰¹ : ∀ {A B C l l′ r1 r2 r3 p q r} → ShapeView₃ Γ l (ι ⁰) l′ A B C r1 r2 r3 p q r → ShapeView₃ Γ l (ι ¹) l′ A B C r1 r2 r3 p (emb emb< q) r emb¹¹⁰ : ∀ {A B C l l′ r1 r2 r3 p q r} → ShapeView₃ Γ l l′ (ι ⁰) A B C r1 r2 r3 p q r → ShapeView₃ Γ l l′ (ι ¹) A B C r1 r2 r3 p q (emb emb< r) emb¹∞∞ : ∀ {A B C l l′ r1 r2 r3 p q r} → ShapeView₃ Γ (ι ¹) l l′ A B C r1 r2 r3 p q r → ShapeView₃ Γ ∞ l l′ A B C r1 r2 r3 (emb ∞< p) q r emb∞¹∞ : ∀ {A B C l l′ r1 r2 r3 p q r} → ShapeView₃ Γ l (ι ¹) l′ A B C r1 r2 r3 p q r → ShapeView₃ Γ l ∞ l′ A B C r1 r2 r3 p (emb ∞< q) r emb∞∞¹ : ∀ {A B C l l′ r1 r2 r3 p q r} → ShapeView₃ Γ l l′ (ι ¹) A B C r1 r2 r3 p q r → ShapeView₃ Γ l l′ ∞ A B C r1 r2 r3 p q (emb ∞< r) -- Combines two two-way views into a three-way view combine : ∀ {Γ l l′ l″ l‴ A B C r1 r2 r2' r3 [A] [B] [B]′ [C]} → ShapeView Γ l l′ A B r1 r2 [A] [B] → ShapeView Γ l″ l‴ B C r2' r3 [B]′ [C] → ShapeView₃ Γ l l′ l‴ A B C r1 r2 r3 [A] [B] [C] combine (Uᵥ UA UB) (Uᵥ UB' UC) = Uᵥ UA UB UC combine (Uᵥ UA (Uᵣ r l′ l< PE.refl D)) (ℕᵥ ℕA ℕB) = ⊥-elim (U≢ℕ (whrDet* (red D , Uₙ) (red ℕA , ℕₙ))) combine (Uᵥ UA (Uᵣ r l′ l< PE.refl D)) (Emptyᵥ EmptyA EmptyB) = ⊥-elim (U≢Empty (whrDet* (red D , Uₙ) (red EmptyA , Emptyₙ))) combine (Uᵥ UA (Uᵣ r l′ l< PE.refl D)) (ne (ne K D' neK K≡K) neB) = ⊥-elim (U≢ne neK (whrDet* (red D , Uₙ) (red D' , ne neK))) combine (Uᵥ UA (Uᵣ r l′ l< PE.refl D)) (Πᵥ (Πᵣ rF lF lG _ _ F G D' ⊢F ⊢G A≡A [F] [G] G-ext) ΠB) = ⊥-elim (U≢Π (whrDet* (red D , Uₙ) (red D' , Πₙ))) combine (Uᵥ UA (Uᵣ r l′ l< PE.refl D)) (∃ᵥ (∃ᵣ F G D' ⊢F ⊢G A≡A [F] [G] G-ext) ∃B) = ⊥-elim (U≢∃ (whrDet* (red D , Uₙ) (red D' , ∃ₙ))) combine (ℕᵥ ℕA ℕB) (Uᵥ (Uᵣ r l′ l< PE.refl D) UB) = ⊥-elim (U≢ℕ (whrDet* (red D , Uₙ) (red ℕB , ℕₙ))) combine (ℕᵥ ℕA ℕB) (Emptyᵥ EmptyA EmptyB) = ⊥-elim (ℕ≢Empty (whrDet* (red ℕB , ℕₙ) (red EmptyA , Emptyₙ))) combine (ℕᵥ ℕA₁ ℕB₁) (ℕᵥ ℕA ℕB) = ℕᵥ ℕA₁ ℕB₁ ℕB combine (ℕᵥ ℕA ℕB) (ne (ne K D neK K≡K) neB) = ⊥-elim (ℕ≢ne neK (whrDet* (red ℕB , ℕₙ) (red D , ne neK))) combine (ℕᵥ ℕA ℕB) (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ΠB) = ⊥-elim (ℕ≢Π (whrDet* (red ℕB , ℕₙ) (red D , Πₙ))) combine (ℕᵥ ℕA ℕB) (∃ᵥ (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ∃B) = ⊥-elim (ℕ≢∃ (whrDet* (red ℕB , ℕₙ) (red D , ∃ₙ))) combine (Emptyᵥ EmptyA EmptyB) (Uᵥ (Uᵣ r l′ l< PE.refl D) UB) = ⊥-elim (U≢Empty (whrDet* (red D , Uₙ) (red EmptyB , Emptyₙ))) combine (Emptyᵥ EmptyA EmptyB) (ℕᵥ ℕA ℕB) = ⊥-elim (Empty≢ℕ (whrDet* (red EmptyB , Emptyₙ) (red ℕA , ℕₙ))) combine (Emptyᵥ EmptyA₁ EmptyB₁) (Emptyᵥ EmptyA EmptyB) = Emptyᵥ EmptyA₁ EmptyB₁ EmptyB combine (Emptyᵥ EmptyA EmptyB) (ne (ne K D neK K≡K) neB) = ⊥-elim (Empty≢ne neK (whrDet* (red EmptyB , Emptyₙ) (red D , ne neK))) combine (Emptyᵥ EmptyA EmptyB) (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ΠB) = ⊥-elim (Empty≢Π (whrDet* (red EmptyB , Emptyₙ) (red D , Πₙ))) combine (Emptyᵥ EmptyA EmptyB) (∃ᵥ (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ∃B) = ⊥-elim (Empty≢∃ (whrDet* (red EmptyB , Emptyₙ) (red D , ∃ₙ))) combine (ne neA (ne K D' neK K≡K)) (Uᵥ (Uᵣ r l′ l< PE.refl D) UB) = ⊥-elim (U≢ne neK (whrDet* (red D , Uₙ) (red D' , ne neK))) combine (ne neA (ne K D neK K≡K)) (ℕᵥ ℕA ℕB) = ⊥-elim (ℕ≢ne neK (whrDet* (red ℕA , ℕₙ) (red D , ne neK))) combine (ne neA (ne K D neK K≡K)) (Emptyᵥ EmptyA EmptyB) = ⊥-elim (Empty≢ne neK (whrDet* (red EmptyA , Emptyₙ) (red D , ne neK))) combine (ne neA₁ neB₁) (ne neA neB) = ne neA₁ neB₁ neB combine (ne neA (ne K D₁ neK K≡K)) (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ΠB) = ⊥-elim (Π≢ne neK (whrDet* (red D , Πₙ) (red D₁ , ne neK))) combine (ne neA (ne K D₁ neK K≡K)) (∃ᵥ (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ∃B) = ⊥-elim (∃≢ne neK (whrDet* (red D , ∃ₙ) (red D₁ , ne neK))) combine (Πᵥ ΠA (Πᵣ rF lF lG _ _ F G D' ⊢F ⊢G A≡A [F] [G] G-ext)) (Uᵥ (Uᵣ r l′ l< PE.refl D) UB) = ⊥-elim (U≢Π (whrDet* (red D , Uₙ) (red D' , Πₙ))) combine (Πᵥ ΠA (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (ℕᵥ ℕA ℕB) = ⊥-elim (ℕ≢Π (whrDet* (red ℕA , ℕₙ) (red D , Πₙ))) combine (Πᵥ ΠA (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (Emptyᵥ EmptyA EmptyB) = ⊥-elim (Empty≢Π (whrDet* (red EmptyA , Emptyₙ) (red D , Πₙ))) combine (Πᵥ ΠA (Πᵣ rF lF lG _ _ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext)) (ne (ne K D neK K≡K) neB) = ⊥-elim (Π≢ne neK (whrDet* (red D₁ , Πₙ) (red D , ne neK))) combine (Πᵥ ΠA₁ ΠB₁) (Πᵥ ΠA ΠB) = Πᵥ ΠA₁ ΠB₁ ΠB combine (Πᵥ ΠA (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (∃ᵥ (∃ᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁) ∃B) = ⊥-elim (Π≢∃ (whrDet* (red D , Πₙ) (red D₁ , ∃ₙ))) combine (∃ᵥ ∃A (∃ᵣ F G D' ⊢F ⊢G A≡A [F] [G] G-ext)) (Uᵥ (Uᵣ r l′ l< PE.refl D) UB) = ⊥-elim (U≢∃ (whrDet* (red D , Uₙ) (red D' , ∃ₙ))) combine (∃ᵥ ∃A (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (ℕᵥ ℕA ℕB) = ⊥-elim (ℕ≢∃ (whrDet* (red ℕA , ℕₙ) (red D , ∃ₙ))) combine (∃ᵥ ∃A (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (Emptyᵥ EmptyA EmptyB) = ⊥-elim (Empty≢∃ (whrDet* (red EmptyA , Emptyₙ) (red D , ∃ₙ))) combine (∃ᵥ ∃A (∃ᵣ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext)) (ne (ne K D neK K≡K) neB) = ⊥-elim (∃≢ne neK (whrDet* (red D₁ , ∃ₙ) (red D , ne neK))) combine (∃ᵥ ΠA (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (Πᵥ (Πᵣ rF₁ lF₁ lG₁ _ _ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁) ∃B) = ⊥-elim (Π≢∃ (whrDet* (red D₁ , Πₙ) (red D , ∃ₙ))) combine (∃ᵥ ∃A ∃B) (∃ᵥ ∃A₁ ∃B₁) = ∃ᵥ ∃A ∃B ∃B₁ combine (emb⁰¹ [AB]) [BC] = emb⁰¹¹ (combine [AB] [BC]) combine (emb¹⁰ [AB]) [BC] = emb¹⁰¹ (combine [AB] [BC]) combine [AB] (emb⁰¹ [BC]) = combine [AB] [BC] combine [AB] (emb¹⁰ [BC]) = emb¹¹⁰ (combine [AB] [BC]) combine (emb¹∞ [AB]) [BC] = emb¹∞∞ (combine [AB] [BC]) combine (emb∞¹ [AB]) [BC] = emb∞¹∞ (combine [AB] [BC]) combine [AB] (emb¹∞ [BC]) = combine [AB] [BC] combine [AB] (emb∞¹ [BC]) = emb∞∞¹ (combine [AB] [BC])
53.544186
146
0.493007
c5739c3a79b770e5a4046ffc1c28cf6c354c8a90
802
agda
Agda
Cubical/Data/InfNat/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/InfNat/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/InfNat/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-} module Cubical.Data.InfNat.Base where open import Cubical.Data.Nat as ℕ using (ℕ) open import Cubical.Core.Primitives data ℕ+∞ : Type₀ where ∞ : ℕ+∞ fin : ℕ → ℕ+∞ suc : ℕ+∞ → ℕ+∞ suc ∞ = ∞ suc (fin n) = fin (ℕ.suc n) zero : ℕ+∞ zero = fin ℕ.zero caseInfNat : ∀ {ℓ} → {A : Type ℓ} → (aF aI : A) → ℕ+∞ → A caseInfNat aF aI (fin n) = aF caseInfNat aF aI ∞ = aI infixl 6 _+_ _+_ : ℕ+∞ → ℕ+∞ → ℕ+∞ ∞ + m = ∞ fin n + ∞ = ∞ fin n + fin m = fin (n ℕ.+ m) infixl 7 _*_ _*_ : ℕ+∞ → ℕ+∞ → ℕ+∞ fin m * fin n = fin (m ℕ.* n) ∞ * fin ℕ.zero = zero fin ℕ.zero * ∞ = zero ∞ * ∞ = ∞ ∞ * fin (ℕ.suc _) = ∞ fin (ℕ.suc _) * ∞ = ∞
21.675676
67
0.450125
c5746e01e318061c86143675460246c4881d6d4f
18,695
agda
Agda
agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex1-HC.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
36
2015-01-29T14:37:15.000Z
2021-07-30T06:55:03.000Z
agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex1-HC.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
null
null
null
agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex1-HC.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
8
2015-04-13T21:40:15.000Z
2021-09-21T15:58:10.000Z
{-# OPTIONS --allow-unsolved-metas #-} ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- CS410 2017/18 Exercise 1 VECTORS AND FRIENDS (worth 25%) ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- NOTE (19/9/17) This file is currently incomplete: more will arrive on -- GitHub. -- MARK SCHEME (transcribed from paper): the (m) numbers add up to slightly -- more than 25, so should be taken as the maximum number of marks losable on -- the exercise. In fact, I did mark it negatively, but mostly because it was -- done so well (with Agda's help) that it was easier to find the errors. ------------------------------------------------------------------------------ -- Dependencies ------------------------------------------------------------------------------ open import CS410-Prelude ------------------------------------------------------------------------------ -- Vectors ------------------------------------------------------------------------------ data Vec (X : Set) : Nat -> Set where -- like lists, but length-indexed [] : Vec X zero _,-_ : {n : Nat} -> X -> Vec X n -> Vec X (suc n) infixr 4 _,-_ -- the "cons" operator associates to the right -- I like to use the asymmetric ,- to remind myself that the element is to -- the left and the rest of the list is to the right. -- Vectors are useful when there are important length-related safety -- properties. ------------------------------------------------------------------------------ -- Heads and Tails ------------------------------------------------------------------------------ -- We can rule out nasty head and tail errors by insisting on nonemptiness! --??--1.1-(2)----------------------------------------------------------------- vHead : {X : Set}{n : Nat} -> Vec X (suc n) -> X vHead (x ,- _) = x vTail : {X : Set}{n : Nat} -> Vec X (suc n) -> Vec X n vTail (_ ,- xs) = xs vHeadTailFact : {X : Set}{n : Nat}(xs : Vec X (suc n)) -> (vHead xs ,- vTail xs) == xs vHeadTailFact (x ,- xs) = refl (x ,- xs) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Concatenation and its Inverse ------------------------------------------------------------------------------ --??--1.2-(2)----------------------------------------------------------------- _+V_ : {X : Set}{m n : Nat} -> Vec X m -> Vec X n -> Vec X (m +N n) [] +V ys = ys (x ,- xs) +V ys = x ,- xs +V ys infixr 4 _+V_ vChop : {X : Set}(m : Nat){n : Nat} -> Vec X (m +N n) -> Vec X m * Vec X n vChop zero xs = [] , xs vChop (suc m) (x ,- xs) with vChop m xs ... | vm , vn = (x ,- vm) , vn vChopAppendFact : {X : Set}{m n : Nat}(xs : Vec X m)(ys : Vec X n) -> vChop m (xs +V ys) == (xs , ys) vChopAppendFact [] ys = refl ([] , ys) vChopAppendFact (x ,- xs) ys rewrite vChopAppendFact xs ys = refl ((x ,- xs) , ys) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Map, take I ------------------------------------------------------------------------------ -- Implement the higher-order function that takes an operation on -- elements and does it to each element of a vector. Use recursion -- on the vector. -- Note that the type tells you the size remains the same. -- Show that if the elementwise function "does nothing", neither does -- its vMap. "map of identity is identity" -- Show that two vMaps in a row can be collapsed to just one, or -- "composition of maps is map of compositions" --??--1.3-(2)----------------------------------------------------------------- vMap : {X Y : Set} -> (X -> Y) -> {n : Nat} -> Vec X n -> Vec Y n vMap f [] = [] vMap f (x ,- xs) = f x ,- vMap f xs vMapIdFact : {X : Set}{f : X -> X}(feq : (x : X) -> f x == x) -> {n : Nat}(xs : Vec X n) -> vMap f xs == xs vMapIdFact feq [] = refl [] vMapIdFact feq (x ,- xs) rewrite vMapIdFact feq xs | feq x = refl (x ,- xs) vMapCpFact : {X Y Z : Set}{f : Y -> Z}{g : X -> Y}{h : X -> Z} (heq : (x : X) -> f (g x) == h x) -> {n : Nat}(xs : Vec X n) -> vMap f (vMap g xs) == vMap h xs vMapCpFact heq [] = refl [] vMapCpFact {_}{_}{_}{f} {g} {h} heq (x ,- xs) rewrite heq x | vMapCpFact {_}{_}{_}{f} {g} {h} heq xs = refl (h x ,- vMap h xs) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- vMap and +V ------------------------------------------------------------------------------ -- Show that if you've got two vectors of Xs and a function from X to Y, -- and you want to concatenate and map, it doesn't matter which you do -- first. --??--1.4-(1)----------------------------------------------------------------- vMap+VFact : {X Y : Set}(f : X -> Y) -> {m n : Nat}(xs : Vec X m)(xs' : Vec X n) -> vMap f (xs +V xs') == (vMap f xs +V vMap f xs') vMap+VFact f [] xs' = refl (vMap f xs') vMap+VFact f (x ,- xs) xs' rewrite vMap+VFact f xs xs' = refl (f x ,- vMap f xs +V vMap f xs') --??-------------------------------------------------------------------------- -- Think about what you could prove, relating vMap with vHead, vTail, vChop... -- Now google "Philip Wadler" "Theorems for Free" -- TODO ------------------------------------------------------------------------------ -- Applicative Structure (giving mapping and zipping cheaply) ------------------------------------------------------------------------------ --??--1.5-(2)----------------------------------------------------------------- -- HINT: you will need to override the default invisibility of n to do this. -- HC : replicate vPure : {X : Set} -> X -> {n : Nat} -> Vec X n vPure x {zero} = [] vPure x {suc n} = x ,- vPure x {n} _$V_ : {X Y : Set}{n : Nat} -> Vec (X -> Y) n -> Vec X n -> Vec Y n [] $V [] = [] f ,- fs $V x ,- xs = f x ,- (fs $V xs) infixl 3 _$V_ -- "Application associates to the left, -- rather as we all did in the sixties." (Roger Hindley) -- Pattern matching and recursion are forbidden for the next two tasks. -- implement vMap again, but as a one-liner vec : {X Y : Set} -> (X -> Y) -> {n : Nat} -> Vec X n -> Vec Y n vec f xs = vPure f $V xs -- implement the operation which pairs up corresponding elements vZip : {X Y : Set}{n : Nat} -> Vec X n -> Vec Y n -> Vec (X * Y) n vZip xs ys = vec (_,_) xs $V ys --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Applicative Laws ------------------------------------------------------------------------------ -- According to "Applicative programming with effects" by -- Conor McBride and Ross Paterson -- some laws should hold for applicative functors. -- Check that this is the case. --??--1.6-(2)----------------------------------------------------------------- vIdentity : {X : Set}{f : X -> X}(feq : (x : X) -> f x == x) -> {n : Nat}(xs : Vec X n) -> (vPure f $V xs) == xs vIdentity feq [] = refl [] vIdentity feq (x ,- xs) rewrite vIdentity feq xs | feq x = refl (x ,- xs) vHomomorphism : {X Y : Set}(f : X -> Y)(x : X) -> {n : Nat} -> (vPure f $V vPure x) == vPure (f x) {n} vHomomorphism f x {zero} = refl [] vHomomorphism f x {suc n} rewrite vHomomorphism f x {n} = refl (f x ,- vPure (f x)) vInterchange : {X Y : Set}{n : Nat}(fs : Vec (X -> Y) n)(x : X) -> (fs $V vPure x) == (vPure (_$ x) $V fs) vInterchange [] x = refl [] vInterchange (f ,- fs) x rewrite vInterchange fs x = refl (f x ,- (vPure (λ x→y → x→y x) $V fs)) vComposition : {X Y Z : Set}{n : Nat} (fs : Vec (Y -> Z) n)(gs : Vec (X -> Y) n)(xs : Vec X n) -> (vPure _<<_ $V fs $V gs $V xs) == (fs $V (gs $V xs)) vComposition [] [] [] = refl [] vComposition (f ,- fs) (g ,- gs) (x ,- xs) rewrite vComposition fs gs xs = refl (f (g x) ,- (fs $V (gs $V xs))) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Order-Preserving Embeddings (also known in the business as "thinnings") ------------------------------------------------------------------------------ -- What have these to do with Pascal's Triangle? -- how to choose N things from M things data _<=_ : Nat -> Nat -> Set where oz : zero <= zero -- stop os : {n m : Nat} -> n <= m -> suc n <= suc m -- take this one and keep going o' : {n m : Nat} -> n <= m -> n <= suc m -- skip this one and keep going refl-<= : (n : Nat) -> n <= n refl-<= zero = oz refl-<= (suc n) = os (refl-<= n) trans-<= : {n m p : Nat} -> n <= m -> m <= p -> n <= p trans-<= oz zero<=p = zero<=p trans-<= (os n<=m) (os sucm<=p) = os (trans-<= n<=m sucm<=p) trans-<= (os n<=m) (o' sucm<=p) = os (trans-<= (o' n<=m) sucm<=p) trans-<= (o' n<=m) (os m<=p) = o' (trans-<= n<=m m<=p) trans-<= (o' n<=m) (o' m<=p) = o' (trans-<= (o' n<=m) m<=p) <=-suc : (x : Nat) -> x <= suc x <=-suc zero = o' oz <=-suc (suc x) = os (<=-suc x) n<=m→sucn<=sucm : {n m : Nat} → n <= m -> suc n <= suc m n<=m→sucn<=sucm oz = os oz n<=m→sucn<=sucm (os n<=m) = os (n<=m→sucn<=sucm n<=m) n<=m→sucn<=sucm (o' n<=m) = o' (n<=m→sucn<=sucm n<=m) -- Find all the values in each of the following <= types. -- This is a good opportunity to learn to use C-c C-a with the -l option -- (a.k.a. "google the type" without "I feel lucky") -- The -s n option also helps. --??--1.7-(1)----------------------------------------------------------------- all0<=4 : Vec (0 <= 4) 1 all0<=4 = o' (o' (o' (o' oz))) ,- [] all1<=4 : Vec (1 <= 4) 1 all1<=4 = os (o' (o' (o' oz))) ,- [] all2<=4 : Vec (2 <= 4) 1 all2<=4 = os (os (o' (o' oz))) ,- [] all3<=4 : Vec (3 <= 4) 1 all3<=4 = os (os (os (o' oz))) ,- [] all4<=4 : Vec (4 <= 4) 1 all4<=4 = os (os (os (os oz))) ,- [] -- Prove the following. A massive case analysis "rant" is fine. no5<=4 : 5 <= 4 -> Zero no5<=4 (os (os (os (os ())))) no5<=4 (os (os (os (o' ())))) no5<=4 (os (os (o' (os ())))) no5<=4 (os (os (o' (o' ())))) no5<=4 (os (o' (os (os ())))) no5<=4 (os (o' (os (o' ())))) no5<=4 (os (o' (o' (os ())))) no5<=4 (os (o' (o' (o' ())))) no5<=4 (o' (os (os (os ())))) no5<=4 (o' (os (os (o' ())))) no5<=4 (o' (os (o' (os ())))) no5<=4 (o' (os (o' (o' ())))) no5<=4 (o' (o' (os (os ())))) no5<=4 (o' (o' (os (o' ())))) no5<=4 (o' (o' (o' (os ())))) no5<=4 (o' (o' (o' (o' ())))) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Order-Preserving Embeddings Select From Vectors ------------------------------------------------------------------------------ -- Use n <= m to encode the choice of n elements from an m-Vector. -- The os constructor tells you to take the next element of the vector; -- the o' constructor tells you to omit the next element of the vector. --??--1.8-(2)----------------------------------------------------------------- _<?=_ : {X : Set}{n m : Nat} -> n <= m -> Vec X m -> Vec X n oz <?= [] = [] os th <?= (x ,- xs) = x ,- th <?= xs o' th <?= (x ,- xs) = th <?= xs vn4 : Vec Nat 4 vn4 = os (os (os (os oz))) <?= (1 ,- 2 ,- 3 ,- 4 ,- []) _ : vn4 == (1 ,- 2 ,- 3 ,- 4 ,- []) _ = refl (1 ,- 2 ,- 3 ,- 4 ,- []) vn3 : Vec Nat 3 vn3 = o' (os (o' (os (o' (os oz))))) <?= (1 ,- 2 ,- 3 ,- 4 ,- 5 ,- 6 ,- []) _ : vn3 == (2 ,- 4 ,- 6 ,- []) _ = refl (2 ,- 4 ,- 6 ,- []) vn2 : Vec Nat 2 vn2 = o' (os (o' (os oz))) <?= (1 ,- 2 ,- 3 ,- 4 ,- []) _ : vn2 == (2 ,- 4 ,- []) _ = refl (2 ,- 4 ,- []) -- it shouldn't matter whether you map then select or select then map vMap<?=Fact : {X Y : Set}(f : X -> Y) {n m : Nat}(th : n <= m)(xs : Vec X m) -> vMap f (th <?= xs) == (th <?= vMap f xs) vMap<?=Fact f oz [] = refl [] vMap<?=Fact f (os th) (x ,- xs) rewrite vMap<?=Fact f th xs = refl (f x ,- (th <?= vMap f xs)) vMap<?=Fact f (o' th) (x ,- xs) rewrite vMap<?=Fact f th xs = refl (th <?= vMap f xs) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Our Favourite Thinnings ------------------------------------------------------------------------------ -- Construct the identity thinning and the empty thinning. --??--1.9-(1)----------------------------------------------------------------- oi : {n : Nat} -> n <= n oi {zero} = oz oi {suc n} = os oi oe : {n : Nat} -> 0 <= n oe {zero} = oz oe {suc n} = o' oe vnoi : Vec Nat 4 vnoi = oi <?= (1 ,- 2 ,- 3 ,- 4 ,- []) _ : vnoi == (1 ,- 2 ,- 3 ,- 4 ,- []) _ = refl (1 ,- 2 ,- 3 ,- 4 ,- []) vnoe : Vec Nat 0 vnoe = oe <?= (1 ,- 2 ,- 3 ,- 4 ,- []) _ : vnoe == [] _ = refl [] --??-------------------------------------------------------------------------- -- Show that all empty thinnings are equal to yours. --??--1.10-(1)---------------------------------------------------------------- oeUnique : {n : Nat}(th : 0 <= n) -> th == oe oeUnique oz = refl oz oeUnique (o' i) rewrite oeUnique i = refl (o' oe) --??-------------------------------------------------------------------------- -- Show that there are no thinnings of form big <= small (TRICKY) -- Then show that all the identity thinnings are equal to yours. -- Note that you can try the second even if you haven't finished the first. -- HINT: you WILL need to expose the invisible numbers. -- HINT: check CS410-Prelude for a reminder of >= --??--1.11-(3)---------------------------------------------------------------- oTooBig : {n m : Nat} -> n >= m -> suc n <= m -> Zero oTooBig {n} {m} n>=m th = {!!} oiUnique : {n : Nat}(n<=n : n <= n) -> n<=n == oi oiUnique {zero} oz = refl oz oiUnique {suc n} (os n<=n) rewrite oiUnique n<=n = refl (os oi) oiUnique {suc n} (o' sucn<=n) = {!!} --??-------------------------------------------------------------------------- -- Show that the identity thinning selects the whole vector --??--1.12-(1)---------------------------------------------------------------- id-<?= : {X : Set}{n : Nat}(xs : Vec X n) -> (oi <?= xs) == xs id-<?= [] = refl [] id-<?= (x ,- xs) rewrite id-<?= xs = refl (x ,- xs) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Composition of Thinnings ------------------------------------------------------------------------------ -- Define the composition of thinnings and show that selecting by a -- composite thinning is like selecting then selecting again. -- A small bonus applies to minimizing the length of the proof. -- To collect the bonus, you will need to think carefully about -- how to make the composition as *lazy* as possible. --??--1.13-(3)---------------------------------------------------------------- _o>>_ : {p n m : Nat} -> p <= n -> n <= m -> p <= m p<=zero o>> oz = p<=zero p<=sucn o>> os n<=m = trans-<= p<=sucn (n<=m→sucn<=sucm n<=m) p<=n o>> o' n<=m = trans-<= p<=n (o' n<=m) -- empty thinning returns an empty vector oe-<?= : {X : Set}{n : Nat}(xs : Vec X n) -> (oe <?= xs) == [] oe-<?= [] = refl [] oe-<?= (x ,- xs) rewrite oe-<?= xs = refl [] cp-<?= : {p n m : Nat}(p<=n : p <= n)(n<=m : n <= m) -> {X : Set}(xs : Vec X m) -> ((p<=n o>> n<=m) <?= xs) == (p<=n <?= (n<=m <?= xs)) cp-<?= oz oz [] = refl [] cp-<?= oz (o' zero<=m) (x ,- xs) rewrite oeUnique zero<=m | oe-<?= xs = refl [] cp-<?= (os p<=n) (os n<=m) (x ,- xs) = {!!} cp-<?= (os p<=n) (o' n<=m) xs = {!!} cp-<?= (o' p<=n) (os n<=m) xs = {!!} cp-<?= (o' p<=n) (o' n<=m) xs = {!!} zero<=4 : zero <= 4 zero<=4 = o' (o' (o' (o' oz))) 1<=4 : 1 <= 4 1<=4 = os (o' (o' (o' oz))) v04 : Vec Nat zero v04 = zero<=4 <?= (1 ,- 2 ,- 3 ,- 4 ,- []) v14 : Vec Nat 1 v14 = 1<=4 <?= (1 ,- 2 ,- 3 ,- 4 ,- []) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Thinning Dominoes ------------------------------------------------------------------------------ --??--1.14-(3)---------------------------------------------------------------- idThen-o>> : {n m : Nat}(n<=m : n <= m) -> (oi o>> n<=m) == n<=m idThen-o>> oz = refl oz idThen-o>> (os n<=m) = {!!} idThen-o>> (o' n<=m) = {!!} idAfter-o>> : {n m : Nat}(n<=m : n <= m) -> (n<=m o>> oi) == n<=m idAfter-o>> n<=m = {!!} assoc-o>> : {q p n m : Nat}(th0 : q <= p)(th1 : p <= n)(th2 : n <= m) -> ((th0 o>> th1) o>> th2) == (th0 o>> (th1 o>> th2)) assoc-o>> th0 th1 th2 = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Vectors as Arrays ------------------------------------------------------------------------------ -- We can use 1 <= n as the type of bounded indices into a vector and do -- a kind of "array projection". First we select a 1-element vector from -- the n-element vector, then we take its head to get the element out. vProject : {n : Nat}{X : Set} -> Vec X n -> 1 <= n -> X vProject xs i = vHead (i <?= xs) -- Your (TRICKY) mission is to reverse the process, tabulating a function -- from indices as a vector. Then show that these operations are inverses. --??--1.15-(3)---------------------------------------------------------------- -- HINT: composition of functions vTabulate : {n : Nat}{X : Set} -> (1 <= n -> X) -> Vec X n vTabulate {n} f = {!!} -- This should be easy if vTabulate is correct. vTabulateProjections : {n : Nat}{X : Set}(xs : Vec X n) -> vTabulate (vProject xs) == xs vTabulateProjections xs = {!!} -- HINT: oeUnique vProjectFromTable : {n : Nat}{X : Set}(f : 1 <= n -> X)(i : 1 <= n) -> vProject (vTabulate f) i == f i vProjectFromTable f i = {!!} --??--------------------------------------------------------------------------
36.021195
96
0.383365
18271ec96129fb954a4206fe709dd02717173474
245
agda
Agda
src/Algebra/Linear.agda
felko/linear-algebra
d87c5a1eb5dd0569238272e67bce1899616b789a
[ "MIT" ]
15
2019-11-02T14:11:00.000Z
2020-12-30T06:18:08.000Z
src/Algebra/Linear.agda
felko/linear-algebra
d87c5a1eb5dd0569238272e67bce1899616b789a
[ "MIT" ]
null
null
null
src/Algebra/Linear.agda
felko/linear-algebra
d87c5a1eb5dd0569238272e67bce1899616b789a
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Algebra.Linear where open import Algebra.Linear.Core public open import Algebra.Linear.Construct public open import Algebra.Linear.Morphism public open import Algebra.Linear.Structures public
27.222222
44
0.77551
4d34edb6a126710dc87a9296ac1f19786fd2aa5f
7,966
agda
Agda
Cubical/Algebra/Group/Instances/IntMod.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/Group/Instances/IntMod.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/Group/Instances/IntMod.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.Group.Instances.IntMod where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Unit open import Cubical.Data.Bool hiding (isProp≤) open import Cubical.Data.Nat renaming (_+_ to _+ℕ_) open import Cubical.Data.Nat.Mod open import Cubical.Data.Nat.Order open import Cubical.Data.Int renaming (_+_ to _+ℤ_) open import Cubical.Data.Fin open import Cubical.Data.Fin.Arithmetic open import Cubical.Data.Sigma open import Cubical.Algebra.Monoid.Base open import Cubical.Algebra.Semigroup.Base open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.Properties open import Cubical.Algebra.Group.Instances.Unit open import Cubical.Algebra.Group.Instances.Bool open import Cubical.Algebra.Group.Instances.Int open GroupStr open IsGroup open IsMonoid ℤGroup/_ : ℕ → Group₀ ℤGroup/ zero = ℤGroup fst (ℤGroup/ suc n) = Fin (suc n) 1g (snd (ℤGroup/ suc n)) = 0 GroupStr._·_ (snd (ℤGroup/ suc n)) = _+ₘ_ inv (snd (ℤGroup/ suc n)) = -ₘ_ IsSemigroup.is-set (isSemigroup (isMonoid (isGroup (snd (ℤGroup/ suc n))))) = isSetFin IsSemigroup.assoc (isSemigroup (isMonoid (isGroup (snd (ℤGroup/ suc n))))) = λ x y z → sym (+ₘ-assoc x y z) fst (identity (isMonoid (isGroup (snd (ℤGroup/ suc n)))) x) = +ₘ-rUnit x snd (identity (isMonoid (isGroup (snd (ℤGroup/ suc n)))) x) = +ₘ-lUnit x fst (inverse (isGroup (snd (ℤGroup/ suc n))) x) = +ₘ-rCancel x snd (inverse (isGroup (snd (ℤGroup/ suc n))) x) = +ₘ-lCancel x ℤGroup/1≅Unit : GroupIso (ℤGroup/ 1) UnitGroup₀ ℤGroup/1≅Unit = contrGroupIsoUnit isContrFin1 Bool≅ℤGroup/2 : GroupIso BoolGroup (ℤGroup/ 2) Iso.fun (fst Bool≅ℤGroup/2) false = 1 Iso.fun (fst Bool≅ℤGroup/2) true = 0 Iso.inv (fst Bool≅ℤGroup/2) (zero , p) = true Iso.inv (fst Bool≅ℤGroup/2) (suc zero , p) = false Iso.inv (fst Bool≅ℤGroup/2) (suc (suc x) , p) = ⊥.rec (¬-<-zero (predℕ-≤-predℕ (predℕ-≤-predℕ p))) Iso.rightInv (fst Bool≅ℤGroup/2) (zero , p) = Σ≡Prop (λ _ → isProp≤) refl Iso.rightInv (fst Bool≅ℤGroup/2) (suc zero , p) = Σ≡Prop (λ _ → isProp≤) refl Iso.rightInv (fst Bool≅ℤGroup/2) (suc (suc x) , p) = ⊥.rec (¬-<-zero (predℕ-≤-predℕ (predℕ-≤-predℕ p))) Iso.leftInv (fst Bool≅ℤGroup/2) false = refl Iso.leftInv (fst Bool≅ℤGroup/2) true = refl snd Bool≅ℤGroup/2 = makeIsGroupHom λ { false false → refl ; false true → refl ; true false → refl ; true true → refl} ℤGroup/2≅Bool : GroupIso (ℤGroup/ 2) BoolGroup ℤGroup/2≅Bool = invGroupIso Bool≅ℤGroup/2 -- Definition of the quotient map homomorphism ℤ → ℤGroup/ (suc n) -- as a group homomorphism. ℤ→Fin : (n : ℕ) → ℤ → Fin (suc n) ℤ→Fin n (pos x) = x mod (suc n) , mod< n x ℤ→Fin n (negsuc x) = -ₘ (suc x mod suc n , mod< n (suc x)) ℤ→Fin-presinv : (n : ℕ) (x : ℤ) → ℤ→Fin n (- x) ≡ -ₘ ℤ→Fin n x ℤ→Fin-presinv n (pos zero) = Σ≡Prop (λ _ → isProp≤) ((λ _ → zero) ∙ sym (cong fst help)) where help : (-ₘ_ {n = n} 0) ≡ 0 help = GroupTheory.inv1g (ℤGroup/ (suc n)) ℤ→Fin-presinv n (pos (suc x)) = Σ≡Prop (λ _ → isProp≤) refl ℤ→Fin-presinv n (negsuc x) = sym (GroupTheory.invInv (ℤGroup/ (suc n)) _) -ₘ1-id : (n : ℕ) → Path (Fin (suc n)) (-ₘ (1 mod (suc n) , mod< n 1)) (n mod (suc n) , mod< n n) -ₘ1-id zero = refl -ₘ1-id (suc n) = cong -ₘ_ (FinPathℕ ((1 mod suc (suc n)) , mod< (suc n) 1) 1 (modIndBase (suc n) 1 (n , +-comm n 2)) .snd) ∙ Σ≡Prop (λ _ → isProp≤) ((+inductionBase (suc n) _ (λ x _ → ((suc (suc n)) ∸ x) mod (suc (suc n))) λ _ x → x) 1 (n , (+-comm n 2))) suc-ₘ1 : (n y : ℕ) → ((suc y mod suc n) , mod< n (suc y)) -ₘ (1 mod (suc n) , mod< n 1) ≡ (y mod suc n , mod< n y) suc-ₘ1 zero y = isContr→isProp (isOfHLevelRetractFromIso 0 (fst ℤGroup/1≅Unit) isContrUnit) _ _ suc-ₘ1 (suc n) y = (λ i → ((suc y mod suc (suc n)) , mod< (suc n) (suc y)) +ₘ (-ₘ1-id (suc n) i)) ∙ Σ≡Prop (λ _ → isProp≤) (cong (_mod (2 +ℕ n)) (cong (_+ℕ (suc n) mod (2 +ℕ n)) (mod+mod≡mod (suc (suc n)) 1 y)) ∙∙ sym (mod+mod≡mod (suc (suc n)) ((1 mod suc (suc n)) +ℕ (y mod suc (suc n))) (suc n)) ∙∙ (mod-rCancel (suc (suc n)) ((1 mod suc (suc n)) +ℕ (y mod suc (suc n))) (suc n) ∙ cong (_mod (suc (suc n))) (cong (_+ℕ (suc n mod suc (suc n))) (+-comm (1 mod suc (suc n)) (y mod suc (suc n))) ∙ sym (+-assoc (y mod suc (suc n)) (1 mod suc (suc n)) (suc n mod suc (suc n)))) ∙∙ mod-rCancel (suc (suc n)) (y mod suc (suc n)) ((1 mod suc (suc n)) +ℕ (suc n mod suc (suc n))) ∙∙ (cong (_mod (2 +ℕ n)) (cong ((y mod suc (suc n)) +ℕ_) (sym (mod+mod≡mod (suc (suc n)) 1 (suc n)) ∙ zero-charac (suc (suc n))) ∙ +-comm _ 0) ∙ mod-idempotent y))) 1-ₘsuc : (n y : ℕ) → ((1 mod (suc n) , mod< n 1) +ₘ (-ₘ (((suc y mod suc n) , mod< n (suc y))))) ≡ -ₘ ((y mod suc n) , mod< n y) 1-ₘsuc n y = sym (GroupTheory.invInv (ℤGroup/ (suc n)) _) ∙ cong -ₘ_ (GroupTheory.invDistr (ℤGroup/ (suc n)) (modInd n 1 , mod< n 1) (-ₘ (modInd n (suc y) , mod< n (suc y))) ∙ cong (_-ₘ (modInd n 1 , mod< n 1)) (GroupTheory.invInv (ℤGroup/ (suc n)) (modInd n (suc y) , mod< n (suc y))) ∙ suc-ₘ1 n y) isHomℤ→Fin : (n : ℕ) → IsGroupHom (snd ℤGroup) (ℤ→Fin n) (snd (ℤGroup/ (suc n))) isHomℤ→Fin n = makeIsGroupHom λ { (pos x) y → pos+case x y ; (negsuc x) (pos y) → cong (ℤ→Fin n) (+Comm (negsuc x) (pos y)) ∙∙ pos+case y (negsuc x) ∙∙ +ₘ-comm (ℤ→Fin n (pos y)) (ℤ→Fin n (negsuc x)) ; (negsuc x) (negsuc y) → sym (cong (ℤ→Fin n) (-Dist+ (pos (suc x)) (pos (suc y)))) ∙∙ ℤ→Fin-presinv n (pos (suc x) +ℤ (pos (suc y))) ∙∙ cong -ₘ_ (pos+case (suc x) (pos (suc y))) ∙∙ GroupTheory.invDistr (ℤGroup/ (suc n)) (modInd n (suc x) , mod< n (suc x)) (modInd n (suc y) , mod< n (suc y)) ∙∙ +ₘ-comm (ℤ→Fin n (negsuc y)) (ℤ→Fin n (negsuc x))} where +1case : (y : ℤ) → ℤ→Fin n (1 +ℤ y) ≡ ℤ→Fin n 1 +ₘ ℤ→Fin n y +1case (pos zero) = sym (GroupStr.rid (snd (ℤGroup/ (suc n))) _) +1case (pos (suc y)) = cong (ℤ→Fin n) (+Comm 1 (pos (suc y))) ∙ Σ≡Prop (λ _ → isProp≤) (mod+mod≡mod (suc n) 1 (suc y)) +1case (negsuc zero) = Σ≡Prop (λ _ → isProp≤) refl ∙ sym (GroupStr.invr (snd (ℤGroup/ (suc n))) (modInd n 1 , mod< n 1)) +1case (negsuc (suc y)) = Σ≡Prop (λ _ → isProp≤) (cong fst (cong (ℤ→Fin n) (+Comm 1 (negsuc (suc y)))) ∙∙ cong fst (cong -ₘ_ (refl {x = suc y mod suc n , mod< n (suc y)})) ∙∙ cong fst (sym (1-ₘsuc n (suc y))) ∙ λ i → fst ((1 mod (suc n) , mod< n 1) +ₘ (-ₘ (((suc (suc y) mod suc n) , mod< n (suc (suc y))))))) pos+case : (x : ℕ) (y : ℤ) → ℤ→Fin n (pos x +ℤ y) ≡ ℤ→Fin n (pos x) +ₘ ℤ→Fin n y pos+case zero y = cong (ℤ→Fin n) (+Comm 0 y) ∙ sym (GroupStr.lid (snd (ℤGroup/ (suc n))) (ℤ→Fin n y)) pos+case (suc zero) y = +1case y pos+case (suc (suc x)) y = cong (ℤ→Fin n) (cong (_+ℤ y) (+Comm (pos (suc x)) 1) ∙ sym (+Assoc 1 (pos (suc x)) y)) ∙∙ +1case (pos (suc x) +ℤ y) ∙∙ (cong ((modInd n 1 , mod< n 1) +ₘ_) (pos+case (suc x) y) ∙∙ sym (+ₘ-assoc (modInd n 1 , mod< n 1) (modInd n (suc x) , mod< n (suc x)) (ℤ→Fin n y)) ∙∙ cong (_+ₘ ℤ→Fin n y) (lem x)) where lem : (x : ℕ) → (modInd n 1 , mod< n 1) +ₘ (modInd n (suc x) , mod< n (suc x)) ≡ ℤ→Fin n (pos (suc (suc x))) lem x = Σ≡Prop (λ _ → isProp≤) (sym (mod+mod≡mod (suc n) 1 (suc x)))
39.241379
81
0.549711
1813f877030cd6c9392d57e9d8f48bacd0c24969
559
agda
Agda
test/Succeed/Issue2998.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2998.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2998.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Reported by Nisse on 2018-03-13 -- The `x` in the parent pattern was eta-expanded to `record{}`, -- but with-abstraction didn't like this. open import Agda.Builtin.Equality record R : Set where postulate easy : (A : Set) → A F : (x : R) → Set₁ F x with easy (x ≡ x) F x | refl with Set F x | refl | _ = Set -- OLD ERROR: -- With clause pattern x is not an instance of its parent pattern -- record {} -- Fixed by allowing parent patterns to be replaced by variables -- in the with clause (but checking that their instantiation is -- type-correct).
22.36
65
0.683363
d0baa68274de613113fe0338b93de9849331c8a6
3,413
agda
Agda
Cubical/HITs/Ints/DiffInt/Base.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
Cubical/HITs/Ints/DiffInt/Base.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
Cubical/HITs/Ints/DiffInt/Base.agda
Edlyr/cubical
5de11df25b79ee49d5c084fbbe6dfc66e4147a2e
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Ints.DiffInt.Base where open import Cubical.Foundations.Prelude open import Cubical.HITs.SetQuotients open import Cubical.Foundations.Isomorphism open import Cubical.Data.Sigma open import Cubical.Data.Nat hiding (+-comm ; +-assoc) renaming (_+_ to _+ℕ_) open import Cubical.Data.Int rel : (ℕ × ℕ) → (ℕ × ℕ) → Type₀ rel (a₀ , b₀) (a₁ , b₁) = x ≡ y where x = a₀ +ℕ b₁ y = a₁ +ℕ b₀ ℤ = (ℕ × ℕ) / rel -- Proof of equivalence between Int and DiffInt private -- Prove all the identities for ℕ×ℕ first and use that to build to ℤ Int→ℕ×ℕ : Int → (ℕ × ℕ) Int→ℕ×ℕ (pos n) = ( n , zero ) Int→ℕ×ℕ (negsuc n) = ( zero , suc n ) ℕ×ℕ→Int : (ℕ × ℕ) → Int ℕ×ℕ→Int(n , m) = n ℕ- m relInt→ℕ×ℕ : ∀ m n → rel (Int→ℕ×ℕ (m ℕ- n)) (m , n) relInt→ℕ×ℕ zero zero = refl relInt→ℕ×ℕ zero (suc n) = refl relInt→ℕ×ℕ (suc m) zero = refl relInt→ℕ×ℕ (suc m) (suc n) = fst (Int→ℕ×ℕ (m ℕ- n)) +ℕ suc n ≡⟨ +-suc (fst (Int→ℕ×ℕ (m ℕ- n))) n ⟩ suc (fst (Int→ℕ×ℕ (m ℕ- n)) +ℕ n) ≡⟨ cong suc (relInt→ℕ×ℕ m n) ⟩ suc (m +ℕ snd (Int→ℕ×ℕ (m ℕ- n))) ∎ Int→ℕ×ℕ→Int : ∀ n → ℕ×ℕ→Int (Int→ℕ×ℕ n) ≡ n Int→ℕ×ℕ→Int (pos n) = refl Int→ℕ×ℕ→Int (negsuc n) = refl ℕ×ℕ→Int→ℕ×ℕ : ∀ p → rel (Int→ℕ×ℕ (ℕ×ℕ→Int p)) p ℕ×ℕ→Int→ℕ×ℕ (p₀ , p₁) = relInt→ℕ×ℕ p₀ p₁ -- Now build to ℤ using the above Int→ℤ : Int → ℤ Int→ℤ n = [ Int→ℕ×ℕ n ] ℤ→Int : ℤ → Int ℤ→Int [ z ] = ℕ×ℕ→Int z ℤ→Int(eq/ a b r i) = lemℤeq a b r i where lemℤeq : (a b : (ℕ × ℕ)) → rel a b → ℕ×ℕ→Int(a) ≡ ℕ×ℕ→Int(b) lemℤeq (a₀ , a₁) (b₀ , b₁) r = a₀ ℕ- a₁ ≡⟨ pos- a₀ a₁ ⟩ pos a₀ - pos a₁ ≡[ i ]⟨ ((pos a₀ - pos a₁) + -Cancel (pos b₁) (~ i)) ⟩ (pos a₀ - pos a₁) + (pos b₁ - pos b₁) ≡⟨ +-assoc (pos a₀ + (- pos a₁)) (pos b₁) (- pos b₁) ⟩ ((pos a₀ - pos a₁) + pos b₁) - pos b₁ ≡[ i ]⟨ +-assoc (pos a₀) (- pos a₁) (pos b₁) (~ i) + (- pos b₁) ⟩ (pos a₀ + ((- pos a₁) + pos b₁)) - pos b₁ ≡[ i ]⟨ (pos a₀ + +-comm (- pos a₁) (pos b₁) i) - pos b₁ ⟩ (pos a₀ + (pos b₁ - pos a₁)) - pos b₁ ≡[ i ]⟨ +-assoc (pos a₀) (pos b₁) (- pos a₁) i + (- pos b₁) ⟩ ((pos a₀ + pos b₁) - pos a₁) - pos b₁ ≡[ i ]⟨ (pos+ a₀ b₁ (~ i) - pos a₁) - pos b₁ ⟩ (pos (a₀ +ℕ b₁) - pos a₁) - pos b₁ ≡[ i ]⟨ (pos (r i) - pos a₁) - pos b₁ ⟩ (pos (b₀ +ℕ a₁) - pos a₁) - pos b₁ ≡[ i ]⟨ (pos+ b₀ a₁ i - pos a₁) - pos b₁ ⟩ ((pos b₀ + pos a₁) - pos a₁) - pos b₁ ≡[ i ]⟨ +-assoc (pos b₀) (pos a₁) (- pos a₁) (~ i) + (- pos b₁) ⟩ (pos b₀ + (pos a₁ - pos a₁)) - pos b₁ ≡[ i ]⟨ (pos b₀ + (-Cancel (pos a₁) i)) - pos b₁ ⟩ pos b₀ - pos b₁ ≡[ i ]⟨ pos- b₀ b₁ (~ i) ⟩ b₀ ℕ- b₁ ∎ ℤ→Int(squash/ x x₀ p q i j) = isSetInt (ℤ→Int x) (ℤ→Int x₀) (cong ℤ→Int p) (cong ℤ→Int q) i j Int→ℤ→Int : ∀ z → ℤ→Int (Int→ℤ z) ≡ z Int→ℤ→Int (pos n) = refl Int→ℤ→Int (negsuc n) = refl ℤ→Int→ℤ : ∀ z → Int→ℤ (ℤ→Int z) ≡ z ℤ→Int→ℤ = elimProp (λ z → squash/ (Int→ℤ (ℤ→Int z)) z) ℕ×ℕprf where ℕ×ℕprf : (a : ℕ × ℕ) → Int→ℤ (ℤ→Int [ a ]) ≡ [ a ] ℕ×ℕprf (a , b) = eq/ (Int→ℕ×ℕ (ℕ×ℕ→Int (a , b))) (a , b) (ℕ×ℕ→Int→ℕ×ℕ (a , b)) Int≡DiffInt : Int ≡ ℤ Int≡DiffInt = isoToPath (iso Int→ℤ ℤ→Int ℤ→Int→ℤ Int→ℤ→Int)
40.152941
122
0.474949
df1114e11e271e0265439a20afa30477173d3311
4,418
agda
Agda
Structure/Operator/Vector.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Structure/Operator/Vector.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Structure/Operator/Vector.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Structure.Operator.Vector where open import Functional using (swap) import Lvl open import Logic open import Logic.Propositional open import Structure.Setoid open import Structure.Operator.Field open import Structure.Operator.Group open import Structure.Operator.Monoid import Structure.Operator.Names as Names open import Structure.Operator.Properties open import Structure.Operator open import Type record VectorSpace {ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ} {V : Type{ℓᵥ}} ⦃ _ : Equiv{ℓᵥₑ}(V) ⦄ {S : Type{ℓₛ}} ⦃ _ : Equiv{ℓₛₑ}(S) ⦄ (_+ᵥ_ : V → V → V) (_⋅ₛᵥ_ : S → V → V) (_+ₛ_ : S → S → S) (_⋅ₛ_ : S → S → S) : Stmt{ℓₛₑ Lvl.⊔ ℓₛ Lvl.⊔ ℓᵥₑ Lvl.⊔ ℓᵥ} where constructor intro field ⦃ scalarField ⦄ : Field(_+ₛ_)(_⋅ₛ_) ⦃ vectorCommutativeGroup ⦄ : CommutativeGroup(_+ᵥ_) open Field(scalarField) renaming ( 𝟎 to 𝟎ₛ ; 𝟏 to 𝟏ₛ ; _−_ to _−ₛ_ ; _/_ to _/ₛ_ ; −_ to −ₛ_ ; ⅟ to ⅟ₛ ; [+]-group to [+ₛ]-group ; [+]-commutativity to [+ₛ]-commutativity ; [+]-monoid to [+ₛ]-monoid ; [+]-binary-operator to [+ₛ]-binary-operator ; [+]-associativity to [+ₛ]-associativity ; [+]-identity-existence to [+ₛ]-identity-existence ; [+]-identity to [+ₛ]-identity ; [+]-identityₗ to [+ₛ]-identityₗ ; [+]-identityᵣ to [+ₛ]-identityᵣ ; [+]-inverse-existence to [+ₛ]-inverse-existence ; [+]-inverse to [+ₛ]-inverse ; [+]-inverseₗ to [+ₛ]-inverseₗ ; [+]-inverseᵣ to [+ₛ]-inverseᵣ ; [−]-function to [−ₛ]-function ; [⋅]-binary-operator to [⋅ₛ]-binary-operator ; [⋅]-associativity to [⋅ₛ]-associativity ; [⋅]-identity-existence to [⋅ₛ]-identity-existence ; [⋅]-identity to [⋅ₛ]-identity ; [⋅]-identityₗ to [⋅ₛ]-identityₗ ; [⋅]-identityᵣ to [⋅ₛ]-identityᵣ ; [⋅]-inverseₗ to [⋅ₛ]-inverseₗ ; [⋅]-inverseᵣ to [⋅ₛ]-inverseᵣ ; distinct-identities to distinct-identitiesₛ ) public open CommutativeGroup(vectorCommutativeGroup) renaming ( id to 𝟎ᵥ ; inv to −ᵥ_ ; inv-op to _−ᵥ_ ; group to [+ᵥ]-group; commutativity to [+ᵥ]-commutativity; monoid to [+ᵥ]-monoid ; binary-operator to [+ᵥ]-binary-operator ; associativity to [+ᵥ]-associativity ; identity-existence to [+ᵥ]-identity-existence ; identity to [+ᵥ]-identity ; identityₗ to [+ᵥ]-identityₗ ; identityᵣ to [+ᵥ]-identityᵣ ; inverse-existence to [+ᵥ]-inverse-existence ; inverse to [+ᵥ]-inverse ; inverseₗ to [+ᵥ]-inverseₗ ; inverseᵣ to [+ᵥ]-inverseᵣ ; inv-function to [−ᵥ]-function ) public field ⦃ [⋅ₛᵥ]-binaryOperator ⦄ : BinaryOperator(_⋅ₛᵥ_) [⋅ₛ][⋅ₛᵥ]-compatibility : Names.Compatibility(_⋅ₛ_)(_⋅ₛᵥ_) -- TODO: This is semigroup action ⦃ [⋅ₛᵥ]-identity ⦄ : Identityₗ(_⋅ₛᵥ_)(𝟏ₛ) ⦃ [⋅ₛᵥ][+ᵥ]-distributivityₗ ⦄ : Distributivityₗ(_⋅ₛᵥ_)(_+ᵥ_) [⋅ₛᵥ][+ₛ][+ᵥ]-distributivityᵣ : Names.DistributivityPatternᵣ(_⋅ₛᵥ_)(_+ₛ_)(_+ᵥ_) -- TODO: This is ∀? → Preserving₂ _⋅ᵥₛ_ = swap(_⋅ₛᵥ_) record VectorSpaceVObject {ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ} {S : Type{ℓₛ}} ⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄ (_+ₛ_ : S → S → S) (_⋅ₛ_ : S → S → S) : Stmt{ℓₛₑ Lvl.⊔ ℓₛ Lvl.⊔ Lvl.𝐒(ℓᵥₑ Lvl.⊔ ℓᵥ)} where constructor intro field {Vector} : Type{ℓᵥ} ⦃ Vector-equiv ⦄ : Equiv{ℓᵥₑ}(Vector) _+ᵥ_ : Vector → Vector → Vector _⋅ₛᵥ_ : S → Vector → Vector ⦃ vectorSpace ⦄ : VectorSpace(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_) open VectorSpace(vectorSpace) public record VectorSpaceObject {ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ} : Stmt{Lvl.𝐒(ℓₛₑ Lvl.⊔ ℓₛ Lvl.⊔ ℓᵥₑ Lvl.⊔ ℓᵥ)} where constructor intro field {Vector} : Type{ℓᵥ} ⦃ equiv-Vector ⦄ : Equiv{ℓᵥₑ}(Vector) {Scalar} : Type{ℓₛ} ⦃ equiv-Scalar ⦄ : Equiv{ℓₛₑ}(Scalar) _+ᵥ_ : Vector → Vector → Vector _⋅ₛᵥ_ : Scalar → Vector → Vector _+ₛ_ : Scalar → Scalar → Scalar _⋅ₛ_ : Scalar → Scalar → Scalar ⦃ vectorSpace ⦄ : VectorSpace(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_) open VectorSpace(vectorSpace) public
36.816667
117
0.546627
12a247a950219a1c574c869f366e3240987e6c4a
956
agda
Agda
test/Succeed/Issue3246.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3246.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3246.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2018-10-29, issue #3246 -- More things are now allowed in mutual blocks. -- @mutual@ just pushes the definition parts to the bottom. -- Definitions exist for data, record, functions, and pattern synonyms. {-# OPTIONS --guardedness #-} postulate Float : Set {-# BUILTIN FLOAT Float #-} -- not (yet) allowed in mutual block mutual import Agda.Builtin.Bool open Agda.Builtin.Bool f : Bool f = g -- pushed to bottom -- module M where -- not (yet) allowed in mutual block module B = Agda.Builtin.Bool primitive primFloatEquality : Float → Float → Bool {-# INJECTIVE primFloatEquality #-} -- certainly a lie open import Agda.Builtin.Equality {-# DISPLAY primFloatEquality x y = x ≡ y #-} postulate A : Set {-# COMPILE GHC A = type Integer #-} variable x : Bool g : Bool g = true -- pushed to bottom {-# STATIC g #-} record R : Set where coinductive field foo : R {-# ETA R #-}
19.510204
71
0.649582
c592d46ed874a6842987632ef070e1bb8f1d54d6
12,586
agda
Agda
Cubical/Foundations/HLevels.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/Foundations/HLevels.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/Foundations/HLevels.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
{- Basic theory about h-levels/n-types: - Basic properties of isContr, isProp and isSet (definitions are in Prelude) - Hedberg's theorem can be found in Cubical/Relation/Nullary/DecidableEq -} {-# OPTIONS --cubical --safe #-} module Cubical.Foundations.HLevels where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.FunExtEquiv open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Transport open import Cubical.Foundations.HAEquiv using (congEquiv) open import Cubical.Foundations.Equiv using (isoToEquiv; isPropIsEquiv; retEq; invEquiv) open import Cubical.Foundations.Univalence using (ua; univalence) open import Cubical.Data.Sigma using (ΣPathP; sigmaPath→pathSigma; pathSigma≡sigmaPath; _Σ≡T_) open import Cubical.Data.Nat using (ℕ; zero; suc; _+_; +-comm) private variable ℓ ℓ' : Level A : Type ℓ B : A → Type ℓ x y : A n : ℕ hProp : Type (ℓ-suc ℓ) hProp {ℓ} = Σ (Type ℓ) isProp isOfHLevel : ℕ → Type ℓ → Type ℓ isOfHLevel 0 A = isContr A isOfHLevel 1 A = isProp A isOfHLevel (suc (suc n)) A = (x y : A) → isOfHLevel (suc n) (x ≡ y) isOfHLevelDep : ℕ → {A : Type ℓ} (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ') isOfHLevelDep 0 {A = A} B = {a : A} → B a isOfHLevelDep 1 {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) (p : a0 ≡ a1) → PathP (λ i → B (p i)) b0 b1 isOfHLevelDep (suc (suc n)) {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) → isOfHLevelDep (suc n) {A = a0 ≡ a1} (λ p → PathP (λ i → B (p i)) b0 b1) isOfHLevel→isOfHLevelDep : {n : ℕ} → {A : Type ℓ} {B : A → Type ℓ'} (h : (a : A) → isOfHLevel n (B a)) → isOfHLevelDep n {A = A} B isOfHLevel→isOfHLevelDep {n = 0} {A = A} {B} h {a} = h a .fst isOfHLevel→isOfHLevelDep {n = 1} {A = A} {B} h = λ b0 b1 p → isProp→PathP h p b0 b1 isOfHLevel→isOfHLevelDep {n = suc (suc n)} {A = A} {B} h {a0} {a1} b0 b1 = isOfHLevel→isOfHLevelDep {n = suc n} {B = λ p → PathP (λ i → B (p i)) b0 b1} λ p → helper a1 p b1 where helper : (a1 : A) (p : a0 ≡ a1) (b1 : B a1) → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1) helper a1 p b1 = J (λ a1 p → ∀ b1 → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1)) (λ _ → h _ _ _) p b1 HLevel : ℕ → Type (ℓ-suc ℓ) HLevel {ℓ} n = Σ[ A ∈ Type ℓ ] (isOfHLevel n A) inhProp→isContr : A → isProp A → isContr A inhProp→isContr x h = x , h x isPropIsProp : isProp (isProp A) isPropIsProp f g i a b = isProp→isSet f a b (f a b) (g a b) i -- A retract of a contractible type is contractible retractIsContr : ∀ {B : Type ℓ} → (f : A → B) (g : B → A) → (h : (x : A) → g (f x) ≡ x) → (v : isContr B) → isContr A retractIsContr f g h (b , p) = (g b , λ x → (cong g (p (f x))) ∙ (h x)) retractIsProp : {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isProp B → isProp A retractIsProp f g h p x y i = hcomp (λ j → λ { (i = i0) → h x j ; (i = i1) → h y j}) (g (p (f x) (f y) i)) retractIsOfHLevel : (n : ℕ) {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isOfHLevel n B → isOfHLevel n A retractIsOfHLevel 0 = retractIsContr retractIsOfHLevel 1 = retractIsProp retractIsOfHLevel (suc (suc n)) f g h ofLevel x y = retractIsOfHLevel (suc n) (cong f) (λ q i → hcomp (λ j → λ { (i = i0) → h x j ; (i = i1) → h y j}) (g (q i))) (λ p k i → hcomp (λ j → λ { (i = i0) → h x (j ∨ k) ; (i = i1) → h y (j ∨ k) ; (k = i1) → p i}) (h (p i) k)) (ofLevel (f x) (f y)) isContrSigma : isContr A → ((x : A) → isContr (B x)) → isContr (Σ[ x ∈ A ] B x) isContrSigma {A = A} {B = B} (a , p) q = let h : (x : A) (y : B x) → (q x) .fst ≡ y h x y = (q x) .snd y in (( a , q a .fst) , ( λ x i → p (x .fst) i , h (p (x .fst) i) (transp (λ j → B (p (x .fst) (i ∨ ~ j))) i (x .snd)) i)) isProp→isPropPathP : (∀ a → isProp (B a)) → (m : x ≡ y) (g : B x) (h : B y) → isProp (PathP (λ i → B (m i)) g h) isProp→isPropPathP {B = B} {x = x} isPropB m = J P d m where P : ∀ σc → x ≡ σc → _ P _ m = ∀ g h → isProp (PathP (λ i → B (m i)) g h) d : P x refl d = isProp→isSet (isPropB x) isProp→isContrPathP : (∀ a → isProp (B a)) → (m : x ≡ y) (g : B x) (h : B y) → isContr (PathP (λ i → B (m i)) g h) isProp→isContrPathP isPropB m g h = inhProp→isContr (isProp→PathP isPropB m g h) (isProp→isPropPathP isPropB m g h) isProp→isContr≡ : isProp A → (x y : A) → isContr (x ≡ y) isProp→isContr≡ isPropA x y = inhProp→isContr (isPropA x y) (isProp→isSet isPropA x y) isContrPath : isContr A → (x y : A) → isContr (x ≡ y) isContrPath cA = isProp→isContr≡ (isContr→isProp cA) -- Π preserves propositionality in the following sense: propPi : (h : (x : A) → isProp (B x)) → isProp ((x : A) → B x) propPi h f0 f1 i x = h x (f0 x) (f1 x) i ΣProp≡ : ((x : A) → isProp (B x)) → {u v : Σ[ a ∈ A ] B a} → (p : u .fst ≡ v .fst) → u ≡ v ΣProp≡ pB {u} {v} p i = (p i) , isProp→PathP pB p (u .snd) (v .snd) i isPropSigma : isProp A → ((x : A) → isProp (B x)) → isProp (Σ[ x ∈ A ] B x) isPropSigma pA pB t u = ΣProp≡ pB (pA (t .fst) (u .fst)) hLevelPi : ∀ n → ((x : A) → isOfHLevel n (B x)) → isOfHLevel n ((x : A) → B x) hLevelPi 0 h = (λ x → fst (h x)) , λ f i y → snd (h y) (f y) i hLevelPi {B = B} 1 h f g i x = (h x) (f x) (g x) i hLevelPi (suc (suc n)) h f g = subst (isOfHLevel (suc n)) funExtPath (hLevelPi (suc n) λ x → h x (f x) (g x)) isSetPi : ((x : A) → isSet (B x)) → isSet ((x : A) → B x) isSetPi Bset = hLevelPi 2 (λ a → Bset a) isSet→isSet' : isSet A → isSet' A isSet→isSet' {A = A} Aset {x} {y} {z} {w} p q r s = transport (squeezeSq≡ r p q s) (Aset _ _ p (r ∙∙ q ∙∙ sym s)) isSet'→isSet : isSet' A → isSet A isSet'→isSet {A = A} Aset' x y p q = Aset' p q refl refl squeezeCu≡ : ∀{w x y z w' x' y' z' : A} → {p : w ≡ y} {q : w ≡ x} {r : y ≡ z} {s : x ≡ z} → {p' : w' ≡ y'} {q' : w' ≡ x'} {r' : y' ≡ z'} {s' : x' ≡ z'} → {a : w ≡ w'} {b : x ≡ x'} {c : y ≡ y'} {d : z ≡ z'} → (ps : Square a p p' c) (qs : Square a q q' b) → (rs : Square c r r' d) (ss : Square b s s' d) → (f0 : Square p q r s) (f1 : Square p' q' r' s') → (f0 ≡ transport⁻ (λ k → Square (ps k) (qs k) (rs k) (ss k)) f1) ≡ Cube ps qs rs ss f0 f1 squeezeCu≡ ps qs rs ss f0 f1 τ = Cube (λ j → ps (j ∧ τ)) (λ j → qs (j ∧ τ)) (λ j → rs (j ∧ τ)) (λ j → ss (j ∧ τ)) f0 (toPathP {A = λ k → Square (ps k) (qs k) (rs k) (ss k)} (transportTransport⁻ (λ k → Square (ps k) (qs k) (rs k) (ss k)) f1) τ) isGroupoid→isGroupoid' : isGroupoid A → isGroupoid' A isGroupoid→isGroupoid' Agpd ps qs rs ss f0 f1 = transport ( squeezeCu≡ (λ _ → refl) f0 f1' (λ _ → refl) (λ _ → f0 i0) (λ _ → f1' i1) ∙ transpose≡ ∙ squeezeCu≡ ps qs rs ss f0 f1 ) (Agpd (ps i0 i0) (ss i0 i0) (f0 i0) (f1' i0) refl rs') where Sq = λ k → Square (ps k) (qs k) (rs k) (ss k) f1' = transport⁻ Sq f1 rs' = transport⁻ (λ k → Square refl (f0 k) (f1' k) refl) (λ _ → f1' i1) transpose≡ : Cube (λ i _ → ps i0 i) f0 f1' (λ i _ → ss i0 i) refl refl ≡ Cube refl refl refl refl f0 f1' transpose≡ = ua ((λ cu i j → cu j i) , λ where .equiv-proof cu → ((λ i j → cu j i) , refl) , (λ{ (cu' , p) → λ k → (λ j i → p (~ k) i j) , λ τ → p (~ k ∨ τ) })) isGroupoid'→isGroupoid : isGroupoid' A → isGroupoid A isGroupoid'→isGroupoid Agpd' w x p q r s = Agpd' {q = p} {r = q} {q' = p} {r' = q} refl refl refl refl r s hLevelSuc : (n : ℕ) (A : Type ℓ) → isOfHLevel n A → isOfHLevel (suc n) A hLevelSuc 0 A = isContr→isProp hLevelSuc 1 A = isProp→isSet hLevelSuc (suc (suc n)) A h a b = hLevelSuc (suc n) (a ≡ b) (h a b) hLevelLift : (m : ℕ) (hA : isOfHLevel n A) → isOfHLevel (m + n) A hLevelLift zero hA = hA hLevelLift {A = A} (suc m) hA = hLevelSuc _ A (hLevelLift m hA) isPropIsOfHLevel : (n : ℕ) (A : Type ℓ) → isProp (isOfHLevel n A) isPropIsOfHLevel 0 A = isPropIsContr isPropIsOfHLevel 1 A = isPropIsProp isPropIsOfHLevel (suc (suc n)) A f g i a b = isPropIsOfHLevel (suc n) (a ≡ b) (f a b) (g a b) i isPropIsSet : isProp (isSet A) isPropIsSet {A = A} = isPropIsOfHLevel 2 A HLevel≡ : ∀ {A B : Type ℓ} {hA : isOfHLevel n A} {hB : isOfHLevel n B} → (A ≡ B) ≡ ((A , hA) ≡ (B , hB)) HLevel≡ {n = n} {A = A} {B = B} {hA} {hB} = isoToPath (iso intro elim intro-elim elim-intro) where intro : A ≡ B → (A , hA) ≡ (B , hB) intro eq = ΣProp≡ (λ A → isPropIsOfHLevel n _) eq elim : (A , hA) ≡ (B , hB) → A ≡ B elim = cong fst intro-elim : ∀ x → intro (elim x) ≡ x intro-elim eq = cong ΣPathP (ΣProp≡ (λ e → J (λ B e → ∀ k → (x y : PathP (λ i → isOfHLevel n (e i)) hA k) → x ≡ y) (λ k → isProp→isSet (isPropIsOfHLevel n _) _ _) e hB) refl) elim-intro : ∀ x → elim (intro x) ≡ x elim-intro eq = refl -- H-level for Σ-types isOfHLevelΣ : ∀ n → isOfHLevel n A → ((x : A) → isOfHLevel n (B x)) → isOfHLevel n (Σ A B) isOfHLevelΣ zero h1 h2 = let center = (fst h1 , fst (h2 (fst h1))) in let p : ∀ x → center ≡ x p = λ x → sym (sigmaPath→pathSigma _ _ (sym (snd h1 (fst x)) , sym (snd (h2 (fst h1)) _))) in (center , p) isOfHLevelΣ 1 h1 h2 x y = sigmaPath→pathSigma x y ((h1 _ _) , (h2 _ _ _)) isOfHLevelΣ {B = B} (suc (suc n)) h1 h2 x y = let h3 : isOfHLevel (suc n) (x Σ≡T y) h3 = isOfHLevelΣ (suc n) (h1 (fst x) (fst y)) λ p → h2 (p i1) (subst B p (snd x)) (snd y) in transport (λ i → isOfHLevel (suc n) (pathSigma≡sigmaPath x y (~ i))) h3 hLevel≃ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≃ B) hLevel≃ zero {A = A} {B = B} hA hB = A≃B , contr where A≃B : A ≃ B A≃B = isoToEquiv (iso (λ _ → fst hB) (λ _ → fst hA) (snd hB ) (snd hA)) contr : (y : A ≃ B) → A≃B ≡ y contr y = ΣProp≡ isPropIsEquiv (funExt (λ a → snd hB (fst y a))) hLevel≃ (suc n) hA hB = isOfHLevelΣ (suc n) (hLevelPi (suc n) (λ _ → hB)) (λ a → subst (λ n → isOfHLevel n (isEquiv a)) (+-comm n 1) (hLevelLift n (isPropIsEquiv a))) hLevelRespectEquiv : {A : Type ℓ} {B : Type ℓ'} → (n : ℕ) → A ≃ B → isOfHLevel n A → isOfHLevel n B hLevelRespectEquiv 0 eq hA = ( fst eq (fst hA) , λ b → cong (fst eq) (snd hA (eq .snd .equiv-proof b .fst .fst)) ∙ eq .snd .equiv-proof b .fst .snd) hLevelRespectEquiv 1 eq hA x y i = hcomp (λ j → λ { (i = i0) → retEq eq x j ; (i = i1) → retEq eq y j }) (cong (eq .fst) (hA (invEquiv eq .fst x) (invEquiv eq .fst y)) i) hLevelRespectEquiv {A = A} {B = B} (suc (suc n)) eq hA x y = hLevelRespectEquiv (suc n) (invEquiv (congEquiv (invEquiv eq))) (hA _ _) hLevel≡ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≡ B) hLevel≡ n hA hB = hLevelRespectEquiv n (invEquiv univalence) (hLevel≃ n hA hB) hLevelHLevel1 : isProp (HLevel {ℓ = ℓ} 0) hLevelHLevel1 x y = ΣProp≡ (λ _ → isPropIsContr) ((hLevel≡ 0 (x .snd) (y .snd) .fst)) hLevelHLevelSuc : ∀ n → isOfHLevel (suc (suc n)) (HLevel {ℓ = ℓ} (suc n)) hLevelHLevelSuc n x y = subst (λ e → isOfHLevel (suc n) e) HLevel≡ (hLevel≡ (suc n) (snd x) (snd y)) hProp≡HLevel1 : hProp {ℓ} ≡ HLevel {ℓ} 1 hProp≡HLevel1 {ℓ} = isoToPath (iso intro elim intro-elim elim-intro) where intro : hProp {ℓ} → HLevel {ℓ} 1 intro h = fst h , snd h elim : HLevel 1 → hProp elim h = (fst h) , (snd h) intro-elim : ∀ h → intro (elim h) ≡ h intro-elim h = ΣProp≡ (λ _ → isPropIsOfHLevel 1 _) refl elim-intro : ∀ h → elim (intro h) ≡ h elim-intro h = ΣProp≡ (λ _ → isPropIsProp) refl isSetHProp : isSet (hProp {ℓ = ℓ}) isSetHProp = subst (λ X → isOfHLevel 2 X) (sym hProp≡HLevel1) (hLevelHLevelSuc 0) isContrPartial→isContr : ∀ {ℓ} {A : Type ℓ} → (extend : ∀ φ → Partial φ A → A) → (∀ u → u ≡ (extend i1 λ { _ → u})) → isContr A isContrPartial→isContr {A = A} extend law = ex , λ y → law ex ∙ (λ i → Aux.v y i) ∙ sym (law y) where ex = extend i0 empty module Aux (y : A) (i : I) where φ = ~ i ∨ i u : Partial φ A u = λ { (i = i0) → ex ; (i = i1) → y } v = extend φ u isOfHLevelLift : ∀ {ℓ ℓ'} (n : ℕ) {A : Type ℓ} → isOfHLevel n A → isOfHLevel n (Lift {j = ℓ'} A) isOfHLevelLift n = retractIsOfHLevel n lower lift λ _ → refl
36.481159
150
0.540521
fbbd3661af2f81c0eb741eed8b428d82b2e5c8cc
2,142
agda
Agda
Globular-TT/Eqdec-syntax.agda
ThiBen/catt-formalization
ed45935b38d6a86fa662f561866140122ee3dcef
[ "MIT" ]
2
2020-05-01T08:26:53.000Z
2020-05-20T00:41:09.000Z
Globular-TT/Eqdec-syntax.agda
ThiBen/catt-formalization
ed45935b38d6a86fa662f561866140122ee3dcef
[ "MIT" ]
null
null
null
Globular-TT/Eqdec-syntax.agda
ThiBen/catt-formalization
ed45935b38d6a86fa662f561866140122ee3dcef
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import Agda.Primitive open import Prelude import GSeTT.Typed-Syntax import Globular-TT.Syntax {- Type theory for globular sets -} module Globular-TT.Eqdec-syntax {l} (index : Set l) (eqdec-index : eqdec index) where open import Globular-TT.Syntax index eqdec-Ty : eqdec Pre-Ty eqdec-Tm : eqdec Pre-Tm eqdec-Sub : eqdec Pre-Sub eqdec-Ty ∗ ∗ = inl idp eqdec-Ty ∗ (_ ⇒[ _ ] _) = inr λ{()} eqdec-Ty (_ ⇒[ _ ] _) ∗ = inr λ{()} eqdec-Ty (t ⇒[ A ] u) (t' ⇒[ B ] u') with eqdec-Ty A B | eqdec-Tm t t' | eqdec-Tm u u' ... | inl idp | inl idp | inl idp = inl idp ... | inr A≠B | _ | _ = inr λ{idp → A≠B idp} ... | inl idp | inr t≠t' | _ = inr λ eq → t≠t' (snd (fst (=⇒ eq))) ... | inl idp | inl idp | inr u≠u' = inr λ eq → u≠u' (snd (=⇒ eq)) eqdec-Tm (Var x) (Var y) with eqdecℕ x y ... | inl idp = inl idp ... | inr x≠y = inr λ {idp → x≠y idp} eqdec-Tm (Var _) (Tm-constructor _ _) = inr λ{()} eqdec-Tm (Tm-constructor _ _) (Var _) = inr λ{()} eqdec-Tm (Tm-constructor i γ) (Tm-constructor i' γ') with eqdec-index i i' | eqdec-Sub γ γ' ... | inl idp | inl idp = inl idp ... | inr i≠i' | _ = inr λ{idp → i≠i' idp} ... | inl idp | inr γ≠γ' = inr λ eq → γ≠γ' (snd (=Tm-constructor eq)) eqdec-Sub <> <> = inl idp eqdec-Sub < _ , _ ↦ _ > <> = inr λ{()} eqdec-Sub <> < _ , _ ↦ _ > = inr λ{()} eqdec-Sub < γ , x ↦ t > < γ' , y ↦ t' > with eqdec-Sub γ γ' | eqdecℕ x y | eqdec-Tm t t' ... | inl idp | inl idp | inl idp = inl idp ... | inr γ≠γ' | _ | _ = inr λ{idp → γ≠γ' idp} ... | inl idp | inr x≠y | _ = inr λ eq → x≠y (snd (fst (=<,> eq))) ... | inl idp | inl idp | inr t≠t' = inr λ eq → t≠t' (snd (=<,> eq))
47.6
121
0.419234
fb0651903caa0db4f8c81582593324d595354821
5,611
agda
Agda
Structure/Relator.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Structure/Relator.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Structure/Relator.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Structure.Relator where import Lvl open import Functional using (_∘₂_) open import Functional.Dependent open import Lang.Instance open import Logic open import Logic.Propositional open import Structure.Setoid open import Structure.Relator.Names open import Structure.Relator.Properties open import Syntax.Function open import Type -- TODO: It seems possible to define UnaryRelator as a special case of Function, so let's do that private variable ℓₒ ℓₒ₁ ℓₒ₂ ℓₒ₃ ℓₗ ℓₗ₁ ℓₗ₂ ℓₗ₃ ℓₗ₄ : Lvl.Level module Names where module _ {A : Type{ℓₒ}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ (P : A → Stmt{ℓₗ₂}) where Substitution₁ = ∀{x y : A} → (x ≡ y) → P(x) → P(y) module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (_▫_ : A → B → Stmt{ℓₗ₃}) where Substitution₂ = ∀{x₁ y₁ : A}{x₂ y₂ : B} → (x₁ ≡ y₁) → (x₂ ≡ y₂) → (x₁ ▫ x₂) → (y₁ ▫ y₂) module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ {C : Type{ℓₒ₃}} ⦃ _ : Equiv{ℓₗ₃}(C) ⦄ (_▫_▫_ : A → B → C → Stmt{ℓₗ₄}) where Substitution₃ = ∀{x₁ y₁ : A}{x₂ y₂ : B}{x₃ y₃ : C} → (x₁ ≡ y₁) → (x₂ ≡ y₂) → (x₃ ≡ y₃) → (x₁ ▫ x₂ ▫ x₃) → (y₁ ▫ y₂ ▫ y₃) -- The unary relator `P` "(behaves like)/is a relator" in the context of `_≡_` from the Equiv instance. module _ {A : Type{ℓₒ}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ (P : A → Stmt{ℓₗ₂}) where record UnaryRelator : Stmt{ℓₒ Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂} where constructor intro field substitution : Names.Substitution₁(P) substitution-sym : ∀{x y : A} → (x ≡ y) → P(x) ← P(y) substitution-sym = substitution ∘ Structure.Relator.Properties.symmetry(_≡_) substitution-equivalence : ∀{x y : A} → (x ≡ y) → (P(x) ↔ P(y)) substitution-equivalence xy = [↔]-intro (substitution-sym xy) (substitution xy) substitute₁ₗ = inst-fn UnaryRelator.substitution-sym substitute₁ᵣ = inst-fn UnaryRelator.substitution substitute₁ₗᵣ = inst-fn UnaryRelator.substitution-equivalence substitute₁ = substitute₁ᵣ unaryRelator = resolve UnaryRelator -- The binary relator `_▫_` "(behaves like)/is a relator" in the context of `_≡_` from the Equiv instance. module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (_▫_ : A → B → Stmt{ℓₗ₃}) where open Structure.Relator.Properties record BinaryRelator : Stmt{ℓₒ₁ Lvl.⊔ ℓₒ₂ Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓₗ₃} where constructor intro field substitution : Names.Substitution₂(_▫_) left : ∀{x} → UnaryRelator(_▫ x) left = intro(\p → substitution p (reflexivity(_≡_))) right : ∀{x} → UnaryRelator(x ▫_) right = intro(\p → substitution (reflexivity(_≡_)) p) substitutionₗ = \{a x y} → UnaryRelator.substitution(left {a}) {x}{y} substitutionᵣ = \{a x y} → UnaryRelator.substitution(right{a}) {x}{y} substitution-sym : ∀{x₁ y₁ : A}{x₂ y₂ : B} → (x₁ ≡ y₁) → (x₂ ≡ y₂) → ((x₁ ▫ x₂) ← (y₁ ▫ y₂)) substitution-sym xy1 xy2 = substitution (Structure.Relator.Properties.symmetry(_≡_) xy1) (Structure.Relator.Properties.symmetry(_≡_) xy2) substitution-equivalence : ∀{x₁ y₁ : A}{x₂ y₂ : B} → (x₁ ≡ y₁) → (x₂ ≡ y₂) → ((x₁ ▫ x₂) ↔ (y₁ ▫ y₂)) substitution-equivalence xy1 xy2 = [↔]-intro (substitution-sym xy1 xy2) (substitution xy1 xy2) substitute₂ = inst-fn BinaryRelator.substitution substitute₂ₗ = inst-fn BinaryRelator.substitutionₗ substitute₂ᵣ = inst-fn BinaryRelator.substitutionᵣ substitute₂ₗᵣ = inst-fn BinaryRelator.substitution-equivalence binaryRelator = resolve BinaryRelator module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ {C : Type{ℓₒ₃}} ⦃ _ : Equiv{ℓₗ₃}(C) ⦄ (_▫_▫_ : A → B → C → Stmt{ℓₗ₄}) where open Structure.Relator.Properties record TrinaryRelator : Stmt{ℓₒ₁ Lvl.⊔ ℓₒ₂ Lvl.⊔ ℓₒ₃ Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓₗ₄} where constructor intro field substitution : Names.Substitution₃(_▫_▫_) unary₁ : ∀{y z} → UnaryRelator(_▫ y ▫ z) unary₁ = intro(\p → substitution p (reflexivity(_≡_)) (reflexivity(_≡_))) unary₂ : ∀{x z} → UnaryRelator(x ▫_▫ z) unary₂ = intro(\p → substitution (reflexivity(_≡_)) p (reflexivity(_≡_))) unary₃ : ∀{x y} → UnaryRelator(x ▫ y ▫_) unary₃ = intro(\p → substitution (reflexivity(_≡_)) (reflexivity(_≡_)) p) binary₁₂ : ∀{z} → BinaryRelator(_▫_▫ z) binary₁₂ = intro(\p q → substitution p q (reflexivity(_≡_))) binary₁₃ : ∀{y} → BinaryRelator(_▫ y ▫_) binary₁₃ = intro(\p q → substitution p (reflexivity(_≡_)) q) binary₂₃ : ∀{x} → BinaryRelator(x ▫_▫_) binary₂₃ = intro(\p q → substitution (reflexivity(_≡_)) p q) substitution-unary₁ = \{a b x y} → UnaryRelator.substitution(unary₁ {a}{b}) {x}{y} substitution-unary₂ = \{a b x y} → UnaryRelator.substitution(unary₂ {a}{b}) {x}{y} substitution-unary₃ = \{a b x y} → UnaryRelator.substitution(unary₃ {a}{b}) {x}{y} substitution-binary₁₂ = \{a x₁ x₂ y₁ y₂} → BinaryRelator.substitution(binary₁₂ {a}) {x₁}{x₂}{y₁}{y₂} substitution-binary₁₃ = \{a x₁ x₂ y₁ y₂} → BinaryRelator.substitution(binary₁₃ {a}) {x₁}{x₂}{y₁}{y₂} substitution-binary₂₃ = \{a x₁ x₂ y₁ y₂} → BinaryRelator.substitution(binary₂₃ {a}) {x₁}{x₂}{y₁}{y₂} substitute₃ = inst-fn TrinaryRelator.substitution substitute₃-unary₁ = inst-fn TrinaryRelator.substitution-unary₁ substitute₃-unary₂ = inst-fn TrinaryRelator.substitution-unary₂ substitute₃-unary₃ = inst-fn TrinaryRelator.substitution-unary₃ substitute₃-binary₁₂ = inst-fn TrinaryRelator.substitution-binary₁₂ substitute₃-binary₁₃ = inst-fn TrinaryRelator.substitution-binary₁₃ substitute₃-binary₂₃ = inst-fn TrinaryRelator.substitution-binary₂₃ trinaryRelator = resolve TrinaryRelator
55.009804
162
0.663162
5065f13c75df4ba68fcfb4f294e4bf9ab7d2a742
531
agda
Agda
Data/Boolean.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Data/Boolean.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Data/Boolean.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Data.Boolean where import Lvl open import Type -- Boolean type data Bool : Type{Lvl.𝟎} where 𝑇 : Bool -- Represents truth 𝐹 : Bool -- Represents falsity {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE 𝑇 #-} {-# BUILTIN FALSE 𝐹 #-} elim : ∀{ℓ}{T : Bool → Type{ℓ}} → T(𝑇) → T(𝐹) → ((b : Bool) → T(b)) elim t _ 𝑇 = t elim _ f 𝐹 = f not : Bool → Bool not 𝑇 = 𝐹 not 𝐹 = 𝑇 {-# COMPILE GHC not = not #-} -- Control-flow if-else expression if_then_else_ : ∀{ℓ}{T : Type{ℓ}} → Bool → T → T → T if b then t else f = elim t f b
19.666667
67
0.587571
10ba03a5545ee26c676b3ee95a49fada4c6e021f
1,855
agda
Agda
test/Fail/Issue1946-4.agda
caryoscelus/agda
98d6f195fe672e54ef0389b4deb62e04e3e98327
[ "BSD-3-Clause" ]
null
null
null
test/Fail/Issue1946-4.agda
caryoscelus/agda
98d6f195fe672e54ef0389b4deb62e04e3e98327
[ "BSD-3-Clause" ]
null
null
null
test/Fail/Issue1946-4.agda
caryoscelus/agda
98d6f195fe672e54ef0389b4deb62e04e3e98327
[ "BSD-3-Clause" ]
null
null
null
-- A minor variant of code reported by Andreas Abel. -- Andreas, 2011-10-04 -- -- Agda's coinduction is incompatible with initial algebras -- -- Sized types are needed to formulate initial algebras in general: -- {-# OPTIONS --sized-types #-} -- -- We need to skip the positivity check since we cannot communicate -- to Agda that we only want strictly positive F's in the definition of Mu -- {-# OPTIONS --no-positivity-check #-} -- module _ where open import Agda.Builtin.Coinduction renaming (∞ to co) open import Agda.Builtin.Size -- initial algebras data Mu (F : Set → Set) : Size → Set where inn : ∀ {i} → F (Mu F i) → Mu F (↑ i) iter : ∀ {F : Set → Set} (map : ∀ {A B} → (A → B) → F A → F B) {A} → (F A → A) → ∀ {i} → Mu F i → A iter map s (inn t) = s (map (iter map s) t) -- the co functor (aka Lift functor) F : Set → Set F A = co A map : ∀ {A B : Set} → (A → B) → co A → co B map f a = ♯ f (♭ a) -- the least fixed-point of co is inhabited bla : Mu F ∞ bla = inn (♯ bla) -- and goal! data ⊥ : Set where false : ⊥ false = iter map ♭ bla -- note that co is indeed strictly positive, as the following -- direct definition of Mu F ∞ is accepted data Bla : Set where c : co Bla → Bla {- -- if we inline ♭ map into iter, the termination checker detects the cheat iter' : Bla → ⊥ iter' (c t) = ♭ (♯ iter' (♭ t)) -- iter' (c t) = ♭ (map iter' t) -} -- Again, I want to emphasize that the problem is not with sized types. -- I have only used sized types to communicate to Agda that initial algebras -- (F, iter) are ok. Once we have initial algebras, we can form the -- initial algebra of the co functor and abuse the guardedness checker -- to construct an inhabitant in this empty initial algebra. -- -- Agda's coinduction mechanism confuses constructor and coconstructors. -- Convenient, but, as you have seen...
26.126761
77
0.644205
23f1df1b3343c69b46cb95f054bc1cee4742c385
12,234
agda
Agda
Definition/Typed/Consequences/Inequality.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
30
2017-05-20T03:05:21.000Z
2022-03-30T18:01:07.000Z
Definition/Typed/Consequences/Inequality.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
4
2017-06-22T12:49:23.000Z
2021-02-22T10:37:24.000Z
Definition/Typed/Consequences/Inequality.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
8
2017-10-18T14:18:20.000Z
2021-11-27T15:58:33.000Z
{-# OPTIONS --without-K --safe #-} module Definition.Typed.Consequences.Inequality where open import Definition.Untyped hiding (U≢ne; ℕ≢ne; B≢ne; U≢B; ℕ≢B) open import Definition.Typed open import Definition.Typed.EqRelInstance open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.ShapeView open import Definition.LogicalRelation.Fundamental.Reducibility open import Definition.Typed.Consequences.Syntactic open import Tools.Nat open import Tools.Product open import Tools.Empty private variable n : Nat Γ : Con Term n A≢B : ∀ {A B Γ} (_⊩′⟨_⟩A_ _⊩′⟨_⟩B_ : Con Term n → TypeLevel → Term n → Set) (A-intr : ∀ {l} → Γ ⊩′⟨ l ⟩A A → Γ ⊩⟨ l ⟩ A) (B-intr : ∀ {l} → Γ ⊩′⟨ l ⟩B B → Γ ⊩⟨ l ⟩ B) (A-elim : ∀ {l} → Γ ⊩⟨ l ⟩ A → ∃ λ l′ → Γ ⊩′⟨ l′ ⟩A A) (B-elim : ∀ {l} → Γ ⊩⟨ l ⟩ B → ∃ λ l′ → Γ ⊩′⟨ l′ ⟩B B) (A≢B′ : ∀ {l l′} ([A] : Γ ⊩′⟨ l ⟩A A) ([B] : Γ ⊩′⟨ l′ ⟩B B) → ShapeView Γ l l′ A B (A-intr [A]) (B-intr [B]) → ⊥) → Γ ⊢ A ≡ B → ⊥ A≢B {A} {B} _ _ A-intr B-intr A-elim B-elim A≢B′ A≡B with reducibleEq A≡B A≢B {A} {B} _ _ A-intr B-intr A-elim B-elim A≢B′ A≡B | [A] , [B] , [A≡B] = let _ , [A]′ = A-elim ([A]) _ , [B]′ = B-elim ([B]) [A≡B]′ = irrelevanceEq [A] (A-intr [A]′) [A≡B] in A≢B′ [A]′ [B]′ (goodCases (A-intr [A]′) (B-intr [B]′) [A≡B]′) U≢ℕ′ : ∀ {B l l′} ([U] : Γ ⊩′⟨ l ⟩U) ([ℕ] : Γ ⊩ℕ B) → ShapeView Γ l l′ _ _ (Uᵣ [U]) (ℕᵣ [ℕ]) → ⊥ U≢ℕ′ a b () U≢ℕ-red : ∀ {B} → Γ ⊢ B ⇒* ℕ → Γ ⊢ U ≡ B → ⊥ U≢ℕ-red D = A≢B (λ Γ l A → Γ ⊩′⟨ l ⟩U) (λ Γ l B → Γ ⊩ℕ B) Uᵣ ℕᵣ (λ x → extractMaybeEmb (U-elim x)) (λ x → extractMaybeEmb (ℕ-elim′ D x)) U≢ℕ′ -- U and ℕ cannot be judgmentally equal. U≢ℕ : Γ ⊢ U ≡ ℕ → ⊥ U≢ℕ U≡ℕ = let _ , ⊢ℕ = syntacticEq U≡ℕ in U≢ℕ-red (id ⊢ℕ) U≡ℕ -- U and Empty U≢Empty′ : ∀ {B l l′} ([U] : Γ ⊩′⟨ l ⟩U) ([Empty] : Γ ⊩Empty B) → ShapeView Γ l l′ _ _ (Uᵣ [U]) (Emptyᵣ [Empty]) → ⊥ U≢Empty′ a b () U≢Empty-red : ∀ {B} → Γ ⊢ B ⇒* Empty → Γ ⊢ U ≡ B → ⊥ U≢Empty-red D = A≢B (λ Γ l A → Γ ⊩′⟨ l ⟩U) (λ Γ l B → Γ ⊩Empty B) Uᵣ Emptyᵣ (λ x → extractMaybeEmb (U-elim x)) (λ x → extractMaybeEmb (Empty-elim′ D x)) U≢Empty′ U≢Emptyⱼ : Γ ⊢ U ≡ Empty → ⊥ U≢Emptyⱼ U≡Empty = let _ , ⊢Empty = syntacticEq U≡Empty in U≢Empty-red (id ⊢Empty) U≡Empty -- U and Unit U≢Unit′ : ∀ {B l l′} ([U] : Γ ⊩′⟨ l ⟩U) ([Unit] : Γ ⊩Unit B) → ShapeView Γ l l′ _ _ (Uᵣ [U]) (Unitᵣ [Unit]) → ⊥ U≢Unit′ a b () U≢Unit-red : ∀ {B} → Γ ⊢ B ⇒* Unit → Γ ⊢ U ≡ B → ⊥ U≢Unit-red D = A≢B (λ Γ l A → Γ ⊩′⟨ l ⟩U) (λ Γ l B → Γ ⊩Unit B) Uᵣ Unitᵣ (λ x → extractMaybeEmb (U-elim x)) (λ x → extractMaybeEmb (Unit-elim′ D x)) U≢Unit′ U≢Unitⱼ : Γ ⊢ U ≡ Unit → ⊥ U≢Unitⱼ U≡Unit = let _ , ⊢Unit = syntacticEq U≡Unit in U≢Unit-red (id ⊢Unit) U≡Unit -- ℕ and Empty ℕ≢Empty′ : ∀ {B l l'} ([ℕ] : Γ ⊩ℕ ℕ) ([Empty] : Γ ⊩Empty B) → ShapeView Γ l l' _ _ (ℕᵣ [ℕ]) (Emptyᵣ [Empty]) → ⊥ ℕ≢Empty′ a b () ℕ≢Empty-red : ∀ {B} → Γ ⊢ B ⇒* Empty → Γ ⊢ ℕ ≡ B → ⊥ ℕ≢Empty-red D = A≢B (λ Γ l A → Γ ⊩ℕ A) (λ Γ l B → Γ ⊩Empty B) ℕᵣ Emptyᵣ (λ x → extractMaybeEmb (ℕ-elim x)) (λ x → extractMaybeEmb (Empty-elim′ D x)) ℕ≢Empty′ ℕ≢Emptyⱼ : Γ ⊢ ℕ ≡ Empty → ⊥ ℕ≢Emptyⱼ ℕ≡Empty = let _ , ⊢Empty = syntacticEq ℕ≡Empty in ℕ≢Empty-red (id ⊢Empty) ℕ≡Empty -- ℕ and Unit ℕ≢Unit′ : ∀ {B l l'} ([ℕ] : Γ ⊩ℕ ℕ) ([Unit] : Γ ⊩Unit B) → ShapeView Γ l l' _ _ (ℕᵣ [ℕ]) (Unitᵣ [Unit]) → ⊥ ℕ≢Unit′ a b () ℕ≢Unit-red : ∀ {B} → Γ ⊢ B ⇒* Unit → Γ ⊢ ℕ ≡ B → ⊥ ℕ≢Unit-red D = A≢B (λ Γ l A → Γ ⊩ℕ A) (λ Γ l B → Γ ⊩Unit B) ℕᵣ Unitᵣ (λ x → extractMaybeEmb (ℕ-elim x)) (λ x → extractMaybeEmb (Unit-elim′ D x)) ℕ≢Unit′ ℕ≢Unitⱼ : Γ ⊢ ℕ ≡ Unit → ⊥ ℕ≢Unitⱼ ℕ≡Unit = let _ , ⊢Unit = syntacticEq ℕ≡Unit in ℕ≢Unit-red (id ⊢Unit) ℕ≡Unit -- Empty and Unit Empty≢Unit′ : ∀ {B l l'} ([Empty] : Γ ⊩Empty Empty) ([Unit] : Γ ⊩Unit B) → ShapeView Γ l l' _ _ (Emptyᵣ [Empty]) (Unitᵣ [Unit]) → ⊥ Empty≢Unit′ a b () Empty≢Unit-red : ∀ {B} → Γ ⊢ B ⇒* Unit → Γ ⊢ Empty ≡ B → ⊥ Empty≢Unit-red D = A≢B (λ Γ l A → Γ ⊩Empty A) (λ Γ l B → Γ ⊩Unit B) Emptyᵣ Unitᵣ (λ x → extractMaybeEmb (Empty-elim x)) (λ x → extractMaybeEmb (Unit-elim′ D x)) Empty≢Unit′ Empty≢Unitⱼ : Γ ⊢ Empty ≡ Unit → ⊥ Empty≢Unitⱼ Empty≡Unit = let _ , ⊢Unit = syntacticEq Empty≡Unit in Empty≢Unit-red (id ⊢Unit) Empty≡Unit -- Universe and binding types U≢B′ : ∀ {B l l′} W ([U] : Γ ⊩′⟨ l ⟩U) ([W] : Γ ⊩′⟨ l′ ⟩B⟨ W ⟩ B) → ShapeView Γ l l′ _ _ (Uᵣ [U]) (Bᵣ W [W]) → ⊥ U≢B′ W a b () U≢B-red : ∀ {B F G} W → Γ ⊢ B ⇒* ⟦ W ⟧ F ▹ G → Γ ⊢ U ≡ B → ⊥ U≢B-red W D = A≢B (λ Γ l A → Γ ⊩′⟨ l ⟩U) (λ Γ l A → Γ ⊩′⟨ l ⟩B⟨ W ⟩ A) Uᵣ (Bᵣ W) (λ x → extractMaybeEmb (U-elim x)) (λ x → extractMaybeEmb (B-elim′ W D x)) (U≢B′ W) -- U and Π F ▹ G for any F and G cannot be judgmentally equal. U≢B : ∀ {F G} W → Γ ⊢ U ≡ ⟦ W ⟧ F ▹ G → ⊥ U≢B W U≡W = let _ , ⊢W = syntacticEq U≡W in U≢B-red W (id ⊢W) U≡W U≢Π : ∀ {Γ : Con Term n} {F G} → _ U≢Π {Γ = Γ} {F} {G} = U≢B {Γ = Γ} {F} {G} BΠ U≢Σ : ∀ {Γ : Con Term n} {F G} → _ U≢Σ {Γ = Γ} {F} {G} = U≢B {Γ = Γ} {F} {G} BΣ U≢ne′ : ∀ {K l l′} ([U] : Γ ⊩′⟨ l ⟩U) ([K] : Γ ⊩ne K) → ShapeView Γ l l′ _ _ (Uᵣ [U]) (ne [K]) → ⊥ U≢ne′ a b () U≢ne-red : ∀ {B K} → Γ ⊢ B ⇒* K → Neutral K → Γ ⊢ U ≡ B → ⊥ U≢ne-red D neK = A≢B (λ Γ l A → Γ ⊩′⟨ l ⟩U) (λ Γ l B → Γ ⊩ne B) Uᵣ ne (λ x → extractMaybeEmb (U-elim x)) (λ x → extractMaybeEmb (ne-elim′ D neK x)) U≢ne′ -- U and K for any neutral K cannot be judgmentally equal. U≢ne : ∀ {K} → Neutral K → Γ ⊢ U ≡ K → ⊥ U≢ne neK U≡K = let _ , ⊢K = syntacticEq U≡K in U≢ne-red (id ⊢K) neK U≡K ℕ≢B′ : ∀ {A B l l′} W ([ℕ] : Γ ⊩ℕ A) ([W] : Γ ⊩′⟨ l′ ⟩B⟨ W ⟩ B) → ShapeView Γ l l′ _ _ (ℕᵣ [ℕ]) (Bᵣ W [W]) → ⊥ ℕ≢B′ W a b () ℕ≢B-red : ∀ {A B F G} W → Γ ⊢ A ⇒* ℕ → Γ ⊢ B ⇒* ⟦ W ⟧ F ▹ G → Γ ⊢ A ≡ B → ⊥ ℕ≢B-red W D D′ = A≢B (λ Γ l A → Γ ⊩ℕ A) (λ Γ l A → Γ ⊩′⟨ l ⟩B⟨ W ⟩ A) ℕᵣ (Bᵣ W) (λ x → extractMaybeEmb (ℕ-elim′ D x)) (λ x → extractMaybeEmb (B-elim′ W D′ x)) (ℕ≢B′ W) -- ℕ and B F ▹ G for any F and G cannot be judgmentally equal. ℕ≢B : ∀ {F G} W → Γ ⊢ ℕ ≡ ⟦ W ⟧ F ▹ G → ⊥ ℕ≢B W ℕ≡W = let ⊢ℕ , ⊢W = syntacticEq ℕ≡W in ℕ≢B-red W (id ⊢ℕ) (id ⊢W) ℕ≡W ℕ≢Π : ∀ {Γ : Con Term n} {F G} → _ ℕ≢Π {Γ = Γ} {F} {G} = ℕ≢B {Γ = Γ} {F} {G} BΠ ℕ≢Σ : ∀ {Γ : Con Term n} {F G} → _ ℕ≢Σ {Γ = Γ} {F} {G} = ℕ≢B {Γ = Γ} {F} {G} BΣ -- Empty and Π Empty≢B′ : ∀ {A B l l′} W ([Empty] : Γ ⊩Empty A) ([W] : Γ ⊩′⟨ l′ ⟩B⟨ W ⟩ B) → ShapeView Γ l l′ _ _ (Emptyᵣ [Empty]) (Bᵣ W [W]) → ⊥ Empty≢B′ W a b () Empty≢B-red : ∀ {A B F G} W → Γ ⊢ A ⇒* Empty → Γ ⊢ B ⇒* ⟦ W ⟧ F ▹ G → Γ ⊢ A ≡ B → ⊥ Empty≢B-red W D D′ = A≢B (λ Γ l A → Γ ⊩Empty A) (λ Γ l A → Γ ⊩′⟨ l ⟩B⟨ W ⟩ A) Emptyᵣ (Bᵣ W) (λ x → extractMaybeEmb (Empty-elim′ D x)) (λ x → extractMaybeEmb (B-elim′ W D′ x)) (Empty≢B′ W) Empty≢Bⱼ : ∀ {F G} W → Γ ⊢ Empty ≡ ⟦ W ⟧ F ▹ G → ⊥ Empty≢Bⱼ W Empty≡W = let ⊢Empty , ⊢W = syntacticEq Empty≡W in Empty≢B-red W (id ⊢Empty) (id ⊢W) Empty≡W Empty≢Πⱼ : ∀ {Γ : Con Term n} {F G} → _ Empty≢Πⱼ {Γ = Γ} {F} {G} = Empty≢Bⱼ {Γ = Γ} {F} {G} BΠ Empty≢Σⱼ : ∀ {Γ : Con Term n} {F G} → _ Empty≢Σⱼ {Γ = Γ} {F} {G} = Empty≢Bⱼ {Γ = Γ} {F} {G} BΣ -- Unit and Π Unit≢B′ : ∀ {A B l l′} W ([Unit] : Γ ⊩Unit A) ([W] : Γ ⊩′⟨ l′ ⟩B⟨ W ⟩ B) → ShapeView Γ l l′ _ _ (Unitᵣ [Unit]) (Bᵣ W [W]) → ⊥ Unit≢B′ W a b () Unit≢B-red : ∀ {A B F G} W → Γ ⊢ A ⇒* Unit → Γ ⊢ B ⇒* ⟦ W ⟧ F ▹ G → Γ ⊢ A ≡ B → ⊥ Unit≢B-red W D D′ = A≢B (λ Γ l A → Γ ⊩Unit A) (λ Γ l A → Γ ⊩′⟨ l ⟩B⟨ W ⟩ A) Unitᵣ (Bᵣ W) (λ x → extractMaybeEmb (Unit-elim′ D x)) (λ x → extractMaybeEmb (B-elim′ W D′ x)) (Unit≢B′ W) Unit≢Bⱼ : ∀ {F G} W → Γ ⊢ Unit ≡ ⟦ W ⟧ F ▹ G → ⊥ Unit≢Bⱼ W Unit≡W = let ⊢Unit , ⊢W = syntacticEq Unit≡W in Unit≢B-red W (id ⊢Unit) (id ⊢W) Unit≡W Unit≢Πⱼ : ∀ {Γ : Con Term n} {F G} → _ Unit≢Πⱼ {Γ = Γ} {F} {G} = Unit≢Bⱼ {Γ = Γ} {F} {G} BΠ Unit≢Σⱼ : ∀ {Γ : Con Term n} {F G} → _ Unit≢Σⱼ {Γ = Γ} {F} {G} = Unit≢Bⱼ {Γ = Γ} {F} {G} BΣ ℕ≢ne′ : ∀ {A K l l′} ([ℕ] : Γ ⊩ℕ A) ([K] : Γ ⊩ne K) → ShapeView Γ l l′ _ _ (ℕᵣ [ℕ]) (ne [K]) → ⊥ ℕ≢ne′ a b () ℕ≢ne-red : ∀ {A B K} → Γ ⊢ A ⇒* ℕ → Γ ⊢ B ⇒* K → Neutral K → Γ ⊢ A ≡ B → ⊥ ℕ≢ne-red D D′ neK = A≢B (λ Γ l A → Γ ⊩ℕ A) (λ Γ l B → Γ ⊩ne B) ℕᵣ ne (λ x → extractMaybeEmb (ℕ-elim′ D x)) (λ x → extractMaybeEmb (ne-elim′ D′ neK x)) ℕ≢ne′ -- ℕ and K for any neutral K cannot be judgmentally equal. ℕ≢ne : ∀ {K} → Neutral K → Γ ⊢ ℕ ≡ K → ⊥ ℕ≢ne neK ℕ≡K = let ⊢ℕ , ⊢K = syntacticEq ℕ≡K in ℕ≢ne-red (id ⊢ℕ) (id ⊢K) neK ℕ≡K -- Empty and neutral Empty≢ne′ : ∀ {A K l l′} ([Empty] : Γ ⊩Empty A) ([K] : Γ ⊩ne K) → ShapeView Γ l l′ _ _ (Emptyᵣ [Empty]) (ne [K]) → ⊥ Empty≢ne′ a b () Empty≢ne-red : ∀ {A B K} → Γ ⊢ A ⇒* Empty → Γ ⊢ B ⇒* K → Neutral K → Γ ⊢ A ≡ B → ⊥ Empty≢ne-red D D′ neK = A≢B (λ Γ l A → Γ ⊩Empty A) (λ Γ l B → Γ ⊩ne B) Emptyᵣ ne (λ x → extractMaybeEmb (Empty-elim′ D x)) (λ x → extractMaybeEmb (ne-elim′ D′ neK x)) Empty≢ne′ Empty≢neⱼ : ∀ {K} → Neutral K → Γ ⊢ Empty ≡ K → ⊥ Empty≢neⱼ neK Empty≡K = let ⊢Empty , ⊢K = syntacticEq Empty≡K in Empty≢ne-red (id ⊢Empty) (id ⊢K) neK Empty≡K -- Unit and neutral Unit≢ne′ : ∀ {A K l l′} ([Unit] : Γ ⊩Unit A) ([K] : Γ ⊩ne K) → ShapeView Γ l l′ _ _ (Unitᵣ [Unit]) (ne [K]) → ⊥ Unit≢ne′ a b () Unit≢ne-red : ∀ {A B K} → Γ ⊢ A ⇒* Unit → Γ ⊢ B ⇒* K → Neutral K → Γ ⊢ A ≡ B → ⊥ Unit≢ne-red D D′ neK = A≢B (λ Γ l A → Γ ⊩Unit A) (λ Γ l B → Γ ⊩ne B) Unitᵣ ne (λ x → extractMaybeEmb (Unit-elim′ D x)) (λ x → extractMaybeEmb (ne-elim′ D′ neK x)) Unit≢ne′ Unit≢neⱼ : ∀ {K} → Neutral K → Γ ⊢ Unit ≡ K → ⊥ Unit≢neⱼ neK Unit≡K = let ⊢Unit , ⊢K = syntacticEq Unit≡K in Unit≢ne-red (id ⊢Unit) (id ⊢K) neK Unit≡K B≢ne′ : ∀ {A K l l′} W ([W] : Γ ⊩′⟨ l ⟩B⟨ W ⟩ A) ([K] : Γ ⊩ne K) → ShapeView Γ l l′ _ _ (Bᵣ W [W]) (ne [K]) → ⊥ B≢ne′ W a b () B≢ne-red : ∀ {A B F G K} W → Γ ⊢ A ⇒* ⟦ W ⟧ F ▹ G → Γ ⊢ B ⇒* K → Neutral K → Γ ⊢ A ≡ B → ⊥ B≢ne-red W D D′ neK = A≢B (λ Γ l A → Γ ⊩′⟨ l ⟩B⟨ W ⟩ A) (λ Γ l B → Γ ⊩ne B) (Bᵣ W) ne (λ x → extractMaybeEmb (B-elim′ W D x)) (λ x → extractMaybeEmb (ne-elim′ D′ neK x)) (B≢ne′ W) -- ⟦ W ⟧ F ▹ G and K for any W, F, G and neutral K cannot be judgmentally equal. B≢ne : ∀ {F G K} W → Neutral K → Γ ⊢ ⟦ W ⟧ F ▹ G ≡ K → ⊥ B≢ne W neK W≡K = let ⊢W , ⊢K = syntacticEq W≡K in B≢ne-red W (id ⊢W) (id ⊢K) neK W≡K Π≢ne : ∀ {Γ : Con Term n} {F G K} → _ Π≢ne {Γ = Γ} {F} {G} {K} = B≢ne {Γ = Γ} {F} {G} {K} BΠ Σ≢ne : ∀ {Γ : Con Term n} {F G K} → _ Σ≢ne {Γ = Γ} {F} {G} {K} = B≢ne {Γ = Γ} {F} {G} {K} BΣ -- Π and Σ Π≢Σ′ : ∀ {A B l l′} ([A] : Γ ⊩′⟨ l ⟩B⟨ BΠ ⟩ A) ([B] : Γ ⊩′⟨ l′ ⟩B⟨ BΣ ⟩ B) → ShapeView Γ l l′ _ _ (Bᵣ BΠ [A]) (Bᵣ BΣ [B]) → ⊥ Π≢Σ′ a b () Π≢Σ-red : ∀ {A B F G H E} → Γ ⊢ A ⇒* Π F ▹ G → Γ ⊢ B ⇒* Σ H ▹ E → Γ ⊢ A ≡ B → ⊥ Π≢Σ-red D D′ = A≢B (λ Γ l A → Γ ⊩′⟨ l ⟩B⟨ BΠ ⟩ A) (λ Γ l A → Γ ⊩′⟨ l ⟩B⟨ BΣ ⟩ A) (Bᵣ BΠ) (Bᵣ BΣ) (λ x → extractMaybeEmb (B-elim′ BΠ D x)) (λ x → extractMaybeEmb (B-elim′ BΣ D′ x)) Π≢Σ′ Π≢Σ : ∀ {F G H E} → Γ ⊢ Π F ▹ G ≡ Σ H ▹ E → ⊥ Π≢Σ Π≡Σ = let ⊢Π , ⊢Σ = syntacticEq Π≡Σ in Π≢Σ-red (id ⊢Π) (id ⊢Σ) Π≡Σ
33.79558
83
0.436243
10cd915b64022e094dcfc20eb593685faae7d609
159
agda
Agda
prototyping/Luau/Var/ToString.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
1
2022-03-18T04:10:20.000Z
2022-03-18T04:10:20.000Z
prototyping/Luau/Var/ToString.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
prototyping/Luau/Var/ToString.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
module Luau.Var.ToString where open import Agda.Builtin.String using (String) open import Luau.Var using (Var) varToString : Var → String varToString x = x
17.666667
46
0.767296
d0aa5d3a1c8e276aa299609e1fdc7a075408468e
1,063
agda
Agda
src/Categories/Category/Construction/SetoidDiscrete.agda
yourboynico/agda-categories
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Construction/SetoidDiscrete.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Construction/SetoidDiscrete.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Category.Construction.SetoidDiscrete where open import Data.Unit using (⊤; tt) open import Function using (flip) open import Level using (Lift; lift) open import Relation.Binary using (Setoid; IsEquivalence) open import Categories.Category.Core using (Category) open import Categories.Category.Discrete using (DiscreteCategory) open import Categories.Morphism using (_≅_; ≅-isEquivalence) {- This is a better version of Discrete, which is more in line with the rest of this library, and makes a Category out of a Setoid. It is still 'wrong' as the equivalence is completely uninformative. -} Discrete : ∀ {o ℓ e} (A : Setoid o ℓ) → DiscreteCategory o ℓ e Discrete {o} {ℓ} {e} A = record { category = C ; isDiscrete = record { isGroupoid = record { _⁻¹ = sym } } } where open Setoid A C : Category o ℓ e C = record { Obj = Carrier ; _⇒_ = _≈_ ; _≈_ = λ _ _ → Lift e ⊤ ; id = Setoid.refl A ; _∘_ = flip trans }
30.371429
68
0.651929
390a0078c4784b5644517431d823e544f181632e
4,423
agda
Agda
src/SizedIO/coIOIOObject.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
23
2016-06-19T12:57:55.000Z
2020-10-12T23:15:25.000Z
src/SizedIO/coIOIOObject.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
null
null
null
src/SizedIO/coIOIOObject.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
2
2018-09-01T15:02:37.000Z
2022-03-12T11:41:00.000Z
module SizedIO.coIOIOObject where open import Data.Unit.Base open import Data.Product open import Data.String.Base open import Size open import SizedIO.Object open import SizedIO.Base open import SizedIO.Console open import SizedIO.coIOIO -- open import SizedIO.IOObject record IOObject' (i : Size) (iface : Interface)(C : Set)(R : C → Set) : Set where coinductive field method : ∀{j : Size< i} (m : Method iface) → IO j C R (Response iface m × IOObject' j iface C R) open IOObject' public -- An IO object is like a simple object, -- but the method returns IO applied to the result type of a simple object -- which means the method returns an IO program which when terminating -- returns the result of the simple object record coIO²Object (i : Size) (iface : Interface) (Cin : Set)(Rin : Cin → Set) (Cext : Set)(Rext : Cext → Set) : Set where coinductive field method' : ∀{j : Size< i} (m : Method iface) → coIO²∞ ∞ Cin Rin Cext Rext (Response iface m × coIO²Object j iface Cin Rin Cext Rext) open coIO²Object public selfrefIOObject : (i : Size) (iface : Interface) (Cext : Set) (Rext : Cext → Set) → Set selfrefIOObject i iface Cext Rext = coIO²Object i iface (Method iface) (Response iface) Cext Rext mutual compileSelfRef : (i : Size) (iface : Interface) (Cext : Set) (Rext : Cext → Set) (obj : selfrefIOObject i iface Cext Rext) → IOObject' i iface Cext Rext IO.force (method (compileSelfRef i iface Cext Rext obj) {i'} m) {j} = compileSelfRefaux i' j iface Cext Rext (Response iface m) (coIO²∞.force (method' obj {i'} m) j) compileSelfRefaux : (i : Size) (j : Size< i) (iface : Interface) (let M = Method iface) (let R = Response iface) (Cext : Set) (Rext : Cext → Set) (A : Set) (coObj : coIO² ∞ j M R Cext Rext (A × coIO²Object i iface M R Cext Rext)) → IO' j Cext Rext (A × IOObject' i iface Cext Rext) compileSelfRefaux i j iface Cext Rext A (coIO².return (r , obj)) = return' (r , compileSelfRef i iface Cext Rext obj) compileSelfRefaux i j iface Cext Rext A (dof i' m f) = {! >>=!} compileSelfRefaux i j iface Cext Rext A (do∞ c f) = do' c (λ r → compileSelfRefaux'' i j iface Cext Rext A (f r)) compileSelfRefaux'' : (i : Size) (j : Size< i) (iface : Interface) (let M = Method iface) (let R = Response iface) (Cext : Set) (Rext : Cext → Set) (A : Set) (coObj : coIO²∞ j M R Cext Rext (A × coIO²Object i iface M R Cext Rext)) → IO j Cext Rext (A × IOObject' i iface Cext Rext) IO.force (compileSelfRefaux'' i j iface Cext Rext A coObj) {j''} = compileSelfRefaux i j'' iface Cext Rext A (coIO²∞.force coObj j'') -- compileSelfRefaux'' i' j iface Cext Rext A coObj -- = compileSelfRefaux' i' j iface Cext Rext A (coIO²∞.force coObj {!!}) {- compileSelfRefaux' : (i' : Size) (j : Size< i') (iface : Interface) (let M = Methods iface) (let R = Responses iface) (Cext : Set) (Rext : Cext → Set) (A : Set) (coObj : coIO² ∞ j M R Cext Rext (A × coIO²Object i' iface M R Cext Rext)) → IO j Cext Rext (A × IOObject' i' iface Cext Rext) IO.force (compileSelfRefaux' i' j iface Cext Rext A coObj) = compileSelfRefaux i' j iface Cext Rext A coObj -} {- 123;456hallo789 123;456hallo789 123;789hallo456 123;789hallo456 123;789456 123;789456 123;456789 123;456789 123;456789 123;456789 C-x r k -- kill rectangle C-x r y -- yank rectangle C-x r t -- text rectangle -} {- M-x abbrev-mode C-x ail crosss → \ -} -- method' obj {j'} m {- compileSelfRefaux : (j' : Size) (iface : Interface) (Cext : Set) (Rext : Cext → Set) (m : Methods iface) ( p : coIO²∞ ∞ (Methods iface) (Responses iface) Cext Rext (Responses iface m × coIO²Object j' iface (Methods iface) (Responses iface) Cext Rext)) → IO' j' Cext Rext (Responses iface m × IOObject' j iface Cext Rext)IO' j' Cext Rext (Responses iface m × IOObject' j iface Cext Rext) -}
32.050725
135
0.582636
fb189a2ac0c648021e4bf61b3378c80a25582b0e
8,092
agda
Agda
src/Web/Semantic/DL/Category/Wiring.agda
agda/agda-web-semantic
8ddbe83965a616bff6fc7a237191fa261fa78bab
[ "MIT" ]
9
2015-09-13T17:46:41.000Z
2020-03-14T14:21:08.000Z
src/Web/Semantic/DL/Category/Wiring.agda
agda/agda-web-semantic
8ddbe83965a616bff6fc7a237191fa261fa78bab
[ "MIT" ]
4
2018-11-14T02:32:28.000Z
2021-01-04T20:57:19.000Z
src/Web/Semantic/DL/Category/Wiring.agda
agda/agda-web-semantic
8ddbe83965a616bff6fc7a237191fa261fa78bab
[ "MIT" ]
3
2017-12-03T14:52:09.000Z
2022-03-12T11:40:03.000Z
open import Data.List using ( List ; [] ; _∷_ ) open import Data.List.Any using ( here ; there ) open import Data.Product using ( _,_ ; proj₁ ; proj₂ ) open import Data.Sum using ( inj₁ ; inj₂ ) open import Relation.Binary.PropositionalEquality using ( refl ; sym ; trans ; subst₂ ) open import Relation.Unary using ( _∈_ ; _⊆_ ) open import Web.Semantic.DL.ABox using ( ABox ; ε ; _,_ ; _∼_ ; ⟨ABox⟩ ; Assertions ; ⟨ABox⟩-resp-id ; ⟨ABox⟩-resp-∘ ; ⟨ABox⟩-resp-∘² ) open import Web.Semantic.DL.ABox.Interp using ( Interp ; _,_ ; ⌊_⌋ ; ind ; _*_ ) open import Web.Semantic.DL.ABox.Interp.Morphism using ( _,_ ) open import Web.Semantic.DL.ABox.Model using ( _⊨a_ ; *-resp-⟨ABox⟩ ; ⊨a-resp-⊇ ) open import Web.Semantic.DL.Category.Object using ( Object ; _,_ ; IN ; fin ; iface ) open import Web.Semantic.DL.Category.Morphism using ( _⇒_ ; _,_ ; BN ; impl ) open import Web.Semantic.DL.Category.Tensor using ( _⊗_ ) open import Web.Semantic.DL.Category.Unit using ( I ) open import Web.Semantic.DL.Integrity using ( Unique ; Mediator ; Initial ; _⊕_⊨_ ; _,_ ) open import Web.Semantic.DL.KB using ( _,_ ) open import Web.Semantic.DL.KB.Model using ( _⊨_ ) open import Web.Semantic.DL.Signature using ( Signature ) open import Web.Semantic.DL.TBox using ( TBox ; _,_ ) open import Web.Semantic.DL.TBox.Interp using ( _⊨_≈_ ; ≈-refl ; ≈-sym ; ≈-trans ) open import Web.Semantic.DL.TBox.Interp.Morphism using ( ≲-refl ; ≲-image ) open import Web.Semantic.DL.TBox.Model using ( _⊨t_ ) open import Web.Semantic.Util using ( id ; _∘_ ; False ; tt ; ⊎-swap ; ⊎-assoc ; ⊎-assoc⁻¹ ; ⊎-unit₁ ; ⊎-unit₂ ; _∈ˡ_ ; _⊕_⊕_ ; inode ; bnode ; enode ) module Web.Semantic.DL.Category.Wiring {Σ : Signature} where wires : ∀ {X Y} → (Y → X) → List Y → ABox Σ (X ⊕ False ⊕ Y) wires f [] = ε wires f (y ∷ ys) = (inode (f y) ∼ enode y , wires f ys) wires-≈ : ∀ {X Y y ys I} (f : Y → X) → (y ∈ˡ ys) → (I ⊨a wires f ys) → (⌊ I ⌋ ⊨ ind I (inode (f y)) ≈ ind I (enode y)) wires-≈ f (here refl) (x≈y , xs≈ys) = x≈y wires-≈ f (there y∈ys) (x≈y , xs≈ys) = wires-≈ f y∈ys xs≈ys wires-≈⁻¹ : ∀ {X Y I} (f : Y → X) → (∀ y → ⌊ I ⌋ ⊨ ind I (inode (f y)) ≈ ind I (enode y)) → ∀ ys → (I ⊨a wires f ys) wires-≈⁻¹ f ∀y∙x≈y [] = tt wires-≈⁻¹ f ∀y∙x≈y (y ∷ ys) = (∀y∙x≈y y , wires-≈⁻¹ f ∀y∙x≈y ys) wired : ∀ {X Y} → (Y → X) → (X ⊕ False ⊕ Y) → X wired f (inode x) = x wired f (bnode ()) wired f (enode y) = f y wired-init : ∀ {X Y} (f : Y → X) ys → (∀ y → y ∈ˡ ys) → (I : Interp Σ X) → (S : TBox Σ) → (⌊ I ⌋ ⊨t S) → (wired f * I ∈ Initial I (S , wires f ys)) wired-init f ys ∀y∙y∈ys (I , i) S I⊨S = ( (≲-refl I , λ x → ≈-refl I) , (I⊨S , wires-≈⁻¹ f (λ x → ≈-refl I) ys) , mediator ) where mediator : Mediator (I , i) (I , i ∘ wired f) (≲-refl I , λ x → ≈-refl I) (S , wires f ys) mediator (K , k) (I≲K , i≲k) (K⊨S , K⊨F) = ((I≲K , j≲k) , (λ x → ≈-refl K) , uniq ) where j≲k : ∀ x → K ⊨ ≲-image I≲K (i (wired f x)) ≈ k x j≲k (inode x) = i≲k x j≲k (bnode ()) j≲k (enode y) = ≈-trans K (i≲k (f y)) (wires-≈ f (∀y∙y∈ys y) K⊨F) uniq : Unique (I , i) (I , i ∘ wired f) (K , k) (≲-refl I , λ x → ≈-refl I) (I≲K , i≲k) uniq J≲₁K J≲₂K I≲K≋I≲J≲₁K I≲K≋I≲J≲₂K x = ≈-trans K (≈-sym K (I≲K≋I≲J≲₁K x)) (I≲K≋I≲J≲₂K x) wires✓ : ∀ {X Y ys} (f : Y → X) → (∀ y → y ∈ˡ ys) → (S T : TBox Σ) (A : ABox Σ X) (B : ABox Σ Y) → (Assertions (⟨ABox⟩ f B) ⊆ Assertions A) → (I : Interp Σ X) → (I ⊨ (S , T) , A) → (I ⊕ S , wires f ys ⊨ T , B) wires✓ {X} {Y} {ys} f ∀y∙y∈ys S T A B B⊆A I I⊨STA = (J , J-init , (J⊨T , J⊨B)) where J : Interp Σ (X ⊕ False ⊕ Y) J = wired f * I J⊨T : ⌊ J ⌋ ⊨t T J⊨T = proj₂ (proj₁ I⊨STA) J⊨B : enode * J ⊨a B J⊨B = *-resp-⟨ABox⟩ f I B (⊨a-resp-⊇ I (⟨ABox⟩ f B) A B⊆A (proj₂ I⊨STA)) J-init : J ∈ Initial I (S , wires f ys) J-init = wired-init f ys ∀y∙y∈ys I S (proj₁ (proj₁ I⊨STA)) wiring-impl : ∀ {S T : TBox Σ} → (A B : Object S T) (f : IN B → IN A) → ABox Σ (IN A ⊕ False ⊕ IN B) wiring-impl A B f = wires f (proj₁ (fin B)) wiring-impl✓ : ∀ {S T : TBox Σ} → (A B : Object S T) (f : IN B → IN A) → (Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)) → ∀ I → (I ⊨ (S , T) , iface A) → (I ⊕ (S , wiring-impl A B f) ⊨ (T , iface B)) wiring-impl✓ {S} {T} (X , X∈Fin , A) (Y , Y∈Fin , B) f B⊆A = wires✓ f (proj₂ Y∈Fin) S T A B B⊆A wiring : ∀ {S T : TBox Σ} → (A B : Object S T) (f : IN B → IN A) → (Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)) → (A ⇒ B) wiring A B f B⊆A = ( False , wiring-impl A B f , wiring-impl✓ A B f B⊆A ) id✓ : ∀ {S T : TBox Σ} → (A : Object S T) → (Assertions (⟨ABox⟩ id (iface A)) ⊆ Assertions (iface A)) id✓ A = subst₂ Assertions (⟨ABox⟩-resp-id (iface A)) refl identity : ∀ {S T : TBox Σ} → (A : Object S T) → (A ⇒ A) identity A = wiring A A id (id✓ A) ⊎-swap✓ : ∀ {S T : TBox Σ} → (A B : Object S T) → Assertions (⟨ABox⟩ ⊎-swap (iface (B ⊗ A))) ⊆ Assertions (iface (A ⊗ B)) ⊎-swap✓ A B (inj₁ b∈B) = inj₂ (subst₂ Assertions (⟨ABox⟩-resp-∘ ⊎-swap inj₁ (iface B)) refl b∈B) ⊎-swap✓ A B (inj₂ a∈A) = inj₁ (subst₂ Assertions (⟨ABox⟩-resp-∘ ⊎-swap inj₂ (iface A)) refl a∈A) symm : ∀ {S T : TBox Σ} → (A B : Object S T) → ((A ⊗ B) ⇒ (B ⊗ A)) symm A B = wiring (A ⊗ B) (B ⊗ A) ⊎-swap (⊎-swap✓ A B) ⊎-assoc⁻¹✓ : ∀ {S T : TBox Σ} → (A B C : Object S T) → (Assertions (⟨ABox⟩ ⊎-assoc⁻¹ (iface (A ⊗ (B ⊗ C))))) ⊆ (Assertions (iface ((A ⊗ B) ⊗ C))) ⊎-assoc⁻¹✓ A B C (inj₁ a∈A) = inj₁ (inj₁ (subst₂ Assertions (trans (⟨ABox⟩-resp-∘ ⊎-assoc⁻¹ inj₁ (iface A)) (sym (⟨ABox⟩-resp-∘ inj₁ inj₁ (iface A)))) refl a∈A)) ⊎-assoc⁻¹✓ A B C (inj₂ (inj₁ b∈B)) = inj₁ (inj₂ (subst₂ Assertions (trans (⟨ABox⟩-resp-∘² ⊎-assoc⁻¹ inj₂ inj₁ (iface B)) (sym (⟨ABox⟩-resp-∘ inj₁ inj₂ (iface B)))) refl b∈B)) ⊎-assoc⁻¹✓ A B C (inj₂ (inj₂ c∈C)) = inj₂ (subst₂ Assertions (⟨ABox⟩-resp-∘² ⊎-assoc⁻¹ inj₂ inj₂ (iface C)) refl c∈C) assoc : ∀ {S T : TBox Σ} → (A B C : Object S T) → (((A ⊗ B) ⊗ C) ⇒ (A ⊗ (B ⊗ C))) assoc A B C = wiring ((A ⊗ B) ⊗ C) (A ⊗ (B ⊗ C)) ⊎-assoc⁻¹ (⊎-assoc⁻¹✓ A B C) ⊎-assoc✓ : ∀ {S T : TBox Σ} → (A B C : Object S T) → (Assertions (⟨ABox⟩ ⊎-assoc (iface ((A ⊗ B) ⊗ C)))) ⊆ (Assertions (iface (A ⊗ (B ⊗ C)))) ⊎-assoc✓ A B C (inj₁ (inj₁ a∈A)) = inj₁ (subst₂ Assertions (⟨ABox⟩-resp-∘² ⊎-assoc inj₁ inj₁ (iface A)) refl a∈A) ⊎-assoc✓ A B C (inj₁ (inj₂ b∈B)) = inj₂ (inj₁ (subst₂ Assertions (trans (⟨ABox⟩-resp-∘² ⊎-assoc inj₁ inj₂ (iface B)) (sym (⟨ABox⟩-resp-∘ inj₂ inj₁ (iface B)))) refl b∈B)) ⊎-assoc✓ A B C (inj₂ c∈C) = inj₂ (inj₂ (subst₂ Assertions (trans (⟨ABox⟩-resp-∘ ⊎-assoc inj₂ (iface C)) (sym (⟨ABox⟩-resp-∘ inj₂ inj₂ (iface C)))) refl c∈C)) assoc⁻¹ : ∀ {S T : TBox Σ} → (A B C : Object S T) → ((A ⊗ (B ⊗ C)) ⇒ ((A ⊗ B) ⊗ C)) assoc⁻¹ A B C = wiring (A ⊗ (B ⊗ C)) ((A ⊗ B) ⊗ C) ⊎-assoc (⊎-assoc✓ A B C) inj₂✓ : ∀ {S T : TBox Σ} → (A : Object S T) → (Assertions (⟨ABox⟩ inj₂ (iface A))) ⊆ (Assertions (iface (I ⊗ A))) inj₂✓ A = inj₂ unit₁ : ∀ {S T : TBox Σ} (A : Object S T) → ((I ⊗ A) ⇒ A) unit₁ A = wiring (I ⊗ A) A inj₂ (inj₂✓ A) ⊎-unit₁✓ : ∀ {S T : TBox Σ} → (A : Object S T) → Assertions (⟨ABox⟩ ⊎-unit₁ (iface (I ⊗ A))) ⊆ Assertions (iface A) ⊎-unit₁✓ A (inj₁ ()) ⊎-unit₁✓ A (inj₂ a∈A) = subst₂ Assertions (trans (⟨ABox⟩-resp-∘ ⊎-unit₁ inj₂ (iface A)) (⟨ABox⟩-resp-id (iface A))) refl a∈A unit₁⁻¹ : ∀ {S T : TBox Σ} (A : Object S T) → (A ⇒ (I ⊗ A)) unit₁⁻¹ A = wiring A (I ⊗ A) ⊎-unit₁ (⊎-unit₁✓ A) inj₁✓ : ∀ {S T : TBox Σ} → (A : Object S T) → (Assertions (⟨ABox⟩ inj₁ (iface A))) ⊆ (Assertions (iface (A ⊗ I))) inj₁✓ A = inj₁ unit₂ : ∀ {S T : TBox Σ} (A : Object S T) → ((A ⊗ I) ⇒ A) unit₂ A = wiring (A ⊗ I) A inj₁ (inj₁✓ A) ⊎-unit₂✓ : ∀ {S T : TBox Σ} (A : Object S T) → Assertions (⟨ABox⟩ ⊎-unit₂ (iface (A ⊗ I))) ⊆ Assertions (iface A) ⊎-unit₂✓ A (inj₁ a∈A) = subst₂ Assertions (trans (⟨ABox⟩-resp-∘ ⊎-unit₂ inj₁ (iface A)) (⟨ABox⟩-resp-id (iface A))) refl a∈A ⊎-unit₂✓ A (inj₂ ()) unit₂⁻¹ : ∀ {S T : TBox Σ} (A : Object S T) → (A ⇒ (A ⊗ I)) unit₂⁻¹ A = wiring A (A ⊗ I) ⊎-unit₂ (⊎-unit₂✓ A)
39.281553
81
0.532254
10e5b9d8c4234ce1c7445086e2e1066dc84c2e02
305
agda
Agda
src/data/lib/prim/Agda/Builtin/Word.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
src/data/lib/prim/Agda/Builtin/Word.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
src/data/lib/prim/Agda/Builtin/Word.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --without-K --safe --no-universe-polymorphism --no-sized-types --no-guardedness #-} module Agda.Builtin.Word where open import Agda.Builtin.Nat postulate Word64 : Set {-# BUILTIN WORD64 Word64 #-} primitive primWord64ToNat : Word64 → Nat primWord64FromNat : Nat → Word64
21.785714
57
0.695082
cbceeedbfd9d2a6315f30d3f9cbfe42bd0c3e187
3,439
agda
Agda
StructurallyRecursiveDescentParsing/Grammar.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
1
2020-07-03T08:56:13.000Z
2020-07-03T08:56:13.000Z
StructurallyRecursiveDescentParsing/Grammar.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
StructurallyRecursiveDescentParsing/Grammar.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Parsers containing non-terminals, and grammars using such parsers ------------------------------------------------------------------------ module StructurallyRecursiveDescentParsing.Grammar where open import Data.Bool open import Data.Empty open import Data.Product open import Relation.Binary.PropositionalEquality open import Codata.Musical.Notation open import Level open import StructurallyRecursiveDescentParsing.Index import StructurallyRecursiveDescentParsing.Simplified as Simplified open Simplified hiding (Parser; module Parser; ⟦_⟧) infixl 10 _!>>=_ _?>>=_ infixl 5 _∣_ -- The parsers are parameterised on a type of nonterminals. data Parser (NT : NonTerminalType) (Tok : Set) : NonTerminalType where return : ∀ {R} (x : R) → Parser NT Tok (true ◇ ε) R fail : ∀ {R} → Parser NT Tok (false ◇ ε) R token : Parser NT Tok (false ◇ ε) Tok _∣_ : ∀ {e₁ e₂ c₁ c₂ R} (p₁ : Parser NT Tok (e₁ ◇ c₁ ) R) (p₂ : Parser NT Tok ( e₂ ◇ c₂) R) → Parser NT Tok (e₁ ∨ e₂ ◇ c₁ ∪ c₂) R _?>>=_ : ∀ {e₂ c₁ c₂ R₁ R₂} (p₁ : Parser NT Tok (true ◇ c₁ ) R₁) (p₂ : R₁ → Parser NT Tok (e₂ ◇ c₂) R₂) → Parser NT Tok (e₂ ◇ c₁ ∪ c₂) R₂ _!>>=_ : ∀ {c₁ R₁ R₂} {i₂ : R₁ → Index} (p₁ : Parser NT Tok (false ◇ c₁) R₁) (p₂ : (x : R₁) → ∞ (Parser NT Tok (i₂ x) R₂)) → Parser NT Tok (false ◇ c₁) R₂ ! : ∀ {e c R} (nt : NT (e ◇ c) R) → Parser NT Tok (e ◇ c ∪ ε) R -- Grammars. Grammar : NonTerminalType → Set → Set1 Grammar NT Tok = ∀ {i R} → NT i R → Parser NT Tok i R -- An empty non-terminal type. EmptyNT : NonTerminalType EmptyNT _ _ = Lift _ ⊥ -- An empty grammar. emptyGrammar : ∀ {Tok} → Grammar EmptyNT Tok emptyGrammar (lift ()) -- The semantics of grammar-based parsers is defined in terms of their -- translation into "plain" parsers. The translation instantiates all -- non-terminals corecursively. ⟦_⟧ : ∀ {Tok NT e c R} → Parser NT Tok (e ◇ c) R → Grammar NT Tok → Simplified.Parser Tok e R ⟦ return x ⟧ g = return x ⟦ fail ⟧ g = fail ⟦ token ⟧ g = token ⟦ p₁ ∣ p₂ ⟧ g = ⟦ p₁ ⟧ g ∣ ⟦ p₂ ⟧ g ⟦ p₁ ?>>= p₂ ⟧ g = ⟦ p₁ ⟧ g ?>>= λ x → ⟦ p₂ x ⟧ g ⟦ p₁ !>>= p₂ ⟧ g = ⟦ p₁ ⟧ g !>>= λ x → ♯ ⟦ ♭ (p₂ x) ⟧ g ⟦ ! nt ⟧ g = ⟦ g nt ⟧ g -- Note that some "plain" parsers cannot be directly rewritten using -- the parser type in this module (although there may be /equivalent/ -- parsers): private only-plain : Simplified.Parser Bool false Bool only-plain = return true ?>>= λ x → if x then token else token ∣ token -- The following code does not type-check. -- doesnt-work : Parser EmptyNT Bool (false ◇ _) Bool -- doesnt-work = return true ?>>= λ x → -- if x then token else token ∣ token -- A map function which can be useful when combining grammars. mapNT : ∀ {NT₁ NT₂ Tok i R} → (∀ {i R} → NT₁ i R → NT₂ i R) → Parser NT₁ Tok i R → Parser NT₂ Tok i R mapNT f (return x) = return x mapNT f fail = fail mapNT f token = token mapNT f (p₁ ∣ p₂) = mapNT f p₁ ∣ mapNT f p₂ mapNT f (p₁ ?>>= p₂) = mapNT f p₁ ?>>= λ x → mapNT f (p₂ x) mapNT f (p₁ !>>= p₂) = mapNT f p₁ !>>= λ x → ♯ mapNT f (♭ (p₂ x)) mapNT f (! nt) = ! (f nt)
32.752381
72
0.548124
1c7bba2f786e520482ebc777c00a34ad10d13b80
9,778
agda
Agda
Cubical/Algebra/Ring/Base.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Algebra/Ring/Base.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Algebra/Ring/Base.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.Ring.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.Group open import Cubical.Algebra.AbGroup open import Cubical.Displayed.Base open import Cubical.Displayed.Auto open import Cubical.Displayed.Record open import Cubical.Displayed.Universe open import Cubical.Reflection.RecordEquiv open Iso private variable ℓ ℓ' ℓ'' : Level record IsRing {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where constructor isring field +IsAbGroup : IsAbGroup 0r _+_ -_ ·IsMonoid : IsMonoid 1r _·_ dist : (x y z : R) → (x · (y + z) ≡ (x · y) + (x · z)) × ((x + y) · z ≡ (x · z) + (y · z)) -- This is in the Agda stdlib, but it's redundant -- zero : (x : R) → (x · 0r ≡ 0r) × (0r · x ≡ 0r) open IsAbGroup +IsAbGroup public renaming ( assoc to +Assoc ; identity to +Identity ; lid to +Lid ; rid to +Rid ; inverse to +Inv ; invl to +Linv ; invr to +Rinv ; comm to +Comm ; isSemigroup to +IsSemigroup ; isMonoid to +IsMonoid ; isGroup to +IsGroup ) open IsMonoid ·IsMonoid public renaming ( assoc to ·Assoc ; identity to ·Identity ; lid to ·Lid ; rid to ·Rid ; isSemigroup to ·IsSemigroup ) hiding ( is-set ) -- We only want to export one proof of this ·Rdist+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z) ·Rdist+ x y z = dist x y z .fst ·Ldist+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z) ·Ldist+ x y z = dist x y z .snd record RingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where constructor ringstr field 0r : A 1r : A _+_ : A → A → A _·_ : A → A → A -_ : A → A isRing : IsRing 0r 1r _+_ _·_ -_ infix 8 -_ infixl 7 _·_ infixl 6 _+_ open IsRing isRing public Ring : ∀ ℓ → Type (ℓ-suc ℓ) Ring ℓ = TypeWithStr ℓ RingStr isSetRing : (R : Ring ℓ) → isSet ⟨ R ⟩ isSetRing R = R .snd .RingStr.isRing .IsRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set makeIsRing : {R : Type ℓ} {0r 1r : R} {_+_ _·_ : R → R → R} { -_ : R → R} (is-setR : isSet R) (+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z) (+-rid : (x : R) → x + 0r ≡ x) (+-rinv : (x : R) → x + (- x) ≡ 0r) (+-comm : (x y : R) → x + y ≡ y + x) (r+-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z) (·-rid : (x : R) → x · 1r ≡ x) (·-lid : (x : R) → 1r · x ≡ x) (·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z)) (·-ldist-+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z)) → IsRing 0r 1r _+_ _·_ -_ makeIsRing is-setR assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ = isring (makeIsAbGroup is-setR assoc +-rid +-rinv +-comm) (makeIsMonoid is-setR ·-assoc ·-rid ·-lid) λ x y z → ·-rdist-+ x y z , ·-ldist-+ x y z makeRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) (is-setR : isSet R) (+-assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z) (+-rid : (x : R) → x + 0r ≡ x) (+-rinv : (x : R) → x + (- x) ≡ 0r) (+-comm : (x y : R) → x + y ≡ y + x) (+-assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z) (·-rid : (x : R) → x · 1r ≡ x) (·-lid : (x : R) → 1r · x ≡ x) (·-rdist-+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z)) (·-ldist-+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z)) → Ring ℓ makeRing 0r 1r _+_ _·_ -_ is-setR assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ = _ , ringstr 0r 1r _+_ _·_ -_ (makeIsRing is-setR assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+ ) record IsRingHom {A : Type ℓ} {B : Type ℓ'} (R : RingStr A) (f : A → B) (S : RingStr B) : Type (ℓ-max ℓ ℓ') where -- Shorter qualified names private module R = RingStr R module S = RingStr S field pres0 : f R.0r ≡ S.0r pres1 : f R.1r ≡ S.1r pres+ : (x y : A) → f (x R.+ y) ≡ f x S.+ f y pres· : (x y : A) → f (x R.· y) ≡ f x S.· f y pres- : (x : A) → f (R.- x) ≡ S.- (f x) unquoteDecl IsRingHomIsoΣ = declareRecordIsoΣ IsRingHomIsoΣ (quote IsRingHom) RingHom : (R : Ring ℓ) (S : Ring ℓ') → Type (ℓ-max ℓ ℓ') RingHom R S = Σ[ f ∈ (⟨ R ⟩ → ⟨ S ⟩) ] IsRingHom (R .snd) f (S .snd) IsRingEquiv : {A : Type ℓ} {B : Type ℓ'} (M : RingStr A) (e : A ≃ B) (N : RingStr B) → Type (ℓ-max ℓ ℓ') IsRingEquiv M e N = IsRingHom M (e .fst) N RingEquiv : (R : Ring ℓ) (S : Ring ℓ') → Type (ℓ-max ℓ ℓ') RingEquiv R S = Σ[ e ∈ (⟨ R ⟩ ≃ ⟨ S ⟩) ] IsRingEquiv (R .snd) e (S .snd) _$_ : {R S : Ring ℓ} → (φ : RingHom R S) → (x : ⟨ R ⟩) → ⟨ S ⟩ φ $ x = φ .fst x RingEquiv→RingHom : {A B : Ring ℓ} → RingEquiv A B → RingHom A B RingEquiv→RingHom (e , eIsHom) = e .fst , eIsHom RingHomIsEquiv→RingEquiv : {A B : Ring ℓ} (f : RingHom A B) → isEquiv (fst f) → RingEquiv A B fst (fst (RingHomIsEquiv→RingEquiv f fIsEquiv)) = fst f snd (fst (RingHomIsEquiv→RingEquiv f fIsEquiv)) = fIsEquiv snd (RingHomIsEquiv→RingEquiv f fIsEquiv) = snd f isPropIsRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) → isProp (IsRing 0r 1r _+_ _·_ -_) isPropIsRing 0r 1r _+_ _·_ -_ (isring RG RM RD) (isring SG SM SD) = λ i → isring (isPropIsAbGroup _ _ _ RG SG i) (isPropIsMonoid _ _ RM SM i) (isPropDistr RD SD i) where isSetR : isSet _ isSetR = RM .IsMonoid.isSemigroup .IsSemigroup.is-set isPropDistr : isProp ((x y z : _) → ((x · (y + z)) ≡ ((x · y) + (x · z))) × (((x + y) · z) ≡ ((x · z) + (y · z)))) isPropDistr = isPropΠ3 λ _ _ _ → isProp× (isSetR _ _) (isSetR _ _) isPropIsRingHom : {A : Type ℓ} {B : Type ℓ'} (R : RingStr A) (f : A → B) (S : RingStr B) → isProp (IsRingHom R f S) isPropIsRingHom R f S = isOfHLevelRetractFromIso 1 IsRingHomIsoΣ (isProp×4 (isSetRing (_ , S) _ _) (isSetRing (_ , S) _ _) (isPropΠ2 λ _ _ → isSetRing (_ , S) _ _) (isPropΠ2 λ _ _ → isSetRing (_ , S) _ _) (isPropΠ λ _ → isSetRing (_ , S) _ _)) isSetRingHom : (R : Ring ℓ) (S : Ring ℓ') → isSet (RingHom R S) isSetRingHom R S = isSetΣSndProp (isSetΠ (λ _ → isSetRing S)) (λ f → isPropIsRingHom (snd R) f (snd S)) isSetRingEquiv : (A : Ring ℓ) (B : Ring ℓ') → isSet (RingEquiv A B) isSetRingEquiv A B = isSetΣSndProp (isOfHLevel≃ 2 (isSetRing A) (isSetRing B)) (λ e → isPropIsRingHom (snd A) (fst e) (snd B)) RingHomPathP : (R S T : Ring ℓ) (p : S ≡ T) (φ : RingHom R S) (ψ : RingHom R T) → PathP (λ i → R .fst → p i .fst) (φ .fst) (ψ .fst) → PathP (λ i → RingHom R (p i)) φ ψ RingHomPathP R S T p φ ψ q = ΣPathP (q , isProp→PathP (λ _ → isPropIsRingHom _ _ _) _ _) RingHom≡ : {R S : Ring ℓ} {φ ψ : RingHom R S} → fst φ ≡ fst ψ → φ ≡ ψ RingHom≡ = Σ≡Prop λ f → isPropIsRingHom _ f _ 𝒮ᴰ-Ring : DUARel (𝒮-Univ ℓ) RingStr ℓ 𝒮ᴰ-Ring = 𝒮ᴰ-Record (𝒮-Univ _) IsRingEquiv (fields: data[ 0r ∣ null ∣ pres0 ] data[ 1r ∣ null ∣ pres1 ] data[ _+_ ∣ bin ∣ pres+ ] data[ _·_ ∣ bin ∣ pres· ] data[ -_ ∣ un ∣ pres- ] prop[ isRing ∣ (λ _ _ → isPropIsRing _ _ _ _ _) ]) where open RingStr open IsRingHom -- faster with some sharing null = autoDUARel (𝒮-Univ _) (λ A → A) un = autoDUARel (𝒮-Univ _) (λ A → A → A) bin = autoDUARel (𝒮-Univ _) (λ A → A → A → A) RingPath : (R S : Ring ℓ) → RingEquiv R S ≃ (R ≡ S) RingPath = ∫ 𝒮ᴰ-Ring .UARel.ua uaRing : {A B : Ring ℓ} → RingEquiv A B → A ≡ B uaRing {A = A} {B = B} = equivFun (RingPath A B) isGroupoidRing : isGroupoid (Ring ℓ) isGroupoidRing _ _ = isOfHLevelRespectEquiv 2 (RingPath _ _) (isSetRingEquiv _ _) -- Rings have an abelian group and a monoid Ring→AbGroup : Ring ℓ → AbGroup ℓ Ring→AbGroup (A , ringstr _ _ _ _ _ R) = A , abgroupstr _ _ _ (IsRing.+IsAbGroup R) Ring→Group : Ring ℓ → Group ℓ Ring→Group = AbGroup→Group ∘ Ring→AbGroup Ring→AddMonoid : Ring ℓ → Monoid ℓ Ring→AddMonoid = Group→Monoid ∘ Ring→Group Ring→MultMonoid : Ring ℓ → Monoid ℓ Ring→MultMonoid (A , ringstr _ _ _ _ _ R) = monoid _ _ _ (IsRing.·IsMonoid R) -- Smart constructor for ring homomorphisms -- that infers the other equations from pres1, pres+, and pres· module _ {R : Ring ℓ} {S : Ring ℓ'} {f : ⟨ R ⟩ → ⟨ S ⟩} where private module R = RingStr (R .snd) module S = RingStr (S .snd) module _ (p1 : f R.1r ≡ S.1r) (p+ : (x y : ⟨ R ⟩) → f (x R.+ y) ≡ f x S.+ f y) (p· : (x y : ⟨ R ⟩) → f (x R.· y) ≡ f x S.· f y) where open IsRingHom private isGHom : IsGroupHom (Ring→Group R .snd) f (Ring→Group S .snd) isGHom = makeIsGroupHom p+ makeIsRingHom : IsRingHom (R .snd) f (S .snd) makeIsRingHom .pres0 = isGHom .IsGroupHom.pres1 makeIsRingHom .pres1 = p1 makeIsRingHom .pres+ = p+ makeIsRingHom .pres· = p· makeIsRingHom .pres- = isGHom .IsGroupHom.presinv
34.551237
103
0.526181
1ce72a68545ea0951345a24e1b8bd4db7661416b
120,837
agda
Agda
complexity/complexity-final/Interp-WithFlatrec.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
2
2016-04-26T20:22:22.000Z
2019-08-08T12:27:18.000Z
complexity/complexity-final/Interp-WithFlatrec.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
1
2020-03-23T08:39:04.000Z
2020-05-12T00:32:45.000Z
complexity/complexity-final/Interp-WithFlatrec.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
null
null
null
{- NEW INTERP WITH RREC -} {-# OPTIONS --no-termination-check #-} open import Preliminaries open import Preorder open import Pilot-WithFlatrec module Interp-WithFlatrec where -- interpret complexity types as preorders [_]t : CTp → PREORDER [ unit ]t = unit-p [ nat ]t = Nat , ♭nat-p [ τ ->c τ₁ ]t = [ τ ]t ->p [ τ₁ ]t [ τ ×c τ₁ ]t = [ τ ]t ×p [ τ₁ ]t [ list τ ]t = (List (fst [ τ ]t)) , list-p (snd [ τ ]t) [ bool ]t = Bool , bool-p [ C ]t = Nat , nat-p [ rnat ]t = Nat , nat-p [_]tm : ∀ {A} → CTpM A → Preorder-max-str (snd [ A ]t) [ runit ]tm = unit-pM [ rn ]tm = nat-pM [ e ×cm e₁ ]tm = axb-pM [ e ]tm [ e₁ ]tm [ _->cm_ {τ1} e ]tm = mono-pM [ e ]tm -- interpret contexts as preorders [_]c : Ctx → PREORDER [ [] ]c = unit-p [ τ :: Γ ]c = [ Γ ]c ×p [ τ ]t lookup : ∀{Γ τ} → τ ∈ Γ → el ([ Γ ]c ->p [ τ ]t) lookup (i0 {Γ} {τ}) = snd' id lookup (iS {Γ} {τ} {τ1} x) = comp (fst' id) (lookup x) interpE : ∀{Γ τ} → Γ |- τ → el ([ Γ ]c ->p [ τ ]t) sound : ∀ {Γ τ} (e e' : Γ |- τ) → e ≤s e' → PREORDER≤ ([ Γ ]c ->p [ τ ]t) (interpE e) (interpE e') interpE unit = monotone (λ x → <>) (λ x y x₁ → <>) interpE 0C = monotone (λ x → Z) (λ x y x₁ → <>) interpE 1C = monotone (λ x → S Z) (λ x y x₁ → <>) interpE (plusC e e₁) = monotone (λ x → Monotone.f (interpE e) x + Monotone.f (interpE e₁) x) (λ x y x₁ → plus-lem (Monotone.f (interpE e) x) (Monotone.f (interpE e₁) x) (Monotone.f (interpE e) y) (Monotone.f (interpE e₁) y) (Monotone.is-monotone (interpE e) x y x₁) (Monotone.is-monotone (interpE e₁) x y x₁)) interpE (var x) = lookup x interpE z = monotone (λ x → Z) (λ x y x₁ → <>) interpE (s e) = monotone (λ x → S (Monotone.f (interpE e) x)) (λ x y x₁ → Monotone.is-monotone (interpE e) x y x₁) interpE {Γ} {τ} (rec e e₁ e₂) = comp (pair' id (interpE e)) (♭rec' (interpE e₁) (interpE e₂)) interpE (lam e) = lam' (interpE e) interpE (app e e₁) = app' (interpE e) (interpE e₁) interpE rz = z' interpE (rsuc e) = suc' (interpE e) interpE (rrec e e₁ e₂ P) = comp (pair' id (interpE e)) (rec' (interpE e₁) (unlam' (unlam' (interpE e₂))) (λ x → sound e₁ (app (app e₂ rz) e₁) P x)) interpE (prod e e₁) = pair' (interpE e) (interpE e₁) interpE (l-proj e) = fst' (interpE e) interpE (r-proj e) = snd' (interpE e) interpE nil = nil' interpE (e ::c e₁) = cons' (interpE e) (interpE e₁) interpE (listrec e e₁ e₂) = comp (pair' id (interpE e)) (lrec' (interpE e₁) (interpE e₂)) interpE true = monotone (λ x → True) (λ x y x₁ → <>) interpE false = monotone (λ x → False) (λ x y x₁ → <>) interpE {Γ} {τ'} (max τ e1 e2) = monotone (λ x → Preorder-max-str.max [ τ ]tm (Monotone.f (interpE e1) x) (Monotone.f (interpE e2) x)) (λ x y x₁ → Preorder-max-str.max-lub [ τ ]tm (Preorder-max-str.max [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y)) (Monotone.f (interpE e1) x) (Monotone.f (interpE e2) x) (Preorder-str.trans (snd [ τ' ]t) (Monotone.f (interpE e1) x) (Monotone.f (interpE e1) y) (Preorder-max-str.max [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y)) (Monotone.is-monotone (interpE e1) x y x₁) (Preorder-max-str.max-l [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y))) (Preorder-str.trans (snd [ τ' ]t) (Monotone.f (interpE e2) x) (Monotone.f (interpE e2) y) (Preorder-max-str.max [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y)) (Monotone.is-monotone (interpE e2) x y x₁) (Preorder-max-str.max-r [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y)))) throw-r : ∀ {Γ Γ' τ} → rctx Γ (τ :: Γ') → rctx Γ Γ' throw-r d = λ x → d (iS x) interpR : ∀ {Γ Γ'} → rctx Γ Γ' → MONOTONE [ Γ ]c [ Γ' ]c interpR {Γ' = []} ρ = monotone (λ _ → <>) (λ x y x₁ → <>) interpR {Γ' = τ :: Γ'} ρ = monotone (λ x → (Monotone.f (interpR (throw-r ρ)) x) , (Monotone.f (lookup (ρ i0)) x)) (λ x y x₁ → (Monotone.is-monotone (interpR (throw-r ρ)) x y x₁) , (Monotone.is-monotone (lookup (ρ i0)) x y x₁)) throw-s : ∀ {Γ Γ' τ} → sctx Γ (τ :: Γ') → sctx Γ Γ' throw-s d = λ x → d (iS x) interpS : ∀ {Γ Γ'} → sctx Γ Γ' → el ([ Γ ]c ->p [ Γ' ]c) interpS {Γ' = []} Θ = monotone (λ _ → <>) (λ x y x₁ → <>) interpS {Γ' = τ :: Γ'} Θ = monotone (λ x → Monotone.f (interpS (throw-s Θ)) x , Monotone.f (interpE (Θ i0)) x) (λ x y x₁ → Monotone.is-monotone (interpS (throw-s Θ)) x y x₁ , (Monotone.is-monotone (interpE (Θ i0)) x y x₁)) ren-eq-l-lam : ∀ {Γ Γ' τ1} (ρ : rctx Γ Γ') (k : fst [ Γ ]c) (x : fst [ τ1 ]t) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpR (throw-r (r-extend {_} {_} {τ1} ρ))) (k , x)) (Monotone.f (interpR ρ) k) ren-eq-l-lam {Γ' = []} ρ k x = <> ren-eq-l-lam {Γ' = x :: Γ'} ρ k x₁ = (ren-eq-l-lam (throw-r ρ) k x₁) , (Preorder-str.refl (snd [ x ]t) (Monotone.f (lookup (ρ i0)) k)) ren-eq-l : ∀ {Γ Γ' τ} → (ρ : rctx Γ Γ') → (e : Γ' |- τ) → (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ τ ]t) (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) ren-eq-l ρ unit k = <> ren-eq-l ρ 0C k = <> ren-eq-l ρ 1C k = <> ren-eq-l ρ (plusC e e₁) k = plus-lem (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (ren-eq-l ρ e k) (ren-eq-l ρ e₁ k) ren-eq-l {τ = τ} ρ (var i0) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (lookup (ρ i0)) k) ren-eq-l {τ = τ} ρ (var (iS x)) k = ren-eq-l (throw-r ρ) (var x) k ren-eq-l ρ z k = <> ren-eq-l ρ (s e) k = ren-eq-l ρ e k ren-eq-l {Γ} {Γ'} {τ = τ} ρ (rec e e₁ e₂) k = Preorder-str.trans (snd [ τ ]t) (natrec (Monotone.f (interpE (ren e₁ ρ)) k) (λ n x₂ → Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) ((k , x₂) , n)) (Monotone.f (interpE (ren e ρ)) k)) (natrec (Monotone.f (interpE (ren e₁ ρ)) k) (λ n x₂ → Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) ((k , x₂) , n)) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (natrec (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (λ n x₂ → Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) k , x₂) , n)) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (♭h-fix-args (interpE (ren e₁ ρ)) (interpE (ren e₂ (r-extend (r-extend ρ)))) (k , (Monotone.f (interpE (ren e ρ)) k)) (k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (ren-eq-l ρ e k)) (♭h-cong (interpE (ren e₁ ρ)) (monotone (λ v → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) v)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpR ρ) x) (Monotone.f (interpR ρ) y) (Monotone.is-monotone (interpR ρ) x y x₁))) (interpE (ren e₂ (r-extend (r-extend ρ)))) (monotone (λ v → Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst v)) , snd (fst v)) , snd v)) (λ x y x₁ → Monotone.is-monotone (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x) ((Monotone.f (interpR ρ) (fst (fst y)) , snd (fst y)) , snd y) (((Monotone.is-monotone (interpR ρ) (fst (fst x)) (fst (fst y)) (fst (fst x₁))) , (snd (fst x₁))) , (snd x₁)))) (k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (λ x → ren-eq-l ρ e₁ x) (λ x → Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) x) (Monotone.f (interpE e₂) (Monotone.f (interpR {nat :: τ :: Γ} {_ :: _ :: Γ'} (r-extend (r-extend ρ))) x)) (Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x)) (ren-eq-l (r-extend (r-extend ρ)) e₂ x) (Monotone.is-monotone (interpE e₂) (Monotone.f (interpR {nat :: τ :: Γ} {_ :: _ :: Γ'} (r-extend (r-extend ρ))) x) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x) ((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpR (λ x₁ → iS (iS (ρ x₁)))) x) (Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst x) , snd (fst x))) (Monotone.f (interpR ρ) (fst (fst x))) (ren-eq-l-lam {τ :: Γ} {Γ'} (throw-r (r-extend ρ)) (fst x) (snd x)) (ren-eq-l-lam ρ (fst (fst x)) (snd (fst x))) , (Preorder-str.refl (snd [ τ ]t) (snd (fst x)))) , (♭nat-refl (snd x)))))) ren-eq-l {Γ} {τ = τ1 ->c τ2} ρ (lam e) k x = Preorder-str.trans (snd [ τ2 ]t) (Monotone.f (Monotone.f (interpE (ren (lam e) ρ)) k) x) (Monotone.f (interpE e) (Monotone.f (interpR (r-extend {_} {_} {τ1} ρ)) (k , x))) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k , x)) (ren-eq-l (r-extend ρ) e (k , x)) (Monotone.is-monotone (interpE e) (Monotone.f (interpR (r-extend {_} {_} {τ1} ρ)) (k , x)) (Monotone.f (interpR ρ) k , x) (ren-eq-l-lam ρ k x , (Preorder-str.refl (snd [ τ1 ]t) x))) ren-eq-l {Γ} {τ = τ} ρ (app e e₁) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k)) (Monotone.f (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))) (Monotone.f (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))) (Monotone.is-monotone (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (ren-eq-l ρ e₁ k)) (ren-eq-l ρ e k (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))) ren-eq-l ρ rz k = <> ren-eq-l ρ (rsuc e) k = ren-eq-l ρ e k ren-eq-l {Γ} {Γ'} {τ} ρ (rrec e e₁ e₂ P) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (comp (pair' id (interpE (ren e ρ))) (rec' (interpE (ren e₁ ρ)) (unlam' (unlam' (interpE (ren e₂ ρ)))) (sound (ren e₁ ρ) (app (app (ren e₂ ρ) rz) (ren e₁ ρ)) (ren-cong P)))) k) (Monotone.f (rec' (interpE (ren e₁ ρ)) (unlam' (unlam' (interpE (ren e₂ ρ)))) (λ x₁ → sound (ren e₁ ρ) (app (app (ren e₂ ρ) rz) (ren e₁ ρ)) (ren-cong P) x₁)) (k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (Monotone.f (comp (pair' id (interpE e)) (rec' (interpE e₁) (unlam' (unlam' (interpE e₂))) (sound e₁ (app (app e₂ rz) e₁) P))) (Monotone.f (interpR ρ) k)) (h-lem2 (interpE (ren e₁ ρ)) (unlam' (unlam' (interpE (ren e₂ ρ)))) (k , Monotone.f (interpE (ren e ρ)) k) (k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (λ x → sound (ren e₁ ρ) (app (app (ren e₂ ρ) rz) (ren e₁ ρ)) (ren-cong P) x) (ren-eq-l ρ e k)) (h-cong2 (interpE (ren e₁ ρ)) (monotone (λ z₁ → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) z₁)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpR ρ) x) (Monotone.f (interpR ρ) y) (Monotone.is-monotone (interpR ρ) x y x₁))) (unlam' (unlam' (interpE (ren e₂ ρ)))) (monotone (λ v → Monotone.f (Monotone.f (Monotone.f (interpE e₂) (Monotone.f (interpR ρ) (fst (fst v)))) (snd (fst v))) (snd v)) (λ x y x₁ → Monotone.is-monotone (unlam' (unlam' (interpE e₂))) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x) ((Monotone.f (interpR ρ) (fst (fst y)) , snd (fst y)) , snd y) ((Monotone.is-monotone (interpR ρ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) , snd (fst x₁)) , snd x₁))) (λ x → ren-eq-l ρ e₁ x) (λ x → ren-eq-l ρ e₂ (fst (fst x)) (snd (fst x)) (snd x)) (λ x₁ → sound (ren e₁ ρ) (app (app (ren e₂ ρ) rz) (ren e₁ ρ)) (ren-cong P) x₁) (λ x₁ → sound e₁ (app (app e₂ rz) e₁) P (Monotone.f (interpR ρ) x₁)) (k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) ren-eq-l ρ (prod e e₁) k = (ren-eq-l ρ e k) , (ren-eq-l ρ e₁ k) ren-eq-l ρ (l-proj e) k = fst (ren-eq-l ρ e k) ren-eq-l ρ (r-proj e) k = snd (ren-eq-l ρ e k) ren-eq-l ρ nil k = <> ren-eq-l ρ (e ::c e₁) k = (ren-eq-l ρ e k) , (ren-eq-l ρ e₁ k) ren-eq-l {Γ} {Γ'} {τ = τ} ρ (listrec {.Γ'} {τ'} e e₁ e₂) k = Preorder-str.trans (snd [ τ ]t) (lrec (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k) (λ x₁ x₂ x₃ → Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (((k , x₃) , x₂) , x₁))) (lrec (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e₁ ρ)) k) (λ x₁ x₂ x₃ → Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (((k , x₃) , x₂) , x₁))) (lrec (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (λ x₁ x₂ x₃ → Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) k , x₃) , x₂) , x₁))) (listrec-fix-args (interpE (ren e₁ ρ)) (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (k , (Monotone.f (interpE (ren e ρ)) k)) (k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) ((Preorder-str.refl (snd [ Γ ]c) k) , (ren-eq-l ρ e k))) (lrec-cong (interpE (ren e₁ ρ)) (monotone (λ k₁ → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k₁)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpR ρ) x) (Monotone.f (interpR ρ) y) (Monotone.is-monotone (interpR ρ) x y x₁))) (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (monotone (λ x → Monotone.f (interpE e₂) ((((Monotone.f (interpR ρ) (fst (fst (fst x)))) , (snd (fst (fst x)))) , (snd (fst x))) , (snd x))) (λ x y x₁ → Monotone.is-monotone (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x) (((Monotone.f (interpR ρ) (fst (fst (fst y))) , snd (fst (fst y))) , snd (fst y)) , snd y) ((((Monotone.is-monotone (interpR ρ) (fst (fst (fst x))) (fst (fst (fst y))) (fst (fst (fst x₁)))) , (snd (fst (fst x₁)))) , (snd (fst x₁))) , (snd x₁)))) (k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (λ x → ren-eq-l ρ e₁ x) (λ x → Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) x) (Monotone.f (interpE e₂) (Monotone.f (interpR {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (r-extend (r-extend (r-extend ρ)))) x)) (Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)) (ren-eq-l (r-extend (r-extend (r-extend ρ))) e₂ x) (Monotone.is-monotone (interpE e₂) (Monotone.f (interpR {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (r-extend (r-extend (r-extend ρ)))) x) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x) (((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpR (λ x₁ → iS (iS (iS (ρ x₁))))) x) (Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst (fst x)) , snd (fst (fst x)))) (Monotone.f (interpR ρ) (fst (fst (fst x)))) (Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpR (λ x₁ → iS (iS (iS (ρ x₁))))) x) (Monotone.f (interpR (λ x₁ → iS (iS (ρ x₁)))) (fst x)) (Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst (fst x)) , snd (fst (fst x)))) (ren-eq-l-lam (λ x₁ → iS (iS (ρ x₁))) (fst x) (snd x)) (ren-eq-l-lam (λ x₁ → iS (ρ x₁)) (fst (fst x)) (snd (fst x)))) (ren-eq-l-lam ρ (fst (fst (fst x))) (snd (fst (fst x)))) , Preorder-str.refl (snd [ τ ]t) (snd (fst (fst x)))) , l-refl (snd [ τ' ]t) (snd (fst x))) , Preorder-str.refl (snd [ τ' ]t) (snd x))))) ren-eq-l ρ true k = <> ren-eq-l ρ false k = <> ren-eq-l {τ = τ} ρ (max x e e₁) k = Preorder-max-str.max-lub [ x ]tm (Monotone.f (interpE (max x e e₁)) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (max x e e₁)) (Monotone.f (interpR ρ) k)) (ren-eq-l ρ e k) (Preorder-max-str.max-l [ x ]tm (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)))) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e₁ ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (max x e e₁)) (Monotone.f (interpR ρ) k)) (ren-eq-l ρ e₁ k) (Preorder-max-str.max-r [ x ]tm (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)))) ren-eq-r-lam : ∀ {Γ Γ' τ1} (ρ : rctx Γ Γ') (k : fst [ Γ ]c) (x : fst [ τ1 ]t) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpR ρ) k) (Monotone.f (interpR (throw-r (r-extend {_} {_} {τ1} ρ))) (k , x)) ren-eq-r-lam {Γ' = []} ρ k x = <> ren-eq-r-lam {Γ' = x :: Γ'} ρ k x₁ = (ren-eq-r-lam (throw-r ρ) k x₁) , (Preorder-str.refl (snd [ x ]t) (Monotone.f (lookup (ρ i0)) k)) ren-eq-r : ∀ {Γ Γ' τ} → (ρ : rctx Γ Γ') → (e : Γ' |- τ) → (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e ρ)) k) ren-eq-r ρ unit k = <> ren-eq-r ρ 0C k = <> ren-eq-r ρ 1C k = <> ren-eq-r ρ (plusC e e₁) k = plus-lem (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k) (ren-eq-r ρ e k) (ren-eq-r ρ e₁ k) ren-eq-r {τ = τ} ρ (var i0) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (lookup (ρ i0)) k) ren-eq-r {τ = τ} ρ (var (iS x)) k = ren-eq-r (throw-r ρ) (var x) k ren-eq-r ρ z k = <> ren-eq-r ρ (s e) k = ren-eq-r ρ e k ren-eq-r {Γ} {Γ'} {τ} ρ (rec e e₁ e₂) k = Preorder-str.trans (snd [ τ ]t) (natrec (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (λ n x₂ → Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) k , x₂) , n)) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (natrec (Monotone.f (interpE (ren e₁ ρ)) k) (λ n x₂ → Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) ((k , x₂) , n)) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (natrec (Monotone.f (interpE (ren e₁ ρ)) k) (λ n x₂ → Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) ((k , x₂) , n)) (Monotone.f (interpE (ren e ρ)) k)) (♭h-cong (monotone (λ v → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) v)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpR ρ) x) (Monotone.f (interpR ρ) y) (Monotone.is-monotone (interpR ρ) x y x₁))) (interpE (ren e₁ ρ)) (monotone (λ v → Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst v)) , snd (fst v)) , snd v)) (λ x y x₁ → Monotone.is-monotone (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x) ((Monotone.f (interpR ρ) (fst (fst y)) , snd (fst y)) , snd y) ((Monotone.is-monotone (interpR ρ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) , snd (fst x₁)) , snd x₁))) (interpE (ren e₂ (r-extend (r-extend ρ)))) (k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (λ x → ren-eq-r ρ e₁ x) (λ x → Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x)) (Monotone.f (interpE e₂) (Monotone.f (interpR {nat :: τ :: Γ} {_ :: _ :: Γ'} (r-extend (r-extend ρ))) x)) (Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) x) (Monotone.is-monotone (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x) (Monotone.f (interpR {nat :: τ :: Γ} {_ :: _ :: Γ'} (r-extend (r-extend ρ))) x) (((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpR ρ) (fst (fst x))) (Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst x) , snd (fst x))) (Monotone.f (interpR (λ x₁ → iS (iS (ρ x₁)))) x) (ren-eq-r-lam ρ (fst (fst x)) (snd (fst x))) (ren-eq-r-lam {τ :: Γ} {Γ'} (throw-r (r-extend ρ)) (fst x) (snd x))) , (Preorder-str.refl (snd [ τ ]t) (snd (fst x)))) , (♭nat-refl (snd x)))) (ren-eq-r (r-extend (r-extend ρ)) e₂ x))) (♭h-fix-args (interpE (ren e₁ ρ)) (interpE (ren e₂ (r-extend (r-extend ρ)))) (k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (k , Monotone.f (interpE (ren e ρ)) k) (ren-eq-r ρ e k)) ren-eq-r {Γ} {τ = τ1 ->c τ2} ρ (lam e) k x = Preorder-str.trans (snd [ τ2 ]t) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k , x)) (Monotone.f (interpE e) (Monotone.f (interpR (r-extend {_} {_} {τ1} ρ)) (k , x))) (Monotone.f (Monotone.f (interpE (ren (lam e) ρ)) k) x) ((Monotone.is-monotone (interpE e) (Monotone.f (interpR ρ) k , x) (Monotone.f (interpR (r-extend {_} {_} {τ1} ρ)) (k , x)) (ren-eq-r-lam ρ k x , (Preorder-str.refl (snd [ τ1 ]t) x)))) (ren-eq-r (r-extend ρ) e (k , x)) ren-eq-r {Γ} {τ = τ} ρ (app e e₁) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))) (Monotone.f (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))) (Monotone.f (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k)) (ren-eq-r ρ e k (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))) (Monotone.is-monotone (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e₁ ρ)) k) (ren-eq-r ρ e₁ k)) ren-eq-r ρ rz k = <> ren-eq-r ρ (rsuc e) k = ren-eq-r ρ e k ren-eq-r {Γ} {Γ'} {τ} ρ (rrec e e₁ e₂ P) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (comp (pair' id (interpE e)) (rec' (interpE e₁) (unlam' (unlam' (interpE e₂))) (sound e₁ (app (app e₂ rz) e₁) P))) (Monotone.f (interpR ρ) k)) (Monotone.f (rec' (interpE (ren e₁ ρ)) (unlam' (unlam' (interpE (ren e₂ ρ)))) (λ x₁ → sound (ren e₁ ρ) (app (app (ren e₂ ρ) rz) (ren e₁ ρ)) (ren-cong P) x₁)) (k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (Monotone.f (comp (pair' id (interpE (ren e ρ))) (rec' (interpE (ren e₁ ρ)) (unlam' (unlam' (interpE (ren e₂ ρ)))) (sound (ren e₁ ρ) (app (app (ren e₂ ρ) rz) (ren e₁ ρ)) (ren-cong P)))) k) (h-cong2 (monotone (λ z₁ → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) z₁)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpR ρ) x) (Monotone.f (interpR ρ) y) (Monotone.is-monotone (interpR ρ) x y x₁))) (interpE (ren e₁ ρ)) (monotone (λ v → Monotone.f (Monotone.f (Monotone.f (interpE e₂) (Monotone.f (interpR ρ) (fst (fst v)))) (snd (fst v))) (snd v)) (λ x y x₁ → Monotone.is-monotone (unlam' (unlam' (interpE e₂))) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x) ((Monotone.f (interpR ρ) (fst (fst y)) , snd (fst y)) , snd y) ((Monotone.is-monotone (interpR ρ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) , snd (fst x₁)) , snd x₁))) (unlam' (unlam' (interpE (ren e₂ ρ)))) (λ x → ren-eq-r ρ e₁ x) (λ x → ren-eq-r ρ e₂ (fst (fst x)) (snd (fst x)) (snd x)) (λ x₁ → sound e₁ (app (app e₂ rz) e₁) P (Monotone.f (interpR ρ) x₁)) (λ x₁ → sound (ren e₁ ρ) (app (app (ren e₂ ρ) rz) (ren e₁ ρ)) (ren-cong P) x₁) (k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))) (h-lem2 (interpE (ren e₁ ρ)) (unlam' (unlam' (interpE (ren e₂ ρ)))) (k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (k , Monotone.f (interpE (ren e ρ)) k) (λ x → sound (ren e₁ ρ) (app (app (ren e₂ ρ) rz) (ren e₁ ρ)) (ren-cong P) x) (ren-eq-r ρ e k)) ren-eq-r ρ (prod e e₁) k = (ren-eq-r ρ e k) , (ren-eq-r ρ e₁ k) ren-eq-r ρ (l-proj e) k = fst (ren-eq-r ρ e k) ren-eq-r ρ (r-proj e) k = snd (ren-eq-r ρ e k) ren-eq-r ρ nil k = <> ren-eq-r ρ (e ::c e₁) k = (ren-eq-r ρ e k) , (ren-eq-r ρ e₁ k) ren-eq-r {Γ} {Γ'} {τ} ρ (listrec {.Γ'} {τ'} e e₁ e₂) k = Preorder-str.trans (snd [ τ ]t) (lrec (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (λ x₁ x₂ x₃ → Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) k , x₃) , x₂) , x₁))) (lrec (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e₁ ρ)) k) (λ x₁ x₂ x₃ → Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (((k , x₃) , x₂) , x₁))) (lrec (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k) (λ x₁ x₂ x₃ → Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (((k , x₃) , x₂) , x₁))) (lrec-cong (monotone (λ k₁ → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k₁)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpR ρ) x) (Monotone.f (interpR ρ) y) (Monotone.is-monotone (interpR ρ) x y x₁))) (interpE (ren e₁ ρ)) (monotone (λ x → Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)) (λ x y x₁ → Monotone.is-monotone (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x) (((Monotone.f (interpR ρ) (fst (fst (fst y))) , snd (fst (fst y))) , snd (fst y)) , snd y) (((Monotone.is-monotone (interpR ρ) (fst (fst (fst x))) (fst (fst (fst y))) (fst (fst (fst x₁))) , snd (fst (fst x₁))) , snd (fst x₁)) , snd x₁))) (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))) (λ x → ren-eq-r ρ e₁ x) (λ x → Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)) (Monotone.f (interpE e₂) (Monotone.f (interpR {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (r-extend (r-extend (r-extend ρ)))) x)) (Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) x) (Monotone.is-monotone (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x) (Monotone.f (interpR {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (r-extend (r-extend (r-extend ρ)))) x) ((((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpR ρ) (fst (fst (fst x)))) (Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst (fst x)) , snd (fst (fst x)))) (Monotone.f (interpR (λ x₁ → iS (iS (iS (ρ x₁))))) x) (ren-eq-r-lam ρ (fst (fst (fst x))) (snd (fst (fst x)))) (Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst (fst x)) , snd (fst (fst x)))) (Monotone.f (interpR (λ x₁ → iS (iS (ρ x₁)))) (fst x)) (Monotone.f (interpR (λ x₁ → iS (iS (iS (ρ x₁))))) x) (ren-eq-r-lam (λ x₁ → iS (ρ x₁)) (fst (fst x)) (snd (fst x))) (ren-eq-r-lam (λ x₁ → iS (iS (ρ x₁))) (fst x) (snd x)))) , (Preorder-str.refl (snd [ τ ]t) (snd (fst (fst x))))) , (l-refl (snd [ τ' ]t) (snd (fst x)))) , (Preorder-str.refl (snd [ τ' ]t) (snd x)))) (ren-eq-r (r-extend (r-extend (r-extend ρ))) e₂ x))) (listrec-fix-args (interpE (ren e₁ ρ)) (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (k , Monotone.f (interpE (ren e ρ)) k) (Preorder-str.refl (snd [ Γ ]c) k , ren-eq-r ρ e k)) ren-eq-r ρ true k = <> ren-eq-r ρ false k = <> ren-eq-r {τ = τ} ρ (max x e e₁) k = Preorder-max-str.max-lub [ x ]tm (Monotone.f (interpE (ren (max x e e₁) ρ)) k) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren (max x e e₁) ρ)) k) (ren-eq-r ρ e k) (Preorder-max-str.max-l [ x ]tm (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k))) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e₁ ρ)) k) (Monotone.f (interpE (ren (max x e e₁) ρ)) k) (ren-eq-r ρ e₁ k) (Preorder-max-str.max-r [ x ]tm (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k))) ids-lem-l : ∀ {Γ} (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ ]c) (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) k ids-lem-l {[]} k = <> ids-lem-l {x :: Γ} (k1 , k2) = (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {x :: Γ} {Γ} (throw-r (λ x₂ → x₂))) (k1 , k2)) (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k1) k1 (ren-eq-l-lam {Γ} {Γ} (λ x₂ → x₂) k1 k2) (ids-lem-l {Γ} k1)) , (Preorder-str.refl (snd [ x ]t) k2) subst-eq-l-lam : ∀ {Γ Γ' τ1} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (x : fst [ τ1 ]t) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS (throw-s (s-extend {_} {_} {τ1} Θ))) (k , x)) (Monotone.f (interpS Θ) k) subst-eq-l-lam {Γ' = []} Θ k x = <> subst-eq-l-lam {Γ} {Γ' = x :: Γ'} {τ1} Θ k x₁ = (subst-eq-l-lam (throw-s Θ) k x₁) , Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (ren (Θ i0) iS)) (k , x₁)) (Monotone.f (interpE (Θ i0)) (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁))) (snd (Monotone.f (interpS Θ) k)) (ren-eq-l iS (Θ i0) (k , x₁)) (Monotone.is-monotone (interpE (Θ i0)) (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁)) k (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁)) (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) k (ren-eq-l-lam {Γ} {Γ} (λ x₂ → x₂) k x₁) (ids-lem-l {Γ} k))) subst-eq-l : ∀ {Γ Γ' τ} → (Θ : sctx Γ Γ') → (e : Γ' |- τ) → (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ τ ]t) (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) subst-eq-l Θ unit k = <> subst-eq-l Θ 0C k = <> subst-eq-l Θ 1C k = <> subst-eq-l Θ (plusC e e₁) k = plus-lem (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (subst-eq-l Θ e k) (subst-eq-l Θ e₁ k) subst-eq-l {τ = τ} Θ (var i0) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE (Θ i0)) k) subst-eq-l {τ = τ} Θ (var (iS x)) k = subst-eq-l (throw-s Θ) (var x) k subst-eq-l Θ z k = <> subst-eq-l Θ (s e) k = subst-eq-l Θ e k subst-eq-l {Γ} {Γ'} {τ} Θ (rec e e₁ e₂) k = Preorder-str.trans (snd [ τ ]t) (natrec (Monotone.f (interpE (subst e₁ Θ)) k) (λ n x₂ → Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) ((k , x₂) , n)) (Monotone.f (interpE (subst e Θ)) k)) (natrec (Monotone.f (interpE (subst e₁ Θ)) k) (λ n x₂ → Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) ((k , x₂) , n)) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) (natrec (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (λ n x₂ → Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) k , x₂) , n)) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) (♭h-fix-args (interpE (subst e₁ Θ)) (interpE (subst e₂ (s-extend (s-extend Θ)))) (k , Monotone.f (interpE (subst e Θ)) k) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (subst-eq-l Θ e k)) (♭h-cong (interpE (subst e₁ Θ)) (monotone (λ v → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) v)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁))) (interpE (subst e₂ (s-extend (s-extend Θ)))) (monotone (λ v → Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst v)) , snd (fst v)) , snd v)) (λ x y x₁ → Monotone.is-monotone (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x) ((Monotone.f (interpS Θ) (fst (fst y)) , snd (fst y)) , snd y) ((Monotone.is-monotone (interpS Θ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) , snd (fst x₁)) , snd x₁))) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (λ x → subst-eq-l Θ e₁ x) (λ x → Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) x) (Monotone.f (interpE e₂) (Monotone.f (interpS {nat :: τ :: Γ} {_ :: _ :: Γ'} (s-extend (s-extend Θ))) x)) (Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x)) (subst-eq-l (s-extend (s-extend Θ)) e₂ x) (Monotone.is-monotone (interpE e₂) (Monotone.f (interpS {nat :: τ :: Γ} {_ :: _ :: Γ'} (s-extend (s-extend Θ))) x) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x) (((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS (λ x₁ → ren (ren (Θ x₁) iS) iS)) x) (Monotone.f (interpS (λ x₁ → ren (Θ x₁) iS)) (fst x)) (Monotone.f (interpS Θ) (fst (fst x))) (subst-eq-l-lam {τ :: Γ} {Γ'} (λ x₁ → ren (Θ x₁) iS) (fst x) (snd x)) (subst-eq-l-lam Θ (fst (fst x)) (snd (fst x)))) , (Preorder-str.refl (snd [ τ ]t) (snd (fst x)))) , (♭nat-refl (snd x)))))) subst-eq-l {Γ} {τ = τ1 ->c τ2} Θ (lam e) k x = Preorder-str.trans (snd [ τ2 ]t) (Monotone.f (Monotone.f (interpE (subst (lam e) Θ)) k) x) (Monotone.f (interpE e) (Monotone.f (interpS (s-extend {_} {_} {τ1} Θ)) (k , x))) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k , x)) (subst-eq-l (s-extend Θ) e (k , x)) (Monotone.is-monotone (interpE e) (Monotone.f (interpS (s-extend {_} {_} {τ1} Θ)) (k , x)) (Monotone.f (interpS Θ) k , x) (subst-eq-l-lam Θ k x , (Preorder-str.refl (snd [ τ1 ]t) x))) subst-eq-l {Γ} {τ = τ} Θ (app e e₁) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k)) (Monotone.f (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))) (Monotone.f (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))) (Monotone.is-monotone (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (subst-eq-l Θ e₁ k)) (subst-eq-l Θ e k (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))) subst-eq-l Θ rz k = <> subst-eq-l Θ (rsuc e) k = subst-eq-l Θ e k subst-eq-l {Γ} {Γ'} {τ} Θ (rrec e e₁ e₂ P) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (comp (pair' id (interpE (subst e Θ))) (rec' (interpE (subst e₁ Θ)) (unlam' (unlam' (interpE (subst e₂ Θ)))) (sound (subst e₁ Θ) (app (app (subst e₂ Θ) rz) (subst e₁ Θ)) (subst-cong P)))) k) (Monotone.f (rec' (interpE (subst e₁ Θ)) (unlam' (unlam' (interpE (subst e₂ Θ)))) (λ x₁ → sound (subst e₁ Θ) (app (app (subst e₂ Θ) rz) (subst e₁ Θ)) (subst-cong P) x₁)) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) (Monotone.f (comp (pair' id (interpE e)) (rec' (interpE e₁) (unlam' (unlam' (interpE e₂))) (sound e₁ (app (app e₂ rz) e₁) P))) (Monotone.f (interpS Θ) k)) (h-lem2 (interpE (subst e₁ Θ)) (unlam' (unlam' (interpE (subst e₂ Θ)))) (k , Monotone.f (interpE (subst e Θ)) k) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (λ x → sound (subst e₁ Θ) (app (app (subst e₂ Θ) rz) (subst e₁ Θ)) (subst-cong P) x) (subst-eq-l Θ e k)) (h-cong2 (interpE (subst e₁ Θ)) (monotone (λ x → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) x)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁))) (unlam' (unlam' (interpE (subst e₂ Θ)))) (monotone (λ x → Monotone.f (Monotone.f (Monotone.f (interpE e₂) (Monotone.f (interpS Θ) (fst (fst x)))) (snd (fst x))) (snd x)) (λ x y x₁ → Monotone.is-monotone (unlam' (unlam' (interpE e₂))) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x) ((Monotone.f (interpS Θ) (fst (fst y)) , snd (fst y)) , snd y) ((Monotone.is-monotone (interpS Θ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) , snd (fst x₁)) , snd x₁))) (λ x → subst-eq-l Θ e₁ x) (λ x → subst-eq-l Θ e₂ (fst (fst x)) (snd (fst x)) (snd x)) (λ x₁ → sound (subst e₁ Θ) (app (app (subst e₂ Θ) rz) (subst e₁ Θ)) (subst-cong P) x₁) (λ x₁ → sound e₁ (app (app e₂ rz) e₁) P (Monotone.f (interpS Θ) x₁)) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) subst-eq-l Θ (prod e e₁) k = (subst-eq-l Θ e k) , (subst-eq-l Θ e₁ k) subst-eq-l Θ (l-proj e) k = fst (subst-eq-l Θ e k) subst-eq-l Θ (r-proj e) k = snd (subst-eq-l Θ e k) subst-eq-l Θ nil k = <> subst-eq-l Θ (e ::c e₁) k = (subst-eq-l Θ e k) , (subst-eq-l Θ e₁ k) subst-eq-l {Γ} {Γ'} {τ} Θ (listrec {.Γ'} {τ'} e e₁ e₂) k = Preorder-str.trans (snd [ τ ]t) (lrec (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k) (λ x₁ x₂ x₃ → Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (((k , x₃) , x₂) , x₁))) (lrec (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e₁ Θ)) k) (λ x₁ x₂ x₃ → Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (((k , x₃) , x₂) , x₁))) (lrec (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (λ x₁ x₂ x₃ → Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) k , x₃) , x₂) , x₁))) (listrec-fix-args (interpE (subst e₁ Θ)) (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (k , Monotone.f (interpE (subst e Θ)) k) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Preorder-str.refl (snd [ Γ ]c) k , subst-eq-l Θ e k)) (lrec-cong (interpE (subst e₁ Θ)) (monotone (λ k₁ → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k₁)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁))) (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (monotone (λ x → Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)) (λ x y x₁ → Monotone.is-monotone (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x) (((Monotone.f (interpS Θ) (fst (fst (fst y))) , snd (fst (fst y))) , snd (fst y)) , snd y) (((Monotone.is-monotone (interpS Θ) (fst (fst (fst x))) (fst (fst (fst y))) (fst (fst (fst x₁))) , snd (fst (fst x₁))) , snd (fst x₁)) , snd x₁))) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (λ x → subst-eq-l Θ e₁ x) (λ x → Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) x) (Monotone.f (interpE e₂) (Monotone.f (interpS {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (s-extend (s-extend (s-extend Θ)))) x)) (Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)) (subst-eq-l (s-extend (s-extend (s-extend Θ))) e₂ x) (Monotone.is-monotone (interpE e₂) (Monotone.f (interpS {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (s-extend (s-extend (s-extend Θ)))) x) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x) ((((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS (λ x₁ → ren (ren (ren (Θ x₁) iS) iS) iS)) x) (Monotone.f (interpS {τ :: Γ} {Γ'} (throw-s (s-extend Θ))) (fst (fst x))) (Monotone.f (interpS Θ) (fst (fst (fst x)))) (Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS (λ x₁ → ren (ren (ren (Θ x₁) iS) iS) iS)) x) (Monotone.f (interpS (λ x₁ → ren (ren (Θ x₁) iS) iS)) (fst x)) (Monotone.f (interpS {τ :: Γ} {Γ'} (throw-s (s-extend Θ))) (fst (fst x))) (subst-eq-l-lam (λ x₁ → ren (ren (Θ x₁) iS) iS) (fst x) (snd x)) (subst-eq-l-lam (λ x₁ → ren (Θ x₁) iS) (fst (fst x)) (snd (fst x)))) (subst-eq-l-lam {Γ} {Γ'} Θ (fst (fst (fst x))) (snd (fst (fst x))))) , (Preorder-str.refl (snd [ τ ]t) (snd (fst (fst x))))) , (l-refl (snd [ τ' ]t) (snd (fst x)))) , (Preorder-str.refl (snd [ τ' ]t) (snd x)))))) subst-eq-l Θ true k = <> subst-eq-l Θ false k = <> subst-eq-l {τ = τ} Θ (max x e e₁) k = Preorder-max-str.max-lub [ x ]tm (Monotone.f (interpE (max x e e₁)) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (max x e e₁)) (Monotone.f (interpS Θ) k)) (subst-eq-l Θ e k) (Preorder-max-str.max-l [ x ]tm (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)))) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e₁ Θ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (max x e e₁)) (Monotone.f (interpS Θ) k)) (subst-eq-l Θ e₁ k) (Preorder-max-str.max-r [ x ]tm (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)))) ids-lem-r : ∀ {Γ} (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ ]c) k (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) ids-lem-r {[]} k = <> ids-lem-r {x :: Γ} (k1 , k2) = (Preorder-str.trans (snd [ Γ ]c) k1 (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k1) (Monotone.f (interpR {x :: Γ} {Γ} (throw-r (λ x₂ → x₂))) (k1 , k2)) (ids-lem-r {Γ} k1) (ren-eq-r-lam {Γ} {Γ} (λ x₂ → x₂) k1 k2)) , (Preorder-str.refl (snd [ x ]t) k2) subst-eq-r-lam : ∀ {Γ Γ' τ1} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (x : fst [ τ1 ]t) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS Θ) k) (Monotone.f (interpS (throw-s (s-extend {_} {_} {τ1} Θ))) (k , x)) subst-eq-r-lam {Γ' = []} Θ k x = <> subst-eq-r-lam {Γ} {Γ' = x :: Γ'} {τ1} Θ k x₁ = (subst-eq-r-lam (throw-s Θ) k x₁) , Preorder-str.trans (snd [ x ]t) (snd (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (Θ i0)) (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁))) (Monotone.f (interpE (ren (Θ i0) iS)) (k , x₁)) (Monotone.is-monotone (interpE (Θ i0)) k (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁)) (Preorder-str.trans (snd [ Γ ]c) k (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁)) (ids-lem-r {Γ} k) (ren-eq-r-lam {Γ} {Γ} (λ x₂ → x₂) k x₁))) (ren-eq-r iS (Θ i0) (k , x₁)) subst-eq-r : ∀ {Γ Γ' τ} → (Θ : sctx Γ Γ') → (e : Γ' |- τ) → (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e Θ)) k) subst-eq-r Θ unit k = <> subst-eq-r Θ 0C k = <> subst-eq-r Θ 1C k = <> subst-eq-r Θ (plusC e e₁) k = plus-lem (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k) (subst-eq-r Θ e k) (subst-eq-r Θ e₁ k) subst-eq-r {τ = τ} Θ (var i0) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE (Θ i0)) k) subst-eq-r {τ = τ} Θ (var (iS x)) k = subst-eq-r (throw-s Θ) (var x) k subst-eq-r Θ z k = <> subst-eq-r Θ (s e) k = subst-eq-r Θ e k subst-eq-r {Γ} {Γ'} {τ} Θ (rec e e₁ e₂) k = Preorder-str.trans (snd [ τ ]t) (natrec (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (λ n x₂ → Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) k , x₂) , n)) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) (natrec (Monotone.f (interpE (subst e₁ Θ)) k) (λ n x₂ → Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) ((k , x₂) , n)) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) (natrec (Monotone.f (interpE (subst e₁ Θ)) k) (λ n x₂ → Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) ((k , x₂) , n)) (Monotone.f (interpE (subst e Θ)) k)) (♭h-cong (monotone (λ v → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) v)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁))) (interpE (subst e₁ Θ)) (monotone (λ v → Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst v)) , snd (fst v)) , snd v)) (λ x y x₁ → Monotone.is-monotone (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x) ((Monotone.f (interpS Θ) (fst (fst y)) , snd (fst y)) , snd y) ((Monotone.is-monotone (interpS Θ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) , snd (fst x₁)) , snd x₁))) (interpE (subst e₂ (s-extend (s-extend Θ)))) (k , (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) (λ x → subst-eq-r Θ e₁ x) (λ x → Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x)) (Monotone.f (interpE e₂) (Monotone.f (interpS {nat :: τ :: Γ} {_ :: _ :: Γ'} (s-extend (s-extend Θ))) x)) (Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) x) (Monotone.is-monotone (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x) (Monotone.f (interpS {nat :: τ :: Γ} {_ :: _ :: Γ'} (s-extend (s-extend Θ))) x) (((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS Θ) (fst (fst x))) (Monotone.f (interpS (λ x₁ → ren (Θ x₁) iS)) (fst x)) (Monotone.f (interpS (λ x₁ → ren (ren (Θ x₁) iS) iS)) x) (subst-eq-r-lam Θ (fst (fst x)) (snd (fst x))) (subst-eq-r-lam {τ :: Γ} {Γ'} (λ x₁ → ren (Θ x₁) iS) (fst x) (snd x))) , (Preorder-str.refl (snd [ τ ]t) (snd (fst x)))) , (♭nat-refl (snd x)))) (subst-eq-r (s-extend (s-extend Θ)) e₂ x))) (♭h-fix-args (interpE (subst e₁ Θ)) (interpE (subst e₂ (s-extend (s-extend Θ)))) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (k , Monotone.f (interpE (subst e Θ)) k) (subst-eq-r Θ e k)) subst-eq-r {Γ} {τ = τ1 ->c τ2} Θ (lam e) k x = Preorder-str.trans (snd [ τ2 ]t) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k , x)) (Monotone.f (interpE e) (Monotone.f (interpS (s-extend {_} {_} {τ1} Θ)) (k , x))) (Monotone.f (Monotone.f (interpE (subst (lam e) Θ)) k) x) ((Monotone.is-monotone (interpE e) (Monotone.f (interpS Θ) k , x) (Monotone.f (interpS (s-extend {_} {_} {τ1} Θ)) (k , x)) (subst-eq-r-lam Θ k x , (Preorder-str.refl (snd [ τ1 ]t) x)))) (subst-eq-r (s-extend Θ) e (k , x)) subst-eq-r {Γ} {τ = τ} Θ (app e e₁) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))) (Monotone.f (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))) (Monotone.f (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k)) (subst-eq-r Θ e k (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))) (Monotone.is-monotone (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e₁ Θ)) k) (subst-eq-r Θ e₁ k)) subst-eq-r Θ rz k = <> subst-eq-r Θ (rsuc e) k = subst-eq-r Θ e k subst-eq-r {Γ} {Γ'} {τ} Θ (rrec e e₁ e₂ P) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (comp (pair' id (interpE e)) (rec' (interpE e₁) (unlam' (unlam' (interpE e₂))) (sound e₁ (app (app e₂ rz) e₁) P))) (Monotone.f (interpS Θ) k)) (Monotone.f (rec' (interpE (subst e₁ Θ)) (unlam' (unlam' (interpE (subst e₂ Θ)))) (λ x₁ → sound (subst e₁ Θ) (app (app (subst e₂ Θ) rz) (subst e₁ Θ)) (subst-cong P) x₁)) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) (Monotone.f (comp (pair' id (interpE (subst e Θ))) (rec' (interpE (subst e₁ Θ)) (unlam' (unlam' (interpE (subst e₂ Θ)))) (sound (subst e₁ Θ) (app (app (subst e₂ Θ) rz) (subst e₁ Θ)) (subst-cong P)))) k) (h-cong2 (monotone (λ z₁ → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) z₁)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁))) (interpE (subst e₁ Θ)) (monotone (λ v → Monotone.f (Monotone.f (Monotone.f (interpE e₂) (Monotone.f (interpS Θ) (fst (fst v)))) (snd (fst v))) (snd v)) (λ x y x₁ → Monotone.is-monotone (unlam' (unlam' (interpE e₂))) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x) ((Monotone.f (interpS Θ) (fst (fst y)) , snd (fst y)) , snd y) ((Monotone.is-monotone (interpS Θ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) , snd (fst x₁)) , snd x₁))) (unlam' (unlam' (interpE (subst e₂ Θ)))) (λ x → subst-eq-r Θ e₁ x) (λ x → subst-eq-r Θ e₂ (fst (fst x)) (snd (fst x)) (snd x)) (λ x₁ → sound e₁ (app (app e₂ rz) e₁) P (Monotone.f (interpS Θ) x₁)) (λ x₁ → sound (subst e₁ Θ) (app (app (subst e₂ Θ) rz) (subst e₁ Θ)) (subst-cong P) x₁) (k , (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)))) (h-lem2 (interpE (subst e₁ Θ)) (unlam' (unlam' (interpE (subst e₂ Θ)))) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (k , Monotone.f (interpE (subst e Θ)) k) (λ x → sound (subst e₁ Θ) (app (app (subst e₂ Θ) rz) (subst e₁ Θ)) (subst-cong P) x) (subst-eq-r Θ e k)) subst-eq-r Θ (prod e e₁) k = (subst-eq-r Θ e k) , (subst-eq-r Θ e₁ k) subst-eq-r Θ (l-proj e) k = fst (subst-eq-r Θ e k) subst-eq-r Θ (r-proj e) k = snd (subst-eq-r Θ e k) subst-eq-r Θ nil k = <> subst-eq-r Θ (e ::c e₁) k = (subst-eq-r Θ e k) , (subst-eq-r Θ e₁ k) subst-eq-r {Γ} {Γ'} {τ} Θ (listrec {.Γ'} {τ'} e e₁ e₂) k = Preorder-str.trans (snd [ τ ]t) (lrec (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (λ x₁ x₂ x₃ → Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) k , x₃) , x₂) , x₁))) (lrec (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e₁ Θ)) k) (λ x₁ x₂ x₃ → Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (((k , x₃) , x₂) , x₁))) (lrec (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k) (λ x₁ x₂ x₃ → Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (((k , x₃) , x₂) , x₁))) (lrec-cong (monotone (λ k₁ → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k₁)) (λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁))) (interpE (subst e₁ Θ)) (monotone (λ x → Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)) (λ x y x₁ → Monotone.is-monotone (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x) (((Monotone.f (interpS Θ) (fst (fst (fst y))) , snd (fst (fst y))) , snd (fst y)) , snd y) (((Monotone.is-monotone (interpS Θ) (fst (fst (fst x))) (fst (fst (fst y))) (fst (fst (fst x₁))) , snd (fst (fst x₁))) , snd (fst x₁)) , snd x₁))) (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (k , (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))) (λ x → subst-eq-r Θ e₁ x) (λ x → Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)) (Monotone.f (interpE e₂) (Monotone.f (interpS {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (s-extend (s-extend (s-extend Θ)))) x)) (Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) x) (Monotone.is-monotone (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x) (Monotone.f (interpS {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (s-extend (s-extend (s-extend Θ)))) x) ((((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS Θ) (fst (fst (fst x)))) (Monotone.f (interpS {τ :: Γ} {Γ'} (throw-s (s-extend Θ))) (fst (fst x))) (Monotone.f (interpS (λ x₁ → ren (ren (ren (Θ x₁) iS) iS) iS)) x) (subst-eq-r-lam {Γ} {Γ'} Θ (fst (fst (fst x))) (snd (fst (fst x)))) (Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS {τ :: Γ} {Γ'} (throw-s (s-extend Θ))) (fst (fst x))) (Monotone.f (interpS (λ x₁ → ren (ren (Θ x₁) iS) iS)) (fst x)) (Monotone.f (interpS (λ x₁ → ren (ren (ren (Θ x₁) iS) iS) iS)) x) (subst-eq-r-lam (λ x₁ → ren (Θ x₁) iS) (fst (fst x)) (snd (fst x))) (subst-eq-r-lam (λ x₁ → ren (ren (Θ x₁) iS) iS) (fst x) (snd x)))) , (Preorder-str.refl (snd [ τ ]t) (snd (fst (fst x))))) , (l-refl (snd [ τ' ]t) (snd (fst x)))) , (Preorder-str.refl (snd [ τ' ]t) (snd x)))) (subst-eq-r (s-extend (s-extend (s-extend Θ))) e₂ x))) (listrec-fix-args (interpE (subst e₁ Θ)) (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (k , Monotone.f (interpE (subst e Θ)) k) (Preorder-str.refl (snd [ Γ ]c) k , subst-eq-r Θ e k)) subst-eq-r Θ true k = <> subst-eq-r Θ false k = <> subst-eq-r {τ = τ} Θ (max x e e₁) k = Preorder-max-str.max-lub [ x ]tm (Monotone.f (interpE (subst (max x e e₁) Θ)) k) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst (max x e e₁) Θ)) k) (subst-eq-r Θ e k) (Preorder-max-str.max-l [ x ]tm (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k))) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e₁ Θ)) k) (Monotone.f (interpE (subst (max x e e₁) Θ)) k) (subst-eq-r Θ e₁ k) (Preorder-max-str.max-r [ x ]tm (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k))) interp-rr-l : ∀ {Γ Γ' Γ''} (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ'' ]c) (Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k)) (Monotone.f (interpR (λ x → ρ1 (ρ2 x))) k) interp-rr-l {Γ'' = []} ρ1 ρ2 k = <> interp-rr-l {Γ'' = x :: Γ''} ρ1 ρ2 k = (interp-rr-l ρ1 (throw-r ρ2) k) , (ren-eq-r ρ1 (var (ρ2 i0)) k) interp-rr-r : ∀ {Γ Γ' Γ''} (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ'' ]c) (Monotone.f (interpR (λ x → ρ1 (ρ2 x))) k) (Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k)) interp-rr-r {Γ'' = []} ρ1 ρ2 k = <> interp-rr-r {Γ'' = x :: Γ''} ρ1 ρ2 k = (interp-rr-r ρ1 (throw-r ρ2) k) , (ren-eq-l ρ1 (var (ρ2 i0)) k) interp-rs-l : ∀ {Γ Γ' Γ''} (ρ : rctx Γ Γ') (Θ : sctx Γ' Γ'') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ'' ]c) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k)) (Monotone.f (interpS (λ x → ren (Θ x) ρ)) k) interp-rs-l {Γ'' = []} ρ Θ k = <> interp-rs-l {Γ'' = x :: Γ''} ρ Θ k = (interp-rs-l ρ (throw-s Θ) k) , (ren-eq-r ρ (Θ i0) k) interp-rs-r : ∀ {Γ Γ' Γ''} (ρ : rctx Γ Γ') (Θ : sctx Γ' Γ'') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ'' ]c) (Monotone.f (interpS (λ x → ren (Θ x) ρ)) k) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k)) interp-rs-r {Γ'' = []} ρ Θ k = <> interp-rs-r {Γ'' = x :: Γ''} ρ Θ k = (interp-rs-r ρ (throw-s Θ) k) , (ren-eq-l ρ (Θ i0) k) interp-sr-l : ∀ {Γ Γ' Γ''} (Θ : sctx Γ Γ') (ρ : rctx Γ' Γ'') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ'' ]c) (Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k)) (Monotone.f (interpS (λ x → Θ (ρ x))) k) interp-sr-l {Γ'' = []} Θ ρ k = <> interp-sr-l {Γ'' = x :: Γ''} Θ ρ k = (interp-sr-l Θ (throw-r ρ) k) , (subst-eq-r Θ (var (ρ i0)) k) interp-sr-r : ∀ {Γ Γ' Γ''} (Θ : sctx Γ Γ') (ρ : rctx Γ' Γ'') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ'' ]c) (Monotone.f (interpS (λ x → Θ (ρ x))) k) (Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k)) interp-sr-r {Γ'' = []} Θ ρ k = <> interp-sr-r {Γ'' = x :: Γ''} Θ ρ k = (interp-sr-r Θ (throw-r ρ) k) , (subst-eq-l Θ (var (ρ i0)) k) interp-ss-l : ∀ {Γ Γ' Γ''} (Θ1 : sctx Γ Γ') (Θ2 : sctx Γ' Γ'') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ'' ]c) (Monotone.f (interpS (λ x → subst (Θ2 x) Θ1)) k) (Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k)) interp-ss-l {Γ'' = []} Θ1 Θ2 k = <> interp-ss-l {Γ'' = x :: Γ''} Θ1 Θ2 k = (interp-ss-l Θ1 (throw-s Θ2) k) , (subst-eq-l Θ1 (Θ2 i0) k) interp-ss-r : ∀ {Γ Γ' Γ''} (Θ1 : sctx Γ Γ') (Θ2 : sctx Γ' Γ'') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ'' ]c) (Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k)) (Monotone.f (interpS (λ x → subst (Θ2 x) Θ1)) k) interp-ss-r {Γ'' = []} Θ1 Θ2 k = <> interp-ss-r {Γ'' = x :: Γ''} Θ1 Θ2 k = (interp-ss-r Θ1 (throw-s Θ2) k) , (subst-eq-r Θ1 (Θ2 i0) k) lam-s-lem : ∀ {Γ} (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ ]c) (Monotone.f (interpS {Γ} {Γ} ids) k) k lam-s-lem {[]} k = <> lam-s-lem {x :: Γ} (k1 , k2) = (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpS {x :: Γ} {Γ} (throw-s ids)) (k1 , k2)) (Monotone.f (interpS {Γ} {Γ} ids) k1) k1 (subst-eq-l-lam {Γ} {Γ} ids k1 (Monotone.f (interpE {x :: Γ} {x} (ids i0)) (k1 , k2))) (lam-s-lem {Γ} k1)) , (Preorder-str.refl (snd [ x ]t) k2) lam-s-lem-r : ∀ {Γ} (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ ]c) k (Monotone.f (interpS {Γ} {Γ} ids) k) lam-s-lem-r {[]} k = <> lam-s-lem-r {x :: Γ} (k1 , k2) = (Preorder-str.trans (snd [ Γ ]c) k1 (Monotone.f (interpS {Γ} {Γ} ids) k1) (Monotone.f (interpS {x :: Γ} {Γ} (throw-s ids)) (k1 , k2)) (lam-s-lem-r {Γ} k1) (subst-eq-r-lam {Γ} {Γ} ids k1 (Monotone.f (interpE {x :: Γ} {x} (ids i0)) (k1 , k2)))) , (Preorder-str.refl (snd [ x ]t) k2) interp-subst-comp-l : ∀ {Γ Γ' τ'} (Θ : sctx Γ Γ') (v : Γ |- τ') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v))) k) (Monotone.f (interpS (λ x → Θ x)) k) interp-subst-comp-l {Γ' = []} Θ v k = <> interp-subst-comp-l {Γ} {Γ' = x :: Γ'} {τ'} Θ v k = (interp-subst-comp-l (throw-s Θ) v k) , (Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v))) k) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v)) k)) (Monotone.f (interpE (Θ i0)) k) (subst-eq-l (lem3' ids v) (ren (Θ i0) iS) k) (Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v)) k)) (Monotone.f (interpE (Θ i0)) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k))) (Monotone.f (interpE (Θ i0)) k) (ren-eq-l iS (Θ i0) (Monotone.f (interpS (lem3' ids v)) k)) (Monotone.is-monotone (interpE (Θ i0)) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)) k (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)) (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) k (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (k , Monotone.f (interpE v) k)) (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) (Monotone.is-monotone (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k) (k , Monotone.f (interpE v) k) (lam-s-lem {Γ} k , (Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v) k)))) (ren-eq-l-lam {Γ} {Γ} {τ'} (λ x₂ → x₂) k (Monotone.f (interpE v) k))) (ids-lem-l {Γ} k))))) interp-subst-comp-r : ∀ {Γ Γ' τ'} (Θ : sctx Γ Γ') (v : Γ |- τ') (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS (λ x → Θ x)) k) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v))) k) interp-subst-comp-r {Γ' = []} Θ v k = <> interp-subst-comp-r {Γ} {Γ' = x :: Γ'} {τ'} Θ v k = (interp-subst-comp-r (throw-s Θ) v k) , Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (Θ i0)) k) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v)) k)) (Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v))) k) (Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (Θ i0)) k) (Monotone.f (interpE (Θ i0)) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k))) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v)) k)) (Monotone.is-monotone (interpE (Θ i0)) k (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)) (Preorder-str.trans (snd [ Γ ]c) k (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)) (ids-lem-r {Γ} k) (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (k , Monotone.f (interpE v) k)) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)) (ren-eq-r-lam {Γ} {Γ} {τ'} (λ x₂ → x₂) k (Monotone.f (interpE v) k)) (Monotone.is-monotone (interpR {τ' :: Γ} {Γ} iS) (k , Monotone.f (interpE v) k) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k) (lam-s-lem-r {Γ} k , Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v) k)))))) (ren-eq-r iS (Θ i0) (Monotone.f (interpS (lem3' ids v)) k))) (subst-eq-r (lem3' ids v) (ren (Θ i0) iS) k) interp-subst-comp2-l : ∀ {Γ Γ' τ' τ''} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (v1 : Γ |- τ') (v2 : Γ |- τ'') → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS {τ' :: τ'' :: Γ} {Γ'} (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k) interp-subst-comp2-l {Γ' = []} Θ k v1 v2 = <> interp-subst-comp2-l {Γ} {Γ' = x :: Γ'} {τ'} {τ''} Θ k v1 v2 = (interp-subst-comp2-l (throw-s Θ) k v1 v2) , Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (ren (ren (Θ i0) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))) (Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v2))) k) (ren-eq-l iS (ren (Θ i0) iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v2)) k)) (Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v2))) k) (Monotone.is-monotone (interpE (ren (Θ i0) iS)) (Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpS (lem3' ids v2)) k) (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ' :: τ'' :: Γ} (λ x₁ → iS (iS x₁))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpR {Γ} {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k)) (Monotone.f (interpS {Γ} ids) k) (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ' :: τ'' :: Γ} (λ x₁ → iS (iS x₁))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpR {τ'' :: Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k)) (Monotone.f (interpR {Γ} {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k)) (ren-eq-l-lam {τ'' :: Γ} (λ x₁ → iS x₁) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) (Monotone.f (interpE v1) k)) (ren-eq-l-lam {Γ} {Γ} {τ''} (λ x₁ → x₁) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpE v2) k))) (interp-sr-l {Γ} ids (λ x₁ → x₁) k) , Preorder-str.refl (snd [ τ'' ]t) (Monotone.f (interpE v2) k))) (subst-eq-r (lem3' ids v2) (ren (Θ i0) iS) k)) interp-subst-comp2-r : ∀ {Γ Γ' τ' τ''} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (v1 : Γ |- τ') (v2 : Γ |- τ'') → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k) (Monotone.f (interpS {τ' :: τ'' :: Γ} {Γ'} (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) interp-subst-comp2-r {Γ' = []} Θ k v1 v2 = <> interp-subst-comp2-r {Γ} {Γ' = x :: Γ'} {τ'} {τ''} Θ k v1 v2 = (interp-subst-comp2-r (throw-s Θ) k v1 v2) , (Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v2))) k) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))) (Monotone.f (interpE (ren (ren (Θ i0) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v2))) k) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v2)) k)) (Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))) (subst-eq-l (lem3' ids v2) (ren (Θ i0) iS) k) (Monotone.is-monotone (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v2)) k) (Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) ((Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpR {Γ} {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k)) (Monotone.f (interpR {τ' :: τ'' :: Γ} (λ x₁ → iS (iS x₁))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (interp-sr-r {Γ} ids (λ x₁ → x₁) k) (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {Γ} {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k)) (Monotone.f (interpR {τ'' :: Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k)) (Monotone.f (interpR {τ' :: τ'' :: Γ} (λ x₁ → iS (iS x₁))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (ren-eq-r-lam {Γ} {Γ} {τ''} (λ x₁ → x₁) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpE v2) k)) (ren-eq-r-lam {τ'' :: Γ} (λ x₁ → iS x₁) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) (Monotone.f (interpE v1) k)))) , (Preorder-str.refl (snd [ τ'' ]t) (Monotone.f (interpE v2) k))))) (ren-eq-r iS (ren (Θ i0) iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))) interp-subst-comp3-l : ∀ {Γ Γ' τ1 τ2 τ3} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (v3 : Γ |- τ3) (v2 : Γ |- τ2) (v1 : Γ |- τ1) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {Γ'} (λ x → ren (ren (ren (Θ x) iS) iS) iS)) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpS {τ2 :: τ3 :: Γ} {Γ'} (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)) interp-subst-comp3-l {Γ' = []} Θ k v3 v2 v1 = <> interp-subst-comp3-l {Γ} {Γ' = x :: Γ'} {τ1} {τ2} {τ3} Θ k v3 v2 v1 = (interp-subst-comp3-l (throw-s Θ) k v3 v2 v1) , (Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (ren (ren (ren (Θ i0) iS) iS) iS)) (((Monotone.f (interpS {Γ} {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpE (ren (ren (Θ i0) iS) iS)) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {τ2 :: τ3 :: Γ} iS) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))) (Monotone.f (interpE (ren (ren (Θ i0) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)) (ren-eq-l iS (ren (ren (Θ i0) iS) iS) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.is-monotone (interpE (ren (ren (Θ i0) iS) iS)) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {τ2 :: τ3 :: Γ} iS) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) ((Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁)))) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpR {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k)) (Monotone.f (interpS {Γ} ids) k) (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁)))) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpR {τ3 :: Γ} {Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k)) (Monotone.f (interpR {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k)) (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁)))) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpR {τ2 :: τ3 :: Γ} (throw-r (r-extend iS))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)) (Monotone.f (interpR {τ3 :: Γ} {Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k)) (fst (ren-eq-l-lam {τ2 :: τ3 :: Γ} {τ3 :: Γ} {τ1} (λ x₁ → iS x₁) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) (Monotone.f (interpE v1) k))) (ren-eq-l-lam {τ3 :: Γ} {Γ} {τ2} (λ x₁ → iS x₁) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) (Monotone.f (interpE v2) k))) (ren-eq-l-lam {Γ} {Γ} {τ3} (λ x₁ → x₁) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpE v3) k))) (interp-sr-l {Γ} ids (λ x₁ → x₁) k) , Preorder-str.refl (snd [ τ3 ]t) (Monotone.f (interpE v3) k)) , Preorder-str.refl (snd [ τ2 ]t) (Monotone.f (interpE v2) k)))) interp-subst-comp3-r : ∀ {Γ Γ' τ1 τ2 τ3} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (v3 : Γ |- τ3) (v2 : Γ |- τ2) (v1 : Γ |- τ1) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS {τ2 :: τ3 :: Γ} {Γ'} (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)) (Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {Γ'} (λ x → ren (ren (ren (Θ x) iS) iS) iS)) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) interp-subst-comp3-r {Γ' = []} Θ k v3 v2 v1 = <> interp-subst-comp3-r {Γ} {Γ' = x :: Γ'} {τ1} {τ2} {τ3} Θ k v3 v2 v1 = (interp-subst-comp3-r (throw-s Θ) k v3 v2 v1) , Preorder-str.trans (snd [ x ]t) (Monotone.f (interpE (ren (ren (Θ i0) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)) (Monotone.f (interpE (ren (ren (Θ i0) iS) iS)) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {τ2 :: τ3 :: Γ} iS) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))) (Monotone.f (interpE (ren (ren (ren (Θ i0) iS) iS) iS)) (((Monotone.f (interpS {Γ} {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.is-monotone (interpE (ren (ren (Θ i0) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {τ2 :: τ3 :: Γ} iS) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (((Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpR {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k)) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁)))) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (interp-sr-r {Γ} ids (λ x₁ → x₁) k) (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k)) (Monotone.f (interpR {τ3 :: Γ} {Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k)) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁)))) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (ren-eq-r-lam {Γ} {Γ} {τ3} (λ x₁ → x₁) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpE v3) k)) (Preorder-str.trans (snd [ Γ ]c) (Monotone.f (interpR {τ3 :: Γ} {Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k)) (Monotone.f (interpR {τ2 :: τ3 :: Γ} (throw-r (r-extend iS))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)) (Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁)))) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (ren-eq-r-lam {τ3 :: Γ} {Γ} {τ2} (λ x₁ → iS x₁) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) (Monotone.f (interpE v2) k)) (fst (ren-eq-r-lam {τ2 :: τ3 :: Γ} {τ3 :: Γ} {τ1} (λ x₁ → iS x₁) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) (Monotone.f (interpE v1) k)))))) , (Preorder-str.refl (snd [ τ3 ]t) (Monotone.f (interpE v3) k))) , (Preorder-str.refl (snd [ τ2 ]t) (Monotone.f (interpE v2) k)))) (ren-eq-r iS (ren (ren (Θ i0) iS) iS) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) s-cong2-lem : ∀ {Γ Γ'} (Θ Θ' : sctx Γ Γ') (x : (τ₁ : CTp) (x₁ : τ₁ ∈ Γ') → Θ x₁ ≤s Θ' x₁) (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS Θ) k) (Monotone.f (interpS Θ') k) s-cong2-lem {Γ' = []} Θ Θ' x k = <> s-cong2-lem {Γ' = x :: Γ'} Θ Θ' x₁ k = s-cong2-lem (throw-s Θ) (throw-s Θ') (λ τ₁ x₂ → x₁ τ₁ (iS x₂)) k , sound (Θ i0) (Θ' i0) (x₁ x i0) k sound {_} {τ} e .e refl-s k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k) sound {Γ} {τ} e e' (trans-s {.Γ} {.τ} {.e} {e''} {.e'} d d₁) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) k) (Monotone.f (interpE e'') k) (Monotone.f (interpE e') k) (sound e e'' d k) (sound e'' e' d₁ k) sound {_} {τ} e .e (cong-refl Refl) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k) sound .(plusC 0C e') e' +-unit-l k = Preorder-str.refl (snd [ rnat ]t) (Monotone.f (interpE e') k) sound e .(plusC 0C e) +-unit-l' k = Preorder-str.refl (snd [ rnat ]t) (Monotone.f (interpE e) k) sound {_} {.C} .(plusC e' 0C) e' +-unit-r k = +-unit (Monotone.f (interpE e') k) sound e .(plusC e 0C) +-unit-r' k = plus-lem' (Monotone.f (interpE e) k) (Monotone.f (interpE e) k) Z (nat-refl (Monotone.f (interpE e) k)) sound {Γ} {.C} ._ ._ (+-assoc {.Γ} {e1} {e2} {e3}) k = plus-assoc (Monotone.f (interpE e1) k) (Monotone.f (interpE e2) k) (Monotone.f (interpE e3) k) sound {Γ} {.C} ._ ._ (+-assoc' {.Γ} {e1} {e2} {e3}) k = plus-assoc' (Monotone.f (interpE e1) k) (Monotone.f (interpE e2) k) (Monotone.f (interpE e3) k) sound {Γ} {.C} ._ ._ (refl-+ {.Γ} {e0} {e1}) k = +-comm (Monotone.f (interpE e0) k) (Monotone.f (interpE e1) k) sound {Γ} {C} ._ ._ (cong-+ {.Γ} {e0} {e1} {e0'} {e1'} d d₁) k = --also called plus-s. should really delete this rule so we don't have duplicates plus-lem (Monotone.f (interpE e0) k) (Monotone.f (interpE e1) k) (Monotone.f (interpE e0') k) (Monotone.f (interpE e1') k) (sound e0 e0' d k) (sound e1 e1' d₁ k) sound {Γ} {τ} ._ ._ (cong-lproj {.Γ} {.τ} {_} {e} {e'} d) k = fst (sound e e' d k) sound {Γ} {τ} ._ ._ (cong-rproj {.Γ} {_} {.τ} {e} {e'} d) k = snd (sound e e' d k) sound {Γ} {τ} ._ ._ (cong-app {.Γ} {τ'} {.τ} {e} {e'} {e1} d) k = sound e e' d k (Monotone.f (interpE e1) k) sound {Γ} {τ} ._ ._ (ren-cong {.Γ} {Γ'} {.τ} {e1} {e2} {ρ} d) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e1 ρ)) k) (Monotone.f (interpE e1) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e2 ρ)) k) (ren-eq-l ρ e1 k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e1) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e2) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e2 ρ)) k) (sound e1 e2 d (Monotone.f (interpR ρ) k)) (ren-eq-r ρ e2 k)) sound {Γ} {τ} ._ ._ (subst-cong {.Γ} {Γ'} {.τ} {e1} {e2} {Θ} d) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 Θ)) k) (Monotone.f (interpE e1) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e2 Θ)) k) (subst-eq-l Θ e1 k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e1) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e2) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e2 Θ)) k) (sound e1 e2 d (Monotone.f (interpS Θ) k)) (subst-eq-r Θ e2 k)) sound {Γ} {τ} ._ ._ (subst-cong2 {.Γ} {Γ'} {.τ} {Θ} {Θ'} {e} x) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e Θ')) k) (subst-eq-l Θ e k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e) (Monotone.f (interpS Θ') k)) (Monotone.f (interpE (subst e Θ')) k) (Monotone.is-monotone (interpE e) (Monotone.f (interpS Θ) k) (Monotone.f (interpS Θ') k) (s-cong2-lem Θ Θ' x k)) (subst-eq-r Θ' e k)) sound {Γ} {τ} ._ ._ (cong-rec {.Γ} {.τ} {e} {e'} {e0} {e1} d) k = ♭h-fix-args (interpE e0) (interpE e1) (k , Monotone.f (interpE e) k) (k , Monotone.f (interpE e') k) (sound e e' d k) sound {Γ} {τ} ._ ._ (cong-listrec {.Γ} {τ'} {.τ} {e} {e'} {e0} {e1} d) k = listrec-fix-args (interpE e0) (interpE e1) (k , (Monotone.f (interpE e) k)) (k , Monotone.f (interpE e') k) ((Preorder-str.refl (snd [ Γ ]c) k) , (sound e e' d k)) sound {Γ} {τ} ._ ._ (lam-s {.Γ} {τ'} {.τ} {e} {e2}) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (q e2))) k) (Monotone.f (interpE e) (Monotone.f (interpS (q e2)) k)) (Monotone.f (interpE e) (k , Monotone.f (interpE e2) k)) (subst-eq-l (q e2) e k) (Monotone.is-monotone (interpE e) (Monotone.f (interpS (q e2)) k) (k , Monotone.f (interpE e2) k) (lam-s-lem {Γ} k , (Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE e2) k)))) sound {Γ} {τ} e ._ (l-proj-s {.Γ}) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k) sound {Γ} {τ} e ._ (r-proj-s {.Γ}) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k) sound {_} {τ} e ._ rec-steps-z k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k) sound {Γ} {τ} ._ ._ (rec-steps-s {.Γ} {.τ} {e} {e0} {e1}) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem3' (lem3' ids (rec e e0 e1)) e))) k) (Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' ids (rec e e0 e1)) e)) k)) (Monotone.f (interpE e1) ((k , natrec (Monotone.f (interpE e0) k) (λ n x₂ → Monotone.f (interpE e1) ((k , x₂) , n)) (Monotone.f (interpE e) k)) , Monotone.f (interpE e) k)) (subst-eq-l (lem3' (lem3' ids (rec e e0 e1)) e) e1 k) (Monotone.is-monotone (interpE e1) (Monotone.f (interpS (lem3' (lem3' ids (rec e e0 e1)) e)) k) ((k , natrec (Monotone.f (interpE e0) k) (λ n x₂ → Monotone.f (interpE e1) ((k , x₂) , n)) (Monotone.f (interpE e) k)) , Monotone.f (interpE e) k) ((lam-s-lem {Γ} k , (Preorder-str.refl (snd [ τ ]t) (natrec (Monotone.f (interpE e0) k) (λ n x₂ → Monotone.f (interpE e1) ((k , x₂) , n)) (Monotone.f (interpE e) k)))) , (♭nat-refl (Monotone.f (interpE e) k)))) sound {Γ} {τ} e ._ listrec-steps-nil k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k) sound {Γ} {τ} ._ ._ (listrec-steps-cons {.Γ} {τ'} {.τ} {h} {t} {e0} {e1}) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem3' (lem3' (lem3' ids (listrec t e0 e1)) t) h))) k) (Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' (lem3' ids (listrec t e0 e1)) t) h)) k)) (Monotone.f (interpE e1) (((k , lrec (Monotone.f (interpE t) k) (Monotone.f (interpE e0) k) (λ x₁ x₂ x₃ → Monotone.f (interpE e1) (((k , x₃) , x₂) , x₁))) , Monotone.f (interpE t) k) , Monotone.f (interpE h) k)) (subst-eq-l (lem3' (lem3' (lem3' ids (listrec t e0 e1)) t) h) e1 k) (Monotone.is-monotone (interpE e1) (Monotone.f (interpS (lem3' (lem3' (lem3' ids (listrec t e0 e1)) t) h)) k) (((k , lrec (Monotone.f (interpE t) k) (Monotone.f (interpE e0) k) (λ x₁ x₂ x₃ → Monotone.f (interpE e1) (((k , x₃) , x₂) , x₁))) , Monotone.f (interpE t) k) , Monotone.f (interpE h) k) (((lam-s-lem {Γ} k , (Preorder-str.refl (snd [ τ ]t) (lrec (Monotone.f (interpE t) k) (Monotone.f (interpE e0) k) (λ x₁ x₂ x₃ → Monotone.f (interpE e1) (((k , x₃) , x₂) , x₁))))) , (l-refl (snd [ τ' ]t) (Monotone.f (interpE t) k))) , (Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE h) k)))) sound {Γ} {τ} .(ren (ren e ρ2) ρ1) ._ (ren-comp-l ρ1 ρ2 e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren (ren e ρ2) ρ1)) k) (Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k)) (Monotone.f (interpE (ren e (ρ1 ∙rr ρ2))) k) (ren-eq-l ρ1 (ren e ρ2) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k)) (Monotone.f (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k)) (Monotone.f (interpE (ren e (ρ1 ∙rr ρ2))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k)) (Monotone.f (interpE e) (Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k))) (Monotone.f (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k)) (ren-eq-l ρ2 e (Monotone.f (interpR ρ1) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k)) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k) (interp-rr-l ρ1 ρ2 k))) (ren-eq-r (ρ1 ∙rr ρ2) e k)) sound {Γ} {τ} ._ .(ren (ren e ρ2) ρ1) (ren-comp-r ρ1 ρ2 e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e (ρ1 ∙rr ρ2))) k) (Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k)) (Monotone.f (interpE (ren (ren e ρ2) ρ1)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e (ρ1 ∙rr ρ2))) k) (Monotone.f (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k)) (Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k)) (ren-eq-l (ρ1 ∙rr ρ2) e k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k)) (Monotone.f (interpE e) (Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k))) (Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k) (Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k)) (interp-rr-r ρ1 ρ2 k)) (ren-eq-r ρ2 e (Monotone.f (interpR ρ1) k)))) (ren-eq-r ρ1 (ren e ρ2) k) sound {Γ} {τ} e ._ (subst-id-l .e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) k) (Monotone.f (interpE e) (Monotone.f (interpS {Γ} {Γ} ids) k)) (Monotone.f (interpE (subst e ids)) k) (Monotone.is-monotone (interpE e) k (Monotone.f (interpS {Γ} {Γ} ids) k) (lam-s-lem-r {Γ} k)) (subst-eq-r ids e k) sound {Γ} {τ} ._ e' (subst-id-r .e') k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e' ids)) k) (Monotone.f (interpE e') (Monotone.f (interpS {Γ} {Γ} ids) k)) (Monotone.f (interpE e') k) (subst-eq-l ids e' k) (Monotone.is-monotone (interpE e') (Monotone.f (interpS {Γ} {Γ} ids) k) k (lam-s-lem {Γ} k)) sound {Γ} {τ} .(ren (subst e Θ) ρ) ._ (subst-rs-l ρ Θ e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren (subst e Θ) ρ)) k) (Monotone.f (interpE (subst e Θ)) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (subst e (ρ rs Θ))) k) (ren-eq-l ρ (subst e Θ) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e Θ)) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k))) (Monotone.f (interpE (subst e (ρ rs Θ))) k) (subst-eq-l Θ e (Monotone.f (interpR ρ) k)) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k))) (Monotone.f (interpE e) (Monotone.f (interpS (ρ rs Θ)) k)) (Monotone.f (interpE (subst e (ρ rs Θ))) k) (Monotone.is-monotone (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k)) (Monotone.f (interpS (ρ rs Θ)) k) (interp-rs-l ρ Θ k)) (subst-eq-r (ρ rs Θ) e k))) sound {Γ} {τ} ._ .(ren (subst e Θ) ρ) (subst-rs-r ρ Θ e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (ρ rs Θ))) k) (Monotone.f (interpE (subst e Θ)) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren (subst e Θ) ρ)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (ρ rs Θ))) k) (Monotone.f (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k))) (Monotone.f (interpE (subst e Θ)) (Monotone.f (interpR ρ) k)) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (ρ rs Θ))) k) (Monotone.f (interpE e) (Monotone.f (interpS (ρ rs Θ)) k)) (Monotone.f (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k))) (subst-eq-l (ρ rs Θ) e k) (Monotone.is-monotone (interpE e) (Monotone.f (interpS (ρ rs Θ)) k) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k)) (interp-rs-r ρ Θ k))) (subst-eq-r Θ e (Monotone.f (interpR ρ) k))) (ren-eq-r ρ (subst e Θ) k) sound {Γ} {τ} .(subst (ren e ρ) Θ) ._ (subst-sr-l Θ ρ e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst (ren e ρ) Θ)) k) (Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e (Θ sr ρ))) k) (subst-eq-l Θ (ren e ρ) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e) (Monotone.f (interpS (Θ sr ρ)) k)) (Monotone.f (interpE (subst e (Θ sr ρ))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e) (Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k))) (Monotone.f (interpE e) (Monotone.f (interpS (Θ sr ρ)) k)) (ren-eq-l ρ e (Monotone.f (interpS Θ) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k)) (Monotone.f (interpS (Θ sr ρ)) k) (interp-sr-l Θ ρ k))) (subst-eq-r (Θ sr ρ) e k)) sound {Γ} {τ} ._ .(subst (ren e ρ) Θ) (subst-sr-r Θ ρ e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (Θ sr ρ))) k) (Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst (ren e ρ) Θ)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (Θ sr ρ))) k) (Monotone.f (interpE e) (Monotone.f (interpS (Θ sr ρ)) k)) (Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k)) (subst-eq-l (Θ sr ρ) e k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS (Θ sr ρ)) k)) (Monotone.f (interpE e) (Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k))) (Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpS (Θ sr ρ)) k) (Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k)) (interp-sr-r Θ ρ k)) (ren-eq-r ρ e (Monotone.f (interpS Θ) k)))) (subst-eq-r Θ (ren e ρ) k) sound {Γ} {τ} ._ .(subst (subst e Θ2) Θ1) (subst-ss-l Θ1 Θ2 e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (Θ1 ss Θ2))) k) (Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k)) (Monotone.f (interpE (subst (subst e Θ2) Θ1)) k) (subst-eq-l (Θ1 ss Θ2) e k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k)) (Monotone.f (interpE (subst e Θ2)) (Monotone.f (interpS Θ1) k)) (Monotone.f (interpE (subst (subst e Θ2) Θ1)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k)) (Monotone.f (interpE e) (Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k))) (Monotone.f (interpE (subst e Θ2)) (Monotone.f (interpS Θ1) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k) (Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k)) (interp-ss-l Θ1 Θ2 k)) (subst-eq-r Θ2 e (Monotone.f (interpS Θ1) k))) (subst-eq-r Θ1 (subst e Θ2) k)) sound {Γ} {τ} .(subst (subst e Θ2) Θ1) ._ (subst-ss-r Θ1 Θ2 e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst (subst e Θ2) Θ1)) k) (Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k)) (Monotone.f (interpE (subst e (Θ1 ss Θ2))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst (subst e Θ2) Θ1)) k) (Monotone.f (interpE (subst e Θ2)) (Monotone.f (interpS Θ1) k)) (Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k)) (subst-eq-l Θ1 (subst e Θ2) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e Θ2)) (Monotone.f (interpS Θ1) k)) (Monotone.f (interpE e) (Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k))) (Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k)) (subst-eq-l Θ2 e (Monotone.f (interpS Θ1) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k)) (Monotone.f (interpS (Θ1 ss Θ2)) k) (interp-ss-r Θ1 Θ2 k)))) (subst-eq-r (Θ1 ss Θ2) e k) sound {Γ} {τ} ._ .(subst e (lem3' Θ v)) (subst-compose-l {.Γ} {Γ'} {τ'} Θ v e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst (subst e (s-extend Θ)) (q v))) k) (Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k)) (Monotone.f (interpE (subst e (lem3' Θ v))) k) (subst-eq-l (q v) (subst e (s-extend Θ)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k)) (Monotone.f (interpE e) (Monotone.f (interpS (lem3' Θ v)) k)) (Monotone.f (interpE (subst e (lem3' Θ v))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k)) (Monotone.f (interpE e) (Monotone.f (interpS {τ' :: Γ} {τ' :: Γ'} (s-extend {Γ} {Γ'} Θ)) (Monotone.f (interpS {Γ} {τ' :: Γ} (q v)) k))) (Monotone.f (interpE e) (Monotone.f (interpS (lem3' Θ v)) k)) (subst-eq-l (s-extend Θ) e (Monotone.f (interpS (q v)) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpS {τ' :: Γ} {τ' :: Γ'} (s-extend {Γ} {Γ'} Θ)) (Monotone.f (interpS {Γ} {τ' :: Γ} (q v)) k)) (Monotone.f (interpS (lem3' Θ v)) k) (Preorder-str.trans (snd [ Γ' ]c) (fst (Monotone.f (interpS (s-extend Θ)) (Monotone.f (interpS (q v)) k))) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v))) k) (Monotone.f (interpS Θ) k) (fst (interp-ss-r (q v) (s-extend Θ) k)) (interp-subst-comp-l Θ v k) , Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v) k)))) (subst-eq-r (lem3' Θ v) e k)) sound {Γ} {τ} .(subst e (lem3' Θ v)) ._ (subst-compose-r {.Γ} {Γ'} {τ'} Θ v e) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (lem3' Θ v))) k) (Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k)) (Monotone.f (interpE (subst (subst e (s-extend Θ)) (q v))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (lem3' Θ v))) k) (Monotone.f (interpE e) (Monotone.f (interpS (lem3' Θ v)) k)) (Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k)) (subst-eq-l (lem3' Θ v) e k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS (lem3' Θ v)) k)) (Monotone.f (interpE e) (Monotone.f (interpS {τ' :: Γ} {τ' :: Γ'} (s-extend {Γ} {Γ'} Θ)) (Monotone.f (interpS {Γ} {τ' :: Γ} (q v)) k))) (Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpS (lem3' Θ v)) k) (Monotone.f (interpS {τ' :: Γ} {τ' :: Γ'} (s-extend {Γ} {Γ'} Θ)) (Monotone.f (interpS {Γ} {τ' :: Γ} (q v)) k)) ((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS Θ) k) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v))) k) (fst (Monotone.f (interpS (s-extend Θ)) (Monotone.f (interpS (q v)) k))) (interp-subst-comp-r Θ v k) (fst (interp-ss-l (q v) (s-extend Θ) k))) , (Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v) k)))) (subst-eq-r (s-extend Θ) e (Monotone.f (interpS (q v)) k)))) (subst-eq-r (q v) (subst e (s-extend Θ)) k) sound {Γ} {τ} ._ .(subst e1 (lem3' (lem3' Θ v2) v1)) (subst-compose2-l {.Γ} {Γ'} {.τ} {τ'} {τ''} Θ e1 v1 v2) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2))) k) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k) (subst-eq-l (lem4 v1 v2) (subst e1 (s-extend (s-extend Θ))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k)) (Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpE e1) (Monotone.f (interpS {τ' :: τ'' :: Γ} {τ' :: τ'' :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k))) (Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k)) (subst-eq-l (s-extend (s-extend Θ)) e1 (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.is-monotone (interpE e1) (Monotone.f (interpS {τ' :: τ'' :: Γ} {τ' :: τ'' :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpS (lem4' Θ v1 v2)) k) ((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k) (Monotone.f (interpS Θ) k) (interp-subst-comp2-l Θ k v1 v2) (interp-subst-comp-l Θ v2 k) , Preorder-str.refl (snd [ τ'' ]t) (Monotone.f (interpE v2) k)) , Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v1) k)))) (subst-eq-r (lem4' Θ v1 v2) e1 k)) sound {Γ} {τ} .(subst e1 (lem3' (lem3' Θ v2) v1)) ._ (subst-compose2-r {.Γ} {Γ'} {.τ} {τ'} {τ''} Θ e1 v1 v2) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpE (subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k) (Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k)) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (subst-eq-l (lem4' Θ v1 v2) e1 k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k)) (Monotone.f (interpE e1) (Monotone.f (interpS {τ' :: τ'' :: Γ} {τ' :: τ'' :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k))) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.is-monotone (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k) (Monotone.f (interpS {τ' :: τ'' :: Γ} {τ' :: τ'' :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k)) (((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS Θ) k) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k) (Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (interp-subst-comp-r Θ v2 k) (interp-subst-comp2-r Θ k v1 v2)) , (Preorder-str.refl (snd [ τ'' ]t) (Monotone.f (interpE v2) k))) , (Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v1) k)))) (subst-eq-r (s-extend (s-extend Θ)) e1 (Monotone.f (interpS (lem4 v1 v2)) k)))) (subst-eq-r (lem4 v1 v2) (subst e1 (s-extend (s-extend Θ))) k) sound {Γ} {τ} ._ .(subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) (subst-compose3-l {.Γ} {Γ'} {.τ} {τ'} {τ''} Θ e1 v1 v2) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst (subst e1 (lem3' (lem3' ids v2) v1)) Θ)) k) (Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)))) k) (subst-eq-l Θ (subst e1 (lem3' (lem3' ids v2) v1)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k)) (Monotone.f (interpE (subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' ids v2) v1)) (Monotone.f (interpS Θ) k))) (Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k)) (subst-eq-l (lem3' (lem3' ids v2) v1) e1 (Monotone.f (interpS Θ) k)) (Monotone.is-monotone (interpE e1) (Monotone.f (interpS (lem3' (lem3' ids v2) v1)) (Monotone.f (interpS Θ) k)) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k) (((interp-ss-r Θ ids k) , (subst-eq-r Θ v2 k)) , (subst-eq-r Θ v1 k)))) (subst-eq-r (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)) e1 k)) sound {Γ} {τ} .(subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) ._ (subst-compose3-r {.Γ} {Γ'} {.τ} {τ'} {τ''} Θ e1 v1 v2) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)))) k) (Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst (subst e1 (lem3' (lem3' ids v2) v1)) Θ)) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)))) k) (Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k)) (Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k)) (subst-eq-l (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)) e1 k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k)) (Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' ids v2) v1)) (Monotone.f (interpS Θ) k))) (Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k)) (Monotone.is-monotone (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k) (Monotone.f (interpS (lem3' (lem3' ids v2) v1)) (Monotone.f (interpS Θ) k)) (((interp-ss-l Θ ids k) , (subst-eq-l Θ v2 k)) , (subst-eq-l Θ v1 k))) (subst-eq-r (lem3' (lem3' ids v2) v1) e1 (Monotone.f (interpS Θ) k)))) (subst-eq-r Θ (subst e1 (lem3' (lem3' ids v2) v1)) k) sound {Γ} {τ} ._ .(subst e1 (lem3' (lem3' Θ v2) v1)) (subst-compose4-l {.Γ} {Γ'} Θ v1 v2 e1) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2))) k) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k) (subst-eq-l (lem4 v1 v2) (subst e1 (s-extend (s-extend Θ))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k)) (Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpE e1) (Monotone.f (interpS {nat :: τ :: Γ} {nat :: τ :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k))) (Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k)) (subst-eq-l (s-extend (s-extend Θ)) e1 (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.is-monotone (interpE e1) (Monotone.f (interpS {nat :: τ :: Γ} {nat :: τ :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpS (lem4' Θ v1 v2)) k) ((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k) (Monotone.f (interpS Θ) k) (interp-subst-comp2-l Θ k v1 v2) (interp-subst-comp-l Θ v2 k) , Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE v2) k)) , Preorder-str.refl (snd [ nat ]t) (Monotone.f (interpE v1) k)))) (subst-eq-r (lem4' Θ v1 v2) e1 k)) sound {Γ} {τ} .(subst e1 (lem3' (lem3' Θ v2) v1)) ._ (subst-compose4-r {.Γ} {Γ'} Θ v1 v2 e1) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.f (interpE (subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k) (Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k)) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (subst-eq-l (lem4' Θ v1 v2) e1 k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k)) (Monotone.f (interpE e1) (Monotone.f (interpS {nat :: τ :: Γ} {nat :: τ :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k))) (Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k)) (Monotone.is-monotone (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k) (Monotone.f (interpS {nat :: τ :: Γ} {nat :: τ :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k)) (((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS Θ) k) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k) (Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (interp-subst-comp-r Θ v2 k) (interp-subst-comp2-r Θ k v1 v2)) , (Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE v2) k))) , (Preorder-str.refl (snd [ nat ]t) (Monotone.f (interpE v1) k)))) (subst-eq-r (s-extend (s-extend Θ)) e1 (Monotone.f (interpS (lem4 v1 v2)) k)))) (subst-eq-r (lem4 v1 v2) (subst e1 (s-extend (s-extend Θ))) k) sound {Γ} {τ} ._ .(subst e (lem3' (lem3' (lem3' Θ v3) v2) v1)) (subst-compose5-l {.Γ} {Γ'} {.τ} {τ1} {τ2} {τ3} Θ e v1 v2 v3) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst (subst e (s-extend (s-extend (s-extend Θ)))) (lem3' (lem3' (lem3' ids v3) v2) v1))) k) (Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) (Monotone.f (interpE (subst e (lem3' (lem3' (lem3' Θ v3) v2) v1))) k) (subst-eq-l (lem3' (lem3' (lem3' ids v3) v2) v1) (subst e (s-extend (s-extend (s-extend Θ)))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) (Monotone.f (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k)) (Monotone.f (interpE (subst e (lem3' (lem3' (lem3' Θ v3) v2) v1))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) (Monotone.f (interpE e) (Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {τ1 :: τ2 :: τ3 :: Γ'} (s-extend (s-extend (s-extend Θ)))) (Monotone.f (interpS {Γ} {τ1 :: τ2 :: τ3 :: Γ} (lem3' (lem3' (lem3' ids v3) v2) v1)) k))) (Monotone.f (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k)) (subst-eq-l (s-extend (s-extend (s-extend Θ))) e (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {τ1 :: τ2 :: τ3 :: Γ'} (s-extend (s-extend (s-extend Θ)))) (Monotone.f (interpS {Γ} {τ1 :: τ2 :: τ3 :: Γ} (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k) ((((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS (λ x → ren (ren (ren (Θ x) iS) iS) iS)) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v3))) k) (Monotone.f (interpS Θ) k) (Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS (λ x → ren (ren (ren (Θ x) iS) iS) iS)) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v3))) k) (interp-subst-comp3-l Θ k v3 v2 v1) (interp-subst-comp2-l Θ k v2 v3)) (interp-subst-comp-l Θ v3 k)) , (Preorder-str.refl (snd [ τ3 ]t) (Monotone.f (interpE v3) k))) , (Preorder-str.refl (snd [ τ2 ]t) (Monotone.f (interpE v2) k))) , (Preorder-str.refl (snd [ τ1 ]t) (Monotone.f (interpE v1) k))))) (subst-eq-r (lem3' (lem3' (lem3' Θ v3) v2) v1) e k)) sound {Γ} {τ} .(subst e (lem3' (lem3' (lem3' Θ v3) v2) v1)) ._ (subst-compose5-r {.Γ} {Γ'} {.τ} {τ1} {τ2} {τ3} Θ e v1 v2 v3) k = Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (lem3' (lem3' (lem3' Θ v3) v2) v1))) k) (Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) (Monotone.f (interpE (subst (subst e (s-extend (s-extend (s-extend Θ)))) (lem3' (lem3' (lem3' ids v3) v2) v1))) k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE (subst e (lem3' (lem3' (lem3' Θ v3) v2) v1))) k) (Monotone.f (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k)) (Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) (subst-eq-l (lem3' (lem3' (lem3' Θ v3) v2) v1) e k) (Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k)) (Monotone.f (interpE e) (Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {τ1 :: τ2 :: τ3 :: Γ'} (s-extend (s-extend (s-extend Θ)))) (Monotone.f (interpS {Γ} {τ1 :: τ2 :: τ3 :: Γ} (lem3' (lem3' (lem3' ids v3) v2) v1)) k))) (Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) (Monotone.is-monotone (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k) (Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {τ1 :: τ2 :: τ3 :: Γ'} (s-extend (s-extend (s-extend Θ)))) (Monotone.f (interpS {Γ} {τ1 :: τ2 :: τ3 :: Γ} (lem3' (lem3' (lem3' ids v3) v2) v1)) k)) ((((Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS Θ) k) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v3))) k) (Monotone.f (interpS (λ x → ren (ren (ren (Θ x) iS) iS) iS)) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (interp-subst-comp-r Θ v3 k) (Preorder-str.trans (snd [ Γ' ]c) (Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v3))) k) (Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)) (Monotone.f (interpS (λ x → ren (ren (ren (Θ x) iS) iS) iS)) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)) (interp-subst-comp2-r Θ k v2 v3) (interp-subst-comp3-r Θ k v3 v2 v1))) , (Preorder-str.refl (snd [ τ3 ]t) (Monotone.f (interpE v3) k))) , (Preorder-str.refl (snd [ τ2 ]t) (Monotone.f (interpE v2) k))) , (Preorder-str.refl (snd [ τ1 ]t) (Monotone.f (interpE v1) k)))) (subst-eq-r (s-extend (s-extend (s-extend Θ))) e (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k)))) (subst-eq-r (lem3' (lem3' (lem3' ids v3) v2) v1) (subst e (s-extend (s-extend (s-extend Θ)))) k)
65.815359
172
0.509753
4d300b0c6b16567f044c75fc20d7e34bee09630b
698
agda
Agda
agda/HITs/PropositionalTruncation/Sugar.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/HITs/PropositionalTruncation/Sugar.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/HITs/PropositionalTruncation/Sugar.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module HITs.PropositionalTruncation.Sugar where open import Cubical.HITs.PropositionalTruncation open import Level _=<<_ : ∀ {a} {A : Type a} {b} {B : ∥ A ∥ → Type b} → ((x : A) → ∥ B ∣ x ∣ ∥) → (xs : ∥ A ∥) → ∥ B xs ∥ _=<<_ = elimPropTrunc (λ _ → squash) _>>=_ : ∀ {a} {A : Type a} {b} {B : Type b} → (xs : ∥ A ∥) → (A → ∥ B ∥) → ∥ B ∥ _>>=_ {a} {A} {b} {B} xs f = elimPropTrunc (λ _ → squash) f xs _>>_ : ∥ A ∥ → ∥ B ∥ → ∥ B ∥ _ >> ys = ys pure : A → ∥ A ∥ pure = ∣_∣ _<*>_ : ∥ (A → B) ∥ → ∥ A ∥ → ∥ B ∥ fs <*> xs = do f ← fs x ← xs ∣ f x ∣ infixr 1 _∥$∥_ _∥$∥_ : (A → B)→ ∥ A ∥ → ∥ B ∥ f ∥$∥ xs = recPropTrunc squash (λ x → ∣ f x ∣) xs
22.516129
62
0.441261
123c1d97f0550cd82b2b9717c15b61a572ee93a9
4,964
agda
Agda
src/Bf/Mp.agda
mietek/formal-logic
2dd761bfa96ccda089888e8defa6814776fa2922
[ "X11" ]
26
2015-08-31T09:49:52.000Z
2021-11-13T12:37:44.000Z
src/Bf/Mp.agda
mietek/formal-logic
2dd761bfa96ccda089888e8defa6814776fa2922
[ "X11" ]
null
null
null
src/Bf/Mp.agda
mietek/formal-logic
2dd761bfa96ccda089888e8defa6814776fa2922
[ "X11" ]
null
null
null
-- Minimal propositional logic, de Bruijn approach, final encoding module Bf.Mp where open import Lib using (List; _,_; LMem; lzero; lsuc) -- Types infixl 2 _&&_ infixl 1 _||_ infixr 0 _=>_ data Ty : Set where UNIT : Ty _=>_ : Ty -> Ty -> Ty _&&_ : Ty -> Ty -> Ty _||_ : Ty -> Ty -> Ty FALSE : Ty infixr 0 _<=>_ _<=>_ : Ty -> Ty -> Ty a <=> b = (a => b) && (b => a) NOT : Ty -> Ty NOT a = a => FALSE TRUE : Ty TRUE = FALSE => FALSE -- Context and truth judgement Cx : Set Cx = List Ty isTrue : Ty -> Cx -> Set isTrue a tc = LMem a tc -- Terms TmRepr : Set1 TmRepr = Cx -> Ty -> Set module ArrMp where record Tm (tr : TmRepr) : Set1 where infixl 1 _$_ infixr 0 lam=>_ field var : forall {tc a} -> isTrue a tc -> tr tc a lam=>_ : forall {tc a b} -> tr (tc , a) b -> tr tc (a => b) _$_ : forall {tc a b} -> tr tc (a => b) -> tr tc a -> tr tc b v0 : forall {tc a} -> tr (tc , a) a v0 = var lzero v1 : forall {tc a b} -> tr (tc , a , b) a v1 = var (lsuc lzero) v2 : forall {tc a b c} -> tr (tc , a , b , c) a v2 = var (lsuc (lsuc lzero)) open Tm {{...}} public module Mp where record Tm (tr : TmRepr) : Set1 where field pair' : forall {tc a b} -> tr tc a -> tr tc b -> tr tc (a && b) fst : forall {tc a b} -> tr tc (a && b) -> tr tc a snd : forall {tc a b} -> tr tc (a && b) -> tr tc b left : forall {tc a b} -> tr tc a -> tr tc (a || b) right : forall {tc a b} -> tr tc b -> tr tc (a || b) case' : forall {tc a b c} -> tr tc (a || b) -> tr (tc , a) c -> tr (tc , b) c -> tr tc c isArrMp : ArrMp.Tm tr open ArrMp.Tm isArrMp public syntax pair' x y = [ x , y ] syntax case' xy x y = case xy => x => y open Tm {{...}} public Thm : Ty -> Set1 Thm a = forall {tr tc} {{_ : Tm tr}} -> tr tc a open Mp public -- Example theorems c1 : forall {a b} -> Thm (a && b <=> b && a) c1 = [ lam=> [ snd v0 , fst v0 ] , lam=> [ snd v0 , fst v0 ] ] c2 : forall {a b} -> Thm (a || b <=> b || a) c2 = [ lam=> (case v0 => right v0 => left v0) , lam=> (case v0 => right v0 => left v0) ] i1 : forall {a} -> Thm (a && a <=> a) i1 = [ lam=> fst v0 , lam=> [ v0 , v0 ] ] i2 : forall {a} -> Thm (a || a <=> a) i2 = [ lam=> (case v0 => v0 => v0) , lam=> left v0 ] l3 : forall {a} -> Thm ((a => a) <=> TRUE) l3 = [ lam=> lam=> v0 , lam=> lam=> v0 ] l1 : forall {a b c} -> Thm (a && (b && c) <=> (a && b) && c) l1 = [ lam=> [ [ fst v0 , fst (snd v0) ] , snd (snd v0) ] , lam=> [ fst (fst v0) , [ snd (fst v0) , snd v0 ] ] ] l2 : forall {a} -> Thm (a && TRUE <=> a) l2 = [ lam=> fst v0 , lam=> [ v0 , lam=> v0 ] ] l4 : forall {a b c} -> Thm (a && (b || c) <=> (a && b) || (a && c)) l4 = [ lam=> (case snd v0 => left [ fst v1 , v0 ] => right [ fst v1 , v0 ]) , lam=> (case v0 => [ fst v0 , left (snd v0) ] => [ fst v0 , right (snd v0) ]) ] l6 : forall {a b c} -> Thm (a || (b && c) <=> (a || b) && (a || c)) l6 = [ lam=> (case v0 => [ left v0 , left v0 ] => [ right (fst v0) , right (snd v0) ]) , lam=> (case fst v0 => left v0 => case snd v1 => left v0 => right [ v1 , v0 ]) ] l7 : forall {a} -> Thm (a || TRUE <=> TRUE) l7 = [ lam=> lam=> v0 , lam=> right v0 ] l9 : forall {a b c} -> Thm (a || (b || c) <=> (a || b) || c) l9 = [ lam=> (case v0 => left (left v0) => case v0 => left (right v0) => right v0) , lam=> (case v0 => case v0 => left v0 => right (left v0) => right (right v0)) ] l11 : forall {a b c} -> Thm ((a => (b && c)) <=> (a => b) && (a => c)) l11 = [ lam=> [ lam=> fst (v1 $ v0) , lam=> snd (v1 $ v0) ] , lam=> lam=> [ fst v1 $ v0 , snd v1 $ v0 ] ] l12 : forall {a} -> Thm ((a => TRUE) <=> TRUE) l12 = [ lam=> lam=> v0 , lam=> lam=> v1 ] l13 : forall {a b c} -> Thm ((a => (b => c)) <=> ((a && b) => c)) l13 = [ lam=> lam=> v1 $ fst v0 $ snd v0 , lam=> lam=> lam=> v2 $ [ v1 , v0 ] ] l16 : forall {a b c} -> Thm (((a && b) => c) <=> (a => (b => c))) l16 = [ lam=> lam=> lam=> v2 $ [ v1 , v0 ] , lam=> lam=> v1 $ fst v0 $ snd v0 ] l17 : forall {a} -> Thm ((TRUE => a) <=> a) l17 = [ lam=> v0 $ (lam=> v0) , lam=> lam=> v1 ] l19 : forall {a b c} -> Thm (((a || b) => c) <=> (a => c) && (b => c)) l19 = [ lam=> [ lam=> v1 $ left v0 , lam=> v1 $ right v0 ] , lam=> lam=> (case v0 => fst v2 $ v0 => snd v2 $ v0) ]
20.016129
94
0.397462
0b23c146cc2c04909f07dd492cef030970354b0d
348
agda
Agda
test/Common/Bool.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Common/Bool.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Common/Bool.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
{-# OPTIONS --cubical-compatible #-} module Common.Bool where open import Agda.Builtin.Bool public not : Bool -> Bool not true = false not false = true notnot : Bool -> Bool notnot true = not (not true) notnot false = not (not false) if_then_else_ : ∀ {a} {A : Set a} → Bool → A → A → A if true then t else f = t if false then t else f = f
19.333333
52
0.655172
18aa41ad1c0c1e753c0165f90b199ec452966d35
87
agda
Agda
examples/NoSig.agda
JoeyEremondi/lambda-pi-constraint
64a1b4c6632153d75cba540f7c91f40b49375e2f
[ "BSD-3-Clause" ]
16
2017-03-16T11:14:56.000Z
2021-02-05T20:21:46.000Z
examples/NoSig.agda
JoeyEremondi/lambda-pi-constraint
64a1b4c6632153d75cba540f7c91f40b49375e2f
[ "BSD-3-Clause" ]
null
null
null
examples/NoSig.agda
JoeyEremondi/lambda-pi-constraint
64a1b4c6632153d75cba540f7c91f40b49375e2f
[ "BSD-3-Clause" ]
null
null
null
module NoSig where open import Data.Nat myFun : ℕ myFun = (\ x y -> y ) (\ x -> x) 0
12.428571
34
0.574713
1245ba860d8525eaba4fdd5751901e7339eb711b
4,839
agda
Agda
Cubical/Data/Queue/Truncated2List.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/Queue/Truncated2List.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/Queue/Truncated2List.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --no-exact-split --safe #-} module Cubical.Data.Queue.Truncated2List where open import Cubical.Foundations.Everything open import Cubical.Foundations.SIP open import Cubical.Structures.Queue open import Cubical.Data.Maybe open import Cubical.Data.List open import Cubical.Data.Sigma open import Cubical.Data.Queue.1List module Truncated2List {ℓ} (A : Type ℓ) (Aset : isSet A) where open Queues-on A Aset data Q : Type ℓ where Q⟨_,_⟩ : (xs ys : List A) → Q tilt : ∀ xs ys z → Q⟨ xs ++ [ z ] , ys ⟩ ≡ Q⟨ xs , ys ++ [ z ] ⟩ trunc : (q q' : Q) (α β : q ≡ q') → α ≡ β multitilt : (xs ys zs : List A) → Q⟨ xs ++ rev zs , ys ⟩ ≡ Q⟨ xs , ys ++ zs ⟩ multitilt xs ys [] = cong₂ Q⟨_,_⟩ (++-unit-r xs) (sym (++-unit-r ys)) multitilt xs ys (z ∷ zs) = cong (λ ws → Q⟨ ws , ys ⟩) (sym (++-assoc xs (rev zs) [ z ])) ∙ tilt (xs ++ rev zs) ys z ∙ multitilt xs (ys ++ [ z ]) zs ∙ cong (λ ws → Q⟨ xs , ws ⟩) (++-assoc ys [ z ] zs) -- enq into the first list, deq from the second if possible emp : Q emp = Q⟨ [] , [] ⟩ enq : A → Q → Q enq a Q⟨ xs , ys ⟩ = Q⟨ a ∷ xs , ys ⟩ enq a (tilt xs ys z i) = tilt (a ∷ xs) ys z i enq a (trunc q q' α β i j) = trunc _ _ (cong (enq a) α) (cong (enq a) β) i j deqFlush : List A → Maybe (Q × A) deqFlush [] = nothing deqFlush (x ∷ xs) = just (Q⟨ [] , xs ⟩ , x) deq : Q → Maybe (Q × A) deq Q⟨ xs , [] ⟩ = deqFlush (rev xs) deq Q⟨ xs , y ∷ ys ⟩ = just (Q⟨ xs , ys ⟩ , y) deq (tilt xs [] z i) = path i where path : deqFlush (rev (xs ++ [ z ])) ≡ just (Q⟨ xs , [] ⟩ , z) path = cong deqFlush (rev-++ xs [ z ]) ∙ cong (λ q → just (q , z)) (sym (multitilt [] [] (rev xs))) ∙ cong (λ ys → just (Q⟨ ys , [] ⟩ , z)) (rev-rev xs) deq (tilt xs (y ∷ ys) z i) = just (tilt xs ys z i , y) deq (trunc q q' α β i j) = isOfHLevelMaybe 0 (isSetΣ trunc λ _ → Aset) (deq q) (deq q') (cong deq α) (cong deq β) i j Raw : RawQueue Raw = (Q , emp , enq , deq) -- We construct an equivalence to 1Lists and prove this is an equivalence of queue structures private module One = 1List A Aset open One renaming (Q to Q₁; emp to emp₁; enq to enq₁; deq to deq₁) using () quot : Q₁ → Q quot xs = Q⟨ xs , [] ⟩ eval : Q → Q₁ eval Q⟨ xs , ys ⟩ = xs ++ rev ys eval (tilt xs ys z i) = path i where path : (xs ++ [ z ]) ++ rev ys ≡ xs ++ rev (ys ++ [ z ]) path = ++-assoc xs [ z ] (rev ys) ∙ cong (_++_ xs) (sym (rev-++ ys [ z ])) eval (trunc q q' α β i j) = -- truncated case isOfHLevelList 0 Aset (eval q) (eval q') (cong eval α) (cong eval β) i j quot∘eval : ∀ q → quot (eval q) ≡ q quot∘eval Q⟨ xs , ys ⟩ = multitilt xs [] ys quot∘eval (tilt xs ys z i) = -- truncated case isOfHLevelPathP' {A = λ i → quot (eval (tilt xs ys z i)) ≡ tilt xs ys z i} 0 (trunc _ _) (multitilt (xs ++ [ z ]) [] ys) (multitilt xs [] (ys ++ [ z ])) .fst i quot∘eval (trunc q q' α β i j) = -- truncated case isOfHLevelPathP' {A = λ i → PathP (λ j → quot (eval (trunc q q' α β i j)) ≡ trunc q q' α β i j) (quot∘eval q) (quot∘eval q')} 0 (isOfHLevelPathP' 1 (isOfHLevelSuc 2 trunc _ _) _ _) (cong quot∘eval α) (cong quot∘eval β) .fst i j eval∘quot : ∀ xs → eval (quot xs) ≡ xs eval∘quot = ++-unit-r -- We get our desired equivalence quotEquiv : Q₁ ≃ Q quotEquiv = isoToEquiv (iso quot eval quot∘eval eval∘quot) -- Now it only remains to prove that this is an equivalence of queue structures quot∘emp : quot emp₁ ≡ emp quot∘emp = refl quot∘enq : ∀ x xs → quot (enq₁ x xs) ≡ enq x (quot xs) quot∘enq x xs = refl quot∘deq : ∀ xs → deqMap quot (deq₁ xs) ≡ deq (quot xs) quot∘deq [] = refl quot∘deq (x ∷ []) = refl quot∘deq (x ∷ x' ∷ xs) = deqMap-∘ quot (enq₁ x) (deq₁ (x' ∷ xs)) ∙ sym (deqMap-∘ (enq x) quot (deq₁ (x' ∷ xs))) ∙ cong (deqMap (enq x)) (quot∘deq (x' ∷ xs)) ∙ lemma x x' (rev xs) where lemma : ∀ x x' ys → deqMap (enq x) (deqFlush (ys ++ [ x' ])) ≡ deqFlush ((ys ++ [ x' ]) ++ [ x ]) lemma x x' [] i = just (tilt [] [] x i , x') lemma x x' (y ∷ ys) i = just (tilt [] (ys ++ [ x' ]) x i , y) quotEquivHasQueueEquivStr : RawQueueEquivStr One.Raw Raw quotEquiv quotEquivHasQueueEquivStr = quot∘emp , quot∘enq , quot∘deq -- And we get a path between the raw 1Lists and 2Lists Raw-1≡2 : One.Raw ≡ Raw Raw-1≡2 = sip rawQueueUnivalentStr _ _ (quotEquiv , quotEquivHasQueueEquivStr) -- We derive the axioms for 2List from those for 1List WithLaws : Queue WithLaws = Q , str Raw , subst (uncurry QueueAxioms) Raw-1≡2 (snd (str One.WithLaws)) WithLaws-1≡2 : One.WithLaws ≡ WithLaws WithLaws-1≡2 = sip queueUnivalentStr _ _ (quotEquiv , quotEquivHasQueueEquivStr) Finite : FiniteQueue Finite = Q , str WithLaws , subst (uncurry FiniteQueueAxioms) WithLaws-1≡2 (snd (str One.Finite))
32.046358
98
0.570986
c5b7614296ff663244d2b46b89f388c23280c59a
5,372
agda
Agda
prototyping/Luau/Type.agda
morgoth990/luau
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
[ "MIT" ]
1
2022-03-18T04:10:20.000Z
2022-03-18T04:10:20.000Z
prototyping/Luau/Type.agda
morgoth990/luau
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
[ "MIT" ]
null
null
null
prototyping/Luau/Type.agda
morgoth990/luau
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
[ "MIT" ]
null
null
null
module Luau.Type where open import FFI.Data.Maybe using (Maybe; just; nothing; just-inv) open import Agda.Builtin.Equality using (_≡_; refl) open import Properties.Dec using (Dec; yes; no) open import Properties.Equality using (cong) open import FFI.Data.Maybe using (Maybe; just; nothing) data Type : Set where nil : Type _⇒_ : Type → Type → Type none : Type any : Type boolean : Type number : Type string : Type _∪_ : Type → Type → Type _∩_ : Type → Type → Type lhs : Type → Type lhs (T ⇒ _) = T lhs (T ∪ _) = T lhs (T ∩ _) = T lhs nil = nil lhs none = none lhs any = any lhs number = number lhs boolean = boolean lhs string = string rhs : Type → Type rhs (_ ⇒ T) = T rhs (_ ∪ T) = T rhs (_ ∩ T) = T rhs nil = nil rhs none = none rhs any = any rhs number = number rhs boolean = boolean rhs string = string _≡ᵀ_ : ∀ (T U : Type) → Dec(T ≡ U) nil ≡ᵀ nil = yes refl nil ≡ᵀ (S ⇒ T) = no (λ ()) nil ≡ᵀ none = no (λ ()) nil ≡ᵀ any = no (λ ()) nil ≡ᵀ number = no (λ ()) nil ≡ᵀ boolean = no (λ ()) nil ≡ᵀ (S ∪ T) = no (λ ()) nil ≡ᵀ (S ∩ T) = no (λ ()) nil ≡ᵀ string = no (λ ()) (S ⇒ T) ≡ᵀ string = no (λ ()) none ≡ᵀ string = no (λ ()) any ≡ᵀ string = no (λ ()) boolean ≡ᵀ string = no (λ ()) number ≡ᵀ string = no (λ ()) (S ∪ T) ≡ᵀ string = no (λ ()) (S ∩ T) ≡ᵀ string = no (λ ()) (S ⇒ T) ≡ᵀ nil = no (λ ()) (S ⇒ T) ≡ᵀ (U ⇒ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ⇒ T) ≡ᵀ (S ⇒ T) | yes refl | yes refl = yes refl (S ⇒ T) ≡ᵀ (U ⇒ V) | _ | no p = no (λ q → p (cong rhs q)) (S ⇒ T) ≡ᵀ (U ⇒ V) | no p | _ = no (λ q → p (cong lhs q)) (S ⇒ T) ≡ᵀ none = no (λ ()) (S ⇒ T) ≡ᵀ any = no (λ ()) (S ⇒ T) ≡ᵀ number = no (λ ()) (S ⇒ T) ≡ᵀ boolean = no (λ ()) (S ⇒ T) ≡ᵀ (U ∪ V) = no (λ ()) (S ⇒ T) ≡ᵀ (U ∩ V) = no (λ ()) none ≡ᵀ nil = no (λ ()) none ≡ᵀ (U ⇒ V) = no (λ ()) none ≡ᵀ none = yes refl none ≡ᵀ any = no (λ ()) none ≡ᵀ number = no (λ ()) none ≡ᵀ boolean = no (λ ()) none ≡ᵀ (U ∪ V) = no (λ ()) none ≡ᵀ (U ∩ V) = no (λ ()) any ≡ᵀ nil = no (λ ()) any ≡ᵀ (U ⇒ V) = no (λ ()) any ≡ᵀ none = no (λ ()) any ≡ᵀ any = yes refl any ≡ᵀ number = no (λ ()) any ≡ᵀ boolean = no (λ ()) any ≡ᵀ (U ∪ V) = no (λ ()) any ≡ᵀ (U ∩ V) = no (λ ()) number ≡ᵀ nil = no (λ ()) number ≡ᵀ (T ⇒ U) = no (λ ()) number ≡ᵀ none = no (λ ()) number ≡ᵀ any = no (λ ()) number ≡ᵀ number = yes refl number ≡ᵀ boolean = no (λ ()) number ≡ᵀ (T ∪ U) = no (λ ()) number ≡ᵀ (T ∩ U) = no (λ ()) boolean ≡ᵀ nil = no (λ ()) boolean ≡ᵀ (T ⇒ U) = no (λ ()) boolean ≡ᵀ none = no (λ ()) boolean ≡ᵀ any = no (λ ()) boolean ≡ᵀ boolean = yes refl boolean ≡ᵀ number = no (λ ()) boolean ≡ᵀ (T ∪ U) = no (λ ()) boolean ≡ᵀ (T ∩ U) = no (λ ()) string ≡ᵀ nil = no (λ ()) string ≡ᵀ (x ⇒ x₁) = no (λ ()) string ≡ᵀ none = no (λ ()) string ≡ᵀ any = no (λ ()) string ≡ᵀ boolean = no (λ ()) string ≡ᵀ number = no (λ ()) string ≡ᵀ string = yes refl string ≡ᵀ (U ∪ V) = no (λ ()) string ≡ᵀ (U ∩ V) = no (λ ()) (S ∪ T) ≡ᵀ nil = no (λ ()) (S ∪ T) ≡ᵀ (U ⇒ V) = no (λ ()) (S ∪ T) ≡ᵀ none = no (λ ()) (S ∪ T) ≡ᵀ any = no (λ ()) (S ∪ T) ≡ᵀ number = no (λ ()) (S ∪ T) ≡ᵀ boolean = no (λ ()) (S ∪ T) ≡ᵀ (U ∪ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ∪ T) ≡ᵀ (S ∪ T) | yes refl | yes refl = yes refl (S ∪ T) ≡ᵀ (U ∪ V) | _ | no p = no (λ q → p (cong rhs q)) (S ∪ T) ≡ᵀ (U ∪ V) | no p | _ = no (λ q → p (cong lhs q)) (S ∪ T) ≡ᵀ (U ∩ V) = no (λ ()) (S ∩ T) ≡ᵀ nil = no (λ ()) (S ∩ T) ≡ᵀ (U ⇒ V) = no (λ ()) (S ∩ T) ≡ᵀ none = no (λ ()) (S ∩ T) ≡ᵀ any = no (λ ()) (S ∩ T) ≡ᵀ number = no (λ ()) (S ∩ T) ≡ᵀ boolean = no (λ ()) (S ∩ T) ≡ᵀ (U ∪ V) = no (λ ()) (S ∩ T) ≡ᵀ (U ∩ V) with (S ≡ᵀ U) | (T ≡ᵀ V) (S ∩ T) ≡ᵀ (U ∩ V) | yes refl | yes refl = yes refl (S ∩ T) ≡ᵀ (U ∩ V) | _ | no p = no (λ q → p (cong rhs q)) (S ∩ T) ≡ᵀ (U ∩ V) | no p | _ = no (λ q → p (cong lhs q)) _≡ᴹᵀ_ : ∀ (T U : Maybe Type) → Dec(T ≡ U) nothing ≡ᴹᵀ nothing = yes refl nothing ≡ᴹᵀ just U = no (λ ()) just T ≡ᴹᵀ nothing = no (λ ()) just T ≡ᴹᵀ just U with T ≡ᵀ U (just T ≡ᴹᵀ just T) | yes refl = yes refl (just T ≡ᴹᵀ just U) | no p = no (λ q → p (just-inv q)) data Mode : Set where strict : Mode nonstrict : Mode src : Mode → Type → Type src m nil = none src m number = none src m boolean = none src m string = none src m (S ⇒ T) = S -- In nonstrict mode, functions are covaraiant, in strict mode they're contravariant src strict (S ∪ T) = (src strict S) ∩ (src strict T) src nonstrict (S ∪ T) = (src nonstrict S) ∪ (src nonstrict T) src strict (S ∩ T) = (src strict S) ∪ (src strict T) src nonstrict (S ∩ T) = (src nonstrict S) ∩ (src nonstrict T) src strict none = any src nonstrict none = none src strict any = none src nonstrict any = any tgt : Type → Type tgt nil = none tgt (S ⇒ T) = T tgt none = none tgt any = any tgt number = none tgt boolean = none tgt string = none tgt (S ∪ T) = (tgt S) ∪ (tgt T) tgt (S ∩ T) = (tgt S) ∩ (tgt T) optional : Type → Type optional nil = nil optional (T ∪ nil) = (T ∪ nil) optional T = (T ∪ nil) normalizeOptional : Type → Type normalizeOptional (S ∪ T) with normalizeOptional S | normalizeOptional T normalizeOptional (S ∪ T) | (S′ ∪ nil) | (T′ ∪ nil) = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | S′ | (T′ ∪ nil) = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | (S′ ∪ nil) | T′ = (S′ ∪ T′) ∪ nil normalizeOptional (S ∪ T) | S′ | nil = optional S′ normalizeOptional (S ∪ T) | nil | T′ = optional T′ normalizeOptional (S ∪ T) | S′ | T′ = S′ ∪ T′ normalizeOptional T = T
28.727273
84
0.515078
50fa96831a26b26807355f2caa8c6a95644fc654
1,444
agda
Agda
Groups/Actions/Stabiliser.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Groups/Actions/Stabiliser.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Groups/Actions/Stabiliser.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import Setoids.Setoids open import Groups.Definition open import Groups.Subgroups.Definition open import Groups.Actions.Definition open import Sets.EquivalenceRelations open import Groups.Actions.Definition module Groups.Actions.Stabiliser {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {_+_ : A → A → A} {G : Group S _+_} (act : GroupAction G T) where open GroupAction act open Setoid T stabiliserPred : (x : B) → (g : A) → Set d stabiliserPred x g = (action g x) ∼ x stabiliserWellDefined : (x : B) → {g h : A} → Setoid._∼_ S g h → (stabiliserPred x g) → stabiliserPred x h stabiliserWellDefined x {g} {h} g=h gx=x = transitive (actionWellDefined1 (Equivalence.symmetric (Setoid.eq S) g=h)) gx=x where open Equivalence eq open Setoid T open Equivalence (Setoid.eq T) stabiliserSubgroup : (x : B) → Subgroup G (stabiliserPred x) Subgroup.isSubset (stabiliserSubgroup x) = stabiliserWellDefined x Subgroup.closedUnderPlus (stabiliserSubgroup x) gx=x hx=x = transitive associativeAction (transitive (actionWellDefined2 hx=x) gx=x) Subgroup.containsIdentity (stabiliserSubgroup x) = identityAction Subgroup.closedUnderInverse (stabiliserSubgroup x) {g} gx=x = transitive (transitive (transitive (actionWellDefined2 (symmetric gx=x)) (symmetric associativeAction)) (actionWellDefined1 (invLeft {g}))) identityAction where open Group G
43.757576
216
0.737535
a12daa5a7304f5dd19802870f6672f4b3f4332e0
385
agda
Agda
test/interaction/PragmasRespected.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/PragmasRespected.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/PragmasRespected.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --show-implicit #-} module PragmasRespected where postulate Foo : {A : Set₁} → Set Bar : Foo {A = Set} -- Andreas, 2014-10-20, AIM XX: -- This test used to check that the --show-implicit option -- is turned on even if the module is just reloaded from -- an interface file. -- However, as we now always recheck when reload, -- this test should now trivially succeed.
25.666667
58
0.696104
dc9f62b9b6332c460a849770f5ace82345194cf6
956
agda
Agda
src/EqBool.agda
mckeankylej/agda-ring-solver
f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500
[ "MIT" ]
36
2019-01-25T16:40:52.000Z
2022-02-15T00:57:55.000Z
src/EqBool.agda
oisdk/agda-algebra
7e4ee048dab68ccb0a8673a6a663a37c1d1f4080
[ "MIT" ]
5
2019-04-17T20:48:48.000Z
2022-03-12T01:55:42.000Z
src/EqBool.agda
oisdk/agda-algebra
7e4ee048dab68ccb0a8673a6a663a37c1d1f4080
[ "MIT" ]
4
2019-04-16T02:23:16.000Z
2022-01-20T07:07:11.000Z
{-# OPTIONS --without-K --safe #-} module EqBool where open import Data.Bool record HasEqBool {a} (A : Set a) : Set a where field _==_ : A → A → Bool open HasEqBool ⦃ ... ⦄ public open import Data.List as List using (List; _∷_; []) ==[] : ∀ {a} {A : Set a} → ⦃ _ : HasEqBool A ⦄ → List A → List A → Bool ==[] [] [] = true ==[] [] (x ∷ ys) = false ==[] (x ∷ xs) [] = false ==[] (x ∷ xs) (y ∷ ys) = x == y ∧ ==[] xs ys instance eqList : ∀ {a} {A : Set a} → ⦃ _ : HasEqBool A ⦄ → HasEqBool (List A) _==_ ⦃ eqList ⦄ = ==[] open import Data.Nat using (ℕ) instance eqNat : HasEqBool ℕ _==_ ⦃ eqNat ⦄ = Agda.Builtin.Nat._==_ where import Agda.Builtin.Nat instance eqBool : HasEqBool Bool _==_ ⦃ eqBool ⦄ false false = true _==_ ⦃ eqBool ⦄ false true = false _==_ ⦃ eqBool ⦄ true y = y open import Data.String using (String) instance eqString : HasEqBool String _==_ ⦃ eqString ⦄ = Data.String._==_ where import Data.String
23.317073
71
0.57636
39dc1583ee45c3c8dc6b98c05e095e2cb0fec708
5,317
agda
Agda
agda-stdlib-0.9/src/Data/Maybe.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/Maybe.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Maybe.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- The Maybe type ------------------------------------------------------------------------ module Data.Maybe where open import Level ------------------------------------------------------------------------ -- The type open import Data.Maybe.Core public ------------------------------------------------------------------------ -- Some operations open import Data.Bool using (Bool; true; false; not) open import Data.Unit using (⊤) open import Function open import Relation.Nullary boolToMaybe : Bool → Maybe ⊤ boolToMaybe true = just _ boolToMaybe false = nothing is-just : ∀ {a} {A : Set a} → Maybe A → Bool is-just (just _) = true is-just nothing = false is-nothing : ∀ {a} {A : Set a} → Maybe A → Bool is-nothing = not ∘ is-just decToMaybe : ∀ {a} {A : Set a} → Dec A → Maybe A decToMaybe (yes x) = just x decToMaybe (no _) = nothing -- A dependent eliminator. maybe : ∀ {a b} {A : Set a} {B : Maybe A → Set b} → ((x : A) → B (just x)) → B nothing → (x : Maybe A) → B x maybe j n (just x) = j x maybe j n nothing = n -- A non-dependent eliminator. maybe′ : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → B → Maybe A → B maybe′ = maybe -- A safe variant of "fromJust". If the value is nothing, then the -- return type is the unit type. From-just : ∀ {a} (A : Set a) → Maybe A → Set a From-just A (just _) = A From-just A nothing = Lift ⊤ from-just : ∀ {a} {A : Set a} (x : Maybe A) → From-just A x from-just (just x) = x from-just nothing = _ ------------------------------------------------------------------------ -- Maybe monad open import Category.Functor open import Category.Monad open import Category.Monad.Identity map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → Maybe A → Maybe B map f = maybe (just ∘ f) nothing functor : ∀ {f} → RawFunctor (Maybe {a = f}) functor = record { _<$>_ = map } monadT : ∀ {f} {M : Set f → Set f} → RawMonad M → RawMonad (λ A → M (Maybe A)) monadT M = record { return = M.return ∘ just ; _>>=_ = λ m f → M._>>=_ m (maybe f (M.return nothing)) } where module M = RawMonad M monad : ∀ {f} → RawMonad (Maybe {a = f}) monad = monadT IdentityMonad monadZero : ∀ {f} → RawMonadZero (Maybe {a = f}) monadZero = record { monad = monad ; ∅ = nothing } monadPlus : ∀ {f} → RawMonadPlus (Maybe {a = f}) monadPlus {f} = record { monadZero = monadZero ; _∣_ = _∣_ } where _∣_ : {A : Set f} → Maybe A → Maybe A → Maybe A nothing ∣ y = y just x ∣ y = just x ------------------------------------------------------------------------ -- Equality open import Relation.Binary as B data Eq {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) : Rel (Maybe A) (a ⊔ ℓ) where just : ∀ {x y} (x≈y : x ≈ y) → Eq _≈_ (just x) (just y) nothing : Eq _≈_ nothing nothing drop-just : ∀ {a ℓ} {A : Set a} {_≈_ : Rel A ℓ} {x y : A} → just x ⟨ Eq _≈_ ⟩ just y → x ≈ y drop-just (just x≈y) = x≈y setoid : ∀ {ℓ₁ ℓ₂} → Setoid ℓ₁ ℓ₂ → Setoid _ _ setoid S = record { Carrier = Maybe S.Carrier ; _≈_ = _≈_ ; isEquivalence = record { refl = refl ; sym = sym ; trans = trans } } where module S = Setoid S _≈_ = Eq S._≈_ refl : ∀ {x} → x ≈ x refl {just x} = just S.refl refl {nothing} = nothing sym : ∀ {x y} → x ≈ y → y ≈ x sym (just x≈y) = just (S.sym x≈y) sym nothing = nothing trans : ∀ {x y z} → x ≈ y → y ≈ z → x ≈ z trans (just x≈y) (just y≈z) = just (S.trans x≈y y≈z) trans nothing nothing = nothing decSetoid : ∀ {ℓ₁ ℓ₂} → DecSetoid ℓ₁ ℓ₂ → DecSetoid _ _ decSetoid D = record { isDecEquivalence = record { isEquivalence = Setoid.isEquivalence (setoid (DecSetoid.setoid D)) ; _≟_ = _≟_ } } where _≟_ : B.Decidable (Eq (DecSetoid._≈_ D)) just x ≟ just y with DecSetoid._≟_ D x y just x ≟ just y | yes x≈y = yes (just x≈y) just x ≟ just y | no x≉y = no (x≉y ∘ drop-just) just x ≟ nothing = no λ() nothing ≟ just y = no λ() nothing ≟ nothing = yes nothing ------------------------------------------------------------------------ -- Any and All open Data.Bool using (T) open import Data.Empty using (⊥) import Relation.Nullary.Decidable as Dec open import Relation.Unary as U data Any {a p} {A : Set a} (P : A → Set p) : Maybe A → Set (a ⊔ p) where just : ∀ {x} (px : P x) → Any P (just x) data All {a p} {A : Set a} (P : A → Set p) : Maybe A → Set (a ⊔ p) where just : ∀ {x} (px : P x) → All P (just x) nothing : All P nothing Is-just : ∀ {a} {A : Set a} → Maybe A → Set a Is-just = Any (λ _ → ⊤) Is-nothing : ∀ {a} {A : Set a} → Maybe A → Set a Is-nothing = All (λ _ → ⊥) to-witness : ∀ {p} {P : Set p} {m : Maybe P} → Is-just m → P to-witness (just {x = p} _) = p to-witness-T : ∀ {p} {P : Set p} (m : Maybe P) → T (is-just m) → P to-witness-T (just p) _ = p to-witness-T nothing () anyDec : ∀ {a p} {A : Set a} {P : A → Set p} → U.Decidable P → U.Decidable (Any P) anyDec p nothing = no λ() anyDec p (just x) = Dec.map′ just (λ { (Any.just px) → px }) (p x) allDec : ∀ {a p} {A : Set a} {P : A → Set p} → U.Decidable P → U.Decidable (All P) allDec p nothing = yes nothing allDec p (just x) = Dec.map′ just (λ { (All.just px) → px }) (p x)
27.127551
72
0.510626
dfeb2eeaea3f135cb012a9d8b685283306437906
272
agda
Agda
test/Fail/Issue1718.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1718.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1718.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-11-17, issue reported by Martin Stone Davis module _ where module Sub (let open import oops) where -- WAS: internal error -- EXPECTED: Not a valid let-declaration -- when scope checking the declaration -- module Sub (let open import oops) where
22.666667
60
0.727941
0ee04806b467405f87b2333693554cc7d4a61062
12,029
agda
Agda
Cubical/Data/Nat/Algebra.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/Nat/Algebra.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/Nat/Algebra.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --no-exact-split --safe #-} {- This file shows that the property of the natural numbers being a homotopy-initial algebra of the functor (1 + _) is equivalent to fulfilling a closely related inductive elimination principle. Proofing the latter is trivial, since the typechecker does the work for us. For details see the paper [Homotopy-initial algebras in type theory](https://arxiv.org/abs/1504.05531) by Steve Awodey, Nicola Gambino and Kristina Sojakova. -} module Cubical.Data.Nat.Algebra where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Path open import Cubical.Foundations.Isomorphism hiding (section) open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Reflection.StrictEquiv open import Cubical.Data.Nat.Base private variable ℓ ℓ' : Level record NatAlgebra ℓ : Type (ℓ-suc ℓ) where field Carrier : Type ℓ alg-zero : Carrier alg-suc : Carrier → Carrier record NatMorphism (A : NatAlgebra ℓ) (B : NatAlgebra ℓ') : Type (ℓ-max ℓ ℓ') where open NatAlgebra field morph : A .Carrier → B .Carrier comm-zero : morph (A .alg-zero) ≡ B .alg-zero comm-suc : morph ∘ A .alg-suc ≡ B .alg-suc ∘ morph record NatFiber (N : NatAlgebra ℓ') ℓ : Type (ℓ-max ℓ' (ℓ-suc ℓ)) where open NatAlgebra N field Fiber : Carrier → Type ℓ fib-zero : Fiber alg-zero fib-suc : ∀ {n} → Fiber n → Fiber (alg-suc n) record NatSection {N : NatAlgebra ℓ'} (F : NatFiber N ℓ) : Type (ℓ-max ℓ' ℓ) where open NatAlgebra N open NatFiber F field section : ∀ n → Fiber n sec-comm-zero : section alg-zero ≡ fib-zero sec-comm-suc : ∀ n → section (alg-suc n) ≡ fib-suc (section n) isNatHInitial : NatAlgebra ℓ' → (ℓ : Level) → Type (ℓ-max ℓ' (ℓ-suc ℓ)) isNatHInitial N ℓ = (M : NatAlgebra ℓ) → isContr (NatMorphism N M) isNatInductive : NatAlgebra ℓ' → (ℓ : Level) → Type (ℓ-max ℓ' (ℓ-suc ℓ)) isNatInductive N ℓ = (S : NatFiber N ℓ) → NatSection S module AlgebraPropositionality {N : NatAlgebra ℓ'} where open NatAlgebra N isPropIsNatHInitial : isProp (isNatHInitial N ℓ) isPropIsNatHInitial = isPropΠ (λ _ → isPropIsContr) -- under the assumption that some shape is nat-inductive, the type of sections over any fiber -- is propositional module SectionProp (ind : isNatInductive N ℓ) {F : NatFiber N ℓ} (S T : NatSection F) where open NatFiber open NatSection ConnectingFiber : NatFiber N ℓ Fiber ConnectingFiber n = S .section n ≡ T .section n fib-zero ConnectingFiber = S .sec-comm-zero ∙∙ refl ∙∙ sym (T .sec-comm-zero) fib-suc ConnectingFiber {n} sntn = S .sec-comm-suc n ∙∙ (λ i → F .fib-suc (sntn i)) ∙∙ sym (T .sec-comm-suc n) open NatSection (ind ConnectingFiber) renaming (section to α ; sec-comm-zero to ζ ; sec-comm-suc to σ) squeezeSquare : ∀{a}{A : Type a}{w x y z : A} (p : w ≡ x) {q : x ≡ y} (r : z ≡ y) → (P : w ≡ z) → (sq : P ≡ p ∙∙ q ∙∙ sym r) → I → I → A squeezeSquare p {q} r P sq i j = transport (sym (PathP≡doubleCompPathʳ p P q r)) sq i j S≡T : S ≡ T section (S≡T i) n = α n i sec-comm-zero (S≡T i) j = squeezeSquare (S .sec-comm-zero) (T .sec-comm-zero) (α alg-zero) ζ j i sec-comm-suc (S≡T i) n j = squeezeSquare (S .sec-comm-suc n) (T .sec-comm-suc n) (α (alg-suc n)) (σ n) j i isPropIsNatInductive : isProp (isNatInductive N ℓ) isPropIsNatInductive a b i F = SectionProp.S≡T a (a F) (b F) i module AlgebraHInd→HInit {N : NatAlgebra ℓ'} (ind : isNatInductive N ℓ) (M : NatAlgebra ℓ) where open NatAlgebra open NatFiber ConstFiberM : NatFiber N ℓ Fiber ConstFiberM _ = M .Carrier fib-zero ConstFiberM = M .alg-zero fib-suc ConstFiberM = M .alg-suc morph→section : NatMorphism N M → NatSection ConstFiberM morph→section x = record { section = morph ; sec-comm-zero = comm-zero ; sec-comm-suc = λ i n → comm-suc n i } where open NatMorphism x section→morph : NatSection ConstFiberM → NatMorphism N M section→morph x = record { morph = section ; comm-zero = sec-comm-zero ; comm-suc = λ n i → sec-comm-suc i n } where open NatSection x Morph≡Section : NatSection ConstFiberM ≡ NatMorphism N M Morph≡Section = ua e where unquoteDecl e = declStrictEquiv e section→morph morph→section isContrMorph : isContr (NatMorphism N M) isContrMorph = subst isContr Morph≡Section (inhProp→isContr (ind ConstFiberM) (AlgebraPropositionality.SectionProp.S≡T ind)) open NatAlgebra open NatFiber open NatSection open NatMorphism module AlgebraHInit→Ind (N : NatAlgebra ℓ') ℓ (hinit : isNatHInitial N (ℓ-max ℓ' ℓ)) (F : NatFiber N (ℓ-max ℓ' ℓ)) where ΣAlgebra : NatAlgebra (ℓ-max ℓ' ℓ) Carrier ΣAlgebra = Σ (N .Carrier) (F .Fiber) alg-zero ΣAlgebra = N .alg-zero , F .fib-zero alg-suc ΣAlgebra (n , fn) = N .alg-suc n , F .fib-suc fn -- the fact that we have to lift the Carrier obstructs readability a bit -- this is the same algebra as N, but lifted into the correct universe LiftN : NatAlgebra (ℓ-max ℓ' ℓ) Carrier LiftN = Lift {_} {ℓ} (N .Carrier) alg-zero LiftN = lift (N .alg-zero) alg-suc LiftN = lift ∘ N .alg-suc ∘ lower _!_ : ∀ {x y} → x ≡ y → F .Fiber x → F .Fiber y _!_ = subst (F .Fiber) -- from homotopy initiality of N we get -- 1) an algebra morphism μ from N → Σ N F together with proofs of commutativity with the algebras -- 2) projecting out the first component after μ, called α, will turn out to be the identity function -- 3) witnesses that μ respects the definitions given in ΣAlgebra -- a) at zero the witnesses are ζ and ζ-h -- b) at suc the witnesses are σ and σ-h open NatMorphism (hinit ΣAlgebra .fst) renaming (morph to μ ; comm-zero to μ-zc ; comm-suc to μ-sc) module _ n where open Σ (μ n) public renaming (fst to α ; snd to α-h) -- module _ i where open Σ (μ-zc i) public renaming (fst to ζ ; snd to ζ-h) ζ : α (N .alg-zero) ≡ N .alg-zero ζ i = μ-zc i .fst ζ-h : PathP (λ i → F .Fiber (ζ i)) (α-h (N .alg-zero)) (F .fib-zero) ζ-h i = μ-zc i .snd -- module _ n i where open Σ (μ-sc i n) public renaming (fst to σ ; snd to σ-h) σ : ∀ n → α (N .alg-suc n) ≡ N .alg-suc (α n) σ n i = μ-sc i n .fst σ-h : ∀ n → PathP (λ i → F .Fiber (σ n i)) (α-h (N .alg-suc n)) (F .fib-suc (α-h n)) σ-h n i = μ-sc i n .snd -- liftMorph would be the identity morphism if it weren't for size issues liftMorph : NatMorphism N LiftN liftMorph = record { morph = lift ; comm-zero = refl ; comm-suc = refl } -- instead of abstractly defining morphism composition and a projection algebra morphism -- from Σ N F → N, define the composite directly. comm-zero and comm-suc thus are -- defined without path composition fst∘μ : NatMorphism N LiftN morph fst∘μ = lift ∘ α comm-zero fst∘μ i = lift (ζ i) comm-suc fst∘μ i n = lift (σ n i) fst∘μ≡id : fst∘μ ≡ liftMorph fst∘μ≡id = isContr→isProp (hinit LiftN) _ _ -- we get a proof that the index is preserved uniformly P : ∀ n → α n ≡ n P n i = lower (fst∘μ≡id i .morph n) -- we also have proofs that α cancels after the algebra of N Q-zero : α (N .alg-zero) ≡ N .alg-zero Q-zero = ζ Q-suc : ∀ n → α (N .alg-suc n) ≡ N .alg-suc n Q-suc n = σ n ∙ cong (N .alg-suc) (P n) -- but P and Q are the same up to homotopy P-zero : P (N .alg-zero) ≡ Q-zero P-zero i j = hcomp (λ k → λ where (i = i0) → lower (fst∘μ≡id j .comm-zero (~ k)) (i = i1) → ζ (j ∨ ~ k) (j = i0) → ζ (~ k) (j = i1) → N .alg-zero ) (N .alg-zero) P-suc : ∀ n → P (N .alg-suc n) ≡ Q-suc n P-suc n i j = hcomp (λ k → λ where (i = i0) → lower (fst∘μ≡id j .comm-suc (~ k) n) (i = i1) → compPath-filler' (σ n) (cong (N .alg-suc) (P n)) k j (j = i0) → σ n (~ k) (j = i1) → N .alg-suc n ) (N .alg-suc (P n j)) Fsection : NatSection F section Fsection n = P n ! α-h n sec-comm-zero Fsection = P (N .alg-zero) ! α-h (N .alg-zero) ≡[ i ]⟨ P-zero i ! α-h _ ⟩ Q-zero ! α-h (N .alg-zero) ≡⟨ fromPathP ζ-h ⟩ F .fib-zero ∎ sec-comm-suc Fsection n = P (N .alg-suc n) ! α-h (N .alg-suc n) ≡[ i ]⟨ P-suc n i ! α-h _ ⟩ Q-suc n ! α-h (N .alg-suc n) ≡⟨ substComposite (F .Fiber) (σ n) (cong (N .alg-suc) (P n)) _ ⟩ cong (N .alg-suc) (P n) ! (σ n ! α-h (N .alg-suc n)) ≡[ i ]⟨ cong (N .alg-suc) (P n) ! fromPathP (σ-h n) i ⟩ cong (N .alg-suc) (P n) ! (F .fib-suc (α-h n)) ≡⟨ substCommSlice (F .Fiber) (F .Fiber ∘ N .alg-suc) (λ _ → F .fib-suc) (P n) (α-h n) ⟩ F .fib-suc (P n ! α-h n) ∎ isNatInductive≡isNatHInitial : {N : NatAlgebra ℓ'} (ℓ : Level) → isNatInductive N (ℓ-max ℓ' ℓ) ≡ isNatHInitial N (ℓ-max ℓ' ℓ) isNatInductive≡isNatHInitial {_} {N} ℓ = hPropExt isPropIsNatInductive isPropIsNatHInitial ind→init init→ind where open AlgebraPropositionality open AlgebraHInit→Ind N ℓ renaming (Fsection to init→ind) open AlgebraHInd→HInit renaming (isContrMorph to ind→init) -- given two homotopy initial algebras there is a path between the algebras -- this implies moreover that the carrier types are isomorphic -- according to 5.16 in the paper this could be strengthened to isContr (N ≡ M) isNatHInitial→algebraPath : {N M : NatAlgebra ℓ} → (hinitN : isNatHInitial N ℓ) (hinitM : isNatHInitial M ℓ) → N ≡ M isNatHInitial→algebraPath {N = N} {M} hinitN hinitM = N≡M where open Σ (hinitN M) renaming (fst to N→M) open Σ (hinitM N) renaming (fst to M→N) idN : NatMorphism N N idN = record { morph = λ x → x ; comm-zero = refl ; comm-suc = refl } idM : NatMorphism M M idM = record { morph = λ x → x ; comm-zero = refl ; comm-suc = refl } N→M→N : NatMorphism N N morph N→M→N = morph M→N ∘ morph N→M comm-zero N→M→N = (λ i → morph M→N (comm-zero N→M i)) ∙ comm-zero M→N comm-suc N→M→N = (λ i → morph M→N ∘ comm-suc N→M i) ∙ (λ i → comm-suc M→N i ∘ morph N→M) nmn≡idn : N→M→N ≡ idN nmn≡idn = isContr→isProp (hinitN N) _ _ M→N→M : NatMorphism M M morph M→N→M = morph N→M ∘ morph M→N comm-zero M→N→M = (λ i → morph N→M (comm-zero M→N i)) ∙ comm-zero N→M comm-suc M→N→M = (λ i → morph N→M ∘ comm-suc M→N i) ∙ (λ i → comm-suc N→M i ∘ morph M→N) mnm≡idm : M→N→M ≡ idM mnm≡idm = isContr→isProp (hinitM M) _ _ carrier≡ : N .Carrier ≡ M .Carrier carrier≡ = isoToPath (iso (N→M .morph) (M→N .morph) (λ x i → mnm≡idm i .morph x) (λ x i → nmn≡idn i .morph x)) zero≡ : PathP (λ i → carrier≡ i) (N .alg-zero) (M .alg-zero) zero≡ = toPathP λ i → transportRefl (N→M .comm-zero i) i suc≡ : PathP (λ i → carrier≡ i → carrier≡ i) (N .alg-suc) (M .alg-suc) suc≡ = toPathP ( transport refl ∘ N→M .morph ∘ N .alg-suc ∘ M→N .morph ∘ transport refl ≡[ i ]⟨ transportReflF i ∘ N→M .morph ∘ N .alg-suc ∘ M→N .morph ∘ transportReflF i ⟩ N→M .morph ∘ N .alg-suc ∘ M→N .morph ≡[ i ]⟨ N→M .comm-suc i ∘ M→N .morph ⟩ M .alg-suc ∘ N→M .morph ∘ M→N .morph ≡[ i ]⟨ M .alg-suc ∘ mnm≡idm i .morph ⟩ M .alg-suc ∎) where transportReflF : transport refl ≡ (λ x → x) transportReflF = funExt transportRefl N≡M : N ≡ M Carrier (N≡M i) = carrier≡ i alg-zero (N≡M i) = zero≡ i alg-suc (N≡M i) = suc≡ i -- the payoff, it is straight forward to define the algebra and show inductiveness of ℕ NatAlgebraℕ : NatAlgebra ℓ-zero Carrier NatAlgebraℕ = ℕ alg-zero NatAlgebraℕ = zero alg-suc NatAlgebraℕ = suc isNatInductiveℕ : isNatInductive NatAlgebraℕ ℓ section (isNatInductiveℕ F) = nat-sec where nat-sec : ∀ n → F .Fiber n nat-sec zero = F .fib-zero nat-sec (suc n) = F .fib-suc (nat-sec n) sec-comm-zero (isNatInductiveℕ F) = refl sec-comm-suc (isNatInductiveℕ F) n = refl isNatHInitialℕ : isNatHInitial NatAlgebraℕ ℓ isNatHInitialℕ = transport (isNatInductive≡isNatHInitial _) isNatInductiveℕ
40.096667
126
0.632887
cbf9f17568abf9ad62bf139eb32a156a00e43c79
3,457
agda
Agda
Globular-TT/Syntax.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
Globular-TT/Syntax.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
Globular-TT/Syntax.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
{-# OPTIONS --rewriting --without-K #-} open import Agda.Primitive open import Prelude import GSeTT.Syntax {- Syntax for a globular type theory, with arbitrary term constructors -} module Globular-TT.Syntax {l} (index : Set l) where data Pre-Ty : Set (lsuc l) data Pre-Tm : Set (lsuc l) data Pre-Sub : Set (lsuc l) data Pre-Ctx : Set (lsuc l) data Pre-Ty where ∗ : Pre-Ty ⇒ : Pre-Ty → Pre-Tm → Pre-Tm → Pre-Ty data Pre-Tm where Var : ℕ → Pre-Tm Tm-constructor : ∀ (i : index) → Pre-Sub → Pre-Tm data Pre-Sub where <> : Pre-Sub <_,_↦_> : Pre-Sub → ℕ → Pre-Tm → Pre-Sub data Pre-Ctx where ⊘ : Pre-Ctx _∙_#_ : Pre-Ctx → ℕ → Pre-Ty → Pre-Ctx C-length : Pre-Ctx → ℕ C-length ⊘ = O C-length (Γ ∙ _ # _) = S (C-length Γ) -- Equality elimination ⇒= : ∀ {A B t t' u u'} → A == B → t == t' → u == u' → ⇒ A t u == ⇒ B t' u' ⇒= idp idp idp = idp =⇒ : ∀ {A B t t' u u'} → ⇒ A t u == ⇒ B t' u' → ((A == B) × (t == t')) × (u == u') =⇒ idp = (idp , idp) , idp Var= : ∀ {v w} → v == w → Var v == Var w Var= idp = idp Tm-constructor= : ∀ {i j γ δ} → i == j → γ == δ → (Tm-constructor i γ) == (Tm-constructor j δ) Tm-constructor= idp idp = idp =Tm-constructor : ∀ {i j γ δ} → (Tm-constructor i γ) == (Tm-constructor j δ) → i == j × γ == δ =Tm-constructor idp = idp , idp <,>= : ∀ {γ δ x y t u} → γ == δ → x == y → t == u → < γ , x ↦ t > == < δ , y ↦ u > <,>= idp idp idp = idp =<,> : ∀ {γ δ x y t u} → < γ , x ↦ t > == < δ , y ↦ u > → ((γ == δ) × (x == y)) × (t == u) =<,> idp = (idp , idp) , idp ∙= : ∀ {Γ Δ x y A B} → Γ == Δ → x == y → A == B → (Γ ∙ x # A) == (Δ ∙ y # B) ∙= idp idp idp = idp {- Action of substitutions on types and terms and substitutions on a syntactical level -} _[_]Pre-Ty : Pre-Ty → Pre-Sub → Pre-Ty _[_]Pre-Tm : Pre-Tm → Pre-Sub → Pre-Tm _∘_ : Pre-Sub → Pre-Sub → Pre-Sub ∗ [ σ ]Pre-Ty = ∗ ⇒ A t u [ σ ]Pre-Ty = ⇒ (A [ σ ]Pre-Ty) (t [ σ ]Pre-Tm) (u [ σ ]Pre-Tm) Var x [ <> ]Pre-Tm = Var x Var x [ < σ , v ↦ t > ]Pre-Tm = if x ≡ v then t else ((Var x) [ σ ]Pre-Tm) Tm-constructor i γ [ σ ]Pre-Tm = Tm-constructor i (γ ∘ σ) <> ∘ γ = <> < γ , x ↦ t > ∘ δ = < γ ∘ δ , x ↦ t [ δ ]Pre-Tm > _#_∈_ : ℕ → Pre-Ty → Pre-Ctx → Set (lsuc l) _ # _ ∈ ⊘ = ⊥ x # A ∈ (Γ ∙ y # B) = (x # A ∈ Γ) + ((x == y) × (A == B)) {- dimension of types -} dim : Pre-Ty → ℕ dim ∗ = O dim (⇒ A t u) = S (dim A) dim[] : ∀ (A : Pre-Ty) (γ : Pre-Sub) → dim (A [ γ ]Pre-Ty) == dim A dim[] ∗ γ = idp dim[] (⇒ A x x₁) γ = S= (dim[] A γ) dimC : Pre-Ctx → ℕ dimC ⊘ = O dimC (Γ ∙ x # A) = max (dimC Γ) (dim A) {- Identity and canonical projection -} Pre-id : ∀ (Γ : Pre-Ctx) → Pre-Sub Pre-id ⊘ = <> Pre-id (Γ ∙ x # A) = < Pre-id Γ , x ↦ Var x > Pre-π : ∀ (Γ : Pre-Ctx) (x : ℕ) (A : Pre-Ty) → Pre-Sub Pre-π Γ x A = Pre-id Γ {- Translation of GSeTT to a globular-TT -} GPre-Ctx : GSeTT.Syntax.Pre-Ctx → Pre-Ctx GPre-Ty : GSeTT.Syntax.Pre-Ty → Pre-Ty GPre-Tm : GSeTT.Syntax.Pre-Tm → Pre-Tm GPre-Ctx nil = ⊘ GPre-Ctx (Γ :: (x , A)) = (GPre-Ctx Γ) ∙ x # (GPre-Ty A) GPre-Ty GSeTT.Syntax.∗ = ∗ GPre-Ty (GSeTT.Syntax.⇒ A t u) = ⇒ (GPre-Ty A) (GPre-Tm t) (GPre-Tm u) GPre-Tm (GSeTT.Syntax.Var x) = Var x {- Depth of a term -} depth : Pre-Tm → ℕ depthS : Pre-Sub → ℕ depth (Var x) = O depth (Tm-constructor i γ) = S (depthS γ) depthS <> = O depthS < γ , x ↦ t > = max (depthS γ) (depth t)
28.336066
96
0.487995
c536995136e55b62b3428a0a2fc68d7aa81849fc
19,124
agda
Agda
Cubical/Homotopy/Connected.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Homotopy/Connected.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Homotopy/Connected.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Homotopy.Connected where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.Properties open import Cubical.Foundations.Pointed open import Cubical.Foundations.Transport open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.HLevels open import Cubical.Foundations.Path open import Cubical.Foundations.Univalence open import Cubical.Functions.Fibration open import Cubical.Data.Unit open import Cubical.Data.Bool open import Cubical.Data.Nat open import Cubical.Data.Sigma open import Cubical.HITs.Nullification open import Cubical.HITs.Susp open import Cubical.HITs.SmashProduct open import Cubical.HITs.Pushout open import Cubical.HITs.Sn.Base open import Cubical.HITs.S1 open import Cubical.HITs.Truncation as Trunc renaming (rec to trRec) open import Cubical.Homotopy.Loopspace -- Note that relative to most sources, this notation is off by +2 isConnected : ∀ {ℓ} (n : HLevel) (A : Type ℓ) → Type ℓ isConnected n A = isContr (hLevelTrunc n A) isConnectedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ') isConnectedFun n f = ∀ b → isConnected n (fiber f b) isTruncatedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ') isTruncatedFun n f = ∀ b → isOfHLevel n (fiber f b) isConnectedSubtr : ∀ {ℓ} {A : Type ℓ} (n m : HLevel) → isConnected (m + n) A → isConnected n A isConnectedSubtr {A = A} n m iscon = isOfHLevelRetractFromIso 0 (truncOfTruncIso n m) (helper n iscon) where helper : (n : ℕ) → isConnected (m + n) A → isContr (hLevelTrunc n (hLevelTrunc (m + n) A)) helper zero iscon = isContrUnit* helper (suc n) iscon = ∣ iscon .fst ∣ , (Trunc.elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → cong ∣_∣ (iscon .snd a)) isConnectedFunSubtr : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n m : HLevel) (f : A → B) → isConnectedFun (m + n) f → isConnectedFun n f isConnectedFunSubtr n m f iscon b = isConnectedSubtr n m (iscon b) private typeToFiberIso : ∀ {ℓ} (A : Type ℓ) → Iso A (fiber (λ (x : A) → tt) tt) Iso.fun (typeToFiberIso A) x = x , refl Iso.inv (typeToFiberIso A) = fst Iso.rightInv (typeToFiberIso A) b i = fst b , (isOfHLevelSuc 1 (isPropUnit) tt tt (snd b) refl) i Iso.leftInv (typeToFiberIso A) a = refl typeToFiber : ∀ {ℓ} (A : Type ℓ) → A ≡ fiber (λ (x : A) → tt) tt typeToFiber A = isoToPath (typeToFiberIso A) isOfHLevelIsConnectedStable : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → isOfHLevel n (isConnected n A) isOfHLevelIsConnectedStable {A = A} zero = (tt* , (λ _ → refl)) , λ _ → refl isOfHLevelIsConnectedStable {A = A} (suc n) = isProp→isOfHLevelSuc n isPropIsContr module elim {ℓ ℓ' : Level} {A : Type ℓ} {B : Type ℓ'} (f : A → B) where private inv : ∀ {ℓ'''} (n : HLevel) (P : B → TypeOfHLevel ℓ''' (suc n)) → ((a : A) → P (f a) .fst) → (b : B) → hLevelTrunc (suc n) (fiber f b) → P b .fst inv n P t b = Trunc.rec (P b .snd) (λ {(a , p) → subst (fst ∘ P) p (t a)}) isIsoPrecompose : ∀ {ℓ'''} (n : ℕ) (P : B → TypeOfHLevel ℓ''' n) → isConnectedFun n f → Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst) Iso.fun (isIsoPrecompose _ P fConn) = _∘ f Iso.inv (isIsoPrecompose zero P fConn) = Iso.inv (isContr→Iso' (isOfHLevelΠ _ (λ b → P b .snd)) (isOfHLevelΠ _ λ a → P (f a) .snd) (_∘ f)) Iso.rightInv (isIsoPrecompose zero P fConn) = Iso.rightInv (isContr→Iso' (isOfHLevelΠ _ (λ b → P b .snd)) (isOfHLevelΠ _ λ a → P (f a) .snd) (_∘ f)) Iso.leftInv (isIsoPrecompose zero P fConn) = Iso.leftInv (isContr→Iso' (isOfHLevelΠ _ (λ b → P b .snd)) (isOfHLevelΠ _ λ a → P (f a) .snd) (_∘ f)) Iso.inv (isIsoPrecompose (suc n) P fConn) t b = inv n P t b (fConn b .fst) Iso.rightInv (isIsoPrecompose (suc n) P fConn) t = funExt λ a → cong (inv n P t (f a)) (fConn (f a) .snd ∣ a , refl ∣) ∙ substRefl {B = fst ∘ P} (t a) Iso.leftInv (isIsoPrecompose (suc n) P fConn) s = funExt λ b → Trunc.elim {B = λ d → inv n P (s ∘ f) b d ≡ s b} (λ _ → isOfHLevelPath (suc n) (P b .snd) _ _) (λ {(a , p) i → transp (λ j → P (p (j ∨ i)) .fst) i (s (p i))}) (fConn b .fst) isEquivPrecompose : ∀ {ℓ'''} (n : ℕ) (P : B → TypeOfHLevel ℓ''' n) → isConnectedFun n f → isEquiv (λ(s : (b : B) → P b .fst) → s ∘ f) isEquivPrecompose zero P fConn = isoToIsEquiv theIso where theIso : Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst) Iso.fun theIso = λ(s : (b : B) → P b .fst) → s ∘ f Iso.inv theIso = λ _ b → P b .snd .fst Iso.rightInv theIso g = funExt λ x → P (f x) .snd .snd (g x) Iso.leftInv theIso g = funExt λ x → P x .snd .snd (g x) isEquivPrecompose (suc n) P fConn = isoToIsEquiv (isIsoPrecompose (suc n) P fConn) isConnectedPrecompose : (n : ℕ) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') n) → hasSection (λ(s : (b : B) → P b .fst) → s ∘ f)) → isConnectedFun n f isConnectedPrecompose zero P→sect b = isContrUnit* isConnectedPrecompose (suc n) P→sect b = c n P→sect b , λ y → sym (fun n P→sect b y) where P : (n : HLevel) → ((P : B → TypeOfHLevel ℓ (suc n)) → hasSection (λ(s : (b : B) → P b .fst) → s ∘ f)) → B → Type _ P n s b = hLevelTrunc (suc n) (fiber f b) c : (n : HLevel) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') (suc n)) → hasSection (λ(s : (b : B) → P b .fst) → s ∘ f)) → (b : B) → hLevelTrunc (suc n) (fiber f b) c n s = (s λ b → (hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _)) .fst λ a → ∣ a , refl ∣ fun : (n : HLevel) (P→sect : ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') (suc n)) → hasSection λ(s : (b : B) → P b .fst) → s ∘ f)) → (b : B) (w : (hLevelTrunc (suc n) (fiber f b))) → w ≡ c n P→sect b fun n P→sect b = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _) λ a → J (λ b p → ∣ (fst a) , p ∣ ≡ c n P→sect b) (c* (fst a)) (snd a) where c* : ((a : A) → ∣ (a , refl {x = f a}) ∣ ≡ c n P→sect (f a)) c* a = sym (cong (λ x → x a) (P→sect (λ b → hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _) .snd λ a → ∣ a , refl ∣)) isOfHLevelPrecomposeConnected : ∀ {ℓ ℓ' ℓ''} (k : HLevel) (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (P : B → TypeOfHLevel ℓ'' (k + n)) (f : A → B) → isConnectedFun n f → isOfHLevelFun k (λ(s : (b : B) → P b .fst) → s ∘ f) isOfHLevelPrecomposeConnected zero n P f fConn = elim.isEquivPrecompose f n P fConn .equiv-proof isOfHLevelPrecomposeConnected (suc k) n P f fConn t = isOfHLevelPath'⁻ k λ {(s₀ , p₀) (s₁ , p₁) → isOfHLevelRetractFromIso k (invIso ΣPathIsoPathΣ) (subst (isOfHLevel k) (sym (fiberPath (s₀ , p₀) (s₁ , p₁))) (isOfHLevelRetract k (λ {(q , α) → (funExt⁻ q) , (cong funExt⁻ α)}) (λ {(h , β) → (funExt h) , (cong funExt β)}) (λ _ → refl) (isOfHLevelPrecomposeConnected k n (λ b → (s₀ b ≡ s₁ b) , isOfHLevelPath' (k + n) (P b .snd) _ _) f fConn (funExt⁻ (p₀ ∙∙ refl ∙∙ sym p₁)))))} indMapEquiv→conType : ∀ {ℓ} {A : Type ℓ} (n : HLevel) → ((B : TypeOfHLevel ℓ n) → isEquiv (λ (b : (fst B)) → λ (a : A) → b)) → isConnected n A indMapEquiv→conType {A = A} zero BEq = isContrUnit* indMapEquiv→conType {A = A} (suc n) BEq = isOfHLevelRetractFromIso 0 (mapCompIso {n = (suc n)} (typeToFiberIso A)) (elim.isConnectedPrecompose (λ _ → tt) (suc n) (λ P → ((λ a _ → a) ∘ invIsEq (BEq (P tt))) , λ a → equiv-proof (BEq (P tt)) a .fst .snd) tt) isConnectedComp : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} (f : B → C) (g : A → B) (n : ℕ) → isConnectedFun n f → isConnectedFun n g → isConnectedFun n (f ∘ g) isConnectedComp {C = C} f g n con-f con-g = elim.isConnectedPrecompose (f ∘ g) n λ P → isEquiv→hasSection (compEquiv (_ , elim.isEquivPrecompose f n P con-f) (_ , elim.isEquivPrecompose g n (λ b → P (f b)) con-g) .snd) isEquiv→isConnected : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) → isEquiv f → (n : ℕ) → isConnectedFun n f isEquiv→isConnected f iseq n b = isContr→isContr∥ n (equiv-proof iseq b) isConnectedPath : ∀ {ℓ} (n : HLevel) {A : Type ℓ} → isConnected (suc n) A → (a₀ a₁ : A) → isConnected n (a₀ ≡ a₁) isConnectedPath zero connA a₀ a₁ = isContrUnit* isConnectedPath (suc n) {A = A} connA a₀ a₁ = isOfHLevelRetractFromIso 0 (invIso (PathIdTruncIso (suc n))) (isContr→isContrPath connA _ _) isConnectedPathP : ∀ {ℓ} (n : HLevel) {A : I → Type ℓ} → isConnected (suc n) (A i1) → (a₀ : A i0) (a₁ : A i1) → isConnected n (PathP A a₀ a₁) isConnectedPathP n con a₀ a₁ = subst (isConnected n) (sym (PathP≡Path _ _ _)) (isConnectedPath n con _ _) isConnectedCong : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → isConnectedFun (suc n) f → ∀ {a₀ a₁} → isConnectedFun n {A = a₀ ≡ a₁} (cong f) isConnectedCong n f cf {a₀} {a₁} q = subst (isConnected n) (sym (fiberCong f q)) (isConnectedPath n (cf (f a₁)) (a₀ , q) (a₁ , refl)) isConnectedCong' : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} {x : A} {y : B} (n : ℕ) (f : A → B) → isConnectedFun (suc n) f → (p : f x ≡ y) → isConnectedFun n λ (q : x ≡ x) → sym p ∙∙ cong f q ∙∙ p isConnectedCong' {x = x} n f conf p = transport (λ i → (isConnectedFun n λ (q : x ≡ x) → doubleCompPath-filler (sym p) (cong f q) p i)) (isConnectedCong n f conf) isConnectedΩ→ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) → (f : A →∙ B) → isConnectedFun (suc n) (fst f) → isConnectedFun n (fst (Ω→ f)) isConnectedΩ→ n f g = transport (λ i → isConnectedFun n λ b → doubleCompPath-filler (sym (snd f)) (cong (fst f) b) (snd f) i) (isConnectedCong n _ g) isConnectedΩ^→ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n m : ℕ) → (f : A →∙ B) → isConnectedFun (suc n) (fst f) → isConnectedFun ((suc n) ∸ m) (fst (Ω^→ m f)) isConnectedΩ^→ n zero f conf = conf isConnectedΩ^→ n (suc zero) f conf = isConnectedΩ→ n f conf isConnectedΩ^→ {A = A} {B = B} n (suc (suc m)) f conf = transport (λ i → isConnectedFun (suc n ∸ suc (suc m)) λ q → doubleCompPath-filler (sym (snd (Ω^→ (suc m) f))) (cong (fst (Ω^→ (suc m) f)) q) (snd (Ω^→ (suc m) f)) i) (main n m (isConnectedΩ^→ n (suc m) f conf)) where open import Cubical.Data.Sum lem : (n m : ℕ) → ((suc n ∸ m ≡ suc (n ∸ m))) ⊎ (suc n ∸ suc m ≡ 0) lem n zero = inl refl lem zero (suc m) = inr refl lem (suc n) (suc m) = lem n m main : (n m : ℕ) → isConnectedFun (suc n ∸ suc m) (fst (Ω^→ (suc m) f)) → isConnectedFun (suc n ∸ suc (suc m)) {A = Path ((Ω^ (suc m)) (_ , pt A) .fst) refl refl} (cong (fst (Ω^→ (suc m) f))) main n m conf with (lem n (suc m)) ... | (inl x) = isConnectedCong (n ∸ suc m) (fst (Ω^→ (suc m) f)) (subst (λ x → isConnectedFun x (fst (Ω^→ (suc m) f))) x conf) ... | (inr x) = subst (λ x → isConnectedFun x (cong {x = refl} {y = refl} (fst (Ω^→ (suc m) f)))) (sym x) λ b → tt* , λ _ → refl isConnectedRetract : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isConnected n B → isConnected n A isConnectedRetract zero _ _ _ _ = isContrUnit* isConnectedRetract (suc n) f g h = isContrRetract (Trunc.map f) (Trunc.map g) (Trunc.elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) (λ a → cong ∣_∣ (h a))) isConnectedRetractFromIso : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} → Iso A B → isConnected n B → isConnected n A isConnectedRetractFromIso n e = isConnectedRetract n (Iso.fun e) (Iso.inv e) (Iso.leftInv e) isConnectedPoint : ∀ {ℓ} (n : HLevel) {A : Type ℓ} → isConnected (suc n) A → (a : A) → isConnectedFun n (λ(_ : Unit) → a) isConnectedPoint n connA a₀ a = isConnectedRetract n snd (_ ,_) (λ _ → refl) (isConnectedPath n connA a₀ a) isConnectedPoint2 : ∀ {ℓ} (n : HLevel) {A : Type ℓ} (a : A) → isConnectedFun n (λ(_ : Unit) → a) → isConnected (suc n) A isConnectedPoint2 n {A = A} a connMap = indMapEquiv→conType _ λ B → isoToIsEquiv (theIso B) where module _ {ℓ' : Level} (B : TypeOfHLevel ℓ' (suc n)) where helper : (f : A → fst B) → (a2 : A) → f a2 ≡ f a helper f = equiv-proof (elim.isEquivPrecompose (λ _ → a) n (λ a2 → (f a2 ≡ f a) , isOfHLevelPath' n (snd B) (f a2) (f a)) connMap) (λ _ → refl) .fst .fst theIso : Iso (fst B) (A → fst B) Iso.fun theIso b a = b Iso.inv theIso f = f a Iso.rightInv theIso f = funExt λ y → sym (helper f y) Iso.leftInv theIso _ = refl connectedTruncIso : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B) → isConnectedFun n f → Iso (hLevelTrunc n A) (hLevelTrunc n B) connectedTruncIso {A = A} {B = B} zero f con = isContr→Iso isContrUnit* isContrUnit* connectedTruncIso {A = A} {B = B} (suc n) f con = g where back : B → hLevelTrunc (suc n) A back y = map fst ((con y) .fst) backSection : (b : B) → Path (hLevelTrunc (suc n) B) (Trunc.rec (isOfHLevelTrunc (suc n)) (λ a → ∣ f a ∣) (Trunc.rec (isOfHLevelTrunc (suc n)) back ∣ b ∣)) ∣ b ∣ backSection b = helper (λ p → map f p ≡ ∣ b ∣) (λ x → (isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n))) (map f (map fst x)) ∣ b ∣) (λ a p → cong ∣_∣ p) (fst (con b)) where helper : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} (P : hLevelTrunc (suc n) A → Type ℓ'') → ((x : hLevelTrunc (suc n) (Σ A B)) → isOfHLevel (suc n) (P (map fst x))) → ((a : A) (b : B a) → P ∣ a ∣) → (p : hLevelTrunc (suc n) (Σ A B)) → P (map fst p) helper P hlev pf = Trunc.elim hlev λ pair → pf (fst pair) (snd pair) g : Iso (hLevelTrunc (suc n) A) (hLevelTrunc (suc n) B) Iso.fun g = map f Iso.inv g = Trunc.rec (isOfHLevelTrunc _) back Iso.leftInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _) λ a → cong (map fst) (con (f a) .snd ∣ a , refl ∣) Iso.rightInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _) backSection connectedTruncIso2 : ∀ {ℓ} {A B : Type ℓ} (n m : HLevel) (f : A → B) → Σ[ x ∈ ℕ ] x + n ≡ m → isConnectedFun m f → Iso (hLevelTrunc n A) (hLevelTrunc n B) connectedTruncIso2 {A = A} {B = B} n m f (x , pf) con = connectedTruncIso n f (isConnectedFunSubtr n x f (transport (λ i → isConnectedFun (pf (~ i)) f) con)) connectedTruncEquiv : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B) → isConnectedFun n f → hLevelTrunc n A ≃ hLevelTrunc n B connectedTruncEquiv {A = A} {B = B} n f con = isoToEquiv (connectedTruncIso n f con) -- TODO : Reorganise the following proofs. inrConnected : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} (n : HLevel) → (f : C → A) (g : C → B) → isConnectedFun n f → isConnectedFun n {A = B} {B = Pushout f g} inr inrConnected {A = A} {B = B} {C = C} n f g iscon = elim.isConnectedPrecompose inr n λ P → (k P) , λ b → refl where module _ {ℓ : Level} (P : (Pushout f g) → TypeOfHLevel ℓ n) (h : (b : B) → typ (P (inr b))) where Q : A → TypeOfHLevel _ n Q a = (P (inl a)) fun : (c : C) → typ (Q (f c)) fun c = transport (λ i → typ (P (push c (~ i)))) (h (g c)) k : (d : Pushout f g) → typ (P d) k (inl x) = equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .fst x k (inr x) = h x k (push a i) = hcomp (λ k → λ { (i = i0) → equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .snd i0 a ; (i = i1) → transportTransport⁻ (λ j → typ (P (push a j))) (h (g a)) k }) (transp (λ j → typ (P (push a (i ∧ j)))) (~ i) (equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .snd i a)) {- Given two fibration B , C : A → Type and a family of maps on fibres f : (a : A) → B a → C a, we have that f a is n-connected for all (a : A) iff the induced map on totalspaces Σ A B → Σ A C is n-connected -} module _ {ℓ ℓ' ℓ'' : Level} {A : Type ℓ} {B : A → Type ℓ'} {C : A → Type ℓ''} (f : ((a : A) → B a → C a)) where open Iso TotalFun : Σ A B → Σ A C TotalFun (a , b) = a , f a b fibTotalFun→fibFun : (x : Σ A C) → Σ[ y ∈ Σ A B ] TotalFun y ≡ x → Σ[ y ∈ B (fst x) ] f (fst x) y ≡ snd x fibTotalFun→fibFun x = uncurry λ r → J (λ x _ → Σ[ y ∈ B (fst x) ] f (fst x) y ≡ snd x) ((snd r) , refl) fibFun→fibTotalFun : (x : Σ A C) → Σ[ y ∈ B (fst x) ] f (fst x) y ≡ snd x → Σ[ y ∈ Σ A B ] TotalFun y ≡ x fibFun→fibTotalFun x (b , p) = (_ , b) , ΣPathP (refl , p) Iso-fibTotalFun-fibFun : (x : Σ A C) → Iso (Σ[ y ∈ Σ A B ] TotalFun y ≡ x) (Σ[ y ∈ B (fst x) ] f (fst x) y ≡ snd x) fun (Iso-fibTotalFun-fibFun x) = fibTotalFun→fibFun x inv (Iso-fibTotalFun-fibFun x) = fibFun→fibTotalFun x rightInv (Iso-fibTotalFun-fibFun x) (r , y) j = transp (λ i → Σ[ b ∈ B (fst x) ] (f (fst x) b ≡ y (i ∨ j))) j (r , λ i → y (i ∧ j)) leftInv (Iso-fibTotalFun-fibFun x) = uncurry λ r → J (λ x y → inv (Iso-fibTotalFun-fibFun x) (fun (Iso-fibTotalFun-fibFun x) (r , y)) ≡ (r , y)) (cong (fibFun→fibTotalFun (TotalFun r)) (transportRefl (snd r , refl))) TotalFunConnected→FunConnected : (n : ℕ) → isConnectedFun n TotalFun → ((a : A) → isConnectedFun n (f a)) TotalFunConnected→FunConnected n con a r = isConnectedRetractFromIso n (invIso (Iso-fibTotalFun-fibFun (a , r))) (con (a , r)) FunConnected→TotalFunConnected : (n : ℕ) → ((a : A) → isConnectedFun n (f a)) → isConnectedFun n TotalFun FunConnected→TotalFunConnected n con r = isConnectedRetractFromIso n (Iso-fibTotalFun-fibFun r) (con (fst r) (snd r))
41.215517
145
0.534041
dfbeb944bc5d024a81e45893eeb7087b03e2acdf
8,750
agda
Agda
src/generic-filter.agda
shinji-kono/zf-in-agda
031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0
[ "MIT" ]
5
2019-10-02T13:46:23.000Z
2021-01-10T13:27:48.000Z
src/generic-filter.agda
shinji-kono/zf-in-agda
031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0
[ "MIT" ]
null
null
null
src/generic-filter.agda
shinji-kono/zf-in-agda
031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0
[ "MIT" ]
null
null
null
open import Level open import Ordinals module generic-filter {n : Level } (O : Ordinals {n}) where import filter open import zf open import logic -- open import partfunc {n} O import OD open import Relation.Nullary open import Relation.Binary open import Data.Empty open import Relation.Binary open import Relation.Binary.Core open import Relation.Binary.PropositionalEquality open import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ ) import BAlgbra open BAlgbra O open inOrdinal O open OD O open OD.OD open ODAxiom odAxiom import OrdUtil import ODUtil open Ordinals.Ordinals O open Ordinals.IsOrdinals isOrdinal open Ordinals.IsNext isNext open OrdUtil O open ODUtil O import ODC open filter O open _∧_ open _∨_ open Bool open HOD ------- -- the set of finite partial functions from ω to 2 -- -- open import Data.List hiding (filter) open import Data.Maybe import OPair open OPair O ODSuc : (y : HOD) → infinite ∋ y → HOD ODSuc y lt = Union (y , (y , y)) data Hω2 : (i : Nat) ( x : Ordinal ) → Set n where hφ : Hω2 0 o∅ h0 : {i : Nat} {x : Ordinal } → Hω2 i x → Hω2 (Suc i) (& (Union ((< nat→ω i , nat→ω 0 >) , * x ))) h1 : {i : Nat} {x : Ordinal } → Hω2 i x → Hω2 (Suc i) (& (Union ((< nat→ω i , nat→ω 1 >) , * x ))) he : {i : Nat} {x : Ordinal } → Hω2 i x → Hω2 (Suc i) x record Hω2r (x : Ordinal) : Set n where field count : Nat hω2 : Hω2 count x open Hω2r HODω2 : HOD HODω2 = record { od = record { def = λ x → Hω2r x } ; odmax = next o∅ ; <odmax = odmax0 } where P : (i j : Nat) (x : Ordinal ) → HOD P i j x = ((nat→ω i , nat→ω i) , (nat→ω i , nat→ω j)) , * x nat1 : (i : Nat) (x : Ordinal) → & (nat→ω i) o< next x nat1 i x = next< nexto∅ ( <odmax infinite (ω∋nat→ω {i})) lemma1 : (i j : Nat) (x : Ordinal ) → osuc (& (P i j x)) o< next x lemma1 i j x = osuc<nx (pair-<xy (pair-<xy (pair-<xy (nat1 i x) (nat1 i x) ) (pair-<xy (nat1 i x) (nat1 j x) ) ) (subst (λ k → k o< next x) (sym &iso) x<nx )) lemma : (i j : Nat) (x : Ordinal ) → & (Union (P i j x)) o< next x lemma i j x = next< (lemma1 i j x ) ho< odmax0 : {y : Ordinal} → Hω2r y → y o< next o∅ odmax0 {y} r with hω2 r ... | hφ = x<nx ... | h0 {i} {x} t = next< (odmax0 record { count = i ; hω2 = t }) (lemma i 0 x) ... | h1 {i} {x} t = next< (odmax0 record { count = i ; hω2 = t }) (lemma i 1 x) ... | he {i} {x} t = next< (odmax0 record { count = i ; hω2 = t }) x<nx 3→Hω2 : List (Maybe Two) → HOD 3→Hω2 t = list→hod t 0 where list→hod : List (Maybe Two) → Nat → HOD list→hod [] _ = od∅ list→hod (just i0 ∷ t) i = Union (< nat→ω i , nat→ω 0 > , ( list→hod t (Suc i) )) list→hod (just i1 ∷ t) i = Union (< nat→ω i , nat→ω 1 > , ( list→hod t (Suc i) )) list→hod (nothing ∷ t) i = list→hod t (Suc i ) Hω2→3 : (x : HOD) → HODω2 ∋ x → List (Maybe Two) Hω2→3 x = lemma where lemma : { y : Ordinal } → Hω2r y → List (Maybe Two) lemma record { count = 0 ; hω2 = hφ } = [] lemma record { count = (Suc i) ; hω2 = (h0 hω3) } = just i0 ∷ lemma record { count = i ; hω2 = hω3 } lemma record { count = (Suc i) ; hω2 = (h1 hω3) } = just i1 ∷ lemma record { count = i ; hω2 = hω3 } lemma record { count = (Suc i) ; hω2 = (he hω3) } = nothing ∷ lemma record { count = i ; hω2 = hω3 } ω→2 : HOD ω→2 = Power infinite ω→2f : (x : HOD) → ω→2 ∋ x → Nat → Two ω→2f x lt n with ODC.∋-p O x (nat→ω n) ω→2f x lt n | yes p = i1 ω→2f x lt n | no ¬p = i0 fω→2-sel : ( f : Nat → Two ) (x : HOD) → Set n fω→2-sel f x = (infinite ∋ x) ∧ ( (lt : odef infinite (& x) ) → f (ω→nat x lt) ≡ i1 ) fω→2 : (Nat → Two) → HOD fω→2 f = Select infinite (fω→2-sel f) open _==_ import Axiom.Extensionality.Propositional postulate f-extensionality : { n m : Level} → Axiom.Extensionality.Propositional.Extensionality n m ω2∋f : (f : Nat → Two) → ω→2 ∋ fω→2 f ω2∋f f = power← infinite (fω→2 f) (λ {x} lt → proj1 ((proj2 (selection {fω→2-sel f} {infinite} )) lt)) ω→2f≡i1 : (X i : HOD) → (iω : infinite ∋ i) → (lt : ω→2 ∋ X ) → ω→2f X lt (ω→nat i iω) ≡ i1 → X ∋ i ω→2f≡i1 X i iω lt eq with ODC.∋-p O X (nat→ω (ω→nat i iω)) ω→2f≡i1 X i iω lt eq | yes p = subst (λ k → X ∋ k ) (nat→ω-iso iω) p open _⊆_ -- someday ... -- postulate -- ω→2f-iso : (X : HOD) → ( lt : ω→2 ∋ X ) → fω→2 ( ω→2f X lt ) =h= X -- fω→2-iso : (f : Nat → Two) → ω→2f ( fω→2 f ) (ω2∋f f) ≡ f record CountableOrdinal : Set (suc (suc n)) where field ctl→ : Nat → Ordinal ctl← : Ordinal → Nat ctl-iso→ : { x : Ordinal } → ctl→ (ctl← x ) ≡ x ctl-iso← : { x : Nat } → ctl← (ctl→ x ) ≡ x record CountableHOD : Set (suc (suc n)) where field mhod : HOD mtl→ : Nat → Ordinal mtl→∈P : (i : Nat) → odef mhod (mtl→ i) mtl← : (x : Ordinal) → odef mhod x → Nat mtl-iso→ : { x : Ordinal } → (lt : odef mhod x ) → mtl→ (mtl← x lt ) ≡ x mtl-iso← : { x : Nat } → mtl← (mtl→ x ) (mtl→∈P x) ≡ x open CountableOrdinal open CountableHOD ---- -- a(n) ∈ M -- ∃ q ∈ Power P → q ∈ a(n) ∧ p(n) ⊆ q -- PGHOD : (i : Nat) → (C : CountableOrdinal) → (P : HOD) → (p : Ordinal) → HOD PGHOD i C P p = record { od = record { def = λ x → odef (Power P) x ∧ odef (* (ctl→ C i)) x ∧ ( (y : Ordinal ) → odef (* p) y → odef (* x) y ) } ; odmax = odmax (Power P) ; <odmax = λ {y} lt → <odmax (Power P) (proj1 lt) } --- -- p(n+1) = if PGHOD n qn otherwise p(n) -- next-p : (C : CountableOrdinal) (P : HOD ) (i : Nat) → (p : Ordinal) → Ordinal next-p C P i p with is-o∅ ( & (PGHOD i C P p)) next-p C P i p | yes y = p next-p C P i p | no not = & (ODC.minimal O (PGHOD i C P p ) (λ eq → not (=od∅→≡o∅ eq))) -- axiom of choice --- -- ascendant search on p(n) -- find-p : (C : CountableOrdinal) (P : HOD ) (i : Nat) → (x : Ordinal) → Ordinal find-p C P Zero x = x find-p C P (Suc i) x = find-p C P i ( next-p C P i x ) --- -- G = { r ∈ Power P | ∃ n → r ⊆ p(n) } -- record PDN (C : CountableOrdinal) (P : HOD ) (x : Ordinal) : Set n where field gr : Nat pn<gr : (y : Ordinal) → odef (* x) y → odef (* (find-p C P gr o∅)) y x∈PP : odef (Power P) x open PDN --- -- G as a HOD -- PDHOD : (C : CountableOrdinal) → (P : HOD ) → HOD PDHOD C P = record { od = record { def = λ x → PDN C P x } ; odmax = odmax (Power P) ; <odmax = λ {y} lt → <odmax (Power P) {y} (PDN.x∈PP lt) } open PDN ---- -- Generic Filter on Power P for HOD's Countable Ordinal (G ⊆ Power P ≡ G i.e. Nat → P → Set ) -- -- p 0 ≡ ∅ -- p (suc n) = if ∃ q ∈ * ( ctl→ n ) ∧ p n ⊆ q → q (axiom of choice) --- else p n P∅ : {P : HOD} → odef (Power P) o∅ P∅ {P} = subst (λ k → odef (Power P) k ) ord-od∅ (lemma o∅ o∅≡od∅) where lemma : (x : Ordinal ) → * x ≡ od∅ → odef (Power P) (& od∅) lemma x eq = power← P od∅ (λ {x} lt → ⊥-elim (¬x<0 lt )) x<y→∋ : {x y : Ordinal} → odef (* x) y → * x ∋ * y x<y→∋ {x} {y} lt = subst (λ k → odef (* x) k ) (sym &iso) lt P-GenericFilter : (C : CountableOrdinal) → (P : HOD ) → GenericFilter P P-GenericFilter C P = record { genf = record { filter = PDHOD C P ; f⊆PL = f⊆PL ; filter1 = {!!} ; filter2 = {!!} } ; generic = λ D → {!!} } where find-p-⊆P : (C : CountableOrdinal) (P : HOD ) (i : Nat) → (x y : Ordinal) → odef (Power P) x → odef (* (find-p C P i x)) y → odef P y find-p-⊆P C P Zero x y Px Py = subst (λ k → odef P k ) &iso ( incl (ODC.power→⊆ O P (* x) (d→∋ (Power P) Px)) (x<y→∋ Py)) find-p-⊆P C P (Suc i) x y Px Py = find-p-⊆P C P i (next-p C P i x) y {!!} {!!} f⊆PL : PDHOD C P ⊆ Power P f⊆PL = record { incl = λ {x} lt → power← P x (λ {y} y<x → find-p-⊆P C P (gr lt) o∅ (& y) P∅ (pn<gr lt (& y) (subst (λ k → odef k (& y)) (sym *iso) y<x))) } open GenericFilter open Filter record Incompatible (P : HOD ) : Set (suc (suc n)) where field except : HOD → ( HOD ∧ HOD ) incompatible : { p : HOD } → Power P ∋ p → Power P ∋ proj1 (except p ) → Power P ∋ proj2 (except p ) → ( p ⊆ proj1 (except p) ) ∧ ( p ⊆ proj2 (except p) ) → ∀ ( r : HOD ) → Power P ∋ r → ¬ (( proj1 (except p) ⊆ r ) ∧ ( proj2 (except p) ⊆ r )) lemma725 : (M : CountableHOD ) (C : CountableOrdinal) (P : HOD ) → mhod M ∋ Power P → Incompatible P → ¬ ( mhod M ∋ filter ( genf ( P-GenericFilter C P ))) lemma725 = {!!} lemma725-1 : Incompatible HODω2 lemma725-1 = {!!} lemma726 : (C : CountableOrdinal) (P : HOD ) → Union ( filter ( genf ( P-GenericFilter C HODω2 ))) =h= ω→2 lemma726 = {!!} -- -- val x G = { val y G | ∃ p → G ∋ p → x ∋ < y , p > } -- -- W (ω , H ( ω , 2 )) = { p ∈ ( Nat → H (ω , 2) ) | { i ∈ Nat → p i ≠ i1 } is finite } --
33.143939
143
0.521829
12d28ebf93e1652d4e8cc01df6c3534bacf69fda
2,404
agda
Agda
src/fot/FOTC/Program/Collatz/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Program/Collatz/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Program/Collatz/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Properties of the Collatz function ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.Collatz.PropertiesI where open import Common.FOL.Relation.Binary.EqReasoning open import FOTC.Base open import FOTC.Base.PropertiesI open import FOTC.Data.Nat open import FOTC.Data.Nat.PropertiesI open import FOTC.Data.Nat.UnaryNumbers open import FOTC.Data.Nat.UnaryNumbers.TotalityI open import FOTC.Program.Collatz.Collatz open import FOTC.Program.Collatz.Data.Nat open import FOTC.Program.Collatz.Data.Nat.PropertiesI ------------------------------------------------------------------------------ collatzCong : ∀ {m n} → m ≡ n → collatz m ≡ collatz n collatzCong refl = refl helper : ∀ {n} → N n → collatz (2' ^ succ₁ n) ≡ collatz (2' ^ n) helper nzero = collatz (2' ^ 1') ≡⟨ collatzCong (x^1≡x 2-N) ⟩ collatz 2' ≡⟨ collatz-even 2-Even ⟩ collatz (div 2' 2') ≡⟨ collatzCong (div-x-x≡1 2-N S≢0) ⟩ collatz (1') ≡⟨ collatzCong (sym (^-0 2')) ⟩ collatz (2' ^ 0') ∎ helper (nsucc {n} Nn) = collatz (2' ^ succ₁ (succ₁ n)) ≡⟨ collatzCong prf ⟩ collatz (succ₁ (succ₁ (2' ^ succ₁ (succ₁ n) ∸ 2'))) ≡⟨ collatz-even (x-Even→SSx-Even (∸-N (^-N 2-N (nsucc (nsucc Nn))) 2-N) (∸-Even (^-N 2-N (nsucc (nsucc Nn))) 2-N (2^[x+1]-Even (nsucc Nn)) 2-Even)) ⟩ collatz (div (succ₁ (succ₁ ((2' ^ succ₁ (succ₁ n)) ∸ 2'))) 2') ≡⟨ collatzCong (divLeftCong (sym prf)) ⟩ collatz (div (2' ^ succ₁ (succ₁ n)) 2') ≡⟨ collatzCong (div-2^[x+1]-2≡2^x (nsucc Nn)) ⟩ collatz (2' ^ succ₁ n) ∎ where prf : 2' ^ succ₁ (succ₁ n) ≡ succ₁ (succ₁ (2' ^ succ₁ (succ₁ n) ∸ 2')) prf = (+∸2 (^-N 2-N (nsucc (nsucc Nn))) (2^x≢0 (nsucc (nsucc Nn))) (2^[x+1]≢1 (nsucc Nn))) collatz-2^x : ∀ {n} → N n → collatz (2' ^ n) ≡ 1' collatz-2^x nzero = collatz (2' ^ 0') ≡⟨ collatzCong (^-0 2') ⟩ collatz 1' ≡⟨ collatz-1 ⟩ 1' ∎ collatz-2^x (nsucc {n} Nn) = collatz (2' ^ succ₁ n) ≡⟨ helper Nn ⟩ collatz (2' ^ n) ≡⟨ collatz-2^x Nn ⟩ 1' ∎
36.424242
78
0.499168
dcfaac7d15921f3446b3004f77a25b2e9d518847
5,105
agda
Agda
src/Ch2-3.agda
banacorn/hott
75eea99a879e100304bd48c538c9d2db0b4a4ff3
[ "MIT" ]
null
null
null
src/Ch2-3.agda
banacorn/hott
75eea99a879e100304bd48c538c9d2db0b4a4ff3
[ "MIT" ]
null
null
null
src/Ch2-3.agda
banacorn/hott
75eea99a879e100304bd48c538c9d2db0b4a4ff3
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} module Ch2-3 where open import Level hiding (lift) open import Ch2-1 open import Ch2-2 -- p -- x ~~~~~~~~~ y -- -- -- P x --------> P y -- -- Lemma 2.3.1 (transport) transport : ∀ {a b} {A : Set a} {x y : A} → (P : A → Set b) → (p : x ≡ y) → P x → P y transport {a} {b} {A} {x} {y} P p = J A D d x y p P -- J A D d x y p P where -- the predicate D : (x y : A) (p : x ≡ y) → Set (a ⊔ suc b) D x y p = (P : A → Set b) → P x → P y -- base case d : (x : A) → D x x refl d x P y = y open import Data.Product -- proof -- +-----+ p +-----+ -- | x ~~~~~~~~~~~~~~~~ y | -- | | | | -- | P x |~~~~~~~~~~~~| P y | -- +-----+ * +-----+ -- -- Lemma 2.3.2 (path lifting property) lift : ∀ {a b} {A : Set a} → (P : A → Set b) → (proof : Σ[ x ∈ A ] P x) → (y : A) → (p : proj₁ proof ≡ y) → proof ≡ (y , transport P p (proj₂ proof)) lift {a} {b} {A} P proof y p = J A D d (proj₁ proof) y p (proj₂ proof) where -- the predicate D : (x y : A) (p : x ≡ y) → Set (a ⊔ b) D x y p = (u : P x) → (x , u) ≡ (y , transport P p u) -- base case d : (x : A) → D x x refl d x u = refl -- A -- +----------------------------------------------+ -- | p | -- | x ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ y | -- | + + | -- +----------------------------------------------+ -- | | -- P x | P y | -- +-------+ +----------------------------------+ -- | v | | * v | -- | f x +-------> transport P p (f x) ~~~~~ f y | -- | | | | -- +-------+ +----------------------------------+ -- -- Lemma 2.3.4 (dependent map) apd : ∀ {a b} {A : Set a} {x y : A} → {P : A → Set b} → (f : (z : A) → P z) → (p : x ≡ y) → transport P p (f x) ≡ f y apd {a} {b} {A} {x} {y} {P} f p = J A D d x y p P f where -- the predicate D : (x y : A) (p : x ≡ y) → _ D x y p = (P : A → Set b) (f : (z : A) → P z) → transport P p (f x) ≡ f y -- base case d : (x : A) → D x x refl d x P f = refl open import Function using (const; _∘_) -- Lemma 2.3.5 transportconst : ∀ {a ℓ} {A : Set a} {x y : A} → {B : Set ℓ} → (p : x ≡ y) → (b : B) → transport (const B) p b ≡ b transportconst {a} {ℓ} {A} {x} {y} {B} p b = J A D d x y p B b where -- the predicate D : (x y : A) (p : x ≡ y) → _ D x y p = (B : Set ℓ) (b : B) → transport (const B) p b ≡ b -- base case d : (x : A) → D x x refl d x B b = refl open import Ch2-2 -- Lemma 2.3.8 lemma-2-3-8 : ∀ {a ℓ} {A : Set a} {B : Set ℓ} {x y : A} → (f : A → B) → (p : x ≡ y) → apd f p ≡ transportconst p (f x) ∙ ap f p lemma-2-3-8 {a} {ℓ} {A} {B} {x} {y} f p = J {a} {a ⊔ ℓ} A D d x y p f where -- the predicate D : (x y : A) (p : x ≡ y) → _ D x y p = (f : A → B) → apd f p ≡ transportconst p (f x) ∙ ap f p -- base case d : (x : A) → D x x refl d x f = refl -- Lemma 2.3.9 lemma-2-3-9 : ∀ {a b} {A : Set a} {x y z : A} → (P : A → Set b) → (p : x ≡ y) → (q : y ≡ z) → (u : P x) → transport P q (transport P p u) ≡ transport P (p ∙ q) u lemma-2-3-9 {a} {b} {A} {x} {y} {z} P p q u = J A D d x y p P z q u where -- the predicate D : (x y : A) (p : x ≡ y) → Set _ D x y p = (P : A → Set b) (z : A) (q : y ≡ z) (u : P x) → transport P q (transport P p u) ≡ transport P (p ∙ q) u -- base case d : (x : A) → D x x refl d x P z q u = J A E e x z q P u where -- the predicate E : (x z : A) (q : x ≡ z) → Set _ E x z q = (P : A → Set b) (u : P x) → transport P q (transport P refl u) ≡ transport P (refl ∙ q) u -- base case e : (x : A) → E x x refl e x P u = refl -- Lemma 2.3.10 lemma-2-3-10 : ∀ {a b c} {A : Set a} {B : Set b} {x y : A} → (P : B → Set c) → (f : A → B) → (p : x ≡ y) → (u : P (f x)) → transport (P ∘ f) p u ≡ transport P (ap f p) u lemma-2-3-10 {a} {b} {c} {A} {B} {x} {y} P f p u = J A D d x y p P f u where -- the predicate D : (x y : A) (p : x ≡ y) → Set _ D x y p = (P : B → Set c) (f : A → B) (u : P (f x)) → transport (P ∘ f) p u ≡ transport P (ap f p) u -- base case d : (x : A) → D x x refl d x P f u = refl -- Lemma 2.3.11 lemma-2-3-11 : {a b c : Level} {A : Set a} {x y : A} → (P : A → Set b) (Q : A → Set c) → (f : (z : A) → P z → Q z) → (p : x ≡ y) → (u : P x) → transport Q p (f x u) ≡ f y (transport P p u) lemma-2-3-11 {a} {b} {c} {A} {x} {y} P Q f p u = J A D d x y p P Q f u -- J A D d x y p {! !} {! !} {! !} {! !} where -- the predicate D : (x y : A) (p : x ≡ y) → Set _ D x y p = (P : A → Set b) (Q : A → Set c) (f : (z : A) → P z → Q z) (u : P x) → transport Q p (f x u) ≡ f y (transport P p u) -- base case d : (x : A) → D x x refl d x P Q f u = refl
27.299465
81
0.359843
10d8d84513a2be6635f62e164ceab248cfd3b03e
717
agda
Agda
test/fail/Issue543.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
test/fail/Issue543.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/Issue543.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
-- Andreas, bug found 2011-12-31 module Issue543 where import Common.Level import Common.Irrelevance open import Common.Equality data ⊥ : Set where record ⊤ : Set where constructor tt data Bool : Set where true false : Bool T : Bool → Set T true = ⊤ T false = ⊥ record Squash {ℓ}(A : Set ℓ) : Set ℓ where constructor squash field .unsquash : A open Squash -- ok: sqT≡sqF : squash true ≡ squash false sqT≡sqF = refl -- this should not be provable!! .irrT≡F : true ≡ false irrT≡F = subst (λ s → unsquash (squash true) ≡ unsquash s) sqT≡sqF refl -- the rest is easy T≠F : true ≡ false → ⊥ T≠F p = subst T p tt .irr⊥ : ⊥ irr⊥ = T≠F irrT≡F rel⊥ : .⊥ → ⊥ rel⊥ () absurd : ⊥ absurd = rel⊥ irr⊥
16.295455
71
0.640167
066ab062e455925fbb055f08de215d5ca1e309c7
12,984
agda
Agda
BTA3_polybta-simplify-aenv.agda
luminousfennell/polybta
ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb
[ "BSD-3-Clause" ]
1
2019-10-15T04:35:29.000Z
2019-10-15T04:35:29.000Z
BTA3_polybta-simplify-aenv.agda
luminousfennell/polybta
ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb
[ "BSD-3-Clause" ]
null
null
null
BTA3_polybta-simplify-aenv.agda
luminousfennell/polybta
ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb
[ "BSD-3-Clause" ]
1
2019-10-15T09:01:37.000Z
2019-10-15T09:01:37.000Z
module BTA3 where open import Data.Nat open import Data.Bool open import Data.List -- Binding times data BT : Set where S : BT D : BT -- defining a data type [BT],where two members are -- [S] standing for "static" and [D] standing for dynamic. -- ``subsumption'' binding times; static can be treated as dynamic, -- but not vice versa _≼_ : BT → BT → Bool _≼_ D S = false _≼_ _ _ = true -- note that the above function can also be specified as follows, -- _≼_ : BT → BT → Bool -- D ≼ S = false -- _ ≼ _ = true -- note that the function [≼] specifies that a "static",S, can be treated -- as a "dynamic",D, and not the other way round -- since in Agda, pattern matching is conducted in a sequencial fashion, -- the above specification makes sure that it returns [false] when the -- first argument is [D] and the second [S] and returns [true] in all -- the other three cases. -- BEGIN: stuff that is also in the standard library -- Standard propositional equality, see also Relation.Binary.PropositionalEquality data _==_ {A : Set} (x : A) : A → Set where refl : x == x -- [_==_] defines an equality proposition -- it takes two identical elements of one type as arguments and gives one -- evidence,[refl],for the proposition -- subst lemma subst : {A B : Set}{x x' : A} {C : A → B} → x == x' → C x == C x' subst{A}{B}{x}{.x} refl = refl -- or being defined in the following manner... -- my_subst : {A B : Set}{x x' : A}{C : A → B} → x == x' → C x == C x' -- my_subst refl = refl -- the above function further helps to construct evidence for equality -- proposition -- it says that if two elements are identical then two new elements obtained -- by applying the former to a function should also be identical record True : Set where data False : Set where -- note that the above is regarding two simple proposition [True] and [False] -- regarding [True], -- it is defined as empty record with a single element of type [True],[record{}] -- the trick here is that the type checker knows this and fills in any implicit -- arguments of [True] with this element -- another way of defining [True] as follows, -- record True : Set where -- trivial : True -- trivial = _ -- regarding [False], -- it is defined as a proposition without any evidence corresponding well to -- what a [False] proposition really means isTrue : Bool → Set isTrue true = True isTrue false = False -- note the isTrue b,given b as boolean, is the type of proof that b is equal to -- true since if it is the case, [isTrue b] returns type [True] where its -- evidence is automatically filled in by the type checker while if it is not -- the case there is no way to supply for the evidence due to the way how -- [false] is constructed -- END standard library ---------------------- -- Sublists ---------------------- data _cx-≤_ {A : Set} : List A → List A → Set where cxle-eq : (l : List A) → l cx-≤ l cxle-lt : ∀ {l₁ l₂} x → l₁ cx-≤ l₂ → l₁ cx-≤ (x ∷ l₂) lem-cx-≤-trans : {A : Set} → {l₁ : List A} {l₂ : List A} {l₃ : List A} → l₁ cx-≤ l₂ → l₂ cx-≤ l₃ → l₁ cx-≤ l₃ lem-cx-≤-trans le1 (cxle-eq l) = le1 lem-cx-≤-trans (cxle-eq l) (cxle-lt x e) = cxle-lt x e lem-cx-≤-trans (cxle-lt x e) (cxle-lt x' e') = cxle-lt x' (lem-cx-≤-trans (cxle-lt x e) e') _cxle-∷_ : {A : Set} (x : A) (l : List A) → l cx-≤ (x ∷ l) x cxle-∷ l = cxle-lt x (cxle-eq l) data _⊆_ {A : Set} : List A → List A → Set where refl-⊆ : ∀ {l} → l ⊆ l step-⊆ : ∀ {l} x l₁ l₂ → l ⊆ (l₁ ++ l₂) → l ⊆ (l₁ ++ (x ∷ l₂)) lem-⊆-trans : {A : Set} → {l₁ : List A} {l₂ : List A} {l₃ : List A} → l₁ ⊆ l₂ → l₂ ⊆ l₃ → l₁ ⊆ l₃ lem-⊆-trans e (refl-⊆ {l}) = e lem-⊆-trans (refl-⊆ {l}) (step-⊆ x l₁ l₂ e) = step-⊆ x l₁ l₂ e lem-⊆-trans (step-⊆ x l₁ l₂ e) (step-⊆ x' l₁' l₂' e') = step-⊆ x' l₁' l₂' (lem-⊆-trans (step-⊆ x l₁ l₂ e) e') -- data _≤1_ {A : Set} : List A → List A → Set where -- cxle1-eq : (l : List A) → l ≤1 l -- cxle1-lt : ∀ x (l : List A) → l ≤1 (x ∷ l) -- data _?∷_ {A : Set} (x : A): List A → Set where -- yes∷ : (l : List A) → x ?∷ (x ∷ l) -- no∷ : (l : List A) → x ?∷ l -- getList : ∀ {A} {x : A} {l : List A} → x ?∷ l → List A -- getList {x = x} (yes∷ l) = x ∷ l -- getList {_} {_} {l} (no∷ .l) = l -- end sublists -- some lemmas about BT subsumption lem-bt≼S : {bt : BT} → isTrue (bt ≼ S) → bt == S lem-bt≼S {S} bt≼S = refl lem-bt≼S {D} () -- which can also be defined as follows, -- my_lem-bt≼S : {bt : BT} → isTrue (bt ≼ S) → bt == S -- my_lem-bt≼S {S} _ = refl -- my_lem-bt≼S {D} () lem-D≼bt : {bt : BT} → isTrue (D ≼ bt) → bt == D lem-D≼bt {S} () lem-D≼bt {D} D≼bt = refl -- Types of the calculus mutual -- s ^ BT data AType : Set where Ann : BT → SType → AType -- int | t -> t data SType : Set where SInt : SType SFun : AType → AType → SType -- aux definitions ATInt : BT → AType ATInt bt = Ann bt SInt ATFun : BT → AType → AType → AType ATFun bt at1 at2 = Ann bt (SFun at1 at2) -- note that the above function labels a ground type with annotations [S] or -- [D],sort of a labelling function -- projection: get the BT from a type btof : AType → BT btof (Ann bt _) = bt -- a related function which takes an annotated type as argument and returns -- the annotation of that type -- "constraint on types: functions have to be at least as dynamic as their component" should be corrected as follows, -- arguments of function should be as dynamic as the function data wft : AType → Set where wf-int : ∀ {bt} → wft (Ann bt SInt) wf-fun : ∀ {bt at1 at2} → wft at1 → wft at2 → isTrue (bt ≼ btof at1) → isTrue (bt ≼ btof at2) → wft (Ann bt (SFun at1 at2)) -- the above proposition specifies a set of well-formed [AType]s, -- any annotated [SInt]s are well-formed, wft (Ann bt SInt) forall bt ∈ BT -- in case of functional type with annotation, the following two criteria have -- to be satisfied to be a well form, -- a. each of its arguments is well-formed -- b. the annotation of the function and the annotations of its arguments must -- satisfy [_≼_] relation -- for instance, the functional type defined above is well-formed while -- the following is not, -- Ann D ( -- SFun (Ann S SInt) (Ann D SInt) -- ) -- in conclusion,for functional type with annotation to be well-formed, -- each of its arguments annotations has to be [D] when that of the function -- is [D] while there is no constraint upon the annotations of its arguments -- when that of the function is [S] lem-force-bt : ∀ {bt at} → isTrue (bt ≼ btof at) → D == bt → D == btof at lem-force-bt {S} bt≼at () lem-force-bt {D} {Ann S y'} () D=bt lem-force-bt {D} {Ann D y'} bt≼at D=bt = refl -- note the above function takes an element[bt] of type [BT] and a type with -- annotation, -- if both -- a. the type is at least as dynamic as [bt] -- b. [bt == D] -- then we know that the annotation of the type must be [D] as well -- and the function in that case returns evidence for that -- Low-level types; types wihtout binding information data Type : Set where TInt : Type TFun : Type → Type → Type -- translation from ATypes to low-level types mutual strip : AType → Type strip (Ann _ σ) = strip' σ strip' : SType → Type strip' SInt = TInt strip' (SFun y y') = TFun (strip y) (strip y') -- note that the above function [strip] converts a type with annotation [AType] -- to a low-level type [Type], -- for instance, -- strip (Ann D SInt) -- = strip' SInt -- = TInt -- strip (Ann S -- SFun (Ann S SInt) (Ann D SInt) -- ) -- = strip' (SFun (Ann S SInt) (Ann D SInt)) -- = TFun (strip (Ann S SInt)) (strip (Ann D SInt)) -- = TFun (strip' SInt) (strip' SInt) -- = TFun TInt TInt^ -- More general purpose definitions (should also be in standard library) -- list membership infix 4 _∈_ data _∈_ {A : Set} : A → List A → Set where hd : ∀ {x xs} → x ∈ (x ∷ xs) tl : ∀ {x y xs} → x ∈ xs → x ∈ (y ∷ xs) -- note the above proposition gives us two constructors for getting -- evidences for an element being a member of one list -- end general purpose definitions -- Typing context Ctx = List Type --data Exp' (Γ Γ' : Ctx) : Type → Set where -- EVar' : -- Typed expression data Exp (Γ : Ctx) : Type → Set where -- [EVar] corresponds to the bounded variables in [AExp] EVar : ∀ {τ} → τ ∈ Γ → Exp Γ τ EInt : ℕ → Exp Γ TInt EFun : ∀ {τ₁ τ₂} → Exp (τ₂ ∷ Γ) τ₁ → Exp Γ (TFun τ₂ τ₁) EApp : ∀ {τ₁ τ₂} → Exp Γ (TFun τ₂ τ₁) → Exp Γ τ₂ → Exp Γ τ₁ -- one additional term, count_tl : ∀ {A Γ Γ'} {τ : A} → τ ∈ Γ → Γ cx-≤ Γ' → τ ∈ Γ' count_tl x (cxle-eq Γ) = x count_tl x (cxle-lt T e) = tl (count_tl x e) data _cx=≤_ {A : Set} : List A → List A → Set where cxle-peq : ∀ {l₁ l₂} { x } → l₁ cx-≤ l₂ → (x ∷ l₁) cx=≤ (x ∷ l₂) cxle-plt : ∀ {l₁ l₂} { x } → l₁ cx=≤ l₂ → (x ∷ l₁) cx=≤ (x ∷ l₂) count_tl' : ∀ {A Γ Γ'} {τ : A } → τ ∈ Γ → Γ cx=≤ Γ' → τ ∈ Γ' count_tl' hd (cxle-plt e) = hd count_tl' hd (cxle-peq e) = hd count_tl' (tl xid) (cxle-plt e) = tl (count_tl' xid e) count_tl' (tl xid) (cxle-peq e) = tl (count_tl xid e) lem-Exp-weakening' : ∀ {τ₂ τ₁ Γ Γ'} → Exp (τ₂ ∷ Γ) τ₁ → (τ₂ ∷ Γ) cx=≤ (τ₂ ∷ Γ') → Exp (τ₂ ∷ Γ') τ₁ lem-Exp-weakening' (EVar x) e = EVar (count_tl' x e) lem-Exp-weakening' (EInt n) e = EInt n lem-Exp-weakening' (EFun t) e = EFun (lem-Exp-weakening' t (cxle-plt e)) lem-Exp-weakening' (EApp t1 t2) e = EApp (lem-Exp-weakening' t1 e) (lem-Exp-weakening' t2 e) lem-Exp-weakening : ∀ {τ Γ Γ'} → Exp Γ τ → Γ cx-≤ Γ' → Exp Γ' τ lem-Exp-weakening t (cxle-eq Γ) = t lem-Exp-weakening (EInt n) e = EInt n lem-Exp-weakening (EVar x) e = EVar (count_tl x e) lem-Exp-weakening (EFun t) (cxle-lt T e) = EFun (lem-Exp-weakening' t (cxle-peq (cxle-lt T e))) lem-Exp-weakening (EApp t1 t2) e = EApp (lem-Exp-weakening t1 e) (lem-Exp-weakening t2 e) -- typed annotated expressions ACtx = List AType data AExp (Δ : ACtx) : AType → Set where AVar : ∀ {α} → α ∈ Δ → AExp Δ α AInt : (bt : BT) → ℕ → AExp Δ (ATInt bt) AFun : ∀ {α₁ α₂} (bt : BT) → wft (ATFun bt α₂ α₁) → AExp (α₂ ∷ Δ) α₁ → AExp Δ (ATFun bt α₂ α₁) AApp : ∀ {α₁ α₂} (bt : BT) → wft (ATFun bt α₂ α₁) → AExp Δ (ATFun bt α₂ α₁) → AExp Δ α₂ → AExp Δ α₁ -- stripping of contexts residual : ACtx → Ctx residual [] = [] residual (Ann S _ ∷ xs) = residual xs residual (Ann D σ ∷ xs) = strip' σ ∷ residual xs -- ``semantic domain'' for partially evaluated AExp-terms: -- - AExp-terms of dynamic type evaluate to Exp-terms -- - AExp-terms of static type evaluate to agda terms, where SFun -- are functions and SInt are natural numbers mutual impTA : Ctx → AType → Set impTA Γ (Ann S σ) = impTA' Γ σ impTA Γ (Ann D σ) = Exp Γ (strip' σ) impTA' : Ctx → SType → Set impTA' Γ SInt = ℕ impTA' Γ (SFun y y') = ∀ {Γ'} → Γ cx-≤ Γ' → impTA Γ' y → impTA Γ' y' lem-impTA-weakening : ∀ {α Γ Γ'} → impTA Γ α → Γ cx-≤ Γ' → impTA Γ' α lem-impTA-weakening {Ann S SInt} v _ = v lem-impTA-weakening {Ann S (SFun x x₁)} f prf = λ prf' → f (lem-cx-≤-trans prf prf') lem-impTA-weakening {Ann D x₁} v prf = lem-Exp-weakening v prf data AEnv : Ctx → ACtx → Set where env[] : ∀ {Γ} → AEnv Γ [] env:: : ∀ {Γ Δ} {α} → impTA Γ α → AEnv Γ Δ → AEnv Γ (α ∷ Δ) lem-AEnv-weakening : ∀ {Γ Γ' Δ} → AEnv Γ Δ → Γ cx-≤ Γ' → AEnv Γ' Δ lem-AEnv-weakening env[] prf = env[] lem-AEnv-weakening (env:: {α = α} x env) prf = env:: (lem-impTA-weakening {α} x prf) (lem-AEnv-weakening env prf) lookup : ∀ {Γ Δ α} → AEnv Γ Δ → (o : α ∈ Δ ) → impTA Γ α lookup env[] () lookup (env:: x env) hd = x lookup (env:: x env) (tl idx) = lookup env idx data IsDynamic : AType → Set where is-dyn : ∀ σ → IsDynamic (Ann D σ) lem-IsDynamic-by-wf : ∀ α → isTrue (D ≼ btof α) → IsDynamic α lem-IsDynamic-by-wf (Ann S σ) () lem-IsDynamic-by-wf (Ann D σ) _ = is-dyn σ -- -- TODO: Do we need additional assurance in the type signature (or as -- -- an aux. lemma) that Γ is the residue of Δ? -- -- Note: It seems that in the light of [AEnv] defined above, -- -- there is no correspondence bewteen Γ and Δ pe : ∀ {Δ Γ α} → AEnv Γ Δ → AExp Δ α → impTA Γ α pe env (AVar idx) = lookup env idx pe env (AInt S i) = i pe env (AInt D i) = EInt i pe {Γ = Γ} env (AFun {α₁} {α₂} S prf exp) = λ {Γ'} (prf₁ : Γ cx-≤ Γ') (v : impTA Γ' α₂) → pe (env:: v (lem-AEnv-weakening env prf₁)) exp pe env (AFun {α₁} {α₂} D (wf-fun _ _ prf-2 prf-1) e) with lem-IsDynamic-by-wf α₁ prf-1 | lem-IsDynamic-by-wf α₂ prf-2 pe {Γ = Γ} env (AFun {.(Ann D σ₁)} {.(Ann D σ₂)} D (wf-fun _ _ prf-1 prf-2) e) | is-dyn σ₁ | is-dyn σ₂ = EFun (pe (env:: (EVar hd) (lem-AEnv-weakening env ((strip' σ₂) cxle-∷ Γ))) e) pe {Γ = Γ} env (AApp S _ f e) = (pe env f (cxle-eq Γ)) (pe env e) pe env (AApp {α₁} {α₂} D (wf-fun _ _ prf₂ prf₁) f e) with lem-IsDynamic-by-wf α₁ prf₁ | lem-IsDynamic-by-wf α₂ prf₂ pe env (AApp {.(Ann D σ₁)} {.(Ann D σ₂)} D (wf-fun _ _ prf₂ prf₁) f e) | is-dyn σ₁ | is-dyn σ₂ = EApp (pe env f) (pe env e)
33.900783
123
0.603512
0602fac044275ce23571ccccf19bbc234b906970
1,158
agda
Agda
src/algebra/group/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
20
2015-06-12T12:20:17.000Z
2022-02-01T11:25:54.000Z
src/algebra/group/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
src/algebra/group/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T12:17:00.000Z
2019-05-04T19:31:00.000Z
{-# OPTIONS --without-K #-} module algebra.group.core where open import level open import algebra.monoid.core open import equality.core open import function.isomorphism open import sum record IsGroup {i} (G : Set i) : Set i where field instance mon : IsMonoid G open IsMonoid mon public field inv : G → G linv : (x : G) → inv x * x ≡ e rinv : (x : G) → x * inv x ≡ e Group : ∀ i → Set (lsuc i) Group i = Σ (Set i) IsGroup module _ {i} {G : Set i} ⦃ grp : IsGroup G ⦄ where open IsGroup ⦃ ... ⦄ left-translation-iso : (g : G) → G ≅ G left-translation-iso g = record { to = λ x → g * x ; from = λ x → inv g * x ; iso₁ = λ x → sym (assoc _ _ _) · ap (λ u → u * x) (linv g) · lunit x ; iso₂ = λ x → sym (assoc _ _ _) · ap (λ u → u * x) (rinv g) · lunit x } right-translation-iso : (g : G) → G ≅ G right-translation-iso g = record { to = λ x → x * g ; from = λ x → x * inv g ; iso₁ = λ x → assoc _ _ _ · ap (λ u → x * u) (rinv g) · runit x ; iso₂ = λ x → assoc _ _ _ · ap (λ u → x * u) (linv g) · runit x }
25.173913
50
0.507772
4de5abd870303d8925534445ff520d312fa0873d
4,388
agda
Agda
Cubical/HITs/Susp/Base.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/HITs/Susp/Base.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/HITs/Susp/Base.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Susp.Base where open import Cubical.Core.Glue open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Data.Bool open import Cubical.HITs.S1 open import Cubical.HITs.S2 open import Cubical.HITs.S3 data Susp {ℓ} (A : Type ℓ) : Type ℓ where north : Susp A south : Susp A merid : (a : A) → north ≡ south SuspBool : Type₀ SuspBool = Susp Bool SuspBool→S¹ : SuspBool → S¹ SuspBool→S¹ north = base SuspBool→S¹ south = base SuspBool→S¹ (merid false i) = loop i SuspBool→S¹ (merid true i) = base S¹→SuspBool : S¹ → SuspBool S¹→SuspBool base = north S¹→SuspBool (loop i) = (merid false ∙ (sym (merid true))) i SuspBool→S¹→SuspBool : (x : SuspBool) → Path _ (S¹→SuspBool (SuspBool→S¹ x)) x SuspBool→S¹→SuspBool north = refl SuspBool→S¹→SuspBool south = merid true SuspBool→S¹→SuspBool (merid false i) = λ j → hcomp (λ k → (λ { (j = i1) → merid false i ; (i = i0) → north ; (i = i1) → merid true (j ∨ ~ k)})) (merid false i) SuspBool→S¹→SuspBool (merid true i) = λ j → merid true (i ∧ j) S¹→SuspBool→S¹ : (x : S¹) → SuspBool→S¹ (S¹→SuspBool x) ≡ x S¹→SuspBool→S¹ base = refl S¹→SuspBool→S¹ (loop i) = λ j → hfill (λ k → λ { (i = i0) → base ; (i = i1) → base }) (inS (loop i)) (~ j) S¹≃SuspBool : S¹ ≃ SuspBool S¹≃SuspBool = isoToEquiv (iso S¹→SuspBool SuspBool→S¹ SuspBool→S¹→SuspBool S¹→SuspBool→S¹) S¹≡SuspBool : S¹ ≡ SuspBool S¹≡SuspBool = isoToPath (iso S¹→SuspBool SuspBool→S¹ SuspBool→S¹→SuspBool S¹→SuspBool→S¹) -- Now the sphere SuspS¹ : Type₀ SuspS¹ = Susp S¹ SuspS¹→S² : SuspS¹ → S² SuspS¹→S² north = base SuspS¹→S² south = base SuspS¹→S² (merid base i) = base SuspS¹→S² (merid (loop j) i) = surf i j meridian-contraction : I → I → I → SuspS¹ meridian-contraction i j l = hfill (λ k → λ { (i = i0) → north ; (i = i1) → merid base (~ k) ; (j = i0) → merid base (~ k ∧ i) ; (j = i1) → merid base (~ k ∧ i) }) (inS (merid (loop j) i)) l S²→SuspS¹ : S² → SuspS¹ S²→SuspS¹ base = north S²→SuspS¹ (surf i j) = meridian-contraction i j i1 S²→SuspS¹→S² : ∀ x → SuspS¹→S² (S²→SuspS¹ x) ≡ x S²→SuspS¹→S² base k = base S²→SuspS¹→S² (surf i j) k = SuspS¹→S² (meridian-contraction i j (~ k)) SuspS¹→S²→SuspS¹ : ∀ x → S²→SuspS¹ (SuspS¹→S² x) ≡ x SuspS¹→S²→SuspS¹ north k = north SuspS¹→S²→SuspS¹ south k = merid base k SuspS¹→S²→SuspS¹ (merid base j) k = merid base (k ∧ j) SuspS¹→S²→SuspS¹ (merid (loop j) i) k = meridian-contraction i j (~ k) S²≡SuspS¹ : S² ≡ SuspS¹ S²≡SuspS¹ = isoToPath (iso S²→SuspS¹ SuspS¹→S² SuspS¹→S²→SuspS¹ S²→SuspS¹→S²) -- And the 3-sphere SuspS² : Type₀ SuspS² = Susp S² SuspS²→S³ : SuspS² → S³ SuspS²→S³ north = base SuspS²→S³ south = base SuspS²→S³ (merid base i) = base SuspS²→S³ (merid (surf j k) i) = surf i j k meridian-contraction-2 : I → I → I → I → SuspS² meridian-contraction-2 i j k l = hfill (λ m → λ { (i = i0) → north ; (i = i1) → merid base (~ m) ; (j = i0) → merid base (~ m ∧ i) ; (j = i1) → merid base (~ m ∧ i) ; (k = i0) → merid base (~ m ∧ i) ; (k = i1) → merid base (~ m ∧ i) }) (inS (merid (surf j k) i)) l S³→SuspS² : S³ → SuspS² S³→SuspS² base = north S³→SuspS² (surf i j k) = meridian-contraction-2 i j k i1 S³→SuspS²→S³ : ∀ x → SuspS²→S³ (S³→SuspS² x) ≡ x S³→SuspS²→S³ base l = base S³→SuspS²→S³ (surf i j k) l = SuspS²→S³ (meridian-contraction-2 i j k (~ l)) SuspS²→S³→SuspS² : ∀ x → S³→SuspS² (SuspS²→S³ x) ≡ x SuspS²→S³→SuspS² north l = north SuspS²→S³→SuspS² south l = merid base l SuspS²→S³→SuspS² (merid base j) l = merid base (l ∧ j) SuspS²→S³→SuspS² (merid (surf j k) i) l = meridian-contraction-2 i j k (~ l) S³≡SuspS² : S³ ≡ SuspS² S³≡SuspS² = isoToPath (iso S³→SuspS² SuspS²→S³ SuspS²→S³→SuspS² S³→SuspS²→S³)
34.551181
97
0.560848
4dc17ee2e630edb7f4e361ddea55a87a09d339c9
16,813
agda
Agda
Cubical/HITs/Sn/Properties.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/HITs/Sn/Properties.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/HITs/Sn/Properties.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.HITs.Sn.Properties where open import Cubical.Foundations.Pointed open import Cubical.Foundations.Path open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Transport open import Cubical.Foundations.Prelude open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Univalence open import Cubical.HITs.S1 open import Cubical.Data.Nat hiding (elim) open import Cubical.Data.Sigma open import Cubical.HITs.Sn.Base open import Cubical.HITs.Susp open import Cubical.HITs.Truncation open import Cubical.Homotopy.Loopspace open import Cubical.Homotopy.Connected private variable ℓ : Level -- Elimination principles for spheres sphereElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isOfHLevel (suc n) (A x)) → A (ptSn (suc n)) → (x : S₊ (suc n)) → A x sphereElim zero hlev pt = toPropElim hlev pt sphereElim (suc n) hlev pt north = pt sphereElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt sphereElim (suc n) {A = A} hlev pt (merid a i) = sphereElim n {A = λ a → PathP (λ i → A (merid a i)) pt (subst A (merid (ptSn (suc n))) pt)} (λ a → isOfHLevelPathP' (suc n) (hlev south) _ _) (λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∧ j))) (~ i) pt) a i sphereElim2 : ∀ {ℓ} (n : ℕ) {A : (S₊ (suc n)) → (S₊ (suc n)) → Type ℓ} → ((x y : S₊ (suc n)) → isOfHLevel (suc n) (A x y)) → A (ptSn (suc n)) (ptSn (suc n)) → (x y : S₊ (suc n)) → A x y sphereElim2 n hlev pt = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → hlev _ _) (sphereElim n (hlev _ ) pt) private compPath-lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y) → PathP (λ i → (p ∙ sym q) i ≡ y) p q compPath-lem {y = y} p q i j = hcomp (λ k → λ { (i = i0) → p j ; (i = i1) → q (~ k ∨ j) ; (j = i1) → y }) (p (j ∨ i)) sphereToPropElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isProp (A x)) → A (ptSn (suc n)) → (x : S₊ (suc n)) → A x sphereToPropElim zero = toPropElim sphereToPropElim (suc n) hlev pt north = pt sphereToPropElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt sphereToPropElim (suc n) {A = A} hlev pt (merid a i) = isProp→PathP {B = λ i → A (merid a i)} (λ _ → hlev _) pt (subst A (merid (ptSn (suc n))) pt) i -- Elimination rule for fibrations (x : Sⁿ) → (y : Sᵐ) → A x y of h-Level (n + m). -- The following principle is just the special case of the "Wedge Connectivity Lemma" -- for spheres (See Cubical.Homotopy.WedgeConnectivity or chapter 8.6 in the HoTT book). -- We prove it directly here for three reasons: -- (i) it should perform better -- (ii) we get a slightly stronger statement for spheres: one of the homotopies will, by design, be refl -- (iii) the fact that the two homotopies only differ by (composition with) the homotopy leftFunction(base) ≡ rightFunction(base) -- is close to trivial wedgeconFun : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ} → ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y)) → (f : (x : _) → A (ptSn (suc n)) x) → (g : (x : _) → A x (ptSn (suc m))) → (g (ptSn (suc n)) ≡ f (ptSn (suc m))) → (x : S₊ (suc n)) (y : S₊ (suc m)) → A x y wedgeconLeft : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ} → (hLev : ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y))) → (f : (x : _) → A (ptSn (suc n)) x) → (g : (x : _) → A x (ptSn (suc m))) → (hom : g (ptSn (suc n)) ≡ f (ptSn (suc m))) → (x : _) → wedgeconFun n m hLev f g hom (ptSn (suc n)) x ≡ f x wedgeconRight : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ} → (hLev : ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y))) → (f : (x : _) → A (ptSn (suc n)) x) → (g : (x : _) → A x (ptSn (suc m))) → (hom : g (ptSn (suc n)) ≡ f (ptSn (suc m))) → (x : _) → wedgeconFun n m hLev f g hom x (ptSn (suc m)) ≡ g x wedgeconFun zero zero {A = A} hlev f g hom = F where helper : SquareP (λ i j → A (loop i) (loop j)) (cong f loop) (cong f loop) (λ i → hcomp (λ k → λ { (i = i0) → hom k ; (i = i1) → hom k }) (g (loop i))) λ i → hcomp (λ k → λ { (i = i0) → hom k ; (i = i1) → hom k }) (g (loop i)) helper = toPathP (isOfHLevelPathP' 1 (hlev _ _) _ _ _ _) F : (x y : S¹) → A x y F base y = f y F (loop i) base = hcomp (λ k → λ { (i = i0) → hom k ; (i = i1) → hom k }) (g (loop i)) F (loop i) (loop j) = helper i j wedgeconFun zero (suc m) {A = A} hlev f g hom = F₀ module _ where transpLemma₀ : (x : S₊ (suc m)) → transport (λ i₁ → A base (merid x i₁)) (g base) ≡ f south transpLemma₀ x = cong (transport (λ i₁ → A base (merid x i₁))) hom ∙ (λ i → transp (λ j → A base (merid x (i ∨ j))) i (f (merid x i))) pathOverMerid₀ : (x : S₊ (suc m)) → PathP (λ i₁ → A base (merid x i₁)) (g base) (transport (λ i₁ → A base (merid (ptSn (suc m)) i₁)) (g base)) pathOverMerid₀ x i = hcomp (λ k → λ { (i = i0) → g base ; (i = i1) → (transpLemma₀ x ∙ sym (transpLemma₀ (ptSn (suc m)))) k}) (transp (λ i₁ → A base (merid x (i₁ ∧ i))) (~ i) (g base)) pathOverMeridId₀ : pathOverMerid₀ (ptSn (suc m)) ≡ λ i → transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g base) pathOverMeridId₀ = (λ j i → hcomp (λ k → λ {(i = i0) → g base ; (i = i1) → rCancel (transpLemma₀ (ptSn (suc m))) j k}) (transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g base))) ∙ λ j i → hfill (λ k → λ { (i = i0) → g base ; (i = i1) → transport (λ i₁ → A base (merid (ptSn (suc m)) i₁)) (g base)}) (inS (transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g base))) (~ j) indStep₀ : (x : _) (a : _) → PathP (λ i → A x (merid a i)) (g x) (subst (λ y → A x y) (merid (ptSn (suc m))) (g x)) indStep₀ = wedgeconFun zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _) pathOverMerid₀ (λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g a)) (sym pathOverMeridId₀) F₀ : (x : S¹) (y : Susp (S₊ (suc m))) → A x y F₀ x north = g x F₀ x south = subst (λ y → A x y) (merid (ptSn (suc m))) (g x) F₀ x (merid a i) = indStep₀ x a i wedgeconFun (suc n) m {A = A} hlev f g hom = F₁ module _ where transpLemma₁ : (x : S₊ (suc n)) → transport (λ i₁ → A (merid x i₁) (ptSn (suc m))) (f (ptSn (suc m))) ≡ g south transpLemma₁ x = cong (transport (λ i₁ → A (merid x i₁) (ptSn (suc m)))) (sym hom) ∙ (λ i → transp (λ j → A (merid x (i ∨ j)) (ptSn (suc m))) i (g (merid x i))) pathOverMerid₁ : (x : S₊ (suc n)) → PathP (λ i₁ → A (merid x i₁) (ptSn (suc m))) (f (ptSn (suc m))) (transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m))) (f (ptSn (suc m)))) pathOverMerid₁ x i = hcomp (λ k → λ { (i = i0) → f (ptSn (suc m)) ; (i = i1) → (transpLemma₁ x ∙ sym (transpLemma₁ (ptSn (suc n)))) k }) (transp (λ i₁ → A (merid x (i₁ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m)))) pathOverMeridId₁ : pathOverMerid₁ (ptSn (suc n)) ≡ λ i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m))) pathOverMeridId₁ = (λ j i → hcomp (λ k → λ { (i = i0) → f (ptSn (suc m)) ; (i = i1) → rCancel (transpLemma₁ (ptSn (suc n))) j k }) (transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m))))) ∙ λ j i → hfill (λ k → λ { (i = i0) → f (ptSn (suc m)) ; (i = i1) → transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m))) (f (ptSn (suc m))) }) (inS (transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m))))) (~ j) indStep₁ : (a : _) (y : _) → PathP (λ i → A (merid a i) y) (f y) (subst (λ x → A x y) (merid (ptSn (suc n))) (f y)) indStep₁ = wedgeconFun n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _) (λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i) (f a)) pathOverMerid₁ pathOverMeridId₁ F₁ : (x : Susp (S₊ (suc n))) (y : S₊ (suc m)) → A x y F₁ north y = f y F₁ south y = subst (λ x → A x y) (merid (ptSn (suc n))) (f y) F₁ (merid a i) y = indStep₁ a y i wedgeconRight zero zero {A = A} hlev f g hom = right where right : (x : S¹) → _ right base = sym hom right (loop i) j = hcomp (λ k → λ { (i = i0) → hom (~ j ∧ k) ; (i = i1) → hom (~ j ∧ k) ; (j = i1) → g (loop i) }) (g (loop i)) wedgeconRight zero (suc m) {A = A} hlev f g hom x = refl wedgeconRight (suc n) m {A = A} hlev f g hom = right where lem : (x : _) → indStep₁ n m hlev f g hom x (ptSn (suc m)) ≡ _ lem = wedgeconRight n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _) (λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i) (f a)) (pathOverMerid₁ n m hlev f g hom) (pathOverMeridId₁ n m hlev f g hom) right : (x : Susp (S₊ (suc n))) → _ ≡ g x right north = sym hom right south = cong (subst (λ x → A x (ptSn (suc m))) (merid (ptSn (suc n)))) (sym hom) ∙ λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∨ j)) (ptSn (suc m))) i (g (merid (ptSn (suc n)) i)) right (merid a i) j = hcomp (λ k → λ { (i = i0) → hom (~ j) ; (i = i1) → transpLemma₁ n m hlev f g hom (ptSn (suc n)) j ; (j = i0) → lem a (~ k) i ; (j = i1) → g (merid a i)}) (hcomp (λ k → λ { (i = i0) → hom (~ j) ; (i = i1) → compPath-lem (transpLemma₁ n m hlev f g hom a) (transpLemma₁ n m hlev f g hom (ptSn (suc n))) k j ; (j = i1) → g (merid a i)}) (hcomp (λ k → λ { (i = i0) → hom (~ j) ; (j = i0) → transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i) (f (ptSn (suc m))) ; (j = i1) → transp (λ j → A (merid a (i ∧ (j ∨ k))) (ptSn (suc m))) (k ∨ ~ i) (g (merid a (i ∧ k))) }) (transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i) (hom (~ j))))) wedgeconLeft zero zero {A = A} hlev f g hom x = refl wedgeconLeft zero (suc m) {A = A} hlev f g hom = help where left₁ : (x : _) → indStep₀ m hlev f g hom base x ≡ _ left₁ = wedgeconLeft zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _) (pathOverMerid₀ m hlev f g hom) (λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i) (g a)) (sym (pathOverMeridId₀ m hlev f g hom)) help : (x : S₊ (suc (suc m))) → _ help north = hom help south = cong (subst (A base) (merid (ptSn (suc m)))) hom ∙ λ i → transp (λ j → A base (merid (ptSn (suc m)) (i ∨ j))) i (f (merid (ptSn (suc m)) i)) help (merid a i) j = hcomp (λ k → λ { (i = i0) → hom j ; (i = i1) → transpLemma₀ m hlev f g hom (ptSn (suc m)) j ; (j = i0) → left₁ a (~ k) i ; (j = i1) → f (merid a i)}) (hcomp (λ k → λ { (i = i0) → hom j ; (i = i1) → compPath-lem (transpLemma₀ m hlev f g hom a) (transpLemma₀ m hlev f g hom (ptSn (suc m))) k j ; (j = i1) → f (merid a i)}) (hcomp (λ k → λ { (i = i0) → hom j ; (j = i0) → transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i) (g base) ; (j = i1) → transp (λ j → A base (merid a (i ∧ (j ∨ k)))) (k ∨ ~ i) (f (merid a (i ∧ k)))}) (transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i) (hom j)))) wedgeconLeft (suc n) m {A = A} hlev f g hom _ = refl ---------- Connectedness ----------- sphereConnected : (n : HLevel) → isConnected (suc n) (S₊ n) sphereConnected n = ∣ ptSn n ∣ , elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) (λ a → sym (spoke ∣_∣ (ptSn n)) ∙ spoke ∣_∣ a) -- The fact that path spaces of Sn are connected can be proved directly for Sⁿ. -- (Unfortunately, this does not work for higher paths) pathIdTruncSⁿ : (n : ℕ) (x y : S₊ (suc n)) → Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣ → hLevelTrunc (suc n) (x ≡ y) pathIdTruncSⁿ n = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n)) (sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n)) λ _ → ∣ refl ∣) pathIdTruncSⁿ⁻ : (n : ℕ) (x y : S₊ (suc n)) → hLevelTrunc (suc n) (x ≡ y) → Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣ pathIdTruncSⁿ⁻ n x y = rec (isOfHLevelTrunc (2 + n) _ _) (J (λ y _ → Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣) refl) pathIdTruncSⁿretract : (n : ℕ) (x y : S₊ (suc n)) → (p : hLevelTrunc (suc n) (x ≡ y)) → pathIdTruncSⁿ n x y (pathIdTruncSⁿ⁻ n x y p) ≡ p pathIdTruncSⁿretract n = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ y → elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) (J (λ y p → pathIdTruncSⁿ n (ptSn (suc n)) y (pathIdTruncSⁿ⁻ n (ptSn (suc n)) y ∣ p ∣) ≡ ∣ p ∣) (cong (pathIdTruncSⁿ n (ptSn (suc n)) (ptSn (suc n))) (transportRefl refl) ∙ pm-help n)) where pm-help : (n : ℕ) → pathIdTruncSⁿ n (ptSn (suc n)) (ptSn (suc n)) refl ≡ ∣ refl ∣ pm-help zero = refl pm-help (suc n) = refl isConnectedPathSⁿ : (n : ℕ) (x y : S₊ (suc n)) → isConnected (suc n) (x ≡ y) isConnectedPathSⁿ n x y = isContrRetract (pathIdTruncSⁿ⁻ n x y) (pathIdTruncSⁿ n x y) (pathIdTruncSⁿretract n x y) ((isContr→isProp (sphereConnected (suc n)) ∣ x ∣ ∣ y ∣) , isProp→isSet (isContr→isProp (sphereConnected (suc n))) _ _ _)
54.061093
138
0.428002
203583786b520bb9c613036013f4cc05853b4056
151
agda
Agda
setoid-cats/Category/Fibration.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
setoid-cats/Category/Fibration.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
setoid-cats/Category/Fibration.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
module Category.Fibration where open import Data.Product open import Category.Category open import Category.Subcategory open import Category.Funct
15.1
32
0.84106
502073185fcdeb926a8bfb1eb9e7a9d96335d438
192
agda
Agda
Cubical/Relation/Binary.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Relation/Binary.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Relation/Binary.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Relation.Binary where open import Cubical.Relation.Binary.Base public open import Cubical.Relation.Binary.Properties public
27.428571
53
0.786458
1216901a0f97074f6668169363b1b78a13fa4488
1,844
agda
Agda
homotopy/OneSkeleton.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/OneSkeleton.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/OneSkeleton.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT module homotopy.OneSkeleton {i} {A : Type i} {j} {B : Type j} where private module _ (map : A → B) where data #OneSkeleton-aux : Type i where #point : A → #OneSkeleton-aux data #OneSkeleton : Type i where #one-skeleton : #OneSkeleton-aux → (Unit → Unit) → #OneSkeleton OneSkeleton : (A → B) → Type i OneSkeleton = #OneSkeleton module _ {map : A → B} where point : A → OneSkeleton map point a = #one-skeleton (#point a) _ postulate -- HIT link : ∀ a₁ a₂ → map a₁ == map a₂ → point a₁ == point a₂ module OneSkeletonElim {l} {P : OneSkeleton map → Type l} (point* : ∀ a → P (point a)) (link* : ∀ a₁ a₂ p → point* a₁ == point* a₂ [ P ↓ link a₁ a₂ p ]) where f : Π (OneSkeleton map) P f = f-aux phantom where f-aux : Phantom link* → Π (OneSkeleton map) P f-aux phantom (#one-skeleton (#point a) _) = point* a postulate link-β : ∀ a₁ a₂ p → apd f (link a₁ a₂ p) == link* a₁ a₂ p open OneSkeletonElim public using () renaming (f to OneSkeleton-elim) module OneSkeletonRec {l} {P : Type l} (point* : ∀ a → P) (link* : ∀ a₁ a₂ p → point* a₁ == point* a₂) where private module M = OneSkeletonElim point* (λ a₁ a₂ p → ↓-cst-in (link* a₁ a₂ p)) f : OneSkeleton map → P f = M.f link-β : ∀ a₁ a₂ p → ap f (link a₁ a₂ p) == link* a₁ a₂ p link-β a₁ a₂ p = apd=cst-in {f = f} (M.link-β a₁ a₂ p) open OneSkeletonRec public using () renaming (f to OneSkeleton-rec) OneSkeleton-lift : OneSkeleton map → B OneSkeleton-lift = OneSkeleton-rec map (λ _ _ p → p) {- module _ {i} {A B : Set i} where skeleton₁ : (A → B) → Set i skeleton₁ f = Graveyard.skeleton₁ {i} {A} {B} {f} -}
27.117647
77
0.560195
a1ae07b6a3c0815898015891eeac50585cad6120
5,605
agda
Agda
Cubical/Algebra/RingSolver/NatExamples.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Algebra/RingSolver/NatExamples.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Algebra/RingSolver/NatExamples.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.Algebra.RingSolver.NatExamples where open import Cubical.Foundations.Prelude open import Cubical.Data.FinData open import Cubical.Data.Nat using (ℕ) open import Cubical.Data.Vec.Base open import Cubical.Algebra.RingSolver.AlmostRing open import Cubical.Algebra.RingSolver.NatAsAlmostRing open import Cubical.Algebra.RingSolver.RingExpression open import Cubical.Algebra.RingSolver.RawRing renaming (⟨_⟩ to ⟨_⟩ᵣ) open import Cubical.Algebra.RingSolver.HornerForms open import Cubical.Algebra.RingSolver.Solver private variable ℓ : Level module MultivariateSolving where open AlmostRing ℕAsAlmostRing ℕAsRawRing = AlmostRing→RawRing ℕAsAlmostRing open EqualityToNormalform ℕAsAlmostRing ℕ[X₀,X₁] = IteratedHornerOperations.asRawRing ℕAsRawRing 2 X₀ : ⟨ ℕ[X₀,X₁] ⟩ᵣ X₀ = Variable 2 ℕAsRawRing (Fin.zero) X₁ : ⟨ ℕ[X₀,X₁] ⟩ᵣ X₁ = Variable 2 ℕAsRawRing (suc Fin.zero) Two : ⟨ ℕ[X₀,X₁] ⟩ᵣ Two = Constant 2 ℕAsRawRing 2 _ : eval 2 X₀ (1 ∷ 0 ∷ []) ≡ 1 _ = refl _ : eval 2 X₁ (0 ∷ 1 ∷ []) ≡ 1 _ = refl X : Expr ℕ 3 X = ∣ Fin.zero Y : Expr ℕ 3 Y = ∣ (suc Fin.zero) Z : Expr ℕ 3 Z = ∣ (suc (suc Fin.zero)) {- 'normalize' maps an expression to its Horner Normalform. Two expressions evaluating to the same ring element have the same Horner Normal form. This means equality of the represented ring elements can be checked by agda's unification (so refl is a proof) -} _ : normalize 3 ((K 2) ⊗ X) ≡ normalize 3 (X ⊕ X) _ = refl _ : normalize 3 ((K 2) ⊗ X) ≡ normalize 3 (X ⊕ X) _ = refl _ : normalize 3 (((K 2) ⊗ X) ⊗ Y) ≡ normalize 3 (Y ⊗ (X ⊕ X)) _ = refl _ : normalize 3 (Z ⊗ (((K 2) ⊗ X) ⊗ Y)) ≡ normalize 3 (Z ⊗ (Y ⊗ (X ⊕ X))) _ = refl {- The solver needs to produce an equality between actual ring elements. So we need a proof that those actual ring elements are equal to a normal form: -} _ : (x y z : ℕ) → eval 3 (normalize 3 ((K 2) ⊗ X ⊗ Y)) (x ∷ y ∷ z ∷ []) ≡ 2 · x · y _ = λ x y z → isEqualToNormalform 3 ((K 2) ⊗ X ⊗ Y) (x ∷ y ∷ z ∷ []) {- Now two of these proofs can be plugged together to solve an equation: -} open Eval ℕAsRawRing _ : (x y z : ℕ) → 3 + x + y · y ≡ y · y + x + 1 + 2 _ = let lhs = (K 3) ⊕ X ⊕ (Y ⊗ Y) rhs = Y ⊗ Y ⊕ X ⊕ (K 1) ⊕ (K 2) in (λ x y z → ⟦ lhs ⟧ (x ∷ y ∷ z ∷ []) ≡⟨ sym (isEqualToNormalform 3 lhs (x ∷ y ∷ z ∷ [])) ⟩ eval 3 (normalize 3 lhs) (x ∷ y ∷ z ∷ []) ≡⟨ refl ⟩ eval 3 (normalize 3 rhs) (x ∷ y ∷ z ∷ []) ≡⟨ isEqualToNormalform 3 rhs (x ∷ y ∷ z ∷ []) ⟩ ⟦ rhs ⟧ (x ∷ y ∷ z ∷ []) ∎) {- Parts of that can be automated easily: -} _ : (x y z : ℕ) → (x + y) · (x + y) ≡ x · x + 2 · x · y + y · y _ = λ x y z → let lhs = (X ⊕ Y) ⊗ (X ⊕ Y) rhs = X ⊗ X ⊕ (K 2) ⊗ X ⊗ Y ⊕ Y ⊗ Y in solve lhs rhs (x ∷ y ∷ z ∷ []) refl {- A bigger example -} _ : (x y z : ℕ) → (x + y) · (x + y) · (x + y) · (x + y) ≡ x · x · x · x + 4 · x · x · x · y + 6 · x · x · y · y + 4 · x · y · y · y + y · y · y · y _ = λ x y z → let lhs = (X ⊕ Y) ⊗ (X ⊕ Y) ⊗ (X ⊕ Y) ⊗ (X ⊕ Y) rhs = X ⊗ X ⊗ X ⊗ X ⊕ (K 4) ⊗ X ⊗ X ⊗ X ⊗ Y ⊕ (K 6) ⊗ X ⊗ X ⊗ Y ⊗ Y ⊕ (K 4) ⊗ X ⊗ Y ⊗ Y ⊗ Y ⊕ Y ⊗ Y ⊗ Y ⊗ Y in solve lhs rhs (x ∷ y ∷ z ∷ []) refl {- this one cannot work so far: _ : (x y z : ℕ) → (x + y) · (x - y) ≡ (x · x - (y · y)) _ = λ x y z → let lhs = (X ⊕ Y) ⊗ (X ⊕ (⊝ Y)) rhs = (X ⊗ X) ⊕ (⊝ (Y ⊗ Y)) in solve lhs rhs (x ∷ y ∷ z ∷ []) {!!} -} module ExamplesForArbitraryRings (R : AlmostRing ℓ) where open AlmostRing R open EqualityToNormalform R X : Expr ⟨ R ⟩ 4 X = ∣ Fin.zero Y : Expr ⟨ R ⟩ 4 Y = ∣ (suc Fin.zero) A : Expr ⟨ R ⟩ 4 A = ∣ (suc (suc Fin.zero)) B : Expr ⟨ R ⟩ 4 B = ∣ (suc (suc (suc Fin.zero))) _ : (x y a b : ⟨ R ⟩) → (x + y) + (a + b) ≡ (y + b) + (x + a) _ = λ x y a b → let lhs = (X ⊕ Y) ⊕ (A ⊕ B) rhs = (Y ⊕ B) ⊕ (X ⊕ A) in solve lhs rhs (x ∷ y ∷ a ∷ b ∷ []) refl _ : (x y a b : ⟨ R ⟩) → (x + y) · (x + y) ≡ x · x + x · y + x · y + y · y _ = λ x y a b → let lhs = (X ⊕ Y) ⊗ (X ⊕ Y) rhs = (X ⊗ X) ⊕ (X ⊗ Y) ⊕ (X ⊗ Y) ⊕ (Y ⊗ Y) in solve lhs rhs (x ∷ y ∷ a ∷ b ∷ []) refl _ : (x y a b : ⟨ R ⟩) → x · a ≡ a · x _ = λ x y a b → let lhs = X ⊗ A rhs = A ⊗ X in solve lhs rhs (x ∷ y ∷ a ∷ b ∷ []) refl {- this one should work, but doesn't: _ : (x y a b : ⟨ R ⟩) → x · (a + b) ≡ a · x + b · x _ = λ x y a b → let lhs = X ⊗ (A ⊕ B) rhs = (A ⊗ X) ⊕ (B ⊗ X) in solve lhs rhs (x ∷ y ∷ a ∷ b ∷ []) refl the reason ist, that lhs and rhs evaluate to definitionally different things: (0r · x + (0r · y + ((0r · a + (0r · b + 1r · 1r)) · a + ((0r · b + 1r · 1r) · b + 1r · 0r)))) · x + 0r (0r · x + (0r · y + ((0r · a + (0r · b + 1r · 1r)) · a + ((0r · b + 1r · 1r) · b + (0r + 0r · 1r))))) · x + 0r -} {- '-' is problematic... _ : (x y a b : ⟨ R ⟩) → (x + y) · (x - y) ≡ (x · x - (y · y)) _ = λ x y a b → let lhs = (X ⊕ Y) ⊗ (X ⊕ (⊝ Y)) rhs = (X ⊗ X) ⊕ (⊝ (Y ⊗ Y)) in solve lhs rhs (x ∷ y ∷ a ∷ b ∷ []) {!!} -}
27.208738
79
0.446922
c5a990787903226158e3bd418c5c6bbf3ed1e544
395
agda
Agda
src/UnSizedIO/Object.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
23
2016-06-19T12:57:55.000Z
2020-10-12T23:15:25.000Z
src/UnSizedIO/Object.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
null
null
null
src/UnSizedIO/Object.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
2
2018-09-01T15:02:37.000Z
2022-03-12T11:41:00.000Z
module UnSizedIO.Object where open import Data.Product record Interface : Set₁ where field Method : Set Result : (m : Method) → Set open Interface public -- A simple object just returns for a method the response -- and the object itself record Object (i : Interface) : Set where coinductive field objectMethod : (m : Method i) → Result i m × Object i open Object public
19.75
57
0.708861
dc2abed092b5dd7539b56c2b13ff339fd1f34d73
2,548
agda
Agda
prototyping/Luau/Subtyping.agda
Libertus-Lab/luau
f1b46f4b967f11fabe666da1de0e71b225368260
[ "MIT" ]
1
2021-11-06T08:03:00.000Z
2021-11-06T08:03:00.000Z
prototyping/Luau/Subtyping.agda
sthagen/Roblox-luau
39fbd2146a379fb0878369b48764cd7e8772c0fb
[ "MIT" ]
null
null
null
prototyping/Luau/Subtyping.agda
sthagen/Roblox-luau
39fbd2146a379fb0878369b48764cd7e8772c0fb
[ "MIT" ]
null
null
null
{-# OPTIONS --rewriting #-} open import Luau.Type using (Type; Scalar; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_) open import Properties.Equality using (_≢_) module Luau.Subtyping where -- An implementation of semantic subtyping -- We think of types as languages of trees data Tree : Set where scalar : ∀ {T} → Scalar T → Tree function : Tree function-ok : Tree → Tree → Tree function-err : Tree → Tree function-tgt : Tree → Tree data Language : Type → Tree → Set data ¬Language : Type → Tree → Set data Language where scalar : ∀ {T} → (s : Scalar T) → Language T (scalar s) function : ∀ {T U} → Language (T ⇒ U) function function-ok₁ : ∀ {T U t u} → (¬Language T t) → Language (T ⇒ U) (function-ok t u) function-ok₂ : ∀ {T U t u} → (Language U u) → Language (T ⇒ U) (function-ok t u) function-err : ∀ {T U t} → (¬Language T t) → Language (T ⇒ U) (function-err t) function-tgt : ∀ {T U t} → (Language U t) → Language (T ⇒ U) (function-tgt t) left : ∀ {T U t} → Language T t → Language (T ∪ U) t right : ∀ {T U u} → Language U u → Language (T ∪ U) u _,_ : ∀ {T U t} → Language T t → Language U t → Language (T ∩ U) t unknown : ∀ {t} → Language unknown t data ¬Language where scalar-scalar : ∀ {S T} → (s : Scalar S) → (Scalar T) → (S ≢ T) → ¬Language T (scalar s) scalar-function : ∀ {S} → (Scalar S) → ¬Language S function scalar-function-ok : ∀ {S t u} → (Scalar S) → ¬Language S (function-ok t u) scalar-function-err : ∀ {S t} → (Scalar S) → ¬Language S (function-err t) scalar-function-tgt : ∀ {S t} → (Scalar S) → ¬Language S (function-tgt t) function-scalar : ∀ {S T U} (s : Scalar S) → ¬Language (T ⇒ U) (scalar s) function-ok : ∀ {T U t u} → (Language T t) → (¬Language U u) → ¬Language (T ⇒ U) (function-ok t u) function-err : ∀ {T U t} → (Language T t) → ¬Language (T ⇒ U) (function-err t) function-tgt : ∀ {T U t} → (¬Language U t) → ¬Language (T ⇒ U) (function-tgt t) _,_ : ∀ {T U t} → ¬Language T t → ¬Language U t → ¬Language (T ∪ U) t left : ∀ {T U t} → ¬Language T t → ¬Language (T ∩ U) t right : ∀ {T U u} → ¬Language U u → ¬Language (T ∩ U) u never : ∀ {t} → ¬Language never t -- Subtyping as language inclusion _<:_ : Type → Type → Set (T <: U) = ∀ t → (Language T t) → (Language U t) -- For warnings, we are interested in failures of subtyping, -- which is whrn there is a tree in T's language that isn't in U's. data _≮:_ (T U : Type) : Set where witness : ∀ t → Language T t → ¬Language U t → ----------------- T ≮: U
37.470588
103
0.589089
a1e59b957649dc72a3eca7cd7d6ed68c26be4d01
2,313
agda
Agda
Algebra/Category/Semigroupoid.agda
esoeylemez/agda-simple
d9245e5a8b2e902781736de09bd17e81022f6f13
[ "BSD-3-Clause" ]
1
2019-10-07T17:36:42.000Z
2019-10-07T17:36:42.000Z
Algebra/Category/Semigroupoid.agda
esoeylemez/agda-simple
d9245e5a8b2e902781736de09bd17e81022f6f13
[ "BSD-3-Clause" ]
null
null
null
Algebra/Category/Semigroupoid.agda
esoeylemez/agda-simple
d9245e5a8b2e902781736de09bd17e81022f6f13
[ "BSD-3-Clause" ]
null
null
null
-- Copyright: (c) 2016 Ertugrul Söylemez -- License: BSD3 -- Maintainer: Ertugrul Söylemez <esz@posteo.de> module Algebra.Category.Semigroupoid where open import Core -- A semigroupoid is a set of objects and morphisms between objects -- together with an associative binary function that combines morphisms. record Semigroupoid {c h r} : Set (lsuc (c ⊔ h ⊔ r)) where field Ob : Set c Hom : Ob → Ob → Set h Eq : ∀ {A B} → Equiv {r = r} (Hom A B) _∘_ : ∀ {A B C} → Hom B C → Hom A B → Hom A C infixl 6 _∘_ open module MyEquiv {A} {B} = Equiv (Eq {A} {B}) public field ∘-cong : ∀ {A B C} {f1 f2 : Hom B C} {g1 g2 : Hom A B} → f1 ≈ f2 → g1 ≈ g2 → f1 ∘ g1 ≈ f2 ∘ g2 assoc : ∀ {A B C D} (f : Hom C D) (g : Hom B C) (h : Hom A B) → (f ∘ g) ∘ h ≈ f ∘ (g ∘ h) Epic : ∀ {A B} → (f : Hom A B) → Set _ Epic f = ∀ {C} {g1 g2 : Hom _ C} → g1 ∘ f ≈ g2 ∘ f → g1 ≈ g2 Monic : ∀ {B C} → (f : Hom B C) → Set _ Monic f = ∀ {A} {g1 g2 : Hom A _} → f ∘ g1 ≈ f ∘ g2 → g1 ≈ g2 Unique : ∀ {A B} → (f : Hom A B) → Set _ Unique f = ∀ g → f ≈ g IsProduct : ∀ A B AB → (fst : Hom AB A) (snd : Hom AB B) → Set _ IsProduct A B AB fst snd = ∀ AB' (fst' : Hom AB' A) (snd' : Hom AB' B) → ∃ (λ (u : Hom AB' AB) → Unique u × (fst ∘ u ≈ fst') × (snd ∘ u ≈ snd')) record Product A B : Set (c ⊔ h ⊔ r) where field A×B : Ob cfst : Hom A×B A csnd : Hom A×B B isProduct : IsProduct A B A×B cfst csnd record _bimonic_ A B : Set (c ⊔ h ⊔ r) where field to : Hom A B from : Hom B A to-monic : Monic to from-monic : Monic from -- A semifunctor is a composition-preserving mapping from a semigroupoid -- to another. record Semifunctor {cc ch cr dc dh dr} (C : Semigroupoid {cc} {ch} {cr}) (D : Semigroupoid {dc} {dh} {dr}) : Set (cc ⊔ ch ⊔ cr ⊔ dc ⊔ dh ⊔ dr) where private module C = Semigroupoid C module D = Semigroupoid D field F : C.Ob → D.Ob map : ∀ {A B} → C.Hom A B → D.Hom (F A) (F B) map-cong : ∀ {A B} {f g : C.Hom A B} → f C.≈ g → map f D.≈ map g ∘-preserving : ∀ {A B C} (f : C.Hom B C) (g : C.Hom A B) → map (f C.∘ g) D.≈ map f D.∘ map g
25.417582
75
0.496325
a1683638be767ed9c73d9fc90c7fc417e81492e9
1,764
agda
Agda
vendor/stdlib/src/Data/Unit.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
56
2015-01-20T02:11:42.000Z
2021-12-21T17:02:19.000Z
vendor/stdlib/src/Data/Unit.agda
larrytheliquid/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
1
2022-03-12T12:17:51.000Z
2022-03-12T12:17:51.000Z
vendor/stdlib/src/Data/Unit.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
3
2015-07-21T16:37:58.000Z
2022-03-12T11:54:10.000Z
------------------------------------------------------------------------ -- The unit type ------------------------------------------------------------------------ module Data.Unit where open import Data.Sum open import Relation.Nullary open import Relation.Binary open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl) ------------------------------------------------------------------------ -- Types -- Note that the name of this type is "\top", not T. record ⊤ : Set where tt : ⊤ tt = record {} record _≤_ (x y : ⊤) : Set where ------------------------------------------------------------------------ -- Operations _≟_ : Decidable {⊤} _≡_ _ ≟ _ = yes refl _≤?_ : Decidable _≤_ _ ≤? _ = yes _ total : Total _≤_ total _ _ = inj₁ _ ------------------------------------------------------------------------ -- Properties preorder : Preorder preorder = PropEq.preorder ⊤ setoid : Setoid setoid = PropEq.setoid ⊤ decTotalOrder : DecTotalOrder decTotalOrder = record { carrier = ⊤ ; _≈_ = _≡_ ; _≤_ = _≤_ ; isDecTotalOrder = record { isTotalOrder = record { isPartialOrder = record { isPreorder = record { isEquivalence = PropEq.isEquivalence ; reflexive = λ _ → _ ; trans = λ _ _ → _ ; ∼-resp-≈ = PropEq.resp₂ _≤_ } ; antisym = antisym } ; total = total } ; _≟_ = _≟_ ; _≤?_ = _≤?_ } } where antisym : Antisymmetric _≡_ _≤_ antisym _ _ = refl decSetoid : DecSetoid decSetoid = DecTotalOrder.Eq.decSetoid decTotalOrder poset : Poset poset = DecTotalOrder.poset decTotalOrder
22.909091
72
0.443878
a141406e92c7cb9c2800d4bfb9fdb67f21dcefe8
4,026
agda
Agda
src/SystemF/Substitutions.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
4
2019-04-05T17:57:11.000Z
2021-05-07T04:08:41.000Z
src/SystemF/Substitutions.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
src/SystemF/Substitutions.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
module SystemF.Substitutions where open import Prelude hiding (subst) open import SystemF.Syntax open import Data.Fin.Substitution open import Data.Star hiding (map) open import Data.Vec hiding ([_]) open import SystemF.Substitutions.Types public module TermTypeSubst where module TermTypeApp {T} (l : Lift T Type) where open Lift l hiding (var) open TypeSubst.TypeApp l renaming (_/_ to _tp/_) infixl 8 _/_ -- Apply a type substitution to a term _/_ : ∀ {ν μ n} → Term ν n → Sub T ν μ → Term μ n var x / σ = var x Λ t / σ = Λ (t / σ ↑) λ' a t / σ = λ' (a tp/ σ) (t / σ) t [ a ] / σ = (t / σ) [ a tp/ σ ] s · t / σ = (s / σ) · (t / σ) open TypeSubst using (varLift; termLift; sub) module Lifted {T} (lift : Lift T Type) {n} where application : Application (λ ν → Term ν n) T application = record { _/_ = TermTypeApp._/_ lift {n = n} } open Application application public open Lifted termLift public -- apply a type variable substitution (renaming) to a term _/Var_ : ∀ {ν μ n} → Term ν n → Sub Fin ν μ → Term μ n _/Var_ = TermTypeApp._/_ varLift -- weaken a term with an additional type variable weaken : ∀ {ν n} → Term ν n → Term (suc ν) n weaken t = t /Var VarSubst.wk infix 8 _[/_] -- shorthand for single-variable type substitutions in terms _[/_] : ∀ {ν n} → Term (suc ν) n → Type ν → Term ν n t [/ b ] = t / sub b module CtxSubst where _/_ : ∀ {ν μ n} → Ctx ν n → Sub Type ν μ → Ctx μ n Γ / σ = Γ TypeSubst.⊙ σ weaken : ∀ {ν n} → Ctx ν n → Ctx (suc ν) n weaken Γ = Γ / TypeSubst.wk -- Variable substitution (renaming) lifted to typing contexts _/Var_ : ∀ {ν m k} → Sub Fin k m → Ctx ν m → Ctx ν k σ /Var Γ = map (λ x → lookup x Γ) σ module TermTermSubst where -- Substitutions of terms in terms TermSub : (ℕ → ℕ → Set) → ℕ → ℕ → ℕ → Set TermSub T ν m n = Sub (T ν) m n record TermLift (T : ℕ → ℕ → Set) : Set where infix 10 _↑tm _↑tp field lift : ∀ {ν n} → T ν n → Term ν n _↑tm : ∀ {ν m n} → TermSub T ν m n → TermSub T ν (suc m) (suc n) _↑tp : ∀ {ν m n} → TermSub T ν m n → TermSub T (suc ν) m n module TermTermApp {T} (l : TermLift T) where open TermLift l infixl 8 _/_ -- Apply a term substitution to a term _/_ : ∀ {ν m n} → Term ν m → TermSub T ν m n → Term ν n var x / σ = lift (lookup x σ) Λ t / σ = Λ (t / (σ ↑tp)) λ' a t / σ = λ' a (t / σ ↑tm) t [ a ] / σ = (t / σ) [ a ] s · t / σ = (s / σ) · (t / σ) Fin′ : ℕ → ℕ → Set Fin′ _ m = Fin m varLift : TermLift Fin′ varLift = record { lift = var; _↑tm = VarSubst._↑; _↑tp = id } infixl 8 _/Var_ _/Var_ : ∀ {ν m n} → Term ν m → Sub Fin m n → Term ν n _/Var_ = TermTermApp._/_ varLift private module ExpandSimple {n : ℕ} where simple : Simple (Term n) simple = record { var = var; weaken = λ t → t /Var VarSubst.wk } open Simple simple public open ExpandSimple using (_↑; simple) open TermTypeSubst using () renaming (weaken to weakenTp) termLift : TermLift Term termLift = record { lift = id; _↑tm = _↑ ; _↑tp = λ ρ → map weakenTp ρ } private module ExpandSubst {ν : ℕ} where app : Application (Term ν) (Term ν) app = record { _/_ = TermTermApp._/_ termLift {ν = ν} } subst : Subst (Term ν) subst = record { simple = simple ; application = app } open Subst subst public open ExpandSubst public hiding (var; simple) infix 8 _[/_] -- Shorthand for single-variable term substitutions in terms _[/_] : ∀ {ν n} → Term ν (suc n) → Term ν n → Term ν n s [/ t ] = s / sub t open TermTermSubst public using () renaming (_/_ to _tm/tm_; _[/_] to _tm[/tm_]; weaken to tmtm-weaken) open TermTypeSubst public using () renaming (_/_ to _tm/tp_; _[/_] to _tm[/tp_]; weaken to tm-weaken) open CtxSubst public using () renaming (_/_ to _ctx/_; weaken to ctx-weaken; _/Var_ to _ctx/Var_)
28.352113
70
0.579483
0ea6ffe55196230d4ca832575f7bbc308561ea25
494
agda
Agda
extra/extra/ModuleInfix.agda
crisoagf/plfa.github.io
195fe74e903dbb9db50ab57a1d76bf9fe20b0133
[ "CC-BY-4.0" ]
1,003
2018-07-05T18:15:14.000Z
2022-03-27T07:03:28.000Z
extra/extra/ModuleInfix.agda
crisoagf/plfa.github.io
195fe74e903dbb9db50ab57a1d76bf9fe20b0133
[ "CC-BY-4.0" ]
323
2018-07-05T22:34:34.000Z
2022-03-30T07:42:57.000Z
extra/extra/ModuleInfix.agda
crisoagf/plfa.github.io
195fe74e903dbb9db50ab57a1d76bf9fe20b0133
[ "CC-BY-4.0" ]
304
2018-07-16T18:24:59.000Z
2022-03-28T11:35:02.000Z
module ModuleInfix where open import Data.List using (List; _∷_; []) open import Data.Bool using (Bool; true; false) module Sort(A : Set)(_≤_ : A → A → Bool)(_⊝_ : A → A → A)(zero : A) where infix 1 _≤_ infix 2 _⊝_ insert : A → List A → List A insert x [] = x ∷ [] insert x (y ∷ ys) with zero ≤ (y ⊝ x) insert x (y ∷ ys) | true = x ∷ y ∷ ys insert x (y ∷ ys) | false = y ∷ insert x ys sort : List A → List A sort [] = [] sort (x ∷ xs) = insert x (sort xs)
24.7
73
0.538462
39a83afcba2dcdff06467b325c8b02fd87f4f6f7
805
agda
Agda
Cubical/Algebra/Group/Construct/Opposite.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Group/Construct/Opposite.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Group/Construct/Opposite.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} open import Cubical.Core.Everything open import Cubical.Algebra.Group module Cubical.Algebra.Group.Construct.Opposite {ℓ} (G : Group ℓ) where open import Cubical.Foundations.Prelude open import Cubical.Data.Prod using (_,_) open Group G import Cubical.Algebra.Monoid.Construct.Opposite monoid as OpMonoid open OpMonoid public hiding (Op-isMonoid; Mᵒᵖ) •ᵒᵖ-inverseˡ : LeftInverse ε _⁻¹ _•ᵒᵖ_ •ᵒᵖ-inverseˡ _ = inverseʳ _ •ᵒᵖ-inverseʳ : RightInverse ε _⁻¹ _•ᵒᵖ_ •ᵒᵖ-inverseʳ _ = inverseˡ _ •ᵒᵖ-inverse : Inverse ε _⁻¹ _•ᵒᵖ_ •ᵒᵖ-inverse = •ᵒᵖ-inverseˡ , •ᵒᵖ-inverseʳ Op-isGroup : IsGroup Carrier _•ᵒᵖ_ ε _⁻¹ Op-isGroup = record { isMonoid = OpMonoid.Op-isMonoid ; inverse = •ᵒᵖ-inverse } Gᵒᵖ : Group ℓ Gᵒᵖ = record { isGroup = Op-isGroup }
23.676471
71
0.731677
fb58454c15d9717fb84a3c839a2feea72ac8c9a5
723
agda
Agda
issues/Issue4.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
10
2015-09-03T20:54:16.000Z
2019-12-03T13:44:25.000Z
issues/Issue4.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
121
2015-01-25T13:22:12.000Z
2018-04-22T06:01:44.000Z
issues/Issue4.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
4
2016-05-10T23:06:19.000Z
2016-08-03T03:54:55.000Z
------------------------------------------------------------------------------ -- Testing the translation of definitions ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module Issue4 where postulate D : Set _≡_ : D → D → Set refl : ∀ {a} → a ≡ a P : D → Set -- We test the translation of a definition where we need to erase proof terms. foo : ∀ {a} → P a → ∀ {b} → P b → a ≡ a foo {a} Pa {b} Pb = bar where c : D c = a {-# ATP definition c #-} postulate bar : c ≡ a {-# ATP prove bar #-}
25.821429
78
0.408022
18292a25e75ea67dc06ee6bd4f88251132ab9b26
7,896
agda
Agda
BasicIS4/Semantics/TarskiOvergluedGentzen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicIS4/Semantics/TarskiOvergluedGentzen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicIS4/Semantics/TarskiOvergluedGentzen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇. -- Tarski-style semantics with contexts as concrete worlds, and glueing for α, ▻, and □. -- Gentzen-style syntax. module BasicIS4.Semantics.TarskiOvergluedGentzen where open import BasicIS4.Syntax.Common public open import Common.Semantics public -- Intuitionistic Tarski models. record Model : Set₁ where infix 3 _⊩ᵅ_ _[⊢]_ _[⊢⋆]_ field -- Forcing for atomic propositions; monotonic. _⊩ᵅ_ : Cx Ty → Atom → Set mono⊩ᵅ : ∀ {P Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩ᵅ P → Γ′ ⊩ᵅ P -- Gentzen-style syntax representation; monotonic. _[⊢]_ : Cx Ty → Ty → Set _[⊢⋆]_ : Cx Ty → Cx Ty → Set mono[⊢] : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ [⊢] A → Γ′ [⊢] A [var] : ∀ {A Γ} → A ∈ Γ → Γ [⊢] A [lam] : ∀ {A B Γ} → Γ , A [⊢] B → Γ [⊢] A ▻ B [app] : ∀ {A B Γ} → Γ [⊢] A ▻ B → Γ [⊢] A → Γ [⊢] B [multibox] : ∀ {A Δ Γ} → Γ [⊢⋆] □⋆ Δ → □⋆ Δ [⊢] A → Γ [⊢] □ A [down] : ∀ {A Γ} → Γ [⊢] □ A → Γ [⊢] A [pair] : ∀ {A B Γ} → Γ [⊢] A → Γ [⊢] B → Γ [⊢] A ∧ B [fst] : ∀ {A B Γ} → Γ [⊢] A ∧ B → Γ [⊢] A [snd] : ∀ {A B Γ} → Γ [⊢] A ∧ B → Γ [⊢] B [unit] : ∀ {Γ} → Γ [⊢] ⊤ -- TODO: Workarounds for Agda bug #2143. top[⊢⋆] : ∀ {Γ} → (Γ [⊢⋆] ∅) ≡ 𝟙 pop[⊢⋆] : ∀ {Ξ A Γ} → (Γ [⊢⋆] Ξ , A) ≡ (Γ [⊢⋆] Ξ × Γ [⊢] A) infix 3 _[⊢]⋆_ _[⊢]⋆_ : Cx Ty → Cx Ty → Set Γ [⊢]⋆ ∅ = 𝟙 Γ [⊢]⋆ Ξ , A = Γ [⊢]⋆ Ξ × Γ [⊢] A [⊢⋆]→[⊢]⋆ : ∀ {Ξ Γ} → Γ [⊢⋆] Ξ → Γ [⊢]⋆ Ξ [⊢⋆]→[⊢]⋆ {∅} {Γ} ts = ∙ [⊢⋆]→[⊢]⋆ {Ξ , A} {Γ} ts rewrite pop[⊢⋆] {Ξ} {A} {Γ} = [⊢⋆]→[⊢]⋆ (π₁ ts) , π₂ ts [⊢]⋆→[⊢⋆] : ∀ {Ξ Γ} → Γ [⊢]⋆ Ξ → Γ [⊢⋆] Ξ [⊢]⋆→[⊢⋆] {∅} {Γ} ∙ rewrite top[⊢⋆] {Γ} = ∙ [⊢]⋆→[⊢⋆] {Ξ , A} {Γ} (ts , t) rewrite pop[⊢⋆] {Ξ} {A} {Γ} = [⊢]⋆→[⊢⋆] ts , t open Model {{…}} public -- Forcing in a particular model. module _ {{_ : Model}} where infix 3 _⊩_ _⊩_ : Cx Ty → Ty → Set Γ ⊩ α P = Glue (Γ [⊢] α P) (Γ ⊩ᵅ P) Γ ⊩ A ▻ B = ∀ {Γ′} → Γ ⊆ Γ′ → Glue (Γ′ [⊢] A ▻ B) (Γ′ ⊩ A → Γ′ ⊩ B) Γ ⊩ □ A = ∀ {Γ′} → Γ ⊆ Γ′ → Glue (Γ′ [⊢] □ A) (Γ′ ⊩ A) Γ ⊩ A ∧ B = Γ ⊩ A × Γ ⊩ B Γ ⊩ ⊤ = 𝟙 infix 3 _⊩⋆_ _⊩⋆_ : Cx Ty → Cx Ty → Set Γ ⊩⋆ ∅ = 𝟙 Γ ⊩⋆ Ξ , A = Γ ⊩⋆ Ξ × Γ ⊩ A -- Monotonicity with respect to context inclusion. module _ {{_ : Model}} where mono⊩ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩ A → Γ′ ⊩ A mono⊩ {α P} η s = mono[⊢] η (syn s) ⅋ mono⊩ᵅ η (sem s) mono⊩ {A ▻ B} η s = λ η′ → s (trans⊆ η η′) mono⊩ {□ A} η s = λ η′ → s (trans⊆ η η′) mono⊩ {A ∧ B} η s = mono⊩ {A} η (π₁ s) , mono⊩ {B} η (π₂ s) mono⊩ {⊤} η s = ∙ mono⊩⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩⋆ Ξ → Γ′ ⊩⋆ Ξ mono⊩⋆ {∅} η ∙ = ∙ mono⊩⋆ {Ξ , A} η (ts , t) = mono⊩⋆ {Ξ} η ts , mono⊩ {A} η t -- Extraction of syntax representation in a particular model. module _ {{_ : Model}} where reifyʳ : ∀ {A Γ} → Γ ⊩ A → Γ [⊢] A reifyʳ {α P} s = syn s reifyʳ {A ▻ B} s = syn (s refl⊆) reifyʳ {□ A} s = syn (s refl⊆) reifyʳ {A ∧ B} s = [pair] (reifyʳ {A} (π₁ s)) (reifyʳ {B} (π₂ s)) reifyʳ {⊤} s = [unit] reifyʳ⋆ : ∀ {Ξ Γ} → Γ ⊩⋆ Ξ → Γ [⊢]⋆ Ξ reifyʳ⋆ {∅} ∙ = ∙ reifyʳ⋆ {Ξ , A} (ts , t) = reifyʳ⋆ ts , reifyʳ t -- Shorthand for variables. module _ {{_ : Model}} where [v₀] : ∀ {A Γ} → Γ , A [⊢] A [v₀] = [var] i₀ [v₁] : ∀ {A B Γ} → Γ , A , B [⊢] A [v₁] = [var] i₁ [v₂] : ∀ {A B C Γ} → Γ , A , B , C [⊢] A [v₂] = [var] i₂ -- Useful theorems in functional form. module _ {{_ : Model}} where [multicut] : ∀ {Ξ A Γ} → Γ [⊢]⋆ Ξ → Ξ [⊢] A → Γ [⊢] A [multicut] {∅} ∙ u = mono[⊢] bot⊆ u [multicut] {Ξ , B} (ts , t) u = [app] ([multicut] ts ([lam] u)) t [dist] : ∀ {A B Γ} → Γ [⊢] □ (A ▻ B) → Γ [⊢] □ A → Γ [⊢] □ B [dist] t u = [multibox] ([⊢]⋆→[⊢⋆] ((∙ , t) , u)) ([app] ([down] [v₁]) ([down] [v₀])) [up] : ∀ {A Γ} → Γ [⊢] □ A → Γ [⊢] □ □ A [up] t = [multibox] ([⊢]⋆→[⊢⋆] ((∙ , t))) [v₀] -- Useful theorems in combinatory form. module _ {{_ : Model}} where [ci] : ∀ {A Γ} → Γ [⊢] A ▻ A [ci] = [lam] [v₀] [ck] : ∀ {A B Γ} → Γ [⊢] A ▻ B ▻ A [ck] = [lam] ([lam] [v₁]) [cs] : ∀ {A B C Γ} → Γ [⊢] (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C [cs] = [lam] ([lam] ([lam] ([app] ([app] [v₂] [v₀]) ([app] [v₁] [v₀])))) [cdist] : ∀ {A B Γ} → Γ [⊢] □ (A ▻ B) ▻ □ A ▻ □ B [cdist] = [lam] ([lam] ([dist] [v₁] [v₀])) [cup] : ∀ {A Γ} → Γ [⊢] □ A ▻ □ □ A [cup] = [lam] ([up] [v₀]) [cdown] : ∀ {A Γ} → Γ [⊢] □ A ▻ A [cdown] = [lam] ([down] [v₀]) [box] : ∀ {A Γ} → ∅ [⊢] A → Γ [⊢] □ A [box] t = [multibox] ([⊢]⋆→[⊢⋆] ∙) t [cpair] : ∀ {A B Γ} → Γ [⊢] A ▻ B ▻ A ∧ B [cpair] = [lam] ([lam] ([pair] [v₁] [v₀])) [cfst] : ∀ {A B Γ} → Γ [⊢] A ∧ B ▻ A [cfst] = [lam] ([fst] [v₀]) [csnd] : ∀ {A B Γ} → Γ [⊢] A ∧ B ▻ B [csnd] = [lam] ([snd] [v₀]) -- Additional useful equipment. module _ {{_ : Model}} where _⟪$⟫_ : ∀ {A B Γ} → Γ ⊩ A ▻ B → Γ ⊩ A → Γ ⊩ B s ⟪$⟫ a = sem (s refl⊆) a ⟪K⟫ : ∀ {A B Γ} → Γ ⊩ A → Γ ⊩ B ▻ A ⟪K⟫ {A} a η = let a′ = mono⊩ {A} η a in [app] [ck] (reifyʳ a′) ⅋ K a′ ⟪S⟫ : ∀ {A B C Γ} → Γ ⊩ A ▻ B ▻ C → Γ ⊩ A ▻ B → Γ ⊩ A → Γ ⊩ C ⟪S⟫ s₁ s₂ a = (s₁ ⟪$⟫ a) ⟪$⟫ (s₂ ⟪$⟫ a) ⟪S⟫′ : ∀ {A B C Γ} → Γ ⊩ A ▻ B ▻ C → Γ ⊩ (A ▻ B) ▻ A ▻ C ⟪S⟫′ {A} {B} {C} s₁ η = let s₁′ = mono⊩ {A ▻ B ▻ C} η s₁ t = syn (s₁′ refl⊆) in [app] [cs] t ⅋ λ s₂ η′ → let s₁″ = mono⊩ {A ▻ B ▻ C} (trans⊆ η η′) s₁ s₂′ = mono⊩ {A ▻ B} η′ s₂ t′ = syn (s₁″ refl⊆) u = syn (s₂′ refl⊆) in [app] ([app] [cs] t′) u ⅋ ⟪S⟫ s₁″ s₂′ _⟪D⟫_ : ∀ {A B Γ} → Γ ⊩ □ (A ▻ B) → Γ ⊩ □ A → Γ ⊩ □ B (s₁ ⟪D⟫ s₂) η = let t ⅋ s₁′ = s₁ η u ⅋ a = s₂ η in [app] ([app] [cdist] t) u ⅋ s₁′ ⟪$⟫ a _⟪D⟫′_ : ∀ {A B Γ} → Γ ⊩ □ (A ▻ B) → Γ ⊩ □ A ▻ □ B _⟪D⟫′_ {A} {B} s₁ η = let s₁′ = mono⊩ {□ (A ▻ B)} η s₁ in [app] [cdist] (reifyʳ (λ {_} η′ → s₁′ η′ )) ⅋ _⟪D⟫_ s₁′ ⟪↑⟫ : ∀ {A Γ} → Γ ⊩ □ A → Γ ⊩ □ □ A ⟪↑⟫ s η = [app] [cup] (syn (s η)) ⅋ λ η′ → s (trans⊆ η η′) ⟪↓⟫ : ∀ {A Γ} → Γ ⊩ □ A → Γ ⊩ A ⟪↓⟫ s = sem (s refl⊆) _⟪,⟫′_ : ∀ {A B Γ} → Γ ⊩ A → Γ ⊩ B ▻ A ∧ B _⟪,⟫′_ {A} a η = let a′ = mono⊩ {A} η a in [app] [cpair] (reifyʳ a′) ⅋ _,_ a′ -- Forcing in a particular world of a particular model, for sequents. module _ {{_ : Model}} where infix 3 _⊩_⇒_ _⊩_⇒_ : Cx Ty → Cx Ty → Ty → Set w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A infix 3 _⊩_⇒⋆_ _⊩_⇒⋆_ : Cx Ty → Cx Ty → Cx Ty → Set w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ -- Entailment, or forcing in all worlds of all models, for sequents. infix 3 _⊨_ _⊨_ : Cx Ty → Ty → Set₁ Γ ⊨ A = ∀ {{_ : Model}} {w : Cx Ty} → w ⊩ Γ ⇒ A infix 3 _⊨⋆_ _⊨⋆_ : Cx Ty → Cx Ty → Set₁ Γ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : Cx Ty} → w ⊩ Γ ⇒⋆ Ξ -- Additional useful equipment, for sequents. module _ {{_ : Model}} where lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A lookup top (γ , a) = a lookup (pop i) (γ , b) = lookup i γ _⟦$⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ▻ B → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B (s₁ ⟦$⟧ s₂) γ = s₁ γ ⟪$⟫ s₂ γ ⟦K⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B ▻ A ⟦K⟧ {A} {B} a γ = ⟪K⟫ {A} {B} (a γ) ⟦S⟧ : ∀ {A B C Γ w} → w ⊩ Γ ⇒ A ▻ B ▻ C → w ⊩ Γ ⇒ A ▻ B → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ C ⟦S⟧ s₁ s₂ a γ = ⟪S⟫ (s₁ γ) (s₂ γ) (a γ) _⟦D⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ □ (A ▻ B) → w ⊩ Γ ⇒ □ A → w ⊩ Γ ⇒ □ B (s₁ ⟦D⟧ s₂) γ = (s₁ γ) ⟪D⟫ (s₂ γ) ⟦↑⟧ : ∀ {A Γ w} → w ⊩ Γ ⇒ □ A → w ⊩ Γ ⇒ □ □ A ⟦↑⟧ s γ = ⟪↑⟫ (s γ) ⟦↓⟧ : ∀ {A Γ w} → w ⊩ Γ ⇒ □ A → w ⊩ Γ ⇒ A ⟦↓⟧ s γ = ⟪↓⟫ (s γ) _⟦,⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B → w ⊩ Γ ⇒ A ∧ B (a ⟦,⟧ b) γ = a γ , b γ ⟦π₁⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ∧ B → w ⊩ Γ ⇒ A ⟦π₁⟧ s γ = π₁ (s γ) ⟦π₂⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ∧ B → w ⊩ Γ ⇒ B ⟦π₂⟧ s γ = π₂ (s γ)
30.252874
88
0.365628
0e16450e67f2e95dd13bb1a98f0f43dc5016ddd3
50
agda
Agda
test/interaction/Issue2447.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2447.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2447.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
import Issue2447.M Rejected : Set Rejected = Set
10
18
0.76
dcc9ffee72b6e33fce411b14f177f834ab26b5c9
4,703
agda
Agda
TypeTheory/SimpleOTT/Terms.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/SimpleOTT/Terms.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
TypeTheory/SimpleOTT/Terms.agda
hbasold/Sandbox
8fc7a6cd878f37f9595124ee8dea62258da28aa4
[ "MIT" ]
null
null
null
module Terms where import Level open import Data.Unit as Unit open import Data.List as List open import Data.Product as Product open import Categories.Category using (Category) open import Types open import Common.Context GType using (Ctx; Var; zero; ctx-cat; ctx-bin-coproducts) renaming (succ to succ′) open Categories.Category.Category ctx-cat renaming ( _⇒_ to _▹_ ; _≡_ to _≈_ ; _∘_ to _●_ ; id to ctx-id ) open import Categories.Object.BinaryCoproducts ctx-cat open BinaryCoproducts ctx-bin-coproducts -- | Signatures over which we can define terms Sig = Ctx -- | Typed patterns data Pat : (a : GType) → Set where var′ : ∀{a : GType} (x : Var [ a ] a) → Pat a κ₁′ : ∀{a₁ a₂ : GType} (p : Pat a₁) → Pat (a₁ ⊕ a₂) κ₂′ : ∀{a₁ a₂ : GType} (p : Pat a₂) → Pat (a₁ ⊕ a₂) α′ : ∀{a : Type [ tt ]} (p : Pat (unfold-μ a)) → Pat (μ a) -- | Context defined by a pattern (this is either empty or contains a single -- variable). pat-ctx : ∀ {a} → Pat a → Ctx pat-ctx {a} (var′ x) = [ a ] pat-ctx (κ₁′ x) = pat-ctx x pat-ctx (κ₂′ x) = pat-ctx x pat-ctx (α′ x) = pat-ctx x -- | Typed copatterns data Copat : (a b : GType) → Set where · : ∀{a} → Copat a a app′ : ∀{a b c : GType} (q : Copat (b ⇒ c) a) (p : Pat c) → Copat c a π₁′ : ∀{a₁ a₂ a : GType} (q : Copat (a₁ ⊗ a₂) a) → Copat a₁ a π₂′ : ∀{a₁ a₂ a : GType} (q : Copat (a₁ ⊗ a₂) a) → Copat a₂ a ξ′ : ∀{b : Type [ tt ]} {a : GType} (q : Copat (ν b) a) → Copat (unfold-ν b) a -- | Context defined by a copattern copat-ctx : ∀ { a b} → Copat a b → Ctx copat-ctx · = [] copat-ctx (app′ q p) = (copat-ctx q) ∐ (pat-ctx p) copat-ctx (π₁′ q) = copat-ctx q copat-ctx (π₂′ q) = copat-ctx q copat-ctx (ξ′ q) = copat-ctx q mutual -- | A clause { q₁ ↦ t₁ ; ... ; qₙ ↦ tₙ } defines the body of a λ-abstraction -- of the definition of a symbol in a signature. record Clause {Δ : Sig} {Γ : Ctx} {a : GType} : Set where inductive field body : List ( Σ GType (λ b → Σ (Copat a b) (λ q → (Term {Δ} ((copat-ctx q) ∐ Γ) b))) ) -- | Terms typed in a context data Term {Δ : Sig} (Γ : Ctx) : GType → Set where var : ∀{a : GType} (x : Var Γ a) → Term Γ a κ₁ : ∀{a₁ a₂ : GType} (t : Term {Δ} Γ a₁) → Term Γ (a₁ ⊕ a₂) κ₂ : ∀{a₁ a₂ : GType} (t : Term {Δ} Γ a₂) → Term Γ (a₁ ⊕ a₂) α : ∀{a : Type [ tt ]} (t : Term {Δ} Γ (unfold-μ a)) → Term Γ (μ a) app : ∀{a b : GType} (t : Term {Δ} Γ (a ⇒ b)) (s : Term {Δ} Γ a) → Term Γ b π₁ : ∀{a₁ a₂ : GType} (t : Term {Δ} Γ (a₁ ⊗ a₂)) → Term Γ a₁ π₂ : ∀{a₁ a₂ : GType} (t : Term {Δ} Γ (a₁ ⊗ a₂)) → Term Γ a₂ ξ : ∀{a : Type [ tt ]} (t : Term {Δ} Γ (ν a)) → Term Γ (unfold-ν a) svar : ∀{a : GType} (f : Var Δ a) → Term Γ a abs : ∀{a : GType} (D : Clause {Δ} {Γ} {a}) → Term Γ a rlet : ∀{a : GType} {Δ' : Sig} → (Ω : Definition Δ') → Term {Δ ∐ Δ'} Γ a → Term {Δ} Γ a -- | A definition consists of a signature and its definition data DeclBlock : Sig → Set where empty : DeclBlock [] record Definition (Δ : Sig) : Set where inductive field defs : List (Σ GType (λ a → (Var Δ a) × Clause {Δ} {[]} {a})) open Definition TermWDef : GType → Set TermWDef a = Σ Sig (λ Δ → (Definition Δ) × (Term {Δ} [] a)) ---------- Convenience _↦_ : ∀{Δ : Sig} {Γ : Ctx} {a b : GType} (q : Copat a b) (t : Term {Δ} ((copat-ctx q) ∐ Γ) b) → (Σ GType (λ b → Σ (Copat a b) (λ q → (Term {Δ} ((copat-ctx q) ∐ Γ) b)))) _↦_ {b = b} q t = b , q , t _≝_ : ∀{Δ : Sig} {a : GType} (f : Var Δ a) (c : Clause {Δ} {[]} {a}) → Σ GType (λ a → (Var Δ a) × Clause {Δ} {[]} {a}) _≝_ {a = a} f c = a , (f , c) -------------------------------- ------ Examples -- 〈〉 : Term [] unit -- 〈〉 = ? {- hd : ∀ {a : GType} → Term (Str a) → Term a hd t = π₁ (ξ q) hd′ : ∀ {a b : GType} → Copat (Str a) b → Copat a b hd′ q = π₁′ (ξ′ q) ones : TermWDef (Str Nat) ones = Δ , def , (svar o) where Δ : Sig Δ = [ Str Nat ] o : Var [ Str Nat ] (Str Nat) o = zero o-def : Clause {[ Str Nat ]} {[]} {Str Nat} o-def = record { body = [ (· ↦ svar o) ] } def : Definition Δ def = record { defs = [ o ≝ o-def ] } -}
32.434483
86
0.458643
208db81eb61a5219f9772b36a0c6ee2035db9c9d
1,892
agda
Agda
Cubical/Algebra/OrderedCommMonoid/Properties.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/OrderedCommMonoid/Properties.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/OrderedCommMonoid/Properties.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.OrderedCommMonoid.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Structure open import Cubical.Foundations.HLevels open import Cubical.Foundations.SIP using (TypeWithStr) open import Cubical.Data.Sigma open import Cubical.Algebra.CommMonoid open import Cubical.Algebra.OrderedCommMonoid.Base open import Cubical.Relation.Binary.Poset private variable ℓ ℓ' ℓ'' : Level module _ (M : OrderedCommMonoid ℓ ℓ') (P : ⟨ M ⟩ → hProp ℓ'') where open OrderedCommMonoidStr (snd M) module _ (·Closed : (x y : ⟨ M ⟩) → ⟨ P x ⟩ → ⟨ P y ⟩ → ⟨ P (x · y) ⟩) (εContained : ⟨ P ε ⟩) where private subtype = Σ[ x ∈ ⟨ M ⟩ ] ⟨ P x ⟩ submonoid = makeSubCommMonoid (OrderedCommMonoid→CommMonoid M) P ·Closed εContained _≤ₛ_ : (x y : ⟨ submonoid ⟩) → Type ℓ' x ≤ₛ y = (fst x) ≤ (fst y) pres≤ : (x y : ⟨ submonoid ⟩) (x≤y : x ≤ₛ y) → (fst x) ≤ (fst y) pres≤ x y x≤y = x≤y makeOrderedSubmonoid : OrderedCommMonoid _ ℓ' fst makeOrderedSubmonoid = subtype OrderedCommMonoidStr._≤_ (snd makeOrderedSubmonoid) = _≤ₛ_ OrderedCommMonoidStr._·_ (snd makeOrderedSubmonoid) = CommMonoidStr._·_ (snd submonoid) OrderedCommMonoidStr.ε (snd makeOrderedSubmonoid) = CommMonoidStr.ε (snd submonoid) OrderedCommMonoidStr.isOrderedCommMonoid (snd makeOrderedSubmonoid) = IsOrderedCommMonoidFromIsCommMonoid (CommMonoidStr.isCommMonoid (snd submonoid)) (λ x y → is-prop-valued (fst x) (fst y)) (λ x → is-refl (fst x)) (λ x y z → is-trans (fst x) (fst y) (fst z)) (λ x y x≤y y≤x → Σ≡Prop (λ x → snd (P x)) (is-antisym (fst x) (fst y) (pres≤ x y x≤y) (pres≤ y x y≤x))) (λ x y z x≤y → MonotoneR (pres≤ x y x≤y)) λ x y z x≤y → MonotoneL (pres≤ x y x≤y)
34.4
91
0.632135
c5545ac0a1859648165b86d057204f4757140df0
937
agda
Agda
test/Succeed/Issue3075b.agda
vlopezj/agda
ff4d89e75970cf27599fb9f572bd43c9455cbb56
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Succeed/Issue3075b.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/Issue3075b.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_) open import Agda.Builtin.Nat open import Agda.Builtin.Unit open import Agda.Builtin.List open import Agda.Builtin.Equality _>>_ : {A B : Set} → TC A → TC B → TC B m >> m' = m >>= λ _ → m' -- Auto-inlined id : {A : Set} → A → A id x = x id-noinline : {A : Set} → A → A id-noinline x = x {-# NOINLINE id-noinline #-} f₁ : Nat → Nat f₁ n = id-noinline n f₂ : Nat → Nat f₂ n = id n macro rhs : Name → Term → TC ⊤ rhs f hole = do function (clause _ rhs ∷ _) ← getDefinition f where _ → typeError (strErr "fail" ∷ []) `rhs ← quoteTC rhs unify hole `rhs pattern vArg x = arg (arg-info visible relevant) x pattern hArg x = arg (arg-info hidden relevant) x -- Should not be inlined check₁ : rhs f₁ ≡ def (quote id-noinline) (hArg (def (quote Nat) []) ∷ vArg (var 0 []) ∷ []) check₁ = refl -- Should be inlined check₂ : rhs f₂ ≡ var 0 [] check₂ = refl
21.790698
92
0.624333
a1bae4e34fbe4c3ef5b48eb39e1a23ea0b4514a5
1,856
agda
Agda
Agda/Cat.agda
chrilves/big4-tutorial
277e034f7152623a17527c4ae55acc7aa8ce1f89
[ "MIT" ]
3
2019-02-02T14:13:39.000Z
2021-08-22T18:44:11.000Z
Agda/Cat.agda
chrilves/big4-tutorial
277e034f7152623a17527c4ae55acc7aa8ce1f89
[ "MIT" ]
1
2021-08-24T14:31:45.000Z
2021-08-24T14:31:45.000Z
Agda/Cat.agda
chrilves/big4-tutorial
277e034f7152623a17527c4ae55acc7aa8ce1f89
[ "MIT" ]
null
null
null
module Cat where open import Agda.Builtin.Equality {- A category is very much like a graph. It has vertices named objects and vertices named arrows. Each arrow goes from an object to an object (possibly the same!). -} record Cat (obj : Set) (arr : obj -> obj -> Set) : Set where constructor MkCat field {- For each object, there is an arrow called `id` which goes from the object to itself. -} id : {o : obj} -> arr o o {- Given an arrow `f` from object `a` to `b` and an arrow `g` from `b` to `c`. We can compose these arrow. The result is an arrow from `a` to `c`. -} compose : {a b c : obj} -> arr a b -> arr b c -> arr a c -- Here comes some properties of `id` and `compose` {- For any arrow `f`, compose id f = f -} neutralLeft : {a b : obj} -> (f : arr a b) -> compose id f ≡ f {- For any arrow `f`, compose f id = f -} neutralRight : {a b : obj} -> (f : arr a b) -> compose f id ≡ f {- For any arrows `f`, `g` and `h`, composing f with g, and then the result with h gives exatctly the same result as composing f with the result of the composition of g and h Which means, like string concatenation than we can commpose the way we preserve the order of each element in the sequence. -} associativity : {a b c d : obj} -> (f : arr a b) -> (g : arr b c) -> (h : arr c d) -> compose f (compose g h) ≡ compose (compose f g) h open import Agda.Builtin.Nat {- `LE n m` encode the property that `n ≤ m` i.e. `n` is less or equal to `m` -} data LE : Nat -> Nat -> Set where LERefl : {n : Nat} -> LE n n LENext : {n m : Nat} -> LE n m -> LE n (suc m) {- Taking naturals as objects and `LE` as arrows, this actually forms a category! -} natPoset : Cat Nat LE natPoset = ???
36.392157
70
0.584591
0beb066878dcd992b9f88a7778407d1cabd0f43c
12,810
agda
Agda
AAOSL/Abstract/EvoCR.agda
VictorCMiraldo/aaosl-agda
8032dd49b4a3803870a3c238abf948c598913f4c
[ "UPL-1.0" ]
1
2021-01-13T17:55:08.000Z
2021-01-13T17:55:08.000Z
AAOSL/Abstract/EvoCR.agda
VictorCMiraldo/aaosl-agda
8032dd49b4a3803870a3c238abf948c598913f4c
[ "UPL-1.0" ]
null
null
null
AAOSL/Abstract/EvoCR.agda
VictorCMiraldo/aaosl-agda
8032dd49b4a3803870a3c238abf948c598913f4c
[ "UPL-1.0" ]
null
null
null
{- Formal verification of authenticated append-only skiplists in Agda, version 1.0. Copyright (c) 2021 Victor C Miraldo. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Data.Unit.NonEta open import Data.Empty open import Data.Sum open import Data.Product open import Data.Product.Properties open import Data.Fin hiding (_<_; _≤_) open import Data.Fin.Properties using () renaming (_≟_ to _≟Fin_) open import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_) open import Data.Nat.Properties open import Data.List renaming (map to List-map) open import Data.List.Properties using (∷-injective; length-map) open import Data.List.Relation.Unary.Any renaming (map to Any-map) open import Data.List.Relation.Unary.All renaming (lookup to All-lookup; map to All-map) open import Data.List.Relation.Unary.All.Properties hiding (All-map) open import Data.List.Relation.Unary.Any.Properties renaming (map⁺ to Any-map⁺) open import Data.List.Relation.Binary.Pointwise using (decidable-≡) open import Data.Bool hiding (_<_; _≤_) open import Data.Maybe renaming (map to Maybe-map) open import Function open import Relation.Binary.PropositionalEquality open import Relation.Binary.Definitions open import Relation.Nullary open import AAOSL.Lemmas open import AAOSL.Abstract.Hash open import AAOSL.Abstract.DepRel module AAOSL.Abstract.EvoCR -- A Hash function maps a bytestring into a hash. (hash : ByteString → Hash) -- And is collision resistant (hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y) -- Indexes can be encoded in an injective way (encodeI : ℕ → ByteString) (encodeI-inj : (m n : ℕ) → encodeI m ≡ encodeI n → m ≡ n) (dep : DepRel) where open WithCryptoHash hash hash-cr open import AAOSL.Abstract.Advancement hash hash-cr encodeI encodeI-inj dep open DepRel dep -- Returns the last element on path a that is smaller than k last-bef : ∀{j i k}(a : AdvPath j i)(i<k : i < k)(k≤j : k ≤′ j) → ℕ last-bef {j} a i<k ≤′-refl = j -- TODO-1 : The same or similar proof is repeated numerous times below; refactor for clarity last-bef AdvDone i<k (≤′-step k≤j) = ⊥-elim (1+n≰n (≤-unstep (≤-trans i<k (≤′⇒≤ k≤j)))) last-bef {k = k} (AdvThere d h a) i<k (≤′-step k≤j) with hop-tgt h ≤?ℕ k ...| yes th≤k = hop-tgt h ...| no th>k = last-bef a i<k (≤⇒≤′ (≰⇒≥ th>k)) last-bef-correct : ∀{j i k}(a : AdvPath j i)(i<k : i < k)(k≤j : k ≤′ j) → last-bef a i<k k≤j ∈AP a last-bef-correct {j} a i<k ≤′-refl = ∈AP-src last-bef-correct AdvDone i<k (≤′-step k≤j) = ⊥-elim (1+n≰n (≤-unstep (≤-trans i<k (≤′⇒≤ k≤j)))) last-bef-correct {k = k} (AdvThere d h a) i<k (≤′-step k≤j) with hop-tgt h ≤?ℕ k ...| yes th≤k = step (<⇒≢ (hop-< h)) ∈AP-src ...| no th>k with last-bef-correct a i<k (≤⇒≤′ (≰⇒≥ th>k)) ...| ind = step (<⇒≢ (≤-trans (s≤s (∈AP-≤ ind)) (hop-< h))) ind lemma5-hop : ∀{j i}(a : AdvPath j i) → ∀{k} → j < k → (h : HopFrom k) → hop-tgt h ≤ j → i ≤ hop-tgt h → hop-tgt h ∈AP a lemma5-hop {j} a j<k h th≤j i≤th with hop-tgt h ≟ℕ j ...| yes th≡j rewrite th≡j = ∈AP-src ...| no th≢j with a ...| AdvDone rewrite ≤-antisym th≤j i≤th = hereTgtDone ...| (AdvThere x h' a') with hop-tgt h' ≟ℕ hop-tgt h ...| yes th'≡th rewrite sym th'≡th = step (<⇒≢ (hop-< h')) ∈AP-src ...| no th'≢th with hop-tgt h' ≤?ℕ hop-tgt h ...| yes th'≤th = ⊥-elim (1+n≰n (≤-trans j<k (hops-nested-or-nonoverlapping (≤∧≢⇒< th'≤th th'≢th) (≤∧≢⇒< th≤j th≢j)))) ...| no th'>th = step th≢j (lemma5-hop a' (≤-trans (hop-< h') (≤-unstep j<k)) h (≰⇒≥ th'>th) i≤th) lemma5 : ∀{j i k}(a : AdvPath j i)(i<k : i < k)(k≤j : k ≤′ j) → ∀{i₀}(b : AdvPath k i₀) → i₀ ≤ i → last-bef a i<k k≤j ∈AP b lemma5 a i<k ≤′-refl b i₀≤i = ∈AP-src lemma5 AdvDone i<k (≤′-step k≤j) b i₀≤i = ⊥-elim (1+n≰n (≤-unstep (≤-trans i<k (≤′⇒≤ k≤j)))) lemma5 {k = k} (AdvThere d h a) i<k (≤′-step k≤j) b i₀≤i with hop-tgt h ≤?ℕ k ...| yes th≤k = lemma5-hop b (s≤s (≤′⇒≤ k≤j)) h th≤k (≤-trans i₀≤i (lemma1 a)) ...| no th>k = lemma5 a i<k (≤⇒≤′ (≰⇒≥ th>k)) b i₀≤i -- returns the first element on path a that is greather than k first-aft : ∀{j i k}(a : AdvPath j i)(i≤k : i ≤′ k)(k<j : k < j) → ℕ first-aft {i = i} a ≤′-refl k<j = i first-aft AdvDone (≤′-step i≤k) k<j = ⊥-elim (1+n≰n (≤-unstep (≤-trans k<j (≤′⇒≤ i≤k)))) first-aft {j} {i} {k} (AdvThere d h a) (≤′-step i≤k) k<j with hop-tgt h ≟ℕ k ...| yes _ = k ...| no th≢k with hop-tgt h ≤?ℕ k ...| yes th≤k = j ...| no th≥k = first-aft a (≤′-step i≤k) (≰⇒> th≥k) first-aft-correct : ∀{j i k}(a : AdvPath j i)(i≤k : i ≤′ k)(k<j : k < j) → first-aft a i≤k k<j ∈AP a first-aft-correct a ≤′-refl k<j = ∈AP-tgt first-aft-correct AdvDone (≤′-step i≤k) k<j = ⊥-elim (1+n≰n (≤-unstep (≤-trans k<j (≤′⇒≤ i≤k)))) first-aft-correct {j} {i} {k} (AdvThere d h a) (≤′-step i≤k) k<j with hop-tgt h ≟ℕ k ...| yes th≡k rewrite sym th≡k = step (<⇒≢ k<j) ∈AP-src ...| no th≢k with hop-tgt h ≤?ℕ k ...| yes th≤k = ∈AP-src ...| no th≥k with first-aft-correct a (≤′-step i≤k) (≰⇒> th≥k) ...| ind = step (<⇒≢ (≤-trans (s≤s (∈AP-≤ ind)) (hop-< h))) ind lemma5'-hop : ∀{j j₁ k}(h : HopFrom j) → hop-tgt h < k → k < j → (b : AdvPath j₁ k) → j ≤ j₁ → j ∈AP b lemma5'-hop {j} {j₁} h th<k k≤j b j≤j₁ with j ≟ℕ j₁ ...| yes refl = ∈AP-src ...| no j≢j₁ with b ...| AdvDone = ⊥-elim (1+n≰n (≤-trans k≤j j≤j₁)) ...| (AdvThere x hb b') with hop-tgt hb ≟ℕ j ...| yes refl = step (<⇒≢ (hop-< hb)) ∈AP-src ...| no tb≢j with hop-tgt hb ≤?ℕ j ...| no tb≰j = step j≢j₁ (lemma5'-hop h th<k k≤j b' (≰⇒≥ tb≰j)) ...| yes tb≤j with hops-nested-or-nonoverlapping (≤-trans th<k (lemma1 b')) (≤∧≢⇒< tb≤j tb≢j) ...| j₁≤j rewrite ≤-antisym j≤j₁ j₁≤j = ∈AP-src lemma5' : ∀{j i k}(a : AdvPath j i)(i≤k : i ≤′ k)(k<j : k < j) → ∀{j₁}(b : AdvPath j₁ k) → j ≤ j₁ → first-aft a i≤k k<j ∈AP b lemma5' a ≤′-refl k<j b j≤j₁ = ∈AP-tgt lemma5' AdvDone (≤′-step i≤k) k<j b j≤j₁ = ⊥-elim (1+n≰n (≤-unstep (≤-trans k<j (≤′⇒≤ i≤k)))) lemma5' {j} {i} {k} (AdvThere d h a) (≤′-step i≤k) k<j b j≤j₁ with hop-tgt h ≟ℕ k ...| yes _ = ∈AP-tgt ...| no th≢k with hop-tgt h ≤?ℕ k ...| yes th≤k = lemma5'-hop h (≤∧≢⇒< th≤k th≢k) k<j b j≤j₁ ...| no th≥k = lemma5' a (≤′-step i≤k) (≰⇒> th≥k) b (≤-unstep (≤-trans (hop-< h) j≤j₁)) ∈AP-⊕-intro-l : ∀{j k i m} → {a₂ : AdvPath j k}{a₁ : AdvPath k i} → m ∈AP a₂ → m ∈AP (a₂ ⊕ a₁) ∈AP-⊕-intro-l hereTgtThere = hereTgtThere ∈AP-⊕-intro-l (step prog m∈a) = step prog (∈AP-⊕-intro-l m∈a) ∈AP-⊕-intro-l {a₁ = AdvDone} hereTgtDone = hereTgtDone ∈AP-⊕-intro-l {a₁ = AdvThere d h a} hereTgtDone = hereTgtThere ∈AP-⊕-intro-r : ∀{j k i m} → {a₂ : AdvPath j k}{a₁ : AdvPath k i} → m ∈AP a₁ → m ∈AP (a₂ ⊕ a₁) ∈AP-⊕-intro-r {a₂ = AdvDone} hyp = hyp ∈AP-⊕-intro-r {k = k} {a₂ = AdvThere d h a} hyp = step (<⇒≢ (≤-trans (s≤s (∈AP-≤ hyp)) (≤-trans (s≤s (lemma1 a)) (hop-< h)))) (∈AP-⊕-intro-r {a₂ = a} hyp) ∈AP-⊕-≤-r : ∀{j k i m}{a₂ : AdvPath j k}{a₁ : AdvPath k i} → m ∈AP (a₂ ⊕ a₁) → m ≤ k → m ∈AP a₁ ∈AP-⊕-≤-r {a₂ = AdvDone} m∈a12 m≤k = m∈a12 ∈AP-⊕-≤-r {a₂ = AdvThere d h a₂} hereTgtThere m≤k = ⊥-elim (1+n≰n (≤-trans (≤-trans (s≤s (lemma1 a₂)) (hop-< h)) m≤k)) ∈AP-⊕-≤-r {a₂ = AdvThere d h a₂} (step x m∈a12) m≤k = ∈AP-⊕-≤-r m∈a12 m≤k findM : ∀ {j i₂ s₁ s₂ tgt} → (a₁₁ : AdvPath j s₁) → (a₂₁ : AdvPath j s₂) → (a₂₂ : AdvPath s₂ i₂) → (m₂ : MembershipProof s₂ tgt) → i₂ ≤ s₁ → tgt ≤ s₁ → s₁ ≤ s₂ → ∃[ M ] (M ∈AP a₂₂ × M ∈AP mbr-proof m₂ × M ∈AP a₁₁) findM {s₁ = s₁} {s₂} a₁₁ a₂₁ a₂₂ m₂ i₂≤s₁ t≤s₁ s₁≤s₂ with <-cmp s₁ s₂ ...| tri> _ _ s₂<s₁ = ⊥-elim (<⇒≢ s₂<s₁ (sym (≤-antisym s₁≤s₂ (≤-unstep s₂<s₁)))) ...| tri≈ _ refl _ = s₁ , ∈AP-src , ∈AP-src , ∈AP-tgt ...| tri< s₁<s₂ _ _ = last-bef a₁₁ s₁<s₂ (≤⇒≤′ (lemma1 a₂₁)) , lemma5 a₁₁ s₁<s₂ (≤⇒≤′ (lemma1 a₂₁)) a₂₂ i₂≤s₁ , lemma5 a₁₁ s₁<s₂ (≤⇒≤′ (lemma1 a₂₁)) (mbr-proof m₂) t≤s₁ , last-bef-correct a₁₁ s₁<s₂ (≤⇒≤′ (lemma1 a₂₁)) findR : ∀{j i₁ s₁ s₂ tgt} → (a₁₁ : AdvPath j s₁) → (a₁₂ : AdvPath s₁ i₁) → (a₂₁ : AdvPath j s₂) → (m₁ : MembershipProof s₁ tgt)(m₂ : MembershipProof s₂ tgt) → i₁ ≤ tgt → tgt ≤ s₁ → s₁ ≤ s₂ -- wlog → ∃[ R ] (R ∈AP mbr-proof m₁ × R ∈AP mbr-proof m₂ × R ∈AP a₁₂) findR {s₁ = s₁} {tgt = tgt} a₁₁ a₁₂ a₂₁ m₁ m₂ i₁≤t t≤s₁ s₁≤s₂ with <-cmp tgt s₁ ...| tri> _ _ s₁<t = ⊥-elim (<⇒≢ s₁<t (sym (≤-antisym t≤s₁ (≤-unstep s₁<t)))) ...| tri≈ _ refl _ = s₁ , ∈AP-src , ∈AP-tgt , ∈AP-src ...| tri< t<s₁ _ _ = first-aft a₁₂ (≤⇒≤′ i₁≤t) t<s₁ , lemma5' a₁₂ (≤⇒≤′ i₁≤t) t<s₁ (mbr-proof m₁) ≤-refl , lemma5' a₁₂ (≤⇒≤′ i₁≤t) t<s₁ (mbr-proof m₂) s₁≤s₂ , first-aft-correct a₁₂ (≤⇒≤′ i₁≤t) t<s₁ -- check Figure 4 (page 12) in: https://arxiv.org/pdf/cs/0302010.pdf -- -- a₁ is dashed black line -- a₂ is dashed gray line -- m₁ is thick black line -- m₂ is thick gray line -- s₁ is j -- s₂ is k -- j is n -- tgt is i evo-cr : ∀{j i₁ i₂}{t₁ t₂ : View} → (a₁ : AdvPath j i₁) → (a₂ : AdvPath j i₂) → rebuild a₁ t₁ j ≡ rebuild a₂ t₂ j → ∀{s₁ s₂ tgt}{u₁ u₂ : View} → (m₁ : MembershipProof s₁ tgt)(m₂ : MembershipProof s₂ tgt) → s₁ ∈AP a₁ → s₂ ∈AP a₂ → tgt ≢ 0 → tgt ≤ s₁ → s₁ ≤ s₂ -- wlog → i₁ ≤ tgt → i₂ ≤ tgt → rebuildMP m₁ u₁ s₁ ≡ rebuild a₁ t₁ s₁ → rebuildMP m₂ u₂ s₂ ≡ rebuild a₂ t₂ s₂ → HashBroke ⊎ (mbr-datum m₁ ≡ mbr-datum m₂) evo-cr {t₁ = t₁} {t₂} a₁ a₂ hyp {s₁} {s₂} {tgt} {u₁} {u₂} m₁ m₂ s₁∈a₁ s₂∈a₂ t≢0 t≤s₁ s₁≤s₂ i₁≤t i₂≤t c₁ c₂ with ∈AP-cut a₁ s₁∈a₁ | ∈AP-cut a₂ s₂∈a₂ ...| ((a₁₁ , a₁₂) , refl) | ((a₂₁ , a₂₂) , refl) -- The first part of the proof is find some points common to three -- of the provided proofs. This is given in Figure 4 of Maniatis and Baker, -- and they are called M and R too, to help make it at least a little clear. -- First we find a point that belongs in a₂, m₁ and a₁. with findM a₁₁ a₂₁ a₂₂ m₂ (≤-trans i₂≤t t≤s₁) t≤s₁ s₁≤s₂ ...| M , M∈a₂₂ , M∈m₂ , M∈a₁₁ -- Next, we find a point that belongs in m₁, m₂ and a₁. with findR a₁₁ a₁₂ a₂₁ m₁ m₂ i₁≤t t≤s₁ s₁≤s₂ ...| R , R∈m₁ , R∈m₂ , R∈a₁₂ -- Now, since a₁ and a₂ rebuild to the same hash and M belongs -- to both these proofs, the hash for M is the same. with AgreeOnCommon a₁ a₂ hyp (∈AP-⊕-intro-l M∈a₁₁) (∈AP-⊕-intro-r M∈a₂₂) ...| inj₁ hb = inj₁ hb ...| inj₂ M-a1a2 -- Similarly, for a₂₂ and m₂ with AgreeOnCommon a₂₂ (mbr-proof m₂) (trans (sym (rebuild-⊕' a₂₁ a₂₂ ∈AP-src)) (sym c₂)) M∈a₂₂ M∈m₂ ...| inj₁ hb = inj₁ hb ...| inj₂ M-a2m2 -- Which brings us to: rebuild a1 M == rebuild m2 M with trans (trans M-a1a2 (rebuild-⊕' a₂₁ a₂₂ M∈a₂₂)) M-a2m2 ...| M-a1m2 -- Well, if a1 and m2 agree on one point, they agree on all points. In particular, they -- agree on R! with ∈AP-cut (mbr-proof m₂) M∈m₂ ...| ((m₂₁ , m₂₂) , refl) with AgreeOnCommon-∈ a₁ m₂₂ (∈AP-⊕-intro-l M∈a₁₁) (trans M-a1m2 (rebuild-⊕' m₂₁ m₂₂ ∈AP-src)) (∈AP-⊕-intro-r R∈a₁₂) (∈AP-⊕-≤-r R∈m₂ (≤-trans (∈AP-≤ R∈a₁₂) (∈AP-≥ M∈a₁₁))) ...| inj₁ hb = inj₁ hb ...| inj₂ R-a1m2 -- Which finally lets us argue that m1 and m2 also agree on R. Similarly, if they agree -- on one point they agree on all points. with AgreeOnCommon a₁₂ (mbr-proof m₁) (trans (sym (rebuild-⊕' a₁₁ a₁₂ ∈AP-src)) (sym c₁)) R∈a₁₂ R∈m₁ ...| inj₁ hb = inj₁ hb ...| inj₂ R-a1m1 with trans (trans (sym R-a1m2) (rebuild-⊕' a₁₁ a₁₂ R∈a₁₂)) R-a1m1 ...| R-m1m2 with ∈AP-cut (mbr-proof m₁) R∈m₁ ...| ((m₁₁ , m₁₂) , refl) with AgreeOnCommon-∈ m₂₂ m₁₂ (∈AP-⊕-≤-r R∈m₂ (≤-trans (∈AP-≤ R∈a₁₂) (∈AP-≥ M∈a₁₁))) (trans R-m1m2 (rebuild-⊕' m₁₁ m₁₂ ∈AP-src)) ∈AP-tgt ∈AP-tgt ...| inj₁ hb = inj₁ hb ...| inj₂ res with trans (rebuild-⊕' m₂₁ m₂₂ ∈AP-tgt) (trans res (sym (rebuild-⊕' m₁₁ m₁₂ ∈AP-tgt))) ...| half with rebuild-tgt-lemma (mbr-proof m₁) {u₁ ∪₁ (tgt , auth tgt (mbr-datum m₁) u₁) } | rebuild-tgt-lemma (mbr-proof m₂) {u₂ ∪₁ (tgt , auth tgt (mbr-datum m₂) u₂) } ...| l1 | l2 rewrite ≟ℕ-refl tgt = auth-inj-1 {tgt} {mbr-datum m₁} {mbr-datum m₂} t≢0 (trans (sym l1) (trans (sym half) l2))
42.842809
120
0.538173
23483e43f042e0eacbb52a09434ed8f56af264f9
496
agda
Agda
OldBasicILP/UntypedSyntax/Common.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
OldBasicILP/UntypedSyntax/Common.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
OldBasicILP/UntypedSyntax/Common.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
module OldBasicILP.UntypedSyntax.Common where open import Common.UntypedContext public -- Types parametrised by closed, untyped representations. module ClosedSyntax (Proof : Set) where infixr 10 _⦂_ infixl 9 _∧_ infixr 7 _▻_ data Ty : Set where α_ : Atom → Ty _▻_ : Ty → Ty → Ty _⦂_ : Proof → Ty → Ty _∧_ : Ty → Ty → Ty ⊤ : Ty -- Additional useful types. infixr 7 _▻⋯▻_ _▻⋯▻_ : Cx Ty → Ty → Ty ∅ ▻⋯▻ B = B (Ξ , A) ▻⋯▻ B = Ξ ▻⋯▻ (A ▻ B)
17.103448
57
0.568548
0e343ce91bc791b4124b14d5387bf9fa950ea7a1
98
agda
Agda
test/Succeed/Issue2487-2.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2487-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2487-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --cubical --prop --rewriting #-} module Issue2487-2 where import Issue2487.Infective
19.6
44
0.734694
18603056edff953c9d869f2dbcc7c5602f837935
2,239
agda
Agda
test/Common/IO.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/Common/IO.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/Common/IO.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
module Common.IO where open import Agda.Builtin.IO public open import Common.Bool open import Common.Char open import Common.Nat open import Common.String open import Common.Unit open import Common.Float infixl 1 _>>=_ postulate return : ∀ {a} {A : Set a} → A → IO A _>>=_ : ∀ {a b} {A : Set a} {B : Set b} → IO A → (A → IO B) → IO B {-# COMPILED return (\_ _ -> return) #-} {-# COMPILED _>>=_ (\_ _ _ _ -> (>>=)) #-} {-# COMPILED_EPIC return (u1 : Unit, a : Any) -> Any = ioreturn(a) #-} {-# COMPILED_EPIC _>>=_ (u1 : Unit, u2 : Unit, x : Any, f : Any) -> Any = iobind(x,f) #-} {-# COMPILED_UHC return (\_ _ x -> UHC.Agda.Builtins.primReturn x) #-} {-# COMPILED_UHC _>>=_ (\_ _ _ _ x y -> UHC.Agda.Builtins.primBind x y) #-} {-# COMPILED_JS return function(u0) { return function(u1) { return function(x) { return function(cb) { cb(x); }; }; }; } #-} {-# COMPILED_JS _>>=_ function(u0) { return function(u1) { return function(u2) { return function(u3) { return function(x) { return function(y) { return function(cb) { x(function (xx) { y(xx)(cb); }); }; }; }; }; }; }; } #-} {-# IMPORT Data.Text.IO #-} postulate putStr : String -> IO Unit {-# COMPILED putStr Data.Text.IO.putStr #-} {-# COMPILED_EPIC putStr (a : String, u : Unit) -> Unit = foreign Int "wputStr" (a : String); primUnit #-} {-# COMPILED_UHC putStr (UHC.Agda.Builtins.primPutStr) #-} {-# COMPILED_JS putStr function (x) { return function(cb) { process.stdout.write(x); cb(0); }; } #-} printChar : Char -> IO Unit printChar c = putStr (charToStr c) putStrLn : String -> IO Unit putStrLn s = putStr s >>= \_ -> putStr "\n" printNat : Nat -> IO Unit printNat n = putStr (natToString n) printBool : Bool -> IO Unit printBool true = putStr "true" printBool false = putStr "false" printFloat : Float -> IO Unit printFloat f = putStr (floatToString f) infixr 2 _<$>_ _<$>_ : {A B : Set}(f : A -> B)(m : IO A) -> IO B f <$> x = x >>= λ y -> return (f y) infixr 0 bind bind : ∀ {a b} {A : Set a} {B : Set b} → IO A → (A → IO B) → IO B bind m f = m >>= f infixr 0 then then : ∀ {a b} {A : Set a} {B : Set b} -> IO A -> IO B -> IO B then m f = m >>= λ _ -> f syntax bind e (\ x -> f) = x <- e , f syntax then e f = e ,, f
29.853333
106
0.585976
1808726baadc36c3ab84d5d3b9370d8208f6f27c
10,151
agda
Agda
agda-stdlib-0.9/src/Data/Bin.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/Bin.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Bin.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- A binary representation of natural numbers ------------------------------------------------------------------------ module Data.Bin where open import Data.Nat as Nat using (ℕ; zero; z≤n; s≤s) renaming (suc to 1+_) open Nat.≤-Reasoning import Data.Nat.Properties as NP open import Data.Digit open import Data.Fin as Fin using (Fin; zero) renaming (suc to 1+_) open import Data.Fin.Properties as FP using (_+′_) open import Data.List as List hiding (downFrom) open import Function open import Data.Product open import Algebra open import Relation.Binary open import Relation.Binary.Consequences open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; _≢_; refl; sym) open import Relation.Nullary private module BitOrd = StrictTotalOrder (FP.strictTotalOrder 2) ------------------------------------------------------------------------ -- The type -- A representation of binary natural numbers in which there is -- exactly one representative for every number. -- The function toℕ below defines the meaning of Bin. infix 8 _1# -- bs stands for the binary number 1<reverse bs>, which is positive. Bin⁺ : Set Bin⁺ = List Bit data Bin : Set where -- Zero. 0# : Bin -- bs 1# stands for the binary number 1<reverse bs>. _1# : (bs : Bin⁺) → Bin ------------------------------------------------------------------------ -- Conversion functions -- Converting to a list of bits starting with the _least_ significant -- one. toBits : Bin → List Bit toBits 0# = [ 0b ] toBits (bs 1#) = bs ++ [ 1b ] -- Converting to a natural number. toℕ : Bin → ℕ toℕ = fromDigits ∘ toBits -- Converting from a list of bits, starting with the _least_ -- significant one. fromBits : List Bit → Bin fromBits [] = 0# fromBits (b ∷ bs) with fromBits bs fromBits (b ∷ bs) | bs′ 1# = (b ∷ bs′) 1# fromBits (zero ∷ bs) | 0# = 0# fromBits (1+ zero ∷ bs) | 0# = [] 1# fromBits (1+ 1+ () ∷ bs) | _ -- Converting from a natural number. fromℕ : ℕ → Bin fromℕ n = fromBits $ proj₁ $ toDigits 2 n ------------------------------------------------------------------------ -- (Bin, _≡_, _<_) is a strict total order infix 4 _<_ -- Order relation. Wrapped so that the parameters can be inferred. data _<_ (b₁ b₂ : Bin) : Set where less : (lt : (Nat._<_ on toℕ) b₁ b₂) → b₁ < b₂ private <-trans : Transitive _<_ <-trans (less lt₁) (less lt₂) = less (NP.<-trans lt₁ lt₂) asym : ∀ {b₁ b₂} → b₁ < b₂ → ¬ b₂ < b₁ asym {b₁} {b₂} (less lt) (less gt) = tri⟶asym cmp lt gt where cmp = StrictTotalOrder.compare NP.strictTotalOrder irr : ∀ {b₁ b₂} → b₁ < b₂ → b₁ ≢ b₂ irr lt eq = asym⟶irr (PropEq.resp₂ _<_) sym asym eq lt irr′ : ∀ {b} → ¬ b < b irr′ lt = irr lt refl ∷∙ : ∀ {b₁ b₂ bs₁ bs₂} → bs₁ 1# < bs₂ 1# → (b₁ ∷ bs₁) 1# < (b₂ ∷ bs₂) 1# ∷∙ {b₁} {b₂} {bs₁} {bs₂} (less lt) = less (begin 1 + (m₁ + n₁ * 2) ≤⟨ ≤-refl {x = 1} +-mono (≤-pred (FP.bounded b₁) +-mono ≤-refl) ⟩ 1 + (1 + n₁ * 2) ≡⟨ refl ⟩ suc n₁ * 2 ≤⟨ lt *-mono ≤-refl ⟩ n₂ * 2 ≤⟨ n≤m+n m₂ (n₂ * 2) ⟩ m₂ + n₂ * 2 ∎ ) where open Nat; open NP open DecTotalOrder decTotalOrder renaming (refl to ≤-refl) m₁ = Fin.toℕ b₁; m₂ = Fin.toℕ b₂ n₁ = toℕ (bs₁ 1#); n₂ = toℕ (bs₂ 1#) ∙∷ : ∀ {b₁ b₂ bs} → Fin._<_ b₁ b₂ → (b₁ ∷ bs) 1# < (b₂ ∷ bs) 1# ∙∷ {b₁} {b₂} {bs} lt = less (begin 1 + (m₁ + n * 2) ≡⟨ sym (+-assoc 1 m₁ (n * 2)) ⟩ (1 + m₁) + n * 2 ≤⟨ lt +-mono ≤-refl ⟩ m₂ + n * 2 ∎) where open Nat; open NP open DecTotalOrder decTotalOrder renaming (refl to ≤-refl) open CommutativeSemiring commutativeSemiring using (+-assoc) m₁ = Fin.toℕ b₁; m₂ = Fin.toℕ b₂; n = toℕ (bs 1#) 1<[23] : ∀ {b} → [] 1# < (b ∷ []) 1# 1<[23] {b} = less (NP.n≤m+n (Fin.toℕ b) 2) 1<2+ : ∀ {bs b} → [] 1# < (b ∷ bs) 1# 1<2+ {[]} = 1<[23] 1<2+ {b ∷ bs} = <-trans 1<[23] (∷∙ {b₁ = b} (1<2+ {bs})) 0<1 : 0# < [] 1# 0<1 = less (s≤s z≤n) 0<+ : ∀ {bs} → 0# < bs 1# 0<+ {[]} = 0<1 0<+ {b ∷ bs} = <-trans 0<1 1<2+ compare⁺ : Trichotomous (_≡_ on _1#) (_<_ on _1#) compare⁺ [] [] = tri≈ irr′ refl irr′ compare⁺ [] (b ∷ bs) = tri< 1<2+ (irr 1<2+) (asym 1<2+) compare⁺ (b ∷ bs) [] = tri> (asym 1<2+) (irr 1<2+ ∘ sym) 1<2+ compare⁺ (b₁ ∷ bs₁) (b₂ ∷ bs₂) with compare⁺ bs₁ bs₂ ... | tri< lt ¬eq ¬gt = tri< (∷∙ lt) (irr (∷∙ lt)) (asym (∷∙ lt)) ... | tri> ¬lt ¬eq gt = tri> (asym (∷∙ gt)) (irr (∷∙ gt) ∘ sym) (∷∙ gt) compare⁺ (b₁ ∷ bs) (b₂ ∷ .bs) | tri≈ ¬lt refl ¬gt with BitOrd.compare b₁ b₂ compare⁺ (b ∷ bs) (.b ∷ .bs) | tri≈ ¬lt refl ¬gt | tri≈ ¬lt′ refl ¬gt′ = tri≈ irr′ refl irr′ ... | tri< lt′ ¬eq ¬gt′ = tri< (∙∷ lt′) (irr (∙∷ lt′)) (asym (∙∷ lt′)) ... | tri> ¬lt′ ¬eq gt′ = tri> (asym (∙∷ gt′)) (irr (∙∷ gt′) ∘ sym) (∙∷ gt′) compare : Trichotomous _≡_ _<_ compare 0# 0# = tri≈ irr′ refl irr′ compare 0# (bs₂ 1#) = tri< 0<+ (irr 0<+) (asym 0<+) compare (bs₁ 1#) 0# = tri> (asym 0<+) (irr 0<+ ∘ sym) 0<+ compare (bs₁ 1#) (bs₂ 1#) = compare⁺ bs₁ bs₂ strictTotalOrder : StrictTotalOrder _ _ _ strictTotalOrder = record { Carrier = Bin ; _≈_ = _≡_ ; _<_ = _<_ ; isStrictTotalOrder = record { isEquivalence = PropEq.isEquivalence ; trans = <-trans ; compare = compare ; <-resp-≈ = PropEq.resp₂ _<_ } } ------------------------------------------------------------------------ -- (Bin, _≡_) is a decidable setoid decSetoid : DecSetoid _ _ decSetoid = StrictTotalOrder.decSetoid strictTotalOrder infix 4 _≟_ _≟_ : Decidable {A = Bin} _≡_ _≟_ = DecSetoid._≟_ decSetoid ------------------------------------------------------------------------ -- Arithmetic -- Power of two. infixr 8 2^_ 2^_ : ℕ → Bin⁺ 2^ 0 = [] 2^ 1+ n = 0b ∷ 2^ n -- Base 2 logarithm (rounded downwards). ⌊log₂_⌋ : Bin⁺ → ℕ ⌊log₂ (b ∷ bs) ⌋ = 1+ ⌊log₂ bs ⌋ ⌊log₂ [] ⌋ = 0 -- Multiplication by 2. infix 7 _*2 _*2+1 _*2 : Bin → Bin 0# *2 = 0# (bs 1#) *2 = (0b ∷ bs) 1# _*2+1 : Bin → Bin 0# *2+1 = [] 1# (bs 1#) *2+1 = (1b ∷ bs) 1# -- Division by 2, rounded downwards. ⌊_/2⌋ : Bin → Bin ⌊ 0# /2⌋ = 0# ⌊ [] 1# /2⌋ = 0# ⌊ (b ∷ bs) 1# /2⌋ = bs 1# -- Addition. Carry : Set Carry = Bit addBits : Carry → Bit → Bit → Carry × Bit addBits c b₁ b₂ with c +′ (b₁ +′ b₂) ... | zero = (0b , 0b) ... | 1+ zero = (0b , 1b) ... | 1+ 1+ zero = (1b , 0b) ... | 1+ 1+ 1+ zero = (1b , 1b) ... | 1+ 1+ 1+ 1+ () addCarryToBitList : Carry → List Bit → List Bit addCarryToBitList zero bs = bs addCarryToBitList (1+ zero) [] = 1b ∷ [] addCarryToBitList (1+ zero) (zero ∷ bs) = 1b ∷ bs addCarryToBitList (1+ zero) (1+ zero ∷ bs) = 0b ∷ addCarryToBitList 1b bs addCarryToBitList (1+ 1+ ()) _ addCarryToBitList _ ((1+ 1+ ()) ∷ _) addBitLists : Carry → List Bit → List Bit → List Bit addBitLists c [] bs₂ = addCarryToBitList c bs₂ addBitLists c bs₁ [] = addCarryToBitList c bs₁ addBitLists c (b₁ ∷ bs₁) (b₂ ∷ bs₂) with addBits c b₁ b₂ ... | (c' , b') = b' ∷ addBitLists c' bs₁ bs₂ infixl 6 _+_ _+_ : Bin → Bin → Bin m + n = fromBits (addBitLists 0b (toBits m) (toBits n)) -- Multiplication. infixl 7 _*_ _*_ : Bin → Bin → Bin 0# * n = 0# [] 1# * n = n -- (b + 2 * bs 1#) * n = b * n + 2 * (bs 1# * n) (b ∷ bs) 1# * n with bs 1# * n (b ∷ bs) 1# * n | 0# = 0# (zero ∷ bs) 1# * n | bs' 1# = (0b ∷ bs') 1# (1+ zero ∷ bs) 1# * n | bs' 1# = n + (0b ∷ bs') 1# ((1+ 1+ ()) ∷ _) 1# * _ | _ -- Successor. suc : Bin → Bin suc n = [] 1# + n -- Division by 2, rounded upwards. ⌈_/2⌉ : Bin → Bin ⌈ n /2⌉ = ⌊ suc n /2⌋ -- Predecessor. pred : Bin⁺ → Bin pred [] = 0# pred (zero ∷ bs) = pred bs *2+1 pred (1+ zero ∷ bs) = (zero ∷ bs) 1# pred (1+ 1+ () ∷ bs) -- downFrom n enumerates all numbers from n - 1 to 0. This function is -- linear in n. Analysis: fromℕ takes linear time, and the preds used -- take amortised constant time (to see this, let the cost of a pred -- be 2, and put 1 debit on every bit which is 1). downFrom : ℕ → List Bin downFrom n = helper n (fromℕ n) where helper : ℕ → Bin → List Bin helper zero 0# = [] helper (1+ n) (bs 1#) = n′ ∷ helper n n′ where n′ = pred bs -- Impossible cases: helper zero (_ 1#) = [] helper (1+ _) 0# = [] ------------------------------------------------------------------------ -- Tests -- The tests below have been commented out since (at least one version -- of) Agda is too slow or memory-hungry to type check them. {- -- The tests below are run when this module is type checked. -- First some test helpers: private testLimit : ℕ testLimit = 5 nats : List ℕ nats = List.downFrom testLimit nats⁺ : List ℕ nats⁺ = filter (λ n → decToBool (Nat._≤?_ 1 n)) nats natPairs : List (ℕ × ℕ) natPairs = zip nats (reverse nats) _=[_]_ : (ℕ → ℕ) → List ℕ → (Bin → Bin) → Set f =[ ns ] g = map f ns ≡ map (toℕ ∘ g ∘ fromℕ) ns _=[_]₂_ : (ℕ → ℕ → ℕ) → List (ℕ × ℕ) → (Bin → Bin → Bin) → Set f =[ ps ]₂ g = map (uncurry f) ps ≡ map (toℕ ∘ uncurry (g on fromℕ)) ps -- And then the tests: private test-*2+1 : (λ n → Nat._+_ (Nat._*_ n 2) 1) =[ nats ] _*2+1 test-*2+1 = refl test-*2 : (λ n → Nat._*_ n 2) =[ nats ] _*2 test-*2 = refl test-⌊_/2⌋ : Nat.⌊_/2⌋ =[ nats ] ⌊_/2⌋ test-⌊_/2⌋ = refl test-+ : Nat._+_ =[ natPairs ]₂ _+_ test-+ = refl test-* : Nat._*_ =[ natPairs ]₂ _*_ test-* = refl test-suc : 1+_ =[ nats ] suc test-suc = refl test-⌈_/2⌉ : Nat.⌈_/2⌉ =[ nats ] ⌈_/2⌉ test-⌈_/2⌉ = refl drop-1# : Bin → Bin⁺ drop-1# 0# = [] drop-1# (bs 1#) = bs test-pred : Nat.pred =[ nats⁺ ] (pred ∘ drop-1#) test-pred = refl test-downFrom : map toℕ (downFrom testLimit) ≡ List.downFrom testLimit test-downFrom = refl -}
27.214477
80
0.503103
d0a78cd19bbae1904734021270341ea54971243a
689
agda
Agda
Numbers/Integers/RingStructure/IntegralDomain.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Numbers/Integers/RingStructure/IntegralDomain.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Numbers/Integers/RingStructure/IntegralDomain.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Integers.RingStructure.Ring open import Rings.IntegralDomains.Definition module Numbers.Integers.RingStructure.IntegralDomain where intDom : (a b : ℤ) → a *Z b ≡ nonneg 0 → (a ≡ nonneg 0 → False) → (b ≡ nonneg 0) intDom (nonneg zero) (nonneg b) x a!=0 = exFalso (a!=0 x) intDom (nonneg (succ a)) (nonneg zero) a!=0 _ = refl intDom (nonneg zero) (negSucc b) pr a!=0 = exFalso (a!=0 pr) intDom (negSucc a) (nonneg zero) _ _ = refl ℤIntDom : IntegralDomain ℤRing IntegralDomain.intDom ℤIntDom {a} {b} = intDom a b IntegralDomain.nontrivial ℤIntDom ()
36.263158
80
0.721335
062d0984c607752277fb5691986ede0c5e0a9de3
6,197
agda
Agda
core/lib/types/Choice.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
core/lib/types/Choice.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
core/lib/types/Choice.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.types.Coproduct open import lib.types.Fin open import lib.types.Pi open import lib.types.Truncation module lib.types.Choice where unchoose : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : A → Type j} → Trunc n (Π A B) → Π A (Trunc n ∘ B) unchoose = Trunc-rec (λ f → [_] ∘ f) has-choice : ∀ {i} (n : ℕ₋₂) (A : Type i) j → Type (lmax i (lsucc j)) has-choice {i} n A j = (B : A → Type j) → is-equiv (unchoose {n = n} {A} {B}) Empty-has-choice : ∀ {n} {j} → has-choice n Empty j Empty-has-choice {n} B = is-eq to from to-from from-to where to = unchoose {n = n} {Empty} {B} from : Π Empty (Trunc n ∘ B) → Trunc n (Π Empty B) from _ = [ (λ{()}) ] abstract to-from : ∀ f → to (from f) == f to-from _ = λ= λ{()} from-to : ∀ f → from (to f) == f from-to = Trunc-elim (λ _ → ap [_] (λ= λ{()})) Unit-has-choice : ∀ {n} {j} → has-choice n Unit j Unit-has-choice {n} B = is-eq to from to-from from-to where to = unchoose {n = n} {Unit} {B} Unit-elim' : B unit → Π Unit B Unit-elim' u unit = u from : Π Unit (Trunc n ∘ B) → Trunc n (Π Unit B) from f = Trunc-fmap Unit-elim' (f unit) abstract to-from : ∀ f → to (from f) == f to-from f = λ= λ{unit → Trunc-elim {P = λ f-unit → to (Trunc-fmap Unit-elim' f-unit) unit == f-unit} (λ _ → idp) (f unit)} from-to : ∀ f → from (to f) == f from-to = Trunc-elim (λ f → ap [_] (λ= λ{unit → idp})) Coprod-has-choice : ∀ {i j} {n} {A : Type i} {B : Type j} {k} → has-choice n A k → has-choice n B k → has-choice n (A ⊔ B) k Coprod-has-choice {n = n} {A} {B} A-hc B-hc C = is-eq to from to-from from-to where A-unchoose = unchoose {n = n} {A} {C ∘ inl} B-unchoose = unchoose {n = n} {B} {C ∘ inr} module A-unchoose = is-equiv (A-hc (C ∘ inl)) module B-unchoose = is-equiv (B-hc (C ∘ inr)) to = unchoose {n = n} {A ⊔ B} {C} from : Π (A ⊔ B) (Trunc n ∘ C) → Trunc n (Π (A ⊔ B) C) from f = Trunc-fmap2 Coprod-elim (A-unchoose.g (f ∘ inl)) (B-unchoose.g (f ∘ inr)) abstract to-from-inl' : ∀ f a → to (from f) (inl a) == A-unchoose (A-unchoose.g (f ∘ inl)) a to-from-inl' f a = Trunc-elim {P = λ f-inl → to (Trunc-fmap2 Coprod-elim f-inl (B-unchoose.g (f ∘ inr))) (inl a) == A-unchoose f-inl a} (λ f-inl → Trunc-elim {P = λ f-inr → to (Trunc-fmap2 Coprod-elim [ f-inl ] f-inr) (inl a) == [ f-inl a ]} (λ f-inr → idp) (B-unchoose.g (f ∘ inr))) (A-unchoose.g (f ∘ inl)) to-from-inl : ∀ f a → to (from f) (inl a) == f (inl a) to-from-inl f a = to-from-inl' f a ∙ app= (A-unchoose.f-g (f ∘ inl)) a to-from-inr' : ∀ f b → to (from f) (inr b) == B-unchoose (B-unchoose.g (f ∘ inr)) b to-from-inr' f b = Trunc-elim {P = λ f-inr → to (Trunc-fmap2 Coprod-elim (A-unchoose.g (f ∘ inl)) f-inr) (inr b) == B-unchoose f-inr b} (λ f-inr → Trunc-elim {P = λ f-inl → to (Trunc-fmap2 Coprod-elim f-inl [ f-inr ]) (inr b) == [ f-inr b ]} (λ f-inl → idp) (A-unchoose.g (f ∘ inl))) (B-unchoose.g (f ∘ inr)) to-from-inr : ∀ f b → to (from f) (inr b) == f (inr b) to-from-inr f b = to-from-inr' f b ∙ app= (B-unchoose.f-g (f ∘ inr)) b to-from : ∀ f → to (from f) == f to-from f = λ= λ{(inl a) → to-from-inl f a; (inr b) → to-from-inr f b} from-to : ∀ f → from (to f) == f from-to = Trunc-elim (λ f → Trunc-fmap2 Coprod-elim (A-unchoose.g (λ a → [ f (inl a)])) (B-unchoose.g (λ b → [ f (inr b)])) =⟨ ap2 (Trunc-fmap2 Coprod-elim) (A-unchoose.g-f [ f ∘ inl ]) (B-unchoose.g-f [ f ∘ inr ]) ⟩ [ Coprod-elim (f ∘ inl) (f ∘ inr) ] =⟨ ap [_] $ λ= (λ{(inl _) → idp; (inr _) → idp}) ⟩ [ f ] =∎) equiv-preserves-choice : ∀ {i j} {n} {A : Type i} {B : Type j} (e : A ≃ B) {k} → has-choice n A k → has-choice n B k equiv-preserves-choice {n = n} {A} {B} (f , f-ise) A-hc C = is-eq to from to-from from-to where module f = is-equiv f-ise A-unchoose = unchoose {n = n} {A} {C ∘ f} module A-unchoose = is-equiv (A-hc (C ∘ f)) to = unchoose {n = n} {B} {C} from' : Trunc n (Π A (C ∘ f)) → Trunc n (Π B C) from' = Trunc-fmap (λ g' b → transport C (f.f-g b) (g' (f.g b))) from : Π B (Trunc n ∘ C) → Trunc n (Π B C) from g = from' (A-unchoose.g (g ∘ f)) abstract to-from''' : ∀ (g-f' : Π A (C ∘ f)) {a a'} (path : f.g (f a) == a') → transport C (ap f path) (g-f' (f.g (f a))) == g-f' a' to-from''' g-f' idp = idp to-from'' : ∀ (g-f' : Π A (C ∘ f)) a → transport C (f.f-g (f a)) (g-f' (f.g (f a))) == g-f' a to-from'' g-f' a = transport C (f.f-g (f a)) (g-f' (f.g (f a))) =⟨ ! $ ap (λ p → transport C p (g-f' (f.g (f a)))) (f.adj a) ⟩ transport C (ap f (f.g-f a)) (g-f' (f.g (f a))) =⟨ to-from''' g-f' (f.g-f a) ⟩ g-f' a =∎ to-from' : ∀ g a → to (from g) (f a) == A-unchoose (A-unchoose.g (g ∘ f)) a to-from' g a = Trunc-elim {P = λ g-f → to (from' g-f) (f a) == A-unchoose g-f a} (λ g-f' → ap [_] $ to-from'' g-f' a) (A-unchoose.g (g ∘ f)) to-from : ∀ g → to (from g) == g to-from g = λ= λ b → transport (λ b → to (from g) b == g b) (f.f-g b) ( to (from g) (f (f.g b)) =⟨ to-from' g (f.g b) ⟩ A-unchoose (A-unchoose.g (g ∘ f)) (f.g b) =⟨ app= (A-unchoose.f-g (g ∘ f)) (f.g b) ⟩ g (f (f.g b)) =∎) from-to' : ∀ g {b b'} (path : f (f.g b) == b') → transport C path (g (f (f.g b))) == g b' from-to' g idp = idp from-to : ∀ g → from (to g) == g from-to = Trunc-elim {P = λ g → from (to g) == g} (λ g → from' (A-unchoose.g (λ a → [ g (f a) ])) =⟨ ap from' (A-unchoose.g-f [ (g ∘ f) ]) ⟩ from' [ (g ∘ f) ] =⟨ ap [_] $ λ= (λ b → from-to' g (f.f-g b)) ⟩ [ g ] =∎) Fin-has-choice : ∀ (n : ℕ₋₂) {m} l → has-choice n (Fin m) l Fin-has-choice _ {O} _ = equiv-preserves-choice (Fin-equiv-Empty ⁻¹) Empty-has-choice Fin-has-choice n {S m} l = equiv-preserves-choice (Fin-equiv-Coprod ⁻¹) (Coprod-has-choice (Fin-has-choice n l) Unit-has-choice)
35.614943
111
0.490399
4df9ae47093d4905aac8766f384f17833a9bf6cf
4,928
agda
Agda
agda/Pi-reasoning.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
14
2015-08-18T21:40:15.000Z
2021-05-05T01:07:57.000Z
agda/Pi-reasoning.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
4
2018-06-07T16:27:41.000Z
2021-10-29T20:41:23.000Z
agda/Pi-reasoning.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
3
2016-05-29T01:56:33.000Z
2019-09-10T09:47:13.000Z
{-# OPTIONS --no-termination-check #-} module Pi-reasoning where open import Data.Empty open import Data.Unit hiding (_≟_) open import Data.Bool hiding (_≟_) open import Data.Nat open import Data.List open import Data.Sum hiding (map) open import Data.Product hiding (map) open import Level hiding (suc) open import Relation.Nullary open import Relation.Binary open import Algebra open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Relation.Binary.PropositionalEquality as PropEq using(sym; trans) import Algebra.FunctionProperties as FunctionProperties -- open import Algebra.FunctionProperties open import Algebra.Structures open import Pi-abstract-machine ------------------------------------------------------------------------------ -- Decidable equality -- normalize a type to a natural number size : B → ℕ size ZERO = 0 size ONE = 1 size (PLUS b₁ b₂) = size b₁ + size b₂ size (TIMES b₁ b₂) = size b₁ * size b₂ -- normalize a value to a number normalize : {b : B} → VB b → ℕ normalize {ZERO} () normalize {ONE} unitB = 0 normalize {PLUS b₁ b₂} (inlB v) = normalize {b₁} v normalize {PLUS b₁ b₂} (inrB v) = size b₁ + normalize {b₂} v normalize {TIMES b₁ b₂} (pairB v₁ v₂) = size b₂ * normalize {b₁} v₁ + normalize {b₂} v₂ -- decidable equality of our values: normalize and compare the -- underlying natural numbers. This is justified by the fact that the -- natural numbers are a model of commutative semirings. -- Note that we can't compare at different types so easily, they have -- to have the same size, something not worth dealing with right now vb= : {b : B} → (v₁ : VB b) → (v₂ : VB b) → Set vb= {b} v₁ v₂ = (normalize {b} v₁) ≡ (normalize {b} v₂) vb-Equivalence : {b : B} → IsEquivalence (vb= {b}) vb-Equivalence = record { refl = refl ; sym = PropEq.sym ; trans = PropEq.trans } vb== : {b : B} → Decidable {A = VB b} vb= vb== {b} x y = (normalize {b} x) ≟ (normalize {b} y) -- generate all values of a type values : (b : B) → List (VB b) values ZERO = [] values ONE = [ unitB ] values (PLUS b₁ b₂) = map inlB (values b₁) ++ map inrB (values b₂) values (TIMES b₁ b₂) = concatMap (λ v₁ → map (pairB v₁) (values b₂)) (values b₁) -- B is a Setoid VB-is-Setoid : {b : B} → Setoid Level.zero Level.zero VB-is-Setoid {b} = record { Carrier = VB b ; _≈_ = vb= ; isEquivalence = vb-Equivalence } -- equality of combinators: -- two combinators are equal if they map equal values to equal values -- best do this via proving that vb= generates a decidable equivalence {- ⟺=bool : {b₁ b₂ : B} → (b₁ ⟺ b₂) → (b₁ ⟺ b₂) → Bool ⟺=bool {b₁} {b₂} f g = and (zipWith vb= (map (eval f) vs) (map (eval g) vs)) where vs = values b₁ data _⟺=_ : {b₁ b₂ : B} → (b₁ ⟺ b₂) → (b₁ ⟺ b₂) → Set where id⟺= : {b₁ b₂ : B} → (f : b₁ ⟺ b₂) → (f ⟺= f) sym⟺= : {b₁ b₂ : B} → (f : b₁ ⟺ b₂) → (g : b₁ ⟺ b₂) → ( f ⟺= g ) → (g ⟺= f) -- verifies that the given combinators relates the given values data _s⟷_ : B → B → Set where sid⟷ : {b : B} {v₁ : VB b} {v₂ : VB b} {p : T (vb= (eval (iso id⟷) v₁) v₂)} → (b s⟷ b) ⟺=IsEquivalence : IsEquivalence _s⟷_ ⟺=IsEquivalence = record { refl = srefl ; sym = {!!} ; trans = {!!} } where srefl : {b : B} {v : VB b} → b s⟷ b srefl {b} {v} = sid⟷ {b} {v} {v} {{!!}} -- <-> : B -> B -> Set with constructors id : {b : B} -> (b <-> b) -- IsEquivalence <-> -- refl = id -- R= : B -> B -> Set with constructos -} ------------------------------------------------------------------------------ {-- testT = PLUS ONE (PLUS ONE ONE) test1 = normalize {testT} (inlB unitB) test2 = normalize {testT} (inrB (inlB unitB)) test3 = normalize {testT} (inrB (inrB unitB)) testT = PLUS ZERO (PLUS ONE ONE) test1 = normalize {testT} (inrB (inlB unitB)) test2 = normalize {testT} (inrB (inrB unitB)) testT = TIMES (PLUS ONE ONE) ZERO test1 = size testT testT = TIMES (PLUS ONE ONE) (PLUS ONE (PLUS ONE ONE)) test1 = normalize {testT} (pairB (inlB unitB) (inlB unitB)) test2 = normalize {testT} (pairB (inrB unitB) (inlB unitB)) test3 = normalize {testT} (pairB (inlB unitB) (inrB (inlB unitB))) test4 = normalize {testT} (pairB (inrB unitB) (inrB (inlB unitB))) test5 = normalize {testT} (pairB (inlB unitB) (inrB (inrB unitB))) test6 = normalize {testT} (pairB (inrB unitB) (inrB (inrB unitB))) BOOL = PLUS ONE ONE test = ⟺= {BOOL} {BOOL} (iso swap₊ ◎ iso swap₊) (iso id⟷) test1 : (iso swap₊) ⟺= (iso swap₊) test1 = check {PLUS ONE ONE} {PLUS ONE ONE} (iso swap₊) (iso swap₊) tt The following does NOT typecheck which is good. Agda rejected my nonsense claim that id is equivalent to swap+ test2 : (iso swap₊) ⟺= (iso id⟷) test2 = check {PLUS ONE ONE} {PLUS ONE ONE} (iso swap₊) (iso id⟷) tt --}
31.793548
89
0.594156
10eeab109077a43d92186b88bde40d9a120b096a
401
agda
Agda
src/data/lib/prim/Agda/Builtin/Int.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
src/data/lib/prim/Agda/Builtin/Int.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
src/data/lib/prim/Agda/Builtin/Int.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --without-K #-} module Agda.Builtin.Int where open import Agda.Builtin.Nat open import Agda.Builtin.String infix 8 pos -- Standard library uses this as +_ data Int : Set where pos : (n : Nat) → Int negsuc : (n : Nat) → Int {-# BUILTIN INTEGER Int #-} {-# BUILTIN INTEGERPOS pos #-} {-# BUILTIN INTEGERNEGSUC negsuc #-} primitive primShowInteger : Int → String
21.105263
48
0.648379
500fdcdef7b5ace5354ce30c3b68a6b93a2c0469
2,229
agda
Agda
src/Data/Finitude/Properties.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
src/Data/Finitude/Properties.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
src/Data/Finitude/Properties.agda
tizmd/agda-finitary
abacd166f63582b7395d9cc10b6323c0f69649e5
[ "MIT" ]
null
null
null
module Data.Finitude.Properties where open import Data.Fin as Fin using (Fin; #_ ) open import Data.Fin.Properties hiding (decSetoid) open import Relation.Nullary open import Relation.Unary open import Relation.Binary renaming (Decidable to Dec₂) hiding (Irrelevant) open import Relation.Binary.PropositionalEquality as P hiding (decSetoid; isEquivalence) open import Data.Finitude open import Function.Equality as F using (_⟨$⟩_) open import Function.Inverse as Inv using (Inverse) open import Data.Nat as ℕ hiding (_≟_) import Level finitude→≡ : ∀ {n m} → Finitude (P.setoid (Fin n)) m → n ≡ m finitude→≡ fin = ⇒Fin∼Fin fin where open import Data.Fin.PigeonHole dec-≈ : ∀ {a ℓ n}{S : Setoid a ℓ} → Finitude S n → Dec₂ (Setoid._≈_ S) dec-≈ {S = S} fin x y with (Inverse.to fin ⟨$⟩ x) ≟ (Inverse.to fin ⟨$⟩ y) dec-≈ {S = S} fin x y | yes fx≡fy = yes (Inverse.injective fin fx≡fy) dec-≈ {S = S} fin x y | no fx≢fy = no (λ x≈y → fx≢fy (F.cong (Inverse.to fin) x≈y)) decSetoid : ∀ {a ℓ n}{S : Setoid a ℓ} → Finitude S n → DecSetoid a ℓ decSetoid {S = S} fin = record { isDecEquivalence = record { _≟_ = dec-≈ fin ; isEquivalence = isEquivalence } } where open Setoid S same-size↔ : ∀ {n a₁ a₂ ℓ₁ ℓ₂}{A₁ : Setoid a₁ ℓ₁}{A₂ : Setoid a₂ ℓ₂} → Finitude A₁ n → Finitude A₂ n → Inverse A₁ A₂ same-size↔ fin₁ fin₂ = Inv.sym fin₂ Inv.∘ fin₁ size-unique : ∀ {a ℓ} {A : Setoid a ℓ} {n m} → Finitude A n → Finitude A m → n ≡ m size-unique finN finM = finitude→≡ (finM Inv.∘ Inv.sym finN) {- open import Data.Empty open import Data.Unit Irr : ∀ {a ℓ}(S : Setoid a ℓ) → Set (a Level.⊔ ℓ) Irr S = ∀ x y → x ≈ y where open Setoid S ⊥-Irr : Irrelevant ⊥ ⊥-Irr = λ () ⊤-Irr : Irrelevant ⊤ ⊤-Irr = λ _ _ → P.refl Irr-finitude : ∀ {a ℓ n}{S : Set a} → Irrelevant S → Finitude (P.setoid S) n → n ℕ.≤ 1 Irr-finitude {n = ℕ.zero} irr fin = z≤n Irr-finitude {n = ℕ.suc ℕ.zero} irr fin = s≤s z≤n Irr-finitude {n = ℕ.suc (ℕ.suc n)}{S} irr fin = ⊥-elim contra where open Setoid S x₀ = Inverse.from fin ⟨$⟩ # 0 x₁ = Inverse.from fin ⟨$⟩ # 1 contra : ⊥ contra with Inverse.injective (Inv.sym fin) (irr x₀ x₁) ... | () -}
32.779412
117
0.618214
0ba86bf0e345499cf3caf1883fb0485859edbb68
3,612
agda
Agda
Structure/Bag/Nehemiah.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
10
2015-03-04T06:09:20.000Z
2019-07-19T07:06:59.000Z
Structure/Bag/Nehemiah.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
6
2015-07-01T18:09:31.000Z
2017-05-04T13:53:59.000Z
Structure/Bag/Nehemiah.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
1
2016-02-18T12:26:44.000Z
2016-02-18T12:26:44.000Z
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Bags of integers, for Nehemiah plugin. -- -- This module imports postulates about bags of integers -- with negative multiplicities as a group under additive union. ------------------------------------------------------------------------ module Structure.Bag.Nehemiah where open import Postulate.Bag-Nehemiah public open import Relation.Binary.PropositionalEquality open import Algebra using (CommutativeRing) open import Algebra.Structures open import Data.Integer open import Data.Integer.Properties using () renaming (+-*-commutativeRing to ℤ-is-commutativeRing) open import Data.Product infixl 9 _\\_ -- same as Data.Map.(\\) _\\_ : Bag → Bag → Bag d \\ b = d ++ (negateBag b) -- Useful properties of abelian groups commutative : ∀ {A : Set} {f : A → A → A} {z} → IsCommutativeMonoid _≡_ f z → (m n : A) → f m n ≡ f n m commutative = IsCommutativeMonoid.comm associative : ∀ {A : Set} {f : A → A → A} {z} → IsCommutativeMonoid _≡_ f z → (k m n : A) → f (f k m) n ≡ f k (f m n) associative abelian = IsCommutativeMonoid.assoc abelian left-inverse : ∀ {A : Set} {f : A → A → A} {z neg} → IsAbelianGroup _≡_ f z neg → (n : A) → f (neg n) n ≡ z left-inverse abelian = proj₁ (IsAbelianGroup.inverse abelian) right-inverse : ∀ {A : Set} {f : A → A → A} {z neg} → IsAbelianGroup _≡_ f z neg → (n : A) → f n (neg n) ≡ z right-inverse abelian = proj₂ (IsAbelianGroup.inverse abelian) left-identity : ∀ {A : Set} {f : A → A → A} {z neg} → IsAbelianGroup _≡_ f z neg → (n : A) → f z n ≡ n left-identity abelian = proj₁ (IsMonoid.identity (IsGroup.isMonoid (IsAbelianGroup.isGroup abelian))) right-identity : ∀ {A : Set} {f : A → A → A} {z neg} → IsAbelianGroup _≡_ f z neg → (n : A) → f n z ≡ n right-identity abelian = proj₂ (IsMonoid.identity (IsGroup.isMonoid (IsAbelianGroup.isGroup abelian))) instance abelian-int : IsAbelianGroup _≡_ _+_ (+ 0) (-_) abelian-int = CommutativeRing.+-isAbelianGroup ℤ-is-commutativeRing abelian→comm-monoid : ∀ {A : Set} {f : A → A → A} {z neg} → {{abel : IsAbelianGroup _≡_ f z neg}} → IsCommutativeMonoid _≡_ f z abelian→comm-monoid {{abel}} = IsAbelianGroup.isCommutativeMonoid abel comm-monoid-int : IsCommutativeMonoid _≡_ _+_ (+ 0) comm-monoid-int = IsAbelianGroup.isCommutativeMonoid abelian-int comm-monoid-bag : IsCommutativeMonoid _≡_ _++_ emptyBag comm-monoid-bag = IsAbelianGroup.isCommutativeMonoid abelian-bag import Data.Nat as N import Data.Nat.Properties as NP comm-monoid-nat : IsCommutativeMonoid _≡_ N._+_ 0 comm-monoid-nat = IsCommutativeSemiring.+-isCommutativeMonoid NP.isCommutativeSemiring commutative-int : (m n : ℤ) → m + n ≡ n + m commutative-int = commutative comm-monoid-int associative-int : (k m n : ℤ) → (k + m) + n ≡ k + (m + n) associative-int = associative comm-monoid-int right-inv-int : (n : ℤ) → n - n ≡ + 0 right-inv-int = right-inverse abelian-int left-id-int : (n : ℤ) → (+ 0) + n ≡ n left-id-int = left-identity abelian-int right-id-int : (n : ℤ) → n + (+ 0) ≡ n right-id-int = right-identity abelian-int commutative-bag : (a b : Bag) → a ++ b ≡ b ++ a commutative-bag = commutative comm-monoid-bag associative-bag : (a b c : Bag) → (a ++ b) ++ c ≡ a ++ (b ++ c) associative-bag = associative comm-monoid-bag right-inv-bag : (b : Bag) → b \\ b ≡ emptyBag right-inv-bag = right-inverse abelian-bag left-id-bag : (b : Bag) → emptyBag ++ b ≡ b left-id-bag = left-identity abelian-bag right-id-bag : (b : Bag) → b ++ emptyBag ≡ b right-id-bag = right-identity abelian-bag
38.83871
88
0.645626
dc966c366aaf566bfaa5cda3fda99e0ec489a092
1,387
agda
Agda
UniDB/Basic.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
UniDB/Basic.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
UniDB/Basic.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
module UniDB.Basic where open import UniDB.Spec open import UniDB.Subst open import Function module _ {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} {{apWkTT : ApWk T T}} {Ξ : MOR} {{upΞ : Up Ξ}} {{compΞ : Comp Ξ}} {{lkTΞ : Lk T Ξ}} {{lkUpTΞ : LkUp T Ξ}} {{lkCompTΞ : LkCompAp T Ξ}} where ⊙-↑₁-pointwise : {γ₁ γ₂ γ₃ : Dom} (ξ₁ : Ξ γ₁ γ₂) (ξ₂ : Ξ γ₂ γ₃) → [ T ] ((ξ₁ ⊙ ξ₂) ↑₁) ≃ (ξ₁ ↑₁ ⊙ ξ₂ ↑₁) lk≃ (⊙-↑₁-pointwise ξ₁ ξ₂) zero = begin lk {T} ((ξ₁ ⊙ ξ₂) ↑₁) zero ≡⟨ lk-↑₁-zero (ξ₁ ⊙ ξ₂) ⟩ vr zero ≡⟨ sym (lk-↑₁-zero ξ₂) ⟩ lk (ξ₂ ↑₁) zero ≡⟨ sym (ap-vr {T} (ξ₂ ↑₁) zero) ⟩ ap {T} (ξ₂ ↑₁) (vr zero) ≡⟨ cong (ap {T} (ξ₂ ↑₁)) (sym (lk-↑₁-zero ξ₁)) ⟩ ap {T} (ξ₂ ↑₁) (lk (ξ₁ ↑₁) zero) ≡⟨ sym (lk-⊙-ap {T} (ξ₁ ↑₁) (ξ₂ ↑₁) zero) ⟩ lk (ξ₁ ↑₁ ⊙ ξ₂ ↑₁) zero ∎ lk≃ (⊙-↑₁-pointwise ξ₁ ξ₂) (suc i) = begin lk ((ξ₁ ⊙ ξ₂) ↑₁) (wk₁ i) ≡⟨ lk-↑₁-suc (ξ₁ ⊙ ξ₂) i ⟩ wk₁ (lk (ξ₁ ⊙ ξ₂) i) ≡⟨ cong wk₁ (lk-⊙-ap {T} ξ₁ ξ₂ i) ⟩ wk₁ (ap {T} ξ₂ (lk ξ₁ i)) ≡⟨ sym (ap-wk₁ {T} ξ₂ (lk ξ₁ i)) ⟩ ap {T} (ξ₂ ↑₁) (wk₁ (lk ξ₁ i)) ≡⟨ cong (ap {T} (ξ₂ ↑₁)) (sym (lk-↑₁-suc ξ₁ i)) ⟩ ap {T} (ξ₂ ↑₁) (lk (ξ₁ ↑₁) (wk₁ i)) ≡⟨ sym (lk-⊙-ap {T} (ξ₁ ↑₁) (ξ₂ ↑₁) (wk₁ i) ) ⟩ lk (ξ₁ ↑₁ ⊙ ξ₂ ↑₁) (wk₁ i) ∎
47.827586
100
0.42682
a14b8ec537cfcb1c5b2a76bae4d064bb2b166965
224
agda
Agda
Cubical/HITs/Truncation/FromNegTwo.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/HITs/Truncation/FromNegTwo.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/HITs/Truncation/FromNegTwo.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Truncation.FromNegTwo where open import Cubical.HITs.Truncation.FromNegTwo.Base public open import Cubical.HITs.Truncation.FromNegTwo.Properties public
37.333333
64
0.808036
508e38845d32c5b56d554073e7579509129b55df
152
agda
Agda
examples/AIM6/Path/Elem.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/AIM6/Path/Elem.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/AIM6/Path/Elem.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Elem where open import Prelude open import Star Elem : {X : Set}(R : Rel X) -> Rel X Elem R x y = Star (LeqBool [×] R) (false , x) (true , y)
16.888889
56
0.611842
127768b0636bcc437c4e61629c478ea663e7d53e
450
agda
Agda
eq-reasoning.agda
JimFixGroupResearch/imper-ial
80d9411b2869614cae488cd4a6272894146c9f3c
[ "MIT" ]
null
null
null
eq-reasoning.agda
JimFixGroupResearch/imper-ial
80d9411b2869614cae488cd4a6272894146c9f3c
[ "MIT" ]
null
null
null
eq-reasoning.agda
JimFixGroupResearch/imper-ial
80d9411b2869614cae488cd4a6272894146c9f3c
[ "MIT" ]
null
null
null
module eq-reasoning {A : Set} where open import eq infix 1 begin_ infixr 2 _≡⟨⟩_ _≡⟨_⟩_ infix 3 _∎ begin_ : ∀ {x y : A} → x ≡ y ----- → x ≡ y begin x≡y = x≡y _≡⟨⟩_ : ∀ (x : A) {y : A} → x ≡ y ----- → x ≡ y x ≡⟨⟩ x≡y = x≡y _≡⟨_⟩_ : ∀ (x : A) {y z : A} → x ≡ y → y ≡ z ----- → x ≡ z x ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z _∎ : ∀ (x : A) ----- → x ≡ x x ∎ = refl
14.0625
35
0.32
cbf6f55823aa454cd4a80e7c727f07197c041911
739
agda
Agda
core/lib/groups/Groups.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
core/lib/groups/Groups.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
core/lib/groups/Groups.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} module lib.groups.Groups where open import lib.groups.CommutingSquare public open import lib.groups.FreeAbelianGroup public open import lib.groups.FreeGroup public open import lib.groups.GroupProduct public open import lib.groups.Homomorphism public open import lib.groups.HomotopyGroup public open import lib.groups.Int public open import lib.groups.Isomorphism public open import lib.groups.Lift public open import lib.groups.LoopSpace public open import lib.groups.QuotientGroup public open import lib.groups.PullbackGroup public open import lib.groups.Subgroup public open import lib.groups.SubgroupProp public open import lib.groups.TruncationGroup public open import lib.groups.Unit public
33.590909
46
0.837618
dce9ea838545c9bdeb2c2babad094a40e9261a9b
15,142
agda
Agda
Cubical/ZCohomology/CohomologyRings/S1.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/ZCohomology/CohomologyRings/S1.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/ZCohomology/CohomologyRings/S1.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} -- This file could be proven using the file Sn -- However the proofs are easier than in Sn -- And so kept for pedagologic reasons module Cubical.ZCohomology.CohomologyRings.S1 where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Transport open import Cubical.Foundations.HLevels open import Cubical.Data.Unit open import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_ ; snotz to nsnotz) open import Cubical.Data.Int open import Cubical.Data.Vec open import Cubical.Data.FinData open import Cubical.Algebra.Group open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.Instances.Int renaming (ℤGroup to ℤG) open import Cubical.Algebra.DirectSum.Base open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.FGIdeal open import Cubical.Algebra.CommRing.QuotientRing open import Cubical.Algebra.Polynomials.Multivariate.Base renaming (base to baseP) open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤCommRing to ℤCR) open import Cubical.Algebra.CommRing.Instances.MultivariatePoly open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-Quotient open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-notationZ open import Cubical.HITs.Truncation open import Cubical.HITs.SetQuotients as SQ renaming (_/_ to _/sq_) open import Cubical.HITs.PropositionalTruncation as PT open import Cubical.HITs.Sn open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.GroupStructure open import Cubical.ZCohomology.RingStructure.CupProduct open import Cubical.ZCohomology.RingStructure.CohomologyRing open import Cubical.ZCohomology.Groups.Sn open Iso module Equiv-S1-Properties where ----------------------------------------------------------------------------- -- Definitions open CommRingStr (snd ℤCR) using () renaming ( 0r to 0ℤ ; 1r to 1ℤ ; _+_ to _+ℤ_ ; -_ to -ℤ_ ; _·_ to _·ℤ_ ; +Assoc to +ℤAssoc ; +Identity to +ℤIdentity ; +Lid to +ℤLid ; +Rid to +ℤRid ; +Inv to +ℤInv ; +Linv to +ℤLinv ; +Rinv to +ℤRinv ; +Comm to +ℤComm ; ·Assoc to ·ℤAssoc ; ·Identity to ·ℤIdentity ; ·Lid to ·ℤLid ; ·Rid to ·ℤRid ; ·Rdist+ to ·ℤRdist+ ; ·Ldist+ to ·ℤLdist+ ; is-set to isSetℤ ) open RingStr (snd (H*R (S₊ 1))) using () renaming ( 0r to 0H* ; 1r to 1H* ; _+_ to _+H*_ ; -_ to -H*_ ; _·_ to _cup_ ; +Assoc to +H*Assoc ; +Identity to +H*Identity ; +Lid to +H*Lid ; +Rid to +H*Rid ; +Inv to +H*Inv ; +Linv to +H*Linv ; +Rinv to +H*Rinv ; +Comm to +H*Comm ; ·Assoc to ·H*Assoc ; ·Identity to ·H*Identity ; ·Lid to ·H*Lid ; ·Rid to ·H*Rid ; ·Rdist+ to ·H*Rdist+ ; ·Ldist+ to ·H*Ldist+ ; is-set to isSetH* ) open CommRingStr (snd ℤ[X]) using () renaming ( 0r to 0Pℤ ; 1r to 1Pℤ ; _+_ to _+Pℤ_ ; -_ to -Pℤ_ ; _·_ to _·Pℤ_ ; +Assoc to +PℤAssoc ; +Identity to +PℤIdentity ; +Lid to +PℤLid ; +Rid to +PℤRid ; +Inv to +PℤInv ; +Linv to +PℤLinv ; +Rinv to +PℤRinv ; +Comm to +PℤComm ; ·Assoc to ·PℤAssoc ; ·Identity to ·PℤIdentity ; ·Lid to ·PℤLid ; ·Rid to ·PℤRid ; ·Comm to ·PℤComm ; ·Rdist+ to ·PℤRdist+ ; ·Ldist+ to ·PℤLdist+ ; is-set to isSetPℤ ) open CommRingStr (snd ℤ[X]/X²) using () renaming ( 0r to 0PℤI ; 1r to 1PℤI ; _+_ to _+PℤI_ ; -_ to -PℤI_ ; _·_ to _·PℤI_ ; +Assoc to +PℤIAssoc ; +Identity to +PℤIIdentity ; +Lid to +PℤILid ; +Rid to +PℤIRid ; +Inv to +PℤIInv ; +Linv to +PℤILinv ; +Rinv to +PℤIRinv ; +Comm to +PℤIComm ; ·Assoc to ·PℤIAssoc ; ·Identity to ·PℤIIdentity ; ·Lid to ·PℤILid ; ·Rid to ·PℤIRid ; ·Rdist+ to ·PℤIRdist+ ; ·Ldist+ to ·PℤILdist+ ; is-set to isSetPℤI ) ----------------------------------------------------------------------------- -- Direct Sens on ℤ[x] ℤ[x]→H*-S¹ : ℤ[x] → H* (S₊ 1) ℤ[x]→H*-S¹ = Poly-Rec-Set.f _ _ _ isSetH* 0H* base-trad _+H*_ +H*Assoc +H*Rid +H*Comm base-neutral-eq base-add-eq where e : _ e = Hᵐ-Sⁿ base-trad : _ base-trad (zero ∷ []) a = base 0 (inv (fst (Hᵐ-Sⁿ 0 1)) a) base-trad (one ∷ []) a = base 1 (inv (fst (Hᵐ-Sⁿ 1 1)) a) base-trad (suc (suc n) ∷ []) a = 0H* base-neutral-eq : _ base-neutral-eq (zero ∷ []) = cong (base 0) (IsGroupHom.pres1 (snd (invGroupIso (Hᵐ-Sⁿ 0 1)))) ∙ base-neutral _ base-neutral-eq (one ∷ []) = cong (base 1) (IsGroupHom.pres1 (snd (invGroupIso (Hᵐ-Sⁿ 1 1)))) ∙ base-neutral _ base-neutral-eq (suc (suc n) ∷ []) = refl base-add-eq : _ base-add-eq (zero ∷ []) a b = (base-add _ _ _) ∙ (cong (base 0) (sym (IsGroupHom.pres· (snd (invGroupIso (Hᵐ-Sⁿ 0 1))) a b))) base-add-eq (one ∷ []) a b = (base-add _ _ _) ∙ (cong (base 1) (sym (IsGroupHom.pres· (snd (invGroupIso (Hᵐ-Sⁿ 1 1))) a b))) base-add-eq (suc (suc n) ∷ []) a b = +H*Rid _ ----------------------------------------------------------------------------- -- Morphism on ℤ[x] ℤ[x]→H*-S¹-pres1Pℤ : ℤ[x]→H*-S¹ (1Pℤ) ≡ 1H* ℤ[x]→H*-S¹-pres1Pℤ = refl ℤ[x]→H*-S¹-pres+ : (x y : ℤ[x]) → ℤ[x]→H*-S¹ (x +Pℤ y) ≡ ℤ[x]→H*-S¹ x +H* ℤ[x]→H*-S¹ y ℤ[x]→H*-S¹-pres+ x y = refl -- cup product on H⁰ → H⁰ → H⁰ T0 : (z : ℤ) → coHom 0 (S₊ 1) T0 = λ z → inv (fst (Hᵐ-Sⁿ 0 1)) z T0g : IsGroupHom (ℤG .snd) (fst (invGroupIso (Hᵐ-Sⁿ 0 1)) .fun) (coHomGr 0 (S₊ (suc 0)) .snd) T0g = snd (invGroupIso (Hᵐ-Sⁿ 0 1)) -- idea : control of the unfolding + simplification of T0 on the left pres·-base-case-00 : (a : ℤ) → (b : ℤ) → T0 (a ·ℤ b) ≡ (T0 a) ⌣ (T0 b) pres·-base-case-00 (pos zero) b = (IsGroupHom.pres1 T0g) pres·-base-case-00 (pos (suc n)) b = ((IsGroupHom.pres· T0g b (pos n ·ℤ b))) ∙ (cong (λ X → (T0 b) +ₕ X) (pres·-base-case-00 (pos n) b)) pres·-base-case-00 (negsuc zero) b = IsGroupHom.presinv T0g b pres·-base-case-00 (negsuc (suc n)) b = cong T0 (+ℤComm (-ℤ b) (negsuc n ·ℤ b)) -- ·ℤ and ·₀ are defined asymetrically ! ∙ IsGroupHom.pres· T0g (negsuc n ·ℤ b) (-ℤ b) ∙ cong₂ _+ₕ_ (pres·-base-case-00 (negsuc n) b) (IsGroupHom.presinv T0g b) -- cup product on H⁰ → H¹ → H¹ T1 : (z : ℤ) → coHom 1 (S₊ 1) T1 = λ z → inv (fst (Hᵐ-Sⁿ 1 1)) z -- idea : control of the unfolding + simplification of T0 on the left T1g : IsGroupHom (ℤG .snd) (fst (invGroupIso (Hᵐ-Sⁿ 1 1)) .fun) (coHomGr 1 (S₊ 1) .snd) T1g = snd (invGroupIso (Hᵐ-Sⁿ 1 1)) pres·-base-case-01 : (a : ℤ) → (b : ℤ) → T1 (a ·ℤ b) ≡ (T0 a) ⌣ (T1 b) pres·-base-case-01 (pos zero) b = (IsGroupHom.pres1 T1g) pres·-base-case-01 (pos (suc n)) b = ((IsGroupHom.pres· T1g b (pos n ·ℤ b))) ∙ (cong (λ X → (T1 b) +ₕ X) (pres·-base-case-01 (pos n) b)) pres·-base-case-01 (negsuc zero) b = IsGroupHom.presinv T1g b pres·-base-case-01 (negsuc (suc n)) b = cong T1 (+ℤComm (-ℤ b) (negsuc n ·ℤ b)) -- ·ℤ and ·₀ are defined asymetrically ! ∙ IsGroupHom.pres· T1g (negsuc n ·ℤ b) (-ℤ b) ∙ cong₂ _+ₕ_ (pres·-base-case-01 (negsuc n) b) (IsGroupHom.presinv T1g b) -- Nice packaging of the proof pres·-base-case-int : (n : ℕ) → (a : ℤ) → (m : ℕ) → (b : ℤ) → ℤ[x]→H*-S¹ (baseP (n ∷ []) a ·Pℤ baseP (m ∷ []) b) ≡ ℤ[x]→H*-S¹ (baseP (n ∷ []) a) cup ℤ[x]→H*-S¹ (baseP (m ∷ []) b) pres·-base-case-int zero a zero b = cong (base 0) (pres·-base-case-00 a b) pres·-base-case-int zero a one b = cong (base 1) (pres·-base-case-01 a b) pres·-base-case-int zero a (suc (suc m)) b = refl pres·-base-case-int one a zero b = cong ℤ[x]→H*-S¹ (·PℤComm (baseP (1 ∷ []) a) (baseP (zero ∷ []) b)) ∙ pres·-base-case-int 0 b 1 a ∙ gradCommRing (S₊ 1) 0 1 (inv (fst (Hᵐ-Sⁿ 0 1)) b) (inv (fst (Hᵐ-Sⁿ 1 1)) a) pres·-base-case-int one a one b = sym (base-neutral 2) ∙ cong (base 2) (isOfHLevelRetractFromIso 1 (fst (Hⁿ-Sᵐ≅0 1 0 nsnotz)) isPropUnit _ _) pres·-base-case-int one a (suc (suc m)) b = refl pres·-base-case-int (suc (suc n)) a m b = refl pres·-base-case-vec : (v : Vec ℕ 1) → (a : ℤ) → (v' : Vec ℕ 1) → (b : ℤ) → ℤ[x]→H*-S¹ (baseP v a ·Pℤ baseP v' b) ≡ ℤ[x]→H*-S¹ (baseP v a) cup ℤ[x]→H*-S¹ (baseP v' b) pres·-base-case-vec (n ∷ []) a (m ∷ []) b = pres·-base-case-int n a m b -- proof of the morphism ℤ[x]→H*-S¹-pres· : (x y : ℤ[x]) → ℤ[x]→H*-S¹ (x ·Pℤ y) ≡ ℤ[x]→H*-S¹ x cup ℤ[x]→H*-S¹ y ℤ[x]→H*-S¹-pres· = Poly-Ind-Prop.f _ _ _ (λ x p q i y j → isSetH* _ _ (p y) (q y) i j) (λ y → refl) base-case λ {U V} ind-U ind-V y → cong₂ _+H*_ (ind-U y) (ind-V y) where base-case : _ base-case (n ∷ []) a = Poly-Ind-Prop.f _ _ _ (λ _ → isSetH* _ _) (sym (RingTheory.0RightAnnihilates (H*R (S₊ 1)) _)) (λ v' b → pres·-base-case-vec (n ∷ []) a v' b) λ {U V} ind-U ind-V → (cong₂ _+H*_ ind-U ind-V) ∙ sym (·H*Rdist+ _ _ _) ----------------------------------------------------------------------------- -- Function on ℤ[x]/x + morphism ℤ[x]→H*-S¹-cancelX : (k : Fin 1) → ℤ[x]→H*-S¹ (<X²> k) ≡ 0H* ℤ[x]→H*-S¹-cancelX zero = refl ℤ[X]→H*-S¹ : RingHom (CommRing→Ring ℤ[X]) (H*R (S₊ 1)) fst ℤ[X]→H*-S¹ = ℤ[x]→H*-S¹ snd ℤ[X]→H*-S¹ = makeIsRingHom ℤ[x]→H*-S¹-pres1Pℤ ℤ[x]→H*-S¹-pres+ ℤ[x]→H*-S¹-pres· ℤ[X]/X²→H*R-S¹ : RingHom (CommRing→Ring ℤ[X]/X²) (H*R (S₊ 1)) ℤ[X]/X²→H*R-S¹ = Quotient-FGideal-CommRing-Ring.inducedHom ℤ[X] (H*R (S₊ 1)) ℤ[X]→H*-S¹ <X²> ℤ[x]→H*-S¹-cancelX ℤ[x]/x²→H*-S¹ : ℤ[x]/x² → H* (S₊ 1) ℤ[x]/x²→H*-S¹ = fst ℤ[X]/X²→H*R-S¹ ----------------------------------------------------------------------------- -- Converse Sens on ℤ[X] + ℤ[x]/x H*-S¹→ℤ[x] : H* (S₊ 1) → ℤ[x] H*-S¹→ℤ[x] = DS-Rec-Set.f _ _ _ _ isSetPℤ 0Pℤ base-trad _+Pℤ_ +PℤAssoc +PℤRid +PℤComm base-neutral-eq base-add-eq where base-trad : _ base-trad zero a = baseP (0 ∷ []) (fun (fst (Hᵐ-Sⁿ 0 1)) a) base-trad one a = baseP (1 ∷ []) (fun (fst (Hᵐ-Sⁿ 1 1)) a) base-trad (suc (suc n)) a = 0Pℤ base-neutral-eq : _ base-neutral-eq zero = cong (baseP (0 ∷ [])) (IsGroupHom.pres1 (snd (Hᵐ-Sⁿ 0 1))) ∙ base-0P _ base-neutral-eq one = cong (baseP (1 ∷ [])) (IsGroupHom.pres1 (snd (Hᵐ-Sⁿ 1 1))) ∙ base-0P _ base-neutral-eq (suc (suc n)) = refl base-add-eq : _ base-add-eq zero a b = (base-poly+ _ _ _) ∙ (cong (baseP (0 ∷ [])) (sym (IsGroupHom.pres· (snd (Hᵐ-Sⁿ 0 1)) a b))) base-add-eq one a b = (base-poly+ _ _ _) ∙ (cong (baseP (1 ∷ [])) (sym (IsGroupHom.pres· (snd (Hᵐ-Sⁿ 1 1)) a b))) base-add-eq (suc (suc n)) a b = +PℤRid _ H*-S¹→ℤ[x]-pres+ : (x y : H* (S₊ 1)) → H*-S¹→ℤ[x] ( x +H* y) ≡ H*-S¹→ℤ[x] x +Pℤ H*-S¹→ℤ[x] y H*-S¹→ℤ[x]-pres+ x y = refl H*-S¹→ℤ[x]/x² : H* (S₊ 1) → ℤ[x]/x² H*-S¹→ℤ[x]/x² = [_] ∘ H*-S¹→ℤ[x] H*-S¹→ℤ[x]/x²-pres+ : (x y : H* (S₊ 1)) → H*-S¹→ℤ[x]/x² (x +H* y) ≡ (H*-S¹→ℤ[x]/x² x) +PℤI (H*-S¹→ℤ[x]/x² y) H*-S¹→ℤ[x]/x²-pres+ x y = refl ----------------------------------------------------------------------------- -- Section e-sect : (x : H* (S₊ 1)) → ℤ[x]/x²→H*-S¹ (H*-S¹→ℤ[x]/x² x) ≡ x e-sect = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH* _ _) refl base-case λ {U V} ind-U ind-V → cong₂ _+H*_ ind-U ind-V where base-case : _ base-case zero a = cong (base 0) (leftInv (fst (Hᵐ-Sⁿ 0 1)) a) base-case one a = cong (base 1) (leftInv (fst (Hᵐ-Sⁿ 1 1)) a) base-case (suc (suc n)) a = (sym (base-neutral (suc (suc n)))) ∙ cong (base (suc (suc n))) (isOfHLevelRetractFromIso 1 (fst (Hⁿ-Sᵐ≅0 (suc n) 0 nsnotz)) isPropUnit _ _) ----------------------------------------------------------------------------- -- Retraction e-retr : (x : ℤ[x]/x²) → H*-S¹→ℤ[x]/x² (ℤ[x]/x²→H*-S¹ x) ≡ x e-retr = SQ.elimProp (λ _ → isSetPℤI _ _) (Poly-Ind-Prop.f _ _ _ (λ _ → isSetPℤI _ _) refl base-case λ {U V} ind-U ind-V → cong₂ _+PℤI_ ind-U ind-V) where base-case : _ base-case (zero ∷ []) a = cong [_] (cong (baseP (0 ∷ [])) (rightInv (fst (Hᵐ-Sⁿ 0 1)) a)) base-case (one ∷ []) a = cong [_] (cong (baseP (1 ∷ [])) (rightInv (fst (Hᵐ-Sⁿ 1 1)) a)) base-case (suc (suc n) ∷ []) a = eq/ 0Pℤ (baseP (suc (suc n) ∷ []) a) ∣ ((λ x → baseP (n ∷ []) (-ℤ a)) , helper) ∣₁ where helper : _ helper = (+PℤLid _) ∙ cong₂ baseP (cong (λ X → X ∷ []) (sym (+-comm n 2))) (sym (·ℤRid _)) ∙ (sym (+PℤRid _)) ----------------------------------------------------------------------------- -- Computation of the Cohomology Ring module _ where open Equiv-S1-Properties S¹-CohomologyRing : RingEquiv (CommRing→Ring ℤ[X]/X²) (H*R (S₊ 1)) fst S¹-CohomologyRing = isoToEquiv is where is : Iso ℤ[x]/x² (H* (S₊ 1)) fun is = ℤ[x]/x²→H*-S¹ inv is = H*-S¹→ℤ[x]/x² rightInv is = e-sect leftInv is = e-retr snd S¹-CohomologyRing = snd ℤ[X]/X²→H*R-S¹ CohomologyRing-S¹ : RingEquiv (H*R (S₊ 1)) (CommRing→Ring ℤ[X]/X²) CohomologyRing-S¹ = RingEquivs.invEquivRing S¹-CohomologyRing
40.271277
147
0.477876
50c04bf572495e68077782ba7124ec60a6676b95
478
agda
Agda
test/Compiler/simple/Issue5421.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/Issue5421.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Compiler/simple/Issue5421.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.IO open import Agda.Builtin.Reflection open import Agda.Builtin.Strict open import Agda.Builtin.String open import Agda.Builtin.Unit postulate putStr : String → IO ⊤ {-# FOREIGN GHC import qualified Data.Text.IO #-} {-# COMPILE GHC putStr = Data.Text.IO.putStr #-} {-# COMPILE JS putStr = function (x) { return function(cb) { process.stdout.write(x); cb(0); }; } #-} main : IO ⊤ main = primForce commitTC λ _ → putStr "Success\n"
25.157895
50
0.686192
06d20e778b12c5183fb1f16bfee4260217dfd950
2,103
agda
Agda
src/fot/FOTC/Data/Conat/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Data/Conat/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Data/Conat/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Conat properties ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Conat.PropertiesATP where open import FOTC.Base open import FOTC.Data.Conat open import FOTC.Data.Nat ------------------------------------------------------------------------------ -- Because a greatest post-fixed point is a fixed-point, then the -- Conat predicate is also a pre-fixed point of the functional NatF, -- i.e. -- -- NatF Conat ≤ Conat (see FOTC.Data.Conat.Type). -- See Issue https://github.com/asr/apia/issues/81 . Conat-inA : D → Set Conat-inA n = n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ Conat n') {-# ATP definition Conat-inA #-} Conat-in : ∀ {n} → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ Conat n') → Conat n Conat-in h = Conat-coind Conat-inA h' h where postulate h' : ∀ {n} → Conat-inA n → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ Conat-inA n') {-# ATP prove h' #-} -- See Issue https://github.com/asr/apia/issues/81 . 0-ConatA : D → Set 0-ConatA n = n ≡ zero {-# ATP definition 0-ConatA #-} 0-Conat : Conat zero 0-Conat = Conat-coind 0-ConatA h refl where postulate h : ∀ {n} → 0-ConatA n → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ 0-ConatA n') {-# ATP prove h #-} ∞-Conat : Conat ∞ ∞-Conat = Conat-coind A h refl where A : D → Set A n = n ≡ ∞ {-# ATP definition A #-} postulate h : ∀ {n} → A n → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ A n') {-# ATP prove h #-} N→Conat : ∀ {n} → N n → Conat n N→Conat Nn = Conat-coind N h Nn where h : ∀ {m} → N m → m ≡ zero ∨ (∃[ m' ] m ≡ succ₁ m' ∧ N m') h nzero = prf where postulate prf : zero ≡ zero ∨ (∃[ m' ] zero ≡ succ₁ m' ∧ N m') {-# ATP prove prf #-} h (nsucc {m} Nm) = prf where postulate prf : succ₁ m ≡ zero ∨ (∃[ m' ] succ₁ m ≡ succ₁ m' ∧ N m') {-# ATP prove prf #-}
30.478261
78
0.477889
188be59e39e17923ffc913050bce8d5aa0ca0b18
9,946
agda
Agda
src/Builtin/Reflection.agda
L-TChen/agda-prelude
158d299b1b365e186f00d8ef5b8c6844235ee267
[ "MIT" ]
null
null
null
src/Builtin/Reflection.agda
L-TChen/agda-prelude
158d299b1b365e186f00d8ef5b8c6844235ee267
[ "MIT" ]
null
null
null
src/Builtin/Reflection.agda
L-TChen/agda-prelude
158d299b1b365e186f00d8ef5b8c6844235ee267
[ "MIT" ]
null
null
null
module Builtin.Reflection where open import Prelude hiding (abs) open import Prelude.Equality.Unsafe open import Builtin.Float open import Container.Traversable open import Control.Monad.Zero open import Prelude.Variables open import Agda.Builtin.Reflection as Builtin open Builtin public hiding ( primQNameEquality ; primQNameLess ; primShowQName ; primMetaEquality ; primMetaLess ; primShowMeta ) --- Names --- instance ShowName : Show Name showsPrec {{ShowName}} _ x = showString (primShowQName x) instance EqName : Eq Name _==_ {{EqName}} x y with primQNameEquality x y ... | true = yes unsafeEqual ... | false = no unsafeNotEqual data LessName (x y : Name) : Set where less-name : primQNameLess x y ≡ true → LessName x y private cmpName : ∀ x y → Comparison LessName x y cmpName x y with inspect (primQNameLess x y) ... | true with≡ eq = less (less-name eq) ... | false with≡ _ with inspect (primQNameLess y x) ... | true with≡ eq = greater (less-name eq) ... | false with≡ _ = equal unsafeEqual instance OrdName : Ord Name OrdName = defaultOrd cmpName OrdLawsName : Ord/Laws Name Ord/Laws.super OrdLawsName = it less-antirefl {{OrdLawsName}} (less-name eq) = unsafeNotEqual eq less-trans {{OrdLawsName}} (less-name _) (less-name _) = less-name unsafeEqual --- Meta variables --- instance ShowMeta : Show Meta showsPrec {{ShowMeta}} _ x = showString (primShowMeta x) instance EqMeta : Eq Meta _==_ {{EqMeta}} x y with primMetaEquality x y ... | true = yes unsafeEqual ... | false = no unsafeNotEqual data LessMeta (x y : Meta) : Set where less-meta : primMetaLess x y ≡ true → LessMeta x y private cmpMeta : ∀ x y → Comparison LessMeta x y cmpMeta x y with inspect (primMetaLess x y) ... | true with≡ eq = less (less-meta eq) ... | false with≡ _ with inspect (primMetaLess y x) ... | true with≡ eq = greater (less-meta eq) ... | false with≡ _ = equal unsafeEqual instance OrdMeta : Ord Meta OrdMeta = defaultOrd cmpMeta OrdLawsMeta : Ord/Laws Meta Ord/Laws.super OrdLawsMeta = it less-antirefl {{OrdLawsMeta}} (less-meta eq) = unsafeNotEqual eq less-trans {{OrdLawsMeta}} (less-meta _) (less-meta _) = less-meta unsafeEqual --- Literals --- instance ShowLiteral : Show Literal showsPrec {{ShowLiteral}} _ (nat n) = shows n showsPrec {{ShowLiteral}} _ (word64 n) = shows n showsPrec {{ShowLiteral}} _ (float x) = shows x showsPrec {{ShowLiteral}} _ (char c) = shows c showsPrec {{ShowLiteral}} _ (string s) = shows s showsPrec {{ShowLiteral}} _ (name x) = shows x showsPrec {{ShowLiteral}} _ (meta x) = shows x --- Terms --- pattern vArg x = arg (arg-info visible relevant) x pattern hArg x = arg (arg-info hidden relevant) x pattern iArg x = arg (arg-info instance′ relevant) x unArg : Arg A → A unArg (arg _ x) = x getArgInfo : Arg A → ArgInfo getArgInfo (arg i _) = i getVisibility : Arg A → Visibility getVisibility (arg (arg-info v _) _) = v getRelevance : Arg A → Relevance getRelevance (arg (arg-info _ r) _) = r isVisible : Arg A → Bool isVisible (arg (arg-info visible _) _) = true isVisible _ = false instance FunctorArg : Functor {a = ℓ} Arg fmap {{FunctorArg}} f (arg i x) = arg i (f x) TraversableArg : Traversable {a = ℓ} Arg traverse {{TraversableArg}} f (arg i x) = ⦇ (arg i) (f x) ⦈ unAbs : Abs A → A unAbs (abs _ x) = x instance FunctorAbs : Functor {a = ℓ} Abs fmap {{FunctorAbs}} f (abs s x) = abs s (f x) TraversableAbs : Traversable {a = ℓ} Abs traverse {{TraversableAbs}} f (abs s x) = ⦇ (abs s) (f x) ⦈ absurd-lam : Term absurd-lam = pat-lam (absurd-clause (("()" , vArg unknown) ∷ []) (vArg (absurd 0) ∷ []) ∷ []) [] --- TC monad --- mapTC : (A → B) → TC A → TC B mapTC f m = bindTC m λ x → returnTC (f x) instance FunctorTC : Functor {ℓ} TC fmap {{FunctorTC}} = mapTC ApplicativeTC : Applicative {ℓ} TC pure {{ApplicativeTC}} = returnTC _<*>_ {{ApplicativeTC}} = monadAp bindTC MonadTC : Monad {ℓ} TC _>>=_ {{MonadTC}} = bindTC FunctorTC′ : Functor′ {ℓ₁} {ℓ₂} TC fmap′ {{FunctorTC′}} = mapTC ApplicativeTC′ : Applicative′ {ℓ₁} {ℓ₂} TC _<*>′_ {{ApplicativeTC′}} = monadAp′ bindTC MonadTC′ : Monad′ {ℓ₁} {ℓ₂} TC _>>=′_ {{MonadTC′}} = bindTC FunctorZeroTC : FunctorZero {ℓ} TC empty {{FunctorZeroTC}} = typeError [] AlternativeTC : Alternative {ℓ} TC _<|>_ {{AlternativeTC}} = catchTC Tactic = Term → TC ⊤ give : Term → Tactic give v = λ hole → unify hole v define : Arg Name → Type → List Clause → TC ⊤ define f a cs = declareDef f a >> defineFun (unArg f) cs newMeta : Type → TC Term newMeta = checkType unknown newMeta! : TC Term newMeta! = newMeta unknown typeErrorS : ∀ {a} {A : Set a} → String → TC A typeErrorS s = typeError (strErr s ∷ []) blockOnMeta! : ∀ {a} {A : Set a} → Meta → TC A blockOnMeta! x = commitTC >>=′ λ _ → blockOnMeta x inferNormalisedType : Term → TC Type inferNormalisedType t = withNormalisation true (inferType t) --- Convenient wrappers --- -- Zero for non-datatypes getParameters : Name → TC Nat getParameters d = caseM getDefinition d of λ { (data-type n _) → pure n ; _ → pure 0 } getConstructors : Name → TC (List Name) getConstructors d = caseM getDefinition d of λ { (data-type _ cs) → pure cs ; (record-type c _) → pure (c ∷ []) ; _ → typeError (strErr "Cannot get constructors of non-data or record type" ∷ nameErr d ∷ []) } getClauses : Name → TC (List Clause) getClauses d = caseM getDefinition d of λ { (function cs) → pure cs ; _ → typeError (strErr "Cannot get constructors of non-function type" ∷ nameErr d ∷ []) } -- Get the constructor of a record type (or single-constructor data type) recordConstructor : Name → TC Name recordConstructor r = caseM getConstructors r of λ { (c ∷ []) → pure c ; _ → typeError $ strErr "Cannot get constructor of non-record type" ∷ nameErr r ∷ [] } -- Injectivity of constructors arg-inj₁ : ∀ {i i′} {x x′ : A} → arg i x ≡ arg i′ x′ → i ≡ i′ arg-inj₁ refl = refl arg-inj₂ : ∀ {i i′} {x x′ : A} → arg i x ≡ arg i′ x′ → x ≡ x′ arg-inj₂ refl = refl arg-info-inj₁ : ∀ {v v′ r r′} → arg-info v r ≡ arg-info v′ r′ → v ≡ v′ arg-info-inj₁ refl = refl arg-info-inj₂ : ∀ {v v′ r r′} → arg-info v r ≡ arg-info v′ r′ → r ≡ r′ arg-info-inj₂ refl = refl abs-inj₁ : ∀ {s s′} {x x′ : A} → abs s x ≡ abs s′ x′ → s ≡ s′ abs-inj₁ refl = refl abs-inj₂ : ∀ {s s′} {x x′ : A} → abs s x ≡ abs s′ x′ → x ≡ x′ abs-inj₂ refl = refl --- Terms --- var-inj₁ : ∀ {x x′ args args′} → Term.var x args ≡ var x′ args′ → x ≡ x′ var-inj₁ refl = refl var-inj₂ : ∀ {x x′ args args′} → Term.var x args ≡ var x′ args′ → args ≡ args′ var-inj₂ refl = refl con-inj₁ : ∀ {c c′ args args′} → Term.con c args ≡ con c′ args′ → c ≡ c′ con-inj₁ refl = refl con-inj₂ : ∀ {c c′ args args′} → Term.con c args ≡ con c′ args′ → args ≡ args′ con-inj₂ refl = refl def-inj₁ : ∀ {f f′ args args′} → def f args ≡ def f′ args′ → f ≡ f′ def-inj₁ refl = refl def-inj₂ : ∀ {f f′ args args′} → def f args ≡ def f′ args′ → args ≡ args′ def-inj₂ refl = refl meta-inj₁ : ∀ {f f′ args args′} → Term.meta f args ≡ meta f′ args′ → f ≡ f′ meta-inj₁ refl = refl meta-inj₂ : ∀ {f f′ args args′} → Term.meta f args ≡ meta f′ args′ → args ≡ args′ meta-inj₂ refl = refl lam-inj₁ : ∀ {v v′ t t′} → lam v t ≡ lam v′ t′ → v ≡ v′ lam-inj₁ refl = refl lam-inj₂ : ∀ {v v′ t t′} → lam v t ≡ lam v′ t′ → t ≡ t′ lam-inj₂ refl = refl pat-lam-inj₁ : ∀ {v v′ t t′} → pat-lam v t ≡ pat-lam v′ t′ → v ≡ v′ pat-lam-inj₁ refl = refl pat-lam-inj₂ : ∀ {v v′ t t′} → pat-lam v t ≡ pat-lam v′ t′ → t ≡ t′ pat-lam-inj₂ refl = refl pi-inj₁ : ∀ {t₁ t₁′ t₂ t₂′} → pi t₁ t₂ ≡ pi t₁′ t₂′ → t₁ ≡ t₁′ pi-inj₁ refl = refl pi-inj₂ : ∀ {t₁ t₁′ t₂ t₂′} → pi t₁ t₂ ≡ pi t₁′ t₂′ → t₂ ≡ t₂′ pi-inj₂ refl = refl sort-inj : ∀ {x y} → agda-sort x ≡ agda-sort y → x ≡ y sort-inj refl = refl lit-inj : ∀ {x y} → Term.lit x ≡ lit y → x ≡ y lit-inj refl = refl --- Sorts --- set-inj : ∀ {x y} → set x ≡ set y → x ≡ y set-inj refl = refl prop-inj : ∀ {x y} → prop x ≡ prop y → x ≡ y prop-inj refl = refl slit-inj : ∀ {x y} → Sort.lit x ≡ lit y → x ≡ y slit-inj refl = refl spropLit-inj : ∀ {x y} → Sort.propLit x ≡ propLit y → x ≡ y spropLit-inj refl = refl sinf-inj : ∀ {x y} → Sort.inf x ≡ inf y → x ≡ y sinf-inj refl = refl --- Patterns --- pcon-inj₁ : ∀ {x y z w} → Pattern.con x y ≡ con z w → x ≡ z pcon-inj₁ refl = refl pcon-inj₂ : ∀ {x y z w} → Pattern.con x y ≡ con z w → y ≡ w pcon-inj₂ refl = refl pvar-inj : ∀ {x y} → Pattern.var x ≡ var y → x ≡ y pvar-inj refl = refl pdot-inj : ∀ {x y} → Pattern.dot x ≡ dot y → x ≡ y pdot-inj refl = refl plit-inj : ∀ {x y} → Pattern.lit x ≡ lit y → x ≡ y plit-inj refl = refl proj-inj : ∀ {x y} → Pattern.proj x ≡ proj y → x ≡ y proj-inj refl = refl absurd-inj : ∀ {x y} → absurd x ≡ absurd y → x ≡ y absurd-inj refl = refl --- Clauses --- clause-inj₁ : ∀ {x y z u v w} → clause x y z ≡ clause u v w → x ≡ u clause-inj₁ refl = refl clause-inj₂ : ∀ {x y z u v w} → clause x y z ≡ clause u v w → y ≡ v clause-inj₂ refl = refl clause-inj₃ : ∀ {x y z u v w} → clause x y z ≡ clause u v w → z ≡ w clause-inj₃ refl = refl absurd-clause-inj₁ : ∀ {x y z w} → absurd-clause x y ≡ absurd-clause z w → x ≡ z absurd-clause-inj₁ refl = refl absurd-clause-inj₂ : ∀ {x y z w} → absurd-clause x y ≡ absurd-clause z w → y ≡ w absurd-clause-inj₂ refl = refl --- Literals --- nat-inj : ∀ {x y} → nat x ≡ nat y → x ≡ y nat-inj refl = refl word64-inj : ∀ {x y} → word64 x ≡ word64 y → x ≡ y word64-inj refl = refl float-inj : ∀ {x y} → float x ≡ float y → x ≡ y float-inj refl = refl char-inj : ∀ {x y} → char x ≡ char y → x ≡ y char-inj refl = refl string-inj : ∀ {x y} → string x ≡ string y → x ≡ y string-inj refl = refl name-inj : ∀ {x y} → name x ≡ name y → x ≡ y name-inj refl = refl meta-inj : ∀ {x y} → Literal.meta x ≡ meta y → x ≡ y meta-inj refl = refl
26.736559
96
0.615926
4dd97837612d5da8867e6fb11ceeddf60dc8fd12
2,075
agda
Agda
src/Int.agda
cruhland/agda-editor
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
[ "MIT" ]
null
null
null
src/Int.agda
cruhland/agda-editor
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
[ "MIT" ]
null
null
null
src/Int.agda
cruhland/agda-editor
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
[ "MIT" ]
null
null
null
module Int where open import Agda.Builtin.FromNat open import Agda.Builtin.FromNeg open import Data.Char hiding (fromNat) open import Data.Integer hiding (_≤_; suc) open import Data.Integer.Literals open import Data.List open import Data.Nat hiding (_≤_) open import Data.String open import Data.Unit hiding (_≤_) open import Function open import Show postulate Int : Set primShow : Int → List Char primFromInteger : ℤ → Int primToInteger : Int → ℤ primMinBound : Int primMaxBound : Int {-# COMPILE GHC Int = type Int #-} {-# COMPILE GHC primShow = show #-} {-# COMPILE GHC primFromInteger = fromInteger #-} {-# COMPILE GHC primToInteger = toInteger #-} {-# COMPILE GHC primMinBound = minBound #-} {-# COMPILE GHC primMaxBound = maxBound #-} instance ShowInt : Show Int ShowInt = fromHaskell primShow instance Numberℤ : Number ℤ Numberℤ = number -- Its values can be automatically derived as instance arguments, but -- is otherwise identical to the standard library version data _ℕ≤_ : ℕ → ℕ → Set where instance z≤n : ∀ {n} → zero ℕ≤ n instance s≤s : ∀ {m n} {{m≤n : m ℕ≤ n}} → suc m ℕ≤ suc n -- Its values can be automatically derived as instance arguments, but -- is otherwise identical to the standard library version data _≤_ : ℤ → ℤ → Set where instance -≤- : {m n : ℕ} → {{n≤m : n ℕ≤ m}} → -[1+ m ] ≤ -[1+ n ] instance -≤+ : {m n : ℕ} → (-[1+ m ]) ≤ (+ n) instance +≤+ : {m n : ℕ} → {{m≤n : m ℕ≤ n}} → (+ m) ≤ (+ n) -- Use a literal for the bound so that Agda can automatically check -- the constraints for fromNat and fromNeg. Value taken from -- https://hackage.haskell.org/package/base-4.12.0.0/docs/Prelude.html#t:Int maxBound : ℤ maxBound = 536870911 -- Use the actual bound in compiled code {-# COMPILE GHC maxBound = toInteger (maxBound :: Int) #-} instance NumberInt : Number Int NumberInt = record { Constraint = Constraint ; fromNat = fromNatInt } where Constraint : ℕ → Set Constraint n = (+ n) ≤ maxBound fromNatInt : ∀ n → {{_ : Constraint n}} → Int fromNatInt n = primFromInteger (+ n)
31.439394
76
0.671325
50e162f21eaa93d6b997b583516dc52fdf3436ec
1,920
agda
Agda
string-format.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
29
2019-02-06T13:09:31.000Z
2022-03-04T15:05:12.000Z
string-format.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
8
2018-07-09T22:53:38.000Z
2022-03-22T03:43:34.000Z
string-format.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
17
2018-12-03T22:38:15.000Z
2021-11-28T20:13:21.000Z
{- formatted printing like printf, except type-safe (as proposed in "Cayenne -- a language with dependent types" by Augustsson). The types of the rest of the arguments are computed from the format string. -} module string-format where open import char open import eq open import list open import nat open import nat-to-string open import string {- We will first convert the format string to the following type, so we can avoid default cases in the definition of format-th (cf. string-format-issue.agda). -} data format-d : Set where format-nat : format-d → format-d format-string : format-d → format-d not-format : (c : char) → format-d → format-d empty-format : format-d format-cover : 𝕃 char → format-d format-cover ('%' :: 'n' :: s) = format-nat (format-cover s) format-cover ('%' :: 's' :: s) = format-string (format-cover s) format-cover (c :: s) = not-format c (format-cover s) format-cover [] = empty-format format-th : format-d → Set format-th (format-nat v) = ℕ → format-th v format-th (format-string v) = string → format-th v format-th (not-format c v) = format-th v format-th empty-format = string format-t : string → Set format-t s = format-th (format-cover (string-to-𝕃char s)) format-h : 𝕃 char → (d : format-d) → format-th d format-h s (format-nat v) = λ n → format-h (s ++ (string-to-𝕃char (ℕ-to-string n))) v format-h s (format-string v) = λ s' → format-h (s ++ (string-to-𝕃char s')) v format-h s (not-format c v) = format-h (s ++ [ c ] ) v format-h s empty-format = 𝕃char-to-string s format : (f : string) → format-t f format f = format-h [] (format-cover (string-to-𝕃char f)) format-type-test : Set format-type-test = format-t "%n% of the %ss are in the %s %s" format-test : string format-test = format "%n% of the %ss are in the %s %s" 25 "dog" "toasty" "doghouse" format-test-lem : format-test ≡ "25% of the dogs are in the toasty doghouse" format-test-lem = refl
34.285714
85
0.677083
1292ca68b3d38cf9795bced0d4a570bdc7aeee2e
29,711
agda
Agda
Agda/rings.agda
UlrikBuchholtz/HoTT-Intro
1e1f8def50f9359928e52ebb2ee53ed1166487d9
[ "CC-BY-4.0" ]
333
2018-09-26T08:33:30.000Z
2022-03-22T23:50:15.000Z
Agda/rings.agda
UlrikBuchholtz/HoTT-Intro
1e1f8def50f9359928e52ebb2ee53ed1166487d9
[ "CC-BY-4.0" ]
8
2019-06-18T04:16:04.000Z
2020-10-16T15:27:01.000Z
Agda/rings.agda
UlrikBuchholtz/HoTT-Intro
1e1f8def50f9359928e52ebb2ee53ed1166487d9
[ "CC-BY-4.0" ]
30
2018-09-26T09:08:57.000Z
2022-03-16T00:33:50.000Z
{-# OPTIONS --without-K --exact-split #-} module rings where import abelian-groups open abelian-groups public has-mul-Ab : { l1 : Level} (A : Ab l1) → UU l1 has-mul-Ab A = Σ ( has-associative-bin-op (set-Ab A)) ( λ μ → ( is-unital (pair (set-Ab A) μ)) × ( ( (a b c : type-Ab A) → Id (pr1 μ a (add-Ab A b c)) (add-Ab A (pr1 μ a b) (pr1 μ a c))) × ( (a b c : type-Ab A) → Id (pr1 μ (add-Ab A a b) c) (add-Ab A (pr1 μ a c) (pr1 μ b c))))) Ring : (l1 : Level) → UU (lsuc l1) Ring l1 = Σ (Ab l1) has-mul-Ab {- Basic infrastructure of rings -} ab-Ring : {l1 : Level} → Ring l1 → Ab l1 ab-Ring R = pr1 R group-Ring : {l : Level} (R : Ring l) → Group l group-Ring R = group-Ab (ab-Ring R) set-Ring : {l : Level} (R : Ring l) → UU-Set l set-Ring R = set-Ab (ab-Ring R) type-Ring : {l : Level} (R : Ring l) → UU l type-Ring R = type-Ab (ab-Ring R) is-set-type-Ring : {l : Level} (R : Ring l) → is-set (type-Ring R) is-set-type-Ring R = is-set-type-Ab (ab-Ring R) associative-add-Ring : {l : Level} (R : Ring l) → has-associative-bin-op (set-Ring R) associative-add-Ring R = associative-add-Ab (ab-Ring R) add-Ring : {l : Level} (R : Ring l) → type-Ring R → type-Ring R → type-Ring R add-Ring R = add-Ab (ab-Ring R) is-associative-add-Ring : {l : Level} (R : Ring l) (x y z : type-Ring R) → Id (add-Ring R (add-Ring R x y) z) (add-Ring R x (add-Ring R y z)) is-associative-add-Ring R = is-associative-add-Ab (ab-Ring R) additive-semi-group-Ring : {l : Level} (R : Ring l) → Semi-Group l additive-semi-group-Ring R = semi-group-Ab (ab-Ring R) is-group-additive-semi-group-Ring : {l : Level} (R : Ring l) → is-group (additive-semi-group-Ring R) is-group-additive-semi-group-Ring R = is-group-Ab (ab-Ring R) has-zero-Ring : {l : Level} (R : Ring l) → is-unital (additive-semi-group-Ring R) has-zero-Ring R = has-zero-Ab (ab-Ring R) zero-Ring : {l : Level} (R : Ring l) → type-Ring R zero-Ring R = zero-Ab (ab-Ring R) left-zero-law-add-Ring : {l : Level} (R : Ring l) (x : type-Ring R) → Id (add-Ring R (zero-Ring R) x) x left-zero-law-add-Ring R = left-zero-law-Ab (ab-Ring R) right-zero-law-add-Ring : {l : Level} (R : Ring l) (x : type-Ring R) → Id (add-Ring R x (zero-Ring R)) x right-zero-law-add-Ring R = right-zero-law-Ab (ab-Ring R) has-negatives-Ring : {l : Level} (R : Ring l) → is-group' (additive-semi-group-Ring R) (has-zero-Ring R) has-negatives-Ring R = has-negatives-Ab (ab-Ring R) neg-Ring : {l : Level} (R : Ring l) → type-Ring R → type-Ring R neg-Ring R = neg-Ab (ab-Ring R) left-negative-law-Ring : {l : Level} (R : Ring l) (x : type-Ring R) → Id (add-Ring R (neg-Ring R x) x) (zero-Ring R) left-negative-law-Ring R = left-negative-law-Ab (ab-Ring R) right-negative-law-Ring : {l : Level} (R : Ring l) (x : type-Ring R) → Id (add-Ring R x (neg-Ring R x)) (zero-Ring R) right-negative-law-Ring R = right-negative-law-Ab (ab-Ring R) is-commutative-add-Ring : {l : Level} (R : Ring l) (x y : type-Ring R) → Id (add-Ring R x y) (add-Ring R y x) is-commutative-add-Ring R = is-commutative-add-Ab (ab-Ring R) has-associative-mul-Ring : {l : Level} (R : Ring l) → has-associative-bin-op (set-Ring R) has-associative-mul-Ring R = pr1 (pr2 R) mul-Ring : {l : Level} (R : Ring l) → type-Ring R → type-Ring R → type-Ring R mul-Ring R = pr1 (has-associative-mul-Ring R) is-associative-mul-Ring : {l : Level} (R : Ring l) (x y z : type-Ring R) → Id (mul-Ring R (mul-Ring R x y) z) (mul-Ring R x (mul-Ring R y z)) is-associative-mul-Ring R = pr2 (has-associative-mul-Ring R) multiplicative-semi-group-Ring : {l : Level} (R : Ring l) → Semi-Group l multiplicative-semi-group-Ring R = pair (set-Ring R) (has-associative-mul-Ring R) is-unital-Ring : {l : Level} (R : Ring l) → is-unital (multiplicative-semi-group-Ring R) is-unital-Ring R = pr1 (pr2 (pr2 R)) multiplicative-monoid-Ring : {l : Level} (R : Ring l) → Monoid l multiplicative-monoid-Ring R = pair (multiplicative-semi-group-Ring R) (is-unital-Ring R) unit-Ring : {l : Level} (R : Ring l) → type-Ring R unit-Ring R = unit-Monoid (multiplicative-monoid-Ring R) left-unit-law-mul-Ring : {l : Level} (R : Ring l) (x : type-Ring R) → Id (mul-Ring R (unit-Ring R) x) x left-unit-law-mul-Ring R = left-unit-law-Monoid (multiplicative-monoid-Ring R) right-unit-law-mul-Ring : {l : Level} (R : Ring l) (x : type-Ring R) → Id (mul-Ring R x (unit-Ring R)) x right-unit-law-mul-Ring R = right-unit-law-Monoid (multiplicative-monoid-Ring R) left-distributive-law-mul-add-Ring : {l : Level} (R : Ring l) (x y z : type-Ring R) → Id ( mul-Ring R x (add-Ring R y z)) ( add-Ring R (mul-Ring R x y) (mul-Ring R x z)) left-distributive-law-mul-add-Ring R = pr1 (pr2 (pr2 (pr2 R))) right-distributive-law-mul-add-Ring : {l : Level} (R : Ring l) (x y z : type-Ring R) → Id ( mul-Ring R (add-Ring R x y) z) ( add-Ring R (mul-Ring R x z) (mul-Ring R y z)) right-distributive-law-mul-add-Ring R = pr2 (pr2 (pr2 (pr2 R))) {- Ring homomorphisms -} preserves-mul-hom-Ab : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → hom-Ab (ab-Ring R1) (ab-Ring R2) → UU (l1 ⊔ l2) preserves-mul-hom-Ab R1 R2 f = (x y : type-Ring R1) → Id ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f (mul-Ring R1 x y)) ( mul-Ring R2 ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f x) ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f y)) is-prop-preserves-mul-hom-Ab : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → ( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) → is-prop (preserves-mul-hom-Ab R1 R2 f) is-prop-preserves-mul-hom-Ab R1 R2 f = is-prop-Π ( λ x → is-prop-Π ( λ y → is-set-type-Ring R2 ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f (mul-Ring R1 x y)) ( mul-Ring R2 ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f x) ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f y)))) preserves-unit-hom-Ab : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → hom-Ab (ab-Ring R1) (ab-Ring R2) → UU l2 preserves-unit-hom-Ab R1 R2 f = Id (map-hom-Ab (ab-Ring R1) (ab-Ring R2) f (unit-Ring R1)) (unit-Ring R2) is-prop-preserves-unit-hom-Ab : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → ( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) → is-prop (preserves-unit-hom-Ab R1 R2 f) is-prop-preserves-unit-hom-Ab R1 R2 f = is-set-type-Ring R2 ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f (unit-Ring R1)) ( unit-Ring R2) is-ring-homomorphism-hom-Ab : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → ( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) → UU (l1 ⊔ l2) is-ring-homomorphism-hom-Ab R1 R2 f = preserves-mul-hom-Ab R1 R2 f × preserves-unit-hom-Ab R1 R2 f is-prop-is-ring-homomorphism-hom-Ab : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → ( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) → is-prop (is-ring-homomorphism-hom-Ab R1 R2 f) is-prop-is-ring-homomorphism-hom-Ab R1 R2 f = is-prop-prod ( is-prop-preserves-mul-hom-Ab R1 R2 f) ( is-prop-preserves-unit-hom-Ab R1 R2 f) hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R : Ring l2) → UU (l1 ⊔ l2) hom-Ring R1 R2 = Σ (hom-Ab (ab-Ring R1) (ab-Ring R2)) (is-ring-homomorphism-hom-Ab R1 R2) {- Basic infrastructure for ring homomorphisms. -} hom-Ab-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → hom-Ring R1 R2 → hom-Ab (ab-Ring R1) (ab-Ring R2) hom-Ab-hom-Ring R1 R2 = pr1 map-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → hom-Ring R1 R2 → type-Ring R1 → type-Ring R2 map-hom-Ring R1 R2 f = map-hom-Ab (ab-Ring R1) (ab-Ring R2) (hom-Ab-hom-Ring R1 R2 f) preserves-add-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → (f : hom-Ring R1 R2) → preserves-add (ab-Ring R1) (ab-Ring R2) (map-hom-Ring R1 R2 f) preserves-add-hom-Ring R1 R2 f = preserves-add-Ab (ab-Ring R1) (ab-Ring R2) (hom-Ab-hom-Ring R1 R2 f) preserves-mul-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → (f : hom-Ring R1 R2) → preserves-mul-hom-Ab R1 R2 (hom-Ab-hom-Ring R1 R2 f) preserves-mul-hom-Ring R1 R2 f = pr1 (pr2 f) preserves-unit-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → (f : hom-Ring R1 R2) → preserves-unit-hom-Ab R1 R2 (hom-Ab-hom-Ring R1 R2 f) preserves-unit-hom-Ring R1 R2 f = pr2 (pr2 f) is-ring-homomorphism-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → (f : hom-Ring R1 R2) → prod ( preserves-mul-hom-Ab R1 R2 (hom-Ab-hom-Ring R1 R2 f)) ( preserves-unit-hom-Ab R1 R2 (hom-Ab-hom-Ring R1 R2 f)) is-ring-homomorphism-hom-Ring R1 R2 f = pair ( preserves-mul-hom-Ring R1 R2 f) ( preserves-unit-hom-Ring R1 R2 f) {- We characterize the identity type of ring homomorphisms -} htpy-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → hom-Ring R1 R2 → hom-Ring R1 R2 → UU (l1 ⊔ l2) htpy-hom-Ring R1 R2 f g = map-hom-Ring R1 R2 f ~ map-hom-Ring R1 R2 g reflexive-htpy-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → (f : hom-Ring R1 R2) → htpy-hom-Ring R1 R2 f f reflexive-htpy-hom-Ring R1 R2 f = refl-htpy htpy-hom-Ring-eq : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → (f g : hom-Ring R1 R2) → Id f g → htpy-hom-Ring R1 R2 f g htpy-hom-Ring-eq R1 R2 f .f refl = reflexive-htpy-hom-Ring R1 R2 f is-contr-total-htpy-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → is-contr (Σ (hom-Ring R1 R2) (htpy-hom-Ring R1 R2 f)) is-contr-total-htpy-hom-Ring R1 R2 f = is-contr-total-Eq-substructure ( is-contr-total-htpy-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( hom-Ab-hom-Ring R1 R2 f)) ( is-prop-is-ring-homomorphism-hom-Ab R1 R2) ( hom-Ab-hom-Ring R1 R2 f) ( reflexive-htpy-hom-Ring R1 R2 f) ( is-ring-homomorphism-hom-Ring R1 R2 f) is-equiv-htpy-hom-Ring-eq : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f g : hom-Ring R1 R2) → is-equiv (htpy-hom-Ring-eq R1 R2 f g) is-equiv-htpy-hom-Ring-eq R1 R2 f = fundamental-theorem-id f ( reflexive-htpy-hom-Ring R1 R2 f) ( is-contr-total-htpy-hom-Ring R1 R2 f) ( htpy-hom-Ring-eq R1 R2 f) equiv-htpy-hom-Ring-eq : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f g : hom-Ring R1 R2) → Id f g ≃ htpy-hom-Ring R1 R2 f g equiv-htpy-hom-Ring-eq R1 R2 f g = pair ( htpy-hom-Ring-eq R1 R2 f g) ( is-equiv-htpy-hom-Ring-eq R1 R2 f g) eq-htpy-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f g : hom-Ring R1 R2) → htpy-hom-Ring R1 R2 f g → Id f g eq-htpy-hom-Ring R1 R2 f g = inv-is-equiv (is-equiv-htpy-hom-Ring-eq R1 R2 f g) is-set-hom-Ring : {l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → is-set (hom-Ring R1 R2) is-set-hom-Ring R1 R2 = is-trunc-succ-subtype ( neg-one-𝕋) ( is-prop-is-ring-homomorphism-hom-Ab R1 R2) ( is-set-hom-Ab (ab-Ring R1) (ab-Ring R2)) {- We define the categorical structure of rings -} preserves-mul-id-hom-Ring : {l : Level} (R : Ring l) → preserves-mul-hom-Ab R R (id-hom-Ab (ab-Ring R)) preserves-mul-id-hom-Ring R x y = refl preserves-unit-id-hom-Ring : {l : Level} (R : Ring l) → preserves-unit-hom-Ab R R (id-hom-Ab (ab-Ring R)) preserves-unit-id-hom-Ring R = refl is-ring-homomorphism-id-hom-Ring : {l : Level} (R : Ring l) → is-ring-homomorphism-hom-Ab R R (id-hom-Ab (ab-Ring R)) is-ring-homomorphism-id-hom-Ring R = pair (preserves-mul-id-hom-Ring R) (preserves-unit-id-hom-Ring R) id-hom-Ring : {l : Level} (R : Ring l) → hom-Ring R R id-hom-Ring R = pair (id-hom-Ab (ab-Ring R)) (is-ring-homomorphism-id-hom-Ring R) hom-Ab-comp-hom-Ring : { l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) → ( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) → hom-Ab (ab-Ring R1) (ab-Ring R3) hom-Ab-comp-hom-Ring R1 R2 R3 g f = comp-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( ab-Ring R3) ( hom-Ab-hom-Ring R2 R3 g) ( hom-Ab-hom-Ring R1 R2 f) preserves-mul-comp-hom-Ring : { l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) → ( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) → preserves-mul-hom-Ab R1 R3 (hom-Ab-comp-hom-Ring R1 R2 R3 g f) preserves-mul-comp-hom-Ring R1 R2 R3 g f x y = ( ap (map-hom-Ring R2 R3 g) (preserves-mul-hom-Ring R1 R2 f x y)) ∙ ( preserves-mul-hom-Ring R2 R3 g ( map-hom-Ring R1 R2 f x) ( map-hom-Ring R1 R2 f y)) preserves-unit-comp-hom-Ring : { l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) → ( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) → preserves-unit-hom-Ab R1 R3 (hom-Ab-comp-hom-Ring R1 R2 R3 g f) preserves-unit-comp-hom-Ring R1 R2 R3 g f = ( ap (map-hom-Ring R2 R3 g) (preserves-unit-hom-Ring R1 R2 f)) ∙ ( preserves-unit-hom-Ring R2 R3 g) is-ring-homomorphism-comp-hom-Ring : { l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) → ( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) → is-ring-homomorphism-hom-Ab R1 R3 (hom-Ab-comp-hom-Ring R1 R2 R3 g f) is-ring-homomorphism-comp-hom-Ring R1 R2 R3 g f = pair ( preserves-mul-comp-hom-Ring R1 R2 R3 g f) ( preserves-unit-comp-hom-Ring R1 R2 R3 g f) comp-hom-Ring : { l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) → hom-Ring R2 R3 → hom-Ring R1 R2 → hom-Ring R1 R3 comp-hom-Ring R1 R2 R3 g f = pair ( hom-Ab-comp-hom-Ring R1 R2 R3 g f) ( is-ring-homomorphism-comp-hom-Ring R1 R2 R3 g f) {- We prove the laws of a category for Rings -} is-associative-comp-hom-Ring : { l1 l2 l3 l4 : Level} ( R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) (R4 : Ring l4) → ( h : hom-Ring R3 R4) (g : hom-Ring R2 R3) (f : hom-Ring R1 R2) → Id (comp-hom-Ring R1 R2 R4 (comp-hom-Ring R2 R3 R4 h g) f) (comp-hom-Ring R1 R3 R4 h (comp-hom-Ring R1 R2 R3 g f)) is-associative-comp-hom-Ring R1 R2 R3 R4 h g f = eq-htpy-hom-Ring R1 R4 ( comp-hom-Ring R1 R2 R4 (comp-hom-Ring R2 R3 R4 h g) f) ( comp-hom-Ring R1 R3 R4 h (comp-hom-Ring R1 R2 R3 g f)) ( refl-htpy) left-unit-law-comp-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → Id (comp-hom-Ring R1 R2 R2 (id-hom-Ring R2) f) f left-unit-law-comp-hom-Ring R1 R2 f = eq-htpy-hom-Ring R1 R2 ( comp-hom-Ring R1 R2 R2 (id-hom-Ring R2) f) ( f) ( refl-htpy) right-unit-law-comp-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → Id (comp-hom-Ring R1 R1 R2 f (id-hom-Ring R1)) f right-unit-law-comp-hom-Ring R1 R2 f = eq-htpy-hom-Ring R1 R2 ( comp-hom-Ring R1 R1 R2 f (id-hom-Ring R1)) ( f) ( refl-htpy) {- We show that the forgetful map ab-Ring is a functor -} id-law-ab-Ring : { l1 : Level} (R1 : Ring l1) → Id (hom-Ab-hom-Ring R1 R1 (id-hom-Ring R1)) (id-hom-Ab (ab-Ring R1)) id-law-ab-Ring R1 = eq-htpy-hom-Ab ( ab-Ring R1) ( ab-Ring R1) ( refl-htpy) comp-law-ab-Ring : { l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) → ( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) → Id ( hom-Ab-hom-Ring R1 R3 (comp-hom-Ring R1 R2 R3 g f)) ( comp-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( ab-Ring R3) ( hom-Ab-hom-Ring R2 R3 g) ( hom-Ab-hom-Ring R1 R2 f)) comp-law-ab-Ring R1 R2 R3 g f = eq-htpy-hom-Ab ( ab-Ring R1) ( ab-Ring R3) ( refl-htpy) {- We introduce ring isomorphisms -} is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → hom-Ring R1 R2 → UU (l1 ⊔ l2) is-iso-hom-Ring R1 R2 f = Σ ( hom-Ring R2 R1) ( λ g → ( Id (comp-hom-Ring R2 R1 R2 f g) (id-hom-Ring R2)) × ( Id (comp-hom-Ring R1 R2 R1 g f) (id-hom-Ring R1))) {- Infrastructure for invertible ring homomorphisms -} inv-is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → is-iso-hom-Ring R1 R2 f → hom-Ring R2 R1 inv-is-iso-hom-Ring R1 R2 f = pr1 is-sec-inv-is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → ( is-iso-f : is-iso-hom-Ring R1 R2 f) → Id (comp-hom-Ring R2 R1 R2 f (inv-is-iso-hom-Ring R1 R2 f is-iso-f)) (id-hom-Ring R2) is-sec-inv-is-iso-hom-Ring R1 R2 f is-iso-f = pr1 (pr2 is-iso-f) is-retr-inv-is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → ( is-iso-f : is-iso-hom-Ring R1 R2 f) → Id (comp-hom-Ring R1 R2 R1 (inv-is-iso-hom-Ring R1 R2 f is-iso-f) f) (id-hom-Ring R1) is-retr-inv-is-iso-hom-Ring R1 R2 f is-iso-f = pr2 (pr2 is-iso-f) inv-map-is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → is-iso-hom-Ring R1 R2 f → type-Ring R2 → type-Ring R1 inv-map-is-iso-hom-Ring R1 R2 f is-iso-f = map-hom-Ring R2 R1 (inv-is-iso-hom-Ring R1 R2 f is-iso-f) is-sec-inv-map-is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → ( is-iso-f : is-iso-hom-Ring R1 R2 f) → ( (map-hom-Ring R1 R2 f) ∘ (inv-map-is-iso-hom-Ring R1 R2 f is-iso-f)) ~ id is-sec-inv-map-is-iso-hom-Ring R1 R2 f is-iso-f = htpy-hom-Ring-eq R2 R2 ( comp-hom-Ring R2 R1 R2 f (inv-is-iso-hom-Ring R1 R2 f is-iso-f)) ( id-hom-Ring R2) ( is-sec-inv-is-iso-hom-Ring R1 R2 f is-iso-f) is-retr-inv-map-is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → ( is-iso-f : is-iso-hom-Ring R1 R2 f) → ( (inv-map-is-iso-hom-Ring R1 R2 f is-iso-f) ∘ (map-hom-Ring R1 R2 f)) ~ id is-retr-inv-map-is-iso-hom-Ring R1 R2 f is-iso-f = htpy-hom-Ring-eq R1 R1 ( comp-hom-Ring R1 R2 R1 (inv-is-iso-hom-Ring R1 R2 f is-iso-f) f) ( id-hom-Ring R1) ( is-retr-inv-is-iso-hom-Ring R1 R2 f is-iso-f) {- Being invertible is a property -} is-prop-is-iso-hom-Ring' : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → is-prop' (is-iso-hom-Ring R1 R2 f) is-prop-is-iso-hom-Ring' R1 R2 f inv-f inv-f' = eq-subtype ( λ g → is-prop-prod ( is-set-hom-Ring R2 R2 (comp-hom-Ring R2 R1 R2 f g) (id-hom-Ring R2)) ( is-set-hom-Ring R1 R1 (comp-hom-Ring R1 R2 R1 g f) (id-hom-Ring R1))) ( eq-htpy-hom-Ring R2 R1 ( inv-is-iso-hom-Ring R1 R2 f inv-f) ( inv-is-iso-hom-Ring R1 R2 f inv-f') ( λ x → ( inv ( ap ( map-hom-Ring R2 R1 (pr1 inv-f)) ( is-sec-inv-map-is-iso-hom-Ring R1 R2 f inv-f' x))) ∙ ( is-retr-inv-map-is-iso-hom-Ring R1 R2 f inv-f ( map-hom-Ring R2 R1 (pr1 inv-f') x)))) is-prop-is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → is-prop (is-iso-hom-Ring R1 R2 f) is-prop-is-iso-hom-Ring R1 R2 f = is-prop-is-prop' (is-prop-is-iso-hom-Ring' R1 R2 f) iso-Ring : { l1 l2 : Level} → Ring l1 → Ring l2 → UU (l1 ⊔ l2) iso-Ring R1 R2 = Σ (hom-Ring R1 R2) (is-iso-hom-Ring R1 R2) hom-iso-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → iso-Ring R1 R2 → hom-Ring R1 R2 hom-iso-Ring R1 R2 = pr1 is-iso-hom-iso-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → ( f : iso-Ring R1 R2) → is-iso-hom-Ring R1 R2 (hom-iso-Ring R1 R2 f) is-iso-hom-iso-Ring R1 R2 = pr2 inv-hom-iso-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → iso-Ring R1 R2 → hom-Ring R2 R1 inv-hom-iso-Ring R1 R2 f = inv-is-iso-hom-Ring R1 R2 ( hom-iso-Ring R1 R2 f) ( is-iso-hom-iso-Ring R1 R2 f) is-iso-id-hom-Ring : { l1 : Level} (R1 : Ring l1) → is-iso-hom-Ring R1 R1 (id-hom-Ring R1) is-iso-id-hom-Ring R1 = pair ( id-hom-Ring R1) ( pair ( left-unit-law-comp-hom-Ring R1 R1 (id-hom-Ring R1)) ( left-unit-law-comp-hom-Ring R1 R1 (id-hom-Ring R1))) id-iso-Ring : { l1 : Level} (R1 : Ring l1) → iso-Ring R1 R1 id-iso-Ring R1 = pair (id-hom-Ring R1) (is-iso-id-hom-Ring R1) iso-eq-Ring : { l : Level} (R1 R2 : Ring l) → Id R1 R2 → iso-Ring R1 R2 iso-eq-Ring R1 .R1 refl = id-iso-Ring R1 {- We first show that a ring homomorphism is an isomorphism if and only if the underlying homomorphism of abelian groups is an isomorphism. -} is-iso-hom-Ab-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → hom-Ring R1 R2 → UU (l1 ⊔ l2) is-iso-hom-Ab-hom-Ring R1 R2 f = is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) (hom-Ab-hom-Ring R1 R2 f) is-iso-hom-Ab-is-iso-hom-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → is-iso-hom-Ring R1 R2 f → is-iso-hom-Ab-hom-Ring R1 R2 f is-iso-hom-Ab-is-iso-hom-Ring R1 R2 f is-iso-f = pair ( hom-Ab-hom-Ring R2 R1 (inv-is-iso-hom-Ring R1 R2 f is-iso-f)) ( pair ( ap ( hom-Ab-hom-Ring R2 R2) ( is-sec-inv-is-iso-hom-Ring R1 R2 f is-iso-f)) ( ap ( hom-Ab-hom-Ring R1 R1) ( is-retr-inv-is-iso-hom-Ring R1 R2 f is-iso-f))) abstract preserves-mul-inv-is-iso-hom-Ab : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → ( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) → ( is-iso-f : is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f) → ( pres-mul-f : preserves-mul-hom-Ab R1 R2 f) → preserves-mul-hom-Ab R2 R1 ( inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f) preserves-mul-inv-is-iso-hom-Ab R1 R2 f is-iso-f pres-mul-f x y = ( inv ( ap ( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f) ( ( pres-mul-f ( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f x) ( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f y)) ∙ ( ( ap ( mul-Ring R2 ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f ( map-inv-is-iso-hom-Ab ( ab-Ring R1) ( ab-Ring R2) f is-iso-f x))) ( is-sec-map-inv-is-iso-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( f) ( is-iso-f) ( y))) ∙ ( ap ( λ z → mul-Ring R2 z y) ( is-sec-map-inv-is-iso-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( f) ( is-iso-f) ( x))))))) ∙ ( is-retr-map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f ( mul-Ring R1 ( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f x) ( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f y))) preserves-unit-inv-is-iso-hom-Ab : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) ( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) → ( is-iso-f : is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f) ( pres-unit-f : preserves-unit-hom-Ab R1 R2 f) → preserves-unit-hom-Ab R2 R1 ( inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f) preserves-unit-inv-is-iso-hom-Ab R1 R2 f is-iso-f pres-unit-f = ( inv ( ap ( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f) ( pres-unit-f))) ∙ ( is-retr-map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f ( unit-Ring R1)) is-ring-homomorphism-inv-is-iso-hom-Ab : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) ( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) → ( is-iso-f : is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f) → ( is-ring-hom-f : is-ring-homomorphism-hom-Ab R1 R2 f) → is-ring-homomorphism-hom-Ab R2 R1 ( inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f) is-ring-homomorphism-inv-is-iso-hom-Ab R1 R2 f is-iso-f (pair pres-mul-f pres-unit-f) = pair ( preserves-mul-inv-is-iso-hom-Ab R1 R2 f is-iso-f pres-mul-f) ( preserves-unit-inv-is-iso-hom-Ab R1 R2 f is-iso-f pres-unit-f) inv-hom-Ring-is-iso-hom-Ab : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) → ( is-iso-f : is-iso-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( hom-Ab-hom-Ring R1 R2 f)) → hom-Ring R2 R1 inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f = pair ( inv-is-iso-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( hom-Ab-hom-Ring R1 R2 f) ( is-iso-f)) ( is-ring-homomorphism-inv-is-iso-hom-Ab R1 R2 ( hom-Ab-hom-Ring R1 R2 f) ( is-iso-f) ( is-ring-homomorphism-hom-Ring R1 R2 f)) abstract is-iso-hom-Ring-is-iso-hom-Ab : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) ( f : hom-Ring R1 R2) → is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) (hom-Ab-hom-Ring R1 R2 f) → is-iso-hom-Ring R1 R2 f is-iso-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f = pair ( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f) ( pair ( eq-htpy-hom-Ring R2 R2 ( comp-hom-Ring R2 R1 R2 f ( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f)) ( id-hom-Ring R2) ( htpy-hom-Ab-eq (ab-Ring R2) (ab-Ring R2) ( hom-Ab-hom-Ring R2 R2 ( comp-hom-Ring R2 R1 R2 f ( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f))) ( id-hom-Ab (ab-Ring R2)) ( is-sec-inv-is-iso-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( hom-Ab-hom-Ring R1 R2 f) ( is-iso-f)))) ( eq-htpy-hom-Ring R1 R1 ( comp-hom-Ring R1 R2 R1 ( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f) ( f)) ( id-hom-Ring R1) ( htpy-hom-Ab-eq (ab-Ring R1) (ab-Ring R1) ( hom-Ab-hom-Ring R1 R1 ( comp-hom-Ring R1 R2 R1 ( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f) ( f))) ( id-hom-Ab (ab-Ring R1)) ( is-retr-inv-is-iso-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( hom-Ab-hom-Ring R1 R2 f) ( is-iso-f))))) iso-Ab-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → UU (l1 ⊔ l2) iso-Ab-Ring R1 R2 = Σ ( iso-Ab (ab-Ring R1) (ab-Ring R2)) ( λ f → is-ring-homomorphism-hom-Ab R1 R2 ( hom-iso-Ab (ab-Ring R1) (ab-Ring R2) f)) iso-Ab-iso-Ab-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → iso-Ab-Ring R1 R2 → iso-Ab (ab-Ring R1) (ab-Ring R2) iso-Ab-iso-Ab-Ring R1 R2 = pr1 iso-Ab-iso-Ring : { l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → iso-Ring R1 R2 → iso-Ab (ab-Ring R1) (ab-Ring R2) iso-Ab-iso-Ring R1 R2 f = pair ( hom-Ab-hom-Ring R1 R2 (hom-iso-Ring R1 R2 f)) ( is-iso-hom-Ab-is-iso-hom-Ring R1 R2 ( hom-iso-Ring R1 R2 f) ( is-iso-hom-iso-Ring R1 R2 f)) equiv-iso-Ab-iso-Ring : { l1 : Level} (R1 : Ring l1) (R2 : Ring l1) → (iso-Ring R1 R2) ≃ (iso-Ab-Ring R1 R2) equiv-iso-Ab-iso-Ring R1 R2 = ( ( ( inv-equiv ( equiv-Σ-assoc ( hom-Ab (ab-Ring R1) (ab-Ring R2)) ( is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2)) ( λ f → is-ring-homomorphism-hom-Ab R1 R2 (pr1 f)))) ∘e ( equiv-tot ( λ f → equiv-swap-prod ( is-ring-homomorphism-hom-Ab R1 R2 f) ( is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f)))) ∘e ( equiv-Σ-assoc ( hom-Ab (ab-Ring R1) (ab-Ring R2)) ( is-ring-homomorphism-hom-Ab R1 R2) ( λ f → is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) (pr1 f)))) ∘e ( equiv-total-subtype ( is-prop-is-iso-hom-Ring R1 R2) ( λ f → is-prop-is-iso-hom-Ab ( ab-Ring R1) ( ab-Ring R2) ( hom-Ab-hom-Ring R1 R2 f)) ( is-iso-hom-Ab-is-iso-hom-Ring R1 R2) ( is-iso-hom-Ring-is-iso-hom-Ab R1 R2)) abstract is-contr-total-iso-Ring : { l : Level} (R : Ring l) → is-contr (Σ (Ring l) (iso-Ring R)) is-contr-total-iso-Ring {l} R = is-contr-equiv ( Σ (Ring l) (iso-Ab-Ring R)) ( equiv-tot (equiv-iso-Ab-iso-Ring R)) ( is-contr-total-Eq-structure ( λ A μ f → is-ring-homomorphism-hom-Ab R (pair A μ) (hom-iso-Ab (ab-Ring R) A f)) ( is-contr-total-iso-Ab (ab-Ring R)) ( pair (ab-Ring R) (id-iso-Ab (ab-Ring R))) ( is-contr-total-Eq-structure ( λ μ H pres-mul → Id (unit-Ring R) (pr1 (pr1 H))) ( is-contr-total-Eq-substructure ( is-contr-total-Eq-Π ( λ x m → (y : type-Ring R) → Id (mul-Ring R x y) (m y)) ( λ x → is-contr-total-htpy (mul-Ring R x)) ( mul-Ring R)) ( λ μ → is-prop-Π (λ x → is-prop-Π (λ y → is-prop-Π (λ z → is-set-type-Ring R (μ (μ x y) z) (μ x (μ y z)))))) ( mul-Ring R) ( λ x y → refl) ( is-associative-mul-Ring R)) ( pair (pair (mul-Ring R) (is-associative-mul-Ring R)) (λ x y → refl)) ( is-contr-total-Eq-substructure ( is-contr-total-Eq-substructure ( is-contr-total-path (unit-Ring R)) ( λ x → is-prop-prod ( is-prop-Π (λ y → is-set-type-Ring R (mul-Ring R x y) y)) ( is-prop-Π (λ y → is-set-type-Ring R (mul-Ring R y x) y))) ( unit-Ring R) ( refl) ( pair (left-unit-law-mul-Ring R) (right-unit-law-mul-Ring R))) ( λ u → is-prop-prod ( is-prop-Π (λ x → is-prop-Π (λ y → is-prop-Π (λ z → is-set-type-Ring R ( mul-Ring R x (add-Ring R y z)) ( add-Ring R (mul-Ring R x y) (mul-Ring R x z)))))) ( is-prop-Π (λ x → is-prop-Π (λ y → is-prop-Π (λ z → is-set-type-Ring R ( mul-Ring R (add-Ring R x y) z) ( add-Ring R (mul-Ring R x z) (mul-Ring R y z))))))) ( is-unital-Ring R) ( refl) ( pair ( left-distributive-law-mul-add-Ring R) ( right-distributive-law-mul-add-Ring R))))) is-equiv-iso-eq-Ring : { l : Level} (R S : Ring l) → is-equiv (iso-eq-Ring R S) is-equiv-iso-eq-Ring R = fundamental-theorem-id R ( id-iso-Ring R) ( is-contr-total-iso-Ring R) ( iso-eq-Ring R) eq-iso-Ring : { l : Level} (R S : Ring l) → iso-Ring R S → Id R S eq-iso-Ring R S = inv-is-equiv (is-equiv-iso-eq-Ring R S)
35.796386
84
0.568813
0bd01c9eea94a2fa87cc7db884a1d2eba3349bcd
189
agda
Agda
agda/Text/Greek/Bible.agda
scott-fleischman/GreekGrammar
915c46c27c7f8aad5907474d8484f2685a4cd6a7
[ "MIT" ]
44
2015-05-29T14:48:51.000Z
2022-03-06T15:41:57.000Z
agda/Text/Greek/Bible.agda
scott-fleischman/GreekGrammar
915c46c27c7f8aad5907474d8484f2685a4cd6a7
[ "MIT" ]
13
2015-05-28T20:04:08.000Z
2020-09-07T11:58:38.000Z
agda/Text/Greek/Bible.agda
scott-fleischman/GreekGrammar
915c46c27c7f8aad5907474d8484f2685a4cd6a7
[ "MIT" ]
5
2015-02-27T22:34:13.000Z
2017-06-11T11:25:09.000Z
module Text.Greek.Bible where open import Data.Nat open import Data.List open import Data.String open import Text.Greek.Script data Word : Set where word : (List Token) → String → Word
18.9
37
0.761905
18151dfc1725840d94ba9c955f3b948bc9c719f9
674
agda
Agda
examples/simple/quantifierIn/quantifierIn-output.agda
wenkokke/vehicle
41d8653d7e48a716f5085ec53171b29094669674
[ "BSD-3-Clause" ]
11
2021-02-24T05:55:15.000Z
2022-02-01T01:35:39.000Z
examples/simple/quantifierIn/quantifierIn-output.agda
wenkokke/vehicle
41d8653d7e48a716f5085ec53171b29094669674
[ "BSD-3-Clause" ]
53
2021-04-16T07:26:42.000Z
2021-12-15T22:42:01.000Z
examples/simple/quantifierIn/quantifierIn-output.agda
wenkokke/vehicle
41d8653d7e48a716f5085ec53171b29094669674
[ "BSD-3-Clause" ]
4
2021-03-15T15:22:31.000Z
2021-11-16T14:30:47.000Z
-- WARNING: This file was generated automatically by Vehicle -- and should not be modified manually! -- Metadata -- - Agda version: 2.6.2 -- - AISEC version: 0.1.0.1 -- - Time generated: ??? {-# OPTIONS --allow-exec #-} open import Vehicle open import Data.Unit open import Data.Integer as ℤ using (ℤ) open import Data.List open import Data.List.Relation.Unary.All as List module quantifierIn-output where private VEHICLE_PROJECT_FILE = "TODO_projectFile" emptyList : List ℤ emptyList = [] abstract empty : List.All (λ (x : ℤ) → ⊤) emptyList empty = checkProperty record { projectFile = VEHICLE_PROJECT_FILE ; propertyUUID = "TODO_propertyUUID" }
23.241379
60
0.712166
06e26da8ad2b577ac8a4ea4fb3426133ee656c4b
102
agda
Agda
test/Fail/RecordConstructorOutOfScope.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/RecordConstructorOutOfScope.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/RecordConstructorOutOfScope.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module RecordConstructorOutOfScope where record R : Set where constructor con id : R id = con
12.75
40
0.735294
506683638b448eaa7db2639625f20acdf257c007
4,757
agda
Agda
unused/Effect.agda
Zalastax/singly-typed-actors
ae541df13d069df4eb1464f29fbaa9804aad439f
[ "MIT" ]
1
2019-10-29T09:30:26.000Z
2019-10-29T09:30:26.000Z
unused/Effect.agda
Zalastax/singly-typed-actors
ae541df13d069df4eb1464f29fbaa9804aad439f
[ "MIT" ]
null
null
null
unused/Effect.agda
Zalastax/singly-typed-actors
ae541df13d069df4eb1464f29fbaa9804aad439f
[ "MIT" ]
null
null
null
module Effect where open import Data.List open import Data.List.All open import Data.List.Any open import Level open import Relation.Binary.PropositionalEquality hiding ([_]) open import Function open import Category.Monad open import Data.Product open import EffectUtil open import Membership-equality hiding (_⊆_; set) Effect : ∀ f → Set (suc f) Effect f = (result : Set f) (i : Set f) (o : result → Set f) → Set f record EFFECT (f : Level) : Set (suc f) where constructor mkEff field S : Set f E : Effect f updateResTy : ∀ {f A E i o} → (val : A) → (es : List (EFFECT f)) → (prf : (mkEff i E) ∈ es) → (eff : E A i o) → List (EFFECT f) updateResTy {o = o} val (mkEff i e ∷ es) (here px) eff = mkEff (o val) e ∷ es updateResTy val (e ∷ es) (there prf) eff = e ∷ updateResTy val es prf eff updateWith : ∀ {f ys} (ys' : List (EFFECT f)) → (xs : List (EFFECT f)) → (ys ⊆ xs) → List (EFFECT f) updateWith [] xs inc = xs updateWith (y' ∷ ys') xs [] = xs updateWith (y' ∷ ys') (_ ∷ xs) (keep inc) = y' ∷ updateWith ys' xs inc updateWith (y' ∷ ys') (x ∷ xs) (skip inc) = x ∷ updateWith (y' ∷ ys') xs inc Handler : ∀ {f} → (Set f → Set f) → Effect f → Set (suc f) Handler M e = ∀ {A a o res} → (r : res) → (eff : e A res o) → (k : ((x : A) → o x → M a)) → M a -- @ A The return type of the result -- @ es The list of allowed side-effects -- @ ce The function to compute a new list of allowed side-effects data EffM {f : Level} (m : Set f → Set f) : (A : Set f) → (es : List (EFFECT f)) → (ce : A → List (EFFECT f)) → Set (suc f) where return : ∀ {A ce} (val : A) → EffM m A (ce val) ce _>>=_ : ∀ {A B es ce₁ ce₂} → EffM m A es ce₁ → (∀ x → EffM m B (ce₁ x) ce₂) → EffM m B es ce₂ effect : ∀ {A E i es o} (prf : (mkEff i E) ∈ es) → (eff : E A i o) → EffM m A es (λ v → updateResTy v es prf eff) -- use to invoke sub-programs that use some or all of the available effects lift : ∀ {A ys ys' xs} → (inc : ys ⊆ xs) → EffM m A ys ys' → EffM m A xs (λ v → updateWith (ys' v) xs inc) new : ∀ {A es} → (e : EFFECT f) → (val : EFFECT.S e) → Handler m (EFFECT.E e) → EffM {f} m A (e ∷ es) (λ v → e ∷ es) → EffM m A es (λ v → es) pure : ∀ {l m A es} → A → EffM {l} m A es (λ v → es) pure = return _<*>_ : ∀ {l m A B es} → EffM {l} m (A → B) es (λ v → es) → EffM {l} m A es (λ v → es) → EffM {l} m B es (λ v → es) _<*>_ prog v = prog >>= λ fn → v >>= λ arg → pure (fn arg) _<$>_ : ∀ {l m A B es} → (f : A → B) → EffM {l} m A es (λ v → es) → EffM {l} m B es (λ v → es) _<$>_ f m = pure f <*> m data Env {f : Level} : (m : Set f → Set f) → List (EFFECT f) → Set (suc f) where [] : ∀ {m} → Env m [] _∷_ : ∀ {m eff es a} → (el : Handler m eff × a) → Env m es → Env m (mkEff a eff ∷ es) execEff : ∀ {f m A es E i} {o : A → Set f} {B} → Env {f} m es → (prf : (mkEff i E) ∈ es) → (eff : E A i o) → ((v : A) → Env {f} m (updateResTy v es prf eff) → m B) → m B execEff {m = m} {A = A} {o = o} {B = B} ((handle , val) ∷ env) (here refl) eff k = handle val eff cont where cont : (v : A) → o v → m B cont v res = k v ((handle , res) ∷ env) execEff (e ∷ env) (there prf) eff k = execEff env prf eff λ v → λ env' → k v (e ∷ env') dropEnv : ∀ {f m ys xs} → Env {f} m ys → xs ⊆ ys → Env m xs dropEnv [] [] = [] dropEnv (el ∷ env) [] = [] dropEnv (el ∷ env) (keep sub) = el ∷ (dropEnv env sub) dropEnv (el ∷ env) (skip sub) = dropEnv env sub rebuildEnv : ∀ {f m ys' ys xs} → Env {f} m ys' → (prf : ys ⊆ xs) → Env m xs → Env m (updateWith ys' xs prf) rebuildEnv [] [] env = env rebuildEnv (_ ∷ _) [] env = env rebuildEnv [] (keep prf) env = env rebuildEnv (el ∷ els) (keep prf) (_ ∷ env) = el ∷ rebuildEnv els prf env rebuildEnv [] (skip prf) env = env rebuildEnv (el ∷ els) (skip prf) (en ∷ env) = en ∷ rebuildEnv (el ∷ els) prf env eff : ∀ {f m es A B ce} → Env {f} m es → EffM m A es ce → ((v : A) → Env m (ce v) → m B) → m B eff env (return val) k = k val env eff env (effM >>= c) k = eff env effM λ p' → λ env' → eff env' ((c p')) k eff env (effect prf effP) k = execEff env prf effP k eff env (lift inc effM) k = eff env' effM λ p' → λ envk → k p' (rebuildEnv envk inc env) where env' = dropEnv env inc eff {f} {m} {es} {A} {B} env (new e val handler effM) k = eff ((handler , val) ∷ env) effM cont where cont : (v : A) → Env {f} m (e ∷ es) → m B cont v (val ∷ envk) = k v envk run : ∀ {f a xs xs'} → ∀ m → (mon : RawMonad m) → (prog : EffM {f} m a xs xs') → Env m xs → m a run m mon prog env = eff env prog λ r → λ env' → RawMonad.return mon r
39.31405
102
0.52407
12d9e3eabc73044131214bae4cd0b8f34d53f4f0
416
agda
Agda
Cubical/Experiments/NatMinusTwo/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Experiments/NatMinusTwo/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Experiments/NatMinusTwo/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-} module Cubical.Experiments.NatMinusTwo.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Data.Nat open import Cubical.Data.NatMinusOne using (ℕ₋₁) open import Cubical.Experiments.NatMinusTwo.Base -2+Path : ℕ ≡ ℕ₋₂ -2+Path = isoToPath (iso -2+_ 2+_ (λ _ → refl) (λ _ → refl))
34.666667
67
0.754808
0bcf3dd2e515293b0bbbfac93711b877c7b53c13
1,060
agda
Agda
examples/examplesPaperJFP/NativeIOSafe.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
23
2016-06-19T12:57:55.000Z
2020-10-12T23:15:25.000Z
examples/examplesPaperJFP/NativeIOSafe.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
null
null
null
examples/examplesPaperJFP/NativeIOSafe.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
2
2018-09-01T15:02:37.000Z
2022-03-12T11:41:00.000Z
module examplesPaperJFP.NativeIOSafe where open import Data.Maybe.Base using (Maybe; nothing; just) public open import Data.String.Base using (String) public record Unit : Set where constructor unit {-# COMPILE GHC Unit = () #-} postulate NativeIO : Set → Set nativeReturn : {A : Set} → A → NativeIO A _native>>=_ : {A B : Set} → NativeIO A → (A → NativeIO B) → NativeIO B {-# BUILTIN IO NativeIO #-} {-# COMPILE GHC NativeIO = IO #-} -- IO.FF-I.AgdaIO {-# COMPILE GHC _native>>=_ = (\_ _ -> (>>=) :: IO a -> (a -> IO b) -> IO b) #-} {-# COMPILE GHC nativeReturn = (\_ -> return :: a -> IO a) #-} postulate nativeGetLine : NativeIO (Maybe String) nativePutStrLn : String → NativeIO Unit {-# FOREIGN GHC import Data.Text #-} {-# FOREIGN GHC import System.IO.Error #-} {-# COMPILE GHC nativePutStrLn = (\ s -> putStrLn (Data.Text.unpack s)) #-} {-# COMPILE GHC nativeGetLine = (fmap (Just . Data.Text.pack) getLine `System.IO.Error.catchIOError` \ err -> if System.IO.Error.isEOFError err then return Nothing else ioError err) #-}
34.193548
185
0.65
506065a875fa7725e9a1b849cedc654e443e0653
10,092
agda
Agda
Categories/Support/SetoidPi.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Support/SetoidPi.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Support/SetoidPi.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
{-# OPTIONS --universe-polymorphism #-} module Categories.Support.SetoidPi where open import Level open import Function as Fun using (_on_) open import Relation.Binary as B using () renaming (_=[_]⇒_ to _=[_]⇒₀_; _⇒_ to _⊆_) open import Relation.Binary.PropositionalEquality as PE using (_≡_) open import Relation.Binary.HeterogeneousEquality using (_≅_) renaming (refl to ≅-refl) open import Relation.Binary.Indexed.Heterogeneous as I using (_=[_]⇒_) open import Categories.Support.Equivalence open import Categories.Support.SetoidFunctions as SF using (_⟶_) renaming (_⟨$⟩_ to _⟨$⟩₀_; cong to cong₀) open Setoid using () renaming (Carrier to Carrier₀; _≈_ to _[_≈_]) _⟶[_,_] : ∀ {cf ℓf} (From : Setoid cf ℓf) (ct ℓt : Level) → Set (cf ⊔ ℓf ⊔ suc (ct ⊔ ℓt)) From ⟶[ ct , ℓt ] = From ⟶ set→setoid (Setoid ct ℓt) ------------------------------------------------------------------------ -- Indexed binary relations ------------------------------------------------------------------------ record IndexedSetoid {i iℓ} (I : Set i) (_∼_ : B.Rel I iℓ) c ℓ : Set (suc (i ⊔ iℓ ⊔ c ⊔ ℓ)) where infix 4 _≈_ field Carrier : I → Set c _≈_ : I.IRel Carrier ℓ .isEquivalence : I.IsIndexedEquivalence Carrier _≈_ -- NOTE one more field, see resp below -- no irrelevant opens ☹ -- .open I.IsEquivalence isEquivalence public private module E = I.IsIndexedEquivalence .refl : I.Reflexive Carrier _≈_ refl = E.refl isEquivalence .sym : I.Symmetric Carrier _≈_ sym = E.sym isEquivalence .trans : I.Transitive Carrier _≈_ trans = E.trans isEquivalence .reflexive : ∀ {i} → _≡_ ⊆ (_≈_ {i}) reflexive = E.reflexive isEquivalence -- conversion to regular setoids by evaluating at an index _at_ : I → Setoid c ℓ _at_ i = record { Carrier = Carrier i ; _≈_ = _≈_ ; isEquivalence = record { refl = E.refl isEquivalence ; sym = E.sym isEquivalence ; trans = E.trans isEquivalence } } -- XXX ideally i should redo the resp stuff and promotion and everything -- with the proper setoid of setoids under equivalence, but first i didn't -- make it yet and second OH MY GOD ─xplat Resp-Type = _∼_ =[ _at_ ]⇒₀ _≡_ {A = Setoid c ℓ} field .resp : Resp-Type resp-per : ∀ {c ℓ} {C₁ C₂ : Set c} {_≈₁_ : B.Rel C₁ ℓ} {_≈₂_ : B.Rel C₂ ℓ} {equiv₁ : B.IsEquivalence _≈₁_} {equiv₂ : B.IsEquivalence _≈₂_} → C₁ ≡ C₂ → _≈₁_ ≅ _≈₂_ → _≡_ {A = Setoid c ℓ} record {Carrier = C₁; _≈_ = _≈₁_; isEquivalence = equiv₁} record {Carrier = C₂; _≈_ = _≈₂_; isEquivalence = equiv₂} resp-per _≡_.refl ≅-refl = _≡_.refl .resp-per′ : ∀ {c ℓ} (S T : Setoid c ℓ) → (Carrier₀ S ≡ Carrier₀ T) → (Setoid._≈_ S ≅ Setoid._≈_ T) → S ≡ T resp-per′ S T = resp-per {equiv₁ = Setoid.isEquivalence S} {equiv₂ = Setoid.isEquivalence T} open IndexedSetoid using (_at_) weaken : ∀ {c ℓ} → Setoid c ℓ → ∀ {i iℓ} {I : Set i} {_∼_ : B.Rel I iℓ} → IndexedSetoid I _∼_ c ℓ weaken S {I = I} {_∼_} = record { Carrier = Fun.const S.Carrier ; _≈_ = S._≈_ ; isEquivalence = record { refl = S.refl; sym = S.sym; trans = S.trans } ; resp = Fun.const _≡_.refl } where module S = Setoid S {- -- this definition is unusable because agda spins in circles trying to infer -- ct and ℓt before it will extract any information from f's type, but f's -- type is the only thing it can infer them from... test is below ☹ _[$]_ : ∀ {cf ℓf ct ℓt} {From : Setoid cf ℓf} → (From ⟶[ ct , ℓt ]) → Carrier From → Set ct f [$] x = Carrier (f ⟨$⟩₀ x) .test : ∀ {cf ℓf ct ℓt} {From : Setoid cf ℓf} (To : From ⟶[ ct , ℓt ]) (x : Carrier From) → (_[$]_ {ct = ct}{ℓt = ℓt} To x) → Set ℓt test = {!!} -} -- i think this approach would work beautifully with regular setoids, but -- with irrelevant setoids the type of cong can't depend on localize -- ─ xplat -- .localize : ∀ {cf ℓf ct ℓt} {From : Setoid cf ℓf} (To : From ⟶[ ct , ℓt ]) {x y : Carrier₀ From} → From [ x ≈ y ] → B.REL (Carrier₀ (To ⟨$⟩₀ x)) (Carrier₀ (To ⟨$⟩₀ y)) ℓt -- localize To {x} x≈y with To ⟨$⟩₀ x | cong₀ To x≈y -- localize To x≈y | ._ | _≡_.refl = Setoid._≈_ (To ⟨$⟩₀ _) -- ... so it's on to yet another annoying heterogeneous equality type module SetoidHetero {cf ℓf} (From : Setoid cf ℓf) (ct ℓt : Level) (To : From ⟶[ ct , ℓt ]) where I = Carrier₀ From To$ = _⟨$⟩₀_ To To$C = Fun._∘_ Carrier₀ (_⟨$⟩₀_ To) localize′ : ∀ {S T : Setoid ct ℓt} → (S ≡ T) → B.REL (Carrier₀ S) (Carrier₀ T) ℓt -- localize′ {S} {T} S≡T localize′ {S} _≡_.refl = Setoid._≈_ S localize : ∀ {x y : I} → (To$ x ≡ To$ y) → B.REL (To$C x) (To$C y) ℓt localize {x} {y} To$x≡To$y with To$ y localize {x} _≡_.refl | ._ = Setoid._≈_ (To$ x) data _≈∗_ {S T : Setoid ct ℓt} (x : Carrier₀ S) : (y : Carrier₀ T) → Set (suc (ct ⊔ ℓt)) where locally : (S≡T : S ≡ T) {y : Carrier₀ T} (x≈y : localize′ S≡T x y) → _≈∗_ {S} {T} x y _≈⋆_ : {iˣ iʸ : I} → B.REL (To$C iˣ) (To$C iʸ) (suc (ct ⊔ ℓt)) _≈⋆_ {iˣ} {iʸ} = _≈∗_ {To$ iˣ} {To$ iʸ} asIndexed : ∀ {cf ℓf} ct ℓt {From : Setoid cf ℓf} → (From ⟶[ ct , ℓt ]) → IndexedSetoid (Carrier₀ From) (Setoid._≈_ From) ct (suc (ct ⊔ ℓt)) asIndexed ct ℓt {From} To = record { Carrier = To$C ; _≈_ = _≈⋆_ ; isEquivalence = record { refl = my-refl ; sym = my-sym ; trans = my-trans } ; resp = λ {i j} i∼j → resp-per′ (fake-at i) (fake-at j) (resp-helper i∼j) (resp-helper₂ i∼j) } where open SetoidHetero _ ct ℓt To .my-refl : I.Reflexive To$C _≈⋆_ my-refl {i} {x} = locally {To$ i} _≡_.refl ((Setoid.refl (To$ i))) .sym-helper : ∀ i j (To$i≡To$j : To$ i ≡ To$ j) (x : To$C i) (y : To$C j) (x≈y : localize′ To$i≡To$j x y) → localize′ (PE.sym To$i≡To$j) y x sym-helper i j To$i≡To$j x y with To$ j sym-helper i j _≡_.refl x y | ._ = Setoid.sym (To$ i) .my-sym : I.Symmetric To$C _≈⋆_ my-sym {i} {j} {x} {y} (locally To$i≡To$j x≈y) = locally (PE.sym To$i≡To$j) (sym-helper i j To$i≡To$j x y x≈y) .trans-helper : ∀ i j k (To$i≡To$j : To$ i ≡ To$ j) (To$j≡To$k : To$ j ≡ To$ k) (x : To$C i) (y : To$C j) (z : To$C k) (x≈y : localize′ To$i≡To$j x y) (y≈z : localize′ To$j≡To$k y z) → localize′ (PE.trans To$i≡To$j To$j≡To$k) x z trans-helper i j k To$i≡To$j To$j≡To$k x y z with To$ j | To$ k trans-helper i j k _≡_.refl _≡_.refl x y z | ._ | ._ = Setoid.trans (To$ i) .my-trans : I.Transitive To$C _≈⋆_ my-trans (locally To$i≡To$j x≈y) (locally To$j≡To$k y≈z) = locally (PE.trans To$i≡To$j To$j≡To$k) (trans-helper _ _ _ To$i≡To$j To$j≡To$k _ _ _ x≈y y≈z) .resp-helper : ∀ {i j} → From [ i ≈ j ] → To$C i ≡ To$C j resp-helper i∼j = PE.cong Carrier₀ (cong₀ To i∼j) .resp-helper₃ : (S T : Setoid ct ℓt) → S ≡ T → _≈∗_ {S} {S} ≅ _≈∗_ {T} {T} resp-helper₃ S .S _≡_.refl = ≅-refl .resp-helper₂ : ∀ {i j} → From [ i ≈ j ] → _≈⋆_ {i} {i} ≅ _≈⋆_ {j} {j} resp-helper₂ {i} {j} i∼j = resp-helper₃ (To$ i) (To$ j) (cong₀ To i∼j) fake-at : ∀ i → Setoid ct (suc (ct ⊔ ℓt)) fake-at i = record { Carrier = To$C i ; _≈_ = _≈⋆_ {i} {i} ; isEquivalence = record { refl = my-refl ; sym = my-sym ; trans = my-trans } } ------------------------------------------------------------------------ -- Functions which preserve equality record Π {f₁ f₂ t₁ t₂} (From : Setoid f₁ f₂) (To : IndexedSetoid (Carrier₀ From) (Setoid._≈_ From) t₁ t₂) : Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where open I using (_=[_]⇒_) infixl 5 _⟨$⟩_ field _⟨$⟩_ : (x : Carrier₀ From) → IndexedSetoid.Carrier To x .cong : Setoid._≈_ From =[ _⟨$⟩_ ]⇒ IndexedSetoid._≈_ To open Π public Π′ : ∀ {cf ℓf} (ct ℓt : Level) (From : Setoid cf ℓf) (To : From ⟶[ ct , ℓt ]) → Set (cf ⊔ ℓf ⊔ suc (ct ⊔ ℓt)) Π′ ct ℓt From To = Π From (asIndexed ct ℓt To) -- Pis that 'just happen' to be independent, instead of being necessarily so. infixr 0 _⟶Π_ _⟶Π_ : ∀ {f₁ f₂ t₁ t₂} → Setoid f₁ f₂ → Setoid t₁ t₂ → Set _ From ⟶Π To = Π From (weaken To) -- Identity and composition. id : ∀ {a₁ a₂} {A : Setoid a₁ a₂} → A ⟶Π A id = record { _⟨$⟩_ = Fun.id; cong = Fun.id } infixr 9 _∙′_ _∙′_ : ∀ {a₁ a₂} {A : Setoid a₁ a₂} {b₁ b₂} {B : Setoid b₁ b₂} {c₁ c₂} {C : Setoid c₁ c₂} → B ⟶Π C → A ⟶Π B → A ⟶Π C f ∙′ g = record { _⟨$⟩_ = Fun._∘_ (_⟨$⟩_ f) (_⟨$⟩_ g) ; cong = Fun._∘_ (cong f) (cong g) } infixr 9 _[_○_] -- XXX this shouldn't need B, but it can't be inferred from f's type _[_○_] : ∀ {a₁ a₂} {A : Setoid a₁ a₂} {b₁ b₂} (B : Setoid b₁ b₂) {c₁ c₂} (C : IndexedSetoid _ (Setoid._≈_ B) c₁ c₂) → (A ⟶Π B) → IndexedSetoid _ _ c₁ c₂ B [ C ○ f ] = record { Carrier = Fun._∘_ C.Carrier (_⟨$⟩_ f) ; _≈_ = C._≈_ ; isEquivalence = record { refl = C.refl; sym = C.sym; trans = C.trans } ; resp = Fun._∘_ C.resp (cong f) } where module C = IndexedSetoid C -- PROPER. well, halfway. infixr 9 _∙_ _∙_ : ∀ {a₁ a₂} {A : Setoid a₁ a₂} {b₁ b₂} {B : Setoid b₁ b₂} {c₁ c₂} {C : IndexedSetoid _ _ c₁ c₂} → (f : Π B C) → (g : A ⟶Π B) → Π A (B [ C ○ g ]) f ∙ g = record { _⟨$⟩_ = Fun._∘_ (_⟨$⟩_ f) (_⟨$⟩_ g) ; cong = Fun._∘_ (cong f) (cong g) } -- Constant equality-preserving function. const : ∀ {a₁ a₂} {A : Setoid a₁ a₂} {b₁ b₂} {B : Setoid b₁ b₂} → Carrier₀ B → A ⟶Π B const {B = B} b = record { _⟨$⟩_ = Fun.const b ; cong = Fun.const (Setoid.refl B) } ------------------------------------------------------------------------ -- Function setoids -- Dependent. setoid : ∀ {f₁ f₂ t₁ t₂} (From : Setoid f₁ f₂) → IndexedSetoid (Carrier₀ From) (Setoid._≈_ From) t₁ t₂ → Setoid _ _ setoid From To = record { Carrier = Π From To ; _≈_ = λ f g → ∀ {x y} → x ≈₁ y → f ⟨$⟩ x ≈₂ g ⟨$⟩ y ; isEquivalence = record { refl = λ {f} → cong f ; sym = λ f∼g x∼y → To.sym (f∼g (From.sym x∼y)) ; trans = λ f∼g g∼h x∼y → To.trans (f∼g From.refl) (g∼h x∼y) } } where open module From = Setoid From using () renaming (_≈_ to _≈₁_) open module To = IndexedSetoid To using () renaming (_≈_ to _≈₂_)
37.102941
301
0.551922
0b75a9804314a50b3144eae1088be671e753b767
213
agda
Agda
test/Fail/Issue5365.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue5365.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue5365.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2021-05-06, issue #5365 -- Error message for incomplete binding in do-block. postulate _>>=_ : Set test = do x ← -- Expected: proper error like -- -- Incomplete binding x ← -- <EOF><ERROR> -- ...
15.214286
52
0.633803