Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --rewriting #-}
open import Common.Equality
{-# BUILTIN REWRITE _≡_ #-}
postulate
A : Set
f g : A → A
f≡g : ∀ a → f a ≡ g a
{-# REWRITE f≡g #-}
-- Adding the same rule again would make Agda loop
postulate
f≡g' : ∀ a → f a ≡ g a
{-# REWRITE f≡g' #-}
goal : ∀ {a} → f a ≡ g a
goal = refl
| {
"alphanum_fraction": 0.5431309904,
"avg_line_length": 14.9047619048,
"ext": "agda",
"hexsha": "4cc2417efafb90161b1bcba26ca7847f29a4c566",
"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/RewriteLhsReduction.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/RewriteLhsReduction.agda",
"max_line_length": 50,
"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/RewriteLhsReduction.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": 122,
"size": 313
} |
module Oscar.Class where
open import Oscar.Data.Equality
open import Oscar.Function
open import Oscar.Relation
open import Oscar.Level
open import Oscar.Function
open import Oscar.Relation
-- instance EquivalenceProp : ∀ {a} {A : Set a} → Equivalence (_≡_ {a} {A})
-- EquivalenceProp = {!!}
-- instance EquivalenceProp1 : ∀ {a} {A : Set a} {b} {B : A → Set b} → Equivalence (_≡̇_ {a} {A} {b} {B})
-- Equivalence.reflexivity EquivalenceProp1 x x₁ = refl
-- import Oscar.Data.Term.internal.SubstituteAndSubstitution FunctionName as ⋆
-- instance SemigroupFinTerm : Semigroup _⊸_ _≡̇_
-- Semigroup.equivalence SemigroupFinTerm = it
-- Semigroup._◇_ SemigroupFinTerm = ⋆._◇_ -- (Semifunctor._◃ SemifunctorFinTerm g) ∘ f --
-- Semigroup.◇-associativity SemigroupFinTerm = {!!}
-- instance Semigroup⋆ : ∀ {a} {A : Set a} {x} {X : A → Set x} → Semigroup (_⟨ X ⟩→_) _≡̇_
-- Semigroup.equivalence Semigroup⋆ = it
-- Semigroup._◇_ Semigroup⋆ g f = g ∘ f
-- Semigroup.◇-associativity Semigroup⋆ = {!!}
-- instance SemifunctorFinTerm : Semifunctor _⊸_ _≡̇_ (_⟨ Term ⟩→_) _≡̇_ id
-- Semifunctor.domain SemifunctorFinTerm = it
-- Semifunctor.codomain SemifunctorFinTerm = it
-- SemifunctorFinTerm Semifunctor.◃ = ⋆._◃_
-- Semifunctor.◃-extensionality SemifunctorFinTerm = ⋆.◃-extensionality
-- Semifunctor.◃-associativity SemifunctorFinTerm = ⋆.◃-associativity
-- -- sufficient for all my substitutions (Term, Formula, etc.)
-- _◂_ : ∀ {m n a} {A : Nat → Set a} ⦃ _ : Semifunctor _⊸_ _≡̇_ (_⟨ A ⟩→_) _≡̇_ id ⦄ → m ⊸ n → m ⟨ A ⟩→ n
-- _◂_ ⦃ semifunctor ⦄ f x = Semifunctor._◃ semifunctor f x
-- -- even more general, handling all pointwise (semi)functors
-- _◂'_ : ∀ {a} {A : Set a} {m n : A} {b} {B : A → Set b} {c} {C : A → Set c} {d} {D : A → Set d}
-- ⦃ _ : Semifunctor (λ m n → B m → C n) _≡̇_ _⟨ D ⟩→_ _≡̇_ id ⦄ → (B m → C n) → m ⟨ D ⟩→ n
-- _◂'_ ⦃ semifunctor ⦄ f x = Semifunctor._◃ semifunctor f x
-- record UsableSemifunctor {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) {d} (D : A → Set d) : Set (a ⊔ b ⊔ c ⊔ d) where
-- field
-- ⦃ semifunctor ⦄ : Semifunctor (λ m n → B m → C n) _≡̇_ _⟨ D ⟩→_ _≡̇_ id
-- _◄_ : ∀ {m n} → (B m → C n) → m ⟨ D ⟩→ n
-- _◄_ f x = Semifunctor._◃ semifunctor f x
-- open UsableSemifunctor ⦃ … ⦄
-- instance UsableSemifunctor⋆ : ∀ {a} {A : Set a} {b} {B : A → Set b} {c} {C : A → Set c} {d} {D : A → Set d}
-- -- { _≋₁_ : ∀ {m n} → (B m → C n) → (B m → C n) → Set (b ⊔ c) }
-- -- ⦃ _ : ∀ {m n} → Equivalence (_≋₁_ {m} {n}) ⦄
-- -- ⦃ _ : Semifunctor (λ m n → B m → C n) _≋₁_ _⟨ D ⟩→_ _≡̇_ id ⦄ → UsableSemifunctor B C D
-- ⦃ _ : Semifunctor (λ m n → B m → C n) _≡̇_ _⟨ D ⟩→_ _≡̇_ id ⦄
-- → UsableSemifunctor B C D
-- UsableSemifunctor.semifunctor (UsableSemifunctor⋆ ⦃ semi ⦄) = semi
-- {-
-- instance UsableSemifunctorFinTermTerm : UsableSemifunctor Fin Term Term
-- UsableSemifunctor.semifunctor UsableSemifunctorFinTermTerm = it
-- -}
-- -- obviously won't work unless we supply _≋₁_
-- _◂''_ : ∀ {a} {A : Set a} {m n : A} {b} {B : A → Set b} {c} {C : A → Set c} {d} {D : A → Set d}
-- ( _≋₁_ : ∀ {m n} → (B m → C n) → (B m → C n) → Set (b ⊔ c) )
-- ⦃ _ : ∀ {m n} → Equivalence (_≋₁_ {m} {n}) ⦄
-- ⦃ _ : Semifunctor (λ m n → B m → C n) _≋₁_ _⟨ D ⟩→_ _≡̇_ id ⦄ → (B m → C n) → m ⟨ D ⟩→ n
-- _◂''_ _ ⦃ _ ⦄ ⦃ semifunctor ⦄ f x = Semifunctor._◃ semifunctor f x
-- foo : ∀ {m n} → m ⊸ n → Term m → Term n
-- foo {m} {n} f x = f ◄ x
-- --foo f x = f ◂ x
-- --foo f x = _◂''_ _≡̇_ f x
-- -- record Ṁonoid {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where
-- -- field
-- -- ε̇ : ∀ {m} → B m → C m
-- -- _◇̇_ : ∀ {l m n} → (g : B m → C n) (f : B l → C m) → B l → C n
-- -- ◇̇-left-identity : ∀ {m n} → (f : B m → C n) → ε̇ ◇̇ f ≡̇ f
-- -- ◇̇-right-identity : ∀ {m n} → (f : B m → C n) → f ◇̇ ε̇ ≡̇ f
-- -- ◇̇-associativity : ∀ {k l m n} (f : B k → C l) (g : B l → C m) (h : B m → C n) → h ◇̇ (g ◇̇ f) ≡̇ (h ◇̇ g) ◇̇ f
-- -- record Monoid {a} {A : Set a} {b} (_↠_ : A → A → Set b) : Set (a ⊔ b) where
-- -- field
-- -- ε : ∀ {m} → m ↠ m
-- -- _◇_ : ∀ {l m n} → m ↠ n → l ↠ m → l ↠ n
-- -- ◇-left-identity : ∀ {m n} → (f : m ↠ n) → ε ◇ f ≡ f
-- -- ◇-right-identity : ∀ {m n} → (f : m ↠ n) → f ◇ ε ≡ f
-- -- ◇-associativity : ∀ {k l m n} (f : k ↠ l) (g : l ↠ m) (h : m ↠ n) → h ◇ (g ◇ f) ≡ (h ◇ g) ◇ f
-- -- record Substitution {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where
-- -- field
-- -- ε : ∀ {m} → B m → C m
-- -- _◇_ : ∀ {l m n} → (g : B m → C n) (f : B l → C m) → B l → C n
-- -- ◇-left-identity : ∀ {m n} → (f : B m → C n) → ε ◇ f ≡̇ f
-- -- ◇-right-identity : ∀ {m n} → (f : B m → C n) → f ◇ ε ≡̇ f
-- -- ◇-associativity : ∀ {k l m n} (f : B k → C l) (g : B l → C m) (h : B m → C n) → h ◇ (g ◇ f) ≡̇ (h ◇ g) ◇ f
-- -- record Substitution {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where
-- -- field
-- -- ε : ∀ {m} → B m → C m
-- -- _◇_ : ∀ {l m n} → (g : B m → C n) (f : B l → C m) → B l → C n
-- -- ◇-left-identity : ∀ {m n} → (f : B m → C n) → ε ◇ f ≡̇ f
-- -- ◇-right-identity : ∀ {m n} → (f : B m → C n) → f ◇ ε ≡̇ f
-- -- ◇-associativity : ∀ {k l m n} (f : B k → C l) (g : B l → C m) (h : B m → C n) → h ◇ (g ◇ f) ≡̇ (h ◇ g) ◇ f
-- -- record Substitution {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where
-- -- field
-- -- ε : ∀ {m} → B m → C m
-- -- _◇_ : ∀ {l m n} → (g : B m → C n) (f : B l → C m) → B l → C n
-- -- ◇-left-identity : ∀ {m n} → (f : B m → C n) → ε ◇ f ≡̇ f
-- -- ◇-right-identity : ∀ {m n} → (f : B m → C n) → f ◇ ε ≡̇ f
-- -- ◇-associativity : ∀ {k l m n} (f : B k → C l) (g : B l → C m) (h : B m → C n) → h ◇ (g ◇ f) ≡̇ (h ◇ g) ◇ f
| {
"alphanum_fraction": 0.4647484435,
"avg_line_length": 49.525,
"ext": "agda",
"hexsha": "45cb6081a5cccb3b22e57daa01eb3b14474a07ed",
"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": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Class.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Class.agda",
"max_line_length": 131,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Class.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2833,
"size": 5943
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRingSolver.HornerEval where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Int hiding (_+_ ; _·_ ; -_)
open import Cubical.Data.Vec
open import Cubical.Data.Bool
open import Cubical.Relation.Nullary.Base using (¬_; yes; no)
open import Cubical.Algebra.CommRingSolver.Utility
open import Cubical.Algebra.CommRingSolver.RawAlgebra
open import Cubical.Algebra.CommRingSolver.IntAsRawRing
open import Cubical.Algebra.CommRingSolver.HornerForms
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
private
variable
ℓ ℓ' : Level
eval : {A : RawAlgebra ℤAsRawRing ℓ'}
{n : ℕ} (P : IteratedHornerForms A n)
→ Vec ⟨ A ⟩ n → ⟨ A ⟩
eval {A = A} (const r) [] = RawAlgebra.scalar A r
eval {A = A} 0H (_ ∷ _) = RawAlgebra.0r A
eval {A = A} (P ·X+ Q) (x ∷ xs) =
let open RawAlgebra A
P' = (eval P (x ∷ xs))
Q' = eval Q xs
in if (isZero A P)
then Q'
else P' · x + Q'
module _ (R : CommRing ℓ) where
private
νR = CommRing→RawℤAlgebra R
open CommRingStr (snd R)
open RingTheory (CommRing→Ring R)
open IteratedHornerOperations νR
someCalculation : {x : fst R} → _ ≡ _
someCalculation {x = x} =
0r ≡⟨ sym (+IdR 0r) ⟩
0r + 0r ≡[ i ]⟨ 0LeftAnnihilates x (~ i) + 0r ⟩
0r · x + 0r ∎
evalIsZero : {n : ℕ} (P : IteratedHornerForms νR n)
→ (l : Vec (fst R) n)
→ isZero νR P ≡ true
→ eval P l ≡ 0r
evalIsZero (const (pos ℕ.zero)) [] isZeroP = refl
evalIsZero (const (pos (ℕ.suc n))) [] isZeroP = byBoolAbsurdity isZeroP
evalIsZero (const (negsuc _)) [] isZeroP = byBoolAbsurdity isZeroP
evalIsZero 0H (x ∷ xs) _ = refl
evalIsZero {n = ℕ.suc n} (P ·X+ Q) (x ∷ xs) isZeroPandQ with isZero νR P
... | true = eval Q xs ≡⟨ evalIsZero Q xs isZeroQ ⟩
0r ∎
where isZeroQ = snd (extractFromAnd _ _ isZeroPandQ)
... | false = byBoolAbsurdity isZeroP
where isZeroP = fst (extractFromAnd _ _ isZeroPandQ)
computeEvalSummandIsZero :
{n : ℕ}
(P : IteratedHornerForms νR (ℕ.suc n))
(Q : IteratedHornerForms νR n)
→ (xs : Vec (fst R) n)
→ (x : (fst R))
→ isZero νR P ≡ true
→ eval (P ·X+ Q) (x ∷ xs) ≡ eval Q xs
computeEvalSummandIsZero P Q xs x isZeroP with isZero νR P
... | true = refl
... | false = byBoolAbsurdity isZeroP
computeEvalNotZero :
{n : ℕ}
(P : IteratedHornerForms νR (ℕ.suc n))
(Q : IteratedHornerForms νR n)
→ (xs : Vec (fst R) n)
→ (x : (fst R))
→ ¬ (isZero νR P ≡ true)
→ eval (P ·X+ Q) (x ∷ xs) ≡ (eval P (x ∷ xs)) · x + eval Q xs
computeEvalNotZero P Q xs x notZeroP with isZero νR P
... | true = byBoolAbsurdity (sym (¬true→false true notZeroP))
... | false = refl
combineCasesEval :
{n : ℕ} (P : IteratedHornerForms νR (ℕ.suc n)) (Q : IteratedHornerForms νR n)
(x : (fst R)) (xs : Vec (fst R) n)
→ eval (P ·X+ Q) (x ∷ xs)
≡ (eval P (x ∷ xs)) · x + eval Q xs
combineCasesEval P Q x xs with isZero νR P ≟ true
... | yes p =
eval (P ·X+ Q) (x ∷ xs) ≡⟨ computeEvalSummandIsZero P Q xs x p ⟩
eval Q xs ≡⟨ sym (+IdL _) ⟩
0r + eval Q xs ≡[ i ]⟨ 0LeftAnnihilates x (~ i) + eval Q xs ⟩
0r · x + eval Q xs ≡[ i ]⟨ (evalIsZero P (x ∷ xs) p (~ i)) · x + eval Q xs ⟩
(eval P (x ∷ xs)) · x + eval Q xs ∎
... | no p = computeEvalNotZero P Q xs x p
compute+ₕEvalBothZero :
(n : ℕ) (P Q : IteratedHornerForms νR (ℕ.suc n))
(r s : IteratedHornerForms νR n)
(x : (fst R)) (xs : Vec (fst R) n)
→ (isZero νR (P +ₕ Q) and isZero νR (r +ₕ s)) ≡ true
→ eval ((P ·X+ r) +ₕ (Q ·X+ s)) (x ∷ xs) ≡ eval ((P +ₕ Q) ·X+ (r +ₕ s)) (x ∷ xs)
compute+ₕEvalBothZero n P Q r s x xs bothZero with isZero νR (P +ₕ Q) and isZero νR (r +ₕ s) | bothZero
... | true | p =
eval {A = νR} 0H (x ∷ xs) ≡⟨ refl ⟩
0r ≡⟨ someCalculation ⟩
0r · x + 0r ≡⟨ step1 ⟩
(eval (P +ₕ Q) (x ∷ xs)) · x + eval (r +ₕ s) xs ≡⟨ step2 ⟩
eval ((P +ₕ Q) ·X+ (r +ₕ s)) (x ∷ xs) ∎
where step1 : 0r · x + 0r ≡ (eval (P +ₕ Q) (x ∷ xs)) · x + eval (r +ₕ s) xs
step1 i = (evalIsZero (P +ₕ Q) (x ∷ xs) (fst (extractFromAnd _ _ (bothZero))) (~ i)) · x
+ (evalIsZero (r +ₕ s) xs (snd (extractFromAnd _ _ (bothZero))) (~ i))
step2 = sym (combineCasesEval (P +ₕ Q) (r +ₕ s) x xs)
... | false | p = byBoolAbsurdity p
compute+ₕEvalNotBothZero :
(n : ℕ) (P Q : IteratedHornerForms νR (ℕ.suc n))
(r s : IteratedHornerForms νR n)
(x : (fst R)) (xs : Vec (fst R) n)
→ (isZero νR (P +ₕ Q) and isZero νR (r +ₕ s)) ≡ false
→ eval ((P ·X+ r) +ₕ (Q ·X+ s)) (x ∷ xs) ≡ eval ((P +ₕ Q) ·X+ (r +ₕ s)) (x ∷ xs)
compute+ₕEvalNotBothZero n P Q r s _ _ notBothZero
with isZero νR (P +ₕ Q) and isZero νR (r +ₕ s) | notBothZero
... | true | p = byBoolAbsurdity (sym p)
... | false | p = refl
| {
"alphanum_fraction": 0.5213060321,
"avg_line_length": 40.4552238806,
"ext": "agda",
"hexsha": "a3cf5ef335db49f459b358b6171b3cbcd2ad1cb8",
"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/CommRingSolver/HornerEval.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/CommRingSolver/HornerEval.agda",
"max_line_length": 106,
"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/CommRingSolver/HornerEval.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2034,
"size": 5421
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of the `Reflects` construct
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary.Reflects where
open import Agda.Builtin.Equality
open import Data.Bool.Base
open import Data.Empty
open import Level
open import Relation.Nullary
private
variable
p : Level
P : Set p
------------------------------------------------------------------------
-- `Reflects P b` is equivalent to `if b then P else ¬ P`.
-- These lemmas are intended to be used mostly when `b` is a value, so
-- that the `if` expressions have already been evaluated away.
-- In this case, `of` works like the relevant constructor (`ofⁿ` or
-- `ofʸ`), and `invert` strips off the constructor to just give either
-- the proof of `P` or the proof of `¬ P`.
of : ∀ {b} → if b then P else ¬ P → Reflects P b
of {b = false} ¬p = ofⁿ ¬p
of {b = true } p = ofʸ p
invert : ∀ {b} → Reflects P b → if b then P else ¬ P
invert (ofʸ p) = p
invert (ofⁿ ¬p) = ¬p
------------------------------------------------------------------------
-- Other lemmas
-- `Reflects` is deterministic.
det : ∀ {b b′} → Reflects P b → Reflects P b′ → b ≡ b′
det (ofʸ p) (ofʸ p′) = refl
det (ofʸ p) (ofⁿ ¬p′) = ⊥-elim (¬p′ p)
det (ofⁿ ¬p) (ofʸ p′) = ⊥-elim (¬p p′)
det (ofⁿ ¬p) (ofⁿ ¬p′) = refl
| {
"alphanum_fraction": 0.5062413315,
"avg_line_length": 30.0416666667,
"ext": "agda",
"hexsha": "6a5f73f61d99ea1b1a890651b14c61aa082c5861",
"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": "agda-stdlib/src/Relation/Nullary/Reflects.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": "agda-stdlib/src/Relation/Nullary/Reflects.agda",
"max_line_length": 72,
"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": "agda-stdlib/src/Relation/Nullary/Reflects.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": 419,
"size": 1442
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing where
open import Cubical.Algebra.CommRing.Base public
open import Cubical.Algebra.CommRing.Properties public
| {
"alphanum_fraction": 0.8072289157,
"avg_line_length": 27.6666666667,
"ext": "agda",
"hexsha": "0f159f20ac6802ccffd9aacec91a58d186b7e9a5",
"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/Algebra/CommRing.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/Algebra/CommRing.agda",
"max_line_length": 54,
"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/Algebra/CommRing.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": 36,
"size": 166
} |
{-# OPTIONS --without-K #-}
module Pim2Cat where
open import Level using (zero)
open import Data.Product using (_,_; _×_; proj₁; proj₂)
import Relation.Binary.PropositionalEquality as P
using (_≡_; refl; isEquivalence)
open import Categories.Category using (Category)
open import Categories.Groupoid using (Groupoid)
open import Categories.Monoidal using (Monoidal)
open import Categories.Monoidal.Helpers using (module MonoidalHelperFunctors)
open import Categories.Bifunctor using (Bifunctor)
open import Categories.NaturalIsomorphism using (NaturalIsomorphism)
open import Categories.Monoidal.Braided using (Braided)
open import Categories.Monoidal.Symmetric using (Symmetric)
open import Categories.RigCategory
using (RigCategory; module BimonoidalHelperFunctors)
open import PiU using (U; PLUS; ZERO; TIMES; ONE)
open import PiLevelm2 using (_⟷_; collapse)
-- We will define a rig category whose objects are Pi types and whose
-- morphisms are the trivial equivalence that identifies all Pi types;
-- and where the equivalence of morphisms is propositional equality ≡
------------------------------------------------------------------------------
-- First it is a category
triv : {A B : U} → (f : A ⟷ B) → (collapse P.≡ f)
triv collapse = P.refl
Pim2Cat : Category zero zero zero
Pim2Cat = record
{ Obj = U
; _⇒_ = _⟷_
; _≡_ = P._≡_
; id = collapse
; _∘_ = λ _ _ → collapse
; assoc = P.refl
; identityˡ = λ {A} {B} {f} → triv f
; identityʳ = λ {A} {B} {f} → triv f
; equiv = P.isEquivalence
; ∘-resp-≡ = λ _ _ → P.refl
}
-- and a groupoid
Pim2Groupoid : Groupoid Pim2Cat
Pim2Groupoid = record
{ _⁻¹ = λ _ → collapse
; iso = record { isoˡ = P.refl; isoʳ = P.refl }
}
-- The additive structure is monoidal
PLUS-bifunctor : Bifunctor Pim2Cat Pim2Cat Pim2Cat
PLUS-bifunctor = record
{ F₀ = λ {( x , y) → PLUS x y}
; F₁ = λ {(x , y) → collapse}
; identity = P.refl
; homomorphism = P.refl
; F-resp-≡ = λ { (e₁ , e₂) → P.refl }
}
module PLUSh = MonoidalHelperFunctors Pim2Cat PLUS-bifunctor ZERO
0PLUSx≡x : NaturalIsomorphism PLUSh.id⊗x PLUSh.x
0PLUSx≡x = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
xPLUS0≡x : NaturalIsomorphism PLUSh.x⊗id PLUSh.x
xPLUS0≡x = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
[xPLUSy]PLUSz≡xPLUS[yPLUSz] : NaturalIsomorphism PLUSh.[x⊗y]⊗z PLUSh.x⊗[y⊗z]
[xPLUSy]PLUSz≡xPLUS[yPLUSz] = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
CPMPLUS : Monoidal Pim2Cat
CPMPLUS = record
{ ⊗ = PLUS-bifunctor
; id = ZERO
; identityˡ = 0PLUSx≡x
; identityʳ = xPLUS0≡x
; assoc = [xPLUSy]PLUSz≡xPLUS[yPLUSz]
; triangle = P.refl
; pentagon = P.refl
}
-- The multiplicative structure is also monoidal
TIMES-bifunctor : Bifunctor Pim2Cat Pim2Cat Pim2Cat
TIMES-bifunctor = record
{ F₀ = λ {( x , y) → TIMES x y}
; F₁ = λ {(x , y) → collapse }
; identity = P.refl
; homomorphism = P.refl
; F-resp-≡ = λ { (e₁ , e₂) → P.refl}
}
module TIMESh = MonoidalHelperFunctors Pim2Cat TIMES-bifunctor ONE
1TIMESy≡y : NaturalIsomorphism TIMESh.id⊗x TIMESh.x
1TIMESy≡y = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
yTIMES1≡y : NaturalIsomorphism TIMESh.x⊗id TIMESh.x
yTIMES1≡y = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
[xTIMESy]TIMESz≡xTIMES[yTIMESz] :
NaturalIsomorphism TIMESh.[x⊗y]⊗z TIMESh.x⊗[y⊗z]
[xTIMESy]TIMESz≡xTIMES[yTIMESz] = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
CPMTIMES : Monoidal Pim2Cat
CPMTIMES = record
{ ⊗ = TIMES-bifunctor
; id = ONE
; identityˡ = 1TIMESy≡y
; identityʳ = yTIMES1≡y
; assoc = [xTIMESy]TIMESz≡xTIMES[yTIMESz]
; triangle = P.refl
; pentagon = P.refl
}
-- The monoidal structures are symmetric
xPLUSy≈yPLUSx : NaturalIsomorphism PLUSh.x⊗y PLUSh.y⊗x
xPLUSy≈yPLUSx = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
BMPLUS : Braided CPMPLUS
BMPLUS = record
{ braid = xPLUSy≈yPLUSx
; unit-coh = P.refl
; hexagon₁ = P.refl
; hexagon₂ = P.refl
}
xTIMESy≈yTIMESx : NaturalIsomorphism TIMESh.x⊗y TIMESh.y⊗x
xTIMESy≈yTIMESx = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
BMTIMES : Braided CPMTIMES
BMTIMES = record
{ braid = xTIMESy≈yTIMESx
; unit-coh = P.refl
; hexagon₁ = P.refl
; hexagon₂ = P.refl
}
SBMPLUS : Symmetric BMPLUS
SBMPLUS = record { symmetry = P.refl }
SBMTIMES : Symmetric BMTIMES
SBMTIMES = record { symmetry = P.refl }
-- And finally the multiplicative structure distributes over the
-- additive one
module r = BimonoidalHelperFunctors BMPLUS BMTIMES
x⊗[y⊕z]≡[x⊗y]⊕[x⊗z] : NaturalIsomorphism r.x⊗[y⊕z] r.[x⊗y]⊕[x⊗z]
x⊗[y⊕z]≡[x⊗y]⊕[x⊗z] = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record { isoˡ = P.refl
; isoʳ = P.refl }
}
[x⊕y]⊗z≡[x⊗z]⊕[y⊗z] : NaturalIsomorphism r.[x⊕y]⊗z r.[x⊗z]⊕[y⊗z]
[x⊕y]⊗z≡[x⊗z]⊕[y⊗z] = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record { isoˡ = P.refl
; isoʳ = P.refl }
}
x⊗0≡0 : NaturalIsomorphism r.x⊗0 r.0↑
x⊗0≡0 = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
0⊗x≡0 : NaturalIsomorphism r.0⊗x r.0↑
0⊗x≡0 = record
{ F⇒G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; F⇐G = record
{ η = λ X → collapse
; commute = λ f → P.refl
}
; iso = λ X → record
{ isoˡ = P.refl
; isoʳ = P.refl
}
}
TERig : RigCategory SBMPLUS SBMTIMES
TERig = record
{ distribₗ = x⊗[y⊕z]≡[x⊗y]⊕[x⊗z]
; distribᵣ = [x⊕y]⊗z≡[x⊗z]⊕[y⊗z]
; annₗ = 0⊗x≡0
; annᵣ = x⊗0≡0
; laplazaI = P.refl
; laplazaII = P.refl
; laplazaIV = P.refl
; laplazaVI = P.refl
; laplazaIX = P.refl
; laplazaX = P.refl
; laplazaXI = P.refl
; laplazaXIII = P.refl
; laplazaXV = P.refl
; laplazaXVI = P.refl
; laplazaXVII = P.refl
; laplazaXIX = P.refl
; laplazaXXIII = P.refl
}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5716127369,
"avg_line_length": 22.484057971,
"ext": "agda",
"hexsha": "90235e63f6abadb8c7f1d92b1ac65d21359d88c6",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Pim2Cat.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Pim2Cat.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Pim2Cat.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 3269,
"size": 7757
} |
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
data ⊤ : Set where
tt : ⊤
data S : Set where
base : S
loop : base ≡ base
postulate
P' : base ≡ base → Set
pl : P' loop
foo : P' loop
foo with tt
... | w = pl
| {
"alphanum_fraction": 0.6271777003,
"avg_line_length": 13.6666666667,
"ext": "agda",
"hexsha": "c45ba59cb0c9dd613fbe4616d64f8f12600da83c",
"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/Issue4214.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/Issue4214.agda",
"max_line_length": 37,
"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/Issue4214.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": 287
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Sum where
open import Cubical.Data.Sum.Base public
open import Cubical.Data.Sum.Properties public
| {
"alphanum_fraction": 0.7647058824,
"avg_line_length": 28.3333333333,
"ext": "agda",
"hexsha": "e72ec4260f0026db29c5443d71c5e8e89b4007c9",
"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/Sum.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/Sum.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/Sum.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 39,
"size": 170
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some code related to transitive closures that relies on the K rule
------------------------------------------------------------------------
{-# OPTIONS --with-K --safe #-}
module Relation.Binary.Construct.Closure.Transitive.WithK where
open import Function
open import Relation.Binary
open import Relation.Binary.Construct.Closure.Transitive
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
module _ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} where
∼⁺⟨⟩-injectiveˡ : ∀ {x y z} {p r : x [ _∼_ ]⁺ y} {q s} →
(x [ _∼_ ]⁺ z ∋ x ∼⁺⟨ p ⟩ q) ≡ (x ∼⁺⟨ r ⟩ s) → p ≡ r
∼⁺⟨⟩-injectiveˡ refl = refl
∼⁺⟨⟩-injectiveʳ : ∀ {x y z} {p r : x [ _∼_ ]⁺ y} {q s} →
(x [ _∼_ ]⁺ z ∋ x ∼⁺⟨ p ⟩ q) ≡ (x ∼⁺⟨ r ⟩ s) → q ≡ s
∼⁺⟨⟩-injectiveʳ refl = refl
| {
"alphanum_fraction": 0.4769921437,
"avg_line_length": 35.64,
"ext": "agda",
"hexsha": "1eff43bbca0eee3788012cd069780f446157379a",
"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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Closure/Transitive/WithK.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"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": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Closure/Transitive/WithK.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Closure/Transitive/WithK.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": 314,
"size": 891
} |
-- Intuitionistic propositional calculus.
-- Hilbert-style formalisation of syntax.
-- Nested terms.
module IPC.Syntax.Hilbert where
open import IPC.Syntax.Common public
-- Derivations.
infix 3 _⊢_
data _⊢_ (Γ : Cx Ty) : Ty → Set where
var : ∀ {A} → A ∈ Γ → Γ ⊢ A
app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B
ci : ∀ {A} → Γ ⊢ A ▻ A
ck : ∀ {A B} → Γ ⊢ A ▻ B ▻ A
cs : ∀ {A B C} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
cpair : ∀ {A B} → Γ ⊢ A ▻ B ▻ A ∧ B
cfst : ∀ {A B} → Γ ⊢ A ∧ B ▻ A
csnd : ∀ {A B} → Γ ⊢ A ∧ B ▻ B
unit : Γ ⊢ ⊤
cboom : ∀ {C} → Γ ⊢ ⊥ ▻ C
cinl : ∀ {A B} → Γ ⊢ A ▻ A ∨ B
cinr : ∀ {A B} → Γ ⊢ B ▻ A ∨ B
ccase : ∀ {A B C} → Γ ⊢ A ∨ B ▻ (A ▻ C) ▻ (B ▻ C) ▻ C
infix 3 _⊢⋆_
_⊢⋆_ : Cx Ty → Cx Ty → Set
Γ ⊢⋆ ∅ = 𝟙
Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A
-- Monotonicity with respect to context inclusion.
mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
mono⊢ η ci = ci
mono⊢ η ck = ck
mono⊢ η cs = cs
mono⊢ η cpair = cpair
mono⊢ η cfst = cfst
mono⊢ η csnd = csnd
mono⊢ η unit = unit
mono⊢ η cboom = cboom
mono⊢ η cinl = cinl
mono⊢ η cinr = cinr
mono⊢ η ccase = ccase
mono⊢⋆ : ∀ {Γ″ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Γ″ → Γ′ ⊢⋆ Γ″
mono⊢⋆ {∅} η ∙ = ∙
mono⊢⋆ {Γ″ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
-- Shorthand for variables.
v₀ : ∀ {A Γ} → Γ , A ⊢ A
v₀ = var i₀
v₁ : ∀ {A B Γ} → Γ , A , B ⊢ A
v₁ = var i₁
v₂ : ∀ {A B C Γ} → Γ , A , B , C ⊢ A
v₂ = var i₂
-- Reflexivity.
refl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ
refl⊢⋆ {∅} = ∙
refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀
-- Deduction theorem.
lam : ∀ {A B Γ} → Γ , A ⊢ B → Γ ⊢ A ▻ B
lam (var top) = ci
lam (var (pop i)) = app ck (var i)
lam (app t u) = app (app cs (lam t)) (lam u)
lam ci = app ck ci
lam ck = app ck ck
lam cs = app ck cs
lam cpair = app ck cpair
lam cfst = app ck cfst
lam csnd = app ck csnd
lam unit = app ck unit
lam cboom = app ck cboom
lam cinl = app ck cinl
lam cinr = app ck cinr
lam ccase = app ck ccase
lam⋆ : ∀ {Ξ Γ A} → Γ ⧺ Ξ ⊢ A → Γ ⊢ Ξ ▻⋯▻ A
lam⋆ {∅} = I
lam⋆ {Ξ , B} = lam⋆ {Ξ} ∘ lam
lam⋆₀ : ∀ {Γ A} → Γ ⊢ A → ∅ ⊢ Γ ▻⋯▻ A
lam⋆₀ {∅} = I
lam⋆₀ {Γ , B} = lam⋆₀ ∘ lam
-- Detachment theorem.
det : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B
det t = app (mono⊢ weak⊆ t) v₀
det⋆ : ∀ {Ξ Γ A} → Γ ⊢ Ξ ▻⋯▻ A → Γ ⧺ Ξ ⊢ A
det⋆ {∅} = I
det⋆ {Ξ , B} = det ∘ det⋆ {Ξ}
det⋆₀ : ∀ {Γ A} → ∅ ⊢ Γ ▻⋯▻ A → Γ ⊢ A
det⋆₀ {∅} = I
det⋆₀ {Γ , B} = det ∘ det⋆₀
-- Cut and multicut.
cut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B
cut t u = app (lam u) t
multicut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A
multicut {∅} ∙ u = mono⊢ bot⊆ u
multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t
-- Transitivity.
trans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″
trans⊢⋆ {∅} ts ∙ = ∙
trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u
-- Contraction.
ccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = lam (lam (app (app v₁ v₀) v₀))
cont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B
cont t = det (app ccont (lam (lam t)))
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = lam (lam (lam (app (app v₂ v₀) v₁)))
exch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C
exch t = det (det (app cexch (lam (lam t))))
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = lam (lam (lam (app v₂ (app v₁ v₀))))
comp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C
comp t u = det (app (app ccomp (lam t)) (lam u))
-- Useful theorems in functional form.
pair : ∀ {A B Γ} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B
pair t u = app (app cpair t) u
fst : ∀ {A B Γ} → Γ ⊢ A ∧ B → Γ ⊢ A
fst t = app cfst t
snd : ∀ {A B Γ} → Γ ⊢ A ∧ B → Γ ⊢ B
snd t = app csnd t
boom : ∀ {C Γ} → Γ ⊢ ⊥ → Γ ⊢ C
boom t = app cboom t
inl : ∀ {A B Γ} → Γ ⊢ A → Γ ⊢ A ∨ B
inl t = app cinl t
inr : ∀ {A B Γ} → Γ ⊢ B → Γ ⊢ A ∨ B
inr t = app cinr t
case : ∀ {A B C Γ} → Γ ⊢ A ∨ B → Γ , A ⊢ C → Γ , B ⊢ C → Γ ⊢ C
case t u v = app (app (app ccase t) (lam u)) (lam v)
-- Closure under context concatenation.
concat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
-- Convertibility.
data _⋙_ {Γ : Cx Ty} : ∀ {A} → Γ ⊢ A → Γ ⊢ A → Set where
refl⋙ : ∀ {A} → {t : Γ ⊢ A}
→ t ⋙ t
trans⋙ : ∀ {A} → {t t′ t″ : Γ ⊢ A}
→ t ⋙ t′ → t′ ⋙ t″
→ t ⋙ t″
sym⋙ : ∀ {A} → {t t′ : Γ ⊢ A}
→ t ⋙ t′
→ t′ ⋙ t
congapp⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ▻ B} → {u u′ : Γ ⊢ A}
→ t ⋙ t′ → u ⋙ u′
→ app t u ⋙ app t′ u′
congi⋙ : ∀ {A} → {t t′ : Γ ⊢ A}
→ t ⋙ t′
→ app ci t ⋙ app ci t′
congk⋙ : ∀ {A B} → {t t′ : Γ ⊢ A} → {u u′ : Γ ⊢ B}
→ t ⋙ t′ → u ⋙ u′
→ app (app ck t) u ⋙ app (app ck t′) u′
congs⋙ : ∀ {A B C} → {t t′ : Γ ⊢ A ▻ B ▻ C} → {u u′ : Γ ⊢ A ▻ B} → {v v′ : Γ ⊢ A}
→ t ⋙ t′ → u ⋙ u′ → v ⋙ v′
→ app (app (app cs t) u) v ⋙ app (app (app cs t′) u′) v′
congpair⋙ : ∀ {A B} → {t t′ : Γ ⊢ A} → {u u′ : Γ ⊢ B}
→ t ⋙ t′ → u ⋙ u′
→ app (app cpair t) u ⋙ app (app cpair t′) u′
congfst⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B}
→ t ⋙ t′
→ app cfst t ⋙ app cfst t′
congsnd⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B}
→ t ⋙ t′
→ app csnd t ⋙ app csnd t′
congboom⋙ : ∀ {C} → {t t′ : Γ ⊢ ⊥}
→ t ⋙ t′
→ app (cboom {C = C}) t ⋙ app cboom t′
conginl⋙ : ∀ {A B} → {t t′ : Γ ⊢ A}
→ t ⋙ t′
→ app (cinl {A = A} {B}) t ⋙ app cinl t′
conginr⋙ : ∀ {A B} → {t t′ : Γ ⊢ B}
→ t ⋙ t′
→ app (cinr {A = A} {B}) t ⋙ app cinr t′
congcase⋙ : ∀ {A B C} → {t t′ : Γ ⊢ A ∨ B} → {u u′ : Γ ⊢ A ▻ C} → {v v′ : Γ ⊢ B ▻ C}
→ t ⋙ t′ → u ⋙ u′ → v ⋙ v′
→ app (app (app ccase t) u) v ⋙ app (app (app ccase t′) u′) v′
-- TODO: Verify this.
beta▻ₖ⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ app (app ck t) u ⋙ t
-- TODO: Verify this.
beta▻ₛ⋙ : ∀ {A B C} → {t : Γ ⊢ A ▻ B ▻ C} → {u : Γ ⊢ A ▻ B} → {v : Γ ⊢ A}
→ app (app (app cs t) u) v ⋙ app (app t v) (app u v)
-- TODO: What about eta for ▻?
beta∧₁⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ app cfst (app (app cpair t) u) ⋙ t
beta∧₂⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ app csnd (app (app cpair t) u) ⋙ u
eta∧⋙ : ∀ {A B} → {t : Γ ⊢ A ∧ B}
→ t ⋙ app (app cpair (app cfst t)) (app csnd t)
eta⊤⋙ : ∀ {t : Γ ⊢ ⊤} → t ⋙ unit
-- TODO: Verify this.
beta∨₁⋙ : ∀ {A B C} → {t : Γ ⊢ A} → {u : Γ ⊢ A ▻ C} → {v : Γ ⊢ B ▻ C}
→ app (app (app ccase (app cinl t)) u) v ⋙ app u t
-- TODO: Verify this.
beta∨₂⋙ : ∀ {A B C} → {t : Γ ⊢ B} → {u : Γ ⊢ A ▻ C} → {v : Γ ⊢ B ▻ C}
→ app (app (app ccase (app cinr t)) u) v ⋙ app v t
-- TODO: What about eta and commuting conversions for ∨? What about ⊥?
| {
"alphanum_fraction": 0.3778424114,
"avg_line_length": 27.2086330935,
"ext": "agda",
"hexsha": "e4b9e5d13db8e76eb1c1b1361d7464cb459b085a",
"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": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "IPC/Syntax/Hilbert.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "IPC/Syntax/Hilbert.agda",
"max_line_length": 87,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "IPC/Syntax/Hilbert.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 3757,
"size": 7564
} |
{-
Add axioms (i.e., propositions) to a structure S without changing the definition of structured equivalence.
X ↦ Σ[ s ∈ S X ] (P X s) where (P X s) is a proposition for all X and s.
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Axioms where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Path
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
private
variable
ℓ ℓ₁ ℓ₁' ℓ₂ : Level
AxiomsStructure : (S : Type ℓ → Type ℓ₁)
(axioms : (X : Type ℓ) → S X → Type ℓ₂)
→ Type ℓ → Type (ℓ-max ℓ₁ ℓ₂)
AxiomsStructure S axioms X = Σ[ s ∈ S X ] (axioms X s)
AxiomsEquivStr : {S : Type ℓ → Type ℓ₁} (ι : StrEquiv S ℓ₁')
(axioms : (X : Type ℓ) → S X → Type ℓ₂)
→ StrEquiv (AxiomsStructure S axioms) ℓ₁'
AxiomsEquivStr ι axioms (X , (s , a)) (Y , (t , b)) e = ι (X , s) (Y , t) e
axiomsUnivalentStr : {S : Type ℓ → Type ℓ₁}
(ι : (A B : TypeWithStr ℓ S) → A .fst ≃ B .fst → Type ℓ₁')
{axioms : (X : Type ℓ) → S X → Type ℓ₂}
(axioms-are-Props : (X : Type ℓ) (s : S X) → isProp (axioms X s))
(θ : UnivalentStr S ι)
→ UnivalentStr (AxiomsStructure S axioms) (AxiomsEquivStr ι axioms)
axiomsUnivalentStr {S = S} ι {axioms = axioms} axioms-are-Props θ {X , s , a} {Y , t , b} e =
ι (X , s) (Y , t) e
≃⟨ θ e ⟩
PathP (λ i → S (ua e i)) s t
≃⟨ invEquiv (Σ-contractSnd λ _ → isOfHLevelPathP' 0 (axioms-are-Props _ _) _ _) ⟩
Σ[ p ∈ PathP (λ i → S (ua e i)) s t ] PathP (λ i → axioms (ua e i) (p i)) a b
≃⟨ ΣPath≃PathΣ ⟩
PathP (λ i → AxiomsStructure S axioms (ua e i)) (s , a) (t , b)
■
inducedStructure : {S : Type ℓ → Type ℓ₁}
{ι : (A B : TypeWithStr ℓ S) → A .fst ≃ B .fst → Type ℓ₁'}
(θ : UnivalentStr S ι)
{axioms : (X : Type ℓ) → S X → Type ℓ₂}
(A : TypeWithStr ℓ (AxiomsStructure S axioms)) (B : TypeWithStr ℓ S)
→ (typ A , str A .fst) ≃[ ι ] B
→ TypeWithStr ℓ (AxiomsStructure S axioms)
inducedStructure θ {axioms} A B eqv =
B .fst , B .snd , subst (uncurry axioms) (sip θ _ _ eqv) (A .snd .snd)
transferAxioms : {S : Type ℓ → Type ℓ₁}
{ι : (A B : TypeWithStr ℓ S) → A .fst ≃ B .fst → Type ℓ₁'}
(θ : UnivalentStr S ι)
{axioms : (X : Type ℓ) → S X → Type ℓ₂}
(A : TypeWithStr ℓ (AxiomsStructure S axioms)) (B : TypeWithStr ℓ S)
→ (typ A , str A .fst) ≃[ ι ] B
→ axioms (fst B) (snd B)
transferAxioms θ {axioms} A B eqv =
subst (uncurry axioms) (sip θ _ _ eqv) (A .snd .snd)
| {
"alphanum_fraction": 0.6247139588,
"avg_line_length": 37.4571428571,
"ext": "agda",
"hexsha": "d773a389d2772147d51a7d34e55552bec5c847f1",
"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": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Structures/Axioms.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/Structures/Axioms.agda",
"max_line_length": 107,
"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/Structures/Axioms.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1094,
"size": 2622
} |
module OldBasicILP.Syntax.Common where
open import Common.ContextPair public
| {
"alphanum_fraction": 0.858974359,
"avg_line_length": 19.5,
"ext": "agda",
"hexsha": "986a57fed730fa9390e5f66b7e27c9d2eb834864",
"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": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "OldBasicILP/Syntax/Common.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "OldBasicILP/Syntax/Common.agda",
"max_line_length": 38,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "OldBasicILP/Syntax/Common.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 16,
"size": 78
} |
module Algebra.LabelledGraph.Reasoning where
open import Algebra.Dioid
open import Algebra.LabelledGraph
-- Standard syntax sugar for writing equational proofs
infix 4 _≈_
data _≈_ {A B eq} {d : Dioid B eq} (x y : LabelledGraph d A) : Set where
prove : x ≡ y -> x ≈ y
infix 1 begin_
begin_ : ∀ {A B eq} {d : Dioid B eq} {x y : LabelledGraph d A} -> x ≈ y -> x ≡ y
begin prove p = p
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : ∀ {A B eq} {d : Dioid B eq} (x : LabelledGraph d A) {y z : LabelledGraph d A} -> x ≡ y -> y ≈ z -> x ≈ z
_ ≡⟨ p ⟩ prove q = prove (transitivity p q)
infix 3 _∎
_∎ : ∀ {A B eq} {d : Dioid B eq} (x : LabelledGraph d A) -> x ≈ x
_∎ _ = prove reflexivity
infixl 8 _>>_
_>>_ : ∀ {A B eq} {d : Dioid B eq} {x y z : LabelledGraph d A} -> x ≡ y -> y ≡ z -> x ≡ z
_>>_ = transitivity
L : ∀ {A B eq} {d : Dioid B eq} {x y z : LabelledGraph d A} {r : B} -> x ≡ y -> x [ r ]> z ≡ y [ r ]> z
L = left-congruence
R : ∀ {A B eq} {d : Dioid B eq} {x y z : LabelledGraph d A} {r : B} -> x ≡ y -> z [ r ]> x ≡ z [ r ]> y
R = right-congruence
| {
"alphanum_fraction": 0.5637583893,
"avg_line_length": 32.59375,
"ext": "agda",
"hexsha": "398aec7a1c4de554f55cbf0e9a1a85ef7cfdf95a",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2019-05-09T23:53:28.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-17T20:48:20.000Z",
"max_forks_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "snowleopard/alga-proofs",
"max_forks_repo_path": "src/Algebra/LabelledGraph/Reasoning.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d",
"max_issues_repo_issues_event_max_datetime": "2018-06-23T13:54:02.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-04-12T16:25:13.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "snowleopard/alga-proofs",
"max_issues_repo_path": "src/Algebra/LabelledGraph/Reasoning.agda",
"max_line_length": 113,
"max_stars_count": 60,
"max_stars_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "snowleopard/alga-proofs",
"max_stars_repo_path": "src/Algebra/LabelledGraph/Reasoning.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:05:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-12-27T14:57:04.000Z",
"num_tokens": 456,
"size": 1043
} |
module Type.Category.ExtensionalFunctionsCategory.HomFunctor where
import Functional as Fn
open import Function.Proofs
open import Function.Equals
open import Function.Equals.Proofs
open import Logic.Predicate
import Lvl
import Relator.Equals.Proofs.Equiv
open import Structure.Category
open import Structure.Category.Dual
open import Structure.Category.Functor
open import Structure.Categorical.Properties
open import Structure.Function
open import Structure.Operator
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
open import Structure.Setoid
open import Syntax.Transitivity
open import Type.Category.ExtensionalFunctionsCategory
open import Type
private variable ℓ ℓₒ ℓₘ ℓₑ : Lvl.Level
-- Note: This is implicitly using the identity type as the equivalence for (_⟶_).
module _ {Obj : Type{ℓₒ}} {_⟶_ : Obj → Obj → Type{ℓₘ}} (C : Category(_⟶_)) where
open Category(C)
covariantHomFunctor : Obj → ((intro C) →ᶠᵘⁿᶜᵗᵒʳ typeExtensionalFnCategoryObject{ℓₘ})
∃.witness (covariantHomFunctor x) y = (x ⟶ y)
Functor.map (∃.proof (covariantHomFunctor _)) = (_∘_)
_⊜_.proof (Function.congruence (Functor.map-function (∃.proof (covariantHomFunctor _))) {f₁} {f₂} f₁f₂) {g} = congruence₂ₗ(_∘_) ⦃ binaryOperator ⦄ g f₁f₂
_⊜_.proof (Functor.op-preserving (∃.proof (covariantHomFunctor _))) = Morphism.associativity(_∘_)
_⊜_.proof (Functor.id-preserving (∃.proof (covariantHomFunctor _))) = Morphism.identityₗ(_∘_)(id)
contravariantHomFunctor : Obj → (dual(intro C) →ᶠᵘⁿᶜᵗᵒʳ typeExtensionalFnCategoryObject{ℓₘ})
∃.witness (contravariantHomFunctor x) y = (y ⟶ x)
Functor.map (∃.proof (contravariantHomFunctor _)) = Fn.swap(_∘_)
_⊜_.proof (Function.congruence (Functor.map-function (∃.proof (contravariantHomFunctor _))) {g₁} {g₂} g₁g₂) {f} = congruence₂ᵣ(_∘_) ⦃ binaryOperator ⦄ f g₁g₂
_⊜_.proof (Functor.op-preserving (∃.proof (contravariantHomFunctor _))) = symmetry(_) (Morphism.associativity(_∘_))
_⊜_.proof (Functor.id-preserving (∃.proof (contravariantHomFunctor _))) = Morphism.identityᵣ(_∘_)(id)
| {
"alphanum_fraction": 0.7599033816,
"avg_line_length": 49.2857142857,
"ext": "agda",
"hexsha": "86a7cf96c66878170b3c00a96b43e22a06f64bef",
"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": "Type/Category/ExtensionalFunctionsCategory/HomFunctor.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": "Type/Category/ExtensionalFunctionsCategory/HomFunctor.agda",
"max_line_length": 159,
"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": "Type/Category/ExtensionalFunctionsCategory/HomFunctor.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": 698,
"size": 2070
} |
{-# OPTIONS --without-K #-}
module pointed.core where
open import sum
open import equality.core
open import function.core
open import function.isomorphism.core
PSet : ∀ i → Set _
PSet i = Σ (Set i) λ X → X
PMap : ∀ {i j} → PSet i → PSet j → Set _
PMap (X , x) (Y , y) = Σ (X → Y) λ f → f x ≡ y
_∘P_ : ∀ {i j k}{𝓧 : PSet i}{𝓨 : PSet j}{𝓩 : PSet k}
→ PMap 𝓨 𝓩 → PMap 𝓧 𝓨 → PMap 𝓧 𝓩
(g , q) ∘P (f , p) = (g ∘ f , ap g p · q)
instance
pmap-comp : ∀ {i j k} → Composition _ _ _ _ _ _
pmap-comp {i}{j}{k} = record
{ U₁ = PSet i
; U₂ = PSet j
; U₃ = PSet k
; hom₁₂ = PMap
; hom₂₃ = PMap
; hom₁₃ = PMap
; _∘_ = _∘P_ }
| {
"alphanum_fraction": 0.5291411043,
"avg_line_length": 22.4827586207,
"ext": "agda",
"hexsha": "1c66284b351da097c555f3e214dea067396d4188",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/pointed/core.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/pointed/core.agda",
"max_line_length": 52,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/pointed/core.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 299,
"size": 652
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
module lib.types.FreeGroup where
module _ {i} where
private
data #FreeGroup-aux (A : Type i) : Type i where
#fg-nil : #FreeGroup-aux A
_#fg::_ : A → #FreeGroup-aux A → #FreeGroup-aux A
_#fg-inv::_ : A → #FreeGroup-aux A → #FreeGroup-aux A
{- Is this okay? The template is to have 'data' here,
- but then the β rules for paths will not typecheck.
-}
record #FreeGroup (A : Type i) : Type i where
constructor
#freegroup
field
#freegroup-proj : #FreeGroup-aux A
#freegroup-unit : Unit → Unit
FreeGroup : (A : Type i) → Type i
FreeGroup A = #FreeGroup A
module _ {A : Type i} where
fg-nil : FreeGroup A
fg-nil = #freegroup #fg-nil _
infixr 60 _fg::_
_fg::_ : A → FreeGroup A → FreeGroup A
a fg:: (#freegroup fg _) = #freegroup (a #fg:: fg) _
infixr 60 _fg-inv::_
_fg-inv::_ : A → FreeGroup A → FreeGroup A
a fg-inv:: (#freegroup fg _) = #freegroup (a #fg-inv:: fg) _
postulate -- HIT
fg-inv-l : ∀ (a : A) → (fg : FreeGroup A) → a fg-inv:: a fg:: fg == fg
fg-inv-r : ∀ (a : A) → (fg : FreeGroup A) → a fg:: a fg-inv:: fg == fg
postulate -- HIT
FreeGroup-level : is-set (FreeGroup A)
FreeGroup-is-set = FreeGroup-level
module FreeGroupElim {j} {P : FreeGroup A → Type j}
(p : (x : FreeGroup A) → is-set (P x)) (nil* : P fg-nil)
(_fg::*_ : ∀ a {fg} (fg* : P fg) → P (a fg:: fg))
(_fg-inv::*_ : ∀ a {fg} (fg* : P fg) → P (a fg-inv:: fg))
(fg-inv-l* : ∀ a {fg} (fg* : P fg) → (a fg-inv::* (a fg::* fg*)) == fg* [ P ↓ fg-inv-l a fg ] )
(fg-inv-r* : ∀ a {fg} (fg* : P fg) → (a fg::* (a fg-inv::* fg*)) == fg* [ P ↓ fg-inv-r a fg ]) where
f : Π (FreeGroup A) P
f = f-aux phantom phantom phantom where
f-aux* : Π (#FreeGroup-aux A) (P ∘ (λ fg → #freegroup fg _))
f-aux* #fg-nil = nil*
f-aux* (a #fg:: fg) = a fg::* f-aux* fg
f-aux* (a #fg-inv:: fg) = a fg-inv::* f-aux* fg
f-aux : Phantom p → Phantom fg-inv-l* → Phantom fg-inv-r*
→ Π (FreeGroup A) P
f-aux phantom phantom phantom (#freegroup fg _) = f-aux* fg
postulate -- HIT
fg-inv-l-β : ∀ a fg → apd f (fg-inv-l a fg) == fg-inv-l* a (f fg)
fg-inv-r-β : ∀ a fg → apd f (fg-inv-r a fg) == fg-inv-r* a (f fg)
open FreeGroupElim public renaming (f to FreeGroup-elim)
module FreeGroupRec {i} {A : Type i} {j} {B : Type j} (p : is-set B)
(nil* : B) (_fg::*[_]_ : A → FreeGroup A → B → B) (_fg-inv::*[_]_ : A → FreeGroup A → B → B)
(fg-inv-l* : ∀ a {fg} fg* → (a fg-inv::*[ a fg:: fg ] (a fg::*[ fg ] fg*)) == fg*)
(fg-inv-r* : ∀ a {fg} fg* → (a fg::*[ a fg-inv:: fg ] (a fg-inv::*[ fg ] fg*)) == fg*) where
private
module M = FreeGroupElim (λ x → p) nil*
(λ a {fg} fg* → a fg::*[ fg ] fg*)
(λ a {fg} fg* → a fg-inv::*[ fg ] fg*)
(λ a {fg} fg* → ↓-cst-in (fg-inv-l* a {fg} fg*))
(λ a {fg} fg* → ↓-cst-in (fg-inv-r* a {fg} fg*))
f : FreeGroup A → B
f = M.f
open FreeGroupRec public renaming (f to FreeGroup-rec)
| {
"alphanum_fraction": 0.5094577554,
"avg_line_length": 34.4782608696,
"ext": "agda",
"hexsha": "ccc7e3ede5a8a6a80adfbc92d807f33e95a57c79",
"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": "lib/types/FreeGroup.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": "lib/types/FreeGroup.agda",
"max_line_length": 110,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/types/FreeGroup.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": 1159,
"size": 3172
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Commutative semirings with some additional structure ("almost"
-- commutative rings), used by the ring solver
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Algebra.Solver.Ring.AlmostCommutativeRing where
open import Relation.Binary
open import Algebra
open import Algebra.Structures
open import Algebra.FunctionProperties
import Algebra.Morphism as Morphism
open import Function
open import Level
------------------------------------------------------------------------
-- Definitions
record IsAlmostCommutativeRing
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ)
(_+_ _*_ : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isCommutativeSemiring : IsCommutativeSemiring _≈_ _+_ _*_ 0# 1#
-‿cong : -_ Preserves _≈_ ⟶ _≈_
-‿*-distribˡ : ∀ x y → ((- x) * y) ≈ (- (x * y))
-‿+-comm : ∀ x y → ((- x) + (- y)) ≈ (- (x + y))
open IsCommutativeSemiring isCommutativeSemiring public
record AlmostCommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
1# : Carrier
isAlmostCommutativeRing :
IsAlmostCommutativeRing _≈_ _+_ _*_ -_ 0# 1#
open IsAlmostCommutativeRing isAlmostCommutativeRing public
commutativeSemiring : CommutativeSemiring _ _
commutativeSemiring =
record { isCommutativeSemiring = isCommutativeSemiring }
open CommutativeSemiring commutativeSemiring public
using ( +-semigroup; +-monoid; +-commutativeMonoid
; *-semigroup; *-monoid; *-commutativeMonoid
; semiring
)
rawRing : RawRing _
rawRing = record
{ _+_ = _+_
; _*_ = _*_
; -_ = -_
; 0# = 0#
; 1# = 1#
}
------------------------------------------------------------------------
-- Homomorphisms
record _-Raw-AlmostCommutative⟶_
{r₁ r₂ r₃}
(From : RawRing r₁)
(To : AlmostCommutativeRing r₂ r₃) : Set (r₁ ⊔ r₂ ⊔ r₃) where
private
module F = RawRing From
module T = AlmostCommutativeRing To
open Morphism.Definitions F.Carrier T.Carrier T._≈_
field
⟦_⟧ : Morphism
+-homo : Homomorphic₂ ⟦_⟧ F._+_ T._+_
*-homo : Homomorphic₂ ⟦_⟧ F._*_ T._*_
-‿homo : Homomorphic₁ ⟦_⟧ F.-_ T.-_
0-homo : Homomorphic₀ ⟦_⟧ F.0# T.0#
1-homo : Homomorphic₀ ⟦_⟧ F.1# T.1#
-raw-almostCommutative⟶
: ∀ {r₁ r₂} (R : AlmostCommutativeRing r₁ r₂) →
AlmostCommutativeRing.rawRing R -Raw-AlmostCommutative⟶ R
-raw-almostCommutative⟶ R = record
{ ⟦_⟧ = id
; +-homo = λ _ _ → refl
; *-homo = λ _ _ → refl
; -‿homo = λ _ → refl
; 0-homo = refl
; 1-homo = refl
}
where open AlmostCommutativeRing R
-- A homomorphism induces a notion of equivalence on the raw ring.
Induced-equivalence :
∀ {c₁ c₂ ℓ} {Coeff : RawRing c₁} {R : AlmostCommutativeRing c₂ ℓ} →
Coeff -Raw-AlmostCommutative⟶ R → Rel (RawRing.Carrier Coeff) ℓ
Induced-equivalence {R = R} morphism a b = ⟦ a ⟧ ≈ ⟦ b ⟧
where
open AlmostCommutativeRing R
open _-Raw-AlmostCommutative⟶_ morphism
------------------------------------------------------------------------
-- Conversions
-- Commutative rings are almost commutative rings.
fromCommutativeRing :
∀ {r₁ r₂} → CommutativeRing r₁ r₂ → AlmostCommutativeRing _ _
fromCommutativeRing CR = record
{ isAlmostCommutativeRing = record
{ isCommutativeSemiring = isCommutativeSemiring
; -‿cong = -‿cong
; -‿*-distribˡ = -‿*-distribˡ
; -‿+-comm = ⁻¹-∙-comm
}
}
where
open CommutativeRing CR
import Algebra.Properties.Ring as R; open R ring
import Algebra.Properties.AbelianGroup as AG; open AG +-abelianGroup
-- Commutative semirings can be viewed as almost commutative rings by
-- using identity as the "almost negation".
fromCommutativeSemiring :
∀ {r₁ r₂} → CommutativeSemiring r₁ r₂ → AlmostCommutativeRing _ _
fromCommutativeSemiring CS = record
{ -_ = id
; isAlmostCommutativeRing = record
{ isCommutativeSemiring = isCommutativeSemiring
; -‿cong = id
; -‿*-distribˡ = λ _ _ → refl
; -‿+-comm = λ _ _ → refl
}
}
where open CommutativeSemiring CS
| {
"alphanum_fraction": 0.5583636753,
"avg_line_length": 31.5472972973,
"ext": "agda",
"hexsha": "f8f01468bc0415ed18b05215c55654799f2f43fb",
"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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/AlmostCommutativeRing.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"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": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/AlmostCommutativeRing.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/AlmostCommutativeRing.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1483,
"size": 4669
} |
open import Agda.Builtin.List
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
macro
m : Term → TC ⊤
m _ =
bindTC (quoteTC (Set → @0 Set → Set)) λ t →
typeError (termErr t ∷ [])
_ : Set
_ = m
| {
"alphanum_fraction": 0.6383928571,
"avg_line_length": 16,
"ext": "agda",
"hexsha": "ace305146e7a64d90cc73bb92278b21f3702fda2",
"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/Issue5317.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/Issue5317.agda",
"max_line_length": 47,
"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/Issue5317.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": 76,
"size": 224
} |
{-# OPTIONS --without-K #-}
module Cat where
import Level as L
open import Data.Fin hiding (fromℕ; toℕ)
open import Data.Nat
open import Data.Product
open import Data.List
open import Function renaming (_∘_ to _○_)
open import HoTT
open import FT
open import FT-Nat
import Equivalences as E
open import Path2Equiv
{--
1. postulate path2equiv
2. show that (FT, path) is equivalent to (FinSet, bijections) as categories
3. show that [[ ]]: (B, <->) -> (Set, function) is a functor
[where (Set is Agda's Set)].
--}
{--
Categories, functors, etc. adapted from:
http://wiki.portal.chalmers.se/agda/uploads/Main.Libraries/20110915Category.agda
Consider using:
https://github.com/tomprince/agda-categories
https://github.com/tomprince/agda-categories/blob/master/Categories/Category.agda
--}
------------------------------------------------------------------
-- Categories
record Setoid (a b : L.Level) : Set (L.suc (a L.⊔ b)) where
infix 2 _∼_
field
object : Set a
_∼_ : object → object → Set b
refl∼ : {x : object} → x ∼ x
sym∼ : {x y : object} → x ∼ y → y ∼ x
trans∼ : {x y z : object} → y ∼ z → x ∼ y → x ∼ z
strictSetoid : ∀ {a} → Set a → Setoid a a
strictSetoid A = record
{ object = A
; _∼_ = _≡_
; refl∼ = λ {x} → refl x
; sym∼ = !
; trans∼ = λ q p → p ∘ q
}
∥_∥ : ∀ {a b c} {X : Set a} → (h : X → X → Setoid b c) → (x y : X) → Set b
∥ h ∥ x y = Setoid.object (h x y)
record Cat (a b c : L.Level) : Set (L.suc (a L.⊔ b L.⊔ c)) where
field
object : Set a
hom : object → object → Setoid b c
identity : (x : object) → ∥ hom ∥ x x
comp : {x y z : object} → ∥ hom ∥ y z → ∥ hom ∥ x y → ∥ hom ∥ x z
comp∼ : {x y z : object} →
{g0 g1 : ∥ hom ∥ y z} → {f0 f1 : ∥ hom ∥ x y} →
(g0∼g1 : let open Setoid (hom y z) in g0 ∼ g1) →
(f0∼f1 : let open Setoid (hom x y) in f0 ∼ f1) →
let open Setoid (hom x z) in comp g0 f0 ∼ comp g1 f1
associativity∼ : {w x y z : object} →
(f : ∥ hom ∥ y z) → (g : ∥ hom ∥ x y) → (h : ∥ hom ∥ w x) →
let open Setoid (hom w z) in comp (comp f g) h ∼ comp f (comp g h)
left-identity∼ : {x y : object} → (f : ∥ hom ∥ x y) →
let open Setoid (hom x y) in comp (identity y) f ∼ f
right-identity∼ : {x y : object} → (f : ∥ hom ∥ x y) →
let open Setoid (hom x y) in comp f (identity x) ∼ f
-- the type of objects in category C
ob : ∀ {a b c} → Cat a b c → Set a
ob C = Cat.object C
-- the type of morphisms between two given objects in C
_〈_,_〉 : ∀ {a b c} → (C : Cat a b c) → ob C → ob C → Set b
C 〈 X , Y 〉 = ∥ Cat.hom C ∥ X Y
-- the type of identities of morphisms
_∣_∼_ : ∀ {a b c} → (C : Cat a b c) → {X Y : ob C} →
C 〈 X , Y 〉 → C 〈 X , Y 〉 → Set c
_∣_∼_ C {X} {Y} f g = Setoid._∼_ (Cat.hom C X Y) f g
-- convenient abbreviation for identity morphism
idC : ∀ {a b c} → (C : Cat a b c) → (x : ob C) → C 〈 x , x 〉
idC C x = Cat.identity C x
-- convenient abbreviation for composition of morphisms
_∣_∘_ : ∀ {a b c} → (C : Cat a b c) → {x y z : ob C } →
C 〈 y , z 〉 → C 〈 x , y 〉 → C 〈 x , z 〉
C ∣ g ∘ f = Cat.comp C g f
------------------------------------------------------------------
-- Functors
record _=>_ {a b c a' b' c'} (C : Cat a b c) (D : Cat a' b' c') :
Set (a L.⊔ a' L.⊔ b L.⊔ b' L.⊔ c L.⊔ c') where
field
object : ob C → ob D
hom : {X Y : ob C} →
C 〈 X , Y 〉 → D 〈 object X , object Y 〉
hom∼ : {X Y : ob C} → (f g : C 〈 X , Y 〉) →
(f∼g : C ∣ f ∼ g) → D ∣ hom f ∼ hom g
identity∼ : {X : ob C} →
D ∣ hom (idC C X) ∼ idC D (object X)
comp∼ : {X Y Z : ob C} → (f : C 〈 Y , Z 〉) → (g : C 〈 X , Y 〉) →
D ∣ hom (C ∣ f ∘ g) ∼ (D ∣ hom f ∘ hom g)
-- Applying the functor to objects
_`_ : ∀ {a b c a' b' c'} {X : Cat a b c} → {Y : Cat a' b' c'} →
X => Y → ob X → ob Y
F ` x = _=>_.object F x
-- Applying the functor to morphisms
_``_ : ∀ {a b c a' b' c'} {X : Cat a b c} → {Y : Cat a' b' c'} →
{x0 x1 : ob X} → (F : X => Y) → X 〈 x0 , x1 〉 → Y 〈 F ` x0 , F ` x1 〉
F `` f = _=>_.hom F f
------------------------------------------------------------------
-- The category (FinSet,bijections)
-- M, N, L are finite sets witnessed by their sizes m, n, l
-- F, G, H are bijections
-- bijections between two sets M and N
record Bijection (m n : ℕ) : Set where
field
f : Fin m → Fin n
g : Fin n → Fin m
injective : {x y : Fin m} → f x ≡ f y → x ≡ y
surjective : {x : Fin n} → f (g x) ≡ x
-- there is a bijection from each set to itself
idBijection : (m : ℕ) → Bijection m m
idBijection m = record {
f = id ;
g = id ;
injective = id ;
surjective = λ {x} → refl x
}
-- composition of bijections
∘Bijection : {m n l : ℕ} → Bijection n l → Bijection m n → Bijection m l
∘Bijection G F = record {
f = Bijection.f G ○ Bijection.f F ;
g = Bijection.g F ○ Bijection.g G ;
injective = λ α → Bijection.injective F (Bijection.injective G α) ;
surjective = λ {x} →
Bijection.f G (Bijection.f F (Bijection.g F (Bijection.g G x)))
≡⟨ ap (λ x → Bijection.f G x) (Bijection.surjective F) ⟩
Bijection.f G (Bijection.g G x)
≡⟨ Bijection.surjective G ⟩
x ∎
}
-- two bijections are the "same" if they agree modulo ≡
∼Bijection : {m n : ℕ} → Bijection m n → Bijection m n → Set
∼Bijection F G = (Bijection.f F) E.∼ (Bijection.f G)
-- the set of all bijections between two sets M and N taken modulo ≡
BijectionSetoid : (m n : ℕ) → Setoid L.zero L.zero
BijectionSetoid m n = record {
object = Bijection m n ;
_∼_ = ∼Bijection ;
refl∼ = λ {F} → E.refl∼ {f = Bijection.f F} ;
sym∼ = λ {F} {G} →
E.sym∼ {f = Bijection.f F} {g = Bijection.f G} ;
trans∼ = λ {F} {G} {H} P Q →
E.trans∼ {f = Bijection.f F}
{g = Bijection.f G}
{h = Bijection.f H}
Q P
}
-- the category of finite sets and bijections
FinCat : Cat L.zero L.zero L.zero
FinCat = record {
object = ℕ ;
hom = BijectionSetoid ;
identity = idBijection ;
comp = λ G F → ∘Bijection G F ;
comp∼ = λ {m} {n} {l} {G₀} {G₁} {F₀} {F₁} Q P x →
Bijection.f (∘Bijection G₀ F₀) x
≡⟨ bydef ⟩
Bijection.f G₀ (Bijection.f F₀ x)
≡⟨ ap (λ z → Bijection.f G₀ z) (P x) ⟩
Bijection.f G₀ (Bijection.f F₁ x)
≡⟨ Q (Bijection.f F₁ x) ⟩
Bijection.f (∘Bijection G₁ F₁) x ∎ ;
associativity∼ = λ F G H x →
Bijection.f (∘Bijection F G) (Bijection.f H x)
≡⟨ bydef ⟩
Bijection.f F (Bijection.f G (Bijection.f H x)) ∎ ;
left-identity∼ = λ {m} {n} F x →
Bijection.f (idBijection n) (Bijection.f F x)
≡⟨ bydef ⟩
Bijection.f F x ∎ ;
right-identity∼ = λ {m} {n} F x →
Bijection.f F (Bijection.f (idBijection m) x)
≡⟨ bydef ⟩
Bijection.f F x ∎
}
------------------------------------------------------------------
-- The category (FinSet,HoTT-equivalence)
-- M, N, L are finite sets witnessed by their sizes m, n, l
-- F, G, H are equivalences
-- an equivalence (A ≃ B) consists of a function f : A → B
-- and a proof that it is an equivalence; the proof consists of
-- two functions g and h : B → A together with two proofs that
-- (f ○ g) ∼ id and (h ○ f) ∼ id
-- for now, I am suggesting that two such equivalences are the same
-- if the forward functions f are the same
∼Equiv : {m n : ℕ} → (Fin m E.≃ Fin n) → (Fin m E.≃ Fin n) → Set
∼Equiv F G = (proj₁ F) E.∼ (proj₁ G)
-- the set of all equivalences between two sets M and N taken modulo ≡
EquivSetoid : (m n : ℕ) → Setoid L.zero L.zero
EquivSetoid m n = record {
object = (Fin m) E.≃ (Fin n) ;
_∼_ = ∼Equiv ;
refl∼ = λ {F} → E.refl∼ {f = proj₁ F} ;
sym∼ = λ {F} {G} → E.sym∼ {f = proj₁ F} {g = proj₁ G} ;
trans∼ = λ {F} {G} {H} P Q →
E.trans∼ {f = proj₁ F} {g = proj₁ G} {h = proj₁ H} Q P
}
FinCat' : Cat L.zero L.zero L.zero
FinCat' = record {
object = ℕ ;
hom = EquivSetoid ;
identity = λ m → E.id≃ {A = Fin m} ;
comp = λ q p → E.trans≃ p q ;
comp∼ = λ {m} {n} {l} {G₀} {G₁} {F₀} {F₁} Q P x →
proj₁ (E.trans≃ F₀ G₀) x
≡⟨ bydef ⟩
proj₁ G₀ (proj₁ F₀ x)
≡⟨ ap (λ z → proj₁ G₀ z) (P x) ⟩
proj₁ G₀ (proj₁ F₁ x)
≡⟨ Q (proj₁ F₁ x) ⟩
proj₁ (E.trans≃ F₁ G₁) x ∎ ;
associativity∼ = λ F G H x → refl (proj₁ F (proj₁ G (proj₁ H x))) ;
left-identity∼ = λ {m} {n} F x → refl (proj₁ F x) ;
right-identity∼ = λ {m} {n} F x → refl (proj₁ F x)
}
------------------------------------------------------------------
-- The category (FT,path)
-- evaluation
evalF : {b₁ b₂ : FT} → (b₁ ⇛ b₂) → ⟦ b₁ ⟧ → ⟦ b₂ ⟧
evalF p = proj₁ (path2equiv p)
-- could equivalently use sym≃ on the result of path2equiv p
evalB : {b₁ b₂ : FT} → (b₁ ⇛ b₂) → ⟦ b₂ ⟧ → ⟦ b₁ ⟧
evalB p = proj₁ (path2equiv (sym⇛ p))
-- equivalence of combinators
_∼c_ : {b₁ b₂ : FT} → (c₁ c₂ : b₁ ⇛ b₂) → Set
_∼c_ {b₁} {b₂} c₁ c₂ = (v : ⟦ b₁ ⟧) → evalF c₁ v ≡ evalF c₂ v
-- equivalence class of paths between two types
paths : FT → FT → Setoid L.zero L.zero
paths b₁ b₂ = record {
object = b₁ ⇛ b₂ ;
_∼_ = _∼c_ ;
refl∼ = λ {c} v → refl (evalF c v) ;
sym∼ = λ p v → ! (p v) ;
trans∼ = λ q p v → (p v) ∘ (q v)
}
-- the category of finite types and paths
FTCat : Cat L.zero L.zero L.zero
FTCat = record {
object = FT ;
hom = paths ;
identity = λ b → id⇛ {b} ;
comp = λ c₂ c₁ → c₁ ◎ c₂ ;
comp∼ = λ {b₀} {b₁} {b₂} {c₂} {c₂'} {c₁} {c₁'} q p v →
evalF (c₁ ◎ c₂) v
≡⟨ bydef ⟩
evalF c₂ (evalF c₁ v)
≡⟨ ap (λ z → evalF c₂ z) (p v) ⟩
evalF c₂ (evalF c₁' v)
≡⟨ q (evalF c₁' v) ⟩
evalF (c₁' ◎ c₂') v ∎ ;
associativity∼ = λ r q p v →
evalF (p ◎ (q ◎ r)) v
≡⟨ bydef ⟩
evalF r (evalF q (evalF p v))
≡⟨ bydef ⟩
evalF ((p ◎ q) ◎ r) v ∎ ;
left-identity∼ = λ p v →
evalF id⇛ (evalF p v)
≡⟨ bydef ⟩
evalF p v ∎ ;
right-identity∼ = λ p v →
evalF p (evalF id⇛ v)
≡⟨ bydef ⟩
evalF p v ∎
}
------------------------------------------------------------------
{--
Two categories C and D are equivalent if we have:
- a functor F : C -> D
- a functor G : D -> C
- two natural isomorphisms ε : F ∘ G -> I_D and η : G ∘ F -> I_C
--}
ff : {m n : ℕ} → (Fin m E.≃ Fin n) → (fromℕ m ⇛ fromℕ n)
ff = {!!}
gg : {b₀ b₁ : FT} → (b₀ ⇛ b₁) → (Fin (suc (toℕ b₀)) E.≃ Fin (suc (toℕ b₁)))
gg = {!!}
-- functor from FinCat' to FTCat
fin2ft : FinCat' => FTCat
fin2ft = record {
object = fromℕ ; -- (Fin 1) should map to ZERO
hom = ff ; --
hom∼ = {!!} ;
identity∼ = {!!} ;
comp∼ = {!!}
}
-- functor from FTCat to FinCat'
ft2fin : FTCat => FinCat'
ft2fin = record {
object = λ b → suc (toℕ b) ; -- ZERO maps to (Fin 1)
hom = gg ;
hom∼ = {!!} ;
identity∼ = {!!} ;
comp∼ = {!!}
}
------------------------------------------------------------------
| {
"alphanum_fraction": 0.4708608703,
"avg_line_length": 33.8691860465,
"ext": "agda",
"hexsha": "aa8db0450d0afc46a18a9f31fd6fb0f6910355ce",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Obsolete/Cat.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/Cat.agda",
"max_line_length": 81,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Obsolete/Cat.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 4432,
"size": 11651
} |
module L.Data.Bool.Core where
open import L.Base.Coproduct.Core
open import L.Base.Unit.Core
-- Deriving the introduction rule as a special case of Coproducts.
Bool : Set
Bool = ⊤ + ⊤
ff : Bool
ff = inr ⋆
tt : Bool
tt = inl ⋆
-- And the elimination rule
if : ∀{c} (C : Bool → Set c)
→ C tt → C ff → (e : Bool) → C e
if = λ C c d e → case C (λ _ → c) (λ _ → d) e
| {
"alphanum_fraction": 0.6075268817,
"avg_line_length": 18.6,
"ext": "agda",
"hexsha": "9f19db4c48413362fba4a5ea56be925ae1679016",
"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": "83707537b182ba8906228ac0bcb9ccef972eaaa3",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "borszag/smallib",
"max_forks_repo_path": "src/L/Data/Bool/Core.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "83707537b182ba8906228ac0bcb9ccef972eaaa3",
"max_issues_repo_issues_event_max_datetime": "2020-11-09T16:40:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-19T10:13:16.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "borszag/smallib",
"max_issues_repo_path": "src/L/Data/Bool/Core.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "83707537b182ba8906228ac0bcb9ccef972eaaa3",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "borszag/smallib",
"max_stars_repo_path": "src/L/Data/Bool/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 136,
"size": 372
} |
{-# OPTIONS --cubical #-}
module HyperFalse where
open import Prelude hiding (false)
{-# NO_POSITIVITY_CHECK #-}
record _↬_ (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where
inductive; constructor hyp
field invoke : (B ↬ A) → B
open _↬_
yes? : ⊥ ↬ ⊥
yes? .invoke h = h .invoke h
no! : (⊥ ↬ ⊥) → ⊥
no! h = h .invoke h
boom : ⊥
boom = no! yes?
| {
"alphanum_fraction": 0.5811965812,
"avg_line_length": 15.9545454545,
"ext": "agda",
"hexsha": "4e692057e67da953b174b08c146f63d2beb95885",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "HyperFalse.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"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/agda-playground",
"max_issues_repo_path": "HyperFalse.agda",
"max_line_length": 58,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "HyperFalse.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 138,
"size": 351
} |
-- Andreas, 2016-04-14 issue 1796 for rewrite
-- {-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.size.solve:100 #-}
-- {-# OPTIONS -v tc.with.abstract:40 #-}
open import Common.Size
open import Common.Equality
data Either (A B : Set) : Set where
left : A → Either A B
right : B → Either A B
either : {A B : Set} → Either A B →
∀{C : Set} → (A → C) → (B → C) → C
either (left a) l r = l a
either (right b) l r = r b
data Nat : Size → Set where
zero : ∀{i} → Nat (↑ i)
suc : ∀{i} → Nat i → Nat (↑ i)
primrec : ∀{ℓ} (C : Size → Set ℓ)
→ (z : ∀{i} → C i)
→ (s : ∀{i} → Nat i → C i → C (↑ i))
→ ∀{i} → Nat i → C i
primrec C z s zero = z
primrec C z s (suc n) = s n (primrec C z s n)
case : ∀{i} → Nat i
→ ∀{ℓ} (C : Size → Set ℓ)
→ (z : ∀{i} → C i)
→ (s : ∀{i} → Nat i → C (↑ i))
→ C i
case n C z s = primrec C z (λ n r → s n) n
diff : ∀{i} → Nat i → ∀{j} → Nat j → Either (Nat i) (Nat j)
diff = primrec (λ i → ∀{j} → Nat j → Either (Nat i) (Nat j))
-- case zero: the second number is bigger and the difference
right
-- case suc n:
(λ{i} n r m → case m (λ j → Either (Nat (↑ i)) (Nat j))
-- subcase zero: the first number (suc n) is bigger and the difference
(left (suc n))
-- subcase suc m: recurse on (n,m)
r)
gcd : ∀{i} → Nat i → ∀{j} → Nat j → Nat ∞
gcd zero m = m
gcd (suc n) zero = suc n
gcd (suc n) (suc m) = either (diff n m)
(λ n' → gcd n' (suc m))
(λ m' → gcd (suc n) m')
er : ∀{i} → Nat i → Nat ∞
er zero = zero
er (suc n) = suc (er n)
diff-diag-erase : ∀{i} (n : Nat i) → diff (er n) (er n) ≡ right zero
diff-diag-erase zero = refl
diff-diag-erase (suc n) = diff-diag-erase n
gcd-diag-erase : ∀{i} (n : Nat i) → gcd (er n) (er n) ≡ er n
gcd-diag-erase zero = refl
gcd-diag-erase (suc {i} n)
rewrite diff-diag-erase n
-- Before fix: diff-diag-erase {i} n.
-- The {i} was necessary, otherwise rewrite failed
-- because an unsolved size var prevented abstraction.
| gcd-diag-erase n = refl
| {
"alphanum_fraction": 0.5272459499,
"avg_line_length": 28.6901408451,
"ext": "agda",
"hexsha": "26ac18da18f3a93352e45c88e551cb5fe78c41b2",
"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/Issue1796rewrite.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/Issue1796rewrite.agda",
"max_line_length": 74,
"max_stars_count": 3,
"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/Issue1796rewrite.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": 800,
"size": 2037
} |
{-# OPTIONS --universe-polymorphism #-}
module Imports.Test where
open import Imports.Level
record Foo (ℓ : Level) : Set ℓ where
| {
"alphanum_fraction": 0.7196969697,
"avg_line_length": 16.5,
"ext": "agda",
"hexsha": "2ba90f54078fa0414a25950e5d2526311e8341d8",
"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/Imports/Test.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/Imports/Test.agda",
"max_line_length": 39,
"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/Imports/Test.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": 33,
"size": 132
} |
open import Agda.Builtin.Equality using (_≡_)
open import Agda.Builtin.Sigma using (Σ; _,_)
postulate
F : Set → Set₁
P : (A : Set) → F A → Set
easy : {A : Set₁} → A
A : Set₁
A = Σ Set λ B → Σ (F B) (P B)
f : (X Y : A) → X ≡ Y
f (C , x , p) (D , y , q) = proof
module _ where
abstract
proof : (C , x , p) ≡ (D , y , q)
proof = easy
| {
"alphanum_fraction": 0.5069637883,
"avg_line_length": 18.8947368421,
"ext": "agda",
"hexsha": "6a49958233fe9d2b10e216c548d66853dc9143bf",
"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/Issue4005.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/Issue4005.agda",
"max_line_length": 45,
"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/Issue4005.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": 155,
"size": 359
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Equivalence where
open import Level
open import Categories.Adjoint
open import Categories.Category
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Properties
open import Categories.NaturalTransformation.NaturalIsomorphism as ≃ using (_≃_; NaturalIsomorphism)
open import Categories.NaturalTransformation.NaturalIsomorphism.Properties
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
C D E : Category o ℓ e
record ⊣Equivalence (L : Functor C D) (R : Functor D C) : Set (levelOfTerm L ⊔ levelOfTerm R) where
field
unit : idF ≃ (R ∘F L)
counit : (L ∘F R) ≃ idF
module unit = NaturalIsomorphism unit
module counit = NaturalIsomorphism counit
private
module C = Category C
module D = Category D
module L = Functor L
module R = Functor R
module ℱ = Functor
field
zig : ∀ {A : C.Obj} → counit.⇒.η (L.F₀ A) D.∘ L.F₁ (unit.⇒.η A) D.≈ D.id
zag : ∀ {B : D.Obj} → R.F₁ (counit.⇒.η B) C.∘ unit.⇒.η (R.F₀ B) C.≈ C.id
zag {B} = F≃id⇒id (≃.sym unit) helper
where open C
open HomReasoning
helper : R.F₁ (L.F₁ (R.F₁ (counit.⇒.η B) ∘ unit.⇒.η (R.F₀ B))) ≈ id
helper = begin
R.F₁ (L.F₁ (R.F₁ (counit.⇒.η B) ∘ unit.⇒.η (R.F₀ B))) ≈⟨ ℱ.homomorphism (R ∘F L) ⟩
R.F₁ (L.F₁ (R.F₁ (counit.⇒.η B))) ∘ R.F₁ (L.F₁ (unit.⇒.η (R.F₀ B))) ≈˘⟨ R.F-resp-≈ (F≃id-comm₁ counit) ⟩∘⟨refl ⟩
R.F₁ (counit.⇒.η (L.F₀ (R.F₀ B))) ∘ R.F₁ (L.F₁ (unit.⇒.η (R.F₀ B))) ≈˘⟨ R.homomorphism ⟩
R.F₁ (counit.⇒.η (L.F₀ (R.F₀ B)) D.∘ L.F₁ (unit.⇒.η (R.F₀ B))) ≈⟨ R.F-resp-≈ zig ⟩
R.F₁ D.id ≈⟨ R.identity ⟩
id ∎
L⊣R : L ⊣ R
L⊣R = record
{ unit = unit.F⇒G
; counit = counit.F⇒G
; zig = zig
; zag = zag
}
module L⊣R = Adjoint L⊣R
open L⊣R hiding (unit; counit; zig; zag) public
R⊣L : R ⊣ L
R⊣L = record
{ unit = counit.F⇐G
; counit = unit.F⇐G
; zig = λ {X} →
let open C.HomReasoning
open MR C
in begin
unit.⇐.η (R.F₀ X) C.∘ R.F₁ (counit.⇐.η X)
≈˘⟨ elimʳ zag ⟩
(unit.⇐.η (R.F₀ X) C.∘ R.F₁ (counit.⇐.η X)) C.∘ (R.F₁ (counit.⇒.η X) C.∘ unit.⇒.η (R.F₀ X))
≈⟨ center ([ R ]-resp-∘ (counit.iso.isoˡ _) ○ R.identity) ⟩
unit.⇐.η (R.F₀ X) C.∘ C.id C.∘ unit.⇒.η (R.F₀ X)
≈⟨ refl⟩∘⟨ C.identityˡ ⟩
unit.⇐.η (R.F₀ X) C.∘ unit.⇒.η (R.F₀ X)
≈⟨ unit.iso.isoˡ _ ⟩
C.id
∎
; zag = λ {X} →
let open D.HomReasoning
open MR D
in begin
L.F₁ (unit.⇐.η X) D.∘ counit.⇐.η (L.F₀ X)
≈˘⟨ elimʳ zig ⟩
(L.F₁ (unit.⇐.η X) D.∘ counit.⇐.η (L.F₀ X)) D.∘ counit.⇒.η (L.F₀ X) D.∘ L.F₁ (unit.⇒.η X)
≈⟨ center (counit.iso.isoˡ _) ⟩
L.F₁ (unit.⇐.η X) D.∘ D.id D.∘ L.F₁ (unit.⇒.η X)
≈⟨ refl⟩∘⟨ D.identityˡ ⟩
L.F₁ (unit.⇐.η X) D.∘ L.F₁ (unit.⇒.η X)
≈⟨ ([ L ]-resp-∘ (unit.iso.isoˡ _)) ○ L.identity ⟩
D.id
∎
}
module R⊣L = Adjoint R⊣L
| {
"alphanum_fraction": 0.4990814452,
"avg_line_length": 33.6701030928,
"ext": "agda",
"hexsha": "76ec79068b5302911a1db7212615d3569009e0ba",
"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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Adjoint/Equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"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": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Adjoint/Equivalence.agda",
"max_line_length": 124,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Adjoint/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1453,
"size": 3266
} |
open import Relation.Binary.Core
module InsertSort.Everything {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import InsertSort.Impl1.Correctness.Order _≤_ tot≤
open import InsertSort.Impl1.Correctness.Permutation.Alternative _≤_ tot≤
open import InsertSort.Impl1.Correctness.Permutation.Base _≤_ tot≤
open import InsertSort.Impl2.Correctness.Order _≤_ tot≤
open import InsertSort.Impl2.Correctness.Permutation.Alternative _≤_ tot≤
open import InsertSort.Impl2.Correctness.Permutation.Base _≤_ tot≤
| {
"alphanum_fraction": 0.7441016334,
"avg_line_length": 39.3571428571,
"ext": "agda",
"hexsha": "c9f2a3618addcdcf166df3d6091175b270d36f56",
"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/InsertSort/Everything.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/InsertSort/Everything.agda",
"max_line_length": 73,
"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/InsertSort/Everything.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": 173,
"size": 551
} |
import cedille-options
module to-string (options : cedille-options.options) where
open import cedille-types
open import constants
open import syntax-util
open import ctxt
open import rename
open import general-util
open import datatype-util
open import type-util
open import free-vars
open import json
data expr-side : Set where
left : expr-side
right : expr-side
neither : expr-side
is-left : expr-side → 𝔹
is-left left = tt
is-left _ = ff
is-right : expr-side → 𝔹
is-right right = tt
is-right _ = ff
exprd-eq : exprd → exprd → 𝔹
exprd-eq TERM TERM = tt
exprd-eq TYPE TYPE = tt
exprd-eq KIND KIND = tt
exprd-eq _ _ = ff
is-eq-op : {ed : exprd} → ⟦ ed ⟧ → 𝔹
is-eq-op{TERM} (VarSigma _) = tt
is-eq-op{TERM} (Rho _ _ _ _) = tt
is-eq-op{TERM} (Phi _ _ _) = tt
is-eq-op{TERM} (Delta _ _ _) = tt
is-eq-op _ = ff
pattern arrow-var = "_arrow_"
pattern TpArrow tp me tp' = TpAbs me arrow-var (Tkt tp) tp'
pattern KdArrow tk kd = KdAbs arrow-var tk kd
is-arrow : {ed : exprd} → ⟦ ed ⟧ → 𝔹
is-arrow {TYPE} (TpArrow _ _ _) = tt
is-arrow {KIND} (KdArrow _ _) = tt
is-arrow _ = ff
is-type-level-app : ∀ {ed} → ⟦ ed ⟧ → 𝔹
is-type-level-app {TYPE} (TpApp T tT) = tt
is-type-level-app _ = ff
{- need-parens e1 e2 s
returns tt iff we need parens when e1 occurs as the given
side s of parent expression e2. -}
need-parens : {ed : exprd} → {ed' : exprd} → ⟦ ed ⟧ → ⟦ ed' ⟧ → expr-side → 𝔹
need-parens {TYPE} {TYPE} (TpAbs _ _ _ _) (TpArrow _ _ _) left = tt
need-parens {TYPE} {TYPE} (TpIota _ _ _) (TpArrow _ _ _) left = tt
need-parens {KIND} {KIND} (KdAbs _ _ _) (KdArrow _ _) left = tt
need-parens {TYPE} {KIND} (TpAbs _ _ _ _) (KdArrow _ _) left = tt
need-parens {TYPE} {KIND} (TpIota _ _ _) (KdArrow _ _) left = tt
need-parens {TERM} {_} (Var x) p lr = ff
need-parens {TERM} {_} (Hole pi) p lr = ff
need-parens {TERM} {_} (IotaPair t₁ t₂ x Tₓ) p lr = ff
need-parens {TERM} {_} (IotaProj t n) p lr = ff
need-parens {TYPE} {_} (TpVar x) p lr = ff
need-parens {TYPE} {_} (TpEq t₁ t₂) p lr = ff
need-parens {TYPE} {_} (TpHole pi) p lr = ff
need-parens {KIND} {_} (KdHole pi) p lr = ff
need-parens {KIND} {_} KdStar p lr = ff
need-parens {_} {TERM} _ (IotaPair t₁ t₂ x Tₓ) lr = ff
need-parens {_} {TYPE} _ (TpEq t₁ t₂) lr = ff
need-parens {_} {TERM} _ (Beta ot ot') lr = ff
need-parens {_} {TERM} _ (Phi tₑ t₁ t₂) lr = is-left lr
need-parens {_} {TERM} _ (Rho _ _ _ _) right = ff
need-parens {_} {TERM} _ (Delta _ _ _) right = ff
need-parens {_} {TERM} _ (LetTm _ _ _ _ _) lr = ff
need-parens {_} {TERM} _ (LetTp _ _ _ _) lr = ff
need-parens {_} {TERM} _ (Lam _ _ _ _) lr = ff
need-parens {_} {TERM} _ (Mu _ _ _ _ _) right = ff
need-parens {_} {TYPE} _ (TpLam _ _ _) lr = ff
need-parens {_} {TYPE} _ (TpAbs _ _ _ _) lr = ff
need-parens {_} {KIND} _ (KdAbs _ _ _) neither = ff
need-parens {_} {TYPE} _ (TpIota _ _ _) lr = ff
need-parens {TERM} {_} (App t t') p lr = tt
need-parens {TERM} {_} (AppE t tT) p lr = tt
need-parens {TERM} {_} (Beta ot ot') p lr = ff
need-parens {TERM} {_} (Delta _ T t) p lr = tt
need-parens {TERM} {_} (Lam me x tk? t) p lr = tt
need-parens {TERM} {_} (LetTm me x T t t') p lr = tt
need-parens {TERM} {_} (LetTp x T t t') p lr = tt
need-parens {TERM} {_} (Phi tₑ t₁ t₂) p lr = tt
need-parens {TERM} {_} (Rho tₑ x Tₓ t) p lr = tt
need-parens {TERM} {_} (VarSigma t) p lr = ~ is-eq-op p
need-parens {TERM} {_} (Mu _ _ _ _ _) p lr = tt
need-parens {TERM} {_} (Sigma _ _ _ _ _) p lr = tt
need-parens {TYPE} {e} (TpAbs me x tk T) p lr = ~ exprd-eq e TYPE || ~ is-arrow p || is-left lr
need-parens {TYPE} {_} (TpIota x T₁ T₂) p lr = tt
need-parens {TYPE} {_} (TpApp T tT) p lr = ~ is-arrow p && (~ is-type-level-app p || is-right lr)
need-parens {TYPE} {_} (TpLam x tk T) p lr = tt
need-parens {KIND} {_} (KdAbs x tk k) p lr = ~ is-arrow p || is-left lr
pattern ced-ops-drop-spine = cedille-options.options.mk-options _ _ _ _ ff _ _ _ ff _ _
pattern ced-ops-conv-arr = cedille-options.options.mk-options _ _ _ _ _ _ _ _ ff _ _
pattern ced-ops-conv-abs = cedille-options.options.mk-options _ _ _ _ _ _ _ _ tt _ _
drop-spine : cedille-options.options → {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
drop-spine ops @ ced-ops-drop-spine = h
where
drop-mod-argse : (mod : args) → (actual : args) → args
drop-mod-argse (ArgE _ :: asₘ) (ArgE _ :: asₐ) = drop-mod-argse asₘ asₐ
drop-mod-argse (Arg _ :: asₘ) (Arg t :: asₐ) = drop-mod-argse asₘ asₐ
drop-mod-argse (_ :: asₘ) asₐ@(Arg t :: _) = drop-mod-argse asₘ asₐ
-- ^ Relevant term arg, so wait until we find its corresponding relevant module arg ^
drop-mod-argse _ asₐ = asₐ
drop-mod-args-term : ctxt → var × args → term
drop-mod-args-term Γ (v , as) =
let uqv = unqual-all (ctxt.qual Γ) v in
flip recompose-apps (Var uqv) $
maybe-else' (ifMaybe (~ v =string uqv) $ ctxt-get-qi Γ uqv)
as λ qi → drop-mod-argse (snd qi) as
drop-mod-args-type : ctxt → var × 𝕃 tmtp → type
drop-mod-args-type Γ (v , as) =
let uqv = unqual-all (ctxt.qual Γ) v in
flip recompose-tpapps (TpVar uqv) $
maybe-else' (ifMaybe (~ v =string uqv) $ ctxt-qualif-args-length Γ Erased uqv)
as λ n → drop n as
h : {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
h {TERM} Γ t = maybe-else' (decompose-var-headed t) t (drop-mod-args-term Γ)
h {TYPE} Γ T = maybe-else' (decompose-tpvar-headed T) T (drop-mod-args-type Γ)
h Γ x = x
drop-spine ops Γ x = x
to-string-rewrite : {ed : exprd} → ctxt → cedille-options.options → ⟦ ed ⟧ → Σi exprd ⟦_⟧
to-string-rewrite{TYPE} Γ ced-ops-conv-arr (TpAbs me x (Tkt T) T') = , TpAbs me (if is-free-in x T' then x else arrow-var) (Tkt T) T'
to-string-rewrite{KIND} Γ ced-ops-conv-arr (KdAbs x tk k) = , KdAbs (if is-free-in x k then x else arrow-var) tk k
to-string-rewrite{TERM} Γ ops (VarSigma t) with to-string-rewrite Γ ops t
...| ,_ {TERM} (VarSigma t') = , t'
...| t? = , VarSigma t
to-string-rewrite Γ ops x = , drop-spine ops Γ x
-------------------------------
open import pretty
use-newlines : 𝔹
use-newlines =
~ iszero (cedille-options.options.pretty-print-columns options)
&& cedille-options.options.pretty-print options
doc-to-rope : DOC → rope
doc-to-rope = if use-newlines
then pretty (cedille-options.options.pretty-print-columns options)
else flatten-out
strM : Set
strM = {ed : exprd} → DOC → ℕ → 𝕃 tag → ctxt → maybe ⟦ ed ⟧ → expr-side → DOC × ℕ × 𝕃 tag
strEmpty : strM
strEmpty s n ts Γ pe lr = s , n , ts
to-stringh : {ed : exprd} → ⟦ ed ⟧ → strM
strM-Γ : (ctxt → strM) → strM
strM-Γ f s n ts Γ = f Γ s n ts Γ
infixr 2 _>>str_
_>>str_ : strM → strM → strM
(m >>str m') s n ts Γ pe lr with m s n ts Γ pe lr
(m >>str m') s n ts Γ pe lr | s' , n' , ts' = m' s' n' ts' Γ pe lr
strAdd : string → strM
strAdd s s' n ts Γ pe lr = s' <> TEXT [[ s ]] , n + string-length s , ts
strLine : strM
strLine s n ts Γ pe lr = s <> LINE , suc n , ts
strNest : ℕ → strM → strM
strNest i m s n ts Γ pe lr with m nil n ts Γ pe lr
...| s' , n' , ts' = s <> nest i s' , n' , ts'
strFold' : (ℕ → ℕ) → {ed : exprd} → 𝕃 (ℕ × strM) → ℕ → 𝕃 tag → ctxt → maybe ⟦ ed ⟧ → expr-side → 𝕃 (ℕ × DOC) × ℕ × 𝕃 tag
strFold' l [] n ts Γ pe lr = [] , n , ts
strFold' l ((i , x) :: []) n ts Γ pe lr with x nil n ts Γ pe lr
...| sₓ , nₓ , tsₓ = [ i , sₓ ] , nₓ , tsₓ
strFold' l ((i , x) :: xs) n ts Γ pe lr with x nil n ts Γ pe lr
...| sₓ , nₓ , tsₓ with strFold' l xs (l nₓ) tsₓ Γ pe lr
...| sₓₛ , nₓₛ , tsₓₛ = (i , sₓ) :: sₓₛ , nₓₛ , tsₓₛ
strFold : (ℕ → ℕ) → (𝕃 (ℕ × DOC) → DOC) → 𝕃 (ℕ × strM) → strM
strFold l f ms s n ts Γ pe lr with strFold' l ms n ts Γ pe lr
...| s' , n' , ts' = s <> f s' , n' , ts'
strFoldi : ℕ → (ℕ → ℕ) → (𝕃 DOC → DOC) → 𝕃 strM → strM
strFoldi i l f = strNest i ∘' strFold suc (f ∘' map snd) ∘' map (_,_ 0)
-- Either fit all args on one line, or give each their own line
strList : ℕ → 𝕃 strM → strM
strList i = strFoldi i suc λ ms → flatten (spread ms) :<|> stack ms
-- Fit as many args on each line as possible
-- (n = number of strM args)
-- (𝕃 strM so that optional args (nil) are possible)
strBreak : (n : ℕ) → fold n strM λ X → ℕ → 𝕃 strM → X
strBreak = h [] where
h : 𝕃 (ℕ × strM) → (n : ℕ) → fold n strM λ X → ℕ → 𝕃 strM → X
h ms (suc n) i m = h (map (_,_ i) m ++ ms) n
h ms zero = strFold suc filln $ reverse ms
strBracket : char → strM → char → strM
strBracket l m r s n ts Γ pe lr with m nil (suc (suc n)) ts Γ pe lr
...| s' , n' , ts' = s <> bracket (char-to-string l) s' (char-to-string r) , suc (suc n') , ts'
strΓ' : defScope → var → strM → strM
strΓ' ds v m s n ts Γ =
let gl = ds iff globalScope
v' = if gl then (ctxt.mn Γ # v) else v in
m s n ts
(record Γ {
qual = qualif-insert-params (ctxt.qual Γ) v' (unqual-local v) (if gl then ctxt.ps Γ else []);
i = trie-insert (ctxt.i Γ) v' (var-decl , missing-location)
})
strΓ : var → strM → strM
strΓ x m s n ts Γ = m s n ts (ctxt-var-decl x Γ)
ctxt-get-file-id : ctxt → (filename : string) → ℕ
ctxt-get-file-id = trie-lookup-else 0 ∘ ctxt.id-map
make-loc-tag : ctxt → (filename start-to end-to : string) → (start-from end-from : ℕ) → tag
make-loc-tag Γ fn s e = make-tag "loc"
(("fn" , json-nat (ctxt-get-file-id Γ fn)) ::
("s" , json-raw [[ s ]]) :: ("e" , json-raw [[ e ]]) :: [])
var-loc-tag : ctxt → location → var → 𝕃 (string × 𝕃 tag)
var-loc-tag Γ ("missing" , "missing") x = []
var-loc-tag Γ ("" , _) x = []
var-loc-tag Γ (_ , "") x = []
var-loc-tag Γ (fn , pi) x =
let fn-tag = "fn" , json-nat (ctxt-get-file-id Γ fn)
s-tag = "s" , json-raw [[ pi ]]
e-tag = "e" , json-raw [[ posinfo-plus-str pi x ]] in
[ "loc" , fn-tag :: s-tag :: e-tag :: [] ]
var-tags : ctxt → var → var → 𝕃 (string × 𝕃 tag)
var-tags Γ qv uqv =
(if qv =string qualif-var Γ uqv then id else ("shadowed" , []) ::_)
(var-loc-tag Γ (ctxt-var-location Γ qv) uqv)
strAddTags : string → 𝕃 (string × 𝕃 tag) → strM
strAddTags sₙ tsₙ sₒ n tsₒ Γ pe lr =
let n' = n + string-length sₙ in
sₒ <> TEXT [[ sₙ ]] , n' , map (uncurry λ k vs → make-tag k vs n n') tsₙ ++ tsₒ
strVar : var → strM
strVar v = strM-Γ λ Γ →
let uqv = unqual-local v -- $ unqual-all (ctxt-get-qualif Γ) v
uqv' = if cedille-options.options.show-qualified-vars options then v else uqv in
strAddTags uqv' (var-tags Γ (qualif-var Γ v) uqv)
strKvar : var → strM
strKvar v = strM-Γ λ Γ → strVar (unqual-all (ctxt.qual Γ) v)
-- Only necessary to unqual-local because of module parameters
strBvar : var → (class body : strM) → strM
strBvar v cm bm = strAdd (unqual-local v) >>str cm >>str strΓ' localScope v bm
strMetaVar : var → span-location → strM
strMetaVar x (fn , pi , pi') s n ts Γ pe lr =
let n' = n + string-length x in
s <> TEXT [[ x ]] , n' , make-loc-tag Γ fn pi pi' n n' :: ts
{-# TERMINATING #-}
term-to-stringh : term → strM
type-to-stringh : type → strM
kind-to-stringh : kind → strM
ctr-to-string : ctr → strM
case-to-string : case → strM
cases-to-string : cases → strM
caseArgs-to-string : case-args → strM → strM
params-to-string : params → strM
params-to-string' : strM → params → strM
params-to-string'' : params → strM → strM
optTerm-to-string : maybe term → char → char → 𝕃 strM
optClass-to-string : maybe tpkd → strM
optType-to-string : maybe char → maybe type → 𝕃 strM
arg-to-string : arg → strM
args-to-string : args → strM
binder-to-string : erased? → string
lam-to-string : erased? → string
arrowtype-to-string : erased? → string
vars-to-string : 𝕃 var → strM
bracketL : erased? → string
bracketR : erased? → string
braceL : erased? → string
braceR : erased? → string
opacity-to-string : opacity → string
hole-to-string : posinfo → strM
to-string-ed : {ed : exprd} → ⟦ ed ⟧ → strM
to-string-ed{TERM} = term-to-stringh
to-string-ed{TYPE} = type-to-stringh
to-string-ed{KIND} = kind-to-stringh
to-stringh' : {ed : exprd} → expr-side → ⟦ ed ⟧ → strM
to-stringh' {ed} lr t {ed'} s n ts Γ mp lr' =
elim-Σi (to-string-rewrite Γ options t) λ t' →
parens-if (maybe𝔹 mp (λ pe → need-parens t' pe lr)) (to-string-ed t') s n ts Γ (just t') lr
where
parens-if : 𝔹 → strM → strM
parens-if p s = if p then (strAdd "(" >>str strNest 1 s >>str strAdd ")") else s
to-stringl : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringr : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringl = to-stringh' left
to-stringr = to-stringh' right
to-stringh = to-stringh' neither
set-parent : ∀ {ed} → ⟦ ed ⟧ → strM → strM
set-parent t m s n ts Γ _ lr = m s n ts Γ (just t) lr
apps-to-string : ∀ {ll : 𝔹} → (if ll then term else type) → strM
apps-to-string {tt} t with decompose-apps t
...| tₕ , as = set-parent t $ strList 2
(to-stringl tₕ :: map arg-to-string as)
apps-to-string {ff} T with decompose-tpapps T
...| Tₕ , as = set-parent T $ strList 2
(to-stringl Tₕ :: map arg-to-string (tmtps-to-args ff as))
lams-to-string : term → strM
lams-to-string t =
elim-pair (decompose-lams-pretty t) λ xs b →
set-parent t $ strFold suc filln $ foldr {B = 𝕃 (ℕ × strM)}
(λ {(x , me , oc) r →
(1 , (strAdd (lam-to-string me) >>str strAdd " " >>str
strBvar x (strNest 4 (optClass-to-string oc)) (strAdd " ."))) ::
map (map-snd $ strΓ' localScope x) r}) [ 2 , to-stringr b ] xs
where
decompose-lams-pretty : term → 𝕃 (var × erased? × maybe tpkd) × term
decompose-lams-pretty = h [] where
h : 𝕃 (var × erased? × maybe tpkd) → term → 𝕃 (var × erased? × maybe tpkd) × term
h acc (Lam me x oc t) = h ((x , me , oc) :: acc) t
h acc t = reverse acc , t
term-to-stringh (App t t') = apps-to-string (App t t')
term-to-stringh (AppE t tT) = apps-to-string (AppE t tT)
term-to-stringh (Beta t t') = strBreak 3
0 [ strAdd "β" ]
2 [ strAdd "<" >>str to-stringh (erase t ) >>str strAdd ">" ]
2 [ strAdd "{" >>str to-stringh (erase t') >>str strAdd "}" ]
term-to-stringh (Delta _ T t) = strBreak 3
0 [ strAdd "δ" ]
2 [ to-stringl T >>str strAdd " -" ]
1 [ to-stringr t ]
term-to-stringh (Hole pi) = hole-to-string pi
term-to-stringh (IotaPair t₁ t₂ x Tₓ) = strBreak 3
1 [ strAdd "[ " >>str to-stringh t₁ >>str strAdd "," ]
1 [ to-stringh t₂ ]
1 [ strAdd "@ " >>str
strBvar x (strAdd " . ") (strNest (5 + string-length x) (to-stringh Tₓ)) >>str
strAdd " ]" ]
term-to-stringh (IotaProj t n) = to-stringh t >>str strAdd (if n iff ι1 then ".1" else ".2")
term-to-stringh (Lam me x oc t) = lams-to-string (Lam me x oc t)
term-to-stringh (LetTm me x T t t') = strBreak 4
1 [ strAdd (bracketL me) >>str strAdd (unqual-local x) ]
5 ( optType-to-string (just ':') T )
3 [ strAdd "= " >>str to-stringh t >>str strAdd (bracketR me) ]
1 [ strΓ' localScope x (to-stringr t') ]
term-to-stringh (LetTp x k T t) = strBreak 4
1 [ strAdd (bracketL NotErased) >>str strAdd (unqual-local x) ]
5 [ strAdd ": " >>str to-stringh k ]
3 [ strAdd "= " >>str to-stringh T >>str strAdd (bracketR NotErased) ]
1 [ strΓ' localScope x (to-stringr t) ]
term-to-stringh (Phi tₑ t₁ t₂) = strBreak 3
0 [ strAdd "φ " >>str to-stringl tₑ >>str strAdd " -" ]
2 [ to-stringh t₁ ]
2 [ strAdd "{ " >>str to-stringr (erase t₂) >>str strAdd " }" ]
term-to-stringh (Rho tₑ x Tₓ t) = strBreak 3
0 [ strAdd "ρ " >>str to-stringl tₑ ]
1 [ strAdd "@ " >>str strBvar x (strAdd " . ") (to-stringh (erase Tₓ)) ]
1 [ strAdd "- " >>str strNest 2 (to-stringr t) ]
term-to-stringh (VarSigma t) = strAdd "ς " >>str to-stringh t
term-to-stringh (Var x) = strVar x
term-to-stringh (Mu x t ot t~ cs) =
strAdd "μ " >>str
strBvar x
(strAdd " . " >>str strBreak 2
2 [ to-stringl t ]
3 ( optType-to-string (just '@') ot ))
(strAdd " " >>str strBracket '{' (cases-to-string cs) '}')
term-to-stringh (Sigma ot t oT t~ cs) =
strAdd "σ " >>str strBreak 3
2 (maybe-else' {B = 𝕃 strM} ot []
λ t → [ strAdd "<" >>str to-stringh t >>str strAdd ">" ])
2 [ to-stringl t ]
3 ( optType-to-string (just '@') oT ) >>str
strAdd " " >>str strBracket '{' (cases-to-string cs) '}'
type-to-stringh (TpArrow T a T') = strBreak 2
2 [ to-stringl T >>str strAdd (arrowtype-to-string a) ]
2 [ to-stringr T' ]
type-to-stringh (TpAbs me x tk T) = strBreak 2
3 [ strAdd (binder-to-string me ^ " ") >>str
strBvar x (strAdd " : " >>str to-stringl -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringh T) ]
type-to-stringh (TpIota x T₁ T₂) = strBreak 2
2 [ strAdd "ι " >>str
strBvar x (strAdd " : " >>str to-stringh T₁ >>str strAdd " .") strEmpty ]
2 [ strΓ' localScope x (to-stringh T₂) ]
type-to-stringh (TpApp T tT) = apps-to-string (TpApp T tT)
type-to-stringh (TpEq t₁ t₂) = strBreak 2
2 [ strAdd "{ " >>str to-stringh (erase t₁) ]
2 [ strAdd "≃ " >>str to-stringh (erase t₂) >>str strAdd " }" ]
type-to-stringh (TpHole pi) = hole-to-string pi
type-to-stringh (TpLam x tk T) = strBreak 2
3 [ strAdd "λ " >>str
strBvar x (strAdd " : " >>str to-stringh -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringr T) ]
type-to-stringh (TpVar x) = strVar x
kind-to-stringh (KdArrow k k') = strBreak 2
2 [ to-stringl -tk' k >>str strAdd " ➔" ]
2 [ to-stringr k' ]
kind-to-stringh (KdAbs x tk k) = strBreak 2
4 [ strAdd "Π " >>str
strBvar x (strAdd " : " >>str to-stringl -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringh k) ]
kind-to-stringh (KdHole pi) = hole-to-string pi
kind-to-stringh KdStar = strAdd "★"
hole-to-string pi = strM-Γ λ Γ → strAddTags "●" (var-loc-tag Γ (split-var pi) "●")
optTerm-to-string nothing c1 c2 = []
optTerm-to-string (just t) c1 c2 =
[ strAdd (𝕃char-to-string (c1 :: [ ' ' ])) >>str
to-stringh t >>str
strAdd (𝕃char-to-string (' ' :: [ c2 ])) ]
optClass-to-string nothing = strEmpty
optClass-to-string (just atk) = strAdd " : " >>str to-stringh -tk' atk
optType-to-string pfx nothing = []
optType-to-string pfx (just T) =
[ maybe-else strEmpty (λ pfx → strAdd (𝕃char-to-string (pfx :: [ ' ' ]))) pfx >>str to-stringh T ]
arg-to-string (Arg t) = to-stringr t
arg-to-string (ArgE (Ttm t)) = strAdd "-" >>str strNest 1 (to-stringr t)
arg-to-string (ArgE (Ttp T)) = strAdd "·" >>str strNest 2 (to-stringr T)
args-to-string = set-parent (App (Hole pi-gen) (Hole pi-gen)) ∘ foldr' strEmpty λ t x → strAdd " " >>str arg-to-string t >>str x
binder-to-string tt = "∀"
binder-to-string ff = "Π"
lam-to-string tt = "Λ"
lam-to-string ff = "λ"
arrowtype-to-string ff = " ➔"
arrowtype-to-string tt = " ➾"
opacity-to-string opacity-open = ""
opacity-to-string opacity-closed = "opaque "
vars-to-string [] = strEmpty
vars-to-string (v :: []) = strVar v
vars-to-string (v :: vs) = strVar v >>str strAdd " " >>str vars-to-string vs
ctr-to-string (Ctr x T) = strAdd x >>str strAdd " : " >>str to-stringh T
case-to-string (Case x as t _) =
strM-Γ λ Γ →
let as-f = λ x as → strVar x >>str caseArgs-to-string as (strAdd " ➔ " >>str to-stringr t) in
case (env-lookup Γ x , options) of uncurry λ where
(just (ctr-def mps T _ _ _ , _ , _)) ced-ops-drop-spine →
as-f (unqual-all (ctxt.qual Γ) x) as
_ _ → as-f x as
cases-to-string = h use-newlines where
h : 𝔹 → cases → strM
h _ [] = strEmpty
h tt (m :: []) = strAdd "| " >>str case-to-string m
h tt (m :: ms) = strAdd "| " >>str case-to-string m >>str strLine >>str h tt ms
h ff (m :: []) = case-to-string m
h ff (m :: ms) = case-to-string m >>str strAdd " | " >>str h ff ms
caseArgs-to-string [] m = m
caseArgs-to-string (CaseArg _ x (just (Tkk _)) :: as) m = strAdd " ·" >>str strBvar x strEmpty (caseArgs-to-string as m)
caseArgs-to-string (CaseArg ff x _ :: as) m = strAdd " " >>str strBvar x strEmpty (caseArgs-to-string as m)
caseArgs-to-string (CaseArg tt x _ :: as) m = strAdd " -" >>str strBvar x strEmpty (caseArgs-to-string as m)
braceL me = if me then "{" else "("
braceR me = if me then "}" else ")"
bracketL me = if me then "{ " else "[ "
bracketR me = if me then " } -" else " ] -"
param-to-string : param → (strM → strM) × strM
param-to-string (Param me v atk) =
strΓ' localScope v ,
(strAdd (braceL me) >>str
strAdd (unqual-local v) >>str
strAdd " : " >>str
to-stringh -tk' atk >>str
strAdd (braceR me))
params-to-string'' ps f = elim-pair (foldr (λ p → uncurry λ g ms → elim-pair (param-to-string p) λ h m → g ∘ h , m :: map h ms) (id , []) ps) λ g ms → strList 2 (strEmpty :: ms) >>str g f
params-to-string' f [] = f
params-to-string' f (p :: []) = elim-pair (param-to-string p) λ g m → m >>str g f
params-to-string' f (p :: ps) = elim-pair (param-to-string p) λ g m → m >>str strAdd " " >>str params-to-string' (g f) ps
params-to-string = params-to-string' strEmpty
strRun : ctxt → strM → rope
strRun Γ m = doc-to-rope $ fst $ m {TERM} NIL 0 [] Γ nothing neither
strRunTag : (name : string) → ctxt → strM → tagged-val
strRunTag name Γ m with m {TERM} NIL 0 [] Γ nothing neither
...| s , n , ts = name , doc-to-rope s , ts
to-stringe : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringe = to-stringh ∘' (if cedille-options.options.erase-types options then erase else id)
to-string-tag : {ed : exprd} → string → ctxt → ⟦ ed ⟧ → tagged-val
to-string-tag name Γ t = strRunTag name Γ (to-stringe t)
to-string : {ed : exprd} → ctxt → ⟦ ed ⟧ → rope
to-string Γ t = strRun Γ (to-stringh t)
tpkd-to-stringe : tpkd → strM
tpkd-to-stringe = to-stringe -tk'_
tpkd-to-string : ctxt → tpkd → rope
tpkd-to-string Γ atk = strRun Γ (tpkd-to-stringe atk)
params-to-string-tag : string → ctxt → params → tagged-val
params-to-string-tag name Γ ps = strRunTag name Γ (params-to-string ps)
| {
"alphanum_fraction": 0.6075582753,
"avg_line_length": 36.9723661485,
"ext": "agda",
"hexsha": "22ff552eb7ef647791edf5246b1e83a9862ccf14",
"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": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ice1k/cedille",
"max_forks_repo_path": "src/to-string.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"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": "ice1k/cedille",
"max_issues_repo_path": "src/to-string.agda",
"max_line_length": 187,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ice1k/cedille",
"max_stars_repo_path": "src/to-string.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8144,
"size": 21407
} |
data Nat : Set where
zero : Nat
suc : Nat → Nat
_+_ : Nat → Nat → Nat
zero + n = n
suc m + n = suc ?
| {
"alphanum_fraction": 0.5185185185,
"avg_line_length": 13.5,
"ext": "agda",
"hexsha": "ece36b73ddadb65c5055ea9a5da58fcfd96b855e",
"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/interaction/Issue1541.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/interaction/Issue1541.agda",
"max_line_length": 21,
"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/interaction/Issue1541.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": 43,
"size": 108
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Sigma
open import lib.types.Bool
open import lib.types.Truncation hiding (Trunc)
open import Pointed
open import Preliminaries hiding (_^_)
module Judgmental_Computation where
-- Chapter 6: On the Truncation's Judgmental
-- Computation Rule
{-
Recall the definition of the propositional
truncation that we use (Prelims.agda):
postulate
∣∣_∣∣ : ∀ {i} → (X : Type i) → Type i
tr-is-prop : ∀ {i} {X : Type i} → is-prop (∣∣ X ∣∣)
∣_∣ : ∀ {i} {X : Type i} → X → ∣∣ X ∣∣
tr-rec : ∀ {i j} {X : Type i} {P : Type j}
→ (is-prop P) → (X → P) → ∣∣ X ∣∣ → P
We now redefine the propositional truncation so
that rec has the judgmental β rule. We use the
library implementation (library.types.Truncation).
However, we still only talk about the *propositional*
truncation (not the more general n-truncation).
This file is independent of (almost) all the other
files of the formalisation.
-}
-- The propositional truncation operator:
Trunc : ∀ {i} → Type i → Type i
Trunc = lib.types.Truncation.Trunc ⟨-1⟩
-- By definition, the truncation is propositional:
h-tr : ∀ {i} → (X : Type i) → is-prop (Trunc X)
h-tr X = Trunc-level
-- The projection.
∣_∣ : ∀ {i} → {X : Type i} → X → Trunc X
∣_∣ = [_]
-- The recursion principle, with judgmental computation.
rec : ∀ {i j} → {X : Type i} → {P : Type j}
→ (is-prop P) → (X → P) → Trunc X → P
rec = Trunc-rec
-- Similarly the induction principle.
ind : ∀ {i j} → {X : Type i} → {P : Trunc X → Type j}
→ ((z : Trunc X) → is-prop (P z))
→ ((x : X) → P ∣ x ∣) → (z : Trunc X) → P z
ind = Trunc-elim
-- Chapter 6.1: The Interval
-- Proposition 6.1.1
interval : Type₀
interval = Trunc Bool
i₁ : interval
i₁ = ∣ true ∣
i₂ : interval
i₂ = ∣ false ∣
seg : i₁ == i₂
seg = prop-has-all-paths (h-tr _) _ _
-- We prove that the interval has the "correct" recursion principle:
module interval {i} {Y : Type i} (y₁ y₂ : Y) (p : y₁ == y₂) where
g : Bool → Σ Y λ y → y₁ == y
g true = (y₁ , idp)
g false = (y₂ , p)
ĝ : interval → Σ Y λ y → y₁ == y
ĝ = rec (contr-is-prop (pathfrom-is-contr _)) g
f : interval → Y
f = fst ∘ ĝ
f-i₁ : f i₁ == y₁
f-i₁ = idp
f-i₂ : f i₂ == y₂
f-i₂ = idp
f-seg : ap f seg == p
f-seg =
ap f seg =⟨ idp ⟩
ap (fst ∘ ĝ) seg =⟨ ! (∘-ap _ _ _) ⟩
(ap fst) (ap ĝ seg) =⟨ ap (ap fst) (prop-has-all-paths (contr-is-set (pathfrom-is-contr _) _ _) _ _) ⟩
(ap fst) (pair= p po-aux) =⟨ fst=-β p _ ⟩
p ∎ where
po-aux : idp == p [ _==_ y₁ ↓ p ]
po-aux = from-transp (_==_ y₁) p (trans-pathfrom p idp)
-- Everything again outside the module:
interval-rec : ∀ {i} → {Y : Type i} → (y₁ y₂ : Y) → (p : y₁ == y₂) → (interval → Y)
interval-rec = interval.f
interval-rec-i₁ : ∀ {i} → {Y : Type i} → (y₁ y₂ : Y) → (p : y₁ == y₂) → (interval-rec y₁ y₂ p) i₁ == y₁
interval-rec-i₁ = interval.f-i₁ -- or: λ _ _ _ → idp
interval-rec-i₂ : ∀ {i} → {Y : Type i} → (y₁ y₂ : Y) → (p : y₁ == y₂) → (interval-rec y₁ y₂ p) i₂ == y₂
interval-rec-i₂ = interval.f-i₂ -- or: λ _ _ _ → idp
interval-rec-seg : ∀ {i} → {Y : Type i} → (y₁ y₂ : Y) → (p : y₁ == y₂) → ap (interval-rec y₁ y₂ p) seg == p
interval-rec-seg = interval.f-seg
-- Chapter 6.2: Function Extensionality
-- Lemma 6.2.1 (Shulman) / Corollary 6.2.2
interval→funext : ∀ {i j} → {X : Type i} → {Y : Type j} → (f g : (X → Y)) → ((x : X) → f x == g x) → f == g
interval→funext {X = X} {Y = Y} f g hom = ap i-x seg where
x-i : X → interval → Y
x-i x = interval-rec (f x) (g x) (hom x)
i-x : interval → X → Y
i-x i x = x-i x i
-- Thus, function extensionality holds automatically;
-- i.e. we could derive all lemmata in lib.types.Pi,
-- which we choose to import for convenience.
open import lib.types.Pi
-- Chapter 6.3: Judgmental Factorisation
-- We use the definitions from Chapter 5, but we
-- re-define them as our definition of "Trunc" has
-- chanced
factorizes : ∀ {i j} → {X : Type i} → {Y : Type j}
→ (f : X → Y) → Type (lmax i j)
factorizes {X = X} {Y = Y} f =
Σ (Trunc X → Y)
λ f' → (x : X) → f' ∣ x ∣ == f x
-- Proposition 6.3.1 - note the line proof' = λ _ → idp
judgmental-factorizer : ∀ {i j} → {X : Type i} → {Y : Type j}
→ (f : X → Y) → factorizes f → factorizes f
judgmental-factorizer {X = X} {Y = Y} f (f₂ , proof) = f' , proof' where
g : X → (z : Trunc X) → Σ Y λ y → y == f₂ z
g x = λ z → f x , (f x =⟨ ! (proof _) ⟩
f₂ ∣ x ∣ =⟨ ap f₂ (prop-has-all-paths (h-tr _) _ _) ⟩
f₂ z ∎)
g-codom-prop : is-prop ((z : Trunc X) → Σ Y λ y → y == f₂ z)
g-codom-prop = contr-is-prop (Π-level (λ z → pathto-is-contr _))
ĝ : Trunc X → (z : Trunc X) → Σ Y λ y → y == f₂ z
ĝ = rec g-codom-prop g
f' : Trunc X → Y
f' = λ z → fst (ĝ z z)
proof' : (x : X) → f' ∣ x ∣ == f x
proof' = λ _ → idp
-- Proposition 6.3.2 - we need the induction principle, but with that,
-- it is actually simpler than the previous construction.
-- Still, it is nearly a replication.
factorizes-dep : ∀ {i j} → {X : Type i} → {Y : Trunc X → Type j}
→ (f : (x : X) → (Y ∣ x ∣)) → Type (lmax i j)
factorizes-dep {X = X} {Y = Y} f =
Σ ((z : Trunc X) → Y z) λ f₂ → ((x : X) → f x == f₂ ∣ x ∣)
judgmental-factorizer-dep : ∀ {i j} → {X : Type i} → {Y : Trunc X → Type j}
→ (f : (x : X) → Y ∣ x ∣) → factorizes-dep {X = X} {Y = Y} f
→ factorizes-dep {X = X} {Y = Y} f
judgmental-factorizer-dep {X = X} {Y = Y} f (f₂ , proof) = f' , proof' where
g : (x : X) → Σ (Y ∣ x ∣) λ y → y == f₂ ∣ x ∣
g x = f x , proof x
g-codom-prop : (z : Trunc X) → is-prop (Σ (Y z) λ y → y == f₂ z)
g-codom-prop z = contr-is-prop (pathto-is-contr _)
ĝ : (z : Trunc X) → Σ (Y z) λ y → y == f₂ z
ĝ = ind g-codom-prop g
f' : (z : Trunc X) → Y z
f' = fst ∘ ĝ
proof' : (x : X) → f' ∣ x ∣ == f x
proof' x = idp
-- Chapter 6.4: An Invertibility Paradox
{- The content of this section is partially taken from my
formalisation of the contents of my original blog post;
see
http://homotopytypetheory.org/2013/10/28/
for a discussion and
http://red.cs.nott.ac.uk/~ngk/html-trunc-inverse/trunc-inverse.html
for a formalisation (the slightly simpler formalization that is mentioned
in the thesis ['Finally, we want to remark that te construction of myst
doest not need the full strength of Proposition 6.3.1']).
-}
-- Definition 6.4.1
is-transitive : ∀ {i} → Type i → Type (lsucc i)
is-transitive {i} X = (x₁ x₂ : X) → _==_ {A = Type• i} (X , x₁) (X , x₂)
-- Example 6.4.2
module dec-trans {i} (X : Type i) (dec : has-dec-eq X) where
module _ (x₁ x₂ : X) where
-- I define a function X → X that switches x and x₀.
switch : X → X
switch = λ y → match dec y x₁
withl (λ _ → x₂)
withr (λ _ → match dec y x₂
withl (λ _ → x₁)
withr (λ _ → y))
-- Rather tedious to prove, but completely straightforward:
-- this map is its own inverse.
switch-selfinverse : (y : X) → switch (switch y) == y
switch-selfinverse y with dec y x₁
switch-selfinverse y | inl _ with dec x₂ x₁
switch-selfinverse y | inl y-x₁ | inl x-x₁ = x-x₁ ∙ ! y-x₁
switch-selfinverse y | inl _ | inr _ with dec x₂ x₂
switch-selfinverse y | inl y-x₁ | inr _ | inl _ = ! y-x₁
switch-selfinverse y | inl _ | inr _ | inr ¬x₂-x₂ = Empty-elim {P = λ _ → x₂ == y} (¬x₂-x₂ idp)
switch-selfinverse y | inr _ with dec y x₂
switch-selfinverse y | inr _ | inl _ with dec x₂ x₁
switch-selfinverse y | inr ¬x₂-x₁ | inl y-x₂ | inl x₂-x₁ = Empty-elim (¬x₂-x₁ (y-x₂ ∙ x₂-x₁))
switch-selfinverse y | inr _ | inl _ | inr _ with dec x₁ x₁
switch-selfinverse y | inr _ | inl y-x₂ | inr _ | inl _ = ! y-x₂
switch-selfinverse y | inr _ | inl _ | inr _ | inr ¬x₁-x₁ = Empty-elim {P = λ _ → _ == y} (¬x₁-x₁ idp)
switch-selfinverse y | inr _ | inr _ with dec y x₁
switch-selfinverse y | inr ¬y-x₁ | inr _ | inl y-x₁ = Empty-elim {P = λ _ → x₂ == y} (¬y-x₁ y-x₁)
switch-selfinverse y | inr _ | inr _ | inr _ with dec y x₂
switch-selfinverse y | inr _ | inr ¬y-x₂ | inr _ | inl y-x₂ = Empty-elim {P = λ _ → x₁ == y} (¬y-x₂ y-x₂)
switch-selfinverse y | inr _ | inr _ | inr _ | inr _ = idp
switch-maps : switch x₂ == x₁
switch-maps with dec x₂ x₁
switch-maps | inl x₂-x₁ = x₂-x₁
switch-maps | inr _ with dec x₂ x₂
switch-maps | inr _ | inl _ = idp
switch-maps | inr _ | inr ¬x-x = Empty-elim {P = λ _ → x₂ == x₁} (¬x-x idp)
-- switch is an equivalence
switch-eq : X ≃ X
switch-eq = equiv switch switch
switch-selfinverse switch-selfinverse
-- X is transitive:
is-trans : is-transitive X
is-trans x₁ x₂ = pair= (ua X-X) x₁-x₂ where
X-X : X ≃ X
X-X = switch-eq x₂ x₁
x₁-x₂ : PathOver (idf (Type i)) (ua X-X) x₁ x₂
x₁-x₂ = ↓-idf-ua-in X-X (switch-maps x₂ x₁)
-- Example 6.4.2 addendum: ℕ is transitive.
-- (Recall that we have defined _+_ ourselves,
-- so that it is defined by recursion on the
-- second argument - this is not important
-- here, but it is the reason why we hide _+_.)
open import lib.types.Nat hiding (_+_)
ℕ-trans : is-transitive ℕ
ℕ-trans = dec-trans.is-trans ℕ ℕ-has-dec-eq
-- Example 6.4.3
-- (Note that this does not need the univalence axiom)
-- Preparation
path-trans-aux : ∀ {i} → (X : Type i) → (x₁ x₂ x₃ : X) → (x₂ == x₃)
→ (p₁₂ : x₁ == x₂) → (p₁₃ : x₁ == x₃) →
_==_ {A = Type• i} ((x₁ == x₂) , p₁₂) ((x₁ == x₃) , p₁₃)
path-trans-aux X x₁ .x₁ .x₁ p idp idp = idp
-- The proposition of Example 6.4.3
path-trans : ∀ {i} → (X : Type i) → (x₁ x₂ : X)
→ is-transitive (x₁ == x₂)
path-trans X x₁ x₂ = path-trans-aux X x₁ x₂ x₂ idp
-- In particular, loop spaces are transitive.
-- To show this, we choose postcomposition here -
-- whether the function exponentiation operator is more
-- convenient to use with pre- or postcomposition depends
-- on the concrete case.
infix 10 _^_
_^_ : ∀ {i} {A : Set i} → (A → A) → ℕ → A → A
f ^ 0 = idf _
f ^ S n = f ∘ (f ^ n)
loop-trans : ∀ {i} → (X : Type• i) → (n : ℕ)
→ is-transitive (fst ((Ω ^ (S n)) X))
loop-trans {i} X n = path-trans type point point where
type : Type i
type = fst ((Ω ^ n) X)
point : type
point = snd ((Ω ^ n) X)
-- We omit the formalisation for Examples 6.4.4, 6.4.5,
-- as they would require us to define
-- (or import) groups / are not essential
-- Finally: Theorem 6.4.6, the myst paradoxon
-- We need some preparations.
module constr-myst {i} (X : Type i) (x₀ : X) (t : is-transitive X) where
f : X → Type• i
f x = (X , x)
f'' : Trunc X → Type• i
f'' _ = (X , x₀)
f-fact : factorizes f
f-fact = f'' , (λ x → t x₀ x)
f' : Trunc X → Type• i
f' = fst (judgmental-factorizer f f-fact)
-- the myst function:
myst : (z : Trunc X) → fst (f' z)
myst = snd ∘ f'
check : (x : X) → myst ∣ x ∣ == x
check x = idp
myst-∣_∣-is-id : myst ∘ ∣_∣ == idf X
myst-∣_∣-is-id = λ= λ x → idp
-- Let us do Myst explicitly for ℕ:
open import lib.types.Nat
myst-ℕ = constr-myst.myst ℕ 0 (dec-trans.is-trans ℕ ℕ-has-dec-eq)
myst-∣_∣-is-id : (n : ℕ) → myst-ℕ ∣ n ∣ == n
myst-∣_∣-is-id n = idp
test : myst-ℕ ∣ 17 ∣ == 17
test = idp
| {
"alphanum_fraction": 0.5580687255,
"avg_line_length": 31.4931506849,
"ext": "agda",
"hexsha": "a35994cdf4951beb29619e811b7acec5ff182d2c",
"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/Judgmental_Computation.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/Judgmental_Computation.agda",
"max_line_length": 115,
"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/Judgmental_Computation.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": 4417,
"size": 11495
} |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Library.Relation.Binary.Equality where
open import Light.Library.Relation.Binary using (Binary ; SelfBinary)
open import Light.Library.Relation using (Base)
open import Light.Variable.Levels
open import Light.Level using (Setω)
open import Light.Variable.Sets
-- Binary relation wrapper for equality. (Purely conventional.)
-- (To facilitate instance lookup.)
record Equality ⦃ base : Base ⦄ (𝕒 : Set aℓ) (𝕓 : Set bℓ) : Setω where
constructor wrap
field relation : Binary 𝕒 𝕓
open Binary relation using () renaming (are to _≈_) public
SelfEquality : ∀ ⦃ base : Base ⦄ → Set aℓ → Setω
SelfEquality 𝕒 = Equality 𝕒 𝕒
open Equality ⦃ ... ⦄ using (_≈_) public
private module Eq = Equality ⦃ ... ⦄
relation : ∀ (𝕒 : Set aℓ) (𝕓 : Set bℓ) ⦃ base : Base ⦄ ⦃ equals : Equality 𝕒 𝕓 ⦄ → Binary 𝕒 𝕓
relation _ _ = Eq.relation
self‐relation : ∀ (𝕒 : Set aℓ) ⦃ base : Base ⦄ ⦃ equals : SelfEquality 𝕒 ⦄ → SelfBinary 𝕒
self‐relation _ = Eq.relation
| {
"alphanum_fraction": 0.6967680608,
"avg_line_length": 35.0666666667,
"ext": "agda",
"hexsha": "76c24abb18aebabb13c991014ab2d7da30b682a1",
"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": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Library/Relation/Binary/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Library/Relation/Binary/Equality.agda",
"max_line_length": 93,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Library/Relation/Binary/Equality.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 344,
"size": 1052
} |
module Oscar.Category.Semifunctor where
open import Oscar.Category.Setoid
open import Oscar.Category.Semigroupoid
open import Oscar.Level
module _
{𝔬₁ 𝔪₁ 𝔮₁} (semigroupoid₁ : Semigroupoid 𝔬₁ 𝔪₁ 𝔮₁)
{𝔬₂ 𝔪₂ 𝔮₂} (semigroupoid₂ : Semigroupoid 𝔬₂ 𝔪₂ 𝔮₂)
where
private module 𝔊₁ = Semigroupoid semigroupoid₁
private module 𝔊₂ = Semigroupoid semigroupoid₂
-- record IsSemifunctor
-- (μ : 𝔊₁.⋆ → 𝔊₂.⋆)
-- (𝔣 : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y)
-- : Set (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂) where
-- field
-- extensionality : ∀ {x y} {f₁ f₂ : x 𝔊₁.↦ y} → f₁ ≋ f₂ → 𝔣 f₁ ≋ 𝔣 f₂
-- distributivity : ∀ {x y} (f : x 𝔊₁.↦ y) {z} (g : y 𝔊₁.↦ z) → 𝔣 (g 𝔊₁.∙ f) ≋ 𝔣 g 𝔊₂.∙ 𝔣 f
-- open IsSemifunctor ⦃ … ⦄ public
-- record Semifunctor 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ : Set (lsuc (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂)) where
-- field
-- semigroupoid₁ : Semigroupoid 𝔬₁ 𝔪₁ 𝔮₁
-- semigroupoid₂ : Semigroupoid 𝔬₂ 𝔪₂ 𝔮₂
-- module 𝔊₁ = Semigroupoid semigroupoid₁
-- module 𝔊₂ = Semigroupoid semigroupoid₂
-- field
-- μ : 𝔊₁.⋆ → 𝔊₂.⋆
-- 𝔣 : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y
-- ⦃ isSemifunctor ⦄ : IsSemifunctor semigroupoid₁ semigroupoid₂ μ 𝔣
-- record Semigroupoids 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ : Set (lsuc (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂)) where
-- constructor _,_
-- field
-- semigroupoid₁ : Semigroupoid 𝔬₁ 𝔪₁ 𝔮₁
-- semigroupoid₂ : Semigroupoid 𝔬₂ 𝔪₂ 𝔮₂
-- module 𝔊₁ = Semigroupoid semigroupoid₁
-- module 𝔊₂ = Semigroupoid semigroupoid₂
-- module _
-- {𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂} (semigroupoids : Semigroupoids 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂)
-- where
-- open Semigroupoids semigroupoids
-- record IsSemifunctor
-- {μ : 𝔊₁.⋆ → 𝔊₂.⋆}
-- (𝔣 : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y)
-- : Set (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂) where
-- instance _ = 𝔊₁.IsSetoid↦
-- instance _ = 𝔊₂.IsSetoid↦
-- field
-- extensionality : ∀ {x y} {f₁ f₂ : x 𝔊₁.↦ y} → f₁ ≋ f₂ → 𝔣 f₁ ≋ 𝔣 f₂
-- distributivity : ∀ {x y} (f : x 𝔊₁.↦ y) {z} (g : y 𝔊₁.↦ z) → 𝔣 (g 𝔊₁.∙ f) ≋ 𝔣 g 𝔊₂.∙ 𝔣 f
-- open IsSemifunctor ⦃ … ⦄ public
-- record Semifunctor 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ : Set (lsuc (𝔬₁ ⊔ 𝔪₁ ⊔ 𝔮₁ ⊔ 𝔬₂ ⊔ 𝔪₂ ⊔ 𝔮₂)) where
-- constructor _,_
-- field
-- semigroupoids : Semigroupoids 𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂
-- open Semigroupoids semigroupoids public
-- field
-- {μ} : 𝔊₁.⋆ → 𝔊₂.⋆
-- 𝔣 : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y
-- ⦃ isSemifunctor ⦄ : IsSemifunctor semigroupoids 𝔣
-- open IsSemifunctor isSemifunctor public
| {
"alphanum_fraction": 0.5855745721,
"avg_line_length": 31.4615384615,
"ext": "agda",
"hexsha": "7b0d7221af543af64988cd6300258ef7a7ed77fc",
"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": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Category/Semifunctor.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Category/Semifunctor.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Category/Semifunctor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1385,
"size": 2454
} |
module Issue561 where
open import Agda.Builtin.Bool
open import Issue561.Core
primitive
primIsDigit : Char → Bool
main : IO Bool
main = return true
| {
"alphanum_fraction": 0.7662337662,
"avg_line_length": 12.8333333333,
"ext": "agda",
"hexsha": "a786291bb46b20c1d31857ebee6f1ef39a4d4169",
"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/Compiler/simple/Issue561.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/Compiler/simple/Issue561.agda",
"max_line_length": 29,
"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/Compiler/simple/Issue561.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": 41,
"size": 154
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module Extensions where
ExtensionOf : ∀ {ℓ} {A B : Type ℓ} (f : A → B) (P : B → Type ℓ) (φ : (a : A) → P (f a)) → Type ℓ
ExtensionOf {A = A} {B = B} f P φ = Σ (Π B P) (λ ψ → (a : A) → ψ (f a) == φ a)
syntax ExtensionOf f P φ = ⟨ P ⟩⟨ φ ↗ f ⟩
path-extension : ∀ {ℓ} {A B : Type ℓ} {f : A → B}
{P : B → Type ℓ} {φ : (a : A) → P (f a)}
(e₀ e₁ : ⟨ P ⟩⟨ φ ↗ f ⟩) →
⟨ (λ b → fst e₀ b == fst e₁ b) ⟩⟨ (λ a → snd e₀ a ∙ ! (snd e₁ a)) ↗ f ⟩ ≃ (e₀ == e₁)
path-extension {f = f} (ψ₀ , ε₀) (ψ₁ , ε₁) = equiv to {!!} {!!} {!!}
where to : ExtensionOf f (λ b → ψ₀ b == ψ₁ b) (λ a → ε₀ a ∙ ! (ε₁ a)) → (ψ₀ , ε₀) == (ψ₁ , ε₁)
to (α , β) = pair= (λ= α) {!!}
from : (ψ₀ , ε₀) == (ψ₁ , ε₁) → ExtensionOf f (λ b → ψ₀ b == ψ₁ b) (λ a → ε₀ a ∙ ! (ε₁ a))
from p = {!!}
-- from : (e₀ == e₁) → ⟨ (λ b → fst e₀ b == fst e₁ b) ⟩⟨ (λ a → snd e₀ a ∙ ! (snd e₁ a)) ↗ f ⟩
-- from = {!!}
-- Definition equiv_path_extension `{Funext} {A B : Type} {f : A -> B}
-- {P : B -> Type} {d : forall x:A, P (f x)}
-- (ext ext' : ExtensionAlong f P d)
-- : (ExtensionAlong f
-- (fun y => pr1 ext y = pr1 ext' y)
-- (fun x => pr2 ext x @ (pr2 ext' x)^))
-- <~> ext = ext'.
| {
"alphanum_fraction": 0.3787561146,
"avg_line_length": 40.8857142857,
"ext": "agda",
"hexsha": "4448d1c96c7342ba91e56169d5a9b6410a3ecc93",
"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/stash/modalities/Extensions.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/stash/modalities/Extensions.agda",
"max_line_length": 104,
"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/stash/modalities/Extensions.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": 603,
"size": 1431
} |
open import IO using ( run ; putStrLn )
open import Web.URI using ( AURI ; toString ; http://_ ; _/_ )
module Web.URI.Examples.HelloWorld where
hw : AURI
hw = http://"example.com"/"hello"/"world"
main = run (putStrLn (toString hw)) | {
"alphanum_fraction": 0.6837606838,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "40afeb87ae33394f2cb1c9930ab6919cb6f8f160",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:37:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:37:59.000Z",
"max_forks_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-uri",
"max_forks_repo_path": "src/Web/URI/Examples/HelloWorld.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"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/agda-web-uri",
"max_issues_repo_path": "src/Web/URI/Examples/HelloWorld.agda",
"max_line_length": 62,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-uri",
"max_stars_repo_path": "src/Web/URI/Examples/HelloWorld.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-23T04:56:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-23T04:56:25.000Z",
"num_tokens": 65,
"size": 234
} |
{-
Verified Red-Black Trees
Toon Nolten
Based on Chris Okasaki's "Red-Black Trees in a Functional Setting"
where he uses red-black trees to implement sets.
Invariants
----------
1. No red node has a red parent
2. Every Path from the root to an empty node contains the same number of
black nodes.
(Empty nodes are considered black)
-}
module RedBlackTree where
open import Data.Bool using (Bool; true; false) renaming (T to So; not to ¬)
_⇒_ : ∀{ℓ₁ ℓ₂} → Set ℓ₁ → Set ℓ₂ → Set _
P ⇒ T = {{p : P}} → T
infixr 3 _⇒_
if_then_else_ : ∀{ℓ}{A : Set ℓ} b → (So b ⇒ A) → (So (¬ b) ⇒ A) → A
if true then t else f = t
if false then t else f = f
open import Data.Nat hiding (_<_; _≤_; _≟_; compare)
renaming (decTotalOrder to ℕ-DTO)
open import Level hiding (suc)
open import Relation.Binary hiding (_⇒_)
open import Data.Sum using (_⊎_) renaming (inj₁ to h+0; inj₂ to h+1)
open import Data.Product using (Σ; Σ-syntax; _,_; proj₁; proj₂)
module RBTree {a ℓ}(order : StrictTotalOrder a ℓ ℓ) where
open module sto = StrictTotalOrder order
A = Carrier
pattern LT = tri< _ _ _
pattern EQ = tri≈ _ _ _
pattern GT = tri> _ _ _
_≤_ = compare
data Color : Set where
R B : Color
_=ᶜ_ : Color → Color → Bool
R =ᶜ R = true
B =ᶜ B = true
_ =ᶜ _ = false
Height = ℕ
data Tree : Color → Height → Set a where
E : Tree B 0
R : ∀{h} → Tree B h → A → Tree B h → Tree R h
B : ∀{cl cr h} → Tree cl h → A → Tree cr h → Tree B (suc h)
data IRTree : Height → Set a where
IRl : ∀{h} → Tree R h → A → Tree B h → IRTree h
IRr : ∀{h} → Tree B h → A → Tree R h → IRTree h
data OutOfBalance : Height → Set a where
_◂_◂_ : ∀{c h} → IRTree h → A → Tree c h → OutOfBalance h
_▸_▸_ : ∀{c h} → Tree c h → A → IRTree h → OutOfBalance h
data Treeish : Color → Height → Set a where
RB : ∀{c h} → Tree c h → Treeish c h
IR : ∀{h} → IRTree h → Treeish R h
-- Insertion
balance : ∀{h} → OutOfBalance h → Tree R (suc h)
balance (IRl (R a x b) y c ◂ z ◂ d) = R (B a x b) y (B c z d)
balance (IRr a x (R b y c) ◂ z ◂ d) = R (B a x b) y (B c z d)
balance (a ▸ x ▸ IRl (R b y c) z d) = R (B a x b) y (B c z d)
balance (a ▸ x ▸ IRr b y (R c z d)) = R (B a x b) y (B c z d)
blacken : ∀{c h} → (Treeish c h)
→ (if c =ᶜ B then Tree B h else Tree B (suc h))
blacken (RB E) = E
blacken (RB (R l b r)) = (B l b r)
blacken (RB (B l b r)) = (B l b r)
blacken (IR (IRl l b r)) = (B l b r)
blacken (IR (IRr l b r)) = (B l b r)
ins : ∀{c h} → (a : A) → (t : Tree c h)
→ Σ[ c' ∈ Color ] (if c =ᶜ B then (Tree c' h) else (Treeish c' h))
ins a E = R , R E a E
--
ins a (R _ b _) with a ≤ b
ins a (R l _ _) | LT with ins a l
ins _ (R _ b r) | LT | R , t = R , IR (IRl t b r)
ins _ (R _ b r) | LT | B , t = R , (RB (R t b r))
ins _ (R l b r) | EQ = R , RB (R l b r)
ins a (R _ _ r) | GT with ins a r
ins _ (R l b _) | GT | R , t = R , (IR (IRr l b t))
ins _ (R l b _) | GT | B , t = R , (RB (R l b t))
--
ins a (B _ b _) with a ≤ b
ins a (B l _ _) | LT with ins a l
ins _ (B {R} _ b r) | LT | c , RB t = B , B t b r
ins _ (B {R} _ b r) | LT | .R , IR t = R , balance (t ◂ b ◂ r)
ins _ (B {B} _ b r) | LT | c , t = B , B t b r
ins _ (B l b r) | EQ = B , B l b r
ins a (B _ _ r) | GT with ins a r
ins _ (B {cr = R} l b _) | GT | c , RB t = B , B l b t
ins _ (B {cr = R} l b _) | GT | .R , IR t = R , balance (l ▸ b ▸ t)
ins _ (B {cr = B} l b _) | GT | c , t = B , B l b t
insert : ∀{c h} → (a : A) → (t : Tree c h)
→ Tree B h ⊎ Tree B (suc h)
insert {R} a t with ins a t
... | R , t' = h+1 (blacken t')
... | B , t' = h+0 (blacken t')
insert {B} a t with ins a t
... | R , t' = h+1 (blacken (RB t'))
... | B , t' = h+0 (blacken (RB t'))
-- Simple Set Operations
set : ∀{c h} → Set _
set {c}{h} = Tree c h
empty : set
empty = E
member : ∀{c h} → (a : A) → set {c}{h} → Bool
member a E = false
member a (R l b r) with a ≤ b
... | LT = member a l
... | EQ = true
... | GT = member a r
member a (B l b r) with a ≤ b
... | LT = member a l
... | EQ = true
... | GT = member a r
-- Usage example
open import Relation.Binary.Properties.DecTotalOrder ℕ-DTO
ℕ-STO : StrictTotalOrder _ _ _
ℕ-STO = strictTotalOrder
open module rbtree = RBTree ℕ-STO
t0 : Tree B 2
t0 = B (R (B E 1 E) 2 (B (R E 3 E) 5 (R E 7 E)))
8
(B E 9 (R E 10 E))
t1 : Tree B 3
t1 = B (B (B E 1 E) 2 (B E 3 E))
4
(B (B E 5 (R E 7 E)) 8 (B E 9 (R E 10 E)))
t2 : Tree B 3
t2 = B (B (B E 1 E) 2 (B E 3 E))
4
(B (R (B E 5 E) 6 (B E 7 E)) 8 (B E 9 (R E 10 E)))
open import Relation.Binary.PropositionalEquality
t1≡t0+4 : h+1 t1 ≡ insert 4 t0
t1≡t0+4 = refl
t2≡t1+6 : h+0 t2 ≡ insert 6 t1
t2≡t1+6 = refl
| {
"alphanum_fraction": 0.5191109265,
"avg_line_length": 27.8265895954,
"ext": "agda",
"hexsha": "e4d8ad9a4999c447371b15ca8e2553eab343265a",
"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": "72e0989445760f63b9422ce5e0f8956d7f58d578",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "toonn/sciartt",
"max_forks_repo_path": "RedBlackTree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "72e0989445760f63b9422ce5e0f8956d7f58d578",
"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": "toonn/sciartt",
"max_issues_repo_path": "RedBlackTree.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "72e0989445760f63b9422ce5e0f8956d7f58d578",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "toonn/sciartt",
"max_stars_repo_path": "RedBlackTree.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2065,
"size": 4814
} |
-- Andreas, 2015-03-26
-- Andrea discovered that unfold for Lists is typable with sized types
-- (and termination checks).
-- Dually, fold for Streams should work. Therefore, the restriction
-- of coinductive records to recursive records should be lifted.
{-# OPTIONS --copatterns #-}
open import Common.Size
-- StreamF A X i = ∀j<i. A × X j
record StreamF (A : Set) (X : Size → Set) (i : Size) : Set where
coinductive
field
head : A
tail : ∀{j : Size< i} → X j
module F = StreamF
record Stream (A : Set) (i : Size) : Set where
coinductive
field
head : A
tail : ∀{j : Size< i} → Stream A j
module S = Stream
module Inlined {A T} (f : ∀ i → StreamF A T i → T i) where
fix : ∀ i → Stream A i → StreamF A T i
F.head (fix i s) = S.head s
F.tail (fix i s) {j = j} = f j (fix j (S.tail s {j = j}))
module Mutual {A T} (f : ∀ i → StreamF A T i → T i) where
mutual
fold : ∀ i → Stream A i → T i
fold i s = f i (h i s)
h : ∀ i → Stream A i → StreamF A T i
F.head (h i s) = S.head s
F.tail (h i s) {j = j} = fold j (S.tail s {j = j})
module Local where
fold : ∀{A T}
→ (f : ∀ i → StreamF A T i → T i)
→ ∀ i → Stream A i → T i
fold {A} {T} f i s = f i (h i s)
where
h : ∀ i → Stream A i → StreamF A T i
F.head (h i s) = S.head s
F.tail (h i s) {j = j} = fold f j (S.tail s {j = j})
-- Unfold for lists
-- ListF A X i = ⊤ + ∃j<i. A × X j
data ListF (A : Set) (X : Size → Set) (i : Size) : Set where
[] : ListF A X i
_∷_ : ∀{j : Size< i} (a : A) (xs : X j) → ListF A X i
data List (A : Set) (i : Size) : Set where
[] : List A i
_∷_ : ∀{j : Size< i} (a : A) (xs : List A j) → List A i
module With where
unfold : ∀{A}{S : Size → Set}
→ (f : ∀ i → S i → ListF A S i)
→ ∀ i → S i → List A i
unfold f i s with f i s
... | [] = []
... | _∷_ {j = j} a s' = a ∷ unfold f j s'
unfold : ∀{A}{S : Size → Set}
→ (f : ∀ i → S i → ListF A S i)
→ ∀ i → S i → List A i
unfold {A}{S} f i s = aux (f i s)
where
aux : ListF A S i → List A i
aux [] = []
aux (_∷_ {j = j} a s') = a ∷ unfold f j s'
| {
"alphanum_fraction": 0.5132450331,
"avg_line_length": 24.5813953488,
"ext": "agda",
"hexsha": "8614ef3881a0d703abfac4883ec179f6b9bed19b",
"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/Issue1470.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/Issue1470.agda",
"max_line_length": 70,
"max_stars_count": 3,
"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/Issue1470.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": 835,
"size": 2114
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.Empty {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Introductions.Universe
open import Tools.Unit
open import Tools.Product
-- Validity of the Empty type.
Emptyᵛ : ∀ {Γ l} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ l ⟩ Empty / [Γ]
Emptyᵛ [Γ] ⊢Δ [σ] = Emptyᵣ (idRed:*: (Emptyⱼ ⊢Δ)) , λ _ x₂ → id (Emptyⱼ ⊢Δ)
-- Validity of the Empty type as a term.
Emptyᵗᵛ : ∀ {Γ} ([Γ] : ⊩ᵛ Γ)
→ Γ ⊩ᵛ⟨ ¹ ⟩ Empty ∷ U / [Γ] / Uᵛ [Γ]
Emptyᵗᵛ [Γ] ⊢Δ [σ] = let ⊢Empty = Emptyⱼ ⊢Δ
[Empty] = Emptyᵣ (idRed:*: (Emptyⱼ ⊢Δ))
in Uₜ Empty (idRedTerm:*: ⊢Empty) Emptyₙ (≅ₜ-Emptyrefl ⊢Δ) [Empty]
, (λ x x₁ → Uₜ₌ Empty Empty (idRedTerm:*: ⊢Empty) (idRedTerm:*: ⊢Empty) Emptyₙ Emptyₙ
(≅ₜ-Emptyrefl ⊢Δ) [Empty] [Empty] (id (Emptyⱼ ⊢Δ)))
| {
"alphanum_fraction": 0.6416938111,
"avg_line_length": 38.375,
"ext": "agda",
"hexsha": "a4de0c9b499b3c37002222f3c3df90bee12f092e",
"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": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Vtec234/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"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": "Vtec234/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Empty.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Vtec234/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Empty.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 450,
"size": 1228
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommMonoid.Instances.FreeComMonoid where
open import Cubical.Foundations.Prelude
open import Cubical.HITs.FreeComMonoids
open import Cubical.Algebra.CommMonoid.Base
private variable
ℓ : Level
FCMCommMonoid : {A : Type ℓ} → CommMonoid ℓ
FCMCommMonoid {A = A} = makeCommMonoid {M = FreeComMonoid A} ε _·_ trunc assoc identityᵣ comm
| {
"alphanum_fraction": 0.777486911,
"avg_line_length": 27.2857142857,
"ext": "agda",
"hexsha": "5575351eba6225f53953ee80c85f52c29c05a259",
"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/CommMonoid/Instances/FreeComMonoid.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/CommMonoid/Instances/FreeComMonoid.agda",
"max_line_length": 93,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommMonoid/Instances/FreeComMonoid.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 119,
"size": 382
} |
module Reduction where
import Level
open import Data.Empty
open import Data.Unit as Unit
open import Data.Nat
open import Data.List as List renaming ([] to Ø; [_] to [_]L)
open import NonEmptyList as NList
open import Data.Fin hiding (_+_)
open import Data.Vec as Vec renaming ([_] to [_]V; _++_ to _++V_)
open import Data.Product as Prod
open import Function
open import Relation.Binary.PropositionalEquality as PE hiding ([_])
open import Relation.Binary
open ≡-Reasoning
Rel₀ : Set → Set₁
Rel₀ X = Rel X Level.zero
open import Common.Context as Context
open import Algebra
open Monoid {{ ... }} hiding (refl)
open import SyntaxRaw
open import Syntax
-----------------------------------------------------
---- Action of types on terms
-----------------------------------------------------
PreArrow : RawCtx → Set
PreArrow Γ = PreType Ø Γ Ø × PreTerm (∗ ∷ Γ) Ø × PreType Ø Γ Ø
Args : TyCtx → Set
Args Ø = ⊤
Args (Γ ∷ Θ) = PreArrow Γ × (Args Θ)
getArg : ∀ {Θ Γ₁} → TyVar Θ Γ₁ → Args Θ → PreTerm (∗ ∷ Γ₁) Ø
getArg zero ((_ , t , _) , ts) = t
getArg (succ Γ₁ X) (_ , ts) = getArg X ts
projArgDom : ∀ {Θ} → Args Θ → TyCtxMorP Ø Θ
projArgDom {Ø} a = tt
projArgDom {Γ ∷ Θ} ((A , _) , a) = (Λ A , projArgDom a)
projArgCodom : ∀ {Θ} → Args Θ → TyCtxMorP Ø Θ
projArgCodom {Ø} a = tt
projArgCodom {Γ ∷ Θ} ((_ , _ , B) , a) = (Λ B , projArgDom a)
-- | Extend arguments by the identity on a given type.
extArgs : ∀ {Θ Γ} → Args Θ → PreType Ø Γ Ø → Args (Γ ∷ Θ)
extArgs a A = ((A , varPO zero , A) , a)
-- | Domain of ⟪ A ⟫(φ) for arguments φ : Args Θ.
⟪_⟫₀ : ∀ {Θ Γ₁ Γ₂} →
PreType Θ Γ₁ Γ₂ → Args Θ → PreType Ø (Γ₂ ++ Γ₁) Ø
⟪_⟫₀ {Γ₁ = Γ₁} {Γ₂} C φ =
substTy (weakenPT' Γ₂ C) (projArgDom φ) §ₜ ctxProjP' Ø Γ₂ Γ₁
-- | Functorial action of a type A on terms.
-- We are given one term with its types for domain and codomain for each
-- variable in Θ. This is ensured by Args Θ. The result is then a term, which
-- can be thought of as ⟪A⟫(φ) : ⟪A⟫₀(φ) → ⟪A⟫₁(φ).
-- Otherwise, ⟪A⟫ is just defined by induction in A, as in the paper.
-- Note: For now, we have to declare this as non-terminating, as the induction
-- is not obviously terminating for Agda. This should be fixable through sized
-- types.
tyAction : ∀ {Θ Γ₁ Γ₂} →
(A : Raw Θ Γ₁ Γ₂) → DecentType A → Args Θ → PreTerm (∗ ∷ Γ₂ ++ Γ₁) Ø
tyAction ._ (DT-⊤ Θ Γ) ts = varPO zero
tyAction ._ (DT-tyVar Γ₁ X) ts = weakenPO'' Γ₁ Ø (getArg X ts)
tyAction ._ (DT-inst {Θ} {Γ₁} {Γ₂} {B} A t p q) ts
= substP (tyAction A p ts) f
where
-- | Substitute t for the second variable, i.e., f = (id, t, x).
f : CtxMorP (∗ ∷ Γ₂ ++ Γ₁) (∗ ∷ Γ₂ ↑ B ++ Γ₁)
f = subst
(Vec (PreTerm (∗ ∷ Γ₂ ++ Γ₁) Ø)) -- (CtxMorP (∗ ∷ Γ₂ ++ Γ₁))
(cong suc r)
(varPO zero
∷ (ctxProjP' [ ∗ ]L Γ₂ Γ₁)
++V [ weakenPO' (∗ ∷ Γ₂) (t , q) ]V
++V ctxProjP Γ₁ (∗ ∷ Γ₂)
)
where
r : length' Γ₂ + suc (length' Γ₁) ≡ length' (Γ₂ ↑ B ++ Γ₁)
r =
begin
length' Γ₂ + suc (length' Γ₁)
≡⟨ refl ⟩
length' Γ₂ + length' (B ∷ Γ₁)
≡⟨ PE.sym (length'-hom Γ₂ (B ∷ Γ₁)) ⟩
length' (Γ₂ ++ B ∷ Γ₁)
≡⟨ mvVar-length Γ₁ Γ₂ B ⟩
length' (Γ₂ ↑ B ++ Γ₁)
∎
tyAction ._ (DT-paramAbstr {Θ} {Γ₂} {B} Γ₁ {A} p) ts =
subst (λ u → PreTerm u Ø)
(cong (_∷_ ∗) (mvVar Γ₁ Γ₂ B))
(tyAction A p ts)
tyAction ._ (DT-fp {Θ} {Γ₂} Γ₁ μ D D-dec) ts
= weakenPO'' Γ₁ Ø (rec Γ₂ (∗ ∷ Γ₂) (gs D D-dec 0) §ₘ ctxidP (∗ ∷ Γ₂))
where
RB : PreType Ø Γ₂ Ø
RB = subst (λ u → PreType Ø u Ø) (proj₂ identity Γ₂)
(⟪ fpPT {Θ} {Γ₂} Ø μ (mkFpDataP {D = D} D-dec) ⟫₀ ts)
-- Construction of gₖ = αₖ id (⟪ Bₖ ⟫ (ts, id))
mkBase : ∀{Γ'}
(f : CtxMor Raw Γ' Γ₂) (A : Raw (Γ₂ ∷ Θ) Γ' Ø) →
DecentCtxMor f →
DecentType A →
ℕ →
Σ RawCtx (λ Γ' →
PreType [ Γ₂ ]L Γ' Ø
× CtxMorP Γ' Γ₂
× PreTerm (∗ ∷ Γ') Ø)
mkBase {Γ'} g M g-dec M-dec k
= (Γ' , C , mkCtxMorP g-dec , αₖ §ₘ r)
where
A : PreType (Γ₂ ∷ Θ) Γ' Ø
A = mkPreType M-dec
αₖ : PreTerm (∗ ∷ Γ') (∗ ∷ Γ')
αₖ = α _ Γ' ∗ k
r : CtxMorP (∗ ∷ Γ') (∗ ∷ Γ')
r = tyAction M M-dec (extArgs ts RB) ∷ ctxProjP Γ' [ ∗ ]L
C : PreType [ Γ₂ ]L Γ' Ø
C = substTy A (tyVarPT Ø zero , weakenTyCtxMor₁ Γ₂ (projArgDom ts))
-- Construct the g₁, ..., gₙ used in the recursion
gs : (D : FpData Raw Θ Γ₂) → DecentFpData D → ℕ → FpMapDataP Γ₂
gs [ Γ' , f , M ] (f-dec , M-dec) k
= [ mkBase f M f-dec M-dec k ]
gs ((Γ' , f , M) ∷ D) ((f-dec , M-dec) , D-dec) k
= mkBase f M f-dec M-dec k ∷ gs D D-dec (suc k)
tyAction ._ (DT-fp {Θ} {Γ₂} Γ₁ ν D D-dec) ts
= weakenPO'' Γ₁ Ø (corec Γ₂ (∗ ∷ Γ₂) (gs D D-dec 0) §ₘ ctxidP (∗ ∷ Γ₂))
where
-- Construction of gₖ = αₖ id (⟪ Bₖ ⟫ (ts, id))
mkBase : ∀{Γ'} (x : CtxMor Raw Γ' Γ₂ × Raw (Γ₂ ∷ Θ) Γ' Ø) →
(f : DecentCtxMor (proj₁ x)) →
(q : DecentType (proj₂ x)) →
ℕ →
Σ RawCtx (λ Γ' →
PreType [ Γ₂ ]L Γ' Ø
× CtxMorP Γ' Γ₂
× PreTerm (∗ ∷ Γ') Ø)
mkBase {Γ'} (g , M) g-dec M-dec k = (Γ' , C , mkCtxMorP g-dec , f)
where
A : PreType (Γ₂ ∷ Θ) Γ' Ø
A = mkPreType M-dec
ξₖ : PreTerm (∗ ∷ Γ') (∗ ∷ Γ')
ξₖ = ξ _ Γ' ∗ k
RA : PreType Ø Γ₂ Ø
RA = subst (λ u → PreType Ø u Ø) (proj₂ identity Γ₂)
(⟪ fpPT {Θ} {Γ₂} Ø μ (mkFpDataP {D = D} D-dec) ⟫₀ ts)
f : PreTerm (∗ ∷ Γ') Ø
f = substPO (tyAction M M-dec (extArgs ts RA))
((ξₖ §ₘ ctxidP (∗ ∷ Γ')) ∷ weakenCtxMorP (ctxidP Γ'))
C : PreType [ Γ₂ ]L Γ' Ø
C = substTy A (tyVarPT Ø zero , weakenTyCtxMor₁ Γ₂ (projArgDom ts))
-- Construct the g₁, ..., gₙ used in the recursion
gs : (D : FpData Raw Θ Γ₂) → DecentFpData D → ℕ → FpMapDataP Γ₂
gs [ Γ' , x ] (f , p) k = [ mkBase x f p k ]
gs ((Γ' , x) ∷ D₁) ((f , q) , p₁) k = mkBase x f q k ∷ gs D₁ p₁ (suc k)
⟪_⟫ : ∀ {Θ Γ₁ Γ₂} →
PreType Θ Γ₁ Γ₂ → Args Θ → PreTerm (∗ ∷ Γ₂ ++ Γ₁) Ø
⟪ A , A-dec ⟫ = tyAction A A-dec
-----------------------------------------------------
---- Reduction relation on pre-types and pre-terms
-----------------------------------------------------
getRecCtx : ∀{Γ} → (D : FpMapDataP Γ) → Pos D → RawCtx
getRecCtx [ x ] _ = proj₁ x
getRecCtx (x ∷ D) zero = proj₁ x
getRecCtx (x ∷ D) (suc p) = getRecCtx D p
getRecMor : ∀{Γ} (D : FpMapDataP Γ) (p : Pos D) →
PreTerm (∗ ∷ getRecCtx D p) Ø
getRecMor [ Γ' , A , f , t ] _ = t
getRecMor ((Γ' , A , f , t) ∷ D) zero = t
getRecMor (x ∷ D) (suc p) = getRecMor D p
getRecTy : ∀{Γ} (D : FpMapDataP Γ) (p : Pos D) →
PreType [ Γ ]L (getRecCtx D p) Ø
getRecTy [ x ] _ = proj₁ (proj₂ x)
getRecTy (x ∷ D) zero = proj₁ (proj₂ x)
getRecTy (x ∷ D) (suc p) = getRecTy D p
getRecSubst : ∀{Γ} (D : FpMapDataP Γ) (p : Pos D) →
CtxMorP (getRecCtx D p) Γ
getRecSubst [ Γ' , A , f , t ] _ = f
getRecSubst ((Γ' , A , f , t) ∷ D) zero = f
getRecSubst (x ∷ D) (suc p) = getRecSubst D p
infix 0 _≻_
-- | Contraction for terms
data _≻_ : {Γ₁ Γ₂ : RawCtx} → PreTerm Γ₁ Γ₂ → PreTerm Γ₁ Γ₂ → Set where
contract-iter : (Γ Δ : RawCtx) (D : FpMapDataP Γ) (C : PreType Ø Ø Γ)
(p : Pos D)
(τ : CtxMorP Δ (getRecCtx D p))
(u : PreTerm Δ Ø) →
rec Γ Δ D §ₘ
(α Δ (getRecCtx D p) ∗ (toℕ p) §ₘ' τ §ₒ u)
∷ getRecSubst D p • τ
≻ (getRecMor D p)
↓[ (⟪ getRecTy D p ⟫ (
( fpPT Γ μ (getFpData D) §ₜ ctxidP Γ
, rec Γ (∗ ∷ Γ) D §ₘ ctxidP _
, (weakenPT'' Γ C) §ₜ ctxidP Γ)
, tt))
∷ ctxProjP (getRecCtx D p) [ ∗ ]L ]
↓[ u ∷ τ ]
contract-coiter : (Γ Δ : RawCtx) (D : FpMapDataP Γ) (C : PreType Ø Ø Γ)
(p : Pos D)
(τ : CtxMorP Δ (getRecCtx D p))
(u : PreTerm Δ Ø) →
ξ Δ (getRecCtx D p) ∗ (toℕ p)
§ₘ' τ
§ₒ corec Γ Δ D §ₘ u ∷ (getRecSubst D p • τ)
≻ (⟪ getRecTy D p ⟫ (
(weakenPT'' Γ C §ₜ ctxidP Γ
, corec Γ (∗ ∷ Γ) D §ₘ ctxidP _
, fpPT Γ ν (getFpData D) §ₜ ctxidP Γ)
, tt)
↓[ (getRecMor D p) ∷ ctxProjP (getRecCtx D p) [ ∗ ]L ])
↓[ u ∷ τ ]
-- | Lift term reduction to fixed point data
data _∼>_ : {Γ : RawCtx} → Rel₀ (FpMapDataP Γ)
-- | Compatible closure of contraction
data _⟶_ : {Γ₁ Γ₂ : RawCtx} → Rel₀ (PreTerm Γ₁ Γ₂) where
contract : {Γ₁ Γ₂ : RawCtx} (t₁ t₂ : PreTerm Γ₁ Γ₂) → t₁ ≻ t₂ → t₁ ⟶ t₂
inst-clos₁ : ∀ {Γ₁ Γ₂ A} (s₁ s₂ : PreTerm Γ₁ (Γ₂ ↑ A)) (t : PreTerm Γ₁ Ø) →
s₁ ⟶ s₂ → instPO {Γ₁} {Γ₂} s₁ t ⟶ instPO s₂ t
inst-clos₂ : ∀ {Γ₁ Γ₂ A} (s : PreTerm Γ₁ (Γ₂ ↑ A)) (t₁ t₂ : PreTerm Γ₁ Ø) →
t₁ ⟶ t₂ → instPO {Γ₁} {Γ₂} s t₂ ⟶ instPO s t₂
grec-clos : (Γ : RawCtx) (Δ : RawCtx) (D D' : FpMapDataP Γ) (ρ : FP) →
D ∼> D' → grec Γ Δ D ρ ⟶ grec Γ Δ D' ρ
data _∼>_ where
single-clos : {Γ : RawCtx} (Γ' : RawCtx) (A : PreType [ Γ ]L Γ' Ø)
(f : CtxMorP Γ' Γ) (M₁ M₂ : PreTerm (∗ ∷ Γ') Ø) →
M₁ ⟶ M₂ → [ Γ' , A , f , M₁ ] ∼> [ Γ' , A , f , M₂ ]
step-clos₁ : {Γ : RawCtx} (Γ' : RawCtx) (A : PreType [ Γ ]L Γ' Ø)
(f : CtxMorP Γ' Γ) (M₁ M₂ : PreTerm (∗ ∷ Γ') Ø)
(D : FpMapDataP Γ) →
M₁ ⟶ M₂ → ((Γ' , A , f , M₁) ∷ D) ∼> ((Γ' , A , f , M₂) ∷ D)
step-clos₂ : {Γ : RawCtx} (Γ' : RawCtx) (A : PreType [ Γ ]L Γ' Ø)
(f : CtxMorP Γ' Γ) (M : PreTerm (∗ ∷ Γ') Ø)
(D₁ D₂ : FpMapDataP Γ) →
D₁ ∼> D₂ → ((Γ' , A , f , M) ∷ D₁) ∼> ((Γ' , A , f , M) ∷ D₂)
-- | β-reduction for parameter abstraction/instantiation
data _⟶ₚ_ : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → Rel₀ (PreType Θ Γ₁ Γ₂) where
β-red : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) {A : U}
(B : PreType Θ (A ∷ Γ₁) Γ₂) (t : PreTerm Γ₁ Ø) →
instPT (paramAbstrPT Γ₁ B) t ⟶ₚ substPT B (t ∷ (ctxidP Γ₁))
-- | Lift type reductions to fixed point data
data _∼>ₜ_ : {Θ : TyCtx} {Γ : RawCtx} → Rel₀ (FpDataP Θ Γ)
-- | Reduction on types. This is either a β-reduction for parameters,
-- a reduction of a term in parameter position, or it happens through
-- the compatible closure.
data _⟶ₜ_ : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → Rel₀ (PreType Θ Γ₁ Γ₂) where
param-conv : ∀ {Θ Γ₁ Γ₂ A}
(B : PreType Θ Γ₁ (Γ₂ ↑ A)) (t₁ t₂ : PreTerm Γ₁ Ø) →
t₁ ⟶ t₂ → instPT {Γ₂ = Γ₂} B t₁ ⟶ₜ instPT B t₂
inst-conv : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → (A₁ A₂ : PreType Θ Γ₁ Γ₂) →
A₁ ⟶ₚ A₂ → A₁ ⟶ₜ A₂
instPT-clos : ∀ {Θ Γ₁ Γ₂ A}
(B₁ B₂ : PreType Θ Γ₁ (Γ₂ ↑ A)) (t : PreTerm Γ₁ Ø) →
B₁ ⟶ₜ B₂ → instPT {Γ₂ = Γ₂} B₁ t ⟶ₜ instPT B₂ t
paramAbstr-clos : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) {A : U} →
(B₁ B₂ : PreType Θ (A ∷ Γ₁) Γ₂) →
B₁ ⟶ₜ B₂ → paramAbstrPT Γ₁ B₁ ⟶ₜ paramAbstrPT Γ₁ B₂
fp-clos : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) →
(ρ : FP) (D₁ D₂ : FpDataP Θ Γ₂) →
D₁ ∼>ₜ D₂ → fpPT Γ₁ ρ D₁ ⟶ₜ fpPT Γ₁ ρ D₂
data _∼>ₜ_ where
singlePT-clos : {Θ : TyCtx} {Γ : RawCtx}
(Γ' : RawCtx) (f : CtxMorP Γ' Γ) (A₁ A₂ : PreType (Γ ∷ Θ) Γ' Ø) →
A₁ ⟶ₜ A₂ → [ Γ' , f , A₁ ] ∼>ₜ [ Γ' , f , A₂ ]
stepPT-clos₁ : {Θ : TyCtx} {Γ : RawCtx}
(Γ' : RawCtx) (f : CtxMorP Γ' Γ) (A₁ A₂ : PreType (Γ ∷ Θ) Γ' Ø)
(D : FpDataP Θ Γ) →
A₁ ⟶ₜ A₂ -> ((Γ' , f , A₁) ∷ D) ∼>ₜ ((Γ' , f , A₂) ∷ D)
stepPT-clos₂ : {Θ : TyCtx} {Γ : RawCtx}
(Γ' : RawCtx) (f : CtxMorP Γ' Γ) (A : PreType (Γ ∷ Θ) Γ' Ø)
(D₁ D₂ : FpDataP Θ Γ) →
D₁ ∼>ₜ D₂ -> ((Γ' , f , A) ∷ D₁) ∼>ₜ ((Γ' , f , A) ∷ D₂)
| {
"alphanum_fraction": 0.4731138993,
"avg_line_length": 37.8827160494,
"ext": "agda",
"hexsha": "a7b9c052b49f4bf374ea122e53774cacc0109ed9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-24T10:54:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-24T10:54:38.000Z",
"max_forks_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "StillerHarpo/CoindDepTypes",
"max_forks_repo_path": "Syntax/Reduction.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_issues_repo_issues_event_max_datetime": "2020-07-24T12:53:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-07-24T12:53:30.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "StillerHarpo/CoindDepTypes",
"max_issues_repo_path": "Syntax/Reduction.agda",
"max_line_length": 79,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "StillerHarpo/CoindDepTypes",
"max_stars_repo_path": "Syntax/Reduction.agda",
"max_stars_repo_stars_event_max_datetime": "2018-04-06T02:10:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-27T14:45:11.000Z",
"num_tokens": 5109,
"size": 12274
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Nat.GCD where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Induction.WellFounded
open import Cubical.Data.Fin
open import Cubical.Data.Sigma as Σ
open import Cubical.Data.NatPlusOne
open import Cubical.HITs.PropositionalTruncation as PropTrunc
open import Cubical.Data.Nat.Base
open import Cubical.Data.Nat.Properties
open import Cubical.Data.Nat.Order
open import Cubical.Data.Nat.Divisibility
private
variable
m n d : ℕ
-- common divisors
isCD : ℕ → ℕ → ℕ → Type₀
isCD m n d = (d ∣ m) × (d ∣ n)
isPropIsCD : isProp (isCD m n d)
isPropIsCD = isProp× isProp∣ isProp∣
symCD : isCD m n d → isCD n m d
symCD (d∣m , d∣n) = (d∣n , d∣m)
-- greatest common divisors
isGCD : ℕ → ℕ → ℕ → Type₀
isGCD m n d = (isCD m n d) × (∀ d' → isCD m n d' → d' ∣ d)
GCD : ℕ → ℕ → Type₀
GCD m n = Σ ℕ (isGCD m n)
isPropIsGCD : isProp (isGCD m n d)
isPropIsGCD = isProp× isPropIsCD (isPropΠ2 (λ _ _ → isProp∣))
isPropGCD : isProp (GCD m n)
isPropGCD (d , dCD , gr) (d' , d'CD , gr') =
ΣProp≡ (λ _ → isPropIsGCD) (antisym∣ (gr' d dCD) (gr d' d'CD))
symGCD : isGCD m n d → isGCD n m d
symGCD (dCD , gr) = symCD dCD , λ { d' d'CD → gr d' (symCD d'CD) }
divsGCD : m ∣ n → isGCD m n m
divsGCD p = (∣-refl refl , p) , λ { d (d∣m , _) → d∣m }
-- The base case of the Euclidean algorithm
zeroGCD : ∀ m → isGCD m 0 m
zeroGCD m = divsGCD (∣-zeroʳ m)
private
lem₁ : prediv d (suc n) → prediv d (m % suc n) → prediv d m
lem₁ {d} {n} {m} (c₁ , p₁) (c₂ , p₂) = (q * c₁ + c₂) , p
where r = m % suc n; q = n%k≡n[modk] m (suc n) .fst
p = (q * c₁ + c₂) * d ≡⟨ sym (*-distribʳ (q * c₁) c₂ d) ⟩
(q * c₁) * d + c₂ * d ≡⟨ cong (_+ c₂ * d) (sym (*-assoc q c₁ d)) ⟩
q * (c₁ * d) + c₂ * d ≡[ i ]⟨ q * (p₁ i) + (p₂ i) ⟩
q * (suc n) + r ≡⟨ n%k≡n[modk] m (suc n) .snd ⟩
m ∎
lem₂ : prediv d (suc n) → prediv d m → prediv d (m % suc n)
lem₂ {d} {n} {m} (c₁ , p₁) (c₂ , p₂) = c₂ ∸ q * c₁ , p
where r = m % suc n; q = n%k≡n[modk] m (suc n) .fst
p = (c₂ ∸ q * c₁) * d ≡⟨ ∸-distribʳ c₂ (q * c₁) d ⟩
c₂ * d ∸ (q * c₁) * d ≡⟨ cong (c₂ * d ∸_) (sym (*-assoc q c₁ d)) ⟩
c₂ * d ∸ q * (c₁ * d) ≡[ i ]⟨ p₂ i ∸ q * (p₁ i) ⟩
m ∸ q * (suc n) ≡⟨ cong (_∸ q * (suc n)) (sym (n%k≡n[modk] m (suc n) .snd)) ⟩
(q * (suc n) + r) ∸ q * (suc n) ≡⟨ cong (_∸ q * (suc n)) (+-comm (q * (suc n)) r) ⟩
(r + q * (suc n)) ∸ q * (suc n) ≡⟨ ∸-cancelʳ r zero (q * (suc n)) ⟩
r ∎
-- The inductive step of the Euclidean algorithm
stepGCD : isGCD (suc n) (m % suc n) d
→ isGCD m (suc n) d
fst (stepGCD ((d∣n , d∣m%n) , gr)) = PropTrunc.map2 lem₁ d∣n d∣m%n , d∣n
snd (stepGCD ((d∣n , d∣m%n) , gr)) d' (d'∣m , d'∣n) = gr d' (d'∣n , PropTrunc.map2 lem₂ d'∣n d'∣m)
-- putting it all together using well-founded induction
euclid< : ∀ m n → n < m → GCD m n
euclid< = WFI.induction <-wellfounded λ {
m rec zero p → m , zeroGCD m ;
m rec (suc n) p → let d , dGCD = rec (suc n) p (m % suc n) (n%sk<sk m n)
in d , stepGCD dGCD }
euclid : ∀ m n → GCD m n
euclid m n with n ≟ m
... | lt p = euclid< m n p
... | gt p = Σ.mapʳ symGCD (euclid< n m p)
... | eq p = m , divsGCD (∣-refl (sym p))
isContrGCD : ∀ m n → isContr (GCD m n)
isContrGCD m n = euclid m n , isPropGCD _
-- the gcd operator on ℕ
gcd : ℕ → ℕ → ℕ
gcd m n = euclid m n .fst
gcdIsGCD : ∀ m n → isGCD m n (gcd m n)
gcdIsGCD m n = euclid m n .snd
| {
"alphanum_fraction": 0.5349391212,
"avg_line_length": 32.5689655172,
"ext": "agda",
"hexsha": "73139e4461ab02c621e7eb5710982177a628dd41",
"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": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmester0/cubical",
"max_forks_repo_path": "Cubical/Data/Nat/GCD.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"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": "cmester0/cubical",
"max_issues_repo_path": "Cubical/Data/Nat/GCD.agda",
"max_line_length": 107,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmester0/cubical",
"max_stars_repo_path": "Cubical/Data/Nat/GCD.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z",
"num_tokens": 1672,
"size": 3778
} |
open import Oscar.Prelude
open import Oscar.Class.HasEquivalence
import Oscar.Data.Constraint
module Oscar.Data.ProductIndexEquivalence where
module _ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {ℓ} ⦃ _ : HasEquivalence 𝔒 ℓ ⦄ where
record _≈₀_ (P Q : Σ 𝔒 𝔓) : Ø ℓ where
constructor ∁
field
π₀ : π₀ P ≈ π₀ Q
open _≈₀_ public
module _ {𝔬} (𝔒 : Ø 𝔬) {𝔭} (𝔓 : 𝔒 → Ø 𝔭) {ℓ} ⦃ _ : HasEquivalence 𝔒 ℓ ⦄ where
ProductIndexEquivalence⟦_/_⟧ : (P Q : Σ 𝔒 𝔓) → Ø ℓ
ProductIndexEquivalence⟦_/_⟧ = _≈₀_
| {
"alphanum_fraction": 0.6299212598,
"avg_line_length": 24.1904761905,
"ext": "agda",
"hexsha": "c8ed41ca5cbf6172d0e3cde30a8bdb4b2fc7a13a",
"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": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Data/ProductIndexEquivalence.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Data/ProductIndexEquivalence.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Data/ProductIndexEquivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 250,
"size": 508
} |
-- https://www.codewars.com/kata/50654ddff44f800200000004
{-# OPTIONS --safe #-}
module Solution where
open import Data.Nat
multiply : ℕ → ℕ → ℕ
multiply a b = a * b
| {
"alphanum_fraction": 0.6882352941,
"avg_line_length": 15.4545454545,
"ext": "agda",
"hexsha": "b0e64ff2a1d7cda8e29b105a43f4fc71f96b544c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-09T17:22:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T17:22:10.000Z",
"max_forks_repo_head_hexsha": "1a423e8cb0fbcac94738f6e51dc333f057b0a731",
"max_forks_repo_licenses": [
"WTFPL"
],
"max_forks_repo_name": "hiljusti/codewars-solutions",
"max_forks_repo_path": "agda/multiply/solution.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1a423e8cb0fbcac94738f6e51dc333f057b0a731",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"WTFPL"
],
"max_issues_repo_name": "hiljusti/codewars-solutions",
"max_issues_repo_path": "agda/multiply/solution.agda",
"max_line_length": 57,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "1a423e8cb0fbcac94738f6e51dc333f057b0a731",
"max_stars_repo_licenses": [
"WTFPL"
],
"max_stars_repo_name": "hiljusti/codewars-solutions",
"max_stars_repo_path": "agda/multiply/solution.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-21T22:21:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-22T08:47:51.000Z",
"num_tokens": 53,
"size": 170
} |
module Channel where
open import Data.Bool hiding (_≤_)
open import Data.Fin hiding (_≤_)
open import Data.List hiding (map)
open import Data.Maybe
open import Data.Nat
open import Data.Nat.Properties
open import Data.Product hiding (map)
open import Relation.Binary.PropositionalEquality
open import Typing
open import Syntax hiding (send ; recv)
open import Global
data ChannelEnd : Set where
POS NEG : ChannelEnd
otherEnd : ChannelEnd → ChannelEnd
otherEnd POS = NEG
otherEnd NEG = POS
-- the main part of a channel endpoint value is a valid channel reference
-- the channel end determines whether it's the front end or the back end of the channel
-- enforces that the session context has only one channel
data ChannelRef : (G : SCtx) (ce : ChannelEnd) (s : STypeF SType) → Set where
here-pos : ∀ {s s'} {G : SCtx}
→ (ina-G : Inactive G)
→ s ≲' s'
→ ChannelRef (just (s , POS) ∷ G) POS s'
here-neg : ∀ {s s'} {G : SCtx}
→ (ina-G : Inactive G)
→ dualF s ≲' s'
→ ChannelRef (just (s , NEG) ∷ G) NEG s'
there : ∀ {b s} {G : SCtx}
→ (vcr : ChannelRef G b s)
→ ChannelRef (nothing ∷ G) b s
-- coerce channel ref to a supertype
vcr-coerce : ∀ {G b s s'} → ChannelRef G b s → s ≲' s' → ChannelRef G b s'
vcr-coerce (here-pos ina-G x) s≤s' = here-pos ina-G (subF-trans x s≤s')
vcr-coerce (here-neg ina-G x) s≤s' = here-neg ina-G (subF-trans x s≤s')
vcr-coerce (there vcr) s≤s' = there (vcr-coerce vcr s≤s')
-- find matching wait instruction in thread pool
vcr-match : ∀ {G G₁ G₂ b₁ b₂ s₁ s₂}
→ SSplit G G₁ G₂
→ ChannelRef G₁ b₁ s₁
→ ChannelRef G₂ b₂ s₂
→ Maybe (b₁ ≡ otherEnd b₂ × dualF s₂ ≲' s₁)
vcr-match () (here-pos _ _) (here-pos _ _)
vcr-match (ss-posneg ss) (here-pos{s} ina-G s<=s') (here-neg ina-G₁ ds<=s'') = just (refl , subF-trans (dual-subF ds<=s'') (subF-trans (eqF-implies-subF (eqF-sym (dual-involutionF s))) s<=s'))
vcr-match (ss-left ss) (here-pos _ _) (there vcr2) = nothing
vcr-match (ss-negpos ss) (here-neg ina-G ds<=s') (here-pos ina-G₁ s<=s'') = just (refl , subF-trans (dual-subF s<=s'') ds<=s')
vcr-match (ss-left ss) (here-neg _ _) (there vcr2) = nothing
vcr-match (ss-right ss) (there vcr1) (here-pos _ ina-G) = nothing
vcr-match (ss-right ss) (there vcr1) (here-neg _ ina-G) = nothing
vcr-match (ss-both ss) (there vcr1) (there vcr2) = vcr-match ss vcr1 vcr2
-- ok. brute force for a fixed tree with three levels
data SSplit2 (G G₁ G₂ G₁₁ G₁₂ : SCtx) : Set where
ssplit2 :
(ss1 : SSplit G G₁ G₂)
→ (ss2 : SSplit G₁ G₁₁ G₁₂)
→ SSplit2 G G₁ G₂ G₁₁ G₁₂
vcr-match-2-sr : ∀ {G G₁ G₂ G₁₁ G₁₂ b₁ b₂ s₁ s₂ t₁ t₂}
→ SSplit2 G G₁ G₂ G₁₁ G₁₂
→ ChannelRef G₁₁ b₁ (recv t₁ s₁)
→ ChannelRef G₁₂ b₂ (send t₂ s₂)
→ Maybe (SubT t₂ t₁ × dual s₂ ≲ s₁ ×
∃ λ G' → ∃ λ G₁' → ∃ λ G₁₁' → ∃ λ G₁₂' →
SSplit2 G' G₁' G₂ G₁₁' G₁₂' ×
ChannelRef G₁₁' b₁ (SType.force s₁) ×
ChannelRef G₁₂' b₂ (SType.force s₂))
vcr-match-2-sr (ssplit2 ss-[] ()) (here-pos ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-both ss1) ()) (here-pos ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-left ss1) ()) (here-pos ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-right ss1) ()) (here-pos ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-posneg ss1) ()) (here-pos ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-negpos ss1) ()) (here-pos ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 ss-[] ()) (here-pos ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-both ss1) ()) (here-pos ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-left ss1) (ss-posneg ss2)) (here-pos ina-G (sub-recv{s1} t t' t<=t' s1<=s1')) (here-neg ina-G₁ (sub-send .t t'' t'<=t s1<=s1'')) = just ((subt-trans t'<=t t<=t') , (sub-trans (dual-sub s1<=s1'') (sub-trans (eq-implies-sub (eq-sym (dual-involution s1))) s1<=s1')) , _ , _ , _ , _ , ssplit2 (ss-left ss1) (ss-posneg ss2) , here-pos ina-G (Sub.force s1<=s1') , here-neg ina-G₁ (Sub.force s1<=s1''))
vcr-match-2-sr (ssplit2 (ss-right ss1) ()) (here-pos ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-posneg ss1) ()) (here-pos ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-negpos ss1) ()) (here-pos ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 ss-[] ()) (here-pos ina-G x) (there vcr2)
vcr-match-2-sr (ssplit2 (ss-both ss1) ()) (here-pos ina-G x) (there vcr2)
vcr-match-2-sr (ssplit2 (ss-left ss1) (ss-left ss2)) (here-pos ina-G x) (there vcr2) = nothing
vcr-match-2-sr (ssplit2 (ss-right ss1) ()) (here-pos ina-G x) (there vcr2)
vcr-match-2-sr (ssplit2 (ss-posneg ss1) (ss-left ss2)) (here-pos ina-G x) (there vcr2) = nothing
vcr-match-2-sr (ssplit2 (ss-negpos ss1) ()) (here-pos ina-G x) (there vcr2)
vcr-match-2-sr (ssplit2 ss-[] ()) (here-neg ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-both ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr {s₁ = s₁} {s₂} (ssplit2 (ss-left ss1) (ss-negpos ss2)) (here-neg ina-G (sub-recv .t t'' t<=t' s1<=s1'')) (here-pos ina-G₁ (sub-send t t' t'<=t s1<=s1')) = just ((subt-trans t'<=t t<=t') , ((sub-trans (dual-sub s1<=s1') s1<=s1'') , (_ , (_ , (_ , (_ , ((ssplit2 (ss-left ss1) (ss-negpos ss2)) , ((here-neg ina-G (Sub.force s1<=s1'')) , (here-pos ina-G₁ (Sub.force s1<=s1'))))))))))
vcr-match-2-sr (ssplit2 (ss-right ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-posneg ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-negpos ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ x₁)
vcr-match-2-sr (ssplit2 ss-[] ()) (here-neg ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-both ss1) ()) (here-neg ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-right ss1) ()) (here-neg ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-posneg ss1) ()) (here-neg ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 (ss-negpos ss1) ()) (here-neg ina-G x) (here-neg ina-G₁ x₁)
vcr-match-2-sr (ssplit2 ss-[] ()) (here-neg ina-G x) (there vcr2)
vcr-match-2-sr (ssplit2 (ss-both ss1) ()) (here-neg ina-G x) (there vcr2)
vcr-match-2-sr (ssplit2 (ss-left ss1) (ss-left ss2)) (here-neg ina-G x) (there vcr2) = nothing
vcr-match-2-sr (ssplit2 (ss-right ss1) ()) (here-neg ina-G x) (there vcr2)
vcr-match-2-sr (ssplit2 (ss-posneg ss1) ()) (here-neg ina-G x) (there vcr2)
vcr-match-2-sr (ssplit2 (ss-negpos ss1) (ss-left ss2)) (here-neg ina-G x) (there vcr2) = nothing
vcr-match-2-sr (ssplit2 ss-[] ()) (there vcr1) (here-pos ina-G x)
vcr-match-2-sr (ssplit2 (ss-both ss1) ()) (there vcr1) (here-pos ina-G x)
vcr-match-2-sr (ssplit2 (ss-left ss1) (ss-right ss2)) (there vcr1) (here-pos ina-G x) = nothing
vcr-match-2-sr (ssplit2 (ss-right ss1) ()) (there vcr1) (here-pos ina-G x)
vcr-match-2-sr (ssplit2 (ss-posneg ss1) (ss-right ss2)) (there vcr1) (here-pos ina-G x) = nothing
vcr-match-2-sr (ssplit2 (ss-negpos ss1) ()) (there vcr1) (here-pos ina-G x)
vcr-match-2-sr (ssplit2 ss-[] ()) (there vcr1) (here-neg ina-G x)
vcr-match-2-sr (ssplit2 (ss-both ss1) ()) (there vcr1) (here-neg ina-G x)
vcr-match-2-sr (ssplit2 (ss-left ss1) (ss-right ss2)) (there vcr1) (here-neg ina-G x) = nothing
vcr-match-2-sr (ssplit2 (ss-right ss1) ()) (there vcr1) (here-neg ina-G x)
vcr-match-2-sr (ssplit2 (ss-negpos ss1) (ss-right ss2)) (there vcr1) (here-neg ina-G x) = nothing
vcr-match-2-sr (ssplit2 ss-[] ()) (there vcr1) (there vcr2)
vcr-match-2-sr (ssplit2 (ss-both ss1) (ss-both ss2)) (there vcr1) (there vcr2) with vcr-match-2-sr (ssplit2 ss1 ss2) vcr1 vcr2
... | nothing = nothing
... | just (t2<=t1 , ds2<=s1 , _ , _ , _ , _ , ssplit2 ss1' ss2' , vcr1' , vcr2') = just (t2<=t1 , ds2<=s1 , _ , _ , _ , _ , (ssplit2 (ss-both ss1') (ss-both ss2')) , ((there vcr1') , (there vcr2')))
vcr-match-2-sr (ssplit2 (ss-right ss1) (ss-both ss2)) (there vcr1) (there vcr2) = map (λ { (t2<=t1 , ds2<=s1 , _ , _ , _ , _ , ssplit2 ss1' ss2' , vcr1' , vcr2') → t2<=t1 , ds2<=s1 , _ , _ , _ , _ , (ssplit2 (ss-right ss1') (ss-both ss2')) , (there vcr1') , (there vcr2') }) (vcr-match-2-sr (ssplit2 ss1 ss2) vcr1 vcr2)
vcr-match-2-sr (ssplit2 (ss-negpos ss1) ()) (there vcr1) (there vcr2)
vcr-match-2-sb : ∀ {G G₁ G₂ G₁₁ G₁₂ b₁ b₂ s₁₁ s₁₂ s₂₁ s₂₂}
→ SSplit2 G G₁ G₂ G₁₁ G₁₂
→ ChannelRef G₁₁ b₁ (sintern s₁₁ s₁₂)
→ ChannelRef G₁₂ b₂ (sextern s₂₁ s₂₂)
→ (lab : Selector)
→ Maybe (dual s₂₁ ≲ s₁₁ × dual s₂₂ ≲ s₁₂ ×
∃ λ G' → ∃ λ G₁' → ∃ λ G₁₁' → ∃ λ G₁₂' →
SSplit2 G' G₁' G₂ G₁₁' G₁₂' ×
ChannelRef G₁₁' b₁ (selection lab (SType.force s₁₁) (SType.force s₁₂)) ×
ChannelRef G₁₂' b₂ (selection lab (SType.force s₂₁) (SType.force s₂₂)))
vcr-match-2-sb (ssplit2 ss1 ss2) (here-pos ina-G (sub-sintern s1<=s1' s2<=s2')) (here-pos ina-G₁ (sub-sextern s1<=s1'' s2<=s2'')) lab = nothing
vcr-match-2-sb (ssplit2 ss-[] ()) (here-pos ina-G (sub-sintern s1<=s1' s2<=s2')) (here-neg ina-G₁ x₁) lab
vcr-match-2-sb (ssplit2 (ss-both ss1) ()) (here-pos ina-G (sub-sintern s1<=s1' s2<=s2')) (here-neg ina-G₁ x₁) lab
vcr-match-2-sb (ssplit2 (ss-left ss1) (ss-posneg ss2)) (here-pos ina-G (sub-sintern s1<=s1' s2<=s2')) (here-neg ina-G₁ (sub-sextern s1<=s1'' s2<=s2'')) Left = just ((sub-trans (dual-sub s1<=s1'') (sub-trans (eq-implies-sub (eq-sym (dual-involution _))) s1<=s1')) , (sub-trans (dual-sub s2<=s2'') (sub-trans (eq-implies-sub (eq-sym (dual-involution _))) s2<=s2')) , _ , _ , _ , _ , (ssplit2 (ss-left ss1) (ss-posneg ss2)) , (here-pos ina-G (Sub.force s1<=s1')) , (here-neg ina-G₁ (Sub.force s1<=s1'')))
vcr-match-2-sb (ssplit2 (ss-left ss1) (ss-posneg ss2)) (here-pos ina-G (sub-sintern s1<=s1' s2<=s2')) (here-neg ina-G₁ (sub-sextern s1<=s1'' s2<=s2'')) Right = just ((sub-trans (dual-sub s1<=s1'') (sub-trans (eq-implies-sub (eq-sym (dual-involution _))) s1<=s1')) , (sub-trans (dual-sub s2<=s2'') (sub-trans (eq-implies-sub (eq-sym (dual-involution _))) s2<=s2')) , _ , _ , _ , _ , (ssplit2 (ss-left ss1) (ss-posneg ss2)) , (here-pos ina-G (Sub.force s2<=s2')) , (here-neg ina-G₁ (Sub.force s2<=s2'')))
vcr-match-2-sb (ssplit2 (ss-right ss1) ()) (here-pos ina-G (sub-sintern s1<=s1' s2<=s2')) (here-neg ina-G₁ x₁) lab
vcr-match-2-sb (ssplit2 (ss-posneg ss1) ()) (here-pos ina-G (sub-sintern s1<=s1' s2<=s2')) (here-neg ina-G₁ x₁) lab
vcr-match-2-sb (ssplit2 (ss-negpos ss1) ()) (here-pos ina-G (sub-sintern s1<=s1' s2<=s2')) (here-neg ina-G₁ x₁) lab
vcr-match-2-sb (ssplit2 ss1 ss2) (here-pos ina-G x) (there vcr2) lab = nothing
vcr-match-2-sb (ssplit2 ss-[] ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextern s1<=s1' s2<=s2')) lab
vcr-match-2-sb (ssplit2 (ss-both ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextern s1<=s1' s2<=s2')) lab
vcr-match-2-sb (ssplit2 (ss-left ss1) (ss-negpos ss2)) (here-neg ina-G (sub-sintern s1<=s1'' s2<=s2'')) (here-pos ina-G₁ (sub-sextern s1<=s1' s2<=s2')) Left = just ((sub-trans (dual-sub s1<=s1') s1<=s1'') , ((sub-trans (dual-sub s2<=s2') s2<=s2'') , (_ , (_ , (_ , (_ , ((ssplit2 (ss-left ss1) (ss-negpos ss2)) , ((here-neg ina-G (Sub.force s1<=s1'')) , (here-pos ina-G₁ (Sub.force s1<=s1'))))))))))
vcr-match-2-sb (ssplit2 (ss-left ss1) (ss-negpos ss2)) (here-neg ina-G (sub-sintern s1<=s1'' s2<=s2'')) (here-pos ina-G₁ (sub-sextern s1<=s1' s2<=s2')) Right = just ((sub-trans (dual-sub s1<=s1') s1<=s1'') , ((sub-trans (dual-sub s2<=s2') s2<=s2'') , (_ , (_ , (_ , (_ , ((ssplit2 (ss-left ss1) (ss-negpos ss2)) , ((here-neg ina-G (Sub.force s2<=s2'')) , (here-pos ina-G₁ (Sub.force s2<=s2'))))))))))
vcr-match-2-sb (ssplit2 (ss-right ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextern s1<=s1' s2<=s2')) lab
vcr-match-2-sb (ssplit2 (ss-posneg ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextern s1<=s1' s2<=s2')) lab
vcr-match-2-sb (ssplit2 (ss-negpos ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextern s1<=s1' s2<=s2')) lab
vcr-match-2-sb (ssplit2 ss1 ss2) (here-neg ina-G x) (here-neg ina-G₁ x₁) lab = nothing
vcr-match-2-sb (ssplit2 ss1 ss2) (here-neg ina-G x) (there vcr2) lab = nothing
vcr-match-2-sb (ssplit2 ss1 ss2) (there vcr1) (here-pos ina-G x) lab = nothing
vcr-match-2-sb (ssplit2 ss1 ss2) (there vcr1) (here-neg ina-G x) lab = nothing
vcr-match-2-sb (ssplit2 ss-[] ()) (there vcr1) (there vcr2) lab
vcr-match-2-sb (ssplit2 (ss-both ss1) (ss-both ss2)) (there vcr1) (there vcr2) lab = map (λ { (ds21<=s11 , ds22<=s12 , _ , _ , _ , _ , ssplit2 ss1' ss2' , vcr1' , vcr2') → ds21<=s11 , ds22<=s12 , _ , _ , _ , _ , (ssplit2 (ss-both ss1') (ss-both ss2')) , ((there vcr1') , (there vcr2')) }) (vcr-match-2-sb (ssplit2 ss1 ss2) vcr1 vcr2 lab)
vcr-match-2-sb (ssplit2 (ss-left ss1) ()) (there vcr1) (there vcr2) lab
vcr-match-2-sb (ssplit2 (ss-right ss1) (ss-both ss2)) (there vcr1) (there vcr2) lab = map (λ { (ds21<=s11 , ds22<=s12 , _ , _ , _ , _ , ssplit2 ss1' ss2' , vcr1' , vcr2') → ds21<=s11 , ds22<=s12 , _ , _ , _ , _ , (ssplit2 (ss-right ss1') (ss-both ss2')) , ((there vcr1') , (there vcr2')) }) (vcr-match-2-sb (ssplit2 ss1 ss2) vcr1 vcr2 lab)
vcr-match-2-sb (ssplit2 (ss-posneg ss1) ()) (there vcr1) (there vcr2) lab
vcr-match-2-sb (ssplit2 (ss-negpos ss1) ()) (there vcr1) (there vcr2) lab
vcr-match-2-nsb : ∀ {G G₁ G₂ G₁₁ G₁₂ b₁ b₂ m₁ m₂ alti alte}
→ SSplit2 G G₁ G₂ G₁₁ G₁₂
→ ChannelRef G₁₁ b₁ (sintN m₁ alti)
→ ChannelRef G₁₂ b₂ (sextN m₂ alte)
→ (lab : Fin m₁)
→ Maybe (Σ (m₁ ≤ m₂) λ { p →
((i : Fin m₁) → dual (alti i) ≲ alte (inject≤ i p)) ×
∃ λ G' → ∃ λ G₁' → ∃ λ G₁₁' → ∃ λ G₁₂' →
SSplit2 G' G₁' G₂ G₁₁' G₁₂' ×
ChannelRef G₁₁' b₁ (SType.force (alti lab)) ×
ChannelRef G₁₂' b₂ (SType.force (alte (inject≤ lab p)))})
vcr-match-2-nsb (ssplit2 ss1 ss2) (here-pos ina-G _) (here-pos ina-G₁ _) lab = nothing
vcr-match-2-nsb (ssplit2 ss-[] ()) (here-pos ina-G (sub-sintN m'≤m x)) (here-neg ina-G₁ x₁) lab
vcr-match-2-nsb (ssplit2 (ss-both ss1) ()) (here-pos ina-G (sub-sintN m'≤m x)) (here-neg ina-G₁ x₁) lab
vcr-match-2-nsb {m₁ = m₁} {alti = alti} {alte = alte} (ssplit2 (ss-left ss1) (ss-posneg ss2)) (here-pos ina-G (sub-sintN {alt = alt} m'≤m subint)) (here-neg ina-G₁ (sub-sextN m≤m' subext)) lab = just (≤-trans m'≤m m≤m' , auxSub , _ , _ , _ , _ , (ssplit2 (ss-left ss1) (ss-posneg ss2)) , (here-pos ina-G (Sub.force (subint lab))) , (here-neg ina-G₁ auxExt))
where
auxSub : (i : Fin m₁) → dual (alti i) ≲ alte (inject≤ i (≤-trans m'≤m m≤m'))
auxSub i with subext (inject≤ i m'≤m)
... | r rewrite (inject-trans m≤m' m'≤m i) = sub-trans (dual-sub (subint i)) r
auxExt : dualF (SType.force (alt (inject≤ lab m'≤m))) ≲' SType.force (alte (inject≤ lab (≤-trans m'≤m m≤m')))
auxExt with Sub.force (subext (inject≤ lab m'≤m))
... | se rewrite inject-trans m≤m' m'≤m lab = se
vcr-match-2-nsb (ssplit2 (ss-right ss1) ()) (here-pos ina-G (sub-sintN m'≤m x)) (here-neg ina-G₁ x₁) lab
vcr-match-2-nsb (ssplit2 (ss-posneg ss1) ()) (here-pos ina-G (sub-sintN m'≤m x)) (here-neg ina-G₁ x₁) lab
vcr-match-2-nsb (ssplit2 (ss-negpos ss1) ()) (here-pos ina-G (sub-sintN m'≤m x)) (here-neg ina-G₁ x₁) lab
vcr-match-2-nsb (ssplit2 ss1 ss2) (here-pos ina-G x) (there vcr2) lab = nothing
vcr-match-2-nsb (ssplit2 ss-[] ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextN m≤m' x₁)) lab
vcr-match-2-nsb (ssplit2 (ss-both ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextN m≤m' x₁)) lab
vcr-match-2-nsb {m₁ = m₁} {alti = alti} {alte = alte} (ssplit2 (ss-left ss1) (ss-negpos ss2)) (here-neg ina-G (sub-sintN m'≤m subint)) (here-pos ina-G₁ (sub-sextN {alt = alt} m≤m' subext)) lab = just ((≤-trans m'≤m m≤m') , auxSub , _ , _ , _ , _ , ssplit2 (ss-left ss1) (ss-negpos ss2) , here-neg ina-G (Sub.force (subint lab)) , here-pos ina-G₁ auxExt)
where
auxSub : (i : Fin m₁) → dual (alti i) ≲ alte (inject≤ i (≤-trans m'≤m m≤m'))
auxSub i with subext (inject≤ i m'≤m)
... | sub2 rewrite (inject-trans m≤m' m'≤m i) =
sub-trans (sub-trans (dual-sub (subint i)) (eq-implies-sub (eq-sym (dual-involution _)))) sub2
auxExt : SType.force (alt (inject≤ lab m'≤m)) ≲' SType.force (alte (inject≤ lab (≤-trans m'≤m m≤m')))
auxExt with Sub.force (subext (inject≤ lab m'≤m))
... | se rewrite (inject-trans m≤m' m'≤m lab) = se
vcr-match-2-nsb (ssplit2 (ss-right ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextN m≤m' x₁)) lab
vcr-match-2-nsb (ssplit2 (ss-posneg ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextN m≤m' x₁)) lab
vcr-match-2-nsb (ssplit2 (ss-negpos ss1) ()) (here-neg ina-G x) (here-pos ina-G₁ (sub-sextN m≤m' x₁)) lab
vcr-match-2-nsb (ssplit2 ss1 ss2) (here-neg ina-G x) (here-neg ina-G₁ x₁) lab = nothing
vcr-match-2-nsb (ssplit2 ss1 ss2) (here-neg ina-G x) (there vcr2) lab = nothing
vcr-match-2-nsb (ssplit2 ss1 ss2) (there vcr1) (here-pos ina-G x) lab = nothing
vcr-match-2-nsb (ssplit2 ss1 ss2) (there vcr1) (here-neg ina-G x) lab = nothing
vcr-match-2-nsb (ssplit2 ss-[] ()) (there vcr1) (there vcr2) lab
vcr-match-2-nsb (ssplit2 (ss-both ss1) (ss-both ss2)) (there vcr1) (there vcr2) lab =
map (λ { (m1≤m2 , fdi≤e , _ , _ , _ , _ , ssplit2 ss1' ss2' , vcr1' , vcr2') → m1≤m2 , fdi≤e , _ , _ , _ , _ , (ssplit2 (ss-both ss1') (ss-both ss2')) , there vcr1' , there vcr2' })
(vcr-match-2-nsb (ssplit2 ss1 ss2) vcr1 vcr2 lab)
vcr-match-2-nsb (ssplit2 (ss-left ss1) ()) (there vcr1) (there vcr2) lab
vcr-match-2-nsb (ssplit2 (ss-right ss1) (ss-both ss2)) (there vcr1) (there vcr2) lab =
map (λ { (m1≤m2 , fdi≤e , _ , _ , _ , _ , ssplit2 ss1' ss2' , vcr1' , vcr2') → m1≤m2 , fdi≤e , _ , _ , _ , _ , (ssplit2 (ss-right ss1') (ss-both ss2')) , there vcr1' , there vcr2' })
(vcr-match-2-nsb (ssplit2 ss1 ss2) vcr1 vcr2 lab)
vcr-match-2-nsb (ssplit2 (ss-posneg ss1) ()) (there vcr1) (there vcr2) lab
vcr-match-2-nsb (ssplit2 (ss-negpos ss1) ()) (there vcr1) (there vcr2) lab
| {
"alphanum_fraction": 0.6227077202,
"avg_line_length": 79.2286995516,
"ext": "agda",
"hexsha": "ce4217504a9567ecca8b0eb6701bca131248a227",
"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/Channel.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/Channel.agda",
"max_line_length": 502,
"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/Channel.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": 7864,
"size": 17668
} |
module Structure.Categorical.Names where
import Lvl
open import Functional using (const ; swap)
open import Logic
open import Structure.Setoid
import Structure.Operator.Names as Names
import Structure.Relator.Names as Names
open import Type
private variable ℓₒ ℓₘ ℓₑ : Lvl.Level
private variable Obj : Type{ℓₒ}
private variable x y z w : Obj
-- Obj is the collection of objects.
-- _⟶_ is the collection of morphisms.
module _ (Morphism : Obj → Obj → Type{ℓₘ}) where
-- A morphism is an endomorphism when the domain and the codomain are equal.
-- Something which morphs itself (referring to the object).
Endomorphism : Obj → Stmt{ℓₘ}
Endomorphism a = Morphism a a
module ArrowNotation where
_⟶_ : Obj → Obj → Type{ℓₘ}
_⟶_ = Morphism
-- Reversed arrow
_⟵_ : Obj → Obj → Type{ℓₘ}
_⟵_ = swap(_⟶_)
-- Self-pointing arrow
⟲_ : Obj → Type{ℓₘ}
⟲_ = Endomorphism
module Morphism where
module _ (Morphism : Obj → Obj → Type{ℓₘ}) where
open ArrowNotation(Morphism)
-- The domain of a morphism
dom : ∀{x y : Obj} → Morphism(x)(y) → Obj
dom{x}{_} (_) = x
-- The codomain of a morphism
codom : ∀{x y : Obj} → Morphism(x)(y) → Obj
codom{_}{y} (_) = y
module _ {Morphism : Obj → Obj → Type{ℓₘ}} ⦃ equiv-morphism : ∀{x y} → Equiv{ℓₑ}(Morphism x y) ⦄ where
open ArrowNotation(Morphism)
module _ (_▫_ : Names.SwappedTransitivity(_⟶_)) where
Associativity : Stmt
Associativity = ∀{x y z w : Obj} → Names.AssociativityPattern {T₁ = z ⟶ w} {T₂ = y ⟶ z} {T₃ = x ⟶ y} (_▫_)(_▫_)(_▫_)(_▫_)
Idempotent : (x ⟶ x) → Stmt
Idempotent(f) = (f ▫ f ≡ f)
module _ (id : Names.Reflexivity(_⟶_)) where
Identityₗ : Stmt
Identityₗ = ∀{x y}{f : x ⟶ y} → (id ▫ f ≡ f)
Identityᵣ : Stmt
Identityᵣ = ∀{x y}{f : x ⟶ y} → (f ▫ id ≡ f)
Inverseₗ : (x ⟶ y) → (y ⟶ x) → Stmt
Inverseₗ(f)(f⁻¹) = (f⁻¹ ▫ f ≡ id)
Inverseᵣ : (x ⟶ y) → (y ⟶ x) → Stmt
Inverseᵣ(f)(f⁻¹) = (f ▫ f⁻¹ ≡ id)
Involution : (x ⟶ x) → Stmt
Involution(f) = Inverseᵣ f f
module Polymorphism where
module _ {Morphism : Obj → Obj → Type{ℓₘ}} ⦃ equiv-morphism : ∀{x y} → Equiv{ℓₑ}(Morphism x y) ⦄ where
open ArrowNotation(Morphism)
module _ (_▫_ : Names.SwappedTransitivity(_⟶_)) where
IdempotentOn : Obj → Obj → (∀{x y} → (x ⟶ y)) → Stmt
IdempotentOn(x)(z) (f) = ∀{y} → (f{y}{z} ▫ f{x}{y} ≡ f{x}{z})
module _ (id : Names.Reflexivity(_⟶_)) where
InvolutionOn : Obj → Obj → (∀{x y} → (x ⟶ y)) → Stmt
InvolutionOn(x)(y) (f) = (f{x}{y} ▫ f{y}{x} ≡ id{y})
Involution : (∀{x y} → (x ⟶ y)) → Stmt
Involution(f) = ∀{x y} → InvolutionOn(x)(y)(f)
| {
"alphanum_fraction": 0.5773722628,
"avg_line_length": 31.4942528736,
"ext": "agda",
"hexsha": "a8cbfbd65b08f57795f4710ab3d4f6d1d9bde86f",
"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/Categorical/Names.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/Categorical/Names.agda",
"max_line_length": 127,
"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/Categorical/Names.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": 1053,
"size": 2740
} |
{-# OPTIONS --cubical-compatible #-}
variable
@0 A : Set
record D : Set₁ where
field
f : A
| {
"alphanum_fraction": 0.5940594059,
"avg_line_length": 11.2222222222,
"ext": "agda",
"hexsha": "1513207f56f2efddc15b6fc0bd59e99fb2c88c47",
"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/Issue5410-4.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/Issue5410-4.agda",
"max_line_length": 36,
"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/Issue5410-4.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 32,
"size": 101
} |
module QuoteContext where
open import Common.Level
open import Common.Prelude
open import Common.Product
open import Common.Equality
open import Common.Reflection
Vec : Set → Nat → Set
Vec A zero = ⊤
Vec A (suc x) = A × Vec A x
test : (n : Nat) (v : Vec Nat n) (m : Nat) → List (Arg Type)
test zero v n = quoteContext
test (suc m) v n = quoteContext
test-zero : test 0 _ 0 ≡
vArg (def (quote Nat) []) ∷
vArg (def (quote ⊤) []) ∷ []
test-zero = refl
test-suc : test 1 (zero , _) 0 ≡
vArg (def (quote Nat) []) ∷
vArg
(def (quote Σ)
(hArg (def (quote lzero) []) ∷
hArg (def (quote lzero) []) ∷
vArg (def (quote Nat) []) ∷
vArg (lam visible (abs "x" (def (quote Vec)
(vArg (def (quote Nat) []) ∷
vArg (var 1 []) ∷ [])))) ∷ [])) ∷
vArg (def (quote Nat) []) ∷ []
test-suc = refl
| {
"alphanum_fraction": 0.5680190931,
"avg_line_length": 24.6470588235,
"ext": "agda",
"hexsha": "40725884eb72a8034e69a7319bde78c36872630a",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/QuoteContext.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"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": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/QuoteContext.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/QuoteContext.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 302,
"size": 838
} |
data D (A : Set) : Set where
c : A → D A
postulate
f : (A : Set) → D A → D A
P : (A : Set) → D A → Set
_ : (A : Set) (B : _) (g : A → B) → P _ (f _ (c g))
| {
"alphanum_fraction": 0.3963414634,
"avg_line_length": 20.5,
"ext": "agda",
"hexsha": "001385ebd0afd788a68776999b1d4b13525fad21",
"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/Issue4969.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/Issue4969.agda",
"max_line_length": 53,
"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/Issue4969.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": 80,
"size": 164
} |
{-# OPTIONS --cumulativity #-}
open import Agda.Primitive
open import Agda.Builtin.Equality
lone ltwo lthree : Level
lone = lsuc lzero
ltwo = lsuc lone
lthree = lsuc ltwo
fails : _≡_ {a = lthree} {A = Set₂} Set₀ Set₁
fails = refl
| {
"alphanum_fraction": 0.7081545064,
"avg_line_length": 17.9230769231,
"ext": "agda",
"hexsha": "6ffc5506881ae9a8ac2baba30ddb840720831e60",
"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/Cumulativity-inequal-universes.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/Cumulativity-inequal-universes.agda",
"max_line_length": 45,
"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/Cumulativity-inequal-universes.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": 82,
"size": 233
} |
open import Agda.Builtin.Unit
open import Agda.Builtin.Bool
open import Agda.Builtin.List
open import Agda.Builtin.Reflection
open import Agda.Builtin.Equality
variable
A B : Set
data Eqn (A : Set) : Set where
eqn : (x y : A) → x ≡ y → Eqn A
infix 3 _==_
pattern _==_ x y = eqn x y refl
infixl 0 such-that
syntax such-that a (λ x → P) p = a is x such-that p proves P
such-that : (x : A) (P : A → Set) → P x → A
such-that x _ _ = x
infix -1 check_
check_ : A → ⊤
check _ = _
infixl -2 _and_
_and_ : ⊤ → A → ⊤
_ and _ = _
-- Record fields can be marked with @tactic
data ShouldRun : Set where
run norun : ShouldRun
defaultTo : {A : Set} (x : A) → ShouldRun → Term → TC ⊤
defaultTo _ norun _ = typeError (strErr "Should not run!" ∷ [])
defaultTo x run hole = bindTC (quoteTC x) (unify hole)
record Class (r : ShouldRun) : Set where
constructor con
field
x : Bool
@(tactic defaultTo x r) {y} : Bool
open Class
-- # Cases where the tactic should run
test₁ test₂ test₃ : Class run
test₁ = con true -- Constructor application
test₂ = record { x = true } -- Record construction
test₃ .x = true -- Missing copattern clause
_ = check test₁ == con true {true}
and test₂ == con true {true}
and test₃ == con true {true}
-- More elaborate missing copatterns
test₃′ : List Bool → Class run
test₃′ [] .x = false
test₃′ [] .y = true
test₃′ (b ∷ _) .x = b
_ =
check test₃′ [] == con false {true}
and λ b → test₃′ (b ∷ []) == con b {b}
-- # Cases where the tactic should not run
-- ## Giving the field explicitly
test₄ test₅ : Class norun
test₄ = con true {_} is c such-that refl proves c .y ≡ false
test₅ = record{ x = true; y = _ } is c such-that refl proves c .y ≡ false
_ = check test₄ == con true {false}
and test₅ == con true {false}
-- ## Eta-expansion
-- Eta-expansion of record metas should *not* trigger the tactic, since that
-- would make eta-expansion potentially lose solutions. For instance,
-- `con true {false} == _1`. Here solving `_1 := con true {false}` is valid, but
-- eta-expanding to `con _2 {_3}` and running `defaultTo _2 _3` leads to an error.
test₆ : Class norun
test₆ =
_ is c such-that refl proves c .x ≡ true
is c such-that refl proves c .y ≡ false
check₆ : test₆ ≡ con true {false}
check₆ = refl
| {
"alphanum_fraction": 0.6315789474,
"avg_line_length": 25.6086956522,
"ext": "agda",
"hexsha": "f20aeb46860ff15ec2b9ce6e4cb56db516dd449d",
"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/Issue4124.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/Issue4124.agda",
"max_line_length": 82,
"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/Issue4124.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": 770,
"size": 2356
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A module used for creating function pipelines, see
-- README.Function.Reasoning for examples
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Function.Reasoning where
open import Function using (_∋_)
-- Need to give _∋_ a new name as syntax cannot contain underscores
infixl 0 ∋-syntax
∋-syntax = _∋_
-- Create ∶ syntax
syntax ∋-syntax A a = a ∶ A
-- Export pipeline functions
open import Function public using (_|>_; _|>′_)
| {
"alphanum_fraction": 0.5404958678,
"avg_line_length": 26.3043478261,
"ext": "agda",
"hexsha": "aee44dcfd728cb21d5665ac77fc60c7f12f277b5",
"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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Function/Reasoning.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"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": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Function/Reasoning.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Function/Reasoning.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 129,
"size": 605
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
module Function.Surjective.Properties where
open import Path
open import Function.Fiber
open import Level
open import HITs.PropositionalTruncation
open import Data.Sigma
open import Function.Surjective.Base
open import Function.Injective.Base
open import Function.Injective.Properties
open import Path.Reasoning
open import Relation.Nullary.Discrete
open import Function
surj-to-inj : (A ↠! B) → (B ↣ A)
surj-to-inj (f , surj) .fst x = surj x .fst
surj-to-inj (f , surj) .snd x y f⁻¹⟨x⟩≡f⁻¹⟨y⟩ =
x ≡˘⟨ surj x .snd ⟩
f (surj x .fst) ≡⟨ cong f f⁻¹⟨x⟩≡f⁻¹⟨y⟩ ⟩
f (surj y .fst) ≡⟨ surj y .snd ⟩
y ∎
Discrete-distrib-surj : (A ↠! B) → Discrete A → Discrete B
Discrete-distrib-surj = Discrete-pull-inj ∘ surj-to-inj
SplitSurjective⟨id⟩ : SplitSurjective (id {A = A})
SplitSurjective⟨id⟩ x .fst = x
SplitSurjective⟨id⟩ x .snd _ = x
↠!-ident : A ↠! A
↠!-ident .fst = id
↠!-ident .snd y .fst = y
↠!-ident .snd y .snd _ = y
↠!-comp : A ↠! B → B ↠! C → A ↠! C
↠!-comp a→b b→c .fst = b→c .fst ∘ a→b .fst
↠!-comp a→b b→c .snd y .fst = a→b .snd (b→c .snd y .fst) .fst
↠!-comp a→b b→c .snd y .snd = cong (fst b→c) (snd (snd a→b (fst (snd b→c y)))) ; snd (snd b→c y)
| {
"alphanum_fraction": 0.6370250606,
"avg_line_length": 30.925,
"ext": "agda",
"hexsha": "c3c0b60fdedae679ff26d4238aa9f16a1f9fff26",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Function/Surjective/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"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/agda-playground",
"max_issues_repo_path": "Function/Surjective/Properties.agda",
"max_line_length": 96,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Function/Surjective/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 525,
"size": 1237
} |
module Data.Collection.Properties where
open import Data.Collection.Core
open import Data.Collection.Equivalence
open import Data.Collection.Inclusion
open import Data.Collection
open import Data.Sum renaming (map to mapSum)
open import Data.Product
open import Function.Equivalence using (_⇔_; equivalence)
-- open import Data.List public using (List; []; _∷_)
-- open import Data.String public using (String; _≟_)
-- open import Level using (zero)
--
open import Function using (id; _∘_)
open import Relation.Nullary
open import Relation.Nullary.Negation
-- open import Relation.Nullary.Decidable renaming (map to mapDec; map′ to mapDec′)
open import Relation.Unary
-- open import Relation.Binary
open import Relation.Binary.PropositionalEquality
--------------------------------------------------------------------------------
-- Singleton
--------------------------------------------------------------------------------
singleton-≡ : ∀ {x y} → x ∈ c[ singleton y ] ⇔ x ≡ y
singleton-≡ = equivalence to from
where to : ∀ {x y} → x ∈ c[ singleton y ] → x ≡ y
to here = refl
to (there ())
from : ∀ {x y} → x ≡ y → x ∈ c[ singleton y ]
from refl = here
--------------------------------------------------------------------------------
-- Delete
--------------------------------------------------------------------------------
-- still-∈-after-deleted : ∀ {x} y A → x ≢ y → x ∈ c[ A ] → x ∈ c[ delete y A ]
still-∈-after-deleted : ∀ y A → c[ A ] ⊆[ _≢_ y ] c[ delete y A ]
still-∈-after-deleted y [] ≢y ()
still-∈-after-deleted y (a ∷ A) {x} ≢y ∈A with y ≟ a
still-∈-after-deleted y (a ∷ A) ≢y here | yes p = contradiction p ≢y
still-∈-after-deleted y (a ∷ A) ≢y (there ∈A) | yes p = still-∈-after-deleted y A ≢y ∈A
still-∈-after-deleted y (x ∷ A) ≢y here | no ¬p = here
still-∈-after-deleted y (a ∷ A) ≢y (there ∈A) | no ¬p = there (still-∈-after-deleted y A ≢y ∈A)
-- still-∉-after-recovered : ∀ {x} y A → x ≢ y → x ∉c delete y A → x ∉ c[ A ]
still-∉-after-recovered : ∀ y A → c[ delete y A ] ⊈[ _≢_ y ] c[ A ]
still-∉-after-recovered y [] ≢y ∉A-y ()
still-∉-after-recovered y (a ∷ A) ≢y ∉A-y ∈a∷A with y ≟ a
still-∉-after-recovered y (a ∷ A) ≢y ∉A-y here | yes p = contradiction p ≢y
still-∉-after-recovered y (a ∷ A) ≢y ∉A-y (there ∈A) | yes p = contradiction (still-∈-after-deleted y A ≢y ∈A) ∉A-y
still-∉-after-recovered y (a ∷ A) ≢y ∉A-y here | no ¬p = contradiction here ∉A-y
still-∉-after-recovered y (a ∷ A) ≢y ∉A-y (there ∈A) | no ¬p = contradiction (there (still-∈-after-deleted y A ≢y ∈A)) ∉A-y
--------------------------------------------------------------------------------
-- Union
--------------------------------------------------------------------------------
in-right-union : ∀ A B → c[ B ] ⊆ c[ union A B ]
in-right-union [] B x∈B = x∈B
in-right-union (a ∷ A) B x∈B with a ∈? B
in-right-union (a ∷ A) B x∈B | yes p = in-right-union A B x∈B
in-right-union (a ∷ A) B x∈B | no ¬p = there (in-right-union A B x∈B)
in-left-union : ∀ A B → c[ A ] ⊆ c[ union A B ]
in-left-union [] B ()
in-left-union (a ∷ A) B x∈A with a ∈? B
in-left-union (a ∷ A) B here | yes p = in-right-union A B p
in-left-union (a ∷ A) B (there x∈A) | yes p = in-left-union A B x∈A
in-left-union (a ∷ A) B here | no ¬p = here
in-left-union (a ∷ A) B (there x∈A) | no ¬p = there (in-left-union A B x∈A)
∪-left-identity : ∀ A → c[ [] ] ∪ c[ A ] ≋ c[ A ]
∪-left-identity A = equivalence to inj₂
where
to : c[ [] ] ∪ c[ A ] ⊆ c[ A ]
to (inj₁ ())
to (inj₂ ∈A) = ∈A
∪-right-identity : ∀ A → c[ A ] ∪ c[ [] ] ≋ c[ A ]
∪-right-identity A = equivalence to inj₁
where
to : c[ A ] ∪ c[ [] ] ⊆ c[ A ]
to (inj₁ ∈A) = ∈A
to (inj₂ ())
in-either : ∀ A B → c[ union A B ] ⊆ c[ A ] ∪ c[ B ]
in-either [] B x∈A∪B = inj₂ x∈A∪B
in-either (a ∷ A) B x∈A∪B with a ∈? B
in-either (a ∷ A) B x∈A∪B | yes p = mapSum there id (in-either A B x∈A∪B)
in-either (a ∷ A) B here | no ¬p = inj₁ here
in-either (a ∷ A) B (there x∈A∪B) | no ¬p = mapSum there id (in-either A B x∈A∪B)
not-in-left-union : ∀ A B → c[ union A B ] ⊈ c[ A ]
not-in-left-union A B ∉union ∈A = contradiction (in-left-union A B ∈A) ∉union
not-in-right-union : ∀ A B → c[ union A B ] ⊈ c[ B ]
not-in-right-union A B ∉union ∈A = contradiction (in-right-union A B ∈A) ∉union
in-neither : ∀ A B → c[ union A B ] ⊈ c[ A ] ∪ c[ B ]
in-neither A B ∉union (inj₁ ∈A) = contradiction (in-left-union A B ∈A) ∉union
in-neither A B ∉union (inj₂ ∈B) = contradiction (in-right-union A B ∈B) ∉union
∪-union : ∀ A B → c[ A ] ∪ c[ B ] ≋ c[ union A B ]
∪-union A B = equivalence to (in-either A B)
where to : ∀ {x} → x ∈ c[ A ] ∪ c[ B ] → x ∈ c[ union A B ]
to (inj₁ ∈A) = in-left-union A B ∈A
to (inj₂ ∈B) = in-right-union A B ∈B
head-∈ : ∀ a A B → c[ a ∷ A ] ⊆ c[ B ] → a ∈ c[ B ]
head-∈ a A B ⊆B = ⊆B here
tail-⊆ : ∀ a A B → c[ a ∷ A ] ⊆ c[ B ] → c[ A ] ⊆ c[ B ]
tail-⊆ a A B ⊆B ∈A = ⊆B (there ∈A)
union-monotone : ∀ {A B C D a} (P : String → Set a) → c[ A ] ⊆[ P ] c[ C ] → c[ B ] ⊆[ P ] c[ D ] → c[ union A B ] ⊆[ P ] c[ union C D ]
union-monotone {[]} {B} {C} {D} P A⊆C B⊆D ∈P ∈A∪B = in-right-union C D (B⊆D ∈P ∈A∪B)
union-monotone {a ∷ A} {B} {C} {D} P A⊆C B⊆D ∈P ∈A∪B with a ∈? B
union-monotone {a ∷ A} P A⊆C B⊆D ∈P ∈A∪B | yes p = union-monotone P (λ P A → A⊆C P (there A)) B⊆D ∈P ∈A∪B
union-monotone {a ∷ A} {B} {C} {D} P A⊆C B⊆D ∈P here | no ¬p = in-left-union C D (A⊆C ∈P here)
union-monotone {a ∷ A} P A⊆C B⊆D ∈P (there ∈A∪B) | no ¬p = union-monotone P (λ P₁ A₁ → A⊆C P₁ (there A₁)) B⊆D ∈P ∈A∪B
-- union-monotone {A} P A⊆C B⊆D ∈P ∈A∪B = {! !}
-- union-monotone : ∀ A B C D → c[ A ] ⊆ c[ C ] → c[ B ] ⊆ c[ D ] → c[ union A B ] ⊆ c[ union C D ]
-- union-monotone [] ._ C D A⊆C B⊆D here = in-right-union C D (B⊆D here)
-- union-monotone [] ._ C D A⊆C B⊆D (there ∈A∪B) = in-right-union C D (B⊆D (there ∈A∪B))
-- union-monotone (a ∷ A) B C D A⊆C B⊆D ∈A∪B with a ∈? B
-- union-monotone (a ∷ A) B C D A⊆C B⊆D ∈A∪B | yes p = union-monotone A B C D (A⊆C ∘ there) B⊆D ∈A∪B
-- union-monotone (a ∷ A) B C D A⊆C B⊆D here | no ¬p = in-left-union C D (A⊆C here)
-- union-monotone (a ∷ A) B C D A⊆C B⊆D (there ∈A∪B) | no ¬p = union-monotone A B C D (A⊆C ∘ there) B⊆D ∈A∪B
| {
"alphanum_fraction": 0.499611137,
"avg_line_length": 47.9776119403,
"ext": "agda",
"hexsha": "71f955177489b7b3f4f6b6b4141de7b8dae8ccec",
"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": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/lambda-calculus",
"max_forks_repo_path": "Data/Collection/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"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": "banacorn/lambda-calculus",
"max_issues_repo_path": "Data/Collection/Properties.agda",
"max_line_length": 136,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/lambda-calculus",
"max_stars_repo_path": "Data/Collection/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2614,
"size": 6429
} |
-- Classical propositional logic, de Bruijn approach, initial encoding
module Bi.Cp where
open import Lib using (List; _,_; LMem; lzero; lsuc)
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Set
Cx = List Ty
isTrue : Ty -> Cx -> Set
isTrue a tc = LMem a tc
-- Terms
module Cp where
infixl 1 _$_
infixr 0 lam=>_
infixr 0 abort=>_
data Tm (tc : Cx) : Ty -> Set where
var : forall {a} -> isTrue a tc -> Tm tc a
lam=>_ : forall {a b} -> Tm (tc , a) b -> Tm tc (a => b)
_$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b
pair' : forall {a b} -> Tm tc a -> Tm tc b -> Tm tc (a && b)
fst : forall {a b} -> Tm tc (a && b) -> Tm tc a
snd : forall {a b} -> Tm tc (a && b) -> Tm tc b
left : forall {a b} -> Tm tc a -> Tm tc (a || b)
right : forall {a b} -> Tm tc b -> Tm tc (a || b)
case' : forall {a b c} -> Tm tc (a || b) -> Tm (tc , a) c -> Tm (tc , b) c -> Tm tc c
abort=>_ : forall {a} -> Tm (tc , NOT a) FALSE -> Tm tc a
syntax pair' x y = [ x , y ]
syntax case' xy x y = case xy => x => y
v0 : forall {tc a} -> Tm (tc , a) a
v0 = var lzero
v1 : forall {tc a b} -> Tm (tc , a , b) a
v1 = var (lsuc lzero)
v2 : forall {tc a b c} -> Tm (tc , a , b , c) a
v2 = var (lsuc (lsuc lzero))
Thm : Ty -> Set
Thm a = forall {tc} -> Tm tc a
open Cp public
| {
"alphanum_fraction": 0.4543946932,
"avg_line_length": 24.7808219178,
"ext": "agda",
"hexsha": "022960ac658c10958a378be65d198aa42fa36850",
"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": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Bi/Cp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Bi/Cp.agda",
"max_line_length": 92,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Bi/Cp.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 701,
"size": 1809
} |
module _ where
open import Function.Iteration using (repeatᵣ ; repeatₗ)
[+]-repeatᵣ-𝐒 : ∀{x y z : ℕ} → (x + y ≡ repeatᵣ y (const 𝐒) z x)
[+]-repeatᵣ-𝐒 {x} {𝟎} = [≡]-intro
[+]-repeatᵣ-𝐒 {x} {𝐒 y} {z} = congruence₁(𝐒) ([+]-repeatᵣ-𝐒 {x} {y} {z})
[+]-repeatₗ-𝐒 : ∀{x y z : ℕ} → (x + y ≡ repeatₗ y (const ∘ 𝐒) x z)
[+]-repeatₗ-𝐒 {x} {𝟎} = [≡]-intro
[+]-repeatₗ-𝐒 {x} {𝐒 y} {z} = congruence₁(𝐒) ([+]-repeatₗ-𝐒 {x} {y} {z})
[⋅]-repeatᵣ-[+] : ∀{x y} → (x ⋅ y ≡ repeatᵣ y (_+_) x 0)
[⋅]-repeatᵣ-[+] {x} {𝟎} = [≡]-intro
[⋅]-repeatᵣ-[+] {x} {𝐒 y} = congruence₁(x +_) ([⋅]-repeatᵣ-[+] {x} {y})
[^]-repeatᵣ-[⋅] : ∀{x y} → (x ^ y ≡ repeatᵣ y (_⋅_) x 1)
[^]-repeatᵣ-[⋅] {x} {𝟎} = [≡]-intro
[^]-repeatᵣ-[⋅] {x} {𝐒 y} = congruence₁(x ⋅_) ([^]-repeatᵣ-[⋅] {x} {y})
| {
"alphanum_fraction": 0.4629388817,
"avg_line_length": 38.45,
"ext": "agda",
"hexsha": "b54b1c830eb9832953dab45fb6554c9608f06d8f",
"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": "Numeral/Natural/Oper/Proofs/Iteration.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": "Numeral/Natural/Oper/Proofs/Iteration.agda",
"max_line_length": 72,
"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": "Numeral/Natural/Oper/Proofs/Iteration.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": 482,
"size": 769
} |
-- Andreas, 2015-11-10, issue reported by Wolfram Kahl
-- {-# OPTIONS -v scope.mod.inst:30 #-}
-- {-# OPTIONS -v tc.mod.check:10 -v tc.mod.apply:80 -v impossible:10 #-}
postulate
A : Set
a : A
module Id (A : Set) (a : A) where
x = a
module ModParamsToLoose (A : Set) where
private module M (a : A) where module I = Id A a
open M public
open ModParamsToLoose A
open I a
y : A
y = x
| {
"alphanum_fraction": 0.6313131313,
"avg_line_length": 18.8571428571,
"ext": "agda",
"hexsha": "82db01dce93a14b091aceb91330a431a503088a1",
"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/Issue1701b.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/Issue1701b.agda",
"max_line_length": 73,
"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/Issue1701b.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": 142,
"size": 396
} |
open import FRP.JS.String using ( String )
open import FRP.JS.Time using ( Time ; _+_ )
open import FRP.JS.Behaviour using ( Beh ; map ; [_] ; join )
open import FRP.JS.DOM using ( DOM ; text )
open import FRP.JS.RSet using ( ⟦_⟧; ⟨_⟩ )
open import FRP.JS.Time using ( toUTCString ; every )
open import FRP.JS.Delay using ( _sec ; _min )
module FRP.JS.Demo.FastClock where
model : ⟦ Beh ⟨ Time ⟩ ⟧
model = map (λ t → t + 5 min) (every (1 sec))
view : ∀ {w} → ⟦ Beh (DOM w) ⟧
view = join (map (λ t → text [ toUTCString t ]) model)
main : ∀ {w} → ⟦ Beh (DOM w) ⟧
main = view
| {
"alphanum_fraction": 0.6273830156,
"avg_line_length": 30.3684210526,
"ext": "agda",
"hexsha": "97c4cf47e3f4aa31324ea1e4f8529a392cc0bf1e",
"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/FastClock.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/FastClock.agda",
"max_line_length": 61,
"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/FastClock.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": 207,
"size": 577
} |
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
postulate
A : Set
B : A → Set
a : A
Pi : (A → Set) → Set
Pi B = {x : A} → B x
foo : Pi \ y → Σ (B y) \ _ → Pi \ z → Σ (y ≡ a → B z) \ _ → B y → B z → A
foo = {!!} , (\ { refl → {!!} }) , {!!}
| {
"alphanum_fraction": 0.456928839,
"avg_line_length": 19.0714285714,
"ext": "agda",
"hexsha": "e077c65fb4e69ddc5451db4adcd6eb9b1e20eebf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/interaction/Issue3678.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/interaction/Issue3678.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/interaction/Issue3678.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 117,
"size": 267
} |
{-# OPTIONS --without-K #-}
open import Prelude
import GSeTT.Syntax
import GSeTT.Rules
import GSeTT.Typed-Syntax
open import MCaTT.Desuspension
open import CaTT.Ps-contexts
import CaTT.CaTT
module MCaTT.MCaTT where
J = CaTT.CaTT.J
eqdecJ = CaTT.CaTT.eqdecJ
open import Globular-TT.Syntax J
↓C : Pre-Ctx → Pre-Ctx
↓T : Pre-Ctx → Pre-Ty → Pre-Ty
↓t : Pre-Ctx → Pre-Tm → Pre-Tm
↓S : Pre-Ctx → Pre-Sub → Pre-Sub
↓C ⊘ = ⊘
↓C (Γ ∙ x # ∗) = ↓C Γ
↓C (Γ ∙ x # A@(_ ⇒[ _ ] _)) = (↓C Γ) ∙ x # (↓T Γ A)
↓T Γ ∗ = ∗
↓T Γ (t ⇒[ ∗ ] u) = ∗
↓T Γ (t ⇒[ A@(_ ⇒[ _ ] _) ] u) = (↓t Γ t) ⇒[ ↓T Γ A ] (↓t Γ u)
count-objects-in_until_ : Pre-Ctx → ℕ → ℕ
count-objects-in ⊘ until x = 0
count-objects-in Γ ∙ y # ∗ until x with dec-≤ y x
... | inl y≤x = S (count-objects-in Γ until x)
... | inr x<y = count-objects-in Γ until x
count-objects-in Γ ∙ y # (_ ⇒[ _ ] _) until x = count-objects-in Γ until x
↓t Γ (Var x) = Var (x - (count-objects-in Γ until x))
↓t Δ (Tm-constructor i@(((Γ , _) , _) , _) γ) = Tm-constructor i (↓S (GPre-Ctx Γ) γ)
↓S Γ <> = <>
↓S Γ < γ , x ↦ t > = < ↓S Γ γ , x ↦ ↓t Γ t >
rule : J → GSeTT.Typed-Syntax.Ctx × Pre-Ty
rule (((Γ , Γ⊢ps) , A) , _) =
let Γ⊢ = Γ⊢ps→Γ⊢ Γ⊢ps in
(↓GC Γ Γ⊢ , ↓⊢C Γ Γ⊢) , ↓T (GPre-Ctx Γ) (CaTT.CaTT.Ty→Pre-Ty A)
open import Globular-TT.Rules J rule
open import Globular-TT.CwF-Structure J rule
open import Globular-TT.Uniqueness-Derivations J rule eqdecJ
open import Globular-TT.Disks J rule eqdecJ
| {
"alphanum_fraction": 0.5650433622,
"avg_line_length": 28.2830188679,
"ext": "agda",
"hexsha": "9e53864868d9cfc31537bfacb1c0175558ff66ad",
"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": "ed45935b38d6a86fa662f561866140122ee3dcef",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ThiBen/catt-formalization",
"max_forks_repo_path": "MCaTT/MCaTT.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed45935b38d6a86fa662f561866140122ee3dcef",
"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": "ThiBen/catt-formalization",
"max_issues_repo_path": "MCaTT/MCaTT.agda",
"max_line_length": 86,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "ed45935b38d6a86fa662f561866140122ee3dcef",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ThiBen/catt-formalization",
"max_stars_repo_path": "MCaTT/MCaTT.agda",
"max_stars_repo_stars_event_max_datetime": "2020-05-20T00:41:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-01T08:26:53.000Z",
"num_tokens": 665,
"size": 1499
} |
-- Andreas, 2015-12-05 issue reported by Conor
-- {-# OPTIONS -v tc.cover.splittree:10 -v tc.cc:20 #-}
module Issue1734 where
infix 4 _≡_
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
record One : Set where constructor <>
data Two : Set where tt ff : Two
-- two : ∀{α}{A : Set α} → A → A → Two → A
two : (S T : Set) → Two → Set
two a b tt = a
two a b ff = b
record Sg (S : Set)(T : S -> Set) : Set where
constructor _,_
field
fst : S
snd : T fst
open Sg public
_+_ : Set -> Set -> Set
S + T = Sg Two (two S T)
data Twoey : Two -> Set where
ffey : Twoey ff
ttey : Twoey tt
postulate Thingy : Set
ThingyIf : Two -> Set
ThingyIf tt = Thingy
ThingyIf ff = One
thingy? : (b : Two) -> ThingyIf b -> Twoey b + One -> Thingy + One
thingy? .ff <> (tt , ffey) = ff , <>
thingy? .tt x (tt , ttey) = tt , x
thingy? _ _ _ = ff , <>
-- WORKS: thingy? _ _ (ff , _ ) = ff , <>
{- Correct split tree
split at 2
|
`- Issue1734.Sg._,_ -> split at 2
|
+- Issue1734.Two.tt -> split at 2
| |
| +- Issue1734.Twoey.ffey -> split at 1
| | |
| | `- Issue1734.One.<> -> done, 0 bindings
| |
| `- Issue1734.Twoey.ttey -> done, 1 bindings
|
`- Issue1734.Two.ff -> done, 3 bindings
but clause compiler deviated from it:
thingy? b x p =
case p of (y , z) ->
case y of
tt -> case x of
<> -> case z of
ffey -> ff , <>
ttey -> tt , <>
_ -> case z of
ttey -> tt , x
_ -> ff , <>
compiled clauses (still containing record splits)
case 2 of
Issue1734.Sg._,_ ->
case 2 of
Issue1734.Two.tt ->
case 1 of
Issue1734.One.<> ->
case 1 of
Issue1734.Twoey.ffey -> ff , <>
Issue1734.Twoey.ttey -> tt , <>
_ -> case 2 of
Issue1734.Twoey.ttey -> tt , x
_ -> ff , <>
-}
test1 : ∀ x → thingy? tt x (tt , ttey) ≡ tt , x
test1 = λ x → refl -- should pass!
first-eq-works : ∀ x → thingy? ff x (tt , ffey) ≡ ff , x
first-eq-works = λ x → refl
-- It's weird. I couldn't make it happen with Twoey b alone: I needed Twoey b + One.
-- I also checked that reordering the arguments made it go away. This...
thygni? : (b : Two) -> Twoey b + One -> ThingyIf b -> Thingy + One
thygni? .ff (tt , ffey) <> = ff , <>
thygni? .tt (tt , ttey) x = tt , x
thygni? _ _ _ = ff , <>
works : ∀ x → thygni? tt (tt , ttey) x ≡ tt , x
works = λ x → refl
-- Moreover, replacing the gratuitous <> pattern by a variable...
hingy? : (b : Two) -> ThingyIf b -> Twoey b + One -> Thingy + One
hingy? .ff x (tt , ffey) = ff , <>
hingy? .tt x (tt , ttey) = tt , x
hingy? _ _ _ = ff , <>
-- ...gives...
works2 : ∀ x → hingy? tt x (tt , ttey) ≡ tt , x
works2 = λ x -> refl
-- ...and it has to be a variable: an _ gives the same outcome as <>.
| {
"alphanum_fraction": 0.5202072539,
"avg_line_length": 23.3467741935,
"ext": "agda",
"hexsha": "57d93ff6b26c0c1dfe0b4246aeb0e218b9b65466",
"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/Issue1734.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/Issue1734.agda",
"max_line_length": 84,
"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/Issue1734.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": 1055,
"size": 2895
} |
-- Andreas, 2018-10-16, wrong quantity in lambda-abstraction
applyErased : {@0 A B : Set} → (@0 A → B) → @0 A → B
applyErased f x = f x
test : {A : Set} → A → A
test x = applyErased (λ (@ω y) → y) x
-- Expected error:
--
-- Wrong quantity annotation in lambda abstraction.
--
-- Current error (because @ω as default quantity is ignored):
--
-- Variable y is declared erased, so it cannot be used here
-- when checking that the expression y has type _B_7
| {
"alphanum_fraction": 0.6630196937,
"avg_line_length": 26.8823529412,
"ext": "agda",
"hexsha": "8aa26835cccd1fff9aa5d7b85ae1180fb8ee09be",
"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/Erasure-Lambda-Wrong-Attribute.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/Erasure-Lambda-Wrong-Attribute.agda",
"max_line_length": 61,
"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/Erasure-Lambda-Wrong-Attribute.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": 137,
"size": 457
} |
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Semirings.Definition
open import Numbers.Naturals.Order
open import Numbers.Naturals.Semiring
module Numbers.Naturals.Order.Lemmas where
open Semiring ℕSemiring
inequalityShrinkRight : {a b c : ℕ} → a +N b <N c → b <N c
inequalityShrinkRight {a} {b} {c} (le x proof) = le (x +N a) (transitivity (applyEquality succ (equalityCommutative (Semiring.+Associative ℕSemiring x a b))) proof)
inequalityShrinkLeft : {a b c : ℕ} → a +N b <N c → a <N c
inequalityShrinkLeft {a} {b} {c} (le x proof) = le (x +N b) (transitivity (applyEquality succ (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring x b a)) (applyEquality (x +N_) (Semiring.commutative ℕSemiring b a)))) proof)
productCancelsRight : (a b c : ℕ) → (zero <N a) → (b *N a ≡ c *N a) → (b ≡ c)
productCancelsRight a zero zero aPos eq = refl
productCancelsRight zero zero (succ c) (le x ()) eq
productCancelsRight (succ a) zero (succ c) aPos eq = contr
where
h : zero ≡ succ c *N succ a
h = eq
contr : zero ≡ succ c
contr = exFalso (naughtE h)
productCancelsRight zero (succ b) zero (le x ()) eq
productCancelsRight (succ a) (succ b) zero aPos eq = contr
where
h : succ b *N succ a ≡ zero
h = eq
contr : succ b ≡ zero
contr = exFalso (naughtE (equalityCommutative h))
productCancelsRight zero (succ b) (succ c) (le x ()) eq
productCancelsRight (succ a) (succ b) (succ c) aPos eq = applyEquality succ (productCancelsRight (succ a) b c aPos l)
where
i : succ a +N b *N succ a ≡ succ c *N succ a
i = eq
j : succ c *N succ a ≡ succ a +N c *N succ a
j = refl
k : succ a +N b *N succ a ≡ succ a +N c *N succ a
k = transitivity i j
l : b *N succ a ≡ c *N succ a
l = canSubtractFromEqualityLeft {succ a} {b *N succ a} {c *N succ a} k
productCancelsLeft : (a b c : ℕ) → (zero <N a) → (a *N b ≡ a *N c) → (b ≡ c)
productCancelsLeft a b c aPos pr = productCancelsRight a b c aPos j
where
i : b *N a ≡ a *N c
i = identityOfIndiscernablesLeft _≡_ pr (multiplicationNIsCommutative a b)
j : b *N a ≡ c *N a
j = identityOfIndiscernablesRight _≡_ i (multiplicationNIsCommutative a c)
productCancelsRight' : (a b c : ℕ) → (b *N a ≡ c *N a) → (a ≡ zero) || (b ≡ c)
productCancelsRight' zero b c pr = inl refl
productCancelsRight' (succ a) b c pr = inr (productCancelsRight (succ a) b c (succIsPositive a) pr)
productCancelsLeft' : (a b c : ℕ) → (a *N b ≡ a *N c) → (a ≡ zero) || (b ≡ c)
productCancelsLeft' zero b c pr = inl refl
productCancelsLeft' (succ a) b c pr = inr (productCancelsLeft (succ a) b c (succIsPositive a) pr)
subtractionPreservesInequality : {a b : ℕ} → (c : ℕ) → a +N c <N b +N c → a <N b
subtractionPreservesInequality {a} {b} zero prABC rewrite commutative a 0 | commutative b 0 = prABC
subtractionPreservesInequality {a} {b} (succ c) (le x proof) = le x (canSubtractFromEqualityRight {b = succ c} (transitivity (equalityCommutative (+Associative (succ x) a (succ c))) proof))
cancelInequalityLeft : {a b c : ℕ} → a *N b <N a *N c → b <N c
cancelInequalityLeft {a} {zero} {zero} (le x proof) rewrite (productZeroRight a) = exFalso (naughtE (equalityCommutative proof))
cancelInequalityLeft {a} {zero} {succ c} pr = succIsPositive c
cancelInequalityLeft {a} {succ b} {zero} (le x proof) rewrite (productZeroRight a) = exFalso (naughtE (equalityCommutative proof))
cancelInequalityLeft {a} {succ b} {succ c} pr = succPreservesInequality q'
where
p' : succ b *N a <N succ c *N a
p' = canFlipMultiplicationsInIneq {a} {succ b} {a} {succ c} pr
p'' : b *N a +N a <N succ c *N a
p'' = identityOfIndiscernablesLeft _<N_ p' (commutative a (b *N a))
p''' : b *N a +N a <N c *N a +N a
p''' = identityOfIndiscernablesRight _<N_ p'' (commutative a (c *N a))
p : b *N a <N c *N a
p = subtractionPreservesInequality a p'''
q : a *N b <N a *N c
q = canFlipMultiplicationsInIneq {b} {a} {c} {a} p
q' : b <N c
q' = cancelInequalityLeft {a} {b} {c} q
<NProp : {a b : ℕ} → .(a <N b) → a <N b
<NProp {zero} {succ b} a<b = succIsPositive _
<NProp {succ a} {succ b} a<b = succPreservesInequality (<NProp (canRemoveSuccFrom<N a<b))
zeroLeast : {m n : ℕ} → m <N n → 0 <N n
zeroLeast {zero} m<n = m<n
zeroLeast {succ m} {succ n} m<n = le n (applyEquality succ (Semiring.sumZeroRight ℕSemiring n))
| {
"alphanum_fraction": 0.6526483292,
"avg_line_length": 48.3406593407,
"ext": "agda",
"hexsha": "f1202c5bb50cc0ca53ef2c1aea41adc56c4e1088",
"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": "Numbers/Naturals/Order/Lemmas.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": "Numbers/Naturals/Order/Lemmas.agda",
"max_line_length": 239,
"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": "Numbers/Naturals/Order/Lemmas.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": 1636,
"size": 4399
} |
{-# OPTIONS --without-K #-}
module Explore.Explorable.Isos where
open import Function
open import Data.Product
open import Data.Nat
open import Data.Vec renaming (sum to vsum)
open import Function.Related.TypeIsomorphisms.NP
import Relation.Binary.PropositionalEquality.NP as ≡
open ≡ using (_≡_; _≗_)
open import Explore.Type
open import Explore.Explorable
open import Explore.Product
swap-μ : ∀ {A B} → Explorable (A × B) → Explorable (B × A)
swap-μ = μ-iso swap-iso
swapS-preserve : ∀ {A B} f (μA×B : Explorable (A × B)) → sum μA×B f ≡ sum (swap-μ μA×B) (f ∘ swap)
swapS-preserve = μ-iso-preserve swap-iso
μ^ : ∀ {A} (μA : Explorable A) n → Explorable (A ^ n)
μ^ μA zero = μLift μ𝟙
μ^ μA (suc n) = μA ×-μ μ^ μA n
μVec : ∀ {A} (μA : Explorable A) n → Explorable (Vec A n)
μVec μA n = μ-iso (^↔Vec n) (μ^ μA n)
| {
"alphanum_fraction": 0.6715328467,
"avg_line_length": 29.3571428571,
"ext": "agda",
"hexsha": "39115e548dfb54ce683f78c86f95dbf19a5dd091",
"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/Experimental/Isos.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/Experimental/Isos.agda",
"max_line_length": 98,
"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/Experimental/Isos.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": 304,
"size": 822
} |
open import Preliminaries
module Lab3-LRSol where
{- de Bruijn indices are representd as proofs that
an element is in a list -}
data _∈_ {A : Set} : (x : A) (l : List A) → Set where -- type \in
i0 : {x : A} {xs : List A} → x ∈ x :: xs
iS : {x y : A} {xs : List A} → x ∈ xs → x ∈ y :: xs
{- types of the STLC -}
data Tp : Set where
b : Tp -- uninterpreted base type
_⇒_ : Tp → Tp → Tp -- type \=>
{- contexts are lists of Tp's -}
Ctx = List Tp
_,,_ : Ctx → Tp → Ctx
Γ ,, τ = τ :: Γ
infixr 10 _⇒_
infixr 9 _,,_
infixr 8 _|-_ -- type \entails
{- Γ ⊢ τ represents a term of type τ in context Γ -}
data _|-_ (Γ : Ctx) : Tp → Set where
c : Γ |- b -- some constant of the base type
v : {τ : Tp}
→ τ ∈ Γ
→ Γ |- τ
lam : {τ1 τ2 : Tp}
→ Γ ,, τ1 |- τ2
→ Γ |- τ1 ⇒ τ2
app : {τ1 τ2 : Tp}
→ Γ |- τ1 ⇒ τ2
→ Γ |- τ1
→ Γ |- τ2
module Examples where
i : [] |- b ⇒ b
i = lam (v i0) -- \ x -> x
k : [] |- b ⇒ b ⇒ b
k = lam (lam (v (iS i0))) -- \ x -> \ y -> x
{- TASK 1: Define a term representing \ x -> \ y -> y -}
k' : [] |- b ⇒ b ⇒ b
k' = lam (lam (v i0))
{- The following proof is like a "0-ary" logical relation.
It gives a semantics of the STLC in Agda.
This shows that the STLC is sound, relative to Agda.
-}
module Semantics (B : Set) (elB : B) where
-- works for any interpretation of the base type b
-- function mapping STLC types to Agda types
[_]t : Tp → Set -- type \(0 and \)0
[ b ]t = B
[ τ1 ⇒ τ2 ]t = [ τ1 ]t → [ τ2 ]t
-- function mapping STLC contexts to Agda types
[_]c : Ctx → Set
[ [] ]c = Unit
[ τ :: Γ ]c = [ Γ ]c × [ τ ]t
{- TASK 2 : Define the interpretation of terms -}
[_] : {Γ : Ctx} {τ : Tp} → Γ |- τ → [ Γ ]c → [ τ ]t
[ c ] γ = elB
[ v i0 ] γ = snd γ
[ v (iS x) ] γ = [ v x ] (fst γ)
[ lam e ] γ = \ x → [ e ] (γ , x)
[ app e1 e2 ] γ = [ e1 ] γ ([ e2 ] γ)
{- the following test should pass
test : ⟦ Examples.k ⟧ == \ γ x y → x
test = Refl
-}
{- you can ignore the implementation of this module.
the interface for the components you need is listed below
-}
module RenamingAndSubstitution where
-- renamings = variable for variable substitutions.
-- For simplicity, these are defined as tuples, by recursion on the context.
-- It might clean up some of the proofs to use a functional view,
-- {τ : Tp} → τ ∈ Γ → τ ∈ Γ'
-- because then we could avoid some of the inductions here,
-- and some of the associativity/unit properties would be free.
module Renamings where
infix 9 _⊇_
_⊇_ : Ctx → Ctx → Set -- type \sup=
Γ' ⊇ [] = Unit
Γ' ⊇ (τ :: Γ) = (Γ' ⊇ Γ) × (τ ∈ Γ')
-- variables are functorial in the context
rename-var : {Γ Γ' : Ctx} {τ : Tp} → Γ' ⊇ Γ → τ ∈ Γ → τ ∈ Γ'
rename-var (ρ , x') i0 = x'
rename-var (ρ , _) (iS x) = rename-var ρ x
{- conceptually, we could define p and ⊇-compose and ⊇-id as primitive
and derive this.
but this works better inductively than ⊇-single does.
-}
p· : {Γ : Ctx} {Γ' : Ctx} → Γ ⊇ Γ' → {τ : Tp} → (Γ ,, τ) ⊇ Γ'
p· {Γ' = []} ren = <>
p· {Γ' = (τ :: Γ')} (ρ , x) = p· ρ , iS x
idr : {Γ : Ctx} → Γ ⊇ Γ
idr {[]} = <>
idr {τ :: Γ} = p· idr , i0
_·rr_ : {Γ1 Γ2 Γ3 : Ctx} → Γ1 ⊇ Γ2 → Γ2 ⊇ Γ3 → Γ1 ⊇ Γ3
_·rr_ {Γ1} {Γ2} {[]} ρ2 ρ3 = <>
_·rr_ {Γ1} {Γ2} {x :: Γ3} ρ2 (ρ3 , x3) = (ρ2 ·rr ρ3) , rename-var ρ2 x3
-- category with families notation
p : {Γ : Ctx} {τ : Tp} → (Γ ,, τ ⊇ Γ)
p = p· idr
-- next, we should show associativity and unit laws for ∘rr.
-- However:
-- (1) because renamings are defined using variables, this depends on (some of) functoriality of τ ∈ -,
-- so we define that here, too.
-- (2) we only need one of the unit laws
rename-var-· : {Γ1 Γ2 Γ3 : Ctx} → (ρ2 : Γ1 ⊇ Γ2) (ρ3 : Γ2 ⊇ Γ3) {τ : Tp} (x : τ ∈ Γ3)
→ rename-var ρ2 (rename-var ρ3 x) == rename-var (_·rr_ ρ2 ρ3) x
rename-var-· ρ2 ρ3 i0 = Refl
rename-var-· ρ2 ρ3 (iS x) = rename-var-· ρ2 (fst ρ3) x
·rr-assoc : {Γ1 Γ2 Γ3 Γ4 : Ctx} → (ρ2 : Γ1 ⊇ Γ2) (ρ3 : Γ2 ⊇ Γ3) (ρ4 : Γ3 ⊇ Γ4) → _·rr_ ρ2 (_·rr_ ρ3 ρ4) == _·rr_ (_·rr_ ρ2 ρ3) ρ4
·rr-assoc {Γ4 = []} ρ2 ρ3 ρ4 = Refl
·rr-assoc {Γ4 = τ4 :: Γ4} ρ2 ρ3 (ρ4 , x4) = ap2 _,_ (·rr-assoc ρ2 ρ3 ρ4) (rename-var-· ρ2 ρ3 x4)
-- rest of functoriality of rename-var
mutual
-- generalization to get the induction to go through
rename-var-p' : {Γ Γ' : Ctx} {τ τ' : Tp} (ρ : Γ' ⊇ Γ) (x : τ ∈ Γ) → rename-var (p· ρ {τ'}) x == (iS (rename-var ρ x))
rename-var-p' ρ i0 = Refl
rename-var-p' (ρ , _) (iS x) = rename-var-p' ρ x
-- this would be definitional if renamings were functions.
-- this instances is often needed below
rename-var-p : {Γ : Ctx} {τ τ' : Tp} (x : τ ∈ Γ) → rename-var (p· idr {τ'}) x == (iS x)
rename-var-p x = ap iS (rename-var-ident _ x) ∘ rename-var-p' idr x
rename-var-ident : {τ : Tp} (Γ : Ctx) (x : τ ∈ Γ) → rename-var idr x == x
rename-var-ident .(τ :: Γ) (i0 {τ} {Γ}) = Refl
rename-var-ident .(τ' :: Γ) (iS {τ} {τ'} {Γ} x) = rename-var-p x
-- beta reduction for p
pβ1' : {Γ1 Γ2 Γ3 : Ctx} → (ρ2 : Γ1 ⊇ Γ2) (ρ3 : Γ2 ⊇ Γ3) {τ : Tp} (x : τ ∈ Γ1)
→ (ρ2 , x) ·rr (p· ρ3) == (ρ2 ·rr ρ3)
pβ1' {Γ1} {_} {[]} ρ2 ρ3 x = Refl
pβ1' {Γ1} {_} {τ3 :: Γ3} ρ2 (ρ3 , x3) x₁ = ap (λ x → x , rename-var ρ2 x3) (pβ1' ρ2 ρ3 _)
mutual
·rr-unitr : {Γ1 Γ2 : Ctx} → (ρ2 : Γ1 ⊇ Γ2)
→ ρ2 ·rr idr == ρ2
·rr-unitr {Γ1} {[]} ρ2 = Refl
·rr-unitr {Γ1} {τ2 :: Γ2} (ρ2 , x2) = ap (λ x → x , x2) (pβ1 ρ2 x2)
pβ1 : {Γ1 Γ2 : Ctx} → (ρ2 : Γ1 ⊇ Γ2) {τ : Tp} (x : τ ∈ Γ1)
→ (ρ2 , x) ·rr p == ρ2
pβ1 ρ2 x = ·rr-unitr ρ2 ∘ pβ1' ρ2 idr x
-- p· is equivalent to the alternate definition.
p·-def : {Γ1 Γ2 : Ctx} {τ : Tp} (ρ : Γ1 ⊇ Γ2) → p· ρ {τ} == p ·rr ρ
p·-def {_}{[]} ρ = Refl
p·-def {_}{τ1 :: Γ1} (ρ , x) = ap2 _,_ (p·-def ρ) (! (rename-var-p x))
-- terms are functorial in renamings
addvar-ren : {Γ Γ' : Ctx} {τ : Tp} → Γ' ⊇ Γ → Γ' ,, τ ⊇ Γ ,, τ
addvar-ren ρ = (p· ρ , i0)
rename : {Γ Γ' : Ctx} {τ : Tp} → Γ' ⊇ Γ → Γ |- τ → Γ' |- τ
rename ρ c = c
rename ρ (v x) = v (rename-var ρ x)
rename ρ (lam e) = lam (rename (addvar-ren ρ) e)
rename ρ (app e e') = app (rename ρ e) (rename ρ e')
rename-· : {Γ1 Γ2 Γ3 : Ctx} → (ρ2 : Γ1 ⊇ Γ2) (ρ3 : Γ2 ⊇ Γ3) {τ : Tp} (e : Γ3 |- τ)
→ rename ρ2 (rename ρ3 e) == rename (ρ2 ·rr ρ3) e
rename-· ρ2 ρ3 c = Refl
rename-· ρ2 ρ3 (v x) = ap v (rename-var-· ρ2 ρ3 x)
rename-·{Γ1}{Γ2}{Γ3} ρ2 ρ3 (lam e) = ap lam (ap (λ x → rename (x , i0) e) lemma1 ∘ rename-· (addvar-ren ρ2) (addvar-ren ρ3) e) where
lemma1 : (p· ρ2 , i0) ·rr (p· ρ3) == p· (ρ2 ·rr ρ3)
lemma1 = (p· ρ2 , i0) ·rr (p· ρ3) =⟨ pβ1' (p· ρ2) ρ3 i0 ⟩
(p· ρ2) ·rr ρ3 =⟨ ap (λ x → _·rr_ x ρ3) (p·-def ρ2) ⟩
(p ·rr ρ2) ·rr ρ3 =⟨ ! (·rr-assoc p ρ2 ρ3) ⟩
p ·rr (ρ2 ·rr ρ3) =⟨ ! (p·-def (ρ2 ·rr ρ3))⟩
p· (ρ2 ·rr ρ3) ∎
rename-· ρ2 ρ3 (app e e₁) = ap2 app (rename-· ρ2 ρ3 e) (rename-· ρ2 ρ3 e₁)
-- not necessary for the proof, but an easy corollary of the above
rename-id : {Γ : Ctx}{τ : Tp} (e : Γ |- τ) → rename idr e == e
rename-id c = Refl
rename-id (v x) = ap v (rename-var-ident _ x)
rename-id (lam e) = ap lam (rename-id e)
rename-id (app e e₁) = ap2 app (rename-id e) (rename-id e₁)
open Renamings
-- expression-for-variable substitutions
module Subst where
_|-c_ : Ctx → Ctx → Set
Γ' |-c [] = Unit
Γ' |-c (τ :: Γ) = (Γ' |-c Γ) × (Γ' |- τ)
_·rs_ : {Γ1 Γ2 Γ3 : Ctx} → Γ1 ⊇ Γ2 → Γ2 |-c Γ3 → Γ1 |-c Γ3
_·rs_ {Γ1} {Γ2} {[]} ρ θ = <>
_·rs_ {Γ1} {Γ2} {τ3 :: Γ3} ρ (θ , e) = ρ ·rs θ , rename ρ e
addvar : {Γ Γ' : Ctx} {τ : Tp} → Γ |-c Γ' → (Γ ,, τ) |-c (Γ' ,, τ)
addvar θ = p ·rs θ , v i0
ids : {Γ : Ctx} → Γ |-c Γ
ids {[]} = <>
ids {τ :: Γ} = p ·rs ids , v i0
subst-var : {Γ Γ' : Ctx}{τ : Tp} → Γ |-c Γ' → τ ∈ Γ' → Γ |- τ
subst-var (θ , e) i0 = e
subst-var (θ , _) (iS x) = subst-var θ x
subst : {Γ Γ' : Ctx}{τ : Tp} → Γ |-c Γ' → Γ' |- τ → Γ |- τ
subst θ c = c
subst θ (v x) = subst-var θ x
subst θ (lam e) = lam (subst (addvar θ) e)
subst θ (app e e') = app (subst θ e) (subst θ e')
subst1 : {τ τ0 : Tp} → [] |- τ0 → ([] ,, τ0) |- τ → [] |- τ
subst1 e0 e = subst (<> , e0) e
-- composition of renamings and substitutions
_·sr_ : {Γ1 Γ2 Γ3 : Ctx} → Γ1 |-c Γ2 → Γ2 ⊇ Γ3 → Γ1 |-c Γ3
_·sr_ {Γ1} {Γ2} {[]} θ ρ = <>
_·sr_ {Γ1} {Γ2} {τ3 :: Γ3} θ (ρ , x) = _·sr_ θ ρ , subst-var θ x
_·ss_ : {Γ1 Γ2 Γ3 : Ctx} → Γ1 |-c Γ2 → Γ2 |-c Γ3 → Γ1 |-c Γ3
_·ss_ {Γ3 = []} θ1 θ2 = <>
_·ss_ {Γ1} {Γ2} {τ :: Γ3} θ1 (θ2 , e2) = θ1 ·ss θ2 , subst θ1 e2
-- subst var functoriality
subst-var-·rs : {Γ1 Γ2 Γ3 : Ctx} (ρ : Γ1 ⊇ Γ2) (θ : Γ2 |-c Γ3) {τ : Tp} (x : τ ∈ Γ3)
→ subst-var (ρ ·rs θ) x == rename ρ (subst-var θ x)
subst-var-·rs ρ θ i0 = Refl
subst-var-·rs ρ (θ , _) (iS x) = subst-var-·rs ρ θ x
subst-var-∘ss : {Γ1 Γ2 Γ3 : Ctx} → (θ2 : Γ1 |-c Γ2) (θ3 : Γ2 |-c Γ3) {τ : Tp} (x : τ ∈ Γ3)
→ subst-var (_·ss_ θ2 θ3) x == subst θ2 (subst-var θ3 x)
subst-var-∘ss θ2 θ3 i0 = Refl
subst-var-∘ss θ2 (θ3 , _) (iS x) = subst-var-∘ss θ2 θ3 x
subst-var-·sr : {Γ1 Γ2 Γ3 : Ctx} {τ : Tp} → (θ2 : Γ1 |-c Γ2) (ρ : Γ2 ⊇ Γ3) (x : τ ∈ Γ3)
→ (subst-var θ2 (rename-var ρ x)) == subst-var (_·sr_ θ2 ρ) x
subst-var-·sr θ2 ρ i0 = Refl
subst-var-·sr θ2 ρ (iS x) = subst-var-·sr θ2 (fst ρ) x
subst-var-id : {Γ : Ctx} {τ : Tp} → (x : τ ∈ Γ) → v x == subst-var ids x
subst-var-id i0 = Refl
subst-var-id {τ :: Γ} (iS x) = !
(_ =〈 subst-var-·rs (p· idr) ids x 〉
rename (p· idr) _ =〈 ! (ap (rename (p· idr)) (subst-var-id x)) 〉
rename (p· idr) (v x) =〈 ap v (rename-var-p x) 〉
v (iS x) ∎)
-- associativity and unit laws for composition.
-- also includes some β rules for composing with p.
-- and functoriality of subst in the various compositions, since substitutions involve terms.
∘rsr-assoc : {Γ1 Γ2 Γ3 Γ4 : Ctx} → (ρ2 : Γ1 ⊇ Γ2) (θ3 : Γ2 ⊢c Γ3) (ρ4 : Γ3 ⊇ Γ4)
→ (ρ2 ·rs θ3) ·sr ρ4 == ρ2 ·rs (θ3 ·sr ρ4)
∘rsr-assoc {Γ1} {Γ2} {Γ3} {[]} ρ2 θ3 ρ4 = Refl
∘rsr-assoc {Γ1} {Γ2} {Γ3} {τ4 :: Γ4} ρ2 θ3 (ρ4 , x4) = ap2 _,_ (∘rsr-assoc ρ2 θ3 ρ4) (subst-var-·rs ρ2 θ3 x4)
·sr-pβ' : {Γ1 Γ2 Γ3 : Ctx} {τ : Tp} → (θ2 : Γ1 ⊢c Γ2) (ρ : Γ2 ⊇ Γ3) {e : _ ⊢ τ}
→ (θ2 , e) ·sr (p· ρ) == θ2 ·sr ρ
·sr-pβ' {Γ1} {Γ2} {[]} θ2 ρ = Refl
·sr-pβ' {Γ1} {Γ2} {τ :: Γ3} θ2 (ρ , x) = ap2 _,_ (·sr-pβ' θ2 ρ) Refl
mutual
·sr-unitr : {Γ1 Γ2 : Ctx} → (θ : Γ1 ⊢c Γ2) → θ ·sr idr == θ
·sr-unitr {Γ1} {[]} θ = Refl
·sr-unitr {Γ1} {τ2 :: Γ2} (θ , e) = ap (λ x → x , e) (·sr-pβ θ)
·sr-pβ : {Γ1 Γ2 : Ctx} {τ : Tp} → (θ2 : Γ1 ⊢c Γ2) {e : _ ⊢ τ}
→ (θ2 , e) ·sr p == θ2
·sr-pβ θ2 = ·sr-unitr θ2 ∘ ·sr-pβ' θ2 idr
subst-id : {Γ : Ctx} {τ : Tp} {e : Γ ⊢ τ} → e == subst (ids) e
subst-id {e = c} = Refl
subst-id {e = v x} = subst-var-id x
subst-id {e = lam e} = ap lam (subst-id)
subst-id {e = app e e₁} = ap2 app subst-id subst-id
subst-·rs : {Γ1 Γ2 Γ4 : Ctx} {τ : Tp} → (ρ : Γ4 ⊇ Γ1) (θ2 : Γ1 ⊢c Γ2) (e : Γ2 ⊢ τ)
→ rename ρ (subst θ2 e) == subst (ρ ·rs θ2) e
subst-·rs ρ θ2 c = Refl
subst-·rs ρ θ2 (v x) = ! (subst-var-·rs ρ θ2 x)
subst-·rs ρ θ2 (lam e) = ap lam (ap (λ x → subst x e) (ap (λ x → x , v i0) (lemma2 ρ θ2)) ∘ subst-·rs (addvar-ren ρ) (addvar θ2) e) where
lemma1 : {Γ3 Γ5 : Ctx} (ρ₁ : Γ5 ⊇ Γ3) {τ3 : Tp}
→ (addvar-ren {_}{_}{τ3} ρ₁) ·rr (p· idr) == (p· idr) ·rr ρ₁
lemma1 {Γ3} {Γ5} ρ₁ = (p· ρ₁ , i0) ·rr (p· idr) =〈 Refl 〉
(p· ρ₁ , i0) ·rr p =〈 ap (λ x → (x , i0) ·rr p) (p·-def ρ₁)〉
(p ·rr ρ₁ , i0) ·rr p =〈 pβ1 (p ·rr ρ₁) i0 〉
p ·rr ρ₁ =〈 Refl 〉
(p· idr) ·rr ρ₁ ∎
lemma2 : {Γ1 Γ2 Γ4 : Ctx} {τ : Tp} → (ρ : Γ4 ⊇ Γ1) (θ2 : Γ1 ⊢c Γ2)
→ (addvar-ren{_}{_}{τ} ρ) ·rs (fst (addvar θ2)) == p ·rs (ρ ·rs θ2)
lemma2 {Γ2 = []} ρ₁ θ3 = Refl
lemma2 {Γ2 = τ2 :: Γ2} ρ₁ (θ3 , e3) = ap2 _,_ (lemma2 ρ₁ θ3)
(! (rename-· (p· idr) ρ₁ e3) ∘
(ap (λ x → rename x e3) (lemma1 ρ₁) ∘
rename-· (addvar-ren ρ₁) (p· idr) e3))
subst-·rs ρ θ2 (app e e₁) = ap2 app (subst-·rs ρ θ2 e) (subst-·rs ρ θ2 e₁)
·rss-assoc : {Γ1 Γ2 Γ3 Γ4 : Ctx} → (ρ : Γ4 ⊇ Γ1) (θ2 : Γ1 ⊢c Γ2) (θ3 : Γ2 ⊢c Γ3)
→ ρ ·rs (θ2 ·ss θ3) == (ρ ·rs θ2) ·ss θ3
·rss-assoc {Γ1} {Γ2} {[]} ρ θ2 θ3 = Refl
·rss-assoc {Γ1} {Γ2} {x :: Γ3} ρ θ2 (θ3 , e3) = ap2 _,_ (·rss-assoc ρ θ2 θ3) (subst-·rs ρ θ2 e3)
subst-·sr : {Γ1 Γ2 Γ3 : Ctx} {τ : Tp} → (θ2 : Γ1 ⊢c Γ2) (ρ : Γ2 ⊇ Γ3) (e : Γ3 ⊢ τ)
→ (subst θ2 (rename ρ e)) == subst (θ2 ·sr ρ) e
subst-·sr θ2 ρ c = Refl
subst-·sr θ2 ρ (v x) = subst-var-·sr θ2 ρ x
subst-·sr θ2 ρ (lam e) = ap lam (ap (λ x → subst x e) (ap (λ x → x , v i0) (lemma θ2 ρ)) ∘ subst-·sr (addvar θ2) (addvar-ren ρ) e) where
lemma : {Γ1 Γ2 Γ3 : Ctx} {τ : Tp} → (θ2 : Γ1 ⊢c Γ2) (ρ : Γ2 ⊇ Γ3) → (addvar{_}{_}{τ} θ2) ·sr (p· ρ) == p ·rs (θ2 ·sr ρ)
lemma θ2 ρ = ∘rsr-assoc (p· idr) θ2 ρ ∘ ·sr-pβ' (_·rs_ (p· idr) θ2) ρ {v i0}
subst-·sr θ2 ρ (app e e₁) = ap2 app (subst-·sr θ2 ρ e) (subst-·sr θ2 ρ e₁)
·srs-assoc : {Γ1 Γ2 Γ3 Γ4 : Ctx} (θ : Γ1 ⊢c Γ2) (ρ : Γ2 ⊇ Γ3) (θ' : Γ3 ⊢c Γ4)
→ θ ·ss (ρ ·rs θ') == (θ ·sr ρ) ·ss θ'
·srs-assoc {Γ1} {Γ2} {Γ3} {[]} θ ρ θ' = Refl
·srs-assoc {Γ1} {Γ2} {Γ3} {x :: Γ4} θ ρ (θ' , e') = ap2 _,_ (·srs-assoc θ ρ θ') (subst-·sr θ ρ e')
subst-·ss : {Γ1 Γ2 Γ3 : Ctx} → (θ2 : Γ1 ⊢c Γ2) (θ3 : Γ2 ⊢c Γ3) {τ : Tp} (e : Γ3 ⊢ τ)
→ subst (θ2 ·ss θ3) e == subst θ2 (subst θ3 e)
subst-·ss θ2 θ3 c = Refl
subst-·ss θ2 θ3 (v x) = subst-var-∘ss θ2 θ3 x
subst-·ss θ2 θ3 (lam e) = ap lam (subst-·ss (addvar θ2) (addvar θ3) e ∘
ap (λ x → subst x e) (ap (λ x → x , v i0)
(lemma1 ∘ ·rss-assoc p θ2 θ3))) where
lemma1 : (p ·rs θ2) ·ss θ3 ==
(addvar θ2) ·ss (fst (addvar θ3))
lemma1 = (p ·rs θ2) ·ss θ3 =〈 ! (ap (λ x → x ·ss θ3) (·sr-pβ (p ·rs θ2) {v i0})) 〉
((p ·rs θ2 , v i0) ·sr p) ·ss θ3 =〈 ! (·srs-assoc (p ·rs θ2 , v i0) p θ3) 〉
(p ·rs θ2 , v i0) ·ss (p ·rs θ3) ∎
subst-·ss θ2 θ3 (app e e₁) = ap2 app (subst-·ss θ2 θ3 e) (subst-·ss θ2 θ3 e₁)
·ss-unitl : {Γ1 Γ2 : Ctx} → (θ : Γ1 ⊢c Γ2) → ids ·ss θ == θ
·ss-unitl {Γ2 = []} θ = Refl
·ss-unitl {Γ2 = τ :: Γ2} (θ , e) = ap2 _,_ (·ss-unitl θ) (! subst-id)
compose1 : {τ1 τ2 : Tp} {Γ : Ctx} (θ : [] ⊢c Γ) (e' : [] ⊢ τ1)
→ (θ , e') == (<> , e') ·ss (addvar θ)
compose1 {τ1}{τ2} θ e' = ap (λ x → x , e') (! (·srs-assoc (<> , e') (p{_}{τ1}) θ) ∘ ! (·ss-unitl θ))
subst-compose1 : {τ1 τ2 : Tp} {Γ : Ctx} (θ : [] ⊢c Γ) (e' : [] ⊢ τ1) (e : Γ ,, τ1 ⊢ τ2)
→ subst (θ , e') e == subst1 e' (subst (addvar θ) e)
subst-compose1{τ1}{τ2}{Γ} θ e' e = subst-·ss (<> , e') (addvar θ) e ∘ ap (λ x → subst x e) (compose1{τ1}{τ2}{Γ} θ e')
open Subst public
open RenamingAndSubstitution using (subst1 ; _⊢c_ ; subst ; subst-id ; subst-compose1)
{- θ : Γ ⊢c Γ' means θ is a substitution for Γ' in terms of Γ. It is defined as follows:
_⊢c_ : Ctx → Ctx → Set
Γ' ⊢c [] = Unit
Γ' ⊢c (τ :: Γ) = (Γ' ⊢c Γ) × (Γ' ⊢ τ)
-- apply a substitution to a term
subst : {Γ Γ' : Ctx}{τ : Tp} → Γ ⊢c Γ' → Γ' ⊢ τ → Γ ⊢ τ
-- substitution for a single variable
subst1 : {τ τ0 : Tp} → [] ⊢ τ0 → ([] ,, τ0) ⊢ τ → [] ⊢ τ
-- you will need these two properties:
subst-compose1 : {τ1 τ2 : Tp} {Γ : Ctx} (θ : [] ⊢c Γ) (e' : [] ⊢ τ1) (e : Γ ,, τ1 ⊢ τ2)
→ subst (θ , e') e == subst1 e' (subst (addvar θ) e)
subst-id : {Γ : Ctx} {τ : Tp} {e : Γ ⊢ τ} → e == subst (ids) e
-}
module OpSem where
-- step relation
data _↦_ : {τ : Tp} → [] |- τ → [] |- τ → Set where
Step/app :{τ1 τ2 : Tp} {e e' : [] |- τ1 ⇒ τ2} {e1 : [] |- τ1}
→ e ↦ e'
→ (app e e1) ↦ (app e' e1)
Step/β : {τ1 τ2 : Tp} {e : [] ,, τ1 |- τ2} {e1 : [] |- τ1}
→ (app (lam e) e1) ↦ subst1 e1 e
-- reflexive/transitive closure
data _↦*_ : {τ : Tp} → [] |- τ → [] |- τ → Set where
Done : {τ : Tp} {e : [] |- τ} → e ↦* e
Step : {τ : Tp} {e1 e2 e3 : [] |- τ}
→ e1 ↦ e2 → e2 ↦* e3
→ e1 ↦* e3
{- Next, you will prove "very weak normalization". The theorem is
that any closed term *of base type b* evaluates to the constant c.
No claims are made about terms of function type.
-}
module VeryWeakNormalization where
open OpSem
WN : (τ : Tp) → [] ⊢ τ → Set
-- WN_τ(e) iff e ↦* c
WN b e = e ↦* c
-- WN_τ(e) iff for all e1 : τ1, if WN_τ1(e1) then WN_τ2(e e1)
WN (τ1 ⇒ τ2) e = (e1 : [] ⊢ τ1) → WN τ1 e1 → WN τ2 (app e e1)
-- extend WN to contexts and substitutions
WNc : (Γ : Ctx) → [] ⊢c Γ → Set
WNc [] θ = Unit
WNc (τ :: Γ) (θ , e) = WNc Γ θ × WN τ e
{- TASK 3 : show that the relation is closed under head expansion: -}
head-expand : (τ : Tp) {e e' : [] ⊢ τ} → e ↦ e' → WN τ e' → WN τ e
head-expand b e↦e' w = Step e↦e' w
head-expand (τ1 ⇒ τ2) e↦e' w = λ e1 we1 → head-expand τ2 (Step/app e↦e') (w e1 we1)
{- TASK 4 : prove the fundamental theorem -}
fund : {Γ : Ctx} {τ : Tp} {θ : [] ⊢c Γ}
→ (e : Γ ⊢ τ)
→ WNc Γ θ
→ WN τ (subst θ e)
fund c wθ = Done
fund (v i0) (_ , we) = we
fund (v (iS x)) (wθ , _) = fund (v x) wθ
fund {_}{._}{θ} (lam{τ1}{τ2} e) wθ =
λ e1 we1 → head-expand τ2 Step/β
(transport (λ x → WN τ2 x) (subst-compose1 θ e1 e) (fund e (wθ , we1)))
fund (app e e₁) wθ = fund e wθ _ (fund e₁ wθ)
{- TASK 5 : conclude weak normalization at base type -}
corollary : (e : [] ⊢ b) → e ↦* c
corollary e = transport (\ x -> x ↦* _) (! subst-id) (fund e <>)
{- TASK 6 : change the definition of the logical relation so that you also can conclude normalization
at function type
-}
module WeakNormalization where
open OpSem
WN : (τ : Tp) → [] ⊢ τ → Set
WN b e = e ↦* c
WN (τ1 ⇒ τ2) e =
Σ \ (e' : [] ,, τ1 ⊢ τ2) →
(e ↦* lam e') × ((e1 : [] ⊢ τ1) → WN τ1 e1 → WN τ2 (subst1 e1 e'))
-- extend WN to contexts and substitutions
WNc : (Γ : Ctx) → [] ⊢c Γ → Set
WNc [] θ = Unit
WNc (τ :: Γ) (θ , e) = WNc Γ θ × WN τ e
open RenamingAndSubstitution using (addvar)
--- you will want to use
-- addvar : {Γ Γ' : Ctx} {τ : Tp} → Γ ⊢c Γ' → (Γ ,, τ) ⊢c (Γ' ,, τ)
head-expand : (τ : Tp) {e e' : [] ⊢ τ} → e ↦ e' → WN τ e' → WN τ e
head-expand b e↦e' w = Step e↦e' w
head-expand (τ1 ⇒ τ2) e↦e' (body , steps , wn) = body , Step e↦e' steps , wn
-- Hint: you will need a couple of lemmas about ↦* that we didn't need above
-- (I used three of them)
head-expand* : {τ : Tp} {e e' : [] ⊢ τ} → e ↦* e' → WN τ e' → WN τ e
head-expand* Done w = w
head-expand* (Step s ss) w = head-expand _ s (head-expand* ss w)
Step/app* :{τ1 τ2 : Tp} {e e' : [] ⊢ τ1 ⇒ τ2} {e1 : [] ⊢ τ1}
→ e ↦* e'
→ (app e e1) ↦* (app e' e1)
Step/app* Done = Done
Step/app* (Step s ss) = (Step (Step/app s) (Step/app* ss))
Step' : {τ : Tp} {e1 e2 e3 : [] ⊢ τ}
→ e1 ↦* e2 → e2 ↦ e3
→ e1 ↦* e3
Step' Done s = Step s Done
Step' (Step s ss) s' = Step s (Step' ss s')
fund : {Γ : Ctx} {τ : Tp} {θ : [] ⊢c Γ}
→ (e : Γ ⊢ τ)
→ WNc Γ θ
→ WN τ (subst θ e)
fund c wθ = Done
fund (v i0) (_ , we) = we
fund (v (iS x)) (wθ , _) = fund (v x) wθ
fund {_}{._}{θ} (lam{τ1}{τ2} e) wθ =
subst (addvar θ) e , Done , (λ e1 we1 → transport (WN τ2) (subst-compose1 θ e1 e) (fund e (wθ , we1)))
fund (app e e₁) wθ with fund e wθ
... | (body , reduction , wn) = head-expand* (Step' (Step/app* reduction) Step/β) (wn _ (fund e₁ wθ))
{- TASK 6a -}
corollary1 : (e : [] ⊢ b) → e ↦* c
corollary1 e = transport (λ x → x ↦* _) (! subst-id) (fund e <>)
{- TASK 6b -}
corollary2 : {τ1 τ2 : Tp} (e : [] ⊢ τ1 ⇒ τ2) → Σ \(e' : _) → e ↦* (lam e')
corollary2 e with (fund e <>)
... | (e' , steps , _) = e' , transport (λ x → x ↦* _) (! subst-id) steps
| {
"alphanum_fraction": 0.4495340899,
"avg_line_length": 41.3702290076,
"ext": "agda",
"hexsha": "0789d085ae6094b9964515297acce1e9298f3d04",
"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": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "benhuds/Agda",
"max_forks_repo_path": "old/Lab3-LRSol.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "benhuds/Agda",
"max_issues_repo_path": "old/Lab3-LRSol.agda",
"max_line_length": 143,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "benhuds/Agda",
"max_stars_repo_path": "old/Lab3-LRSol.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z",
"num_tokens": 9722,
"size": 21678
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Basic properties of ℕᵇ
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Binary.Properties where
open import Algebra.Bundles
open import Algebra.Morphism.Structures
import Algebra.Morphism.MonoidMonomorphism as MonoidMonomorphism
open import Algebra.Consequences.Propositional
open import Data.Nat.Binary.Base
open import Data.Nat as ℕ using (ℕ; z≤n; s≤s)
import Data.Nat.Properties as ℕₚ
open import Data.Nat.Solver
open import Data.Product using (_,_; proj₁; proj₂; ∃)
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
open import Function using (_∘_; _$_; id)
open import Function.Definitions using (Injective)
open import Function.Definitions.Core2 using (Surjective)
open import Level using (0ℓ)
open import Relation.Binary
open import Relation.Binary.Consequences
open import Relation.Binary.Morphism
import Relation.Binary.Morphism.OrderMonomorphism as OrderMonomorphism
open import Relation.Binary.PropositionalEquality
import Relation.Binary.Reasoning.Base.Triple as InequalityReasoning
open import Relation.Nullary using (¬_; yes; no)
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Negation using (contradiction)
open import Algebra.Definitions {A = ℕᵇ} _≡_
open import Algebra.Structures {A = ℕᵇ} _≡_
import Algebra.Properties.CommutativeSemigroup ℕₚ.+-commutativeSemigroup
as ℕ-+-semigroupProperties
import Relation.Binary.Construct.StrictToNonStrict _≡_ _<_
as StrictToNonStrict
open +-*-Solver
------------------------------------------------------------------------
-- Properties of _≡_
------------------------------------------------------------------------
2[1+x]≢0 : ∀ {x} → 2[1+ x ] ≢ 0ᵇ
2[1+x]≢0 ()
1+[2x]≢0 : ∀ {x} → 1+[2 x ] ≢ 0ᵇ
1+[2x]≢0 ()
2[1+_]-injective : Injective _≡_ _≡_ 2[1+_]
2[1+_]-injective refl = refl
1+[2_]-injective : Injective _≡_ _≡_ 1+[2_]
1+[2_]-injective refl = refl
_≟_ : Decidable {A = ℕᵇ} _≡_
zero ≟ zero = yes refl
zero ≟ 2[1+ _ ] = no λ()
zero ≟ 1+[2 _ ] = no λ()
2[1+ _ ] ≟ zero = no λ()
2[1+ x ] ≟ 2[1+ y ] = Dec.map′ (cong 2[1+_]) 2[1+_]-injective (x ≟ y)
2[1+ _ ] ≟ 1+[2 _ ] = no λ()
1+[2 _ ] ≟ zero = no λ()
1+[2 _ ] ≟ 2[1+ _ ] = no λ()
1+[2 x ] ≟ 1+[2 y ] = Dec.map′ (cong 1+[2_]) 1+[2_]-injective (x ≟ y)
≡-isDecEquivalence : IsDecEquivalence {A = ℕᵇ} _≡_
≡-isDecEquivalence = isDecEquivalence _≟_
≡-setoid : Setoid 0ℓ 0ℓ
≡-setoid = setoid ℕᵇ
≡-decSetoid : DecSetoid 0ℓ 0ℓ
≡-decSetoid = decSetoid _≟_
------------------------------------------------------------------------
-- Properties of toℕ & fromℕ
------------------------------------------------------------------------
toℕ-double : ∀ x → toℕ (double x) ≡ 2 ℕ.* (toℕ x)
toℕ-double zero = refl
toℕ-double 1+[2 x ] = cong ((2 ℕ.*_) ∘ ℕ.suc) (toℕ-double x)
toℕ-double 2[1+ x ] = cong (2 ℕ.*_) (sym (ℕₚ.*-distribˡ-+ 2 1 (toℕ x)))
toℕ-suc : ∀ x → toℕ (suc x) ≡ ℕ.suc (toℕ x)
toℕ-suc zero = refl
toℕ-suc 2[1+ x ] = cong (ℕ.suc ∘ (2 ℕ.*_)) (toℕ-suc x)
toℕ-suc 1+[2 x ] = ℕₚ.*-distribˡ-+ 2 1 (toℕ x)
toℕ-pred : ∀ x → toℕ (pred x) ≡ ℕ.pred (toℕ x)
toℕ-pred zero = refl
toℕ-pred 2[1+ x ] = cong ℕ.pred $ sym $ ℕₚ.*-distribˡ-+ 2 1 (toℕ x)
toℕ-pred 1+[2 x ] = toℕ-double x
toℕ-fromℕ : toℕ ∘ fromℕ ≗ id
toℕ-fromℕ 0 = refl
toℕ-fromℕ (ℕ.suc n) = begin
toℕ (fromℕ (ℕ.suc n)) ≡⟨⟩
toℕ (suc (fromℕ n)) ≡⟨ toℕ-suc (fromℕ n) ⟩
ℕ.suc (toℕ (fromℕ n)) ≡⟨ cong ℕ.suc (toℕ-fromℕ n) ⟩
ℕ.suc n ∎
where open ≡-Reasoning
toℕ-injective : Injective _≡_ _≡_ toℕ
toℕ-injective {zero} {zero} _ = refl
toℕ-injective {2[1+ x ]} {2[1+ y ]} 2[1+xN]≡2[1+yN] = cong 2[1+_] x≡y
where
1+xN≡1+yN = ℕₚ.*-cancelˡ-≡ {ℕ.suc _} {ℕ.suc _} 1 2[1+xN]≡2[1+yN]
xN≡yN = cong ℕ.pred 1+xN≡1+yN
x≡y = toℕ-injective xN≡yN
toℕ-injective {2[1+ x ]} {1+[2 y ]} 2[1+xN]≡1+2yN =
contradiction 2[1+xN]≡1+2yN (ℕₚ.even≢odd (ℕ.suc (toℕ x)) (toℕ y))
toℕ-injective {1+[2 x ]} {2[1+ y ]} 1+2xN≡2[1+yN] =
contradiction (sym 1+2xN≡2[1+yN]) (ℕₚ.even≢odd (ℕ.suc (toℕ y)) (toℕ x))
toℕ-injective {1+[2 x ]} {1+[2 y ]} 1+2xN≡1+2yN = cong 1+[2_] x≡y
where
2xN≡2yN = cong ℕ.pred 1+2xN≡1+2yN
xN≡yN = ℕₚ.*-cancelˡ-≡ 1 2xN≡2yN
x≡y = toℕ-injective xN≡yN
toℕ-surjective : Surjective _≡_ toℕ
toℕ-surjective n = (fromℕ n , toℕ-fromℕ n)
toℕ-isRelHomomorphism : IsRelHomomorphism _≡_ _≡_ toℕ
toℕ-isRelHomomorphism = record
{ cong = cong toℕ
}
fromℕ-injective : Injective _≡_ _≡_ fromℕ
fromℕ-injective {x} {y} f[x]≡f[y] = begin
x ≡⟨ sym (toℕ-fromℕ x) ⟩
toℕ (fromℕ x) ≡⟨ cong toℕ f[x]≡f[y] ⟩
toℕ (fromℕ y) ≡⟨ toℕ-fromℕ y ⟩
y ∎
where open ≡-Reasoning
fromℕ-toℕ : fromℕ ∘ toℕ ≗ id
fromℕ-toℕ = toℕ-injective ∘ toℕ-fromℕ ∘ toℕ
fromℕ-pred : ∀ n → fromℕ (ℕ.pred n) ≡ pred (fromℕ n)
fromℕ-pred n = begin
fromℕ (ℕ.pred n) ≡⟨ cong (fromℕ ∘ ℕ.pred) (sym (toℕ-fromℕ n)) ⟩
fromℕ (ℕ.pred (toℕ x)) ≡⟨ cong fromℕ (sym (toℕ-pred x)) ⟩
fromℕ (toℕ (pred x)) ≡⟨ fromℕ-toℕ (pred x) ⟩
pred x ≡⟨ refl ⟩
pred (fromℕ n) ∎
where open ≡-Reasoning; x = fromℕ n
x≡0⇒toℕ[x]≡0 : ∀ {x} → x ≡ zero → toℕ x ≡ 0
x≡0⇒toℕ[x]≡0 {zero} _ = refl
toℕ[x]≡0⇒x≡0 : ∀ {x} → toℕ x ≡ 0 → x ≡ zero
toℕ[x]≡0⇒x≡0 {zero} _ = refl
------------------------------------------------------------------------
-- Properties of _<_
------------------------------------------------------------------------
-- Basic properties
x≮0 : ∀ {x} → x ≮ zero
x≮0 ()
x≢0⇒x>0 : ∀ {x} → x ≢ zero → x > zero
x≢0⇒x>0 {zero} 0≢0 = contradiction refl 0≢0
x≢0⇒x>0 {2[1+ _ ]} _ = 0<even
x≢0⇒x>0 {1+[2 _ ]} _ = 0<odd
1+[2x]<2[1+x] : ∀ x → 1+[2 x ] < 2[1+ x ]
1+[2x]<2[1+x] x = odd<even (inj₂ refl)
<⇒≢ : _<_ ⇒ _≢_
<⇒≢ (even<even x<x) refl = <⇒≢ x<x refl
<⇒≢ (odd<odd x<x) refl = <⇒≢ x<x refl
>⇒≢ : _>_ ⇒ _≢_
>⇒≢ y<x = ≢-sym (<⇒≢ y<x)
≡⇒≮ : _≡_ ⇒ _≮_
≡⇒≮ x≡y x<y = <⇒≢ x<y x≡y
≡⇒≯ : _≡_ ⇒ _≯_
≡⇒≯ x≡y x>y = >⇒≢ x>y x≡y
<⇒≯ : _<_ ⇒ _≯_
<⇒≯ (even<even x<y) (even<even y<x) = <⇒≯ x<y y<x
<⇒≯ (even<odd x<y) (odd<even (inj₁ y<x)) = <⇒≯ x<y y<x
<⇒≯ (even<odd x<y) (odd<even (inj₂ refl)) = <⇒≢ x<y refl
<⇒≯ (odd<even (inj₁ x<y)) (even<odd y<x) = <⇒≯ x<y y<x
<⇒≯ (odd<even (inj₂ refl)) (even<odd y<x) = <⇒≢ y<x refl
<⇒≯ (odd<odd x<y) (odd<odd y<x) = <⇒≯ x<y y<x
>⇒≮ : _>_ ⇒ _≮_
>⇒≮ y<x = <⇒≯ y<x
<⇒≤ : _<_ ⇒ _≤_
<⇒≤ = inj₁
------------------------------------------------------------------------------
-- Properties of _<_ and toℕ & fromℕ.
toℕ-mono-< : toℕ Preserves _<_ ⟶ ℕ._<_
toℕ-mono-< {zero} {2[1+ _ ]} _ = ℕₚ.0<1+n
toℕ-mono-< {zero} {1+[2 _ ]} _ = ℕₚ.0<1+n
toℕ-mono-< {2[1+ x ]} {2[1+ y ]} (even<even x<y) = begin
ℕ.suc (2 ℕ.* (ℕ.suc xN)) ≤⟨ ℕₚ.+-monoʳ-≤ 1 (ℕₚ.*-monoʳ-≤ 2 xN<yN) ⟩
ℕ.suc (2 ℕ.* yN) ≤⟨ ℕₚ.≤-step ℕₚ.≤-refl ⟩
2 ℕ.+ (2 ℕ.* yN) ≡⟨ sym (ℕₚ.*-distribˡ-+ 2 1 yN) ⟩
2 ℕ.* (ℕ.suc yN) ∎
where open ℕₚ.≤-Reasoning; xN = toℕ x; yN = toℕ y; xN<yN = toℕ-mono-< x<y
toℕ-mono-< {2[1+ x ]} {1+[2 y ]} (even<odd x<y) =
ℕₚ.+-monoʳ-≤ 1 (ℕₚ.*-monoʳ-≤ 2 (toℕ-mono-< x<y))
toℕ-mono-< {1+[2 x ]} {2[1+ y ]} (odd<even (inj₁ x<y)) = begin
ℕ.suc (ℕ.suc (2 ℕ.* xN)) ≡⟨⟩
2 ℕ.+ (2 ℕ.* xN) ≡⟨ sym (ℕₚ.*-distribˡ-+ 2 1 xN) ⟩
2 ℕ.* (ℕ.suc xN) ≤⟨ ℕₚ.*-monoʳ-≤ 2 xN<yN ⟩
2 ℕ.* yN ≤⟨ ℕₚ.*-monoʳ-≤ 2 (ℕₚ.≤-step ℕₚ.≤-refl) ⟩
2 ℕ.* (ℕ.suc yN) ∎
where open ℕₚ.≤-Reasoning; xN = toℕ x; yN = toℕ y; xN<yN = toℕ-mono-< x<y
toℕ-mono-< {1+[2 x ]} {2[1+ .x ]} (odd<even (inj₂ refl)) =
ℕₚ.≤-reflexive (sym (ℕₚ.*-distribˡ-+ 2 1 (toℕ x)))
toℕ-mono-< {1+[2 x ]} {1+[2 y ]} (odd<odd x<y) = ℕₚ.+-monoʳ-< 1 (ℕₚ.*-monoʳ-< 1 xN<yN)
where xN = toℕ x; yN = toℕ y; xN<yN = toℕ-mono-< x<y
toℕ-cancel-< : ∀ {x y} → toℕ x ℕ.< toℕ y → x < y
toℕ-cancel-< {zero} {2[1+ y ]} x<y = 0<even
toℕ-cancel-< {zero} {1+[2 y ]} x<y = 0<odd
toℕ-cancel-< {2[1+ x ]} {2[1+ y ]} x<y =
even<even (toℕ-cancel-< (ℕ.≤-pred (ℕₚ.*-cancelˡ-< 2 x<y)))
toℕ-cancel-< {2[1+ x ]} {1+[2 y ]} x<y
rewrite ℕₚ.*-distribˡ-+ 2 1 (toℕ x) =
even<odd (toℕ-cancel-< (ℕₚ.*-cancelˡ-< 2 (ℕₚ.≤-trans (s≤s (ℕₚ.n≤1+n _)) (ℕₚ.≤-pred x<y))))
toℕ-cancel-< {1+[2 x ]} {2[1+ y ]} x<y with toℕ x ℕₚ.≟ toℕ y
... | yes x≡y = odd<even (inj₂ (toℕ-injective x≡y))
... | no x≢y
rewrite ℕₚ.+-suc (toℕ y) (toℕ y ℕ.+ 0) =
odd<even (inj₁ (toℕ-cancel-< (ℕₚ.≤∧≢⇒< (ℕₚ.*-cancelˡ-≤ 1 (ℕₚ.+-cancelˡ-≤ 2 x<y)) x≢y)))
toℕ-cancel-< {1+[2 x ]} {1+[2 y ]} x<y =
odd<odd (toℕ-cancel-< (ℕₚ.*-cancelˡ-< 2 (ℕ.≤-pred x<y)))
fromℕ-cancel-< : ∀ {x y} → fromℕ x < fromℕ y → x ℕ.< y
fromℕ-cancel-< = subst₂ ℕ._<_ (toℕ-fromℕ _) (toℕ-fromℕ _) ∘ toℕ-mono-<
fromℕ-mono-< : fromℕ Preserves ℕ._<_ ⟶ _<_
fromℕ-mono-< = toℕ-cancel-< ∘ subst₂ ℕ._<_ (sym (toℕ-fromℕ _)) (sym (toℕ-fromℕ _))
toℕ-isHomomorphism-< : IsOrderHomomorphism _≡_ _≡_ _<_ ℕ._<_ toℕ
toℕ-isHomomorphism-< = record
{ cong = cong toℕ
; mono = toℕ-mono-<
}
toℕ-isMonomorphism-< : IsOrderMonomorphism _≡_ _≡_ _<_ ℕ._<_ toℕ
toℕ-isMonomorphism-< = record
{ isOrderHomomorphism = toℕ-isHomomorphism-<
; injective = toℕ-injective
; cancel = toℕ-cancel-<
}
------------------------------------------------------------------------------
-- Relational properties of _<_
<-irrefl : Irreflexive _≡_ _<_
<-irrefl refl (even<even x<x) = <-irrefl refl x<x
<-irrefl refl (odd<odd x<x) = <-irrefl refl x<x
<-trans : Transitive _<_
<-trans {zero} {_} {2[1+ _ ]} _ _ = 0<even
<-trans {zero} {_} {1+[2 _ ]} _ _ = 0<odd
<-trans (even<even x<y) (even<even y<z) = even<even (<-trans x<y y<z)
<-trans (even<even x<y) (even<odd y<z) = even<odd (<-trans x<y y<z)
<-trans (even<odd x<y) (odd<even (inj₁ y<z)) = even<even (<-trans x<y y<z)
<-trans (even<odd x<y) (odd<even (inj₂ refl)) = even<even x<y
<-trans (even<odd x<y) (odd<odd y<z) = even<odd (<-trans x<y y<z)
<-trans (odd<even (inj₁ x<y)) (even<even y<z) = odd<even (inj₁ (<-trans x<y y<z))
<-trans (odd<even (inj₂ refl)) (even<even x<z) = odd<even (inj₁ x<z)
<-trans (odd<even (inj₁ x<y)) (even<odd y<z) = odd<odd (<-trans x<y y<z)
<-trans (odd<even (inj₂ refl)) (even<odd x<z) = odd<odd x<z
<-trans (odd<odd x<y) (odd<even (inj₁ y<z)) = odd<even (inj₁ (<-trans x<y y<z))
<-trans (odd<odd x<y) (odd<even (inj₂ refl)) = odd<even (inj₁ x<y)
<-trans (odd<odd x<y) (odd<odd y<z) = odd<odd (<-trans x<y y<z)
-- Should not be implemented via the morphism `toℕ` in order to
-- preserve O(log n) time requirement.
<-cmp : Trichotomous _≡_ _<_
<-cmp zero zero = tri≈ x≮0 refl x≮0
<-cmp zero 2[1+ _ ] = tri< 0<even (λ()) x≮0
<-cmp zero 1+[2 _ ] = tri< 0<odd (λ()) x≮0
<-cmp 2[1+ _ ] zero = tri> (λ()) (λ()) 0<even
<-cmp 2[1+ x ] 2[1+ y ] with <-cmp x y
... | tri< x<y _ _ = tri< lt (<⇒≢ lt) (<⇒≯ lt) where lt = even<even x<y
... | tri≈ _ refl _ = tri≈ (<-irrefl refl) refl (<-irrefl refl)
... | tri> _ _ x>y = tri> (>⇒≮ gt) (>⇒≢ gt) gt where gt = even<even x>y
<-cmp 2[1+ x ] 1+[2 y ] with <-cmp x y
... | tri< x<y _ _ = tri< lt (<⇒≢ lt) (<⇒≯ lt) where lt = even<odd x<y
... | tri≈ _ refl _ = tri> (>⇒≮ gt) (>⇒≢ gt) gt
where
gt = subst (_< 2[1+ x ]) refl (1+[2x]<2[1+x] x)
... | tri> _ _ y<x = tri> (>⇒≮ gt) (>⇒≢ gt) gt where gt = odd<even (inj₁ y<x)
<-cmp 1+[2 _ ] zero = tri> (>⇒≮ gt) (>⇒≢ gt) gt where gt = 0<odd
<-cmp 1+[2 x ] 2[1+ y ] with <-cmp x y
... | tri< x<y _ _ = tri< lt (<⇒≢ lt) (<⇒≯ lt) where lt = odd<even (inj₁ x<y)
... | tri≈ _ x≡y _ = tri< lt (<⇒≢ lt) (<⇒≯ lt) where lt = odd<even (inj₂ x≡y)
... | tri> _ _ x>y = tri> (>⇒≮ gt) (>⇒≢ gt) gt where gt = even<odd x>y
<-cmp 1+[2 x ] 1+[2 y ] with <-cmp x y
... | tri< x<y _ _ = tri< lt (<⇒≢ lt) (<⇒≯ lt) where lt = odd<odd x<y
... | tri≈ _ refl _ = tri≈ (≡⇒≮ refl) refl (≡⇒≯ refl)
... | tri> _ _ x>y = tri> (>⇒≮ gt) (>⇒≢ gt) gt where gt = odd<odd x>y
_<?_ : Decidable _<_
_<?_ = tri⟶dec< <-cmp
------------------------------------------------------------------------------
-- Structures for _<_
<-isStrictPartialOrder : IsStrictPartialOrder _≡_ _<_
<-isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = <-irrefl
; trans = <-trans
; <-resp-≈ = resp₂ _<_
}
<-isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_
<-isStrictTotalOrder = record
{ isEquivalence = isEquivalence
; trans = <-trans
; compare = <-cmp
}
------------------------------------------------------------------------------
-- Bundles for _<_
<-strictPartialOrder : StrictPartialOrder _ _ _
<-strictPartialOrder = record
{ isStrictPartialOrder = <-isStrictPartialOrder
}
<-strictTotalOrder : StrictTotalOrder _ _ _
<-strictTotalOrder = record
{ isStrictTotalOrder = <-isStrictTotalOrder
}
------------------------------------------------------------------------------
-- Other properties of _<_
x<2[1+x] : ∀ x → x < 2[1+ x ]
x<1+[2x] : ∀ x → x < 1+[2 x ]
x<2[1+x] zero = 0<even
x<2[1+x] 2[1+ x ] = even<even (x<2[1+x] x)
x<2[1+x] 1+[2 x ] = odd<even (inj₁ (x<1+[2x] x))
x<1+[2x] zero = 0<odd
x<1+[2x] 2[1+ x ] = even<odd (x<2[1+x] x)
x<1+[2x] 1+[2 x ] = odd<odd (x<1+[2x] x)
------------------------------------------------------------------------------
-- Properties of _≤_
------------------------------------------------------------------------------
-- Basic properties
<⇒≱ : _<_ ⇒ _≱_
<⇒≱ x<y (inj₁ y<x) = contradiction y<x (<⇒≯ x<y)
<⇒≱ x<y (inj₂ y≡x) = contradiction (sym y≡x) (<⇒≢ x<y)
≤⇒≯ : _≤_ ⇒ _≯_
≤⇒≯ x≤y x>y = <⇒≱ x>y x≤y
≮⇒≥ : _≮_ ⇒ _≥_
≮⇒≥ {x} {y} x≮y with <-cmp x y
... | tri< lt _ _ = contradiction lt x≮y
... | tri≈ _ eq _ = inj₂ (sym eq)
... | tri> _ _ y<x = <⇒≤ y<x
≰⇒> : _≰_ ⇒ _>_
≰⇒> {x} {y} x≰y with <-cmp x y
... | tri< lt _ _ = contradiction (<⇒≤ lt) x≰y
... | tri≈ _ eq _ = contradiction (inj₂ eq) x≰y
... | tri> _ _ x>y = x>y
≤∧≢⇒< : ∀ {x y} → x ≤ y → x ≢ y → x < y
≤∧≢⇒< (inj₁ x<y) _ = x<y
≤∧≢⇒< (inj₂ x≡y) x≢y = contradiction x≡y x≢y
0≤x : ∀ x → zero ≤ x
0≤x zero = inj₂ refl
0≤x 2[1+ _ ] = inj₁ 0<even
0≤x 1+[2 x ] = inj₁ 0<odd
x≤0⇒x≡0 : ∀ {x} → x ≤ zero → x ≡ zero
x≤0⇒x≡0 (inj₂ x≡0) = x≡0
------------------------------------------------------------------------------
-- Properties of _<_ and toℕ & fromℕ.
fromℕ-mono-≤ : fromℕ Preserves ℕ._≤_ ⟶ _≤_
fromℕ-mono-≤ m≤n with ℕₚ.m≤n⇒m<n∨m≡n m≤n
... | inj₁ m<n = inj₁ (fromℕ-mono-< m<n)
... | inj₂ m≡n = inj₂ (cong fromℕ m≡n)
toℕ-mono-≤ : toℕ Preserves _≤_ ⟶ ℕ._≤_
toℕ-mono-≤ (inj₁ x<y) = ℕₚ.<⇒≤ (toℕ-mono-< x<y)
toℕ-mono-≤ (inj₂ refl) = ℕₚ.≤-reflexive refl
toℕ-cancel-≤ : ∀ {x y} → toℕ x ℕ.≤ toℕ y → x ≤ y
toℕ-cancel-≤ = subst₂ _≤_ (fromℕ-toℕ _) (fromℕ-toℕ _) ∘ fromℕ-mono-≤
fromℕ-cancel-≤ : ∀ {x y} → fromℕ x ≤ fromℕ y → x ℕ.≤ y
fromℕ-cancel-≤ = subst₂ ℕ._≤_ (toℕ-fromℕ _) (toℕ-fromℕ _) ∘ toℕ-mono-≤
toℕ-isHomomorphism-≤ : IsOrderHomomorphism _≡_ _≡_ _≤_ ℕ._≤_ toℕ
toℕ-isHomomorphism-≤ = record
{ cong = cong toℕ
; mono = toℕ-mono-≤
}
toℕ-isMonomorphism-≤ : IsOrderMonomorphism _≡_ _≡_ _≤_ ℕ._≤_ toℕ
toℕ-isMonomorphism-≤ = record
{ isOrderHomomorphism = toℕ-isHomomorphism-≤
; injective = toℕ-injective
; cancel = toℕ-cancel-≤
}
------------------------------------------------------------------------------
-- Relational properties of _≤_
≤-refl : Reflexive _≤_
≤-refl = inj₂ refl
≤-reflexive : _≡_ ⇒ _≤_
≤-reflexive {x} {_} refl = ≤-refl {x}
≤-trans : Transitive _≤_
≤-trans = StrictToNonStrict.trans isEquivalence (resp₂ _<_) <-trans
<-≤-trans : ∀ {x y z} → x < y → y ≤ z → x < z
<-≤-trans x<y (inj₁ y<z) = <-trans x<y y<z
<-≤-trans x<y (inj₂ refl) = x<y
≤-<-trans : ∀ {x y z} → x ≤ y → y < z → x < z
≤-<-trans (inj₁ x<y) y<z = <-trans x<y y<z
≤-<-trans (inj₂ refl) y<z = y<z
≤-antisym : Antisymmetric _≡_ _≤_
≤-antisym = StrictToNonStrict.antisym isEquivalence <-trans <-irrefl
≤-total : Total _≤_
≤-total x y with <-cmp x y
... | tri< x<y _ _ = inj₁ (<⇒≤ x<y)
... | tri≈ _ x≡y _ = inj₁ (≤-reflexive x≡y)
... | tri> _ _ y<x = inj₂ (<⇒≤ y<x)
-- Should not be implemented via the morphism `toℕ` in order to
-- preserve O(log n) time requirement.
_≤?_ : Decidable _≤_
x ≤? y with <-cmp x y
... | tri< x<y _ _ = yes (<⇒≤ x<y)
... | tri≈ _ x≡y _ = yes (≤-reflexive x≡y)
... | tri> _ _ y<x = no (<⇒≱ y<x)
------------------------------------------------------------------------------
-- Structures
≤-isPreorder : IsPreorder _≡_ _≤_
≤-isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = ≤-reflexive
; trans = ≤-trans
}
≤-isPartialOrder : IsPartialOrder _≡_ _≤_
≤-isPartialOrder = record
{ isPreorder = ≤-isPreorder
; antisym = ≤-antisym
}
≤-isTotalOrder : IsTotalOrder _≡_ _≤_
≤-isTotalOrder = record
{ isPartialOrder = ≤-isPartialOrder
; total = ≤-total
}
≤-isDecTotalOrder : IsDecTotalOrder _≡_ _≤_
≤-isDecTotalOrder = record
{ isTotalOrder = ≤-isTotalOrder
; _≟_ = _≟_
; _≤?_ = _≤?_
}
------------------------------------------------------------------------------
-- Bundles
≤-preorder : Preorder 0ℓ 0ℓ 0ℓ
≤-preorder = record
{ isPreorder = ≤-isPreorder
}
≤-partialOrder : Poset 0ℓ 0ℓ 0ℓ
≤-partialOrder = record
{ isPartialOrder = ≤-isPartialOrder
}
≤-totalOrder : TotalOrder 0ℓ 0ℓ 0ℓ
≤-totalOrder = record
{ isTotalOrder = ≤-isTotalOrder
}
≤-decTotalOrder : DecTotalOrder 0ℓ 0ℓ 0ℓ
≤-decTotalOrder = record
{ isDecTotalOrder = ≤-isDecTotalOrder
}
------------------------------------------------------------------------------
-- Equational reasoning for _≤_ and _<_
module ≤-Reasoning = InequalityReasoning
≤-isPreorder
<-trans
(resp₂ _<_) <⇒≤
<-≤-trans ≤-<-trans
hiding (step-≈; step-≈˘)
------------------------------------------------------------------------------
-- Properties of _<ℕ_
------------------------------------------------------------------------------
<⇒<ℕ : ∀ {x y} → x < y → x <ℕ y
<⇒<ℕ x<y = toℕ-mono-< x<y
<ℕ⇒< : ∀ {x y} → x <ℕ y → x < y
<ℕ⇒< {x} {y} t[x]<t[y] = begin-strict
x ≡⟨ sym (fromℕ-toℕ x) ⟩
fromℕ (toℕ x) <⟨ fromℕ-mono-< t[x]<t[y] ⟩
fromℕ (toℕ y) ≡⟨ fromℕ-toℕ y ⟩
y ∎
where open ≤-Reasoning
------------------------------------------------------------------------
-- Properties of _+_
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Raw bundles for _+_
+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _+_
}
+-0-rawMonoid : RawMonoid 0ℓ 0ℓ
+-0-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _+_
; ε = 0ᵇ
}
------------------------------------------------------------------------
-- toℕ/fromℕ are homomorphisms for _+_
toℕ-homo-+ : ∀ x y → toℕ (x + y) ≡ toℕ x ℕ.+ toℕ y
toℕ-homo-+ zero _ = refl
toℕ-homo-+ 2[1+ x ] zero = cong ℕ.suc (sym (ℕₚ.+-identityʳ _))
toℕ-homo-+ 1+[2 x ] zero = cong ℕ.suc (sym (ℕₚ.+-identityʳ _))
toℕ-homo-+ 2[1+ x ] 2[1+ y ] = begin
toℕ (2[1+ x ] + 2[1+ y ]) ≡⟨⟩
toℕ 2[1+ (suc (x + y)) ] ≡⟨⟩
2 ℕ.* (1 ℕ.+ (toℕ (suc (x + y)))) ≡⟨ cong ((2 ℕ.*_) ∘ ℕ.suc) (toℕ-suc (x + y)) ⟩
2 ℕ.* (2 ℕ.+ toℕ (x + y)) ≡⟨ cong ((2 ℕ.*_) ∘ (2 ℕ.+_)) (toℕ-homo-+ x y) ⟩
2 ℕ.* (2 ℕ.+ (toℕ x ℕ.+ toℕ y)) ≡⟨ solve 2 (λ m n → con 2 :* (con 2 :+ (m :+ n)) :=
con 2 :* (con 1 :+ m) :+ con 2 :* (con 1 :+ n))
refl (toℕ x) (toℕ y) ⟩
toℕ 2[1+ x ] ℕ.+ toℕ 2[1+ y ] ∎
where open ≡-Reasoning
toℕ-homo-+ 2[1+ x ] 1+[2 y ] = begin
toℕ (2[1+ x ] + 1+[2 y ]) ≡⟨⟩
toℕ (suc 2[1+ (x + y) ]) ≡⟨ toℕ-suc 2[1+ (x + y) ] ⟩
ℕ.suc (toℕ 2[1+ (x + y) ]) ≡⟨⟩
ℕ.suc (2 ℕ.* (ℕ.suc (toℕ (x + y)))) ≡⟨ cong (λ v → ℕ.suc (2 ℕ.* ℕ.suc v)) (toℕ-homo-+ x y) ⟩
ℕ.suc (2 ℕ.* (ℕ.suc (m ℕ.+ n))) ≡⟨ solve 2 (λ m n → con 1 :+ (con 2 :* (con 1 :+ (m :+ n))) :=
con 2 :* (con 1 :+ m) :+ (con 1 :+ (con 2 :* n)))
refl m n ⟩
(2 ℕ.* ℕ.suc m) ℕ.+ (ℕ.suc (2 ℕ.* n)) ≡⟨⟩
toℕ 2[1+ x ] ℕ.+ toℕ 1+[2 y ] ∎
where open ≡-Reasoning; m = toℕ x; n = toℕ y
toℕ-homo-+ 1+[2 x ] 2[1+ y ] = begin
toℕ (1+[2 x ] + 2[1+ y ]) ≡⟨⟩
toℕ (suc 2[1+ (x + y) ]) ≡⟨ toℕ-suc 2[1+ (x + y) ] ⟩
ℕ.suc (toℕ 2[1+ (x + y) ]) ≡⟨⟩
ℕ.suc (2 ℕ.* (ℕ.suc (toℕ (x + y)))) ≡⟨ cong (ℕ.suc ∘ (2 ℕ.*_) ∘ ℕ.suc) (toℕ-homo-+ x y) ⟩
ℕ.suc (2 ℕ.* (ℕ.suc (m ℕ.+ n))) ≡⟨ solve 2 (λ m n → con 1 :+ (con 2 :* (con 1 :+ (m :+ n))) :=
(con 1 :+ (con 2 :* m)) :+ (con 2 :* (con 1 :+ n)))
refl m n ⟩
(ℕ.suc (2 ℕ.* m)) ℕ.+ (2 ℕ.* (ℕ.suc n)) ≡⟨⟩
toℕ 1+[2 x ] ℕ.+ toℕ 2[1+ y ] ∎
where open ≡-Reasoning; m = toℕ x; n = toℕ y
toℕ-homo-+ 1+[2 x ] 1+[2 y ] = begin
toℕ (1+[2 x ] + 1+[2 y ]) ≡⟨⟩
toℕ (suc 1+[2 (x + y) ]) ≡⟨ toℕ-suc 1+[2 (x + y) ] ⟩
ℕ.suc (toℕ 1+[2 (x + y) ]) ≡⟨⟩
ℕ.suc (ℕ.suc (2 ℕ.* (toℕ (x + y)))) ≡⟨ cong (ℕ.suc ∘ ℕ.suc ∘ (2 ℕ.*_)) (toℕ-homo-+ x y) ⟩
ℕ.suc (ℕ.suc (2 ℕ.* (m ℕ.+ n))) ≡⟨ solve 2 (λ m n → con 1 :+ (con 1 :+ (con 2 :* (m :+ n))) :=
(con 1 :+ (con 2 :* m)) :+ (con 1 :+ (con 2 :* n)))
refl m n ⟩
(ℕ.suc (2 ℕ.* m)) ℕ.+ (ℕ.suc (2 ℕ.* n)) ≡⟨⟩
toℕ 1+[2 x ] ℕ.+ toℕ 1+[2 y ] ∎
where open ≡-Reasoning; m = toℕ x; n = toℕ y
toℕ-isMagmaHomomorphism-+ : IsMagmaHomomorphism +-rawMagma ℕₚ.+-rawMagma toℕ
toℕ-isMagmaHomomorphism-+ = record
{ isRelHomomorphism = toℕ-isRelHomomorphism
; homo = toℕ-homo-+
}
toℕ-isMonoidHomomorphism-+ : IsMonoidHomomorphism +-0-rawMonoid ℕₚ.+-0-rawMonoid toℕ
toℕ-isMonoidHomomorphism-+ = record
{ isMagmaHomomorphism = toℕ-isMagmaHomomorphism-+
; ε-homo = refl
}
toℕ-isMonoidMonomorphism-+ : IsMonoidMonomorphism +-0-rawMonoid ℕₚ.+-0-rawMonoid toℕ
toℕ-isMonoidMonomorphism-+ = record
{ isMonoidHomomorphism = toℕ-isMonoidHomomorphism-+
; injective = toℕ-injective
}
suc≗1+ : suc ≗ 1ᵇ +_
suc≗1+ zero = refl
suc≗1+ 2[1+ _ ] = refl
suc≗1+ 1+[2 _ ] = refl
suc-+ : ∀ x y → suc x + y ≡ suc (x + y)
suc-+ zero y = sym (suc≗1+ y)
suc-+ 2[1+ x ] zero = refl
suc-+ 1+[2 x ] zero = refl
suc-+ 2[1+ x ] 2[1+ y ] = cong (suc ∘ 2[1+_]) (suc-+ x y)
suc-+ 2[1+ x ] 1+[2 y ] = cong (suc ∘ 1+[2_]) (suc-+ x y)
suc-+ 1+[2 x ] 2[1+ y ] = refl
suc-+ 1+[2 x ] 1+[2 y ] = refl
1+≗suc : (1ᵇ +_) ≗ suc
1+≗suc = suc-+ zero
fromℕ-homo-+ : ∀ m n → fromℕ (m ℕ.+ n) ≡ fromℕ m + fromℕ n
fromℕ-homo-+ 0 _ = refl
fromℕ-homo-+ (ℕ.suc m) n = begin
fromℕ ((ℕ.suc m) ℕ.+ n) ≡⟨⟩
suc (fromℕ (m ℕ.+ n)) ≡⟨ cong suc (fromℕ-homo-+ m n) ⟩
suc (a + b) ≡⟨ sym (suc-+ a b) ⟩
(suc a) + b ≡⟨⟩
(fromℕ (ℕ.suc m)) + (fromℕ n) ∎
where open ≡-Reasoning; a = fromℕ m; b = fromℕ n
------------------------------------------------------------------------
-- Algebraic properties of _+_
-- Mostly proved by using the isomorphism between `ℕ` and `ℕᵇ` provided
-- by `toℕ`/`fromℕ`.
private
module +-Monomorphism = MonoidMonomorphism toℕ-isMonoidMonomorphism-+
+-assoc : Associative _+_
+-assoc = +-Monomorphism.assoc ℕₚ.+-isMagma ℕₚ.+-assoc
+-comm : Commutative _+_
+-comm = +-Monomorphism.comm ℕₚ.+-isMagma ℕₚ.+-comm
+-identityˡ : LeftIdentity zero _+_
+-identityˡ _ = refl
+-identityʳ : RightIdentity zero _+_
+-identityʳ = +-Monomorphism.identityʳ ℕₚ.+-isMagma ℕₚ.+-identityʳ
+-identity : Identity zero _+_
+-identity = +-identityˡ , +-identityʳ
+-cancelˡ-≡ : LeftCancellative _+_
+-cancelˡ-≡ = +-Monomorphism.cancelˡ ℕₚ.+-isMagma ℕₚ.+-cancelˡ-≡
+-cancelʳ-≡ : RightCancellative _+_
+-cancelʳ-≡ = +-Monomorphism.cancelʳ ℕₚ.+-isMagma ℕₚ.+-cancelʳ-≡
------------------------------------------------------------------------
-- Structures for _+_
+-isMagma : IsMagma _+_
+-isMagma = isMagma _+_
+-isSemigroup : IsSemigroup _+_
+-isSemigroup = +-Monomorphism.isSemigroup ℕₚ.+-isSemigroup
+-0-isMonoid : IsMonoid _+_ 0ᵇ
+-0-isMonoid = +-Monomorphism.isMonoid ℕₚ.+-0-isMonoid
+-0-isCommutativeMonoid : IsCommutativeMonoid _+_ 0ᵇ
+-0-isCommutativeMonoid = +-Monomorphism.isCommutativeMonoid ℕₚ.+-0-isCommutativeMonoid
------------------------------------------------------------------------
-- Bundles for _+_
+-magma : Magma 0ℓ 0ℓ
+-magma = magma _+_
+-semigroup : Semigroup 0ℓ 0ℓ
+-semigroup = record
{ isSemigroup = +-isSemigroup
}
+-0-monoid : Monoid 0ℓ 0ℓ
+-0-monoid = record
{ ε = zero
; isMonoid = +-0-isMonoid
}
+-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
+-0-commutativeMonoid = record
{ isCommutativeMonoid = +-0-isCommutativeMonoid
}
------------------------------------------------------------------------------
-- Properties of _+_ and _≤_
+-mono-≤ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
+-mono-≤ {x} {x'} {y} {y'} x≤x' y≤y' = begin
x + y ≡⟨ sym $ cong₂ _+_ (fromℕ-toℕ x) (fromℕ-toℕ y) ⟩
fromℕ m + fromℕ n ≡⟨ sym (fromℕ-homo-+ m n) ⟩
fromℕ (m ℕ.+ n) ≤⟨ fromℕ-mono-≤ (ℕₚ.+-mono-≤ m≤m' n≤n') ⟩
fromℕ (m' ℕ.+ n') ≡⟨ fromℕ-homo-+ m' n' ⟩
fromℕ m' + fromℕ n' ≡⟨ cong₂ _+_ (fromℕ-toℕ x') (fromℕ-toℕ y') ⟩
x' + y' ∎
where
open ≤-Reasoning
m = toℕ x; m' = toℕ x'
n = toℕ y; n' = toℕ y'
m≤m' = toℕ-mono-≤ x≤x'; n≤n' = toℕ-mono-≤ y≤y'
+-monoˡ-≤ : ∀ x → (_+ x) Preserves _≤_ ⟶ _≤_
+-monoˡ-≤ x y≤z = +-mono-≤ y≤z (≤-refl {x})
+-monoʳ-≤ : ∀ x → (x +_) Preserves _≤_ ⟶ _≤_
+-monoʳ-≤ x y≤z = +-mono-≤ (≤-refl {x}) y≤z
+-mono-<-≤ : _+_ Preserves₂ _<_ ⟶ _≤_ ⟶ _<_
+-mono-<-≤ {x} {x'} {y} {y'} x<x' y≤y' = begin-strict
x + y ≡⟨ sym $ cong₂ _+_ (fromℕ-toℕ x) (fromℕ-toℕ y) ⟩
fromℕ m + fromℕ n ≡⟨ sym (fromℕ-homo-+ m n) ⟩
fromℕ (m ℕ.+ n) <⟨ fromℕ-mono-< (ℕₚ.+-mono-<-≤ m<m' n≤n') ⟩
fromℕ (m' ℕ.+ n') ≡⟨ fromℕ-homo-+ m' n' ⟩
fromℕ m' + fromℕ n' ≡⟨ cong₂ _+_ (fromℕ-toℕ x') (fromℕ-toℕ y') ⟩
x' + y' ∎
where
open ≤-Reasoning
m = toℕ x; n = toℕ y
m' = toℕ x'; n' = toℕ y'
m<m' = toℕ-mono-< x<x'; n≤n' = toℕ-mono-≤ y≤y'
+-mono-≤-< : _+_ Preserves₂ _≤_ ⟶ _<_ ⟶ _<_
+-mono-≤-< {x} {x'} {y} {y'} x≤x' y<y' = subst₂ _<_ (+-comm y x) (+-comm y' x') y+x<y'+x'
where
y+x<y'+x' = +-mono-<-≤ y<y' x≤x'
+-monoˡ-< : ∀ x → (_+ x) Preserves _<_ ⟶ _<_
+-monoˡ-< x y<z = +-mono-<-≤ y<z (≤-refl {x})
+-monoʳ-< : ∀ x → (x +_) Preserves _<_ ⟶ _<_
+-monoʳ-< x y<z = +-mono-≤-< (≤-refl {x}) y<z
x≤y+x : ∀ x y → x ≤ y + x
x≤y+x x y = begin
x ≡⟨ sym (+-identityˡ x) ⟩
0ᵇ + x ≤⟨ +-monoˡ-≤ x (0≤x y) ⟩
y + x ∎
where open ≤-Reasoning
x≤x+y : ∀ x y → x ≤ x + y
x≤x+y x y = begin
x ≤⟨ x≤y+x x y ⟩
y + x ≡⟨ +-comm y x ⟩
x + y ∎
where open ≤-Reasoning
x<x+y : ∀ x {y} → y > 0ᵇ → x < x + y
x<x+y x {y} y>0 = begin-strict
x ≡⟨ sym (fromℕ-toℕ x) ⟩
fromℕ (toℕ x) <⟨ fromℕ-mono-< (ℕₚ.m<m+n (toℕ x) (toℕ-mono-< y>0)) ⟩
fromℕ (toℕ x ℕ.+ toℕ y) ≡⟨ fromℕ-homo-+ (toℕ x) (toℕ y) ⟩
fromℕ (toℕ x) + fromℕ (toℕ y) ≡⟨ cong₂ _+_ (fromℕ-toℕ x) (fromℕ-toℕ y) ⟩
x + y ∎
where open ≤-Reasoning
x<x+1 : ∀ x → x < x + 1ᵇ
x<x+1 x = x<x+y x 0<odd
x<1+x : ∀ x → x < 1ᵇ + x
x<1+x x rewrite +-comm 1ᵇ x = x<x+1 x
x<1⇒x≡0 : ∀ {x} → x < 1ᵇ → x ≡ zero
x<1⇒x≡0 0<odd = refl
------------------------------------------------------------------------
-- Other properties
x≢0⇒x+y≢0 : ∀ {x} (y : ℕᵇ) → x ≢ zero → x + y ≢ zero
x≢0⇒x+y≢0 {2[1+ _ ]} zero _ = λ()
x≢0⇒x+y≢0 {zero} _ 0≢0 = contradiction refl 0≢0
------------------------------------------------------------------------
-- Properties of _*_
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Raw bundles for _*_
*-rawMagma : RawMagma 0ℓ 0ℓ
*-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _*_
}
*-1-rawMonoid : RawMonoid 0ℓ 0ℓ
*-1-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _*_
; ε = 1ᵇ
}
------------------------------------------------------------------------
-- toℕ/fromℕ are homomorphisms for _*_
private 2*ₙ2*ₙ = (2 ℕ.*_) ∘ (2 ℕ.*_)
toℕ-homo-* : ∀ x y → toℕ (x * y) ≡ toℕ x ℕ.* toℕ y
toℕ-homo-* x y = aux x y (size x ℕ.+ size y) ℕₚ.≤-refl
where
aux : (x y : ℕᵇ) → (cnt : ℕ) → (size x ℕ.+ size y ℕ.≤ cnt) → toℕ (x * y) ≡ toℕ x ℕ.* toℕ y
aux zero _ _ _ = refl
aux 2[1+ x ] zero _ _ = sym (ℕₚ.*-zeroʳ (toℕ x ℕ.+ (ℕ.suc (toℕ x ℕ.+ 0))))
aux 1+[2 x ] zero _ _ = sym (ℕₚ.*-zeroʳ (toℕ x ℕ.+ (toℕ x ℕ.+ 0)))
aux 2[1+ x ] 2[1+ y ] (ℕ.suc cnt) (s≤s |x|+1+|y|≤cnt) = begin
toℕ (2[1+ x ] * 2[1+ y ]) ≡⟨⟩
toℕ (double 2[1+ (x + (y + xy)) ]) ≡⟨ toℕ-double 2[1+ (x + (y + xy)) ] ⟩
2 ℕ.* (toℕ 2[1+ (x + (y + xy)) ]) ≡⟨⟩
2*ₙ2*ₙ (ℕ.suc (toℕ (x + (y + xy)))) ≡⟨ cong (2*ₙ2*ₙ ∘ ℕ.suc) (toℕ-homo-+ x (y + xy)) ⟩
2*ₙ2*ₙ (ℕ.suc (m ℕ.+ (toℕ (y + xy)))) ≡⟨ cong (2*ₙ2*ₙ ∘ ℕ.suc ∘ (m ℕ.+_)) (toℕ-homo-+ y xy) ⟩
2*ₙ2*ₙ (ℕ.suc (m ℕ.+ (n ℕ.+ toℕ xy))) ≡⟨ cong (2*ₙ2*ₙ ∘ ℕ.suc ∘ (m ℕ.+_) ∘ (n ℕ.+_))
(aux x y cnt |x|+|y|≤cnt) ⟩
2*ₙ2*ₙ (ℕ.suc (m ℕ.+ (n ℕ.+ (m ℕ.* n)))) ≡⟨ solve 2 (λ m n → con 2 :* (con 2 :* (con 1 :+ (m :+ (n :+ m :* n)))) :=
(con 2 :* (con 1 :+ m)) :* (con 2 :* (con 1 :+ n)))
refl m n ⟩
(2 ℕ.* (1 ℕ.+ m)) ℕ.* (2 ℕ.* (1 ℕ.+ n)) ≡⟨⟩
toℕ 2[1+ x ] ℕ.* toℕ 2[1+ y ] ∎
where
open ≡-Reasoning; m = toℕ x; n = toℕ y; xy = x * y
|x|+|y|≤cnt = ℕₚ.≤-trans (ℕₚ.+-monoʳ-≤ (size x) (ℕₚ.n≤1+n (size y))) |x|+1+|y|≤cnt
aux 2[1+ x ] 1+[2 y ] (ℕ.suc cnt) (s≤s |x|+1+|y|≤cnt) = begin
toℕ (2[1+ x ] * 1+[2 y ]) ≡⟨⟩
toℕ (2[1+ (x + y * 2[1+ x ]) ]) ≡⟨⟩
2 ℕ.* (ℕ.suc (toℕ (x + y * 2[1+ x ]))) ≡⟨ cong ((2 ℕ.*_) ∘ ℕ.suc) (toℕ-homo-+ x _) ⟩
2 ℕ.* (ℕ.suc (m ℕ.+ (toℕ (y * 2[1+ x ])))) ≡⟨ cong ((2 ℕ.*_) ∘ ℕ.suc ∘ (m ℕ.+_))
(aux y 2[1+ x ] cnt |y|+1+|x|≤cnt) ⟩
2 ℕ.* (1+m ℕ.+ (n ℕ.* (toℕ 2[1+ x ]))) ≡⟨⟩
2 ℕ.* (1+m ℕ.+ (n ℕ.* 2[1+m])) ≡⟨ solve 2 (λ m n →
con 2 :* ((con 1 :+ m) :+ (n :* (con 2 :* (con 1 :+ m)))) :=
(con 2 :* (con 1 :+ m)) :* (con 1 :+ con 2 :* n))
refl m n ⟩
2[1+m] ℕ.* (ℕ.suc (2 ℕ.* n)) ≡⟨⟩
toℕ 2[1+ x ] ℕ.* toℕ 1+[2 y ] ∎
where
open ≡-Reasoning; m = toℕ x; n = toℕ y; 1+m = ℕ.suc m; 2[1+m] = 2 ℕ.* (ℕ.suc m)
eq : size x ℕ.+ (ℕ.suc (size y)) ≡ size y ℕ.+ (ℕ.suc (size x))
eq = ℕ-+-semigroupProperties.x∙yz≈z∙yx (size x) 1 _
|y|+1+|x|≤cnt = subst (ℕ._≤ cnt) eq |x|+1+|y|≤cnt
aux 1+[2 x ] 2[1+ y ] (ℕ.suc cnt) (s≤s |x|+1+|y|≤cnt) = begin
toℕ (1+[2 x ] * 2[1+ y ]) ≡⟨⟩
toℕ 2[1+ (y + x * 2[1+ y ]) ] ≡⟨⟩
2 ℕ.* (ℕ.suc (toℕ (y + x * 2[1+ y ]))) ≡⟨ cong ((2 ℕ.*_) ∘ ℕ.suc)
(toℕ-homo-+ y (x * 2[1+ y ])) ⟩
2 ℕ.* (ℕ.suc (n ℕ.+ (toℕ (x * 2[1+ y ])))) ≡⟨ cong ((2 ℕ.*_) ∘ ℕ.suc ∘ (n ℕ.+_))
(aux x 2[1+ y ] cnt |x|+1+|y|≤cnt) ⟩
2 ℕ.* (1+n ℕ.+ (m ℕ.* toℕ 2[1+ y ])) ≡⟨⟩
2 ℕ.* (1+n ℕ.+ (m ℕ.* 2[1+n])) ≡⟨ solve 2 (λ m n →
con 2 :* ((con 1 :+ n) :+ (m :* (con 2 :* (con 1 :+ n)))) :=
(con 1 :+ (con 2 :* m)) :* (con 2 :* (con 1 :+ n)))
refl m n ⟩
(ℕ.suc 2m) ℕ.* 2[1+n] ≡⟨⟩
toℕ 1+[2 x ] ℕ.* toℕ 2[1+ y ] ∎
where
open ≡-Reasoning
m = toℕ x; n = toℕ y; 1+n = ℕ.suc n
2m = 2 ℕ.* m; 2[1+n] = 2 ℕ.* (ℕ.suc n)
aux 1+[2 x ] 1+[2 y ] (ℕ.suc cnt) (s≤s |x|+1+|y|≤cnt) = begin
toℕ (1+[2 x ] * 1+[2 y ]) ≡⟨⟩
toℕ 1+[2 (x + y * 1+2x) ] ≡⟨⟩
ℕ.suc (2 ℕ.* (toℕ (x + y * 1+2x))) ≡⟨ cong (ℕ.suc ∘ (2 ℕ.*_)) (toℕ-homo-+ x (y * 1+2x)) ⟩
ℕ.suc (2 ℕ.* (m ℕ.+ (toℕ (y * 1+2x)))) ≡⟨ cong (ℕ.suc ∘ (2 ℕ.*_) ∘ (m ℕ.+_))
(aux y 1+2x cnt |y|+1+|x|≤cnt) ⟩
ℕ.suc (2 ℕ.* (m ℕ.+ (n ℕ.* [1+2x]'))) ≡⟨ cong ℕ.suc $ ℕₚ.*-distribˡ-+ 2 m (n ℕ.* [1+2x]') ⟩
ℕ.suc (2m ℕ.+ (2 ℕ.* (n ℕ.* [1+2x]'))) ≡⟨ cong (ℕ.suc ∘ (2m ℕ.+_)) (sym (ℕₚ.*-assoc 2 n _)) ⟩
(ℕ.suc 2m) ℕ.+ 2n ℕ.* [1+2x]' ≡⟨⟩
[1+2x]' ℕ.+ 2n ℕ.* [1+2x]' ≡⟨ cong (ℕ._+ (2n ℕ.* [1+2x]')) $
sym (ℕₚ.*-identityˡ [1+2x]') ⟩
1 ℕ.* [1+2x]' ℕ.+ 2n ℕ.* [1+2x]' ≡⟨ sym (ℕₚ.*-distribʳ-+ [1+2x]' 1 2n) ⟩
(ℕ.suc 2n) ℕ.* [1+2x]' ≡⟨ ℕₚ.*-comm (ℕ.suc 2n) [1+2x]' ⟩
toℕ 1+[2 x ] ℕ.* toℕ 1+[2 y ] ∎
where
open ≡-Reasoning
m = toℕ x; n = toℕ y; 2m = 2 ℕ.* m; 2n = 2 ℕ.* n
1+2x = 1+[2 x ]; [1+2x]' = toℕ 1+2x
eq : size x ℕ.+ (ℕ.suc (size y)) ≡ size y ℕ.+ (ℕ.suc (size x))
eq = ℕ-+-semigroupProperties.x∙yz≈z∙yx (size x) 1 _
|y|+1+|x|≤cnt = subst (ℕ._≤ cnt) eq |x|+1+|y|≤cnt
toℕ-isMagmaHomomorphism-* : IsMagmaHomomorphism *-rawMagma ℕₚ.*-rawMagma toℕ
toℕ-isMagmaHomomorphism-* = record
{ isRelHomomorphism = toℕ-isRelHomomorphism
; homo = toℕ-homo-*
}
toℕ-isMonoidHomomorphism-* : IsMonoidHomomorphism *-1-rawMonoid ℕₚ.*-1-rawMonoid toℕ
toℕ-isMonoidHomomorphism-* = record
{ isMagmaHomomorphism = toℕ-isMagmaHomomorphism-*
; ε-homo = refl
}
toℕ-isMonoidMonomorphism-* : IsMonoidMonomorphism *-1-rawMonoid ℕₚ.*-1-rawMonoid toℕ
toℕ-isMonoidMonomorphism-* = record
{ isMonoidHomomorphism = toℕ-isMonoidHomomorphism-*
; injective = toℕ-injective
}
fromℕ-homo-* : ∀ m n → fromℕ (m ℕ.* n) ≡ fromℕ m * fromℕ n
fromℕ-homo-* m n = begin
fromℕ (m ℕ.* n) ≡⟨ cong fromℕ (cong₂ ℕ._*_ m≡aN n≡bN) ⟩
fromℕ (toℕ a ℕ.* toℕ b) ≡⟨ cong fromℕ (sym (toℕ-homo-* a b)) ⟩
fromℕ (toℕ (a * b)) ≡⟨ fromℕ-toℕ (a * b) ⟩
a * b ∎
where
open ≡-Reasoning
a = fromℕ m; b = fromℕ n
m≡aN = sym (toℕ-fromℕ m); n≡bN = sym (toℕ-fromℕ n)
private
module *-Monomorphism = MonoidMonomorphism toℕ-isMonoidMonomorphism-*
------------------------------------------------------------------------
-- Algebraic properties of _*_
-- Mostly proved by using the isomorphism between `ℕ` and `ℕᵇ` provided
-- by `toℕ`/`fromℕ`.
*-assoc : Associative _*_
*-assoc = *-Monomorphism.assoc ℕₚ.*-isMagma ℕₚ.*-assoc
*-comm : Commutative _*_
*-comm = *-Monomorphism.comm ℕₚ.*-isMagma ℕₚ.*-comm
*-identityˡ : LeftIdentity 1ᵇ _*_
*-identityˡ = *-Monomorphism.identityˡ ℕₚ.*-isMagma ℕₚ.*-identityˡ
*-identityʳ : RightIdentity 1ᵇ _*_
*-identityʳ x = trans (*-comm x 1ᵇ) (*-identityˡ x)
*-identity : Identity 1ᵇ _*_
*-identity = (*-identityˡ , *-identityʳ)
*-zeroˡ : LeftZero zero _*_
*-zeroˡ _ = refl
*-zeroʳ : RightZero zero _*_
*-zeroʳ zero = refl
*-zeroʳ 2[1+ _ ] = refl
*-zeroʳ 1+[2 _ ] = refl
*-zero : Zero zero _*_
*-zero = *-zeroˡ , *-zeroʳ
*-distribˡ-+ : _*_ DistributesOverˡ _+_
*-distribˡ-+ a b c = begin
a * (b + c) ≡⟨ sym (fromℕ-toℕ (a * (b + c))) ⟩
fromℕ (toℕ (a * (b + c))) ≡⟨ cong fromℕ (toℕ-homo-* a (b + c)) ⟩
fromℕ (k ℕ.* (toℕ (b + c))) ≡⟨ cong (fromℕ ∘ (k ℕ.*_)) (toℕ-homo-+ b c) ⟩
fromℕ (k ℕ.* (m ℕ.+ n)) ≡⟨ cong fromℕ (ℕₚ.*-distribˡ-+ k m n) ⟩
fromℕ (k ℕ.* m ℕ.+ k ℕ.* n) ≡⟨ cong fromℕ $ sym $
cong₂ ℕ._+_ (toℕ-homo-* a b) (toℕ-homo-* a c) ⟩
fromℕ (toℕ (a * b) ℕ.+ toℕ (a * c)) ≡⟨ cong fromℕ (sym (toℕ-homo-+ (a * b) (a * c))) ⟩
fromℕ (toℕ (a * b + a * c)) ≡⟨ fromℕ-toℕ (a * b + a * c) ⟩
a * b + a * c ∎
where open ≡-Reasoning; k = toℕ a; m = toℕ b; n = toℕ c
*-distribʳ-+ : _*_ DistributesOverʳ _+_
*-distribʳ-+ = comm+distrˡ⇒distrʳ *-comm *-distribˡ-+
*-distrib-+ : _*_ DistributesOver _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
------------------------------------------------------------------------
-- Structures
*-isMagma : IsMagma _*_
*-isMagma = isMagma _*_
*-isSemigroup : IsSemigroup _*_
*-isSemigroup = *-Monomorphism.isSemigroup ℕₚ.*-isSemigroup
*-1-isMonoid : IsMonoid _*_ 1ᵇ
*-1-isMonoid = *-Monomorphism.isMonoid ℕₚ.*-1-isMonoid
*-1-isCommutativeMonoid : IsCommutativeMonoid _*_ 1ᵇ
*-1-isCommutativeMonoid = *-Monomorphism.isCommutativeMonoid ℕₚ.*-1-isCommutativeMonoid
*-+-isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero _+_ _*_ zero 1ᵇ
*-+-isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-0-isCommutativeMonoid
; *-isMonoid = *-1-isMonoid
; distrib = *-distrib-+
}
*-+-isSemiring : IsSemiring _+_ _*_ zero 1ᵇ
*-+-isSemiring = record
{ isSemiringWithoutAnnihilatingZero = *-+-isSemiringWithoutAnnihilatingZero
; zero = *-zero
}
*-+-isCommutativeSemiring : IsCommutativeSemiring _+_ _*_ zero 1ᵇ
*-+-isCommutativeSemiring = record
{ isSemiring = *-+-isSemiring
; *-comm = *-comm
}
------------------------------------------------------------------------
-- Bundles
*-magma : Magma 0ℓ 0ℓ
*-magma = record
{ isMagma = *-isMagma
}
*-semigroup : Semigroup 0ℓ 0ℓ
*-semigroup = record
{ isSemigroup = *-isSemigroup
}
*-1-monoid : Monoid 0ℓ 0ℓ
*-1-monoid = record
{ isMonoid = *-1-isMonoid
}
*-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
*-1-commutativeMonoid = record
{ isCommutativeMonoid = *-1-isCommutativeMonoid
}
*-+-semiring : Semiring 0ℓ 0ℓ
*-+-semiring = record
{ isSemiring = *-+-isSemiring
}
*-+-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ
*-+-commutativeSemiring = record
{ isCommutativeSemiring = *-+-isCommutativeSemiring
}
------------------------------------------------------------------------
-- Properties of _*_ and _≤_ & _<_
*-mono-≤ : _*_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
*-mono-≤ {x} {u} {y} {v} x≤u y≤v = toℕ-cancel-≤ (begin
toℕ (x * y) ≡⟨ toℕ-homo-* x y ⟩
toℕ x ℕ.* toℕ y ≤⟨ ℕₚ.*-mono-≤ (toℕ-mono-≤ x≤u) (toℕ-mono-≤ y≤v) ⟩
toℕ u ℕ.* toℕ v ≡⟨ sym (toℕ-homo-* u v) ⟩
toℕ (u * v) ∎)
where open ℕₚ.≤-Reasoning
*-monoʳ-≤ : ∀ x → (x *_) Preserves _≤_ ⟶ _≤_
*-monoʳ-≤ x y≤y' = *-mono-≤ (≤-refl {x}) y≤y'
*-monoˡ-≤ : ∀ x → (_* x) Preserves _≤_ ⟶ _≤_
*-monoˡ-≤ x y≤y' = *-mono-≤ y≤y' (≤-refl {x})
*-mono-< : _*_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
*-mono-< {x} {u} {y} {v} x<u y<v = toℕ-cancel-< (begin-strict
toℕ (x * y) ≡⟨ toℕ-homo-* x y ⟩
toℕ x ℕ.* toℕ y <⟨ ℕₚ.*-mono-< (toℕ-mono-< x<u) (toℕ-mono-< y<v) ⟩
toℕ u ℕ.* toℕ v ≡⟨ sym (toℕ-homo-* u v) ⟩
toℕ (u * v) ∎)
where open ℕₚ.≤-Reasoning
*-monoʳ-< : ∀ x → ((1ᵇ + x) *_) Preserves _<_ ⟶ _<_
*-monoʳ-< x {y} {z} y<z = begin-strict
(1ᵇ + x) * y ≡⟨ *-distribʳ-+ y 1ᵇ x ⟩
1ᵇ * y + x * y ≡⟨ cong (_+ x * y) (*-identityˡ y) ⟩
y + x * y <⟨ +-mono-<-≤ y<z (*-monoʳ-≤ x (<⇒≤ y<z)) ⟩
z + x * z ≡⟨ cong (_+ x * z) (sym (*-identityˡ z)) ⟩
1ᵇ * z + x * z ≡⟨ sym (*-distribʳ-+ z 1ᵇ x) ⟩
(1ᵇ + x) * z ∎
where open ≤-Reasoning
*-monoˡ-< : ∀ x → (_* (1ᵇ + x)) Preserves _<_ ⟶ _<_
*-monoˡ-< x {y} {z} y<z = begin-strict
y * (1ᵇ + x) ≡⟨ *-comm y (1ᵇ + x) ⟩
(1ᵇ + x) * y <⟨ *-monoʳ-< x y<z ⟩
(1ᵇ + x) * z ≡⟨ *-comm (1ᵇ + x) z ⟩
z * (1ᵇ + x) ∎
where open ≤-Reasoning
------------------------------------------------------------------------
-- Other properties of _*_
x*y≡0⇒x≡0∨y≡0 : ∀ x {y} → x * y ≡ zero → x ≡ zero ⊎ y ≡ zero
x*y≡0⇒x≡0∨y≡0 zero {_} _ = inj₁ refl
x*y≡0⇒x≡0∨y≡0 _ {zero} _ = inj₂ refl
x≢0∧y≢0⇒x*y≢0 : ∀ {x y} → x ≢ zero → y ≢ zero → x * y ≢ zero
x≢0∧y≢0⇒x*y≢0 {x} {_} x≢0 y≢0 xy≡0 with x*y≡0⇒x≡0∨y≡0 x xy≡0
... | inj₁ x≡0 = x≢0 x≡0
... | inj₂ y≡0 = y≢0 y≡0
2*x≡x+x : ∀ x → 2ᵇ * x ≡ x + x
2*x≡x+x x = begin
2ᵇ * x ≡⟨⟩
(1ᵇ + 1ᵇ) * x ≡⟨ *-distribʳ-+ x 1ᵇ 1ᵇ ⟩
1ᵇ * x + 1ᵇ * x ≡⟨ cong₂ _+_ (*-identityˡ x) (*-identityˡ x) ⟩
x + x ∎
where open ≡-Reasoning
1+-* : ∀ x y → (1ᵇ + x) * y ≡ y + x * y
1+-* x y = begin
(1ᵇ + x) * y ≡⟨ *-distribʳ-+ y 1ᵇ x ⟩
1ᵇ * y + x * y ≡⟨ cong (_+ x * y) (*-identityˡ y) ⟩
y + x * y ∎
where open ≡-Reasoning
*-1+ : ∀ x y → y * (1ᵇ + x) ≡ y + y * x
*-1+ x y = begin
y * (1ᵇ + x) ≡⟨ *-distribˡ-+ y 1ᵇ x ⟩
y * 1ᵇ + y * x ≡⟨ cong (_+ y * x) (*-identityʳ y) ⟩
y + y * x ∎
where open ≡-Reasoning
------------------------------------------------------------------------
-- Properties of double
------------------------------------------------------------------------
double[x]≡0⇒x≡0 : ∀ {x} → double x ≡ zero → x ≡ zero
double[x]≡0⇒x≡0 {zero} _ = refl
x≢0⇒double[x]≢0 : ∀ {x} → x ≢ zero → double x ≢ zero
x≢0⇒double[x]≢0 x≢0 = x≢0 ∘ double[x]≡0⇒x≡0
double≢1 : ∀ {x} → double x ≢ 1ᵇ
double≢1 {zero} ()
double≗2* : double ≗ 2ᵇ *_
double≗2* x = toℕ-injective $ begin
toℕ (double x) ≡⟨ toℕ-double x ⟩
2 ℕ.* (toℕ x) ≡⟨ sym (toℕ-homo-* 2ᵇ x) ⟩
toℕ (2ᵇ * x) ∎
where open ≡-Reasoning
double-*-assoc : ∀ x y → (double x) * y ≡ double (x * y)
double-*-assoc x y = begin
(double x) * y ≡⟨ cong (_* y) (double≗2* x) ⟩
(2ᵇ * x) * y ≡⟨ *-assoc 2ᵇ x y ⟩
2ᵇ * (x * y) ≡⟨ sym (double≗2* (x * y)) ⟩
double (x * y) ∎
where open ≡-Reasoning
double[x]≡x+x : ∀ x → double x ≡ x + x
double[x]≡x+x x = trans (double≗2* x) (2*x≡x+x x)
double-distrib-+ : ∀ x y → double (x + y) ≡ double x + double y
double-distrib-+ x y = begin
double (x + y) ≡⟨ double≗2* (x + y) ⟩
2ᵇ * (x + y) ≡⟨ *-distribˡ-+ 2ᵇ x y ⟩
(2ᵇ * x) + (2ᵇ * y) ≡⟨ sym (cong₂ _+_ (double≗2* x) (double≗2* y)) ⟩
double x + double y ∎
where open ≡-Reasoning
double-mono-≤ : double Preserves _≤_ ⟶ _≤_
double-mono-≤ {x} {y} x≤y = begin
double x ≡⟨ double≗2* x ⟩
2ᵇ * x ≤⟨ *-monoʳ-≤ 2ᵇ x≤y ⟩
2ᵇ * y ≡⟨ sym (double≗2* y) ⟩
double y ∎
where open ≤-Reasoning
double-mono-< : double Preserves _<_ ⟶ _<_
double-mono-< {x} {y} x<y = begin-strict
double x ≡⟨ double≗2* x ⟩
2ᵇ * x <⟨ *-monoʳ-< 1ᵇ x<y ⟩
2ᵇ * y ≡⟨ sym (double≗2* y) ⟩
double y ∎
where open ≤-Reasoning
double-cancel-≤ : ∀ {x y} → double x ≤ double y → x ≤ y
double-cancel-≤ {x} {y} 2x≤2y with <-cmp x y
... | tri< x<y _ _ = <⇒≤ x<y
... | tri≈ _ x≡y _ = ≤-reflexive x≡y
... | tri> _ _ x>y = contradiction 2x≤2y (<⇒≱ (double-mono-< x>y))
double-cancel-< : ∀ {x y} → double x < double y → x < y
double-cancel-< {x} {y} 2x<2y with <-cmp x y
... | tri< x<y _ _ = x<y
... | tri≈ _ refl _ = contradiction 2x<2y (<-irrefl refl)
... | tri> _ _ x>y = contradiction (double-mono-< x>y) (<⇒≯ 2x<2y)
x<double[x] : ∀ x → x ≢ zero → x < double x
x<double[x] x x≢0 = begin-strict
x <⟨ x<x+y x (x≢0⇒x>0 x≢0) ⟩
x + x ≡⟨ sym (double[x]≡x+x x) ⟩
double x ∎
where open ≤-Reasoning
x≤double[x] : ∀ x → x ≤ double x
x≤double[x] x = begin
x ≤⟨ x≤x+y x x ⟩
x + x ≡⟨ sym (double[x]≡x+x x) ⟩
double x ∎
where open ≤-Reasoning
------------------------------------------------------------------------
-- Properties of suc
------------------------------------------------------------------------
2[1+_]-double-suc : 2[1+_] ≗ double ∘ suc
2[1+_]-double-suc zero = refl
2[1+_]-double-suc 2[1+ x ] = cong 2[1+_] (2[1+_]-double-suc x)
2[1+_]-double-suc 1+[2 x ] = refl
1+[2_]-suc-double : 1+[2_] ≗ suc ∘ double
1+[2_]-suc-double zero = refl
1+[2_]-suc-double 2[1+ x ] = refl
1+[2_]-suc-double 1+[2 x ] = begin
1+[2 1+[2 x ] ] ≡⟨ cong 1+[2_] (1+[2_]-suc-double x) ⟩
1+[2 (suc 2x) ] ≡⟨⟩
suc 2[1+ 2x ] ≡⟨ cong suc (2[1+_]-double-suc 2x) ⟩
suc (double (suc 2x)) ≡⟨ cong (suc ∘ double) (sym (1+[2_]-suc-double x)) ⟩
suc (double 1+[2 x ]) ∎
where open ≡-Reasoning; 2x = double x
suc≢0 : ∀ {x} → suc x ≢ zero
suc≢0 {zero} ()
suc≢0 {2[1+ _ ]} ()
suc≢0 {1+[2 _ ]} ()
0<suc : ∀ x → zero < suc x
0<suc x = x≢0⇒x>0 (suc≢0 {x})
x<suc[x] : ∀ x → x < suc x
x<suc[x] x = begin-strict
x <⟨ x<1+x x ⟩
1ᵇ + x ≡⟨ sym (suc≗1+ x) ⟩
suc x ∎
where open ≤-Reasoning
x≤suc[x] : ∀ x → x ≤ suc x
x≤suc[x] x = <⇒≤ (x<suc[x] x)
x≢suc[x] : ∀ x → x ≢ suc x
x≢suc[x] x = <⇒≢ (x<suc[x] x)
suc-mono-≤ : suc Preserves _≤_ ⟶ _≤_
suc-mono-≤ {x} {y} x≤y = begin
suc x ≡⟨ suc≗1+ x ⟩
1ᵇ + x ≤⟨ +-monoʳ-≤ 1ᵇ x≤y ⟩
1ᵇ + y ≡⟨ sym (suc≗1+ y) ⟩
suc y ∎
where open ≤-Reasoning
suc[x]≤y⇒x<y : ∀ {x y} → suc x ≤ y → x < y
suc[x]≤y⇒x<y {x} (inj₁ sx<y) = <-trans (x<suc[x] x) sx<y
suc[x]≤y⇒x<y {x} (inj₂ refl) = x<suc[x] x
x<y⇒suc[x]≤y : ∀ {x y} → x < y → suc x ≤ y
x<y⇒suc[x]≤y {x} {y} x<y = begin
suc x ≡⟨ sym (fromℕ-toℕ (suc x)) ⟩
fromℕ (toℕ (suc x)) ≡⟨ cong fromℕ (toℕ-suc x) ⟩
fromℕ (ℕ.suc (toℕ x)) ≤⟨ fromℕ-mono-≤ (toℕ-mono-< x<y) ⟩
fromℕ (toℕ y) ≡⟨ fromℕ-toℕ y ⟩
y ∎
where open ≤-Reasoning
suc-* : ∀ x y → suc x * y ≡ y + x * y
suc-* x y = begin
suc x * y ≡⟨ cong (_* y) (suc≗1+ x) ⟩
(1ᵇ + x) * y ≡⟨ 1+-* x y ⟩
y + x * y ∎
where open ≡-Reasoning
*-suc : ∀ x y → x * suc y ≡ x + x * y
*-suc x y = begin
x * suc y ≡⟨ cong (x *_) (suc≗1+ y) ⟩
x * (1ᵇ + y) ≡⟨ *-1+ y x ⟩
x + x * y ∎
where open ≡-Reasoning
x≤suc[y]*x : ∀ x y → x ≤ (suc y) * x
x≤suc[y]*x x y = begin
x ≤⟨ x≤x+y x (y * x) ⟩
x + y * x ≡⟨ sym (suc-* y x) ⟩
(suc y) * x ∎
where open ≤-Reasoning
suc[x]≤double[x] : ∀ x → x ≢ zero → suc x ≤ double x
suc[x]≤double[x] x = x<y⇒suc[x]≤y {x} {double x} ∘ x<double[x] x
suc[x]<2[1+x] : ∀ x → suc x < 2[1+ x ]
suc[x]<2[1+x] x = begin-strict
suc x <⟨ x<double[x] (suc x) suc≢0 ⟩
double (suc x) ≡⟨ sym (2[1+_]-double-suc x) ⟩
2[1+ x ] ∎
where open ≤-Reasoning
double[x]<1+[2x] : ∀ x → double x < 1+[2 x ]
double[x]<1+[2x] x = begin-strict
double x <⟨ x<suc[x] (double x) ⟩
suc (double x) ≡⟨ sym (1+[2_]-suc-double x) ⟩
1+[2 x ] ∎
where open ≤-Reasoning
------------------------------------------------------------------------
-- Properties of pred
------------------------------------------------------------------------
pred-suc : pred ∘ suc ≗ id
pred-suc zero = refl
pred-suc 2[1+ x ] = sym (2[1+_]-double-suc x)
pred-suc 1+[2 x ] = refl
suc-pred : ∀ {x} → x ≢ zero → suc (pred x) ≡ x
suc-pred {zero} 0≢0 = contradiction refl 0≢0
suc-pred {2[1+ _ ]} _ = refl
suc-pred {1+[2 x ]} _ = sym (1+[2_]-suc-double x)
pred-mono-≤ : pred Preserves _≤_ ⟶ _≤_
pred-mono-≤ {x} {y} x≤y = begin
pred x ≡⟨ cong pred (sym (fromℕ-toℕ x)) ⟩
pred (fromℕ m) ≡⟨ sym (fromℕ-pred m) ⟩
fromℕ (ℕ.pred m) ≤⟨ fromℕ-mono-≤ (ℕₚ.pred-mono (toℕ-mono-≤ x≤y)) ⟩
fromℕ (ℕ.pred n) ≡⟨ fromℕ-pred n ⟩
pred (fromℕ n) ≡⟨ cong pred (fromℕ-toℕ y) ⟩
pred y ∎
where
open ≤-Reasoning; m = toℕ x; n = toℕ y
pred[x]<x : ∀ {x} → x ≢ zero → pred x < x
pred[x]<x {x} x≢0 = begin-strict
pred x <⟨ x<suc[x] (pred x) ⟩
suc (pred x) ≡⟨ suc-pred x≢0 ⟩
x ∎
where open ≤-Reasoning
------------------------------------------------------------------------
-- Properties of size
------------------------------------------------------------------------
|x|≡0⇒x≡0 : ∀ {x} → size x ≡ 0 → x ≡ 0ᵇ
|x|≡0⇒x≡0 {zero} refl = refl
| {
"alphanum_fraction": 0.4570037298,
"avg_line_length": 34.9963741842,
"ext": "agda",
"hexsha": "83ed3c23d6bf8ca5c81515872c97e559b92186f6",
"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": "agda-stdlib/src/Data/Nat/Binary/Properties.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": "agda-stdlib/src/Data/Nat/Binary/Properties.agda",
"max_line_length": 119,
"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": "agda-stdlib/src/Data/Nat/Binary/Properties.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": 22952,
"size": 48260
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lemmas for use in proving the polynomial homomorphism.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Tactic.RingSolver.Core.Polynomial.Parameters
module Tactic.RingSolver.Core.Polynomial.Homomorphism.Lemmas
{r₁ r₂ r₃ r₄}
(homo : Homomorphism r₁ r₂ r₃ r₄)
where
open import Data.Bool using (Bool;true;false)
open import Data.Nat.Base as ℕ using (ℕ; suc; zero; compare; _≤′_; ≤′-step; ≤′-refl)
open import Data.Nat.Properties as ℕₚ using (≤′-trans)
open import Data.Vec.Base as Vec using (Vec; _∷_)
open import Data.Fin using (Fin; zero; suc)
open import Data.List using (_∷_; [])
open import Data.Unit using (tt)
open import Data.List.Kleene
open import Data.Product using (_,_; proj₁; proj₂; map₁; _×_)
open import Data.Empty using (⊥-elim)
open import Data.Maybe using (nothing; just)
open import Function
open import Level using (lift)
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
open Homomorphism homo hiding (_^_)
open import Tactic.RingSolver.Core.Polynomial.Reasoning to
open import Tactic.RingSolver.Core.Polynomial.Base from
open import Tactic.RingSolver.Core.Polynomial.Semantics homo
open import Algebra.Operations.Ring rawRing
------------------------------------------------------------------------
-- Power lemmas
--
-- We prove some things about our odd exponentiation operator (described
-- in Algebra.Operations.Ring.Compact) here.
-- First, that the optimised operator is the same as normal
-- exponentiation.
pow-opt : ∀ x ρ i → x *⟨ ρ ⟩^ i ≈ ρ ^ i * x
pow-opt x ρ ℕ.zero = sym (*-identityˡ x)
pow-opt x ρ (suc i) = refl
-- Some normal identities on exponentiation.
-- xⁿxᵐ = xⁿ⁺ᵐ
pow-add′ : ∀ x i j → (x ^ i +1) * (x ^ j +1) ≈ x ^ (j ℕ.+ suc i) +1
pow-add′ x i ℕ.zero = refl
pow-add′ x i (suc j) =
begin
x ^ i +1 * (x ^ j +1 * x)
≈⟨ sym (*-assoc _ _ _) ⟩
x ^ i +1 * x ^ j +1 * x
≈⟨ ≪* pow-add′ x i j ⟩
x ^ (j ℕ.+ suc i) +1 * x
∎
pow-add : ∀ x y i j → y ^ j +1 * x *⟨ y ⟩^ i ≈ x *⟨ y ⟩^ (i ℕ.+ suc j)
pow-add x y ℕ.zero j = refl
pow-add x y (suc i) j = go x y i j
where
go : ∀ x y i j → y ^ j +1 * ((y ^ i +1) * x) ≈ y ^ (i ℕ.+ suc j) +1 * x
go x y ℕ.zero j = sym (*-assoc _ _ _)
go x y (suc i) j =
begin
y ^ j +1 * (y ^ i +1 * y * x)
≈⟨ *≫ *-assoc _ y x ⟩
y ^ j +1 * (y ^ i +1 * (y * x))
≈⟨ go (y * x) y i j ⟩
y ^ (i ℕ.+ suc j) +1 * (y * x)
≈⟨ sym (*-assoc _ y x) ⟩
y ^ suc (i ℕ.+ suc j) +1 * x
∎
-- Here we show a homomorphism on exponentiation, i.e. that using the
-- exponentiation function on polynomials and then evaluating is the same
-- as evaluating and then exponentiating.
pow-hom : ∀ {n} i
→ (xs : Coeff n +)
→ ∀ ρ ρs
→ ⅀⟦ xs ⟧ (ρ , ρs) *⟨ ρ ⟩^ i ≈ ⅀⟦ xs ⍓+ i ⟧ (ρ , ρs)
pow-hom ℕ.zero (x Δ j & xs) ρ ρs rewrite ℕₚ.+-identityʳ j = refl
pow-hom (suc i) (x ≠0 Δ j & xs) ρ ρs =
begin
ρ ^ i +1 * (((x , xs) ⟦∷⟧ (ρ , ρs)) *⟨ ρ ⟩^ j)
≈⟨ pow-add _ ρ j i ⟩
(((x , xs) ⟦∷⟧ (ρ , ρs)) *⟨ ρ ⟩^ (j ℕ.+ suc i))
∎
-- Proving a congruence (we don't get this for free because we're using
-- setoids).
pow-mul-cong : ∀ {x y} → x ≈ y → ∀ ρ i → x *⟨ ρ ⟩^ i ≈ y *⟨ ρ ⟩^ i
pow-mul-cong x≈y ρ ℕ.zero = x≈y
pow-mul-cong x≈y ρ (suc i₁) = *≫ x≈y
-- The identity:
-- (xy)ⁿ = xⁿyⁿ
pow-distrib-+1 : ∀ x y i → (x * y) ^ i +1 ≈ x ^ i +1 * y ^ i +1
pow-distrib-+1 x y ℕ.zero = refl
pow-distrib-+1 x y (suc i) =
begin
(x * y) ^ i +1 * (x * y)
≈⟨ ≪* pow-distrib-+1 x y i ⟩
(x ^ i +1 * y ^ i +1) * (x * y)
≈⟨ *-assoc _ _ _ ⟨ trans ⟩ (*≫ (sym (*-assoc _ _ _) ⟨ trans ⟩ (≪* *-comm _ _))) ⟩
x ^ i +1 * (x * y ^ i +1 * y)
≈⟨ (*≫ *-assoc _ _ _) ⟨ trans ⟩ sym (*-assoc _ _ _) ⟩
(x ^ i +1 * x) * (y ^ i +1 * y)
∎
pow-distrib : ∀ x y i → (x * y) ^ i ≈ x ^ i * y ^ i
pow-distrib x y ℕ.zero = sym (*-identityˡ _)
pow-distrib x y (suc i) = pow-distrib-+1 x y i
-- This proves the identity:
-- (xⁿ)ᵐ = xⁿᵐ
-- The reason it looks different is because we're using the special exponentiation
-- operator.
pow-mult-+1 : ∀ x i j → (x ^ i +1) ^ j +1 ≈ x ^ (i ℕ.+ j ℕ.* suc i) +1
pow-mult-+1 x i ℕ.zero rewrite ℕₚ.+-identityʳ i = refl
pow-mult-+1 x i (suc j) =
begin
(x ^ i +1) ^ j +1 * (x ^ i +1)
≈⟨ ≪* pow-mult-+1 x i j ⟩
(x ^ (i ℕ.+ j ℕ.* suc i) +1) * (x ^ i +1)
≈⟨ pow-add′ x _ i ⟩
x ^ (i ℕ.+ suc (i ℕ.+ j ℕ.* suc i)) +1
∎
pow-cong-+1 : ∀ {x y} i → x ≈ y → x ^ i +1 ≈ y ^ i +1
pow-cong-+1 ℕ.zero x≈y = x≈y
pow-cong-+1 (suc i) x≈y = pow-cong-+1 i x≈y ⟨ *-cong ⟩ x≈y
pow-cong : ∀ {x y} i → x ≈ y → x ^ i ≈ y ^ i
pow-cong ℕ.zero x≈y = refl
pow-cong (suc i) x≈y = pow-cong-+1 i x≈y
-- Demonstrating that the proof of zeroness is correct.
zero-hom : ∀ {n} (p : Poly n) → Zero p → (ρs : Vec Carrier n) → 0# ≈ ⟦ p ⟧ ρs
zero-hom (Κ x ⊐ i≤n) p≡0 ρs = Zero-C⟶Zero-R x p≡0
-- x¹⁺ⁿ = xxⁿ
pow-suc : ∀ x i → x ^ suc i ≈ x * x ^ i
pow-suc x ℕ.zero = sym (*-identityʳ _)
pow-suc x (suc i) = *-comm _ _
-- x¹⁺ⁿ = xⁿx
pow-sucʳ : ∀ x i → x ^ suc i ≈ x ^ i * x
pow-sucʳ x ℕ.zero = sym (*-identityˡ _)
pow-sucʳ x (suc i) = refl
-- In the proper evaluation function, we avoid ever inserting an unnecessary 0#
-- like we do here. However, it is easier to prove with the form that does insert
-- 0#. So we write one here, and then prove that it's equivalent to the one that
-- adds a 0#.
⅀?⟦_⟧ : ∀ {n} (xs : Coeff n *) → Carrier × Vec Carrier n → Carrier
⅀?⟦ [] ⟧ _ = 0#
⅀?⟦ ∹ x ⟧ = ⅀⟦ x ⟧
_⟦∷⟧?_ : ∀ {n} (x : Poly n × Coeff n *) → Carrier × Vec Carrier n → Carrier
(x , xs) ⟦∷⟧? (ρ , ρs) = ρ * ⅀?⟦ xs ⟧ (ρ , ρs) + ⟦ x ⟧ ρs
⅀?-hom : ∀ {n} (xs : Coeff n +) → ∀ ρ → ⅀?⟦ ∹ xs ⟧ ρ ≈ ⅀⟦ xs ⟧ ρ
⅀?-hom _ _ = refl
⟦∷⟧?-hom : ∀ {n} (x : Poly n) → ∀ xs ρ ρs → (x , xs) ⟦∷⟧? (ρ , ρs) ≈ (x , xs) ⟦∷⟧ (ρ , ρs)
⟦∷⟧?-hom x (∹ xs ) ρ ρs = refl
⟦∷⟧?-hom x [] ρ ρs = (≪+ zeroʳ _) ⟨ trans ⟩ +-identityˡ _
pow′-hom : ∀ {n} i (xs : Coeff n *) → ∀ ρ ρs → ((⅀?⟦ xs ⟧ (ρ , ρs)) *⟨ ρ ⟩^ i) ≈ (⅀?⟦ xs ⍓* i ⟧ (ρ , ρs))
pow′-hom i (∹ xs ) ρ ρs = pow-hom i xs ρ ρs
pow′-hom zero [] ρ ρs = refl
pow′-hom (suc i) [] ρ ρs = zeroʳ _
-- Here, we show that the normalising cons is correct.
-- This lets us prove with respect to the non-normalising form, especially
-- when we're using the folds.
∷↓-hom-0 : ∀ {n} (x : Poly n) → ∀ xs ρ ρs → ⅀?⟦ x Δ 0 ∷↓ xs ⟧ (ρ , ρs) ≈ (x , xs) ⟦∷⟧ (ρ , ρs)
∷↓-hom-0 x xs ρ ρs with zero? x
∷↓-hom-0 x xs ρ ρs | no ¬p = refl
∷↓-hom-0 x [] ρ ρs | yes p = zero-hom x p ρs
∷↓-hom-0 x (∹ xs ) ρ ρs | yes p =
begin
⅀⟦ xs ⍓+ 1 ⟧ (ρ , ρs)
≈⟨ sym (pow-hom 1 xs ρ ρs) ⟩
ρ * ⅀⟦ xs ⟧ (ρ , ρs)
≈⟨ sym (+-identityʳ _) ⟨ trans ⟩ (+≫ zero-hom x p ρs) ⟩
ρ * ⅀⟦ xs ⟧ (ρ , ρs) + ⟦ x ⟧ ρs
∎
∷↓-hom-s : ∀ {n} (x : Poly n) → ∀ i xs ρ ρs → ⅀?⟦ x Δ suc i ∷↓ xs ⟧ (ρ , ρs) ≈ (ρ ^ i +1) * (x , xs) ⟦∷⟧ (ρ , ρs)
∷↓-hom-s x i xs ρ ρs with zero? x
∷↓-hom-s x i xs ρ ρs | no ¬p = refl
∷↓-hom-s x i [] ρ ρs | yes p = sym ((*≫ sym (zero-hom x p ρs)) ⟨ trans ⟩ zeroʳ _)
∷↓-hom-s x i (∹ xs ) ρ ρs | yes p =
begin
⅀⟦ xs ⍓+ (suc (suc i)) ⟧ (ρ , ρs)
≈⟨ sym (pow-hom (suc (suc i)) xs ρ ρs) ⟩
(ρ ^ suc i +1) * ⅀⟦ xs ⟧ (ρ , ρs)
≈⟨ *-assoc _ _ _ ⟩
(ρ ^ i +1) * (ρ * ⅀⟦ xs ⟧ (ρ , ρs))
≈⟨ *≫ (sym (+-identityʳ _) ⟨ trans ⟩ (+≫ zero-hom x p ρs)) ⟩
ρ ^ i +1 * (ρ * ⅀⟦ xs ⟧ (ρ , ρs) + ⟦ x ⟧ ρs)
∎
∷↓-hom : ∀ {n}
→ (x : Poly n)
→ ∀ i xs ρ ρs
→ ⅀?⟦ x Δ i ∷↓ xs ⟧ (ρ , ρs) ≈ ρ ^ i * ((x , xs) ⟦∷⟧ (ρ , ρs))
∷↓-hom x ℕ.zero xs ρ ρs = ∷↓-hom-0 x xs ρ ρs ⟨ trans ⟩ sym (*-identityˡ _)
∷↓-hom x (suc i) xs ρ ρs = ∷↓-hom-s x i xs ρ ρs
⟦∷⟧-hom : ∀ {n}
→ (x : Poly n)
→ (xs : Coeff n *)
→ ∀ ρ ρs → (x , xs) ⟦∷⟧ (ρ , ρs) ≈ ρ * ⅀?⟦ xs ⟧ (ρ , ρs) + ⟦ x ⟧ ρs
⟦∷⟧-hom x [] ρ ρs = sym ((≪+ zeroʳ _) ⟨ trans ⟩ +-identityˡ _)
⟦∷⟧-hom x (∹ xs) ρ ρs = refl
-- This proves that injecting a polynomial into more variables is correct.
-- Basically, we show that if a polynomial doesn't care about the first few
-- variables, we can drop them from the input vector.
⅀-⊐↑-hom : ∀ {i n m}
→ (xs : Coeff i +)
→ (si≤n : suc i ≤′ n)
→ (sn≤m : suc n ≤′ m)
→ ∀ ρ
→ ⅀⟦ xs ⟧ (drop-1 (≤′-step si≤n ⟨ ≤′-trans ⟩ sn≤m) ρ)
≈ ⅀⟦ xs ⟧ (drop-1 si≤n (proj₂ (drop-1 sn≤m ρ)))
⅀-⊐↑-hom xs si≤n ≤′-refl (_ ∷ _) = refl
⅀-⊐↑-hom xs si≤n (≤′-step sn≤m) (_ ∷ ρ) = ⅀-⊐↑-hom xs si≤n sn≤m ρ
⊐↑-hom : ∀ {n m}
→ (x : Poly n)
→ (sn≤m : suc n ≤′ m)
→ ∀ ρ
→ ⟦ x ⊐↑ sn≤m ⟧ ρ ≈ ⟦ x ⟧ (proj₂ (drop-1 sn≤m ρ))
⊐↑-hom (Κ x ⊐ i≤sn) _ _ = refl
⊐↑-hom (⅀ xs ⊐ i≤sn) = ⅀-⊐↑-hom xs i≤sn
trans-join-coeffs-hom : ∀ {i j-1 n}
→ (i≤j-1 : suc i ≤′ j-1)
→ (j≤n : suc j-1 ≤′ n)
→ (xs : Coeff i +)
→ ∀ ρ
→ ⅀⟦ xs ⟧ (drop-1 i≤j-1 (proj₂ (drop-1 j≤n ρ))) ≈ ⅀⟦ xs ⟧ (drop-1 (≤′-step i≤j-1 ⟨ ≤′-trans ⟩ j≤n) ρ)
trans-join-coeffs-hom i<j-1 ≤′-refl xs (_ ∷ _) = refl
trans-join-coeffs-hom i<j-1 (≤′-step j<n) xs (_ ∷ ρ) = trans-join-coeffs-hom i<j-1 j<n xs ρ
trans-join-hom : ∀ {i j-1 n}
→ (i≤j-1 : i ≤′ j-1)
→ (j≤n : suc j-1 ≤′ n)
→ (x : FlatPoly i)
→ ∀ ρ
→ ⟦ x ⊐ i≤j-1 ⟧ (proj₂ (drop-1 j≤n ρ)) ≈ ⟦ x ⊐ (≤′-step i≤j-1 ⟨ ≤′-trans ⟩ j≤n) ⟧ ρ
trans-join-hom i≤j-1 j≤n (Κ x) _ = refl
trans-join-hom i≤j-1 j≤n (⅀ x) = trans-join-coeffs-hom i≤j-1 j≤n x
⊐↓-hom : ∀ {n m}
→ (xs : Coeff n *)
→ (sn≤m : suc n ≤′ m)
→ ∀ ρ
→ ⟦ xs ⊐↓ sn≤m ⟧ ρ ≈ ⅀?⟦ xs ⟧ (drop-1 sn≤m ρ)
⊐↓-hom [] sn≤m _ = 0-homo
⊐↓-hom (∹ x₁ Δ zero & ∹ xs) sn≤m _ = refl
⊐↓-hom (∹ x Δ suc j & xs ) sn≤m _ = refl
⊐↓-hom (∹ _≠0 x {x≠0} Δ zero & []) sn≤m ρs =
let (ρ , ρs′) = drop-1 sn≤m ρs
in
begin
⟦ x ⊐↑ sn≤m ⟧ ρs
≈⟨ ⊐↑-hom x sn≤m ρs ⟩
⟦ x ⟧ ρs′
∎
drop-1⇒lookup : ∀ {n} (i : Fin n) (ρs : Vec Carrier n) →
proj₁ (drop-1 (space≤′n i) ρs) ≡ Vec.lookup ρs i
drop-1⇒lookup zero (ρ ∷ ρs) = ≡.refl
drop-1⇒lookup (suc i) (ρ ∷ ρs) = drop-1⇒lookup i ρs
-- The fold: this function saves us hundreds of lines of proofs in the rest of the
-- homomorphism proof.
-- Many of the functions on polynomials are defined using para: this function allows
-- us to prove properties of those functions (in a foldr-fusion style) *ignoring*
-- optimisations we have made to the polynomial structure.
poly-foldR : ∀ {n} ρ ρs
→ ([f] : Fold n)
→ (f : Carrier → Carrier)
→ (∀ {x y} → x ≈ y → f x ≈ f y)
→ (∀ x y → x * f y ≈ f (x * y))
→ (∀ y {ys} zs → ⅀?⟦ ys ⟧ (ρ , ρs) ≈ f (⅀?⟦ zs ⟧ (ρ , ρs)) → [f] (y , ys) ⟦∷⟧? (ρ , ρs) ≈ f ((y , zs) ⟦∷⟧? (ρ , ρs)) )
→ (f 0# ≈ 0#)
→ ∀ xs
→ ⅀?⟦ para [f] xs ⟧ (ρ , ρs) ≈ f (⅀⟦ xs ⟧ (ρ , ρs))
poly-foldR ρ ρs f e cng dist step base (x ≠0 Δ suc i & []) =
let y,ys = f (x , [])
y = proj₁ y,ys
ys = proj₂ y,ys
in
begin
⅀?⟦ y Δ suc i ∷↓ ys ⟧ (ρ , ρs)
≈⟨ ∷↓-hom-s y i ys ρ ρs ⟩
(ρ ^ i +1) * ((y , ys) ⟦∷⟧ (ρ , ρs))
≈˘⟨ *≫ ⟦∷⟧?-hom y ys ρ ρs ⟩
(ρ ^ i +1) * ((y , ys) ⟦∷⟧? (ρ , ρs))
≈⟨ *≫ step x [] (sym base) ⟩
(ρ ^ i +1) * e ((x , []) ⟦∷⟧? (ρ , ρs))
≈⟨ *≫ cng (⟦∷⟧?-hom x [] ρ ρs) ⟩
(ρ ^ i +1) * e ((x , []) ⟦∷⟧ (ρ , ρs))
≈⟨ dist _ _ ⟩
e (ρ ^ i +1 * ((x , []) ⟦∷⟧ (ρ , ρs)))
∎
poly-foldR ρ ρs f e cng dist step base (x ≠0 Δ suc i & ∹ xs) =
let ys = para f xs
y,zs = f (x , ys)
y = proj₁ y,zs
zs = proj₂ y,zs
in
begin
⅀?⟦ y Δ suc i ∷↓ zs ⟧ (ρ , ρs)
≈⟨ ∷↓-hom-s y i zs ρ ρs ⟩
(ρ ^ i +1) * ((y , zs) ⟦∷⟧ (ρ , ρs))
≈˘⟨ *≫ ⟦∷⟧?-hom y zs ρ ρs ⟩
(ρ ^ i +1) * ((y , zs) ⟦∷⟧? (ρ , ρs))
≈⟨ *≫ step x (∹ xs) (poly-foldR ρ ρs f e cng dist step base xs) ⟩
(ρ ^ i +1) * e ((x , (∹ xs )) ⟦∷⟧? (ρ , ρs))
≈⟨ *≫ cng (⟦∷⟧?-hom x (∹ xs ) ρ ρs) ⟩
(ρ ^ i +1) * e ((x , (∹ xs )) ⟦∷⟧ (ρ , ρs))
≈⟨ dist _ _ ⟩
e (ρ ^ i +1 * ((x , (∹ xs )) ⟦∷⟧ (ρ , ρs)))
∎
poly-foldR ρ ρs f e cng dist step base (x ≠0 Δ ℕ.zero & []) =
let y,zs = f (x , [])
y = proj₁ y,zs
zs = proj₂ y,zs
in
begin
⅀?⟦ y Δ ℕ.zero ∷↓ zs ⟧ (ρ , ρs)
≈⟨ ∷↓-hom-0 y zs ρ ρs ⟩
((y , zs) ⟦∷⟧ (ρ , ρs))
≈˘⟨ ⟦∷⟧?-hom y zs ρ ρs ⟩
((y , zs) ⟦∷⟧? (ρ , ρs))
≈⟨ step x [] (sym base) ⟩
e ((x , []) ⟦∷⟧? (ρ , ρs))
≈⟨ cng (⟦∷⟧?-hom x [] ρ ρs) ⟩
e ((x , []) ⟦∷⟧ (ρ , ρs))
∎
poly-foldR ρ ρs f e cng dist step base (x ≠0 Δ ℕ.zero & (∹ xs )) =
let ys = para f xs
y,zs = f (x , ys)
y = proj₁ y,zs
zs = proj₂ y,zs
in
begin
⅀?⟦ y Δ ℕ.zero ∷↓ zs ⟧ (ρ , ρs)
≈⟨ ∷↓-hom-0 y zs ρ ρs ⟩
((y , zs) ⟦∷⟧ (ρ , ρs))
≈˘⟨ ⟦∷⟧?-hom y zs ρ ρs ⟩
((y , zs) ⟦∷⟧? (ρ , ρs))
≈⟨ step x (∹ xs ) (poly-foldR ρ ρs f e cng dist step base xs) ⟩
e ((x , (∹ xs )) ⟦∷⟧ (ρ , ρs))
≈⟨ cng (⟦∷⟧?-hom x (∹ xs ) ρ ρs) ⟩
e ((x , (∹ xs )) ⟦∷⟧ (ρ , ρs))
∎
poly-mapR : ∀ {n} ρ ρs
→ ([f] : Poly n → Poly n)
→ (f : Carrier → Carrier)
→ (∀ {x y} → x ≈ y → f x ≈ f y)
→ (∀ x y → x * f y ≈ f (x * y))
→ (∀ x y → f (x + y) ≈ f x + f y)
→ (∀ y → ⟦ [f] y ⟧ ρs ≈ f (⟦ y ⟧ ρs) )
→ (f 0# ≈ 0#)
→ ∀ xs
→ ⅀?⟦ poly-map [f] xs ⟧ (ρ , ρs) ≈ f (⅀⟦ xs ⟧ (ρ , ρs))
poly-mapR ρ ρs [f] f cng *-dist +-dist step′ base xs = poly-foldR ρ ρs (map₁ [f]) f cng *-dist step base xs
where
step : ∀ y {ys} zs → ⅀?⟦ ys ⟧ (ρ , ρs) ≈ f (⅀?⟦ zs ⟧ (ρ , ρs)) →(map₁ [f] (y , ys) ⟦∷⟧? (ρ , ρs)) ≈ f ((y , zs) ⟦∷⟧? (ρ , ρs))
step y {ys} zs ys≋zs =
begin
map₁ [f] (y , ys) ⟦∷⟧? (ρ , ρs)
≡⟨⟩
ρ * ⅀?⟦ ys ⟧ (ρ , ρs) + ⟦ [f] y ⟧ ρs
≈⟨ ((*≫ ys≋zs) ⟨ trans ⟩ *-dist ρ _) ⟨ +-cong ⟩ step′ y ⟩
f (ρ * ⅀?⟦ zs ⟧ (ρ , ρs)) + f (⟦ y ⟧ ρs)
≈⟨ sym (+-dist _ _) ⟩
f ((y , zs) ⟦∷⟧? (ρ , ρs))
∎
| {
"alphanum_fraction": 0.4437151528,
"avg_line_length": 35.8708860759,
"ext": "agda",
"hexsha": "7ecf834237cb4fda0e61f41ab968f2ebd754bf8b",
"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": "agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Homomorphism/Lemmas.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": "agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Homomorphism/Lemmas.agda",
"max_line_length": 128,
"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": "agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Homomorphism/Lemmas.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": 6981,
"size": 14169
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Duality where
open import Level
open import Data.Product using (Σ; _,_)
open import Categories.Category
open import Categories.Category.Construction.Cones as Con
open import Categories.Category.Construction.Cocones as Coc
open import Categories.Functor
open import Categories.Functor.Limits
open import Categories.Object.Initial
open import Categories.Object.Terminal
open import Categories.Diagram.Limit as Lim
open import Categories.Diagram.Colimit as Col
open import Categories.Diagram.Duality
open import Categories.Morphism.Duality as MorD
private
variable
o ℓ e : Level
C D E J : Category o ℓ e
module _ (G : Functor C D) {J : Category o ℓ e} where
private
module C = Category C
module D = Category D
module G = Functor G
module J = Category J
coPreservesLimit⇒PreservesCoLimit : ∀ {F : Functor J C} (L : Limit (Functor.op F)) →
PreservesLimit G.op L →
PreservesColimit G (coLimit⇒Colimit C L)
coPreservesLimit⇒PreservesCoLimit L is⊤ = record
{ ! = λ {K} → coCone⇒⇒Cocone⇒ _ (! {Cocone⇒coCone _ K})
; !-unique = λ f → !-unique (Cocone⇒⇒coCone⇒ _ f)
}
where open IsTerminal is⊤
PreservesColimit⇒coPreservesLimit : ∀ {F : Functor J C} (L : Colimit F) →
PreservesColimit G L →
PreservesLimit G.op (Colimit⇒coLimit C L)
PreservesColimit⇒coPreservesLimit L is⊥ = record
{ ! = λ {K} → Cocone⇒⇒coCone⇒ _ (! {coCone⇒Cocone _ K})
; !-unique = λ f → !-unique (coCone⇒⇒Cocone⇒ _ f)
}
where open IsInitial is⊥
module _ {o ℓ e} (G : Functor C D) where
private
module G = Functor G
coContinuous⇒Cocontinuous : Continuous o ℓ e G.op → Cocontinuous o ℓ e G
coContinuous⇒Cocontinuous Con L =
coPreservesLimit⇒PreservesCoLimit G (Colimit⇒coLimit C L) (Con (Colimit⇒coLimit C L))
Cocontinuous⇒coContinuous : Cocontinuous o ℓ e G → Continuous o ℓ e G.op
Cocontinuous⇒coContinuous Coc L =
PreservesColimit⇒coPreservesLimit G (coLimit⇒Colimit C L) (Coc (coLimit⇒Colimit C L))
| {
"alphanum_fraction": 0.6580263756,
"avg_line_length": 36.0491803279,
"ext": "agda",
"hexsha": "eb225bf824730ff52ce5d0377f8d4d3c919fcf0c",
"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/Duality.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/Duality.agda",
"max_line_length": 89,
"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/Duality.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": 694,
"size": 2199
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Sum combinators for setoid equality preserving functions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Sum.Function.Setoid where
open import Data.Sum
open import Data.Sum.Relation.Binary.Pointwise
open import Relation.Binary
open import Function.Equality as F using (_⟶_; _⟨$⟩_)
open import Function.Equivalence as Eq
using (Equivalence; _⇔_; module Equivalence)
open import Function.Injection as Inj
using (Injection; _↣_; module Injection)
open import Function.Inverse as Inv
using (Inverse; _↔_; module Inverse)
open import Function.LeftInverse as LeftInv
using (LeftInverse; _↞_; _LeftInverseOf_; module LeftInverse)
open import Function.Related
open import Function.Surjection as Surj
using (Surjection; _↠_; module Surjection)
------------------------------------------------------------------------
-- Combinators for equality preserving functions
module _ {a₁ a₂ b₁ b₂ c₁ c₂ d₁ d₂}
{A : Setoid a₁ a₂} {B : Setoid b₁ b₂}
{C : Setoid c₁ c₂} {D : Setoid d₁ d₂}
where
_⊎-⟶_ : (A ⟶ B) → (C ⟶ D) → (A ⊎ₛ C) ⟶ (B ⊎ₛ D)
_⊎-⟶_ f g = record
{ _⟨$⟩_ = fg
; cong = fg-cong
}
where
open Setoid (A ⊎ₛ C) using () renaming (_≈_ to _≈AC_)
open Setoid (B ⊎ₛ D) using () renaming (_≈_ to _≈BD_)
fg = map (_⟨$⟩_ f) (_⟨$⟩_ g)
fg-cong : _≈AC_ =[ fg ]⇒ _≈BD_
fg-cong (inj₁ x∼₁y) = inj₁ (F.cong f x∼₁y)
fg-cong (inj₂ x∼₂y) = inj₂ (F.cong g x∼₂y)
module _ {a₁ a₂ b₁ b₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂} where
inj₁ₛ : A ⟶ (A ⊎ₛ B)
inj₁ₛ = record { _⟨$⟩_ = inj₁ ; cong = inj₁ }
inj₂ₛ : B ⟶ (A ⊎ₛ B)
inj₂ₛ = record { _⟨$⟩_ = inj₂ ; cong = inj₂ }
[_,_]ₛ : ∀ {c₁ c₂} {C : Setoid c₁ c₂} →
(A ⟶ C) → (B ⟶ C) → (A ⊎ₛ B) ⟶ C
[ f , g ]ₛ = record
{ _⟨$⟩_ = [ f ⟨$⟩_ , g ⟨$⟩_ ]
; cong = λ where
(inj₁ x∼₁y) → F.cong f x∼₁y
(inj₂ x∼₂y) → F.cong g x∼₂y
}
module _ {a₁ a₂ b₁ b₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂} where
swapₛ : (A ⊎ₛ B) ⟶ (B ⊎ₛ A)
swapₛ = [ inj₂ₛ , inj₁ₛ ]ₛ
------------------------------------------------------------------------
-- Combinators for more complex function types
module _ {a₁ a₂ b₁ b₂ c₁ c₂ d₁ d₂}
{A : Setoid a₁ a₂} {B : Setoid b₁ b₂}
{C : Setoid c₁ c₂} {D : Setoid d₁ d₂}
where
_⊎-equivalence_ : Equivalence A B → Equivalence C D →
Equivalence (A ⊎ₛ C) (B ⊎ₛ D)
A⇔B ⊎-equivalence C⇔D = record
{ to = to A⇔B ⊎-⟶ to C⇔D
; from = from A⇔B ⊎-⟶ from C⇔D
} where open Equivalence
_⊎-injection_ : Injection A B → Injection C D →
Injection (A ⊎ₛ C) (B ⊎ₛ D)
_⊎-injection_ A↣B C↣D = record
{ to = to A↣B ⊎-⟶ to C↣D
; injective = inj _ _
}
where
open Injection
open Setoid (A ⊎ₛ C) using () renaming (_≈_ to _≈AC_)
open Setoid (B ⊎ₛ D) using () renaming (_≈_ to _≈BD_)
inj : ∀ x y →
(to A↣B ⊎-⟶ to C↣D) ⟨$⟩ x ≈BD (to A↣B ⊎-⟶ to C↣D) ⟨$⟩ y →
x ≈AC y
inj (inj₁ x) (inj₁ y) (inj₁ x∼₁y) = inj₁ (injective A↣B x∼₁y)
inj (inj₂ x) (inj₂ y) (inj₂ x∼₂y) = inj₂ (injective C↣D x∼₂y)
-- Can be removed in Agda 2.6.0?
inj (inj₁ x) (inj₂ y) ()
inj (inj₂ x) (inj₁ y) ()
_⊎-left-inverse_ : LeftInverse A B → LeftInverse C D →
LeftInverse (A ⊎ₛ C) (B ⊎ₛ D)
A↞B ⊎-left-inverse C↞D = record
{ to = Equivalence.to eq
; from = Equivalence.from eq
; left-inverse-of = [ (λ x → inj₁ (left-inverse-of A↞B x))
, (λ x → inj₂ (left-inverse-of C↞D x)) ]
}
where
open LeftInverse
eq = LeftInverse.equivalence A↞B ⊎-equivalence
LeftInverse.equivalence C↞D
module _ {a₁ a₂ b₁ b₂ c₁ c₂ d₁ d₂}
{A : Setoid a₁ a₂} {B : Setoid b₁ b₂}
{C : Setoid c₁ c₂} {D : Setoid d₁ d₂}
where
_⊎-surjection_ : Surjection A B → Surjection C D →
Surjection (A ⊎ₛ C) (B ⊎ₛ D)
A↠B ⊎-surjection C↠D = record
{ to = LeftInverse.from inv
; surjective = record
{ from = LeftInverse.to inv
; right-inverse-of = LeftInverse.left-inverse-of inv
}
}
where
open Surjection
inv = right-inverse A↠B ⊎-left-inverse right-inverse C↠D
_⊎-inverse_ : Inverse A B → Inverse C D →
Inverse (A ⊎ₛ C) (B ⊎ₛ D)
A↔B ⊎-inverse C↔D = record
{ to = Surjection.to surj
; from = Surjection.from surj
; inverse-of = record
{ left-inverse-of = LeftInverse.left-inverse-of inv
; right-inverse-of = Surjection.right-inverse-of surj
}
}
where
open Inverse
surj = Inverse.surjection A↔B ⊎-surjection
Inverse.surjection C↔D
inv = Inverse.left-inverse A↔B ⊎-left-inverse
Inverse.left-inverse C↔D
| {
"alphanum_fraction": 0.5255945183,
"avg_line_length": 32.2207792208,
"ext": "agda",
"hexsha": "acf8744fc5f6a659bbc4061787c67322e71884a8",
"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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Function/Setoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"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": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Function/Setoid.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Function/Setoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1898,
"size": 4962
} |
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
open import Data.Unit
open import Data.Int as ℤ using (ℤ)
open import Data.List
open import Data.List.Relation.Unary.All as List
module MyTestModule where
emptyList : List ℤ
emptyList = []
empty : List.All (λ (x : ℤ) → ⊤) emptyList
empty = checkProperty record
{ databasePath = DATABASE_PATH
; propertyUUID = ????
} | {
"alphanum_fraction": 0.6994219653,
"avg_line_length": 23.5909090909,
"ext": "agda",
"hexsha": "65b666694c7442cc2c0513ac83ac223879f0eca8",
"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": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Yiergot/vehicle",
"max_forks_repo_path": "examples/simple/quantifierIn/quantifierIn-output.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"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": "Yiergot/vehicle",
"max_issues_repo_path": "examples/simple/quantifierIn/quantifierIn-output.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "Yiergot/vehicle",
"max_stars_repo_path": "examples/simple/quantifierIn/quantifierIn-output.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 154,
"size": 519
} |
------------------------------------------------------------------------
-- An investigation of various ways to define the semantics of an
-- untyped λ-calculus and a virtual machine, and a discussion of
-- type soundness and compiler correctness
--
-- Nils Anders Danielsson
------------------------------------------------------------------------
module Lambda where
-- Syntax and type system for an untyped λ-calculus.
import Lambda.Syntax
------------------------------------------------------------------------
-- Semantics based on substitutions
-- Substitutions.
import Lambda.Substitution
-- A big-step semantics for the language. Conditional coinduction is
-- used to avoid duplication of rules.
--
-- Cousot and Cousot give a similar definition in "Bi-inductive
-- structural semantics", and their definition inspired this one.
-- Their definition has almost the same rules, but these rules are
-- interpreted in the framework of bi-induction rather than the
-- framework of mixed induction and (conditional) coinduction.
import Lambda.Substitution.OneSemantics
-- Two separate semantics for the language, one for converging terms
-- and the other for diverging terms, as given by Leroy and Grall in
-- "Coinductive big-step operational semantics".
--
-- Leroy and Grall attempted to unify their two semantics into a
-- single one, using only coinduction, but failed to find a definition
-- which was equivalent to the two that they started with. However,
-- they aimed for a definition which did not have more rules than the
-- definition for converging terms; the definition in OneSemantics
-- does not satisfy this criterion.
import Lambda.Substitution.TwoSemantics
-- The two definitions are equivalent.
import Lambda.Substitution.Equivalence
-- A functional semantics, along with a type soundness proof.
import Lambda.Substitution.Functional
------------------------------------------------------------------------
-- Virtual machine
-- A virtual machine with two semantics (one relational and one
-- functional), a compiler from the λ-calculus defined above into the
-- language of the virtual machine, and a proof showing that the two
-- semantics are equivalent.
import Lambda.VirtualMachine
------------------------------------------------------------------------
-- Semantics based on closures
-- A semantics for the untyped λ-calculus, based on closures and
-- environments, as given by Leroy and Grall in "Coinductive big-step
-- operational semantics" (more or less).
--
-- The module also contains a proof which shows that the compiler in
-- Lambda.VirtualMachine preserves the semantics (assuming that the
-- virtual machine is deterministic). Leroy and Grall prove almost the
-- same thing. In their proof they use a relation indexed by a natural
-- number to work around limitations in Coq's productivity checker.
-- Agda has similar limitations, but I work around them using mixed
-- induction/coinduction, which in my opinion is more elegant. I am
-- not sure if my workaround would work in Coq, though.
import Lambda.Closure.Relational
-- A semantics for the untyped λ-calculus which uses the partiality
-- monad, along with another compiler correctness proof. An advantage
-- of formulating the semantics in this way is that it is very easy to
-- state compiler correctness.
import Lambda.Closure.Functional
-- The module above uses some workarounds in order to convince Agda
-- that the code is productive. The following module contains (more or
-- less) the same code without the workarounds, but is checked with
-- the termination checker turned off.
import Lambda.Closure.Functional.No-workarounds
-- The relational and functional semantics are equivalent.
import Lambda.Closure.Equivalence
-- An alternative definition of the functional semantics. This
-- definition uses continuation-passing style instead of bind.
import Lambda.Closure.Functional.Alternative
-- A definition of a type system (with recursive types) for the
-- λ-calculus given above, and a proof of type soundness for the
-- functional semantics.
import Lambda.Closure.Functional.Type-soundness
-- A very brief treatment of different kinds of term equivalences,
-- including contextual equivalence and applicative bisimilarity.
import Lambda.Closure.Equivalences
-- A functional semantics, a compiler and a compiler correctness
-- proof, and a type soundness proof for a non-deterministic untyped
-- λ-calculus with constants.
import Lambda.Closure.Functional.Non-deterministic
-- A variant of the code above without the workarounds used to
-- convince Agda that the code is productive.
import Lambda.Closure.Functional.Non-deterministic.No-workarounds
| {
"alphanum_fraction": 0.7253356062,
"avg_line_length": 37.246031746,
"ext": "agda",
"hexsha": "3ca5b4c094a30c7e4438c3ba550c1c81db6d1b17",
"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": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Lambda.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"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/codata",
"max_issues_repo_path": "Lambda.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Lambda.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 935,
"size": 4693
} |
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Show using (show)
open import Function using (_$!_)
open import IO using (run; putStrLn)
sum : ℕ
sum = f 1000000000 0
where
f : ℕ → ℕ → ℕ
f zero acc = acc
f (suc n) acc = f n $! suc n + acc
main = run (putStrLn (show sum))
| {
"alphanum_fraction": 0.6348684211,
"avg_line_length": 21.7142857143,
"ext": "agda",
"hexsha": "10509db800b365b646bf6d6ecba5cb37e5fea90e",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-01-17T23:23:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-09T19:39:43.000Z",
"max_forks_repo_head_hexsha": "e686673067a3744475f89582cbdcc3719425a9bf",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ThePeeps191/one-two-three...infinity",
"max_forks_repo_path": "Agda.agda",
"max_issues_count": 23,
"max_issues_repo_head_hexsha": "e686673067a3744475f89582cbdcc3719425a9bf",
"max_issues_repo_issues_event_max_datetime": "2022-01-23T21:18:50.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-09-10T13:51:09.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ThePeeps191/one-two-three...infinity",
"max_issues_repo_path": "Agda.agda",
"max_line_length": 46,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "e686673067a3744475f89582cbdcc3719425a9bf",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ThePeeps191/one-two-three...infinity",
"max_stars_repo_path": "Agda.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T09:01:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-01-02T18:14:51.000Z",
"num_tokens": 107,
"size": 304
} |
{-# OPTIONS --without-K --rewriting #-}
module HoTT where
open import lib.Basics public
open import lib.Equivalence2 public
open import lib.NConnected public
open import lib.NType2 public
open import lib.Relation2 public
open import lib.Function2 public
open import lib.cubical.Cubical public
open import lib.types.Types public
open import lib.groups.Groups public
open import lib.groupoids.Groupoids public
open import lib.modalities.Modalities public
{-
To use coinduction in the form of [∞], [♭] and [♯] you can do:
open import HoTT
open Coinduction
You can also use coinductive records and copatterns instead, that’s prettier
(see experimental/GlobularTypes.agda for an example)
-}
module Coinduction where
open import lib.Coinduction public
-- deprecated operators
module _ where
infix 15 _∎
_∎ = _=∎
conn-elim = conn-extend
conn-elim-β = conn-extend-β
conn-elim-general = conn-extend-general
conn-intro = conn-in
if_then_else_ : ∀ {i} {A : Type i}
→ Bool → A → A → A
if true then t else e = t
if false then t else e = e
| {
"alphanum_fraction": 0.7450424929,
"avg_line_length": 24.0681818182,
"ext": "agda",
"hexsha": "81bc171b4ca6f8a96878154ad2917eb80d189707",
"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": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/HoTT.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"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": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/HoTT.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/HoTT.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 304,
"size": 1059
} |
module StreamPredicates where
open import PropsAsTypes
open import Stream
module Modalities (A : Set) where
private
Aω : Set
Aω = Stream A
record Always (P : Pred Aω) (s : Stream A) : Prop where
coinductive
field
valid : P s
step : Always P (tl s)
open Always public
data Eventually (P : Pred Aω) (s : Stream A) : Prop where
now : P s → Eventually P s
later : Eventually P (tl s) → Eventually P s
GE : Pred Aω → Pred Aω
GE P = Always (Eventually P)
EG : Pred Aω → Pred Aω
EG P = Eventually (Always P)
Always⇒GE : ∀{P : Pred Aω} → Always P ⊆ GE P
Always⇒GE s p .valid = now (p .valid)
Always⇒GE s p .step = Always⇒GE (s .tl) (p .step)
EG⇒Eventually : ∀{P : Pred Aω} → EG P ⊆ Eventually P
EG⇒Eventually s (now p) = now (p .valid)
EG⇒Eventually s (later Evs') = later (EG⇒Eventually (s .tl) Evs')
EG⇒GE : ∀{P : Pred Aω} → EG P ⊆ GE P
EG⇒GE s p .valid = EG⇒Eventually s p
EG⇒GE s (now p) .step = Always⇒GE (tl s) (p .step)
EG⇒GE s (later p) .step = EG⇒GE (tl s) p
module ModalitiesExamples where
open import Data.Nat
open import Relation.Binary.PropositionalEquality as PE
exP : Pred (Stream ℕ)
exP s = s .hd ≡ 0
alt : Stream ℕ
alt .hd = 0
alt .tl .hd = 1
alt .tl .tl = alt
open Modalities ℕ
exP-holds-on-alt-GE : GE exP alt
exP-holds-on-alt-GE .valid = now refl
exP-holds-on-alt-GE .step .valid = later (now refl)
exP-holds-on-alt-GE .step .step = exP-holds-on-alt-GE
exP-holds-not-on-alt-EG : ¬ (EG exP alt)
exP-holds-not-on-alt-EG (now p) = zero-not-suc 0 (p .step .valid)
exP-holds-not-on-alt-EG (later (now p)) = zero-not-suc 0 (p .valid)
exP-holds-not-on-alt-EG (later (later EGalt'')) =
exP-holds-not-on-alt-EG EGalt''
| {
"alphanum_fraction": 0.6100840336,
"avg_line_length": 27.0454545455,
"ext": "agda",
"hexsha": "fbb8c8018468ede3ababf89f81c4973e310e376c",
"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": "TypeTheory/Lecture/StreamPredicates.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": "TypeTheory/Lecture/StreamPredicates.agda",
"max_line_length": 75,
"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": "TypeTheory/Lecture/StreamPredicates.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 678,
"size": 1785
} |
{-# OPTIONS --universe-polymorphism #-}
-- in a lot of cases we have a relation that is already reflexive and symmetric
-- and we want to make it symmetric
module Categories.Support.ZigZag where
open import Level
open import Relation.Binary
open import Relation.Binary.Construct.On using () renaming (isEquivalence to on-preserves-equivalence)
open import Categories.Support.Equivalence using () renaming (Setoid to ISetoid; module Setoid to ISetoid)
data Direction : Set where
↘ ↗ : Direction
rotate : Direction → Direction
rotate ↘ = ↗
rotate ↗ = ↘
data ZigZag′ {c ℓ₂} {Carrier : Set c} (_∼_ : Carrier -> Carrier -> Set ℓ₂) : (x y : Carrier) (begin end : Direction) → Set (c ⊔ ℓ₂) where
zig : ∀ {x y z e} (first : x ∼ y) (rest : ZigZag′ _∼_ y z ↗ e) → ZigZag′ _∼_ x z ↘ e
zag : ∀ {x y z e} (first : y ∼ x) (rest : ZigZag′ _∼_ y z ↘ e) → ZigZag′ _∼_ x z ↗ e
slish : ∀ {x y} (last : x ∼ y) → ZigZag′ _∼_ x y ↘ ↘
slash : ∀ {x y} (last : y ∼ x) → ZigZag′ _∼_ x y ↗ ↗
ZigZag : ∀ {c ℓ₁ ℓ₂} (Base : Preorder c ℓ₁ ℓ₂) → (x y : Preorder.Carrier Base) (begin end : Direction) → Set (c ⊔ ℓ₂)
ZigZag Base = ZigZag′ (Preorder._∼_ Base)
zz-sym′ : ∀ {c ℓ₁ ℓ₂} {Base : Preorder c ℓ₁ ℓ₂} {x y z begin middle end} → ZigZag Base y z middle end → ZigZag Base y x middle begin → ZigZag Base z x (rotate end) begin
zz-sym′ {Base = Base} (zig first rest) accum = zz-sym′ {Base = Base} rest (zag first accum)
zz-sym′ {Base = Base} (zag first rest) accum = zz-sym′ {Base = Base} rest (zig first accum)
zz-sym′ (slish last) accum = zag last accum
zz-sym′ (slash last) accum = zig last accum
zz-sym : ∀ {c ℓ₁ ℓ₂} {Base : Preorder c ℓ₁ ℓ₂} {x y begin end} → ZigZag Base x y begin end → ZigZag Base y x (rotate end) (rotate begin)
zz-sym {Base = Base} (zig first rest) = zz-sym′ {Base = Base} rest (slash first)
zz-sym {Base = Base} (zag first rest) = zz-sym′ {Base = Base} rest (slish first)
zz-sym (slish last) = slash last
zz-sym (slash last) = slish last
zz-trans : ∀ {c ℓ₁ ℓ₂} {Base : Preorder c ℓ₁ ℓ₂} {x y z begin end begin′ end′} → ZigZag Base x y begin end → ZigZag Base y z begin′ end′ → ZigZag Base x z begin end′
zz-trans {Base = Base} (zig first rest) yz = zig first (zz-trans {Base = Base} rest yz)
zz-trans {Base = Base} (zag first rest) yz = zag first (zz-trans {Base = Base} rest yz)
zz-trans {Base = Base} (slish last) (zig first rest) = zig (Preorder.trans Base last first) rest
zz-trans (slish last) (zag first rest) = zig last (zag first rest)
zz-trans {Base = Base} (slish last) (slish only) = slish (Preorder.trans Base last only)
zz-trans (slish last) (slash only) = zig last (slash only)
zz-trans (slash last) (zig first rest) = zag last (zig first rest)
zz-trans {Base = Base} (slash last) (zag first rest) = zag (Preorder.trans Base first last) rest
zz-trans (slash last) (slish only) = zag last (slish only)
zz-trans {Base = Base} (slash last) (slash only) = slash (Preorder.trans Base only last)
data Alternating′ {c ℓ₂} {Carrier : Set c} (_∼_ : Carrier -> Carrier -> Set ℓ₂) (x y : Carrier) : Set (c ⊔ ℓ₂) where
disorient : ∀ {begin end} (zz : ZigZag′ _∼_ x y begin end) → Alternating′ _∼_ x y
Alternating : ∀ {c ℓ₁ ℓ₂} (Base : Preorder c ℓ₁ ℓ₂) → (x y : Preorder.Carrier Base) → Set (c ⊔ ℓ₂)
Alternating Base = Alternating′ (Preorder._∼_ Base)
is-equivalence : ∀ {c ℓ₁ ℓ₂} (Base : Preorder c ℓ₁ ℓ₂) → IsEquivalence (Alternating Base)
is-equivalence Base = record
{ refl = disorient (slash (Base.refl))
; sym = my-sym
; trans = my-trans
}
where
module Base = Preorder Base
my-sym : ∀ {i j} → Alternating Base i j → Alternating Base j i
my-sym (disorient zz) = disorient (zz-sym {Base = Base} zz)
my-trans : ∀ {i j k} → Alternating Base i j → Alternating Base j k → Alternating Base i k
my-trans (disorient ij) (disorient jk) = disorient (zz-trans {Base = Base} ij jk)
setoid : ∀ {c ℓ₁ ℓ₂} (Base : Preorder c ℓ₁ ℓ₂) → Setoid c (c ⊔ ℓ₂)
setoid Base = record
{ Carrier = Preorder.Carrier Base
; _≈_ = Alternating Base
; isEquivalence = is-equivalence Base }
isetoid : ∀ {c ℓ₁ ℓ₂} (Base : Preorder c ℓ₁ ℓ₂) → ISetoid c (c ⊔ ℓ₂)
isetoid Base = record
{ Carrier = Preorder.Carrier Base
; _≈_ = Alternating Base
; isEquivalence = is-equivalence Base }
-- the main eliminators for Alternating -- they prove that any equivalence that
-- respects the base preorder also respects its Alternating completion.
locally-minimal : ∀ {c ℓ₁ ℓ₂ ℓ′} (Base : Preorder c ℓ₁ ℓ₂) {_≈_ : Rel (Preorder.Carrier Base) ℓ′} (≈-isEquivalence : IsEquivalence _≈_) → (Preorder._∼_ Base ⇒ _≈_) → (Alternating Base ⇒ _≈_)
locally-minimal Base {_≋_} isEq inj (disorient zz) = impl zz
where
open IsEquivalence isEq renaming (trans to _>trans>_)
impl : ∀ {i j b e} → ZigZag Base i j b e → i ≋ j
impl (zig first rest) = inj first >trans> impl rest
impl (zag first rest) = sym (inj first) >trans> impl rest
impl (slish last) = inj last
impl (slash last) = sym (inj last)
minimal : ∀ {c ℓ₁ ℓ₂ c′ ℓ′} (Base : Preorder c ℓ₁ ℓ₂) (Dest : Setoid c′ ℓ′) (f : Preorder.Carrier Base → Setoid.Carrier Dest) → (Preorder._∼_ Base =[ f ]⇒ Setoid._≈_ Dest) → (Alternating Base =[ f ]⇒ Setoid._≈_ Dest)
minimal Base Dest f inj = locally-minimal Base (on-preserves-equivalence f (Setoid.isEquivalence Dest)) inj
.iminimal : ∀ {c ℓ₁ ℓ₂ c′ ℓ′} (Base : Preorder c ℓ₁ ℓ₂) (Dest : ISetoid c′ ℓ′) (f : Preorder.Carrier Base → ISetoid.Carrier Dest) → (Preorder._∼_ Base =[ f ]⇒ ISetoid._≈_ Dest) → (Alternating Base =[ f ]⇒ ISetoid._≈_ Dest)
iminimal Base Dest f inj = locally-minimal Base (on-preserves-equivalence f (ISetoid.isEquivalence Dest)) inj
| {
"alphanum_fraction": 0.6645126548,
"avg_line_length": 54.0873786408,
"ext": "agda",
"hexsha": "f1a6aee1a3a3d266ce531e42dfe852174bbcffdc",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Support/ZigZag.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Support/ZigZag.agda",
"max_line_length": 222,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Support/ZigZag.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 2025,
"size": 5571
} |
-- Copyright: (c) 2016 Ertugrul Söylemez
-- License: BSD3
-- Maintainer: Ertugrul Söylemez <[email protected]>
module Algebra.Category.Groupoid where
open import Algebra.Category.Category
open import Core
-- A groupoid is a category where all morphisms are isomorphisms.
record Groupoid {c h r} : Set (lsuc (c ⊔ h ⊔ r)) where
field category : Category {c} {h} {r}
open Category category public
field iso : ∀ {A B} (f : Hom A B) → Iso f
open module MyIso {A B} (f : Hom A B) = Iso (iso f) public
using (inv; left-inv; right-inv; inv-unique)
field
inv-cong : ∀ {A B} {f g : Hom A B} → f ≈ g → inv f ≈ inv g
-- The inverse function is an involution.
inv-invol : ∀ {A B} {f : Hom A B} → inv (inv f) ≈ f
inv-invol {f = f} =
begin
inv (inv f) ≈[ sym (right-id _) ]
inv (inv f) ∘ id ≈[ ∘-cong refl (sym (left-inv _)) ]
inv (inv f) ∘ (inv f ∘ f) ≈[ sym (assoc _ _ _) ]
(inv (inv f) ∘ inv f) ∘ f ≈[ ∘-cong (left-inv _) refl ]
id ∘ f ≈[ left-id _ ]
f
qed
| {
"alphanum_fraction": 0.5572232645,
"avg_line_length": 30.4571428571,
"ext": "agda",
"hexsha": "198fba3577418100b6325cc9da5fe3334e89241d",
"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": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "esoeylemez/agda-simple",
"max_forks_repo_path": "Algebra/Category/Groupoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"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": "esoeylemez/agda-simple",
"max_issues_repo_path": "Algebra/Category/Groupoid.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "esoeylemez/agda-simple",
"max_stars_repo_path": "Algebra/Category/Groupoid.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z",
"num_tokens": 384,
"size": 1066
} |
module Data.Num.Pred where
open import Data.Num.Core
open import Data.Num
open import Data.Num.Properties
open import Data.Num.Continuous
-- open import Data.Num.Bijection
open import Data.Nat
open import Data.Nat.Properties.Simple
open import Data.Nat.Properties.Extra
open import Data.Fin using (Fin; suc; zero; #_)
open import Data.Vec
open import Data.Product hiding (map)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Nullary.Decidable using (True; fromWitness; toWitness)
open ≡-Reasoning
open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)
open DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)
-- infixl 6 _∔_
infixl 6 _∔_
data Term : ℕ → Set where
var : ∀ {n} → Fin n → Term n
_∔_ : ∀ {n} → Term n → Term n → Term n
data Predicate : ℕ → Set where
-- equality
_≋P_ : ∀ {n} → (t₁ : Term n) → (t₂ : Term n) → Predicate n
-- implication
_→P_ : ∀ {n} → (p₁ : Predicate n) → (p₂ : Predicate n) → Predicate n
-- ∀, introduces new variable
∀P : ∀ {n} → (p : Predicate (suc n)) → Predicate n
record Signature : Set₁ where
constructor sig
field
carrier : Set
_⊕_ : carrier → carrier → carrier
_≈_ : carrier → carrier → Set
open Signature
ℕ-sig : Signature
ℕ-sig = sig ℕ _+_ _≡_
Numeral-sig : (b d : ℕ) → True (Continuous? b d 0) → Signature
Numeral-sig b d cont = sig (Numeral b d 0) (_⊹_ {cont = cont}) _≋_
-- BijN-sig : ℕ → Signature
-- BijN-sig b = sig (BijN b) (_⊹_ {surj = fromWitness (BijN⇒Surjective b)}) _≡_
--
Env : Set → ℕ → Set
Env = Vec
-- the decoder
⟦_⟧T : ∀ {n}
→ Term n
→ (sig : Signature)
→ Vec (carrier sig) n
→ carrier sig
⟦ var i ⟧T _ env = lookup i env
⟦ term₁ ∔ term₂ ⟧T (sig A _⊕_ _≈_) env = ⟦ term₁ ⟧T (sig A _⊕_ _≈_) env ⊕ ⟦ term₂ ⟧T (sig A _⊕_ _≈_) env
⟦_⟧P : ∀ {n}
→ Predicate n
→ (sig : Signature)
→ Env (carrier sig) n
→ Set
⟦ t₁ ≋P t₂ ⟧P (sig carrier _⊕_ _≈_) env
= ⟦ t₁ ⟧T (sig carrier _⊕_ _≈_) env ≈ ⟦ t₂ ⟧T (sig carrier _⊕_ _≈_) env
⟦ p →P q ⟧P signature env = ⟦ p ⟧P signature env → ⟦ q ⟧P signature env
⟦ ∀P pred ⟧P signature env = ∀ x → ⟦ pred ⟧P signature (x ∷ env)
module Example-1 where
≋-trans : Predicate zero
≋-trans = let x = var (# 0)
y = var (# 1)
z = var (# 2)
in ∀P (∀P (∀P (((x ≋P y) →P (y ≋P z)) →P (x ≋P z))))
≋-trans-ℕ : Set
≋-trans-ℕ = ⟦ ≋-trans ⟧P ℕ-sig []
≋-trans-Numeral : (b d : ℕ) → True (Continuous? b d 0) → Set
≋-trans-Numeral b d prop = ⟦ ≋-trans ⟧P (Numeral-sig b d prop) []
-- lemma for env
lookup-map : ∀ {i j} → {A : Set i} {B : Set j}
→ (f : A → B) →
∀ {n} → (xs : Vec A n) (i : Fin n)
→ lookup i (map f xs) ≡ f (lookup i xs)
lookup-map f [] ()
lookup-map f (x ∷ xs) zero = refl
lookup-map f (x ∷ xs) (suc i) = lookup-map f xs i
-- ------------------------------------------------------------------------
-- -- toℕ : preserving structures of terms and predicates
-- ------------------------------------------------------------------------
toℕ-term-homo : ∀ {b d n}
→ (cont : True (Continuous? b d 0))
→ (t : Term n)
→ (env : Vec (Numeral b d 0) n)
→ ⟦ t ⟧T ℕ-sig (map ⟦_⟧ env) ≡ ⟦ ⟦ t ⟧T (Numeral-sig b d cont) env ⟧
toℕ-term-homo cont (var i) env = lookup-map ⟦_⟧ env i
toℕ-term-homo {b} {d} cont (t₁ ∔ t₂) env
rewrite toℕ-term-homo cont t₁ env | toℕ-term-homo cont t₂ env
= sym (toℕ-⊹-homo cont (⟦ t₁ ⟧T (Numeral-sig b d cont) env) (⟦ t₂ ⟧T (Numeral-sig b d cont) env))
mutual
toℕ-pred-ℕ⇒Numeral : ∀ {b d n}
→ (cont : True (Continuous? b (suc d) 0))
→ (pred : Predicate n)
→ (env : Vec (Numeral b (suc d) 0) n)
→ ⟦ pred ⟧P ℕ-sig (map ⟦_⟧ env)
→ ⟦ pred ⟧P (Numeral-sig b (suc d) cont) env
toℕ-pred-ℕ⇒Numeral {b} {d} cont (t₁ ≋P t₂) env sem-ℕ =
begin
⟦ ⟦ t₁ ⟧T (Numeral-sig b (suc d) cont) env ⟧
≡⟨ sym (toℕ-term-homo cont t₁ env) ⟩
⟦ t₁ ⟧T ℕ-sig (map ⟦_⟧ env)
≡⟨ sem-ℕ ⟩
⟦ t₂ ⟧T ℕ-sig (map ⟦_⟧ env)
≡⟨ toℕ-term-homo cont t₂ env ⟩
⟦ ⟦ t₂ ⟧T (Numeral-sig b (suc d) cont) env ⟧
∎
toℕ-pred-ℕ⇒Numeral cont (p →P q) env sem-ℕ ⟦p⟧P-Numeral =
toℕ-pred-ℕ⇒Numeral cont q env
(sem-ℕ (toℕ-pred-Numeral⇒ℕ cont p env ⟦p⟧P-Numeral))
toℕ-pred-ℕ⇒Numeral cont (∀P pred) env sem-ℕ x =
toℕ-pred-ℕ⇒Numeral cont pred (x ∷ env) (sem-ℕ ⟦ x ⟧)
toℕ-pred-Numeral⇒ℕ : ∀ {b d n}
→ (cont : True (Continuous? b (suc d) 0))
→ (pred : Predicate n)
→ (env : Vec (Numeral b (suc d) 0) n)
→ ⟦ pred ⟧P (Numeral-sig b (suc d) cont) env
→ ⟦ pred ⟧P ℕ-sig (map ⟦_⟧ env)
toℕ-pred-Numeral⇒ℕ {b} {d} cont (t₁ ≋P t₂) env sem-Num =
begin
⟦ t₁ ⟧T ℕ-sig (map ⟦_⟧ env)
≡⟨ toℕ-term-homo cont t₁ env ⟩
⟦ ⟦ t₁ ⟧T (Numeral-sig b (suc d) cont) env ⟧
≡⟨ sem-Num ⟩
⟦ ⟦ t₂ ⟧T (Numeral-sig b (suc d) cont) env ⟧
≡⟨ sym (toℕ-term-homo cont t₂ env) ⟩
⟦ t₂ ⟧T ℕ-sig (map ⟦_⟧ env)
∎
toℕ-pred-Numeral⇒ℕ cont (p →P q) env sem-Num ⟦p⟧P
= toℕ-pred-Numeral⇒ℕ cont q env
(sem-Num
(toℕ-pred-ℕ⇒Numeral cont p env ⟦p⟧P))
toℕ-pred-Numeral⇒ℕ {b} {d} cont (∀P pred) env sem-Num n with n ≟ ⟦ fromℕ {cont = cont} n z≤n ⟧
toℕ-pred-Numeral⇒ℕ {b} {d} cont (∀P pred) env sem-Num n | yes eq
rewrite eq
= toℕ-pred-Numeral⇒ℕ cont pred (fromℕ {cont = cont} n _ ∷ env) (sem-Num (fromℕ {cont = cont} n _))
toℕ-pred-Numeral⇒ℕ {b} {d} cont (∀P pred) env sem-Num n | no ¬eq
= contradiction (sym (fromℕ-toℕ cont n _)) ¬eq
module Example-2 where
+-comm-Predicate : Predicate 0
+-comm-Predicate = ∀P (∀P ((var (# 1) ∔ var (# 0)) ≋P (var (# 0) ∔ var (# 1))))
+-comm-ℕ : ∀ a b → a + b ≡ b + a
+-comm-ℕ = +-comm
+-comm-Num : ∀ {b d}
→ {cont : True (Continuous? b (suc d) 0)}
→ (xs ys : Numeral b (suc d) 0)
→ (_⊹_ {cont = cont} xs ys) ≋ (_⊹_ {cont = cont} ys xs)
+-comm-Num {cont = cont} = toℕ-pred-ℕ⇒Numeral cont +-comm-Predicate [] +-comm-ℕ
--
-- mutual
-- toℕ-pred-ℕ⇒Bij : ∀ {b n}
-- → (pred : Predicate n)
-- → (env : Vec (Bij (suc b)) n)
-- → ⟦ pred ⟧ ℕ-sig (map toℕ env)
-- → ⟦ pred ⟧ (BijN-sig (suc b)) env
-- toℕ-pred-ℕ⇒Bij {b} (t₁ ≋ t₂) env ⟦t₁≈t₂⟧ℕ
-- rewrite toℕ-term-homo t₁ env | toℕ-term-homo t₂ env -- ⟦ t₁ ⟧T ℕ-sig (map toℕ env) ≡ toℕ (⟦ t₁ ⟧T (Bij-sig (suc b)) env)
-- = toℕ-injective (⟦ t₁ ⟧T (BijN-sig (suc b)) env) (⟦ t₂ ⟧T (BijN-sig (suc b)) env) ⟦t₁≈t₂⟧ℕ
-- toℕ-pred-ℕ⇒Bij (p ⇒ q) env ⟦p→q⟧ℕ ⟦p⟧B = toℕ-pred-ℕ⇒Bij q env (⟦p→q⟧ℕ (toℕ-pred-Bij⇒ℕ p env ⟦p⟧B))
-- toℕ-pred-ℕ⇒Bij (All p) env ⟦λx→p⟧ℕ x = toℕ-pred-ℕ⇒Bij p (x ∷ env) (⟦λx→p⟧ℕ (toℕ x))
--
-- toℕ-pred-Bij⇒ℕ : ∀ {b n}
-- → (pred : Predicate n)
-- → (env : Vec (Bij (suc b)) n)
-- → ⟦ pred ⟧ (BijN-sig (suc b)) env
-- → ⟦ pred ⟧ ℕ-sig (map toℕ env)
-- toℕ-pred-Bij⇒ℕ (t₁ ≋ t₂) env ⟦t₁≈t₂⟧B
-- rewrite toℕ-term-homo t₁ env | toℕ-term-homo t₂ env
-- = cong toℕ ⟦t₁≈t₂⟧B
-- toℕ-pred-Bij⇒ℕ (p ⇒ q) env ⟦p→q⟧B ⟦p⟧ℕ = toℕ-pred-Bij⇒ℕ q env (⟦p→q⟧B (toℕ-pred-ℕ⇒Bij p env ⟦p⟧ℕ))
-- toℕ-pred-Bij⇒ℕ {b} (All p) env ⟦λx→p⟧B x
-- rewrite (sym (toℕ-fromℕ b x)) -- rewritting "x" to "toℕ (fromℕ x)"
-- = toℕ-pred-Bij⇒ℕ p (fromℕ x ∷ env) (⟦λx→p⟧B (fromℕ x))
-- fromℕ-term-homo : ∀ {b n}
-- → (term : Term n)
-- → (env : Vec ℕ n)
-- → ⟦ term ⟧T (Bij-sig (suc b)) (map fromℕ env) ≡ fromℕ (⟦ term ⟧T ℕ-sig env)
-- fromℕ-term-homo (var i) env = lookup-map fromℕ env i
-- fromℕ-term-homo {b} {n} (t₁ ∔ t₂) env
-- rewrite fromℕ-term-homo {b} {n} t₁ env | fromℕ-term-homo {b} {n} t₂ env
-- = sym (fromℕ-⊹-homo (⟦ t₁ ⟧T (sig ℕ _+_ _≡_) env) (⟦ t₂ ⟧T (sig ℕ _+_ _≡_) env))
--
--
-- ------------------------------------------------------------------------
--
-- open import Data.Nat.Properties.Simple
--
--
-- testExtract : {pred : Predicate 0}
-- → ⟦ pred ⟧ ℕ-sig []
-- → Predicate 0
-- testExtract {pred} ⟦pred⟧ℕ = pred
--
-- ∔-comm : Predicate 0
-- ∔-comm = testExtract {All (All (var (suc zero) ∔ var zero ≋ var zero ∔ var (suc zero)))} +-comm
--
-- ∔-assoc : Predicate 0
-- ∔-assoc = testExtract {All (All (All (var (suc (suc zero)) ∔ var (suc zero) ∔ var zero ≋ var (suc (suc zero)) ∔ (var (suc zero) ∔ var zero))))} +-assoc
-- ∔-assoc = testExtract {All (All (All (var (suc (suc zero)) ∔ var (suc zero) ∔ var zero ≋ var (suc (suc zero)) ∔ (var (suc zero) ∔ var zero))))} +-assoc
| {
"alphanum_fraction": 0.5133767986,
"avg_line_length": 36.9128630705,
"ext": "agda",
"hexsha": "3afc88c57dd2abc601cf7c6188e75c8f68fe8399",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Pred.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"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": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Pred.agda",
"max_line_length": 154,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Pred.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 3826,
"size": 8896
} |
{-# OPTIONS --cubical #-}
module Multidimensional.Data.DirNum.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Unit
open import Cubical.Data.Prod
open import Cubical.Data.Nat
open import Multidimensional.Data.Dir
-- Dependent "directional numerals":
-- for natural n, obtain 2ⁿ "numerals".
-- This is basically a little-endian binary notation.
-- NOTE: Would an implementation of DirNum with dependent vectors be preferable
-- over using products?
DirNum : ℕ → Type₀
DirNum zero = Unit
DirNum (suc n) = Dir × (DirNum n)
DirNum→ℕ : ∀ {n} → DirNum n → ℕ
DirNum→ℕ {zero} tt = zero
DirNum→ℕ {suc n} (↓ , d) = doublesℕ (suc zero) (DirNum→ℕ d)
DirNum→ℕ {suc n} (↑ , d) = suc (doublesℕ (suc zero) (DirNum→ℕ d))
-- give the next numeral, cycling back to 0
-- in case of 2ⁿ - 1
next : ∀ {n} → DirNum n → DirNum n
next {zero} tt = tt
next {suc n} (↓ , ds) = (↑ , ds)
next {suc n} (↑ , ds) = (↓ , next ds)
prev : ∀ {n} → DirNum n → DirNum n
prev {zero} tt = tt
prev {suc n} (↓ , ds) = (↓ , prev ds)
prev {suc n} (↑ , ds) = (↓ , ds)
zero-n : (n : ℕ) → DirNum n
zero-n zero = tt
zero-n (suc n) = (↓ , zero-n n)
one-n : (n : ℕ) → DirNum n
one-n zero = tt
one-n (suc n) = (↑ , zero-n n)
-- numeral for 2ⁿ - 1
max-n : (n : ℕ) → DirNum n
max-n zero = tt
max-n (suc n) = (↑ , max-n n)
-- -- TODO: rename
-- embed-next : (r : ℕ) → DirNum r → DirNum (suc r)
-- embed-next zero tt = (↓ , tt)
-- embed-next (suc r) (d , ds) with zero-n? ds
-- ... | no _ = (d , embed-next r ds)
-- ... | yes _ = (d , zero-n (suc r))
sucDoubleDirNum+ : (r : ℕ) → DirNum r → DirNum (suc r)
sucDoubleDirNum+ r x = (↑ , x)
-- bad name, since this is doubling "to" suc r
doubleDirNum+ : (r : ℕ) → DirNum r → DirNum (suc r)
doubleDirNum+ r x = (↓ , x)
dropLeast : {r : ℕ} → DirNum (suc r) → DirNum r
dropLeast {zero} d = tt
dropLeast {suc r} (x , x₁) = x₁
dropMost : {r : ℕ} → DirNum (suc r) → DirNum r
dropMost {zero} d = tt
dropMost {suc zero} (x , (x₁ , x₂)) = (x₁ , x₂)
dropMost {suc (suc r)} (x , x₁) = (x , dropMost x₁)
-- need to prove property about doubleable
--doubleDirNum : (r : ℕ) (d : DirNum r) → doubleable-n? {r} d ≡ true → DirNum r
-- bad? is not correct when not "doubleable"
-- possibly should view as operations in residue classes?
doubleDirNum : (r : ℕ) (d : DirNum r) → DirNum r
doubleDirNum zero d = tt
doubleDirNum (suc r) d = doubleDirNum+ r (dropMost {r} d)
-- doubleDirNum zero d doubleable = ⊥-elim (false≢true doubleable)
-- doubleDirNum (suc r) d doubleable = doubleDirNum+ r (dropMost {r} d)
| {
"alphanum_fraction": 0.6166007905,
"avg_line_length": 30.119047619,
"ext": "agda",
"hexsha": "7fb200287ebc5f2fac5f6a18bdff1573de1896db",
"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": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_forks_repo_path": "Multidimensional/Data/DirNum/Base.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_issues_repo_issues_event_max_datetime": "2019-07-02T16:24:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-19T20:40:07.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_issues_repo_path": "Multidimensional/Data/DirNum/Base.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_stars_repo_path": "Multidimensional/Data/DirNum/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 957,
"size": 2530
} |
module MinMax where
open import Prelude
open import Logic.Base
open import Logic.Relations
open import Logic.Identity using (_≡_)
import Logic.ChainReasoning
open import DecidableOrder as DecOrder
module Min {A : Set}(Ord : DecidableOrder A) where
open DecidableOrder Ord
min : A → A → A
min a b with decide a b
... | \/-IL _ = a
... | \/-IR _ = b
data CaseMin x y : A → Set where
leq : x ≤ y → CaseMin x y x
geq : x ≥ y → CaseMin x y y
case-min′ : ∀ x y → CaseMin x y (min x y)
case-min′ x y with decide x y
... | \/-IL xy = leq xy
... | \/-IR ¬xy with total x y
... | \/-IL xy = elim-False (¬xy xy)
... | \/-IR yx = geq yx
case-min : (P : A → Set)(x y : A) →
(x ≤ y → P x) →
(y ≤ x → P y) → P (min x y)
case-min P x y ifx ify with min x y | case-min′ x y
... | .x | leq xy = ifx xy
... | .y | geq yx = ify yx
min-glb : ∀ x y z → z ≤ x → z ≤ y → z ≤ min x y
min-glb x y z zx zy with min x y | case-min′ x y
... | .x | leq _ = zx
... | .y | geq _ = zy
min-left : ∀ x y → min x y ≤ x
min-left x y with min x y | case-min′ x y
... | .x | leq _ = refl _
... | .y | geq yx = yx
min-right : ∀ x y → min x y ≤ y
min-right x y with min x y | case-min′ x y
... | .x | leq xy = xy
... | .y | geq _ = refl _
min-sym : ∀ x y → min x y ≡ min y x
min-sym x y = antisym _ _ (lem x y) (lem y x)
where
lem : ∀ a b → min a b ≤ min b a
lem a b with min b a | case-min′ b a
... | .b | leq _ = min-right _ _
... | .a | geq _ = min-left _ _
Dual : {A : Set} → DecidableOrder A → DecidableOrder A
Dual Ord = record
{ _≤_ = _≥_
; refl = refl
; antisym = \x y xy yx → antisym _ _ yx xy
; trans = \x y z xy yz → trans _ _ _ yz xy
; total = \x y → total _ _
; decide = \x y → decide _ _
}
where
open DecidableOrder Ord
module Max {A : Set}(Ord : DecidableOrder A)
= Min (Dual Ord) renaming
( min to max
; case-min to case-max
; case-min′ to case-max′
; CaseMin to CaseMax
; module CaseMin to CaseMax
; leq to geq
; geq to leq
; min-glb to max-lub
; min-sym to max-sym
; min-right to max-right
; min-left to max-left
)
module MinMax {A : Set}(Ord : DecidableOrder A) where
open DecidableOrder Ord public
open Min Ord public
open Max Ord public
module DistributivityA {A : Set}(Ord : DecidableOrder A) where
open MinMax Ord
min-max-distr : ∀ x y z → min x (max y z) ≡ max (min x y) (min x z)
min-max-distr x y z = antisym _ _ left right
where
open Logic.ChainReasoning.Mono.Homogenous _≤_ refl trans
left : min x (max y z) ≤ max (min x y) (min x z)
left with max y z | case-max′ y z
... | .z | Min.geq _ = max-right _ _
... | .y | Min.leq _ = max-left _ _
right : max (min x y) (min x z) ≤ min x (max y z)
-- right with max (min x y) (min x z) | case-max′ (min x y) (min x z)
right = case-max (\w → w ≤ min x (max y z)) (min x y) (min x z)
(\_ → case-max (\w → min x y ≤ min x w) y z
(\_ → refl _)
(\yz → min-glb x z _ (min-left x y)
( chain>
min x y === y by min-right x y
=== z by yz
)
)
)
(\_ → case-max (\w → min x z ≤ min x w) y z
(\zy → min-glb x y _ (min-left x z)
( chain>
min x z === z by min-right x z
=== y by zy
)
)
(\_ → refl _)
)
module DistributivityB {A : Set}(Ord : DecidableOrder A) where
open DistributivityA (Dual Ord) public renaming (min-max-distr to max-min-distr)
module Distributivity {A : Set}(Ord : DecidableOrder A) where
open DistributivityA Ord public
open DistributivityB Ord public
-- Testing
postulate
X : Set
OrdX : DecidableOrder X
-- open DecidableOrder OrdX
open MinMax OrdX -- hiding (_≤_)
open Distributivity OrdX
open Logic.ChainReasoning.Mono.Homogenous
-- Displayforms doesn't work for MinMax._≤_ (reduces to DecidableOrder._≤_)
test : ∀ x y → min x y ≤ x
test x y = min-left x y
| {
"alphanum_fraction": 0.4673133699,
"avg_line_length": 31.4039735099,
"ext": "agda",
"hexsha": "426d900a0d633e51a5158afbe09ddd4c8d6cd458",
"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": "examples/order/MinMax.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": "examples/order/MinMax.agda",
"max_line_length": 82,
"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": "examples/order/MinMax.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": 1467,
"size": 4742
} |
module Pruning where
le2 : {B : Set} -> (A : Set) -> A -> (C : Set) -> C -> (A -> C -> B) -> B
le2 _ x _ y f = f x y
test : le2 Set _ (Set -> Set) _ (\ H -> (\M -> (z : Set) -> H == M z))
test z = refl
{-
let : {B : Set} -> (A : Set) -> A -> (A -> B) -> B
let A x f = f x
test : let Set _ (\ H -> let (Set -> Set) _ (\ M -> (z : Set) -> H == M z))
test z = refl
-}
| {
"alphanum_fraction": 0.4010840108,
"avg_line_length": 23.0625,
"ext": "agda",
"hexsha": "bb0684447a958ca4ab6828a34f7b8a0b95d0de09",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "src/prototyping/term/tests/Pruning.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"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": "larrytheliquid/agda",
"max_issues_repo_path": "src/prototyping/term/tests/Pruning.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "src/prototyping/term/tests/Pruning.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 156,
"size": 369
} |
open import Agda.Primitive using (lzero; lsuc; _⊔_)
open import Relation.Binary.PropositionalEquality
import Relation.Binary.Reasoning.Setoid as SetoidR
import Categories.Category as Category
import Categories.Category.Cartesian as Cartesian
open import Categories.Object.Terminal using (Terminal)
open import Categories.Object.Product using (Product)
open import MultiSorted.AlgebraicTheory
import MultiSorted.Substitution as Substitution
import MultiSorted.Product as Product
module MultiSorted.SyntacticCategory
{ℓt}
{𝓈 ℴ}
{Σ : Signature {𝓈} {ℴ}}
(T : Theory ℓt Σ) where
open Theory T
open Substitution T
-- The syntactic category
𝒮 : Category.Category 𝓈 (lsuc ℴ) (lsuc (ℓt ⊔ 𝓈 ⊔ ℴ))
𝒮 =
record
{ Obj = Context
; _⇒_ = _⇒s_
; _≈_ = _≈s_
; id = id-s
; _∘_ = _∘s_
; assoc = λ {_ _ _ _ _ _ σ} x → subst-∘s (σ x)
; sym-assoc = λ {_ _ _ _ _ _ σ} x → eq-symm (subst-∘s (σ x))
; identityˡ = λ x → eq-refl
; identityʳ = λ {A B f} x → tm-var-id
; identity² = λ x → eq-refl
; equiv = record
{ refl = λ x → eq-refl
; sym = λ ξ y → eq-symm (ξ y)
; trans = λ ζ ξ y → eq-tran (ζ y) (ξ y)}
; ∘-resp-≈ = ∘s-resp-≈s
}
-- We use the product structure which gives back the context directly
prod-𝒮 : Context → Context
prod-𝒮 Γ = Γ
π-𝒮 : ∀ {Γ} (x : var Γ) → Γ ⇒s ctx-slot (sort-of Γ x)
π-𝒮 x _ = tm-var x
tuple-𝒮 : ∀ Γ {Δ} → (∀ (x : var Γ) → Δ ⇒s ctx-slot (sort-of Γ x)) → Δ ⇒s Γ
tuple-𝒮 Γ ts = λ x → ts x var-var
project-𝒮 : ∀ {Γ Δ} {x : var Γ} {ts : ∀ (y : var Γ) → Δ ⇒s ctx-slot (sort-of Γ y)} →
π-𝒮 x ∘s tuple-𝒮 Γ ts ≈s ts x
project-𝒮 {Γ} {Δ} {x} {ts} var-var = eq-refl
unique-𝒮 : ∀ {Γ Δ} {ts : ∀ (x : var Γ) → Δ ⇒s ctx-slot (sort-of Γ x)} {g : Δ ⇒s Γ} →
(∀ x → π-𝒮 x ∘s g ≈s ts x) → tuple-𝒮 Γ ts ≈s g
unique-𝒮 ξ x = eq-symm (ξ x var-var)
producted-𝒮 : Product.Producted 𝒮 {Σ = Σ} ctx-slot
producted-𝒮 =
record
{ prod = prod-𝒮
; π = π-𝒮
; tuple = tuple-𝒮
; project = λ {Γ Δ x ts} → project-𝒮 {ts = ts}
; unique = unique-𝒮
}
-- The terminal object is the empty context
⊤-𝒮 : Context
⊤-𝒮 = ctx-empty
!-𝒮 : ∀ {Γ} → Γ ⇒s ⊤-𝒮
!-𝒮 ()
!-unique-𝒮 : ∀ {Γ} (σ : Γ ⇒s ⊤-𝒮) → !-𝒮 ≈s σ
!-unique-𝒮 σ ()
terminal-𝒮 : Terminal 𝒮
terminal-𝒮 =
record
{ ⊤ = ⊤-𝒮
; ⊤-is-terminal =
record { ! = !-𝒮
; !-unique = !-unique-𝒮 } }
-- Binary product is context contatenation
product-𝒮 : ∀ {Γ Δ} → Product 𝒮 Γ Δ
product-𝒮 {Γ} {Δ} =
record
{ A×B = ctx-concat Γ Δ
; π₁ = λ x → tm-var (var-inl x)
; π₂ = λ x → tm-var (var-inr x)
; ⟨_,_⟩ = ⟨_,_⟩s
; project₁ = λ x → eq-refl
; project₂ = λ x → eq-refl
; unique = λ {Θ σ σ₁ σ₂} ξ₁ ξ₂ z → u Θ σ σ₁ σ₂ ξ₁ ξ₂ z
}
where u : ∀ Θ (σ : Θ ⇒s ctx-concat Γ Δ) (σ₁ : Θ ⇒s Γ) (σ₂ : Θ ⇒s Δ) →
((λ x → σ (var-inl x)) ≈s σ₁) → ((λ y → σ (var-inr y)) ≈s σ₂) → ⟨ σ₁ , σ₂ ⟩s ≈s σ
u Θ σ σ₁ σ₂ ξ₁ ξ₂ (var-inl z) = eq-symm (ξ₁ z)
u Θ σ σ₁ σ₂ ξ₁ ξ₂ (var-inr z) = eq-symm (ξ₂ z)
-- The cartesian structure of the syntactic category
cartesian-𝒮 : Cartesian.Cartesian 𝒮
cartesian-𝒮 =
record
{ terminal = terminal-𝒮
; products = record { product = product-𝒮 } }
| {
"alphanum_fraction": 0.5275729873,
"avg_line_length": 29.2327586207,
"ext": "agda",
"hexsha": "5e4a1cc95ee348a497145f02f736474e7c48a505",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/MultiSorted/SyntacticCategory.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/MultiSorted/SyntacticCategory.agda",
"max_line_length": 99,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/MultiSorted/SyntacticCategory.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 1432,
"size": 3391
} |
{- --- 4. Lists --- -}
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
infixr 5 _∷_
open import Data.Nat
open import Relation.Binary.PropositionalEquality
{- 4.1 Length -}
length : {A : Set} → List A → ℕ
length [] = 0
length (x ∷ l) = 1 + (length l)
{- 4.2 List reversal -}
concat : {A : Set} → List A → List A → List A
concat [] l = l
concat (x ∷ k) l = x ∷ (concat k l)
concat-length : {A : Set} → (k l : List A) → length (concat k l) ≡ (length k) + (length l)
concat-length [] l = refl
concat-length (x ∷ k) l rewrite concat-length k l = refl
concat-assoc : {A : Set} → (j k l : List A) → concat (concat j k) l ≡ concat j (concat k l)
concat-assoc [] k l = refl
concat-assoc (x ∷ j) k l rewrite concat-assoc j k l = refl
{- 4.3 List reversal -}
snoc : {A : Set} → A -> List A → List A
snoc a [] = a ∷ []
snoc a (x ∷ l) = x ∷ (snoc a l)
rev : {A : Set} → List A → List A
rev [] = []
rev (x ∷ l) = snoc x (rev l)
snoc-length : {A : Set} → (a : A) → (l : List A) → length (snoc a l) ≡ suc (length l)
snoc-length a [] = refl
snoc-length a (x ∷ l) rewrite snoc-length a l = refl
rev-length : {A : Set} → (l : List A) → (length (rev l)) ≡ (length l)
rev-length [] = refl
rev-length (x ∷ l) rewrite snoc-length x (rev l) | rev-length l = refl
snoc-rev : {A : Set} → (a : A) → (l : List A) → rev (snoc a l) ≡ a ∷ (rev l)
snoc-rev a [] = refl
snoc-rev a (x ∷ l) rewrite snoc-rev a l = refl
double-rev : {A : Set} → (l : List A) → rev (rev l) ≡ l
double-rev [] = refl
double-rev (x ∷ l) rewrite snoc-rev x (rev l) | double-rev l = refl
{- 4.4 Filtering -}
open import Data.Bool
filter : {A : Set} → (p : A → Bool) → (l : List A) → List A
filter p [] = []
filter p (x ∷ l) with p x
filter p (x ∷ l) | false = filter p l
filter p (x ∷ l) | true = x ∷ (filter p l)
empty-list : {A : Set} → (l : List A) → filter (λ _ → false) l ≡ []
empty-list [] = refl
empty-list (x ∷ l) = empty-list l
identity-list : {A : Set} → (l : List A) → filter (λ _ → true) l ≡ l
identity-list [] = refl
identity-list (x ∷ l) rewrite identity-list l = refl
| {
"alphanum_fraction": 0.5597878496,
"avg_line_length": 26.9350649351,
"ext": "agda",
"hexsha": "0ed03b0e3c0b242114cdef79a211fa8589861966",
"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": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "erwinkn/program-eq-proof",
"max_forks_repo_path": "TD6/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"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": "erwinkn/program-eq-proof",
"max_issues_repo_path": "TD6/List.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "erwinkn/program-eq-proof",
"max_stars_repo_path": "TD6/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 802,
"size": 2074
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category; module Definitions)
-- Definition of the "Twisted Arrow" Category of a Category 𝒞
module Categories.Category.Construction.TwistedArrow {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level
open import Data.Product using (_,_; _×_; map; zip)
open import Function.Base using (_$_; flip)
open import Relation.Binary.Core using (Rel)
import Categories.Morphism as M
open M 𝒞
open import Categories.Morphism.Reasoning 𝒞
open Category 𝒞
open Definitions 𝒞
open HomReasoning
private
variable
A B C : Obj
record Morphism : Set (o ⊔ ℓ) where
field
{dom} : Obj
{cod} : Obj
arr : dom ⇒ cod
record Morphism⇒ (f g : Morphism) : Set (ℓ ⊔ e) where
constructor mor⇒
private
module f = Morphism f
module g = Morphism g
field
{dom⇐} : g.dom ⇒ f.dom
{cod⇒} : f.cod ⇒ g.cod
square : cod⇒ ∘ f.arr ∘ dom⇐ ≈ g.arr
TwistedArrow : Category (o ⊔ ℓ) (ℓ ⊔ e) e
TwistedArrow = record
{ Obj = Morphism
; _⇒_ = Morphism⇒
; _≈_ = λ f g → dom⇐ f ≈ dom⇐ g × cod⇒ f ≈ cod⇒ g
; id = mor⇒ (identityˡ ○ identityʳ)
; _∘_ = λ {A} {B} {C} m₁ m₂ → mor⇒ {A} {C} (∘′ m₁ m₂ ○ square m₁)
; assoc = sym-assoc , assoc
; sym-assoc = assoc , sym-assoc
; identityˡ = identityʳ , identityˡ
; identityʳ = identityˡ , identityʳ
; identity² = identity² , identity²
; equiv = record
{ refl = refl , refl
; sym = map sym sym
; trans = zip trans trans
}
; ∘-resp-≈ = zip (flip ∘-resp-≈) ∘-resp-≈
}
where
open Morphism⇒
open Equiv
open HomReasoning
∘′ : ∀ {A B C} (m₁ : Morphism⇒ B C) (m₂ : Morphism⇒ A B) →
(cod⇒ m₁ ∘ cod⇒ m₂) ∘ Morphism.arr A ∘ (dom⇐ m₂ ∘ dom⇐ m₁) ≈ cod⇒ m₁ ∘ Morphism.arr B ∘ dom⇐ m₁
∘′ {A} {B} {C} m₁ m₂ = begin
(cod⇒ m₁ ∘ cod⇒ m₂) ∘ Morphism.arr A ∘ (dom⇐ m₂ ∘ dom⇐ m₁) ≈⟨ pullʳ sym-assoc ⟩
cod⇒ m₁ ∘ (cod⇒ m₂ ∘ Morphism.arr A) ∘ (dom⇐ m₂ ∘ dom⇐ m₁) ≈⟨ refl⟩∘⟨ (pullˡ assoc) ⟩
cod⇒ m₁ ∘ (cod⇒ m₂ ∘ Morphism.arr A ∘ dom⇐ m₂) ∘ dom⇐ m₁ ≈⟨ (refl⟩∘⟨ square m₂ ⟩∘⟨refl) ⟩
cod⇒ m₁ ∘ Morphism.arr B ∘ dom⇐ m₁ ∎
| {
"alphanum_fraction": 0.5905030559,
"avg_line_length": 29.9577464789,
"ext": "agda",
"hexsha": "01211c24734e0fa91fa6df27681fce15b06301fb",
"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/Category/Construction/TwistedArrow.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/Category/Construction/TwistedArrow.agda",
"max_line_length": 99,
"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/Category/Construction/TwistedArrow.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": 930,
"size": 2127
} |
--------------------------------------------------------------------------------
-- This is part of Agda Inference Systems
{-# OPTIONS --guardedness #-}
open import Agda.Builtin.Equality
open import Data.Product
open import Data.Sum
open import Level
open import Relation.Unary using (_⊆_)
module is-lib.InfSys.FlexCoinduction {𝓁} where
private
variable
U : Set 𝓁
open import is-lib.InfSys.Base {𝓁}
open import is-lib.InfSys.Induction {𝓁}
open import is-lib.InfSys.Coinduction {𝓁}
open MetaRule
open IS
{- Generalized inference systems -}
FCoInd⟦_,_⟧ : ∀{𝓁c 𝓁p 𝓁n 𝓁n'} → (I : IS {𝓁c} {𝓁p} {𝓁n} U) → (C : IS {𝓁c} {𝓁p} {𝓁n'} U) → U → Set _
FCoInd⟦ I , C ⟧ = CoInd⟦ I ⊓ Ind⟦ I ∪ C ⟧ ⟧
{- Bounded Coinduction Principle -}
bdc-lem : ∀{𝓁c 𝓁p 𝓁n 𝓁' 𝓁''}
→ (I : IS {𝓁c} {𝓁p} {𝓁n} U)
→ (S : U → Set 𝓁')
→ (Q : U → Set 𝓁'')
→ S ⊆ Q
→ S ⊆ ISF[ I ] S
→ S ⊆ ISF[ I ⊓ Q ] S
bdc-lem _ _ _ bd cn Su with cn Su
... | rn , c , refl , pr = rn , (c , bd Su) , refl , pr
bounded-coind[_,_] : ∀{𝓁c 𝓁p 𝓁n 𝓁n' 𝓁'}
→ (I : IS {𝓁c} {𝓁p} {𝓁n} U)
→ (C : IS {𝓁c} {𝓁p} {𝓁n'} U)
→ (S : U → Set 𝓁')
→ S ⊆ Ind⟦ I ∪ C ⟧ -- S is bounded w.r.t. I ∪ C
→ S ⊆ ISF[ I ] S -- S is consistent w.r.t. I
→ S ⊆ FCoInd⟦ I , C ⟧
bounded-coind[ I , C ] S bd cn Su = coind[ I ⊓ Ind⟦ I ∪ C ⟧ ] S (bdc-lem I S Ind⟦ I ∪ C ⟧ bd cn) Su
{- Get Ind from FCoInd -}
fcoind-to-ind : ∀{𝓁c 𝓁p 𝓁n 𝓁n'}
{is : IS {𝓁c} {𝓁p} {𝓁n} U}{cois : IS {𝓁c} {𝓁p} {𝓁n'} U}
→ FCoInd⟦ is , cois ⟧ ⊆ Ind⟦ is ∪ cois ⟧
fcoind-to-ind co with CoInd⟦_⟧.unfold co
... | _ , (_ , sd) , refl , _ = sd
{- Apply Rule -}
apply-fcoind : ∀{𝓁c 𝓁p 𝓁n 𝓁n'}
{is : IS {𝓁c} {𝓁p} {𝓁n} U}{cois : IS {𝓁c} {𝓁p} {𝓁n'} U}
→ (rn : is .Names) → RClosed (is .rules rn) FCoInd⟦ is , cois ⟧
apply-fcoind rn c pr = apply-coind rn (c , apply-ind (inj₁ rn) c λ i → fcoind-to-ind (pr i)) pr
{- Postfix - Prefix -}
fcoind-postfix : ∀{𝓁c 𝓁p 𝓁n 𝓁n'}
{is : IS {𝓁c} {𝓁p} {𝓁n} U}{cois : IS {𝓁c} {𝓁p} {𝓁n'} U}
→ FCoInd⟦ is , cois ⟧ ⊆ ISF[ is ] FCoInd⟦ is , cois ⟧
fcoind-postfix FCoInd with FCoInd .CoInd⟦_⟧.unfold
... | rn , (c , _) , refl , pr = rn , c , refl , pr
fcoind-prefix : ∀{𝓁c 𝓁p 𝓁n 𝓁n'}
{is : IS {𝓁c} {𝓁p} {𝓁n} U}{cois : IS {𝓁c} {𝓁p} {𝓁n'} U}
→ ISF[ is ] FCoInd⟦ is , cois ⟧ ⊆ FCoInd⟦ is , cois ⟧
fcoind-prefix (rn , c , refl , pr) = apply-fcoind rn c pr | {
"alphanum_fraction": 0.4911575563,
"avg_line_length": 32.7368421053,
"ext": "agda",
"hexsha": "5f2a8713d1d716432863a55234301eec583fcfdc",
"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": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "boystrange/FairSubtypingAgda",
"max_forks_repo_path": "src/is-lib/InfSys/FlexCoinduction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"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": "boystrange/FairSubtypingAgda",
"max_issues_repo_path": "src/is-lib/InfSys/FlexCoinduction.agda",
"max_line_length": 101,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "boystrange/FairSubtypingAgda",
"max_stars_repo_path": "src/is-lib/InfSys/FlexCoinduction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z",
"num_tokens": 1228,
"size": 2488
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Diagram.Equalizer.Limit {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Data.Nat.Base using (ℕ)
open import Data.Fin.Base hiding (lift)
open import Data.Fin.Patterns
open import Categories.Category.Lift
open import Categories.Category.Finite.Fin
open import Categories.Category.Finite.Fin.Instance.Parallel
open import Categories.Diagram.Equalizer C
open import Categories.Diagram.Limit
open import Categories.Functor.Core
import Categories.Category.Construction.Cones as Co
import Categories.Morphism.Reasoning as MR
private
module C = Category C
open C
open MR C
open HomReasoning
open Equiv
module _ {o′ ℓ′ e′} {F : Functor (liftC o′ ℓ′ e′ Parallel) C} where
private
module F = Functor F
open F
limit⇒equalizer : Limit F → Equalizer {B = F₀ (lift 1F)} (F₁ (lift 0F)) (F₁ (lift 1F))
limit⇒equalizer L = record
{ obj = apex
; arr = proj (lift 0F)
; equality = limit-commute (lift 0F) ○ ⟺ (limit-commute (lift 1F))
; equalize = λ {_} {h} eq → rep record
{ apex = record
{ ψ = λ { (lift 0F) → h
; (lift 1F) → F₁ (lift 1F) ∘ h }
; commute = λ { {lift 0F} {lift 0F} (lift 0F) → elimˡ identity
; {lift 0F} {lift 1F} (lift 0F) → eq
; {lift 0F} {lift 1F} (lift 1F) → refl
; {lift 1F} {lift 1F} (lift 0F) → elimˡ identity }
}
}
; universal = ⟺ commute
; unique = λ {_} {h i} eq → ⟺ (terminal.!-unique record
{ arr = i
; commute = λ { {lift 0F} → ⟺ eq
; {lift 1F} → begin
proj (lift 1F) ∘ i ≈˘⟨ pullˡ (limit-commute (lift 1F)) ⟩
F₁ (lift 1F) ∘ proj (lift 0F) ∘ i ≈˘⟨ refl⟩∘⟨ eq ⟩
F₁ (lift 1F) ∘ h ∎ }
})
}
where open Limit L
module _ o′ ℓ′ e′ {X Y} (f g : X ⇒ Y) where
equalizer⇒limit-F : Functor (liftC o′ ℓ′ e′ Parallel) C
equalizer⇒limit-F = record
{ F₀ = λ { (lift 0F) → X
; (lift 1F) → Y }
; F₁ = λ { {lift 0F} {lift 0F} (lift 0F) → C.id
; {lift 0F} {lift 1F} (lift 0F) → f
; {lift 0F} {lift 1F} (lift 1F) → g
; {lift 1F} {lift 1F} (lift 0F) → C.id }
; identity = λ { {lift 0F} → refl
; {lift 1F} → refl }
; homomorphism = λ { {lift 0F} {lift 0F} {lift 0F} {lift 0F} {lift 0F} → ⟺ identity²
; {lift 0F} {lift 0F} {lift 1F} {lift 0F} {lift 0F} → ⟺ identityʳ
; {lift 0F} {lift 0F} {lift 1F} {lift 0F} {lift 1F} → ⟺ identityʳ
; {lift 0F} {lift 1F} {lift 1F} {lift 0F} {lift 0F} → ⟺ identityˡ
; {lift 0F} {lift 1F} {lift 1F} {lift 1F} {lift 0F} → ⟺ identityˡ
; {lift 1F} {lift 1F} {lift 1F} {lift 0F} {lift 0F} → ⟺ identity² }
; F-resp-≈ = λ { {lift 0F} {lift 0F} {lift 0F} {lift 0F} _ → refl
; {lift 0F} {lift 1F} {lift 0F} {lift 0F} _ → refl
; {lift 0F} {lift 1F} {lift 1F} {lift 1F} _ → refl
; {lift 1F} {lift 1F} {lift 0F} {lift 0F} _ → refl }
}
module _ o′ ℓ′ e′ {X Y} {f g : X ⇒ Y} (e : Equalizer f g) where
open Equalizer e
private
F = equalizer⇒limit-F o′ ℓ′ e′ f g
equalizer⇒limit : Limit F
equalizer⇒limit = record
{ terminal = record
{ ⊤ = record
{ N = obj
; apex = record
{ ψ = λ { (lift 0F) → arr
; (lift 1F) → g ∘ arr }
; commute = λ { {lift 0F} {lift 0F} (lift 0F) → identityˡ
; {lift 0F} {lift 1F} (lift 0F) → equality
; {lift 0F} {lift 1F} (lift 1F) → refl
; {lift 1F} {lift 1F} (lift 0F) → identityˡ }
}
}
; ! = λ {K} →
let open Co.Cone F K
in record
{ arr = equalize (commute (lift 0F) ○ ⟺ (commute (lift 1F)))
; commute = λ { {lift 0F} → ⟺ universal
; {lift 1F} → pullʳ (⟺ universal) ○ commute (lift 1F) }
}
; !-unique = λ f →
let open Co.Cone⇒ F f
in ⟺ (unique (⟺ commute))
}
}
| {
"alphanum_fraction": 0.4812457377,
"avg_line_length": 37.9224137931,
"ext": "agda",
"hexsha": "467306416335a537306781c64161567293d20a4e",
"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": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Equalizer/Limit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"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": "laMudri/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Equalizer/Limit.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Equalizer/Limit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1609,
"size": 4399
} |
module Main where
-- Ensure that the entire library is compiled.
import README
open import Coinduction
open import Data.String
open import Data.Unit using (⊤)
open import IO
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
-- Check that trustMe works.
testTrustMe : IO ⊤
testTrustMe with "apa" ≟ "apa"
... | yes refl = putStrLn "Yes!"
... | no _ = putStrLn "No."
-- Check that ∞ can be used as an "expression".
testInf : Set → Set
testInf = ∞
main = run testTrustMe
| {
"alphanum_fraction": 0.7199211045,
"avg_line_length": 19.5,
"ext": "agda",
"hexsha": "cc8b93fa0268d6c1e251cc6d51dcb43d069b3e2f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/compiler/Main.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"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": "masondesu/agda",
"max_issues_repo_path": "test/compiler/Main.agda",
"max_line_length": 49,
"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/compiler/Main.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": 136,
"size": 507
} |
-- Andreas, 2016-08-26, issue 2152
-- Option --allow-unsolved-metas is not --safe
Unsolved : Set
Unsolved = ?
| {
"alphanum_fraction": 0.6846846847,
"avg_line_length": 18.5,
"ext": "agda",
"hexsha": "f52dcfbb5a33c3ac083be7767c9805eb1c08e116",
"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/Issue2152.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/Issue2152.agda",
"max_line_length": 46,
"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/Issue2152.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": 41,
"size": 111
} |
module Test.Factorial where
open import Data.Nat
factorial : ℕ -> ℕ
factorial zero = 1
factorial n@(suc n') = n * factorial n'
| {
"alphanum_fraction": 0.7054263566,
"avg_line_length": 16.125,
"ext": "agda",
"hexsha": "822dc28ea61189244b5354cc00564fd191a2f7ea",
"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": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yanok/normalize-via-instances",
"max_forks_repo_path": "test/Test/Factorial.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"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": "yanok/normalize-via-instances",
"max_issues_repo_path": "test/Test/Factorial.agda",
"max_line_length": 39,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yanok/normalize-via-instances",
"max_stars_repo_path": "test/Test/Factorial.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 41,
"size": 129
} |
-- Andreas, 2018-05-09, issue 2636, reported by nad
-- {-# OPTIONS -v tc.pos:10 #-}
id : (A : Set₁) → A → A
id A x = x
A : Set₁
A = Set
where
F : Set₁ → Set₁
F X = X
data D : Set₁ where
c : F D → D
lemma : F (D → Set) → D → Set
lemma fp d = id (F (D → Set)) fp d
-- Problem was:
-- Positivity checker for D complained when lemma was present.
| {
"alphanum_fraction": 0.5549450549,
"avg_line_length": 16.5454545455,
"ext": "agda",
"hexsha": "43d754f32d616b014889d1742f3524a0e80f325a",
"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/Bugs/Issue2636.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/Bugs/Issue2636.agda",
"max_line_length": 62,
"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/Bugs/Issue2636.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": 139,
"size": 364
} |
module Inductive.Examples.Ord where
open import Inductive
open import Tuple
open import Data.Fin
open import Data.Product
open import Data.List
open import Data.Vec hiding (lookup)
open import Inductive.Examples.Nat
Ord : Set
Ord = Inductive (([] , []) ∷ (([] , ((Nat ∷ []) ∷ [])) ∷ []))
zeroₒ : Ord
zeroₒ = construct Fin.zero [] []
supₒ : (Nat → Ord) → Ord
supₒ f = construct (Fin.suc Fin.zero) [] ((λ x → f (lookup Fin.zero x)) ∷ [])
| {
"alphanum_fraction": 0.649321267,
"avg_line_length": 21.0476190476,
"ext": "agda",
"hexsha": "4979fa426cd729675904120fd5d4d29c8190c029",
"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": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mr-ohman/general-induction",
"max_forks_repo_path": "Inductive/Examples/Ord.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"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": "mr-ohman/general-induction",
"max_issues_repo_path": "Inductive/Examples/Ord.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mr-ohman/general-induction",
"max_stars_repo_path": "Inductive/Examples/Ord.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 137,
"size": 442
} |
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Change contexts
--
-- This module specifies how a context of values is merged
-- together with the corresponding context of changes.
--
-- In the PLDI paper, instead of merging the contexts together, we just
-- concatenate them. For example, in the "typing rule" for Derive
-- in Sec. 3.2 of the paper, we write in the conclusion of the rule:
-- "Γ, ΔΓ ⊢ Derive(t) : Δτ". Simple concatenation is possible because
-- the paper uses named variables and assumes that no user variables
-- start with "d". In this formalization, we use de Bruijn indices, so
-- it is easier to alternate values and their changes in the context.
------------------------------------------------------------------------
module Base.Change.Context
{Type : Set}
(ΔType : Type → Type) where
open import Base.Syntax.Context Type
-- Transform a context of values into a context of values and
-- changes.
ΔContext : Context → Context
ΔContext ∅ = ∅
ΔContext (τ • Γ) = ΔType τ • τ • ΔContext Γ
-- like ΔContext, but ΔType τ and τ are swapped
ΔContext′ : Context → Context
ΔContext′ ∅ = ∅
ΔContext′ (τ • Γ) = τ • ΔType τ • ΔContext′ Γ
-- This sub-context relationship explains how to go back from
-- ΔContext Γ to Γ: You have to drop every other binding.
Γ≼ΔΓ : ∀ {Γ} → Γ ≼ ΔContext Γ
Γ≼ΔΓ {∅} = ∅
Γ≼ΔΓ {τ • Γ} = drop ΔType τ • keep τ • Γ≼ΔΓ
| {
"alphanum_fraction": 0.6274509804,
"avg_line_length": 35.7,
"ext": "agda",
"hexsha": "f737caeb1edb0a10cfea74541fa53205c8878539",
"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/Context.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/Context.agda",
"max_line_length": 72,
"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/Context.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": 402,
"size": 1428
} |
module GGT.Group.Bundles
{a b ℓ}
where
open import Algebra.Bundles using (Group)
open import Relation.Unary
open import Relation.Binary
open import Level
open import GGT.Group.Structures
record SubGroup (G : Group a ℓ) : Set (a ⊔ suc b ⊔ ℓ) where
open Group G public
field
P : Pred Carrier b
isSubGroup : IsSubGroup G P
open IsSubGroup isSubGroup public
-- imports ~
-- xy-1 ∈ H => xy-1 = h => h'xy-1 = h'' => h'x = h''y -- right cosets
-- x ↦ ω · x = ω · yx-1 · x = ω · y
cosetʳRel : {G : Group a ℓ} → (SubGroup G) → Setoid a b
cosetʳRel {G} H = record { Carrier = Carrier;
_≈_ = _∼_;
isEquivalence = iseq} where
open SubGroup H
open import GGT.Group.Facts G
iseq = record {refl = cosetRelRefl isSubGroup ;
sym = cosetRelSym isSubGroup ;
trans = cosetRelTrans isSubGroup }
syntax cosetʳRel {G} H = H \\ G
| {
"alphanum_fraction": 0.5478775913,
"avg_line_length": 29.7941176471,
"ext": "agda",
"hexsha": "3326e2edfadc15903982718bcc248434c18e986a",
"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": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zampino/ggt",
"max_forks_repo_path": "src/ggt/group/Bundles.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"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": "zampino/ggt",
"max_issues_repo_path": "src/ggt/group/Bundles.agda",
"max_line_length": 71,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zampino/ggt",
"max_stars_repo_path": "src/ggt/group/Bundles.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-28T05:48:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-17T11:10:00.000Z",
"num_tokens": 312,
"size": 1013
} |
------------------------------------------------------------------------
-- Code related to the paper "Compiling Programs with Erased
-- Univalence"
--
-- Nils Anders Danielsson
--
-- The paper is coauthored with Andreas Abel and Andrea Vezzosi.
------------------------------------------------------------------------
-- Most of the code referenced below can be found in modules that are
-- parametrised by a notion of equality. One can use them both with
-- Cubical Agda paths and with the Cubical Agda identity type family.
-- Note that the code does not follow the paper exactly. For instance,
-- some definitions use bijections (functions with quasi-inverses)
-- instead of equivalences.
-- An attempt has been made to track uses of univalence by passing
-- around explicit proofs of the univalence axiom (except in certain
-- README modules). However, some library code that is used does not
-- adhere to this convention (note that univalence is provable in
-- Cubical Agda), so perhaps some use of univalence is not tracked in
-- this way. On the other hand some library code that is not defined
-- in Cubical Agda passes around explicit proofs of function
-- extensionality.
-- Some other differences are mentioned below.
-- Note that there is a known problem with guarded corecursion in
-- Agda. Due to "quantifier inversion" (see "Termination Checking in
-- the Presence of Nested Inductive and Coinductive Types" by Thorsten
-- Altenkirch and myself) certain types may not have the expected
-- semantics when the option --guardedness is used. I expect that the
-- results would still hold if this bug were fixed, but because I do
-- not know what the rules of a fixed version of Agda would be I do
-- not know if any changes to the code would be required.
{-# OPTIONS --guardedness #-}
module README.Compiling-Programs-with-Erased-Univalence where
import Coherently-constant
import Colimit.Sequential
import Colimit.Sequential.Very-erased
import Equality.Path
import Equality.Path.Univalence
import Equivalence
import Equivalence.Erased
import Equivalence.Erased.Basics
import Equivalence.Erased.Contractible-preimages
import Equivalence.Half-adjoint
import Erased.Basics
import Erased.Cubical
import Erased.Level-1
import Erased.Stability
import H-level.Truncation.Propositional
import H-level.Truncation.Propositional.Completely-erased
import H-level.Truncation.Propositional.Erased
import H-level.Truncation.Propositional.Non-recursive
import H-level.Truncation.Propositional.Non-recursive.Erased
import H-level.Truncation.Propositional.One-step
import Preimage
import Univalence-axiom
import Lens.Non-dependent.Higher
import Lens.Non-dependent.Higher.Erased
import Lens.Non-dependent.Higher.Capriotti.Variant.Erased.Variant
import Lens.Non-dependent.Higher.Coinductive
import Lens.Non-dependent.Higher.Coinductive.Erased
import Lens.Non-dependent.Higher.Coinductive.Small
import Lens.Non-dependent.Higher.Coinductive.Small.Erased
import README.Fst-snd
------------------------------------------------------------------------
-- 2: Cubical Agda
-- The functions cong and ext.
cong = Equality.Path.cong
ext = Equality.Path.⟨ext⟩
-- The propositional truncation operator.
--
-- The current module uses --erased-cubical, so this operator, which
-- is defined using --cubical, can only be used in erased contexts.
@0 ∥_∥ : _
∥_∥ = H-level.Truncation.Propositional.∥_∥
-- The map function. This function is not defined in the same way as
-- in the paper, it is defined using a non-dependent eliminator.
@0 map : _
map = H-level.Truncation.Propositional.∥∥-map
-- The propositional truncation operator with an erased truncation
-- constructor.
∥_∥ᴱ = H-level.Truncation.Propositional.Erased.∥_∥ᴱ
-- Half adjoint equivalences. Note that, unlike in the paper, _≃_ is
-- defined as a record type.
Is-equivalence = Equivalence.Half-adjoint.Is-equivalence
_≃_ = Equivalence._≃_
-- Univalence. (This type family is not defined in exactly the same
-- way as in the paper.)
Univalence = Univalence-axiom.Univalence
-- A proof of univalence. The proof uses glue.
@0 univ : _
univ = Equality.Path.Univalence.univ
------------------------------------------------------------------------
-- 3: Postulating Erased Univalence
-- Erased.
Erased = Erased.Basics.Erased
-- []-cong for paths.
[]-cong = Erased.Cubical.[]-cong-Path
------------------------------------------------------------------------
-- 6.1: Equivalences with Erased Proofs
-- Equivalences with erased proofs. Note that, unlike in the paper,
-- _≃ᴱ_ is defined as a record type.
Is-equivalenceᴱ = Equivalence.Erased.Basics.Is-equivalenceᴱ
_≃ᴱ_ = Equivalence.Erased.Basics._≃ᴱ_
to = Equivalence.Erased.Basics._≃ᴱ_.to
from = Equivalence.Erased.Basics._≃ᴱ_.from
@0 to-from : _
to-from = Equivalence.Erased.Basics._≃ᴱ_.right-inverse-of
@0 from-to : _
from-to = Equivalence.Erased.Basics._≃ᴱ_.left-inverse-of
-- Erased≃ is stated a little differently.
Erased≃ = Erased.Level-1.Erased↔
-- Lemmas 41 and 42 are proved in modules parametrised by definitions
-- of []-cong, in the latter case []-cong is also assumed to satisfy
-- certain properties (that hold for the definition mentioned above).
-- Some definitions below are also defined in such modules.
Lemma-41 = Erased.Level-1.[]-cong₁.Erased-cong-≃
Lemma-42 = Equivalence.Erased.[]-cong.Σ-cong-≃ᴱ-Erased
-- The functions substᴱ and subst.
substᴱ = Erased.Level-1.[]-cong₁.substᴱ
subst = Equality.Path.subst
-- Lemmas 45–47.
Lemma-45 = Equivalence.Erased.[]-cong.drop-⊤-left-Σ-≃ᴱ-Erased
Lemma-46 = Equivalence.Erased.Σ-cong-≃ᴱ
Lemma-47 = Equivalence.Erased.drop-⊤-left-Σ-≃ᴱ
------------------------------------------------------------------------
-- 6.2: A Non-recursive Definition of the Propositional Truncation
-- Operator
-- ∥_∥¹ and Colimit.
@0 ∥_∥¹ : _
∥_∥¹ = H-level.Truncation.Propositional.One-step.∥_∥¹
@0 Colimit : _
Colimit = Colimit.Sequential.Colimit
-- Lemma 50.
@0 Lemma-50 : _
Lemma-50 = Colimit.Sequential.universal-property
-- ∥_∥¹-out and ∥_∥ᴺ.
@0 ∥_∥¹-out : _
∥_∥¹-out = H-level.Truncation.Propositional.One-step.∥_∥¹-out-^
@0 ∥_∥ᴺ : _
∥_∥ᴺ = H-level.Truncation.Propositional.Non-recursive.∥_∥
-- ∥_∥ᴺ and ∥_∥ are pointwise equivalent.
@0 ∥∥ᴺ≃∥∥ : _
∥∥ᴺ≃∥∥ = H-level.Truncation.Propositional.Non-recursive.∥∥≃∥∥
-- Colimitᴱ.
Colimitᴱ = Colimit.Sequential.Very-erased.Colimitᴱ
-- Lemma 54.
Lemma-54 = Colimit.Sequential.Very-erased.universal-property
-- ∥_∥ᴺᴱ.
∥_∥ᴺᴱ = H-level.Truncation.Propositional.Non-recursive.Erased.∥_∥ᴱ
-- Lemma 56 (or rather its inverse).
Lemma-56 = H-level.Truncation.Propositional.Erased.∥∥ᴱ≃∥∥ᴱ
------------------------------------------------------------------------
-- 6.3: Higher Lenses with Erased Proofs
-- Lensᴱ, get and set.
@0 Lensᴱ : _
Lensᴱ = Lens.Non-dependent.Higher.Lens
@0 get : _
get = Lens.Non-dependent.Higher.Lens.get
@0 set : _
set = Lens.Non-dependent.Higher.Lens.set
-- Lensᴱᴱ.
Lensᴱᴱ = Lens.Non-dependent.Higher.Erased.Lens
-- The function _⁻¹_.
_⁻¹_ = Preimage._⁻¹_
-- Lens^C (defined using a record type).
@0 Lens^C : _
Lens^C = Lens.Non-dependent.Higher.Coinductive.Small.Lens
-- Coherently-constant^C.
@0 Coherently-constant^C : _
Coherently-constant^C =
Lens.Non-dependent.Higher.Coinductive.Small.Coherently-constant
-- Lens^CE (with the field name get⁻¹-coherently-constant instead of
-- cc).
Lens^CE = Lens.Non-dependent.Higher.Coinductive.Small.Erased.Lens
------------------------------------------------------------------------
-- 6.4: The Definitions Are Equivalent
-- Lemma 65 (or rather its inverse), and a proof (in an erased
-- context) showing that Lemma 65 preserves getters and setters.
--
-- Lemma 65 and some other lemmas use arguments of type Block s (for
-- some string s). This type is equivalent to the unit type. These
-- arguments are used to block definitions from being unfolded by the
-- type-checker.
Lemma-65 =
Lens.Non-dependent.Higher.Coinductive.Small.Erased.Lens≃ᴱLensᴱ
@0 Lemma-65-preserves-getters-and-setters : _
Lemma-65-preserves-getters-and-setters =
Lens.Non-dependent.Higher.Coinductive.Small.Erased.Lens≃ᴱLensᴱ-preserves-getters-and-setters
-- Lens₁ᴱ and Lens₂ᴱ.
Lens₁ᴱ = Lens.Non-dependent.Higher.Capriotti.Variant.Erased.Variant.Lens
Lens₂ᴱ = Lens.Non-dependent.Higher.Coinductive.Erased.Lens
-- The function _⁻¹ᴱ_.
_⁻¹ᴱ_ = Equivalence.Erased.Contractible-preimages._⁻¹ᴱ_
-- Coherently-constant₁ᴱ, Coherently-constant, Coherently-constant₂ᴱ,
-- Coherently-constant₂^C and constant.
Coherently-constant₁ᴱ =
Lens.Non-dependent.Higher.Capriotti.Variant.Erased.Variant.Coherently-constant
@0 Coherently-constant : _
Coherently-constant = Coherently-constant.Coherently-constant
Coherently-constant₂ᴱ =
Lens.Non-dependent.Higher.Coinductive.Erased.Coherently-constant
@0 Coherently-constant₂^C : _
Coherently-constant₂^C =
Lens.Non-dependent.Higher.Coinductive.Coherently-constant
@0 constant : _
constant = Lens.Non-dependent.Higher.Coinductive.constant
-- Lemmas 74–77.
Lemma-74 = Erased.Stability.[]-cong.Erased-other-singleton≃ᴱ⊤
Lemma-75 = Lens.Non-dependent.Higher.Coinductive.Erased.∥∥ᴱ→≃
Lemma-76 = Equivalence.Erased.other-singleton-with-Π-≃ᴱ-≃ᴱ-⊤
Lemma-77 = H-level.Truncation.Propositional.Erased.Σ-Π-∥∥ᴱ-Erased-≡-≃
------------------------------------------------------------------------
-- 6.5: Compilation of Lenses
-- A slightly more general variant of sndᴱ.
sndᴱ = Lens.Non-dependent.Higher.Erased.snd
-- Lemma 79.
Lemma-79 =
H-level.Truncation.Propositional.Completely-erased.Erased-∥∥×≃
-- A slightly more general variant of snd^C.
snd^C = README.Fst-snd.snd-with-space-leak
-- Lemma 81.
Lemma-81 =
Lens.Non-dependent.Higher.Coinductive.Small.Erased.with-other-setter
-- A slightly more general variant of the variant of snd^C with a
-- changed setter.
snd^C-with-changed-setter = README.Fst-snd.snd
| {
"alphanum_fraction": 0.7043987086,
"avg_line_length": 30.975,
"ext": "agda",
"hexsha": "ec8e4a5bb08bee4a548ea7465a44c43d3ab15df0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependent-lenses",
"max_forks_repo_path": "README/Compiling-Programs-with-Erased-Univalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"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/dependent-lenses",
"max_issues_repo_path": "README/Compiling-Programs-with-Erased-Univalence.agda",
"max_line_length": 94,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependent-lenses",
"max_stars_repo_path": "README/Compiling-Programs-with-Erased-Univalence.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z",
"num_tokens": 2946,
"size": 9912
} |
module ASN1.X509 where
open import Data.Word8 using (Word8; _and_; _or_; _==_) renaming (primWord8fromNat to to𝕎; primWord8toNat to from𝕎)
open import Data.ByteString using (ByteString; Strict; pack; fromChunks; toStrict)
open import Data.ByteString.Utf8 using (packStrict)
open import Data.Bool using (Bool; true; false)
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.List using (List; []; _∷_; foldl)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_)
open import Data.String using (String)
open import ASN1.Untyped
import ASN1.BER as BER
AlgorithmIdentifier : List ℕ → AST → AST
AlgorithmIdentifier oid params = SEQUENCE (OBJECT-IDENTIFIER oid ∷ params ∷ [])
AttributeTypeAndValue : List ℕ → AST → AST
AttributeTypeAndValue type value = SEQUENCE (OBJECT-IDENTIFIER type ∷ value ∷ [])
id-at-commonName : List ℕ
id-at-commonName = 2 ∷ 5 ∷ 4 ∷ 3 ∷ []
CommonName : String → AST
CommonName cn = AttributeTypeAndValue id-at-commonName (UTF8String cn)
RDN : String → AST
RDN cn = SET (CommonName cn ∷ [])
RDNSequence : String → AST
RDNSequence cn = SEQUENCE (RDN cn ∷ [])
Name : String → AST
Name cn = RDNSequence cn
Validity : (from to : String) → AST
Validity from to = SEQUENCE (GeneralizedTime from ∷ GeneralizedTime to ∷ [])
bign-with-hbelt-oid : List ℕ
bign-with-hbelt-oid = 1 ∷ 2 ∷ 112 ∷ 0 ∷ 2 ∷ 0 ∷ 34 ∷ 101 ∷ 45 ∷ 12 ∷ []
bign-pubkey-oid : List ℕ
bign-pubkey-oid = 1 ∷ 2 ∷ 112 ∷ 0 ∷ 2 ∷ 0 ∷ 34 ∷ 101 ∷ 45 ∷ 2 ∷ 1 ∷ []
bign-curve256v1-oid : List ℕ
bign-curve256v1-oid = 1 ∷ 2 ∷ 112 ∷ 0 ∷ 2 ∷ 0 ∷ 34 ∷ 101 ∷ 45 ∷ 3 ∷ 1 ∷ []
SubjectPublicKeyInfo : ByteString Strict → AST
SubjectPublicKeyInfo pub = SEQUENCE
( AlgorithmIdentifier bign-pubkey-oid (OBJECT-IDENTIFIER bign-curve256v1-oid)
∷ BIT-STRING 0 pub ∷ [])
Extension : OID → (critical : Bool) → ByteString Strict → AST
Extension oid true value = SEQUENCE (OBJECT-IDENTIFIER oid ∷ BOOLEAN true ∷ OCTET-STRING value ∷ [])
Extension oid false value = SEQUENCE (OBJECT-IDENTIFIER oid ∷ OCTET-STRING value ∷ [])
module mkCert
(issuer-cn : String)
(subject-cn : String)
(validity-from : String)
(validity-to : String)
(pub : ByteString Strict)
(sign : ByteString Strict → ByteString Strict) -- tbs → sig
where
sa version serial issuer validity subject spki : AST
sa = AlgorithmIdentifier bign-with-hbelt-oid NULL
version = EXPLICIT (to𝕎 0) (INTEGER 2) -- v3
serial = INTEGER 1
issuer = Name issuer-cn
validity = Validity validity-from validity-to
subject = Name subject-cn
spki = SubjectPublicKeyInfo pub
{-
ku
eku
skid
ikid
-- id-ce = 2 ∷ 5 ∷ 29 ∷ []
-}
id-ce-arc : OID → OID
id-ce-arc tail = 2 ∷ 5 ∷ 29 ∷ tail
id-kp-arc : OID → OID
id-kp-arc tail = 1 ∷ 3 ∷ 6 ∷ 1 ∷ 5 ∷ 5 ∷ 7 ∷ 3 ∷ tail
ku-oid : OID
ku-oid = id-ce-arc (15 ∷ [])
data KeyUsage : Set where
digitalSignature nonRepudation keyEncipherment dataEncipherment
keyAgreement keyCertSign cRLSign encipherOnly decipherOnly : KeyUsage
pattern contentCommitment = nonRepudation
ku : List KeyUsage → AST
ku kus = Extension ku-oid true (BER.encode″ (BIT-STRING 7 (pack (w₀ ∷ w₁ ∷ [])))) where
kuIdx : KeyUsage → ℕ
kuIdx digitalSignature = 0
kuIdx nonRepudation = 1
kuIdx keyEncipherment = 2
kuIdx dataEncipherment = 3
kuIdx keyAgreement = 4
kuIdx keyCertSign = 5
kuIdx cRLSign = 6
kuIdx encipherOnly = 7
kuIdx decipherOnly = 8
i₀ i₁ : KeyUsage → Word8
i₀ digitalSignature = to𝕎 0x80
i₀ nonRepudation = to𝕎 0x40
i₀ keyEncipherment = to𝕎 0x20
i₀ dataEncipherment = to𝕎 0x10
i₀ keyAgreement = to𝕎 0x08
i₀ keyCertSign = to𝕎 0x04
i₀ cRLSign = to𝕎 0x02
i₀ encipherOnly = to𝕎 0x01
i₀ decipherOnly = to𝕎 0
i₁ digitalSignature = to𝕎 0
i₁ nonRepudation = to𝕎 0
i₁ keyEncipherment = to𝕎 0
i₁ dataEncipherment = to𝕎 0
i₁ keyAgreement = to𝕎 0
i₁ keyCertSign = to𝕎 0
i₁ cRLSign = to𝕎 0
i₁ encipherOnly = to𝕎 0
i₁ decipherOnly = to𝕎 0x80
f₀ f₁ : Word8 → KeyUsage → Word8
f₀ w u = w or (i₀ u)
f₁ w u = w or (i₁ u)
w₀ w₁ : Word8
w₀ = foldl f₀ (to𝕎 0) kus
w₁ = foldl f₁ (to𝕎 0) kus
id-kp-serverAuth id-kp-clientAuth : OID
id-kp-serverAuth = id-kp-arc (1 ∷ [])
id-kp-clientAuth = id-kp-arc (2 ∷ [])
eku-oid : OID
eku-oid = id-ce-arc (37 ∷ [])
eku : AST
eku = Extension eku-oid false (BER.encode″ (SEQUENCE (OBJECT-IDENTIFIER id-kp-serverAuth ∷ OBJECT-IDENTIFIER id-kp-clientAuth ∷ [])))
bc-oid : OID
bc-oid = id-ce-arc (19 ∷ [])
bc : AST
bc = Extension bc-oid true (BER.encode″ (SEQUENCE (BOOLEAN is-ca-true ∷ []))) where
is-ca-true : Bool
is-ca-true = true
exts : AST
exts = EXPLICIT (tag 3) (SEQUENCE (bc ∷ ku (keyAgreement ∷ []) ∷ eku ∷ []))
tbs : AST
tbs = SEQUENCE (version ∷ serial ∷ sa ∷ issuer ∷ validity ∷ subject ∷ spki ∷ exts ∷ [])
tbs′ : ByteString Strict
tbs′ = toStrict (fromChunks (BER.encode tbs))
sig : ByteString Strict
sig = sign tbs′
sv : AST
sv = BIT-STRING 0 sig
cert : AST
cert = SEQUENCE (tbs ∷ sa ∷ sv ∷ [])
| {
"alphanum_fraction": 0.662850375,
"avg_line_length": 30.5180722892,
"ext": "agda",
"hexsha": "f477d67b86bd08c94651221afa3791e30b988968",
"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": "bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "semenov-vladyslav/asn1-agda",
"max_forks_repo_path": "src/ASN1/X509.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8",
"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": "semenov-vladyslav/asn1-agda",
"max_issues_repo_path": "src/ASN1/X509.agda",
"max_line_length": 135,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "semenov-vladyslav/asn1-agda",
"max_stars_repo_path": "src/ASN1/X509.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1897,
"size": 5066
} |
{-
Elementary transformation specific to coefficient ℤ
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.IntegerMatrix.Elementaries where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Data.Nat hiding (_+_ ; _·_)
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Algebra.RingSolver.Reflection
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤ to Ringℤ)
open import Cubical.Algebra.Matrix
open import Cubical.Algebra.Matrix.CommRingCoefficient
open import Cubical.Algebra.Matrix.RowTransformation
private
variable
ℓ : Level
m n : ℕ
-- It seems there are bugs when applying ring solver to integers.
-- The following is a work-around.
private
module Helper {ℓ : Level}(𝓡 : CommRing ℓ) where
open CommRingStr (𝓡 .snd)
helper1 : (a b x y g : 𝓡 .fst) → (a · x - b · - y) · g ≡ a · (x · g) + b · (y · g)
helper1 = solve 𝓡
helper2 : (a b : 𝓡 .fst) → a ≡ 1r · a + 0r · b
helper2 = solve 𝓡
open Helper Ringℤ
module ElemTransformationℤ where
open import Cubical.Foundations.Powerset
open import Cubical.Data.Int using (·rCancel)
open import Cubical.Data.Int.Divisibility
private
ℤ = Ringℤ .fst
open CommRingStr (Ringℤ .snd)
open Sum (CommRing→Ring Ringℤ)
open Coefficient Ringℤ
open LinearTransformation Ringℤ
open Bézout
open SimRel
open Sim
open isLinear
open isLinear2×2
-- The Bézout step to simplify one row
module _
(x y : ℤ)(b : Bézout x y) where
bézout2Mat : Mat 2 2
bézout2Mat zero zero = b .coef₁
bézout2Mat zero one = b .coef₂
bézout2Mat one zero = - (div₂ b)
bézout2Mat one one = div₁ b
module _
(p : ¬ x ≡ 0) where
open Units Ringℤ
private
detEq : det2×2 bézout2Mat · b .gcd ≡ b .gcd
detEq =
helper1 (b .coef₁) (b .coef₂) _ _ _
∙ (λ t → b .coef₁ · divideEq (b .isCD .fst) t + b .coef₂ · divideEq (b .isCD .snd) t)
∙ b .identity
det≡1 : det2×2 bézout2Mat ≡ 1
det≡1 = ·rCancel _ _ _ (detEq ∙ sym (·Lid _)) (¬m≡0→¬gcd≡0 b p)
isInvBézout2Mat : isInv bézout2Mat
isInvBézout2Mat = isInvMat2x2 bézout2Mat (subst (λ r → r ∈ Rˣ) (sym det≡1) RˣContainsOne)
module _
(M : Mat 2 (suc n)) where
private
b = bézout (M zero zero) (M one zero)
bézout2Rows : Mat 2 (suc n)
bézout2Rows zero i = b .coef₁ · M zero i + b .coef₂ · M one i
bézout2Rows one i = - (div₂ b) · M zero i + div₁ b · M one i
bézout2Rows-vanish : bézout2Rows one zero ≡ 0
bézout2Rows-vanish = div·- b
bézout2Rows-div₁ : (n : ℤ) → M zero zero ∣ n → bézout2Rows zero zero ∣ n
bézout2Rows-div₁ n p = subst (λ a → a ∣ n) (sym (b .identity)) (∣-trans (b .isCD .fst) p)
bézout2Rows-div₂ : (n : ℤ) → M one zero ∣ n → bézout2Rows zero zero ∣ n
bézout2Rows-div₂ n p = subst (λ a → a ∣ n) (sym (b .identity)) (∣-trans (b .isCD .snd) p)
bézout2Rows-nonZero : ¬ M zero zero ≡ 0 → ¬ bézout2Rows zero zero ≡ 0
bézout2Rows-nonZero p r =
p (sym (∣-zeroˡ (subst (λ a → a ∣ M zero zero) r (bézout2Rows-div₁ (M zero zero) (∣-refl refl)))))
bézout2Rows-inv : ¬ M zero zero ≡ 0 → M zero zero ∣ M one zero → M zero ≡ bézout2Rows zero
bézout2Rows-inv p q t j =
let (c₁≡1 , c₂≡0) = bézout∣ _ _ p q in
(helper2 (M zero j) (M one j) ∙ (λ t → c₁≡1 (~ t) · M zero j + c₂≡0 (~ t) · M one j)) t
bézout2Rows-commonDiv : (a : ℤ)
→ ((j : Fin (suc n)) → a ∣ M zero j)
→ ((j : Fin (suc n)) → a ∣ M one j)
→ (i : Fin 2)(j : Fin (suc n)) → a ∣ bézout2Rows i j
bézout2Rows-commonDiv a p q zero j = ∣-+ (∣-right· {n = b .coef₁} (p j)) (∣-right· {n = b .coef₂} (q j))
bézout2Rows-commonDiv a p q one j = ∣-+ (∣-right· {n = - (div₂ b)} (p j)) (∣-right· {n = div₁ b} (q j))
module _
(M : Mat (suc m) (suc n)) where
bézoutRows : Mat (suc m) (suc n)
bézoutRows = transRows bézout2Rows M
bézoutRows-vanish : (i : Fin m) → bézoutRows (suc i) zero ≡ 0
bézoutRows-vanish = transRowsIndP' _ (λ v → v zero ≡ 0) bézout2Rows-vanish M
bézoutRows-div₁-helper : (n : ℤ) → M zero zero ∣ n → bézoutRows zero zero ∣ n
bézoutRows-div₁-helper n = transRowsIndP _ (λ v → v zero ∣ n) (λ M → bézout2Rows-div₁ M n) M
bézoutRows-div₂-helper : (n : ℤ) → (i : Fin m) → M (suc i) zero ∣ n → bézoutRows zero zero ∣ n
bézoutRows-div₂-helper n =
transRowsIndPQ' _ (λ v → v zero ∣ n) (λ v → v zero ∣ n)
(λ M → bézout2Rows-div₁ M n) (λ M → bézout2Rows-div₂ M n) M
bézoutRows-div : (i : Fin (suc m)) → bézoutRows zero zero ∣ M i zero
bézoutRows-div zero = bézoutRows-div₁-helper _ (∣-refl refl)
bézoutRows-div (suc i) = bézoutRows-div₂-helper _ i (∣-refl refl)
bézoutRows-nonZero : ¬ M zero zero ≡ 0 → ¬ bézoutRows zero zero ≡ 0
bézoutRows-nonZero p r = p (sym (∣-zeroˡ (subst (λ a → a ∣ M zero zero) r (bézoutRows-div zero))))
bézoutRows-inv : ¬ M zero zero ≡ 0 → ((i : Fin m) → M zero zero ∣ M (suc i) zero) → M zero ≡ bézoutRows zero
bézoutRows-inv = transRowsIndPRelInv _ (λ V → ¬ V zero ≡ 0) (λ U V → U zero ∣ V zero) bézout2Rows-inv M
bézoutRows-commonDiv₀ : (a : ℤ)
→ ((j : Fin (suc n)) → a ∣ M zero j)
→ ((i : Fin m)(j : Fin (suc n)) → a ∣ M (suc i) j)
→ (j : Fin (suc n)) → a ∣ bézoutRows zero j
bézoutRows-commonDiv₀ a =
transRowsIndP₀ _ (λ V → ((j : Fin (suc n)) → a ∣ V j))
(λ N s s' → bézout2Rows-commonDiv N a s s' zero)
(λ N s s' → bézout2Rows-commonDiv N a s s' one) _
bézoutRows-commonDiv₁ : (a : ℤ)
→ ((j : Fin (suc n)) → a ∣ M zero j)
→ ((i : Fin m)(j : Fin (suc n)) → a ∣ M (suc i) j)
→ (i : Fin m)(j : Fin (suc n)) → a ∣ bézoutRows (suc i) j
bézoutRows-commonDiv₁ a =
transRowsIndP₁ _ (λ V → ((j : Fin (suc n)) → a ∣ V j))
(λ N s s' → bézout2Rows-commonDiv N a s s' zero)
(λ N s s' → bézout2Rows-commonDiv N a s s' one) _
bézoutRows-commonDiv :
((i : Fin (suc m))(j : Fin (suc n)) → M zero zero ∣ M i j)
→ (i : Fin (suc m))(j : Fin (suc n)) → M zero zero ∣ bézoutRows i j
bézoutRows-commonDiv p zero = bézoutRows-commonDiv₀ _ (p zero) (p ∘ suc)
bézoutRows-commonDiv p (suc i) = bézoutRows-commonDiv₁ _ (p zero) (p ∘ suc) i
bézoutRows-commonDivInv :
¬ M zero zero ≡ 0
→ ((i : Fin (suc m))(j : Fin (suc n)) → M zero zero ∣ M i j)
→ (i : Fin (suc m))(j : Fin (suc n)) → bézoutRows zero zero ∣ bézoutRows i j
bézoutRows-commonDivInv h p i j =
let inv = (λ t → bézoutRows-inv h (λ i → p (suc i) zero) t zero) in
subst (_∣ bézoutRows i j) inv (bézoutRows-commonDiv p i j)
isLinear2Bézout2Rows : isLinear2×2 (bézout2Rows {n = n})
isLinear2Bézout2Rows .transMat M = bézout2Mat _ _ (bézout (M zero zero) (M one zero))
isLinear2Bézout2Rows .transEq M t zero j = mul2 (isLinear2Bézout2Rows .transMat M) M zero j (~ t)
isLinear2Bézout2Rows .transEq M t one j = mul2 (isLinear2Bézout2Rows .transMat M) M one j (~ t)
isLinearBézoutRows : isLinear (bézoutRows {m = m} {n = n})
isLinearBézoutRows = isLinearTransRows _ isLinear2Bézout2Rows _
isInv2Bézout2Rows : (M : Mat 2 (suc n))(p : ¬ M zero zero ≡ 0) → isInv (isLinear2Bézout2Rows .transMat M)
isInv2Bézout2Rows _ p = isInvBézout2Mat _ _ _ p
isInvBézout2Rows : (M : Mat (suc m) (suc n))(p : ¬ M zero zero ≡ 0) → isInv (isLinearBézoutRows .transMat M)
isInvBézout2Rows = isInvTransRowsInd _ _ (λ V → ¬ V zero ≡ 0) bézout2Rows-nonZero isInv2Bézout2Rows
-- Using Bézout identity to eliminate the first column/row
record RowsImproved (M : Mat (suc m) (suc n)) : Type where
field
sim : Sim M
div : (i : Fin (suc m)) → sim .result zero zero ∣ M i zero
vanish : (i : Fin m) → sim .result (suc i) zero ≡ 0
nonZero : ¬ sim .result zero zero ≡ 0
record ColsImproved (M : Mat (suc m) (suc n)) : Type where
field
sim : Sim M
div : (j : Fin (suc n)) → sim .result zero zero ∣ M zero j
vanish : (j : Fin n) → sim .result zero (suc j) ≡ 0
nonZero : ¬ sim .result zero zero ≡ 0
open RowsImproved
open ColsImproved
improveRows : (M : Mat (suc m) (suc n))(p : ¬ M zero zero ≡ 0) → RowsImproved M
improveRows M _ .sim .result = bézoutRows M
improveRows M _ .sim .simrel .transMatL = isLinearBézoutRows .transMat M
improveRows _ _ .sim .simrel .transMatR = 𝟙
improveRows _ _ .sim .simrel .transEq = isLinearBézoutRows .transEq _ ∙ sym (⋆rUnit _)
improveRows _ p .sim .simrel .isInvTransL = isInvBézout2Rows _ p
improveRows _ p .sim .simrel .isInvTransR = isInv𝟙
improveRows _ _ .div = bézoutRows-div _
improveRows _ _ .vanish = bézoutRows-vanish _
improveRows M p .nonZero = bézoutRows-nonZero M p
improveCols : (M : Mat (suc m) (suc n))(p : ¬ M zero zero ≡ 0) → ColsImproved M
improveCols M _ .sim .result = (bézoutRows (M ᵗ))ᵗ
improveCols _ _ .sim .simrel .transMatL = 𝟙
improveCols M _ .sim .simrel .transMatR = (isLinearBézoutRows .transMat (M ᵗ))ᵗ
improveCols M _ .sim .simrel .transEq =
let P = isLinearBézoutRows .transMat (M ᵗ) in
(λ t → (isLinearBézoutRows .transEq (M ᵗ) t)ᵗ)
∙ compᵗ P (M ᵗ)
∙ (λ t → idemᵗ M t ⋆ P ᵗ)
∙ (λ t → ⋆lUnit M (~ t) ⋆ P ᵗ)
improveCols _ _ .sim .simrel .isInvTransL = isInv𝟙
improveCols M p .sim .simrel .isInvTransR =
isInvᵗ {M = isLinearBézoutRows .transMat (M ᵗ)} (isInvBézout2Rows (M ᵗ) p)
improveCols _ _ .div = bézoutRows-div _
improveCols _ _ .vanish = bézoutRows-vanish _
improveCols M p .nonZero = bézoutRows-nonZero (M ᵗ) p
| {
"alphanum_fraction": 0.6135732648,
"avg_line_length": 38.4387351779,
"ext": "agda",
"hexsha": "dc86af51e544944ab4d276babe9df100f95d64ae",
"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": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Algebra/IntegerMatrix/Elementaries.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"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": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Algebra/IntegerMatrix/Elementaries.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Algebra/IntegerMatrix/Elementaries.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3900,
"size": 9725
} |
postulate
A : Set
_+_ : A → A → A
f₁ : A → A → A
f₁ x y = {!_+ x!} -- ? + x
f₂ : A → A → A
f₂ x y = {!x +_!} -- x + ?
f₃ : A → A → A
f₃ x = {!_+ x!} -- λ section → section + x
f₄ : A → A → A
f₄ x y = {!λ z → z + x!} -- ? + x
f₅ : A → A → A
f₅ x y = {!λ a b → b + x!} -- ? + x
f₆ : A → A → A
f₆ x y = {!λ a → a + (a + x)!} -- (λ a → a + (a + x)) ?
f₇ : A → A → A
f₇ x y = {!λ a → x + (y + a)!} -- x + (y + ?)
f₈ : A → A → A
f₈ x = {!λ a b → a + b!} -- λ b → ? + b
| {
"alphanum_fraction": 0.3064182195,
"avg_line_length": 16.6551724138,
"ext": "agda",
"hexsha": "f192015acf7cadcbfcc3733f08b25fa6545e61b2",
"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/interaction/Issue1541a.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/interaction/Issue1541a.agda",
"max_line_length": 55,
"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/interaction/Issue1541a.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": 274,
"size": 483
} |
open import Relation.Binary hiding (_⇒_)
module Experiments.Category {ℓ₁ ℓ₂ ℓ₃} (APO : Preorder ℓ₁ ℓ₂ ℓ₃) where
open import Level
open Preorder APO renaming (_∼_ to _≤_)
open import Function as Fun using (flip)
open import Relation.Unary using (Pred)
open import Data.Product as Prod using (_,_; _×_)
open import Relation.Binary.PropositionalEquality as PEq using (_≡_; cong)
open PEq.≡-Reasoning
open import Function.Inverse using (Inverse)
open import Algebra.FunctionProperties
record IsMP {ℓ}(P : Pred Carrier ℓ) : Set (ℓ ⊔ ℓ₁ ⊔ ℓ₃) where
field
monotone : ∀ {c c'} → c ≤ c' → P c → P c'
monotone-refl : ∀ {c} p → monotone (refl {c}) p PEq.≡ p
monotone-trans : ∀ {c c' c''} p (c~c' : c ≤ c')(c'~c'' : c' ≤ c'') →
monotone (trans c~c' c'~c'') p
PEq.≡
monotone c'~c'' (monotone c~c' p)
-- monotone predicates over a fixed carrier
record MP ℓ : Set (suc ℓ ⊔ ℓ₁ ⊔ ℓ₃) where
constructor mp
field
pred : Pred Carrier ℓ
is-mp : IsMP pred
open IsMP is-mp public
MP₀ = MP zero
-- application
_·_ : ∀ {ℓ} → MP ℓ → Carrier → Set _
(mp P _) · c = P c
-- monotone-predicate equality
_≗_ : ∀ {ℓ₁} → MP ℓ₁ → MP ℓ₁ → Set _
P ≗ Q = ∀ {c} → P · c PEq.≡ Q · c
import Data.Unit as Unit
Const : ∀ {ℓ}(P : Set ℓ) → MP ℓ
Const P = mp (λ _ → P) (record {
monotone = λ x p → p ;
monotone-refl = λ p → PEq.refl ;
monotone-trans = λ p c~c' c'~c'' → PEq.refl
})
⊤ : MP zero
⊤ = Const Unit.⊤
-- we package the Agda function that represents morphisms
-- in this category in a record such that P ⇒ Q doesn't get
-- reduced to the simple underlying type of `apply`
infixl 30 _⇒_
record _⇒_ {p q}(P : MP p)(Q : MP q) : Set (p ⊔ q ⊔ ℓ₁ ⊔ ℓ₃) where
constructor mk⇒
field
apply : ∀ {c} → P · c → Q · c
monotone-comm : ∀ {c c'}(c~c' : c ≤ c'){p : P · c} →
apply {c'} (MP.monotone P c~c' p) PEq.≡ MP.monotone Q c~c' (apply p)
open _⇒_ public
-- Const identifies objects that are terminal for this category
terminal : ∀ {ℓ a}{A : Set a}{P : MP ℓ} → A → P ⇒ Const A
terminal x = mk⇒ (λ _ → x) λ c~c' → λ {p} → PEq.refl
infixl 100 _∘_
_∘_ : ∀ {ℓ₁ ℓ₂ ℓ₃}{P : MP ℓ₁}{Q : MP ℓ₂}{R : MP ℓ₃} → Q ⇒ R → P ⇒ Q → P ⇒ R
_∘_ {P = P}{Q}{R} F G = mk⇒
(λ p → apply F (apply G p))
(λ c~c' →
begin _
≡⟨ PEq.cong (λ e → apply F e) (monotone-comm G c~c') ⟩
apply F (MP.monotone Q c~c' (apply G _))
≡⟨ monotone-comm F c~c' ⟩
_ ∎
)
id : ∀ {ℓ}(P : MP ℓ) → P ⇒ P
id P = mk⇒ Fun.id (λ _ → PEq.refl)
-- morphism equality
infixl 20 _⇒≡_
_⇒≡_ : ∀ {ℓ₁ ℓ₂}{P : MP ℓ₁}{Q : MP ℓ₂}(F G : P ⇒ Q) → Set _
_⇒≡_ {P = P}{Q} F G = ∀ {c}(p : P · c) → apply F p PEq.≡ apply G p
-- extensionality for morphisms
-- This should be provable from proof-irrelevance + extensionality.
⇒-Ext : ∀ (ℓ₁ ℓ₂ : Level) → Set _
⇒-Ext ℓ₁ ℓ₂ = ∀ {P : MP ℓ₁}{Q : MP ℓ₂}{F G : P ⇒ Q} → F ⇒≡ G → F PEq.≡ G
-- isomorphism
record _≅_ {ℓ}(P Q : MP ℓ) : Set (ℓ₁ ⊔ ℓ ⊔ ℓ₃) where
field
to : P ⇒ Q
from : Q ⇒ P
left-inv : to ∘ from ⇒≡ id Q
right-inv : from ∘ to ⇒≡ id P
∘-assoc : ∀ {p q r s}{P : MP p}{Q : MP q}{R : MP r}{S : MP s}
{F : R ⇒ S}{G : Q ⇒ R}{H : P ⇒ Q} →
F ∘ (G ∘ H) ⇒≡ (F ∘ G) ∘ H
∘-assoc _ = PEq.refl
∘-left-id : ∀ {P Q : MP ℓ₁}{F : P ⇒ Q} → (id Q) ∘ F ⇒≡ F
∘-left-id _ = PEq.refl
∘-right-id : ∀ {P Q : MP ℓ₁}{F : P ⇒ Q} → F ∘ (id P) ⇒≡ F
∘-right-id p = PEq.refl
module Product where
-- within the category
infixl 40 _⊗_
_⊗_ : ∀ {ℓ₁ ℓ₂} → MP ℓ₁ → MP ℓ₂ → MP (ℓ₁ ⊔ ℓ₂)
P ⊗ Q = mp
(λ c → (P · c) × (Q · c))
(record {
monotone = λ{ c~c' (p , q) →
MP.monotone P c~c' p
, MP.monotone Q c~c' q
};
monotone-refl = λ _ → PEq.cong₂ _,_ (MP.monotone-refl P _) (MP.monotone-refl Q _) ;
monotone-trans = λ _ _ _ → PEq.cong₂ _,_ (MP.monotone-trans P _ _ _) (MP.monotone-trans Q _ _ _)
})
⟨_,_⟩ : ∀ {y p q}{Y : MP y}{P : MP p}{Q : MP q} → Y ⇒ P → Y ⇒ Q → Y ⇒ P ⊗ Q
⟨ F , G ⟩ = mk⇒
(λ x → apply F x , apply G x)
(λ c~c' → PEq.cong₂ _,_ (monotone-comm F c~c') (monotone-comm G c~c'))
π₁ : ∀ {ℓ₁ ℓ₂}{P : MP ℓ₁}{Q : MP ℓ₂} → P ⊗ Q ⇒ P
π₁ = mk⇒ (λ{ (pc , qc) → pc}) (λ c~c' → PEq.refl)
π₂ : ∀ {ℓ₁ ℓ₂}{P : MP ℓ₁}{Q : MP ℓ₂} → P ⊗ Q ⇒ Q
π₂ = mk⇒ (λ{ (pc , qc) → qc}) (λ c~c' → PEq.refl)
swap : ∀ {ℓ₁ ℓ₂}(P : MP ℓ₁)(Q : MP ℓ₂) → P ⊗ Q ⇒ Q ⊗ P
swap _ _ = mk⇒ Prod.swap λ c~c' → PEq.refl
comm : ∀ {ℓ₁ ℓ₂ ℓ₃}(P : MP ℓ₁)(Q : MP ℓ₂)(R : MP ℓ₃) → (P ⊗ Q) ⊗ R ⇒ P ⊗ (Q ⊗ R)
comm _ _ _ = mk⇒
(λ{ ((p , q) , r) → p , (q , r) })
(λ c~c' → PEq.refl)
xmap : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄}{P : MP ℓ₁}{Q : MP ℓ₂}{R : MP ℓ₃}{S : MP ℓ₄} →
(F : P ⇒ R)(G : Q ⇒ S) → P ⊗ Q ⇒ R ⊗ S
xmap F G = ⟨ F ∘ π₁ , G ∘ π₂ ⟩
uncurry₁ : ∀ {ℓ₁ ℓ₂ ℓ₃}{A : Set ℓ₁}{P : MP ℓ₂}{Q : MP ℓ₃} →
(A → P ⇒ Q) → (Const A ⊗ P ⇒ Q)
uncurry₁ {A = A}{P}{Q} f = mk⇒
(λ{ (a , p) → apply (f a) p })
(λ{ c~c' {a , p} → monotone-comm (f a) c~c' })
module ⊗-Properties where
π₁-comm : ∀ {y p q}{Y : MP y}{P : MP p}{Q : MP q}{F : Y ⇒ P}{G : Y ⇒ Q} →
π₁ ∘ ⟨ F , G ⟩ ⇒≡ F
π₁-comm _ = PEq.refl
π₂-comm : ∀ {y p q}{Y : MP y}{P : MP p}{Q : MP q}{F : Y ⇒ P}{G : Y ⇒ Q} →
π₂ ∘ ⟨ F , G ⟩ ⇒≡ G
π₂-comm _ = PEq.refl
unique : ∀ {y p q}{Y : MP y}{P : MP p}{Q : MP q}{g : Y ⇒ (P ⊗ Q)} → ⟨ π₁ ∘ g , π₂ ∘ g ⟩ ⇒≡ g
unique _ = PEq.refl
module Forall (funext : ∀ {a b} → PEq.Extensionality a b) where
-- ∀-quantification over Set
Forall : ∀ {ℓ₁ ℓ₂}{I : Set ℓ₁}(P : I → MP ℓ₂) → MP _
Forall {I = I} P = mp
(λ c → ∀ (i : I) → P i · c)
(record {
monotone = λ x x₁ i → MP.monotone (P i) x (x₁ i) ;
monotone-refl = λ p → funext λ i → MP.monotone-refl (P i) (p i) ;
monotone-trans = λ p c~c' c'~c'' → funext λ i → MP.monotone-trans (P i) (p i) c~c' c'~c'' })
module ListAll where
-- quantification over the elements in a list
open import Data.Nat
open import Data.List
import Data.List.All as All
open import Data.List.All.Properties
open import Data.List.All.Properties.Extra
module _ {a p} {A : Set a} {P : A → Set p} where
map-id' : ∀ {xs} (pxs : All.All P xs) → All.map {P = P} {Q = P} (λ x → x) pxs ≡ pxs
map-id' All.[] = PEq.refl
map-id' (px All.∷ pxs) = cong (px All.∷_) (map-id' pxs)
All : ∀ {ℓ₁}{I : Set ℓ₁}(P : I → MP ℓ₂) → List I → MP _
All P xs = mp
(λ c → All.All (λ x → P x · c) xs)
(record {
monotone = λ c~c' ps → All.map (λ {i} x → MP.monotone (P i) c~c' x ) ps ;
monotone-refl = λ p → (begin
All.map (λ {i} x → MP.monotone (P i) refl x) p
≡⟨ map-cong p (λ {i} px → MP.monotone-refl (P i) px) ⟩
All.map (λ x → x) p
≡⟨ map-id' p ⟩
p ∎) ;
monotone-trans = λ p c~c' c'~c'' → (begin
All.map (λ {i} x → MP.monotone (P i) (trans c~c' c'~c'') x) p
≡⟨ map-cong p (λ {i} p → MP.monotone-trans (P i) p c~c' c'~c'') ⟩
All.map (λ {i} x → MP.monotone (P i) c'~c'' (MP.monotone (P i) c~c' x)) p
≡⟨ PEq.sym (map-map p) ⟩
All.map (λ {i} x → MP.monotone (P i) c'~c'' x) (All.map (λ {i} x → MP.monotone (P i) c~c' x) p)
∎) })
module Exists where
-- ∃-quantification over Set
Exists : ∀ {ℓ₁ ℓ₂}{I : Set ℓ₁}(P : I → MP ℓ₂) → MP _
Exists {I = I} P = mp (λ x → Prod.∃ λ (i : I) → P i · x) (record {
monotone = λ{ c~c' (i , px) → i , MP.monotone (P i) c~c' px } ;
monotone-refl = λ{
(i , px) → PEq.cong (λ u → i , u) (MP.monotone-refl (P i) px) };
monotone-trans = (λ {
(i , px) p q → PEq.cong (λ u → i , u) (MP.monotone-trans (P i) px p q)})
})
elim : ∀ {ℓ₁ ℓ₂ ℓ₃}{I : Set ℓ₁}{P : I → MP ℓ₂}{Q : MP ℓ₃} →
(∀ {i} → P i ⇒ Q) → Exists P ⇒ Q
elim {P = P}{Q} F = mk⇒
(λ{ (i , pi) → apply F pi})
(λ{ c~c' {(i , pi)} → monotone-comm F c~c' })
open Product
∃-⊗-comm : ∀ {ℓ₁ ℓ₂ ℓ₃}{I : Set ℓ₁}(P : I → MP ℓ₂)(Q : MP ℓ₃) →
Exists (λ i → P i) ⊗ Q ⇒ Exists (λ i → P i ⊗ Q)
∃-⊗-comm _ _ = mk⇒
(λ{ ((i , pi) , q) → (i , pi , q)})
(λ c~c' → PEq.refl)
module Monoid where
-- identifies _⊗_ as a tensor/monoidal product
open Product
-- associator
assoc : ∀ {p q r}{P : MP p}{Q : MP q}{R : MP r} → (P ⊗ Q) ⊗ R ≅ P ⊗ (Q ⊗ R)
assoc = record {
to = mk⇒ (λ{ ((p , q) , r) → p , (q , r) }) (λ c~c' → PEq.refl) ;
from = mk⇒ (λ{ (p , (q , r)) → (p , q) , r }) (λ c~c' → PEq.refl) ;
left-inv = λ _ → PEq.refl ;
right-inv = λ _ → PEq.refl }
-- left unitor
⊗-left-id : ∀ {p}{P : MP p} → ⊤ ⊗ P ≅ P
⊗-left-id = record {
to = π₂ {P = ⊤} ;
from = ⟨ mk⇒ (λ x → Unit.tt) (λ c~c' → PEq.refl) , id _ ⟩ ;
left-inv = λ p → PEq.refl ;
right-inv = λ p → PEq.refl }
-- right unitor
⊗-right-id : ∀ {p}{P : MP p} → P ⊗ ⊤ ≅ P
⊗-right-id = record {
to = π₁ {Q = ⊤} ;
from = ⟨ mk⇒ (λ {c} z → z) (λ c~c' → PEq.refl) , mk⇒ (λ {c} _ → Unit.tt) (λ c~c' → PEq.refl) ⟩ ;
left-inv = λ p → PEq.refl ;
right-inv = λ p → PEq.refl }
-- TODO: coherence conditions
module Exponential
(trans-assoc : ∀ {c c' c'' c'''}{p : c ≤ c'}{q : c' ≤ c''}{r : c'' ≤ c'''} →
trans (trans p q) r PEq.≡ trans p (trans q r))
(trans-refl₁ : ∀ {c c'}{p : c ≤ c'} → trans refl p PEq.≡ p)
(trans-refl₂ : ∀ {c c'}{p : c ≤ c'} → trans p refl PEq.≡ p)
where
-- for convencience we assume extensionality for morphisms here for now
postulate ⇒-ext : ∀ {ℓ₁ ℓ₂} → ⇒-Ext ℓ₁ ℓ₂
open Product
-- the preorder that we have defined monotonicity by is itself
-- a monotone predicate
≤mono : Carrier → MP _
≤mono c = mp (λ c' → c ≤ c' ) (record {
monotone = flip trans ;
monotone-refl = λ _ → trans-refl₂ ;
monotone-trans = λ _ _ _ → PEq.sym trans-assoc })
-- ... such that we can define the notion of a monotone function as follows:
Mono⇒ : ∀ {ℓ ℓ₂}(P : MP ℓ)(Q : MP ℓ₂)(c : Carrier) → Set _
Mono⇒ P Q c = ≤mono c ⊗ P ⇒ Q
-- the intuition here comes from the naive interpretation
-- of the type of curry: (X ⊗ P ⇒ Q) → X ⇒ (Const (P ⇒ Q)).
-- unfolding the return type you would get something like the following Agda type:
-- ∀ c → X · c → (∀ c' → P · c' → Q · c')
-- this is too weak, because c' and c are unrelated and thus we can't combine
-- X · c and P · c' into a product (X ⊗ P) · c'.
-- The above Mono⇒ fixes this by simply requiring the relation c ≤ c' as
-- an additional argument.
infixl 80 _^_
_^_ : ∀ {ℓ₁ ℓ₂}(Q : MP ℓ₁)(P : MP ℓ₂) → MP _
Q ^ P = mp
(Mono⇒ P Q)
(record {
monotone = λ c~c' φ →
mk⇒
(λ p → apply φ (trans c~c' (Prod.proj₁ p) , Prod.proj₂ p))
(λ{ c~c'' {w , p} → (begin
apply φ (trans c~c' (MP.monotone (≤mono _) c~c'' w) , (MP.monotone P c~c'' p))
≡⟨ PEq.cong (λ u → apply φ (u , MP.monotone P c~c'' p)) (PEq.sym trans-assoc) ⟩
apply φ (MP.monotone (≤mono _ ⊗ P) c~c'' (trans c~c' w , p))
≡⟨ monotone-comm φ c~c'' ⟩
MP.monotone Q c~c'' (apply φ (trans c~c' w , p))
∎)});
monotone-refl = λ φ → ⇒-ext (λ p → PEq.cong (λ u → apply φ (u , (Prod.proj₂ p))) trans-refl₁);
monotone-trans = λ φ w₀ w₁ → ⇒-ext λ p → PEq.cong (λ u → apply φ (u , Prod.proj₂ p)) trans-assoc
})
curry : ∀ {ℓ₁ ℓ₂ ℓ₃}{X : MP ℓ₁}{Y : MP ℓ₂}{Z : MP ℓ₃}(F : (X ⊗ Y) ⇒ Z) → X ⇒ (Z ^ Y)
curry {X = X}{Y}{Z} F = mk⇒
(λ xc → mk⇒
(λ{ (w , yc) → apply F ((MP.monotone X w xc) , yc)})
(λ{ c~c' {w , yc} → (begin
apply F (MP.monotone X (trans w c~c') xc , MP.monotone Y c~c' yc)
≡⟨ PEq.cong (λ u → apply F (u , _)) (MP.monotone-trans X xc w c~c') ⟩
apply F (MP.monotone X c~c' (MP.monotone X w xc) , MP.monotone Y c~c' yc)
≡⟨ monotone-comm F c~c' ⟩
MP.monotone Z c~c' (apply F (MP.monotone X w xc , yc))
∎ )}))
λ c~c' {xc} → ⇒-ext λ p →
PEq.cong (λ u → apply F (u , _)) (PEq.sym (MP.monotone-trans X xc c~c' (Prod.proj₁ p)))
ε : ∀ {ℓ₁ ℓ₂}{Y : MP ℓ₁}{Z : MP ℓ₂} → (Z ^ Y) ⊗ Y ⇒ Z
ε {Y = Y}{Z} = mk⇒
(λ zʸ×y → apply (Prod.proj₁ zʸ×y) (refl , Prod.proj₂ zʸ×y) )
λ{ c~c' {φ@(F , p)} → (begin
(apply F (trans c~c' refl , MP.monotone Y c~c' p))
≡⟨ PEq.cong (λ u → apply F (u , _)) trans-refl₂ ⟩
(apply F (c~c' , MP.monotone Y c~c' p))
≡⟨ PEq.sym (PEq.cong (λ u → apply F (u , _)) trans-refl₁) ⟩
(apply F (trans refl c~c' , MP.monotone Y c~c' p))
≡⟨ PEq.refl ⟩
(apply F (MP.monotone (≤mono _ ⊗ Y) c~c' (refl , p)))
≡⟨ monotone-comm F c~c' ⟩
MP.monotone Z c~c' (apply F (refl , p))
∎ )}
uncurry : ∀ {ℓ₁ ℓ₂ ℓ₃}{X : MP ℓ₁}{Y : MP ℓ₂}{Z : MP ℓ₃}(F : X ⇒ (Z ^ Y)) → (X ⊗ Y) ⇒ Z
uncurry {X = x}{Y}{Z} F = ε ∘ xmap F (id Y)
module Sum where
open import Data.Sum as Sum using (_⊎_)
infixl 30 _⊕_
_⊕_ : ∀ {ℓ₁ ℓ₂} → MP ℓ₁ → MP ℓ₂ → MP (ℓ₁ ⊔ ℓ₂)
P ⊕ Q = mp
(λ c → (P · c) ⊎ (Q · c))
(record {
monotone = λ{
c≤c' (Sum.inj₁ p) → Sum.inj₁ (MP.monotone P c≤c' p) ;
c≤c' (Sum.inj₂ q) → Sum.inj₂ (MP.monotone Q c≤c' q)
} ;
monotone-refl = λ{
(Sum.inj₁ p) → PEq.cong Sum.inj₁ (MP.monotone-refl P p) ;
(Sum.inj₂ q) → PEq.cong Sum.inj₂ (MP.monotone-refl Q q) };
monotone-trans = λ{
(Sum.inj₁ p) c≤c' c'≤c'' → PEq.cong Sum.inj₁ (MP.monotone-trans P p c≤c' c'≤c'') ;
(Sum.inj₂ q) c≤c' c'≤c'' → PEq.cong Sum.inj₂ (MP.monotone-trans Q q c≤c' c'≤c'') }
})
-- canonical injections
inj₁ : ∀ {ℓ₁ ℓ₂}{P : MP ℓ₁}(Q : MP ℓ₂) → P ⇒ (P ⊕ Q)
inj₁ Q = mk⇒ Sum.inj₁ λ c~c' → PEq.refl
inj₂ : ∀ {ℓ₁ ℓ₂}(P : MP ℓ₁){Q : MP ℓ₂} → Q ⇒ (P ⊕ Q)
inj₂ Q = mk⇒ Sum.inj₂ λ c~c' → PEq.refl
[_,_] : ∀ {ℓ₁ ℓ₂ ℓ₃}{P : MP ℓ₁}{Q : MP ℓ₂}{R : MP ℓ₃} → P ⇒ R → Q ⇒ R → (P ⊕ Q) ⇒ R
[_,_] F G = mk⇒
(λ{ (Sum.inj₁ x) → apply F x ; (Sum.inj₂ y) → apply G y})
(λ{
c~c' {Sum.inj₁ x} → monotone-comm F c~c' ;
c~c' {Sum.inj₂ y} → monotone-comm G c~c'
})
-- TODO [_,_] is unique
[g,*]∘inj₁ : ∀ {ℓ₁ ℓ₂ ℓ₃}{P : MP ℓ₁}{Q : MP ℓ₂}{R : MP ℓ₃} → (F : P ⇒ R)(G : Q ⇒ R) → [ F , G ] ∘ inj₁ _ ⇒≡ F
[g,*]∘inj₁ F G p = PEq.refl
[*,g]∘inj₂ : ∀ {ℓ₁ ℓ₂ ℓ₃}{P : MP ℓ₁}{Q : MP ℓ₂}{R : MP ℓ₃} → (F : P ⇒ R)(G : Q ⇒ R) → [ F , G ] ∘ inj₂ _ ⇒≡ G
[*,g]∘inj₂ F G p = PEq.refl
| {
"alphanum_fraction": 0.4865680017,
"avg_line_length": 35.4651741294,
"ext": "agda",
"hexsha": "09ac02cb65805cb4e5a240abc2d6204fb364aef7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/Experiments/Category.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/Experiments/Category.agda",
"max_line_length": 111,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/Experiments/Category.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 6524,
"size": 14257
} |
{-# OPTIONS --safe #-}
{-
Successor structures for spectra, chain complexes and fiber sequences.
This is an idea from Floris van Doorn's phd thesis.
-}
module Cubical.Structures.Successor where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Int
open import Cubical.Data.Nat
private
variable
ℓ : Level
record SuccStr (ℓ : Level) : Type (ℓ-suc ℓ) where
field
Index : Type ℓ
succ : Index → Index
open SuccStr
ℤ+ : SuccStr ℓ-zero
ℤ+ .Index = ℤ
ℤ+ .succ = sucℤ
ℕ+ : SuccStr ℓ-zero
ℕ+ .Index = ℕ
ℕ+ .succ = suc
| {
"alphanum_fraction": 0.6958105647,
"avg_line_length": 18.3,
"ext": "agda",
"hexsha": "ce72551c60ae90926f65da9b61a3e195e9d5ca81",
"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/Structures/Successor.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/Structures/Successor.agda",
"max_line_length": 72,
"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/Structures/Successor.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": 180,
"size": 549
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Sums (disjoint unions)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Sum.Base where
open import Data.Bool.Base using (true; false)
open import Function.Base using (_∘_; _-[_]-_ ; id)
open import Relation.Nullary.Reflects using (invert)
open import Relation.Nullary using (Dec; yes; no; _because_; ¬_)
open import Level using (Level; _⊔_)
private
variable
a b c d : Level
A : Set a
B : Set b
C : Set c
D : Set d
------------------------------------------------------------------------
-- Definition
infixr 1 _⊎_
data _⊎_ (A : Set a) (B : Set b) : Set (a ⊔ b) where
inj₁ : (x : A) → A ⊎ B
inj₂ : (y : B) → A ⊎ B
------------------------------------------------------------------------
-- Functions
[_,_] : ∀ {C : A ⊎ B → Set c} →
((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) →
((x : A ⊎ B) → C x)
[ f , g ] (inj₁ x) = f x
[ f , g ] (inj₂ y) = g y
[_,_]′ : (A → C) → (B → C) → (A ⊎ B → C)
[_,_]′ = [_,_]
fromInj₁ : (B → A) → A ⊎ B → A
fromInj₁ = [ id ,_]′
fromInj₂ : (A → B) → A ⊎ B → B
fromInj₂ = [_, id ]′
swap : A ⊎ B → B ⊎ A
swap (inj₁ x) = inj₂ x
swap (inj₂ x) = inj₁ x
map : (A → C) → (B → D) → (A ⊎ B → C ⊎ D)
map f g = [ inj₁ ∘ f , inj₂ ∘ g ]
map₁ : (A → C) → (A ⊎ B → C ⊎ B)
map₁ f = map f id
map₂ : (B → D) → (A ⊎ B → A ⊎ D)
map₂ = map id
infixr 1 _-⊎-_
_-⊎-_ : (A → B → Set c) → (A → B → Set d) → (A → B → Set (c ⊔ d))
f -⊎- g = f -[ _⊎_ ]- g
-- Conversion back and forth with Dec
fromDec : Dec A → A ⊎ ¬ A
fromDec ( true because [p]) = inj₁ (invert [p])
fromDec (false because [¬p]) = inj₂ (invert [¬p])
toDec : A ⊎ ¬ A → Dec A
toDec (inj₁ p) = yes p
toDec (inj₂ ¬p) = no ¬p
| {
"alphanum_fraction": 0.4209378408,
"avg_line_length": 23.5128205128,
"ext": "agda",
"hexsha": "3365c88653a898f917609b309b2adf805fd7d214",
"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": "agda-stdlib/src/Data/Sum/Base.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": "agda-stdlib/src/Data/Sum/Base.agda",
"max_line_length": 72,
"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": "agda-stdlib/src/Data/Sum/Base.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": 698,
"size": 1834
} |
------------------------------------------------------------------------
-- Localisation
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- Following "Modalities in Homotopy Type Theory" by Rijke, Shulman
-- and Spitters.
-- The module is parametrised by a notion of equality. The higher
-- constructors of the HIT defining localisation use path equality,
-- but the supplied notion of equality is used for many other things.
import Equality.Path as P
module Localisation
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Prelude as P
open import Bijection equality-with-J using (_↔_)
open import Equality.Path.Isomorphisms eq hiding (ext)
open import Pushout eq as Pushout using (Pushout)
private
variable
a b c p q r : Level
A B C : Type a
P Q R : A → Type p
e f g x y : A
------------------------------------------------------------------------
-- Localisation
-- A first approximation to localisation.
--
-- This is a slight generalisation of the HIT that Rijke et al. call
-- 𝓙: they require all types to live in the same universe.
data Localisation′
{A : Type a} {P : A → Type p} {Q : A → Type q}
(f : ∀ x → P x → Q x) (B : Type b) :
Type (a ⊔ b ⊔ p ⊔ q) where
[_] : B → Localisation′ f B
ext : (P x → Localisation′ f B) →
(Q x → Localisation′ f B)
ext≡ᴾ : ext g (f x y) P.≡ g y
-- A variant of ext≡ᴾ.
ext≡ :
{f : (x : A) → P x → Q x} {g : P x → Localisation′ f B} →
ext g (f x y) ≡ g y
ext≡ = _↔_.from ≡↔≡ ext≡ᴾ
-- Localisation.
Localisation :
{A : Type a} {P : A → Type p} {Q : A → Type q} →
(∀ x → P x → Q x) →
Type b → Type (a ⊔ b ⊔ p ⊔ q)
Localisation {p = p} {q = q} {A = A} {P = P} {Q = Q} f =
Localisation′ f̂
where
P̂ : A ⊎ A → Type (p ⊔ q)
P̂ = P.[ ↑ q ∘ P
, (λ x → Pushout (record { left = f x; right = f x }))
]
Q̂ : A ⊎ A → Type q
Q̂ = P.[ Q , Q ]
f̂ : (x : A ⊎ A) → P̂ x → Q̂ x
f̂ = P.[ (λ x → f x ∘ lower)
, (λ x → Pushout.rec id id (refl ∘ f x))
]
------------------------------------------------------------------------
-- Some eliminators for Localisation′
-- A dependent eliminator, expressed using paths.
record Elimᴾ
{A : Type a} {P : A → Type p} {Q : A → Type q}
(f : ∀ x → P x → Q x) (B : Type b)
(R : Localisation′ f B → Type r) :
Type (a ⊔ b ⊔ p ⊔ q ⊔ r) where
no-eta-equality
field
[]ʳ : ∀ x → R [ x ]
extʳ : (∀ y → R (g y)) → ∀ y → R (ext {x = x} g y)
ext≡ʳ : (h : (y : P x) → R (g y)) →
P.[ (λ i → R (ext≡ᴾ {g = g} {y = y} i)) ] extʳ h (f x y) ≡
h y
open Elimᴾ public
elimᴾ : Elimᴾ f B R → (x : Localisation′ f B) → R x
elimᴾ {f = f} {B = B} {R = R} e = helper
where
module E = Elimᴾ e
helper : (x : Localisation′ f B) → R x
helper [ x ] = E.[]ʳ x
helper (ext g y) = E.extʳ (λ y → helper (g y)) y
helper (ext≡ᴾ {g = g} i) = E.ext≡ʳ (λ y → helper (g y)) i
-- A non-dependent eliminator, expressed using paths.
record Recᴾ
{A : Type a} {P : A → Type p} {Q : A → Type q}
(f : ∀ x → P x → Q x) (B : Type b)
(C : Type c) :
Type (a ⊔ b ⊔ p ⊔ q ⊔ c) where
no-eta-equality
field
[]ʳ : B → C
extʳ : (P x → C) → Q x → C
ext≡ʳ : (g : P x → C) → extʳ g (f x y) P.≡ g y
open Recᴾ public
recᴾ : Recᴾ f B C → Localisation′ f B → C
recᴾ r = elimᴾ λ where
.[]ʳ → R.[]ʳ
.extʳ → R.extʳ
.ext≡ʳ → R.ext≡ʳ
where
module R = Recᴾ r
-- A dependent eliminator.
record Elim
{A : Type a} {P : A → Type p} {Q : A → Type q}
(f : ∀ x → P x → Q x) (B : Type b)
(R : Localisation′ f B → Type r) :
Type (a ⊔ b ⊔ p ⊔ q ⊔ r) where
no-eta-equality
field
[]ʳ : ∀ x → R [ x ]
extʳ : (∀ y → R (g y)) → ∀ y → R (ext {x = x} g y)
ext≡ʳ : (h : (y : P x) → R (g y)) →
subst R (ext≡ {y = y} {g = g}) (extʳ h (f x y)) ≡ h y
open Elim public
elim : Elim f B R → (x : Localisation′ f B) → R x
elim e = elimᴾ λ where
.[]ʳ → E.[]ʳ
.extʳ → E.extʳ
.ext≡ʳ → subst≡→[]≡ ∘ E.ext≡ʳ
where
module E = Elim e
-- A "computation" rule.
elim-ext≡ :
dcong (elim e) (ext≡ {y = y} {g = g}) ≡
Elim.ext≡ʳ e (elim e ∘ g)
elim-ext≡ = dcong-subst≡→[]≡ (refl _)
-- A non-dependent eliminator.
record Rec
{A : Type a} {P : A → Type p} {Q : A → Type q}
(f : ∀ x → P x → Q x) (B : Type b)
(C : Type c) :
Type (a ⊔ b ⊔ p ⊔ q ⊔ c) where
no-eta-equality
field
[]ʳ : B → C
extʳ : (P x → C) → Q x → C
ext≡ʳ : (g : P x → C) → extʳ g (f x y) ≡ g y
open Rec public
rec : Rec f B C → Localisation′ f B → C
rec r = recᴾ λ where
.[]ʳ → R.[]ʳ
.extʳ → R.extʳ
.ext≡ʳ → _↔_.to ≡↔≡ ∘ R.ext≡ʳ
where
module R = Rec r
-- A "computation" rule.
rec-ext≡ :
{f : ∀ x → P x → Q x}
{r : Rec f B C}
{g : P x → Localisation′ f B} →
cong (rec r) (ext≡ {y = y} {g = g}) ≡
Rec.ext≡ʳ r (rec r ∘ g)
rec-ext≡ = cong-≡↔≡ (refl _)
| {
"alphanum_fraction": 0.4679399727,
"avg_line_length": 26.1785714286,
"ext": "agda",
"hexsha": "76008549b39be5412276a812ad2c94cf02613d56",
"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": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Localisation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"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/equality",
"max_issues_repo_path": "src/Localisation.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Localisation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 2059,
"size": 5131
} |
-- Andreas, 2015-03-17
open import Common.Size
data ⊥ : Set where
data D (i : Size) : Set where
c : Size< i → D i
-- This definition of size predecessor should be forbidden...
module _ (i : Size) where
postulate
pred : Size< i
-- ...otherwise the injectivity test loops here.
iter : ∀ i → D i → ⊥
iter i (c j) = iter j (c (pred j))
loop : Size → ⊥
loop i = iter i (c (pred i))
absurd : ⊥
absurd = FIXME loop ∞
-- Testcase temporarily mutilated, original error
-- -Issue1428c.agda:13,5-19
-- -We don't like postulated sizes in parametrized modules.
-- +Issue1428c.agda:23,10-15
-- +Not in scope:
-- + FIXME at Issue1428c.agda:23,10-15
-- +when scope checking FIXME
| {
"alphanum_fraction": 0.6563876652,
"avg_line_length": 21.28125,
"ext": "agda",
"hexsha": "88ac3f4549a56b9296e508f57ab301d06060e83f",
"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/Fail/Issue1428c.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Fail/Issue1428c.agda",
"max_line_length": 61,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/Issue1428c.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": 228,
"size": 681
} |
module DeMorgan where
open import Definitions
deMorgan : {A B : Set} → ¬ A ∧ ¬ B → ¬ (A ∨ B)
deMorgan = {!!}
| {
"alphanum_fraction": 0.5803571429,
"avg_line_length": 14,
"ext": "agda",
"hexsha": "cc90ca4b51dd94b27cbe3c53708aa5d32f3fbd29",
"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": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "danr/agder",
"max_forks_repo_path": "problems/DeMorgan/DeMorgan.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"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": "danr/agder",
"max_issues_repo_path": "problems/DeMorgan/DeMorgan.agda",
"max_line_length": 46,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "danr/agder",
"max_stars_repo_path": "problems/DeMorgan/DeMorgan.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-17T12:07:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-17T12:07:03.000Z",
"num_tokens": 40,
"size": 112
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.