Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --prop --rewriting #-}
module Examples.Gcd.Clocked where
open import Calf.CostMonoid
import Calf.CostMonoids as CM
open import Calf CM.ℕ-CostMonoid
open import Calf.Types.Nat
open import Data.Nat using (_≤_; z≤n)
open import Calf.Types.Unit
open import Calf.Types.Bounded CM.ℕ-CostMonoid
open import Calf.Types.BoundedFunction CM.ℕ-CostMonoid
open import Data.Nat.DivMod
open import Relation.Binary.PropositionalEquality as P
open import Data.Product
open import Examples.Gcd.Euclid
{- Alternative definition of gcd with an explicit clock parameter.
It is easier to see the computational behavior of the code in this version:
1) when the clock is nonzero: the algorithm proceeds as normal
2) clock is zero: algorithm terminates
Crucially, if the recursor is by-name, then the value of the clock does not
affect asymptotic behavior of the algorithm.
Two things one can do in calf:
1) give a good characterization of the clock in terms of the input by refining the raw recurrence (see Refine.agda)
2) give a good characterization for of the clock for running the code; this usually
means finding a clock computation that is simpler to compute
than the "good" upperbound. For gcd, one can reuse the argument as the clock (see Spec.agda)
-}
gcd/clocked : cmp (Π nat λ _ → Π gcd/i λ _ → F nat)
gcd/clocked zero (x , y , h) = ret x
gcd/clocked (suc k) (x , 0 , h) = ret {nat} x
gcd/clocked (suc k) (x , suc y , h) =
bind {mod-tp x (suc y) triv} (F nat) (mod x (suc y) triv)
λ { (z , eqn2) →
let h2 = P.subst (λ k → suc k ≤ suc y) (P.sym eqn2) (m%n<n' x _ triv) in
gcd/clocked k (suc y , z , h2) }
gcd : cmp (Π gcd/i λ _ → F nat)
gcd i = gcd/clocked (gcd/depth i) i
-- cost of clocked gcd is bounded by for any (not necessarily safe)
-- instantiation of the clock
gcd/clocked≤gcd/depth : ∀ k i → IsBounded nat (gcd/clocked k i) (gcd/depth i)
gcd/clocked≤gcd/depth zero i = bound/relax (λ _ → z≤n) bound/ret
gcd/clocked≤gcd/depth (suc k) (x , zero , h) = bound/ret
gcd/clocked≤gcd/depth (suc k) (x , suc y , h) rewrite gcd/depth-unfold-suc {x} {y} {h} =
bound/step 1 _ (gcd/clocked≤gcd/depth k (suc y , x % suc y , m%n<n' x _ triv))
gcd≤gcd/depth : ∀ i → IsBounded nat (gcd i) (gcd/depth i)
gcd≤gcd/depth i = gcd/clocked≤gcd/depth (gcd/depth i) i
gcd/bounded : cmp (Ψ gcd/i (λ { _ → nat }) gcd/depth)
gcd/bounded = gcd , gcd≤gcd/depth
|
{
"alphanum_fraction": 0.70041841,
"avg_line_length": 41.2068965517,
"ext": "agda",
"hexsha": "606ccf084ac3a6367d476f5baab9762631562835",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Examples/Gcd/Clocked.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Examples/Gcd/Clocked.agda",
"max_line_length": 118,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Examples/Gcd/Clocked.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 788,
"size": 2390
}
|
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LeibnizEquality where
------------------------------------------------------------------------------
-- The identity type.
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
-- Leibniz equality (see [Luo 1994, sec. 5.1.3])
-- (From Agda/examples/lib/Logic/Leibniz.agda)
_≐_ : {A : Set} → A → A → Set₁
x ≐ y = (P : _ → Set) → P x → P y
-- Properties
≐-refl : {A : Set}{x : A} → x ≐ x
≐-refl P Px = Px
≐-sym : {A : Set}{x y : A} → x ≐ y → y ≐ x
≐-sym {x = x} {y} h P Py = h (λ z → P z → P x) (λ Px → Px) Py
≐-trans : {A : Set}{x y z : A} → x ≐ y → y ≐ z → x ≐ z
≐-trans h₁ h₂ P Px = h₂ P (h₁ P Px)
≐-subst : {A : Set}(P : A → Set){x y : A} → x ≐ y → P x → P y
≐-subst P h = h P
------------------------------------------------------------------------------
-- Leibniz's equality and the identity type
-- "In the presence of a type of propositions "Prop" one can also
-- define propositional equality by Leibniz's principle." [Hofmman
-- 1995, p. 4]
≐→≡ : {A : Set}{x y : A} → x ≐ y → x ≡ y
≐→≡ {x = x} h = h (λ z → x ≡ z) refl
≡→≐ : {A : Set}{x y : A} → x ≡ y → x ≐ y
≡→≐ refl P Px = Px
------------------------------------------------------------------------------
-- References
--
-- Hofmann, Martin (1995). Extensional concepts in intensional type
-- theory. PhD thesis. University of Edinburgh.
-- Luo, Zhaohui (1994). Computation and Reasoning. A Type Theory for
-- Computer Science. Oxford University Press.
|
{
"alphanum_fraction": 0.4636871508,
"avg_line_length": 30.3962264151,
"ext": "agda",
"hexsha": "a9f9539f45553719c5e6588ee4a93c67795c73eb",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/setoids/LeibnizEquality.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/setoids/LeibnizEquality.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/setoids/LeibnizEquality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 556,
"size": 1611
}
|
{-# OPTIONS --without-K --safe #-}
-- Definition of Pi with fractionals
module PiFrac where
-- From the standard library:
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; cong; cong₂)
-- The basic types we add:
open import Singleton
infixr 70 _×ᵤ_
infixr 60 _+ᵤ_
infixr 50 _⊚_
------------------------------------------------------------------------------
-- Pi with fractionals
-- The following are all mutually dependent:
data 𝕌 : Set -- 𝕌niverse of types
⟦_⟧ : (A : 𝕌) → Set -- denotation of types
data _⟷_ : 𝕌 → 𝕌 → Set -- type equivalences
eval : {A B : 𝕌} → (A ⟷ B) → ⟦ A ⟧ → ⟦ B ⟧ -- evaluating an equivalence
data 𝕌 where
𝟘 : 𝕌
𝟙 : 𝕌
_+ᵤ_ : 𝕌 → 𝕌 → 𝕌
_×ᵤ_ : 𝕌 → 𝕌 → 𝕌
●_[_] : (A : 𝕌) → ⟦ A ⟧ → 𝕌
𝟙/●_[_] : (A : 𝕌) → ⟦ A ⟧ → 𝕌
⟦ 𝟘 ⟧ = ⊥
⟦ 𝟙 ⟧ = ⊤
⟦ t₁ +ᵤ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ t₁ ×ᵤ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
⟦ ● A [ v ] ⟧ = Singleton ⟦ A ⟧ v
⟦ 𝟙/● A [ v ] ⟧ = Recip ⟦ A ⟧ v
data _⟷_ where
unite₊l : {t : 𝕌} → 𝟘 +ᵤ t ⟷ t
uniti₊l : {t : 𝕌} → t ⟷ 𝟘 +ᵤ t
unite₊r : {t : 𝕌} → t +ᵤ 𝟘 ⟷ t
uniti₊r : {t : 𝕌} → t ⟷ t +ᵤ 𝟘
swap₊ : {t₁ t₂ : 𝕌} → t₁ +ᵤ t₂ ⟷ t₂ +ᵤ t₁
assocl₊ : {t₁ t₂ t₃ : 𝕌} → t₁ +ᵤ (t₂ +ᵤ t₃) ⟷ (t₁ +ᵤ t₂) +ᵤ t₃
assocr₊ : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) +ᵤ t₃ ⟷ t₁ +ᵤ (t₂ +ᵤ t₃)
unite⋆l : {t : 𝕌} → 𝟙 ×ᵤ t ⟷ t
uniti⋆l : {t : 𝕌} → t ⟷ 𝟙 ×ᵤ t
unite⋆r : {t : 𝕌} → t ×ᵤ 𝟙 ⟷ t
uniti⋆r : {t : 𝕌} → t ⟷ t ×ᵤ 𝟙
swap⋆ : {t₁ t₂ : 𝕌} → t₁ ×ᵤ t₂ ⟷ t₂ ×ᵤ t₁
assocl⋆ : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ ×ᵤ t₃) ⟷ (t₁ ×ᵤ t₂) ×ᵤ t₃
assocr⋆ : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₂) ×ᵤ t₃ ⟷ t₁ ×ᵤ (t₂ ×ᵤ t₃)
absorbr : {t : 𝕌} → 𝟘 ×ᵤ t ⟷ 𝟘
absorbl : {t : 𝕌} → t ×ᵤ 𝟘 ⟷ 𝟘
factorzr : {t : 𝕌} → 𝟘 ⟷ t ×ᵤ 𝟘
factorzl : {t : 𝕌} → 𝟘 ⟷ 𝟘 ×ᵤ t
dist : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) ×ᵤ t₃ ⟷ (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃)
factor : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃) ⟷ (t₁ +ᵤ t₂) ×ᵤ t₃
distl : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ +ᵤ t₃) ⟷ (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃)
factorl : {t₁ t₂ t₃ : 𝕌 } → (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃) ⟷ t₁ ×ᵤ (t₂ +ᵤ t₃)
id⟷ : {t : 𝕌} → t ⟷ t
_⊚_ : {t₁ t₂ t₃ : 𝕌} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (t₁ +ᵤ t₂ ⟷ t₃ +ᵤ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (t₁ ×ᵤ t₂ ⟷ t₃ ×ᵤ t₄)
-- new operations on Singleton
lift : {t₁ t₂ : 𝕌} → {v₁ : ⟦ t₁ ⟧} →
(c : t₁ ⟷ t₂) →
(● t₁ [ v₁ ] ⟷ ● t₂ [ eval c v₁ ])
tensorl : {t₁ t₂ : 𝕌} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} →
● t₁ ×ᵤ t₂ [ v₁ , v₂ ] ⟷ ● t₁ [ v₁ ] ×ᵤ ● t₂ [ v₂ ]
tensorr : {t₁ t₂ : 𝕌} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} →
● t₁ [ v₁ ] ×ᵤ ● t₂ [ v₂ ] ⟷ ● t₁ ×ᵤ t₂ [ v₁ , v₂ ]
plusll : {t₁ t₂ : 𝕌} {v : ⟦ t₁ ⟧} →
● (t₁ +ᵤ t₂) [ inj₁ v ] ⟷ ● t₁ [ v ]
pluslr : {t₁ t₂ : 𝕌} {v : ⟦ t₁ ⟧} →
● t₁ [ v ] ⟷ ● (t₁ +ᵤ t₂) [ inj₁ v ]
plusrl : {t₁ t₂ : 𝕌} {v : ⟦ t₂ ⟧} →
● (t₁ +ᵤ t₂) [ inj₂ v ] ⟷ ● t₂ [ v ]
plusrr : {t₁ t₂ : 𝕌} {v : ⟦ t₂ ⟧} →
● t₂ [ v ] ⟷ ● (t₁ +ᵤ t₂) [ inj₂ v ]
fracl : {t₁ t₂ : 𝕌} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} →
𝟙/● t₁ ×ᵤ t₂ [ v₁ , v₂ ] ⟷ 𝟙/● t₁ [ v₁ ] ×ᵤ 𝟙/● t₂ [ v₂ ]
fracr : {t₁ t₂ : 𝕌} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} →
𝟙/● t₁ [ v₁ ] ×ᵤ 𝟙/● t₂ [ v₂ ] ⟷ 𝟙/● t₁ ×ᵤ t₂ [ v₁ , v₂ ]
-- fractionals
η : {t : 𝕌} → (v : ⟦ t ⟧) → 𝟙 ⟷ ● t [ v ] ×ᵤ 𝟙/● t [ v ]
ε : {t : 𝕌} → (v : ⟦ t ⟧) → ● t [ v ] ×ᵤ 𝟙/● t [ v ] ⟷ 𝟙
-- double lift prop eq
ll : ∀ {t : 𝕌} {v : ⟦ t ⟧} {w : ⟦ ● t [ v ] ⟧} →
● (● t [ v ]) [ w ] ⟷ ● t [ v ]
== : ∀ {t₁ t₂ : 𝕌} {v : ⟦ t₁ ⟧} {w w' : ⟦ t₂ ⟧} →
(● t₁ [ v ] ⟷ ● t₂ [ w ]) → (w ≡ w') → (● t₁ [ v ] ⟷ ● t₂ [ w' ])
eval unite₊l (inj₂ v) = v
eval uniti₊l v = inj₂ v
eval unite₊r (inj₁ v) = v
eval uniti₊r v = inj₁ v
eval swap₊ (inj₁ v) = inj₂ v
eval swap₊ (inj₂ v) = inj₁ v
eval assocl₊ (inj₁ v) = inj₁ (inj₁ v)
eval assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)
eval assocl₊ (inj₂ (inj₂ v)) = inj₂ v
eval assocr₊ (inj₁ (inj₁ v)) = inj₁ v
eval assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)
eval assocr₊ (inj₂ v) = inj₂ (inj₂ v)
eval unite⋆l (tt , v) = v
eval uniti⋆l v = (tt , v)
eval unite⋆r (v , tt) = v
eval uniti⋆r v = (v , tt)
eval swap⋆ (v₁ , v₂) = (v₂ , v₁)
eval assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)
eval assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))
eval absorbl ()
eval absorbr ()
eval factorzl ()
eval factorzr ()
eval dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)
eval dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)
eval factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)
eval factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)
eval distl (v , inj₁ v₁) = inj₁ (v , v₁)
eval distl (v , inj₂ v₂) = inj₂ (v , v₂)
eval factorl (inj₁ (v , v₁)) = (v , inj₁ v₁)
eval factorl (inj₂ (v , v₂)) = (v , inj₂ v₂)
eval id⟷ v = v
eval (c₁ ⊚ c₂) v = eval c₂ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₁ v) = inj₁ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₂ v) = inj₂ (eval c₂ v)
eval (c₁ ⊗ c₂) (v₁ , v₂) = (eval c₁ v₁ , eval c₂ v₂)
eval (lift c) (w , v≡w) = eval c w , cong (eval c) v≡w
eval tensorl ((w₁ , w₂) , vp≡wp) =
(w₁ , cong proj₁ vp≡wp) , (w₂ , cong proj₂ vp≡wp)
eval tensorr ((w₁ , p₁) , (w₂ , p₂)) =
(w₁ , w₂) , cong₂ _,_ p₁ p₂
eval (η v) tt = (v , refl) , λ _ → tt
eval (ε v) (p , f) = f p
eval (plusll {v = .w₁}) (inj₁ w₁ , refl) = w₁ , refl
eval pluslr (v₁ , refl) = inj₁ v₁ , refl
eval (plusrl {v = .w₂}) (inj₂ w₂ , refl) = w₂ , refl
eval plusrr (v₂ , refl) = inj₂ v₂ , refl
eval (fracl {v₁ = v₁} {v₂ = v₂}) f = (λ _ → f ((v₁ , v₂) , refl)) , (λ _ → f ((v₁ , v₂) , refl))
eval fracr (f₁ , f₂) ((w₁ , w₂) , refl) = let _ = f₁ (w₁ , refl) ; _ = f₂ (w₂ , refl) in tt
eval (ll {t} {v} {.w}) (w , refl) = v , refl
eval (== c eq) s₁ = let (w₂ , p) = eval c s₁ in w₂ , trans (sym eq) p
focus : {t : 𝕌} → (v : ⟦ t ⟧) → Singleton ⟦ t ⟧ v
focus v = (v , refl)
unfocus : {t : 𝕌} {v : ⟦ t ⟧} → Singleton ⟦ t ⟧ v → ⟦ t ⟧
unfocus (v , refl) = v
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4410130719,
"avg_line_length": 37.5460122699,
"ext": "agda",
"hexsha": "acd5c292c0730f9d05127a73ce6962b19148a805",
"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": "fracGC/PiFrac.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": "fracGC/PiFrac.agda",
"max_line_length": 96,
"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": "fracGC/PiFrac.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": 3500,
"size": 6120
}
|
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
import Web.Semantic.DL.Category.Composition
import Web.Semantic.DL.Category.Morphism
import Web.Semantic.DL.Category.Object
import Web.Semantic.DL.Category.Properties
import Web.Semantic.DL.Category.Tensor
import Web.Semantic.DL.Category.Unit
import Web.Semantic.DL.Category.Wiring
module Web.Semantic.DL.Category {Σ : Signature} where
infix 2 _≣_ _⇒_
infixr 5 _∙_ _⊗_ _⟨⊗⟩_
-- Categorial structure
Object : TBox Σ → TBox Σ → Set₁
Object = Web.Semantic.DL.Category.Object.Object
_⇒_ : ∀ {S T} → (Object S T) → (Object S T) → Set₁
_⇒_ = Web.Semantic.DL.Category.Morphism._⇒_
identity : ∀ {S T} (A : Object S T) → (A ⇒ A)
identity = Web.Semantic.DL.Category.Wiring.identity
_∙_ : ∀ {S T} {A B C : Object S T} → (A ⇒ B) → (B ⇒ C) → (A ⇒ C)
_∙_ = Web.Semantic.DL.Category.Composition._∙_
-- Symmetric monoidal structure
I : ∀ {S T} → Object S T
I = Web.Semantic.DL.Category.Unit.I
_⊗_ : ∀ {S T} → Object S T → Object S T → Object S T
_⊗_ = Web.Semantic.DL.Category.Tensor._⊗_
_⟨⊗⟩_ : ∀ {S T : TBox Σ} {A₁ A₂ B₁ B₂ : Object S T} →
(A₁ ⇒ B₁) → (A₂ ⇒ B₂) → ((A₁ ⊗ A₂) ⇒ (B₁ ⊗ B₂))
_⟨⊗⟩_ = Web.Semantic.DL.Category.Tensor._⟨⊗⟩_
symm : ∀ {S T : TBox Σ} → (A B : Object S T) → ((A ⊗ B) ⇒ (B ⊗ A))
symm = Web.Semantic.DL.Category.Wiring.symm
assoc : ∀ {S T : TBox Σ} → (A B C : Object S T) →
(((A ⊗ B) ⊗ C) ⇒ (A ⊗ (B ⊗ C)))
assoc = Web.Semantic.DL.Category.Wiring.assoc
assoc⁻¹ : ∀ {S T : TBox Σ} → (A B C : Object S T) →
((A ⊗ (B ⊗ C)) ⇒ ((A ⊗ B) ⊗ C))
assoc⁻¹ = Web.Semantic.DL.Category.Wiring.assoc⁻¹
unit₁ : ∀ {S T : TBox Σ} (A : Object S T) → ((I ⊗ A) ⇒ A)
unit₁ = Web.Semantic.DL.Category.Wiring.unit₁
unit₁⁻¹ : ∀ {S T : TBox Σ} (A : Object S T) → (A ⇒ (I ⊗ A))
unit₁⁻¹ = Web.Semantic.DL.Category.Wiring.unit₁⁻¹
unit₂ : ∀ {S T : TBox Σ} (A : Object S T) → ((A ⊗ I) ⇒ A)
unit₂ = Web.Semantic.DL.Category.Wiring.unit₂
unit₂⁻¹ : ∀ {S T : TBox Σ} (A : Object S T) → (A ⇒ (A ⊗ I))
unit₂⁻¹ = Web.Semantic.DL.Category.Wiring.unit₂⁻¹
-- Equivalence of morphisms
_≣_ : ∀ {S T} {A B : Object S T} → (A ⇒ B) → (A ⇒ B) → Set₁
_≣_ = Web.Semantic.DL.Category.Morphism._≣_
≣-refl : ∀ {S T} {A B : Object S T} (F : A ⇒ B) →
(F ≣ F)
≣-refl = Web.Semantic.DL.Category.Properties.≣-refl
≣-sym : ∀ {S T} {A B : Object S T} {F G : A ⇒ B} →
(F ≣ G) → (G ≣ F)
≣-sym = Web.Semantic.DL.Category.Properties.≣-sym
≣-trans : ∀ {S T} {A B : Object S T} {F G H : A ⇒ B} →
(F ≣ G) → (G ≣ H) → (F ≣ H)
≣-trans = Web.Semantic.DL.Category.Properties.≣-trans
-- Equations of a category
compose-resp-≣ : ∀ {S T} {A B C : Object S T} {F₁ F₂ : A ⇒ B} {G₁ G₂ : B ⇒ C} →
(F₁ ≣ F₂) → (G₁ ≣ G₂) → (F₁ ∙ G₁ ≣ F₂ ∙ G₂)
compose-resp-≣ = Web.Semantic.DL.Category.Properties.compose-resp-≣
compose-unit₁ : ∀ {S T} {A B C : Object S T} (F : A ⇒ B) →
(identity A ∙ F ≣ F)
compose-unit₁ = Web.Semantic.DL.Category.Properties.compose-unit₁
compose-unit₂ : ∀ {S T} {A B C : Object S T} (F : A ⇒ B) →
(F ∙ identity B ≣ F)
compose-unit₂ = Web.Semantic.DL.Category.Properties.compose-unit₂
compose-assoc : ∀ {S T} {A B C D : Object S T}
(F : A ⇒ B) (G : B ⇒ C) (H : C ⇒ D) →
((F ∙ G) ∙ H ≣ F ∙ (G ∙ H))
compose-assoc = Web.Semantic.DL.Category.Properties.compose-assoc
-- Tensor is a bifunctor
tensor-resp-≣ : ∀ {S T} {A₁ A₂ B₁ B₂ : Object S T}
{F₁ G₁ : A₁ ⇒ B₁} {F₂ G₂ : A₂ ⇒ B₂} →
(F₁ ≣ G₁) → (F₂ ≣ G₂) → (F₁ ⟨⊗⟩ F₂ ≣ G₁ ⟨⊗⟩ G₂)
tensor-resp-≣ = Web.Semantic.DL.Category.Properties.tensor-resp-≣
tensor-resp-compose : ∀ {S T} {A₁ A₂ B₁ B₂ C₁ C₂ : Object S T}
(F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) (G₁ : B₁ ⇒ C₁) (G₂ : B₂ ⇒ C₂) →
(((F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂)) ≣ ((F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂)))
tensor-resp-compose = Web.Semantic.DL.Category.Properties.tensor-resp-compose
tensor-resp-id : ∀ {S T} (A₁ A₂ : Object S T) →
((identity A₁ ⟨⊗⟩ identity A₂) ≣ identity (A₁ ⊗ A₂))
tensor-resp-id = Web.Semantic.DL.Category.Properties.tensor-resp-id
-- Isomorphisms of a symmetric monoidal category
symm-iso : ∀ {S T} (A₁ A₂ : Object S T) →
(symm A₁ A₂ ∙ symm A₂ A₁ ≣ identity (A₁ ⊗ A₂))
symm-iso = Web.Semantic.DL.Category.Properties.symm-iso
assoc-iso : ∀ {S T} (A₁ A₂ A₃ : Object S T) →
(assoc A₁ A₂ A₃ ∙ assoc⁻¹ A₁ A₂ A₃ ≣ identity ((A₁ ⊗ A₂) ⊗ A₃))
assoc-iso = Web.Semantic.DL.Category.Properties.assoc-iso
assoc⁻¹-iso : ∀ {S T} (A₁ A₂ A₃ : Object S T) →
(assoc⁻¹ A₁ A₂ A₃ ∙ assoc A₁ A₂ A₃ ≣ identity (A₁ ⊗ (A₂ ⊗ A₃)))
assoc⁻¹-iso = Web.Semantic.DL.Category.Properties.assoc⁻¹-iso
unit₁-iso : ∀ {S T} (A : Object S T) →
(unit₁ A ∙ unit₁⁻¹ A ≣ identity (I ⊗ A))
unit₁-iso = Web.Semantic.DL.Category.Properties.unit₁-iso
unit₁⁻¹-iso : ∀ {S T} (A : Object S T) →
(unit₁⁻¹ A ∙ unit₁ A ≣ identity A)
unit₁⁻¹-iso = Web.Semantic.DL.Category.Properties.unit₁⁻¹-iso
unit₂-iso : ∀ {S T} (A : Object S T) →
(unit₂ A ∙ unit₂⁻¹ A ≣ identity (A ⊗ I))
unit₂-iso = Web.Semantic.DL.Category.Properties.unit₂-iso
unit₂⁻¹-iso : ∀ {S T} (A : Object S T) →
(unit₂⁻¹ A ∙ unit₂ A ≣ identity A)
unit₂⁻¹-iso = Web.Semantic.DL.Category.Properties.unit₂⁻¹-iso
-- Coherence conditions of a symmetric monoidal category
assoc-unit : ∀ {S T} (A₁ A₂ : Object S T) →
(assoc A₁ I A₂ ∙ (identity A₁ ⟨⊗⟩ unit₁ A₂) ≣ unit₂ A₁ ⟨⊗⟩ identity A₂)
assoc-unit = Web.Semantic.DL.Category.Properties.assoc-unit
assoc-assoc : ∀ {S T} (A₁ A₂ A₃ A₄ : Object S T) →
(assoc (A₁ ⊗ A₂) A₃ A₄ ∙ assoc A₁ A₂ (A₃ ⊗ A₄) ≣
(assoc A₁ A₂ A₃ ⟨⊗⟩ identity A₄) ∙ assoc A₁ (A₂ ⊗ A₃) A₄ ∙ (identity A₁ ⟨⊗⟩ assoc A₂ A₃ A₄))
assoc-assoc = Web.Semantic.DL.Category.Properties.assoc-assoc
assoc-symm : ∀ {S T} (A₁ A₂ A₃ : Object S T) →
(symm (A₁ ⊗ A₂) A₃ ∙ assoc⁻¹ A₃ A₁ A₂ ≣
assoc A₁ A₂ A₃ ∙ (identity A₁ ⟨⊗⟩ symm A₂ A₃) ∙ assoc⁻¹ A₁ A₃ A₂ ∙ (symm A₁ A₃ ⟨⊗⟩ identity A₂))
assoc-symm = Web.Semantic.DL.Category.Properties.assoc-symm
-- Naturality conditions of a symmetric monoidal category
unit₁-natural : ∀ {S T} {A B : Object S T} (F : A ⇒ B) →
((identity I ⟨⊗⟩ F) ∙ unit₁ B ≣ unit₁ A ∙ F)
unit₁-natural = Web.Semantic.DL.Category.Properties.unit₁-natural
unit₂-natural : ∀ {S T} {A B : Object S T} (F : A ⇒ B) →
((F ⟨⊗⟩ identity I) ∙ unit₂ B ≣ unit₂ A ∙ F)
unit₂-natural = Web.Semantic.DL.Category.Properties.unit₂-natural
symm-natural : ∀ {S T} {A₁ A₂ B₁ B₂ : Object S T}
(F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) →
((F₁ ⟨⊗⟩ F₂) ∙ symm B₁ B₂ ≣ symm A₁ A₂ ∙ (F₂ ⟨⊗⟩ F₁))
symm-natural = Web.Semantic.DL.Category.Properties.symm-natural
assoc-natural : ∀ {S T} {A₁ A₂ A₃ B₁ B₂ B₃ : Object S T}
(F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) (F₃ : A₃ ⇒ B₃) →
(((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) ∙ assoc B₁ B₂ B₃ ≣
assoc A₁ A₂ A₃ ∙ (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)))
assoc-natural = Web.Semantic.DL.Category.Properties.assoc-natural
|
{
"alphanum_fraction": 0.6059518469,
"avg_line_length": 36.3423913043,
"ext": "agda",
"hexsha": "13c0375a880985435b1287735b6a3f6bbad1cb14",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Category.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Category.agda",
"max_line_length": 100,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Category.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 2997,
"size": 6687
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Explaining how to use the inspect idiom and elaborating on the way
-- it is implemented in the standard library.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module README.Inspect where
open import Data.Nat.Base
open import Data.Nat.Properties
open import Data.Product
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Using inspect
-- We start with the definition of a (silly) predicate: `Plus m n p` states
-- that `m + n` is equal to `p` in a rather convoluted way. Crucially, it
-- distinguishes two cases: whether `p` is 0 or not.
Plus-eq : (m n p : ℕ) → Set
Plus-eq m n zero = m ≡ 0 × n ≡ 0
Plus-eq m n p@(suc _) = m + n ≡ p
-- A sensible lemma to prove of this predicate is that whenever `p` is literally
-- `m + n` then `Plus m n p` holds. That is to say `∀ m n → Plus m n (m + n)`.
-- To be able to prove `Plus-eq m n (m + n)`, we need `m + n` to have either
-- the shape `zero` or `suc _` so that `Plus-eq` may reduce.
-- We could follow the way `_+_` computes by mimicking the same splitting
-- strategy, thus forcing `m + n` to reduce:
plus-eq-+ : ∀ m n → Plus-eq m n (m + n)
plus-eq-+ zero zero = refl , refl
plus-eq-+ zero (suc n) = refl
plus-eq-+ (suc m) n = refl
-- Or we could attempt to compute `m + n` first and check whether the result
-- is `zero` or `suc p`. By using `with m + n` and naming the result `p`,
-- the goal will become `Plus-eq m n p`. We can further refine this definition
-- by distinguishing two cases like so:
-- plus-eq-with : ∀ m n → Plus-eq m n (m + n)
-- plus-eq-with m n with m + n
-- ... | zero = {!!}
-- ... | suc p = {!!}
-- The problem however is that we have abolutely lost the connection between the
-- computation `m + n` and its result `p`. Which makes the two goals unprovable:
-- 1. `m ≡ 0 × n ≡ 0`, with no assumption whatsoever
-- 2. `m + n ≡ suc p`, with no assumption either
-- By using the `with` construct, we have generated an auxiliary function that
-- looks like this:
-- `plus-eq-with-aux : ∀ m n p → Plus-eq m n p`
-- when we would have wanted a more precise type of the form:
-- `plus-eq-aux : ∀ m n p → m + n ≡ p → Plus-eq m n p`.
-- This is where we can use `inspect`. By using `with f x | inspect f x`,
-- we get both a `y` which is the result of `f x` and a proof that `f x ≡ y`.
-- Splitting on the result of `m + n`, we get two cases:
-- 1. `m ≡ 0 × n ≡ 0` under the assumption that `m + n ≡ zero`
-- 2. `m + n ≡ suc p` under the assumption that `m + n ≡ suc p`
-- The first one can be discharged using lemmas from Data.Nat.Properties and
-- the second one is trivial.
plus-eq-with : ∀ m n → Plus-eq m n (m + n)
plus-eq-with m n with m + n | inspect (m +_) n
... | zero | [ m+n≡0 ] = m+n≡0⇒m≡0 m m+n≡0 , m+n≡0⇒n≡0 m m+n≡0
... | suc p | [ m+n≡1+p ] = m+n≡1+p
------------------------------------------------------------------------
-- Understanding the implementation of inspect
-- So why is it that we have to go through the record type `Reveal_·_is_`
-- and the ̀inspect` function? The fact is: we don't have to if we write
-- our own auxiliary lemma:
plus-eq-aux : ∀ m n → Plus-eq m n (m + n)
plus-eq-aux m n = aux m n (m + n) refl where
aux : ∀ m n p → m + n ≡ p → Plus-eq m n p
aux m n zero m+n≡0 = m+n≡0⇒m≡0 m m+n≡0 , m+n≡0⇒n≡0 m m+n≡0
aux m n (suc p) m+n≡1+p = m+n≡1+p
-- The problem is that when we write ̀with f x | pr`, `with` decides to call `y`
-- the result `f x` and to replace *all* of the occurences of `f x` in the type
-- of `pr` with `y`. That is to say that if we were to write:
-- plus-eq-naïve : ∀ m n → Plus-eq m n (m + n)
-- plus-eq-naïve m n with m + n | refl {x = m + n}
-- ... | p | eq = {!!}
-- then `with` would abstract `m + n` as `p` on *both* sides of the equality
-- proven by `refl` thus giving us the following goal with an extra, useless,
-- assumption:
-- 1. `Plus-eq m n p` under the assumption that `p ≡ p`
-- So how does `inspect` work? The standard library uses a more general version
-- of the following type and function:
record MyReveal_·_is_ (f : ℕ → ℕ) (x y : ℕ) : Set where
constructor [_]
field eq : f x ≡ y
my-inspect : ∀ f n → MyReveal f · n is (f n)
my-inspect f n = [ refl ]
-- Given that `inspect` has the type `∀ f n → Reveal f · n is (f n)`, when we
-- write `with f n | inspect f n`, the only `f n` that can be abstracted in the
-- type of `inspect f n` is the third argument to `Reveal_·_is_`.
-- That is to say that the auxiliary definition generated looks like this:
plus-eq-reveal : ∀ m n → Plus-eq m n (m + n)
plus-eq-reveal m n = aux m n (m + n) (my-inspect (m +_) n) where
aux : ∀ m n p → MyReveal (m +_) · n is p → Plus-eq m n p
aux m n zero [ m+n≡0 ] = m+n≡0⇒m≡0 m m+n≡0 , m+n≡0⇒n≡0 m m+n≡0
aux m n (suc p) [ m+n≡1+p ] = m+n≡1+p
-- At the cost of having to unwrap the constructor `[_]` around the equality
-- we care about, we can keep relying on `with` and avoid having to roll out
-- handwritten auxiliary definitions.
|
{
"alphanum_fraction": 0.5906286155,
"avg_line_length": 38.992481203,
"ext": "agda",
"hexsha": "22f11e5d4db856fbe41b387b626c1fe95a4db081",
"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/README/Inspect.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/README/Inspect.agda",
"max_line_length": 80,
"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/README/Inspect.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": 1706,
"size": 5186
}
|
-- named arguments should be allowed in module applications
module Issue420 where
module M {A : Set₁} where
open M {A = Set}
|
{
"alphanum_fraction": 0.7401574803,
"avg_line_length": 18.1428571429,
"ext": "agda",
"hexsha": "48863f5ae183ba22775d9f1f914df8dc76e28912",
"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/Issue420.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/Issue420.agda",
"max_line_length": 59,
"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/Issue420.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": 32,
"size": 127
}
|
{-# OPTIONS --without-K --safe #-}
module Data.Bool.Base where
open import Level
open import Agda.Builtin.Bool using (Bool; true; false) public
open import Data.Unit
bool : ∀ {ℓ} {P : Bool → Type ℓ} (f : P false) (t : P true) → (x : Bool) → P x
bool f t false = f
bool f t true = t
{-# INLINE bool #-}
bool′ : A → A → Bool → A
bool′ = bool
{-# INLINE bool′ #-}
not : Bool → Bool
not false = true
not true = false
infixl 6 _or_
_or_ : Bool → Bool → Bool
false or y = y
true or y = true
infixl 7 _and_
_and_ : Bool → Bool → Bool
false and y = false
true and y = y
infixr 0 if_then_else_
if_then_else_ : ∀ {a} {A : Set a} → Bool → A → A → A
if p then x else y = bool y x p
{-# INLINE if_then_else_ #-}
|
{
"alphanum_fraction": 0.6197183099,
"avg_line_length": 19.1891891892,
"ext": "agda",
"hexsha": "9dab142c1b3e1259175007a53e8aa5f40a26d4fe",
"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": "Data/Bool/Base.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": "Data/Bool/Base.agda",
"max_line_length": 78,
"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": "Data/Bool/Base.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": 245,
"size": 710
}
|
module sn-calculus-compatconf.in-lift where
open import sn-calculus-compatconf.base
open import sn-calculus
open import utility renaming (_U̬_ to _∪_)
open import context-properties
using (get-view ; wrap-rho ; unwrap-rho
; ->E-view ; E-view-main-bind ; _a~_
; ->E-view-term ; ->E-view-inner-term ; done-E-view-term-disjoint)
open import Esterel.Lang
open import Esterel.Lang.Properties
open import Esterel.Lang.Binding
open import Esterel.Context
using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ;
Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c)
open import Esterel.Context.Properties
using (plug)
open import Esterel.Environment as Env
using (Env ; []env ; _←_)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym ; cong ; trans ; subst ; module ≡-Reasoning)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; _∷_ ; [] ; _++_ ; map)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_ ; ∃)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open ->E-view
open EvaluationContext1
open _≐_⟦_⟧e
open Context1
open _≐_⟦_⟧c
{-
Base case where (E , C) = (_∷_ , []). LHS is arbitrary ->E-view reduction
and RHS is a merge. This case is delegated to R-confluence.
p
ρθ. E⟦E₁⟦qin⟧⟧ -- sn⟶₁ -> ρθq. E⟦E₁⟦qo⟧⟧
(ρθ) E⟦E₂⟦ρθ'.rin⟧⟧ -- sn⟶₁ -> (ρθ) E⟦ρθ'.E₂⟦rin⟧⟧
-}
1-steplρ-E-view-ecin-lift : ∀{E E₁ Ei p qin q qo rin r ro θ θq BV FV A Aq} →
{ρθ·psn⟶₁ρθq·q : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θq , Aq ⟩· q} →
CorrectBinding p BV FV →
(p≐E⟦qin⟧ : p ≐ (E ++ (E₁ ∷ Ei)) ⟦ qin ⟧e) →
(q≐E⟦qo⟧ : q ≐ (E ++ (E₁ ∷ Ei)) ⟦ qo ⟧e) →
->E-view ρθ·psn⟶₁ρθq·q p≐E⟦qin⟧ q≐E⟦qo⟧ →
(p≐E⟦rin⟧ : p ≐ (map ceval E) ⟦ rin ⟧c) →
(r≐E⟦ro⟧ : r ≐ (map ceval E) ⟦ ro ⟧c) →
(rinsn⟶₁ro : rin sn⟶₁ ro) →
⊥
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(depar₁ p'≐E⟦qin⟧) q≐E⟦qo⟧ e-view dchole dchole
(rpar-done-right p'/halted q'/done) =
(done-E-view-term-disjoint
(dhalted (halted-⟦⟧e p'/halted p'≐E⟦qin⟧))
(->E-view-inner-term e-view))
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(depar₂ q'≐E⟦qin⟧) q≐E⟦qo⟧ e-view dchole dchole
(rpar-done-right p'/halted q'/done) =
(done-E-view-term-disjoint
(done-⟦⟧e q'/done q'≐E⟦qin⟧)
(->E-view-inner-term e-view))
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(depar₁ p'≐E⟦qin⟧) q≐E⟦qo⟧ e-view dchole dchole
(rpar-done-left p'/done q'/halted) =
(done-E-view-term-disjoint
(done-⟦⟧e p'/done p'≐E⟦qin⟧)
(->E-view-inner-term e-view))
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(depar₂ q'≐E⟦qin⟧) q≐E⟦qo⟧ e-view dchole dchole
(rpar-done-left p'/done q'/halted) =
(done-E-view-term-disjoint
(dhalted (halted-⟦⟧e q'/halted q'≐E⟦qin⟧))
(->E-view-inner-term e-view))
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(deseq dehole) q≐E⟦qo⟧ () dchole dchole
rseq-done
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(deseq dehole) q≐E⟦qo⟧ () dchole dchole
rseq-exit
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(deloopˢ dehole) q≐E⟦qo⟧ () dchole dchole
rloopˢ-exit
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(desuspend p≐E⟦qin⟧) q≐E⟦qo⟧ e-view dchole dchole
(rsuspend-done p/halted) =
(done-E-view-term-disjoint
(dhalted (halted-⟦⟧e p/halted p≐E⟦qin⟧))
(->E-view-inner-term e-view))
1-steplρ-E-view-ecin-lift {[]} {ρθ·psn⟶₁ρθq·q = ρθ·psn⟶₁ρθq·q} cb
(detrap p≐E⟦qin⟧) q≐E⟦qo⟧ e-view dchole dchole
(rtrap-done p/halted) =
(done-E-view-term-disjoint
(dhalted (halted-⟦⟧e p/halted p≐E⟦qin⟧))
(->E-view-inner-term e-view))
1-steplρ-E-view-ecin-lift {E₁ ∷ E} {ρθ·psn⟶₁ρθq·q = ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧}
cb@(CBpar cbp cbq _ _ _ _)
(depar₁ p≐E⟦qin⟧) (depar₁ q≐E⟦qo⟧) e-view-E₁
(dcpar₁ p≐E⟦rin⟧) (dcpar₁ r≐E⟦ro⟧) rinsn⟶₁ro
with unwrap-rho ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧ (depar₁ p≐E⟦qin⟧) (depar₁ q≐E⟦qo⟧)
p≐E⟦qin⟧ q≐E⟦qo⟧ e-view-E₁
... | (ρθ·psn⟶₁ρθq·q , e-view) =
1-steplρ-E-view-ecin-lift cbp p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐E⟦rin⟧ r≐E⟦ro⟧ rinsn⟶₁ro
1-steplρ-E-view-ecin-lift {E₁ ∷ E} {ρθ·psn⟶₁ρθq·q = ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧}
cb@(CBpar cbp cbq _ _ _ _)
(depar₂ p≐E⟦qin⟧) (depar₂ q≐E⟦qo⟧) e-view-E₁
(dcpar₂ p≐E⟦rin⟧) (dcpar₂ r≐E⟦ro⟧) rinsn⟶₁ro
with unwrap-rho ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧ (depar₂ p≐E⟦qin⟧) (depar₂ q≐E⟦qo⟧)
p≐E⟦qin⟧ q≐E⟦qo⟧ e-view-E₁
... | (ρθ·psn⟶₁ρθq·q , e-view) =
1-steplρ-E-view-ecin-lift cbq p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐E⟦rin⟧ r≐E⟦ro⟧ rinsn⟶₁ro
1-steplρ-E-view-ecin-lift {E₁ ∷ E} {ρθ·psn⟶₁ρθq·q = ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧}
cb@(CBseq cbp cbq _)
(deseq p≐E⟦qin⟧) (deseq q≐E⟦qo⟧) e-view-E₁
(dcseq₁ p≐E⟦rin⟧) (dcseq₁ r≐E⟦ro⟧) rinsn⟶₁ro
with unwrap-rho ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧ (deseq p≐E⟦qin⟧) (deseq q≐E⟦qo⟧)
p≐E⟦qin⟧ q≐E⟦qo⟧ e-view-E₁
... | (ρθ·psn⟶₁ρθq·q , e-view) =
1-steplρ-E-view-ecin-lift cbp p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐E⟦rin⟧ r≐E⟦ro⟧ rinsn⟶₁ro
1-steplρ-E-view-ecin-lift {E₁ ∷ E} {ρθ·psn⟶₁ρθq·q = ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧}
cb@(CBloopˢ cbp cbq _ _)
(deloopˢ p≐E⟦qin⟧) (deloopˢ q≐E⟦qo⟧) e-view-E₁
(dcloopˢ₁ p≐E⟦rin⟧) (dcloopˢ₁ r≐E⟦ro⟧) rinsn⟶₁ro
with unwrap-rho ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧ (deloopˢ p≐E⟦qin⟧) (deloopˢ q≐E⟦qo⟧)
p≐E⟦qin⟧ q≐E⟦qo⟧ e-view-E₁
... | (ρθ·psn⟶₁ρθq·q , e-view) =
1-steplρ-E-view-ecin-lift cbp p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐E⟦rin⟧ r≐E⟦ro⟧ rinsn⟶₁ro
1-steplρ-E-view-ecin-lift {E₁ ∷ E} {ρθ·psn⟶₁ρθq·q = ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧}
cb@(CBsusp cb' _)
(desuspend p≐E⟦qin⟧) (desuspend q≐E⟦qo⟧) e-view-E₁
(dcsuspend p≐E⟦rin⟧) (dcsuspend r≐E⟦ro⟧) rinsn⟶₁ro
with unwrap-rho ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧ (desuspend p≐E⟦qin⟧) (desuspend q≐E⟦qo⟧)
p≐E⟦qin⟧ q≐E⟦qo⟧ e-view-E₁
... | (ρθ·psn⟶₁ρθq·q , e-view) =
1-steplρ-E-view-ecin-lift cb' p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐E⟦rin⟧ r≐E⟦ro⟧ rinsn⟶₁ro
1-steplρ-E-view-ecin-lift {E₁ ∷ E} {ρθ·psn⟶₁ρθq·q = ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧}
cb@(CBtrap cb')
(detrap p≐E⟦qin⟧) (detrap q≐E⟦qo⟧) e-view-E₁
(dctrap p≐E⟦rin⟧) (dctrap r≐E⟦ro⟧) rinsn⟶₁ro
with unwrap-rho ρθ·E₁⟦p⟧sn⟶₁ρθq·E₁⟦q⟧ (detrap p≐E⟦qin⟧) (detrap q≐E⟦qo⟧)
p≐E⟦qin⟧ q≐E⟦qo⟧ e-view-E₁
... | (ρθ·psn⟶₁ρθq·q , e-view) =
1-steplρ-E-view-ecin-lift cb' p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐E⟦rin⟧ r≐E⟦ro⟧ rinsn⟶₁ro
|
{
"alphanum_fraction": 0.6027067669,
"avg_line_length": 36.5384615385,
"ext": "agda",
"hexsha": "acf83fb6edf6164190d771a3306272a5f7ff9def",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/sn-calculus-compatconf/in-lift.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"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": "florence/esterel-calculus",
"max_issues_repo_path": "agda/sn-calculus-compatconf/in-lift.agda",
"max_line_length": 82,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/sn-calculus-compatconf/in-lift.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 3841,
"size": 6650
}
|
-- Modified: Andreas, 2011-04-11 freezing metas, removed unused uni.poly
{-# OPTIONS --guardedness-preserving-type-constructors #-}
module UnusedArgsInPositivity where
open import Common.Coinduction
module Ex₁ where
data Unit : Set where
unit : Unit
unused : Set → Unit → Set → Set
unused X unit Y = Y
mutual
data D : Set where
d : (x : Unit) → (El x x → D) → D
El : Unit → Unit → Set
El unit x = unused D x Unit
module Ex₂ where
data Maybe (A : Set) : Set where
data Rec (A : ∞ Set) : Set where
fold : ♭ A → Rec A
mutual
data Data : Set where
maybe : ∞ Data -> Data
sigma : (A : Data) → (El A → Data) -> Data
El : Data → Set
El (maybe A) = Rec (♯ Maybe (El (♭ {A = Data} A)))
El (sigma A B) = El A
{- This fails for 2 reasons:
1. Rec doesn't preserve guardedness (hence -no-termination-check)
2. Data "appears" in the definition of El
The 1st one is now fixed.
It is not clear how to fix the 2nd. Irrelevant parameters?
-}
{-
/Users/txa/current/AIMXI/DataGuard.agda:15,8-12
Data is not strictly positive, because it occurs in the type of the
constructor sigma in the definition of Data, which occurs in the
second argument to ♭ in the first argument to El in the second
argument to Maybe in the first clause in the definition of
.DataGuard.♯-0, which occurs in the third clause in the definition
of El.
-}
module Ex₃ where
data D (A : Set) : Set where
d : D A
data E : Set where
e : (D E → E) → E
|
{
"alphanum_fraction": 0.643989432,
"avg_line_length": 23.65625,
"ext": "agda",
"hexsha": "d9966b8c74ca67e84939dcd3893caf5a9772e101",
"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/UnusedArgsInPositivity.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/UnusedArgsInPositivity.agda",
"max_line_length": 72,
"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/UnusedArgsInPositivity.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": 467,
"size": 1514
}
|
{-# OPTIONS --without-K #-}
module M-types.Base.Axiom where
open import M-types.Base.Core public
open import M-types.Base.Sum public
open import M-types.Base.Prod public
open import M-types.Base.Eq public
open import M-types.Base.Equi public
postulate
funext-axiom : {X : Ty ℓ₀} {Y : X → Ty ℓ₁} {f₀ f₁ : ∏ X Y} →
IsEqui {_} {_} {f₀ ≡ f₁} {∏[ x ∈ X ] f₀ x ≡ f₁ x} (≡-apply)
funext : {X : Ty ℓ₀} {Y : X → Ty ℓ₁} {f₀ f₁ : ∏ X Y} →
(∏[ x ∈ X ] f₀ x ≡ f₁ x) → f₀ ≡ f₁
funext = inv (≡-apply , funext-axiom)
|
{
"alphanum_fraction": 0.5467372134,
"avg_line_length": 29.8421052632,
"ext": "agda",
"hexsha": "c96a1b86175e13a129db7484e48d66235f406037",
"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": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DDOtten/M-types",
"max_forks_repo_path": "Base/Axiom.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"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": "DDOtten/M-types",
"max_issues_repo_path": "Base/Axiom.agda",
"max_line_length": 71,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DDOtten/M-types",
"max_stars_repo_path": "Base/Axiom.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 223,
"size": 567
}
|
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary.Product where
-- Stdlib imports
open import Level using (Level; _⊔_)
open import Function using (flip)
open import Data.Product using (_×_; _,_; map₁; map₂)
open import Relation.Unary using (Pred; _∈_)
open import Relation.Binary using (REL; Rel)
-- Local imports
open import Dodo.Unary.Equality
open import Dodo.Binary.Equality
open import Dodo.Binary.Domain
open import Dodo.Binary.Composition
infix 40 _×₂_
_×₂_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
→ Pred A ℓ₁
→ Pred B ℓ₂
-----------------
→ REL A B (ℓ₁ ⊔ ℓ₂)
_×₂_ P Q x y = P x × Q y
-- ## Operations: ×₂ ##
module _ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b}
{d : Pred A ℓ₁} {r : Pred B ℓ₂} where
×₂-dom : ∀ {x : A} {y : B} → ( d ×₂ r ) x y → d x
×₂-dom (dx , ry) = dx
×₂-codom : ∀ {x : A} {y : B} → ( d ×₂ r ) x y → r y
×₂-codom (dx , ry) = ry
×₂-flip : ∀ {x : A} {y : B} → ( d ×₂ r ) x y → ( r ×₂ d ) y x
×₂-flip (dx , ry) = (ry , dx)
module _ {a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b}
{d₁ : Pred A ℓ₁} {d₂ : Pred A ℓ₂} {r₁ : Pred B ℓ₃} {r₂ : Pred B ℓ₄} where
×₂-lift : ( d₁ ⊆₁ d₂ ) → ( r₁ ⊆₁ r₂ ) → d₁ ×₂ r₁ ⊆₂ d₂ ×₂ r₂
×₂-lift f g = ⊆: lemma
where
lemma : d₁ ×₂ r₁ ⊆₂' d₂ ×₂ r₂
lemma x y (d₁x , r₁y) = (⊆₁-apply f d₁x , ⊆₁-apply g r₁y)
module _ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {R : REL A B ℓ₁}
{d : Pred A ℓ₂} {r : Pred B ℓ₃} where
×₂-applyˡ : R ⊆₂ ( d ×₂ r ) → {x : A} {y : B} → R x y → d x
×₂-applyˡ R⊆₂d×r Rxy = ×₂-dom {d = d} {r = r} (⊆₂-apply R⊆₂d×r Rxy)
×₂-apply-dom : R ⊆₂ (d ×₂ r) → {x : A} → x ∈ dom R → d x
×₂-apply-dom R⊆d×r (y , Rxy) = ×₂-applyˡ R⊆d×r Rxy
×₂-applyʳ : R ⊆₂ ( d ×₂ r ) → {x : A} {y : B} → R x y → r y
×₂-applyʳ R⊆₂d×r Rxy = ×₂-codom {d = d} {r = r} (⊆₂-apply R⊆₂d×r Rxy)
×₂-apply-codom : R ⊆₂ (d ×₂ r) → {y : B} → y ∈ codom R → r y
×₂-apply-codom R⊆d×r (x , Rxy) = ×₂-applyʳ R⊆d×r Rxy
module _ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b}
{Q : REL A B ℓ₁} {d : A → Set ℓ₂} {r : B → Set ℓ₃} where
×₂-flip-⊆₂ : Q ⊆₂ d ×₂ r → flip Q ⊆₂ r ×₂ d
×₂-flip-⊆₂ (⊆: Q⊆×) = ⊆: lemma
where
lemma : flip Q ⊆₂' r ×₂ d
lemma x y Qyx with Q⊆× y x Qyx
... | (dy , rx) = (rx , dy)
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a}
{R : Rel A ℓ₁} {P : Pred A ℓ₂} where
×₂-lift-udr :
udr R ⊆₁ P
-----------
→ R ⊆₂ P ×₂ P
×₂-lift-udr udrR⊆P = ⊆: lemma
where
lemma : R ⊆₂' P ×₂ P
lemma x y Rxy = ⊆₁-apply udrR⊆P (take-udrˡ R Rxy) , ⊆₁-apply udrR⊆P (take-udrʳ R Rxy)
module _ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b}
{R : REL A B ℓ₁} {P : Pred A ℓ₂} {Q : Pred B ℓ₃} where
×₂-lift-dom :
dom R ⊆₁ P
→ codom R ⊆₁ Q
------------
→ R ⊆₂ P ×₂ Q
×₂-lift-dom (⊆: dom⊆P) (⊆: codom⊆Q) = ⊆: lemma
where
lemma : R ⊆₂' P ×₂ Q
lemma x y Rxy = (dom⊆P x (take-dom R Rxy) , codom⊆Q y (take-codom R Rxy))
module _ {a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b}
{Q : REL A B ℓ₁} {d₁ : Pred A ℓ₂} {d₂ : Pred A ℓ₃} {r : B → Set ℓ₄} where
×₂-⊆ˡ :
d₁ ⊆₁ d₂
------------------
→ d₁ ×₂ r ⊆₂ d₂ ×₂ r
×₂-⊆ˡ d₁⊆d₂ = ⊆: lemma
where
lemma : d₁ ×₂ r ⊆₂' d₂ ×₂ r
lemma x y = map₁ (⊆₁-apply d₁⊆d₂)
module _ {a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b}
{Q : REL A B ℓ₁} {d : Pred A ℓ₂} {r₁ : Pred B ℓ₃} {r₂ : Pred B ℓ₄} where
×₂-⊆ʳ :
r₁ ⊆₁ r₂
------------------
→ d ×₂ r₁ ⊆₂ d ×₂ r₂
×₂-⊆ʳ r₁⊆r₂ = ⊆: lemma
where
lemma : d ×₂ r₁ ⊆₂' d ×₂ r₂
lemma x y = map₂ (⊆₁-apply r₁⊆r₂)
module _ {a b c ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c}
{d₁ : Pred A ℓ₁} {r₁ : Pred B ℓ₂} {d₂ : Pred B ℓ₃} {r₂ : Pred C ℓ₄} where
×₂-combine-⨾ : ( d₁ ×₂ r₁ ) ⨾ ( d₂ ×₂ r₂ ) ⊆₂ d₁ ×₂ r₂
×₂-combine-⨾ = ⊆: lemma
where
lemma : ( d₁ ×₂ r₁ ) ⨾ ( d₂ ×₂ r₂ ) ⊆₂' d₁ ×₂ r₂
lemma x y ((d₁x , r₁z) ⨾[ z ]⨾ (d₂z , r₂y)) = (d₁x , r₂y)
|
{
"alphanum_fraction": 0.4827323514,
"avg_line_length": 27.9290780142,
"ext": "agda",
"hexsha": "6e10758dbeeecc011692325a063e0a4423549e34",
"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": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Binary/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"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": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Binary/Product.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Binary/Product.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2060,
"size": 3938
}
|
------------------------------------------------------------------------
-- A memoising backend
------------------------------------------------------------------------
-- This code has bitrotted.
-- Following Frost/Szydlowski and Frost/Hafiz/Callaghan (but without
-- the left recursion fix). An improvement has been made: The user
-- does not have to insert memoisation annotations manually. Instead
-- all grammar nonterminals are memoised. This is perhaps a bit less
-- flexible, but less error-prone, since there is no need to guarantee
-- that all "keys" (arguments to the memoise combinator) are unique
-- (assuming that the nonterminal equality is strong enough).
open import Relation.Binary
import Relation.Binary.PropositionalEquality as PropEq
import Relation.Binary.PropositionalEquality1 as PropEq1
open PropEq using (_≡_)
open PropEq1 using (_≡₁_)
open import StructurallyRecursiveDescentParsing.Index
open import Data.Product as Prod
module StructurallyRecursiveDescentParsing.Memoised
-- In order to be able to store results in a memo table (and avoid
-- having to lift the table code to Set1) the result types have to
-- come from the following universe:
{Result : Set} (⟦_⟧ : Result → Set)
-- Nonterminals also have to be small enough:
{NT : Index → Result → Set} {LargeNT : NonTerminalType}
(resultType : ∀ {i r} → LargeNT i r → Result)
(resultTypeCorrect : ∀ {i r} (x : LargeNT i r) →
⟦ resultType x ⟧ ≡₁ r)
(notTooLarge : ∀ {i r} (x : LargeNT i r) → NT i (resultType x))
-- Furthermore nonterminals need to be ordered, so that they can be
-- used as memo table keys:
{_≈_ _<_ : Rel (∃₂ NT)}
(ntOrdered : IsStrictTotalOrder _≈_ _<_)
-- And the underlying equality needs to be strong enough:
(indicesEqual : _≈_ =[ (λ irx → (proj₁ irx , proj₁ (proj₂ irx))) ]⇒
_≡_ {Index × Result})
-- Token type:
{Tok : Set}
where
open import Data.Bool renaming (true to ⊤; false to ⊥)
import Data.Nat as Nat
open Nat using (ℕ; zero; suc; pred; z≤n; s≤s)
import Data.Nat.Properties as NatProp
open import Function using (_∘_; _on_)
import Data.Vec as Vec; open Vec using (Vec; []; _∷_)
import Data.List as List; open List using (List; []; _∷_)
open import Data.Sum
open import Data.Maybe
open import Relation.Binary.OrderMorphism hiding (_∘_)
open _⇒-Poset_
import Relation.Binary.On as On
import Relation.Binary.Props.StrictTotalOrder as STOProps
open STOProps NatProp.strictTotalOrder
import StructurallyRecursiveDescentParsing.Memoised.Monad as Monad
open import StructurallyRecursiveDescentParsing.Type
open import StructurallyRecursiveDescentParsing.Utilities
renaming (_∘_ to _∘′_)
------------------------------------------------------------------------
-- Some monotone functions
MonoFun : Set
MonoFun = poset ⇒-Poset poset
suc-mono : _≤_ =[ suc ]⇒ _≤_
suc-mono (inj₁ i<j) = inj₁ (s≤s i<j)
suc-mono (inj₂ ≡-refl) = inj₂ ≡-refl
pred-mono : _≤_ =[ pred ]⇒ _≤_
pred-mono (inj₁ (s≤s (z≤n {zero}))) = inj₂ PropEq.refl
pred-mono (inj₁ (s≤s (z≤n {suc j}))) = inj₁ (s≤s z≤n)
pred-mono (inj₁ (s≤s (s≤s i<j))) = inj₁ (s≤s i<j)
pred-mono (inj₂ PropEq.refl) = inj₂ PropEq.refl
sucM : MonoFun
sucM = record
{ fun = suc
; monotone = suc-mono
}
predM : MonoFun
predM = record
{ fun = pred
; monotone = pred-mono
}
maybePredM : Empty → MonoFun
maybePredM e = if e then id else predM
lemma : ∀ e pos → fun (maybePredM e) pos ≤ pos
lemma ⊤ pos = refl
lemma ⊥ zero = refl
lemma ⊥ (suc pos) = inj₁ (Poset.refl Nat.poset)
------------------------------------------------------------------------
-- Parser monad
data Key : MonoFun → Result → Set where
key : ∀ {e c r} (nt : NT (e ◇ c) r) → Key (maybePredM e) r
shuffle : ∃₂ Key → ∃₂ NT
shuffle (._ , _ , key x) = (, , x)
_≈K_ : Rel (∃₂ Key)
_≈K_ = _≈_ on shuffle
_<K_ : Rel (∃₂ Key)
_<K_ = _<_ on shuffle
ordered : IsStrictTotalOrder _≈K_ _<K_
ordered = On.isStrictTotalOrder shuffle ntOrdered
funsEqual : _≈K_ =[ proj₁ ]⇒ _≡_
funsEqual {(._ , _ , key _)} {(._ , _ , key _)} eq =
PropEq.cong (maybePredM ∘ empty ∘ proj₁) (indicesEqual eq)
resultsEqual : _≈K_ =[ (λ rfk → proj₁ (proj₂ rfk)) ]⇒ _≡_
resultsEqual {(._ , _ , key _)} {(._ , _ , key _)} eq =
PropEq.cong proj₂ (indicesEqual eq)
open Monad
(StrictTotalOrder.isStrictTotalOrder NatProp.strictTotalOrder)
(Vec Tok)
⟦_⟧
ordered
(λ {k₁} {k₂} → funsEqual {k₁} {k₂})
(λ {k₁} {k₂} → resultsEqual {k₁} {k₂})
open PM
renaming ( return to return′
; _>>=_ to _>>=′_
; _=<<_ to _=<<′_
; ∅ to fail′
; _∣_ to _∣′_
)
cast : ∀ {bnd f A₁ A₂} → A₁ ≡₁ A₂ → P bnd f A₁ → P bnd f A₂
cast refl p = p
------------------------------------------------------------------------
-- Run function for the parsers
-- Some helper functions.
private
-- Extracts the first element from the input, if any.
eat : ∀ {bnd} (inp : Input≤ bnd) →
Maybe Tok × Input≤ (pred (position inp))
eat {bnd} xs = helper (bounded xs) (string xs)
where
helper : ∀ {pos} → pos ≤ bnd → Vec Tok pos →
Maybe Tok × Input≤ (pred pos)
helper _ [] = (nothing , [] isBounded∶ refl)
helper le (c ∷ cs) = (just c , cs isBounded∶ refl)
-- Fails if it encounters nothing.
fromJust : ∀ {bnd} → Maybe Tok → P bnd idM Tok
fromJust nothing = fail′
fromJust (just c) = return′ c
-- For every successful parse the run function returns the remaining
-- string. (Since there can be several successful parses a list of
-- strings is returned.)
-- This function is structurally recursive with respect to the
-- following lexicographic measure:
--
-- 1) The upper bound of the length of the input string.
-- 2) The parser's proper left corner tree.
private
module Dummy (g : Grammar LargeNT Tok) where
mutual
parse : ∀ n {e c R} →
Parser LargeNT Tok (e ◇ c) R →
P n (if e then idM else predM) R
parse n (return x) = return′ x
parse n (_∣_ {⊤} p₁ p₂) = parse n p₁ ∣′ parse↑ n p₂
parse n (_∣_ {⊥} {⊤} p₁ p₂) = parse↑ n p₁ ∣′ parse n p₂
parse n (_∣_ {⊥} {⊥} p₁ p₂) = parse n p₁ ∣′ parse n p₂
parse n (p₁ ?>>= p₂) = parse n p₁ >>=′ parse n ∘′ p₂
parse (suc n) (p₁ !>>= p₂) = parse (suc n) p₁ >>=′ parse↑ n ∘′ p₂
parse zero (p₁ !>>= p₂) = fail′
parse n fail = fail′
parse n token = fromJust =<<′ gmodify predM eat
parse n (! x) = memoParse n x
parse↑ : ∀ n {e c R} → Parser LargeNT Tok (e ◇ c) R → P n idM R
parse↑ n {e} p = adjustBound (lemma e) (parse n p)
memoParse : ∀ n {R e c} → LargeNT (e ◇ c) R →
P n (if e then idM else predM) R
memoParse n x = cast₁ (memoise k (cast₂ (parse n (g x))))
where
k = key (notTooLarge x)
cast₁ = cast (resultTypeCorrect x)
cast₂ = cast (sym (resultTypeCorrect x))
-- Exported run function.
parse : ∀ {i R} →
Grammar LargeNT Tok → Parser LargeNT Tok i R →
List Tok → List (R × List Tok)
parse g p toks =
List.map (Prod.map id (λ xs → Vec.toList (string xs))) $
run (Vec.fromList toks) (Dummy.parse g _ p)
-- A variant which only returns parses which leave no remaining input.
parse-complete : ∀ {i R} →
Grammar Tok LargeNT → Parser Tok LargeNT i R →
List Tok → List R
parse-complete g p s =
List.map proj₁ (List.filter (List.null ∘ proj₂) (parse g p s))
|
{
"alphanum_fraction": 0.5865775331,
"avg_line_length": 32.3262711864,
"ext": "agda",
"hexsha": "8cf8a7ec78c12813ff550825d305ba9b295208b0",
"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": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "StructurallyRecursiveDescentParsing/Memoised.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "StructurallyRecursiveDescentParsing/Memoised.agda",
"max_line_length": 76,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "StructurallyRecursiveDescentParsing/Memoised.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 2427,
"size": 7629
}
|
{-# OPTIONS --cubical-compatible --rewriting --confluence-check #-}
postulate
_↦_ : {A : Set} → A → A → Set
{-# BUILTIN REWRITE _↦_ #-}
data _==_ {A : Set} (a : A) : A → Set where
idp : a == a
PathOver : {A : Set} (B : A → Set)
{x y : A} (p : x == y) (u : B x) (v : B y) → Set
PathOver B idp u v = (u == v)
infix 30 PathOver
syntax PathOver B p u v =
u == v [ B ↓ p ]
apd : {A : Set} {B : A → Set} (f : (a : A) → B a) {x y : A}
→ (p : x == y) → f x == f y [ B ↓ p ]
apd f idp = idp
module Disk where
module _ where
postulate -- HIT
Disk : Set
baseD : Disk
loopD : baseD == baseD
drumD : loopD == idp
module DiskElim {P : Disk → Set}
(baseD* : P baseD )
(loopD* : baseD* == baseD* [ P ↓ loopD ] )
(drumD* : loopD* == idp [ ((λ p → baseD* == baseD* [ P ↓ p ] ) ) ↓ drumD ] ) where
postulate
f : (x : Disk) → P x
baseD-β : f baseD ↦ baseD*
{-# REWRITE baseD-β #-}
postulate
loopD-ι : apd f loopD ↦ loopD*
{-# REWRITE loopD-ι #-}
postulate
drumD-ι : apd (apd f) drumD ↦ drumD*
{-# REWRITE drumD-ι #-}
loopD-β : apd f loopD == loopD*
loopD-β = idp
drumD-β : apd (apd f) drumD == drumD*
drumD-β = idp
|
{
"alphanum_fraction": 0.4954806902,
"avg_line_length": 22.1272727273,
"ext": "agda",
"hexsha": "d5d3791987707f96c39ff37161420e4b4b7a8d82",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue2549.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue2549.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue2549.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 498,
"size": 1217
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
open import Algebra
module Algebra.Properties.Ring {r₁ r₂} (R : Ring r₁ r₂) where
import Algebra.Properties.AbelianGroup as AGP
open import Data.Product
open import Function
import Relation.Binary.EqReasoning as EqR
open Ring R
open EqR setoid
open AGP +-abelianGroup public
renaming ( ⁻¹-involutive to -‿involutive
; left-identity-unique to +-left-identity-unique
; right-identity-unique to +-right-identity-unique
; identity-unique to +-identity-unique
; left-inverse-unique to +-left-inverse-unique
; right-inverse-unique to +-right-inverse-unique
; ⁻¹-∙-comm to -‿+-comm
)
-‿*-distribˡ : ∀ x y → - x * y ≈ - (x * y)
-‿*-distribˡ x y = begin
- x * y ≈⟨ sym $ proj₂ +-identity _ ⟩
- x * y + 0# ≈⟨ refl ⟨ +-cong ⟩ sym (proj₂ -‿inverse _) ⟩
- x * y + (x * y + - (x * y)) ≈⟨ sym $ +-assoc _ _ _ ⟩
- x * y + x * y + - (x * y) ≈⟨ sym (proj₂ distrib _ _ _) ⟨ +-cong ⟩ refl ⟩
(- x + x) * y + - (x * y) ≈⟨ (proj₁ -‿inverse _ ⟨ *-cong ⟩ refl)
⟨ +-cong ⟩
refl ⟩
0# * y + - (x * y) ≈⟨ proj₁ zero _ ⟨ +-cong ⟩ refl ⟩
0# + - (x * y) ≈⟨ proj₁ +-identity _ ⟩
- (x * y) ∎
-‿*-distribʳ : ∀ x y → x * - y ≈ - (x * y)
-‿*-distribʳ x y = begin
x * - y ≈⟨ sym $ proj₁ +-identity _ ⟩
0# + x * - y ≈⟨ sym (proj₁ -‿inverse _) ⟨ +-cong ⟩ refl ⟩
- (x * y) + x * y + x * - y ≈⟨ +-assoc _ _ _ ⟩
- (x * y) + (x * y + x * - y) ≈⟨ refl ⟨ +-cong ⟩ sym (proj₁ distrib _ _ _) ⟩
- (x * y) + x * (y + - y) ≈⟨ refl ⟨ +-cong ⟩ (refl ⟨ *-cong ⟩ proj₂ -‿inverse _) ⟩
- (x * y) + x * 0# ≈⟨ refl ⟨ +-cong ⟩ proj₂ zero _ ⟩
- (x * y) + 0# ≈⟨ proj₂ +-identity _ ⟩
- (x * y) ∎
|
{
"alphanum_fraction": 0.4163150492,
"avg_line_length": 41.0192307692,
"ext": "agda",
"hexsha": "84ef44d4a2af053673ead20175db8a67136ed287",
"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": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Algebra/Properties/Ring.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Algebra/Properties/Ring.agda",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Algebra/Properties/Ring.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 755,
"size": 2133
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Polynomials.Multivariate.EquivCarac.An[X]X-A where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order
open import Cubical.Data.Vec
open import Cubical.Data.Vec.OperationsNat
open import Cubical.Data.Sigma
open import Cubical.Data.FinData
open import Cubical.Data.Empty as ⊥
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.QuotientRing
open import Cubical.Algebra.Polynomials.Multivariate.Base
open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤCommRing to ℤCR)
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-Quotient
open import Cubical.Relation.Nullary
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
private variable
ℓ : Level
-----------------------------------------------------------------------------
-- Functions
module Properties-Equiv-QuotientXn-A
(Ar@(A , Astr) : CommRing ℓ)
(n : ℕ)
where
open CommRingStr Astr using ()
renaming
( 0r to 0A
; 1r to 1A
; _+_ to _+A_
; -_ to -A_
; _·_ to _·A_
; +Assoc to +AAssoc
; +Identity to +AIdentity
; +Lid to +ALid
; +Rid to +ARid
; +Inv to +AInv
; +Linv to +ALinv
; +Rinv to +ARinv
; +Comm to +AComm
; ·Assoc to ·AAssoc
; ·Identity to ·AIdentity
; ·Lid to ·ALid
; ·Rid to ·ARid
; ·Rdist+ to ·ARdist+
; ·Ldist+ to ·ALdist+
; is-set to isSetA )
open CommRingStr (snd (A[X1,···,Xn] Ar n) ) using ()
renaming
( 0r to 0PA
; 1r to 1PA
; _+_ to _+PA_
; -_ to -PA_
; _·_ to _·PA_
; +Assoc to +PAAssoc
; +Identity to +PAIdentity
; +Lid to +PALid
; +Rid to +PARid
; +Inv to +PAInv
; +Linv to +PALinv
; +Rinv to +PARinv
; +Comm to +PAComm
; ·Assoc to ·PAAssoc
; ·Identity to ·PAIdentity
; ·Lid to ·PALid
; ·Rid to ·PARid
; ·Comm to ·PAComm
; ·Rdist+ to ·PARdist+
; ·Ldist+ to ·PALdist+
; is-set to isSetPA )
open CommRingStr (snd (A[X1,···,Xn]/<X1,···,Xn> Ar n)) using ()
renaming
( 0r to 0PAI
; 1r to 1PAI
; _+_ to _+PAI_
; -_ to -PAI_
; _·_ to _·PAI_
; +Assoc to +PAIAssoc
; +Identity to +PAIIdentity
; +Lid to +PAILid
; +Rid to +PAIRid
; +Inv to +PAIInv
; +Linv to +PAILinv
; +Rinv to +PAIRinv
; +Comm to +PAIComm
; ·Assoc to ·PAIAssoc
; ·Identity to ·PAIIdentity
; ·Lid to ·PAILid
; ·Rid to ·PAIRid
; ·Rdist+ to ·PAIRdist+
; ·Ldist+ to ·PAILdist+
; is-set to isSetPAI )
open RingTheory
discreteVecℕn = VecPath.discreteA→discreteVecA discreteℕ n
-----------------------------------------------------------------------------
-- Direct sens
PA→A : A[x1,···,xn] Ar n → A
PA→A = Poly-Rec-Set.f Ar n _ isSetA
0A
base-trad
_+A_
+AAssoc
+ARid
+AComm
base-0P-eq
base-Poly+-eq
where
base-trad : (v : Vec ℕ n) → (a : A) → A
base-trad v a with (discreteVecℕn v (replicate 0))
... | yes p = a
... | no ¬p = 0A
base-0P-eq : (v : Vec ℕ n) → base-trad v 0A ≡ 0A
base-0P-eq v with (discreteVecℕn v (replicate 0))
... | yes p = refl
... | no ¬p = refl
base-Poly+-eq : (v : Vec ℕ n) → (a b : A) → base-trad v a +A base-trad v b ≡ base-trad v (a +A b)
base-Poly+-eq v a b with (discreteVecℕn v (replicate 0))
... | yes p = refl
... | no ¬p = +ARid _
PA→A-pres1 : PA→A 1PA ≡ 1A
PA→A-pres1 with (discreteVecℕn (replicate 0) (replicate 0))
... | yes p = refl
... | no ¬p = ⊥.rec (¬p refl)
PA→A-pres+ : (P Q : A[x1,···,xn] Ar n) → PA→A (P +PA Q) ≡ PA→A P +A PA→A Q
PA→A-pres+ P Q = refl
PA→A-pres· : (P Q : A[x1,···,xn] Ar n) → PA→A (P ·PA Q) ≡ PA→A P ·A PA→A Q
PA→A-pres· = Poly-Ind-Prop.f _ _ _
(λ P u v i Q → isSetA _ _ (u Q) (v Q) i)
(λ Q → sym (0LeftAnnihilates (CommRing→Ring Ar) _))
(λ v a → Poly-Ind-Prop.f _ _ _ (λ Q → isSetA _ _)
(sym (0RightAnnihilates (CommRing→Ring Ar) _))
(λ v' a' → base-base-eq a a' v v')
λ {U V} ind-U ind-V → cong₂ _+A_ ind-U ind-V ∙ sym (·ARdist+ _ _ _))
λ {U V} ind-U ind-V Q → cong₂ _+A_ (ind-U Q) (ind-V Q) ∙ sym (·ALdist+ _ _ _)
where
base-base-eq : (a a' : A) → (v v' : Vec ℕ n) →
PA→A (base v a ·PA base v' a') ≡ PA→A (base v a) ·A PA→A (base v' a')
base-base-eq a a' v v' with (discreteVecℕn (v +n-vec v') (replicate 0))
| (discreteVecℕn v (replicate 0))
| (discreteVecℕn v' (replicate 0))
... | yes r | yes p | yes e = refl
... | yes r | yes p | no ¬q = ⊥.rec (¬q (snd (+n-vecSplitReplicate0 v v' r)))
... | yes r | no ¬p | q = ⊥.rec (¬p (fst (+n-vecSplitReplicate0 v v' r)))
... | no ¬r | yes p | yes q = ⊥.rec (¬r (cong₂ _+n-vec_ p q ∙ +n-vec-rid _))
... | no ¬r | yes p | no ¬q = sym (0RightAnnihilates (CommRing→Ring Ar) _)
... | no ¬r | no ¬p | yes q = sym (0LeftAnnihilates (CommRing→Ring Ar) _)
... | no ¬r | no ¬p | no ¬q = sym (0RightAnnihilates (CommRing→Ring Ar) _)
PA→A-cancel : (k : Fin n) → PA→A (<X1,···,Xn> Ar n k) ≡ 0A
PA→A-cancel k with (discreteVecℕn (δℕ-Vec n (toℕ k)) (replicate 0))
... | yes p = ⊥.rec (δℕ-Vec-k<n→≢ n (toℕ k) (toℕ<n k) p)
... | no ¬p = refl
PAr→Ar : CommRingHom (A[X1,···,Xn] Ar n) Ar
fst PAr→Ar = PA→A
snd PAr→Ar = makeIsRingHom PA→A-pres1 PA→A-pres+ PA→A-pres·
PAIr→Ar : CommRingHom (A[X1,···,Xn]/<X1,···,Xn> Ar n) Ar
PAIr→Ar = Quotient-FGideal-CommRing-CommRing.f (A[X1,···,Xn] Ar n) Ar PAr→Ar (<X1,···,Xn> Ar n) PA→A-cancel
PAI→A : A[x1,···,xn]/<x1,···,xn> Ar n → A
PAI→A = fst PAIr→Ar
-----------------------------------------------------------------------------
-- Converse sens
A→PA : A → A[x1,···,xn] Ar n
A→PA a = (base (replicate 0) a)
A→PA-pres1 : A→PA 1A ≡ 1PA
A→PA-pres1 = refl
A→PA-pres+ : (a a' : A) → A→PA (a +A a') ≡ (A→PA a) +PA (A→PA a')
A→PA-pres+ a a' = sym (base-poly+ _ _ _)
A→PA-pres· : (a a' : A) → A→PA (a ·A a') ≡ (A→PA a) ·PA (A→PA a')
A→PA-pres· a a' = cong (λ X → base X (a ·A a')) (sym (+n-vec-rid _))
A→PAI : A → (A[x1,···,xn]/<x1,···,xn> Ar n)
A→PAI = [_] ∘ A→PA
-----------------------------------------------------------------------------
-- Section
e-sect : (a : A) → PAI→A (A→PAI a) ≡ a
e-sect a with (discreteVecℕn (replicate 0) (replicate 0))
... | yes p = refl
... | no ¬p = ⊥.rec (¬p refl)
-----------------------------------------------------------------------------
-- Retraction
open RingStr
open IsRing
e-retr : (x : A[x1,···,xn]/<x1,···,xn> Ar n) → A→PAI (PAI→A x) ≡ x
e-retr = SQ.elimProp (λ _ → isSetPAI _ _)
(Poly-Ind-Prop.f _ _ _ (λ _ → isSetPAI _ _)
base0-eq
base-eq
λ {U V} ind-U ind-V → cong [_] (A→PA-pres+ _ _) ∙ cong₂ _+PAI_ ind-U ind-V)
where
base0-eq : A→PAI (PAI→A [ 0P ]) ≡ [ 0P ]
base0-eq = cong [_] (base-0P (replicate 0))
base-eq : (v : Vec ℕ n) → (a : A ) → [ A→PA (PA→A (base v a)) ] ≡ [ base v a ]
base-eq v a with (discreteVecℕn v (replicate 0))
... | yes p = cong [_] (cong (λ X → base X a) (sym p))
... | no ¬p with (pred-vec-≢0 v ¬p)
... | k , v' , infkn , eqvv' = eq/ (base (replicate 0) 0A)
(base v a) ∣ ((genδ-FinVec n k (base v' (-A a)) 0PA) , helper) ∣₁
where
helper : _
helper = cong (λ X → X poly+ base v (-A a)) (base-0P (replicate 0))
∙ +PALid (base v (-A a))
∙ sym (
genδ-FinVec-ℕLinearCombi ((A[X1,···,Xn] Ar n)) n k infkn (base v' (-A a)) (<X1,···,Xn> Ar n)
∙ cong₂ base (cong (λ X → v' +n-vec δℕ-Vec n X) (toFromId' n k infkn)) (·ARid _)
∙ cong (λ X → base X (-A a)) (sym eqvv'))
-----------------------------------------------------------------------------
-- Equiv
module _
(Ar@(A , Astr) : CommRing ℓ)
(n : ℕ)
where
open Iso
open Properties-Equiv-QuotientXn-A Ar n
Equiv-QuotientX-A : CommRingEquiv (A[X1,···,Xn]/<X1,···,Xn> Ar n) Ar
fst Equiv-QuotientX-A = isoToEquiv is
where
is : Iso (A[x1,···,xn]/<x1,···,xn> Ar n) A
fun is = PAI→A
inv is = A→PAI
rightInv is = e-sect
leftInv is = e-retr
snd Equiv-QuotientX-A = snd PAIr→Ar
-- Warning this doesn't prove Z[X]/X ≅ ℤ because you get two definition,
-- see notation Multivariate-Quotient-notationZ for more details
|
{
"alphanum_fraction": 0.485479798,
"avg_line_length": 33.5830388693,
"ext": "agda",
"hexsha": "bc79ade974622cab08783493c39ccac10387693a",
"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": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xekoukou/cubical",
"max_forks_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/An[X]X-A.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"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": "xekoukou/cubical",
"max_issues_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/An[X]X-A.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xekoukou/cubical",
"max_stars_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/An[X]X-A.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3517,
"size": 9504
}
|
open import Categories
open import Functors
open import RMonads
module RMonads.CatofRAdj.TermRAdjHom {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}
{J : Fun C D}(M : RMonad J) where
open import Library
open import RAdjunctions
open import RMonads.CatofRAdj M
open import Categories.Terminal
open import RMonads.REM M
open import RMonads.REM.Adjunction M
open import RAdjunctions.RAdj2RMon
open import RMonads.CatofRAdj.TermRAdjObj M
open Cat
open Fun
open RAdj
alaw1lem : ∀{e f}{E : Cat {e}{f}}(T : Fun C D)(L : Fun C E)(R : Fun E D)
(p : R ○ L ≅ T)
(η : ∀ {X} → Hom D (OMap J X) (OMap T X)) →
(right : ∀ {X Y} → Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y) →
(left : ∀ {X Y} → Hom E (OMap L X) Y → Hom D (OMap J X) (OMap R Y)) →
(ηlaw : ∀ {X} → left (iden E {OMap L X}) ≅ η {X}) →
∀ {X}{Z}{f : Hom D (OMap J Z) (OMap R X)} →
(nat : comp D (HMap R (right f)) (comp D (left (iden E)) (HMap J (iden C)))
≅
left (comp E (right f) (comp E (iden E) (HMap L (iden C))))) →
(lawb : left (right f) ≅ f) →
f
≅
comp D (subst (λ Z → Hom D Z (OMap R X))
(fcong Z (cong OMap p))
(HMap R (right f)))
η
alaw1lem {E = E} .(R ○ L) L R refl η right left ηlaw {X}{Z}{f} nat lawb =
trans (trans (trans (sym lawb)
(cong left
(trans (sym (idr E))
(cong (comp E (right f))
(trans (sym (fid L))
(sym (idl E)))))))
(trans (sym nat)
(cong (comp D (HMap R (right f)))
(trans (cong (comp D (left (iden E))) (fid J))
(idr D)))))
(cong (comp D (HMap R (right f))) ηlaw)
alaw2lem : ∀{e f}{E : Cat {e}{f}}(T : Fun C D)(L : Fun C E)(R : Fun E D)
(p : R ○ L ≅ T) →
(right : ∀ {X Y} → Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y) →
(bind : ∀{X Y} →
Hom D (OMap J X) (OMap T Y) → Hom D (OMap T X) (OMap T Y)) →
(natright : {X X' : Obj C} {Y Y' : Obj E} (f : Hom C X' X)
(g : Hom E Y Y') (h : Hom D (OMap J X) (OMap R Y)) →
right (comp D (HMap R g) (comp D h (HMap J f)))
≅
comp E g (comp E (right h) (HMap L f))) →
∀{X}{Z}{W}
{k : Hom D (OMap J Z) (OMap T W)}
{f : Hom D (OMap J W) (OMap R X)} →
(bindlaw : HMap R (right (subst (Hom D (OMap J Z))
(fcong W (cong OMap (sym p)))
k))
≅
bind k) →
subst (λ Z → Hom D Z (OMap R X))
(fcong Z (cong OMap p))
(HMap R
(right
(comp D
(subst (λ Z → Hom D Z (OMap R X))
(fcong W (cong OMap p)) (HMap R (right f)))
k)))
≅
comp D
(subst (λ Z → Hom D Z (OMap R X))
(fcong W (cong OMap p)) (HMap R (right f)))
(bind k)
alaw2lem {E = E} .(R ○ L) L R refl right bind natright {k = k}{f = f} bl =
trans (trans (cong (HMap R)
(trans (cong (λ k → right (comp D (HMap R (right f)) k))
(trans (sym (idr D)) (cong (comp D k)
(sym (fid J)))))
(trans (trans (natright (iden C) (right f) k)
(trans (sym (ass E))
(cong (comp E
(comp E
(right f)
(right k)))
(fid L))))
(idr E))))
(fcomp R))
(cong (comp D (HMap R (right f))) bl)
ahomlem : ∀{e f}{E : Cat {e}{f}}(T : Fun C D)(L : Fun C E)(R : Fun E D)
(p : R ○ L ≅ T) →
(right : ∀ {X Y} → Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y) →
(natright : {X X' : Obj C} {Y Y' : Obj E} (f : Hom C X' X)
(g : Hom E Y Y') (h : Hom D (OMap J X) (OMap R Y)) →
right (comp D (HMap R g) (comp D h (HMap J f)))
≅
comp E g (comp E (right h) (HMap L f))) →
{X : Obj E}{Y : Obj E}{f : Hom E X Y} →
{Z : Obj C} {g : Hom D (OMap J Z) (OMap R X)} →
comp D (HMap R f)
(subst (λ Z → Hom D Z (OMap R X))
(fcong Z (cong OMap p))
(HMap R (right g)))
≅
subst (λ Z → Hom D Z (OMap R Y))
(fcong Z (cong OMap p))
(HMap R (right (comp D (HMap R f) g)))
ahomlem {E = E} .(R ○ L) L R refl right natright {X}{Y}{f}{Z}{g} =
trans (sym (fcomp R))
(cong (HMap R)
(trans (trans (sym (idr E))
(trans (cong (comp E (comp E f (right g)))
(sym (fid L)))
(trans (ass E)
(sym (natright (iden C) f g)))))
(cong (λ g → right (comp D (HMap R f) g))
(trans (cong (comp D g) (fid J)) (idr D)))))
open ObjAdj
Llawlem : ∀{e f}{E : Cat {e}{f}}(T : Fun C D)(L : Fun C E)(R : Fun E D)
(p : R ○ L ≅ T) →
(right : ∀{X Y} → Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y) →
(bind : ∀{X Y} →
Hom D (OMap J X) (OMap T Y) → Hom D (OMap T X) (OMap T Y)) →
(bindlaw : {X Y : Obj C} {f : Hom D (OMap J X) (OMap T Y)} →
HMap R
(right
(subst (Hom D (OMap J X)) (fcong Y (cong OMap (sym p))) f))
≅ bind f) →
∀{X Z} →
{f : Hom D (OMap J Z) (OMap R (OMap L X))}
{f' : Hom D (OMap J Z) (OMap T X)} → (q : f ≅ f') →
subst (λ Z → Hom D Z (OMap R (OMap L X)))
(fcong Z (cong OMap p)) (HMap R (right f))
≅ bind f'
Llawlem .(R ○ L) L R refl right bind bindlaw {X}{Z}{f}{.f} refl = bindlaw
K : ∀{e f}(A : Obj (CatofAdj {e}{f})) → Fun (E A) (E EMObj)
K A = record {
OMap = λ X → record {
acar = OMap (R (adj A)) X;
astr = λ {Z} f →
subst (λ Z₁ → Hom D Z₁ (OMap (R (adj A)) X))
(fcong Z (cong OMap (law A)))
(HMap (R (adj A)) (right (adj A) f));
alaw1 = λ {Z} {f} →
alaw1lem
(TFun M)
(L (adj A))
(R (adj A))
(law A)
η
(right (adj A))
(left (adj A))
(ηlaw A)
(natleft (adj A) (iden C) (right (adj A) f) (iden (E A)))
(lawb (adj A) f);
alaw2 = λ {Z} {W} {k} {f} →
alaw2lem
(TFun M)
(L (adj A))
(R (adj A))
(law A)
(right (adj A))
bind
(natright (adj A))
(bindlaw A {_} {_} {k})};
HMap = λ {X} {Y} f → record {
amor = HMap (R (adj A)) f;
ahom = λ {Z} {g} →
ahomlem
(TFun M)
(L (adj A))
(R (adj A))
(law A)
(right (adj A))
(natright (adj A)) };
fid = RAlgMorphEq (fid (R (adj A)));
fcomp = RAlgMorphEq (fcomp (R (adj A)))}
where open RMonad M
Llaw' : ∀{e f}(A : Obj (CatofAdj {e}{f})) →
K A ○ L (adj A) ≅ L (adj EMObj)
Llaw' A = FunctorEq _ _
(ext λ X → AlgEq (fcong X (cong OMap (law A)))
(iext λ Z → dext λ {f} {f'} →
Llawlem (TFun M)
(L (adj A))
(R (adj A))
(law A)
(right (adj A))
bind
(bindlaw A)))
(iext λ X → iext λ Y → ext λ f →
lemZ
(AlgEq (fcong X (cong OMap (law A)))
(iext λ Z →
dext
(Llawlem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A))
bind (bindlaw A))))
(AlgEq (fcong Y (cong OMap (law A)))
(iext λ Z →
dext
(Llawlem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A))
bind (bindlaw A))))
(cong' refl
(ext
(λ _ →
cong₂ (Hom D) (fcong X (cong OMap (law A)))
(fcong Y (cong OMap (law A)))))
(icong' refl
(ext
(λ Z →
cong₂ (λ x y → Hom C X Z → Hom D x y) (fcong X (cong OMap (law A)))
(fcong Z (cong OMap (law A)))))
(icong' refl
(ext
(λ Z →
cong
(λ (F : Obj C → Obj D) →
{Y₁ : Obj C} → Hom C Z Y₁ → Hom D (F Z) (F Y₁))
(cong OMap (law A))))
(cong HMap (law A)) (refl {x = X}))
(refl {x = Y}))
(refl {x = f})))
where open RMonad M
Rlaw' : ∀{e f}(A : Obj (CatofAdj {e}{f})) →
R (adj A) ≅ R (adj EMObj) ○ K A
Rlaw' A = FunctorEq _ _ refl refl
rightlaw' : ∀{e f}(A : Obj (CatofAdj {e}{f})) →
{X : Obj C}{Y : Obj (E A)} →
{f : Hom D (OMap J X) (OMap (R (adj A)) Y)} →
HMap (K A) (right (adj A) f)
≅
right (adj EMObj) {X} {OMap (K A) Y}
(subst (Hom D (OMap J X)) (fcong Y (cong OMap (Rlaw' A))) f)
rightlaw' A {X}{Y}{f} = lemZ
(AlgEq (fcong X (cong OMap (law A)))
(iext λ Z →
dext
(λ {g} {g'} p →
Llawlem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A))
bind (bindlaw A) p)))
refl
(trans
(cong
(λ (f₁ : Hom D (OMap J X) (OMap (R (adj A)) Y)) →
HMap (R (adj A)) (right (adj A) f₁))
(sym
(stripsubst (Hom D (OMap J X)) f
(fcong Y (cong OMap (Rlaw' A))))))
(sym
(stripsubst (λ (Z : Obj D) → Hom D Z (OMap (R (adj A)) Y)) _
(fcong X (cong OMap (law A))))))
where open RMonad M
EMHom : {A : Obj CatofAdj} → Hom CatofAdj A EMObj
EMHom {A} = record {
K = K A;
Llaw = Llaw' A;
Rlaw = Rlaw' A;
rightlaw = rightlaw' A }
-- -}
|
{
"alphanum_fraction": 0.3994931576,
"avg_line_length": 35.3584229391,
"ext": "agda",
"hexsha": "9ec22c194427b303c94f0017a3eac2c2c75b7f1b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "RMonads/CatofRAdj/TermRAdjHom.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "RMonads/CatofRAdj/TermRAdjHom.agda",
"max_line_length": 79,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "RMonads/CatofRAdj/TermRAdjHom.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 3623,
"size": 9865
}
|
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Data.NatMinusOne.Base where
open import Cubical.Core.Primitives
open import Cubical.Data.Nat
open import Cubical.Data.Empty
record ℕ₋₁ : Type₀ where
constructor -1+_
field
n : ℕ
pattern neg1 = -1+ zero
pattern ℕ→ℕ₋₁ n = -1+ (suc n)
1+_ : ℕ₋₁ → ℕ
1+_ (-1+ n) = n
suc₋₁ : ℕ₋₁ → ℕ₋₁
suc₋₁ (-1+ n) = -1+ (suc n)
-- Natural number and negative integer literals for ℕ₋₁
open import Cubical.Data.Nat.Literals public
instance
fromNatℕ₋₁ : HasFromNat ℕ₋₁
fromNatℕ₋₁ = record { Constraint = λ _ → Unit ; fromNat = ℕ→ℕ₋₁ }
instance
fromNegℕ₋₁ : HasFromNeg ℕ₋₁
fromNegℕ₋₁ = record { Constraint = λ { (suc (suc _)) → ⊥ ; _ → Unit }
; fromNeg = λ { zero → 0 ; (suc zero) → neg1 } }
|
{
"alphanum_fraction": 0.6295369212,
"avg_line_length": 23.5,
"ext": "agda",
"hexsha": "fd3c36d46cfbb755fa40843e43b4b44471391841",
"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/NatMinusOne/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/NatMinusOne/Base.agda",
"max_line_length": 71,
"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/NatMinusOne/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 303,
"size": 799
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.ChainComplex
open import cohomology.Theory
open import groups.KernelImage
open import cw.CW
module cw.cohomology.ReconstructedCohomologyGroups {i : ULevel} (OT : OrdinaryTheory i) where
open OrdinaryTheory OT
open import cw.cohomology.Descending OT
open import cw.cohomology.ReconstructedCochainComplex OT
open import cw.cohomology.ReconstructedZerothCohomologyGroup OT
open import cw.cohomology.ReconstructedFirstCohomologyGroup OT
open import cw.cohomology.ReconstructedHigherCohomologyGroups OT
abstract
reconstructed-cohomology-group : ∀ m {n} (⊙skel : ⊙Skeleton {i} n)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ C m ⊙⟦ ⊙skel ⟧ ≃ᴳ cohomology-group (cochain-complex ⊙skel) m
reconstructed-cohomology-group (pos 0) ⊙skel ac =
zeroth-cohomology-group ⊙skel ac
reconstructed-cohomology-group (pos 1) ⊙skel ac =
first-cohomology-group ⊙skel ac
reconstructed-cohomology-group (pos (S (S m))) ⊙skel ac =
higher-cohomology-group m ⊙skel ac
reconstructed-cohomology-group (negsucc m) ⊙skel ac =
lift-iso {j = i} ∘eᴳ trivial-iso-0ᴳ (C-cw-at-negsucc ⊙skel m ac)
|
{
"alphanum_fraction": 0.7398171239,
"avg_line_length": 40.1,
"ext": "agda",
"hexsha": "1a7e720991d776b984ded657cb7d23495468c150",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/ReconstructedCohomologyGroups.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"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": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/ReconstructedCohomologyGroups.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/ReconstructedCohomologyGroups.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 389,
"size": 1203
}
|
module Qsort where
open import Sec4 -- The module with definition of propositions
import Sec2
-- postulate needed for ≤ on A
postulate leq : {A : Set} → A → A → Prop
postulate geq : {A : Set} → A → A → Prop
postulate tot-list : {A : Set} → (a b : A) → (leq a b) ∨ (leq b a)
postulate trans-list : {A : Set} → (a b c : A) → (leq a b) → (leq b c) → (leq a c)
{-
Definition of a list
-}
data List (A : Set) : Set where
[] : List A -- Empty list
_∷_ : A → List A → List A -- Cons
-- Proposition stating what is a non empty list
nelist : {A : Set} → (List A) → Prop
nelist [] = ⊥
nelist (x ∷ x₁) = ⊤
-- Head function that only works on non empty list
head : {A : Set} → (l : List A) → (p : nelist l) → A
head [] () -- This can never happen
head (x ∷ _) ⋆ = x -- This is the head of the list
-- The tail of the list only works on non empty list
tail : {A : Set} → (l : List A) → (p : nelist l) → (List A)
tail [] ()
tail (_ ∷ l) ⋆ = l
data Bool : Set where
True : Bool
False : Bool
data ℕ : Set where
Z : ℕ
S : ℕ → ℕ
-- Addition of natural numbers
_+_ : ℕ → ℕ → ℕ
Z + y = y
S x + y = S (x + y)
-- Relation on natural numbers
_≤_ : ℕ → ℕ → Prop
Z ≤ Z = ⊤
Z ≤ (S y) = ⊤
S x ≤ Z = ⊥
S x ≤ S y = x ≤ y
-- {-# BUILTIN NATURAL ℕ #-}
-- {-# BUILTIN BOOL Bool #-}
-- ≤ is reflexive
≤-ref : ∀ (x : ℕ) → (x ≤ x) → (x ≤ x)
≤-ref _ y = y
-- ≤ is not symmetric
-- ≤-sym : ∀ (x y : ℕ) → (x ≤ y) → (y ≤ x)
-- ≤-sym Z Z p = ⋆
-- ≤-sym Z (S y) ⋆ = {!!}
-- ≤-sym (S x) Z ()
-- ≤-sym (S x) (S y) p = ≤-sym x y p
-- ≤ is transitive
≤-trans : ∀ (x y z : ℕ) → (x ≤ y) → (y ≤ z) → (x ≤ z)
≤-trans Z Z Z p1 p2 = ⋆
≤-trans Z Z (S z) p1 p2 = ⋆
≤-trans Z (S y) Z p1 p2 = ⋆
≤-trans Z (S y) (S z) p1 p2 = ⋆
≤-trans (S x) Z z () p2
≤-trans (S x) (S y) Z p1 ()
≤-trans (S x) (S y) (S z) p1 p2 = ≤-trans x y z p1 p2
-- length of a list
length : {A : Set} → (List A) → ℕ
length [] = Z
length (x ∷ l) = (S Z) + (length l)
-- filter' on a list
filter' : {A : Set} → (A → Bool) → (l : List A)
→ List A
filter' f [] = []
filter' f (x ∷ l) with (f x)
filter' f (x ∷ l) | True = (x ∷ (filter' f l))
filter' f (x ∷ l) | False = filter' f l
≤-cong : ∀ (x y : ℕ) → (x ≤ y) → (x ≤ (S y))
≤-cong Z y p = ⋆
≤-cong (S x) Z ()
≤-cong (S x) (S y) p = ≤-cong x y p
thm-filter' : {A : Set} → (l : List A) → (f : A → Bool) → length (filter' f l) ≤ S (length l)
thm-filter' [] f = ⋆
thm-filter' (x ∷ l) f with (f x)
thm-filter' (x ∷ l) f | True = thm-filter' l f
thm-filter' (x ∷ l) f | False = ≤-cong (length (filter' f l)) (S (length l)) (thm-filter' l f)
filter : {A : Set} → (A → Bool) → (l : List A)
→ Exists (List A) (λ l' → (length l') ≤ (length l))
filter f [] = [ [] , ⋆ ]
filter f (x ∷ l) = [ filter' f l , thm-filter' l f ]
-- append two lists
_++_ : {A : Set} → (l : List A) → (l' : List A) → (List A)
[] ++ l' = l'
(x ∷ l) ++ l' = (x ∷ (l ++ l'))
leq-nat : ℕ → ℕ → Bool
leq-nat Z _ = True
leq-nat (S n) Z = False
leq-nat (S n) (S m) = leq-nat n m
_<_ : ℕ → ℕ → Bool
Z < (S _) = True
Z < Z = False
(S n) < (S m) = n < m
(S n) < Z = False
_>_ : ℕ → ℕ → Bool
m > n = n < m
-- The sorting algorithm
-- The trick here is that we are reducing qsort on "n"
qsort' : ∀ (n : ℕ) → ∀ (l : List ℕ) → (p : (length l) ≤ n) → (List ℕ)
qsort' Z [] p = []
qsort' Z (x ∷ l) ()
qsort' (S n) [] p = []
qsort' (S n) (x ∷ l) p =
let
ll = (filter (leq-nat x) l)
rr = (filter ((_>_) x) l)
pl = elim2-exists ll
pr = elim2-exists rr
left = qsort' n (elim1-exists ll) (≤-trans (length (elim1-exists ll)) (length l) n pl p)
right = qsort' n (elim1-exists rr) (≤-trans (length (elim1-exists rr)) (length l) n pr p)
in
(left ++ (x ∷ [])) ++ right
l' : {A : Set} → (l : List A) → (length l ≤ length l)
l' [] = ⋆
l' (x ∷ l) = l' l
qsort : ∀ (l : List ℕ) → List ℕ
qsort l = qsort' (length l) l (l' l)
-- XXX: definition of an sorted list
all-sorted-list : {A : Set} → (a : A)
→ (l : List A)
→ Prop
all-sorted-list a [] = ⊤
all-sorted-list a (x ∷ l) = leq a x ∧ (all-sorted-list a l)
sorted-list : {A : Set} → List A → Prop
sorted-list [] = ⊤
sorted-list (x ∷ l) = (all-sorted-list x l) ∧ (sorted-list l)
lem-qsort' : (x₁ : ℕ) → (l : List ℕ) → sorted-list
((qsort' (S (length l)) (filter' (leq-nat x₁) l)
(≤-trans (length (filter' (leq-nat x₁) l)) (S (length l))
(S (length l)) (thm-filter' l (leq-nat x₁)) (l' l))
++ (x₁ ∷ []))
++
qsort' (S (length l)) (filter' (_>_ x₁) l)
(≤-trans (length (filter' (_>_ x₁) l)) (S (length l))
(S (length l)) (thm-filter' l (_>_ x₁)) (l' l)))
lem-qsort' x [] = and ⋆ ⋆
lem-qsort' x (x₁ ∷ l) = {!!}
lem-qsort : (l : List ℕ) → (x : ℕ) →
sorted-list
((qsort' (length l) (elim1-exists (filter (leq-nat x) l))
(≤-trans (length (elim1-exists (filter (leq-nat x) l))) (length l)
(length l) (elim2-exists (filter (leq-nat x) l)) (l' l))
++ (x ∷ []))
++
qsort' (length l) (elim1-exists (filter (_>_ x) l))
(≤-trans (length (elim1-exists (filter (_>_ x) l))) (length l)
(length l) (elim2-exists (filter (_>_ x) l)) (l' l)))
lem-qsort [] x = and ⋆ ⋆
lem-qsort (x ∷ l) x₁ = lem-qsort' x₁ l
-- Theorem that given a list, qsort will actually sort the list
thm-qsort : ∀ (l : List ℕ) → sorted-list (qsort l)
thm-qsort [] = ⋆
thm-qsort (x ∷ l) = lem-qsort l x
|
{
"alphanum_fraction": 0.4739740629,
"avg_line_length": 28.4292929293,
"ext": "agda",
"hexsha": "2e2df15bc99760ee9792c7cb918bf9c13f3e8098",
"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": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "amal029/agda-tutorial-dybjer",
"max_forks_repo_path": "Qsort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"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": "amal029/agda-tutorial-dybjer",
"max_issues_repo_path": "Qsort.agda",
"max_line_length": 114,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "amal029/agda-tutorial-dybjer",
"max_stars_repo_path": "Qsort.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:52:30.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:52:30.000Z",
"num_tokens": 2286,
"size": 5629
}
|
-- Andreas, 2021-07-25, issue #5478 reported by mrohman
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --double-check #-}
-- {-# OPTIONS -v impossible:70 #-}
-- {-# OPTIONS -v tc:20 #-}
-- {-# OPTIONS -v tc.interaction:30 #-}
-- {-# OPTIONS -v tc.meta:25 #-}
-- {-# OPTIONS -v tc.rec:20 #-}
-- {-# OPTIONS -v tc.cc:25 #-}
-- {-# OPTIONS -v tc.record.eta.contract:20 #-}
record ⊤ : Set where
record R (A : Set) : Set₁ where
foo : ⊤
foo = {!!} -- works with _ instead of ?
field
X : Set
-- 2021-07-28, issue #5463, reported by laMudri
open import Agda.Primitive
record Foo (o : Level) : Set (lsuc o) where
field
Obj : Set o
Hom : Set o
Sub : Set {!!}
Sub = Hom
field
id : Set o
|
{
"alphanum_fraction": 0.5666666667,
"avg_line_length": 19.4594594595,
"ext": "agda",
"hexsha": "a915f45caeeee26f6e3dff80e6359ff97f048a9c",
"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/Succeed/Issue5478.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/Succeed/Issue5478.agda",
"max_line_length": 55,
"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/Succeed/Issue5478.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": 241,
"size": 720
}
|
-- Scenario:
-- * start with B only
-- * write 'f B = B'
-- * add constructor A
-- * want to deal with it first to preserve alphabetical ordering of clauses
-- * add 'f t = ?' *above* 'f B = B'
-- WAS: split t, get A and B
-- WANT: split t, get A only
data Type : Set where
A B : Type
f : Type → Type
f t = {!!}
f B = B
|
{
"alphanum_fraction": 0.5727272727,
"avg_line_length": 19.4117647059,
"ext": "agda",
"hexsha": "7f00391e2e10a7fc5b962885ad4c3059cf16849b",
"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/interaction/Issue3829.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/interaction/Issue3829.agda",
"max_line_length": 77,
"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/interaction/Issue3829.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": 112,
"size": 330
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.Theory
open import groups.ExactSequence
open import groups.HomSequence
open import homotopy.CofiberSequence
module cohomology.LongExactSequence {i} (CT : CohomologyTheory i)
{X Y : Ptd i} (n : ℤ) (f : X ⊙→ Y) where
open CohomologyTheory CT
open import cohomology.PtdMapSequence CT
co∂ : C n X →ᴳ C (succ n) (⊙Cofiber f)
co∂ = record {f = CEl-fmap (succ n) ⊙extract-glue ∘ GroupIso.g (C-Susp n X); pres-comp = lemma} where
abstract lemma = ∘ᴳ-pres-comp (C-fmap (succ n) ⊙extract-glue) (GroupIso.g-hom (C-Susp n X))
⊙∂-before-Susp : ⊙Cofiber f ⊙→ ⊙Susp X
⊙∂-before-Susp = ⊙extract-glue
∂-before-Susp : Cofiber (fst f) → Susp (de⊙ X)
∂-before-Susp = extract-glue
abstract
∂-before-Susp-glue-β : ∀ x →
ap ∂-before-Susp (cfglue x) == merid x
∂-before-Susp-glue-β = ExtractGlue.glue-β
C-cofiber-seq : HomSequence (C n Y) (C (succ n) X)
C-cofiber-seq =
C n Y →⟨ C-fmap n f ⟩ᴳ
C n X →⟨ co∂ ⟩ᴳ
C (succ n) (⊙Cofiber f) →⟨ C-fmap (succ n) (⊙cfcod' f) ⟩ᴳ
C (succ n) Y →⟨ C-fmap (succ n) f ⟩ᴳ
C (succ n) X ⊣|ᴳ
private
C-iterated-cofiber-seq = C-seq (succ n) (iterated-cofiber-seq f)
C-iterated-cofiber-seq-is-exact : is-exact-seq C-iterated-cofiber-seq
C-iterated-cofiber-seq-is-exact =
C-exact (succ n) (⊙cfcod²' f) , C-exact (succ n) (⊙cfcod' f) , C-exact (succ n) f , lift tt
-- An intermediate sequence for proving exactness of [C-cofiber-seq].
C-cofiber-seq' = C-seq (succ n) (cyclic-cofiber-seq f)
C-cofiber-seq'-is-exact : is-exact-seq C-cofiber-seq'
C-cofiber-seq'-is-exact =
seq-equiv-preserves'-exact
(C-seq-emap (succ n) (iterated-equiv-cyclic f))
C-iterated-cofiber-seq-is-exact
-- Now the final sequence
C-cofiber-seq'-to-C-cofiber-seq :
HomSeqMap C-cofiber-seq' C-cofiber-seq
(GroupIso.f-hom (C-Susp n Y)) (idhom _)
C-cofiber-seq'-to-C-cofiber-seq =
GroupIso.f-hom (C-Susp n Y) ↓⟨ C-Susp-fmap n f ⟩ᴳ
GroupIso.f-hom (C-Susp n X) ↓⟨ comm-sqrᴳ (λ x → ap (CEl-fmap (succ n) ⊙extract-glue) (! $ GroupIso.g-f (C-Susp n X) x)) ⟩ᴳ
idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ
idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ
idhom _ ↓|ᴳ
C-cofiber-seq'-equiv-C-cofiber-seq :
HomSeqEquiv C-cofiber-seq' C-cofiber-seq
(GroupIso.f-hom (C-Susp n Y)) (idhom _)
C-cofiber-seq'-equiv-C-cofiber-seq =
C-cofiber-seq'-to-C-cofiber-seq ,
(GroupIso.f-is-equiv (C-Susp n Y) , GroupIso.f-is-equiv (C-Susp n X) , idf-is-equiv _ , idf-is-equiv _ , idf-is-equiv _)
abstract
C-cofiber-seq-is-exact : is-exact-seq C-cofiber-seq
C-cofiber-seq-is-exact = seq-equiv-preserves-exact
C-cofiber-seq'-equiv-C-cofiber-seq C-cofiber-seq'-is-exact
C-cofiber-exact-seq : ExactSequence (C n Y) (C (succ n) X)
C-cofiber-exact-seq = C-cofiber-seq , C-cofiber-seq-is-exact
|
{
"alphanum_fraction": 0.6144859813,
"avg_line_length": 37.9240506329,
"ext": "agda",
"hexsha": "600d7060c88ae782a8c17d0fc0140cc4d53b3ef8",
"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": "theorems/cohomology/LongExactSequence.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": "theorems/cohomology/LongExactSequence.agda",
"max_line_length": 126,
"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": "theorems/cohomology/LongExactSequence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1175,
"size": 2996
}
|
{-# OPTIONS --erased-cubical #-}
open import Agda.Builtin.Bool
open import Agda.Builtin.Cubical.Path
open import Agda.Primitive
open import Agda.Primitive.Cubical
private
variable
a p : Level
A : Set a
P : A → Set p
x y : A
refl : x ≡ x
refl {x = x} = λ _ → x
subst : (P : A → Set p) → x ≡ y → P x → P y
subst P eq p = primTransp (λ i → P (eq i)) i0 p
record Erased (@0 A : Set a) : Set a where
constructor [_]
field
@0 erased : A
[]-cong : {@0 A : Set a} {@0 x y : A} → @0 x ≡ y → [ x ] ≡ [ y ]
[]-cong eq = λ i → [ eq i ]
data Box : @0 Set → Set₁ where
[_] : ∀ {A} → A → Box A
unbox : ∀ {@0 A} → Box A → A
unbox [ x ] = x
postulate
@0 not : Bool ≡ Bool
should-be-true : Bool
should-be-true =
unbox (subst (λ ([ A ]) → Box A) ([]-cong refl) [ true ])
should-be-false : Bool
should-be-false =
unbox (subst (λ ([ A ]) → Box A) ([]-cong not) [ true ])
|
{
"alphanum_fraction": 0.5428253615,
"avg_line_length": 19.9777777778,
"ext": "agda",
"hexsha": "55e9ab9c92dc8c3026ea1f347560f0da477525f6",
"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/Issue5468.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/Issue5468.agda",
"max_line_length": 64,
"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/Issue5468.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": 349,
"size": 899
}
|
module Issue3879.Fin where
open import Agda.Builtin.Nat
data Fin : Nat → Set where
zero : ∀ {n} → Fin (suc n)
suc : ∀ {n} → Fin n → Fin (suc n)
pattern 0F = zero
|
{
"alphanum_fraction": 0.6176470588,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "635d984f8b5888cab82654d7b56f2fb9bc99030c",
"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/interaction/Issue3879/Fin.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/interaction/Issue3879/Fin.agda",
"max_line_length": 36,
"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/interaction/Issue3879/Fin.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": 64,
"size": 170
}
|
module UnifyTerm where
open import Data.Fin using (Fin; suc; zero)
open import Data.Nat using (ℕ; suc; zero)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong₂; cong; sym; trans)
open import Function using (_∘_)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Data.Product using (∃; _,_; _×_)
open import Data.Empty using (⊥-elim)
data Term (n : ℕ) : Set where
i : (x : Fin n) -> Term n
leaf : Term n
_fork_ : (s t : Term n) -> Term n
_~>_ : (m n : ℕ) -> Set
m ~> n = Fin m -> Term n
▹ : ∀ {m n} -> (r : Fin m -> Fin n) -> Fin m -> Term n
▹ r = i ∘ r
_◃_ : ∀ {m n} -> (f : m ~> n) -> Term m -> Term n
f ◃ i x = f x
f ◃ leaf = leaf
f ◃ (s fork t) = (f ◃ s) fork (f ◃ t)
_≐_ : {m n : ℕ} -> (Fin m -> Term n) -> (Fin m -> Term n) -> Set
f ≐ g = ∀ x -> f x ≡ g x
◃ext : ∀ {m n} {f g : Fin m -> Term n} -> f ≐ g -> ∀ t -> f ◃ t ≡ g ◃ t
◃ext p (i x) = p x
◃ext p leaf = refl
◃ext p (s fork t) = cong₂ _fork_ (◃ext p s) (◃ext p t)
_◇_ : ∀ {l m n : ℕ } -> (f : Fin m -> Term n) (g : Fin l -> Term m) -> Fin l -> Term n
f ◇ g = (f ◃_) ∘ g
≐-cong : ∀ {m n o} {f : m ~> n} {g} (h : _ ~> o) -> f ≐ g -> (h ◇ f) ≐ (h ◇ g)
≐-cong h f≐g t = cong (h ◃_) (f≐g t)
≐-sym : ∀ {m n} {f : m ~> n} {g} -> f ≐ g -> g ≐ f
≐-sym f≐g = sym ∘ f≐g
module Sub where
fact1 : ∀ {n} -> (t : Term n) -> i ◃ t ≡ t
fact1 (i x) = refl
fact1 leaf = refl
fact1 (s fork t) = cong₂ _fork_ (fact1 s) (fact1 t)
fact2 : ∀ {l m n} -> (f : Fin m -> Term n) (g : _) (t : Term l)
-> (f ◇ g) ◃ t ≡ f ◃ (g ◃ t)
fact2 f g (i x) = refl
fact2 f g leaf = refl
fact2 f g (s fork t) = cong₂ _fork_ (fact2 f g s) (fact2 f g t)
fact3 : ∀ {l m n} (f : Fin m -> Term n) (r : Fin l -> Fin m) -> (f ◇ (▹ r)) ≡ (f ∘ r)
fact3 f r = refl -- ext (λ _ -> refl)
◃ext' : ∀ {m n o} {f : Fin m -> Term n}{g : Fin m -> Term o}{h} -> f ≐ (h ◇ g) -> ∀ t -> f ◃ t ≡ h ◃ (g ◃ t)
◃ext' p t = trans (◃ext p t) (Sub.fact2 _ _ t)
s : ℕ -> ℕ
s = suc
thin : ∀ {n} -> (x : Fin (s n)) (y : Fin n) -> Fin (s n)
thin zero y = suc y
thin (suc x) zero = zero
thin (suc x) (suc y) = suc (thin x y)
p : ∀ {n} -> Fin (suc (suc n)) -> Fin (suc n)
p (suc x) = x
p zero = zero
module Thin where
fact1 : ∀ {n} x y z -> thin {n} x y ≡ thin x z -> y ≡ z
fact1 zero y .y refl = refl
fact1 (suc x) zero zero r = refl
fact1 (suc x) zero (suc z) ()
fact1 (suc x) (suc y) zero ()
fact1 (suc x) (suc y) (suc z) r = cong suc (fact1 x y z (cong p r))
fact2 : ∀ {n} x y -> ¬ thin {n} x y ≡ x
fact2 zero y ()
fact2 (suc x) zero ()
fact2 (suc x) (suc y) r = fact2 x y (cong p r)
fact3 : ∀{n} x y -> ¬ x ≡ y -> ∃ λ y' -> thin {n} x y' ≡ y
fact3 zero zero ne = ⊥-elim (ne refl)
fact3 zero (suc y) _ = y , refl
fact3 {zero} (suc ()) _ _
fact3 {suc n} (suc x) zero ne = zero , refl
fact3 {suc n} (suc x) (suc y) ne with y | fact3 x y (ne ∘ cong suc)
... | .(thin x y') | y' , refl = suc y' , refl
open import Data.Maybe
open import Category.Functor
open import Category.Monad
import Level
open RawMonad (Data.Maybe.monad {Level.zero})
thick : ∀ {n} -> (x y : Fin (suc n)) -> Maybe (Fin n)
thick zero zero = nothing
thick zero (suc y) = just y
thick {zero} (suc ()) _
thick {suc _} (suc x) zero = just zero
thick {suc _} (suc x) (suc y) = suc <$> (thick x y)
open import Data.Sum
_≡Fin_ : ∀ {n} -> (x y : Fin n) -> Dec (x ≡ y)
zero ≡Fin zero = yes refl
zero ≡Fin suc y = no λ ()
suc x ≡Fin zero = no λ ()
suc {suc _} x ≡Fin suc y with x ≡Fin y
... | yes r = yes (cong suc r)
... | no r = no λ e -> r (cong p e)
suc {zero} () ≡Fin _
module Thick where
half1 : ∀ {n} (x : Fin (suc n)) -> thick x x ≡ nothing
half1 zero = refl
half1 {suc _} (suc x) = cong (_<$>_ suc) (half1 x)
half1 {zero} (suc ())
half2 : ∀ {n} (x : Fin (suc n)) y -> ∀ y' -> thin x y' ≡ y -> thick x y ≡ just y'
half2 zero zero y' ()
half2 zero (suc y) .y refl = refl
half2 {suc n} (suc x) zero zero refl = refl
half2 {suc _} (suc _) zero (suc _) ()
half2 {suc n} (suc x) (suc y) zero ()
half2 {suc n} (suc x) (suc .(thin x y')) (suc y') refl with thick x (thin x y') | half2 x (thin x y') y' refl
... | .(just y') | refl = refl
half2 {zero} (suc ()) _ _ _
fact1 : ∀ {n} (x : Fin (suc n)) y r
-> thick x y ≡ r
-> x ≡ y × r ≡ nothing ⊎ ∃ λ y' -> thin x y' ≡ y × r ≡ just y'
fact1 x y .(thick x y) refl with x ≡Fin y
fact1 x .x ._ refl | yes refl = inj₁ (refl , half1 x)
... | no el with Thin.fact3 x y el
... | y' , thinxy'=y = inj₂ (y' , ( thinxy'=y , half2 x y y' thinxy'=y ))
check : ∀{n} (x : Fin (suc n)) (t : Term (suc n)) -> Maybe (Term n)
check x (i y) = i <$> thick x y
check x leaf = just leaf
check x (s fork t) = _fork_ <$> check x s ⊛ check x t
_for_ : ∀ {n} (t' : Term n) (x : Fin (suc n)) -> Fin (suc n) -> Term n
(t' for x) y = maybe′ i t' (thick x y)
data AList : ℕ -> ℕ -> Set where
anil : ∀ {n} -> AList n n
_asnoc_/_ : ∀ {m n} (σ : AList m n) (t' : Term m) (x : Fin (suc m))
-> AList (suc m) n
sub : ∀ {m n} (σ : AList m n) -> Fin m -> Term n
sub anil = i
sub (σ asnoc t' / x) = sub σ ◇ (t' for x)
_++_ : ∀ {l m n} (ρ : AList m n) (σ : AList l m) -> AList l n
ρ ++ anil = ρ
ρ ++ (σ asnoc t' / x) = (ρ ++ σ) asnoc t' / x
++-assoc : ∀ {l m n o} (ρ : AList l m) (σ : AList n _) (τ : AList o _) -> ρ ++ (σ ++ τ) ≡ (ρ ++ σ) ++ τ
++-assoc ρ σ anil = refl
++-assoc ρ σ (τ asnoc t / x) = cong (λ s -> s asnoc t / x) (++-assoc ρ σ τ)
module SubList where
anil-id-l : ∀ {m n} (σ : AList m n) -> anil ++ σ ≡ σ
anil-id-l anil = refl
anil-id-l (σ asnoc t' / x) = cong (λ σ -> σ asnoc t' / x) (anil-id-l σ)
fact1 : ∀ {l m n} (ρ : AList m n) (σ : AList l m) -> sub (ρ ++ σ) ≐ (sub ρ ◇ sub σ)
fact1 ρ anil v = refl
fact1 {suc l} {m} {n} r (s asnoc t' / x) v = trans hyp-on-terms ◃-assoc
where
t = (t' for x) v
hyp-on-terms = ◃ext (fact1 r s) t
◃-assoc = Sub.fact2 (sub r) (sub s) t
_∃asnoc_/_ : ∀ {m} (a : ∃ (AList m)) (t' : Term m) (x : Fin (suc m))
-> ∃ (AList (suc m))
(n , σ) ∃asnoc t' / x = n , σ asnoc t' / x
flexFlex : ∀ {m} (x y : Fin m) -> ∃ (AList m)
flexFlex {suc m} x y with thick x y
... | just y' = m , anil asnoc i y' / x
... | nothing = suc m , anil
flexFlex {zero} () _
flexRigid : ∀ {m} (x : Fin m) (t : Term m) -> Maybe (∃(AList m))
flexRigid {suc m} x t with check x t
... | just t' = just (m , anil asnoc t' / x)
... | nothing = nothing
flexRigid {zero} () _
|
{
"alphanum_fraction": 0.4915927851,
"avg_line_length": 33.2081218274,
"ext": "agda",
"hexsha": "546a81d7aed5bff09097a8a59f45eff0a5252e29",
"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-1/UnifyTerm.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-1/UnifyTerm.agda",
"max_line_length": 111,
"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-1/UnifyTerm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2862,
"size": 6542
}
|
open import Function.Equivalence as FE using ()
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Nullary.Decidable using (False; map)
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; sym; cong; module ≡-Reasoning)
open import Relation.Binary.PropositionalEquality.WithK using (≡-irrelevant)
open ≡-Reasoning
open import Data.Product using (_×_; _,_; uncurry)
open import Data.Unit using (⊤; tt)
open import Agda.Builtin.FromNat using (Number)
module AKS.Rational.Base where
open import Data.Integer using (ℤ; +_; +0; +[1+_]; -[1+_]; ∣_∣) renaming (_+_ to _+ℤ_; _*_ to _*ℤ_; -_ to -ℤ_; _≟_ to _≟ℤ_)
open import Data.Integer.DivMod using () renaming (_divℕ_ to _/ℤ_)
open import Data.Integer.Properties using (∣-n∣≡∣n∣)
open import AKS.Nat using (ℕ; suc; ≢⇒¬≟; ¬≟⇒≢) renaming (_+_ to _+ℕ_; _*_ to _*ℕ_; _≟_ to _≟ℕ_)
open import AKS.Nat using (n≢0∧m≢0⇒n*m≢0)
open import AKS.Nat.Divisibility using () renaming (_/_ to _/ℕ_)
open import AKS.Nat.GCD using (gcd; _⊥_; gcd[a,1]≡1; b≢0⇒gcd[a,b]≢0; gcd[0,a]≡1⇒a≡1; ⊥-respˡ; ⊥-sym)
record ℚ : Set where
constructor ℚ✓
field
numerator : ℤ
denominator : ℕ
den≢0 : False (denominator ≟ℕ 0)
coprime : ∣ numerator ∣ ⊥ denominator
fromℤ : ℤ → ℚ
fromℤ n = record
{ numerator = n
; denominator = 1
; den≢0 = tt
; coprime = gcd[a,1]≡1 (∣ n ∣)
}
fromℕ : ℕ → ℚ
fromℕ n = fromℤ (+ n)
instance
ℚ-number : Number ℚ
ℚ-number = record
{ Constraint = λ _ → ⊤
; fromNat = λ n → fromℕ n
}
open import AKS.Unsafe using (trustMe; TODO)
open import Data.Fin using (Fin)
open import Data.Nat.DivMod using (_divMod_; result)
∣a/ℤb∣≡∣a∣/ℕb : ∀ a b {b≢0} → ∣ (a /ℤ b) {b≢0} ∣ ≡ (∣ a ∣ /ℕ b) {b≢0}
∣a/ℤb∣≡∣a∣/ℕb (+ n) b {b≢0} = refl
∣a/ℤb∣≡∣a∣/ℕb (-[1+ x ]) b {b≢0} with (suc x divMod b) {b≢0}
... | result q Fin.zero eq rewrite ∣-n∣≡∣n∣ (+ q) = trustMe
... | result q (Fin.suc r) eq = trustMe
a/d⊥b/d : ∀ a b d {d≢0} → gcd a b ≡ d → (a /ℕ d) {d≢0} ⊥ (b /ℕ d) {d≢0}
a/d⊥b/d a b d gcd[a,b]≡d = begin
gcd (a /ℕ d) (b /ℕ d) ≡⟨ trustMe ⟩
1 ∎
a≢0⇒a/b≢0 : ∀ a b (a≢0 : False (a ≟ℕ 0)) {b≢0} → (a /ℕ b) {b≢0} ≢ 0
a≢0⇒a/b≢0 (suc a) (suc b) a≢0 = TODO
canonical : ∀ (num : ℤ) (den : ℕ) {den≢0 : False (den ≟ℕ 0)} → ℚ
canonical num den {den≢0} = construct num den {den≢0} (gcd ∣ num ∣ den) {≢⇒¬≟ (b≢0⇒gcd[a,b]≢0 (∣ num ∣) den (¬≟⇒≢ den≢0))} refl
where
construct : ∀ num den {den≢0 : False (den ≟ℕ 0)} d {d≢0 : False (d ≟ℕ 0)} → gcd ∣ num ∣ den ≡ d → ℚ
construct num den {den≢0} d {d≢0} gcd[num,den]≡d = record
{ numerator = (num /ℤ d) {d≢0}
; denominator = (den /ℕ d) {d≢0}
; den≢0 = ≢⇒¬≟ (a≢0⇒a/b≢0 den d den≢0)
; coprime = ⊥-respˡ {den /ℕ d} (sym (∣a/ℤb∣≡∣a∣/ℕb num d)) (a/d⊥b/d ∣ num ∣ den d gcd[num,den]≡d)
}
infixl 6 _+_
_+_ : ℚ → ℚ → ℚ
(ℚ✓ num₁ den₁ den₁≢0 _) + (ℚ✓ num₂ den₂ den₂≢0 _) = canonical (num₁ *ℤ (+ den₂) +ℤ num₂ *ℤ (+ den₁)) (den₁ *ℕ den₂) {≢⇒¬≟ (n≢0∧m≢0⇒n*m≢0 (¬≟⇒≢ den₁≢0) (¬≟⇒≢ den₂≢0))}
infix 8 -_
-_ : ℚ → ℚ
- (ℚ✓ num den den≢0 num⊥den) = ℚ✓ (-ℤ num) den den≢0 (⊥-respˡ {den} (sym (∣-n∣≡∣n∣ num)) num⊥den)
infixl 7 _*_
_*_ : ℚ → ℚ → ℚ
(ℚ✓ num₁ den₁ den₁≢0 _) * (ℚ✓ num₂ den₂ den₂≢0 _) = canonical (num₁ *ℤ num₂) (den₁ *ℕ den₂) {≢⇒¬≟ (n≢0∧m≢0⇒n*m≢0 (¬≟⇒≢ den₁≢0) (¬≟⇒≢ den₂≢0))}
infix 8 _⁻¹
_⁻¹ : ∀ (q : ℚ) {q≢0 : q ≢ 0} → ℚ
(ℚ✓ +0 den den≢0 num⊥den ⁻¹) {q≢0} with gcd[0,a]≡1⇒a≡1 den num⊥den
(ℚ✓ +0 .1 tt refl ⁻¹) {q≢0} | refl = contradiction refl q≢0
(ℚ✓ +[1+ num ] (suc den) den≢0 num⊥den) ⁻¹ = ℚ✓ +[1+ den ] (suc num) tt (⊥-sym {suc num} {suc den} num⊥den)
(ℚ✓ -[1+ num ] (suc den) den≢0 num⊥den) ⁻¹ = ℚ✓ -[1+ den ] (suc num) tt (⊥-sym {suc num} {suc den} num⊥den)
infixl 7 _/_
_/_ : ∀ (p q : ℚ) {q≢0 : q ≢ 0} → ℚ
_/_ p q {q≢0}= p * (q ⁻¹) {q≢0}
_≟_ : Decidable {A = ℚ} _≡_
(ℚ✓ num₁ (suc den₁) tt num₁⊥den₁) ≟ (ℚ✓ num₂ (suc den₂) tt num₂⊥den₂)
= map (FE.equivalence forward backward) (num₁ ≟ℤ num₂ ×-dec den₁ ≟ℕ den₂)
where
forward : ∀ {num₁ num₂} {den₁ den₂} {num₁⊥den₁ num₂⊥den₂} → num₁ ≡ num₂ × den₁ ≡ den₂ → ℚ✓ num₁ (suc den₁) tt num₁⊥den₁ ≡ ℚ✓ num₂ (suc den₂) tt num₂⊥den₂
forward {num₁} {num₂} {den₁} {den₂} {num₁⊥den₁} {num₂⊥den₂} (refl , refl) = cong (λ pf → ℚ✓ num₁ (suc den₁) tt pf) (≡-irrelevant num₁⊥den₁ num₂⊥den₂)
backward : ∀ {num₁ num₂} {den₁ den₂} {num₁⊥den₁ num₂⊥den₂} → ℚ✓ num₁ (suc den₁) tt num₁⊥den₁ ≡ ℚ✓ num₂ (suc den₂) tt num₂⊥den₂ → num₁ ≡ num₂ × den₁ ≡ den₂
backward refl = (refl , refl)
≢0 : ∀ {p : ℚ} {p≢0 : False (p ≟ 0)} → p ≢ 0
≢0 {p} with p ≟ 0
≢0 {p} | no p≢0 = p≢0
test = ((1 / 2) {≢0} + (3 / 4) {≢0}) ⁻¹
open import Data.String using (String; _++_)
open import Data.Nat.Show using () renaming (show to show-ℕ)
show-ℤ : ℤ → String
show-ℤ (+ n) = show-ℕ n
show-ℤ (-[1+ n ]) = "-" ++ show-ℕ (suc n)
show-ℚ : ℚ → String
show-ℚ (ℚ✓ num 1 _ _) = show-ℤ num
show-ℚ (ℚ✓ num den _ _) = show-ℤ num ++ "/" ++ show-ℕ den
|
{
"alphanum_fraction": 0.5776173285,
"avg_line_length": 38.0610687023,
"ext": "agda",
"hexsha": "f182b5d4fd20141b1c2f90d8c88555df8f7fec58",
"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": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Rational/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"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": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Rational/Base.agda",
"max_line_length": 166,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Rational/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 2648,
"size": 4986
}
|
-- Andreas, 2017-12-04, issue #2862, reported by m0davis, case for records
-- Regression in development version 2.5.4
-- Scope checker allowed definition in different module than signature
module _ where
module N where
record R : Set where
open N hiding (module R)
module M where
record R where -- should be rejected since signature lives in different module
inhabited-R : R
inhabited-R = _
data ⊥ : Set where
record R where
field absurd : ⊥
boom : ⊥
boom = R.absurd M.inhabited-R
|
{
"alphanum_fraction": 0.7245508982,
"avg_line_length": 19.2692307692,
"ext": "agda",
"hexsha": "85f0054786a701aac262771a2c5838f130a37a1a",
"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/Issue2862record.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/Issue2862record.agda",
"max_line_length": 81,
"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/Issue2862record.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": 501
}
|
{-# OPTIONS --universe-polymorphism #-}
module NoPanic where
postulate
Level : Set
lzero : Level
lsuc : Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO lzero #-}
{-# BUILTIN LEVELSUC lsuc #-}
module M {A : Set} where
postulate
I : A → ∀ a → Set a
i : ∀ (x : A) {a} → I x a
f : {B : Set} → B
a : A
Foo : Set₁
Foo with i (f a)
Foo | _ = Set
-- Old (bad) error message:
-- NoPanic.agda:24,3-16
-- Panic: Pattern match failure in do expression at
-- src/full/Agda/TypeChecking/Rules/Term.hs:646:7-18
-- when checking that the expression _22 {A} has type Level
|
{
"alphanum_fraction": 0.6045380875,
"avg_line_length": 19.28125,
"ext": "agda",
"hexsha": "57afbd3a87871b4aa6661de6ad9394ec40d3018f",
"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/NoPanic.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/NoPanic.agda",
"max_line_length": 59,
"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/NoPanic.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": 210,
"size": 617
}
|
module Ual.Ord where
open import Agda.Primitive
open import Ual.Void
open import Ual.Eq
open import Ual.Either
open import Ual.Both
record Ord {a} (A : Set a) : Set (lsuc a) where
infix 30 _<_
infix 30 _>_
infix 30 _≤_
infix 30 _≥_
field
⦃ eqA ⦄ : Eq A
_<_ : A → A → Set
_>_ : A → A → Set
x > y = x ≠ y ∧ ¬ (x < y)
_≤_ : A → A → Set
x ≤ y = x == y ∨ x < y
_≥_ : A → A → Set
x ≥ y = x == y ∨ x > y
field
ltNotEq : {x y : A} → x < y → x ≠ y
symLt : {x y : A} → x < y → y > x
symGt : {x y : A} → x > y → y < x
transLt : {x y z : A} → x < y → y < z → x < z
transLe : {x y z : A} → x ≤ y → y ≤ z → x ≤ z
symLe : {x y : A} → x ≤ y → y ≥ x
symLe (orL eq) = orL (sym ⦃ eqA ⦄ eq)
symLe (orR lt) = orR (symLt lt)
symGe : {x y : A} → x ≥ y → y ≤ x
symGe (orL eq) = orL (sym ⦃ eqA ⦄ eq)
symGe (orR gt) = orR (symGt gt)
transGt : {x y z : A} → x > y → y > z → x > z
transGt gt1 gt2 = symLt (transLt (symGt gt2) (symGt gt1))
transGe : {x y z : A} → x ≥ y → y ≥ z → x ≥ z
transGe ge1 ge2 = symLe (transLe (symGe ge2) (symGe ge1))
open Ord ⦃ ... ⦄ public
data Order {a} {A : Set a} ⦃ ordA : Ord A ⦄ : A → A → Set where
less : {x y : A} → x < y → Order x y
equal : {x y : A} → x == y → Order x y
greater : {x y : A} → x > y → Order x y
record Compare {a} (A : Set a) : Set (lsuc a) where
field
⦃ ordA ⦄ : Ord A
compare : (x : A) → (y : A) → Order x y
|
{
"alphanum_fraction": 0.4751724138,
"avg_line_length": 27.358490566,
"ext": "agda",
"hexsha": "dda745e6310ae3e005279a3a44d93a88e1a57c32",
"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": "ea0260e1a0612ba581e4283dfb187f531a944dfd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "brunoczim/ual",
"max_forks_repo_path": "Ord.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ea0260e1a0612ba581e4283dfb187f531a944dfd",
"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": "brunoczim/ual",
"max_issues_repo_path": "Ord.agda",
"max_line_length": 63,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ea0260e1a0612ba581e4283dfb187f531a944dfd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "brunoczim/ual",
"max_stars_repo_path": "Ord.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 680,
"size": 1450
}
|
record R : Set₁ where
field
⟨_+_⟩ : Set
open R
-- Name parts coming from projections can not be used as part of
-- variables.
F : Set → Set
F + = +
|
{
"alphanum_fraction": 0.6242038217,
"avg_line_length": 13.0833333333,
"ext": "agda",
"hexsha": "6b5d74906bf1525e78827d4e05267f9309f25f5f",
"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/Issue3400-3.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/Issue3400-3.agda",
"max_line_length": 64,
"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/Issue3400-3.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": 48,
"size": 157
}
|
------------------------------------------------------------------------
-- IO
------------------------------------------------------------------------
{-# OPTIONS --without-K #-}
module IO-monad where
open import Monad.Raw
open import Prelude
open import String
------------------------------------------------------------------------
-- The IO type former
open import Agda.Builtin.IO public using (IO)
------------------------------------------------------------------------
-- The IO monad
postulate
returnIO : ∀ {a} {A : Type a} → A → IO A
bindIO : ∀ {a b} {A : Type a} {B : Type b} →
IO A → (A → IO B) → IO B
{-# COMPILE GHC returnIO = \_ _ -> return #-}
{-# COMPILE GHC bindIO = \_ _ _ _ -> (>>=) #-}
instance
io-monad : ∀ {ℓ} → Raw-monad (IO {a = ℓ})
Raw-monad.return io-monad = returnIO
Raw-monad._>>=_ io-monad = bindIO
------------------------------------------------------------------------
-- Some IO primitives
-- Note that some commands may raise exceptions when executed.
postulate
putStr : String → IO ⊤
putStrLn : String → IO ⊤
exitFailure : IO ⊤
getArgs : IO (List String)
{-# FOREIGN GHC
import qualified Data.Text
import qualified Data.Text.IO
import qualified System.Environment
import qualified System.Exit
#-}
-- Note that the GHC code below ignores potential problems. For
-- instance, putStr could raise an exception.
{-# COMPILE GHC putStr = Data.Text.IO.putStr #-}
{-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn #-}
{-# COMPILE GHC exitFailure = System.Exit.exitFailure #-}
{-# COMPILE GHC getArgs = fmap (map Data.Text.pack)
System.Environment.getArgs #-}
|
{
"alphanum_fraction": 0.4914956012,
"avg_line_length": 27.9508196721,
"ext": "agda",
"hexsha": "ed1b784d896b8230b60e9cde6bd43c5c93a9c5f5",
"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/IO-monad.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/IO-monad.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/IO-monad.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": 380,
"size": 1705
}
|
{-# OPTIONS --cubical-compatible #-}
{-# OPTIONS --allow-unsolved-metas #-}
-- This issue demonstrates that a failing termination check,
-- subsequently blocking reductions, makes some `impossible'
-- cases possible in the conversion checker.
module Issue921 where
infix 3 _==_
postulate
_==_ : {A : Set} → A → A → Set
transport : {A : Set} (B : A → Set) {x y : A} (p : x == y) → (B x → B y)
! : {A : Set} {x y : A} → (x == y → y == x)
infixr 1 _,_
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
open Σ public
infix 4 _≃_
_≃_ : ∀ (A : Set) (B : Set) → Set
A ≃ B = Σ (A → B) (λ _ → B → A)
postulate
<– : {A : Set} {B : Set} → (A ≃ B) → B → A
infixr 4 _∘e_
_∘e_ : {A : Set} {B : Set} {C : Set} → B ≃ C → A ≃ B → A ≃ C
e1 ∘e e2 = ({!!} , λ c → snd e2 (snd e1 c))
module _ {A : Set} {B : A → Set} {C : (a : A) → B a → Set} where
Σ-assoc : Σ (Σ A B) (λ z → C (fst z) (snd z)) ≃ Σ A (λ a → Σ (B a) (C a))
Σ-assoc = ({!!} , λ {(a , (b , c)) → ((a , b) , c)})
data Ctx : Set
postulate
Ty : Ctx → Set
data Ctx where
_·_ : (Γ : Ctx) → Ty {!!} → Ctx
infix 5 _ctx-⇛_
_ctx-⇛_ : Ctx → Ctx → Set
-- swap these two lines and the internal error disappears
Tm : Σ Ctx Ty → Set
Γ ctx-⇛ (Δ · A) = Σ {!!} {!!}
infix 10 _*_
postulate
_*_ : {Γ Δ : Ctx} (m : Γ ctx-⇛ Δ) → Ty {!!} → Ty {!!}
pullback : {Γ Δ : Ctx} {A : Ty Δ} → Tm (Δ , A) → (m : Γ ctx-⇛ Δ) → Tm (Γ , m * A)
infix 7 _·_
data Xtc (Γ : Ctx) : Set where
_·_ : (A : Ty {!!}) → Xtc {!!} → Xtc Γ
infix 6 _⋯_
_⋯_ : (Γ : Ctx) → Xtc Γ → Ctx
Γ ⋯ (A · s) = (Γ · A) ⋯ s
module xtc where
infix 5 _⇛_∣_
_⇛_∣_ : (Γ : Ctx) {Δ : Ctx} (m : Γ ctx-⇛ Δ) → Xtc Δ → Set
Γ ⇛ m ∣ A · T = Σ (Tm (Γ , m * A)) (λ t → Γ ⇛ (m , t) ∣ T)
infix 5 _⇛_
_⇛_ : (Γ : Ctx) → Σ Ctx (λ Δ → Xtc Δ) → Set
Γ ⇛ (Δ , T) = Σ (Γ ctx-⇛ Δ) (λ m → Γ ⇛ m ∣ T)
eq : {Γ Δ : Ctx} {T : Xtc Δ} → Γ ctx-⇛ Δ ⋯ T ≃ Γ ⇛ (Δ , T)
eq {T = A · T} = Σ-assoc ∘e eq
weaken : (Γ : Ctx) {T : Xtc Γ} → Γ ⋯ T ctx-⇛ Γ
infix 10 _○_
_○_ : {Γ Δ Θ : Ctx} → Δ ctx-⇛ Θ → Γ ctx-⇛ Δ → Γ ctx-⇛ Θ
postulate
_○=_ : {Γ Δ Θ : Ctx} (n : Δ ctx-⇛ Θ) (m : Γ ctx-⇛ {!!}) {A : Ty {!!}} → (n ○ m) * A == m * (n * A)
Tm P = Σ Ctx λ Γ → Σ (Ty {!!}) λ A → Σ (Xtc (Γ · A)) λ T → (Γ · A ⋯ T , weaken Γ {A · T} * A) == P
weaken (Γ · A) {T} = (weaken Γ {A · T} , (Γ , A , T , {!!}))
_○_ {Θ = Θ · _} (n , x) m = (n ○ m , transport (λ z → Tm (_ , z)) (! (n ○= m)) (pullback x m))
weaken-○-scope : {Γ Δ : Ctx} {T : Xtc Δ} (ms : Γ xtc.⇛ (Δ , T)) → weaken Δ {T} ○ snd xtc.eq ms == fst ms
pullback-var : {Γ Δ : Ctx} {A : Ty {!!}} {T : Xtc (Δ · A)}
(ms : Γ xtc.⇛ (Δ , A · T))
→ Tm (Γ , snd xtc.eq ms * (weaken Δ {A · T} * A))
pullback-var {Γ} {Δ} {A} {T} ms =
transport (λ z → Tm (Γ , z)) (weaken Δ {A · T} ○= snd xtc.eq ms)
(transport (λ z → Tm (Γ , z * A)) (! (weaken-○-scope ms))
(fst (snd ms)))
pullback (Δ' , _ , T , p) = transport (λ P → (m : _ ctx-⇛ fst P) → Tm (_ , m * snd P)) p (<– {!!} pullback-var)
weaken-○-scope {Γ} {Δ · A} {T} ((m , t) , ts) = {!!} where
helper3 : transport (λ z → Tm (Γ , z))
(! (fst (weaken (Δ · A)) ○= snd xtc.eq ((m , t) , ts)))
(pullback-var {!!})
== transport (λ z → Tm (Γ , z * A))
(! (weaken-○-scope (m , t , ts)))
t
helper3 = {!!}
|
{
"alphanum_fraction": 0.4378522694,
"avg_line_length": 28.5677966102,
"ext": "agda",
"hexsha": "f193a4562c87b3e2464c4c4d27b0ff08bb2731e0",
"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/Issue921.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/Issue921.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/Issue921.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1647,
"size": 3371
}
|
open import Relation.Binary.Core
module InsertSort.Impl2.Correctness.Permutation.Base {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Data.List
open import Data.Sum
open import InsertSort.Impl2 _≤_ tot≤
open import List.Permutation.Base A
open import OList _≤_
lemma-forget-insert : {b : Bound} → (x : A) → (b≤x : LeB b (val x)) → (xs : OList b) → forget (insert b≤x xs) / x ⟶ forget xs
lemma-forget-insert x b≤x onil = /head
lemma-forget-insert x b≤x (:< {x = y} b≤y ys)
with tot≤ x y
... | inj₁ x≤y = /head
... | inj₂ y≤x = /tail (lemma-forget-insert x (lexy y≤x) ys)
theorem-insertSort∼ : (xs : List A) → xs ∼ forget (insertSort xs)
theorem-insertSort∼ [] = ∼[]
theorem-insertSort∼ (x ∷ xs) = ∼x /head (lemma-forget-insert x lebx (insertSort xs)) (theorem-insertSort∼ xs)
|
{
"alphanum_fraction": 0.6418242492,
"avg_line_length": 35.96,
"ext": "agda",
"hexsha": "1e6220ecb2344163c905f2b03863fddd78699e5e",
"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/Impl2/Correctness/Permutation/Base.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/Impl2/Correctness/Permutation/Base.agda",
"max_line_length": 125,
"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/Impl2/Correctness/Permutation/Base.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": 318,
"size": 899
}
|
module Issue731 where
data empty : Set where
foo : empty → _
foo ()
bar : empty → Set
bar = foo
{- But when I want to know what are the constraints (C-c C-= in
emacs), I get the following error instead:
No binding for builtin thing LEVELZERO, use {-# BUILTIN LEVELZERO
name #-} to bind it to 'name'
when checking that the expression foo has type empty → Set
I’m not sure it is a bug, but it seems a bit strange to get an error
message when doing C-c C-= -}
-- Now displays correctly:
-- _4 := foo [blocked by problem 3]
-- [3] _2 =< Set : Set _1
-- _1 = (.Agda.Primitive.lsuc .Agda.Primitive.lzero)
-- _1 = (.Agda.Primitive.lsuc .Agda.Primitive.lzero)
|
{
"alphanum_fraction": 0.6904400607,
"avg_line_length": 25.3461538462,
"ext": "agda",
"hexsha": "0866e0f7c70fcfb0b27756f5757af5e527db0a2f",
"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/interaction/Issue731.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/interaction/Issue731.agda",
"max_line_length": 68,
"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/interaction/Issue731.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": 191,
"size": 659
}
|
record R : Set₁ where
field
A : Set
open R ⦃ … ⦄
-- The inferred type of A is ⦃ r : R ⦄ → Set. However, the following
-- code is rejected:
X : R → Set
X r = A ⦃ r = r ⦄
-- WAS: Function does not accept argument ⦃ r = r ⦄
-- when checking that ⦃ r = r ⦄ is a valid argument to a function of
-- type ⦃ r = r₁ : R ⦄ → Set
-- SHOULD: succeed
|
{
"alphanum_fraction": 0.58,
"avg_line_length": 18.4210526316,
"ext": "agda",
"hexsha": "6b0224bdc4697b12f154f06adc5800b1284a2f68",
"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/Issue3463.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/Issue3463.agda",
"max_line_length": 68,
"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/Issue3463.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": 350
}
|
-- 2017-11-01, issue #2668 reported by brprice
--
-- This seems to have been fixed in 2.5.3 (specifically, commit
-- 8518b8e seems to have solved this, along with #2727 and #2726)
-- {-# OPTIONS -v tc.mod.apply:20 #-}
-- {-# OPTIONS -v tc.proj.like:40 #-}
-- {-# OPTIONS -v tc.signature:60 #-}
-- {-# OPTIONS -v tc.with:60 #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
module _ (Q : Set) where -- parameter needed to trigger issue
-- has to pattern match: `badRefl _ = refl` typechecks
badRefl : (n : Nat) → n ≡ n
badRefl zero = refl
badRefl (suc n) = refl
-- has to wrap: `Wrap = Nat` (and changing uses of wrap) typechecks
data Wrap : Set where
wrap : (n : Nat) → Wrap
record Rec (A : Set) : Set where
field
recW : (m : Nat) → Wrap
foo : A → Wrap → Wrap
foo _ (wrap i) = recW i
Thin : Rec Nat
Thin = record { recW = wrap }
module Th = Rec Thin
test : ∀ (th : Nat)(t : Wrap)
→ Th.foo th t ≡ Th.foo th t
-- If we don't go via Th, it typechecks
-- → Rec.foo Thin th t ≡ Rec.foo Thin th t
-- test = {!Rec.foo!}
test th t with badRefl th
... | p = refl
-- ERROR WAS:
-- Expected a hidden argument, but found a visible argument
-- when checking that the type
-- (Q : Set) (th : Nat) → th ≡ th → (t : Wrap) →
-- Rec.foo (record { recW = wrap }) th t ≡
-- Rec.foo (record { recW = wrap }) th t
-- of the generated with function is well-formed
-- Should succeed
|
{
"alphanum_fraction": 0.6138268156,
"avg_line_length": 24.6896551724,
"ext": "agda",
"hexsha": "8ae14a41848e379c72edaecbf31611c7098b631d",
"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/Issue2668.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/Issue2668.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2668.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": 471,
"size": 1432
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.Theory
open import groups.Exactness
open import groups.HomSequence
open import groups.ExactSequence
open import cw.CW
module cw.cohomology.Descending {i} (OT : OrdinaryTheory i) where
open OrdinaryTheory OT
open import cw.cohomology.TipAndAugment OT
open import cw.cohomology.WedgeOfCells OT
open import cohomology.LongExactSequence cohomology-theory
private
C-cw-descend-at-succ : ∀ {n} (⊙skel : ⊙Skeleton (S n))
{m} (m≠n : m ≠ ℕ-to-ℤ n) (Sm≠n : succ m ≠ ℕ-to-ℤ n)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ C (succ m) ⊙⟦ ⊙skel ⟧ ≃ᴳ C (succ m) ⊙⟦ ⊙cw-init ⊙skel ⟧
C-cw-descend-at-succ ⊙skel {m} m≠n Sm≠n ac =
Exact2.G-trivial-and-L-trivial-implies-H-iso-K
(exact-seq-index 2 $ C-cofiber-exact-seq m (⊙cw-incl-last ⊙skel))
(exact-seq-index 0 $ C-cofiber-exact-seq (succ m) (⊙cw-incl-last ⊙skel))
(CXₙ/Xₙ₋₁-≠-is-trivial ⊙skel (succ-≠ m≠n) ac)
(CXₙ/Xₙ₋₁-≠-is-trivial ⊙skel (succ-≠ Sm≠n) ac)
C-cw-descend : ∀ {n} (⊙skel : ⊙Skeleton (S n))
{m} (m≠n : m ≠ ℕ-to-ℤ n) (m≠Sn : m ≠ ℕ-to-ℤ (S n))
→ ⊙has-cells-with-choice 0 ⊙skel i
→ C m ⊙⟦ ⊙skel ⟧ ≃ᴳ C m ⊙⟦ ⊙cw-init ⊙skel ⟧
C-cw-descend ⊙skel {m = negsucc m} -Sm≠n -Sm≠Sn
= C-cw-descend-at-succ ⊙skel (pred-≠ -Sm≠Sn) -Sm≠n
C-cw-descend ⊙skel {m = pos O} O≠n O≠Sn
= C-cw-descend-at-succ ⊙skel (pred-≠ O≠Sn) O≠n
C-cw-descend ⊙skel {m = pos (S n)} Sm≠n Sm≠Sn
= C-cw-descend-at-succ ⊙skel (pred-≠ Sm≠Sn) Sm≠n
abstract
C-cw-at-higher : ∀ {n} (⊙skel : ⊙Skeleton n) {m} (n<m : n < m)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ is-trivialᴳ (C (ℕ-to-ℤ m) ⊙⟦ ⊙skel ⟧)
C-cw-at-higher {n = O} ⊙skel 0<n ac =
CX₀-≠-is-trivial ⊙skel (ℕ-to-ℤ-≠ (≠-inv (<-to-≠ 0<n))) ac
C-cw-at-higher {n = S n} ⊙skel Sn<m ac =
iso-preserves'-trivial
(C-cw-descend ⊙skel
(ℕ-to-ℤ-≠ (≠-inv (<-to-≠ (<-trans ltS Sn<m))))
(ℕ-to-ℤ-≠ (≠-inv (<-to-≠ Sn<m)))
ac)
(C-cw-at-higher (⊙cw-init ⊙skel) (<-trans ltS Sn<m) (⊙init-has-cells-with-choice ⊙skel ac))
C-cw-at-negsucc : ∀ {n} (⊙skel : ⊙Skeleton n) m
→ ⊙has-cells-with-choice 0 ⊙skel i
→ is-trivialᴳ (C (negsucc m) ⊙⟦ ⊙skel ⟧)
C-cw-at-negsucc {n = O} ⊙skel m ac =
CX₀-≠-is-trivial ⊙skel (ℤ-negsucc≠pos m O) ac
C-cw-at-negsucc {n = S n} ⊙skel m ac =
iso-preserves'-trivial
(C-cw-descend ⊙skel
(ℤ-negsucc≠pos _ n)
(ℤ-negsucc≠pos _ (S n))
ac)
(C-cw-at-negsucc (⊙cw-init ⊙skel) m (⊙init-has-cells-with-choice ⊙skel ac))
C-cw-descend-at-lower : ∀ {n} (⊙skel : ⊙Skeleton (S n)) {m} (m<n : m < n)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ C (ℕ-to-ℤ m) ⊙⟦ ⊙skel ⟧ ≃ᴳ C (ℕ-to-ℤ m) ⊙⟦ ⊙cw-init ⊙skel ⟧
C-cw-descend-at-lower ⊙skel m<n ac =
C-cw-descend ⊙skel (ℕ-to-ℤ-≠ (<-to-≠ m<n)) (ℕ-to-ℤ-≠ (<-to-≠ (ltSR m<n))) ac
{-
favonia: it turns out easier (?) to do the descending step by step
C-cw-to-diag-at-lower : ∀ n {m} (Sn≤m : S n ≤ m) (⊙skel : ⊙Skeleton m)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ C (ℕ-to-ℤ n) ⊙⟦ ⊙skel ⟧ ≃ᴳ C (ℕ-to-ℤ n) ⊙⟦ ⊙cw-take Sn≤m ⊙skel ⟧
C-cw-to-diag-at-lower _ (inl idp) _ _ = idiso _
C-cw-to-diag-at-lower n (inr ltS) ⊙skel ac =
C-cw-descend (ℕ-to-ℤ n) (ℕ-to-ℤ-≠ (<-to-≠ ltS)) (ℕ-to-ℤ-≠ (<-to-≠ (ltSR ltS))) ⊙skel ac
C-cw-to-diag-at-lower n {S m} (inr (ltSR lt)) ⊙skel ac =
C-cw-to-diag-at-lower n (inr lt) (⊙cw-init ⊙skel) (⊙init-has-cells-with-choice ⊙skel ac)
∘eᴳ C-cw-descend (ℕ-to-ℤ n) (ℕ-to-ℤ-≠ n≠m) (ℕ-to-ℤ-≠ n≠Sm) ⊙skel ac
where
n≠Sm : n ≠ S m
n≠Sm = <-to-≠ (<-trans ltS (ltSR lt))
n≠m : n ≠ m
n≠m = <-to-≠ (<-trans ltS lt)
-}
|
{
"alphanum_fraction": 0.5721448468,
"avg_line_length": 38.6021505376,
"ext": "agda",
"hexsha": "904b91452588acc5d2cfb9156022ea34f1cdc837",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/Descending.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"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": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/Descending.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/Descending.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1813,
"size": 3590
}
|
module Issue558 where
data Nat : Set where
Z : Nat
S : Nat → Nat
data _≡_ {A : Set} (a : A) : A → Set where
Refl : a ≡ a
plus : Nat → Nat → Nat
plus Z n = n
plus (S n) m = S (plus n m)
record Addable (τ : Set) : Set where
constructor addable
field
_+_ : τ → τ → τ
open module AddableIFS {t : Set} {{r : Addable t}} = Addable {t} r
record CommAddable (τ : Set) : Set where
constructor commAddable
field
foo : Addable τ
comm : (a b : τ) → (a + b) ≡ (b + a)
natAdd : Addable Nat
natAdd = record {_+_ = plus}
postulate commPlus : (a b : Nat) → plus a b ≡ plus b a
commAdd : CommAddable Nat
commAdd = record {foo = natAdd; comm = commPlus}
open CommAddable {{...}}
test : (Z + Z) ≡ Z
test = comm Z Z
a : {x y : Nat} → (S (S Z) + (x + y)) ≡ ((x + y) + S (S Z))
a {x}{y} = comm (S (S Z)) (x + y) -- ERROR!
|
{
"alphanum_fraction": 0.5646916566,
"avg_line_length": 19.6904761905,
"ext": "agda",
"hexsha": "08028f8bf612d273b4b80f641a49dbb84ce0e243",
"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/succeed/Issue558.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/succeed/Issue558.agda",
"max_line_length": 66,
"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/succeed/Issue558.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": 322,
"size": 827
}
|
{-# OPTIONS --rewriting #-}
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
_+_ : Nat → Nat → Nat
zero + m = m
suc n + m = suc (n + m)
{-# BUILTIN NATPLUS _+_ #-} -- Without this, the internal error disappears.
postulate
_≡_ : Nat → Nat → Set
{-# BUILTIN REWRITE _≡_ #-}
postulate
a b n : Nat
Q : Nat → Set
R : (m n : Nat) → Q (m + n) → Set
+S : (n + a) ≡ b
{-# REWRITE +S #-}
variable
m : Nat -- Explicitly quantifying over m, the internal error disappears.
postulate
bug : (q : Q n) → R m n q
|
{
"alphanum_fraction": 0.5648994516,
"avg_line_length": 18.8620689655,
"ext": "agda",
"hexsha": "e959d550480176a7fd37c257067186c4dca55d35",
"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/Issue4323.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/Issue4323.agda",
"max_line_length": 75,
"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/Issue4323.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": 193,
"size": 547
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Ring.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.AbGroup
open import Cubical.Displayed.Base
open import Cubical.Displayed.Auto
open import Cubical.Displayed.Record
open import Cubical.Displayed.Universe
open import Cubical.Reflection.RecordEquiv
open Iso
private
variable
ℓ ℓ' ℓ'' : Level
record IsRing {R : Type ℓ}
(0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where
constructor isring
field
+IsAbGroup : IsAbGroup 0r _+_ -_
·IsMonoid : IsMonoid 1r _·_
·DistR+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z)
·DistL+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z)
-- This is in the Agda stdlib, but it's redundant
-- zero : (x : R) → (x · 0r ≡ 0r) × (0r · x ≡ 0r)
open IsAbGroup +IsAbGroup public
renaming
( isSemigroup to +IsSemigroup
; isMonoid to +IsMonoid
; isGroup to +IsGroup )
open IsMonoid ·IsMonoid public
renaming
( isSemigroup to ·IsSemigroup )
hiding
( is-set ) -- We only want to export one proof of this
unquoteDecl IsRingIsoΣ = declareRecordIsoΣ IsRingIsoΣ (quote IsRing)
record RingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
constructor ringstr
field
0r : A
1r : A
_+_ : A → A → A
_·_ : A → A → A
-_ : A → A
isRing : IsRing 0r 1r _+_ _·_ -_
infix 8 -_
infixl 7 _·_
infixl 6 _+_
open IsRing isRing public
Ring : ∀ ℓ → Type (ℓ-suc ℓ)
Ring ℓ = TypeWithStr ℓ RingStr
isSetRing : (R : Ring ℓ) → isSet ⟨ R ⟩
isSetRing R = R .snd .RingStr.isRing .IsRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
module _ {R : Type ℓ} {0r 1r : R} {_+_ _·_ : R → R → R} { -_ : R → R}
(is-setR : isSet R)
(+Assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+IdR : (x : R) → x + 0r ≡ x)
(+InvR : (x : R) → x + (- x) ≡ 0r)
(+Comm : (x y : R) → x + y ≡ y + x)
(·Assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·IdR : (x : R) → x · 1r ≡ x)
(·IdL : (x : R) → 1r · x ≡ x)
(·DistR+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·DistL+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z))
where
makeIsRing : IsRing 0r 1r _+_ _·_ -_
makeIsRing .IsRing.+IsAbGroup = makeIsAbGroup is-setR +Assoc +IdR +InvR +Comm
makeIsRing .IsRing.·IsMonoid = makeIsMonoid is-setR ·Assoc ·IdR ·IdL
makeIsRing .IsRing.·DistR+ = ·DistR+
makeIsRing .IsRing.·DistL+ = ·DistL+
module _ {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
(is-setR : isSet R)
(+Assoc : (x y z : R) → x + (y + z) ≡ (x + y) + z)
(+IdR : (x : R) → x + 0r ≡ x)
(+InvR : (x : R) → x + (- x) ≡ 0r)
(+Comm : (x y : R) → x + y ≡ y + x)
(·Assoc : (x y z : R) → x · (y · z) ≡ (x · y) · z)
(·IdR : (x : R) → x · 1r ≡ x)
(·IdL : (x : R) → 1r · x ≡ x)
(·DistR+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z))
(·DistL+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z))
where
makeRing : Ring ℓ
makeRing .fst = R
makeRing .snd .RingStr.0r = 0r
makeRing .snd .RingStr.1r = 1r
makeRing .snd .RingStr._+_ = _+_
makeRing .snd .RingStr._·_ = _·_
makeRing .snd .RingStr.-_ = -_
makeRing .snd .RingStr.isRing =
makeIsRing is-setR +Assoc +IdR +InvR +Comm
·Assoc ·IdR ·IdL ·DistR+ ·DistL+
record IsRingHom {A : Type ℓ} {B : Type ℓ'} (R : RingStr A) (f : A → B) (S : RingStr B)
: Type (ℓ-max ℓ ℓ')
where
-- Shorter qualified names
private
module R = RingStr R
module S = RingStr S
field
pres0 : f R.0r ≡ S.0r
pres1 : f R.1r ≡ S.1r
pres+ : (x y : A) → f (x R.+ y) ≡ f x S.+ f y
pres· : (x y : A) → f (x R.· y) ≡ f x S.· f y
pres- : (x : A) → f (R.- x) ≡ S.- (f x)
unquoteDecl IsRingHomIsoΣ = declareRecordIsoΣ IsRingHomIsoΣ (quote IsRingHom)
RingHom : (R : Ring ℓ) (S : Ring ℓ') → Type (ℓ-max ℓ ℓ')
RingHom R S = Σ[ f ∈ (⟨ R ⟩ → ⟨ S ⟩) ] IsRingHom (R .snd) f (S .snd)
IsRingEquiv : {A : Type ℓ} {B : Type ℓ'} (M : RingStr A) (e : A ≃ B) (N : RingStr B)
→ Type (ℓ-max ℓ ℓ')
IsRingEquiv M e N = IsRingHom M (e .fst) N
RingEquiv : (R : Ring ℓ) (S : Ring ℓ') → Type (ℓ-max ℓ ℓ')
RingEquiv R S = Σ[ e ∈ (⟨ R ⟩ ≃ ⟨ S ⟩) ] IsRingEquiv (R .snd) e (S .snd)
_$_ : {R : Ring ℓ} {S : Ring ℓ'} → (φ : RingHom R S) → (x : ⟨ R ⟩) → ⟨ S ⟩
φ $ x = φ .fst x
RingEquiv→RingHom : {A B : Ring ℓ} → RingEquiv A B → RingHom A B
RingEquiv→RingHom (e , eIsHom) = e .fst , eIsHom
RingHomIsEquiv→RingEquiv : {A B : Ring ℓ} (f : RingHom A B)
→ isEquiv (fst f) → RingEquiv A B
fst (fst (RingHomIsEquiv→RingEquiv f fIsEquiv)) = fst f
snd (fst (RingHomIsEquiv→RingEquiv f fIsEquiv)) = fIsEquiv
snd (RingHomIsEquiv→RingEquiv f fIsEquiv) = snd f
isPropIsRing : {R : Type ℓ} (0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R)
→ isProp (IsRing 0r 1r _+_ _·_ -_)
isPropIsRing 0r 1r _+_ _·_ -_ =
isOfHLevelRetractFromIso 1 IsRingIsoΣ
(isPropΣ (isPropIsAbGroup 0r _+_ (-_)) λ abgrp →
isProp× (isPropIsMonoid 1r _·_)
(isProp× (isPropΠ3 λ _ _ _ → abgrp .is-set _ _)
(isPropΠ3 λ _ _ _ → abgrp .is-set _ _)))
where
open IsAbGroup
isPropIsRingHom : {A : Type ℓ} {B : Type ℓ'} (R : RingStr A) (f : A → B) (S : RingStr B)
→ isProp (IsRingHom R f S)
isPropIsRingHom R f S = isOfHLevelRetractFromIso 1 IsRingHomIsoΣ
(isProp×4 (isSetRing (_ , S) _ _)
(isSetRing (_ , S) _ _)
(isPropΠ2 λ _ _ → isSetRing (_ , S) _ _)
(isPropΠ2 λ _ _ → isSetRing (_ , S) _ _)
(isPropΠ λ _ → isSetRing (_ , S) _ _))
isSetRingHom : (R : Ring ℓ) (S : Ring ℓ') → isSet (RingHom R S)
isSetRingHom R S = isSetΣSndProp (isSetΠ (λ _ → isSetRing S)) (λ f → isPropIsRingHom (snd R) f (snd S))
isSetRingEquiv : (A : Ring ℓ) (B : Ring ℓ') → isSet (RingEquiv A B)
isSetRingEquiv A B = isSetΣSndProp (isOfHLevel≃ 2 (isSetRing A) (isSetRing B))
(λ e → isPropIsRingHom (snd A) (fst e) (snd B))
RingHomPathP : (R S T : Ring ℓ) (p : S ≡ T) (φ : RingHom R S) (ψ : RingHom R T)
→ PathP (λ i → R .fst → p i .fst) (φ .fst) (ψ .fst)
→ PathP (λ i → RingHom R (p i)) φ ψ
RingHomPathP R S T p φ ψ q = ΣPathP (q , isProp→PathP (λ _ → isPropIsRingHom _ _ _) _ _)
RingHom≡ : {R S : Ring ℓ} {φ ψ : RingHom R S} → fst φ ≡ fst ψ → φ ≡ ψ
RingHom≡ = Σ≡Prop λ f → isPropIsRingHom _ f _
𝒮ᴰ-Ring : DUARel (𝒮-Univ ℓ) RingStr ℓ
𝒮ᴰ-Ring =
𝒮ᴰ-Record (𝒮-Univ _) IsRingEquiv
(fields:
data[ 0r ∣ null ∣ pres0 ]
data[ 1r ∣ null ∣ pres1 ]
data[ _+_ ∣ bin ∣ pres+ ]
data[ _·_ ∣ bin ∣ pres· ]
data[ -_ ∣ un ∣ pres- ]
prop[ isRing ∣ (λ _ _ → isPropIsRing _ _ _ _ _) ])
where
open RingStr
open IsRingHom
-- faster with some sharing
null = autoDUARel (𝒮-Univ _) (λ A → A)
un = autoDUARel (𝒮-Univ _) (λ A → A → A)
bin = autoDUARel (𝒮-Univ _) (λ A → A → A → A)
RingPath : (R S : Ring ℓ) → RingEquiv R S ≃ (R ≡ S)
RingPath = ∫ 𝒮ᴰ-Ring .UARel.ua
uaRing : {A B : Ring ℓ} → RingEquiv A B → A ≡ B
uaRing {A = A} {B = B} = equivFun (RingPath A B)
isGroupoidRing : isGroupoid (Ring ℓ)
isGroupoidRing _ _ = isOfHLevelRespectEquiv 2 (RingPath _ _) (isSetRingEquiv _ _)
open RingStr
open IsRingHom
-- TODO: Induced structure results are temporarily inconvenient while we transition between algebra
-- representations
module _ (R : Ring ℓ) {A : Type ℓ}
(0a 1a : A)
(add mul : A → A → A)
(inv : A → A)
(e : ⟨ R ⟩ ≃ A)
(p0 : e .fst (R .snd .0r) ≡ 0a)
(p1 : e .fst (R .snd .1r) ≡ 1a)
(p+ : ∀ x y → e .fst (R .snd ._+_ x y) ≡ add (e .fst x) (e .fst y))
(p· : ∀ x y → e .fst (R .snd ._·_ x y) ≡ mul (e .fst x) (e .fst y))
(pinv : ∀ x → e .fst (R .snd .-_ x) ≡ inv (e .fst x))
where
private
module R = RingStr (R .snd)
BaseΣ : Type (ℓ-suc ℓ)
BaseΣ = Σ[ B ∈ Type ℓ ] B × B × (B → B → B) × (B → B → B) × (B → B)
FamilyΣ : BaseΣ → Type ℓ
FamilyΣ (B , u0 , u1 , a , m , i) = IsRing u0 u1 a m i
inducedΣ : FamilyΣ (A , 0a , 1a , add , mul , inv)
inducedΣ =
subst FamilyΣ
(UARel.≅→≡ (autoUARel BaseΣ) (e , p0 , p1 , p+ , p· , pinv))
R.isRing
InducedRing : Ring ℓ
InducedRing .fst = A
0r (InducedRing .snd) = 0a
1r (InducedRing .snd) = 1a
_+_ (InducedRing .snd) = add
_·_ (InducedRing .snd) = mul
- InducedRing .snd = inv
isRing (InducedRing .snd) = inducedΣ
InducedRingEquiv : RingEquiv R InducedRing
fst InducedRingEquiv = e
pres0 (snd InducedRingEquiv) = p0
pres1 (snd InducedRingEquiv) = p1
pres+ (snd InducedRingEquiv) = p+
pres· (snd InducedRingEquiv) = p·
pres- (snd InducedRingEquiv) = pinv
InducedRingPath : R ≡ InducedRing
InducedRingPath = RingPath _ _ .fst InducedRingEquiv
-- Rings have an abelian group and a monoid
module _ ((A , (ringstr 0r 1r _+_ _·_ -_ R)) : Ring ℓ) where
Ring→AbGroup : AbGroup ℓ
Ring→AbGroup .fst = A
Ring→AbGroup .snd .AbGroupStr.0g = 0r
Ring→AbGroup .snd .AbGroupStr._+_ = _+_
Ring→AbGroup .snd .AbGroupStr.-_ = -_
Ring→AbGroup .snd .AbGroupStr.isAbGroup = IsRing.+IsAbGroup R
Ring→MultMonoid : Monoid ℓ
Ring→MultMonoid = monoid A 1r _·_ (IsRing.·IsMonoid R)
Ring→Group : Ring ℓ → Group ℓ
Ring→Group = AbGroup→Group ∘ Ring→AbGroup
Ring→AddMonoid : Ring ℓ → Monoid ℓ
Ring→AddMonoid = Group→Monoid ∘ Ring→Group
-- Smart constructor for ring homomorphisms
-- that infers the other equations from pres1, pres+, and pres·
module _ {R : Ring ℓ} {S : Ring ℓ'} {f : ⟨ R ⟩ → ⟨ S ⟩} where
private
module R = RingStr (R .snd)
module S = RingStr (S .snd)
module _
(p1 : f R.1r ≡ S.1r)
(p+ : (x y : ⟨ R ⟩) → f (x R.+ y) ≡ f x S.+ f y)
(p· : (x y : ⟨ R ⟩) → f (x R.· y) ≡ f x S.· f y)
where
open IsRingHom
private
isGHom : IsGroupHom (Ring→Group R .snd) f (Ring→Group S .snd)
isGHom = makeIsGroupHom p+
makeIsRingHom : IsRingHom (R .snd) f (S .snd)
makeIsRingHom .pres0 = isGHom .IsGroupHom.pres1
makeIsRingHom .pres1 = p1
makeIsRingHom .pres+ = p+
makeIsRingHom .pres· = p·
makeIsRingHom .pres- = isGHom .IsGroupHom.presinv
|
{
"alphanum_fraction": 0.5525492361,
"avg_line_length": 32.6306306306,
"ext": "agda",
"hexsha": "c89640ae8ba0953163df6b052c9581c0e0310308",
"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/Ring/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/Ring/Base.agda",
"max_line_length": 103,
"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/Ring/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4457,
"size": 10866
}
|
module Data.Tree where
open import Data.Tree.Base public
|
{
"alphanum_fraction": 0.8103448276,
"avg_line_length": 14.5,
"ext": "agda",
"hexsha": "64e7c097e7976eca734e9cda3987b340b585aaf3",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Data/Tree.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Data/Tree.agda",
"max_line_length": 33,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Data/Tree.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 12,
"size": 58
}
|
{-# OPTIONS --without-K #-}
module sets.nat.ordering.leq where
open import sets.nat.ordering.leq.core public
open import sets.nat.ordering.leq.level public
open import sets.nat.ordering.leq.decide public
|
{
"alphanum_fraction": 0.7853658537,
"avg_line_length": 29.2857142857,
"ext": "agda",
"hexsha": "6751c1de330438486c84d4b1bf7544e7c3366fd0",
"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/sets/nat/ordering/leq.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/sets/nat/ordering/leq.agda",
"max_line_length": 47,
"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/sets/nat/ordering/leq.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": 53,
"size": 205
}
|
module InfConj where
open import Data.Bool
open import Data.Sum
open import Relation.Binary.PropositionalEquality
record Stream (A : Set) : Set where
coinductive
constructor _∷_
field
hd : A
tl : Stream A
open Stream public
-- | Partial elements
record D (A : Set) : Set where
coinductive
field step : A ⊎ D A
open D public
-- | Lift ⊎ to relations
data _⊎'_ {A B : Set} (R : A → A → Set) (S : B → B → Set) : A ⊎ B → A ⊎ B → Set where
inj₁' : {x y : A} → R x y → (R ⊎' S) (inj₁ x) (inj₁ y)
inj₂' : {x y : B} → S x y → (R ⊎' S) (inj₂ x) (inj₂ y)
-- | Bisimilarity for partial elements
record _~_ {A : Set} (x y : D A) : Set where
coinductive
field step~ : (_≡_ ⊎' _~_) (x .step) (y .step)
open _~_ public
-- | Injection into D
η : {A : Set} → A → D A
η a .step = inj₁ a
-- | Conjunction for partial Booleans
_∧'_ : D Bool → D Bool → D Bool
(x ∧' y) .step with x .step | y .step
(x ∧' y) .step | inj₁ false | v = inj₁ false
(x ∧' y) .step | inj₁ true | v = v
(x ∧' y) .step | inj₂ x' | inj₁ false = inj₁ false
(x ∧' y) .step | inj₂ x' | inj₁ true = inj₂ x'
(x ∧' y) .step | inj₂ x' | inj₂ y' = inj₂ (x' ∧' y')
-- | Infinite conjunction
⋀∞ : Stream Bool → D Bool
⋀∞ s .step with s .hd
⋀∞ s .step | false = inj₁ false
⋀∞ s .step | true = inj₂ (⋀∞ (s .tl))
-- | Constant stream
K : {A : Set} → A → Stream A
K a .hd = a
K a .tl = K a
-- | Non-terminating computation
⊥ : {A : Set} → D A
⊥ .step = inj₂ ⊥
-- | Infinite conjunction of constant stream does not terminate
prop : ⋀∞ (K true) ~ ⊥
prop .step~ = inj₂' prop
-- | If there is an entry "false" in the stream, then the infinite conjunction
-- terminates. Here is just an example.
ex : ⋀∞ (false ∷ K true) ~ η false
ex .step~ = inj₁' refl
|
{
"alphanum_fraction": 0.5707013575,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "2e7ce4693f21bb89b5e8b421a381ebeb45f7e457",
"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": "Partial/InfConj.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": "Partial/InfConj.agda",
"max_line_length": 85,
"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": "Partial/InfConj.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 695,
"size": 1768
}
|
------------------------------------------------------------------------
-- List membership and some related definitions
open import Level using (Level; _⊔_)
open import Relation.Binary
open import Relation.Binary.List.Pointwise as ListEq using ([]; _∷_)
open import Relation.Nullary
open import Data.List
open import Data.List.Any
open import Function
import Relation.Binary.InducedPreorders as Ind
open import Data.Product as Prod using (∃; _×_; _,_)
module Membership-old {c ℓ : Level} (S : Setoid c ℓ) where
private
open module S = Setoid S using (_≈_) renaming (Carrier to A)
open module LS = Setoid (ListEq.setoid S)
using () renaming (_≈_ to _≋_)
-- If a predicate P respects the underlying equality then Any P
-- respects the list equality.
lift-resp : ∀ {p} {P : A → Set p} →
P Respects _≈_ → Any P Respects _≋_
lift-resp resp [] ()
lift-resp resp (x≈y ∷ xs≈ys) (here px) = here (resp x≈y px)
lift-resp resp (x≈y ∷ xs≈ys) (there pxs) =
there (lift-resp resp xs≈ys pxs)
-- List membership.
infix 4 _∈_ _∉_
_∈_ : A → List A → Set _
x ∈ xs = Any (_≈_ x) xs
_∉_ : A → List A → Set _
x ∉ xs = ¬ x ∈ xs
-- Subsets.
infix 4 _⊆_ _⊈_
_⊆_ : List A → List A → Set _
xs ⊆ ys = ∀ {x} → x ∈ xs → x ∈ ys
_⊈_ : List A → List A → Set _
xs ⊈ ys = ¬ xs ⊆ ys
-- Equality is respected by the predicate which is used to define
-- _∈_.
∈-resp-≈ : ∀ {x} → (_≈_ x) Respects _≈_
∈-resp-≈ = flip S.trans
-- List equality is respected by _∈_.
∈-resp-list-≈ : ∀ {x} → _∈_ x Respects _≋_
∈-resp-list-≈ = lift-resp ∈-resp-≈
-- _⊆_ is a preorder.
⊆-preorder : Preorder _ _ _
⊆-preorder = Ind.InducedPreorder₂ (ListEq.setoid S) _∈_ ∈-resp-list-≈
module ⊆-Reasoning where
import Relation.Binary.PreorderReasoning as PreR
open PreR ⊆-preorder public
renaming (_∼⟨_⟩_ to _⊆⟨_⟩_)
infix 1 _∈⟨_⟩_
_∈⟨_⟩_ : ∀ x {xs ys} → x ∈ xs → xs IsRelatedTo ys → x ∈ ys
x ∈⟨ x∈xs ⟩ xs⊆ys = (begin xs⊆ys) x∈xs
-- A variant of List.map.
map-with-∈ : ∀ {b} {B : Set b}
(xs : List A) → (∀ {x} → x ∈ xs → B) → List B
map-with-∈ [] f = []
map-with-∈ (x ∷ xs) f = f (here S.refl) ∷ map-with-∈ xs (f ∘ there)
-- Finds an element satisfying the predicate.
find : ∀ {p} {P : A → Set p} {xs} →
Any P xs → ∃ λ x → x ∈ xs × P x
find (here px) = (_ , here S.refl , px)
find (there pxs) = Prod.map id (Prod.map there id) (find pxs)
lose : ∀ {p} {P : A → Set p} {x xs} →
P Respects _≈_ → x ∈ xs → P x → Any P xs
lose resp x∈xs px = Data.List.Any.map (flip resp px) x∈xs
|
{
"alphanum_fraction": 0.5608828006,
"avg_line_length": 28.5652173913,
"ext": "agda",
"hexsha": "ada23fc138c1e66f317da46a6851e454c23a2e5e",
"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": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/singly-typed-actors",
"max_forks_repo_path": "unused/Membership-old.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"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": "Zalastax/singly-typed-actors",
"max_issues_repo_path": "unused/Membership-old.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/thesis",
"max_stars_repo_path": "unused/Membership-old.agda",
"max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z",
"num_tokens": 985,
"size": 2628
}
|
data ⊤ : Set where tt : ⊤
record R : Set where
constructor r
field .x : ⊤
f : R → R
R.x (f (r x)) = {!x!}
|
{
"alphanum_fraction": 0.4955752212,
"avg_line_length": 11.3,
"ext": "agda",
"hexsha": "5b4dec09dfba3d3165c703e632cfe7e23628fa3b",
"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/interaction/Issue3452.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/interaction/Issue3452.agda",
"max_line_length": 25,
"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/interaction/Issue3452.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": 49,
"size": 113
}
|
-- {-# OPTIONS -v tc.with:40 #-}
id : (A : Set) → A → A
id A = {!id′!}
-- C-c C-h produces: id′ : ∀ {A} → A
-- when it should produce: id′ : ∀ {A} → A → A
f : (A : Set) (B : A → Set) (a : A) → B a
f A B a = {!g A a!}
-- Before: ∀ {A} {B : A → Set} A₁ (a : A₁) → B a
-- After: ∀ A (a : A) {B : A → Set} → B a
|
{
"alphanum_fraction": 0.3839009288,
"avg_line_length": 26.9166666667,
"ext": "agda",
"hexsha": "5c06d5cb00d2720fd0c566ff642397e85e3c36d9",
"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": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/interaction/Issue1130.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/Issue1130.agda",
"max_line_length": 50,
"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/interaction/Issue1130.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 151,
"size": 323
}
|
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.PushoutDef
module Homotopy.PushoutIsPushout {i} (d : pushout-diag i) where
import Homotopy.PushoutUP as PushoutUP
open PushoutUP d (λ _ → unit) -- A B C f g (λ _ → unit)
pushout-cocone : cocone (pushout d)
pushout-cocone = (left , right , glue)
factor-pushout : (E : Set i) → (cocone E → (pushout d → E))
factor-pushout E (A→top , B→top , h) = pushout-rec-nondep E A→top B→top h
abstract
pushout-is-pushout : is-pushout (pushout d) pushout-cocone
pushout-is-pushout E ⦃ tt ⦄ = iso-is-eq _ (factor-pushout E)
(λ y → ap (λ u → _ , _ , u)
(funext (λ x → pushout-β-glue-nondep E (cocone.A→top y)
(cocone.B→top y) (cocone.h y) x)))
(λ f → funext (pushout-rec _ (λ _ → refl) (λ _ → refl)
(λ c → trans-app≡app
(pushout-rec-nondep E (f ◯ left) (f ◯ right)
(λ c' → ap f (glue c')))
f (glue c) refl
∘ (ap (λ u → ! u ∘ ap f (glue c))
(pushout-β-glue-nondep E (f ◯ left) (f ◯ right)
(λ c' → ap f (glue c')) c)
∘ opposite-left-inverse (ap f (glue c))))))
|
{
"alphanum_fraction": 0.538590604,
"avg_line_length": 36.1212121212,
"ext": "agda",
"hexsha": "f785856f1e67fae3f7239315d143e592d64655c1",
"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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Homotopy/PushoutIsPushout.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"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": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Homotopy/PushoutIsPushout.agda",
"max_line_length": 73,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "old/Homotopy/PushoutIsPushout.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": 410,
"size": 1192
}
|
{-# OPTIONS -v tc.force:60 #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.List
module _ {a} {A : Set a} where
[_] : A → List A
[ x ] = x ∷ []
data FSet : List A → Set a where
sg : (x : A) → FSet [ x ]
-- ^ should be forced
HOLE : Set
HOLE = {!!} -- just to force make bugs to look at the output
|
{
"alphanum_fraction": 0.552238806,
"avg_line_length": 19.7058823529,
"ext": "agda",
"hexsha": "702177211bb6d56274514e041bd32bcbd8294210",
"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/Issue3898.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/Issue3898.agda",
"max_line_length": 63,
"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/Issue3898.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": 116,
"size": 335
}
|
module Numeral.Natural.Function.FlooredLogarithm where
open import Data
open import Data.Boolean.Stmt
open import Numeral.Natural
open import Numeral.Natural.Inductions
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.FlooredDivision
open import Numeral.Natural.Oper.FlooredDivision.Proofs
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Structure.Relator.Ordering
open Structure.Relator.Ordering.Strict.Properties
⌊log⌋ : (b : ℕ) → ⦃ _ : IsTrue(b ≥? 2) ⦄ → (n : ℕ) → ⦃ _ : IsTrue(n ≥? 1) ⦄ → ℕ
⌊log⌋ b@(𝐒(𝐒 _)) n = wellfounded-recursion (_<_) f(n) where
f : (n : ℕ) → ((prev : ℕ) ⦃ _ : (prev < n) ⦄ → ℕ) → ℕ
f 𝟎 _ = 𝟎
f (𝐒 𝟎) _ = 𝟎
f n@(𝐒(𝐒 _)) prev = 𝐒(prev((n ⌊/⌋ b)) ⦃ [⌊/⌋]-ltₗ {b = b} ⦄)
|
{
"alphanum_fraction": 0.6859323882,
"avg_line_length": 38.2083333333,
"ext": "agda",
"hexsha": "da088a946968fbdfa4efd54fa5b9401c63089bf4",
"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/Function/FlooredLogarithm.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/Function/FlooredLogarithm.agda",
"max_line_length": 79,
"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/Function/FlooredLogarithm.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": 359,
"size": 917
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Natural Literals
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Literals where
open import Agda.Builtin.FromNat
open import Agda.Builtin.Nat
open import Data.Unit
number : Number Nat
number = record
{ Constraint = λ _ → ⊤
; fromNat = λ n → n
}
|
{
"alphanum_fraction": 0.4547511312,
"avg_line_length": 22.1,
"ext": "agda",
"hexsha": "ac6a33aaacc332feb5c10a274bd2dbc132bfc4fe",
"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/Data/Nat/Literals.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/Nat/Literals.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/Data/Nat/Literals.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": 88,
"size": 442
}
|
{-# OPTIONS --without-K --exact-split --safe #-}
module Fragment.Setoid.Morphism.Base where
open import Level using (Level; _⊔_)
open import Function using (_∘_; Congruent)
import Relation.Binary.PropositionalEquality as PE
open import Relation.Binary using (Setoid)
private
variable
a b c ℓ₁ ℓ₂ ℓ₃ : Level
module _ (S : Setoid a ℓ₁) (T : Setoid b ℓ₂) where
open Setoid S renaming (Carrier to A; _≈_ to _≈₁_)
open Setoid T renaming (Carrier to B; _≈_ to _≈₂_)
infixr 1 _↝_
record _↝_ : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
∣_∣ : A → B
∣_∣-cong : Congruent _≈₁_ _≈₂_ ∣_∣
open _↝_ public
lift : ∀ {A : Set a} {B : Setoid b ℓ₂}
→ (A → Setoid.Carrier B)
→ (PE.setoid A ↝ B)
lift {B = B} f
= record { ∣_∣ = f
; ∣_∣-cong = reflexive ∘ (PE.cong f)
}
where open Setoid B
id : ∀ {A : Setoid a ℓ₁} → A ↝ A
id = record { ∣_∣ = λ x → x ; ∣_∣-cong = λ x → x }
_·_ : ∀ {A : Setoid a ℓ₁} {B : Setoid b ℓ₂} {C : Setoid c ℓ₃}
→ B ↝ C → A ↝ B → A ↝ C
g · f = record { ∣_∣ = ∣ g ∣ ∘ ∣ f ∣
; ∣_∣-cong = ∣ g ∣-cong ∘ ∣ f ∣-cong
}
|
{
"alphanum_fraction": 0.5329815303,
"avg_line_length": 24.7173913043,
"ext": "agda",
"hexsha": "fd05e5f006236d4957b00dc8515c44b0e3d46b2a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Setoid/Morphism/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Setoid/Morphism/Base.agda",
"max_line_length": 61,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Setoid/Morphism/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 488,
"size": 1137
}
|
{-# OPTIONS --cubical --safe #-}
module Data.Unit.Properties where
open import Data.Unit
open import Prelude
isProp⊤ : isProp ⊤
isProp⊤ _ _ = refl
|
{
"alphanum_fraction": 0.7066666667,
"avg_line_length": 15,
"ext": "agda",
"hexsha": "2497d6023e5ac0e5879b6926f0231798444c8968",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Unit/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"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/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Unit/Properties.agda",
"max_line_length": 33,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Unit/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 45,
"size": 150
}
|
postulate
R : Set → Set1
r : {X : Set} {{ _ : R X }} → X → Set
A : Set
a : A
instance
RI : R A
-- RI = {!!} -- uncommenting lets instance resolution succeed
foo : r a
|
{
"alphanum_fraction": 0.5248618785,
"avg_line_length": 15.0833333333,
"ext": "agda",
"hexsha": "cbaa18ca5e472af05ae84c6e8db67fa9276c38bd",
"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/Issue3338.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/Issue3338.agda",
"max_line_length": 63,
"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/Issue3338.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": 67,
"size": 181
}
|
module Numeral.Natural.Relation.Divisibility.Proofs.Product where
open import Data.Tuple
open import Functional
open import Logic
open import Logic.Predicate
open import Logic.Propositional
import Lvl
open import Numeral.Integer
import Numeral.Integer.Oper as ℤ
open import Numeral.Integer.Proofs
import Numeral.Integer.Relation.Divisibility as ℤ
import Numeral.Integer.Relation.Divisibility.Proofs as ℤ
open import Numeral.Natural
open import Numeral.Natural.Coprime
open import Numeral.Natural.Coprime.Proofs
open import Numeral.Natural.Function.GreatestCommonDivisor.Extended
open import Numeral.Natural.Relation.Divisibility.Proofs
open import Numeral.Natural.Oper
open import Numeral.Natural.Prime
open import Numeral.Natural.Relation.Divisibility
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Function
open import Structure.Function.Multi
open import Structure.Operator
open import Structure.Operator.Proofs.Util
open import Structure.Operator.Properties
open import Structure.Relator.Properties
open import Structure.Relator
open import Syntax.Transitivity
private variable n x y d p : ℕ
-- When d and x does not have any common divisors, thus no common prime divisors, it means that all common prime divisors lies in d and y.
-- Also called: Generalized Euclid's lemma.
coprime-divides-of-[⋅] : (d ∣ (x ⋅ y)) → Coprime(d)(x) → (d ∣ y)
coprime-divides-of-[⋅] {d}{x}{y} dxy coprim
with [∃]-intro (a , b) ⦃ p ⦄ ← gcd-linearCombination-existence {d}{x}
= sub₂((ℤ._∣_) on₂ (+ₙ_))(_∣_) (substitute₂ᵣ(ℤ._∣_) {+ₙ d} eq div) where
eq =
((+ₙ d) ℤ.⋅ a ℤ.⋅ (+ₙ y)) ℤ.+ ((+ₙ x) ℤ.⋅ b ℤ.⋅ (+ₙ y)) 🝖[ _≡_ ]-[ distributivityᵣ(ℤ._⋅_)(ℤ._+_) {(+ₙ d) ℤ.⋅ a}{(+ₙ x) ℤ.⋅ b}{+ₙ y} ]-sym
(((+ₙ d) ℤ.⋅ a) ℤ.+ ((+ₙ x) ℤ.⋅ b)) ℤ.⋅ (+ₙ y) 🝖[ _≡_ ]-[ congruence₂ₗ(ℤ._⋅_)(+ₙ y) {_}{+ₙ 1} (p 🝖 congruence₁(+ₙ_) ([↔]-to-[→] Coprime-gcd coprim)) ]
(+ₙ 1) ℤ.⋅ (+ₙ y) 🝖[ _≡_ ]-[ identityₗ(ℤ._⋅_)(+ₙ 1) ]
(+ₙ y) 🝖-end
r-eq : (+ₙ(x ⋅ y)) ℤ.⋅ b ≡ (+ₙ x) ℤ.⋅ b ℤ.⋅ (+ₙ y)
r-eq =
(+ₙ (x ⋅ y)) ℤ.⋅ b 🝖[ _≡_ ]-[ congruence₂ₗ(ℤ._⋅_)(b) (preserving₂(+ₙ_)(_⋅_)(ℤ._⋅_)) ]
((+ₙ x) ℤ.⋅ (+ₙ y)) ℤ.⋅ b 🝖[ _≡_ ]-[ One.commuteᵣ-assocₗ {a = +ₙ x}{b = +ₙ y}{c = b} ]
((+ₙ x) ℤ.⋅ b) ℤ.⋅ (+ₙ y) 🝖-end
div : (+ₙ d) ℤ.∣ ((+ₙ d) ℤ.⋅ a ℤ.⋅ (+ₙ y) ℤ.+ (+ₙ x) ℤ.⋅ b ℤ.⋅ (+ₙ y))
div = ℤ.divides-with-[+] {+ₙ d}{(+ₙ d) ℤ.⋅ a ℤ.⋅ (+ₙ y)}{(+ₙ x) ℤ.⋅ b ℤ.⋅ (+ₙ y)}
(ℤ.divides-with-[⋅] {+ₙ d}{(+ₙ d) ℤ.⋅ a} ([∨]-introₗ (ℤ.divides-with-[⋅] {+ₙ d}{+ₙ d} ([∨]-introₗ (reflexivity(_∣_))))))
(substitute₂ᵣ(ℤ._∣_) {+ₙ d} r-eq (ℤ.divides-with-[⋅] {+ₙ d}{+ₙ(x ⋅ y)} ([∨]-introₗ dxy)))
-- A prime number dividing a product means that the prime divides one of its factors.
-- Obvious intuitively because prime numbers are the "smallest units" in the context of divisibility.
-- Also called: Euclid's lemma.
prime-divides-of-[⋅] : Prime(p) → (p ∣ (x ⋅ y)) → ((p ∣ x) ∨ (p ∣ y))
prime-divides-of-[⋅] {p}{x}{y} prim pxy with Prime-to-div-or-coprime {y = x} prim
... | [∨]-introₗ div = [∨]-introₗ div
... | [∨]-introᵣ coprim = [∨]-introᵣ (coprime-divides-of-[⋅] pxy coprim)
Coprime-of-[⋅] : ∀{x y z} → Coprime(x)(y) → Coprime(x)(z) → Coprime(x)(y ⋅ z)
Coprime-of-[⋅] {x}{y}{z} xy (intro xz) = intro (\{n} → nx ↦ nyz ↦ xz nx (coprime-divides-of-[⋅] {n}{y}{z} nyz (divides-to-converse-coprime nx xy)))
Coprime-of-[^]ₗ : Coprime(x)(y) ← Coprime(x)(y ^ 𝐒(n))
Coprime-of-[^]ₗ {x}{y}{ℕ.𝟎} p = p
Coprime-of-[^]ₗ {x}{y}{ℕ.𝐒 n} (intro p) = Coprime-of-[^]ₗ {n = n} (intro \{d} dx dyn → p dx (divides-with-[⋅] {d}{y}{y ^ 𝐒(n)} ([∨]-introᵣ dyn)))
Coprime-of-[^]ᵣ : Coprime(x)(y) → Coprime(x)(y ^ n)
Coprime-of-[^]ᵣ {x}{y}{ℕ.𝟎} p = symmetry(Coprime) Coprime-of-1
Coprime-of-[^]ᵣ {x}{y}{ℕ.𝐒 n} p = Coprime-of-[⋅] p (Coprime-of-[^]ᵣ {n = n} p)
-- Coprime-[+][⋅] : Coprime(x)(y) ↔ Coprime(x + y)(x ⋅ y)
|
{
"alphanum_fraction": 0.5912628672,
"avg_line_length": 51.0641025641,
"ext": "agda",
"hexsha": "0cc1a7cd9da3d69554b7aa06c0d67cc1535c4cdf",
"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/Relation/Divisibility/Proofs/Product.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/Relation/Divisibility/Proofs/Product.agda",
"max_line_length": 165,
"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/Relation/Divisibility/Proofs/Product.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": 1810,
"size": 3983
}
|
open import Agda.Primitive
variable
@0 ℓ : Level
A : Set ℓ
levelOf : A → Level
levelOf {a} _ = a
|
{
"alphanum_fraction": 0.640776699,
"avg_line_length": 11.4444444444,
"ext": "agda",
"hexsha": "bccae8166c58106c3df5483916239d953b2c4cab",
"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/Issue5363b.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/Issue5363b.agda",
"max_line_length": 26,
"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/Issue5363b.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": 40,
"size": 103
}
|
module Selective.Examples.Bookstore where
open import Selective.ActorMonad
open import Selective.Libraries.Call using (UniqueTag ; call)
open import Prelude
open import Data.Nat
using ( _≟_ ; pred ; ⌈_/2⌉ ; _≤?_ ; _∸_ ; _≤_ ; z≤n ; s≤s ; _<_ ; _≰_ )
open import Data.Nat.Properties
using (≤-antisym ; ≰⇒>)
open import Data.Nat.Show
using (show)
open import Data.String
using (primStringEquality)
open import Debug
BookTitle = String
Money = ℕ
data BuyerRole : Set where
Buyer1 Buyer2 : BuyerRole
record Book : Set where
field
title : BookTitle
price : Money
-- ===========
-- GET QUOTE
-- ===========
GetQuoteReply : MessageType
GetQuoteReply = ValueType UniqueTag ∷ [ ValueType (Maybe Book) ]ˡ
GetQuoteReplyInterface : InboxShape
GetQuoteReplyInterface = [ GetQuoteReply ]ˡ
GetQuote : MessageType
GetQuote = ValueType UniqueTag ∷ ReferenceType GetQuoteReplyInterface ∷ [ ValueType BookTitle ]ˡ
-- ======================
-- PROPOSE CONTRIBUTION
-- ======================
record Contribution : Set where
field
book : Book
money : Money
ContributionMessage : MessageType
ContributionMessage = [ ValueType Contribution ]ˡ
-- ===============
-- AGREE OR QUIT
-- ===============
data AgreeChoice : Set where
AGREE QUIT : AgreeChoice
AgreeDecision : MessageType
AgreeDecision = [ ValueType AgreeChoice ]ˡ
-- ================
-- TRANSFER MONEY
-- ================
Transfer : MessageType
Transfer = ValueType BuyerRole ∷ [ ValueType Contribution ]ˡ
-- ============
-- INTERFACES
-- ============
Buyer1-to-Seller : InboxShape
Buyer1-to-Seller = GetQuote ∷ [ Transfer ]ˡ
Buyer2-to-Seller : InboxShape
Buyer2-to-Seller = AgreeDecision ∷ [ Transfer ]ˡ
Buyer1-to-Buyer2 : InboxShape
Buyer1-to-Buyer2 = [ ContributionMessage ]ˡ
Buyer2-to-Buyer1 : InboxShape
Buyer2-to-Buyer1 = [ AgreeDecision ]ˡ
SellerInterface : InboxShape
SellerInterface = GetQuote ∷ AgreeDecision ∷ [ Transfer ]ˡ
Buyer1Interface : InboxShape
Buyer1Interface = [ ReferenceType Buyer1-to-Seller ]ˡ ∷ [ ReferenceType Buyer1-to-Buyer2 ]ˡ ∷ GetQuoteReply ∷ [ AgreeDecision ]ˡ
Buyer2Interface : InboxShape
Buyer2Interface = [ ReferenceType Buyer2-to-Seller ]ˡ ∷ [ ReferenceType Buyer2-to-Buyer1 ]ˡ ∷ [ ContributionMessage ]ˡ
-- ========
-- COMMON
-- ========
book1 : BookTitle
book1 = "Crime and Punishment"
transfer-money : ∀ {i IS Seller Γ} →
Γ ⊢ Seller →
[ Transfer ]ˡ <: Seller →
BuyerRole →
Book →
Money →
∞ActorM i IS ⊤₁ Γ (λ _ → Γ)
transfer-money p sub role book money = p ![t: translate-⊆ sub Z ] ((lift role) ∷ [ lift record { book = book ; money = money } ]ᵃ)
-- ========
-- SELLER
-- ========
same-buyer-role : BuyerRole → BuyerRole → Bool
same-buyer-role Buyer1 Buyer1 = true
same-buyer-role Buyer1 Buyer2 = false
same-buyer-role Buyer2 Buyer1 = false
same-buyer-role Buyer2 Buyer2 = true
data TransactionStatus (book : Book) (c1 c2 : Contribution) : Set where
TooLittleMoney : (Contribution.money c1 + Contribution.money c2) < (Book.price book) → TransactionStatus book c1 c2
Accepted : (Contribution.money c1 + Contribution.money c2) ≡ (Book.price book) → TransactionStatus book c1 c2
TooMuchMoney : (Book.price book) < (Contribution.money c1 + Contribution.money c2) → TransactionStatus book c1 c2
transaction-status? : ∀ book c1 c2 → TransactionStatus book c1 c2
transaction-status? book c1 c2 with (Contribution.money c1 + Contribution.money c2 ≤? Book.price book) | (Book.price book ≤? Contribution.money c1 + Contribution.money c2)
transaction-status? book c1 c2 | yes p | yes q = Accepted (≤-antisym p q)
transaction-status? book c1 c2 | yes p | no ¬p = TooLittleMoney (≰⇒> ¬p)
transaction-status? book c1 c2 | no ¬p | q = TooMuchMoney (≰⇒> ¬p)
seller : ∀ {i} → ActorM i SellerInterface ⊤₁ [] (λ _ → [])
seller = begin do
record {msg = Msg Z (tag ∷ _ ∷ title ∷ []) } ← selective-receive select-quote
where
record { msg = (Msg (S _) _) ; msg-ok = () }
let maybe-book = find-book known-books title
(Z ![t: Z ] (lift tag ∷ [ lift maybe-book ]ᵃ))
after-book-quote maybe-book
where
select-quote : MessageFilter SellerInterface
select-quote (Msg Z _) = true
select-quote _ = false
known-books : List Book
known-books = [ record { title = book1 ; price = 37 } ]ˡ
find-book : List Book → BookTitle → Maybe Book
find-book [] title = nothing
find-book (book ∷ books) title with (primStringEquality (Book.title book) title)
... | true = just book
... | false = find-book books title
select-decision : MessageFilter SellerInterface
select-decision (Msg (S Z) _) = true
select-decision _ = false
wait-for-decision : ∀ {i Γ} →
∞ActorM i SellerInterface (Lift (lsuc lzero) AgreeChoice) Γ (λ _ → Γ)
wait-for-decision = do
record { msg = Msg (S Z) (ac ∷ []) } ← (selective-receive select-decision)
where
record { msg = (Msg Z _) ; msg-ok = () }
record { msg = (Msg (S (S _)) _) ; msg-ok = () }
return ac
select-contribution-from : BuyerRole → MessageFilter SellerInterface
select-contribution-from br (Msg (S (S Z)) (br' ∷ _)) = same-buyer-role br br'
select-contribution-from _ _ = false
wait-for-money-from : ∀ {i Γ} →
BuyerRole →
∞ActorM i SellerInterface (Lift (lsuc lzero) Contribution) Γ (λ _ → Γ)
wait-for-money-from br = do
record { msg = Msg (S (S Z)) (_ ∷ contribution ∷ []) } ← (selective-receive (select-contribution-from br))
where
record { msg = (Msg Z _) ; msg-ok = () }
record { msg = (Msg (S Z) _) ; msg-ok = () }
record { msg = (Msg (S (S (S _))) _) ; msg-ok = () }
return contribution
transaction-message : Book → Contribution → Contribution → String
transaction-message book c1 c2 with (transaction-status? book c1 c2)
... | Accepted _ = "Accepted purchase of " || Book.title book || " for $" || show (Book.price book)
... | TooLittleMoney p = "Received too little money for " || Book.title book || ". $" || show (Book.price book) || " - $" || show (Contribution.money c1) || " - $" || show (Contribution.money c2) || " = $" || show (Book.price book ∸ Contribution.money c1 ∸ Contribution.money c2)
... | TooMuchMoney p = "Received too much money for " || Book.title book || ". $" || show (Book.price book) || " - $" || show (Contribution.money c1) || " - $" || show (Contribution.money c2) || " = -$" || show ((Contribution.money c1 + Contribution.money c2) ∸ Book.price book)
after-book-quote : ∀ {i} →
Maybe Book →
∞ActorM i SellerInterface ⊤₁ [ GetQuoteReplyInterface ]ˡ (λ _ → [])
after-book-quote (just book) = do
lift AGREE ← wait-for-decision
where
lift QUIT → debug "seller sees that transaction was quit" (strengthen [])
lift contrib1 ← wait-for-money-from Buyer1
lift contrib2 ← wait-for-money-from Buyer2
debug (transaction-message book contrib1 contrib2) (strengthen [])
after-book-quote nothing = strengthen []
-- =========
-- BUYER 1
-- =========
buyer1 : ∀ {i} → ActorM i Buyer1Interface ⊤₁ [] (λ _ → [])
buyer1 = begin do
wait-for-seller
lift (just book) ← get-quote Z 0 book1
where
(lift nothing) → strengthen []
wait-for-buyer2
let my-contribution = ⌈ Book.price book /2⌉
send-contribution Z book my-contribution
lift AGREE ← wait-for-decision
where
lift QUIT → debug "buyer1 sees that transaction was quit" (strengthen [])
(transfer-money (S Z) (⊆-suc ⊆-refl) Buyer1 book my-contribution)
(strengthen [])
where
select-seller : MessageFilter Buyer1Interface
select-seller (Msg Z _) = true
select-seller (Msg (S _) _) = false
wait-for-seller : ∀ {i Γ} → ∞ActorM i Buyer1Interface ⊤₁ Γ (λ _ → Buyer1-to-Seller ∷ Γ)
wait-for-seller = do
record { msg = Msg Z _ } ← (selective-receive select-seller)
where
record { msg = (Msg (S _) _) ; msg-ok = () }
return _
select-buyer2 : MessageFilter Buyer1Interface
select-buyer2 (Msg (S Z) _) = true
select-buyer2 _ = false
wait-for-buyer2 : ∀ {i Γ} → ∞ActorM i Buyer1Interface ⊤₁ Γ (λ _ → Buyer1-to-Buyer2 ∷ Γ)
wait-for-buyer2 = do
record {msg = Msg (S Z) _ } ← selective-receive select-buyer2
where
record { msg = (Msg Z _) ; msg-ok = () }
record { msg = (Msg (S (S _)) _) ; msg-ok = () }
return _
get-quote : ∀ {i Γ} →
Γ ⊢ Buyer1-to-Seller →
UniqueTag →
BookTitle →
∞ActorM i Buyer1Interface (Lift (lsuc lzero) (Maybe Book)) Γ (λ _ → Γ)
get-quote p tag title = do
record { msg = Msg (S (S Z)) (_ ∷ book ∷ []) ; msg-ok = msg-ok } ← call p Z tag [ lift title ]ᵃ [ S (S Z) ]ᵐ Z
where
record { msg = (Msg Z (_ ∷ _)) ; msg-ok = () }
record { msg = (Msg (S Z) (_ ∷ _)) ; msg-ok = () }
record { msg = (Msg (S (S (S Z))) _) ; msg-ok = () }
record { msg = (Msg (S (S (S (S _)))) _) ; msg-ok = () }
return book
send-contribution : ∀ {i Γ} →
Γ ⊢ Buyer1-to-Buyer2 →
Book →
Money →
∞ActorM i Buyer1Interface ⊤₁ Γ (λ _ → Γ)
send-contribution p book money = p ![t: Z ] [ lift record { book = book ; money = money } ]ᵃ
select-decision : MessageFilter Buyer1Interface
select-decision (Msg (S (S (S Z))) _) = true
select-decision _ = false
wait-for-decision : ∀ {i Γ} →
∞ActorM i Buyer1Interface (Lift (lsuc lzero) AgreeChoice) Γ (λ _ → Γ)
wait-for-decision = do
record {msg = Msg (S (S (S Z))) (ac ∷ []) } ← (selective-receive select-decision)
where
record { msg = (Msg Z _) ; msg-ok = () }
record { msg = (Msg (S Z) _) ; msg-ok = () }
record { msg = (Msg (S (S Z)) _) ; msg-ok = () }
record { msg = (Msg (S (S (S (S _)))) _) ; msg-ok = () }
return ac
-- =========
-- BUYER 2
-- =========
buyer2 : ∀ {i} → ActorM i Buyer2Interface ⊤₁ [] (λ _ → [])
buyer2 = begin do
wait-for-seller
wait-for-buyer1
lift contribution ← wait-for-contribution
handle-contribution (S Z) Z contribution
strengthen []
where
select-seller : MessageFilter Buyer2Interface
select-seller (Msg Z _) = true
select-seller (Msg (S _) _) = false
wait-for-seller : ∀ {i Γ} → ∞ActorM i Buyer2Interface ⊤₁ Γ (λ _ → Buyer2-to-Seller ∷ Γ)
wait-for-seller = do
record { msg = Msg Z _ } ← (selective-receive select-seller)
where
record { msg = (Msg (S _) _) ; msg-ok = () }
return _
select-buyer1 : MessageFilter Buyer2Interface
select-buyer1 (Msg (S Z) _) = true
select-buyer1 _ = false
wait-for-buyer1 : ∀ {i Γ} → ∞ActorM i Buyer2Interface ⊤₁ Γ (λ _ → Buyer2-to-Buyer1 ∷ Γ)
wait-for-buyer1 = do
record {msg = Msg (S Z) _ } ← selective-receive select-buyer1
where
record { msg = (Msg Z _) ; msg-ok = () }
record { msg = (Msg (S (S _)) _) ; msg-ok = () }
return _
select-contribution : MessageFilter Buyer2Interface
select-contribution (Msg (S (S Z)) _) = true
select-contribution _ = false
wait-for-contribution : ∀ {i Γ} → ∞ActorM i Buyer2Interface (Lift (lsuc lzero) Contribution) Γ (λ _ → Γ)
wait-for-contribution = do
record { msg = Msg (S (S Z)) (cc ∷ []) } ← (selective-receive select-contribution)
where
record { msg = (Msg Z _) ; msg-ok = () }
record { msg = (Msg (S Z) _) ; msg-ok = () }
record { msg = (Msg (S (S (S _))) _) ; msg-ok = () }
return cc
contribution-is-fair : Money → Money → Bool
contribution-is-fair price money = ⌊ price ∸ money ≤? money ⌋
handle-contribution : ∀ {i Γ} →
Γ ⊢ Buyer2-to-Seller →
Γ ⊢ Buyer2-to-Buyer1 →
Contribution →
∞ActorM i Buyer2Interface ⊤₁ Γ (λ _ → Γ)
handle-contribution seller buyer1 record { book = book ; money = money } with (contribution-is-fair (Book.price book) money)
... | true = do
buyer1 ![t: Z ] [ lift AGREE ]ᵃ
seller ![t: Z ] [ lift AGREE ]ᵃ
transfer-money seller (⊆-suc ⊆-refl) Buyer2 book ((Book.price book) ∸ money)
... | false = do
buyer1 ![t: Z ] [ lift QUIT ]ᵃ
seller ![t: Z ] [ lift QUIT ]ᵃ
-- ============
-- SUPERVISOR
-- ============
bookstore-supervisor : ∀ {i} → ∞ActorM i [] ⊤₁ [] (λ _ → [])
bookstore-supervisor = do
spawn seller
spawn buyer1
spawn buyer2
Z ![t: Z ] [ [ (S (S Z)) ]>: ( S Z ∷ [ S (S Z) ]ᵐ)]ᵃ
Z ![t: S Z ] [ [ S Z ]>: [ S (S (S Z)) ]ᵐ ]ᵃ
(S Z) ![t: Z ] [ [ S (S Z) ]>: (Z ∷ [ S (S Z) ]ᵐ) ]ᵃ
(S Z) ![t: S Z ] [ [ Z ]>: [ S (S Z) ]ᵐ ]ᵃ
(strengthen [])
|
{
"alphanum_fraction": 0.5800369401,
"avg_line_length": 38.4437869822,
"ext": "agda",
"hexsha": "783a68d9e9fdc8e4d156fc3330db14f8af3bb9bd",
"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": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/singly-typed-actors",
"max_forks_repo_path": "src/Selective/Examples/Bookstore.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"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": "Zalastax/singly-typed-actors",
"max_issues_repo_path": "src/Selective/Examples/Bookstore.agda",
"max_line_length": 283,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/singly-typed-actors",
"max_stars_repo_path": "src/Selective/Examples/Bookstore.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-29T09:30:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:30:26.000Z",
"num_tokens": 3938,
"size": 12994
}
|
open import Mockingbird.Forest using (Forest)
-- Is There a Sage Bird?
module Mockingbird.Problems.Chapter10 {b ℓ} (forest : Forest {b} {ℓ}) where
open import Data.Product using (_,_; proj₁; proj₂; ∃-syntax)
open import Function using (_$_)
open import Mockingbird.Forest.Birds forest
open Forest forest
module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasLark ⦄ where
private
hasMockingbirdComposer : ∃[ A ] (∀ x y → A ∙ x ∙ y ≈ x ∙ (M ∙ y))
hasMockingbirdComposer = (L , isMockingbirdComposer)
where
isMockingbirdComposer = λ x y → begin
L ∙ x ∙ y ≈⟨ isLark x y ⟩
x ∙ (y ∙ y) ≈˘⟨ congˡ $ isMockingbird y ⟩
x ∙ (M ∙ y) ∎
hasSageBird : HasSageBird
hasSageBird = record
{ Θ = M ∘ L
; isSageBird = λ x → begin
x ∙ ((M ∘ L) ∙ x) ≈⟨ congˡ $ isComposition M L x ⟩
x ∙ (M ∙ (L ∙ x)) ≈⟨ congˡ $ isMockingbird (L ∙ x) ⟩
x ∙ ((L ∙ x) ∙ (L ∙ x)) ≈˘⟨ isLark x (L ∙ x) ⟩
(L ∙ x) ∙ (L ∙ x) ≈˘⟨ isMockingbird (L ∙ x) ⟩
M ∙ (L ∙ x) ≈˘⟨ isComposition M L x ⟩
(M ∘ L) ∙ x ∎
}
module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄
(hasMockingbirdComposer : ∃[ A ] (∀ x y → A ∙ x ∙ y ≈ x ∙ (M ∙ y))) where
private
A = proj₁ hasMockingbirdComposer
[Ax]y≈x[My] = proj₂ hasMockingbirdComposer
instance
hasLark : HasLark
hasLark = record
{ L = A
; isLark = λ x y → begin
(A ∙ x) ∙ y ≈⟨ [Ax]y≈x[My] x y ⟩
x ∙ (M ∙ y) ≈⟨ congˡ $ isMockingbird y ⟩
x ∙ (y ∙ y) ∎
}
hasSageBird′ : HasSageBird
hasSageBird′ = hasSageBird
|
{
"alphanum_fraction": 0.5148104265,
"avg_line_length": 31.2592592593,
"ext": "agda",
"hexsha": "03734d2c50fc6c13af1c1247930406c7e5df8440",
"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": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "splintah/combinatory-logic",
"max_forks_repo_path": "Mockingbird/Problems/Chapter10.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"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": "splintah/combinatory-logic",
"max_issues_repo_path": "Mockingbird/Problems/Chapter10.agda",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "splintah/combinatory-logic",
"max_stars_repo_path": "Mockingbird/Problems/Chapter10.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z",
"num_tokens": 711,
"size": 1688
}
|
_ : Set
|
{
"alphanum_fraction": 0.5,
"avg_line_length": 4,
"ext": "agda",
"hexsha": "3701a9bb7a89cd3e4ca49c4d9ad98287c612ca10",
"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/Issue4881a.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/Issue4881a.agda",
"max_line_length": 7,
"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/Issue4881a.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": 4,
"size": 8
}
|
module eq-reas-nouni {A : Set} where
open import eq
infix 1 begin_
infixr 2 _equiv[]_ _equiv[_]_
infix 3 _qed
begin_ : ∀ {x y : A}
→ x ≡ y
-----
→ x ≡ y
begin x≡y = x≡y
_equiv[]_ : ∀ (x : A) {y : A}
→ x ≡ y
-----
→ x ≡ y
x equiv[] x≡y = x≡y
_equiv[_]_ : ∀ (x : A) {y z : A}
→ x ≡ y
→ y ≡ z
-----
→ x ≡ z
x equiv[ x≡y ] y≡z = trans x≡y y≡z
_qed : ∀ (x : A)
-----
→ x ≡ x
x qed = refl
|
{
"alphanum_fraction": 0.3860759494,
"avg_line_length": 14.3636363636,
"ext": "agda",
"hexsha": "7e7e494e9fcb4500e4c680515a77ae647b11dac1",
"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": "80d9411b2869614cae488cd4a6272894146c9f3c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JimFixGroupResearch/imper-ial",
"max_forks_repo_path": "eq-reas-nouni.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "80d9411b2869614cae488cd4a6272894146c9f3c",
"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": "JimFixGroupResearch/imper-ial",
"max_issues_repo_path": "eq-reas-nouni.agda",
"max_line_length": 38,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "80d9411b2869614cae488cd4a6272894146c9f3c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JimFixGroupResearch/imper-ial",
"max_stars_repo_path": "eq-reas-nouni.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 233,
"size": 474
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
module Haskell.Modules.FunctorApplicativeMonad where
open import Haskell.Modules.Either
------------------------------------------------------------------------------
open import Data.List
open import Data.Maybe renaming (_>>=_ to _Maybe->>=_)
open import Function
open import Level renaming (suc to ℓ+1; zero to ℓ0; _⊔_ to _ℓ⊔_)
record Functor {ℓ₁ ℓ₂ : Level} (F : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where
infixl 4 _<$>_
field
_<$>_ : ∀ {A B : Set ℓ₁} → (A → B) → F A → F B
fmap = _<$>_
open Functor ⦃ ... ⦄ public
record Applicative {ℓ₁ ℓ₂ : Level} (F : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where
infixl 4 _<*>_
field
pure : ∀ {A : Set ℓ₁} → A → F A
_<*>_ : ∀ {A B : Set ℓ₁} → F (A → B) → F A → F B
open Applicative ⦃ ... ⦄ public
instance
ApplicativeFunctor : ∀ {ℓ₁ ℓ₂} {F : Set ℓ₁ → Set ℓ₂} ⦃ _ : Applicative F ⦄ → Functor F
Functor._<$>_ ApplicativeFunctor f xs = pure f <*> xs
record Monad {ℓ₁ ℓ₂ : Level} (M : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where
infixl 1 _>>=_ _>>_
field
return : ∀ {A : Set ℓ₁} → A → M A
_>>=_ : ∀ {A B : Set ℓ₁} → M A → (A → M B) → M B
_>>_ : ∀ {A B : Set ℓ₁} → M A → M B → M B
m₁ >> m₂ = m₁ >>= λ _ → m₂
open Monad ⦃ ... ⦄ public
instance
MonadApplicative : ∀ {ℓ₁ ℓ₂} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄ → Applicative M
Applicative.pure MonadApplicative = return
Applicative._<*>_ MonadApplicative fs xs = do
f ← fs
x ← xs
return (f x)
instance
Monad-Either : ∀ {ℓ}{C : Set ℓ} → Monad{ℓ}{ℓ} (Either C)
Monad.return (Monad-Either{ℓ}{C}) = Right
Monad._>>=_ (Monad-Either{ℓ}{C}) = either (const ∘ Left) _|>_
Monad-Maybe : ∀ {ℓ} → Monad {ℓ} {ℓ} Maybe
Monad.return (Monad-Maybe{ℓ}) = just
Monad._>>=_ (Monad-Maybe{ℓ}) = _Maybe->>=_
Monad-List : ∀ {ℓ} → Monad {ℓ}{ℓ} List
Monad.return Monad-List x = x ∷ []
Monad._>>=_ Monad-List x f = concat (Data.List.map f x)
|
{
"alphanum_fraction": 0.5753488372,
"avg_line_length": 34.126984127,
"ext": "agda",
"hexsha": "8c2321543f8395c205947d33cac2f687d8e281f9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/Haskell/Modules/FunctorApplicativeMonad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/Haskell/Modules/FunctorApplicativeMonad.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/Haskell/Modules/FunctorApplicativeMonad.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 861,
"size": 2150
}
|
module Issue279-4 where
module M (X : Set) where
data R : Set where
r : X → R
postulate
P Q : Set
open M P using (r)
shouldn't-check : M.R Q → Q
shouldn't-check (r q) = q
|
{
"alphanum_fraction": 0.6032608696,
"avg_line_length": 12.2666666667,
"ext": "agda",
"hexsha": "c8d4c8d7d9dff932aba8a4422a5f0668a2919348",
"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/Issue279-4.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/Issue279-4.agda",
"max_line_length": 27,
"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/Issue279-4.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": 68,
"size": 184
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bisimilarity for Colists
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Colist.Bisimilarity where
open import Level using (Level; _⊔_)
open import Size
open import Codata.Thunk
open import Codata.Colist
open import Data.List.Base using (List; []; _∷_)
open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_)
open import Data.List.NonEmpty as List⁺ using (List⁺; _∷_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as Eq using (_≡_)
private
variable
a b c p q r : Level
A : Set a
B : Set b
C : Set c
i : Size
data Bisim {A : Set a} {B : Set b} (R : REL A B r) (i : Size) :
REL (Colist A ∞) (Colist B ∞) (r ⊔ a ⊔ b) where
[] : Bisim R i [] []
_∷_ : ∀ {x y xs ys} → R x y → Thunk^R (Bisim R) i xs ys →
Bisim R i (x ∷ xs) (y ∷ ys)
module _ {R : Rel A r} where
reflexive : Reflexive R → Reflexive (Bisim R i)
reflexive refl^R {[]} = []
reflexive refl^R {r ∷ rs} = refl^R ∷ λ where .force → reflexive refl^R
module _ {P : REL A B p} {Q : REL B A q} where
symmetric : Sym P Q → Sym (Bisim P i) (Bisim Q i)
symmetric sym^PQ [] = []
symmetric sym^PQ (p ∷ ps) = sym^PQ p ∷ λ where .force → symmetric sym^PQ (ps .force)
module _ {P : REL A B p} {Q : REL B C q} {R : REL A C r} where
transitive : Trans P Q R → Trans (Bisim P i) (Bisim Q i) (Bisim R i)
transitive trans^PQR [] [] = []
transitive trans^PQR (p ∷ ps) (q ∷ qs) =
trans^PQR p q ∷ λ where .force → transitive trans^PQR (ps .force) (qs .force)
------------------------------------------------------------------------
-- Congruence rules
module _ {R : REL A B r} where
++⁺ : ∀ {as bs xs ys} → Pointwise R as bs →
Bisim R i xs ys → Bisim R i (fromList as ++ xs) (fromList bs ++ ys)
++⁺ [] rs = rs
++⁺ (r ∷ pw) rs = r ∷ λ where .force → ++⁺ pw rs
⁺++⁺ : ∀ {as bs xs ys} → Pointwise R (List⁺.toList as) (List⁺.toList bs) →
Thunk^R (Bisim R) i xs ys → Bisim R i (as ⁺++ xs) (bs ⁺++ ys)
⁺++⁺ (r ∷ pw) rs = r ∷ λ where .force → ++⁺ pw (rs .force)
------------------------------------------------------------------------
-- Pointwise Equality as a Bisimilarity
module _ {A : Set a} where
infix 1 _⊢_≈_
_⊢_≈_ : ∀ i → Colist A ∞ → Colist A ∞ → Set a
_⊢_≈_ = Bisim _≡_
refl : Reflexive (i ⊢_≈_)
refl = reflexive Eq.refl
fromEq : ∀ {as bs} → as ≡ bs → i ⊢ as ≈ bs
fromEq Eq.refl = refl
sym : Symmetric (i ⊢_≈_)
sym = symmetric Eq.sym
trans : Transitive (i ⊢_≈_)
trans = transitive Eq.trans
isEquivalence : {R : Rel A r} → IsEquivalence R → IsEquivalence (Bisim R i)
isEquivalence equiv^R = record
{ refl = reflexive equiv^R.refl
; sym = symmetric equiv^R.sym
; trans = transitive equiv^R.trans
} where module equiv^R = IsEquivalence equiv^R
setoid : Setoid a r → Size → Setoid a (a ⊔ r)
setoid S i = record
{ isEquivalence = isEquivalence {i = i} (Setoid.isEquivalence S)
}
module ≈-Reasoning {a} {A : Set a} {i} where
open import Relation.Binary.Reasoning.Setoid (setoid (Eq.setoid A) i) public
|
{
"alphanum_fraction": 0.5472682627,
"avg_line_length": 31.3269230769,
"ext": "agda",
"hexsha": "543062a96a9ccb50f043f0fd1e1cb732a0c79b93",
"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/Codata/Colist/Bisimilarity.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/Codata/Colist/Bisimilarity.agda",
"max_line_length": 85,
"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/Codata/Colist/Bisimilarity.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": 1124,
"size": 3258
}
|
module LC.Example where
open import LC.Base
open import LC.Subst
open import LC.Reduction
open import LC.Reasoning
test-1 : ((ƛ var 0) ∙ var 0) β→* ((var 0) [ var 0 ])
test-1 =
begin
(ƛ var 0) ∙ var 0
→⟨ β-ƛ-∙ ⟩
(var 0) [ var 0 ]
∎
test-0 : ƛ (ƛ var 0 ∙ var 1) ∙ (ƛ var 0 ∙ var 1) β→* ƛ var 0 ∙ var 0
test-0 =
begin
ƛ (ƛ var 0 ∙ var 1) ∙ (ƛ var 0 ∙ var 1)
→⟨ β-ƛ β-ƛ-∙ ⟩
ƛ (var 0 ∙ var 1) [ ƛ var 0 ∙ var 1 ]
→⟨⟩
ƛ (var 0 ∙ var 1) [ ƛ var 0 ∙ var 1 / 0 ]
→⟨⟩
ƛ (var 0) [ ƛ var 0 ∙ var 1 / 0 ] ∙ (var 1) [ ƛ var 0 ∙ var 1 / 0 ]
→⟨⟩
ƛ lift 0 0 (ƛ var 0 ∙ var 1) ∙ var 0
→⟨⟩
ƛ (ƛ lift 0 0 (var 0 ∙ var 1)) ∙ var 0
→⟨⟩
ƛ (ƛ lift 0 0 (var 0) ∙ lift 0 0 (var 1)) ∙ var 0
→⟨⟩
ƛ ((ƛ var 0 ∙ var 1) ∙ var 0)
→⟨ β-ƛ β-ƛ-∙ ⟩
ƛ (var 0 ∙ var 1) [ var 0 / 0 ]
→⟨⟩
ƛ var 0 ∙ var 0
∎
Z : Term
Z = ƛ ƛ var 0
SZ : Term
SZ = ƛ ƛ var 1 ∙ var 0
PLUS : Term
PLUS = ƛ ƛ ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)
test-2 : PLUS ∙ Z ∙ SZ β→* SZ
test-2 =
begin
PLUS ∙ Z ∙ SZ
→⟨ β-∙-l β-ƛ-∙ ⟩
(ƛ ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 0 ] ∙ SZ
→⟨⟩
(ƛ ((ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 1 ])) ∙ SZ
→⟨⟩
(ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 2 ])) ∙ SZ
→⟨⟩
(ƛ (ƛ (ƛ ((var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 3 ])))) ∙ SZ
→⟨⟩
(ƛ (ƛ (ƛ (var 3) [ ƛ ƛ var 0 / 3 ] ∙ (var 1) [ ƛ ƛ var 0 / 3 ] ∙ (var 2 ∙ var 1 ∙ var 0) [ ƛ ƛ var 0 / 3 ]))) ∙ SZ
→⟨⟩
(ƛ (ƛ (ƛ (lift 0 3 (ƛ (ƛ var 0))) ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ
→⟨⟩
(ƛ (ƛ (ƛ (ƛ (ƛ (var 0))) ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ
→⟨ β-∙-l (β-ƛ (β-ƛ (β-ƛ (β-∙-l β-ƛ-∙)))) ⟩
(ƛ (ƛ (ƛ (ƛ var 0) [ var 1 / 0 ] ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ
→⟨⟩
(ƛ (ƛ (ƛ (ƛ (var 0) [ var 1 / 1 ]) ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ
→⟨⟩
(ƛ (ƛ (ƛ (ƛ var 0) ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ
→⟨ β-∙-l (β-ƛ (β-ƛ (β-ƛ β-ƛ-∙))) ⟩
(ƛ (ƛ (ƛ (var 0) [ var 2 ∙ var 1 ∙ var 0 / 0 ]))) ∙ SZ
→⟨⟩
(ƛ (ƛ (ƛ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ
→⟨ β-ƛ-∙ ⟩
(ƛ (ƛ (var 2 ∙ var 1 ∙ var 0))) [ SZ / 0 ]
→⟨⟩
ƛ (ƛ (var 2 ∙ var 1 ∙ var 0) [ SZ / 2 ])
→⟨⟩
ƛ (ƛ lift 0 2 SZ ∙ var 1 ∙ var 0)
→⟨⟩
ƛ (ƛ (ƛ ƛ var 1 ∙ var 0) ∙ var 1 ∙ var 0)
→⟨ β-ƛ (β-ƛ (β-∙-l β-ƛ-∙)) ⟩
ƛ (ƛ (ƛ var 1 ∙ var 0) [ var 1 / 0 ] ∙ var 0)
→⟨⟩
ƛ (ƛ (ƛ ((var 1 ∙ var 0) [ var 1 / 1 ])) ∙ var 0)
→⟨⟩
ƛ (ƛ (ƛ ((var 1) [ var 1 / 1 ] ∙ (var 0) [ var 1 / 1 ])) ∙ var 0)
→⟨⟩
ƛ (ƛ (ƛ (lift 0 1 (var 1) ∙ var 0)) ∙ var 0)
→⟨⟩
ƛ (ƛ (ƛ (var 2 ∙ var 0)) ∙ var 0)
→⟨ β-ƛ (β-ƛ β-ƛ-∙) ⟩
ƛ (ƛ (var 2 ∙ var 0) [ var 0 / 0 ])
→⟨⟩
ƛ (ƛ (var 2) [ var 0 / 0 ] ∙ var 0)
→⟨⟩
ƛ (ƛ var 1 ∙ var 0)
∎
|
{
"alphanum_fraction": 0.379707113,
"avg_line_length": 28.1176470588,
"ext": "agda",
"hexsha": "74ebfbf7d64a059137fc9bc743320303ba8bc907",
"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": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/bidirectional",
"max_forks_repo_path": "LC/Example.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"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/bidirectional",
"max_issues_repo_path": "LC/Example.agda",
"max_line_length": 118,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/bidirectional",
"max_stars_repo_path": "LC/Example.agda",
"max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z",
"num_tokens": 1876,
"size": 2868
}
|
module Data.Num.Digit where
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Properties.Simple
open import Data.Nat.Properties.Extra
open import Data.Fin as Fin
using (Fin; fromℕ≤; inject≤; toℕ; zero; suc)
open import Data.Fin.Properties as FinProps using (bounded; toℕ-fromℕ≤)
open import Function
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary
open ≡-Reasoning
open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)
open DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)
--------------------------------------------------------------------------------
-- Digits
--------------------------------------------------------------------------------
Digit : ℕ → Set
Digit = Fin
-- converting to and from ℕ
Digit-toℕ : ∀ {d} → Digit d → ℕ → ℕ
Digit-toℕ x o = toℕ x + o
Digit-fromℕ : ∀ {d} → (n o : ℕ) → d + o ≥ n → Digit (suc d)
Digit-fromℕ {d} n o upper-bound with n ∸ o ≤? d
Digit-fromℕ {d} n o upper-bound | yes p = fromℕ≤ (s≤s p)
Digit-fromℕ {d} n o upper-bound | no ¬p = contradiction p ¬p
where p : n ∸ o ≤ d
p = start
n ∸ o
≤⟨ ∸n-mono o upper-bound ⟩
(d + o) ∸ o
≈⟨ m+n∸n≡m d o ⟩
d
□
Digit-fromℕ-toℕ : ∀ {d o}
→ (n : ℕ)
→ (lower-bound : o ≤ n)
→ (upper-bound : d + o ≥ n)
→ Digit-toℕ (Digit-fromℕ {d} n o upper-bound) o ≡ n
Digit-fromℕ-toℕ {d} {o} n lb ub with n ∸ o ≤? d
Digit-fromℕ-toℕ {d} {o} n lb ub | yes q =
begin
toℕ (fromℕ≤ (s≤s q)) + o
≡⟨ cong (λ x → x + o) (toℕ-fromℕ≤ (s≤s q)) ⟩
n ∸ o + o
≡⟨ m∸n+n≡m lb ⟩
n
∎
Digit-fromℕ-toℕ {d} {o} n lb ub | no ¬q = contradiction q ¬q
where q : n ∸ o ≤ d
q = +n-mono-inverse o $
start
n ∸ o + o
≈⟨ m∸n+n≡m lb ⟩
n
≤⟨ ub ⟩
d + o
□
--------------------------------------------------------------------------------
-- Properties of all Digits
--------------------------------------------------------------------------------
Digit-upper-bound : ∀ {d} → (o : ℕ) → (x : Digit d) → Digit-toℕ x o < d + o
Digit-upper-bound {d} o x = +n-mono o (bounded x)
Digit-lower-bound : ∀ {d} → (o : ℕ) → (x : Digit d) → Digit-toℕ x o ≥ o
Digit-lower-bound {d} o x = n≤m+n (toℕ x) o
--------------------------------------------------------------------------------
-- Special Digits
--------------------------------------------------------------------------------
-- A digit at its greatest
Greatest : ∀ {d} (x : Digit d) → Set
Greatest {d} x = suc (toℕ x) ≡ d
Greatest? : ∀ {d} (x : Digit d) → Dec (Greatest x)
Greatest? {d} x = suc (toℕ x) ≟ d
greatest-digit : ∀ d → Digit (suc d)
greatest-digit d = Fin.fromℕ d
greatest-digit-toℕ : ∀ {d o}
→ (x : Digit (suc d))
→ Greatest x
→ Digit-toℕ x o ≡ d + o
greatest-digit-toℕ {d} {o} x greatest = cancel-suc $
begin
suc (Digit-toℕ x o)
≡⟨ cong (λ w → w + o) greatest ⟩
suc (d + o)
∎
greatest-of-all : ∀ {d} (o : ℕ) → (x y : Digit d) → Greatest x → Digit-toℕ x o ≥ Digit-toℕ y o
greatest-of-all o zero zero refl = ≤-refl
greatest-of-all o zero (suc ()) refl
greatest-of-all o (suc x) zero greatest = +n-mono o {zero} {suc (toℕ x)} z≤n
greatest-of-all o (suc x) (suc y) greatest = s≤s (greatest-of-all o x y (cancel-suc greatest))
greatest-digit-is-the-Greatest : ∀ d → Greatest (greatest-digit d)
greatest-digit-is-the-Greatest d = cong suc (FinProps.to-from d)
-- carry, 1 `max` o, in case that the least digit "o" is 0
carry : ℕ → ℕ
carry o = 1 ⊔ o
carry-lower-bound : ∀ {o} → carry o ≥ o
carry-lower-bound {o} = m≤n⊔m o 1
carry-upper-bound : ∀ {d o} → 2 ≤ suc d + o → carry o ≤ d + o
carry-upper-bound {d} {zero} proper = ≤-pred proper
carry-upper-bound {d} {suc o} proper = n≤m+n d (suc o)
carry-digit : ∀ d o → 2 ≤ suc d + o → Digit (suc d)
carry-digit d o proper = Digit-fromℕ (carry o) o (carry-upper-bound {d} proper)
carry-digit-toℕ : ∀ d o
→ (proper : 2 ≤ suc (d + o))
→ Digit-toℕ (carry-digit d o proper) o ≡ carry o
carry-digit-toℕ d o proper = Digit-fromℕ-toℕ (carry o) (m≤n⊔m o 1) (carry-upper-bound {d} proper)
-- LCD-upper-bound-prim d zero proper = ≤-pred proper
-- LCD-upper-bound-prim d (suc o) proper = n≤m+n (suc o) d
--
-- LCD : ∀ d o → 2 ≤ suc d + o → Digit (suc d)
-- LCD d o proper = Digit-fromℕ (1 ⊔ o) o (LCD-upper-bound-prim d o proper)
--
-- LCD-toℕ : ∀ d o
-- → (proper : 2 ≤ suc (d + o))
-- → Digit-toℕ (LCD d o proper) o ≡ 1 ⊔ o
-- LCD-toℕ d o proper = Digit-fromℕ-toℕ (1 ⊔ o) (m≤n⊔m o 1) (LCD-upper-bound-prim d o proper)
--
-- LCD-upper-bound : ∀ {d o}
-- → (proper : 2 ≤ suc (d + o))
-- → Digit-toℕ (LCD d o proper) o ≤ d + o
-- LCD-upper-bound {d} {o} proper =
-- start
-- Digit-toℕ (LCD d o proper) o
-- ≈⟨ LCD-toℕ d o proper ⟩
-- 1 ⊔ o
-- ≤⟨ LCD-upper-bound-prim d o proper ⟩
-- d + o
-- □
--------------------------------------------------------------------------------
-- Functions on Digits
--------------------------------------------------------------------------------
-- +1
digit+1 : ∀ {d} → (x : Digit d) → (¬greatest : ¬ (Greatest x)) → Fin d
digit+1 x ¬greatest = fromℕ≤ {suc (toℕ x)} (≤∧≢⇒< (bounded x) ¬greatest)
digit+1-toℕ : ∀ {d o}
→ (x : Digit d)
→ (¬greatest : ¬ (Greatest x))
→ Digit-toℕ (digit+1 x ¬greatest) o ≡ suc (Digit-toℕ x o)
digit+1-toℕ {d} {o} x ¬greatest =
begin
Digit-toℕ (digit+1 x ¬greatest) o
≡⟨ cong (λ w → w + o) (toℕ-fromℕ≤ (≤∧≢⇒< (bounded x) ¬greatest)) ⟩
suc (Digit-toℕ x o)
∎
digit+1-n-lemma : ∀ {d}
→ (x : Digit d)
→ Greatest x
→ (n : ℕ)
→ n > 0
→ suc (toℕ x) ∸ n < d
digit+1-n-lemma {zero } () greatest n n>0
digit+1-n-lemma {suc d} x greatest n n>0 = s≤s $ start
suc (toℕ x) ∸ n
≤⟨ ∸n-mono n (bounded x) ⟩
suc d ∸ n
≤⟨ n∸-mono (suc d) n>0 ⟩
suc d ∸ 1
≤⟨ ≤-refl ⟩
d
□
-- +1 and then -n, useful for handling carrying on increment
digit+1-n : ∀ {d}
→ (x : Digit d)
→ Greatest x
→ (n : ℕ)
→ n > 0
→ Digit d
digit+1-n x greatest n n>0 = fromℕ≤ (digit+1-n-lemma x greatest n n>0)
digit+1-n-toℕ : ∀ {d o}
→ (x : Digit d)
→ (greatest : Greatest x)
→ (n : ℕ)
→ (n>0 : n > 0)
→ n ≤ d
→ Digit-toℕ (digit+1-n x greatest n n>0) o ≡ suc (Digit-toℕ x o) ∸ n
digit+1-n-toℕ {zero} {o} () greatest n n>0 n≤d
digit+1-n-toℕ {suc d} {o} x greatest n n>0 n≤d =
begin
toℕ (digit+1-n x greatest n n>0) + o
≡⟨ cong (λ w → w + o) (toℕ-fromℕ≤ (digit+1-n-lemma x greatest n n>0)) ⟩
suc (toℕ x) ∸ n + o
≡⟨ +-comm (suc (toℕ x) ∸ n) o ⟩
o + (suc (toℕ x) ∸ n)
≡⟨ sym (+-∸-assoc o {suc (toℕ x)} {n} $
start
n
≤⟨ n≤d ⟩
suc d
≈⟨ sym greatest ⟩
suc (toℕ x)
□)
⟩
(o + suc (toℕ x)) ∸ n
≡⟨ cong (λ w → w ∸ n) (+-comm o (suc (toℕ x))) ⟩
suc (toℕ x) + o ∸ n
∎
|
{
"alphanum_fraction": 0.4750277469,
"avg_line_length": 31.0689655172,
"ext": "agda",
"hexsha": "d2f4b2fdbc50e7486b9d54bfc4e2322b6f800bed",
"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/Digit.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/Digit.agda",
"max_line_length": 97,
"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/Digit.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": 2699,
"size": 7208
}
|
module IID-Proof-Setup where
open import LF
open import Identity
open import IID
open import IIDr
open import DefinitionalEquality
OPg : Set -> Set1
OPg I = OP I I
-- Encoding indexed inductive types as non-indexed types.
ε : {I : Set}(γ : OPg I) -> OPr I
ε (ι i) j = σ (i == j) (\_ -> ι ★)
ε (σ A γ) j = σ A (\a -> ε (γ a) j)
ε (δ H i γ) j = δ H i (ε γ j)
-- Adds a reflexivity proof.
g→rArgs : {I : Set}(γ : OPg I)(U : I -> Set)
(a : Args γ U) ->
rArgs (ε γ) U (index γ U a)
g→rArgs (ι e) U arg = (refl , ★)
g→rArgs (σ A γ) U arg = (π₀ arg , g→rArgs (γ (π₀ arg)) U (π₁ arg))
g→rArgs (δ H i γ) U arg = (π₀ arg , g→rArgs γ U (π₁ arg))
-- Strips the equality proof.
r→gArgs : {I : Set}(γ : OPg I)(U : I -> Set)
(i : I)(a : rArgs (ε γ) U i) ->
Args γ U
r→gArgs (ι i) U j _ = ★
r→gArgs (σ A γ) U j arg = (π₀ arg , r→gArgs (γ (π₀ arg)) U j (π₁ arg))
r→gArgs (δ H i γ) U j arg = (π₀ arg , r→gArgs γ U j (π₁ arg))
-- Converting an rArgs to a gArgs and back is (provably, not definitionally)
-- the identity.
r←→gArgs-subst :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> rArgs (ε γ) U i -> Set)
(i : I)(a : rArgs (ε γ) U i) ->
(C (index γ U (r→gArgs γ U i a))
(g→rArgs γ U (r→gArgs γ U i a))
) -> C i a
r←→gArgs-subst {I} (ι i) U C j arg m =
elim== i (\k q -> C k (q , ★)) m j (π₀ arg)
r←→gArgs-subst (σ A γ) U C j arg m =
r←→gArgs-subst (γ (π₀ arg)) U (\i c -> C i (π₀ arg , c)) j (π₁ arg) m
r←→gArgs-subst (δ H i γ) U C j arg m =
r←→gArgs-subst γ U (\i c -> C i (π₀ arg , c)) j (π₁ arg) m
-- r←→gArgs-subst eliminates the identity proof stored in the rArgs. If this proof is
-- by reflexivity r←→gArgs-subst is a definitional identity. This is the case
-- when a = g→rArgs a'
r←→gArgs-subst-identity :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> rArgs (ε γ) U i -> Set)
(a' : Args γ U) ->
let a = g→rArgs γ U a'
i = index γ U a' in
(h : C (index γ U (r→gArgs γ U i a))
(g→rArgs γ U (r→gArgs γ U i a))
) -> r←→gArgs-subst γ U C i a h ≡ h
r←→gArgs-subst-identity (ι i) U C _ h = refl-≡
r←→gArgs-subst-identity (σ A γ) U C arg h = r←→gArgs-subst-identity (γ (π₀ arg)) U C' (π₁ arg) h
where C' = \i c -> C i (π₀ arg , c)
r←→gArgs-subst-identity (δ H i γ) U C arg h = r←→gArgs-subst-identity γ U C' (π₁ arg) h
where C' = \i c -> C i (π₀ arg , c)
-- Going the other way around is definitionally the identity.
g←→rArgs-identity :
{I : Set}(γ : OPg I)(U : I -> Set)
(a : Args γ U) ->
r→gArgs γ U (index γ U a) (g→rArgs γ U a) ≡ a
g←→rArgs-identity (ι i) U _ = refl-≡
g←→rArgs-identity (σ A γ) U arg = cong-≡ (\ ∙ -> (π₀ arg , ∙)) (g←→rArgs-identity (γ (π₀ arg)) U (π₁ arg))
g←→rArgs-identity (δ H i γ) U arg = cong-≡ (\ ∙ -> (π₀ arg , ∙)) (g←→rArgs-identity γ U (π₁ arg))
-- Corresponding conversion functions for assumptions to inductive occurrences.
-- Basically an identity function.
g→rIndArg : {I : Set}(γ : OPg I)(U : I -> Set)
(i : I)(a : rArgs (ε γ) U i) ->
IndArg γ U (r→gArgs γ U i a) -> IndArg (ε γ i) U a
g→rIndArg (ι j) U i _ ()
g→rIndArg (σ A γ) U i arg v = g→rIndArg (γ (π₀ arg)) U i (π₁ arg) v
g→rIndArg (δ A j γ) U i arg (inl a) = inl a
g→rIndArg (δ A j γ) U i arg (inr v) = inr (g→rIndArg γ U i (π₁ arg) v)
-- Basically we can substitute general inductive occurences for the encoded
-- restricted inductive occurrences.
g→rIndArg-subst :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> U i -> Set)
(i : I)(a : rArgs (ε γ) U i)
(v : IndArg γ U (r→gArgs γ U i a)) ->
C (IndIndex (ε γ i) U a (g→rIndArg γ U i a v))
(Ind (ε γ i) U a (g→rIndArg γ U i a v)) ->
C (IndIndex γ U (r→gArgs γ U i a) v)
(Ind γ U (r→gArgs γ U i a) v)
g→rIndArg-subst (ι j) U C i _ () h
g→rIndArg-subst (σ A γ) U C i arg v h = g→rIndArg-subst (γ (π₀ arg)) U C i (π₁ arg) v h
g→rIndArg-subst (δ A j γ) U C i arg (inl a) h = h
g→rIndArg-subst (δ A j γ) U C i arg (inr v) h = g→rIndArg-subst γ U C i (π₁ arg) v h
-- g→rIndArg-subst is purely book-keeping. On the object level it's definitional identity.
g→rIndArg-subst-identity :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> U i -> Set)
(i : I)(a : rArgs (ε γ) U i)
(v : IndArg γ U (r→gArgs γ U i a))
(h : C (IndIndex (ε γ i) U a (g→rIndArg γ U i a v))
(Ind (ε γ i) U a (g→rIndArg γ U i a v))
) -> g→rIndArg-subst γ U C i a v h ≡ h
g→rIndArg-subst-identity (ι j) U C i _ () h
g→rIndArg-subst-identity (σ A γ) U C i arg v h =
g→rIndArg-subst-identity (γ (π₀ arg)) U C i (π₁ arg) v h
g→rIndArg-subst-identity (δ A j γ) U C i arg (inl a) h = refl-≡
g→rIndArg-subst-identity (δ A j γ) U C i arg (inr v) h =
g→rIndArg-subst-identity γ U C i (π₁ arg) v h
-- And finally conversion of induction hypotheses. This goes the other direction.
r→gIndHyp :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> U i -> Set)
(i : I)(a : rArgs (ε γ) U i) ->
IndHyp (ε γ i) U C a -> IndHyp γ U C (r→gArgs γ U i a)
r→gIndHyp γ U C i a h v = g→rIndArg-subst γ U C i a v (h (g→rIndArg γ U i a v))
|
{
"alphanum_fraction": 0.5488308116,
"avg_line_length": 38.8473282443,
"ext": "agda",
"hexsha": "ef388f8bda7a6f04f9c8f552973e1a1e7783954a",
"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": "examples/outdated-and-incorrect/iird/IID-Proof-Setup.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": "examples/outdated-and-incorrect/iird/IID-Proof-Setup.agda",
"max_line_length": 108,
"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": "examples/outdated-and-incorrect/iird/IID-Proof-Setup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2208,
"size": 5089
}
|
module Data.Boolean.Stmt where
import Lvl
open import Data.Boolean
import Data.Boolean.Operators
open Data.Boolean.Operators.Programming
open import Functional
open import Logic.Propositional
open import Type
IsTrue : Bool → Type
IsTrue = if_then ⊤ else ⊥
IsFalse : Bool → Type
IsFalse = IsTrue ∘ !
|
{
"alphanum_fraction": 0.7460815047,
"avg_line_length": 19.9375,
"ext": "agda",
"hexsha": "90f6395973875169a0591c0297e14740cae6db52",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/Boolean/Stmt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/Boolean/Stmt.agda",
"max_line_length": 46,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/Boolean/Stmt.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": 81,
"size": 319
}
|
{-# OPTIONS --without-K #-}
module PathStructure.Coproduct {a b} {A : Set a} {B : Set b} where
open import Equivalence
open import PathOperations
open import Types
-- We need to use Lift here, because Agda doesn't have
-- cumulative universes.
F : A ⊎ B → A ⊎ B → Set (a ⊔ b)
F = case (λ _ → A ⊎ B → Set _)
(λ a₁ → case (λ _ → Set _)
(λ a₂ → Lift b (a₁ ≡ a₂))
(λ _ → Lift _ ⊥))
(λ b₁ → case (λ _ → Set _)
(λ _ → Lift _ ⊥)
(λ b₂ → Lift a (b₁ ≡ b₂)))
F-lemma : (x : A ⊎ B) → F x x
F-lemma = case (λ x → F x x) (λ _ → lift refl) (λ _ → lift refl)
split-path : {x y : A ⊎ B} → x ≡ y → F x y
split-path {x = x} p = tr (F x) p (F-lemma x)
merge-path : {x y : A ⊎ B} → F x y → x ≡ y
merge-path = case (λ x → ∀ y → F x y → x ≡ y)
(λ a → case (λ y → F (inl a) y → inl a ≡ y)
(λ _ → ap inl ∘ lower)
(λ _ → 0-elim ∘ lower))
(λ b → case (λ y → F (inr b) y → inr b ≡ y)
(λ _ → 0-elim ∘ lower)
(λ _ → ap inr ∘ lower))
_ _
split-merge-eq : {x y : A ⊎ B} → (x ≡ y) ≃ F x y
split-merge-eq {x = x} {y = y}
= split-path
, (merge-path , λ f → case
(λ x → ∀ y (f : F x y) → split-path (merge-path {x} {y} f) ≡ f)
(λ a → case
(λ y → (f : F (inl a) y) →
split-path (merge-path {inl a} {y} f) ≡ f)
(λ a′ p → J
(λ a a′ p →
split-path (merge-path {inl a} {inl a′} (lift p)) ≡ lift p)
(λ _ → refl) _ _ (lower p))
(λ _ → 0-elim ∘ lower))
(λ b → case
(λ y → (f : F (inr b) y) →
split-path (merge-path {inr b} {y} f) ≡ f)
(λ _ → 0-elim ∘ lower)
(λ b′ p → J
(λ b b′ p →
split-path (merge-path {inr b} {inr b′} (lift p)) ≡ lift p)
(λ _ → refl) _ _ (lower p)))
x y f)
, (merge-path , J (λ _ _ p → merge-path (split-path p) ≡ p)
(case
(λ x → merge-path {x} {x} (split-path {x} {x} refl) ≡ refl)
(λ _ → refl)
(λ _ → refl))
_ _)
|
{
"alphanum_fraction": 0.4533264569,
"avg_line_length": 30.7777777778,
"ext": "agda",
"hexsha": "98cf757193b5f86df3ebd2355b3d622fe1455360",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/PathStructure/Coproduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/PathStructure/Coproduct.agda",
"max_line_length": 71,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/PathStructure/Coproduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 810,
"size": 1939
}
|
module Lvl.Decidable where
open import Data.Boolean.Stmt
open import Logic.Propositional
open import Logic.Propositional.Theorems
import Lvl
open import Type.Properties.Decidable
open import Type.Properties.Decidable.Proofs
open import Type
private variable ℓ ℓ₁ : Lvl.Level
-- Changing classical propositions' universe levels by using their boolean representation.
module _ (P : Type{ℓ}) ⦃ dec : Decidable(0)(P) ⦄ where
Convert : Type{ℓ₁}
Convert = Lvl.Up(IsTrue(decide(0)(P)))
-- LvlConvert is satisfied whenever its proposition is.
Convert-correctness : P ↔ Convert{ℓ₁}
Convert-correctness = [↔]-transitivity decider-true ([↔]-intro Lvl.Up.obj Lvl.up)
|
{
"alphanum_fraction": 0.7596439169,
"avg_line_length": 32.0952380952,
"ext": "agda",
"hexsha": "4daf49118700d03a4a444d9972030d1970d95eac",
"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": "Lvl/Decidable.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": "Lvl/Decidable.agda",
"max_line_length": 90,
"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": "Lvl/Decidable.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": 187,
"size": 674
}
|
module Formalization.LambdaCalculus.Semantics where
open import Data
open import Formalization.LambdaCalculus
open import Syntax.Number
open import Type
-- A value in the language of lambda calculus is a irreducible term by a standard reduction definition.
-- It can also be defined as terms that are lambda abstractions because an application of a lambda is supposed to be β-reducible.
data Value : Expression → Type{0} where
instance abs : ∀{body : Term(1)} → Value(Abstract body)
|
{
"alphanum_fraction": 0.7926078029,
"avg_line_length": 40.5833333333,
"ext": "agda",
"hexsha": "ff97ab7be53bff0b1ec2aee22008bdffa8b422fe",
"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": "Formalization/LambdaCalculus/Semantics.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": "Formalization/LambdaCalculus/Semantics.agda",
"max_line_length": 129,
"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": "Formalization/LambdaCalculus/Semantics.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": 109,
"size": 487
}
|
module Cutting where
open import Basics
open import Ix
open import All
record _|>_ (I O : Set) : Set1 where
field
Cuts : O -> Set
inners : {o : O} -> Cuts o -> List I
NatCut : Nat |> Nat
NatCut = record
{ Cuts = \ mn -> Sg Nat \ m -> Sg Nat \ n -> (m +N n) == mn
; inners = \ { (m , n , _) -> m ,- n ,- [] }
}
record Cutting {I O}(C : I |> O)(P : I -> Set)(o : O) : Set where
constructor _8><_
open _|>_ C
field
cut : Cuts o
pieces : All P (inners cut)
infixr 3 _8><_
open Cutting public
|
{
"alphanum_fraction": 0.5319548872,
"avg_line_length": 19.7037037037,
"ext": "agda",
"hexsha": "4f9469dfaaf6408751d627bd1ea5d230da9f84ac",
"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": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pigworker/InteriorDesign",
"max_forks_repo_path": "Cutting.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"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": "pigworker/InteriorDesign",
"max_issues_repo_path": "Cutting.agda",
"max_line_length": 65,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pigworker/InteriorDesign",
"max_stars_repo_path": "Cutting.agda",
"max_stars_repo_stars_event_max_datetime": "2018-07-31T02:00:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-18T15:25:39.000Z",
"num_tokens": 197,
"size": 532
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- You can transform functions out of discrete
-- categories into functors.
module Categories.Functor.Construction.FromDiscrete {o ℓ e} (𝒞 : Category o ℓ e) where
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
open import Categories.Category.Discrete
open import Categories.Functor using (Functor)
private
module 𝒞 = Category 𝒞
open Category 𝒞
open 𝒞.HomReasoning
FromDiscrete : ∀ {o} {A : Set o} → (A → Obj) → Functor (Discrete A) 𝒞
FromDiscrete {o} {A = A} select = record
{ F₀ = select
; F₁ = λ { ≡.refl → id }
; identity = refl
; homomorphism = λ { {_} {_} {_} {≡.refl} {≡.refl} → sym identity² }
; F-resp-≈ = λ { ≡.refl → refl }
}
|
{
"alphanum_fraction": 0.6729475101,
"avg_line_length": 27.5185185185,
"ext": "agda",
"hexsha": "a2a2b52858db07962ee89519c6fbf436a44d8a38",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Construction/FromDiscrete.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Construction/FromDiscrete.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Construction/FromDiscrete.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 248,
"size": 743
}
|
module Dimension.PartialWeakening.Soundness where
open import Exception -- using (Except; left; right; _<$>_; _>>=_)
open import Injective
-- Semantics given by application to a name in Fin n
apply : ∀ {n m} (f : PWeak n m) (i : Fin n) → Except E (Fin m)
apply [] ()
apply (e ∷ f) zero = left e
apply (e ∷ f) (suc i) = apply f i
apply (lift f) zero = right zero
apply (lift f) (suc i) = suc <$> apply f i
apply (weak f) i = suc <$> apply f i
-- Proof of injectivity wrt. semantics
injective : ∀ {n m} (f : PWeak n m) (i j : Fin n) →
let k = apply f i in
let l = apply f j in
IsDefined k → k ≡ l → i ≡ j
injective [] ()
injective (e ∷ f) zero j () p
injective (e ∷ f) (suc i) zero fi p with apply f i
injective (e ∷ f) (suc i) zero () p | left _
injective (e ∷ f) (suc i) zero fi () | right a
injective (e ∷ f) (suc i) (suc j) fi p = cong suc (injective f i j fi p)
injective (lift f) zero zero fi p = refl
injective (lift f) zero (suc j) fi p with apply f j
injective (lift f) zero (suc j) fi p | left _ = ⊥-elim (right≢left p)
injective (lift f) zero (suc j) fi p | right l = ⊥-elim (zero≢suc (right-injective _ _ p))
injective (lift f) (suc i) zero fi p with apply f i
injective (lift f) (suc i) zero fi p | left e = ⊥-elim (left≢right p)
injective (lift f) (suc i) zero fi p | right k = ⊥-elim (suc≢zero (right-injective _ _ p))
injective (lift f) (suc i) (suc j) fi p = cong suc (injective f i j (map-def-inv _ fi) (map-injective suc-injective _ _ p))
injective (weak f) i j fi p = injective f i j (map-def-inv _ fi) (map-injective suc-injective _ _ p)
-- Soundness of id
apply-id : ∀ n (i : Fin n) → apply id i ≡ return i
apply-id 0 ()
apply-id (suc n) zero = refl
apply-id (suc n) (suc i) with (apply id i) | (apply-id n i)
apply-id (suc n) (suc i) | .(right i) | refl = refl
-- Lemma: one inductive step
lift-lift-suc : ∀ {n m l} (f : PWeak n m) {g : PWeak m l} {i : Fin n} →
(ih : apply (comp f g) i ≡ apply f i >>= apply g) →
apply (comp (lift f) (lift g)) (suc i) ≡
apply (lift f) (suc i) >>= apply (lift g)
lift-lift-suc f {g = g} {i = i} ih = begin
apply (comp (lift f) (lift g)) (suc i)
≡⟨⟩ -- definition of comp
apply (lift (comp f g)) (suc i)
≡⟨⟩ -- definition of apply
suc <$> apply (comp f g) i
≡⟨ cong (_<$>_ suc) ih ⟩ -- induction hypothesis
suc <$> (apply f i >>= apply g)
≡⟨ map-after-bind (apply f i) ⟩ -- map commutes with bind I
(apply f i >>= λ j → suc <$> apply g j)
≡⟨⟩ -- definition of apply
(apply f i >>= λ j → apply (lift g) (suc j))
≡⟨ sym (bind-after-map (apply f i)) ⟩ -- map commutes with bind II
(suc <$> apply f i) >>= apply (lift g)
≡⟨⟩ -- definition of apply
apply (lift f) (suc i) >>= apply (lift g)
∎
-- Soundness of comp
apply-comp : ∀ {n m l} (f : PWeak n m) (g : PWeak m l) (i : Fin n) →
apply (comp f g) i ≡ apply f i >>= apply g
apply-comp [] g ()
apply-comp (e ∷ f) g zero = refl
apply-comp (e ∷ f) g (suc i) = apply-comp f g i
-- apply-comp (lift f) (e ∷ g) i = {!!}
apply-comp (lift f) (e ∷ g) zero = refl
apply-comp (lift f) (e ∷ g) (suc i) with apply f i
apply-comp (lift f) (e ∷ g) (suc i) | left e′ = {!!}
apply-comp (lift f) (e ∷ g) (suc i) | right a = {!!}
apply-comp (lift f) (lift g) zero = refl
apply-comp (lift f) (lift g) (suc i) = lift-lift-suc f (apply-comp f g i)
apply-comp (lift f) (weak g) i = begin
suc <$> apply (comp (lift f) g) i
≡⟨ cong (_<$>_ suc) (apply-comp (lift f) g i) ⟩ -- ind. hyp.
suc <$> (apply (lift f) i >>= apply g)
≡⟨ map-after-bind (apply (lift f) i) ⟩ -- move map
apply (lift f) i >>= (λ j → suc <$> apply g j)
∎
apply-comp (weak f) g i = {!!}
|
{
"alphanum_fraction": 0.516263145,
"avg_line_length": 34.9487179487,
"ext": "agda",
"hexsha": "94ece769ef307eae41d6dbb331deb805dd44945a",
"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": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andreasabel/cubical",
"max_forks_repo_path": "src/Dimension/PartialWeakening/Soundness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"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": "andreasabel/cubical",
"max_issues_repo_path": "src/Dimension/PartialWeakening/Soundness.agda",
"max_line_length": 125,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andreasabel/cubical",
"max_stars_repo_path": "src/Dimension/PartialWeakening/Soundness.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1486,
"size": 4089
}
|
{-# OPTIONS --prop --rewriting #-}
module Examples.Exp2 where
open import Calf.CostMonoid
open import Calf.CostMonoids using (ℕ²-ParCostMonoid)
parCostMonoid = ℕ²-ParCostMonoid
open ParCostMonoid parCostMonoid
open import Calf costMonoid
open import Calf.ParMetalanguage parCostMonoid
open import Calf.Types.Bool
open import Calf.Types.Nat
open import Calf.Types.Bounded costMonoid
open import Calf.Types.BigO costMonoid
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; _≢_; module ≡-Reasoning)
open import Data.Nat as Nat using (_+_; pred; _*_; _^_; _⊔_)
import Data.Nat.Properties as N
open import Data.Nat.PredExp2
open import Data.Product
open import Data.Empty
Correct : cmp (Π nat λ _ → F nat) → Set
Correct exp₂ = (n : ℕ) → ◯ (exp₂ n ≡ ret (2 ^ n))
module Slow where
exp₂ : cmp (Π nat λ _ → F nat)
exp₂ zero = ret (suc zero)
exp₂ (suc n) =
bind (F nat) (exp₂ n & exp₂ n) λ (r₁ , r₂) →
step (F nat) (1 , 1) (ret (r₁ + r₂))
exp₂/correct : Correct exp₂
exp₂/correct zero u = refl
exp₂/correct (suc n) u =
begin
exp₂ (suc n)
≡⟨⟩
(bind (F nat) (exp₂ n & exp₂ n) λ (r₁ , r₂) →
step (F nat) (1 , 1) (ret (r₁ + r₂)))
≡⟨ Eq.cong (bind (F nat) (exp₂ n & exp₂ n)) (funext (λ (r₁ , r₂) → step/ext (F nat) _ (1 , 1) u)) ⟩
(bind (F nat) (exp₂ n & exp₂ n) λ (r₁ , r₂) →
ret (r₁ + r₂))
≡⟨ Eq.cong (λ e → bind (F nat) (e & e) _) (exp₂/correct n u) ⟩
step (F nat) (𝟘 ⊗ 𝟘) (ret (2 ^ n + 2 ^ n))
≡⟨⟩
ret (2 ^ n + 2 ^ n)
≡⟨ Eq.cong ret (lemma/2^suc n) ⟩
ret (2 ^ suc n)
∎
where open ≡-Reasoning
exp₂/cost : cmp (Π nat λ _ → cost)
exp₂/cost zero = 𝟘
exp₂/cost (suc n) =
bind cost (exp₂ n & exp₂ n) λ (r₁ , r₂) → (exp₂/cost n ⊗ exp₂/cost n) ⊕
((1 , 1) ⊕ 𝟘)
exp₂/cost/closed : cmp (Π nat λ _ → cost)
exp₂/cost/closed n = pred[2^ n ] , n
exp₂/cost≤exp₂/cost/closed : ∀ n → ◯ (exp₂/cost n ≤ exp₂/cost/closed n)
exp₂/cost≤exp₂/cost/closed zero u = ≤-refl
exp₂/cost≤exp₂/cost/closed (suc n) u =
let ≡ = exp₂/correct n u in
let open ≤-Reasoning in
begin
exp₂/cost (suc n)
≡⟨⟩
(bind cost (exp₂ n & exp₂ n) λ (r₁ , r₂) → (exp₂/cost n ⊗ exp₂/cost n) ⊕
((1 , 1) ⊕ 𝟘))
≡⟨ Eq.cong₂ (λ e₁ e₂ → bind cost (e₁ & e₂) λ (r₁ , r₂) → (exp₂/cost n ⊗ exp₂/cost n) ⊕ _) (≡) (≡) ⟩
(exp₂/cost n ⊗ exp₂/cost n) ⊕ ((1 , 1) ⊕ 𝟘)
≡⟨ Eq.cong ((exp₂/cost n ⊗ exp₂/cost n) ⊕_) (⊕-identityʳ _) ⟩
(exp₂/cost n ⊗ exp₂/cost n) ⊕ (1 , 1)
≤⟨ ⊕-monoˡ-≤ (1 , 1) (⊗-mono-≤ (exp₂/cost≤exp₂/cost/closed n u) (exp₂/cost≤exp₂/cost/closed n u)) ⟩
(exp₂/cost/closed n ⊗ exp₂/cost/closed n) ⊕ (1 , 1)
≡⟨ Eq.cong₂ _,_ arithmetic/work arithmetic/span ⟩
exp₂/cost/closed (suc n)
∎
where
arithmetic/work : proj₁ (exp₂/cost/closed n ⊗ exp₂/cost/closed n ⊕ (1 , 1)) ≡ proj₁ (exp₂/cost/closed (suc n))
arithmetic/work =
begin
proj₁ (exp₂/cost/closed n ⊗ exp₂/cost/closed n ⊕ (1 , 1))
≡⟨⟩
proj₁ (exp₂/cost/closed n) + proj₁ (exp₂/cost/closed n) + 1
≡⟨ N.+-comm _ 1 ⟩
suc (proj₁ (exp₂/cost/closed n) + proj₁ (exp₂/cost/closed n))
≡⟨⟩
suc (pred[2^ n ] + pred[2^ n ])
≡⟨ pred[2^suc[n]] n ⟩
pred[2^ suc n ]
≡⟨⟩
proj₁ (exp₂/cost/closed (suc n))
∎
where open ≡-Reasoning
arithmetic/span : proj₂ (exp₂/cost/closed n ⊗ exp₂/cost/closed n ⊕ (1 , 1)) ≡ proj₂ (exp₂/cost/closed (suc n))
arithmetic/span =
begin
proj₂ (exp₂/cost/closed n ⊗ exp₂/cost/closed n ⊕ (1 , 1))
≡⟨⟩
proj₂ (exp₂/cost/closed n) ⊔ proj₂ (exp₂/cost/closed n) + 1
≡⟨⟩
n ⊔ n + 1
≡⟨ Eq.cong (_+ 1) (N.⊔-idem n) ⟩
n + 1
≡⟨ N.+-comm _ 1 ⟩
suc n
≡⟨⟩
proj₂ (exp₂/cost/closed (suc n))
∎
where open ≡-Reasoning
exp₂≤exp₂/cost : ∀ n → IsBounded nat (exp₂ n) (exp₂/cost n)
exp₂≤exp₂/cost zero = bound/ret
exp₂≤exp₂/cost (suc n) =
bound/bind (exp₂/cost n ⊗ exp₂/cost n) _ (bound/par (exp₂≤exp₂/cost n) (exp₂≤exp₂/cost n)) λ (r₁ , r₂) →
bound/step (1 , 1) 𝟘 bound/ret
exp₂≤exp₂/cost/closed : ∀ n → IsBounded nat (exp₂ n) (exp₂/cost/closed n)
exp₂≤exp₂/cost/closed n = bound/relax (exp₂/cost≤exp₂/cost/closed n) (exp₂≤exp₂/cost n)
exp₂/asymptotic : given nat measured-via (λ n → n) , exp₂ ∈𝓞(λ n → 2 ^ n , n)
exp₂/asymptotic = 0 ≤n⇒f[n]≤g[n]via λ n _ → bound/relax (λ u → N.pred[n]≤n , N.≤-refl) (exp₂≤exp₂/cost/closed n)
module Fast where
exp₂ : cmp (Π nat λ _ → F nat)
exp₂ zero = ret (suc zero)
exp₂ (suc n) =
bind (F nat) (exp₂ n) λ r →
step (F nat) (1 , 1) (ret (r + r))
exp₂/correct : Correct exp₂
exp₂/correct zero u = refl
exp₂/correct (suc n) u =
begin
exp₂ (suc n)
≡⟨⟩
(bind (F nat) (exp₂ n) λ r →
step (F nat) (1 , 1) (ret (r + r)))
≡⟨ Eq.cong (bind (F nat) (exp₂ n)) (funext (λ r → step/ext (F nat) _ (1 , 1) u)) ⟩
(bind (F nat) (exp₂ n) λ r →
ret (r + r))
≡⟨ Eq.cong (λ e → bind (F nat) e _) (exp₂/correct n u) ⟩
(bind (F nat) (ret {nat} (2 ^ n)) λ r →
ret (r + r))
≡⟨⟩
ret (2 ^ n + 2 ^ n)
≡⟨ Eq.cong ret (lemma/2^suc n) ⟩
ret (2 ^ suc n)
∎
where open ≡-Reasoning
exp₂/cost : cmp (Π nat λ _ → cost)
exp₂/cost zero = 𝟘
exp₂/cost (suc n) =
bind cost (exp₂ n) λ r → exp₂/cost n ⊕
((1 , 1) ⊕ 𝟘)
exp₂/cost/closed : cmp (Π nat λ _ → cost)
exp₂/cost/closed n = n , n
exp₂/cost≤exp₂/cost/closed : ∀ n → ◯ (exp₂/cost n ≤ exp₂/cost/closed n)
exp₂/cost≤exp₂/cost/closed zero u = ≤-refl
exp₂/cost≤exp₂/cost/closed (suc n) u =
let open ≤-Reasoning in
begin
exp₂/cost (suc n)
≡⟨⟩
(bind cost (exp₂ n) λ r → exp₂/cost n ⊕
((1 , 1) ⊕ 𝟘))
≡⟨ Eq.cong (λ e → bind cost e λ r → exp₂/cost n ⊕ _) (exp₂/correct n u) ⟩
exp₂/cost n ⊕ ((1 , 1) ⊕ 𝟘)
≤⟨ ⊕-monoˡ-≤ ((1 , 1) ⊕ 𝟘) (exp₂/cost≤exp₂/cost/closed n u) ⟩
exp₂/cost/closed n ⊕ ((1 , 1) ⊕ 𝟘)
≡⟨ Eq.cong (exp₂/cost/closed n ⊕_) (⊕-identityʳ _) ⟩
exp₂/cost/closed n ⊕ (1 , 1)
≡⟨ Eq.cong₂ _,_ (N.+-comm _ 1) (N.+-comm _ 1) ⟩
exp₂/cost/closed (suc n)
∎
exp₂≤exp₂/cost : ∀ n → IsBounded nat (exp₂ n) (exp₂/cost n)
exp₂≤exp₂/cost zero = bound/ret
exp₂≤exp₂/cost (suc n) =
bound/bind (exp₂/cost n) _ (exp₂≤exp₂/cost n) λ r →
bound/step (1 , 1) 𝟘 bound/ret
exp₂≤exp₂/cost/closed : ∀ n → IsBounded nat (exp₂ n) (exp₂/cost/closed n)
exp₂≤exp₂/cost/closed n = bound/relax (exp₂/cost≤exp₂/cost/closed n) (exp₂≤exp₂/cost n)
exp₂/asymptotic : given nat measured-via (λ n → n) , exp₂ ∈𝓞(λ n → n , n)
exp₂/asymptotic = 0 ≤n⇒f[n]≤ 1 g[n]via λ n _ → Eq.subst (IsBounded _ _) (Eq.sym (⊕-identityʳ _)) (exp₂≤exp₂/cost/closed n)
slow≡fast : ◯ (Slow.exp₂ ≡ Fast.exp₂)
slow≡fast u = funext λ n →
begin
Slow.exp₂ n
≡⟨ Slow.exp₂/correct n u ⟩
ret (2 ^ n)
≡˘⟨ Fast.exp₂/correct n u ⟩
Fast.exp₂ n
∎
where open ≡-Reasoning
|
{
"alphanum_fraction": 0.5425889605,
"avg_line_length": 34.1531100478,
"ext": "agda",
"hexsha": "52d123ad92887359c4c0836cc3c876f47b1ffbe1",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Examples/Exp2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Examples/Exp2.agda",
"max_line_length": 124,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Examples/Exp2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 3172,
"size": 7138
}
|
------------------------------------------------------------------------
-- Semantics of the parsers
------------------------------------------------------------------------
module TotalParserCombinators.Semantics where
open import Codata.Musical.Notation
open import Data.List hiding (drop)
open import Data.List.Relation.Binary.BagAndSetEquality
using (bag) renaming (_∼[_]_ to _List-∼[_]_)
open import Data.Maybe using (Maybe); open Data.Maybe.Maybe
open import Data.Product
open import Data.Unit using (⊤; tt)
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence as Eq using (_⇔_; module Equivalence)
open import Function.Inverse using (_↔_; module Inverse)
open import Function.Related as Related using (Related)
open import Level
import Relation.Binary.HeterogeneousEquality as H
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open import TotalParserCombinators.Parser
------------------------------------------------------------------------
-- Semantics
-- The semantics of the parsers. x ∈ p · s means that x can be the
-- result of applying the parser p to the string s. Note that the
-- semantics is defined inductively.
infix 60 <$>_
infixl 50 _⊛_ [_-_]_⊛_
infixl 10 _>>=_ [_-_]_>>=_
infix 4 _∈_·_
data _∈_·_ {Tok} :
∀ {R xs} → R → Parser Tok R xs → List Tok → Set₁ where
return : ∀ {R} {x : R} → x ∈ return x · []
token : ∀ {x} → x ∈ token · [ x ]
∣-left : ∀ {R x xs₁ xs₂ s}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂}
(x∈p₁ : x ∈ p₁ · s) → x ∈ p₁ ∣ p₂ · s
∣-right : ∀ {R x xs₂ s} xs₁
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂}
(x∈p₂ : x ∈ p₂ · s) → x ∈ p₁ ∣ p₂ · s
<$>_ : ∀ {R₁ R₂ x s xs} {p : Parser Tok R₁ xs} {f : R₁ → R₂}
(x∈p : x ∈ p · s) → f x ∈ f <$> p · s
_⊛_ : ∀ {R₁ R₂ f x s₁ s₂ fs xs}
{p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs)}
{p₂ : ∞⟨ fs ⟩Parser Tok R₁ (flatten xs)} →
(f∈p₁ : f ∈ ♭? p₁ · s₁)
(x∈p₂ : x ∈ ♭? p₂ · s₂) →
f x ∈ p₁ ⊛ p₂ · s₁ ++ s₂
_>>=_ : ∀ {R₁ R₂ x y s₁ s₂ xs} {f : Maybe (R₁ → List R₂)}
{p₁ : ∞⟨ f ⟩Parser Tok R₁ (flatten xs)}
{p₂ : (x : R₁) → ∞⟨ xs ⟩Parser Tok R₂ (apply f x)}
(x∈p₁ : x ∈ ♭? p₁ · s₁)
(y∈p₂x : y ∈ ♭? (p₂ x) · s₂) →
y ∈ p₁ >>= p₂ · s₁ ++ s₂
nonempty : ∀ {R xs x y s} {p : Parser Tok R xs}
(x∈p : y ∈ p · x ∷ s) → y ∈ nonempty p · x ∷ s
cast : ∀ {R xs₁ xs₂ x s}
{xs₁≈xs₂ : xs₁ List-∼[ bag ] xs₂} {p : Parser Tok R xs₁}
(x∈p : x ∈ p · s) → x ∈ cast xs₁≈xs₂ p · s
-- Some variants with fewer implicit arguments. (The arguments xs and
-- fs can usually not be inferred, but I do not want to mention them
-- in the paper, so I have made them implicit in the definition
-- above.)
[_-_]_⊛_ : ∀ {Tok R₁ R₂ f x s₁ s₂} xs fs
{p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs)}
{p₂ : ∞⟨ fs ⟩Parser Tok R₁ (flatten xs)} →
f ∈ ♭? p₁ · s₁ → x ∈ ♭? p₂ · s₂ → f x ∈ p₁ ⊛ p₂ · s₁ ++ s₂
[ xs - fs ] f∈p₁ ⊛ x∈p₂ = _⊛_ {fs = fs} {xs = xs} f∈p₁ x∈p₂
[_-_]_>>=_ : ∀ {Tok R₁ R₂ x y s₁ s₂} (f : Maybe (R₁ → List R₂)) xs
{p₁ : ∞⟨ f ⟩Parser Tok R₁ (flatten xs)}
{p₂ : (x : R₁) → ∞⟨ xs ⟩Parser Tok R₂ (apply f x)} →
x ∈ ♭? p₁ · s₁ → y ∈ ♭? (p₂ x) · s₂ →
y ∈ p₁ >>= p₂ · s₁ ++ s₂
[ f - xs ] x∈p₁ >>= y∈p₂x = _>>=_ {xs = xs} {f = f} x∈p₁ y∈p₂x
------------------------------------------------------------------------
-- Parser and language equivalence
infix 4 _∼[_]_ _≈_ _≅_ _≲_
-- There are two kinds of equivalences. Parser equivalences are
-- stronger, and correspond to bag equality. Language equivalences are
-- weaker, and correspond to set equality.
open Data.List.Relation.Binary.BagAndSetEquality public
using (Kind)
renaming ( bag to parser
; set to language
; subbag to subparser
; subset to sublanguage
; superbag to superparser
; superset to superlanguage
)
-- General definition of equivalence between parsers. (Note that this
-- definition also gives access to some ordering relations.)
_∼[_]_ : ∀ {Tok R xs₁ xs₂} →
Parser Tok R xs₁ → Kind → Parser Tok R xs₂ → Set₁
p₁ ∼[ k ] p₂ = ∀ {x s} → Related k (x ∈ p₁ · s) (x ∈ p₂ · s)
-- Language equivalence. (Corresponds to set equality.)
_≈_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Set₁
p₁ ≈ p₂ = p₁ ∼[ language ] p₂
-- Parser equivalence. (Corresponds to bag equality.)
_≅_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Set₁
p₁ ≅ p₂ = p₁ ∼[ parser ] p₂
-- p₁ ≲ p₂ means that the language defined by p₂ contains all the
-- string/result pairs contained in the language defined by p₁.
_≲_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Set₁
p₁ ≲ p₂ = p₁ ∼[ sublanguage ] p₂
-- p₁ ≈ p₂ iff both p₁ ≲ p₂ and p₂ ≲ p₁.
≈⇔≲≳ : ∀ {Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ≈ p₂ ⇔ (p₁ ≲ p₂ × p₂ ≲ p₁)
≈⇔≲≳ = Eq.equivalence
(λ p₁≈p₂ →
((λ {x s} → _⟨$⟩_ (Equivalence.to (p₁≈p₂ {x = x} {s = s})))
, λ {x s} → _⟨$⟩_ (Equivalence.from (p₁≈p₂ {x = x} {s = s}))))
(λ p₁≲≳p₂ → λ {x s} → Eq.equivalence (proj₁ p₁≲≳p₂ {s = s})
(proj₂ p₁≲≳p₂ {s = s}))
-- Parser equivalence implies language equivalence.
≅⇒≈ : ∀ {Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ≅ p₂ → p₁ ≈ p₂
≅⇒≈ p₁≅p₂ = Related.↔⇒ p₁≅p₂
-- Language equivalence does not (in general) imply parser
-- equivalence.
¬≈⇒≅ : ¬ (∀ {Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ≈ p₂ → p₁ ≅ p₂)
¬≈⇒≅ hyp with Inverse.injective p₁≅p₂
{∣-left return} {∣-right [ tt ] return} (lemma _ _)
where
p₁ : Parser ⊤ ⊤ _
p₁ = return tt ∣ return tt
p₂ : Parser ⊤ ⊤ _
p₂ = return tt
p₁≲p₂ : p₁ ≲ p₂
p₁≲p₂ (∣-left return) = return
p₁≲p₂ (∣-right ._ return) = return
p₁≅p₂ : p₁ ≅ p₂
p₁≅p₂ = hyp $ Eq.equivalence p₁≲p₂ ∣-left
lemma : ∀ {x s} (x∈₁ x∈₂ : x ∈ p₂ · s) → x∈₁ ≡ x∈₂
lemma return return = P.refl
... | ()
------------------------------------------------------------------------
-- A simple cast lemma
cast∈ : ∀ {Tok R xs} {p p′ : Parser Tok R xs} {x x′ s s′} →
x ≡ x′ → p ≡ p′ → s ≡ s′ → x ∈ p · s → x′ ∈ p′ · s′
cast∈ P.refl P.refl P.refl x∈ = x∈
|
{
"alphanum_fraction": 0.5117513268,
"avg_line_length": 36.6388888889,
"ext": "agda",
"hexsha": "1ebfe84395caa8654bc1a75838e841d391c2a3f2",
"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": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Semantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"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/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Semantics.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Semantics.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 2481,
"size": 6595
}
|
-- Agda should warn if a coinductive record is declared but neither
-- --guardedness nor --sized-types is enabled.
record R : Set where
coinductive
field
r : R
|
{
"alphanum_fraction": 0.7100591716,
"avg_line_length": 21.125,
"ext": "agda",
"hexsha": "0872da64c55ee9781a6eba43f8e8368b13b2f82c",
"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/WarningNoGuardedness.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/WarningNoGuardedness.agda",
"max_line_length": 67,
"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/WarningNoGuardedness.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": 47,
"size": 169
}
|
{-# OPTIONS --safe --no-qualified-instances #-}
{- Noop removal transformation on bytecode -}
module JVM.Transform.Noooops where
open import Data.Product
open import Data.Sum
open import Function using (case_of_)
open import Data.List
open import Relation.Unary hiding (Empty)
open import Relation.Binary.Structures
open import Relation.Binary.PropositionalEquality using (refl; _≡_)
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Structures.Syntax hiding (_∣_)
open import JVM.Types
open import JVM.Model StackTy
open import JVM.Syntax.Instructions
open import Relation.Ternary.Data.ReflexiveTransitive {{intf-rel}}
open IsEquivalence {{...}} using (sym)
open import Data.Maybe using (just; nothing; Maybe)
is-noop : ∀[ ⟨ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟩ ⇒ (Empty (ψ₁ ≡ ψ₂) ∪ U) ]
is-noop noop = inj₁ (emp refl)
is-noop _ = inj₂ _
noooop : ∀[ ⟪ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟫ ⇒ ⟪ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟫ ]
noooop nil = nil
-- (1) not labeled
noooop (cons (instr (↓ i) ∙⟨ σ ⟩ is)) =
case (is-noop i) of λ where
(inj₂ _) → instr (↓ i) ▹⟨ σ ⟩ noooop is
(inj₁ (emp refl)) → coe (∙-id⁻ˡ σ) (noooop is)
-- (2) is labeled
noooop (cons (li@(labeled (l ∙⟨ σ₀ ⟩ ↓ i)) ∙⟨ σ ⟩ is)) =
case (is-noop i) of λ where
(inj₂ _) → cons (li ∙⟨ σ ⟩ noooop is)
(inj₁ (emp refl)) → label-start noop l ⟨ coe {{∙-respects-≈ˡ}} (≈-sym (∙-id⁻ʳ σ₀)) σ ⟩ (noooop is)
|
{
"alphanum_fraction": 0.659269864,
"avg_line_length": 32.488372093,
"ext": "agda",
"hexsha": "c7699236b82eb23e9a99032f7b2d08d339f0d169",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/JVM/Transform/Noooops.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/JVM/Transform/Noooops.agda",
"max_line_length": 102,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/JVM/Transform/Noooops.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 506,
"size": 1397
}
|
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.Consequences.Equality where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Fundamental.Reducibility
open import Tools.Embedding
open import Tools.Product
import Tools.PropositionalEquality as PE
U≡A′ : ∀ {A Γ l} ([U] : Γ ⊩⟨ l ⟩U)
→ Γ ⊩⟨ l ⟩ U ≡ A / (U-intr [U])
→ A PE.≡ U
U≡A′ (noemb [U]) (U₌ [U≡A]) = [U≡A]
U≡A′ (emb 0<1 [U]) (ιx [U≡A]) = U≡A′ [U] [U≡A]
-- If A is judgmentally equal to U, then A is propsitionally equal to U.
U≡A : ∀ {A Γ}
→ Γ ⊢ U ≡ A
→ A PE.≡ U
U≡A {A} U≡A with reducibleEq U≡A
U≡A {A} U≡A | [U] , [A] , [U≡A] =
U≡A′ (U-elim [U]) (irrelevanceEq [U] (U-intr (U-elim [U])) [U≡A])
ℕ≡A′ : ∀ {A Γ l} ([ℕ] : Γ ⊩⟨ l ⟩ℕ ℕ)
→ Γ ⊩⟨ l ⟩ ℕ ≡ A / (ℕ-intr [ℕ])
→ Whnf A
→ A PE.≡ ℕ
ℕ≡A′ (noemb x) (ιx (ℕ₌ [ℕ≡A])) whnfA = whnfRed* [ℕ≡A] whnfA
ℕ≡A′ (emb 0<1 [ℕ]) (ιx [ℕ≡A]) whnfA = ℕ≡A′ [ℕ] [ℕ≡A] whnfA
-- If A in WHNF is judgmentally equal to ℕ, then A is propsitionally equal to ℕ.
ℕ≡A : ∀ {A Γ}
→ Γ ⊢ ℕ ≡ A
→ Whnf A
→ A PE.≡ ℕ
ℕ≡A {A} ℕ≡A whnfA with reducibleEq ℕ≡A
ℕ≡A {A} ℕ≡A whnfA | [ℕ] , [A] , [ℕ≡A] =
ℕ≡A′ (ℕ-elim [ℕ]) (irrelevanceEq [ℕ] (ℕ-intr (ℕ-elim [ℕ])) [ℕ≡A]) whnfA
ne≡A′ : ∀ {A K Γ l}
→ ([K] : Γ ⊩⟨ l ⟩ne K)
→ Γ ⊩⟨ l ⟩ K ≡ A / (ne-intr [K])
→ Whnf A
→ ∃ λ M → Neutral M × A PE.≡ M
ne≡A′ (noemb [K]) (ιx (ne₌ M D′ neM K≡M)) whnfA =
M , neM , (whnfRed* (red D′) whnfA)
ne≡A′ (emb 0<1 [K]) (ιx [K≡A]) whnfA = ne≡A′ [K] [K≡A] whnfA
-- If A in WHNF is judgmentally equal to K, then there exists a M such that
-- A is propsitionally equal to M.
ne≡A : ∀ {A K Γ}
→ Neutral K
→ Γ ⊢ K ≡ A
→ Whnf A
→ ∃ λ M → Neutral M × A PE.≡ M
ne≡A {A} neK ne≡A whnfA with reducibleEq ne≡A
ne≡A {A} neK ne≡A whnfA | [ne] , [A] , [ne≡A] =
ne≡A′ (ne-elim neK [ne])
(irrelevanceEq [ne] (ne-intr (ne-elim neK [ne])) [ne≡A]) whnfA
Π≡A′ : ∀ {A F G Γ l} ([Π] : Γ ⊩⟨ l ⟩Π Π F ▹ G)
→ Γ ⊩⟨ l ⟩ Π F ▹ G ≡ A / (Π-intr [Π])
→ Whnf A
→ ∃₂ λ H E → A PE.≡ Π H ▹ E
Π≡A′ (noemb [Π]) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) whnfA =
F′ , G′ , whnfRed* D′ whnfA
Π≡A′ (emb 0<1 [Π]) (ιx [Π≡A]) whnfA = Π≡A′ [Π] [Π≡A] whnfA
-- If A is judgmentally equal to Π F ▹ G, then there exists H and E such that
-- A is propsitionally equal to Π H ▹ E.
Π≡A : ∀ {A F G Γ}
→ Γ ⊢ Π F ▹ G ≡ A
→ Whnf A
→ ∃₂ λ H E → A PE.≡ Π H ▹ E
Π≡A {A} Π≡A whnfA with reducibleEq Π≡A
Π≡A {A} Π≡A whnfA | [Π] , [A] , [Π≡A] =
Π≡A′ (Π-elim [Π]) (irrelevanceEq [Π] (Π-intr (Π-elim [Π])) [Π≡A]) whnfA
|
{
"alphanum_fraction": 0.5437969253,
"avg_line_length": 32.1494252874,
"ext": "agda",
"hexsha": "df370493c6fe0e76d300f1e1bfefd154472ea146",
"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": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/Consequences/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"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": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/Consequences/Equality.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/Consequences/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1458,
"size": 2797
}
|
{-# OPTIONS --rewriting #-}
module Issue5470.Import where
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
private
postulate
foo : Nat → Nat
bar : Nat → Nat
bar n = foo n
private
postulate
lemma : ∀ n → foo n ≡ n
{-# REWRITE lemma #-}
|
{
"alphanum_fraction": 0.6816720257,
"avg_line_length": 14.8095238095,
"ext": "agda",
"hexsha": "0f522bcf18bed2d20c021fc886f0b03c11646d32",
"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/Issue5470/Import.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/Issue5470/Import.agda",
"max_line_length": 41,
"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/Issue5470/Import.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": 93,
"size": 311
}
|
module ProposedSemantics where
open import Syntax public
-- Vindicative Kripke models.
record Model : Set₁ where
infix 3 _⊩ᵅ_
field
World : Set
_≤_ : World → World → Set
refl≤ : ∀ {w} → w ≤ w
trans≤ : ∀ {w w′ w″} → w ≤ w′ → w′ ≤ w″ → w ≤ w″
_R_ : World → World → Set
reflR : ∀ {w} → w R w
transR : ∀ {w w′ w″} → w R w′ → w′ R w″ → w R w″
_⊩ᵅ_ : World → Atom → Set
mono⊩ᵅ : ∀ {w w′ P} → w ≤ w′ → w ⊩ᵅ P → w′ ⊩ᵅ P
-- Vindication, a consequence of brilliance and persistence.
field
≤→R : ∀ {v′ w} → w ≤ v′ → w R v′
open Model {{…}} public
-- Forcing in a particular world of a particular model.
module _ {{_ : Model}} where
infix 3 _⊩_
_⊩_ : World → Type → Set
w ⊩ α P = w ⊩ᵅ P
w ⊩ A ⇒ B = ∀ {w′} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B
w ⊩ □ A = ∀ {v′} → w R v′ → v′ ⊩ A
w ⊩ A ⩕ B = w ⊩ A ∧ w ⊩ B
w ⊩ ⫪ = ⊤
w ⊩ ⫫ = ⊥
w ⊩ A ⩖ B = w ⊩ A ∨ w ⊩ B
infix 3 _⊩⋆_
_⊩⋆_ : World → Stack Type → Set
w ⊩⋆ ∅ = ⊤
w ⊩⋆ Ξ , A = w ⊩⋆ Ξ ∧ w ⊩ A
-- Monotonicity of forcing with respect to constructive accessibility.
module _ {{_ : Model}} where
mono⊩ : ∀ {A w w′} → w ≤ w′ → w ⊩ A → w′ ⊩ A
mono⊩ {α P} ψ s = mono⊩ᵅ ψ s
mono⊩ {A ⇒ B} ψ f = λ ψ′ a → f (trans≤ ψ ψ′) a
mono⊩ {□ A} ψ f = λ ρ → f (transR (≤→R ψ) ρ)
mono⊩ {A ⩕ B} ψ (a , b) = mono⊩ {A} ψ a , mono⊩ {B} ψ b
mono⊩ {⫪} ψ ∙ = ∙
mono⊩ {⫫} ψ ()
mono⊩ {A ⩖ B} ψ (ι₁ a) = ι₁ (mono⊩ {A} ψ a)
mono⊩ {A ⩖ B} ψ (ι₂ b) = ι₂ (mono⊩ {B} ψ b)
mono⊩⋆ : ∀ {Ξ w w′} → w ≤ w′ → w ⊩⋆ Ξ → w′ ⊩⋆ Ξ
mono⊩⋆ {∅} ψ ∙ = ∙
mono⊩⋆ {Ξ , A} ψ (ξ , s) = mono⊩⋆ {Ξ} ψ ξ , mono⊩ {A} ψ s
-- Additional equipment.
module _ {{_ : Model}} where
lookup : ∀ {Ξ A w} → A ∈ Ξ → w ⊩⋆ Ξ → w ⊩ A
lookup top (ξ , s) = s
lookup (pop i) (ξ , s) = lookup i ξ
-- Forcing in all worlds of all models, or semantic entailment.
infix 3 _⊨_
_⊨_ : Context → Type → Set₁
Γ ⁏ Δ ⊨ A = ∀ {{_ : Model}} {w} →
w ⊩⋆ Γ →
(∀ {v′} → w R v′ → v′ ⊩⋆ Δ) →
w ⊩ A
-- Soundness of the semantics with respect to the syntax.
reflect : ∀ {Γ Δ A} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A
reflect (var i) γ δ = lookup i γ
reflect (mvar i) γ δ = lookup i (δ reflR)
reflect (lam d) γ δ = λ ψ a → reflect d (mono⊩⋆ ψ γ , a)
(λ ρ → δ (transR (≤→R ψ) ρ))
reflect (app d e) γ δ = (reflect d γ δ) refl≤ (reflect e γ δ)
reflect (box d) γ δ = λ ρ → reflect d ∙
(λ ρ′ → δ (transR ρ ρ′))
reflect (unbox d e) γ δ = reflect e γ (λ ρ → δ ρ , (reflect d γ δ) ρ)
reflect (pair d e) γ δ = reflect d γ δ , reflect e γ δ
reflect (fst d) γ δ = π₁ (reflect d γ δ)
reflect (snd d) γ δ = π₂ (reflect d γ δ)
reflect unit γ δ = ∙
reflect (boom d) γ δ = elim⊥ (reflect d γ δ)
reflect (left d) γ δ = ι₁ (reflect d γ δ)
reflect (right d) γ δ = ι₂ (reflect d γ δ)
reflect (case d e f) γ δ = elim∨ (reflect d γ δ) (λ a → reflect e (γ , a) δ)
(λ b → reflect f (γ , b) δ)
|
{
"alphanum_fraction": 0.4454748961,
"avg_line_length": 30.359223301,
"ext": "agda",
"hexsha": "8fb0d05d6e20d9c85a8d9ad1e73bf4568a12d844",
"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": "accc6c57390c435728d568ae590a02b2776b8891",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/imla2017",
"max_forks_repo_path": "src/ProposedSemantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "accc6c57390c435728d568ae590a02b2776b8891",
"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/imla2017",
"max_issues_repo_path": "src/ProposedSemantics.agda",
"max_line_length": 76,
"max_stars_count": 17,
"max_stars_repo_head_hexsha": "accc6c57390c435728d568ae590a02b2776b8891",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/imla2017",
"max_stars_repo_path": "src/ProposedSemantics.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-17T13:02:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-02-27T05:04:55.000Z",
"num_tokens": 1474,
"size": 3127
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommMonoid.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.CommMonoid.Base
private
variable
ℓ ℓ' : Level
module _
(M : CommMonoid ℓ)
(P : ⟨ M ⟩ → hProp ℓ')
where
open CommMonoidStr (snd M)
module _
(·Closed : (x y : ⟨ M ⟩) → ⟨ P x ⟩ → ⟨ P y ⟩ → ⟨ P (x · y) ⟩)
(εContained : ⟨ P ε ⟩)
where
private
subtype = Σ[ x ∈ ⟨ M ⟩ ] ⟨ P x ⟩
makeSubCommMonoid : CommMonoid _
fst makeSubCommMonoid = subtype
CommMonoidStr.ε (snd makeSubCommMonoid) = ε , εContained
CommMonoidStr._·_ (snd makeSubCommMonoid) (x , xContained) (y , yContained) =
(x · y) , ·Closed x y xContained yContained
IsCommMonoid.isMonoid (CommMonoidStr.isCommMonoid (snd makeSubCommMonoid)) =
makeIsMonoid
(isOfHLevelΣ 2 (isSetFromIsCommMonoid isCommMonoid) λ _ → isProp→isSet (snd (P _)))
(λ x y z → Σ≡Prop (λ _ → snd (P _)) (·Assoc (fst x) (fst y) (fst z)))
(λ x → Σ≡Prop (λ _ → snd (P _)) (·IdR (fst x)))
λ x → Σ≡Prop (λ _ → snd (P _)) (·IdL (fst x))
IsCommMonoid.·Comm (CommMonoidStr.isCommMonoid (snd makeSubCommMonoid)) =
λ x y → Σ≡Prop (λ _ → snd (P _)) (·Comm (fst x) (fst y))
module CommMonoidTheory (M' : CommMonoid ℓ) where
open CommMonoidStr (snd M')
private M = ⟨ M' ⟩
commAssocl : (x y z : M) → x · (y · z) ≡ y · (x · z)
commAssocl x y z = ·Assoc x y z ∙∙ cong (_· z) (·Comm x y) ∙∙ sym (·Assoc y x z)
commAssocr : (x y z : M) → x · y · z ≡ x · z · y
commAssocr x y z = sym (·Assoc x y z) ∙∙ cong (x ·_) (·Comm y z) ∙∙ ·Assoc x z y
commAssocr2 : (x y z : M) → x · y · z ≡ z · y · x
commAssocr2 x y z = commAssocr _ _ _ ∙∙ cong (_· y) (·Comm _ _) ∙∙ commAssocr _ _ _
commAssocSwap : (x y z w : M) → (x · y) · (z · w) ≡ (x · z) · (y · w)
commAssocSwap x y z w = ·Assoc (x · y) z w ∙∙ cong (_· w) (commAssocr x y z)
∙∙ sym (·Assoc (x · z) y w)
|
{
"alphanum_fraction": 0.5778823529,
"avg_line_length": 35.4166666667,
"ext": "agda",
"hexsha": "40ee5bc4ef1d3348edda75eb6e7b83bc50b1285d",
"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/Properties.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/Properties.agda",
"max_line_length": 91,
"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/CommMonoid/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 823,
"size": 2125
}
|
-- Andreas, Ulf, AIM XXIX, 2019-03-18, issue #3597
-- Eta-expansion of record metas disregards freezing.
-- Meta occurs check is then insufficient, leading to cyclic assignment.
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v tc.meta:40 #-}
-- {-# OPTIONS -v tc.meta.assign:100 #-}
-- {-# OPTIONS -v tc.meta.eta:100 #-}
postulate P : (A : Set) → (a : A) → Set
record R : Set₁ where
constructor c
-- no-eta-equality -- WORKS without eta
field
A : Set
a : A
p : P A a → P A a
C : R
C = {!!}
module M = R C
test : P {!!} M.a → P {!!} M.a
test x = M.p x
-- WAS: cyclic assignment
-- C = _5
-- _7 := _5 .A
-- _9 := _5 .A
-- _5 := c _10 _11 _12
-- _10 := C .A
-- NOW: frozed metas are eta-expanded to records of frozen metas
|
{
"alphanum_fraction": 0.5787401575,
"avg_line_length": 20.0526315789,
"ext": "agda",
"hexsha": "000b3d20844975dd0ed5ba08339c230136b10a5a",
"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/Issue3597.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/Issue3597.agda",
"max_line_length": 72,
"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/Issue3597.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": 268,
"size": 762
}
|
module Generic.Lib.Data.Sum where
open import Data.Sum hiding (swap) renaming (map to smap) hiding (map₁; map₂; assocʳ; assocˡ; reduce) public
|
{
"alphanum_fraction": 0.7638888889,
"avg_line_length": 36,
"ext": "agda",
"hexsha": "eeed72f85b868764ee4b7974282130aacf01fb97",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "380554b20e0991290d1864ddf81f0587ec1647ed",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "iblech/Generic",
"max_forks_repo_path": "src/Generic/Lib/Data/Sum.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "380554b20e0991290d1864ddf81f0587ec1647ed",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "iblech/Generic",
"max_issues_repo_path": "src/Generic/Lib/Data/Sum.agda",
"max_line_length": 108,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "380554b20e0991290d1864ddf81f0587ec1647ed",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "iblech/Generic",
"max_stars_repo_path": "src/Generic/Lib/Data/Sum.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 42,
"size": 144
}
|
module Lectures.Four where
open import Lectures.One public
open import Lectures.Two public
open import Lectures.Three public
_∘_ : {A B C : Set} → (B → C) → (A → B) → (A → C)
(f ∘ g) x = f (g x)
record _↔_ (A B : Set) : Set where
constructor Isomorphism
field
to : A → B
from : B → A
from∘to : ∀ x → (from ∘ to) x ≡ x
to∘from : ∀ y → (to ∘ from) y ≡ y
open List
foldr-List : {A B : Set} → (A → B → B) → B → List A → B
foldr-List f z [] = z
foldr-List f z (x ∷ xs) = f x (foldr-List f z xs)
foldr-ℕ : {A : Set} → (A → A) → A → ℕ → A
foldr-ℕ f z zero = z
foldr-ℕ f z (suc n) = f (foldr-ℕ f z n)
ℕ↔List⊤ : ℕ ↔ List ⊤
ℕ↔List⊤ = Isomorphism to from from∘to to∘from
where
to : ℕ → List ⊤
to = foldr-ℕ (tt ∷_) []
from : List ⊤ → ℕ
from = foldr-List (λ _ → suc) 0
from∘to : ∀ x → (from ∘ to) x ≡ x
from∘to zero = refl
from∘to (suc x) = cong suc (from∘to x)
to∘from : ∀ x → (to ∘ from) x ≡ x
to∘from [] = refl
to∘from (tt ∷ xs) = cong (tt ∷_) (to∘from xs)
ℕ↔Even : ℕ ↔ Σ ℕ _isEven
ℕ↔Even = Isomorphism to from from∘to to∘from
where
to : ℕ → Σ ℕ _isEven
to zero = zero , tt
to (suc n) with to n
to (suc n) | (2n , 2nEven) = (suc (suc 2n) , 2nEven)
from : (Σ ℕ _isEven) → ℕ
from (n , nEven) = half n nEven
from∘to : ∀ x → (from ∘ to) x ≡ x
from∘to zero = refl
from∘to (suc n) with to n | from∘to n
from∘to (suc .(half (proj₁ q) (proj₂ q))) | q | refl = refl
to∘from : ∀ x → (to ∘ from) x ≡ x
to∘from (zero , tt) = refl
to∘from (suc (suc n) , nEven) rewrite to∘from (n , nEven) = refl
data Fin : ℕ → Set where
zero : ∀ {n} → Fin (suc n)
suc : ∀ {n} → Fin n → Fin (suc n)
noFin0 : Fin 0 → ⊥
noFin0 ()
open Vec
lookup : ∀ {n} {A : Set} → Vec A n → Fin n → A
lookup (x ∷ xs) zero = x
lookup (x ∷ xs) (suc i) = lookup xs i
-- For next time:
-- Fin
-- Constructive leq
|
{
"alphanum_fraction": 0.5411700975,
"avg_line_length": 22.512195122,
"ext": "agda",
"hexsha": "687fe23c64f77281b72cb710ac0cc2e4fdbac9f1",
"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": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "UoG-Agda/Agda101",
"max_forks_repo_path": "Lectures/Four.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"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": "UoG-Agda/Agda101",
"max_issues_repo_path": "Lectures/Four.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UoG-Agda/Agda101",
"max_stars_repo_path": "Lectures/Four.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 857,
"size": 1846
}
|
module Issue2447.M where
|
{
"alphanum_fraction": 0.84,
"avg_line_length": 12.5,
"ext": "agda",
"hexsha": "524fe7df459cd260e60b9488a79df9a437225883",
"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/interaction/Issue2447/M.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/interaction/Issue2447/M.agda",
"max_line_length": 24,
"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/interaction/Issue2447/M.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": 7,
"size": 25
}
|
------------------------------------------------------------------------
-- Data and codata can sometimes be "unified"
------------------------------------------------------------------------
-- In Haskell one can define the partial list type once, and define
-- map once and for all for this type. In Agda one typically defines
-- the (finite) list type + map and separately the (potentially
-- infinite) colist type + map. This is not strictly necessary,
-- though: the two types can be unified. The gain may be small,
-- though.
module DataAndCodata where
open import Codata.Musical.Notation
open import Function
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Conditional coinduction
data Rec : Set where
μ : Rec
ν : Rec
∞? : Rec → Set → Set
∞? μ = id
∞? ν = ∞
♯? : ∀ (r : Rec) {A} → A → ∞? r A
♯? μ x = x
♯? ν x = ♯ x
♭? : ∀ (r : Rec) {A} → ∞? r A → A
♭? μ = id
♭? ν = ♭
------------------------------------------------------------------------
-- A type for definitely finite or potentially infinite lists
-- If the Rec parameter is μ, then the type contains finite lists, and
-- otherwise it contains potentially infinite lists.
infixr 5 _∷_
data List∞? (r : Rec) (A : Set) : Set where
[] : List∞? r A
_∷_ : A → ∞? r (List∞? r A) → List∞? r A
-- List equality.
infix 4 _≈_
data _≈_ {r A} : List∞? r A → List∞? r A → Set where
[] : [] ≈ []
_∷_ : ∀ {x y xs ys} →
x ≡ y → ∞? r (♭? r xs ≈ ♭? r ys) → x ∷ xs ≈ y ∷ ys
-- μ-lists can be seen as ν-lists.
lift : ∀ {A} → List∞? μ A → List∞? ν A
lift [] = []
lift (x ∷ xs) = x ∷ ♯ lift xs
------------------------------------------------------------------------
-- The map function
-- Maps over any list. The definition contains separate cases for _∷_
-- depending on whether the Rec index is μ or ν, though.
map : ∀ {r A B} → (A → B) → List∞? r A → List∞? r B
map f [] = []
map {μ} f (x ∷ xs) = f x ∷ map f xs -- Structural recursion
-- (guarded).
map {ν} f (x ∷ xs) = f x ∷ ♯ map f (♭ xs) -- Guarded corecursion.
-- In Haskell the map function is automatically (in effect) parametric
-- in the Rec parameter. Here this property is not automatic, so I
-- have proved it manually:
map-parametric : ∀ {A B} (f : A → B) (xs : List∞? μ A) →
map f (lift xs) ≈ lift (map f xs)
map-parametric f [] = []
map-parametric f (x ∷ xs) = refl ∷ ♯ map-parametric f xs
|
{
"alphanum_fraction": 0.4968152866,
"avg_line_length": 29.9047619048,
"ext": "agda",
"hexsha": "4ef7e78516337a81789d9d81a5ead72033fee44f",
"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": "DataAndCodata.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": "DataAndCodata.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": "DataAndCodata.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": 756,
"size": 2512
}
|
{-# OPTIONS --universe-polymorphism --allow-unsolved-metas #-}
module Issue253 where
open import Common.Level
data Id l (X : Set l)(x : X) : X → Set where
refl : Id l X x x
resp : (A B : Set _) → Id _ (Set _) A B → Set
resp _ _ eq with eq
resp ._ _ eq | refl = Level
{-
An internal error has occurred. Please report this as a bug.
Location of the error: src/full/Agda/TypeChecking/Telescope.hs:51
-}
|
{
"alphanum_fraction": 0.6724137931,
"avg_line_length": 25.375,
"ext": "agda",
"hexsha": "a6ff7490146eba90771f66325de228ea68d3274c",
"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": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue253.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/succeed/Issue253.agda",
"max_line_length": 65,
"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/succeed/Issue253.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": 127,
"size": 406
}
|
-- Record projections should be positive in their argument
module Issue602-2 where
record A : Set₁ where
constructor mkA
field
f : Set
unA : A → Set
unA (mkA x) = x
data B (a : A) : Set where
mkB : unA a → B a
data D : Set where
d : B (mkA D) → D
|
{
"alphanum_fraction": 0.6311787072,
"avg_line_length": 15.4705882353,
"ext": "agda",
"hexsha": "38c5dfa21d8b2a495d67021aacf51e38fc9b1f73",
"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/Issue602-2.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/Issue602-2.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue602-2.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": 94,
"size": 263
}
|
module Luau.RuntimeError.ToString where
open import FFI.Data.String using (String; _++_)
open import Luau.RuntimeError using (RuntimeErrorᴮ; RuntimeErrorᴱ; local; return; NilIsNotAFunction; UnboundVariable; SEGV; app; block)
open import Luau.Addr.ToString using (addrToString)
open import Luau.Var.ToString using (varToString)
errToStringᴱ : ∀ {H B} → RuntimeErrorᴱ H B → String
errToStringᴮ : ∀ {H B} → RuntimeErrorᴮ H B → String
errToStringᴱ NilIsNotAFunction = "nil is not a function"
errToStringᴱ (UnboundVariable x) = "variable " ++ varToString x ++ " is unbound"
errToStringᴱ (SEGV a x) = "address " ++ addrToString a ++ " is unallocated"
errToStringᴱ (app E) = errToStringᴱ E
errToStringᴱ (block b E) = errToStringᴮ E ++ "\n in call of function " ++ varToString b
errToStringᴮ (local x E) = errToStringᴱ E ++ "\n in definition of " ++ varToString x
errToStringᴮ (return E) = errToStringᴱ E ++ "\n in return statement"
|
{
"alphanum_fraction": 0.7395498392,
"avg_line_length": 49.1052631579,
"ext": "agda",
"hexsha": "f11756f74c453fd717db47fcda5a129711ca6108",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FreakingBarbarians/luau",
"max_forks_repo_path": "prototyping/Luau/RuntimeError/ToString.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "FreakingBarbarians/luau",
"max_issues_repo_path": "prototyping/Luau/RuntimeError/ToString.agda",
"max_line_length": 135,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FreakingBarbarians/luau",
"max_stars_repo_path": "prototyping/Luau/RuntimeError/ToString.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z",
"num_tokens": 295,
"size": 933
}
|
------------------------------------------------------------------------
-- Colists
------------------------------------------------------------------------
{-# OPTIONS --without-K --sized-types #-}
open import Equality
module Colist {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where
private
open module E = Derived-definitions-and-properties eq using (_≡_)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Prelude.Size
open import Conat eq as Conat using (Conat; zero; suc; force; infinity)
open import Function-universe eq hiding (id; _∘_)
import Nat eq as Nat
------------------------------------------------------------------------
-- The type
-- Colists.
mutual
infixr 5 _∷_
data Colist {a} (A : Type a) (i : Size) : Type a where
[] : Colist A i
_∷_ : A → Colist′ A i → Colist A i
record Colist′ {a} (A : Type a) (i : Size) : Type a where
coinductive
field
force : {j : Size< i} → Colist A j
open Colist′ public
------------------------------------------------------------------------
-- Some operations
-- A variant of cons.
infixr 5 _∷′_
_∷′_ : ∀ {i a} {A : Type a} → A → Colist A i → Colist A i
x ∷′ xs = x ∷ λ { .force → xs }
-- The colist's tail, if any.
tail : ∀ {a} {A : Type a} {i} → Colist A i → Colist′ A i
tail xs@[] = λ { .force → xs }
tail (x ∷ xs) = xs
-- A map function.
map : ∀ {a b i} {A : Type a} {B : Type b} →
(A → B) → Colist A i → Colist B i
map f [] = []
map f (x ∷ xs) = f x ∷ λ { .force → map f (force xs) }
-- The length of a colist.
length : ∀ {a i} {A : Type a} → Colist A i → Conat i
length [] = zero
length (n ∷ ns) = suc λ { .force → length (force ns) }
-- The colist replicate n x contains exactly n copies of x (and
-- nothing else).
replicate : ∀ {a i} {A : Type a} → Conat i → A → Colist A i
replicate zero x = []
replicate (suc n) x = x ∷ λ { .force → replicate (force n) x }
-- Repeats the given element indefinitely.
repeat : ∀ {a i} {A : Type a} → A → Colist A i
repeat = replicate infinity
-- Appends one colist to another.
infixr 5 _++_
_++_ : ∀ {a i} {A : Type a} → Colist A i → Colist A i → Colist A i
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ λ { .force → force xs ++ ys }
-- The colist cycle x xs is an endless cycle of repetitions of the
-- colist x ∷ xs.
cycle : ∀ {a i} {A : Type a} → A → Colist′ A i → Colist A i
cycle x xs = x ∷ λ { .force → force xs ++ cycle x xs }
-- "Scan left".
scanl : ∀ {a b i} {A : Type a} {B : Type b} →
(A → B → A) → A → Colist B i → Colist A i
scanl c n [] = n ∷ λ { .force → [] }
scanl c n (x ∷ xs) = n ∷ λ { .force → scanl c (c n x) (force xs) }
-- The natural numbers in strictly increasing order.
nats : ∀ {i} → Colist ℕ i
nats = 0 ∷ λ { .force → map suc nats }
-- The colist nats-from n is the natural numbers greater than or equal
-- to n, in strictly increasing order.
nats-from : ∀ {i} → ℕ → Colist ℕ i
nats-from n = n ∷ λ { .force → nats-from (suc n) }
-- The list take n xs is the longest possible prefix of xs that
-- contains at most n elements.
take : ∀ {a} {A : Type a} → ℕ → Colist A ∞ → List A
take zero _ = []
take _ [] = []
take (suc n) (x ∷ xs) = x ∷ take n (force xs)
-- The sum of the successor of every element in the list.
sum-of-successors : ∀ {i} → Colist (Conat ∞) i → Conat i
sum-of-successors [] = zero
sum-of-successors (n ∷ ns) = suc λ { .force →
n Conat.+ sum-of-successors (ns .force) }
------------------------------------------------------------------------
-- Bisimilarity
module _ {a} {A : Type a} where
-- [ ∞ ] xs ∼ ys means that xs and ys are "equal".
mutual
infix 4 [_]_∼_ [_]_∼′_
data [_]_∼_ (i : Size) : Colist A ∞ → Colist A ∞ → Type a where
[] : [ i ] [] ∼ []
_∷_ : ∀ {x y xs ys} →
x ≡ y → [ i ] force xs ∼′ force ys → [ i ] x ∷ xs ∼ y ∷ ys
record [_]_∼′_ (i : Size) (xs ys : Colist A ∞) : Type a where
coinductive
field
force : {j : Size< i} → [ j ] xs ∼ ys
open [_]_∼′_ public
-- Bisimilarity is an equivalence relation.
reflexive-∼ : ∀ {i} xs → [ i ] xs ∼ xs
reflexive-∼ [] = []
reflexive-∼ (x ∷ xs) =
E.refl _ ∷ λ { .force → reflexive-∼ (force xs) }
symmetric-∼ : ∀ {i xs ys} →
[ i ] xs ∼ ys → [ i ] ys ∼ xs
symmetric-∼ [] = []
symmetric-∼ (p₁ ∷ p₂) =
E.sym p₁ ∷ λ { .force → symmetric-∼ (force p₂) }
transitive-∼ : ∀ {i xs ys zs} →
[ i ] xs ∼ ys → [ i ] ys ∼ zs → [ i ] xs ∼ zs
transitive-∼ [] [] = []
transitive-∼ (p₁ ∷ p₂) (q₁ ∷ q₂) =
E.trans p₁ q₁ ∷ λ { .force → transitive-∼ (force p₂) (force q₂) }
-- Equational reasoning combinators.
infix -1 _∎
infixr -2 step-∼ step-≡ _∼⟨⟩_
_∎ : ∀ {i} xs → [ i ] xs ∼ xs
_∎ = reflexive-∼
step-∼ : ∀ {i} xs {ys zs} →
[ i ] ys ∼ zs → [ i ] xs ∼ ys → [ i ] xs ∼ zs
step-∼ _ ys∼zs xs∼ys = transitive-∼ xs∼ys ys∼zs
syntax step-∼ xs ys∼zs xs∼ys = xs ∼⟨ xs∼ys ⟩ ys∼zs
step-≡ : ∀ {i} xs {ys zs} → [ i ] ys ∼ zs → xs ≡ ys → [ i ] xs ∼ zs
step-≡ {i} _ ys∼zs xs≡ys = E.subst ([ i ]_∼ _) (E.sym xs≡ys) ys∼zs
syntax step-≡ xs ys∼zs xs≡ys = xs ≡⟨ xs≡ys ⟩ ys∼zs
_∼⟨⟩_ : ∀ {i} xs {ys} → [ i ] xs ∼ ys → [ i ] xs ∼ ys
_ ∼⟨⟩ xs∼ys = xs∼ys
-- A property relating Colist._∷_ and _∷′_.
∷∼∷′ : ∀ {i} {x : A} {xs} →
[ i ] x ∷ xs ∼ x ∷′ force xs
∷∼∷′ = E.refl _ ∷ λ { .force → reflexive-∼ _ }
-- Functor laws.
map-id :
∀ {a i} {A : Type a} (xs : Colist A ∞) →
[ i ] map id xs ∼ xs
map-id [] = []
map-id (_ ∷ xs) = E.refl _ ∷ λ { .force → map-id (force xs) }
map-∘ :
∀ {a b c i} {A : Type a} {B : Type b} {C : Type c}
{f : B → C} {g : A → B}
(xs : Colist A ∞) →
[ i ] map (f ∘ g) xs ∼ map f (map g xs)
map-∘ [] = []
map-∘ (_ ∷ xs) = E.refl _ ∷ λ { .force → map-∘ (force xs) }
-- If two non-empty colists are bisimilar, then their heads are
-- bisimilar.
head-cong : ∀ {a i} {A : Type a} {x y : A} {xs ys} →
[ i ] x ∷ xs ∼ y ∷ ys → x ≡ y
head-cong (p ∷ _) = p
-- Some preservation lemmas.
tail-cong :
∀ {a i} {A : Type a} {xs ys : Colist A ∞} →
[ i ] xs ∼ ys → [ i ] force (tail xs) ∼′ force (tail ys)
tail-cong [] = λ { .force → [] }
tail-cong (_ ∷ ps) = ps
map-cong :
∀ {a b i} {A : Type a} {B : Type b} {f g : A → B} {xs ys} →
(∀ x → f x ≡ g x) → [ i ] xs ∼ ys → [ i ] map f xs ∼ map g ys
map-cong f≡g [] = []
map-cong {f = f} {g} f≡g (_∷_ {x = x} {y = y} x≡y ps) =
(f x E.≡⟨ E.cong f x≡y ⟩
f y E.≡⟨ f≡g y ⟩∎
g y ∎) ∷ λ { .force →
map-cong f≡g (force ps) }
length-cong :
∀ {a i} {A : Type a} {xs ys : Colist A ∞} →
[ i ] xs ∼ ys → Conat.[ i ] length xs ∼ length ys
length-cong [] = zero
length-cong (_ ∷ ps) = suc λ { .force → length-cong (force ps) }
replicate-cong :
∀ {a i} {A : Type a} {m n} {x : A} →
Conat.[ i ] m ∼ n → [ i ] replicate m x ∼ replicate n x
replicate-cong zero = []
replicate-cong (suc p) =
E.refl _ ∷ λ { .force → replicate-cong (force p) }
infixr 5 _++-cong_
_++-cong_ :
∀ {a i} {A : Type a} {xs₁ xs₂ ys₁ ys₂ : Colist A ∞} →
[ i ] xs₁ ∼ ys₁ → [ i ] xs₂ ∼ ys₂ → [ i ] xs₁ ++ xs₂ ∼ ys₁ ++ ys₂
[] ++-cong qs = qs
(p ∷ ps) ++-cong qs = p ∷ λ { .force → force ps ++-cong qs }
cycle-cong :
∀ {a i} {A : Type a} {x : A} {xs ys} →
[ i ] force xs ∼′ force ys → [ i ] cycle x xs ∼ cycle x ys
cycle-cong p = E.refl _ ∷ λ { .force → force p ++-cong cycle-cong p }
scanl-cong :
∀ {a b i} {A : Type a} {B : Type b} {c : A → B → A} {n : A} {xs ys} →
[ i ] xs ∼ ys → [ i ] scanl c n xs ∼ scanl c n ys
scanl-cong [] = E.refl _ ∷ λ { .force → [] }
scanl-cong {c = c} {n}
(_∷_ {x = x} {y = y} {xs = xs} {ys = ys} x≡y ps) =
E.refl n ∷ λ { .force →
scanl c (c n x) (force xs) ≡⟨ E.cong (λ x → scanl _ (c _ x) _) x≡y ⟩
scanl c (c n y) (force xs) ∼⟨ scanl-cong (force ps) ⟩
scanl c (c n y) (force ys) ∎ }
take-cong :
∀ {a} {A : Type a} n {xs ys : Colist A ∞} →
[ ∞ ] xs ∼ ys → take n xs ≡ take n ys
take-cong n [] = E.refl _
take-cong zero (p ∷ ps) = E.refl _
take-cong (suc n) (p ∷ ps) = E.cong₂ _∷_ p (take-cong n (force ps))
sum-of-successors-cong :
∀ {i ms ns} →
[ i ] ms ∼ ns →
Conat.[ i ] sum-of-successors ms ∼ sum-of-successors ns
sum-of-successors-cong [] = zero
sum-of-successors-cong (p ∷ ps) = suc λ { .force →
E.subst (Conat.[ _ ] _ ∼_) p (Conat.reflexive-∼ _)
Conat.+-cong
sum-of-successors-cong (ps .force) }
-- The length of replicate n x is bisimilar to n.
length-replicate :
∀ {a i} {A : Type a} {x : A} n →
Conat.[ i ] length (replicate n x) ∼ n
length-replicate zero = zero
length-replicate (suc n) =
suc λ { .force → length-replicate (force n) }
-- A lemma relating nats and nats-from n.
map-+-nats∼nats-from :
∀ {i} n → [ i ] map (n +_) nats ∼ nats-from n
map-+-nats∼nats-from n = Nat.+-right-identity ∷ λ { .force →
map (n +_) (map suc nats) ∼⟨ symmetric-∼ (map-∘ _) ⟩
map ((n +_) ∘ suc) nats ∼⟨ map-cong (λ _ → E.sym (Nat.suc+≡+suc _)) (_ ∎) ⟩
map (suc n +_) nats ∼⟨ map-+-nats∼nats-from (suc n) ⟩
nats-from (suc n) ∎ }
-- The colist nats is bisimilar to nats-from 0.
nats∼nats-from-0 : ∀ {i} → [ i ] nats ∼ nats-from 0
nats∼nats-from-0 =
nats ∼⟨ symmetric-∼ (map-id _) ⟩
map id nats ∼⟨⟩
map (0 +_) nats ∼⟨ map-+-nats∼nats-from _ ⟩
nats-from 0 ∎
------------------------------------------------------------------------
-- The ◇ predicate
-- ◇ ∞ P xs means that P holds for some element in xs.
data ◇ {a p} {A : Type a} (i : Size)
(P : A → Type p) : Colist A ∞ → Type (a ⊔ p) where
here : ∀ {x xs} → P x → ◇ i P (x ∷ xs)
there : ∀ {x xs} {j : Size< i} → ◇ j P (force xs) → ◇ i P (x ∷ xs)
-- ◇ respects bisimilarity.
◇-∼ :
∀ {a p i} {A : Type a} {P : A → Type p} {xs ys} →
[ ∞ ] xs ∼ ys → ◇ i P xs → ◇ i P ys
◇-∼ (x≡y ∷ _) (here p) = here (E.subst _ x≡y p)
◇-∼ (_ ∷ b) (there p) = there (◇-∼ (force b) p)
-- A map function for ◇.
◇-map : ∀ {a p q i} {A : Type a} {P : A → Type p} {Q : A → Type q} →
(∀ {x} → P x → Q x) →
(∀ {xs} → ◇ i P xs → ◇ i Q xs)
◇-map f (here p) = here (f p)
◇-map f (there p) = there (◇-map f p)
-- A variant of ◇-map.
◇-map′ : ∀ {a b c p q i} {A : Type a} {B : Type b} {C : Type c}
{P : B → Type p} {Q : C → Type q}
{f : A → B} {g : A → C} →
(∀ {x} → P (f x) → Q (g x)) →
(∀ {xs} → ◇ i P (map f xs) → ◇ i Q (map g xs))
◇-map′ g {_ ∷ _} (here p) = here (g p)
◇-map′ g {_ ∷ _} (there p) = there (◇-map′ g p)
◇-map′ g {[]} ()
-- If a predicate holds for some element in a colist, then it holds
-- for some value.
◇-witness : ∀ {a p i} {A : Type a} {P : A → Type p} {xs} →
◇ i P xs → ∃ P
◇-witness (here p) = _ , p
◇-witness (there p) = ◇-witness p
-- If const P holds for some element, then P holds.
◇-const : ∀ {a p i} {A : Type a} {P : Type p} {xs : Colist A ∞} →
◇ i (const P) xs → P
◇-const = proj₂ ∘ ◇-witness
-- Colist membership.
infix 4 [_]_∈_
[_]_∈_ : ∀ {a} {A : Type a} → Size → A → Colist A ∞ → Type a
[ i ] x ∈ xs = ◇ i (x ≡_) xs
-- A generalisation of "◇ ∞ P xs holds iff P holds for some element in
-- xs".
◇⇔∈× : ∀ {a p i} {A : Type a} {P : A → Type p} {xs} →
◇ i P xs ⇔ ∃ λ x → [ i ] x ∈ xs × P x
◇⇔∈× {P = P} = record { to = to; from = from }
where
to : ∀ {i xs} → ◇ i P xs → ∃ λ x → [ i ] x ∈ xs × P x
to (here p) = _ , here (E.refl _) , p
to (there p) = Σ-map id (Σ-map there id) (to p)
from : ∀ {i xs} → (∃ λ x → [ i ] x ∈ xs × P x) → ◇ i P xs
from (x , here eq , p) = here (E.subst P eq p)
from (x , there x∈xs , p) = there (from (x , x∈xs , p))
-- If P holds for some element in replicate (suc n) x, then it also
-- holds for x, and vice versa.
◇-replicate-suc⇔ :
∀ {a p i} {A : Type a} {P : A → Type p} {x : A} {n} →
◇ i P (replicate (suc n) x) ⇔ P x
◇-replicate-suc⇔ {P = P} {x} = record
{ to = to _
; from = here
}
where
to : ∀ {i} n → ◇ i P (replicate n x) → P x
to zero ()
to (suc n) (here p) = p
to (suc n) (there p) = to (force n) p
-- If P holds for some element in cycle x xs, then it also holds for
-- some element in x ∷ xs, and vice versa.
◇-cycle⇔ :
∀ {a p i} {A : Type a} {P : A → Type p} {x : A} {xs} →
◇ i P (cycle x xs) ⇔ ◇ i P (x ∷ xs)
◇-cycle⇔ {i = i} {P = P} {x} {xs} = record
{ to = ◇ i P (cycle x xs) ↝⟨ ◇-∼ (transitive-∼ ∷∼∷′ (symmetric-∼ ∷∼∷′)) ⟩
◇ i P ((x ∷ xs) ++ cycle x xs) ↝⟨ to _ ⟩
◇ i P (x ∷ xs) ⊎ ◇ i P (x ∷ xs) ↝⟨ [ id , id ] ⟩□
◇ i P (x ∷ xs) □
; from = ◇ i P (x ∷ xs) ↝⟨ from ⟩
◇ i P ((x ∷ xs) ++ cycle x xs) ↝⟨ ◇-∼ (transitive-∼ ∷∼∷′ (symmetric-∼ ∷∼∷′)) ⟩□
◇ i P (cycle x xs) □
}
where
to : ∀ {i} ys → ◇ i P (ys ++ cycle x xs) → ◇ i P ys ⊎ ◇ i P (x ∷ xs)
to [] (here p) = inj₂ (here p)
to [] (there p) = case to (force xs) p of
[ inj₂ ∘ there , inj₂ ]
to (y ∷ ys) (here p) = inj₁ (here p)
to (y ∷ ys) (there p) = ⊎-map there id (to (force ys) p)
from : ∀ {i ys} → ◇ i P ys → ◇ i P (ys ++ cycle x xs)
from (here p) = here p
from (there ps) = there (from ps)
------------------------------------------------------------------------
-- The □ predicate
-- □ ∞ P xs means that P holds for every element in xs.
mutual
data □ {a p} {A : Type a} (i : Size)
(P : A → Type p) : Colist A ∞ → Type (a ⊔ p) where
[] : □ i P []
_∷_ : ∀ {x xs} → P x → □′ i P (force xs) → □ i P (x ∷ xs)
record □′ {a p} {A : Type a} (i : Size)
(P : A → Type p) (xs : Colist A ∞) : Type (a ⊔ p) where
coinductive
field
force : {j : Size< i} → □ j P xs
open □′ public
-- Some projections.
□-head : ∀ {a p i} {A : Type a} {P : A → Type p} {x xs} →
□ i P (x ∷ xs) → P x
□-head (p ∷ _) = p
□-tail : ∀ {a p i} {j : Size< i} {A : Type a} {P : A → Type p} {x xs} →
□ i P (x ∷ xs) → □ j P (force xs)
□-tail (_ ∷ ps) = force ps
-- □ respects bisimilarity.
□-∼ :
∀ {i a p} {A : Type a} {P : A → Type p} {xs ys} →
[ i ] xs ∼ ys → □ i P xs → □ i P ys
□-∼ [] _ = []
□-∼ (eq ∷ b) (p ∷ ps) =
E.subst _ eq p ∷ λ { .force →
□-∼ (force b) (force ps) }
-- A generalisation of "□ ∞ P xs holds iff P is true for every element
-- in xs".
□⇔∈→ : ∀ {a p i} {A : Type a} {P : A → Type p} {xs} →
□ i P xs ⇔ (∀ x → [ i ] x ∈ xs → P x)
□⇔∈→ {P = P} = record { to = to; from = from _ }
where
to : ∀ {i xs} → □ i P xs → (∀ x → [ i ] x ∈ xs → P x)
to (p ∷ ps) x (here eq) = E.subst P (E.sym eq) p
to (p ∷ ps) x (there x∈xs) = to (force ps) x x∈xs
from : ∀ {i} xs → (∀ x → [ i ] x ∈ xs → P x) → □ i P xs
from [] f = []
from (x ∷ xs) f =
f x (here (E.refl _)) ∷ λ { .force →
from (force xs) (λ x → f x ∘ there) }
-- If P is universally true, then □ i P is also universally true.
□-replicate : ∀ {a p i} {A : Type a} {P : A → Type p} →
(∀ x → P x) →
(∀ xs → □ i P xs)
□-replicate f _ = _⇔_.from □⇔∈→ (λ x _ → f x)
-- Something resembling applicative functor application for □.
infixl 4 _□-⊛_
_□-⊛_ :
∀ {i a p q} {A : Type a} {P : A → Type p} {Q : A → Type q} {xs} →
□ i (λ x → P x → Q x) xs → □ i P xs → □ i Q xs
[] □-⊛ _ = []
(f ∷ fs) □-⊛ (p ∷ ps) = f p ∷ λ { .force → force fs □-⊛ force ps }
-- A map function for □.
□-map : ∀ {a p q i} {A : Type a} {P : A → Type p} {Q : A → Type q} →
(∀ {x} → P x → Q x) →
(∀ {xs} → □ i P xs → □ i Q xs)
□-map f ps = □-replicate (λ _ → f) _ □-⊛ ps
-- A variant of □-map.
□-map′ : ∀ {a b c p q i} {A : Type a} {B : Type b} {C : Type c}
{P : B → Type p} {Q : C → Type q}
{f : A → B} {g : A → C} →
(∀ {x} → P (f x) → Q (g x)) →
(∀ {xs} → □ i P (map f xs) → □ i Q (map g xs))
□-map′ g {[]} [] = []
□-map′ g {_ ∷ _} (p ∷ ps) = g p ∷ λ { .force → □-map′ g (force ps) }
-- Something resembling applicative functor application for □ and ◇.
infixl 4 _□◇-⊛_
_□◇-⊛_ :
∀ {a p q i} {A : Type a} {P : A → Type p} {Q : A → Type q} {xs} →
□ i (λ x → P x → Q x) xs → ◇ i P xs → ◇ i Q xs
(f ∷ _) □◇-⊛ (here p) = here (f p)
(_ ∷ fs) □◇-⊛ (there p) = there (force fs □◇-⊛ p)
-- A combination of some of the combinators above.
□◇-witness :
∀ {a p q i} {A : Type a} {P : A → Type p} {Q : A → Type q} {xs} →
□ i P xs → ◇ i Q xs → ∃ λ x → P x × Q x
□◇-witness p q = ◇-witness (□-map _,_ p □◇-⊛ q)
-- If P holds for every element in replicate (suc n) x, then it also holds
-- for x, and vice versa.
□-replicate-suc⇔ :
∀ {a p i} {A : Type a} {P : A → Type p} {x : A} {n} →
□ i P (replicate (suc n) x) ⇔ P x
□-replicate-suc⇔ {P = P} {x} = record
{ to = □-head
; from = from _
}
where
from : ∀ {i} n → P x → □ i P (replicate n x)
from zero p = []
from (suc n) p = p ∷ λ { .force → from (force n) p }
-- If P holds for every element in cycle x xs, then it also holds for
-- every element in x ∷ xs, and vice versa.
□-cycle⇔ :
∀ {a p i} {A : Type a} {P : A → Type p} {x : A} {xs} →
□ i P (cycle x xs) ⇔ □ i P (x ∷ xs)
□-cycle⇔ {i = i} {P = P} {x} {xs} = record
{ to = □ i P (cycle x xs) ↝⟨ (λ { (p ∷ ps) → p ∷ ps }) ⟩
□ i P ((x ∷ xs) ++ cycle x xs) ↝⟨ to _ ⟩□
□ i P (x ∷ xs) □
; from = □ i P (x ∷ xs) ↝⟨ (λ hyp → from hyp hyp) ⟩
□ i P ((x ∷ xs) ++ cycle x xs) ↝⟨ (λ { (p ∷ ps) → p ∷ ps }) ⟩□
□ i P (cycle x xs) □
}
where
to : ∀ {i} ys → □ i P (ys ++ cycle x xs) → □ i P ys
to [] _ = []
to (y ∷ ys) (p ∷ ps) = p ∷ λ { .force → to (force ys) (force ps) }
from : ∀ {i ys} →
□ i P (x ∷ xs) → □ i P ys → □ i P (ys ++ cycle x xs)
from ps (q ∷ qs) = q ∷ λ { .force → from ps (force qs) }
from (p ∷ ps) [] = p ∷ λ { .force → from (p ∷ ps) (force ps) }
------------------------------------------------------------------------
-- A variant of ◇ with a sized predicate
-- ◇ˢ ∞ P xs means that (some instance of) P holds for some element in
-- xs.
data ◇ˢ {a p} {A : Type a} (i : Size)
(P : Size → A → Type p) : Colist A ∞ → Type (a ⊔ p) where
here : ∀ {x xs} → P i x → ◇ˢ i P (x ∷ xs)
there : ∀ {x xs} {j : Size< i} → ◇ˢ j P (force xs) → ◇ˢ i P (x ∷ xs)
-- ◇ˢ respects bisimilarity.
◇ˢ-∼ :
∀ {a p i} {A : Type a} {P : Size → A → Type p} {xs ys} →
[ ∞ ] xs ∼ ys → ◇ˢ i P xs → ◇ˢ i P ys
◇ˢ-∼ (eq ∷ _) (here p) = here (E.subst _ eq p)
◇ˢ-∼ (_ ∷ b) (there p) = there (◇ˢ-∼ (force b) p)
-- If P is upwards closed, then flip ◇ˢ P is upwards closed.
◇ˢ-upwards-closed :
∀ {a p} {A : Type a} {P : Size → A → Type p} →
(∀ {i} {j : Size< i} {x} → P j x → P i x) →
(∀ {i} {j : Size< i} {xs} → ◇ˢ j P xs → ◇ˢ i P xs)
◇ˢ-upwards-closed P-closed (here p) = here (P-closed p)
◇ˢ-upwards-closed P-closed (there p) =
there (◇ˢ-upwards-closed P-closed p)
-- A variant of the previous lemma.
◇ˢ-upwards-closed-∞ :
∀ {a p} {A : Type a} {P : Size → A → Type p} →
(∀ {i x} → P i x → P ∞ x) →
(∀ {i xs} → ◇ˢ i P xs → ◇ˢ ∞ P xs)
◇ˢ-upwards-closed-∞ P-closed-∞ (here p) = here (P-closed-∞ p)
◇ˢ-upwards-closed-∞ P-closed-∞ (there p) =
there (◇ˢ-upwards-closed-∞ P-closed-∞ p)
-- A map function for ◇ˢ.
◇ˢ-map :
∀ {a p q i}
{A : Type a} {P : Size → A → Type p} {Q : Size → A → Type q} →
(∀ {i x} → P i x → Q i x) →
(∀ {xs} → ◇ˢ i P xs → ◇ˢ i Q xs)
◇ˢ-map f (here p) = here (f p)
◇ˢ-map f (there p) = there (◇ˢ-map f p)
-- A variant of ◇ˢ-map.
◇ˢ-map′ : ∀ {a b c p q i} {A : Type a} {B : Type b} {C : Type c}
{P : Size → B → Type p} {Q : Size → C → Type q}
{f : A → B} {g : A → C} →
(∀ {i x} → P i (f x) → Q i (g x)) →
(∀ {xs} → ◇ˢ i P (map f xs) → ◇ˢ i Q (map g xs))
◇ˢ-map′ g {_ ∷ _} (here p) = here (g p)
◇ˢ-map′ g {_ ∷ _} (there p) = there (◇ˢ-map′ g p)
◇ˢ-map′ g {[]} ()
-- If a predicate holds for some element in a colist, then it holds
-- for some value (assuming that P is upwards closed).
◇ˢ-witness : ∀ {a p i} {A : Type a} {P : Size → A → Type p} {xs} →
(∀ {i} {j : Size< i} {x} → P j x → P i x) →
◇ˢ i P xs → ∃ (P i)
◇ˢ-witness closed (here p) = _ , p
◇ˢ-witness closed (there p) = Σ-map id closed (◇ˢ-witness closed p)
-- If P ∞ holds for some element in xs, then ◇ˢ ∞ P xs holds.
∈×∞→◇ˢ : ∀ {a p} {A : Type a} {P : Size → A → Type p} {x xs} →
[ ∞ ] x ∈ xs → P ∞ x → ◇ˢ ∞ P xs
∈×∞→◇ˢ (here eq) p = here (E.subst _ eq p)
∈×∞→◇ˢ (there x∈xs) p = there (∈×∞→◇ˢ x∈xs p)
-- If P i x implies P ∞ x for any i and x, then ◇ˢ ∞ P xs holds iff
-- P ∞ holds for some element in xs.
◇ˢ⇔∈× : ∀ {a p} {A : Type a} {P : Size → A → Type p} {xs} →
(∀ {i x} → P i x → P ∞ x) →
◇ˢ ∞ P xs ⇔ (∃ λ x → [ ∞ ] x ∈ xs × P ∞ x)
◇ˢ⇔∈× {P = P} →∞ = record
{ to = to
; from = λ { (_ , x∈xs , p) → ∈×∞→◇ˢ x∈xs p }
}
where
to : ∀ {i xs} → ◇ˢ i P xs → ∃ λ x → [ ∞ ] x ∈ xs × P ∞ x
to (here p) = _ , here (E.refl _) , →∞ p
to (there p) = Σ-map id (Σ-map there id) (to p)
-- Sized variants of the previous lemma.
◇ˢ→∈× : ∀ {a p} {A : Type a} {P : Size → A → Type p} →
(∀ {i} {j : Size< i} {x} → P j x → P i x) →
∀ {i xs} → ◇ˢ i P xs → ∃ λ x → [ i ] x ∈ xs × P i x
◇ˢ→∈× closed (here p) = _ , here (E.refl _) , p
◇ˢ→∈× closed (there p) = Σ-map id (Σ-map there closed) (◇ˢ→∈× closed p)
∈×→◇ˢ : ∀ {a p} {A : Type a} {P : Size → A → Type p} →
(∀ {i} {j : Size< i} {x} → P i x → P j x) →
∀ {i x xs} → [ i ] x ∈ xs → P i x → ◇ˢ i P xs
∈×→◇ˢ closed (here eq) p = here (E.subst _ eq p)
∈×→◇ˢ closed (there x∈xs) p = there (∈×→◇ˢ closed x∈xs (closed p))
-- ◇ ∞ (P ∞) is "contained in" ◇ˢ ∞ P.
◇∞→◇ˢ∞ : ∀ {a p} {A : Type a} {P : Size → A → Type p} {xs} →
◇ ∞ (P ∞) xs → ◇ˢ ∞ P xs
◇∞→◇ˢ∞ {P = P} {xs} =
◇ ∞ (P ∞) xs ↝⟨ _⇔_.to ◇⇔∈× ⟩
(∃ λ x → [ ∞ ] x ∈ xs × P ∞ x) ↝⟨ (λ { (_ , x∈xs , p) → ∈×∞→◇ˢ x∈xs p }) ⟩□
◇ˢ ∞ P xs □
-- If P i x implies P ∞ x for any i and x, then ◇ˢ ∞ P is pointwise
-- logically equivalent to ◇ ∞ (P ∞).
◇ˢ∞⇔◇∞ : ∀ {a p} {A : Type a} {P : Size → A → Type p} {xs} →
(∀ {i x} → P i x → P ∞ x) →
◇ˢ ∞ P xs ⇔ ◇ ∞ (P ∞) xs
◇ˢ∞⇔◇∞ {P = P} {xs} →∞ =
◇ˢ ∞ P xs ↝⟨ ◇ˢ⇔∈× →∞ ⟩
(∃ λ x → [ ∞ ] x ∈ xs × P ∞ x) ↝⟨ inverse ◇⇔∈× ⟩□
◇ ∞ (P ∞) xs □
-- ◇ˢ i (const P) is pointwise logically equivalent to ◇ i P.
◇ˢ⇔◇ : ∀ {a p i} {A : Type a} {P : A → Type p} {xs} →
◇ˢ i (λ _ → P) xs ⇔ ◇ i P xs
◇ˢ⇔◇ {P = P} {xs} = record { to = to; from = from }
where
to : ∀ {i xs} → ◇ˢ i (λ _ → P) xs → ◇ i P xs
to (here p) = here p
to (there p) = there (to p)
from : ∀ {i xs} → ◇ i P xs → ◇ˢ i (λ _ → P) xs
from (here p) = here p
from (there p) = there (from p)
-- If ◇ˢ i P (x ∷ xs) holds, then ◇ˢ i P (cycle x xs) also holds.
◇ˢ-cycle← :
∀ {a p i} {A : Type a} {P : Size → A → Type p} {x : A} {xs} →
◇ˢ i P (x ∷ xs) → ◇ˢ i P (cycle x xs)
◇ˢ-cycle← {i = i} {P = P} {x} {xs} =
◇ˢ i P (x ∷ xs) ↝⟨ from ⟩
◇ˢ i P ((x ∷ xs) ++ cycle x xs) ↝⟨ ◇ˢ-∼ (transitive-∼ ∷∼∷′ (symmetric-∼ ∷∼∷′)) ⟩□
◇ˢ i P (cycle x xs) □
where
from : ∀ {i ys} → ◇ˢ i P ys → ◇ˢ i P (ys ++ cycle x xs)
from (here p) = here p
from (there ps) = there (from ps)
-- If P i x implies P ∞ x for any i and x, then ◇ˢ ∞ P (cycle x xs) is
-- logically equivalent to ◇ˢ ∞ P (x ∷ xs).
◇ˢ-cycle⇔ :
∀ {a p} {A : Type a} {P : Size → A → Type p} {x : A} {xs} →
(∀ {i x} → P i x → P ∞ x) →
◇ˢ ∞ P (cycle x xs) ⇔ ◇ˢ ∞ P (x ∷ xs)
◇ˢ-cycle⇔ {P = P} {x} {xs} →∞ = record
{ to = ◇ˢ ∞ P (cycle x xs) ↝⟨ ◇ˢ-∼ (transitive-∼ ∷∼∷′ (symmetric-∼ ∷∼∷′)) ⟩
◇ˢ ∞ P ((x ∷ xs) ++ cycle x xs) ↝⟨ to _ ⟩
◇ˢ ∞ P (x ∷ xs) ⊎ ◇ˢ ∞ P (x ∷ xs) ↝⟨ [ id , id ] ⟩□
◇ˢ ∞ P (x ∷ xs) □
; from = ◇ˢ-cycle←
}
where
to :
∀ {i} ys → ◇ˢ i P (ys ++ cycle x xs) → ◇ˢ ∞ P ys ⊎ ◇ˢ ∞ P (x ∷ xs)
to [] (here p) = inj₂ (here (→∞ p))
to [] (there p) = case to (force xs) p of
[ inj₂ ∘ there , inj₂ ]
to (y ∷ ys) (here p) = inj₁ (here (→∞ p))
to (y ∷ ys) (there p) = ⊎-map there id (to (force ys) p)
------------------------------------------------------------------------
-- A variant of □ with a sized predicate
-- □ˢ ∞ P xs means that (some instance of) P holds for every element
-- in xs.
mutual
data □ˢ {a p} {A : Type a} (i : Size)
(P : Size → A → Type p) : Colist A ∞ → Type (a ⊔ p) where
[] : □ˢ i P []
_∷_ : ∀ {x xs} → P i x → □ˢ′ i P (force xs) → □ˢ i P (x ∷ xs)
record □ˢ′ {a p} {A : Type a} (i : Size)
(P : Size → A → Type p) (xs : Colist A ∞) :
Type (a ⊔ p) where
coinductive
field
force : {j : Size< i} → □ˢ j P xs
open □ˢ′ public
-- Some projections.
□ˢ-head : ∀ {a p i} {A : Type a} {P : Size → A → Type p} {x xs} →
□ˢ i P (x ∷ xs) → P i x
□ˢ-head (p ∷ _) = p
□ˢ-tail : ∀ {a p i} {j : Size< i}
{A : Type a} {P : Size → A → Type p} {x xs} →
□ˢ i P (x ∷ xs) → □ˢ j P (force xs)
□ˢ-tail (_ ∷ ps) = force ps
-- □ˢ respects bisimilarity.
□ˢ-∼ :
∀ {i a p} {A : Type a} {P : Size → A → Type p} {xs ys} →
[ i ] xs ∼ ys → □ˢ i P xs → □ˢ i P ys
□ˢ-∼ [] _ = []
□ˢ-∼ (eq ∷ b) (p ∷ ps) =
E.subst _ eq p ∷ λ { .force →
□ˢ-∼ (force b) (force ps) }
-- If P is downwards closed, then flip □ˢ P is downwards closed.
□ˢ-downwards-closed :
∀ {a p} {A : Type a} {P : Size → A → Type p} →
(∀ {i} {j : Size< i} {x} → P i x → P j x) →
(∀ {i} {j : Size< i} {xs} → □ˢ i P xs → □ˢ j P xs)
□ˢ-downwards-closed P-closed [] = []
□ˢ-downwards-closed P-closed (p ∷ ps) =
P-closed p ∷ λ { .force → □ˢ-downwards-closed P-closed (force ps) }
-- A variant of the previous lemma.
□ˢ-downwards-closed-∞ :
∀ {a p} {A : Type a} {P : Size → A → Type p} →
(∀ {i x} → P ∞ x → P i x) →
(∀ {i xs} → □ˢ ∞ P xs → □ˢ i P xs)
□ˢ-downwards-closed-∞ P-closed-∞ [] = []
□ˢ-downwards-closed-∞ P-closed-∞ (p ∷ ps) =
P-closed-∞ p ∷ λ { .force →
□ˢ-downwards-closed-∞ P-closed-∞ (force ps) }
-- If □ˢ ∞ P xs holds, then P ∞ holds for every element in xs.
□ˢ∞∈→ : ∀ {a p} {A : Type a} {P : Size → A → Type p} {xs x} →
□ˢ ∞ P xs → [ ∞ ] x ∈ xs → P ∞ x
□ˢ∞∈→ (p ∷ ps) (here eq) = E.subst _ (E.sym eq) p
□ˢ∞∈→ (p ∷ ps) (there x∈xs) = □ˢ∞∈→ (force ps) x∈xs
-- If P ∞ x implies P i x for any i and x, then □ˢ ∞ P xs holds iff P ∞
-- holds for every element in xs.
□ˢ⇔∈→ : ∀ {a p} {A : Type a} {P : Size → A → Type p} {xs} →
(∀ {i x} → P ∞ x → P i x) →
□ˢ ∞ P xs ⇔ (∀ x → [ ∞ ] x ∈ xs → P ∞ x)
□ˢ⇔∈→ {P = P} ∞→ = record { to = λ p _ → □ˢ∞∈→ p; from = from _ }
where
from : ∀ {i} xs → (∀ x → [ ∞ ] x ∈ xs → P ∞ x) → □ˢ i P xs
from [] f = []
from (x ∷ xs) f =
∞→ (f x (here (E.refl _))) ∷ λ { .force →
from (force xs) (λ x → f x ∘ there) }
-- Sized variants of the previous lemma.
□ˢ∈→ : ∀ {a p} {A : Type a} {P : Size → A → Type p} →
(∀ {i} {j : Size< i} {x} → P j x → P i x) →
∀ {i x xs} → □ˢ i P xs → [ i ] x ∈ xs → P i x
□ˢ∈→ closed (p ∷ ps) (here eq) = E.subst _ (E.sym eq) p
□ˢ∈→ closed (p ∷ ps) (there x∈xs) = closed (□ˢ∈→ closed (force ps) x∈xs)
∈→→□ˢ : ∀ {a p} {A : Type a} {P : Size → A → Type p} →
(∀ {i} {j : Size< i} {x} → P i x → P j x) →
∀ {i} xs → (∀ x → [ i ] x ∈ xs → P i x) → □ˢ i P xs
∈→→□ˢ closed [] f = []
∈→→□ˢ closed (x ∷ xs) f =
f x (here (E.refl _)) ∷ λ { .force →
∈→→□ˢ closed (force xs) (λ x → closed ∘ f x ∘ there) }
-- □ˢ ∞ P is "contained in" □ ∞ (P ∞).
□ˢ∞→□∞ : ∀ {a p} {A : Type a} {P : Size → A → Type p} {xs} →
□ˢ ∞ P xs → □ ∞ (P ∞) xs
□ˢ∞→□∞ {P = P} {xs} =
□ˢ ∞ P xs ↝⟨ (λ p _ → □ˢ∞∈→ p) ⟩
(∀ x → [ ∞ ] x ∈ xs → P ∞ x) ↝⟨ _⇔_.from □⇔∈→ ⟩□
□ ∞ (P ∞) xs □
-- If P ∞ x implies P i x for any i and x, then □ˢ ∞ P is pointwise
-- logically equivalent to □ ∞ (P ∞).
□ˢ∞⇔□∞ : ∀ {a p} {A : Type a} {P : Size → A → Type p} {xs} →
(∀ {i x} → P ∞ x → P i x) →
□ˢ ∞ P xs ⇔ □ ∞ (P ∞) xs
□ˢ∞⇔□∞ {P = P} {xs} ∞→ =
□ˢ ∞ P xs ↝⟨ □ˢ⇔∈→ ∞→ ⟩
(∀ x → [ ∞ ] x ∈ xs → P ∞ x) ↝⟨ inverse □⇔∈→ ⟩□
□ ∞ (P ∞) xs □
-- □ˢ i (const P) is pointwise logically equivalent to □ i P.
□ˢ⇔□ : ∀ {a p i} {A : Type a} {P : A → Type p} {xs} →
□ˢ i (λ _ → P) xs ⇔ □ i P xs
□ˢ⇔□ {P = P} {xs} = record { to = to; from = from }
where
to : ∀ {i xs} → □ˢ i (λ _ → P) xs → □ i P xs
to [] = []
to (p ∷ ps) = p ∷ λ { .force → to (force ps) }
from : ∀ {i xs} → □ i P xs → □ˢ i (λ _ → P) xs
from [] = []
from (p ∷ ps) = p ∷ λ { .force → from (force ps) }
-- If P is universally true, then □ˢ i P is also universally true.
□ˢ-replicate : ∀ {a p i} {A : Type a} {P : Size → A → Type p} →
(∀ {i} x → P i x) →
(∀ xs → □ˢ i P xs)
□ˢ-replicate f [] = []
□ˢ-replicate f (x ∷ xs) = f x ∷ λ { .force → □ˢ-replicate f (force xs) }
-- Something resembling applicative functor application for □ˢ.
infixl 4 _□ˢ-⊛_
_□ˢ-⊛_ : ∀ {i a p q} {A : Type a}
{P : Size → A → Type p} {Q : Size → A → Type q} {xs} →
□ˢ i (λ j x → P j x → Q j x) xs → □ˢ i P xs → □ˢ i Q xs
[] □ˢ-⊛ _ = []
(f ∷ fs) □ˢ-⊛ (p ∷ ps) = f p ∷ λ { .force → force fs □ˢ-⊛ force ps }
-- A map function for □ˢ.
□ˢ-map :
∀ {a p q i}
{A : Type a} {P : Size → A → Type p} {Q : Size → A → Type q} →
(∀ {i x} → P i x → Q i x) →
(∀ {xs} → □ˢ i P xs → □ˢ i Q xs)
□ˢ-map f ps = □ˢ-replicate (λ _ → f) _ □ˢ-⊛ ps
-- A variant of □ˢ-map.
□ˢ-map′ : ∀ {a b c p q i} {A : Type a} {B : Type b} {C : Type c}
{P : Size → B → Type p} {Q : Size → C → Type q}
{f : A → B} {g : A → C} →
(∀ {i x} → P i (f x) → Q i (g x)) →
(∀ {xs} → □ˢ i P (map f xs) → □ˢ i Q (map g xs))
□ˢ-map′ g {[]} [] = []
□ˢ-map′ g {_ ∷ _} (p ∷ ps) = g p ∷ λ { .force → □ˢ-map′ g (force ps) }
-- Something resembling applicative functor application for □ˢ and ◇ˢ.
infixl 4 _□ˢ◇ˢ-⊛_
_□ˢ◇ˢ-⊛_ : ∀ {a p q i} {A : Type a}
{P : Size → A → Type p} {Q : Size → A → Type q} {xs} →
□ˢ i (λ j x → P j x → Q j x) xs → ◇ˢ i P xs → ◇ˢ i Q xs
(f ∷ _) □ˢ◇ˢ-⊛ (here p) = here (f p)
(_ ∷ fs) □ˢ◇ˢ-⊛ (there p) = there (force fs □ˢ◇ˢ-⊛ p)
-- A combination of some of the combinators above.
□ˢ◇ˢ-witness :
∀ {a p q i}
{A : Type a} {P : Size → A → Type p} {Q : Size → A → Type q} {xs} →
(∀ {i} {j : Size< i} {x} → P j x → P i x) →
(∀ {i} {j : Size< i} {x} → Q j x → Q i x) →
□ˢ i P xs → ◇ˢ i Q xs → ∃ λ x → P i x × Q i x
□ˢ◇ˢ-witness P-closed Q-closed p q =
◇ˢ-witness (λ { {_} {_} → Σ-map P-closed Q-closed })
(□ˢ-map _,_ p □ˢ◇ˢ-⊛ q)
-- If □ˢ i P (cycle x xs) holds, then □ˢ i P (x ∷ xs) also holds.
□ˢ-cycle→ :
∀ {a p i} {A : Type a} {P : Size → A → Type p} {x : A} {xs} →
□ˢ i P (cycle x xs) → □ˢ i P (x ∷ xs)
□ˢ-cycle→ {i = i} {P = P} {x} {xs} =
□ˢ i P (cycle x xs) ↝⟨ (λ { (p ∷ ps) → p ∷ ps }) ⟩
□ˢ i P ((x ∷ xs) ++ cycle x xs) ↝⟨ to _ ⟩□
□ˢ i P (x ∷ xs) □
where
to : ∀ {i} ys → □ˢ i P (ys ++ cycle x xs) → □ˢ i P ys
to [] _ = []
to (y ∷ ys) (p ∷ ps) = p ∷ λ { .force → to (force ys) (force ps) }
-- If P ∞ x implies P i x for any i and x, then □ˢ ∞ P (cycle x xs) is
-- logically equivalent to □ˢ ∞ P (x ∷ xs).
□ˢ-cycle⇔ :
∀ {a p} {A : Type a} {P : Size → A → Type p} {x : A} {xs} →
(∀ {i x} → P ∞ x → P i x) →
□ˢ ∞ P (cycle x xs) ⇔ □ˢ ∞ P (x ∷ xs)
□ˢ-cycle⇔ {P = P} {x} {xs} ∞→ = record
{ to = □ˢ-cycle→
; from = □ˢ ∞ P (x ∷ xs) ↝⟨ (λ hyp → from hyp hyp) ⟩
□ˢ ∞ P ((x ∷ xs) ++ cycle x xs) ↝⟨ (λ { (p ∷ ps) → p ∷ ps }) ⟩□
□ˢ ∞ P (cycle x xs) □
}
where
from : ∀ {i ys} →
□ˢ ∞ P (x ∷ xs) → □ˢ i P ys → □ˢ i P (ys ++ cycle x xs)
from ps (q ∷ qs) = q ∷ λ { .force → from ps (force qs) }
from (p ∷ ps) [] = ∞→ p ∷ λ { .force →
from (p ∷ ps) (force ps) }
|
{
"alphanum_fraction": 0.4370089743,
"avg_line_length": 32.5282828283,
"ext": "agda",
"hexsha": "7e9285cbd8ca0bf834ed7cc513351c8f52664e6f",
"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/Colist.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/Colist.agda",
"max_line_length": 94,
"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/Colist.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": 15003,
"size": 32203
}
|
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary.Transitive where
-- Stdlib imports
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; _≢_; refl)
open import Level using (Level; _⊔_)
open import Function using (flip; _∘_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_,_; _×_; proj₁; proj₂; ∃-syntax)
open import Relation.Unary using (Pred; _∈_)
open import Relation.Binary using (Rel; REL)
open import Relation.Binary using (Transitive)
open import Relation.Binary.Construct.Closure.Transitive using (TransClosure; [_]; _∷_; _∷ʳ_; _++_)
-- Local imports
open import Dodo.Unary.Equality
open import Dodo.Binary.Equality
open import Dodo.Binary.Domain
⁺-flip : {a ℓ : Level} {A : Set a} → {R : Rel A ℓ}
→ {x y : A}
→ TransClosure R x y
→ TransClosure (flip R) y x
⁺-flip [ x∼y ] = [ x∼y ]
⁺-flip (x∼z ∷ z∼⁺y) = ⁺-flip z∼⁺y ∷ʳ x∼z
⁺-map : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b}
→ {R : Rel A ℓ₁} {Q : Rel B ℓ₂}
→ (f : A → B)
→ (map : ∀ {x y : A} → R x y → Q (f x) (f y))
→ {x y : A}
→ TransClosure R x y
→ TransClosure Q (f x) (f y)
⁺-map _ map [ Rxy ] = [ map Rxy ]
⁺-map _ map ( Rxz ∷ R⁺zy ) = map Rxz ∷ ⁺-map _ map R⁺zy
⁺-dom : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ {x y : A}
→ TransClosure R x y
------------------
→ x ∈ dom R
⁺-dom {R = R} [ Rxy ] = take-dom R Rxy
⁺-dom {R = R} ( Rxz ∷ R⁺zy ) = take-dom R Rxz
⁺-codom : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ {x y : A}
→ TransClosure R x y
------------------
→ y ∈ codom R
⁺-codom {R = R} [ Rxy ] = take-codom R Rxy
⁺-codom {R = R} ( Rxz ∷ R⁺zy ) = ⁺-codom R⁺zy
⁺-udrˡ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ {x y : A}
→ TransClosure R x y
------------------
→ x ∈ udr R
⁺-udrˡ = inj₁ ∘ ⁺-dom
⁺-udrʳ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ {x y : A}
→ TransClosure R x y
------------------
→ y ∈ udr R
⁺-udrʳ = inj₂ ∘ ⁺-codom
⁺-predʳ : {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {R : Rel A ℓ₂}
→ (f : ∀ {x y : A} → P x → R x y → P y)
→ {x y : A}
→ TransClosure R x y
→ P x
→ P y
⁺-predʳ f [ Rxy ] Px = f Px Rxy
⁺-predʳ f ( Rxz ∷ R⁺zy ) Px = ⁺-predʳ f R⁺zy (f Px Rxz)
⁺-predˡ : {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {R : Rel A ℓ₂}
→ (f : ∀ {x y : A} → P y → R x y → P x)
→ {x y : A}
→ TransClosure R x y
→ P y
→ P x
⁺-predˡ f [ Rxy ] Px = f Px Rxy
⁺-predˡ f ( Rxz ∷ R⁺zy ) Px = f (⁺-predˡ f R⁺zy Px) Rxz
⁺-lift-predʳ : {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {R : Rel A ℓ₂}
→ (f : ∀ {x y : A} → R x y → P y)
→ {x y : A}
→ TransClosure R x y
→ P y
⁺-lift-predʳ f [ Rxy ] = f Rxy
⁺-lift-predʳ f ( Rxz ∷ R⁺zy ) = ⁺-lift-predʳ f R⁺zy
⁺-lift-predˡ : {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {R : Rel A ℓ₂}
→ (f : ∀ {x y : A} → R x y → P x)
→ {x y : A}
→ TransClosure R x y
→ P x
⁺-lift-predˡ f [ Rxy ] = f Rxy
⁺-lift-predˡ f ( Rxz ∷ R⁺zy ) = f Rxz
module _ {a ℓ : Level} {A : Set a} {R : Rel A ℓ} where
⁺-idem : TransClosure R ⇔₂ TransClosure (TransClosure R)
⁺-idem = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : TransClosure R ⊆₂' TransClosure (TransClosure R)
⊆-proof _ _ R⁺xy = [ R⁺xy ]
⊇-proof : TransClosure (TransClosure R) ⊆₂' TransClosure R
⊇-proof _ _ [ R⁺xy ] = R⁺xy
⊇-proof _ y ( _∷_ {_} {z} R⁺xz R⁺⁺zy ) = R⁺xz ++ ⊇-proof z y R⁺⁺zy
⁺-join : ∀ {x y : A} → TransClosure (TransClosure R) x y → TransClosure R x y
⁺-join = ⇔₂-apply-⊇₂ ⁺-idem
module _ {a ℓ : Level} {A : Set a} {R : Rel A ℓ} where
⁺-preserves-dom : dom R ⇔₁ dom (TransClosure R)
⁺-preserves-dom = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : dom R ⊆₁' dom (TransClosure R)
⊆-proof x (y , Rxy) = (y , [ Rxy ])
⊇-proof : dom (TransClosure R) ⊆₁' dom R
⊇-proof x (y , R⁺xy) = ⁺-dom R⁺xy
⁺-preserves-codom : codom R ⇔₁ codom (TransClosure R)
⁺-preserves-codom = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : codom R ⊆₁' codom (TransClosure R)
⊆-proof y (x , Rxy) = (x , [ Rxy ])
⊇-proof : codom (TransClosure R) ⊆₁' codom R
⊇-proof y (x , R⁺xy) = ⁺-codom R⁺xy
⁺-preserves-udr : udr R ⇔₁ udr (TransClosure R)
⁺-preserves-udr = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : udr R ⊆₁' udr (TransClosure R)
⊆-proof _ (inj₁ x∈dom) = inj₁ (⇔₁-apply-⊆₁ ⁺-preserves-dom x∈dom)
⊆-proof _ (inj₂ x∈codom) = inj₂ (⇔₁-apply-⊆₁ ⁺-preserves-codom x∈codom)
⊇-proof : udr (TransClosure R) ⊆₁' udr R
⊇-proof _ (inj₁ x∈dom) = inj₁ (⇔₁-apply-⊇₁ ⁺-preserves-dom x∈dom)
⊇-proof _ (inj₂ x∈codom) = inj₂ (⇔₁-apply-⊇₁ ⁺-preserves-codom x∈codom)
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Rel A ℓ₁} {Q : Rel A ℓ₂} where
⁺-preserves-⊆₂ : P ⊆₂ Q → TransClosure P ⊆₂ TransClosure Q
⁺-preserves-⊆₂ P⊆Q = ⊆: lemma
where
lemma : TransClosure P ⊆₂' TransClosure Q
lemma _ _ [ Pxy ] = [ ⊆₂-apply P⊆Q Pxy ]
lemma _ y ( _∷_ {_} {z} Pxz P⁺zy ) = ⊆₂-apply P⊆Q Pxz ∷ lemma z y P⁺zy
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Rel A ℓ₁} {Q : Rel A ℓ₂} where
⁺-preserves-⇔₂ : P ⇔₂ Q → TransClosure P ⇔₂ TransClosure Q
⁺-preserves-⇔₂ = ⇔₂-compose ⁺-preserves-⊆₂ ⁺-preserves-⊆₂
module _ {a ℓ : Level} {A : Set a} {R : Rel A ℓ} where
⁺-trans-⇔₂ : Transitive R → R ⇔₂ TransClosure R
⁺-trans-⇔₂ transR = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : R ⊆₂' TransClosure R
⊆-proof _ _ = [_]
⊇-proof : TransClosure R ⊆₂' R
⊇-proof _ _ [ Rxy ] = Rxy
⊇-proof _ y (_∷_ {_} {w} Rxw R⁺wy) = transR Rxw (⊇-proof w y R⁺wy)
⁺-trans-⊆₂ : Transitive R → TransClosure R ⊆₂ R
⁺-trans-⊆₂ transR = ⇔₂-to-⊇₂ (⁺-trans-⇔₂ transR)
⁺-join-trans : Transitive R → {x y : A} → TransClosure R x y → R x y
⁺-join-trans = ⊆₂-apply ∘ ⁺-trans-⊆₂
⁺-unconsʳ :
{x y : A}
→ TransClosure R x y
→ R x y ⊎ ∃[ z ] (TransClosure R x z × R z y)
⁺-unconsʳ [ Rxy ] = inj₁ Rxy
⁺-unconsʳ ( Rxz ∷ R⁺zy ) with ⁺-unconsʳ R⁺zy
... | inj₁ Rzy = inj₂ (_ , [ Rxz ] , Rzy)
... | inj₂ (v , R⁺zv , Rvy) = inj₂ (v , Rxz ∷ R⁺zv , Rvy)
|
{
"alphanum_fraction": 0.5308207705,
"avg_line_length": 30.7731958763,
"ext": "agda",
"hexsha": "8d900d640ac4d7e13600136824cebe4f51dc4bca",
"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": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Binary/Transitive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"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": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Binary/Transitive.agda",
"max_line_length": 99,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Binary/Transitive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2879,
"size": 5970
}
|
{-# OPTIONS --cubical --safe #-}
module Data.List.Filter where
open import Prelude
open import Data.List
open import Data.List.Membership
open import Data.Sigma.Properties
open import Data.Bool.Properties
open import Data.Fin
module _ {p} {P : A → Type p} where
filter : (P? : ∀ x → Dec (P x)) → List A → List (∃ P)
filter P? = foldr f []
where
f : _ → List (∃ P) → List (∃ P)
f y ys with P? y
... | yes t = (y , t) ∷ ys
... | no _ = ys
filter-preserves : (isPropP : ∀ x → isProp (P x)) (P? : ∀ x → Dec (P x)) (xs : List A) →
(x : A) →
(v : P x) →
(x ∈ xs) →
((x , v) ∈ filter P? xs)
filter-preserves isPropP P? (x ∷ xs) y v (n , y∈xs) with P? x
filter-preserves isPropP P? (x ∷ xs) y v (f0 , y∈xs) | yes t = f0 , ΣProp≡ isPropP y∈xs
filter-preserves isPropP P? (x ∷ xs) y v (fs n , y∈xs) | yes t = let m , q = filter-preserves isPropP P? xs y v (n , y∈xs) in fs m , q
filter-preserves isPropP P? (x ∷ xs) y v (f0 , y∈xs) | no ¬t = ⊥-elim (¬t (subst P (sym y∈xs) v))
filter-preserves isPropP P? (x ∷ xs) y v (fs n , y∈xs) | no ¬t = filter-preserves isPropP P? xs y v (n , y∈xs)
|
{
"alphanum_fraction": 0.5252692626,
"avg_line_length": 38.935483871,
"ext": "agda",
"hexsha": "dc10e2cc4797d9f635b1730e42080cfcc64d46e4",
"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": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/List/Filter.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"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/combinatorics-paper",
"max_issues_repo_path": "agda/Data/List/Filter.agda",
"max_line_length": 136,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/List/Filter.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 464,
"size": 1207
}
|
open import FRP.JS.Nat using ( ℕ ; float ) renaming
( _+_ to _+n_ ; _∸_ to _∸n_ ; _*_ to _*n_ ; _≟_ to _≟n_ ; _≠_ to _≠n_
; _/_ to _/n_ ; _/?_ to _/?n_ ; _≤_ to _≤n_ ; _<_ to _<n_ )
open import FRP.JS.Float using ( ℝ )
open import FRP.JS.Bool using ( Bool )
open import FRP.JS.True using ( True )
open import FRP.JS.Maybe using ( Maybe )
module FRP.JS.Delay where
record Delay : Set where
constructor _ms
field toℕ : ℕ
{-# COMPILED_JS Delay function(x,v) { return v["_ms"](x); } #-}
{-# COMPILED_JS _ms function(d) { return d; } #-}
_≟_ : Delay → Delay → Bool
(d ms) ≟ (e ms) = d ≟n e
{-# COMPILED_JS _≟_ function(d) { return function(e) { return d === e; }; } #-}
_≠_ : Delay → Delay → Bool
(d ms) ≠ (e ms) = d ≠n e
{-# COMPILED_JS _≠_ function(d) { return function(e) { return d !== e; }; } #-}
_≤_ : Delay → Delay → Bool
(d ms) ≤ (e ms) = d ≤n e
{-# COMPILED_JS _≤_ function(d) { return function(e) { return d <= e; }; } #-}
_<_ : Delay → Delay → Bool
(d ms) < (e ms) = d <n e
{-# COMPILED_JS _<_ function(d) { return function(e) { return d < e; }; } #-}
_+_ : Delay → Delay → Delay
(d ms) + (e ms) = (d +n e) ms
{-# COMPILED_JS _+_ function(d) { return function(e) { return d + e; }; } #-}
_∸_ : Delay → Delay → Delay
(d ms) ∸ (e ms) = (d ∸n e) ms
{-# COMPILED_JS _∸_ function(d) { return function(e) { return Math.min(0, d - e); }; } #-}
_*_ : ℕ → Delay → Delay
n * (d ms) = (n *n d) ms
{-# COMPILED_JS _*_ function(n) { return function(d) { return n * d; }; } #-}
_/_ : ∀ (d e : Delay) → {e≠0 : True (e ≠ 0 ms)} → ℝ
_/_ (d ms) (e ms) {e≠0} = _/n_ d e {e≠0}
{-# COMPILED_JS _/_ function(d) { return function(e) { return function() { return d / e; }; }; } #-}
_/?_ : Delay → Delay → Maybe ℝ
(d ms) /? (e ms) = d /?n e
{-# COMPILED_JS _/?_ function(d) { return function(e) { if (e === 0) { return null; } else { return d / e; } }; } #-}
_sec : ℕ → Delay
n sec = n * (1000 ms)
{-# COMPILED_JS _sec function(t) { return t * 1000; } #-}
_min : ℕ → Delay
n min = n * (60000 ms)
{-# COMPILED_JS _min function(t) { return t * 60000; } #-}
|
{
"alphanum_fraction": 0.552173913,
"avg_line_length": 28.75,
"ext": "agda",
"hexsha": "a236a0364b1773a585b5d375064b49dd895f6764",
"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": "src/agda/FRP/JS/Delay.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": "src/agda/FRP/JS/Delay.agda",
"max_line_length": 117,
"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": "src/agda/FRP/JS/Delay.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": 797,
"size": 2070
}
|
-- This variant of the code is due to Ulf Norell.
open import Agda.Builtin.Size
data ⊥ : Set where
mutual
data Unit (i : Size) : Set where
c : Unit′ i → Unit i
data Unit₁ (i : Size) : Set where
c₁ : ⊥ → Unit i → Unit₁ i
record Unit′ (i : Size) : Set where
coinductive
field
force : {j : Size< i} → Unit₁ j
open Unit′ public
tail : Unit ∞ → Unit₁ ∞
tail (c x) = force x
u : (∀ {i} → Unit′ i → Unit i) →
∀ {i} → Unit₁ i
u cons = tail (cons λ { .force → u cons })
bad : Unit₁ ∞
bad = u c
refute : Unit₁ ∞ → ⊥
refute (c₁ () _)
loop : ⊥
loop = refute bad
|
{
"alphanum_fraction": 0.5622895623,
"avg_line_length": 16.0540540541,
"ext": "agda",
"hexsha": "2efc0c7cc5bc8e9e6c621ef521ab2e5a24bdad7e",
"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/Issue2985-2.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2985-2.agda",
"max_line_length": 49,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2985-2.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 225,
"size": 594
}
|
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core
module Definitions
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality
where
open import Algebra.Core
open import Data.Product
open import Algebra.Definitions
Alternativeˡ : Op₂ A → Set _
Alternativeˡ _∙_ = ∀ x y → ((x ∙ x) ∙ y) ≈ (x ∙ (y ∙ y))
Alternativeʳ : Op₂ A → Set _
Alternativeʳ _∙_ = ∀ x y → (x ∙ (y ∙ y)) ≈ ((x ∙ y) ∙ y)
Alternative : Op₂ A → Set _
Alternative _∙_ = (Alternativeˡ _∙_ ) × ( Alternativeʳ _∙_)
Flexible : Op₂ A → Set _
Flexible _∙_ = ∀ x y → ((x ∙ y) ∙ x) ≈ (x ∙ (y ∙ x))
Medial : Op₂ A → Set _
Medial _∙_ = ∀ x y u z → ((x ∙ y) ∙ (u ∙ z)) ≈ ((x ∙ u) ∙ (y ∙ z))
LeftSemimedial : Op₂ A → Set _
LeftSemimedial _∙_ = ∀ x y z → ((x ∙ x) ∙ (y ∙ z)) ≈ ((x ∙ y) ∙ (x ∙ z))
RightSemimedial : Op₂ A → Set _
RightSemimedial _∙_ = ∀ x y z → ((y ∙ z) ∙ (x ∙ x)) ≈ ((y ∙ x) ∙ (z ∙ x))
Semimedial : Op₂ A → Set _
Semimedial _∙_ = (LeftSemimedial _∙_) × (RightSemimedial _∙_)
LatinSquare₁ : Op₂ A → Set _
LatinSquare₁ _*_ = ∀ a b x → (a * x) ≈ b
LatinSquare₂ : Op₂ A → Set _
LatinSquare₂ _*_ = ∀ a b y → (y * a) ≈ b
LatinSquare : Op₂ A → Set _
LatinSquare _*_ = (LatinSquare₁ _*_) × (LatinSquare₂ _*_)
LeftBol : Op₂ A → Set _
LeftBol _∙_ = ∀ x y z → (x ∙ (y ∙ (x ∙ z))) ≈ ((x ∙ (y ∙ z)) ∙ z )
RightBol : Op₂ A → Set _
RightBol _∙_ = ∀ x y z → (((z ∙ x) ∙ y) ∙ x) ≈ (z ∙ ((x ∙ y) ∙ x))
MoufangIdentity₁ : Op₂ A → Set _
MoufangIdentity₁ _∙_ = ∀ x y z → (z ∙ (x ∙ (z ∙ y))) ≈ (((z ∙ x) ∙ z) ∙ y)
MoufangIdentity₂ : Op₂ A → Set _
MoufangIdentity₂ _∙_ = ∀ x y z → (x ∙ (z ∙ (y ∙ z))) ≈ (((x ∙ z) ∙ y) ∙ z)
MoufangIdentity₃ : Op₂ A → Set _
MoufangIdentity₃ _∙_ = ∀ x y z → ((z ∙ x) ∙ (y ∙ z)) ≈ ((z ∙ (x ∙ y)) ∙ z)
MoufangIdentity₄ : Op₂ A → Set _
MoufangIdentity₄ _∙_ = ∀ x y z → ((z ∙ x) ∙ (y ∙ z)) ≈ (z ∙ ((x ∙ y) ∙ z))
-- (x²y)x = x²(yx)
JordanIdentity: : Op₂ A → Set _
JordanIdentity: _∙_ = ∀ x y → (((x ∙ x) ∙ y) ∙ x) ≈ (((x ∙ x) ∙ y) ∙ x)
-- x = xyx
PesudoInverse₁ : Op₂ A → Set _
PesudoInverse₁ _∙_ = ∀ x y → ((x ∙ y) ∙ x) ≈ x
-- y = yxy
PseudoInverse₂ : Op₂ A → Set _
PseudoInverse₂ _∙_ = ∀ x y → ((y ∙ x) ∙ y) ≈ y
PseudoInverse : Op₂ A → Set _
PseudoInverse ∙ = (PesudoInverse₁ ∙) × (PseudoInverse₂ ∙)
-- JacobiIdentity is (x ∙ (y ∙ z)) + ((y ∙ (z ∙ x)) + (z ∙ (x ∙ y))) = 0
-- Using the antisymmetry property Jacobi identity may be rewritten as a modification of the associative property
JacobiIdentity : Op₂ A → Op₂ A → Set _
JacobiIdentity _∙_ _-_ = ∀ x y z → (x ∙ (y ∙ z)) ≈ ((y ∙ (z ∙ x)) - (z ∙ (x ∙ y)))
|
{
"alphanum_fraction": 0.5373831776,
"avg_line_length": 30.2117647059,
"ext": "agda",
"hexsha": "28d229bb6f889abfe6628d37172beb8284304026",
"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": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/Agda-Algebra",
"max_forks_repo_path": "src/Definitions.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_issues_repo_issues_event_max_datetime": "2022-01-31T18:19:52.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-02T20:50:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/Agda-Algebra",
"max_issues_repo_path": "src/Definitions.agda",
"max_line_length": 113,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "72030f78934877ad67bf4e36e74e43845cabbf55",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/Agda-Algebra",
"max_stars_repo_path": "src/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1175,
"size": 2568
}
|
-- Andreas, 2014-06-16
data D A : Set where
c : {x : A} → A → D A
f : ∀(A : Set) → D A → Set
f A (c a b) = D A
-- Expected error:
-- The constructor c expects 2 arguments (including hidden ones), but
-- has been given 3 (including hidden ones)
-- when checking that the pattern c a b has type D A
|
{
"alphanum_fraction": 0.6258278146,
"avg_line_length": 23.2307692308,
"ext": "agda",
"hexsha": "1f4bd6f6ec8b79ba1e006168295290334ef91639",
"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/Issue1202.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/Issue1202.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue1202.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": 302
}
|
{-# OPTIONS --without-K #-}
open import HoTT.Base using (𝒰 ; Level ; module variables)
module HoTT.Exercises.Chapter1 where
open variables
module Exercise1 where
open HoTT.Base hiding (_∘_)
_∘_ : {A B C : 𝒰 i} (g : B → C) (f : A → B) → A → C
g ∘ f = λ x → g (f x)
_ : {A B C D : 𝒰 i} {f : A → B} {g : B → C} {h : C → D} →
h ∘ (g ∘ f) == (h ∘ g) ∘ f
_ = refl
module Exercise2 where
open HoTT.Base hiding (×-rec ; Σ-rec)
×-rec : (C : 𝒰 i) → (A → B → C) → A × B → C
×-rec _ g x = g (pr₁ x) (pr₂ x)
_ : {C : 𝒰 i} {g : A → B → C} {a : A} {b : B} →
×-rec C g (a , b) == g a b
_ = refl
Σ-rec : (C : 𝒰 i) → ((x : A) → P x → C) → Σ A P → C
Σ-rec _ g x = g (pr₁ x) (pr₂ x)
_ : {C : 𝒰 i} {g : (x : A) → P x → C} {a : A} {b : P a} →
Σ-rec C g (a , b) == g a b
_ = refl
module Exercise3 where
open HoTT.Base hiding (×-ind ; Σ-ind)
×-ind : {A B : 𝒰 i} (C : A × B → 𝒰 i) →
((a : A) → (b : B) → C (a , b)) → (x : A × B) → C x
×-ind C g x = transport C (×-uniq x) (g (pr₁ x) (pr₂ x))
Σ-ind : {A : 𝒰 i} {B : A → 𝒰 i} (C : Σ A B → 𝒰 i) →
((a : A) → (b : B a) → C (a , b)) → (x : Σ A B) → C x
Σ-ind C g x = transport C (Σ-uniq x) (g (pr₁ x) (pr₂ x))
module Exercise4 where
open HoTT.Base hiding (ℕ-rec)
iter : (C : 𝒰 i) → C → (C → C) → ℕ → C
iter C c₀ cₛ 0 = c₀
iter C c₀ cₛ (succ n) = cₛ (iter C c₀ cₛ n)
f : {C : 𝒰 i} {cₛ : ℕ → C → C} → ℕ × C → ℕ × C
f {cₛ = cₛ} (n , c) = succ n , cₛ n c
iterℕ : (C : 𝒰 i) → C → (ℕ → C → C) → ℕ → ℕ × C
iterℕ C c₀ cₛ n = iter (ℕ × C) (0 , c₀) (f {C = C} {cₛ = cₛ}) n
ℕ-rec : (C : 𝒰 i) → C → (ℕ → C → C) → ℕ → C
ℕ-rec C c₀ cₛ n = pr₂ (iterℕ C c₀ cₛ n)
module _ {C : 𝒰 i} {c₀ : C} {cₛ : ℕ → C → C} where
_ : ℕ-rec C c₀ cₛ 0 == c₀
_ = refl
_ : (n : ℕ) → ℕ-rec C c₀ cₛ (succ n) == cₛ n (ℕ-rec C c₀ cₛ n)
_ = ℕ-ind D d₀ dₛ
where
E : ℕ → 𝒰₀
E n = pr₁ (iterℕ C c₀ cₛ n) == n
e₀ : E 0
e₀ = refl
eₛ : (n : ℕ) → E n → E (succ n)
eₛ n = ×-ind (λ z → pr₁ z == n → pr₁ (f z) == succ n)
(λ _ _ p → ap succ p) (iterℕ C c₀ cₛ n)
D : ℕ → 𝒰 i
D n = ℕ-rec C c₀ cₛ (succ n) == cₛ n (ℕ-rec C c₀ cₛ n)
d₀ : D 0
d₀ = refl
dₛ : (n : ℕ) → D n → D (succ n)
dₛ n _ = ×-ind (λ z → pr₁ z == n → pr₂ (f (f z)) == cₛ (succ n) (pr₂ (f z)))
(λ x y p → ap (λ n → cₛ (succ n) (cₛ x y)) p)
(iterℕ C c₀ cₛ n) (ℕ-ind E e₀ eₛ n)
module Exercise5 where
open HoTT.Base hiding (_+_ ; inl ; inr ; +-ind)
_+_ : 𝒰 i → 𝒰 i → 𝒰 i
_+_ A B = Σ[ x ∶ 𝟐 ] (𝟐-rec A B x)
private variable C : A + B → 𝒰 i
inl : A → A + B
inl a = 0₂ , a
inr : B → A + B
inr b = 1₂ , b
+-ind : (C : A + B → 𝒰 i) → ((a : A) → C (inl a)) → ((b : B) → C (inr b)) →
(x : A + B) → C x
+-ind C g₀ g₁ (0₂ , a) = g₀ a
+-ind C g₀ g₁ (1₂ , b) = g₁ b
_ : {g₀ : (a : A) → C (inl a)} {g₁ : (b : B) → C (inr b)} {a : A} →
+-ind C g₀ g₁ (inl a) == g₀ a
_ = refl
_ : {g₀ : (a : A) → C (inl a)} {g₁ : (b : B) → C (inr b)} {b : B} →
+-ind C g₀ g₁ (inr b) == g₁ b
_ = refl
module Exercise6 where
open HoTT.Base hiding (_×_ ; _,_ ; pr₁ ; pr₂ ; ×-uniq ; ×-ind)
open import HoTT.Identity.Pi
_×_ : 𝒰 i → 𝒰 i → 𝒰 i
_×_ A B = (x : 𝟐) → 𝟐-rec A B x
_,_ : A → B → A × B
_,_ a b = 𝟐-ind _ a b
pr₁ : A × B → A
pr₁ x = x 0₂
pr₂ : A × B → B
pr₂ x = x 1₂
×-uniq : (x : A × B) → pr₁ x , pr₂ x == x
×-uniq x = funext λ b → 𝟐-ind (λ b → (pr₁ x , pr₂ x) b == x b) refl refl b
×-ind : (C : A × B → 𝒰 i) → ((a : A) (b : B) → C (a , b)) → (x : A × B) → C x
×-ind C g x = transport C (×-uniq x) (g (pr₁ x) (pr₂ x))
module _ {C : A × B → 𝒰 i} {g : (a : A) (b : B) → C (a , b)} {a : A} {b : B}
where
_ : ×-ind C g (a , b) == g a b
_ = ap (λ p → transport C p (g a b))
(ap funext (funext (𝟐-ind _ refl refl)) ∙ =Π-η refl)
-- Alternative solution from https://pcapriotti.github.io/hott-exercises/chapter1.ex6.html
{-
×-uniq-compute : (x : A × B) → pr₁ x , pr₂ x == x
×-uniq-compute x = ×-uniq (pr₁ x , pr₂ x) ⁻¹ ∙ ×-uniq x
×-ind' : (C : A × B → 𝒰 i) → ((a : A) (b : B) → C (a , b)) → (x : A × B) → C x
×-ind' C g x = transport C (×-uniq-compute x) (g (pr₁ x) (pr₂ x))
module _ {C : A × B → 𝒰 i} {g : (a : A) (b : B) → C (a , b)} {a : A} {b : B}
where
_ : ×-ind' C g (a , b) == g a b
_ = ap (λ p → transport C p (g a b)) (∙-invₗ (×-uniq (a , b)))
-}
module Exercise7 where
open HoTT.Base hiding (=-ind')
open import HoTT.Identity.Sigma
open import HoTT.Identity
-- TODO: Using Lemma 3.11.8 might simplify this.
=-ind' : (a : A) → (C : (x : A) → a == x → 𝒰 j) →
C a refl → (x : A) → (p : a == x) → C x p
=-ind' {A = A} a C c x p = transport (λ{(x , p) → C x p}) q c
where
D : (x y : A) → x == y → 𝒰 _
D x y p = transport (x ==_) p refl == p
d : (x : A) → D x x refl
d x = refl
q : (a , refl) == (x , p)
q = pair⁼ (p , =-ind D d p)
module Exercise8 where
open HoTT.Base hiding (_+_) renaming (ℕ-rec to rec ; ℕ-ind to ind)
open import HoTT.Identity
_+_ : ℕ → ℕ → ℕ
n + m = rec m (λ _ → succ) n
infix 17 _+_
_*_ : ℕ → ℕ → ℕ
n * m = rec 0 (λ _ x → m + x) n
infix 18 _*_
_^_ : ℕ → ℕ → ℕ
n ^ m = rec 1 (λ _ x → m * x) n
infix 19 _^_
+-assoc : (a b c : ℕ) → (a + b) + c == a + (b + c)
+-assoc a b c = ind D d₀ dₛ a
where
D : ℕ → 𝒰₀
D a = (a + b) + c == a + (b + c)
d₀ : D 0
d₀ = refl
dₛ : (n : ℕ) → D n → D (succ n)
dₛ n p = ap succ p
+-unitₗ : (a : ℕ) → 0 + a == a
+-unitₗ a = refl
+-unitᵣ : (a : ℕ) → a + 0 == a
+-unitᵣ a = ind (λ a → a + 0 == a) refl (λ _ → ap succ) a
+-commute : (a b : ℕ) → a + b == b + a
+-commute = ind D d₀ dₛ
where
D : ℕ → 𝒰₀
D a = (b : ℕ) → a + b == b + a
d₀ : D 0
d₀ b = +-unitₗ b ∙ +-unitᵣ b ⁻¹
dₛ : (n : ℕ) → D n → D (succ n)
dₛ n p b = ap succ (p b) ∙ ind E e₀ eₛ b
where
E : ℕ → 𝒰₀
E b = (succ b) + n == b + (succ n)
e₀ : E 0
e₀ = refl
eₛ : (m : ℕ) → E m → E (succ m)
eₛ m q = ap succ q
*-unitₗ : (a : ℕ) → 1 * a == a
*-unitₗ = +-unitᵣ
*-unitᵣ : (a : ℕ) → a * 1 == a
*-unitᵣ = ind (λ a → a * 1 == a) refl (λ _ → ap succ)
*-distₗ : (a b c : ℕ) → a * (b + c) == a * b + a * c
*-distₗ a b c = ind D d₀ dₛ a
where
D : ℕ → 𝒰₀
D a = a * (b + c) == a * b + a * c
d₀ : D 0
d₀ = refl
dₛ : (a : ℕ) → D a → D (succ a)
dₛ a p =
succ a * (b + c) =⟨⟩
(b + c) + a * (b + c) =⟨ ap ((b + c) +_) p ⟩
(b + c) + (a * b + a * c) =⟨ +-assoc b c (a * b + a * c) ⟩
b + (c + (a * b + a * c)) =⟨ ap (b +_) (+-assoc c (a * b) (a * c) ⁻¹) ⟩
b + ((c + a * b) + a * c) =⟨ ap (λ n → b + (n + a * c)) (+-commute c (a * b)) ⟩
b + ((a * b + c) + a * c) =⟨ ap (b +_) (+-assoc (a * b) c (a * c)) ⟩
b + (a * b + (c + a * c)) =⟨ +-assoc b (a * b) (c + a * c) ⁻¹ ⟩
(b + a * b) + (c + a * c) =⟨⟩
succ a * b + succ a * c ∎
where open =-Reasoning
*-zeroₗ : (a : ℕ) → 0 * a == 0
*-zeroₗ _ = refl
*-zeroᵣ : (a : ℕ) → a * 0 == 0
*-zeroᵣ a = ind (λ n → n * 0 == 0) refl (λ _ p → p) a
*-comm : (a b : ℕ) → a * b == b * a
*-comm a b = ind D d₀ dₛ a
where
D : ℕ → 𝒰₀
D n = n * b == b * n
d₀ : D 0
d₀ = *-zeroᵣ b ⁻¹
dₛ : (n : ℕ) → D n → D (succ n)
dₛ n p = ap (b +_) p ∙ ap (_+ (b * n)) (*-unitᵣ b ⁻¹) ∙ *-distₗ b 1 n ⁻¹
*-distᵣ : (a b c : ℕ) → (a + b) * c == (a * c) + (b * c)
*-distᵣ a b c =
(a + b) * c =⟨ *-comm (a + b) c ⟩
c * (a + b) =⟨ *-distₗ c a b ⟩
c * a + c * b =⟨ ap (_+ (c * b)) (*-comm c a) ⟩
a * c + c * b =⟨ ap ((a * c) +_) (*-comm c b) ⟩
a * c + b * c ∎
where open =-Reasoning
*-assoc : (a b c : ℕ) → (a * b) * c == a * (b * c)
*-assoc a b c = ind D d₀ dₛ a
where
D : ℕ → 𝒰₀
D n = (n * b) * c == n * (b * c)
d₀ : D 0
d₀ = refl
dₛ : (n : ℕ) → D n → D (succ n)
dₛ n p = *-distᵣ b (n * b) c ∙ ap ((b * c) +_) p
module Exercise9 where
open HoTT.Base
Fin : ℕ → 𝒰₀
Fin n = ℕ-rec 𝟎 (λ _ A → 𝟏 + A) n
fmax : (n : ℕ) → Fin (succ n)
fmax = ℕ-ind (Fin ∘ succ) (inl ★) (λ _ → inr)
module Exercise10 where
open HoTT.Base
ack : ℕ → ℕ → ℕ
ack m n = ℕ-rec succ cₛ m n
where
cₛ : ℕ → (ℕ → ℕ) → ℕ → ℕ
cₛ m c n = c (ℕ-rec 1 (λ _ → c) n)
module Exercise11 where
open HoTT.Base
_ : ¬ ¬ ¬ A → ¬ A
_ = λ f a → f (λ g → g a)
module Exercise12 where
open HoTT.Base
_ : A → B → A
_ = λ a _ → a
_ : A → ¬ ¬ A
_ = λ a f → f a
_ : ¬ A + ¬ B → ¬ (A × B)
_ = λ x y → +-rec (λ f → 𝟎-rec (f (pr₁ y))) (λ f → 𝟎-rec (f (pr₂ y))) x
module Exercise13 where
open HoTT.Base
_ : ¬ ¬ (A + ¬ A)
_ = λ f → f (inr (f ∘ inl))
module Exercise14 where
-- For induction, we must have a function C : (s : A) → (t : A) → (q : s == t) → 𝒰.
-- Since q : s == t, the equality type q == refl {s} does not make sense because
-- we are trying to equate elements of two different types.
module Exercise15 {C : A → 𝒰 i} where
open HoTT.Base using (_==_ ; refl ; =-ind ; id)
_ : {x y : A} → (p : x == y) → C x → C y
_ = =-ind D d
where
D : (x y : A) → x == y → 𝒰 _
D x y p = C x → C y
d : (x : A) → D x x refl
d _ = id
module Exercise16 where
-- This is just a subset of Exercise8. See +-commute above.
|
{
"alphanum_fraction": 0.414581997,
"avg_line_length": 27.1918604651,
"ext": "agda",
"hexsha": "61560ee9979c8f6bc933d4c8cccd5798bc834140",
"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": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Exercises/Chapter1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"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": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Exercises/Chapter1.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Exercises/Chapter1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4641,
"size": 9354
}
|
{-# OPTIONS --without-K #-}
module decidable where
open import level using (Level)
open import sets.empty using (⊥; ¬_)
open import sets.unit using (⊤; tt)
-- Decidable relations.
data Dec {i} (P : Set i) : Set i where
yes : ( p : P) → Dec P
no : (¬p : ¬ P) → Dec P
True : ∀ {i}{P : Set i} → Dec P → Set
True (yes _) = ⊤
True (no _) = ⊥
witness : ∀ {i}{P : Set i}{d : Dec P} → True d → P
witness {d = yes x} _ = x
witness {d = no _} ()
decide : ∀ {i} {P : Set i} {d : Dec P} → P → True d
decide {d = yes p} = λ _ → tt
decide {d = no f} = f
|
{
"alphanum_fraction": 0.5351351351,
"avg_line_length": 21.3461538462,
"ext": "agda",
"hexsha": "70539bc8e1f05928d40dc8163593db471169e081",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "decidable.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "decidable.agda",
"max_line_length": 51,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "decidable.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 219,
"size": 555
}
|
{-
This file contains a summary of the proofs that π₄(S³) ≡ ℤ/2ℤ
- The first proof "π₄S³≃ℤ/2ℤ" closely follows Brunerie's thesis.
- The second proof "π₄S³≃ℤ/2ℤ-direct" is much more direct and avoids
all of the more advanced constructions in chapters 4-6 in Brunerie's
thesis.
- The third proof "π₄S³≃ℤ/2ℤ-computation" uses ideas from the direct
proof to define an alternative Brunerie number which computes to -2
in a few seconds and the main result is hence obtained by computation
as conjectured on page 85 of Brunerie's thesis.
The --experimental-lossy-unification flag is used to speed up type checking.
The file still type checks without it, but it's a lot slower (about 10 times).
-}
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Group.Pi4S3.Summary where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Data.Nat.Base
open import Cubical.Data.Int.Base
open import Cubical.Data.Sigma.Base
open import Cubical.HITs.Sn
open import Cubical.HITs.SetTruncation
open import Cubical.Homotopy.HopfInvariant.Base
open import Cubical.Homotopy.HopfInvariant.Homomorphism
open import Cubical.Homotopy.HopfInvariant.HopfMap
open import Cubical.Homotopy.HopfInvariant.Brunerie
open import Cubical.Homotopy.Whitehead
open import Cubical.Homotopy.Group.Base hiding (π)
open import Cubical.Homotopy.Group.Pi3S2
open import Cubical.Homotopy.Group.Pi4S3.BrunerieNumber
open import Cubical.Homotopy.Group.Pi4S3.DirectProof as DirectProof
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Instances.Bool
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.GroupPath
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.Algebra.Group.Instances.IntMod
open import Cubical.Algebra.Group.ZAction
-- Homotopy groups (shifted version of π'Gr to get nicer numbering)
π : ℕ → Pointed₀ → Group₀
π n X = π'Gr (predℕ n) X
-- Nicer notation for the spheres (as pointed types)
𝕊² 𝕊³ : Pointed₀
𝕊² = S₊∙ 2
𝕊³ = S₊∙ 3
-- The Brunerie number; defined in Cubical.Homotopy.Group.Pi4S3.BrunerieNumber
-- as "abs (HopfInvariant-π' 0 ([ (∣ idfun∙ _ ∣₂ , ∣ idfun∙ _ ∣₂) ]×))"
β : ℕ
β = Brunerie
-- The connection to π₄(S³) is then also proved in the BrunerieNumber
-- file following Corollary 3.4.5 in Guillaume Brunerie's PhD thesis.
βSpec : GroupEquiv (π 4 𝕊³) (ℤGroup/ β)
βSpec = BrunerieIso
-- Ideally one could prove that β is 2 by normalization, but this does
-- not seem to terminate before we run out of memory. To try normalize
-- this use "C-u C-c C-n β≡2" (which normalizes the term, ignoring
-- abstract's). So instead we prove this by hand as in the second half
-- of Guillaume's thesis.
β≡2 : β ≡ 2
β≡2 = Brunerie≡2
-- This involves a lot of theory, for example that π₃(S²) ≃ ℤGroup where
-- the underlying map is induced by the Hopf invariant (which involves
-- the cup product on cohomology).
_ : GroupEquiv (π 3 𝕊²) ℤGroup
_ = hopfInvariantEquiv
-- Which is a consequence of the fact that π₃(S²) is generated by the
-- Hopf map.
_ : gen₁-by (π 3 𝕊²) ∣ HopfMap ∣₂
_ = π₂S³-gen-by-HopfMap
-- etc. For more details see the proof of "Brunerie≡2".
-- Combining all of this gives us the desired equivalence of groups:
π₄S³≃ℤ/2ℤ : GroupEquiv (π 4 𝕊³) (ℤGroup/ 2)
π₄S³≃ℤ/2ℤ = subst (GroupEquiv (π 4 𝕊³)) (cong ℤGroup/_ β≡2) βSpec
-- By the SIP this induces an equality of groups:
π₄S³≡ℤ/2ℤ : π 4 𝕊³ ≡ ℤGroup/ 2
π₄S³≡ℤ/2ℤ = GroupPath _ _ .fst π₄S³≃ℤ/2ℤ
-- As a sanity check we also establish the equality with Bool:
π₄S³≡Bool : π 4 𝕊³ ≡ BoolGroup
π₄S³≡Bool = π₄S³≡ℤ/2ℤ ∙ GroupPath _ _ .fst (GroupIso→GroupEquiv ℤGroup/2≅Bool)
-- We also have a much more direct proof in Cubical.Homotopy.Group.Pi4S3.DirectProof,
-- not relying on any of the more advanced constructions in chapters
-- 4-6 in Brunerie's thesis (but still using chapters 1-3 for the
-- construction). For details see the header of that file.
π₄S³≃ℤ/2ℤ-direct : GroupEquiv (π 4 𝕊³) (ℤGroup/ 2)
π₄S³≃ℤ/2ℤ-direct = DirectProof.BrunerieGroupEquiv
-- This direct proof allows us to define a much simplified version of
-- the Brunerie number:
β' : ℤ
β' = fst DirectProof.computer η₃'
-- This number computes definitionally to -2 in a few seconds!
β'≡-2 : β' ≡ -2
β'≡-2 = refl
-- As a sanity check we have proved (commented as typechecking is quite slow):
-- β'Spec : GroupEquiv (π 4 𝕊³) (ℤGroup/ abs β')
-- β'Spec = DirectProof.BrunerieGroupEquiv'
-- Combining all of this gives us the desired equivalence of groups by
-- computation as conjectured in Brunerie's thesis:
π₄S³≃ℤ/2ℤ-computation : GroupEquiv (π 4 𝕊³) (ℤGroup/ 2)
π₄S³≃ℤ/2ℤ-computation = DirectProof.BrunerieGroupEquiv''
|
{
"alphanum_fraction": 0.7527287993,
"avg_line_length": 34.0285714286,
"ext": "agda",
"hexsha": "64c0a1896e3e72b26b60d0307322569991cf68fa",
"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/Homotopy/Group/Pi4S3/Summary.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/Homotopy/Group/Pi4S3/Summary.agda",
"max_line_length": 85,
"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/Homotopy/Group/Pi4S3/Summary.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": 1622,
"size": 4764
}
|
-- 2010-10-02
-- termination checker now recognizes projections
module Issue334 where
data Functor : Set₁ where
|Id| : Functor
_|x|_ : Functor → Functor → Functor
record _×_ (A B : Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B
[_] : Functor → Set → Set
[ |Id| ] X = X
[ F |x| G ] X = [ F ] X × [ G ] X
data µ_ (F : Functor) : Set where
<_> : [ F ] (µ F) → µ F
mapFold : ∀ {X} F G → ([ G ] X → X) → [ F ] (µ G) → [ F ] X
mapFold |Id| G φ < x > = φ (mapFold G G φ x)
mapFold (F1 |x| F2 ) G φ (x , y) = mapFold F1 G φ x , mapFold F2 G φ y
-- after record pattern translation, this becomes
-- mapFold (F1 |x| F2) G φ r = mapFold F1 G φ (proj₁ r) , mapFold F2 G φ (proj₂ r)
-- foetus now honors proj₁ p <= p
|
{
"alphanum_fraction": 0.5548216645,
"avg_line_length": 26.1034482759,
"ext": "agda",
"hexsha": "2c4c642b7ddb831b40806b2b085327eb21ec2164",
"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": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue334.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/succeed/Issue334.agda",
"max_line_length": 82,
"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/succeed/Issue334.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": 295,
"size": 757
}
|
{-
Computer Aided Formal Reasoning (G53CFR, G54CFR)
Thorsten Altenkirch
Lecture 2: A first taste of Agda
In this lecture we start to explore the Agda system, a functional
programming language based on Type Theory. We start with some
ordinary examples which we could have developed in Haskell as well.
-}
module l02 where
-- module myNat where
{- Agda has no automatically loaded prelude. Hence we can start from
scratch and define the natural numbers. Later we will use the
standard libray. -}
data ℕ : Set where -- to type ℕ we type \bn
zero : ℕ
suc : (m : ℕ) → ℕ -- \-> or \to
{- To process an Agda file we use C-c C-c from emacs. Once Agda has
checked the file the type checker also colours the different
symbols. -}
{- We define addition. Note Agda's syntax for mixfix operations. The
arguments are represented by _s -}
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
{- Try to evaluate: (suc (suc zero)) + (suc (suc zero))
by typing in C-c C-n -}
{- Better we import the library definition of ℕ
This way we can type 2 instead of (suc (suc zero))
-}
-- open import Data.Nat
{- We define Lists : -}
data List (A : Set) : Set where
[] : List A
_∷_ : (a : A) → (as : List A) → List A
{- In future we'll use
open import Data.List -}
{- declare the fixity of ∷ (type \::) -}
infixr 5 _∷_
{- Two example lists -}
{-
l1 : List ℕ
l1 = 1 ∷ 2 ∷ 3 ∷ []
l2 : List ℕ
l2 = 4 ∷ 5 ∷ []
-}
{- implementing append (++) -}
_++_ : {A : Set} → List A → List A → List A
[] ++ bs = bs
(a ∷ as) ++ bs = a ∷ (as ++ bs)
{- Note that Agda checks wether a function is terminating.
If we type
(a ∷ as) ++ bs = (a ∷ as) ++ bs
in the 2nd line Agda will complain by coloring the offending
function calls in red.
-}
{- What does the following variant of ++ do ? -}
_++'_ : {A : Set} → List A → List A → List A
as ++' [] = as
as ++' (b ∷ bs) = (b ∷ as) ++' bs
{- Indeed it can be used to define reverse. This way to implement
reverse is often called fast reverse because it is "tail recursive"
which leads to a more efficient execution than the naive
implementation. -}
rev : {A : Set} → List A → List A
rev as = [] ++' as
{- We tried to define a function which accesses the nth element of a list:
_!!_ : {A : Set} → List A → ℕ → A
[] !! n = {!!}
(a ∷ as) !! zero = a
(a ∷ as) !! suc n = as !! n
but there is no way to complete the first line (consider what happens
if A is the empty type!
-}
{- To fix this we handle errors explicitely, using Maybe -}
-- open import Data.Maybe
data Maybe (A : Set) : Set where
just : (x : A) → Maybe A
nothing : Maybe A
{- This version of the function can either return an element of the list
(just a) or an error (nothing).
-}
_!!_ : {A : Set} → List A → ℕ → Maybe A
[] !! n = nothing
(a ∷ as) !! zero = just a
(a ∷ as) !! suc n = as !! n
|
{
"alphanum_fraction": 0.6085164835,
"avg_line_length": 24.2666666667,
"ext": "agda",
"hexsha": "cb61f43baa8e6c9169b9a890009372a7cc2bad7c",
"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": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/l02.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"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": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/l02.agda",
"max_line_length": 74,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/l02.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 924,
"size": 2912
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.