Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
module lib.Relation {i} where
Rel : ∀ (A : Type i) j → Type (lmax i (lsucc j))
Rel A j = A → A → Type j
module _ {A : Type i} {j} (rel : Rel A j) where
Decidable : Type (lmax i j)
Decidable = ∀ a₁ a₂ → Dec (rel a₁ a₂)
is-refl : Type (lmax i j)
is-refl = ∀ a → rel a a
is-sym : Type (lmax i j)
is-sym = ∀ {a b} → rel a b → rel b a
is-trans : Type (lmax i j)
is-trans = ∀ {a b c} → rel a b → rel b c → rel a c
-- as equivalence relation
-- is-equational : Type (lmax i j)
| {
"alphanum_fraction": 0.5625,
"avg_line_length": 21.5384615385,
"ext": "agda",
"hexsha": "9c66729633825bcaeabb9057e5ba2d8a2d29a036",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/Relation.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/Relation.agda",
"max_line_length": 52,
"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/Relation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 212,
"size": 560
} |
------------------------------------------------------------------------
-- Some defined operations (multiplication by natural number and
-- exponentiation)
------------------------------------------------------------------------
open import Algebra
module Algebra.Operations (s : Semiring) where
open Semiring s hiding (zero)
open import Data.Nat using (zero; suc; ℕ)
open import Data.Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_)
import Relation.Binary.EqReasoning as EqR
open EqR setoid
------------------------------------------------------------------------
-- Operations
-- Multiplication by natural number.
infixr 7 _×_
_×_ : ℕ → carrier → carrier
zero × x = 0#
suc n × x = x + n × x
-- Exponentiation.
infixr 8 _^_
_^_ : carrier → ℕ → carrier
x ^ zero = 1#
x ^ suc n = x * x ^ n
------------------------------------------------------------------------
-- Some properties
×-pres-≈ : _×_ Preserves₂ _≡_ ⟶ _≈_ ⟶ _≈_
×-pres-≈ {n} {n'} {x} {x'} n≡n' x≈x' = begin
n × x ≈⟨ reflexive $ PropEq.cong (λ n → n × x) n≡n' ⟩
n' × x ≈⟨ ×-pres-≈ʳ n' x≈x' ⟩
n' × x' ∎
where
×-pres-≈ʳ : ∀ n → (_×_ n) Preserves _≈_ ⟶ _≈_
×-pres-≈ʳ zero x≈x' = refl
×-pres-≈ʳ (suc n) x≈x' = x≈x' ⟨ +-pres-≈ ⟩ ×-pres-≈ʳ n x≈x'
^-pres-≈ : _^_ Preserves₂ _≈_ ⟶ _≡_ ⟶ _≈_
^-pres-≈ {x} {x'} {n} {n'} x≈x' n≡n' = begin
x ^ n ≈⟨ reflexive $ PropEq.cong (_^_ x) n≡n' ⟩
x ^ n' ≈⟨ ^-pres-≈ˡ n' x≈x' ⟩
x' ^ n' ∎
where
^-pres-≈ˡ : ∀ n → (λ x → x ^ n) Preserves _≈_ ⟶ _≈_
^-pres-≈ˡ zero x≈x' = refl
^-pres-≈ˡ (suc n) x≈x' = x≈x' ⟨ *-pres-≈ ⟩ ^-pres-≈ˡ n x≈x'
| {
"alphanum_fraction": 0.4662203287,
"avg_line_length": 27.8474576271,
"ext": "agda",
"hexsha": "8a9b418ac18ec3ca2bdec9c11ee8aff9ad349d41",
"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/Algebra/Operations.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/Algebra/Operations.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/Algebra/Operations.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": 657,
"size": 1643
} |
module WellFormed where
data Nat : Set where
zero : Nat
succ : Nat -> Nat
postulate Vec : Set -> Nat -> Set
postulate _X_ : Set -> Set -> Set
postulate zip : {A B : Set} -> (n : Nat) -> Vec A n -> Vec B n -> Vec (A X B) n
| {
"alphanum_fraction": 0.5833333333,
"avg_line_length": 22.8,
"ext": "agda",
"hexsha": "dd6208cfc8ecd3fcfad05067168dafe4727114fc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/WellFormed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/WellFormed.agda",
"max_line_length": 79,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/WellFormed.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 79,
"size": 228
} |
{-# OPTIONS --prop --rewriting #-}
open import Examples.Sorting.Sequential.Comparable
module Examples.Sorting.Sequential.InsertionSort (M : Comparable) where
open Comparable M
open import Examples.Sorting.Sequential.Core M
open import Calf costMonoid
open import Calf.Types.Bool
open import Calf.Types.List
open import Calf.Types.Eq
open import Calf.Types.Bounded costMonoid
open import Calf.Types.BigO costMonoid
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; module ≡-Reasoning)
open import Data.Product using (_×_; _,_; ∃)
open import Data.Sum using (inj₁; inj₂)
open import Function
open import Data.Nat as Nat using (ℕ; zero; suc; z≤n; s≤s; _+_; _*_)
import Data.Nat.Properties as N
open import Data.Nat.Square
insert : cmp (Π A λ _ → Π (list A) λ _ → F (list A))
insert x [] = ret [ x ]
insert x (y ∷ ys) =
bind (F (list A)) (x ≤ᵇ y)
λ { false → bind (F (list A)) (insert x ys) (ret ∘ (y ∷_))
; true → ret (x ∷ (y ∷ ys)) }
insert/correct : ∀ x l → Sorted l → ◯ (∃ λ l' → insert x l ≡ ret l' × SortedOf (x ∷ l) l')
insert/correct x [] [] u = [ x ] , refl , refl , [] ∷ []
insert/correct x (y ∷ ys) (h ∷ hs) u with h-cost x y
insert/correct x (y ∷ ys) (h ∷ hs) u | ⇓ b withCost q [ _ , h-eq ] rewrite eq/ref h-eq
with ≤ᵇ-reflects-≤ u (Eq.trans (eq/ref h-eq) (step/ext (F bool) (ret b) q u)) | ≤-total x y
insert/correct x (y ∷ ys) (h ∷ hs) u | ⇓ false withCost q [ _ , _ ] | ofⁿ ¬x≤y | inj₁ x≤y = contradiction x≤y ¬x≤y
insert/correct x (y ∷ ys) (h ∷ hs) u | ⇓ false withCost q [ _ , _ ] | ofⁿ ¬x≤y | inj₂ x≤y =
let (ys' , h-ys' , x∷ys↭ys' , sorted-ys') = insert/correct x ys hs u in
y ∷ ys' , (
let open ≡-Reasoning in
begin
step (F (list A)) q (bind (F (list A)) (insert x ys) (ret ∘ (y ∷_)))
≡⟨ step/ext (F (list A)) (bind (F (list A)) (insert x ys) (ret ∘ (y ∷_))) q u ⟩
bind (F (list A)) (insert x ys) (ret ∘ (y ∷_))
≡⟨ Eq.cong (λ e → bind (F (list A)) e (ret ∘ (y ∷_))) h-ys' ⟩
ret (y ∷ ys')
∎
) , (
let open PermutationReasoning in
begin
x ∷ y ∷ ys
<<⟨ refl ⟩
y ∷ (x ∷ ys)
<⟨ x∷ys↭ys' ⟩
y ∷ ys'
∎
) , All-resp-↭ x∷ys↭ys' (x≤y ∷ h) ∷ sorted-ys'
insert/correct x (y ∷ ys) (h ∷ hs) u | ⇓ true withCost q [ _ , _ ] | ofʸ x≤y | _ =
x ∷ (y ∷ ys) , step/ext (F (list A)) (ret _) q u , refl , (x≤y ∷ ≤-≤* x≤y h) ∷ (h ∷ hs)
insert/cost : cmp (Π A λ _ → Π (list A) λ _ → cost)
insert/cost x [] = zero
insert/cost x (y ∷ ys) with h-cost x y
... | ⇓ false withCost q [ q≤1 , h-eq ] = q + (insert/cost x ys + zero)
... | ⇓ true withCost q [ q≤1 , h-eq ] = q + 0
insert/cost/closed : cmp (Π A λ _ → Π (list A) λ _ → cost)
insert/cost/closed x l = length l
insert/cost≤insert/cost/closed : ∀ x l → ◯ (insert/cost x l Nat.≤ insert/cost/closed x l)
insert/cost≤insert/cost/closed x [] u = N.≤-refl
insert/cost≤insert/cost/closed x (y ∷ ys) u with h-cost x y
... | ⇓ false withCost q [ q≤1 , h-eq ] =
Eq.subst (λ n → (q + n) Nat.≤ (suc (length ys))) (Eq.sym (+-identityʳ (insert/cost x ys))) (
N.≤-trans
(+-monoˡ-≤ _ (q≤1 u))
(s≤s (insert/cost≤insert/cost/closed x ys u))
)
... | ⇓ true withCost q [ q≤1 , h-eq ] =
Eq.subst (Nat._≤ (suc (length ys))) (Eq.sym (+-identityʳ q)) (
N.≤-trans (q≤1 u) (s≤s z≤n)
)
insert≤insert/cost : ∀ x l → IsBounded (list A) (insert x l) (insert/cost x l)
insert≤insert/cost x [] = bound/ret
insert≤insert/cost x (y ∷ ys) with h-cost x y
... | ⇓ false withCost q [ q≤1 , h-eq ] rewrite eq/ref h-eq =
bound/step q (insert/cost x ys + 0) (bound/bind/const (insert/cost x ys) 0 (insert≤insert/cost x ys) λ _ → bound/ret)
... | ⇓ true withCost q [ q≤1 , h-eq ] rewrite eq/ref h-eq =
bound/step q 0 bound/ret
insert≤insert/cost/closed : ∀ x l → IsBounded (list A) (insert x l) (insert/cost/closed x l)
insert≤insert/cost/closed x l = bound/relax (insert/cost≤insert/cost/closed x l) (insert≤insert/cost x l)
sort : cmp (Π (list A) λ _ → F (list A))
sort [] = ret []
sort (x ∷ xs) = bind (F (list A)) (sort xs) (insert x)
sort/correct : IsSort sort
sort/correct [] u = [] , refl , refl , []
sort/correct (x ∷ xs) u =
let (xs' , h-xs' , xs↭xs' , sorted-xs' ) = sort/correct xs u in
let (x∷xs' , h-x∷xs' , x∷xs↭x∷xs' , sorted-x∷xs') = insert/correct x xs' sorted-xs' u in
x∷xs' , (
let open ≡-Reasoning in
begin
sort (x ∷ xs)
≡⟨⟩
bind (F (list A)) (sort xs) (insert x)
≡⟨ Eq.cong (λ e → bind (F (list A)) e (insert x)) h-xs' ⟩
bind (F (list A)) (ret {list A} xs') (insert x)
≡⟨⟩
insert x xs'
≡⟨ h-x∷xs' ⟩
ret x∷xs'
∎
) , (
let open PermutationReasoning in
begin
x ∷ xs
<⟨ xs↭xs' ⟩
x ∷ xs'
↭⟨ x∷xs↭x∷xs' ⟩
x∷xs'
∎
) , sorted-x∷xs'
sort/cost : cmp (Π (list A) λ _ → cost)
sort/cost [] = 0
sort/cost (x ∷ xs) = bind cost (sort xs) (λ xs' → sort/cost xs + insert/cost/closed x xs')
sort/cost/closed : cmp (Π (list A) λ _ → cost)
sort/cost/closed l = length l ²
sort/cost≤sort/cost/closed : ∀ l → ◯ (sort/cost l Nat.≤ sort/cost/closed l)
sort/cost≤sort/cost/closed [] u = N.≤-refl
sort/cost≤sort/cost/closed (x ∷ xs) u =
let (xs' , ≡ , ↭ , sorted) = sort/correct xs u in
begin
sort/cost (x ∷ xs)
≡⟨⟩
bind cost (sort xs) (λ xs' → sort/cost xs + length xs')
≡⟨ Eq.cong (λ e → bind cost e λ xs' → sort/cost xs + length xs') (≡) ⟩
sort/cost xs + length xs'
≡˘⟨ Eq.cong (sort/cost xs +_) (↭-length ↭) ⟩
sort/cost xs + length xs
≤⟨ +-monoˡ-≤ (insert/cost/closed x xs) (sort/cost≤sort/cost/closed xs u) ⟩
sort/cost/closed xs + insert/cost/closed x xs
≡⟨⟩
length xs ² + length xs
≤⟨ lemma/arithmetic (length xs) ⟩
length (x ∷ xs) ²
≡⟨⟩
sort/cost/closed (x ∷ xs)
∎
where
open ≤-Reasoning
lemma/arithmetic : ∀ n → n ² + n Nat.≤ suc n ²
lemma/arithmetic n =
begin
n ² + n
≡⟨ N.+-comm (n ²) n ⟩
n + n ²
≡⟨⟩
n + n * n
≤⟨ N.m≤n+m (n + n * n) (suc n) ⟩
suc n + (n + n * n)
≡⟨⟩
suc (n + (n + n * n))
≡˘⟨ Eq.cong (λ m → suc (n + m)) (N.*-suc n n) ⟩
suc (n + n * suc n)
≡⟨⟩
suc n ²
∎
sort≤sort/cost : ∀ l → IsBounded (list A) (sort l) (sort/cost l)
sort≤sort/cost [] = bound/ret
sort≤sort/cost (x ∷ xs) = bound/bind (sort/cost xs) (insert/cost/closed x) (sort≤sort/cost xs) (insert≤insert/cost/closed x)
sort≤sort/cost/closed : ∀ l → IsBounded (list A) (sort l) (sort/cost/closed l)
sort≤sort/cost/closed l = bound/relax (sort/cost≤sort/cost/closed l) (sort≤sort/cost l)
sort/asymptotic : given (list A) measured-via length , sort ∈𝓞(λ n → n ²)
sort/asymptotic = 0 ≤n⇒f[n]≤g[n]via λ l _ → sort≤sort/cost/closed l
| {
"alphanum_fraction": 0.5570322769,
"avg_line_length": 36.0368421053,
"ext": "agda",
"hexsha": "5f3843faef1bdb9c3a6f7962735a2d5886c0f2c8",
"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/Sorting/Sequential/InsertionSort.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/Sorting/Sequential/InsertionSort.agda",
"max_line_length": 124,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Examples/Sorting/Sequential/InsertionSort.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": 2842,
"size": 6847
} |
postulate Name : Set
{-# BUILTIN QNAME Name #-}
data ⊤ : Set where
tt : ⊤
data Term : Set where
con : Name → Term → Term
data X : ⊤ → Set where
x : {t : ⊤} → X t
data Y : Set where
y : Y
-- this type checks
g : {t : ⊤} → Term → X t
g {t} (con nm args) = x {t}
-- this doesn't
f : {t : ⊤} → Term → X t
f {t} (con (quote Y.y) args) = x {t}
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- offending line is above
f t = x
-- t != args of type ⊤
-- when checking that the expression x {t} has type X args
| {
"alphanum_fraction": 0.5049115914,
"avg_line_length": 16.4193548387,
"ext": "agda",
"hexsha": "6756204bcafdad40c93f9a94937c8d0f2332318e",
"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/Issue1610.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/Issue1610.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1610.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 191,
"size": 509
} |
{-# OPTIONS --without-K #-}
module well-typed-quoted-syntax-defs where
open import common
open import well-typed-syntax
open import well-typed-syntax-helpers
open import well-typed-syntax-context-helpers
‘ε’ : Term {Γ = ε} ‘Context’
‘ε’ = ⌜ ε ⌝c
‘□’ : Typ (ε ▻ ‘Typ’ ‘’ ‘ε’)
‘□’ = ‘Term’ ‘’₁ ‘ε’
| {
"alphanum_fraction": 0.6510067114,
"avg_line_length": 22.9230769231,
"ext": "agda",
"hexsha": "de365ce771350b0c1156607d40a3cb9fd2012bdf",
"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-quoted-syntax-defs.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-quoted-syntax-defs.agda",
"max_line_length": 45,
"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-quoted-syntax-defs.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": 109,
"size": 298
} |
module Data.Fin.Map where
open import Class.Monad
open import Data.Nat
open import Data.Fin
open import Function
DepFinMap : ∀ {a} (n : ℕ) (A : Fin n -> Set a) -> Set a
DepFinMap n A = (k : Fin n) -> A k
FinMap : ∀ {a} (n : ℕ) -> Set a -> Set a
FinMap n A = DepFinMap n (λ _ -> A)
sequenceDepFinMap : ∀ {a n A} {M : Set a -> Set a} {{_ : Monad M}}
-> DepFinMap n (λ x -> M $ A x) -> M (DepFinMap n A)
sequenceDepFinMap {n = zero} f = return λ ()
sequenceDepFinMap {n = suc n} f = do
f' <- sequenceDepFinMap $ f ∘ suc
fzero <- f zero
return λ
{ zero → fzero
; (suc v) → f' v}
| {
"alphanum_fraction": 0.581512605,
"avg_line_length": 25.8695652174,
"ext": "agda",
"hexsha": "72012effd2db4c5852c6cb54dfeff9e59e39a773",
"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/Fin/Map.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/Fin/Map.agda",
"max_line_length": 66,
"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/Fin/Map.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": 226,
"size": 595
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Wedge where
open import Cubical.HITs.Wedge.Base public
| {
"alphanum_fraction": 0.7401574803,
"avg_line_length": 25.4,
"ext": "agda",
"hexsha": "859627437afbad233d9b9f634ff5aaca52a901ec",
"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/HITs/Wedge.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/HITs/Wedge.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/HITs/Wedge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 36,
"size": 127
} |
postulate
A : Set
P : A → Set
variable
x : A
y : P x
data D₁ {x : A} : P x → Set where
z : D₁ y
s : D₁ y → D₁ y
data D₂ : {x : A} → P x → Set where
z : D₂ y
s : D₂ y → D₂ y
| {
"alphanum_fraction": 0.4611398964,
"avg_line_length": 11.3529411765,
"ext": "agda",
"hexsha": "7c14a20154c85f0ce738953ff7016e1ede9beeb9",
"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/Issue3362.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/Issue3362.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/Issue3362.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": 96,
"size": 193
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Ring where
open import Cubical.Algebra.Ring.Base public
open import Cubical.Algebra.Ring.Properties public
| {
"alphanum_fraction": 0.7802197802,
"avg_line_length": 30.3333333333,
"ext": "agda",
"hexsha": "6b199fffc24aab607eb4e939ec028d0ee04cfc6f",
"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": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "knrafto/cubical",
"max_forks_repo_path": "Cubical/Algebra/Ring.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"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": "knrafto/cubical",
"max_issues_repo_path": "Cubical/Algebra/Ring.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "knrafto/cubical",
"max_stars_repo_path": "Cubical/Algebra/Ring.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 45,
"size": 182
} |
module _ where
data Unit : Set where
unit : Unit
data D₁ : Set where
c₁ : D₁
module M (_ : Set₁) where
data D₂ : Set where
c₂ : D₂
open M Set
f : D₁ → D₂
f c₁ = c₂
record R (A : Set) : Set where
field a : A
open R ⦃ … ⦄ public
instance
r₁ : R D₁
r₁ = record { a = c₁ }
r₂ : ⦃ r : R D₁ ⦄ → R D₂
r₂ ⦃ r ⦄ = record { a = f (R.a r) }
postulate
P : (A : Set) → A → Set
g : (A : Set) (x : A) → P A x
accepted : P D₂ a
accepted = g D₂ a
rejected : P D₂ a
rejected = g _ a
-- WAS:
-- No instance of type (R D₂) was found in scope.
-- when checking that the expression a has type D₂
-- SHOULD: succeed
| {
"alphanum_fraction": 0.5581761006,
"avg_line_length": 13.8260869565,
"ext": "agda",
"hexsha": "d84d9ea310acbcbdf176e25f910346d2123b5e5d",
"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/Issue3434.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/Issue3434.agda",
"max_line_length": 52,
"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/Issue3434.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": 261,
"size": 636
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- Properties relating Initial and Terminal Objects,
-- Product / Coproduct, Zero objects, and Kernel / Cokernel via op
module Categories.Object.Duality {o ℓ e} (C : Category o ℓ e) where
open Category C
open import Level
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
open import Categories.Morphism C
open import Categories.Object.Terminal op
open import Categories.Object.Initial C
open import Categories.Object.Product op
open import Categories.Object.Coproduct C
open import Categories.Object.Zero
import Categories.Object.Kernel as Kernels
import Categories.Object.Cokernel as Cokernels
private
variable
A B X Z : Obj
f g k : A ⇒ B
IsInitial⇒coIsTerminal : IsInitial X → IsTerminal X
IsInitial⇒coIsTerminal is⊥ = record
{ ! = !
; !-unique = !-unique
}
where open IsInitial is⊥
⊥⇒op⊤ : Initial → Terminal
⊥⇒op⊤ i = record
{ ⊤ = ⊥
; ⊤-is-terminal = IsInitial⇒coIsTerminal ⊥-is-initial
}
where open Initial i
coIsTerminal⇒IsInitial : IsTerminal X → IsInitial X
coIsTerminal⇒IsInitial is⊤ = record
{ ! = !
; !-unique = !-unique
}
where open IsTerminal is⊤
op⊤⇒⊥ : Terminal → Initial
op⊤⇒⊥ t = record
{ ⊥ = ⊤
; ⊥-is-initial = coIsTerminal⇒IsInitial ⊤-is-terminal
}
where open Terminal t
Coproduct⇒coProduct : Coproduct A B → Product A B
Coproduct⇒coProduct A+B = record
{ A×B = A+B.A+B
; π₁ = A+B.i₁
; π₂ = A+B.i₂
; ⟨_,_⟩ = A+B.[_,_]
; project₁ = A+B.inject₁
; project₂ = A+B.inject₂
; unique = A+B.unique
}
where
module A+B = Coproduct A+B
coProduct⇒Coproduct : ∀ {A B} → Product A B → Coproduct A B
coProduct⇒Coproduct A×B = record
{ A+B = A×B.A×B
; i₁ = A×B.π₁
; i₂ = A×B.π₂
; [_,_] = A×B.⟨_,_⟩
; inject₁ = A×B.project₁
; inject₂ = A×B.project₂
; unique = A×B.unique
}
where
module A×B = Product A×B
-- Zero objects are autodual
IsZero⇒coIsZero : IsZero C Z → IsZero op Z
IsZero⇒coIsZero is-zero = record
{ isInitial = record { ! = ! ; !-unique = !-unique }
; isTerminal = record { ! = ¡ ; !-unique = ¡-unique }
}
where
open IsZero is-zero
coIsZero⇒IsZero : IsZero op Z → IsZero C Z
coIsZero⇒IsZero co-is-zero = record
{ isInitial = record { ! = ! ; !-unique = !-unique }
; isTerminal = record { ! = ¡ ; !-unique = ¡-unique }
}
where
open IsZero co-is-zero
coZero⇒Zero : Zero op → Zero C
coZero⇒Zero zero = record
{ 𝟘 = 𝟘
; isZero = coIsZero⇒IsZero isZero
}
where
open Zero zero
Zero⇒coZero : Zero C → Zero op
Zero⇒coZero zero = record
{ 𝟘 = 𝟘
; isZero = IsZero⇒coIsZero isZero
}
where
open Zero zero
-- Tests to ensure that dualities are involutive up to definitional equality.
private
coIsTerminal⟺IsInitial : (⊥ : IsInitial X) → coIsTerminal⇒IsInitial (IsInitial⇒coIsTerminal ⊥) ≡ ⊥
coIsTerminal⟺IsInitial _ = ≡.refl
IsInitial⟺coIsTerminal : (⊤ : IsTerminal X) → IsInitial⇒coIsTerminal (coIsTerminal⇒IsInitial ⊤) ≡ ⊤
IsInitial⟺coIsTerminal _ = ≡.refl
⊥⟺op⊤ : (⊤ : Terminal) → ⊥⇒op⊤ (op⊤⇒⊥ ⊤) ≡ ⊤
⊥⟺op⊤ _ = ≡.refl
op⊤⟺⊥ : (⊥ : Initial) → op⊤⇒⊥ (⊥⇒op⊤ ⊥) ≡ ⊥
op⊤⟺⊥ _ = ≡.refl
Coproduct⟺coProduct : (p : Product A B) → Coproduct⇒coProduct (coProduct⇒Coproduct p) ≡ p
Coproduct⟺coProduct _ = ≡.refl
coProduct⟺Coproduct : (p : Coproduct A B) → coProduct⇒Coproduct (Coproduct⇒coProduct p) ≡ p
coProduct⟺Coproduct _ = ≡.refl
coIsZero⟺IsZero : {zero : IsZero op Z} → IsZero⇒coIsZero (coIsZero⇒IsZero zero) ≡ zero
coIsZero⟺IsZero = ≡.refl
IsZero⟺coIsZero : ∀ {Z} {zero : IsZero C Z} → coIsZero⇒IsZero (IsZero⇒coIsZero zero) ≡ zero
IsZero⟺coIsZero = ≡.refl
coZero⟺Zero : ∀ {zero : Zero op} → Zero⇒coZero (coZero⇒Zero zero) ≡ zero
coZero⟺Zero = ≡.refl
Zero⟺coZero : ∀ {zero : Zero C} → coZero⇒Zero (Zero⇒coZero zero) ≡ zero
Zero⟺coZero = ≡.refl
module _ (𝟎 : Zero C) where
open Kernels (Zero⇒coZero 𝟎)
open Cokernels 𝟎
coIsKernel⇒IsCokernel : IsKernel k f → IsCokernel f k
coIsKernel⇒IsCokernel isKernel = record
{ commute = commute
; universal = universal
; factors = factors
; unique = unique
}
where
open IsKernel isKernel
IsCokernel⇒coIsKernel : IsCokernel f k → IsKernel k f
IsCokernel⇒coIsKernel isCokernel = record
{ commute = commute
; universal = universal
; factors = factors
; unique = unique
}
where
open IsCokernel isCokernel
coKernel⇒Cokernel : Kernel f → Cokernel f
coKernel⇒Cokernel k = record
{ cokernel⇒ = kernel⇒
; isCokernel = coIsKernel⇒IsCokernel isKernel
}
where
open Kernel k
Cokernel⇒coKernel : Cokernel f → Kernel f
Cokernel⇒coKernel k = record
{ kernel⇒ = cokernel⇒
; isKernel = IsCokernel⇒coIsKernel isCokernel
}
where
open Cokernel k
private
coIsKernel⟺IsCokernel : ∀ {isKernel : IsKernel k f} → IsCokernel⇒coIsKernel (coIsKernel⇒IsCokernel isKernel) ≡ isKernel
coIsKernel⟺IsCokernel = ≡.refl
IsCokernel⟺coIsKernel : ∀ {isCokernel : IsCokernel f k} → coIsKernel⇒IsCokernel (IsCokernel⇒coIsKernel isCokernel) ≡ isCokernel
IsCokernel⟺coIsKernel = ≡.refl
coKernel⟺Cokernel : ∀ {kernel : Kernel f} → Cokernel⇒coKernel (coKernel⇒Cokernel kernel) ≡ kernel
coKernel⟺Cokernel = ≡.refl
Cokernel⟺coKernel : ∀ {cokernel : Cokernel f} → coKernel⇒Cokernel (Cokernel⇒coKernel cokernel) ≡ cokernel
Cokernel⟺coKernel = ≡.refl
| {
"alphanum_fraction": 0.6552544855,
"avg_line_length": 27.31,
"ext": "agda",
"hexsha": "4cbf00fe7210e4912a4e94d691b41b9f2faa614b",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Duality.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Duality.agda",
"max_line_length": 131,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Duality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 2197,
"size": 5462
} |
{-# OPTIONS --safe --without-K #-}
open import Relation.Nullary.Decidable using (True; toWitness)
open import Function using (_∘_)
import Data.Product as Product
import Data.Unit as Unit
import Data.Fin as Fin
import Data.Nat as Nat
import Data.Vec as Vec
import Data.Vec.Relation.Unary.All as All
open Product using (Σ; Σ-syntax; _×_; _,_; proj₁)
open Unit using (⊤; tt)
open Nat using (ℕ; zero; suc)
open Fin using (Fin; zero; suc)
open Vec using (Vec; []; _∷_)
open All using (All; []; _∷_)
open import PiCalculus.Syntax
open Scoped
open import PiCalculus.LinearTypeSystem.Algebras
module PiCalculus.LinearTypeSystem (Ω : Algebras) where
open Algebras Ω
infixr 4 _;_⊢_▹_
infixr 4 _;_∋[_]_;_▹_ _∋[_]_▹_ _∋[_]_
infixr 10 ν _⦅⦆_ _⟨_⟩_
private
variable
name : Name
idx idx' : Idx
n : ℕ
i j : Fin n
data Type : Set where
𝟙 : Type
B[_] : ℕ → Type
C[_;_] : Type → (Usage idx) ² → Type
-- P[_&_] : Type → Type → Type
-- Context of types
PreCtx : ℕ → Set
PreCtx = Vec Type
-- Context of usage indices
Idxs : ℕ → Set
Idxs = Vec Idx
-- Indexed context of usages
Ctx : ∀ {n} → Idxs n → Set
Ctx = All λ idx → (Usage idx) ²
private
variable
γ : PreCtx n
idxs : Idxs n
Γ Δ Ξ Θ : Ctx idxs
b : ℕ
t t' : Type
x y z : Usage idx
P Q : Scoped n
-- γ ∋[ i ] t is a proof that variable i in Γ has type t
data _∋[_]_ : PreCtx n → Fin n → Type → Set where
zero : γ -, t ∋[ zero ] t
suc : γ ∋[ i ] t → γ -, t' ∋[ suc i ] t
-- Γ ∋[ i ] x ▹ Δ is a proof that subtracting x from variable in in Γ results in Δ
data _∋[_]_▹_ : {idxs : Idxs n} → Ctx idxs → Fin n → (Usage idx) ² → Ctx idxs → Set where
zero : {idxs : Idxs n} {Γ : Ctx idxs} {x y z : Usage idx ²}
→ x ≔ y ∙² z
→ Γ -, x ∋[ zero {n} ] y ▹ Γ -, z
suc : {Γ Δ : Ctx idxs} {x : (Usage idx) ² } {x' : (Usage idx') ²}
→ Γ ∋[ i ] x ▹ Δ
→ Γ -, x' ∋[ suc i ] x ▹ Δ -, x'
-- For convenience, merge together γ ∋[ i ] t and Γ ∋[ i ] x ▹ Δ
_;_∋[_]_;_▹_ : {idxs : Idxs n} → PreCtx n → Ctx idxs → Fin n → Type → (Usage idx) ² → Ctx idxs → Set
γ ; Γ ∋[ i ] t ; x ▹ Δ = (γ ∋[ i ] t) × (Γ ∋[ i ] x ▹ Δ)
-- Constructor for (zero , zero xyz) that computes z from x and y
here : {γ : PreCtx n} {idxs : Idxs n} {Γ : Ctx idxs} {x y : Usage idx ²} ⦃ check : True (∙²-computeʳ x y) ⦄
→ γ -, t ; Γ -, x ∋[ zero ] t ; y ▹ Γ -, proj₁ (toWitness check)
here ⦃ check ⦄ = let _ , x≔y∙²z = toWitness check in zero , zero x≔y∙²z
infixr 20 there_
there_ : {γ : PreCtx n} {idxs : Idxs n} {Γ Δ : Ctx idxs} {x : Usage idx ²} {x' : Usage idx' ²}
→ γ ; Γ ∋[ i ] t ; x ▹ Δ
→ γ -, t' ; Γ -, x' ∋[ suc i ] t ; x ▹ Δ -, x'
there_ (i , j) = suc i , suc j
-- Typing judgment γ ; Γ ⊢ P ▹ Δ where P is a well-typed process
-- under typing context γ and input and output usage contexts Γ and Δ
data _;_⊢_▹_ : {idxs : Idxs n} → PreCtx n → Ctx idxs → Scoped n → Ctx idxs → Set where
𝟘 : γ ; Γ ⊢ 𝟘 ▹ Γ
-- Note (μ , μ): the created channel is balanced
ν : ∀ (t : Type) {idx' : Idx} (m : Usage idx' ²) {idx : Idx} (μ : Usage idx)
→ γ -, C[ t ; m ] ; Γ -, (μ , μ) ⊢ P ▹ Δ -, ℓ∅
-----------------------------------------------------
→ γ ; Γ ⊢ ν P ⦃ name ⦄ ▹ Δ
_⦅⦆_ : ∀ {t : Type} {m : (Usage idx') ²}
→ γ ; Γ ∋[ i ] C[ t ; m ] ; ℓᵢ {idx} ▹ Ξ
→ γ -, t ; Ξ -, m ⊢ P ▹ Θ -, ℓ∅
-----------------------------------------------------------
→ γ ; Γ ⊢ (i ⦅⦆ P) ⦃ name ⦄ ▹ Θ
_⟨_⟩_ : {t : Type} {m : (Usage idx') ²}
→ γ ; Γ ∋[ i ] C[ t ; m ] ; ℓₒ {idx} ▹ Δ
→ γ ; Δ ∋[ j ] t ; m ▹ Ξ
→ γ ; Ξ ⊢ P ▹ Θ
-----------------------------------------
→ γ ; Γ ⊢ i ⟨ j ⟩ P ▹ Θ
_∥_ : γ ; Γ ⊢ P ▹ Δ
→ γ ; Δ ⊢ Q ▹ Ξ
-------------------
→ γ ; Γ ⊢ P ∥ Q ▹ Ξ
_;[_]_⊢_▹_ : PreCtx n → (idxs : Idxs n) → Ctx idxs → Scoped n → Ctx idxs → Set
γ ;[ idxs ] Γ ⊢ P ▹ Δ = _;_⊢_▹_ {idxs = idxs} γ Γ P Δ
| {
"alphanum_fraction": 0.4747425208,
"avg_line_length": 31.6124031008,
"ext": "agda",
"hexsha": "798f46e2ac4dc0ca2c4e305350c820a0cc725070",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z",
"max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/typing-linear-pi",
"max_forks_repo_path": "src/PiCalculus/LinearTypeSystem.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/typing-linear-pi",
"max_issues_repo_path": "src/PiCalculus/LinearTypeSystem.agda",
"max_line_length": 107,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/typing-linear-pi",
"max_stars_repo_path": "src/PiCalculus/LinearTypeSystem.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z",
"num_tokens": 1706,
"size": 4078
} |
------------------------------------------------------------------------
-- A delimited continuation monad
------------------------------------------------------------------------
module Category.Monad.Continuation where
open import Category.Applicative
open import Category.Applicative.Indexed
open import Category.Monad
open import Category.Monad.Indexed
open import Category.Monad.Identity
open import Data.Function
------------------------------------------------------------------------
-- Delimited continuation monads
DContT : {I : Set} → (I → Set) → (Set → Set) → IFun I
DContT K M r₂ r₁ a = (a → M (K r₁)) → M (K r₂)
DCont : {I : Set} → (I → Set) → IFun I
DCont K = DContT K Identity
DContTIMonad : ∀ {I} (K : I → Set) {M} →
RawMonad M → RawIMonad (DContT K M)
DContTIMonad K Mon = record
{ return = λ a k → k a
; _>>=_ = λ c f k → c (flip f k)
}
where open RawMonad Mon
DContIMonad : ∀ {I} (K : I → Set) → RawIMonad (DCont K)
DContIMonad K = DContTIMonad K IdentityMonad
------------------------------------------------------------------------
-- Delimited continuation operations
record RawIMonadDCont {I : Set} (K : I → Set)
(M : I → I → Set → Set) : Set₁ where
field
monad : RawIMonad M
reset : ∀ {r₁ r₂ r₃} → M r₁ r₂ (K r₂) → M r₃ r₃ (K r₁)
shift : ∀ {a r₁ r₂ r₃ r₄} →
((a → M r₁ r₁ (K r₂)) → M r₃ r₄ (K r₄)) → M r₃ r₂ a
open RawIMonad monad public
DContTIMonadDCont : ∀ {I} (K : I → Set) {M} →
RawMonad M → RawIMonadDCont K (DContT K M)
DContTIMonadDCont K Mon = record
{ monad = DContTIMonad K Mon
; reset = λ e k → e return >>= k
; shift = λ e k → e (λ a k' → (k a) >>= k') return
}
where
open RawIMonad Mon
DContIMonadDCont : ∀ {I} (K : I → Set) → RawIMonadDCont K (DCont K)
DContIMonadDCont K = DContTIMonadDCont K IdentityMonad
| {
"alphanum_fraction": 0.5179432244,
"avg_line_length": 31.1166666667,
"ext": "agda",
"hexsha": "880a5656f6c0354ccca934e906119c29a6c9f0b0",
"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/Continuation.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/Continuation.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/Continuation.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": 606,
"size": 1867
} |
{-# OPTIONS --without-K --rewriting #-}
open import Basics
open import lib.Basics
open import Flat
module Axiom.C0 {@♭ i j : ULevel} (@♭ I : Type i) (@♭ R : I → Type j) where
postulate C0 : {@♭ k : ULevel} (@♭ A : Type k)
(p : (index : I) → (is-equiv (λ (a : A) → λ (r : R index) → a)))
→ A is-discrete
| {
"alphanum_fraction": 0.4739726027,
"avg_line_length": 30.4166666667,
"ext": "agda",
"hexsha": "c726d389ffe79c3930b236b6380a14ce84fc10a6",
"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": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "glangmead/formalization",
"max_forks_repo_path": "cohesion/david_jaz_261/Axiom/C0.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"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": "glangmead/formalization",
"max_issues_repo_path": "cohesion/david_jaz_261/Axiom/C0.agda",
"max_line_length": 83,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "glangmead/formalization",
"max_stars_repo_path": "cohesion/david_jaz_261/Axiom/C0.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-13T05:51:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-06T17:39:22.000Z",
"num_tokens": 119,
"size": 365
} |
module Common.Unit where
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () () #-}
{-# COMPILED_DATA_UHC Unit __UNIT__ __UNIT__ #-}
| {
"alphanum_fraction": 0.6827586207,
"avg_line_length": 18.125,
"ext": "agda",
"hexsha": "bed0429e5d492fda883df5a17ba3316578f82131",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Common/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Common/Unit.agda",
"max_line_length": 48,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Common/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 40,
"size": 145
} |
module Classical where
open import Data.Empty using (⊥-elim)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_) renaming (_,_ to ⟨_,_⟩)
open import Negation using (¬_)
-- 排中律 → 二重否定の除去
em-→-¬¬-elim :
(∀ {A : Set} → A ⊎ ¬ A)
-------------------------
→ (∀ {A : Set} → ¬ ¬ A → A)
em-→-¬¬-elim a⊎¬a ¬¬a with a⊎¬a
... | inj₁ a = a
... | inj₂ ¬a = ⊥-elim (¬¬a ¬a)
-- 排中律 → パースの法則
em-→-peirce :
(∀ {A : Set} → A ⊎ ¬ A)
-----------------------------------
→ (∀ {A B : Set} → ((A → B) → A) → A)
em-→-peirce a⊎¬a [a→b]→a with a⊎¬a
... | inj₁ a = a
... | inj₂ ¬a = [a→b]→a (λ a → ⊥-elim (¬a a))
-- 排中律 → 直和としての含意
em-→-iad :
(∀ {A : Set} → A ⊎ ¬ A)
-------------------------------------
→ (∀ {A B : Set} → (A → B) → ¬ A ⊎ B)
em-→-iad a⊎¬a a→b with a⊎¬a
... | inj₁ a = inj₂ (a→b a)
... | inj₂ ¬a = inj₁ ¬a
-- 排中律 → ド・モルガンの法則
em-→-demorgan :
(∀ {A : Set} → A ⊎ ¬ A)
---------------------------------------
→ (∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B)
em-→-demorgan a⊎¬a {A} {B} ¬[¬a׬b] with a⊎¬a {A} | a⊎¬a {B}
... | inj₁ a | _ = inj₁ a
... | inj₂ ¬a | inj₁ b = inj₂ b
... | inj₂ ¬a | inj₂ ¬b = ⊥-elim (¬[¬a׬b] ⟨ ¬a , ¬b ⟩)
-- 二重否定の除去 → 排中律
-- (¬¬ A → A) の A を (A ⊎ ¬ A) と見なす
-- ¬¬ (A ⊎ ¬ A) → (A ⊎ ¬ A)
¬¬-elim-→-em :
(∀ {A : Set} → ¬ ¬ A → A)
-------------------------
→ (∀ {A : Set} → A ⊎ ¬ A)
¬¬-elim-→-em ¬¬[a⊎¬a]→[a⊎¬a] = ¬¬[a⊎¬a]→[a⊎¬a] (λ ¬[a⊎¬a] → ¬[a⊎¬a] (inj₂ (λ a → ¬[a⊎¬a] (inj₁ a))))
-- 二重否定の除去 → パースの法則
¬¬-elim-→-peirce :
(∀ {A : Set} → ¬ ¬ A → A)
-----------------------------------
→ (∀ {A B : Set} → ((A → B) → A) → A)
¬¬-elim-→-peirce ¬¬a→a [a→b]→a = ¬¬a→a (λ ¬a → ¬a ([a→b]→a (λ a → ⊥-elim (¬a a))))
-- 二重否定の除去 → 直和としての含意
-- (¬¬ A → A) の A を (¬ A ⊎ B) と見なす
-- ¬¬ (¬ A ⊎ B) → (¬ A ⊎ B)
¬¬-elim-→-iad :
(∀ {A : Set} → ¬ ¬ A → A)
-------------------------------------
→ (∀ {A B : Set} → (A → B) → ¬ A ⊎ B)
¬¬-elim-→-iad ¬¬[¬a⊎b]→[¬a⊎b] a→b = ¬¬[¬a⊎b]→[¬a⊎b] (λ ¬[¬a⊎b] → ¬[¬a⊎b] (inj₁ (λ a → ¬[¬a⊎b] (inj₂ (a→b a)))))
-- 二重否定の除去 → ド・モルガンの法則
-- (¬¬ A → A) の A を (A ⊎ B) と見なす
-- ¬¬ (A ⊎ B) → (A ⊎ B)
¬¬-elim-→-demorgan :
(∀ {A : Set} → ¬ ¬ A → A)
---------------------------------------
→ (∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B)
¬¬-elim-→-demorgan ¬¬[a⊎b]→[a⊎b] ¬[¬a׬b] = ¬¬[a⊎b]→[a⊎b] (λ ¬[a⊎b] → ¬[¬a׬b] ⟨ (λ a → ¬[a⊎b] (inj₁ a)) , (λ b → ¬[a⊎b] (inj₂ b)) ⟩)
-- パースの法則 → 排中律
-- ((A → B) → A) → A) の A を (A ⊎ ¬ A) と見なす
-- ((((A ⊎ ¬ A) → B) → (A ⊎ ¬ A)) → (A ⊎ ¬ A))
peirce-→-em :
(∀ {A B : Set} → ((A → B) → A) → A)
-----------------------------------
→ (∀ {A : Set} → A ⊎ ¬ A)
peirce-→-em [[[a⊎¬a]→b]→[a⊎¬a]]→[a⊎¬a] = [[[a⊎¬a]→b]→[a⊎¬a]]→[a⊎¬a] (λ [a⊎¬a]→b → inj₂ (λ a → [a⊎¬a]→b (inj₁ a)))
-- パースの法則 → 二重否定の除去
-- ((A → B) → A) → A) の A を (¬¬ A → A) と見なす
-- (((¬¬ A → A) → B) → (¬¬ A → A)) → (¬¬ A → A))
peirce-→-¬¬-elim :
(∀ {A B : Set} → ((A → B) → A) → A)
-----------------------------------
→ (∀ {A : Set} → ¬ ¬ A → A)
peirce-→-¬¬-elim [[[¬¬a→a]→b]→[¬¬a→a]]→[¬¬a→a] = [[[¬¬a→a]→b]→[¬¬a→a]]→[¬¬a→a] (λ [¬¬a→a]→b → (λ ¬¬a → ⊥-elim (¬¬a (λ a → [¬¬a→a]→b (λ ¬¬a → a)))))
-- パースの法則 → 直和としての含意
-- ((A → B) → A) → A の A を ¬ A ⊎ B, B を ⊥ と見なす
-- (¬ (¬ A ⊎ B)) → (¬ A ⊎ B) → (¬ A ⊎ B)
peirce-→-iad :
(∀ {A B : Set} → ((A → B) → A) → A)
-------------------------------------
→ (∀ {A B : Set} → (A → B) → ¬ A ⊎ B)
peirce-→-iad [¬[¬a⊎b]→[¬a⊎b]]→[¬a⊎b] a→b = [¬[¬a⊎b]→[¬a⊎b]]→[¬a⊎b] (λ ¬[¬a⊎b] → inj₁ (λ a → ¬[¬a⊎b] (inj₂ (a→b a))))
-- パースの法則 → ド・モルガンの法則
-- ((A → B) → A) → A) の A を (A ⊎ B), B を ⊥ と見なす
-- (¬ (A ⊎ B) → (A ⊎ B)) → (A ⊎ B)
peirce-→-demorgan :
(∀ {A B : Set} → ((A → B) → A) → A)
---------------------------------------
→ (∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B)
peirce-→-demorgan ¬[a⊎b]→[a⊎b]→[a⊎b] ¬[¬a׬b] = ¬[a⊎b]→[a⊎b]→[a⊎b] (λ ¬[a⊎b] → ⊥-elim (¬[¬a׬b] ⟨ (λ a → ¬[a⊎b] (inj₁ a)) , (λ b → ¬[a⊎b] (inj₂ b)) ⟩))
-- 直和としての含意 → 排中律
-- (A → B) → ¬ A ⊎ B は B を A と見ることで排中律と同じように扱える
-- (A → A) → ¬ A ⊎ A
iad-→-em :
(∀ {A B : Set} → (A → B) → ¬ A ⊎ B)
-----------------------------------
→ (∀ {A : Set} → A ⊎ ¬ A)
iad-→-em [a→b]→¬a⊎b with [a→b]→¬a⊎b (λ a → a)
... | inj₁ ¬a = inj₂ ¬a
... | inj₂ a = inj₁ a
-- 直和としての含意 → 二重否定の除去
iad-→-¬¬-elim :
(∀ {A B : Set} → (A → B) → ¬ A ⊎ B)
-----------------------------------
→ (∀ {A : Set} → ¬ ¬ A → A)
iad-→-¬¬-elim [a→b]→¬a⊎b with [a→b]→¬a⊎b (λ a → a)
... | inj₁ ¬a = λ ¬¬a → ⊥-elim (¬¬a ¬a)
... | inj₂ a = λ ¬¬a → a
-- 直和としての含意 → パースの法則
iad-→-peirce :
(∀ {A B : Set} → (A → B) → ¬ A ⊎ B)
-----------------------------------
→ (∀ {A B : Set} → ((A → B) → A) → A)
iad-→-peirce [a→b]→¬a⊎b [a→b]→a with [a→b]→¬a⊎b (λ a → a)
... | inj₁ ¬a = [a→b]→a (λ a → ⊥-elim (¬a a))
... | inj₂ a = a
-- 直和としての含意 → ド・モルガンの法則
iad-→-demorgan :
(∀ {A B : Set} → (A → B) → ¬ A ⊎ B)
---------------------------------------
→ (∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B)
iad-→-demorgan [a→b]→¬a⊎b {A} {B} ¬[¬a׬b] with [a→b]→¬a⊎b {A} {A} (λ a → a) | [a→b]→¬a⊎b {B} {B} (λ b → b)
... | inj₁ ¬a | inj₁ ¬b = ⊥-elim (¬[¬a׬b] ⟨ ¬a , ¬b ⟩)
... | inj₂ a | _ = inj₁ a
... | inj₁ ¬a | inj₂ b = inj₂ b
-- ド・モルガンの法則 → 排中律
demorgan-→-em :
(∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B)
---------------------------------------
→ (∀ {A : Set} → A ⊎ ¬ A)
demorgan-→-em ¬[¬a׬b]→a⊎b = ¬[¬a׬b]→a⊎b (λ{ (⟨ ¬a , ¬¬a ⟩) → ¬¬a ¬a })
-- ド・モルガンの法則 → 二重否定の除去
-- (¬ (¬ A × ¬ B) → A ⊎ B) の B を A と見なす
-- ¬ (¬ A × ¬ A) → A ⊎ A
demorgan-→-¬¬-elim :
(∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B)
---------------------------------------
→ (∀ {A : Set} → ¬ ¬ A → A)
demorgan-→-¬¬-elim ¬[¬a׬b]→a⊎b {A} ¬¬a with ¬[¬a׬b]→a⊎b {A} {A} λ{ (⟨ ¬a , ¬b ⟩) → ¬¬a ¬a }
... | inj₁ a = a
... | inj₂ a = a
-- ド・モルガンの法則 → パースの法則
-- (¬ (¬ A × ¬ B) → A ⊎ B) の B を A と見なす
-- ¬ (¬ A × ¬ A) → A ⊎ A
demorgan-→-peirce :
(∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B)
---------------------------------------
→ (∀ {A B : Set} → ((A → B) → A) → A)
demorgan-→-peirce ¬[¬¬a׬b]→¬a⊎b {A} {B} [a→b]→a with ¬[¬¬a׬b]→¬a⊎b {A} {A} λ{ (⟨ ¬a , ¬b ⟩) → ¬a ([a→b]→a (λ a → ⊥-elim (¬a a))) }
... | inj₁ a = a
... | inj₂ a = a
-- ド・モルガンの法則 → 直和としての含意
-- (¬ (¬ A × ¬ B) → A ⊎ B) の A を ¬A と見なす
-- ¬ (¬¬ A × ¬ B) → ¬ A ⊎ B
demorgan-→-iad :
(∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B)
---------------------------------------
→ (∀ {A B : Set} → (A → B) → ¬ A ⊎ B)
demorgan-→-iad ¬[¬¬a׬b]→¬a⊎b a→b = ¬[¬¬a׬b]→¬a⊎b (λ (⟨ ¬¬a , ¬b ⟩) → ¬¬a (λ a → ¬b (a→b a)))
| {
"alphanum_fraction": 0.2616440164,
"avg_line_length": 39.2694300518,
"ext": "agda",
"hexsha": "e6572f99fe7a8bc4b48957883587a8f0f02737e2",
"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/negation/Classical.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/negation/Classical.agda",
"max_line_length": 151,
"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/negation/Classical.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": 3794,
"size": 7579
} |
module PLRTree.Equality {A : Set} where
open import PLRTree {A}
data _≃_ : PLRTree → PLRTree → Set where
≃lf : leaf ≃ leaf
≃nd : {l r l' r' : PLRTree}
(x x' : A)
→ l ≃ r
→ l' ≃ r'
→ l ≃ l'
→ node perfect x l r ≃ node perfect x' l' r'
| {
"alphanum_fraction": 0.3988269795,
"avg_line_length": 26.2307692308,
"ext": "agda",
"hexsha": "bf8d2373a6c25ede3ec96c1e5b5067bf3229b447",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/PLRTree/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/PLRTree/Equality.agda",
"max_line_length": 64,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/PLRTree/Equality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 116,
"size": 341
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Consequences of a monomorphism between ring-like structures
------------------------------------------------------------------------
-- See Data.Nat.Binary.Properties for examples of how this and similar
-- modules can be used to easily translate properties between types.
{-# OPTIONS --without-K --safe #-}
open import Algebra.Bundles
open import Algebra.Morphism.Structures
open import Relation.Binary.Core
module Algebra.Morphism.RingMonomorphism
{a b ℓ₁ ℓ₂} {R₁ : RawRing a ℓ₁} {R₂ : RawRing b ℓ₂} {⟦_⟧}
(isRingMonomorphism : IsRingMonomorphism R₁ R₂ ⟦_⟧)
where
open IsRingMonomorphism isRingMonomorphism
open RawRing R₁ renaming (Carrier to A; _≈_ to _≈₁_)
open RawRing R₂ renaming
( Carrier to B; _≈_ to _≈₂_; _+_ to _⊕_
; _*_ to _⊛_; 1# to 1#₂; 0# to 0#₂; -_ to ⊝_)
open import Algebra.Definitions
open import Algebra.Structures
open import Data.Product
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
------------------------------------------------------------------------
-- Re-export all properties of group and monoid monomorphisms
open import Algebra.Morphism.GroupMonomorphism
+-isGroupMonomorphism renaming
( assoc to +-assoc
; comm to +-comm
; cong to +-cong
; idem to +-idem
; identity to +-identity; identityˡ to +-identityˡ; identityʳ to +-identityʳ
; cancel to +-cancel; cancelˡ to +-cancelˡ; cancelʳ to +-cancelʳ
; zero to +-zero; zeroˡ to +-zeroˡ; zeroʳ to +-zeroʳ
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
; isSelectiveMagma to +-isSelectiveMagma
; isSemilattice to +-isSemilattice
; sel to +-sel
; isBand to +-isBand
; isCommutativeMonoid to +-isCommutativeMonoid
) public
open import Algebra.Morphism.MonoidMonomorphism
*-isMonoidMonomorphism renaming
( assoc to *-assoc
; comm to *-comm
; cong to *-cong
; idem to *-idem
; identity to *-identity; identityˡ to *-identityˡ; identityʳ to *-identityʳ
; cancel to *-cancel; cancelˡ to *-cancelˡ; cancelʳ to *-cancelʳ
; zero to *-zero; zeroˡ to *-zeroˡ; zeroʳ to *-zeroʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
; isMonoid to *-isMonoid
; isSelectiveMagma to *-isSelectiveMagma
; isSemilattice to *-isSemilattice
; sel to *-sel
; isBand to *-isBand
; isCommutativeMonoid to *-isCommutativeMonoid
) public
------------------------------------------------------------------------
-- Properties
module _ (+-isGroup : IsGroup _≈₂_ _⊕_ 0#₂ ⊝_)
(*-isMagma : IsMagma _≈₂_ _⊛_) where
open IsGroup +-isGroup hiding (setoid; refl)
open IsMagma *-isMagma renaming (∙-cong to ◦-cong)
open SetoidReasoning setoid
distribˡ : _DistributesOverˡ_ _≈₂_ _⊛_ _⊕_ → _DistributesOverˡ_ _≈₁_ _*_ _+_
distribˡ distribˡ x y z = injective (begin
⟦ x * (y + z) ⟧ ≈⟨ *-homo x (y + z) ⟩
⟦ x ⟧ ⊛ ⟦ y + z ⟧ ≈⟨ ◦-cong refl (+-homo y z) ⟩
⟦ x ⟧ ⊛ (⟦ y ⟧ ⊕ ⟦ z ⟧) ≈⟨ distribˡ ⟦ x ⟧ ⟦ y ⟧ ⟦ z ⟧ ⟩
⟦ x ⟧ ⊛ ⟦ y ⟧ ⊕ ⟦ x ⟧ ⊛ ⟦ z ⟧ ≈˘⟨ ∙-cong (*-homo x y) (*-homo x z) ⟩
⟦ x * y ⟧ ⊕ ⟦ x * z ⟧ ≈˘⟨ +-homo (x * y) (x * z) ⟩
⟦ x * y + x * z ⟧ ∎)
distribʳ : _DistributesOverʳ_ _≈₂_ _⊛_ _⊕_ → _DistributesOverʳ_ _≈₁_ _*_ _+_
distribʳ distribˡ x y z = injective (begin
⟦ (y + z) * x ⟧ ≈⟨ *-homo (y + z) x ⟩
⟦ y + z ⟧ ⊛ ⟦ x ⟧ ≈⟨ ◦-cong (+-homo y z) refl ⟩
(⟦ y ⟧ ⊕ ⟦ z ⟧) ⊛ ⟦ x ⟧ ≈⟨ distribˡ ⟦ x ⟧ ⟦ y ⟧ ⟦ z ⟧ ⟩
⟦ y ⟧ ⊛ ⟦ x ⟧ ⊕ ⟦ z ⟧ ⊛ ⟦ x ⟧ ≈˘⟨ ∙-cong (*-homo y x) (*-homo z x) ⟩
⟦ y * x ⟧ ⊕ ⟦ z * x ⟧ ≈˘⟨ +-homo (y * x) (z * x) ⟩
⟦ y * x + z * x ⟧ ∎)
distrib : _DistributesOver_ _≈₂_ _⊛_ _⊕_ → _DistributesOver_ _≈₁_ _*_ _+_
distrib distrib = distribˡ (proj₁ distrib) , distribʳ (proj₂ distrib)
zeroˡ : LeftZero _≈₂_ 0#₂ _⊛_ → LeftZero _≈₁_ 0# _*_
zeroˡ zeroˡ x = injective (begin
⟦ 0# * x ⟧ ≈⟨ *-homo 0# x ⟩
⟦ 0# ⟧ ⊛ ⟦ x ⟧ ≈⟨ ◦-cong 0#-homo refl ⟩
0#₂ ⊛ ⟦ x ⟧ ≈⟨ zeroˡ ⟦ x ⟧ ⟩
0#₂ ≈˘⟨ 0#-homo ⟩
⟦ 0# ⟧ ∎)
zeroʳ : RightZero _≈₂_ 0#₂ _⊛_ → RightZero _≈₁_ 0# _*_
zeroʳ zeroʳ x = injective (begin
⟦ x * 0# ⟧ ≈⟨ *-homo x 0# ⟩
⟦ x ⟧ ⊛ ⟦ 0# ⟧ ≈⟨ ◦-cong refl 0#-homo ⟩
⟦ x ⟧ ⊛ 0#₂ ≈⟨ zeroʳ ⟦ x ⟧ ⟩
0#₂ ≈˘⟨ 0#-homo ⟩
⟦ 0# ⟧ ∎)
zero : Zero _≈₂_ 0#₂ _⊛_ → Zero _≈₁_ 0# _*_
zero zero = zeroˡ (proj₁ zero) , zeroʳ (proj₂ zero)
isRing : IsRing _≈₂_ _⊕_ _⊛_ ⊝_ 0#₂ 1#₂ → IsRing _≈₁_ _+_ _*_ -_ 0# 1#
isRing isRing = record
{ +-isAbelianGroup = isAbelianGroup R.+-isAbelianGroup
; *-isMonoid = *-isMonoid R.*-isMonoid
; distrib = distrib R.+-isGroup R.*-isMagma R.distrib
; zero = zero R.+-isGroup R.*-isMagma R.zero
} where module R = IsRing isRing
| {
"alphanum_fraction": 0.5559701493,
"avg_line_length": 37.1076923077,
"ext": "agda",
"hexsha": "2568794547094fcc8a03ebf0a12a4cf24dd90dfd",
"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/Algebra/Morphism/RingMonomorphism.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/Algebra/Morphism/RingMonomorphism.agda",
"max_line_length": 78,
"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/Algebra/Morphism/RingMonomorphism.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": 2049,
"size": 4824
} |
module builtinInModule where
module Int where
postulate I : Set
{-# BUILTIN INTEGER I #-}
primitive primIntegerPlus : I -> I -> I
| {
"alphanum_fraction": 0.6785714286,
"avg_line_length": 14,
"ext": "agda",
"hexsha": "30906128a86c09a529accd02e6dd52831f25cd0f",
"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/builtinInModule.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/builtinInModule.agda",
"max_line_length": 41,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/builtinInModule.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": 38,
"size": 140
} |
{-
This file contains:
- Definition of set coequalizers as performed in https://1lab.dev/Data.Set.Coequaliser.html
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.SetCoequalizer.Base where
open import Cubical.Core.Primitives
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
B : Type ℓ'
-- Set coequalizers as a higher inductive type
data SetCoequalizer {A : Type ℓ} {B : Type ℓ'} (f g : A → B) : Type (ℓ-max ℓ ℓ') where
inc : B → SetCoequalizer f g
coeq : (a : A) → inc (f a) ≡ inc (g a)
squash : (x y : SetCoequalizer f g) → (p q : x ≡ y) → p ≡ q
| {
"alphanum_fraction": 0.6265270506,
"avg_line_length": 23.875,
"ext": "agda",
"hexsha": "86315a36177e8dc065dc5661ce617f2e1a504c97",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/HITs/SetCoequalizer/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/HITs/SetCoequalizer/Base.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/HITs/SetCoequalizer/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 210,
"size": 573
} |
{- NEW TRANSLATION: notation change to avoid exponential increase in term size during translation -}
open import Preliminaries
open import Source
open import Pilot2
module Translation where
mutual
⟨⟨_⟩⟩ : Tp → CTp
⟨⟨ unit ⟩⟩ = unit
⟨⟨ nat ⟩⟩ = nat
⟨⟨ susp A ⟩⟩ = || A ||
⟨⟨ A ->s B ⟩⟩ = ⟨⟨ A ⟩⟩ ->c || B ||
⟨⟨ A ×s B ⟩⟩ = ⟨⟨ A ⟩⟩ ×c ⟨⟨ B ⟩⟩
⟨⟨ list A ⟩⟩ = list ⟨⟨ A ⟩⟩
⟨⟨ bool ⟩⟩ = bool
||_|| : Tp → CTp
|| τ || = C ×c ⟨⟨ τ ⟩⟩
⟨⟨_⟩⟩c : Source.Ctx → Pilot2.Ctx
⟨⟨ [] ⟩⟩c = []
⟨⟨ x :: Γ ⟩⟩c = ⟨⟨ x ⟩⟩ :: ⟨⟨ Γ ⟩⟩c
interp-Cost : ∀{Γ} → Cost → Γ Pilot2.|- C
interp-Cost 0c = 0C
interp-Cost 1c = 1C
interp-Cost (m +c n) = plusC (interp-Cost m) (interp-Cost n)
lookup : ∀{Γ τ} → τ Source.∈ Γ → ⟨⟨ τ ⟩⟩ Pilot2.∈ ⟨⟨ Γ ⟩⟩c
lookup i0 = i0
lookup (iS x) = iS (lookup x)
throw-s : ∀ {Γ Γ' τ} → Pilot2.sctx Γ (τ :: Γ') → Pilot2.sctx Γ Γ'
throw-s Θ x = Θ (iS x)
-- translation from source expressions to complexity expressions
||_||e : ∀{Γ τ} → Γ Source.|- τ → ⟨⟨ Γ ⟩⟩c Pilot2.|- || τ ||
|| unit ||e = prod 0C unit
|| var x ||e = prod 0C (var (lookup x))
|| z ||e = prod 0C z
|| suc e ||e = (letc (prod (l-proj (var i0)) (s (r-proj (var i0)))) || e ||e)
|| rec e e0 e1 ||e =
letc (l-proj (var i0) +C rec (r-proj (var i0))
(Pilot2.wkn (1C +C || e0 ||e)) (Pilot2.subst (1C +C || e1 ||e) (Pilot2.s-extend (Pilot2.s-extend (throw-s Pilot2.ids))))) || e ||e
|| lam e ||e = prod 0C (lam || e ||e)
|| app e1 e2 ||e = letc (letc (prod (plusC (plusC (l-proj (var (iS i0))) (l-proj (var i0))) (l-proj (app (r-proj (var (iS i0))) (r-proj (var i0)))))
(r-proj (app (r-proj (var (iS i0))) (r-proj (var i0))))) (Pilot2.wkn || e2 ||e)) || e1 ||e
|| prod e1 e2 ||e = letc (letc (prod (plusC (l-proj (var (iS i0))) (l-proj (var i0))) (prod (r-proj (var (iS i0))) (r-proj (var i0)))) (Pilot2.wkn || e2 ||e)) || e1 ||e
|| delay e ||e = prod 0C || e ||e
|| force e ||e = letc (prod (plusC (l-proj (var i0)) (l-proj (r-proj (var i0)))) (r-proj (r-proj (var i0)))) || e ||e
|| split e0 e1 ||e = letc (prod (plusC (Pilot2.wkn (l-proj || e0 ||e)) (l-proj (var i0))) (r-proj (var i0))) E1
where E1 = letc (Pilot2.subst || e1 ||e (Pilot2.lem4 (l-proj (r-proj (var i0))) (r-proj (r-proj (var i0))) Pilot2.ss Pilot2.s-extend (Pilot2.s-extend (throw-s Pilot2.ids)))) || e0 ||e
|| nil ||e = prod 0C nil
|| e ::s e₁ ||e = letc (letc (prod (plusC (l-proj (var (iS i0))) (l-proj (var i0))) (r-proj (var (iS i0)) ::c r-proj (var i0))) (Pilot2.wkn || e₁ ||e)) || e ||e
|| listrec e e₁ e₂ ||e =
letc (l-proj (var i0) +C listrec (r-proj (var i0))
(Pilot2.wkn (1C +C || e₁ ||e)) (Pilot2.subst (1C +C || e₂ ||e) (Pilot2.s-extend (Pilot2.s-extend (Pilot2.s-extend (throw-s Pilot2.ids)))))) || e ||e
|| true ||e = prod 0C true
|| false ||e = prod 0C false
| {
"alphanum_fraction": 0.5113596645,
"avg_line_length": 46.1451612903,
"ext": "agda",
"hexsha": "f6ea15e26c196242ed49420ea1cab4fee16c3e38",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "benhuds/Agda",
"max_forks_repo_path": "complexity/complexity-final/Translation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "benhuds/Agda",
"max_issues_repo_path": "complexity/complexity-final/Translation.agda",
"max_line_length": 187,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "benhuds/Agda",
"max_stars_repo_path": "complexity/complexity-final/Translation.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z",
"num_tokens": 1295,
"size": 2861
} |
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Setoids.Setoids
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Groups.Definition
open import Groups.Orders.Archimedean
open import Fields.Fields
open import Sets.EquivalenceRelations
open import Sequences
open import Setoids.Orders.Partial.Definition
open import Functions.Definition
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Fields.Orders.Total.Archimedean
module Fields.CauchyCompletion.Archimedean {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {R : Ring S _+_ _*_} {pRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pRing) (F : Field R) (arch : ArchimedeanField {F = F} (record { oRing = pRing })) where
open import Fields.CauchyCompletion.Group order F
open import Fields.CauchyCompletion.Ring order F
open import Fields.CauchyCompletion.Comparison order F
open import Fields.CauchyCompletion.PartiallyOrderedRing order F
CArchimedean : Archimedean (toGroup CRing CpOrderedRing)
CArchimedean x y xPos yPos = {!!}
| {
"alphanum_fraction": 0.7742424242,
"avg_line_length": 45.5172413793,
"ext": "agda",
"hexsha": "d6611c91319abd0ea606ea6cf06aa2df4707d18f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Fields/CauchyCompletion/Archimedean.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Fields/CauchyCompletion/Archimedean.agda",
"max_line_length": 360,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Fields/CauchyCompletion/Archimedean.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 371,
"size": 1320
} |
module correct where
open import cfg
open import jarsec using (Parser ; parse ; run-parser ; partial-parse ; _>>=_ ; _>>_ ; _<*>_)
open import Data.Bool
open import Data.List hiding (lookup)
open import Data.Fin hiding (_+_)
open import Data.Char
open import Agda.Builtin.Char renaming ( primCharEquality to charEq )
open import Data.Nat
open import Relation.Binary.PropositionalEquality using (_≡_ ; _≢_ ; refl)
open import Relation.Unary
open import Data.Maybe hiding (Any ; All)
open import Data.Sum hiding (map)
open import Data.String hiding (length ; _++_) renaming (primStringToList to 𝕊→𝕃 ; primStringFromList to 𝕃→𝕊)
open import Data.Product hiding (map)
open import Agda.Builtin.Unit
open import Data.List.All
open import Level
postulate
sym : ∀ {A : Set} {x y : A} → x ≡ y → y ≡ x
head-from-≡ : ∀ {A : Set} {x y : A} {xs ys : List A} → (x List.∷ xs) ≡ (y ∷ ys) → x ≡ y
tail-from-≡ : ∀ {A : Set} {x y : A} {xs ys : List A} → (x List.∷ xs) ≡ (y ∷ ys) → xs ≡ ys
++-runit : ∀ {A : Set} (m : List A) → m ++ [] ≡ m
++-assoc : ∀ {A : Set} (m n p : List A) → (m ++ n) ++ p ≡ m ++ (n ++ p)
charEq-T : ∀ x c → (charEq x c) ≡ true → x ≡ c
charEq-F : ∀ x c → (charEq x c) ≡ false → x ≢ c
correct : ∀ (cfg : Cfg 0) (cs : List Char)
→ let rs = jarsec.parse (interp cfg) cs in
All (λ r → ((proj₁ r) ∈[ cfg ]) × (proj₁ r) ++ (proj₂ r) ≡ cs) rs
correct emp cs = []
correct eps cs = (eps , refl) ∷ []
correct (lit x) [] = []
correct (lit x) (c ∷ cs) with charEq x c | charEq-T x c | charEq-F x c
... | true | b | d rewrite b refl = (lit c , refl) ∷ []
... | false | b | d = []
correct (var ()) cs
correct (seq cfg₁ cfg₂) cs = {! correct-seq₁ (parse (interp cfg₁) cs) (correct cfg₁ cs) !}
correct (seq cfg₁ cfg₂) cs with (parse (interp cfg₁) cs) | correct cfg₁ cs
correct (seq cfg₁ cfg₂) cs | [] | [] = []
correct (seq cfg₁ cfg₂) cs | r₁ ∷ rs₁ | a₁ ∷ all₁ with parse (interp cfg₂) (proj₂ r₁) | correct cfg₂ (proj₂ r₁)
correct (seq cfg₁ cfg₂) cs | r₁ ∷ rs₁ | a₁ ∷ all₁ | [] | [] = ?
correct (seq cfg₁ cfg₂) cs | r₁ ∷ rs₁ | a₁ ∷ all₁ | r₂ ∷ rs₂ | a₂ ∷ all₂
= strengthen-to-seq r₁ a₁ r₂ a₂ ∷ correct-seq₁ cfg₁ cfg₂ cs r₁ rs₁ a₁ all₁ rs₂ all₂
where
Result : Set
Result = List Char × List Char
strengthen-to-seq :
∀ (r₁ : Result)
→ (a₁ : proj₁ r₁ ∈[ cfg₁ ] × proj₁ r₁ ++ proj₂ r₁ ≡ cs)
→ (r₂ : Result)
→ (a₂ : proj₁ r₂ ∈[ cfg₂ ] × proj₁ r₂ ++ proj₂ r₂ ≡ proj₂ r₁)
→ (proj₁ r₁ ++ proj₁ r₂) ∈[ seq cfg₁ cfg₂ ] × (proj₁ r₁ ++ proj₁ r₂) ++ proj₂ r₂ ≡ cs
strengthen-to-seq r₁ a₁ r₂ a₂
rewrite ++-assoc (proj₁ r₁) (proj₁ r₂) (proj₂ r₂)
| proj₂ a₂
| proj₂ a₁
= (seq (proj₁ a₁) (proj₁ a₂)) , refl
-- correct-seq₁ :
-- ∀ (rs₁ : List Result)
-- → (all₁ : All (λ r → (proj₁ r ∈[ cfg₁ ]) × proj₁ r ++ proj₂ r ≡ cs) rs₁)
-- → All (λ r → (proj₁ r ∈[ seq cfg₁ cfg₂ ]) × proj₁ r ++ proj₂ r ≡ cs)
-- (parse (interp cfg₁ >>= (λ x → interp cfg₂ >>= (λ y →
-- Parser.mk-parser (λ str → (x ++ y , str) ∷ [])))) cs)
-- correct-seq₁ [] [] = {! [] !}
-- correct-seq₁ (r₁ ∷ rs₁) (a₁ ∷ all₁) = {! !}
correct-seq₂ :
∀ (cfg₁ cfg₂ : Cfg 0) (cs : List Char)
→ (r₁ : Result)
→ (rs₁ : List Result)
→ (a₁ : Σ (proj₁ r₁ ∈[ cfg₁ ]) (λ x → proj₁ r₁ ++ proj₂ r₁ ≡ cs))
→ (all₁ : All (λ r → Σ (proj₁ r ∈[ cfg₁ ]) (λ x → proj₁ r ++ proj₂ r ≡ cs)) rs₁)
→ All (λ r → (proj₁ r ∈[ seq cfg₁ cfg₂ ]) × proj₁ r ++ proj₂ r ≡ cs)
(concatMap
(λ x →
concatMap (λ x₁ → (proj₁ x ++ proj₁ x₁ , proj₂ x₁) ∷ [])
(parse (interp cfg₂) (proj₂ x)))
rs₁)
correct-seq₂ cfg₁ cfg₂ cs r₁ [] a₁ [] = []
correct-seq₂ cfg₁ cfg₂ cs r₁ (x ∷ rs₁) a₁ (px ∷ all₁) = ?
correct-seq₁ :
∀ (cfg₁ cfg₂ : Cfg 0) (cs : List Char)
→ (r₁ : Result)
→ (rs₁ : List Result)
→ (a₁ : Σ (proj₁ r₁ ∈[ cfg₁ ]) (λ x → proj₁ r₁ ++ proj₂ r₁ ≡ cs))
→ (all₁ : All (λ r → Σ (proj₁ r ∈[ cfg₁ ]) (λ x → proj₁ r ++ proj₂ r ≡ cs)) rs₁)
→ (rs₂ : List Result)
→ (all₂ : All (λ r → Σ (proj₁ r ∈[ cfg₂ ]) (λ x → proj₁ r ++ proj₂ r ≡ proj₂ r₁)) rs₂)
→ All (λ r → proj₁ r ∈[ seq cfg₁ cfg₂ ] × proj₁ r ++ proj₂ r ≡ cs)
(foldr _++_ []
(Data.List.map (λ x → (proj₁ r₁ ++ proj₁ x , proj₂ x) ∷ []) rs₂)
++
(concatMap (λ x →
(concatMap (λ x₁ → (proj₁ x ++ proj₁ x₁ , proj₂ x₁) ∷ [])
(parse (interp cfg₂) (proj₂ x))))
rs₁))
correct-seq₁ cfg₁ cfg₂ cs r₁ rs₁ a₁ all₁ [] [] = correct-seq₂ cfg₁ cfg₂ cs r₁ rs₁ a₁ all₁
correct-seq₁ cfg₁ cfg₂ cs r₁ rs₁ a₁ all₁ (r₂ ∷ rs₂) (a₂ ∷ all₂)
= ((seq (proj₁ a₁) (proj₁ a₂)) , fact) ∷ correct-seq₁ cfg₁ cfg₂ cs r₁ rs₁ a₁ all₁ rs₂ all₂
where
fact : (proj₁ r₁ ++ proj₁ r₂) ++ proj₂ r₂ ≡ cs
fact rewrite ++-assoc (proj₁ r₁) (proj₁ r₂) (proj₂ r₂)
| proj₂ a₂
| proj₂ a₁
= refl
correct (alt cfg₁ cfg₂) cs with (Parser.parse (interp (seq cfg₁ cfg₂)) cs)
... | rs =
let all₁ = correct cfg₁ cs
all₂ = correct cfg₂ cs
weak-all₁ : All (λ r → proj₁ r ∈[ alt cfg₁ cfg₂ ] × proj₁ r ++ proj₂ r ≡ cs) (Parser.parse (interp cfg₁) cs)
weak-all₁ = Data.List.All.map
(λ r → ((weaken-to-alt {cfg₁ = cfg₁} {cfg₂ = cfg₂} (inj₁ (proj₁ r))) , (proj₂ r)))
all₁
weak-all₂ : All (λ r → proj₁ r ∈[ alt cfg₁ cfg₂ ] × proj₁ r ++ proj₂ r ≡ cs) (Parser.parse (interp cfg₂) cs)
weak-all₂ = Data.List.All.map
(λ r → (weaken-to-alt {cfg₁ = cfg₁} {cfg₂ = cfg₂} (inj₂ (proj₁ r))) , (proj₂ r))
all₂
in all++ weak-all₁ weak-all₂
where
all++ : ∀ {p} {A : Set} {P : Pred A p} {xs ys : List A}
→ All P xs → All P ys → All P (xs ++ ys)
all++ [] [] = []
all++ [] (py ∷ all₂) = py ∷ (all++ [] all₂)
all++ (px ∷ all₁) all₂ = px ∷ (all++ all₁ all₂)
weaken-to-alt : ∀ {r} {cfg₁ cfg₂ : Cfg 0}
→ (r ∈[ cfg₁ ]) ⊎ (r ∈[ cfg₂ ]) → r ∈[ alt cfg₁ cfg₂ ]
weaken-to-alt (inj₁ e) = alt₁ e
weaken-to-alt (inj₂ e) = alt₂ e
correct (many cfg) cs = ?
correct (fix cfg) cs = ?
| {
"alphanum_fraction": 0.5425745893,
"avg_line_length": 40.0402684564,
"ext": "agda",
"hexsha": "476b2b5816a87c66f1e6536808e211f926ae460f",
"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": "40cca331810f1d3f7dc099614ddca4fa96bd695c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jaywunder/jarsec-verified",
"max_forks_repo_path": "src/correct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "40cca331810f1d3f7dc099614ddca4fa96bd695c",
"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": "jaywunder/jarsec-verified",
"max_issues_repo_path": "src/correct.agda",
"max_line_length": 114,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "40cca331810f1d3f7dc099614ddca4fa96bd695c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jaywunder/jarsec-verified",
"max_stars_repo_path": "src/correct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2369,
"size": 5966
} |
record R : Set where
infix 0 _+_
| {
"alphanum_fraction": 0.6571428571,
"avg_line_length": 11.6666666667,
"ext": "agda",
"hexsha": "5fe34163fe2b4387f3fb578e32977720aa4230a1",
"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/Issue2728.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/Issue2728.agda",
"max_line_length": 20,
"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/Issue2728.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": 13,
"size": 35
} |
-- Mergesort
{-# OPTIONS --without-K --safe #-}
module Algorithms.List.Sort.Merge where
-- agda-stdlib
open import Level
open import Data.Bool using (true; false)
open import Data.List
import Data.List.Properties as Listₚ
open import Data.Product as Prod
import Data.Nat as ℕ
open import Data.Nat.Induction as Ind
open import Function.Base
open import Relation.Binary as B
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open import Relation.Unary as U
import Relation.Unary.Properties as Uₚ
open import Induction.WellFounded
private
variable
a p r : Level
module Mergesort {A : Set a} {_≤_ : Rel A r} (_≤?_ : B.Decidable _≤_) where
merge′ : A → A → List A → List A → List A
merge′ x y xs ys with x ≤? y
merge′ x y [] ys | true because _ = x ∷ y ∷ ys
merge′ x y (x₁ ∷ xs) ys | true because _ = x ∷ merge′ x₁ y xs ys
merge′ x y xs [] | false because _ = y ∷ x ∷ xs
merge′ x y xs (y₁ ∷ ys) | false because _ = y ∷ merge′ x y₁ xs ys
merge : List A → List A → List A
merge [] ys = ys
merge (x ∷ xs) [] = x ∷ xs
merge (x ∷ xs) (y ∷ ys) = merge′ x y xs ys
_L<_ : Rel (List A) _
_L<_ = ℕ._<_ on length
L<-wf : WellFounded _L<_
L<-wf = InverseImage.wellFounded length Ind.<-wellFounded
split : List A → (List A × List A)
split [] = [] , []
split (x ∷ []) = [ x ] , []
split (x ∷ y ∷ xs) = Prod.map (x ∷_) (y ∷_) (split xs)
{-
sort : List A → List A
sort [] = []
sort (x ∷ xs) = {! !}
sort xs = split xs
ys , zs = merge (sort ys) (sort zs)
-}
| {
"alphanum_fraction": 0.6001243781,
"avg_line_length": 28.2105263158,
"ext": "agda",
"hexsha": "3b60821b91435941eaad14b4597738072994c246",
"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": "Algorithms/List/Sort/Merge.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": "Algorithms/List/Sort/Merge.agda",
"max_line_length": 75,
"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": "Algorithms/List/Sort/Merge.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": 546,
"size": 1608
} |
module slots.test where
open import slots.imports
open import slots.defs using (config ; game)
open import slots.bruteforce using (rtp)
c : config
c = record { n = 3 ; m = 4 }
g : game c
g = record { reels = reels ; winTable = winTable } where
open config c
reel : Reel
reel = # 1 ∷ # 1 ∷ # 1 ∷ # 0 ∷ []
reel′ : Reel
reel′ = # 1 ∷ # 1 ∷ # 2 ∷ # 0 ∷ []
reel″ : Reel
reel″ = # 1 ∷ # 3 ∷ # 1 ∷ # 0 ∷ []
reels : Reels
reels =
reel ∷
reel′ ∷
reel″ ∷
[]
winTable : WinTable
winTable =
(0 ∷ 0 ∷ 0 ∷ []) ∷
(0 ∷ 1 ∷ 2 ∷ []) ∷
(0 ∷ 0 ∷ 0 ∷ []) ∷
(0 ∷ 0 ∷ 0 ∷ []) ∷
[]
% : ℕ × ℕ
% = rtp g
%-prf : % ≡ (36 , 64)
%-prf = refl
| {
"alphanum_fraction": 0.4602941176,
"avg_line_length": 16.1904761905,
"ext": "agda",
"hexsha": "0de54236b8ba51446fac242ff8278f8c0d0efd68",
"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": "86d777ade14f63032c46bd168b76ac60d6bdf9b9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "semenov-vladyslav/slots-agda",
"max_forks_repo_path": "src/slots/test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "86d777ade14f63032c46bd168b76ac60d6bdf9b9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "semenov-vladyslav/slots-agda",
"max_issues_repo_path": "src/slots/test.agda",
"max_line_length": 56,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "86d777ade14f63032c46bd168b76ac60d6bdf9b9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "semenov-vladyslav/slots-agda",
"max_stars_repo_path": "src/slots/test.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 312,
"size": 680
} |
{-# OPTIONS --without-K --safe #-}
module Categories.FreeObjects.Free where
open import Level
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
open import Relation.Binary using (IsEquivalence)
open import Categories.Functor renaming (id to idF)
open import Categories.Category
open import Categories.Adjoint
open import Categories.NaturalTransformation.Core
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e o' ℓ' e' : Level
record FreeObject {C : Category o ℓ e} {D : Category o' ℓ' e'} (U : Functor D C) (X : Category.Obj C) : Set (suc (e ⊔ e' ⊔ o ⊔ ℓ ⊔ o' ⊔ ℓ')) where
private
module C = Category C using (Obj; id; identityʳ; identityˡ; _⇒_; _∘_; equiv; module Equiv)
module D = Category D using (Obj; _⇒_; _∘_; equiv)
module U = Functor U using (₀; ₁)
field
FX : D.Obj
η : C [ X , U.₀ FX ]
_* : ∀ {A : D.Obj} → C [ X , U.₀ A ] → D [ FX , A ]
*-lift : ∀ {A : D.Obj} (f : C [ X , U.₀ A ]) → C [ (U.₁ (f *) C.∘ η) ≈ f ]
*-uniq : ∀ {A : D.Obj} (f : C [ X , U.₀ A ]) (g : D [ FX , A ]) → C [ (U.₁ g) C.∘ η ≈ f ] → D [ g ≈ f * ]
*-cong : ∀ {A : D.Obj} {f g : C [ X , U.₀ A ]} → C [ f ≈ g ] → D [ f * ≈ g * ]
*-cong {A} {f} {g} f≈g = *-uniq g (f *) (trans (*-lift f) f≈g) where open C.Equiv
open FreeObject
module _ {C : Category o ℓ e} {D : Category o' ℓ' e'} (U : Functor D C) where
private
module C = Category C using (Obj; id; _⇒_; _∘_; identityʳ; identityˡ; assoc; equiv; module Equiv; module HomReasoning)
module D = Category D using (Obj; id; _⇒_; _∘_; identityʳ; identityˡ; assoc; equiv; module Equiv; module HomReasoning)
module U = Functor U using (₀; ₁; identity; homomorphism)
-- free object construction is functorial
FO⇒Functor : (F : ((X : C.Obj) → FreeObject U X)) → Functor C D
FO⇒Functor F =
record
{ F₀ = λ X → FX (F X)
; F₁ = λ {X} {Y} f → _* (F X) (η (F Y) C.∘ f)
; identity = λ {X} → sym (*-uniq (F X) (η (F X) C.∘ C.id) D.id (id-proof {X}))
; homomorphism = λ {X} {Y} {Z} {f} {g} →
sym (*-uniq (F X) (η (F Z) C.∘ (g C.∘ f))
((_* (F Y) (η (F Z) C.∘ g)) D.∘ (_* (F X) (η (F Y) C.∘ f)))
(⟺ (hom-proof {X} {Y} {Z} {f} {g}))
)
; F-resp-≈ = λ {X} {Y} {f} {g} f≈g → sym (*-uniq (F X) (η (F Y) C.∘ f) (_* (F X) (η (F Y) C.∘ g)) (resp-proof f≈g))
}
where
open C.HomReasoning
open D.Equiv
id-proof : ∀ {X : C.Obj} → C [ U.₁ D.id C.∘ η (F X) ≈ η (F X) C.∘ C.id ]
id-proof {X} = begin
(U.₁ D.id) C.∘ FX.η ≈⟨ U.identity ⟩∘⟨refl ⟩
C.id C.∘ FX.η ≈⟨ id-comm-sym ⟩
FX.η C.∘ C.id ∎
where
open MR C
module FX = FreeObject (F X) using (η)
hom-proof : ∀ {X : C.Obj} {Y : C.Obj} {Z : C.Obj} {f : C [ X , Y ]} {g : C [ Y , Z ]} →
C [ (η (F Z) C.∘ (g C.∘ f)) ≈ (U.₁ (_* (F Y) (η (F Z) C.∘ g) D.∘ _* (F X) (η (F Y) C.∘ f) ) C.∘ η (F X)) ]
hom-proof {X} {Y} {Z} {f} {g} = begin
FZ.η C.∘ (g C.∘ f) ≈˘⟨ pushˡ (FY.*-lift (FZ.η C.∘ g)) ⟩
(U.₁((FZ.η C.∘ g) FY.*) C.∘ FY.η) C.∘ f ≈˘⟨ pushʳ (FX.*-lift (FY.η C.∘ f)) ⟩
U.₁((FZ.η C.∘ g) FY.*) C.∘ (U.₁((FY.η C.∘ f) FX.*) C.∘ FX.η) ≈˘⟨ pushˡ U.homomorphism ⟩
U.₁ ((FZ.η C.∘ g) FY.* D.∘ (FY.η C.∘ f) FX.*) C.∘ FX.η ∎
where
open MR C
open C.Equiv
module FX = FreeObject (F X) using (η; _*; *-lift)
module FY = FreeObject (F Y) using (η; _*; *-lift)
module FZ = FreeObject (F Z) using (η)
resp-proof :{X Y : C.Obj} {f g : C [ X , Y ]} → C [ f ≈ g ] → C [ U.₁ ((F X *) (η (F Y) C.∘ g)) C.∘ η (F X) ≈ η (F Y) C.∘ f ]
resp-proof {X} {Y} {f} {g} f≈g = begin
U.₁((FY.η C.∘ g) FX.*) C.∘ FX.η ≈⟨ FX.*-lift (FY.η C.∘ g) ⟩
(FY.η C.∘ g) ≈˘⟨ refl⟩∘⟨ f≈g ⟩
(FY.η C.∘ f) ∎
where
module FX = FreeObject (F X) using (η; _*; *-lift)
module FY = FreeObject (F Y) using (η; _*; *-lift)
FO⇒unit : (F : ((X : C.Obj) → FreeObject U X)) → NaturalTransformation idF (U ∘F FO⇒Functor F)
FO⇒unit F = ntHelper (record { η = λ X → η (F X) ; commute = λ {X} {Y} f → sym (*-lift (F X) (η (F Y) C.∘ f)) }) where open C.Equiv
-- define a counit
FO⇒counit : (F : ((X : C.Obj) → FreeObject U X)) → NaturalTransformation (FO⇒Functor F ∘F U) idF
FO⇒counit F = ntHelper (record { η = λ X → _* (F (U.₀ X)) C.id ; commute = λ {X} {Y} f → counit-comm {X} {Y} f })
where
open D.Equiv
module F = Functor (FO⇒Functor F) using (₀; ₁; identity; homomorphism)
counit-comm : {X Y : D.Obj} (f : D [ X , Y ]) → D [ (_* (F (U.₀ Y)) C.id D.∘ F.₁ (U.₁ f)) ≈ (f D.∘ _* (F (U.₀ X)) C.id) ]
-- proof idea: id* ∘ FU f ≈ (U f)* ≈ f ∘ id* using *-uniq two times
-- left identity
counit-comm-left : {X Y : D.Obj} (f : D [ X , Y ]) → C [ U.₁ ((_* (F (U.₀ Y)) C.id) D.∘ (F.₁ (U.₁ f)) ) C.∘ η (F (U.₀ X)) ≈ U.₁ f ]
counit-comm-left {X} {Y} f = begin
U.₁(C.id FUY.* D.∘ F.₁(U.₁ f)) C.∘ FUX.η ≈⟨ U.homomorphism ⟩∘⟨refl ⟩
(U.₁ (C.id FUY.*) C.∘ U.₁ (F.₁(U.₁ f))) C.∘ FUX.η ≈⟨ C.assoc ⟩
U.₁ (C.id FUY.*) C.∘ (U.₁(F.₁(U.₁ f)) C.∘ FUX.η) ≈⟨ refl⟩∘⟨ FUX.*-lift (FUY.η C.∘ U.₁ f) ⟩
U.₁ (C.id FUY.*) C.∘ (FUY.η C.∘ U.₁ f) ≈˘⟨ C.assoc ⟩
(U.₁ (C.id FUY.*) C.∘ FUY.η) C.∘ U.₁ f ≈⟨ FUY.*-lift C.id ⟩∘⟨refl ⟩
C.id C.∘ U.₁ f ≈⟨ C.identityˡ ⟩
U.₁ f ∎
where
open C.HomReasoning
module FUX = FreeObject (F (U.₀ X)) using (η; *-lift)
module FUY = FreeObject (F (U.₀ Y)) using (η; _*; *-lift)
-- right identity
counit-comm-right : {X Y : D.Obj} (f : D [ X , Y ]) → C [ U.₁ (f D.∘ (_* (F (U.₀ X)) C.id)) C.∘ η (F (U.₀ X)) ≈ U.₁ f ]
counit-comm-right {X} {Y} f = begin
U.₁ (f D.∘ (C.id FUX.*)) C.∘ FUX.η ≈⟨ U.homomorphism ⟩∘⟨refl ⟩
(U.₁ f C.∘ U.₁ (C.id FUX.*)) C.∘ FUX.η ≈⟨ C.assoc ⟩
U.₁ f C.∘ (U.₁ (C.id FUX.*) C.∘ FUX.η) ≈⟨ refl⟩∘⟨ FUX.*-lift C.id ⟩
U.₁ f C.∘ C.id ≈⟨ C.identityʳ ⟩
U.₁ f ∎
where
open C.HomReasoning
module FUX = FreeObject (F (U.₀ X)) using (η; _*; *-lift)
counit-comm {X} {Y} f = begin
C.id FUY.* D.∘ F.₁ (U.₁ f) ≈⟨ FUX.*-uniq (U.₁ f) (C.id FUY.* D.∘ F.₁ (U.₁ f)) (counit-comm-left {X} {Y} f) ⟩
(U.₁ f) FUX.* ≈˘⟨ FUX.*-uniq (U.₁ f) (f D.∘ C.id FUX.*) (counit-comm-right {X} {Y} f) ⟩
f D.∘ C.id FUX.* ∎
where
open D.HomReasoning
module FUX = FreeObject (F (U.₀ X)) using (η; _*; *-lift; *-uniq)
module FUY = FreeObject (F (U.₀ Y)) using (η; _*; *-lift)
-- Free object functor is left adjoint to the forgetful functor
FO⇒LAdj : (F : ((X : C.Obj) → FreeObject U X)) → (FO⇒Functor F) ⊣ U
FO⇒LAdj F = record
{ unit = FO⇒unit F
; counit = FO⇒counit F
; zig = zig
; zag = zag
}
where
module F = Functor (FO⇒Functor F) using (₀; ₁; identity; homomorphism)
zig-comm1 : {X : C.Obj} → C [ U.₁ D.id C.∘ η (F X) ≈ η (F X) ]
zig-comm1 {X} = elimˡ (U.identity) where open MR C
zig-helper1 : {X : C.Obj} → D [ _* (F X) (η (F X)) ≈ D.id ]
zig-helper1 {X} = sym (FX.*-uniq FX.η D.id (zig-comm1 {X}))
where
open D.Equiv
module FX = FreeObject (F X) using (η; *-uniq)
zig-comm2 : {X : C.Obj} → C [ U.₁ (_* (F (U.₀ (F.₀ X))) C.id D.∘ F.₁ (η (F X)) ) C.∘ η (F X) ≈ η (F X) ]
zig-comm2 {X} = begin
U.₁(C.id FUFX.* D.∘ F.₁ FX.η) C.∘ FX.η ≈⟨ U.homomorphism ⟩∘⟨refl ⟩
(U.₁(C.id FUFX.*) C.∘ U.₁(F.₁ FX.η)) C.∘ FX.η ≈⟨ C.assoc ⟩
U.₁(C.id FUFX.*) C.∘ (U.₁(F.₁ FX.η) C.∘ FX.η) ≈˘⟨ refl⟩∘⟨ NaturalTransformation.commute (FO⇒unit F) FX.η ⟩
U.₁(C.id FUFX.*) C.∘ (FUFX.η C.∘ FX.η) ≈˘⟨ C.assoc ⟩
(U.₁(C.id FUFX.*) C.∘ FUFX.η) C.∘ FX.η ≈⟨ FUFX.*-lift C.id ⟩∘⟨refl ⟩
C.id C.∘ FX.η ≈⟨ C.identityˡ ⟩
FX.η ∎
where
open C.HomReasoning
module FX = FreeObject (F X) using (η)
module FUFX = FreeObject (F (U.₀ (F.₀ X)) ) using (η; _*; *-lift)
zig-helper2 : {X : C.Obj} → D [ _* (F (U.₀ (F.₀ X))) C.id D.∘ F.₁ (η (F X)) ≈ _* (F X) (η (F X)) ]
zig-helper2 {X} = FX.*-uniq FX.η (C.id FUFX.* D.∘ F.₁ FX.η) (zig-comm2 {X})
where
module FX = FreeObject (F X) using (η; *-uniq)
module FUFX = FreeObject (F (U.₀ (F.₀ X))) using (η; _*)
zig : {X : C.Obj} → D [ _* (F (U.₀ (F.₀ X))) C.id D.∘ F.₁ (η (F X)) ≈ D.id ]
zig {X} = trans zig-helper2 zig-helper1 where open D.Equiv
zag : {B : D.Obj} → C [ U.₁ (_* (F (U.₀ B)) C.id) C.∘ η (F (U.₀ B)) ≈ C.id ]
zag {B} = FUB.*-lift C.id
where module FUB = FreeObject (F (U.₀ B)) using (*-lift)
-- left adjoints yield free objects
LAdj⇒FO : (Free : Functor C D) → (Free ⊣ U) → (X : C.Obj) → FreeObject U X
LAdj⇒FO Free Free⊣U X = record
{ FX = F.₀ X
; η = η₁ X
; _* = λ {A : D.Obj} f → ε A D.∘ F.₁ f
; *-lift = *-lift'
; *-uniq = *-uniq'
}
where
module F = Functor Free using (₀; ₁; identity; homomorphism; F-resp-≈)
open Adjoint (Free⊣U) using (unit; counit; zig; zag)
open NaturalTransformation unit renaming (η to η₁; sym-commute to η-sym-commute)
open NaturalTransformation counit renaming (η to ε; commute to ε-commute)
*-lift' : {A : D.Obj} (f : C [ X , U.₀ A ]) → C [ U.₁ (ε A D.∘ F.₁ f) C.∘ η₁ X ≈ f ]
*-lift' {A} f = begin
U.₁ (ε A D.∘ F.₁ f) C.∘ η₁ X ≈⟨ U.homomorphism ⟩∘⟨refl ⟩
(U.₁ (ε A) C.∘ U.₁ (F.₁ f)) C.∘ η₁ X ≈⟨ C.assoc ⟩
U.₁ (ε A) C.∘ (U.₁ (F.₁ f) C.∘ η₁ X) ≈⟨ refl⟩∘⟨ η-sym-commute f ⟩
U.₁ (ε A) C.∘ (η₁ (U.₀ A) C.∘ f) ≈˘⟨ C.assoc ⟩
(U.₁ (ε A) C.∘ η₁ (U.₀ A)) C.∘ f ≈⟨ zag ⟩∘⟨refl ⟩
C.id C.∘ f ≈⟨ C.identityˡ ⟩
f ∎
where
open C.HomReasoning
*-uniq-sym : {A : D.Obj} (f : C [ X , U.₀ A ]) (g : D [ F.₀ X , A ]) → C [ U.₁ g C.∘ η₁ X ≈ f ] → D [ ε A D.∘ F.₁ f ≈ g ]
*-uniq-sym {A} f g comm_proof = begin
ε A D.∘ F.₁ f ≈˘⟨ refl⟩∘⟨ F.F-resp-≈ comm_proof ⟩
ε A D.∘ F.₁ (U.₁ g C.∘ η₁ X) ≈⟨ refl⟩∘⟨ F.homomorphism ⟩
ε A D.∘ ( F.₁ (U.₁ g) D.∘ F.₁ (η₁ X) ) ≈˘⟨ D.assoc ⟩
(ε A D.∘ F.₁ (U.₁ g)) D.∘ F.₁ (η₁ X) ≈⟨ ε-commute g ⟩∘⟨refl ⟩
(g D.∘ ε (F.₀ X)) D.∘ F.₁ (η₁ X) ≈⟨ D.assoc ⟩
(g D.∘ (ε (F.₀ X) D.∘ F.₁ (η₁ X))) ≈⟨ refl⟩∘⟨ zig ⟩
g D.∘ D.id ≈⟨ D.identityʳ ⟩
g ∎
where
open D.HomReasoning
*-uniq' : {A : D.Obj} (f : C [ X , U.₀ A ]) (g : D [ F.₀ X , A ]) → C [ U.₁ g C.∘ η₁ X ≈ f ] → D [ g ≈ ε A D.∘ F.₁ f ]
*-uniq' {A} f g comm_proof = begin
g ≈˘⟨ *-uniq-sym f g comm_proof ⟩
ε A D.∘ F.₁ f ∎
where
open D.HomReasoning
| {
"alphanum_fraction": 0.4192333445,
"avg_line_length": 46.4902723735,
"ext": "agda",
"hexsha": "61837cbb0008978471c446eaef0a4714c5be9a70",
"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": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/FreeObjects/Free.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"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": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/FreeObjects/Free.agda",
"max_line_length": 146,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/FreeObjects/Free.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-22T03:54:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-21T17:07:19.000Z",
"num_tokens": 5125,
"size": 11948
} |
{- Jesper Cockx, 26-05-2014
Issue 1023
-}
{-# OPTIONS --cubical-compatible #-}
module TerminationAndUnivalence where
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
J : ∀ {a b} {A : Set a} {x : A} (P : (y : A) → x ≡ y → Set b) →
(p : P x refl) {y : A} (e : x ≡ y) → P y e
J P p refl = p
data ⊥ : Set where
data WOne : Set where
wrap : (⊥ → WOne) → WOne
FOne = ⊥ → WOne
f : WOne → FOne
f x ()
g : FOne → WOne
g x = wrap (λ ())
postulate iso : WOne ≡ FOne
noo : (X : Set) → (WOne ≡ X) → X → ⊥
noo .WOne refl (wrap x) = noo FOne iso x
absurd : ⊥
absurd = noo FOne iso (λ ())
| {
"alphanum_fraction": 0.5188216039,
"avg_line_length": 16.9722222222,
"ext": "agda",
"hexsha": "ec62889cee805efc1e4a41e96d564c7eb385624c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Fail/TerminationAndUnivalence.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/TerminationAndUnivalence.agda",
"max_line_length": 63,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/TerminationAndUnivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 275,
"size": 611
} |
{-# OPTIONS --without-K #-}
module Functoriality {a} {A : Set a} where
open import PathOperations
open import Types
ap⁻¹ : ∀ {b} {B : Set b} {x y : A} (f : A → B) (p : x ≡ y) →
ap f (p ⁻¹) ≡ (ap f p) ⁻¹
ap⁻¹ f = J
(λ _ _ p → ap f (p ⁻¹) ≡ ap f p ⁻¹)
(λ _ → refl) _ _
ap· : ∀ {b} {B : Set b} {x y z : A} (f : A → B)
(p : x ≡ y) (q : y ≡ z) →
ap f (p · q) ≡ ap f p · ap f q
ap· {z = z} f = J
(λ _ y p → (q : y ≡ z) → ap f (p · q) ≡ ap f p · ap f q)
(λ _ _ → refl) _ _
ap-id : {x y : A} (p : x ≡ y) → ap id p ≡ p
ap-id = J (λ _ _ p → ap id p ≡ p) (λ _ → refl) _ _
ap-∘ : ∀ {b c} {B : Set b} {C : Set c} {x y : A}
(f : B → C) (g : A → B) (p : x ≡ y) →
ap (f ∘ g) p ≡ ap f (ap g p)
ap-∘ f g = J
(λ _ _ p → ap (f ∘ g) p ≡ ap f (ap g p))
(λ _ → refl) _ _
| {
"alphanum_fraction": 0.4051612903,
"avg_line_length": 26.724137931,
"ext": "agda",
"hexsha": "5f922e5a8fc489726008c5bf7140f40362261303",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/Functoriality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/Functoriality.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/Functoriality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 410,
"size": 775
} |
-- Given p : A ⟷ B do action on X
act : (A ⟷ B) ⟷ (X ⟷ X)
act = ?
| {
"alphanum_fraction": 0.4202898551,
"avg_line_length": 11.5,
"ext": "agda",
"hexsha": "9b8f18763ab59e2786506d9fef70327d08b7393b",
"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": "GA.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": "GA.agda",
"max_line_length": 33,
"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": "GA.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": 34,
"size": 69
} |
{-# OPTIONS --safe #-}
module Cubical.Homotopy.Loopspace where
open import Cubical.Core.Everything
open import Cubical.Data.Nat
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws
open import Cubical.HITs.SetTruncation
open import Cubical.HITs.Truncation hiding (elim2) renaming (rec to trRec)
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Function
open import Cubical.Foundations.Path
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Equiv
open import Cubical.Functions.Morphism
open import Cubical.Data.Sigma
open Iso
{- loop space of a pointed type -}
Ω : {ℓ : Level} → Pointed ℓ → Pointed ℓ
Ω (_ , a) = ((a ≡ a) , refl)
{- n-fold loop space of a pointed type -}
Ω^_ : ∀ {ℓ} → ℕ → Pointed ℓ → Pointed ℓ
(Ω^ 0) p = p
(Ω^ (suc n)) p = Ω ((Ω^ n) p)
{- loop space map -}
Ω→ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'}
→ (A →∙ B) → (Ω A →∙ Ω B)
fst (Ω→ {A = A} {B = B} (f , p)) q = sym p ∙∙ cong f q ∙∙ p
snd (Ω→ {A = A} {B = B} (f , p)) = ∙∙lCancel p
Ω^→ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ)
→ (A →∙ B) → ((Ω^ n) A →∙ (Ω^ n) B)
Ω^→ zero f = f
Ω^→ (suc n) f = Ω→ (Ω^→ n f)
{- loop space map functoriality (missing pointedness proof) -}
Ω→∘ : ∀ {ℓ ℓ' ℓ''} {A : Pointed ℓ} {B : Pointed ℓ'} {C : Pointed ℓ''}
(g : B →∙ C) (f : A →∙ B)
→ ∀ p → Ω→ (g ∘∙ f) .fst p ≡ (Ω→ g ∘∙ Ω→ f) .fst p
Ω→∘ g f p k i =
hcomp
(λ j → λ
{ (i = i0) → compPath-filler' (cong (g .fst) (f .snd)) (g .snd) (~ k) j
; (i = i1) → compPath-filler' (cong (g .fst) (f .snd)) (g .snd) (~ k) j
})
(g .fst (doubleCompPath-filler (sym (f .snd)) (cong (f .fst) p) (f .snd) k i))
{- Ω→ is a homomorphism -}
Ω→pres∙ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B)
→ (p q : typ (Ω A))
→ fst (Ω→ f) (p ∙ q) ≡ fst (Ω→ f) p ∙ fst (Ω→ f) q
Ω→pres∙ f p q i j =
hcomp
(λ k → λ
{ (i = i1) →
(doubleCompPath-filler
(sym (snd f)) (cong (fst f) p) (snd f) k
∙ doubleCompPath-filler
(sym (snd f)) (cong (fst f) q) (snd f) k) j
; (j = i0) → snd f k
; (j = i1) → snd f k})
(cong-∙ (fst f) p q i j)
isEquivΩ→ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'}
→ (f : (A →∙ B))
→ isEquiv (fst f) → isEquiv (Ω→ f .fst)
isEquivΩ→ {B = (B , b)} =
uncurry λ f →
J (λ b y → isEquiv f
→ isEquiv (λ q → (λ i → y (~ i)) ∙∙ (λ i → f (q i)) ∙∙ y))
λ eqf → subst isEquiv (funExt (rUnit ∘ cong f))
(isoToIsEquiv (congIso (equivToIso (f , eqf))))
ΩfunExtIso : ∀ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ')
→ Iso (typ (Ω (A →∙ B ∙))) (A →∙ Ω B)
fst (fun (ΩfunExtIso A B) p) x = funExt⁻ (cong fst p) x
snd (fun (ΩfunExtIso A B) p) i j = snd (p j) i
fst (inv (ΩfunExtIso A B) (f , p) i) x = f x i
snd (inv (ΩfunExtIso A B) (f , p) i) j = p j i
rightInv (ΩfunExtIso A B) _ = refl
leftInv (ΩfunExtIso A B) _ = refl
{- Commutativity of loop spaces -}
isComm∙ : ∀ {ℓ} (A : Pointed ℓ) → Type ℓ
isComm∙ A = (p q : typ (Ω A)) → p ∙ q ≡ q ∙ p
private
mainPath : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → (α β : typ ((Ω^ (2 + n)) A))
→ (λ i → α i ∙ refl) ∙ (λ i → refl ∙ β i)
≡ (λ i → refl ∙ β i) ∙ (λ i → α i ∙ refl)
mainPath n α β i = (λ j → α (j ∧ ~ i) ∙ β (j ∧ i)) ∙ λ j → α (~ i ∨ j) ∙ β (i ∨ j)
EH-filler : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → typ ((Ω^ (2 + n)) A)
→ typ ((Ω^ (2 + n)) A) → I → I → I → _
EH-filler {A = A} n α β i j z =
hfill (λ k → λ { (i = i0) → ((cong (λ x → rUnit x (~ k)) α)
∙ cong (λ x → lUnit x (~ k)) β) j
; (i = i1) → ((cong (λ x → lUnit x (~ k)) β)
∙ cong (λ x → rUnit x (~ k)) α) j
; (j = i0) → rUnit refl (~ k)
; (j = i1) → rUnit refl (~ k)})
(inS (mainPath n α β i j)) z
{- Eckmann-Hilton -}
EH : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → isComm∙ ((Ω^ (suc n)) A)
EH {A = A} n α β i j = EH-filler n α β i j i1
{- Lemmas for the syllepsis : EH α β ≡ (EH β α) ⁻¹ -}
EH-refl-refl : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ EH {A = A} n refl refl ≡ refl
EH-refl-refl {A = A} n k i j =
hcomp (λ r → λ { (k = i1) → (refl ∙ (λ _ → basep)) j
; (j = i0) → rUnit basep (~ r ∧ ~ k)
; (j = i1) → rUnit basep (~ r ∧ ~ k)
; (i = i0) → (refl ∙ (λ _ → lUnit basep (~ r ∧ ~ k))) j
; (i = i1) → (refl ∙ (λ _ → lUnit basep (~ r ∧ ~ k))) j})
(((cong (λ x → rUnit x (~ k)) (λ _ → basep))
∙ cong (λ x → lUnit x (~ k)) (λ _ → basep)) j)
where
basep = snd (Ω ((Ω^ n) A))
{- Generalisations of EH α β when α or β is refl -}
EH-gen-l : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → {x y : typ ((Ω^ (suc n)) A)} (α : x ≡ y)
→ α ∙ refl ≡ refl ∙ α
EH-gen-l {ℓ = ℓ} {A = A} n {x = x} {y = y} α i j z =
hcomp (λ k → λ { (i = i0) → ((cong (λ x → rUnit x (~ k)) α) ∙ refl) j z
; (i = i1) → (refl ∙ cong (λ x → rUnit x (~ k)) α) j z
; (j = i0) → rUnit (refl {x = x z}) (~ k) z
; (j = i1) → rUnit (refl {x = y z}) (~ k) z
; (z = i0) → x i1
; (z = i1) → y i1})
(((λ j → α (j ∧ ~ i) ∙ refl) ∙ λ j → α (~ i ∨ j) ∙ refl) j z)
EH-gen-r : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → {x y : typ ((Ω^ (suc n)) A)} (β : x ≡ y)
→ refl ∙ β ≡ β ∙ refl
EH-gen-r {A = A} n {x = x} {y = y} β i j z =
hcomp (λ k → λ { (i = i0) → (refl ∙ cong (λ x → lUnit x (~ k)) β) j z
; (i = i1) → ((cong (λ x → lUnit x (~ k)) β) ∙ refl) j z
; (j = i0) → lUnit (λ k → x (k ∧ z)) (~ k) z
; (j = i1) → lUnit (λ k → y (k ∧ z)) (~ k) z
; (z = i0) → x i1
; (z = i1) → y i1})
(((λ j → refl ∙ β (j ∧ i)) ∙ λ j → refl ∙ β (i ∨ j)) j z)
{- characterisations of EH α β when α or β is refl -}
EH-α-refl : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (α : typ ((Ω^ (2 + n)) A))
→ EH n α refl ≡ sym (rUnit α) ∙ lUnit α
EH-α-refl {A = A} n α i j k =
hcomp (λ r → λ { (i = i0) → EH-gen-l n (λ i → α (i ∧ r)) j k
; (i = i1) → (sym (rUnit λ i → α (i ∧ r)) ∙ lUnit λ i → α (i ∧ r)) j k
; (j = i0) → ((λ i → α (i ∧ r)) ∙ refl) k
; (j = i1) → (refl ∙ (λ i → α (i ∧ r))) k
; (k = i0) → refl
; (k = i1) → α r})
((EH-refl-refl n ∙ sym (lCancel (rUnit refl))) i j k)
EH-refl-β : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (β : typ ((Ω^ (2 + n)) A))
→ EH n refl β ≡ sym (lUnit β) ∙ rUnit β
EH-refl-β {A = A} n β i j k =
hcomp (λ r → λ { (i = i0) → EH-gen-r n (λ i → β (i ∧ r)) j k
; (i = i1) → (sym (lUnit λ i → β (i ∧ r)) ∙ rUnit λ i → β (i ∧ r)) j k
; (j = i0) → (refl ∙ (λ i → β (i ∧ r))) k
; (j = i1) → ((λ i → β (i ∧ r)) ∙ refl) k
; (k = i0) → refl
; (k = i1) → β r})
((EH-refl-refl n ∙ sym (lCancel (rUnit refl))) i j k)
syllepsis : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (α β : typ ((Ω^ 3) A))
→ EH 0 α β ≡ sym (EH 0 β α)
syllepsis {A = A} n α β k i j =
hcomp (λ r → λ { (i = i0) → i=i0 r j k
; (i = i1) → i=i1 r j k
; (j = i0) → j-filler r j k
; (j = i1) → j-filler r j k
; (k = i0) → EH-filler 1 α β i j r
; (k = i1) → EH-filler 1 β α (~ i) j r})
(btm-filler (~ k) i j)
where
guy = snd (Ω (Ω A))
btm-filler : I → I → I → typ (Ω (Ω A))
btm-filler j i k =
hcomp (λ r
→ λ {(j = i0) → mainPath 1 β α (~ i) k
; (j = i1) → mainPath 1 α β i k
; (i = i0) → (cong (λ x → EH-α-refl 0 x r (~ j)) α
∙ cong (λ x → EH-refl-β 0 x r (~ j)) β) k
; (i = i1) → (cong (λ x → EH-refl-β 0 x r (~ j)) β
∙ cong (λ x → EH-α-refl 0 x r (~ j)) α) k
; (k = i0) → EH-α-refl 0 guy r (~ j)
; (k = i1) → EH-α-refl 0 guy r (~ j)})
(((λ l → EH 0 (α (l ∧ ~ i)) (β (l ∧ i)) (~ j))
∙ λ l → EH 0 (α (l ∨ ~ i)) (β (l ∨ i)) (~ j)) k)
link : I → I → I → _
link z i j =
hfill (λ k → λ { (i = i1) → refl
; (j = i0) → rUnit refl (~ i)
; (j = i1) → lUnit guy (~ i ∧ k)})
(inS (rUnit refl (~ i ∧ ~ j))) z
i=i1 : I → I → I → typ (Ω (Ω A))
i=i1 r j k =
hcomp (λ i → λ { (r = i0) → (cong (λ x → compPath-filler (sym (lUnit x)) (rUnit x) i k) β
∙ cong (λ x → compPath-filler (sym (rUnit x)) (lUnit x) i k) α) j
; (r = i1) → (β ∙ α) j
; (k = i0) → (cong (λ x → lUnit x (~ r)) β ∙
cong (λ x → rUnit x (~ r)) α) j
; (k = i1) → (cong (λ x → rUnit x (~ r ∧ i)) β ∙
cong (λ x → lUnit x (~ r ∧ i)) α) j
; (j = i0) → link i r k
; (j = i1) → link i r k})
(((cong (λ x → lUnit x (~ r ∧ ~ k)) β
∙ cong (λ x → rUnit x (~ r ∧ ~ k)) α)) j)
i=i0 : I → I → I → typ (Ω (Ω A))
i=i0 r j k =
hcomp (λ i → λ { (r = i0) → (cong (λ x → compPath-filler (sym (rUnit x)) (lUnit x) i k) α
∙ cong (λ x → compPath-filler (sym (lUnit x)) (rUnit x) i k) β) j
; (r = i1) → (α ∙ β) j
; (k = i0) → (cong (λ x → rUnit x (~ r)) α ∙
cong (λ x → lUnit x (~ r)) β) j
; (k = i1) → (cong (λ x → lUnit x (~ r ∧ i)) α ∙
cong (λ x → rUnit x (~ r ∧ i)) β) j
; (j = i0) → link i r k
; (j = i1) → link i r k})
((cong (λ x → rUnit x (~ r ∧ ~ k)) α
∙ cong (λ x → lUnit x (~ r ∧ ~ k)) β) j)
j-filler : I → I → I → typ (Ω (Ω A))
j-filler r i k =
hcomp (λ j → λ { (i = i0) → link j r k
; (i = i1) → link j r k
; (r = i0) → compPath-filler (sym (rUnit guy))
(lUnit guy) j k
; (r = i1) → refl
; (k = i0) → rUnit guy (~ r)
; (k = i1) → rUnit guy (j ∧ ~ r)})
(rUnit guy (~ r ∧ ~ k))
------ Ωⁿ⁺¹ A ≃ Ωⁿ(Ω A) ------
flipΩPath : {ℓ : Level} {A : Pointed ℓ} (n : ℕ)
→ ((Ω^ (suc n)) A) ≡ (Ω^ n) (Ω A)
flipΩPath {A = A} zero = refl
flipΩPath {A = A} (suc n) = cong Ω (flipΩPath {A = A} n)
flipΩIso : {ℓ : Level} {A : Pointed ℓ} (n : ℕ)
→ Iso (fst ((Ω^ (suc n)) A)) (fst ((Ω^ n) (Ω A)))
flipΩIso {A = A} n = pathToIso (cong fst (flipΩPath n))
flipΩIso⁻pres· : {ℓ : Level} {A : Pointed ℓ} (n : ℕ)
→ (f g : fst ((Ω^ (suc n)) (Ω A)))
→ inv (flipΩIso (suc n)) (f ∙ g)
≡ (inv (flipΩIso (suc n)) f)
∙ (inv (flipΩIso (suc n)) g)
flipΩIso⁻pres· {A = A} n f g i =
transp (λ j → flipΩPath {A = A} n (~ i ∧ ~ j) .snd
≡ flipΩPath n (~ i ∧ ~ j) .snd) i
(transp (λ j → flipΩPath {A = A} n (~ i ∨ ~ j) .snd
≡ flipΩPath n (~ i ∨ ~ j) .snd) (~ i) f
∙ transp (λ j → flipΩPath {A = A} n (~ i ∨ ~ j) .snd
≡ flipΩPath n (~ i ∨ ~ j) .snd) (~ i) g)
flipΩIsopres· : {ℓ : Level} {A : Pointed ℓ} (n : ℕ)
→ (f g : fst (Ω ((Ω^ (suc n)) A)))
→ fun (flipΩIso (suc n)) (f ∙ g)
≡ (fun (flipΩIso (suc n)) f)
∙ (fun (flipΩIso (suc n)) g)
flipΩIsopres· n =
morphLemmas.isMorphInv _∙_ _∙_
(inv (flipΩIso (suc n)))
(flipΩIso⁻pres· n)
(fun (flipΩIso (suc n)))
(Iso.leftInv (flipΩIso (suc n)))
(Iso.rightInv (flipΩIso (suc n)))
flipΩrefl : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ fun (flipΩIso {A = A} (suc n)) refl ≡ refl
flipΩrefl {A = A} n j =
transp (λ i₁ → fst (Ω (flipΩPath {A = A} n ((i₁ ∨ j)))))
j (snd (Ω (flipΩPath n j)))
---- Misc. ----
isCommA→isCommTrunc : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → isComm∙ A
→ isOfHLevel (suc n) (typ A)
→ isComm∙ (∥ typ A ∥ (suc n) , ∣ pt A ∣)
isCommA→isCommTrunc {A = (A , a)} n comm hlev p q =
((λ i j → (leftInv (truncIdempotentIso (suc n) hlev) ((p ∙ q) j) (~ i)))
∙∙ (λ i → cong {B = λ _ → ∥ A ∥ (suc n) } (λ x → ∣ x ∣)
(cong (trRec hlev (λ x → x)) (p ∙ q)))
∙∙ (λ i → cong {B = λ _ → ∥ A ∥ (suc n) } (λ x → ∣ x ∣)
(congFunct {A = ∥ A ∥ (suc n)} {B = A} (trRec hlev (λ x → x)) p q i)))
∙ ((λ i → cong {B = λ _ → ∥ A ∥ (suc n) } (λ x → ∣ x ∣)
(comm (cong (trRec hlev (λ x → x)) p) (cong (trRec hlev (λ x → x)) q) i))
∙∙ (λ i → cong {B = λ _ → ∥ A ∥ (suc n) } (λ x → ∣ x ∣)
(congFunct {A = ∥ A ∥ (suc n)} {B = A} (trRec hlev (λ x → x)) q p (~ i)))
∙∙ (λ i j → (leftInv (truncIdempotentIso (suc n) hlev) ((q ∙ p) j) i)))
ptdIso→comm : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Type ℓ'} (e : Iso (typ A) B)
→ isComm∙ A → isComm∙ (B , fun e (pt A))
ptdIso→comm {A = (A , a)} {B = B} e comm p q =
sym (rightInv (congIso e) (p ∙ q))
∙∙ (cong (fun (congIso e)) ((invCongFunct e p q)
∙∙ (comm (inv (congIso e) p) (inv (congIso e) q))
∙∙ (sym (invCongFunct e q p))))
∙∙ rightInv (congIso e) (q ∙ p)
{- Homotopy group version -}
π-comp : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → ∥ typ ((Ω^ (suc n)) A) ∥₂
→ ∥ typ ((Ω^ (suc n)) A) ∥₂ → ∥ typ ((Ω^ (suc n)) A) ∥₂
π-comp n = elim2 (λ _ _ → isSetSetTrunc) λ p q → ∣ p ∙ q ∣₂
EH-π : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (p q : ∥ typ ((Ω^ (2 + n)) A) ∥₂)
→ π-comp (1 + n) p q ≡ π-comp (1 + n) q p
EH-π n = elim2 (λ x y → isOfHLevelPath 2 isSetSetTrunc _ _)
λ p q → cong ∣_∣₂ (EH n p q)
| {
"alphanum_fraction": 0.4040712107,
"avg_line_length": 42.5951661631,
"ext": "agda",
"hexsha": "a68c264951f9e6b581b55c6f419be9b47d9f0c40",
"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": "8dea02ee105b45898dbf1f77271ead38994f4d61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rnarkk/cubical",
"max_forks_repo_path": "Cubical/Homotopy/Loopspace.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8dea02ee105b45898dbf1f77271ead38994f4d61",
"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": "rnarkk/cubical",
"max_issues_repo_path": "Cubical/Homotopy/Loopspace.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8dea02ee105b45898dbf1f77271ead38994f4d61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rnarkk/cubical",
"max_stars_repo_path": "Cubical/Homotopy/Loopspace.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6080,
"size": 14099
} |
module Serializer.Vec where
open import Data.Fin hiding (_+_)
open import Data.Nat
open import Data.Vec
open import Function using (_∘_ ; _$_ ; _∋_ ; id ; const)
open import Function.Bijection
open import Function.Injection
open import Function.Surjection
open import Function.Equality using (_⟶_ ; _⟨$⟩_ ; Π )
open import Function.LeftInverse hiding (_∘_)
open import Relation.Binary
open import Relation.Binary.EqReasoning
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; cong ; setoid )
import Relation.Binary.Indexed as I
open import Serializer
open import Helper.Fin
open Serializer.Serializer {{...}}
-----------------------------------
-- Generic instance for Vec
-----------------------------------
2^ : ℕ -> ℕ
2^ zero = 1
2^ (suc b) = 2 * 2^ b
-- inverted exponent
_^_ : ℕ -> ℕ -> ℕ
zero ^ a = 1
suc b ^ a = a * (b ^ a)
fromVec : ∀ {n} {A : Set} -> {{t : Serializer A}} -> Vec A n -> Fin (n ^ (size {A}))
fromVec {zero} [] = zero
fromVec {suc n} {a} (x ∷ v) = × (size {a}) (n ^ (size {a})) (from x) (fromVec v)
toVec` : ∀ {n} {A : Set} -> {{t : Serializer A}} -> Fin (n ^ (size {A})) -> Vec A n
toVec` {zero} x = []
toVec` {suc n} {a} {{t}} x with Serializer.to t | toVec` {n} {a} {{t}}
... | to1 | to2 with Serializer.size t
... | s with ⨂ s (n ^ s) x
toVec` {suc n} .(× s (n ^ s) i j) | to1 | to2 | s | is× i j = to1 i ∷ to2 j
vec-from-cong : ∀ {n} {A : Set} -> {{t : Serializer A}} -> Setoid._≈_ (setoid (Vec A n)) I.=[ fromVec ]⇒ Setoid._≈_ (setoid (Fin (n ^ (size {A}))))
vec-from-cong refl = refl
vec-from-preserves-eq : ∀ {n} {A : Set} -> {{t : Serializer A}} -> setoid (Vec A n) ⟶ setoid (Fin (n ^ (size {A})))
vec-from-preserves-eq = record { _⟨$⟩_ = fromVec ; cong = vec-from-cong }
vec-from-injective : ∀ {n} {A : Set} -> {{t : Serializer A}} -> Injective (vec-from-preserves-eq {n} {A} {{t}})
vec-from-injective {zero} {a} {{t}} {x = []} {[]} x₁ with fromVec {A = a} {{t}} []
... | p1 = refl
vec-from-injective {suc n} {a} {{t}} {x ∷ x₁} {y ∷ y₁} p with (⨂ (Serializer.size t) (n ^ (Serializer.size t)) (fromVec (x ∷ x₁))) | (⨂ (Serializer.size t) (n ^ (Serializer.size t)) (fromVec (y ∷ y₁)))
... | a1 | b2 with vec-from-injective {n} {_} {{t}} {x₁} {y₁}
... | c with c (×-equal₁ {x₁ = (Serializer.from t x)} {x₂ = (Serializer.from t y)} p) | (×-equal₂ {x₁ = (Serializer.from t x)} {x₂ = (Serializer.from t y)} p)
... | p1 | p2 with Serializer.from t
... | la = ?
--(Injection.injective (Serializer.injection t))
{-
vec-from-injective : ∀ {n} -> Injective (vec-from-preserves-eq {n})
vec-from-injective {zero} {[]} {[]} p with fromVec []
... | p2 = refl
vec-from-injective {suc n} {x ∷ x₁} {y ∷ y₁} p with (⨂ 2 (2^ n) (fromVec (x ∷ x₁))) | (⨂ 2 (2^ n) (fromVec (y ∷ y₁)))
... | a1 | b2 with vec-from-injective {n} {x₁} {y₁}
... | c with c (×-equal₁ {x₁ = (fromBool x)} {x₂ = (fromBool y)} p) | (×-equal₂ {x₁ = (fromBool x)} {x₂ = (fromBool y)} p)
... | p1 | p2 with from-bool-injective p2
vec-from-injective {suc n} {x ∷ x₁} {.x ∷ .x₁} p | a1 | b2 | c | refl | p2 | refl = refl
-}
vec-from-surjective : ∀ {n} {A : Set} -> {{t : Serializer A}} -> Surjective (vec-from-preserves-eq {n} {A} {{t}})
vec-from-surjective {n} {a} {{t}} = record { from = preserves-eq-inv ; right-inverse-of = (inv {n} {a} {{t}}) }
where
cong-inverse : ∀ {n} {A : Set} -> {{t : Serializer A}} -> Setoid._≈_ (setoid (Fin (n ^ (size {A})))) I.=[ toVec` ]⇒ Setoid._≈_ (setoid (Vec A n))
cong-inverse refl = refl
preserves-eq-inv : ∀ {n} {A : Set} -> {{t : Serializer A}} -> setoid (Fin (n ^ (size {A}))) ⟶ setoid (Vec A n)
preserves-eq-inv = record { _⟨$⟩_ = toVec` ; cong = cong-inverse }
inv : ∀ {n} {A : Set} -> {{t : Serializer A}} -> (preserves-eq-inv {n} {A} {{t}}) RightInverseOf (vec-from-preserves-eq {n} {A} {{t}})
inv {zero} zero = refl
inv {zero} (suc ())
inv {suc n₁} {a} {{t}} x with ⨂ (Serializer.size t) (n₁ ^ (Serializer.size t)) x
inv {suc n₁} {a} {{t}} ._ | is× i j with (Surjective.right-inverse-of (Bijective.surjective (Bijection.bijective (Serializer.bijection t)))) i
... | ple = {!!}
-- rewrite (inv {n₁} {a} {{t}} j)
-- ... | ple = ?
-- ... | moo with (inv {n₁} {a} {{t}} j)
-- ... | moo1 = refl -- {!!}
{-
inv {suc n₁} ._ | is× i j with (Surjective.right-inverse-of (Bijective.surjective (Bijection.bijective (Serializer.bijection t))))
... | moo = {!!}-}
-- rewrite (Surjective.right-inverse-of (Bijective.surjective (Bijection.bijective (Serializer.bijection t)))) i | (inv {n₁} j) = refl
{-
vec-from-surjective : ∀ {n} -> Surjective (vec-from-preserves-eq {n})
vec-from-surjective {n} = record { from = preserves-eq-inv ; right-inverse-of = (inv {n}) }
where
cong-inverse : ∀ {n} -> Setoid._≈_ (setoid (Fin (2^ n))) I.=[ toVec` ]⇒ Setoid._≈_ (setoid (Vec Bool n))
cong-inverse refl = refl
preserves-eq-inv : ∀ {n} -> setoid (Fin (2^ n)) ⟶ setoid (Vec Bool n)
preserves-eq-inv = record { _⟨$⟩_ = toVec` ; cong = cong-inverse }
inv : ∀ {n} -> (preserves-eq-inv {n}) RightInverseOf (vec-from-preserves-eq {n})
inv {zero} zero = refl
inv {zero} (suc ())
inv {suc n₁} x with ⨂ 2 (2^ n₁) x
inv {suc n₁} .(× 2 (2^ n₁) i j) | is× i j
rewrite (Surjective.right-inverse-of (Bijective.surjective (Bijection.bijective (bijection {Bool})))) i | (inv {n₁} j) = refl
-}
| {
"alphanum_fraction": 0.561918929,
"avg_line_length": 44.8166666667,
"ext": "agda",
"hexsha": "60dd1441feb38601522ca773c69719b3865d376d",
"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": "cb95986b772b7a01195619be5e8e590f2429c759",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mathijsb/generic-in-agda",
"max_forks_repo_path": "Serializer/Vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759",
"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": "mathijsb/generic-in-agda",
"max_issues_repo_path": "Serializer/Vec.agda",
"max_line_length": 202,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mathijsb/generic-in-agda",
"max_stars_repo_path": "Serializer/Vec.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-04T16:05:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-09T09:59:27.000Z",
"num_tokens": 1991,
"size": 5378
} |
open import Data.List using ( [] )
open import Data.Product using ( proj₁ ; proj₂ )
open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ )
open import Relation.Binary.PropositionalEquality using ( refl )
open import Web.Semantic.DL.ABox.Interp using ( ⌊_⌋ ; ind ; _*_ )
open import Web.Semantic.DL.ABox.Interp.Morphism using ( _,_ )
open import Web.Semantic.DL.ABox.Model using
( _⊨a_ ; on-bnode ; bnodes ; _,_ ; ⊨a-resp-≲ )
open import Web.Semantic.DL.Category.Composition using ( _∙_ )
open import Web.Semantic.DL.Category.Properties.Composition.Assoc using
( compose-assoc )
open import Web.Semantic.DL.Category.Properties.Composition.Lemmas using
( compose-left ; compose-right ; compose-resp-⊨a )
open import Web.Semantic.DL.Category.Properties.Composition.RespectsEquiv using
( compose-resp-≣ )
open import Web.Semantic.DL.Category.Properties.Equivalence using
( ≣-refl ; ≣-sym ; ≣-trans )
open import Web.Semantic.DL.Category.Properties.Tensor.Coherence using
( symm-unit )
open import Web.Semantic.DL.Category.Properties.Tensor.Lemmas using
( tensor-up ; tensor-down ; tensor-resp-⊨a )
open import Web.Semantic.DL.Category.Properties.Tensor.SymmNatural using
( symm-natural )
open import Web.Semantic.DL.Category.Object using ( Object ; IN ; fin )
open import Web.Semantic.DL.Category.Morphism using
( _⇒_ ; BN ; impl ; _⊑_ ; _≣_ ; _,_ )
open import Web.Semantic.DL.Category.Tensor using ( _⟨⊗⟩_ )
open import Web.Semantic.DL.Category.Unit using ( I )
open import Web.Semantic.DL.Category.Wiring using
( wires-≈ ; wires-≈⁻¹ ; identity ; unit₁ ; unit₂ ; symm )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
open import Web.Semantic.DL.TBox.Interp using ( Δ ; _⊨_≈_ ; ≈-refl ; ≈-sym )
open import Web.Semantic.DL.TBox.Interp.Morphism using ( ≲-refl )
open import Web.Semantic.Util using
( _∘_ ; False ; _⊕_⊕_ ; inode ; bnode ; enode ; left ; right ; up ; down )
module Web.Semantic.DL.Category.Properties.Tensor.UnitNatural
{Σ : Signature} {S T : TBox Σ} where
unit₁-natural : ∀ {A B : Object S T} (F : A ⇒ B) →
((identity I ⟨⊗⟩ F) ∙ unit₁ B ≣ unit₁ A ∙ F)
unit₁-natural {A} {B} F = (LHS⊑RHS , RHS⊑LHS) where
LHS⊑RHS : ((identity I ⟨⊗⟩ F) ∙ unit₁ B ⊑ unit₁ A ∙ F)
LHS⊑RHS J J⊨STA J⊨LHS = (f , J⊨RHS) where
f : False ⊕ IN A ⊕ BN F → Δ ⌊ J ⌋
f (inode ())
f (bnode x) = ind J (inode (inj₂ x))
f (enode v) = ind J (bnode (inode (inj₂ v)))
f✓ : ∀ x → ⌊ J ⌋ ⊨ ind J (left (down x)) ≈ on-bnode f (ind J) (right x)
f✓ (inode x) = ≈-refl ⌊ J ⌋
f✓ (bnode v) = ≈-refl ⌊ J ⌋
f✓ (enode y) = wires-≈ inj₂ (proj₂ (fin B) y)
(compose-right (identity I ⟨⊗⟩ F) (unit₁ B) J J⊨LHS)
J⊨RHS : bnodes J f ⊨a impl (unit₁ A ∙ F)
J⊨RHS = compose-resp-⊨a (unit₁ A) F (bnodes J f)
(wires-≈⁻¹ inj₂ (λ x → ≈-refl ⌊ J ⌋) (proj₁ (fin A)))
(⊨a-resp-≲ (≲-refl ⌊ J ⌋ , f✓) (impl F)
(tensor-down (identity I) F (left * J)
(compose-left (identity I ⟨⊗⟩ F) (unit₁ B) J J⊨LHS)))
RHS⊑LHS : (unit₁ A ∙ F ⊑ (identity I ⟨⊗⟩ F) ∙ unit₁ B)
RHS⊑LHS J J⊨STA J⊨RHS = (f , J⊨LHS) where
f : ((False ⊎ BN F) ⊕ (False ⊎ IN B) ⊕ False) → Δ ⌊ J ⌋
f (inode (inj₁ ()))
f (inode (inj₂ v)) = ind J (bnode (enode v))
f (bnode (inj₁ ()))
f (bnode (inj₂ y)) = ind J (enode y)
f (enode ())
f✓ : ∀ x → ⌊ J ⌋ ⊨ ind J (right x) ≈ on-bnode f (ind J) (left (down x))
f✓ (inode x) = ≈-sym ⌊ J ⌋ (wires-≈ inj₂ (proj₂ (fin A) x) (compose-left (unit₁ A) F J J⊨RHS))
f✓ (bnode v) = ≈-refl ⌊ J ⌋
f✓ (enode y) = ≈-refl ⌊ J ⌋
J⊨LHS : bnodes J f ⊨a impl ((identity I ⟨⊗⟩ F) ∙ unit₁ B)
J⊨LHS = compose-resp-⊨a (identity I ⟨⊗⟩ F) (unit₁ B) (bnodes J f)
(tensor-resp-⊨a (identity I) F (left * bnodes J f)
(wires-≈⁻¹ {I = up * left * bnodes J f} (λ ()) (λ ()) [])
(⊨a-resp-≲ (≲-refl ⌊ J ⌋ , f✓) (impl F)
(compose-right (unit₁ A) F J J⊨RHS)))
(wires-≈⁻¹ inj₂ (λ x → ≈-refl ⌊ J ⌋) (proj₁ (fin B)))
unit₂-natural : ∀ {A B : Object S T} (F : A ⇒ B) →
((F ⟨⊗⟩ identity I) ∙ unit₂ B ≣ unit₂ A ∙ F)
unit₂-natural {A} {B} F =
≣-trans
(compose-resp-≣ (≣-refl (F ⟨⊗⟩ identity I)) (≣-sym (symm-unit B)))
(≣-trans
(≣-sym (compose-assoc (F ⟨⊗⟩ identity I) (symm B I) (unit₁ B)))
(≣-trans
(compose-resp-≣ (symm-natural F (identity I)) (≣-refl (unit₁ B)))
(≣-trans
(compose-assoc (symm A I) (identity I ⟨⊗⟩ F) (unit₁ B))
(≣-trans
(compose-resp-≣ (≣-refl (symm A I)) (unit₁-natural F))
(≣-trans
(≣-sym (compose-assoc (symm A I) (unit₁ A) F))
(compose-resp-≣ (symm-unit A) (≣-refl F)))))))
| {
"alphanum_fraction": 0.5968370884,
"avg_line_length": 43.9619047619,
"ext": "agda",
"hexsha": "a397c787bd0a55cae930b18f6a36a7919c5f5704",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Category/Properties/Tensor/UnitNatural.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Category/Properties/Tensor/UnitNatural.agda",
"max_line_length": 98,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Category/Properties/Tensor/UnitNatural.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 1966,
"size": 4616
} |
module PiFrac where
open import Level
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product
infixr 20 _◎_
data <_> {A : Set} : A → Set where
singleton : (x : A) -> < x >
mutual
data B : Set₁ where
ZERO : B
ONE : B
PLUS : B → B → B
TIMES : B → B → B
SING : (b : B) → ⟦ b ⟧ → B
RECIP : (b : B) → ⟦ b ⟧ → B
DPAIR : (b : B) → (⟦ b ⟧ → B) → B
⟦_⟧ : B → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS b₁ b₂ ⟧ = ⟦ b₁ ⟧ ⊎ ⟦ b₂ ⟧
⟦ TIMES b₁ b₂ ⟧ = ⟦ b₁ ⟧ × ⟦ b₂ ⟧
⟦ SING b v ⟧ = <_> {⟦ b ⟧} v
⟦ RECIP b v ⟧ = <_> {⟦ b ⟧} v → ⊤
⟦ DPAIR b c ⟧ = Σ ⟦ b ⟧ (λ v → ⟦ c v ⟧)
data _⟷_ : B → B → Set₁ where
unite₊ : {b : B} → PLUS ZERO b ⟷ b
uniti₊ : {b : B} → b ⟷ PLUS ZERO b
swap₊ : {b₁ b₂ : B} → PLUS b₁ b₂ ⟷ PLUS b₂ b₁
assocl₊ : { b₁ b₂ b₃ : B } → PLUS b₁ (PLUS b₂ b₃) ⟷ PLUS (PLUS b₁ b₂) b₃
assocr₊ : { b₁ b₂ b₃ : B } → PLUS (PLUS b₁ b₂) b₃ ⟷ PLUS b₁ (PLUS b₂ b₃)
unite⋆ : { b : B } → TIMES ONE b ⟷ b
uniti⋆ : { b : B } → b ⟷ TIMES ONE b
swap⋆ : {b₁ b₂ : B} → TIMES b₁ b₂ ⟷ TIMES b₂ b₁
assocl⋆ : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷ TIMES (TIMES b₁ b₂) b₃
assocr⋆ : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷ TIMES b₁ (TIMES b₂ b₃)
id⟷ : {b : B } → b ⟷ b
sym : { b₁ b₂ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁)
_◎_ : { b₁ b₂ b₃ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₃) → (b₁ ⟷ b₃)
_⊕_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (PLUS b₁ b₂ ⟷ PLUS b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (TIMES b₁ b₂ ⟷ TIMES b₃ b₄)
η : {b : B} → ONE ⟷ DPAIR b (λ v → RECIP b v)
ε : {b : B} → DPAIR b (λ v → RECIP b v) ⟷ ONE
mutual
eval : {b₁ b₂ : B} → (c : b₁ ⟷ b₂) → ⟦ b₁ ⟧ → ⟦ b₂ ⟧
eval unite₊ (inj₁ ())
eval unite₊ (inj₂ v) = v
eval uniti₊ v = inj₂ v
eval swap₊ (inj₁ x) = inj₂ x
eval swap₊ (inj₂ y) = inj₁ y
eval assocl₊ (inj₁ x) = inj₁ (inj₁ x)
eval assocl₊ (inj₂ (inj₁ x)) = inj₁ (inj₂ x)
eval assocl₊ (inj₂ (inj₂ x)) = inj₂ x
eval assocr₊ (inj₁ (inj₁ x)) = inj₁ x
eval assocr₊ (inj₁ (inj₂ y)) = inj₂ (inj₁ y)
eval assocr₊ (inj₂ y) = inj₂ (inj₂ y)
eval unite⋆ (tt , x) = x
eval uniti⋆ v = ( tt , v)
eval swap⋆ (v₁ , v₂) = (v₂ , v₁)
eval assocl⋆ (x , (y , z)) = ((x , y), z)
eval assocr⋆ ((x , y), z) = (x , (y , z))
eval id⟷ v = v
eval (sym c) v = evalB c v
eval (c₁ ◎ c₂) v = eval c₂ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₁ x) = inj₁ (eval c₁ x)
eval (c₁ ⊕ c₂) (inj₂ y) = inj₂ (eval c₂ y)
eval (c₁ ⊗ c₂) (x , y) = (eval c₁ x , eval c₂ y)
eval (η {b}) tt = {!!}
eval (ε {b}) (w , c) = c (singleton w)
evalB : {b₁ b₂ : B} → (c : b₁ ⟷ b₂) → ⟦ b₂ ⟧ → ⟦ b₁ ⟧
evalB uniti₊ (inj₁ ())
evalB uniti₊ (inj₂ v) = v
evalB unite₊ v = inj₂ v
evalB swap₊ (inj₁ x) = inj₂ x
evalB swap₊ (inj₂ y) = inj₁ y
evalB assocr₊ (inj₁ x) = inj₁ (inj₁ x)
evalB assocr₊ (inj₂ (inj₁ x)) = inj₁ (inj₂ x)
evalB assocr₊ (inj₂ (inj₂ x)) = inj₂ x
evalB assocl₊ (inj₁ (inj₁ x)) = inj₁ x
evalB assocl₊ (inj₁ (inj₂ y)) = inj₂ (inj₁ y)
evalB assocl₊ (inj₂ y) = inj₂ (inj₂ y)
evalB uniti⋆ (tt , x) = x
evalB unite⋆ v = ( tt , v)
evalB swap⋆ (v₁ , v₂) = (v₂ , v₁)
evalB assocr⋆ (x , (y , z)) = ((x , y), z)
evalB assocl⋆ ((x , y), z) = (x , (y , z))
evalB id⟷ v = v
evalB (sym c) v = eval c v
evalB (c₁ ◎ c₂) v = evalB c₁ (evalB c₂ v)
evalB (c₁ ⊕ c₂) (inj₁ x) = inj₁ (evalB c₁ x)
evalB (c₁ ⊕ c₂) (inj₂ y) = inj₂ (evalB c₂ y)
evalB (c₁ ⊗ c₂) (x , y) = (evalB c₁ x , evalB c₂ y)
evalB (η {b}) (w , c) = c (singleton w)
evalB (ε {b}) tt = {!!}
-- this is better in that one can't use inj₂ tt on the rhs
-- the overly precise version doesn't type check, don't know why
test : ⊤
test = eval (ε {PLUS ONE ONE}) (inj₁ tt , f)
where f : < inj₁ {B = ⊤} tt > → ⊤
-- f (singleton (inj₁ {B = ⊤} tt)) = tt
f x = tt
{-
mutual
data B : Set where
ONE : B
PLUS : B → B → B
TIMES : B → B → B
MATCH : {b : B} → Singleton b → B
DPAIR : {b : B} → (Σ (BV b) Singleton) → B
mutual
eval : {b₁ b₂ : B} → b₁ ⟷ b₂ → BV b₁ → BV b₂
eval swap₊ (LEFT v) = RIGHT v
eval swap₊ (RIGHT v) = LEFT v
eval (η {b₁} {v}) UNIT = NCPROD b₁ v
eval assocl₊ (LEFT v) = LEFT (LEFT v)
eval assocl₊ (RIGHT (LEFT v)) = LEFT (RIGHT v)
eval assocl₊ (RIGHT (RIGHT v)) = RIGHT v
eval assocr₊ (LEFT (LEFT v)) = LEFT v
eval assocr₊ (LEFT (RIGHT v)) = RIGHT (LEFT v)
eval assocr₊ (RIGHT v) = RIGHT (RIGHT v)
eval unite⋆ (PAIR UNIT v) = v
eval uniti⋆ v = PAIR UNIT v
eval (ε {b₁} {v}) (NCPROD .b₁ .v) = UNIT
eval id⟷ v = v
eval (c₁ ◎ c₂) v = eval c₂ (eval c₁ v)
eval (c₁ ⊕ c₂) (LEFT v) = LEFT (eval c₁ v)
eval (c₁ ⊕ c₂) (RIGHT v) = RIGHT (eval c₂ v)
eval (c₁ ⊗ c₂) (PAIR v₁ v₂) = PAIR (eval c₁ v₁) (eval c₂ v₂)
eval (lift {b₁} {b₂} {v} c) (NCPROD .b₁ .v) = NCPROD b₂ (eval c v)
-- name : {b₁ b₂ : B} {v : BV b₁} → (b₁ ⟷ b₂) → (ONE ⟷ DPAIR (v , singleton v))
-- name {b₁} {b₂} {v} c = η {b₁} {v} ◎ (lift (id⟷ ⊗ c))
--}
--------------------------------------------------------------------------------
-- Jacques's code
{--
data Singleton {A : Set} : A → Set where
singleton : (x : A) -> Singleton x
mutual
data B : Set where
ONE : B
PLUS : B → B → B
TIMES : B → B → B
MATCH : {b : B} → Singleton b → B
DPAIR : {b : B} → (Σ (BV b) Singleton) → B
data BV : B → Set where
UNIT : BV ONE
LEFT : {b₁ b₂ : B} → BV b₁ → BV (PLUS b₁ b₂)
RIGHT : {b₁ b₂ : B} → BV b₂ → BV (PLUS b₁ b₂)
PAIR : {b₁ b₂ : B} → BV b₁ → BV b₂ → BV (TIMES b₁ b₂)
SINGLE : {b₁ : B} → BV b₁ → BV (MATCH {b₁} (singleton b₁))
NCPROD : (b₁ : B) → (v : BV b₁) → BV (DPAIR (v , (singleton v)))
mutual
data _⟷_ : B → B → Set where
swap₊ : {b₁ b₂ : B} → PLUS b₁ b₂ ⟷ PLUS b₂ b₁
assocl₊ : { b₁ b₂ b₃ : B } → PLUS b₁ (PLUS b₂ b₃) ⟷ PLUS (PLUS b₁ b₂) b₃
assocr₊ : { b₁ b₂ b₃ : B } → PLUS (PLUS b₁ b₂) b₃ ⟷ PLUS b₁ (PLUS b₂ b₃)
unite⋆ : { b : B } → TIMES ONE b ⟷ b
uniti⋆ : { b : B } → b ⟷ TIMES ONE b
η : {b₁ : B} {v : BV b₁} → ONE ⟷ DPAIR (v , (singleton v))
ε : {b₁ : B} {v : BV b₁} → DPAIR (v , (singleton v)) ⟷ ONE
id⟷ : {b : B } → b ⟷ b
-- closure combinators
-- sym : { b₁ b₂ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁)
_◎_ : { b₁ b₂ b₃ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₃) → (b₁ ⟷ b₃)
_⊕_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (PLUS b₁ b₂ ⟷ PLUS b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (TIMES b₁ b₂ ⟷ TIMES b₃ b₄)
-- refe⋆ : { b : BF } → RECIP (RECIP b) ⟺ b
-- refi⋆ : { b : BF } → b ⟺ RECIP (RECIP b)
-- rile⋆ : { b : BF } → TIMESF b (TIMESF b (RECIP b)) ⟺ b
-- rili⋆ : { b : BF } → b ⟺ TIMESF b (TIMESF b (RECIP b))
lift : {b₁ b₂ : B} {v : BV b₁} → (c : b₁ ⟷ b₂) →
DPAIR (v , (singleton v)) ⟷ DPAIR (eval c v , (singleton (eval c v)))
eval : {b₁ b₂ : B} → b₁ ⟷ b₂ → BV b₁ → BV b₂
eval swap₊ (LEFT v) = RIGHT v
eval swap₊ (RIGHT v) = LEFT v
eval (η {b₁} {v}) UNIT = NCPROD b₁ v
eval assocl₊ (LEFT v) = LEFT (LEFT v)
eval assocl₊ (RIGHT (LEFT v)) = LEFT (RIGHT v)
eval assocl₊ (RIGHT (RIGHT v)) = RIGHT v
eval assocr₊ (LEFT (LEFT v)) = LEFT v
eval assocr₊ (LEFT (RIGHT v)) = RIGHT (LEFT v)
eval assocr₊ (RIGHT v) = RIGHT (RIGHT v)
eval unite⋆ (PAIR UNIT v) = v
eval uniti⋆ v = PAIR UNIT v
eval (ε {b₁} {v}) (NCPROD .b₁ .v) = UNIT
eval id⟷ v = v
eval (c₁ ◎ c₂) v = eval c₂ (eval c₁ v)
eval (c₁ ⊕ c₂) (LEFT v) = LEFT (eval c₁ v)
eval (c₁ ⊕ c₂) (RIGHT v) = RIGHT (eval c₂ v)
eval (c₁ ⊗ c₂) (PAIR v₁ v₂) = PAIR (eval c₁ v₁) (eval c₂ v₂)
eval (lift {b₁} {b₂} {v} c) (NCPROD .b₁ .v) = NCPROD b₂ (eval c v)
-- name : {b₁ b₂ : B} {v : BV b₁} → (b₁ ⟷ b₂) → (ONE ⟷ DPAIR (v , singleton v))
-- name {b₁} {b₂} {v} c = η {b₁} {v} ◎ (lift (id⟷ ⊗ c))
--}
| {
"alphanum_fraction": 0.4876670092,
"avg_line_length": 34.5955555556,
"ext": "agda",
"hexsha": "853fc6de7a10812e91492d3cc6a4faaacdbad1fc",
"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": "agda/PiFrac.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "agda/PiFrac.agda",
"max_line_length": 80,
"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": "agda/PiFrac.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 3886,
"size": 7784
} |
T-to-≡ : ∀ {x} → T x → x ≡ true
T-to-≡ {true} tx = refl
≡-to-T : ∀ {x} → x ≡ true → T x
≡-to-T {true} x≡true = tt
≤-to-→ : ∀ {x y} → x 𝔹.≤ y → T x → T y
≤-to-→ {true} {true} x≤y _ = tt
→-to-≤ : ∀ {x y} → (T x → T y) → x 𝔹.≤ y
→-to-≤ {false} {false} Tx→Ty = b≤b
→-to-≤ {false} {true} Tx→Ty = f≤t
→-to-≤ {true} {false} Tx→Ty = ⊥-elim (Tx→Ty tt)
→-to-≤ {true} {true} Tx→Ty = b≤b
toFun : (x : ℕ → Bool) → (∀ i → x (suc i) 𝔹.≤ x i) →
∀ i → T (x (suc i)) → T (x i)
toFun x p i = ≤-to-→ (p i)
fromFun : (x : ℕ → Bool) → (∀ i → T (x (suc i)) → T (x i)) →
∀ i → x (suc i) 𝔹.≤ x i
fromFun _ f i = →-to-≤ (f i)
Dec-T : ∀ b → Dec (T b)
Dec-T false = no id
Dec-T true = yes tt
private
_≈Decidable_ : ∀ {P Q : ℕ → Set} (P? : U.Decidable P) (Q? : U.Decidable Q) → Set
P? ≈Decidable Q? = ∀ x → isYes (P? x) ≡ isYes (Q? x)
make≈Decidable : {P Q : ℕ → Set} → (∀ x → P x → Q x) → (∀ x → Q x → P x) →
(P? : U.Decidable P) (Q? : U.Decidable Q) → P? ≈Decidable Q?
make≈Decidable P→Q Q→P P? Q? x with P? x | Q? x
... | yes p | yes q = refl
... | yes p | no ¬q = contradiction (P→Q _ p) ¬q
... | no ¬p | yes q = contradiction (Q→P _ q) ¬p
... | no ¬p | no ¬q = refl
ℕ≤-all-dec′ : ∀ {P : ℕ → Set} → U.Decidable P → U.Decidable (λ n → ∀ i → i ≤ n → P i)
ℕ≤-all-dec′ P? = DecU⇒decidable $ ℕ≤-all-dec (decidable⇒DecU P?)
idem-map-Pred : (α : ℕ → Bool) → ℕ → Set
idem-map-Pred α n = ∀ i → i ≤ n → T (α i)
idem-map-Pred? : (α : ℕ → Bool) → U.Decidable (idem-map-Pred α)
idem-map-Pred? α = ℕ≤-all-dec′ (λ i → Dec-T (α i))
idem-map : (ℕ → Bool) → (ℕ → Bool)
idem-map α n = isYes (idem-map-Pred? α n)
idem-map-idem : ∀ α → idem-map (idem-map α) ≈ idem-map α
idem-map-idem α =
make≈Decidable
(λ n x i i≤n → {! !})
{! !}
(idem-map-Pred? (λ n → isYes (idem-map-Pred? α n)))
(idem-map-Pred? α)
-- x : idem-map-Pred (λ n₁ → isYes (idem-map-Pred? α n₁)) n
-- x : ∀ i → i ≤ n → T (isYes (idem-map-Pred? α i))
-- True toWitness
-- hyp : idem-map-Pred α i
-- hyp : ∀ i →
-- Goal : ∀ i → i ≤ n → T (α i)
-- idem-map α n
-- isYes (ℕ-all-dec′ (λ i → Dec-⊤ (α i)) n)
idem-map-image : ∀ α → let x = idem-map α in (∀ i → T (x (suc i)) → T (x i))
idem-map-image α n ppp with ℕ≤-all-dec′ (λ i → Dec-T (α i)) n
... | yes _ = {! !}
... | no _ = {! !}
| {
"alphanum_fraction": 0.4670995671,
"avg_line_length": 29.6153846154,
"ext": "agda",
"hexsha": "d778a6741481d52d23650fc8db27d4c4a392de40",
"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": "Constructive/Omniscience/Misc.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": "Constructive/Omniscience/Misc.agda",
"max_line_length": 87,
"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": "Constructive/Omniscience/Misc.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": 1121,
"size": 2310
} |
{-# OPTIONS --universe-polymorphism #-}
module Issue354 where
------------------------------------------------------------------------
-- Preliminaries
postulate
Level : Set
zero : Level
suc : (i : Level) → Level
_⊔_ : Level → Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
_≗_ : ∀ {a b} {A : Set a} {B : Set b} (f g : A → B) → Set (a ⊔ b)
f ≗ g = ∀ x → f x ≡ g x
------------------------------------------------------------------------
-- Example
postulate
a : Level
A : Set a
P : A → Set
x : A
f : ∀ {a} {A : Set a} → A → A
g : A → A
lemma : f ≗ g
p : f x ≡ g x
p with f x | lemma x
... | .(g x) | refl = refl
-- The code above fails to type check, even though lemma x has the
-- type f x ≡ g x. However, if A is given the type Set zero, then the
-- code checks.
-- Excerpt from agda -vtc.with:100 --show-implicit Bug.agda:
--
-- checkWithFunction
-- delta1 =
-- delta2 =
-- gamma =
-- as = [A, _≡_ {a} {A} (f {a ⊔ a} {A} x) (g x)]
-- vs = [f {a} {A} x, lemma x]
-- b = _≡_ {a} {A} (f {a} {A} x) (g x)
-- qs = []
-- perm = ->
--
-- Notice the occurrence of a ⊔ a.
| {
"alphanum_fraction": 0.4317673378,
"avg_line_length": 22.7288135593,
"ext": "agda",
"hexsha": "1d2eb63e9e1ce07c28ca1d74a0564dd3f0d1aa3c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/succeed/Issue354.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/succeed/Issue354.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/Issue354.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": 475,
"size": 1341
} |
module Optics.Iso where
open import Agda.Primitive using (Level; _⊔_; lsuc)
open import Function.Equality using (Π)
open import Function.Inverse using (_↔_; inverse; Inverse; _InverseOf_)
open import Relation.Binary.PropositionalEquality using (_≡_; →-to-⟶; refl)
open import Category.Functor.Arr
open import Category.Functor.Const
open import Category.Profunctor
open import Category.Profunctor.Star
open import Category.Profunctor.Joker
open import Optics
Iso : ∀ {l} (S T A B : Set l) → Set (lsuc l)
Iso = Optic ProfunctorImp
module Iso {l} {S T A B : Set l} (iso : Iso S T A B) where
get : S → A
get = getOptic S T A B (starProfunctor constFunctor) iso
put : B → T
put = putOptic S T A B (jokerProfunctor arrFunctor) iso
record LawfulIsoImp {l} {S A : Set l} (iso' : Iso S S A A) : Set (lsuc l) where
open Iso iso'
field
putget : ∀ (s : S) → put (get s) ≡ s
getput : ∀ (a : A) → get (put a) ≡ a
module LawfulIso {l} {S A : Set l} {iso' : Iso S S A A} (isLawful : LawfulIsoImp iso') where
open Iso iso' public
iso : Iso S S A A
iso = iso'
open LawfulIsoImp isLawful public
isoIso : ∀ {S A : Set} {iso : Iso S S A A} → (i : LawfulIsoImp iso) → S ↔ A
isoIso {S} {A} i = inverse to from from∘to to∘from
where
open LawfulIso i
to = get
from = put
from∘to : (s : S) → from (to s) ≡ s
from∘to = putget
to∘from : (a : A) → to (from a) ≡ a
to∘from = getput
invLawfulIso : ∀ {l} {S A : Set l} {get : S → A} {put : A → S} → (→-to-⟶ get) InverseOf (→-to-⟶ put) ↔ LawfulIsoImp (λ p → Profunctor.dimap p get put)
invLawfulIso = inverse invertibleIsLawful lawfulIsInvertible (λ _ → refl) (λ _ → refl)
where
invertibleIsLawful : ∀ {l} {S A : Set l} {get : S → A} {put : A → S} → (→-to-⟶ get) InverseOf (→-to-⟶ put) → LawfulIsoImp (λ p → Profunctor.dimap p get put)
invertibleIsLawful i = record
{ putget = right-inverse-of
; getput = left-inverse-of
} where
open _InverseOf_ i
lawfulIsInvertible : ∀ {l} {S A : Set l} {get : S → A} {put : A → S} → LawfulIsoImp (λ p → Profunctor.dimap p get put) → (→-to-⟶ get) InverseOf (→-to-⟶ put)
lawfulIsInvertible isLawful = record
{ left-inverse-of = getput
; right-inverse-of = putget
}
where open LawfulIso isLawful
| {
"alphanum_fraction": 0.6297592998,
"avg_line_length": 36.2698412698,
"ext": "agda",
"hexsha": "e766c0cff58da1575b38547697049d47a4f1ad59",
"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": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crisoagf/agda-optics",
"max_forks_repo_path": "src/Optics/Iso.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"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": "crisoagf/agda-optics",
"max_issues_repo_path": "src/Optics/Iso.agda",
"max_line_length": 160,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crisoagf/agda-optics",
"max_stars_repo_path": "src/Optics/Iso.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 851,
"size": 2285
} |
----------------------------------------------------------------
-- This file contains the definition of natural isomorphisms. --
----------------------------------------------------------------
module Category.NatIsomorphism where
open import Category.NatTrans public
open import Category.Iso public
record NatIso {l₁ l₂ : Level}
{ℂ₁ : Cat {l₁}}
{ℂ₂ : Cat {l₂}}
(F G : Functor ℂ₁ ℂ₂) : Set (l₁ ⊔ l₂) where
field
-- The natural transformation.
natt : NatTrans F G
-- Each component of (η natt) is an iso.
η-iso-ax : ∀{A : Obj ℂ₁} → Iso {l₂}{ℂ₂}{A = omap F A}{omap G A} (η natt A)
open NatIso public
| {
"alphanum_fraction": 0.4872944694,
"avg_line_length": 31.8571428571,
"ext": "agda",
"hexsha": "9179e2536ee5406a42782420a3ea6900191eca90",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "setoid-cats/Category/NatIsomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "setoid-cats/Category/NatIsomorphism.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "setoid-cats/Category/NatIsomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 183,
"size": 669
} |
{-# OPTIONS --cubical-compatible #-}
module Common.Prelude where
import Common.Level
open import Agda.Builtin.Unit public
open import Common.Bool public
open import Common.Char public
open import Common.Float public
open import Common.IO public
open import Common.List public
open import Common.Maybe public
open import Common.Nat public
open import Common.String public
open import Common.Unit public
data ⊥ : Set where
| {
"alphanum_fraction": 0.7725225225,
"avg_line_length": 23.3684210526,
"ext": "agda",
"hexsha": "c713b5f13b23e7c4b28948231beff762a2d2524f",
"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/Prelude.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/Prelude.agda",
"max_line_length": 36,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Common/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 98,
"size": 444
} |
module NonEmptyList where
infixr 5 _∷_
open import Data.Nat
data NList (A : Set) : Set where
[_] : A → NList A
_∷_ : A → NList A → NList A
map : {A B : Set} → (f : A → B) → NList A → NList B
map f [ x ] = [ f x ]
map f (x ∷ l) = f x ∷ map f l
length : ∀ {A} → NList A → ℕ
length [ _ ] = 1
length (_ ∷ l) = suc (length l)
| {
"alphanum_fraction": 0.5333333333,
"avg_line_length": 18.3333333333,
"ext": "agda",
"hexsha": "69d286dae9267263e7bc72ffce33419efe828371",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "TypeTheory/FibDataTypes/NonEmptyList.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "TypeTheory/FibDataTypes/NonEmptyList.agda",
"max_line_length": 51,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "TypeTheory/FibDataTypes/NonEmptyList.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 144,
"size": 330
} |
{-# OPTIONS --without-K --safe #-}
-- Bundled version of Monoidal Category
module Categories.Category.Monoidal.Bundle where
open import Level
open import Categories.Category.Core using (Category)
open import Categories.Category.Monoidal.Core using (Monoidal)
open import Categories.Category.Monoidal.Braided using (Braided)
open import Categories.Category.Monoidal.Symmetric using (Symmetric)
record MonoidalCategory o ℓ e : Set (suc (o ⊔ ℓ ⊔ e)) where
field
U : Category o ℓ e
monoidal : Monoidal U
open Category U public
open Monoidal monoidal public
record BraidedMonoidalCategory o ℓ e : Set (suc (o ⊔ ℓ ⊔ e)) where
field
U : Category o ℓ e
monoidal : Monoidal U
braided : Braided monoidal
monoidalCategory : MonoidalCategory o ℓ e
monoidalCategory = record { U = U ; monoidal = monoidal }
open Category U public
open Braided braided public
record SymmetricMonoidalCategory o ℓ e : Set (suc (o ⊔ ℓ ⊔ e)) where
field
U : Category o ℓ e
monoidal : Monoidal U
symmetric : Symmetric monoidal
open Category U public
open Symmetric symmetric public
braidedMonoidalCategory : BraidedMonoidalCategory o ℓ e
braidedMonoidalCategory = record
{ U = U
; monoidal = monoidal
; braided = braided
}
open BraidedMonoidalCategory braidedMonoidalCategory public
using (monoidalCategory)
| {
"alphanum_fraction": 0.715,
"avg_line_length": 27.4509803922,
"ext": "agda",
"hexsha": "4ed249bb467a7acc8a9f255fd53bf0938eb760f5",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Bundle.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Bundle.agda",
"max_line_length": 68,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Bundle.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 384,
"size": 1400
} |
module Numeric.Nat.GCD where
open import Prelude
open import Control.WellFounded
open import Numeric.Nat.Properties
open import Numeric.Nat.DivMod
open import Numeric.Nat.Divide
open import Numeric.Nat.Divide.Properties
open import Tactic.Nat
--- GCD ---
record IsGCD (d a b : Nat) : Set where
no-eta-equality
constructor is-gcd
field d|a : d Divides a
d|b : d Divides b
g : ∀ k → k Divides a → k Divides b → k Divides d
record GCD (a b : Nat) : Set where
no-eta-equality
constructor gcd-res
field d : Nat
isGCD : IsGCD d a b
open GCD public using () renaming (d to get-gcd)
-- Projections --
is-gcd-factor₁ : ∀ {a b d} → IsGCD d a b → Nat
is-gcd-factor₁ g = get-factor (IsGCD.d|a g)
is-gcd-factor₂ : ∀ {a b d} → IsGCD d a b → Nat
is-gcd-factor₂ g = get-factor (IsGCD.d|b g)
gcd-factor₁ : ∀ {a b} → GCD a b → Nat
gcd-factor₁ g = is-gcd-factor₁ (GCD.isGCD g)
gcd-factor₂ : ∀ {a b} → GCD a b → Nat
gcd-factor₂ g = is-gcd-factor₂ (GCD.isGCD g)
-- Euclid's algorithm --
isGCD-step : ∀ {d r₀ r₁ r₂} q → q * r₁ + r₂ ≡ r₀ → IsGCD d r₁ r₂ → IsGCD d r₀ r₁
isGCD-step q refl (is-gcd d|r₁ d|r₂ g) =
is-gcd (divides-add (divides-mul-r q d|r₁) d|r₂)
d|r₁ (λ k k|r₀ k|r₁ → g k k|r₁ (divides-sub-l k|r₀ (divides-mul-r q k|r₁)))
private
gcd-step : ∀ {a b} q {r} → q * suc b + r ≡ a → GCD (suc b) r → GCD a (suc b)
gcd-step q eq (gcd-res d p) = gcd-res d (isGCD-step q eq p)
gcd-cert-acc : ∀ a b → Acc _<_ b → GCD a b
gcd-cert-acc a zero _ = gcd-res a (is-gcd (factor 1 auto) (factor! 0) (λ k k|a _ → k|a))
gcd-cert-acc a (suc b) (acc wf) =
case a divmod suc b of λ
{ (qr q r lt eq) → gcd-step q eq (gcd-cert-acc (suc b) r (wf r lt)) }
eraseIsGCD : ∀ {d a b} → IsGCD d a b → IsGCD d a b
eraseIsGCD (is-gcd d|a d|b g) =
is-gcd (fast-divides d|a) (fast-divides d|b)
λ k k|a k|b → fast-divides (g k k|a k|b)
eraseGCD : ∀ {a b} → GCD a b → GCD a b
eraseGCD (gcd-res d p) = gcd-res d (eraseIsGCD p)
gcd : ∀ a b → GCD a b
gcd 0 b = gcd-res b (is-gcd (factor! 0) divides-refl (λ _ _ k|b → k|b))
gcd 1 b = gcd-res 1 (is-gcd divides-refl (factor b auto) (λ _ k|1 _ → k|1))
gcd a b = eraseGCD (gcd-cert-acc a b (wfNat b))
gcd! : Nat → Nat → Nat
gcd! a b = get-gcd (gcd a b)
Coprime : Nat → Nat → Set
Coprime a b = gcd! a b ≡ 1
| {
"alphanum_fraction": 0.6059947871,
"avg_line_length": 29.5128205128,
"ext": "agda",
"hexsha": "d749bab4ef2352be2baa9575419135d09ef61461",
"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": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Numeric/Nat/GCD.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"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": "lclem/agda-prelude",
"max_issues_repo_path": "src/Numeric/Nat/GCD.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Numeric/Nat/GCD.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 933,
"size": 2302
} |
primitive
ID : Set → Set
ID A = A
| {
"alphanum_fraction": 0.5833333333,
"avg_line_length": 6,
"ext": "agda",
"hexsha": "2761693f28b0f78e26deff67fd9898de6b104184",
"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/emptyprimitive.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/emptyprimitive.agda",
"max_line_length": 14,
"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/emptyprimitive.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": 13,
"size": 36
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
module lib.types.Unit where
⊤ = Unit
tt = unit
abstract
-- Unit is contractible
Unit-is-contr : is-contr Unit
Unit-is-contr = (unit , λ y → idp)
Unit-has-level : {n : ℕ₋₂} → has-level n Unit
Unit-has-level = contr-has-level Unit-is-contr
-- [Unit-has-level#instance] produces unsolved metas
Unit-has-level-S#instance : {n : ℕ₋₂} → has-level (S n) Unit
Unit-has-level-S#instance = contr-has-level Unit-is-contr
Unit-is-prop : is-prop Unit
Unit-is-prop = Unit-has-level
Unit-is-set : is-set Unit
Unit-is-set = Unit-has-level
Unit-level = Unit-is-contr
⊤-is-contr = Unit-is-contr
⊤-level = Unit-is-contr
⊤-has-level = Unit-has-level
⊤-is-prop = Unit-is-prop
⊤-is-set = Unit-is-set
| {
"alphanum_fraction": 0.6666666667,
"avg_line_length": 22.4117647059,
"ext": "agda",
"hexsha": "d0fa9c0d6a0fe41889b9ace1dba45baaa745a396",
"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": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sattlerc/HoTT-Agda",
"max_forks_repo_path": "lib/types/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"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": "sattlerc/HoTT-Agda",
"max_issues_repo_path": "lib/types/Unit.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sattlerc/HoTT-Agda",
"max_stars_repo_path": "lib/types/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 252,
"size": 762
} |
{-# OPTIONS --without-K #-}
-- Drop-in replacement for the module [Base].
module BaseOver where
-- We hide [apd] and [Σ-eq] because their type is not correct, we want to use
-- dependent paths instead
open import Base public hiding (apd; Σ-eq)
-- Notion of path over a path
path-over : ∀ {i j} {A : Set i} (B : A → Set j)
{x y : A} (p : x == y) (u : B x) (v : B y) → Set j
path-over B refl u v = (u == v)
syntax path-over B p u v =
u == v [ B ↓ p ]
-- New apd
apd : ∀ {i j} {A : Set i} {B : A → Set j} (f : (a : A) → B a) {x y : A}
→ (p : x == y) → f x == f y [ B ↓ p ]
apd f refl = refl
-- Σ-types are used to simulate telescopes and to be able to only use the
-- notion of path over a single path
-- Intro for paths in a Σ
Σ-eq : ∀ {i j} {A : Set i} {B : A → Set j} {x y : A} (p : x == y)
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ (x , u) == (y , v)
Σ-eq refl refl = refl
uncurryi : ∀ {i j k} {A : Set i} {B : A → Set j} {C : ∀ x → B x → Set k}
→ (∀ {x} y → C x y) → (∀ s → C (π₁ s) (π₂ s))
uncurryi f (x , y) = f y
apdd : ∀ {i j k} {A : Set i} {B : A → Set j} {C : (a : A) → B a → Set k}
(g : {a : A} → Π (B a) (C a)) {x y : A} (p : x == y)
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ g u == g v [ uncurry C ↓ Σ-eq p q ]
apdd g p q = apd (uncurryi g) (Σ-eq p q)
-- Dependent paths in a constant fibration
module _ {i j} {A : Set i} {B : Set j} where
↓-cst-in : {x y : A} (p : x == y) {u v : B}
→ u == v
→ u == v [ (λ _ → B) ↓ p ]
↓-cst-in refl q = q
↓-cst-out : {x y : A} {p : x == y} {u v : B}
→ u == v [ (λ _ → B) ↓ p ]
→ u == v
↓-cst-out {p = refl} q = q
↓-cst-β : {x y : A} (p : x == y) {u v : B} (q : u == v)
→ (↓-cst-out (↓-cst-in p q) == q)
↓-cst-β refl q = refl
-- -- ap can be defined via apd, not sure whether it’s a good idea or not
-- ap : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) {x y : A} (p : x == y)
-- → f x == f y
-- ap f p = ↓-cst-out (apd f p)
-- Dependent paths in a Π-type
module _ {i j k} {A : Set i} {B : A → Set j} {C : (a : A) → B a → Set k} where
↓-Π-in : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ Σ-eq p q ])
→ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])
↓-Π-in {p = refl} f = funext (λ x → f (refl {a = x}))
↓-Π-out : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ Σ-eq p q ])
↓-Π-out {p = refl} q refl = happly q _
↓-Π-β : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ (f : {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ Σ-eq p q ])
→ {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ ↓-Π-out (↓-Π-in f) q == f q
↓-Π-β {p = refl} f refl = happly (happly-funext (λ x → f (refl {a = x}))) _
-- Dependent paths in a Π-type where the codomain is not dependent on anything
module _ {i j k} {A : Set i} {B : A → Set j} {C : Set k} {x x' : A} {p : x == x'}
{u : B x → C} {u' : B x' → C} where
↓-app→cst-in :
({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t')
→ (u == u' [ (λ x → B x → C) ↓ p ])
↓-app→cst-in f = ↓-Π-in (λ q → ↓-cst-in (Σ-eq p q) (f q))
↓-app→cst-out :
(u == u' [ (λ x → B x → C) ↓ p ])
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t')
↓-app→cst-out r q = ↓-cst-out (↓-Π-out r q)
↓-app→cst-β :
(f : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t'))
→ {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ ↓-app→cst-out (↓-app→cst-in f) q == f q
↓-app→cst-β f q =
↓-app→cst-out (↓-app→cst-in f) q
≡⟨ refl ⟩
↓-cst-out (↓-Π-out (↓-Π-in (λ qq → ↓-cst-in (Σ-eq p qq) (f qq))) q)
≡⟨ ↓-Π-β (λ qq → ↓-cst-in (Σ-eq p qq) (f qq)) q |in-ctx ↓-cst-out ⟩
↓-cst-out (↓-cst-in (Σ-eq p q) (f q))
≡⟨ ↓-cst-β (Σ-eq p q) (f q) ⟩
f q ∎
-- Dependent paths in a Π-type where the domain is constant
module _ {i j k} {A : Set i} {B : Set j} {C : A → B → Set k}
{x x' : A} {p : x == x'}
{u : (b : B) → C x b} {u' : (b : B) → C x' b} where
postulate
↓-cst→app-in :
({t t' : B} (q : t == t')
→ u t == u' t' [ uncurry C ↓ Σ-eq p (↓-cst-in p q) ])
→ (u == u' [ (λ x → (b : B) → C x b) ↓ p ])
-- ↓-cst→app-in f = ↓-Π-in (λ q → {!f (↓-cst-out q)!})
postulate
↓-cst→app-out :
(u == u' [ (λ x → (b : B) → C x b) ↓ p ])
→ ({t t' : B} (q : t == t')
→ u t == u' t' [ uncurry C ↓ Σ-eq p (↓-cst-in p q) ])
split-ap2 : ∀ {i j k} {A : Set i} {B : A → Set j} {C : Set k} (f : Σ A B → C)
{x y : A} (p : x == y)
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ ap f (Σ-eq p q) == ↓-app→cst-out (apd (curry f) p) q
split-ap2 f refl refl = refl
↓-app='cst-in : ∀ {i j} {A : Set i} {B : Set j} {f : A → B} {b : B}
{x y : A} {p : x == y} {u : f x == b} {v : f y == b}
→ u == (ap f p ∘' v)
→ (u == v [ (λ x → f x == b) ↓ p ])
↓-app='cst-in {p = refl} q = q ∘ refl-left-unit _
↓-app='cst-out : ∀ {i j} {A : Set i} {B : Set j} {f : A → B} {b : B}
{x y : A} {p : x == y} {u : f x == b} {v : f y == b}
→ (u == v [ (λ x → f x == b) ↓ p ])
→ u == (ap f p ∘' v)
↓-app='cst-out {p = refl} refl = ! (refl-left-unit _)
↓-cst='app-in : ∀ {i j} {A : Set i} {B : Set j} {f : A → B} {b : B}
{x y : A} {p : x == y} {u : b == f x} {v : b == f y}
→ (u ∘' ap f p) == v
→ (u == v [ (λ x → b == f x) ↓ p ])
↓-cst='app-in {p = refl} refl = refl
↓-cst='app-out : ∀ {i j} {A : Set i} {B : Set j} {f : A → B} {b : B}
{x y : A} {p : x == y} {u : b == f x} {v : b == f y}
→ (u == v [ (λ x → b == f x) ↓ p ])
→ (u ∘' ap f p) == v
↓-cst='app-out {p = refl} refl = refl
↓-='-in : ∀ {i j} {A : Set i} {B : Set j} {f g : A → B}
{x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
→ (u ∘ ap g p) == (ap f p ∘' v)
→ (u == v [ (λ x → f x == g x) ↓ p ])
↓-='-in {p = refl} q = ! (refl-right-unit _) ∘ (q ∘ refl-left-unit _)
-- Dependent vs nondependent whiskering
-- This definitional behaviour make [↓-=-in] slightly more complicated to prove
-- but [↓-=-in] is often used in the case where [u] and [v] are [refl]
_▹_ : ∀ {i j} {A : Set i} {B : A → Set j} {x y : A} {u : B x}
{v w : B y} {p : x == y}
→ (u == v [ B ↓ p ]) → v == w
→ (u == w [ B ↓ p ])
_▹_ {p = refl} q refl = q
refl▹ : ∀ {i j} {A : Set i} {B : A → Set j} {x : A}
{v w : B x} (q : v == w)
→ _▹_ {B = B} {p = refl} refl q == q
refl▹ refl = refl
_◃_ : ∀ {i j} {A : Set i} {B : A → Set j} {x y : A} {u v : B x}
{w : B y} {p : x == y}
→ (u == v → (v == w [ B ↓ p ])
→ (u == w [ B ↓ p ]))
_◃_ {p = refl} refl q = q
◃refl : ∀ {i j} {A : Set i} {B : A → Set j} {x : A}
{v w : B x} (q : v == w)
→ _◃_ {B = B} {p = refl} q refl == q
◃refl refl = refl
↓-=-in : ∀ {i j} {A : Set i} {B : A → Set j} {f g : Π A B}
{x y : A} {p : x == y} {u : g x == f x} {v : g y == f y}
→ (u ◃ apd f p) == (apd g p ▹ v)
→ (u == v [ (λ x → g x == f x) ↓ p ])
↓-=-in {B = B} {p = refl} {u} {v} q =
! (◃refl {B = B} u) ∘ (q ∘ refl▹ {B = B} v)
postulate
↓-=-out : ∀ {i j} {A : Set i} {B : A → Set j} {f g : Π A B}
{x y : A} {p : x == y} {u : g x == f x} {v : g y == f y}
→ (u == v [ (λ x → g x == f x) ↓ p ])
→ (u ◃ apd f p) == (apd g p ▹ v)
--↓-=-out {B = B} {p = refl} refl = {!!}
{- Not used yet
apdd-cst : ∀ {i j k} {A : Set i} {B : Set j} {C : A → B → Set k}
(g : (a : A) → Π B (C a)) {x y : A} (p : x ≡ y)
{u v : B} (q : u ≡ v) {r : u ≡[ (λ _ → B) ↓ p ] v} (α : ↓-cst-in p q ≡ r)
→ apdd (λ {a} b → g a b) p r ≡ apd (uncurry g) (Σ-eq p r)
apdd-cst g refl refl refl = refl
-}
-- This one seems a bit weird
↓-apd-out : ∀ {i j k} {A : Set i} {B : A → Set j} (C : (a : A) → B a → Set k)
(f : Π A B) {x y : A} (p : x == y)
{u : C x (f x)} {v : C y (f y)}
→ u == v [ uncurry C ↓ Σ-eq p (apd f p) ]
→ u == v [ (λ z → C z (f z)) ↓ p ]
↓-apd-out C f refl refl = refl
{-
-- Dependent paths over [ap f p]
module _ {i j k} {A : Set i} {B : Set j} (C : B → Set k) (f : A → B) where
↓-ap-in : {x y : A} {p : x ≡ y} {u : C (f x)} {v : C (f y)}
→ u ≡[ C ◯ f ↓ p ] v
→ u ≡[ C ↓ ap f p ] v
↓-ap-in {p = refl} refl = refl
↓-ap-out : {x y : A} (p : x ≡ y) {u : C (f x)} {v : C (f y)}
→ u ≡[ C ↓ ap f p ] v
→ u ≡[ C ◯ f ↓ p ] v
↓-ap-out refl refl = refl
-- ↓-ap-β
ap-, : ∀ {i j k} {A : Set i} {B : Set j} {C : B → Set k}
(f : A → B) (g : (a : A) → C (f a)) {x y : A} (p : x ≡ y)
→ ap (λ x → _,_ {P = C} (f x) (g x)) p
≡ Σ-eq (ap f p) (↓-ap-in C f (apd g p))
ap-, f g refl = refl
-}
-- Special case of [ap-,]
ap-cst,id : ∀ {i j} {A : Set i} (B : A → Set j)
{a : A} {x y : B a} (p : x == y)
→ ap (λ x → _,_ {P = B} a x) p == Σ-eq refl p
ap-cst,id B refl = refl
-- apd-nd : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) {x y : A}
-- → (p : x ≡ y) → apd f p ≡ ↓-cst-in p (ap f p)
-- apd-nd f refl = refl
apd-◯ : ∀ {i j k} {A : Set i} {B : A → Set j} {C : (a : A) → B a → Set k}
(f : Π A B) (g : {a : A} → Π (B a) (C a)) {x y : A} (p : x == y)
→ apd (g ◯ f) p == ↓-apd-out C f p (apdd g p (apd f p))
apd-◯ f g refl = refl
{- Not used yet
-- apd-apd : ∀ {i j k} {A : Set i} {B : A → Set j} {C : (a : A) → B a → Set k}
-- (g : (u : Σ A B) → C (π₁ u) (π₂ u)) (f : Π A B) {x y : A} (p : x ≡ y)
-- → apd g (Σ-eq p (apd f p)) ≡ {!↓-ap-in!}
-- apd-apd = {!!}
apd-π₁-β : ∀ {i j} {A : Set i} {B : A → Set j} {x x' : A} (p : x ≡ x')
{y : B x} {y' : B x'} (q : y ≡[ B ↓ p ] y')
→ ap π₁ (Σ-eq p q) ≡ p
apd-π₁-β refl refl = refl
apd-π₂-β : ∀ {i j} {A : Set i} {B : A → Set j} {x x' : A} (p : x ≡ x')
{y : B x} {y' : B x'} (q : y ≡[ B ↓ p ] y')
→ apd π₂ (Σ-eq p q) ≡ ↓-ap-out B π₁ (Σ-eq p q)
(transport (λ p → y ≡[ B ↓ p ] y') (! (apd-π₁-β p q)) q)
apd-π₂-β refl refl = refl
-}
-- Dependent path in a type of the form [λ x → g (f x) ≡ x]
module _ {i j} {A : Set i} {B : Set j} (f : A → B) (g : B → A) where
↓-◯=id-in : {x y : A} {p : x == y} {u : g (f x) == x} {v : g (f y) == y}
→ ((ap g (ap f p) ∘' v) == (u ∘ p))
→ (u == v [ (λ x → g (f x) == x) ↓ p ])
↓-◯=id-in {p = refl} q = ! (refl-right-unit _) ∘ (! q ∘ refl-left-unit _)
-- WIP, derive it from more primitive principles
-- ↓-◯≡id-in f g {p = p} {u} {v} q =
-- ↓-≡-in (u ◃ apd (λ x → g (f x)) p ≡⟨ apd-◯ f g p |in-ctx (λ t → u ◃ t) ⟩
-- u ◃ ↓-apd-out _ f p (apdd g p (apd f p)) ≡⟨ apdd-cst (λ _ b → g b) p (ap f p) (! (apd-nd f p)) |in-ctx (λ t → u ◃ ↓-apd-out _ f p t) ⟩
-- u ◃ ↓-apd-out _ f p (apd (λ t → g (π₂ t)) (Σ-eq p (apd f p))) ≡⟨ apd-◯ π₂ g (Σ-eq p (apd f p)) |in-ctx (λ t → u ◃ ↓-apd-out _ f p t) ⟩
-- u ◃ ↓-apd-out _ f p (↓-apd-out _ π₂ (Σ-eq p (apd f p)) (apdd g (Σ-eq p (apd f p)) (apd π₂ (Σ-eq p (apd f p))))) ≡⟨ {!!} ⟩
-- apd (λ x → x) p ▹ v ∎)
ua-in : ∀ {i} {A B : Set i} → A ≃ B → A == B
ua-in = eq-to-path
ua-out : ∀ {i} {A B : Set i} → A == B → A ≃ B
ua-out = path-to-eq
ua-β : ∀ {i} {A B : Set i} (e : A ≃ B)
→ ua-out (ua-in e) == e
ua-β e = eq-to-path-right-inverse e
-- These lemmas do not really look computational, but they are only used in the
-- [↓-pp] lemmas which do look computational.
to-transp-in : ∀ {i j} {A : Set i} (B : A → Set j)
{a a' : A} (p : a == a')
{u : B a} {v : B a'}
→ (π₁ (ua-out (ap B p)) u == v)
→ (u == v [ B ↓ p ])
to-transp-in B refl refl = refl
to-transp-out : ∀ {i j} {A : Set i} {B : A → Set j}
{a a' : A} {p : a == a'}
{u : B a} {v : B a'}
→ (u == v [ B ↓ p ])
→ (π₁ (ua-out (ap B p)) u == v)
to-transp-out {p = refl} refl = refl
to-transp-β : ∀ {i j} {A : Set i} (B : A → Set j)
{a a' : A} (p : a == a')
{u : B a} {v : B a'}
(q : π₁ (ua-out (ap B p)) u == v)
→ to-transp-out (to-transp-in B p q) == q
to-transp-β B refl refl = refl
-- Stuff that do not belong here
ap-∘' : ∀ {i j} {A : Set i} {B : Set j} (f : A → B)
{x y z : A} (p : x == y) (q : y == z)
→ ap f (p ∘' q) == (ap f p ∘' ap f q)
ap-∘' f refl refl = refl
-- Dependent concatenation'
_∘'dep_ : ∀ {i j} {A : Set i} {B : A → Set j}
{x y z : A} {p : x == y} {p' : y == z}
{u : B x} {v : B y} {w : B z}
→ (u == v [ B ↓ p ]
→ v == w [ B ↓ p' ]
→ u == w [ B ↓ (p ∘' p') ])
_∘'dep_ {p' = refl} q refl = q
-- Implementation of [_∘'_] on Σ
Σ-∘' : ∀ {i j} {A : Set i} {B : A → Set j}
{x y z : A} {p : x == y} {p' : y == z}
{u : B x} {v : B y} {w : B z}
(q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ])
→ (Σ-eq p q ∘' Σ-eq p' r) == Σ-eq (p ∘' p') (q ∘'dep r)
Σ-∘' {p' = refl} q refl = refl
-- No idea what that is
to-transp-weird : ∀ {i j} {A : Set i} {B : A → Set j}
{u v : A} {d : B u} {d' d'' : B v} {p : u == v}
(q : d == d' [ B ↓ p ]) (r : π₁ (ua-out (ap B p)) d == d'')
→ (to-transp-in B p r ∘'dep (! r ∘ to-transp-out q)) == q
to-transp-weird {p = refl} refl refl = refl
_∘'2_ : ∀ {i j} {A : Set i} {B : A → Set j} {a b c : Π A B}
{x y : A} {p : x == y} {q : a x == b x} {q' : a y == b y}
{r : b x == c x} {r' : b y == c y}
→ (q == q' [ (λ z → a z == b z) ↓ p ])
→ (r == r' [ (λ z → b z == c z) ↓ p ])
→ (q ∘' r == q' ∘' r' [ (λ z → a z == c z) ↓ p ])
_∘'2_ {p = refl} refl refl = refl
stuff : ∀ {i j} {A : Set i} {B : Set j} {b : B} {c : A → B} {d : A → B}
(q : (a : A) → b == c a) (r : (a : A) → c a == d a) {a a' : A} (p : a == a')
→ apd (λ a → q a ∘' r a) p == ((apd q p) ∘'2 (apd r p))
stuff q r refl = refl
apd= : ∀ {i j} {A : Set i} {B : A → Set j} {f g : Π A B} (q : (x : A) → f x == g x) {x y : A} (p : x == y)
-- → (q x == q y [ (λ z → f z == g z) ↓ p ])
→ (apd f p ▹ q y) == (q x ◃ apd g p)
apd= q p = ! (↓-=-out (apd q p))
--apd= q refl =
| {
"alphanum_fraction": 0.3882026168,
"avg_line_length": 35.6276041667,
"ext": "agda",
"hexsha": "7134c901e5f7bd56456a1a2cbbd9dc657b8377df",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/BaseOver.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/BaseOver.agda",
"max_line_length": 145,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "old/BaseOver.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 6820,
"size": 13681
} |
module _ where
module M (_ : Set₁) where
record R₁ (A : Set) : Set₁ where
no-eta-equality
postulate
x : A
open R₁ ⦃ … ⦄ public
record R₂ (A : Set) : Set₁ where
field
instance
r₁ : R₁ A
open R₂ ⦃ … ⦄
open module MSet = M Set
postulate
A : Set
instance
postulate
m : R₁ A
a : A
a = x
| {
"alphanum_fraction": 0.55,
"avg_line_length": 10.9677419355,
"ext": "agda",
"hexsha": "f3678b5501676702131bc4a1f567ff9cef7030dd",
"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/Succeed/Issue2008a.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/Succeed/Issue2008a.agda",
"max_line_length": 34,
"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/Succeed/Issue2008a.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": 133,
"size": 340
} |
module Tactic.Reflection.Free where
open import Prelude
open import Builtin.Reflection
open import Tactic.Reflection.DeBruijn
VarSet = List Nat -- ordered
private
_∪_ : VarSet → VarSet → VarSet
[] ∪ ys = ys
xs ∪ [] = xs
(x ∷ xs) ∪ (y ∷ ys) with compare x y
... | (less _) = x ∷ (xs ∪ (y ∷ ys))
... | (equal _) = x ∷ (xs ∪ ys)
... | (greater _) = y ∷ ((x ∷ xs) ∪ ys)
∅ : VarSet
∅ = []
record FreeVars {a} (A : Set a) : Set a where
field freeVars : A → VarSet
open FreeVars {{...}} public
-- Instances --
private
freeTerm : Nat → Term → VarSet
freeSort : Nat → Sort → VarSet
freeArgTerm : Nat → Arg Term → VarSet
freeArgs : Nat → List (Arg Term) → VarSet
freeClauses : Nat → List Clause → VarSet
freeClause : Nat → Clause → VarSet
freeTerm n (var x args) = freeArgs n args ∪
(case compare (suc x) n of
λ { (greater (diff k _)) → [ k ]
; _ → ∅
})
freeTerm n (con c args) = freeArgs n args
freeTerm n (def f args) = freeArgs n args
freeTerm n (meta x args) = freeArgs n args
freeTerm n (lam _ (abs _ v)) = freeTerm (suc n) v
freeTerm n (pat-lam cs args) = freeClauses n cs ∪ freeArgs n args
freeTerm n (pi a (abs _ b)) = freeArgTerm n a ∪ freeTerm (suc n) b
freeTerm n (agda-sort s) = freeSort n s
freeTerm n (lit l) = ∅
freeTerm n unknown = ∅
freeSort n (set t) = freeTerm n t
freeSort _ (lit n) = ∅
freeSort _ unknown = ∅
freeArgTerm n (arg i x) = freeTerm n x
freeArgs n [] = ∅
freeArgs n (a ∷ as) = freeArgTerm n a ∪ freeArgs n as
freeClauses n [] = ∅
freeClauses n (c ∷ cs) = freeClause n c ∪ freeClauses n cs
freeClause n (clause ps b) = freeTerm (patternBindings ps + n) b
freeClause n (absurd-clause _) = ∅
instance
FreeTerm : FreeVars Term
freeVars {{FreeTerm}} = freeTerm 0
FreeSort : FreeVars Sort
freeVars {{FreeSort}} = freeSort 0
FreeArg : ∀ {A} {{_ : FreeVars A}} → FreeVars (Arg A)
freeVars {{FreeArg}} (arg _ x) = freeVars x
FreeList : ∀ {a} {A : Set a} {{_ : FreeVars A}} → FreeVars (List A)
freeVars {{FreeList}} = foldr (λ x → freeVars x ∪_) ∅
| {
"alphanum_fraction": 0.6019924099,
"avg_line_length": 27.0256410256,
"ext": "agda",
"hexsha": "17dd010d42f86246c8cb92968276ae064d4c3a43",
"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": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Tactic/Reflection/Free.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"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": "lclem/agda-prelude",
"max_issues_repo_path": "src/Tactic/Reflection/Free.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Tactic/Reflection/Free.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 772,
"size": 2108
} |
{-# OPTIONS --cubical-compatible --rewriting --confluence-check #-}
module _ where
{- Rewriting relation -}
postulate
_↦_ : ∀ {i} {A : Set i} → A → A → Set i
idr : ∀ {i} {A : Set i} {a : A} → a ↦ a
{-# BUILTIN REWRITE _↦_ #-}
{- Identity type -}
infixr 3 _==_
data _==_ {i} {A : Set i} (a : A) : A → Set i where
idp : a == a
ap : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) {x y : A}
→ (p : x == y) → f x == f y
ap f idp = idp
postulate
A : Set
C : A → Set
-- Definition of W
postulate
W : Set
c : A → W
module _ {l} {P : W → Set l} (c* : (a : A) → P (c a)) where
postulate
W-elim : (w : W) → P w
W-c-β : (a : A) → W-elim (c a) ↦ c* a
{-# REWRITE W-c-β #-}
-- Definition of P
P : W → Set
P = W-elim C
-- Definition of WT
postulate
WT : Set
cT : (a : A) (x : C a) → WT
-- Definition of TotP
record TotP : Set where
constructor _,_
field
fst : W
snd : P fst
-- Function from TotP to WT
from-curry : (x : W) (y : P x) → WT
from-curry = W-elim cT
from : TotP → WT
from (x , y) = from-curry x y
postulate
a : A
x y : C a
foo : (c a , x) == (c a , y)
bar : cT a x == cT a y
rew1 : ap from foo ↦ bar
{-# REWRITE rew1 #-}
-- The following has exactly the same type as [rew1], so [idr] should work
rew1' : ap from foo ↦ bar
rew1' = idr
| {
"alphanum_fraction": 0.5137614679,
"avg_line_length": 16.35,
"ext": "agda",
"hexsha": "05f68eea7e3843a00691a40e103bc9c3d4564f8e",
"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/Issue1724.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/Issue1724.agda",
"max_line_length": 74,
"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/Issue1724.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 543,
"size": 1308
} |
{-# OPTIONS --without-K --exact-split --safe #-}
module HoTT-UF-Agda where
open import Universes public
variable
𝓤 𝓥 𝓦 𝓣 : Universe
data 𝟙 : 𝓤₀ ̇ where
⋆ : 𝟙
𝟙-induction : (A : 𝟙 → 𝓤 ̇ ) → A ⋆ → (x : 𝟙) → A x
𝟙-induction A a ⋆ = a
𝟙-recursion : (B : 𝓤 ̇ ) → B → (𝟙 → B)
𝟙-recursion B b x = 𝟙-induction (λ _ → B) b x
!𝟙' : (X : 𝓤 ̇ ) → X → 𝟙
!𝟙' X x = ⋆
!𝟙 : {X : 𝓤 ̇ } → X → 𝟙
!𝟙 x = ⋆
data 𝟘 : 𝓤₀ ̇ where
𝟘-induction : (A : 𝟘 → 𝓤 ̇ ) → (x : 𝟘) → A x
𝟘-induction A ()
𝟘-recursion : (A : 𝓤 ̇ ) → 𝟘 → A
𝟘-recursion A a = 𝟘-induction (λ _ → A) a
!𝟘 : (A : 𝓤 ̇ ) → 𝟘 → A
!𝟘 = 𝟘-recursion
is-empty : 𝓤 ̇ → 𝓤 ̇
is-empty X = X → 𝟘
¬ : 𝓤 ̇ → 𝓤 ̇
¬ X = X → 𝟘
data ℕ : 𝓤₀ ̇ where
zero : ℕ
succ : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
ℕ-induction : (A : ℕ → 𝓤 ̇ )
→ A 0
→ ((n : ℕ) → A n → A (succ n))
→ (n : ℕ) → A n
ℕ-induction A a₀ f = h
where
h : (n : ℕ) → A n
h 0 = a₀
h (succ n) = f n (h n)
ℕ-recursion : (X : 𝓤 ̇ )
→ X
→ (ℕ → X → X)
→ ℕ → X
ℕ-recursion X = ℕ-induction (λ _ → X)
ℕ-iteration : (X : 𝓤 ̇ )
→ X
→ (X → X)
→ ℕ → X
ℕ-iteration X x f = ℕ-recursion X x (λ _ x → f x)
module Arithmetic where
_+_ _×_ : ℕ → ℕ → ℕ
x + 0 = x
x + succ y = succ (x + y)
x × 0 = 0
x × succ y = x + x × y
infixl 20 _+_
infixl 21 _×_
module Arithmetic' where
_+_ _×_ : ℕ → ℕ → ℕ
x + y = h y
where
h : ℕ → ℕ
h = ℕ-iteration ℕ x succ
x × y = h y
where
h : ℕ → ℕ
h = ℕ-iteration ℕ 0 (x +_)
infixl 20 _+_
infixl 21 _×_
module ℕ-order where
_≤_ _≥_ : ℕ → ℕ → 𝓤₀ ̇
0 ≤ y = 𝟙
succ x ≤ 0 = 𝟘
succ x ≤ succ y = x ≤ y
x ≥ y = y ≤ x
infix 10 _≤_
infix 10 _≥_
data _+_ {𝓤 𝓥} (X : 𝓤 ̇ ) (Y : 𝓥 ̇ ) : 𝓤 ⊔ 𝓥 ̇ where
inl : X → X + Y
inr : Y → X + Y
+-induction : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } (A : X + Y → 𝓦 ̇ )
→ ((x : X) → A (inl x))
→ ((y : Y) → A (inr y))
→ (z : X + Y) → A z
+-induction A f g (inl x) = f x
+-induction A f g (inr y) = g y
+-recursion : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } {A : 𝓦 ̇ } → (X → A) → (Y → A) → X + Y → A
+-recursion {𝓤} {𝓥} {𝓦} {X} {Y} {A} = +-induction (λ _ → A)
𝟚 : 𝓤₀ ̇
𝟚 = 𝟙 + 𝟙
pattern ₀ = inl ⋆
pattern ₁ = inr ⋆
𝟚-induction : (A : 𝟚 → 𝓤 ̇ ) → A ₀ → A ₁ → (n : 𝟚) → A n
𝟚-induction A a₀ a₁ ₀ = a₀
𝟚-induction A a₀ a₁ ₁ = a₁
𝟚-induction' : (A : 𝟚 → 𝓤 ̇ ) → A ₀ → A ₁ → (n : 𝟚) → A n
𝟚-induction' A a₀ a₁ = +-induction A
(𝟙-induction (λ (x : 𝟙) → A (inl x)) a₀)
(𝟙-induction (λ (y : 𝟙) → A (inr y)) a₁)
record Σ {𝓤 𝓥} {X : 𝓤 ̇ } (Y : X → 𝓥 ̇ ) : 𝓤 ⊔ 𝓥 ̇ where
constructor
_,_
field
x : X
y : Y x
pr₁ : {X : 𝓤 ̇ } {Y : X → 𝓥 ̇ } → Σ Y → X
pr₁ (x , y) = x
pr₂ : {X : 𝓤 ̇ } {Y : X → 𝓥 ̇ } → (z : Σ Y) → Y (pr₁ z)
pr₂ (x , y) = y
-Σ : {𝓤 𝓥 : Universe} (X : 𝓤 ̇ ) (Y : X → 𝓥 ̇ ) → 𝓤 ⊔ 𝓥 ̇
-Σ X Y = Σ Y
syntax -Σ X (λ x → y) = Σ x ꞉ X , y
Σ-induction : {X : 𝓤 ̇ } {Y : X → 𝓥 ̇ } {A : Σ Y → 𝓦 ̇ }
→ ((x : X) (y : Y x) → A (x , y))
→ ((x , y) : Σ Y) → A (x , y)
Σ-induction g (x , y) = g x y
curry : {X : 𝓤 ̇ } {Y : X → 𝓥 ̇ } {A : Σ Y → 𝓦 ̇ }
→ (((x , y) : Σ Y) → A (x , y))
→ ((x : X) (y : Y x) → A (x , y))
curry f x y = f (x , y)
_×_ : 𝓤 ̇ → 𝓥 ̇ → 𝓤 ⊔ 𝓥 ̇
X × Y = Σ x ꞉ X , Y
Π : {X : 𝓤 ̇ } (A : X → 𝓥 ̇ ) → 𝓤 ⊔ 𝓥 ̇
Π {𝓤} {𝓥} {X} A = (x : X) → A x
-Π : {𝓤 𝓥 : Universe} (X : 𝓤 ̇ ) (Y : X → 𝓥 ̇ ) → 𝓤 ⊔ 𝓥 ̇
-Π X Y = Π Y
syntax -Π A (λ x → b) = Π x ꞉ A , b
id : {X : 𝓤 ̇ } → X → X
id x = x
𝑖𝑑 : (X : 𝓤 ̇ ) → X → X
𝑖𝑑 X = id
_∘_ : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } {Z : Y → 𝓦 ̇ }
→ ((y : Y) → Z y)
→ (f : X → Y)
→ (x : X) → Z (f x)
g ∘ f = λ x → g (f x)
domain : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } → (X → Y) → 𝓤 ̇
domain {𝓤} {𝓥} {X} {Y} f = X
codomain : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } → (X → Y) → 𝓥 ̇
codomain {𝓤} {𝓥} {X} {Y} f = Y
type-of : {X : 𝓤 ̇ } → X → 𝓤 ̇
type-of {𝓤} {X} x = X
data Id {𝓤} (X : 𝓤 ̇ ) : X → X → 𝓤 ̇ where
refl : (x : X) → Id X x x
_≡_ : {X : 𝓤 ̇ } → X → X → 𝓤 ̇
x ≡ y = Id _ x y
𝕁 : (X : 𝓤 ̇ ) (A : (x y : X) → x ≡ y → 𝓥 ̇ )
→ ((x : X) → A x x (refl x))
→ (x y : X) (p : x ≡ y) → A x y p
𝕁 X A f x x (refl x) = f x
ℍ : {X : 𝓤 ̇ } (x : X) (B : (y : X) → x ≡ y → 𝓥 ̇ )
→ B x (refl x)
→ (y : X) (p : x ≡ y) → B y p
ℍ x B b x (refl x) = b
𝕁' : (X : 𝓤 ̇ ) (A : (x y : X) → x ≡ y → 𝓥 ̇ )
→ ((x : X) → A x x (refl x))
→ (x y : X) (p : x ≡ y) → A x y p
𝕁' X A f x = ℍ x (A x) (f x)
𝕁s-agreement : (X : 𝓤 ̇ ) (A : (x y : X) → x ≡ y → 𝓥 ̇ )
(f : (x : X) → A x x (refl x)) (x y : X) (p : x ≡ y)
→ 𝕁 X A f x y p ≡ 𝕁' X A f x y p
𝕁s-agreement X A f x x (refl x) = refl (f x)
transport : {X : 𝓤 ̇ } (A : X → 𝓥 ̇ ) {x y : X}
→ x ≡ y → A x → A y
transport A (refl x) = 𝑖𝑑 (A x)
transport𝕁 : {X : 𝓤 ̇ } (A : X → 𝓥 ̇ ) {x y : X}
→ x ≡ y → A x → A y
transport𝕁 {𝓤} {𝓥} {X} A {x} {y} = 𝕁 X (λ x y _ → A x → A y) (λ x → 𝑖𝑑 (A x)) x y
nondep-ℍ : {X : 𝓤 ̇ } (x : X) (A : X → 𝓥 ̇ )
→ A x → (y : X) → x ≡ y → A y
nondep-ℍ x A = ℍ x (λ y _ → A y)
transportℍ : {X : 𝓤 ̇ } (A : X → 𝓥 ̇ ) {x y : X}
→ x ≡ y → A x → A y
transportℍ A {x} {y} p a = nondep-ℍ x A a y p
transports-agreement : {X : 𝓤 ̇ } (A : X → 𝓥 ̇ ) {x y : X} (p : x ≡ y)
→ (transportℍ A p ≡ transport A p)
× (transport𝕁 A p ≡ transport A p)
transports-agreement A (refl x) = refl (transport A (refl x)) ,
refl (transport A (refl x))
lhs : {X : 𝓤 ̇ } {x y : X} → x ≡ y → X
lhs {𝓤} {X} {x} {y} p = x
rhs : {X : 𝓤 ̇ } {x y : X} → x ≡ y → X
rhs {𝓤} {X} {x} {y} p = y
_∙_ : {X : 𝓤 ̇ } {x y z : X} → x ≡ y → y ≡ z → x ≡ z
p ∙ q = transport (lhs p ≡_) q p
_≡⟨_⟩_ : {X : 𝓤 ̇ } (x : X) {y z : X} → x ≡ y → y ≡ z → x ≡ z
x ≡⟨ p ⟩ q = p ∙ q
_∎ : {X : 𝓤 ̇ } (x : X) → x ≡ x
x ∎ = refl x
_⁻¹ : {X : 𝓤 ̇ } → {x y : X} → x ≡ y → y ≡ x
p ⁻¹ = transport (_≡ lhs p) p (refl (lhs p))
_∙'_ : {X : 𝓤 ̇ } {x y z : X} → x ≡ y → y ≡ z → x ≡ z
p ∙' q = transport (_≡ rhs q) (p ⁻¹) q
∙agreement : {X : 𝓤 ̇ } {x y z : X} (p : x ≡ y) (q : y ≡ z)
→ (p ∙' q) ≡ (p ∙ q)
∙agreement (refl x) (refl x) = refl (refl x)
rdnel : {X : 𝓤 ̇ } {x y : X} (p : x ≡ y)
→ (p ∙ refl y) ≡ p
rdnel p = refl p
rdner : {X : 𝓤 ̇ } {y z : X} (q : y ≡ z)
→ (refl y ∙' q) ≡ q
rdner q = refl q
ap : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } (f : X → Y) {x x' : X} → x ≡ x' → f x ≡ f x'
ap f {x} {x'} p = transport (λ - → f x ≡ f -) p (refl (f x))
_∼_ : {X : 𝓤 ̇ } {A : X → 𝓥 ̇ } → Π A → Π A → 𝓤 ⊔ 𝓥 ̇
f ∼ g = ∀ x → f x ≡ g x
¬¬ ¬¬¬ : 𝓤 ̇ → 𝓤 ̇
¬¬ A = ¬(¬ A)
¬¬¬ A = ¬(¬¬ A)
dni : (A : 𝓤 ̇ ) → A → ¬¬ A
dni A a u = u a
contrapositive : {A : 𝓤 ̇ } {B : 𝓥 ̇ } → (A → B) → (¬ B → ¬ A)
contrapositive f v a = v (f a)
tno : (A : 𝓤 ̇ ) → ¬¬¬ A → ¬ A
tno A = contrapositive (dni A)
_⇔_ : 𝓤 ̇ → 𝓥 ̇ → 𝓤 ⊔ 𝓥 ̇
X ⇔ Y = (X → Y) × (Y → X)
lr-implication : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } → (X ⇔ Y) → (X → Y)
lr-implication = pr₁
rl-implication : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } → (X ⇔ Y) → (Y → X)
rl-implication = pr₂
absurdity³-is-absurdity : {A : 𝓤 ̇ } → ¬¬¬ A ⇔ ¬ A
absurdity³-is-absurdity {𝓤} {A} = firstly , secondly
where
firstly : ¬¬¬ A → ¬ A
firstly = contrapositive (dni A)
secondly : ¬ A → ¬¬¬ A
secondly = dni (¬ A)
_≢_ : {X : 𝓤 ̇ } → X → X → 𝓤 ̇
x ≢ y = ¬(x ≡ y)
≢-sym : {X : 𝓤 ̇ } {x y : X} → x ≢ y → y ≢ x
≢-sym {𝓤} {X} {x} {y} u = λ (p : y ≡ x) → u (p ⁻¹)
Id→Fun : {X Y : 𝓤 ̇ } → X ≡ Y → X → Y
Id→Fun {𝓤} = transport (𝑖𝑑 (𝓤 ̇ ))
Id→Fun' : {X Y : 𝓤 ̇ } → X ≡ Y → X → Y
Id→Fun' (refl X) = 𝑖𝑑 X
Id→Funs-agree : {X Y : 𝓤 ̇ } (p : X ≡ Y)
→ Id→Fun p ≡ Id→Fun' p
Id→Funs-agree (refl X) = refl (𝑖𝑑 X)
𝟙-is-not-𝟘 : 𝟙 ≢ 𝟘
𝟙-is-not-𝟘 p = Id→Fun p ⋆
₁-is-not-₀ : ₁ ≢ ₀
₁-is-not-₀ p = 𝟙-is-not-𝟘 q
where
f : 𝟚 → 𝓤₀ ̇
f ₀ = 𝟘
f ₁ = 𝟙
q : 𝟙 ≡ 𝟘
q = ap f p
₁-is-not-₀[not-an-MLTT-proof] : ¬(₁ ≡ ₀)
₁-is-not-₀[not-an-MLTT-proof] ()
decidable : 𝓤 ̇ → 𝓤 ̇
decidable A = A + ¬ A
has-decidable-equality : 𝓤 ̇ → 𝓤 ̇
has-decidable-equality X = (x y : X) → decidable (x ≡ y)
𝟚-has-decidable-equality : has-decidable-equality 𝟚
𝟚-has-decidable-equality ₀ ₀ = inl (refl ₀)
𝟚-has-decidable-equality ₀ ₁ = inr (≢-sym ₁-is-not-₀)
𝟚-has-decidable-equality ₁ ₀ = inr ₁-is-not-₀
𝟚-has-decidable-equality ₁ ₁ = inl (refl ₁)
not-zero-is-one : (n : 𝟚) → n ≢ ₀ → n ≡ ₁
not-zero-is-one ₀ f = !𝟘 (₀ ≡ ₁) (f (refl ₀))
not-zero-is-one ₁ f = refl ₁
inl-inr-disjoint-images : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } {x : X} {y : Y} → inl x ≢ inr y
inl-inr-disjoint-images {𝓤} {𝓥} {X} {Y} p = 𝟙-is-not-𝟘 q
where
f : X + Y → 𝓤₀ ̇
f (inl x) = 𝟙
f (inr y) = 𝟘
q : 𝟙 ≡ 𝟘
q = ap f p
right-fails-gives-left-holds : {P : 𝓤 ̇ } {Q : 𝓥 ̇ } → P + Q → ¬ Q → P
right-fails-gives-left-holds (inl p) u = p
right-fails-gives-left-holds (inr q) u = !𝟘 _ (u q)
module twin-primes where
open Arithmetic renaming (_×_ to _*_ ; _+_ to _∔_)
open ℕ-order
is-prime : ℕ → 𝓤₀ ̇
is-prime n = (n ≥ 2) × ((x y : ℕ) → x * y ≡ n → (x ≡ 1) + (x ≡ n))
twin-prime-conjecture : 𝓤₀ ̇
twin-prime-conjecture =
(n : ℕ) → -Σ ℕ (λ p → ((p ≥ n) × is-prime p) × is-prime (p ∔ 2))
positive-not-zero : (x : ℕ) → succ x ≢ 0
positive-not-zero x p = 𝟙-is-not-𝟘 q where
f : ℕ → 𝓤₀ ̇
f zero = 𝟘
f (succ n) = 𝟙
q : 𝟙 ≡ 𝟘
q = ap f p
pred : ℕ → ℕ
pred 0 = 0
pred (succ n) = n
succ-lc : {x y : ℕ} → succ x ≡ succ y → x ≡ y
succ-lc = ap pred
ℕ-has-decidable-equality : has-decidable-equality ℕ
ℕ-has-decidable-equality 0 0 = inl (refl 0)
ℕ-has-decidable-equality 0 (succ y) = inr (≢-sym (positive-not-zero y))
ℕ-has-decidable-equality (succ x) 0 = inr (positive-not-zero x)
ℕ-has-decidable-equality (succ x) (succ y) = f (ℕ-has-decidable-equality x y)
where
f : decidable (x ≡ y) → decidable (succ x ≡ succ y)
f (inl p) = inl (ap succ p)
f (inr k) = inr (λ (s : succ x ≡ succ y) → k (succ-lc s))
module basic-arithmetic-and-order where
open ℕ-order public
open Arithmetic renaming (_+_ to _∔_) hiding (_×_)
+-assoc : (x y z : ℕ) → ((x ∔ y) ∔ z) ≡ (x ∔ (y ∔ z))
+-assoc x y zero = ((x ∔ y) ∔ 0) ≡⟨ (refl _) ⟩
(x ∔ (y ∔ 0)) ∎
+-assoc x y (succ z) = ((x ∔ y) ∔ succ z) ≡⟨ (refl _) ⟩
(succ ((x ∔ y) ∔ z)) ≡⟨ ap succ IH ⟩
(succ (x ∔ (y ∔ z))) ≡⟨ refl _ ⟩
(x ∔ (y ∔ succ z)) ∎
where
IH : ((x ∔ y) ∔ z) ≡ (x ∔ (y ∔ z))
IH = +-assoc x y z
+-base-on-first : (x : ℕ) → 0 ∔ x ≡ x
+-base-on-first 0 = refl 0
+-base-on-first (succ x) = 0 ∔ succ x ≡⟨ refl _ ⟩
succ (0 ∔ x) ≡⟨ ap succ IH ⟩
succ x ∎
where
IH : 0 ∔ x ≡ x
IH = +-base-on-first x
+-step-on-first : (x y : ℕ) → succ x ∔ y ≡ succ (x ∔ y)
+-step-on-first x zero = refl (succ x)
+-step-on-first x (succ y) = succ x ∔ succ y ≡⟨ refl _ ⟩
succ (succ x ∔ y) ≡⟨ ap succ IH ⟩
succ (x ∔ succ y) ∎
where
IH : succ x ∔ y ≡ succ (x ∔ y)
IH = +-step-on-first x y
+-comm : (x y : ℕ) → x ∔ y ≡ y ∔ x
+-comm 0 y = 0 ∔ y ≡⟨ +-base-on-first y ⟩
y ≡⟨ refl _ ⟩
y ∔ 0 ∎
+-comm (succ x) y = succ x ∔ y ≡⟨ +-step-on-first x y ⟩
succ(x ∔ y) ≡⟨ ap succ IH ⟩
succ(y ∔ x) ≡⟨ refl _ ⟩
y ∔ succ x ∎
where
IH : x ∔ y ≡ y ∔ x
IH = +-comm x y
+-lc : (x y z : ℕ) → x ∔ y ≡ x ∔ z → y ≡ z
+-lc 0 y z p = y ≡⟨ (+-base-on-first y)⁻¹ ⟩
0 ∔ y ≡⟨ p ⟩
0 ∔ z ≡⟨ +-base-on-first z ⟩
z ∎
+-lc (succ x) y z p = IH
where
q = succ (x ∔ y) ≡⟨ (+-step-on-first x y)⁻¹ ⟩
succ x ∔ y ≡⟨ p ⟩
succ x ∔ z ≡⟨ +-step-on-first x z ⟩
succ (x ∔ z) ∎
IH : y ≡ z
IH = +-lc x y z (succ-lc q)
_≼_ : ℕ → ℕ → 𝓤₀ ̇
x ≼ y = Σ z ꞉ ℕ , x ∔ z ≡ y
≤-gives-≼ : (x y : ℕ) → x ≤ y → x ≼ y
≤-gives-≼ 0 0 l = 0 , refl 0
≤-gives-≼ 0 (succ y) l = succ y , +-base-on-first (succ y)
≤-gives-≼ (succ x) 0 l = !𝟘 (succ x ≼ zero) l
≤-gives-≼ (succ x) (succ y) l = γ
where
IH : x ≼ y
IH = ≤-gives-≼ x y l
z : ℕ
z = pr₁ IH
p : x ∔ z ≡ y
p = pr₂ IH
γ : succ x ≼ succ y
γ = z , (succ x ∔ z ≡⟨ +-step-on-first x z ⟩
succ (x ∔ z) ≡⟨ ap succ p ⟩
succ y ∎)
≼-gives-≤ : (x y : ℕ) → x ≼ y → x ≤ y
≼-gives-≤ 0 0 (z , p) = ⋆
≼-gives-≤ 0 (succ y) (z , p) = ⋆
≼-gives-≤ (succ x) 0 (z , p) = positive-not-zero (x ∔ z) q
where
q = succ (x ∔ z) ≡⟨ (+-step-on-first x z)⁻¹ ⟩
succ x ∔ z ≡⟨ p ⟩
zero ∎
≼-gives-≤ (succ x) (succ y) (z , p) = IH
where
q = succ (x ∔ z) ≡⟨ (+-step-on-first x z)⁻¹ ⟩
succ x ∔ z ≡⟨ p ⟩
succ y ∎
IH : x ≤ y
IH = ≼-gives-≤ x y (z , succ-lc q)
≤-refl : (n : ℕ) → n ≤ n
≤-refl zero = ⋆
≤-refl (succ n) = ≤-refl n
≤-trans : (l m n : ℕ) → l ≤ m → m ≤ n → l ≤ n
≤-trans zero m n p q = ⋆
≤-trans (succ l) zero n p q = !𝟘 (succ l ≤ n) p
≤-trans (succ l) (succ m) zero p q = q
≤-trans (succ l) (succ m) (succ n) p q = ≤-trans l m n p q
≤-anti : (m n : ℕ) → m ≤ n → n ≤ m → m ≡ n
≤-anti zero zero p q = refl zero
≤-anti zero (succ n) p q = !𝟘 (zero ≡ succ n) q
≤-anti (succ m) zero p q = !𝟘 (succ m ≡ zero) p
≤-anti (succ m) (succ n) p q = ap succ (≤-anti m n p q)
≤-succ : (n : ℕ) → n ≤ succ n
≤-succ zero = ⋆
≤-succ (succ n) = ≤-succ n
zero-minimal : (n : ℕ) → zero ≤ n
zero-minimal n = ⋆
unique-minimal : (n : ℕ) → n ≤ zero → n ≡ zero
unique-minimal zero p = refl zero
unique-minimal (succ n) p = !𝟘 (succ n ≡ zero) p
≤-split : (m n : ℕ) → m ≤ succ n → (m ≤ n) + (m ≡ succ n)
≤-split zero n l = inl l
≤-split (succ m) zero l = inr (ap succ (unique-minimal m l))
≤-split (succ m) (succ n) l = +-recursion inl (inr ∘ ap succ) (≤-split m n l)
_<_ : ℕ → ℕ → 𝓤₀ ̇
x < y = succ x ≤ y
infix 10 _<_
not-<-gives-≥ : (m n : ℕ) → ¬(n < m) → m ≤ n
not-<-gives-≥ zero n u = zero-minimal n
not-<-gives-≥ (succ m) zero u = dni (zero < succ m) (zero-minimal m) u
not-<-gives-≥ (succ m) (succ n) u = not-<-gives-≥ m n u
bounded-∀-next : (A : ℕ → 𝓤 ̇ ) (k : ℕ)
→ A k
→ ((n : ℕ) → n < k → A n)
→ (n : ℕ) → n < succ k → A n
bounded-∀-next A k a φ n l = +-recursion f g s
where
s : (n < k) + (succ n ≡ succ k)
s = ≤-split (succ n) k l
f : n < k → A n
f = φ n
g : succ n ≡ succ k → A n
g p = transport A ((succ-lc p)⁻¹) a
root : (ℕ → ℕ) → 𝓤₀ ̇
root f = Σ n ꞉ ℕ , f n ≡ 0
_has-no-root<_ : (ℕ → ℕ) → ℕ → 𝓤₀ ̇
f has-no-root< k = (n : ℕ) → n < k → f n ≢ 0
is-minimal-root : (ℕ → ℕ) → ℕ → 𝓤₀ ̇
is-minimal-root f m = (f m ≡ 0) × (f has-no-root< m)
at-most-one-minimal-root : (f : ℕ → ℕ) (m n : ℕ)
→ is-minimal-root f m → is-minimal-root f n → m ≡ n
at-most-one-minimal-root f m n (p , φ) (q , ψ) = c m n a b
where
a : ¬(m < n)
a u = ψ m u p
b : ¬(n < m)
b v = φ n v q
c : (m n : ℕ) → ¬(m < n) → ¬(n < m) → m ≡ n
c m n u v = ≤-anti m n (not-<-gives-≥ m n v) (not-<-gives-≥ n m u)
minimal-root : (ℕ → ℕ) → 𝓤₀ ̇
minimal-root f = Σ m ꞉ ℕ , is-minimal-root f m
minimal-root-is-root : ∀ f → minimal-root f → root f
minimal-root-is-root f (m , p , _) = m , p
bounded-ℕ-search : ∀ k f → (minimal-root f) + (f has-no-root< k)
bounded-ℕ-search zero f = inr (λ n → !𝟘 (f n ≢ 0))
bounded-ℕ-search (succ k) f = +-recursion φ γ (bounded-ℕ-search k f)
where
A : ℕ → (ℕ → ℕ) → 𝓤₀ ̇
A k f = (minimal-root f) + (f has-no-root< k)
φ : minimal-root f → A (succ k) f
φ = inl
γ : f has-no-root< k → A (succ k) f
γ u = +-recursion γ₀ γ₁ (ℕ-has-decidable-equality (f k) 0)
where
γ₀ : f k ≡ 0 → A (succ k) f
γ₀ p = inl (k , p , u)
γ₁ : f k ≢ 0 → A (succ k) f
γ₁ v = inr (bounded-∀-next (λ n → f n ≢ 0) k v u)
root-gives-minimal-root : ∀ f → root f → minimal-root f
root-gives-minimal-root f (n , p) = γ
where
g : ¬(f has-no-root< (succ n))
g φ = φ n (≤-refl n) p
γ : minimal-root f
γ = right-fails-gives-left-holds (bounded-ℕ-search (succ n) f) g
is-singleton : 𝓤 ̇ → 𝓤 ̇
is-singleton X = Σ c ꞉ X , ((x : X) → c ≡ x)
is-center : (X : 𝓤 ̇ ) → X → 𝓤 ̇
is-center X c = (x : X) → c ≡ x
𝟙-is-singleton : is-singleton 𝟙
𝟙-is-singleton = ⋆ , λ x → 𝟙-induction (λ y → ⋆ ≡ y) (refl ⋆) x
center : (X : 𝓤 ̇ ) → is-singleton X → X
center X (c , φ) = c
centrality : (X : 𝓤 ̇ ) (i : is-singleton X) (x : X) → center X i ≡ x
centrality X (c , φ) = φ
is-subsingleton : 𝓤 ̇ → 𝓤 ̇
is-subsingleton X = (x y : X) → x ≡ y
𝟘-is-subsingleton : is-subsingleton 𝟘
𝟘-is-subsingleton x y = !𝟘 (x ≡ y) x
singletons-are-subsingletons : (X : 𝓤 ̇ ) → is-singleton X → is-subsingleton X
singletons-are-subsingletons X (c , φ) x y = x ≡⟨ (φ x)⁻¹ ⟩
c ≡⟨ φ y ⟩
y ∎
𝟙-is-subsingleton : is-subsingleton 𝟙
𝟙-is-subsingleton = singletons-are-subsingletons 𝟙 𝟙-is-singleton
pointed-subsingletons-are-singletons : (X : 𝓤 ̇ )
→ X → is-subsingleton X → is-singleton X
pointed-subsingletons-are-singletons X x s = (x , s x)
singleton-iff-pointed-and-subsingleton : {X : 𝓤 ̇ }
→ is-singleton X ⇔ (X × is-subsingleton X)
singleton-iff-pointed-and-subsingleton {𝓤} {X} = (a , b)
where
a : is-singleton X → X × is-subsingleton X
a s = center X s , singletons-are-subsingletons X s
b : X × is-subsingleton X → is-singleton X
b (x , t) = pointed-subsingletons-are-singletons X x t
is-prop is-truth-value : 𝓤 ̇ → 𝓤 ̇
is-prop = is-subsingleton
is-truth-value = is-subsingleton
is-set : 𝓤 ̇ → 𝓤 ̇
is-set X = (x y : X) → is-subsingleton (x ≡ y)
EM EM' : ∀ 𝓤 → 𝓤 ⁺ ̇
EM 𝓤 = (X : 𝓤 ̇ ) → is-subsingleton X → X + ¬ X
EM' 𝓤 = (X : 𝓤 ̇ ) → is-subsingleton X → is-singleton X + is-empty X
EM-gives-EM' : EM 𝓤 → EM' 𝓤
EM-gives-EM' em X s = γ (em X s)
where
γ : X + ¬ X → is-singleton X + is-empty X
γ (inl x) = inl (pointed-subsingletons-are-singletons X x s)
γ (inr x) = inr x
EM'-gives-EM : EM' 𝓤 → EM 𝓤
EM'-gives-EM em' X s = γ (em' X s)
where
γ : is-singleton X + is-empty X → X + ¬ X
γ (inl i) = inl (center X i)
γ (inr x) = inr x
no-unicorns : ¬(Σ X ꞉ 𝓤 ̇ , is-subsingleton X × ¬(is-singleton X) × ¬(is-empty X))
no-unicorns (X , i , f , g) = c
where
e : is-empty X
e x = f (pointed-subsingletons-are-singletons X x i)
c : 𝟘
c = g e
module magmas where
Magma : (𝓤 : Universe) → 𝓤 ⁺ ̇
Magma 𝓤 = Σ X ꞉ 𝓤 ̇ , is-set X × (X → X → X)
⟨_⟩ : Magma 𝓤 → 𝓤 ̇
⟨ X , i , _·_ ⟩ = X
magma-is-set : (M : Magma 𝓤) → is-set ⟨ M ⟩
magma-is-set (X , i , _·_) = i
magma-operation : (M : Magma 𝓤) → ⟨ M ⟩ → ⟨ M ⟩ → ⟨ M ⟩
magma-operation (X , i , _·_) = _·_
syntax magma-operation M x y = x ·⟨ M ⟩ y
is-magma-hom : (M N : Magma 𝓤) → (⟨ M ⟩ → ⟨ N ⟩) → 𝓤 ̇
is-magma-hom M N f = (x y : ⟨ M ⟩) → f (x ·⟨ M ⟩ y) ≡ f x ·⟨ N ⟩ f y
id-is-magma-hom : (M : Magma 𝓤) → is-magma-hom M M (𝑖𝑑 ⟨ M ⟩)
id-is-magma-hom M = λ (x y : ⟨ M ⟩) → refl (x ·⟨ M ⟩ y)
is-magma-iso : (M N : Magma 𝓤) → (⟨ M ⟩ → ⟨ N ⟩) → 𝓤 ̇
is-magma-iso M N f = is-magma-hom M N f
× (Σ g ꞉ (⟨ N ⟩ → ⟨ M ⟩), is-magma-hom N M g
× (g ∘ f ∼ 𝑖𝑑 ⟨ M ⟩)
× (f ∘ g ∼ 𝑖𝑑 ⟨ N ⟩))
id-is-magma-iso : (M : Magma 𝓤) → is-magma-iso M M (𝑖𝑑 ⟨ M ⟩)
id-is-magma-iso M = id-is-magma-hom M ,
𝑖𝑑 ⟨ M ⟩ ,
id-is-magma-hom M ,
refl ,
refl
Id→iso : {M N : Magma 𝓤} → M ≡ N → ⟨ M ⟩ → ⟨ N ⟩
Id→iso p = transport ⟨_⟩ p
Id→iso-is-iso : {M N : Magma 𝓤} (p : M ≡ N) → is-magma-iso M N (Id→iso p)
Id→iso-is-iso (refl M) = id-is-magma-iso M
_≅ₘ_ : Magma 𝓤 → Magma 𝓤 → 𝓤 ̇
M ≅ₘ N = Σ f ꞉ (⟨ M ⟩ → ⟨ N ⟩), is-magma-iso M N f
magma-Id→iso : {M N : Magma 𝓤} → M ≡ N → M ≅ₘ N
magma-Id→iso p = Id→iso p , Id→iso-is-iso p
∞-Magma : (𝓤 : Universe) → 𝓤 ⁺ ̇
∞-Magma 𝓤 = Σ X ꞉ 𝓤 ̇ , (X → X → X)
module monoids where
left-neutral : {X : 𝓤 ̇ } → X → (X → X → X) → 𝓤 ̇
left-neutral e _·_ = ∀ x → e · x ≡ x
right-neutral : {X : 𝓤 ̇ } → X → (X → X → X) → 𝓤 ̇
right-neutral e _·_ = ∀ x → x · e ≡ x
associative : {X : 𝓤 ̇ } → (X → X → X) → 𝓤 ̇
associative _·_ = ∀ x y z → (x · y) · z ≡ x · (y · z)
Monoid : (𝓤 : Universe) → 𝓤 ⁺ ̇
Monoid 𝓤 = Σ X ꞉ 𝓤 ̇ , is-set X
× (Σ · ꞉ (X → X → X) , (Σ e ꞉ X , (left-neutral e ·)
× (right-neutral e ·)
× (associative ·)))
module groups where
left-neutral : {X : 𝓤 ̇ } → X → (X → X → X) → 𝓤 ̇
left-neutral e _·_ = ∀ x → e · x ≡ x
right-neutral : {X : 𝓤 ̇ } → X → (X → X → X) → 𝓤 ̇
right-neutral e _·_ = ∀ x → x · e ≡ x
associative : {X : 𝓤 ̇ } → (X → X → X) → 𝓤 ̇
associative _·_ = ∀ x y z → (x · y) · z ≡ x · (y · z)
inverse : {X : 𝓤 ̇ } → X → (X → X → X) → 𝓤 ̇
inverse e _·_ = ∀ x → Σ (λ x' → x · x' ≡ e)
Monoid : (𝓤 : Universe) → 𝓤 ⁺ ̇
Monoid 𝓤 = Σ X ꞉ 𝓤 ̇ , is-set X
× (Σ · ꞉ (X → X → X) , (Σ e ꞉ X , (left-neutral e ·)
× (right-neutral e ·)
× (associative ·)
× (inverse e ·)))
refl-left : {X : 𝓤 ̇ } {x y : X} {p : x ≡ y} → refl x ∙ p ≡ p
refl-left {𝓤} {X} {x} {x} {refl x} = refl (refl x)
refl-right : {X : 𝓤 ̇ } {x y : X} {p : x ≡ y} → p ∙ refl y ≡ p
refl-right {𝓤} {X} {x} {y} {p} = refl p
∙assoc : {X : 𝓤 ̇ } {x y z t : X} (p : x ≡ y) (q : y ≡ z) (r : z ≡ t)
→ (p ∙ q) ∙ r ≡ p ∙ (q ∙ r)
∙assoc p q (refl z) = refl (p ∙ q)
⁻¹-left∙ : {X : 𝓤 ̇ } {x y : X} (p : x ≡ y)
→ p ⁻¹ ∙ p ≡ refl y
⁻¹-left∙ (refl x) = refl (refl x)
⁻¹-right∙ : {X : 𝓤 ̇ } {x y : X} (p : x ≡ y)
→ p ∙ p ⁻¹ ≡ refl x
⁻¹-right∙ (refl x) = refl (refl x)
⁻¹-involutive : {X : 𝓤 ̇ } {x y : X} (p : x ≡ y)
→ (p ⁻¹)⁻¹ ≡ p
⁻¹-involutive (refl x) = refl (refl x)
ap-refl : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } (f : X → Y) (x : X)
→ ap f (refl x) ≡ refl (f x)
ap-refl f x = refl (refl (f x))
ap-∙ : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } (f : X → Y) {x y z : X} (p : x ≡ y) (q : y ≡ z)
→ ap f (p ∙ q) ≡ ap f p ∙ ap f q
ap-∙ f p (refl y) = refl (ap f p)
ap⁻¹ : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } (f : X → Y) {x y : X} (p : x ≡ y)
→ (ap f p)⁻¹ ≡ ap f (p ⁻¹)
ap⁻¹ f (refl x) = refl (refl (f x))
ap-id : {X : 𝓤 ̇ } {x y : X} (p : x ≡ y)
→ ap id p ≡ p
ap-id (refl x) = refl (refl x)
ap-∘ : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } {Z : 𝓦 ̇ }
(f : X → Y) (g : Y → Z) {x y : X} (p : x ≡ y)
→ ap (g ∘ f) p ≡ (ap g ∘ ap f) p
ap-∘ f g (refl x) = refl (refl (g (f x)))
transport∙ : {X : 𝓤 ̇ } (A : X → 𝓥 ̇ ) {x y z : X} (p : x ≡ y) (q : y ≡ z)
→ transport A (p ∙ q) ≡ transport A q ∘ transport A p
transport∙ A p (refl y) = refl (transport A p)
Nat : {X : 𝓤 ̇ } → (X → 𝓥 ̇ ) → (X → 𝓦 ̇ ) → 𝓤 ⊔ 𝓥 ⊔ 𝓦 ̇
Nat A B = (x : domain A) → A x → B x
Nats-are-natural : {X : 𝓤 ̇ } (A : X → 𝓥 ̇ ) (B : X → 𝓦 ̇ ) (τ : Nat A B)
→ {x y : X} (p : x ≡ y)
→ τ y ∘ transport A p ≡ transport B p ∘ τ x
Nats-are-natural A B τ (refl x) = refl (τ x)
NatΣ : {X : 𝓤 ̇ } {A : X → 𝓥 ̇ } {B : X → 𝓦 ̇ } → Nat A B → Σ A → Σ B
NatΣ τ (x , a) = (x , τ x a)
transport-ap : {X : 𝓤 ̇ } {Y : 𝓥 ̇ } (A : Y → 𝓦 ̇ )
(f : X → Y) {x x' : X} (p : x ≡ x') (a : A (f x))
→ transport (A ∘ f) p a ≡ transport A (ap f p) a
transport-ap A f (refl x) a = refl a
data Color : 𝓤₀ ̇ where
Black White : Color
apd : {X : 𝓤 ̇ } {A : X → 𝓥 ̇ } (f : (x : X) → A x) {x y : X}
(p : x ≡ y) → transport A p (f x) ≡ f y
apd f (refl _) = refl (f _)
module Exercise where
≤ : ℕ → ℕ → 𝓤₀ ̇
≤ x = ℕ-induction (λ _ → ℕ → 𝓤₀ ̇) (λ _ → 𝟙)
(λ _ f x₂ → ℕ-induction (λ _ → 𝓤₀ ̇) 𝟘 (λ n _ → f n) x₂) x
ℍ' : {X : 𝓤 ̇ } (x : X) (B : (y : X) → x ≡ y → 𝓥 ̇ )
→ B x (refl x)
→ (y : X) (p : x ≡ y) → B y p
ℍ' {X} x B b y p = {!!}
ℕ-has-decidable-equality' : has-decidable-equality ℕ
ℕ-has-decidable-equality' = ℕ-induction (λ z → (x : ℕ) → Id ℕ z x + (z ≢ x))
(λ m → ℕ-induction
(λ x → Id ℕ zero x + (zero ≢ x))
(inl (refl zero))
(λ n _ → inr (λ ())) m)
λ n f → ℕ-induction (λ x → Id ℕ (succ n) x + (succ n ≢ x))
(inr (λ ()))
λ n₁ x → g (f n₁)
where
g : {x y : ℕ} → decidable (x ≡ y) → decidable (succ x ≡ succ y)
g (inl p) = inl (ap succ p)
g {x} {y} (inr k) = inr (λ (s : succ x ≡ succ y) → k (succ-lc s))
Sub-EM Sub-EM' : ∀ 𝓤 → 𝓤 ⁺ ̇
Sub-EM 𝓤 = (X : 𝓤 ̇ ) → is-subsingleton X → ¬¬(is-singleton X + is-empty X)
Sub-EM' 𝓤 = ¬¬((X : 𝓤 ̇ ) → is-subsingleton X → is-singleton X + is-empty X)
Sub-EM-gives-Sub-EM' : Sub-EM 𝓤 → Sub-EM' 𝓤
Sub-EM-gives-Sub-EM' {𝓤} sub neg = {!!}
Sub-EM'-gives-Sub-EM : Sub-EM' 𝓤 → Sub-EM 𝓤
Sub-EM'-gives-Sub-EM sub' X subsing neg = sub' λ z → neg (z X subsing)
∙assoc' : {X : 𝓤 ̇ } {x y z t : X} (p : x ≡ y) (q : y ≡ z) (r : z ≡ t)
→ (p ∙ q) ∙ r ≡ p ∙ (q ∙ r)
∙assoc' p q r = {!𝕁!}
infix 0 _∼_
infixr 50 _,_
infixr 30 _×_
infixr 20 _+_
infixl 70 _∘_
infix 0 Id
infix 0 _≡_
infix 10 _⇔_
infixl 30 _∙_
infixr 0 _≡⟨_⟩_
infix 1 _∎
infix 40 _⁻¹
infix 10 _◁_
infixr 0 _◁⟨_⟩_
infix 1 _◀
infix 10 _≃_
infixl 30 _●_
infixr 0 _≃⟨_⟩_
infix 1 _■
infix 40 _∈_
infix 30 _[_,_]
infixr -1 -Σ
infixr -1 -Π
infixr -1 -∃!
| {
"alphanum_fraction": 0.4114352745,
"avg_line_length": 27.7594537815,
"ext": "agda",
"hexsha": "02fcc4b38d769001457c587ec732da1ad5513fdb",
"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": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sym-cereal/proofs",
"max_forks_repo_path": "HoTT-UT-Agda/HoTT-UF-Agda.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"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": "sym-cereal/proofs",
"max_issues_repo_path": "HoTT-UT-Agda/HoTT-UF-Agda.agda",
"max_line_length": 100,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UnsoundWitch/proofs",
"max_stars_repo_path": "HoTT-UT-Agda/HoTT-UF-Agda.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-18T10:58:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-03T03:29:40.000Z",
"num_tokens": 13197,
"size": 26427
} |
{-# OPTIONS --cubical --safe #-}
open import Prelude
open import Relation.Binary
module Relation.Binary.Construct.LowerBound {e} {E : Type e} {r₁ r₂} (totalOrder : TotalOrder E r₁ 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 _
⌊ x ⌋≤ ⌊⊥⌋ = Poly.⊥
⌊ x ⌋≤ ⌊ y ⌋ = x ≤ y
_⌊≤⌋_ : ⌊∙⌋ → ⌊∙⌋ → Type _
⌊⊥⌋ ⌊≤⌋ y = Poly.⊤
⌊ x ⌋ ⌊≤⌋ y = ⌊ x ⌋≤ y
_<⌊_⌋ : ⌊∙⌋ → E → Type _
⌊⊥⌋ <⌊ y ⌋ = Poly.⊤
⌊ x ⌋ <⌊ y ⌋ = x < y
_⌊<⌋_ : ⌊∙⌋ → ⌊∙⌋ → Type _
_ ⌊<⌋ ⌊⊥⌋ = Poly.⊥
x ⌊<⌋ ⌊ y ⌋ = x <⌊ y ⌋
lb-pord : PartialOrder ⌊∙⌋ _
Preorder._≤_ (PartialOrder.preorder lb-pord) = _⌊≤⌋_
Preorder.refl (PartialOrder.preorder lb-pord) {⌊⊥⌋} = _
Preorder.refl (PartialOrder.preorder lb-pord) {⌊ x ⌋} = <-refl
Preorder.trans (PartialOrder.preorder lb-pord) {⌊⊥⌋} {_} {_} p q = _
Preorder.trans (PartialOrder.preorder lb-pord) {⌊ x ⌋} {⌊ y ⌋} {⌊ z ⌋} p q = ≤-trans p q
PartialOrder.antisym lb-pord {⌊⊥⌋} {⌊⊥⌋} p q = refl
PartialOrder.antisym lb-pord {⌊ x ⌋} {⌊ x₁ ⌋} p q = cong ⌊_⌋ (antisym p q)
lb-sord : StrictPartialOrder ⌊∙⌋ _
StrictPreorder._<_ (StrictPartialOrder.strictPreorder lb-sord) = _⌊<⌋_
StrictPreorder.trans (StrictPartialOrder.strictPreorder lb-sord) {⌊⊥⌋} {⌊⊥⌋} {⌊⊥⌋} p q = q
StrictPreorder.trans (StrictPartialOrder.strictPreorder lb-sord) {⌊⊥⌋} {⌊⊥⌋} {⌊ x ⌋} p q = q
StrictPreorder.trans (StrictPartialOrder.strictPreorder lb-sord) {⌊⊥⌋} {⌊ x ⌋} {⌊ x₁ ⌋} p q = p
StrictPreorder.trans (StrictPartialOrder.strictPreorder lb-sord) {⌊ x ⌋} {⌊ x₁ ⌋} {⌊ x₂ ⌋} p q = <-trans p q
StrictPreorder.irrefl (StrictPartialOrder.strictPreorder lb-sord) {⌊ x ⌋} = irrefl {x = x}
StrictPartialOrder.conn lb-sord {⌊⊥⌋} {⌊⊥⌋} p q = refl
StrictPartialOrder.conn lb-sord {⌊⊥⌋} {⌊ x ⌋} p q = ⊥-elim (p _)
StrictPartialOrder.conn lb-sord {⌊ x ⌋} {⌊⊥⌋} p q = ⊥-elim (q _)
StrictPartialOrder.conn lb-sord {⌊ x ⌋} {⌊ x₁ ⌋} p q = cong ⌊_⌋ (conn p q)
lb-lt : ∀ x y → Dec (x ⌊<⌋ y)
lb-lt x ⌊⊥⌋ = no (λ ())
lb-lt ⌊⊥⌋ ⌊ y ⌋ = yes Poly.tt
lb-lt ⌊ x ⌋ ⌊ y ⌋ = x <? y
lb-ord : TotalOrder ⌊∙⌋ _ _
TotalOrder.strictPartialOrder lb-ord = lb-sord
TotalOrder.partialOrder lb-ord = lb-pord
TotalOrder._<?_ lb-ord = lb-lt
TotalOrder.≰⇒> lb-ord {⌊⊥⌋} {⌊⊥⌋} p = ⊥-elim (p _)
TotalOrder.≰⇒> lb-ord {⌊⊥⌋} {⌊ x ⌋} p = ⊥-elim (p _ )
TotalOrder.≰⇒> lb-ord {⌊ x ⌋} {⌊⊥⌋} p = _
TotalOrder.≰⇒> lb-ord {⌊ x ⌋} {⌊ x₁ ⌋} p = ≰⇒> p
TotalOrder.≮⇒≥ lb-ord {x} {⌊⊥⌋} p = _
TotalOrder.≮⇒≥ lb-ord {⌊⊥⌋} {⌊ y ⌋} p = ⊥-elim (p _)
TotalOrder.≮⇒≥ lb-ord {⌊ x ⌋} {⌊ y ⌋} p = ≮⇒≥ p
| {
"alphanum_fraction": 0.5723006486,
"avg_line_length": 36.4027777778,
"ext": "agda",
"hexsha": "73203d355ef1b1608218a1825af640ea1cbfaf45",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Relation/Binary/Construct/LowerBound.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Relation/Binary/Construct/LowerBound.agda",
"max_line_length": 108,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Relation/Binary/Construct/LowerBound.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 1561,
"size": 2621
} |
{-# OPTIONS --without-K --safe #-}
{-
Properties and definitions regarding Morphisms of a category:
- Monomorphism
- Epimorphism
- Isomorphism
- (object) equivalence ('spelled' _≅_ ). Exported as the module ≅
-}
open import Categories.Category
module Categories.Morphism {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level
open import Relation.Binary hiding (_⇒_)
open import Categories.Morphism.Reasoning.Core 𝒞
open Category 𝒞
private
variable
A B C : Obj
Mono : ∀ (f : A ⇒ B) → Set (o ⊔ ℓ ⊔ e)
Mono {A = A} f = ∀ {C} → (g₁ g₂ : C ⇒ A) → f ∘ g₁ ≈ f ∘ g₂ → g₁ ≈ g₂
Epi : ∀ (f : A ⇒ B) → Set (o ⊔ ℓ ⊔ e)
Epi {B = B} f = ∀ {C} → (g₁ g₂ : B ⇒ C) → g₁ ∘ f ≈ g₂ ∘ f → g₁ ≈ g₂
record Iso (from : A ⇒ B) (to : B ⇒ A) : Set e where
field
isoˡ : to ∘ from ≈ id
isoʳ : from ∘ to ≈ id
infix 4 _≅_
record _≅_ (A B : Obj) : Set (ℓ ⊔ e) where
field
from : A ⇒ B
to : B ⇒ A
iso : Iso from to
open Iso iso public
-- don't pollute the name space too much
private
≅-refl : Reflexive _≅_
≅-refl = record
{ from = id
; to = id
; iso = record
{ isoˡ = identityˡ
; isoʳ = identityʳ
}
}
≅-sym : Symmetric _≅_
≅-sym A≅B = record
{ from = to
; to = from
; iso = record
{ isoˡ = isoʳ
; isoʳ = isoˡ
}
}
where open _≅_ A≅B
≅-trans : Transitive _≅_
≅-trans A≅B B≅C = record
{ from = from B≅C ∘ from A≅B
; to = to A≅B ∘ to B≅C
; iso = record
{ isoˡ = begin
(to A≅B ∘ to B≅C) ∘ from B≅C ∘ from A≅B ≈⟨ cancelInner (isoˡ B≅C) ⟩
to A≅B ∘ from A≅B ≈⟨ isoˡ A≅B ⟩
id ∎
; isoʳ = begin
(from B≅C ∘ from A≅B) ∘ to A≅B ∘ to B≅C ≈⟨ cancelInner (isoʳ A≅B) ⟩
from B≅C ∘ to B≅C ≈⟨ isoʳ B≅C ⟩
id ∎
}
}
where open _≅_
open HomReasoning
open Equiv
≅-isEquivalence : IsEquivalence _≅_
≅-isEquivalence = record
{ refl = ≅-refl
; sym = ≅-sym
; trans = ≅-trans
}
-- But make accessing it easy:
module ≅ = IsEquivalence ≅-isEquivalence
≅-setoid : Setoid _ _
≅-setoid = record
{ Carrier = Obj
; _≈_ = _≅_
; isEquivalence = ≅-isEquivalence
}
| {
"alphanum_fraction": 0.5002169197,
"avg_line_length": 22.3786407767,
"ext": "agda",
"hexsha": "be2fc2c75a389c8acc24142fbf60a3ad993c98f2",
"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/Morphism.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/Morphism.agda",
"max_line_length": 75,
"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/Morphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 943,
"size": 2305
} |
------------------------------------------------------------------------
-- Code related to the paper
-- "Operational Semantics Using the Partiality Monad"
--
-- Nils Anders Danielsson
------------------------------------------------------------------------
-- Several definitions and proofs in this code are closely related to
-- definitions and proofs in the paper "Coinductive big-step
-- operational semantics" by Leroy and Grall. See my paper for more
-- detailed references to related work, and also for more explanations
-- of how the code works.
module Operational-semantics-using-the-partiality-monad where
------------------------------------------------------------------------
-- Section 2
-- Fin.
import Data.Fin
-- Vec, lookup.
import Data.Vec
-- The partiality monad.
import Category.Monad.Partiality
-- A variant of trivial, as well as proofs showing that the definition
-- of weak bisimilarity in the paper coincides with Capretta's
-- definition and a more standard definition based on weak
-- bisimulations.
import AdmissibleButNotPostulable
------------------------------------------------------------------------
-- Section 3
-- Tm, Env, Value.
import Lambda.Syntax
-- Big-step functional semantics, Ω.
import Lambda.Closure.Functional
-- The module above uses some workarounds in order to convince Agda
-- that the code is productive. The following module contains (more or
-- less) the same code without the workarounds, but is checked with
-- the termination checker turned off.
import Lambda.Closure.Functional.No-workarounds
-- An alternative definition of the functional semantics. This
-- definition uses continuation-passing style instead of bind.
import Lambda.Closure.Functional.Alternative
------------------------------------------------------------------------
-- Section 4
-- Type system.
import Lambda.Syntax
-- Type soundness.
import Lambda.Closure.Functional.Type-soundness
-- The use of Lift in the paper is replaced by the use of two
-- different predicate transformers: Any for Maybe and All for the
-- partiality monad.
import Data.Maybe
import Category.Monad.Partiality.All
-- An alternative definition of the functional semantics, using
-- substitutions instead of environments and closures, plus a proof of
-- type soundness.
import Lambda.Substitution.Functional
------------------------------------------------------------------------
-- Section 5
-- The relational semantics.
import Lambda.Closure.Relational
-- Proofs of equivalence.
import Lambda.Closure.Equivalence
------------------------------------------------------------------------
-- Section 6
-- The virtual machine. Two semantics are given, one relational and
-- one functional, and they are proved to be equivalent.
import Lambda.VirtualMachine
------------------------------------------------------------------------
-- Section 7
-- The compiler.
import Lambda.VirtualMachine
-- Compiler correctness for the functional semantics.
import Lambda.Closure.Functional
import Lambda.Closure.Functional.No-workarounds
-- Compiler correctness for the relational semantics.
import Lambda.Closure.Relational
------------------------------------------------------------------------
-- Section 8
-- The non-deterministic language along with a compiler and a compiler
-- correctness proof, as well as a type soundness proof.
import Lambda.Closure.Functional.Non-deterministic
import Lambda.Closure.Functional.Non-deterministic.No-workarounds
------------------------------------------------------------------------
-- Section 9
-- A very brief treatment of different kinds of term equivalences,
-- including contextual equivalence and applicative bisimilarity.
import Lambda.Closure.Equivalences
-- _⇓.
import Category.Monad.Partiality
| {
"alphanum_fraction": 0.631467793,
"avg_line_length": 27.0571428571,
"ext": "agda",
"hexsha": "cb312041da770ba57b394cb6de036f232cbc4b7b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Operational-semantics-using-the-partiality-monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "Operational-semantics-using-the-partiality-monad.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Operational-semantics-using-the-partiality-monad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 693,
"size": 3788
} |
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
{-# OPTIONS --allow-exec #-}
open import Vehicle
open import Data.Integer as ℤ using (ℤ)
open import Data.Rational as ℚ using (ℚ)
module simple-untypedDecls-temp-output where
fin3 : ∀ {_x0 : Set} {{_x1 : HasNatLits _x0}} → _x0
fin3 = 3
intMinus3 : ∀ {_x4 : Set} {{_x5 : HasNatLits _x4}} {{_x6 : HasNeg _x4}} → _x4
intMinus3 = - 3
ratMinus3 : ∀ {_x10 : Set} {{_x11 : HasRatLits _x10}} {{_x12 : HasNeg _x10}} → _x10
ratMinus3 = - (ℤ.+ 3 ℚ./ 1) | {
"alphanum_fraction": 0.6521060842,
"avg_line_length": 27.8695652174,
"ext": "agda",
"hexsha": "f0229d5ffe60bcfd2e4e8eda8ba0952e657259c0",
"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": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vehicle-lang/vehicle",
"max_forks_repo_path": "test/Test/Compile/Golden/simple-untypedDecls/simple-untypedDecls-output.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T20:49:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-07T14:09:13.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vehicle-lang/vehicle",
"max_issues_repo_path": "test/Test/Compile/Golden/simple-untypedDecls/simple-untypedDecls-output.agda",
"max_line_length": 83,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vehicle-lang/vehicle",
"max_stars_repo_path": "test/Test/Compile/Golden/simple-untypedDecls/simple-untypedDecls-output.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-17T18:51:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-10T12:56:42.000Z",
"num_tokens": 246,
"size": 641
} |
module ListTest where
import AlonzoPrelude
import PreludeList
open AlonzoPrelude
open PreludeList
mynil : {A:Set} -> List A
mynil = []
mycons : {A:Set} -> A -> List A -> List A
mycons x xs = x :: xs
head : (A:Set) -> List A -> A
head A (x :: xs) = x
| {
"alphanum_fraction": 0.6403162055,
"avg_line_length": 16.8666666667,
"ext": "agda",
"hexsha": "e67bcd42bc08fd38afc53c3cbf843d01f455f4ee",
"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": "examples/outdated-and-incorrect/Alonzo/ListTest.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": "examples/outdated-and-incorrect/Alonzo/ListTest.agda",
"max_line_length": 41,
"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": "examples/outdated-and-incorrect/Alonzo/ListTest.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": 91,
"size": 253
} |
module Prelude.Word where
import Agda.Builtin.Word as Word
open import Prelude.Nat
open import Prelude.Number
open import Prelude.Semiring
open import Prelude.Equality
open import Prelude.Equality.Unsafe
open import Prelude.Ord
open import Prelude.Unit
open import Prelude.Function
open import Prelude.Decidable
open Word public using (Word64) renaming (primWord64ToNat to word64ToNat;
primWord64FromNat to word64FromNat)
open Word
private
2⁶⁴ : Nat
2⁶⁴ = 18446744073709551616
{-# INLINE 2⁶⁴ #-}
inv-word64ToNat : ∀ {a} → word64FromNat (word64ToNat a) ≡ a
inv-word64ToNat = unsafeEqual
emb-word64FromNat : ∀ n → word64ToNat (word64FromNat n) ≡ n mod 2⁶⁴
emb-word64FromNat n = unsafeEqual
inj-word64ToNat : ∀ {a b} → word64ToNat a ≡ word64ToNat b → a ≡ b
inj-word64ToNat {a} {b} eq = eraseEquality (
a ≡⟨ inv-word64ToNat ⟩ʳ
word64FromNat (word64ToNat a)
≡⟨ word64FromNat $≡ eq ⟩
word64FromNat (word64ToNat b)
≡⟨ inv-word64ToNat ⟩
b ∎)
instance
NumWord64 : Number Word64
Number.Constraint NumWord64 _ = ⊤
fromNat {{NumWord64}} n = word64FromNat n
EqWord64 : Eq Word64
_==_ {{EqWord64}} a b =
case word64ToNat a == word64ToNat b of λ where
(yes _) → yes unsafeEqual
(no _) → no unsafeNotEqual
OrdWord64 : Ord Word64
OrdWord64 = OrdBy inj-word64ToNat
OrdLawsWord64 : Ord/Laws Word64
OrdLawsWord64 = OrdLawsBy inj-word64ToNat
-- Arithmetic --
private
natOp : (Nat → Nat → Nat) → Word64 → Word64 → Word64
natOp f a b = fromNat (f (word64ToNat a) (word64ToNat b))
{-# INLINE natOp #-}
add64 : Word64 → Word64 → Word64
add64 = natOp _+_
sub64 : Word64 → Word64 → Word64
sub64 = natOp λ a b → a + 2⁶⁴ - b
mul64 : Word64 → Word64 → Word64
mul64 = natOp _*_
{-# INLINE add64 #-}
{-# INLINE sub64 #-}
{-# INLINE mul64 #-}
NonZero64 : Word64 → Set
NonZero64 a = NonZero (word64ToNat a)
infixl 7 divWord64 modWord64
syntax divWord64 b a = a div64 b
divWord64 : (b : Word64) {{nz : NonZero64 b}} → Word64 → Word64
divWord64 b a = fromNat (word64ToNat a div word64ToNat b)
syntax modWord64 b a = a mod64 b
modWord64 : (b : Word64) {{nz : NonZero64 b}} → Word64 → Word64
modWord64 b a = fromNat (word64ToNat a mod word64ToNat b)
{-# INLINE divWord64 #-}
{-# INLINE modWord64 #-}
instance
SemiringWord64 : Semiring Word64
Semiring.zro SemiringWord64 = 0
Semiring.one SemiringWord64 = 1
Semiring._+_ SemiringWord64 = add64
Semiring._*_ SemiringWord64 = mul64
NegWord64 : Negative Word64
Negative.Constraint NegWord64 _ = ⊤
fromNeg {{NegWord64}} n = sub64 0 (fromNat n)
SubWord64 : Subtractive Word64
_-_ {{SubWord64}} = sub64
negate {{SubWord64}} = sub64 0
| {
"alphanum_fraction": 0.6952487008,
"avg_line_length": 25.4150943396,
"ext": "agda",
"hexsha": "4daa3027f8bae65377ab57aba428181b600f5116",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Prelude/Word.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Prelude/Word.agda",
"max_line_length": 77,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Prelude/Word.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 939,
"size": 2694
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Maybe where
open import Cubical.Data.Maybe.Base public
open import Cubical.Data.Maybe.Properties public
| {
"alphanum_fraction": 0.7727272727,
"avg_line_length": 29.3333333333,
"ext": "agda",
"hexsha": "babc11325db33713927d7c19a906526f4f86b2d0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/Maybe.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/Maybe.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/Maybe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 39,
"size": 176
} |
-- 2011-09-09, submitted by [email protected]
-- This bug report wins the first price in the false golfing tournament!
-- {-# OPTIONS -v term:20 #-}
module Issue444 where
data ⊥ : Set where
relevant : .⊥ → ⊥
relevant ()
false : ⊥
false = relevant false
| {
"alphanum_fraction": 0.6718146718,
"avg_line_length": 19.9230769231,
"ext": "agda",
"hexsha": "39e37311d24846dd264f6116a3a5e77d5800531f",
"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/Issue444.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/Issue444.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue444.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": 79,
"size": 259
} |
{-# OPTIONS --prop --rewriting #-}
open import Examples.Sorting.Sequential.Comparable
module Examples.Sorting.Sequential.Core (M : Comparable) where
open import Calf.CostMonoid
open CostMonoid costMonoid
hiding (zero; _+_; _≤_; ≤-refl; ≤-trans) public
open import Examples.Sorting.Core costMonoid fromℕ M public
| {
"alphanum_fraction": 0.7672955975,
"avg_line_length": 26.5,
"ext": "agda",
"hexsha": "9c2eb0830bb515451584898ad0df57b3ee0a8400",
"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/Sorting/Sequential/Core.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/Sorting/Sequential/Core.agda",
"max_line_length": 62,
"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/Sorting/Sequential/Core.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": 85,
"size": 318
} |
module E where
t : Set -> Set
t x = x
| {
"alphanum_fraction": 0.55,
"avg_line_length": 10,
"ext": "agda",
"hexsha": "5da13d9fa7d80ac3d577ab40e064b0fb67efb04c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/E.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/E.agda",
"max_line_length": 15,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/E.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 15,
"size": 40
} |
module Term (Gnd : Set)(U : Set)(El : U -> Set) where
open import Basics
open import Pr
open import Nom
import Kind
open module KindGUEl = Kind Gnd U El
import Loc
open module LocK = Loc Kind
import Cxt
open module CxtK = Cxt Kind
data Jud : Set where
Term : Kind -> Jud
Args : Kind -> Gnd -> Jud
Head : Jud
data _[_]-_ : Loc -> Jud -> Kind -> Set where
[_] : {C : Kind}{L : Loc}{Z : Gnd} ->
L [ Args C Z ]- C -> L [ Term C ]- Ty Z
fn : {C : Kind}{L : Loc}(A : U){K : El A -> Kind} ->
((x : El A) -> L [ Term C ]- K x) -> L [ Term C ]- Pi A K
\\ : {C : Kind}{L : Loc}{S T : Kind} ->
(L * S) [ Term C ]- T -> L [ Term C ]- (S |> T)
_^_ : {C : Kind}{L : Loc}{Z : Gnd}{A : U}{K : El A -> Kind} ->
(x : El A) -> L [ Args C Z ]- K x -> L [ Args C Z ]- Pi A K
_&_ : {C : Kind}{L : Loc}{S T : Kind}{Z : Gnd} ->
L [ Term C ]- S -> L [ Args C Z ]- T -> L [ Args C Z ]- (S |> T)
nil : {C : Kind}{L : Loc}{Z : Gnd} -> L [ Args C Z ]- Ty Z
_$_ : {C : Kind}{L : Loc}{T : Kind}{Z : Gnd} ->
L [ Head ]- T -> L [ Args C Z ]- T -> L [ Term C ]- Ty Z
` : Nom -> {S : Kind}{L : Loc} -> L [ Head ]- S
# : {L : Loc}{S : Kind} -> L ! S -> L [ Head ]- S
infixr 90 _^_ _&_
infix 40 _[_]-_
Good : Cxt -> {L : Loc}{j : Jud}{T : Kind} -> L [ j ]- T -> Pr
Good G [ c ] = Good G c
Good G (fn A f) = all (El A) \a -> Good G (f a)
Good G (\\ b) = Good G b
Good G (a ^ ss) = Good G ss
Good G (s & ss) = Good G s /\ Good G ss
Good G nil = tt
Good G (x $ ss) = Good G x /\ Good G ss
Good G (` x {S}) = GooN G S x
Good G (# v) = tt
data _[_/_]-_ (G : Cxt)(L : Loc)(j : Jud)(T : Kind) : Set where
_-!_ : (t : L [ j ]- T) -> [| Good G t |] -> G [ L / j ]- T
gtm : {G : Cxt}{L : Loc}{j : Jud}{T : Kind} -> G [ L / j ]- T -> L [ j ]- T
gtm (t -! _) = t
good : {G : Cxt}{L : Loc}{j : Jud}{T : Kind}
(t : G [ L / j ]- T) -> [| Good G (gtm t) |]
good (t -! g) = g
_[!_!]-_ : Cxt -> Kind -> Kind -> Set
G [! C !]- T = G [ EL / Term C ]- T
G[_] : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd} ->
G [ L / Args C Z ]- C ->
----------------------------
G [ L / Term C ]- Ty Z
G[ c -! cg ] = [ c ] -! cg
Gfn : {G : Cxt}{C : Kind}{L : Loc}(A : U){K : El A -> Kind} ->
((x : El A) -> G [ L / Term C ]- K x) ->
-------------------------------------------
G [ L / Term C ]- Pi A K
Gfn A f = fn A (gtm o f) -! (good o f)
G\\ : {G : Cxt}{C : Kind}{L : Loc}{S T : Kind} ->
G [ L * S / Term C ]- T ->
------------------------------
G [ L / Term C ]- (S |> T)
G\\ (b -! bg) = \\ b -! bg
_G^_ : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd}{A : U}{K : El A -> Kind} ->
(x : El A) ->
G [ L / Args C Z ]- K x ->
------------------------------
G [ L / Args C Z ]- Pi A K
a G^ (s -! sg) = (a ^ s) -! sg
_G&_ : {G : Cxt}{C : Kind}{L : Loc}{S T : Kind}{Z : Gnd} ->
G [ L / Term C ]- S ->
G [ L / Args C Z ]- T ->
----------------------------------
G [ L / Args C Z ]- (S |> T)
(r -! rg) G& (s -! sg) = (r & s) -! (rg , sg)
Gnil : {G : Cxt}{C : Kind}{L : Loc}{Z : Gnd} ->
-----------------------------
G [ L / Args C Z ]- Ty Z
Gnil = nil -! _
_G$_ : {G : Cxt}{C : Kind}{L : Loc}{T : Kind}{Z : Gnd} ->
G [ L / Head ]- T ->
G [ L / Args C Z ]- T ->
-----------------------------
G [ L / Term C ]- Ty Z
(h -! hg) G$ (s -! sg) = (h $ s) -! (hg , sg)
G` : {G : Cxt}{S : Kind}{L : Loc} -> Nom :- GooN G S ->
------------------------------------------------------
G [ L / Head ]- S
G` [ x / xg ] = ` x -! xg
G# : {G : Cxt}{L : Loc}{S : Kind} -> L ! S ->
--------------------------
G [ L / Head ]- S
G# v = # v -! _
infixr 90 _G^_ _G&_
| {
"alphanum_fraction": 0.3577472237,
"avg_line_length": 29.3178294574,
"ext": "agda",
"hexsha": "a682d0671f96d22382c02e1f4c4eeccdb30cb3c0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "benchmark/Syntacticosmos/Term.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": "benchmark/Syntacticosmos/Term.agda",
"max_line_length": 76,
"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": "benchmark/Syntacticosmos/Term.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": 1526,
"size": 3782
} |
module Base.Prelude.Integer where
open import Data.Nat using (ℕ; zero; suc)
open import Data.Integer using (+_; -_) renaming (ℤ to ℤᵖ; _+_ to _+ᵖ_; _-_ to _-ᵖ_; _*_ to _*ᵖ_)
open import Data.Integer.Properties using (_≤?_; _<?_) renaming (_≟_ to _≟ᵖ_)
open import Relation.Nullary.Decidable using (⌊_⌋)
-- Imports for literals.
open import Agda.Builtin.FromNat
open import Agda.Builtin.FromNeg
open import Agda.Builtin.FromNat public
open import Base.Free using (Free; pure; impure; _>>=_)
open import Base.Partial using (Partial; error)
open import Base.Prelude.Bool using (𝔹; not)
open import Base.Prelude.Unit using (⊤ᵖ)
ℤ : (Shape : Set) → (Shape → Set) → Set
ℤ _ _ = ℤᵖ
_+_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (ℤ S P)
mx + my = mx >>= λ x → my >>= λ y → pure (x +ᵖ y)
_-_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (ℤ S P)
mx - my = mx >>= λ x → my >>= λ y → pure (x -ᵖ y)
_*_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (ℤ S P)
mx * my = mx >>= λ x → my >>= λ y → pure (x *ᵖ y)
_≤_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)
mx ≤ my = mx >>= λ x → my >>= λ y → pure ⌊ x ≤? y ⌋
_<_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)
mx < my = mx >>= λ x → my >>= λ y → pure ⌊ x <? y ⌋
_>_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)
mx > my = my ≤ mx
_≥_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)
mx ≥ my = my < mx
_≟_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)
mx ≟ my = mx >>= λ x → my >>= λ y → pure ⌊ x ≟ᵖ y ⌋
_≠_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)
mx ≠ my = not (mx ≟ my)
instance
number : Number ℤᵖ
number = record
{ Constraint = λ _ → ⊤ᵖ
; fromNat = λ n → + n
}
negative : Negative ℤᵖ
negative = record
{ Constraint = λ _ → ⊤ᵖ
; fromNeg = λ n → - (+ n)
}
_^ᵖ_ : ℤᵖ → ℕ → ℤᵖ
b ^ᵖ 0 = 1
b ^ᵖ suc e = b *ᵖ (b ^ᵖ e)
-- If it encounters a negative exponent the Haskell implementation of @(^)@ raises an exception using @errorWithoutStackTrace@.
_^_ : ∀ {S P} → ⦃ Partial S P ⦄ → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (ℤ S P)
mb ^ me = me >>= λ where
(ℤᵖ.negsuc _) → error "Negative exponent"
(+ 0) → pure 1
(+ (suc e)) → mb >>= λ b → pure (b ^ᵖ suc e)
neg : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P)
neg x = pure -1 * x
| {
"alphanum_fraction": 0.5125748503,
"avg_line_length": 33.4,
"ext": "agda",
"hexsha": "56040a565b29ca879b6c33b5e9845a228d5782b3",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T07:48:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-08T11:23:46.000Z",
"max_forks_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "FreeProving/free-compiler",
"max_forks_repo_path": "base/agda/Base/Prelude/Integer.agda",
"max_issues_count": 120,
"max_issues_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_issues_repo_issues_event_max_datetime": "2020-12-08T07:46:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-04-09T09:40:39.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "FreeProving/free-compiler",
"max_issues_repo_path": "base/agda/Base/Prelude/Integer.agda",
"max_line_length": 127,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "FreeProving/free-compiler",
"max_stars_repo_path": "base/agda/Base/Prelude/Integer.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-21T13:38:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-06T11:03:34.000Z",
"num_tokens": 1080,
"size": 2505
} |
------------------------------------------------------------------------
-- Partiality algebras
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
module Partiality-algebra where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (id; T) renaming (_∘_ to _⊚_)
open import Bijection equality-with-J as Bijection using (_↔_)
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import Univalence-axiom equality-with-J
------------------------------------------------------------------------
-- Partiality algebras
-- Partiality algebras for certain universe levels and types, with a
-- certain underlying type (T).
record Partiality-algebra-with
{a p} (T : Type p) q (A : Type a) : Type (a ⊔ p ⊔ lsuc q) where
-- A binary relation on the type.
infix 4 _⊑_ _⊒_
field
_⊑_ : T → T → Type q
_⊒_ : T → T → Type q
_⊒_ x y = y ⊑ x
-- Increasing sequences.
Increasing-sequence : Type (p ⊔ q)
Increasing-sequence = ∃ λ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n)
-- Projection functions for Increasing-sequence.
infix 30 _[_]
_[_] : Increasing-sequence → ℕ → T
_[_] s n = proj₁ s n
increasing : (s : Increasing-sequence) →
∀ n → (s [ n ]) ⊑ (s [ suc n ])
increasing = proj₂
-- Upper bounds.
Is-upper-bound : Increasing-sequence → T → Type q
Is-upper-bound s x = ∀ n → (s [ n ]) ⊑ x
field
-- T "constructors".
never : T
now : A → T
⨆ : Increasing-sequence → T
antisymmetry : ∀ {x y} → x ⊑ y → y ⊑ x → x ≡ y
-- We have chosen to explicitly make the type set-truncated.
-- However, this "constructor" is not used anywhere in the
-- development (except when partiality algebras are modified, see
-- for instance equality-characterisation-Partiality-algebra-with₁
-- or Partiality-algebra.Pi.Π-with).
T-is-set-unused : Is-set T
-- _⊑_ "constructors".
⊑-refl : ∀ x → x ⊑ x
⊑-trans : ∀ {x y z} → x ⊑ y → y ⊑ z → x ⊑ z
never⊑ : ∀ x → never ⊑ x
upper-bound : ∀ s → Is-upper-bound s (⨆ s)
least-upper-bound : ∀ s ub → Is-upper-bound s ub → ⨆ s ⊑ ub
⊑-propositional : ∀ {x y} → Is-proposition (x ⊑ y)
----------------------------------------------------------------------
-- Some simple consequences
private
-- A lemma.
T-is-set-and-equality-characterisation : Is-set T × _
T-is-set-and-equality-characterisation =
Eq.propositional-identity≃≡
(λ x y → x ⊑ y × y ⊑ x)
(λ _ _ → ×-closure 1 ⊑-propositional ⊑-propositional)
(λ x → ⊑-refl x , ⊑-refl x)
(λ x y → uncurry {B = λ _ → y ⊑ x} antisymmetry)
-- T is a set. (This lemma is analogous to Theorem 11.3.9 in
-- "Homotopy Type Theory: Univalent Foundations of Mathematics"
-- (first edition).)
T-is-set : Is-set T
T-is-set = proj₁ T-is-set-and-equality-characterisation
-- Equality characterisation lemma for T.
equality-characterisation-T :
∀ {x y} → (x ⊑ y × y ⊑ x) ≃ (x ≡ y)
equality-characterisation-T =
proj₂ T-is-set-and-equality-characterisation ext
-- Equality characterisation lemma for increasing sequences.
equality-characterisation-increasing :
∀ {s₁ s₂} → (∀ n → s₁ [ n ] ≡ s₂ [ n ]) ↔ s₁ ≡ s₂
equality-characterisation-increasing {s₁} {s₂} =
(∀ n → s₁ [ n ] ≡ s₂ [ n ]) ↔⟨ Eq.extensionality-isomorphism bad-ext ⟩
proj₁ s₁ ≡ proj₁ s₂ ↝⟨ ignore-propositional-component
(Π-closure ext 1 λ _ →
⊑-propositional) ⟩□
s₁ ≡ s₂ □
-- Partiality algebras for certain universe levels and types.
record Partiality-algebra {a} p q (A : Type a) :
Type (a ⊔ lsuc (p ⊔ q)) where
constructor ⟨_⟩
field
-- A type.
{T} : Type p
-- A partiality-algebra with that type as the underlying type.
partiality-algebra-with : Partiality-algebra-with T q A
open Partiality-algebra-with partiality-algebra-with public
------------------------------------------------------------------------
-- Partiality algebra morphisms
-- Morphisms from one partiality algebra to another.
record Morphism {a p₁ p₂ q₁ q₂} {A : Type a}
(P₁ : Partiality-algebra p₁ q₁ A)
(P₂ : Partiality-algebra p₂ q₂ A) :
Type (a ⊔ p₁ ⊔ p₂ ⊔ q₁ ⊔ q₂) where
private
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
field
function : P₁.T → P₂.T
monotone : ∀ {x y} → x P₁.⊑ y → function x P₂.⊑ function y
sequence-function : P₁.Increasing-sequence → P₂.Increasing-sequence
sequence-function = Σ-map (function ⊚_) (monotone ⊚_)
field
strict : function P₁.never ≡ P₂.never
now-to-now : ∀ x → function (P₁.now x) ≡ P₂.now x
ω-continuous : ∀ s → function (P₁.⨆ s) ≡ P₂.⨆ (sequence-function s)
-- An identity morphism.
id :
∀ {a p q} {A : Type a} {P : Partiality-algebra p q A} →
Morphism P P
id = record
{ function = Prelude.id
; monotone = Prelude.id
; strict = refl
; now-to-now = λ _ → refl
; ω-continuous = λ _ → refl
}
-- Composition of morphisms.
_∘_ : ∀ {a p₁ p₂ p₃ q₁ q₂ q₃} {A : Type a}
{P₁ : Partiality-algebra p₁ q₁ A}
{P₂ : Partiality-algebra p₂ q₂ A}
{P₃ : Partiality-algebra p₃ q₃ A} →
Morphism P₂ P₃ → Morphism P₁ P₂ → Morphism P₁ P₃
_∘_ {P₁ = P₁} {P₂} {P₃} m₁ m₂ = record
{ function = function m₁ ⊚ function m₂
; monotone = monotone m₁ ⊚ monotone m₂
; strict = function m₁ (function m₂ (never P₁)) ≡⟨ cong (function m₁) (strict m₂) ⟩
function m₁ (never P₂) ≡⟨ strict m₁ ⟩∎
never P₃ ∎
; now-to-now = λ x →
function m₁ (function m₂ (now P₁ x)) ≡⟨ cong (function m₁) (now-to-now m₂ x) ⟩
function m₁ (now P₂ x) ≡⟨ now-to-now m₁ x ⟩∎
now P₃ x ∎
; ω-continuous = λ s →
function m₁ (function m₂ (⨆ P₁ s)) ≡⟨ cong (function m₁) (ω-continuous m₂ s) ⟩
function m₁ (⨆ P₂ (sequence-function m₂ s)) ≡⟨ ω-continuous m₁ (sequence-function m₂ s) ⟩∎
⨆ P₃ (sequence-function m₁ (sequence-function m₂ s)) ∎
}
where
open Morphism
open Partiality-algebra
-- Is-morphism-with P Q f holds if f is a morphism from P to Q.
Is-morphism-with :
∀ {a p₁ p₂ q₁ q₂} {T₁ : Type p₁} {T₂ : Type p₂} {A : Type a}
(P₁ : Partiality-algebra-with T₁ q₁ A)
(P₂ : Partiality-algebra-with T₂ q₂ A) →
(T₁ → T₂) → Type _
Is-morphism-with P₁ P₂ f =
∃ λ (m : ∀ {x y} → x P₁.⊑ y → f x P₂.⊑ f y) →
f P₁.never ≡ P₂.never
×
(∀ x → f (P₁.now x) ≡ P₂.now x)
×
(∀ s → f (P₁.⨆ s) ≡ P₂.⨆ (Σ-map (f ⊚_) (m ⊚_) s))
where
module P₁ = Partiality-algebra-with P₁
module P₂ = Partiality-algebra-with P₂
-- Is-morphism P Q f holds if f is a morphism from P to Q.
Is-morphism :
let open Partiality-algebra in
∀ {a p₁ p₂ q₁ q₂} {A : Type a}
(P₁ : Partiality-algebra p₁ q₁ A) (P₂ : Partiality-algebra p₂ q₂ A) →
(T P₁ → T P₂) → Type _
Is-morphism P₁ P₂ =
Is-morphism-with P₁.partiality-algebra-with
P₂.partiality-algebra-with
where
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
-- An alternative definition of morphisms.
Morphism-as-Σ :
∀ {a p₁ p₂ q₁ q₂} {A : Type a} →
Partiality-algebra p₁ q₁ A → Partiality-algebra p₂ q₂ A → Type _
Morphism-as-Σ P₁ P₂ =
∃ λ (f : P₁.T → P₂.T) → Is-morphism P₁ P₂ f
where
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
-- The two definitions are isomorphic.
Morphism↔Morphism-as-Σ :
∀ {a p₁ p₂ q₁ q₂} {A : Type a}
{P₁ : Partiality-algebra p₁ q₁ A}
{P₂ : Partiality-algebra p₂ q₂ A} →
Morphism P₁ P₂ ↔ Morphism-as-Σ P₁ P₂
Morphism↔Morphism-as-Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ m → function m
, monotone m
, strict m
, now-to-now m
, ω-continuous m
; from = λ { (f , m , s , n , ω) → record
{ function = f
; monotone = m
; strict = s
; now-to-now = n
; ω-continuous = ω
}
}
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
}
where
open Morphism
abstract
-- Is-morphism-with is pointwise propositional.
Is-morphism-with-propositional :
let open Partiality-algebra in
∀ {a p₁ p₂ q₁ q₂} {T₁ : Type p₁} {T₂ : Type p₂} {A : Type a}
(P₁ : Partiality-algebra-with T₁ q₁ A)
(P₂ : Partiality-algebra-with T₂ q₂ A)
{f : T₁ → T₂} →
Is-proposition (Is-morphism-with P₁ P₂ f)
Is-morphism-with-propositional _ P₂ =
Σ-closure 1 (implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
P₂.⊑-propositional) λ _ →
×-closure 1 P₂.T-is-set $
×-closure 1 (Π-closure ext 1 λ _ →
P₂.T-is-set) $
Π-closure ext 1 λ _ →
P₂.T-is-set
where
module P₂ = Partiality-algebra-with P₂
-- Is-morphism is pointwise propositional.
Is-morphism-propositional :
let open Partiality-algebra in
∀ {a p₁ p₂ q₁ q₂} {A : Type a}
(P₁ : Partiality-algebra p₁ q₁ A)
(P₂ : Partiality-algebra p₂ q₂ A)
{f : T P₁ → T P₂} →
Is-proposition (Is-morphism P₁ P₂ f)
Is-morphism-propositional P₁ P₂ =
Is-morphism-with-propositional
P₁.partiality-algebra-with
P₂.partiality-algebra-with
where
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
-- An equality characterisation lemma for morphisms.
equality-characterisation-Morphism :
∀ {a p₁ p₂ q₁ q₂} {A : Type a}
{P₁ : Partiality-algebra p₁ q₁ A}
{P₂ : Partiality-algebra p₂ q₂ A} →
{m₁ m₂ : Morphism P₁ P₂} →
Morphism.function m₁ ≡ Morphism.function m₂
↔
m₁ ≡ m₂
equality-characterisation-Morphism {P₁ = P₁} {P₂} {m₁} {m₂} =
function m₁ ≡ function m₂ ↝⟨ ignore-propositional-component (Is-morphism-propositional P₁ P₂) ⟩
_↔_.to Morphism↔Morphism-as-Σ m₁ ≡ _↔_.to Morphism↔Morphism-as-Σ m₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Morphism↔Morphism-as-Σ) ⟩□
m₁ ≡ m₂ □
where
open Morphism
-- The type of morphisms is a set.
Morphism-set :
∀ {a p₁ p₂ q₁ q₂} {A : Type a}
{P₁ : Partiality-algebra p₁ q₁ A}
{P₂ : Partiality-algebra p₂ q₂ A} →
Is-set (Morphism P₁ P₂)
Morphism-set {P₂ = P₂} =
H-level.respects-surjection
(_↔_.surjection equality-characterisation-Morphism)
1
(Π-closure ext 2 λ _ → T-is-set P₂)
where
open Partiality-algebra
| {
"alphanum_fraction": 0.5545373665,
"avg_line_length": 31.9318181818,
"ext": "agda",
"hexsha": "354d18f10f2f45c5e02d90efde17b9395ee02018",
"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": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-algebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"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/partiality-monad",
"max_issues_repo_path": "src/Partiality-algebra.agda",
"max_line_length": 142,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-algebra.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 3727,
"size": 11240
} |
------------------------------------------------------------------------------
-- Twice funcion
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Twice where
open import LTC-PCF.Base
------------------------------------------------------------------------------
twice : (D → D) → D → D
twice f x = f (f x)
twice-succ : ∀ n → twice succ₁ n ≡ succ₁ (succ₁ n)
twice-succ n = refl
| {
"alphanum_fraction": 0.3322203673,
"avg_line_length": 28.5238095238,
"ext": "agda",
"hexsha": "11e312ff63cb6bede808733b4e56b820ff063975",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/thesis/report/LTC-PCF/Twice.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/thesis/report/LTC-PCF/Twice.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/thesis/report/LTC-PCF/Twice.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": 112,
"size": 599
} |
{- This example test that the order in which unification
constraints are generated doesn't matter. The pattern
matching in foo generates the unification problem
[x, zero] = [n + m, n]
with n and m flexible. The first equation can only be
solved after the second one has been solved. For completeness
we check that the other way around also works.
-}
module PostponedUnification where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
data T : Nat -> Nat -> Set where
t : (x : Nat) -> T x zero
foo : (n m : Nat) -> T (n + m) n -> Set
foo ._ ._ (t x) = Nat
data U : Nat -> Nat -> Set where
u : (x : Nat) -> U zero x
bar : (n m : Nat) -> U n (n + m) -> Set
bar ._ ._ (u x) = Nat
| {
"alphanum_fraction": 0.6002554278,
"avg_line_length": 24.46875,
"ext": "agda",
"hexsha": "d062795f2d3ea2daa3579a5fcdf5a2df2022a61a",
"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/PostponedUnification.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/PostponedUnification.agda",
"max_line_length": 65,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/PostponedUnification.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": 250,
"size": 783
} |
------------------------------------------------------------------------
-- Bijections
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Bijection
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open Derived-definitions-and-properties eq
open import Equality.Decision-procedures eq
open import H-level eq
open import Injection eq using (Injective; _↣_)
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id) renaming (_∘_ to _⊚_)
open import Surjection eq as Surjection using (_↠_; module _↠_)
------------------------------------------------------------------------
-- Bijections
infix 0 _↔_
record _↔_ {f t} (From : Type f) (To : Type t) : Type (f ⊔ t) where
field
surjection : From ↠ To
open _↠_ surjection
field
left-inverse-of : ∀ x → from (to x) ≡ x
injective : Injective to
injective {x = x} {y = y} to-x≡to-y =
x ≡⟨ sym (left-inverse-of x) ⟩
from (to x) ≡⟨ cong from to-x≡to-y ⟩
from (to y) ≡⟨ left-inverse-of y ⟩∎
y ∎
injection : From ↣ To
injection = record
{ to = to
; injective = injective
}
-- A lemma.
to-from : ∀ {x y} → to x ≡ y → from y ≡ x
to-from {x} {y} to-x≡y =
from y ≡⟨ cong from $ sym to-x≡y ⟩
from (to x) ≡⟨ left-inverse-of x ⟩∎
x ∎
-- Every right inverse of to is pointwise equal to from.
right-inverse-unique :
(f : To → From) →
(∀ x → to (f x) ≡ x) →
(∀ x → f x ≡ from x)
right-inverse-unique _ right x = sym $ to-from (right x)
-- Every left inverse of from is pointwise equal to to.
left-inverse-of-from-unique :
(f : From → To) →
(∀ x → f (from x) ≡ x) →
(∀ x → f x ≡ to x)
left-inverse-of-from-unique f left x =
f x ≡⟨ cong f $ sym $ left-inverse-of _ ⟩
f (from (to x)) ≡⟨ left _ ⟩∎
to x ∎
open _↠_ surjection public
-- The type of quasi-inverses of a function (as defined in the HoTT
-- book).
Has-quasi-inverse :
∀ {a b} {A : Type a} {B : Type b} →
(A → B) → Type (a ⊔ b)
Has-quasi-inverse {A = A} {B = B} to =
∃ λ (from : B → A) →
(∀ x → to (from x) ≡ x) ×
(∀ x → from (to x) ≡ x)
-- An alternative characterisation of bijections.
↔-as-Σ :
∀ {a b} {A : Type a} {B : Type b} →
(A ↔ B) ↔ ∃ λ (f : A → B) → Has-quasi-inverse f
↔-as-Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ A↔B → _↔_.to A↔B
, _↔_.from A↔B
, _↔_.right-inverse-of A↔B
, _↔_.left-inverse-of A↔B
; from = λ (t , f , r , l) → record
{ surjection = record
{ logical-equivalence = record
{ to = t
; from = f
}
; right-inverse-of = r
}
; left-inverse-of = l
}
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
------------------------------------------------------------------------
-- Equivalence
-- _↔_ is an equivalence relation.
id : ∀ {a} {A : Type a} → A ↔ A
id = record
{ surjection = Surjection.id
; left-inverse-of = refl
}
inverse : ∀ {a b} {A : Type a} {B : Type b} → A ↔ B → B ↔ A
inverse A↔B = record
{ surjection = record
{ logical-equivalence = Logical-equivalence.inverse
logical-equivalence
; right-inverse-of = left-inverse-of
}
; left-inverse-of = right-inverse-of
} where open _↔_ A↔B
infixr 9 _∘_
_∘_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
B ↔ C → A ↔ B → A ↔ C
f ∘ g = record
{ surjection = Surjection._∘_ (surjection f) (surjection g)
; left-inverse-of = from∘to
}
where
open _↔_
from∘to : ∀ x → from g (from f (to f (to g x))) ≡ x
from∘to = λ x →
from g (from f (to f (to g x))) ≡⟨ cong (from g) (left-inverse-of f (to g x)) ⟩
from g (to g x) ≡⟨ left-inverse-of g x ⟩∎
x ∎
-- "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 □
------------------------------------------------------------------------
-- 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 A↔B f ≡f = record
{ surjection = record
{ logical-equivalence = record
{ to = f
; from = _↔_.from A↔B
}
; right-inverse-of = λ x →
f (_↔_.from A↔B x) ≡⟨ sym $ ≡f _ ⟩
_↔_.to A↔B (_↔_.from A↔B x) ≡⟨ _↔_.right-inverse-of A↔B _ ⟩∎
x ∎
}
; left-inverse-of = λ x →
_↔_.from A↔B (f x) ≡⟨ cong (_↔_.from A↔B) $ sym $ ≡f _ ⟩
_↔_.from A↔B (_↔_.to A↔B x) ≡⟨ _↔_.left-inverse-of A↔B _ ⟩∎
x ∎
}
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 ≡f =
inverse $ with-other-function (inverse A↔B) f ≡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 _
------------------------------------------------------------------------
-- More lemmas
-- Uninhabited types are isomorphic to the empty type.
⊥↔uninhabited : ∀ {a ℓ} {A : Type a} → ¬ A → ⊥ {ℓ = ℓ} ↔ A
⊥↔uninhabited ¬A = record
{ surjection = record
{ logical-equivalence = record
{ to = ⊥-elim
; from = ⊥-elim ⊚ ¬A
}
; right-inverse-of = ⊥-elim ⊚ ¬A
}
; left-inverse-of = λ ()
}
-- A lifted set is isomorphic to the underlying one.
↑↔ : ∀ {a b} {A : Type a} → ↑ b A ↔ A
↑↔ {b = b} {A} = record
{ surjection = record
{ logical-equivalence = record
{ to = lower
; from = lift
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Equality between pairs can be expressed as a pair of equalities.
Σ-≡,≡↔≡ : ∀ {a b} {A : Type a} {B : A → Type b} {p₁ p₂ : Σ A B} →
(∃ λ (p : proj₁ p₁ ≡ proj₁ p₂) →
subst B p (proj₂ p₁) ≡ proj₂ p₂) ↔
(p₁ ≡ p₂)
Σ-≡,≡↔≡ {A = A} {B} {p₁} {p₂} = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
from-P = λ {p₁ p₂ : Σ A B} (_ : p₁ ≡ p₂) →
∃ λ (p : proj₁ p₁ ≡ proj₁ p₂) →
subst B p (proj₂ p₁) ≡ proj₂ p₂
from : {p₁ p₂ : Σ A B} →
p₁ ≡ p₂ →
∃ λ (p : proj₁ p₁ ≡ proj₁ p₂) →
subst B p (proj₂ p₁) ≡ proj₂ p₂
from = Σ-≡,≡←≡
to : {p₁ p₂ : Σ A B} →
(∃ λ (p : proj₁ p₁ ≡ proj₁ p₂) →
subst B p (proj₂ p₁) ≡ proj₂ p₂) →
p₁ ≡ p₂
to = uncurry Σ-≡,≡→≡
abstract
to∘from : ∀ eq → to (from {p₁ = p₁} {p₂ = p₂} eq) ≡ eq
to∘from = elim (λ p≡q → to (from p≡q) ≡ p≡q) λ x →
let lem = subst-refl B (proj₂ x) in
to (from (refl x)) ≡⟨ cong to (elim-refl from-P _) ⟩
to (refl (proj₁ x) , lem) ≡⟨ Σ-≡,≡→≡-reflˡ _ ⟩
cong (_,_ (proj₁ x)) (trans (sym lem) lem) ≡⟨ cong (cong (_,_ (proj₁ x))) $ trans-symˡ lem ⟩
cong (_,_ (proj₁ x)) (refl (proj₂ x)) ≡⟨ cong-refl (_,_ (proj₁ x)) ⟩∎
refl x ∎
from∘to : ∀ p → from (to {p₁ = p₁} {p₂ = p₂} p) ≡ p
from∘to p = elim
(λ {x₁ x₂} x₁≡x₂ →
∀ {y₁ y₂} (y₁′≡y₂ : subst B x₁≡x₂ y₁ ≡ y₂) →
from (to (x₁≡x₂ , y₁′≡y₂)) ≡ (x₁≡x₂ , y₁′≡y₂))
(λ x {y₁} y₁′≡y₂ → elim
(λ {y₁ y₂} (y₁≡y₂ : y₁ ≡ y₂) →
(y₁′≡y₂ : subst B (refl x) y₁ ≡ y₂) →
y₁≡y₂ ≡ trans (sym $ subst-refl B y₁) y₁′≡y₂ →
from (to (refl x , y₁′≡y₂)) ≡ (refl x , y₁′≡y₂))
(λ y y′≡y eq →
let lem = subst-refl B y in
from (to (refl x , y′≡y)) ≡⟨ cong from $ Σ-≡,≡→≡-reflˡ _ ⟩
from (cong (_,_ x) (trans (sym lem) y′≡y)) ≡⟨ cong (from ⊚ cong (_,_ x)) $ sym eq ⟩
from (cong (_,_ x) (refl y)) ≡⟨ cong from $ cong-refl (_,_ x) ⟩
from (refl (x , y)) ≡⟨ elim-refl from-P _ ⟩
(refl x , lem) ≡⟨ cong (_,_ (refl x)) (
lem ≡⟨ sym $ trans-reflʳ _ ⟩
trans lem (refl _) ≡⟨ cong (trans lem) eq ⟩
trans lem (trans (sym lem) y′≡y) ≡⟨ sym $ trans-assoc _ _ _ ⟩
trans (trans lem (sym lem)) y′≡y ≡⟨ cong (λ p → trans p y′≡y) $ trans-symʳ lem ⟩
trans (refl _) y′≡y ≡⟨ trans-reflˡ _ ⟩∎
y′≡y ∎) ⟩∎
(refl x , y′≡y) ∎)
(trans (sym $ subst-refl B y₁) y₁′≡y₂)
y₁′≡y₂
(refl _))
(proj₁ p) (proj₂ p)
-- Equalities are closed, in a strong sense, under applications of
-- certain injections (at least inj₁ and inj₂).
≡↔inj₁≡inj₁ : ∀ {a b} {A : Type a} {B : Type b} {x y : A} →
(x ≡ y) ↔ _≡_ {A = A ⊎ B} (inj₁ x) (inj₁ y)
≡↔inj₁≡inj₁ {A = A} {B} {x} {y} = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
to : x ≡ y → _≡_ {A = A ⊎ B} (inj₁ x) (inj₁ y)
to = cong inj₁
from = ⊎.cancel-inj₁
abstract
to∘from : ∀ ix≡iy → to (from ix≡iy) ≡ ix≡iy
to∘from ix≡iy =
cong inj₁ (⊎.cancel-inj₁ ix≡iy) ≡⟨ cong-∘ inj₁ [ P.id , const x ] ix≡iy ⟩
cong f ix≡iy ≡⟨ cong-roughly-id f p ix≡iy _ _ f≡id ⟩
trans (refl _) (trans ix≡iy $ sym (refl _)) ≡⟨ trans-reflˡ _ ⟩
trans ix≡iy (sym $ refl _) ≡⟨ cong (trans ix≡iy) sym-refl ⟩
trans ix≡iy (refl _) ≡⟨ trans-reflʳ _ ⟩∎
ix≡iy ∎
where
f : A ⊎ B → A ⊎ B
f = inj₁ ⊚ [ P.id , const x ]
p : A ⊎ B → Bool
p = if_then true else false
f≡id : ∀ z → T (p z) → f z ≡ z
f≡id (inj₁ x) = const (refl (inj₁ x))
f≡id (inj₂ y) = ⊥-elim
from∘to : ∀ x≡y → from (to x≡y) ≡ x≡y
from∘to x≡y =
cong [ P.id , const x ] (cong inj₁ x≡y) ≡⟨ cong-∘ [ P.id , const x ] inj₁ _ ⟩
cong P.id x≡y ≡⟨ sym $ cong-id _ ⟩∎
x≡y ∎
≡↔inj₂≡inj₂ : ∀ {a b} {A : Type a} {B : Type b} {x y : B} →
(x ≡ y) ↔ _≡_ {A = A ⊎ B} (inj₂ x) (inj₂ y)
≡↔inj₂≡inj₂ {A = A} {B} {x} {y} = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
to : x ≡ y → _≡_ {A = A ⊎ B} (inj₂ x) (inj₂ y)
to = cong inj₂
from = ⊎.cancel-inj₂
abstract
to∘from : ∀ ix≡iy → to (from ix≡iy) ≡ ix≡iy
to∘from ix≡iy =
cong inj₂ (⊎.cancel-inj₂ ix≡iy) ≡⟨ cong-∘ inj₂ [ const x , P.id ] ix≡iy ⟩
cong f ix≡iy ≡⟨ cong-roughly-id f p ix≡iy _ _ f≡id ⟩
trans (refl _) (trans ix≡iy $ sym (refl _)) ≡⟨ trans-reflˡ _ ⟩
trans ix≡iy (sym $ refl _) ≡⟨ cong (trans ix≡iy) sym-refl ⟩
trans ix≡iy (refl _) ≡⟨ trans-reflʳ _ ⟩∎
ix≡iy ∎
where
f : A ⊎ B → A ⊎ B
f = inj₂ ⊚ [ const x , P.id ]
p : A ⊎ B → Bool
p = if_then false else true
f≡id : ∀ z → T (p z) → f z ≡ z
f≡id (inj₁ x) = ⊥-elim
f≡id (inj₂ y) = const (refl (inj₂ y))
from∘to : ∀ x≡y → from (to x≡y) ≡ x≡y
from∘to x≡y =
cong [ const x , P.id ] (cong inj₂ x≡y) ≡⟨ cong-∘ [ const x , P.id ] inj₂ _ ⟩
cong P.id x≡y ≡⟨ sym $ cong-id _ ⟩∎
x≡y ∎
-- An alternative characterisation of equality for binary sums.
Equality-⊎ : ∀ {a b} {A : Type a} {B : Type b} →
A ⊎ B → A ⊎ B → Type (a ⊔ b)
Equality-⊎ {b = b} (inj₁ x) (inj₁ y) = ↑ b (x ≡ y)
Equality-⊎ (inj₁ x) (inj₂ y) = ⊥
Equality-⊎ (inj₂ x) (inj₁ y) = ⊥
Equality-⊎ {a = a} (inj₂ x) (inj₂ y) = ↑ a (x ≡ y)
≡↔⊎ : ∀ {a b} {A : Type a} {B : Type b} {x y : A ⊎ B} →
x ≡ y ↔ Equality-⊎ x y
≡↔⊎ {x = inj₁ x} {inj₁ y} = inj₁ x ≡ inj₁ y ↔⟨ inverse ≡↔inj₁≡inj₁ ⟩
x ≡ y ↔⟨ inverse ↑↔ ⟩□
↑ _ (x ≡ y) □
≡↔⊎ {x = inj₁ x} {inj₂ y} = inj₁ x ≡ inj₂ y ↔⟨ inverse (⊥↔uninhabited ⊎.inj₁≢inj₂) ⟩□
⊥ □
≡↔⊎ {x = inj₂ x} {inj₁ y} = inj₂ x ≡ inj₁ y ↔⟨ inverse (⊥↔uninhabited (⊎.inj₁≢inj₂ ⊚ sym)) ⟩□
⊥ □
≡↔⊎ {x = inj₂ x} {inj₂ y} = inj₂ x ≡ inj₂ y ↔⟨ inverse ≡↔inj₂≡inj₂ ⟩
x ≡ y ↔⟨ inverse ↑↔ ⟩□
↑ _ (x ≡ y) □
-- Decidable equality respects bijections.
decidable-equality-respects :
∀ {a b} {A : Type a} {B : Type b} →
A ↔ B → Decidable-equality A → Decidable-equality B
decidable-equality-respects A↔B _≟A_ x y =
⊎-map (_↔_.injective (inverse A↔B))
(λ from-x≢from-y → from-x≢from-y ⊚ cong from)
(from x ≟A from y)
where open _↔_ A↔B
-- All contractible types are isomorphic.
contractible-isomorphic :
∀ {a b} {A : Type a} {B : Type b} →
Contractible A → Contractible B → A ↔ B
contractible-isomorphic {A} {B} cA cB = record
{ surjection = record
{ logical-equivalence = record
{ to = const (proj₁ cB)
; from = const (proj₁ cA)
}
; right-inverse-of = proj₂ cB
}
; left-inverse-of = proj₂ cA
}
-- Implicit and explicit Π's are isomorphic.
implicit-Π↔Π : ∀ {a b} {A : Type a} {B : A → Type b} →
({x : A} → B x) ↔ ((x : A) → B x)
implicit-Π↔Π = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f x → f {x}
; from = λ f {x} → f x
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Implicit and explicit Π's with erased domains are isomorphic.
implicit-Πᴱ↔Πᴱ :
∀ {a b} {A : Type a} {B : A → Type b} →
({@0 x : A} → B x) ↔ ((@0 x : A) → B x)
implicit-Πᴱ↔Πᴱ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f x → f {x}
; from = λ f {x} → f x
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- A variant of implicit-Πᴱ↔Πᴱ.
implicit-Πᴱ↔Πᴱ′ :
∀ {a b} {@0 A : Type a} {B : @0 A → Type b} →
({@0 x : A} → B x) ↔ ((@0 x : A) → B x)
implicit-Πᴱ↔Πᴱ′ {A = A} {B = B} = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f x → f {x}
; from = λ f {x} → f x
}
; right-inverse-of = refl {A = (@0 x : A) → B x}
}
; left-inverse-of = refl {A = {@0 x : A} → B x}
}
-- Σ is associative.
Σ-assoc : ∀ {a b c}
{A : Type a} {B : A → Type b} {C : (x : A) → B x → Type c} →
(Σ A λ x → Σ (B x) (C x)) ↔ Σ (Σ A B) (uncurry C)
Σ-assoc = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (x , (y , z)) → (x , y) , z }
; from = λ { ((x , y) , z) → x , (y , z) }
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Π and Σ commute (in a certain sense).
ΠΣ-comm :
∀ {a b c} {A : Type a} {B : A → Type b} {C : (x : A) → B x → Type c} →
(∀ x → ∃ λ (y : B x) → C x y)
↔
(∃ λ (f : ∀ x → B x) → ∀ x → C x (f x))
ΠΣ-comm = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → proj₁ ⊚ f , proj₂ ⊚ f
; from = λ { (f , g) x → f x , g x }
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Equality is commutative.
≡-comm :
∀ {a} {A : Type a} {x y : A} →
x ≡ y ↔ y ≡ x
≡-comm = record
{ surjection = record
{ logical-equivalence = record { to = sym }
; right-inverse-of = sym-sym
}
; left-inverse-of = sym-sym
}
-- Families of functions that satisfy a kind of involution property
-- can be turned into bijections.
bijection-from-involutive-family :
∀ {a b} {A : Type a} {B : A → Type b} →
(f : ∀ a₁ a₂ → B a₁ → B a₂) →
(∀ a₁ a₂ (x : B a₁) → f _ _ (f _ a₂ x) ≡ x) →
∀ a₁ a₂ → B a₁ ↔ B a₂
bijection-from-involutive-family f f-involutive _ _ = record
{ surjection = record
{ logical-equivalence = record
{ to = f _ _
; from = f _ _
}
; right-inverse-of = f-involutive _ _
}
; left-inverse-of = f-involutive _ _
}
abstract
-- An equality rearrangement lemma.
trans-to-to≡to-trans :
∀ {a b} {A : Type a} {B : Type b} {f : A → B}
(iso : ∀ x y → f x ≡ f y ↔ x ≡ y) →
(∀ x → _↔_.from (iso x x) (refl x) ≡ refl (f x)) →
∀ {x y z p q} →
trans (_↔_.to (iso x y) p) (_↔_.to (iso y z) q) ≡
_↔_.to (iso x z) (trans p q)
trans-to-to≡to-trans {f = f} iso iso-refl {x} {y} {z} {p} {q} =
trans (_↔_.to (iso x y) p) (_↔_.to (iso y z) q) ≡⟨ elim₁ (λ {x} p → trans p (_↔_.to (iso y z) q) ≡
_↔_.to (iso x z) (trans (_↔_.from (iso x y) p) q)) (
trans (refl y) (_↔_.to (iso y z) q) ≡⟨ trans-reflˡ _ ⟩
_↔_.to (iso y z) q ≡⟨ cong (_↔_.to (iso y z)) $ sym $ trans-reflˡ _ ⟩
_↔_.to (iso y z) (trans (refl (f y)) q) ≡⟨ cong (_↔_.to (iso y z) ⊚ flip trans _) $ sym $ iso-refl y ⟩∎
_↔_.to (iso y z) (trans (_↔_.from (iso y y) (refl y)) q) ∎)
(_↔_.to (iso x y) p) ⟩
_↔_.to (iso x z)
(trans (_↔_.from (iso x y) (_↔_.to (iso x y) p)) q) ≡⟨ cong (_↔_.to (iso x z) ⊚ flip trans _) $
_↔_.left-inverse-of (iso _ _) _ ⟩∎
_↔_.to (iso x z) (trans p q) ∎
| {
"alphanum_fraction": 0.4444557893,
"avg_line_length": 31.5935483871,
"ext": "agda",
"hexsha": "c37578138b8ca6c05620418fcb9e3d402c7d409c",
"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/Bijection.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/Bijection.agda",
"max_line_length": 138,
"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/Bijection.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": 7768,
"size": 19588
} |
-- Andreas, 2018-08-14, re issue #1558
-- Termination checking functions over inductive-inductive types
-- {-# OPTIONS -v term:40 #-}
mutual
data Cxt : Set where
ε : Cxt
_,_ : (Γ : Cxt) (A : Ty Γ) → Cxt
data Ty : (Γ : Cxt) → Set where
u : ∀ Γ → Ty Γ
Π : ∀ Γ (A : Ty Γ) (B : Ty (Γ , A)) → Ty Γ
mutual
f : Cxt → Cxt
f ε = ε
f (Γ , T) = (f Γ , g Γ T)
g : ∀ Γ → Ty Γ → Ty (f Γ)
g Γ (u .Γ) = u (f Γ)
g Γ (Π .Γ A B) = Π (f Γ) (g Γ A) (g (Γ , A) B)
-- The type of g contains a call
--
-- g Γ _ --> f Γ
--
-- which is now recorded by the termination checker.
-- Should pass termination.
| {
"alphanum_fraction": 0.487654321,
"avg_line_length": 20.9032258065,
"ext": "agda",
"hexsha": "d992abfe7adf318c87033cab46d10e9c1a4eb646",
"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/TerminationInductionInduction.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/TerminationInductionInduction.agda",
"max_line_length": 64,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/TerminationInductionInduction.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": 276,
"size": 648
} |
-- Andreas, 2018-11-23, issue #3304, report and test case by Nisse
open import Agda.Builtin.Equality
open import Agda.Builtin.Sigma
map : {A B : Set} {P : A → Set} {Q : B → Set} →
(f : A → B) → (∀ {x} → P x → Q (f x)) →
Σ A P → Σ B Q
map f g (x , y) = (f x , g y)
postulate
F : Set → Set → Set
apply : {A B : Set} → F A B → A → B
construct : {A B : Set} → (A → B) → F A B
A : Set
B : A → Set
f : A → A
g : ∀ {x} → B x → B (f x)
mutual
k : Σ A B → Σ A _
k = map f g
h : F (Σ A B) (Σ A B)
h = construct k
P : ∀ {x y} → k x ≡ k y → Set₁
P refl = Set
-- WAS: internal error in
-- TypeChecking.Rules.Term.catchIlltypedPatternBlockedOnMeta
--
-- EXPECTED:
-- I'm not sure if there should be a case for the constructor refl,
-- because I get stuck when trying to solve the following unification
-- problems (inferred index ≟ expected index):
-- k x ≟ k y
-- when checking that the pattern refl has type k x ≡ k y
| {
"alphanum_fraction": 0.5442655936,
"avg_line_length": 24.85,
"ext": "agda",
"hexsha": "0c637c079fc9a43c083799c70d9d68360e06ad88",
"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/Issue3403.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/Issue3403.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue3403.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": 368,
"size": 994
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Rings.IntegralDomains.Definition
module Rings.Associates.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (intDom : IntegralDomain R) where
open import Rings.Divisible.Definition R
open import Rings.IntegralDomains.Lemmas intDom
open import Rings.Associates.Definition intDom
open import Rings.Ideals.Definition R
open Setoid S
open Ring R
open Equivalence eq
associatesEquiv : Equivalence Associates
Equivalence.reflexive associatesEquiv {x} = 1R , ((1R , identIsIdent) ,, symmetric (transitive *Commutative identIsIdent))
Equivalence.symmetric associatesEquiv {x} {y} (a , ((invA , prInv) ,, x=ya)) = invA , ((a , transitive *Commutative prInv) ,, transitive (symmetric identIsIdent) (transitive (*WellDefined (symmetric prInv) reflexive) (transitive *Commutative (transitive *Associative (*WellDefined (symmetric x=ya) reflexive)))))
Equivalence.transitive associatesEquiv {x} {y} {z} (a , ((invA , prInvA) ,, x=ya)) (b , ((invB , prInvB) ,, y=zb)) = (a * b) , (((invA * invB) , transitive *Associative (transitive (*WellDefined (transitive *Commutative *Associative) reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined (transitive *Commutative prInvA) prInvB) identIsIdent)))) ,, transitive x=ya (transitive (*WellDefined y=zb reflexive) (transitive (symmetric *Associative) (*WellDefined reflexive *Commutative))))
associateImpliesMutualDivision : {a b : A} → Associates a b → a ∣ b
associateImpliesMutualDivision {a} {b} (x , ((invX , prInvX) ,, a=bx)) = invX , transitive (transitive (*WellDefined a=bx reflexive) (transitive (transitive (symmetric *Associative) (*WellDefined reflexive prInvX)) *Commutative)) identIsIdent
mutualDivisionImpliesAssociate : {a b : A} → (a ∣ b) → (b ∣ a) → ((a ∼ 0R) → False) → Associates a b
mutualDivisionImpliesAssociate {a} {b} (r , ar=b) (s , bs=a) a!=0 = s , ((r , cancelIntDom {a = a} (transitive (transitive (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (*WellDefined ar=b reflexive))) bs=a) (transitive (symmetric identIsIdent) *Commutative)) a!=0) ,, symmetric bs=a)
mutualDivisionImpliesAssociate' : {a b : A} → (a ∣ b) → (b ∣ a) → (a ∼ 0R) → Associates a b
mutualDivisionImpliesAssociate' {a} {b} (r , ar=b) (s , bs=a) a=0 = 1R , ((1R , identIsIdent) ,, transitive a=0 (symmetric (transitive (*WellDefined b=0 reflexive) (transitive *Commutative timesZero))))
where
b=0 : b ∼ 0R
b=0 = transitive (symmetric ar=b) (transitive (transitive *Commutative (*WellDefined reflexive a=0)) (timesZero {r}))
associateImpliesGeneratedIdealsEqual : {a b : A} → Associates a b → {x : A} → generatedIdealPred a x → generatedIdealPred b x
associateImpliesGeneratedIdealsEqual {a} {b} (r , ((s , rs=1) ,, a=br)) {x} (c , ac=x) = (r * c) , transitive *Associative (transitive (*WellDefined (symmetric a=br) reflexive) ac=x)
associateImpliesGeneratedIdealsEqual' : {a b : A} → Associates a b → {x : A} → generatedIdealPred b x → generatedIdealPred a x
associateImpliesGeneratedIdealsEqual' assoc = associateImpliesGeneratedIdealsEqual (Equivalence.symmetric associatesEquiv assoc)
| {
"alphanum_fraction": 0.7228588661,
"avg_line_length": 78.9523809524,
"ext": "agda",
"hexsha": "e9f02ea71b560a7ae2158dce45e0dc29c576b6ce",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Associates/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Associates/Lemmas.agda",
"max_line_length": 504,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Associates/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 1050,
"size": 3316
} |
{-# OPTIONS --universe-polymorphism #-}
open import Categories.Category
module Categories.Object.Products.Properties {o ℓ e}
(C : Category o ℓ e) where
open Category C
open import Level
import Categories.Object.Terminal
open Categories.Object.Terminal C
import Categories.Object.BinaryProducts
open Categories.Object.BinaryProducts C
import Categories.Object.Products
open Categories.Object.Products C
import Categories.Morphisms
open Categories.Morphisms C
module Properties (P : Products) where
open Products P
open Terminal terminal
open BinaryProducts binary
open HomReasoning
open Equiv
unitˡ : ∀ {X} → (⊤ × X) ≅ X
unitˡ {X} = record
{ f = π₂
; g = ⟨ ! , id {X} ⟩
; iso = record
{ isoˡ =
begin
⟨ ! , id {X} ⟩ ∘ π₂
↓⟨ ⟨⟩∘ ⟩
⟨ ! ∘ π₂ , id ∘ π₂ ⟩
↓⟨ ⟨⟩-cong₂ (!-unique₂ (! ∘ π₂) π₁) (identityˡ) ⟩
⟨ π₁ , π₂ ⟩
↓⟨ η ⟩
id
∎
; isoʳ = commute₂
}
}
.unitˡ-natural : ∀ {X Y} {f : X ⇒ Y} → ⟨ ! , id {Y} ⟩ ∘ f ≡ second f ∘ ⟨ ! , id {X} ⟩
unitˡ-natural {f = f} =
begin
⟨ ! , id ⟩ ∘ f
↓⟨ ⟨⟩∘ ⟩
⟨ ! ∘ f , id ∘ f ⟩
↑⟨ ⟨⟩-cong₂ (!-unique (! ∘ f)) (id-comm {f = f}) ⟩
⟨ ! , f ∘ id ⟩
↑⟨ second∘⟨⟩ ⟩
second f ∘ ⟨ ! , id ⟩
∎
unitʳ : ∀ {X} → (X × ⊤) ≅ X
unitʳ {X} = record
{ f = π₁
; g = ⟨ id {X} , ! ⟩
; iso = record
{ isoˡ =
begin
⟨ id {X} , ! ⟩ ∘ π₁
↓⟨ ⟨⟩∘ ⟩
⟨ id ∘ π₁ , ! ∘ π₁ ⟩
↓⟨ ⟨⟩-cong₂ (identityˡ) (!-unique₂ (! ∘ π₁) π₂) ⟩
⟨ π₁ , π₂ ⟩
↓⟨ η ⟩
id
∎
; isoʳ = commute₁
}
}
.unitʳ-natural : ∀ {X Y} {f : X ⇒ Y} → ⟨ id , ! ⟩ ∘ f ≡ first f ∘ ⟨ id , ! ⟩
unitʳ-natural {f = f} =
begin
⟨ id , ! ⟩ ∘ f
↓⟨ ⟨⟩∘ ⟩
⟨ id ∘ f , ! ∘ f ⟩
↑⟨ ⟨⟩-cong₂ (id-comm {f = f}) (!-unique (! ∘ f)) ⟩
⟨ f ∘ id , ! ⟩
↑⟨ first∘⟨⟩ ⟩
first f ∘ ⟨ id , ! ⟩
∎
| {
"alphanum_fraction": 0.4414278532,
"avg_line_length": 21.3870967742,
"ext": "agda",
"hexsha": "39715b7dc66fea0d5c2af1fc96e7b58c7e16ca2c",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Object/Products/Properties.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Object/Products/Properties.agda",
"max_line_length": 87,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Object/Products/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 827,
"size": 1989
} |
module Check where
open import Data.Fin using (Fin)
open import Data.Nat using (ℕ; suc)
open import Data.Vec hiding (head; tail)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (Dec; yes; no)
open import Types
open import Utils
data Check {n} (Γ : Ctx n) : Syntax → Set where
yes : (τ : Type) (t : Term Γ τ) → Check Γ (erase t)
no : {e : Syntax} → Check Γ e
check : ∀ {n} (Γ : Ctx n) (t : Syntax) → Check Γ t
check Γ bitI = yes 𝔹 bitI
check Γ bitO = yes 𝔹 bitO
check Γ [] = yes (𝔹⁺ 0) []
check Γ (x ∷ xs) with check Γ x | check Γ xs
check Γ (.(erase t) ∷ .(erase t₁)) | yes 𝔹 t | yes (𝔹⁺ n) t₁ = yes (𝔹⁺ (suc n)) (t ∷ t₁)
check Γ (x ∷ xs) | _ | _ = no
check Γ (x nand y) with check Γ x | check Γ y
check Γ (._ nand ._) | yes 𝔹 x | yes 𝔹 y = yes 𝔹 (x nand y)
check Γ (_ nand _) | _ | _ = no
check Γ (reg xt ft) with check Γ xt | check Γ ft
check Γ (reg ._ ._) | yes τ xt | yes (τ′ ⇒ (τ″ × σ)) ft with τ ≟T τ′ | τ ≟T τ″
check Γ (reg ._ ._) | yes τ xt | yes (.τ ⇒ (.τ × σ)) ft | yes refl | yes refl = yes _ (reg xt ft)
check Γ (reg ._ ._) | yes τ xt | yes (τ′ ⇒ (τ″ × σ)) ft | _ | _ = no
check Γ (reg _ _) | _ | _ = no
check Γ (pair xt yt) with check Γ xt | check Γ yt
check Γ (pair ._ ._) | yes σ t | yes τ t₁ with σ ≟T τ
check Γ (pair ._ ._) | yes σ t | yes .σ t₁ | yes refl = yes (σ × σ) (pair t t₁)
check Γ (pair ._ ._) | yes σ t | yes τ t₁ | no _ = no
check Γ (pair xt yt) | _ | _ = no
check Γ (latest t) with check Γ t
check Γ (latest ._) | yes (ℂ τ) t′ = yes τ (latest t′)
check Γ (latest t) | _ = no
check Γ (head x) with check Γ x
check Γ (head ._) | yes (𝔹⁺ (suc n)) t = yes 𝔹 (head t)
check Γ (head _) | _ = no
check Γ (tail xs) with check Γ xs
check Γ (tail .(erase t)) | yes (𝔹⁺ (suc n)) t = yes (𝔹⁺ n) (tail t)
check Γ (tail xs) | _ = no
check {n} Γ (var i) with fromℕ n i
check Γ (var ._) | yes m = yes (lookup m Γ) (var m refl)
check Γ (var ._) | no m = no
check Γ (x ∙ y) with check Γ x | check Γ y
check Γ (._ ∙ ._) | yes (σ ⇒ τ) x | yes σ′ y with σ ≟T σ′
check Γ (._ ∙ ._) | yes (σ ⇒ τ) x | yes .σ y | yes refl = yes τ (x ∙ y)
check Γ (._ ∙ ._) | yes (σ ⇒ τ) x | yes σ′ y | no ¬p = no
check Γ (x ∙ y) | _ | _ = no
check Γ (lam τ x) with check (τ ∷ Γ) x
check Γ (lam τ ._) | yes τ₁ t = yes (τ ⇒ τ₁) (lam t)
check Γ (lam τ x) | no = no
| {
"alphanum_fraction": 0.5551265551,
"avg_line_length": 34.7910447761,
"ext": "agda",
"hexsha": "d7a825485b6d3313e58304c2b52a5645897146ae",
"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": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bens/hwlc",
"max_forks_repo_path": "Check.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"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": "bens/hwlc",
"max_issues_repo_path": "Check.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bens/hwlc",
"max_stars_repo_path": "Check.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 954,
"size": 2331
} |
data Bool : Set where
true : Bool
false : Bool
if_then_else : ∀ {l} {A : Set l} -> Bool -> A -> A -> A
if true then t else e = t
if false then t else e = e
if2_,_then_else1_else2_else_ : ∀ {l} {A : Set l} -> (b1 b2 : Bool) -> (t e1 e2 e : A) -> A
if2 true , true then t else1 e1 else2 e2 else e = t
if2 true , false then t else1 e1 else2 e2 else e = e1
if2 false , true then t else1 e1 else2 e2 else e = e2
if2 false , false then t else1 e1 else2 e2 else e = e
example : Bool
example = if2 true , false then true else1 false else2 true else false
| {
"alphanum_fraction": 0.6462093863,
"avg_line_length": 32.5882352941,
"ext": "agda",
"hexsha": "c2ebba458a6de33c40fe8da301be89ea82c500bd",
"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": "9ad63ea473a958506c041077f1d810c0c7c8c18d",
"max_forks_repo_licenses": [
"Info-ZIP"
],
"max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData",
"max_forks_repo_path": "Task/Extend-your-language/Agda/extend-your-language.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Info-ZIP"
],
"max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData",
"max_issues_repo_path": "Task/Extend-your-language/Agda/extend-your-language.agda",
"max_line_length": 90,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d",
"max_stars_repo_licenses": [
"Info-ZIP"
],
"max_stars_repo_name": "LaudateCorpus1/RosettaCodeData",
"max_stars_repo_path": "Task/Extend-your-language/Agda/extend-your-language.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T13:42:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-05T13:42:20.000Z",
"num_tokens": 206,
"size": 554
} |
{-# OPTIONS --without-K #-}
module sets.vec.properties where
open import equality.core
open import function.core
open import function.extensionality
open import function.isomorphism
open import sets.nat.core using (ℕ; zero; suc)
open import sets.fin using (Fin; zero; suc)
open import sets.vec.core
tabulate-lookup : ∀ {i}{A : Set i}{n : ℕ}
→ (xs : Vec A n)
→ tabulate (lookup xs) ≡ xs
tabulate-lookup [] = refl
tabulate-lookup (x ∷ xs) = ap (_∷_ x) (tabulate-lookup xs)
lookup-tabulate-funext : ∀ {i}{A : Set i}{n : ℕ}
→ (f : Fin n → A)(i : Fin n)
→ lookup (tabulate f) i ≡ f i
lookup-tabulate-funext {n = zero} f ()
lookup-tabulate-funext {n = suc m} f zero = refl
lookup-tabulate-funext {n = suc m} f (suc i) =
lookup-tabulate-funext (f ∘ suc) i
lookup-tabulate : ∀ {i}{A : Set i}{n : ℕ}
→ (f : Fin n → A)
→ lookup (tabulate f) ≡ f
lookup-tabulate f = funext (lookup-tabulate-funext f)
lookup-iso : ∀ {i}{A : Set i}{n : ℕ}
→ Vec A n ≅ (Fin n → A)
lookup-iso = iso lookup tabulate tabulate-lookup lookup-tabulate
| {
"alphanum_fraction": 0.5954265611,
"avg_line_length": 33.4411764706,
"ext": "agda",
"hexsha": "aece6dc9dcfddfdf789128a9b6c5bac613e23c43",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "sets/vec/properties.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/vec/properties.agda",
"max_line_length": 64,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "sets/vec/properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 354,
"size": 1137
} |
------------------------------------------------------------------------
-- The two definitions of context extensions are isomorphic
------------------------------------------------------------------------
open import Data.Universe.Indexed
module deBruijn.Context.Extension.Isomorphic
{i u e} (Uni : IndexedUniverse i u e) where
import deBruijn.Context.Basics as Basics
import deBruijn.Context.Extension.Left as Left
import deBruijn.Context.Extension.Right as Right
open import Function.Base
open import Function.Inverse using (_↔_)
import Relation.Binary.PropositionalEquality as P
open Basics Uni
open Left Uni
open Right Uni
open P.≡-Reasoning
-- Ctxt₊-s can be turned into Ctxt⁺-s.
₊-to-⁺ : ∀ {Γ} → Ctxt₊ Γ → Ctxt⁺ Γ
₊-to-⁺ ε = ε
₊-to-⁺ (σ ◅ Γ₊) = ε ▻ σ ⁺++⁺ ₊-to-⁺ Γ₊
abstract
-- The semantics is preserved.
++⁺-₊-to-⁺ : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) → Γ ++₊ Γ₊ ≅-Ctxt Γ ++⁺ ₊-to-⁺ Γ₊
++⁺-₊-to-⁺ ε = P.refl
++⁺-₊-to-⁺ {Γ} (σ ◅ Γ₊) = begin
Γ ▻ σ ++₊ Γ₊ ≡⟨ ++⁺-₊-to-⁺ Γ₊ ⟩
Γ ▻ σ ++⁺ ₊-to-⁺ Γ₊ ≡⟨ ++⁺-++⁺ (ε ▻ σ) (₊-to-⁺ Γ₊) ⟩
Γ ++⁺ (ε ▻ σ ⁺++⁺ ₊-to-⁺ Γ₊) ∎
mutual
-- Ctxt⁺-s can be turned into Ctxt₊-s.
⁺-to-₊ : ∀ {Γ} → Ctxt⁺ Γ → Ctxt₊ Γ
⁺-to-₊ ε = ε
⁺-to-₊ (Γ⁺ ▻ σ) =
⁺-to-₊ Γ⁺ ₊++₊ P.subst Ctxt₊ (++₊-⁺-to-₊ Γ⁺) (σ ◅ ε)
abstract
-- The semantics is preserved.
++₊-⁺-to-₊ : ∀ {Γ} (Γ⁺ : Ctxt⁺ Γ) → Γ ++⁺ Γ⁺ ≅-Ctxt Γ ++₊ ⁺-to-₊ Γ⁺
++₊-⁺-to-₊ ε = P.refl
++₊-⁺-to-₊ {Γ} (Γ⁺ ▻ σ) =
let σ◅ε = P.subst Ctxt₊ (++₊-⁺-to-₊ Γ⁺) (σ ◅ ε)
in begin
Γ ++⁺ Γ⁺ ▻ σ ≡⟨ P.refl ⟩
Γ ++⁺ Γ⁺ ++₊ (σ ◅ ε) ≡⟨ P.sym $ ++₊-cong $ drop-subst-Ctxt₊ id (++₊-⁺-to-₊ Γ⁺) ⟩
Γ ++₊ ⁺-to-₊ Γ⁺ ++₊ σ◅ε ≡⟨ ++₊-++₊ (⁺-to-₊ Γ⁺) σ◅ε ⟩
Γ ++₊ (⁺-to-₊ Γ⁺ ₊++₊ σ◅ε) ∎
-- Some congruence lemmas.
₊-to-⁺-cong : ∀ {Γ₁} {Γ₊₁ : Ctxt₊ Γ₁}
{Γ₂} {Γ₊₂ : Ctxt₊ Γ₂} →
Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ₊-to-⁺ Γ₊₁ ≅-Ctxt⁺ ₊-to-⁺ Γ₊₂
₊-to-⁺-cong P.refl = P.refl
⁺-to-₊-cong : ∀ {Γ₁} {Γ⁺₁ : Ctxt⁺ Γ₁}
{Γ₂} {Γ⁺₂ : Ctxt⁺ Γ₂} →
Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ⁺-to-₊ Γ⁺₁ ≅-Ctxt₊ ⁺-to-₊ Γ⁺₂
⁺-to-₊-cong P.refl = P.refl
-- Ctxt⁺ and Ctxt₊ are isomorphic.
Ctxt⁺↔Ctxt₊ : ∀ Γ → Ctxt⁺ Γ ↔ Ctxt₊ Γ
Ctxt⁺↔Ctxt₊ Γ = record
{ to = P.→-to-⟶ ⁺-to-₊
; from = P.→-to-⟶ ₊-to-⁺
; inverse-of = record
{ left-inverse-of = λ Γ⁺ → ≅-Ctxt⁺-⇒-≡ $ ₊-to-⁺-⁺-to-₊ Γ⁺
; right-inverse-of = λ Γ₊ → ≅-Ctxt₊-⇒-≡ $ ⁺-to-₊-₊-to-⁺ Γ₊
}
}
where
abstract
₊-to-⁺-⁺-to-₊ : (Γ⁺ : Ctxt⁺ Γ) → ₊-to-⁺ (⁺-to-₊ Γ⁺) ≅-Ctxt⁺ Γ⁺
₊-to-⁺-⁺-to-₊ Γ⁺ = cancel-++⁺-left _ _ (begin
Γ ++⁺ ₊-to-⁺ (⁺-to-₊ Γ⁺) ≡⟨ P.sym $ ++⁺-₊-to-⁺ (⁺-to-₊ Γ⁺) ⟩
Γ ++₊ (⁺-to-₊ Γ⁺) ≡⟨ P.sym $ ++₊-⁺-to-₊ Γ⁺ ⟩
Γ ++⁺ Γ⁺ ∎)
⁺-to-₊-₊-to-⁺ : (Γ₊ : Ctxt₊ Γ) → ⁺-to-₊ (₊-to-⁺ Γ₊) ≅-Ctxt₊ Γ₊
⁺-to-₊-₊-to-⁺ Γ₊ = cancel-++₊-left _ _ (begin
Γ ++₊ ⁺-to-₊ (₊-to-⁺ Γ₊) ≡⟨ P.sym $ ++₊-⁺-to-₊ (₊-to-⁺ Γ₊) ⟩
Γ ++⁺ (₊-to-⁺ Γ₊) ≡⟨ P.sym $ ++⁺-₊-to-⁺ Γ₊ ⟩
Γ ++₊ Γ₊ ∎)
| {
"alphanum_fraction": 0.388942774,
"avg_line_length": 31.2424242424,
"ext": "agda",
"hexsha": "1a27eab9a6f7f53e2b7239e7f08d8cf14da28b0d",
"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": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependently-typed-syntax",
"max_forks_repo_path": "deBruijn/Context/Extension/Isomorphic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"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/dependently-typed-syntax",
"max_issues_repo_path": "deBruijn/Context/Extension/Isomorphic.agda",
"max_line_length": 93,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependently-typed-syntax",
"max_stars_repo_path": "deBruijn/Context/Extension/Isomorphic.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z",
"num_tokens": 1764,
"size": 3093
} |
module UniDB.Morph.Sim where
open import UniDB.Spec
open import UniDB.Subst.Core
open import UniDB.Morph.Depth
import Level
open import Relation.Binary.PropositionalEquality
--------------------------------------------------------------------------------
record Sim (T : STX) (γ₁ γ₂ : Dom) : Set where
constructor sim
field
lk-sim : (i : Ix γ₁) → T γ₂
open Sim public
module _ {T : STX} where
instance
iLkSim : {{vrT : Vr T}} → Lk T (Sim T)
lk {{iLkSim}} = lk-sim
iWkSim : {{wkT : Wk T}} → {γ₁ : Dom} → Wk (Sim T γ₁)
wk₁ {{iWkSim}} (sim f) = sim (wk₁ ∘ f)
wk {{iWkSim}} δ (sim f) = sim (wk δ ∘ f)
wk-zero {{iWkSim {{wkT}}}} (sim f) = cong sim (ext (wk-zero {T} ∘ f))
where postulate ext : Extensionality Level.zero Level.zero
wk-suc {{iWkSim}} δ (sim f) = cong sim (ext (wk-suc {T} δ ∘ f))
where postulate ext : Extensionality Level.zero Level.zero
iSnocSim : Snoc T (Sim T)
snoc {{iSnocSim}} (sim f) t = sim λ
{ zero → t
; (suc i) → f i
}
iUpSim : {{vrT : Vr T}} {{wkT : Wk T}} → Up (Sim T)
_↑₁ {{iUpSim}} ξ = snoc {T} {Sim T} (wk₁ ξ) (vr {T} zero)
_↑_ {{iUpSim}} ξ 0 = ξ
_↑_ {{iUpSim}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁
↑-zero {{iUpSim}} ξ = refl
↑-suc {{iUpSim}} ξ δ⁺ = refl
iIdmSim : {{vrT : Vr T}} → Idm (Sim T)
idm {{iIdmSim}} γ = sim (vr {T})
iWkmSim : {{vrT : Vr T}} → Wkm (Sim T)
wkm {{iWkmSim}} δ = sim (vr {T} ∘ wk δ)
iBetaSim : {{vrT : Vr T}} → Beta T (Sim T)
beta {{iBetaSim}} t = snoc {T} {Sim T} (idm {Sim T} _) t
iCompSim : {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} → Comp (Sim T)
lk-sim (_⊙_ {{iCompSim}} ξ ζ) i =
ap {T} {T} {Sim T} ζ (lk {T} {Sim T} ξ i)
iLkUpSim : {{vrT : Vr T}} {{wkT : Wk T}} → LkUp T (Sim T)
lk-↑₁-zero {{iLkUpSim}} ξ = refl
lk-↑₁-suc {{iLkUpSim}} ξ zero = refl
lk-↑₁-suc {{iLkUpSim}} ξ (suc i) = refl
iLkWkmSim : {{vrT : Vr T}} → LkWkm T (Sim T)
lk-wkm {{iLkWkmSim}} δ i = refl
iLkIdmSim : {{vrT : Vr T}} → LkIdm T (Sim T)
lk-idm {{iLkIdmSim}} i = refl
iLkCompSim : {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} → LkCompAp T (Sim T)
lk-⊙-ap {{iLkCompSim}} ξ₁ ξ₂ i = refl
--------------------------------------------------------------------------------
module SimIxInstances (T : STX) where
instance
iLkSimIx : {{vrT : Vr T}} → Lk T (Sim Ix)
lk {{iLkSimIx}} ξ i = vr {T} (lk {Ix} {Sim Ix} ξ i)
iLkUpSimIx : {{vrT : Vr T}} {{wkT : Wk T}}
{{wkVrT : WkVr T}} → LkUp T (Sim Ix)
lk-↑₁-zero {{iLkUpSimIx}} ξ = refl
lk-↑₁-suc {{iLkUpSimIx}} ξ i = sym (wk₁-vr {T} (lk {Ix} {Sim Ix} ξ i))
iLkWkmSimIx : {{vrT : Vr T}} → LkWkm T (Sim Ix)
lk-wkm {{iLkWkmSimIx}} δ i = refl
iLkIdmSimIx : {{vrT : Vr T}} → LkIdm T (Sim Ix)
lk-idm {{iLkIdmSimIx}} i = refl
iLkCompSimIx : {{vrT : Vr T}} {{apTT : Ap T T}}
{{apVrT : ApVr T}} → LkCompAp T (Sim Ix)
lk-⊙-ap {{iLkCompSimIx}} ξ₁ ξ₂ i =
sym (ap-vr {T} {Sim Ix} ξ₂ (lk {Ix} {Sim Ix} ξ₁ i))
--------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4784126984,
"avg_line_length": 32.8125,
"ext": "agda",
"hexsha": "58a1d8de1f9af52f4f3c904e751ee47927936a53",
"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": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Morph/Sim.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"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": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Morph/Sim.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Morph/Sim.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1340,
"size": 3150
} |
open import Nat
open import Prelude
open import dynamics-core
open import disjointness
module elaboration-generality where
mutual
elaboration-generality-synth : {Γ : tctx} {e : hexp} {τ : htyp} {d : ihexp} {Δ : hctx} →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
Γ ⊢ e => τ
elaboration-generality-synth ESNum = SNum
elaboration-generality-synth (ESPlus dis apt x₁ x₂) =
SPlus (elaboration-generality-ana x₁) (elaboration-generality-ana x₂)
elaboration-generality-synth (ESAsc x) = SAsc (elaboration-generality-ana x)
elaboration-generality-synth (ESVar x₁) = SVar x₁
elaboration-generality-synth (ESLam apt ex) with elaboration-generality-synth ex
... | ih = SLam apt ih
elaboration-generality-synth (ESAp dis _ a x₁ x₂ x₃) =
SAp a x₁ (elaboration-generality-ana x₃)
elaboration-generality-synth (ESPair x x₁ x₂ x₃) =
SPair (elaboration-generality-synth x₂) (elaboration-generality-synth x₃)
elaboration-generality-synth ESEHole = SEHole
elaboration-generality-synth (ESNEHole dis ex) = SNEHole (elaboration-generality-synth ex)
elaboration-generality-synth (ESFst wt x₁ x₂) = SFst wt x₁
elaboration-generality-synth (ESSnd wt x₁ x₂) = SSnd wt x₁
elaboration-generality-ana : {Γ : tctx} {e : hexp} {τ τ' : htyp} {d : ihexp} {Δ : hctx} →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
Γ ⊢ e <= τ
elaboration-generality-ana (EALam apt m ex) = ALam apt m (elaboration-generality-ana ex)
elaboration-generality-ana (EASubsume x x₁ x₂ x₃) =
ASubsume (elaboration-generality-synth x₂) x₃
elaboration-generality-ana EAEHole = ASubsume SEHole TCHole1
elaboration-generality-ana (EANEHole dis x) =
ASubsume (SNEHole (elaboration-generality-synth x)) TCHole1
elaboration-generality-ana (EAInl x x₁) = AInl x (elaboration-generality-ana x₁)
elaboration-generality-ana (EAInr x x₁) = AInr x (elaboration-generality-ana x₁)
elaboration-generality-ana (EACase x x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀ x₁₁) =
ACase x₆ x₇ x₉ (elaboration-generality-synth x₈)
(elaboration-generality-ana x₁₀)
(elaboration-generality-ana x₁₁)
| {
"alphanum_fraction": 0.6532685512,
"avg_line_length": 53.9047619048,
"ext": "agda",
"hexsha": "cfe603be1ad35007aa8ef357faa25d4b9f25905d",
"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": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "elaboration-generality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"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": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "elaboration-generality.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "elaboration-generality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 802,
"size": 2264
} |
postulate A : Set
record R : Set where
field f : A
record S : Set where
field g : A
test : R → A
test record{g = a} = a
| {
"alphanum_fraction": 0.5984251969,
"avg_line_length": 11.5454545455,
"ext": "agda",
"hexsha": "a01e88b8e51d59dc94e3d6675506f82451fdcca7",
"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/RecordPattern2.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/RecordPattern2.agda",
"max_line_length": 22,
"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/RecordPattern2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 46,
"size": 127
} |
open import Agda.Primitive using (lsuc; _⊔_)
open import Data.Fin using (Fin)
open import MultiSorted.AlgebraicTheory
module MultiSorted.Substitution {ℓ} {𝓈 ℴ} {Σ : Signature {𝓈} {ℴ}} (T : Theory ℓ Σ) where
open Theory T
-- an equality is preserved by the action of the identity
eq-id-action : ∀ {Γ : Context} {A} {u v : Term Γ A} → (⊢ Γ ∥ (u [ id-s ]s) ≈ (v [ id-s ]s) ⦂ A) → (⊢ Γ ∥ u ≈ v ⦂ A)
eq-id-action {u = u} {v = v} p = eq-tran (id-action {a = u}) (eq-tran p (eq-symm (id-action {a = v})))
-- equality of substitutions
_≈s_ : ∀ {Γ Δ : Context} → Γ ⇒s Δ → Γ ⇒s Δ → Set (lsuc (ℓ ⊔ 𝓈 ⊔ ℴ))
_≈s_ {Γ} {Δ} σ ρ = ∀ x → ⊢ Γ ∥ σ x ≈ ρ x ⦂ sort-of Δ x
infix 5 _≈s_
-- reflexivity of the equality of substitutions
refl-subst : ∀ {γ δ : Context} {f : γ ⇒s δ} → f ≈s f
refl-subst = λ x → eq-refl
-- symmetry of the equality of substitutions
symm-subst : ∀ {Γ Δ : Context} {f g : Γ ⇒s Δ} → f ≈s g → g ≈s f
symm-subst {Γ} {Δ} {f} {g} p = λ x → eq-symm (p x)
-- transitivity of the equality of substitutions
trans-subst : ∀ {Γ Δ : Context} {f g h : Γ ⇒s Δ} → f ≈s g → g ≈s h → f ≈s h
trans-subst {Γ} {Δ} {f} {g} {h} p q = λ x → eq-tran (p x) (q x)
-- neutrality of tm-var
tm-var-id : ∀ {Γ} {A} {t : Term Γ A} → ⊢ Γ ∥ t [ id-s ]s ≈ t ⦂ A
tm-var-id {t = tm-var x} = eq-refl
tm-var-id {t = tm-oper f ts} = eq-congr (λ i → tm-var-id)
-- any two substitutions into the empty context are equal
empty-ctx-subst-unique : ∀ {Γ : Context} {σ ρ : Γ ⇒s ctx-empty} → σ ≈s ρ
empty-ctx-subst-unique ()
-- composition of substitutions is functorial
subst-∘s : ∀ {Γ Δ Θ} {ρ : Δ ⇒s Γ} {σ : Θ ⇒s Δ} {A} (t : Term Γ A) →
⊢ Θ ∥ (t [ ρ ]s) [ σ ]s ≈ t [ ρ ∘s σ ]s ⦂ A
subst-∘s (tm-var x) = eq-refl
subst-∘s (tm-oper f ts) = eq-congr (λ i → subst-∘s (ts i))
-- substitution preserves equality
eq-subst : ∀ {Γ Δ : Context} {σ : Γ ⇒s Δ} {A} {u v : Term Δ A} →
⊢ Δ ∥ u ≈ v ⦂ A → ⊢ Γ ∥ u [ σ ]s ≈ v [ σ ]s ⦂ A
eq-subst eq-refl = eq-refl
eq-subst (eq-symm ξ) = eq-symm (eq-subst ξ)
eq-subst (eq-tran ζ ξ) = eq-tran (eq-subst ζ) (eq-subst ξ)
eq-subst (eq-congr ξ) = eq-congr (λ i → eq-subst (ξ i))
eq-subst {σ = σ} (eq-axiom ε ρ) = eq-tran (subst-∘s (ax-lhs ε)) (eq-tran (eq-axiom ε (ρ ∘s σ)) (eq-symm (subst-∘s (ax-rhs ε))))
-- equivalent substitutions act the same on terms
equiv-subst : ∀ {Γ Δ : Context} {σ τ : Γ ⇒s Δ} {A} (u : Term Δ A) →
σ ≈s τ → ⊢ Γ ∥ u [ σ ]s ≈ u [ τ ]s ⦂ A
equiv-subst (tm-var x) ξ = ξ x
equiv-subst (tm-oper f ts) ξ = eq-congr (λ i → equiv-subst (ts i) ξ)
-- equivalent substitution preserve equality
equiv-eq-subst : ∀ {Γ Δ : Context} {σ τ : Γ ⇒s Δ} {A} {u v : Term Δ A} →
σ ≈s τ → ⊢ Δ ∥ u ≈ v ⦂ A → ⊢ Γ ∥ u [ σ ]s ≈ v [ τ ]s ⦂ A
equiv-eq-subst {u = u} p eq-refl = equiv-subst u p
equiv-eq-subst p (eq-symm q) = eq-symm (equiv-eq-subst (symm-subst p) q)
equiv-eq-subst p (eq-tran q r) = eq-tran (eq-subst q) (equiv-eq-subst p r)
equiv-eq-subst p (eq-congr ξ) = eq-congr λ i → equiv-eq-subst p (ξ i)
equiv-eq-subst {σ = σ} {τ = τ} p (eq-axiom ε θ) = eq-tran (eq-subst (eq-axiom ε θ)) (equiv-subst (ax-rhs ε [ θ ]s) p)
-- the pairing of two substitutions
⟨_,_⟩s : ∀ {Γ Δ Θ} (σ : Γ ⇒s Δ) (ρ : Γ ⇒s Θ) → Γ ⇒s ctx-concat Δ Θ
⟨ σ , ρ ⟩s (var-inl x) = σ x
⟨ σ , ρ ⟩s (var-inr y) = ρ y
-- composition of substitutions preserves equality
∘s-resp-≈s : ∀ {Γ Δ Θ} {σ₁ σ₂ : Γ ⇒s Δ} {τ₁ τ₂ : Δ ⇒s Θ} →
τ₁ ≈s τ₂ → σ₁ ≈s σ₂ → τ₁ ∘s σ₁ ≈s τ₂ ∘s σ₂
∘s-resp-≈s ξ ζ z = equiv-eq-subst ζ (ξ z)
-- the action of a substitution on an equation
open Equation
_[_]s-eq : ∀ (ε : Equation Σ) {Γ : Context} ( σ : Γ ⇒s (eq-ctx ε)) → Equation Σ
_[_]s-eq ε {Γ} σ = Γ ∥ ((eq-lhs ε) [ σ ]s) ≈ ((eq-rhs ε) [ σ ]s) ⦂ (eq-sort ε)
| {
"alphanum_fraction": 0.5364308342,
"avg_line_length": 44.5647058824,
"ext": "agda",
"hexsha": "ea02a930c3d4f6f5d851092143807a60c383bd55",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/MultiSorted/Substitution.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/MultiSorted/Substitution.agda",
"max_line_length": 129,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/MultiSorted/Substitution.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 1716,
"size": 3788
} |
{-# OPTIONS --without-K --safe #-}
------------------------------------------------------------------------
-- Lists, based on the Kleene star and plus.
--
-- These lists are exatcly equivalent to normal lists, except the "cons"
-- case is split into its own data type. This lets us write all the same
-- functions as before, but it has 2 advantages:
--
-- * Some functions are easier to express on the non-empty type. For
-- instance, head can be clearly expressed without the need for
-- maybes.
-- * It can make some proofs easier. By using the non-empty type where
-- possible, we can avoid an extra pattern match, which can really
-- simplify certain proofs.
module Data.List.Kleene.Base where
open import Data.Product as Product using (_×_; _,_; map₂; map₁; proj₁; proj₂)
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂)
open import Algebra
open import Function
------------------------------------------------------------------------
-- Definitions
infixr 5 _&_ ∹_
mutual
-- Non-Empty Lists
record _⁺ {a} (A : Set a) : Set a where
inductive
constructor _&_
field
head : A
tail : A ⋆
-- Possibly Empty Lists
data _⋆ {a} (A : Set a) : Set a where
[] : A ⋆
∹_ : A ⁺ → A ⋆
open _⁺ public
------------------------------------------------------------------------
-- FoldMap
module _ {c ℓ a} (sgrp : Semigroup c ℓ) {A : Set a} where
open Semigroup sgrp
foldMap⁺ : (A → Carrier) → A ⁺ → Carrier
foldMap⁺ f (x & []) = f x
foldMap⁺ f (x & ∹ xs) = f x ∙ foldMap⁺ f xs
module _ {c ℓ a} (mon : Monoid c ℓ) {A : Set a} where
open Monoid mon
foldMap⋆ : (A → Carrier) → A ⋆ → Carrier
foldMap⋆ f [] = ε
foldMap⋆ f (∹ xs) = foldMap⁺ semigroup f xs
------------------------------------------------------------------------
-- Folds
module _ {a b} {A : Set a} {B : Set b} (f : A → B → B) (b : B) where
foldr⁺ : A ⁺ → B
foldr⋆ : A ⋆ → B
foldr⁺ (x & xs) = f x (foldr⋆ xs)
foldr⋆ [] = b
foldr⋆ (∹ xs) = foldr⁺ xs
module _ {a b} {A : Set a} {B : Set b} (f : B → A → B) where
foldl⁺ : B → A ⁺ → B
foldl⋆ : B → A ⋆ → B
foldl⁺ b (x & xs) = foldl⋆ (f b x) xs
foldl⋆ b [] = b
foldl⋆ b (∹ xs) = foldl⁺ b xs
------------------------------------------------------------------------
-- Concatenation
module _ {a} {A : Set a} where
_⁺++⁺_ : A ⁺ → A ⁺ → A ⁺
_⁺++⋆_ : A ⁺ → A ⋆ → A ⁺
_⋆++⁺_ : A ⋆ → A ⁺ → A ⁺
_⋆++⋆_ : A ⋆ → A ⋆ → A ⋆
head (xs ⁺++⋆ ys) = head xs
tail (xs ⁺++⋆ ys) = tail xs ⋆++⋆ ys
xs ⋆++⋆ ys = foldr⋆ (λ x zs → ∹ x & zs) ys xs
xs ⁺++⁺ ys = foldr⁺ (λ x zs → x & ∹ zs) ys xs
[] ⋆++⁺ ys = ys
(∹ xs) ⋆++⁺ ys = xs ⁺++⁺ ys
------------------------------------------------------------------------
-- Mapping
module _ {a b} {A : Set a} {B : Set b} (f : A → B) where
map⁺ : A ⁺ → B ⁺
map⋆ : A ⋆ → B ⋆
head (map⁺ xs) = f (head xs)
tail (map⁺ xs) = map⋆ (tail xs)
map⋆ [] = []
map⋆ (∹ xs) = ∹ map⁺ xs
------------------------------------------------------------------------
-- Applicative Operations
module _ {a} {A : Set a} where
pure⁺ : A → A ⁺
pure⋆ : A → A ⋆
head (pure⁺ x) = x
tail (pure⁺ x) = []
pure⋆ x = ∹ pure⁺ x
module _ {a b} {A : Set a} {B : Set b} where
_⋆<*>⋆_ : (A → B) ⋆ → A ⋆ → B ⋆
_⁺<*>⋆_ : (A → B) ⁺ → A ⋆ → B ⋆
_⋆<*>⁺_ : (A → B) ⋆ → A ⁺ → B ⋆
_⁺<*>⁺_ : (A → B) ⁺ → A ⁺ → B ⁺
[] ⋆<*>⋆ xs = []
(∹ fs) ⋆<*>⋆ xs = fs ⁺<*>⋆ xs
fs ⁺<*>⋆ xs = map⋆ (head fs) xs ⋆++⋆ (tail fs ⋆<*>⋆ xs)
[] ⋆<*>⁺ xs = []
(∹ fs) ⋆<*>⁺ xs = ∹ fs ⁺<*>⁺ xs
fs ⁺<*>⁺ xs = map⁺ (head fs) xs ⁺++⋆ (tail fs ⋆<*>⁺ xs)
------------------------------------------------------------------------
-- Monadic Operations
module _ {a b} {A : Set a} {B : Set b} where
_⁺>>=⁺_ : A ⁺ → (A → B ⁺) → B ⁺
_⁺>>=⋆_ : A ⁺ → (A → B ⋆) → B ⋆
_⋆>>=⁺_ : A ⋆ → (A → B ⁺) → B ⋆
_⋆>>=⋆_ : A ⋆ → (A → B ⋆) → B ⋆
(x & xs) ⁺>>=⁺ k = k x ⁺++⋆ (xs ⋆>>=⁺ k)
(x & xs) ⁺>>=⋆ k = k x ⋆++⋆ (xs ⋆>>=⋆ k)
[] ⋆>>=⋆ k = []
(∹ xs) ⋆>>=⋆ k = xs ⁺>>=⋆ k
[] ⋆>>=⁺ k = []
(∹ xs) ⋆>>=⁺ k = ∹ xs ⁺>>=⁺ k
------------------------------------------------------------------------
-- Scans
module Scanr {a b} {A : Set a} {B : Set b} (f : A → B → B) (b : B) where
cons : A → B ⁺ → B ⁺
head (cons x xs) = f x (head xs)
tail (cons x xs) = ∹ xs
scanr⁺ : A ⁺ → B ⁺
scanr⋆ : A ⋆ → B ⁺
scanr⋆ = foldr⋆ cons (b & [])
scanr⁺ = foldr⁺ cons (b & [])
open Scanr public using (scanr⁺; scanr⋆)
module _ {a b} {A : Set a} {B : Set b} (f : B → A → B) where
scanl⁺ : B → A ⁺ → B ⁺
scanl⋆ : B → A ⋆ → B ⁺
head (scanl⁺ b xs) = b
tail (scanl⁺ b xs) = ∹ scanl⋆ (f b (head xs)) (tail xs)
head (scanl⋆ b xs) = b
tail (scanl⋆ b []) = []
tail (scanl⋆ b (∹ xs)) = ∹ scanl⋆ (f b (head xs)) (tail xs)
scanl₁ : B → A ⁺ → B ⁺
scanl₁ b xs = scanl⋆ (f b (head xs)) (tail xs)
------------------------------------------------------------------------
-- Accumulating maps
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : B → A → (B × C)) where
mapAccumL⋆ : B → A ⋆ → (B × C ⋆)
mapAccumL⁺ : B → A ⁺ → (B × C ⁺)
mapAccumL⋆ b [] = b , []
mapAccumL⋆ b (∹ xs) = map₂ ∹_ (mapAccumL⁺ b xs)
mapAccumL⁺ b (x & xs) =
let y , ys = f b x
z , zs = mapAccumL⋆ y xs
in z , (ys & zs)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B → (C × B)) (b : B) where
mapAccumR⋆ : A ⋆ → (C ⋆ × B)
mapAccumR⁺ : A ⁺ → (C ⁺ × B)
mapAccumR⋆ [] = [] , b
mapAccumR⋆ (∹ xs) = map₁ ∹_ (mapAccumR⁺ xs)
mapAccumR⁺ (x & xs) =
let ys , y = mapAccumR⋆ xs
zs , z = f x y
in (zs & ys) , z
------------------------------------------------------------------------
-- Non-Empty Folds
module _ {a} {A : Set a} where
last : A ⁺ → A
last (x & []) = x
last (_ & (∹ xs)) = last xs
module _ {a} {A : Set a} (f : A → A → A) where
foldr1 : A ⁺ → A
foldr1 (x & []) = x
foldr1 (x & (∹ xs)) = f x (foldr1 xs)
foldl1 : A ⁺ → A
foldl1 (x & xs) = foldl⋆ f x xs
module _ {a b} {A : Set a} {B : Set b} (f : A → Maybe B → B) where
foldrMay⋆ : A ⋆ → Maybe B
foldrMay⁺ : A ⁺ → B
foldrMay⋆ [] = nothing
foldrMay⋆ (∹ xs) = just (foldrMay⁺ xs)
foldrMay⁺ xs = f (head xs) (foldrMay⋆ (tail xs))
------------------------------------------------------------------------
-- Indexing
module _ {a} {A : Set a} where
_[_]⋆ : A ⋆ → ℕ → Maybe A
_[_]⁺ : A ⁺ → ℕ → Maybe A
[] [ _ ]⋆ = nothing
(∹ xs) [ i ]⋆ = xs [ i ]⁺
xs [ zero ]⁺ = just (head xs)
xs [ suc i ]⁺ = tail xs [ i ]⋆
applyUpTo⋆ : (ℕ → A) → ℕ → A ⋆
applyUpTo⁺ : (ℕ → A) → ℕ → A ⁺
applyUpTo⋆ f zero = []
applyUpTo⋆ f (suc n) = ∹ applyUpTo⁺ f n
head (applyUpTo⁺ f n) = f zero
tail (applyUpTo⁺ f n) = applyUpTo⋆ (f ∘ suc) n
upTo⋆ : ℕ → ℕ ⋆
upTo⋆ = applyUpTo⋆ id
upTo⁺ : ℕ → ℕ ⁺
upTo⁺ = applyUpTo⁺ id
------------------------------------------------------------------------
-- Manipulation
module _ {a} {A : Set a} (x : A) where
intersperse⁺ : A ⁺ → A ⁺
intersperse⋆ : A ⋆ → A ⋆
head (intersperse⁺ xs) = head xs
tail (intersperse⁺ xs) = prepend (tail xs)
where
prepend : A ⋆ → A ⋆
prepend [] = []
prepend (∹ xs) = ∹ x & ∹ intersperse⁺ xs
intersperse⋆ [] = []
intersperse⋆ (∹ xs) = ∹ intersperse⁺ xs
module _ {a} {A : Set a} where
_⁺<|>⁺_ : A ⁺ → A ⁺ → A ⁺
_⁺<|>⋆_ : A ⁺ → A ⋆ → A ⁺
_⋆<|>⁺_ : A ⋆ → A ⁺ → A ⁺
_⋆<|>⋆_ : A ⋆ → A ⋆ → A ⋆
head (xs ⁺<|>⁺ ys) = head xs
tail (xs ⁺<|>⁺ ys) = ∹ (ys ⁺<|>⋆ tail xs)
head (xs ⁺<|>⋆ ys) = head xs
tail (xs ⁺<|>⋆ ys) = ys ⋆<|>⋆ tail xs
[] ⋆<|>⁺ ys = ys
(∹ xs) ⋆<|>⁺ ys = xs ⁺<|>⁺ ys
[] ⋆<|>⋆ ys = ys
(∹ xs) ⋆<|>⋆ ys = ∹ (xs ⁺<|>⋆ ys)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B → C) where
⁺zipWith⁺ : A ⁺ → B ⁺ → C ⁺
⋆zipWith⁺ : A ⋆ → B ⁺ → C ⋆
⁺zipWith⋆ : A ⁺ → B ⋆ → C ⋆
⋆zipWith⋆ : A ⋆ → B ⋆ → C ⋆
head (⁺zipWith⁺ xs ys) = f (head xs) (head ys)
tail (⁺zipWith⁺ xs ys) = ⋆zipWith⋆ (tail xs) (tail ys)
⋆zipWith⁺ [] ys = []
⋆zipWith⁺ (∹ xs) ys = ∹ ⁺zipWith⁺ xs ys
⁺zipWith⋆ xs [] = []
⁺zipWith⋆ xs (∹ ys) = ∹ ⁺zipWith⁺ xs ys
⋆zipWith⋆ [] ys = []
⋆zipWith⋆ (∹ xs) ys = ⁺zipWith⋆ xs ys
module Unzip {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B × C) where
cons : B × C → B ⋆ × C ⋆ → B ⁺ × C ⁺
head (proj₁ (cons x xs)) = proj₁ x
tail (proj₁ (cons x xs)) = proj₁ xs
head (proj₂ (cons x xs)) = proj₂ x
tail (proj₂ (cons x xs)) = proj₂ xs
unzipWith⋆ : A ⋆ → B ⋆ × C ⋆
unzipWith⁺ : A ⁺ → B ⁺ × C ⁺
unzipWith⋆ = foldr⋆ (λ x xs → Product.map ∹_ ∹_ (cons (f x) xs)) ([] , [])
unzipWith⁺ xs = cons (f (head xs)) (unzipWith⋆ (tail xs))
open Unzip using (unzipWith⁺; unzipWith⋆) public
module Partition {a b c} {A : Set a} {B : Set b} {C : Set c} (f : A → B ⊎ C) where
cons : B ⊎ C → B ⋆ × C ⋆ → B ⋆ × C ⋆
proj₁ (cons (inj₁ x) xs) = ∹ x & proj₁ xs
proj₂ (cons (inj₁ x) xs) = proj₂ xs
proj₂ (cons (inj₂ x) xs) = ∹ x & proj₂ xs
proj₁ (cons (inj₂ x) xs) = proj₁ xs
partitionSumsWith⋆ : A ⋆ → B ⋆ × C ⋆
partitionSumsWith⁺ : A ⁺ → B ⋆ × C ⋆
partitionSumsWith⋆ = foldr⋆ (cons ∘ f) ([] , [])
partitionSumsWith⁺ = foldr⁺ (cons ∘ f) ([] , [])
open Partition using (partitionSumsWith⁺; partitionSumsWith⋆) public
module _ {a} {A : Set a} where
⋆transpose⋆ : (A ⋆) ⋆ → (A ⋆) ⋆
⋆transpose⁺ : (A ⋆) ⁺ → (A ⁺) ⋆
⁺transpose⋆ : (A ⁺) ⋆ → (A ⋆) ⁺
⁺transpose⁺ : (A ⁺) ⁺ → (A ⁺) ⁺
⋆transpose⋆ [] = []
⋆transpose⋆ (∹ xs) = map⋆ ∹_ (⋆transpose⁺ xs)
⋆transpose⁺ (x & []) = map⋆ pure⁺ x
⋆transpose⁺ (x & (∹ xs)) = ⋆zipWith⋆ (λ y z → y & ∹ z) x (⋆transpose⁺ xs)
⁺transpose⋆ [] = [] & []
⁺transpose⋆ (∹ xs) = map⁺ ∹_ (⁺transpose⁺ xs)
⁺transpose⁺ (x & []) = map⁺ pure⁺ x
⁺transpose⁺ (x & (∹ xs)) = ⁺zipWith⁺ (λ y z → y & ∹ z) x (⁺transpose⁺ xs)
module _ {a} {A : Set a} where
tails⋆ : A ⋆ → (A ⁺) ⋆
tails⁺ : A ⁺ → (A ⁺) ⁺
head (tails⁺ xs) = xs
tail (tails⁺ xs) = tails⋆ (tail xs)
tails⋆ [] = []
tails⋆ (∹ xs) = ∹ tails⁺ xs
module _ {a} {A : Set a} where
reverse⋆ : A ⋆ → A ⋆
reverse⋆ = foldl⋆ (λ xs x → ∹ x & xs) []
reverse⁺ : A ⁺ → A ⁺
reverse⁺ (x & xs) = foldl⋆ (λ ys y → y & (∹ ys)) (x & []) xs
| {
"alphanum_fraction": 0.429031943,
"avg_line_length": 26.2487179487,
"ext": "agda",
"hexsha": "c5bac97156d193f3ffbd67716e8ed36a8a6be4a9",
"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": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-kleene-lists",
"max_forks_repo_path": "Data/List/Kleene/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-kleene-lists",
"max_issues_repo_path": "Data/List/Kleene/Base.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-kleene-lists",
"max_stars_repo_path": "Data/List/Kleene/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4796,
"size": 10237
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Unary.Raw where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude using (isProp)
open import Cubical.Data.Empty hiding (rec)
open import Cubical.Data.Unit.Base using (⊤)
open import Cubical.Data.Sigma
open import Cubical.Data.Sum.Base using (_⊎_; rec)
open import Cubical.Foundations.Function
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.Decidable using (IsYes)
open import Cubical.Relation.Unary using (RawPred)
private
variable
a b c ℓ ℓ₁ ℓ₂ : Level
A : Type a
B : Type b
C : Type c
------------------------------------------------------------------------
-- Special sets
-- The empty set.
∅ : RawPred A _
∅ = λ _ → ⊥
-- The singleton set.
{_} : A → RawPred A _
{ x } = _≡ x
-- The universal set.
U : RawPred A _
U = λ _ → ⊤
------------------------------------------------------------------------
-- Membership
infix 6 _∈_ _∉_
_∈_ : A → RawPred A ℓ → Type _
x ∈ P = P x
_∉_ : A → RawPred A ℓ → Type _
x ∉ P = ¬ x ∈ P
------------------------------------------------------------------------
-- Subset relations
infix 6 _⊆_ _⊇_ _⊈_ _⊉_ _⊂_ _⊃_ _⊄_ _⊅_
_⊆_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q
_⊇_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⊇ Q = Q ⊆ P
_⊈_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⊈ Q = ¬ (P ⊆ Q)
_⊉_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⊉ Q = ¬ (P ⊇ Q)
_⊂_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⊂ Q = P ⊆ Q × Q ⊈ P
_⊃_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⊃ Q = Q ⊂ P
_⊄_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⊄ Q = ¬ (P ⊂ Q)
_⊅_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⊅ Q = ¬ (P ⊃ Q)
------------------------------------------------------------------------
-- Properties of sets
infix 10 Satisfiable Universal IUniversal
-- Emptiness - no element satisfies P.
Empty : RawPred A ℓ → Type _
Empty P = ∀ x → x ∉ P
-- Satisfiable - at least one element satisfies P.
Satisfiable : RawPred A ℓ → Type _
Satisfiable {A = A} P = ∃[ x ∈ A ] x ∈ P
syntax Satisfiable P = ∃⟨ P ⟩
-- Universality - all elements satisfy P.
Universal : RawPred A ℓ → Type _
Universal P = ∀ x → x ∈ P
syntax Universal P = Π[ P ]
-- Implicit universality - all elements satisfy P.
IUniversal : RawPred A ℓ → Type _
IUniversal P = ∀ {x} → x ∈ P
syntax IUniversal P = ∀[ P ]
-- Decidability - it is possible to determine if an arbitrary element
-- satisfies P.
Decidable : RawPred A ℓ → Type _
Decidable P = ∀ x → Dec (P x)
-- Disjointness - Any element satisfying both P and Q is contradictory.
_⊃⊂_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
_⊃⊂_ P Q = ∀ {x} → x ∈ P → x ∈ Q → ⊥
-- Positive version of non-disjointness, dual to inclusion.
_≬_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
_≬_ {A = A} P Q = ∃[ x ∈ A ] x ∈ P × x ∈ Q
------------------------------------------------------------------------
-- Operations on sets
infix 10 ⋃ ⋂
infixr 9 _⊢_
infixr 8 _⇒_
infixr 7 _∩_
infixr 6 _∪_
infix 5 _≬_
-- Complement.
∁ : RawPred A ℓ → RawPred A ℓ
∁ P = λ x → x ∉ P
-- Implication.
_⇒_ : RawPred A ℓ₁ → RawPred A ℓ₂ → RawPred A _
P ⇒ Q = λ x → x ∈ P → x ∈ Q
-- Union.
_∪_ : RawPred A ℓ₁ → RawPred A ℓ₂ → RawPred A _
P ∪ Q = λ x → x ∈ P ⊎ x ∈ Q
-- Intersection.
_∩_ : RawPred A ℓ₁ → RawPred A ℓ₂ → RawPred A _
P ∩ Q = λ x → x ∈ P × x ∈ Q
-- Infinitary union.
⋃ : ∀ {i} (I : Type i) → (I → RawPred A ℓ) → RawPred A _
⋃ I P = λ x → Σ[ i ∈ I ] P i x
syntax ⋃ I (λ i → P) = ⋃[ i ∶ I ] P
-- Infinitary intersection.
⋂ : ∀ {i} (I : Type i) → (I → RawPred A ℓ) → RawPred A _
⋂ I P = λ x → (i : I) → P i x
syntax ⋂ I (λ i → P) = ⋂[ i ∶ I ] P
-- Preimage.
_⊢_ : (A → B) → RawPred B ℓ → RawPred A ℓ
f ⊢ P = λ x → P (f x)
------------------------------------------------------------------------
-- Preservation under operations
_Preserves_⟶_ : (A → B) → RawPred A ℓ₁ → RawPred B ℓ₂ → Type _
f Preserves P ⟶ Q = P ⊆ f ⊢ Q
_Preserves_ : (A → A) → RawPred A ℓ → Type _
f Preserves P = f Preserves P ⟶ P
-- A binary variant of _Preserves_⟶_.
_Preserves₂_⟶_⟶_ : (A → B → C) → RawPred A ℓ₁ → RawPred B ℓ₂ → RawPred C ℓ → Type _
_∙_ Preserves₂ P ⟶ Q ⟶ R = ∀ {x y} → x ∈ P → y ∈ Q → x ∙ y ∈ R
_Preserves₂_ : (A → A → A) → RawPred A ℓ → Type _
_∙_ Preserves₂ P = _∙_ Preserves₂ P ⟶ P ⟶ P
------------------------------------------------------------------------
-- Logical equivalence
_⇔_ : RawPred A ℓ₁ → RawPred A ℓ₂ → Type _
P ⇔ Q = Π[ P ⇒ Q ∩ Q ⇒ P ]
------------------------------------------------------------------------
-- Predicate combinators
-- These differ from the set operations above, as the carrier set of the
-- resulting predicates are not the same as the carrier set of the
-- component predicates.
infixr 2 _⟨×⟩_
infixr 2 _⟨⊙⟩_
infixr 1 _⟨⊎⟩_
infixr 0 _⟨→⟩_
infixl 9 _⟨·⟩_
infix 10 _~
infixr 9 _⟨∘⟩_
infixr 2 _//_ _\\_
-- Product.
_⟨×⟩_ : RawPred A ℓ₁ → RawPred B ℓ₂ → RawPred (A × B) _
(P ⟨×⟩ Q) (x , y) = x ∈ P × y ∈ Q
-- Sum over one element.
_⟨⊎⟩_ : RawPred A ℓ → RawPred B ℓ → RawPred (A ⊎ B) _
P ⟨⊎⟩ Q = rec P Q
-- Sum over two elements.
_⟨⊙⟩_ : RawPred A ℓ₁ → RawPred B ℓ₂ → RawPred (A × B) _
(P ⟨⊙⟩ Q) (x , y) = x ∈ P ⊎ y ∈ Q
-- Implication.
_⟨→⟩_ : RawPred A ℓ₁ → RawPred B ℓ₂ → RawPred (A → B) _
(P ⟨→⟩ Q) f = f Preserves P ⟶ Q
-- Product.
_⟨·⟩_ : (P : RawPred A ℓ₁) (Q : RawPred B ℓ₂) →
(P ⟨×⟩ (P ⟨→⟩ Q)) ⊆ Q ∘ uncurry (flip _$_)
(P ⟨·⟩ Q) (p , f) = f p
-- Converse.
_~ : RawPred (A × B) ℓ → RawPred (B × A) ℓ
P ~ = P ∘ λ { (x , y) → y , x }
-- Composition.
_⟨∘⟩_ : RawPred (A × B) ℓ₁ → RawPred (B × C) ℓ₂ → RawPred (A × C) _
_⟨∘⟩_ {B = B} P Q (x , z) = ∃[ y ∈ B ] (x , y) ∈ P × (y , z) ∈ Q
-- Post-division.
_//_ : RawPred (A × C) ℓ₁ → RawPred (B × C) ℓ₂ → RawPred (A × B) _
(P // Q) (x , y) = Q ∘ (y ,_) ⊆ P ∘ (x ,_)
-- Pre-division.
_\\_ : RawPred (A × C) ℓ₁ → RawPred (A × B) ℓ₂ → RawPred (B × C) _
P \\ Q = (P ~ // Q ~) ~
| {
"alphanum_fraction": 0.5152181265,
"avg_line_length": 22.4866920152,
"ext": "agda",
"hexsha": "85071890f3a4a0e53ce819c6f46b2277980d5468",
"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": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Unary/Raw.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"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": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Unary/Raw.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Unary/Raw.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2354,
"size": 5914
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Definitions of algebraic structures like monoids and rings
-- (packed in records together with sets, operations, etc.)
------------------------------------------------------------------------
module Algebra where
open import Relation.Binary
open import Algebra.FunctionProperties
open import Algebra.Structures
open import Function
open import Level
------------------------------------------------------------------------
-- Semigroups, (commutative) monoids and (abelian) groups
record Semigroup c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
isSemigroup : IsSemigroup _≈_ _∙_
open IsSemigroup isSemigroup public
setoid : Setoid _ _
setoid = record { isEquivalence = isEquivalence }
-- A raw monoid is a monoid without any laws.
record RawMonoid c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
ε : Carrier
record Monoid c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
ε : Carrier
isMonoid : IsMonoid _≈_ _∙_ ε
open IsMonoid isMonoid public
semigroup : Semigroup _ _
semigroup = record { isSemigroup = isSemigroup }
open Semigroup semigroup public using (setoid)
rawMonoid : RawMonoid _ _
rawMonoid = record
{ _≈_ = _≈_
; _∙_ = _∙_
; ε = ε
}
record CommutativeMonoid c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
ε : Carrier
isCommutativeMonoid : IsCommutativeMonoid _≈_ _∙_ ε
open IsCommutativeMonoid isCommutativeMonoid public
monoid : Monoid _ _
monoid = record { isMonoid = isMonoid }
open Monoid monoid public using (setoid; semigroup; rawMonoid)
record Group c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 _⁻¹
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
ε : Carrier
_⁻¹ : Op₁ Carrier
isGroup : IsGroup _≈_ _∙_ ε _⁻¹
open IsGroup isGroup public
monoid : Monoid _ _
monoid = record { isMonoid = isMonoid }
open Monoid monoid public using (setoid; semigroup; rawMonoid)
record AbelianGroup c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 _⁻¹
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
ε : Carrier
_⁻¹ : Op₁ Carrier
isAbelianGroup : IsAbelianGroup _≈_ _∙_ ε _⁻¹
open IsAbelianGroup isAbelianGroup public
group : Group _ _
group = record { isGroup = isGroup }
open Group group public using (setoid; semigroup; monoid; rawMonoid)
commutativeMonoid : CommutativeMonoid _ _
commutativeMonoid =
record { isCommutativeMonoid = isCommutativeMonoid }
------------------------------------------------------------------------
-- Various kinds of semirings
record NearSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
0# : Carrier
isNearSemiring : IsNearSemiring _≈_ _+_ _*_ 0#
open IsNearSemiring isNearSemiring public
+-monoid : Monoid _ _
+-monoid = record { isMonoid = +-isMonoid }
open Monoid +-monoid public
using (setoid)
renaming ( semigroup to +-semigroup
; rawMonoid to +-rawMonoid)
*-semigroup : Semigroup _ _
*-semigroup = record { isSemigroup = *-isSemigroup }
record SemiringWithoutOne c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
0# : Carrier
isSemiringWithoutOne : IsSemiringWithoutOne _≈_ _+_ _*_ 0#
open IsSemiringWithoutOne isSemiringWithoutOne public
nearSemiring : NearSemiring _ _
nearSemiring = record { isNearSemiring = isNearSemiring }
open NearSemiring nearSemiring public
using ( setoid
; +-semigroup; +-rawMonoid; +-monoid
; *-semigroup
)
+-commutativeMonoid : CommutativeMonoid _ _
+-commutativeMonoid =
record { isCommutativeMonoid = +-isCommutativeMonoid }
record SemiringWithoutAnnihilatingZero c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
0# : Carrier
1# : Carrier
isSemiringWithoutAnnihilatingZero :
IsSemiringWithoutAnnihilatingZero _≈_ _+_ _*_ 0# 1#
open IsSemiringWithoutAnnihilatingZero
isSemiringWithoutAnnihilatingZero public
+-commutativeMonoid : CommutativeMonoid _ _
+-commutativeMonoid =
record { isCommutativeMonoid = +-isCommutativeMonoid }
open CommutativeMonoid +-commutativeMonoid public
using (setoid)
renaming ( semigroup to +-semigroup
; rawMonoid to +-rawMonoid
; monoid to +-monoid
)
*-monoid : Monoid _ _
*-monoid = record { isMonoid = *-isMonoid }
open Monoid *-monoid public
using ()
renaming ( semigroup to *-semigroup
; rawMonoid to *-rawMonoid
)
record Semiring c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
0# : Carrier
1# : Carrier
isSemiring : IsSemiring _≈_ _+_ _*_ 0# 1#
open IsSemiring isSemiring public
semiringWithoutAnnihilatingZero : SemiringWithoutAnnihilatingZero _ _
semiringWithoutAnnihilatingZero = record
{ isSemiringWithoutAnnihilatingZero =
isSemiringWithoutAnnihilatingZero
}
open SemiringWithoutAnnihilatingZero
semiringWithoutAnnihilatingZero public
using ( setoid
; +-semigroup; +-rawMonoid; +-monoid
; +-commutativeMonoid
; *-semigroup; *-rawMonoid; *-monoid
)
semiringWithoutOne : SemiringWithoutOne _ _
semiringWithoutOne =
record { isSemiringWithoutOne = isSemiringWithoutOne }
open SemiringWithoutOne semiringWithoutOne public
using (nearSemiring)
record CommutativeSemiringWithoutOne c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
0# : Carrier
isCommutativeSemiringWithoutOne :
IsCommutativeSemiringWithoutOne _≈_ _+_ _*_ 0#
open IsCommutativeSemiringWithoutOne
isCommutativeSemiringWithoutOne public
semiringWithoutOne : SemiringWithoutOne _ _
semiringWithoutOne =
record { isSemiringWithoutOne = isSemiringWithoutOne }
open SemiringWithoutOne semiringWithoutOne public
using ( setoid
; +-semigroup; +-rawMonoid; +-monoid
; +-commutativeMonoid
; *-semigroup
; nearSemiring
)
record CommutativeSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
0# : Carrier
1# : Carrier
isCommutativeSemiring : IsCommutativeSemiring _≈_ _+_ _*_ 0# 1#
open IsCommutativeSemiring isCommutativeSemiring public
semiring : Semiring _ _
semiring = record { isSemiring = isSemiring }
open Semiring semiring public
using ( setoid
; +-semigroup; +-rawMonoid; +-monoid
; +-commutativeMonoid
; *-semigroup; *-rawMonoid; *-monoid
; nearSemiring; semiringWithoutOne
; semiringWithoutAnnihilatingZero
)
*-commutativeMonoid : CommutativeMonoid _ _
*-commutativeMonoid =
record { isCommutativeMonoid = *-isCommutativeMonoid }
commutativeSemiringWithoutOne : CommutativeSemiringWithoutOne _ _
commutativeSemiringWithoutOne = record
{ isCommutativeSemiringWithoutOne = isCommutativeSemiringWithoutOne
}
------------------------------------------------------------------------
-- (Commutative) rings
-- A raw ring is a ring without any laws.
record RawRing c : Set (suc c) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
field
Carrier : Set c
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
1# : Carrier
record Ring c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
1# : Carrier
isRing : IsRing _≈_ _+_ _*_ -_ 0# 1#
open IsRing isRing public
+-abelianGroup : AbelianGroup _ _
+-abelianGroup = record { isAbelianGroup = +-isAbelianGroup }
semiring : Semiring _ _
semiring = record { isSemiring = isSemiring }
open Semiring semiring public
using ( setoid
; +-semigroup; +-rawMonoid; +-monoid
; +-commutativeMonoid
; *-semigroup; *-rawMonoid; *-monoid
; nearSemiring; semiringWithoutOne
; semiringWithoutAnnihilatingZero
)
open AbelianGroup +-abelianGroup public
using () renaming (group to +-group)
rawRing : RawRing _
rawRing = record
{ _+_ = _+_
; _*_ = _*_
; -_ = -_
; 0# = 0#
; 1# = 1#
}
record CommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
1# : Carrier
isCommutativeRing : IsCommutativeRing _≈_ _+_ _*_ -_ 0# 1#
open IsCommutativeRing isCommutativeRing public
ring : Ring _ _
ring = record { isRing = isRing }
commutativeSemiring : CommutativeSemiring _ _
commutativeSemiring =
record { isCommutativeSemiring = isCommutativeSemiring }
open Ring ring public using (rawRing; +-group; +-abelianGroup)
open CommutativeSemiring commutativeSemiring public
using ( setoid
; +-semigroup; +-rawMonoid; +-monoid; +-commutativeMonoid
; *-semigroup; *-rawMonoid; *-monoid; *-commutativeMonoid
; nearSemiring; semiringWithoutOne
; semiringWithoutAnnihilatingZero; semiring
; commutativeSemiringWithoutOne
)
------------------------------------------------------------------------
-- (Distributive) lattices and boolean algebras
record Lattice c ℓ : Set (suc (c ⊔ ℓ)) where
infixr 7 _∧_
infixr 6 _∨_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∨_ : Op₂ Carrier
_∧_ : Op₂ Carrier
isLattice : IsLattice _≈_ _∨_ _∧_
open IsLattice isLattice public
setoid : Setoid _ _
setoid = record { isEquivalence = isEquivalence }
record DistributiveLattice c ℓ : Set (suc (c ⊔ ℓ)) where
infixr 7 _∧_
infixr 6 _∨_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∨_ : Op₂ Carrier
_∧_ : Op₂ Carrier
isDistributiveLattice : IsDistributiveLattice _≈_ _∨_ _∧_
open IsDistributiveLattice isDistributiveLattice public
lattice : Lattice _ _
lattice = record { isLattice = isLattice }
open Lattice lattice public using (setoid)
record BooleanAlgebra c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 ¬_
infixr 7 _∧_
infixr 6 _∨_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∨_ : Op₂ Carrier
_∧_ : Op₂ Carrier
¬_ : Op₁ Carrier
⊤ : Carrier
⊥ : Carrier
isBooleanAlgebra : IsBooleanAlgebra _≈_ _∨_ _∧_ ¬_ ⊤ ⊥
open IsBooleanAlgebra isBooleanAlgebra public
distributiveLattice : DistributiveLattice _ _
distributiveLattice =
record { isDistributiveLattice = isDistributiveLattice }
open DistributiveLattice distributiveLattice public
using (setoid; lattice)
| {
"alphanum_fraction": 0.5684838417,
"avg_line_length": 27.94092827,
"ext": "agda",
"hexsha": "0607fbccabe946625153c973e40753384cf68c6b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Algebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Algebra.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/Algebra.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": 4046,
"size": 13244
} |
-- Some extra properties of integers.
{-# OPTIONS --without-K --safe #-}
module Integer.Properties where
-- imports from stdlib.
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality as PE
using (_≡_ ; refl ; sym ; cong ; trans ; cong₂)
open import Data.Sum using (_⊎_ ; inj₁ ; inj₂)
open import Data.Product as P using (_×_ ; _,_ ; ∃ ; proj₁ ; proj₂)
open import Data.Nat as Nat using (ℕ ; suc ; zero ; z≤n)
import Data.Nat.Solver as NS
open import Data.Integer as Int
using (ℤ ; ∣_∣ ; +_ ; +[1+_] ; -[1+_] ; 1ℤ ; +<+ ; -<- ; -≤- ; -<+ ; -≤+ ; +≤+ ; 0ℤ ; NonNegative ; +0)
import Data.Integer.Properties as IntP
open import Function
-- imports from local.
open import Instances
-- Triangle equality.
tri-eq : ∀ (a b : ℤ) .{{_ : NonNegative a}} .{{_ : NonNegative b}} -> ∣ a + b ∣ ≡ ∣ a ∣ + ∣ b ∣
tri-eq (+_ a) (+_ b) = begin
∣ + a + + b ∣ ≡⟨ refl ⟩
∣ + (a + b) ∣ ≡⟨ refl ⟩
a + b ≡⟨ refl ⟩
∣ + a ∣ + ∣ + b ∣ ∎
where
open PE.≡-Reasoning
-- For all a, a * a is always non-negative.
a*a=+b : ∀ a -> ∃ λ b → a * a ≡ + b
a*a=+b (+_ a) = (a * a) , IntP.pos-distrib-* a a
a*a=+b (-[1+_] a) = suc a * suc a , refl
0≤a*a : ∀ {a} → 0ℤ ≤ a * a
0≤a*a {a} rewrite proj₂ $ a*a=+b a = +≤+ Nat.z≤n
-- For non-zero natrual number a, a * a is always positive.
a*a-pos : ∀ (a : ℕ) .{{_ : Nat.NonZero a}} -> ∃ λ n → a * a ≡ suc n
a*a-pos (suc b) = b * b + 2 * b , claim
where
claim : suc b * suc b ≡ suc (b * b + 2 * b)
claim =
begin
suc b * suc b ≡⟨ refl ⟩
(1 + b) * (1 + b) ≡⟨ solve 1 (λ b → (con 1 :+ b) :* (con 1 :+ b) := con 1 :+ (b :* b :+ con 2 :* b)) refl b ⟩
1 + (b * b + 2 * b) ≡⟨ refl ⟩
suc (b * b + 2 * b) ∎
where
open NS.+-*-Solver
open PE.≡-Reasoning
a*a-pos' : ∀ (a : ℤ) .{{_ : NonZero a}} -> ∃ λ n → a * a ≡ + (suc n)
a*a-pos' +[1+ n ] rewrite proj₂ $ a*a-pos (suc n) = (proj₁ $ a*a-pos (suc n)) , refl
a*a-pos' -[1+ n ] rewrite proj₂ $ a*a-pos (suc n) = (proj₁ $ a*a-pos (suc n)) , refl
-- For an non-zero integer a, ∣ a * a ∣ is always positive.
∣a*a∣-pos : ∀ (a : ℤ) .{{_ : NonZero a}} -> ∃ λ n → ∣ a * a ∣ ≡ suc n
∣a*a∣-pos (+ (suc b)) = b * b + 2 * b , claim
where
claim : suc b * suc b ≡ suc (b * b + 2 * b)
claim = proj₂ $ a*a-pos (suc b)
∣a*a∣-pos (-[1+_] b) = b * b + 2 * b , claim
where
claim : suc b * suc b ≡ suc (b * b + 2 * b)
claim = proj₂ $ a*a-pos (suc b)
+∣a*a∣=a*a : ∀ (a : ℤ) -> + ∣ a * a ∣ ≡ a * a
+∣a*a∣=a*a a = IntP.0≤i⇒+∣i∣≡i (0≤a*a {a})
pos : ∀ {a : ℤ} -> ¬ a ≡ 0ℤ -> 0ℤ < a * a
pos {+_ zero} n0 with n0 refl
... | ()
pos {a@(+[1+ n ])} n0 rewrite proj₂ $ a*a-pos' a = +<+ (Nat.s≤s Nat.z≤n)
pos {a@(-[1+ n ])} n0 rewrite proj₂ $ a*a-pos' a = +<+ (Nat.s≤s Nat.z≤n)
pos' : ∀ {a} -> 0ℤ < a -> Nat.NonZero ∣ a ∣
pos' {(+_ zero)} (+<+ ())
pos' {+[1+ n ]} l = record { nonZero = _ }
-- ∣ a * a + b * b ∣ is not zero if one of a and b is.
∣aa+bb∣-nonzero : ∀ a b -> ¬ a ≡ 0ℤ ⊎ ¬ b ≡ 0ℤ -> Nat.NonZero ∣ a * a + b * b ∣
∣aa+bb∣-nonzero a b (inj₁ x) = pos' (IntP.+-mono-<-≤ (pos x) (0≤a*a {b}))
∣aa+bb∣-nonzero a b (inj₂ y) = pos' (IntP.+-mono-≤-< (0≤a*a {a}) (pos y))
-- ----------------------------------------------------------------------
-- Properties of aa + bb
-- A special case of tri-eq.
tri-eq' : ∀ a b -> ∣ a * a + b * b ∣ ≡ ∣ a * a ∣ + ∣ b * b ∣
tri-eq' a b = begin
let (sa , sae) = (a*a=+b a) in let (sb , sbe) = a*a=+b b in
∣ a * a + b * b ∣ ≡⟨ cong (λ x → ∣ x ∣) (cong₂ _+_ sae sbe) ⟩
∣ + sa + + sb ∣ ≡⟨ (tri-eq (+ sa) (+ sb)) ⟩
∣ + sa ∣ + ∣ + sb ∣ ≡⟨ cong₂ _+_ (cong ∣_∣ (sym sae)) (cong ∣_∣ (sym sbe)) ⟩
∣ a * a ∣ + ∣ b * b ∣ ∎
where
open PE.≡-Reasoning
-- A property of a pair of integers.
a=0×b=0⇒aa+bb=0 : ∀ {a b : ℤ} -> a ≡ 0ℤ × b ≡ 0ℤ -> a * a + b * b ≡ 0ℤ
a=0×b=0⇒aa+bb=0 {.0ℤ} {.0ℤ} (refl , refl) = refl
aa+bb=0⇒a=0×b=0 : ∀ {a b : ℤ} -> a * a + b * b ≡ 0ℤ -> a ≡ 0ℤ × b ≡ 0ℤ
aa+bb=0⇒a=0×b=0 {a} {b} eq = P.map x^2=0⇒x=0 x^2=0⇒x=0 $ z+z (0≤a*a {a}) (0≤a*a {b}) eq
where
z+z : ∀ {x y} -> 0ℤ ≤ x -> 0ℤ ≤ y -> x + y ≡ 0ℤ -> x ≡ 0ℤ × y ≡ 0ℤ
z+z {.+0} {.(+ _)} (+≤+ {n = zero} z≤n) (+≤+ z≤n) x+y=0 = (refl , x+y=0)
z+z {.(+[1+ n ])} {.+0} (+≤+ {n = ℕ.suc n} z≤n) (+≤+ {n = zero} m≤n) ()
z+z {.(+[1+ n ])} {.(+[1+ n₁ ])} (+≤+ {n = ℕ.suc n} z≤n) (+≤+ {n = ℕ.suc n₁} m≤n) ()
x^2=0⇒x=0 : ∀ {x} -> x * x ≡ 0ℤ -> x ≡ 0ℤ
x^2=0⇒x=0 {+_ zero} eq = refl
| {
"alphanum_fraction": 0.4423983831,
"avg_line_length": 36.5,
"ext": "agda",
"hexsha": "115ce55a06e2e614ed2670dce7fc24ddbf032672",
"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": "Integer/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "onestruggler/EucDomain",
"max_issues_repo_path": "Integer/Properties.agda",
"max_line_length": 118,
"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": "Integer/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2198,
"size": 4453
} |
module FRP.LTL.RSet where
open import FRP.LTL.RSet.Core public using ( RSet ; ⟨_⟩ ; ⟦_⟧ )
-- Propositional logic
open import FRP.LTL.RSet.Unit public using ( T )
open import FRP.LTL.RSet.Empty public using ( F )
open import FRP.LTL.RSet.Product public using ( _∧_ ; fst ; snd ; _&&&_ )
open import FRP.LTL.RSet.Sum public using ( _∨_ )
open import FRP.LTL.RSet.Stateless public using ( _⇒_ )
-- LTL
open import FRP.LTL.RSet.Next public using ( ○ )
open import FRP.LTL.RSet.Future public using ( ◇ )
open import FRP.LTL.RSet.Globally public using ( □ ; [_] )
open import FRP.LTL.RSet.Until public using ( _U_ )
open import FRP.LTL.RSet.Causal public using ( _⊵_ ; arr ; identity ; _⋙_ )
open import FRP.LTL.RSet.Decoupled public using ( _▹_ )
| {
"alphanum_fraction": 0.7054886212,
"avg_line_length": 35.5714285714,
"ext": "agda",
"hexsha": "9df82a77d0f37a4d766b9a0f30a4bb1e07b919c7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z",
"max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-frp-ltl",
"max_forks_repo_path": "src/FRP/LTL/RSet.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-frp-ltl",
"max_issues_repo_path": "src/FRP/LTL/RSet.agda",
"max_line_length": 75,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-frp-ltl",
"max_stars_repo_path": "src/FRP/LTL/RSet.agda",
"max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z",
"num_tokens": 248,
"size": 747
} |
{-# OPTIONS --without-K #-}
module A2 where
open import Data.Nat
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product
infix 4 _≡_ -- propositional equality
infixr 10 _◎_
infixr 30 _⟷_
------------------------------------------------------------------------------
-- Our own version of refl that makes 'a' explicit
data _≡_ {ℓ} {A : Set ℓ} : (a b : A) → Set ℓ where
refl : (a : A) → (a ≡ a)
sym : ∀ {ℓ} {A : Set ℓ} {a b : A} → (a ≡ b) → (b ≡ a)
sym {a = a} {b = .a} (refl .a) = refl a
trans : ∀ {ℓ} {A : Set ℓ} {a b c : A} → (a ≡ b) → (b ≡ c) → (a ≡ c)
trans {a = a} {b = .a} {c = .a} (refl .a) (refl .a) = refl a
------------------------------------------------------------------------------
{--
Types are higher groupoids:
- 0 is empty
- 1 has one element and one path refl
- sum type is disjoint union; paths are component wise
- product type is cartesian product; paths are pairs of paths
--}
mutual
data U : Set where
ZERO : U
ONE : U
PLUS : U → U → U
TIMES : U → U → U
ID : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₁ ⟧ → ⟦ t₂ ⟧ → U
⟦_⟧ : U → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS t t' ⟧ = ⟦ t ⟧ ⊎ ⟦ t' ⟧
⟦ TIMES t t' ⟧ = ⟦ t ⟧ × ⟦ t' ⟧
⟦ ID {t₁} {t₂} c v₁ v₂ ⟧ = Paths {t₁} {t₂} c v₁ v₂
data _⟷_ : U → U → Set where
-- semiring axioms
unite₊ : {t : U} → PLUS ZERO t ⟷ t
uniti₊ : {t : U} → t ⟷ PLUS ZERO t
swap₊ : {t₁ t₂ : U} → PLUS t₁ t₂ ⟷ PLUS t₂ t₁
assocl₊ : {t₁ t₂ t₃ : U} → PLUS t₁ (PLUS t₂ t₃) ⟷ PLUS (PLUS t₁ t₂) t₃
assocr₊ : {t₁ t₂ t₃ : U} → PLUS (PLUS t₁ t₂) t₃ ⟷ PLUS t₁ (PLUS t₂ t₃)
unite⋆ : {t : U} → TIMES ONE t ⟷ t
uniti⋆ : {t : U} → t ⟷ TIMES ONE t
swap⋆ : {t₁ t₂ : U} → TIMES t₁ t₂ ⟷ TIMES t₂ t₁
assocl⋆ : {t₁ t₂ t₃ : U} → TIMES t₁ (TIMES t₂ t₃) ⟷ TIMES (TIMES t₁ t₂) t₃
assocr⋆ : {t₁ t₂ t₃ : U} → TIMES (TIMES t₁ t₂) t₃ ⟷ TIMES t₁ (TIMES t₂ t₃)
distz : {t : U} → TIMES ZERO t ⟷ ZERO
factorz : {t : U} → ZERO ⟷ TIMES ZERO t
dist : {t₁ t₂ t₃ : U} →
TIMES (PLUS t₁ t₂) t₃ ⟷ PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)
factor : {t₁ t₂ t₃ : U} →
PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) ⟷ TIMES (PLUS t₁ t₂) t₃
-- equivalence relation and 2 combinators
id⟷ : {t : U} → t ⟷ t
sym⟷ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁)
_◎_ : {t₁ t₂ t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (PLUS t₁ t₂ ⟷ PLUS t₃ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (TIMES t₁ t₂ ⟷ TIMES t₃ t₄)
-- and one level up
{-
lid : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {c : t₁ ⟷ t₂} →
ID (id⟷ ◎ c) v₁ v₂ ⟷ ID c v₁ v₂
rid : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {c : t₁ ⟷ t₂} →
ID (c ◎ id⟷) v₁ v₂ ⟷ ID c v₁ v₂
linv : {t₁ t₂ : U} {v : ⟦ t₂ ⟧} {c : t₁ ⟷ t₂} →
ID ((sym⟷ c) ◎ c) v v ⟷ ID {t₂} {t₂} id⟷ v v
rinv : {t₁ t₂ : U} {v : ⟦ t₁ ⟧} {c : t₁ ⟷ t₂} →
ID (c ◎ (sym⟷ c)) v v ⟷ ID {t₁} {t₁} id⟷ v v
invinv : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {c : t₁ ⟷ t₂} →
ID (sym⟷ (sym⟷ c)) v₁ v₂ ⟷ ID {t₁} {t₂} c v₁ v₂
assoc : {t₁ t₂ t₃ t₄ : U}
{v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {v₃ : ⟦ t₃ ⟧} {v₄ : ⟦ t₄ ⟧}
{c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} →
ID (c₁ ◎ (c₂ ◎ c₃)) v₁ v₄ ⟷ ID ((c₁ ◎ c₂) ◎ c₃) v₁ v₄
-}
-- add the other direction for lid, rid, linv, rinv, invinv, and assoc
data Unite₊ {t : U} : ⊥ ⊎ ⟦ t ⟧ → ⟦ t ⟧ → Set where
val_unite₊ : (v₁ : ⊥ ⊎ ⟦ t ⟧) → (v₂ : ⟦ t ⟧) → Unite₊ v₁ v₂
Paths : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₁ ⟧ → ⟦ t₂ ⟧ → Set
Paths unite₊ (inj₁ ())
Paths {PLUS ZERO t} {.t} unite₊ (inj₂ v) v' = (v ≡ v') × Unite₊ {t} (inj₂ v) v'
Paths uniti₊ v (inj₁ ())
Paths uniti₊ v (inj₂ v') = (v ≡ v')
Paths swap₊ (inj₁ v) (inj₁ v') = ⊥
Paths swap₊ (inj₁ v) (inj₂ v') = (v ≡ v')
Paths swap₊ (inj₂ v) (inj₁ v') = (v ≡ v')
Paths swap₊ (inj₂ v) (inj₂ v') = ⊥
Paths assocl₊ (inj₁ v) (inj₁ (inj₁ v')) = (v ≡ v')
Paths assocl₊ (inj₁ v) (inj₁ (inj₂ v')) = ⊥
Paths assocl₊ (inj₁ v) (inj₂ v') = ⊥
Paths assocl₊ (inj₂ (inj₁ v)) (inj₁ (inj₁ v')) = ⊥
Paths assocl₊ (inj₂ (inj₁ v)) (inj₁ (inj₂ v')) = (v ≡ v')
Paths assocl₊ (inj₂ (inj₁ v)) (inj₂ v') = ⊥
Paths assocl₊ (inj₂ (inj₂ v)) (inj₁ v') = ⊥
Paths assocl₊ (inj₂ (inj₂ v)) (inj₂ v') = (v ≡ v')
Paths assocr₊ (inj₁ (inj₁ v)) (inj₁ v') = (v ≡ v')
Paths assocr₊ (inj₁ (inj₁ v)) (inj₂ v') = ⊥
Paths assocr₊ (inj₁ (inj₂ v)) (inj₁ v') = ⊥
Paths assocr₊ (inj₁ (inj₂ v)) (inj₂ (inj₁ v')) = (v ≡ v')
Paths assocr₊ (inj₁ (inj₂ v)) (inj₂ (inj₂ v')) = ⊥
Paths assocr₊ (inj₂ v) (inj₁ v') = ⊥
Paths assocr₊ (inj₂ v) (inj₂ (inj₁ v')) = ⊥
Paths assocr₊ (inj₂ v) (inj₂ (inj₂ v')) = (v ≡ v')
Paths unite⋆ (tt , v) v' = (v ≡ v')
Paths uniti⋆ v (tt , v') = (v ≡ v')
Paths swap⋆ (v₁ , v₂) (v₂' , v₁') = (v₁ ≡ v₁') × (v₂ ≡ v₂')
Paths assocl⋆ (v₁ , (v₂ , v₃)) ((v₁' , v₂') , v₃') =
(v₁ ≡ v₁') × (v₂ ≡ v₂') × (v₃ ≡ v₃')
Paths assocr⋆ ((v₁ , v₂) , v₃) (v₁' , (v₂' , v₃')) =
(v₁ ≡ v₁') × (v₂ ≡ v₂') × (v₃ ≡ v₃')
Paths distz (() , v)
Paths factorz ()
Paths dist (inj₁ v₁ , v₃) (inj₁ (v₁' , v₃')) = (v₁ ≡ v₁') × (v₃ ≡ v₃')
Paths dist (inj₁ v₁ , v₃) (inj₂ (v₂' , v₃')) = ⊥
Paths dist (inj₂ v₂ , v₃) (inj₁ (v₁' , v₃')) = ⊥
Paths dist (inj₂ v₂ , v₃) (inj₂ (v₂' , v₃')) = (v₂ ≡ v₂') × (v₃ ≡ v₃')
Paths factor (inj₁ (v₁ , v₃)) (inj₁ v₁' , v₃') =
(v₁ ≡ v₁') × (v₃ ≡ v₃')
Paths factor (inj₁ (v₁ , v₃)) (inj₂ v₂' , v₃') = ⊥
Paths factor (inj₂ (v₂ , v₃)) (inj₁ v₁' , v₃') = ⊥
Paths factor (inj₂ (v₂ , v₃)) (inj₂ v₂' , v₃') =
(v₂ ≡ v₂') × (v₃ ≡ v₃')
Paths {t} id⟷ v v' = (v ≡ v')
Paths (sym⟷ c) v v' = PathsB c v v'
Paths (_◎_ {t₁} {t₂} {t₃} c₁ c₂) v v' =
Σ[ u ∈ ⟦ t₂ ⟧ ] (Paths c₁ v u × Paths c₂ u v')
Paths (c₁ ⊕ c₂) (inj₁ v) (inj₁ v') = Paths c₁ v v'
Paths (c₁ ⊕ c₂) (inj₁ v) (inj₂ v') = ⊥
Paths (c₁ ⊕ c₂) (inj₂ v) (inj₁ v') = ⊥
Paths (c₁ ⊕ c₂) (inj₂ v) (inj₂ v') = Paths c₂ v v'
Paths (c₁ ⊗ c₂) (v₁ , v₂) (v₁' , v₂') =
Paths c₁ v₁ v₁' × Paths c₂ v₂ v₂'
{-
Paths lid (v , refl .v , p) q = (p ≡ q)
Paths rid (v , p , refl .v) q = (p ≡ q)
Paths (linv {t₁} {v = v} {c}) (w , proj₂ , proj₃) y = {!!}
Paths rinv (proj₁ , proj₂ , proj₃) y = {!!}
Paths (invinv {c = c}) x y = {!!}
Paths assoc (v₂ , proj₂ , v₃ , proj₄ , proj₅) (w₃ , (w₂ , proj₈ , proj₉) , proj₁₀) = v₂ ≡ w₂ × v₃ ≡ w₃
-}
PathsB : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₂ ⟧ → ⟦ t₁ ⟧ → Set
PathsB unite₊ v (inj₁ ())
PathsB unite₊ v (inj₂ v') = (v ≡ v')
PathsB uniti₊ (inj₁ ())
PathsB uniti₊ (inj₂ v) v' = (v ≡ v')
PathsB swap₊ (inj₁ v) (inj₁ v') = ⊥
PathsB swap₊ (inj₁ v) (inj₂ v') = (v ≡ v')
PathsB swap₊ (inj₂ v) (inj₁ v') = (v ≡ v')
PathsB swap₊ (inj₂ v) (inj₂ v') = ⊥
PathsB assocl₊ (inj₁ (inj₁ v)) (inj₁ v') = (v ≡ v')
PathsB assocl₊ (inj₁ (inj₁ v)) (inj₂ v') = ⊥
PathsB assocl₊ (inj₁ (inj₂ v)) (inj₁ v') = ⊥
PathsB assocl₊ (inj₁ (inj₂ v)) (inj₂ (inj₁ v')) = (v ≡ v')
PathsB assocl₊ (inj₁ (inj₂ v)) (inj₂ (inj₂ v')) = ⊥
PathsB assocl₊ (inj₂ v) (inj₁ v') = ⊥
PathsB assocl₊ (inj₂ v) (inj₂ (inj₁ v')) = ⊥
PathsB assocl₊ (inj₂ v) (inj₂ (inj₂ v')) = (v ≡ v')
PathsB assocr₊ (inj₁ v) (inj₁ (inj₁ v')) = (v ≡ v')
PathsB assocr₊ (inj₁ v) (inj₁ (inj₂ v')) = ⊥
PathsB assocr₊ (inj₁ v) (inj₂ v') = ⊥
PathsB assocr₊ (inj₂ (inj₁ v)) (inj₁ (inj₁ v')) = ⊥
PathsB assocr₊ (inj₂ (inj₁ v)) (inj₁ (inj₂ v')) = (v ≡ v')
PathsB assocr₊ (inj₂ (inj₁ v)) (inj₂ v') = ⊥
PathsB assocr₊ (inj₂ (inj₂ v)) (inj₁ v') = ⊥
PathsB assocr₊ (inj₂ (inj₂ v)) (inj₂ v') = (v ≡ v')
PathsB unite⋆ v (tt , v') = (v ≡ v')
PathsB uniti⋆ (tt , v) v' = (v ≡ v')
PathsB swap⋆ (v₁ , v₂) (v₂' , v₁') = (v₁ ≡ v₁') × (v₂ ≡ v₂')
PathsB assocl⋆ ((v₁ , v₂) , v₃) (v₁' , (v₂' , v₃')) =
(v₁ ≡ v₁') × (v₂ ≡ v₂') × (v₃ ≡ v₃')
PathsB assocr⋆ (v₁ , (v₂ , v₃)) ((v₁' , v₂') , v₃') =
(v₁ ≡ v₁') × (v₂ ≡ v₂') × (v₃ ≡ v₃')
PathsB distz ()
PathsB factorz (() , v)
PathsB dist (inj₁ (v₁ , v₃)) (inj₁ v₁' , v₃') =
(v₁ ≡ v₁') × (v₃ ≡ v₃')
PathsB dist (inj₁ (v₁ , v₃)) (inj₂ v₂' , v₃') = ⊥
PathsB dist (inj₂ (v₂ , v₃)) (inj₁ v₁' , v₃') = ⊥
PathsB dist (inj₂ (v₂ , v₃)) (inj₂ v₂' , v₃') =
(v₂ ≡ v₂') × (v₃ ≡ v₃')
PathsB factor (inj₁ v₁ , v₃) (inj₁ (v₁' , v₃')) =
(v₁ ≡ v₁') × (v₃ ≡ v₃')
PathsB factor (inj₁ v₁ , v₃) (inj₂ (v₂' , v₃')) = ⊥
PathsB factor (inj₂ v₂ , v₃) (inj₁ (v₁' , v₃')) = ⊥
PathsB factor (inj₂ v₂ , v₃) (inj₂ (v₂' , v₃')) =
(v₂ ≡ v₂') × (v₃ ≡ v₃')
PathsB {t} id⟷ v v' = (v ≡ v')
PathsB (sym⟷ c) v v' = Paths c v v'
PathsB (_◎_ {t₁} {t₂} {t₃} c₁ c₂) v v' =
Σ[ u ∈ ⟦ t₂ ⟧ ] (PathsB c₂ v u × PathsB c₁ u v')
PathsB (c₁ ⊕ c₂) (inj₁ v) (inj₁ v') = PathsB c₁ v v'
PathsB (c₁ ⊕ c₂) (inj₁ v) (inj₂ v') = ⊥
PathsB (c₁ ⊕ c₂) (inj₂ v) (inj₁ v') = ⊥
PathsB (c₁ ⊕ c₂) (inj₂ v) (inj₂ v') = PathsB c₂ v v'
PathsB (c₁ ⊗ c₂) (v₁ , v₂) (v₁' , v₂') =
PathsB c₁ v₁ v₁' × PathsB c₂ v₂ v₂'
{-
PathsB rid q (a , p , refl .a) = q ≡ p
PathsB lid x y = {!!}
PathsB linv x y = {!!}
PathsB rinv = {!!}
PathsB invinv = {!!}
PathsB assoc = {!!}
-}
------------------------------------------------------------------------------
-- Examples...
BOOL : U
BOOL = PLUS ONE ONE
BOOL² : U
BOOL² = TIMES BOOL BOOL
FALSE : ⟦ BOOL ⟧
FALSE = inj₂ tt
TRUE : ⟦ BOOL ⟧
TRUE = inj₁ tt
e₁ : ⟦ ID {BOOL²} {BOOL²} id⟷ (FALSE , TRUE) (FALSE , TRUE) ⟧
e₁ = refl (FALSE , TRUE)
e₂ : ⟦ ID {BOOL²} {BOOL²} (id⟷ ⊗ id⟷) (FALSE , TRUE) (FALSE , TRUE) ⟧
e₂ = (refl FALSE , refl TRUE)
---------------
| {
"alphanum_fraction": 0.4626616604,
"avg_line_length": 38.6612903226,
"ext": "agda",
"hexsha": "a56734e26347ce90de93f1291c358188bfc65a23",
"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/A2.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/A2.agda",
"max_line_length": 105,
"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/A2.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": 5110,
"size": 9588
} |
{-
Agda Implementors' Meeting VI
Göteborg
May 24 - 3zero, 2zerozero7
Hello Agda!
Ulf Norell
-}
-- Records are labeled sigma types.
module R where
{-
A very simple record.
-}
data Nat : Set where
zero : Nat
succ : Nat
record Point : Set where
field x : Nat
y : Nat
-- A record can be seen as a one constructor datatype. In this case:
data Point' : Set where
mkPoint : (x : Nat)(y : Nat) -> Point'
-- There are a few differences, though:
-- To construct a record you use the syntax record { ..; x = e; .. }
origin : Point
origin = record { x = zero; y = zero }
-- instead of
origin' : Point'
origin' = mkPoint zero zero
-- What's more interesting is that you get projection functions
-- for free when you declare a record. More precisely, you get a module
-- parameterised over a record, containing functions corresponding to the
-- fields. In the Point example you get:
{-
module Point (p : Point) where
x : Nat
y : Nat
-}
-- So Point.x : Point -> Nat is the projection function for the field x.
getX : Point -> Nat
getX = Point.x
-- getX = x
| {
"alphanum_fraction": 0.6232758621,
"avg_line_length": 19.0163934426,
"ext": "agda",
"hexsha": "f8c46544d94fdcabbdd0b66e74896c3666dad60d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/beyond/R.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/beyond/R.agda",
"max_line_length": 73,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/beyond/R.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 307,
"size": 1160
} |
open import Oscar.Prelude
module Oscar.Class.Fmap where
module _ where
open import Oscar.Data.Proposequality
open import Oscar.Class.IsFunctor
open import Oscar.Class.Reflexivity
import Oscar.Class.Reflexivity.Function
open import Oscar.Class.Surjidentity
record Fmap {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂) : Ø (↑̂ (↑̂ 𝔬₁ ∙̂ 𝔬₂)) where
constructor ∁
field
fmap : ∀ {𝔄 𝔅} → (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅 -- level-polymorphic functors cannot be represented by `Functor` or any other type in universe < ω.
⦃ isFunctor ⦄ : IsFunctor
Function⟦ 𝔬₁ ⟧
Proposextensequality ε (flip _∘′_)
(MFunction 𝓕)
Proposextensequality ε (flip _∘′_)
fmap
fmap-id-law : ∀ {𝔄} → fmap ¡[ 𝔄 ] ≡̇ ¡
fmap-id-law = surjidentity
open Fmap ⦃ … ⦄ public using (fmap)
-- level-polymorphic functor
module _
(𝔉 : ∀ {𝔣} → Ø 𝔣 → Ø 𝔣)
𝔬₁ 𝔬₂
where
𝓯map = ∀ {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} (f : 𝔒₁ → 𝔒₂) → 𝔉 𝔒₁ → 𝔉 𝔒₂
record 𝓕map : Ø ↑̂ (𝔬₁ ∙̂ 𝔬₂) where field fmap′ : 𝓯map
open 𝓕map ⦃ … ⦄ public
| {
"alphanum_fraction": 0.5638489209,
"avg_line_length": 30.8888888889,
"ext": "agda",
"hexsha": "951623c4b229cec15ea9a907d6dfa029828d954a",
"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/Fmap.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/Fmap.agda",
"max_line_length": 142,
"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/Fmap.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 455,
"size": 1112
} |
module SyntaxRaw where
import Level
open import Data.Empty
open import Data.Unit as Unit
open import Data.Nat
open import Data.List as List renaming ([] to Ø; [_] to [_]L)
open import Data.List.Properties using (++-monoid)
open import NonEmptyList as NList
open import Data.Vec as Vec hiding ([_]; _++_)
open import Data.Product as Prod
open import Function
open import Relation.Binary.PropositionalEquality as PE hiding ([_])
open import Relation.Binary using (module IsEquivalence; Setoid; module Setoid)
open ≡-Reasoning
open import Common.Context as Context
open import Algebra
open Monoid {{ ... }} hiding (refl)
data Phantom {A : Set} (a : A) : Set where
phantom : Phantom a
record Univ (P : Phantom tt) : Set where
field
x : ⊤
U : Set
U = Σ (Phantom tt) Univ
∗ : U
∗ = (phantom , record { x = tt })
length' : {A : Set} → List A → ℕ
length' Ø = 0
length' (x ∷ xs) = suc (length' xs)
length'-hom : {A : Set} → (l₁ l₂ : List A) →
length' (l₁ ++ l₂) ≡ length' l₁ + length' l₂
length'-hom Ø l₂ = refl
length'-hom (x ∷ l₁) l₂ = cong suc (length'-hom l₁ l₂)
length'ᵣ-1 : {A : Set} (l : List A) (a : A) →
(length' l) + 1 ≡ length' (l ++ a ∷ Ø)
length'ᵣ-1 Ø a = refl
length'ᵣ-1 (x ∷ l) a = cong suc (length'ᵣ-1 l a)
length'-commute₁ : {A : Set} (l : List A) (a : A) →
length' (a ∷ l) ≡ length' (l ++ a ∷ Ø)
length'-commute₁ Ø a = refl
length'-commute₁ (x ∷ l) a = cong suc (length'-commute₁ l a)
mvVar : ∀ {A} (Γ₁ Γ₂ : List A) (x : A) → Γ₂ ++ x ∷ Γ₁ ≡ Γ₂ ↑ x ++ Γ₁
mvVar Γ₁ Ø x = refl
mvVar Γ₁ (y ∷ Γ₂) x = cong (λ u → y ∷ u) (mvVar Γ₁ Γ₂ x)
mvVar-length : ∀ {A} (Γ₁ Γ₂ : List A) (x : A) →
length' (Γ₂ ++ x ∷ Γ₁) ≡ length' (Γ₂ ↑ x ++ Γ₁)
mvVar-length Γ₁ Γ₂ x = cong length' (mvVar Γ₁ Γ₂ x)
data FP : Set where
μ : FP
ν : FP
RawCtx : Set
RawCtx = Ctx U
instance ctx-monoid : Monoid _ _
ctx-monoid = ++-monoid U
RawVar : RawCtx → U → Set
RawVar = Var
TyCtx : Set
TyCtx = Ctx RawCtx
instance tyctx-monoid : Monoid _ _
tyctx-monoid = ++-monoid RawCtx
TyVar : TyCtx → RawCtx → Set
TyVar = Var
CtxMor : (TyCtx → RawCtx → RawCtx → Set) → RawCtx → RawCtx → Set
CtxMor R Γ₁ Γ₂ = Vec (R Ø Γ₁ Ø) (length' Γ₂)
FpData : (TyCtx → RawCtx → RawCtx → Set) → TyCtx → RawCtx → Set
FpData R Θ Γ = NList (Σ RawCtx (λ Γ' → CtxMor R Γ' Γ × R (Γ ∷ Θ) Γ' Ø))
-- | List of types, context morphisms and terms (Aₖ, fₖ, gₖ) such that
-- Γₖ, x : Aₖ[C/X] ⊢ gₖ : C fₖ or
-- Γₖ, x : C fₖ ⊢ gₖ : Aₖ[C/X],
-- which are the premisses of the rule for recursion and corecursion,
-- respectively.
FpMapData : (TyCtx → RawCtx → RawCtx → Set) → RawCtx → Set
FpMapData R Γ = NList (Σ RawCtx λ Γ' →
R [ Γ ]L Γ' Ø × CtxMor R Γ' Γ × R Ø (∗ ∷ Γ') Ø)
-- | Types and objects with their corresponding (untyped) type, object
-- variable contexts and parameter contexts.
-- Note that, if Θ | Γ₁ ⊢ M ⊸ Γ₂, i.e., M : Raw Θ Γ₁ Γ₂,
-- then Γ₂ needs to be read in reverse. The reason is that Γ₂ signifies
-- parameters that are instantiated in application-style. Also, variables
-- can be moved for types like in
-- Γ₁, x : A ⊢ B : Γ₂(∗) → Γ₁ ⊢ λx.B : (x : A) ⊸ Γ₂(∗).
data Raw : TyCtx → RawCtx → RawCtx → Set where
----- Common constructors
instRaw : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} {A : U} →
Raw Θ Γ₁ (Γ₂ ↑ A) → Raw Ø Γ₁ Ø → Raw Θ Γ₁ Γ₂
----- Object constructors
unitRaw : (Γ : RawCtx) → Raw Ø Γ Ø
objVarRaw : {Γ : RawCtx} {A : U} → RawVar Γ A → Raw Ø Γ Ø
-- | initial/final dialgebra. dialgRaw ρ k is either αₖ or ξₖ, depending on ρ.
dialgRaw : (Δ : RawCtx) (Γ : RawCtx) (A : U) → FP → ℕ → Raw Ø Δ (A ∷ Γ)
recRaw : (Γ Δ : RawCtx) → FpMapData Raw Γ → FP → Raw Ø Δ (∗ ∷ Γ)
----- Type constructors
⊤-Raw : (Θ : TyCtx) (Γ : RawCtx) → Raw Θ Γ Ø
tyVarRaw : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ : RawCtx} → TyVar Θ Γ₂ → Raw Θ Γ₁ Γ₂
paramAbstrRaw : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) {A : U} →
Raw Θ (A ∷ Γ₁) Γ₂ → Raw Θ Γ₁ (Γ₂ ↑ A)
-- | Constructor for fixed points. The first component is intended to be
-- the context morphism, the second is the type.
fpRaw : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) →
FP → FpData Raw Θ Γ₂ → Raw Θ Γ₁ Γ₂
weakenObjVar : (Γ₁ : RawCtx) {Γ₂ : RawCtx} →
(A : U) {B : U} → RawVar (Γ₁ ++ Γ₂) B → RawVar (Γ₁ ++ A ∷ Γ₂) B
weakenObjVar Ø A x = succ _ x
weakenObjVar (._ ∷ Γ₁) A zero = zero
weakenObjVar (B ∷ Γ₁) A (succ ._ x) = succ _ (weakenObjVar Γ₁ A x)
weaken : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ Γ₃ : RawCtx} →
(A : U) → Raw Θ (Γ₁ ++ Γ₂) Γ₃ → Raw Θ (Γ₁ ++ A ∷ Γ₂) Γ₃
weaken Γ₁ {Γ₂} A (instRaw t s) =
instRaw (weaken Γ₁ A t) (weaken Γ₁ A s)
weaken Γ₁ {Γ₂} A (unitRaw .(Γ₁ ++ Γ₂)) = unitRaw _
weaken Γ₁ {Γ₂} A (objVarRaw x) =
objVarRaw (weakenObjVar Γ₁ A x)
weaken Γ₁ {Γ₂} A (dialgRaw .(Γ₁ ++ Γ₂) Γ B ρ k) = dialgRaw _ Γ B ρ k
weaken Γ₁ {Γ₂} A (recRaw Γ .(Γ₁ ++ Γ₂) gs ρ) = recRaw Γ _ gs ρ
weaken Γ₁ {Γ₂} A (⊤-Raw Θ .(Γ₁ ++ Γ₂)) = ⊤-Raw Θ _
weaken Γ₁ {Γ₂} A (tyVarRaw .(Γ₁ ++ Γ₂) X) = tyVarRaw _ X
weaken Γ₁ {Γ₂} A (paramAbstrRaw .(Γ₁ ++ Γ₂) {B} C) =
paramAbstrRaw (Γ₁ ++ A ∷ Γ₂) (weaken (B ∷ Γ₁) A C)
weaken Γ₁ {Γ₂} A (fpRaw .(Γ₁ ++ Γ₂) ρ D) = fpRaw _ ρ D
weaken₁ : ∀ {Θ Γ₁ Γ₂} → (A : U) → Raw Θ Γ₁ Γ₂ → Raw Θ (A ∷ Γ₁) Γ₂
weaken₁ = weaken Ø
ctxid : (Γ : RawCtx) → CtxMor Raw Γ Γ
ctxid Ø = []
ctxid (A ∷ Γ) = (objVarRaw {A ∷ Γ} {A} zero)
∷ Vec.map (weaken Ø A) (ctxid Γ)
-- | Build the instantiation "t f" of a raw term t by a context morphism f
instWCtxMor : {Θ : TyCtx} {Γ₁ Γ₂ Γ₃ : RawCtx} →
Raw Θ Γ₁ (Γ₃ ++ Γ₂) → CtxMor Raw Γ₁ Γ₂ → Raw Θ Γ₁ Γ₃
instWCtxMor {Θ} {Γ₁} {Ø} {Γ₃} t [] = subst (Raw Θ Γ₁) (proj₂ identity Γ₃) t
instWCtxMor {Θ} {Γ₁} {x ∷ Γ₂} {Γ₃} t (s ∷ f) =
instRaw (instWCtxMor (subst (Raw Θ Γ₁) (mvVar _ Γ₃ x) t) f) s
-- | Retrieve the term to be substituted for a variable from a context morphism
get : {R : TyCtx → RawCtx → RawCtx → Set} {Γ₁ Γ₂ : RawCtx} {A : U} →
CtxMor R Γ₂ Γ₁ → RawVar Γ₁ A → R Ø Γ₂ Ø
get {R} {Ø} [] ()
get {R} {_ ∷ Γ₁} (M ∷ f) zero = M
get {R} {_ ∷ Γ₁} (M ∷ f) (succ ._ x) = get {R} f x
-- | Extends a context morphism to be the identity on a new variable
extend : {Γ₁ Γ₂ : RawCtx} →
(A : U) → CtxMor Raw Γ₂ Γ₁ → CtxMor Raw (A ∷ Γ₂) (A ∷ Γ₁)
extend {Γ₁} {Γ₂} A f = (objVarRaw {A ∷ Γ₂} {A} zero) ∷ (Vec.map (weaken₁ A) f)
-- | Substitution on raw terms
substRaw : ∀ {Θ Γ₁ Γ Γ₂} → Raw Θ Γ₁ Γ → CtxMor Raw Γ₂ Γ₁ → Raw Θ Γ₂ Γ
substRaw (instRaw M N) f = instRaw (substRaw M f) (substRaw N f)
substRaw (unitRaw Γ) f = unitRaw _
substRaw (objVarRaw x) f = get {Raw} f x
substRaw (dialgRaw Δ Γ A ρ k) f = dialgRaw _ Γ A ρ k
substRaw (recRaw Γ Δ gs ρ) f = recRaw Γ _ gs ρ
substRaw (⊤-Raw Θ Γ) f = ⊤-Raw Θ _
substRaw (tyVarRaw Γ₁ X) f = tyVarRaw _ X
substRaw (paramAbstrRaw Γ₁ A) f = paramAbstrRaw _ (substRaw A (extend _ f))
substRaw (fpRaw Γ₁ ρ D) f = fpRaw _ ρ D
-- | Context morphism that projects on arbitrary prefix of a context
ctxProjRaw : (Γ₁ Γ₂ : RawCtx) → CtxMor Raw (Γ₂ ++ Γ₁) Γ₁
ctxProjRaw Γ₁ Ø = ctxid Γ₁
ctxProjRaw Γ₁ (A ∷ Γ₂) = Vec.map (weaken₁ A) (ctxProjRaw Γ₁ Γ₂)
-- | Extend one step weakening to weakening by arbitrary contexts
weaken' : ∀ {Θ Γ₁ Γ₃} →
(Γ₂ : RawCtx) → Raw Θ Γ₁ Γ₃ → Raw Θ (Γ₂ ++ Γ₁) Γ₃
weaken' {Γ₁ = Γ₁} Γ₂ t = substRaw t (ctxProjRaw Γ₁ Γ₂)
-----------------------------------------
--- Examples
-----------------------------------------
_︵_ : {A : Set} → A → A → List A
a ︵ b = a ∷ b ∷ Ø
-- | Binary product type
ProdRaw : (Γ : RawCtx) → Raw (Γ ︵ Γ) Ø Γ
ProdRaw Γ = fpRaw Ø ν D
where
Δ = Γ ︵ Γ
A : TyVar (Γ ∷ Δ) Γ
A = succ Γ zero
B : TyVar (Γ ∷ Δ) Γ
B = succ Γ (succ Γ zero)
D₁ = (Γ , ctxid Γ , instWCtxMor (tyVarRaw Γ A) (ctxid Γ))
D₂ = (Γ , ctxid Γ , instWCtxMor (tyVarRaw Γ B) (ctxid Γ))
D : FpData Raw Δ Γ
D = D₁ ∷ [ D₂ ]
| {
"alphanum_fraction": 0.5656363409,
"avg_line_length": 35.6741071429,
"ext": "agda",
"hexsha": "be66034244fbc940ea1fca34b87dbc23bd26b013",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-24T10:54:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-24T10:54:38.000Z",
"max_forks_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "StillerHarpo/CoindDepTypes",
"max_forks_repo_path": "Syntax/SyntaxRaw.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_issues_repo_issues_event_max_datetime": "2020-07-24T12:53:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-07-24T12:53:30.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "StillerHarpo/CoindDepTypes",
"max_issues_repo_path": "Syntax/SyntaxRaw.agda",
"max_line_length": 80,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "StillerHarpo/CoindDepTypes",
"max_stars_repo_path": "Syntax/SyntaxRaw.agda",
"max_stars_repo_stars_event_max_datetime": "2018-04-06T02:10:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-27T14:45:11.000Z",
"num_tokens": 3331,
"size": 7991
} |
{-# OPTIONS --copatterns #-}
module CS410-Indexed where
open import CS410-Prelude
open import CS410-Nat
-- some notation for working with indexed sets
_-:>_ _*:_ _+:_ : {I : Set}(S T : I -> Set) -> I -> Set
(S -:> T) i = S i -> T i -- index-respecting functions
(S *: T) i = S i * T i -- index-matching pairs
(S +: T) i = S i + T i -- index-consistent choice
infixr 3 _-:>_
infixr 5 _*:_
-- wrapping in the brackets means "works for all indices"
[_] : {I : Set}(X : I -> Set) -> Set
[ X ] = forall {i} -> X i
-- each set I gives us a category, I -> Set, whose objects are
-- indexed sets A : I -> Set, and whose arrows are
-- things in [ A -:> B ]
-- what is a functor between categories of indexed sets?
record FunctorIx {I J : Set}(F : (I -> Set) -> (J -> Set)) : Set1 where
field
mapIx : {A B : I -> Set} -> [ A -:> B ] -> [ F A -:> F B ]
-- what is a monad on indexed sets?
-- it's the usual kit for monads, instantiated for the kinds of
-- "arrows" that we use for indexed sets, the index-respecting functions
record MonadIx {W : Set}(F : (W -> Set) -> (W -> Set)) : Set1 where
field
retIx : forall {P} -> [ P -:> F P ]
extendIx : forall {P Q} -> [ P -:> F Q ] -> [ F P -:> F Q ]
_?>=_ : forall {P Q w} ->
F P w -> (forall {v} -> P v -> F Q v) -> F Q w
fp ?>= k = extendIx k fp
-- every MonadIx gives a FunctorIx
monadFunctorIx : forall {W}{F} -> MonadIx {W} F -> FunctorIx {W}{W} F
monadFunctorIx M = record { mapIx = \ f -> extendIx (retIx o f) }
where open MonadIx M
-- indexed containers, also known as interaction strutures, give us
-- functors
record _=>_ (I J : Set) : Set1 where
constructor _<!_/_
field
Shape : J -> Set
Position : (j : J) -> Shape j -> Set
index : (j : J)(s : Shape j) -> Position j s -> I
IC : forall {I J} -> I => J -> (I -> Set) -> (J -> Set)
IC {I}{J} C X j = Sg (Shape j) \ s -> (p : Position j s) -> X (index j s p)
where open _=>_ C
icFunctorIx : forall {I J}(C : I => J) -> FunctorIx (IC C)
icFunctorIx C = record { mapIx = \ {f (s , k) -> s , \ p -> f (k p) } }
where open _=>_ C
-- iterating an indexed container whose input (child) and output (parent) index
-- types are the same gives us "strategy trees"
data FreeIx {I}(C : I => I)(X : I -> Set)(i : I) : Set where
ret : (X -:> FreeIx C X) i
do : (IC C (FreeIx C X) -:> FreeIx C X) i
-- and they're monadic
freeMonadIx : forall {I}(C : I => I) -> MonadIx (FreeIx C)
freeMonadIx C = record { retIx = ret ; extendIx = graft } where
graft : forall {P Q} -> [ P -:> FreeIx C Q ] -> [ FreeIx C P -:> FreeIx C Q ]
graft k (ret p) = k p
graft k (do (s , f)) = do (s , \ p -> graft k (f p))
-- potentially infinite strategies
data Iterating {I}(C : I => I)(X : I -> Set)(i : I) : Set
record IterIx {I}(C : I => I)(X : I -> Set)(i : I) : Set where
coinductive
constructor step
field
force : Iterating C X i
open IterIx public
data Iterating {i} C X i where
ret : (X -:> Iterating C X) i
do : (IC C (IterIx C X) -:> Iterating C X) i
iterMonadIx : forall {I}(C : I => I) -> MonadIx (IterIx C)
iterMonadIx C = record { retIx = retHelp ; extendIx = extHelp } where
open _=>_ C
retHelp : forall {P} -> [ P -:> IterIx C P ]
force (retHelp p) = ret p
extHelp : forall {P Q} -> [ P -:> IterIx C Q ] -> [ IterIx C P -:> IterIx C Q ]
force (extHelp k t) with force t
force (extHelp k t) | ret p = force (k p)
force (extHelp k t) | do (s , f) = do (s , \ p -> extHelp k (f p))
| {
"alphanum_fraction": 0.5642713999,
"avg_line_length": 31.7545454545,
"ext": "agda",
"hexsha": "b56cebcb9b897e993f4d5f81932d204ba6459153",
"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": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "CS410-Indexed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"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": "clarkdm/CS410",
"max_issues_repo_path": "CS410-Indexed.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "CS410-Indexed.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1237,
"size": 3493
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Reduction {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Tools.Product
-- Weak head expansion of valid terms.
redSubstTermᵛ : ∀ {A t u l Γ}
→ ([Γ] : ⊩ᵛ Γ)
→ Γ ⊩ᵛ t ⇒ u ∷ A / [Γ]
→ ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ u ∷ A / [Γ] / [A]
→ (Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A])
×ω₃ (Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A])
redSubstTermᵛ [Γ] t⇒u [A] [u] =
(λ ⊢Δ [σ] →
let [σA] = proj₁ ([A] ⊢Δ [σ])
[σt] , [σt≡σu] = redSubstTerm (t⇒u ⊢Δ [σ])
(proj₁ ([A] ⊢Δ [σ]))
(proj₁ ([u] ⊢Δ [σ]))
in [σt]
, (λ [σ′] [σ≡σ′] →
let [σ′A] = proj₁ ([A] ⊢Δ [σ′])
[σA≡σ′A] = proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′]
[σ′t] , [σ′t≡σ′u] = redSubstTerm (t⇒u ⊢Δ [σ′])
(proj₁ ([A] ⊢Δ [σ′]))
(proj₁ ([u] ⊢Δ [σ′]))
in transEqTerm [σA] [σt≡σu]
(transEqTerm [σA] ((proj₂ ([u] ⊢Δ [σ])) [σ′] [σ≡σ′])
(convEqTerm₂ [σA] [σ′A] [σA≡σ′A]
(symEqTerm [σ′A] [σ′t≡σ′u])))))
, (λ ⊢Δ [σ] → proj₂ (redSubstTerm (t⇒u ⊢Δ [σ])
(proj₁ ([A] ⊢Δ [σ]))
(proj₁ ([u] ⊢Δ [σ]))))
| {
"alphanum_fraction": 0.3586247777,
"avg_line_length": 40.1666666667,
"ext": "agda",
"hexsha": "f3df8fd7797e8882a62d50f711d6b01057a7586d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Reduction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Reduction.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Reduction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 649,
"size": 1687
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.HSpace renaming (HSpaceStructure to HSS)
import homotopy.WedgeExtension as WedgeExt
module homotopy.Pi2HSusp {i} {X : Ptd i} {{_ : has-level 1 (de⊙ X)}}
{{_ : is-connected 0 (de⊙ X)}} (H-X : HSS X)
where
{- TODO this belongs somewhere else, but where? -}
private
Type=-ext : ∀ {i} {A B : Type i} (p q : A == B)
→ (coe p ∼ coe q) → p == q
Type=-ext p q α =
! (ua-η p)
∙ ap ua (Subtype=-out is-equiv-prop (λ= α))
∙ ua-η q
module μ = ConnectedHSpace H-X
μ = μ.μ
private
A = de⊙ X
e = pt X
P : Susp A → Type i
P x = Trunc 1 (north == x)
module Codes = SuspRec A A (λ a → ua (μ.r-equiv a))
Codes : Susp A → Type i
Codes = Codes.f
Codes-level : (x : Susp A) → has-level 1 (Codes x)
Codes-level = Susp-elim ⟨⟩ ⟨⟩
(λ _ → prop-has-all-paths-↓)
encode'₀ : {x : Susp A} → (north == x) → Codes x
encode'₀ α = transport Codes α e
encode' : {x : Susp A} → P x → Codes x
encode' {x} = Trunc-rec {{Codes-level x}} encode'₀
import homotopy.SuspAdjointLoop as SAL
{- This should be [[_] ∘ η] where [η] is the functor in SuspAdjointLoop.agda -}
decodeN' : A → P north
decodeN' = [_] ∘ fst (SAL.η X)
abstract
transport-Codes-mer : (a a' : A)
→ transport Codes (merid a) a' == μ a a'
transport-Codes-mer a a' =
coe (ap Codes (merid a)) a'
=⟨ Codes.merid-β a |in-ctx (λ w → coe w a') ⟩
coe (ua (μ.r-equiv a)) a'
=⟨ coe-β (μ.r-equiv a) a' ⟩
μ a a' ∎
transport-Codes-mer-e-! : (a : A)
→ transport Codes (! (merid e)) a == a
transport-Codes-mer-e-! a =
coe (ap Codes (! (merid e))) a
=⟨ ap-! Codes (merid e) |in-ctx (λ w → coe w a) ⟩
coe (! (ap Codes (merid e))) a
=⟨ Codes.merid-β e |in-ctx (λ w → coe (! w) a) ⟩
coe (! (ua (μ.r-equiv e))) a
=⟨ Type=-ext (ua (μ.r-equiv e)) idp (λ x → coe-β _ x ∙ μ.unit-l x)
|in-ctx (λ w → coe (! w) a) ⟩
coe (! idp) a ∎
abstract
encode'-decodeN' : (a : A) → encode' (decodeN' a) == a
encode'-decodeN' a =
transport Codes (merid a ∙ ! (merid e)) e
=⟨ transp-∙ {B = Codes} (merid a) (! (merid e)) e ⟩
transport Codes (! (merid e)) (transport Codes (merid a) e)
=⟨ transport-Codes-mer a e ∙ μ.unit-r a
|in-ctx (λ w → transport Codes (! (merid e)) w) ⟩
transport Codes (! (merid e)) a
=⟨ transport-Codes-mer-e-! a ⟩
a ∎
abstract
homomorphism : (a a' : A)
→ Path {A = Trunc 1 (north == south)}
[ merid (μ a a' ) ] [ merid a' ∙ ! (merid e) ∙ merid a ]
homomorphism = WedgeExt.ext args
where
args : WedgeExt.args {a₀ = e} {b₀ = e}
args = record {m = -1; n = -1;
P = λ a a' → (_ , ⟨⟩);
f = λ a → ap [_] $
merid (μ a e)
=⟨ ap merid (μ.unit-r a) ⟩
merid a
=⟨ ap (λ w → w ∙ merid a) (! (!-inv-r (merid e)))
∙ ∙-assoc (merid e) (! (merid e)) (merid a) ⟩
merid e ∙ ! (merid e) ∙ merid a ∎;
g = λ a' → ap [_] $
merid (μ e a')
=⟨ ap merid (μ.unit-l a') ⟩
merid a'
=⟨ ! (∙-unit-r (merid a'))
∙ ap (λ w → merid a' ∙ w) (! (!-inv-l (merid e))) ⟩
merid a' ∙ ! (merid e) ∙ merid e ∎ ;
p = ap (λ {(p₁ , p₂) → ap [_] $
merid (μ e e) =⟨ p₁ ⟩
merid e =⟨ p₂ ⟩
merid e ∙ ! (merid e) ∙ merid e ∎})
(pair×= (ap (λ x → ap merid x) (! μ.coh)) (coh (merid e)))}
where coh : {B : Type i} {b b' : B} (p : b == b')
→ ap (λ w → w ∙ p) (! (!-inv-r p)) ∙ ∙-assoc p (! p) p
== ! (∙-unit-r p) ∙ ap (λ w → p ∙ w) (! (!-inv-l p))
coh idp = idp
decode' : {x : Susp A} → Codes x → P x
decode' {x} = Susp-elim {P = λ x → Codes x → P x}
decodeN'
(λ a → [ merid a ])
(λ a → ↓-→-from-transp (λ= $ STS a))
x
where
abstract
STS : (a a' : A) → transport P (merid a) (decodeN' a')
== [ merid (transport Codes (merid a) a') ]
STS a a' =
transport P (merid a) [ merid a' ∙ ! (merid e) ]
=⟨ transport-Trunc (north ==_) (merid a) _ ⟩
[ transport (north ==_) (merid a) (merid a' ∙ ! (merid e)) ]
=⟨ ap [_] (transp-cst=idf {A = Susp A} (merid a) _) ⟩
[ (merid a' ∙ ! (merid e)) ∙ merid a ]
=⟨ ap [_] (∙-assoc (merid a') (! (merid e)) (merid a)) ⟩
[ merid a' ∙ ! (merid e) ∙ merid a ]
=⟨ ! (homomorphism a a') ⟩
[ merid (μ a a') ]
=⟨ ap ([_] ∘ merid) (! (transport-Codes-mer a a')) ⟩
[ merid (transport Codes (merid a) a') ] ∎
abstract
decode'-encode' : {x : Susp A} (tα : P x)
→ decode' {x} (encode' {x} tα) == tα
decode'-encode' {x} = Trunc-elim
{P = λ tα → decode' {x} (encode' {x} tα) == tα}
-- FIXME: Agda very slow (looping?) when omitting the next line
{{λ _ → =-preserves-level Trunc-level}}
(J (λ y p → decode' {y} (encode' {y} [ p ]) == [ p ])
(ap [_] (!-inv-r (merid e))))
eq' : Trunc 1 (Ω (⊙Susp X)) ≃ A
eq' = equiv encode' decodeN' encode'-decodeN' decode'-encode'
⊙decodeN : ⊙Trunc 1 X ⊙→ ⊙Trunc 1 (⊙Ω (⊙Susp X))
⊙decodeN = ⊙Trunc-fmap (SAL.η X)
decodeN : Trunc 1 A → Trunc 1 (Ω (⊙Susp X))
decodeN = fst ⊙decodeN
encodeN : Trunc 1 (Ω (⊙Susp X)) → Trunc 1 A
encodeN = [_] ∘ encode' {x = north}
eq : Trunc 1 (Ω (⊙Susp X)) ≃ Trunc 1 A
eq = encodeN ,
replace-inverse (snd ((unTrunc-equiv A)⁻¹ ∘e eq'))
{decodeN}
(Trunc-elim (λ _ → idp))
⊙eq : ⊙Trunc 1 (⊙Ω (⊙Susp X)) ⊙≃ ⊙Trunc 1 X
⊙eq = ≃-to-⊙≃ eq idp
⊙eq⁻¹ : ⊙Trunc 1 X ⊙≃ ⊙Trunc 1 (⊙Ω (⊙Susp X))
⊙eq⁻¹ = ⊙decodeN , snd (eq ⁻¹)
iso : Ω^S-group 0 (⊙Trunc 1 (⊙Ω (⊙Susp X)))
≃ᴳ Ω^S-group 0 (⊙Trunc 1 X)
iso = Ω^S-group-emap 0 ⊙eq
abstract
π₂-Susp : πS 1 (⊙Susp X) ≃ᴳ πS 0 X
π₂-Susp =
πS 1 (⊙Susp X)
≃ᴳ⟨ πS-Ω-split-iso 0 (⊙Susp X) ⟩
πS 0 (⊙Ω (⊙Susp X))
≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso 0 (⊙Ω (⊙Susp X)) ⁻¹ᴳ ⟩
Ω^S-group 0 (⊙Trunc 1 (⊙Ω (⊙Susp X)))
≃ᴳ⟨ iso ⟩
Ω^S-group 0 (⊙Trunc 1 X)
≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso 0 X ⟩
πS 0 X ≃ᴳ∎
| {
"alphanum_fraction": 0.4630179828,
"avg_line_length": 33.835978836,
"ext": "agda",
"hexsha": "b3668b0eb36ffe2bdaea76af5aeae7b6e7565eba",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/Pi2HSusp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/Pi2HSusp.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/Pi2HSusp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2679,
"size": 6395
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Object.Terminal
-- Various constructors of Product Objects
module Categories.Object.Product.Construction {o ℓ e} (C : Category o ℓ e) (T : Terminal C) where
open import Categories.Object.Exponential C hiding (repack)
open import Categories.Object.Product C
open Category C
open Terminal T
open HomReasoning
-- we can get some products
[⊤×⊤]-product : Product ⊤ ⊤
[⊤×⊤]-product = record
{ A×B = ⊤
; π₁ = !
; π₂ = !
; ⟨_,_⟩ = λ _ _ → !
; project₁ = !-unique₂
; project₂ = !-unique₂
; unique = λ _ _ → !-unique _
}
[⊤×_]-product : (X : Obj) → Product ⊤ X
[⊤×_]-product X = record
{ A×B = X
; π₁ = !
; π₂ = id
; ⟨_,_⟩ = λ _ y → y
; project₁ = !-unique₂
; project₂ = identityˡ
; unique = λ _ id∘h≈j → ⟺ id∘h≈j ○ identityˡ
}
[_×⊤]-product : (X : Obj) → Product X ⊤
[_×⊤]-product X = Reversible [⊤× X ]-product
-- and some exponentials too
[_↑⊤]-exponential : (B : Obj) → Exponential ⊤ B
[ B ↑⊤]-exponential = record
{ B^A = B
; product = [ B ×⊤]-product
; eval = id
; λg = λ {X} X×⊤ X⇒B → X⇒B ∘ repack [ X ×⊤]-product X×⊤
; β = λ p {g} → begin
id ∘ (g ∘ [ p ]⟨ id , ! ⟩) ∘ [ p ]π₁ ≈⟨ identityˡ ○ assoc ⟩
g ∘ [ p ]⟨ id , ! ⟩ ∘ [ p ]π₁ ≈⟨ refl⟩∘⟨ [ p ]⟨⟩∘ ⟩
g ∘ [ p ]⟨ id ∘ [ p ]π₁ , ! ∘ [ p ]π₁ ⟩ ≈⟨ refl⟩∘⟨ ⟨⟩-cong₂ p identityˡ !-unique₂ ⟩
g ∘ [ p ]⟨ [ p ]π₁ , [ p ]π₂ ⟩ ≈⟨ refl⟩∘⟨ η p ○ identityʳ ⟩
g ∎
; λ-unique = λ {X} p {g} {h} h-comm → begin
h ≈˘⟨ identityʳ ⟩
h ∘ id ≈˘⟨ refl⟩∘⟨ project₁ p ⟩
h ∘ [ p ]π₁ ∘ [ p ]⟨ id , ! ⟩ ≈˘⟨ assoc ⟩
(h ∘ [ p ]π₁) ∘ [ p ]⟨ id , ! ⟩ ≈˘⟨ identityˡ ⟩∘⟨refl ⟩
(id ∘ h ∘ [ p ]π₁) ∘ [ p ]⟨ id , ! ⟩ ≈⟨ h-comm ⟩∘⟨refl ⟩
g ∘ repack [ X ×⊤]-product p ∎
}
where open Product
[⊤↑_]-exponential : (A : Obj) → Exponential A ⊤
[⊤↑ A ]-exponential = record
{ B^A = ⊤
; product = [⊤× A ]-product
; eval = !
; λg = λ _ _ → !
; β = λ _ → !-unique₂
; λ-unique = λ _ _ → !-unique₂
}
| {
"alphanum_fraction": 0.4649042844,
"avg_line_length": 29.6486486486,
"ext": "agda",
"hexsha": "61a855ecd2ce2dc7c15042a91c6380b6bb95d25f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Object/Product/Construction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Object/Product/Construction.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Object/Product/Construction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 979,
"size": 2194
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Group where
open import Cubical.Structures.Group.Base public
open import Cubical.Structures.Group.Properties public
open import Cubical.Structures.Group.Morphism public
open import Cubical.Structures.Group.MorphismProperties public
| {
"alphanum_fraction": 0.8258064516,
"avg_line_length": 38.75,
"ext": "agda",
"hexsha": "1bac5a4e613bdd0a9ff18dfa6baada8d43789cfe",
"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": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Structures/Group.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"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": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Structures/Group.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Structures/Group.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 65,
"size": 310
} |
module Haskell.Prim.Applicative where
open import Haskell.Prim
open import Haskell.Prim.Either
open import Haskell.Prim.Foldable
open import Haskell.Prim.Functor
open import Haskell.Prim.List
open import Haskell.Prim.Maybe
open import Haskell.Prim.Monoid
open import Haskell.Prim.Tuple
--------------------------------------------------
-- Applicative
record Applicative (f : Set → Set) : Set₁ where
infixl 4 _<*>_
field
pure : a → f a
_<*>_ : f (a → b) → f a → f b
overlap ⦃ super ⦄ : Functor f
_<*_ : f a → f b → f a
x <* y = const <$> x <*> y
_*>_ : f a → f b → f b
x *> y = const id <$> x <*> y
open Applicative ⦃ ... ⦄ public
instance
iApplicativeList : Applicative List
iApplicativeList .pure x = x ∷ []
iApplicativeList ._<*>_ fs xs = concatMap (λ f → map f xs) fs
iApplicativeMaybe : Applicative Maybe
iApplicativeMaybe .pure = Just
iApplicativeMaybe ._<*>_ (Just f) (Just x) = Just (f x)
iApplicativeMaybe ._<*>_ _ _ = Nothing
iApplicativeEither : Applicative (Either a)
iApplicativeEither .pure = Right
iApplicativeEither ._<*>_ (Right f) (Right x) = Right (f x)
iApplicativeEither ._<*>_ (Left e) _ = Left e
iApplicativeEither ._<*>_ _ (Left e) = Left e
iApplicativeFun : Applicative (λ b → a → b)
iApplicativeFun .pure = const
iApplicativeFun ._<*>_ f g x = f x (g x)
iApplicativeTuple₂ : ⦃ Monoid a ⦄ → Applicative (a ×_)
iApplicativeTuple₂ .pure x = mempty , x
iApplicativeTuple₂ ._<*>_ (a , f) (b , x) = a <> b , f x
iApplicativeTuple₃ : ⦃ Monoid a ⦄ → ⦃ Monoid b ⦄ → Applicative (a × b ×_)
iApplicativeTuple₃ .pure x = mempty , mempty , x
iApplicativeTuple₃ ._<*>_ (a , b , f) (a₁ , b₁ , x) = a <> a₁ , b <> b₁ , f x
iApplicativeTuple₄ : ⦃ Monoid a ⦄ → ⦃ Monoid b ⦄ → ⦃ Monoid c ⦄ →
Applicative (λ d → Tuple (a ∷ b ∷ c ∷ d ∷ []))
iApplicativeTuple₄ .pure x = mempty ∷ mempty ∷ mempty ∷ x ∷ []
iApplicativeTuple₄ ._<*>_ (a ∷ b ∷ c ∷ f ∷ []) (a₁ ∷ b₁ ∷ c₁ ∷ x ∷ []) =
a <> a₁ ∷ b <> b₁ ∷ c <> c₁ ∷ f x ∷ []
| {
"alphanum_fraction": 0.5673659674,
"avg_line_length": 33,
"ext": "agda",
"hexsha": "ad19a78ee4ad7ac71d0007a566c462fd7ea198c5",
"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": "4cb28f1b5032948b19b977b390fa260be292abf6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Applicative.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6",
"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": "flupe/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Applicative.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Applicative.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 769,
"size": 2145
} |
module Data.FixedTree.Properties where
import Lvl
open import Data using (Unit ; <>)
open import Data.Boolean
open import Data.FixedTree
open import Data.Tuple.Raise
import Data.Tuple.Raiseᵣ.Functions as Raise
open import Functional as Fn
open import Logic.Propositional
open import Numeral.Finite
open import Numeral.Finite.Oper.Comparisons
open import Numeral.Natural
open import Type
private variable ℓ ℓᵢ ℓₗ ℓₙ ℓₒ : Lvl.Level
private variable n : ℕ
private variable N N₁ N₂ L T A B : Type{ℓ}
-- A tree is full when every node has no or all children.
data Full {L : Type{ℓₗ}}{N : Type{ℓₙ}}{n} : FixedTree(n) L N → Type{ℓₗ Lvl.⊔ ℓₙ} where
leaf : ∀{l} → Full(Leaf l)
single : ∀{a}{l} → Full(Node a (Raise.repeat(n) (Leaf l))) -- TODO: All the leaves should not be forced to all have the same data
step : ∀{a : N}{ca : N ^ n}{cc : ((FixedTree(n) L N) ^ n) ^ n} → (∀{i : 𝕟(n)} → Full(Node (Raise.index i ca) (Raise.index i cc))) → Full(Node a (Raise.map₂{n} Node ca cc))
-- step : ∀{a : T}{ca : T ^ n}{cc : (FixedTree(n)(T) ^ n) ^ n} → Raise.reduceOrᵣ{n}(_⨯_) Unit (Raise.map₂(Full ∘₂ Node) ca cc) → Full(Node a (Raise.map₂{n} Node ca cc))
-- A tree is perfect at depth `n` when all leaves are at height `n`.
-- In other words, a tree is perfect when all leaves are at the same height.
data Perfect {L : Type{ℓₗ}}{N : Type{ℓₙ}}{n} : FixedTree(n) L N → ℕ → Type{ℓₗ Lvl.⊔ ℓₙ} where
leaf : ∀{l} → Perfect(Leaf l)(𝟎)
step : ∀{a}{c}{h} → (∀{i : 𝕟(n)} → Perfect(Raise.index i c)(h)) → Perfect(Node a c)(𝐒(h))
data Complete {L : Type{ℓₗ}}{N : Type{ℓₙ}}{n} : FixedTree(n) L N → ℕ → Bool → Type{ℓₗ Lvl.⊔ ℓₙ} where
perfect-leaf : ∀{l} → Complete(Leaf l)(𝟎)(𝑇)
imperfect-leaf : ∀{l} → Complete(Leaf l)(𝐒(𝟎))(𝐹)
step : ∀{a}{c}{h}{t : 𝕟(n)} → (∀{i : 𝕟(n)} → Complete(Raise.index i c)(h)(i ≤? t)) → Complete(Node a c)(𝐒(h))(t ≤? maximum{n})
data DepthOrdered {L : Type{ℓₗ}}{N : Type{ℓₙ}} (_≤_ : N → N → Type{ℓₒ}) {n} : FixedTree(n) L N → Type{ℓₗ Lvl.⊔ ℓₙ Lvl.⊔ ℓₒ} where
leaf : ∀{l} → DepthOrdered(_≤_)(Leaf l)
step : ∀{p}{c : (FixedTree(n) L N) ^ n} → (∀{i : 𝕟(n)} → (\{(Leaf _) → Unit ; (Node a c) → (p ≤ a) ∧ DepthOrdered(_≤_)(Node a c)}) $ (Raise.index i c)) → DepthOrdered(_≤_)(Node p c)
Heap : ∀{L : Type{ℓₗ}}{N : Type{ℓₙ}} → (N → N → Type{ℓₒ}) → ∀{n} → FixedTree(n) L N → ℕ → Bool → Type
Heap(_≤_) tree height perfect = DepthOrdered(_≤_)(tree) ∧ Complete(tree)(height)(perfect)
| {
"alphanum_fraction": 0.613918807,
"avg_line_length": 54.8636363636,
"ext": "agda",
"hexsha": "1077065d9c430a8b22e67e5e8c48345f8b2a6239",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/FixedTree/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/FixedTree/Properties.agda",
"max_line_length": 183,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/FixedTree/Properties.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": 988,
"size": 2414
} |
{-# OPTIONS --without-K #-}
open import Types
open import Functions
open import Paths
open import HLevel
open import Equivalences
module Univalence {i} where
postulate -- Univalence axiom
univalence : (A B : Set i) → is-equiv (path-to-eq {i} {A} {B})
path-to-eq-equiv : {A B : Set i} → ((A ≡ B) ≃ (A ≃ B))
path-to-eq-equiv = (path-to-eq , univalence _ _)
eq-to-path-equiv : {A B : Set i} → ((A ≃ B) ≃ (A ≡ B))
eq-to-path-equiv = path-to-eq-equiv ⁻¹
eq-to-path : {A B : Set i} → (A ≃ B → A ≡ B)
eq-to-path {A} {B} = π₁ eq-to-path-equiv
eq-to-path-right-inverse : {A B : Set i} (f : A ≃ B)
→ path-to-eq (eq-to-path f) ≡ f
eq-to-path-right-inverse = inverse-right-inverse path-to-eq-equiv
path-to-eq-right-inverse : {A B : Set i} (f : A ≡ B)
→ eq-to-path (path-to-eq f) ≡ f
path-to-eq-right-inverse = inverse-left-inverse path-to-eq-equiv
-- Transport in the structural fibration of a universe
trans-id : {A B : Set i} (f : A ≡ B) (u : A)
→ transport (λ X → X) f u ≡ (path-to-eq f) ☆ u
trans-id refl u = refl
trans-id! : {A B : Set i} (f : A ≡ B) (u : B)
→ transport (λ X → X) (! f) u ≡ inverse (path-to-eq f) u
trans-id! refl u = refl
trans-id-eq-to-path : {A B : Set i} (f : A ≃ B) (u : A)
→ transport (λ X → X) (eq-to-path f) u ≡ f ☆ u
trans-id-eq-to-path {A} {B} f u =
trans-id (eq-to-path f) u
∘ ap (λ (t : A ≃ B) → t ☆ u) (eq-to-path-right-inverse f)
trans-id-!eq-to-path : {A B : Set i} (f : A ≃ B) (u : B)
→ transport (λ X → X) (! (eq-to-path f)) u ≡ inverse f u
trans-id-!eq-to-path {A} {B} f u =
trans-id! (eq-to-path f) u
∘ ap (λ (t : A ≃ B) → inverse t u) (eq-to-path-right-inverse f)
-- Not used
--
-- trans-id→A : ∀ {i j} (A : Set j) {X Y : Set i} (e : X ≡ Y) (f : X → A)
-- (a : Y) → transport (λ (X : Set i) → X → A) e f a
-- ≡ f (inverse (path-to-eq e) a)
-- trans-id→A A (refl _) f a = refl _
-- trans-id→A-eq-to-path : ∀ {i j} (A : Set j) {X Y : Set i} (e : X ≃ Y)
-- (f : X → A) (a : Y)
-- → transport (λ (X : Set i) → X → A) (eq-to-path e) f a ≡ f (inverse e a)
-- trans-id→A-eq-to-path A e f a =
-- trans-id→A A (eq-to-path e) f a
-- ∘ ap (λ u → f (inverse u a)) (eq-to-path-right-inverse e)
-- trans-cst→X : ∀ {i j} (A : Set j) {X Y : Set i} (e : X ≡ Y) (f : A → X)
-- (a : A) → transport (λ (X : Set i) → A → X) e f a
-- ≡ π₁ (path-to-eq e) (f a)
-- trans-cst→X A (refl _) f a = refl _
-- trans-cst→X-eq-to-path : ∀ {i j} (A : Set j) {X Y : Set i} (e : X ≃ Y)
-- (f : A → X) (a : A)
-- → transport (λ (X : Set i) → A → X) (eq-to-path e) f a ≡ π₁ e (f a)
-- trans-cst→X-eq-to-path A e f a =
-- trans-cst→X A (eq-to-path e) f a
-- ∘ ap (λ u → π₁ u (f a)) (eq-to-path-right-inverse e)
-- Induction along equivalences
equiv-induction : ∀ {j} (P : {A B : Set i} (f : A ≃ B) → Set j)
(d : (A : Set i) → P (id-equiv A)) {A B : Set i} (f : A ≃ B)
→ P f
equiv-induction P d f =
transport P (eq-to-path-right-inverse f)
(equiv-induction-int P d (eq-to-path f)) where
equiv-induction-int : ∀ {j}
(P : {A : Set i} {B : Set i} (f : A ≃ B) → Set j)
(d : (A : Set i) → P (id-equiv A)) {A B : Set i} (p : A ≡ B)
→ P (path-to-eq p)
equiv-induction-int P d refl = d _
| {
"alphanum_fraction": 0.5268308081,
"avg_line_length": 34.064516129,
"ext": "agda",
"hexsha": "ae2dc3e57b03f84f5aac827898b3e8e621acd73b",
"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/Univalence.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/Univalence.agda",
"max_line_length": 77,
"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/Univalence.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": 1310,
"size": 3168
} |
{-# OPTIONS --without-K --safe #-}
module Fragment.Tactic.Utils where
open import Reflection hiding (name; Type; _≟_)
open import Reflection.Term using (_≟_)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Fin using (Fin)
open import Data.Nat.Show using (show)
open import Data.String using (String) renaming (_++_ to _⟨S⟩_)
open import Data.List using (List; []; _∷_; _++_; drop; take; reverse)
open import Data.Vec using (Vec; []; _∷_; map; toList)
open import Data.Bool using (Bool; true; false; if_then_else_)
open import Data.Maybe using (Maybe; nothing; just)
open import Data.Product using (_×_; _,_)
open import Relation.Nullary using (yes; no; _because_)
open import Relation.Binary.PropositionalEquality as PE using (_≡_)
vra : ∀ {a} {A : Set a} → A → Arg A
vra = arg (arg-info visible relevant)
hra : ∀ {a} {A : Set a} → A → Arg A
hra = arg (arg-info hidden relevant)
infixr 5 λ⦅_⦆→_ λ⦃_⦄→_
λ⦅_⦆→_ : String → Term → Term
λ⦅ x ⦆→ body = lam visible (abs x body)
λ⦃_⦄→_ : String → Term → Term
λ⦃ x ⦄→ body = lam hidden (abs x body)
constructors : Definition → List Name
constructors (data-type _ cs) = cs
constructors _ = []
apply : Term → List (Arg Term) → Term
apply (var x xs) args = var x (xs ++ args)
apply (con x xs) args = con x (xs ++ args)
apply (def x xs) args = def x (xs ++ args)
apply (meta x xs) args = meta x (xs ++ args)
apply (pat-lam cs xs) args = pat-lam cs (xs ++ args)
apply x _ = x
prod : ∀ {a} {A : Set a} → ℕ → List A → List A
prod n xs = reverse (drop n (reverse xs))
ekat : ∀ {a} {A : Set a} → ℕ → List A → List A
ekat n xs = reverse (take n (reverse xs))
find : ∀ {a} {A : Set a} → (A → TC Bool) → List A → TC (Maybe A)
find p [] = return nothing
find p (x ∷ xs)
= do p? ← p x
if p? then return (just x)
else find p xs
mapList : ∀ {a b} {A : Set a} {B : Set b}
→ List (A → B) → List A → List B
mapList [] _ = []
mapList _ [] = []
mapList (f ∷ fs) (x ∷ xs) = f x ∷ mapList fs xs
unapply : Term → ℕ → Term
unapply (var x args) n = var x (prod n args)
unapply (con x args) n = con x (prod n args)
unapply (def x args) n = def x (prod n args)
unapply (meta x args) n = meta x (prod n args)
unapply (pat-lam cs args) n = pat-lam cs (prod n args)
unapply x _ = x
equalTypes : Term → Term → Bool
equalTypes τ τ' with τ ≟ τ'
... | yes _ = true
... | _ = false
flatten : ∀ {a} {A : Set a} → TC (TC A) → TC A
flatten x
= do x' ← x
x'
listTC : ∀ {a} {A : Set a} → List (TC A) → TC (List A)
listTC [] = return []
listTC (x ∷ xs)
= do x' ← x
xs' ← listTC xs
return (x' ∷ xs')
n-ary : ∀ (n : ℕ) → Term → Term
n-ary zero body = body
n-ary (suc n) body = λ⦅ "x" ⟨S⟩ show n ⦆→ (n-ary n body)
debrujin : ∀ (n : ℕ) → Vec Term n
debrujin zero = []
debrujin (suc n) = (var n []) ∷ debrujin n
η-convert : ∀ (n : ℕ) → Term → TC Term
η-convert n t = runSpeculative inner
where inner : TC (Term × Bool)
inner
= do t ← normalise (n-ary n (apply t (toList (map vra (debrujin n)))))
return (t , false)
prefix : ℕ → Term → Term → TC Bool
prefix n x y
= do y ← catchTC (η-convert n (unapply y n)) (return y)
let (b because _) = x ≟ y
return b
extract-type-arg : Term → TC Term
extract-type-arg (pi (arg _ x) _) = return x
extract-type-arg x = typeError (termErr x ∷ strErr "isn't a pi type" ∷ [])
extract-name : Term → TC Name
extract-name (def x _) = return x
extract-name x = typeError (termErr x ∷ strErr "isn't an application of a definition" ∷ [])
extract-definition : Term → TC Definition
extract-definition x
= do x' ← normalise x
η ← extract-name x'
getDefinition η
extract-constructors : Term → TC (List Name)
extract-constructors x
= do δ ← extract-definition x
return (constructors δ)
fin : ℕ → Term
fin zero = con (quote Fin.zero) []
fin (suc n) = con (quote Fin.suc) (vra (fin n) ∷ [])
vec : ∀ {n : ℕ} → Vec Term n → Term
vec [] = con (quote Vec.[]) []
vec (x ∷ xs) = con (quote Vec._∷_) (vra x ∷ vra (vec xs) ∷ [])
vec-len : Term → TC ℕ
vec-len (def (quote Vec) (_ ∷ _ ∷ (arg _ n) ∷ [])) = unquoteTC n
vec-len t = typeError (termErr t ∷ strErr "isn't a" ∷ nameErr (quote Vec) ∷ [])
panic : ∀ {a} {A : Set a} → Term → TC A
panic x = typeError (termErr x ∷ [])
strip-telescope : Term → TC (Term × List (Arg String))
strip-telescope (pi (vArg _) (abs s x))
= do (τ , acc) ← strip-telescope x
return (τ , vra s ∷ acc)
strip-telescope (pi (hArg _) (abs s x))
= do (τ , acc) ← strip-telescope x
return (τ , hra s ∷ acc)
strip-telescope (pi _ _) =
typeError (strErr "no support for irrelevant goals" ∷ [])
strip-telescope t = return (t , [])
restore-telescope : List (Arg String) → Term → TC Term
restore-telescope [] t = return t
restore-telescope (vArg x ∷ xs) t
= do t ← restore-telescope xs t
return (λ⦅ x ⦆→ t)
restore-telescope (hArg x ∷ xs) t
= do t ← restore-telescope xs t
return (λ⦃ x ⦄→ t)
restore-telescope (_ ∷ _) _ =
typeError (strErr "no support for irrelevant goals" ∷ [])
hasType : Term → Term → TC Bool
hasType τ t = runSpeculative inner
where inner = do τ' ← inferType t
return (equalTypes τ τ' , false)
insert : List Term → Term → List Term
insert [] n = n ∷ []
insert (x ∷ xs) n with x ≟ n
... | yes _ = x ∷ xs
... | no _ = x ∷ insert xs n
indexOf : List Term → Term → Maybe ℕ
indexOf [] t = nothing
indexOf (x ∷ xs) t with x ≟ t | indexOf xs t
... | yes _ | _ = just 0
... | no _ | just n = just (suc n)
... | no _ | nothing = nothing
| {
"alphanum_fraction": 0.5672746043,
"avg_line_length": 31.4162162162,
"ext": "agda",
"hexsha": "37de7de28fa51d45edf516e8ee767baf9c966e29",
"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/Tactic/Utils.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/Tactic/Utils.agda",
"max_line_length": 99,
"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/Tactic/Utils.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": 1955,
"size": 5812
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Util.Prelude
-- This module defines types used in the specification of a SystemModel.
module Yasm.Types where
-- Actions that can be performed by peers.
--
-- For now, the SystemModel supports only one kind of action: to send a
-- message. Later it might include things like logging, crashes, assertion
-- failures, etc. For example, if an assertion fires, this
-- could "kill the process" and make it not send any messages in the future.
-- We could also then prove that the handlers do not crash, certain
-- messages are logged under certain circumstances, etc.
--
-- Alternatively, certain actions can be kept outside the system model by
-- defining an application-specific PeerState type (see `Yasm.Base`).
-- For example:
--
-- > libraHandle : Msg → Status × Log × LState → Status × LState × List Action
-- > libraHandle _ (Crashed , l , s) = Crashed , s , [] -- i.e., crashed peers never send messages
-- >
-- > handle = filter isSend ∘ libraHandle
data Action (Msg : Set) : Set where
send : (m : Msg) → Action Msg
-- Injectivity of `send`.
action-send-injective : ∀ {Msg}{m m' : Msg} → send m ≡ send m' → m ≡ m'
action-send-injective refl = refl
| {
"alphanum_fraction": 0.7162066525,
"avg_line_length": 40.3714285714,
"ext": "agda",
"hexsha": "2e5cdb30e95f4d195ea3988f21e74ad8e29fb9f5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/Yasm/Types.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/Yasm/Types.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/Yasm/Types.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 361,
"size": 1413
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Properties {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Weakening
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Irrelevance
using (irrelevanceSubst′)
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
import Definition.LogicalRelation.Weakening as LR
open import Tools.Unit
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Valid substitutions are well-formed
wellformedSubst : ∀ {Γ Δ σ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ
→ Δ ⊢ˢ σ ∷ Γ
wellformedSubst ε′ ⊢Δ [σ] = id
wellformedSubst ([Γ] ∙′ [A]) ⊢Δ ([tailσ] , [headσ]) =
wellformedSubst [Γ] ⊢Δ [tailσ]
, escapeTerm (proj₁ ([A] ⊢Δ [tailσ])) [headσ]
-- Valid substitution equality is well-formed
wellformedSubstEq : ∀ {Γ Δ σ σ′} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]
→ Δ ⊢ˢ σ ≡ σ′ ∷ Γ
wellformedSubstEq ε′ ⊢Δ [σ] [σ≡σ′] = id
wellformedSubstEq ([Γ] ∙′ [A]) ⊢Δ ([tailσ] , [headσ]) ([tailσ≡σ′] , [headσ≡σ′]) =
wellformedSubstEq [Γ] ⊢Δ [tailσ] [tailσ≡σ′]
, ≅ₜ-eq (escapeTermEq (proj₁ ([A] ⊢Δ [tailσ])) [headσ≡σ′])
-- Extend a valid substitution with a term
consSubstS : ∀ {l σ t A Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
([t] : Δ ⊩⟨ l ⟩ t ∷ subst σ A / proj₁ ([A] ⊢Δ [σ]))
→ Δ ⊩ˢ consSubst σ t ∷ Γ ∙ A / [Γ] ∙″ [A] / ⊢Δ
consSubstS [Γ] ⊢Δ [σ] [A] [t] = [σ] , [t]
-- Extend a valid substitution equality with a term
consSubstSEq : ∀ {l σ σ′ t A Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ])
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
([t] : Δ ⊩⟨ l ⟩ t ∷ subst σ A / proj₁ ([A] ⊢Δ [σ]))
→ Δ ⊩ˢ consSubst σ t ≡ consSubst σ′ t ∷ Γ ∙ A / [Γ] ∙″ [A] / ⊢Δ
/ consSubstS {t = t} {A = A} [Γ] ⊢Δ [σ] [A] [t]
consSubstSEq [Γ] ⊢Δ [σ] [σ≡σ′] [A] [t] =
[σ≡σ′] , reflEqTerm (proj₁ ([A] ⊢Δ [σ])) [t]
-- Weakening of valid substitutions
wkSubstS : ∀ {ρ σ Γ Δ Δ′} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) (⊢Δ′ : ⊢ Δ′)
([ρ] : ρ ∷ Δ′ ⊆ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ′ ⊩ˢ ρ •ₛ σ ∷ Γ / [Γ] / ⊢Δ′
wkSubstS ε′ ⊢Δ ⊢Δ′ ρ [σ] = tt
wkSubstS {σ = σ} {Γ = Γ ∙ A} ([Γ] ∙′ x) ⊢Δ ⊢Δ′ ρ [σ] =
let [tailσ] = wkSubstS [Γ] ⊢Δ ⊢Δ′ ρ (proj₁ [σ])
in [tailσ]
, irrelevanceTerm′ (wk-subst A)
(LR.wk ρ ⊢Δ′ (proj₁ (x ⊢Δ (proj₁ [σ]))))
(proj₁ (x ⊢Δ′ [tailσ]))
(LR.wkTerm ρ ⊢Δ′ (proj₁ (x ⊢Δ (proj₁ [σ]))) (proj₂ [σ]))
-- Weakening of valid substitution equality
wkSubstSEq : ∀ {ρ σ σ′ Γ Δ Δ′} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) (⊢Δ′ : ⊢ Δ′)
([ρ] : ρ ∷ Δ′ ⊆ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ])
→ Δ′ ⊩ˢ ρ •ₛ σ ≡ ρ •ₛ σ′ ∷ Γ / [Γ]
/ ⊢Δ′ / wkSubstS [Γ] ⊢Δ ⊢Δ′ [ρ] [σ]
wkSubstSEq ε′ ⊢Δ ⊢Δ′ ρ [σ] [σ≡σ′] = tt
wkSubstSEq {Γ = Γ ∙ A} ([Γ] ∙′ x) ⊢Δ ⊢Δ′ ρ [σ] [σ≡σ′] =
wkSubstSEq [Γ] ⊢Δ ⊢Δ′ ρ (proj₁ [σ]) (proj₁ [σ≡σ′])
, irrelevanceEqTerm′ (wk-subst A) (LR.wk ρ ⊢Δ′ (proj₁ (x ⊢Δ (proj₁ [σ]))))
(proj₁ (x ⊢Δ′ (wkSubstS [Γ] ⊢Δ ⊢Δ′ ρ (proj₁ [σ]))))
(LR.wkEqTerm ρ ⊢Δ′ (proj₁ (x ⊢Δ (proj₁ [σ]))) (proj₂ [σ≡σ′]))
-- Weaken a valid substitution by one type
wk1SubstS : ∀ {F σ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
(⊢F : Δ ⊢ F)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ (Δ ∙ F) ⊩ˢ wk1Subst σ ∷ Γ / [Γ]
/ (⊢Δ ∙ ⊢F)
wk1SubstS {F} {σ} {Γ} {Δ} [Γ] ⊢Δ ⊢F [σ] =
wkSubstS [Γ] ⊢Δ (⊢Δ ∙ ⊢F) (step id) [σ]
-- Weaken a valid substitution equality by one type
wk1SubstSEq : ∀ {F σ σ′ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
(⊢F : Δ ⊢ F)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ])
→ (Δ ∙ F) ⊩ˢ wk1Subst σ ≡ wk1Subst σ′ ∷ Γ / [Γ]
/ (⊢Δ ∙ ⊢F) / wk1SubstS [Γ] ⊢Δ ⊢F [σ]
wk1SubstSEq {l} {F} {σ} {Γ} {Δ} [Γ] ⊢Δ ⊢F [σ] [σ≡σ′] =
wkSubstSEq [Γ] ⊢Δ (⊢Δ ∙ ⊢F) (step id) [σ] [σ≡σ′]
-- Lift a valid substitution
liftSubstS : ∀ {l F σ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ (Δ ∙ subst σ F) ⊩ˢ liftSubst σ ∷ Γ ∙ F / [Γ] ∙″ [F]
/ (⊢Δ ∙ escape (proj₁ ([F] ⊢Δ [σ])))
liftSubstS {F = F} {σ = σ} {Δ = Δ} [Γ] ⊢Δ [F] [σ] =
let ⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[tailσ] = wk1SubstS {F = subst σ F} [Γ] ⊢Δ (escape (proj₁ ([F] ⊢Δ [σ]))) [σ]
var0 = var (⊢Δ ∙ ⊢F) (PE.subst (λ x → 0 ∷ x ∈ (Δ ∙ subst σ F))
(wk-subst F) here)
in [tailσ] , neuTerm (proj₁ ([F] (⊢Δ ∙ ⊢F) [tailσ])) (var 0)
var0 (~-var var0)
-- Lift a valid substitution equality
liftSubstSEq : ∀ {l F σ σ′ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ])
→ (Δ ∙ subst σ F) ⊩ˢ liftSubst σ ≡ liftSubst σ′ ∷ Γ ∙ F / [Γ] ∙″ [F]
/ (⊢Δ ∙ escape (proj₁ ([F] ⊢Δ [σ])))
/ liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
liftSubstSEq {F = F} {σ = σ} {σ′ = σ′} {Δ = Δ} [Γ] ⊢Δ [F] [σ] [σ≡σ′] =
let ⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[tailσ] = wk1SubstS {F = subst σ F} [Γ] ⊢Δ (escape (proj₁ ([F] ⊢Δ [σ]))) [σ]
[tailσ≡σ′] = wk1SubstSEq [Γ] ⊢Δ (escape (proj₁ ([F] ⊢Δ [σ]))) [σ] [σ≡σ′]
var0 = var (⊢Δ ∙ ⊢F) (PE.subst (λ x → 0 ∷ x ∈ (Δ ∙ subst σ F)) (wk-subst F) here)
in [tailσ≡σ′] , neuEqTerm (proj₁ ([F] (⊢Δ ∙ ⊢F) [tailσ])) (var 0) (var 0)
var0 var0 (~-var var0)
mutual
-- Valid contexts are well-formed
soundContext : ∀ {Γ} → ⊩ᵛ Γ → ⊢ Γ
soundContext ε′ = ε
soundContext (x ∙′ x₁) =
soundContext x ∙ escape (irrelevance′ (subst-id _)
(proj₁ (x₁ (soundContext x)
(idSubstS x))))
-- From a valid context we can constuct a valid identity substitution
idSubstS : ∀ {Γ} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ˢ idSubst ∷ Γ / [Γ] / soundContext [Γ]
idSubstS ε′ = tt
idSubstS {Γ = Γ ∙ A} ([Γ] ∙′ [A]) =
let ⊢Γ = soundContext [Γ]
⊢Γ∙A = soundContext ([Γ] ∙″ [A])
⊢Γ∙A′ = ⊢Γ ∙ escape (proj₁ ([A] ⊢Γ (idSubstS [Γ])))
[A]′ = wk1SubstS {F = subst idSubst A} [Γ] ⊢Γ
(escape (proj₁ ([A] (soundContext [Γ])
(idSubstS [Γ]))))
(idSubstS [Γ])
[tailσ] = irrelevanceSubst′ (PE.cong (_∙_ Γ) (subst-id A))
[Γ] [Γ] ⊢Γ∙A′ ⊢Γ∙A [A]′
var0 = var ⊢Γ∙A (PE.subst (λ x → 0 ∷ x ∈ (Γ ∙ A))
(wk-subst A)
(PE.subst (λ x → 0 ∷ wk1 (subst idSubst A)
∈ (Γ ∙ x))
(subst-id A) here))
in [tailσ]
, neuTerm (proj₁ ([A] ⊢Γ∙A [tailσ]))
(var 0)
var0 (~-var var0)
-- Reflexivity valid substitutions
reflSubst : ∀ {σ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩ˢ σ ≡ σ ∷ Γ / [Γ] / ⊢Δ / [σ]
reflSubst ε′ ⊢Δ [σ] = tt
reflSubst ([Γ] ∙′ x) ⊢Δ [σ] =
reflSubst [Γ] ⊢Δ (proj₁ [σ]) , reflEqTerm (proj₁ (x ⊢Δ (proj₁ [σ]))) (proj₂ [σ])
-- Reflexivity of valid identity substitution
reflIdSubst : ∀ {Γ} ([Γ] : ⊩ᵛ Γ)
→ Γ ⊩ˢ idSubst ≡ idSubst ∷ Γ / [Γ] / soundContext [Γ] / idSubstS [Γ]
reflIdSubst [Γ] = reflSubst [Γ] (soundContext [Γ]) (idSubstS [Γ])
-- Symmetry of valid substitution
symS : ∀ {σ σ′ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]
→ Δ ⊩ˢ σ′ ≡ σ ∷ Γ / [Γ] / ⊢Δ / [σ′]
symS ε′ ⊢Δ [σ] [σ′] [σ≡σ′] = tt
symS ([Γ] ∙′ x) ⊢Δ [σ] [σ′] [σ≡σ′] =
symS [Γ] ⊢Δ (proj₁ [σ]) (proj₁ [σ′]) (proj₁ [σ≡σ′])
, let [σA] = proj₁ (x ⊢Δ (proj₁ [σ]))
[σ′A] = proj₁ (x ⊢Δ (proj₁ [σ′]))
[σA≡σ′A] = (proj₂ (x ⊢Δ (proj₁ [σ]))) (proj₁ [σ′]) (proj₁ [σ≡σ′])
[headσ′≡headσ] = symEqTerm [σA] (proj₂ [σ≡σ′])
in convEqTerm₁ [σA] [σ′A] [σA≡σ′A] [headσ′≡headσ]
-- Transitivity of valid substitution
transS : ∀ {σ σ′ σ″ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ)
([σ″] : Δ ⊩ˢ σ″ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]
→ Δ ⊩ˢ σ′ ≡ σ″ ∷ Γ / [Γ] / ⊢Δ / [σ′]
→ Δ ⊩ˢ σ ≡ σ″ ∷ Γ / [Γ] / ⊢Δ / [σ]
transS ε′ ⊢Δ [σ] [σ′] [σ″] [σ≡σ′] [σ′≡σ″] = tt
transS ([Γ] ∙′ x) ⊢Δ [σ] [σ′] [σ″] [σ≡σ′] [σ′≡σ″] =
transS [Γ] ⊢Δ (proj₁ [σ]) (proj₁ [σ′]) (proj₁ [σ″])
(proj₁ [σ≡σ′]) (proj₁ [σ′≡σ″])
, let [σA] = proj₁ (x ⊢Δ (proj₁ [σ]))
[σ′A] = proj₁ (x ⊢Δ (proj₁ [σ′]))
[σ″A] = proj₁ (x ⊢Δ (proj₁ [σ″]))
[σ′≡σ″]′ = convEqTerm₂ [σA] [σ′A]
((proj₂ (x ⊢Δ (proj₁ [σ]))) (proj₁ [σ′])
(proj₁ [σ≡σ′])) (proj₂ [σ′≡σ″])
in transEqTerm [σA] (proj₂ [σ≡σ′]) [σ′≡σ″]′
| {
"alphanum_fraction": 0.4203410982,
"avg_line_length": 43.9086757991,
"ext": "agda",
"hexsha": "741478719f59a4083824dd4613c2214be2ae5504",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Properties.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4784,
"size": 9616
} |
module Self where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
data B : Set where
T : B
F : B
_&&_ : B -> B -> B
infixl 20 _&&_
T && T = T
T && F = F
F && _ = F
_||_ : B -> B -> B
infixl 15 _||_
T || _ = T
F || T = T
F || F = F
p||p≡p : ∀ (p : B) -> p || p ≡ p
p||p≡p T = refl
p||p≡p F = refl
p&&p≡p : ∀ (p : B) -> p && p ≡ p
p&&p≡p T = refl
p&&p≡p F = refl
-- 交换律
a&&b≡b&&a : ∀ (a b : B) -> a && b ≡ b && a
a&&b≡b&&a T T = refl
a&&b≡b&&a T F = refl
a&&b≡b&&a F T = refl
a&&b≡b&&a F F = refl
a||b≡b||a : ∀ (a b : B) -> a || b ≡ b || a
a||b≡b||a T T = refl
a||b≡b||a T F = refl
a||b≡b||a F T = refl
a||b≡b||a F F = refl
abc||abc : ∀ (a b c : B) -> (a || b) || c ≡ a || (b || c)
abc||abc T b c = refl
abc||abc F T c = refl
abc||abc F F T = refl
abc||abc F F F = refl
abc&&abc : ∀ (a b c : B) -> a && b && c ≡ a && (b && c)
abc&&abc T T T = refl
abc&&abc T T F = refl
abc&&abc T F c = refl
abc&&abc F b c = refl
-- 分配律
a&&b||c≡a&&b||a&&c : ∀ (a b c : B) -> a && (b || c) ≡ a && b || a && c
a&&b||c≡a&&b||a&&c T T c = refl
a&&b||c≡a&&b||a&&c T F T = refl
a&&b||c≡a&&b||a&&c T F F = refl
a&&b||c≡a&&b||a&&c F T c = refl
a&&b||c≡a&&b||a&&c F F c = refl
a||b&&c≡a||b&&a||c : ∀ (a b c : B) -> a || b && c ≡ (a || b) && (a || c)
a||b&&c≡a||b&&a||c T b c = refl
a||b&&c≡a||b&&a||c F T T = refl
a||b&&c≡a||b&&a||c F T F = refl
a||b&&c≡a||b&&a||c F F c = refl
T&&p≡p : ∀ (p : B) -> T && p ≡ p
T&&p≡p T = refl
T&&p≡p F = refl
F||p≡p : ∀ (p : B) -> F || p ≡ p
F||p≡p T = refl
F||p≡p F = refl
¬_ : B -> B
infix 25 ¬_
¬ F = T
¬ T = F
-- 负负得正
¬¬p≡p : ∀ (p : B) -> ¬ (¬ p) ≡ p
¬¬p≡p T = refl
¬¬p≡p F = refl
-- 德·摩根律
¬a&&b≡¬a||¬b : ∀ (a b : B) -> ¬ (a && b) ≡ ¬ a || ¬ b
¬a&&b≡¬a||¬b T T = refl
¬a&&b≡¬a||¬b T F = refl
¬a&&b≡¬a||¬b F T = refl
¬a&&b≡¬a||¬b F F = refl
¬a||b≡¬a&&¬b : ∀ (a b : B) -> ¬ (a || b) ≡ ¬ a && ¬ b
¬a||b≡¬a&&¬b T T = refl
¬a||b≡¬a&&¬b T F = refl
¬a||b≡¬a&&¬b F T = refl
¬a||b≡¬a&&¬b F F = refl
-- 自反律
p&&¬p≡F : ∀ (p : B) -> p && ¬ p ≡ F
p&&¬p≡F T = refl
p&&¬p≡F F = refl
-- 排中律
¬p||p≡T : ∀ (p : B) -> ¬ p || p ≡ T
¬p||p≡T T = refl
¬p||p≡T F = refl
-- 蕴含 如果 .. 就
_to_ : B -> B -> B
infixl 10 _to_
T to F = F
T to T = T
F to _ = T
-- 蕴含等值推演
ptoq≡¬p||q : ∀ (p q : B) -> p to q ≡ ¬ p || q
ptoq≡¬p||q T T = refl
ptoq≡¬p||q T F = refl
ptoq≡¬p||q F q = refl
Ttop≡p : ∀ (p : B) -> T to p ≡ p
Ttop≡p T = refl
Ttop≡p F = refl
Ftop≡T : ∀ (p : B) -> F to p ≡ T
Ftop≡T p = refl
-- 等价
_<>_ : B -> B -> B
infixl 10 _eq_
T <> T = T
F <> T = F
T <> F = F
F <> F = T
-- 等价等值式
p<>q≡ptoq&&qtop : ∀ (p q : B) -> p <> q ≡ (p to q) && (q to p)
p<>q≡ptoq&&qtop T T = refl
p<>q≡ptoq&&qtop T F = refl
p<>q≡ptoq&&qtop F T = refl
p<>q≡ptoq&&qtop F F = refl
-- lemma 01
p||q&&¬q≡p : ∀ (p q : B) -> p || q && ¬ q ≡ p
p||q&&¬q≡p T T = refl
p||q&&¬q≡p T F = refl
p||q&&¬q≡p F q rewrite p&&¬p≡F q = refl
-- proof 01
p&&q||p&&¬q≡p : ∀ (p q : B) -> p && q || p && ¬ q ≡ p
p&&q||p&&¬q≡p T T = refl
p&&q||p&&¬q≡p T F = refl
p&&q||p&&¬q≡p F q = refl
-- proof 02
atob≡¬bto¬a : ∀ (a b : B) -> a to b ≡ ¬ b to ¬ a
atob≡¬bto¬a a b
rewrite ptoq≡¬p||q a b
| ptoq≡¬p||q (¬ b) (¬ a)
| a||b≡b||a (¬ a) b
| ¬¬p≡p b = refl
implies₁ : ∀ (p q r s : B) -> ((p to (q to r)) && (¬ s || p) && q) to (s to r) ≡ T
implies₁ T T T T = refl
implies₁ T T T F = refl
implies₁ T T F s = refl
implies₁ T F T T = refl
implies₁ T F T F = refl
implies₁ T F F T = refl
implies₁ T F F F = refl
implies₁ F T T T = refl
implies₁ F T T F = refl
implies₁ F T F T = refl
implies₁ F T F F = refl
implies₁ F F r T = refl
implies₁ F F r F = refl
| {
"alphanum_fraction": 0.4321678322,
"avg_line_length": 18.9153439153,
"ext": "agda",
"hexsha": "2852390130abeeb86119492fb2ee970ed59edf64",
"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": "b3c9c4f678feac75af6f30d0dd941ab58b9f40dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kands-code/agda-exercise",
"max_forks_repo_path": "Self.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b3c9c4f678feac75af6f30d0dd941ab58b9f40dd",
"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": "kands-code/agda-exercise",
"max_issues_repo_path": "Self.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b3c9c4f678feac75af6f30d0dd941ab58b9f40dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kands-code/agda-exercise",
"max_stars_repo_path": "Self.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2013,
"size": 3575
} |
module my-vector where
open import nat
open import bool
open import eq
data 𝕍 {ℓ}(A : Set ℓ) : ℕ → Set ℓ where
[] : 𝕍 A 0
_::_ : {n : ℕ} (x : A) (xs : 𝕍 A n) → 𝕍 A (suc n)
infixr 6 _::_ _++𝕍_
_++𝕍_ : ∀ {ℓ} {A : Set ℓ}{n m : ℕ} →
𝕍 A n → 𝕍 A m → 𝕍 A (n + m)
[] ++𝕍 ys = ys
(x :: xs) ++𝕍 ys = x :: (xs ++𝕍 ys)
test-vector : 𝕍 𝔹 4
test-vector = ff :: tt :: ff :: ff :: []
test-vector-append : 𝕍 𝔹 8
test-vector-append = test-vector ++𝕍 test-vector
head𝕍 : ∀{ℓ}{A : Set ℓ}{n : ℕ} → 𝕍 A (suc n) → A
head𝕍 (x :: _) = x
tail𝕍 : ∀{ℓ}{A : Set ℓ}{n : ℕ} → 𝕍 A n → 𝕍 A (pred n)
tail𝕍 [] = []
tail𝕍 (_ :: xs) = xs
map𝕍 : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}{n : ℕ} →
(A → B) → 𝕍 A n → 𝕍 B n
map𝕍 f [] = []
map𝕍 f (x :: xs) = f x :: map𝕍 f xs
concat𝕍 : ∀{ℓ}{A : Set ℓ}{n m : ℕ} →
𝕍 (𝕍 A n) m → 𝕍 A (m * n)
concat𝕍 [] = []
concat𝕍 (xs :: xs₁) = xs ++𝕍 (concat𝕍 xs₁)
nth𝕍 : ∀{ℓ}{A : Set ℓ}{m : ℕ} →
(n : ℕ) → n < m ≡ tt → 𝕍 A m → A
nth𝕍 zero () []
nth𝕍 zero _ (x :: _) = x
nth𝕍 (suc _) () []
nth𝕍 (suc n₁) p (_ :: xs) = nth𝕍 n₁ p xs
repeat𝕍 : ∀{ℓ}{A : Set ℓ} → (a : A)(n : ℕ) → 𝕍 A n
repeat𝕍 a zero = []
repeat𝕍 a (suc n) = a :: (repeat𝕍 a n)
| {
"alphanum_fraction": 0.4564102564,
"avg_line_length": 22.9411764706,
"ext": "agda",
"hexsha": "5f94e896505d9932c95b5ea250f2cd466a11403b",
"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": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "logicshan/IAL",
"max_forks_repo_path": "my-vector.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"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": "logicshan/IAL",
"max_issues_repo_path": "my-vector.agda",
"max_line_length": 53,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "logicshan/IAL",
"max_stars_repo_path": "my-vector.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 636,
"size": 1170
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.