Search is not available for this dataset
text
string | meta
dict |
---|---|
module #12 where
{-
Using the propositions as types interpretation, derive the following tautologies.
(i) If A, then (if B then A).
(ii) If A, then not (not A).
(iii) If (not A or not B), then not (A and B).
-}
open import Data.Product
open import Data.Sum
open import Relation.Nullary
const : {A B : Set} → A → (B → A)
const = λ z _ → z
double-negation : {A : Set} → A → ¬ (¬ A)
double-negation = λ z z₁ → z₁ z
demorgans-law₁ : {A B C : Set} → ((¬ A) ⊎ (¬ B)) → (¬ (A × B))
demorgans-law₁ (inj₁ ¬x) (a , _) = ¬x a
demorgans-law₁ (inj₂ ¬y) (_ , b) = ¬y b
|
{
"alphanum_fraction": 0.5877192982,
"avg_line_length": 24.7826086957,
"ext": "agda",
"hexsha": "d99a9794dd73ee73b466763a7a19f9ba124f429a",
"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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Chapter1/#12.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"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": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Chapter1/#12.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Chapter1/#12.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 218,
"size": 570
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Induction over Fin
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Induction where
open import Data.Nat.Base using (ℕ)
open import Data.Nat.Induction using (<′-wellFounded)
open import Data.Fin.Base using (_≺_)
open import Data.Fin.Properties
open import Induction
open import Induction.WellFounded as WF
------------------------------------------------------------------------
-- Re-export accessability
open WF public using (Acc; acc)
------------------------------------------------------------------------
-- Complete induction based on _≺_
≺-Rec : ∀ {ℓ} → RecStruct ℕ ℓ ℓ
≺-Rec = WfRec _≺_
≺-wellFounded : WellFounded _≺_
≺-wellFounded = Subrelation.wellFounded ≺⇒<′ <′-wellFounded
module _ {ℓ} where
open WF.All ≺-wellFounded ℓ public
renaming
( wfRecBuilder to ≺-recBuilder
; wfRec to ≺-rec
)
hiding (wfRec-builder)
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
≺-rec-builder = ≺-recBuilder
{-# WARNING_ON_USAGE ≺-rec-builder
"Warning: ≺-rec-builder was deprecated in v0.15.
Please use ≺-recBuilder instead."
#-}
≺-well-founded = ≺-wellFounded
{-# WARNING_ON_USAGE ≺-well-founded
"Warning: ≺-well-founded was deprecated in v0.15.
Please use ≺-wellFounded instead."
#-}
|
{
"alphanum_fraction": 0.5140931373,
"avg_line_length": 28.1379310345,
"ext": "agda",
"hexsha": "9a00091f0a70a57d3e3c27d78e57d08473a6d707",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Fin/Induction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Fin/Induction.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Fin/Induction.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": 382,
"size": 1632
}
|
{-# OPTIONS --type-in-type #-}
module TooFewArgs where
open import AgdaPrelude
myFun : (a : Set) -> a -> a -> a
myFun a x y = x
myApp : Nat
myApp = myFun _ Zero
|
{
"alphanum_fraction": 0.6242424242,
"avg_line_length": 15,
"ext": "agda",
"hexsha": "c0b2cb7037a379b2c985b8bcac319b3e652fdd68",
"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": "64a1b4c6632153d75cba540f7c91f40b49375e2f",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "JoeyEremondi/lambda-pi-constraint",
"max_forks_repo_path": "thesisExamples/TooFewArgs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "64a1b4c6632153d75cba540f7c91f40b49375e2f",
"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": "JoeyEremondi/lambda-pi-constraint",
"max_issues_repo_path": "thesisExamples/TooFewArgs.agda",
"max_line_length": 32,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "64a1b4c6632153d75cba540f7c91f40b49375e2f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "JoeyEremondi/lambda-pi-constraint",
"max_stars_repo_path": "thesisExamples/TooFewArgs.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-05T20:21:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-16T11:14:56.000Z",
"num_tokens": 57,
"size": 165
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Closed {o ℓ e} (C : Category o ℓ e) where
private
module C = Category C
open C
variable
A B X X′ Y Y′ Z Z′ U V : Obj
f g : A ⇒ B
open Commutation
open import Level
open import Data.Product using (Σ; _,_)
open import Function.Equality using (_⟶_)
open import Function.Inverse using (_InverseOf_; Inverse)
open import Categories.Category.Product
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Bifunctor
open import Categories.Functor.Construction.Constant
open import Categories.NaturalTransformation
open import Categories.NaturalTransformation.NaturalIsomorphism
open import Categories.NaturalTransformation.Dinatural
record Closed : Set (levelOfTerm C) where
field
-- internal hom
[-,-] : Bifunctor C.op C C
unit : Obj
[_,-] : Obj → Functor C C
[_,-] = appˡ [-,-]
[-,_] : Obj → Functor C.op C
[-,_] = appʳ [-,-]
module [-,-] = Functor [-,-]
[_,_]₀ : Obj → Obj → Obj
[ X , Y ]₀ = [-,-].F₀ (X , Y)
[_,_]₁ : A ⇒ B → X ⇒ Y → [ B , X ]₀ ⇒ [ A , Y ]₀
[ f , g ]₁ = [-,-].F₁ (f , g)
field
-- i
identity : NaturalIsomorphism idF [ unit ,-]
-- j
diagonal : Extranaturalʳ unit [-,-]
module identity = NaturalIsomorphism identity
module diagonal = DinaturalTransformation diagonal
[[X,-],[X,-]] : Obj → Bifunctor C.op C C
[[X,-],[X,-]] X = [-,-] ∘F (Functor.op [ X ,-] ⁂ [ X ,-])
[[-,Y],[-,Z]] : Obj → Obj → Bifunctor C C.op C
[[-,Y],[-,Z]] Y Z = [-,-] ∘F ((Functor.op [-, Y ]) ⁂ [-, Z ])
-- L needs to be natural in Y and Z while extranatural in Z.
-- it is better to spell out the conditions and then prove that indeed
-- the naturality conditions hold.
field
L : ∀ X Y Z → [ Y , Z ]₀ ⇒ [ [ X , Y ]₀ , [ X , Z ]₀ ]₀
L-natural-comm : [ [ Y , Z ]₀ ⇒ [ [ X , Y′ ]₀ , [ X , Z′ ]₀ ]₀ ]⟨
[ f , g ]₁ ⇒⟨ [ Y′ , Z′ ]₀ ⟩
L X Y′ Z′
≈ L X Y Z ⇒⟨ [ [ X , Y ]₀ , [ X , Z ]₀ ]₀ ⟩
[ [ C.id , f ]₁ , [ C.id , g ]₁ ]₁
⟩
L-dinatural-comm : [ [ Y , Z ]₀ ⇒ [ [ X , Y ]₀ , [ X′ , Z ]₀ ]₀ ]⟨
L X′ Y Z ⇒⟨ [ [ X′ , Y ]₀ , [ X′ , Z ]₀ ]₀ ⟩
[ [ f , C.id ]₁ , [ C.id , C.id ]₁ ]₁
≈ L X Y Z ⇒⟨ [ [ X , Y ]₀ , [ X , Z ]₀ ]₀ ⟩
[ [ C.id , C.id ]₁ , [ f , C.id ]₁ ]₁
⟩
L-natural : NaturalTransformation [-,-] ([[X,-],[X,-]] X)
L-natural {X} = ntHelper record
{ η = λ where
(Y , Z) → L X Y Z
; commute = λ _ → L-natural-comm
}
L-dinatural : Extranaturalʳ [ Y , Z ]₀ (flip-bifunctor ([[-,Y],[-,Z]] Y Z))
L-dinatural {Y} {Z} = extranaturalʳ (λ X → L X Y Z) L-dinatural-comm
module L-natural {X} = NaturalTransformation (L-natural {X})
module L-dinatural {Y Z} = DinaturalTransformation (L-dinatural {Y} {Z})
-- other required diagrams
field
Lj≈j : [ unit ⇒ [ [ X , Y ]₀ , [ X , Y ]₀ ]₀ ]⟨
diagonal.α Y ⇒⟨ [ Y , Y ]₀ ⟩
L X Y Y
≈ diagonal.α [ X , Y ]₀
⟩
jL≈i : [ [ X , Y ]₀ ⇒ [ unit , [ X , Y ]₀ ]₀ ]⟨
L X X Y ⇒⟨ [ [ X , X ]₀ , [ X , Y ]₀ ]₀ ⟩
[ diagonal.α X , C.id ]₁
≈ identity.⇒.η [ X , Y ]₀
⟩
iL≈i : [ [ Y , Z ]₀ ⇒ [ Y , [ unit , Z ]₀ ]₀ ]⟨
L unit Y Z ⇒⟨ [ [ unit , Y ]₀ , [ unit , Z ]₀ ]₀ ⟩
[ identity.⇒.η Y , C.id ]₁
≈ [ C.id , identity.⇒.η Z ]₁
⟩
pentagon : [ [ U , V ]₀ ⇒ [ [ Y , U ]₀ , [ [ X , Y ]₀ , [ X , V ]₀ ]₀ ]₀ ]⟨
L X U V ⇒⟨ [ [ X , U ]₀ , [ X , V ]₀ ]₀ ⟩
L [ X , Y ]₀ [ X , U ]₀ [ X , V ]₀ ⇒⟨ [ [ [ X , Y ]₀ , [ X , U ]₀ ]₀ , [ [ X , Y ]₀ , [ X , V ]₀ ]₀ ]₀ ⟩
[ L X Y U , C.id ]₁
≈ L Y U V ⇒⟨ [ [ Y , U ]₀ , [ Y , V ]₀ ]₀ ⟩
[ C.id , L X Y V ]₁
⟩
open Functor
γ : hom-setoid {X} {Y} ⟶ hom-setoid {unit} {[ X , Y ]₀}
γ {X} = record
{ _⟨$⟩_ = λ f → [ C.id , f ]₁ ∘ diagonal.α _
; cong = λ eq → ∘-resp-≈ˡ (F-resp-≈ [ X ,-] eq)
}
field
γ⁻¹ : hom-setoid {unit} {[ X , Y ]₀} ⟶ hom-setoid {X} {Y}
γ-inverseOf-γ⁻¹ : γ {X} {Y} InverseOf γ⁻¹
γ-inverse : Inverse (hom-setoid {unit} {[ X , Y ]₀}) (hom-setoid {X} {Y})
γ-inverse = record
{ to = γ⁻¹
; from = γ
; inverse-of = γ-inverseOf-γ⁻¹
}
|
{
"alphanum_fraction": 0.4219075385,
"avg_line_length": 34.5467625899,
"ext": "agda",
"hexsha": "ae2a44107ad946c7f955cd84b9ecb867b52852be",
"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/Category/Closed.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/Category/Closed.agda",
"max_line_length": 121,
"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/Category/Closed.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1716,
"size": 4802
}
|
{-# OPTIONS --prop --rewriting #-}
module Examples.Gcd.Spec where
open import Calf.CostMonoid
import Calf.CostMonoids as CM
open import Calf CM.ℕ-CostMonoid
open import Calf.Types.Nat
open import Examples.Gcd.Euclid
open import Examples.Gcd.Clocked
open import Data.Nat.DivMod
open import Data.Nat
open import Relation.Binary.PropositionalEquality as P
open import Data.Nat.Properties
open import Data.Product
gcd/clocked≡spec/zero : ∀ k x h → k ≥ gcd/depth (x , ℕ.zero , h) →
◯ (gcd/clocked k (x , ℕ.zero , h) ≡ ret {nat} x)
gcd/clocked≡spec/zero ℕ.zero x h h1 u = refl
gcd/clocked≡spec/zero (suc k) x h h1 u = refl
suc-cancel-≤ : ∀ {m n} → suc m ≤ suc n → m ≤ n
suc-cancel-≤ (s≤s h) = h
gcd/clocked/mono : ∀ k x y h → k ≥ gcd/depth (x , y , h) →
gcd/clocked k (x , y , h) ≡ gcd/clocked (suc k) (x , y , h)
gcd/clocked/mono ℕ.zero x ℕ.zero h h1 = refl
gcd/clocked/mono (suc k) x ℕ.zero h h1 = refl
gcd/clocked/mono (suc k) x (suc y) h h1 =
begin
gcd/clocked (suc k) (x , suc y , h) ≡⟨ refl ⟩
step (F nat) 1 (gcd/clocked k (suc y , x % suc y , m%n<n x y)) ≡⟨
P.cong (step (F nat) 1)
(gcd/clocked/mono k (suc y) (x % suc y) (m%n<n x y)
(suc-cancel-≤ (P.subst (λ r → suc k ≥ r) (gcd/depth-unfold-suc {x} {y} {h}) h1))) ⟩
step (F nat) 1 (gcd/clocked (suc k) (suc y , x % suc y , m%n<n x y))
∎
where open ≡-Reasoning
gcd/clocked≡spec/suc : ∀ k x y h → k ≥ gcd/depth (x , suc y , h) →
◯ (gcd/clocked k (x , suc y , h) ≡ gcd/clocked k (suc y , x % suc y , m%n<n x y))
gcd/clocked≡spec/suc (suc k) x y h h1 u =
begin
gcd/clocked (suc k) (x , suc y , h) ≡⟨ refl ⟩
step (F nat) 1 (gcd/clocked k (suc y , x % suc y , m%n<n x y)) ≡⟨ step/ext (F nat) ((gcd/clocked k (suc y , x % suc y , m%n<n x y))) 1 u ⟩
gcd/clocked k (suc y , x % suc y , m%n<n x y) ≡⟨ gcd/clocked/mono k (suc y) (x % suc y) (m%n<n x y)
(suc-cancel-≤ (P.subst (λ r → suc k ≥ r) (gcd/depth-unfold-suc {x} {y} {h}) h1)) ⟩
gcd/clocked (suc k) (suc y , x % suc y , m%n<n x y)
∎
where open ≡-Reasoning
gcd≡spec/zero : ∀ x h → ◯ (gcd (x , 0 , h) ≡ ret {nat} x)
gcd≡spec/zero x h = gcd/clocked≡spec/zero (gcd/depth (x , 0 , h)) x h ≤-refl
gcd≡spec/suc : ∀ x y h → ◯ (gcd (x , suc y , h) ≡ gcd (suc y , x % suc y , m%n<n x y))
gcd≡spec/suc x y h u =
begin
gcd (x , suc y , h) ≡⟨ gcd/clocked≡spec/suc (gcd/depth (x , suc y , h)) x y h ≤-refl u ⟩
gcd/clocked (gcd/depth (x , suc y , h)) (suc y , x % suc y , m%n<n x y) ≡⟨
cong (λ k → gcd/clocked k (suc y , x % suc y , m%n<n x y))
(gcd/depth-unfold-suc {x} {y} {h}) ⟩
gcd/clocked (suc (gcd/depth (suc y , x % suc y , m%n<n x y))) (suc y , x % suc y , m%n<n x y) ≡⟨
sym (gcd/clocked/mono
(gcd/depth (suc y , x % suc y , m%n<n x y)) (suc y) (x % suc y) (m%n<n x y) ≤-refl) ⟩
gcd/clocked (gcd/depth (suc y , x % suc y , m%n<n x y)) (suc y , x % suc y , m%n<n x y)
∎
where open ≡-Reasoning
|
{
"alphanum_fraction": 0.5630800963,
"avg_line_length": 40.9718309859,
"ext": "agda",
"hexsha": "47548b54b78ed1f2c614973bc8a4d21029ced7b3",
"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/Spec.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/Spec.agda",
"max_line_length": 140,
"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/Spec.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": 1264,
"size": 2909
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The free monad construction on indexed containers
------------------------------------------------------------------------
module Data.Container.Indexed.FreeMonad where
open import Level
open import Function hiding (const)
open import Category.Monad.Predicate
open import Data.Container.Indexed hiding (_∈_)
open import Data.Container.Indexed.Combinator hiding (id; _∘_)
open import Data.Empty
open import Data.Sum using (inj₁; inj₂)
open import Data.Product
open import Data.W.Indexed
open import Relation.Unary
open import Relation.Unary.PredicateTransformer
------------------------------------------------------------------------
infixl 9 _⋆C_
infix 9 _⋆_
_⋆C_ : ∀ {i o c r} {I : Set i} {O : Set o} →
Container I O c r → Pred O c → Container I O _ _
C ⋆C X = const X ⊎ C
_⋆_ : ∀ {ℓ} {O : Set ℓ} → Container O O ℓ ℓ → Pt O ℓ
C ⋆ X = μ (C ⋆C X)
pattern returnP x = (inj₁ x , _)
pattern doP c k = (inj₂ c , k)
do : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} {X} →
⟦ C ⟧ (C ⋆ X) ⊆ C ⋆ X
do (c , k) = sup (doP c k)
rawPMonad : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} →
RawPMonad {ℓ = ℓ} (_⋆_ C)
rawPMonad {C = C} = record
{ return? = return
; _=<?_ = _=<<_
}
where
return : ∀ {X} → X ⊆ C ⋆ X
return x = sup (inj₁ x , ⊥-elim ∘ lower)
_=<<_ : ∀ {X Y} → X ⊆ C ⋆ Y → C ⋆ X ⊆ C ⋆ Y
f =<< sup (returnP x) = f x
f =<< sup (doP c k) = do (c , λ r → f =<< k r)
leaf : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} {X : Pred O ℓ} →
⟦ C ⟧ X ⊆ C ⋆ X
leaf (c , k) = do (c , return? ∘ k)
where
open RawPMonad rawPMonad
|
{
"alphanum_fraction": 0.5056581298,
"avg_line_length": 28.4576271186,
"ext": "agda",
"hexsha": "74051bef594aaba7393c6a404fd78e32ef34e702",
"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/Data/Container/Indexed/FreeMonad.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/Data/Container/Indexed/FreeMonad.agda",
"max_line_length": 72,
"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/Data/Container/Indexed/FreeMonad.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": 615,
"size": 1679
}
|
{-# OPTIONS --type-in-type --no-termination-check --no-positivity-check
#-}
module Data1 where
_-_ : {A : Set}{B : A -> Set}{C : (a : A) -> B a -> Set} ->
({a : A}(b : B a) -> C a b) -> (f : (a : A) -> B a) ->
(a : A) -> C a (f a)
f - g = \ x -> f (g x)
id : {X : Set} -> X -> X
id x = x
konst : {S : Set}{T : S -> Set} -> ({x : S} -> T x) -> (x : S) -> T x
konst c x = c
data Zero : Set where
record One : Set where
record Sig (S : Set)(T : S -> Set) : Set where
field
fst : S
snd : T fst
open module Sig' {S : Set}{T : S -> Set} = Sig {S}{T}
_,_ : forall {S T}(s : S) -> T s -> Sig S T
s , t = record {fst = s; snd = t}
infixr 40 _,_
_*_ : Set -> Set -> Set
S * T = Sig S \ _ -> T
sig : forall {S T}{P : Sig S T -> Set} ->
((s : S)(t : T s) -> P (s , t)) -> (st : Sig S T) -> P st
sig f st = f (fst st) (snd st)
data Cx : Set where
E : Cx
_/_ : Cx -> Set -> Cx
data _:>_ : Cx -> Set -> Set where
ze : {G : Cx}{S : Set} -> (G / S) :> S
su : {G : Cx}{S T : Set} -> G :> T -> (G / S) :> T
data PROP : Set where
Absu : PROP
Triv : PROP
_/\_ : PROP -> PROP -> PROP
All : (S : Set) -> (S -> PROP) -> PROP
Prf : PROP -> Set
Prf Absu = Zero
Prf Triv = One
Prf (P /\ Q) = Prf P * Prf Q
Prf (All S P) = (x : S) -> Prf (P x)
data CON (G : Cx) : Set where
?? : {S : Set} -> G :> S -> S -> CON G
PrfC : PROP -> CON G
_*C_ : CON G -> CON G -> CON G
PiC : (S : Set) -> (S -> CON G) -> CON G
SiC : (S : Set) -> (S -> CON G) -> CON G
MuC : (O : Set) -> (O -> CON (G / O)) -> O -> CON G
NuC : (O : Set) -> (O -> CON (G / O)) -> O -> CON G
Box : (G : Cx) -> ((S : Set) -> (G :> S) -> Set) -> Set
Box E F = One
Box (G / S) F = Box G (\ S n -> F S (su n)) * F S ze
pr : {G : Cx}{S : Set}{F : (S : Set) -> (G :> S) -> Set} -> Box G F -> (n : G :> S) -> F S n
pr fsf ze = snd fsf
pr fsf (su n) = pr (fst fsf) n
Pay : Cx -> Set
Pay G = Box G (\ I _ -> I -> Set)
Arr : (G : Cx) -> Pay G -> Pay G -> Set
Arr G X Y = Box G (\ S n -> (s : S) -> pr X n s -> pr Y n s)
mutual
[|_|] : {G : Cx} -> CON G -> Pay G -> Set
[| ?? n i |] X = pr X n i
[| PrfC P |] X = Prf P
[| C *C D |] X = [| C |] X * [| D |] X
[| PiC S C |] X = (s : S) -> [| C s |] X
[| SiC S C |] X = Sig S \ s -> [| C s |] X
[| MuC O C o |] X = Mu C X o
[| NuC O C o |] X = Nu C X o
data Mu {G : Cx}{O : Set}(C : O -> CON (G / O))(X : Pay G)(o : O) : Set where
con : [| C o |] ( X , Mu C X ) -> Mu C X o
codata Nu {G : Cx}{O : Set}(C : O -> CON (G / O))(X : Pay G)(o : O) : Set where
con : [| C o |] ( X , Nu C X ) -> Nu C X o
noc : {G : Cx}{O : Set}{C : O -> CON (G / O)}{X : Pay G}{o : O} ->
Nu C X o -> [| C o |] ( X , Nu C X )
noc (con xs) = xs
mutual
map : {G : Cx}{X Y : Pay G} -> (C : CON G) ->
Arr G X Y ->
[| C |] X -> [| C |] Y
map (?? n i) f = pr f n i
map (PrfC P) f = id
map (C *C D) f = sig \ c d -> map C f c , map D f d
map (PiC S C) f = \ c s -> map (C s) f (c s)
map (SiC S C) f = sig \ s c -> s , map (C s) f c
map (MuC O C o) f = foldMap C (Mu C _) f (\ o -> con) o
map (NuC O C o) f = unfoldMap C (Nu C _) f (\ o -> noc) o
foldMap : {G : Cx}{O : Set}(C : O -> CON (G / O)){X Y : Pay G}(Z : O -> Set) ->
Arr G X Y ->
((o : O) -> [| C o |] ( Y , Z ) -> Z o) ->
(o : O) -> Mu C X o -> Z o
foldMap C Z f alg o (con xs) = alg o (map (C o) (f , foldMap C Z f alg) xs)
unfoldMap : {G : Cx}{O : Set}(C : O -> CON (G / O)){X Y : Pay G}(Z : O -> Set) ->
Arr G X Y ->
((o : O) -> Z o -> [| C o |] ( X , Z )) ->
(o : O) -> Z o -> Nu C Y o
unfoldMap C Z f coalg o y = con (map (C o) (f , unfoldMap C Z f coalg) (coalg o y))
ida : (G : Cx) -> (X : Pay G) -> Arr G X X
ida E = id
ida (G / S) = sig \ Xs X -> ida G Xs , \ s x -> x
compa : (G : Cx) -> (X Y Z : Pay G) -> Arr G Y Z -> Arr G X Y -> Arr G X Z
compa E = \ _ _ _ _ _ -> _
compa (G / S) = sig \ Xs X -> sig \ Ys Y -> sig \ Zs Z -> sig \ fs f -> sig \ gs g ->
compa G Xs Ys Zs fs gs , \ s x -> f s (g s x)
data _==_ {X : Set}(x : X) : {Y : Set} -> Y -> Set where
refl : x == x
subst : {X : Set}{P : X -> Set}{x y : X} -> x == y -> P x -> P y
subst refl p = p
_=,=_ : {S : Set}{T : S -> Set}
{s0 : S}{s1 : S} -> s0 == s1 ->
{t0 : T s0}{t1 : T s1} -> t0 == t1 ->
_==_ {Sig S T} (s0 , t0) {Sig S T} (s1 , t1)
refl =,= refl = refl
mylem : (G : Cx) -> (X : Pay G) -> compa G X X X (ida G X) (ida G X) == ida G X
mylem E X = refl
mylem (G / S) X = mylem G (fst X) =,= refl
claim : (G : Cx){O : Set}(C : O -> CON (G / O))(X : Pay G)
(P : (o : O) -> Mu C X o -> Set) -> (p : (o : O)(y : Mu C X o) -> P o y)
(o : O) ->
compa (G / O) (X , Mu C X) (X , (\ o -> Sig (Mu C X o) (P o))) (X , Mu C X)
(ida G X , konst fst) (ida G X , (\ o y -> (y , p o y)))
== ida (G / O) (X , Mu C X)
claim G C X P p o = mylem G X =,= refl
idLem : {G : Cx}{S : Set}{X : Pay G}(n : G :> S) ->
pr (ida G X) n == (\ (s : S)(x : pr X n s) -> x)
idLem ze = refl
idLem (su y) = idLem y
_=$_ : {S : Set}{T : S -> Set}{f g : (s : S) -> T s} ->
f == g -> (s : S) -> f s == g s
refl =$ s = refl
mutual -- and too intensional
mapId : {G : Cx}{X : Pay G} -> (C : CON G) -> (xs : [| C |] X) ->
map C (ida G X) xs == xs
mapId (?? y y') xs = (idLem y =$ y') =$ xs
mapId (PrfC y) xs = refl
mapId (y *C y') xs = mapId y (fst xs) =,= mapId y' (snd xs)
mapId (PiC S y) xs = {!!} -- no chance
mapId (SiC S y) xs = refl =,= mapId (y (fst xs)) (snd xs)
mapId (MuC O y y') xs = foldMapId y y' xs
mapId (NuC O y y') xs = {!!}
foldMapId : {G : Cx}{O : Set}(C : O -> CON (G / O)){X : Pay G}
(o : O)(z : Mu C X o) ->
foldMap C (Mu C X) (ida G X) (\ o -> con) o z == z
foldMapId C o (con xzs) = {!!} -- close but no banana
mapComp : {G : Cx}{X Y Z : Pay G} (f : Arr G Y Z)(g : Arr G X Y)
(C : CON G) -> (xs : [| C |] X) ->
map C f (map C g xs) == map C (compa G X Y Z f g) xs
mapComp = {!!}
_-=-_ : {X : Set}{x y z : X} -> x == y -> y == z -> x == z
refl -=- refl = refl
induction : {G : Cx}{O : Set}(C : O -> CON (G / O)){X : Pay G}
(P : (o : O) -> Mu C X o -> Set) ->
((o : O)(xyps : [| C o |] (X , (\ o -> Sig (Mu C X o) (P o)))) ->
P o (con (map (C o) (ida G X , konst fst) xyps))) ->
(o : O)(y : Mu C X o) -> P o y
induction {G} C {X} P p o (con xys) =
subst {P = \ xys -> P o (con xys)}{y = xys}
((mapComp
(ida G X , konst fst) (ida G X , (\ o y -> (y , induction C P p o y))) (C o) xys
-=- {!!})
-=- mapId (C o) xys)
(p o (map (C o) (ida G X , (\ o y -> (y , induction C P p o y))) xys))
|
{
"alphanum_fraction": 0.4001180289,
"avg_line_length": 32.7439613527,
"ext": "agda",
"hexsha": "8385e7b94654c6c347b7eeeaf5b10549bcd69a75",
"lang": "Agda",
"max_forks_count": 12,
"max_forks_repo_forks_event_max_datetime": "2022-02-11T01:57:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-08-14T21:36:35.000Z",
"max_forks_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mietek/epigram",
"max_forks_repo_path": "models/Data1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"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": "mietek/epigram",
"max_issues_repo_path": "models/Data1.agda",
"max_line_length": 92,
"max_stars_count": 48,
"max_stars_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mietek/epigram",
"max_stars_repo_path": "models/Data1.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T01:55:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-01-09T17:36:19.000Z",
"num_tokens": 2980,
"size": 6778
}
|
{-# OPTIONS --no-positivity-check #-}
module Generics where
data Zero : Set where
data One : Set where
∙ : One
data _+_ (A B : Set) : Set where
inl : A -> A + B
inr : B -> A + B
data _×_ (A : Set)(B : A -> Set) : Set where
<_,_> : (x : A) -> B x -> A × B
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
data Shape (I : Set) : Set where
ι : Shape I
σ : Shape I -> Shape I
δ : Shape I -> Shape I
data Tel {I : Set} : Shape I -> Set1 where
empty : Tel ι
non-rec : {s : Shape I}(A : Set) -> (A -> Tel s) -> Tel (σ s)
rec : {s : Shape I}(H : Set) -> (H -> I) -> Tel s -> Tel (δ s)
Index : {I : Set}(E : Set){s : Shape I} -> Tel s -> Set
Index E empty = E
Index E (non-rec A f) = (x : A) -> Index E (f x)
Index E (rec H i s) = Index E s
data Con (I E : Set) : Set1 where
con : {s : Shape I}(tel : Tel s) -> Index E tel -> Con I E
infixr 40 _|_
data OP (I E : Set) : Set1 where
∅ : OP I E
_|_ : Con I E -> OP I E -> OP I E
Args-tel : {I : Set}(U : I -> Set){s : Shape I} -> Tel s -> Set
Args-tel U empty = One
Args-tel U (non-rec A s) = A × \a -> Args-tel U (s a)
Args-tel U (rec H i s) = ((x : H) -> U (i x)) × \_ -> Args-tel U s
Args : {I E : Set}(U : I -> Set) -> OP I E -> Set
Args U ∅ = Zero
Args U (con tel _ | γ) = Args-tel U tel + Args U γ
index-tel : {I E : Set}{s : Shape I}(U : I -> Set)(tel : Tel s) -> Index E tel -> Args-tel U tel -> E
index-tel U empty i ∙ = i
index-tel U (non-rec A s) i < a , arg > = index-tel U (s a) (i a) arg
index-tel U (rec H di s) i < d , arg > = index-tel U s i arg
index : {I E : Set}(U : I -> Set)(γ : OP I E) -> Args U γ -> E
index U ∅ ()
index U (con tel i | _) (inl x) = index-tel U tel i x
index U (con _ _ | γ) (inr y) = index U γ y
OPr : Set -> Set1
OPr I = I -> OP I One
data Ur {I : Set}(γ : OPr I)(i : I) : Set where
intror : Args (Ur γ) (γ i) -> Ur γ i
OPg : Set -> Set1
OPg I = OP I I
const-index : {I E : Set}{s : Shape I} -> E -> (tel : Tel s) -> Index E tel
const-index i empty = i
const-index i (non-rec _ s) = \a -> const-index i (s a)
const-index i (rec _ _ s) = const-index i s
ε-shape : {I : Set} -> Shape I -> Shape I
ε-shape ι = σ ι
ε-shape (σ s) = σ (ε-shape s)
ε-shape (δ s) = δ (ε-shape s)
ε-tel : {I : Set}{s : Shape I} -> I -> (tel : Tel s) -> Index I tel -> Tel (ε-shape s)
ε-tel i empty j = non-rec (j == i) \_ -> empty
ε-tel i (non-rec A arg) j = non-rec A \a -> ε-tel i (arg a) (j a)
ε-tel i (rec H di arg) j = rec H di (ε-tel i arg j)
ε-con : {I : Set} -> I -> Con I I -> Con I One
ε-con j (con tel i) = con args' (const-index ∙ args')
where
args' = ε-tel j tel i
ε : {I : Set} -> OPg I -> OPr I
ε ∅ _ = ∅
ε (c | γ) j = ε-con j c | ε γ j
Ug : {I : Set} -> OPg I -> I -> Set
Ug γ = Ur (ε γ)
g→rArgs-tel : {I : Set}(U : I -> Set){s : Shape I}
(tel : Tel s)(i : Index I tel)(arg : Args-tel U tel) ->
Args-tel U (ε-tel (index-tel U tel i arg) tel i)
g→rArgs-tel U empty i ∙ = < refl , ∙ >
g→rArgs-tel U (non-rec A tel) i < a , arg > = < a , g→rArgs-tel U (tel a) (i a) arg >
g→rArgs-tel U (rec H di tel) i < d , arg > = < d , g→rArgs-tel U tel i arg >
g→rArgs : {I : Set}(U : I -> Set)(γ : OPg I)(a : Args U γ) -> Args U (ε γ (index U γ a))
g→rArgs U ∅ ()
g→rArgs U (con tel i | _) (inl arg) = inl (g→rArgs-tel U tel i arg)
g→rArgs U (con _ _ | γ) (inr arg) = inr (g→rArgs U γ arg)
introg : {I : Set}(γ : OPg I)(a : Args (Ug γ) γ) -> Ug γ (index (Ug γ) γ a)
introg γ a = intror (g→rArgs (Ug γ) γ a)
r→gArgs-tel : {I : Set}(U : I -> Set){s : Shape I}(tel : Tel s)(ind : Index I tel)
(i : I) -> Args-tel U (ε-tel i tel ind) -> Args-tel U tel
r→gArgs-tel U empty ind i < p , ∙ > = ∙
r→gArgs-tel U (non-rec A tel) ind i < a , arg > = < a , r→gArgs-tel U (tel a) (ind a) i arg >
r→gArgs-tel U (rec H di tel) ind i < d , arg > = < d , r→gArgs-tel U tel ind i arg >
r→gArgs : {I : Set}(U : I -> Set)(γ : OPg I)(i : I)(a : Args U (ε γ i)) -> Args U γ
r→gArgs U ∅ _ ()
r→gArgs U (con tel ind | _) i (inl arg) = inl (r→gArgs-tel U tel ind i arg)
r→gArgs U (con _ _ | γ) i (inr arg) = inr (r→gArgs U γ i arg)
-- Elimination rules
IndArg-tel : {I : Set}(U : I -> Set){s : Shape I}(tel : Tel s) -> Args-tel U tel -> Set
IndArg-tel U empty ∙ = Zero
IndArg-tel U (non-rec A tel) < a , arg > = IndArg-tel U (tel a) arg
IndArg-tel U (rec H di tel) < d , arg > = H + IndArg-tel U tel arg
IndArg : {I E : Set}(U : I -> Set)(γ : OP I E) -> Args U γ -> Set
IndArg U ∅ ()
IndArg U (con tel _ | _) (inl arg) = IndArg-tel U tel arg
IndArg U (con _ _ | γ) (inr arg) = IndArg U γ arg
-- Examples
nat : OPr One
nat = \i -> con empty ∙ | con (rec One (\_ -> ∙) empty) ∙ | ∅
N : Set
N = Ur nat ∙
z : N
z = intror (inl ∙)
s : N -> N
s n = intror (inr (inl < (\_ -> n) , ∙ >))
|
{
"alphanum_fraction": 0.5100810642,
"avg_line_length": 32.0733333333,
"ext": "agda",
"hexsha": "9eff75d7a9d0d9c06aafc2b8a45d0dc81a7c60eb",
"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": "examples/outdated-and-incorrect/iird/new/IID.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": "examples/outdated-and-incorrect/iird/new/IID.agda",
"max_line_length": 101,
"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": "examples/outdated-and-incorrect/iird/new/IID.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": 2044,
"size": 4811
}
|
{-# OPTIONS --cubical-compatible --guardedness #-}
module Common.Coinduction where
open import Agda.Builtin.Coinduction public
private
my-♯ : ∀ {a} {A : Set a} → A → ∞ A
my-♯ x = ♯ x
|
{
"alphanum_fraction": 0.6455026455,
"avg_line_length": 21,
"ext": "agda",
"hexsha": "e46d1fd76e1e5d31ffc0e904c7519b4c92e0d53b",
"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/Common/Coinduction.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/Common/Coinduction.agda",
"max_line_length": 50,
"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/Common/Coinduction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 65,
"size": 189
}
|
module New.Changes where
open import Data.Product public hiding (map)
open import Data.Sum public hiding (map)
open import Data.Unit.Base public
open import Relation.Binary.PropositionalEquality public hiding ([_])
open import Postulate.Extensionality public
open import Level
open import Theorem.Groups-Nehemiah public
record IsChAlg {ℓ : Level} (A : Set ℓ) (Ch : Set ℓ) : Set (suc ℓ) where
field
_⊕_ : A → Ch → A
_⊝_ : A → A → Ch
valid : A → Ch → Set ℓ
_⊚[_]_ : Ch → A → Ch → Ch
⊝-valid : ∀ (a b : A) → valid a (b ⊝ a)
⊕-⊝ : (b a : A) → a ⊕ (b ⊝ a) ≡ b
⊚-correct : ∀ (a : A) → (da1 : Ch) → valid a da1 → (da2 : Ch) → valid (a ⊕ da1) da2 →
a ⊕ da1 ⊚[ a ] da2 ≡ a ⊕ da1 ⊕ da2
⊚-valid : (a : A) → (da1 : Ch) → valid a da1 → (da2 : Ch) → valid (a ⊕ da1) da2 → valid a (da1 ⊚[ a ] da2)
infixl 6 _⊕_ _⊝_
Δ : A → Set ℓ
Δ a = Σ[ da ∈ Ch ] (valid a da)
update-diff = ⊕-⊝
nil : A → Ch
nil a = a ⊝ a
nil-valid : (a : A) → valid a (nil a)
nil-valid a = ⊝-valid a a
update-nil : (a : A) → a ⊕ nil a ≡ a
update-nil a = update-diff a a
default-⊚ : Ch → A → Ch → Ch
default-⊚ da1 a da2 = a ⊕ da1 ⊕ da2 ⊝ a
default-⊚-valid : (a : A) → (da1 : Ch) → valid a da1 → (da2 : Ch) → valid (a ⊕ da1) da2 → valid a (default-⊚ da1 a da2)
default-⊚-valid a da1 ada1 da2 ada2 = ⊝-valid a (a ⊕ da1 ⊕ da2)
default-⊚-correct : ∀ (a : A) → (da1 : Ch) → valid a da1 → (da2 : Ch) → valid (a ⊕ da1) da2 →
a ⊕ default-⊚ da1 a da2 ≡ a ⊕ da1 ⊕ da2
default-⊚-correct a da1 ada1 da2 ada2 = update-diff (a ⊕ da1 ⊕ da2) a
record ChAlg {ℓ : Level} (A : Set ℓ) : Set (suc ℓ) where
field
Ch : Set ℓ
isChAlg : IsChAlg A Ch
open IsChAlg isChAlg public
open ChAlg {{...}} public hiding (Ch)
Ch : ∀ {ℓ} (A : Set ℓ) → {{CA : ChAlg A}} → Set ℓ
Ch A {{CA}} = ChAlg.Ch CA
-- Huge hack, but it does gives the output you want to see in all cases I've seen.
{-# DISPLAY IsChAlg.valid x = valid #-}
{-# DISPLAY ChAlg.valid x = valid #-}
{-# DISPLAY IsChAlg._⊕_ x = _⊕_ #-}
{-# DISPLAY ChAlg._⊕_ x = _⊕_ #-}
{-# DISPLAY IsChAlg.nil x = nil #-}
{-# DISPLAY ChAlg.nil x = nil #-}
{-# DISPLAY IsChAlg._⊝_ x = _⊝_ #-}
{-# DISPLAY ChAlg._⊝_ x = _⊝_ #-}
module _ {ℓ₁} {ℓ₂}
{A : Set ℓ₁} {B : Set ℓ₂} {{CA : ChAlg A}} {{CB : ChAlg B}} where
open ≡-Reasoning
open import Postulate.Extensionality
instance
funCA : ChAlg (A → B)
private
fCh = A → Ch A → Ch B
_f⊕_ : (A → B) → fCh → A → B
_f⊕_ = λ f df a → f a ⊕ df a (nil a)
_f⊝_ : (g f : A → B) → fCh
_f⊝_ = λ g f a da → g (a ⊕ da) ⊝ f a
IsDerivative : ∀ (f : A → B) → (df : fCh) → Set (ℓ₁ ⊔ ℓ₂)
IsDerivative f df = ∀ a da (v : valid a da) → f (a ⊕ da) ≡ f a ⊕ df a da
WellDefinedFunChangePoint : ∀ (f : A → B) → (df : fCh) → ∀ a da → Set ℓ₂
WellDefinedFunChangePoint f df a da = (f f⊕ df) (a ⊕ da) ≡ f a ⊕ df a da
WellDefinedFunChange : ∀ (f : A → B) → (df : fCh) → Set (ℓ₁ ⊔ ℓ₂)
WellDefinedFunChange f df = ∀ a da (ada : valid a da) → WellDefinedFunChangePoint f df a da
private
fvalid : (A → B) → fCh → Set (ℓ₁ ⊔ ℓ₂)
fvalid = λ f df → ∀ a da (ada : valid a da) →
valid (f a) (df a da) ×
WellDefinedFunChangePoint f df a da
f⊝-valid : ∀ (f g : A → B) → fvalid f (g f⊝ f)
f⊝-valid = λ f g a da (v : valid a da) →
⊝-valid (f a) (g (a ⊕ da))
, ( begin
f (a ⊕ da) ⊕ (g (a ⊕ da ⊕ nil (a ⊕ da)) ⊝ f (a ⊕ da))
≡⟨ cong (λ □ → f (a ⊕ da) ⊕ (g □ ⊝ f (a ⊕ da)))
(update-nil (a ⊕ da)) ⟩
f (a ⊕ da) ⊕ (g (a ⊕ da) ⊝ f (a ⊕ da))
≡⟨ update-diff (g (a ⊕ da)) (f (a ⊕ da)) ⟩
g (a ⊕ da)
≡⟨ sym (update-diff (g (a ⊕ da)) (f a)) ⟩
f a ⊕ (g (a ⊕ da) ⊝ f a)
∎)
-- Two alternatives. Proofs on f⊚ are a bit easier.
-- f⊚ is optimized relying on the incrementalization property for df2.
f⊚ f⊚2 : fCh → (A → B) → fCh → fCh
f⊚ df1 f df2 = λ a da → (df1 a (nil a)) ⊚[ f a ] (df2 a da)
f⊚-valid : (f : A → B) → (df1 : fCh) → fvalid f df1 → (df2 : fCh) → fvalid (f f⊕ df1) df2 → fvalid f (f⊚ df1 f df2)
f⊚-valid f df1 fdf1 df2 fdf2 a da ada
rewrite ⊚-correct (f a) (df1 a (nil a)) (proj₁ (fdf1 a (nil a) (nil-valid a))) (df2 a da) (proj₁ (fdf2 a da ada))
| ⊚-correct
(f (a ⊕ da))
(df1 (a ⊕ da) (nil (a ⊕ da))) (proj₁ (fdf1 (a ⊕ da) (nil (a ⊕ da)) (nil-valid (a ⊕ da))))
(df2 (a ⊕ da) (nil (a ⊕ da))) (proj₁ (fdf2 (a ⊕ da) (nil (a ⊕ da)) (nil-valid (a ⊕ da))))
=
⊚-valid (f a) (df1 a (nil a)) (proj₁ (fdf1 a (nil a) (nil-valid a))) (df2 a da) (proj₁ (fdf2 a da ada))
, proj₂ (fdf2 a da ada)
-- f⊚2 is optimized relying on the incrementalization property for df1, so we need to use that property to rewrite some goals.
f⊚2 df1 f df2 = λ a da → df1 a da ⊚[ f a ] df2 (a ⊕ da) (nil (a ⊕ da))
f⊚-valid2 : (f : A → B) → (df1 : fCh) → fvalid f df1 → (df2 : fCh) → fvalid (f f⊕ df1) df2 → fvalid f (f⊚2 df1 f df2)
f⊚-valid2 f df1 fdf1 df2 fdf2 = lemma
where
-- Prove that (df2 (a ⊕ da) (nil (a ⊕ da))) is valid for (f a ⊕ df1 a da).
-- Using the incrementalization property for df1, that becomes (f ⊕ df1) (a ⊕ da).
--
-- Since df2 is valid for f ⊕ df1, it follows that (df2 (a ⊕ da) (nil (a ⊕ da)))
-- is indeed valid for (f ⊕ df1) (a ⊕ da).
valid-df2-a2-nila2 : ∀ a da → (valid a da) → valid (f a ⊕ df1 a da) (df2 (a ⊕ da) (nil (a ⊕ da)))
valid-df2-a2-nila2 a da ada rewrite sym (proj₂ (fdf1 a da ada)) = proj₁ (fdf2 (a ⊕ da) (nil (a ⊕ da)) (nil-valid (a ⊕ da)))
lemma : fvalid f (f⊚2 df1 f df2)
lemma a da ada
rewrite ⊚-correct
(f a)
(df1 a da) (proj₁ (fdf1 a da ada))
(df2 (a ⊕ da) (nil (a ⊕ da))) (valid-df2-a2-nila2 a da ada)
| update-nil (a ⊕ da)
| ⊚-correct
(f (a ⊕ da))
(df1 (a ⊕ da) (nil (a ⊕ da))) (proj₁ (fdf1 (a ⊕ da) (nil (a ⊕ da)) (nil-valid (a ⊕ da))))
(df2 (a ⊕ da) (nil (a ⊕ da))) (proj₁ (fdf2 (a ⊕ da) (nil (a ⊕ da)) (nil-valid (a ⊕ da))))
| proj₂ (fdf1 a da ada)
= ⊚-valid (f a) (df1 a da) (proj₁ (fdf1 a da ada)) (df2 (a ⊕ da) (nil (a ⊕ da))) (valid-df2-a2-nila2 a da ada)
, refl
f⊚-correct : ∀ (f : A → B) → (df1 : fCh) → fvalid f df1 → (df2 : fCh) → fvalid (f f⊕ df1) df2 → (a : A) →
(f f⊕ f⊚ df1 f df2) a ≡ ((f f⊕ df1) f⊕ df2) a
f⊚-correct f df1 fdf1 df2 fdf2 a = ⊚-correct (f a) (df1 a (nil a)) (proj₁ (fdf1 a (nil a) (nil-valid a))) (df2 a (nil a)) (proj₁ (fdf2 a (nil a) (nil-valid a)))
private
funUpdateDiff : ∀ g f a → (f f⊕ (g f⊝ f)) a ≡ g a
funUpdateDiff g f a rewrite update-nil a = update-diff (g a) (f a)
funCA = record
{ Ch = A → Ch A → Ch B
; isChAlg = record
{ _⊕_ = _f⊕_
; _⊝_ = _f⊝_
; valid = fvalid
; _⊚[_]_ = f⊚
; ⊝-valid = f⊝-valid
; ⊕-⊝ = λ g f → ext (funUpdateDiff g f)
; ⊚-correct = λ f df1 fdf1 df2 fdf2 → ext (f⊚-correct f df1 fdf1 df2 fdf2)
; ⊚-valid = f⊚-valid
} }
private
pCh = Ch A × Ch B
_p⊕_ : A × B → Ch A × Ch B → A × B
_p⊕_ (a , b) (da , db) = a ⊕ da , b ⊕ db
_p⊝_ : A × B → A × B → pCh
_p⊝_ (a2 , b2) (a1 , b1) = a2 ⊝ a1 , b2 ⊝ b1
pvalid : A × B → pCh → Set (ℓ₂ ⊔ ℓ₁)
pvalid (a , b) (da , db) = valid a da × valid b db
p⊝-valid : (p1 p2 : A × B) → pvalid p1 (p2 p⊝ p1)
p⊝-valid (a1 , b1) (a2 , b2) = ⊝-valid a1 a2 , ⊝-valid b1 b2
p⊕-⊝ : (p2 p1 : A × B) → p1 p⊕ (p2 p⊝ p1) ≡ p2
p⊕-⊝ (a2 , b2) (a1 , b1) = cong₂ _,_ (⊕-⊝ a2 a1) (⊕-⊝ b2 b1)
_p⊚[_]_ : pCh → A × B → pCh → pCh
(da1 , db1) p⊚[ a , b ] (da2 , db2) = da1 ⊚[ a ] da2 , db1 ⊚[ b ] db2
p⊚-valid : (p : A × B) (dp1 : pCh) →
pvalid p dp1 →
(dp2 : pCh) → pvalid (p p⊕ dp1) dp2 → pvalid p (dp1 p⊚[ p ] dp2)
p⊚-valid (a , b) (da1 , db1) (ada1 , bdb1) (da2 , db2) (ada2 , bdb2) = ⊚-valid a da1 ada1 da2 ada2 , ⊚-valid b db1 bdb1 db2 bdb2
p⊚-correct : (p : A × B) (dp1 : pCh) →
pvalid p dp1 →
(dp2 : pCh) → pvalid (p p⊕ dp1) dp2 → p p⊕ (dp1 p⊚[ p ] dp2) ≡ (p p⊕ dp1) p⊕ dp2
p⊚-correct (a , b) (da1 , db1) (ada1 , bdb1) (da2 , db2) (ada2 , bdb2) rewrite ⊚-correct a da1 ada1 da2 ada2 | ⊚-correct b db1 bdb1 db2 bdb2 = refl
instance
pairCA : ChAlg (A × B)
pairCA = record
{ Ch = pCh
; isChAlg = record
{ _⊕_ = _p⊕_
; _⊝_ = _p⊝_
; valid = pvalid
; ⊝-valid = p⊝-valid
; ⊕-⊝ = p⊕-⊝
; _⊚[_]_ = _p⊚[_]_
; ⊚-valid = p⊚-valid
; ⊚-correct = p⊚-correct
} }
private
SumChange = (Ch A ⊎ Ch B) ⊎ (A ⊎ B)
data SumChange2 : Set (ℓ₁ ⊔ ℓ₂) where
ch₁ : (da : Ch A) → SumChange2
ch₂ : (db : Ch B) → SumChange2
rp : (s : A ⊎ B) → SumChange2
convert : SumChange → SumChange2
convert (inj₁ (inj₁ da)) = ch₁ da
convert (inj₁ (inj₂ db)) = ch₂ db
convert (inj₂ s) = rp s
convert₁ : SumChange2 → SumChange
convert₁ (ch₁ da) = inj₁ (inj₁ da)
convert₁ (ch₂ db) = inj₁ (inj₂ db)
convert₁ (rp s) = inj₂ s
data SValid : A ⊎ B → SumChange → Set (ℓ₁ ⊔ ℓ₂) where
sv₁ : ∀ (a : A) (da : Ch A) (ada : valid a da) → SValid (inj₁ a) (convert₁ (ch₁ da))
sv₂ : ∀ (b : B) (db : Ch B) (bdb : valid b db) → SValid (inj₂ b) (convert₁ (ch₂ db))
svrp₁ : ∀ a1 b2 → SValid (inj₁ a1) (convert₁ (rp (inj₂ b2)))
svrp₂ : ∀ b1 a2 → SValid (inj₂ b1) (convert₁ (rp (inj₁ a2)))
inv1 : ∀ ds → convert₁ (convert ds) ≡ ds
inv1 (inj₁ (inj₁ da)) = refl
inv1 (inj₁ (inj₂ db)) = refl
inv1 (inj₂ s) = refl
inv2 : ∀ ds → convert (convert₁ ds) ≡ ds
inv2 (ch₁ da) = refl
inv2 (ch₂ db) = refl
inv2 (rp s) = refl
private
s⊕2 : A ⊎ B → SumChange2 → A ⊎ B
s⊕2 (inj₁ a) (ch₁ da) = inj₁ (a ⊕ da)
s⊕2 (inj₂ b) (ch₂ db) = inj₂ (b ⊕ db)
s⊕2 (inj₂ b) (ch₁ da) = inj₂ b -- invalid
s⊕2 (inj₁ a) (ch₂ db) = inj₁ a -- invalid
s⊕2 s (rp s₁) = s₁
s⊕ : A ⊎ B → SumChange → A ⊎ B
s⊕ s ds = s⊕2 s (convert ds)
s⊝2 : A ⊎ B → A ⊎ B → SumChange2
s⊝2 (inj₁ x2) (inj₁ x1) = ch₁ (x2 ⊝ x1)
s⊝2 (inj₂ y2) (inj₂ y1) = ch₂ (y2 ⊝ y1)
s⊝2 s2 s1 = rp s2
s⊝ : A ⊎ B → A ⊎ B → SumChange
s⊝ s2 s1 = convert₁ (s⊝2 s2 s1)
s⊝-valid : (a b : A ⊎ B) → SValid a (s⊝ b a)
s⊝-valid (inj₁ x1) (inj₁ x2) = sv₁ x1 (x2 ⊝ x1) (⊝-valid x1 x2)
s⊝-valid (inj₂ y1) (inj₂ y2) = sv₂ y1 (y2 ⊝ y1) (⊝-valid y1 y2)
s⊝-valid s1@(inj₁ x) s2@(inj₂ y) = svrp₁ x y
s⊝-valid s1@(inj₂ y) s2@(inj₁ x) = svrp₂ y x
s⊕-⊝ : (b a : A ⊎ B) → s⊕ a (s⊝ b a) ≡ b
s⊕-⊝ (inj₁ x2) (inj₁ x1) rewrite ⊕-⊝ x2 x1 = refl
s⊕-⊝ (inj₁ x2) (inj₂ y1) = refl
s⊕-⊝ (inj₂ y2) (inj₁ x1) = refl
s⊕-⊝ (inj₂ y2) (inj₂ y1) rewrite ⊕-⊝ y2 y1 = refl
{-# TERMINATING #-}
isSumCA : IsChAlg (A ⊎ B) SumChange
s⊚-valid : (a : A ⊎ B) (da1 : SumChange) →
SValid a da1 →
(da2 : SumChange) →
SValid (s⊕ a da1) da2 →
SValid a (IsChAlg.default-⊚ isSumCA da1 a da2)
s⊚-correct : (a : A ⊎ B) (da1 : SumChange) →
SValid a da1 →
(da2 : SumChange) →
SValid (s⊕ a da1) da2 →
s⊕ a (IsChAlg.default-⊚ isSumCA da1 a da2) ≡
s⊕ (s⊕ a da1) da2
instance
sumCA : ChAlg (A ⊎ B)
isSumCA = record
{ _⊕_ = s⊕
; _⊝_ = s⊝
; valid = SValid
; ⊝-valid = s⊝-valid
; ⊕-⊝ = s⊕-⊝
; _⊚[_]_ = IsChAlg.default-⊚ isSumCA
; ⊚-valid = s⊚-valid
; ⊚-correct = s⊚-correct
}
s⊚-valid = IsChAlg.default-⊚-valid isSumCA
s⊚-correct = IsChAlg.default-⊚-correct isSumCA
sumCA = record
{ Ch = SumChange
; isChAlg = isSumCA }
open import Data.Integer
instance
intCA : ChAlg ℤ
intCA = record
{ Ch = ℤ
; isChAlg = record
{ _⊕_ = _+_
; _⊝_ = _-_
; valid = λ a b → ⊤
; ⊝-valid = λ a b → tt
; ⊕-⊝ = λ b a → n+[m-n]=m {a} {b}
; ⊚-valid = λ a da1 _ da2 _ → tt
; _⊚[_]_ = λ da1 a da2 → da1 + da2
; ⊚-correct = λ a da1 _ da2 _ → sym (associative-int a da1 da2)
} }
|
{
"alphanum_fraction": 0.5030783503,
"avg_line_length": 37.053125,
"ext": "agda",
"hexsha": "ba7c0af1eeff3cbe8a925073aa3b5dbfa443eea8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "New/Changes.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "New/Changes.agda",
"max_line_length": 164,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "New/Changes.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 5700,
"size": 11857
}
|
module Issue620 where
module A where
postulate _+_*_ : Set → Set → Set → Set
postulate X : Set
2X : Set
2X = X A.+ X * X
|
{
"alphanum_fraction": 0.6220472441,
"avg_line_length": 11.5454545455,
"ext": "agda",
"hexsha": "06e9924320ecb29c1f64a5e28f66532d71f9679e",
"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/Issue620.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/Issue620.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/interaction/Issue620.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": 127
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Complete.Properties {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Data.Product
open import Relation.Binary
open import Categories.Category.Complete
open import Categories.Category.Complete.Finitely
open import Categories.Category.Construction.Functors
open import Categories.Diagram.Limit as Lim
open import Categories.Diagram.Limit.Properties
open import Categories.Diagram.Equalizer.Limit C
open import Categories.Diagram.Cone.Properties
open import Categories.Object.Terminal
open import Categories.Object.Product.Limit C
open import Categories.Object.Terminal.Limit C
open import Categories.Functor
open import Categories.Functor.Limits
open import Categories.Functor.Properties
open import Categories.NaturalTransformation
open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_)
import Categories.Category.Construction.Cones as Co
import Categories.Morphism.Reasoning as MR
import Categories.Morphism as Mor
-- exports
open import Categories.Category.Complete.Properties.Construction public
open import Categories.Category.Complete.Properties.SolutionSet public
private
variable
o′ ℓ′ e′ o″ ℓ″ e″ : Level
module C = Category C
module _ (Com : Complete o′ ℓ′ e′ C) where
Complete⇒FinitelyComplete : FinitelyComplete C
Complete⇒FinitelyComplete = record
{ cartesian = record
{ terminal = limit⇒⊥ (Com (⊥⇒limit-F _ _ _))
; products = record
{ product = λ {A B} → limit⇒product (Com (product⇒limit-F _ _ _ A B))
}
}
; equalizer = complete⇒equalizer Com
}
-- if the base category is complete, then the functor category is complete.
-- in addition, the evaluation functor is continuous.
--
-- Functors-Complete : Complete o″ ℓ″ e″ D^C
-- evalF-Continuous : ∀ X → Continuous o″ ℓ″ e″ (evalF C D X)
module _ {D : Category o′ ℓ′ e′} (Com : Complete o″ ℓ″ e″ D) where
private
D^C = Functors C D
module D^C = Category D^C
module D = Category D
module _ {J : Category o″ ℓ″ e″} (F : Functor J D^C) where
private
module J = Category J
module F = Functor F
open F
module F₀ j = Functor (F₀ j)
module F₁ {a b} (f : a J.⇒ b) = NaturalTransformation (F₁ f)
ev : C.Obj → Functor D^C D
ev = evalF C D
F[-,_] : C.Obj → Functor J D
F[-, X ] = ev X ∘F F
F[-,-] : Functor C (Functors J D)
F[-,-] = record
{ F₀ = F[-,_]
; F₁ = λ {A B} f → ntHelper record
{ η = λ j → F₀.₁ j f
; commute = λ {j k} g → begin
F₀.₁ k f D.∘ F₁.η g A D.∘ F₀.₁ j C.id ≈⟨ pullˡ (F₁.sym-commute g f) ⟩
(F₁.η g B D.∘ F₀.₁ j f) D.∘ F₀.₁ j C.id ≈⟨ elimʳ (F₀.identity _) ⟩
F₁.η g B D.∘ F₀.₁ j f ≈⟨ introʳ (F₀.identity _) ⟩∘⟨refl ⟩
(F₁.η g B D.∘ F₀.₁ j C.id) D.∘ F₀.₁ j f ∎
}
; identity = F₀.identity _
; homomorphism = F₀.homomorphism _
; F-resp-≈ = λ eq → F₀.F-resp-≈ _ eq
}
where open D.HomReasoning
open MR D
module F[-,-] = Functor F[-,-]
module LimFX X = Limit (Com F[-, X ])
open LimFX hiding (commute)
K⇒lim : ∀ {X Y} (f : X C.⇒ Y) K → Co.Cones F[-, Y ] [ nat-map-Cone (F[-,-].₁ f) K , limit Y ]
K⇒lim f K = rep-cone _ (nat-map-Cone (F[-,-].₁ f) K)
lim⇒lim : ∀ {X Y} (f : X C.⇒ Y) → Co.Cones F[-, Y ] [ nat-map-Cone (F[-,-].₁ f) (limit X) , limit Y ]
lim⇒lim f = K⇒lim f (limit _)
module lim⇒lim {X Y} (f : X C.⇒ Y) = Co.Cone⇒ F[-, Y ] (lim⇒lim f)
module FCone (K : Co.Cone F) where
open Co.Cone F K public
module N = Functor N
module ψ j = NaturalTransformation (ψ j)
module FCone⇒ {K K′ : Co.Cone F} (K⇒K′ : Co.Cone⇒ F K K′) where
open Co.Cone⇒ F K⇒K′ public
module arr = NaturalTransformation arr
FXcone : ∀ X → (K : Co.Cone F) → Co.Cone F[-, X ]
FXcone X K = record
{ N = N.₀ X
; apex = record
{ ψ = λ j → ψ.η j X
; commute = λ f → D.∘-resp-≈ˡ (elimʳ (F₀.identity _)) ○ commute f
}
}
where open FCone K
open D.HomReasoning
open MR D
⊤ : Co.Cone F
⊤ = record
{ N = record
{ F₀ = λ X → apex X
; F₁ = λ {A B} f → lim⇒lim.arr f
; identity = λ {X} →
terminal.!-unique X record
{ arr = D.id
; commute = D.identityʳ ○ ⟺ (elimˡ (F₀.identity _))
}
; homomorphism = λ {X Y Z} {f g} →
terminal.!-unique₂ Z
{nat-map-Cone (F[-,-].₁ (g C.∘ f)) (limit X)}
{terminal.! Z}
{record { commute = λ {j} →
begin
proj Z j ∘ lim⇒lim.arr g ∘ lim⇒lim.arr f
≈⟨ pullˡ (lim⇒lim.commute g) ⟩
(F₀.₁ j g ∘ proj Y j) ∘ lim⇒lim.arr f
≈⟨ pullʳ (lim⇒lim.commute f) ⟩
F₀.₁ j g ∘ F₀.₁ j f ∘ proj X j
≈˘⟨ pushˡ (F₀.homomorphism j) ⟩
F₀.₁ j (g C.∘ f) ∘ proj X j
∎ }}
; F-resp-≈ = λ {A B} {f g} eq → terminal.!-unique B record
{ commute = lim⇒lim.commute g ○ ∘-resp-≈ˡ (F₀.F-resp-≈ _ (C.Equiv.sym eq)) }
}
; apex = record
{ ψ = λ j → ntHelper record
{ η = λ X → proj X j
; commute = λ _ → LimFX.commute _
}
; commute = λ f {X} → ∘-resp-≈ˡ (introʳ (F₀.identity _)) ○ limit-commute X f
}
}
where open D
open D.HomReasoning
open MR D
K⇒⊤′ : ∀ X {K} → Co.Cones F [ K , ⊤ ] → Co.Cones F[-, X ] [ FXcone X K , LimFX.limit X ]
K⇒⊤′ X {K} K⇒⊤ = record
{ arr = arr.η X
; commute = comm
}
where open FCone⇒ K⇒⊤ renaming (commute to comm)
complete : Limit F
complete = record
{ terminal = record
{ ⊤ = ⊤
; ⊤-is-terminal = record
{ ! = λ {K} →
let module K = FCone K
in record
{ arr = ntHelper record
{ η = λ X → rep X (FXcone X K)
; commute = λ {X Y} f →
terminal.!-unique₂ Y
{nat-map-Cone (F[-,-].₁ f) (FXcone X K)}
{record { commute = λ {j} →
begin
proj Y j ∘ rep Y (FXcone Y K) ∘ K.N.₁ f ≈⟨ pullˡ (LimFX.commute Y) ⟩
K.ψ.η j Y ∘ K.N.F₁ f ≈⟨ K.ψ.commute j f ⟩
F₀.₁ j f ∘ K.ψ.η j X ∎ }}
{record { commute = λ {j} →
begin
proj Y j ∘ lim⇒lim.arr f ∘ rep X (FXcone X K) ≈⟨ pullˡ (lim⇒lim.commute f) ⟩
(F₀.₁ j f ∘ proj X j) ∘ rep X (FXcone X K) ≈⟨ pullʳ (LimFX.commute X) ⟩
F₀.₁ j f ∘ K.ψ.η j X ∎ }}
}
; commute = λ {_} {X} → LimFX.commute X
}
; !-unique = λ K⇒⊤ {X} → terminal.!-unique X (K⇒⊤′ X K⇒⊤)
}
}
}
where open D
open D.HomReasoning
open MR D
module _ (L : Limit F) (X : C.Obj) where
module LimExpanded (L : Limit F) where
private
module L = Limit L
open L public
module apex = Functor L.apex
module proj j = NaturalTransformation (L.proj j)
module L = LimExpanded L
module complete = LimExpanded complete
open MR D
open D.HomReasoning
cone-iso : Mor._≅_ (Co.Cones F) complete.limit L.limit
cone-iso = up-to-iso-cone F complete L
module cone-iso where
open Mor._≅_ cone-iso public
module from where
open Co.Cone⇒ F from public
module arr = NaturalTransformation arr
module to where
open Co.Cone⇒ F to public
module arr = NaturalTransformation arr
ft-iso : Mor._≅_ D^C complete.apex L.apex
ft-iso = Lim.up-to-iso F complete L
module ft-iso = Mor._≅_ ft-iso
apex-iso : ∀ X → Mor._≅_ D (complete.apex.₀ X) (L.apex.₀ X)
apex-iso X = record
{ from = NaturalTransformation.η ft-iso.from X
; to = NaturalTransformation.η ft-iso.to X
; iso = record
{ isoˡ = ft-iso.isoˡ
; isoʳ = ft-iso.isoʳ
}
}
! : {K : Co.Cone F[-, X ]} → Co.Cone⇒ F[-, X ] K (F-map-Coneˡ (ev X) L.limit)
! {K} = record
{ arr = cone-iso.from.arr.η X D.∘ rep X K
; commute = λ {j} → begin
(L.proj.η j X D.∘ L.apex.₁ C.id) D.∘ cone-iso.from.arr.η X D.∘ rep X K
≈⟨ elimʳ L.apex.identity ⟩∘⟨refl ⟩
L.proj.η j X D.∘ cone-iso.from.arr.η X D.∘ rep X K
≈⟨ pullˡ cone-iso.from.commute ⟩
complete.proj.η j X D.∘ rep X K
≈⟨ LimFX.commute X {_} {K} ⟩
ψ j
∎
}
where open Co.Cone _ K
module ! K = Co.Cone⇒ _ (! {K})
!-unique : {K : Co.Cone F[-, X ]} (f : Co.Cone⇒ F[-, X ] K (F-map-Coneˡ (ev X) L.limit)) →
!.arr K D.≈ Co.Cone⇒.arr f
!-unique {K} f = ⟺ (switch-tofromˡ (cone-iso.apex-iso X) target)
where open Co.Cone _ K
module f = Co.Cone⇒ _ f
target : cone-iso.to.arr.η X D.∘ f.arr D.≈ rep X K
target = terminal.!-unique₂ X {K}
{record
{ arr = cone-iso.to.arr.η X D.∘ f.arr
; commute = λ {j} → begin
proj X j D.∘ cone-iso.to.arr.η X D.∘ f.arr ≈⟨ pullˡ cone-iso.to.commute ⟩
L.proj.η j X D.∘ f.arr ≈⟨ introʳ L.apex.identity ⟩∘⟨refl ⟩
(L.proj.η j X D.∘ L.apex.₁ C.id) D.∘ f.arr ≈⟨ f.commute ⟩
ψ j ∎
}}
{record
{ arr = rep X K
; commute = λ {j} → begin
proj X j D.∘ rep X K ≈⟨ LimFX.commute X ⟩
ψ j ∎
}}
preserves : IsTerminal (Co.Cones F[-, X ]) (F-map-Coneˡ (ev X) L.limit)
preserves = record
{ ! = !
; !-unique = !-unique
}
Functors-Complete : Complete o″ ℓ″ e″ D^C
Functors-Complete = complete
evalF-Continuous : ∀ X → Continuous o″ ℓ″ e″ (evalF C D X)
evalF-Continuous X {J} {F} L = preserves F L X
|
{
"alphanum_fraction": 0.4716520481,
"avg_line_length": 36.8633333333,
"ext": "agda",
"hexsha": "02357213bb723b03a6c7c136e1526f77538dd9b7",
"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": "ad0f94b6cf18d8a448b844b021aeda58e833d152",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Complete/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ad0f94b6cf18d8a448b844b021aeda58e833d152",
"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": "turion/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Complete/Properties.agda",
"max_line_length": 107,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "ad0f94b6cf18d8a448b844b021aeda58e833d152",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Complete/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 3579,
"size": 11059
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Papers.Synthetic where
-- Cubical synthetic homotopy theory
-- Mörtberg and Pujet, „Cubical synthetic homotopy theory“.
-- https://dl.acm.org/doi/abs/10.1145/3372885.3373825
-- 2.1
import Agda.Builtin.Cubical.Path as Path
import Cubical.Foundations.Prelude as Prelude
-- 2.2
import Agda.Primitive.Cubical as PrimitiveCubical
import Cubical.Data.Bool as Bool
import Cubical.Core.Primitives as CorePrimitives
-- 2.3
import Cubical.HITs.S1 as S1
-- 2.4
import Cubical.Foundations.Equiv as Equiv
import Cubical.Core.Glue as CoreGlue
import Cubical.Foundations.Univalence as Univalence
-- 3.
import Cubical.HITs.Torus as T2
-- 3.1
import Cubical.Data.Int as Int
import Cubical.Data.Int.Properties as IntProp
import Cubical.Foundations.Isomorphism as Isomorphism
-- 4.1
import Cubical.HITs.Susp as Suspension
import Cubical.HITs.Sn as Sn
import Agda.Builtin.Nat as BNat
import Agda.Builtin.Bool as BBool
import Cubical.Foundations.GroupoidLaws as GroupoidLaws
import Cubical.HITs.S2 as S2
import Cubical.HITs.S3 as S3
-- 4.2
import Cubical.HITs.Pushout as Push
import Cubical.HITs.Pushout.Properties as PushProp
-- 4.3
import Cubical.HITs.Join as Join
import Cubical.HITs.Join.Properties as JoinProp
-- 5.
import Cubical.HITs.Hopf as Hopf
--------------------------------------------------------------------------------
-- 2. Cubical Agda
-- 2.1 The Interval and Path Types
-- 2.2 Transport and Composition
-- 2.3 Higher Inductive Types
-- 2.4 Glue Types and Univalence
--------------------------------------------------------------------------------
-- 2.1 The Interval and Path Types
open Path using (PathP) public
open Prelude using (_≡_ ; refl ; funExt) public
open Prelude renaming (sym to _⁻¹) public
-- 2.2 Transport and Composition
open Prelude using (transport ; subst ; J ; JRefl) public
open PrimitiveCubical using (Partial) public
open Bool using (Bool ; true ; false) public
partialBool : ∀ i → Partial (i ∨ ~ i) Bool
partialBool i = λ {(i = i1) → true
; (i = i0) → false}
open CorePrimitives using (inS ; outS ; hcomp) public
open Prelude using (_∙_) public
-- 2.3 Higher Inductive Types
open S1 using (S¹ ; base ; loop) public
double : S¹ → S¹
double base = base
double (loop i) = (loop ∙ loop) i
-- 2.4 Glue Types and Univalence
open Equiv using (idEquiv) public
open CoreGlue using (Glue) public
open Univalence using (ua) public
--------------------------------------------------------------------------------
-- 3. The Circle and Torus
-- 3.1 The Loop Spaces of the Circle and Torus
--------------------------------------------------------------------------------
open T2 using ( Torus ; point ; line1 ; line2 ; square
; t2c ; c2t ; c2t-t2c ; t2c-c2t ; Torus≡S¹×S¹)
-- 3.1 The Loop Spaces of the Circle and Torus
open S1 using (ΩS¹) public
open T2 using (ΩTorus) public
open Int using (Int ; pos ; negsuc) public
open IntProp using (sucPathInt) public
open S1 using (helix ; winding) public
-- Examples computing the winding numbers of the circle
_ : winding (loop ∙ loop ∙ loop) ≡ pos 3
_ = refl
_ : winding ((loop ⁻¹) ∙ loop ∙ (loop ⁻¹)) ≡ negsuc 0
_ = refl
open S1 renaming (intLoop to loopn) public
open S1 renaming (windingIntLoop to winding-loopn) public
open S1 using (encode ; decode ; decodeEncode ; ΩS¹≡Int) public
open Isomorphism using (isoToPath ; iso) public
-- Notation of the paper, current notation under ΩS¹≡Int
ΩS¹≡Int' : ΩS¹ ≡ Int
ΩS¹≡Int' = isoToPath (iso winding loopn
winding-loopn (decodeEncode base))
open T2 using (ΩTorus≡Int×Int ; windingTorus) public
-- Examples at the end of section 3.
_ : windingTorus (line1 ∙ line2) ≡ (pos 1 , pos 1)
_ = refl
_ : windingTorus ((line1 ⁻¹) ∙ line2 ∙ line1) ≡ (pos 0 , pos 1)
_ = refl
--------------------------------------------------------------------------------
-- 4. Suspension, Spheres and Pushouts
-- 4.1 Suspension
-- 4.2 Pushouts and the 3 × 3 Lemma
-- 4.3 The Join and S³
--------------------------------------------------------------------------------
-- 4.1 Suspension
open Suspension using (Susp ; north ; south ; merid) public
open Sn using (S₊) public
open Suspension using ( SuspBool→S¹ ; S¹→SuspBool
; SuspBool→S¹→SuspBool
; S¹→SuspBool→S¹) public
-- Deprecated version of S₊
open BNat renaming (Nat to ℕ) hiding (_*_) public
open CorePrimitives renaming (Type to Set) public
open BBool using (Bool) public
-- At the time the paper was published, Set was used instead of Type
_-sphere : ℕ → Set
0 -sphere = Bool
(suc n) -sphere = Susp (n -sphere)
-- Lemma 4.1. The (1)-sphere is equal to the circle S1.
open BBool using (true ; false) public
-- Deprecated version of SuspBool→S¹
s2c : 1 -sphere → S¹
s2c north = base
s2c south = base
s2c (merid true i) = loop i
s2c (merid false i) = base -- (loop ⁻¹) i
-- Deprecated version of S¹→SuspBool
c2s : S¹ → 1 -sphere
c2s base = north
c2s (loop i) = (merid true ∙ (merid false ⁻¹)) i
open GroupoidLaws using (rUnit) public
-- Deprecated version of SuspBool→S¹→SuspBool
s2c-c2s : ∀ (p : S¹) → s2c (c2s p) ≡ p
s2c-c2s base = refl
s2c-c2s (loop i) j = rUnit loop (~ j) i
h1 : I → I → 1 -sphere
h1 i j = merid false (i ∧ j)
h2 : I → I → 1 -sphere
h2 i j = hcomp (λ k → λ { (i = i0) → north
; (i = i1) → merid false (j ∨ ~ k)
; (j = i1) → merid true i })
(merid true i)
-- Deprecated version of S¹→SuspBool→S¹
c2s-s2c : ∀ (t : 1 -sphere) → c2s (s2c t) ≡ t
c2s-s2c north j = north
c2s-s2c south j = merid false j
c2s-s2c (merid true i) j = h2 i j
c2s-s2c (merid false i) j = merid false (i ∧ j)
-- Notation of the paper, current notation under S¹≡SuspBool
-- Proof of Lemma 4.1
1-sphere≡S¹ : 1 -sphere ≡ S¹
1-sphere≡S¹ = isoToPath (iso s2c c2s s2c-c2s c2s-s2c)
-- Definitions of S2 and S3
open S2 using (S²) public
open S3 using (S³) public
-- 4.2 Pushouts and the 3 × 3 Lemma
open Push using (Pushout) public
-- 3x3-span is implemented as a record
open PushProp using (3x3-span) public
open 3x3-span using (f□1) public
-- The rest of the definitions inside the 3x3-lemma
-- A□0-A○□ , A□○-A○□ ...
open 3x3-span using (3x3-lemma) public
-- 4.3 The Join and S³
open Join renaming (join to Join) using (S³≡joinS¹S¹) public
open JoinProp using (join-assoc) public
--------------------------------------------------------------------------------
-- 5. The Hopf Fibration
--------------------------------------------------------------------------------
-- rot (denoted by _·_ here) in the paper is substituted by a rot and rotLoop in S1
open S1 using (_·_ ; rotLoop) public
open Hopf renaming ( HopfSuspS¹ to Hopf
; JoinS¹S¹→TotalHopf to j2h
; TotalHopf→JoinS¹S¹ to h2j)
using (HopfS²) public
open S1 renaming (rotInv-1 to lem-rot-inv) public
|
{
"alphanum_fraction": 0.5891780822,
"avg_line_length": 33.9534883721,
"ext": "agda",
"hexsha": "380b21d657fefc305b5b999bf062a89221a4c0dd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Papers/Synthetic.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/Papers/Synthetic.agda",
"max_line_length": 83,
"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/Papers/Synthetic.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2251,
"size": 7300
}
|
{-# OPTIONS --without-K #-}
module well-typed-syntax-interpreter-full where
open import common public
open import well-typed-syntax
open import well-typed-syntax-interpreter
Contextε⇓ : Context⇓ ε
Contextε⇓ = tt
Typε⇓ : Typ ε → Set max-level
Typε⇓ T = Typ⇓ T Contextε⇓
Termε⇓ : {T : Typ ε} → Term T → Typε⇓ T
Termε⇓ t = Term⇓ t Contextε⇓
Typε▻⇓ : ∀ {A} → Typ (ε ▻ A) → Typε⇓ A → Set max-level
Typε▻⇓ T A⇓ = Typ⇓ T (Contextε⇓ , A⇓)
Termε▻⇓ : ∀ {A} → {T : Typ (ε ▻ A)} → Term T → (x : Typε⇓ A) → Typε▻⇓ T x
Termε▻⇓ t x = Term⇓ t (Contextε⇓ , x)
|
{
"alphanum_fraction": 0.6113138686,
"avg_line_length": 26.0952380952,
"ext": "agda",
"hexsha": "383e71c7ce874ea4b79e5b1f8db97b64d2722945",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JasonGross/lob",
"max_forks_repo_path": "internal/well-typed-syntax-interpreter-full.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JasonGross/lob",
"max_issues_repo_path": "internal/well-typed-syntax-interpreter-full.agda",
"max_line_length": 73,
"max_stars_count": 19,
"max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JasonGross/lob",
"max_stars_repo_path": "internal/well-typed-syntax-interpreter-full.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z",
"num_tokens": 263,
"size": 548
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import stash.modalities.Orthogonality
module stash.modalities.Nullification where
module _ {i} where
postulate -- HIT
P⟨_⟩ : (A X : Type i) → Type i
p[_] : {A X : Type i} → X → P⟨ A ⟩ X
is-orth : {A X : Type i} → ⟦ A ⊥ P⟨ A ⟩ X ⟧
module NullElim {A X : Type i} {Q : P⟨ A ⟩ X → Type i}
(p : (x : P⟨ A ⟩ X) → ⟦ A ⊥ Q x ⟧) (d : (x : X) → Q p[ x ]) where
postulate
f : Π (P⟨ A ⟩ X) Q
p[_]-β : ∀ x → f p[ x ] ↦ d x
{-# REWRITE p[_]-β #-}
open NullElim public renaming (f to Null-elim)
module _ {i} (A : Type i) where
NullModality : Modality i
Modality.is-local NullModality X = ⟦ A ⊥ X ⟧
Modality.is-local-is-prop NullModality = is-equiv-is-prop
Modality.◯ NullModality = P⟨ A ⟩
Modality.◯-is-local NullModality = is-orth
Modality.η NullModality = p[_]
Modality.◯-elim NullModality = Null-elim
Modality.◯-elim-β NullModality _ _ _ = idp
Modality.◯-=-is-local NullModality x y = pths-orth is-orth
module _ {i} (A X : Type i) where
f-aux : (x : P⟨ Susp A ⟩ X) → P⟨ A ⟩ (x == x)
f-aux = Null-elim (λ x → susp-≻ A (P⟨ A ⟩ (x == x)) is-orth) (λ x → p[ idp ])
f : (x y : P⟨ Susp A ⟩ X) → x == y → P⟨ A ⟩ (x == y)
f x .x idp = f-aux x
module _ {i} {A B : Type i} (f : A → B) where
ap-fib-to : {a₀ a₁ : A} (p : f a₀ == f a₁) → hfiber (ap f) p
→ Σ (hfiber f (f a₀)) (λ α →
Σ (hfiber f (f a₁)) (λ β →
Σ (fst α == fst β) (λ q →
ap f q == snd α ∙ p ∙ ! (snd β))))
ap-fib-to {a₀} {a₁} .(ap f q) (q , idp) = (a₀ , idp) , (a₁ , idp) , q , ! (∙-unit-r (ap f q))
postulate
ap-fib : {a₀ a₁ : A} (p : f a₀ == f a₁) → is-equiv (ap-fib-to p)
new-ap-fib : {a₀ a₁ : A} (p : f a₀ == f a₁) → hfiber (ap f) p
→ Σ (hfiber f (f a₀)) (λ α →
Σ (hfiber f (f a₁)) (λ β →
α == β [ (λ z → hfiber f z) ↓ p ]))
new-ap-fib = {!!}
module _ {i} (A X : Type i) (x y : X) where
module NMA = Modality (NullModality A)
module NMSA = Modality (NullModality (Susp A))
-- Okay. Here is the map in question:
pΣ : x == y → Path {A = P⟨ Susp A ⟩ X} p[ x ] p[ y ]
pΣ = ap p[_]
lemma : NMSA.is-◯-equiv pΣ
lemma p = NMSA.equiv-preserves-◯-conn ((ap-fib-to p[_] p , ap-fib p[_] p) ⁻¹)
{!!}
thm : NMA.is-◯-equiv pΣ
thm p = {!!}
-- equiv-preserves-◯-conn : {A B : Type ℓ} → A ≃ B → is-◯-connected A → is-◯-connected B
-- equiv-preserves-◯-conn e c = equiv-preserves-level (◯-emap e) c
-- Okay, here's a better explanation: you are simply applying the
-- full fledged join adjunction formula to the p[_]. I think
-- the diagonal of this map will have fibers which are exactly
-- the PathOver description you give above. Or something
-- very close to this. That's the main idea.
-- Theorem 19.1 of CwA and PA asserts that this map
-- is A-connected. Have to trace through the argument.
-- So we don't contruct a direct inverse ...
-- He starts by observing that it is ΣA-connected.
-- Do you have a proof of this? It should be obvious ...
-- So by adjuction, loops on this fiber is A-connected.
-- Then the claim is that you can commute with limits, i.e.
-- that this is the fiber on loops of the canoncial map.
-- Right. This is much clearer. We'll need some preparation,
-- but I think this should be quite doable.
-- this map is fairly easy by adjunction ...
to : P⟨ A ⟩ (x == y) → (Path {A = P⟨ Susp A ⟩ X} p[ x ] p[ y ])
to = Null-elim (λ p → adj-orth A (P⟨ Susp A ⟩ X) is-orth p[ x ] p[ y ]) (λ p → ap p[_] p)
|
{
"alphanum_fraction": 0.5578651685,
"avg_line_length": 32.0720720721,
"ext": "agda",
"hexsha": "d2bb3763e5f1b5124500d1c693b472568a81ffa3",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/stash/modalities/Nullification.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/stash/modalities/Nullification.agda",
"max_line_length": 95,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/stash/modalities/Nullification.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": 1415,
"size": 3560
}
|
module Categories where
open import Library
record Cat {a b} : Set (lsuc (a ⊔ b)) where
field Obj : Set a
Hom : Obj → Obj → Set b
iden : ∀{X} → Hom X X
comp : ∀{X Y Z} → Hom Y Z → Hom X Y → Hom X Z
idl : ∀{X Y}{f : Hom X Y} → comp iden f ≅ f
idr : ∀{X Y}{f : Hom X Y} → comp f iden ≅ f
ass : ∀{W X Y Z}{f : Hom Y Z}{g : Hom X Y}{h : Hom W X} →
comp (comp f g) h ≅ comp f (comp g h)
open Cat
_Op : ∀{a b} → Cat {a}{b} → Cat
C Op = record{
Obj = Obj C;
Hom = λ X Y → Hom C Y X;
iden = iden C;
comp = λ f g → comp C g f;
idl = idr C;
idr = idl C;
ass = sym (ass C)}
|
{
"alphanum_fraction": 0.4613050076,
"avg_line_length": 26.36,
"ext": "agda",
"hexsha": "7aa38b8cc242dd5eb95b09583ea85cb69c870b49",
"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": "Categories.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": "Categories.agda",
"max_line_length": 67,
"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": "Categories.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": 275,
"size": 659
}
|
module list where
module List (A : Set) where
data List : Set where
nil : List
_::_ : A -> List -> List
_++_ : List -> List -> List
nil ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
|
{
"alphanum_fraction": 0.4736842105,
"avg_line_length": 14.9285714286,
"ext": "agda",
"hexsha": "072c344d4459e6737f9677502e12f0210ac9604b",
"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/list.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/list.agda",
"max_line_length": 35,
"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/list.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": 72,
"size": 209
}
|
module x01-842Naturals-hc-2 where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
one : ℕ
one = suc zero
two : ℕ
two = suc (suc zero)
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
seven : ℕ
seven = suc (suc (suc (suc (suc (suc (suc zero))))))
_ : seven ≡ 7
_ = refl
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
_ : 2 + 3 ≡ 5
_ = refl
_ : 2 + 3 ≡ 5
_ =
begin
2 + 3
≡⟨⟩ -- is shorthand for
(suc (suc zero)) + (suc (suc (suc zero)))
≡⟨⟩ -- many steps condensed
5
∎
_*_ : ℕ → ℕ → ℕ
zero * n = zero
suc m * n = n + (m * n)
_ =
begin
2 * 3
≡⟨⟩ -- many steps condensed
6
∎
_ : 3 * 4 ≡ 12
_ = refl
_^_ : ℕ → ℕ → ℕ
m ^ zero = suc zero
m ^ suc n = m * (m ^ n)
_ : 2 ^ 0 ≡ 1
_ = refl
_ : 2 ^ 1 ≡ 2
_ = refl
_ : 2 ^ 2 ≡ 4
_ = refl
_ : 2 ^ 3 ≡ 8
_ = refl
_ : 3 ^ 3 ≡ 27
_ = refl
_∸_ : ℕ → ℕ → ℕ
zero ∸ n = zero
m ∸ zero = m
suc m ∸ suc n = m ∸ n
_ : 3 ∸ 2 ≡ 1
_ = refl
_ : 2 ∸ 3 ≡ 0
_ = refl
infixl 6 _+_ _∸_
infixl 7 _*_
{-# BUILTIN NATPLUS _+_ #-}
{-# BUILTIN NATTIMES _*_ #-}
{-# BUILTIN NATMINUS _∸_ #-}
-- Binary representation.
data Bin-ℕ : Set where
bits : Bin-ℕ
_x0 : Bin-ℕ → Bin-ℕ
_x1 : Bin-ℕ → Bin-ℕ
-- Our representation of zero is different from PLFA.
-- We use the empty sequence of bits (more consistent).
bin-zero : Bin-ℕ
bin-zero = bits
bin-one : Bin-ℕ
bin-one = bits x1 -- 1 in binary
bin-two : Bin-ℕ
bin-two = bits x1 x0 -- 10 in binary
-- 842 exercise: Increment (1 point)
-- Define increment (add one).
inc : Bin-ℕ → Bin-ℕ
inc bits = bits x1
inc (m x0) = m x1
inc (m x1) = (inc m) x0
_ : inc (bits) ≡ bits x1
_ = refl
_ : inc (bits x1) ≡ bits x1 x0
_ = refl
_ : inc (bits x1 x0) ≡ bits x1 x1
_ = refl
_ : inc (bits x1 x1) ≡ bits x1 x0 x0
_ = refl
_ : inc (bits x1 x0 x0) ≡ bits x1 x0 x1
_ = refl
_ : inc (bits x1 x0 x1) ≡ bits x1 x1 x0
_ = refl
_ : inc (bits x1 x1 x0) ≡ bits x1 x1 x1
_ = refl
_ : inc (bits x1 x1 x1) ≡ bits x1 x0 x0 x0
_ = refl
_ : inc (bits x1 x0 x1 x1) ≡ bits x1 x1 x0 x0
_ = refl
dbl : ℕ → ℕ
dbl zero = zero
dbl (suc m) = suc (suc (dbl m))
tob : ℕ → Bin-ℕ
tob zero = bits
tob (suc m) = inc (tob m)
fromb : Bin-ℕ → ℕ
fromb bits = zero
fromb (n x0) = dbl (fromb n)
fromb (n x1) = suc (dbl (fromb n))
_ : tob 6 ≡ bits x1 x1 x0
_ = refl
_ : fromb bits ≡ 0
_ = refl
_ : fromb (bits x0) ≡ 0
_ = refl
_ : fromb (bits x1) ≡ 1
_ = refl
_ : fromb (bits x1 x0) ≡ 2
_ = refl
_ : fromb (bits x1 x1) ≡ 3
_ = refl
_ : fromb (bits x1 x1 x0) ≡ 6
_ = refl
_ : fromb (bits x1 x1 x0) ≡ 6
_ = refl
-- Do NOT use 'to' and 'from'. Work with Bin-ℕ as if ℕ did not exist.
_bin-+_ : Bin-ℕ → Bin-ℕ → Bin-ℕ
bits bin-+ n = n
m bin-+ bits = m
(m x0) bin-+ (n x0) = (m bin-+ n) x0
(m x0) bin-+ (n x1) = inc ((m bin-+ n) x0)
(m x1) bin-+ (n x0) = inc ((m bin-+ n) x0)
(m x1) bin-+ (n x1) = inc (inc ((m bin-+ n) x0))
_ : (bits x1 x0 x0 x0) bin-+ (bits x1) ≡ (bits x1 x0 x0 x1)
_ = refl
_ : (bits x1 x0 x0 x1) bin-+ (bits x1) ≡ (bits x1 x0 x1 x0)
_ = refl
_ : (bits x1 x0 x0 x0) bin-+ (bits x1 x1 x1) ≡ (bits x1 x1 x1 x1)
_ = refl
_ : (tob 6) bin-+ (tob 2) ≡ (tob 8)
_ = refl
_ : (bits x1 x0) bin-+ (bits x1 x1) ≡ (bits x1 x0 x1)
_ = refl
|
{
"alphanum_fraction": 0.5181498829,
"avg_line_length": 18.170212766,
"ext": "agda",
"hexsha": "a929e643a2ec6107eaa30e1d1711192b9a590874",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x01-842Naturals-hc-2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x01-842Naturals-hc-2.agda",
"max_line_length": 69,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x01-842Naturals-hc-2.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 1616,
"size": 3416
}
|
{-
A simpler definition of truncation ∥ A ∥ n from n ≥ -1
Note that this uses the HoTT book's indexing, so it will be off
from `∥_∥_` in HITs.Truncation.Base by -2
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Truncation.Base where
open import Cubical.Data.NatMinusOne renaming (suc₋₁ to suc)
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.HITs.Sn.Base
open import Cubical.Data.Nat.Base renaming (suc to sucℕ)
open import Cubical.Data.Unit.Base
open import Cubical.Data.Empty
-- this definition is off by one. Use hLevelTrunc or ∥_∥ for truncations
-- (off by 2 w.r.t. the HoTT-book)
data HubAndSpoke {ℓ} (A : Type ℓ) (n : ℕ) : Type ℓ where
∣_∣ : A → HubAndSpoke A n
hub : (f : S₊ n → HubAndSpoke A n) → HubAndSpoke A n
spoke : (f : S₊ n → HubAndSpoke A n) (x : S₊ n) → hub f ≡ f x
hLevelTrunc : ∀ {ℓ} (n : ℕ) (A : Type ℓ) → Type ℓ
hLevelTrunc zero A = Unit*
hLevelTrunc (sucℕ n) A = HubAndSpoke A n
∥_∥_ : ∀ {ℓ} (A : Type ℓ) (n : ℕ) → Type ℓ
∥ A ∥ n = hLevelTrunc n A
|
{
"alphanum_fraction": 0.6769953052,
"avg_line_length": 32.2727272727,
"ext": "agda",
"hexsha": "b902713b5cb85d3d9b012edde5d9f1523c8e7bb4",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/HITs/Truncation/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/HITs/Truncation/Base.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/HITs/Truncation/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 407,
"size": 1065
}
|
{-# OPTIONS --guardedness-preserving-type-constructors #-}
open import Agda.Builtin.Coinduction
open import Agda.Builtin.IO
open import Agda.Builtin.Unit
data Rec (A : ∞ Set) : Set where
fold : ♭ A → Rec A
D : Set
D = Rec (♯ (∞ D))
d : D
d = fold (♯ d)
postulate
seq : {A B : Set} → A → B → B
return : {A : Set} → A → IO A
{-# COMPILE GHC return = \_ -> return #-}
{-# COMPILE GHC seq = \_ _ -> seq #-}
main : IO ⊤
main = seq d (return tt)
|
{
"alphanum_fraction": 0.5732758621,
"avg_line_length": 18.56,
"ext": "agda",
"hexsha": "85d5ca52732bbb4d3637fcf11c01d649ca51d4d2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Compiler/simple/Issue2909-3.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Compiler/simple/Issue2909-3.agda",
"max_line_length": 58,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Compiler/simple/Issue2909-3.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z",
"num_tokens": 161,
"size": 464
}
|
module FlatDomInequality-2 where
postulate
A : Set
h : (@♭ x : A) → A
h x = x
q : A → A
q = h
|
{
"alphanum_fraction": 0.5454545455,
"avg_line_length": 9,
"ext": "agda",
"hexsha": "236b959c6ab8ead59c722ed9de1a0f8c735d64ba",
"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/FlatDomInequality-2.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/FlatDomInequality-2.agda",
"max_line_length": 32,
"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/FlatDomInequality-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": 44,
"size": 99
}
|
module thms where
open import bool-thms public
open import bool-thms2 public
open import list-thms public
open import list-thms2 public
open import maybe-thms public
open import product-thms public
open import string-thms public
open import sum-thms public
open import nat-thms public
open import trie-thms public
|
{
"alphanum_fraction": 0.8312101911,
"avg_line_length": 26.1666666667,
"ext": "agda",
"hexsha": "82ccf201a0f05a56fe56fe22ebaeb4049f435de5",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "thms.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "thms.agda",
"max_line_length": 31,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "thms.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 76,
"size": 314
}
|
{-# OPTIONS --no-positivity-check #-}
open import Prelude hiding (id; Bool; _∷_; [])
module Examples.Bad where
data TC : Set where
tc-int : TC
tc-bool : TC
tc-char : TC
_tc≟_ : (a b : TC) → Dec (a ≡ b)
tc-int tc≟ tc-int = yes refl
tc-int tc≟ tc-bool = no (λ ())
tc-bool tc≟ tc-int = no (λ ())
tc-bool tc≟ tc-bool = yes refl
tc-int tc≟ tc-char = no (λ ())
tc-bool tc≟ tc-char = no (λ ())
tc-char tc≟ tc-int = no (λ ())
tc-char tc≟ tc-bool = no (λ ())
tc-char tc≟ tc-char = yes refl
open import Implicits.Oliveira.Types TC _tc≟_
open import Implicits.Oliveira.Terms TC _tc≟_
open import Implicits.Oliveira.Contexts TC _tc≟_
open import Implicits.Oliveira.WellTyped TC _tc≟_
open import Implicits.Oliveira.Substitutions TC _tc≟_
open import Implicits.Oliveira.Types.Unification TC _tc≟_
open import Implicits.Improved.Undecidable.Resolution TC _tc≟_
open import Data.Maybe
open import Data.List
open import Extensions.ListFirst
Bool : ∀ {n} → Type n
Bool = simpl (tc tc-bool)
Int : ∀ {n} → Type n
Int = simpl (tc tc-int)
Char : ∀ {n} → Type n
Char = simpl (tc tc-char)
module Ex₀ where
data Bad : Set where
bad : ¬ Bad → Bad
getFun : Bad → ¬ Bad
getFun (bad x) = x
omega : Bad → ⊥
omega b = getFun b b
loop : ⊥
loop = omega (bad omega)
module Ex₁ where
Δ : ICtx zero
Δ = Bool ⇒ Bool ∷ Bool ∷ []
Bad : Set
Bad = Δ ⊢ (Bool ⇒ Bool ) ↓ (tc tc-bool)
getFun : Bad → ¬ Bad
getFun (i-iabs (r-simp (here p ._)) x₁) = {!!}
getFun (i-iabs (r-simp (there ._ f x)) y) = f
omega : Bad → ⊥
omega b = getFun b b
bad : ¬ Bad → Bad
bad ¬x = i-iabs (r-simp (there _ ¬x (here (i-simp (tc tc-bool)) []))) (i-simp (tc tc-bool))
loop : ⊥
loop = omega (bad omega)
|
{
"alphanum_fraction": 0.6258782201,
"avg_line_length": 22.1818181818,
"ext": "agda",
"hexsha": "b82e3e49b683e98508bf411316da81711536702b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Examples/Bad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Examples/Bad.agda",
"max_line_length": 93,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Examples/Bad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 622,
"size": 1708
}
|
module nouse_CollatzProof where
open import Data.Nat
-- 偽
data ⊥ : Set where
-- 真
record ⊤ : Set where
-- 選言
data _∨_ (P Q : Set) : Set where
∨Intro1 : P → P ∨ Q
∨Intro2 : Q → P ∨ Q
∨Elim : {P Q R : Set} → P ∨ Q → (P → R) → (Q → R) → R
∨Elim (∨Intro1 a) prfP _ = prfP a
∨Elim (∨Intro2 b) _ prfQ = prfQ b
-- 否定
¬ : Set → Set
¬ p = p → ⊥
⊥Elim : {P : Set} → ⊥ → P
⊥Elim ()
postulate
LEM : (P : Set) → (P ∨ ¬ P)
smaller : ℕ → Set
-- n:左端からの連続するビット1
-- k+2で小さくならない→k+1で小さくならない
lemma1-3 : (k : ℕ) → ¬ (smaller (suc (suc k))) → ¬ (smaller (suc k))
lemma2 : smaller 0 -- evenは小さくなる
lemma3 : smaller 1 -- 4x+1は小さくなる
-- 二重否定除去
DNE1 : {p : Set} → p → ¬ (¬ p)
DNE1 p q = q p
DNE2 : {p : Set} → ¬ (¬ p) → p
DNE2 {p0} p1 = ∨Elim (LEM p0) (λ y → y) (λ z → ⊥Elim (p1 z))
-- 対偶
contraposition : {A B : Set} → (A → B) → (¬ B → ¬ A)
contraposition = λ f g x → g (f x)
contraposition2 : {A B : Set} → (¬ B → ¬ A) → (A → B)
contraposition2 p a =
let t = (contraposition p) (DNE1 a) in DNE2 t
-- 本論
-- n:最下位からの連続するビット1
proof : (n : ℕ) → smaller n
proof zero = lemma2 -- even
proof (suc zero) = lemma3 -- 4x+1
proof (suc (suc n)) = part n (proof (suc n))
where
-- (k+2で小さくならない→k+1で小さくならない)→(k+1で小さくなる→k+2で小さくなる)
part : (k : ℕ) → smaller (suc k) → smaller (suc (suc k))
part k = contraposition2 (lemma1-3 k)
|
{
"alphanum_fraction": 0.5106685633,
"avg_line_length": 23.8305084746,
"ext": "agda",
"hexsha": "5e4761a0e315cae09755e53eb733c864bab1cdaf",
"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": "7e3f7a76b8cb0db264175392ff5e584a26930379",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "righ1113/collatzProof",
"max_forks_repo_path": "nouse_CollatzProof.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7e3f7a76b8cb0db264175392ff5e584a26930379",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "righ1113/collatzProof",
"max_issues_repo_path": "nouse_CollatzProof.agda",
"max_line_length": 71,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7e3f7a76b8cb0db264175392ff5e584a26930379",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "righ1113/collatzProof",
"max_stars_repo_path": "nouse_CollatzProof.agda",
"max_stars_repo_stars_event_max_datetime": "2018-02-25T14:44:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-25T14:44:08.000Z",
"num_tokens": 698,
"size": 1406
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Definition of and lemmas related to "true infinitely often"
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.InfinitelyOften where
open import Category.Monad using (RawMonad)
open import Level using (0ℓ)
open import Data.Empty using (⊥-elim)
open import Data.Nat
open import Data.Nat.Properties
open import Data.Product as Prod hiding (map)
open import Data.Sum hiding (map)
open import Function
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (¬_)
open import Relation.Nullary.Negation using (¬¬-Monad; call/cc)
open import Relation.Unary using (Pred; _∪_; _⊆_)
open RawMonad (¬¬-Monad {p = 0ℓ})
-- Only true finitely often.
Fin : ∀ {ℓ} → Pred ℕ ℓ → Set ℓ
Fin P = ∃ λ i → ∀ j → i ≤ j → ¬ P j
-- A non-constructive definition of "true infinitely often".
Inf : ∀ {ℓ} → Pred ℕ ℓ → Set ℓ
Inf P = ¬ Fin P
-- Fin is preserved by binary sums.
_∪-Fin_ : ∀ {ℓp ℓq P Q} → Fin {ℓp} P → Fin {ℓq} Q → Fin (P ∪ Q)
_∪-Fin_ {P = P} {Q} (i , ¬p) (j , ¬q) = (i ⊔ j , helper)
where
open ≤-Reasoning
helper : ∀ k → i ⊔ j ≤ k → ¬ (P ∪ Q) k
helper k i⊔j≤k (inj₁ p) = ¬p k (begin
i ≤⟨ m≤m⊔n i j ⟩
i ⊔ j ≤⟨ i⊔j≤k ⟩
k ∎) p
helper k i⊔j≤k (inj₂ q) = ¬q k (begin
j ≤⟨ m≤m⊔n j i ⟩
j ⊔ i ≡⟨ ⊔-comm j i ⟩
i ⊔ j ≤⟨ i⊔j≤k ⟩
k ∎) q
-- Inf commutes with binary sums (in the double-negation monad).
commutes-with-∪ : ∀ {P Q} → Inf (P ∪ Q) → ¬ ¬ (Inf P ⊎ Inf Q)
commutes-with-∪ p∪q =
call/cc λ ¬[p⊎q] →
(λ ¬p ¬q → ⊥-elim (p∪q (¬p ∪-Fin ¬q)))
<$> ¬[p⊎q] ∘ inj₁ ⊛ ¬[p⊎q] ∘ inj₂
-- Inf is functorial.
map : ∀ {ℓp ℓq P Q} → P ⊆ Q → Inf {ℓp} P → Inf {ℓq} Q
map P⊆Q ¬fin = ¬fin ∘ Prod.map id (λ fin j i≤j → fin j i≤j ∘ P⊆Q)
-- Inf is upwards closed.
up : ∀ {ℓ P} n → Inf {ℓ} P → Inf (P ∘ _+_ n)
up zero = id
up {P = P} (suc n) = up n ∘ up₁
where
up₁ : Inf P → Inf (P ∘ suc)
up₁ ¬fin (i , fin) = ¬fin (suc i , helper)
where
helper : ∀ j → 1 + i ≤ j → ¬ P j
helper ._ (s≤s i≤j) = fin _ i≤j
-- A witness.
witness : ∀ {ℓ P} → Inf {ℓ} P → ¬ ¬ ∃ P
witness ¬fin ¬p = ¬fin (0 , λ i _ Pi → ¬p (i , Pi))
-- Two different witnesses.
twoDifferentWitnesses
: ∀ {P} → Inf P → ¬ ¬ ∃₂ λ m n → m ≢ n × P m × P n
twoDifferentWitnesses inf =
witness inf >>= λ w₁ →
witness (up (1 + proj₁ w₁) inf) >>= λ w₂ →
return (_ , _ , m≢1+m+n (proj₁ w₁) , proj₂ w₁ , proj₂ w₂)
|
{
"alphanum_fraction": 0.5218068536,
"avg_line_length": 28.2197802198,
"ext": "agda",
"hexsha": "06b3b5abbf0b6e4c2bcee55dffe30643a77848bf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/InfinitelyOften.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/InfinitelyOften.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/InfinitelyOften.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1037,
"size": 2568
}
|
-- 2010-10-14
{-# OPTIONS --universe-polymorphism #-}
module FakeProjectionsDoNotPreserveGuardedness where
-- Coinduction is only available with universe polymorphism
postulate
Level : Set
zero : Level
suc : (i : Level) → Level
_⊔_ : Level → Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
infixl 6 _⊔_
-- Coinduction
infix 1000 ♯_
postulate
∞ : ∀ {a} (A : Set a) → Set a
♯_ : ∀ {a} {A : Set a} → A → ∞ A
♭ : ∀ {a} {A : Set a} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
-- Products
infixr 4 _,_
infixr 2 _×_
-- fake product with projections
postulate
_×_ : (A B : Set) → Set
_,_ : {A B : Set}(a : A)(b : B) → A × B
proj₁ : {A B : Set}(p : A × B) → A
proj₂ : {A B : Set}(p : A × B) → B
-- Streams
infixr 5 _∷_
data Stream (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
mutual
repeat : {A : Set}(a : A) → Stream A
repeat a = a ∷ proj₂ (repeat' a)
repeat' : {A : Set}(a : A) → A × ∞ (Stream A)
repeat' a = a , ♯ repeat a
|
{
"alphanum_fraction": 0.5425065732,
"avg_line_length": 18.7049180328,
"ext": "agda",
"hexsha": "c2085782e189631538ac95aaba5393382bb05e5f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/agda-kanso",
"max_forks_repo_path": "test/fail/FakeProjectionsDoNotPreserveGuardedness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/agda-kanso",
"max_issues_repo_path": "test/fail/FakeProjectionsDoNotPreserveGuardedness.agda",
"max_line_length": 59,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/FakeProjectionsDoNotPreserveGuardedness.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 455,
"size": 1141
}
|
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Sigma
open import lib.types.Span
open import lib.types.Pointed
open import lib.types.Pushout
module lib.types.Join where
module _ {i j} (A : Type i) (B : Type j) where
*-span : Span
*-span = span A B (A × B) fst snd
_*_ : Type _
_*_ = Pushout *-span
module _ {i j} (X : Ptd i) (Y : Ptd j) where
*-⊙span : ⊙Span
*-⊙span = ⊙span X Y (X ⊙× Y) ⊙fst ⊙snd
_⊙*_ : Ptd _
_⊙*_ = ⊙Pushout *-⊙span
|
{
"alphanum_fraction": 0.6041237113,
"avg_line_length": 18.6538461538,
"ext": "agda",
"hexsha": "7c7d0a612997c647b0976ae4ed20f6e1bdf06798",
"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": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danbornside/HoTT-Agda",
"max_forks_repo_path": "lib/types/Join.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"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": "danbornside/HoTT-Agda",
"max_issues_repo_path": "lib/types/Join.agda",
"max_line_length": 46,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danbornside/HoTT-Agda",
"max_stars_repo_path": "lib/types/Join.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 194,
"size": 485
}
|
module RandomAccessList.Redundant.Core.Properties where
open import BuildingBlock
open import BuildingBlock.BinaryLeafTree using (BinaryLeafTree; Node; Leaf)
open import RandomAccessList.Redundant.Core
open import Data.Num.Redundant
open import Data.Num.Redundant.Properties
open import Data.Nat using (ℕ; zero; suc)
open import Data.Nat.Etc
open import Data.Nat.Properties.Simple
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong; cong₂; trans; sym; inspect)
open PropEq.≡-Reasoning
⟦[]⟧≈zero∷[] : ∀ {n A} → (xs : 0-2-RAL A n) → {xs≣[] : xs ≡ []} → ⟦ xs ⟧ ≈ zero ∷ []
⟦[]⟧≈zero∷[] {n} {A} [] = <<<-zero n [] {eq refl}
⟦[]⟧≈zero∷[] ( 0∷ xs) {()}
⟦[]⟧≈zero∷[] (x 1∷ xs) {()}
⟦[]⟧≈zero∷[] (x , y 2∷ xs) {()}
--------------------------------------------------------------------------------
-- On ⟦_⟧ and ⟦_⟧ₙ
{-
⟦[]⟧ₙ≡0 : ∀ {A n} → (xs : 0-2-RAL A n) → {xs≣[] : xs ≡ []} → ⟦ xs ⟧ₙ ≡ zero ∷ []
⟦[]⟧ₙ≡0 [] = refl
⟦[]⟧ₙ≡0 ( 0∷ xs) {()}
⟦[]⟧ₙ≡0 (x 1∷ xs) {()}
⟦[]⟧ₙ≡0 (x , y 2∷ xs) {()}
⟦[]⟧≡0 : ∀ {n A} → (xs : 0-2-RAL A n) → {xs≣[] : xs ≡ []} → ⟦ xs ⟧ ≡ zero ∷ []
⟦[]⟧≡0 {n} [] {p} =
begin
n <<< (zero ∷ [])
≡⟨ {! !} ⟩
zero ∷ []
∎
⟦[]⟧≡0 ( 0∷ xs) {()}
⟦[]⟧≡0 (x 1∷ xs) {()}
⟦[]⟧≡0 (x , y 2∷ xs) {()}
-- identity
⟦[]⟧ₙ≡0 : ∀ {A n} → (xs : 0-2-RAL A n) → xs ≡ [] → ⟦ xs ⟧ₙ ≡ zero
⟦[]⟧ₙ≡0 [] p = refl
⟦[]⟧ₙ≡0 ( 0∷ xs) ()
⟦[]⟧ₙ≡0 (x 1∷ xs) ()
⟦[]⟧ₙ≡0 (x , y 2∷ xs) ()
⟦[]⟧≡0 : ∀ {n A} → (xs : 0-2-RAL A n) → xs ≡ [] → ⟦ xs ⟧ ≡ 0
⟦[]⟧≡0 {zero } [] p = refl
⟦[]⟧≡0 {suc n} [] p = *-right-zero (2 * 2 ^ n)
⟦[]⟧≡0 ( 0∷ xs) ()
⟦[]⟧≡0 (x 1∷ xs) ()
⟦[]⟧≡0 (x , y 2∷ xs) ()
⟦0∷xs⟧≡⟦xs⟧ : ∀ {n A} → (xs : 0-2-RAL A (suc n)) → ⟦ 0∷ xs ⟧ ≡ ⟦ xs ⟧
⟦0∷xs⟧≡⟦xs⟧ {zero} xs = +-right-identity (2 * ⟦ xs ⟧ₙ)
⟦0∷xs⟧≡⟦xs⟧ {suc n} xs =
begin
2 * 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ sym (*-assoc (2 * 2 ^ n) 2 ⟦ xs ⟧ₙ) ⟩
((2 * 2 ^ n) * 2) * ⟦ xs ⟧ₙ
≡⟨ cong (λ x → x * ⟦ xs ⟧ₙ) (*-comm (2 * 2 ^ n) 2) ⟩
(2 * (2 * 2 ^ n)) * ⟦ xs ⟧ₙ
∎
⟦[]⟧≡⟦[]⟧ : ∀ {m n A} → ⟦ [] {A} {m} ⟧ ≡ ⟦ [] {A} {n} ⟧
⟦[]⟧≡⟦[]⟧ {m} {n} =
begin
2 ^ m * 0
≡⟨ *-right-zero (2 ^ m) ⟩
0
≡⟨ sym (*-right-zero (2 ^ n)) ⟩
2 ^ n * 0
∎
splitIndex : ∀ {n A} → (x : BinaryLeafTree A n) → (xs : 0-2-RAL A (suc n)) → ⟦ x 1∷ xs ⟧ ≡ 1 * (2 ^ n) + ⟦ xs ⟧
splitIndex {n} x xs =
begin
2 ^ n * suc (2 * ⟦ xs ⟧ₙ)
≡⟨ +-*-suc (2 ^ n) (2 * ⟦ xs ⟧ₙ) ⟩
2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ cong (λ w → 2 ^ n + w) (sym (*-assoc (2 ^ n) 2 ⟦ xs ⟧ₙ)) ⟩
2 ^ n + (2 ^ n * 2) * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → 2 ^ n + w * ⟦ xs ⟧ₙ) (*-comm (2 ^ n) 2) ⟩
2 ^ n + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → w + (2 * 2 ^ n) * ⟦ xs ⟧ₙ) (sym (+-right-identity (2 ^ n))) ⟩
2 ^ n + 0 + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
∎
splitIndex2 : ∀ {n A} → (x : BinaryLeafTree A n) → (y : BinaryLeafTree A n) → (xs : 0-2-RAL A (suc n)) → ⟦ x , y 2∷ xs ⟧ ≡ 2 * (2 ^ n) + ⟦ xs ⟧
splitIndex2 {n} x y xs =
begin
2 ^ n * (1 + (1 + (2 * ⟦ xs ⟧ₙ)))
≡⟨ +-*-suc (2 ^ n) ((1 + (2 * ⟦ xs ⟧ₙ))) ⟩
2 ^ n + 2 ^ n * (1 + (2 * ⟦ xs ⟧ₙ))
≡⟨ cong (λ w → 2 ^ n + w) (+-*-suc (2 ^ n) (2 * ⟦ xs ⟧ₙ)) ⟩
2 ^ n + (2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ))
≡⟨ sym (+-assoc (2 ^ n) (2 ^ n) (2 ^ n * (2 * ⟦ xs ⟧ₙ))) ⟩
2 ^ n + 2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ cong (λ w → 2 ^ n + 2 ^ n + w) (sym (*-assoc (2 ^ n) 2 ⟦ xs ⟧ₙ)) ⟩
2 ^ n + 2 ^ n + (2 ^ n * 2) * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → 2 ^ n + 2 ^ n + w * ⟦ xs ⟧ₙ) (*-comm (2 ^ n) 2) ⟩
2 ^ n + 2 ^ n + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → 2 ^ n + w + (2 * 2 ^ n) * ⟦ xs ⟧ₙ) (sym (+-right-identity (2 ^ n))) ⟩
2 ^ n + (2 ^ n + 0) + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
≡⟨ refl ⟩
2 * 2 ^ n + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
∎
begin
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
∎
-}
{-
⟦[]⟧≡⟦[]⟧ : ∀ {n A} → ⟦ [] {A} {suc n} ⟧ ≡ ⟦ [] {A} {n} ⟧
⟦[]⟧≡⟦[]⟧ {n} =
begin
(2 * 2 ^ n) * 0
≡⟨ *-right-zero (2 * 2 ^ n) ⟩
0
≡⟨ sym (*-right-zero (2 ^ n)) ⟩
2 ^ n * 0
∎
⟦0∷xs⟧≡⟦xs⟧ {zero} xs = +-right-identity (2 * ⟦ xs ⟧ₙ)
⟦0∷xs⟧≡⟦xs⟧ {suc n} xs =
begin
2 * 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ sym (*-assoc (2 * 2 ^ n) 2 ⟦ xs ⟧ₙ) ⟩
2 * 2 ^ n * 2 * ⟦ xs ⟧ₙ
≡⟨ cong (λ x → x * ⟦ xs ⟧ₙ) (*-assoc 2 (2 ^ n) 2) ⟩
2 * (2 ^ n * 2) * ⟦ xs ⟧ₙ
≡⟨ cong (λ x → 2 * x * ⟦ xs ⟧ₙ) (*-comm (2 ^ n) 2) ⟩
(2 * (2 * 2 ^ n)) * ⟦ xs ⟧ₙ
∎
⟦0∷xs⟧≢0⇒⟦xs⟧≢0 : ∀ {n A}
→ (xs : 0-1-RAL A (suc n))
→ ⟦ 0∷ xs ⟧ ≢ 0
→ ⟦ xs ⟧ ≢ 0
⟦0∷xs⟧≢0⇒⟦xs⟧≢0 xs p = contraposition (trans (⟦0∷xs⟧≡⟦xs⟧ xs)) p
-}
|
{
"alphanum_fraction": 0.3347098906,
"avg_line_length": 31.0448717949,
"ext": "agda",
"hexsha": "cba53d3a581b08964ca9788cdc0e0d7c61652d66",
"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": "legacy/RandomAccessList/Redundant/Core/Properties.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": "legacy/RandomAccessList/Redundant/Core/Properties.agda",
"max_line_length": 143,
"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": "legacy/RandomAccessList/Redundant/Core/Properties.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": 2741,
"size": 4843
}
|
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Equational.Theory
module Fragment.Equational.Model.Synthetic (Θ : Theory) where
open import Fragment.Algebra.Signature
open import Fragment.Algebra.Algebra (Σ Θ)
open import Fragment.Algebra.Free (Σ Θ)
open import Fragment.Algebra.Homomorphism (Σ Θ)
open import Fragment.Algebra.Quotient (Σ Θ)
open import Fragment.Equational.Model.Base Θ
using (Model; IsModel; Models)
open import Fragment.Setoid.Morphism using (_·_)
open import Level using (Level; _⊔_)
open import Function using (_∘_)
open import Data.Empty using (⊥)
open import Data.Nat using (ℕ)
open import Data.Product using (proj₁; proj₂)
open import Data.Vec using (map)
open import Data.Vec.Relation.Binary.Pointwise.Inductive
using (Pointwise; []; _∷_)
open import Relation.Binary using (Setoid; IsEquivalence)
import Relation.Binary.PropositionalEquality as PE
private
variable
a ℓ : Level
module _ (A : Algebra {a} {ℓ}) where
infix 4 _≊_
data _≊_ : ∥ A ∥ → ∥ A ∥ → Set (a ⊔ ℓ) where
refl : ∀ {x} → x ≊ x
sym : ∀ {x y} → x ≊ y → y ≊ x
trans : ∀ {x y z} → x ≊ y → y ≊ z → x ≊ z
inherit : ∀ {x y} → x =[ A ] y → x ≊ y
cong : ∀ {n} → (f : ops (Σ Θ) n)
→ ∀ {xs ys} → Pointwise _≊_ xs ys
→ A ⟦ f ⟧ xs ≊ A ⟦ f ⟧ ys
axiom : ∀ {n} → (eq : eqs Θ n) → (θ : Env A n)
→ ∣ inst A θ ∣ (proj₁ (Θ ⟦ eq ⟧ₑ))
≊ ∣ inst A θ ∣ (proj₂ (Θ ⟦ eq ⟧ₑ))
private
≊-isEquivalence : IsEquivalence _≊_
≊-isEquivalence = record { refl = refl
; sym = sym
; trans = trans
}
instance
≊-isDenom : IsDenominator A _≊_
≊-isDenom = record { isEquivalence = ≊-isEquivalence
; isCompatible = cong
; isCoarser = inherit
}
Synthetic : Model
Synthetic = record { ∥_∥/≈ = ∥ A ∥/ _≊_
; isModel = isModel
}
where open module T = Setoid (∥ A ∥/ _≊_)
open import Relation.Binary.Reasoning.Setoid (∥ A ∥/ _≊_)
models : Models (A / _≊_)
models eq θ = begin
∣ inst (A / _≊_) θ ∣ lhs
≈⟨ T.sym (lemma {x = lhs}) ⟩
∣ (inc A _≊_) ⊙ (inst A θ) ∣ lhs
≈⟨ axiom eq θ ⟩
∣ (inc A _≊_) ⊙ (inst A θ) ∣ rhs
≈⟨ lemma {x = rhs} ⟩
∣ inst (A / _≊_) θ ∣ rhs
∎
where lhs = proj₁ (Θ ⟦ eq ⟧ₑ)
rhs = proj₂ (Θ ⟦ eq ⟧ₑ)
lemma = inst-universal (A / _≊_) θ
{h = (inc A _≊_) ⊙ (inst A θ) }
(λ x → PE.refl)
isModel : IsModel (∥ A ∥/ _≊_)
isModel = record { isAlgebra = A / _≊_ -isAlgebra
; models = models
}
J : ℕ → Model
J = Synthetic ∘ F
|
{
"alphanum_fraction": 0.4921008403,
"avg_line_length": 31.6489361702,
"ext": "agda",
"hexsha": "32617ddafbbe13560debc769b256eef8816f5321",
"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/Equational/Model/Synthetic.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/Equational/Model/Synthetic.agda",
"max_line_length": 67,
"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/Equational/Model/Synthetic.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": 986,
"size": 2975
}
|
------------------------------------------------------------------------------
-- Simple example of a nested recursive function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- From: Ana Bove and Venanzio Capretta. Nested general recursion and
-- partiality in type theory. Vol. 2152 of LNCS. 2001.
module FOTC.Program.Nest.Nest where
open import FOTC.Base
------------------------------------------------------------------------------
-- The nest function.
postulate
nest : D → D
nest-0 : nest zero ≡ zero
nest-S : ∀ n → nest (succ₁ n) ≡ nest (nest n)
{-# ATP axioms nest-0 nest-S #-}
|
{
"alphanum_fraction": 0.4319018405,
"avg_line_length": 33.9583333333,
"ext": "agda",
"hexsha": "31ebb03ba6e664548815b83a99426e8a3b517f04",
"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": "src/fot/FOTC/Program/Nest/Nest.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": "src/fot/FOTC/Program/Nest/Nest.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": "src/fot/FOTC/Program/Nest/Nest.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": 162,
"size": 815
}
|
-- Jesper, 2015-12-18: the helper function shouldn't be accepted, since it
-- matches on a heterogeneous equality and the equation between the types
-- Box A and Box B cannot be solved without injective type constructors.
data Box (A : Set) : Set where
[_] : A → Box A
data _≡_ (A : Set) : Set → Set₁ where
refl : A ≡ A
data _≅_ {A : Set₁} (x : A) : {B : Set₁} → B → Set₂ where
refl : x ≅ x
data C : Set → Set₁ where
c₁ c₂ : (A : Set) → C (Box A)
data D : {A : Set} → C A → Set₂ where
d₁ : (A : Set) → D (c₁ A)
d₂ : (A : Set) → D (c₂ A)
D-elim-c₁-helper :
(P : {A B : Set} {c : C A} →
D c → A ≡ Box B → c ≅ c₁ B → Set₂) →
((A : Set) → P (d₁ A) refl refl) →
{A B : Set} {c : C A}
(x : D c) (eq₂ : c ≅ c₁ B) (eq₁ : A ≡ Box B) → P x eq₁ eq₂
D-elim-c₁-helper P p (d₂ A) () _
D-elim-c₁-helper P p (d₁ A) refl refl = p A
|
{
"alphanum_fraction": 0.5458823529,
"avg_line_length": 29.3103448276,
"ext": "agda",
"hexsha": "1462b56fae015a50ba80a74964ec63d986b5fa66",
"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/Issue1435-helper.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/Issue1435-helper.agda",
"max_line_length": 74,
"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/Issue1435-helper.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": 357,
"size": 850
}
|
module sum-downFrom where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; cong)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _≤_; s≤s; z≤n)
open import Data.Nat.Properties using
(*-suc; *-identityʳ; *-distribʳ-+; *-distribˡ-∸; +-∸-assoc; +-∸-comm; m+n∸m≡n; m≤m*n)
open import lists using (List; []; _∷_; [_,_,_]; sum)
-- (n - 1), ⋯ , 0 を返す
downFrom : ℕ → List ℕ
downFrom zero = []
downFrom (suc n) = n ∷ downFrom n
_ : downFrom 3 ≡ [ 2 , 1 , 0 ]
_ = refl
-- n ≤ n * n の証明
n≤n*n : ∀ (n : ℕ) → n ≤ n * n
n≤n*n zero = z≤n
n≤n*n (suc n) = m≤m*n (suc n) (s≤s z≤n)
-- n ≤ n * 2 の証明
n≤n*2 : ∀ (n : ℕ) → n ≤ n * 2
n≤n*2 n = m≤m*n n (s≤s z≤n)
-- n * 2 ∸ n = n の証明
n*2∸n≡n : ∀ (n : ℕ) → n * 2 ∸ n ≡ n
n*2∸n≡n n =
begin
n * 2 ∸ n
≡⟨ cong (_∸ n) (*-suc n 1) ⟩ -- 積の展開
n + n * 1 ∸ n
≡⟨ m+n∸m≡n n (n * 1) ⟩ -- n ∸ n の除去
n * 1
≡⟨ *-identityʳ n ⟩ -- * 1 の除去
n
∎
-- m * (n ∸ 1) = m * n ∸ m の証明
m*[n∸1]≡m*n∸m : ∀ (m n : ℕ) → m * (n ∸ 1) ≡ m * n ∸ m
m*[n∸1]≡m*n∸m m n =
begin
m * (n ∸ 1)
≡⟨ *-distribˡ-∸ m n 1 ⟩ -- n * の分配
m * n ∸ m * 1
≡⟨ cong (m * n ∸_) (*-identityʳ m) ⟩ -- * 1 の除去
m * n ∸ m
∎
-- (n - 1) + ⋯ + 0 と n * (n ∸ 1) / 2 が等しいことの証明
sum-downFrom : ∀ (n : ℕ) → sum (downFrom n) * 2 ≡ n * (n ∸ 1)
sum-downFrom zero =
begin
sum (downFrom zero) * 2
≡⟨⟩
sum [] * 2
≡⟨⟩
zero
-- = zero * (zero ∸ 1)
∎
sum-downFrom (suc n) =
begin
sum (downFrom (suc n)) * 2
≡⟨⟩
sum (n ∷ downFrom n) * 2
≡⟨⟩
(n + sum (downFrom n)) * 2
≡⟨ *-distribʳ-+ 2 n (sum (downFrom n)) ⟩ -- * 2 の分配
(n * 2) + (sum (downFrom n)) * 2
≡⟨ cong (n * 2 +_) (sum-downFrom n) ⟩ -- 帰納法
(n * 2) + (n * (n ∸ 1))
≡⟨ cong (n * 2 +_) (m*[n∸1]≡m*n∸m n n) ⟩ -- n * の分配
(n * 2) + (n * n ∸ n)
≡⟨ sym (+-∸-assoc (n * 2) (n≤n*n n)) ⟩ -- 結合法則
(n * 2) + n * n ∸ n
≡⟨ +-∸-comm (n * n) (n≤n*2 n) ⟩ -- 交換法則
(n * 2) ∸ n + n * n
≡⟨ cong (_+ n * n) (n*2∸n≡n n) ⟩ -- n ∸ n の除去
n + n * n
-- = n * (suc n)
-- = (suc n) * n
-- = (suc n) * ((suc n) ∸ 1)
∎
|
{
"alphanum_fraction": 0.4249642687,
"avg_line_length": 24.1264367816,
"ext": "agda",
"hexsha": "14301fd8a7dfba069f44363617059136f4432394",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/lists/sum-downFrom.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/lists/sum-downFrom.agda",
"max_line_length": 87,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/lists/sum-downFrom.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 1246,
"size": 2099
}
|
open import Categories
open import Functors
open import RMonads
module RMonads.REM {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}
(M : RMonad J) where
open import Library
open RMonad M
open Fun
record RAlg : Set (a ⊔ c ⊔ d) where
constructor ralg
open Cat D
field acar : Obj
astr : ∀ {Z} → Hom (OMap J Z) acar → Hom (T Z) acar
alaw1 : ∀ {Z}{f : Hom (OMap J Z) acar} →
f ≅ comp (astr f) η
alaw2 : ∀{Z}{W}{k : Hom (OMap J Z) (T W)}
{f : Hom (OMap J W) acar} →
astr (comp (astr f) k) ≅ comp (astr f) (bind k)
AlgEq : {X Y : RAlg} → RAlg.acar X ≅ RAlg.acar Y →
((λ {Z} → RAlg.astr X {Z}) ≅ (λ {Z} → RAlg.astr Y {Z})) →
X ≅ Y
AlgEq {ralg acar astr _ _}{ralg .acar .astr _ _} refl refl = let open Cat in
cong₂ (ralg acar astr)
(iext λ _ → iext λ _ → ir _ _)
(iext λ _ → iext λ _ → iext λ _ → iext λ _ → ir _ _)
astrnat : ∀(alg : RAlg){X Y}
(f : Cat.Hom C X Y) →
(g : Cat.Hom D (OMap J X) (RAlg.acar alg))
(g' : Cat.Hom D (OMap J Y) (RAlg.acar alg)) →
Cat.comp D g' (HMap J f) ≅ g →
Cat.comp D (RAlg.astr alg g')
(RMonad.bind M (Cat.comp D (RMonad.η M) (HMap J f)))
≅
RAlg.astr alg g
astrnat alg f g g' p = let
open RAlg alg; open Cat D in
proof
comp (astr g') (bind (comp η (HMap J f)))
≅⟨ sym alaw2 ⟩
astr (comp (astr g') (comp η (HMap J f)))
≅⟨ cong astr (sym ass) ⟩
astr (comp (comp (astr g') η) (HMap J f))
≅⟨ cong (λ g₁ → astr (comp g₁ (HMap J f))) (sym alaw1) ⟩
astr (comp g' (HMap J f))
≅⟨ cong astr p ⟩
astr g ∎
record RAlgMorph (A B : RAlg) : Set (a ⊔ c ⊔ d)
where
constructor ralgmorph
open Cat D
open RAlg
field amor : Hom (acar A) (acar B)
ahom : ∀{Z}{f : Hom (OMap J Z) (acar A)} →
comp amor (astr A f) ≅ astr B (comp amor f)
open RAlgMorph
RAlgMorphEq : ∀{X Y : RAlg}{f g : RAlgMorph X Y} → amor f ≅ amor g → f ≅ g
RAlgMorphEq {X}{Y}{ralgmorph amor _}{ralgmorph .amor _} refl =
cong (ralgmorph amor) (iext λ _ → iext λ _ → ir _ _)
lemZ : ∀{X X' Y Y' : RAlg}
{f : RAlgMorph X Y}{g : RAlgMorph X' Y'} → X ≅ X' → Y ≅ Y' →
amor f ≅ amor g → f ≅ g
lemZ refl refl = RAlgMorphEq
IdMorph : ∀{A : RAlg} → RAlgMorph A A
IdMorph {A} = let open Cat D; open RAlg A in record {
amor = iden;
ahom = λ {_ f} →
proof
comp iden (astr f)
≅⟨ idl ⟩
astr f
≅⟨ cong astr (sym idl) ⟩
astr (comp iden f)
∎}
CompMorph : ∀{X Y Z : RAlg} →
RAlgMorph Y Z → RAlgMorph X Y → RAlgMorph X Z
CompMorph {X}{Y}{Z} f g = let open Cat D; open RAlg in record {
amor = comp (amor f) (amor g);
ahom = λ {_ f'} →
proof
comp (comp (amor f) (amor g)) (astr X f')
≅⟨ ass ⟩
comp (amor f) (comp (amor g) (astr X f'))
≅⟨ cong (comp (amor f)) (ahom g) ⟩
comp (amor f) (astr Y (comp (amor g) f'))
≅⟨ ahom f ⟩
astr Z (comp (amor f) (comp (amor g) f'))
≅⟨ cong (astr Z) (sym ass) ⟩
astr Z (comp (comp (amor f) (amor g)) f')
∎}
idlMorph : {X Y : RAlg}{f : RAlgMorph X Y} →
CompMorph IdMorph f ≅ f
idlMorph = RAlgMorphEq (Cat.idl D)
idrMorph : ∀{X Y : RAlg}{f : RAlgMorph X Y} →
CompMorph f IdMorph ≅ f
idrMorph = RAlgMorphEq (Cat.idr D)
assMorph : ∀{W X Y Z : RAlg}
{f : RAlgMorph Y Z}{g : RAlgMorph X Y}{h : RAlgMorph W X} →
CompMorph (CompMorph f g) h ≅ CompMorph f (CompMorph g h)
assMorph = RAlgMorphEq (Cat.ass D)
EM : Cat
EM = record{
Obj = RAlg;
Hom = RAlgMorph;
iden = IdMorph;
comp = CompMorph;
idl = idlMorph;
idr = idrMorph;
ass = λ{_ _ _ _ f g h} → assMorph {f = f}{g}{h}}
|
{
"alphanum_fraction": 0.5230192719,
"avg_line_length": 30.1290322581,
"ext": "agda",
"hexsha": "116a9d74eb27a9da5b8db966536e91480a937f3d",
"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/REM.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/REM.agda",
"max_line_length": 76,
"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/REM.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": 1570,
"size": 3736
}
|
module Data.Bool.Instance where
open import Class.Equality
open import Class.Show
open import Data.Bool
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
instance
Bool-Eq : Eq Bool
Bool-Eq = record { _≟_ = helper }
where
helper : ∀ (x y : Bool) → Dec (x ≡ y)
helper false false = yes refl
helper false true = no (λ ())
helper true false = no (λ ())
helper true true = yes refl
Bool-Show : Show Bool
Bool-Show = record { show = λ { false → "false" ; true → "true" } }
|
{
"alphanum_fraction": 0.6506469501,
"avg_line_length": 25.7619047619,
"ext": "agda",
"hexsha": "7f01124a4460d6ab72bde7de683d4b2a22ce6ba7",
"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/Bool/Instance.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/Bool/Instance.agda",
"max_line_length": 69,
"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/Bool/Instance.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": 148,
"size": 541
}
|
module Type.Properties.Empty{ℓ} where
import Lvl
open import Type
-- A type is empty when "empty functions" exists for it, which essentially means that there are no objects with this type.
-- This is an useful definition because the empty type is not unique (There are an infinite number of "empty types").
-- An explanation for why there are an infinite number of them:
-- · Types are not equal to each other extensionally (unlike sets, type equality is not based on their inhabitants (set equality is based on which elements that the set contains)).
-- An alternative explanation:
-- · Type equality is nominal (loosely: based on its name (assuming no other type could be named the same)), and not representional.
-- Or more simply by an example:
-- · `data Empty : Type where` defines an empty type.
-- `data Empty2 : Type where` also defines an empty type.
-- Now, `Empty` is not type equal to `Empty2` because the terms does not normalize further (by the rules of the language).
-- So by proving IsEmpty(T), it means that the type T is empty, because empty types are the only types that has the property of having empty functions.
record IsEmpty (T : Type{ℓ}) : Type{Lvl.𝐒(ℓ)} where
constructor intro
field
-- Empty functions for an empty type
-- For any type U, it is always possible to construct a function from T to U if T is empty
empty : ∀{U : Type{ℓ}} → T → U
|
{
"alphanum_fraction": 0.7317596567,
"avg_line_length": 60.7826086957,
"ext": "agda",
"hexsha": "865735c5b7620566d105ff6a62cf9e679c9607b2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Type/Properties/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Type/Properties/Empty.agda",
"max_line_length": 180,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Type/Properties/Empty.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": 340,
"size": 1398
}
|
{-# OPTIONS --without-K --exact-split --safe #-}
module Fragment.Equational.Theory where
open import Fragment.Equational.Theory.Base public
|
{
"alphanum_fraction": 0.7605633803,
"avg_line_length": 23.6666666667,
"ext": "agda",
"hexsha": "49f39404073f6749ca5ae5cfe560fbd7e0998543",
"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/Equational/Theory.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/Equational/Theory.agda",
"max_line_length": 50,
"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/Equational/Theory.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": 31,
"size": 142
}
|
{-# OPTIONS --without-K --safe #-}
module Cats.Limit where
open import Level
open import Cats.Category.Base
open import Cats.Category.Cones as Cones using
(Cone ; Cones ; ConesF ; cone-iso→obj-iso)
open import Cats.Category.Constructions.Terminal using (HasTerminal)
open import Cats.Category.Constructions.Unique using (∃!′)
open import Cats.Category.Fun as Fun using (Trans ; _↝_)
open import Cats.Functor using (Functor)
open import Cats.Util.Conv
import Cats.Category.Constructions.Terminal as Terminal
import Cats.Category.Constructions.Iso as Iso
open Cone
open Cones._⇒_
open Functor
open Fun._≈_
open Trans
private
module Cs {lo la l≈ lo′ la′ l≈′} {C : Category lo la l≈}
{D : Category lo′ la′ l≈′} {F : Functor C D} = Category (Cones F)
module _ {lo la l≈ lo′ la′ l≈′}
{J : Category lo la l≈}
{Z : Category lo′ la′ l≈′}
where
private
module J = Category J
module Z = Category Z
IsLimit : {D : Functor J Z} → Cone D → Set (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′)
IsLimit {D} = Terminal.IsTerminal {C = Cones D}
record Limit (D : Functor J Z) : Set (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′) where
field
cone : Cone D
isLimit : IsLimit cone
open Cone cone using () renaming (arr to proj)
private
hasTerminal : HasTerminal (Cones D)
hasTerminal = record { ⊤ = cone ; isTerminal = isLimit }
open HasTerminal hasTerminal public using
( ! ; !-unique ) renaming
( ⊤-unique to cone-unique
; ⇒⊤-unique to ⇒cone-unique )
!! : (cone′ : Cone D) → cone′ .Cone.Apex Z.⇒ cone .Cone.Apex
!! cone′ = ! cone′ .arr
!!-unique : {cone′ : Cone D} (f : cone′ Cs.⇒ cone)
→ !! cone′ Z.≈ f .arr
!!-unique f = !-unique f
arr∘!! : ∀ cone′ {j} → proj j Z.∘ !! cone′ Z.≈ cone′ .Cone.arr j
arr∘!! cone′ = ! cone′ .commute _
!!∘ : ∀ {C D} (f : C Cs.⇒ D)
→ !! D Z.∘ f .arr Z.≈ !! C
!!∘ {C} {D} f = Z.≈.sym (!!-unique record
{ commute = λ j →
let open Z.≈-Reasoning in
begin
proj j Z.∘ !! D Z.∘ f .arr
≈⟨ Z.unassoc ⟩
(proj j Z.∘ !! D) Z.∘ f .arr
≈⟨ Z.∘-resp-l (arr∘!! D) ⟩
D .arr j Z.∘ f .arr
≈⟨ f .commute j ⟩
C .arr j
∎
})
open Cone cone public
open Limit public
instance
HasObj-Limit : ∀ {D} → HasObj (Limit D) _ _ _
HasObj-Limit {D} = record { Cat = Cones D ; _ᴼ = cone }
module _ {D : Functor J Z} where
unique : (l m : Limit D) → Iso.Build._≅_ (Cones D) (l ᴼ) (m ᴼ)
unique l m = Terminal.terminal-unique (isLimit l) (isLimit m)
obj-unique : (l m : Limit D) → Iso.Build._≅_ Z (l ᴼ ᴼ) (m ᴼ ᴼ)
obj-unique l m = cone-iso→obj-iso _ (unique l m)
module _ {F G : Functor J Z} where
trans : (ϑ : Trans F G) (l : Limit F) (m : Limit G)
→ l .Apex Z.⇒ m .Apex
trans ϑ l m = !! m (ConesF .fmap ϑ .fobj (l .cone))
arr∘trans : ∀ ϑ l m c
→ m .arr c Z.∘ trans ϑ l m
Z.≈ ϑ .component c Z.∘ l .arr c
arr∘trans ϑ l m c = arr∘!! m (ConesF .fmap ϑ .fobj (l .cone))
trans-resp : ∀ {ϑ ι} l m
→ ϑ Fun.≈ ι
→ trans ϑ l m Z.≈ trans ι l m
trans-resp {ϑ} {ι} l m ϑ≈ι = !!-unique m record
{ commute = λ j → Z.≈.trans (arr∘trans ι l m j)
(Z.∘-resp-l (Z.≈.sym (≈-elim ϑ≈ι)))
}
trans-id : {F : Functor J Z} (l : Limit F)
→ trans Fun.id l l Z.≈ Z.id
trans-id l = !!-unique l record
{ commute = λ j → Z.≈.trans Z.id-r (Z.≈.sym Z.id-l)
}
trans-∘ : {F G H : Functor J Z} (ϑ : Trans G H) (ι : Trans F G)
→ ∀ l m n
→ trans ϑ m n Z.∘ trans ι l m Z.≈ trans (ϑ Fun.∘ ι) l n
trans-∘ {F} {G} {H} ϑ ι l m n = Z.≈.sym (!!-unique n record
{ commute = λ j → let open Z.≈-Reasoning in
begin
n .arr j Z.∘ trans ϑ m n Z.∘ trans ι l m
≈⟨ Z.unassoc ⟩
(n .arr j Z.∘ trans ϑ m n) Z.∘ trans ι l m
≈⟨ Z.∘-resp-l (arr∘trans ϑ m n j ) ⟩
(ϑ .component j Z.∘ m .arr j) Z.∘ trans ι l m
≈⟨ Z.assoc ⟩
ϑ .component j Z.∘ m .arr j Z.∘ trans ι l m
≈⟨ Z.∘-resp-r (arr∘trans ι l m j) ⟩
ϑ .component j Z.∘ ι .component j Z.∘ l .arr j
≈⟨ Z.unassoc ⟩
(ϑ Fun.∘ ι) .component j Z.∘ l .arr j
∎
})
record _HasLimitsOf_
{lo la l≈} (C : Category lo la l≈) {lo′ la′ l≈′} (J : Category lo′ la′ l≈′)
: Set (lo ⊔ la ⊔ l≈ ⊔ lo′ ⊔ la′ ⊔ l≈′ )
where
private
module C = Category C
module J↝C = Category (J ↝ C)
field
lim′ : (F : Functor J C) → Limit F
lim : Functor J C → C.Obj
lim F = lim′ F .cone .Apex
limF : Functor (J ↝ C) C
limF = record
{ fobj = λ F → lim F
; fmap = λ {F} {G} ϑ → trans ϑ (lim′ _) (lim′ _)
; fmap-resp = λ ϑ≈ι → trans-resp (lim′ _) (lim′ _) ϑ≈ι
; fmap-id = trans-id (lim′ _)
; fmap-∘ = trans-∘ _ _ (lim′ _) (lim′ _) (lim′ _)
}
record Complete {lo la l≈} (C : Category lo la l≈) lo′ la′ l≈′
: Set (lo ⊔ la ⊔ l≈ ⊔ suc (lo′ ⊔ la′ ⊔ l≈′))
where
field
lim′ : ∀ {J : Category lo′ la′ l≈′} (F : Functor J C) → Limit F
hasLimitsOf : (J : Category lo′ la′ l≈′) → C HasLimitsOf J
hasLimitsOf J ._HasLimitsOf_.lim′ = lim′
private
open module HasLimitsOf {J} = _HasLimitsOf_ (hasLimitsOf J) public hiding (lim′)
preservesLimits : ∀ {lo la l≈ lo′ la′ l≈′}
→ {C : Category lo la l≈} {D : Category lo′ la′ l≈′}
→ Functor C D
→ (lo″ la″ l≈″ : Level)
→ Set _
preservesLimits {C = C} F lo″ la″ l≈″
= {J : Category lo″ la″ l≈″}
→ {D : Functor J C}
→ {c : Cone D}
→ IsLimit c
→ IsLimit (Cones.apFunctor F c)
|
{
"alphanum_fraction": 0.5264960346,
"avg_line_length": 25.4495412844,
"ext": "agda",
"hexsha": "aa079b44703a03d74aba41c45bf98c59d10ff9c3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Limit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"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": "JLimperg/cats",
"max_issues_repo_path": "Cats/Limit.agda",
"max_line_length": 84,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Limit.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 2268,
"size": 5548
}
|
module Generic.Lib.Equality.Congn where
open import Generic.Lib.Intro
open import Generic.Lib.Equality.Propositional
open import Generic.Lib.Data.Product
open import Generic.Lib.Data.Nat
open import Generic.Lib.Data.Pow
open import Generic.Lib.Data.Sets
zip≡ : ∀ {n αs} {As : Sets {n} αs} -> HList As -> HList As -> Sets (replicatePow n lzero)
zip≡ {0} tt tt = tt
zip≡ {suc _} (x , xs) (y , ys) = (x ≡ y) , zip≡ xs ys
congn : ∀ {β} {B : Set β} n {αs} {As : Sets {n} αs} {xs ys : HList As}
-> (f : FoldSets As B) -> FoldSets (zip≡ xs ys) (applyFoldSets f xs ≡ applyFoldSets f ys)
congn 0 y = refl
congn (suc n) f refl = congn n (f _)
private
module Test where
cong′ : ∀ {α β} {A : Set α} {B : Set β} {x y} -> (f : A -> B) -> x ≡ y -> f x ≡ f y
cong′ = congn 1
cong₂′ : ∀ {α β γ} {A : Set α} {B : Set β} {C : Set γ} {x₁ x₂ y₁ y₂}
-> (g : A -> B -> C) -> x₁ ≡ x₂ -> y₁ ≡ y₂ -> g x₁ y₁ ≡ g x₂ y₂
cong₂′ = congn 2
|
{
"alphanum_fraction": 0.5584016393,
"avg_line_length": 36.1481481481,
"ext": "agda",
"hexsha": "cad733e0e5597474c9f46d76b1295eeae5e2efe3",
"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": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Equality/Congn.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"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": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Equality/Congn.agda",
"max_line_length": 95,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Equality/Congn.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": 389,
"size": 976
}
|
postulate
A : Set
a : A
data D : A → Set where
d : (a : A) → D a
f : A → (D a → Set) → Set
f a f = f (d a)
-- Bad error:
-- a != a of type A
-- when checking that the pattern d a has type D a
-- Better error:
-- a != a of type A
-- (because one is a variable and one a defined identifier)
-- when checking that the pattern d a has type D a
|
{
"alphanum_fraction": 0.5885714286,
"avg_line_length": 18.4210526316,
"ext": "agda",
"hexsha": "479a5f5c40c399667b8c6d9ab6ca9843c048990a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/Issue998.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"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": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue998.agda",
"max_line_length": 59,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue998.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": 118,
"size": 350
}
|
module TermShape where
open import Relation.Unary using (_∈_; _⊆_)
open import Size
open import Library
open import Terms
open import Substitution
-- Evaluation contexts.
data ECxt (Γ : Cxt) : (a b : Ty) → Set where
appl : ∀ {a b} (u : Tm Γ a) → ECxt Γ (a →̂ b) b
-- Ehole Et E t ~~ Et = E[t]
data Ehole {Γ : Cxt} : {a b : Ty} → Tm Γ b → ECxt Γ a b → Tm Γ a → Set where
appl : ∀ {a b} {t : Tm Γ (a →̂ b)} (u : Tm Γ a) → Ehole (app t u) (appl u) t
-- Evaluation contexts are closed under substitution.
substEC : ∀ {i vt Γ Δ a b} → (σ : RenSub {i} vt Γ Δ) → ECxt Γ a b → ECxt Δ a b
substEC σ (appl u) = appl (subst σ u)
substEh : ∀ {i vt Γ Δ a b} → (σ : RenSub {i} vt Γ Δ) → ∀ {E}{Et : Tm Γ b}{t : Tm Γ a} → (Eh : Ehole Et E t)
→ Ehole (subst σ Et) (substEC σ E) (subst σ t)
substEh σ (appl u) = appl (subst σ u)
mkEHole : ∀ {Γ} {a b} (E : ECxt Γ a b) {t} → ∃ λ E[t] → Ehole E[t] E t
mkEHole (appl u) = _ , appl u
_[_] : ∀ {Γ} {a b} (E : ECxt Γ a b) (t : Tm Γ a) → Tm Γ b
E [ t ] = proj₁ (mkEHole E {t})
data ECxt* (Γ : Cxt) : Ty → Ty → Set where
[] : ∀ {a} → ECxt* Γ a a
_∷_ : ∀ {a₀ a₁ a₂} → ECxt Γ a₀ a₁ → ECxt* Γ a₁ a₂ → ECxt* Γ a₀ a₂
_[_]* : ∀ {Γ} {a b} (E : ECxt* Γ a b) (t : Tm Γ a) → Tm Γ b
[] [ t ]* = t
(E ∷ Es) [ t ]* = Es [ E [ t ] ]*
_++*_ : ∀ {Γ a b c} → ECxt* Γ a b → ECxt* Γ b c → ECxt* Γ a c
[] ++* ys = ys
(x ∷ xs) ++* ys = x ∷ (xs ++* ys)
_∷r_ : ∀ {Γ a b c} → ECxt* Γ a b → ECxt Γ b c → ECxt* Γ a c
xs ∷r x = xs ++* (x ∷ [])
data Ehole* {Γ : Cxt} : {a b : Ty} → Tm Γ b → ECxt* Γ a b → Tm Γ a → Set where
[] : ∀ {a} {t : Tm Γ a} → Ehole* t [] t
_∷_ : ∀ {a b c t} {E : ECxt Γ b c} {Es : ECxt* Γ a b} {EEst Est}
→ Ehole EEst E Est → Ehole* Est Es t → Ehole* EEst (Es ∷r E) t
-- Inductive definition of strong normalization.
-- Parameterized evaluation contexts
data PCxt {Γ : Cxt} (P : ∀{c} → Tm Γ c → Set) : {a b : Ty} → Tm Γ b → ECxt Γ a b → Tm Γ a → Set where
appl : ∀ {a b u}{t : Tm _ (a →̂ b)}
→ (𝒖 : P u)
→ PCxt P (app t u) (appl u) t
-- Parameterized neutral terms.
data PNe {Γ} (P : ∀{c} → Tm Γ c → Set) {b} : Tm Γ b → Set where
var : ∀ x → PNe P (var x)
elim : ∀ {a} {t : Tm Γ a} {E Et}
→ (𝒏 : PNe P t) (𝑬𝒕 : PCxt P Et E t) → PNe P Et
-- Parametrized weak head reduction
infix 10 _/_⇒_
data _/_⇒_ {Γ} (P : ∀{c} → Tm Γ c → Set): ∀ {a} → Tm Γ a → Tm Γ a → Set where
β : ∀ {a b}{t : Tm (a ∷ Γ) b}{u}
→ (𝒖 : P u)
→ P / (app (abs t) u) ⇒ subst0 u t
cong : ∀ {a b t t' Et Et'}{E : ECxt Γ a b}
→ (𝑬𝒕 : Ehole Et E t)
→ (𝑬𝒕' : Ehole Et' E t')
→ (t⇒ : P / t ⇒ t')
→ P / Et ⇒ Et'
-- Weak head reduction is deterministic.
detP⇒ : ∀ {a Γ} {P : ∀ {c} → Tm Γ c → Set} {t t₁ t₂ : Tm Γ a}
→ (t⇒₁ : P / t ⇒ t₁) (t⇒₂ : P / t ⇒ t₂) → t₁ ≡ t₂
{-
detP⇒ (β 𝒖) (β 𝒖₁) = ≡.refl
detP⇒ (β 𝒖) (cong (appl u) (appl .u) (cong () 𝑬𝒕' d'))
detP⇒ (cong (appl u) (appl .u) (cong () 𝑬𝒕' d)) (β 𝒖)
detP⇒ (cong (appl u) (appl .u) d) (cong (appl .u) (appl .u) d') = ≡.cong (λ t → app t u) (detP⇒ d d')
-}
detP⇒ (β _) (β _) = ≡.refl
detP⇒ (β _) (cong (appl u) (appl .u) (cong () _ _))
detP⇒ (cong (appl u) (appl .u) (cong () _ _)) (β _)
detP⇒ (cong (appl u) (appl .u) x) (cong (appl .u) (appl .u) y) = ≡.cong (λ t → app t u) (detP⇒ x y)
-- Neutrals are closed under application.
pneApp : ∀{Γ a b}{P : ∀{c} → Tm Γ c → Set}{t : Tm Γ (a →̂ b)}{u : Tm Γ a} →
PNe P t → P u → PNe P (app t u)
pneApp 𝒏 𝒖 = elim 𝒏 (appl 𝒖)
-- Functoriality of the notions wrt. P.
mapPCxt : ∀ {Γ} {P Q : ∀{c} → Tm Γ c → Set} (P⊆Q : ∀ {c}{t : Tm Γ c} → P t → Q t) {a b} {E : ECxt Γ a b}{Et t} → PCxt P Et E t -> PCxt Q Et E t
mapPCxt P⊆Q (appl u∈P) = appl (P⊆Q u∈P)
mapPNe : ∀ {Γ} {P Q : ∀{c} → Tm Γ c → Set} (P⊆Q : ∀ {c}{t : Tm Γ c} → P t → Q t) {a}{t : Tm Γ a} → PNe P t -> PNe Q t
mapPNe P⊆Q (var x) = var x
mapPNe P⊆Q (elim t∈Ne E∈SNh) = elim (mapPNe P⊆Q t∈Ne) (mapPCxt P⊆Q E∈SNh)
mapP⇒ : ∀ {Γ} {P Q : ∀{c} → Tm Γ c → Set} (P⊆Q : ∀ {c}{t : Tm Γ c} → P t → Q t) {a}{t t' : Tm Γ a} → P / t ⇒ t' → Q / t ⇒ t'
mapP⇒ P⊆Q (β t∈P) = β (P⊆Q t∈P)
mapP⇒ P⊆Q (cong Et Et' t→t') = cong Et Et' (mapP⇒ P⊆Q t→t')
_[_]⇒ : ∀ {Γ} {P : ∀{c} → Tm Γ c → Set} {a b} (E : ECxt Γ a b) {t₁ t₂ : Tm Γ a} → P / t₁ ⇒ t₂ → P / E [ t₁ ] ⇒ E [ t₂ ]
E [ t⇒ ]⇒ = cong (proj₂ (mkEHole E)) (proj₂ (mkEHole E)) t⇒
_[_]⇒* : ∀ {Γ} {P : ∀{c} → Tm Γ c → Set} {a b} (E : ECxt* Γ a b) {t₁ t₂ : Tm Γ a} → P / t₁ ⇒ t₂ → P / E [ t₁ ]* ⇒ E [ t₂ ]*
[] [ t⇒ ]⇒* = t⇒
(E ∷ Es) [ t⇒ ]⇒* = Es [ E [ t⇒ ]⇒ ]⇒*
hole→≡ : ∀ {Γ a b}{Et t}{E : ECxt Γ a b} → (Es : Ehole Et E t) → Et ≡ E [ t ]
hole→≡ (appl u) = ≡.refl
lemma : ∀ {Γ b} {a} {t : Tm Γ a} (Es : ECxt* Γ a b)
{b₁} {E : ECxt Γ b b₁}
→ E [ Es [ t ]* ] ≡ (Es ++* (E ∷ [])) [ t ]*
lemma [] = ≡.refl
lemma (x ∷ Es) = lemma Es
hole*→≡ : ∀ {Γ a b}{Et t}{E : ECxt* Γ a b} → (Es : Ehole* Et E t) → Et ≡ E [ t ]*
hole*→≡ [] = ≡.refl
hole*→≡ {t = t} (_∷_ {Es = Es} x Es₁) rewrite hole→≡ x | hole*→≡ Es₁ = lemma Es
++*-unit : ∀ {Γ a b} → (xs : ECxt* Γ a b) → xs ++* [] ≡ xs
++*-unit [] = ≡.refl
++*-unit (x ∷ xs) = ≡.cong (_∷_ x) (++*-unit xs)
++*-assoc : ∀ {Γ a b c d} → (xs : ECxt* Γ a b) → {ys : ECxt* Γ b c} → {zs : ECxt* Γ c d} → xs ++* (ys ++* zs) ≡ (xs ++* ys) ++* zs
++*-assoc [] = ≡.refl
++*-assoc (x ∷ xs) = ≡.cong (_∷_ x) (++*-assoc xs)
_++h*_ : ∀ {Γ a b c} {Es1 : ECxt* Γ a b} {Es2 : ECxt* Γ b c} → ∀ {t1 t2 t3} → Ehole* t2 Es1 t3 → Ehole* t1 Es2 t2 → Ehole* t1 (Es1 ++* Es2) t3
_++h*_ {Es1 = Es1} xs [] rewrite ++*-unit Es1 = xs
_++h*_ {Es1 = Es1} xs (_∷_ {E = E} {Es = Es} x ys) rewrite ++*-assoc Es1 {Es} {E ∷ []} = x ∷ (xs ++h* ys)
mkEhole* : ∀ {Γ} {a b} (E : ECxt* Γ a b) {t} → Ehole* (E [ t ]*) E t
mkEhole* [] = []
mkEhole* (E ∷ Es) {t} = (proj₂ (mkEHole E) ∷ []) ++h* mkEhole* Es
|
{
"alphanum_fraction": 0.4500341064,
"avg_line_length": 35.1137724551,
"ext": "agda",
"hexsha": "79dcb786ab3a9f51917ee47aa4c00eb3632b3dff",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z",
"max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ryanakca/strong-normalization",
"max_forks_repo_path": "agda-aplas14/TermShape.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ryanakca/strong-normalization",
"max_issues_repo_path": "agda-aplas14/TermShape.agda",
"max_line_length": 143,
"max_stars_count": 32,
"max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ryanakca/strong-normalization",
"max_stars_repo_path": "agda-aplas14/TermShape.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z",
"num_tokens": 3000,
"size": 5864
}
|
-- There was a bug with the new constraint machinery
-- where a type error could be ignored and checking
-- continued.
module LostTypeError where
postulate
Wrap : (A : Set) (P : A → Set) → A → Set
wrap : ∀ A (P : A → Set) (x : A) → P x → Wrap A P x
A : Set
data Box : Set where
box : A → Box
data Dummy : Set where
box : Dummy
postulate
x y : A
P : Box → Set
px : P (box x)
bad : Wrap Box P (box y)
bad = wrap _ (λ a → P _) (box x) px
|
{
"alphanum_fraction": 0.5865800866,
"avg_line_length": 19.25,
"ext": "agda",
"hexsha": "99a8287820f2e4b37b61874ead10b30e03a34e97",
"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/LostTypeError.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/LostTypeError.agda",
"max_line_length": 53,
"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/LostTypeError.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": 160,
"size": 462
}
|
{-# OPTIONS --type-in-type #-}
-- Also called "Girard's paradox" or "Russell's paradox".
module Miscellaneous.TypeInTypeInconsistency where
data ISet : Set where
set : ∀{I : Set} → (I → ISet) → ISet
open import Functional
open import Logic.Predicate
open import Logic.Propositional
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Relator
open import Syntax.Function
_∉_ : ISet → ISet → Set
a ∉ set(b) = ∀{ib} → (a ≢ b(ib))
NotSelfContaining : ISet → Set
NotSelfContaining(a) = a ∉ a
NotSelfContainingSet : ISet
NotSelfContainingSet = set{∃(NotSelfContaining)} [∃]-witness
is-not-in : NotSelfContainingSet ∉ NotSelfContainingSet
is-not-in {[∃]-intro (set a) ⦃ proof ⦄} p = substitute₁ₗ(NotSelfContaining) p (\{_} → proof) {[∃]-intro (set a) ⦃ \{_} → proof ⦄} p
is-in : ¬(NotSelfContainingSet ∉ NotSelfContainingSet)
is-in p = p {[∃]-intro NotSelfContainingSet ⦃ \{proof} → p{proof} ⦄ } [≡]-intro
contradiction : ⊥
contradiction = is-in (\{proof} → is-not-in {proof})
{-
open import Data.Tuple as Tuple using ()
open import Logic.Predicate
open import Logic.Propositional
open import Functional
import Structure.Relator.Names as Names
open import Structure.Relator
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
open import Structure.Relator.Proofs
open import Structure.Setoid using (Equiv)
open import Syntax.Transitivity
_≡_ : ISet → ISet → Set
_∈_ : ISet → ISet → Set
_∉_ : ISet → ISet → Set
set {Ia} a ≡ set {Ib} b = ∃{Obj = Ib → Ia}(f ↦ ∀{ib} → (a(f(ib)) ≡ b(ib))) ∧ ∃{Obj = Ia → Ib}(f ↦ ∀{ia} → (a(ia) ≡ b(f(ia))))
a ∈ set(b) = ∃(ib ↦ (a ≡ b(ib)))
_∉_ = (¬_) ∘₂ (_∈_)
instance
[≡]-reflexivity : Reflexivity(_≡_)
[≡]-reflexivity = intro p where
p : Names.Reflexivity(_≡_)
p {set a} = [∧]-intro ([∃]-intro id ⦃ p ⦄) ([∃]-intro id ⦃ p ⦄)
instance
[≡]-symmetry : Symmetry(_≡_)
[≡]-symmetry = intro p where
p : Names.Symmetry(_≡_)
p {set a}{set b} ([∧]-intro l r) = [∧]-intro ([∃]-map-proof (\eq {i} → p(eq{i})) r) (([∃]-map-proof (\eq {i} → p(eq{i})) l))
instance
[≡]-transitivity : Transitivity(_≡_)
[≡]-transitivity = intro p where
p : Names.Transitivity(_≡_)
p {set x} {set y} {set z} ([↔]-intro ([∃]-intro fyx ⦃ yx ⦄) ([∃]-intro fxy ⦃ xy ⦄)) ([↔]-intro ([∃]-intro fzy ⦃ zy ⦄) ([∃]-intro fyz ⦃ yz ⦄)) = [∧]-intro ([∃]-intro (fyx ∘ fzy) ⦃ p yx zy ⦄) ([∃]-intro (fyz ∘ fxy) ⦃ p xy yz ⦄)
instance
[≡]-equivalence : Equivalence(_≡_)
[≡]-equivalence = intro
instance
[≡]-equiv : Equiv(ISet)
Equiv._≡_ [≡]-equiv = (_≡_)
Equiv.equivalence [≡]-equiv = [≡]-equivalence
instance
[∈]-unaryOperatorₗ : ∀{b} → UnaryRelator(_∈ b)
UnaryRelator.substitution ([∈]-unaryOperatorₗ {set b}) {a₁} {a₂} a1a2 = [∃]-map-proof (symmetry(_≡_) a1a2 🝖_)
instance
[∈]-unaryOperatorᵣ : ∀{a} → UnaryRelator(a ∈_)
UnaryRelator.substitution ([∈]-unaryOperatorᵣ {a}) {set b₁} {set b₂} ([∧]-intro _ ([∃]-intro fb1b2 ⦃ b1b2 ⦄)) ([∃]-intro ib₁ ⦃ p ⦄) = [∃]-intro (fb1b2(ib₁)) ⦃ p 🝖 b1b2 ⦄
instance
[∈]-binaryOperator : BinaryRelator(_∈_)
[∈]-binaryOperator = binaryRelator-from-unaryRelator
NotSelfContaining : ISet
NotSelfContaining = set{∃(a ↦ (a ∉ a))} [∃]-witness
NotSelfContaining-membership : ∀{x} → (x ∈ NotSelfContaining) ↔ (x ∉ x)
NotSelfContaining-membership = [↔]-intro l r where
l : ∀{x} → (x ∈ NotSelfContaining) ← (x ∉ x)
∃.witness (l {x} xin) = [∃]-intro x ⦃ xin ⦄
∃.proof (l {x} xin) = reflexivity(_≡_)
r : ∀{x} → (x ∈ NotSelfContaining) → (x ∉ x)
r {x} ([∃]-intro ([∃]-intro witness ⦃ nxinx ⦄) ⦃ p ⦄) xinx = nxinx(substitute₂(_∈_) p p xinx)
NotSelfContaining-self : (NotSelfContaining ∈ NotSelfContaining)
∃.witness NotSelfContaining-self = [∃]-intro NotSelfContaining ⦃ \{s@([∃]-intro ([∃]-intro _ ⦃ p ⦄) ⦃ b ⦄) → p(substitute₂(_∈_) b b s)} ⦄
∃.proof NotSelfContaining-self = [∧]-intro ([∃]-intro id ⦃ reflexivity(_≡_) ⦄) ([∃]-intro id ⦃ reflexivity(_≡_) ⦄)
paradox : ⊥
paradox = [↔]-to-[→] NotSelfContaining-membership NotSelfContaining-self NotSelfContaining-self
-}
|
{
"alphanum_fraction": 0.6284301607,
"avg_line_length": 32.6209677419,
"ext": "agda",
"hexsha": "d41e8104edc2750e53c74c1ba83dade11421180b",
"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": "Miscellaneous/TypeInTypeInconsistency.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": "Miscellaneous/TypeInTypeInconsistency.agda",
"max_line_length": 229,
"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": "Miscellaneous/TypeInTypeInconsistency.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": 1624,
"size": 4045
}
|
{-# OPTIONS --without-K #-}
open import Base
open import Spaces.Circle
open import Integers
module Spaces.LoopSpaceCircle where
-- Path fibration
path-fib : S¹ → Set
path-fib t = (t ≡ base)
tot-path-fib : Set
tot-path-fib = Σ S¹ path-fib
tot-path-fib-is-contr : is-contr tot-path-fib
tot-path-fib-is-contr = pathto-is-contr base
-- Universal cover
succ-path : ℤ ≡ ℤ
succ-path = eq-to-path succ-equiv
universal-cover : S¹ → Set
universal-cover = S¹-rec-nondep Set ℤ succ-path
tot-cover : Set
tot-cover = Σ S¹ universal-cover
-- Transport in the universal cover
loop-to-succ : (n : ℤ) → transport universal-cover loop n ≡ succ n
loop-to-succ n = ! (trans-ap (λ A → A) universal-cover loop n)
∘ (ap (λ t → transport (λ A → A) t n)
(S¹-β-loop-nondep Set ℤ succ-path)
∘ trans-id-eq-to-path succ-equiv n)
{- The flattening lemma
Here is an HIT declaration for the CW-complex of real numbers:
data ℝ : Set where
z : ℤ → ℝ
e : (n : ℤ) → z n ≡ z (succ n)
We want to show that [tot-cover] has the same introduction and elimination
rules.
-}
-- Introduction rules
R-z : ℤ → tot-cover
R-z n = (base , n)
R-e : (n : ℤ) → R-z n ≡ R-z (succ n)
R-e n = Σ-eq loop (loop-to-succ n)
-- Elimination rule
module Tot-cover-is-ℝ
{i}
(P : tot-cover → Set i)
(z : (n : ℤ) → P (R-z n))
(e : (n : ℤ) → transport P (R-e n) (z n) ≡ z (succ n)) where
-- I redefine [R-e] and [e] to have something involving
-- [transport universal-cover loop] instead of [succ]
R-e' : (n : ℤ) → R-z n ≡ R-z (transport universal-cover loop n)
R-e' n = Σ-eq loop refl
e' : (n : ℤ) → transport P (R-e' n) (z n)
≡ z (transport universal-cover loop n)
e' n = (trans-totalpath universal-cover P {x = (base , n)}
{y = (base , transport universal-cover loop n)}
loop refl z
∘ move!-transp-left (λ z → P (base , z)) _ (loop-to-succ n)
(z (succ n))
(! (trans-totalpath universal-cover P {x = (base , n)}
{y = (base , succ n)} loop (loop-to-succ n) z)
∘ e n))
∘ apd z (! (loop-to-succ n))
-- Now I can prove what I want by induction on the circle
P-base : (t : universal-cover base) → P (base , t)
P-base t = z t
P-loop : (t : universal-cover base)
→ transport (λ x → (u : universal-cover x) → P (x , u)) loop P-base t
≡ P-base t
P-loop t = transport (λ t → transport
(λ x → (u : universal-cover x) → P (x , u))
loop P-base t ≡ P-base t)
(trans-trans-opposite universal-cover loop t)
(! (trans-totalpath universal-cover P
loop refl z)
∘ e' (transport universal-cover (! loop) t))
P-R-rec : (x : S¹) → (t : universal-cover x) → P (x , t)
P-R-rec = S¹-rec (λ x → (t : universal-cover x) → P (x , t))
P-base (funext P-loop)
-- Here is the conclusion of the elimination rule
R-rec : (t : tot-cover) → P t
R-rec (x , y) = P-R-rec x y
-- We can now prove that [tot-cover] is contractible using [R-rec], that’s a
-- little tedious but not difficult
P-R-contr : (x : tot-cover) → Set _
P-R-contr x = R-z O ≡ x
R-contr-base : (n : ℤ) → P-R-contr (R-z n)
R-contr-base O = refl
R-contr-base (pos O) = R-e O
R-contr-base (pos (S y)) = R-contr-base (pos y) ∘ R-e (pos y)
R-contr-base (neg O) = ! (R-e (neg O))
R-contr-base (neg (S y)) = R-contr-base (neg y) ∘ ! (R-e (neg (S y)))
R-contr-loop : (n : ℤ)
→ transport P-R-contr (R-e n) (R-contr-base n) ≡ (R-contr-base (succ n))
R-contr-loop O = trans-cst≡id (R-e O) refl
R-contr-loop (pos O) = trans-cst≡id (R-e (pos O)) (R-e O)
R-contr-loop (pos (S y)) = trans-cst≡id (R-e (pos (S y)))
(R-contr-base (pos y) ∘ R-e (pos y))
R-contr-loop (neg O) = trans-cst≡id (R-e (neg O))
(! (R-e (neg O))) ∘ opposite-left-inverse (R-e (neg O))
R-contr-loop (neg (S y)) =
((trans-cst≡id (R-e (neg (S y))) (R-contr-base (neg y) ∘ ! (R-e (neg (S y))))
∘ concat-assoc (R-contr-base (neg y)) (! (R-e (neg (S y))))
(R-e (neg (S y))))
∘ (whisker-left (R-contr-base (neg y))
(opposite-left-inverse (R-e (neg (S y))))))
∘ refl-right-unit (R-contr-base (neg y))
R-contr : (x : tot-cover) → P-R-contr x
R-contr = Tot-cover-is-ℝ.R-rec P-R-contr R-contr-base R-contr-loop
tot-cover-is-contr : is-contr tot-cover
tot-cover-is-contr = (R-z O , λ x → ! (R-contr x))
-- We define now a fiberwise map between the two fibrations [path-fib]
-- and [universal-cover]
fiberwise-map : (x : S¹) → (path-fib x → universal-cover x)
fiberwise-map x p = transport universal-cover (! p) O
-- This induces an equivalence on the total spaces, because both total spaces
-- are contractible
total-is-equiv : is-equiv (total-map fiberwise-map)
total-is-equiv = contr-to-contr-is-equiv (total-map fiberwise-map)
tot-path-fib-is-contr
tot-cover-is-contr
-- Hence an equivalence fiberwise
fiberwise-map-is-equiv : (x : S¹) → is-equiv (fiberwise-map x)
fiberwise-map-is-equiv x = fiberwise-is-equiv fiberwise-map total-is-equiv x
-- We can then conclude that the based loop space of the circle is equivalent to
-- the type of the integers
ΩS¹≃ℤ : (base ≡ base) ≃ ℤ
ΩS¹≃ℤ = (fiberwise-map base , fiberwise-map-is-equiv base)
-- We can also deduce that the circle is 1-truncated
ΩS¹-is-set : is-set (base ≡ base)
ΩS¹-is-set = equiv-types-truncated _ (ΩS¹≃ℤ ⁻¹) ℤ-is-set
S¹-is-gpd : is-gpd S¹
S¹-is-gpd =
S¹-rec _
(S¹-rec _
ΩS¹-is-set -- [base ≡ base] is a set
(π₁ (is-truncated-is-prop _ _ _)))
(funext
(S¹-rec _
(π₁ (is-truncated-is-prop _ _ _))
(prop-has-all-paths (≡-is-truncated _ (is-truncated-is-prop _)) _ _)))
|
{
"alphanum_fraction": 0.5722533537,
"avg_line_length": 33.2711864407,
"ext": "agda",
"hexsha": "38d11d9454280a888e8b794cb94f316ece8a9513",
"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/Spaces/LoopSpaceCircle.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/Spaces/LoopSpaceCircle.agda",
"max_line_length": 80,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/Spaces/LoopSpaceCircle.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": 1934,
"size": 5889
}
|
open import Oscar.Prelude
open import Oscar.Class.Reflexivity
open import Oscar.Class.Symmetry
open import Oscar.Class.Transitivity
module Oscar.Class.IsEquivalence where
record IsEquivalence
{𝔬} {𝔒 : Ø 𝔬}
{ℓ} (_≈_ : 𝔒 → 𝔒 → Ø ℓ)
: Ø 𝔬 ∙̂ ℓ where
constructor ∁
field
⦃ `𝓡eflexivity ⦄ : Reflexivity.class _≈_
⦃ `𝓢ymmetry ⦄ : Symmetry.class _≈_
⦃ `𝓣ransitivity ⦄ : Transitivity.class _≈_
|
{
"alphanum_fraction": 0.6893203883,
"avg_line_length": 22.8888888889,
"ext": "agda",
"hexsha": "5e2c42c81e6630e2435112b024656fde68b4d76c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/IsEquivalence.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/IsEquivalence.agda",
"max_line_length": 47,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/IsEquivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 168,
"size": 412
}
|
module AmbiguousName where
module A where
postulate X : Set
module B where
module A where
postulate X : Set
open A renaming (X to Y)
open B
Z = A.X
|
{
"alphanum_fraction": 0.6894409938,
"avg_line_length": 10.7333333333,
"ext": "agda",
"hexsha": "ea51fa5acffddbbfb3ba35d97de7567b9b24e0e9",
"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/AmbiguousName.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/AmbiguousName.agda",
"max_line_length": 26,
"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/AmbiguousName.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": 50,
"size": 161
}
|
module Lib.Id where
data _≡_ {A : Set}(x : A) : A -> Set where
refl : x ≡ x
cong : {A B : Set}(f : A -> B){x y : A} -> x ≡ y -> f x ≡ f y
cong f refl = refl
subst : {A : Set}(P : A -> Set){x y : A} -> x ≡ y -> P y -> P x
subst P refl px = px
|
{
"alphanum_fraction": 0.4578313253,
"avg_line_length": 19.1538461538,
"ext": "agda",
"hexsha": "bb9c52c54f2201318562241a65f26a5ba6c55495",
"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/simple-lib/Lib/Id.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/simple-lib/Lib/Id.agda",
"max_line_length": 63,
"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/simple-lib/Lib/Id.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 111,
"size": 249
}
|
module inspect where
open import eq
-- From Norell's tutorial:
data Inspect {A : Set}(x : A) : Set where
it : (y : A) -> x ≡ y -> Inspect x
inspect : {A : Set}(x : A) -> Inspect x
inspect x = it x refl
|
{
"alphanum_fraction": 0.5933014354,
"avg_line_length": 16.0769230769,
"ext": "agda",
"hexsha": "f54359624a0c6d47cf1713e9b8372b6f7343d272",
"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": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "mihanus/curry-agda",
"max_forks_repo_path": "nondet/inspect.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"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": "mihanus/curry-agda",
"max_issues_repo_path": "nondet/inspect.agda",
"max_line_length": 41,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "mihanus/curry-agda",
"max_stars_repo_path": "nondet/inspect.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 73,
"size": 209
}
|
open import HoTT
open import groups.Exactness
open import groups.HomSequence
module groups.ExactSequence where
is-exact-seq : ∀ {i} {G H : Group i}
→ HomSequence G H → Type i
is-exact-seq (_ ⊣|ᴳ) = Lift ⊤
is-exact-seq (_ →⟨ φ ⟩ᴳ _ ⊣|ᴳ) = Lift ⊤
is-exact-seq (_ →⟨ φ ⟩ᴳ _ →⟨ ψ ⟩ᴳ seq) =
is-exact φ ψ × is-exact-seq (_ →⟨ ψ ⟩ᴳ seq)
ExactSequence : ∀ {i} (G H : Group i) → Type (lsucc i)
ExactSequence G H = Σ (HomSequence G H) is-exact-seq
{- equivalences preserve exactness -}
abstract
seq-equiv-preserves-exact : ∀ {i₀ i₁} {G₀ H₀ : Group i₀} {G₁ H₁ : Group i₁}
{seq₀ : HomSequence G₀ H₀} {seq₁ : HomSequence G₁ H₁}
{ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁}
→ HomSeqEquiv seq₀ seq₁ ξG ξH
→ is-exact-seq seq₀ → is-exact-seq seq₁
seq-equiv-preserves-exact ((_ ↓|ᴳ) , _) _ = lift tt
seq-equiv-preserves-exact ((_ ↓⟨ _ ⟩ᴳ _ ↓|ᴳ) , _) _ = lift tt
seq-equiv-preserves-exact
( (ξG ↓⟨ φ□ ⟩ᴳ _↓⟨_⟩ᴳ_ ξH {ξK} ψ□ seq-map)
, (ξG-ise , ξH-ise , seq-map-ise))
(φ₀-ψ₀-is-exact , ψ₀-seq₀-is-exact-seq) =
equiv-preserves-exact
φ□ ψ□ ξG-ise ξH-ise (is-seqᴳ-equiv.head seq-map-ise)
φ₀-ψ₀-is-exact ,
seq-equiv-preserves-exact
((ξH ↓⟨ ψ□ ⟩ᴳ seq-map) , (ξH-ise , seq-map-ise))
ψ₀-seq₀-is-exact-seq
seq-equiv-preserves'-exact : ∀ {i} {G₀ G₁ H₀ H₁ : Group i}
{seq₀ : HomSequence G₀ H₀} {seq₁ : HomSequence G₁ H₁}
{ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁}
→ HomSeqEquiv seq₀ seq₁ ξG ξH
→ is-exact-seq seq₁ → is-exact-seq seq₀
seq-equiv-preserves'-exact seq-equiv =
seq-equiv-preserves-exact (HomSeqEquiv-inverse seq-equiv)
private
exact-seq-index-type : ∀ {i} {G H : Group i} → ℕ → HomSequence G H → Type i
exact-seq-index-type _ (G ⊣|ᴳ) = Lift ⊤
exact-seq-index-type _ (G →⟨ φ ⟩ᴳ H ⊣|ᴳ) = Lift ⊤
exact-seq-index-type O (G →⟨ φ ⟩ᴳ H →⟨ ψ ⟩ᴳ s) = is-exact φ ψ
exact-seq-index-type (S n) (_ →⟨ _ ⟩ᴳ s) = exact-seq-index-type n s
abstract
exact-seq-index : ∀ {i} {G H : Group i}
→ (n : ℕ) (seq : ExactSequence G H)
→ exact-seq-index-type n (fst seq)
exact-seq-index _ ((G ⊣|ᴳ) , _) = lift tt
exact-seq-index _ ((G →⟨ φ ⟩ᴳ H ⊣|ᴳ) , _) = lift tt
exact-seq-index O ((G →⟨ φ ⟩ᴳ H →⟨ ψ ⟩ᴳ seq) , ise-seq) = fst ise-seq
exact-seq-index (S n) ((G →⟨ φ ⟩ᴳ H →⟨ ψ ⟩ᴳ seq) , ise-seq) =
exact-seq-index n ((H →⟨ ψ ⟩ᴳ seq) , snd ise-seq)
{-
private
exact-build-arg-type : ∀ {i} {G H : Group i} → HomSequence G H → List (Type i)
exact-build-arg-type (G ⊣|) = nil
exact-build-arg-type (G ⟨ φ ⟩→ H ⊣|) = nil
exact-build-arg-type (G ⟨ φ ⟩→ H ⟨ ψ ⟩→ s) =
is-exact φ ψ :: exact-build-arg-type (H ⟨ ψ ⟩→ s)
exact-build-helper : ∀ {i} {G H : Group i} (seq : HomSequence G H)
→ HList (exact-build-arg-type seq) → is-exact-seq seq
exact-build-helper (G ⊣|) nil = exact-seq-zero
exact-build-helper (G ⟨ φ ⟩→ H ⊣|) nil = exact-seq-one
exact-build-helper (G ⟨ φ ⟩→ H ⟨ ψ ⟩→ s) (ie :: ies) =
exact-seq-more ie (exact-build-helper (H ⟨ ψ ⟩→ s) ies)
exact-build : ∀ {i} {G H : Group i} (seq : HomSequence G H)
→ hlist-curry-type (exact-build-arg-type seq) (λ _ → is-exact-seq seq)
exact-build seq = hlist-curry (exact-build-helper seq)
hom-seq-concat : ∀ {i} {G H K : Group i}
→ HomSequence G H → HomSequence H K → HomSequence G K
hom-seq-concat (G ⊣|) s₂ = s₂
hom-seq-concat (G ⟨ φ ⟩→ s₁) s₂ = G ⟨ φ ⟩→ (hom-seq-concat s₁ s₂)
abstract
exact-concat : ∀ {i} {G H K L : Group i}
{seq₁ : HomSequence G H} {φ : H →ᴳ K} {seq₂ : HomSequence K L}
→ is-exact-seq (hom-seq-snoc seq₁ φ) → is-exact-seq (H ⟨ φ ⟩→ seq₂)
→ is-exact-seq (hom-seq-concat seq₁ (H ⟨ φ ⟩→ seq₂))
exact-concat {seq₁ = G ⊣|} exact-seq-one es₂ = es₂
exact-concat {seq₁ = G ⟨ ψ ⟩→ H ⊣|} (exact-seq-more ex _) es₂ =
exact-seq-more ex es₂
exact-concat {seq₁ = G ⟨ ψ ⟩→ H ⟨ χ ⟩→ s} (exact-seq-more ex es₁) es₂ =
exact-seq-more ex (exact-concat {seq₁ = H ⟨ χ ⟩→ s} es₁ es₂)
-}
|
{
"alphanum_fraction": 0.585007728,
"avg_line_length": 39.612244898,
"ext": "agda",
"hexsha": "492dd21593405a76fbc1e02e39658e73014267f9",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/groups/ExactSequence.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/groups/ExactSequence.agda",
"max_line_length": 80,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/groups/ExactSequence.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": 1708,
"size": 3882
}
|
------------------------------------------------------------------------
-- The partiality monad
------------------------------------------------------------------------
module Category.Monad.Partiality where
open import Coinduction
open import Category.Monad
open import Data.Nat
open import Data.Bool
-- The partiality monad.
data _⊥ (A : Set) : Set where
now : (x : A) → A ⊥
later : (x : ∞ (A ⊥)) → A ⊥
monad : RawMonad _⊥
monad = record
{ return = now
; _>>=_ = _>>=_
}
where
_>>=_ : ∀ {A B} → A ⊥ → (A → B ⊥) → B ⊥
now x >>= f = f x
later x >>= f = later (♯ ♭ x >>= f)
-- run x for n steps peels off at most n "later" constructors from x.
run_for_steps : ∀ {A} → A ⊥ → ℕ → A ⊥
run now x for n steps = now x
run later x for zero steps = later x
run later x for suc n steps = run ♭ x for n steps
-- Is the computation done?
isNow : ∀ {A} → A ⊥ → Bool
isNow (now x) = true
isNow (later x) = false
------------------------------------------------------------------------
-- Productivity checker workaround
-- The monad can be awkward to use, due to the limitations of guarded
-- coinduction. The following code provides a (limited) workaround.
infixl 1 _>>=_
data _⊥-prog : Set → Set₁ where
now : ∀ {A} (x : A) → A ⊥-prog
later : ∀ {A} (x : ∞₁ (A ⊥-prog)) → A ⊥-prog
_>>=_ : ∀ {A B} (x : A ⊥-prog) (f : A → B ⊥-prog) → B ⊥-prog
data _⊥-whnf : Set → Set₁ where
now : ∀ {A} (x : A) → A ⊥-whnf
later : ∀ {A} (x : A ⊥-prog) → A ⊥-whnf
whnf : ∀ {A} → A ⊥-prog → A ⊥-whnf
whnf (now x) = now x
whnf (later x) = later (♭₁ x)
whnf (x >>= f) with whnf x
whnf (x >>= f) | now x′ = whnf (f x′)
whnf (x >>= f) | later x′ = later (x′ >>= f)
mutual
value : ∀ {A} → A ⊥-whnf → A ⊥
value (now x) = now x
value (later x) = later (♯ run x)
run : ∀ {A} → A ⊥-prog → A ⊥
run x = value (whnf x)
------------------------------------------------------------------------
-- Examples
module Examples where
open import Relation.Nullary
-- McCarthy's f91:
f91′ : ℕ → ℕ ⊥-prog
f91′ n with n ≤? 100
... | yes _ = later (♯₁ (f91′ (11 + n) >>= f91′))
... | no _ = now (n ∸ 10)
f91 : ℕ → ℕ ⊥
f91 n = run (f91′ n)
|
{
"alphanum_fraction": 0.4684065934,
"avg_line_length": 24.2666666667,
"ext": "agda",
"hexsha": "5e70d56688ef61c7de448fb2ce972bd52a718393",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Category/Monad/Partiality.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Category/Monad/Partiality.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Category/Monad/Partiality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 793,
"size": 2184
}
|
module _ (A : Set) where
open import Issue1701.ModParamsToLose
module ParamA = Param A
open ParamA
failed : (A → A) → A → A
failed G = S.F
module fails where
module S = r A G
|
{
"alphanum_fraction": 0.6684782609,
"avg_line_length": 15.3333333333,
"ext": "agda",
"hexsha": "f9dd7b903bf9541f9bcd2d22bafacc4ecffd7733",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1701c.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1701c.agda",
"max_line_length": 37,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1701c.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": 63,
"size": 184
}
|
{-# OPTIONS --universe-polymorphism #-}
module Reflection where
open import Common.Prelude hiding (Unit; module Unit) renaming (Nat to ℕ; module Nat to ℕ)
open import Common.Reflect
data _≡_ {a}{A : Set a}(x : A) : A → Set a where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL refl #-}
data Id {A : Set}(x : A) : (B : Set) → B → Set where
course : Id x A x
primitive
primTrustMe : ∀{a}{A : Set a}{x y : A} → x ≡ y
open import Common.Level
unEl : Type → Term
unEl (el _ t) = t
argᵛʳ : ∀{A} → A → Arg A
argᵛʳ = arg (arginfo visible relevant)
argʰʳ : ∀{A} → A → Arg A
argʰʳ = arg (arginfo hidden relevant)
el₀ : Term → Type
el₀ = el (lit 0)
el₁ : Term → Type
el₁ = el (lit 1)
set₀ : Type
set₀ = el₁ (sort (lit 0))
unCheck : Term → Term
unCheck (def x (_ ∷ _ ∷ arg _ t ∷ [])) = t
unCheck t = unknown
data Check {a}{A : Set a}(x : A) : Set where
_is_of_ : (t t′ : Term) →
Id (primTrustMe {x = unCheck t} {t′})
(t′ ≡ t′) refl → Check x
`Check : QName
`Check = quote Check
test₁ : Check ({A : Set} → A → A)
test₁ = quoteGoal t in
t is pi (argʰʳ set₀) (el₀ (pi (argᵛʳ (el₀ (var 0 []))) (el₀ (var 1 []))))
of course
test₂ : (X : Set) → Check (λ (x : X) → x)
test₂ X = quoteGoal t in
t is lam visible (var 0 []) of course
infixr 40 _`∷_
_`∷_ : Term → Term → Term
x `∷ xs = con (quote _∷_) (argᵛʳ x ∷ argᵛʳ xs ∷ [])
`[] = con (quote []) []
`true = con (quote true) []
`false = con (quote false) []
test₃ : Check (true ∷ false ∷ [])
test₃ = quoteGoal t in
t is `true `∷ `false `∷ `[] of course
`List : Term → Term
`List A = def (quote List) (argᵛʳ A ∷ [])
`ℕ = def (quote ℕ) []
`Term : Term
`Term = def (quote Term) []
`Type : Term
`Type = def (quote Type) []
`Sort : Term
`Sort = def (quote Sort) []
test₄ : Check (List ℕ)
test₄ = quoteGoal t in
t is `List `ℕ of course
test₅ : primQNameType (quote Term) ≡ set₀
test₅ = refl
-- TODO => test₆ : primQNameType (quote set₀) ≡ el unknown `Type ≢ el₀ `Type
test₆ : unEl (primQNameType (quote set₀)) ≡ `Type
test₆ = refl
test₇ : primQNameType (quote Sort.lit) ≡ el₀ (pi (argᵛʳ (el₀ `ℕ)) (el₀ `Sort))
test₇ = refl
mutual
ℕdef : DataDef
ℕdef = _
test₈ : dataDef ℕdef ≡ primQNameDefinition (quote ℕ)
test₈ = refl
test₉ : primDataConstructors ℕdef ≡ quote ℕ.zero ∷ quote ℕ.suc ∷ []
test₉ = refl
test₁₀ : primQNameDefinition (quote ℕ.zero) ≡ dataConstructor
test₁₀ = refl
postulate
a : ℕ
test₁₁ : primQNameDefinition (quote a) ≡ axiom
test₁₁ = refl
test₁₂ : primQNameDefinition (quote primQNameDefinition) ≡ prim
test₁₂ = refl
record Unit : Set where
mutual
UnitDef : RecordDef
UnitDef = _
test₁₃ : recordDef UnitDef ≡ primQNameDefinition (quote Unit)
test₁₃ = refl
test₁₄ : Check 1
test₁₄ = quoteGoal t in
t is con ( quote ℕ.suc ) (argᵛʳ (con (quote ℕ.zero) []) ∷ [])
of course
|
{
"alphanum_fraction": 0.6022176022,
"avg_line_length": 21.8636363636,
"ext": "agda",
"hexsha": "2c9e700aca8251478ab18e2f4af897125be4fa0c",
"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/Reflection.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/Reflection.agda",
"max_line_length": 90,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Reflection.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 1108,
"size": 2886
}
|
module tests.Mutual where
open import Prelude.IO
open import Prelude.String
open import Prelude.Unit
mutual
data G : Set where
GA : {g : G}(f : F g) -> G
GB : G
data F : G -> Set where
FA : (g : G) -> F g
FB : F GB
mutual
incG : G -> G
incG GB = GA FB
incG (GA f) = GA (incF f)
incF : {g : G} -> F g -> F (incG g)
incF FB = FA (GA FB)
incF (FA g) = FA (incG g)
mutual
PrintF : {g : G} -> F g -> String
PrintF FB = "FB"
PrintF (FA g) = "(FA " +S+ PrintG g +S+ ")"
PrintG : G -> String
PrintG GB = "GB"
PrintG (GA f) = "(GA " +S+ PrintF f +S+ ")"
main : IO Unit
main =
putStrLn (PrintF (FA (GA (FA GB)))) ,,
putStrLn (PrintG (incG (GA (incF FB)))) ,, --
return unit
|
{
"alphanum_fraction": 0.5154777927,
"avg_line_length": 17.6904761905,
"ext": "agda",
"hexsha": "9f6cdb8e1c525ee2c0c776171f87c718aa2faff0",
"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": "test/epic/tests/Mutual.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": "test/epic/tests/Mutual.agda",
"max_line_length": 49,
"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": "test/epic/tests/Mutual.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 288,
"size": 743
}
|
data A : Set where
consA : A → A
A-false : {Y : Set} → A → Y
A-false (consA b) = A-false b
data Nat : Set where
zero : Nat
suc : Nat → Nat
A-on-Nat : A → Nat → Nat
A-on-Nat σ zero = A-false σ
A-on-Nat σ (suc t) = suc (A-on-Nat σ t)
module _
(any : {X : Set} → X)
(P : Nat → Set)
(p : (n : Nat) → P n → P (suc n))
(eternity : (a : A) (n : Nat) → P (A-on-Nat (A-false a) n))
where
A-loop-term : (a : A) (n : Nat) → P (A-on-Nat a n)
A-loop-term a zero = any
A-loop-term a (suc n) = p _ (eternity _ n)
|
{
"alphanum_fraction": 0.5133079848,
"avg_line_length": 20.2307692308,
"ext": "agda",
"hexsha": "b9fc37c6f24314dcdfbc5fee0bacf10a82be9bc5",
"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/Issue3067.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/Issue3067.agda",
"max_line_length": 61,
"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/Issue3067.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": 231,
"size": 526
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Core.Everything where
-- Basic primitives (some are from Agda.Primitive)
open import Cubical.Core.Primitives public
-- Definition of equivalences and Glue types
open import Cubical.Core.Glue public
-- Definition of cubical Identity types
open import Cubical.Core.Id
|
{
"alphanum_fraction": 0.7791044776,
"avg_line_length": 27.9166666667,
"ext": "agda",
"hexsha": "95b9469673c28d2033cf0deaf6a96fbf695c93ca",
"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/Core/Everything.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/Core/Everything.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Core/Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 79,
"size": 335
}
|
-- Andreas, 2019-03-02, issue #3601 reported by 3abc
{-# OPTIONS --cubical --safe #-}
open import Agda.Primitive.Cubical renaming
(primINeg to ~_; primIMin to _∧_; primTransp to transp)
open import Agda.Builtin.Cubical.Path
module _ (A : Set) (x y z t : A) (f : y ≡ z) (g : y ≡ x) (h : z ≡ t) where
test : PathP (λ i → g i ≡ h i) f (transp (λ i → g i ≡ h i) i0 f)
test k i = transp (λ i → g (i ∧ k) ≡ h (i ∧ k)) (~ k) f i
-- Should pass.
-- Problem was: Agda did not accept overapplied primTransp
-- Also should pass.
-- We had a problem with checking the sides at the right type.
test2 : ∀ {ℓ} (i : I) {A : Partial i (Set ℓ)}
→ PartialP i (λ z → A z)
→ (r : IsOne i)
→ A r
test2 i {A} u r = primPOr i i {A} u (λ o → u o) r
|
{
"alphanum_fraction": 0.5631443299,
"avg_line_length": 29.8461538462,
"ext": "agda",
"hexsha": "bba999a0dd415d4be2658e1108579b489c4fc0df",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3601.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3601.agda",
"max_line_length": 74,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3601.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": 301,
"size": 776
}
|
{-
This second-order equational theory was created from the following second-order syntax description:
syntax STLC | Λ
type
N : 0-ary
_↣_ : 2-ary | r30
term
app : α ↣ β α -> β | _$_ l20
lam : α.β -> α ↣ β | ƛ_ r10
theory
(ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a]
(ƛη) f : α ↣ β |> lam (x. app(f, x)) = f
-}
module STLC.Equality where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Families.Build
open import SOAS.ContextMaps.Inductive
open import STLC.Signature
open import STLC.Syntax
open import SOAS.Metatheory.SecondOrder.Metasubstitution Λ:Syn
open import SOAS.Metatheory.SecondOrder.Equality Λ:Syn
private
variable
α β γ τ : ΛT
Γ Δ Π : Ctx
infix 1 _▹_⊢_≋ₐ_
-- Axioms of equality
data _▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ Λ) α Γ → (𝔐 ▷ Λ) α Γ → Set where
ƛβ : ⁅ α ⊩ β ⁆ ⁅ α ⁆̣ ▹ ∅ ⊢ (ƛ 𝔞⟨ x₀ ⟩) $ 𝔟 ≋ₐ 𝔞⟨ 𝔟 ⟩
ƛη : ⁅ α ↣ β ⁆̣ ▹ ∅ ⊢ ƛ (𝔞 $ x₀) ≋ₐ 𝔞
open EqLogic _▹_⊢_≋ₐ_
open ≋-Reasoning
|
{
"alphanum_fraction": 0.6155339806,
"avg_line_length": 21.4583333333,
"ext": "agda",
"hexsha": "4b46deeed527412324205b2ed3afc2a4d489b881",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/STLC/Equality.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/STLC/Equality.agda",
"max_line_length": 99,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/STLC/Equality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 476,
"size": 1030
}
|
open import bool
open import eq using (_≡_)
open import nat
open import nat-thms
open import z05-01-hc-slist2-base
module z05-01-hc-slist2-test where
data _R≤_ : ℕ → ℕ → Set where
z≤n : ∀ {n : ℕ}
--------
→ zero R≤ n
s≤s : ∀ {m n : ℕ}
→ m R≤ n
-------------
→ suc m R≤ suc n
≤-pred : ∀ {m n} → suc m R≤ suc n → m R≤ n
≤-pred (s≤s m≤n) = m≤n
_≤?_ : Decidable _R≤_
zero ≤? _ = left z≤n
suc m ≤? zero = right λ()
suc m ≤? suc n with m ≤? n
... | left m≤n = left (s≤s m≤n)
... | right m≰n = right λ x → m≰n (≤-pred x)
ℕ-Equivalence : Equivalence {X = ℕ} _≡_
ℕ-Equivalence = record
{ refl = _≡_.refl
; sym = λ x≡y → eq.sym x≡y
; trans = λ {_≡_.refl _≡_.refl → eq.trans _≡_.refl _≡_.refl} }
xR≤y→x≤y≡tt : ∀ {x y : ℕ} → x R≤ y → x ≤ y ≡ bool.𝔹.tt
xR≤y→x≤y≡tt {x} {y} z≤n = 0-≤ y
xR≤y→x≤y≡tt {x} {y} (s≤s xR≤y) = xR≤y→x≤y≡tt xR≤y
x≤y≡tt→xR≤y : ∀ {x y : ℕ} → x ≤ y ≡ bool.𝔹.tt → x R≤ y
x≤y≡tt→xR≤y {zero} {_} _ = z≤n
x≤y≡tt→xR≤y {suc x} {y} sucx≤y≡tt = {!!} -- TODO
R≤-total : (x y : ℕ) → Either (x R≤ y) (y R≤ x)
R≤-total zero zero = left z≤n
R≤-total zero (suc y) = left z≤n
R≤-total (suc x) zero = right z≤n
R≤-total (suc x) (suc y) with R≤-total x y
... | left l = left (s≤s l)
... | right r = right (s≤s r)
x≡y→xR≤y : ∀ {x y : ℕ} → x ≡ y → x R≤ y
x≡y→xR≤y {zero} {_} _ = z≤n
x≡y→xR≤y {suc x} {.(suc x)} _≡_.refl = s≤s (x≤y≡tt→xR≤y (≤-refl x))
ℕ-TotalOrder : TotalOrder {X = ℕ} _≡_ _R≤_
ℕ-TotalOrder = record
{ antisym = λ x≤y y≤x → ≤-antisym (xR≤y→x≤y≡tt x≤y) (xR≤y→x≤y≡tt y≤x)
; trans = λ {x} {y} {z} xR≤y yR≤z →
x≤y≡tt→xR≤y (≤-trans {x} {y} {z} (xR≤y→x≤y≡tt xR≤y) (xR≤y→x≤y≡tt yR≤z))
; total = R≤-total
; reflexive = x≡y→xR≤y
; equivalence = ℕ-Equivalence
}
import z05-01-hc-slist2-list as SL
open SL {ℕ}
{_≡_}
{_R≤_}
_≤?_
ℕ-TotalOrder
empty : OList ⟦ 0 ⟧ ⟦ 9 ⟧
empty = nil (≤-lift z≤n)
l-9 : OList ⟦ 0 ⟧ ⟦ 9 ⟧
l-9 = insert 9 empty (≤-lift z≤n) (≤-lift (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))))))
l-5-9 : OList ⟦ 0 ⟧ ⟦ 9 ⟧
l-5-9 = insert 5 l-9 (≤-lift z≤n) (≤-lift (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))
l-1-5-9 : OList ⟦ 0 ⟧ ⟦ 9 ⟧
l-1-5-9 = insert 1 l-5-9 (≤-lift z≤n) (≤-lift (s≤s z≤n))
l-1-5-9' : OList ⊥ ⊤
l-1-5-9' = isort' (9 ∷ 1 ∷ 5 ∷ [])
-- cannot do because lower/upper indices different : l-1-5-9 ≡ l-1-5-9'
_ : toList l-1-5-9 ≡ toList l-1-5-9'
_ = eq.refl
|
{
"alphanum_fraction": 0.4778582931,
"avg_line_length": 27.2967032967,
"ext": "agda",
"hexsha": "e5acc02faf5b7a82ad73f3bd92980f7ee8a90320",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-slist2-test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-slist2-test.agda",
"max_line_length": 100,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-slist2-test.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 1449,
"size": 2484
}
|
module Data.Maybe.Primitive where
{-# IMPORT Data.Maybe #-}
-- In Agda 2.2.10 and below, there's no FFI binding for the stdlib
-- Maybe type, so we have to roll our own. This will change.
data #Maybe (X : Set) : Set where
just : X → #Maybe X
nothing : #Maybe X
{-# COMPILED_DATA #Maybe Data.Maybe.Maybe Data.Maybe.Just Data.Maybe.Nothing #-}
|
{
"alphanum_fraction": 0.6905444126,
"avg_line_length": 29.0833333333,
"ext": "agda",
"hexsha": "d45a03d4069787d5ad144878f325a25d511c489b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:40:14.000Z",
"max_forks_repo_head_hexsha": "84d51967e20bf248e9f73af37f52972922ffc77c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-data-bindings",
"max_forks_repo_path": "src/Data/Maybe/Primitive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84d51967e20bf248e9f73af37f52972922ffc77c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-data-bindings",
"max_issues_repo_path": "src/Data/Maybe/Primitive.agda",
"max_line_length": 80,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "84d51967e20bf248e9f73af37f52972922ffc77c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-data-bindings",
"max_stars_repo_path": "src/Data/Maybe/Primitive.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-24T13:51:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-02T23:17:59.000Z",
"num_tokens": 99,
"size": 349
}
|
open import Agda.Builtin.Bool
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.Reflection
macro
printType : Term → TC ⊤
printType hole = bindTC (inferType hole) λ t → typeError (termErr t ∷ [])
test1 : (a : Nat) → Nat
test1 = {! printType !}
test2 : (a : Bool) → Bool
test2 = {! printType !}
|
{
"alphanum_fraction": 0.6967213115,
"avg_line_length": 22.875,
"ext": "agda",
"hexsha": "843af17afe0e2acd0300da7b789d912c32b2e993",
"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": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "test/interaction/Issue5695.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"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": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "test/interaction/Issue5695.agda",
"max_line_length": 75,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/interaction/Issue5695.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": 117,
"size": 366
}
|
module naturals where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
-- 1)
seven : ℕ
seven = suc (suc (suc (suc (suc (suc (suc zero))))))
{-# BUILTIN NATURAL ℕ #-}
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
_+_ : ℕ → ℕ → ℕ
zero + n = n
(suc m) + n = suc (m + n)
-- 2)
_ : 3 + 4 ≡ 7
_ =
begin
3 + 4
≡⟨⟩
suc (2 + 4)
≡⟨⟩
suc (suc (1 + 4))
≡⟨⟩
suc (suc (suc (0 + 4)))
≡⟨⟩
suc (suc (suc 4))
≡⟨⟩
suc (suc 5)
≡⟨⟩
suc 6
≡⟨⟩
7
∎
_*_ : ℕ → ℕ → ℕ
zero * n = zero
(suc m) * n = n + (m * n)
-- 3)
_ : 3 * 4 ≡ 12
_ =
begin
3 * 4
≡⟨⟩
4 + (2 * 4)
≡⟨⟩
4 + (4 + (1 * 4))
≡⟨⟩
4 + (4 + (4 + (0 * 4)))
≡⟨⟩
4 + (4 + (4 + 0))
≡⟨⟩
4 + (4 + (4))
≡⟨⟩
12
∎
-- 4)
_^_ : ℕ → ℕ → ℕ
m ^ zero = suc zero
m ^ suc n = m * (m ^ n)
_ : 3 ^ 4 ≡ 81
_ =
begin
3 ^ 4
≡⟨⟩
3 * (3 ^ 3)
≡⟨⟩
3 * (3 * (3 ^ 2))
≡⟨⟩
3 * (3 * (3 * (3 ^ 1)))
≡⟨⟩
3 * (3 * (3 * (3 * (3 ^ 0))))
≡⟨⟩
3 * (3 * (3 * (3 * 1)))
≡⟨⟩
81
∎
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
-- 5)
_ : 5 ∸ 3 ≡ 2
_ =
begin
5 ∸ 3
≡⟨⟩
4 ∸ 2
≡⟨⟩
3 ∸ 1
≡⟨⟩
2 ∸ 0
≡⟨⟩
2
∎
_ : 3 ∸ 5 ≡ 0
_ =
begin
3 ∸ 5
≡⟨⟩
2 ∸ 4
≡⟨⟩
1 ∸ 3
≡⟨⟩
0 ∸ 2
≡⟨⟩
0
∎
infixl 6 _+_ _∸_
infixl 7 _*_
{-# BUILTIN NATPLUS _+_ #-}
{-# BUILTIN NATTIMES _*_ #-}
{-# BUILTIN NATMINUS _∸_ #-}
-- 6)
data Bin : Set where
- : Bin
_O : Bin → Bin
_I : Bin → Bin
inc : Bin → Bin
inc - = - I
inc (rest O) = rest I
inc (rest I) = (inc rest) O
to : ℕ → Bin
to zero = - O
to (suc n) = inc (to n)
from : Bin → ℕ
from - = 0
from (rest O) = 2 * from rest
from (rest I) = 2 * from rest + 1
|
{
"alphanum_fraction": 0.3716255026,
"avg_line_length": 11.7635135135,
"ext": "agda",
"hexsha": "45e17078a875639c2eb555a43042125cc4892e97",
"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": "64a00f1f97f053d246d5b9deab090e75d923fe8f",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "aronerben/agda-playground",
"max_forks_repo_path": "plfa/naturals.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "64a00f1f97f053d246d5b9deab090e75d923fe8f",
"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": "aronerben/agda-playground",
"max_issues_repo_path": "plfa/naturals.agda",
"max_line_length": 52,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "64a00f1f97f053d246d5b9deab090e75d923fe8f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "aronerben/agda-playground",
"max_stars_repo_path": "plfa/naturals.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1000,
"size": 1741
}
|
{-# OPTIONS --copatterns --sized-types #-}
-- {-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.conv:10 -v tc.conv.size:15 #-}
module Delay where
--open import Library
open import Size
open import Category.Monad
open import Level renaming (zero to lzero; suc to lsuc)
open import Relation.Binary public
import Relation.Binary.PreorderReasoning
module Pre = Relation.Binary.PreorderReasoning
open import Data.Product
-- Coinductive delay monad.
mutual
data Delay (A : Set) (i : Size) : Set where
now : A → Delay A i
later : ∞Delay A i → Delay A i
record ∞Delay (A : Set) (i : Size) : Set where
coinductive
constructor delay
field
force : {j : Size< i} → Delay A j
open ∞Delay public
-- Smart constructor.
later! : ∀ {A i} → Delay A i → Delay A (↑ i)
later! x = later (delay x)
-- Monad instance.
module Bind where
mutual
_>>=_ : ∀ {i A B} → Delay A i → (A → Delay B i) → Delay B i
now x >>= f = f x
later x >>= f = later (x ∞>>= f)
_∞>>=_ : ∀ {i A B} → ∞Delay A i → (A → Delay B i) → ∞Delay B i
force (x ∞>>= f) = force x >>= f
delayMonad : ∀ {i} → RawMonad {f = lzero} (λ A → Delay A i)
delayMonad {i} = record
{ return = now
; _>>=_ = _>>=_ {i}
} where open Bind
module _ {i : Size} where
open module DelayMonad = RawMonad (delayMonad {i = i})
public renaming (_⊛_ to _<*>_)
open Bind public using (_∞>>=_)
-- Map for ∞Delay
_∞<$>_ : ∀ {i A B} (f : A → B) (∞a : ∞Delay A i) → ∞Delay B i
f ∞<$> ∞a = ∞a ∞>>= λ a → return (f a)
-- force (f ∞<$> ∞a) = f <$> force ∞a
-- Double bind
_=<<2_,_ : ∀ {i A B C} → (A → B → Delay C i) → Delay A i → Delay B i → Delay C i
f =<<2 x , y = x >>= λ a → y >>= λ b → f a b
-- Strong bisimilarity
mutual
data _~_ {i : Size} {A : Set} : (a? b? : Delay A ∞) → Set where
~now : ∀ a → now a ~ now a
~later : ∀ {a∞ b∞} (eq : _∞~_ {i} a∞ b∞) → later a∞ ~ later b∞
record _∞~_ {i : Size} {A : Set} (a∞ b∞ : ∞Delay A ∞) : Set where
coinductive
constructor ~delay
field
~force : {j : Size< i} → _~_ {j} (force a∞) (force b∞)
open _∞~_ public
-- Reflexivity
mutual
~refl : ∀ {i A} (a? : Delay A ∞) → _~_ {i} a? a?
~refl (now a) = ~now a
~refl (later a∞) = ~later (∞~refl a∞)
∞~refl : ∀ {i A} (a∞ : ∞Delay A ∞) → _∞~_ {i} a∞ a∞
~force (∞~refl a∞) = ~refl (force a∞)
-- Symmetry
mutual
~sym : ∀ {i A} {a? b? : Delay A ∞} → _~_ {i} a? b? → _~_ {i} b? a?
~sym (~now a) = ~now a
~sym (~later eq) = ~later (∞~sym eq)
∞~sym : ∀ {i A} {a? b? : ∞Delay A ∞} → _∞~_ {i} a? b? → _∞~_ {i} b? a?
~force (∞~sym eq) = ~sym (~force eq)
-- Transitivity
mutual
~trans : ∀ {i A} {a? b? c? : Delay A ∞}
(eq : _~_ {i} a? b?) (eq' : _~_ {i} b? c?) → _~_ {i} a? c?
~trans (~now a) (~now .a) = ~now a
~trans (~later eq) (~later eq') = ~later (∞~trans eq eq')
∞~trans : ∀ {i A} {a∞ b∞ c∞ : ∞Delay A ∞}
(eq : _∞~_ {i} a∞ b∞) (eq' : _∞~_ {i} b∞ c∞) → _∞~_ {i} a∞ c∞
~force (∞~trans eq eq') = ~trans (~force eq) (~force eq')
-- Equality reasoning
~setoid : (i : Size) (A : Set) → Setoid lzero lzero
~setoid i A = record
{ Carrier = Delay A ∞
; _≈_ = _~_ {i}
; isEquivalence = record
{ refl = λ {a?} → ~refl a?
; sym = ~sym
; trans = ~trans
}
}
module ~-Reasoning {i : Size} {A : Set} where
open Pre (Setoid.preorder (~setoid i A)) public
-- using (begin_; _∎) (_≈⟨⟩_ to _~⟨⟩_; _≈⟨_⟩_ to _~⟨_⟩_)
renaming (_≈⟨⟩_ to _≡⟨⟩_; _≈⟨_⟩_ to _≡⟨_⟩_; _∼⟨_⟩_ to _~⟨_⟩_; begin_ to proof_)
∞~setoid : (i : Size) (A : Set) → Setoid lzero lzero
∞~setoid i A = record
{ Carrier = ∞Delay A ∞
; _≈_ = _∞~_ {i}
; isEquivalence = record
{ refl = λ {a?} → ∞~refl a?
; sym = ∞~sym
; trans = ∞~trans
}
}
module ∞~-Reasoning {i : Size} {A : Set} where
open Pre (Setoid.preorder (∞~setoid i A)) public
-- using (begin_; _∎) (_≈⟨⟩_ to _~⟨⟩_; _≈⟨_⟩_ to _~⟨_⟩_)
renaming (_≈⟨⟩_ to _≡⟨⟩_; _≈⟨_⟩_ to _≡⟨_⟩_; _∼⟨_⟩_ to _∞~⟨_⟩_; begin_ to proof_)
-- Congruence laws.
mutual
bind-cong-l : ∀ {i A B} {a? b? : Delay A ∞} (eq : _~_ {i} a? b?)
(k : A → Delay B ∞) → _~_ {i} (a? >>= k) (b? >>= k)
bind-cong-l (~now a) k = ~refl _
bind-cong-l (~later eq) k = ~later (∞bind-cong-l eq k)
∞bind-cong-l : ∀ {i A B} {a∞ b∞ : ∞Delay A ∞} (eq : _∞~_ {i} a∞ b∞) →
(k : A → Delay B ∞) →
_∞~_ {i} (a∞ ∞>>= k) (b∞ ∞>>= k)
~force (∞bind-cong-l eq k) = bind-cong-l (~force eq) k
_>>=l_ = bind-cong-l
mutual
bind-cong-r : ∀ {i A B} (a? : Delay A ∞) {k l : A → Delay B ∞} →
(h : ∀ a → _~_ {i} (k a) (l a)) → _~_ {i} (a? >>= k) (a? >>= l)
bind-cong-r (now a) h = h a
bind-cong-r (later a∞) h = ~later (∞bind-cong-r a∞ h)
∞bind-cong-r : ∀ {i A B} (a∞ : ∞Delay A ∞) {k l : A → Delay B ∞} →
(h : ∀ a → _~_ {i} (k a) (l a)) → _∞~_ {i} (a∞ ∞>>= k) (a∞ ∞>>= l)
~force (∞bind-cong-r a∞ h) = bind-cong-r (force a∞) h
_>>=r_ = bind-cong-r
mutual
bind-cong : ∀ {i A B} {a? b? : Delay A ∞} (eq : _~_ {i} a? b?)
{k l : A → Delay B ∞} (h : ∀ a → _~_ {i} (k a) (l a)) →
_~_ {i} (a? >>= k) (b? >>= l)
bind-cong (~now a) h = h a
bind-cong (~later eq) h = ~later (∞bind-cong eq h)
∞bind-cong : ∀ {i A B} {a∞ b∞ : ∞Delay A ∞} (eq : _∞~_ {i} a∞ b∞)
{k l : A → Delay B ∞} (h : ∀ a → _~_ {i} (k a) (l a)) →
_∞~_ {i} (a∞ ∞>>= k) (b∞ ∞>>= l)
~force (∞bind-cong eq h) = bind-cong (~force eq) h
_~>>=_ = bind-cong
-- Monad laws.
mutual
bind-assoc : ∀{i A B C}(m : Delay A ∞)
{k : A → Delay B ∞}{l : B → Delay C ∞} →
_~_ {i} ((m >>= k) >>= l) (m >>= λ a → k a >>= l)
bind-assoc (now a) = ~refl _
bind-assoc (later a∞) = ~later (∞bind-assoc a∞)
∞bind-assoc : ∀{i A B C}(a∞ : ∞Delay A ∞)
{k : A → Delay B ∞}{l : B → Delay C ∞} →
_∞~_ {i} ((a∞ ∞>>= λ a → k a) ∞>>= l) (a∞ ∞>>= λ a → k a >>= l)
~force (∞bind-assoc a∞) = bind-assoc (force a∞)
-- Termination/Convergence. Makes sense only for Delay A ∞.
data _⇓_ {A : Set} : (a? : Delay A ∞) (a : A) → Set where
now⇓ : ∀ {a} → now a ⇓ a
later⇓ : ∀ {a} {a∞ : ∞Delay A ∞} → force a∞ ⇓ a → later a∞ ⇓ a
_⇓ : {A : Set} (x : Delay A ∞) → Set
x ⇓ = ∃ λ a → x ⇓ a
-- Monotonicity.
map⇓ : ∀ {A B} {a : A} {a? : Delay A ∞}
(f : A → B) (a⇓ : a? ⇓ a) → (f <$> a?) ⇓ f a
map⇓ f now⇓ = now⇓
map⇓ f (later⇓ a⇓) = later⇓ (map⇓ f a⇓)
-- some lemmas about convergence
subst~⇓ : ∀{A}{t t' : Delay A ∞}{n : A} → t ⇓ n → t ~ t' → t' ⇓ n
subst~⇓ now⇓ (~now a) = now⇓
subst~⇓ (later⇓ p) (~later eq) = later⇓ (subst~⇓ p (~force eq))
-- this should also hold for weak bisimularity right?
{-
subst≈⇓ : ∀{A}{t t' : Delay A ∞}{n : A} → t ⇓ n → t ≈ t' → t' ⇓ n
subst≈⇓ = ?
-}
⇓>>= : ∀{A B}(f : A → Delay B ∞)
{?a : Delay A ∞}{a : A} → ?a ⇓ a →
{b : B} → (?a >>= f) ⇓ b → f a ⇓ b
⇓>>= f now⇓ q = q
⇓>>= f (later⇓ p) (later⇓ q) = ⇓>>= f p q
>>=⇓ : ∀{A B}(f : A → Delay B ∞)
{?a : Delay A ∞}{a : A} → ?a ⇓ a →
{b : B} → f a ⇓ b → (?a >>= f) ⇓ b
>>=⇓ f now⇓ q = q
>>=⇓ f (later⇓ p) q = later⇓ (>>=⇓ f p q)
-- handy when you can't pattern match like in a let definition
unlater : ∀{A}{∞a : ∞Delay A ∞}{a : A} → later ∞a ⇓ a → force ∞a ⇓ a
unlater (later⇓ p) = p
{-
mutual
_⇓_ : {A : Set} {i : Size} (x : Delay A i) (a : A) → Set
x ⇓ a = Terminates a x
data Terminates {A : Set} {i : Size} (a : A) : Delay A i → Set where
now : now a ⇓ a
later : ∀ {x : ∞Delay A i} → (force x {j = ?}) ⇓ a → later x ⇓ a
mutual
cast : ∀ {A i} → Delay A i → (j : Size< ↑ i) → Delay A j
cast (now x) j = now x
cast (later x) j = {!later (∞cast x j)!}
∞cast : ∀ {A i} → ∞Delay A i → (j : Size< ↑ i) → ∞Delay A j
♭ (∞cast x j) {k} = cast {i = j} (♭ x) k
-}
|
{
"alphanum_fraction": 0.4660394381,
"avg_line_length": 28.3175182482,
"ext": "agda",
"hexsha": "f717df6b0ed2280e77b699f06e40d7461ea326b6",
"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": "Delay.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": "Delay.agda",
"max_line_length": 84,
"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": "Delay.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": 3654,
"size": 7759
}
|
module Cats.Adjunction where
open import Level using (suc ; _⊔_)
open import Cats.Category
open import Cats.Category.Cat.Facts.Product using (First ; Second)
open import Cats.Category.Fun using (Fun)
open import Cats.Category.Op using (_ᵒᵖ)
open import Cats.Category.Product.Binary using (_×_)
open import Cats.Category.Setoids using (Setoids)
open import Cats.Functor using (Functor ; _∘_)
open import Cats.Functor.Op using (Op)
open import Cats.Functor.Representable using (Hom[_])
open Functor
module _ {lo la l≈} {C D : Category lo la l≈} where
private
module Fun = Category (Fun ((C ᵒᵖ) × D) (Setoids la l≈))
record Adjunction (F : Functor C D) (U : Functor D C)
: Set (lo ⊔ suc la ⊔ suc l≈)
where
field
iso : (Hom[ D ] ∘ First (Op F)) Fun.≅ (Hom[ C ] ∘ Second U)
|
{
"alphanum_fraction": 0.6899128269,
"avg_line_length": 27.6896551724,
"ext": "agda",
"hexsha": "2d7653b406dbc30d7b1d611add18526e7a166aae",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Adjunction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Adjunction.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Adjunction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 249,
"size": 803
}
|
-- Example usage of solver
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor renaming (id to idF)
module Experiment.Categories.Solver.Functor.Example
{o ℓ e o′ ℓ′ e′} {𝒞 : Category o ℓ e} {𝒟 : Category o′ ℓ′ e′}
(F : Functor 𝒞 𝒟)
where
open Category 𝒟
open HomReasoning
open Functor F
open import Experiment.Categories.Solver.Functor F
module _ {A B C D E}
(f : 𝒞 [ D , E ]) (g : 𝒞 [ C , D ]) (h : 𝒞 [ B , C ]) (i : 𝒞 [ A , B ]) where
_ : F₁ (f 𝒞.∘ g 𝒞.∘ h) ∘ F₁ 𝒞.id ∘ F₁ i ∘ id ≈ F₁ (f 𝒞.∘ g) ∘ F₁ (h 𝒞.∘ i)
_ = solve (:F₁ (∥-∥′ :∘ ∥-∥′ :∘ ∥-∥′) :∘ :F₁ :id :∘ :F₁ (∥-∥′) :∘ :id)
(:F₁ (∥-∥′ :∘ ∥-∥′) :∘ :F₁ (∥-∥′ :∘ ∥-∥′))
refl
|
{
"alphanum_fraction": 0.5096418733,
"avg_line_length": 29.04,
"ext": "agda",
"hexsha": "652c61e7f49393ee9bd3430b6d584faf0b7854e5",
"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": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/Categories/Solver/Functor/Example.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"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": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/Categories/Solver/Functor/Example.agda",
"max_line_length": 86,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/Categories/Solver/Functor/Example.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 349,
"size": 726
}
|
postulate
P : (A : Set) → A → Set
X : Set
x : X
P' : (A : Set) → _
R : Set
R = P' _ x
P' = P
|
{
"alphanum_fraction": 0.3883495146,
"avg_line_length": 7.9230769231,
"ext": "agda",
"hexsha": "6dfef6ab3fb4bf8c01190f6cb17a15dba4998088",
"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/Issue1016.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/Issue1016.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/Succeed/Issue1016.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": 53,
"size": 103
}
|
open import Level using (0ℓ)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; cong; cong₂; isEquivalence; setoid)
open import Relation.Binary.PropositionalEquality.WithK using (≡-irrelevant)
open import Data.Unit using (⊤; tt)
open import Agda.Builtin.FromNat using (Number)
open import Data.Product using (_,_)
module AKS.Rational.Properties where
open import AKS.Rational.Base using (ℚ; _+_; _*_; -_; _/_; _≟_)
open import Algebra.Structures {A = ℚ} _≡_ using
( IsCommutativeRing; IsRing; IsAbelianGroup
; IsGroup; IsMonoid; IsSemigroup; IsMagma
)
open import Algebra.Definitions {A = ℚ} _≡_ using
( _DistributesOver_; _DistributesOverʳ_; _DistributesOverˡ_
; RightIdentity; LeftIdentity; Identity; Associative; Commutative
; RightInverse; LeftInverse; Inverse
)
open import AKS.Algebra.Structures ℚ _≡_ using (IsNonZeroCommutativeRing; IsIntegralDomain; IsGCDDomain; IsDecField)
open import Algebra.Bundles using (Ring; CommutativeRing)
open import AKS.Algebra.Bundles using (NonZeroCommutativeRing; DecField)
open import AKS.Unsafe using (BOTTOM; ≢-irrelevant)
+-isMagma : IsMagma _+_
+-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _+_
}
+-assoc : Associative _+_
+-assoc = BOTTOM
+-isSemigroup : IsSemigroup _+_
+-isSemigroup = record
{ isMagma = +-isMagma
; assoc = +-assoc
}
+-comm : Commutative _+_
+-comm = BOTTOM
+-identityˡ : LeftIdentity 0 _+_
+-identityˡ = BOTTOM
open import Algebra.FunctionProperties.Consequences.Propositional using (comm+idˡ⇒idʳ; comm+invˡ⇒invʳ; comm+distrˡ⇒distrʳ)
+-identityʳ : RightIdentity 0 _+_
+-identityʳ = BOTTOM -- comm+idˡ⇒idʳ +-comm +-identityˡ
+-identity : Identity 0 _+_
+-identity = +-identityˡ , +-identityʳ
+-isMonoid : IsMonoid _+_ 0
+-isMonoid = record
{ isSemigroup = +-isSemigroup
; identity = +-identity
}
-‿inverseˡ : LeftInverse 0 -_ _+_
-‿inverseˡ = BOTTOM
-‿inverseʳ : RightInverse 0 -_ _+_
-‿inverseʳ = BOTTOM -- comm+invˡ⇒invʳ +-comm -‿inverseˡ
-‿inverse : Inverse 0 -_ _+_
-‿inverse = -‿inverseˡ , -‿inverseʳ
+-isGroup : IsGroup _+_ 0 -_
+-isGroup = record
{ isMonoid = +-isMonoid
; inverse = -‿inverse
; ⁻¹-cong = cong -_
}
+-isAbelianGroup : IsAbelianGroup _+_ 0 -_
+-isAbelianGroup = record
{ isGroup = +-isGroup
; comm = +-comm
}
*-isMagma : IsMagma _*_
*-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _*_
}
*-assoc : Associative _*_
*-assoc = BOTTOM
*-isSemigroup : IsSemigroup _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc
}
*-comm : Commutative _*_
*-comm x y = BOTTOM
*-identityˡ : LeftIdentity 1 _*_
*-identityˡ x = BOTTOM
*-identityʳ : RightIdentity 1 _*_
*-identityʳ = BOTTOM -- comm+idˡ⇒idʳ *-comm *-identityˡ
*-identity : Identity 1 _*_
*-identity = *-identityˡ , *-identityʳ
*-isMonoid : IsMonoid _*_ 1
*-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-distribˡ-+ : _*_ DistributesOverˡ _+_
*-distribˡ-+ = BOTTOM
*-distribʳ-+ : _*_ DistributesOverʳ _+_
*-distribʳ-+ = BOTTOM -- comm+distrˡ⇒distrʳ *-comm *-distribˡ-+
*-distrib-+ : _*_ DistributesOver _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
+-*-isRing : IsRing _+_ _*_ -_ 0 1
+-*-isRing = record
{ +-isAbelianGroup = +-isAbelianGroup
; *-isMonoid = *-isMonoid
; distrib = *-distrib-+
}
+-*-isCommutativeRing : IsCommutativeRing _+_ _*_ -_ 0 1
+-*-isCommutativeRing = record
{ isRing = +-*-isRing
; *-comm = *-comm
}
+-*-isNonZeroCommutativeRing : IsNonZeroCommutativeRing _+_ _*_ -_ 0 1
+-*-isNonZeroCommutativeRing = record
{ isCommutativeRing = +-*-isCommutativeRing
; 0#≉1# = λ ()
}
+-*-nonZeroCommutativeRing : NonZeroCommutativeRing 0ℓ 0ℓ
+-*-nonZeroCommutativeRing = record { isNonZeroCommutativeRing = +-*-isNonZeroCommutativeRing }
/-inverse : ∀ x y {y≢0} → x ≡ y * (x / y) {y≢0}
/-inverse x y {y≢0} = BOTTOM
open import AKS.Algebra.Consequences +-*-nonZeroCommutativeRing using (module Inverse⇒Field)
open Inverse⇒Field _≟_ ≡-irrelevant ≢-irrelevant _/_ /-inverse
using (gcd)
renaming (isField to +-*-/-isField; [field] to +-*-/-field) public
+-*-/-isDecField : IsDecField _≟_ _+_ _*_ -_ 0 1 _/_ gcd
+-*-/-isDecField = record { isField = +-*-/-isField }
+-*-/-decField : DecField 0ℓ 0ℓ
+-*-/-decField = record { isDecField = +-*-/-isDecField }
|
{
"alphanum_fraction": 0.6873408933,
"avg_line_length": 26.3475609756,
"ext": "agda",
"hexsha": "935be09790206cdd540adc00726d7f0546c5d774",
"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/Properties.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/Properties.agda",
"max_line_length": 122,
"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/Properties.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": 1608,
"size": 4321
}
|
------------------------------------------------------------------------
-- Progress of CBV reductions in pure type systems (PTS)
------------------------------------------------------------------------
-- This module contains a variant of the "progress" theorem for PTS.
-- Progress says roughly that well-typed terms do not get stuck.
-- I.e. a well-typed term is either a value or it can take a CBV
-- reduction step. Together with the subject reduction (aka
-- "preservation") theorem from Pts.Typing, progress ensures type
-- soundness. For detials, see e.g.
--
-- * B. C. Pierce, TAPL (2002), pp. 95.
--
-- * A. Wright and M. Felleisen, "A Syntactic Approach to Type
-- Soundness" (1994).
module Pts.Typing.Progress where
open import Data.Product using (_,_; ∃; _×_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (¬_)
open import Relation.Nullary.Negation using (contradiction)
open import Pts.Typing
open import Pts.Reduction.Cbv
open import Pts.Reduction.Full
-- Definitions and lemmas are parametrized by a given PTS instance.
module _ {pts} where
open PTS pts
open Syntax
open Ctx
open Substitution using (_[_])
open Typing pts
-- A helper lemma: sorts are not product types.
Π≢sort : ∀ {n s} {a : Term n} {b} → ¬ (Π a b ≡β sort s)
Π≢sort Πab≡s =
let _ , Πab→*c , s→*c = ≡β⇒→β* Πab≡s
_ , _ , _ , _ , Πa′b′≡c = Π-→β* Πab→*c
in contradiction Πa′b′≡c (sort⇒¬Π (sort-→β* s→*c))
where
sort⇒¬Π : ∀ {n s a b} {c : Term n} → sort s ≡ c → ¬ (Π a b ≡ c)
sort⇒¬Π refl ()
-- A canonical forms lemma for dependent product values: closed
-- values of product type are abstractions.
Π-can : ∀ {f a b} → Val f → [] ⊢ f ∈ Π a b → ∃ λ a′ → ∃ λ t → f ≡ ƛ a′ t
Π-can (sort s) s∈Πab =
let _ , _ , Πab≡s′ = sort-gen s∈Πab
in contradiction Πab≡s′ Π≢sort
Π-can (Π c d) Πcd∈Πab =
let _ , _ , _ , _ , _ , _ , Πab≡s = Π-gen Πcd∈Πab
in contradiction Πab≡s Π≢sort
Π-can (ƛ a′ t) (ƛ a∈s t∈b) = a′ , t , refl
Π-can (ƛ a′ t) (conv λa′t∈c c∈s c≡Πab) = a′ , t , refl
-- Progress: well-typed terms do not get stuck (under CBV reduction).
prog : ∀ {a b} → [] ⊢ a ∈ b → Val a ⊎ (∃ λ a′ → a →v a′)
prog (var () Γ-wf)
prog (axiom a Γ-wf) = inj₁ (sort _)
prog (Π r a∈s₁ b∈s₂) = inj₁ (Π _ _)
prog (ƛ t∈b Πab∈s) = inj₁ (ƛ _ _)
prog (f∈Πab · t∈a) with prog f∈Πab
prog (f∈Πab · t∈a) | inj₁ u with prog t∈a
prog (f∈Πab · t∈a) | inj₁ u | inj₁ v with Π-can u f∈Πab
...| a′ , t′ , refl = inj₂ (_ , cont a′ t′ v)
prog (f∈Πab · t∈a) | inj₁ u | inj₂ (t′ , t→t′) = inj₂ (_ , u ·₂ t→t′)
prog (f∈Πab · t∈a) | inj₂ (f′ , f→f′) = inj₂ (_ , f→f′ ·₁ _)
prog (conv a∈b₁ b₂∈s b₁≡b₂) = prog a∈b₁
|
{
"alphanum_fraction": 0.5620280475,
"avg_line_length": 38.095890411,
"ext": "agda",
"hexsha": "06331551b39d7a061634aa53ce19c927e3fe523c",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-08-11T23:28:33.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-20T10:29:44.000Z",
"max_forks_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "asr/pts-agda",
"max_forks_repo_path": "src/Pts/Typing/Progress.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43",
"max_issues_repo_issues_event_max_datetime": "2017-08-21T16:01:50.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-08-21T14:48:09.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "asr/pts-agda",
"max_issues_repo_path": "src/Pts/Typing/Progress.agda",
"max_line_length": 74,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "asr/pts-agda",
"max_stars_repo_path": "src/Pts/Typing/Progress.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-31T10:47:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-05-13T12:11:10.000Z",
"num_tokens": 1133,
"size": 2781
}
|
module Structure where
-- Structures in meta-functions.
module Function' where -- TODO: Temporary naming fix with tick
module Properties ⦃ signature : Signature ⦄ where
Type : Domain → Domain → Function → Formula
Type(X)(Y)(f) = ∀ₛ(X)(x ↦ f(x) ∈ Y)
Closed : Domain → Function → Formula
Closed(S)(f) = Type(S)(S)(f)
Injective'' : Domain → Function → Formula
Injective''(A)(f) = ∀ₛ(A)(x ↦ ∀ₛ(A)(y ↦ (f(x) ≡ f(y)) ⟶ (x ≡ y)))
Surjective'' : Domain → Domain → Function → Formula
Surjective''(A)(B)(f) = ∀ₛ(B)(y ↦ ∃ₛ(A)(x ↦ f(x) ≡ y))
Bijective'' : Domain → Domain → Function → Formula
Bijective''(A)(B)(f) =
Injective''(A)(f)
∧ Surjective''(A)(B)(f)
Preserving₁'' : Domain → Function → Function → Function → Formula
Preserving₁''(A)(f)(g₁)(g₂) = ∀ₛ(A)(x ↦ f(g₁(x)) ≡ g₂(f(x)))
Preserving₂'' : Domain → Domain → Function → BinaryOperator → BinaryOperator → Formula
Preserving₂''(A)(B)(f)(_▫₁_)(_▫₂_) = ∀ₛ(A)(x ↦ ∀ₛ(B)(y ↦ f(x ▫₁ y) ≡ (f(x) ▫₂ f(y))))
module Relator where
module Properties where
Reflexivity : Domain → BinaryRelator → Formula
Reflexivity(S)(_▫_) = ∀ₛ(S)(x ↦ x ▫ x)
Irreflexivity : Domain → BinaryRelator → Formula
Irreflexivity(S)(_▫_) = ∀ₛ(S)(x ↦ ¬(x ▫ x))
Symmetry : Domain → BinaryRelator → Formula
Symmetry(S)(_▫_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ (x ▫ y) ⟶ (y ▫ x)))
Asymmetry : Domain → BinaryRelator → Formula
Asymmetry(S)(_▫_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ (x ▫ y) ⟶ ¬(y ▫ x)))
Antisymmetry : Domain → BinaryRelator → Formula
Antisymmetry(S)(_▫_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ (x ▫ y)∧(y ▫ x) ⟶ (x ≡ y)))
Transitivity : Domain → BinaryRelator → Formula
Transitivity(S)(_▫_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ ∀ₛ(S)(z ↦ (x ▫ y)∧(y ▫ z) ⟶ (x ▫ z))))
Equivalence : Domain → BinaryRelator → Formula
Equivalence(S)(_▫_) =
Reflexivity(S)(_▫_)
∧ Symmetry(S)(_▫_)
∧ Transitivity(S)(_▫_)
SymmetricallyTotal : Domain → BinaryRelator → Formula
SymmetricallyTotal(S)(_▫_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ (x ▫ y) ∨ (y ▫ x)))
module Ordering where
open Relator.Properties
Minima : Domain → BinaryRelator → Domain → Formula
Minima(S)(_≤_)(min) = ∀ₛ(S)(x ↦ min ≤ x)
Maxima : Domain → BinaryRelator → Domain → Formula
Maxima(S)(_≤_)(max) = ∀ₛ(S)(x ↦ x ≤ max)
module _ ⦃ signature : Signature ⦄ where
open Signature ⦃ ... ⦄
lowerBounds : Domain → BinaryRelator → Domain → Domain
lowerBounds(S)(_≤_)(Sₛ) = filter(S)(Minima(S)(_≤_))
upperBounds : Domain → BinaryRelator → Domain → Domain
upperBounds(S)(_≤_)(Sₛ) = filter(S)(Maxima(S)(_≤_))
interval : Domain → BinaryRelator → Domain → Domain → Domain
interval(S)(_≤_) (a)(b) = filter(S)(s ↦ (a ≤ s) ∧ (s ≤ b))
Bounded : Domain → BinaryRelator → Domain → Domain → Formula
Bounded(S)(_≤_) (a)(b) = ∀ₛ(S)(s ↦ (a ≤ s) ∧ (s ≤ b))
Infima : Domain → BinaryRelator → Domain → Domain → Formula
Infima(S)(_≤_)(Sₛ)(inf) = Maxima(lowerBounds(S)(_≤_)(Sₛ))(_≤_)(inf)
Suprema : Domain → BinaryRelator → Domain → Domain → Formula
Suprema(S)(_≤_)(Sₛ)(sup) = Minima(upperBounds(S)(_≤_)(Sₛ))(_≤_)(sup)
module Weak where
PartialOrder : Domain → BinaryRelator → Formula
PartialOrder(S)(_≤_) =
Reflexivity(S)(_≤_)
∧ Antisymmetry(S)(_≤_)
∧ Transitivity(S)(_≤_)
TotalOrder : Domain → BinaryRelator → Formula
TotalOrder(S)(_≤_) =
PartialOrder(S)(_≤_)
∧ SymmetricallyTotal(S)(_≤_)
module Strict where
Order : Domain → BinaryRelator → Formula
Order(S)(_<_) =
Irreflexivity(S)(_<_)
∧ Asymmetry(S)(_<_)
∧ Transitivity(S)(_<_)
Dense : Domain → BinaryRelator → Formula
Dense(S)(_<_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ (x < y) ⟶ ∃ₛ(S)(z ↦ (x < z)∧(z < y))))
module Operator where
module Properties where
AssociativityPattern : Domain → Domain → Domain → BinaryOperator → BinaryOperator → BinaryOperator → BinaryOperator → Formula
AssociativityPattern(x)(y)(z)(_▫₁_)(_▫₂_)(_▫₃_)(_▫₄_) = (((x ▫₁ y) ▫₂ z) ≡ (x ▫₃ (y ▫₄ z)))
DistributivityₗPattern : Domain → Domain → Domain → BinaryOperator → BinaryOperator → BinaryOperator → BinaryOperator → BinaryOperator → Formula
DistributivityₗPattern(x)(y)(z)(_▫₁_)(_▫₂_)(_▫₃_)(_▫₄_)(_▫₅_) = (x ▫₁ (y ▫₂ z)) ≡ ((x ▫₃ y) ▫₄ (x ▫₅ z))
DistributivityᵣPattern : Domain → Domain → Domain → BinaryOperator → BinaryOperator → BinaryOperator → BinaryOperator → BinaryOperator → Formula
DistributivityᵣPattern(x)(y)(z)(_▫₁_)(_▫₂_)(_▫₃_)(_▫₄_)(_▫₅_) = ((x ▫₂ y) ▫₁ z) ≡ ((x ▫₃ z) ▫₄ (y ▫₅ z))
Type : BinaryOperator → Domain → Domain → Domain → Formula
Type(_▫_)(X)(Y)(Z) = ∀ₛ(X)(x ↦ ∀ₛ(Y)(y ↦ (x ▫ y) ∈ Z))
Closed : Domain → BinaryOperator → Formula
Closed(S)(_▫_) = Type(_▫_)(S)(S)(S)
Commutativity : Domain → BinaryOperator → Formula
Commutativity(S)(_▫_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ (x ▫ y) ≡ (y ▫ x)))
Associativity : Domain → BinaryOperator → Formula
Associativity(S)(_▫_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ ∀ₛ(S)(z ↦ AssociativityPattern(x)(y)(z)(_▫_)(_▫_)(_▫_)(_▫_))))
Identityₗ : Domain → BinaryOperator → Domain → Formula
Identityₗ(S)(_▫_)(id) = ∀ₛ(S)(x ↦ (id ▫ x) ≡ x)
Identityᵣ : Domain → BinaryOperator → Domain → Formula
Identityᵣ(S)(_▫_)(id) = ∀ₛ(S)(x ↦ (x ▫ id) ≡ x)
Identity : Domain → BinaryOperator → Domain → Formula
Identity(S)(_▫_)(id) = Identityₗ(S)(_▫_)(id) ∧ Identityᵣ(S)(_▫_)(id)
Invertibleₗ : Domain → BinaryOperator → Domain → Formula
Invertibleₗ(S)(_▫_)(id) = ∀ₛ(S)(x ↦ ∃ₛ(S)(x⁻¹ ↦ (x⁻¹ ▫ x) ≡ id))
Invertibleᵣ : Domain → BinaryOperator → Domain → Formula
Invertibleᵣ(S)(_▫_)(id) = ∀ₛ(S)(x ↦ ∃ₛ(S)(x⁻¹ ↦ (x ▫ x⁻¹) ≡ id))
Invertible : Domain → BinaryOperator → Domain → Formula
Invertible(S)(_▫_)(id) = ∀ₛ(S)(x ↦ ∃ₛ(S)(x⁻¹ ↦ ((x⁻¹ ▫ x) ≡ id) ∧ ((x ▫ x⁻¹) ≡ id)))
Distributivityₗ : Domain → BinaryOperator → BinaryOperator → Formula
Distributivityₗ(S)(_▫₁_)(_▫₂_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ ∀ₛ(S)(z ↦ DistributivityₗPattern(x)(y)(z)(_▫₁_)(_▫₂_)(_▫₁_)(_▫₂_)(_▫₁_))))
Distributivityᵣ : Domain → BinaryOperator → BinaryOperator → Formula
Distributivityᵣ(S)(_▫₁_)(_▫₂_) = ∀ₛ(S)(x ↦ ∀ₛ(S)(y ↦ ∀ₛ(S)(z ↦ DistributivityᵣPattern(x)(y)(z)(_▫₁_)(_▫₂_)(_▫₁_)(_▫₂_)(_▫₁_))))
Distributivity : Domain → BinaryOperator → BinaryOperator → Formula
Distributivity(S)(_▫₁_)(_▫₂_) = Distributivityₗ(S)(_▫₁_)(_▫₂_) ∧ Distributivityᵣ(S)(_▫₁_)(_▫₂_)
Compatibility : Domain → Domain → BinaryOperator → BinaryOperator → Formula
Compatibility(A)(B)(_▫₁_)(_▫₂_) = ∀ₛ(A)(a₁ ↦ ∀ₛ(A)(a₂ ↦ ∀ₛ(B)(b ↦ AssociativityPattern(a₁)(a₂)(b)(_▫₁_)(_▫₁_)(_▫₂_)(_▫₁_))))
Semigroup : Domain → BinaryOperator → Formula
Semigroup(S)(_▫_) =
Closed(S)(_▫_)
∧ Associativity(S)(_▫_)
Monoid : Domain → BinaryOperator → Formula
Monoid(S)(_▫_) =
Semigroup(S)(_▫_)
∧ ∃ₛ(S)(Identity(S)(_▫_))
Group : Domain → BinaryOperator → Formula
Group(S)(_▫_) =
Monoid(S)(_▫_)
∧ ∀ₛ(S)(id ↦ Identity(S)(_▫_)(id) ⟶ Invertible(S)(_▫_)(id))
CommutativeGroup : Domain → BinaryOperator → Formula
CommutativeGroup(S)(_▫_) =
Group(S)(_▫_)
∧ Commutativity(S)(_▫_)
Rng : Domain → BinaryOperator → BinaryOperator → Formula
Rng(S)(_▫₁_)(_▫₂_) =
CommutativeGroup(S)(_▫₁_)
∧ Semigroup(S)(_▫₂_)
∧ Distributivity(S)(_▫₂_)(_▫₁_)
Ring : Domain → BinaryOperator → BinaryOperator → Formula
Ring(S)(_▫₁_)(_▫₂_) =
CommutativeGroup(S)(_▫₁_)
∧ Monoid(S)(_▫₂_)
∧ Distributivity(S)(_▫₂_)(_▫₁_)
module _ ⦃ signature : Signature ⦄ where
open Signature ⦃ ... ⦄
Field : Domain → BinaryOperator → BinaryOperator → Formula
Field(S)(_▫₁_)(_▫₂_) =
CommutativeGroup(S)(_▫₁_)
∧ ∀ₛ(S)(id₁ ↦ Identity(S)(_▫₁_)(id₁) ⟶ CommutativeGroup(S ∖ singleton(id₁))(_▫₂_))
∧ Distributivity(S)(_▫₂_)(_▫₁_)
VectorSpace : Domain → Domain → BinaryOperator → BinaryOperator → BinaryOperator → BinaryOperator → Formula
VectorSpace(V)(S)(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_) =
CommutativeGroup(V)(_+ᵥ_)
∧ Field(S)(_+ₛ_)(_⋅ₛ_)
∧ ∀ₛ(S)(id ↦ Identity(S)(_⋅ₛ_)(id) ⟶ Identityₗ(V)(_⋅ₛᵥ_)(id))
∧ Compatibility(S)(V)(_⋅ₛᵥ_)(_⋅ₛ_)
∧ ∀ₛ(S)(s ↦ ∀ₛ(V)(v₁ ↦ ∀ₛ(V)(v₂ ↦ DistributivityₗPattern(s)(v₁)(v₂)(_⋅ₛᵥ_)(_+ᵥ_)(_⋅ₛᵥ_)(_+ᵥ_)(_⋅ₛᵥ_))))
∧ ∀ₛ(S)(s₁ ↦ ∀ₛ(S)(s₂ ↦ ∀ₛ(V)(v ↦ DistributivityᵣPattern(s₁)(s₂)(v)(_⋅ₛᵥ_)(_+ᵥ_)(_⋅ₛᵥ_)(_+ᵥ_)(_⋅ₛᵥ_))))
module Numeral where
module Natural ⦃ signature : Signature ⦄ where
open Signature ⦃ ... ⦄
FormulaInduction : Domain → Domain → Function → (Domain → Formula) → Formula
FormulaInduction(ℕ)(𝟎)(𝐒) (φ) = (φ(𝟎) ∧ ∀ₛ(ℕ)(n ↦ φ(n) ⟶ φ(𝐒(n)))) ⟶ ∀ₛ(ℕ)(φ)
SetInduction : Domain → Domain → Function → Formula
SetInduction(ℕ)(𝟎)(𝐒) = ∀ₗ(X ↦ ((𝟎 ∈ X) ∧ ∀ₛ(ℕ)(n ↦ (n ∈ X) ⟶ (𝐒(n) ∈ X))) ⟶ (ℕ ⊆ X))
-- TODO: Can be expressed as ∀ₗ(X ↦ Inductive(X) ⟶ (ℕ ⊆ X))
-- A set ℕ which can be constructed ℕ-inductively.
Peano : Domain → Domain → Function → Formula
Peano(ℕ)(𝟎)(𝐒) =
(𝟎 ∈ ℕ)
∧ Function'.Properties.Closed(ℕ)(𝐒)
∧ Function'.Properties.Injective''(ℕ)(𝐒)
∧ ∀ₛ(ℕ)(n ↦ 𝐒(n) ≢ 𝟎)
∧ SetInduction(ℕ)(𝟎)(𝐒)
|
{
"alphanum_fraction": 0.5585670764,
"avg_line_length": 41.0301724138,
"ext": "agda",
"hexsha": "ff8638ff8eb7b58b89163febc01bb51dac555f21",
"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": "old/Structure/Logic/Classical/SetTheory/Structure/Relator.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": "old/Structure/Logic/Classical/SetTheory/Structure/Relator.agda",
"max_line_length": 150,
"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": "old/Structure/Logic/Classical/SetTheory/Structure/Relator.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": 3694,
"size": 9519
}
|
module BasicIPC.Metatheory.Hilbert-TarskiConcreteGluedImplicit where
open import BasicIPC.Syntax.Hilbert public
open import BasicIPC.Semantics.TarskiConcreteGluedImplicit public
open ImplicitSyntax (_⊢_) public
-- Completeness with respect to a particular model.
module _ {{_ : Model}} where
reify : ∀ {A w} → w ⊩ A → unwrap w ⊢ A
reify {α P} s = syn s
reify {A ▻ B} s = syn s
reify {A ∧ B} s = pair (reify (π₁ s)) (reify (π₂ s))
reify {⊤} s = unit
reify⋆ : ∀ {Ξ w} → w ⊩⋆ Ξ → unwrap w ⊢⋆ Ξ
reify⋆ {∅} ∙ = ∙
reify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t
-- Additional useful equipment.
module _ {{_ : Model}} where
⟪K⟫ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A
⟪K⟫ {A} a = app ck (reify a) ⅋ K a
⟪S⟫′ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ {A} {B} {C} s₁ = app cs (syn s₁) ⅋ λ s₂ →
app (app cs (syn s₁)) (syn s₂) ⅋ ⟪S⟫ s₁ s₂
_⟪,⟫′_ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ∧ B
_⟪,⟫′_ {A} a = app cpair (reify a) ⅋ _,_ a
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (app t u) γ = eval t γ ⟪$⟫ eval u γ
eval ci γ = ci ⅋ I
eval ck γ = ck ⅋ ⟪K⟫
eval cs γ = cs ⅋ ⟪S⟫′
eval cpair γ = cpair ⅋ _⟪,⟫′_
eval cfst γ = cfst ⅋ π₁
eval csnd γ = csnd ⅋ π₂
eval unit γ = ∙
-- TODO: Correctness of evaluation with respect to conversion.
-- The canonical model.
private
instance
canon : Model
canon = record
{ _⊩ᵅ_ = λ w P → unwrap w ⊢ α P
}
-- Soundness with respect to the canonical model.
reflectᶜ : ∀ {A w} → unwrap w ⊢ A → w ⊩ A
reflectᶜ {α P} t = t ⅋ t
reflectᶜ {A ▻ B} t = t ⅋ λ a → reflectᶜ (app t (reify a))
reflectᶜ {A ∧ B} t = reflectᶜ (fst t) , reflectᶜ (snd t)
reflectᶜ {⊤} t = ∙
reflectᶜ⋆ : ∀ {Ξ w} → unwrap w ⊢⋆ Ξ → w ⊩⋆ Ξ
reflectᶜ⋆ {∅} ∙ = ∙
reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {w} → w ⊩⋆ unwrap w
refl⊩⋆ = reflectᶜ⋆ refl⊢⋆
trans⊩⋆ : ∀ {w w′ w″} → w ⊩⋆ unwrap w′ → w′ ⊩⋆ unwrap w″ → w ⊩⋆ unwrap w″
trans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reify⋆ ts) (reify⋆ us))
-- Completeness with respect to all models, or quotation.
quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A
quot s = reify (s refl⊩⋆)
-- Normalisation by evaluation.
norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
|
{
"alphanum_fraction": 0.5415813191,
"avg_line_length": 24.6565656566,
"ext": "agda",
"hexsha": "41c5d63c53d74313252afac2bf7073ea0ddc89ee",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.agda",
"max_line_length": 73,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 1130,
"size": 2441
}
|
open import Level hiding ( suc ; zero )
open import Algebra
module sym5n where
open import Symmetric
open import Data.Unit
open import Function.Inverse as Inverse using (_↔_; Inverse; _InverseOf_)
open import Function
open import Data.Nat hiding (_⊔_) -- using (ℕ; suc; zero)
open import Relation.Nullary
open import Data.Empty
open import Data.Product
open import Gutil
open import Putil
open import Solvable using (solvable)
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open import Data.Fin
open import Data.Fin.Permutation hiding (_∘ₚ_)
infixr 200 _∘ₚ_
_∘ₚ_ = Data.Fin.Permutation._∘ₚ_
-- open import IO
open import Data.String hiding (toList)
open import Data.Unit
open import Agda.Builtin.String
sym5solvable : (n : ℕ) → String -- ¬ solvable (Symmetric 5)
sym5solvable n = FListtoStr (CommFListN 5 n) where
open import Data.List using ( List ; [] ; _∷_ )
open Solvable (Symmetric 5)
open import FLutil
open import Data.List.Fresh hiding ([_])
open import Relation.Nary using (⌊_⌋)
p0id : FL→perm (zero :: zero :: zero :: (zero :: (zero :: f0))) =p= pid
p0id = pleq _ _ refl
open import Data.List.Fresh.Relation.Unary.Any
open import FLComm
stage4FList = CommFListN 5 0
stage6FList = CommFListN 5 3
-- stage5FList = {!!}
-- s2=s3 : CommFListN 5 2 ≡ CommFListN 5 3
-- s2=s3 = refl
FLtoStr : {n : ℕ} → (x : FL n) → String
FLtoStr f0 = "f0"
FLtoStr (x :: y) = primStringAppend ( primStringAppend (primShowNat (toℕ x)) " :: " ) (FLtoStr y)
FListtoStr : {n : ℕ} → (x : FList n) → String
FListtoStr [] = ""
FListtoStr (cons a x x₁) = primStringAppend (FLtoStr a) (primStringAppend "\n" (FListtoStr x))
open import Codata.Musical.Notation
open import Data.Maybe hiding (_>>=_)
open import Data.List
open import Data.Char
open import IO.Primitive
open import Codata.Musical.Costring
postulate
getArgs : IO (List (List Char))
{-# FOREIGN GHC import qualified System.Environment #-}
{-# COMPILE GHC getArgs = System.Environment.getArgs #-}
charToDigit : Char → Maybe ℕ
charToDigit '0' = just ( 0)
charToDigit '1' = just ( 1)
charToDigit '2' = just ( 2)
charToDigit '3' = just ( 3)
charToDigit '4' = just ( 4)
charToDigit '5' = just ( 5)
charToDigit '6' = just ( 6)
charToDigit '7' = just ( 7)
charToDigit '8' = just ( 8)
charToDigit '9' = just ( 9)
charToDigit _ = nothing
getNumArg1 : (List (List Char)) → ℕ
getNumArg1 [] = 0
getNumArg1 ([] ∷ y) = 0
getNumArg1 ((x ∷ _) ∷ y) with charToDigit x
... | just n = n
... | nothing = 0
--
-- CommFListN 5 x is too slow use compiler
-- agda --compile sym5n.agda
--
main : IO ⊤
main = getArgs >>= (λ x → putStrLn $ toCostring $ sym5solvable $ getNumArg1 x )
|
{
"alphanum_fraction": 0.6759735489,
"avg_line_length": 26.1730769231,
"ext": "agda",
"hexsha": "f1c4e9900f08ac4fa4bda3de5331c052219fd703",
"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": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/Galois",
"max_forks_repo_path": "src/sym5n.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/Galois",
"max_issues_repo_path": "src/sym5n.agda",
"max_line_length": 100,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/Galois",
"max_stars_repo_path": "src/sym5n.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-16T03:37:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-16T03:37:05.000Z",
"num_tokens": 916,
"size": 2722
}
|
-- Automatic solvers for equations over Gaussian Integers.
{-# OPTIONS --without-K --safe #-}
module GauInt.Solver where
import Algebra.Solver.Ring.Simple as Solver
import Algebra.Solver.Ring.AlmostCommutativeRing as ACR
open import GauInt.Properties
------------------------------------------------------------------------
-- A module for automatically solving propositional equivalences
-- containing _+𝔾_ and _*𝔾_
module +-*-Solver =
Solver (ACR.fromCommutativeRing +-*-commutativeRing) _≟_
|
{
"alphanum_fraction": 0.666,
"avg_line_length": 31.25,
"ext": "agda",
"hexsha": "708f6d53f692bc536d0c0c5f1f733a95170a33b4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "onestruggler/EucDomain",
"max_forks_repo_path": "GauInt/Solver.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "onestruggler/EucDomain",
"max_issues_repo_path": "GauInt/Solver.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "onestruggler/EucDomain",
"max_stars_repo_path": "GauInt/Solver.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 114,
"size": 500
}
|
module Agda.Builtin.Size where
{-# BUILTIN SIZEUNIV SizeU #-}
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZELT Size<_ #-}
{-# BUILTIN SIZESUC ↑_ #-}
{-# BUILTIN SIZEINF ω #-}
{-# BUILTIN SIZEMAX _⊔ˢ_ #-}
|
{
"alphanum_fraction": 0.5650224215,
"avg_line_length": 22.3,
"ext": "agda",
"hexsha": "15daf1b7449de2105da108abe3ba8a3a220c2d4f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Size.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Size.agda",
"max_line_length": 31,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Size.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 75,
"size": 223
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.SuspSmash
open import homotopy.SuspSmashComm
module homotopy.IterSuspSmash where
module _ {i j} (X : Ptd i) (Y : Ptd j) where
Σ^∧-out : (n : ℕ) → ⊙Susp^ n X ∧ Y → Susp^ n (X ∧ Y)
Σ^∧-out O = idf _
Σ^∧-out (S n) = Susp-fmap (Σ^∧-out n) ∘ Σ∧-out (⊙Susp^ n X) Y
private
Σ^∧-out-pt : (n : ℕ) → Σ^∧-out n (pt (⊙Susp^ n X ⊙∧ Y)) == pt (⊙Susp^ n (X ⊙∧ Y))
Σ^∧-out-pt O = idp
Σ^∧-out-pt (S n) = idp
⊙Σ^∧-out : (n : ℕ) → ⊙Susp^ n X ⊙∧ Y ⊙→ ⊙Susp^ n (X ⊙∧ Y)
⊙Σ^∧-out n = Σ^∧-out n , Σ^∧-out-pt n
∧Σ^-out : (n : ℕ) → X ∧ ⊙Susp^ n Y → Susp^ n (X ∧ Y)
∧Σ^-out O = idf _
∧Σ^-out (S n) = Susp-fmap (∧Σ^-out n) ∘ ∧Σ-out X (⊙Susp^ n Y)
private
∧Σ^-out-pt : (n : ℕ) → ∧Σ^-out n (pt (X ⊙∧ ⊙Susp^ n Y)) == pt (⊙Susp^ n (X ⊙∧ Y))
∧Σ^-out-pt O = idp
∧Σ^-out-pt (S n) = idp
⊙∧Σ^-out : (n : ℕ) → X ⊙∧ ⊙Susp^ n Y ⊙→ ⊙Susp^ n (X ⊙∧ Y)
⊙∧Σ^-out n = ∧Σ^-out n , ∧Σ^-out-pt n
private
⊙maybe-Susp^-flip-+ : ∀ {i} {X : Ptd i} (m n : ℕ) (b : Bool)
→ (m == 0 → b == false)
→ ⊙coe (⊙Susp^-+ m n {X}) ◃⊙∘
⊙maybe-Susp^-flip {X = ⊙Susp^ n X} m b ◃⊙idf
=⊙∘
⊙maybe-Susp^-flip (m + n) b ◃⊙∘
⊙coe (⊙Susp^-+ m n) ◃⊙idf
⊙maybe-Susp^-flip-+ O O b h = =⊙∘-in idp
⊙maybe-Susp^-flip-+ O (S n) true h = ⊥-elim (Bool-true≠false (h idp))
⊙maybe-Susp^-flip-+ O (S n) false h = =⊙∘-in idp
⊙maybe-Susp^-flip-+ {X = X} (S m) n true h =
⊙coe (ap ⊙Susp (Susp^-+ m n)) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp^ n X)) ◃⊙idf
=⊙∘₁⟨ 0 & 1 & ! p ⟩
⊙Susp-fmap (fst (⊙coe (⊙Susp^-+ m n))) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp^ n X)) ◃⊙idf
=⊙∘⟨ =⊙∘-in $ ! $
⊙Susp-flip-natural (⊙coe (⊙Susp^-+ m n)) ⟩
⊙Susp-flip (⊙Susp^ (m + n) X) ◃⊙∘
⊙Susp-fmap (fst (⊙coe (⊙Susp^-+ m n))) ◃⊙idf
=⊙∘₁⟨ 1 & 1 & p ⟩
⊙Susp-flip (⊙Susp^ (m + n) X) ◃⊙∘
⊙coe (ap ⊙Susp (Susp^-+ m n)) ◃⊙idf ∎⊙∘
where
p : ⊙Susp-fmap (fst (⊙coe (⊙Susp^-+ m n {X}))) ==
⊙coe (ap ⊙Susp (Susp^-+ m n))
p =
ap (⊙Susp-fmap ∘ coe) (de⊙-⊙Susp^-+ m n {X}) ∙
! (⊙transport-⊙Susp (Susp^-+ m n)) ∙
⊙transport-⊙coe ⊙Susp (Susp^-+ m n)
⊙maybe-Susp^-flip-+ (S m) n false h = =⊙∘-in $ ! $ ⊙λ= $ ⊙∘-unit-l _
⊙maybe-Susp^-flip-comm : ∀ {i} {X : Ptd i} (m n : ℕ) (b : Bool)
→ (m == 0 → b == false)
→ (n == 0 → b == false)
→ ⊙coe (⊙Susp^-comm m n {X = X}) ◃⊙∘
⊙maybe-Susp^-flip {X = ⊙Susp^ n X} m b ◃⊙idf
=⊙∘
⊙maybe-Susp^-flip {X = ⊙Susp^ m X} n b ◃⊙∘
⊙coe (⊙Susp^-comm m n) ◃⊙idf
⊙maybe-Susp^-flip-comm O O b h₁ h₂ = =⊙∘-in (! (⊙λ= (⊙∘-unit-l (⊙coe (⊙Susp^-comm 0 0)))))
⊙maybe-Susp^-flip-comm O (S _) true h₁ h₂ = ⊥-elim (Bool-true≠false (h₁ idp))
⊙maybe-Susp^-flip-comm O (S _) false h₁ h₂ = =⊙∘-in (! (⊙λ= (⊙∘-unit-l _)))
⊙maybe-Susp^-flip-comm (S m) O true h₁ h₂ = ⊥-elim (Bool-true≠false (h₂ idp))
⊙maybe-Susp^-flip-comm (S m) O false h₁ h₂ = =⊙∘-in (! (⊙λ= (⊙∘-unit-l _)))
⊙maybe-Susp^-flip-comm {X = X} (S m) (S n) true h₁ h₂ =
⊙coe (⊙Susp^-comm (S m) (S n)) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp^ (S n) X)) ◃⊙idf
=⊙∘₁⟨ 0 & 1 & p ⟩
⊙Susp-fmap (fst (⊙coe (⊙Susp^-comm m (S n) ∙ ⊙Susp^-comm 1 n))) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp^ (S n) X)) ◃⊙idf
=⊙∘⟨ =⊙∘-in $ ! $
⊙Susp-flip-natural (⊙coe (⊙Susp^-comm m (S n) ∙ ⊙Susp^-comm 1 n)) ⟩
⊙Susp-flip (⊙Susp^ n (⊙Susp^ (S m) X)) ◃⊙∘
⊙Susp-fmap (fst (⊙coe (⊙Susp^-comm m (S n) ∙ ⊙Susp^-comm 1 n))) ◃⊙idf
=⊙∘₁⟨ 1 & 1 & ! p ⟩
⊙Susp-flip (⊙Susp^ n (⊙Susp^ (S m) X)) ◃⊙∘
⊙Susp^-swap (S m) (S n) ◃⊙idf ∎⊙∘
where
p : ⊙Susp^-swap (S m) (S n) {X} ==
⊙Susp-fmap (fst (⊙coe (⊙Susp^-comm m (S n) {X} ∙ ⊙Susp^-comm 1 n {⊙Susp^ m X})))
p =
ap ⊙coe (⊙Susp^-comm-S-S m n) ∙
! (⊙transport-⊙coe ⊙Susp (Susp^-comm m (S n) ∙ Susp^-comm 1 n)) ∙
⊙transport-⊙Susp (Susp^-comm m (S n) ∙ Susp^-comm 1 n) ∙
! (ap (⊙Susp-fmap ∘ coe) (ap2 _∙_ (de⊙-⊙Susp^-comm m (S n)) (de⊙-⊙Susp^-comm 1 n))) ∙
ap (⊙Susp-fmap ∘ coe) (∙-ap de⊙ (⊙Susp^-comm m (S n)) (⊙Susp^-comm 1 n))
⊙maybe-Susp^-flip-comm (S m) (S n) false h₁ h₂ = =⊙∘-in (! (⊙λ= (⊙∘-unit-l _)))
⊙∧Σ-Σ^∧-out : ∀ {i} {j} (X : Ptd i) (Y : Ptd j) (m : ℕ)
→ ⊙Susp-fmap (∧Σ^-out X Y m) ◃⊙∘
⊙Σ∧-out X (⊙Susp^ m Y) ◃⊙idf
=⊙∘
⊙Susp^-swap m 1 {X = X ⊙∧ Y} ◃⊙∘
⊙maybe-Susp^-flip m (odd m) ◃⊙∘
⊙Susp^-fmap m (⊙Σ∧-out X Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ X)) Y m ◃⊙idf
⊙∧Σ-Σ^∧-out X Y 0 =
⊙Susp-fmap (idf (X ∧ Y)) ◃⊙∘
⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf
=⊙∘⟨ 0 & 1 & ⊙Susp-fmap-idf _ ⟩
⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf
=⊙∘⟨ 0 & 0 & ⊙contract ⟩
⊙idf _ ◃⊙∘
⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf
=⊙∘₁⟨ 0 & 1 & ap ⊙coe (! (⊙Susp^-comm-0-l 1 (X ⊙∧ Y))) ⟩
⊙Susp^-swap 0 1 ◃⊙∘
⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf
=⊙∘⟨ 1 & 0 & ⊙contract ⟩
⊙Susp^-swap 0 1 ◃⊙∘
⊙idf _ ◃⊙∘
⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf
=⊙∘⟨ 3 & 0 & ⊙contract ⟩
⊙Susp^-swap 0 1 ◃⊙∘
⊙idf _ ◃⊙∘
⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙∘
⊙idf _ ◃⊙idf ∎⊙∘
⊙∧Σ-Σ^∧-out X Y (S m) =
⊙Susp-fmap (∧Σ^-out X Y (S m)) ◃⊙∘
⊙Σ∧-out X (⊙Susp^ (S m) Y) ◃⊙idf
=⊙∘⟨ 0 & 1 & ⊙Susp-fmap-seq-∘ (Susp-fmap (∧Σ^-out X Y m) ◃∘
∧Σ-out X (⊙Susp^ m Y) ◃idf) ⟩
⊙Susp^-fmap 2 (⊙∧Σ^-out X Y m) ◃⊙∘
⊙Susp-fmap (∧Σ-out X (⊙Susp^ m Y)) ◃⊙∘
⊙Σ∧-out X (⊙Susp^ (S m) Y) ◃⊙idf
=⊙∘⟨ 1 & 2 & ⊙∧Σ-Σ∧-out X (⊙Susp^ m Y) ⟩
⊙Susp^-fmap 2 (⊙∧Σ^-out X Y m) ◃⊙∘
⊙Susp-flip (⊙Susp (X ∧ ⊙Susp^ m Y)) ◃⊙∘
⊙Susp-fmap (Σ∧-out X (⊙Susp^ m Y)) ◃⊙∘
⊙∧Σ-out (⊙Susp (de⊙ X)) (⊙Susp^ m Y) ◃⊙idf
=⊙∘⟨ 0 & 2 & =⊙∘-in {gs = ⊙Susp-flip (⊙Susp (Susp^ m (X ∧ Y))) ◃⊙∘
⊙Susp^-fmap 2 (⊙∧Σ^-out X Y m) ◃⊙idf} $
! (⊙Susp-flip-natural (⊙Susp-fmap (∧Σ^-out X Y m))) ⟩
⊙Susp-flip (⊙Susp (Susp^ m (X ∧ Y))) ◃⊙∘
⊙Susp^-fmap 2 (⊙∧Σ^-out X Y m) ◃⊙∘
⊙Susp-fmap (Σ∧-out X (⊙Susp^ m Y)) ◃⊙∘
⊙∧Σ-out (⊙Susp (de⊙ X)) (⊙Susp^ m Y) ◃⊙idf
=⊙∘⟨ 1 & 2 & ⊙Susp-fmap-seq-=⊙∘ (de⊙-seq-=⊙∘ (⊙∧Σ-Σ^∧-out X Y m)) ⟩
⊙Susp-flip (⊙Susp (Susp^ m (X ∧ Y))) ◃⊙∘
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm m 1))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip m (odd m))) ◃⊙∘
⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘
⊙Susp-fmap (∧Σ^-out (⊙Susp (de⊙ X)) Y m) ◃⊙∘
⊙∧Σ-out (⊙Susp (de⊙ X)) (⊙Susp^ m Y) ◃⊙idf
=⊙∘⟨ 0 & 2 & =⊙∘-in {gs = ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm m 1))) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙idf} $
⊙Susp-flip-natural (⊙coe (⊙Susp^-comm m 1)) ⟩
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm m 1))) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip m (odd m))) ◃⊙∘
⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘
⊙Susp-fmap (∧Σ^-out (⊙Susp (de⊙ X)) Y m) ◃⊙∘
⊙∧Σ-out (⊙Susp (de⊙ X)) (⊙Susp^ m Y) ◃⊙idf
=⊙∘⟨ 4 & 2 & ⊙contract ⟩
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm m 1))) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip m (odd m))) ◃⊙∘
⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf
=⊙∘₁⟨ 0 & 1 & ! (⊙transport-⊙Susp (ap de⊙ (⊙Susp^-comm m 1))) ∙
ap (⊙transport ⊙Susp) (de⊙-⊙Susp^-comm m 1) ∙
⊙transport-⊙coe ⊙Susp (Susp^-comm m 1) ∙
ap ⊙coe (! (⊙Susp^-comm-S-1 m {X ⊙∧ Y})) ⟩
⊙coe (⊙Susp^-comm (S m) 1) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip m (odd m))) ◃⊙∘
⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf
=⊙∘₁⟨ 2 & 1 & ap ⊙Susp-fmap (de⊙-⊙maybe-Susp^-flip m (odd m)) ⟩
⊙coe (⊙Susp^-comm (S m) 1) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘
⊙Susp-fmap (maybe-Susp^-flip m (odd m)) ◃⊙∘
⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf
=⊙∘₁⟨ 2 & 1 & ⊙Susp-fmap-maybe-Susp^-flip m (odd m) (ap odd) ⟩
⊙coe (⊙Susp^-comm (S m) 1) ◃⊙∘
⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘
⊙maybe-Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) (odd m) ◃⊙∘
⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf
=⊙∘⟨ 1 & 2 & ⊙maybe-Susp-flip-flip _ true (odd m) ⟩
⊙coe (⊙Susp^-comm (S m) 1) ◃⊙∘
⊙maybe-Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) (odd (S m)) ◃⊙∘
⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf ∎⊙∘
module _ {i j} (X : Ptd i) (Y : Ptd j) where
⊙∧Σ^-Σ^∧-out : ∀ (m n : ℕ)
→ ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf
=⊙∘
⊙coe (⊙Susp^-comm n m) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘
⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf
⊙∧Σ^-Σ^∧-out O n =
⊙∧Σ^-out X Y n ◃⊙∘
⊙idf _ ◃⊙idf
=⊙∘⟨ 1 & 1 & ⊙expand ⊙idf-seq ⟩
⊙∧Σ^-out X Y n ◃⊙idf
=⊙∘⟨ 0 & 0 & !⊙∘ (⊙Susp^-fmap-idf n (X ⊙∧ Y)) ⟩
⊙Susp^-fmap n (⊙idf (X ⊙∧ Y)) ◃⊙∘
⊙∧Σ^-out X Y n ◃⊙idf
=⊙∘₁⟨ 0 & 0 & ! (⊙maybe-Susp^-flip-false n) ⟩
⊙maybe-Susp^-flip n false ◃⊙∘
⊙Susp^-fmap n (⊙idf (X ⊙∧ Y)) ◃⊙∘
⊙∧Σ^-out X Y n ◃⊙idf
=⊙∘₁⟨ 0 & 0 & ap ⊙coe (! (⊙Susp^-comm-0-r n _)) ⟩
⊙coe (⊙Susp^-comm n O) ◃⊙∘
⊙maybe-Susp^-flip n false ◃⊙∘
⊙Susp^-fmap n (⊙idf (X ⊙∧ Y)) ◃⊙∘
⊙∧Σ^-out X Y n ◃⊙idf ∎⊙∘
⊙∧Σ^-Σ^∧-out (S m) n =
⊙Susp^-fmap (S m) (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) (S m) ◃⊙idf
=⊙∘⟨ 1 & 1 & ⊙expand (⊙Susp-fmap (Σ^∧-out X (⊙Susp^ n Y) m) ◃⊙∘
⊙Σ∧-out (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf) ⟩
⊙Susp^-fmap (S m) (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Susp-fmap (Σ^∧-out X (⊙Susp^ n Y) m) ◃⊙∘
⊙Σ∧-out (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf
=⊙∘⟨ 0 & 2 & ⊙Susp-fmap-seq-=⊙∘ (de⊙-seq-=⊙∘ (⊙∧Σ^-Σ^∧-out m n)) ⟩
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘
⊙Susp-fmap (Susp^-fmap n (Σ^∧-out X Y m)) ◃⊙∘
⊙Susp-fmap (∧Σ^-out (⊙Susp^ m X) Y n) ◃⊙∘
⊙Σ∧-out (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf
=⊙∘⟨ 3 & 2 & ⊙∧Σ-Σ^∧-out (⊙Susp^ m X) Y n ⟩
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘
⊙Susp-fmap (Susp^-fmap n (Σ^∧-out X Y m)) ◃⊙∘
⊙Susp^-swap n 1 ◃⊙∘
⊙maybe-Susp^-flip n (odd n) ◃⊙∘
⊙Susp^-fmap n (⊙Σ∧-out (⊙Susp^ m X) Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf
=⊙∘⟨ 2 & 2 & !⊙∘ $ ⊙Susp^-swap-natural n 1 (⊙Σ^∧-out X Y m) ⟩
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘
⊙Susp^-swap n 1 ◃⊙∘
⊙Susp^-fmap n (⊙Susp-fmap (Σ^∧-out X Y m)) ◃⊙∘
⊙maybe-Susp^-flip n (odd n) ◃⊙∘
⊙Susp^-fmap n (⊙Σ∧-out (⊙Susp^ m X) Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf
=⊙∘⟨ 3 & 2 & ⊙maybe-Susp^-flip-natural-=⊙∘ (⊙Susp-fmap (Σ^∧-out X Y m)) n (odd n) ⟩
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘
⊙Susp^-swap n 1 ◃⊙∘
⊙maybe-Susp^-flip n (odd n) ◃⊙∘
⊙Susp^-fmap n (⊙Susp-fmap (Σ^∧-out X Y m)) ◃⊙∘
⊙Susp^-fmap n (⊙Σ∧-out (⊙Susp^ m X) Y) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf
=⊙∘₁⟨ 4 & 2 & ! $ ⊙Susp^-fmap-∘ n (⊙Susp-fmap (Σ^∧-out X Y m)) (⊙Σ∧-out (⊙Susp^ m X) Y) ⟩
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘
⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘
⊙Susp^-swap n 1 ◃⊙∘
⊙maybe-Susp^-flip n (odd n) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf
=⊙∘⟨ 1 & 2 & ⊙maybe-Susp^-flip-⊙Susp^-comm _ n 1 (and (odd m) (odd n)) ⟩
⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘
⊙coe (⊙Susp^-comm n 1) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙maybe-Susp^-flip n (odd n) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf
=⊙∘₁⟨ 0 & 1 & ! (⊙transport-⊙Susp (ap de⊙ (⊙Susp^-comm n m))) ∙
⊙transport-⊙coe ⊙Susp (ap de⊙ (⊙Susp^-comm n m)) ∙
ap (⊙coe ∘ ap ⊙Susp) (de⊙-⊙Susp^-comm n m) ⟩
⊙coe (ap ⊙Susp (Susp^-comm n m)) ◃⊙∘
⊙coe (⊙Susp^-comm n 1) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙maybe-Susp^-flip n (odd n) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf
=⊙∘₁⟨ 0 & 2 & ! (=⊙∘-out (⊙coe-∙ (⊙Susp^-comm n 1) (ap ⊙Susp (Susp^-comm n m)))) ∙
ap ⊙coe (! (=ₛ-out (⊙Susp^-comm-S-r n m))) ⟩
⊙coe (⊙Susp^-comm n (S m)) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙maybe-Susp^-flip n (odd n) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf
=⊙∘⟨ 1 & 2 & ⊙maybe-Susp^-flip-flip n (and (odd m) (odd n)) (odd n) ⟩
⊙coe (⊙Susp^-comm n (S m)) ◃⊙∘
⊙maybe-Susp^-flip n (xor (and (odd m) (odd n)) (odd n)) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf
=⊙∘₁⟨ 1 & 1 & ap (⊙maybe-Susp^-flip n) (table (odd m) (odd n)) ⟩
⊙coe (⊙Susp^-comm n (S m)) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd (S m)) (odd n)) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘
⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf ∎⊙∘
where
table : ∀ (b c : Bool) → xor (and b c) c == and (negate b) c
table true true = idp
table true false = idp
table false true = idp
table false false = idp
⊙∧Σ^-Σ^∧-out' : ∀ (m n : ℕ)
→ ⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘
⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf
=⊙∘
⊙coe (⊙Susp^-comm m n) ◃⊙∘
⊙maybe-Susp^-flip m (and (odd m) (odd n)) ◃⊙∘
⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf
⊙∧Σ^-Σ^∧-out' m n =
⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘
⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf
=⊙∘₁⟨ 0 & 0 & ! (⊙maybe-Susp^-flip-false n) ∙
ap (⊙maybe-Susp^-flip n) (! (xor-diag (and (odd m) (odd n)))) ⟩
⊙maybe-Susp^-flip n (xor (and (odd m) (odd n)) (and (odd m) (odd n))) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘
⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf
=⊙∘⟨ 0 & 1 & !⊙∘ $ ⊙maybe-Susp^-flip-flip n (and (odd m) (odd n)) (and (odd m) (odd n)) ⟩
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘
⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf
=⊙∘⟨ 1 & 0 & =⊙∘-in {gs = ⊙coe (! (⊙Susp^-comm n m)) ◃⊙∘
⊙coe (⊙Susp^-comm n m) ◃⊙idf} $
ap ⊙coe (! (!-inv-r (⊙Susp^-comm n m))) ∙
=⊙∘-out (⊙coe-∙ (⊙Susp^-comm n m) (! (⊙Susp^-comm n m))) ⟩
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙coe (! (⊙Susp^-comm n m)) ◃⊙∘
⊙coe (⊙Susp^-comm n m) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘
⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf
=⊙∘⟨ 2 & 4 & !⊙∘ $ ⊙∧Σ^-Σ^∧-out m n ⟩
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙coe (! (⊙Susp^-comm n m)) ◃⊙∘
⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf
=⊙∘₁⟨ 1 & 1 & ap ⊙coe (⊙Susp^-comm-! n m) ⟩
⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘
⊙coe (⊙Susp^-comm m n) ◃⊙∘
⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf
=⊙∘⟨ 0 & 2 & !⊙∘ $
⊙maybe-Susp^-flip-comm m n (and (odd m) (odd n))
(ap (λ k → and (odd k) (odd n)))
(λ p → ap (and (odd m) ∘ odd) p ∙ and-false-r (odd m)) ⟩
⊙coe (⊙Susp^-comm m n) ◃⊙∘
⊙maybe-Susp^-flip m (and (odd m) (odd n)) ◃⊙∘
⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf ∎⊙∘
⊙Σ^∧Σ^-out-seq : ∀ (m n : ℕ) → (⊙Susp^ m X ⊙∧ ⊙Susp^ n Y) ⊙–→ ⊙Susp^ (m + n) (X ⊙∧ Y)
⊙Σ^∧Σ^-out-seq m n =
⊙coe (⊙Susp^-+ m n {X ⊙∧ Y}) ◃⊙∘
⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf
⊙Σ^∧Σ^-out : ∀ (m n : ℕ) → ⊙Susp^ m X ⊙∧ ⊙Susp^ n Y ⊙→ ⊙Susp^ (m + n) (X ⊙∧ Y)
⊙Σ^∧Σ^-out m n = ⊙compose (⊙Σ^∧Σ^-out-seq m n)
swap-⊙Σ^∧-out : ∀ (m : ℕ)
→ ⊙Susp^-fmap m (⊙∧-swap X Y) ◃⊙∘
⊙Σ^∧-out X Y m ◃⊙idf
=⊙∘
⊙∧Σ^-out Y X m ◃⊙∘
⊙∧-swap (⊙Susp^ m X) Y ◃⊙idf
swap-⊙Σ^∧-out O = =⊙∘-in $ ! $ ⊙λ= $ ⊙∘-unit-l (⊙∧-swap X Y)
swap-⊙Σ^∧-out (S m) =
⊙Susp^-fmap (S m) (⊙∧-swap X Y) ◃⊙∘
⊙Σ^∧-out X Y (S m) ◃⊙idf
=⊙∘⟨ 1 & 1 & ⊙expand (⊙Susp-fmap (Σ^∧-out X Y m) ◃⊙∘
⊙Σ∧-out (⊙Susp^ m X) Y ◃⊙idf) ⟩
⊙Susp^-fmap (S m) (⊙∧-swap X Y) ◃⊙∘
⊙Susp-fmap (Σ^∧-out X Y m) ◃⊙∘
⊙Σ∧-out (⊙Susp^ m X) Y ◃⊙idf
=⊙∘⟨ 0 & 2 &
⊙Susp-fmap-seq-=⊙∘ (de⊙-seq-=⊙∘ (swap-⊙Σ^∧-out m)) ⟩
⊙Susp-fmap (∧Σ^-out Y X m) ◃⊙∘
⊙Susp-fmap (∧-swap (⊙Susp^ m X) Y) ◃⊙∘
⊙Σ∧-out (⊙Susp^ m X) Y ◃⊙idf
=⊙∘⟨ 1 & 2 & ⊙swap-Σ∧-out (⊙Susp^ m X) Y ⟩
⊙Susp-fmap (∧Σ^-out Y X m) ◃⊙∘
⊙∧Σ-out Y (⊙Susp^ m X) ◃⊙∘
⊙∧-swap (⊙Susp (de⊙ (⊙Susp^ m X))) Y ◃⊙idf
=⊙∘⟨ 0 & 2 & ⊙contract ⟩
⊙∧Σ^-out Y X (S m) ◃⊙∘
⊙∧-swap (⊙Susp^ (S m) X) Y ◃⊙idf ∎⊙∘
swap-⊙∧Σ^-out : ∀ (n : ℕ)
→ ⊙Susp^-fmap n (⊙∧-swap X Y) ◃⊙∘
⊙∧Σ^-out X Y n ◃⊙idf
=⊙∘
⊙Σ^∧-out Y X n ◃⊙∘
⊙∧-swap X (⊙Susp^ n Y) ◃⊙idf
swap-⊙∧Σ^-out O = =⊙∘-in $ ! $ ⊙λ= $ ⊙∘-unit-l (⊙∧-swap X Y)
swap-⊙∧Σ^-out (S n) =
⊙Susp^-fmap (S n) (⊙∧-swap X Y) ◃⊙∘
⊙∧Σ^-out X Y (S n) ◃⊙idf
=⊙∘⟨ 1 & 1 & ⊙expand (⊙Susp-fmap (∧Σ^-out X Y n) ◃⊙∘
⊙∧Σ-out X (⊙Susp^ n Y) ◃⊙idf) ⟩
⊙Susp^-fmap (S n) (⊙∧-swap X Y) ◃⊙∘
⊙Susp-fmap (∧Σ^-out X Y n) ◃⊙∘
⊙∧Σ-out X (⊙Susp^ n Y) ◃⊙idf
=⊙∘⟨ 0 & 2 &
⊙Susp-fmap-seq-=⊙∘ (de⊙-seq-=⊙∘ (swap-⊙∧Σ^-out n))⟩
⊙Susp-fmap (fst (⊙Σ^∧-out Y X n)) ◃⊙∘
⊙Susp-fmap (fst (⊙∧-swap X (⊙Susp^ n Y))) ◃⊙∘
⊙∧Σ-out X (⊙Susp^ n Y) ◃⊙idf
=⊙∘⟨ 1 & 2 & ⊙swap-∧Σ-out X (⊙Susp^ n Y) ⟩
⊙Susp-fmap (fst (⊙Σ^∧-out Y X n)) ◃⊙∘
⊙Σ∧-out (⊙Susp^ n Y) X ◃⊙∘
⊙∧-swap X (⊙Susp (de⊙ (⊙Susp^ n Y))) ◃⊙idf
=⊙∘⟨ 0 & 2 & ⊙contract ⟩
⊙Σ^∧-out Y X (S n) ◃⊙∘
⊙∧-swap X (⊙Susp^ (S n) Y) ◃⊙idf ∎⊙∘
⊙Σ^∧Σ^-out-swap : ∀ {i} {j} (X : Ptd i) (Y : Ptd j) (m n : ℕ)
→ ⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘
⊙Susp^-fmap (m + n) (⊙∧-swap X Y) ◃⊙∘
⊙Σ^∧Σ^-out X Y m n ◃⊙idf
=⊙∘
⊙maybe-Susp^-flip (n + m) (and (odd n) (odd m)) ◃⊙∘
⊙Σ^∧Σ^-out Y X n m ◃⊙∘
⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf
⊙Σ^∧Σ^-out-swap X Y m n =
⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘
⊙Susp^-fmap (m + n) (⊙∧-swap X Y) ◃⊙∘
⊙Σ^∧Σ^-out X Y m n ◃⊙idf
=⊙∘⟨ 2 & 1 & ⊙expand (⊙Σ^∧Σ^-out-seq X Y m n) ⟩
⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘
⊙Susp^-fmap (m + n) (⊙∧-swap X Y) ◃⊙∘
⊙coe (⊙Susp^-+ m n) ◃⊙∘
⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf
=⊙∘⟨ 1 & 2 & =⊙∘-in {gs = ⊙coe (⊙Susp^-+ m n) ◃⊙∘
⊙Susp^-fmap m (⊙Susp^-fmap n (⊙∧-swap X Y)) ◃⊙idf} $
! $ ⊙Susp^-+-natural m n (⊙∧-swap X Y) ⟩
⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘
⊙coe (⊙Susp^-+ m n) ◃⊙∘
⊙Susp^-fmap m (⊙Susp^-fmap n (⊙∧-swap X Y)) ◃⊙∘
⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf
=⊙∘⟨ 2 & 2 & ⊙Susp^-fmap-seq-=⊙∘ m $ swap-⊙∧Σ^-out X Y n ⟩
⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘
⊙coe (⊙Susp^-+ m n) ◃⊙∘
⊙Susp^-fmap m (⊙Σ^∧-out Y X n) ◃⊙∘
⊙Susp^-fmap m (⊙∧-swap X (⊙Susp^ n Y)) ◃⊙∘
⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf
=⊙∘⟨ 3 & 2 & swap-⊙Σ^∧-out X (⊙Susp^ n Y) m ⟩
⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘
⊙coe (⊙Susp^-+ m n) ◃⊙∘
⊙Susp^-fmap m (⊙Σ^∧-out Y X n) ◃⊙∘
⊙∧Σ^-out (⊙Susp^ n Y) X m ◃⊙∘
⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf
=⊙∘⟨ 2 & 2 & ⊙∧Σ^-Σ^∧-out' Y X n m ⟩
⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘
⊙coe (⊙Susp^-+ m n) ◃⊙∘
⊙coe (⊙Susp^-comm n m) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd n) (odd m)) ◃⊙∘
⊙Susp^-fmap n (⊙∧Σ^-out Y X m) ◃⊙∘
⊙Σ^∧-out Y (⊙Susp^ m X) n ◃⊙∘
⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf
=⊙∘₁⟨ 0 & 1 & ⊙transport-⊙coe (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ⟩
⊙coe (ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n)) ◃⊙∘
⊙coe (⊙Susp^-+ m n) ◃⊙∘
⊙coe (⊙Susp^-comm n m) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd n) (odd m)) ◃⊙∘
⊙Susp^-fmap n (⊙∧Σ^-out Y X m) ◃⊙∘
⊙Σ^∧-out Y (⊙Susp^ m X) n ◃⊙∘
⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf
=⊙∘⟨ 0 & 3 & ⊙coe-seq-=ₛ p ⟩
⊙coe (⊙Susp^-+ n m) ◃⊙∘
⊙maybe-Susp^-flip n (and (odd n) (odd m)) ◃⊙∘
⊙Susp^-fmap n (⊙∧Σ^-out Y X m) ◃⊙∘
⊙Σ^∧-out Y (⊙Susp^ m X) n ◃⊙∘
⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf
=⊙∘⟨ 0 & 2 & ⊙maybe-Susp^-flip-+ n m (and (odd n) (odd m))
(ap (λ k → and (odd k) (odd m))) ⟩
⊙maybe-Susp^-flip (n + m) (and (odd n) (odd m)) ◃⊙∘
⊙coe (⊙Susp^-+ n m) ◃⊙∘
⊙Susp^-fmap n (⊙∧Σ^-out Y X m) ◃⊙∘
⊙Σ^∧-out Y (⊙Susp^ m X) n ◃⊙∘
⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf
=⊙∘⟨ 1 & 3 & ⊙contract ⟩
⊙maybe-Susp^-flip (n + m) (and (odd n) (odd m)) ◃⊙∘
⊙Σ^∧Σ^-out Y X n m ◃⊙∘
⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf ∎⊙∘
where
p : ⊙Susp^-comm n m ◃∙
⊙Susp^-+ m n {Y ⊙∧ X} ◃∙
ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃∎
=ₛ
⊙Susp^-+ n m {Y ⊙∧ X} ◃∎
p =
⊙Susp^-comm n m ◃∙
⊙Susp^-+ m n {Y ⊙∧ X} ◃∙
ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃∎
=ₛ⟨ 0 & 1 & expand (⊙Susp^-comm-seq n m) ⟩
⊙Susp^-+ n m ◃∙
ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm n m) ◃∙
! (⊙Susp^-+ m n) ◃∙
⊙Susp^-+ m n ◃∙
ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃∎
=ₛ⟨ 2 & 2 & seq-!-inv-l (⊙Susp^-+ m n ◃∎) ⟩
⊙Susp^-+ n m ◃∙
ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm n m) ◃∙
ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃∎
=ₛ⟨ 1 & 2 & ap-seq-=ₛ (λ k → ⊙Susp^ k (Y ⊙∧ X)) $
=ₛ-in {s = +-comm n m ◃∙ +-comm m n ◃∎} {t = []} $
set-path ℕ-level _ _ ⟩
⊙Susp^-+ n m ◃∎ ∎ₛ
|
{
"alphanum_fraction": 0.4183320257,
"avg_line_length": 41.3492366412,
"ext": "agda",
"hexsha": "9f9d1019b2f2addfbb10c92c6bda0c94a4b41cad",
"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": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/IterSuspSmash.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"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": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/IterSuspSmash.agda",
"max_line_length": 95,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/IterSuspSmash.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": 14346,
"size": 21667
}
|
open import Everything
{-
open import Oscar.Prelude
open import Oscar.Class.HasEquivalence
open import Oscar.Class.Symmetrical
open import Oscar.Data.Fin
open import Oscar.Data.Term
open import Oscar.Data.Substitunction
open import Oscar.Data.Proposequality
open import Oscar.Data.Surjcollation
open import Oscar.Data.Surjextenscollation
import Oscar.Class.HasEquivalence.ExtensionṖroperty
import Oscar.Class.HasEquivalence.Ṗroperty
import Oscar.Class.Symmetrical.ExtensionalUnifies
import Oscar.Class.Symmetrical.Unifies
import Oscar.Property.Setoid.Proposequality -- FIXME see fact1⋆ below; comment this out to observe confusing error messages
import Oscar.Property.Functor.SubstitunctionExtensionTerm
import Oscar.Class.Surjection.⋆
-}
module Test.Surjcollation {𝔭} (𝔓 : Ø 𝔭) where
open Term 𝔓
open Substitunction 𝔓
module 𝓢 = Surjcollation Substitunction Proposequality
module 𝓢̇ = Surjextenscollation Substitunction Proposextensequality
fact1⋆ : ∀ {𝓃} (𝓈 𝓉 : Term 𝓃) → 𝓈 𝓢.⟹ 𝓉 ≈ 𝓉 𝓢.⟹ 𝓈
fact1⋆ 𝓈 𝓉 = symmetrical 𝓈 𝓉
-- fact1⋆ 𝓈 𝓉 = symmetrical ⦃ r = Oscar.Class.Symmetrical.Unifies.𝓢ymmetricalUnifies₀ ⦃ ! ⦄ ⦃ ! ⦄ ⦃ Oscar.Property.Setoid.Proposequality.𝓢ymmetryProposequality ⦄ ⦄ 𝓈 𝓉 -- FIXME I wish Agda would tell us that this is how the instances were resolved
fact1⋆s : ∀ {N 𝓃} (𝓈 𝓉 : Terms N 𝓃) → 𝓈 𝓢.⟹ 𝓉 ≈ 𝓉 𝓢.⟹ 𝓈
fact1⋆s 𝓈 𝓉 = symmetrical 𝓈 𝓉
fact1 : ∀ {𝓃} (𝓈 𝓉 : Term 𝓃) → 𝓈 𝓢̇.⟹ 𝓉 ≈ 𝓉 𝓢̇.⟹ 𝓈
fact1 𝓈 𝓉 = symmetrical 𝓈 𝓉
|
{
"alphanum_fraction": 0.7573479152,
"avg_line_length": 39.5405405405,
"ext": "agda",
"hexsha": "87202123de403913315fe9a5d637a737bc9d424f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Test/Surjcollation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Test/Surjcollation.agda",
"max_line_length": 249,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Test/Surjcollation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 585,
"size": 1463
}
|
-- Andreas, 2014-06-11, issue reported by Ulf
-- {-# OPTIONS -v tc.check.internal:100 -v tc.conv.elim:40 #-}
postulate
Nat : Set
zero : Nat
module Projection where
record _×_ (A B : Set) : Set where
field fst : A
snd : B
open _×_
postulate
T : (Nat × Nat → Nat) → Set
foo : T fst → Nat
works : T fst → Nat
works t with foo t
works t | z = zero
module ProjectionLike where
data _×_ (A B : Set) : Set where
_,_ : A → B → A × B
fst : {A B : Set} → A × B → A
fst (x , y) = x
postulate
T : (Nat × Nat → Nat) → Set
foo : T fst → Nat
-- Error WAS::
-- {A B : Set} → A × B → A != Nat × Nat → Nat because one is an
-- implicit function type and the other is an explicit function type
-- when checking that the type (t : T fst) → Nat → Nat of the
-- generated with function is well-formed
test : T fst → Nat
test t with foo t
test t | z = zero
-- Problem WAS:
-- It looks like CheckInternal doesn't handle projection-like functions
-- correctly. It works for actual projections (if you make _×_ a record)
-- and non-projection-like functions (if you make fst a postulate).
-- Should work without error.
|
{
"alphanum_fraction": 0.6047098402,
"avg_line_length": 23.3137254902,
"ext": "agda",
"hexsha": "bcbee5d30ed6587007dc71fc61693626d0188967",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1187.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1187.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1187.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": 374,
"size": 1189
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Type(s) used (only) when calling out to Haskell via the FFI
------------------------------------------------------------------------
module Foreign.Haskell where
-- A unit type.
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () () #-}
|
{
"alphanum_fraction": 0.3955431755,
"avg_line_length": 23.9333333333,
"ext": "agda",
"hexsha": "e0c462a0a569316080eeb8cf9b396b37842bd585",
"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/Foreign/Haskell.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/Foreign/Haskell.agda",
"max_line_length": 72,
"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/Foreign/Haskell.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": 61,
"size": 359
}
|
open import Prelude
module MJ.Classtable (c : ℕ) where
open import MJ.Classtable.Core c public
|
{
"alphanum_fraction": 0.7731958763,
"avg_line_length": 16.1666666667,
"ext": "agda",
"hexsha": "b5d1024969bb9fbc06e46cd1bef288b863c2ce89",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Classtable.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Classtable.agda",
"max_line_length": 39,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Classtable.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 26,
"size": 97
}
|
module TermIsomorphism where
open import OscarPrelude
open import Term
open import VariableName
open import FunctionName
open import Arity
open import Vector
open import Data.Fin using (fromℕ ; toℕ ) renaming (raise to raiseFin)
open import Unify using (i ; leaf ; _fork_) renaming (Term to STerm ; AList to SAList)
open import UnifyProof2 using (mgu-c)
raiseSTerm : ∀ {m} n {o} → o ≡ n + m → STerm m → STerm o
raiseSTerm n refl (i x) = i (raiseFin n x)
raiseSTerm n o≡n+m leaf = leaf
raiseSTerm n refl (τ₁ fork τ₂) = raiseSTerm n refl τ₁ fork raiseSTerm n refl τ₂
max' : Nat → Nat → Nat
max' x y = if x >? y then x else y
aux-lemma-m<n : ∀ {m n : Nat} → IsTrue (lessNat m n) → n ≡ n - m + m
aux-lemma-m<n {zero} {zero} _ = refl
aux-lemma-m<n {zero} {suc _} _ = auto
aux-lemma-m<n {suc _} {zero} ()
aux-lemma-m<n {suc m} {suc n} m<n = by (aux-lemma-m<n {m} {n} m<n)
aux-lemma-m≮n,n≮m : ∀ {m n : Nat} → ¬ IsTrue (lessNat m n) → ¬ IsTrue (lessNat n m) → m ≡ n
aux-lemma-m≮n,n≮m {zero} {zero} m≮n n≮m = refl
aux-lemma-m≮n,n≮m {zero} {suc n} m≮n n≮m = ⊥-elim (m≮n true)
aux-lemma-m≮n,n≮m {suc m} {zero} m≮n n≮m = ⊥-elim (n≮m true)
aux-lemma-m≮n,n≮m {suc m} {suc n} m≮n n≮m = by (aux-lemma-m≮n,n≮m {m} {n} m≮n n≮m)
max-lemma-left : ∀ {m n : Nat} → max m n ≡ max m n - m + m
max-lemma-left {m} {n} with decBool (lessNat n m)
max-lemma-left {m} {n} | yes n<m = auto
max-lemma-left {m} {n} | no n≮m with decBool (lessNat m n)
max-lemma-left {m} {n} | no n≮m | (yes m<n) = aux-lemma-m<n m<n
max-lemma-left {m} {n} | no n≮m | (no m≮n)rewrite aux-lemma-m≮n,n≮m {m} {n} m≮n n≮m = auto
max-lemma-right : ∀ {m n : Nat} → max m n ≡ max m n - n + n
max-lemma-right {m} {n} with decBool (lessNat n m)
max-lemma-right {m} {n} | yes n<m = aux-lemma-m<n n<m
max-lemma-right {m} {n} | no n≮m with decBool (lessNat m n)
max-lemma-right {m} {n} | no n≮m | (yes m<n) = auto
max-lemma-right {m} {n} | no n≮m | (no m≮n)rewrite aux-lemma-m≮n,n≮m {m} {n} m≮n n≮m = auto
_⊕_ : ∃ STerm → ∃ STerm → ∃ STerm
_⊕_ (n₁ , τ₁) (n₂ , τ₂) = max n₁ n₂ , raiseSTerm (max n₁ n₂ - n₁) (max-lemma-left {n₁}) τ₁ fork raiseSTerm (max n₁ n₂ - n₂) (max-lemma-right {n₁}) τ₂
functionNameToSTerm : FunctionName → STerm 0
functionNameToSTerm ⟨ zero ⟩ = leaf
functionNameToSTerm ⟨ suc 𝑓 ⟩ = leaf fork functionNameToSTerm ⟨ 𝑓 ⟩
mutual
termToSTerm : Term → ∃ STerm
termToSTerm (variable x) = _ , i (fromℕ $ name x)
termToSTerm (function 𝑓 τs) = (_ , functionNameToSTerm 𝑓) ⊕ termsToSTerm τs
termsToSTerm : Terms → ∃ STerm
termsToSTerm ⟨ ⟨ [] ⟩ ⟩ = 0 , leaf
termsToSTerm ⟨ ⟨ τ ∷ τs ⟩ ⟩ = termToSTerm τ ⊕ termsToSTerm ⟨ ⟨ τs ⟩ ⟩
sTermToFunctionName : ∀ {n} → STerm n → Maybe FunctionName
sTermToFunctionName (i x) = nothing
sTermToFunctionName leaf = just ⟨ 0 ⟩
sTermToFunctionName (i x fork t₁) = nothing
sTermToFunctionName (leaf fork t₁) = sTermToFunctionName t₁ >>= (λ { ⟨ n ⟩ → just ⟨ suc n ⟩})
sTermToFunctionName ((t fork t₁) fork t₂) = nothing
mutual
sTermToTerm : ∀ {n} → STerm n → Maybe Term
sTermToTerm {n} (i x) = just $ variable ⟨ toℕ x ⟩
sTermToTerm {n} leaf = just $ function ⟨ 0 ⟩ ⟨ ⟨ [] ⟩ ⟩
sTermToTerm {n} (t₁ fork t₂) = sTermToFunctionName t₁ >>= λ 𝑓 → sTermToTerms t₂ >>= λ τs → just $ function 𝑓 τs
sTermToTerms : ∀ {n} → STerm n → Maybe Terms
sTermToTerms (i x) = nothing
sTermToTerms leaf = just ⟨ ⟨ [] ⟩ ⟩
sTermToTerms (x fork x₁) = sTermToTerm x >>= λ τ → sTermToTerms x₁ >>= λ τs → just ⟨ ⟨ τ ∷ vector (terms τs) ⟩ ⟩
term-round-trip : ∀ τ → sTermToTerm (snd $ termToSTerm τ) ≡ just τ
term-round-trip (variable ⟨ name₁ ⟩) = {!!}
term-round-trip (function x x₁) = {!!}
open import Relation.Binary.HeterogeneousEquality.Core as H
open import Data.Product
open import Data.Fin
open import Data.Sum
open import Data.Maybe.Base
open import Data.Empty
sTerm-round-trip : ∀ {n} → (t : STerm n) → (τ : Term) → just τ ≡ sTermToTerm t → snd (termToSTerm τ) H.≅ t
sTerm-round-trip (i x) (variable .(⟨ toℕ x ⟩)) refl = {!!}
sTerm-round-trip leaf (variable x) ()
sTerm-round-trip (i x fork t₁) (variable x₁) ()
sTerm-round-trip (t₁ fork t₂) (variable x) x₁ with sTermToFunctionName t₁ | sTermToTerms t₂
sTerm-round-trip (t₁ fork t₂) (variable x) () | nothing | ttt
sTerm-round-trip (t₁ fork t₂) (variable x₁) () | just x | nothing
sTerm-round-trip (t₁ fork t₂) (variable x₂) () | just x | (just x₁)
sTerm-round-trip t (function x x₁) x₂ = {!mgu-c!}
module Parameterized (Source : Nat → Set)
(Target : Nat → Set)
(let Sub : ∀ m n → Set
Sub m n = Source m → Target n)
where
_≐'_ : {m n : Nat} -> Sub m n → Sub m n -> Set
f ≐' g = ∀ x -> f x ≡ g x
Property' : (m : Nat) → Set₁
Property' m = OscarPrelude.Σ (∀ {n} → (Sub m n) → Set) λ P → ∀ {m f g} -> f ≐' g -> P {m} f -> P g
{-
data AList : Set where
anil : AList
_asnoc_/_ : (σ : AList) (t' : Term) (x : VariableName) → AList
aListToSAList : AList → ∃
-}
|
{
"alphanum_fraction": 0.6189503778,
"avg_line_length": 38.5590551181,
"ext": "agda",
"hexsha": "2c2427904bb130ea7520ce852cd63404f5cae8b7",
"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/TermIsomorphism.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/TermIsomorphism.agda",
"max_line_length": 149,
"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/TermIsomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2016,
"size": 4897
}
|
module _ where
open import Agda.Builtin.Unit
open import Imports.Issue5583 tt
_ : X
_ = it
|
{
"alphanum_fraction": 0.7446808511,
"avg_line_length": 10.4444444444,
"ext": "agda",
"hexsha": "f8a2c99e298f2026a6b1f2af8a441a55779e9d10",
"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": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue5583.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"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": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue5583.agda",
"max_line_length": 32,
"max_stars_count": 1989,
"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/Issue5583.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": 30,
"size": 94
}
|
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc)
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
+-assoc′ : ∀ m n p → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = refl
+-assoc′ (suc m) n p rewrite +-assoc′ m n p = refl
{-
Goal: ℕ
————————————————————————————————————————————————————————————
n : ℕ
-}
{-
Goal: ℕ
————————————————————————————————————————————————————————————
n : ℕ
m : ℕ
-}
|
{
"alphanum_fraction": 0.4234404537,
"avg_line_length": 18.8928571429,
"ext": "agda",
"hexsha": "28a1b3a369439aa0c3fb7cc657eedecb3e1fc4fe",
"lang": "Agda",
"max_forks_count": 304,
"max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z",
"max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "manikdv/plfa.github.io",
"max_forks_repo_path": "extra/extra/Addition.agda",
"max_issues_count": 323,
"max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "manikdv/plfa.github.io",
"max_issues_repo_path": "extra/extra/Addition.agda",
"max_line_length": 60,
"max_stars_count": 1003,
"max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "manikdv/plfa.github.io",
"max_stars_repo_path": "extra/extra/Addition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z",
"num_tokens": 187,
"size": 529
}
|
{-# OPTIONS --guardedness #-}
open import Agda.Builtin.Coinduction
open import Agda.Builtin.IO
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.String
open import Agda.Builtin.Unit
private
variable
A : Set
postulate
putStrLn : String → IO ⊤
{-# FOREIGN GHC import qualified Data.Text.IO #-}
{-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn #-}
record Stream₁ (A : Set) : Set where
coinductive
constructor _∷_
field
head : A
tail : Stream₁ A
open Stream₁
repeat₁ : A → Stream₁ A
repeat₁ x .head = x
repeat₁ x .tail = repeat₁ x
take₁ : Nat → Stream₁ A → List A
take₁ zero xs = []
take₁ (suc n) xs = xs .head ∷ take₁ n (xs .tail)
data List′ (A : Set) : Set where
[] : List′ A
_∷_ : A → List′ A → List′ A
to-list : List′ A → List A
to-list [] = []
to-list (x ∷ xs) = x ∷ to-list xs
data Stream₂ (A : Set) : Set where
_∷_ : A → ∞ (Stream₂ A) → Stream₂ A
repeat₂ : A → Stream₂ A
repeat₂ x = x ∷ ♯ repeat₂ x
take₂ : Nat → Stream₂ A → List′ A
take₂ zero _ = []
take₂ (suc n) (x ∷ xs) = x ∷ take₂ n (♭ xs)
_++_ : List A → List′ A → List A
[] ++ ys = to-list ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
main : IO ⊤
main =
putStrLn
(primStringFromList
(take₁ 3 (repeat₁ '(') ++ take₂ 3 (repeat₂ ')')))
|
{
"alphanum_fraction": 0.6043110085,
"avg_line_length": 20.296875,
"ext": "agda",
"hexsha": "6be3919d9a9f4428ec598a0ae551dbfe812acbc6",
"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/Compiler/simple/Strict.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/Compiler/simple/Strict.agda",
"max_line_length": 56,
"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/Compiler/simple/Strict.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": 456,
"size": 1299
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The Maybe type
------------------------------------------------------------------------
module Data.Maybe where
open import Level
------------------------------------------------------------------------
-- The type
open import Data.Maybe.Core public
------------------------------------------------------------------------
-- Some operations
open import Data.Bool using (Bool; true; false; not)
open import Data.Unit using (⊤)
open import Function
open import Relation.Nullary
boolToMaybe : Bool → Maybe ⊤
boolToMaybe true = just _
boolToMaybe false = nothing
is-just : ∀ {a} {A : Set a} → Maybe A → Bool
is-just (just _) = true
is-just nothing = false
is-nothing : ∀ {a} {A : Set a} → Maybe A → Bool
is-nothing = not ∘ is-just
decToMaybe : ∀ {a} {A : Set a} → Dec A → Maybe A
decToMaybe (yes x) = just x
decToMaybe (no _) = nothing
-- A dependent eliminator.
maybe : ∀ {a b} {A : Set a} {B : Maybe A → Set b} →
((x : A) → B (just x)) → B nothing → (x : Maybe A) → B x
maybe j n (just x) = j x
maybe j n nothing = n
-- A non-dependent eliminator.
maybe′ : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → B → Maybe A → B
maybe′ = maybe
-- A safe variant of "fromJust". If the value is nothing, then the
-- return type is the unit type.
From-just : ∀ {a} (A : Set a) → Maybe A → Set a
From-just A (just _) = A
From-just A nothing = Lift ⊤
from-just : ∀ {a} {A : Set a} (x : Maybe A) → From-just A x
from-just (just x) = x
from-just nothing = _
------------------------------------------------------------------------
-- Maybe monad
open import Category.Functor
open import Category.Monad
open import Category.Monad.Identity
map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → Maybe A → Maybe B
map f = maybe (just ∘ f) nothing
functor : ∀ {f} → RawFunctor (Maybe {a = f})
functor = record
{ _<$>_ = map
}
monadT : ∀ {f} {M : Set f → Set f} →
RawMonad M → RawMonad (λ A → M (Maybe A))
monadT M = record
{ return = M.return ∘ just
; _>>=_ = λ m f → M._>>=_ m (maybe f (M.return nothing))
}
where module M = RawMonad M
monad : ∀ {f} → RawMonad (Maybe {a = f})
monad = monadT IdentityMonad
monadZero : ∀ {f} → RawMonadZero (Maybe {a = f})
monadZero = record
{ monad = monad
; ∅ = nothing
}
monadPlus : ∀ {f} → RawMonadPlus (Maybe {a = f})
monadPlus {f} = record
{ monadZero = monadZero
; _∣_ = _∣_
}
where
_∣_ : {A : Set f} → Maybe A → Maybe A → Maybe A
nothing ∣ y = y
just x ∣ y = just x
------------------------------------------------------------------------
-- Equality
open import Relation.Binary as B
data Eq {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) : Rel (Maybe A) (a ⊔ ℓ) where
just : ∀ {x y} (x≈y : x ≈ y) → Eq _≈_ (just x) (just y)
nothing : Eq _≈_ nothing nothing
drop-just : ∀ {a ℓ} {A : Set a} {_≈_ : Rel A ℓ} {x y : A} →
just x ⟨ Eq _≈_ ⟩ just y → x ≈ y
drop-just (just x≈y) = x≈y
setoid : ∀ {ℓ₁ ℓ₂} → Setoid ℓ₁ ℓ₂ → Setoid _ _
setoid S = record
{ Carrier = Maybe S.Carrier
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
module S = Setoid S
_≈_ = Eq S._≈_
refl : ∀ {x} → x ≈ x
refl {just x} = just S.refl
refl {nothing} = nothing
sym : ∀ {x y} → x ≈ y → y ≈ x
sym (just x≈y) = just (S.sym x≈y)
sym nothing = nothing
trans : ∀ {x y z} → x ≈ y → y ≈ z → x ≈ z
trans (just x≈y) (just y≈z) = just (S.trans x≈y y≈z)
trans nothing nothing = nothing
decSetoid : ∀ {ℓ₁ ℓ₂} → DecSetoid ℓ₁ ℓ₂ → DecSetoid _ _
decSetoid D = record
{ isDecEquivalence = record
{ isEquivalence = Setoid.isEquivalence (setoid (DecSetoid.setoid D))
; _≟_ = _≟_
}
}
where
_≟_ : B.Decidable (Eq (DecSetoid._≈_ D))
just x ≟ just y with DecSetoid._≟_ D x y
just x ≟ just y | yes x≈y = yes (just x≈y)
just x ≟ just y | no x≉y = no (x≉y ∘ drop-just)
just x ≟ nothing = no λ()
nothing ≟ just y = no λ()
nothing ≟ nothing = yes nothing
------------------------------------------------------------------------
-- Any and All
open Data.Bool using (T)
open import Data.Empty using (⊥)
import Relation.Nullary.Decidable as Dec
open import Relation.Unary as U
data Any {a p} {A : Set a} (P : A → Set p) : Maybe A → Set (a ⊔ p) where
just : ∀ {x} (px : P x) → Any P (just x)
data All {a p} {A : Set a} (P : A → Set p) : Maybe A → Set (a ⊔ p) where
just : ∀ {x} (px : P x) → All P (just x)
nothing : All P nothing
Is-just : ∀ {a} {A : Set a} → Maybe A → Set a
Is-just = Any (λ _ → ⊤)
Is-nothing : ∀ {a} {A : Set a} → Maybe A → Set a
Is-nothing = All (λ _ → ⊥)
to-witness : ∀ {p} {P : Set p} {m : Maybe P} → Is-just m → P
to-witness (just {x = p} _) = p
to-witness-T : ∀ {p} {P : Set p} (m : Maybe P) → T (is-just m) → P
to-witness-T (just p) _ = p
to-witness-T nothing ()
anyDec : ∀ {a p} {A : Set a} {P : A → Set p} →
U.Decidable P → U.Decidable (Any P)
anyDec p nothing = no λ()
anyDec p (just x) = Dec.map′ just (λ { (Any.just px) → px }) (p x)
allDec : ∀ {a p} {A : Set a} {P : A → Set p} →
U.Decidable P → U.Decidable (All P)
allDec p nothing = yes nothing
allDec p (just x) = Dec.map′ just (λ { (All.just px) → px }) (p x)
|
{
"alphanum_fraction": 0.510626293,
"avg_line_length": 27.1275510204,
"ext": "agda",
"hexsha": "39dc1583ee45c3c8dc6b98c05e095e2cb0fec708",
"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/Data/Maybe.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/Data/Maybe.agda",
"max_line_length": 72,
"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/Data/Maybe.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": 1890,
"size": 5317
}
|
module Issue2762-2 where
open import Agda.Builtin.List
open import Agda.Builtin.Equality
pattern [_] x = x ∷ []
singleton : {A : Set} → A → List A
singleton x = x ∷ []
{-# DISPLAY _∷_ x [] = singleton x #-}
_ : ∀ {A} (x : A) → singleton x ≡ [ x ]
_ = {!!}
|
{
"alphanum_fraction": 0.5785440613,
"avg_line_length": 17.4,
"ext": "agda",
"hexsha": "b23243a43ec37aa1f97853dc2e1475d9c451addc",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue2762-2.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2762-2.agda",
"max_line_length": 39,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2762-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": 89,
"size": 261
}
|
import Lvl
module Type.Functions.Proofs {ℓₗ : Lvl.Level} where
open import Functional
import Function.Domains
import Lang.Irrelevance
import Logic.Predicate
import Logic.Predicate.Theorems
import Relator.Equals
import Relator.Equals.Proofs
open import Type
open import Type.Properties.Empty
import Type.Functions
import Type.Singleton.Proofs
open import Type.Properties.Singleton
open import Type.Properties.Singleton.Proofs
module _ {ℓₒ₁}{ℓₒ₂} {X : Type{ℓₒ₁}} {Y : Type{ℓₒ₂}} {f : X → Y} where
open Type.Functions {ℓₗ}{ℓₒ₁}{ℓₒ₂} {X}{Y}
bijective-to-injective : ⦃ bij : Bijective(f) ⦄ → Injective(f)
Injective.proof (bijective-to-injective ⦃ intro proof ⦄) {y} =
unit-is-prop {ℓₒ₁} ⦃ proof{y} ⦄
bijective-to-surjective : ⦃ bij : Bijective(f) ⦄ → Surjective(f)
Surjective.proof (bijective-to-surjective ⦃ intro proof ⦄) {y} =
unit-is-pos {ℓₗ Lvl.⊔ ℓₒ₁} ⦃ proof{y} ⦄
injective-surjective-to-bijective : ⦃ inj : Injective(f) ⦄ → ⦃ surj : Surjective(f) ⦄ → Bijective(f)
Bijective.proof(injective-surjective-to-bijective ⦃ intro inj ⦄ ⦃ intro surj ⦄) {y} =
pos-prop-is-unit {ℓₗ Lvl.⊔ ℓₒ₁} ⦃ surj{y} ⦄ ⦃ inj{y} ⦄
module _ {ℓₒ₁}{ℓₒ₂} {X : Type{ℓₒ₁}} {Y : Type{ℓₒ₂}} {f : X → Y} where
open Function.Domains
open Type.Functions {ℓₗ}{ℓₒ₁}{ℓₒ₂} {X}{Y}
open Relator.Equals
private
_≡₁_ = _≡_ {ℓₗ Lvl.⊔ ℓₒ₁}
Injective-apply : ⦃ _ : Injective(f) ⦄ → ∀{x y} → (f(x) ≡₁ f(y)) → (x ≡₁ y)
Injective-apply ⦃ Injective.intro proof ⦄ {x}{y} (fxfy) with proof{f(y)}
... | MereProposition.intro uniqueness with uniqueness{Unapply.intro x ⦃ fxfy ⦄} {Unapply.intro y ⦃ [≡]-intro ⦄}
... | [≡]-intro = [≡]-intro
module _ {ℓₒ : Lvl.Level} {X : Type{ℓₒ}} where
open Type.Functions {ℓₗ Lvl.⊔ ℓₒ}{ℓₒ}{ℓₒ} {X}{X}
open Type.Singleton.Proofs {ℓₗ}{ℓₒ} {X}
instance
id-is-bijective : Bijective(id)
id-is-bijective = intro Singleton-is-unit
|
{
"alphanum_fraction": 0.6541471049,
"avg_line_length": 35.5,
"ext": "agda",
"hexsha": "ee0e6d745b950408153b57bab16ecd0703c5a9cb",
"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": "old/Type/Functions/Proofs.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": "old/Type/Functions/Proofs.agda",
"max_line_length": 114,
"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": "old/Type/Functions/Proofs.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": 804,
"size": 1917
}
|
open import Agda.Builtin.Nat
record C (A : Set) : Set where
module M (X : Set) where
module Ci = C {{...}}
module CiNat = M.Ci Nat -- error: The module M.Ci is not parameterized...
|
{
"alphanum_fraction": 0.6417112299,
"avg_line_length": 18.7,
"ext": "agda",
"hexsha": "e07ec0dfb271ba3625dcbef18357e4edfff445b1",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1983.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1983.agda",
"max_line_length": 73,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1983.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 59,
"size": 187
}
|
module map-is-fold-Tree where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; trans; cong)
open Eq.≡-Reasoning
open import map-Tree using (Tree; leaf; node; map-Tree)
open import fold-Tree using (fold-Tree)
postulate
-- 外延性の公理
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
-- 外延性の公理を利用した証明のための補題
lemma : ∀ {A B C D : Set} → (f : A → C) → (g : B → D) → (tree : Tree A B)
→ map-Tree f g tree ≡ fold-Tree (λ a → leaf (f a)) (λ treeˡ b treeʳ → node treeˡ (g b) treeʳ) tree
lemma f g (leaf a) =
begin
map-Tree f g (leaf a)
≡⟨⟩
leaf (f a)
≡⟨⟩
fold-Tree (λ a → leaf (f a)) (λ treeˡ b treeʳ → node treeˡ (g b) treeʳ) (leaf a)
∎
lemma f g (node treeˡ b treeʳ) =
begin
map-Tree f g (node treeˡ b treeʳ)
≡⟨⟩
node (map-Tree f g treeˡ) (g b) (map-Tree f g treeʳ)
≡⟨ cong (λ treeʳ′ → node (map-Tree f g treeˡ) (g b) treeʳ′) (lemma f g treeʳ) ⟩
node (map-Tree f g treeˡ)
(g b)
(fold-Tree (λ a → leaf (f a)) (λ treeˡ b treeʳ → node treeˡ (g b) treeʳ) treeʳ)
≡⟨ cong (λ treeˡ′ → node treeˡ′
(g b)
(fold-Tree (λ a → leaf (f a)) (λ treeˡ b treeʳ → node treeˡ (g b) treeʳ) treeʳ))
(lemma f g treeˡ) ⟩
node (fold-Tree (λ a → leaf (f a)) (λ treeˡ b treeʳ → node treeˡ (g b) treeʳ) treeˡ)
(g b)
(fold-Tree (λ a → leaf (f a)) (λ treeˡ b treeʳ → node treeˡ (g b) treeʳ) treeʳ)
≡⟨⟩
fold-Tree (λ a → leaf (f a)) (λ treeˡ b treeʳ → node treeˡ (g b) treeʳ) (node treeˡ b treeʳ)
∎
-- Treeのmapが畳み込みで表現できることの証明
map-is-fold-Tree : ∀ {A B C D : Set} → (f : A → C) → (g : B → D)
→ map-Tree f g ≡ fold-Tree (λ a → leaf (f a)) (λ treeˡ b treeʳ → node treeˡ (g b) treeʳ)
map-is-fold-Tree f g = extensionality (lemma f g)
|
{
"alphanum_fraction": 0.5450620615,
"avg_line_length": 35.6346153846,
"ext": "agda",
"hexsha": "15647b4007f56f78d297c7005e3e04e581cbabdc",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/lists/map-is-fold-Tree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/lists/map-is-fold-Tree.agda",
"max_line_length": 107,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/lists/map-is-fold-Tree.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 819,
"size": 1853
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Type(s) used (only) when calling out to Haskell via the FFI
------------------------------------------------------------------------
{-# OPTIONS --without-K #-}
module Foreign.Haskell where
open import Level
------------------------------------------------------------------------
-- Pairs
open import Foreign.Haskell.Pair public
renaming
( toForeign to toForeignPair
; fromForeign to fromForeignPair
)
------------------------------------------------------------------------
-- Sums
open import Foreign.Haskell.Either public
renaming
( toForeign to toForeignEither
; fromForeign to fromForeignEither
)
------------------------------------------------------------------------
-- Maybe
open import Foreign.Haskell.Maybe public
renaming
( toForeign to toForeignMaybe
; fromForeign to fromForeignMaybe
)
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
open import Data.Unit using (⊤; tt)
-- Version 1.1
Unit = ⊤
{-# WARNING_ON_USAGE Unit
"Warning: Unit was deprecated in v1.1.
Please use ⊤ from Data.Unit instead."
#-}
unit = tt
{-# WARNING_ON_USAGE unit
"Warning: unit was deprecated in v1.1.
Please use tt from Data.Unit instead."
#-}
|
{
"alphanum_fraction": 0.4755525787,
"avg_line_length": 24.8833333333,
"ext": "agda",
"hexsha": "6243ca498b84a0ac5aaac53b31595994acc7df6f",
"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/Foreign/Haskell.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/Foreign/Haskell.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Foreign/Haskell.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": 276,
"size": 1493
}
|
open import Nat
open import Prelude
open import List
open import contexts
module core where
-- types
data typ : Set where
b : typ
⦇·⦈ : typ
_==>_ : typ → typ → typ
_⊗_ : typ → typ → typ
-- arrow type constructors bind very tightly
infixr 25 _==>_
infixr 25 _⊗_
-- we use natural numbers as names throughout the development. here we
-- provide some aliases to that the definitions below are more readable
-- about what's being named, even though the underlying implementations
-- are the same and there's no abstraction protecting you from breaking
-- invariants.
-- written `x` in math
varname : Set
varname = Nat
-- written `u` in math
holename : Set
holename = Nat
-- written `a` in math
livelitname : Set
livelitname = Nat
-- "external expressions", or the middle layer of expressions. presented
-- first because of the dependence structure below.
data eexp : Set where
c : eexp
_·:_ : eexp → typ → eexp
X : varname → eexp
·λ : varname → eexp → eexp
·λ_[_]_ : varname → typ → eexp → eexp
⦇⦈[_] : holename → eexp
⦇⌜_⌟⦈[_] : eexp → holename → eexp
_∘_ : eexp → eexp → eexp
⟨_,_⟩ : eexp → eexp → eexp
fst : eexp → eexp
snd : eexp → eexp
-- the type of type contexts, i.e. Γs in the judegments below
tctx : Set
tctx = typ ctx
mutual
-- identity substitution, substitition environments
data env : Set where
Id : (Γ : tctx) → env
Subst : (d : iexp) → (y : varname) → env → env
-- internal expressions, the bottom most layer of expresions. these are
-- what the elaboration phase targets and the expressions on which
-- evaluation is given.
data iexp : Set where
c : iexp
X : varname → iexp
·λ_[_]_ : varname → typ → iexp → iexp
⦇⦈⟨_⟩ : (holename × env) → iexp
⦇⌜_⌟⦈⟨_⟩ : iexp → (holename × env) → iexp
_∘_ : iexp → iexp → iexp
_⟨_⇒_⟩ : iexp → typ → typ → iexp
_⟨_⇒⦇⦈⇏_⟩ : iexp → typ → typ → iexp
⟨_,_⟩ : iexp → iexp → iexp
fst : iexp → iexp
snd : iexp → iexp
-- convenient notation for chaining together two agreeable casts
_⟨_⇒_⇒_⟩ : iexp → typ → typ → typ → iexp
d ⟨ τ1 ⇒ τ2 ⇒ τ3 ⟩ = d ⟨ τ1 ⇒ τ2 ⟩ ⟨ τ2 ⇒ τ3 ⟩
record livelitdef : Set where
field
expand : iexp
model-type : typ
expansion-type : typ
-- unexpanded expressions, the outermost layer of expressions: a langauge
-- exactly like eexp, but also with livelits
mutual
data uexp : Set where
c : uexp
_·:_ : uexp → typ → uexp
X : varname → uexp
·λ : varname → uexp → uexp
·λ_[_]_ : varname → typ → uexp → uexp
⦇⦈[_] : holename → uexp
⦇⌜_⌟⦈[_] : uexp → holename → uexp
_∘_ : uexp → uexp → uexp
⟨_,_⟩ : uexp → uexp → uexp
fst : uexp → uexp
snd : uexp → uexp
-- new forms below
$_⟨_⁏_⟩[_] : (a : livelitname) → (d : iexp) → (ϕᵢ : List splice) → (u : holename) → uexp
splice : Set
splice = typ × uexp
-- type consistency
data _~_ : (t1 t2 : typ) → Set where
TCRefl : {τ : typ} → τ ~ τ
TCHole1 : {τ : typ} → τ ~ ⦇·⦈
TCHole2 : {τ : typ} → ⦇·⦈ ~ τ
TCArr : {τ1 τ2 τ1' τ2' : typ} →
τ1 ~ τ1' →
τ2 ~ τ2' →
τ1 ==> τ2 ~ τ1' ==> τ2'
TCProd : {τ1 τ2 τ1' τ2' : typ} →
τ1 ~ τ1' →
τ2 ~ τ2' →
(τ1 ⊗ τ2) ~ (τ1' ⊗ τ2')
-- type inconsistency
data _~̸_ : (τ1 τ2 : typ) → Set where
ICBaseArr1 : {τ1 τ2 : typ} → b ~̸ τ1 ==> τ2
ICBaseArr2 : {τ1 τ2 : typ} → τ1 ==> τ2 ~̸ b
ICArr1 : {τ1 τ2 τ3 τ4 : typ} →
τ1 ~̸ τ3 →
τ1 ==> τ2 ~̸ τ3 ==> τ4
ICArr2 : {τ1 τ2 τ3 τ4 : typ} →
τ2 ~̸ τ4 →
τ1 ==> τ2 ~̸ τ3 ==> τ4
ICBaseProd1 : {τ1 τ2 : typ} → b ~̸ τ1 ⊗ τ2
ICBaseProd2 : {τ1 τ2 : typ} → τ1 ⊗ τ2 ~̸ b
ICProdArr1 : {τ1 τ2 τ3 τ4 : typ} →
τ1 ==> τ2 ~̸ τ3 ⊗ τ4
ICProdArr2 : {τ1 τ2 τ3 τ4 : typ} →
τ1 ⊗ τ2 ~̸ τ3 ==> τ4
ICProd1 : {τ1 τ2 τ3 τ4 : typ} →
τ1 ~̸ τ3 →
τ1 ⊗ τ2 ~̸ τ3 ⊗ τ4
ICProd2 : {τ1 τ2 τ3 τ4 : typ} →
τ2 ~̸ τ4 →
τ1 ⊗ τ2 ~̸ τ3 ⊗ τ4
--- matching for arrows
data _▸arr_ : typ → typ → Set where
MAHole : ⦇·⦈ ▸arr ⦇·⦈ ==> ⦇·⦈
MAArr : {τ1 τ2 : typ} → τ1 ==> τ2 ▸arr τ1 ==> τ2
-- matching for products
data _▸prod_ : typ → typ → Set where
MPHole : ⦇·⦈ ▸prod ⦇·⦈ ⊗ ⦇·⦈
MPProd : {τ1 τ2 : typ} → τ1 ⊗ τ2 ▸prod τ1 ⊗ τ2
-- the type of hole contexts, i.e. Δs in the judgements
hctx : Set
hctx = (typ ctx × typ) ctx
-- notation for a triple to match the CMTT syntax
_::_[_] : holename → typ → tctx → (holename × (tctx × typ))
u :: τ [ Γ ] = u , (Γ , τ)
-- the hole name u does not appear in the term e
data hole-name-new : (e : eexp) (u : holename) → Set where
HNConst : ∀{u} → hole-name-new c u
HNAsc : ∀{e τ u} →
hole-name-new e u →
hole-name-new (e ·: τ) u
HNVar : ∀{x u} → hole-name-new (X x) u
HNLam1 : ∀{x e u} →
hole-name-new e u →
hole-name-new (·λ x e) u
HNLam2 : ∀{x e u τ} →
hole-name-new e u →
hole-name-new (·λ x [ τ ] e) u
HNHole : ∀{u u'} →
u' ≠ u →
hole-name-new (⦇⦈[ u' ]) u
HNNEHole : ∀{u u' e} →
u' ≠ u →
hole-name-new e u →
hole-name-new (⦇⌜ e ⌟⦈[ u' ]) u
HNAp : ∀{ u e1 e2 } →
hole-name-new e1 u →
hole-name-new e2 u →
hole-name-new (e1 ∘ e2) u
HNFst : ∀{ u e } →
hole-name-new e u →
hole-name-new (fst e) u
HNSnd : ∀{ u e } →
hole-name-new e u →
hole-name-new (snd e) u
HNPair : ∀{ u e1 e2 } →
hole-name-new e1 u →
hole-name-new e2 u →
hole-name-new ⟨ e1 , e2 ⟩ u
-- two terms that do not share any hole names
data holes-disjoint : (e1 : eexp) → (e2 : eexp) → Set where
HDConst : ∀{e} → holes-disjoint c e
HDAsc : ∀{e1 e2 τ} → holes-disjoint e1 e2 → holes-disjoint (e1 ·: τ) e2
HDVar : ∀{x e} → holes-disjoint (X x) e
HDLam1 : ∀{x e1 e2} → holes-disjoint e1 e2 → holes-disjoint (·λ x e1) e2
HDLam2 : ∀{x e1 e2 τ} → holes-disjoint e1 e2 → holes-disjoint (·λ x [ τ ] e1) e2
HDHole : ∀{u e2} → hole-name-new e2 u → holes-disjoint (⦇⦈[ u ]) e2
HDNEHole : ∀{u e1 e2} → hole-name-new e2 u → holes-disjoint e1 e2 → holes-disjoint (⦇⌜ e1 ⌟⦈[ u ]) e2
HDAp : ∀{e1 e2 e3} → holes-disjoint e1 e3 → holes-disjoint e2 e3 → holes-disjoint (e1 ∘ e2) e3
HDFst : ∀{e1 e2} → holes-disjoint e1 e2 → holes-disjoint (fst e1) e2
HDSnd : ∀{e1 e2} → holes-disjoint e1 e2 → holes-disjoint (snd e1) e2
HDPair : ∀{e1 e2 e3} → holes-disjoint e1 e3 → holes-disjoint e2 e3 → holes-disjoint ⟨ e1 , e2 ⟩ e3
-- bidirectional type checking judgements for eexp
mutual
-- synthesis
data _⊢_=>_ : (Γ : tctx) (e : eexp) (τ : typ) → Set where
SConst : {Γ : tctx} → Γ ⊢ c => b
SAsc : {Γ : tctx} {e : eexp} {τ : typ} →
Γ ⊢ e <= τ →
Γ ⊢ (e ·: τ) => τ
SVar : {Γ : tctx} {τ : typ} {x : varname} →
(x , τ) ∈ Γ →
Γ ⊢ X x => τ
SAp : {Γ : tctx} {e1 e2 : eexp} {τ τ1 τ2 : typ} →
holes-disjoint e1 e2 →
Γ ⊢ e1 => τ1 →
τ1 ▸arr τ2 ==> τ →
Γ ⊢ e2 <= τ2 →
Γ ⊢ (e1 ∘ e2) => τ
SEHole : {Γ : tctx} {u : holename} → Γ ⊢ ⦇⦈[ u ] => ⦇·⦈
SNEHole : {Γ : tctx} {e : eexp} {τ : typ} {u : holename} →
hole-name-new e u →
Γ ⊢ e => τ →
Γ ⊢ ⦇⌜ e ⌟⦈[ u ] => ⦇·⦈
SLam : {Γ : tctx} {e : eexp} {τ1 τ2 : typ} {x : varname} →
x # Γ →
(Γ ,, (x , τ1)) ⊢ e => τ2 →
Γ ⊢ ·λ x [ τ1 ] e => τ1 ==> τ2
SFst : ∀{ e τ τ1 τ2 Γ} →
Γ ⊢ e => τ →
τ ▸prod τ1 ⊗ τ2 →
Γ ⊢ fst e => τ1
SSnd : ∀{ e τ τ1 τ2 Γ} →
Γ ⊢ e => τ →
τ ▸prod τ1 ⊗ τ2 →
Γ ⊢ snd e => τ2
SPair : ∀{ e1 e2 τ1 τ2 Γ} →
holes-disjoint e1 e2 →
Γ ⊢ e1 => τ1 →
Γ ⊢ e2 => τ2 →
Γ ⊢ ⟨ e1 , e2 ⟩ => τ1 ⊗ τ2
-- analysis
data _⊢_<=_ : (Γ : tctx) (e : eexp) (τ : typ) → Set where
ASubsume : {Γ : tctx} {e : eexp} {τ τ' : typ} →
Γ ⊢ e => τ' →
τ ~ τ' →
Γ ⊢ e <= τ
ALam : {Γ : tctx} {e : eexp} {τ τ1 τ2 : typ} {x : varname} →
x # Γ →
τ ▸arr τ1 ==> τ2 →
(Γ ,, (x , τ1)) ⊢ e <= τ2 →
Γ ⊢ (·λ x e) <= τ
-- those types without holes
data _tcomplete : typ → Set where
TCBase : b tcomplete
TCArr : ∀{τ1 τ2} → τ1 tcomplete → τ2 tcomplete → (τ1 ==> τ2) tcomplete
TCProd : ∀{τ1 τ2} → τ1 tcomplete → τ2 tcomplete → (τ1 ⊗ τ2) tcomplete
-- those external expressions without holes
data _ecomplete : eexp → Set where
ECConst : c ecomplete
ECAsc : ∀{τ e} → τ tcomplete → e ecomplete → (e ·: τ) ecomplete
ECVar : ∀{x} → (X x) ecomplete
ECLam1 : ∀{x e} → e ecomplete → (·λ x e) ecomplete
ECLam2 : ∀{x e τ} → e ecomplete → τ tcomplete → (·λ x [ τ ] e) ecomplete
ECAp : ∀{e1 e2} → e1 ecomplete → e2 ecomplete → (e1 ∘ e2) ecomplete
ECFst : ∀{e} → e ecomplete → (fst e) ecomplete
ECSnd : ∀{e} → e ecomplete → (snd e) ecomplete
ECPair : ∀{e1 e2} → e1 ecomplete → e2 ecomplete → ⟨ e1 , e2 ⟩ ecomplete
-- those internal expressions without holes
data _dcomplete : iexp → Set where
DCVar : ∀{x} → (X x) dcomplete
DCConst : c dcomplete
DCLam : ∀{x τ d} → d dcomplete → τ tcomplete → (·λ x [ τ ] d) dcomplete
DCAp : ∀{d1 d2} → d1 dcomplete → d2 dcomplete → (d1 ∘ d2) dcomplete
DCCast : ∀{d τ1 τ2} → d dcomplete → τ1 tcomplete → τ2 tcomplete → (d ⟨ τ1 ⇒ τ2 ⟩) dcomplete
DCFst : ∀{d} → d dcomplete → (fst d) dcomplete
DCSnd : ∀{d} → d dcomplete → (snd d) dcomplete
DCPair : ∀{d1 d2} → d1 dcomplete → d2 dcomplete → ⟨ d1 , d2 ⟩ dcomplete
-- contexts that only produce complete types
_gcomplete : tctx → Set
Γ gcomplete = (x : varname) (τ : typ) → (x , τ) ∈ Γ → τ tcomplete
-- those internal expressions where every cast is the identity cast and
-- there are no failed casts
data cast-id : iexp → Set where
CIConst : cast-id c
CIVar : ∀{x} → cast-id (X x)
CILam : ∀{x τ d} → cast-id d → cast-id (·λ x [ τ ] d)
CIHole : ∀{u} → cast-id (⦇⦈⟨ u ⟩)
CINEHole : ∀{d u} → cast-id d → cast-id (⦇⌜ d ⌟⦈⟨ u ⟩)
CIAp : ∀{d1 d2} → cast-id d1 → cast-id d2 → cast-id (d1 ∘ d2)
CICast : ∀{d τ} → cast-id d → cast-id (d ⟨ τ ⇒ τ ⟩)
CIFst : ∀{d} → cast-id d → cast-id (fst d)
CISnd : ∀{d} → cast-id d → cast-id (snd d)
CIPair : ∀{d1 d2} → cast-id d1 → cast-id d2 → cast-id ⟨ d1 , d2 ⟩
-- expansion
mutual
-- synthesis
data _⊢_⇒_~>_⊣_ : (Γ : tctx) (e : eexp) (τ : typ) (d : iexp) (Δ : hctx) → Set where
ESConst : ∀{Γ} → Γ ⊢ c ⇒ b ~> c ⊣ ∅
ESVar : ∀{Γ x τ} → (x , τ) ∈ Γ →
Γ ⊢ X x ⇒ τ ~> X x ⊣ ∅
ESLam : ∀{Γ x τ1 τ2 e d Δ } →
(x # Γ) →
(Γ ,, (x , τ1)) ⊢ e ⇒ τ2 ~> d ⊣ Δ →
Γ ⊢ ·λ x [ τ1 ] e ⇒ (τ1 ==> τ2) ~> ·λ x [ τ1 ] d ⊣ Δ
ESAp : ∀{Γ e1 τ τ1 τ1' τ2 τ2' d1 Δ1 e2 d2 Δ2 } →
holes-disjoint e1 e2 →
Δ1 ## Δ2 →
Γ ⊢ e1 => τ1 →
τ1 ▸arr τ2 ==> τ →
Γ ⊢ e1 ⇐ (τ2 ==> τ) ~> d1 :: τ1' ⊣ Δ1 →
Γ ⊢ e2 ⇐ τ2 ~> d2 :: τ2' ⊣ Δ2 →
Γ ⊢ e1 ∘ e2 ⇒ τ ~> (d1 ⟨ τ1' ⇒ τ2 ==> τ ⟩) ∘ (d2 ⟨ τ2' ⇒ τ2 ⟩) ⊣ (Δ1 ∪ Δ2)
ESEHole : ∀{ Γ u } →
Γ ⊢ ⦇⦈[ u ] ⇒ ⦇·⦈ ~> ⦇⦈⟨ u , Id Γ ⟩ ⊣ ■ (u :: ⦇·⦈ [ Γ ])
ESNEHole : ∀{ Γ e τ d u Δ } →
Δ ## (■ (u , Γ , ⦇·⦈)) →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
Γ ⊢ ⦇⌜ e ⌟⦈[ u ] ⇒ ⦇·⦈ ~> ⦇⌜ d ⌟⦈⟨ u , Id Γ ⟩ ⊣ (Δ ,, u :: ⦇·⦈ [ Γ ])
ESAsc : ∀ {Γ e τ d τ' Δ} →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
Γ ⊢ (e ·: τ) ⇒ τ ~> d ⟨ τ' ⇒ τ ⟩ ⊣ Δ
ESFst : ∀{Γ e τ τ' d τ1 τ2 Δ} →
Γ ⊢ e => τ →
τ ▸prod τ1 ⊗ τ2 →
Γ ⊢ e ⇐ τ1 ⊗ τ2 ~> d :: τ' ⊣ Δ →
Γ ⊢ fst e ⇒ τ1 ~> fst (d ⟨ τ' ⇒ τ1 ⊗ τ2 ⟩) ⊣ Δ
ESSnd : ∀{Γ e τ τ' d τ1 τ2 Δ} →
Γ ⊢ e => τ →
τ ▸prod τ1 ⊗ τ2 →
Γ ⊢ e ⇐ τ1 ⊗ τ2 ~> d :: τ' ⊣ Δ →
Γ ⊢ snd e ⇒ τ2 ~> snd (d ⟨ τ' ⇒ τ1 ⊗ τ2 ⟩) ⊣ Δ
ESPair : ∀{Γ e1 τ1 d1 Δ1 e2 τ2 d2 Δ2} →
holes-disjoint e1 e2 →
Δ1 ## Δ2 →
Γ ⊢ e1 ⇒ τ1 ~> d1 ⊣ Δ1 →
Γ ⊢ e2 ⇒ τ2 ~> d2 ⊣ Δ2 →
Γ ⊢ ⟨ e1 , e2 ⟩ ⇒ τ1 ⊗ τ2 ~> ⟨ d1 , d2 ⟩ ⊣ (Δ1 ∪ Δ2)
-- analysis
data _⊢_⇐_~>_::_⊣_ : (Γ : tctx) (e : eexp) (τ : typ) (d : iexp) (τ' : typ) (Δ : hctx) → Set where
EALam : ∀{Γ x τ τ1 τ2 e d τ2' Δ } →
(x # Γ) →
τ ▸arr τ1 ==> τ2 →
(Γ ,, (x , τ1)) ⊢ e ⇐ τ2 ~> d :: τ2' ⊣ Δ →
Γ ⊢ ·λ x e ⇐ τ ~> ·λ x [ τ1 ] d :: τ1 ==> τ2' ⊣ Δ
EASubsume : ∀{e Γ τ' d Δ τ} →
((u : holename) → e ≠ ⦇⦈[ u ]) →
((e' : eexp) (u : holename) → e ≠ ⦇⌜ e' ⌟⦈[ u ]) →
Γ ⊢ e ⇒ τ' ~> d ⊣ Δ →
τ ~ τ' →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ
EAEHole : ∀{ Γ u τ } →
Γ ⊢ ⦇⦈[ u ] ⇐ τ ~> ⦇⦈⟨ u , Id Γ ⟩ :: τ ⊣ ■ (u :: τ [ Γ ])
EANEHole : ∀{ Γ e u τ d τ' Δ } →
Δ ## (■ (u , Γ , τ)) →
Γ ⊢ e ⇒ τ' ~> d ⊣ Δ →
Γ ⊢ ⦇⌜ e ⌟⦈[ u ] ⇐ τ ~> ⦇⌜ d ⌟⦈⟨ u , Id Γ ⟩ :: τ ⊣ (Δ ,, u :: τ [ Γ ])
-- ground types
data _ground : (τ : typ) → Set where
GBase : b ground
GHole : ⦇·⦈ ==> ⦇·⦈ ground
GProd : ⦇·⦈ ⊗ ⦇·⦈ ground
mutual
-- substitution typing
data _,_⊢_:s:_ : hctx → tctx → env → tctx → Set where
STAId : ∀{Γ Γ' Δ} →
((x : varname) (τ : typ) → (x , τ) ∈ Γ' → (x , τ) ∈ Γ) →
Δ , Γ ⊢ Id Γ' :s: Γ'
STASubst : ∀{Γ Δ σ y Γ' d τ } →
Δ , Γ ,, (y , τ) ⊢ σ :s: Γ' →
Δ , Γ ⊢ d :: τ →
Δ , Γ ⊢ Subst d y σ :s: Γ'
-- type assignment
data _,_⊢_::_ : (Δ : hctx) (Γ : tctx) (d : iexp) (τ : typ) → Set where
TAConst : ∀{Δ Γ} → Δ , Γ ⊢ c :: b
TAVar : ∀{Δ Γ x τ} → (x , τ) ∈ Γ → Δ , Γ ⊢ X x :: τ
TALam : ∀{ Δ Γ x τ1 d τ2} →
x # Γ →
Δ , (Γ ,, (x , τ1)) ⊢ d :: τ2 →
Δ , Γ ⊢ ·λ x [ τ1 ] d :: (τ1 ==> τ2)
TAAp : ∀{ Δ Γ d1 d2 τ1 τ} →
Δ , Γ ⊢ d1 :: τ1 ==> τ →
Δ , Γ ⊢ d2 :: τ1 →
Δ , Γ ⊢ d1 ∘ d2 :: τ
TAEHole : ∀{ Δ Γ σ u Γ' τ} →
(u , (Γ' , τ)) ∈ Δ →
Δ , Γ ⊢ σ :s: Γ' →
Δ , Γ ⊢ ⦇⦈⟨ u , σ ⟩ :: τ
TANEHole : ∀ { Δ Γ d τ' Γ' u σ τ } →
(u , (Γ' , τ)) ∈ Δ →
Δ , Γ ⊢ d :: τ' →
Δ , Γ ⊢ σ :s: Γ' →
Δ , Γ ⊢ ⦇⌜ d ⌟⦈⟨ u , σ ⟩ :: τ
TACast : ∀{ Δ Γ d τ1 τ2} →
Δ , Γ ⊢ d :: τ1 →
τ1 ~ τ2 →
Δ , Γ ⊢ d ⟨ τ1 ⇒ τ2 ⟩ :: τ2
TAFailedCast : ∀{Δ Γ d τ1 τ2} →
Δ , Γ ⊢ d :: τ1 →
τ1 ground →
τ2 ground →
τ1 ≠ τ2 →
Δ , Γ ⊢ d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩ :: τ2
TAFst : ∀{Δ Γ d τ1 τ2} →
Δ , Γ ⊢ d :: τ1 ⊗ τ2 →
Δ , Γ ⊢ fst d :: τ1
TASnd : ∀{Δ Γ d τ1 τ2} →
Δ , Γ ⊢ d :: τ1 ⊗ τ2 →
Δ , Γ ⊢ snd d :: τ2
TAPair : ∀{Δ Γ d1 d2 τ1 τ2} →
Δ , Γ ⊢ d1 :: τ1 →
Δ , Γ ⊢ d2 :: τ2 →
Δ , Γ ⊢ ⟨ d1 , d2 ⟩ :: τ1 ⊗ τ2
-- substitution
[_/_]_ : iexp → varname → iexp → iexp
[ d / y ] c = c
[ d / y ] X x
with natEQ x y
[ d / y ] X .y | Inl refl = d
[ d / y ] X x | Inr neq = X x
[ d / y ] (·λ x [ x₁ ] d')
with natEQ x y
[ d / y ] (·λ .y [ τ ] d') | Inl refl = ·λ y [ τ ] d'
[ d / y ] (·λ x [ τ ] d') | Inr x₁ = ·λ x [ τ ] ( [ d / y ] d')
[ d / y ] ⦇⦈⟨ u , σ ⟩ = ⦇⦈⟨ u , Subst d y σ ⟩
[ d / y ] ⦇⌜ d' ⌟⦈⟨ u , σ ⟩ = ⦇⌜ [ d / y ] d' ⌟⦈⟨ u , Subst d y σ ⟩
[ d / y ] (d1 ∘ d2) = ([ d / y ] d1) ∘ ([ d / y ] d2)
[ d / y ] (d' ⟨ τ1 ⇒ τ2 ⟩ ) = ([ d / y ] d') ⟨ τ1 ⇒ τ2 ⟩
[ d / y ] (d' ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩ ) = ([ d / y ] d') ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩
[ d / y ] ⟨ d1 , d2 ⟩ = ⟨ [ d / y ] d1 , [ d / y ] d2 ⟩
[ d / y ] (fst d') = fst ([ d / y ] d')
[ d / y ] (snd d') = snd ([ d / y ] d')
-- applying an environment to an expression
apply-env : env → iexp → iexp
apply-env (Id Γ) d = d
apply-env (Subst d y σ) d' = [ d / y ] ( apply-env σ d')
-- values
data _val : (d : iexp) → Set where
VConst : c val
VLam : ∀{x τ d} → (·λ x [ τ ] d) val
VPair : ∀{d1 d2} → d1 val → d2 val → ⟨ d1 , d2 ⟩ val
-- boxed values
data _boxedval : (d : iexp) → Set where
BVVal : ∀{d} → d val → d boxedval
BVPair : ∀{d1 d2} → d1 boxedval → d2 boxedval → ⟨ d1 , d2 ⟩ boxedval
BVArrCast : ∀{ d τ1 τ2 τ3 τ4 } →
τ1 ==> τ2 ≠ τ3 ==> τ4 →
d boxedval →
d ⟨ (τ1 ==> τ2) ⇒ (τ3 ==> τ4) ⟩ boxedval
BVProdCast : ∀{ d τ1 τ2 τ3 τ4 } →
τ1 ⊗ τ2 ≠ τ3 ⊗ τ4 →
d boxedval →
d ⟨ (τ1 ⊗ τ2) ⇒ (τ3 ⊗ τ4) ⟩ boxedval
BVHoleCast : ∀{ τ d } → τ ground → d boxedval → d ⟨ τ ⇒ ⦇·⦈ ⟩ boxedval
mutual
-- indeterminate forms
data _indet : (d : iexp) → Set where
IEHole : ∀{u σ} → ⦇⦈⟨ u , σ ⟩ indet
INEHole : ∀{d u σ} → d final → ⦇⌜ d ⌟⦈⟨ u , σ ⟩ indet
IAp : ∀{d1 d2} → ((τ1 τ2 τ3 τ4 : typ) (d1' : iexp) →
d1 ≠ (d1' ⟨(τ1 ==> τ2) ⇒ (τ3 ==> τ4)⟩)) →
d1 indet →
d2 final →
(d1 ∘ d2) indet
IFst : ∀{d} →
d indet →
(∀{d1 d2} → d ≠ ⟨ d1 , d2 ⟩) →
(∀{d' τ1 τ2 τ3 τ4} → d ≠ (d' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩)) →
(fst d) indet
ISnd : ∀{d} →
d indet →
(∀{d1 d2} → d ≠ ⟨ d1 , d2 ⟩) →
(∀{d' τ1 τ2 τ3 τ4} → d ≠ (d' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩)) →
(snd d) indet
IPair1 : ∀{d1 d2} →
d1 indet →
d2 final →
⟨ d1 , d2 ⟩ indet
IPair2 : ∀{d1 d2} →
d1 final →
d2 indet →
⟨ d1 , d2 ⟩ indet
ICastArr : ∀{d τ1 τ2 τ3 τ4} →
τ1 ==> τ2 ≠ τ3 ==> τ4 →
d indet →
d ⟨ (τ1 ==> τ2) ⇒ (τ3 ==> τ4) ⟩ indet
ICastProd : ∀{d τ1 τ2 τ3 τ4} →
τ1 ⊗ τ2 ≠ τ3 ⊗ τ4 →
d indet →
d ⟨ (τ1 ⊗ τ2) ⇒ (τ3 ⊗ τ4) ⟩ indet
ICastGroundHole : ∀{ τ d } →
τ ground →
d indet →
d ⟨ τ ⇒ ⦇·⦈ ⟩ indet
ICastHoleGround : ∀ { d τ } →
((d' : iexp) (τ' : typ) → d ≠ (d' ⟨ τ' ⇒ ⦇·⦈ ⟩)) →
d indet →
τ ground →
d ⟨ ⦇·⦈ ⇒ τ ⟩ indet
IFailedCast : ∀{ d τ1 τ2 } →
d final →
τ1 ground →
τ2 ground →
τ1 ≠ τ2 →
d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩ indet
-- final expressions
data _final : (d : iexp) → Set where
FBoxedVal : ∀{d} → d boxedval → d final
FIndet : ∀{d} → d indet → d final
-- contextual dynamics
-- evaluation contexts
data ectx : Set where
⊙ : ectx
_∘₁_ : ectx → iexp → ectx
_∘₂_ : iexp → ectx → ectx
⦇⌜_⌟⦈⟨_⟩ : ectx → (holename × env ) → ectx
fst·_ : ectx → ectx
snd·_ : ectx → ectx
⟨_,_⟩₁ : ectx → iexp → ectx
⟨_,_⟩₂ : iexp → ectx → ectx
_⟨_⇒_⟩ : ectx → typ → typ → ectx
_⟨_⇒⦇·⦈⇏_⟩ : ectx → typ → typ → ectx
-- note: this judgement is redundant: in the absence of the premises in
-- the red brackets, all syntactically well formed ectxs are valid. with
-- finality premises, that's not true, and that would propagate through
-- additions to the calculus. so we leave it here for clarity but note
-- that, as written, in any use case its either trival to prove or
-- provides no additional information
--ε is an evaluation context
data _evalctx : (ε : ectx) → Set where
ECDot : ⊙ evalctx
ECAp1 : ∀{d ε} →
ε evalctx →
(ε ∘₁ d) evalctx
ECAp2 : ∀{d ε} →
-- d final → -- red brackets
ε evalctx →
(d ∘₂ ε) evalctx
ECNEHole : ∀{ε u σ} →
ε evalctx →
⦇⌜ ε ⌟⦈⟨ u , σ ⟩ evalctx
ECFst : ∀{ε} →
(fst· ε) evalctx
ECSnd : ∀{ε} →
(snd· ε) evalctx
ECPair1 : ∀{d ε} →
ε evalctx →
⟨ ε , d ⟩₁ evalctx
ECPair2 : ∀{d ε} →
-- d final → -- red brackets
ε evalctx →
⟨ d , ε ⟩₂ evalctx
ECCast : ∀{ ε τ1 τ2} →
ε evalctx →
(ε ⟨ τ1 ⇒ τ2 ⟩) evalctx
ECFailedCast : ∀{ ε τ1 τ2 } →
ε evalctx →
ε ⟨ τ1 ⇒⦇·⦈⇏ τ2 ⟩ evalctx
-- d is the result of filling the hole in ε with d'
data _==_⟦_⟧ : (d : iexp) (ε : ectx) (d' : iexp) → Set where
FHOuter : ∀{d} → d == ⊙ ⟦ d ⟧
FHAp1 : ∀{d1 d1' d2 ε} →
d1 == ε ⟦ d1' ⟧ →
(d1 ∘ d2) == (ε ∘₁ d2) ⟦ d1' ⟧
FHAp2 : ∀{d1 d2 d2' ε} →
-- d1 final → -- red brackets
d2 == ε ⟦ d2' ⟧ →
(d1 ∘ d2) == (d1 ∘₂ ε) ⟦ d2' ⟧
FHNEHole : ∀{ d d' ε u σ} →
d == ε ⟦ d' ⟧ →
⦇⌜ d ⌟⦈⟨ (u , σ ) ⟩ == ⦇⌜ ε ⌟⦈⟨ (u , σ ) ⟩ ⟦ d' ⟧
FHFst : ∀{d d' ε} →
d == ε ⟦ d' ⟧ →
fst d == (fst· ε) ⟦ d' ⟧
FHSnd : ∀{d d' ε} →
d == ε ⟦ d' ⟧ →
snd d == (snd· ε) ⟦ d' ⟧
FHPair1 : ∀{d1 d1' d2 ε} →
d1 == ε ⟦ d1' ⟧ →
⟨ d1 , d2 ⟩ == ⟨ ε , d2 ⟩₁ ⟦ d1' ⟧
FHPair2 : ∀{d1 d2 d2' ε} →
d2 == ε ⟦ d2' ⟧ →
⟨ d1 , d2 ⟩ == ⟨ d1 , ε ⟩₂ ⟦ d2' ⟧
FHCast : ∀{ d d' ε τ1 τ2 } →
d == ε ⟦ d' ⟧ →
d ⟨ τ1 ⇒ τ2 ⟩ == ε ⟨ τ1 ⇒ τ2 ⟩ ⟦ d' ⟧
FHFailedCast : ∀{ d d' ε τ1 τ2} →
d == ε ⟦ d' ⟧ →
(d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩) == (ε ⟨ τ1 ⇒⦇·⦈⇏ τ2 ⟩) ⟦ d' ⟧
-- matched ground types
data _▸gnd_ : typ → typ → Set where
MGArr : ∀{τ1 τ2} →
(τ1 ==> τ2) ≠ (⦇·⦈ ==> ⦇·⦈) →
(τ1 ==> τ2) ▸gnd (⦇·⦈ ==> ⦇·⦈)
MGProd : ∀{τ1 τ2} →
(τ1 ⊗ τ2) ≠ (⦇·⦈ ⊗ ⦇·⦈) →
(τ1 ⊗ τ2) ▸gnd (⦇·⦈ ⊗ ⦇·⦈)
-- instruction transition judgement
data _→>_ : (d d' : iexp) → Set where
ITLam : ∀{ x τ d1 d2 } →
-- d2 final → -- red brackets
((·λ x [ τ ] d1) ∘ d2) →> ([ d2 / x ] d1)
ITFst : ∀{d1 d2} →
-- d1 final → -- red brackets
-- d2 final → -- red brackets
fst ⟨ d1 , d2 ⟩ →> d1
ITSnd : ∀{d1 d2} →
-- d1 final → -- red brackets
-- d2 final → -- red brackets
snd ⟨ d1 , d2 ⟩ →> d2
ITCastID : ∀{d τ } →
-- d final → -- red brackets
(d ⟨ τ ⇒ τ ⟩) →> d
ITCastSucceed : ∀{d τ } →
-- d final → -- red brackets
τ ground →
(d ⟨ τ ⇒ ⦇·⦈ ⇒ τ ⟩) →> d
ITCastFail : ∀{ d τ1 τ2} →
-- d final → -- red brackets
τ1 ground →
τ2 ground →
τ1 ≠ τ2 →
(d ⟨ τ1 ⇒ ⦇·⦈ ⇒ τ2 ⟩) →> (d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩)
ITApCast : ∀{d1 d2 τ1 τ2 τ1' τ2' } →
-- d1 final → -- red brackets
-- d2 final → -- red brackets
((d1 ⟨ (τ1 ==> τ2) ⇒ (τ1' ==> τ2')⟩) ∘ d2) →> ((d1 ∘ (d2 ⟨ τ1' ⇒ τ1 ⟩)) ⟨ τ2 ⇒ τ2' ⟩)
ITFstCast : ∀{d τ1 τ2 τ1' τ2' } →
-- d final → -- red brackets
fst (d ⟨ τ1 ⊗ τ2 ⇒ τ1' ⊗ τ2' ⟩) →> ((fst d) ⟨ τ1 ⇒ τ1' ⟩)
ITSndCast : ∀{d τ1 τ2 τ1' τ2' } →
-- d final → -- red brackets
snd (d ⟨ τ1 ⊗ τ2 ⇒ τ1' ⊗ τ2' ⟩) →> ((snd d) ⟨ τ2 ⇒ τ2' ⟩)
ITGround : ∀{ d τ τ'} →
-- d final → -- red brackets
τ ▸gnd τ' →
(d ⟨ τ ⇒ ⦇·⦈ ⟩) →> (d ⟨ τ ⇒ τ' ⇒ ⦇·⦈ ⟩)
ITExpand : ∀{d τ τ' } →
-- d final → -- red brackets
τ ▸gnd τ' →
(d ⟨ ⦇·⦈ ⇒ τ ⟩) →> (d ⟨ ⦇·⦈ ⇒ τ' ⇒ τ ⟩)
-- single step (in contextual evaluation sense)
data _↦_ : (d d' : iexp) → Set where
Step : ∀{ d d0 d' d0' ε} →
d == ε ⟦ d0 ⟧ →
d0 →> d0' →
d' == ε ⟦ d0' ⟧ →
d ↦ d'
-- reflexive transitive closure of single steps into multi steps
data _↦*_ : (d d' : iexp) → Set where
MSRefl : ∀{d} → d ↦* d
MSStep : ∀{d d' d''} →
d ↦ d' →
d' ↦* d'' →
d ↦* d''
-- freshness
mutual
-- ... with respect to a hole context
data envfresh : varname → env → Set where
EFId : ∀{x Γ} → x # Γ → envfresh x (Id Γ)
EFSubst : ∀{x d σ y} → fresh x d
→ envfresh x σ
→ x ≠ y
→ envfresh x (Subst d y σ)
-- ... for inernal expressions
data fresh : varname → iexp → Set where
FConst : ∀{x} → fresh x c
FVar : ∀{x y} → x ≠ y → fresh x (X y)
FLam : ∀{x y τ d} → x ≠ y → fresh x d → fresh x (·λ y [ τ ] d)
FHole : ∀{x u σ} → envfresh x σ → fresh x (⦇⦈⟨ u , σ ⟩)
FNEHole : ∀{x d u σ} → envfresh x σ → fresh x d → fresh x (⦇⌜ d ⌟⦈⟨ u , σ ⟩)
FAp : ∀{x d1 d2} → fresh x d1 → fresh x d2 → fresh x (d1 ∘ d2)
FCast : ∀{x d τ1 τ2} → fresh x d → fresh x (d ⟨ τ1 ⇒ τ2 ⟩)
FFailedCast : ∀{x d τ1 τ2} → fresh x d → fresh x (d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩)
FFst : ∀{x d} → fresh x d → fresh x (fst d)
FSnd : ∀{x d} → fresh x d → fresh x (snd d)
FPair : ∀{x d1 d2} → fresh x d1 → fresh x d2 → fresh x ⟨ d1 , d2 ⟩
-- ... for external expressions
data freshe : varname → eexp → Set where
FRHConst : ∀{x} → freshe x c
FRHAsc : ∀{x e τ} → freshe x e → freshe x (e ·: τ)
FRHVar : ∀{x y} → x ≠ y → freshe x (X y)
FRHLam1 : ∀{x y e} → x ≠ y → freshe x e → freshe x (·λ y e)
FRHLam2 : ∀{x τ e y} → x ≠ y → freshe x e → freshe x (·λ y [ τ ] e)
FRHEHole : ∀{x u} → freshe x (⦇⦈[ u ])
FRHNEHole : ∀{x u e} → freshe x e → freshe x (⦇⌜ e ⌟⦈[ u ])
FRHAp : ∀{x e1 e2} → freshe x e1 → freshe x e2 → freshe x (e1 ∘ e2)
FRHFst : ∀{x e} → freshe x e → freshe x (fst e)
FRHSnd : ∀{x e} → freshe x e → freshe x (snd e)
FRHPair : ∀{x e1 e2} → freshe x e1 → freshe x e2 → freshe x ⟨ e1 , e2 ⟩
-- with respect to all bindings in a context
freshΓ : {A : Set} → (Γ : A ctx) → (e : eexp) → Set
freshΓ {A} Γ e = (x : varname) → dom Γ x → freshe x e
-- x is not used in a binding site in d
mutual
data unbound-in-σ : varname → env → Set where
UBσId : ∀{x Γ} → unbound-in-σ x (Id Γ)
UBσSubst : ∀{x d y σ} → unbound-in x d
→ unbound-in-σ x σ
→ x ≠ y
→ unbound-in-σ x (Subst d y σ)
data unbound-in : (x : varname) (d : iexp) → Set where
UBConst : ∀{x} → unbound-in x c
UBVar : ∀{x y} → unbound-in x (X y)
UBLam2 : ∀{x d y τ} → x ≠ y
→ unbound-in x d
→ unbound-in x (·λ_[_]_ y τ d)
UBHole : ∀{x u σ} → unbound-in-σ x σ
→ unbound-in x (⦇⦈⟨ u , σ ⟩)
UBNEHole : ∀{x u σ d }
→ unbound-in-σ x σ
→ unbound-in x d
→ unbound-in x (⦇⌜ d ⌟⦈⟨ u , σ ⟩)
UBAp : ∀{ x d1 d2 } →
unbound-in x d1 →
unbound-in x d2 →
unbound-in x (d1 ∘ d2)
UBCast : ∀{x d τ1 τ2} → unbound-in x d → unbound-in x (d ⟨ τ1 ⇒ τ2 ⟩)
UBFailedCast : ∀{x d τ1 τ2} → unbound-in x d → unbound-in x (d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩)
UBFst : ∀{x d} → unbound-in x d → unbound-in x (fst d)
UBSnd : ∀{x d} → unbound-in x d → unbound-in x (snd d)
UBPair : ∀{x d1 d2} → unbound-in x d1 → unbound-in x d2 → unbound-in x ⟨ d1 , d2 ⟩
mutual
remove-from-free' : varname → eexp → List varname
remove-from-free' x e = remove-all natEQ (free-vars e) x
free-vars : (e : eexp) → List varname
free-vars c = []
free-vars (e ·: τ) = free-vars e
free-vars (X x) = x :: []
free-vars (·λ x e) = remove-from-free' x e
free-vars (·λ x [ τ ] e) = remove-from-free' x e
free-vars ⦇⦈[ u ] = []
free-vars ⦇⌜ e ⌟⦈[ u ] = free-vars e
free-vars (e₁ ∘ e₂) = free-vars e₁ ++ free-vars e₂
free-vars ⟨ x , x₁ ⟩ = free-vars x ++ free-vars x₁
free-vars (fst x) = free-vars x
free-vars (snd x) = free-vars x
mutual
data binders-disjoint-σ : env → iexp → Set where
BDσId : ∀{Γ d} → binders-disjoint-σ (Id Γ) d
BDσSubst : ∀{d1 d2 y σ} → binders-disjoint d1 d2
→ binders-disjoint-σ σ d2
→ binders-disjoint-σ (Subst d1 y σ) d2
-- two terms that do not share any binders
data binders-disjoint : (d1 : iexp) → (d2 : iexp) → Set where
BDConst : ∀{d} → binders-disjoint c d
BDVar : ∀{x d} → binders-disjoint (X x) d
BDLam : ∀{x τ d1 d2} → binders-disjoint d1 d2
→ unbound-in x d2
→ binders-disjoint (·λ_[_]_ x τ d1) d2
BDHole : ∀{u σ d2} → binders-disjoint-σ σ d2
→ binders-disjoint (⦇⦈⟨ u , σ ⟩) d2
BDNEHole : ∀{u σ d1 d2} → binders-disjoint-σ σ d2
→ binders-disjoint d1 d2
→ binders-disjoint (⦇⌜ d1 ⌟⦈⟨ u , σ ⟩) d2
BDAp : ∀{d1 d2 d3} → binders-disjoint d1 d3
→ binders-disjoint d2 d3
→ binders-disjoint (d1 ∘ d2) d3
BDCast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint (d1 ⟨ τ1 ⇒ τ2 ⟩) d2
BDFailedCast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint (d1 ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩) d2
BDFst : ∀{d1 d2} → binders-disjoint d1 d2 → binders-disjoint (fst d1) d2
BDSnd : ∀{d1 d2} → binders-disjoint d1 d2 → binders-disjoint (snd d1) d2
BDPair : ∀{d1 d2 d3} →
binders-disjoint d1 d3 →
binders-disjoint d2 d3 →
binders-disjoint ⟨ d1 , d2 ⟩ d3
mutual
-- each term has to be binders unique, and they have to be pairwise
-- disjoint with the collection of bound vars
data binders-unique-σ : env → Set where
BUσId : ∀{Γ} → binders-unique-σ (Id Γ)
BUσSubst : ∀{d y σ} → binders-unique d
→ binders-unique-σ σ
→ binders-disjoint-σ σ d
→ binders-unique-σ (Subst d y σ)
-- all the variable names in the term are unique
data binders-unique : iexp → Set where
BUHole : binders-unique c
BUVar : ∀{x} → binders-unique (X x)
BULam : {x : varname} {τ : typ} {d : iexp} → binders-unique d
→ unbound-in x d
→ binders-unique (·λ_[_]_ x τ d)
BUEHole : ∀{u σ} → binders-unique-σ σ
→ binders-unique (⦇⦈⟨ u , σ ⟩)
BUNEHole : ∀{u σ d} → binders-unique d
→ binders-unique-σ σ
→ binders-unique (⦇⌜ d ⌟⦈⟨ u , σ ⟩)
BUAp : ∀{d1 d2} → binders-unique d1
→ binders-unique d2
→ binders-disjoint d1 d2
→ binders-unique (d1 ∘ d2)
BUCast : ∀{d τ1 τ2} → binders-unique d
→ binders-unique (d ⟨ τ1 ⇒ τ2 ⟩)
BUFailedCast : ∀{d τ1 τ2} → binders-unique d
→ binders-unique (d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩)
BUFst : ∀{d} →
binders-unique d →
binders-unique (fst d)
BUSnd : ∀{d} →
binders-unique d →
binders-unique (snd d)
BUPair : ∀{d1 d2} →
binders-unique d1 →
binders-unique d2 →
binders-disjoint d1 d2 →
binders-unique ⟨ d1 , d2 ⟩
_⇓_ : iexp → iexp → Set
d1 ⇓ d2 = (d1 ↦* d2 × d2 final)
-- this is the decoding function, so half the iso. this won't work long term
postulate
_↑_ : iexp → eexp → Set
_↓_ : eexp → iexp → Set
iso : Set
Exp : typ
-- naming conventions:
--
-- type contexts, tctx, are named Γ (because they always are)
-- hole contextst, ??, are named Δ
--
-- types, typ, are named τ
-- unexpanded expressions, uexp, are named ê (for "_e_xpression but also following the POPL17 notation)
-- expanded expressions, eexp, are named e (for "_e_xpression")
-- internal expressions, iexp, are named d (because they have a _d_ynamics)
-- splices are named ψ
-- function-like livelit context well-formedness
mutual
livelitctx = Σ[ Φ' ∈ livelitdef ctx ] (Φ' livelitctx')
data _livelitctx' : (Φ' : livelitdef ctx) → Set where
PhiWFEmpty : ∅ livelitctx'
PhiWFMac : ∀{a π} →
(Φ : livelitctx) →
a # π1 Φ →
(π1 Φ ,, (a , π)) livelitctx'
_₁ : (Φ : livelitctx) → livelitdef ctx
_₁ = π1
infixr 25 _₁
_,,_::_⦅given_⦆ : (Φ : livelitctx) →
(a : livelitname) →
livelitdef →
a # (Φ)₁ →
livelitctx
Φ ,, a :: π ⦅given #h ⦆ = ((Φ)₁ ,, (a , π) , PhiWFMac Φ #h)
-- livelit expansion
mutual
data _,_⊢_~~>_⇒_ : (Φ : livelitctx) →
(Γ : tctx) →
(ê : uexp) →
(e : eexp) →
(τ : typ) →
Set
where
SPEConst : ∀{Φ Γ} → Φ , Γ ⊢ c ~~> c ⇒ b
SPEAsc : ∀{Φ Γ ê e τ} →
Φ , Γ ⊢ ê ~~> e ⇐ τ →
Φ , Γ ⊢ (ê ·: τ) ~~> e ·: τ ⇒ τ
SPEVar : ∀{Φ Γ x τ} →
(x , τ) ∈ Γ →
Φ , Γ ⊢ (X x) ~~> (X x) ⇒ τ
SPELam : ∀{Φ Γ x e τ1 τ2 ê} →
x # Γ →
Φ , Γ ,, (x , τ1) ⊢ ê ~~> e ⇒ τ2 →
Φ , Γ ⊢ (·λ_[_]_ x τ1 ê) ~~> (·λ x [ τ1 ] e) ⇒ (τ1 ==> τ2)
SPEAp : ∀{Φ Γ ê1 ê2 τ1 τ2 τ e1 e2} →
Φ , Γ ⊢ ê1 ~~> e1 ⇒ τ1 →
τ1 ▸arr τ2 ==> τ →
Φ , Γ ⊢ ê2 ~~> e2 ⇐ τ2 →
holes-disjoint e1 e2 →
Φ , Γ ⊢ ê1 ∘ ê2 ~~> e1 ∘ e2 ⇒ τ
SPEHole : ∀{Φ Γ u} → Φ , Γ ⊢ ⦇⦈[ u ] ~~> ⦇⦈[ u ] ⇒ ⦇·⦈
SPNEHole : ∀{Φ Γ ê e τ u} →
hole-name-new e u →
Φ , Γ ⊢ ê ~~> e ⇒ τ →
Φ , Γ ⊢ ⦇⌜ ê ⌟⦈[ u ] ~~> ⦇⌜ e ⌟⦈[ u ] ⇒ ⦇·⦈
SPEFst : ∀{Φ Γ ê e τ τ1 τ2} →
Φ , Γ ⊢ ê ~~> e ⇒ τ →
τ ▸prod τ1 ⊗ τ2 →
Φ , Γ ⊢ fst ê ~~> fst e ⇒ τ1
SPESnd : ∀{Φ Γ ê e τ τ1 τ2} →
Φ , Γ ⊢ ê ~~> e ⇒ τ →
τ ▸prod τ1 ⊗ τ2 →
Φ , Γ ⊢ snd ê ~~> snd e ⇒ τ2
SPEPair : ∀{Φ Γ ê1 ê2 τ1 τ2 e1 e2} →
Φ , Γ ⊢ ê1 ~~> e1 ⇒ τ1 →
Φ , Γ ⊢ ê2 ~~> e2 ⇒ τ2 →
holes-disjoint e1 e2 →
Φ , Γ ⊢ ⟨ ê1 , ê2 ⟩ ~~> ⟨ e1 , e2 ⟩ ⇒ τ1 ⊗ τ2
SPEApLivelit : ∀{Φ Γ a dm π denc eexpanded τsplice psplice esplice u} →
holes-disjoint eexpanded esplice →
freshΓ Γ eexpanded →
(a , π) ∈ (Φ)₁ →
∅ , ∅ ⊢ dm :: (livelitdef.model-type π) →
((livelitdef.expand π) ∘ dm) ⇓ denc →
denc ↑ eexpanded →
Φ , Γ ⊢ psplice ~~> esplice ⇐ τsplice →
∅ ⊢ eexpanded <= τsplice ==> (livelitdef.expansion-type π) →
Φ , Γ ⊢ $ a ⟨ dm ⁏ (τsplice , psplice) :: [] ⟩[ u ] ~~> ((eexpanded ·: τsplice ==> livelitdef.expansion-type π) ∘ esplice) ⇒ livelitdef.expansion-type π
data _,_⊢_~~>_⇐_ : (Φ : livelitctx) →
(Γ : tctx) →
(ê : uexp) →
(e : eexp) →
(τ : typ) →
Set
where
APELam : ∀{Φ Γ x e τ τ1 τ2 ê} →
x # Γ →
τ ▸arr τ1 ==> τ2 →
Φ , Γ ,, (x , τ1) ⊢ ê ~~> e ⇐ τ2 →
Φ , Γ ⊢ (·λ x ê) ~~> (·λ x e) ⇐ τ
APESubsume : ∀{Φ Γ ê e τ τ'} →
Φ , Γ ⊢ ê ~~> e ⇒ τ' →
τ ~ τ' →
Φ , Γ ⊢ ê ~~> e ⇐ τ
|
{
"alphanum_fraction": 0.4021015481,
"avg_line_length": 38.3993839836,
"ext": "agda",
"hexsha": "4453c13c104f2cb9195ca5dfbbe3659204f7fdc1",
"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": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda",
"max_forks_repo_path": "core.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazel-palette-agda",
"max_issues_repo_path": "core.agda",
"max_line_length": 177,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazel-palette-agda",
"max_stars_repo_path": "core.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z",
"num_tokens": 15299,
"size": 37401
}
|
open import Prelude
module Implicits.Resolution.Finite.Expressiveness where
open import Coinduction
open import Data.Fin.Substitution
open import Implicits.Syntax
open import Implicits.Substitutions
open import Implicits.Resolution.Deterministic.Resolution as D
open import Implicits.Resolution.Ambiguous.Resolution as A
open import Implicits.Resolution.Finite.Resolution as F
open import Implicits.Resolution.Infinite.Resolution as ∞
open import Implicits.Resolution.Termination
module Finite⊆Infinite where
p : ∀ {ν} {a} {Δ : ICtx ν} → Δ F.⊢ᵣ a → Δ ∞.⊢ᵣ a
p (r-simp a a↓τ) = r-simp a (lem a↓τ)
where
lem : ∀ {ν} {a τ} {Δ : ICtx ν} → Δ F.⊢ a ↓ τ → Δ ∞.⊢ a ↓ τ
lem (i-simp τ) = i-simp τ
lem (i-iabs _ ⊢ᵣa b↓τ) = i-iabs (p ⊢ᵣa) (lem b↓τ)
lem (i-tabs b a[/b]↓τ) = i-tabs b (lem a[/b]↓τ)
p (r-iabs x) = r-iabs (p x)
p (r-tabs x) = r-tabs (p x)
module Finite⊆Ambiguous where
p : ∀ {ν} {a} {Δ : ICtx ν} → Δ F.⊢ᵣ a → Δ A.⊢ᵣ a
p (r-simp a a↓τ) = lem a↓τ (r-ivar a)
where
lem : ∀ {ν} {a τ} {Δ : ICtx ν} → Δ F.⊢ a ↓ τ → Δ A.⊢ᵣ a → Δ A.⊢ᵣ simpl τ
lem (i-simp τ) K⊢ᵣτ = K⊢ᵣτ
lem (i-iabs _ ⊢ᵣa b↓τ) K⊢ᵣa⇒b = lem b↓τ (r-iapp K⊢ᵣa⇒b (p ⊢ᵣa))
lem (i-tabs b a[/b]↓τ) K⊢ᵣ∀a = lem a[/b]↓τ (r-tapp b K⊢ᵣ∀a)
p (r-iabs x) = r-iabs (p x)
p (r-tabs x) = r-tabs (p x)
module Deterministic⊆Finite where
open import Extensions.ListFirst
-- Oliveira's termination condition is part of the well-formdness of types
-- So we assume here that ⊢term x holds for all types x
p : ∀ {ν} {a : Type ν} {Δ : ICtx ν} → (∀ {ν} (a : Type ν) → ⊢term a) → Δ D.⊢ᵣ a → Δ F.⊢ᵣ a
p term (r-simp {ρ = r} x r↓a) =
r-simp (proj₁ $ first⟶∈ x) (lem r↓a)
where
lem : ∀ {ν} {Δ : ICtx ν} {a r} → Δ D.⊢ r ↓ a → Δ F.⊢ r ↓ a
lem (i-simp a) = i-simp a
lem (i-iabs {ρ₁ = ρ₁} {ρ₂ = ρ₂} ⊢ᵣρ₁ ρ₂↓τ) with term (ρ₁ ⇒ ρ₂)
lem (i-iabs ⊢ᵣρ₁ ρ₂↓τ) | term-iabs _ _ a-ρ<-b _ = i-iabs a-ρ<-b (p term ⊢ᵣρ₁) (lem ρ₂↓τ)
lem (i-tabs b x₁) = i-tabs b (lem x₁)
p term (r-iabs ρ₁ {ρ₂ = ρ₂} x) = r-iabs (p term x)
p term (r-tabs x) = r-tabs (p term x)
|
{
"alphanum_fraction": 0.5814726841,
"avg_line_length": 37.5892857143,
"ext": "agda",
"hexsha": "59d9e95076388ea3e5bc8c654e9d9c395d0fbcf3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Finite/Expressiveness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Finite/Expressiveness.agda",
"max_line_length": 94,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Finite/Expressiveness.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 1004,
"size": 2105
}
|
module Numeral.Natural.LinearSearchDecidable where -- TODO: Maybe move and rename to Numeral.Natural.Sequence.BoundedSearch
-- TODO: Maybe more natural to use 𝕟 (finite naturals) instead of ℕ (naturals)?
open import Data.Boolean
open import Data.Boolean.Stmt
open import Data.List
import Data.List.Functions as List
open import Data.List.Relation.Membership using (_∈_)
open import Data.List.Relation.Membership.Proofs
open import Data.List.Relation.Quantification
open import Data.List.Relation.Quantification.Proofs
open import Data.List.Sorting
open import Data.Option
import Data.Option.Functions as Option
open import Functional
open import Logic.Propositional
open import Numeral.Finite
import Numeral.Finite.LinearSearch as 𝕟
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.Proofs.Order
open import Numeral.Natural.Relation.Order
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Function
private variable a b n i j : ℕ
private variable f : ℕ → Bool
{-
open import Data.Boolean
open import Data.Boolean.Stmt
open import Data.Option
import Data.Option.Functions as Option
open import Functional
open import Logic
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Relation.Order
open import Structure.Relator.Ordering
-- Finds the maximal argument satisfying the given argument within the given search upper bound by searching linearly.
-- Examples:
-- findUpperBoundedMax(10 ∣?_) 5 = None
-- findUpperBoundedMax(10 ∣?_) 20 = Some 20
-- findUpperBoundedMax(10 ∣?_) 22 = Some 20
-- findUpperBoundedMax(10 ∣?_) 100 = Some 100
-- findUpperBoundedMax(10 ∣?_) 102 = Some 100
findUpperBoundedMax : (ℕ → Bool) → ℕ → Option(ℕ)
findUpperBoundedMax f(i) with f(i)
findUpperBoundedMax f(i) | 𝑇 = Some i
findUpperBoundedMax f(𝟎) | 𝐹 = None
findUpperBoundedMax f(𝐒(i)) | 𝐹 = findUpperBoundedMax f(i)
findMaxIndexInRange : (ℕ → Bool) → ℕ → ℕ → Option(ℕ)
findMaxIndexInRange f min max = Option.map (_+ min) (findUpperBoundedMax (f ∘ (_+ min)) (max −₀ min))
-- Finds the minimal argument satisfying the given argument within the given search upper bound by searching linearly.
-- Examples:
-- findUpperBoundedMin(10 ∣?_) 5 = None
-- findUpperBoundedMin(10 ∣?_) 20 = Some 10
-- findUpperBoundedMin(10 ∣?_) 22 = Some 10
-- findUpperBoundedMin(10 ∣?_) 100 = Some 10
-- findUpperBoundedMax(10 ∣?_) 102 = Some 10
findUpperBoundedMin : (ℕ → Bool) → ℕ → Option(ℕ)
findUpperBoundedMin f(i) with f(𝟎)
findUpperBoundedMin f(i) | 𝑇 = Some 𝟎
findUpperBoundedMin f(𝟎) | 𝐹 = None
findUpperBoundedMin f(𝐒(i)) | 𝐹 = Option.map 𝐒 (findUpperBoundedMin (f ∘ 𝐒)(i))
open import Data
open import Data.Boolean.Stmt.Proofs
open import Data.Option.Equiv.Id
open import Lang.Inspect
open import Logic.Predicate
open import Logic.Propositional
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Function.Domain
open import Structure.Relator.Properties
open import Structure.Relator
findUpperBoundedMax-correctness : ∀{f}{max i} → (findUpperBoundedMax f(max) ≡ Some(i)) → ((i ≤ max) ∧ IsTrue(f(i)))
findUpperBoundedMax-correctness {f} {max} {i} p with f(max) | inspect f(max)
findUpperBoundedMax-correctness {f} {max} {.max} [≡]-intro | 𝑇 | intro eq = [∧]-intro (reflexivity(_≤_)) (substitute₁ₗ(IsTrue) eq <>)
findUpperBoundedMax-correctness {f} {𝟎} {i} () | 𝐹 | _
findUpperBoundedMax-correctness {f} {𝐒(max)} {i} p | 𝐹 | intro eq with findUpperBoundedMax-correctness {f} {max} {i} p
... | [∧]-intro a b = [∧]-intro ([≤]-successor a) b
findUpperBoundedMin-correctness : ∀{f}{max i} → (findUpperBoundedMin f(max) ≡ Some(i)) → ((i ≤ max) ∧ IsTrue(f(i)))
findUpperBoundedMin-correctness {f} {max} {i} p with f(𝟎) | inspect f(𝟎)
findUpperBoundedMin-correctness {f} {max} {.𝟎} [≡]-intro | 𝑇 | intro eq = [∧]-intro [≤]-minimum ([↔]-to-[←] IsTrue.is-𝑇 eq)
findUpperBoundedMin-correctness {f} {𝐒 max} {𝟎} p | 𝐹 | intro eq with findUpperBoundedMin (f ∘ 𝐒) max
findUpperBoundedMin-correctness {f} {𝐒 max} {𝟎} () | 𝐹 | intro eq | None
findUpperBoundedMin-correctness {f} {𝐒 max} {𝟎} () | 𝐹 | intro eq | Some _
findUpperBoundedMin-correctness {f} {𝐒 max} {𝐒 i} p | 𝐹 | intro eq = [∧]-map (\p → [≤]-with-[𝐒] ⦃ p ⦄) id (findUpperBoundedMin-correctness {f ∘ 𝐒} {max} {i} (injective(Option.map 𝐒) ⦃ map-injectivity ⦄ p))
findUpperBoundedMin-minimal : ∀{f}{max i j} → (findUpperBoundedMin f(max) ≡ Some(i)) → IsTrue(f(j)) → (i ≤ j)
findUpperBoundedMin-minimal {i = 𝟎} {_} p q = [≤]-minimum
findUpperBoundedMin-minimal {i = 𝐒 i} {𝟎} p q = {!!}
findUpperBoundedMin-minimal {i = 𝐒 i} {𝐒 j} p q = [≤]-with-[𝐒] ⦃ findUpperBoundedMin-minimal {i = i}{j} {!!} q ⦄
-- foldRange : ()
{-
searchUntilUpperBound : (f : ℕ → Bool) → ∃(IsTrue ∘ f) → ℕ
searchUntilUpperBound f ([∃]-intro upperBound ⦃ proof ⦄) = {!fold!}
searchUntilUpperBoundProof : ∀{f}{upperBound} → (IsTrue ∘ f)(searchUntilUpperBound f upperBound)
searchUntilUpperBoundProof = {!!}
bruteforceMinExistence : ∀{ℓ} → (P : ℕ → Stmt{ℓ}) → ⦃ ComputablyDecidable(P) ⦄ → ∃(P) → ∃(Weak.Properties.MinimumOf(_≤_)(P))
∃.witness (bruteforceMinExistence P upperBound) = {!!}
∃.proof (bruteforceMinExistence P upperBound) = {!!}
-}
-}
|
{
"alphanum_fraction": 0.7106274008,
"avg_line_length": 45.5583333333,
"ext": "agda",
"hexsha": "2ca1cda55d54f80972ee2282565b7767d15ef288",
"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/LinearSearchDecidable.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/LinearSearchDecidable.agda",
"max_line_length": 213,
"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/LinearSearchDecidable.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": 1881,
"size": 5467
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Paths
module lib.types.Unit where
pattern tt = unit
⊙Unit : Ptd₀
⊙Unit = ⊙[ Unit , unit ]
-- Unit is contractible
instance
Unit-level : {n : ℕ₋₂} → has-level n Unit
Unit-level {n = ⟨-2⟩} = has-level-in (unit , λ y → idp)
Unit-level {n = S n} = raise-level n Unit-level
|
{
"alphanum_fraction": 0.6438356164,
"avg_line_length": 20.2777777778,
"ext": "agda",
"hexsha": "a6f7c37f36b25bfde9516080b7d7b0b02c33551c",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Unit.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Unit.agda",
"max_line_length": 57,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Unit.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": 119,
"size": 365
}
|
open import Prelude
module Implicits.Resolution.Termination.Stack
where
open import Induction.WellFounded
open import Induction.Nat
open import Data.Fin.Substitution
open import Implicits.Syntax
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas
open import Data.Nat hiding (_<_)
open import Data.Nat.Properties
open import Data.List
open import Data.List.All
open import Data.List.Any
open Membership-≡
open import Implicits.Resolution.Termination.SizeMeasures
-- on the stack we maintain, for each rule in Δ,
-- the last goal type that resulted from using the rule
Stack : ∀ {ν} → ICtx ν → Set
Stack {ν} Δ = All (const $ Type ν) Δ
----------------------------------------------------------------
-- basic stack operations
_push_for_ : ∀ {ν r} {Δ : ICtx ν} → Stack Δ → Type ν → r ∈ Δ → Stack Δ
(a All.∷ s) push a' for here _ = a' All.∷ s
(b All.∷ s) push a for there r∈Δ = b All.∷ s push a for r∈Δ
_prepend_ : ∀ {ν r} {Δ : ICtx ν} → Stack Δ → Type ν → Stack (r ∷ Δ)
s prepend a = a All.∷ s
_get_ : ∀ {ν r} {Δ : ICtx ν} → Stack Δ → r ∈ Δ → Type ν
(a All.∷ s) get here _ = a
(a All.∷ s) get there r∈Δ = s get r∈Δ
ssum : ∀ {ν} {Δ : ICtx ν} → Stack Δ → ℕ
ssum All.[] = 0
ssum (a All.∷ s) = h|| a || + ssum s
stack-weaken : ∀ {ν} {Δ : ICtx ν} → Stack Δ → Stack (ictx-weaken Δ)
stack-weaken All.[] = All.[]
stack-weaken (px All.∷ s) = (tp-weaken px) All.∷ (stack-weaken s)
----------------------------------------------------------------
-- stack ordering
_s<_ : ∀ {ν} {Δ : ICtx ν} → (s s' : Stack Δ) → Set
s s< s' = ssum s < ssum s'
_for_⊬dom_ : ∀ {ν r} {Δ : ICtx ν} → Type ν → r ∈ Δ → Stack Δ → Set
a for r∈Δ ⊬dom s = (s push a for r∈Δ) s< s
|
{
"alphanum_fraction": 0.5929887106,
"avg_line_length": 30.0535714286,
"ext": "agda",
"hexsha": "a88259e22cf76be5c3f70c74933444b6f4c05d9b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Termination/Stack.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Termination/Stack.agda",
"max_line_length": 70,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Termination/Stack.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 594,
"size": 1683
}
|
{-# OPTIONS --cubical-compatible --rewriting --confluence-check #-}
open import Agda.Primitive using (Level; _⊔_; Setω; lzero; lsuc)
module Issue4032 where
infix 4 _≡_
data _≡_ {ℓ : Level} {A : Set ℓ} (a : A) : A → Set ℓ where
refl : a ≡ a
{-# BUILTIN REWRITE _≡_ #-}
run : ∀ {ℓ} {A B : Set ℓ} → A ≡ B → A → B
run refl x = x
nur : ∀ {ℓ} {A B : Set ℓ} → A ≡ B → B → A
nur refl x = x
convert : ∀ {ℓ} {A B : Set ℓ} (p : A ≡ B) (a : A) → nur p (run p a) ≡ a
convert refl a = refl
trevnoc : ∀ {ℓ} {A B : Set ℓ} (p : A ≡ B) (b : B) → run p (nur p b) ≡ b
trevnoc refl b = refl
ap : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {a₁ a₂} → a₁ ≡ a₂ → f a₁ ≡ f a₂
ap f refl = refl
transport : ∀ {a b} {A : Set a} (B : A → Set b) {x y : A} (p : x ≡ y) → B x → B y
transport B p = run (ap B p)
apD : ∀ {a b} {A : Set a} {B : A → Set b} (f : (x : A) → B x) {a₁ a₂} → (p : a₁ ≡ a₂) → transport B p (f a₁) ≡ f a₂
apD f refl = refl
ap2 : ∀ {a b c} {A : Set a} {B : A → Set b} {C : Set c} (f : (x : A) → B x → C) {a₁ a₂} (pa : a₁ ≡ a₂) {b₁ b₂} → transport B pa b₁ ≡ b₂ → f a₁ b₁ ≡ f a₂ b₂
ap2 f refl refl = refl
postulate fromIso : ∀ {ℓ} {A B : Set ℓ} (f : A → B) (g : B → A) (η : (x : A) → g (f x) ≡ x) (ε : (x : B) → f (g x) ≡ x) (τ : (x : A) → ap f (η x) ≡ ε (f x)) → A ≡ B
postulate fromIso-refl : ∀ {ℓ} {A : Set ℓ} → fromIso {ℓ} {A} {A} (λ x → x) (λ x → x) (λ x → refl) (λ x → refl) (λ x → refl) ≡ refl
{-# REWRITE fromIso-refl #-}
J : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} {a : A} (P : (b : A) → a ≡ b → Set ℓ₂) {b : A} (p : a ≡ b) → P a refl → P b p
J R refl r = r
module foo {-ℓ₁-} {ℓ} {Γ : Set ℓ{-₁-}} {xs ys : Γ} (ps : xs ≡ ys) (tA : Γ → Set ℓ) (tB : (γ : Γ) → tA γ → Set ℓ) where
module pf where
iso-f : ((a : tA xs) → (tB xs) a) → ((a : tA ys) → (tB ys) a)
iso-f var1 var0 = run (ap2 tB ps (trevnoc (ap tA ps) var0)) (var1 (nur (ap tA ps) var0))
iso-g : ((a : tA ys) → (tB ys) a) → ((a : tA xs) → (tB xs) a)
iso-g var1 var0 = nur (ap2 tB ps refl) (var1 (run (ap tA ps) var0))
iso-η : (var0 : _) → iso-g (iso-f var0) ≡ var0
iso-η var0 = J (λ ys (ps : xs ≡ ys) → (λ var1 → nur (ap2 tB ps refl) (run (ap2 tB ps (trevnoc (ap tA ps) (run (ap tA ps) var1))) (var0 (nur (ap tA ps) (run (ap tA ps) var1))))) ≡ var0) ps refl
iso-ε : (var0 : _) → iso-f (iso-g var0) ≡ var0
iso-ε = J (λ ys (ps : xs ≡ ys) → (var0 : (a : tA ys) → tB ys a) → (λ var1 → run (ap2 tB ps (trevnoc (ap tA ps) var1)) (nur (ap2 tB ps refl) (var0 (run (ap tA ps) (nur (ap tA ps) var1))))) ≡ var0) ps (λ var0 → refl)
iso-τ : (var0 : _) → ap iso-f (iso-η var0) ≡ iso-ε (iso-f var0)
iso-τ var0 = J
(λ ys (ps : xs ≡ ys) →
ap
(λ var1 var2 →
run (ap2 tB ps (trevnoc (ap tA ps) var2))
(var1 (nur (ap tA ps) var2)))
(J
(λ ys₁ ps₁ →
(λ var1 →
nur (ap2 tB ps₁ refl)
(run (ap2 tB ps₁ (trevnoc (ap tA ps₁) (run (ap tA ps₁) var1)))
(var0 (nur (ap tA ps₁) (run (ap tA ps₁) var1)))))
≡ var0)
ps refl)
≡
J
(λ ys₁ ps₁ →
(var1 : (a : tA ys₁) → tB ys₁ a) →
(λ var2 →
run (ap2 tB ps₁ (trevnoc (ap tA ps₁) var2))
(nur (ap2 tB ps₁ refl)
(var1 (run (ap tA ps₁) (nur (ap tA ps₁) var2)))))
≡ var1)
ps (λ var1 → refl)
(λ var1 →
run (ap2 tB ps (trevnoc (ap tA ps) var1))
(var0 (nur (ap tA ps) var1))))
ps refl
open pf
pf : ((a : tA xs) → (tB xs) a) ≡ ((a : tA ys) → (tB ys) a)
pf = fromIso iso-f iso-g iso-η iso-ε iso-τ
module bar {ℓ} {Γ : Set ℓ} {γ : Γ} {A : Γ → Set ℓ} {B : (γ : Γ) → A γ → Set ℓ} where
g1 : ((a : A γ) → B γ a) → (a : A γ) → B γ a
g2 : ((a : A γ) → B γ a) → (a : A γ) → B γ a
g1 = foo.pf.iso-g {xs = γ} refl A B
g2 = λ f x → f x
pfg : g1 ≡ g2
pfg = refl
baz : foo.pf {xs = γ} refl A B ≡ refl
baz = pf
where
pf : fromIso {_} {(x : A γ) → B γ x} (λ f x → f x) g2 (foo.pf.iso-η refl A B) (foo.pf.iso-ε refl A B) (foo.pf.iso-τ refl A B) ≡ refl
pf = refl
{- WAS:
refl !=
fromIso (foo.pf.iso-f refl A B) (foo.pf.iso-g refl A B)
(foo.pf.iso-η refl A B) (foo.pf.iso-ε refl A B)
(foo.pf.iso-τ refl A B)
of type ((x : A γ) → B γ x) ≡ ((x : A γ) → B γ x)
when checking that the expression pf has type
foo.pf refl A B ≡ refl
-}
|
{
"alphanum_fraction": 0.4307529162,
"avg_line_length": 39.9576271186,
"ext": "agda",
"hexsha": "81e36dd853d325675ef0410e64735af57f5efed6",
"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/Issue4032.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/Issue4032.agda",
"max_line_length": 218,
"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/Issue4032.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2030,
"size": 4715
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Predicate transformers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Unary.PredicateTransformer where
open import Level hiding (_⊔_)
open import Function
open import Data.Product
open import Relation.Nullary
open import Relation.Unary
open import Relation.Binary using (REL)
------------------------------------------------------------------------
-- Heterogeneous and homogeneous predicate transformers
PT : ∀ {a b} → Set a → Set b → (ℓ₁ ℓ₂ : Level) → Set _
PT A B ℓ₁ ℓ₂ = Pred A ℓ₁ → Pred B ℓ₂
Pt : ∀ {a} → Set a → (ℓ : Level) → Set _
Pt A ℓ = PT A A ℓ ℓ
-- Composition and identity
_⍮_ : ∀ {a b c ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} {C : Set c} →
PT B C ℓ₂ ℓ₃ → PT A B ℓ₁ ℓ₂ → PT A C ℓ₁ _
S ⍮ T = S ∘ T
skip : ∀ {a ℓ} {A : Set a} → PT A A ℓ ℓ
skip P = P
------------------------------------------------------------------------
-- Operations on predicates extend pointwise to predicate transformers
module _ {a b} {A : Set a} {B : Set b} where
-- The bottom and the top of the predicate transformer lattice.
abort : PT A B zero zero
abort = λ _ → ∅
magic : PT A B zero zero
magic = λ _ → U
-- Negation.
∼_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂
∼ T = ∁ ∘ T
-- Refinement.
infix 4 _⊑_ _⊒_ _⊑′_ _⊒′_
_⊑_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂ → Set _
S ⊑ T = ∀ {X} → S X ⊆ T X
_⊑′_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂ → Set _
S ⊑′ T = ∀ X → S X ⊆ T X
_⊒_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂ → Set _
T ⊒ S = T ⊑ S
_⊒′_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂ → Set _
T ⊒′ S = S ⊑′ T
-- The dual of refinement.
infix 4 _⋢_
_⋢_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂ → Set _
S ⋢ T = ∃ λ X → S X ≬ T X
-- Union.
infixl 6 _⊓_
_⊓_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂
S ⊓ T = λ X → S X ∪ T X
-- Intersection.
infixl 7 _⊔_
_⊔_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂
S ⊔ T = λ X → S X ∩ T X
-- Implication.
infixl 8 _⇛_
_⇛_ : ∀ {ℓ₁ ℓ₂} → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂ → PT A B ℓ₁ ℓ₂
S ⇛ T = λ X → S X ⇒ T X
-- Infinitary union and intersection.
infix 9 ⨆ ⨅
⨆ : ∀ {ℓ₁ ℓ₂ i} (I : Set i) → (I → PT A B ℓ₁ ℓ₂) → PT A B ℓ₁ _
⨆ I T = λ X → ⋃[ i ∶ I ] T i X
syntax ⨆ I (λ i → T) = ⨆[ i ∶ I ] T
⨅ : ∀ {ℓ₁ ℓ₂ i} (I : Set i) → (I → PT A B ℓ₁ ℓ₂) → PT A B ℓ₁ _
⨅ I T = λ X → ⋂[ i ∶ I ] T i X
syntax ⨅ I (λ i → T) = ⨅[ i ∶ I ] T
-- Angelic and demonic update.
⟨_⟩ : ∀ {ℓ} → REL A B ℓ → PT B A ℓ _
⟨ R ⟩ P = λ x → R x ≬ P
[_] : ∀ {ℓ} → REL A B ℓ → PT B A ℓ _
[ R ] P = λ x → R x ⊆ P
|
{
"alphanum_fraction": 0.4579847217,
"avg_line_length": 22.9083333333,
"ext": "agda",
"hexsha": "6cda31c3cf237bae832a3741e73cbf2929a68055",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Unary/PredicateTransformer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Unary/PredicateTransformer.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Unary/PredicateTransformer.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1246,
"size": 2749
}
|
{-# OPTIONS --without-K #-}
-- This should really be called FinSet. From nlab:
-- FinSet is the category of finite sets and all functions between
-- them: the full subcategory of Set on finite sets. It is easy (and
-- thus common) to make FinSet skeletal; there is one object for each
-- natural number n (including n=0), and a morphism from m to n is an
-- m-tuple (f0,…,fm−1) of numbers satisfying 0≤fi<n. This amounts to
-- identifying n with the set {0,…,n−1}. (Sometimes {1,…,n} is used
-- instead.) This is exactly what we do below
-- Definition of the Operations on permutations, based on the Vector representation
-- There are 2 sets of definitions here:
-- 1. pure Vector, in which the contents are arbitrary sets
-- 2. specialized to Fin contents.
-- Some notes:
-- - There are operations (such as sequential composition) which 'lift' more
-- awkwardly.
-- - To avoid a proliferation of bad names, we use sub-modules
-- Cauchy representation Vec (Fin m) n without checks that m=n or
-- checks of uniqueness and completeness has a commutative semiring
-- structure (modulo a postulate about sym). This is the main building
-- block of ConcretePermutation
module FinVec where
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.Vec renaming (map to mapV; _++_ to _++V_; concat to concatV)
open import Data.Fin using (Fin; inject+; raise; zero; suc)
open import Function using (_∘_; id; _$_)
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]′) renaming (map to map⊎)
open import Data.Product using (_×_; _,′_; proj₁; proj₂)
open import Equiv
open import TypeEquiv using (swap₊; swap⋆)
import TypeEquiv as TE
open import FinEquiv using (module Plus; module Times; module PlusTimes)
open import Proofs using (
-- VectorLemmas
_!!_; concat-map; map-map-map; lookup-map; map-∘
)
import Level
open import Algebra
open import Algebra.Structures
open import Relation.Binary.Core
open import Relation.Binary.PropositionalEquality using (subst; sym; trans; cong₂)
open import Groupoid
------------------------------------------------------------------------------
-- Pure vector operations
-- Does not involve Fin at all.
-- Note: not exported!
private
module V where
_⊎v_ : ∀ {m n} {A B : Set} → Vec A m → Vec B n → Vec (A ⊎ B) (m + n)
α ⊎v β = tabulate (inj₁ ∘ _!!_ α) ++V tabulate (inj₂ ∘ _!!_ β)
swap+ : {m n : ℕ} {A B : Set} → Vec (A ⊎ B) (m + n) → Vec (B ⊎ A) (m + n)
swap+ v = tabulate (swap₊ ∘ _!!_ v)
_×v_ : ∀ {m n} {A B : Set} → Vec A m → Vec B n → Vec (A × B) (m * n)
α ×v β = α >>= (λ b → mapV (_,′_ b) β)
0v : {A : Set} → Vec A 0
0v = []
------------------------------------------------------------------------------
-- Elementary permutations, Fin version
-- Cauchy Representation Vec (Fin m) n without checks of uniqueness
-- and completeness
-- We need to define (at least) 0, 1, +, *, ∘, swap+, swap*
module F where
open import Data.Nat.Properties.Simple using (+-right-identity)
open import Data.Vec.Properties
using (lookup-allFin; tabulate∘lookup; lookup∘tabulate; tabulate-∘; lookup-++-inject+)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; cong; cong₂; subst; module ≡-Reasoning)
open ≡-Reasoning
open import Equiv using (_∼_)
open import Proofs using (congD!;
-- FinNatLemmas
inject+0≡uniti+;
-- FiniteFunctions
finext;
-- VectorLemmas
lookupassoc; map-++-commute; tabulate-split; left!!; right!!;
lookup-++-raise; unSplit; tab++[]≡tab∘̂unite+
)
open V
-- convenient abbreviations
FinVec : ℕ → ℕ → Set
FinVec m n = Vec (Fin m) n
private
fwd : {m n : ℕ} → (Fin m ⊎ Fin n) → Fin (m + n)
fwd = proj₁ Plus.fwd-iso
bwd : {m n : ℕ} → Fin (m + n) → (Fin m ⊎ Fin n)
bwd = Equiv.qinv.g (proj₂ Plus.fwd-iso)
bwd∘fwd~id : {m n : ℕ} → bwd {m} {n} ∘ fwd ∼ id
bwd∘fwd~id = Equiv.qinv.β (proj₂ Plus.fwd-iso)
-- make all the definitions abstract. Note that the type isn't,
-- otherwise we could not do anything at all with it!
abstract
-- principal component of the identity permutation
1C : {n : ℕ} → FinVec n n
1C {n} = allFin n
-- corresponds to ⊥ ≃ (⊥ × A) and other impossibilities
-- but don't use it, as it is abstract and will confuse external proofs!
0C : FinVec 0 0
0C = 1C {0}
-- Sequential composition
_∘̂_ : {n₀ n₁ n₂ : ℕ} → Vec (Fin n₁) n₀ → Vec (Fin n₂) n₁ → Vec (Fin n₂) n₀
π₁ ∘̂ π₂ = tabulate (_!!_ π₂ ∘ _!!_ π₁)
-- swap the first m elements with the last n elements
-- [ v₀ , v₁ , v₂ , ... , vm-1 , vm , vm₊₁ , ... , vm+n-1 ]
-- ==>
-- [ vm , vm₊₁ , ... , vm+n-1 , v₀ , v₁ , v₂ , ... , vm-1 ]
swap+cauchy : (m n : ℕ) → FinVec (n + m) (m + n)
swap+cauchy m n = tabulate (Plus.swapper m n)
-- Parallel additive composition
-- conceptually, what we want is
_⊎c'_ : ∀ {m₁ n₁ m₂ n₂} → FinVec m₁ m₂ → FinVec n₁ n₂ → FinVec (m₁ + n₁) (m₂ + n₂)
_⊎c'_ α β = mapV fwd (α ⊎v β)
-- but the above is tedious to work with. Instead, inline a bit to get
_⊎c_ : ∀ {m₁ n₁ m₂ n₂} → FinVec m₁ m₂ → FinVec n₁ n₂ → FinVec (m₁ + n₁) (m₂ + n₂)
_⊎c_ {m₁} α β = tabulate (fwd ∘ inj₁ ∘ _!!_ α) ++V
tabulate (fwd {m₁} ∘ inj₂ ∘ _!!_ β)
-- see ⊎c≡⊎c' lemma below
_⊎fv_ : ∀ {m₁ n₁ m₂ n₂} → FinVec m₁ m₂ → FinVec n₁ n₂ → FinVec (m₁ + n₁) (m₂ + n₂)
_⊎fv_ {m₁} α β = tabulate (λ j → fwd (map⊎ (_!!_ α) (_!!_ β) (bwd j)))
⊎-equiv : ∀ {m₁ n₁ m₂ n₂} → (α : FinVec m₁ m₂) → (β : FinVec n₁ n₂) → α ⊎c β ≡ α ⊎fv β
⊎-equiv {m₁} {n₁} {m₂} {n₂} α β =
let mm s = map⊎ (_!!_ α) (_!!_ β) s in
let g = fwd ∘ mm ∘ bwd in
begin (
tabulate (λ j → fwd (inj₁ (α !! j))) ++V tabulate (λ j → fwd {m₁} (inj₂ (β !! j)))
≡⟨ refl ⟩ -- map⊎ evaluates on inj₁/inj₂
tabulate (fwd ∘ mm ∘ inj₁) ++V tabulate (fwd ∘ mm ∘ inj₂)
≡⟨ cong₂ _++V_ (finext (λ i → cong (fwd ∘ mm) (sym (bwd∘fwd~id (inj₁ i)))))
(finext (λ i → cong (fwd ∘ mm) (sym (bwd∘fwd~id (inj₂ i))))) ⟩
tabulate {m₂} (g ∘ fwd ∘ inj₁) ++V tabulate {n₂} (g ∘ fwd {m₂} ∘ inj₂)
≡⟨ sym (tabulate-split {m₂} {n₂} {f = g}) ⟩
tabulate g ∎)
where
open ≡-Reasoning
-- Tensor multiplicative composition
-- Transpositions in α correspond to swapping entire rows
-- Transpositions in β correspond to swapping entire columns
_×c_ : ∀ {m₁ n₁ m₂ n₂} → FinVec m₁ m₂ → FinVec n₁ n₂ → FinVec (m₁ * n₁) (m₂ * n₂)
α ×c β = mapV Times.fwd (α ×v β)
-- swap⋆
--
-- This is essentially the classical problem of in-place matrix transpose:
-- "http://en.wikipedia.org/wiki/In-place_matrix_transposition"
-- Given m and n, the desired permutation in Cauchy representation is:
-- P(i) = m*n-1 if i=m*n-1
-- = m*i mod m*n-1 otherwise
-- transposeIndex : {m n : ℕ} → Fin m × Fin n → Fin (n * m)
-- transposeIndex = Times.fwd ∘ swap
-- inject≤ (fromℕ (toℕ d * m + toℕ b)) (i*n+k≤m*n d b)
swap⋆cauchy : (m n : ℕ) → FinVec (n * m) (m * n)
swap⋆cauchy m n = tabulate (Times.swapper m n)
-- mapV transposeIndex (V.tcomp 1C 1C)
-------------------------------------------------------------------------------------------
-- Things which are the foundations of other permutations, but coming
-- from properties, rather than being operators
unite+ : {m : ℕ} → FinVec m (0 + m)
unite+ {m} = tabulate (proj₁ (Plus.unite+ {m}))
uniti+ : {m : ℕ} → FinVec (0 + m) m
uniti+ {m} = tabulate (proj₁ (Plus.uniti+ {m}))
unite+r : {m : ℕ} → FinVec m (m + 0)
unite+r {m} = tabulate (proj₁ (Plus.unite+r {m}))
uniti+r : {m : ℕ} → FinVec (m + 0) m
uniti+r {m} = tabulate (proj₁ (Plus.uniti+r {m}))
assocl+ : {m n o : ℕ} → FinVec ((m + n) + o) (m + (n + o))
assocl+ {m} {n} {o} = tabulate (proj₁ (Plus.assocl+ {m} {n} {o}))
assocr+ : {m n o : ℕ} → FinVec (m + (n + o)) (m + n + o)
assocr+ {m} {n} {o} = tabulate (proj₁ (Plus.assocr+ {m} {n} {o}))
unite* : {m : ℕ} → FinVec m (1 * m)
unite* {m} = tabulate (proj₁ (Times.unite* {m}))
uniti* : {m : ℕ} → FinVec (1 * m) m
uniti* {m} = tabulate (proj₁ (Times.uniti* {m}))
unite*r : {m : ℕ} → FinVec m (m * 1)
unite*r {m} = tabulate (proj₁ (Times.unite*r {m}))
uniti*r : {m : ℕ} → FinVec (m * 1) m
uniti*r {m} = tabulate (proj₁ (Times.uniti*r {m}))
assocl* : {m n o : ℕ} → FinVec ((m * n) * o) (m * (n * o))
assocl* {m} {n} {o} = tabulate (proj₁ (Times.assocl* {m} {n} {o}))
assocr* : {m n o : ℕ} → FinVec (m * (n * o)) (m * n * o)
assocr* {m} {n} {o} = tabulate (proj₁ (Times.assocr* {m} {n} {o}))
dist*+ : ∀ {m n o} → FinVec (m * o + n * o) ((m + n) * o)
dist*+ {m} {n} {o} = tabulate (proj₁ (PlusTimes.dist {m} {n} {o}))
factor*+ : ∀ {m n o} → FinVec ((m + n) * o) (m * o + n * o)
factor*+ {m} {n} {o} = tabulate (proj₁ (PlusTimes.factor {m} {n} {o}))
distl*+ : ∀ {m n o} → FinVec (m * n + m * o) (m * (n + o))
distl*+ {m} {n} {o} = tabulate (proj₁ (PlusTimes.distl {m} {n} {o}))
factorl*+ : ∀ {m n o} → FinVec (m * (n + o)) (m * n + m * o)
factorl*+ {m} {n} {o} = tabulate (proj₁ (PlusTimes.factorl {m} {n} {o}))
right-zero*l : ∀ {m} → FinVec 0 (m * 0)
right-zero*l {m} = tabulate (proj₁ (Times.distzr {m}))
right-zero*r : ∀ {m} → FinVec (m * 0) 0
right-zero*r {m} = tabulate (proj₁ (Times.factorzr {m}))
-------------------------------------------------------------------------------------------
-- Below here, we start with properties
-- Useful stuff
infix 4 _∼p_
_∼p_ : {n m : ℕ} (p₁ p₂ : Vec (Fin m) n) → Set
_∼p_ {n} p₁ p₂ = (i : Fin n) → p₁ !! i ≡ p₂ !! i
∼p⇒≡ : {n : ℕ} {p₁ p₂ : Vec (Fin n) n} → (p₁ ∼p p₂) → p₁ ≡ p₂
∼p⇒≡ {n} {p₁} {p₂} eqv =
begin (
p₁ ≡⟨ sym (tabulate∘lookup p₁) ⟩
tabulate (_!!_ p₁) ≡⟨ finext eqv ⟩
tabulate (_!!_ p₂) ≡⟨ tabulate∘lookup p₂ ⟩
p₂ ∎)
where open ≡-Reasoning
-- note the flip!
∘̂⇒∘ : {m n o : ℕ} → (f : Fin m → Fin n) → (g : Fin n → Fin o) →
tabulate f ∘̂ tabulate g ∼p tabulate (g ∘ f)
∘̂⇒∘ f g i =
begin (
(tabulate f ∘̂ tabulate g) !! i
≡⟨ lookup∘tabulate _ i ⟩
(tabulate g) !! (tabulate f !! i)
≡⟨ lookup∘tabulate _ (tabulate f !! i) ⟩
g (tabulate f !! i)
≡⟨ cong g (lookup∘tabulate f i) ⟩
g (f i)
≡⟨ sym (lookup∘tabulate (g ∘ f) i) ⟩
tabulate (g ∘ f) !! i ∎)
where open ≡-Reasoning
-- this is just tabulate∘lookup, but it hides the details; should this be
-- called 'join' or 'flatten' ?
cauchyext : {m n : ℕ} (π : FinVec m n) → tabulate (_!!_ π) ≡ π
cauchyext π = tabulate∘lookup π
-- we could go through ~p, but this works better in practice
~⇒≡ : {m n : ℕ} {f : Fin m → Fin n} {g : Fin n → Fin m} →
(f ∘ g ∼ id) → (tabulate g ∘̂ tabulate f ≡ 1C)
~⇒≡ {f = f} {g} β = ∼p⇒≡ (λ i → trans (∘̂⇒∘ g f i) (cong (λ x → x !! i) (finext β)))
-- make a permutation from something lower level, directly
-- ~⇒≡ {m} {n = m} {o = m} (p∘!p≡id {p = Plus.unite+ {m}})
-- properties of sequential composition
∘̂-assoc : {m₁ m₂ m₃ m₄ : ℕ} →
(a : Vec (Fin m₂) m₁) (b : Vec (Fin m₃) m₂) (c : Vec (Fin m₄) m₃) →
a ∘̂ (b ∘̂ c) ≡ (a ∘̂ b) ∘̂ c
∘̂-assoc a b c = finext (lookupassoc a b c)
∘̂-rid : {m n : ℕ} → (π : Vec (Fin m) n) → π ∘̂ 1C ≡ π
∘̂-rid π = trans (finext (λ i → lookup-allFin (π !! i))) (cauchyext π)
∘̂-lid : {m n : ℕ} → (π : Vec (Fin m) n) → 1C ∘̂ π ≡ π
∘̂-lid π = trans (finext (λ i → cong (_!!_ π) (lookup-allFin i))) (cauchyext π)
!!⇒∘̂ : {n₁ n₂ n₃ : ℕ} →
(π₁ : Vec (Fin n₁) n₂) → (π₂ : Vec (Fin n₂) n₃) → (i : Fin n₃) →
π₁ !! (π₂ !! i) ≡ (π₂ ∘̂ π₁) !! i
!!⇒∘̂ π₁ π₂ i =
begin (
π₁ !! (π₂ !! i)
≡⟨ sym (lookup∘tabulate (λ j → (π₁ !! (π₂ !! j))) i) ⟩
tabulate (λ i → π₁ !! (π₂ !! i)) !! i
≡⟨ refl ⟩
(π₂ ∘̂ π₁) !! i ∎)
where open ≡-Reasoning
-- properties of sequential composition
0C∘̂0C≡0C : 1C {0} ∘̂ 1C {0} ≡ 1C {0}
0C∘̂0C≡0C = refl
-- properties of parallel composition
-- trivial ones first
1C₀⊎x≡x : ∀ {m n} {x : FinVec m n} → 1C {0} ⊎c x ≡ x
1C₀⊎x≡x {x = x} = cauchyext x
unite+∘[0⊎x]≡x∘unite+ : ∀ {m n} {x : FinVec m n} → unite+ ∘̂ (1C {0} ⊎c x) ≡ x ∘̂ unite+
unite+∘[0⊎x]≡x∘unite+ {m} {n} {x} = finext pf
where
pf : (i : Fin n) → (0C ⊎c x) !! (unite+ !! i) ≡ unite+ !! (x !! i)
pf i =
begin (
tabulate (λ y → x !! y) !! (tabulate id !! i)
≡⟨ cong (λ j → tabulate (λ y → x !! y) !! j) (lookup∘tabulate id i) ⟩
tabulate (λ y → x !! y) !! i
≡⟨ lookup∘tabulate (_!!_ x) i ⟩
x !! i
≡⟨ sym (lookup∘tabulate id (x !! i)) ⟩
tabulate id !! (x !! i) ∎)
uniti+∘x≡[0⊎x]∘uniti+ : ∀ {m n} {x : FinVec m n} →
uniti+ ∘̂ x ≡ (1C {0} ⊎c x) ∘̂ uniti+
uniti+∘x≡[0⊎x]∘uniti+ {m} {n} {x} = finext pf
where
pf : (i : Fin n) → x !! (uniti+ !! i) ≡ uniti+ !! ((0C ⊎c x) !! i)
pf i = begin (
x !! (tabulate id !! i)
≡⟨ cong (_!!_ x) (lookup∘tabulate id i) ⟩
x !! i
≡⟨ sym (lookup∘tabulate (λ y → x !! y) i) ⟩
tabulate (λ y → x !! y) !! i
≡⟨ sym (lookup∘tabulate id _) ⟩
tabulate id !! (tabulate (λ y → x !! y) !! i) ∎)
{-
x⊎1C₀≡x : ∀ {m n} {x : FinVec m n} → x ⊎c (1C {0}) ≡ ?
x⊎1C₀≡x {m} {n} {x = x} =
let e = proj₁ (Plus.unite+) in
let i = proj₁ (Plus.uniti+) in
let eq = sym (+-right-identity m) in
begin (
tabulate (λ j → inject+ 0 (x !! j)) ++V []
≡⟨ cong (λ x → x ++V []) (finext (λ j → inject+0≡uniti+ (x !! j) eq)) ⟩
tabulate (λ j → i (x !! j)) ++V []
≡⟨ tab++[]≡tab∘̂unite+ (λ j → i (x !! j)) (+-right-identity n) ⟩
tabulate (λ j → i (x !! e j))
≡⟨ finext (λ j → sym (lookup∘tabulate (λ k → i (x !! k)) (e j))) ⟩
tabulate (λ j → tabulate (λ k → i (x !! k)) !! (e j))
≡⟨ finext (λ j → cong₂ _!!_
(finext (λ k → sym (lookup∘tabulate i (x !! k))))
(sym (lookup∘tabulate e j))) ⟩
tabulate (λ j →
(tabulate (λ k → tabulate i !! (x !! k))) !! ((tabulate e) !! j))
∎)
where open ≡-Reasoning -}
1C⊎1C≡1C : ∀ {m n} → 1C {m} ⊎c 1C {n} ≡ 1C
1C⊎1C≡1C {m} {n} =
begin (
tabulate {m} (inject+ n ∘ _!!_ 1C) ++V tabulate {n} (raise m ∘ _!!_ 1C)
≡⟨ cong₂ (_++V_ {m = m}) (finext (λ i → cong (inject+ n) (lookup-allFin i)))
(finext (λ i → cong (raise m) (lookup-allFin i))) ⟩
tabulate {m} (inject+ n) ++V tabulate {n} (raise m)
≡⟨ unSplit {m} id ⟩
tabulate {m + n} id ∎)
where open ≡-Reasoning
1C!!i≡i : ∀ {m} {i : Fin m} → 1C {m} !! i ≡ i
1C!!i≡i = lookup∘tabulate id _
unite+∘̂uniti+~id : ∀ {m} → (unite+ {m}) ∘̂ uniti+ ≡ 1C {m}
unite+∘̂uniti+~id {m} = ~⇒≡ {m} {n = m} (p∘!p≡id {p = Plus.unite+ {m}})
uniti+∘̂unite+~id : ∀ {m} → (uniti+ {m}) ∘̂ unite+ ≡ 1C {m}
uniti+∘̂unite+~id {m} = ~⇒≡ {m} {n = m} (p∘!p≡id {p = Plus.uniti+})
unite+r∘̂uniti+r~id : ∀ {m} → (unite+r {m}) ∘̂ uniti+r ≡ 1C {m + 0}
unite+r∘̂uniti+r~id {m} = ~⇒≡ {m} (p∘!p≡id {p = Plus.unite+r {m}})
uniti+r∘̂unite+r~id : ∀ {m} → (uniti+r {m}) ∘̂ unite+r ≡ 1C {m}
uniti+r∘̂unite+r~id {m} = ~⇒≡ (p∘!p≡id {p = Plus.uniti+r})
assocl+∘̂assocr+~id : ∀ {m n o} → assocl+ {m} {n} {o} ∘̂ assocr+ {m} ≡ 1C
assocl+∘̂assocr+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = Plus.assocl+ {m}})
assocr+∘̂assocl+~id : ∀ {m n o} → assocr+ {m} {n} {o} ∘̂ assocl+ {m} ≡ 1C
assocr+∘̂assocl+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = Plus.assocr+ {m}})
swap+-inv : ∀ {m n} → swap+cauchy m n ∘̂ swap+cauchy n m ≡ 1C
swap+-inv {m} {n} = ~⇒≡ (Plus.swap-inv m n)
idˡ⊕ : ∀ {m n} {x : FinVec m n} → uniti+ ∘̂ (1C {0} ⊎c x) ≡ x ∘̂ uniti+
idˡ⊕ {m} {n} {x} = finext pf
where
open ≡-Reasoning
pf : (i : Fin n) → (1C {0} ⊎c x) !! (uniti+ !! i) ≡ (uniti+ !! (x !! i))
pf i = begin (
tabulate (λ y → x !! y) !! (tabulate id !! i)
≡⟨ cong (_!!_ (tabulate λ y → x !! y)) (lookup∘tabulate id i) ⟩
(tabulate (λ y → x !! y)) !! i
≡⟨ lookup∘tabulate (λ y → x !! y) i ⟩
x !! i
≡⟨ sym (lookup∘tabulate id (x !! i)) ⟩
tabulate id !! (x !! i) ∎)
[,]-commute : {A B C D E : Set} → {f : A → C} → {g : B → C} → {h : C → D} →
∀ x → h ([ f , g ]′ x) ≡ [ (h ∘ f) , (h ∘ g) ]′ x
[,]-commute (inj₁ x) = refl
[,]-commute (inj₂ y) = refl
{-
assocl-commute : ∀ {m₁ m₂ m₃ n₁ n₂ n₃} {a : FinVec m₁ n₁} {b : FinVec m₂ n₂}
{c : FinVec m₃ n₃} → assocl+ {n₁} ∘̂ ((a ⊎c b) ⊎c c) ≡ (a ⊎c (b ⊎c c)) ∘̂ assocl+ {m₁}
assocl-commute {m₁} {m₂} {m₃} {n₁} {n₂} {n₃} {a} {b} {c} = begin (
assocl+ {n₁} ∘̂ ((a ⊎c b) ⊎c c)
≡⟨ cong (λ x → assocl+ {n₁} ∘̂ x) (trans (⊎-equiv (a ⊎c b) c) (cong (λ x → x ⊎fv c) (⊎-equiv a b))) ⟩
assocl+ {n₁} ∘̂ ((a ⊎fv b) ⊎fv c)
≡⟨ refl ⟩
tabulate (λ i → ((a ⊎fv b) ⊎fv c) !! (assocl+ {n₁} !! i))
≡⟨ finext pf₁ ⟩
tabulate (λ i → assocl+ {m₁} !! ((a ⊎fv (b ⊎fv c)) !! i) )
≡⟨ refl ⟩
(a ⊎fv (b ⊎fv c)) ∘̂ assocl+ {m₁}
≡⟨ cong (λ x → x ∘̂ assocl+ {m₁}) (sym (trans (cong (λ x → a ⊎c x) (⊎-equiv b c)) (⊎-equiv a (b ⊎fv c)))) ⟩
(a ⊎c (b ⊎c c)) ∘̂ assocl+ {m₁} ∎)
where
pf₁ : ∀ i → ((a ⊎fv b) ⊎fv c) !! (assocl+ {n₁} !! i) ≡ assocl+ {m₁} !! ((a ⊎fv (b ⊎fv c)) !! i)
pf₁ i =
let assoc1 k = proj₁ (Plus.assocl+ {n₁}) k in
let assoc2 k = proj₁ (Plus.assocl+ {m₁} {m₂}) k in
let abc!! = (_!!_ ((a ⊎fv b) ⊎fv c)) in
let a!! = (_!!_ a) in let b!! = (_!!_ b) in let c!! = (_!!_ c) in
let ab!! = (_!!_ (a ⊎fv b)) in
let bc!! = (_!!_ (b ⊎fv c)) in
let iso4 = ((sym≃ (Plus.fwd-iso {n₁})) ● ((path⊎ id≃ (sym≃ Plus.fwd-iso)) ● (TE.assocl₊equiv ● (path⊎ Plus.fwd-iso id≃)))) in
let iso3 = (sym≃ (Plus.fwd-iso {n₁})) ● ((path⊎ id≃ (sym≃ Plus.fwd-iso)) ● (TE.assocl₊equiv)) in
let iso4b = (path⊎ id≃ (sym≃ Plus.fwd-iso) ● ((TE.assocl₊equiv ● path⊎ Plus.fwd-iso id≃) ● Plus.fwd-iso)) in
begin (
((a ⊎fv b) ⊎fv c) !! (assocl+ {n₁} !! i)
≡⟨ cong abc!! (lookup∘tabulate _ i) ⟩
abc!! (assoc1 i)
≡⟨ lookup∘tabulate _ (assoc1 i) ⟩
fwd (map⊎ ab!! c!! (bwd (assoc1 i)))
≡⟨ cong (fwd ∘ map⊎ ab!! c!!) (bwd∘fwd~id (iso4 ⋆ i)) ⟩
fwd (map⊎ ab!! c!! (iso4 ⋆ i))
≡⟨ cong fwd (merge-[,] {h = fwd} {i = id} (iso3 ⋆ i)) ⟩
fwd (map⊎ (ab!! ∘ fwd) c!! (iso3 ⋆ i))
≡⟨ {!!} ⟩
iso4b ⋆ (map⊎ a!! bc!! (bwd i))
≡⟨ sym (cong (λ x → iso4b ⋆ x) (bwd∘fwd~id (map⊎ a!! bc!! (bwd i)))) ⟩
assoc2 (fwd (map⊎ a!! bc!! (bwd i)))
≡⟨ sym (cong assoc2 (lookup∘tabulate _ i)) ⟩
assoc2 ((a ⊎fv (b ⊎fv c)) !! i)
≡⟨ sym (lookup∘tabulate assoc2 _) ⟩
assocl+ {m₁} !! ((a ⊎fv (b ⊎fv c)) !! i) ∎)
-}
-- properties of multiplicative composition
unite*∘̂uniti*~id : ∀ {m} → (unite* {m}) ∘̂ uniti* ≡ 1C {1 * m}
unite*∘̂uniti*~id {m} = ~⇒≡ {m} {n = 1 * m} (p∘!p≡id {p = Times.unite* {m}})
uniti*∘̂unite*~id : ∀ {m} → (uniti* {m}) ∘̂ unite* ≡ 1C {m}
uniti*∘̂unite*~id {m} = ~⇒≡ {1 * m} {n = m} (p∘!p≡id {p = Times.uniti* {m}})
unite*r∘̂uniti*r~id : ∀ {m} → (unite*r {m}) ∘̂ uniti*r ≡ 1C {m * 1}
unite*r∘̂uniti*r~id {m} = ~⇒≡ {m} {n = m * 1} (p∘!p≡id {p = Times.unite*r {m}})
uniti*r∘̂unite*r~id : ∀ {m} → (uniti*r {m}) ∘̂ unite*r ≡ 1C {m}
uniti*r∘̂unite*r~id {m} = ~⇒≡ {m * 1} {n = m} (p∘!p≡id {p = Times.uniti*r {m}})
assocl*∘̂assocr*~id : ∀ {m n o} → assocl* {m} {n} {o} ∘̂ assocr* {m} ≡ 1C
assocl*∘̂assocr*~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = Times.assocl* {m}})
assocr*∘̂assocl*~id : ∀ {m n o} → assocr* {m} {n} {o} ∘̂ assocl* {m} ≡ 1C
assocr*∘̂assocl*~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = Times.assocr* {m}})
dist*+∘̂factor*+~id : ∀ {m n o} → dist*+ {m} {n} {o} ∘̂ factor*+ {m} ≡ 1C
dist*+∘̂factor*+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = PlusTimes.dist {m}})
factor*+∘̂dist*+~id : ∀ {m n o} → factor*+ {m} {n} {o} ∘̂ dist*+ {m} ≡ 1C
factor*+∘̂dist*+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = PlusTimes.factor {m}})
distl*+∘̂factorl*+~id : ∀ {m n o} → distl*+ {m} {n} {o} ∘̂ factorl*+ {m} ≡ 1C
distl*+∘̂factorl*+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = PlusTimes.distl {m}})
factorl*+∘̂distl*+~id : ∀ {m n o} → factorl*+ {m} {n} {o} ∘̂ distl*+ {m} ≡ 1C
factorl*+∘̂distl*+~id {m} {_} {o} = ~⇒≡ (p∘!p≡id {p = PlusTimes.factorl {m}})
right-zero*l∘̂right-zero*r~id : ∀ {m} → right-zero*l {m} ∘̂ right-zero*r {m} ≡ 1C {m * 0}
right-zero*l∘̂right-zero*r~id {m} = ~⇒≡ {f = proj₁ (Times.factorzr {m})} (p∘!p≡id {p = Times.distzr {m}})
right-zero*r∘̂right-zero*l~id : ∀ {m} → right-zero*r {m} ∘̂ right-zero*l {m} ≡ 1C
right-zero*r∘̂right-zero*l~id {m} = ~⇒≡ { f = proj₁ (Times.factorz {m})} (p∘!p≡id {p = Times.distz {m}})
private
left⊎⊎!! : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → (p₁ : FinVec m₁ n₁) → (p₂ : FinVec m₂ n₂)
→ (p₃ : FinVec m₃ m₁) → (p₄ : FinVec m₄ m₂) → (i : Fin n₁) →
(p₃ ⊎c p₄) !! ( (p₁ ⊎c p₂) !! inject+ n₂ i ) ≡ inject+ m₄ ( (p₁ ∘̂ p₃) !! i)
left⊎⊎!! {m₁} {m₂} {_} {m₄} {_} {n₂} p₁ p₂ p₃ p₄ i =
let pp = p₃ ⊎c p₄ in
let qq = p₁ ⊎c p₂ in
begin (
pp !! (qq !! inject+ n₂ i)
≡⟨ cong
(_!!_ pp)
(lookup-++-inject+
(tabulate (inject+ m₂ ∘ _!!_ p₁))
(tabulate (raise m₁ ∘ _!!_ p₂))
i) ⟩
pp !! (tabulate (inject+ m₂ ∘ _!!_ p₁ ) !! i)
≡⟨ cong (_!!_ pp) (lookup∘tabulate _ i) ⟩
pp !! (inject+ m₂ (p₁ !! i))
≡⟨ left!! (p₁ !! i) (inject+ m₄ ∘ (_!!_ p₃)) ⟩
inject+ m₄ (p₃ !! (p₁ !! i))
≡⟨ cong (inject+ m₄) (sym (lookup∘tabulate _ i)) ⟩
inject+ m₄ ((p₁ ∘̂ p₃) !! i) ∎ )
right⊎⊎!! : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → (p₁ : FinVec m₁ n₁) → (p₂ : FinVec m₂ n₂)
→ (p₃ : FinVec m₃ m₁) → (p₄ : FinVec m₄ m₂) → (i : Fin n₂) →
(p₃ ⊎c p₄) !! ( (p₁ ⊎c p₂) !! raise n₁ i ) ≡ raise m₃ ( (p₂ ∘̂ p₄) !! i)
right⊎⊎!! {m₁} {m₂} {m₃} {_} {n₁} {_} p₁ p₂ p₃ p₄ i =
let pp = p₃ ⊎c p₄ in
let qq = p₁ ⊎c p₂ in
begin (
pp !! (qq !! raise n₁ i)
≡⟨ cong
(_!!_ pp)
(lookup-++-raise
(tabulate (inject+ m₂ ∘ _!!_ p₁))
(tabulate (raise m₁ ∘ _!!_ p₂))
i) ⟩
pp !! (tabulate (raise m₁ ∘ _!!_ p₂) !! i)
≡⟨ cong (_!!_ pp) (lookup∘tabulate _ i) ⟩
pp !! raise m₁ (p₂ !! i)
≡⟨ right!! {m₁} (p₂ !! i) (raise m₃ ∘ (_!!_ p₄)) ⟩
raise m₃ (p₄ !! (p₂ !! i))
≡⟨ cong (raise m₃) (sym (lookup∘tabulate _ i)) ⟩
raise m₃ ((p₂ ∘̂ p₄) !! i) ∎ )
⊎c-distrib : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → {p₁ : FinVec m₁ n₁} → {p₂ : FinVec m₂ n₂}
→ {p₃ : FinVec m₃ m₁} → {p₄ : FinVec m₄ m₂} →
(p₁ ⊎c p₂) ∘̂ (p₃ ⊎c p₄) ≡ (p₁ ∘̂ p₃) ⊎c (p₂ ∘̂ p₄)
⊎c-distrib {m₁} {m₂} {m₃} {m₄} {n₁} {n₂} {p₁} {p₂} {p₃} {p₄} =
let p₃₄ = p₃ ⊎c p₄ in let p₁₂ = p₁ ⊎c p₂ in
let lhs = λ i → p₃₄ !! (p₁₂ !! i) in
begin (
tabulate lhs
≡⟨ tabulate-split {n₁} {n₂} ⟩
tabulate {n₁} (lhs ∘ inject+ n₂) ++V tabulate {n₂} (lhs ∘ raise n₁)
≡⟨ cong₂ _++V_ (finext (left⊎⊎!! p₁ _ _ _)) (finext (right⊎⊎!! p₁ _ _ _)) ⟩
tabulate {n₁} (λ i → inject+ m₄ ((p₁ ∘̂ p₃) !! i)) ++V
tabulate {n₂} (λ i → raise m₃ ((p₂ ∘̂ p₄) !! i))
≡⟨ refl ⟩
(p₁ ∘̂ p₃) ⊎c (p₂ ∘̂ p₄) ∎)
------------------------------------------------------------------------------
-- properties of ×c
private
concat!! : {A : Set} {m n : ℕ} → (a : Fin m) → (b : Fin n) → (xss : Vec (Vec A n) m) →
concatV xss !! (Times.fwd (a ,′ b)) ≡ (xss !! a) !! b
concat!! zero b (xs ∷ xss) = lookup-++-inject+ xs (concatV xss) b
concat!! (suc a) b (xs ∷ xss) =
trans (lookup-++-raise xs (concatV xss) (Times.fwd (a ,′ b))) (concat!! a b xss)
×c-equiv : {m₁ m₂ n₁ n₂ : ℕ} (p₁ : FinVec m₁ n₁) (p₂ : FinVec m₂ n₂) →
(p₁ ×c p₂) ≡ concatV (mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂)) p₁)
×c-equiv p₁ p₂ =
let zss = mapV (λ b → mapV (λ x → b ,′ x) p₂) p₁ in
begin (
(p₁ ×c p₂)
≡⟨ refl ⟩
mapV Times.fwd (concatV zss)
≡⟨ sym (concat-map zss Times.fwd) ⟩
concatV (mapV (mapV Times.fwd) zss)
≡⟨ cong concatV (map-map-map Times.fwd (λ b → mapV (λ x → b ,′ x) p₂) p₁) ⟩
concatV (mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂)) p₁) ∎)
lookup-2d : {A : Set} (m n : ℕ) → (k : Fin (m * n)) → {f : Fin m × Fin n → A} →
concatV (tabulate {m} (λ i → tabulate {n} (λ j → f (i ,′ j)))) !! k ≡ f (Times.bwd k)
lookup-2d m n k {f} =
let lhs = concatV (tabulate {m} (λ i → tabulate {n} (λ j → f (i ,′ j)))) in
let a = proj₁ (Times.bwd {m} {n} k) in
let b = proj₂ (Times.bwd {m} {n} k) in
begin (
lhs !! k
≡⟨ cong (_!!_ lhs) (sym (Times.fwd∘bwd~id {m} k)) ⟩
lhs !! (Times.fwd (a ,′ b))
≡⟨ concat!! a b _ ⟩
(tabulate {m} (λ i → tabulate {n} (λ j → f (i ,′ j))) !! a) !! b
≡⟨ cong (λ x → x !! b) (lookup∘tabulate _ a) ⟩
tabulate {n} (λ j → f (a ,′ j)) !! b
≡⟨ lookup∘tabulate _ b ⟩
f (a ,′ b)
≡⟨ refl ⟩
f (Times.bwd k) ∎)
×c!! : {m₁ m₂ n₁ n₂ : ℕ} (p₁ : FinVec m₁ n₁) (p₂ : FinVec m₂ n₂) (k : Fin (n₁ * n₂)) →
(p₁ ×c p₂) !! k ≡ Times.fwd (p₁ !! proj₁ (Times.bwd k) ,′ p₂ !! proj₂ (Times.bwd {n₁} k))
×c!! {n₁ = n₁} p₁ p₂ k =
let a = proj₁ (Times.bwd {n₁} k) in
let b = proj₂ (Times.bwd {n₁} k) in
begin (
(p₁ ×c p₂) !! k
≡⟨ cong₂ _!!_ (×c-equiv p₁ p₂) (sym (Times.fwd∘bwd~id {n₁} k)) ⟩
concatV (mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂)) p₁) !! Times.fwd (a ,′ b)
≡⟨ concat!! a b _ ⟩
((mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂)) p₁) !! a) !! b
≡⟨ cong (λ x → x !! b) (lookup-map a _ p₁) ⟩
mapV Times.fwd (mapV (λ x → p₁ !! a ,′ x) p₂) !! b
≡⟨ cong (λ x → x !! b) (sym (map-∘ Times.fwd _ p₂)) ⟩
mapV (Times.fwd ∘ (λ x → p₁ !! a ,′ x)) p₂ !! b
≡⟨ lookup-map b _ p₂ ⟩
Times.fwd (p₁ !! a ,′ p₂ !! b) ∎)
×c-distrib : ∀ {m₁ m₂ m₃ m₄ n₁ n₂} → {p₁ : FinVec m₁ n₁} → {p₂ : FinVec m₂ n₂}
→ {p₃ : FinVec m₃ m₁} → {p₄ : FinVec m₄ m₂} →
(p₁ ×c p₂) ∘̂ (p₃ ×c p₄) ≡ (p₁ ∘̂ p₃) ×c (p₂ ∘̂ p₄)
×c-distrib {m₁} {m₂} {m₃} {m₄} {n₁} {n₂} {p₁} {p₂} {p₃} {p₄} =
let p₃₄ = p₃ ×c p₄ in let p₁₂ = p₁ ×c p₂ in
let p₂₄ = p₂ ∘̂ p₄ in let p₁₃ = p₁ ∘̂ p₃ in
let lhs = λ i → p₃₄ !! (p₁₂ !! i) in
let zss = mapV (λ b → mapV (λ x → b ,′ x) (p₂ ∘̂ p₄)) (p₁ ∘̂ p₃) in
begin (
tabulate {n₁ * n₂} (λ i → p₃₄ !! (p₁₂ !! i))
≡⟨ finext (λ j → cong (_!!_ p₃₄) (×c!! p₁ p₂ j)) ⟩
tabulate {n₁ * n₂}
(λ i → p₃₄ !! Times.fwd (p₁ !! proj₁ (Times.bwd i) ,′ p₂ !! proj₂ (Times.bwd i)))
≡⟨ finext (λ j → ×c!! p₃ p₄ _) ⟩
tabulate (λ i →
let k = Times.fwd (p₁ !! proj₁ (Times.bwd i) ,′ p₂ !! proj₂ (Times.bwd i)) in
Times.fwd (p₃ !! proj₁ (Times.bwd k) ,′ p₄ !! proj₂ (Times.bwd k)))
≡⟨ finext (λ i → cong₂ (λ x y → Times.fwd (p₃ !! proj₁ x ,′ p₄ !! proj₂ y))
(Times.bwd∘fwd~id {m₁} {m₂} (p₁ !! proj₁ (Times.bwd i) ,′ _))
(Times.bwd∘fwd~id (_ ,′ p₂ !! proj₂ (Times.bwd i)))) ⟩
tabulate (λ i → Times.fwd (p₃ !! (p₁ !! proj₁ (Times.bwd i)) ,′
(p₄ !! (p₂ !! proj₂ (Times.bwd i)))))
≡⟨ finext (λ k → sym (lookup-2d n₁ n₂ k)) ⟩
tabulate (λ k →
concatV (tabulate {n₁} (λ z →
tabulate {n₂} (λ w →
Times.fwd ((p₃ !! (p₁ !! z)) ,′ (p₄ !! (p₂ !! w))))))
!! k)
≡⟨ tabulate∘lookup _ ⟩
concatV (tabulate {n₁} (λ z →
tabulate {n₂} (λ w →
Times.fwd ((p₃ !! (p₁ !! z)) ,′ (p₄ !! (p₂ !! w))))))
≡⟨ cong
concatV
(finext (λ i →
tabulate-∘ Times.fwd (λ w → ((p₃ !! (p₁ !! i)) ,′ (p₄ !! (p₂ !! w)))) )) ⟩
concatV (tabulate (λ z →
mapV Times.fwd (tabulate (λ w → (p₃ !! (p₁ !! z)) ,′ (p₄ !! (p₂ !! w))))))
≡⟨ cong
concatV
(finext (λ i →
cong
(mapV Times.fwd)
(tabulate-∘ (λ x → (p₃ !! (p₁ !! i)) ,′ x) (_!!_ p₄ ∘ _!!_ p₂)))) ⟩
concatV (tabulate (λ z → mapV Times.fwd (mapV (λ x → (p₃ !! (p₁ !! z)) ,′ x) p₂₄)))
≡⟨ cong concatV (tabulate-∘ _ (_!!_ p₃ ∘ _!!_ p₁)) ⟩
concatV (mapV (λ y → mapV Times.fwd (mapV (λ x → y ,′ x) p₂₄)) p₁₃)
≡⟨ sym (×c-equiv p₁₃ p₂₄) ⟩
(p₁ ∘̂ p₃) ×c (p₂ ∘̂ p₄) ∎)
-- there might be a simpler proofs of this using tablate∘lookup right
-- at the start.
1C×1C≡1C : ∀ {m n} → (1C {m} ×c 1C {n}) ≡ 1C {m * n}
1C×1C≡1C {m} {n} =
begin (
1C {m} ×c 1C
≡⟨ ×c-equiv 1C 1C ⟩
concatV (mapV (λ y → mapV Times.fwd (mapV (_,′_ y) (1C {n}))) (1C {m}))
≡⟨ cong (concatV {n = m}) (sym (tabulate-∘ _ id)) ⟩
concatV {n = m} (tabulate (λ y → mapV Times.fwd (mapV (_,′_ y) (1C {n}))))
≡⟨ cong (concatV {n = m}) (finext (λ y → sym (map-∘ Times.fwd (λ x → y ,′ x) 1C))) ⟩
concatV (tabulate {n = m} (λ y → mapV (Times.fwd ∘ (_,′_ y)) (1C {n})))
≡⟨ cong
(concatV {m = n} {m})
(finext (λ y → sym (tabulate-∘ (Times.fwd ∘ (_,′_ y)) id))) ⟩
concatV (tabulate {n = m} (λ a → tabulate {n = n} (λ b → Times.fwd (a ,′ b))))
≡⟨ sym (tabulate∘lookup _) ⟩
tabulate (λ k →
concatV (tabulate {n = m} (λ a → tabulate {n = n} (λ b → Times.fwd (a ,′ b)))) !! k)
≡⟨ finext (λ k → lookup-2d m n k) ⟩
tabulate (λ k → Times.fwd {m} {n} (Times.bwd k))
≡⟨ finext (Times.fwd∘bwd~id {m} {n}) ⟩
1C {m * n} ∎ )
swap*-inv : ∀ {m n} → swap⋆cauchy m n ∘̂ swap⋆cauchy n m ≡ 1C
swap*-inv {m} {n} = ~⇒≡ (Times.swap-inv m n)
------------------------
-- A few "reveal" functions, to let us peek into the representation
reveal1C : ∀ {m} → allFin m ≡ 1C
reveal1C = refl
reveal0C : [] ≡ 1C {0}
reveal0C = refl
reveal⊎c : ∀ {m₁ n₁ m₂ n₂} → {α : FinVec m₁ m₂} → {β : FinVec n₁ n₂} →
α ⊎c β ≡
tabulate (fwd ∘ inj₁ ∘ _!!_ α) ++V
tabulate (fwd {m₁} ∘ inj₂ ∘ _!!_ β)
reveal⊎c = refl
------------------------------------------------------------------------------
-- Commutative semiring structure
open F
_cauchy≃_ : (m n : ℕ) → Set
m cauchy≃ n = FinVec m n
id-iso : {m : ℕ} → FinVec m m
id-iso = 1C
private
postulate sym-iso : {m n : ℕ} → FinVec m n → FinVec n m
trans-iso : {m n o : ℕ} → FinVec m n → FinVec n o → FinVec m o
trans-iso c₁ c₂ = c₂ ∘̂ c₁
cauchy≃IsEquiv : IsEquivalence {Level.zero} {Level.zero} {ℕ} _cauchy≃_
cauchy≃IsEquiv = record {
refl = id-iso ;
sym = sym-iso ;
trans = trans-iso
}
cauchyPlusIsSG : IsSemigroup {Level.zero} {Level.zero} {ℕ} _cauchy≃_ _+_
cauchyPlusIsSG = record {
isEquivalence = cauchy≃IsEquiv ;
assoc = λ m n o → assocl+ {m} {n} {o} ;
∙-cong = _⊎c_
}
cauchyTimesIsSG : IsSemigroup {Level.zero} {Level.zero} {ℕ} _cauchy≃_ _*_
cauchyTimesIsSG = record {
isEquivalence = cauchy≃IsEquiv ;
assoc = λ m n o → assocl* {m} {n} {o} ;
∙-cong = _×c_
}
cauchyPlusIsCM : IsCommutativeMonoid _cauchy≃_ _+_ 0
cauchyPlusIsCM = record {
isSemigroup = cauchyPlusIsSG ;
identityˡ = λ m → 1C ;
comm = λ m n → swap+cauchy n m
}
cauchyTimesIsCM : IsCommutativeMonoid _cauchy≃_ _*_ 1
cauchyTimesIsCM = record {
isSemigroup = cauchyTimesIsSG ;
identityˡ = λ m → uniti* {m} ;
comm = λ m n → swap⋆cauchy n m
}
cauchyIsCSR : IsCommutativeSemiring _cauchy≃_ _+_ _*_ 0 1
cauchyIsCSR = record {
+-isCommutativeMonoid = cauchyPlusIsCM ;
*-isCommutativeMonoid = cauchyTimesIsCM ;
distribʳ = λ o m n → factor*+ {m} {n} {o} ;
zeroˡ = λ m → 0C
}
cauchyCSR : CommutativeSemiring Level.zero Level.zero
cauchyCSR = record {
Carrier = ℕ ;
_≈_ = _cauchy≃_ ;
_+_ = _+_ ;
_*_ = _*_ ;
0# = 0 ;
1# = 1 ;
isCommutativeSemiring = cauchyIsCSR
}
------------------------------------------------------------------------------
-- Groupoid structure
private
postulate linv : {m n : ℕ} (c : FinVec m n) → (sym-iso c) ∘̂ c ≡ 1C
postulate rinv : {m n : ℕ} (c : FinVec m n) → c ∘̂ (sym-iso c) ≡ 1C
G : 1Groupoid
G = record {
set = ℕ ;
_↝_ = _cauchy≃_ ;
_≈_ = _≡_ ;
id = id-iso ;
_∘_ = λ c₁ c₂ → trans-iso c₂ c₁ ;
_⁻¹ = sym-iso ;
lneutr = ∘̂-lid ;
rneutr = ∘̂-rid ;
assoc = λ c₁ c₂ c₃ → sym (∘̂-assoc c₁ c₂ c₃) ;
equiv = record {
refl = refl ;
sym = sym ;
trans = trans
} ;
linv = linv ;
rinv = rinv ;
∘-resp-≈ = cong₂ _∘̂_
}
{--
-- Move to its own spot later
merge-[,] : {A B C D E : Set} → {h : A → C} → {i : B → D} → {f : C → E}
→ {g : D → E} → (x : A ⊎ B) →
[ f , g ]′ ( map⊎ h i x ) ≡ [ (f ∘ h) , (g ∘ i) ]′ x
merge-[,] (inj₁ x) = refl
merge-[,] (inj₂ y) = refl
--}
|
{
"alphanum_fraction": 0.4626393889,
"avg_line_length": 40.7720763723,
"ext": "agda",
"hexsha": "a2d11240dff3cac802b2dfcf597ad0b83530c82e",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Obsolete/FinVec.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/FinVec.agda",
"max_line_length": 135,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Obsolete/FinVec.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": 15083,
"size": 34167
}
|
------------------------------------------------------------------------
-- Equivalences
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- Partly based on Voevodsky's work on so-called univalent
-- foundations.
open import Equality
module Equivalence
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq as Bijection using (_↔_)
open Derived-definitions-and-properties eq
open import Equality.Decidable-UIP eq using (propositional-identity⇒set)
import Equivalence.Half-adjoint eq as HA
open import Groupoid eq
open import H-level eq as H-level
open import H-level.Closure eq
open import Injection eq using (_↣_; Injective)
open import Logical-equivalence as L-eq using (_⇔_)
open import Nat eq
open import Preimage eq as Preimage using (_⁻¹_)
open import Prelude as P hiding (id) renaming (_∘_ to _⊚_)
open import Surjection eq as Surjection using (_↠_)
------------------------------------------------------------------------
-- Is-equivalence
open HA public using
(Is-equivalence;
propositional;
sometimes-contractible;
respects-extensional-equality;
function-between-contractible-types-is-equivalence;
drop-Σ-map-id;
inverse-drop-Σ-map-id;
ext⁻¹-is-equivalence)
------------------------------------------------------------------------
-- _≃_
private
module Dummy where
-- Equivalences.
infix 4 _≃_
record _≃_ {a b} (A : Type a) (B : Type b) : Type (a ⊔ b) where
constructor ⟨_,_⟩
field
to : A → B
is-equivalence : Is-equivalence to
open Dummy public using (_≃_; ⟨_,_⟩) hiding (module _≃_)
-- Some definitions with erased type arguments.
module _≃₀_ {a b} {@0 A : Type a} {@0 B : Type b} (A≃B : A ≃ B) where
-- The forward direction of the equivalence.
to : A → B
to = Dummy._≃_.to A≃B
-- The function to is an equivalence.
is-equivalence : Is-equivalence to
is-equivalence = Dummy._≃_.is-equivalence A≃B
-- Equivalent types are isomorphic.
from : B → A
from = HA.inverse is-equivalence
right-inverse-of : ∀ x → to (from x) ≡ x
right-inverse-of = HA.right-inverse-of is-equivalence
left-inverse-of : ∀ x → from (to x) ≡ x
left-inverse-of = HA.left-inverse-of is-equivalence
bijection : A ↔ B
bijection = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = right-inverse-of
}
; left-inverse-of = left-inverse-of
}
module _≃_ {a b} {A : Type a} {B : Type b} (A≃B : A ≃ B) where
open _≃₀_ A≃B public
open _↔_ bijection public
hiding (from; to; right-inverse-of; left-inverse-of)
-- All preimages of an element under the equivalence are equal.
irrelevance : ∀ y (p : to ⁻¹ y) → (from y , right-inverse-of y) ≡ p
irrelevance = HA.irrelevance is-equivalence
-- The two proofs left-inverse-of and right-inverse-of are
-- related.
left-right-lemma :
∀ x → cong to (left-inverse-of x) ≡ right-inverse-of (to x)
left-right-lemma = proj₂ (proj₂ (proj₂ is-equivalence))
right-left-lemma :
∀ x → cong from (right-inverse-of x) ≡ left-inverse-of (from x)
right-left-lemma =
proj₂ (proj₂ (proj₂ (HA.inverse-equivalence is-equivalence)))
-- Equivalences are isomorphic to pairs.
≃-as-Σ : ∀ {a b} {A : Type a} {B : Type b} →
A ≃ B ↔ ∃ λ (f : A → B) → Is-equivalence f
≃-as-Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { ⟨ f , is ⟩ → f , is }
; from = uncurry ⟨_,_⟩
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Bijections are equivalences.
--
-- Note that the right inverse proof is preserved unchanged.
↔⇒≃ : ∀ {a b} {A : Type a} {B : Type b} → A ↔ B → A ≃ B
↔⇒≃ A↔B = record
{ to = _↔_.to A↔B
; is-equivalence = HA.↔→Is-equivalenceʳ A↔B
}
_ :
∀ {a b} {A : Type a} {B : Type b} {A↔B : A ↔ B} →
_≃_.right-inverse-of (↔⇒≃ A↔B) ≡ _↔_.right-inverse-of A↔B
_ = refl _
-- A variant of the previous result.
--
-- Note that the right inverse proof is preserved unchanged.
↔→≃ :
∀ {a b} {A : Type a} {B : Type b} →
(f : A → B) (g : B → A) →
(∀ x → f (g x) ≡ x) →
(∀ x → g (f x) ≡ x) →
A ≃ B
↔→≃ f g f∘g g∘f = ↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = f
; from = g
}
; right-inverse-of = f∘g
}
; left-inverse-of = g∘f
})
_ :
∀ {a b} {A : Type a} {B : Type b} {f : A → B} {g : B → A}
{f-g : ∀ x → f (g x) ≡ x} {g-f : ∀ x → g (f x) ≡ x} →
_≃_.right-inverse-of (↔→≃ f g f-g g-f) ≡ f-g
_ = refl _
-- There is a logical equivalence between A ↔ B and A ≃ B.
↔⇔≃ :
∀ {a b} {A : Type a} {B : Type b} →
(A ↔ B) ⇔ (A ≃ B)
↔⇔≃ = record
{ to = ↔⇒≃
; from = _≃_.bijection
}
-- The function subst is an equivalence family.
subst-as-equivalence :
∀ {a p} {A : Type a} (P : A → Type p) {x y : A} (x≡y : x ≡ y) →
P x ≃ P y
subst-as-equivalence P {y = y} x≡y = ↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = subst P x≡y
; from = subst P (sym x≡y)
}
; right-inverse-of = subst-subst-sym P x≡y
}
; left-inverse-of = λ p →
subst P (sym x≡y) (subst P x≡y p) ≡⟨ cong (λ eq → subst P (sym x≡y) (subst P eq _)) $ sym $ sym-sym _ ⟩
subst P (sym x≡y) (subst P (sym (sym x≡y)) p) ≡⟨ subst-subst-sym P _ _ ⟩∎
p ∎
})
abstract
subst-is-equivalence :
∀ {a p} {A : Type a} (P : A → Type p) {x y : A} (x≡y : x ≡ y) →
Is-equivalence (subst P x≡y)
subst-is-equivalence P x≡y =
_≃_.is-equivalence (subst-as-equivalence P x≡y)
------------------------------------------------------------------------
-- Equivalence
-- Equivalences are equivalence relations.
id : ∀ {a} {A : Type a} → A ≃ A
id = ⟨ P.id , HA.id-equivalence ⟩
inverse : ∀ {a b} {A : Type a} {B : Type b} → A ≃ B → B ≃ A
inverse A≃B =
⟨ HA.inverse (_≃_.is-equivalence A≃B)
, HA.inverse-equivalence (_≃_.is-equivalence A≃B)
⟩
infixr 9 _∘_
_∘_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
B ≃ C → A ≃ B → A ≃ C
f ∘ g =
⟨ _≃_.to f ⊚ _≃_.to g
, HA.composition-equivalence
(_≃_.is-equivalence f)
(_≃_.is-equivalence g)
⟩
-- Equational reasoning combinators.
infix -1 finally-≃
infixr -2 step-≃
-- For an explanation of why step-≃ is defined in this way, see
-- Equality.step-≡.
step-≃ : ∀ {a b c} (A : Type a) {B : Type b} {C : Type c} →
B ≃ C → A ≃ B → A ≃ C
step-≃ _ = _∘_
syntax step-≃ A B≃C A≃B = A ≃⟨ A≃B ⟩ B≃C
finally-≃ : ∀ {a b} (A : Type a) (B : Type b) → A ≃ B → A ≃ B
finally-≃ _ _ A≃B = A≃B
syntax finally-≃ A B A≃B = A ≃⟨ A≃B ⟩□ B □
-- Some simplification lemmas.
right-inverse-of-id :
∀ {a} {A : Type a} {x : A} →
_≃_.right-inverse-of id x ≡ refl x
right-inverse-of-id {x = x} = refl (refl x)
left-inverse-of-id :
∀ {a} {A : Type a} {x : A} →
_≃_.left-inverse-of id x ≡ refl x
left-inverse-of-id {x = x} = refl (refl x)
right-inverse-of∘inverse :
∀ {a b} {A : Type a} {B : Type b} →
∀ (A≃B : A ≃ B) {x} →
_≃_.right-inverse-of (inverse A≃B) x ≡
_≃_.left-inverse-of A≃B x
right-inverse-of∘inverse _ = refl _
left-inverse-of∘inverse :
∀ {a b} {A : Type a} {B : Type b} →
∀ (A≃B : A ≃ B) {x} →
_≃_.left-inverse-of (inverse A≃B) x ≡
_≃_.right-inverse-of A≃B x
left-inverse-of∘inverse _ = refl _
------------------------------------------------------------------------
-- One can replace either of the functions with an extensionally equal
-- function
with-other-function :
∀ {a b} {A : Type a} {B : Type b}
(A≃B : A ≃ B) (f : A → B) →
(∀ x → _≃_.to A≃B x ≡ f x) →
A ≃ B
with-other-function ⟨ g , is-equivalence ⟩ f g≡f =
⟨ f , respects-extensional-equality g≡f is-equivalence ⟩
with-other-inverse :
∀ {a b} {A : Type a} {B : Type b}
(A≃B : A ≃ B) (f : B → A) →
(∀ x → _≃_.from A≃B x ≡ f x) →
A ≃ B
with-other-inverse A≃B f from≡f =
inverse $ with-other-function (inverse A≃B) f from≡f
private
-- The two functions above compute in the right way.
to∘with-other-function :
∀ {a b} {A : Type a} {B : Type b}
(A≃B : A ≃ B) (f : A → B)
(to≡f : ∀ x → _≃_.to A≃B x ≡ f x) →
_≃_.to (with-other-function A≃B f to≡f) ≡ f
to∘with-other-function _ _ _ = refl _
from∘with-other-function :
∀ {a b} {A : Type a} {B : Type b}
(A≃B : A ≃ B) (f : A → B)
(to≡f : ∀ x → _≃_.to A≃B x ≡ f x) →
_≃_.from (with-other-function A≃B f to≡f) ≡ _≃_.from A≃B
from∘with-other-function _ _ _ = refl _
to∘with-other-inverse :
∀ {a b} {A : Type a} {B : Type b}
(A≃B : A ≃ B) (g : B → A)
(from≡g : ∀ x → _≃_.from A≃B x ≡ g x) →
_≃_.to (with-other-inverse A≃B g from≡g) ≡ _≃_.to A≃B
to∘with-other-inverse _ _ _ = refl _
from∘with-other-inverse :
∀ {a b} {A : Type a} {B : Type b}
(A≃B : A ≃ B) (g : B → A)
(from≡g : ∀ x → _≃_.from A≃B x ≡ g x) →
_≃_.from (with-other-inverse A≃B g from≡g) ≡ g
from∘with-other-inverse _ _ _ = refl _
------------------------------------------------------------------------
-- The two-out-of-three property
-- If two out of three of f, g and g ∘ f are equivalences, then the
-- third one is also an equivalence.
record Two-out-of-three
{a b c} {A : Type a} {B : Type b} {C : Type c}
(f : A → B) (g : B → C) : Type (a ⊔ b ⊔ c) where
field
f-g : Is-equivalence f → Is-equivalence g → Is-equivalence (g ⊚ f)
g-g∘f : Is-equivalence g → Is-equivalence (g ⊚ f) → Is-equivalence f
g∘f-f : Is-equivalence (g ⊚ f) → Is-equivalence f → Is-equivalence g
two-out-of-three :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c}
(f : A → B) (g : B → C) → Two-out-of-three f g
two-out-of-three f g = record
{ f-g = λ f-eq g-eq →
_≃_.is-equivalence (⟨ g , g-eq ⟩ ∘ ⟨ f , f-eq ⟩)
; g-g∘f = λ g-eq g∘f-eq →
respects-extensional-equality
(λ x → let g⁻¹ = _≃_.from ⟨ g , g-eq ⟩ in
g⁻¹ (g (f x)) ≡⟨ _≃_.left-inverse-of ⟨ g , g-eq ⟩ (f x) ⟩∎
f x ∎)
(_≃_.is-equivalence
(inverse ⟨ g , g-eq ⟩ ∘ ⟨ _ , g∘f-eq ⟩))
; g∘f-f = λ g∘f-eq f-eq →
respects-extensional-equality
(λ x → let f⁻¹ = _≃_.from ⟨ f , f-eq ⟩ in
g (f (f⁻¹ x)) ≡⟨ cong g (_≃_.right-inverse-of ⟨ f , f-eq ⟩ x) ⟩∎
g x ∎)
(_≃_.is-equivalence
(⟨ _ , g∘f-eq ⟩ ∘ inverse ⟨ f , f-eq ⟩))
}
------------------------------------------------------------------------
-- Extensionality
-- f ≡ g and ∀ x → f x ≡ g x are isomorphic (assuming extensionality).
extensionality-isomorphism :
∀ {a b} →
Extensionality a b →
{A : Type a} {B : A → Type b} {f g : (x : A) → B x} →
(∀ x → f x ≡ g x) ≃ (f ≡ g)
extensionality-isomorphism ext =
inverse ⟨ _ , ext⁻¹-is-equivalence (apply-ext ext) ⟩
-- Note that the isomorphism gives us a really well-behaved notion of
-- extensionality.
good-ext : ∀ {a b} → Extensionality a b → Extensionality a b
apply-ext (good-ext ext) = _≃_.to (extensionality-isomorphism ext)
abstract
good-ext-is-equivalence :
∀ {a b} (ext : Extensionality a b) →
{A : Type a} {B : A → Type b} {f g : (x : A) → B x} →
Is-equivalence {A = ∀ x → f x ≡ g x} (apply-ext (good-ext ext))
good-ext-is-equivalence ext =
_≃_.is-equivalence (extensionality-isomorphism ext)
good-ext-refl :
∀ {a b} (ext : Extensionality a b)
{A : Type a} {B : A → Type b} (f : (x : A) → B x) →
apply-ext (good-ext ext) (λ x → refl (f x)) ≡ refl f
good-ext-refl ext f =
_≃_.to (extensionality-isomorphism ext) (λ x → refl (f x)) ≡⟨ cong (_≃_.to (extensionality-isomorphism ext)) $ sym $
apply-ext ext (λ _ → ext⁻¹-refl f) ⟩
_≃_.to (extensionality-isomorphism ext) (ext⁻¹ (refl f)) ≡⟨ _≃_.right-inverse-of (extensionality-isomorphism ext) _ ⟩∎
refl f ∎
good-ext-const :
∀ {a b} (ext : Extensionality a b)
{A : Type a} {B : Type b} {x y : B}
(x≡y : x ≡ y) →
apply-ext (good-ext ext) (const {B = A} x≡y) ≡
cong const x≡y
good-ext-const ext x≡y =
apply-ext (good-ext ext) (const x≡y) ≡⟨ cong (apply-ext (good-ext ext) ⊚ const) $ cong-id _ ⟩
apply-ext (good-ext ext) (const (cong P.id x≡y)) ≡⟨⟩
apply-ext (good-ext ext) (λ z → cong ((_$ z) ⊚ const) x≡y) ≡⟨ cong (apply-ext (good-ext ext)) $
apply-ext (good-ext ext) (λ _ → sym $ cong-∘ _ _ _) ⟩
apply-ext (good-ext ext) (ext⁻¹ (cong const x≡y)) ≡⟨ _≃_.right-inverse-of (extensionality-isomorphism ext) _ ⟩∎
cong const x≡y ∎
cong-good-ext :
∀ {a b} (ext : Extensionality a b)
{A : Type a} {B : A → Type b} {f g : (x : A) → B x}
(f≡g : ∀ x → f x ≡ g x) {x} →
cong (_$ x) (apply-ext (good-ext ext) f≡g) ≡ f≡g x
cong-good-ext ext f≡g {x} =
cong (_$ x) (apply-ext (good-ext ext) f≡g) ≡⟨⟩
ext⁻¹ (apply-ext (good-ext ext) f≡g) x ≡⟨ cong (_$ x) $ _≃_.left-inverse-of (extensionality-isomorphism ext) f≡g ⟩∎
f≡g x ∎
good-ext-cong :
∀ {a b c} (ext : Extensionality b c)
{A : Type a} {B : Type b} {C : B → Type c}
{f : A → (x : B) → C x} {x y : A} {x≡y : x ≡ y} →
apply-ext (good-ext ext) (λ z → cong (flip f z) x≡y) ≡
cong f x≡y
good-ext-cong ext {f = f} {x≡y = x≡y} =
apply-ext (good-ext ext) (λ z → cong (flip f z) x≡y) ≡⟨ (cong (apply-ext (good-ext ext)) $ apply-ext ext λ _ → sym $ cong-∘ _ _ _) ⟩
apply-ext (good-ext ext) (λ z → cong (_$ z) (cong f x≡y)) ≡⟨⟩
apply-ext (good-ext ext) (ext⁻¹ (cong f x≡y)) ≡⟨ _≃_.right-inverse-of (extensionality-isomorphism ext) _ ⟩∎
cong f x≡y ∎
subst-good-ext :
∀ {a b p} (ext : Extensionality a b)
{A : Type a} {B : A → Type b} {f g : (x : A) → B x} {x}
(P : B x → Type p) {p}
(f≡g : ∀ x → f x ≡ g x) →
subst (λ f → P (f x)) (apply-ext (good-ext ext) f≡g) p ≡
subst P (f≡g x) p
subst-good-ext ext {f = f} {g} {x} P {p} f≡g =
subst (λ f → P (f x)) (apply-ext (good-ext ext) f≡g) p ≡⟨ subst-∘ P (_$ x) _ ⟩
subst P (cong (_$ x) (apply-ext (good-ext ext) f≡g)) p ≡⟨ cong (λ eq → subst P eq p) (cong-good-ext ext f≡g) ⟩∎
subst P (f≡g x) p ∎
elim-good-ext :
∀ {a b p}
(ext : Extensionality a b)
{A : Type a} {B : A → Type b} {x : A}
(P : B x → B x → Type p)
(p : (y : B x) → P y y)
{f g : (x : A) → B x}
(f≡g : ∀ x → f x ≡ g x) →
elim (λ {f g} _ → P (f x) (g x)) (p ⊚ (_$ x))
(apply-ext (good-ext ext) f≡g) ≡
elim (λ {x y} _ → P x y) p (f≡g x)
elim-good-ext ext {x = x} P p f≡g =
elim (λ {f g} _ → P (f x) (g x)) (p ⊚ (_$ x)) (apply-ext (good-ext ext) f≡g) ≡⟨ sym $ elim-cong _ _ _ ⟩
elim (λ {x y} _ → P x y) p (cong (_$ x) (apply-ext (good-ext ext) f≡g)) ≡⟨ cong (elim (λ {x y} _ → P x y) p) (cong-good-ext ext f≡g) ⟩
elim (λ {x y} _ → P x y) p (f≡g x) ∎
-- I based the statements of the following three lemmas on code in
-- the Lean Homotopy Type Theory Library with Jakob von Raumer and
-- Floris van Doorn listed as authors. The file was claimed to have
-- been ported from the Coq HoTT library. (The third lemma has later
-- been generalised.)
good-ext-sym :
∀ {a b} (ext : Extensionality a b)
{A : Type a} {B : A → Type b} {f g : (x : A) → B x}
(f≡g : ∀ x → f x ≡ g x) →
apply-ext (good-ext ext) (sym ⊚ f≡g) ≡
sym (apply-ext (good-ext ext) f≡g)
good-ext-sym ext f≡g =
apply-ext (good-ext ext) (sym ⊚ f≡g) ≡⟨ cong (apply-ext (good-ext ext) ⊚ (sym ⊚_)) $ sym $
_≃_.left-inverse-of (extensionality-isomorphism ext) _ ⟩
apply-ext (good-ext ext)
(sym ⊚ ext⁻¹ (apply-ext (good-ext ext) f≡g)) ≡⟨⟩
apply-ext (good-ext ext) (λ x →
sym $ cong (_$ x) (apply-ext (good-ext ext) f≡g)) ≡⟨ cong (apply-ext (good-ext ext)) $
apply-ext ext (λ _ → sym $ cong-sym _ _) ⟩
apply-ext (good-ext ext) (λ x →
cong (_$ x) (sym $ apply-ext (good-ext ext) f≡g)) ≡⟨⟩
apply-ext (good-ext ext)
(ext⁻¹ (sym $ apply-ext (good-ext ext) f≡g)) ≡⟨ _≃_.right-inverse-of (extensionality-isomorphism ext) _ ⟩∎
sym (apply-ext (good-ext ext) f≡g) ∎
good-ext-trans :
∀ {a b} (ext : Extensionality a b)
{A : Type a} {B : A → Type b} {f g h : (x : A) → B x}
(f≡g : ∀ x → f x ≡ g x) (g≡h : ∀ x → g x ≡ h x) →
apply-ext (good-ext ext) (λ x → trans (f≡g x) (g≡h x)) ≡
trans (apply-ext (good-ext ext) f≡g) (apply-ext (good-ext ext) g≡h)
good-ext-trans ext f≡g g≡h =
apply-ext (good-ext ext) (λ x → trans (f≡g x) (g≡h x)) ≡⟨ sym $ cong₂ (λ f g → apply-ext (good-ext ext) (λ x → trans (f x) (g x)))
(_≃_.left-inverse-of (extensionality-isomorphism ext) _)
(_≃_.left-inverse-of (extensionality-isomorphism ext) _) ⟩
apply-ext (good-ext ext) (λ x →
trans (ext⁻¹ (apply-ext (good-ext ext) f≡g) x)
(ext⁻¹ (apply-ext (good-ext ext) g≡h) x)) ≡⟨⟩
apply-ext (good-ext ext) (λ x →
trans (cong (_$ x) (apply-ext (good-ext ext) f≡g))
(cong (_$ x) (apply-ext (good-ext ext) g≡h))) ≡⟨ cong (apply-ext (good-ext ext)) $ apply-ext ext (λ _ → sym $
cong-trans _ _ _) ⟩
apply-ext (good-ext ext) (λ x →
cong (_$ x) (trans (apply-ext (good-ext ext) f≡g)
(apply-ext (good-ext ext) g≡h))) ≡⟨⟩
apply-ext (good-ext ext)
(ext⁻¹ (trans (apply-ext (good-ext ext) f≡g)
(apply-ext (good-ext ext) g≡h))) ≡⟨ _≃_.right-inverse-of (extensionality-isomorphism ext) _ ⟩∎
trans (apply-ext (good-ext ext) f≡g)
(apply-ext (good-ext ext) g≡h) ∎
cong-post-∘-good-ext :
∀ {a b c} {A : Type a} {B : A → Type b} {C : A → Type c}
{f g : (x : A) → B x} {h : ∀ {x} → B x → C x}
(ext₁ : Extensionality a b)
(ext₂ : Extensionality a c)
(f≡g : ∀ x → f x ≡ g x) →
cong (h ⊚_) (apply-ext (good-ext ext₁) f≡g) ≡
apply-ext (good-ext ext₂) (cong h ⊚ f≡g)
cong-post-∘-good-ext {f = f} {g} {h} ext₁ ext₂ f≡g =
cong (h ⊚_) (apply-ext (good-ext ext₁) f≡g) ≡⟨ sym $ _≃_.right-inverse-of (extensionality-isomorphism ext₂) _ ⟩
apply-ext (good-ext ext₂)
(ext⁻¹ (cong (h ⊚_) (apply-ext (good-ext ext₁) f≡g))) ≡⟨⟩
apply-ext (good-ext ext₂) (λ x →
cong (_$ x) (cong (h ⊚_) (apply-ext (good-ext ext₁) f≡g))) ≡⟨ cong (apply-ext (good-ext ext₂)) $ apply-ext ext₂ (λ _ →
cong-∘ _ _ _) ⟩
apply-ext (good-ext ext₂) (λ x →
cong (λ f → h (f x)) (apply-ext (good-ext ext₁) f≡g)) ≡⟨ cong (apply-ext (good-ext ext₂)) $ apply-ext ext₂ (λ _ → sym $
cong-∘ _ _ _) ⟩
apply-ext (good-ext ext₂) (λ x →
cong h (cong (_$ x) (apply-ext (good-ext ext₁) f≡g))) ≡⟨⟩
apply-ext (good-ext ext₂)
(cong h ⊚ ext⁻¹ (apply-ext (good-ext ext₁) f≡g)) ≡⟨ cong (apply-ext (good-ext ext₂) ⊚ (cong h ⊚_)) $
_≃_.left-inverse-of (extensionality-isomorphism ext₁) _ ⟩∎
apply-ext (good-ext ext₂) (cong h ⊚ f≡g) ∎
cong-pre-∘-good-ext :
∀ {a b c} {A : Type a} {B : Type b} {C : B → Type c}
{f g : (x : B) → C x} {h : A → B}
(ext₁ : Extensionality a c)
(ext₂ : Extensionality b c)
(f≡g : ∀ x → f x ≡ g x) →
cong (_⊚ h) (apply-ext (good-ext ext₂) f≡g) ≡ apply-ext (good-ext ext₁) (f≡g ⊚ h)
cong-pre-∘-good-ext {f = f} {g} {h} ext₁ ext₂ f≡g =
cong (_⊚ h) (apply-ext (good-ext ext₂) f≡g) ≡⟨ sym $ _≃_.right-inverse-of (extensionality-isomorphism ext₁) _ ⟩
apply-ext (good-ext ext₁)
(ext⁻¹ (cong (_⊚ h) (apply-ext (good-ext ext₂) f≡g))) ≡⟨⟩
apply-ext (good-ext ext₁) (λ x →
cong (_$ x) (cong (_⊚ h) (apply-ext (good-ext ext₂) f≡g))) ≡⟨ cong (apply-ext (good-ext ext₁)) $ apply-ext ext₁ (λ _ →
cong-∘ _ _ _) ⟩
apply-ext (good-ext ext₁) (λ x →
cong (_$ h x) (apply-ext (good-ext ext₂) f≡g)) ≡⟨ cong (apply-ext (good-ext ext₁)) $ apply-ext ext₁ (λ _ →
cong-good-ext ext₂ _) ⟩
apply-ext (good-ext ext₁) (λ x → f≡g (h x)) ≡⟨⟩
apply-ext (good-ext ext₁) (f≡g ⊚ h) ∎
cong-∘-good-ext :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c} {f g : B → C}
(ext₁ : Extensionality b c)
(ext₂ : Extensionality (a ⊔ b) (a ⊔ c))
(ext₃ : Extensionality a c)
(f≡g : ∀ x → f x ≡ g x) →
cong {B = (A → B) → (A → C)}
(λ f → f ⊚_) (apply-ext (good-ext ext₁) f≡g) ≡
apply-ext (good-ext ext₂) λ h → apply-ext (good-ext ext₃) λ x →
f≡g (h x)
cong-∘-good-ext ext₁ ext₂ ext₃ f≡g =
cong (λ f → f ⊚_) (apply-ext (good-ext ext₁) f≡g) ≡⟨ sym $ _≃_.right-inverse-of (extensionality-isomorphism ext₂) _ ⟩
(apply-ext (good-ext ext₂) λ h →
cong (_$ h) (cong (λ f → f ⊚_) (apply-ext (good-ext ext₁) f≡g))) ≡⟨ (cong (apply-ext (good-ext ext₂)) $ apply-ext ext₂ λ _ →
cong-∘ _ _ _) ⟩
(apply-ext (good-ext ext₂) λ h →
cong (_⊚ h) (apply-ext (good-ext ext₁) f≡g)) ≡⟨ (cong (apply-ext (good-ext ext₂)) $ apply-ext ext₂ λ _ → cong-pre-∘-good-ext ext₃ ext₁ _) ⟩∎
(apply-ext (good-ext ext₂) λ h → apply-ext (good-ext ext₃) λ x →
f≡g (h x)) ∎
------------------------------------------------------------------------
-- Groupoid
abstract
-- Two proofs of equivalence are equal if the function components
-- are equal (assuming extensionality).
--
-- See also Function-universe.≃-to-≡↔≡.
lift-equality :
∀ {a b} → Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ≃ B} →
_≃_.to p ≡ _≃_.to q → p ≡ q
lift-equality {a} {b} ext {p = ⟨ f , f-eq ⟩} {q = ⟨ g , g-eq ⟩} f≡g =
elim (λ {f g} f≡g → ∀ f-eq g-eq → ⟨ f , f-eq ⟩ ≡ ⟨ g , g-eq ⟩)
(λ f f-eq g-eq →
cong (⟨_,_⟩ f) (propositional ext f f-eq g-eq))
f≡g f-eq g-eq
-- A computation rule for lift-equality.
lift-equality-refl :
∀ {a b} {A : Type a} {B : Type b}
{p : A ≃ B} {q : Is-equivalence (_≃_.to p)}
(ext : Extensionality (a ⊔ b) (a ⊔ b)) →
lift-equality ext (refl (_≃_.to p)) ≡
cong ⟨ _≃_.to p ,_⟩
(propositional ext (_≃_.to p) (_≃_.is-equivalence p) q)
lift-equality-refl ext =
cong (λ f → f _ _) $
elim-refl
(λ {f g} f≡g → ∀ f-eq g-eq → ⟨ f , f-eq ⟩ ≡ ⟨ g , g-eq ⟩)
_
-- Two proofs of equivalence are equal if the /inverses/ of the
-- function components are equal (assuming extensionality).
--
-- See also Function-universe.≃-from-≡↔≡.
lift-equality-inverse :
∀ {a b} → Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ≃ B} →
_≃_.from p ≡ _≃_.from q → p ≡ q
lift-equality-inverse ext {p = p} {q = q} f≡g =
p ≡⟨ lift-equality ext (refl _) ⟩
inverse (inverse p) ≡⟨ cong inverse $
lift-equality ext {p = inverse p} {q = inverse q} f≡g ⟩
inverse (inverse q) ≡⟨ lift-equality ext (refl _) ⟩∎
q ∎
-- An equality rearrangement lemma.
cong-to-from-lift-equality :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c} {eq₁ eq₂ : A ≃ B}
{f : (A → B) → (B → A) → C}
{eq : _≃_.to eq₁ ≡ _≃_.to eq₂} →
(ext₁ : Extensionality (a ⊔ b) (a ⊔ b))
(ext₂ : Extensionality b a) →
cong (λ eq → f (_≃_.to eq) (_≃_.from eq))
(lift-equality ext₁ {p = eq₁} {q = eq₂} eq) ≡
cong₂ f
eq
(apply-ext (good-ext ext₂) λ b →
_≃_.from eq₁ b ≡⟨ cong (_≃_.from eq₁) $ sym $ _≃_.right-inverse-of eq₂ b ⟩
_≃_.from eq₁ (_≃_.to eq₂ (_≃_.from eq₂ b)) ≡⟨ cong (_≃_.from eq₁) $ cong (_$ _≃_.from eq₂ b) $ sym eq ⟩
_≃_.from eq₁ (_≃_.to eq₁ (_≃_.from eq₂ b)) ≡⟨ _≃_.left-inverse-of eq₁ (_≃_.from eq₂ b) ⟩∎
_≃_.from eq₂ b ∎)
cong-to-from-lift-equality {eq₂ = eq₂} {f = f} {eq = eq} ext₁ ext₂ =
elim₁
(λ {g} eq →
(is-eq : Is-equivalence g) →
let eq₁ = ⟨ g , is-eq ⟩ in
cong (λ eq → f (_≃_.to eq) (_≃_.from eq))
(lift-equality ext₁ {p = eq₁} {q = eq₂} eq) ≡
cong₂ f
eq
(apply-ext (good-ext ext₂) λ b →
trans (cong (_≃_.from eq₁) $ sym $
_≃_.right-inverse-of eq₂ b) $
trans (cong (_≃_.from eq₁) $
cong (_$ _≃_.from eq₂ b) $ sym eq) $
_≃_.left-inverse-of eq₁ (_≃_.from eq₂ b)))
(λ is-eq →
let eq₁ = ⟨ _≃_.to eq₂ , is-eq ⟩ in
cong (λ eq → f (_≃_.to eq) (_≃_.from eq))
(lift-equality ext₁ (refl _)) ≡⟨ cong (cong _) $ lift-equality-refl ext₁ ⟩
cong (λ eq → f (_≃_.to eq) (_≃_.from eq))
(cong ⟨ _≃_.to eq₂ ,_⟩
(propositional ext₁ (_≃_.to eq₂) _ _)) ≡⟨ cong-∘ _ _ _ ⟩
cong (λ is-eq → f (_≃_.to eq₂) (_≃_.from ⟨ _ , is-eq ⟩))
(propositional ext₁ (_≃_.to eq₂) _ _) ≡⟨ sym $ cong-∘ _ _ _ ⟩
cong (f (_≃_.to eq₂))
(cong (λ is-eq → _≃_.from ⟨ _ , is-eq ⟩)
(propositional ext₁ (_≃_.to eq₂) _ _)) ≡⟨ cong (cong _) $
elim₁
(λ {is-eq} eq →
let eq₁ = ⟨ _≃_.to eq₂ , is-eq ⟩ in
cong (λ is-eq → _≃_.from ⟨ _ , is-eq ⟩) eq ≡
apply-ext (good-ext ext₂) λ b →
trans (cong (_≃_.from eq₁) $ sym $
_≃_.right-inverse-of eq₂ b) $
_≃_.left-inverse-of eq₁ (_≃_.from eq₂ b))
(
cong (λ is-eq → _≃_.from ⟨ _ , is-eq ⟩) (refl _) ≡⟨ cong-refl _ ⟩
refl _ ≡⟨ sym (good-ext-refl ext₂ _) ⟩
(apply-ext (good-ext ext₂) λ _ → refl _) ≡⟨ (cong (apply-ext (good-ext ext₂)) $ apply-ext ext₂ λ _ → sym $
trans-symˡ _) ⟩
(apply-ext (good-ext ext₂) λ b →
trans (sym $ cong (_≃_.from eq₂) $
_≃_.right-inverse-of eq₂ b) $
cong (_≃_.from eq₂) $ _≃_.right-inverse-of eq₂ b) ≡⟨ (cong (apply-ext (good-ext ext₂)) $ apply-ext ext₂ λ _ →
cong₂ trans
(sym $ cong-sym _ _)
(_≃_.right-left-lemma eq₂ _)) ⟩∎
(apply-ext (good-ext ext₂) λ b →
trans (cong (_≃_.from eq₂) $ sym $
_≃_.right-inverse-of eq₂ b) $
_≃_.left-inverse-of eq₂ (_≃_.from eq₂ b)) ∎)
(propositional ext₁ (_≃_.to eq₂) _ _) ⟩
cong (f (_≃_.to eq₂))
(apply-ext (good-ext ext₂) λ b →
trans (cong (_≃_.from eq₁) $ sym $
_≃_.right-inverse-of eq₂ b) $
_≃_.left-inverse-of eq₁ (_≃_.from eq₂ b)) ≡⟨ (cong (cong _) $
cong (apply-ext (good-ext ext₂)) $ apply-ext ext₂ λ _ →
cong (trans _) $ sym $
trans (cong (flip trans _) $
trans (cong (cong _) $
trans (cong (cong _) sym-refl) $
cong-refl _) $
cong-refl _) $
trans-reflˡ _) ⟩
cong (f (_≃_.to eq₂))
(apply-ext (good-ext ext₂) λ b →
trans (cong (_≃_.from eq₁) $ sym $
_≃_.right-inverse-of eq₂ b) $
trans (cong (_≃_.from eq₁) $ cong (_$ _≃_.from eq₂ b) $ sym $
refl (_≃_.to eq₂)) $
_≃_.left-inverse-of eq₁ (_≃_.from eq₂ b)) ≡⟨ sym $ cong₂-reflˡ _ ⟩∎
cong₂ f
(refl _)
(apply-ext (good-ext ext₂) λ b →
trans (cong (_≃_.from eq₁) $ sym $
_≃_.right-inverse-of eq₂ b) $
trans (cong (_≃_.from eq₁) $ cong (_$ _≃_.from eq₂ b) $ sym $
refl (_≃_.to eq₂)) $
_≃_.left-inverse-of eq₁ (_≃_.from eq₂ b)) ∎)
eq
_
-- _≃_ comes with a groupoid structure (assuming extensionality).
groupoid : ∀ {ℓ} → Extensionality ℓ ℓ → Groupoid (lsuc ℓ) ℓ
groupoid {ℓ} ext = record
{ Object = Type ℓ
; _∼_ = _≃_
; id = id
; _∘_ = _∘_
; _⁻¹ = inverse
; left-identity = left-identity
; right-identity = right-identity
; assoc = assoc
; left-inverse = left-inverse
; right-inverse = right-inverse
}
where
abstract
left-identity : {X Y : Type ℓ} (p : X ≃ Y) → id ∘ p ≡ p
left-identity _ = lift-equality ext (refl _)
right-identity : {X Y : Type ℓ} (p : X ≃ Y) → p ∘ id ≡ p
right-identity _ = lift-equality ext (refl _)
assoc : {W X Y Z : Type ℓ} (p : Y ≃ Z) (q : X ≃ Y) (r : W ≃ X) →
p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r
assoc _ _ _ = lift-equality ext (refl _)
left-inverse : {X Y : Type ℓ} (p : X ≃ Y) → inverse p ∘ p ≡ id
left-inverse p =
lift-equality ext (apply-ext ext $ _≃_.left-inverse-of p)
right-inverse : {X Y : Type ℓ} (p : X ≃ Y) → p ∘ inverse p ≡ id
right-inverse p =
lift-equality ext (apply-ext ext $ _≃_.right-inverse-of p)
-- Inverse is involutive (assuming extensionality).
--
-- This property is more general than
-- Groupoid.involutive (groupoid …), because A and B do not have to
-- have the same size.
inverse-involutive :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
(p : A ≃ B) →
inverse (inverse p) ≡ p
inverse-involutive ext p = lift-equality ext (refl _)
-- Inverse is a logical equivalence.
inverse-logical-equivalence :
∀ {a b} {A : Type a} {B : Type b} →
A ≃ B ⇔ B ≃ A
inverse-logical-equivalence = record
{ to = inverse
; from = inverse
}
-- Inverse is an isomorphism (assuming extensionality).
--
-- This property is more general than
-- Groupoid.⁻¹-bijection (groupoid …), because A and B do not have to
-- have the same size.
inverse-isomorphism :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
A ≃ B ↔ B ≃ A
inverse-isomorphism ext = record
{ surjection = record
{ logical-equivalence = inverse-logical-equivalence
; right-inverse-of = inverse-involutive ext
}
; left-inverse-of = inverse-involutive ext
}
------------------------------------------------------------------------
-- A surjection from A ↔ B to A ≃ B, and related results
private
abstract
-- ↔⇒≃ is a left inverse of _≃_.bijection (assuming extensionality).
↔⇒≃-left-inverse :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
(A≃B : A ≃ B) →
↔⇒≃ (_≃_.bijection A≃B) ≡ A≃B
↔⇒≃-left-inverse ext _ = lift-equality ext (refl _)
-- When sets are used ↔⇒≃ is a right inverse of _≃_.bijection
-- (assuming extensionality).
↔⇒≃-right-inverse :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-set A → (A↔B : A ↔ B) →
_≃_.bijection (↔⇒≃ A↔B) ≡ A↔B
↔⇒≃-right-inverse {a} {b} {B = B} ext A-set A↔B =
cong₂ (λ l r → record
{ surjection = record
{ logical-equivalence = _↔_.logical-equivalence A↔B
; right-inverse-of = r
}
; left-inverse-of = l
})
(apply-ext (lower-extensionality b b ext) λ _ → A-set _ _)
(apply-ext (lower-extensionality a a ext) λ _ → B-set _ _)
where
B-set : Is-set B
B-set = respects-surjection (_↔_.surjection A↔B) 2 A-set
-- There is a surjection from A ↔ B to A ≃ B (assuming
-- extensionality).
↔↠≃ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
(A ↔ B) ↠ (A ≃ B)
↔↠≃ ext = record
{ logical-equivalence = ↔⇔≃
; right-inverse-of = ↔⇒≃-left-inverse ext
}
-- When A is a set A ↔ B and A ≃ B are isomorphic (assuming
-- extensionality).
↔↔≃ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-set A → (A ↔ B) ↔ (A ≃ B)
↔↔≃ ext A-set = record
{ surjection = ↔↠≃ ext
; left-inverse-of = ↔⇒≃-right-inverse ext A-set
}
-- When B is a set A ↔ B and A ≃ B are isomorphic (assuming
-- extensionality).
↔↔≃′ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-set B → (A ↔ B) ↔ (A ≃ B)
↔↔≃′ ext B-set = record
{ surjection = ↔↠≃ ext
; left-inverse-of = λ A↔B →
↔⇒≃-right-inverse
ext
(H-level.respects-surjection
(_↔_.surjection $ Bijection.inverse A↔B) 2 B-set)
A↔B
}
-- For propositional types there is a split surjection from
-- equivalence to logical equivalence.
≃↠⇔ : ∀ {a b} {A : Type a} {B : Type b} →
Is-proposition A → Is-proposition B → (A ≃ B) ↠ (A ⇔ B)
≃↠⇔ {A = A} {B} A-prop B-prop = record
{ logical-equivalence = record
{ to = _≃_.logical-equivalence
; from = ⇔→≃
}
; right-inverse-of = refl
}
where
⇔→≃ : A ⇔ B → A ≃ B
⇔→≃ A⇔B = ↔⇒≃ record
{ surjection = record
{ logical-equivalence = A⇔B
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
open _⇔_ A⇔B
abstract
to∘from : ∀ x → to (from x) ≡ x
to∘from _ = B-prop _ _
from∘to : ∀ x → from (to x) ≡ x
from∘to _ = A-prop _ _
-- A corollary.
⇔→≃ :
∀ {a b} {A : Type a} {B : Type b} →
Is-proposition A → Is-proposition B →
(A → B) → (B → A) →
A ≃ B
⇔→≃ A-prop B-prop to from =
_↠_.from (≃↠⇔ A-prop B-prop)
(record { to = to; from = from })
-- For propositional types logical equivalence is isomorphic to
-- equivalence (assuming extensionality).
⇔↔≃ : ∀ {a b} → Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} →
Is-proposition A → Is-proposition B → (A ⇔ B) ↔ (A ≃ B)
⇔↔≃ ext {A} {B} A-prop B-prop = record
{ surjection = record
{ logical-equivalence = L-eq.inverse $ _↠_.logical-equivalence $
≃↠⇔ A-prop B-prop
; right-inverse-of = λ _ → lift-equality ext (refl _)
}
; left-inverse-of = refl
}
-- If there is a propositional, reflexive relation on A, and related
-- elements are equal, then A is a set, and (assuming extensionality)
-- the relation is equivalent to equality.
--
-- (This is more or less Theorem 7.2.2 from "Homotopy Type Theory:
-- Univalent Foundations of Mathematics" (first edition).)
propositional-identity≃≡ :
∀ {a b} {A : Type a}
(B : A → A → Type b) →
(∀ x y → Is-proposition (B x y)) →
(∀ x → B x x) →
(∀ x y → B x y → x ≡ y) →
Is-set A ×
(Extensionality (a ⊔ b) (a ⊔ b) → ∀ {x y} → B x y ≃ (x ≡ y))
propositional-identity≃≡ B B-prop B-refl f =
A-set
, λ ext →
_↔_.to (⇔↔≃ ext (B-prop _ _) A-set)
(record
{ to = f _ _
; from = λ x≡y → subst (B _) x≡y (B-refl _)
})
where
A-set = propositional-identity⇒set B B-prop B-refl f
------------------------------------------------------------------------
-- Closure, preservation
abstract
-- All h-levels are closed under the equivalence operator (assuming
-- extensionality).
h-level-closure :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
∀ {A : Type a} {B : Type b} n →
H-level n A → H-level n B → H-level n (A ≃ B)
h-level-closure {a} {b} ext {A = A} {B} n hA hB =
H-level.respects-surjection
(_↔_.surjection $ Bijection.inverse ≃-as-Σ) n lemma₂
where
lemma₁ : ∀ n {to : A → B} →
H-level n A → H-level n B →
H-level n (Is-equivalence to)
lemma₁ zero cA cB = sometimes-contractible ext cA (mono₁ 0 cB)
lemma₁ (suc n) _ _ = mono (m≤m+n 1 n) (propositional ext _)
lemma₂ : H-level n (∃ λ (to : A → B) → Is-equivalence to)
lemma₂ = Σ-closure n
(Π-closure (lower-extensionality b a ext) n (λ _ → hB))
(λ _ → lemma₁ n hA hB)
-- For positive h-levels it is enough if one of the sides has the
-- given h-level.
left-closure :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
∀ {A : Type a} {B : Type b} n →
H-level (1 + n) A → H-level (1 + n) (A ≃ B)
left-closure ext {A = A} {B} n hA =
H-level.[inhabited⇒+]⇒+ n λ (A≃B : A ≃ B) →
h-level-closure ext (1 + n) hA $
H-level.respects-surjection (_≃_.surjection A≃B) (1 + n) hA
right-closure :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
∀ {A : Type a} {B : Type b} n →
H-level (1 + n) B → H-level (1 + n) (A ≃ B)
right-closure ext {A = A} {B} n hB =
H-level.[inhabited⇒+]⇒+ n λ (A≃B : A ≃ B) →
left-closure ext n $
H-level.respects-surjection
(_≃_.surjection (inverse A≃B)) (1 + n) hB
-- This is not enough for level 0.
¬-left-closure :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
∃ λ (A : Type a) → ∃ λ (B : Type b) →
Contractible A × Is-proposition B × ¬ Contractible (A ≃ B)
¬-left-closure ext =
↑ _ ⊤ ,
⊥ ,
↑-closure 0 ⊤-contractible ,
⊥-propositional ,
λ c → ⊥-elim (_≃_.to (proj₁ c) _)
¬-right-closure :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
∃ λ (A : Type a) → ∃ λ (B : Type b) →
Is-proposition A × Contractible B × ¬ Contractible (A ≃ B)
¬-right-closure ext =
⊥ ,
↑ _ ⊤ ,
⊥-propositional ,
↑-closure 0 ⊤-contractible ,
λ c → ⊥-elim (_≃_.from (proj₁ c) _)
-- ⊥ ≃ ⊥ is contractible (assuming extensionality).
⊥≃⊥-contractible :
∀ {ℓ₁ ℓ₂} →
Extensionality (ℓ₁ ⊔ ℓ₂) (ℓ₁ ⊔ ℓ₂) →
Contractible (⊥ {ℓ = ℓ₁} ≃ ⊥ {ℓ = ℓ₂})
⊥≃⊥-contractible {ℓ₁} {ℓ₂} ext =
↔⇒≃ ⊥↔⊥ , λ ⊥↔⊥′ →
lift-equality ext $
apply-ext (lower-extensionality ℓ₂ ℓ₁ ext) λ x → ⊥-elim x
where
⊥↔⊥ : ⊥ {ℓ = ℓ₁} ↔ ⊥ {ℓ = ℓ₂}
⊥↔⊥ = record
{ surjection = record
{ logical-equivalence = record
{ to = ⊥-elim
; from = ⊥-elim
}
; right-inverse-of = λ x → ⊥-elim x
}
; left-inverse-of = λ x → ⊥-elim x
}
-- Equalities are closed, in a strong sense, under applications of
-- equivalences.
≃-≡ : ∀ {a b} {A : Type a} {B : Type b} (A≃B : A ≃ B) {x y : A} →
let open _≃_ A≃B in
(to x ≡ to y) ≃ (x ≡ y)
≃-≡ A≃B {x} {y} = ↔⇒≃ record
{ surjection = surjection′
; left-inverse-of = left-inverse-of′
}
where
open _≃_ A≃B
surjection′ : (to x ≡ to y) ↠ (x ≡ y)
surjection′ =
Surjection.↠-≡ $
_↔_.surjection $
Bijection.inverse $
_≃_.bijection A≃B
abstract
left-inverse-of′ :
∀ p → _↠_.from surjection′ (_↠_.to surjection′ p) ≡ p
left-inverse-of′ = λ to-x≡to-y →
cong to (
trans (sym (left-inverse-of x)) $
trans (cong from to-x≡to-y) $
left-inverse-of y) ≡⟨ cong-trans to _ _ ⟩
trans (cong to (sym (left-inverse-of x))) (
cong to (trans (cong from to-x≡to-y) (
left-inverse-of y))) ≡⟨ cong₂ trans (cong-sym to _) (cong-trans to _ _) ⟩
trans (sym (cong to (left-inverse-of x))) (
trans (cong to (cong from to-x≡to-y)) (
cong to (left-inverse-of y))) ≡⟨ cong₂ (λ eq₁ eq₂ → trans (sym eq₁) $
trans (cong to (cong from to-x≡to-y)) $
eq₂)
(left-right-lemma x)
(left-right-lemma y) ⟩
trans (sym (right-inverse-of (to x))) (
trans (cong to (cong from to-x≡to-y)) (
right-inverse-of (to y))) ≡⟨ _↠_.right-inverse-of (Surjection.↠-≡ $ _≃_.surjection A≃B) to-x≡to-y ⟩∎
to-x≡to-y ∎
-- A "computation rule" for ≃-≡.
to-≃-≡-refl :
∀ {a b} {A : Type a} {B : Type b} (A≃B : A ≃ B) {x : A} →
_≃_.to (≃-≡ A≃B) (refl (_≃_.to A≃B x)) ≡ refl x
to-≃-≡-refl A≃B =
Surjection.to-↠-≡-refl
(_↔_.surjection $ Bijection.inverse $ _≃_.bijection A≃B)
-- ∃ preserves equivalences.
∃-cong :
∀ {a b₁ b₂} {A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ≃ B₂ x) → ∃ B₁ ≃ ∃ B₂
∃-cong B₁≃B₂ = ↔⇒≃ (record
{ surjection = Surjection.∃-cong (_≃_.surjection ⊚ B₁≃B₂)
; left-inverse-of = uncurry λ x y →
cong (_,_ x) (_≃_.left-inverse-of (B₁≃B₂ x) y)
})
abstract
private
-- We can push subst through certain function applications.
push-subst :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
(B₁ : A₁ → Type b₁) {B₂ : A₂ → Type b₂}
{f : A₂ → A₁} {x₁ x₂ : A₂} {y : B₁ (f x₁)}
(g : ∀ x → B₁ (f x) → B₂ x) (eq : x₁ ≡ x₂) →
subst B₂ eq (g x₁ y) ≡ g x₂ (subst B₁ (cong f eq) y)
push-subst B₁ {B₂} {f} g eq = elim
(λ {x₁ x₂} eq → ∀ y → subst B₂ eq (g x₁ y) ≡
g x₂ (subst B₁ (cong f eq) y))
(λ x y → subst B₂ (refl x) (g x y) ≡⟨ subst-refl B₂ _ ⟩
g x y ≡⟨ sym $ cong (g x) $ subst-refl B₁ _ ⟩
g x (subst B₁ (refl (f x)) y) ≡⟨ cong (λ eq → g x (subst B₁ eq y)) (sym $ cong-refl f) ⟩∎
g x (subst B₁ (cong f (refl x)) y) ∎)
eq _
push-subst′ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
(A₁≃A₂ : A₁ ≃ A₂) (B₁ : A₁ → Type b₁) (B₂ : A₂ → Type b₂) →
let open _≃_ A₁≃A₂ in {x₁ x₂ : A₁} {y : B₁ (from (to x₁))}
(g : ∀ x → B₁ (from (to x)) → B₂ (to x)) (eq : to x₁ ≡ to x₂) →
subst B₂ eq (g x₁ y) ≡ g x₂ (subst B₁ (cong from eq) y)
push-subst′ A₁≃A₂ B₁ B₂ {x₁} {x₂} {y} g eq =
subst B₂ eq (g x₁ y) ≡⟨ cong (subst B₂ eq) $ sym $ g′-lemma _ _ ⟩
subst B₂ eq (g′ (to x₁) y) ≡⟨ push-subst B₁ g′ eq ⟩
g′ (to x₂) (subst B₁ (cong from eq) y) ≡⟨ g′-lemma _ _ ⟩∎
g x₂ (subst B₁ (cong from eq) y) ∎
where
open _≃_ A₁≃A₂
g′ : ∀ x′ → B₁ (from x′) → B₂ x′
g′ x′ y = subst B₂ (right-inverse-of x′) $
g (from x′) $
subst B₁ (sym $ cong from $ right-inverse-of x′) y
g′-lemma : ∀ x y → g′ (to x) y ≡ g x y
g′-lemma x y =
let lemma = λ y →
let gy = g (from (to x)) $
subst B₁
(sym $ cong from $ cong to (refl _)) y in
subst B₂ (cong to (refl _)) gy ≡⟨ cong (λ p → subst B₂ p gy) $ cong-refl to ⟩
subst B₂ (refl _) gy ≡⟨ subst-refl B₂ gy ⟩
gy ≡⟨ cong (λ p → g (from (to x)) $ subst B₁ (sym $ cong from p) y) $ cong-refl to ⟩
g (from (to x))
(subst B₁ (sym $ cong from (refl _)) y) ≡⟨ cong (λ p → g (from (to x)) $ subst B₁ (sym p) y) $ cong-refl from ⟩
g (from (to x))
(subst B₁ (sym (refl _)) y) ≡⟨ cong (λ p → g (from (to x)) $ subst B₁ p y) sym-refl ⟩
g (from (to x)) (subst B₁ (refl _) y) ≡⟨ cong (g (from (to x))) $ subst-refl B₁ y ⟩∎
g (from (to x)) y ∎
in
subst B₂ (right-inverse-of (to x))
(g (from (to x)) $
subst B₁ (sym $ cong from $
right-inverse-of (to x)) y) ≡⟨ cong (λ p → subst B₂ p (g (from (to x)) $ subst B₁ (sym $ cong from p) y)) $
sym $ left-right-lemma x ⟩
subst B₂ (cong to $ left-inverse-of x)
(g (from (to x)) $
subst B₁ (sym $ cong from $ cong to $
left-inverse-of x) y) ≡⟨ elim¹
(λ {x′} eq →
(y : B₁ (from (to x′))) →
subst B₂ (cong to eq)
(g (from (to x)) $ subst B₁ (sym $ cong from $ cong to eq) y) ≡
g x′ y)
lemma
(left-inverse-of x) y ⟩∎
g x y ∎
-- If the first component is instantiated to the identity, then the
-- following lemmas state that ∃ preserves injections and bijections.
∃-preserves-injections :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂}
(A₁≃A₂ : A₁ ≃ A₂) → (∀ x → B₁ x ↣ B₂ (_≃_.to A₁≃A₂ x)) →
Σ A₁ B₁ ↣ Σ A₂ B₂
∃-preserves-injections {A₁ = A₁} {A₂} {B₁} {B₂} A₁≃A₂ B₁↣B₂ = record
{ to = to′
; injective = injective′
}
where
open _↣_
to′ : Σ A₁ B₁ → Σ A₂ B₂
to′ = Σ-map (_≃_.to A₁≃A₂) (_↣_.to (B₁↣B₂ _))
abstract
injective′ : Injective to′
injective′ {x = (x₁ , x₂)} {y = (y₁ , y₂)} =
_↔_.to Bijection.Σ-≡,≡↔≡ ⊚
Σ-map (_≃_.injective A₁≃A₂) (λ {eq₁} eq₂ →
let lemma =
to (B₁↣B₂ y₁) (subst B₁ (_≃_.injective A₁≃A₂ eq₁) x₂) ≡⟨ refl _ ⟩
to (B₁↣B₂ y₁)
(subst B₁ (trans (sym (_≃_.left-inverse-of A₁≃A₂ x₁)) $
trans (cong (_≃_.from A₁≃A₂) eq₁)
(_≃_.left-inverse-of A₁≃A₂ y₁))
x₂) ≡⟨ cong (to (B₁↣B₂ y₁)) $ sym $ subst-subst B₁ _ _ _ ⟩
to (B₁↣B₂ y₁)
(subst B₁ (trans (cong (_≃_.from A₁≃A₂) eq₁)
(_≃_.left-inverse-of A₁≃A₂ y₁)) $
subst B₁ (sym (_≃_.left-inverse-of A₁≃A₂ x₁))
x₂) ≡⟨ cong (to (B₁↣B₂ y₁)) $ sym $ subst-subst B₁ _ _ _ ⟩
to (B₁↣B₂ y₁)
(subst B₁ (_≃_.left-inverse-of A₁≃A₂ y₁) $
subst B₁ (cong (_≃_.from A₁≃A₂) eq₁) $
subst B₁ (sym (_≃_.left-inverse-of A₁≃A₂ x₁)) x₂) ≡⟨ sym $ push-subst′ A₁≃A₂ B₁ B₂
(λ x y → to (B₁↣B₂ x)
(subst B₁ (_≃_.left-inverse-of A₁≃A₂ x) y))
eq₁ ⟩
subst B₂ eq₁
(to (B₁↣B₂ x₁) $
subst B₁ (_≃_.left-inverse-of A₁≃A₂ x₁) $
subst B₁ (sym (_≃_.left-inverse-of A₁≃A₂ x₁)) x₂) ≡⟨ cong (subst B₂ eq₁ ⊚ to (B₁↣B₂ x₁)) $ subst-subst B₁ _ _ _ ⟩
subst B₂ eq₁
(to (B₁↣B₂ x₁) $
subst B₁ (trans (sym (_≃_.left-inverse-of A₁≃A₂ x₁))
(_≃_.left-inverse-of A₁≃A₂ x₁))
x₂) ≡⟨ cong (λ p → subst B₂ eq₁ (to (B₁↣B₂ x₁) (subst B₁ p x₂))) $
trans-symˡ _ ⟩
subst B₂ eq₁ (to (B₁↣B₂ x₁) $ subst B₁ (refl _) x₂) ≡⟨ cong (subst B₂ eq₁ ⊚ to (B₁↣B₂ x₁)) $
subst-refl B₁ x₂ ⟩
subst B₂ eq₁ (to (B₁↣B₂ x₁) x₂) ≡⟨ eq₂ ⟩∎
to (B₁↣B₂ y₁) y₂ ∎
in
subst B₁ (_≃_.injective A₁≃A₂ eq₁) x₂ ≡⟨ _↣_.injective (B₁↣B₂ y₁) lemma ⟩∎
y₂ ∎) ⊚
Σ-≡,≡←≡
∃-preserves-bijections :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂}
(A₁≃A₂ : A₁ ≃ A₂) → (∀ x → B₁ x ↔ B₂ (_≃_.to A₁≃A₂ x)) →
Σ A₁ B₁ ↔ Σ A₂ B₂
∃-preserves-bijections {A₁ = A₁} {A₂} {B₁} {B₂} A₁≃A₂ B₁↔B₂ = record
{ surjection = surjection′
; left-inverse-of = left-inverse-of′
}
where
open _↔_
surjection′ : Σ A₁ B₁ ↠ Σ A₂ B₂
surjection′ =
Surjection.Σ-cong (_≃_.surjection A₁≃A₂) (surjection ⊚ B₁↔B₂)
abstract
left-inverse-of′ :
∀ p → _↠_.from surjection′ (_↠_.to surjection′ p) ≡ p
left-inverse-of′ = λ p → Σ-≡,≡→≡
(_≃_.left-inverse-of A₁≃A₂ (proj₁ p))
(subst B₁ (_≃_.left-inverse-of A₁≃A₂ (proj₁ p))
(from (B₁↔B₂ _)
(subst B₂ (sym (_≃_.right-inverse-of A₁≃A₂
(_≃_.to A₁≃A₂ (proj₁ p))))
(to (B₁↔B₂ _) (proj₂ p)))) ≡⟨ push-subst B₂ (λ x → from (B₁↔B₂ x))
(_≃_.left-inverse-of A₁≃A₂ (proj₁ p)) ⟩
from (B₁↔B₂ _)
(subst B₂ (cong (_≃_.to A₁≃A₂)
(_≃_.left-inverse-of A₁≃A₂ (proj₁ p)))
(subst B₂ (sym (_≃_.right-inverse-of A₁≃A₂
(_≃_.to A₁≃A₂ (proj₁ p))))
(to (B₁↔B₂ _) (proj₂ p)))) ≡⟨ cong (λ eq → from (B₁↔B₂ _)
(subst B₂ eq
(subst B₂ (sym (_≃_.right-inverse-of A₁≃A₂ _))
(to (B₁↔B₂ _) (proj₂ p))))) $
_≃_.left-right-lemma A₁≃A₂ _ ⟩
from (B₁↔B₂ _)
(subst B₂ (_≃_.right-inverse-of A₁≃A₂
(_≃_.to A₁≃A₂ (proj₁ p)))
(subst B₂ (sym (_≃_.right-inverse-of A₁≃A₂
(_≃_.to A₁≃A₂ (proj₁ p))))
(to (B₁↔B₂ _) (proj₂ p)))) ≡⟨ cong (from (B₁↔B₂ _)) $ subst-subst-sym B₂ _ _ ⟩
from (B₁↔B₂ _) (to (B₁↔B₂ _) (proj₂ p)) ≡⟨ left-inverse-of (B₁↔B₂ _) _ ⟩∎
proj₂ p ∎)
-- Σ preserves equivalence.
Σ-preserves : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂}
(A₁≃A₂ : A₁ ≃ A₂) → (∀ x → B₁ x ≃ B₂ (_≃_.to A₁≃A₂ x)) →
Σ A₁ B₁ ≃ Σ A₂ B₂
Σ-preserves A₁≃A₂ B₁≃B₂ = ↔⇒≃ $
∃-preserves-bijections A₁≃A₂ (_≃_.bijection ⊚ B₁≃B₂)
-- A part of the implementation of ≃-preserves (see below) that does
-- not depend on extensionality.
≃-preserves-⇔ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂} {B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ ≃ B₁) ⇔ (A₂ ≃ B₂)
≃-preserves-⇔ A₁≃A₂ B₁≃B₂ = record
{ to = λ A₁≃B₁ → B₁≃B₂ ∘ A₁≃B₁ ∘ inverse A₁≃A₂
; from = λ A₂≃B₂ → inverse B₁≃B₂ ∘ A₂≃B₂ ∘ A₁≃A₂
}
-- Equivalence preserves equivalences (assuming extensionality).
≃-preserves :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂) (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂} {B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ ≃ B₁) ≃ (A₂ ≃ B₂)
≃-preserves {a₁} {a₂} {b₁} {b₂} ext {A₁} {A₂} {B₁} {B₂} A₁≃A₂ B₁≃B₂ =
↔⇒≃ (record
{ surjection = record
{ logical-equivalence = ≃-preserves-⇔ A₁≃A₂ B₁≃B₂
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
})
where
open _≃_
ext₁ = lower-extensionality (a₁ ⊔ b₁) (a₁ ⊔ b₁) ext
ext₂ = lower-extensionality (a₂ ⊔ b₂) (a₂ ⊔ b₂) ext
abstract
to∘from :
(A₂≃B₂ : A₂ ≃ B₂) →
B₁≃B₂ ∘ (inverse B₁≃B₂ ∘ A₂≃B₂ ∘ A₁≃A₂) ∘ inverse A₁≃A₂ ≡ A₂≃B₂
to∘from A₂≃B₂ =
lift-equality ext₁ $
apply-ext (lower-extensionality b₂ a₂ ext₁) λ x →
to B₁≃B₂ (from B₁≃B₂ (to A₂≃B₂ (to A₁≃A₂ (from A₁≃A₂ x)))) ≡⟨ right-inverse-of B₁≃B₂ _ ⟩
to A₂≃B₂ (to A₁≃A₂ (from A₁≃A₂ x)) ≡⟨ cong (to A₂≃B₂) $ right-inverse-of A₁≃A₂ _ ⟩∎
to A₂≃B₂ x ∎
from∘to :
(A₁≃B₁ : A₁ ≃ B₁) →
inverse B₁≃B₂ ∘ (B₁≃B₂ ∘ A₁≃B₁ ∘ inverse A₁≃A₂) ∘ A₁≃A₂ ≡ A₁≃B₁
from∘to A₁≃B₁ =
lift-equality ext₂ $
apply-ext (lower-extensionality b₁ a₁ ext₂) λ x →
from B₁≃B₂ (to B₁≃B₂ (to A₁≃B₁ (from A₁≃A₂ (to A₁≃A₂ x)))) ≡⟨ left-inverse-of B₁≃B₂ _ ⟩
to A₁≃B₁ (from A₁≃A₂ (to A₁≃A₂ x)) ≡⟨ cong (to A₁≃B₁) $ left-inverse-of A₁≃A₂ _ ⟩∎
to A₁≃B₁ x ∎
-- Equivalence preserves bijections (assuming extensionality).
≃-preserves-bijections :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂) (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂} {B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↔ A₂ → B₁ ↔ B₂ → (A₁ ≃ B₁) ↔ (A₂ ≃ B₂)
≃-preserves-bijections ext A₁↔A₂ B₁↔B₂ =
_≃_.bijection $ ≃-preserves ext (↔⇒≃ A₁↔A₂) (↔⇒≃ B₁↔B₂)
------------------------------------------------------------------------
-- More lemmas
abstract
-- As a consequence of extensionality-isomorphism and ≃-≡ we get a
-- strengthening of W-≡,≡↠≡.
W-≡,≡≃≡ : ∀ {a b} {A : Type a} {B : A → Type b} →
Extensionality b (a ⊔ b) →
∀ {x y} {f : B x → W A B} {g : B y → W A B} →
(∃ λ (p : x ≡ y) → ∀ i → f i ≡ g (subst B p i)) ≃
(sup x f ≡ sup y g)
W-≡,≡≃≡ {a} {A = A} {B} ext {x} {y} {f} {g} =
(∃ λ p → ∀ i → f i ≡ g (subst B p i)) ≃⟨ Σ-preserves id lemma ⟩
(∃ λ p → subst (λ x → B x → W A B) p f ≡ g) ≃⟨ ↔⇒≃ Bijection.Σ-≡,≡↔≡ ⟩
((x , f) ≡ (y , g)) ≃⟨ ≃-≡ (↔⇒≃ W-unfolding) ⟩□
(sup x f ≡ sup y g) □
where
lemma : (p : x ≡ y) →
(∀ i → f i ≡ g (subst B p i)) ≃
(subst (λ x → B x → W A B) p f ≡ g)
lemma p = elim
(λ {x y} p → (f : B x → W A B) (g : B y → W A B) →
(∀ i → f i ≡ g (subst B p i)) ≃
(subst (λ x → B x → W A B) p f ≡ g))
(λ x f g →
(∀ i → f i ≡ g (subst B (refl x) i)) ≃⟨ subst (λ h → (∀ i → f i ≡ g (h i)) ≃ (∀ i → f i ≡ g i))
(sym (apply-ext (lower-extensionality lzero a ext) (subst-refl B)))
id ⟩
(∀ i → f i ≡ g i) ≃⟨ extensionality-isomorphism ext ⟩
(f ≡ g) ≃⟨ subst (λ h → (f ≡ g) ≃ (h ≡ g))
(sym $ subst-refl (λ x' → B x' → W A B) f)
id ⟩□
(subst (λ x → B x → W A B) (refl x) f ≡ g) □)
p f g
-- Some rearrangement lemmas.
to-subst :
∀ {a p q} {A : Type a} {P : A → Type p} {Q : A → Type q}
{x y : A} {eq : x ≡ y} {f : P x ≃ Q x} →
_≃_.to (subst (λ x → P x ≃ Q x) eq f) ≡
subst (λ x → P x → Q x) eq (_≃_.to f)
to-subst {P = P} {Q = Q} {eq = eq} {f = f} = elim¹
(λ eq →
_≃_.to (subst (λ x → P x ≃ Q x) eq f) ≡
subst (λ x → P x → Q x) eq (_≃_.to f))
(_≃_.to (subst (λ x → P x ≃ Q x) (refl _) f) ≡⟨ cong _≃_.to $ subst-refl (λ _ → _ ≃ _) _ ⟩
_≃_.to f ≡⟨ sym $ subst-refl _ _ ⟩∎
subst (λ x → P x → Q x) (refl _) (_≃_.to f) ∎)
eq
from-subst :
∀ {a p q} {A : Type a} {P : A → Type p} {Q : A → Type q}
{x y : A} {eq : x ≡ y} {f : P x ≃ Q x} →
_≃_.from (subst (λ x → P x ≃ Q x) eq f) ≡
subst (λ x → Q x → P x) eq (_≃_.from f)
from-subst {P = P} {Q = Q} {eq = eq} {f = f} = elim¹
(λ eq →
_≃_.from (subst (λ x → P x ≃ Q x) eq f) ≡
subst (λ x → Q x → P x) eq (_≃_.from f))
(_≃_.from (subst (λ x → P x ≃ Q x) (refl _) f) ≡⟨ cong _≃_.from $ subst-refl (λ _ → _ ≃ _) _ ⟩
_≃_.from f ≡⟨ sym $ subst-refl _ _ ⟩∎
subst (λ x → Q x → P x) (refl _) (_≃_.from f) ∎)
eq
-- If P is pointwise equivalent to x ≡_, then every function of type
-- {y : A} → x ≡ y → P y is an equivalence (pointwise).
--
-- Andrea Vezzosi showed me a similar result, that he thought that
-- Thierry Coquand had informed him about.
≡≃→≡→→Is-equivalence :
∀ {a p} {A : Type a} {x : A}
(P : A → Type p) →
({y : A} → (x ≡ y) ≃ P y) →
(f : {y : A} → x ≡ y → P y) →
{y : A} → Is-equivalence (f {y = y})
≡≃→≡→→Is-equivalence {x = x} P ≡≃P f {y = y} =
drop-Σ-map-id f equiv₂ y
where
equiv₁ : (∃ λ y → x ≡ y) ≃ ∃ P
equiv₁ = ∃-cong λ _ → ≡≃P
contr : Contractible (∃ P)
contr =
H-level.respects-surjection
(_≃_.surjection equiv₁)
0
(other-singleton-contractible _)
equiv₂ : Is-equivalence (Σ-map P.id f)
equiv₂ =
_≃_.is-equivalence $
with-other-function
equiv₁
_
(λ _ → mono₁ 0 contr _ _)
|
{
"alphanum_fraction": 0.4504995612,
"avg_line_length": 38.9815789474,
"ext": "agda",
"hexsha": "f1f798a6f6088c1936e9628b6ca4f3438b3d141d",
"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/Equivalence.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/Equivalence.agda",
"max_line_length": 166,
"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/Equivalence.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": 21810,
"size": 59252
}
|
module Data.Char.Instance where
open import Agda.Builtin.Char
open import Class.Equality
open import Class.Show
open import Data.Char renaming (_≟_ to _≟C_)
open import Data.List
open import Data.String
instance
Char-Eq : Eq Char
Char-Eq = record { _≟_ = _≟C_ }
Char-EqB : EqB Char
Char-EqB = record { _≣_ = primCharEquality }
Char-Show : Show Char
Char-Show = record { show = λ c -> fromList [ c ] }
CharList-Show : Show (List Char)
CharList-Show = record { show = fromList }
|
{
"alphanum_fraction": 0.6947791165,
"avg_line_length": 22.6363636364,
"ext": "agda",
"hexsha": "15b43a437d394dee024ffa4a5be92e03975a595c",
"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/Char/Instance.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/Char/Instance.agda",
"max_line_length": 53,
"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/Char/Instance.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": 155,
"size": 498
}
|
{-# OPTIONS --without-K --rewriting #-}
module lib.types.Types where
open import lib.Basics
open import lib.types.BigWedge public
open import lib.types.Bool public
open import lib.types.Choice public
open import lib.types.Circle public
open import lib.types.Cofiber public
open import lib.types.CommutingSquare public
open import lib.types.Coproduct public
open import lib.types.Cospan public
open import lib.types.Cover public
open import lib.types.EilenbergMacLane1 public
open import lib.types.Empty public
open import lib.types.Fin public
open import lib.types.NatColim public
open import lib.types.Group public
open import lib.types.GroupSet public
open import lib.types.Groupoid public
open import lib.types.HList public
open import lib.types.Int public
open import lib.types.IteratedSuspension public
open import lib.types.Join public
open import lib.types.Lift public
open import lib.types.List public
open import lib.types.LoopSpace public
open import lib.types.Modality public
open import lib.types.Nat public
open import lib.types.PathSeq public
open import lib.types.PathSet public
open import lib.types.Paths public
open import lib.types.Pi public
open import lib.types.Pointed public
open import lib.types.Pullback public
open import lib.types.Pushout public
open import lib.types.PushoutFlattening public
open import lib.types.PushoutFlip public
open import lib.types.PushoutFmap public
open import lib.types.SetQuotient public
open import lib.types.Sigma public
open import lib.types.Smash public
open import lib.types.Span public
open import lib.types.Subtype public
open import lib.types.Suspension public
open import lib.types.TLevel public
open import lib.types.Torus public
open import lib.types.Truncation public
open import lib.types.Unit public
open import lib.types.Wedge public
open import lib.types.Word public
-- This should probably not be exported
-- module Generic1HIT {i j} (A : Type i) (B : Type j) (f g : B → A) where
-- open import lib.types.Generic1HIT A B f g public
|
{
"alphanum_fraction": 0.8168242907,
"avg_line_length": 35.2456140351,
"ext": "agda",
"hexsha": "1549a581bff7bf660727b3989b55c7fc2dbf66f8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Types.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Types.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Types.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 466,
"size": 2009
}
|
{-# OPTIONS --without-K --safe #-}
module Algebra.Linear.Core where
open import Relation.Binary
open import Relation.Nullary using (¬_)
open import Level using (_⊔_)
open import Data.Fin using (Fin; suc; zero)
VectorAddition : ∀ {c} -> Set c -> Set c
VectorAddition V = V -> V -> V
ScalarMultiplication : ∀ {c k} -> Set k -> Set c -> Set (k ⊔ c)
ScalarMultiplication K V = K -> V -> V
|
{
"alphanum_fraction": 0.6606683805,
"avg_line_length": 25.9333333333,
"ext": "agda",
"hexsha": "cbd3b7c6aeb6db17928f32252382022e97c86ec5",
"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": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"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": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Core.agda",
"max_line_length": 63,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 111,
"size": 389
}
|
{-# OPTIONS --cubical --safe #-}
open import Prelude
open import Relation.Binary
module Relation.Binary.Construct.LowerBound {e} {E : Type e} {r} (totalOrder : TotalOrder E r) where
open TotalOrder totalOrder renaming (refl to ≤-refl)
import Data.Unit.UniversePolymorphic as Poly
import Data.Empty.UniversePolymorphic as Poly
data ⌊∙⌋ : Type e where
⌊⊥⌋ : ⌊∙⌋
⌊_⌋ : E → ⌊∙⌋
_≤⌊_⌋ : ⌊∙⌋ → E → Type r
⌊⊥⌋ ≤⌊ y ⌋ = Poly.⊤
⌊ x ⌋ ≤⌊ y ⌋ = x ≤ y
_⌊≤⌋_ : ⌊∙⌋ → ⌊∙⌋ → Type r
x ⌊≤⌋ ⌊ y ⌋ = x ≤⌊ y ⌋
⌊⊥⌋ ⌊≤⌋ ⌊⊥⌋ = Poly.⊤
⌊ x ⌋ ⌊≤⌋ ⌊⊥⌋ = Poly.⊥
lb-ord : TotalOrder ⌊∙⌋ r
PartialOrder._≤_ (TotalOrder.partialOrder lb-ord) = _⌊≤⌋_
PartialOrder.refl (partialOrder lb-ord) {⌊⊥⌋} = Poly.tt
PartialOrder.refl (partialOrder lb-ord) {⌊ x ⌋} = ≤-refl
PartialOrder.antisym (TotalOrder.partialOrder lb-ord) {⌊⊥⌋} {⌊⊥⌋} x≤y y≤x _ = ⌊⊥⌋
PartialOrder.antisym (TotalOrder.partialOrder lb-ord) {⌊ x ⌋} {⌊ x₁ ⌋} x≤y y≤x i = ⌊ antisym x≤y y≤x i ⌋
PartialOrder.trans (TotalOrder.partialOrder lb-ord) {⌊⊥⌋} {⌊⊥⌋} {⌊⊥⌋} x≤y y≤z = Poly.tt
PartialOrder.trans (TotalOrder.partialOrder lb-ord) {⌊⊥⌋} {⌊⊥⌋} {⌊ x ⌋} x≤y y≤z = Poly.tt
PartialOrder.trans (TotalOrder.partialOrder lb-ord) {⌊⊥⌋} {⌊ x ⌋} {⌊ x₁ ⌋} x≤y y≤z = Poly.tt
PartialOrder.trans (TotalOrder.partialOrder lb-ord) {⌊ x ⌋} {⌊ x₁ ⌋} {⌊ x₂ ⌋} x≤y y≤z = trans x≤y y≤z
TotalOrder._≤?_ lb-ord ⌊⊥⌋ ⌊⊥⌋ = inl Poly.tt
TotalOrder._≤?_ lb-ord ⌊ x ⌋ ⌊⊥⌋ = inr Poly.tt
TotalOrder._≤?_ lb-ord ⌊⊥⌋ ⌊ x₁ ⌋ = inl Poly.tt
TotalOrder._≤?_ lb-ord ⌊ x ⌋ ⌊ y ⌋ = x ≤? y
|
{
"alphanum_fraction": 0.5937291528,
"avg_line_length": 37.475,
"ext": "agda",
"hexsha": "b47f5888fedb2b33f2670b2f1950c1fa54649c71",
"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/Relation/Binary/Construct/LowerBound.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/Relation/Binary/Construct/LowerBound.agda",
"max_line_length": 104,
"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/Relation/Binary/Construct/LowerBound.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": 903,
"size": 1499
}
|
module Logic.DiagonalMethod where
open import Functional
open import Logic.Predicate
open import Logic.Propositional
import Lvl
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Function.Domain
open import Structure.Operator
open import Structure.Relator.Properties
open import Syntax.Function
open import Type.Size
open import Type
private variable ℓ : Lvl.Level
private variable T A B : Type{ℓ}
-- Also called: Diagonal method, Cantor's diagonal argument.
function-type-surjectivity-fixpoint : (A ≽ (A → B)) → ∀{f : B → B} → ∃(Fixpoint f)
function-type-surjectivity-fixpoint ([∃]-intro s) {f}
with [∃]-intro i ⦃ p ⦄ ← surjective(s) {f ∘ (s $₂_)}
= [∃]-intro(s i i) ⦃ intro(symmetry(_≡_) (congruence₂ₗ(_$_)(i) p)) ⦄
module _ where
open import Data.Boolean
open import Data.Boolean.Proofs
decidable-power-set-no-surjection : ¬(T ≽ (T → Bool))
decidable-power-set-no-surjection = (p ↦ [!]-no-fixpoints(Fixpoint.proof([∃]-proof(p{not})))) ∘ function-type-surjectivity-fixpoint
module _ where
open import Data.Boolean
open import Data.Boolean.Proofs
open import Function.Inverseᵣ
open import Structure.Function.Domain.Proofs
open import Structure.Function
open import Syntax.Transitivity
function-type-no-surjection : (B ≽ Bool) → ¬(A ≽ (A → B))
function-type-no-surjection ([∃]-intro r-bool) surj
with [∃]-intro i ⦃ fix ⦄ ← function-type-surjectivity-fixpoint surj {invᵣ r-bool ⦃ surjective-to-invertibleᵣ ⦄ ∘ not ∘ r-bool}
= [!]-no-fixpoints(symmetry(_≡_) (Inverseᵣ.proof surjective-to-inverseᵣ) 🝖 congruence₁(r-bool) (Fixpoint.proof fix))
module _ where
open import Numeral.Natural
open import Numeral.Natural.Oper.Proofs
ℕ-function-non-surjectivity : ¬(ℕ ≽ (ℕ → ℕ))
ℕ-function-non-surjectivity = (p ↦ 𝐒-not-self(Fixpoint.proof([∃]-proof(p{𝐒})))) ∘ function-type-surjectivity-fixpoint
|
{
"alphanum_fraction": 0.723347548,
"avg_line_length": 36.7843137255,
"ext": "agda",
"hexsha": "0cd7b0ce0d37e0ed0c639b2c6c74d9dff26f6e39",
"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": "Logic/DiagonalMethod.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": "Logic/DiagonalMethod.agda",
"max_line_length": 133,
"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": "Logic/DiagonalMethod.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": 594,
"size": 1876
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.