Search is not available for this dataset
text
string
meta
dict
{-# OPTIONS --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Properties.Symmetry {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Weakening hiding (wk) open import Definition.Typed.Properties open import Definition.Typed.EqualityRelation open import Definition.LogicalRelation open import Definition.LogicalRelation.ShapeView open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Properties.Escape open import Definition.LogicalRelation.Properties.Conversion open import Tools.Product open import Tools.Empty import Tools.PropositionalEquality as PE import Data.Fin as Fin import Data.Nat as Nat mutual -- Helper function for symmetry of type equality using shape views. symEqT : ∀ {Γ A B r l l′} {[A] : Γ ⊩⟨ l ⟩ A ^ r} {[B] : Γ ⊩⟨ l′ ⟩ B ^ r} → ShapeView Γ l l′ A B r r [A] [B] → Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A] → Γ ⊩⟨ l′ ⟩ B ≡ A ^ r / [B] symEqT (ℕᵥ D D′) A≡B = red D symEqT (Emptyᵥ D D′) A≡B = red D symEqT (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M) rewrite whrDet* (red D′ , ne neM) (red D₁ , ne neK₁) = ne₌ _ D neK (~-sym K≡M) symEqT {Γ = Γ} {r = [ r , ι lΠ ] } (Πᵥ (Πᵣ rF lF lG _ _ 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′]) = let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ) F₁≡F′ , rF₁≡rF′ , lF₁≡lF′ , G₁≡G′ , lG₁≡lG′ , lΠ≡lΠ₁ = Π-PE-injectivity ΠF₁G₁≡ΠF′G′ [F₁≡F] : ∀ {Δ} {ρ} [ρ] ⊢Δ → _ [F₁≡F] {Δ} {ρ} [ρ] ⊢Δ = let ρF′≡ρF₁ ρ = PE.cong (wk ρ) (PE.sym F₁≡F′) [ρF′] {ρ} [ρ] ⊢Δ = PE.subst (λ x → Δ ⊩⟨ _ ⟩ wk ρ x ^ _) F₁≡F′ ([F]₁ [ρ] ⊢Δ) in irrelevanceEq′ {Δ} (ρF′≡ρF₁ ρ) PE.refl PE.refl ([ρF′] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) (symEq′ (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([ρF′] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)) in Π₌ _ _ (red (PE.subst₃ _ (PE.sym rF₁≡rF′) (PE.sym lF₁≡lF′) (PE.sym lG₁≡lG′) D)) (PE.subst₃ _ (PE.sym rF₁≡rF′) (PE.sym lF₁≡lF′) (PE.sym lG₁≡lG′) (≅-sym (PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≅ x ^ [ r , ι lΠ ]) (PE.sym ΠF₁G₁≡ΠF′G′) A≡B))) [F₁≡F] (λ {ρ} [ρ] ⊢Δ [a] → let ρG′a≡ρG₁′a = PE.cong (λ x → wk (lift ρ) x [ _ ]) (PE.sym G₁≡G′) [ρG′a] = PE.subst (λ x → _ ⊩⟨ _ ⟩ wk (lift ρ) x [ _ ] ^ _) G₁≡G′ ([G]₁ [ρ] ⊢Δ [a]) [a]₁ = convTerm₁′ rF₁≡rF′ (PE.cong ι lF₁≡lF′) ([F]₁ [ρ] ⊢Δ) ([F] [ρ] ⊢Δ) ([F₁≡F] [ρ] ⊢Δ) [a] in irrelevanceEq′ ρG′a≡ρG₁′a PE.refl PE.refl [ρG′a] ([G]₁ [ρ] ⊢Δ [a]) (symEq′ PE.refl (PE.sym (PE.cong ι lG₁≡lG′)) ([G] [ρ] ⊢Δ [a]₁) [ρG′a] ([G≡G′] [ρ] ⊢Δ [a]₁))) symEqT {Γ = Γ} {r = r} (∃ᵥ (∃ᵣ 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′]) = let ∃F₁G₁≡∃F′G′ = whrDet* (red D₁ , ∃ₙ) (D′ , ∃ₙ) F₁≡F′ , G₁≡G′ = ∃-PE-injectivity ∃F₁G₁≡∃F′G′ [F₁≡F] : ∀ {Δ} {ρ} [ρ] ⊢Δ → _ [F₁≡F] {Δ} {ρ} [ρ] ⊢Δ = let ρF′≡ρF₁ ρ = PE.cong (wk ρ) (PE.sym F₁≡F′) [ρF′] {ρ} [ρ] ⊢Δ = PE.subst (λ x → Δ ⊩⟨ _ ⟩ wk ρ x ^ _) F₁≡F′ ([F]₁ [ρ] ⊢Δ) in irrelevanceEq′ {Δ} (ρF′≡ρF₁ ρ) PE.refl PE.refl ([ρF′] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) (symEq′ PE.refl PE.refl ([F] [ρ] ⊢Δ) ([ρF′] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)) in ∃₌ _ _ (red D) (≅-sym (PE.subst (λ x → Γ ⊢ ∃ F ▹ G ≅ x ^ r) (PE.sym ∃F₁G₁≡∃F′G′) A≡B)) [F₁≡F] (λ {ρ} [ρ] ⊢Δ [a] → let ρG′a≡ρG₁′a = PE.cong (λ x → wk (lift ρ) x [ _ ]) (PE.sym G₁≡G′) [ρG′a] = PE.subst (λ x → _ ⊩⟨ _ ⟩ wk (lift ρ) x [ _ ] ^ _) G₁≡G′ ([G]₁ [ρ] ⊢Δ [a]) [a]₁ = convTerm₁′ PE.refl PE.refl ([F]₁ [ρ] ⊢Δ) ([F] [ρ] ⊢Δ) ([F₁≡F] [ρ] ⊢Δ) [a] in irrelevanceEq′ ρG′a≡ρG₁′a PE.refl PE.refl [ρG′a] ([G]₁ [ρ] ⊢Δ [a]) (symEq ([G] [ρ] ⊢Δ [a]₁) [ρG′a] ([G≡G′] [ρ] ⊢Δ [a]₁))) symEqT (Uᵥ (Uᵣ r l l< el d) (Uᵣ r' l' l<' PE.refl d')) A≡B = let U≡U = whrDet* (A≡B , Uₙ) (red d' , Uₙ) r≡r , l≡l = Univ-PE-injectivity (PE.sym U≡U) in PE.subst _ (PE.sym l≡l) (PE.subst _ (PE.sym r≡r) (red d)) symEqT (emb⁰¹ X) A≡B = symEqT X A≡B symEqT (emb¹⁰ X) A≡B = symEqT X A≡B symEqT (emb¹∞ X) A≡B = symEqT X A≡B symEqT (emb∞¹ X) A≡B = symEqT X A≡B -- Symmetry of type equality. symEq : ∀ {Γ A B r l l′} ([A] : Γ ⊩⟨ l ⟩ A ^ r) ([B] : Γ ⊩⟨ l′ ⟩ B ^ r) → Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A] → Γ ⊩⟨ l′ ⟩ B ≡ A ^ r / [B] symEq [A] [B] A≡B = symEqT (goodCases [A] [B] A≡B) A≡B -- same but with PE symEq′ : ∀ {Γ A B r r' l l′ ll ll'} (eq : r PE.≡ r') (eq' : ll PE.≡ ll') ([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ll ]) ([B] : Γ ⊩⟨ l′ ⟩ B ^ [ r' , ll' ]) → Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ll ] / [A] → Γ ⊩⟨ l′ ⟩ B ≡ A ^ [ r' , ll' ] / [B] symEq′ PE.refl PE.refl [A] [B] A≡B = symEq [A] [B] A≡B symNeutralTerm : ∀ {t u A r Γ} → Γ ⊩neNf t ≡ u ∷ A ^ r → Γ ⊩neNf u ≡ t ∷ A ^ r symNeutralTerm {r = [ ! , ll ]} (neNfₜ₌ neK neM k≡m) = neNfₜ₌ neM neK (~-sym k≡m) symNeutralTerm {r = [ % , ll ]} (neNfₜ₌ neK neM k≡m) = neNfₜ₌ neM neK (~-sym k≡m) symNatural-prop : ∀ {Γ k k′} → [Natural]-prop Γ k k′ → [Natural]-prop Γ k′ k symNatural-prop (sucᵣ (ℕₜ₌ k k′ d d′ t≡u prop)) = sucᵣ (ℕₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symNatural-prop prop)) symNatural-prop zeroᵣ = zeroᵣ symNatural-prop (ne prop) = ne (symNeutralTerm prop) symEmpty-prop : ∀ {Γ k k′ l} → [Empty]-prop Γ k k′ l → [Empty]-prop Γ k′ k l symEmpty-prop (ne t u ) = ne u t symEqTerm⁰ : ∀ {Γ A t u r} ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ r) → Γ ⊩⟨ ι ⁰ ⟩ t ≡ u ∷ A ^ r / [A] → Γ ⊩⟨ ι ⁰ ⟩ u ≡ t ∷ A ^ r / [A] symEqTerm⁰ (ℕᵣ D) (ℕₜ₌ k k′ d d′ t≡u prop) = ℕₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symNatural-prop prop) symEqTerm⁰ (Emptyᵣ D) (Emptyₜ₌ prop) = Emptyₜ₌ (symEmpty-prop prop) symEqTerm⁰ {r = [ ! , ll ]} (ne′ K D neK K≡K) (neₜ₌ k m d d′ nf) = neₜ₌ m k d′ d (symNeutralTerm nf) symEqTerm⁰ {r = [ % , ll ]} (ne′ K D neK K≡K) (neₜ₌ d d′) = neₜ₌ d′ d symEqTerm⁰ {r = [ ! , ll ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g]) = Πₜ₌ g f d′ d funcG funcF (≅ₜ-sym f≡g) [g] [f] (λ ρ ⊢Δ [a] → symEqTerm⁰ ([G] ρ ⊢Δ [a]) ([f≡g] ρ ⊢Δ [a])) symEqTerm⁰ {r = [ % , ll ]} (Πᵣ′ rF lF _ _ F lG G D ⊢F ⊢G A≡A [F] [G] G-ext) (d , d′) = d′ , d symEqTerm⁰ {r = [ % , ll ]} (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (d , d′) = d′ , d symEqTerm¹ : ∀ {Γ A t u r} ([A] : Γ ⊩⟨ ι ¹ ⟩ A ^ r) → Γ ⊩⟨ ι ¹ ⟩ t ≡ u ∷ A ^ r / [A] → Γ ⊩⟨ ι ¹ ⟩ u ≡ t ∷ A ^ r / [A] symEqTerm¹ {Γ} {A} {t} {u} (Uᵣ (Uᵣ r ⁰ l< el D)) (Uₜ₌ [A] [B] A≡B [A≡B]) = let [B≡A] = λ {ρ} {Δ} ([ρ] : ρ ∷ Δ ⊆ Γ) ⊢Δ → symEq (LogRel._⊩¹U_∷_^_/_.[t] [A] [ρ] ⊢Δ) (LogRel._⊩¹U_∷_^_/_.[t] [B] [ρ] ⊢Δ) ([A≡B] [ρ] ⊢Δ) u_to_t : ∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) → (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⟨ ι ⁰ ⟩ a ∷ wk ρ u ^ [ r , ι ⁰ ] / (LogRel._⊩¹U_∷_^_/_.[t] [B] [ρ] ⊢Δ)) → Δ ⊩⟨ ι ⁰ ⟩ a ∷ wk ρ t ^ [ r , ι ⁰ ] / (LogRel._⊩¹U_∷_^_/_.[t] [A] [ρ] ⊢Δ) u_to_t = λ [ρ] ⊢Δ [a] → convTerm₂ (LogRel._⊩¹U_∷_^_/_.[t] [A] [ρ] ⊢Δ) (LogRel._⊩¹U_∷_^_/_.[t] [B] [ρ] ⊢Δ) ([A≡B] [ρ] ⊢Δ) [a] in Uₜ₌ [B] [A] (≅ₜ-sym A≡B) [B≡A] symEqTerm¹ (ℕᵣ D) (ℕₜ₌ k k′ d d′ t≡u prop) = ℕₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symNatural-prop prop) symEqTerm¹ (Emptyᵣ D) (Emptyₜ₌ prop) = Emptyₜ₌ (symEmpty-prop prop) symEqTerm¹ {r = [ ! , ll ]} (ne′ K D neK K≡K) (neₜ₌ k m d d′ nf) = neₜ₌ m k d′ d (symNeutralTerm nf) symEqTerm¹ {r = [ % , ll ]} (ne′ K D neK K≡K) (neₜ₌ d d′) = neₜ₌ d′ d symEqTerm¹ {r = [ ! , ll ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g]) = Πₜ₌ g f d′ d funcG funcF (≅ₜ-sym f≡g) [g] [f] (λ ρ ⊢Δ [a] → symEqTerm¹ ([G] ρ ⊢Δ [a]) ([f≡g] ρ ⊢Δ [a])) symEqTerm¹ {r = [ % , ll ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (d , d′) = d′ , d symEqTerm¹ {r = [ % , ll ]} (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (d , d′) = d′ , d symEqTerm¹ (emb <l x) t≡u = symEqTerm⁰ x t≡u -- Symmetry of term equality. symEqTerm∞ : ∀ {Γ A t u r} ([A] : Γ ⊩⟨ ∞ ⟩ A ^ r) → Γ ⊩⟨ ∞ ⟩ t ≡ u ∷ A ^ r / [A] → Γ ⊩⟨ ∞ ⟩ u ≡ t ∷ A ^ r / [A] symEqTerm∞ {Γ} {A} {t} {u} (Uᵣ (Uᵣ r ⁰ l< el D)) (Uₜ₌ [A] [B] A≡B [A≡B]) = let [B≡A] = λ {ρ} {Δ} ([ρ] : ρ ∷ Δ ⊆ Γ) ⊢Δ → symEq (LogRel._⊩¹U_∷_^_/_.[t] [A] [ρ] ⊢Δ) (LogRel._⊩¹U_∷_^_/_.[t] [B] [ρ] ⊢Δ) ([A≡B] [ρ] ⊢Δ) in Uₜ₌ [B] [A] (≅ₜ-sym A≡B) [B≡A] symEqTerm∞ {Γ} {A} {t} {u} (Uᵣ (Uᵣ r ¹ l< el D)) (Uₜ₌ [A] [B] A≡B [A≡B]) = let [B≡A] = λ {ρ} {Δ} ([ρ] : ρ ∷ Δ ⊆ Γ) ⊢Δ → symEq (LogRel._⊩¹U_∷_^_/_.[t] [A] [ρ] ⊢Δ) (LogRel._⊩¹U_∷_^_/_.[t] [B] [ρ] ⊢Δ) ([A≡B] [ρ] ⊢Δ) in Uₜ₌ [B] [A] (≅ₜ-sym A≡B) [B≡A] symEqTerm∞ (ℕᵣ D) (ℕₜ₌ k k′ d d′ t≡u prop) = ℕₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symNatural-prop prop) symEqTerm∞ (Emptyᵣ D) (Emptyₜ₌ prop) = Emptyₜ₌ (symEmpty-prop prop) symEqTerm∞ {r = [ ! , ll ]} (ne′ K D neK K≡K) (neₜ₌ k m d d′ nf) = neₜ₌ m k d′ d (symNeutralTerm nf) symEqTerm∞ {r = [ % , ll ]} (ne′ K D neK K≡K) (neₜ₌ d d′) = neₜ₌ d′ d symEqTerm∞ {r = [ ! , ll ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g]) = Πₜ₌ g f d′ d funcG funcF (≅ₜ-sym f≡g) [g] [f] (λ ρ ⊢Δ [a] → symEqTerm∞ ([G] ρ ⊢Δ [a]) ([f≡g] ρ ⊢Δ [a])) symEqTerm∞ {r = [ % , ll ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (d , d′) = d′ , d symEqTerm∞ {r = [ % , ll ]} (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (d , d′) = d′ , d symEqTerm∞ (emb <l x) t≡u = symEqTerm¹ x t≡u symEqTerm : ∀ {l Γ A t u r} ([A] : Γ ⊩⟨ l ⟩ A ^ r) → Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ r / [A] → Γ ⊩⟨ l ⟩ u ≡ t ∷ A ^ r / [A] symEqTerm {l = ι ⁰} = symEqTerm⁰ symEqTerm {l = ι ¹} = symEqTerm¹ symEqTerm {l = ∞} = symEqTerm∞
{ "alphanum_fraction": 0.4342168214, "avg_line_length": 48.3842592593, "ext": "agda", "hexsha": "843066039e31ed50587a152a3254edf3c580dd63", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z", "max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z", "max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CoqHott/logrel-mltt", "max_forks_repo_path": "Definition/LogicalRelation/Properties/Symmetry.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "CoqHott/logrel-mltt", "max_issues_repo_path": "Definition/LogicalRelation/Properties/Symmetry.agda", "max_line_length": 178, "max_stars_count": 2, "max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CoqHott/logrel-mltt", "max_stars_repo_path": "Definition/LogicalRelation/Properties/Symmetry.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z", "max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z", "num_tokens": 5809, "size": 10451 }
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Bifunctor.Properties where open import Level open import Data.Product using (Σ; _,_) open import Categories.Category open import Categories.Functor open import Categories.Functor.Bifunctor import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level C D E : Category o ℓ e module _ (F : Bifunctor C D E) where private module C = Category C module D = Category D module E = Category E variable A B : C.Obj X Y : D.Obj f h j : A C.⇒ B g i k : X D.⇒ Y open E open HomReasoning open Functor F [_]-commute : F₁ (C.id , g) ∘ F₁ (f , D.id) ≈ F₁ (f , D.id) ∘ F₁ (C.id , g) [_]-commute {g = g} {f = f} = begin F₁ (C.id , g) ∘ F₁ (f , D.id) ≈˘⟨ homomorphism ⟩ F₁ (C.id C.∘ f , g D.∘ D.id) ≈⟨ F-resp-≈ (MR.id-comm-sym C , MR.id-comm D) ⟩ F₁ (f C.∘ C.id , D.id D.∘ g) ≈⟨ homomorphism ⟩ F₁ (f , D.id) ∘ F₁ (C.id , g) ∎ [_]-decompose₁ : F₁ (f , g) ≈ F₁ (f , D.id) ∘ F₁ (C.id , g) [_]-decompose₁ {f = f} {g = g} = begin F₁ (f , g) ≈˘⟨ F-resp-≈ (C.identityʳ , D.identityˡ) ⟩ F₁ (f C.∘ C.id , D.id D.∘ g) ≈⟨ homomorphism ⟩ F₁ (f , D.id) ∘ F₁ (C.id , g) ∎ [_]-decompose₂ : F₁ (f , g) ≈ F₁ (C.id , g) ∘ F₁ (f , D.id) [_]-decompose₂ {f = f} {g = g} = begin F₁ (f , g) ≈˘⟨ F-resp-≈ (C.identityˡ , D.identityʳ) ⟩ F₁ (C.id C.∘ f , g D.∘ D.id) ≈⟨ homomorphism ⟩ F₁ (C.id , g) ∘ F₁ (f , D.id) ∎ [_]-merge : f C.∘ h C.≈ j → g D.∘ i D.≈ k → F₁ (f , g) ∘ F₁ (h , i) ≈ F₁ (j , k) [_]-merge {f = f} {h = h} {j = j} {g = g} {i = i} {k = k} eq eq′ = begin F₁ (f , g) ∘ F₁ (h , i) ≈˘⟨ homomorphism ⟩ F₁ (f C.∘ h , g D.∘ i) ≈⟨ F-resp-≈ (eq , eq′) ⟩ F₁ (j , k) ∎
{ "alphanum_fraction": 0.4938752784, "avg_line_length": 30.9655172414, "ext": "agda", "hexsha": "43ddc7b1020d45420d2d8f0b5b7f69dd32b73262", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Functor/Bifunctor/Properties.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Functor/Bifunctor/Properties.agda", "max_line_length": 83, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Functor/Bifunctor/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 839, "size": 1796 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category open import Categories.Monad module Categories.Adjoint.Construction.Kleisli {o ℓ e} {C : Category o ℓ e} (M : Monad C) where open import Categories.Category.Construction.Kleisli open import Categories.Adjoint open import Categories.Functor open import Categories.Functor.Properties open import Categories.NaturalTransformation open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_) open import Categories.Morphism.Reasoning C private module C = Category C module M = Monad M open M.F open C open HomReasoning Forgetful : Functor (Kleisli M) C Forgetful = record { F₀ = λ X → F₀ X ; F₁ = λ f → M.μ.η _ ∘ F₁ f ; identity = M.identityˡ ; homomorphism = λ {X Y Z} {f g} → begin M.μ.η Z ∘ F₁ ((M.μ.η Z ∘ F₁ g) ∘ f) ≈⟨ refl⟩∘⟨ homomorphism ⟩ M.μ.η Z ∘ F₁ (M.μ.η Z ∘ F₁ g) ∘ F₁ f ≈⟨ refl⟩∘⟨ homomorphism ⟩∘⟨refl ⟩ M.μ.η Z ∘ (F₁ (M.μ.η Z) ∘ F₁ (F₁ g)) ∘ F₁ f ≈⟨ pull-first M.assoc ⟩ (M.μ.η Z ∘ M.μ.η (F₀ Z)) ∘ F₁ (F₁ g) ∘ F₁ f ≈⟨ center (M.μ.commute g) ⟩ M.μ.η Z ∘ (F₁ g ∘ M.μ.η Y) ∘ F₁ f ≈⟨ pull-first refl ⟩ (M.μ.η Z ∘ F₁ g) ∘ M.μ.η Y ∘ F₁ f ∎ ; F-resp-≈ = λ eq → ∘-resp-≈ʳ (F-resp-≈ eq) } Free : Functor C (Kleisli M) Free = record { F₀ = λ X → X ; F₁ = λ f → M.η.η _ ∘ f ; identity = identityʳ ; homomorphism = λ {X Y Z} {f g} → begin M.η.η Z ∘ g ∘ f ≈⟨ sym-assoc ○ ⟺ identityˡ ⟩ C.id ∘ (M.η.η Z ∘ g) ∘ f ≈˘⟨ pull-first M.identityˡ ⟩ M.μ.η Z ∘ (F₁ (M.η.η Z) ∘ M.η.η Z ∘ g) ∘ f ≈⟨ refl⟩∘⟨ pushʳ (M.η.commute g) ⟩∘⟨refl ⟩ M.μ.η Z ∘ ((F₁ (M.η.η Z) ∘ F₁ g) ∘ M.η.η Y) ∘ f ≈˘⟨ center (∘-resp-≈ˡ homomorphism) ⟩ (M.μ.η Z ∘ F₁ (M.η.η Z ∘ g)) ∘ M.η.η Y ∘ f ∎ ; F-resp-≈ = ∘-resp-≈ʳ } FF≃F : Forgetful ∘F Free ≃ M.F FF≃F = record { F⇒G = ntHelper record { η = λ X → F₁ C.id ; commute = λ {X Y} f → begin F₁ C.id ∘ M.μ.η Y ∘ F₁ (M.η.η Y ∘ f) ≈⟨ refl⟩∘⟨ refl⟩∘⟨ homomorphism ⟩ F₁ C.id ∘ M.μ.η Y ∘ F₁ (M.η.η Y) ∘ F₁ f ≈⟨ refl⟩∘⟨ cancelˡ M.identityˡ ⟩ F₁ C.id ∘ F₁ f ≈⟨ [ M.F ]-resp-square id-comm-sym ⟩ F₁ f ∘ F₁ C.id ∎ } ; F⇐G = ntHelper record { η = λ X → F₁ C.id ; commute = λ {X Y} f → begin F₁ C.id ∘ F₁ f ≈⟨ [ M.F ]-resp-square id-comm-sym ⟩ F₁ f ∘ F₁ C.id ≈˘⟨ cancelˡ M.identityˡ ⟩∘⟨refl ⟩ (M.μ.η Y ∘ F₁ (M.η.η Y) ∘ F₁ f) ∘ F₁ C.id ≈˘⟨ ∘-resp-≈ʳ homomorphism ⟩∘⟨refl ⟩ (M.μ.η Y ∘ F₁ (M.η.η Y ∘ f)) ∘ F₁ C.id ∎ } ; iso = λ X → record { isoˡ = elimˡ identity ○ identity ; isoʳ = elimˡ identity ○ identity } } Free⊣Forgetful : Free ⊣ Forgetful Free⊣Forgetful = record { unit = ntHelper record { η = M.η.η ; commute = λ {X Y} f → begin M.η.η Y ∘ f ≈⟨ M.η.commute f ⟩ F₁ f ∘ M.η.η X ≈˘⟨ cancelˡ M.identityˡ ⟩∘⟨refl ⟩ (M.μ.η Y ∘ F₁ (M.η.η Y) ∘ F₁ f) ∘ M.η.η X ≈˘⟨ ∘-resp-≈ʳ homomorphism ⟩∘⟨refl ⟩ (M.μ.η Y ∘ F₁ (M.η.η Y ∘ f)) ∘ M.η.η X ∎ } ; counit = ntHelper record { η = λ X → F₁ C.id ; commute = λ {X Y} f → begin (M.μ.η Y ∘ F₁ (F₁ C.id)) ∘ M.η.η (F₀ Y) ∘ M.μ.η Y ∘ F₁ f ≈⟨ elimʳ (F-resp-≈ identity ○ identity) ⟩∘⟨refl ⟩ M.μ.η Y ∘ M.η.η (F₀ Y) ∘ M.μ.η Y ∘ F₁ f ≈⟨ cancelˡ M.identityʳ ⟩ M.μ.η Y ∘ F₁ f ≈⟨ introʳ identity ⟩ (M.μ.η Y ∘ F₁ f) ∘ F₁ C.id ∎ } ; zig = λ {A} → begin (M.μ.η A ∘ F₁ (F₁ C.id)) ∘ M.η.η (F₀ A) ∘ M.η.η A ≈⟨ elimʳ (F-resp-≈ identity ○ identity) ⟩∘⟨refl ⟩ M.μ.η A ∘ M.η.η (F₀ A) ∘ M.η.η A ≈⟨ cancelˡ M.identityʳ ⟩ M.η.η A ∎ ; zag = λ {B} → begin (M.μ.η B ∘ F₁ (F₁ C.id)) ∘ M.η.η (F₀ B) ≈⟨ elimʳ (F-resp-≈ identity ○ identity) ⟩∘⟨refl ⟩ M.μ.η B ∘ M.η.η (F₀ B) ≈⟨ M.identityʳ ⟩ C.id ∎ }
{ "alphanum_fraction": 0.460385439, "avg_line_length": 39.2803738318, "ext": "agda", "hexsha": "fa6d8b0df9e3379248b3d2c206f16cbc5de2afab", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "MirceaS/agda-categories", "max_forks_repo_path": "src/Categories/Adjoint/Construction/Kleisli.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "MirceaS/agda-categories", "max_issues_repo_path": "src/Categories/Adjoint/Construction/Kleisli.agda", "max_line_length": 103, "max_stars_count": null, "max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "MirceaS/agda-categories", "max_stars_repo_path": "src/Categories/Adjoint/Construction/Kleisli.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1977, "size": 4203 }
------------------------------------------------------------------------ -- A coinductive definition of the expansion ordering ------------------------------------------------------------------------ -- The definition of expansion is based on the one in "Enhancements of -- the bisimulation proof method" by Pous and Sangiorgi. {-# OPTIONS --sized-types #-} open import Labelled-transition-system module Expansion {ℓ} (lts : LTS ℓ) where open import Equality.Propositional open import Prelude open import Prelude.Size import Bisimilarity import Bisimilarity.Equational-reasoning-instances import Bisimilarity.General open import Equational-reasoning open import Indexed-container using (Container; ν; ν′) open import Relation open LTS lts private open module SB = Bisimilarity lts using (_∼_; _∼′_; [_]_∼_; [_]_∼′_) private module General = Bisimilarity.General lts _[_]⟶̂_ _[_]⇒_ ⟶→⟶̂ ⟶→[]⇒ open General public using (module StepC; ⟨_,_⟩; left-to-right; right-to-left; force; [_]_≡_; [_]_≡′_; []≡↔; Extensionality; extensionality) renaming ( reflexive-∼ to reflexive-≳ ; reflexive-∼′ to reflexive-≳′ ; ≡⇒∼ to ≡⇒≳ ; ∼:_ to ≳:_ ; ∼′:_ to ≳′:_ ) -- StepC is given in the following way, rather than via open public, -- to make hyperlinks to it more informative. StepC : Container (Proc × Proc) (Proc × Proc) StepC = General.StepC -- The following definitions are given explicitly, to make the code -- easier to follow for readers of the paper. Expansion : Size → Rel₂ ℓ Proc Expansion = ν StepC Expansion′ : Size → Rel₂ ℓ Proc Expansion′ = ν′ StepC infix 4 _≳_ _≳′_ [_]_≳_ [_]_≳′_ [_]_≳_ : Size → Proc → Proc → Type ℓ [ i ] p ≳ q = ν StepC i (p , q) [_]_≳′_ : Size → Proc → Proc → Type ℓ [ i ] p ≳′ q = ν′ StepC i (p , q) _≳_ : Proc → Proc → Type ℓ _≳_ = [ ∞ ]_≳_ _≳′_ : Proc → Proc → Type ℓ _≳′_ = [ ∞ ]_≳′_ private -- However, these definitions are definitionally equivalent to -- corresponding definitions in General. indirect-Expansion : Expansion ≡ General.Bisimilarity indirect-Expansion = refl indirect-Expansion′ : Expansion′ ≡ General.Bisimilarity′ indirect-Expansion′ = refl indirect-[]≳ : [_]_≳_ ≡ General.[_]_∼_ indirect-[]≳ = refl indirect-[]≳′ : [_]_≳′_ ≡ General.[_]_∼′_ indirect-[]≳′ = refl indirect-≳ : _≳_ ≡ General._∼_ indirect-≳ = refl indirect-≳′ : _≳′_ ≡ General._∼′_ indirect-≳′ = refl -- The converse relation. infix 4 _≲_ _≲′_ [_]_≲_ [_]_≲′_ [_]_≲_ : Size → Proc → Proc → Type ℓ [_]_≲_ i = flip [ i ]_≳_ [_]_≲′_ : Size → Proc → Proc → Type ℓ [_]_≲′_ i = flip [ i ]_≳′_ _≲_ : Proc → Proc → Type ℓ _≲_ = [ ∞ ]_≲_ _≲′_ : Proc → Proc → Type ℓ _≲′_ = [ ∞ ]_≲′_ -- Combinators that can perhaps make the code a bit nicer to read. infix -3 lr-result-⟶̂ rl-result-⇒ lr-result-⇒ rl-result-⟶̂ lr-result-⟶̂ : ∀ {i p′ q q′} μ → [ i ] p′ ≳′ q′ → q [ μ ]⟶̂ q′ → ∃ λ q′ → q [ μ ]⟶̂ q′ × [ i ] p′ ≳′ q′ lr-result-⟶̂ _ p′≳′q′ q⟶̂q′ = _ , q⟶̂q′ , p′≳′q′ rl-result-⇒ : ∀ {i p p′ q′} μ → p [ μ ]⇒ p′ → [ i ] p′ ≳′ q′ → ∃ λ p′ → p [ μ ]⇒ p′ × [ i ] p′ ≳′ q′ rl-result-⇒ _ p⇒p′ p′≳′q′ = _ , p⇒p′ , p′≳′q′ lr-result-⇒ : ∀ {i p′ q q′} μ → [ i ] p′ ≲′ q′ → q [ μ ]⇒ q′ → ∃ λ q′ → q [ μ ]⇒ q′ × [ i ] p′ ≲′ q′ lr-result-⇒ _ p′≲′q′ q⇒q′ = _ , q⇒q′ , p′≲′q′ rl-result-⟶̂ : ∀ {i p p′ q′} μ → p [ μ ]⟶̂ p′ → [ i ] p′ ≲′ q′ → ∃ λ p′ → p [ μ ]⟶̂ p′ × [ i ] p′ ≲′ q′ rl-result-⟶̂ _ p⟶̂p′ p′≲′q′ = _ , p⟶̂p′ , p′≲′q′ syntax lr-result-⟶̂ μ p′≳′q′ q⟶̂q′ = p′≳′q′ ⟵̂[ μ ] q⟶̂q′ syntax rl-result-⇒ μ p⇒p′ p′≳′q′ = p⇒p′ ⇒[ μ ] p′≳′q′ syntax lr-result-⇒ μ p′≲′q′ q⇒q′ = p′≲′q′ ⇐[ μ ] q⇒q′ syntax rl-result-⟶̂ μ p⟶̂p′ p′≲′q′ = p⟶̂p′ ⟶̂[ μ ] p′≲′q′ -- Strongly bisimilar processes are related by the expansion ordering. mutual ∼⇒≳ : ∀ {i p q} → [ i ] p ∼ q → [ i ] p ≳ q ∼⇒≳ {i} = λ p∼q → StepC.⟨ lr p∼q , rl p∼q ⟩ where lr : ∀ {p p′ q μ} → [ i ] p ∼ q → p [ μ ]⟶ p′ → ∃ λ q′ → q [ μ ]⟶̂ q′ × [ i ] p′ ≳′ q′ lr p∼q p⟶p′ = let q′ , q⟶q′ , p′∼′q′ = SB.left-to-right p∼q p⟶p′ in q′ , step q⟶q′ , ∼⇒≳′ p′∼′q′ rl : ∀ {p q q′ μ} → [ i ] p ∼ q → q [ μ ]⟶ q′ → ∃ λ p′ → p [ μ ]⇒ p′ × [ i ] p′ ≳′ q′ rl p∼q q⟶q′ = let p′ , p⟶p′ , p′∼′q′ = SB.right-to-left p∼q q⟶q′ in p′ , ⟶→[]⇒ p⟶p′ , ∼⇒≳′ p′∼′q′ ∼⇒≳′ : ∀ {i p q} → [ i ] p ∼′ q → [ i ] p ≳′ q force (∼⇒≳′ p∼′q) = ∼⇒≳ (SB.force p∼′q) -- Expansion is a weak simulation (of three different kinds). expansion-is-weak⇒ : ∀ {p p′ q} → p ≳ q → p ⇒ p′ → ∃ λ q′ → q ⇒ q′ × p′ ≳ q′ expansion-is-weak⇒ = is-weak⇒ StepC.left-to-right (λ p≳′q → force p≳′q) ⟶̂→⇒ expansion-is-weak[]⇒ : ∀ {p p′ q μ} → ¬ Silent μ → p ≳ q → p [ μ ]⇒ p′ → ∃ λ q′ → q [ μ ]⇒ q′ × p′ ≳ q′ expansion-is-weak[]⇒ ¬s = is-weak[]⇒ StepC.left-to-right (λ p≳′q → force p≳′q) ⟶̂→⇒ (⇒̂→[]⇒ ¬s ∘ ⟶̂→⇒̂) expansion-is-weak⇒̂ : ∀ {p p′ q μ} → p ≳ q → p [ μ ]⇒̂ p′ → ∃ λ q′ → q [ μ ]⇒̂ q′ × p′ ≳ q′ expansion-is-weak⇒̂ = is-weak⇒̂ StepC.left-to-right (λ p≳′q → force p≳′q) ⟶̂→⇒ ⟶̂→⇒̂ -- The converse of expansion is a weak simulation (of three different -- kinds). converse-of-expansion-is-weak : ∀ {p p′ q} → p ≲ q → p ⇒ p′ → ∃ λ q′ → q ⇒ q′ × p′ ≲ q′ converse-of-expansion-is-weak = is-weak⇒ StepC.right-to-left (λ p≲′q → force p≲′q) []⇒→⇒ converse-of-expansion-is-weak[]⇒ : ∀ {p p′ q μ} → p ≲ q → p [ μ ]⇒ p′ → ∃ λ q′ → q [ μ ]⇒ q′ × p′ ≲ q′ converse-of-expansion-is-weak[]⇒ = is-weak[]⇒ StepC.right-to-left (λ p≲′q → force p≲′q) []⇒→⇒ id converse-of-expansion-is-weak⇒̂ : ∀ {p p′ q μ} → p ≲ q → p [ μ ]⇒̂ p′ → ∃ λ q′ → q [ μ ]⇒̂ q′ × p′ ≲ q′ converse-of-expansion-is-weak⇒̂ = is-weak⇒̂ StepC.right-to-left (λ p≲′q → force p≲′q) []⇒→⇒ ⇒→⇒̂ mutual -- Expansion is transitive. -- -- Note that the transitivity proof is not claimed to be fully -- size-preserving. For a proof showing that it cannot, in general, -- be size-preserving in the first argument, see -- Expansion.Delay-monad.size-preserving-transitivityˡ⇔uninhabited. transitive-≳ : ∀ {i p q r} → p ≳ q → [ i ] q ≳ r → [ i ] p ≳ r transitive-≳ {i} = λ p≳q q≳r → StepC.⟨ lr p≳q q≳r , rl p≳q q≳r ⟩ where lr : ∀ {p p′ q r μ} → p ≳ q → [ i ] q ≳ r → p [ μ ]⟶ p′ → ∃ λ r′ → r [ μ ]⟶̂ r′ × [ i ] p′ ≳′ r′ lr p≳q q≳r p⟶p′ with StepC.left-to-right p≳q p⟶p′ ... | _ , done s , p′≳′q = _ , done s , transitive-≳′ p′≳′q (record { force = λ { {_} → q≳r } }) ... | q′ , step q⟶q′ , p′≳′q′ = let r′ , r⟶̂r′ , q′≳′r′ = StepC.left-to-right q≳r q⟶q′ in r′ , r⟶̂r′ , transitive-≳′ p′≳′q′ q′≳′r′ rl : ∀ {p q r r′ μ} → p ≳ q → [ i ] q ≳ r → r [ μ ]⟶ r′ → ∃ λ p′ → p [ μ ]⇒ p′ × [ i ] p′ ≳′ r′ rl p≳q q≳r r⟶r′ = let q′ , q⇒q′ , q′≳′r′ = StepC.right-to-left q≳r r⟶r′ p′ , p⇒̂p′ , p′≳q′ = converse-of-expansion-is-weak[]⇒ p≳q q⇒q′ in p′ , p⇒̂p′ , transitive-≳′ (record { force = p′≳q′ }) q′≳′r′ transitive-≳′ : ∀ {i p q r} → p ≳′ q → [ i ] q ≳′ r → [ i ] p ≳′ r force (transitive-≳′ p≳q q≳r) = transitive-≳ (force p≳q) (force q≳r) -- The following variant of transitivity is fully size-preserving. mutual transitive-≳∼ : ∀ {i p q r} → [ i ] p ≳ q → [ i ] q ∼ r → [ i ] p ≳ r transitive-≳∼ {i} {p} {r = r} p≳q q∼r = StepC.⟨ lr , rl ⟩ where rl : ∀ {r′ μ} → r [ μ ]⟶ r′ → ∃ λ p′ → p [ μ ]⇒ p′ × [ i ] p′ ≳′ r′ rl r⟶r′ = let q′ , q⟶q′ , q′∼′r′ = SB.right-to-left q∼r r⟶r′ p′ , p⇒p′ , p′≳′q′ = StepC.right-to-left p≳q q⟶q′ in p′ , p⇒p′ , transitive-≳∼′ p′≳′q′ q′∼′r′ lr : ∀ {p′ μ} → p [ μ ]⟶ p′ → ∃ λ r′ → r [ μ ]⟶̂ r′ × [ i ] p′ ≳′ r′ lr p⟶p′ = let q′ , q⟶̂q′ , p′≳′q′ = StepC.left-to-right p≳q p⟶p′ r′ , r⇒̂r′ , q′∼r′ = lemma q∼r q⟶̂q′ in r′ , r⇒̂r′ , transitive-≳∼′ p′≳′q′ q′∼r′ where lemma : ∀ {i p p′ q μ} → [ i ] p ∼ q → p [ μ ]⟶̂ p′ → ∃ λ q′ → q [ μ ]⟶̂ q′ × [ i ] p′ ∼′ q′ lemma p∼q (done s) = _ , done s , record { force = λ { {_} → p∼q } } lemma p∼q (step p⟶p′) = let q′ , q⟶q′ , p′∼q′ = SB.left-to-right p∼q p⟶p′ in q′ , ⟶→⟶̂ q⟶q′ , p′∼q′ transitive-≳∼′ : ∀ {i p q r} → [ i ] p ≳′ q → [ i ] q ∼′ r → [ i ] p ≳′ r force (transitive-≳∼′ p≳′q q∼′r) = transitive-≳∼ (force p≳′q) (SB.force q∼′r) -- The following variant of transitivity is partially size-preserving. -- -- For a proof showing that it cannot, in general, be size-preserving -- in the first argument, see -- Expansion.Delay-monad.size-preserving-transitivity-∼≳ˡ⇔uninhabited. transitive-∼≳ : ∀ {i p q r} → p ∼ q → [ i ] q ≳ r → [ i ] p ≳ r transitive-∼≳ = transitive-≳ ∘ ∼⇒≳
{ "alphanum_fraction": 0.4747108188, "avg_line_length": 30.4068965517, "ext": "agda", "hexsha": "a60ce59ee2da8f4afb7d9df0ee1cf0663008e5c3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/up-to", "max_forks_repo_path": "src/Expansion.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/up-to", "max_issues_repo_path": "src/Expansion.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/up-to", "max_stars_repo_path": "src/Expansion.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4271, "size": 8818 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} import LibraBFT.Impl.OBM.Crypto as Crypto open import LibraBFT.Impl.OBM.Rust.RustTypes open import LibraBFT.Impl.OBM.Util open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Util.Dijkstra.All open import Optics.All import Util.KVMap as Map open import Util.PKCS hiding (verify) open import Util.Prelude ------------------------------------------------------------------------------ open import Data.String using (String) module LibraBFT.Impl.Types.ValidatorVerifier where ------------------------------------------------------------------------------ calculateQuorumVotingPower : U64 -> U64 checkNumOfSignatures : ValidatorVerifier → Map.KVMap AccountAddress Signature → Either ErrLog Unit checkVotingPower : ValidatorVerifier → List AccountAddress → Either ErrLog Unit getPublicKey : ValidatorVerifier → AccountAddress → Maybe PK getVotingPower : ValidatorVerifier → AccountAddress → Maybe U64 sumVotingPower-ed-abs : (List String → List String) → Map.KVMap AccountAddress ValidatorConsensusInfo → EitherD ErrLog U64 ------------------------------------------------------------------------------ -- LBFT-OBM-DIFF : this is specific to OBM. -- It enables specifying the number of faults allowed. -- Assumes everyone has 1 vote -- IMPL-DIFF : gets an alist instead of list of Author initValidatorVerifier : U64 → List (Author × (SK × PK)) → Either ErrLog ValidatorVerifier initValidatorVerifier numFailures0 authors0 = checkBftAndRun numFailures0 authors0 f where f : U64 → List (Author × (SK × PK)) → ValidatorVerifier f numFailures authors = record -- ValidatorVerifier { _vvAddressToValidatorInfo = Map.fromList (fmap (λ (author , (_ , pk)) → (author , ValidatorConsensusInfo∙new pk 1)) authors) ; _vvQuorumVotingPower = numNodesNeededForNFailures numFailures ∸ numFailures ; _vvTotalVotingPower = length authors } new : Map.KVMap AccountAddress ValidatorConsensusInfo → EitherD ErrLog ValidatorVerifier new addressToValidatorInfo = do totalVotingPower ← sumVotingPower-ed-abs here' addressToValidatorInfo let quorumVotingPower = if Map.kvm-size addressToValidatorInfo == 0 then 0 else calculateQuorumVotingPower totalVotingPower pure (mkValidatorVerifier addressToValidatorInfo quorumVotingPower totalVotingPower) where here' : List String → List String here' t = "ValidatorVerifier" ∷ "new" ∷ t -- This scales up the number of faults tolerated with the number of votes. -- see TestValidatorVerifier in Haskell calculateQuorumVotingPower totalVotingPower = (div (totalVotingPower * 2) 3) + 1 verifyIfAuthor : {V : Set} ⦃ _ : Crypto.CryptoHash V ⦄ → {-Text →-} ValidatorVerifier → AccountAddress → V → Signature → Either ErrLog Unit verifyIfAuthor {-msg-} self author v signature = case getPublicKey self author of λ where (just pk) → case Crypto.verify {-msg-} pk signature v of λ where (Left e) → Left fakeErr -- (ErrVerify e InvalidSignature) (Right unit) → Right unit nothing → Left fakeErr -- Left (ErrVerify (msg:known) (UnknownAuthor (author^.aAuthorName))) -- where -- known = fmap _aAuthorName (Map.keys (self^.vvAddressToValidatorInfo)) verify : {V : Set} ⦃ _ : Crypto.CryptoHash V ⦄ → ValidatorVerifier → AccountAddress → V → Signature → Either ErrLog Unit verify = verifyIfAuthor -- (icSemi ["ValidatorVerifier", "verifySignature"]) verifyAggregatedStructSignature : {V : Set} ⦃ _ : Crypto.CryptoHash V ⦄ → ValidatorVerifier → V → Map.KVMap AccountAddress Signature → Either ErrLog Unit verifyAggregatedStructSignature self v aggregatedSignature = do checkNumOfSignatures self aggregatedSignature checkVotingPower self (Map.kvm-keys aggregatedSignature) forM_ (Map.kvm-toList aggregatedSignature) λ (author , signature) → verify self author v signature batchVerifyAggregatedSignatures : {V : Set} ⦃ _ : Crypto.CryptoHash V ⦄ → ValidatorVerifier → V → Map.KVMap AccountAddress Signature → Either ErrLog Unit batchVerifyAggregatedSignatures = verifyAggregatedStructSignature checkNumOfSignatures self aggregatedSignature = if-dec Map.kvm-size aggregatedSignature >? Map.kvm-size (self ^∙ vvAddressToValidatorInfo) then Left (ErrVerify (TooManySignatures (Map.kvm-size aggregatedSignature) (Map.kvm-size (self ^∙ vvAddressToValidatorInfo)))) else Right unit checkVotingPower self authors = do let go : AccountAddress → U64 → Either ErrLog U64 go a acc = case getVotingPower self a of λ where nothing → Left (ErrVerify (UnknownAuthor (a ^∙ aAuthorName))) (just n) → Right (n + acc) aggregatedVotingPower ← foldrM go 0 authors if-dec aggregatedVotingPower <? self ^∙ vvQuorumVotingPower then Left (ErrVerify (TooLittleVotingPower aggregatedVotingPower (self ^∙ vvQuorumVotingPower))) else Right unit getPublicKey self author = (_^∙ vciPublicKey) <$> Map.lookup author (self ^∙ vvAddressToValidatorInfo) getVotingPower self author = (_^∙ vciVotingPower) <$> Map.lookup author (self ^∙ vvAddressToValidatorInfo) sumVotingPower : (List String → List String) → Map.KVMap AccountAddress ValidatorConsensusInfo → Either ErrLog U64 sumVotingPower here' addressToValidatorInfo = foldr go (Right 0) (Map.elems addressToValidatorInfo) where maxBoundU64 : U64 maxBoundU64 = 18446744073709551615 go : ValidatorConsensusInfo → Either ErrLog U64 → Either ErrLog U64 go x (Right sum') = if-dec sum' ≤? maxBoundU64 ∸ (x ^∙ vciVotingPower) then Right (sum' + x ^∙ vciVotingPower) else Left fakeErr -- (ErrL (here' ("sum too big" ∷ []))) go _ (Left err) = Left err abstract sumVotingPower-ed-abs f = fromEither ∘ sumVotingPower f getOrderedAccountAddressesObmTODO : ValidatorVerifier → List AccountAddress getOrderedAccountAddressesObmTODO self = -- TODO ORDER Map.kvm-keys (self ^∙ vvAddressToValidatorInfo) from-ed : ValidatorSet → EitherD ErrLog ValidatorVerifier from-ed validatorSet = new (foldl' go Map.empty (validatorSet ^∙ vsPayload)) where go : Map.KVMap AccountAddress ValidatorConsensusInfo → ValidatorInfo → Map.KVMap AccountAddress ValidatorConsensusInfo go map0 validator = Map.insert (validator ^∙ viAccountAddress) (ValidatorConsensusInfo∙new (validator ^∙ viConsensusPublicKey) (validator ^∙ viConsensusVotingPower)) map0 abstract from-e-abs = toEither ∘ from-ed from-ed-abs = from-ed
{ "alphanum_fraction": 0.6767380053, "avg_line_length": 43.5914634146, "ext": "agda", "hexsha": "bb068af80573fbb5552c141c92775cd2278d2e8b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/LibraBFT/Impl/Types/ValidatorVerifier.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Impl/Types/ValidatorVerifier.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/LibraBFT/Impl/Types/ValidatorVerifier.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1813, "size": 7149 }
module Alg where open import Data.Bool open import Data.Fin hiding (_+_ ; fold) open import Data.List hiding (lookup ; [_] ; map) open import Data.Nat open import Data.Product hiding (map) open import Data.Vec hiding (_++_) open import Size RankedAlphabet : ℕ → Set RankedAlphabet = Vec ℕ -- natural numbers = { zero_0, suc_1 } rNat : RankedAlphabet 2 rNat = zero ∷ suc zero ∷ [] -- words over {t,f} = { eps_0, false_1, true_1 } rBin : RankedAlphabet 3 rBin = zero ∷ suc zero ∷ suc zero ∷ [] -- binary trees = { leaf_0, branch_2 } rBtr : RankedAlphabet 2 rBtr = zero ∷ suc (suc zero) ∷ [] module FailedAttempt where -- terms data Term {n} (ra : RankedAlphabet n) : Set where mk : (sym : Fin n) → (Fin (lookup ra sym) → Term ra) → Term ra tNat0 : Term rNat tNat0 = mk zero (λ ()) tNat1 : Term rNat tNat1 = mk (suc zero) λ zero → tNat0 tNat2 : Term rNat tNat2 = mk (suc zero) λ zero → tNat1 -- interpretations nary : Set → ℕ → Set nary A zero = A nary A (suc n) = A → nary A n Algebra : ∀ {n} → RankedAlphabet n → Set → Set Algebra {n} ra A = (sym : Fin n) → nary A (lookup ra sym) -- I don't see how to implement this as a function postulate eval : ∀ {n} {ra : RankedAlphabet n} {A} → Term ra → Algebra ra A → A -- end FailedAttempt -- interpretations nary : Set → ℕ → Set nary A n = Vec A n → A Algebra : ∀ {n} → RankedAlphabet n → Set → Set Algebra {n} ra A = (sym : Fin n) → nary A (lookup ra sym) -- natural numbers aNat : Algebra rNat ℕ aNat zero = λ [] → 0 aNat (suc zero) = λ{ (x ∷ []) → suc x } aNat (suc (suc ())) -- bitstrings aBin : Algebra rBin (List Bool) aBin zero = λ _ → [] aBin (suc zero) = λ x → false ∷ lookup x zero aBin (suc (suc zero)) = λ x → true ∷ lookup x zero aBin (suc (suc (suc ()))) -- compute value of bitstring aBinVal : Algebra rBin ℕ aBinVal zero = λ [] → 0 aBinVal (suc zero) = λ{ (x ∷ []) → x + x } aBinVal (suc (suc zero)) = λ{ (x ∷ []) → suc (x + x) } aBinVal (suc (suc (suc ()))) -- the initial btree algebra data BTree : Set where Leaf : BTree Branch : BTree → BTree → BTree aBtrInitial : Algebra rBtr BTree aBtrInitial zero = λ [] → Leaf aBtrInitial (suc zero) = λ{ (l ∷ r ∷ []) → Branch l r } aBtrInitial (suc (suc ())) -- count leaves aBtrCount : Algebra rBtr ℕ aBtrCount zero = λ [] → 1 aBtrCount (suc zero) = λ{ (l ∷ r ∷ []) → l + r } aBtrCount (suc (suc ())) -- height aBtrHeight : Algebra rBtr ℕ aBtrHeight zero = λ [] → 0 aBtrHeight (suc zero) = λ{ (l ∷ r ∷ []) → suc (l ⊔ r) } aBtrHeight (suc (suc ())) -- terms (using sized types) data Term {n} (ra : RankedAlphabet n) : {i : Size} → Set where mk : ∀ {i} → (sym : Fin n) → Vec (Term ra {i}) (lookup ra sym) → Term ra {↑ i} eval : ∀ {n} {ra : RankedAlphabet n} {A} {i} → Algebra ra A → Term ra {i} → A eval alg (mk sym subterms) = alg sym (map (eval alg) subterms) tNat0 : Term rNat tNat0 = mk zero [] tNat1 : Term rNat tNat1 = mk (suc zero) [ tNat0 ] tNat2 : Term rNat tNat2 = mk (suc zero) [ tNat1 ] aNatTerm : Algebra rNat (Term rNat) aNatTerm = mk ---------------------------------------------------------------------- -- many-sorted algebra open import Data.Unit open import Data.Nat.GeneralisedArithmetic Sorts = Fin Signature : ℕ → ℕ → Set Signature s = Vec (List (Sorts s) × Sorts s) sNat : Signature 1 2 sNat = ([] , zero) ∷ (( zero ∷ []) , zero) ∷ [] sMon : Signature 2 6 sMon = ([] , zero) ∷ (zero ∷ [] , zero) ∷ ([] , suc zero) ∷ (suc zero ∷ [] , suc zero) ∷ (suc zero ∷ [] , suc zero) ∷ (zero ∷ suc zero ∷ [] , suc zero) ∷ [] -- this is: 0. S. eps. 0(). 1(). n*s. sary : ∀ {s} → (Sorts s → Set) → List (Sorts s) → Set sary int [] = ⊤ sary int (sort ∷ sort*) = int sort × sary int sort* data STerm {s} {n} (sig : Signature s n) : Sorts s → Set where mk : (sym : Fin n) → let (sort* , sort) = lookup sig sym in sary (STerm sig) sort* → STerm sig sort sNat0 : STerm sNat zero sNat0 = mk zero tt sNat1 : STerm sNat zero sNat1 = mk (suc zero) (sNat0 , tt) SAlgebra : ∀ {s n} → Signature s n → (Sorts s → Set) → Set SAlgebra sig int = (sym : Fin _) → let (sort* , sort) = lookup sig sym in sary int sort* → int sort asNat : SAlgebra sNat λ zero → ℕ asNat zero = λ{ tt → 0 } asNat (suc zero) = λ{ (x , tt) → suc x } asNat (suc (suc ())) asNatTerm : SAlgebra sNat (STerm sNat) asNatTerm = mk {- written out: asNatTerm zero = mk zero asNatTerm (suc zero) = mk (suc zero) asNatTerm (suc (suc ())) -} asMon : SAlgebra sMon λ{ zero → ℕ ; (suc zero) → List Bool ; (suc (suc ())) } asMon zero tt = 0 asMon (suc zero) (n , _) = suc n asMon (suc (suc zero)) tt = [] asMon (suc (suc (suc zero))) (w , _) = true ∷ w asMon (suc (suc (suc (suc zero)))) (w , _) = false ∷ w asMon (suc (suc (suc (suc (suc zero))))) (n , w , _) = fold [] (_++_ w) n asMon (suc (suc (suc (suc (suc (suc ())))))) x
{ "alphanum_fraction": 0.5863928646, "avg_line_length": 26.0594594595, "ext": "agda", "hexsha": "f7b5d641c4a092fed6ddfff3ace3d4dff66bd5a8", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-14T17:52:29.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-14T17:52:29.000Z", "max_forks_repo_head_hexsha": "9ed48acc0064665f3f623bd1b3168d5ba92243e0", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "proglang/ldlc", "max_forks_repo_path": "src/Alg.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9ed48acc0064665f3f623bd1b3168d5ba92243e0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "proglang/ldlc", "max_issues_repo_path": "src/Alg.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "9ed48acc0064665f3f623bd1b3168d5ba92243e0", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "proglang/ldlc", "max_stars_repo_path": "src/Alg.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1847, "size": 4821 }
{- This file contains: - Properties of set truncations -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.SetTruncation.Properties where open import Cubical.Core.Glue open import Cubical.HITs.SetTruncation.Base open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels private variable ℓ : Level A : Type ℓ -- lemma 6.9.1 in HoTT book elimSetTrunc : {B : ∥ A ∥₀ → Type ℓ} → (Bset : (x : ∥ A ∥₀) → isSet (B x)) → (g : (a : A) → B (∣ a ∣₀)) → (x : ∥ A ∥₀) → B x elimSetTrunc Bset g ∣ a ∣₀ = g a elimSetTrunc {A = A} {B = B} Bset g (squash₀ x y p q i j) = isOfHLevel→isOfHLevelDep {n = 2} Bset (elimSetTrunc Bset g x) (elimSetTrunc Bset g y) (cong (elimSetTrunc Bset g) p) (cong (elimSetTrunc Bset g) q) (squash₀ x y p q) i j setTruncUniversal : {B : Type ℓ} → (isSet B) → (∥ A ∥₀ → B) ≃ (A → B) setTruncUniversal Bset = isoToEquiv (iso intro elim leftInv rightInv) where intro = (λ h a → h ∣ a ∣₀) elim = elimSetTrunc (λ x → Bset) leftInv : ∀ g → intro (elim g) ≡ g leftInv g = refl rightInv : ∀ h → elim (intro h) ≡ h rightInv h i x = elimSetTrunc (λ x → isProp→isSet (Bset (elim (intro h) x) (h x))) (λ a → refl) x i elimSetTrunc2 : {B : ∥ A ∥₀ → ∥ A ∥₀ → Type ℓ} (Bset : ((x y : ∥ A ∥₀) → isSet (B x y))) (g : (a b : A) → B ∣ a ∣₀ ∣ b ∣₀) (x y : ∥ A ∥₀) → B x y elimSetTrunc2 Bset g = elimSetTrunc (λ _ → hLevelPi 2 (λ _ → Bset _ _)) (λ a → elimSetTrunc (λ _ → Bset _ _) (λ b → g a b)) elimSetTrunc3 : {B : (x y z : ∥ A ∥₀) → Type ℓ} (Bset : ((x y z : ∥ A ∥₀) → isSet (B x y z))) (g : (a b c : A) → B ∣ a ∣₀ ∣ b ∣₀ ∣ c ∣₀) (x y z : ∥ A ∥₀) → B x y z elimSetTrunc3 Bset g = elimSetTrunc2 (λ _ _ → hLevelPi 2 λ _ → Bset _ _ _) (λ a b → elimSetTrunc (λ _ → Bset _ _ _) (λ c → g a b c))
{ "alphanum_fraction": 0.5325875486, "avg_line_length": 33.7049180328, "ext": "agda", "hexsha": "38d85a06e7810e34d23d09f50b273ab1038644ca", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cj-xu/cubical", "max_forks_repo_path": "Cubical/HITs/SetTruncation/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cj-xu/cubical", "max_issues_repo_path": "Cubical/HITs/SetTruncation/Properties.agda", "max_line_length": 88, "max_stars_count": null, "max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cj-xu/cubical", "max_stars_repo_path": "Cubical/HITs/SetTruncation/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 824, "size": 2056 }
-- Andreas, 2020-06-21, issue #4769 -- Name and hiding ignored in subsequent face constraint patterns. -- Instead, we should throw a warning. open import Agda.Primitive.Cubical data S : Set where base : S foo : ∀ i j → Partial _ S foo i j (i = i0) {{agdaDoesNotSeeThisName = (j = i1)}} = base -- Expect: warning about name and "instance" flavor and argument.
{ "alphanum_fraction": 0.698630137, "avg_line_length": 26.0714285714, "ext": "agda", "hexsha": "9a38acf5c9046902da96294c6b61c626f73e258f", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Succeed/Issue4769.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue4769.agda", "max_line_length": 66, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue4769.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 108, "size": 365 }
open import Prelude hiding (subst) module Implicits.Substitutions.MetaType where open import Implicits.Syntax.Type open import Implicits.Syntax.MetaType open import Data.Fin.Substitution open import Data.Star as Star hiding (map) open import Data.Star.Properties open import Data.Nat.Properties.Simple open import Data.Vec hiding ([_]) module MetaTypeTypeSubst where MetaSub : (ℕ → ℕ → Set) → ℕ → ℕ → ℕ → Set MetaSub T m ν μ = Sub (T m) ν μ record MetaLift (T : ℕ → ℕ → Set) : Set where field simple : ∀ {m} → Simple (T m) lift : ∀ {m ν} → T m ν → MetaType m ν module MetaTypeApp {T} (l : MetaLift T) where open MetaLift l infixl 8 _/_ mutual _s/_ : ∀ {m μ ν} → MetaSimpleType m ν → MetaSub T m ν μ → MetaType m μ tvar x s/ σ = lift (lookup x σ) mvar x s/ σ = simpl (mvar x) (a →' b) s/ σ = simpl ((a / σ) →' (b / σ)) tc c s/ σ = simpl (tc c) _/_ : ∀ {m μ ν} → MetaType m ν → MetaSub T m ν μ → MetaType m μ simpl x / σ = (x s/ σ) (a ⇒ b) / σ = (a / σ) ⇒ (b / σ) (∀' a) / σ = ∀' (a / σ ↑) where open Simple simple module _ {m : ℕ} where open Application (record { _/_ = _/_ {m = m} }) public using (_/✶_) open Simple (simple {m}) →'-/✶-↑✶ : ∀ k {n n' a b} (ρs : Subs (T m) n n') → (simpl (a →' b)) /✶ ρs ↑✶ k ≡ simpl ((a /✶ ρs ↑✶ k) →' (b /✶ ρs ↑✶ k)) →'-/✶-↑✶ k ε = refl →'-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (→'-/✶-↑✶ k ρs) refl ⇒-/✶-↑✶ : ∀ k {n n' a b} (ρs : Subs (T m) n n') → (a ⇒ b) /✶ ρs ↑✶ k ≡ (a /✶ ρs ↑✶ k) ⇒ (b /✶ ρs ↑✶ k) ⇒-/✶-↑✶ k ε = refl ⇒-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (⇒-/✶-↑✶ k ρs) refl tc-/✶-↑✶ : ∀ k {c n n'} (ρs : Subs (T m) n n') → (simpl (tc c)) /✶ ρs ↑✶ k ≡ simpl (tc c) tc-/✶-↑✶ k ε = refl tc-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (tc-/✶-↑✶ k ρs) refl mvar-/✶-↑✶ : ∀ k {n n' c} (ρs : Subs (T m) n n') → (simpl (mvar c)) /✶ ρs ↑✶ k ≡ simpl (mvar c) mvar-/✶-↑✶ k ε = refl mvar-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (mvar-/✶-↑✶ k ρs) refl ∀'-/✶-↑✶ : ∀ k {n n' a} (ρs : Subs (T m) n n') → (∀' a) /✶ ρs ↑✶ k ≡ ∀' (a /✶ ρs ↑✶ (suc k)) ∀'-/✶-↑✶ k ε = refl ∀'-/✶-↑✶ k (x ◅ ρs) = cong₂ _/_ (∀'-/✶-↑✶ k ρs) refl Fin′ : ℕ → ℕ → Set Fin′ m ν = Fin ν module Lifted {m} {T} (lift : MetaLift T) where application : Application (MetaType m) (T m) application = record { _/_ = MetaTypeApp._/_ lift } open MetaLift lift public open Application application public open Simple (simple {m}) public varLift : MetaLift Fin′ varLift = record { simple = record { var = Prelude.id ; weaken = suc } ; lift = (λ n → simpl (tvar n)) } infixl 8 _/Var_ _/Var_ : ∀ {m n k} → MetaType m n → Sub Fin n k → MetaType m k _/Var_ = MetaTypeApp._/_ varLift simple : ∀ {m} → Simple (MetaType m) simple = record { var = λ x → simpl (tvar x); weaken = λ x → x /Var VarSubst.wk } termLift : MetaLift MetaType termLift = record { simple = simple; lift = Prelude.id } private module ExpandSubst {n : ℕ} where app : Application (MetaType n) (MetaType n) app = record { _/_ = MetaTypeApp._/_ termLift } subst : Subst (MetaType n) subst = record { simple = simple ; application = app } open Subst subst public open ExpandSubst public hiding (var; simple) module MetaTypeMetaSubst where MetaSub : (ℕ → ℕ → Set) → ℕ → ℕ → ℕ → Set MetaSub T ν m m' = Sub (flip T ν) m m' record ExpandSimple (T : ℕ → ℕ → Set) : Set where field simple : ∀ {ν} → Simple (flip T ν) module _ {ν : ℕ} where open Simple (simple {ν}) public record ExpandApp (T : ℕ → ℕ → Set) : Set where field app : ∀ {ν} → Application (flip MetaType ν) (flip T ν) module _ {ν : ℕ} where open Application (app {ν}) public record MetaLift (T : ℕ → ℕ → Set) : Set where field exp-simple : ExpandSimple T lift : ∀ {m ν} → T m ν → MetaType m ν tpweaken : ∀ {m ν} → T m ν → T m (suc ν) open ExpandSimple exp-simple using (simple; _↑; weaken) renaming (var to evar) _↑tp : ∀ {m m' ν} → MetaSub T ν m m' → MetaSub T (suc ν) m m' _↑tp s = map tpweaken s field comm-weaken-tpweaken : ∀ {m ν} (a : T m ν) → weaken (tpweaken a) ≡ tpweaken (weaken a) tpweaken-var : ∀ {ν m} (n : Fin m) → (tpweaken {ν = ν} (evar n)) ≡ evar n _↑tp⋆_ : ∀ {m m' ν} → MetaSub T ν m m' → (k : ℕ) → MetaSub T (k + ν) m m' s ↑tp⋆ zero = s s ↑tp⋆ suc k = (s ↑tp⋆ k) ↑tp module MetaTypeApp {T} (l : MetaLift T) where open MetaLift l infixl 8 _/_ mutual _s/_ : ∀ {m n ν} → MetaSimpleType m ν → MetaSub T ν m n → MetaType n ν tvar x s/ σ = simpl (tvar x) mvar x s/ σ = lift (lookup x σ) (a →' b) s/ σ = simpl ((a / σ) →' (b / σ)) tc c s/ σ = simpl (tc c) _/_ : ∀ {m n ν} → MetaType m ν → MetaSub T ν m n → MetaType n ν simpl x / σ = (x s/ σ) (a ⇒ b) / σ = (a / σ) ⇒ (b / σ) (∀' a) / σ = ∀' (a / σ ↑tp) open ExpandApp (record { app = record { _/_ = _/_ } }) hiding (_/_) open ExpandSimple exp-simple Fin′ : ℕ → ℕ → Set Fin′ m ν = Fin m module Lifted {T} (lift : MetaLift T) where open ExpandApp (record { app = record { _/_ = MetaTypeApp._/_ lift }}) public open MetaLift lift public open ExpandSimple exp-simple public module _ where private exp-simple : ExpandSimple Fin′ exp-simple = record { simple = record { var = Prelude.id ; weaken = suc }} open ExpandSimple exp-simple varLift : MetaLift Fin′ varLift = record { tpweaken = Prelude.id ; exp-simple = exp-simple ; lift = (λ n → simpl (mvar n)) ; comm-weaken-tpweaken = λ s → refl ; tpweaken-var = λ n → refl } infixl 8 _/Var_ _/Var_ : ∀ {m m' ν} → MetaType m ν → Sub Fin m m' → MetaType m' ν _/Var_ = MetaTypeApp._/_ varLift simple : ∀ {ν} → Simple (flip MetaType ν) simple = record { var = λ x → simpl (mvar x); weaken = λ x → x /Var VarSubst.wk } module _ where exp-simple : ExpandSimple MetaType exp-simple = record { simple = simple } open ExpandSimple exp-simple module MTTS = MetaTypeTypeSubst _↑⋆tp_ : ∀ {m m' ν} → MetaSub MetaType ν m m' → ∀ k → MetaSub MetaType (k + ν) m m' x ↑⋆tp zero = x x ↑⋆tp (suc k) = map MTTS.weaken (x ↑⋆tp k) _↑tp : ∀ {m m' ν} → MetaSub MetaType ν m m' → MetaSub MetaType (suc ν) m m' x ↑tp = x ↑⋆tp 1 tp-weaken = MTTS.weaken comm-tp/var-/var : ∀ {ν ν' m m'} (a : MetaType m ν) {s : Sub Fin ν ν'} {s' : Sub Fin m m'} → (a MTTS./Var s) /Var s' ≡ (a /Var s') MTTS./Var s comm-tp/var-/var (a ⇒ b) = cong₂ _⇒_ (comm-tp/var-/var a) (comm-tp/var-/var b) comm-tp/var-/var (∀' a) = cong ∀' (comm-tp/var-/var a) comm-tp/var-/var (simpl (tvar x)) = refl comm-tp/var-/var (simpl (mvar x)) = refl comm-tp/var-/var (simpl (a →' b)) = cong₂ (λ u v → simpl (u →' v)) (comm-tp/var-/var a) (comm-tp/var-/var b) comm-tp/var-/var (simpl (tc c)) = refl comm-weaken-tpweaken : ∀ {m ν} (a : MetaType m ν) → weaken (tp-weaken a) ≡ tp-weaken (weaken a) comm-weaken-tpweaken (a ⇒ b) = cong₂ _⇒_ (comm-weaken-tpweaken a) (comm-weaken-tpweaken b) comm-weaken-tpweaken (∀' a) = cong ∀' (comm-tp/var-/var a) comm-weaken-tpweaken (simpl (tvar x)) = refl comm-weaken-tpweaken (simpl (mvar x)) = refl comm-weaken-tpweaken (simpl (a →' b)) = cong₂ (λ u v → simpl (u →' v)) (comm-weaken-tpweaken a) (comm-weaken-tpweaken b) comm-weaken-tpweaken (simpl (tc c)) = refl open import Data.Vec.Properties termLift : MetaLift MetaType termLift = record { tpweaken = MetaTypeTypeSubst.weaken ; exp-simple = exp-simple ; lift = Prelude.id ; comm-weaken-tpweaken = comm-weaken-tpweaken ; tpweaken-var = λ n → refl} private module ExpandSubst {n : ℕ} where app : Application (flip MetaType n) (flip MetaType n) app = record { _/_ = MetaTypeApp._/_ termLift } subst : Subst (flip MetaType n) subst = record { simple = simple ; application = app } open Subst subst public open ExpandSubst public hiding (var; simple) open-meta-k : ∀ {m ν} k → (a : MetaType m (k + suc ν)) → MetaType (suc m) (k + ν) open-meta-k {m} {ν} k a = (weaken a) MetaTypeTypeSubst./ (MetaTypeTypeSubst.sub (simpl (mvar zero)) MetaTypeTypeSubst.↑⋆ k) open-meta : ∀ {m ν} → (a : MetaType m (suc ν)) → MetaType (suc m) ν open-meta a = open-meta-k zero a _◁m₁ : ∀ {ν m} (r : MetaType m ν) → ℕ _◁m₁ (a ⇒ b) = b ◁m₁ _◁m₁ (∀' r) = 1 + r ◁m₁ _◁m₁ (simpl x) = zero -- heads of metatypes _◁m : ∀ {ν m} (r : MetaType m ν) → (MetaType ((r ◁m₁) + m) ν) (a ⇒ b) ◁m = b ◁m ∀' r ◁m = open-meta (r ◁m) simpl x ◁m = simpl x smeta-weaken : ∀ {m ν} → MetaSimpleType m ν → MetaSimpleType (suc m) ν smeta-weaken (tc x) = tc x smeta-weaken (tvar n) = tvar n smeta-weaken (mvar m) = mvar (suc m) smeta-weaken (a →' b) = weaken a →' weaken b
{ "alphanum_fraction": 0.5276371081, "avg_line_length": 32.3379790941, "ext": "agda", "hexsha": "f4d11d9aca983392d4c35069845acd568b4b7b43", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_path": "src/Implicits/Substitutions/MetaType.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_path": "src/Implicits/Substitutions/MetaType.agda", "max_line_length": 99, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/Implicits/Substitutions/MetaType.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z", "max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z", "num_tokens": 3604, "size": 9281 }
------------------------------------------------------------------------ -- Many properties which hold for _∼_ also hold for flip₁ _∼_ ------------------------------------------------------------------------ open import Relation.Binary module Relation.Binary.Flip where open import Data.Function open import Data.Product implies : ∀ {A} (≈ ∼ : Rel A) → ≈ ⇒ ∼ → flip₁ ≈ ⇒ flip₁ ∼ implies _ _ impl = impl reflexive : ∀ {A} (∼ : Rel A) → Reflexive ∼ → Reflexive (flip₁ ∼) reflexive _ refl = refl irreflexive : ∀ {A} (≈ ∼ : Rel A) → Irreflexive ≈ ∼ → Irreflexive (flip₁ ≈) (flip₁ ∼) irreflexive _ _ irrefl = irrefl symmetric : ∀ {A} (∼ : Rel A) → Symmetric ∼ → Symmetric (flip₁ ∼) symmetric _ sym = sym transitive : ∀ {A} (∼ : Rel A) → Transitive ∼ → Transitive (flip₁ ∼) transitive _ trans = flip trans antisymmetric : ∀ {A} (≈ ≤ : Rel A) → Antisymmetric ≈ ≤ → Antisymmetric (flip₁ ≈) (flip₁ ≤) antisymmetric _ _ antisym = antisym asymmetric : ∀ {A} (< : Rel A) → Asymmetric < → Asymmetric (flip₁ <) asymmetric _ asym = asym respects : ∀ {A} (∼ : Rel A) P → Symmetric ∼ → P Respects ∼ → P Respects flip₁ ∼ respects _ _ sym resp ∼ = resp (sym ∼) respects₂ : ∀ {A} (∼₁ ∼₂ : Rel A) → Symmetric ∼₂ → ∼₁ Respects₂ ∼₂ → flip₁ ∼₁ Respects₂ flip₁ ∼₂ respects₂ _ _ sym (resp₁ , resp₂) = ((λ {_} {_} {_} ∼ → resp₂ (sym ∼)) , λ {_} {_} {_} ∼ → resp₁ (sym ∼)) decidable : ∀ {A} (∼ : Rel A) → Decidable ∼ → Decidable (flip₁ ∼) decidable _ dec x y = dec y x total : ∀ {A} (∼ : Rel A) → Total ∼ → Total (flip₁ ∼) total _ tot x y = tot y x trichotomous : ∀ {A} (≈ < : Rel A) → Trichotomous ≈ < → Trichotomous (flip₁ ≈) (flip₁ <) trichotomous _ _ compare x y = compare y x isEquivalence : ∀ {A} {≈ : Rel A} → IsEquivalence ≈ → IsEquivalence (flip₁ ≈) isEquivalence {≈ = ≈} eq = record { refl = reflexive ≈ Eq.refl ; sym = symmetric ≈ Eq.sym ; trans = transitive ≈ Eq.trans } where module Eq = IsEquivalence eq setoid : Setoid → Setoid setoid S = record { _≈_ = flip₁ S._≈_ ; isEquivalence = isEquivalence S.isEquivalence } where module S = Setoid S isPreorder : ∀ {A} {≈ ∼ : Rel A} → IsPreorder ≈ ∼ → IsPreorder (flip₁ ≈) (flip₁ ∼) isPreorder {≈ = ≈} {∼} pre = record { isEquivalence = isEquivalence Pre.isEquivalence ; reflexive = implies ≈ ∼ Pre.reflexive ; trans = transitive ∼ Pre.trans ; ∼-resp-≈ = respects₂ ∼ ≈ Pre.Eq.sym Pre.∼-resp-≈ } where module Pre = IsPreorder pre preorder : Preorder → Preorder preorder P = record { _∼_ = flip₁ P._∼_ ; _≈_ = flip₁ P._≈_ ; isPreorder = isPreorder P.isPreorder } where module P = Preorder P isDecEquivalence : ∀ {A} {≈ : Rel A} → IsDecEquivalence ≈ → IsDecEquivalence (flip₁ ≈) isDecEquivalence {≈ = ≈} dec = record { isEquivalence = isEquivalence Dec.isEquivalence ; _≟_ = decidable ≈ Dec._≟_ } where module Dec = IsDecEquivalence dec decSetoid : DecSetoid → DecSetoid decSetoid S = record { _≈_ = flip₁ S._≈_ ; isDecEquivalence = isDecEquivalence S.isDecEquivalence } where module S = DecSetoid S isPartialOrder : ∀ {A} {≈ ≤ : Rel A} → IsPartialOrder ≈ ≤ → IsPartialOrder (flip₁ ≈) (flip₁ ≤) isPartialOrder {≈ = ≈} {≤} po = record { isPreorder = isPreorder Po.isPreorder ; antisym = antisymmetric ≈ ≤ Po.antisym } where module Po = IsPartialOrder po poset : Poset → Poset poset O = record { _≈_ = flip₁ O._≈_ ; _≤_ = flip₁ O._≤_ ; isPartialOrder = isPartialOrder O.isPartialOrder } where module O = Poset O isStrictPartialOrder : ∀ {A} {≈ < : Rel A} → IsStrictPartialOrder ≈ < → IsStrictPartialOrder (flip₁ ≈) (flip₁ <) isStrictPartialOrder {≈ = ≈} {<} spo = record { isEquivalence = isEquivalence Spo.isEquivalence ; irrefl = irreflexive ≈ < Spo.irrefl ; trans = transitive < Spo.trans ; <-resp-≈ = respects₂ < ≈ Spo.Eq.sym Spo.<-resp-≈ } where module Spo = IsStrictPartialOrder spo strictPartialOrder : StrictPartialOrder → StrictPartialOrder strictPartialOrder O = record { _≈_ = flip₁ O._≈_ ; _<_ = flip₁ O._<_ ; isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder } where module O = StrictPartialOrder O isTotalOrder : ∀ {A} {≈ ≤ : Rel A} → IsTotalOrder ≈ ≤ → IsTotalOrder (flip₁ ≈) (flip₁ ≤) isTotalOrder {≈ = ≈} {≤} to = record { isPartialOrder = isPartialOrder To.isPartialOrder ; total = total ≤ To.total } where module To = IsTotalOrder to totalOrder : TotalOrder → TotalOrder totalOrder O = record { _≈_ = flip₁ O._≈_ ; _≤_ = flip₁ O._≤_ ; isTotalOrder = isTotalOrder O.isTotalOrder } where module O = TotalOrder O isDecTotalOrder : ∀ {A} {≈ ≤ : Rel A} → IsDecTotalOrder ≈ ≤ → IsDecTotalOrder (flip₁ ≈) (flip₁ ≤) isDecTotalOrder {≈ = ≈} {≤} dec = record { isTotalOrder = isTotalOrder Dec.isTotalOrder ; _≟_ = decidable ≈ Dec._≟_ ; _≤?_ = decidable ≤ Dec._≤?_ } where module Dec = IsDecTotalOrder dec decTotalOrder : DecTotalOrder → DecTotalOrder decTotalOrder O = record { _≈_ = flip₁ O._≈_ ; _≤_ = flip₁ O._≤_ ; isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder } where module O = DecTotalOrder O isStrictTotalOrder : ∀ {A} {≈ < : Rel A} → IsStrictTotalOrder ≈ < → IsStrictTotalOrder (flip₁ ≈) (flip₁ <) isStrictTotalOrder {≈ = ≈} {<} sto = record { isEquivalence = isEquivalence Sto.isEquivalence ; trans = transitive < Sto.trans ; compare = trichotomous ≈ < Sto.compare ; <-resp-≈ = respects₂ < ≈ Sto.Eq.sym Sto.<-resp-≈ } where module Sto = IsStrictTotalOrder sto strictTotalOrder : StrictTotalOrder → StrictTotalOrder strictTotalOrder O = record { _≈_ = flip₁ O._≈_ ; _<_ = flip₁ O._<_ ; isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder } where module O = StrictTotalOrder O
{ "alphanum_fraction": 0.5785564347, "avg_line_length": 33.6576086957, "ext": "agda", "hexsha": "10fe317b542557d6c20eaf6cd536449fa388f96c", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/Relation/Binary/Flip.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/Relation/Binary/Flip.agda", "max_line_length": 72, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/Relation/Binary/Flip.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 2115, "size": 6193 }
module spaceShipCell where open import Unit open import Data.List.Base hiding ([]) open import Data.Bool.Base open import Data.Integer open import Data.Product hiding (map) open import NativeIO open import SizedIO.Object open import SizedIO.IOObject open import StateSizedIO.GUI.WxBindingsFFI open import StateSizedIO.GUI.WxGraphicsLib open import StateSized.GUI.ShipBitMap open import SizedIO.Base open import StateSizedIO.GUI.BaseStateDependent open import StateSizedIO.GUI.VariableList open import Sized.SimpleCell hiding (main; program) VarType = Object (cellI ℤ) cellℤC : (z : ℤ ) → VarType objectMethod (cellℤC z) get = ( z , cellℤC z ) objectMethod (cellℤC z) (put z') = ( _ , cellℤC z' ) varInit : VarType varInit = cellℤC (+ 150) onPaint : ∀{i} → VarType → DC → Rect → IO GuiLev1Interface i VarType onPaint c dc rect = let (z , c₁) = objectMethod c get in do (drawBitmap dc ship (z , (+ 150)) true) λ _ → return c₁ moveSpaceShip : ∀{i} → Frame → VarType → IO GuiLev1Interface i VarType moveSpaceShip fra c = let (z , c₁) = objectMethod c get (_ , c₂) = objectMethod c₁ (put (z + + 20)) in return c₂ callRepaint : ∀{i} → Frame → VarType → IO GuiLev1Interface i VarType callRepaint fra c = do (repaint fra) λ _ → return c buttonHandler : ∀{i} → Frame → List (VarType → IO GuiLev1Interface i VarType) buttonHandler fra = moveSpaceShip fra ∷ [ callRepaint fra ] program : ∀{i} → IOˢ GuiLev2Interface i (λ _ → Unit) [] program = doˢ (level1C makeFrame) λ fra → doˢ (level1C (makeButton fra)) λ bt → doˢ (level1C (addButton fra bt)) λ _ → doˢ (createVar varInit) λ _ → doˢ (setButtonHandler bt (buttonHandler fra)) λ _ → doˢ (setOnPaint fra [ onPaint ]) returnˢ main : NativeIO Unit main = start (translateLev2 program)
{ "alphanum_fraction": 0.6649159664, "avg_line_length": 32.2711864407, "ext": "agda", "hexsha": "2ef6f632a2bd8080c0979d243748019317fcc99a", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/spaceShipCell.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/spaceShipCell.agda", "max_line_length": 78, "max_stars_count": 23, "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/spaceShipCell.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z", "num_tokens": 616, "size": 1904 }
module FFI where open import Common.Prelude _+'_ : Nat → Nat → Nat zero +' y = y suc x +' y = suc (x +' y) {-# COMPILE GHC _+'_ = (+) :: Integer -> Integer -> Integer #-} -- on-purpose buggy haskell implementation! _+''_ : Nat → Nat → Nat zero +'' y = y suc x +'' y = suc (x +'' y) {-# COMPILE GHC _+''_ = (-) :: Integer -> Integer -> Integer #-} open import Common.IO open import Common.Unit main : IO Unit main = printNat (10 +' 5) ,, printNat (30 +'' 7)
{ "alphanum_fraction": 0.5695931478, "avg_line_length": 18.68, "ext": "agda", "hexsha": "8a7f1e8a306e065e3bb25c6a903384369684e51f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Blaisorblade/Agda", "max_forks_repo_path": "test/Compiler/simple/FFI.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "Blaisorblade/Agda", "max_issues_repo_path": "test/Compiler/simple/FFI.agda", "max_line_length": 64, "max_stars_count": 3, "max_stars_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "Blaisorblade/Agda", "max_stars_repo_path": "test/Compiler/simple/FFI.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 151, "size": 467 }
module Spire.IDarkwingDuck.Primitive where ---------------------------------------------------------------------- infixr 4 _,_ infixr 5 _∷_ ---------------------------------------------------------------------- postulate String : Set {-# BUILTIN STRING String #-} ---------------------------------------------------------------------- data ⊥ : Set where elimBot : (P : ⊥ → Set) (v : ⊥) → P v elimBot P () ---------------------------------------------------------------------- data ⊤ : Set where tt : ⊤ elimUnit : (P : ⊤ → Set) (ptt : P tt) (u : ⊤) → P u elimUnit P ptt tt = ptt ---------------------------------------------------------------------- data Σ (A : Set) (B : A → Set) : Set where _,_ : (a : A) (b : B a) → Σ A B elimPair : {A : Set} {B : A → Set} (P : Σ A B → Set) (ppair : (a : A) (b : B a) → P (a , b)) (ab : Σ A B) → P ab elimPair P ppair (a , b) = ppair a b ---------------------------------------------------------------------- data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x elimEq : {A : Set} {x : A} (P : (y : A) → x ≡ y → Set) (prefl : P x refl) (y : A) (q : x ≡ y) → P y q elimEq P prefl x refl = prefl ---------------------------------------------------------------------- data List (A : Set) : Set where [] : List A _∷_ : (x : A) (xs : List A) → List A elimList : {A : Set} (P : List A → Set) (pnil : P []) (pcons : (x : A) (xs : List A) → P xs → P (x ∷ xs)) (xs : List A) → P xs elimList P pnil pcons [] = pnil elimList P pnil pcons (x ∷ xs) = pcons x xs (elimList P pnil pcons xs) ---------------------------------------------------------------------- data PointsTo (A : Set) : List A → Set where here : ∀{x xs} → PointsTo A (x ∷ xs) there : ∀{x xs} → PointsTo A xs → PointsTo A (x ∷ xs) elimPointsTo : {A : Set} (P : (xs : List A) → PointsTo A xs → Set) (phere : (x : A) (xs : List A) → P (x ∷ xs) here) (pthere : (x : A) (xs : List A) (t : PointsTo A xs) → P xs t → P (x ∷ xs) (there t)) (xs : List A) (t : PointsTo A xs) → P xs t elimPointsTo P phere pthere (x ∷ xs) here = phere x xs elimPointsTo P phere pthere (x ∷ xs) (there t) = pthere x xs t (elimPointsTo P phere pthere xs t) ---------------------------------------------------------------------- data Tel : Set₁ where End : Tel Arg IArg : (A : Set) (B : A → Tel) → Tel elimTel : (P : Tel → Set) (pend : P End) (parg : (A : Set) (B : A → Tel) (pb : (a : A) → P (B a)) → P (Arg A B)) (piarg : (A : Set) (B : A → Tel) (pb : (a : A) → P (B a)) → P (IArg A B)) (T : Tel) → P T elimTel P pend parg piarg End = pend elimTel P pend parg piarg (Arg A B) = parg A B (λ a → elimTel P pend parg piarg (B a)) elimTel P pend parg piarg (IArg A B) = piarg A B (λ a → elimTel P pend parg piarg (B a)) ---------------------------------------------------------------------- data Desc (I : Set) : Set₁ where End : (i : I) → Desc I Rec : (i : I) (D : Desc I) → Desc I Arg : (A : Set) (B : A → Desc I) → Desc I IArg : (A : Set) (B : A → Desc I) → Desc I elimDesc : {I : Set} (P : Desc I → Set) (pend : (i : I) → P (End i)) (prec : (i : I) (D : Desc I) (pd : P D) → P (Rec i D)) (parg : (A : Set) (B : A → Desc I) (pb : (a : A) → P (B a)) → P (Arg A B)) (piarg : (A : Set) (B : A → Desc I) (pb : (a : A) → P (B a)) → P (IArg A B)) (D : Desc I) → P D elimDesc P pend prec parg piarg (End i) = pend i elimDesc P pend prec parg piarg (Rec i D) = prec i D (elimDesc P pend prec parg piarg D) elimDesc P pend prec parg piarg (Arg A B) = parg A B (λ a → elimDesc P pend prec parg piarg (B a)) elimDesc P pend prec parg piarg (IArg A B) = piarg A B (λ a → elimDesc P pend prec parg piarg (B a)) Elᴰ : {I : Set} (D : Desc I) → (I → Set) → I → Set Elᴰ (End j) X i = j ≡ i Elᴰ (Rec j D) X i = Σ (X j) (λ _ → Elᴰ D X i) Elᴰ (Arg A B) X i = Σ A (λ a → Elᴰ (B a) X i) Elᴰ (IArg A B) X i = Σ A (λ a → Elᴰ (B a) X i) Hyps : {I : Set} (D : Desc I) (X : I → Set) (P : (i : I) → X i → Set) (i : I) (xs : Elᴰ D X i) → Set Hyps (End j) X P i q = ⊤ Hyps (Rec j D) X P i (x , xs) = Σ (P j x) (λ _ → Hyps D X P i xs) Hyps (Arg A B) X P i (a , b) = Hyps (B a) X P i b Hyps (IArg A B) X P i (a , b) = Hyps (B a) X P i b ---------------------------------------------------------------------- data μ {I : Set} (D : Desc I) (i : I) : Set where init : Elᴰ D (μ D) i → μ D i ind : {I : Set} (D : Desc I) (M : (i : I) → μ D i → Set) (α : ∀ i (xs : Elᴰ D (μ D) i) (ihs : Hyps D (μ D) M i xs) → M i (init xs)) (i : I) (x : μ D i) → M i x prove : {I : Set} (D E : Desc I) (M : (i : I) → μ E i → Set) (α : ∀ i (xs : Elᴰ E (μ E) i) (ihs : Hyps E (μ E) M i xs) → M i (init xs)) (i : I) (xs : Elᴰ D (μ E) i) → Hyps D (μ E) M i xs ind D M α i (init xs) = α i xs (prove D D M α i xs) prove (End j) E M α i q = tt prove (Rec j D) E M α i (x , xs) = ind E M α j x , prove D E M α i xs prove (Arg A B) E M α i (a , xs) = prove (B a) E M α i xs prove (IArg A B) E M α i (a , xs) = prove (B a) E M α i xs ----------------------------------------------------------------------
{ "alphanum_fraction": 0.4186507937, "avg_line_length": 33.8255033557, "ext": "agda", "hexsha": "31e90b0912c5673258df1f86e91676621d00d2f4", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-08-17T21:00:07.000Z", "max_forks_repo_forks_event_min_datetime": "2015-08-17T21:00:07.000Z", "max_forks_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "spire/spire", "max_forks_repo_path": "formalization/agda/Spire/IDarkwingDuck/Primitive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "spire/spire", "max_issues_repo_path": "formalization/agda/Spire/IDarkwingDuck/Primitive.agda", "max_line_length": 100, "max_stars_count": 43, "max_stars_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "spire/spire", "max_stars_repo_path": "formalization/agda/Spire/IDarkwingDuck/Primitive.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T17:10:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-28T23:25:33.000Z", "num_tokens": 1953, "size": 5040 }
-- Andreas, 2015-07-13 Better parse errors for illegal type signatures A rewrite B : Set
{ "alphanum_fraction": 0.7472527473, "avg_line_length": 22.75, "ext": "agda", "hexsha": "b5af85cd1656f883b64a1529b8692ba145533438", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue1609e.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue1609e.agda", "max_line_length": 71, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue1609e.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 25, "size": 91 }
module Category where open import Function hiding (_∘_; id) open import Level open import Data.Product open import Relation.Binary open import Relation.Binary.Core using (_≡_) open Setoid renaming (_≈_ to eqSetoid) open import Basic record Category (C₀ C₁ ℓ : Level) : Set (suc (C₀ ⊔ C₁ ⊔ ℓ)) where field Obj : Set C₀ Homsetoid : Obj → Obj → Setoid C₁ ℓ Hom : Obj → Obj → Set C₁ Hom A B = Carrier (Homsetoid A B) equal : {A B : Obj} → Hom A B → Hom A B → Set ℓ equal {A} {B} f g = eqSetoid (Homsetoid A B) f g field comp : {A B C : Obj} → Hom B C → Hom A B → Hom A C id : {A : Obj} → Hom A A field leftId : {A B : Obj} {f : Hom A B} → equal (comp id f) f rightId : {A B : Obj} {f : Hom A B} → equal (comp f id) f assoc : {A B C D : Obj} {f : Hom A B} {g : Hom B C} {h : Hom C D} → equal (comp (comp h g) f) (comp h (comp g f)) ≈-composite : {A B C : Obj} {f g : Hom B C} {h i : Hom A B} → equal f g → equal h i → equal (comp f h) (comp g i) dom : {A B : Obj} → Hom A B → Obj dom {A} _ = A cod : {A B : Obj} → Hom A B → Obj cod {B} _ = B op : Category C₀ C₁ ℓ op = record { Obj = Obj ; Homsetoid = flip Homsetoid ; comp = flip comp ; id = id ; leftId = rightId ; rightId = leftId ; assoc = λ{A B C D} → IsEquivalence.sym (isEquivalence (Homsetoid D A)) assoc ; ≈-composite = flip ≈-composite } open Category infixr 9 _∘_ infixr 7 _[_∘_] infixr 2 _≈_ infixr 2 _[_≈_] infix 4 _[_≅_] _[_∘_] : ∀{C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) {a b c : Obj C} → Hom C b c → Hom C a b → Hom C a c C [ f ∘ g ] = comp C f g _∘_ : ∀{C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} {a b c : Obj C} → Hom C b c → Hom C a b → Hom C a c _∘_ {C = C} = _[_∘_] C _[_≈_] : ∀{C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) {A B : Obj C} → Rel (Hom C A B) ℓ C [ f ≈ g ] = equal C f g _≈_ : ∀{C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} {A B : Obj C} → Rel (Hom C A B) ℓ _≈_ {C = C} = equal C equiv : ∀{C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) {A B : Obj C} → IsEquivalence (eqSetoid (Homsetoid C A B)) equiv C {A} {B} = isEquivalence (Homsetoid C A B) refl-hom : ∀{C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) {A B : Obj C} {f : Hom C A B} → C [ f ≈ f ] refl-hom C = IsEquivalence.refl (equiv C) sym-hom : ∀{C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) {A B : Obj C} {f g : Hom C A B} → C [ f ≈ g ] → C [ g ≈ f ] sym-hom C = IsEquivalence.sym (equiv C) trans-hom : ∀{C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) {A B : Obj C} {f g h : Hom C A B} → C [ f ≈ g ] → C [ g ≈ h ] → C [ f ≈ h ] trans-hom C = IsEquivalence.trans (equiv C) record _[_≅_] {C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) (a b : Obj C) : Set (C₀ ⊔ C₁ ⊔ ℓ) where field map-→ : Hom C a b map-← : Hom C b a proof : (C [ C [ map-→ ∘ map-← ] ≈ id C ]) × (C [ C [ map-← ∘ map-→ ] ≈ id C ]) record isomorphism {C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) {a b : Obj C} (f : Hom C a b) : Set (C₀ ⊔ C₁ ⊔ ℓ) where field inverse-map : Hom C b a proof : (C [ C [ f ∘ inverse-map ] ≈ id C ]) × (C [ C [ inverse-map ∘ f ] ≈ id C ]) iso-≅ : ∀ {C₀ C₁ ℓ} (C : Category C₀ C₁ ℓ) {a b : Obj C} {f : Hom C a b} → isomorphism C f → C [ a ≅ b ] iso-≅ C {f = f} iso = record { map-→ = f ; map-← = isomorphism.inverse-map iso ; proof = isomorphism.proof iso } Setoids : {c₀ ℓ : Level} → Category (suc (c₀ ⊔ ℓ)) (suc (c₀ ⊔ ℓ)) (c₀ ⊔ ℓ) Setoids {c₀} {ℓ} = record { Obj = Setoid c₀ ℓ; Homsetoid = λ A B → record { Carrier = Map.Map A B; _≈_ = Map.equality; isEquivalence = Map-Equal-Equiv A B }; comp = Map.compose; id = Map.identity; leftId = λ {_ B} _ → refl B; rightId = λ {_ B} _ → refl B; assoc = λ {_ _ _ D} x → refl D; ≈-composite = λ {_ _ C f g h} x x₁ x₂ → trans C (x (Map.Map.mapping h x₂)) (Map.Map.preserveEq g (x₁ x₂)) } where Map-Equal-Equiv : (A B : Setoid _ _) → IsEquivalence Map.equality Map-Equal-Equiv A B = record { refl = λ _ → refl B ; sym = λ x x₁ → sym B (x x₁) ; trans = λ x x₁ x₂ → trans B (x x₂) (x₁ x₂) } module CategoryReasoning where infix 1 begin⟨_⟩_ infixr 2 _≈⟨_⟩_ _≡⟨_⟩_ infix 3 _∎ data IsRelatedTo[_] {c₀ c₁ ℓ} (C : Category c₀ c₁ ℓ) (a b : Obj C) (x y : Hom C a b) : Set ℓ where relTo : C [ x ≈ y ] → IsRelatedTo[ C ] a b x y begin⟨_⟩_ : ∀ {c₀ c₁ ℓ} (C : Category c₀ c₁ ℓ) → {A B : Obj C} {f g : Hom C A B} → IsRelatedTo[ C ] A B f g → equal C f g begin⟨_⟩_ C {A} {B} (relTo x≈y) = x≈y _∎ : ∀ {c₀ c₁ ℓ} {C : Category c₀ c₁ ℓ} {A B : Obj C} (f : Hom C A B) → IsRelatedTo[ C ] A B f f _∎ {C = C} f = relTo (refl-hom C) _≈⟨_⟩_ : ∀ {c₀ c₁ ℓ} {C : Category c₀ c₁ ℓ} → {A B : Obj C} (f : Hom C A B) → {g h : Hom C A B} → equal C f g → IsRelatedTo[ C ] A B g h → IsRelatedTo[ C ] A B f h _≈⟨_⟩_ {C = C} f f≈g (relTo g≈h) = relTo (trans-hom C f≈g g≈h) _≡⟨_⟩_ : ∀ {c₀ c₁ ℓ} {C : Category c₀ c₁ ℓ} → {A B : Obj C} (f : Hom C A B) → {g h : Hom C A B} → f ≡ g → IsRelatedTo[ C ] A B g h → IsRelatedTo[ C ] A B f h _≡⟨_⟩_ {C = C} f _≡_.refl (relTo g≈h) = relTo g≈h open CategoryReasoning public
{ "alphanum_fraction": 0.5398337726, "avg_line_length": 35.7463768116, "ext": "agda", "hexsha": "d1dd359d5740c42b7857a03095841fb777936424", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "myuon/agda-cate", "max_forks_repo_path": "src/Category.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "myuon/agda-cate", "max_issues_repo_path": "src/Category.agda", "max_line_length": 165, "max_stars_count": 2, "max_stars_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "myuon/agda-cate", "max_stars_repo_path": "src/Category.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-02T07:30:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-07-28T04:59:31.000Z", "num_tokens": 2235, "size": 4933 }
module Cats.Util.Simp where open import Data.List using (List ; [] ; _∷_) open import Data.Nat using (ℕ ; zero ; suc) open import Data.Product using (_×_ ; _,_ ; ∃-syntax) open import Data.Unit using (⊤) open import Function using () renaming (_∘_ to _⊚_) open import Level using (_⊔_) renaming (zero to lzero) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_ ; inspect ; [_]) open import Cats.Category.Base open import Cats.Util.Reflection _>>=_ = bindTC return = returnTC _>>_ : ∀ {a} {A : Set a} {b} {B : Set b} → TC A → TC B → TC B ma >> mb = ma >>= λ _ → mb module _ {lo la l≈} (C : Category lo la l≈) where infixr 9 _∘_ private module C = Category C module ≈ = C.≈ open C.≈-Reasoning data Tm : C.Obj → C.Obj → Set (lo ⊔ la) where var : ∀ {A B} → A C.⇒ B → Tm A B id : ∀ {A} → Tm A A _∘_ : ∀ {A B C} → Tm B C → Tm A B → Tm A C ⟦_⟧ : ∀ {A B} → Tm A B → A C.⇒ B ⟦ var f ⟧ = f ⟦ id ⟧ = C.id ⟦ f ∘ g ⟧ = ⟦ f ⟧ C.∘ ⟦ g ⟧ Method : Set (lo ⊔ la) Method = ∀ {A B} → Tm A B → Tm A B Correct : Method → Set (lo ⊔ la ⊔ l≈) Correct f = ∀ {A B} (t : Tm A B) → ⟦ t ⟧ C.≈ ⟦ f t ⟧ Correct→Injective : (f : Method) → Correct f → ∀ {A B} (t u : Tm A B) → ⟦ f t ⟧ C.≈ ⟦ f u ⟧ → ⟦ t ⟧ C.≈ ⟦ u ⟧ Correct→Injective f fcor t u eq = ≈.trans (fcor t) (≈.trans eq (≈.sym (fcor u))) ⊚-correct : (f g : Method) → Correct f → Correct g → Correct (f ⊚ g) ⊚-correct _ _ fcor gcor t = ≈.trans (gcor _) (fcor _) {-# TERMINATING #-} reassoc : Method reassoc (var f) = var f reassoc id = id reassoc (var f ∘ g) = var f ∘ reassoc g reassoc (id ∘ g) = id ∘ reassoc g reassoc ((f ∘ g) ∘ h) = reassoc (f ∘ g ∘ h) {-# TERMINATING #-} reassoc-correct : Correct reassoc reassoc-correct (var f) = C.≈.refl reassoc-correct id = C.≈.refl reassoc-correct (var f ∘ g) = C.∘-resp-r (reassoc-correct g) reassoc-correct (id ∘ f) = C.∘-resp-r (reassoc-correct f) reassoc-correct ((f ∘ g) ∘ h) = ≈.trans C.assoc (reassoc-correct (f ∘ g ∘ h)) simpId : Method simpId (var x) = var x simpId id = id simpId (f ∘ g) with simpId f | simpId g ... | var f′ | var g′ = var f′ ∘ var g′ ... | var f′ | id = var f′ ... | var f′ | g′ ∘ g″ = var f′ ∘ g′ ∘ g″ ... | id | g′ = g′ ... | f′ ∘ f″ | var g′ = f′ ∘ f″ ∘ var g′ ... | f′ ∘ f″ | id = f′ ∘ f″ ... | f′ ∘ f″ | g′ ∘ g″ = f′ ∘ f″ ∘ g′ ∘ g″ simpId-correct : Correct simpId simpId-≡ : ∀ {A B} t {u : Tm A B} → simpId t ≡ u → ⟦ t ⟧ C.≈ ⟦ u ⟧ simpId-correct (var x) = C.≈.refl simpId-correct id = C.≈.refl simpId-correct (f ∘ g) with simpId f | inspect simpId f | simpId g | inspect simpId g ... | var f′ | [ eq-f ] | var g′ | [ eq-g ] = C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g) ... | var f′ | [ eq-f ] | id | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-r ... | var f′ | [ eq-f ] | g′ ∘ g″ | [ eq-g ] = C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g) ... | id | [ eq-f ] | g' | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-l ... | f′ ∘ f″ | [ eq-f ] | var x | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.assoc ... | f′ ∘ f″ | [ eq-f ] | id | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-r ... | f′ ∘ f″ | [ eq-f ] | g′ ∘ g″ | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.assoc simpId-≡ t eq = ≈.trans (simpId-correct t) (≈.reflexive (≡.cong ⟦_⟧ eq)) simp : Method simp = reassoc ⊚ simpId simp-correct : Correct simp simp-correct = ⊚-correct reassoc simpId reassoc-correct simpId-correct simp-injective : ∀ {A B} (t u : Tm A B) → ⟦ simp t ⟧ C.≈ ⟦ simp u ⟧ → ⟦ t ⟧ C.≈ ⟦ u ⟧ simp-injective = Correct→Injective simp simp-correct simp-injective′ : ∀ {A B} (t u : Tm A B) → simp t ≡ simp u → ⟦ t ⟧ C.≈ ⟦ u ⟧ simp-injective′ t u eq = simp-injective t u (≈.reflexive (≡.cong ⟦_⟧ eq)) reify : Term → Term reify (def (quote Category.id) (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH _ ∷ [])) = con (quote id) [] reify (def (quote Category._∘_) (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH _ ∷ argH _ ∷ argH _ ∷ argD f ∷ argD g ∷ [])) = con (quote _∘_) (argD (reify f) ∷ argD (reify g) ∷ []) reify t = con (quote Tm.var) (argD t ∷ []) matchGoal : Term → TC (Term × Term) matchGoal (def (quote Category._≈_) (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH A ∷ argH B ∷ argD f ∷ argD g ∷ [])) = return (reify f , reify g) matchGoal _ = typeError (strErr "matchGoal: not an equality" ∷ []) macro simp! : ∀ {lo la l≈} → Category lo la l≈ → Term → TC ⊤ simp! C hole = do goal ← inferType hole blockOnAnyMeta goal (lhs , rhs) ← matchGoal goal C′ ← quoteTC C let solution = def (quote simp-injective′) ( argD C′ ∷ argD lhs ∷ argD rhs ∷ argD (con (quote ≡.refl) []) ∷ []) unify hole solution module Test {lo la l≈} {C : Category lo la l≈} (let module C = Category C) {A B C′ D} {f : C′ C.⇒ D} {g : B C.⇒ C′} {h : A C.⇒ B} where test : ((C.id C.∘ f) C.∘ g) C.∘ h C.≈ C.id C.∘ f C.∘ g C.∘ h test = simp! C
{ "alphanum_fraction": 0.5052251568, "avg_line_length": 28.9175824176, "ext": "agda", "hexsha": "576cbf200fd286b02ec4cf966ec966baf0bb36eb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "alessio-b-zak/cats", "max_forks_repo_path": "Cats/Util/Simp.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "alessio-b-zak/cats", "max_issues_repo_path": "Cats/Util/Simp.agda", "max_line_length": 135, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "alessio-b-zak/cats", "max_stars_repo_path": "Cats/Util/Simp.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2323, "size": 5263 }
{- This file contains: - The first Eilenberg–Mac Lane type as a HIT -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.EilenbergMacLane1.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.GroupoidLaws renaming (assoc to assoc∙) open import Cubical.Algebra.Group.Base private variable ℓ : Level module _ (Group@(G , str) : Group ℓ) where open GroupStr str data EM₁ : Type ℓ where embase : EM₁ emloop : G → embase ≡ embase emcomp : (g h : G) → PathP (λ j → embase ≡ emloop h j) (emloop g) (emloop (g · h)) emsquash : ∀ (x y : EM₁) (p q : x ≡ y) (r s : p ≡ q) → r ≡ s {- The emcomp constructor fills the square: ^ emloop (g · h) [a]— — — >[c] ‖ ^ ‖ | emloop h ^ ‖ | j | [a]— — — >[b] ∙ — > emloop g i We use this to give another constructor-like construction: -} emloop-comp : (g h : G) → emloop (g · h) ≡ emloop g ∙ emloop h emloop-comp g h i = compPath-unique refl (emloop g) (emloop h) (emloop (g · h) , emcomp g h) (emloop g ∙ emloop h , compPath-filler (emloop g) (emloop h)) i .fst emloop-1g : emloop 1g ≡ refl emloop-1g = lUnit (emloop 1g) ∙∙ cong (_∙ emloop 1g) (sym (lCancel (emloop 1g)) ) ∙∙ sym (assoc∙ _ _ _) ∙∙ cong (sym (emloop 1g) ∙_) (sym (emloop-comp 1g 1g) ∙ cong emloop (·IdL 1g)) ∙∙ rCancel _ emloop-sym : (g : G) → emloop (inv g) ≡ sym (emloop g) emloop-sym g = rUnit _ ∙∙ cong (emloop (inv g) ∙_) (sym (rCancel (emloop g))) ∙∙ assoc∙ _ _ _ ∙∙ cong (_∙ sym (emloop g)) (sym (emloop-comp (inv g) g) ∙∙ cong emloop (·InvL g) ∙∙ emloop-1g) ∙∙ sym (lUnit _)
{ "alphanum_fraction": 0.5570200573, "avg_line_length": 28.1451612903, "ext": "agda", "hexsha": "d8c02d368ddd4640cc678ca27660572b3c2aad0e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/HITs/EilenbergMacLane1/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/HITs/EilenbergMacLane1/Base.agda", "max_line_length": 99, "max_stars_count": null, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/HITs/EilenbergMacLane1/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 679, "size": 1745 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Paths open import lib.types.Pi open import lib.types.Unit open import lib.types.Nat open import lib.types.TLevel open import lib.types.Pointed open import lib.types.Sigma open import lib.NType2 open import lib.types.PathSeq open import nicolai.pseudotruncations.Preliminary-definitions open import nicolai.pseudotruncations.Liblemmas open import nicolai.pseudotruncations.SeqColim module nicolai.pseudotruncations.wconst-preparation where {- first, we show that a weakly constant sequence for which we have an a₀ : A₀ is contractible. We proceed step-wise. -} module wconst-init {i} {C : Sequence {i}} (wc : wconst-chain C) (a₀ : fst C O) where A = fst C f = snd C SC = SeqCo C -- first, we show that [ins] is weakly constant ins-wconst : (n : ℕ) → wconst (ins {C = C} n) ins-wconst n a₁ a₂ = ins n a₁ =⟨ glue n a₁ ⟩ ins (S n) (f n a₁) =⟨ ap (ins (S n)) (wc n a₁ a₂) ⟩ ins (S n) (f n a₂) =⟨ ! (glue n a₂) ⟩ ins n a₂ ∎ {- Now, we want to define what is overline(i) is the paper (here, we call it î-def); that is: any a : A n is, if moved to A ω , equal to a₀. It is easy to define this, but the tricky part is that afterwards, we need to be able to reason about it. The 'equational reasoning' combinators are not suitable at all for this. What we use are the 'reified equational reasoning combinators', which allow this sort of thing. These are in the HoTT library, implemented by Guillaume Brunerie [I have extended it a bit in order to make it useable in my situation]. For an introduction to the concept, see the file lib.types.PathSeq. -} î-def : (n : ℕ) → (a : A n) → (ins {C = C} n a) =-= (ins O a₀) î-def n a = ins n a =⟪ glue n a ⟫ ins (S n) (f n a) =⟪ ap (ins (S n)) (wc n _ _) ⟫ ins (S n) (lift-point C a₀ (S n)) =⟪ ! (lift-point-= C a₀ (S n)) ⟫ ins O a₀ ∎∎ {- It was easy to define î; it is more difficult to show that it satisfied the required coherence. This is the 'heptagon-proof'; we present it in nicolai.pseudotruncations.heptagon.agda. -}
{ "alphanum_fraction": 0.6328331862, "avg_line_length": 29.4285714286, "ext": "agda", "hexsha": "de4472341f28de02ae77b422bc06303c66e42658", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "nicolai/pseudotruncations/wconst-preparation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "nicolai/pseudotruncations/wconst-preparation.agda", "max_line_length": 84, "max_stars_count": 1, "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_path": "nicolai/pseudotruncations/wconst-preparation.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z", "num_tokens": 733, "size": 2266 }
module Excercises where open import Library open import Core/Category SmallType : Category (mk (ℓ-suc ℓ-zero) ℓ-zero) SmallType = record { Obj = Set ; _⇒_ = λ (X Y : Set) → (X → Y) ; id = λ (X : Set) → (λ x → x) ; _∘_ = λ {X Y Z : Set} (g : Y → Z) (f : X → Y) → (λ x → g (f x)) ; idl = ≡-refl ; idr = ≡-refl ; assoc = ≡-refl }
{ "alphanum_fraction": 0.4944134078, "avg_line_length": 22.375, "ext": "agda", "hexsha": "bb7ab72f3ea5a030e99f37a6d377853be542505d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "045f2ab8a40c1b87f578ef12c0d1e10d131b7da3", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "gunpinyo/agda-cat", "max_forks_repo_path": "Excercises.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "045f2ab8a40c1b87f578ef12c0d1e10d131b7da3", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "gunpinyo/agda-cat", "max_issues_repo_path": "Excercises.agda", "max_line_length": 69, "max_stars_count": null, "max_stars_repo_head_hexsha": "045f2ab8a40c1b87f578ef12c0d1e10d131b7da3", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "gunpinyo/agda-cat", "max_stars_repo_path": "Excercises.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 162, "size": 358 }
{-# OPTIONS --allow-unsolved-metas #-} module Issue203 where open import Common.Level -- Should work but give unsolved metas (type of b) data ↓ {a b} (A : Set a) : Set a where [_] : (x : A) → ↓ A mutual -- avoid freezing -- Shouldn't instantiate the level of Σ to a data Σ {a b} (A : Set a) (B : A → Set b) : Set _ where _,_ : (x : A) (y : B x) → Σ A B instantiateToMax : ∀ {a b}(A : Set a)(B : A → Set b) → Set (a ⊔ b) instantiateToMax = Σ
{ "alphanum_fraction": 0.5757575758, "avg_line_length": 23.1, "ext": "agda", "hexsha": "9319b7c79cc5a74482b344a2188719404b73f230", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue203.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue203.agda", "max_line_length": 68, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue203.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 170, "size": 462 }
-- Test unquoteTC and quoteTC primitives. module _ where open import Common.Prelude hiding (_>>=_) open import Common.Reflection open import Common.Equality open import Common.Product sum : List Nat → Nat sum [] = 0 sum (x ∷ xs) = x + sum xs pattern `Bool = def (quote Bool) [] pattern `true = con (quote true) [] pattern `false = con (quote false) [] infix 2 case_of_ case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B case x of f = f x macro ` : Term → Tactic ` v hole = bindTC (quoteTC v) λ e → unify hole e ~ : Term → Tactic ~ e hole = bindTC (unquoteTC e) λ v → unify hole v msum : Term → Tactic msum e hole = bindTC (unquoteTC e) λ xs → unify hole (lit (nat (sum xs))) test₁ : Term test₁ = ` (1 ∷ 2 ∷ 3 ∷ []) test₂ : ~ test₁ ≡ (1 ∷ 2 ∷ 3 ∷ []) test₂ = refl test₃ : msum (1 ∷ 2 ∷ 3 ∷ []) ≡ 6 test₃ = refl macro simp : Term → Tactic simp (def f (vArg x ∷ [])) hole = checkType (def f []) (pi (vArg `Bool) (abs "_" `Bool)) >>= λ _ → unquoteTC (def f (vArg `true ∷ [])) >>= λ (t : Bool) → unquoteTC (def f (vArg `false ∷ [])) >>= λ (f : Bool) → unify hole (case (t , f) of λ { (true , true) → `true ; (false , false) → `false ; (true , false) → x ; (false , true) → def (quote not) (vArg x ∷ []) }) simp v _ = typeError (strErr "Can't simplify" ∷ termErr v ∷ []) f₁ f₂ f₃ f₄ : Bool → Bool f₁ false = false f₁ true = false f₂ false = false f₂ true = true f₃ false = true f₃ true = false f₄ false = true f₄ true = true test-f₁ : ∀ b → simp (f₁ b) ≡ false test-f₁ b = refl test-f₂ : ∀ b → simp (f₂ b) ≡ b test-f₂ b = refl test-f₃ : ∀ b → simp (f₃ b) ≡ not b test-f₃ b = refl test-f₄ : ∀ b → simp (f₄ b) ≡ true test-f₄ b = refl
{ "alphanum_fraction": 0.565774156, "avg_line_length": 22.0256410256, "ext": "agda", "hexsha": "7b5147822f2cc613632747509961eec43b72496e", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/QuoteTC.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/QuoteTC.agda", "max_line_length": 75, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/QuoteTC.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 683, "size": 1718 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Monoid.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.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Record open import Cubical.Algebra.Semigroup open import Cubical.Reflection.StrictEquiv open Iso private variable ℓ : Level record IsMonoid {A : Type ℓ} (ε : A) (_·_ : A → A → A) : Type ℓ where constructor ismonoid field isSemigroup : IsSemigroup _·_ identity : (x : A) → (x · ε ≡ x) × (ε · x ≡ x) open IsSemigroup isSemigroup public lid : (x : A) → ε · x ≡ x lid x = identity x .snd rid : (x : A) → x · ε ≡ x rid x = identity x .fst record MonoidStr (A : Type ℓ) : Type (ℓ-suc ℓ) where constructor monoidstr field ε : A _·_ : A → A → A isMonoid : IsMonoid ε _·_ infixl 7 _·_ open IsMonoid isMonoid public -- semigrp : Semigroup -- semigrp = record { isSemigroup = isSemigroup } -- open Semigroup semigrp public Monoid : Type (ℓ-suc ℓ) Monoid = TypeWithStr _ MonoidStr monoid : (A : Type ℓ) (ε : A) (_·_ : A → A → A) (h : IsMonoid ε _·_) → Monoid monoid A ε _·_ h = A , monoidstr ε _·_ h -- Easier to use constructors makeIsMonoid : {M : Type ℓ} {ε : M} {_·_ : M → M → M} (is-setM : isSet M) (assoc : (x y z : M) → x · (y · z) ≡ (x · y) · z) (rid : (x : M) → x · ε ≡ x) (lid : (x : M) → ε · x ≡ x) → IsMonoid ε _·_ IsMonoid.isSemigroup (makeIsMonoid is-setM assoc rid lid) = issemigroup is-setM assoc IsMonoid.identity (makeIsMonoid is-setM assoc rid lid) = λ x → rid x , lid x makeMonoid : {M : Type ℓ} (ε : M) (_·_ : M → M → M) (is-setM : isSet M) (assoc : (x y z : M) → x · (y · z) ≡ (x · y) · z) (rid : (x : M) → x · ε ≡ x) (lid : (x : M) → ε · x ≡ x) → Monoid makeMonoid ε _·_ is-setM assoc rid lid = monoid _ ε _·_ (makeIsMonoid is-setM assoc rid lid) record MonoidEquiv (M N : Monoid {ℓ}) (e : ⟨ M ⟩ ≃ ⟨ N ⟩) : Type ℓ where constructor monoidiso private module M = MonoidStr (snd M) module N = MonoidStr (snd N) field presε : equivFun e M.ε ≡ N.ε isHom : (x y : ⟨ M ⟩) → equivFun e (x M.· y) ≡ equivFun e x N.· equivFun e y module MonoidΣTheory {ℓ} where RawMonoidStructure : Type ℓ → Type ℓ RawMonoidStructure X = X × (X → X → X) RawMonoidEquivStr = AutoEquivStr RawMonoidStructure rawMonoidUnivalentStr : UnivalentStr _ RawMonoidEquivStr rawMonoidUnivalentStr = autoUnivalentStr RawMonoidStructure MonoidAxioms : (M : Type ℓ) → RawMonoidStructure M → Type ℓ MonoidAxioms M (e , _·_) = IsSemigroup _·_ × ((x : M) → (x · e ≡ x) × (e · x ≡ x)) MonoidStructure : Type ℓ → Type ℓ MonoidStructure = AxiomsStructure RawMonoidStructure MonoidAxioms MonoidΣ : Type (ℓ-suc ℓ) MonoidΣ = TypeWithStr ℓ MonoidStructure isPropMonoidAxioms : (M : Type ℓ) (s : RawMonoidStructure M) → isProp (MonoidAxioms M s) isPropMonoidAxioms M (e , _·_) = isPropΣ (isPropIsSemigroup _·_) λ α → isPropΠ λ _ → isProp× (IsSemigroup.is-set α _ _) (IsSemigroup.is-set α _ _) MonoidEquivStr : StrEquiv MonoidStructure ℓ MonoidEquivStr = AxiomsEquivStr RawMonoidEquivStr MonoidAxioms MonoidAxiomsIsoIsMonoid : {M : Type ℓ} (s : RawMonoidStructure M) → Iso (MonoidAxioms M s) (IsMonoid (s .fst) (s .snd)) fun (MonoidAxiomsIsoIsMonoid s) (x , y) = ismonoid x y inv (MonoidAxiomsIsoIsMonoid s) a = (IsMonoid.isSemigroup a) , IsMonoid.identity a rightInv (MonoidAxiomsIsoIsMonoid s) _ = refl leftInv (MonoidAxiomsIsoIsMonoid s) _ = refl MonoidAxioms≡IsMonoid : {M : Type ℓ} (s : RawMonoidStructure M) → MonoidAxioms M s ≡ IsMonoid (s .fst) (s .snd) MonoidAxioms≡IsMonoid s = ua (strictIsoToEquiv (MonoidAxiomsIsoIsMonoid s)) open MonoidStr Monoid→MonoidΣ : Monoid → MonoidΣ Monoid→MonoidΣ (A , M) = A , (ε M , _·_ M) , MonoidAxiomsIsoIsMonoid (ε M , _·_ M) .inv (isMonoid M) MonoidΣ→Monoid : MonoidΣ → Monoid MonoidΣ→Monoid (M , (ε , _·_) , isMonoidΣ) = monoid M ε _·_ (MonoidAxiomsIsoIsMonoid (ε , _·_) .fun isMonoidΣ) MonoidIsoMonoidΣ : Iso Monoid MonoidΣ MonoidIsoMonoidΣ = iso Monoid→MonoidΣ MonoidΣ→Monoid (λ _ → refl) (λ _ → refl) monoidUnivalentStr : UnivalentStr MonoidStructure MonoidEquivStr monoidUnivalentStr = axiomsUnivalentStr _ isPropMonoidAxioms rawMonoidUnivalentStr MonoidΣPath : (M N : MonoidΣ) → (M ≃[ MonoidEquivStr ] N) ≃ (M ≡ N) MonoidΣPath = SIP monoidUnivalentStr MonoidEquivΣ : (M N : Monoid) → Type ℓ MonoidEquivΣ M N = Monoid→MonoidΣ M ≃[ MonoidEquivStr ] Monoid→MonoidΣ N MonoidIsoΣPath : {M N : Monoid} → Iso (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] (MonoidEquiv M N e)) (MonoidEquivΣ M N) fun MonoidIsoΣPath (e , monoidiso h1 h2) = (e , h1 , h2) inv MonoidIsoΣPath (e , h1 , h2) = (e , monoidiso h1 h2) rightInv MonoidIsoΣPath _ = refl leftInv MonoidIsoΣPath _ = refl MonoidPath : (M N : Monoid {ℓ}) → (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] (MonoidEquiv M N e)) ≃ (M ≡ N) MonoidPath M N = Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] MonoidEquiv M N e ≃⟨ isoToEquiv MonoidIsoΣPath ⟩ MonoidEquivΣ M N ≃⟨ MonoidΣPath _ _ ⟩ Monoid→MonoidΣ M ≡ Monoid→MonoidΣ N ≃⟨ isoToEquiv (invIso (congIso MonoidIsoMonoidΣ)) ⟩ M ≡ N ■ RawMonoidΣ : Type (ℓ-suc ℓ) RawMonoidΣ = TypeWithStr ℓ RawMonoidStructure Monoid→RawMonoidΣ : Monoid → RawMonoidΣ Monoid→RawMonoidΣ (A , M) = A , (ε M) , (_·_ M) InducedMonoid : (M : Monoid) (N : RawMonoidΣ) (e : M .fst ≃ N .fst) → RawMonoidEquivStr (Monoid→RawMonoidΣ M) N e → Monoid InducedMonoid M N e r = MonoidΣ→Monoid (inducedStructure rawMonoidUnivalentStr (Monoid→MonoidΣ M) N (e , r)) InducedMonoidPath : (M : Monoid {ℓ}) (N : RawMonoidΣ) (e : M .fst ≃ N .fst) (E : RawMonoidEquivStr (Monoid→RawMonoidΣ M) N e) → M ≡ InducedMonoid M N e E InducedMonoidPath M N e E = MonoidPath M (InducedMonoid M N e E) .fst (e , monoidiso (E .fst) (E .snd)) -- We now extract the important results from the above module isPropIsMonoid : {M : Type ℓ} (ε : M) (_·_ : M → M → M) → isProp (IsMonoid ε _·_) isPropIsMonoid ε _·_ = subst isProp (MonoidΣTheory.MonoidAxioms≡IsMonoid (ε , _·_)) (MonoidΣTheory.isPropMonoidAxioms _ (ε , _·_)) MonoidPath : (M N : Monoid {ℓ}) → (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] MonoidEquiv M N e) ≃ (M ≡ N) MonoidPath {ℓ = ℓ} = SIP (autoUnivalentRecord (autoRecordSpec (MonoidStr {ℓ}) MonoidEquiv (fields: data[ ε ∣ presε ] data[ _·_ ∣ isHom ] prop[ isMonoid ∣ (λ _ → isPropIsMonoid _ _) ])) _ _) where open MonoidStr open MonoidEquiv InducedMonoid : (M : Monoid {ℓ}) (N : MonoidΣTheory.RawMonoidΣ) (e : M .fst ≃ N .fst) → MonoidΣTheory.RawMonoidEquivStr (MonoidΣTheory.Monoid→RawMonoidΣ M) N e → Monoid InducedMonoid = MonoidΣTheory.InducedMonoid InducedMonoidPath : (M : Monoid {ℓ}) (N : MonoidΣTheory.RawMonoidΣ) (e : M .fst ≃ N .fst) (E : MonoidΣTheory.RawMonoidEquivStr (MonoidΣTheory.Monoid→RawMonoidΣ M) N e) → M ≡ InducedMonoid M N e E InducedMonoidPath = MonoidΣTheory.InducedMonoidPath module MonoidTheory {ℓ} (M : Monoid {ℓ}) where open MonoidStr (snd M) -- Added for its use in groups -- If there exists a inverse of an element it is unique inv-lemma : (x y z : ⟨ M ⟩) → y · x ≡ ε → x · z ≡ ε → y ≡ z inv-lemma x y z left-inverse right-inverse = y ≡⟨ sym (rid y) ⟩ y · ε ≡⟨ cong (λ - → y · -) (sym right-inverse) ⟩ y · (x · z) ≡⟨ assoc y x z ⟩ (y · x) · z ≡⟨ cong (λ - → - · z) left-inverse ⟩ ε · z ≡⟨ lid z ⟩ z ∎
{ "alphanum_fraction": 0.6223520818, "avg_line_length": 34.512605042, "ext": "agda", "hexsha": "93f4da4fa43f51450c9a743bf02777e2d46dcf70", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Edlyr/cubical", "max_forks_repo_path": "Cubical/Algebra/Monoid/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Edlyr/cubical", "max_issues_repo_path": "Cubical/Algebra/Monoid/Base.agda", "max_line_length": 103, "max_stars_count": null, "max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Edlyr/cubical", "max_stars_repo_path": "Cubical/Algebra/Monoid/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3191, "size": 8214 }
{-# OPTIONS --without-K #-} module PathStructure.Nat where open import Equivalence open import PathOperations open import Types F : ℕ → ℕ → Set F = ind (λ _ → ℕ → Set) (λ _ r → ind (λ _ → Set) (λ n-1 _ → r n-1) ⊥) ( ind (λ _ → Set) (λ _ _ → ⊥) ⊤) F-lemma : ∀ n → F n n F-lemma = ind (λ n → F n n) (λ _ f → f) _ -- Explicit arguments to prevent code littered with curly brackets. split-path : ∀ x y → x ≡ y → F x y split-path x _ p = tr (F x) p (F-lemma x) merge-path : ∀ x y → F x y → x ≡ y merge-path _ _ f = ind (λ x → ∀ y → F x y → x ≡ y) (λ x r → ind (λ y → F (suc x) y → suc x ≡ y) (λ _ _ f → ap suc (r _ f)) 0-elim) (ind (λ y → F zero y → zero ≡ y) (λ _ _ → 0-elim) (λ _ → refl)) _ _ f -- Lemmas. ap-refl : ∀ {n} (p : n ≡ n) → p ≡ refl → ap suc p ≡ refl ap-refl _ = J (λ p q _ → J (λ x y _ → suc x ≡ suc y) (λ _ → refl) _ _ p ≡ ap suc q) (λ _ → refl) _ refl tr-ap : ∀ m n (f : F m n) → tr (F (suc m)) (ap suc (merge-path m n f)) (F-lemma (suc m)) ≡ tr (F (suc m) ∘ suc) (merge-path m n f) (F-lemma (suc m)) tr-ap m n f = J (λ x y p → tr (F (suc x)) (ap suc p) (F-lemma (suc x)) ≡ tr (F (suc x) ∘ suc) p (F-lemma (suc x))) (λ _ → refl) _ _ (merge-path m n f) split-merge-eq : ∀ {x y} → (x ≡ y) ≃ F x y split-merge-eq {x = x} {y = y} = split-path _ _ , (merge-path _ _ , λ f → ind (λ x → ∀ y (f : F x y) → split-path x y (merge-path x y f) ≡ f) (λ x r → ind (λ y → (f : F (suc x) y) → split-path (suc x) y (merge-path (suc x) y f) ≡ f) (λ y _ f → tr-ap x y f · r y f) (λ b → 0-elim b)) (ind (λ y → (f : F zero y) → split-path zero y (merge-path zero y f) ≡ f) (λ _ _ b → 0-elim b) (λ _ → refl)) x y f) , (merge-path _ _ , J (λ _ _ p → merge-path _ _ (split-path _ _ p) ≡ p) (ind (λ x → merge-path x x (split-path x x refl) ≡ refl) (λ _ → ap-refl _) refl) _ _)
{ "alphanum_fraction": 0.4574257426, "avg_line_length": 28.0555555556, "ext": "agda", "hexsha": "e430b4a65470cbf89211fb1203a657f5e4e0dbe3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "vituscze/HoTT-lectures", "max_forks_repo_path": "src/PathStructure/Nat.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "vituscze/HoTT-lectures", "max_issues_repo_path": "src/PathStructure/Nat.agda", "max_line_length": 71, "max_stars_count": null, "max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "vituscze/HoTT-lectures", "max_stars_repo_path": "src/PathStructure/Nat.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 849, "size": 2020 }
module PiFrac.Everything where open import PiFrac.Syntax -- Syntax of PiFrac open import PiFrac.Opsem -- Abstract machine semantics of PiFrac open import PiFrac.AuxLemmas -- Some auxiliary lemmas about opsem for forward/backward deterministic proof open import PiFrac.NoRepeat -- Forward/backward deterministic lemmas and Non-repeating lemma open import PiFrac.Invariants -- Some invariants about abstract machine semantics open import PiFrac.Eval -- Evaluator for PiFrac open import PiFrac.Interp -- Big-step intepreter for PiFrac using Maybe monad open import PiFrac.Properties -- Properties of PiFrac open import PiFrac.Examples -- Examples open import PiFrac.Category -- PiFrac pointed category
{ "alphanum_fraction": 0.7931034483, "avg_line_length": 60.4166666667, "ext": "agda", "hexsha": "fa2404f99d6a9c72db277e57796f85cf2de53a3a", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "PiFrac/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "PiFrac/Everything.agda", "max_line_length": 107, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "PiFrac/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 181, "size": 725 }
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Delta-observational equivalence - support for equational reasoning ------------------------------------------------------------------------ module Base.Change.Equivalence.EqReasoning where open import Relation.Binary.PropositionalEquality open import Base.Change.Algebra open import Level open import Data.Unit open import Function open import Base.Change.Equivalence.Base public module _ {a} {A : Set a} {{ca : ChangeAlgebra A}} {x : A} where ------------------------------------------------------------------------ -- Convenient syntax for equational reasoning import Relation.Binary.EqReasoning as EqR module ≙-Reasoning where open EqR (≙-setoid {x = x}) public renaming (_≈⟨_⟩_ to _≙⟨_⟩_)
{ "alphanum_fraction": 0.5505481121, "avg_line_length": 32.84, "ext": "agda", "hexsha": "5e80ce71828f65fc75bd64f6dc5fd265e41881fd", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Base/Change/Equivalence/EqReasoning.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Base/Change/Equivalence/EqReasoning.agda", "max_line_length": 74, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Base/Change/Equivalence/EqReasoning.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 174, "size": 821 }
{-# OPTIONS --no-qualified-instances #-} postulate A : Set f : {{A}} → A module M where postulate instance a : A test : A test = f
{ "alphanum_fraction": 0.6086956522, "avg_line_length": 12.5454545455, "ext": "agda", "hexsha": "c1d6fb337dd2a05237f6a0ab19dcdd3caaadc0b0", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Fail/NoQualifiedInstances.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/NoQualifiedInstances.agda", "max_line_length": 40, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/NoQualifiedInstances.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 44, "size": 138 }
-- P: <E[fork e]> --> <E[()]> | <e> module Properties.StepFork where open import Data.List open import Data.List.All open import Data.Product open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Typing open import Syntax open import Global open import Channel open import Values open import Session open import Schedule open import ProcessSyntax open import ProcessRun open import Properties.Base mkfork : ∀ {Φ Φ₁ Φ₂} → Split Φ Φ₁ Φ₂ → Expr Φ₁ TUnit → Expr (TUnit ∷ Φ₂) TUnit → Expr Φ TUnit mkfork sp e E = letbind sp (fork e) E mklhs : ∀ {Φ Φ₁ Φ₂} → Split Φ Φ₁ Φ₂ → Expr Φ₁ TUnit → Expr (TUnit ∷ Φ₂) TUnit → Proc Φ mklhs sp e E = exp (mkfork sp e E) mkrhs : ∀ {Φ Φ₁ Φ₂} → Split Φ Φ₁ Φ₂ → Expr Φ₁ TUnit → Expr (TUnit ∷ Φ₂) TUnit → Proc Φ mkrhs sp e E = par sp (exp e) (exp (letbind (split-all-right _) (unit []) E)) -- weaken2-command : ∀ {G} G' G'' → Command (G' ++ G) → Command (G' ++ inactive-clone G'' ++ G) -- obviously true, but requires a nasty inductive proof postulate weaken2-ident : ∀ {G} → (cmd : Command G) → weaken2-command [] [] cmd ≡ cmd reduction : (e : Expr [] TUnit) → (E : Expr (TUnit ∷ []) TUnit) → let lhs = (runProc [] (mklhs [] e E) (vnil []-inactive)) in let rhs = (runProc [] (mkrhs [] e E) (vnil []-inactive)) in let rhs' = one-step rhs in one-step lhs ≡ (Forked , proj₁ rhs , proj₂ rhs) reduction e E with ssplit-refl-left-inactive [] ... | G' , ina-G' , ss-GG' rewrite weaken2-ident (run [] ss-[] e (vnil []-inactive) (halt []-inactive UUnit)) = refl
{ "alphanum_fraction": 0.643494898, "avg_line_length": 28, "ext": "agda", "hexsha": "acf7118008b65c48df90de68862d362b1921806d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "peterthiemann/definitional-session", "max_forks_repo_path": "src/Properties/StepFork.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "peterthiemann/definitional-session", "max_issues_repo_path": "src/Properties/StepFork.agda", "max_line_length": 95, "max_stars_count": 9, "max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "peterthiemann/definitional-session", "max_stars_repo_path": "src/Properties/StepFork.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z", "num_tokens": 564, "size": 1568 }
-- Andreas, 2019-07-07, issue #3892 postulate Foo : Set data Foo where -- WAS: internal error -- EXPECTED: -- Multiple definitions of Foo. Previous definition at ...
{ "alphanum_fraction": 0.7041420118, "avg_line_length": 16.9, "ext": "agda", "hexsha": "10d5d48387efc521554f5d14db1a7fb0539e302d", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue3892.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue3892.agda", "max_line_length": 58, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue3892.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 46, "size": 169 }
module Structure.Setoid {ℓₑ ℓₒ} where import Lvl open import Functional.Dependent open import Lang.Instance open import Logic.Propositional open import Logic.Predicate open import Structure.Relator.Equivalence open import Syntax.Function import Type module _ where open Type -- An instance of `Equiv(T)` is that the type `T` has an equivalence relation which may be treated as a default one. -- Helps finding an instance of an equivalence relation for a type. record Equiv (T : Type{ℓₒ}) : Type{Lvl.𝐒(ℓₑ) Lvl.⊔ ℓₒ} where constructor intro infixl 15 _≡_ _≢_ field _≡_ : T → T → Type{ℓₑ} field instance ⦃ equivalence ⦄ : Equivalence(_≡_) _≢_ : T → T → Type{ℓₑ} a ≢ b = ¬(a ≡ b) open Equivalence(equivalence) public open Equiv ⦃ ... ⦄ using (_≡_ ; _≢_) renaming (equivalence to Equiv-equivalence) public {-# INLINE _≡_ #-} -- TODO: Not sure if this does anything {-# DISPLAY Equiv._≡_ a b = a ≡ b #-} -- TODO: Not sure about this either module _ where -- A set and an equivalence relation on it Setoid = ∃(Equiv) module Setoid(([∃]-intro T ⦃ equiv-T ⦄) : Setoid) where Type : Type.Type Type = T open Equiv(equiv-T) public
{ "alphanum_fraction": 0.668879668, "avg_line_length": 28.023255814, "ext": "agda", "hexsha": "9afc69a77fb744b70045de0c6a2fdc76c3d62265", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Structure/Setoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Structure/Setoid.agda", "max_line_length": 118, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Structure/Setoid.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 405, "size": 1205 }
{-# OPTIONS --without-K --exact-split #-} module subrings where import rings open rings public -------------------------------------------------------------------------------- {- Subrings -} subset-Ring : (l : Level) {l1 : Level} → Ring l1 → UU ((lsuc l) ⊔ l1) subset-Ring l R = type-Ring R → UU-Prop l is-additive-subset-Ring : {l l1 : Level} (R : Ring l1) (S : subset-Ring l R) → UU _ is-additive-subset-Ring R S = (x y : type-Ring R) → type-Prop (S x) → type-Prop (S y) → type-Prop (S (add-Ring R x y))
{ "alphanum_fraction": 0.5134615385, "avg_line_length": 24.7619047619, "ext": "agda", "hexsha": "d0daef1cf43cec50a44d4916e8163af0f444bb1a", "lang": "Agda", "max_forks_count": 30, "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_forks_repo_path": "Agda/subrings.agda", "max_issues_count": 8, "max_issues_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_issues_repo_path": "Agda/subrings.agda", "max_line_length": 80, "max_stars_count": 333, "max_stars_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_stars_repo_path": "Agda/subrings.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "num_tokens": 168, "size": 520 }
open import Relation.Binary.Core module BSTree.Properties {A : Set} (_≤_ : A → A → Set) (trans≤ : Transitive _≤_) where open import BTree {A} open import BSTree _≤_ open import List.Order.Simple _≤_ open import List.Order.Simple.Properties _≤_ trans≤ open import List.Sorted _≤_ lemma-*⊴-*≤ : {x : A}{t : BTree} → BSTree t → t *⊴ x → flatten t *≤ x lemma-*⊴-*≤ slf lelf = lenx lemma-*⊴-*≤ (snd sl sr l≤y y≤r) (lend y≤x r≤x) = lemma-++-*≤ y≤x (lemma-*⊴-*≤ sl l≤y) (lemma-*⊴-*≤ sr r≤x) lemma-⊴*-≤* : {x : A}{t : BTree} → BSTree t → x ⊴* t → x ≤* flatten t lemma-⊴*-≤* slf gelf = genx lemma-⊴*-≤* (snd sl sr l≤y y≤r) (gend x≤y x≤l) = lemma-≤*-++ x≤y (lemma-⊴*-≤* sl x≤l) (lemma-⊴*-≤* sr y≤r) lemma-bst-sorted : {t : BTree} → BSTree t → Sorted (flatten t) lemma-bst-sorted slf = nils lemma-bst-sorted (snd sl sr l≤x x≤r) = lemma-sorted++ (lemma-*⊴-*≤ sl l≤x) (lemma-⊴*-≤* sr x≤r) (lemma-bst-sorted sl) (lemma-bst-sorted sr)
{ "alphanum_fraction": 0.570239334, "avg_line_length": 35.5925925926, "ext": "agda", "hexsha": "fa088b3e6de2b6b318e41c88e7d09a760f1b1577", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/BSTree/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_path": "agda/BSTree/Properties.agda", "max_line_length": 139, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/BSTree/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 452, "size": 961 }
{-# OPTIONS --universe-polymorphism #-} module Issue203 where open import Imports.Level -- shouldn't work data Bad {a b} (A : Set a) : Set b where [_] : (x : A) → Bad A
{ "alphanum_fraction": 0.632183908, "avg_line_length": 17.4, "ext": "agda", "hexsha": "20a716b5169235a1e32906050c1546f021c710a7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/fail/Issue203.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/fail/Issue203.agda", "max_line_length": 40, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/Issue203.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 54, "size": 174 }
module Issue395 where foo : Set → Set₁ foo foo with Set ... | _ = Set
{ "alphanum_fraction": 0.6388888889, "avg_line_length": 10.2857142857, "ext": "agda", "hexsha": "0c964c4b99411319863eaedd45416ec249f4b90e", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue395.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue395.agda", "max_line_length": 21, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue395.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 24, "size": 72 }
{-# OPTIONS --without-K #-} module sum-properties-setoid where open import Type import Level as L open import Algebra import Algebra.FunctionProperties as FP open import Data.Zero using (𝟘) open import Data.Bool.NP open Data.Bool.NP.Indexed open import Data.Fin using (Fin) open import Data.Nat.NP open import Data.Nat.Properties open import Data.Product renaming (map to pmap) open import Data.Sum open import Data.One using (𝟙) open import Function.NP import Function.Inverse as Inv open Inv using (_↔_) open import Function.Related open import Function.Related.TypeIsomorphisms.NP import Function.Equality as FE open FE using (_⟨$⟩_) import Function.Injection as FInj open import sum-setoid open import Relation.Binary open import Relation.Binary.Sum.NP open import Relation.Binary.Product.Pointwise import Relation.Binary.PropositionalEquality.NP as ≡ open ≡ using (_≡_ ; _≗_ ; _≗₂_) module _ {A : ★} (μA : SumProp A) (f g : A → ℕ) where open ≡.≡-Reasoning sum-⊓-∸ : sum μA f ≡ sum μA (f ⊓° g) + sum μA (f ∸° g) sum-⊓-∸ = sum μA f ≡⟨ sum-ext μA (f ⟨ a≡a⊓b+a∸b ⟩° g) ⟩ sum μA ((f ⊓° g) +° (f ∸° g)) ≡⟨ sum-hom μA (f ⊓° g) (f ∸° g) ⟩ sum μA (f ⊓° g) + sum μA (f ∸° g) ∎ sum-⊔-⊓ : sum μA f + sum μA g ≡ sum μA (f ⊔° g) + sum μA (f ⊓° g) sum-⊔-⊓ = sum μA f + sum μA g ≡⟨ ≡.sym (sum-hom μA f g) ⟩ sum μA (f +° g) ≡⟨ sum-ext μA (f ⟨ a+b≡a⊔b+a⊓b ⟩° g) ⟩ sum μA (f ⊔° g +° f ⊓° g) ≡⟨ sum-hom μA (f ⊔° g) (f ⊓° g) ⟩ sum μA (f ⊔° g) + sum μA (f ⊓° g) ∎ sum-⊔ : sum μA (f ⊔° g) ≤ sum μA f + sum μA g sum-⊔ = ℕ≤.trans (sum-mono μA (f ⟨ ⊔≤+ ⟩° g)) (ℕ≤.reflexive (sum-hom μA f g)) module _M2 {A : ★} (μA : SumProp A) (f g : A → Bool) where count-∧-not : count μA f ≡ count μA (f ∧° g) + count μA (f ∧° not° g) count-∧-not rewrite sum-⊓-∸ μA (toℕ ∘ f) (toℕ ∘ g) | sum-ext μA (f ⟨ toℕ-⊓ ⟩° g) | sum-ext μA (f ⟨ toℕ-∸ ⟩° g) = ≡.refl count-∨-∧ : count μA f + count μA g ≡ count μA (f ∨° g) + count μA (f ∧° g) count-∨-∧ rewrite sum-⊔-⊓ μA (toℕ ∘ f) (toℕ ∘ g) | sum-ext μA (f ⟨ toℕ-⊔ ⟩° g) | sum-ext μA (f ⟨ toℕ-⊓ ⟩° g) = ≡.refl count-∨≤+ : count μA (f ∨° g) ≤ count μA f + count μA g count-∨≤+ = ℕ≤.trans (ℕ≤.reflexive (sum-ext μA (≡.sym ∘ (f ⟨ toℕ-⊔ ⟩° g)))) (sum-⊔ μA (toℕ ∘ f) (toℕ ∘ g)) sum-ext₂ : ∀ {A B}{f g : A → B → ℕ}(μA : SumProp A)(μB : SumProp B) → f ≗₂ g → sum μA (sum μB ∘ f) ≡ sum μA (sum μB ∘ g) sum-ext₂ μA μB f≗g = sum-ext μA (sum-ext μB ∘ f≗g) Injective : ∀ {a b}{A : Set a}{B : Set b}(f : A → B) → Set (a L.⊔ b) Injective f = ∀ {x y} → f x ≡ f y → x ≡ y Injectivoid : ∀ {A B : SEToid} → (Setoid.Carrier A → Setoid.Carrier B) → Set Injectivoid {A}{B} f = ∀ {x y} → Setoid._≈_ B (f x) (f y) → Setoid._≈_ A x y StableUnderInjection : ∀ {A} → SumPropoid A → Set StableUnderInjection {A} μ = ∀ p → SumStableUnder μ (FInj.Injection.to p) CountStableUnderInjection : ∀ {A} → SumPropoid A → Set CountStableUnderInjection μ = ∀ p → CountStableUnder μ (FInj.Injection.to p) {- #-StableUnderInjection : ∀ {A}{μ : SumPropoid A} → StableUnderInjection μ → ∀ f p → Injective p → count μ f ≡ count μ (f ∘ p) #-StableUnderInjection sui f p p-inj = {!sui p p-inj (toℕ ∘ f)!} -} sum$ : ∀ {As} → SumPropoid As → (As FE.⟶ ≡.setoid ℕ) → ℕ sum$ μA f = sum μA (_⟨$⟩_ f) infix 4 _≈_ -- _≈'_ record _≈_ {As Bs : SEToid}(μA : SumPropoid As)(μB : SumPropoid Bs): Set where constructor mk field iso : Inv.Inverse As Bs private A = Setoid.Carrier As B = Setoid.Carrier Bs from : Bs FE.⟶ As from = Inv.Inverse.from iso from$ : B → A from$ = _⟨$⟩_ from to : As FE.⟶ Bs to = Inv.Inverse.to iso to$ : A → B to$ = _⟨$⟩_ to from-inj : FInj.Injection Bs As -- Injectivoid {Bs} {As} from$ from-inj = Inv.Inverse.injection (Inv.sym iso) to-inj : FInj.Injection As Bs -- Injectivoid {As} {Bs} to$ to-inj = Inv.Inverse.injection iso field sums-ok : ∀ f → sum$ μA f ≡ sum$ μB (f FE.∘ from) sums-ok' : ∀ f → sum$ μB f ≡ sum$ μA (f FE.∘ to) sums-ok' f = sum$ μB f ≡⟨ search-extoid μB _+_ {f = f} {g = f FE.∘ to FE.∘ from} (λ {x}{y} x≈y → FE.cong f (SB.trans x≈y (SB.sym (Inv.Inverse.right-inverse-of iso y)))) ⟩ sum$ μB (f FE.∘ to FE.∘ from) ≡⟨ ≡.sym (sums-ok (f FE.∘ to)) ⟩ sum$ μA (f FE.∘ to) ∎ where open ≡.≡-Reasoning module SB = Setoid Bs module SA = Setoid As StableUnder≈ : StableUnderInjection μA → StableUnderInjection μB StableUnder≈ μA-SUI p f = sum$ μB f ≡⟨ sums-ok' f ⟩ sum$ μA (f FE.∘ to) ≡⟨ μA-SUI (from-inj FInj.∘ p FInj.∘ to-inj) (f FE.∘ to) ⟩ sum$ μA (f FE.∘ to FE.∘ from FE.∘ FInj.Injection.to p FE.∘ to) ≡⟨ ≡.sym (sums-ok' (f FE.∘ to FE.∘ from FE.∘ FInj.Injection.to p)) ⟩ sum$ μB (f FE.∘ to FE.∘ from FE.∘ FInj.Injection.to p) ≡⟨ search-extoid μB _+_ {f = f FE.∘ to FE.∘ from FE.∘ FInj.Injection.to p} {g = f FE.∘ FInj.Injection.to p} (FE.cong f ∘ Setoid.trans Bs (Inv.Inverse.right-inverse-of iso _) ∘ FE.cong (FInj.Injection.to p)) ⟩ sum$ μB (f FE.∘ FInj.Injection.to p) ∎ where open ≡.≡-Reasoning _≈'_ : ∀ {A B} (μA : SumProp A)(μB : SumProp B) → Set _≈'_ = _≈_ ≈-refl : ∀ {A} (μA : SumPropoid A) → μA ≈ μA ≈-refl μA = mk Inv.id (λ f → ≡.refl) ≈-id : ∀ {A} {μA : SumPropoid A} → μA ≈ μA ≈-id = ≈-refl _ ≈-sym : ∀ {A B}{μA : SumPropoid A}{μB : SumPropoid B} → μA ≈ μB → μB ≈ μA ≈-sym A≈B = mk (Inv.sym iso) sums-ok' where open _≈_ A≈B ≈-trans : ∀ {A B C}{μA : SumPropoid A}{μB : SumPropoid B}{μC : SumPropoid C} → μA ≈ μB → μB ≈ μC → μA ≈ μC ≈-trans A≈B B≈C = mk (iso B≈C Inv.∘ iso A≈B) (λ f → ≡.trans (sums-ok A≈B f) (sums-ok B≈C (f FE.∘ from A≈B))) where open _≈_ infix 2 _≈∎ infixr 2 _≈⟨_⟩_ _≈∎ : ∀ {A} (μA : SumPropoid A) → μA ≈ μA _≈∎ = ≈-refl _≈⟨_⟩_ : ∀ {A B C} (μA : SumPropoid A){μB : SumPropoid B}{μC : SumPropoid C} → μA ≈ μB → μB ≈ μC → μA ≈ μC _ ≈⟨ A≈B ⟩ B≈C = ≈-trans A≈B B≈C lift-⊎ : ∀ {A B : Set} → Inv.Inverse (≡.setoid (A ⊎ B)) ((≡.setoid A) ⊎-setoid (≡.setoid B)) lift-⊎ {A} {B} = record { to = to; from = from; inverse-of = inverse-of } where to : _ to = record { _⟨$⟩_ = id; cong = cong } where cong : ∀ {i j} → i ≡ j → _ cong ≡.refl = Setoid.refl (≡.setoid (A) ⊎-setoid (≡.setoid B)) from : _ from = record { _⟨$⟩_ = id; cong = cong } where cong : ∀ {i j} → ⊎ʳ 𝟘 _≡_ _≡_ i j → i ≡ j cong (₁∼₂ ()) cong (₁∼₁ x∼₁y) = ≡.cong inj₁ x∼₁y cong (₂∼₂ x∼₂y) = ≡.cong inj₂ x∼₂y inverse-of : _ inverse-of = record { left-inverse-of = left-inverse-of; right-inverse-of = right-inverse-of } where left-inverse-of : (_ : _) → _ left-inverse-of x = Setoid.refl (≡.setoid (A ⊎ B)) right-inverse-of : (_ : _) → _ right-inverse-of x = Setoid.refl ((≡.setoid A) ⊎-setoid (≡.setoid B)) Fin0≈𝟙 : μFinSuc zero ≈ μ𝟙 Fin0≈𝟙 = mk iso sums-ok where open import Relation.Binary.Sum iso : _ iso = (A⊎𝟘↔A Inv.∘ Inv.id ⊎-cong Fin0↔𝟘) Inv.∘ Fin∘suc↔𝟙⊎Fin sums-ok : (_ : _) → _ sums-ok f = ≡.refl 𝟙+Fin : ∀ {n} → μ𝟙 +μ μFinSuc n ≈ μFinSuc (suc n) 𝟙+Fin {n} = mk iso sums-ok where iso : _ iso = Inv.sym (Inv._∘_ (lift-⊎ {𝟙} {Fin (suc n)}) Fin∘suc↔𝟙⊎Fin) sums-ok : (_ : _) → _ sums-ok f = ≡.refl 𝟙×A≈A : ∀ {A}{μA : SumProp A} → μ𝟙 ×μ μA ≈ μA 𝟙×A≈A {A} = mk iso sums-ok where iso : _ iso = ×-ICMon.identityˡ _ sums-ok : (_ : _) → _ sums-ok f = ≡.refl μFinPres : ∀ {m n} → m ≡ n → μFinSuc m ≈ μFinSuc n μFinPres eq rewrite eq = ≈-refl _ _+μ-cong_ : ∀ {A B C D}{μA : SumPropoid A}{μB : SumPropoid B}{μC : SumPropoid C}{μD : SumPropoid D} → μA ≈ μC → μB ≈ μD → μA +μ μB ≈ μC +μ μD A≈C +μ-cong B≈D = mk iso sums-ok where iso : _ iso = (_≈_.iso A≈C) ⊎-inverse (_≈_.iso B≈D) -- (_≈_.iso A≈C) ⊎-cong (_≈_.iso B≈D) sums-ok : (_ : _) → _ sums-ok f = ≡.cong₂ _+_ (_≈_.sums-ok A≈C (f FE.∘ inj₁-setoid)) -- (λ x≈y → f-resp (₁∼₁ x≈y))) (_≈_.sums-ok B≈D (f FE.∘ inj₂-setoid)) -- (λ x≈y → f-resp (₂∼₂ x≈y))) +μ-assoc : ∀ {A B C}(μA : SumPropoid A)(μB : SumPropoid B)(μC : SumPropoid C) → (μA +μ μB) +μ μC ≈ μA +μ (μB +μ μC) +μ-assoc μA μB μC = mk iso sums-ok where iso : _ iso = ⊎-ICMon.assoc _ _ _ sums-ok : (_ : _) → _ sums-ok f = ℕ°.+-assoc (sum μA (_⟨$⟩_ f ∘ inj₁ ∘ inj₁)) (sum μB (_⟨$⟩_ f ∘ inj₁ ∘ inj₂)) (sum μC (_⟨$⟩_ f ∘ inj₂)) +μ-comm : ∀ {A B}(μA : SumPropoid A)(μB : SumPropoid B) → μA +μ μB ≈ μB +μ μA +μ-comm μA μB = mk iso sums-ok where iso : _ iso = ⊎-ICMon.comm _ _ sums-ok : (_ : _) → _ sums-ok f = ℕ°.+-comm (sum$ μA (f FE.∘ inj₁-setoid)) (sum$ μB (f FE.∘ inj₂-setoid)) _×μ-cong_ : ∀ {A B C D}{μA : SumPropoid A}{μB : SumPropoid B}{μC : SumPropoid C}{μD : SumPropoid D} → μA ≈ μC → μB ≈ μD → μA ×μ μB ≈ μC ×μ μD _×μ-cong_ {A}{B}{C}{D}{μA}{μB}{μC}{μD} A≈C B≈D = mk iso sums-ok where open import Relation.Binary.Product.Pointwise iso : _ iso = _≈_.iso A≈C ×-inverse _≈_.iso B≈D sums-ok : (_ : (A ×-setoid B) FE.⟶ ≡.setoid ℕ) → _ sums-ok f = sum$ (μA ×μ μB) f ≡⟨ sum-ext μA (λ xa → _≈_.sums-ok B≈D (record { _⟨$⟩_ = λ x → f ⟨$⟩ (xa , x) ; cong = λ x → FE.cong f (Setoid.refl A , x) })) ⟩ sum$ (μA ×μ μD) (f FE.∘ FE.id {A = A} ×-⟶ _≈_.from B≈D) ≡⟨ _≈_.sums-ok A≈C (record { _⟨$⟩_ = _; cong = λ x → search-ext μD _+_ (λ y → FE.cong f (x , Setoid.refl B)) }) ⟩ sum$ (μC ×μ μD) (f FE.∘ Inv.Inverse.from iso) ∎ where open ≡.≡-Reasoning ×μ-assoc : ∀ {A B C}(μA : SumPropoid A)(μB : SumPropoid B)(μC : SumPropoid C) → (μA ×μ μB) ×μ μC ≈ μA ×μ (μB ×μ μC) ×μ-assoc {A}{B}{C} μA μB μC = mk iso sums-ok where iso : _ iso = ×-ICMon.assoc A B C sums-ok : (_ : _) → _ sums-ok f = ≡.refl ×μ-comm : ∀ {A B}(μA : SumPropoid A)(μB : SumPropoid B) → μA ×μ μB ≈ μB ×μ μA ×μ-comm {A}{B} μA μB = mk iso sums-ok where iso : _ iso = ×-ICMon.comm A B sums-ok : (_ : _) → _ sums-ok f = sum-swap μA μB (curry (_⟨$⟩_ f)) ×+-distrib : ∀ {A B C}(μA : SumPropoid A)(μB : SumPropoid B)(μC : SumPropoid C) → (μA +μ μB) ×μ μC ≈ (μA ×μ μC) +μ (μB ×μ μC) ×+-distrib {A}{B}{C} μA μB μC = mk iso sums-ok where iso : _ iso = ×⊎°I.distribʳ C A B sums-ok : (_ : _) → _ sums-ok f = ≡.refl +-≈ : ∀ m n → (μFinSuc m) +μ (μFinSuc n) ≈ μFinSuc (m + suc n) +-≈ zero n = μFinSuc zero +μ μFinSuc n ≈⟨ Fin0≈𝟙 +μ-cong ≈-refl (μFinSuc n) ⟩ μ𝟙 +μ μFinSuc n ≈⟨ 𝟙+Fin ⟩ μFinSuc (suc n) ≈∎ +-≈ (suc m) n = μFinSuc (suc m) +μ μFinSuc n ≈⟨ ≈-sym 𝟙+Fin +μ-cong ≈-refl (μFinSuc n) ⟩ (μ𝟙 +μ μFinSuc m) +μ μFinSuc n ≈⟨ +μ-assoc μ𝟙 (μFinSuc m) (μFinSuc n) ⟩ μ𝟙 +μ (μFinSuc m +μ μFinSuc n) ≈⟨ ≈-refl μ𝟙 +μ-cong +-≈ m n ⟩ μ𝟙 +μ μFinSuc (m + suc n) ≈⟨ 𝟙+Fin ⟩ μFinSuc (suc m + suc n) ≈∎ ×-≈ : ∀ m n → μFinSuc m ×μ μFinSuc n ≈ μFinSuc (n + m * suc n) ×-≈ zero n = μFinSuc 0 ×μ μFinSuc n ≈⟨ Fin0≈𝟙 ×μ-cong (≈-refl (μFinSuc n)) ⟩ μ𝟙 ×μ μFinSuc n ≈⟨ 𝟙×A≈A ⟩ μFinSuc n ≈⟨ μFinPres (ℕ°.+-comm 0 n) ⟩ μFinSuc (n + 0) ≈∎ ×-≈ (suc m) n = μFinSuc (suc m) ×μ μFinSuc n ≈⟨ ≈-sym 𝟙+Fin ×μ-cong ≈-refl (μFinSuc n) ⟩ (μ𝟙 +μ μFinSuc m) ×μ μFinSuc n ≈⟨ ×+-distrib μ𝟙 (μFinSuc m) (μFinSuc n) ⟩ (μ𝟙 ×μ μFinSuc n) +μ (μFinSuc m ×μ μFinSuc n) ≈⟨ 𝟙×A≈A {μA = μFinSuc n} +μ-cong ×-≈ m n ⟩ μFinSuc n +μ μFinSuc (n + m * suc n) ≈⟨ +-≈ n (n + m * suc n) ⟩ μFinSuc (n + suc m * suc n) ≈∎ open import Data.Fin using (Fin ; zero ; suc) Finable : ∀ {A} → SumPropoid A → Set Finable μA = Σ ℕ λ FinCard → μA ≈ μFinSuc FinCard 𝟙-Finable : Finable μ𝟙 𝟙-Finable = 0 , ≈-sym Fin0≈𝟙 Fin-Finable : ∀ {n} → Finable (μFinSuc n) Fin-Finable {n} = n , ≈-refl (μFinSuc n) +-Finable : ∀ {A B}(μA : SumPropoid A)(μB : SumPropoid B) → Finable μA → Finable μB → Finable (μA +μ μB) +-Finable μA μB (|A| , A≈) (|B| , B≈) = (|A| + suc |B|) , ( μA +μ μB ≈⟨ A≈ +μ-cong B≈ ⟩ μFinSuc |A| +μ μFinSuc |B| ≈⟨ +-≈ |A| |B| ⟩ μFinSuc (|A| + suc |B|) ≈∎) ×-Finable : ∀ {A B}(μA : SumPropoid A)(μB : SumPropoid B) → Finable μA → Finable μB → Finable (μA ×μ μB) ×-Finable μA μB (|A| , A≈) (|B| , B≈) = (|B| + |A| * suc |B|) , ( μA ×μ μB ≈⟨ A≈ ×μ-cong B≈ ⟩ μFinSuc |A| ×μ μFinSuc |B| ≈⟨ ×-≈ |A| |B| ⟩ μFinSuc (|B| + |A| * suc |B|) ≈∎) module _ where open import bijection-fin open import Data.Fin using (Fin; zero; suc) open import Data.Vec.NP renaming (sum to vsum) sumFin : ∀ n → Sum (Fin n) sumFin n f = vsum (tabulate f) sumFin-spec : ∀ n → sumFin (suc n) ≗ sum (μFinSuc n) sumFin-spec zero f = ℕ°.+-comm (f zero) 0 sumFin-spec (suc n) f = ≡.cong (_+_ (f zero)) (sumFin-spec n (f ∘ suc)) sumFinSUI : ∀ n f p → Injective p → sumFin n f ≡ sumFin n (f ∘ p) sumFinSUI n f p p-inj = count-perm f p (λ _ _ → p-inj) μFinSUI : ∀ {n} → StableUnderInjection (μFinSuc n) μFinSUI {n} p f rewrite ≡.sym (sumFin-spec n (_⟨$⟩_ f)) | ≡.sym (sumFin-spec n (_⟨$⟩_ (f FE.∘ FInj.Injection.to p))) = sumFinSUI (suc n) (_⟨$⟩_ f) (_⟨$⟩_ (FInj.Injection.to p)) (FInj.Injection.injective p) StableIfFinable : ∀ {A} (μA : SumProp A) → Finable μA → StableUnderInjection μA StableIfFinable μA (_ , A≈Fin) = _≈_.StableUnder≈ (≈-sym A≈Fin) μFinSUI -- -} -- -}
{ "alphanum_fraction": 0.5136150235, "avg_line_length": 33.7682926829, "ext": "agda", "hexsha": "10b2b04ff0e356bcfbfd3d1a4170eeae244b6cc9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "crypto-agda/explore", "max_forks_repo_path": "lib/Explore/Old/Sum/sum-properties-setoid.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "crypto-agda/explore", "max_issues_repo_path": "lib/Explore/Old/Sum/sum-properties-setoid.agda", "max_line_length": 142, "max_stars_count": 2, "max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "crypto-agda/explore", "max_stars_repo_path": "lib/Explore/Old/Sum/sum-properties-setoid.agda", "max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z", "num_tokens": 6409, "size": 13845 }
module Common.Integer where open import Agda.Builtin.Int public renaming (Int to Integer)
{ "alphanum_fraction": 0.8131868132, "avg_line_length": 22.75, "ext": "agda", "hexsha": "28e973a7e919ff34ad769ed9a8234de58c1e0429", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Common/Integer.agda", "max_issues_count": 16, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "test/Common/Integer.agda", "max_line_length": 61, "max_stars_count": 7, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Common/Integer.agda", "max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z", "max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z", "num_tokens": 19, "size": 91 }
-- Andreas, 2017-02-15, issue #2462 -- Overloaded postfix projection should resolve postulate A : Set record R : Set where constructor mkR field f : A open R record S : Set where field f : R open S test : S → A test s = let mkR x = s .f in x -- Error WAS: -- Cannot resolve overloaded projection f because it is not applied to -- a visible argument -- when inferring the type of .f
{ "alphanum_fraction": 0.6886075949, "avg_line_length": 17.1739130435, "ext": "agda", "hexsha": "a3bacd88e92d74102ee325a11288571396740908", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue2462.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue2462.agda", "max_line_length": 70, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue2462.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 119, "size": 395 }
module FFI.MachineWord where import Lvl open import Data.Boolean open import Numeral.Natural open import String open import Syntax.Number open import Type postulate Word64 : Type{Lvl.𝟎} {-# BUILTIN WORD64 Word64 #-} private module Primitives where primitive primWord64ToNat : Word64 → ℕ primitive primWord64FromNat : ℕ → Word64 module Word64 where open Primitives renaming ( primWord64ToNat to toℕ ; primWord64FromNat to fromℕ ) public instance Word64-infiniteNumeral : InfiniteNumeral(Word64) Word64-infiniteNumeral = InfiniteNumeral.intro fromℕ
{ "alphanum_fraction": 0.756302521, "avg_line_length": 22.037037037, "ext": "agda", "hexsha": "c86fa3b4396e4adc75fea2bc86ecb0cab5b52d54", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "FFI/MachineWord.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "FFI/MachineWord.agda", "max_line_length": 56, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "FFI/MachineWord.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 169, "size": 595 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import groups.Exactness open import cohomology.Theory {- Finite additivity is provable (and in a stronger form) without using - the additivity axiom. We have Cⁿ(X ∨ Y) == Cⁿ(X) × Cⁿ(Y) - and over this path - ∙ Cⁿ(winl) corresponds to fst : Cⁿ(X) × Cⁿ(Y) → Cⁿ(X), - ∙ Cⁿ(winr) corresponds to snd : Cⁿ(X) × Cⁿ(Y) → Cⁿ(Y), - ∙ Cⁿ(Wedge-rec winl* winr* wglue*) : Cⁿ(Z) → Cⁿ(X ∨ Y) corresponds to Cⁿ(winl*) × Cⁿ(winr*). - ∙ Cⁿ(f) : Cⁿ(X ∨ Y) → Cⁿ(Z) corresponds to Cⁿ(projl ∘ f) + Cⁿ(projr ∘ f) : Cⁿ(X) × Cⁿ(Y) → Cⁿ(Z) -} module cohomology.Wedge {i} (CT : CohomologyTheory i) (n : ℤ) where open CohomologyTheory CT module _ (X Y : Ptd i) where open import homotopy.WedgeCofiber X Y open import cohomology.PtdMapSequence CT private abstract βl : ∀ x → CEl-fmap n ⊙winl (CEl-fmap n (⊙projl {X = X} {Y}) x) == x βl = CEl-fmap-inverse n ⊙winl ⊙projl λ _ → idp βr : ∀ y → CEl-fmap n ⊙winr (CEl-fmap n (⊙projr {X = X} {Y}) y) == y βr = CEl-fmap-inverse n ⊙winr ⊙projr λ _ → idp C-projr-C-winl-is-exact : is-exact (C-fmap n (⊙projr {X = X} {Y})) (C-fmap n ⊙winl) C-projr-C-winl-is-exact = equiv-preserves'-exact (C-comm-square n cfcod-winl-projr-comm-sqr) (C-comm-square n $ comm-sqr λ _ → idp) (snd (C-emap n CofWinl.⊙eq)) (C-isemap n (⊙idf _) (idf-is-equiv _)) (C-isemap n (⊙idf _) (idf-is-equiv _)) (C-exact n ⊙winl) C-projl-C-winr-is-exact : is-exact (C-fmap n (⊙projl {X = X} {Y})) (C-fmap n ⊙winr) C-projl-C-winr-is-exact = equiv-preserves'-exact (C-comm-square n cfcod-winr-projl-comm-sqr) (C-comm-square n $ comm-sqr λ _ → idp) (snd (C-emap n CofWinr.⊙eq)) (C-isemap n (⊙idf _) (idf-is-equiv _)) (C-isemap n (⊙idf _) (idf-is-equiv _)) (C-exact n ⊙winr) import groups.ProductRepr (C-fmap n (⊙projl {X = X} {Y})) (C-fmap n ⊙projr) (C-fmap n ⊙winl) (C-fmap n ⊙winr) βl βr C-projl-C-winr-is-exact C-projr-C-winl-is-exact as PR C-Wedge : C n (X ⊙∨ Y) ≃ᴳ C n X ×ᴳ C n Y C-Wedge = PR.iso {- projl *-----* id | | C-W *-----* inl -} C-projl-inl-comm-sqr : CommSquareᴳ (C-fmap n ⊙projl) ×ᴳ-inl (idhom _) (–>ᴳ C-Wedge) C-projl-inl-comm-sqr = PR.i₁-inl-comm-sqr {- projr *-----* id | | C-W *-----* inr -} C-projr-inr-comm-sqr : CommSquareᴳ (C-fmap n ⊙projr) ×ᴳ-inr (idhom _) (–>ᴳ C-Wedge) C-projr-inr-comm-sqr = PR.i₂-inr-comm-sqr abstract C-Wedge-rec-comm-sqr : ∀ {Z : Ptd i} (winl* : X ⊙→ Z) (winr* : Y ⊙→ Z) → CommSquareᴳ (C-fmap n (⊙Wedge-rec winl* winr*)) (×ᴳ-fanout (C-fmap n winl*) (C-fmap n winr*)) (idhom _) (–>ᴳ C-Wedge) C-Wedge-rec-comm-sqr winl* winr* = comm-sqrᴳ λ z → pair×= ( ∘-CEl-fmap n ⊙winl (⊙Wedge-rec winl* winr*) z ∙ CEl-fmap-base-indep n (λ _ → idp) z) ( ∘-CEl-fmap n ⊙winr (⊙Wedge-rec winl* winr*) z ∙ CEl-fmap-base-indep n (λ _ → idp) z) C-Wedge-rec-comm-sqr' : ∀ {Z : Ptd i} (winl* : X ⊙→ Z) (winr* : Y ⊙→ Z) → CommSquareᴳ (×ᴳ-fanout (C-fmap n winl*) (C-fmap n winr*)) (C-fmap n (⊙Wedge-rec winl* winr*)) (idhom _) (<–ᴳ C-Wedge) C-Wedge-rec-comm-sqr' winl* winr* = comm-sqrᴳ λ z → ! (ap (GroupIso.g C-Wedge) (C-Wedge-rec-comm-sqr winl* winr* □$ᴳ z)) ∙ GroupIso.g-f C-Wedge (CEl-fmap n (⊙Wedge-rec winl* winr*) z) C-Wedge-out-η-comm-sqr : {Z : Ptd i} (φ : C n (⊙Wedge X Y) →ᴳ C n Z) → CommSquareᴳ φ (×ᴳ-fanin (C-is-abelian n _) (φ ∘ᴳ C-fmap n ⊙projl) (φ ∘ᴳ C-fmap n ⊙projr)) (–>ᴳ C-Wedge) (idhom _) C-Wedge-out-η-comm-sqr φ = comm-sqrᴳ λ x∨y → ap (GroupHom.f φ) (! (GroupIso.g-f C-Wedge x∨y)) ∙ ! (×ᴳ-fanin-pre∘ (C-is-abelian n _) (C-is-abelian n _) φ (C-fmap n ⊙projl) (C-fmap n ⊙projr) _) C-Wedge-out-η-comm-sqr' : {Z : Ptd i} (φ : C n (⊙Wedge X Y) →ᴳ C n Z) → CommSquareᴳ (×ᴳ-fanin (C-is-abelian n _) (φ ∘ᴳ C-fmap n ⊙projl) (φ ∘ᴳ C-fmap n ⊙projr)) φ (<–ᴳ C-Wedge) (idhom _) C-Wedge-out-η-comm-sqr' {Z} φ = comm-sqrᴳ λ z → ×ᴳ-fanin-pre∘ (C-is-abelian n _) (C-is-abelian n _) φ (C-fmap n ⊙projl) (C-fmap n ⊙projr) _ C-Wedge-in-comm-sqr : {Z : Ptd i} (f : Z ⊙→ ⊙Wedge X Y) → CommSquareᴳ (C-fmap n f) (×ᴳ-fanin (C-is-abelian n _) (C-fmap n (⊙projl ⊙∘ f)) (C-fmap n (⊙projr ⊙∘ f))) (–>ᴳ C-Wedge) (idhom _) C-Wedge-in-comm-sqr f = comm-sqrᴳ λ x∨y → (C-Wedge-out-η-comm-sqr (C-fmap n f) □$ᴳ x∨y) ∙ ap2 (Group.comp (C n _)) (∘-C-fmap n f ⊙projl _) (∘-C-fmap n f ⊙projr _) C-Wedge-in-comm-sqr' : {Z : Ptd i} (f : Z ⊙→ ⊙Wedge X Y) → CommSquareᴳ (×ᴳ-fanin (C-is-abelian n _) (C-fmap n (⊙projl ⊙∘ f)) (C-fmap n (⊙projr ⊙∘ f))) (C-fmap n f) (<–ᴳ C-Wedge) (idhom _) C-Wedge-in-comm-sqr' f = comm-sqrᴳ λ z → ap2 (Group.comp (C n _)) (C-fmap-∘ n ⊙projl f _) (C-fmap-∘ n ⊙projr f _) ∙ (C-Wedge-out-η-comm-sqr' (C-fmap n f) □$ᴳ z) module _ (X : Ptd i) where abstract C-fold-comm-sqr : CommSquareᴳ (C-fmap n ⊙fold) ×ᴳ-diag (idhom (C n X)) (–>ᴳ (C-Wedge X X)) C-fold-comm-sqr = comm-sqrᴳ λ x → GroupIso.f (C-Wedge X X) (CEl-fmap n ⊙fold x) =⟨ C-Wedge-rec-comm-sqr X X (⊙idf X) (⊙idf X) □$ᴳ x ⟩ (CEl-fmap n (⊙idf X) x , CEl-fmap n (⊙idf X) x) =⟨ pair×= (CEl-fmap-idf n x) (CEl-fmap-idf n x) ⟩ (x , x) =∎ C-fold-comm-sqr' : CommSquareᴳ ×ᴳ-diag (C-fmap n ⊙fold) (idhom (C n X)) (<–ᴳ (C-Wedge X X)) C-fold-comm-sqr' = comm-sqrᴳ λ x → ! (ap (GroupIso.g (C-Wedge X X)) (C-fold-comm-sqr □$ᴳ x)) ∙ GroupIso.g-f (C-Wedge X X) (CEl-fmap n ⊙fold x)
{ "alphanum_fraction": 0.5070189926, "avg_line_length": 35.2034883721, "ext": "agda", "hexsha": "746042b2a579d1a946202d2559f0669dd1ad32c3", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "theorems/cohomology/Wedge.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_path": "theorems/cohomology/Wedge.agda", "max_line_length": 89, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "theorems/cohomology/Wedge.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "num_tokens": 2703, "size": 6055 }
{-# OPTIONS --safe #-} module Cubical.Algebra.DirectSum.DirectSumFun.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_) open import Cubical.Data.Nat.Order open import Cubical.Data.Sigma open import Cubical.HITs.PropositionalTruncation as PT open import Cubical.Algebra.AbGroup private variable ℓ : Level open AbGroupStr ----------------------------------------------------------------------------- -- Definition AlmostNullProof : (G : ℕ → Type ℓ) → (Gstr : (n : ℕ) → AbGroupStr (G n)) → (f : (n : ℕ) → G n) → (k : ℕ) → Type ℓ AlmostNullProof G Gstr f k = (n : ℕ) → k < n → f n ≡ 0g (Gstr n) AlmostNull : (G : ℕ → Type ℓ) → (Gstr : (n : ℕ) → AbGroupStr (G n)) → (f : (n : ℕ) → G n) → Type ℓ AlmostNull G Gstr f = Σ[ k ∈ ℕ ] AlmostNullProof G Gstr f k AlmostNullP : (G : ℕ → Type ℓ) → (Gstr : (n : ℕ) → AbGroupStr (G n)) → (f : (n : ℕ) → G n) → Type ℓ AlmostNullP G Gstr f = ∥ (AlmostNull G Gstr f) ∥₁ ⊕Fun : (G : ℕ → Type ℓ) → (Gstr : (n : ℕ) → AbGroupStr (G n)) → Type ℓ ⊕Fun G Gstr = Σ[ f ∈ ((n : ℕ) → G n) ] AlmostNullP G Gstr f
{ "alphanum_fraction": 0.5636515913, "avg_line_length": 32.2702702703, "ext": "agda", "hexsha": "13a21780132a4a0b943de2357f0fb9a265e9551c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Algebra/DirectSum/DirectSumFun/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Algebra/DirectSum/DirectSumFun/Base.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Algebra/DirectSum/DirectSumFun/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 422, "size": 1194 }
------------------------------------------------------------------------ -- Functors ------------------------------------------------------------------------ -- Note that currently the functor laws are not included here. module Category.Functor where open import Data.Function record RawFunctor (f : Set → Set) : Set₁ where infixl 4 _<$>_ _<$_ field _<$>_ : ∀ {a b} → (a → b) → f a → f b _<$_ : ∀ {a b} → a → f b → f a x <$ y = const x <$> y
{ "alphanum_fraction": 0.3934782609, "avg_line_length": 24.2105263158, "ext": "agda", "hexsha": "5963aaae30787d38262a0deae2134e3d6bab7a95", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/Category/Functor.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/Category/Functor.agda", "max_line_length": 72, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/Category/Functor.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 115, "size": 460 }
{-# OPTIONS --without-K --safe #-} -------------------------------------------------------------------------------- -- A simple reflection based solver for categories. -- -- Based off 'Tactic.MonoidSolver' from 'agda-stdlib' -------------------------------------------------------------------------------- open import Categories.Category module Categories.Tactic.Category where open import Level open import Function using (_⟨_⟩_) open import Data.Bool as Bool using (Bool; _∨_; if_then_else_) open import Data.Maybe as Maybe using (Maybe; just; nothing; maybe) open import Data.List as List using (List; _∷_; []) open import Data.Product as Product using (_×_; _,_) open import Agda.Builtin.Reflection open import Reflection.Argument open import Reflection.Term using (getName; _⋯⟅∷⟆_) open import Reflection.TypeChecking.Monad.Syntax module _ {o ℓ e} (𝒞 : Category o ℓ e) where open Category 𝒞 open HomReasoning open Equiv private variable A B C : Obj f g : A ⇒ B -------------------------------------------------------------------------------- -- An 'Expr' reifies the parentheses/identity morphisms of some series of -- compositions of morphisms into a data structure. In fact, this is also -- a category! -------------------------------------------------------------------------------- data Expr : Obj → Obj → Set (o ⊔ ℓ) where _∘′_ : ∀ {A B C} → Expr B C → Expr A B → Expr A C id′ : ∀ {A} → Expr A A [_↑] : ∀ {A B} → A ⇒ B → Expr A B -- Embed a morphism in 'Expr' back into '𝒞' without normalizing. [_↓] : Expr A B → A ⇒ B [ f ∘′ g ↓] = [ f ↓] ∘ [ g ↓] [ id′ ↓] = id [ [ f ↑] ↓] = f -- Convert an 'Expr' back into a morphism, while normalizing -- -- This actually embeds the morphism into the category of copresheaves -- on 𝒞, which obeys the category laws up to beta-eta equality. -- This lets us normalize away all the associations/identity morphisms. embed : Expr B C → A ⇒ B → A ⇒ C embed (f ∘′ g) h = embed f (embed g h) embed id′ h = h embed [ f ↑] h = f ∘ h preserves-≈′ : ∀ (f : Expr B C) → (h : A ⇒ B) → embed f id ∘ h ≈ embed f h preserves-≈′ id′ f = identityˡ preserves-≈′ [ x ↑] f = ∘-resp-≈ˡ identityʳ preserves-≈′ (f ∘′ g) h = begin embed (f ∘′ g) id ∘ h ≡⟨⟩ embed f (embed g id) ∘ h ≈˘⟨ preserves-≈′ f (embed g id) ⟩∘⟨refl ⟩ (embed f id ∘ embed g id) ∘ h ≈⟨ assoc ⟩ embed f id ∘ embed g id ∘ h ≈⟨ refl⟩∘⟨ preserves-≈′ g h ⟩ embed f id ∘ embed g h ≈⟨ preserves-≈′ f (embed g h) ⟩ embed (f ∘′ g) h ∎ preserves-≈ : ∀ (f : Expr A B) → embed f id ≈ [ f ↓] preserves-≈ id′ = refl preserves-≈ [ x ↑] = identityʳ preserves-≈ (f ∘′ g) = begin embed (f ∘′ g) id ≈˘⟨ preserves-≈′ f (embed g id) ⟩ embed f id ∘ embed g id ≈⟨ preserves-≈ f ⟩∘⟨ preserves-≈ g ⟩ [ f ↓] ∘ [ g ↓] ≡⟨⟩ [ f ∘′ g ↓] ∎ -------------------------------------------------------------------------------- -- Reflection Helpers -------------------------------------------------------------------------------- _==_ = primQNameEquality {-# INLINE _==_ #-} getArgs : Term → Maybe (Term × Term) getArgs (def _ xs) = go xs where go : List (Arg Term) → Maybe (Term × Term) go (vArg x ∷ vArg y ∷ []) = just (x , y) go (x ∷ xs) = go xs go _ = nothing getArgs _ = nothing -------------------------------------------------------------------------------- -- Getting Category Names -------------------------------------------------------------------------------- record CategoryNames : Set where field is-∘ : Name → Bool is-id : Name → Bool buildMatcher : Name → Maybe Name → Name → Bool buildMatcher n nothing x = n == x buildMatcher n (just m) x = n == x ∨ m == x findCategoryNames : Term → TC CategoryNames findCategoryNames cat = do ∘-altName ← normalise (def (quote Category._∘_) (3 ⋯⟅∷⟆ cat ⟨∷⟩ [])) id-altName ← normalise (def (quote Category.id) (3 ⋯⟅∷⟆ cat ⟨∷⟩ [])) returnTC record { is-∘ = buildMatcher (quote Category._∘_) (getName ∘-altName) ; is-id = buildMatcher (quote Category.id) (getName id-altName) } -------------------------------------------------------------------------------- -- Constructing an Expr -------------------------------------------------------------------------------- ″id″ : Term ″id″ = quote id′ ⟨ con ⟩ [] ″[_↑]″ : Term → Term ″[ t ↑]″ = quote [_↑] ⟨ con ⟩ (t ⟨∷⟩ []) module _ (names : CategoryNames) where open CategoryNames names mutual ″∘″ : List (Arg Term) → Term ″∘″ (x ⟨∷⟩ y ⟨∷⟩ xs) = quote _∘′_ ⟨ con ⟩ buildExpr x ⟨∷⟩ buildExpr y ⟨∷⟩ [] ″∘″ (x ∷ xs) = ″∘″ xs ″∘″ _ = unknown buildExpr : Term → Term buildExpr t@(def n xs) = if (is-∘ n) then ″∘″ xs else if (is-id n) then ″id″ else ″[ t ↑]″ buildExpr t@(con n xs) = if (is-∘ n) then ″∘″ xs else if (is-id n) then ″id″ else ″[ t ↑]″ buildExpr t = ″[ t ↑]″ -------------------------------------------------------------------------------- -- Constructing the Solution -------------------------------------------------------------------------------- constructSoln : Term → CategoryNames → Term → Term → Term constructSoln cat names lhs rhs = quote Category.Equiv.trans ⟨ def ⟩ 3 ⋯⟅∷⟆ cat ⟨∷⟩ (quote Category.Equiv.sym ⟨ def ⟩ 3 ⋯⟅∷⟆ cat ⟨∷⟩ (quote preserves-≈ ⟨ def ⟩ 3 ⋯⟅∷⟆ cat ⟨∷⟩ buildExpr names lhs ⟨∷⟩ []) ⟨∷⟩ []) ⟨∷⟩ (quote preserves-≈ ⟨ def ⟩ 3 ⋯⟅∷⟆ cat ⟨∷⟩ buildExpr names rhs ⟨∷⟩ []) ⟨∷⟩ [] solve-macro : Term → Term → TC _ solve-macro mon hole = do hole′ ← inferType hole >>= normalise names ← findCategoryNames mon just (lhs , rhs) ← returnTC (getArgs hole′) where nothing → typeError (termErr hole′ ∷ []) let soln = constructSoln mon names lhs rhs unify hole soln macro solve : Term → Term → TC _ solve = solve-macro
{ "alphanum_fraction": 0.4715379494, "avg_line_length": 32.4756756757, "ext": "agda", "hexsha": "1ab24c52bfb880a247b80b2ccf8ad241fd091cbf", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Tactic/Category.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Tactic/Category.agda", "max_line_length": 83, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Tactic/Category.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 1880, "size": 6008 }
module Category.Test where open import Equality.Eq postulate A : Set postulate o : A → A postulate x : A postulate y : A postulate h : A → A → Set postulate f : h x y postulate I : A postulate i : h I I postulate m : h x y → h (o x) (o y) postulate pf₁ : o x ≅ I postulate pf₂ : o y ≅ I subst≅2 : {A : Set }{a a' b b' : A}{P : A → A → Set} → a ≅ a' → b ≅ b' → P a b → P a' b' subst≅2 refl refl x = x eq-f-i-m : Set eq-f-i-m = let i-m = let h-pf = eqApp2 pf₁ pf₂ (λ A B → h A B) in subst≅2 {A}{I}{(o x)}{I}{(o y)}{h} (sym pf₁) (sym pf₂) i in m f ≅ i-m
{ "alphanum_fraction": 0.534923339, "avg_line_length": 27.9523809524, "ext": "agda", "hexsha": "fc06477c4d69a8f3e96ac16d04f2207679eacfaa", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "heades/AUGL", "max_forks_repo_path": "setoid-cats/Category/test.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "heades/AUGL", "max_issues_repo_path": "setoid-cats/Category/test.agda", "max_line_length": 137, "max_stars_count": null, "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "heades/AUGL", "max_stars_repo_path": "setoid-cats/Category/test.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 264, "size": 587 }
module Impure.STLCRef.Syntax where open import Prelude hiding (subst) open import Data.Vec open import Data.List open import Function data Type : Set where Unit : Type _⇒_ : (a b : Type) → Type Ref : Type → Type infixl 10 _·_ data Exp : (n : ℕ) → Set where unit : ∀ {n} → Exp n var : ∀ {n} → Fin n → Exp n loc : ∀ {n} → ℕ → Exp n ƛ : ∀ {n} → Type → Exp (suc n) → Exp n _·_ : ∀ {n} → (f e : Exp n) → Exp n ref : ∀ {n} → (e : Exp n) → Exp n !_ : ∀ {n} → (e : Exp n) → Exp n _≔_ : ∀ {n} → (x y : Exp n) → Exp n data Val : ∀ {n} → Exp n → Set where unit : ∀ {n} → Val {n} unit ƛ : ∀ {n} A → (e : Exp (suc n)) → Val (ƛ A e) loc : ∀ {n} i → Val {n} (loc i) Store : ℕ → Set Store n = List (∃ λ (e : Exp n) → Val e) open import Data.Fin.Substitution module ExpApp {T} (l : Lift T Exp) where open Lift l _/_ : ∀ {n n'} → Exp n → Sub T n n' → Exp n' var x / s = lift $ lookup x s ƛ A t / s = ƛ A (t / (s ↑)) (f · e) / s = (f / s) · (e / s) unit / s = unit loc x / s = loc x ref e / s = ref (e / s) (! e) / s = ! (e / s) (e ≔ e₁) / s = (e / s) ≔ (e₁ / s) open Application (record { _/_ = _/_ }) using (_/✶_) tmSubst : TermSubst Exp tmSubst = record { var = var; app = ExpApp._/_ } open TermSubst tmSubst hiding (var) public
{ "alphanum_fraction": 0.5007751938, "avg_line_length": 24.3396226415, "ext": "agda", "hexsha": "e33d1280b49b99a07bf96d1681094e6beae75fcc", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_path": "src/Impure/STLCRef/Syntax.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_path": "src/Impure/STLCRef/Syntax.agda", "max_line_length": 54, "max_stars_count": null, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/Impure/STLCRef/Syntax.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 556, "size": 1290 }
------------------------------------------------------------------------ -- Finite sets, based on AVL trees ------------------------------------------------------------------------ open import Relation.Binary module Data.AVL.Sets (OrderedKeySet : StrictTotalOrder) where import Data.AVL as AVL open StrictTotalOrder OrderedKeySet renaming (carrier to Key) open import Data.Unit open import Data.Function open import Data.Product as Prod using (_×_; _,_; proj₁) open import Data.Maybe as Maybe open import Data.Bool open import Data.List open import Category.Functor open RawFunctor Maybe.functor -- The set type. (Note that Set is a reserved word.) private open module S = AVL OrderedKeySet (const₁ ⊤) public using () renaming (Tree to ⟨Set⟩) -- Repackaged functions. empty : ⟨Set⟩ empty = S.empty singleton : Key → ⟨Set⟩ singleton k = S.singleton k _ insert : Key → ⟨Set⟩ → ⟨Set⟩ insert k = S.insert k _ delete : Key → ⟨Set⟩ → ⟨Set⟩ delete = S.delete lookup : Key → ⟨Set⟩ → Maybe Key lookup k s = proj₁ <$> S.lookup k s _∈?_ : Key → ⟨Set⟩ → Bool _∈?_ = S._∈?_ headTail : ⟨Set⟩ → Maybe (Key × ⟨Set⟩) headTail s = Prod.map proj₁ id <$> S.headTail s initLast : ⟨Set⟩ → Maybe (⟨Set⟩ × Key) initLast s = Prod.map id proj₁ <$> S.initLast s fromList : List Key → ⟨Set⟩ fromList = S.fromList ∘ map (λ k → (k , _)) toList : ⟨Set⟩ → List Key toList = map proj₁ ∘ S.toList
{ "alphanum_fraction": 0.6144404332, "avg_line_length": 24.298245614, "ext": "agda", "hexsha": "275a9b22a207c6592726113fe379240559e7cb62", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/Data/AVL/Sets.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/Data/AVL/Sets.agda", "max_line_length": 72, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/Data/AVL/Sets.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 380, "size": 1385 }
-- Andreas, 2013-10-26, reported by Jesper Cockx {-# OPTIONS --cubical-compatible #-} module Issue920a where import Common.Level open import Common.Equality record ⊥ : Set where data Bool : Set where true false : Bool -- Standard eliminator for ≡ J : ∀ {a b} {A : Set a} {x : A} {Φ : (y : A) → x ≡ y → Set b} → Φ x refl → {y : A} → (e : x ≡ y) → Φ y e J φ refl = φ -- A kind of heterogeneous equality _≃_ : {A : Set} (x : A) {A' : Set} → A' → Set _ _≃_ {A} x {A'} x' = (E : A ≡ A') → J x E ≡ x' -- It shouldn't be possible to define this without K ≃refl : {A : Set} {x : A} → x ≃ x ≃refl {x = x} = λ E → J {Φ = λ A' E' → J x E' ≡ _} refl E -- These can be given using univalence postulate Swap : Bool ≡ Bool postulate swap : true ≡ J {Φ = λ A _ → A} false Swap -- Univalence and ≃refl don't play nice together right : (true ≡ false) → ⊥ right () wrong : true ≡ false wrong = trans swap (≃refl Swap) madness : ⊥ madness = right wrong
{ "alphanum_fraction": 0.5797705944, "avg_line_length": 23.3902439024, "ext": "agda", "hexsha": "d48eefc1753b40a3ea504f55a6bb336dcbccd12f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Fail/Issue920a.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Fail/Issue920a.agda", "max_line_length": 63, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Fail/Issue920a.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 368, "size": 959 }
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Standard evaluation (Def. 3.3 and Fig. 4i) ------------------------------------------------------------------------ import Parametric.Syntax.Type as Type import Parametric.Syntax.Term as Term import Parametric.Denotation.Value as Value module Parametric.Denotation.Evaluation {Base : Type.Structure} (Const : Term.Structure Base) (⟦_⟧Base : Value.Structure Base) where open Type.Structure Base open Term.Structure Base Const open Value.Structure Base ⟦_⟧Base open import Base.Denotation.Notation open import Relation.Binary.PropositionalEquality open import Theorem.CongApp open import Postulate.Extensionality -- Extension Point: Evaluation of constants. Structure : Set Structure = ∀ {τ} → Const τ → ⟦ τ ⟧ module Structure (⟦_⟧Const : Structure) where ⟦_⟧Term : ∀ {Γ τ} → Term Γ τ → ⟦ Γ ⟧ → ⟦ τ ⟧ -- We provide: Evaluation of arbitrary terms. ⟦ const c ⟧Term ρ = ⟦ c ⟧Const ⟦ var x ⟧Term ρ = ⟦ x ⟧ ρ ⟦ app s t ⟧Term ρ = (⟦ s ⟧Term ρ) (⟦ t ⟧Term ρ) ⟦ abs t ⟧Term ρ = λ v → ⟦ t ⟧Term (v • ρ) instance meaningOfTerm : ∀ {Γ τ} → Meaning (Term Γ τ) meaningOfTerm = meaning ⟦_⟧Term weaken-sound : ∀ {Γ₁ Γ₂ τ} {Γ₁≼Γ₂ : Γ₁ ≼ Γ₂} (t : Term Γ₁ τ) (ρ : ⟦ Γ₂ ⟧) → ⟦ weaken Γ₁≼Γ₂ t ⟧ ρ ≡ ⟦ t ⟧ (⟦ Γ₁≼Γ₂ ⟧ ρ) weaken-sound {Γ₁≼Γ₂ = Γ₁≼Γ₂} (var x) ρ = weaken-var-sound Γ₁≼Γ₂ x ρ weaken-sound (app s t) ρ = weaken-sound s ρ ⟨$⟩ weaken-sound t ρ weaken-sound (abs t) ρ = ext (λ v → weaken-sound t (v • ρ)) weaken-sound (const c) ρ = refl
{ "alphanum_fraction": 0.5916824197, "avg_line_length": 31.74, "ext": "agda", "hexsha": "d87f5d9ce83dc63f593dae88eee06f77cb8f1ec1", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Parametric/Denotation/Evaluation.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Parametric/Denotation/Evaluation.agda", "max_line_length": 77, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Parametric/Denotation/Evaluation.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 571, "size": 1587 }
-- Andreas, 2012-03-15, example by Nisse -- {-# OPTIONS --show-implicit -v tc.meta:20 #-} module Issue585-17 where data List (A : Set) : Set where [] : List A _∷_ : A → List A → List A data ″ℕ″ : Set where suc : ″ℕ″ → ″ℕ″ replicate : {A : Set} → ″ℕ″ → A → List A replicate (suc n) x = x ∷ replicate n x data P (A B : Set) : List B → Set where p : (x : B) → P A B (x ∷ []) data Q {A B xs} : List B → P A B xs → Set where q : ∀ {x xs p} → Q xs p → Q (x ∷ xs) p foo : {A B : Set} (x : B) (n : ″ℕ″) → Q (replicate n x) (p {A = A} x) foo x n = bar x n where bar : {B : Set} (x : B) (n : ″ℕ″) → Q (replicate n x) (p x) bar x (suc n) = q (bar x n)
{ "alphanum_fraction": 0.5007518797, "avg_line_length": 24.6296296296, "ext": "agda", "hexsha": "668213dae435ff7c018cf593ad0fff938855780a", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue585-17.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue585-17.agda", "max_line_length": 69, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue585-17.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 304, "size": 665 }
------------------------------------------------------------------------------ -- Agda-Prop Library. -- Theorems of ⊃ connective. ------------------------------------------------------------------------------ open import Data.Nat using ( ℕ ) module Data.PropFormula.Theorems.Implication ( n : ℕ ) where ------------------------------------------------------------------------------ open import Data.PropFormula.Syntax n open import Data.PropFormula.Theorems.Classical n open import Function using ( _$_; _∘_; flip ) ------------------------------------------------------------------------------ -- Theorem. ⊃-equiv : ∀ {Γ} {φ ψ} → Γ ⊢ φ ⊃ ψ → Γ ⊢ ¬ φ ∨ ψ ⊃-to-¬∨ = ⊃-equiv -- Proof. ⊃-equiv {φ = φ}{ψ} Γ⊢φ⊃ψ = (⊃-elim (⊃-intro (∨-elim (∨-intro₂ (¬ φ) (⊃-elim (weaken φ Γ⊢φ⊃ψ) (assume φ))) (∨-intro₁ ψ (assume (¬ φ))))) PEM) -------------------------------------------------------------------------- ∎ -- Theorems from the book: -- van Dalen 4th Edition. Chapter 2. Section 2.4. -- Theorem. vanDalen244a : ∀ {Γ} {φ ψ} → Γ ⊢ φ ⊃ (ψ ⊃ φ) -- Proof. vanDalen244a {φ = φ}{ψ} = (⊃-intro (⊃-intro (weaken ψ (assume φ)))) -------------------------------------------------------------------------- ∎ -- Theorem. vanDalen244b : ∀ {Γ} {φ ψ} → Γ ⊢ φ ⊃ (¬ φ ⊃ ψ) -- Proof. vanDalen244b {Γ}{φ}{ψ} = ⊃-intro $ ⊃-intro $ ⊥-elim {Γ = (Γ , φ , ¬ φ)} ψ $ ¬-elim (assume {Γ = Γ , φ} (¬ φ)) (weaken (¬ φ) (assume φ)) -------------------------------------------------------------------------- ∎ -- Theorem. vanDalen244c : ∀ {Γ} {φ ψ γ} → Γ ⊢ (φ ⊃ ψ) ⊃ ((ψ ⊃ γ) ⊃ (φ ⊃ γ)) -- Proof. vanDalen244c {Γ}{φ}{ψ}{γ} = ⊃-intro $ ⊃-intro $ ⊃-intro $ ⊃-elim (weaken φ $ assume {Γ = Γ , φ ⊃ ψ} $ ψ ⊃ γ) (⊃-elim (weaken φ $ weaken (ψ ⊃ γ) $ assume $ φ ⊃ ψ) (assume {Γ = Γ , φ ⊃ ψ , ψ ⊃ γ} φ)) -------------------------------------------------------------------------- ∎ -- Theorem. vanDalen244d : ∀ {Γ} {φ ψ} → Γ ⊢ ¬ ψ ⊃ ¬ φ → Γ ⊢ φ ⊃ ψ ¬⊃¬-to-⊃ = vanDalen244d contraposition₁ = vanDalen244d -- Proof. vanDalen244d {Γ}{φ}{ψ} Γ⊢¬ψ⊃¬φ = (⊃-elim (⊃-intro $ (⊃-intro $ RAA $ ¬-elim (⊃-elim (weaken (¬ ψ) $ weaken φ $ assume $ ¬ ψ ⊃ ¬ φ) (assume {Γ = Γ , ¬ ψ ⊃ ¬ φ , φ} $ ¬ ψ)) (weaken (¬ ψ) $ assume {Γ = Γ , ¬ ψ ⊃ ¬ φ} φ))) Γ⊢¬ψ⊃¬φ) -------------------------------------------------------------------------- ∎ -- Theorem. contraposition₂ : ∀ {Γ} {φ ψ} → Γ ⊢ φ ⊃ ψ → Γ ⊢ ¬ ψ ⊃ ¬ φ ⊃-to-¬⊃¬ = contraposition₂ -- Proof. contraposition₂ {Γ}{φ}{ψ} Γ⊢φ⊃ψ = ⊃-intro (¬-intro (¬-elim (weaken φ (assume (¬ ψ))) (⊃-elim (weaken φ (weaken (¬ ψ) Γ⊢φ⊃ψ)) (assume {Γ = Γ , ¬ ψ} φ)))) -------------------------------------------------------------------------- ∎ -- Theorem. vanDalen244e : ∀ {Γ} {φ} → Γ ⊢ ¬ (¬ φ) ⊃ φ -- Proof. vanDalen244e {Γ}{φ} = ⊃-intro $ RAA (¬-elim (weaken (¬ φ) $ assume $ ¬ (¬ φ)) (assume {Γ = Γ , ¬ (¬ φ)} $ ¬ φ)) -------------------------------------------------------------------------- ∎ -- Theorem. ⊃⊃-to-∧⊃ : ∀ {Γ} {φ ψ γ} → Γ ⊢ φ ⊃ (ψ ⊃ γ) → Γ ⊢ (φ ∧ ψ) ⊃ γ -- Proof. ⊃⊃-to-∧⊃ {Γ}{φ}{ψ} Γ⊢φ⊃ψ⊃γ = ⊃-intro (⊃-elim (⊃-elim (weaken (φ ∧ ψ) Γ⊢φ⊃ψ⊃γ) (∧-proj₁ (assume (φ ∧ ψ)))) (∧-proj₂ (assume (φ ∧ ψ)))) -------------------------------------------------------------------------- ∎ -- Theorem. ∧⊃-to-⊃⊃ : ∀ {Γ} {φ ψ γ} → Γ ⊢ (φ ∧ ψ) ⊃ γ → Γ ⊢ φ ⊃ (ψ ⊃ γ) -- Proof. ∧⊃-to-⊃⊃ {Γ}{φ}{ψ} Γ⊢φ∧ψ⊃γ = ⊃-intro (⊃-intro (⊃-elim (weaken ψ (weaken φ Γ⊢φ∧ψ⊃γ)) (∧-intro (weaken ψ (assume φ)) (assume {Γ = Γ , φ} ψ)))) -------------------------------------------------------------------------- ∎ -- Theorem. ⊃∧⊃-to-⊃∧ : ∀ {Γ} {φ ψ γ} → Γ ⊢ (φ ⊃ ψ) ∧ (φ ⊃ γ) → Γ ⊢ φ ⊃ (ψ ∧ γ) -- Proof. ⊃∧⊃-to-⊃∧ {φ = φ} Γ⊢⟨φ⊃ψ⟩∧⟨φ⊃γ⟩ = ⊃-intro (∧-intro (⊃-elim (∧-proj₁ (weaken φ Γ⊢⟨φ⊃ψ⟩∧⟨φ⊃γ⟩)) (assume φ)) (⊃-elim (∧-proj₂ (weaken φ Γ⊢⟨φ⊃ψ⟩∧⟨φ⊃γ⟩)) (assume φ))) -------------------------------------------------------------------------- ∎ -- Theorem. subst⊢⊃₁ : ∀ {Γ} {φ ψ γ} → Γ ⊢ γ ⊃ φ → Γ ⊢ φ ⊃ ψ → Γ ⊢ γ ⊃ ψ -- Proof. subst⊢⊃₁ {γ = γ} Γ⊢ψ⊃γ Γ⊢φ⊃ψ = ⊃-intro (⊃-elim (weaken γ Γ⊢φ⊃ψ) (⊃-elim (weaken γ Γ⊢ψ⊃γ) (assume γ))) -------------------------------------------------------------------------- ∎ -- Theorem. subst⊢⊃₂ : ∀ {Γ} {φ ψ γ} → Γ ⊢ ψ ⊃ γ → Γ ⊢ φ ⊃ ψ → Γ ⊢ φ ⊃ γ -- Proof. subst⊢⊃₂ {φ = φ} Γ⊢γ⊃φ Γ⊢φ⊃ψ = ⊃-intro (⊃-elim (weaken φ Γ⊢γ⊃φ) (⊃-elim (weaken φ Γ⊢φ⊃ψ) (assume φ))) -------------------------------------------------------------------------- ∎ -- Theorem. ⊃-trans : ∀ {Γ} {φ ψ γ} → Γ ⊢ φ ⊃ ψ → Γ ⊢ ψ ⊃ γ → Γ ⊢ φ ⊃ γ -- Proof. ⊃-trans Γ⊢φ⊃ψ Γ⊢ψ⊃γ = subst⊢⊃₂ Γ⊢ψ⊃γ Γ⊢φ⊃ψ -------------------------------------------------------------------------- ∎
{ "alphanum_fraction": 0.2975619121, "avg_line_length": 22.1659574468, "ext": "agda", "hexsha": "7bb00d7ceda0a130780e51e1b138420a48f26f01", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2017-12-01T17:01:25.000Z", "max_forks_repo_forks_event_min_datetime": "2017-03-30T16:41:56.000Z", "max_forks_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jonaprieto/agda-prop", "max_forks_repo_path": "src/Data/PropFormula/Theorems/Implication.agda", "max_issues_count": 18, "max_issues_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae", "max_issues_repo_issues_event_max_datetime": "2017-12-18T16:34:21.000Z", "max_issues_repo_issues_event_min_datetime": "2017-03-08T14:33:10.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jonaprieto/agda-prop", "max_issues_repo_path": "src/Data/PropFormula/Theorems/Implication.agda", "max_line_length": 78, "max_stars_count": 13, "max_stars_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jonaprieto/agda-prop", "max_stars_repo_path": "src/Data/PropFormula/Theorems/Implication.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T03:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2017-05-01T16:45:41.000Z", "num_tokens": 2212, "size": 5209 }
module Luau.Substitution where open import Luau.Syntax using (Expr; Stat; Block; nil; addr; var; function⟨_⟩_end; _$_; block_is_end; local_←_; _∙_; done; function_⟨_⟩_end; return) open import Luau.Value using (Value; val) open import Luau.Var using (Var; _≡ⱽ_) open import Properties.Dec using (Dec; yes; no) _[_/_]ᴱ : Expr → Value → Var → Expr _[_/_]ᴮ : Block → Value → Var → Block var_[_/_]ᴱwhenever_ : ∀ {P} → Var → Value → Var → (Dec P) → Expr _[_/_]ᴮunless_ : ∀ {P} → Block → Value → Var → (Dec P) → Block nil [ v / x ]ᴱ = nil var y [ v / x ]ᴱ = var y [ v / x ]ᴱwhenever (x ≡ⱽ y) addr a [ v / x ]ᴱ = addr a (M $ N) [ v / x ]ᴱ = (M [ v / x ]ᴱ) $ (N [ v / x ]ᴱ) function⟨ y ⟩ C end [ v / x ]ᴱ = function⟨ y ⟩ C [ v / x ]ᴮunless (x ≡ⱽ y) end block b is C end [ v / x ]ᴱ = block b is C [ v / x ]ᴮ end (function f ⟨ y ⟩ C end ∙ B) [ v / x ]ᴮ = function f ⟨ y ⟩ (C [ v / x ]ᴮunless (x ≡ⱽ y)) end ∙ (B [ v / x ]ᴮunless (x ≡ⱽ f)) (local y ← M ∙ B) [ v / x ]ᴮ = local y ← (M [ v / x ]ᴱ) ∙ (B [ v / x ]ᴮunless (x ≡ⱽ y)) (return M ∙ B) [ v / x ]ᴮ = return (M [ v / x ]ᴱ) ∙ (B [ v / x ]ᴮ) done [ v / x ]ᴮ = done var y [ v / x ]ᴱwhenever yes p = val v var y [ v / x ]ᴱwhenever no p = var y B [ v / x ]ᴮunless yes p = B B [ v / x ]ᴮunless no p = B [ v / x ]ᴮ
{ "alphanum_fraction": 0.5393794749, "avg_line_length": 40.5483870968, "ext": "agda", "hexsha": "1a36117405a1006a2789cf4e55b22b283f0c7643", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "FreakingBarbarians/luau", "max_forks_repo_path": "prototyping/Luau/Substitution.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "FreakingBarbarians/luau", "max_issues_repo_path": "prototyping/Luau/Substitution.agda", "max_line_length": 148, "max_stars_count": 1, "max_stars_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FreakingBarbarians/luau", "max_stars_repo_path": "prototyping/Luau/Substitution.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z", "max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z", "num_tokens": 606, "size": 1257 }
module Issue1691.Nat where data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ {-# BUILTIN NATURAL ℕ #-} _∸_ : ℕ → ℕ → ℕ m ∸ zero = m zero ∸ suc n = zero suc m ∸ suc n = m ∸ n pred : ℕ → ℕ pred zero = zero pred (suc n) = n
{ "alphanum_fraction": 0.5191489362, "avg_line_length": 13.8235294118, "ext": "agda", "hexsha": "50321df32d758dd427b30a7e625f12e20ea194c8", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue1691/Nat.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue1691/Nat.agda", "max_line_length": 26, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1691/Nat.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 101, "size": 235 }
module Issue2579.Instance (A : Set) (a : A) where open import Issue2579.Import instance w : Wrap A w = wrap a
{ "alphanum_fraction": 0.6810344828, "avg_line_length": 14.5, "ext": "agda", "hexsha": "962f7ede5fee37d2653efd541146ec900c316325", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue2579/Instance.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue2579/Instance.agda", "max_line_length": 49, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue2579/Instance.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 38, "size": 116 }
module BuiltinMustBeConstructor where data Bool : Set where true : Bool other : Bool false : Bool false = true {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE true #-} {-# BUILTIN FALSE false #-}
{ "alphanum_fraction": 0.665, "avg_line_length": 14.2857142857, "ext": "agda", "hexsha": "216d7fafe9199139129adfb3fc91e50eeda15f63", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/BuiltinMustBeConstructor.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/BuiltinMustBeConstructor.agda", "max_line_length": 37, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/BuiltinMustBeConstructor.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 52, "size": 200 }
open import Relation.Binary.Core module PLRTree.DropLast.Complete {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) where open import Data.Sum renaming (_⊎_ to _∨_) open import PLRTree {A} open import PLRTree.Drop _≤_ tot≤ open import PLRTree.Complete {A} open import PLRTree.Complete.Properties {A} open import PLRTree.Compound {A} open import PLRTree.Equality {A} open import PLRTree.Equality.Properties {A} lemma-dropLast-≃ : {l r : PLRTree} → l ≃ r → Compound l → l ⋙ dropLast r lemma-dropLast-≃ (≃nd x x' ≃lf ≃lf ≃lf) compound = ⋙p (⋗lf x) lemma-dropLast-≃ (≃nd x x' (≃nd _ _ _ _ _) ≃lf ()) compound lemma-dropLast-≃ (≃nd x x' l≃r (≃nd x'₁ x'₂ l'₁≃r'₁ l'₂≃r'₂ l'₁≃l'₂) (≃nd x₁ .x'₁ l₁≃r₁ _ l₁≃l'₁)) compound = let x'₁l'₁r'₁⋙dl-x'₂l'₂r'₂ = lemma-dropLast-≃ (≃nd x'₁ x'₂ l'₁≃r'₁ l'₂≃r'₂ l'₁≃l'₂) compound in ⋙r x x' l≃r x'₁l'₁r'₁⋙dl-x'₂l'₂r'₂ (≃nd x₁ x'₁ l₁≃r₁ l'₁≃r'₁ l₁≃l'₁) lemma-dropLast-⋗ : {l r : PLRTree} → l ⋗ r → Compound r → dropLast l ⋘ r lemma-dropLast-⋗ (⋗nd _ _ ≃lf _ ()) compound lemma-dropLast-⋗ (⋗nd x x' (≃nd x₁ x₂ ≃lf ≃lf ≃lf) ≃lf (⋗lf .x₁)) compound = x⋘ x x₁ x' lemma-dropLast-⋗ (⋗nd _ _ (≃nd x₁ _ ≃lf (≃nd _ _ _ _ _) ()) ≃lf (⋗lf .x₁)) compound lemma-dropLast-⋗ (⋗nd x x' (≃nd {l₁} {r₁} x₁ x₂ l₁≃r₁ l₂≃r₂ l₁≃l₂) l'≃r' (⋗nd .x₁ x'₁ _ l'₁≃r'₁ l₁⋗l'₁)) compound = let x₁l₁r₁⋙dl-x₂l₂r₂ = lemma-dropLast-≃ (≃nd x₁ x₂ l₁≃r₁ l₂≃r₂ l₁≃l₂) compound in r⋘ x x' x₁l₁r₁⋙dl-x₂l₂r₂ l'≃r' (⋗nd x₁ x'₁ l₁≃r₁ l'₁≃r'₁ l₁⋗l'₁) mutual lemma-dropLast-⋘ : {l r : PLRTree} → l ⋘ r → dropLast l ⋘ r ∨ dropLast l ≃ r lemma-dropLast-⋘ (x⋘ x _ z) = inj₂ (≃nd x z ≃lf ≃lf ≃lf) lemma-dropLast-⋘ (l⋘ x x' (x⋘ x₁ x₂ x₃) x'₁≃x'₂ (≃nd .x₃ x'₁ ≃lf ≃lf ≃lf)) = inj₂ (≃nd x x' (≃nd x₁ x₃ ≃lf ≃lf ≃lf) x'₁≃x'₂ (≃nd x₁ x'₁ ≃lf ≃lf ≃lf)) lemma-dropLast-⋘ (l⋘ x x' (l⋘ {l₁} {r₁} x₁ x₂ l₁⋘r₁ l₂≃r₂ r₁≃l₂) l'≃r' (≃nd .x₂ x'₁ _ l'₁≃r'₁ l₂≃l'₁)) with dropLast (node left x₁ l₁ r₁) | lemma-dropLast-⋘ (l⋘ x₁ x₂ l₁⋘r₁ l₂≃r₂ r₁≃l₂) ... | leaf | inj₁ () ... | node perfect _ _ _ | inj₁ () ... | node left _ _ _ | inj₁ dl-x₁l₁r₁⋘x₂l₂r₂ = inj₁ (l⋘ x x' dl-x₁l₁r₁⋘x₂l₂r₂ l'≃r' (≃nd x₂ x'₁ l₂≃r₂ l'₁≃r'₁ l₂≃l'₁)) ... | node right _ _ _ | inj₁ dl-x₁l₁r₁⋘x₂l₂r₂ = inj₁ (l⋘ x x' dl-x₁l₁r₁⋘x₂l₂r₂ l'≃r' (≃nd x₂ x'₁ l₂≃r₂ l'₁≃r'₁ l₂≃l'₁)) ... | leaf | inj₂ () ... | node perfect x'' l'' r'' | inj₂ (≃nd .x'' .x₂ l''≃r'' _ l''≃l₂) = let l''≃l'₁ = trans≃ l''≃l₂ l₂≃l'₁ in inj₂ (≃nd x x' (≃nd x'' x₂ l''≃r'' l₂≃r₂ l''≃l₂) l'≃r' (≃nd x'' x'₁ l''≃r'' l'₁≃r'₁ l''≃l'₁)) ... | node left _ _ _ | inj₂ () ... | node right _ _ _ | inj₂ () lemma-dropLast-⋘ (l⋘ x x' (r⋘ {l₁} {r₁} x₁ x₂ l₁⋙r₁ l₂≃r₂ l₁⋗l₂) l'≃r' (≃nd .x₂ x'₁ _ l'₁≃r'₁ l₂≃l'₁)) with dropLast (node right x₁ l₁ r₁) | lemma-dropLast-⋘ (r⋘ x₁ x₂ l₁⋙r₁ l₂≃r₂ l₁⋗l₂) ... | leaf | inj₁ () ... | node perfect _ _ _ | inj₁ () ... | node left _ _ _ | inj₁ dl-x₁l₁r₁⋘x₂l₂r₂ = inj₁ (l⋘ x x' dl-x₁l₁r₁⋘x₂l₂r₂ l'≃r' (≃nd x₂ x'₁ l₂≃r₂ l'₁≃r'₁ l₂≃l'₁)) ... | node right _ _ _ | inj₁ dl-x₁l₁r₁⋘x₂l₂r₂ = inj₁ (l⋘ x x' dl-x₁l₁r₁⋘x₂l₂r₂ l'≃r' (≃nd x₂ x'₁ l₂≃r₂ l'₁≃r'₁ l₂≃l'₁)) ... | leaf | inj₂ () ... | node perfect x'' l'' r'' | inj₂ (≃nd .x'' .x₂ l''≃r'' _ l''≃l₂) = let l''≃l'₁ = trans≃ l''≃l₂ l₂≃l'₁ in inj₂ (≃nd x x' (≃nd x'' x₂ l''≃r'' l₂≃r₂ l''≃l₂) l'≃r' (≃nd x'' x'₁ l''≃r'' l'₁≃r'₁ l''≃l'₁)) ... | node left _ _ _ | inj₂ () ... | node right _ _ _ | inj₂ () lemma-dropLast-⋘ (r⋘ x x' (⋙p (⋗lf x₁)) ≃lf (⋗lf .x₁)) = inj₂ (≃nd x x' ≃lf ≃lf ≃lf) lemma-dropLast-⋘ (r⋘ _ _ (⋙p (⋗lf x₁)) l'≃r' (⋗nd .x₁ _ _ _ ())) lemma-dropLast-⋘ (r⋘ _ _ (⋙p (⋗nd x₁ _ ≃lf _ ())) ≃lf (⋗lf .x₁)) lemma-dropLast-⋘ (r⋘ x x' (⋙p (⋗nd x₁ x₂ l₁≃r₁ l₂≃r₂ l₁⋗l₂)) l'≃r' (⋗nd .x₁ x'₁ _ l'₁≃r'₁ l₁⋗l'₁)) = let dl-x₁l₁r₁⋘x₂l₂r₂ = lemma-dropLast-⋗ (⋗nd x₁ x₂ l₁≃r₁ l₂≃r₂ l₁⋗l₂) compound ; l₂≃l'₁ = lemma-⋗* l₁⋗l₂ l₁⋗l'₁ in inj₁ (l⋘ x x' dl-x₁l₁r₁⋘x₂l₂r₂ l'≃r' (≃nd x₂ x'₁ l₂≃r₂ l'₁≃r'₁ l₂≃l'₁)) lemma-dropLast-⋘ (r⋘ _ _ (⋙l x₁ _ ≃lf _ ()) ≃lf (⋗lf .x₁)) lemma-dropLast-⋘ (r⋘ x x' (⋙l x₁ x₂ l₁≃r₁ l₂⋘r₂ l₁⋗r₂) l'≃r' (⋗nd .x₁ x'₁ _ l'₁≃r'₁ l₁⋗l'₁)) with lemma-dropLast-⋙ (⋙l x₁ x₂ l₁≃r₁ l₂⋘r₂ l₁⋗r₂) ... | inj₁ dl-x₁l₁r₁⋘x₂l₂r₂ = inj₁ (r⋘ x x' dl-x₁l₁r₁⋘x₂l₂r₂ l'≃r' (⋗nd x₁ x'₁ l₁≃r₁ l'₁≃r'₁ l₁⋗l'₁)) ... | inj₂ () lemma-dropLast-⋘ (r⋘ x x' (⋙r x₁ x₂ ≃lf (⋙p ()) ≃lf) ≃lf (⋗lf .x₁)) lemma-dropLast-⋘ (r⋘ _ _ (⋙r x₁ _ ≃lf (⋙l _ _ _ _ _) ()) ≃lf (⋗lf .x₁)) lemma-dropLast-⋘ (r⋘ _ _ (⋙r x₁ _ ≃lf (⋙r _ _ _ _ _) ()) ≃lf (⋗lf .x₁)) lemma-dropLast-⋘ (r⋘ x x' (⋙r x₁ x₂ l₁≃r₁ l₂⋙r₂ l₁≃l₂) l'≃r' (⋗nd .x₁ x'₁ _ l'₁≃r'₁ l₁⋗l'₁)) with lemma-dropLast-⋙ (⋙r x₁ x₂ l₁≃r₁ l₂⋙r₂ l₁≃l₂) ... | inj₁ dl-x₁l₁r₁⋘x₂l₂r₂ = inj₁ (r⋘ x x' dl-x₁l₁r₁⋘x₂l₂r₂ l'≃r' (⋗nd x₁ x'₁ l₁≃r₁ l'₁≃r'₁ l₁⋗l'₁)) ... | inj₂ () lemma-dropLast-⋙ : {l r : PLRTree} → l ⋙ r → l ⋙ dropLast r ∨ l ⋗ r lemma-dropLast-⋙ (⋙p l⋗r) = inj₂ l⋗r lemma-dropLast-⋙ (⋙l x x' l≃r (x⋘ x'₁ x'₂ x'₃) (⋗nd x₁ .x'₃ l₁≃r₁ ≃lf l₁⋗x'₂)) = inj₁ (⋙p (⋗nd x x' l≃r (≃nd x'₁ x'₃ ≃lf ≃lf ≃lf) (⋗nd x₁ x'₁ l₁≃r₁ ≃lf l₁⋗x'₂))) lemma-dropLast-⋙ (⋙l x x' l≃r (l⋘ {l'₁} {r'₁} x'₁ x'₂ l'₁⋘r'₁ l'₂≃r'₂ r'₁≃l'₂) (⋗nd x₁ .x'₂ l₁≃r₁ _ l₁⋗l'₂)) with dropLast (node left x'₁ l'₁ r'₁) | lemma-dropLast-⋘ (l⋘ x'₁ x'₂ l'₁⋘r'₁ l'₂≃r'₂ r'₁≃l'₂) ... | leaf | inj₁ () ... | node perfect _ _ _ | inj₁ () ... | node left _ _ _ | inj₁ dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ = inj₁ (⋙l x x' l≃r dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ (⋗nd x₁ x'₂ l₁≃r₁ l'₂≃r'₂ l₁⋗l'₂)) ... | node right _ _ _ | inj₁ dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ = inj₁ (⋙l x x' l≃r dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ (⋗nd x₁ x'₂ l₁≃r₁ l'₂≃r'₂ l₁⋗l'₂)) ... | leaf | inj₂ () ... | node perfect x'' l'' r'' | inj₂ (≃nd .x'' .x'₂ l''≃r'' _ l''≃l'₂) = let l₁⋗l'' = lemma-⋗-≃ l₁⋗l'₂ (sym≃ l''≃l'₂) in inj₁ (⋙p (⋗nd x x' l≃r (≃nd x'' x'₂ l''≃r'' l'₂≃r'₂ l''≃l'₂) (⋗nd x₁ x'' l₁≃r₁ l''≃r'' l₁⋗l''))) ... | node left _ _ _ | inj₂ () ... | node right _ _ _ | inj₂ () lemma-dropLast-⋙ (⋙l x x' l≃r (r⋘ {l'₁} {r'₁} x'₁ x'₂ l'₁⋙r'₁ l'₂≃r'₂ l'₁⋗l'₂) (⋗nd x₁ .x'₂ l₁≃r₁ _ l₁⋗l'₂)) with dropLast (node right x'₁ l'₁ r'₁) | lemma-dropLast-⋘ (r⋘ x'₁ x'₂ l'₁⋙r'₁ l'₂≃r'₂ l'₁⋗l'₂) ... | leaf | inj₁ () ... | node perfect _ _ _ | inj₁ () ... | node left _ _ _ | inj₁ dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ = inj₁ (⋙l x x' l≃r dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ (⋗nd x₁ x'₂ l₁≃r₁ l'₂≃r'₂ l₁⋗l'₂)) ... | node right _ _ _ | inj₁ dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ = inj₁ (⋙l x x' l≃r dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ (⋗nd x₁ x'₂ l₁≃r₁ l'₂≃r'₂ l₁⋗l'₂)) ... | leaf | inj₂ () ... | node perfect x'' l'' r'' | inj₂ (≃nd .x'' .x'₂ l''≃r'' _ l''≃l'₂) = let l₁⋗l'' = lemma-⋗-≃ l₁⋗l'₂ (sym≃ l''≃l'₂) in inj₁ (⋙p (⋗nd x x' l≃r (≃nd x'' x'₂ l''≃r'' l'₂≃r'₂ l''≃l'₂) (⋗nd x₁ x'' l₁≃r₁ l''≃r'' l₁⋗l''))) ... | node left _ _ _ | inj₂ () ... | node right _ _ _ | inj₂ () lemma-dropLast-⋙ (⋙r x x' l≃r (⋙p ()) ≃lf) lemma-dropLast-⋙ (⋙r x x' l≃r (⋙p (⋗lf x'₁)) (≃nd x₁ .x'₁ ≃lf ≃lf ≃lf)) = inj₁ (⋙p (⋗nd x x' l≃r ≃lf (⋗lf x₁))) lemma-dropLast-⋙ (⋙r x x' l≃r (⋙p (⋗nd x'₁ x'₂ l'₁≃r'₁ l'₂≃r'₂ l'₁⋗l'₂)) (≃nd x₁ .x'₁ l₁≃r₁ _ l₁≃l'₁)) = let dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ = lemma-dropLast-⋗ (⋗nd x'₁ x'₂ l'₁≃r'₁ l'₂≃r'₂ l'₁⋗l'₂) compound ; l₁⋗l'₂ = lemma-≃-⋗ (sym≃ l₁≃l'₁) l'₁⋗l'₂ in inj₁ (⋙l x x' l≃r dl-x'₁l'₁r'₁⋘x'₂l'₂r'₂ (⋗nd x₁ x'₂ l₁≃r₁ l'₂≃r'₂ l₁⋗l'₂)) lemma-dropLast-⋙ (⋙r x x' l≃r (⋙l x'₁ x'₂ l'₁≃r'₁ l'₂⋘r'₂ l'₁⋗r'₂) (≃nd x₁ .x'₁ l₁≃r₁ _ l₁≃l'₁)) with lemma-dropLast-⋙ (⋙l x'₁ x'₂ l'₁≃r'₁ l'₂⋘r'₂ l'₁⋗r'₂) ... | inj₁ x'₁l'₁r'₁⋙dl-x'₂l'₂r'₂ = inj₁ (⋙r x x' l≃r x'₁l'₁r'₁⋙dl-x'₂l'₂r'₂ (≃nd x₁ x'₁ l₁≃r₁ l'₁≃r'₁ l₁≃l'₁)) ... | inj₂ () lemma-dropLast-⋙ (⋙r x x' l≃r (⋙r x'₁ x'₂ l'₁≃r'₁ l'₂⋙r'₂ l'₁≃l'₂) (≃nd x₁ .x'₁ l₁≃r₁ _ l₁≃l'₁)) with lemma-dropLast-⋙ (⋙r x'₁ x'₂ l'₁≃r'₁ l'₂⋙r'₂ l'₁≃l'₂) ... | inj₁ x'₁l'₁r'₁⋙dl-x'₂l'₂r'₂ = inj₁ (⋙r x x' l≃r x'₁l'₁r'₁⋙dl-x'₂l'₂r'₂ (≃nd x₁ x'₁ l₁≃r₁ l'₁≃r'₁ l₁≃l'₁)) ... | inj₂ () lemma-dropLast-complete : {t : PLRTree} → Complete t → Complete (dropLast t) lemma-dropLast-complete leaf = leaf lemma-dropLast-complete (perfect {l} {r} x cl cr l≃r) with l | r | l≃r ... | leaf | leaf | ≃lf = leaf ... | node perfect x' l' r' | node perfect x'' l'' r'' | ≃nd .x' .x'' l'≃r' l''≃r'' l'≃l'' = right x cl (lemma-dropLast-complete cr) (lemma-dropLast-≃ (≃nd x' x'' l'≃r' l''≃r'' l'≃l'') compound) lemma-dropLast-complete (left {l} {r} x cl cr l⋘r) with l | r | l⋘r | lemma-dropLast-⋘ l⋘r ... | leaf | _ | () | _ ... | node perfect x' l' r' | _ | () | _ ... | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₁ ld⋘r with dropLast (node left x' l' r') | ld⋘r | lemma-dropLast-complete cl ... | leaf | () | _ ... | node perfect _ _ _ | () | _ ... | node left x''' l''' r''' | ld⋘r' | cld = left x cld cr ld⋘r' ... | node right x''' l''' r''' | ld⋘r' | cld = left x cld cr ld⋘r' lemma-dropLast-complete (left x cl cr l⋘r) | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₂ ld≃r with dropLast (node left x' l' r') | ld≃r | lemma-dropLast-complete cl ... | leaf | () | _ ... | node perfect x''' l''' r''' | ld≃r' | cld = perfect x cld cr ld≃r' ... | node left _ _ _ | () | _ ... | node right _ _ _ | () | _ lemma-dropLast-complete (left x cl cr l⋘r) | node right x' l' r' | leaf | () | _ lemma-dropLast-complete (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₁ () lemma-dropLast-complete (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₂ x'≃x''' = perfect x (perfect x' leaf leaf ≃lf) cr x'≃x''' lemma-dropLast-complete (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₁ ld⋘r with dropLast (node right x' l' r') | ld⋘r | lemma-dropLast-complete cl ... | leaf | () | _ ... | node perfect _ _ _ | () | _ ... | node left x''' l''' r''' | ld⋘r' | cld = left x cld cr ld⋘r' ... | node right x''' l''' r''' | ld⋘r' | cld = left x cld cr ld⋘r' lemma-dropLast-complete (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₂ ld≃r with dropLast (node right x' l' r') | ld≃r | lemma-dropLast-complete cl ... | leaf | () | _ ... | node perfect x''' l''' r''' | ld≃r' | cld = perfect x cld cr ld≃r' ... | node left _ _ _ | () | _ ... | node right _ _ _ | () | _ lemma-dropLast-complete (left x cl cr l⋘r) | node right x' l' r' | node left x'' l'' r'' | () | _ lemma-dropLast-complete (left x cl cr l⋘r) | node right x' l' r' | node right x'' l'' r'' | () | _ lemma-dropLast-complete (right {l} {r} x cl cr l⋙r) with l | r | l⋙r ... | leaf | _ | ⋙p () ... | node perfect x' leaf leaf | leaf | ⋙p (⋗lf .x') = perfect x leaf leaf ≃lf ... | node perfect x' leaf leaf | node left _ _ _ | ⋙p () ... | node perfect x' leaf leaf | node right _ _ _ | ⋙p () ... | node perfect x' l' r' | node perfect x'' l'' r'' | ⋙p (⋗nd .x' .x'' l'≃r' l''≃r'' l'⋗l'') = left x (lemma-dropLast-complete cl) cr (lemma-dropLast-⋗ (⋗nd x' x'' l'≃r' l''≃r'' l'⋗l'') compound) ... | node perfect x' l' r' | node left x'' l'' r'' | ⋙l .x' .x'' l'≃r' l''⋘r'' l'⋗r'' with lemma-dropLast-⋙ (⋙l x' x'' l'≃r' l''⋘r'' l'⋗r'') ... | inj₁ l⋙rd = right x cl (lemma-dropLast-complete cr) l⋙rd ... | inj₂ () lemma-dropLast-complete (right x cl cr l⋙r) | node perfect x' l' r' | node right x'' l'' r'' | ⋙r .x' .x'' l'≃r' l''⋙r'' l'≃l'' with lemma-dropLast-⋙ (⋙r x' x'' l'≃r' l''⋙r'' l'≃l'') ... | inj₁ l⋙rd = right x cl (lemma-dropLast-complete cr) l⋙rd ... | inj₂ () lemma-dropLast-complete (right x cl cr l⋙r) | node left _ _ _ | _ | ⋙p () lemma-dropLast-complete (right x cl cr l⋙r) | node right _ _ _ | _ | ⋙p ()
{ "alphanum_fraction": 0.5107594407, "avg_line_length": 67.095505618, "ext": "agda", "hexsha": "c3126bec36ee06d0d9dcd493888e4bee38f25398", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/PLRTree/DropLast/Complete.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_path": "agda/PLRTree/DropLast/Complete.agda", "max_line_length": 198, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/PLRTree/DropLast/Complete.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 6931, "size": 11943 }
module Direction where open import Relation.Binary.PropositionalEquality hiding (Extensionality) ---------------------------------------------------------------------- -- direction data Dir : Set where SND RCV : Dir variable d d₁ d₂ d₃ : Dir -- dual dual-dir : Dir → Dir dual-dir SND = RCV dual-dir RCV = SND dual-dir-inv : (d : Dir) → dual-dir (dual-dir d) ≡ d dual-dir-inv SND = refl dual-dir-inv RCV = refl
{ "alphanum_fraction": 0.5771971496, "avg_line_length": 18.3043478261, "ext": "agda", "hexsha": "ed29bc18eaecbe785f8f4e27ff5296870d3ebf0b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "kcaliban/dual-session", "max_forks_repo_path": "src/Direction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "kcaliban/dual-session", "max_issues_repo_path": "src/Direction.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "kcaliban/dual-session", "max_stars_repo_path": "src/Direction.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 115, "size": 421 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Setoids.Setoids open import Groups.Definition open import Groups.Abelian.Definition module Groups.Abelian.DirectSum {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {_+1_ : A → A → A} {_+2_ : B → B → B} {G1' : Group S _+1_} {G2' : Group T _+2_} (G1 : AbelianGroup G1') (G2 : AbelianGroup G2') where open import Groups.DirectSum.Definition G1' G2' open import Setoids.Product S T directSumAbGroup : AbelianGroup directSumGroup AbelianGroup.commutative directSumAbGroup = productLift (AbelianGroup.commutative G1) (AbelianGroup.commutative G2)
{ "alphanum_fraction": 0.7065217391, "avg_line_length": 46, "ext": "agda", "hexsha": "79fb13e64b017391aef7c6f89a641a48f504216e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Groups/Abelian/DirectSum.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Groups/Abelian/DirectSum.agda", "max_line_length": 249, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Groups/Abelian/DirectSum.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 222, "size": 644 }
open import Nat open import Prelude open import contexts open import core module canonical-value-forms where canonical-value-forms-b : ∀{Δ d} → Δ , ∅ ⊢ d :: b → d val → d == c canonical-value-forms-b TAConst VConst = refl canonical-value-forms-b (TAVar x₁) () canonical-value-forms-b (TAAp wt wt₁) () canonical-value-forms-b (TAEHole x x₁) () canonical-value-forms-b (TANEHole x wt x₁) () canonical-value-forms-b (TACast wt x) () canonical-value-forms-b (TAFailedCast wt x x₁ x₂) () canonical-value-forms-arr : ∀{Δ d τ1 τ2} → Δ , ∅ ⊢ d :: (τ1 ==> τ2) → d val → Σ[ x ∈ Nat ] Σ[ d' ∈ ihexp ] ((d == (·λ x [ τ1 ] d')) × (Δ , ■ (x , τ1) ⊢ d' :: τ2)) canonical-value-forms-arr (TAVar x₁) () canonical-value-forms-arr (TALam _ wt) VLam = _ , _ , refl , wt canonical-value-forms-arr (TAAp wt wt₁) () canonical-value-forms-arr (TAEHole x x₁) () canonical-value-forms-arr (TANEHole x wt x₁) () canonical-value-forms-arr (TACast wt x) () canonical-value-forms-arr (TAFailedCast x x₁ x₂ x₃) () -- this argues (somewhat informally, because you still have to inspect -- the types of the theorems above and manually verify this property) -- that we didn't miss any cases above; this intentionally will make this -- file fail to typecheck if we added more types, hopefully forcing us to -- remember to add canonical forms lemmas as appropriate canonical-value-forms-coverage1 : ∀{Δ d τ} → Δ , ∅ ⊢ d :: τ → d val → τ ≠ b → ((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) → ⊥ canonical-value-forms-coverage1 TAConst VConst = λ z _ → z refl canonical-value-forms-coverage1 (TAVar x₁) () canonical-value-forms-coverage1 (TALam _ wt) VLam = λ _ z → z _ _ refl canonical-value-forms-coverage1 (TAAp wt wt₁) () canonical-value-forms-coverage1 (TAEHole x x₁) () canonical-value-forms-coverage1 (TANEHole x wt x₁) () canonical-value-forms-coverage1 (TACast wt x) () canonical-value-forms-coverage1 (TAFailedCast wt x x₁ x₂) () canonical-value-forms-coverage2 : ∀{Δ d} → Δ , ∅ ⊢ d :: ⦇-⦈ → d val → ⊥ canonical-value-forms-coverage2 (TAVar x₁) () canonical-value-forms-coverage2 (TAAp wt wt₁) () canonical-value-forms-coverage2 (TAEHole x x₁) () canonical-value-forms-coverage2 (TANEHole x wt x₁) () canonical-value-forms-coverage2 (TACast wt x) () canonical-value-forms-coverage2 (TAFailedCast wt x x₁ x₂) ()
{ "alphanum_fraction": 0.5505735141, "avg_line_length": 45.6666666667, "ext": "agda", "hexsha": "1df293a9034f351e3b1264e0b97cddd4f43f9820", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_path": "canonical-value-forms.agda", "max_issues_count": 54, "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_path": "canonical-value-forms.agda", "max_line_length": 80, "max_stars_count": 16, "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_path": "canonical-value-forms.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "num_tokens": 845, "size": 2877 }
{-# OPTIONS --cubical #-} open import Agda.Builtin.Equality data Unit : Set where unit : Unit f : (x : Unit) → _ -- x ≡ x g : (x : Unit) → x ≡ x f unit = refl g x = f x
{ "alphanum_fraction": 0.5542857143, "avg_line_length": 13.4615384615, "ext": "agda", "hexsha": "73a178c31527a4f6894a45165178773a13b98755", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue4899.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue4899.agda", "max_line_length": 33, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue4899.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 66, "size": 175 }
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 } --
{ "alphanum_fraction": 0.5218285714, "avg_line_length": 33.1439393939, "ext": "agda", "hexsha": "dfbeb944bc5d024a81e45893eeb7087b03e2acdf", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shinji-kono/zf-in-agda", "max_forks_repo_path": "src/generic-filter.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "shinji-kono/zf-in-agda", "max_issues_repo_path": "src/generic-filter.agda", "max_line_length": 143, "max_stars_count": 5, "max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shinji-kono/zf-in-agda", "max_stars_repo_path": "src/generic-filter.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z", "num_tokens": 3777, "size": 8750 }
-- Andreas, 2015-07-13 Better parse errors for illegal type signatures A with B : Set
{ "alphanum_fraction": 0.7386363636, "avg_line_length": 22, "ext": "agda", "hexsha": "284000f61e707cbf6c7e80be43f2cd8be487de79", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue1609d.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue1609d.agda", "max_line_length": 71, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue1609d.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 25, "size": 88 }
-- You are not allowed to export the same name twice from a -- module. However, if the name is only exported once, ambiguity -- is allowed. module Issue154 where module A where postulate X : Set module B where postulate X : Set module C where open A public -- X is ambiguous here, but only exported once from C module D where private postulate X : Set open A public -- same here module E where postulate X : Set open A -- and here module F where open A public open D public -- in this case there is no ambiguity, A.X and D.X refer -- to the same entity (A.X) module G where open B public module H where open G public open B public -- same as F but for modules postulate test : A.X → B.X → B.C.X → D.X → E.X → F.X → G.X → H.X
{ "alphanum_fraction": 0.6696658098, "avg_line_length": 18.5238095238, "ext": "agda", "hexsha": "adbf4eae2923efb035e72b65752e5705f3609d0b", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue154.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue154.agda", "max_line_length": 64, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue154.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 230, "size": 778 }
{-# OPTIONS --safe #-} module Cubical.Algebra.NatSolver.NatExpression where open import Cubical.Foundations.Prelude open import Cubical.Data.FinData open import Cubical.Data.Nat open import Cubical.Data.Nat.Order using (zero-≤) open import Cubical.Data.Vec.Base infixl 6 _+'_ infixl 7 _·'_ -- Expression in a ring on A with n variables data Expr (n : ℕ) : Type ℓ-zero where K : ℕ → Expr n ∣ : Fin n → Expr n _+'_ : Expr n → Expr n → Expr n _·'_ : Expr n → Expr n → Expr n module Eval where open import Cubical.Data.Vec ⟦_⟧ : ∀ {n} → Expr n → Vec ℕ n → ℕ ⟦ K r ⟧ v = r ⟦ ∣ k ⟧ v = lookup k v ⟦ x +' y ⟧ v = ⟦ x ⟧ v + ⟦ y ⟧ v ⟦ x ·' y ⟧ v = ⟦ x ⟧ v · ⟦ y ⟧ v
{ "alphanum_fraction": 0.6096491228, "avg_line_length": 23.5862068966, "ext": "agda", "hexsha": "7c9e4edd58349bedcf15320d2536d395a371b5af", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Seanpm2001-web/cubical", "max_forks_repo_path": "Cubical/Algebra/NatSolver/NatExpression.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Seanpm2001-web/cubical", "max_issues_repo_path": "Cubical/Algebra/NatSolver/NatExpression.agda", "max_line_length": 52, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FernandoLarrain/cubical", "max_stars_repo_path": "Cubical/Algebra/NatSolver/NatExpression.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z", "num_tokens": 265, "size": 684 }
{-# OPTIONS --safe #-} module Cubical.Relation.Nullary.DecidableEq where open import Cubical.Relation.Nullary.Properties using (Dec→Stable; Discrete→isSet) public
{ "alphanum_fraction": 0.7831325301, "avg_line_length": 27.6666666667, "ext": "agda", "hexsha": "7c66fe00a606a5a1430f63b1e16de93f127ae7c6", "lang": "Agda", "max_forks_count": 134, "max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z", "max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "marcinjangrzybowski/cubical", "max_forks_repo_path": "Cubical/Relation/Nullary/DecidableEq.agda", "max_issues_count": 584, "max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "marcinjangrzybowski/cubical", "max_issues_repo_path": "Cubical/Relation/Nullary/DecidableEq.agda", "max_line_length": 49, "max_stars_count": 301, "max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "marcinjangrzybowski/cubical", "max_stars_repo_path": "Cubical/Relation/Nullary/DecidableEq.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z", "num_tokens": 43, "size": 166 }
module Listy where open import Measure open import Data.List as List using (List; []; _∷_) open import Data.Product using (_,_; _×_; proj₁; proj₂) open import Data.Nat as ℕ using (ℕ; suc; zero) open import Function record Prob (A : Set) : Set where constructor weighted field runProb : List (A × ℙ) open Prob open import Category.Monad monad : RawMonad Prob monad = record { return = λ x → weighted ((x , fromNat 1) ∷ []) ; _>>=_ = bind } where import Data.List.Categorical open RawMonad Data.List.Categorical.monad bind : {A B : Set} → Prob A → (A → Prob B) → Prob B bind xs f = weighted do (x , xp) ← runProb xs (y , yp) ← runProb (f x) return (y , xp * yp) support : {A : Set} → Prob A → List A support = List.map proj₁ ∘ runProb expect : {A : Set} → (A → ℙ) → Prob A → ℙ expect p = List.foldl (λ ys y → ys + (p (proj₁ y) * (proj₂ y)) ) (fromNat 0) ∘ runProb open import Data.Bool using (Bool; if_then_else_) probOf : {A : Set} → (A → Bool) → Prob A → ℙ probOf p = expect (λ x → if p x then fromNat 1 else fromNat 0) uniform : {A : Set} → List A → Prob A uniform [] = weighted [] uniform (x ∷ xs) = weighted (List.map (flip _,_ p) (x ∷ xs)) where p : ℙ p = 1 ?÷ (suc (List.length xs)) open import Data.Fin as Fin using (Fin) enumerate : (n : ℕ) → List (Fin n) enumerate zero = [] enumerate (suc n) = Fin.zero ∷ List.map Fin.suc (enumerate n) module Die where die : Prob (Fin 6) die = uniform (enumerate 6) open RawMonad monad pairadice : Prob ℕ pairadice = do x ← die y ← die return (suc (Fin.toℕ x) ℕ.+ suc (Fin.toℕ y)) open import Data.String using (String) open import Relation.Nullary.Decidable using (⌊_⌋) example : String example = show (probOf (λ x → ⌊ x ℕ.≟ 7 ⌋) Die.pairadice)
{ "alphanum_fraction": 0.6242969629, "avg_line_length": 24.027027027, "ext": "agda", "hexsha": "c5e04b557d286db9b83119f96cf1a2cb4ace1bef", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "880217ca51ab62f6feee58ccacdb39bfade43101", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/prob-presentation", "max_forks_repo_path": "probability/Listy.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "880217ca51ab62f6feee58ccacdb39bfade43101", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/prob-presentation", "max_issues_repo_path": "probability/Listy.agda", "max_line_length": 86, "max_stars_count": null, "max_stars_repo_head_hexsha": "880217ca51ab62f6feee58ccacdb39bfade43101", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/prob-presentation", "max_stars_repo_path": "probability/Listy.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 616, "size": 1778 }
open import FRP.JS.Behaviour using ( Beh ; [_] ) open import FRP.JS.DOM using ( DOM ; text ) open import FRP.JS.RSet using ( ⟦_⟧ ) module FRP.JS.Demo.Hello where main : ∀ {w} → ⟦ Beh (DOM w) ⟧ main = text ["Hello, world."]
{ "alphanum_fraction": 0.6355555556, "avg_line_length": 25, "ext": "agda", "hexsha": "d5eba85b318e2e50bf001dda3f9658acc13e151f", "lang": "Agda", "max_forks_count": 7, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z", "max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z", "max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_forks_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_forks_repo_name": "agda/agda-frp-js", "max_forks_repo_path": "demo/agda/FRP/JS/Demo/Hello.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_issues_repo_name": "agda/agda-frp-js", "max_issues_repo_path": "demo/agda/FRP/JS/Demo/Hello.agda", "max_line_length": 48, "max_stars_count": 63, "max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_stars_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_stars_repo_name": "agda/agda-frp-js", "max_stars_repo_path": "demo/agda/FRP/JS/Demo/Hello.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z", "num_tokens": 81, "size": 225 }
module Luau.TypeSaturation where open import Luau.Type using (Type; _⇒_; _∩_; _∪_) open import Luau.TypeNormalization using (_∪ⁿ_; _∩ⁿ_) -- So, there's a problem with overloaded functions -- (of the form (S_1 ⇒ T_1) ∩⋯∩ (S_n ⇒ T_n)) -- which is that it's not good enough to compare them -- for subtyping by comparing all of their overloads. -- For example (nil → nil) is a subtype of (number? → number?) ∩ (string? → string?) -- but not a subtype of any of its overloads. -- To fix this, we adapt the semantic subtyping algorithm for -- function types, given in -- https://www.irif.fr/~gc/papers/covcon-again.pdf and -- https://pnwamk.github.io/sst-tutorial/ -- A function type is *intersection-saturated* if for any overloads -- (S₁ ⇒ T₁) and (S₂ ⇒ T₂), there exists an overload which is a subtype -- of ((S₁ ∩ S₂) ⇒ (T₁ ∩ T₂)). -- A function type is *union-saturated* if for any overloads -- (S₁ ⇒ T₁) and (S₂ ⇒ T₂), there exists an overload which is a subtype -- of ((S₁ ∪ S₂) ⇒ (T₁ ∪ T₂)). -- A function type is *saturated* if it is both intersection- and -- union-saturated. -- For example (number? → number?) ∩ (string? → string?) -- is not saturated, but (number? → number?) ∩ (string? → string?) ∩ (nil → nil) ∩ ((number ∪ string)? → (number ∪ string)?) -- is. -- Saturated function types have the nice property that they can ber -- compared by just comparing their overloads: F <: G whenever for any -- overload of G, there is an overload os F which is a subtype of it. -- Forunately every function type can be saturated! _⋓_ : Type → Type → Type (S₁ ⇒ T₁) ⋓ (S₂ ⇒ T₂) = (S₁ ∪ⁿ S₂) ⇒ (T₁ ∪ⁿ T₂) (F₁ ∩ G₁) ⋓ F₂ = (F₁ ⋓ F₂) ∩ (G₁ ⋓ F₂) F₁ ⋓ (F₂ ∩ G₂) = (F₁ ⋓ F₂) ∩ (F₁ ⋓ G₂) F ⋓ G = F ∩ G _⋒_ : Type → Type → Type (S₁ ⇒ T₁) ⋒ (S₂ ⇒ T₂) = (S₁ ∩ⁿ S₂) ⇒ (T₁ ∩ⁿ T₂) (F₁ ∩ G₁) ⋒ F₂ = (F₁ ⋒ F₂) ∩ (G₁ ⋒ F₂) F₁ ⋒ (F₂ ∩ G₂) = (F₁ ⋒ F₂) ∩ (F₁ ⋒ G₂) F ⋒ G = F ∩ G _∩ᵘ_ : Type → Type → Type F ∩ᵘ G = (F ∩ G) ∩ (F ⋓ G) _∩ⁱ_ : Type → Type → Type F ∩ⁱ G = (F ∩ G) ∩ (F ⋒ G) ∪-saturate : Type → Type ∪-saturate (F ∩ G) = (∪-saturate F ∩ᵘ ∪-saturate G) ∪-saturate F = F ∩-saturate : Type → Type ∩-saturate (F ∩ G) = (∩-saturate F ∩ⁱ ∩-saturate G) ∩-saturate F = F saturate : Type → Type saturate F = ∪-saturate (∩-saturate F)
{ "alphanum_fraction": 0.6153157188, "avg_line_length": 33.328358209, "ext": "agda", "hexsha": "fa24ff735bcc9913799ee26ca52f00c01079d375", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "39fbd2146a379fb0878369b48764cd7e8772c0fb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "sthagen/Roblox-luau", "max_forks_repo_path": "prototyping/Luau/TypeSaturation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "39fbd2146a379fb0878369b48764cd7e8772c0fb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "sthagen/Roblox-luau", "max_issues_repo_path": "prototyping/Luau/TypeSaturation.agda", "max_line_length": 124, "max_stars_count": 1, "max_stars_repo_head_hexsha": "f1b46f4b967f11fabe666da1de0e71b225368260", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Libertus-Lab/luau", "max_stars_repo_path": "prototyping/Luau/TypeSaturation.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-06T08:03:00.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-06T08:03:00.000Z", "num_tokens": 933, "size": 2233 }
module Base.Change.Products where open import Relation.Binary.PropositionalEquality open import Level open import Base.Change.Algebra open import Base.Change.Equivalence open import Base.Change.Equivalence.Realizers -- Also try defining sectioned change structures on the positives halves of -- groups? Or on arbitrary subsets? -- Restriction: we pair sets on the same level (because right now everything -- else would risk getting in the way). module ProductChanges ℓ {A B : Set ℓ} {{CA : ChangeAlgebra A}} {{CB : ChangeAlgebra B}} where -- Avoid having to specify A and B all the time; they'd often be ambiguous -- otherwise. import Data.Product as DP open DP.Σ {A = A} {B = λ _ → B} open DP using (_×_; _,_) -- The simplest possible definition of changes for products. PChange : A × B → Set ℓ PChange (a , b) = Δ a × Δ b -- An interesting alternative definition allows omitting the nil change of a -- component when that nil change can be computed from the type. For instance, the nil change for integers is always the same. -- However, the nil change for function isn't always the same (unless we -- defunctionalize them first), so nil changes for functions can't be omitted. _⊕_ : (v : A × B) → PChange v → A × B _⊕_ (a , b) (da , db) = a ⊞ da , b ⊞ db _⊝_ : A × B → (v : A × B) → PChange v _⊝_ (aNew , bNew) (a , b) = aNew ⊟ a , bNew ⊟ b p-nil : (v : A × B) → PChange v p-nil (a , b) = (nil a , nil b) p-update-diff : (u v : A × B) → v ⊕ (u ⊝ v) ≡ u p-update-diff (ua , ub) (va , vb) = let u = (ua , ub) v = (va , vb) in begin v ⊕ (u ⊝ v) ≡⟨⟩ (va ⊞ (ua ⊟ va) , vb ⊞ (ub ⊟ vb)) --v ⊕ ((ua ⊟ va , ub ⊟ vb)) ≡⟨ cong₂ _,_ (update-diff ua va) (update-diff ub vb)⟩ (ua , ub) ≡⟨⟩ u ∎ where open ≡-Reasoning p-update-nil : (v : A × B) → v ⊕ (p-nil v) ≡ v p-update-nil (a , b) = let v = (a , b) in begin v ⊕ (p-nil v) ≡⟨⟩ (a ⊞ nil a , b ⊞ nil b) ≡⟨ cong₂ _,_ (update-nil a) (update-nil b)⟩ (a , b) ≡⟨⟩ v ∎ where open ≡-Reasoning instance changeAlgebraProducts : ChangeAlgebra (A × B) changeAlgebraProducts = record { Change = PChange ; update = _⊕_ ; diff = _⊝_ ; nil = p-nil ; isChangeAlgebra = record { update-diff = p-update-diff ; update-nil = p-update-nil } } -- -- Derivatives of introductions and elimination forms for products. -- -- For each one define a naive derivative using nil, write a hand-optimized *realizer* for an efficient derivative, and prove they're equivalent. -- proj₁′ : Δ proj₁ proj₁′ = nil proj₁ proj₁′-realizer : (v : A × B) → Δ v → Δ (proj₁ v) proj₁′-realizer (a , b) (da , db) = da proj₁′-realizer-correct : ∀ (p : A × B) (dp : Δ p) → apply proj₁′ p dp ≙₍ proj₁ p ₎ proj₁′-realizer p dp proj₁′-realizer-correct (a , b) (da , db) = diff-update {x = a} {dx = da} proj₁′Derivative : IsDerivative proj₁ proj₁′-realizer -- Implementation note: we do not need to pattern match on v and dv because -- they are records, hence Agda knows that pattern matching on records cannot -- fail. Technically, the required feature is the eta-rule on records. proj₁′Derivative v dv = refl -- An extended explanation. proj₁′Derivative₁ : IsDerivative proj₁ proj₁′-realizer proj₁′Derivative₁ (a , b) (da , db) = let v = (a , b) dv = (da , db) in begin proj₁ v ⊞ proj₁′-realizer v dv ≡⟨⟩ a ⊞ da ≡⟨⟩ proj₁ (v ⊞ dv) ∎ where open ≡-Reasoning proj₁′-faster-w-proof : equiv-raw-change-to-change-ResType proj₁ proj₁′-realizer proj₁′-faster-w-proof = equiv-raw-change-to-change proj₁ proj₁′ proj₁′-realizer proj₁′-realizer-correct proj₁′-faster : Δ proj₁ proj₁′-faster = DP.proj₁ proj₁′-faster-w-proof -- Same for the second extractor. proj₂′-realizer : (v : A × B) → Δ v → Δ (proj₂ v) proj₂′-realizer (a , b) (da , db) = db proj₂′ : Δ proj₂ proj₂′ = nil proj₂ proj₂′-realizer-correct : ∀ p (dp : Δ p) → apply proj₂′ p dp ≙₍ proj₂ p ₎ proj₂′-realizer p dp proj₂′-realizer-correct (a , b) (da , db) = diff-update proj₂′Derivative : IsDerivative proj₂ proj₂′-realizer proj₂′Derivative v dv = refl proj₂′-faster-w-proof : equiv-raw-change-to-change-ResType proj₂ proj₂′-realizer proj₂′-faster-w-proof = equiv-raw-change-to-change proj₂ proj₂′ proj₂′-realizer proj₂′-realizer-correct proj₂′-faster : Δ proj₂ proj₂′-faster = DP.proj₁ proj₂′-faster-w-proof -- Morally, the following is a change: -- What one could wrongly expect to be the derivative of the constructor: _,_′-realizer : (a : A) → (da : Δ a) → (b : B) → (db : Δ b) → Δ (a , b) _,_′-realizer a da b db = da , db -- That has the correct behavior, in a sense, and it would be in the -- subset-based formalization in the paper. -- -- But the above is not even a change, because it does not contain a proof of -- its own validity, and because after application it does not contain a -- proof. -- -- However, the above is (morally) a "realizer" of the actual change, since it -- only represents its computational behavior, not its proof manipulation. -- Hence, we need to do some additional work. _,_′ : Δ (_,_ {A = A} {B = λ _ → B}) _,_′ = _,_ ⊟ _,_ _,_′-realizer-correct : ∀ a da b db → apply (apply _,_′ a da) b db ≙₍ a , b ₎ _,_′-realizer a da b db _,_′-realizer-correct a da b db = doe (≙-cong₂ _,_ diff-update diff-update) open import Data.Product using (Σ-syntax) _,_′-faster-w-proof : equiv-raw-change-to-change-binary-ResType _,_ _,_′-realizer _,_′-faster-w-proof = equiv-raw-change-to-change-binary _,_ _,_′ _,_′-realizer _,_′-realizer-correct _,_′-faster : Δ (_,_ {A = A} {B = λ _ → B}) _,_′-faster = DP.proj₁ _,_′-faster-w-proof -- Define specialized variant of uncurry, and derive it. uncurry₀ : ∀ {C : Set ℓ} → (A → B → C) → A × B → C uncurry₀ f (a , b) = f a b module _ {C : Set ℓ} {{CC : ChangeAlgebra C}} where uncurry₀′ : Δ uncurry₀ uncurry₀′ = nil (uncurry₀ {C = C}) uncurry₀′-realizer : (f : A → B → C) → Δ f → (p : A × B) → Δ p → Δ (uncurry₀ f p) uncurry₀′-realizer f df (a , b) (da , db) = apply (apply df a da) b db uncurry₀′-realizer-correct : ∀ f df p dp → apply (apply uncurry₀′ f df) p dp ≙₍ uncurry₀ f p ₎ uncurry₀′-realizer f df p dp uncurry₀′-realizer-correct f df (a , b) (da , db) = begin (f ⊞ df) (a ⊞ da) (b ⊞ db) ⊟ f a b ≙⟨ equiv-cancel-2 _ _ (incrementalization-binary f df a da b db) ⟩ apply (apply df a da) b db ∎ where open ≙-Reasoning open BinaryFunctionChanges A B C uncurry₀′-faster-w-proof : equiv-raw-change-to-change-binary-ResType uncurry₀ uncurry₀′-realizer uncurry₀′-faster-w-proof = equiv-raw-change-to-change-binary uncurry₀ uncurry₀′ uncurry₀′-realizer uncurry₀′-realizer-correct uncurry₀′-faster : Δ uncurry₀ uncurry₀′-faster = DP.proj₁ uncurry₀′-faster-w-proof
{ "alphanum_fraction": 0.6135946975, "avg_line_length": 34.7598039216, "ext": "agda", "hexsha": "8dd83cef96b741928551f69456f64385e6f8af1d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Base/Change/Products.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Base/Change/Products.agda", "max_line_length": 147, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Base/Change/Products.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 2510, "size": 7091 }
-- This file gives the definition of Gaussian Integers, the addition -- and multiplication on them, and shows that they form a commutative -- ring, and other properties. All the proofs are straightforward. {-# OPTIONS --without-K --safe #-} module GauInt.Properties where -- imports from local. open import GauInt.Instances open import Instances open import GauInt.Base using (𝔾 ; _+_i ; _ᶜ ; Re ; Im ; _+0i ; _+0i' ; 0𝔾) open import Integer.Properties -- imports from stdlib and Agda. open import Level using (0ℓ) open import Relation.Nullary using (yes; no; ¬_) open import Relation.Binary using (DecidableEquality ; Setoid ; DecSetoid ; tri< ; tri≈ ; tri>) open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Data.Product using (proj₁; proj₂; _,_ ; _×_) open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) renaming ([_,_]′ to ⊎-elim) open import Data.Nat as Nat using (ℕ; suc; zero) import Data.Nat.Properties as NatP open import Data.Integer.Properties as IntP using (+-assoc ; +-identityˡ ; +-identityʳ ; *-identityˡ ; +-inverseˡ ; +-inverseʳ ; +-comm ; 0≤i⇒+∣i∣≡i ; +-mono-≤ ; +-mono-<-≤ ; +-mono-≤-<) open import Data.Integer as Int using (ℤ ; +_ ; NonNegative ; -[1+_] ; +[1+_] ; +≤+ ; +<+ ; ∣_∣ ; 0ℤ ; +0) import Data.Integer.Solver as IS open IS.+-*-Solver open import Algebra.Bundles as B import Algebra.Morphism as Morphism open import Algebra.Structures {A = 𝔾} _≡_ open import Function.Base using (_$_) module 𝔾toℕ = Morphism.Definitions 𝔾 ℕ _≡_ module ℕto𝔾 = Morphism.Definitions ℕ 𝔾 _≡_ open import Algebra.Definitions (_≡_ {A = 𝔾}) using (AlmostLeftCancellative) -- ---------------------------------------------------------------------- -- Equality -- Injections are injective. +0i'-injective : ∀ {a b} -> a +0i' ≡ b +0i' → a ≡ b +0i'-injective refl = refl +0i-injective : ∀ {m n} -> m +0i ≡ n +0i → m ≡ n +0i-injective refl = refl -- Decidable equality on 𝔾. infix 4 _≟_ _≟_ : DecidableEquality 𝔾 _≟_ x@(a + b i) y@(c + d i) with a Int.≟ c | b Int.≟ d ... | yes p | yes q = yes (cong₂ _+_i p q) ... | yes p | no ¬q = no (λ { refl → ¬q refl}) ... | no ¬p | hyp = no (λ { refl → ¬p refl}) ≡-setoid : Setoid 0ℓ 0ℓ ≡-setoid = setoid 𝔾 ≡-decSetoid : DecSetoid 0ℓ 0ℓ ≡-decSetoid = decSetoid _≟_ -- ---------------------------------------------------------------------- -- Properties of _+_ -- Associativity of addition. assoc-+ : ∀ (x y z : 𝔾) -> ((x + y) + z) ≡ (x + (y + z)) assoc-+ x@(a + b i) y@(c + d i) z@(e + f i) = begin (((a + b i) + (c + d i)) + (e + f i)) ≡⟨ refl ⟩ ((a + c + e) + (b + d + f) i) ≡⟨ cong₂ _+_i (+-assoc a c e) (+-assoc b d f) ⟩ ((a + (c + e)) + (b + (d + f)) i) ≡⟨ refl ⟩ (x + (y + z)) ∎ -- Left additive identity. leftId-+ : ∀ (x : 𝔾) -> 0# + x ≡ x leftId-+ x@(a + b i) = begin (0# + 0# i) + (a + b i) ≡⟨ refl ⟩ -- cannot parse if remove the outer layer parenthese. ((0# + a) + (0# + b) i) ≡⟨ cong₂ _+_i (+-identityˡ a) (+-identityˡ b) ⟩ (a + b i) ∎ -- Right additive identity. rightId-+ : ∀ (x : 𝔾) -> (x + 0#) ≡ x rightId-+ x@(a + b i) = begin (a + b i) + (0# + 0# i) ≡⟨ refl ⟩ ((a + 0#) + (b + 0#) i) ≡⟨ cong₂ _+_i (+-identityʳ a) (+-identityʳ b) ⟩ (a + b i) ∎ -- Left additive inverse. leftInv-+ : ∀ (x : 𝔾) -> (- x) + x ≡ 0# leftInv-+ x@(a + b i) = cong₂ _+_i (+-inverseˡ a) (+-inverseˡ b) -- Right additive inverse. rightInv-+ : ∀ (x : 𝔾) -> x + (- x) ≡ 0# rightInv-+ x@(a + b i) = cong₂ _+_i (+-inverseʳ a) (+-inverseʳ b) -- Addition is commutative. comm-+ : (x y : 𝔾) → (x + y) ≡ (y + x) comm-+ x@(a + b i) y@(c + d i) = cong₂ _+_i (+-comm a c) (+-comm b d) -- ---------------------------------------------------------------------- -- Structures for addition +-isMagma : IsMagma _+_ +-isMagma = record { isEquivalence = isEquivalence ; ∙-cong = cong₂ _+_ } +-isSemigroup : IsSemigroup _+_ +-isSemigroup = record { isMagma = +-isMagma ; assoc = assoc-+ } +-isCommutativeSemigroup : IsCommutativeSemigroup _+_ +-isCommutativeSemigroup = record { isSemigroup = +-isSemigroup ; comm = comm-+ } +-0-isMonoid : IsMonoid _+_ 0# +-0-isMonoid = record { isSemigroup = +-isSemigroup ; identity = leftId-+ , rightId-+ } +-0-isCommutativeMonoid : IsCommutativeMonoid _+_ 0# +-0-isCommutativeMonoid = record { isMonoid = +-0-isMonoid ; comm = comm-+ } +-0-isGroup : IsGroup _+_ 0# (-_) +-0-isGroup = record { isMonoid = +-0-isMonoid ; inverse = leftInv-+ , rightInv-+ ; ⁻¹-cong = cong (-_) } +-isAbelianGroup : IsAbelianGroup _+_ 0# (-_) +-isAbelianGroup = record { isGroup = +-0-isGroup ; comm = comm-+ } -- ---------------------------------------------------------------------- -- Bundles for addition +-magma : Magma 0ℓ 0ℓ +-magma = record { isMagma = +-isMagma } +-semigroup : Semigroup 0ℓ 0ℓ +-semigroup = record { isSemigroup = +-isSemigroup } +-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ +-commutativeSemigroup = record { isCommutativeSemigroup = +-isCommutativeSemigroup } +-0-monoid : Monoid 0ℓ 0ℓ +-0-monoid = record { isMonoid = +-0-isMonoid } +-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ +-0-commutativeMonoid = record { isCommutativeMonoid = +-0-isCommutativeMonoid } +-0-abelianGroup : AbelianGroup 0ℓ 0ℓ +-0-abelianGroup = record { isAbelianGroup = +-isAbelianGroup } -- ---------------------------------------------------------------------- -- Properties of multiplication -- Associativity of multiplication. assoc-* : ∀ (x y z : 𝔾) -> ((x * y) * z) ≡ (x * (y * z)) assoc-* x@(a + b i) y@(c + d i) z@(e + f i) = begin (((a + b i) * (c + d i)) * (e + f i)) ≡⟨ refl ⟩ ((a * c - b * d) + (a * d + b * c) i) * (e + f i) ≡⟨ refl ⟩ ((a * c - b * d) * e - (a * d + b * c) * f) + ((a * c - b * d) * f + (a * d + b * c) * e) i ≡⟨ cong₂ _+_i (let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> (((a * c) - (b * d)) * e) - (((a * d) + (b * c)) * f) := (a * ((c * e) - (d * f))) - (b * ((c * f) + (d * e)))) refl a b c d e f)) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> (((a * c) - (b * d)) * f) + (((a * d) + (b * c)) * e) := (a * ((c * f) + (d * e))) + (b * ((c * e) - (d * f)))) refl a b c d e f))) ⟩ ((a * (c * e - d * f) - b * (c * f + d * e) ) + (a * (c * f + d * e) + b * (c * e - d * f)) i ) ≡⟨ refl ⟩ ((a + b i) * ((c * e - d * f) + (c * f + d * e) i) ) ≡⟨ refl ⟩ (x * (y * z)) ∎ -- Left multiplicative identity. leftId-* : ∀ (x : 𝔾) -> (1# * x) ≡ x leftId-* x@(a + b i) = begin (1# + 0# i) * (a + b i) ≡⟨ refl ⟩ ((1# * a - 0# * b) + (1# * b + 0# * a) i) ≡⟨ cong₂ _+_i (let _*_ = _:*_ in let _-_ = _:-_ in (solve 2 (\ a b -> (con 1# * a) - (con 0# * b) := con 1# * a) refl a b)) ( (let _*_ = _:*_ in let _+_ = _:+_ in (solve 2 (\ a b -> (con 1# * b) + (con 0# * a) := con 1# * b) refl a b))) ⟩ ((1# * a) + (1# * b) i) ≡⟨ cong₂ _+_i (*-identityˡ a) (*-identityˡ b) ⟩ (a + b i) ∎ -- Right multiplicative identity. rightId-* : ∀ (x : 𝔾) -> (x * 1#) ≡ x rightId-* x@(a + b i) = begin (a + b i) * (1# + 0# i) ≡⟨ refl ⟩ (( a * 1# - b * 0#) + ( a * 0# + b * 1# ) i) ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _-_ = _:-_ in (solve 2 (\ a b -> (a * con 1# ) - (b * con 0# ) := con 1# * a) refl a b))) ((let _*_ = _:*_ in let _+_ = _:+_ in (solve 2 (\ a b -> (a * con 0#) + (b * con 1# ) := con 1# * b) refl a b))) ⟩ ((1# * a) + (1# * b) i) ≡⟨ cong₂ _+_i (*-identityˡ a) (*-identityˡ b) ⟩ (a + b i) ∎ -- Zero leftly times any number is zero. leftZero : ∀ x -> (0# + 0# i) * x ≡ (0# + 0# i) leftZero x@(a + b i) = begin (0# + 0# i) * (a + b i) ≡⟨ refl ⟩ (0# * a - 0# * b) + (0# * a - 0# * b) i ≡⟨ refl ⟩ 0# + 0# i ∎ -- Zero rightly times any number is zero. rightZero : ∀ x -> x * (0# + 0# i) ≡ (0# + 0# i) rightZero x@(a + b i) = begin (a + b i) * (0# + 0# i) ≡⟨ refl ⟩ (a * 0# - b * 0# ) + (a * 0# + b * 0# ) i ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 2 (\ a b -> (a * con 0#) - (b * con 0# ) := con 0#) refl a b))) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 2 (\ a b -> (a * con 0#) + (b * con 0# ) := con 0#) refl a b))) ⟩ 0# + 0# i ∎ -- Left multiplication is distributive over addition. *-DistributesOver-+ˡ : ∀ (x y z : 𝔾) -> (x * (y + z)) ≡ ((x * y) + (x * z)) *-DistributesOver-+ˡ x@(a + b i) y@(c + d i) z@(e + f i) = begin x * (y + z) ≡⟨ refl ⟩ (a * (c + e) - b * (d + f) + (a * (d + f) + b * (c + e)) i) ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> (a * (c + e)) - (b * (d + f) ) := ((a * c) - (b * d)) + ((a * e) - (b * f)) ) refl a b c d e f))) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> (a * (d + f)) + (b * (c + e) ) := ((a * d) + (b * c)) + ((a * f) + (b * e)) ) refl a b c d e f))) ⟩ ((a * c - b * d) + (a * e - b * f)) + ((a * d + b * c) + (a * f + b * e)) i ≡⟨ refl ⟩ ((x * y) + (x * z)) ∎ -- Right multiplication is distributive over addition. *-DistributesOver-+ʳ : ∀ (x y z : 𝔾) -> ((y + z) * x) ≡ (y * x) + (z * x) *-DistributesOver-+ʳ x@(a + b i) y@(c + d i) z@(e + f i) = begin (y + z) * x ≡⟨ refl ⟩ ((c + e) * a - (d + f) * b + ( (c + e) * b + (d + f) * a ) i) ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> ((c + e) * a) - ((d + f) * b ) := ((c * a ) - (d * b)) + ((e * a) - (f * b )) ) refl a b c d e f))) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 6 (\ a b c d e f -> ((c + e) * b) + ((d + f) * a ) := ((c * b ) + (d * a)) + ((e * b) + (f * a )) ) refl a b c d e f))) ⟩ ((c * a - d * b) + (e * a - f * b)) + ((c * b + d * a ) + (e * b + f * a )) i ≡⟨ refl ⟩ ((y * x) + (z * x)) ∎ -- Multiplicaton is commutative. comm-* : ∀ (x y : 𝔾) -> x * y ≡ y * x comm-* x@(a + b i) y@(c + d i) = begin x * y ≡⟨ refl ⟩ (a * c - b * d) + (a * d + b * c) i ≡⟨ cong₂ _+_i ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 4 (\ a b c d -> (a * c) - (b * d) := (c * a ) - (d * b)) refl a b c d))) ((let _*_ = _:*_ in let _+_ = _:+_ in let _-_ = _:-_ in (solve 4 (\ a b c d -> (a * d) + (b * c) := (c * b) + (d * a)) refl a b c d))) ⟩ (c * a - d * b) + (c * b + d * a) i ≡⟨ refl ⟩ (y * x) ∎ -- ---------------------------------------------------------------------- -- Structures for multiplication *-isMagma : IsMagma _*_ *-isMagma = record { isEquivalence = isEquivalence ; ∙-cong = cong₂ _*_ } *-isSemigroup : IsSemigroup _*_ *-isSemigroup = record { isMagma = *-isMagma ; assoc = assoc-* } *-isCommutativeSemigroup : IsCommutativeSemigroup _*_ *-isCommutativeSemigroup = record { isSemigroup = *-isSemigroup ; comm = comm-* } *-1-isMonoid : IsMonoid _*_ 1# *-1-isMonoid = record { isSemigroup = *-isSemigroup ; identity = leftId-* , rightId-* } *-1-isCommutativeMonoid : IsCommutativeMonoid _*_ 1# *-1-isCommutativeMonoid = record { isMonoid = *-1-isMonoid ; comm = comm-* } -- ---------------------------------------------------------------------- -- Structures for multiplication and addition +-*-isSemiring : IsSemiring _+_ _*_ 0# 1# +-*-isSemiring = record { isSemiringWithoutAnnihilatingZero = record { +-isCommutativeMonoid = +-0-isCommutativeMonoid ; *-isMonoid = *-1-isMonoid ; distrib = *-DistributesOver-+ˡ , *-DistributesOver-+ʳ } ; zero = leftZero , rightZero } +-*-isCommutativeSemiring : IsCommutativeSemiring _+_ _*_ 0# 1# +-*-isCommutativeSemiring = record { isSemiring = +-*-isSemiring ; *-comm = comm-* } +-*-isRing : IsRing _+_ _*_ -_ 0# 1# +-*-isRing = record { +-isAbelianGroup = +-isAbelianGroup ; *-isMonoid = *-1-isMonoid ; distrib = *-DistributesOver-+ˡ , *-DistributesOver-+ʳ ; zero = leftZero , rightZero } +-*-isCommutativeRing : IsCommutativeRing _+_ _*_ -_ 0# 1# +-*-isCommutativeRing = record { isRing = +-*-isRing ; *-comm = comm-* } ------------------------------------------------------------------------ -- Bundles for multiplication *-magma : Magma 0ℓ 0ℓ *-magma = record { isMagma = *-isMagma } *-semigroup : Semigroup 0ℓ 0ℓ *-semigroup = record { isSemigroup = *-isSemigroup } *-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ *-commutativeSemigroup = record { isCommutativeSemigroup = *-isCommutativeSemigroup } *-1-monoid : Monoid 0ℓ 0ℓ *-1-monoid = record { isMonoid = *-1-isMonoid } *-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ *-1-commutativeMonoid = record { isCommutativeMonoid = *-1-isCommutativeMonoid } ------------------------------------------------------------------------ -- Bundles for multiplication and addition +-*-semiring : Semiring 0ℓ 0ℓ +-*-semiring = record { isSemiring = +-*-isSemiring } +-*-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ +-*-commutativeSemiring = record { isCommutativeSemiring = +-*-isCommutativeSemiring } +-*-ring : B.Ring 0ℓ 0ℓ +-*-ring = record { isRing = +-*-isRing } +-*-commutativeRing : CommutativeRing 0ℓ 0ℓ +-*-commutativeRing = record { isCommutativeRing = +-*-isCommutativeRing } -- ---------------------------------------------------------------------- -- Properties of Re and Im -- Re x + Im x i = x Re+Im*i : ∀ {x} -> Re x + Im x i ≡ x Re+Im*i {x + x₁ i} = refl -- Re (y * y ᶜ) ≡ + rank y Re[yyᶜ]=rank : ∀ {y : 𝔾} -> Re (y * y ᶜ) ≡ + rank y Re[yyᶜ]=rank {y@(a + b i)} = sym $ begin + (rank y) ≡⟨ refl ⟩ + (rank (a + b i)) ≡⟨ refl ⟩ + ∣ a * a + b * b ∣ ≡⟨ cong +_ (tri-eq' a b) ⟩ + (∣ a * a ∣ + ∣ b * b ∣) ≡⟨ refl ⟩ + ∣ a * a ∣ + + ∣ b * b ∣ ≡⟨ cong₂ _+_ (+∣a*a∣=a*a a) (+∣a*a∣=a*a b) ⟩ a * a + b * b ≡⟨ solve 2 (\ a b -> a :* a :+ b :* b := a :* a :- b :* (:- b)) refl a b ⟩ a * a - b * (- b) ≡⟨ refl ⟩ Re ((a * a - b * (- b)) + 0ℤ i) ≡⟨ refl ⟩ Re ((a * a - b * (- b)) + (a * (- b) + b * a) i) ≡⟨ refl ⟩ Re (y * y ᶜ) ∎ -- Im y * y ᶜ = 0 Im[yyᶜ]=0 : ∀ {y : 𝔾} -> Im (y * y ᶜ) ≡ 0# Im[yyᶜ]=0 {y@(a + b i)} = begin Im (y * y ᶜ) ≡⟨ refl ⟩ Im ((a * a - b * (- b)) + (a * (- b) + b * a) i) ≡⟨ refl ⟩ a * (- b) + b * a ≡⟨ solve 2 (\ a b -> a :* (:- b) :+ b :* a := con 0#) refl a b ⟩ 0# ∎ -- ---------------------------------------------------------------------- -- Properties of conjugation -- Conjugation is injective. ᶜ-injective : ∀ {x} -> x ᶜ ≡ 0# -> x ≡ 0# ᶜ-injective {+ 0 + + 0 i} eq = refl -- y * y ᶜ = rank y y*yᶜ=rank : ∀ {y : 𝔾} -> y * y ᶜ ≡ rank y +0i y*yᶜ=rank {y@(a + b i)} = begin y * y ᶜ ≡⟨ sym $ Re+Im*i ⟩ Re (y * y ᶜ) + Im (y * y ᶜ) i ≡⟨ cong₂ _+_i (Re[yyᶜ]=rank {y}) (Im[yyᶜ]=0 {y}) ⟩ + rank y + 0# i ∎ -- ---------------------------------------------------------------------- -- Properties of rank -- rank on 𝔾 is homomorphic in multiplication. rank-*-commute : 𝔾toℕ.Homomorphic₂ rank _*_ Nat._*_ rank-*-commute x@(a + b i) y@(c + d i) = claim where claim : rank (x * y) ≡ rank x * rank y claim = begin rank (x * y) ≡⟨ refl ⟩ rank ((a * c - b * d) + (a * d + b * c) i) ≡⟨ refl ⟩ ∣ (a * c - b * d)^2 + (a * d + b * c)^2 ∣ ≡⟨ cong ∣_∣ (solve 4 (λ a b c d → (a :* c :- b :* d) :* (a :* c :- b :* d) :+ (a :* d :+ b :* c) :* (a :* d :+ b :* c) := (a :* a :+ b :* b) :* (c :* c :+ d :* d)) refl a b c d) ⟩ ∣ (a ^2 + b ^2) * (c ^2 + d ^2) ∣ ≡⟨ IntP.abs-*-commute ((a ^2 + b ^2)) ((c ^2 + d ^2)) ⟩ ∣ a ^2 + b ^2 ∣ * ∣ c ^2 + d ^2 ∣ ≡⟨ refl ⟩ rank x * rank y ∎ rank=∣Re[y*yᶜ]∣ : ∀ (x : 𝔾) -> rank x ≡ ∣ Re (x * x ᶜ) ∣ rank=∣Re[y*yᶜ]∣ x@(a + b i) = begin rank (a + b i) ≡⟨ refl ⟩ ∣ a * a + b * b ∣ ≡⟨ cong ∣_∣ (solve 2 (λ a b → a :* a :+ b :* b := a :* a :- b :* (:- b)) refl a b) ⟩ ∣ a * a - b * (- b) ∣ ≡⟨ refl ⟩ ∣ Re ((a * a - b * (- b)) + 0ℤ i) ∣ ≡⟨ refl ⟩ ∣ Re ((a * a - b * (- b)) + (a * (- b) + b * a) i) ∣ ≡⟨ refl ⟩ ∣ Re (x * x ᶜ) ∣ ∎ -- rank y + 0 i = y * y ᶜ rank+0i=y*yᶜ : ∀ {y : 𝔾} -> (rank y) +0i ≡ y * y ᶜ rank+0i=y*yᶜ {y} = sym $ begin y * y ᶜ ≡⟨ sym $ Re+Im*i ⟩ Re (y * y ᶜ) + Im (y * y ᶜ) i ≡⟨ cong₂ _+_i (Re[yyᶜ]=rank {y}) (Im[yyᶜ]=0 {y}) ⟩ + rank y + 0# i ∎ -- ---------------------------------------------------------------------- -- Injection preserves SemiRing Structure +0i-+-commute : ℕto𝔾.Homomorphic₂ _+0i Nat._+_ _+_ +0i-+-commute a b = refl +0i-*-commute : ℕto𝔾.Homomorphic₂ _+0i Nat._*_ _*_ +0i-*-commute a b rewrite NatP.*-zeroˡ a | NatP.*-zeroˡ b | NatP.*-zeroʳ a | NatP.*-zeroʳ b | sym (IntP.pos-distrib-* a b) | IntP.+-identityʳ (+ a * + b) = refl 0+0i=0 : 0 +0i ≡ 0# 0+0i=0 = refl 1+0i=1 : 1 +0i ≡ 1# 1+0i=1 = refl -- ---------------------------------------------------------------------- -- Domain Structrue on 𝔾 -- Some auxillaries. -- Zero is unique. unique0 : ∀ {a b} -> (a + b i) ≡ 0# -> a ≡ 0ℤ × b ≡ 0ℤ unique0 {.+0} {.+0} refl = refl , refl -- Conversely, if a + bi ≠ 0 then at least one of a and b is not zero. unique0' : ∀ {a b} -> ¬ (a + b i) ≡ 0# -> ¬ a ≡ 0ℤ ⊎ ¬ b ≡ 0ℤ unique0' {a@(+_ zero)} {b@(+_ zero)} neq with neq refl ... | () unique0' {+_ zero} {+[1+ n ]} neq = inj₂ (λ ()) unique0' {+_ zero} { -[1+_] n} neq = inj₂ (λ ()) unique0' {+[1+ n ]} {b} neq = inj₁ (λ ()) unique0' { -[1+_] n} {b} neq = inj₁ (λ ()) -- Make an equation onesided. oneside : ∀ {a b : 𝔾} -> a ≡ b -> a - b ≡ 0# oneside {a} {b} eq rewrite eq = rightInv-+ b -- Make an equation twosided. twoside : ∀ {a b : 𝔾} -> a - b ≡ 0# -> a ≡ b twoside {a} {b} eq = sym $ -‿injective $ +-inverseʳ-unique a (- b) eq where open import Algebra.Properties.Ring +-*-ring -- Make an equation twosided, ℤ version. twosideℤ : ∀ {a b : ℤ} -> a - b ≡ 0# -> a ≡ b twosideℤ {a} {b} eq = sym (PRI.-‿injective (PRI.+-inverseʳ-unique a (- b) eq )) where import Algebra.Properties.Ring IntP.+-*-ring as PRI -- We show zero divisor is necessary zero (equivalent to left or right -- cancellation in a commutative ring), which makes 𝔾 an integral -- domain. zero-divisor-is-zero : ∀ {x y : 𝔾} -> x * y ≡ 0# -> ¬ x ≡ 0# -> y ≡ 0# zero-divisor-is-zero {x@(a + b i)} {y@(c + d i)} eq neq = cong₂ _+_i (proj₁ step6) (proj₂ step6) where open ≡-Reasoning open IS.+-*-Solver -- 0 = x * y = (a * c - b * d) + (a * d + b * c) i, together with -- c + d i ≠ 0, we can derive a = 0 and b = 0, contradicting x ≠ -- 0. The proof idea is: -- -- step0 : a * c - b * d = 0 and a * d + b * c = 0 -- step1 : a * c * c - b * d * c = 0 -- step2 : a * d * d + b * c * d = 0 -- s1,s2 ⇒ step1&2 : a * (c * c + d * d) = 0 -- step3 : a * c * d - b * d * d = 0 -- step4 : a * d * c + b * c * c = 0 -- s3,s4 ⇒ step3&4 : b * (c * c + d * d) = 0 -- one of a b nonzero ⇒ step5 : (c * c + d * d) = 0 -- step5 ⇒ step6 : c = 0 and d = 0 -- step0 : a * c - b * d = 0 and a * d + b * c = 0 step0 : a * c - b * d ≡ 0# × a * d + b * c ≡ 0# step0 = unique0 eq -- step1 : a * c * c - b * d * c = 0 step1 : a * c * c - b * d * c ≡ 0# step1 = begin a * c * c - b * d * c ≡⟨ solve 4 (\ a b c d -> a :* c :* c :- b :* d :* c := (a :* c :- b :* d) :* c) refl a b c d ⟩ (a * c - b * d) * c ≡⟨ cong (_* c) (proj₁ step0) ⟩ 0ℤ * c ≡⟨ refl ⟩ 0ℤ ∎ -- step2 : a * d * d + b * c * d = 0 step2 : a * d * d + b * c * d ≡ 0# step2 = begin a * d * d + b * c * d ≡⟨ solve 4 (\ a b c d -> a :* d :* d :+ b :* c :* d := (a :* d :+ b :* c) :* d) refl a b c d ⟩ (a * d + (b * c)) * d ≡⟨ cong (_* d) (proj₂ step0) ⟩ 0ℤ * d ≡⟨ refl ⟩ 0ℤ ∎ -- c1,c2 ⇒ step1&2 : a * (c * c + d * d) = 0 step1&2 : a * (c * c + d * d) ≡ 0# step1&2 = begin a * (c * c + d * d) ≡⟨ solve 4 (\ a b c d -> a :* (c :* c :+ d :* d) := (a :* c :* c :- b :* d :* c) :+ (a :* d :* d :+ b :* c :* d) ) refl a b c d ⟩ (a * c * c - b * d * c) + (a * d * d + b * c * d) ≡⟨ cong₂ _+_ step1 step2 ⟩ 0# ∎ -- step3 : a * c * d - b * d * d = 0 step3 : a * c * d - b * d * d ≡ 0# step3 = begin a * c * d - b * d * d ≡⟨ solve 4 (\ a b c d -> a :* c :* d :- b :* d :* d := (a :* c :- b :* d) :* d) refl a b c d ⟩ (a * c - b * d) * d ≡⟨ cong (_* d) (proj₁ step0) ⟩ 0ℤ * d ≡⟨ refl ⟩ 0ℤ ∎ -- step4 : a * d * c + b * c * c = 0 step4 : a * d * c + b * c * c ≡ 0# step4 = begin a * d * c + b * c * c ≡⟨ solve 4 (\ a b c d -> a :* d :* c :+ b :* c :* c := (a :* d :+ b :* c) :* c) refl a b c d ⟩ (a * d + (b * c)) * c ≡⟨ cong (_* c) (proj₂ step0) ⟩ 0ℤ * c ≡⟨ refl ⟩ 0ℤ ∎ -- s3,s4 ⇒ step3&4 : b * (c * c + d * d) = 0 step3&4 : b * (c * c + d * d) ≡ 0# step3&4 = begin b * (c * c + d * d) ≡⟨ solve 4 (\ a b c d -> b :* (c :* c :+ d :* d) := :- (a :* c :* d :- b :* d :* d) :+ (a :* d :* c :+ b :* c :* c) ) refl a b c d ⟩ - (a * c * d - b * d * d) + (a * d * c + b * c * c) ≡⟨ cong₂ (\x y -> (- x) + y) step3 step4 ⟩ 0# ∎ -- one of a b nonzero ⇒ step5 : (c * c + d * d) = 0 -- some auxillary lemma. aux : ∀ {a : ℤ} -> a * 0# ≡ 0# aux {a} rewrite IntP.*-comm a 0# = refl step1&2' : a * (c * c + d * d) ≡ a * 0# step1&2' rewrite aux {a} = step1&2 step3&4' : b * (c * c + d * d) ≡ b * 0# step3&4' rewrite aux {b} = step3&4 step5 : c * c + d * d ≡ 0# step5 = ⊎-elim (λ x₁ → IntP.*-cancelˡ-≡ a (c * c + d * d) 0# {{myins2 {a} {x₁}}} step1&2') (λ x₁ → IntP.*-cancelˡ-≡ b (c * c + d * d) 0# {{myins2 {b} {x₁}}} step3&4') (unique0' neq) where -- We need a translation from non-equality to NonZero predicate. open import Agda.Builtin.Unit myins2 : ∀ {x : ℤ} -> {n0 : ¬ x ≡ 0ℤ} -> NonZero x myins2 {+_ zero} {n0} with n0 refl ... | () myins2 {+[1+ n ]} {n0} = record { nonZero = tt } myins2 { -[1+_] n} {n0} = record { nonZero = tt } -- step5 ⇒ step6 : c = 0 and d = 0 step6 : c ≡ 0# × d ≡ 0# step6 = aa+bb=0⇒a=0×b=0 step5 -- Almost left cancellative. *-alc-𝔾 : AlmostLeftCancellative 0𝔾 _*_ *-alc-𝔾 {x@(a + b i)} y@(c + d i) z@(e + f i) neq eq = y=z where onesided-eq : x * (y + (- z)) ≡ 0# onesided-eq = begin x * (y + (- z)) ≡⟨ *-DistributesOver-+ˡ x y (- z) ⟩ x * y + x * (- z) ≡⟨ refl ⟩ x * y + (a + b i) * (- e + - f i) ≡⟨ cong (λ t → x * y + t) refl ⟩ x * y + ((a * - e - b * - f ) + (a * - f + b * - e) i) ≡⟨ cong (λ t → x * y + t) (cong₂ _+_i (solve 4 (\a e b f -> a :* :- e :- b :* :- f := :- (a :* e :- b :* f)) refl a e b f) (solve 4 (\a e b f -> a :* :- f :+ b :* :- e := :- (a :* f :+ b :* e)) refl a e b f)) ⟩ x * y + (- (a * e - b * f) + - (a * f + b * e) i) ≡⟨ cong (λ t → x * y + t) refl ⟩ x * y + (- (x * z)) ≡⟨ oneside eq ⟩ 0# ∎ where open ≡-Reasoning open IS.+-*-Solver y-z=0 : (y + (- z)) ≡ 0# y-z=0 = zero-divisor-is-zero onesided-eq neq y=z : y ≡ z y=z = twoside y-z=0 -- Multiplication commutativity plus left cancellative implies 𝔾 is an -- commutative Domain. Knowing this, we can show e.g. y≠0⇒y*yᶜ≠0 : ∀ {y} -> ¬ y ≡ 0# -> ¬ y * y ᶜ ≡ 0# y≠0⇒y*yᶜ≠0 {y} n0 eq = ⊥-elim (n0' e0) where open import Data.Empty n0' : ¬ y ᶜ ≡ 0# n0' x with n0 (ᶜ-injective {y} x) ... | () eq' : y * y ᶜ ≡ y * 0# eq' = begin y * y ᶜ ≡⟨ eq ⟩ 0# ≡⟨ sym $ rightZero y ⟩ y * 0# ∎ where open IS.+-*-Solver open ≡-Reasoning e0 : y ᶜ ≡ 0# e0 = *-alc-𝔾 {y} (y ᶜ) 0# n0 eq' y≠0#⇒rank≠0 : ∀ {y : 𝔾} -> ¬ y ≡ 0# -> ¬ rank y ≡ 0# y≠0#⇒rank≠0 {y} n0 = rank≠0 where open import Data.Empty y*yᶜ≠0 : ¬ y * y ᶜ ≡ 0# y*yᶜ≠0 = y≠0⇒y*yᶜ≠0 n0 rank≠0 : ¬ rank y ≡ 0# rank≠0 e = ⊥-elim (y*yᶜ≠0 y*yᶜ=0) where y*yᶜ=0 : y * y ᶜ ≡ 0# y*yᶜ=0 = begin y * y ᶜ ≡⟨ sym $ Re+Im*i ⟩ Re (y * y ᶜ) + Im (y * y ᶜ) i ≡⟨ cong₂ _+_i (Re[yyᶜ]=rank {y}) refl ⟩ + rank y + Im (y * y ᶜ) i ≡⟨ cong₂ _+_i (cong +_ e) (Im[yyᶜ]=0 {y}) ⟩ 0# ∎ where open IS.+-*-Solver open ≡-Reasoning rank=0⇒y=0 : ∀ {y : 𝔾} -> rank y ≡ 0# -> y ≡ 0# rank=0⇒y=0 {y@(a + b i)} eq0 = y=0 where eq0' : a * a + b * b ≡ 0# eq0' = IntP.∣i∣≡0⇒i≡0 eq0 s1 : a ≡ 0ℤ × b ≡ 0ℤ s1 = aa+bb=0⇒a=0×b=0 eq0' y=0 : y ≡ 0# y=0 with s1 ... | fst , snd rewrite fst | snd = refl rank≥1 : ∀ {y : 𝔾} -> ¬ y ≡ 0# -> 1# ≤ rank y rank≥1 {y} n0 = aux (rank y) (y≠0#⇒rank≠0 {y} n0) where aux : ∀ (n : ℕ) -> ¬ n ≡ 0 -> 1 ≤ n aux zero n0' with n0' refl ... | () aux (suc n) n0' = Nat.s≤s Nat.z≤n ranky<1⇒y=0 : ∀ (y : 𝔾) -> rank y < 1# -> y ≡ 0# ranky<1⇒y=0 y r = rank=0⇒y=0 {y} ranky=0 where aux : ∀ (n : ℕ) -> n < 1 -> n ≡ 0 aux .zero (Nat.s≤s Nat.z≤n) = refl ranky=0 : rank y ≡ 0 ranky=0 = aux (rank y) r -- ---------------------------------------------------------------------- -- Properties of NonZero
{ "alphanum_fraction": 0.448256513, "avg_line_length": 35.1408450704, "ext": "agda", "hexsha": "1c186540eede2928925622247536273631451904", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "onestruggler/EucDomain", "max_forks_repo_path": "GauInt/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "onestruggler/EucDomain", "max_issues_repo_path": "GauInt/Properties.agda", "max_line_length": 446, "max_stars_count": null, "max_stars_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "onestruggler/EucDomain", "max_stars_repo_path": "GauInt/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 11276, "size": 24950 }
{-# OPTIONS --erased-cubical --safe #-} module FarmFugue where open import Data.Bool using (Bool; true; false; if_then_else_) open import Data.Fin using (#_) open import Data.List using (List; _∷_; []; map; _++_) open import Data.Nat using (ℕ; _*_; _+_) open import Data.Sign using () renaming (+ to s+ ; - to s-) open import Data.Vec using (Vec; _∷_; []; lookup; foldl₁) renaming (map to vmap) open import Function using (_∘_) open import Canon using (makeCanon) open import Interval open import Instruments using (pianos) open import MakeTracks using (makeTrackList) open import Music using (melody→notes; notes→melody; fixLength; dropPoints) open import Note using (Note; tone; rest; 8th; qtr; dqtr; half; whole; transposeNoteInterval) open import Pitch using (a; b; c; d; e; f; g) open import MidiEvent using (MidiTrack) open import Util using (repeat) open import Transformation -------------- b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 : List Note b1 = tone 8th (c 5) ∷ tone 8th (d 5) ∷ tone 8th (e 5) ∷ rest 8th ∷ tone 8th (e 5) ∷ rest 8th ∷ tone 8th (c 5) ∷ rest 8th ∷ [] b2 = tone 8th (c 5) ∷ tone 8th (d 5) ∷ tone 8th (c 5) ∷ tone 8th (d 5) ∷ tone qtr (e 5) ∷ tone qtr (c 5) ∷ [] b3 = tone dqtr (e 5) ∷ tone 8th (e 5) ∷ tone 8th (d 5) ∷ tone 8th (e 5) ∷ tone 8th (d 5) ∷ tone 8th (e 5) ∷ [] b4 = tone dqtr (e 5) ∷ tone 8th (e 5) ∷ tone qtr (g 4) ∷ tone qtr (b 4) ∷ [] b5 = tone 8th (c 6) ∷ rest 8th ∷ tone 8th (a 5) ∷ rest 8th ∷ tone 8th (e 5) ∷ tone 8th (f 5) ∷ tone 8th (e 5) ∷ tone 8th (f 5) ∷ [] b6 = tone 8th (c 6) ∷ rest 8th ∷ tone 8th (a 5) ∷ rest 8th ∷ tone half (c 5) ∷ [] b7 = tone 8th (c 5) ∷ rest 8th ∷ tone 8th (e 5) ∷ rest 8th ∷ tone 8th (f 5) ∷ rest 8th ∷ tone 8th (d 5) ∷ rest 8th ∷ [] b8 = tone 8th (g 5) ∷ tone 8th (g 5) ∷ tone 8th (f 5) ∷ tone 8th (f 5) ∷ tone 8th (e 5) ∷ tone 8th (e 5) ∷ tone 8th (d 5) ∷ tone 8th (d 5) ∷ [] b9 = tone qtr (g 5) ∷ tone qtr (f 5) ∷ tone qtr (e 5) ∷ tone 8th (d 5) ∷ tone 8th (d 5) ∷ [] b10 = tone dqtr (c 5) ∷ tone 8th (c 5) ∷ tone 8th (c 5) ∷ rest 8th ∷ tone 8th (c 5) ∷ rest 8th ∷ [] b11 = tone qtr (b 5) ∷ tone qtr (a 5) ∷ tone qtr (g 5) ∷ tone qtr (f 5) ∷ [] b12 = tone qtr (c 4) ∷ tone qtr (c 4) ∷ [] b13 = tone 8th (c 4) ∷ tone 8th (c 4) ∷ tone 8th (c 4) ∷ tone 8th (c 4) ∷ [] subject countersubject extra base : List Note subject = b1 ++ b3 ++ b1 ++ b4 countersubject = map (transposeNoteInterval (makeSigned s- per5)) (b5 ++ b6 ++ b5 ++ b7) extra = b8 ++ b10 ++ b9 ++ b10 base = subject ++ countersubject ++ extra transpositions : Vec Opi 3 transpositions = vmap (makeSigned s-) (per1 ∷ per5 ∷ per8 ∷ []) -- Exposition is a truncated canon expo exposition : Vec (List Note) 3 expo = makeCanon base 2 (whole + whole + whole + whole) transpositions -- Truncate to first 20 bars (16 16th notes per bar in 4/4 time) exposition = vmap (melody→notes ∘ fixLength (20 * 16) ∘ notes→melody) expo -- Variation doubleLastDuration : List Note → List Note doubleLastDuration [] = [] doubleLastDuration (m ∷ n ∷ ns) = m ∷ doubleLastDuration (n ∷ ns) doubleLastDuration (tone d p ∷ []) = tone (2 * d) p ∷ [] doubleLastDuration (rest d ∷ []) = rest (2 * d) ∷ [] makeVariation : List Note → List Note → List Note → Vec (List Note) 3 makeVariation s c e = let base = s ++ c ++ e expo = makeCanon base 2 (whole + whole + whole + whole) transpositions in vmap (melody→notes ∘ fixLength (20 * 16) ∘ notes→melody) expo makeVariation' : List Note → List Note → List Note → Vec (List Note) 3 makeVariation' s c e = let base = s ++ c ++ e expo = makeCanon base 2 (whole + whole + whole + whole) transpositions in vmap (melody→notes ∘ dropPoints (2 * 16) ∘ fixLength (16 * 16) ∘ notes→melody) expo v1 v2 v3 variations : Vec (List Note) 3 v1 = makeVariation (doubleLastDuration subject) countersubject extra v2 = makeVariation' (doubleLastDuration countersubject) extra subject v3 = makeVariation' (doubleLastDuration extra) subject countersubject variations = v1 -- (lookup v1 (# 0) ++ {- lookup v2 (# 0) ++ -} lookup v3 (# 0)) ∷ -- (lookup v1 (# 1) ++ {- lookup v2 (# 1) ++ -} lookup v3 (# 1)) ∷ -- (lookup v1 (# 2) ++ {- lookup v2 (# 2) ++ -} lookup v3 (# 2)) ∷ -- [] dev1 dev2 dev3 end1 end2 end3 line1 line2 line3 : List Note dev1 = map (transposeNoteInterval (makeSigned s+ per12)) countersubject ++ map (transposeNoteInterval (makeSigned s+ per12)) subject ++ map (transposeNoteInterval (makeSigned s+ per12)) b8 ++ map (transposeNoteInterval (makeSigned s+ per8)) b8 ++ map (transposeNoteInterval (makeSigned s+ per4)) b8 ++ map (transposeNoteInterval (makeSigned s- maj2)) b9 ++ map (transposeNoteInterval (makeSigned s- per4)) subject ++ map (transposeNoteInterval (makeSigned s- per5)) countersubject ++ map (transposeNoteInterval (makeSigned s+ min3)) b12 ++ map (transposeNoteInterval (makeSigned s+ maj3)) b12 ++ map (transposeNoteInterval (makeSigned s+ min3)) b12 ++ map (transposeNoteInterval (makeSigned s+ maj3)) b13 dev2 = map (transposeNoteInterval (makeSigned s+ per8)) subject ++ map (transposeNoteInterval (makeSigned s+ per8)) countersubject ++ map (transposeNoteInterval (makeSigned s+ per8)) b8 ++ map (transposeNoteInterval (makeSigned s+ per4)) b8 ++ map (transposeNoteInterval (makeSigned s- maj2)) b8 ++ map (transposeNoteInterval (makeSigned s- maj6)) b9 ++ map (transposeNoteInterval (makeSigned s- per8)) countersubject ++ map (transposeNoteInterval (makeSigned s- per8)) subject ++ map (transposeNoteInterval (makeSigned s- per4)) (b12 ++ b12 ++ b12 ++ b13) dev3 = map (transposeNoteInterval (makeSigned s+ per5)) countersubject ++ map (transposeNoteInterval (makeSigned s+ per5)) subject ++ map (transposeNoteInterval (makeSigned s+ per5)) b8 ++ map (transposeNoteInterval (makeSigned s+ per1)) b8 ++ map (transposeNoteInterval (makeSigned s- per5)) b8 ++ map (transposeNoteInterval (makeSigned s- maj9)) b9 ++ map (transposeNoteInterval (makeSigned s- per12)) subject ++ map (transposeNoteInterval (makeSigned s- per12)) countersubject ++ map (transposeNoteInterval (makeSigned s- maj6)) b12 ++ map (transposeNoteInterval (makeSigned s- min6)) b12 ++ map (transposeNoteInterval (makeSigned s- maj6)) b12 ++ map (transposeNoteInterval (makeSigned s- min6)) b13 end1 = map (transposeNoteInterval (makeSigned s+ per8)) b1 ++ tone whole (e 6) ∷ [] end2 = map (transposeNoteInterval (makeSigned s+ per1)) b1 ++ tone whole (g 5) ∷ [] end3 = map (transposeNoteInterval (makeSigned s- per8)) b1 ++ tone whole (c 4) ∷ [] line1 = lookup exposition (# 0) ++ dev1 ++ lookup variations (# 0) ++ end1 line2 = lookup exposition (# 1) ++ dev2 ++ lookup variations (# 1) ++ end2 line3 = lookup exposition (# 2) ++ dev3 ++ lookup variations (# 2) ++ end3 fugue : Vec (List Note) 3 fugue = line1 ∷ line2 ∷ line3 ∷ [] tempo : ℕ tempo = 160 fugueTracks : List MidiTrack fugueTracks = makeTrackList pianos tempo fugue
{ "alphanum_fraction": 0.6170356371, "avg_line_length": 29.2806324111, "ext": "agda", "hexsha": "54e498b3736b379b14a700a22ce087e5e27678e2", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z", "max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z", "max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "halfaya/MusicTools", "max_forks_repo_path": "agda/FarmFugue.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z", "max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "halfaya/MusicTools", "max_issues_repo_path": "agda/FarmFugue.agda", "max_line_length": 104, "max_stars_count": 28, "max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "halfaya/MusicTools", "max_stars_repo_path": "agda/FarmFugue.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z", "max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z", "num_tokens": 2802, "size": 7408 }
module PatternShadowsConstructor where module A where data B : Set where x : B data C : Set where c : B → C open A using (C; c) f : C → C f (c x) = x
{ "alphanum_fraction": 0.5868263473, "avg_line_length": 11.1333333333, "ext": "agda", "hexsha": "07b04bd49d2879f4cf4faaecfc692b83d23b0292", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/PatternShadowsConstructor.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/PatternShadowsConstructor.agda", "max_line_length": 38, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/PatternShadowsConstructor.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 59, "size": 167 }
module STLCRef.Readme where open import STLCRef.Syntax open import STLCRef.Welltyped open import STLCRef.Eval open import STLCRef.Properties.Soundness
{ "alphanum_fraction": 0.8552631579, "avg_line_length": 21.7142857143, "ext": "agda", "hexsha": "89266a9b454653356f74f5cd788b0d7548832ef2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ef2e347a4470e55083c83b743efbc2902ef1ad22", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ElessarWebb/implicits.agda", "max_forks_repo_path": "src/STLCRef/Readme.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ef2e347a4470e55083c83b743efbc2902ef1ad22", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ElessarWebb/implicits.agda", "max_issues_repo_path": "src/STLCRef/Readme.agda", "max_line_length": 40, "max_stars_count": 4, "max_stars_repo_head_hexsha": "ef2e347a4470e55083c83b743efbc2902ef1ad22", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ajrouvoet/implicits.agda", "max_stars_repo_path": "src/STLCRef/Readme.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z", "max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z", "num_tokens": 41, "size": 152 }
{-# OPTIONS --type-in-type #-} module prelude.io where open import prelude open import functors open import Agda.Builtin.IO public using (IO) open import Data.String open import prelude.Stream as Stream using (Stream) open import Data.List as L using (List) IO[_,_] : Set → Set → Set IO[ A , B ] = A → IO B 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 return>>= : ∀ {a b} (f : a → IO b) → (λ x → return x >>= f) ≡ f >>=return : ∀ {a b} (f : a → IO b) → (λ x → f x >>= return) ≡ f {-# COMPILE GHC return = \_ _ -> return #-} {-# COMPILE GHC _>>=_ = \_ _ _ _ -> (>>=) #-} -- record Category {O : Set} (𝒞[_,_] : O → O → Set) : Set where -- constructor 𝒾:_▸:_𝒾▸:_▸𝒾: -- infixl 8 _▸_ -- field -- 𝒾 : ∀ {x} → 𝒞[ x , x ] -- _▸_ : ∀ {x y z} → 𝒞[ x , y ] → 𝒞[ y , z ] → 𝒞[ x , z ] -- 𝒾▸ : ∀ {x y} (f : 𝒞[ x , y ]) → (𝒾 ▸ f) ≡ f -- ▸𝒾 : ∀ {x y} (f : 𝒞[ x , y ]) → (f ▸ 𝒾) ≡ f -- open Category ⦃...⦄ public instance io-cat : Category IO[_,_] io-cat = 𝒾: return ▸: (λ f g x → f x >>= g) 𝒾▸: return>>= ▸𝒾: >>=return {-# FOREIGN GHC import qualified Data.Text as T #-} {-# FOREIGN GHC import qualified Data.Text.IO as T #-} postulate getContents : IO String putStrLn : String → IO ⊤ {-# COMPILE GHC getContents = T.getContents #-} {-# COMPILE GHC putStrLn = T.putStrLn #-} postulate showℕ : ℕ → String {-# COMPILE GHC showℕ = T.pack . show #-} {-# NON_TERMINATING #-} printStream : Stream ℕ → IO ⊤ printStream s = putStrLn (showℕ (Stream.hd s)) >>= λ _ → printStream (Stream.tl s) printList : List ℕ → IO ⊤ printList L.[] = return tt printList (x L.∷ xs) = putStrLn (showℕ x) >>= λ _ → printList xs
{ "alphanum_fraction": 0.5395268321, "avg_line_length": 27.9516129032, "ext": "agda", "hexsha": "15439a7c86b1d557188365cef51f243ef6b50a83", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-30T11:45:57.000Z", "max_forks_repo_forks_event_min_datetime": "2021-07-10T17:19:37.000Z", "max_forks_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dspivak/poly", "max_forks_repo_path": "code-examples/agda/prelude/io.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea", "max_issues_repo_issues_event_max_datetime": "2022-01-12T10:06:32.000Z", "max_issues_repo_issues_event_min_datetime": "2021-09-02T02:29:39.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dspivak/poly", "max_issues_repo_path": "code-examples/agda/prelude/io.agda", "max_line_length": 82, "max_stars_count": 53, "max_stars_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mstone/poly", "max_stars_repo_path": "code-examples/agda/prelude/io.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:27.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-18T16:31:04.000Z", "num_tokens": 681, "size": 1733 }
-- 2014-05-26 Andrea & Andreas -- hasBadRigids (in pruning) should reduce term before checking. open import Common.Equality postulate Fence : Set → Set id : ∀{a}{A : Set a}(x : A) → A id x = x test : let H : Set; H = _; M : Set → Set; M = _ in (A : Set) → H ≡ Fence (M (id A)) test A = refl -- Expected output: -- M remains unsolved, -- but H is solved by pruning the argument of M!
{ "alphanum_fraction": 0.6120906801, "avg_line_length": 20.8947368421, "ext": "agda", "hexsha": "a07141485ea459985903d2f5681680e9a4678222", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/PruneBadRigidDef.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/PruneBadRigidDef.agda", "max_line_length": 64, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/PruneBadRigidDef.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 133, "size": 397 }
{-# OPTIONS --without-K --safe #-} module Reflection.Helpers where open import Agda.Builtin.Reflection open import Function open import Data.List as List using (List; _∷_; []) open import Data.Nat as ℕ using (ℕ; suc; zero) open import Data.Nat.GeneralisedArithmetic using (fold) open import Data.Fin as Fin using (Fin) open import Data.Vec as Vec using (Vec) open import Data.Nat.Table as Table using (Table) open import Data.String using (String) open import Data.Maybe as Maybe using (Maybe; just; nothing) module _ {a} {A : Set a} where pure : A → TC A pure = returnTC {-# INLINE pure #-} infixl 3 _<|>_ _<|>_ : TC A → TC A → TC A _<|>_ = catchTC {-# INLINE _<|>_ #-} module _ {a b} {A : Set a} {B : Set b} where infixl 1 _>>=_ _>>_ _<&>_ _>>=_ : TC A → (A → TC B) → TC B _>>=_ = bindTC {-# INLINE _>>=_ #-} _>>_ : TC A → TC B → TC B xs >> ys = bindTC xs (λ _ → ys) {-# INLINE _>>_ #-} infixl 4 _<$>_ _<*>_ _<$_ _<*>_ : TC (A → B) → TC A → TC B fs <*> xs = bindTC fs (λ f → bindTC xs (λ x → returnTC (f x))) {-# INLINE _<*>_ #-} _<$>_ : (A → B) → TC A → TC B f <$> xs = bindTC xs (λ x → returnTC (f x)) {-# INLINE _<$>_ #-} _<$_ : A → TC B → TC A x <$ xs = bindTC xs (λ _ → returnTC x) {-# INLINE _<$_ #-} _<&>_ : TC A → (A → B) → TC B xs <&> f = bindTC xs (λ x → returnTC (f x)) {-# INLINE _<&>_ #-} infixr 5 _⟨∷⟩_ _⟅∷⟆_ pattern _⟨∷⟩_ x xs = arg (arg-info visible relevant) x ∷ xs pattern _⟅∷⟆_ x xs = arg (arg-info hidden relevant) x ∷ xs infixr 5 _⋯⟅∷⟆_ _⋯⟅∷⟆_ : ℕ → List (Arg Term) → List (Arg Term) zero ⋯⟅∷⟆ xs = xs suc i ⋯⟅∷⟆ xs = unknown ⟅∷⟆ i ⋯⟅∷⟆ xs {-# INLINE _⋯⟅∷⟆_ #-} ℕ′ : ℕ → Term ℕ′ zero = quote zero ⟨ con ⟩ [] ℕ′ (suc i) = quote suc ⟨ con ⟩ ℕ′ i ⟨∷⟩ [] Fin′ : ℕ → Term Fin′ zero = quote Fin.zero ⟨ con ⟩ 1 ⋯⟅∷⟆ [] Fin′ (suc i) = quote Fin.suc ⟨ con ⟩ 1 ⋯⟅∷⟆ Fin′ i ⟨∷⟩ [] curriedTerm : Table → Term curriedTerm = List.foldr go (quote Vec.[] ⟨ con ⟩ 2 ⋯⟅∷⟆ []) ∘ Table.toList where go : ℕ → Term → Term go x xs = quote Vec._∷_ ⟨ con ⟩ 3 ⋯⟅∷⟆ var x [] ⟨∷⟩ xs ⟨∷⟩ [] hlams : ∀ {n} → Vec String n → Term → Term hlams vs xs = Vec.foldr (const Term) (λ v vs → lam hidden (abs v vs)) xs vs vlams : ∀ {n} → Vec String n → Term → Term vlams vs xs = Vec.foldr (const Term) (λ v vs → lam visible (abs v vs)) xs vs getVisible : Arg Term → Maybe Term getVisible (arg (arg-info visible relevant) x) = just x getVisible (arg (arg-info visible irrelevant) x) = nothing getVisible (arg (arg-info hidden r) x) = nothing getVisible (arg (arg-info instance′ r) x) = nothing getArgs : ∀ n → Term → Maybe (Vec Term n) getArgs n (def _ xs) = Maybe.map Vec.reverse (List.foldl f b (List.mapMaybe getVisible xs) n) where f : (∀ n → Maybe (Vec Term n)) → Term → ∀ n → Maybe (Vec Term n) f xs x zero = just Vec.[] f xs x (suc n) = Maybe.map (x Vec.∷_) (xs n) b : ∀ n → Maybe (Vec Term n) b zero = just Vec.[] b (suc _ ) = nothing getArgs _ _ = nothing open import Data.Product underPi : Term → ∃[ n ] (Vec String n × Term) underPi = go (λ xs y → _ , xs , y) where go : {A : Set} → (∀ {n} → Vec String n → Term → A) → Term → A go k (pi a (abs s x)) = go (k ∘ (s Vec.∷_)) x go k t = k Vec.[] t
{ "alphanum_fraction": 0.5645363409, "avg_line_length": 29.2844036697, "ext": "agda", "hexsha": "74b93dd5f052f65cdb711998ec3e8b80c24b3887", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-20T07:07:11.000Z", "max_forks_repo_forks_event_min_datetime": "2019-04-16T02:23:16.000Z", "max_forks_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/agda-ring-solver", "max_forks_repo_path": "src/Reflection/Helpers.agda", "max_issues_count": 5, "max_issues_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_issues_repo_issues_event_max_datetime": "2022-03-12T01:55:42.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-17T20:48:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mckeankylej/agda-ring-solver", "max_issues_repo_path": "src/Reflection/Helpers.agda", "max_line_length": 93, "max_stars_count": 36, "max_stars_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/agda-ring-solver", "max_stars_repo_path": "src/Reflection/Helpers.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-15T00:57:55.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-25T16:40:52.000Z", "num_tokens": 1276, "size": 3192 }
{-# OPTIONS --cubical --no-import-sorts #-} module Bundles where open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero) private variable ℓ ℓ' ℓ'' : Level open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc) open import Cubical.Structures.CommRing open import Cubical.Relation.Nullary.Base -- ¬_ open import Cubical.Relation.Binary.Base open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_) open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_) open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim` -- open import Cubical.Structures.Poset open import Cubical.Foundations.Function open import Cubical.Structures.Ring open import Cubical.Foundations.Logic renaming (¬_ to ¬ᵖ_) open import Function.Base using (_∋_) -- open import Function.Reasoning using (∋-syntax) open import Function.Base using (it) -- instance search open import Utils open import MoreLogic open MoreLogic.Reasoning open MoreLogic.Properties open import MoreAlgebra open MoreAlgebra.Definitions open MoreAlgebra.Consequences -- 4.1 Algebraic structure of numbers -- -- Fields have the property that nonzero numbers have a multiplicative inverse, or more precisely, that -- (∀ x : F) x ≠ 0 ⇒ (∃ y : F) x · y = 1. -- -- Remark 4.1.1. -- If we require the collection of numbers to form a set in the sense of Definition 2.5.4, and satisfy the ring axioms, then multiplicative inverses are unique, so that the above is equivalent to the proposition -- (Π x : F) x ≠ 0 ⇒ (Σ y : F) x · y = 1. -- -- Definition 4.1.2. -- A classical field is a set F with points 0, 1 : F, operations +, · : F → F → F, which is a commutative ring with unit, such that -- (∀ x : F) x ≠ 0 ⇒ (∃ y : F) x · y = 1. module ClassicalFieldModule where record IsClassicalField {F : Type ℓ} (0f : F) (1f : F) (_+_ : F → F → F) (_·_ : F → F → F) (-_ : F → F) (_⁻¹ᶠ : (x : F) → {{¬(x ≡ 0f)}} → F) : Type ℓ where constructor isclassicalfield field isCommRing : IsCommRing 0f 1f _+_ _·_ -_ ·-rinv : (x : F) → (p : ¬(x ≡ 0f)) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f ·-linv : (x : F) → (p : ¬(x ≡ 0f)) → (_⁻¹ᶠ x {{p}}) · x ≡ 1f open IsCommRing {0r = 0f} {1r = 1f} isCommRing public record ClassicalField : Type (ℓ-suc ℓ) where field Carrier : Type ℓ 0f : Carrier 1f : Carrier _+_ : Carrier → Carrier → Carrier _·_ : Carrier → Carrier → Carrier -_ : Carrier → Carrier _⁻¹ᶠ : (x : Carrier) → {{¬(x ≡ 0f)}} → Carrier isClassicalField : IsClassicalField 0f 1f _+_ _·_ -_ _⁻¹ᶠ infix 9 _⁻¹ᶠ infix 8 -_ infixl 7 _·_ infixl 6 _+_ open IsClassicalField isClassicalField public -- Remark 4.1.3. -- As in the classical case, by proving that additive and multiplicative inverses are unique, we also obtain the negation and division operations. -- -- For the reals, the assumption x ≠ 0 does not give us any information allowing us to bound x away from 0, which we would like in order to compute multiplicative inverses. -- Hence, we give a variation on the denition of fields in which the underlying set comes equipped with an apartness relation #, which satises x # y ⇒ x ≠ y, although the converse implication may not hold. -- This apartness relation allows us to make appropriate error bounds and compute multiplicative inverses based on the assumption x # 0. -- -- NOTE: there is also PropRel in Cubical.Relation.Binary.Base which -- NOTE: one needs these "all-lowercase constructors" to make use of copatterns -- NOTE: see also Relation.Binary.Indexed.Homogeneous.Definitions.html -- NOTE: see also Algebra.Definitions.html -- Definition 4.1.5. -- A constructive field is a set F with points 0, 1 : F, binary operations +, · : F → F → F, and a binary relation # such that -- 1. (F, 0, 1, +, ·) is a commutative ring with unit; -- 2. x : F has a multiplicative inverse iff x # 0; -- 3. + is #-extensional, that is, for all w, x, y, z : F -- w + x # y + z ⇒ w # y ∨ x # z. record IsConstructiveField {F : Type ℓ} (0f : F) (1f : F) (_+_ : F → F → F) (_·_ : F → F → F) (-_ : F → F) (_#_ : hPropRel F F ℓ') (_⁻¹ᶠ : (x : F) → {{[ x # 0f ]}} → F) : Type (ℓ-max ℓ ℓ') where constructor isconstructivefield field isCommRing : IsCommRing 0f 1f _+_ _·_ -_ ·-rinv : ∀ x → (p : [ x # 0f ]) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f ·-linv : ∀ x → (p : [ x # 0f ]) → (_⁻¹ᶠ x {{p}}) · x ≡ 1f ·-inv-back : ∀ x y → (x · y ≡ 1f) → [ x # 0f ] × [ y # 0f ] #-tight : ∀ x y → ¬([ x # y ]) → x ≡ y -- NOTE: the following ⊎ caused trouble two times with resolving ℓ or ℓ' +-#-extensional : ∀ w x y z → [ (w + x) # (y + z) ] → [ (w # y) ⊔ (x # z) ] isApartnessRel : IsApartnessRelᵖ _#_ open IsCommRing {0r = 0f} {1r = 1f} isCommRing public open IsApartnessRelᵖ isApartnessRel public renaming ( isIrrefl to #-irrefl ; isSym to #-sym ; isCotrans to #-cotrans ) record ConstructiveField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where constructor constructivefield field Carrier : Type ℓ 0f : Carrier 1f : Carrier _+_ : Carrier → Carrier → Carrier _·_ : Carrier → Carrier → Carrier -_ : Carrier → Carrier _#_ : hPropRel Carrier Carrier ℓ' _⁻¹ᶠ : (x : Carrier) → {{[ x # 0f ]}} → Carrier isConstructiveField : IsConstructiveField 0f 1f _+_ _·_ -_ _#_ _⁻¹ᶠ infix 9 _⁻¹ᶠ infixl 7 _·_ infix 6 -_ infixl 5 _+_ infixl 4 _#_ open IsConstructiveField isConstructiveField public -- Definition 4.1.8. -- Let (A, ≤) be a partial order, and let min, max : A → A → A be binary operators on A. We say that (A, ≤, min, max) is a lattice if min computes greatest lower bounds in the sense that for every x, y, z : A, we have -- z ≤ min(x,y) ⇔ z ≤ x ∧ z ≤ y, -- and max computes least upper bounds in the sense that for every x, y, z : A, we have -- max(x,y) ≤ z ⇔ x ≤ z ∧ y ≤ z. record IsLattice {A : Type ℓ} (_≤_ : Rel A A ℓ') (min max : A → A → A) : Type (ℓ-max ℓ ℓ') where constructor islattice field isPartialOrder : IsPartialOrder _≤_ glb : ∀ x y z → z ≤ min x y → z ≤ x × z ≤ y glb-back : ∀ x y z → z ≤ x × z ≤ y → z ≤ min x y lub : ∀ x y z → max x y ≤ z → x ≤ z × y ≤ z lub-back : ∀ x y z → x ≤ z × y ≤ z → max x y ≤ z open IsPartialOrder isPartialOrder public renaming ( isRefl to ≤-refl ; isAntisym to ≤-antisym ; isTrans to ≤-trans ) record Lattice : Type (ℓ-suc (ℓ-max ℓ ℓ')) where constructor lattice field Carrier : Type ℓ _≤_ : Rel Carrier Carrier ℓ' min max : Carrier → Carrier → Carrier isLattice : IsLattice _≤_ min max infixl 4 _≤_ open IsLattice isLattice public -- Remark 4.1.9.2 -- 1. From the fact that (A, ≤, min, max) is a lattice, it does not follow that for every x and y, min(x,y) = x ∨ min(x,y) = y. However, we can characterize min as -- z < min(x,y) ⇔ z < x ∨ z < y -- and similarly for max, see Lemma 6.7.1. -- 2. In a partial order, for two fixed elements a and b, all joins and meets of a, b are equal, so that Lemma 2.6.20 the type of joins and the type of meets are propositions. Hence, providing the maps min and max as in the above definition is equivalent to the showing the existenceof all binary joins and meets. -- -- The following definition is modified from on The Univalent Foundations Program [89, Definition 11.2.7]. -- -- Definition 4.1.10. -- An ordered field is a set F together with constants 0, 1, operations +, ·, min, max, and a binary relation < such that: -- 1. (F, 0, 1, +, ·) is a commutative ring with unit; -- 2. < is a strict [partial] order; -- 3. x : F has a multiplicative inverse iff x # 0, recalling that # is defined as in Lemma 4.1.7; -- 4. ≤, as in Lemma 4.1.7, is antisymmetric, so that (F, ≤) is a partial order; -- 5. (F, ≤, min, max) is a lattice. -- 6. for all x, y, z, w : F: -- x + y < z + w ⇒ x < z ∨ y < w, (†) -- 0 < z ∧ x < y ⇒ x z < y z. (∗) -- Our notion of ordered fields coincides with The Univalent Foundations Program [89, Definition 11.2.7]. -- NOTE: well, the HOTT book definition organizes things slightly different. Why prefer one approach over the other? record IsAlmostOrderedField {F : Type ℓ} (0f 1f : F) (_+_ : F → F → F) (-_ : F → F) (_·_ min max : F → F → F) (_<_ _#_ _≤_ : Rel F F ℓ') (_⁻¹ᶠ : (x : F) → {{x # 0f}} → F) : Type (ℓ-max ℓ ℓ') where field -- 1. isCommRing : IsCommRing 0f 1f _+_ _·_ -_ -- 2. <-isStrictPartialOrder : IsStrictPartialOrder _<_ -- 3. ·-rinv : (x : F) → (p : x # 0f) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f ·-linv : (x : F) → (p : x # 0f) → (_⁻¹ᶠ x {{p}}) · x ≡ 1f ·-inv-back : (x y : F) → (x · y ≡ 1f) → x # 0f × y # 0f -- 4. NOTE: we already have ≤-isPartialOrder in <-isLattice -- ≤-isPartialOrder : IsPartialOrder _≤_ -- 5. ≤-isLattice : IsLattice _≤_ min max open IsCommRing {0r = 0f} {1r = 1f} isCommRing public open IsStrictPartialOrder <-isStrictPartialOrder public renaming ( isIrrefl to <-irrefl ; isTrans to <-trans ; isCotrans to <-cotrans ) open IsLattice ≤-isLattice public record AlmostOrderedField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where constructor orderedfield field Carrier : Type ℓ 0f 1f : Carrier _+_ : Carrier → Carrier → Carrier -_ : Carrier → Carrier _·_ : Carrier → Carrier → Carrier min max : Carrier → Carrier → Carrier _<_ : Rel Carrier Carrier ℓ' <-isProp : ∀ x y → isProp (x < y) _#_ = _#'_ {_<_ = _<_} _≤_ = _≤'_ {_<_ = _<_} field _⁻¹ᶠ : (x : Carrier) → {{x # 0f}} → Carrier isAlmostOrderedField : IsAlmostOrderedField 0f 1f _+_ -_ _·_ min max _<_ _#_ _≤_ _⁻¹ᶠ infix 9 _⁻¹ᶠ infixl 7 _·_ infix 6 -_ infixl 5 _+_ infixl 4 _#_ infixl 4 _≤_ infixl 4 _<_ open IsAlmostOrderedField isAlmostOrderedField public #-isProp : ∀ x y → isProp (x # y) #-isProp = #-from-<-isProp _<_ <-isStrictPartialOrder <-isProp record IsOrderedField {F : Type ℓ} (0f 1f : F) (_+_ : F → F → F) (-_ : F → F) (_·_ min max : F → F → F) (_<_ _#_ _≤_ : Rel F F ℓ') (_⁻¹ᶠ : (x : F) → {{x # 0f}} → F) : Type (ℓ-max ℓ ℓ') where constructor isorderedfield field -- 1. 2. 3. 4. 5. isAlmostOrderedField : IsAlmostOrderedField 0f 1f _+_ -_ _·_ min max _<_ _#_ _≤_ _⁻¹ᶠ -- 6. (†) -- NOTE: this is 'shifted' from the pevious definition of #-extensionality for + .. does the name still fit? +-<-extensional : ∀ w x y z → (x + y) < (z + w) → (x < z) ⊎ (y < w) -- 6. (∗) ·-preserves-< : ∀ x y z → 0f < z → x < y → (x · z) < (y · z) open IsAlmostOrderedField isAlmostOrderedField public record OrderedField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where constructor orderedfield field Carrier : Type ℓ 0f 1f : Carrier _+_ : Carrier → Carrier → Carrier -_ : Carrier → Carrier _·_ : Carrier → Carrier → Carrier min max : Carrier → Carrier → Carrier _<_ : Rel Carrier Carrier ℓ' <-isProp : ∀ x y → isProp (x < y) _#_ = _#'_ {_<_ = _<_} _≤_ = _≤'_ {_<_ = _<_} field _⁻¹ᶠ : (x : Carrier) → {{x # 0f}} → Carrier isOrderedField : IsOrderedField 0f 1f _+_ -_ _·_ min max _<_ _#_ _≤_ _⁻¹ᶠ infix 9 _⁻¹ᶠ infixl 7 _·_ infix 6 -_ infixl 5 _+_ infixl 4 _#_ infixl 4 _≤_ infixl 4 _<_ open IsOrderedField isOrderedField public abstract -- NOTE: there might be some reason not to "do" (or "open") all the theory of a record within that record +-preserves-< : ∀ a b x → a < b → a + x < b + x +-preserves-< a b x a<b = ( a < b ⇒⟨ transport (λ i → sym (fst (+-identity a)) i < sym (fst (+-identity b)) i) ⟩ a + 0f < b + 0f ⇒⟨ transport (λ i → a + sym (+-rinv x) i < b + sym (+-rinv x) i) ⟩ a + (x - x) < b + (x - x) ⇒⟨ transport (λ i → +-assoc a x (- x) i < +-assoc b x (- x) i) ⟩ (a + x) - x < (b + x) - x ⇒⟨ +-<-extensional (- x) (a + x) (- x) (b + x) ⟩ (a + x < b + x) ⊎ (- x < - x) ⇒⟨ (λ{ (inl a+x<b+x) → a+x<b+x -- somehow ⊥-elim needs a hint in the next line ; (inr -x<-x ) → ⊥-elim {A = λ _ → (a + x < b + x)} (<-irrefl (- x) -x<-x) }) ⟩ a + x < b + x ◼) a<b ≤-isPreorder : IsPreorder _≤_ ≤-isPreorder = ≤-isPreorder' {_<_ = _<_} {<-isStrictPartialOrder} -- Definition 4.3.1. -- A morphism from an ordered field (F, 0F , 1F , +F , ·F , minF , maxF , <F ) -- to an ordered field (G, 0G , 1G , +G , ·G , minG , maxG , <G ) -- is a map f : F → G such that -- 1. f is a morphism of rings, -- 2. f reflects < in the sense that for every x, y : F -- f (x) <G f (y) ⇒ x <F y. -- NOTE: see Cubical.Structures.Group.Morphism -- and Cubical.Structures.Group.MorphismProperties -- open import Cubical.Structures.Group.Morphism record IsRingMor {ℓ ℓ'} (F : Ring {ℓ}) (G : Ring {ℓ'}) (f : (Ring.Carrier F) → (Ring.Carrier G)) : Type (ℓ-max ℓ ℓ') where module F = Ring F module G = Ring G field preserves-+ : ∀ a b → f (a F.+ b) ≡ f a G.+ f b preserves-· : ∀ a b → f (a F.· b) ≡ f a G.· f b perserves-1 : f F.1r ≡ G.1r record IsOrderedFieldMor {ℓ ℓ' ℓₚ ℓₚ'} -- NOTE: this is a lot of levels. Can we get rid of some of these? (F : OrderedField {ℓ} {ℓₚ}) (G : OrderedField {ℓ'} {ℓₚ'}) -- (let module F = OrderedField F) -- NOTE: `let` is not allowed in a telescope -- (let module G = OrderedField G) (f : (OrderedField.Carrier F) → (OrderedField.Carrier G)) : Type (ℓ-max (ℓ-max ℓ ℓ') (ℓ-max ℓₚ ℓₚ')) where module F = OrderedField F module G = OrderedField G field isRingMor : IsRingMor (record {F}) (record {G}) f reflects-< : ∀ x y → f x G.< f y → x F.< y -- NOTE: for more properties, see https://en.wikipedia.org/wiki/Ring_homomorphism#Properties record OrderedFieldMor {ℓ ℓ' ℓₚ ℓₚ'} (F : OrderedField {ℓ} {ℓₚ}) (G : OrderedField {ℓ'} {ℓₚ'}) : Type (ℓ-max (ℓ-max ℓ ℓ') (ℓ-max ℓₚ ℓₚ')) where constructor orderedfieldmor module F = OrderedField F module G = OrderedField G field fun : F.Carrier → G.Carrier isOrderedFieldMor : IsOrderedFieldMor F G fun -- NOTE: f preserves P: P A ⇒ P (f A) -- f reflects P: P (f A) ⇒ P A -- Remark 4.3.2. The contrapositive of reflecting < means preserving ≤.
{ "alphanum_fraction": 0.5925797021, "avg_line_length": 40.0167130919, "ext": "agda", "hexsha": "dc0d1e4f7bfa81e9e3afcbc2a9ad1afb868ae68c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mchristianl/synthetic-reals", "max_forks_repo_path": "agda/Bundles.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mchristianl/synthetic-reals", "max_issues_repo_path": "agda/Bundles.agda", "max_line_length": 313, "max_stars_count": 3, "max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mchristianl/synthetic-reals", "max_stars_repo_path": "agda/Bundles.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z", "num_tokens": 5345, "size": 14366 }
------------------------------------------------------------------------ -- Soundness of normalization w.r.t. to declarative kinding of Fω with -- interval kinds ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module FOmegaInt.Kinding.Declarative.Normalization where open import Data.Fin using (zero) open import Data.Fin.Substitution open import Data.Product using (_,_; proj₂; _×_) open import Data.Vec using ([]) open import Relation.Binary.PropositionalEquality hiding ([_]) open import FOmegaInt.Syntax open import FOmegaInt.Syntax.HereditarySubstitution open import FOmegaInt.Syntax.Normalization open import FOmegaInt.Typing open import FOmegaInt.Typing.Validity open Syntax open TermCtx open Substitution hiding (subst) open ContextConversions open Typing open TypedSubstitution ------------------------------------------------------------------------ -- Soundness of hereditary substitutions -- NOTE. The following are corollaries of the corresponding soundness -- lemmas using untyped β-reduction and the subject reduction property -- for kinding (see the Syntax.HereditarySubstitution and -- Typing.Validity modules for details). -- Soundness of hereditary substitution: the results of ordinary and -- hereditary substitutions in well-formed kinds resp. well-kinded -- types are equal (w.r.t. type resp. kind equality). kd-⌞⌟-[]-≅ : ∀ {n} {Γ : Ctx n} {j k a} → kd ⌞ j ⌟Kd ∷ Γ ⊢ ⌞ k ⌟Kd kd → Γ ⊢Tp ⌞ a ⌟ ∈ ⌞ j ⌟Kd → Γ ⊢ ⌞ k ⌟Kd Kind[ ⌞ a ⌟ ] ≅ ⌞ k Kind[ a ∈ ⌊ j ⌋ ] ⌟Kd kd-⌞⌟-[]-≅ {k = k} ⌞k⌟-kd ⌞a⌟∈⌞j⌟ = kd-→β*-≅ (kd-[] ⌞k⌟-kd (∈-tp ⌞a⌟∈⌞j⌟)) (⌞⌟Kd-/⟨⟩-β k) Tp∈-⌞⌟-[]-≃ : ∀ {n} {Γ : Ctx n} {j a k b} → kd ⌞ j ⌟Kd ∷ Γ ⊢Tp ⌞ a ⌟ ∈ ⌞ k ⌟Kd → Γ ⊢Tp ⌞ b ⌟ ∈ ⌞ j ⌟Kd → Γ ⊢ ⌞ a ⌟ [ ⌞ b ⌟ ] ≃ ⌞ a [ b ∈ ⌊ j ⌋ ] ⌟ ∈ ⌞ k ⌟Kd Kind[ ⌞ b ⌟ ] Tp∈-⌞⌟-[]-≃ {a = a} ⌞a⌟∈⌞k⌟ ⌞b⌟∈⌞j⌟ = Tp∈-→β*-≃ (Tp∈-[] ⌞a⌟∈⌞k⌟ (∈-tp ⌞b⌟∈⌞j⌟)) (⌞⌟-/⟨⟩-β a) -- Soundness of potentially reducing application: ordinary and -- potentially reducing application of well-kinded types are equal -- (w.r.t. type equality). Tp∈-⌞⌟-·-≃ : ∀ {n} {Γ : Ctx n} {a b j k} → Γ ⊢Tp ⌞ a ⌟ ∈ Π j k → Γ ⊢Tp ⌞ b ⌟ ∈ j → Γ ⊢ ⌞ a ⌟ · ⌞ b ⌟ ≃ ⌞ a ↓⌜·⌝ b ⌟ ∈ k Kind[ ⌞ b ⌟ ] Tp∈-⌞⌟-·-≃ {_} {_} {a} {b} {j} {k} ⌞a⌟∈Πjk ⌞b⌟∈j = Tp∈-→β*-≃ (∈-Π-e ⌞a⌟∈Πjk ⌞b⌟∈j) (⌞⌟-↓⌜·⌝-β a b) ------------------------------------------------------------------------ -- Soundness of η-expansion. module TrackSimpleKindsDeclarativeEtaExp where open RenamingCommutes open SimpHSubstLemmas private module V = VarSubst module TK = TrackSimpleKindsEtaExp -- NOTE. The definition of the function Tp∈-⌞⌟-≃-η below is -- structurally recursive in the *shape* parameter k, but *not* in -- the kind j because we need to weaken the domain j₁ of the -- dependent kind (j = Π j₁ j₂) in the arrow case. The additional -- hypothesis ⌊ j ⌋≡ k ensures that k is indeed the shape of the -- kind j. -- Well-kinded neutrals are equal to to their η-expansions. Tp∈-⌞⌟-≃-η : ∀ {n} {Γ : Ctx n} {x as j k} (hyp : ⌊ j ⌋≡ k) → Γ ⊢ ⌞ j ⌟Kd kd → Γ ⊢Tp ⌞ var x ∙ as ⌟ ∈ ⌞ j ⌟Kd → Γ ⊢ ⌞ var x ∙ as ⌟ ≃ ⌞ TK.η-exp j hyp (var x ∙ as) ⌟ ∈ ⌞ j ⌟Kd Tp∈-⌞⌟-≃-η is-★ ⌞b₂⋯c₂⌟-kd ⌞x∙as⌟∈⌞b₁⋯c₁⌟ = ≃-refl ⌞x∙as⌟∈⌞b₁⋯c₁⌟ Tp∈-⌞⌟-≃-η {_} {Γ} {x} {as} (is-⇒ {j₁} {j₂} ⌊j₁⌋≡k₁ ⌊j₂⌋≡k₂) (kd-Π ⌞j₁⌟-kd ⌞j₂⌟-kd) ⌞x∙as⌟∈⌞Πj₁j₂⌟ = begin ⌞ var x ∙ as ⌟ ≃⟨ ≃-sym (≃-η ⌞x∙as⌟∈⌞Πj₁j₂⌟) ⟩ Λ ⌞ j₁ ⌟Kd (weaken ⌞ var x ∙ as ⌟ · var zero) ≃⟨ ≃-λ′ (≅-refl ⌞j₁⌟-kd) (begin weaken ⌞ var x ∙ as ⌟ · var zero ≃⟨ ⌞x∙as⌟·z≃⌞x∙as⌟·⌞η-z⌟∈⌞j₂⌟ ⟩ weaken ⌞ var x ∙ as ⌟ · ⌞ TK.η-exp (weakenKind′ _) (⌊⌋≡-weaken ⌊j₁⌋≡k₁) (var∙ zero) ⌟ ≡⟨ ⌞x∙as⌟·⌞η-z⌟≡⌞x∙as⌜·⌝η-z⌟ ⟩ ⌞ weakenElim (var x ∙ as) ⌜·⌝ TK.η-exp (weakenKind′ _) (⌊⌋≡-weaken ⌊j₁⌋≡k₁) (var∙ zero) ⌟ ≃⟨ Tp∈-⌞⌟-≃-η ⌊j₂⌋≡k₂ ⌞j₂⌟-kd (subst (_ ⊢Tp_∈ _) ⌞x∙as⌟·⌞η-z⌟≡⌞x∙as⌜·⌝η-z⌟ ⌞x∙as⌟·⌞η-z⌟∈⌞j₂⌟) ⟩ ⌞ TK.η-exp j₂ ⌊j₂⌋≡k₂ _ ⌟ ∎) ⟩ ⌞ TK.η-exp (Π j₁ j₂) (is-⇒ ⌊j₁⌋≡k₁ ⌊j₂⌋≡k₂) (var x ∙ as) ⌟ ∎ where ⌞j₁⌟-wf = wf-kd ⌞j₁⌟-kd ⌞j₁⌟′-kd = kd-weaken ⌞j₁⌟-wf ⌞j₁⌟-kd ⌞j₁⌟′≡⌞j₁′⌟ = sym (⌞⌟Kd-/Var j₁) ⌞j₁′⌟-kd = subst (kd ⌞ j₁ ⌟Kd ∷ _ ⊢_kd) ⌞j₁⌟′≡⌞j₁′⌟ ⌞j₁⌟′-kd ⌞j₁⌟∷Γ-ctx = ⌞j₁⌟-wf ∷ Tp∈-ctx ⌞x∙as⌟∈⌞Πj₁j₂⌟ ⌞x∙as⌟′∈⌞Πj₁j₂′⌟ = subst (kd ⌞ j₁ ⌟Kd ∷ Γ ⊢Tp weaken ⌞ var x ∙ as ⌟ ∈_) (sym (⌞⌟Kd-/Var (Π j₁ j₂))) (Tp∈-weaken ⌞j₁⌟-wf ⌞x∙as⌟∈⌞Πj₁j₂⌟) z∈⌞j₁⌟ = ∈-var zero ⌞j₁⌟∷Γ-ctx (cong kd ⌞j₁⌟′≡⌞j₁′⌟ ) z≃η-z∈⌞j₁⌟ = Tp∈-⌞⌟-≃-η (⌊⌋≡-weaken ⌊j₁⌋≡k₁) ⌞j₁′⌟-kd z∈⌞j₁⌟ ⌞j₂′⌟[z]≡⌞j₂⌟ = begin ⌞ j₂ Kind′/Var V.wk V.↑ ⌟Kd Kind[ var zero ] ≡⟨ cong (_Kind[ var zero ]) (⌞⌟Kd-/Var j₂) ⟩ (⌞ j₂ ⌟Kd Kind/Var V.wk V.↑) Kind[ var zero ] ≡⟨ Kind-wk↑-sub-zero-vanishes ⌞ j₂ ⌟Kd ⟩ ⌞ j₂ ⌟Kd ∎ where open ≡-Reasoning ⌞x∙as⌟·z≃⌞x∙as⌟·⌞η-z⌟∈⌞j₂⌟ = subst (_ ⊢ _ ≃ _ ∈_) ⌞j₂′⌟[z]≡⌞j₂⌟ (≃-· (≃-refl (⌞x∙as⌟′∈⌞Πj₁j₂′⌟)) z≃η-z∈⌞j₁⌟) ⌞x∙as⌟·⌞η-z⌟∈⌞j₂⌟ = proj₂ (≃-valid ⌞x∙as⌟·z≃⌞x∙as⌟·⌞η-z⌟∈⌞j₂⌟) ⌞x∙as⌟·⌞η-z⌟≡⌞x∙as⌜·⌝η-z⌟ = begin weaken ⌞ var x ∙ as ⌟ · ⌞ TK.η-exp (weakenKind′ _) (⌊⌋≡-weaken ⌊j₁⌋≡k₁) (var∙ zero) ⌟ ≡⟨ cong (_· _) (sym (⌞⌟-/Var (var x ∙ as))) ⟩ ⌞ weakenElim (var x ∙ as) ⌟ · ⌞ TK.η-exp (weakenKind′ _) (⌊⌋≡-weaken ⌊j₁⌋≡k₁) (var∙ zero) ⌟ ≡⟨ sym (⌞⌟-· (weakenElim (var x ∙ as)) _) ⟩ ⌞ weakenElim (var x ∙ as) ⌜·⌝ TK.η-exp (weakenKind′ _) (⌊⌋≡-weaken ⌊j₁⌋≡k₁) (var∙ zero) ⌟ ∎ where open ≡-Reasoning open ≃-Reasoning private module TK = TrackSimpleKindsDeclarativeEtaExp -- Soundness of η-expansion of neutrals: well-kinded neutral types are -- equal to their η-expansions (w.r.t. to type equality). Tp∈-⌞⌟-≃-η : ∀ {n} {Γ : Ctx n} {x as k} → Γ ⊢Tp ⌞ var x ∙ as ⌟ ∈ ⌞ k ⌟Kd → Γ ⊢ ⌞ var x ∙ as ⌟ ≃ ⌞ η-exp k (var x ∙ as) ⌟ ∈ ⌞ k ⌟Kd Tp∈-⌞⌟-≃-η ⌞x∙as⌟∈⌞k⌟ = TK.Tp∈-⌞⌟-≃-η (⌊⌋-⌊⌋≡ _) (Tp∈-valid ⌞x∙as⌟∈⌞k⌟) ⌞x∙as⌟∈⌞k⌟ ------------------------------------------------------------------------ -- Soundness of normalization mutual -- Soundness of normalization: well-formed kinds and well-kinded -- types are equal to their normal forms (w.r.t. to kind resp. type -- equality). Tp∈-≃-⌞⌟-nf : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a ≃ ⌞ nf (nfCtx Γ) a ⌟ ∈ k Tp∈-≃-⌞⌟-nf {_} {Γ} (∈-var {k} x Γ-ctx Γ[x]≡kd-k) with ElimCtx.lookup (nfCtx Γ) x | nfCtx-lookup-kd x Γ Γ[x]≡kd-k ... | kd ._ | refl = ≃-⇑ (Tp∈-⌞⌟-≃-η (∈-⇑ (∈-var x Γ-ctx Γ[x]≡kd-k) (≅⇒<∷ k≅⌞nf-k⌟))) (≅⇒<∷ (≅-sym k≅⌞nf-k⌟)) where open ≡-Reasoning open CtxEqOps using (lookup-≃-kd) Γ≃⌞nf-Γ⌟ = ctx-≃-⌞⌟-nf Γ-ctx ⌞nf-Γ⌟[x]≡kd-⌞k⌟ = begin lookup ⌞ nfCtx Γ ⌟Ctx x ≡⟨ ⌞⌟Asc-lookup (nfCtx Γ) x ⟩ ⌞ ElimCtx.lookup (nfCtx Γ) x ⌟Asc ≡⟨ cong ⌞_⌟Asc (nfCtx-lookup-kd x Γ Γ[x]≡kd-k) ⟩ kd ⌞ nfKind (nfCtx Γ) k ⌟Kd ∎ k≅⌞nf-k⌟ : Γ ⊢ k ≅ ⌞ nfKind (nfCtx Γ) k ⌟Kd k≅⌞nf-k⌟ = lookup-≃-kd x Γ≃⌞nf-Γ⌟ Γ[x]≡kd-k ⌞nf-Γ⌟[x]≡kd-⌞k⌟ Tp∈-≃-⌞⌟-nf (∈-⊥-f Γ-ctx) = ≃-refl (∈-⊥-f Γ-ctx) Tp∈-≃-⌞⌟-nf (∈-⊤-f Γ-ctx) = ≃-refl (∈-⊤-f Γ-ctx) Tp∈-≃-⌞⌟-nf (∈-∀-f k-kd a∈*) = ≃-∀ (kd-≅-⌞⌟-nf k-kd) (Tp∈-≃-⌞⌟-nf a∈*) Tp∈-≃-⌞⌟-nf (∈-→-f a∈* b∈*) = ≃-→ (Tp∈-≃-⌞⌟-nf a∈*) (Tp∈-≃-⌞⌟-nf b∈*) Tp∈-≃-⌞⌟-nf (∈-Π-i j-kd a∈k) = ≃-λ′ (kd-≅-⌞⌟-nf j-kd) (Tp∈-≃-⌞⌟-nf a∈k) Tp∈-≃-⌞⌟-nf {_} {Γ} (∈-Π-e {a} {b} {j} {k} a∈Πjk b∈j) with Tp∈-valid a∈Πjk ... | (kd-Π j-kd k-kd) = begin a · b ≃⟨ ≃-· a≃⌞nf-a⌟∈Πjk b≃⌞nf-b⌟∈j ⟩ ⌞ nf (nfCtx Γ) a ⌟ · ⌞ nf (nfCtx Γ) b ⌟ ≃⟨ ≃-⇑ (Tp∈-⌞⌟-·-≃ {a = nf (nfCtx Γ) a} {nf (nfCtx Γ) b} ⌞nf-a⌟∈Πjk ⌞nf-b⌟∈j) (≅⇒<∷ (≅-sym (kd-[≃] k-kd b≃⌞nf-b⌟∈j))) ⟩ ⌞ nf (nfCtx Γ) a ↓⌜·⌝ nf (nfCtx Γ) b ⌟ ∎ where open ≃-Reasoning a≃⌞nf-a⌟∈Πjk = Tp∈-≃-⌞⌟-nf a∈Πjk ⌞nf-a⌟∈Πjk = proj₂ (≃-valid a≃⌞nf-a⌟∈Πjk) b≃⌞nf-b⌟∈j = Tp∈-≃-⌞⌟-nf b∈j ⌞nf-b⌟∈j = proj₂ (≃-valid b≃⌞nf-b⌟∈j) Tp∈-≃-⌞⌟-nf (∈-s-i a∈b⋯c) = ≃-s-i (Tp∈-≃-⌞⌟-nf a∈b⋯c) Tp∈-≃-⌞⌟-nf (∈-⇑ a∈j j<∷k) = ≃-⇑ (Tp∈-≃-⌞⌟-nf a∈j) j<∷k kd-≅-⌞⌟-nf : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k ≅ ⌞ nfKind (nfCtx Γ) k ⌟Kd kd-≅-⌞⌟-nf (kd-⋯ a∈* b∈*) = ≅-⋯ (Tp∈-≃-⌞⌟-nf a∈* ) (Tp∈-≃-⌞⌟-nf b∈*) kd-≅-⌞⌟-nf (kd-Π j-kd k-kd) = ≅-Π (kd-≅-⌞⌟-nf j-kd) (kd-≅-⌞⌟-nf k-kd) -- Well-formed ascriptions and contexts are equal to their normal -- forms. wf-≃-⌞⌟-nf : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ a wf → Γ ⊢ a ≃ ⌞ nfAsc (nfCtx Γ) a ⌟Asc wf wf-≃-⌞⌟-nf (wf-kd k-kd) = ≃wf-≅ (kd-≅-⌞⌟-nf k-kd) wf-≃-⌞⌟-nf (wf-tp a∈*) = ≃wf-≃ (Tp∈-≃-⌞⌟-nf a∈*) ctx-≃-⌞⌟-nf : ∀ {n} {Γ : Ctx n} → Γ ctx → Γ ≃ ⌞ nfCtx Γ ⌟Ctx ctx ctx-≃-⌞⌟-nf [] = ≃-[] ctx-≃-⌞⌟-nf (a-wf ∷ Γ-ctx) = ≃-∷ (wf-≃-⌞⌟-nf a-wf) (ctx-≃-⌞⌟-nf Γ-ctx) -- Some corollaries. -- The domain and co-domain of universal types are equal to their -- normal forms. Tp∈-∀-≃-⌞⌟-nf : ∀ {n} {Γ : Ctx n} {k a} → Γ ⊢Tp Π k a ∈ * → Γ ⊢ k ≅ ⌞ nfKind (nfCtx Γ) k ⌟Kd × kd k ∷ Γ ⊢ a ≃ ⌞ nf (nfCtx (kd k ∷ Γ)) a ⌟ ∈ * Tp∈-∀-≃-⌞⌟-nf ∀ka∈* with Tp∈-∀-inv ∀ka∈* ... | k-kd , a∈* = kd-≅-⌞⌟-nf k-kd , Tp∈-≃-⌞⌟-nf a∈* -- The domain and co-domain of arrow types are equal to their normal -- forms. Tp∈-→-≃-⌞⌟-nf : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢Tp a ⇒ b ∈ * → Γ ⊢ a ≃ ⌞ nf (nfCtx Γ) a ⌟ ∈ * × Γ ⊢ b ≃ ⌞ nf (nfCtx Γ) b ⌟ ∈ * Tp∈-→-≃-⌞⌟-nf a⇒b∈* with Tp∈-→-inv a⇒b∈* ... | a∈* , b∈* = Tp∈-≃-⌞⌟-nf a∈* , Tp∈-≃-⌞⌟-nf b∈*
{ "alphanum_fraction": 0.4441737718, "avg_line_length": 39.0952380952, "ext": "agda", "hexsha": "bee20462017e7327911996b20ffc974bd3e18352", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_path": "src/FOmegaInt/Kinding/Declarative/Normalization.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z", "max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_path": "src/FOmegaInt/Kinding/Declarative/Normalization.agda", "max_line_length": 79, "max_stars_count": 12, "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_path": "src/FOmegaInt/Kinding/Declarative/Normalization.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z", "max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z", "num_tokens": 6125, "size": 9852 }
-- Andreas, 2017-10-04, issue #2752, report and test case by nad -- -- Problem was: instance does not distribute into mutual blocks. open import Agda.Builtin.List open import Agda.Builtin.Size mutual data Rose (i : Size) (A : Set) : Set where node : List (Rose′ i A) → Rose i A data Rose′ (i : Size) (A : Set) : Set where delay : {j : Size< i} → Rose j A → Rose′ i A record Map (F : Set → Set) : Set₁ where field map : {A B : Set} → (A → B) → F A → F B open Map ⦃ … ⦄ public instance Map-List : Map List Map.map Map-List = λ where f [] → [] f (x ∷ xs) → f x ∷ map f xs instance mutual Map-Rose : ∀ {i} → Map (Rose i) Map.map Map-Rose f (node xs) = node (map (map f) xs) Map-Rose′ : ∀ {i} → Map (Rose′ i) Map.map Map-Rose′ f (delay t) = delay (map f t) -- Was: unresolved instance arguments. -- Should succeed.
{ "alphanum_fraction": 0.5797266515, "avg_line_length": 20.9047619048, "ext": "agda", "hexsha": "58fffb185baab7e1a62edcbdb245d559832ef2d2", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue2752.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue2752.agda", "max_line_length": 64, "max_stars_count": 2, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue2752.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z", "num_tokens": 306, "size": 878 }
module RecordDef where data ⊤ : Set where tt : ⊤ data ⊤' (x : ⊤) : Set where tt : ⊤' x record R {y : ⊤} (y' : ⊤' y) : Set record R {z} _ where postulate r : R {tt} tt
{ "alphanum_fraction": 0.4380952381, "avg_line_length": 7, "ext": "agda", "hexsha": "0ce175c8e1cad647817fe001d2fc6e1c0197f6ac", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "msuperdock/agda-unused", "max_forks_repo_path": "data/declaration/RecordDef.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "msuperdock/agda-unused", "max_issues_repo_path": "data/declaration/RecordDef.agda", "max_line_length": 22, "max_stars_count": 6, "max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "msuperdock/agda-unused", "max_stars_repo_path": "data/declaration/RecordDef.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z", "num_tokens": 98, "size": 210 }
------------------------------------------------------------------------ -- Extra definitions related to simultaneous substitutions ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module Data.Fin.Substitution.Extra where open import Data.Fin using (Fin) open import Data.Fin.Substitution open import Data.Nat using (ℕ; zero; suc; _+_) open import Data.Vec using (_∷_; map) open import Level using (_⊔_) renaming (zero to lzero; suc to lsuc) open import Relation.Unary using (Pred) -- Extension of substitutions and iterated weakening. record Extension {ℓ} (T : Pred ℕ ℓ) : Set ℓ where infixr 5 _/∷_ field weaken : ∀ {n} → T n → T (suc n) -- Weakens Ts. -- Iterated weakening of Ts. weaken⋆ : ∀ m {n} → T n → T (m + n) weaken⋆ zero t = t weaken⋆ (suc m) t = weaken (weaken⋆ m t) -- Extension. -- -- The extension operation t /∷ ρ takes a substitution ρ and extends -- it with a term t for an additional free variable. It is a -- generalization of the lifting substitution ρ ↑ = var zero /∷ ρ -- where the term for the additional free variable may be something -- other than var zero. Note that the term t must itself admit an -- additional free variable so that the resulting substitution t /∷ -- ρ has an extended domain *and* codomain. This is in contrast to -- t ∷ ρ where the codomain has no additional free variables. -- I.e. given (ρ : Sub T m n) we have -- -- t ∷ ρ : Sub T (1 + m) m for t : T m -- u /∷ ρ : Sub T (1 + m) (1 + m) for u : T (1 + m) _/∷_ : ∀ {m n} → T (suc n) → Sub T m n → Sub T (suc m) (suc n) t /∷ ρ = t ∷ map weaken ρ -- A helper module for unpacking an instance of the Simple record -- together with the extra operations from the Extension module (as if -- Simple contained an instance of Extension). module SimpleExt {ℓ} {T : Pred ℕ ℓ} (simple : Simple T) where open Simple simple public extension : Extension T extension = record { weaken = weaken } open Extension extension public hiding (weaken) -- T₂-substitutions in term-like T₁ record TermLikeSubst {ℓ} (T₁ : Pred ℕ ℓ) (T₂ : ℕ → Set) : Set (lsuc (ℓ ⊔ lzero)) where field app : ∀ {T₃} → Lift T₃ T₂ → ∀ {m n} → T₁ m → Sub T₃ m n → T₁ n termSubst : TermSubst T₂ open TermSubst termSubst public hiding (app; var; weaken; _/Var_; _/_; _/✶_) termApplication : Application T₁ T₂ termApplication = record { _/_ = app termLift } varApplication : Application T₁ Fin varApplication = record { _/_ = app varLift } open Application termApplication public using (_/_; _/✶_) open Application varApplication public using () renaming (_/_ to _/Var_) -- Weakening of T₁s. weaken : ∀ {n} → T₁ n → T₁ (suc n) weaken t = t /Var VarSubst.wk
{ "alphanum_fraction": 0.6150849858, "avg_line_length": 34.4390243902, "ext": "agda", "hexsha": "b05a5302cd206f9f4d05182c2e845e7328c46d58", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z", "max_forks_repo_head_hexsha": "ae648c9520895a8428a7ad80f47bb55ecf4d50ea", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "sstucki/f-omega-int-agda", "max_forks_repo_path": "src/Data/Fin/Substitution/Extra.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ae648c9520895a8428a7ad80f47bb55ecf4d50ea", "max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z", "max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "sstucki/f-omega-int-agda", "max_issues_repo_path": "src/Data/Fin/Substitution/Extra.agda", "max_line_length": 75, "max_stars_count": 12, "max_stars_repo_head_hexsha": "ae648c9520895a8428a7ad80f47bb55ecf4d50ea", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "sstucki/f-omega-int-agda", "max_stars_repo_path": "src/Data/Fin/Substitution/Extra.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z", "max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z", "num_tokens": 859, "size": 2824 }
module Prelude.Float where open import Prelude.String postulate Float : Set floatToString : Float -> String stringToFloat : String -> Float {-# BUILTIN FLOAT Float #-} {-# COMPILED_EPIC floatToString (f : Float) -> String = frString(floatToStr(f)) #-} {-# COMPILED_EPIC stringToFloat (s : Any) -> Float = strToFloat(mkString(s)) #-}
{ "alphanum_fraction": 0.6988304094, "avg_line_length": 28.5, "ext": "agda", "hexsha": "da682507182a9663dc2b7206b49b53d6f009e1bb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/agda-kanso", "max_forks_repo_path": "test/epic/Prelude/Float.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/agda-kanso", "max_issues_repo_path": "test/epic/Prelude/Float.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/epic/Prelude/Float.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 92, "size": 342 }
module List.Order.Simple {A : Set}(_≤_ : A → A → Set) where open import Data.List data _*≤_ : List A → A → Set where lenx : {x : A} → [] *≤ x lecx : {x y : A}{ys : List A} → y ≤ x → ys *≤ x → (y ∷ ys) *≤ x data _≤*_ : A → List A → Set where genx : {x : A} → x ≤* [] gecx : {x y : A}{ys : List A} → x ≤ y → x ≤* ys → x ≤* (y ∷ ys)
{ "alphanum_fraction": 0.3063241107, "avg_line_length": 22, "ext": "agda", "hexsha": "66773815ff6b49341cf03d1b112f8548b8e124ac", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/List/Order/Simple.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_path": "agda/List/Order/Simple.agda", "max_line_length": 59, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/List/Order/Simple.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 174, "size": 506 }
{-# OPTIONS --rewriting --confluence-check --double-check #-} data _==_ {A : Set} : (x y : A) → Set where refl : {a : A} → a == a {-# BUILTIN REWRITE _==_ #-} postulate copy : ∀ {X : Set} → X → X A : Set a : A uip : (p : a == a) → p == refl record S : Set where field x : A x-β : x == a open S module T (s : S) where dummy = x-β (copy s) {-# REWRITE dummy #-} y-β-is-refl : x-β (copy s) == refl y-β-is-refl = uip _ -- WAS: Double check complains about solution to meta.
{ "alphanum_fraction": 0.5268389662, "avg_line_length": 20.12, "ext": "agda", "hexsha": "3099c07f5e495c5991d29ba09533952a46c1a85a", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue4158.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue4158.agda", "max_line_length": 76, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue4158.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 190, "size": 503 }
{-# OPTIONS --without-K --safe #-} module Definition.Typed.EqRelInstance where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Weakening open import Definition.Typed.Reduction open import Definition.Typed.EqualityRelation open import Tools.Function -- Judgmental instance of the equality relation instance eqRelInstance : EqRelSet eqRelInstance = record { _⊢_≅_ = _⊢_≡_; _⊢_≅_∷_ = _⊢_≡_∷_; _⊢_~_∷_ = _⊢_≡_∷_; ~-to-≅ₜ = idᶠ; ≅-eq = idᶠ; ≅ₜ-eq = idᶠ; ≅-univ = univ; ≅-sym = sym; ≅ₜ-sym = sym; ~-sym = sym; ≅-trans = trans; ≅ₜ-trans = trans; ~-trans = trans; ≅-conv = conv; ~-conv = conv; ≅-wk = wkEq; ≅ₜ-wk = wkEqTerm; ~-wk = wkEqTerm; ≅-red = reduction; ≅ₜ-red = reductionₜ; ≅-Urefl = refl ∘ᶠ Uⱼ; ≅-ℕrefl = refl ∘ᶠ ℕⱼ; ≅ₜ-ℕrefl = refl ∘ᶠ ℕⱼ; ≅-Emptyrefl = refl ∘ᶠ Emptyⱼ; ≅ₜ-Emptyrefl = refl ∘ᶠ Emptyⱼ; ≅-Unitrefl = refl ∘ᶠ Unitⱼ; ≅ₜ-Unitrefl = refl ∘ᶠ Unitⱼ; ≅ₜ-η-unit = η-unit; ≅-Π-cong = Π-cong; ≅ₜ-Π-cong = Π-cong; ≅-Σ-cong = Σ-cong; ≅ₜ-Σ-cong = Σ-cong; ≅ₜ-zerorefl = refl ∘ᶠ zeroⱼ; ≅-suc-cong = suc-cong; ≅-η-eq = λ x x₁ x₂ x₃ x₄ x₅ → η-eq x x₁ x₂ x₅; ≅-Σ-η = λ ⊢F ⊢G ⊢p ⊢r pProd rProd fst≡ snd≡ → Σ-η ⊢F ⊢G ⊢p ⊢r fst≡ snd≡; ~-var = refl; ~-app = app-cong; ~-fst = fst-cong; ~-snd = snd-cong; ~-natrec = natrec-cong; ~-Emptyrec = Emptyrec-cong }
{ "alphanum_fraction": 0.6002896452, "avg_line_length": 23.0166666667, "ext": "agda", "hexsha": "09448e16be1f102de9c5cf6448d87a7a6bd6aa70", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z", "max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z", "max_forks_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Vtec234/logrel-mltt", "max_forks_repo_path": "Definition/Typed/EqRelInstance.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Vtec234/logrel-mltt", "max_issues_repo_path": "Definition/Typed/EqRelInstance.agda", "max_line_length": 74, "max_stars_count": 30, "max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Vtec234/logrel-mltt", "max_stars_repo_path": "Definition/Typed/EqRelInstance.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z", "max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z", "num_tokens": 704, "size": 1381 }
-- A minor variant of code reported by Andreas Abel. The code below -- should be rejected. open import Agda.Builtin.Size data ⊥ : Set where data SizeLt (i : Size) : Set where size : (j : Size< i) → SizeLt i data D {i : Size} : SizeLt i → Set where c : ∀{i' : Size< i} → ((j : SizeLt i') → D j) → D (size i') f : D (size ∞) → ⊥ f (c h) = f (h (size ∞)) d : ∀{i} s → D {i} s d (size i) = c λ{ (size j) → d (size j) } loop : ⊥ loop = f (d (size ∞))
{ "alphanum_fraction": 0.5404814004, "avg_line_length": 20.7727272727, "ext": "agda", "hexsha": "ae858f86d6edd4b6f31897546491e07ce07141e4", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue1946-2.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue1946-2.agda", "max_line_length": 67, "max_stars_count": 2, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue1946-2.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z", "num_tokens": 182, "size": 457 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types open import LibraBFT.Concrete.System.Parameters open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Consensus.Types.EpochDep open import LibraBFT.ImplShared.Util.Crypto open import Optics.All open import Util.Hash open import Util.KVMap open import Util.Lemmas open import Util.PKCS open import Util.Prelude open import LibraBFT.Abstract.Types.EpochConfig UID NodeId open EpochConfig -- This module defines an abstract system state (represented by a value of type -- 'IntermediateSystemState') for a given concrete state. The culminaton of this -- module is the 'intSystemState' "function" at the bottom, which is probably the -- best place to start understanding this. Longer term, we will also need -- higher-level, cross-epoch properties. open import Yasm.Base open import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms module LibraBFT.Concrete.System where module PerEpoch (𝓔 : EpochConfig) where open WithEC open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 (ConcreteVoteEvidence 𝓔) as Abs hiding (qcVotes; Vote) open import LibraBFT.Concrete.Intermediate 𝓔 (ConcreteVoteEvidence 𝓔) open import LibraBFT.Concrete.Records as LCR open LCR.WithEC 𝓔 module PerState (st : SystemState) where -- * Auxiliary definitions; -- Here we capture the idea that there exists a vote message that -- witnesses the existence of a given Abs.Vote record ∃VoteMsgFor (v : Abs.Vote) : Set where constructor mk∃VoteMsgFor field -- A message that was actually sent nm : NetworkMsg cv : Vote cv∈nm : cv ⊂Msg nm -- And contained a valid vote that, once abstracted, yeilds v. vmsgMember : EpochConfig.Member 𝓔 vmsgSigned : WithVerSig (getPubKey 𝓔 vmsgMember) cv vmsg≈v : α-ValidVote 𝓔 cv vmsgMember ≡ v vmsgEpoch : cv ^∙ vEpoch ≡ epoch 𝓔 open ∃VoteMsgFor public record ∃VoteMsgSentFor (sm : SentMessages)(v : Abs.Vote) : Set where constructor mk∃VoteMsgSentFor field vmFor : ∃VoteMsgFor v vmSender : NodeId nmSentByAuth : (vmSender , (nm vmFor)) ∈ sm open ∃VoteMsgSentFor public ∈QC⇒sent : ∀{st : SystemState} {q α} → Abs.Q q α-Sent (msgPool st) → Meta-Honest-Member α → (vα : α Abs.∈QC q) → ∃VoteMsgSentFor (msgPool st) (Abs.∈QC-Vote q vα) ∈QC⇒sent vsent@(ws {sender} {nm} e≡ nm∈st (qc∈NM {cqc} .{nm} valid cqc∈nm)) ha va with All-reduce⁻ {vdq = Any-lookup va} (α-Vote cqc valid) All-self (Any-lookup-correctP va) ...| as , as∈cqc , α≡ with α-Vote-evidence cqc valid as∈cqc | inspect (α-Vote-evidence cqc valid) as∈cqc ...| ev | [ refl ] with vote∈qc {vs = as} as∈cqc refl cqc∈nm ...| v∈nm = mk∃VoteMsgSentFor (mk∃VoteMsgFor nm (_cveVote ev) v∈nm (_ivvMember (_cveIsValidVote ev)) (_ivvSigned (_cveIsValidVote ev)) (sym α≡) (_ivvEpoch (_cveIsValidVote ev))) sender nm∈st -- Finally, we can define the abstract system state corresponding to the concrete state st intSystemState : IntermediateSystemState ℓ0 intSystemState = record { InSys = λ { r → r α-Sent (msgPool st) } ; HasBeenSent = λ { v → ∃VoteMsgSentFor (msgPool st) v } ; ∈QC⇒HasBeenSent = ∈QC⇒sent {st = st} } module InSys (siah : SystemInitAndHandlers ℓ-RoundManager ConcSysParms) where open WithInitAndHandlers siah open All-InSys-props stable : ∀ {st0 st1 : SystemState} → Step st0 st1 → {r : Abs.Record} → IntermediateSystemState.InSys (PerState.intSystemState st0) r → IntermediateSystemState.InSys (PerState.intSystemState st1) r stable theStep (_α-Sent_.ws refl x₁ x₂) = _α-Sent_.ws refl (msgs-stable theStep x₁) x₂ ais-stable : ∀ {st0 st1 : SystemState} → Step st0 st1 → {o r : Abs.Record} → (rc : RecordChainFrom o r) → All-InSys (IntermediateSystemState.InSys (PerState.intSystemState st0)) rc → All-InSys (IntermediateSystemState.InSys (PerState.intSystemState st1)) rc ais-stable theStep rc ais = λ x → stable theStep (ais x)
{ "alphanum_fraction": 0.6423938062, "avg_line_length": 43.4454545455, "ext": "agda", "hexsha": "4446aa3cf13e095ad97982c1df024b9d3d0f057f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/LibraBFT/Concrete/System.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Concrete/System.agda", "max_line_length": 120, "max_stars_count": null, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/LibraBFT/Concrete/System.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1399, "size": 4779 }
------------------------------------------------------------------------ -- Empty type (in Set₁) ------------------------------------------------------------------------ module Data.Empty1 where data ⊥₁ : Set₁ where
{ "alphanum_fraction": 0.2293577982, "avg_line_length": 27.25, "ext": "agda", "hexsha": "990a548597cf2a7bddf382b222cbedf0b18303ac", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/Data/Empty1.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/Data/Empty1.agda", "max_line_length": 72, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/Data/Empty1.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 27, "size": 218 }
module erase where open import syntax-util open import lib open import cedille-types open import general-util open import constants open import is-free {-# TERMINATING #-} erase : { ed : exprd } → ⟦ ed ⟧ → ⟦ ed ⟧ erase-term : term → term erase-type : type → type erase-kind : kind → kind erase-lterms : term → lterms → term erase-tk : tk → tk erase-liftingType : liftingType → liftingType erase-cases : cases → cases erase-case : case → case erase-caseArgs : caseArgs → caseArgs erase-term-args : args → 𝕃 term erase-if : 𝔹 → { ed : exprd } → ⟦ ed ⟧ → ⟦ ed ⟧ erase-if tt = erase erase-if ff = id erase-term (Parens _ t _) = erase-term t erase-term (App t1 Erased t2) = erase-term t1 erase-term (App t1 NotErased t2) = App (erase-term t1) NotErased (erase-term t2) erase-term (AppTp t tp) = erase-term t erase-term (Lam _ Erased _ _ _ t) = erase-term t erase-term (Lam _ NotErased _ x oc t) = Lam posinfo-gen NotErased posinfo-gen x NoClass (erase-term t) erase-term (Let _ NotErased (DefTerm _ x _ t) t') = let body = erase-term t' in if is-free-in skip-erased x t' then Let posinfo-gen ff (DefTerm posinfo-gen x NoType (erase-term t)) body -- if x does not occur in an unerase position in t', then the binding is irrelevant in the erasure else body erase-term (Let _ Erased (DefTerm _ x _ t) t') = erase-term t' erase-term (Let _ _ (DefType _ _ _ _) t) = erase-term t erase-term (Open _ _ _ _ t) = erase-term t erase-term (Var _ x) = Var posinfo-gen x erase-term (Beta _ _ NoTerm) = id-term erase-term (Beta _ _ (SomeTerm t _)) = erase-term t erase-term (IotaPair _ t1 t2 _ _) = erase-term t1 erase-term (IotaProj t n _) = erase-term t erase-term (Epsilon _ lr _ t) = erase-term t erase-term (Sigma _ t) = erase-term t erase-term (Hole pi) = Hole pi -- Retain position, so jumping to hole works erase-term (Phi _ t t₁ t₂ _) = erase-term t₂ erase-term (Rho _ _ _ t _ t') = erase-term t' erase-term (Chi _ T t') = erase-term t' erase-term (Delta _ T t) = id-term erase-term (Theta _ u t ls) = erase-lterms (erase-term t) ls erase-term (Mu _ _ x t ot _ c _) = Mu posinfo-gen posinfo-gen x (erase-term t) NoType posinfo-gen (erase-cases c) posinfo-gen erase-term (Mu' _ _ t _ _ c _) = Mu' posinfo-gen NoTerm (erase-term t) NoType posinfo-gen (erase-cases c) posinfo-gen erase-cases = map erase-case erase-case (Case _ x as t) = Case posinfo-gen x (erase-caseArgs as) (erase-term t) erase-caseArgs [] = [] erase-caseArgs ((CaseTermArg pi NotErased t) :: as) = CaseTermArg posinfo-gen NotErased t :: erase-caseArgs as erase-caseArgs (_ :: as) = erase-caseArgs as erase-term-args [] = [] erase-term-args (TermArg NotErased t :: as) = erase t :: erase-term-args as erase-term-args (_ :: as) = erase-term-args as -- Only erases TERMS in types, leaving the structure of types the same erase-type (Abs _ b _ v atk tp) = Abs posinfo-gen b posinfo-gen v (erase-tk atk) (erase-type tp) erase-type (Iota _ _ v otp tp) = Iota posinfo-gen posinfo-gen v (erase-type otp) (erase-type tp) erase-type (Lft _ _ v t lt) = Lft posinfo-gen posinfo-gen v (erase-term t) (erase-liftingType lt) erase-type (NoSpans tp _) = NoSpans (erase-type tp) posinfo-gen erase-type (TpApp tp tp') = TpApp (erase-type tp) (erase-type tp') erase-type (TpAppt tp t) = TpAppt (erase-type tp) (erase-term t) erase-type (TpArrow tp at tp') = TpArrow (erase-type tp) at (erase-type tp') erase-type (TpEq _ t t' _) = TpEq posinfo-gen (erase-term t) (erase-term t') posinfo-gen erase-type (TpLambda _ _ v atk tp) = TpLambda posinfo-gen posinfo-gen v (erase-tk atk) (erase-type tp) erase-type (TpParens _ tp _) = erase-type tp erase-type (TpHole pi) = TpHole pi -- Retain position, so jumping to hole works erase-type (TpVar _ x) = TpVar posinfo-gen x erase-type (TpLet _ (DefTerm _ x _ t) T) = TpLet posinfo-gen (DefTerm posinfo-gen x NoType (erase-term t)) (erase-type T) erase-type (TpLet _ (DefType _ x k T) T') = TpLet posinfo-gen (DefType posinfo-gen x (erase-kind k) (erase-type T)) (erase-type T') -- Only erases TERMS in types in kinds, leaving the structure of kinds and types in those kinds the same erase-kind (KndArrow k k') = KndArrow (erase-kind k) (erase-kind k') erase-kind (KndParens _ k _) = erase-kind k erase-kind (KndPi _ _ v atk k) = KndPi posinfo-gen posinfo-gen v (erase-tk atk) (erase-kind k) erase-kind (KndTpArrow tp k) = KndTpArrow (erase-type tp) (erase-kind k) erase-kind (KndVar _ x ps) = KndVar posinfo-gen x ps erase-kind (Star _) = Star posinfo-gen erase{TERM} t = erase-term t erase{TYPE} tp = erase-type tp erase{KIND} k = erase-kind k erase{LIFTINGTYPE} lt = erase-liftingType lt erase{TK} atk = erase-tk atk erase{ARG} a = a erase{QUALIF} q = q erase-tk (Tkt tp) = Tkt (erase-type tp) erase-tk (Tkk k) = Tkk (erase-kind k) erase-liftingType (LiftArrow lt lt') = LiftArrow (erase-liftingType lt) (erase-liftingType lt') erase-liftingType (LiftParens _ lt _) = erase-liftingType lt erase-liftingType (LiftPi _ v tp lt) = LiftPi posinfo-gen v (erase-type tp) (erase-liftingType lt) erase-liftingType (LiftTpArrow tp lt) = LiftTpArrow (erase-type tp) (erase-liftingType lt) erase-liftingType lt = lt erase-lterms t [] = t erase-lterms t ((Lterm Erased t') :: ls) = erase-lterms t ls erase-lterms t ((Lterm NotErased t') :: ls) = erase-lterms (App t NotErased (erase-term t')) ls
{ "alphanum_fraction": 0.6998113208, "avg_line_length": 46.4912280702, "ext": "agda", "hexsha": "a8bf41050810dcc3d252caa9395514c1c71ab27f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CarlOlson/cedille", "max_forks_repo_path": "src/erase.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "CarlOlson/cedille", "max_issues_repo_path": "src/erase.agda", "max_line_length": 131, "max_stars_count": null, "max_stars_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CarlOlson/cedille", "max_stars_repo_path": "src/erase.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1731, "size": 5300 }
{-# 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 ,- xs) = x vTail : {X : Set}{n : Nat} -> Vec X (suc n) -> Vec X n vTail (x ,- 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 vChop (suc m) (x ,- xs) | fst₁ , snd₁ = (x ,- fst₁) , snd₁ 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 feq x | vMapIdFact feq xs = 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 X Y Z f g h heq (x ,- xs) rewrite heq x | vMapCpFact X Y Z 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 _ --??-------------------------------------------------------------------------- -- Think about what you could prove, relating vMap with vHead, vTail, vChop... -- Now google "Philip Wadler" "Theorems for Free" ------------------------------------------------------------------------------ -- Applicative Structure (giving mapping and zipping cheaply) ------------------------------------------------------------------------------ --??--1.5-(2)----------------------------------------------------------------- -- HINT: you will need to override the default invisibility of n to do this. vPure : {X : Set} -> X -> {n : Nat} -> Vec X n vPure x {zero} = [] vPure x {suc n} = x ,- vPure x _$V_ : {X Y : Set}{n : Nat} -> Vec (X -> Y) n -> Vec X n -> Vec Y n [] $V [] = [] x ,- fs $V x₁ ,- xs = x 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 [] [] = [] vZip (x ,- xs) (x₁ ,- ys) = (x , x₁) ,- vZip xs 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 feq x | vIdentity feq xs = 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 (x₁ ,- fs) x rewrite vInterchange fs x = refl _ 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 (x₁ ,- fs) (x₂ ,- gs) (x ,- xs) rewrite vComposition fs gs xs = refl _ --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Order-Preserving Embeddings (also known in the business as "thinnings") ------------------------------------------------------------------------------ -- What have these to do with Pascal's Triangle? data _<=_ : Nat -> Nat -> Set where oz : zero <= zero os : {n m : Nat} -> n <= m -> suc n <= suc m o' : {n m : Nat} -> n <= m -> n <= suc 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) 3 all0<=4 = o' (o' (o' (o' oz))) ,- o' (o' (o' (o' oz))) ,- o' (o' (o' (o' oz))) ,- [] all1<=4 : Vec (1 <= 4) 2 all1<=4 = os (o' (o' (o' oz))) ,- os (o' (o' (o' oz))) ,- [] all2<=4 : Vec (2 <= 4) _ all2<=4 = os (o' (o' (os oz))) ,- os (os (o' (o' oz))) ,- [] all3<=4 : Vec (3 <= 4) zero all3<=4 = [] all4<=4 : Vec (4 <= 4) zero all4<=4 = [] -- 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 -- 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 _ vMap<?=Fact f (o' th) (x ,- xs) = vMap<?=Fact f th 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 --??-------------------------------------------------------------------------- -- 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)---------------------------------------------------------------- thinMore : {n m : Nat} -> suc n <= m -> n <= m thinMore (os n<=m) = o' n<=m thinMore (o' n<=m) = o' (thinMore n<=m) oTooBig : {n m : Nat} -> n >= m -> suc n <= m -> Zero oTooBig {zero} {.(suc _)} n>=m (os th) = n>=m oTooBig {zero} {.(suc _)} n>=m (o' th) = n>=m oTooBig {suc n} {.(suc _)} n>=m (os th) = oTooBig n>=m th oTooBig {suc n} {.(suc _)} n>=m (o' th) = oTooBig n>=m (thinMore th) oiUnique : {n : Nat}(th : n <= n) -> th == oi oiUnique oz = refl oz oiUnique (os th) rewrite oiUnique th = refl (os oi) oiUnique {m} (o' th) with oTooBig (refl->= m) th oiUnique {.(suc _)} (o' th) | () --??-------------------------------------------------------------------------- -- 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 th o>> oz = th os th o>> os th' = os (th o>> th') o' th o>> os th' = o' (th o>> th') th o>> o' th' = o' (th o>> th') cp-<?= : {p n m : Nat}(th : p <= n)(th' : n <= m) -> {X : Set}(xs : Vec X m) -> ((th o>> th') <?= xs) == (th <?= (th' <?= xs)) cp-<?= th oz [] = refl (th <?= []) cp-<?= oz (o' th') (x ,- xs) = cp-<?= oz th' xs cp-<?= (os th) (os th') (x ,- xs) rewrite cp-<?= th th' xs = refl (x ,- (th <?= (th' <?= xs))) cp-<?= (os th) (o' th') (x ,- xs) = cp-<?= (os th) th' xs cp-<?= (o' th) (os th') (x ,- xs) = cp-<?= th th' xs cp-<?= (o' th) (o' th') (x ,- xs) = cp-<?= (o' th) th' xs --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Thinning Dominoes ------------------------------------------------------------------------------ --??--1.14-(3)---------------------------------------------------------------- idThen-o>> : {n m : Nat}(th : n <= m) -> (oi o>> th) == th idThen-o>> oz = refl oz idThen-o>> (os th) rewrite idThen-o>> th = refl (os th) idThen-o>> (o' th) rewrite idThen-o>> th = refl (o' th) idAfter-o>> : {n m : Nat}(th : n <= m) -> (th o>> oi) == th idAfter-o>> oz = refl oz idAfter-o>> (os th) rewrite idAfter-o>> th = refl (os th) idAfter-o>> (o' th) rewrite idAfter-o>> th = refl (o' th) 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 oz = refl (th0 o>> th1) assoc-o>> th0 (o' th1) (os th2) rewrite assoc-o>> th0 th1 th2 = refl (o' (th0 o>> (th1 o>> th2))) assoc-o>> (os th0) (os th1) (os th2) rewrite assoc-o>> th0 th1 th2 = refl (os (th0 o>> (th1 o>> th2))) assoc-o>> (o' th0) (os th1) (os th2) rewrite assoc-o>> th0 th1 th2 = refl (o' (th0 o>> (th1 o>> th2))) assoc-o>> th0 th1 (o' th2) rewrite assoc-o>> th0 th1 th2 = refl (o' (th0 o>> (th1 o>> 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)---------------------------------------------------------------- selectHead : (n : Nat) -> 1 <= (suc n) selectHead n = os oe -- HINT: composition of functions vTabulate : {n : Nat}{X : Set} -> (1 <= n -> X) -> Vec X n vTabulate {zero} f = [] vTabulate {suc n} f = (f (selectHead n)) ,- (vTabulate (\p -> f (o' p))) -- This should be easy if vTabulate is correct. vTabulateProjections : {n : Nat}{X : Set}(xs : Vec X n) -> vTabulate (vProject xs) == xs vTabulateProjections [] = refl [] vTabulateProjections (x ,- xs) rewrite vTabulateProjections xs = refl (x ,- xs) -- HINT: oeUnique vProjectFromTable : {n : Nat}{X : Set}(f : 1 <= n -> X)(i : 1 <= n) -> vProject (vTabulate f) i == f i vProjectFromTable {.(suc _)} {X} f (os i) with oeUnique i vProjectFromTable {.(suc _)} {X} f (os .oe) | refl .oe = refl (f (os oe)) vProjectFromTable {.(suc _)} {X} f (o' i) = vProjectFromTable (λ z → f (o' z)) i --??--------------------------------------------------------------------------
{ "alphanum_fraction": 0.4033232628, "avg_line_length": 39.1115973742, "ext": "agda", "hexsha": "d26261938e8d52df95f0e8d18055a5d6b6b72aaa", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "5b20aeffeaf714769e121bc9f7aa7c25106d0a1b", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "poscat0x04/CS410", "max_forks_repo_path": "Ex1.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "5b20aeffeaf714769e121bc9f7aa7c25106d0a1b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "poscat0x04/CS410", "max_issues_repo_path": "Ex1.agda", "max_line_length": 108, "max_stars_count": null, "max_stars_repo_head_hexsha": "5b20aeffeaf714769e121bc9f7aa7c25106d0a1b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "poscat0x04/CS410", "max_stars_repo_path": "Ex1.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4957, "size": 17874 }
------------------------------------------------------------------------ -- A general grammar and pretty-printer for binary operators of -- various (not necessarily linearly ordered) precedences ------------------------------------------------------------------------ -- The code below uses a variant of the operator grammars described by -- Ulf Norell and me in "Parsing Mixfix Operators". For simplicity the -- code only handles binary infix operators. {-# OPTIONS --guardedness #-} module Examples.Precedence where open import Codata.Musical.Notation open import Data.Bool using (Bool; T) import Data.Bool.Properties as Bool-prop open import Data.Char as Char using (Char; _==_) open import Data.Fin using (Fin; zero; suc; #_) open import Data.Fin.Properties as Fin using () renaming (_≟_ to _≟F_) open import Data.List as List open import Data.List.Membership.Propositional open import Data.List.NonEmpty as List⁺ import Data.List.Properties as List open import Data.List.Relation.Unary.Any as Any open import Data.Nat using (ℕ) open import Data.Product as Prod import Data.String as String open import Data.Unit import Data.Vec as Vec open import Data.Vec.Membership.Propositional.Properties open import Function using (id; _∘_; _∘′_) open import Relation.Binary open import Relation.Binary.PropositionalEquality as P using (_≡_) open import Relation.Nullary open import Relation.Nullary.Decidable as Decidable open import Relation.Nullary.Product open import Examples.Identifier open import Grammar.Infinite as Grammar using (Grammar-for) open import Pretty using (Pretty-printer-for) open import Renderer open import Utilities ------------------------------------------------------------------------ -- Binary operators -- Associativities. data Associativity : Set where - -- Non-associative. ⇾ -- Right associative. ⇽ -- Left associative. : Associativity -- Operator names. is-operator-char : Char → Bool is-operator-char t = List.any (_==_ t) (String.toList "+-*/.:^<>=!&|") Operator-name : Set Operator-name = List⁺ (∃ (T ∘ is-operator-char)) -- Operators (parametrised by their associativity). record Operator (assoc : Associativity) : Set where constructor ⟪_⟫ field name : Operator-name -- Equality of operators can be decided. _≟O_ : ∀ {assoc} → Decidable (_≡_ {A = Operator assoc}) ⟪ n₁ ∷ ns₁ ⟫ ≟O ⟪ n₂ ∷ ns₂ ⟫ = Decidable.map′ (P.cong ⟪_⟫ ∘ uncurry (P.cong₂ _∷_)) (< P.cong List⁺.head , P.cong List⁺.tail > ∘′ P.cong Operator.name) ((n₁ ≟OC n₂) ×-dec List.≡-dec _≟OC_ ns₁ ns₂) where _≟OC_ : Decidable (_≡_ {A = ∃ (T ∘ is-operator-char)}) (c₁ , _) ≟OC (c₂ , _) = Decidable.map′ lemma (P.cong proj₁) (c₁ Char.≟ c₂) where lemma : {p₁ p₂ : ∃ (T ∘ is-operator-char)} → proj₁ p₁ ≡ proj₁ p₂ → p₁ ≡ p₂ lemma {p₁ = _ , _} {p₂ = ._ , _} P.refl = P.cong -,_ (Bool-prop.T-irrelevant _ _) -- A grammar for a given operator name. operator-name : Grammar-for Operator-name operator-name n = list⁺ (tok-sat _) n where open Grammar -- A pretty-printer for operator names. operator-name-printer : Pretty-printer-for operator-name operator-name-printer n = list⁺ tok-sat n where open Pretty -- A grammar for a given operator. operator : ∀ {assoc} → Grammar-for (Operator assoc) operator op = Prod.map ⟪_⟫ (P.cong ⟪_⟫) <$> operator-name (Operator.name op) where open Grammar -- A pretty-printer for operators. operator-printer : ∀ {assoc} → Pretty-printer-for (operator {assoc = assoc}) operator-printer op = <$> operator-name-printer (Operator.name op) where open Pretty ------------------------------------------------------------------------ -- Precedence graphs -- Precedence graphs are represented by the number of precedence -- levels, plus functions mapping node identifiers (precedences) to -- node contents and successor precedences. record Precedence-graph : Set where field -- The number of precedence levels. levels : ℕ -- Precedence levels. Precedence : Set Precedence = Fin levels field -- The precedence level's operators. ops : Precedence → (assoc : Associativity) → List (Operator assoc) -- The immediate successors of the precedence level. ↑ : Precedence → List Precedence -- All precedence levels. all-precedences : List Precedence all-precedences = Vec.toList (Vec.allFin levels) -- Every precedence level is a member of all-precedences. ∈-all-precedences : ∀ {p} → p ∈ all-precedences ∈-all-precedences {p} = ∈-toList⁺ (∈-allFin⁺ p) -- A membership test for precedences. _∈?_ : ∀ (p : Precedence) ps → Dec (p ∈ ps) p ∈? ps = Any.any? (_≟F_ p) ps ------------------------------------------------------------------------ -- Expressions -- The code is parametrised by a precedence graph. module Expr (g : Precedence-graph) where open Precedence-graph g -- Operators with a given precedence and associativity. Op : Precedence → Associativity → Set Op p assoc = ∃ λ op → op ∈ ops p assoc mutual -- Expressions. data Expr : Set where var : Identifier → Expr app : ∀ {p} → ∃ (App p) → Expr -- Binary operator applications where the operator has a given -- precedence and associativity. App : Precedence → Associativity → Set App p assoc = Expr × Op p assoc × Expr -- The following function can be convenient to use when constructing -- examples. _⟨_⟩_ : ∀ {assoc} → Expr → (op : Operator assoc) → {member : True (Fin.any? λ p → Any.any? (_≟O_ op) (ops p assoc))} → Expr → Expr _⟨_⟩_ e₁ op {member} e₂ = app (_ , e₁ , (op , proj₂ (toWitness member)) , e₂) module _ where open Grammar mutual -- Expression grammar. expr : Grammar Expr expr = whitespace ⋆ ⊛> precs all-precedences <⊛ whitespace ⋆ -- Grammar for a given list of precedence levels. precs : List Precedence → Grammar Expr precs ps = string′ "(" ⊛> ♯ expr <⊛ string′ ")" ∣ var <$> identifier ∣ precs′ ps precs′ : List Precedence → Grammar Expr precs′ [] = fail precs′ (p ∷ ps) = app <$> ♯ prec p ∣ precs′ ps -- Grammar for a given precedence level. prec : (p : Precedence) → Grammar (∃ (App p)) prec p = -,_ <$> non-assoc p ∣ -,_ <$> right⁺ p ∣ -,_ <$> left⁺ p -- Grammar for higher precedence levels. higher : Precedence → Grammar Expr higher p = precs (↑ p) -- Non-associative operators. non-assoc : (p : Precedence) → Grammar (App p -) non-assoc p = (λ e₁ op e₂ → e₁ , op , e₂) <$> higher p ⊛ operators (ops p -) ⊛ higher p -- Right-associative operators. right⁺ : (p : Precedence) → Grammar (App p ⇾) right⁺ p = (λ e₁ op e₂ → e₁ , op , e₂) <$> higher p ⊛ operators (ops p ⇾) ⊛ right⁺↑ p right⁺↑ : Precedence → Grammar Expr right⁺↑ p = (app ∘ -,_) <$> ♯ right⁺ p ∣ higher p -- Left-associative operators. left⁺ : (p : Precedence) → Grammar (App p ⇽) left⁺ p = (λ e₁ op e₂ → e₁ , op , e₂) <$> left⁺↑ p ⊛ operators (ops p ⇽) ⊛ higher p left⁺↑ : Precedence → Grammar Expr left⁺↑ p = (app ∘ -,_) <$> ♯ left⁺ p ∣ higher p -- An operator from a given list of operators. operators : ∀ {assoc} (os : List (Operator assoc)) → Grammar (∃ λ op → op ∈ os) operators [] = fail operators (op ∷ ops) = whitespace ⋆ ⊛> (Prod.map id here <$> operator op) <⊛ whitespace ⋆ ∣ Prod.map id there <$> operators ops open Pretty mutual -- Pretty-printer. The produced layout could probably be improved, -- I have not tried very hard to make it pretty. expr-printer : Pretty-printer expr expr-printer e = nil-⋆ ⊛> precs-printer e <⊛ nil-⋆ precs-printer : ∀ {ps} → Pretty-printer (precs ps) precs-printer e = group (precs-printer′ e) where precs-printer′ : ∀ {ps} → Pretty-printer (precs ps) precs-printer′ (var x) = left (right (<$> identifier-printer x)) precs-printer′ {ps} (app {p = p} e) with p ∈? ps ... | yes p∈ps = right (precs′-printer p∈ps e) ... | no _ = -- Incorrect precedence level: insert parentheses. left (left (text ⊛> nest 1 d <⊛ text)) where d = nil-⋆ ⊛> right (precs′-printer ∈-all-precedences e) <⊛ nil-⋆ precs′-printer : ∀ {p ps} → p ∈ ps → (e : ∃ (App p)) → Doc (precs′ ps) (app e) precs′-printer (here P.refl) e = left (<$> prec-printer e) precs′-printer (there p∈ps) e = right (precs′-printer p∈ps e) prec-printer : ∀ {p} → Pretty-printer (prec p) prec-printer (- , e) = left (left (<$> non-assoc-printer e)) prec-printer (⇾ , e) = left (right (<$> right⁺-printer e)) prec-printer (⇽ , e) = right (<$> left⁺-printer e) non-assoc-printer : ∀ {p} → Pretty-printer (non-assoc p) non-assoc-printer (e₁ , op , e₂) = <$> higher-printer e₁ ⊛ operators-printer op ⊛ higher-printer e₂ right⁺-printer : ∀ {p} → Pretty-printer (right⁺ p) right⁺-printer (e₁ , op , e₂) = <$> higher-printer e₁ ⊛ operators-printer op ⊛ right⁺↑-printer e₂ right⁺↑-printer : ∀ {p} → Pretty-printer (right⁺↑ p) right⁺↑-printer {p₁} (app {p = p₂} (⇾ , e)) with p₁ ≟F p₂ | higher-printer (app (⇾ , e)) right⁺↑-printer (app (⇾ , e)) | yes P.refl | _ = -- Matching precedence and associativity. left (<$> right⁺-printer e) right⁺↑-printer (app (⇾ , e)) | no _ | d = right d right⁺↑-printer e = right (higher-printer e) left⁺-printer : ∀ {p} → Pretty-printer (left⁺ p) left⁺-printer (e₁ , op , e₂) = <$> left⁺↑-printer e₁ ⊛ operators-printer op ⊛ higher-printer e₂ left⁺↑-printer : ∀ {p} → Pretty-printer (left⁺↑ p) left⁺↑-printer {p₁} (app {p = p₂} (⇽ , e)) with p₁ ≟F p₂ | higher-printer (app (⇽ , e)) left⁺↑-printer (app (⇽ , e)) | yes P.refl | _ = -- Matching precedence and associativity. left (<$> left⁺-printer e) left⁺↑-printer (app (⇽ , e)) | no _ | d = right d left⁺↑-printer e = right (higher-printer e) higher-printer : ∀ {p} → Pretty-printer (higher p) higher-printer e = nest 2 (precs-printer e) operators-printer : ∀ {assoc} {os : List (Operator assoc)} → Pretty-printer (operators os) operators-printer {os = []} (_ , ()) operators-printer {os = ._ ∷ _} (op , here P.refl) = left (line⋆ tt-⊛> <$> operator-printer op <⊛ space) operators-printer {os = _ ∷ _} (_ , there op∈os) = right (<$> operators-printer (_ , op∈os)) ------------------------------------------------------------------------ -- An example -- Some operators. add : Operator ⇽ add = ⟪ str⁺ "+" ⟫ sub : Operator ⇽ sub = ⟪ str⁺ "-" ⟫ mul : Operator ⇽ mul = ⟪ str⁺ "*" ⟫ div : Operator ⇽ div = ⟪ str⁺ "/" ⟫ cons : Operator ⇾ cons = ⟪ str⁺ "<:" ⟫ snoc : Operator ⇽ snoc = ⟪ str⁺ ":>" ⟫ -- A precedence graph. g : Precedence-graph g = record { ops = ops; ↑ = ↑ } where ops : Fin 3 → (assoc : Associativity) → List (Operator assoc) ops zero ⇽ = snoc ∷ [] ops zero ⇾ = cons ∷ [] ops (suc zero) ⇽ = add ∷ sub ∷ [] ops (suc (suc zero)) ⇽ = mul ∷ div ∷ [] ops _ _ = [] ↑ : Fin 3 → List (Fin 3) ↑ zero = # 1 ∷ # 2 ∷ [] ↑ (suc zero) = # 2 ∷ [] ↑ (suc (suc p)) = [] open Precedence-graph g open Expr g -- An expression. example : Expr example = (((var (str⁺ "y") ⟨ add ⟩ var (str⁺ "k")) ⟨ cons ⟩ (((var (str⁺ "i") ⟨ add ⟩ var (str⁺ "foo")) ⟨ add ⟩ ((var (str⁺ "a") ⟨ div ⟩ (var (str⁺ "b") ⟨ sub ⟩ var (str⁺ "c"))) ⟨ mul ⟩ var (str⁺ "c"))) ⟨ cons ⟩ (var (str⁺ "xs")))) ⟨ snoc ⟩ (var (str⁺ "x"))) ⟨ snoc ⟩ (var (str⁺ "z") ⟨ mul ⟩ var (str⁺ "z")) -- Some unit tests. test₁ : render 80 (expr-printer example) ≡ "(y + k <: i + foo + a / (b - c) * c <: xs) :> x :> z * z" test₁ = P.refl test₂ : render 50 (expr-printer example) ≡ "(y + k <: i + foo + a / (b - c) * c <: xs)\n:> x\n:> z * z" test₂ = P.refl test₃ : render 40 (expr-printer example) ≡ "(y + k\n <: i + foo + a / (b - c) * c\n <: xs)\n:> x\n:> z * z" test₃ = P.refl test₄ : render 30 (expr-printer example) ≡ "(y + k\n <: i\n + foo\n + a / (b - c) * c\n <: xs)\n:> x\n:> z * z" test₄ = P.refl test₅ : render 20 (expr-printer example) ≡ "(y + k\n <: i\n + foo\n + a\n / (b - c)\n * c\n <: xs)\n:> x\n:> z * z" test₅ = P.refl test₆ : render 6 (expr-printer example) ≡ "(y + k\n <: i\n + foo\n + a\n / (b\n - c)\n * c\n <: xs)\n:> x\n:> z\n * z" test₆ = P.refl -- The rendering of "y + k" in the following test may seem strange: if -- no newline had been inserted before +, then the total width of this -- subexpression would have been smaller. -- -- Wadler's pretty-printing algorithm is not always optimal for texts -- that do not fit in the allotted width, if by "optimal" we mean -- "with as little overflow as possible". To see what I mean, try -- running the following Haskell code, where the functions are -- implemented as in Wadler's paper: -- -- pretty 1 (group (nest 20 (line <> text "x"))) -- -- The result is "\n                    x", which can be seen as much -- worse than the alternative result " x". However, note that Wadler -- uses a lexicographic definition of "better", in which -- "\n                    x" is better than " x", because the first -- line of "\n                    x" fits, but the first line of " x" -- doesn't. test₇ : render 5 (expr-printer example) ≡ "(y\n + k\n <: i\n + foo\n + a\n / (b\n - c)\n * c\n <: xs)\n:> x\n:> z\n * z" test₇ = P.refl
{ "alphanum_fraction": 0.5570921986, "avg_line_length": 30.7860262009, "ext": "agda", "hexsha": "c89e571c3318ccbc392610f24e5088ccb371f35b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/pretty", "max_forks_repo_path": "Examples/Precedence.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/pretty", "max_issues_repo_path": "Examples/Precedence.agda", "max_line_length": 124, "max_stars_count": null, "max_stars_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/pretty", "max_stars_repo_path": "Examples/Precedence.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4425, "size": 14100 }
module sets.fin.core where open import decidable open import equality.core open import sets.empty open import sets.unit public open import sets.nat.core hiding (_≟_; pred) open import sets.empty data Fin : ℕ → Set where zero : {n : ℕ} → Fin (suc n) suc : {n : ℕ} → Fin n → Fin (suc n) raise : ∀ {n} → Fin n → Fin (suc n) raise zero = zero raise (suc i) = suc (raise i) fin-disj : ∀ {n}(i : Fin n) → ¬ (zero ≡ suc i) fin-disj {n} i = J' P tt (suc i) where P : (i : Fin (suc n)) → zero ≡ i → Set P zero _ = ⊤ P (suc _) _ = ⊥ fin-suc-inj : ∀ {n} {i j : Fin n} → Fin.suc i ≡ suc j → i ≡ j fin-suc-inj {n}{i}{j} = J' P refl (suc j) where P : (j : Fin (suc n)) → Fin.suc i ≡ j → Set P zero _ = ⊤ P (suc j) _ = i ≡ j _≟_ : ∀ {n} → (i j : Fin n) → Dec (i ≡ j) _≟_ zero zero = yes refl _≟_ zero (suc i) = no (fin-disj i) _≟_ (suc i) zero = no (λ p → fin-disj i (sym p)) _≟_ {suc n} (suc i) (suc j) with i ≟ j ... | yes p = yes (ap suc p) ... | no a = no (λ p → a (fin-suc-inj p)) last-fin : {n : ℕ} → Fin (suc n) last-fin {zero} = zero last-fin {suc n} = suc last-fin
{ "alphanum_fraction": 0.5386012716, "avg_line_length": 25.0227272727, "ext": "agda", "hexsha": "cf2c17bfb24194daa88c414929ba562278ae2468", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z", "max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "HoTT/M-types", "max_forks_repo_path": "sets/fin/core.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "HoTT/M-types", "max_issues_repo_path": "sets/fin/core.agda", "max_line_length": 61, "max_stars_count": 27, "max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "HoTT/M-types", "max_stars_repo_path": "sets/fin/core.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z", "num_tokens": 472, "size": 1101 }
open import Agda.Primitive.Cubical data BadData : IUniv where
{ "alphanum_fraction": 0.8095238095, "avg_line_length": 15.75, "ext": "agda", "hexsha": "9b3cd117ac107c4074cee8d4e67075446d164477", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "cagix/agda", "max_forks_repo_path": "test/Fail/IUnivData.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "cagix/agda", "max_issues_repo_path": "test/Fail/IUnivData.agda", "max_line_length": 34, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "cagix/agda", "max_stars_repo_path": "test/Fail/IUnivData.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 19, "size": 63 }
------------------------------------------------------------------------ -- A variant of declarative kinding in Fω with interval kinds ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module FOmegaInt.Kinding.Declarative where open import Data.Context.WellFormed open import Data.Fin using (Fin; zero) open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Fin.Substitution.ExtraLemmas open import Data.Fin.Substitution.Typed open import Data.Fin.Substitution.TypedRelation open import Data.Nat using (ℕ) open import Data.Product using (_,_; _×_; proj₁) import Data.Vec as Vec open import Function using (_∘_) import Level open import Relation.Binary.PropositionalEquality as PropEq hiding ([_]) open import FOmegaInt.Syntax ------------------------------------------------------------------------ -- Declarative (sub)kinding, subtyping and kind/type equality. -- -- This module contains variants of the declarative kinding and -- subtyping judgments which differ slightly from those given in the -- Typing module. Some of the rules in this module have additional -- premises which we call "validity conditions". These validity -- conditions are redundant in the sense that they follow (more or -- less) directly from so-called "validity" properties of the -- corresponding judgments. For example, the kinding rule (∈-Π-e) -- below concludes that `Γ ⊢ a · b ∈ k Kind[ b ]' and has, among -- others, the validity condition `Γ ⊢ k Kind[ b ] kd' as one of its -- premises. But this is a direct consequence of "kinding validity" -- which states that the kinds of well-kinded types are themselves -- well-formed, i.e. that `Γ ⊢ k kd' whenever `Γ ⊢Tp a ∈ k' (see the -- Kinding.Declarative.Validity module for the full set of validity -- lemmas). Since all the validity conditions follow from -- corresponding validity lemmas, they are, in principle, redundant. -- Indeed, this is why they do not appear in the kinding and subtyping -- rules of the Typing module. The reason for including the validity -- conditions as premises in the rules below is that the proofs of -- some lemmas (notably the validity lemmas themselves) are done by -- induction on kinding and subtyping derivations and require the -- proofs of these conditions to be proper sub-derivations of the -- derivations on which the induction is performed. -- -- To proof the validity lemmas for both variants of the kinding and -- subtyping judgments, we use the following strategy: -- -- 1. prove the validity lemmas for the judgments containing the -- additional validity conditions as premises, -- -- 2. prove that the two variants of the judgments are -- equivalent, i.e. -- -- a) the extended judgments are sound w.r.t to the original -- judgments: we can drop the validity conditions without -- affecting the conclusion of the derivations, and -- -- b) the extended judgments are complete w.r.t. to the original -- judgments: crucially, the additional validity conditions -- follow from the *remaining premises* of the extended rules -- via the validity lemmas proved in step 1, -- -- 3. prove that validity holds for the original judgments via the -- equivalence: convert to the extended judgment (via -- completeness), apply the lemma in question, convert the -- conclusion back (via soundness). -- -- See the Kinding.Declarative.Equivalence module for the full proof -- of equivalence (point 2) and the `Tp∈-valid' lemma in the -- Typing.Inversion module for an example of point 3. module Kinding where open TermCtx open Syntax open Substitution using (_[_]; _Kind[_]; weaken) infix 4 _ctx _⊢_kd _⊢_wf infix 4 _⊢Tp_∈_ _⊢_∈_ infix 4 _⊢_<:_∈_ _⊢_<∷_ infix 4 _⊢_≃_∈_ _⊢_≅_ _⊢_≃⊎≡_∈_ mutual -- Well-formed typing contexts. _ctx : ∀ {n} → Ctx n → Set _ctx = ContextFormation._wf _⊢_wf -- Well-formed type/kind ascriptions in typing contexts. data _⊢_wf {n} (Γ : Ctx n) : TermAsc n → Set where wf-kd : ∀ {a} → Γ ⊢ a kd → Γ ⊢ (kd a) wf wf-tp : ∀ {a} → Γ ⊢Tp a ∈ * → Γ ⊢ (tp a) wf -- Well-formed kinds. data _⊢_kd {n} (Γ : Ctx n) : Kind Term n → Set where kd-⋯ : ∀ {a b} → Γ ⊢Tp a ∈ * → Γ ⊢Tp b ∈ * → Γ ⊢ a ⋯ b kd kd-Π : ∀ {j k} → Γ ⊢ j kd → kd j ∷ Γ ⊢ k kd → Γ ⊢ Π j k kd -- Kinding derivations. data _⊢Tp_∈_ {n} (Γ : Ctx n) : Term n → Kind Term n → Set where ∈-var : ∀ {k} x → Γ ctx → lookup Γ x ≡ kd k → Γ ⊢Tp var x ∈ k ∈-⊥-f : Γ ctx → Γ ⊢Tp ⊥ ∈ * ∈-⊤-f : Γ ctx → Γ ⊢Tp ⊤ ∈ * ∈-∀-f : ∀ {k a} → Γ ⊢ k kd → kd k ∷ Γ ⊢Tp a ∈ * → Γ ⊢Tp Π k a ∈ * ∈-→-f : ∀ {a b} → Γ ⊢Tp a ∈ * → Γ ⊢Tp b ∈ * → Γ ⊢Tp a ⇒ b ∈ * ∈-Π-i : ∀ {j a k} → Γ ⊢ j kd → kd j ∷ Γ ⊢Tp a ∈ k → -- Validity condition: kd j ∷ Γ ⊢ k kd → Γ ⊢Tp Λ j a ∈ Π j k ∈-Π-e : ∀ {a b j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢Tp b ∈ j → -- Validity conditions: kd j ∷ Γ ⊢ k kd → Γ ⊢ k Kind[ b ] kd → Γ ⊢Tp a · b ∈ k Kind[ b ] ∈-s-i : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢Tp a ∈ a ⋯ a ∈-⇑ : ∀ {a j k} → Γ ⊢Tp a ∈ j → Γ ⊢ j <∷ k → Γ ⊢Tp a ∈ k -- Subkinding derivations. data _⊢_<∷_ {n} (Γ : Ctx n) : Kind Term n → Kind Term n → Set where <∷-⋯ : ∀ {a₁ a₂ b₁ b₂} → Γ ⊢ a₂ <: a₁ ∈ * → Γ ⊢ b₁ <: b₂ ∈ * → Γ ⊢ a₁ ⋯ b₁ <∷ a₂ ⋯ b₂ <∷-Π : ∀ {j₁ j₂ k₁ k₂} → Γ ⊢ j₂ <∷ j₁ → kd j₂ ∷ Γ ⊢ k₁ <∷ k₂ → Γ ⊢ Π j₁ k₁ kd → Γ ⊢ Π j₁ k₁ <∷ Π j₂ k₂ -- Subtyping derivations. data _⊢_<:_∈_ {n} (Γ : Ctx n) : Term n → Term n → Kind Term n → Set where <:-refl : ∀ {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a <: a ∈ k <:-trans : ∀ {a b c k} → Γ ⊢ a <: b ∈ k → Γ ⊢ b <: c ∈ k → Γ ⊢ a <: c ∈ k <:-β₁ : ∀ {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j → -- Validity conditions: Γ ⊢Tp a [ b ] ∈ k Kind[ b ] → kd j ∷ Γ ⊢ k kd → Γ ⊢ k Kind[ b ] kd → Γ ⊢ (Λ j a) · b <: a [ b ] ∈ k Kind[ b ] <:-β₂ : ∀ {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j → -- Validity conditions: Γ ⊢Tp a [ b ] ∈ k Kind[ b ] → kd j ∷ Γ ⊢ k kd → Γ ⊢ k Kind[ b ] kd → Γ ⊢ a [ b ] <: (Λ j a) · b ∈ k Kind[ b ] <:-η₁ : ∀ {a j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢ Λ j (weaken a · var zero) <: a ∈ Π j k <:-η₂ : ∀ {a j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢ a <: Λ j (weaken a · var zero) ∈ Π j k <:-⊥ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ ⊥ <: a ∈ * <:-⊤ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ a <: ⊤ ∈ * <:-∀ : ∀ {k₁ k₂ a₁ a₂} → Γ ⊢ k₂ <∷ k₁ → kd k₂ ∷ Γ ⊢ a₁ <: a₂ ∈ * → Γ ⊢Tp Π k₁ a₁ ∈ * → Γ ⊢ Π k₁ a₁ <: Π k₂ a₂ ∈ * <:-→ : ∀ {a₁ a₂ b₁ b₂} → Γ ⊢ a₂ <: a₁ ∈ * → Γ ⊢ b₁ <: b₂ ∈ * → Γ ⊢ a₁ ⇒ b₁ <: a₂ ⇒ b₂ ∈ * <:-λ : ∀ {j₁ j₂ a₁ a₂ j k} → kd j ∷ Γ ⊢ a₁ <: a₂ ∈ k → Γ ⊢Tp Λ j₁ a₁ ∈ Π j k → Γ ⊢Tp Λ j₂ a₂ ∈ Π j k → Γ ⊢ Λ j₁ a₁ <: Λ j₂ a₂ ∈ Π j k <:-· : ∀ {a₁ a₂ b₁ b₂ j k} → Γ ⊢ a₁ <: a₂ ∈ Π j k → Γ ⊢ b₁ ≃ b₂ ∈ j → -- Validity conditions: Γ ⊢Tp b₁ ∈ j → kd j ∷ Γ ⊢ k kd → Γ ⊢ k Kind[ b₁ ] kd → Γ ⊢ a₁ · b₁ <: a₂ · b₂ ∈ k Kind[ b₁ ] <:-⟨| : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ b <: a ∈ * <:-|⟩ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ a <: c ∈ * <:-⋯-i : ∀ {a b c d} → Γ ⊢ a <: b ∈ c ⋯ d → Γ ⊢ a <: b ∈ a ⋯ b <:-⇑ : ∀ {a b j k} → Γ ⊢ a <: b ∈ j → Γ ⊢ j <∷ k → Γ ⊢ a <: b ∈ k -- Type equality. data _⊢_≃_∈_ {n} (Γ : Ctx n) : Term n → Term n → Kind Term n → Set where <:-antisym : ∀ {a b k} → Γ ⊢ a <: b ∈ k → Γ ⊢ b <: a ∈ k → Γ ⊢ a ≃ b ∈ k -- Kind equality. data _⊢_≅_ {n} (Γ : Ctx n) : Kind Term n → Kind Term n → Set where <∷-antisym : ∀ {j k} → Γ ⊢ j <∷ k → Γ ⊢ k <∷ j → Γ ⊢ j ≅ k -- Combined kinding of types and term variable typing. data _⊢_∈_ {n} (Γ : Ctx n) : Term n → TermAsc n → Set where ∈-tp : ∀ {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a ∈ kd k ∈-var : ∀ x {a} → Γ ctx → lookup Γ x ≡ tp a → Γ ⊢ var x ∈ tp a -- Combined type equality and syntactic term variable equality (used -- for well-formed equality lifted to substitutions). data _⊢_≃⊎≡_∈_ {n} (Γ : Ctx n) : Term n → Term n → TermAsc n → Set where ≃-tp : ∀ {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ a ≃⊎≡ b ∈ kd k ≃-var : ∀ x {a} → Γ ctx → lookup Γ x ≡ tp a → Γ ⊢ var x ≃⊎≡ var x ∈ tp a open PropEq using ([_]) -- Derived variable rules. ∈-var′ : ∀ {n} {Γ : Ctx n} x → Γ ctx → Γ ⊢ var x ∈ lookup Γ x ∈-var′ {Γ = Γ} x Γ-ctx with lookup Γ x | inspect (lookup Γ) x ∈-var′ x Γ-ctx | kd k | [ Γ[x]≡kd-k ] = ∈-tp (∈-var x Γ-ctx Γ[x]≡kd-k) ∈-var′ x Γ-ctx | tp a | [ Γ[x]≡tp-a ] = ∈-var x Γ-ctx Γ[x]≡tp-a ≃⊎≡-var : ∀ {n} {Γ : Ctx n} x → Γ ctx → Γ ⊢ var x ≃⊎≡ var x ∈ lookup Γ x ≃⊎≡-var {Γ = Γ} x Γ-ctx with lookup Γ x | inspect (lookup Γ) x ≃⊎≡-var x Γ-ctx | kd k | [ Γ[x]≡kd-k ] = let x∈a = ∈-var x Γ-ctx Γ[x]≡kd-k in ≃-tp (<:-antisym (<:-refl x∈a) (<:-refl x∈a)) ≃⊎≡-var x Γ-ctx | tp a | [ Γ[x]≡tp-a ] = ≃-var x Γ-ctx Γ[x]≡tp-a open ContextFormation _⊢_wf public hiding (_wf) renaming (_⊢_wfExt to _⊢_ext) ------------------------------------------------------------------------ -- Properties of typings open Syntax open TermCtx open Kinding -- An inversion lemma for _⊢_wf. wf-kd-inv : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ kd k wf → Γ ⊢ k kd wf-kd-inv (wf-kd k-kd) = k-kd -- Subkinds have the same shape. <∷-⌊⌋ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → ⌊ j ⌋ ≡ ⌊ k ⌋ <∷-⌊⌋ (<∷-⋯ _ _) = refl <∷-⌊⌋ (<∷-Π j₂<∷j₁ k₁<∷k₂ _) = cong₂ _⇒_ (sym (<∷-⌊⌋ j₂<∷j₁)) (<∷-⌊⌋ k₁<∷k₂) -- Equal kinds have the same shape. ≅-⌊⌋ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → ⌊ j ⌋ ≡ ⌊ k ⌋ ≅-⌊⌋ (<∷-antisym j<∷k k<∷j) = <∷-⌊⌋ j<∷k -- Kind and type equality imply subkinding and subtyping, respectively. ≅⇒<∷ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ j <∷ k ≅⇒<∷ (<∷-antisym j<∷k k<∷j) = j<∷k ≃⇒<: : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ a <: b ∈ k ≃⇒<: (<:-antisym a<:b b<:a) = a<:b -- Reflexivity of subkinding. <∷-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k <∷ k <∷-refl (kd-⋯ a∈* b∈*) = <∷-⋯ (<:-refl a∈*) (<:-refl b∈*) <∷-refl (kd-Π j-kd k-kd) = <∷-Π (<∷-refl j-kd) (<∷-refl k-kd) (kd-Π j-kd k-kd) -- Reflexivity of kind equality. ≅-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k ≅ k ≅-refl k-kd = <∷-antisym (<∷-refl k-kd) (<∷-refl k-kd) -- Symmetry of kind equality. ≅-sym : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ k ≅ j ≅-sym (<∷-antisym j<∷k k<∷j) = <∷-antisym k<∷j j<∷k -- An admissible kind equality rule for interval kinds. ≅-⋯ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂} → Γ ⊢ a₁ ≃ a₂ ∈ * → Γ ⊢ b₁ ≃ b₂ ∈ * → Γ ⊢ a₁ ⋯ b₁ ≅ a₂ ⋯ b₂ ≅-⋯ (<:-antisym a₁<:a₂ a₂<:a₁) (<:-antisym b₁<:b₂ b₂<:b₁) = <∷-antisym (<∷-⋯ a₂<:a₁ b₁<:b₂) (<∷-⋯ a₁<:a₂ b₂<:b₁) -- Type equality is reflexive. ≃-refl : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a ≃ a ∈ k ≃-refl a∈k = <:-antisym (<:-refl a∈k) (<:-refl a∈k) -- Type equality is transitive. ≃-trans : ∀ {n} {Γ : Ctx n} {a b c k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ b ≃ c ∈ k → Γ ⊢ a ≃ c ∈ k ≃-trans (<:-antisym a<:b b<:a) (<:-antisym b<:c c<:b) = <:-antisym (<:-trans a<:b b<:c) (<:-trans c<:b b<:a) -- Type equality is symmetric. ≃-sym : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ b ≃ a ∈ k ≃-sym (<:-antisym a<:b b<:a) = <:-antisym b<:a a<:b -- Reflexivity of the combined type and term variable equality. ≃⊎≡-refl : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ∈ b → Γ ⊢ a ≃⊎≡ a ∈ b ≃⊎≡-refl (∈-tp a∈k) = ≃-tp (≃-refl a∈k) ≃⊎≡-refl (∈-var x Γ-ctx Γ[x]≡tp-a) = ≃-var x Γ-ctx Γ[x]≡tp-a -- Types inhabiting interval kinds are proper Types. Tp∈-⋯-* : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢Tp a ∈ * Tp∈-⋯-* a∈b⋯c = ∈-⇑ (∈-s-i a∈b⋯c) (<∷-⋯ (<:-⊥ a∈b⋯c) (<:-⊤ a∈b⋯c)) -- Well-formedness of the * kind. *-kd : ∀ {n} {Γ : Ctx n} → Γ ctx → Γ ⊢ * kd *-kd Γ-ctx = kd-⋯ (∈-⊥-f Γ-ctx) (∈-⊤-f Γ-ctx) module _ where open Substitution -- An admissible β-rule for type equality. ≃-β : ∀ {n} {Γ : Ctx n} {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j → -- Validity conditions: Γ ⊢Tp a [ b ] ∈ k Kind[ b ] → kd j ∷ Γ ⊢ k kd → Γ ⊢ k Kind[ b ] kd → Γ ⊢ (Λ j a) · b ≃ a [ b ] ∈ k Kind[ b ] ≃-β a∈k b∈j a[b]∈k[b] k-kd k[b]-kd = <:-antisym (<:-β₁ a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) (<:-β₂ a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) -- An admissible η-rule for type equality. ≃-η : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢ Λ j (weaken a · var zero) ≃ a ∈ Π j k ≃-η a∈Πjk = <:-antisym (<:-η₁ a∈Πjk) (<:-η₂ a∈Πjk) -- An admissible congruence rule for type equality w.r.t. formation of -- arrow types. ≃-→ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂} → Γ ⊢ a₁ ≃ a₂ ∈ * → Γ ⊢ b₁ ≃ b₂ ∈ * → Γ ⊢ a₁ ⇒ b₁ ≃ a₂ ⇒ b₂ ∈ * ≃-→ (<:-antisym a₁<:a₂∈* a₂<:a₁∈*) (<:-antisym b₁<:b₂∈* b₂<:b₁∈*) = <:-antisym (<:-→ a₂<:a₁∈* b₁<:b₂∈*) (<:-→ a₁<:a₂∈* b₂<:b₁∈*) -- An admissible congruence rule for type equality w.r.t. operator -- abstraction. ≃-λ : ∀ {n} {Γ : Ctx n} {j₁ j₂ a₁ a₂ j k} → kd j ∷ Γ ⊢ a₁ ≃ a₂ ∈ k → Γ ⊢Tp Λ j₁ a₁ ∈ Π j k → Γ ⊢Tp Λ j₂ a₂ ∈ Π j k → Γ ⊢ Λ j₁ a₁ ≃ Λ j₂ a₂ ∈ Π j k ≃-λ (<:-antisym a₁<:a₂∈k a₂<:a₁∈k) Λj₁a₁∈Πjk Λj₂a₂∈Πjk = <:-antisym (<:-λ a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk) (<:-λ a₂<:a₁∈k Λj₂a₂∈Πjk Λj₁a₁∈Πjk) -- An admissible subsumption rule for type equality. ≃-⇑ : ∀ {n} {Γ : Ctx n} {a b j k} → Γ ⊢ a ≃ b ∈ j → Γ ⊢ j <∷ k → Γ ⊢ a ≃ b ∈ k ≃-⇑ (<:-antisym a<:b b<:a) j<∷k = <:-antisym (<:-⇑ a<:b j<∷k) (<:-⇑ b<:a j<∷k) -- The contexts of all the above judgments are well-formed. mutual kd-ctx : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ctx kd-ctx (kd-⋯ a∈* b∈*) = Tp∈-ctx a∈* kd-ctx (kd-Π j-kd k-kd) = kd-ctx j-kd Tp∈-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ctx Tp∈-ctx (∈-var x Γ-ctx Γ[x]≡kd-k) = Γ-ctx Tp∈-ctx (∈-⊥-f Γ-ctx) = Γ-ctx Tp∈-ctx (∈-⊤-f Γ-ctx) = Γ-ctx Tp∈-ctx (∈-∀-f k-kd a∈*) = kd-ctx k-kd Tp∈-ctx (∈-→-f a∈* b∈*) = Tp∈-ctx a∈* Tp∈-ctx (∈-Π-i j-kd a∈k k-kd) = kd-ctx j-kd Tp∈-ctx (∈-Π-e a∈Πjk b∈j k-kd k[b]-kd) = Tp∈-ctx a∈Πjk Tp∈-ctx (∈-s-i a∈b⋯c) = Tp∈-ctx a∈b⋯c Tp∈-ctx (∈-⇑ a∈j j<∷k) = Tp∈-ctx a∈j wf-ctx : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ a wf → Γ ctx wf-ctx (wf-kd k-kd) = kd-ctx k-kd wf-ctx (wf-tp a∈*) = Tp∈-ctx a∈* <:-ctx : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a <: b ∈ k → Γ ctx <:-ctx (<:-refl a∈k) = Tp∈-ctx a∈k <:-ctx (<:-trans a<:b∈k b<:c∈k) = <:-ctx a<:b∈k <:-ctx (<:-β₁ a∈j b∈k a[b]∈k[b] k-kd k[b]-kd) = Tp∈-ctx b∈k <:-ctx (<:-β₂ a∈j b∈k a[b]∈k[b] k-kd k[b]-kd) = Tp∈-ctx b∈k <:-ctx (<:-η₁ a∈Πjk) = Tp∈-ctx a∈Πjk <:-ctx (<:-η₂ a∈Πjk) = Tp∈-ctx a∈Πjk <:-ctx (<:-⊥ a∈b⋯c) = Tp∈-ctx a∈b⋯c <:-ctx (<:-⊤ a∈b⋯c) = Tp∈-ctx a∈b⋯c <:-ctx (<:-∀ k₂<∷k₁ a₁<:a₂ ∀k₁a₁∈*) = Tp∈-ctx ∀k₁a₁∈* <:-ctx (<:-→ a₂<:a₁ b₁<:b₂) = <:-ctx a₂<:a₁ <:-ctx (<:-λ a₂<:a₁∈Πjk Λa₁k₁∈Πjk Λa₂k₂∈Πjk) = Tp∈-ctx Λa₁k₁∈Πjk <:-ctx (<:-· a₂<:a₁∈Πjk b₂≃b₁∈j b₁∈j k-kd k[b₁]-kd) = <:-ctx a₂<:a₁∈Πjk <:-ctx (<:-⟨| a∈b⋯c) = Tp∈-ctx a∈b⋯c <:-ctx (<:-|⟩ a∈b⋯c) = Tp∈-ctx a∈b⋯c <:-ctx (<:-⋯-i a<:b∈c⋯d) = <:-ctx a<:b∈c⋯d <:-ctx (<:-⇑ a<:b∈j j<∷k) = <:-ctx a<:b∈j <∷-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → Γ ctx <∷-ctx (<∷-⋯ a₂<:a₁ b₁<:b₂) = <:-ctx a₂<:a₁ <∷-ctx (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) = <∷-ctx j₂<∷j₁ ≅-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ctx ≅-ctx (<∷-antisym j<∷k k<∷j) = <∷-ctx j<∷k ≃-ctx : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ctx ≃-ctx (<:-antisym a<:b∈k b<:a∈k) = <:-ctx a<:b∈k ∈-ctx : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ∈ b → Γ ctx ∈-ctx (∈-tp a∈k) = Tp∈-ctx a∈k ∈-ctx (∈-var x Γ-ctx Γ[x]≡tp-a) = Γ-ctx ≃⊎≡-ctx : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a ≃⊎≡ b ∈ c → Γ ctx ≃⊎≡-ctx (≃-tp a≃b∈k) = ≃-ctx a≃b∈k ≃⊎≡-ctx (≃-var x Γ-ctx Γ[x]≡tp-a) = Γ-ctx ---------------------------------------------------------------------- -- Well-kinded/typed substitutions (i.e. substitution lemmas) -- A shorthand for kindings and typings of Ts by kind or type -- ascriptions. TermAscTyping : (ℕ → Set) → Set₁ TermAscTyping T = Typing TermAsc T TermAsc Level.zero -- Liftings from well-typed Ts to well-typed/kinded terms/types. LiftTo-∈ : ∀ {T} → TermAscTyping T → Set₁ LiftTo-∈ _⊢T_∈_ = LiftTyped Substitution.termAscTermSubst _⊢_wf _⊢T_∈_ _⊢_∈_ -- Helper lemmas about untyped T-substitutions in raw terms and kinds. record TypedSubstAppHelpers {T} (rawLift : Lift T Term) : Set where open Substitution using (weaken; _[_]; _Kind[_]) module A = SubstApp rawLift module L = Lift rawLift field -- Substitutions in kinds and types commute. Kind/-sub-↑ : ∀ {m n} k a (σ : Sub T m n) → k Kind[ a ] A.Kind/ σ ≡ (k A.Kind/ σ L.↑) Kind[ a A./ σ ] /-sub-↑ : ∀ {m n} b a (σ : Sub T m n) → b [ a ] A./ σ ≡ (b A./ σ L.↑) [ a A./ σ ] -- Weakening of terms commutes with substitution in terms. weaken-/ : ∀ {m n} {σ : Sub T m n} a → weaken (a A./ σ) ≡ weaken a A./ σ L.↑ -- Application of generic well-typed T-substitutions to all the judgments. module TypedSubstApp {T : ℕ → Set} (_⊢T_∈_ : TermAscTyping T) (liftTyped : LiftTo-∈ _⊢T_∈_) (helpers : TypedSubstAppHelpers (LiftTyped.rawLift liftTyped)) where open LiftTyped liftTyped renaming (lookup to /∈-lookup) open TypedSubstAppHelpers helpers -- Lift well-kinded Ts to well-kinded types. liftTp : ∀ {n} {Γ : Ctx n} {a k kd-k} → kd-k ≡ kd k → Γ ⊢T a ∈ kd-k → Γ ⊢Tp L.lift a ∈ k liftTp refl a∈kd-k with ∈-lift a∈kd-k liftTp refl a∈kd-k | ∈-tp a∈k = a∈k mutual -- Substitutions preserve well-formedness of kinds and -- well-kindedness of types. kd-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {k σ} → Γ ⊢ k kd → Δ ⊢/ σ ∈ Γ → Δ ⊢ k A.Kind/ σ kd kd-/ (kd-⋯ a∈* b∈*) σ∈Γ = kd-⋯ (Tp∈-/ a∈* σ∈Γ) (Tp∈-/ b∈* σ∈Γ) kd-/ (kd-Π j-kd k-kd) σ∈Γ = kd-Π j/σ-kd (kd-/ k-kd (∈-↑ (wf-kd j/σ-kd) σ∈Γ)) where j/σ-kd = kd-/ j-kd σ∈Γ Tp∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k σ} → Γ ⊢Tp a ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢Tp a A./ σ ∈ k A.Kind/ σ Tp∈-/ (∈-var x Γ-ctx Γ[x]≡kd-k) σ∈Γ = liftTp (cong (_/ _) Γ[x]≡kd-k) (/∈-lookup σ∈Γ x) Tp∈-/ (∈-⊥-f Γ-ctx) σ∈Γ = ∈-⊥-f (/∈-wf σ∈Γ) Tp∈-/ (∈-⊤-f Γ-ctx) σ∈Γ = ∈-⊤-f (/∈-wf σ∈Γ) Tp∈-/ (∈-∀-f k-kd a∈*) σ∈Γ = ∈-∀-f k/σ-kd (Tp∈-/ a∈* (∈-↑ (wf-kd k/σ-kd) σ∈Γ)) where k/σ-kd = kd-/ k-kd σ∈Γ Tp∈-/ (∈-→-f a∈* b∈*) σ∈Γ = ∈-→-f (Tp∈-/ a∈* σ∈Γ) (Tp∈-/ b∈* σ∈Γ) Tp∈-/ (∈-Π-i j-kd a∈k k-kd) σ∈Γ = ∈-Π-i j/σ-kd (Tp∈-/ a∈k σ↑∈j∷Γ) (kd-/ k-kd σ↑∈j∷Γ) where j/σ-kd = kd-/ j-kd σ∈Γ σ↑∈j∷Γ = ∈-↑ (wf-kd j/σ-kd) σ∈Γ Tp∈-/ (∈-Π-e {_} {b} {_} {k} a∈Πjk b∈j k-kd k[b]-kd) σ∈Γ = subst (_ ⊢Tp _ ∈_) (sym k[b]/σ≡k/σ[b/σ]) (∈-Π-e (Tp∈-/ a∈Πjk σ∈Γ) (Tp∈-/ b∈j σ∈Γ) (kd-/ k-kd (∈-↑ (kd-/-wf k-kd σ∈Γ) σ∈Γ)) (subst (_ ⊢_kd) k[b]/σ≡k/σ[b/σ] (kd-/ k[b]-kd σ∈Γ))) where k[b]/σ≡k/σ[b/σ] = Kind/-sub-↑ k b _ Tp∈-/ (∈-s-i a∈b⋯c) σ∈Γ = ∈-s-i (Tp∈-/ a∈b⋯c σ∈Γ) Tp∈-/ (∈-⇑ a∈j j<∷k) σ∈Γ = ∈-⇑ (Tp∈-/ a∈j σ∈Γ) (<∷-/ j<∷k σ∈Γ) -- Substitutions commute with subkinding, subtyping and type -- equality. <∷-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} → Γ ⊢ j <∷ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ j A.Kind/ σ <∷ k A.Kind/ σ <∷-/ (<∷-⋯ a₂<:a₁ b₁<:b₂) σ∈Γ = <∷-⋯ (<:-/ a₂<:a₁ σ∈Γ) (<:-/ b₁<:b₂ σ∈Γ) <∷-/ (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) σ∈Γ = <∷-Π (<∷-/ j₂<∷j₁ σ∈Γ) (<∷-/ k₁<∷k₂ (∈-↑ (<∷-/-wf k₁<∷k₂ σ∈Γ) σ∈Γ)) (kd-/ Πj₁k₁-kd σ∈Γ) <:-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b k σ} → Γ ⊢ a <: b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ <: b A./ σ ∈ k A.Kind/ σ <:-/ (<:-refl a∈k) σ∈Γ = <:-refl (Tp∈-/ a∈k σ∈Γ) <:-/ (<:-trans a<:b∈k b<:c∈k) σ∈Γ = <:-trans (<:-/ a<:b∈k σ∈Γ) (<:-/ b<:c∈k σ∈Γ) <:-/ (<:-β₁ {j} {a} {k} {b} a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) σ∈Γ = subst₂ (_ ⊢ (Λ j a) · b A./ _ <:_∈_) (sym a[b]/σ≡a/σ[b/σ]) (sym k[b]/σ≡k/σ[b/σ]) (<:-β₁ (Tp∈-/ a∈k σ↑∈j∷Γ) (Tp∈-/ b∈j σ∈Γ) (subst₂ (_ ⊢Tp_∈_) a[b]/σ≡a/σ[b/σ] k[b]/σ≡k/σ[b/σ] (Tp∈-/ a[b]∈k[b] σ∈Γ)) (kd-/ k-kd σ↑∈j∷Γ) (subst (_ ⊢_kd) k[b]/σ≡k/σ[b/σ] (kd-/ k[b]-kd σ∈Γ))) where σ↑∈j∷Γ = ∈-↑ (Tp∈-/-wf a∈k σ∈Γ) σ∈Γ k[b]/σ≡k/σ[b/σ] = Kind/-sub-↑ k b _ a[b]/σ≡a/σ[b/σ] = /-sub-↑ a b _ <:-/ (<:-β₂ {j} {a} {k} {b} a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) σ∈Γ = subst₂ (_ ⊢_<: (Λ j a) · b A./ _ ∈_) (sym a[b]/σ≡a/σ[b/σ]) (sym k[b]/σ≡k/σ[b/σ]) (<:-β₂ (Tp∈-/ a∈k σ↑∈j∷Γ) (Tp∈-/ b∈j σ∈Γ) (subst₂ (_ ⊢Tp_∈_) a[b]/σ≡a/σ[b/σ] k[b]/σ≡k/σ[b/σ] (Tp∈-/ a[b]∈k[b] σ∈Γ)) (kd-/ k-kd σ↑∈j∷Γ) (subst (_ ⊢_kd) k[b]/σ≡k/σ[b/σ] (kd-/ k[b]-kd σ∈Γ))) where σ↑∈j∷Γ = ∈-↑ (Tp∈-/-wf a∈k σ∈Γ) σ∈Γ k[b]/σ≡k/σ[b/σ] = Kind/-sub-↑ k b _ a[b]/σ≡a/σ[b/σ] = /-sub-↑ a b _ <:-/ {Δ = Δ} {σ = σ} (<:-η₁ {a} {j} {k} a∈Πjk) σ∈Γ = subst (Δ ⊢_<: a A./ σ ∈ Π j k A.Kind/ σ) (cong (Λ _) (cong₂ _·_ (weaken-/ a) (sym (lift-var zero)))) (<:-η₁ (Tp∈-/ a∈Πjk σ∈Γ)) <:-/ {Δ = Δ} {σ = σ} (<:-η₂ {a} {j} {k} a∈Πjk) σ∈Γ = subst (Δ ⊢ a A./ σ <:_∈ Π j k A.Kind/ σ) (cong (Λ _) (cong₂ _·_ (weaken-/ a) (sym (lift-var zero)))) (<:-η₂ (Tp∈-/ a∈Πjk σ∈Γ)) <:-/ (<:-⊥ a∈b⋯c) σ∈Γ = <:-⊥ (Tp∈-/ a∈b⋯c σ∈Γ) <:-/ (<:-⊤ a∈b⋯c) σ∈Γ = <:-⊤ (Tp∈-/ a∈b⋯c σ∈Γ) <:-/ (<:-∀ k₂<∷k₁ a₁<:a₂∈* ∀j₁k₁∈*) σ∈Γ = <:-∀ (<∷-/ k₂<∷k₁ σ∈Γ) (<:-/ a₁<:a₂∈* (∈-↑ (<:-/-wf a₁<:a₂∈* σ∈Γ) σ∈Γ)) (Tp∈-/ ∀j₁k₁∈* σ∈Γ) <:-/ (<:-→ a₂<:a₁∈* b₁<:b₂∈*) σ∈Γ = <:-→ (<:-/ a₂<:a₁∈* σ∈Γ) (<:-/ b₁<:b₂∈* σ∈Γ) <:-/ (<:-λ a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk) σ∈Γ = <:-λ (<:-/ a₁<:a₂∈k (∈-↑ (<:-/-wf a₁<:a₂∈k σ∈Γ) σ∈Γ)) (Tp∈-/ Λj₁a₁∈Πjk σ∈Γ) (Tp∈-/ Λj₂a₂∈Πjk σ∈Γ) <:-/ (<:-· {k = k} a₁<:a₂∈Πjk b₁≃b₂∈j b₁∈j k-kd k[b₁]-kd) σ∈Γ = subst (_ ⊢ _ <: _ ∈_) (sym k[b₁]/σ≡k/σ[b₁/σ]) (<:-· (<:-/ a₁<:a₂∈Πjk σ∈Γ) (≃-/ b₁≃b₂∈j σ∈Γ) (Tp∈-/ b₁∈j σ∈Γ) (kd-/ k-kd (∈-↑ (kd-/-wf k-kd σ∈Γ) σ∈Γ)) (subst (_ ⊢_kd) k[b₁]/σ≡k/σ[b₁/σ] (kd-/ k[b₁]-kd σ∈Γ))) where k[b₁]/σ≡k/σ[b₁/σ] = Kind/-sub-↑ k _ _ <:-/ (<:-⟨| a∈b⋯c) σ∈Γ = <:-⟨| (Tp∈-/ a∈b⋯c σ∈Γ) <:-/ (<:-|⟩ a∈b⋯c) σ∈Γ = <:-|⟩ (Tp∈-/ a∈b⋯c σ∈Γ) <:-/ (<:-⋯-i a<:b∈c⋯d) σ∈Γ = <:-⋯-i (<:-/ a<:b∈c⋯d σ∈Γ) <:-/ (<:-⇑ a<:b∈j j<∷k) σ∈Γ = <:-⇑ (<:-/ a<:b∈j σ∈Γ) (<∷-/ j<∷k σ∈Γ) ≃-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b k σ} → Γ ⊢ a ≃ b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ ≃ b A./ σ ∈ k A.Kind/ σ ≃-/ (<:-antisym a<:b∈k b<:a∈k) σ∈Γ = <:-antisym (<:-/ a<:b∈k σ∈Γ) (<:-/ b<:a∈k σ∈Γ) -- Helpers (to satisfy the termination checker). kd-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} → kd j ∷ Γ ⊢ k kd → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf kd-/-wf (kd-⋯ a∈* _) σ∈Γ = Tp∈-/-wf a∈* σ∈Γ kd-/-wf (kd-Π j-kd _) σ∈Γ = kd-/-wf j-kd σ∈Γ Tp∈-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k σ} → kd j ∷ Γ ⊢Tp a ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf Tp∈-/-wf (∈-var x (wf-kd k-kd ∷ Γ-ctx) _) σ∈Γ = wf-kd (kd-/ k-kd σ∈Γ) Tp∈-/-wf (∈-⊥-f (wf-kd j-kd ∷ Γ-ctx)) σ∈Γ = wf-kd (kd-/ j-kd σ∈Γ) Tp∈-/-wf (∈-⊤-f (wf-kd j-kd ∷ Γ-ctx)) σ∈Γ = wf-kd (kd-/ j-kd σ∈Γ) Tp∈-/-wf (∈-∀-f k-kd _) σ∈Γ = kd-/-wf k-kd σ∈Γ Tp∈-/-wf (∈-→-f a∈* _) σ∈Γ = Tp∈-/-wf a∈* σ∈Γ Tp∈-/-wf (∈-Π-i j-kd _ _) σ∈Γ = kd-/-wf j-kd σ∈Γ Tp∈-/-wf (∈-Π-e a∈Πjk _ _ _) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ Tp∈-/-wf (∈-s-i a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ Tp∈-/-wf (∈-⇑ a∈b _) σ∈Γ = Tp∈-/-wf a∈b σ∈Γ <:-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b j k σ} → kd j ∷ Γ ⊢ a <: b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf <:-/-wf (<:-refl a∈k) σ∈Γ = Tp∈-/-wf a∈k σ∈Γ <:-/-wf (<:-trans a<:b _) σ∈Γ = <:-/-wf a<:b σ∈Γ <:-/-wf (<:-β₁ _ b∈j _ _ _) σ∈Γ = Tp∈-/-wf b∈j σ∈Γ <:-/-wf (<:-β₂ _ b∈j _ _ _) σ∈Γ = Tp∈-/-wf b∈j σ∈Γ <:-/-wf (<:-η₁ a∈Πjk) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ <:-/-wf (<:-η₂ a∈Πjk) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ <:-/-wf (<:-⊥ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ <:-/-wf (<:-⊤ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ <:-/-wf (<:-∀ j₂<∷j₁ _ _) σ∈Γ = <∷-/-wf j₂<∷j₁ σ∈Γ <:-/-wf (<:-→ a₂<:a₁∈* _) σ∈Γ = <:-/-wf a₂<:a₁∈* σ∈Γ <:-/-wf (<:-λ _ Λj₁a₂∈Πjk _) σ∈Γ = Tp∈-/-wf Λj₁a₂∈Πjk σ∈Γ <:-/-wf (<:-· a₁<:a₂∈Πjk _ _ _ _) σ∈Γ = <:-/-wf a₁<:a₂∈Πjk σ∈Γ <:-/-wf (<:-⟨| a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ <:-/-wf (<:-|⟩ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ <:-/-wf (<:-⋯-i a<:b∈c⋯d) σ∈Γ = <:-/-wf a<:b∈c⋯d σ∈Γ <:-/-wf (<:-⇑ a<:b∈k _) σ∈Γ = <:-/-wf a<:b∈k σ∈Γ <∷-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k l σ} → kd j ∷ Γ ⊢ k <∷ l → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf <∷-/-wf (<∷-⋯ j₂<:j₁ _) σ∈Γ = <:-/-wf j₂<:j₁ σ∈Γ <∷-/-wf (<∷-Π j₂<∷j₁ _ _) σ∈Γ = <∷-/-wf j₂<∷j₁ σ∈Γ -- Substitutions preserve well-formedness of ascriptions. wf-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a σ} → Γ ⊢ a wf → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.TermAsc/ σ wf wf-/ (wf-kd k-kd) σ∈Γ = wf-kd (kd-/ k-kd σ∈Γ) wf-/ (wf-tp a∈b) σ∈Γ = wf-tp (Tp∈-/ a∈b σ∈Γ) -- Substitutions commute with kind equality. ≅-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} → Γ ⊢ j ≅ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ j A.Kind/ σ ≅ k A.Kind/ σ ≅-/ (<∷-antisym j<∷k k<∷j) σ∈Γ = <∷-antisym (<∷-/ j<∷k σ∈Γ) (<∷-/ k<∷j σ∈Γ) -- Substitutions preserve well-kindedness and well-typedness. ∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} → Γ ⊢ a ∈ b → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ ∈ b A.TermAsc/ σ ∈-/ (∈-tp a∈b) σ∈Γ = ∈-tp (Tp∈-/ a∈b σ∈Γ) ∈-/ (∈-var x Γ-ctx Γ[x]≡tp-a) σ∈Γ = subst (_ ⊢ _ ∈_) (cong (A._TermAsc/ _) Γ[x]≡tp-a) (∈-lift (/∈-lookup σ∈Γ x)) -- Substitutions preserve type and syntactic term equality. ≃⊎≡-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b c σ} → Γ ⊢ a ≃⊎≡ b ∈ c → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ ≃⊎≡ b A./ σ ∈ c A.TermAsc/ σ ≃⊎≡-/ (≃-tp a≃b∈k) σ∈Γ = ≃-tp (≃-/ a≃b∈k σ∈Γ) ≃⊎≡-/ (≃-var x Γ-ctx Γ[x]≡tp-a) σ∈Γ = let x/σ∈tp-a/σ = subst (_ ⊢ _ ∈_) (cong (A._TermAsc/ _) Γ[x]≡tp-a) (∈-lift (/∈-lookup σ∈Γ x)) in ≃⊎≡-refl x/σ∈tp-a/σ -- Well-kinded type substitutions. module KindedSubstitution where open Substitution using (simple; termSubst) open SimpleExt simple using (extension) open TermSubst termSubst using (varLift; termLift) private module S = Substitution module KL = TermLikeLemmas S.termLikeLemmasKind -- Helper lemmas about untyped renamings and substitutions in terms -- and kinds. varHelpers : TypedSubstAppHelpers varLift varHelpers = record { Kind/-sub-↑ = KL./-sub-↑ ; /-sub-↑ = LiftSubLemmas./-sub-↑ S.varLiftSubLemmas ; weaken-/ = LiftAppLemmas.wk-commutes S.varLiftAppLemmas } termHelpers : TypedSubstAppHelpers termLift termHelpers = record { Kind/-sub-↑ = λ k _ _ → KL.sub-commutes k ; /-sub-↑ = λ a _ _ → S.sub-commutes a ; weaken-/ = S.weaken-/ } -- Kinded type substitutions. typedTermSubst : TypedTermSubst TermAsc Term Level.zero TypedSubstAppHelpers typedTermSubst = record { _⊢_wf = _⊢_wf ; _⊢_∈_ = _⊢_∈_ ; termLikeLemmas = S.termLikeLemmasTermAsc ; varHelpers = varHelpers ; termHelpers = termHelpers ; wf-wf = wf-ctx ; ∈-wf = ∈-ctx ; ∈-var = ∈-var′ ; typedApp = TypedSubstApp.∈-/ } open TypedTermSubst typedTermSubst public hiding (_⊢_wf; _⊢_∈_; varHelpers; termHelpers; ∈-var; ∈-/Var; ∈-/) renaming (lookup to /∈-lookup) open TypedSubstApp _⊢Var_∈_ varLiftTyped varHelpers public using () renaming ( wf-/ to wf-/Var ; kd-/ to kd-/Var ; Tp∈-/ to Tp∈-/Var ; <∷-/ to <∷-/Var ; <:-/ to <:-/Var ; ∈-/ to ∈-/Var ; ≃⊎≡-/ to ≃⊎≡-/Var ) open Substitution using (weaken; weakenKind; weakenTermAsc) -- Weakening preserves the various judgments. wf-weaken : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a wf → Γ ⊢ b wf → (a ∷ Γ) ⊢ weakenTermAsc b wf wf-weaken a-wf b-wf = wf-/Var b-wf (Var∈-wk a-wf) kd-weaken : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢ a wf → Γ ⊢ k kd → (a ∷ Γ) ⊢ weakenKind k kd kd-weaken a-wf k-kd = kd-/Var k-kd (Var∈-wk a-wf) Tp∈-weaken : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a wf → Γ ⊢Tp b ∈ k → (a ∷ Γ) ⊢Tp weaken b ∈ weakenKind k Tp∈-weaken a-wf b∈k = Tp∈-/Var b∈k (Var∈-wk a-wf) <∷-weaken : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢ a wf → Γ ⊢ j <∷ k → (a ∷ Γ) ⊢ weakenKind j <∷ weakenKind k <∷-weaken a-wf j<∷k = <∷-/Var j<∷k (Var∈-wk a-wf) <:-weaken : ∀ {n} {Γ : Ctx n} {a b c k} → Γ ⊢ a wf → Γ ⊢ b <: c ∈ k → (a ∷ Γ) ⊢ weaken b <: weaken c ∈ weakenKind k <:-weaken a-wf b<:c∈k = <:-/Var b<:c∈k (Var∈-wk a-wf) ∈-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b ∈ c → (a ∷ Γ) ⊢ weaken b ∈ weakenTermAsc c ∈-weaken a-wf b∈c = ∈-/Var b∈c (Var∈-wk a-wf) -- Weakening preserves type and syntactic term equality. ≃⊎≡-weaken : ∀ {n} {Γ : Ctx n} {a b c d} → Γ ⊢ a wf → Γ ⊢ b ≃⊎≡ c ∈ d → (a ∷ Γ) ⊢ weaken b ≃⊎≡ weaken c ∈ weakenTermAsc d ≃⊎≡-weaken a-wf b≃⊎≡c∈d = ≃⊎≡-/Var b≃⊎≡c∈d (Var∈-wk a-wf) open TypedSubstApp _⊢_∈_ termLiftTyped termHelpers public open Substitution using (_/_; _Kind/_; id; sub; _↑⋆_; _[_]; _Kind[_]) -- Substitution of a single well-typed term or well-kinded type -- preserves the various judgments. kd-[] : ∀ {n} {Γ : Ctx n} {a b k} → b ∷ Γ ⊢ k kd → Γ ⊢ a ∈ b → Γ ⊢ k Kind[ a ] kd kd-[] k-kd a∈b = kd-/ k-kd (∈-sub a∈b) ≅-[] : ∀ {n} {Γ : Ctx n} {j k a b} → b ∷ Γ ⊢ j ≅ k → Γ ⊢ a ∈ b → Γ ⊢ j Kind[ a ] ≅ k Kind[ a ] ≅-[] j≅k a∈b = ≅-/ j≅k (∈-sub a∈b) Tp∈-[] : ∀ {n} {Γ : Ctx n} {a b k c} → c ∷ Γ ⊢Tp a ∈ k → Γ ⊢ b ∈ c → Γ ⊢Tp a [ b ] ∈ k Kind[ b ] Tp∈-[] a∈k b∈c = Tp∈-/ a∈k (∈-sub b∈c) -- Context narrowing. -- A typed substitution that narrows the kind of the first type -- variable. ∈-<∷-sub : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j kd → Γ ⊢ j <∷ k → kd j ∷ Γ ⊢/ id ∈ kd k ∷ Γ ∈-<∷-sub j-kd j<∷k = ∈-tsub (∈-tp (∈-⇑ (∈-var zero (j-wf ∷ Γ-ctx) refl) (<∷-weaken j-wf j<∷k))) where j-wf = wf-kd j-kd Γ-ctx = kd-ctx j-kd -- Narrowing the kind of the first type variable preserves -- well-formedness of kinds. ⇓-kd : ∀ {n} {Γ : Ctx n} {j₁ j₂ k} → Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢ k kd → kd j₁ ∷ Γ ⊢ k kd ⇓-kd j₁-kd j₁<∷j₂ k-kd = subst (_ ⊢_kd) (KL.id-vanishes _) (kd-/ k-kd (∈-<∷-sub j₁-kd j₁<∷j₂)) -- Narrowing the kind of the first type variable preserves -- well-kindedness. ⇓-Tp∈ : ∀ {n} {Γ : Ctx n} {j₁ j₂ a k} → Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢Tp a ∈ k → kd j₁ ∷ Γ ⊢Tp a ∈ k ⇓-Tp∈ j₁-kd j₁<∷j₂ a∈k = subst₂ (_ ⊢Tp_∈_) (S.id-vanishes _) (KL.id-vanishes _) (Tp∈-/ a∈k (∈-<∷-sub j₁-kd j₁<∷j₂)) -- Narrowing the kind of the first type variable preserves -- subkinding and subtyping. ⇓-<∷ : ∀ {n} {Γ : Ctx n} {j₁ j₂ k₁ k₂} → Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢ k₁ <∷ k₂ → kd j₁ ∷ Γ ⊢ k₁ <∷ k₂ ⇓-<∷ j₁-kd j₁<∷j₂ k₁<∷k₂ = subst₂ (_ ⊢_<∷_) (KL.id-vanishes _) (KL.id-vanishes _) (<∷-/ k₁<∷k₂ (∈-<∷-sub j₁-kd j₁<∷j₂)) ⇓-<: : ∀ {n} {Γ : Ctx n} {j₁ j₂ a₁ a₂ k} → Γ ⊢ j₁ kd → Γ ⊢ j₁ <∷ j₂ → kd j₂ ∷ Γ ⊢ a₁ <: a₂ ∈ k → kd j₁ ∷ Γ ⊢ a₁ <: a₂ ∈ k ⇓-<: j₁-kd j₁<∷j₂ a₁<:a₂∈k = subst (_ ⊢ _ <: _ ∈_) (KL.id-vanishes _) (subst₂ (_ ⊢_<:_∈ _) (S.id-vanishes _) (S.id-vanishes _) (<:-/ a₁<:a₂∈k (∈-<∷-sub j₁-kd j₁<∷j₂))) -- Operations on well-formed contexts that require weakening of -- well-formedness judgments. module WfCtxOps where wfWeakenOps : WellFormedWeakenOps weakenOps wfWeakenOps = record { wf-weaken = KindedSubstitution.wf-weaken } open WellFormedWeakenOps wfWeakenOps public renaming (lookup to lookup-wf) -- Lookup the kind of a type variable in a well-formed context. lookup-kd : ∀ {m} {Γ : Ctx m} {k} x → Γ ctx → TermCtx.lookup Γ x ≡ kd k → Γ ⊢ k kd lookup-kd x Γ-ctx Γ[x]≡kd-k = wf-kd-inv (subst (_ ⊢_wf) Γ[x]≡kd-k (lookup-wf Γ-ctx x)) open KindedSubstitution open WfCtxOps -- Transitivity of subkinding. <∷-trans : ∀ {n} {Γ : Ctx n} {j k l} → Γ ⊢ j <∷ k → Γ ⊢ k <∷ l → Γ ⊢ j <∷ l <∷-trans (<∷-⋯ a₂<:a₁ b₁<:b₂) (<∷-⋯ a₃<:a₂ b₂<:b₃) = <∷-⋯ (<:-trans a₃<:a₂ a₂<:a₁) (<:-trans b₁<:b₂ b₂<:b₃) <∷-trans (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) (<∷-Π j₃<∷j₂ k₂<∷k₃ Πj₂k₂-kd) = <∷-Π (<∷-trans j₃<∷j₂ j₂<∷j₁) (<∷-trans (⇓-<∷ (wf-kd-inv (wf-∷₁ (<∷-ctx k₂<∷k₃))) j₃<∷j₂ k₁<∷k₂) k₂<∷k₃) Πj₁k₁-kd -- Transitivity of kind equality. ≅-trans : ∀ {n} {Γ : Ctx n} {j k l} → Γ ⊢ j ≅ k → Γ ⊢ k ≅ l → Γ ⊢ j ≅ l ≅-trans (<∷-antisym k₁<∷k₂ k₂<∷k₁) (<∷-antisym k₂<∷k₃ k₃<∷k₂) = <∷-antisym (<∷-trans k₁<∷k₂ k₂<∷k₃) (<∷-trans k₃<∷k₂ k₂<∷k₁) ---------------------------------------------------------------------- -- Well-formed equality lifted to substitutions module WfSubstitutionEquality where open Substitution hiding (subst) open TermSubst termSubst using (termLift) open ZipUnzipSimple simple simple open TypedSubstAppHelpers KindedSubstitution.termHelpers private module KL = TermLikeLemmas termLikeLemmasKind module AL = TermLikeLemmas termLikeLemmasTermAsc module S = SimpleExt simple module Z = SimpleExt zippedSimple -- Well-formed equal substitutions: pairs of substitutions that are -- point-wise equal. wfEqSub : TypedSubRel TermAsc Term Level.zero wfEqSub = record { typedRelation = record { _⊢_wf = _⊢_wf ; _⊢_∼_∈_ = _⊢_≃⊎≡_∈_ } ; typeExtension = TermCtx.weakenOps ; typeTermApplication = record { _/_ = λ a ρσ → a TermAsc/ (π₁ ρσ) } ; termSimple = simple } open TypedSubRel wfEqSub public using () renaming (_⊢/_∼_∈_ to _⊢/_≃_∈_) -- Simple substitutions of well-formed equal terms and types. wfEqWeakenOps : TypedRelWeakenOps wfEqSub wfEqWeakenOps = record { ∼∈-weaken = ≃⊎≡-weaken ; ∼∈-wf = ≃⊎≡-ctx ; /-wk = /-wk-π₁ ; /-weaken = λ {m} {n} {στ} a → /-weaken-π₁ {m} {n} {στ} a ; weaken-/-∷ = AL.weaken-/-∷ } where open ≡-Reasoning /-wk-π₁ : ∀ {n} {a : TermAsc n} → a TermAsc/ π₁ Z.wk ≡ weakenTermAsc a /-wk-π₁ {_} {a} = begin a TermAsc/ π₁ Z.wk ≡⟨ cong ((a TermAsc/_) ∘ proj₁) (sym wk-unzip) ⟩ a TermAsc/ wk ≡⟨ AL./-wk ⟩ weakenTermAsc a ∎ /-weaken-π₁ : ∀ {m n} {στ : Sub (Term ⊗ Term) m n} a → a TermAsc/ π₁ (Vec.map Z.weaken στ) ≡ a TermAsc/ π₁ στ TermAsc/ π₁ Z.wk /-weaken-π₁ {_} {_} {στ} a = begin a TermAsc/ π₁ (Vec.map Z.weaken στ) ≡˘⟨ cong ((a TermAsc/_) ∘ proj₁) (map-weaken-unzip στ) ⟩ a TermAsc/ Vec.map S.weaken (π₁ στ) ≡⟨ AL./-weaken a ⟩ a TermAsc/ π₁ στ TermAsc/ S.wk ≡⟨ cong ((a TermAsc/ π₁ στ TermAsc/_) ∘ proj₁) wk-unzip ⟩ a TermAsc/ π₁ στ TermAsc/ π₁ Z.wk ∎ wfEqSimple : TypedRelSimple wfEqSub wfEqSimple = record { typedRelWeakenOps = wfEqWeakenOps ; ∼∈-var = ≃⊎≡-var ; wf-wf = wf-ctx ; id-vanishes = id-vanishes-π₁ } where open TypedRelWeakenOps wfEqWeakenOps open ≡-Reasoning id-vanishes-π₁ : ∀ {n} (a : TermAsc n) → a TermAsc/ π₁ Z.id ≡ a id-vanishes-π₁ a = begin a TermAsc/ π₁ Z.id ≡⟨ cong ((a TermAsc/_) ∘ proj₁) (sym id-unzip) ⟩ a TermAsc/ id ≡⟨ AL.id-vanishes a ⟩ a ∎ open TypedRelSimple wfEqSimple public hiding (typedRelWeakenOps; ∼∈-var; ∼∈-weaken; ∼∈-wf; wf-wf) renaming (lookup to ≃-lookup) infixl 4 _⊢/_≃′_∈_ -- An inversion lemma for the generic term/type equality. ≃⊎≡-kd-inv : ∀ {n} {Γ : Ctx n} {a b k kd-k} → kd-k ≡ kd k → Γ ⊢ a ≃⊎≡ b ∈ kd-k → Γ ⊢ a ≃ b ∈ k ≃⊎≡-kd-inv refl (≃-tp a≃b∈k) = a≃b∈k -- A shorthand. -- -- TODO: explain why we use this particular representation of equal -- substitutions here. _⊢/_≃′_∈_ : ∀ {m n} → Ctx n → Sub Term m n → Sub Term m n → Ctx m → Set Δ ⊢/ σ ≃′ ρ ∈ Γ = Δ ⊢/ σ ∈ Γ × Δ ⊢/ ρ ∈ Γ × Δ ⊢/ σ ≃ ρ ∈ Γ × Δ ⊢/ ρ ≃ σ ∈ Γ -- Symmetry of substitution equality. ≃′-sym : ∀ {m n Δ Γ} {ρ σ : Sub Term m n} → Δ ⊢/ ρ ≃′ σ ∈ Γ → Δ ⊢/ σ ≃′ ρ ∈ Γ ≃′-sym (ρ∈Γ , σ∈Γ , ρ≃σ∈Γ , σ≃ρ∈Γ) = σ∈Γ , ρ∈Γ , σ≃ρ∈Γ , ρ≃σ∈Γ -- Lift a pair of equal substitutions over an additional type -- variable. ≃′-↑ : ∀ {m n Γ Δ} {ρ σ : Sub Term m n} {j k} → Δ ⊢ j kd → Δ ⊢ j ≅ k Kind/ ρ → Δ ⊢ j ≅ k Kind/ σ → Δ ⊢/ ρ ≃′ σ ∈ Γ → kd j ∷ Δ ⊢/ ρ ↑ ≃′ σ ↑ ∈ kd k ∷ Γ ≃′-↑ j-kd j≅k/ρ j≅k/σ (ρ∈Γ , σ∈Γ , ρ≃σ∈ , σ≃ρ∈) = ∈-/∷ (∈-tp z∈k/ρ) ρ∈Γ , ∈-/∷ (∈-tp z∈k/σ) σ∈Γ , ∼∈-/∷ (≃-tp (≃-refl z∈k/ρ′)) ρ≃σ∈ , ∼∈-/∷ (≃-tp (≃-refl z∈k/σ′)) σ≃ρ∈ where j-wf = wf-kd j-kd j∷Δ-ctx = j-wf ∷ kd-ctx j-kd z∈k/ρ = ∈-⇑ (∈-var zero j∷Δ-ctx refl) (<∷-weaken j-wf (≅⇒<∷ j≅k/ρ)) z∈k/σ = ∈-⇑ (∈-var zero j∷Δ-ctx refl) (<∷-weaken j-wf (≅⇒<∷ j≅k/σ)) z∈k/ρ′ = subst (_ ⊢Tp _ ∈_) (cong (weakenKind ∘ (_ Kind/_)) (sym (π₁-zip _ _))) z∈k/ρ z∈k/σ′ = subst (_ ⊢Tp _ ∈_) (cong (weakenKind ∘ (_ Kind/_)) (sym (π₁-zip _ _))) z∈k/σ -- Lemmas about equal substitutions (weak versions). mutual -- Equal substitutions map well-formed kinds to kind equations. kd-/≃ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {k ρ σ} → Γ ⊢ k kd → Δ ⊢/ ρ ≃′ σ ∈ Γ → Δ ⊢ k Kind/ ρ ≅ k Kind/ σ kd-/≃ (kd-⋯ a∈* b∈*) ρ≃σ∈Γ = ≅-⋯ (Tp∈-/≃ a∈* ρ≃σ∈Γ) (Tp∈-/≃ b∈* ρ≃σ∈Γ) kd-/≃ (kd-Π j-kd k-kd) ρ≃σ∈Γ = let ρ∈Γ , σ∈Γ , _ = ρ≃σ∈Γ j/ρ-kd = kd-/ j-kd ρ∈Γ j/σ-kd = kd-/ j-kd σ∈Γ j/ρ≅j/σ = kd-/≃ j-kd ρ≃σ∈Γ k/ρ≅k/σ = kd-/≃ k-kd (≃′-↑ j/σ-kd (≅-sym j/ρ≅j/σ) (≅-refl j/σ-kd) ρ≃σ∈Γ) k/σ≅k/ρ = kd-/≃ k-kd (≃′-↑ j/ρ-kd j/ρ≅j/σ (≅-refl j/ρ-kd) (≃′-sym ρ≃σ∈Γ)) Πjk/ρ-kd = kd-/ (kd-Π j-kd k-kd) ρ∈Γ Πjk/σ-kd = kd-/ (kd-Π j-kd k-kd) σ∈Γ in <∷-antisym (<∷-Π (≅⇒<∷ (≅-sym j/ρ≅j/σ)) (≅⇒<∷ k/ρ≅k/σ) Πjk/ρ-kd) (<∷-Π (≅⇒<∷ j/ρ≅j/σ) (≅⇒<∷ k/σ≅k/ρ) Πjk/σ-kd) -- Equal substitutions map well-kinded types to type equations. Tp∈-/≃ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k ρ σ} → Γ ⊢Tp a ∈ k → Δ ⊢/ ρ ≃′ σ ∈ Γ → Δ ⊢ a / ρ ≃ a / σ ∈ k Kind/ ρ Tp∈-/≃ {ρ = ρ} {σ} (∈-var x Γ-ctx Γ[x]≡kd-k) (_ , _ , ρ≃σ∈Γ , _) = (≃⊎≡-kd-inv (cong (_TermAsc/ ρ) Γ[x]≡kd-k) (subst (_ ⊢ _ ≃⊎≡ _ ∈_) (cong (_ TermAsc/_) (π₁-zip ρ σ)) (≃-lookup ρ≃σ∈Γ x))) Tp∈-/≃ (∈-⊥-f Γ-ctx) (ρ∈Γ , _) = ≃-refl (∈-⊥-f (/∈-wf ρ∈Γ)) Tp∈-/≃ (∈-⊤-f Γ-ctx) (ρ∈Γ , _) = ≃-refl (∈-⊤-f (/∈-wf ρ∈Γ)) Tp∈-/≃ (∈-∀-f k-kd a∈*) ρ≃σ∈Γ = let ρ∈Γ , σ∈Γ , _ = ρ≃σ∈Γ k/ρ-kd = kd-/ k-kd ρ∈Γ k/σ-kd = kd-/ k-kd σ∈Γ k/ρ≅k/σ = kd-/≃ k-kd ρ≃σ∈Γ a/ρ≃a/σ∈* = Tp∈-/≃ a∈* (≃′-↑ k/σ-kd (≅-sym k/ρ≅k/σ) (≅-refl k/σ-kd) ρ≃σ∈Γ) a/σ≃a/ρ∈* = Tp∈-/≃ a∈* (≃′-↑ k/ρ-kd k/ρ≅k/σ (≅-refl k/ρ-kd) (≃′-sym ρ≃σ∈Γ)) ∀ka/ρ∈* = Tp∈-/ (∈-∀-f k-kd a∈*) ρ∈Γ ∀ka/σ∈* = Tp∈-/ (∈-∀-f k-kd a∈*) σ∈Γ in <:-antisym (<:-∀ (≅⇒<∷ (≅-sym k/ρ≅k/σ)) (≃⇒<: a/ρ≃a/σ∈*) ∀ka/ρ∈*) (<:-∀ (≅⇒<∷ k/ρ≅k/σ) (≃⇒<: a/σ≃a/ρ∈*) ∀ka/σ∈*) Tp∈-/≃ (∈-→-f a∈* b∈*) ρ≃σ∈Γ = ≃-→ (Tp∈-/≃ a∈* ρ≃σ∈Γ) (Tp∈-/≃ b∈* ρ≃σ∈Γ) Tp∈-/≃ (∈-Π-i j-kd a∈k k-kd) ρ≃σ∈Γ = let ρ∈Γ , σ∈Γ , _ = ρ≃σ∈Γ j/ρ-kd = kd-/ j-kd ρ∈Γ j/σ-kd = kd-/ j-kd σ∈Γ j/ρ≅j/σ = kd-/≃ j-kd ρ≃σ∈Γ ρ↑∈j∷Γ = ∈-↑ (wf-kd j/ρ-kd) ρ∈Γ σ↑∈j∷Γ = ∈-↑ (wf-kd j/σ-kd) σ∈Γ ρ↑≃σ↑∈j∷Γ = ≃′-↑ j/ρ-kd (≅-refl j/ρ-kd) j/ρ≅j/σ ρ≃σ∈Γ a/ρ∈k/ρ = Tp∈-/ a∈k ρ↑∈j∷Γ a/σ∈k/σ = Tp∈-/ a∈k σ↑∈j∷Γ a/ρ≃a/σ∈k/ρ = Tp∈-/≃ a∈k ρ↑≃σ↑∈j∷Γ k/ρ-kd = kd-/ k-kd ρ↑∈j∷Γ k/σ-kd = kd-/ k-kd σ↑∈j∷Γ k/ρ≅k/σ = kd-/≃ k-kd ρ↑≃σ↑∈j∷Γ Λja/ρ∈Πjk/ρ = ∈-Π-i j/ρ-kd a/ρ∈k/ρ k/ρ-kd Πjk/σ<∷Πjk/ρ = <∷-Π (≅⇒<∷ j/ρ≅j/σ) (≅⇒<∷ (≅-sym k/ρ≅k/σ)) (kd-Π j/σ-kd k/σ-kd) Λja/σ∈Πjk/ρ = ∈-⇑ (∈-Π-i j/σ-kd a/σ∈k/σ k/σ-kd) Πjk/σ<∷Πjk/ρ in ≃-λ a/ρ≃a/σ∈k/ρ Λja/ρ∈Πjk/ρ Λja/σ∈Πjk/ρ Tp∈-/≃ (∈-Π-e {k = k} a∈Πjk b∈j k-kd k[b]-kd) ρ≃σ∈Γ = let k[b]/ρ≡k/ρ[b/ρ] = Kind/-sub-↑ k _ _ k[b]/σ≡k/σ[b/σ] = Kind/-sub-↑ k _ _ ρ∈Γ , σ∈Γ , _ = ρ≃σ∈Γ j-wf = wf-∷₁ (kd-ctx k-kd) j-kd = wf-kd-inv j-wf j/σ≅j/ρ = kd-/≃-≅ k-kd (≃′-sym ρ≃σ∈Γ) j/σ-kd = kd-/ j-kd σ∈Γ ρ↑≃σ↑∈j∷Γ = ≃′-↑ j/σ-kd j/σ≅j/ρ (≅-refl j/σ-kd) ρ≃σ∈Γ ρ↑∈j∷Γ = (∈-↑ (wf-/ j-wf ρ∈Γ) ρ∈Γ) a/ρ≃a/σ∈Πjk/ρ = Tp∈-/≃ a∈Πjk ρ≃σ∈Γ b/ρ≃b/σ∈j/ρ = Tp∈-/≃ b∈j ρ≃σ∈Γ k[b]/ρ≅k[b]/σ = kd-/≃ k[b]-kd ρ≃σ∈Γ k/ρ≅k/σ = kd-/≃ k-kd ρ↑≃σ↑∈j∷Γ b/ρ∈j/ρ = Tp∈-/ b∈j ρ∈Γ b/σ∈j/σ = Tp∈-/ b∈j σ∈Γ b/σ∈j/ρ = ∈-⇑ b/σ∈j/σ (≅⇒<∷ j/σ≅j/ρ) k/ρ-kd = kd-/ k-kd ρ↑∈j∷Γ k/ρ[b/ρ]-kd = subst (_ ⊢_kd) k[b]/ρ≡k/ρ[b/ρ] (kd-/ k[b]-kd ρ∈Γ) k/ρ[b/σ]-kd = kd-[] k/ρ-kd (∈-tp b/σ∈j/ρ) k/ρ[b/σ]≅k[b]/σ = subst (_ ⊢ (k Kind/ _) Kind[ _ ] ≅_) (sym k[b]/σ≡k/σ[b/σ]) (≅-[] k/ρ≅k/σ (∈-tp b/σ∈j/σ)) k[b]/σ≅k/ρ[b/ρ] = subst (_ ⊢ _ ≅_) k[b]/ρ≡k/ρ[b/ρ] (≅-sym k[b]/ρ≅k[b]/σ) k/ρ[b/σ]≅k/ρ[b/ρ] = ≅-trans k/ρ[b/σ]≅k[b]/σ k[b]/σ≅k/ρ[b/ρ] in (subst (_ ⊢ _ ≃ _ ∈_) (sym k[b]/ρ≡k/ρ[b/ρ]) (<:-antisym (<:-· (≃⇒<: a/ρ≃a/σ∈Πjk/ρ) b/ρ≃b/σ∈j/ρ b/ρ∈j/ρ k/ρ-kd k/ρ[b/ρ]-kd) (<:-⇑ (<:-· (≃⇒<: (≃-sym a/ρ≃a/σ∈Πjk/ρ)) (≃-sym b/ρ≃b/σ∈j/ρ) b/σ∈j/ρ k/ρ-kd k/ρ[b/σ]-kd) (≅⇒<∷ k/ρ[b/σ]≅k/ρ[b/ρ])))) Tp∈-/≃ (∈-s-i a∈b⋯d) ρ≃σ∈Γ = let ρ∈Γ , σ∈Γ , _ = ρ≃σ∈Γ a/ρ∈* = Tp∈-⋯-* (Tp∈-/ a∈b⋯d ρ∈Γ) a/σ∈* = Tp∈-⋯-* (Tp∈-/ a∈b⋯d σ∈Γ) a/ρ≃a/σ∈b/ρ⋯d/ρ = Tp∈-/≃ a∈b⋯d ρ≃σ∈Γ a/ρ<:a/σ∈a/ρ⋯a/σ = <:-⋯-i (≃⇒<: a/ρ≃a/σ∈b/ρ⋯d/ρ) a/σ<:a/ρ∈a/σ⋯a/ρ = <:-⋯-i (≃⇒<: (≃-sym a/ρ≃a/σ∈b/ρ⋯d/ρ)) a/ρ<:a/σ∈* = <:-⇑ a/ρ<:a/σ∈a/ρ⋯a/σ (<∷-⋯ (<:-⊥ a/ρ∈*) (<:-⊤ a/σ∈*)) a/σ<:a/ρ∈* = <:-⇑ a/σ<:a/ρ∈a/σ⋯a/ρ (<∷-⋯ (<:-⊥ a/σ∈*) (<:-⊤ a/ρ∈*)) a/ρ<:a/σ∈a/ρ⋯a/ρ = <:-⇑ a/ρ<:a/σ∈a/ρ⋯a/σ (<∷-⋯ (<:-refl a/ρ∈*) a/σ<:a/ρ∈*) a/σ<:a/ρ∈a/ρ⋯a/ρ = <:-⇑ a/σ<:a/ρ∈a/σ⋯a/ρ (<∷-⋯ a/ρ<:a/σ∈* (<:-refl a/ρ∈*)) in <:-antisym a/ρ<:a/σ∈a/ρ⋯a/ρ a/σ<:a/ρ∈a/ρ⋯a/ρ Tp∈-/≃ (∈-⇑ a∈j j<∷k) ρ≃σ∈Γ = ≃-⇑ (Tp∈-/≃ a∈j ρ≃σ∈Γ) (<∷-/ j<∷k (proj₁ ρ≃σ∈Γ)) -- Helpers (to satisfy the termination checker). kd-/≃-≅ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k ρ σ} → kd j ∷ Γ ⊢ k kd → Δ ⊢/ ρ ≃′ σ ∈ Γ → Δ ⊢ j Kind/ ρ ≅ j Kind/ σ kd-/≃-≅ (kd-⋯ a∈* _) ρ≃σ∈Γ = Tp∈-/≃-≅ a∈* ρ≃σ∈Γ kd-/≃-≅ (kd-Π j-kd _) ρ≃σ∈Γ = kd-/≃-≅ j-kd ρ≃σ∈Γ Tp∈-/≃-≅ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k ρ σ} → kd j ∷ Γ ⊢Tp a ∈ k → Δ ⊢/ ρ ≃′ σ ∈ Γ → Δ ⊢ j Kind/ ρ ≅ j Kind/ σ Tp∈-/≃-≅ (∈-var x (wf-kd k-kd ∷ Γ-ctx) _) ρ≃σ∈Γ = kd-/≃ k-kd ρ≃σ∈Γ Tp∈-/≃-≅ (∈-⊥-f (wf-kd k-kd ∷ Γ-ctx)) ρ≃σ∈Γ = kd-/≃ k-kd ρ≃σ∈Γ Tp∈-/≃-≅ (∈-⊤-f (wf-kd k-kd ∷ Γ-ctx)) ρ≃σ∈Γ = kd-/≃ k-kd ρ≃σ∈Γ Tp∈-/≃-≅ (∈-∀-f k-kd _) ρ≃σ∈Γ = kd-/≃-≅ k-kd ρ≃σ∈Γ Tp∈-/≃-≅ (∈-→-f a∈* _) ρ≃σ∈Γ = Tp∈-/≃-≅ a∈* ρ≃σ∈Γ Tp∈-/≃-≅ (∈-Π-i j-kd _ _) ρ≃σ∈Γ = kd-/≃-≅ j-kd ρ≃σ∈Γ Tp∈-/≃-≅ (∈-Π-e a∈Πjk _ _ _) ρ≃σ∈Γ = Tp∈-/≃-≅ a∈Πjk ρ≃σ∈Γ Tp∈-/≃-≅ (∈-s-i a∈b⋯c) ρ≃σ∈Γ = Tp∈-/≃-≅ a∈b⋯c ρ≃σ∈Γ Tp∈-/≃-≅ (∈-⇑ a∈k _) ρ≃σ∈Γ = Tp∈-/≃-≅ a∈k ρ≃σ∈Γ -- Functionality of kind formation and kinding. -- Equal single-variable substitutions map well-formed kinds to kind -- equations (weak version). kd-[≃′] : ∀ {n} {Γ : Ctx n} {a b j k} → kd j ∷ Γ ⊢ k kd → Γ ⊢Tp a ∈ j → Γ ⊢Tp b ∈ j → Γ ⊢ a ≃ b ∈ j → Γ ⊢ k Kind[ a ] ≅ k Kind[ b ] kd-[≃′] k-kd a∈j b∈j a≃b∈j = kd-/≃ k-kd (∈-sub (∈-tp a∈j) , ∈-sub (∈-tp b∈j) , ∼∈-sub (≃-tp a≃b∈j) , ∼∈-sub (≃-tp (≃-sym (a≃b∈j)))) -- Equal single-variable substitutions map well-kinded types to type -- equations (weak version). Tp∈-[≃′] : ∀ {n} {Γ : Ctx n} {a b c j k} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j → Γ ⊢Tp c ∈ j → Γ ⊢ b ≃ c ∈ j → Γ ⊢ a [ b ] ≃ a [ c ] ∈ k Kind[ b ] Tp∈-[≃′] a∈k b∈j c∈j b≃c∈j = Tp∈-/≃ a∈k (∈-sub (∈-tp b∈j) , ∈-sub (∈-tp c∈j) , ∼∈-sub (≃-tp b≃c∈j) , ∼∈-sub (≃-tp (≃-sym (b≃c∈j))))
{ "alphanum_fraction": 0.4384338532, "avg_line_length": 43.0065666041, "ext": "agda", "hexsha": "1f65250f18f23e40a0c88a003c60070e58fb03c4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_path": "src/FOmegaInt/Kinding/Declarative.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_path": "src/FOmegaInt/Kinding/Declarative.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_path": "src/FOmegaInt/Kinding/Declarative.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 24225, "size": 45845 }
open import Prelude open import Container.List open import Ataca.Utils open import Ataca.Core open import Ataca.Tactics module Ataca.Demo where test₁ : Nat test₁ = {! exact 42 !} test₂ : Nat → Bool → Nat test₂ x y = {! assumption !} test₃ : Nat → Bool → Bool test₃ x y = {! assumption !} test₄ : Nat → Bool → Nat test₄ = {! intros !} test₅ : Bool test₅ = {! introConstructor !} test₆ : Nat test₆ = {! introConstructor !} test₇ : _≡_ {A = Bool} true true test₇ = {! introConstructor !} test₈ : Vec Nat 0 test₈ = {! introConstructor!} test₉ : Vec Bool 3 test₉ = {! introConstructors !} test₁₀ : {A : Set} → A → Vec A 5 test₁₀ = {! mini-auto !} data DecrVec (n : Nat) : Nat → Set where [] : DecrVec n zero cons : ∀ {k} → (m : Nat) → m < n → DecrVec m k → DecrVec n (suc k) test₁₁ : DecrVec 4 3 test₁₁ = {! mini-auto !} test₁₂ : Any {A = Nat} (_≡ 1) (zero ∷ (suc zero) ∷ []) test₁₂ = {! mini-auto !} postulate X Y : Set fun : X → Y test₁₃ : X → Y test₁₃ = {! mini-auto-with hints !} where hints : Hints hints = def (quote fun) [] ∷ [] test₁₄ : {A : Set} → ⊥ → A test₁₄ = {! mini-auto !} test₁₅ : (x : Nat) → Either (x ≡ 0) (Σ Nat λ y → x ≡ suc y) test₁₅ x = {! destruct x !} postulate P=NP : Set proof : P=NP proof = run do try mini-auto' admit'
{ "alphanum_fraction": 0.5956622773, "avg_line_length": 17.2133333333, "ext": "agda", "hexsha": "8913eaf4e9960ee454b3544948d7c290a007115e", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z", "max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ajnavarro/language-dataset", "max_forks_repo_path": "data/github.com/jespercockx/ataca/a9a7c06407a57c351143dc42d357782a541c9071/src/Ataca/Demo.agda", "max_issues_count": 91, "max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z", "max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ajnavarro/language-dataset", "max_issues_repo_path": "data/github.com/jespercockx/ataca/a9a7c06407a57c351143dc42d357782a541c9071/src/Ataca/Demo.agda", "max_line_length": 68, "max_stars_count": 9, "max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ajnavarro/language-dataset", "max_stars_repo_path": "data/github.com/jespercockx/ataca/a9a7c06407a57c351143dc42d357782a541c9071/src/Ataca/Demo.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z", "max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z", "num_tokens": 496, "size": 1291 }
module NaturalTransFacts where open import Level open import Categories.Support.Equivalence open import Categories.Category open import Categories.Functor open import Categories.NaturalTransformation renaming (id to natId; _≡_ to _≡N_; setoid to natSetoid) hiding (_∘ˡ_; _∘ʳ_) open import Categories.Support.EqReasoning _⇒_ = NaturalTransformation _∘ˡ_ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂} → {C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂} → {F G : Functor C D} → (H : Functor D E) → (η : NaturalTransformation F G) → (H ∘ F) ⇒ (H ∘ G) H ∘ˡ η = (natId {F = H}) ∘₀ η _∘ʳ_ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂} → {C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂} → {F G : Functor C D} → (η : NaturalTransformation F G) → (K : Functor E C) → (F ∘ K) ⇒ (G ∘ K) η ∘ʳ K = η ∘₀ (natId {F = K}) .∘₁-resp-≡ˡ : ∀ {o ℓ e} {o′ ℓ′ e′} {D : Category o ℓ e} {E : Category o′ ℓ′ e′} {A B C : Functor D E} {f h : B ⇒ C} {g : A ⇒ B} → f ≡N h → f ∘₁ g ≡N h ∘₁ g ∘₁-resp-≡ˡ {f = f} {h} {g} f≡h = ∘₁-resp-≡ {f = f} {h} {g} {g} f≡h (Setoid.refl natSetoid {g}) .∘₁-resp-≡ʳ : ∀ {o ℓ e} {o′ ℓ′ e′} {D : Category o ℓ e} {E : Category o′ ℓ′ e′} {A B C : Functor D E} {f : B ⇒ C} {g i : A ⇒ B} → g ≡N i → f ∘₁ g ≡N f ∘₁ i ∘₁-resp-≡ʳ {f = f} {g} {i} g≡i = ∘₁-resp-≡ {f = f} {f} {g} {i} (Setoid.refl natSetoid {f}) g≡i .∘ʳ-distr-∘₁ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂} → {C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂} → {F G H : Functor C D} → (β : G ⇒ H) → (α : F ⇒ G) → (K : Functor E C) → (β ∘₁ α) ∘ʳ K ≡N (β ∘ʳ K) ∘₁ (α ∘ʳ K) ∘ʳ-distr-∘₁ {F = F} {G} {H} β α K = begin (β ∘₁ α) ∘ʳ K ↓⟨ Setoid.refl natSetoid {(β ∘₁ α) ∘ʳ K} ⟩ (β ∘₁ α) ∘₀ idK ↑⟨ ∘₀-resp-≡ {f = (β ∘₁ α)} {(β ∘₁ α)} {idK ∘₁ idK} {idK} (Setoid.refl natSetoid {β ∘₁ α}) (identity₁ʳ {X = idK}) ⟩ (β ∘₁ α) ∘₀ (idK ∘₁ idK) ↑⟨ interchange {α = β} {idK} {α} {idK} ⟩ (β ∘₀ idK) ∘₁ (α ∘₀ idK) ↓⟨ ∘₁-resp-≡ {f = β ∘₀ idK} {β ∘ʳ K} {α ∘₀ idK} {α ∘ʳ K} (Setoid.refl natSetoid {β ∘₀ idK}) (Setoid.refl natSetoid {α ∘₀ idK}) ⟩ (β ∘ʳ K) ∘₁ (α ∘ʳ K) ∎ where open SetoidReasoning (natSetoid {F = F ∘ K} {H ∘ K}) idK = natId {F = K} .∘ˡ-distr-∘₁ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂} → {C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂} → {F G H : Functor C D} → (K : Functor D E) → (β : G ⇒ H) → (α : F ⇒ G) → K ∘ˡ (β ∘₁ α) ≡N (K ∘ˡ β) ∘₁ (K ∘ˡ α) ∘ˡ-distr-∘₁ {F = F} {G} {H} K β α = begin K ∘ˡ (β ∘₁ α) ↓⟨ Setoid.refl natSetoid {K ∘ˡ (β ∘₁ α)} ⟩ idK ∘₀ (β ∘₁ α) ↑⟨ ∘₀-resp-≡ {f = idK ∘₁ idK} {idK} {(β ∘₁ α)} {(β ∘₁ α)} (identity₁ʳ {X = idK}) (Setoid.refl natSetoid {β ∘₁ α}) ⟩ (idK ∘₁ idK) ∘₀ (β ∘₁ α) ↑⟨ interchange {α = idK} {β} {idK} {α} ⟩ (idK ∘₀ β) ∘₁ (idK ∘₀ α) ↓⟨ ∘₁-resp-≡ {f = idK ∘₀ β} {K ∘ˡ β} {idK ∘₀ α} {K ∘ˡ α} (Setoid.refl natSetoid {idK ∘₀ β}) (Setoid.refl natSetoid {idK ∘₀ α}) ⟩ (K ∘ˡ β) ∘₁ (K ∘ˡ α) ∎ where open SetoidReasoning (natSetoid {F = K ∘ F} {K ∘ H}) idK = natId {F = K} .identityNatˡ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂} → {C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂} → {F : Functor C D} → (H : Functor D E) → H ∘ˡ natId {F = F} ≡N natId identityNatˡ H = identity₀ʳ {X = natId {F = H}} .identityNatʳ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂} → {C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂} → {F : Functor C D} → (K : Functor E C) → natId {F = F} ∘ʳ K ≡N natId identityNatʳ {F = F} K = identity₀ʳ {X = natId {F = F}}
{ "alphanum_fraction": 0.4645669291, "avg_line_length": 33.6495726496, "ext": "agda", "hexsha": "a6a497732ade656f9a6ec83c7c4d2ca3a9848a7d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_path": "UpTo-Properties/NaturalTransFacts.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_path": "UpTo-Properties/NaturalTransFacts.agda", "max_line_length": 87, "max_stars_count": null, "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_path": "UpTo-Properties/NaturalTransFacts.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1976, "size": 3937 }
module Data.List.SizeOrdering where open import Data.List
{ "alphanum_fraction": 0.8305084746, "avg_line_length": 14.75, "ext": "agda", "hexsha": "d28349db7a0181de596a07dd4749887771004685", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Data/List/SizeOrdering.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Data/List/SizeOrdering.agda", "max_line_length": 35, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Data/List/SizeOrdering.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 13, "size": 59 }
{-# OPTIONS --without-K #-} open import lib.Basics hiding (_⊔_) open import lib.types.Sigma open import lib.NType2 open import Preliminaries open import Truncation_Level_Criteria open import Anonymous_Existence_CollSplit open wtrunc open with-weak-trunc module Weakly_Constant_Functions where -- Definition 5.1.1 factorizes-through : ∀ {i j} {X : Type i} {Y : Type j} → Type i → (X → Y) → Type (i ⊔ j) factorizes-through {X = X} {Y = Y} Z f = Σ (X → Z) λ f₁ → Σ (Z → Y) λ f₂ → (x : X) → f₂ (f₁ x) == f x -- Definition 5.1.1 addendum: 'factorizes through the truncation' -- In the theory of the thesis, universes are cumulative. -- Here, we ask all the types to be in the same universe. factorizes : ∀ {i} {X : Type i} {Y : Type i} → (X → Y) → Type i factorizes {X = X} = factorizes-through (∣∣ X ∣∣) -- Principle 5.2.1 factorize-helper : ∀ {i} {X : Type i} {Y : Type i} → (f : X → Y) → (P : Type i) → (X → is-prop P) → (factorizes-through P f) → factorizes f factorize-helper {X = X} {Y = Y} f P xpp (f₁ , f₂ , q) = f₁' , f₂' , q' where f₁' : X → ∣∣ X ∣∣ f₁' = ∣_∣ f₂' : ∣∣ X ∣∣ → Y f₂' z = f₂ (tr-rec {X = X} (tr-rec is-prop-is-prop xpp z) f₁ z) q' : (x : X) → f₂' (f₁' x) == f x q' x = f₂' (f₁' x) =⟨ idp ⟩ f₂' ∣ x ∣ =⟨ idp ⟩ f₂ (tr-rec _ f₁ ∣ x ∣ ) =⟨ ap f₂ (trunc-β _ f₁ x) ⟩ f₂ (f₁ x) =⟨ q x ⟩ f x ∎ -- Proposition 5.2.2 module st522 {i : ULevel} {X : Type i} {Y : Type i} (f : X → Y) (c : const f) where One = ¬ X Two = X Three = ∣∣ X ∣∣ → X Four = coll X Five = Y → X One→Three : One → Three One→Three nx z = Empty-elim {P = λ _ → X} (tr-rec Empty-elim nx z) Two→Three : Two → Three Two→Three x = λ _ → x Five→Four : Five → Four Five→Four g = g ∘ f , (λ x₁ x₂ → ap g (c x₁ x₂)) Three↔Four : Three ↔ Four Three↔Four = snd coll↔splitSup , fst coll↔splitSup Three→factorizes : Three → factorizes f Three→factorizes s = ∣_∣ , f ∘ s , (λ x → c _ _) -- Proposition 5.2.3 preparation -- as a small preparation, let us define a function that applies the truncation tr-recursor twice. -- Because of how we have defined the operator ∣∣_∣∣, we need everything to happen in the same universe double-tr-rec : ∀ {i} {X₁ X₂ P : Type i} → (is-prop P) → (X₁ → X₂ → P) → ∣∣ X₁ ∣∣ → ∣∣ X₂ ∣∣ → P double-tr-rec {i} {X₁} {X₂} {P} pp f z₁ z₂ = next-step z₁ z₂ where step : X₁ → ∣∣ X₂ ∣∣ → P step x₁ = tr-rec {X = X₂} {P = P} pp (f x₁) step-switch : ∣∣ X₂ ∣∣ → X₁ → P step-switch z₂ x₁ = step x₁ z₂ next-step : ∣∣ X₁ ∣∣ → ∣∣ X₂ ∣∣ → P next-step z₁ z₂ = tr-rec pp (step-switch z₂) z₁ -- tr-rec pp (step-switch z₂) -- now, the actual Proposition 5.2.3 factorize-codomain-set : ∀ {i} {X : Type i} {Y : Type i} → (f : X → Y) → const f → is-set Y → factorizes f factorize-codomain-set {i} {X} {Y} f c h = factorize-helper f P (λ _ → pp) fact-through-p where P : Type i P = Σ Y λ y → ∣∣ (Σ X λ x → f x == y) ∣∣ pp : is-prop P pp = all-paths-is-prop all-paths where all-paths : has-all-paths P all-paths (y₁ , t₁) (y₂ , t₂) = pair= ys ts where ys = double-tr-rec {P = y₁ == y₂} (h _ _) (λ {(x₁ , p₁) (x₂ , p₂) → ! p₁ ∙ c _ _ ∙ p₂}) t₁ t₂ ts = from-transp _ ys (prop-has-all-paths tr-is-prop _ _) fact-through-p : factorizes-through P f fact-through-p = f₁ , f₂ , q where f₁ : X → P f₁ x = f x , ∣ x , idp ∣ f₂ : P → Y f₂ = fst q : (x : X) → f₂ (f₁ x) == f x q x = idp -- Theorem 5.2.6 -- We need function extensionality and thus import -- the following: open import lib.types.Pi -- A general auxiliary function which switches the second -- and third component of a Σ-type with four components -- (provided that it is possible). -- We formulate this explicitly as we will need it several times: switch23 : ∀ {i} {X : Type i} → {Y Z : X → Type i} → {W : (x : X) → (Y x) → (Z x) → Type i} → (Σ X λ x → Σ (Y x) λ y → Σ (Z x) λ z → (W x y z)) ≃ (Σ X λ x → Σ (Z x) λ z → Σ (Y x) λ y → (W x y z)) switch23 = equiv (λ {(y , s , t , coh) → (y , t , s , coh)}) (λ {(y , t , s , coh) → (y , s , t , coh)}) (λ _ → idp) (λ _ → idp) -- Theorem 5.2.6, with the 'equivalence reasoning' tactic: module thm526 {i : ULevel} {Q R Y : Type i} (qq : is-prop Q) (rr : is-prop R) (f : Coprod Q R → Y) (c : const f) where P : Type i P = Σ Y λ y → Σ ((q : Q) → y == f(inl q)) λ s → Σ ((r : R) → y == f(inr r)) λ t → (q : Q) → (r : R) → ! (s q) ∙ (t r) == c (inl q) (inr r) -- This is going to be tedious: if q₀ : Q is given, we can show that P is equivalent to the Unit type. given-q-reduce-P : Q → P ≃ Unit given-q-reduce-P q₀ = P ≃⟨ switch23 ⟩ (Σ Y λ y → Σ ((r : R) → y == f(inr r)) λ t → Σ ((q : Q) → y == f(inl q)) λ s → (q : Q) → (r : R) → ! (s q) ∙ (t r) == c (inl q) (inr r)) ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ t → choice ⁻¹)) ⟩ (Σ Y λ y → Σ ((r : R) → y == f(inr r)) λ t → (q : Q) → Σ (y == f(inl q)) λ s-reduced → (r : R) → ! s-reduced ∙ (t r) == c (inl q) (inr r)) ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ t → Π₁-contr (q₀ , prop-has-all-paths qq q₀))) ⟩ (Σ Y λ y → Σ ((r : R) → y == f(inr r)) λ t → Σ (y == f(inl q₀)) λ s-reduced → (r : R) → ! s-reduced ∙ (t r) == c (inl q₀) (inr r)) ≃⟨ switch23 ⟩ (Σ Y λ y → Σ (y == f(inl q₀)) λ s-reduced → Σ ((r : R) → y == f(inr r)) λ t → (r : R) → ! s-reduced ∙ (t r) == c (inl q₀) (inr r)) ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ t → choice ⁻¹)) ⟩ (Σ Y λ y → Σ (y == f(inl q₀)) λ s-reduced → (r : R) → Σ (y == f(inr r)) λ t-reduced → ! s-reduced ∙ t-reduced == c (inl q₀) (inr r)) ≃⟨ Σ-assoc ⁻¹ ⟩ (Σ (Σ Y λ y → (y == f(inl q₀))) λ {(y , s-reduced) → (r : R) → Σ (y == f(inr r)) λ t-reduced → ! s-reduced ∙ t-reduced == c (inl q₀) (inr r)}) ≃⟨ Σ₁-contr (pathto-is-contr _) ⟩ ((r : R) → Σ (f(inl q₀) == f(inr r)) λ t-reduced → idp ∙ t-reduced == c (inl q₀) (inr r)) ≃⟨ Π₂-contr (λ r → pathto-is-contr _) ⟩ Unit ≃∎ given-r-reduce-P : R → P ≃ Unit given-r-reduce-P r₀ = P ≃⟨ equiv-Σ-snd (λ _ → equiv-Σ-snd (λ _ → equiv-Σ-snd (λ _ → switch-args))) ⟩ (Σ Y λ y → Σ ((q : Q) → y == f(inl q)) λ s → Σ ((r : R) → y == f(inr r)) λ t → (r : R) → (q : Q) → ! (s q) ∙ (t r) == c (inl q) (inr r)) ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ s → choice ⁻¹)) ⟩ (Σ Y λ y → Σ ((q : Q) → y == f(inl q)) λ s → (r : R) → Σ (y == f(inr r)) λ t-reduced → (q : Q) → ! (s q) ∙ t-reduced == c (inl q) (inr r)) ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ t → Π₁-contr (r₀ , prop-has-all-paths rr r₀))) ⟩ (Σ Y λ y → Σ ((q : Q) → y == f(inl q)) λ s → Σ (y == f(inr r₀)) λ t-reduced → (q : Q) → ! (s q) ∙ t-reduced == c (inl q) (inr r₀)) ≃⟨ switch23 ⟩ (Σ Y λ y → Σ (y == f(inr r₀)) λ t-reduced → Σ ((q : Q) → y == f(inl q)) λ s → (q : Q) → ! (s q) ∙ t-reduced == c (inl q) (inr r₀)) ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ s → choice ⁻¹)) ⟩ (Σ Y λ y → Σ (y == f(inr r₀)) λ t-reduced → (q : Q) → Σ (y == f(inl q)) λ s-reduced → ! s-reduced ∙ t-reduced == c (inl q) (inr r₀)) ≃⟨ Σ-assoc ⁻¹ ⟩ (Σ (Σ Y λ y → (y == f(inr r₀))) λ {(y , t-reduced) → (q : Q) → Σ (y == f(inl q)) λ s-reduced → ! s-reduced ∙ t-reduced == c (inl q) (inr r₀)}) ≃⟨ Σ₁-contr (pathto-is-contr _) ⟩ ((q : Q) → Σ (f(inr r₀) == f(inl q)) λ s-reduced → ! s-reduced ∙ idp == c (inl q) (inr r₀)) ≃⟨ equiv-Π-r (λ q → equiv-Σ-snd (λ proof → ! proof ∙ idp == c (inl q) (inr r₀) ≃⟨ delete-idp _ _ ⟩ ! proof == c (inl q) (inr r₀) ≃⟨ reverse-paths _ _ ⟩ proof == ! (c (inl q) (inr r₀)) ≃∎ )) ⟩ ((q : Q) → Σ (f(inr r₀) == f(inl q)) λ s-reduced → s-reduced == ! (c (inl q) (inr r₀))) ≃⟨ Π₂-contr (λ q → pathto-is-contr _) ⟩ Unit ≃∎ given-q+r-reduce-P : Coprod Q R → P ≃ Unit given-q+r-reduce-P (inl q) = given-q-reduce-P q given-q+r-reduce-P (inr r) = given-r-reduce-P r Q+R→P : Coprod Q R → P Q+R→P x = <– (given-q+r-reduce-P x) _ P→Y : P → Y P→Y = fst open import lib.types.Unit -- Finally : the statement of Theorem 5.2.6 factorize-f : factorizes f factorize-f = factorize-helper f P (λ x → equiv-preserves-level ((given-q+r-reduce-P x) ⁻¹) Unit-is-prop) (Q+R→P , P→Y , proof) where proof : (x : Coprod Q R) → P→Y (Q+R→P x) == f x proof (inl q) = idp proof (inr r) = idp -- and Theorem 5.2.6 again (outside of a specialized module) Theorem526 : ∀ {i} {Q R Y : Type i} → (is-prop Q) → (is-prop R) → (f : Coprod Q R → Y) → (const f) → factorizes f Theorem526 = thm526.factorize-f
{ "alphanum_fraction": 0.4604803724, "avg_line_length": 34.4927007299, "ext": "agda", "hexsha": "8805dc1b92d52a12c74de7ea026896de6fb4fa4b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "nicolai/thesis/Weakly_Constant_Functions.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "nicolai/thesis/Weakly_Constant_Functions.agda", "max_line_length": 139, "max_stars_count": 1, "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_path": "nicolai/thesis/Weakly_Constant_Functions.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z", "num_tokens": 3899, "size": 9451 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Maybe.Base where open import Cubical.Core.Everything private variable ℓ : Level A B : Type ℓ data Maybe (A : Type ℓ) : Type ℓ where nothing : Maybe A just : A → Maybe A caseMaybe : (n j : B) → Maybe A → B caseMaybe n _ nothing = n caseMaybe _ j (just _) = j map-Maybe : (A → B) → Maybe A → Maybe B map-Maybe _ nothing = nothing map-Maybe f (just x) = just (f x) rec : B → (A → B) → Maybe A → B rec n j nothing = n rec n j (just a) = j a
{ "alphanum_fraction": 0.6153846154, "avg_line_length": 20.5, "ext": "agda", "hexsha": "47d6d6aab39bbd7ca8b659b7283afc4b0db3db0c", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Data/Maybe/Base.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Data/Maybe/Base.agda", "max_line_length": 50, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Data/Maybe/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 186, "size": 533 }
module nodcap.Norm where open import Category.Monad open import Data.Nat as ℕ using (ℕ; suc; zero) open import Data.Pos as ℕ⁺ using (ℕ⁺; suc; _+_) open import Data.List as L using (List; []; _∷_; _++_) open import Data.List.Any as LA using (Any; here; there) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Function using (_$_) open import Relation.Binary.PropositionalEquality as P using (_≡_) open import Data.Environment open import nodcap.Base open import nodcap.Typing as FF using (⊢_) open import nodcap.NF.Typing as NF using (⊢ⁿᶠ_) import nodcap.NF.Axiom as NFA import nodcap.NF.Cut as NFD import nodcap.NF.CutND as NFND private open module LM {ℓ} = RawMonadPlus (L.monadPlus {ℓ}) nf : {Γ : Environment} → ⊢ Γ → ⊢ⁿᶠ Γ nf FF.ax = NFA.ax nf (FF.cut x y) = NFD.cut (nf x) (nf y) nf (FF.send x y) = NF.send (nf x) (nf y) nf (FF.recv x) = NF.recv (nf x) nf (FF.sel₁ x) = NF.sel₁ (nf x) nf (FF.sel₂ x) = NF.sel₂ (nf x) nf (FF.case x y) = NF.case (nf x) (nf y) nf FF.halt = NF.halt nf (FF.wait x) = NF.wait (nf x) nf FF.loop = NF.loop nf (FF.mk?₁ x) = NF.mk?₁ (nf x) nf (FF.mk!₁ x) = NF.mk!₁ (nf x) nf (FF.cont x) = NF.cont (nf x) nf (FF.pool x y) = NF.pool (nf x) (nf y) nf (FF.exch b x) = NF.exch b (nf x) nfND : {Γ : Environment} → ⊢ Γ → List (⊢ⁿᶠ Γ) nfND FF.ax = return NFA.ax nfND (FF.cut x y) = nfND x >>= λ x → nfND y >>= λ y → NFND.cutND x y nfND (FF.send x y) = nfND x >>= λ x → nfND y >>= λ y → return $ NF.send x y nfND (FF.recv x) = nfND x >>= λ x → return $ NF.recv x nfND (FF.sel₁ x) = nfND x >>= λ x → return $ NF.sel₁ x nfND (FF.sel₂ x) = nfND x >>= λ x → return $ NF.sel₂ x nfND (FF.case x y) = nfND x >>= λ x → nfND y >>= λ y → return $ NF.case x y nfND FF.halt = return NF.halt nfND (FF.wait x) = nfND x >>= λ x → return (NF.wait x) nfND FF.loop = return NF.loop nfND (FF.mk?₁ x) = nfND x >>= λ x → return $ NF.mk?₁ x nfND (FF.mk!₁ x) = nfND x >>= λ x → return $ NF.mk!₁ x nfND (FF.cont x) = nfND x >>= λ x → return $ NF.cont x nfND (FF.pool x y) = nfND x >>= λ x → nfND y >>= λ y → return $ NF.pool x y nfND (FF.exch b x) = nfND x >>= λ x → return $ NF.exch b x -- -} -- -} -- -} -- -} -- -}
{ "alphanum_fraction": 0.5902683038, "avg_line_length": 35.4677419355, "ext": "agda", "hexsha": "f9bee4df861d16fa29904296dfa8e7ce208c83d0", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z", "max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "pepijnkokke/nodcap", "max_forks_repo_path": "src/cpnd1/nodcap/Norm.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "pepijnkokke/nodcap", "max_issues_repo_path": "src/cpnd1/nodcap/Norm.agda", "max_line_length": 75, "max_stars_count": 4, "max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "wenkokke/nodcap", "max_stars_repo_path": "src/cpnd1/nodcap/Norm.agda", "max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z", "max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z", "num_tokens": 868, "size": 2199 }
-- 2018-01-05, Jesper: having a `rewrite` after a `with` caused problems -- because the patterns stripped by with-desugaring were not propagated -- to the generated rewrite-clause. This should now be fixed. open import Agda.Builtin.Equality postulate lem : Set ≡ Set simple-test : {A : Set₁} → A ≡ Set → Set₁ simple-test {A = A} refl with Set simple-test {A = A} refl | _ rewrite lem = A record ⊤ : Set where constructor tt data G : Set → Set₁ where d : (A : Set) → G A → G A postulate exists : (A : Set) → G A unique : (A : Set) (x : G A) → exists A ≡ x test : (A : Set) → G A → ⊤ test _ (d A x) with unique A x test _ (d A _) | refl rewrite refl {x = tt} = tt
{ "alphanum_fraction": 0.6371681416, "avg_line_length": 25.1111111111, "ext": "agda", "hexsha": "f0f03b8d17c62cf0128660ffe31970cee6869b58", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/RewriteAfterWithStripping.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/RewriteAfterWithStripping.agda", "max_line_length": 72, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/RewriteAfterWithStripping.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 230, "size": 678 }
module Curry5 where open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; subst) open import Function using (id) lemma1 : {X Y : Set} → (X ≡ (X → Y)) → X lemma1 p rewrite p = (λ x → let f = subst id p x in f x) curry : {X Y : Set} → (X ≡ (X → Y)) → Y curry p = (let f = subst id p (lemma1 p) in f (lemma1 p))
{ "alphanum_fraction": 0.5924855491, "avg_line_length": 24.7142857143, "ext": "agda", "hexsha": "ce59376517b8f34e5f11f7b08b0d8dd7569675f4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "righ1113/Agda", "max_forks_repo_path": "Curry5.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "righ1113/Agda", "max_issues_repo_path": "Curry5.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "righ1113/Agda", "max_stars_repo_path": "Curry5.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 119, "size": 346 }
{-# OPTIONS --cubical-compatible --rewriting #-} open import Agda.Primitive using (Level; _⊔_; Setω; lzero; lsuc) module Issue4020b where data _≡_ {ℓ : Level} {A : Set ℓ} (a : A) : A → Set ℓ where refl : a ≡ a {-# BUILTIN REWRITE _≡_ #-} ap : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {a₁ a₂} → a₁ ≡ a₂ → f a₁ ≡ f a₂ ap f refl = refl ap-const-Pi : ∀ {a b} {A : Set a} {B : A → Set b} {a₁ a₂ : A} (p : a₁ ≡ a₂) → ap (\ _ → (x : A) → B x) p ≡ refl ap-const-Pi refl = refl {-# REWRITE ap-const-Pi #-} {- /home/jason/bug2.agda:18,1-28 ap-const-Pi is not a legal rewrite rule, since the following variables are not bound by the left hand side: b when checking the pragma REWRITE ap-const-Pi -}
{ "alphanum_fraction": 0.594017094, "avg_line_length": 31.9090909091, "ext": "agda", "hexsha": "a59382f4c4e7579648cdda1908edb04266bca044", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Succeed/Issue4020b.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Succeed/Issue4020b.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Succeed/Issue4020b.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 285, "size": 702 }