Search is not available for this dataset
text
string | meta
dict |
---|---|
open import Agda.Builtin.Bool
data D : Set where
run-time : D
@0 compile-time : D
-- This code should be rejected: Both f compile-time and f run-time
-- are type-correct run-time terms.
f : @0 D → Bool
f compile-time = true
f run-time = false
| {
"alphanum_fraction": 0.6590038314,
"avg_line_length": 20.0769230769,
"ext": "agda",
"hexsha": "b3d4d02f6d2a9c75fe7fe0322d57fbe757c8c5db",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Fail/Issue4638-4.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Fail/Issue4638-4.agda",
"max_line_length": 67,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Fail/Issue4638-4.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 77,
"size": 261
} |
------------------------------------------------------------------------
-- Solver for commutative ring or semiring equalities
------------------------------------------------------------------------
-- Uses ideas from the Coq ring tactic. See "Proving Equalities in a
-- Commutative Ring Done Right in Coq" by Grégoire and Mahboubi. The
-- code below is not optimised like theirs, though.
open import Algebra
open import Algebra.RingSolver.AlmostCommutativeRing
module Algebra.RingSolver
(coeff : RawRing) -- Coefficient "ring".
(r : AlmostCommutativeRing) -- Main "ring".
(morphism : coeff -Raw-AlmostCommutative⟶ r)
where
import Algebra.RingSolver.Lemmas as L; open L coeff r morphism
private module C = RawRing coeff
open AlmostCommutativeRing r hiding (zero)
import Algebra.FunctionProperties as P; open P _≈_
open import Algebra.Morphism
open _-RawRing⟶_ morphism renaming (⟦_⟧ to ⟦_⟧')
import Algebra.Operations as Ops; open Ops semiring
open import Relation.Binary
import Relation.Binary.PropositionalEquality as PropEq
import Relation.Binary.Reflection as Reflection
open import Data.Nat using (ℕ; suc; zero) renaming (_+_ to _ℕ-+_)
open import Data.Fin as Fin using (Fin; zero; suc)
open import Data.Vec
open import Data.Function hiding (_∶_)
infix 9 _↑ :-_ -‿NF_
infixr 9 _:^_ _^-NF_ _:↑_
infix 8 _*x _*x+_
infixl 8 _:*_ _*-NF_ _↑-*-NF_
infixl 7 _:+_ _+-NF_ _:-_
infixl 0 _∶_
------------------------------------------------------------------------
-- Polynomials
data Op : Set where
[+] : Op
[*] : Op
-- The polynomials are indexed over the number of variables.
data Polynomial (m : ℕ) : Set where
op : (o : Op) (p₁ : Polynomial m) (p₂ : Polynomial m) → Polynomial m
con : (c : C.carrier) → Polynomial m
var : (x : Fin m) → Polynomial m
_:^_ : (p : Polynomial m) (n : ℕ) → Polynomial m
:-_ : (p : Polynomial m) → Polynomial m
-- Short-hand notation.
_:+_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
_:+_ = op [+]
_:*_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
_:*_ = op [*]
_:-_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
x :- y = x :+ :- y
-- Semantics.
sem : Op → Op₂ carrier
sem [+] = _+_
sem [*] = _*_
⟦_⟧ : ∀ {n} → Polynomial n → Vec carrier n → carrier
⟦ op o p₁ p₂ ⟧ ρ = ⟦ p₁ ⟧ ρ ⟨ sem o ⟩ ⟦ p₂ ⟧ ρ
⟦ con c ⟧ ρ = ⟦ c ⟧'
⟦ var x ⟧ ρ = lookup x ρ
⟦ p :^ n ⟧ ρ = ⟦ p ⟧ ρ ^ n
⟦ :- p ⟧ ρ = - ⟦ p ⟧ ρ
private
-- Equality.
_≛_ : ∀ {n} → Polynomial n → Polynomial n → Set
p₁ ≛ p₂ = ∀ {ρ} → ⟦ p₁ ⟧ ρ ≈ ⟦ p₂ ⟧ ρ
-- Reindexing.
_:↑_ : ∀ {n} → Polynomial n → (m : ℕ) → Polynomial (m ℕ-+ n)
op o p₁ p₂ :↑ m = op o (p₁ :↑ m) (p₂ :↑ m)
con c :↑ m = con c
var x :↑ m = var (Fin.raise m x)
(p :^ n) :↑ m = (p :↑ m) :^ n
(:- p) :↑ m = :- (p :↑ m)
------------------------------------------------------------------------
-- Normal forms of polynomials
private
-- The normal forms (Horner forms) are indexed over
-- * the number of variables in the polynomial, and
-- * an equivalent polynomial.
data Normal : (n : ℕ) → Polynomial n → Set where
con : (c : C.carrier) → Normal 0 (con c)
_↑ : ∀ {n p'} (p : Normal n p') → Normal (suc n) (p' :↑ 1)
_*x+_ : ∀ {n p' c'} (p : Normal (suc n) p') (c : Normal n c') →
Normal (suc n) (p' :* var zero :+ c' :↑ 1)
_∶_ : ∀ {n p₁ p₂} (p : Normal n p₁) (eq : p₁ ≛ p₂) → Normal n p₂
⟦_⟧-NF : ∀ {n p} → Normal n p → Vec carrier n → carrier
⟦ p ∶ _ ⟧-NF ρ = ⟦ p ⟧-NF ρ
⟦ con c ⟧-NF ρ = ⟦ c ⟧'
⟦ p ↑ ⟧-NF (x ∷ ρ) = ⟦ p ⟧-NF ρ
⟦ p *x+ c ⟧-NF (x ∷ ρ) = (⟦ p ⟧-NF (x ∷ ρ) * x) + ⟦ c ⟧-NF ρ
------------------------------------------------------------------------
-- Normalisation
private
con-NF : ∀ {n} → (c : C.carrier) → Normal n (con c)
con-NF {zero} c = con c
con-NF {suc _} c = con-NF c ↑
_+-NF_ : ∀ {n p₁ p₂} → Normal n p₁ → Normal n p₂ → Normal n (p₁ :+ p₂)
(p₁ ∶ eq₁) +-NF (p₂ ∶ eq₂) = p₁ +-NF p₂ ∶ eq₁ ⟨ +-pres-≈ ⟩ eq₂
(p₁ ∶ eq) +-NF p₂ = p₁ +-NF p₂ ∶ eq ⟨ +-pres-≈ ⟩ refl
p₁ +-NF (p₂ ∶ eq) = p₁ +-NF p₂ ∶ refl ⟨ +-pres-≈ ⟩ eq
con c₁ +-NF con c₂ = con (C._+_ c₁ c₂) ∶ +-homo _ _
p₁ ↑ +-NF p₂ ↑ = (p₁ +-NF p₂) ↑ ∶ refl
p₁ *x+ c₁ +-NF p₂ ↑ = p₁ *x+ (c₁ +-NF p₂) ∶ sym (+-assoc _ _ _)
p₁ *x+ c₁ +-NF p₂ *x+ c₂ = (p₁ +-NF p₂) *x+ (c₁ +-NF c₂) ∶ lemma₁ _ _ _ _ _
p₁ ↑ +-NF p₂ *x+ c₂ = p₂ *x+ (p₁ +-NF c₂) ∶ lemma₂ _ _ _
_*x : ∀ {n p} → Normal (suc n) p → Normal (suc n) (p :* var zero)
p *x = p *x+ con-NF C.0# ∶ lemma₀ _
mutual
-- The first function is just a variant of _*-NF_ which I used to
-- make the termination checker believe that the code is
-- terminating.
_↑-*-NF_ : ∀ {n p₁ p₂} →
Normal n p₁ → Normal (suc n) p₂ →
Normal (suc n) (p₁ :↑ 1 :* p₂)
p₁ ↑-*-NF (p₂ ∶ eq) = p₁ ↑-*-NF p₂ ∶ refl ⟨ *-pres-≈ ⟩ eq
p₁ ↑-*-NF p₂ ↑ = (p₁ *-NF p₂) ↑ ∶ refl
p₁ ↑-*-NF (p₂ *x+ c₂) = (p₁ ↑-*-NF p₂) *x+ (p₁ *-NF c₂) ∶ lemma₄ _ _ _ _
_*-NF_ : ∀ {n p₁ p₂} →
Normal n p₁ → Normal n p₂ → Normal n (p₁ :* p₂)
(p₁ ∶ eq₁) *-NF (p₂ ∶ eq₂) = p₁ *-NF p₂ ∶ eq₁ ⟨ *-pres-≈ ⟩ eq₂
(p₁ ∶ eq) *-NF p₂ = p₁ *-NF p₂ ∶ eq ⟨ *-pres-≈ ⟩ refl
p₁ *-NF (p₂ ∶ eq) = p₁ *-NF p₂ ∶ refl ⟨ *-pres-≈ ⟩ eq
con c₁ *-NF con c₂ = con (C._*_ c₁ c₂) ∶ *-homo _ _
p₁ ↑ *-NF p₂ ↑ = (p₁ *-NF p₂) ↑ ∶ refl
(p₁ *x+ c₁) *-NF p₂ ↑ = (p₁ *-NF p₂ ↑) *x+ (c₁ *-NF p₂) ∶ lemma₃ _ _ _ _
p₁ ↑ *-NF (p₂ *x+ c₂) = (p₁ ↑ *-NF p₂) *x+ (p₁ *-NF c₂) ∶ lemma₄ _ _ _ _
(p₁ *x+ c₁) *-NF (p₂ *x+ c₂) =
(p₁ *-NF p₂) *x *x +-NF
(p₁ *-NF c₂ ↑ +-NF c₁ ↑-*-NF p₂) *x+ (c₁ *-NF c₂) ∶ lemma₅ _ _ _ _ _
-‿NF_ : ∀ {n p} → Normal n p → Normal n (:- p)
-‿NF (p ∶ eq) = -‿NF p ∶ -‿pres-≈ eq
-‿NF con c = con (C.-_ c) ∶ -‿homo _
-‿NF (p ↑) = (-‿NF p) ↑
-‿NF (p *x+ c) = -‿NF p *x+ -‿NF c ∶ lemma₆ _ _ _
var-NF : ∀ {n} → (i : Fin n) → Normal n (var i)
var-NF zero = con-NF C.1# *x+ con-NF C.0# ∶ lemma₇ _
var-NF (suc i) = var-NF i ↑
_^-NF_ : ∀ {n p} → Normal n p → (i : ℕ) → Normal n (p :^ i)
p ^-NF zero = con-NF C.1# ∶ 1-homo
p ^-NF suc n = p *-NF p ^-NF n ∶ refl
normaliseOp : ∀ (o : Op) {n p₁ p₂} →
Normal n p₁ → Normal n p₂ → Normal n (p₁ ⟨ op o ⟩ p₂)
normaliseOp [+] = _+-NF_
normaliseOp [*] = _*-NF_
normalise : ∀ {n} (p : Polynomial n) → Normal n p
normalise (op o p₁ p₂) = normalise p₁ ⟨ normaliseOp o ⟩ normalise p₂
normalise (con c) = con-NF c
normalise (var i) = var-NF i
normalise (p :^ n) = normalise p ^-NF n
normalise (:- p) = -‿NF normalise p
⟦_⟧↓ : ∀ {n} → Polynomial n → Vec carrier n → carrier
⟦ p ⟧↓ ρ = ⟦ normalise p ⟧-NF ρ
------------------------------------------------------------------------
-- Correctness
private
sem-pres-≈ : ∀ op → sem op Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_
sem-pres-≈ [+] = +-pres-≈
sem-pres-≈ [*] = *-pres-≈
raise-sem : ∀ {n x} (p : Polynomial n) ρ →
⟦ p :↑ 1 ⟧ (x ∷ ρ) ≈ ⟦ p ⟧ ρ
raise-sem (op o p₁ p₂) ρ = raise-sem p₁ ρ ⟨ sem-pres-≈ o ⟩
raise-sem p₂ ρ
raise-sem (con c) ρ = refl
raise-sem (var x) ρ = refl
raise-sem (p :^ n) ρ = raise-sem p ρ ⟨ ^-pres-≈ ⟩
PropEq.refl {x = n}
raise-sem (:- p) ρ = -‿pres-≈ (raise-sem p ρ)
nf-sound : ∀ {n p} (nf : Normal n p) ρ →
⟦ nf ⟧-NF ρ ≈ ⟦ p ⟧ ρ
nf-sound (nf ∶ eq) ρ = nf-sound nf ρ ⟨ trans ⟩ eq
nf-sound (con c) ρ = refl
nf-sound (_↑ {p' = p'} nf) (x ∷ ρ) =
nf-sound nf ρ ⟨ trans ⟩ sym (raise-sem p' ρ)
nf-sound (_*x+_ {c' = c'} nf₁ nf₂) (x ∷ ρ) =
(nf-sound nf₁ (x ∷ ρ) ⟨ *-pres-≈ ⟩ refl)
⟨ +-pres-≈ ⟩
(nf-sound nf₂ ρ ⟨ trans ⟩ sym (raise-sem c' ρ))
-- Completeness can presumably also be proved (i.e. the normal forms
-- should be unique, if the casts are ignored).
------------------------------------------------------------------------
-- "Tactics"
open Reflection setoid var ⟦_⟧ ⟦_⟧↓ (nf-sound ∘ normalise)
public using (prove; solve) renaming (_⊜_ to _:=_)
-- For examples of how solve and _:=_ can be used to
-- semi-automatically prove ring equalities, see, for instance,
-- Data.Digit or Data.Nat.DivMod.
| {
"alphanum_fraction": 0.4684956987,
"avg_line_length": 36.1428571429,
"ext": "agda",
"hexsha": "77c962636fbce2daacd519b90de552bedb6c6c6c",
"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/RingSolver.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/RingSolver.agda",
"max_line_length": 91,
"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/RingSolver.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": 3416,
"size": 8602
} |
{-# OPTIONS --without-K #-}
module function.overloading {i j}{X : Set i}{Y : Set j} where
open import level
open import sum
open import overloading.core
fun-is-fun : Coercion (X → Y) (X → Y)
fun-is-fun = coerce-self _
private
module fun-methods {k}{Source : Set k}
⦃ c : Coercion Source (X → Y) ⦄ where
open Coercion c public using ()
renaming (coerce to apply)
open fun-methods public
| {
"alphanum_fraction": 0.6382978723,
"avg_line_length": 23.5,
"ext": "agda",
"hexsha": "4143716d5cbefb0ac3aa85a7fc9bbeda3776ba79",
"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": "function/overloading.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/function/overloading.agda",
"max_line_length": 61,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "function/overloading.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": 124,
"size": 423
} |
module Base.Isomorphism where
open import Relation.Binary.PropositionalEquality using (_≡_)
-- The stdlib contains `Function.Inverse`, which seems to have a similar purpose, but is more complicated.
infix 0 _≃_
record _≃_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
| {
"alphanum_fraction": 0.6328125,
"avg_line_length": 25.6,
"ext": "agda",
"hexsha": "ae646cc65749e0a242fa4ad46806e81a175f588c",
"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/Isomorphism.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/Isomorphism.agda",
"max_line_length": 106,
"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/Isomorphism.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": 134,
"size": 384
} |
{-# OPTIONS --without-K #-}
module A 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
{--
Just confirming that the following does not typecheck!
proof-irrelevance : {A : Set} {x y : A} (p q : x ≡ y) → p ≡ q
proof-irrelevance (refl x) (refl .x) = refl (refl x)
--}
------------------------------------------------------------------------------
{--
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
--}
data U : Set where
ZERO : U
ONE : U
PLUS : U → U → U
TIMES : U → U → U
-- Points
⟦_⟧ : U → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS t t' ⟧ = ⟦ t ⟧ ⊎ ⟦ t' ⟧
⟦ TIMES t t' ⟧ = ⟦ t ⟧ × ⟦ t' ⟧
BOOL : U
BOOL = PLUS ONE ONE
BOOL² : U
BOOL² = TIMES BOOL BOOL
TRUE : ⟦ BOOL ⟧
TRUE = inj₁ tt
FALSE : ⟦ BOOL ⟧
FALSE = inj₂ tt
NOT : ⟦ BOOL ⟧ → ⟦ BOOL ⟧
NOT (inj₁ tt) = FALSE
NOT (inj₂ tt) = TRUE
CNOT : ⟦ BOOL ⟧ → ⟦ BOOL ⟧ → ⟦ BOOL ⟧ × ⟦ BOOL ⟧
CNOT (inj₁ tt) b = (TRUE , NOT b)
CNOT (inj₂ tt) b = (FALSE , b)
------------------------------------------------------------------------------
-- Paths connect points in t₁ and t₂ if there is an isomorphism between the
-- types t₁ and t₂. The family ⟷ plays the role of identity types in HoTT
data _⟷_ : U → U → Set where
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₃
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₄)
cond : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₁ ⟷ t₂) →
((TIMES BOOL t₁) ⟷ (TIMES BOOL t₂))
cond f g = dist ◎ ((id⟷ ⊗ f) ⊕ (id⟷ ⊗ g)) ◎ factor
controlled : {t : U} → (t ⟷ t) → ((TIMES BOOL t) ⟷ (TIMES BOOL t))
controlled f = cond f id⟷
cnot : BOOL² ⟷ BOOL²
cnot = controlled swap₊
-- Paths: each combinator defines a space of paths between its end points
mutual
Paths : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₁ ⟧ → ⟦ t₂ ⟧ → Set
Paths unite₊ (inj₁ ())
Paths unite₊ (inj₂ v) v' = (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₂'
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₂'
-- Given a combinator c : t₁ ⟷ t₂ and values v₁ : ⟦ t₁ ⟧ and v₂ : ⟦ t₂ ⟧,
-- Paths c v₁ v₂ gives us the space of paths that could connect v₁ and v₂
-- Examples:
pathIdtt : Paths id⟷ tt tt
pathIdtt = refl tt
-- four different ways of relating F to F:
pathIdFF : Paths id⟷ FALSE FALSE
pathIdFF = refl FALSE
pathIdIdFF : Paths (id⟷ ◎ id⟷) FALSE FALSE
pathIdIdFF = (FALSE , refl FALSE , refl FALSE)
pathNotNotFF : Paths (swap₊ ◎ swap₊) FALSE FALSE
pathNotNotFF = TRUE , refl tt , refl tt
pathPlusFF : Paths (id⟷ ⊕ id⟷) FALSE FALSE
pathPlusFF = refl tt
-- are there 2-paths between the above 3 paths???
-- space of paths is empty; cannot produce any path; can
-- use pattern matching to confirm that the space is empty
pathIdFT : Paths id⟷ FALSE TRUE → ⊤
pathIdFT ()
-- three different ways of relating (F,F) to (F,F)
pathIdFFFF : Paths id⟷ (FALSE , FALSE) (FALSE , FALSE)
pathIdFFFF = refl (FALSE , FALSE)
pathTimesFFFF : Paths (id⟷ ⊗ id⟷) (FALSE , FALSE) (FALSE , FALSE)
pathTimesFFFF = (refl FALSE , refl FALSE)
pathTimesPlusFFFF : Paths
((id⟷ ⊕ id⟷) ⊗ (id⟷ ⊕ id⟷))
(FALSE , FALSE) (FALSE , FALSE)
pathTimesPlusFFFF = (refl tt , refl tt)
pathSwap₊FT : Paths swap₊ FALSE TRUE
pathSwap₊FT = refl tt
pathSwap₊TF : Paths swap₊ TRUE FALSE
pathSwap₊TF = refl tt
-- no path
pathSwap₊FF : Paths swap₊ FALSE FALSE → ⊤
pathSwap₊FF ()
-- intuitively the two paths below should not be related by a 2-path because
-- pathCnotTF is "essentially" cnot which would map (F,F) to (F,F) but
-- pathIdNotTF would map (F,F) to (F,T).
pathIdNotFF : Paths (id⟷ ⊗ swap₊) (FALSE , FALSE) (FALSE , TRUE)
pathIdNotFF = refl FALSE , refl tt
pathIdNotFT : Paths (id⟷ ⊗ swap₊) (FALSE , TRUE) (FALSE , FALSE)
pathIdNotFT = refl FALSE , refl tt
pathIdNotTF : Paths (id⟷ ⊗ swap₊) (TRUE , FALSE) (TRUE , TRUE)
pathIdNotTF = refl TRUE , refl tt
pathIdNotTT : Paths (id⟷ ⊗ swap₊) (TRUE , TRUE) (TRUE , FALSE)
pathIdNotTT = refl TRUE , refl tt
pathIdNotb : {b₁ b₂ : ⟦ BOOL ⟧} → Paths (id⟷ ⊗ swap₊) (b₁ , b₂) (b₁ , NOT b₂)
pathIdNotb {b₁} {inj₁ tt} = refl b₁ , refl tt
pathIdNotb {b₁} {inj₂ tt} = refl b₁ , refl tt
pathCnotbb : {b₁ b₂ : ⟦ BOOL ⟧} → Paths cnot (b₁ , b₂) (CNOT b₁ b₂)
pathCnotbb {inj₁ tt} {inj₁ tt} = inj₁ (tt , TRUE) ,
(refl tt , refl TRUE) ,
(inj₁ (tt , FALSE) ,
(refl tt , refl tt) ,
(refl tt , refl FALSE))
pathCnotbb {inj₁ tt} {inj₂ tt} = inj₁ (tt , FALSE) ,
(refl tt , refl FALSE) ,
(inj₁ (tt , TRUE) ,
(refl tt , refl tt) ,
(refl tt , refl TRUE))
pathCnotbb {inj₂ tt} {b₂} = inj₂ (tt , b₂) ,
(refl tt , refl b₂) ,
(inj₂ (tt , b₂) ,
(refl tt , refl b₂) ,
(refl tt , refl b₂))
pathCnotFF : Paths cnot (FALSE , FALSE) (FALSE , FALSE)
pathCnotFF = inj₂ (tt , FALSE) ,
(refl tt , refl FALSE) ,
(inj₂ (tt , FALSE) ,
(refl tt , refl FALSE) ,
(refl tt , refl FALSE))
pathCnotFT : Paths cnot (FALSE , TRUE) (FALSE , TRUE)
pathCnotFT = inj₂ (tt , TRUE) ,
(refl tt , refl TRUE) ,
(inj₂ (tt , TRUE) ,
(refl tt , refl TRUE) ,
(refl tt , refl TRUE))
pathCnotTF : Paths cnot (TRUE , FALSE) (TRUE , TRUE)
pathCnotTF = inj₁ (tt , FALSE) , -- first intermediate value
-- path using dist from (T,F) to (inj₁ (tt , F))
(refl tt , refl FALSE) ,
-- path from (inj₁ (tt , F)) to (T,T)
(inj₁ (tt , TRUE) , -- next intermediate value
(refl tt , refl tt) ,
(refl tt , refl TRUE))
pathCnotTT : Paths cnot (TRUE , TRUE) (TRUE , FALSE)
pathCnotTT = inj₁ (tt , TRUE) ,
(refl tt , refl TRUE) ,
(inj₁ (tt , FALSE) ,
(refl tt , refl tt) ,
(refl tt , refl FALSE))
pathUnite₊ : {t : U} {v v' : ⟦ t ⟧} → (v ≡ v') → Paths unite₊ (inj₂ v) v'
pathUnite₊ p = p
-- Higher groupoid structure
-- For every path between v₁ and v₂ there is a path between v₂ and v₁
mutual
pathInv : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {c : t₁ ⟷ t₂} →
Paths c v₁ v₂ → Paths (sym⟷ c) v₂ v₁
pathInv {v₁ = inj₁ ()} {v₂ = v} {unite₊}
pathInv {v₁ = inj₂ v} {v₂ = v'} {unite₊} p = sym p
pathInv {v₁ = v} {v₂ = inj₁ ()} {uniti₊}
pathInv {v₁ = v} {v₂ = inj₂ v'} {uniti₊} p = sym p
pathInv {v₁ = inj₁ v} {v₂ = inj₁ v'} {swap₊} ()
pathInv {v₁ = inj₁ v} {v₂ = inj₂ v'} {swap₊} p = sym p
pathInv {v₁ = inj₂ v} {v₂ = inj₁ v'} {swap₊} p = sym p
pathInv {v₁ = inj₂ v} {v₂ = inj₂ v'} {swap₊} ()
pathInv {v₁ = inj₁ v} {v₂ = inj₁ (inj₁ v')} {assocl₊} p = sym p
pathInv {v₁ = inj₁ v} {v₂ = inj₁ (inj₂ v')} {assocl₊} ()
pathInv {v₁ = inj₁ v} {v₂ = inj₂ v'} {assocl₊} ()
pathInv {v₁ = inj₂ (inj₁ v)} {v₂ = inj₁ (inj₁ v')} {assocl₊} ()
pathInv {v₁ = inj₂ (inj₁ v)} {v₂ = inj₁ (inj₂ v')} {assocl₊} p = sym p
pathInv {v₁ = inj₂ (inj₁ v)} {v₂ = inj₂ v'} {assocl₊} ()
pathInv {v₁ = inj₂ (inj₂ v)} {v₂ = inj₁ v'} {assocl₊} ()
pathInv {v₁ = inj₂ (inj₂ v)} {v₂ = inj₂ v'} {assocl₊} p = sym p
pathInv {v₁ = inj₁ (inj₁ v)} {v₂ = inj₁ v'} {assocr₊} p = sym p
pathInv {v₁ = inj₁ (inj₁ v)} {v₂ = inj₂ v'} {assocr₊} ()
pathInv {v₁ = inj₁ (inj₂ v)} {v₂ = inj₁ v'} {assocr₊} ()
pathInv {v₁ = inj₁ (inj₂ v)} {v₂ = inj₂ (inj₁ v')} {assocr₊} p = sym p
pathInv {v₁ = inj₁ (inj₂ v)} {v₂ = inj₂ (inj₂ v')} {assocr₊} ()
pathInv {v₁ = inj₂ v} {v₂ = inj₁ v'} {assocr₊} ()
pathInv {v₁ = inj₂ v} {v₂ = inj₂ (inj₁ v')} {assocr₊} ()
pathInv {v₁ = inj₂ v} {v₂ = inj₂ (inj₂ v')} {assocr₊} p = sym p
pathInv {v₁ = (tt , v)} {v₂ = v'} {unite⋆} p = sym p
pathInv {v₁ = v} {v₂ = (tt , v')} {uniti⋆} p = sym p
pathInv {v₁ = (u , v)} {v₂ = (v' , u')} {swap⋆} (p₁ , p₂) = (sym p₂ , sym p₁)
pathInv {v₁ = (u , (v , w))} {v₂ = ((u' , v') , w')} {assocl⋆} (p₁ , p₂ , p₃)
= (sym p₁ , sym p₂ , sym p₃)
pathInv {v₁ = ((u , v) , w)} {v₂ = (u' , (v' , w'))} {assocr⋆} (p₁ , p₂ , p₃)
= (sym p₁ , sym p₂ , sym p₃)
pathInv {v₁ = _} {v₂ = ()} {distz}
pathInv {v₁ = ()} {v₂ = _} {factorz}
pathInv {v₁ = (inj₁ v₁ , v₃)} {v₂ = inj₁ (v₁' , v₃')} {dist} (p₁ , p₂) =
(sym p₁ , sym p₂)
pathInv {v₁ = (inj₁ v₁ , v₃)} {v₂ = inj₂ (v₂' , v₃')} {dist} ()
pathInv {v₁ = (inj₂ v₂ , v₃)} {v₂ = inj₁ (v₁' , v₃')} {dist} ()
pathInv {v₁ = (inj₂ v₂ , v₃)} {v₂ = inj₂ (v₂' , v₃')} {dist} (p₁ , p₂) =
(sym p₁ , sym p₂)
pathInv {v₁ = inj₁ (v₁ , v₃)} {v₂ = (inj₁ v₁' , v₃')} {factor} (p₁ , p₂) =
(sym p₁ , sym p₂)
pathInv {v₁ = inj₁ (v₁ , v₃)} {v₂ = (inj₂ v₂' , v₃')} {factor} ()
pathInv {v₁ = inj₂ (v₂ , v₃)} {v₂ = (inj₁ v₁' , v₃')} {factor} ()
pathInv {v₁ = inj₂ (v₂ , v₃)} {v₂ = (inj₂ v₂' , v₃')} {factor} (p₁ , p₂) =
(sym p₁ , sym p₂)
pathInv {v₁ = v} {v₂ = v'} {id⟷} p = sym p
pathInv {v₁ = v} {v₂ = v'} {sym⟷ c} p = pathBInv {v₁ = v'} {v₂ = v} {c} p
pathInv {v₁ = v} {v₂ = v'} {c₁ ◎ c₂} (u , (p₁ , p₂)) =
(u , (pathInv {c = c₂} p₂ , pathInv {c = c₁} p₁))
pathInv {v₁ = inj₁ v} {v₂ = inj₁ v'} {c₁ ⊕ c₂} p = pathInv {c = c₁} p
pathInv {v₁ = inj₁ v} {v₂ = inj₂ v'} {c₁ ⊕ c₂} ()
pathInv {v₁ = inj₂ v} {v₂ = inj₁ v'} {c₁ ⊕ c₂} ()
pathInv {v₁ = inj₂ v} {v₂ = inj₂ v'} {c₁ ⊕ c₂} p = pathInv {c = c₂} p
pathInv {v₁ = (u , v)} {v₂ = (u' , v')} {c₁ ⊗ c₂} (p₁ , p₂) =
(pathInv {c = c₁} p₁ , pathInv {c = c₂} p₂)
pathBInv : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {c : t₁ ⟷ t₂} →
PathsB c v₂ v₁ → PathsB (sym⟷ c) v₁ v₂
pathBInv {v₁ = inj₁ ()} {v₂ = v} {unite₊}
pathBInv {v₁ = inj₂ v} {v₂ = v'} {unite₊} p = sym p
pathBInv {v₁ = v} {v₂ = inj₁ ()} {uniti₊}
pathBInv {v₁ = v} {v₂ = inj₂ v'} {uniti₊} p = sym p
pathBInv {v₁ = inj₁ v} {v₂ = inj₁ v'} {swap₊} ()
pathBInv {v₁ = inj₁ v} {v₂ = inj₂ v'} {swap₊} p = sym p
pathBInv {v₁ = inj₂ v} {v₂ = inj₁ v'} {swap₊} p = sym p
pathBInv {v₁ = inj₂ v} {v₂ = inj₂ v'} {swap₊} ()
pathBInv {v₁ = inj₁ v} {v₂ = inj₁ (inj₁ v')} {assocl₊} p = sym p
pathBInv {v₁ = inj₂ v} {v₂ = inj₁ (inj₁ v')} {assocl₊} ()
pathBInv {v₁ = inj₁ v} {v₂ = inj₁ (inj₂ v')} {assocl₊} ()
pathBInv {v₁ = inj₂ (inj₁ v)} {v₂ = inj₁ (inj₂ v')} {assocl₊} p = sym p
pathBInv {v₁ = inj₂ (inj₂ v)} {v₂ = inj₁ (inj₂ v')} {assocl₊} ()
pathBInv {v₁ = inj₁ v} {v₂ = inj₂ v'} {assocl₊} ()
pathBInv {v₁ = inj₂ (inj₁ v)} {v₂ = inj₂ v'} {assocl₊} ()
pathBInv {v₁ = inj₂ (inj₂ v)} {v₂ = inj₂ v'} {assocl₊} p = sym p
pathBInv {v₁ = inj₁ (inj₁ v)} {v₂ = inj₁ v'} {assocr₊} p = sym p
pathBInv {v₁ = inj₁ (inj₂ v)} {v₂ = inj₁ v'} {assocr₊} ()
pathBInv {v₁ = inj₂ v} {v₂ = inj₁ v'} {assocr₊} ()
pathBInv {v₁ = inj₁ (inj₁ v)} {v₂ = inj₂ (inj₁ v')} {assocr₊} ()
pathBInv {v₁ = inj₁ (inj₂ v)} {v₂ = inj₂ (inj₁ v')} {assocr₊} p = sym p
pathBInv {v₁ = inj₂ v} {v₂ = inj₂ (inj₁ v')} {assocr₊} ()
pathBInv {v₁ = inj₁ v} {v₂ = inj₂ (inj₂ v')} {assocr₊} ()
pathBInv {v₁ = inj₂ v} {v₂ = inj₂ (inj₂ v')} {assocr₊} p = sym p
pathBInv {v₁ = (tt , v)} {v₂ = v'} {unite⋆} p = sym p
pathBInv {v₁ = v} {v₂ = (tt , v')} {uniti⋆} p = sym p
pathBInv {v₁ = (u , v)} {v₂ = (v' , u')} {swap⋆} (p₁ , p₂) = (sym p₂ , sym p₁)
pathBInv {v₁ = (u , (v , w))} {v₂ = ((u' , v') , w')} {assocl⋆} (p₁ , p₂ , p₃)
= (sym p₁ , sym p₂ , sym p₃)
pathBInv {v₁ = ((u , v) , w)} {v₂ = (u' , (v' , w'))} {assocr⋆} (p₁ , p₂ , p₃)
= (sym p₁ , sym p₂ , sym p₃)
pathBInv {v₁ = _} {v₂ = ()} {distz}
pathBInv {v₁ = ()} {v₂ = _} {factorz}
pathBInv {v₁ = (inj₁ v₁ , v₃)} {v₂ = inj₁ (v₁' , v₃')} {dist} (p₁ , p₂) =
(sym p₁ , sym p₂)
pathBInv {v₁ = (inj₁ v₁ , v₃)} {v₂ = inj₂ (v₂' , v₃')} {dist} ()
pathBInv {v₁ = (inj₂ v₂ , v₃)} {v₂ = inj₁ (v₁' , v₃')} {dist} ()
pathBInv {v₁ = (inj₂ v₂ , v₃)} {v₂ = inj₂ (v₂' , v₃')} {dist} (p₁ , p₂) =
(sym p₁ , sym p₂)
pathBInv {v₁ = inj₁ (v₁ , v₃)} {v₂ = (inj₁ v₁' , v₃')} {factor} (p₁ , p₂) =
(sym p₁ , sym p₂)
pathBInv {v₁ = inj₁ (v₁ , v₃)} {v₂ = (inj₂ v₂' , v₃')} {factor} ()
pathBInv {v₁ = inj₂ (v₂ , v₃)} {v₂ = (inj₁ v₁' , v₃')} {factor} ()
pathBInv {v₁ = inj₂ (v₂ , v₃)} {v₂ = (inj₂ v₂' , v₃')} {factor} (p₁ , p₂) =
(sym p₁ , sym p₂)
pathBInv {v₁ = v} {v₂ = v'} {id⟷} p = sym p
pathBInv {v₁ = v} {v₂ = v'} {sym⟷ c} p = pathInv {v₁ = v'} {v₂ = v} {c} p
pathBInv {t₁} {t₂} {v₁} {v₂} {c₁ ◎ c₂} (u , (p₂ , p₁)) =
(u , (pathBInv {v₁ = v₁} {v₂ = u} {c = c₁} p₁ ,
pathBInv {v₁ = u} {v₂ = v₂} {c = c₂} p₂))
pathBInv {v₁ = inj₁ v} {v₂ = inj₁ v'} {c₁ ⊕ c₂} p = pathBInv {c = c₁} p
pathBInv {v₁ = inj₁ v} {v₂ = inj₂ v'} {c₁ ⊕ c₂} ()
pathBInv {v₁ = inj₂ v} {v₂ = inj₁ v'} {c₁ ⊕ c₂} ()
pathBInv {v₁ = inj₂ v} {v₂ = inj₂ v'} {c₁ ⊕ c₂} p = pathBInv {c = c₂} p
pathBInv {v₁ = (u , v)} {v₂ = (u' , v')} {c₁ ⊗ c₂} (p₁ , p₂) =
(pathBInv {c = c₁} p₁ , pathBInv {c = c₂} p₂)
-- for every paths from v1 to v2 and from v2 to v3, there is a path from v1
-- to v3 that (obviously) goes through v2
pathTrans : {t₁ t₂ t₃ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {v₃ : ⟦ t₃ ⟧}
{c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} →
Paths c₁ v₁ v₂ → Paths c₂ v₂ v₃ → Paths (c₁ ◎ c₂) v₁ v₃
pathTrans {v₂ = v₂} p q = (v₂ , p , q)
pathBTrans : {t₁ t₂ t₃ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {v₃ : ⟦ t₃ ⟧}
{c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} →
PathsB c₁ v₂ v₁ → PathsB c₂ v₃ v₂ → PathsB (c₁ ◎ c₂) v₃ v₁
pathBTrans {v₂ = v₂} p q = (v₂ , q , p)
-- we always have a canonical path from v to v
pathId : {t : U} {v : ⟦ t ⟧} → Paths id⟷ v v
pathId {v = v} = refl v
------------------------------------------------------------------------------
-- Int construction
-- this will allow us to represents paths as values and then define 2paths
-- between them
data DU : Set where
diff : U → U → DU
pos : DU → U
pos (diff t₁ t₂) = t₁
neg : DU → U
neg (diff t₁ t₂) = t₂
zeroD : DU
zeroD = diff ZERO ZERO
oneD : DU
oneD = diff ONE ZERO
plusD : DU → DU → DU
plusD (diff t₁ t₂) (diff t₁' t₂') = diff (PLUS t₁ t₁') (PLUS t₂ t₂')
timesD : DU → DU → DU
timesD (diff t₁ t₂) (diff t₁' t₂') =
diff (PLUS (TIMES t₁ t₁') (TIMES t₂ t₂'))
(PLUS (TIMES t₂ t₁') (TIMES t₁ t₂'))
dualD : DU → DU
dualD (diff t₁ t₂) = diff t₂ t₁
lolliD : DU → DU → DU
lolliD (diff t₁ t₂) (diff t₁' t₂') = diff (PLUS t₂ t₁') (PLUS t₁ t₂')
_≤=>_ : DU → DU → Set
d₁ ≤=> d₂ = PLUS (pos d₁) (neg d₂) ⟷ PLUS (neg d₁) (pos d₂)
idD : {d : DU} → d ≤=> d
idD = swap₊
--curryD : {d₁ d₂ d₃ : DU} → (plusD d₁ d₂ ≤=> d₃) → (d₁ ≤=> lolliD d₂ d₃)
--curryD f = assocl₊ ◎ f ◎ assocr₊
-- take a path and represent it as a value of type lolli and then use
-- ≤=> between these values as the definition of 2paths???
------------------------------------------------------------------------------
-- Can we show:
-- p : Paths c v₁ v₂ == pathTrans p (refl v₂)
-- Groupoid structure (i.e. laws), for 2Paths. Some of the rest of
-- the structure is given above already
-- If the following is right, we can come up with syntax (like _[_]⟺[_]_ ) for p₁ [c₁]⟺[c₂] p₂ . We really do
-- need to index the ⟺ by the combinators 'explicitly' as Agda can never infer them.
data 2P {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧ } : {c₁ c₂ : t₁ ⟷ t₂} → Paths c₁ v₁ v₂ → Paths c₂ v₁ v₂ → Set where
id2 : {c : t₁ ⟷ t₂} {p : Paths c v₁ v₂} → 2P {c₁ = c} {c} p p
inv2 : {c₁ c₂ : t₁ ⟷ t₂} {p₁ : Paths c₁ v₁ v₂} {p₂ : Paths c₂ v₁ v₂} → 2P {c₁ = c₁} {c₂} p₁ p₂ → 2P {c₁ = c₂} {c₁} p₂ p₁
comp2 : {c₁ c₂ c₃ : t₁ ⟷ t₂} {p₁ : Paths c₁ v₁ v₂} {p₂ : Paths c₂ v₁ v₂} {p₃ : Paths c₃ v₁ v₂} →
2P {c₁ = c₁} {c₂} p₁ p₂ → 2P {c₁ = c₂} {c₃} p₂ p₃ → 2P {c₁ = c₁} {c₃} p₁ p₃
-- should define composition which effectively does as below??
lid : {c : t₁ ⟷ t₂} {p : Paths c v₁ v₂} → 2P {c₁ = id⟷ ◎ c} {c} (pathTrans {c₁ = id⟷} {c} pathId p) p
rid : {c : t₁ ⟷ t₂} {p : Paths c v₁ v₂} → 2P {c₁ = c ◎ id⟷} {c} (pathTrans {c₁ = c} {id⟷} p pathId) p
-- also need:
-- assoc
-- linv : {c : t₁ ⟷ t₂} {p : Paths c v₁ v₂} → 2P {c₁ = c}
-- linv
-- rinv
-- and perhaps cong, i.e. ◎-resp-2P
mutual
2Paths : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧ } {c₁ c₂ : t₁ ⟷ t₂} {p₁ : Paths c₁ v₁ v₂} {p₂ : Paths c₂ v₁ v₂} → 2P {c₁ = c₁} {c₂} p₁ p₂ → Paths c₁ v₁ v₂ → Paths c₂ v₁ v₂ → Set
2Paths id2 p₁ p₂ = p₁ ≡ p₂
2Paths (inv2 p) p₁ p₂ = 2PathsB p p₁ p₂
2Paths {t₁} {t₂} {v₁} {v₂} (comp2 {c₁ = c₁} {c₂} {c₃} {p₁} {p₂} {p₃} p q) α₁ α₂ =
Σ[ r ∈ Paths c₂ v₁ v₂ ] (2P {c₁ = c₁} {c₂} α₁ r × 2P {c₁ = c₂} {c₃} r α₂)
2Paths lid (a , refl .a , p₂) p₃ = p₂ ≡ p₃
2Paths rid (a , p₂ , refl .a) p₃ = p₂ ≡ p₃
2PathsB : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧ } {c₁ c₂ : t₁ ⟷ t₂} {p₁ : Paths c₁ v₁ v₂} {p₂ : Paths c₂ v₁ v₂} → 2P {c₁ = c₁} {c₂} p₁ p₂ → Paths c₂ v₁ v₂ → Paths c₁ v₁ v₂ → Set
2PathsB id2 p q = q ≡ p
2PathsB (inv2 p) p₁ p₂ = 2PathsB p p₂ p₁
2PathsB (comp2 p q) p₁ p₂ = {!!}
2PathsB lid p (a , refl .a , p₃) = p ≡ p₃
2PathsB rid p (a , p₂ , refl .a) = p ≡ p₂
example : 2Paths {t₁ = BOOL} {t₂ = BOOL} {v₁ = FALSE} {v₂ = FALSE}
{c₁ = id⟷ ◎ id⟷} {c₂ = id⟷} {p₁ = pathIdIdFF}
lid pathIdIdFF pathIdFF
example = refl (refl FALSE)
{--
2Paths : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {c₁ c₂ : t₁ ⟷ t₂} →
Paths c₁ v₁ v₂ → Paths c₂ v₁ v₂ → Set
2Paths p q = {!!}
reflR : {t₁ t₂ : U} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} {c : t₁ ⟷ t₂}
{p : Paths c v₁ v₂} → {q : Paths (c ◎ id⟷) v₁ v₂} →
2Paths {t₁} {t₂} {v₁} {v₂} {c} {c ◎ id⟷} p q
reflR {c = unite₊} = {!!}
-- p : Paths unite₊ .v₁ .v₂
-- q : Paths (unite₊ ◎ id⟷) .v₁ .v₂
-- 2Paths p q
reflR {c = uniti₊} = {!!}
reflR {c = swap₊} = {!!}
reflR {c = assocl₊} = {!!}
reflR {c = assocr₊} = {!!}
reflR {c = unite⋆} = {!!}
reflR {c = uniti⋆} = {!!}
reflR {c = swap⋆} = {!!}
reflR {c = assocl⋆} = {!!}
reflR {c = assocr⋆} = {!!}
reflR {c = distz} = {!!}
reflR {c = factorz} = {!!}
reflR {c = dist} = {!!}
reflR {c = factor} = {!!}
reflR {c = id⟷} = {!!}
reflR {c = sym⟷ c} = {!!}
reflR {c = c₁ ◎ c₂} = {!!}
reflR {c = c₁ ⊕ c₂} = {!!}
reflR {c = c₁ ⊗ c₂} = {!!}
--}
{--
-- If we have a path between v₁ and v₁' and a combinator that connects v₁ to
-- v₂, then the combinator also connects v₁' to some v₂' such that there is
-- path between v₂ and v₂'
pathFunctor : {t₁ t₂ : U} {v₁ v₁' : ⟦ t₁ ⟧} {v₂ v₂' : ⟦ t₂ ⟧} {c : t₁ ⟷ t₂} →
(v₁ ≡ v₁') → Paths c v₁ v₂ → (v₂ ≡ v₂') → Paths c v₁' v₂'
pathFunctor = {!!}
All kind of structure to investigate in the HoTT book. Let's push forward
with cubical types though...
--}
------------------------------------------------------------------------------
-- N dimensional version
{-
data C : ℕ → Set where
ZD : U → C 0
Node : {n : ℕ} → C n → C n → C (suc n)
⟦_⟧N : {n : ℕ} → C n → Set
⟦ ZD t ⟧N = ⟦ t ⟧
⟦ Node c₁ c₂ ⟧N = ⟦ c₁ ⟧N ⊎ ⟦ c₂ ⟧N
liftN : (n : ℕ) → (t : U) → C n
liftN 0 t = ZD t
liftN (suc n) t = Node (liftN n t) (liftN n ZERO)
zeroN : (n : ℕ) → C n
zeroN n = liftN n ZERO
oneN : (n : ℕ) → C n
oneN n = liftN n ONE
plus : {n : ℕ} → C n → C n → C n
plus (ZD t₁) (ZD t₂) = ZD (PLUS t₁ t₂)
plus (Node c₁ c₂) (Node c₁' c₂') = Node (plus c₁ c₁') (plus c₂ c₂')
times : {m n : ℕ} → C m → C n → C (m + n)
times (ZD t₁) (ZD t₂) = ZD (TIMES t₁ t₂)
times (ZD t) (Node c₁ c₂) = Node (times (ZD t) c₁) (times (ZD t) c₂)
times (Node c₁ c₂) c = Node (times c₁ c) (times c₂ c)
-- N-dimensional paths connect points in c₁ and c₂ if there is an isomorphism
-- between the types c₁ and c₂.
data _⟺_ : {n : ℕ} → C n → C n → Set where
baseC : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ((ZD t₁) ⟺ (ZD t₂))
nodeC : {n : ℕ} {c₁ : C n} {c₂ : C n} {c₃ : C n} {c₄ : C n} →
(c₁ ⟺ c₂) → (c₃ ⟺ c₄) → ((Node c₁ c₃) ⟺ (Node c₂ c₄))
-- zerolC : {n : ℕ} {c : C n} → ((Node c c) ⟺ (zeroN (suc n)))
-- zerorC : {n : ℕ} {c : C n} → ((zeroN (suc n)) ⟺ (Node c c))
NPaths : {n : ℕ} {c₁ c₂ : C n} → (c₁ ⟺ c₂) → ⟦ c₁ ⟧N → ⟦ c₂ ⟧N → Set
NPaths (baseC c) v₁ v₂ = Paths c v₁ v₂
NPaths (nodeC α₁ α₂) (inj₁ v₁) (inj₁ v₂) = NPaths α₁ v₁ v₂
NPaths (nodeC α₁ α₂) (inj₁ v₁) (inj₂ v₂) = ⊥
NPaths (nodeC α₁ α₂) (inj₂ v₁) (inj₁ v₂) = ⊥
NPaths (nodeC α₁ α₂) (inj₂ v₁) (inj₂ v₂) = NPaths α₂ v₁ v₂
--NPaths zerolC v₁ v₂ = {!!}
--NPaths zerorC v₁ v₂ = {!!}
-}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.500976856,
"avg_line_length": 39.1988217968,
"ext": "agda",
"hexsha": "d462dd917d789e7dede53c69780b58e2ad900404",
"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/A.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/A.agda",
"max_line_length": 180,
"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/A.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": 12910,
"size": 26616
} |
-- 2015-02-24 Andrea Vezzosi
-- Since type constructors are considered injective by the forcing analysis we are able to define the type for the "russel" paradox:
open import Common.Product
Type = Set₁
data Box : Type -> Set where
-- The following type should be rejected, as A is not forced.
data Tree' : Set -> Type where
sup' : ∀ (A : Type) -> (A → ∃ Tree') → Tree' (Box A)
Tree = ∃ Tree'
sup : (a : Type) -> (f : a -> Tree) -> Tree
sup a f = _ , sup' a f
a : Tree -> Type
a (._ , sup' a _) = a
f : (t : Tree) -> a t -> Tree
f (._ , sup' a f) = f
-- The rest is the standard paradox
open import Common.Equality
open import Common.Prelude
normal : Tree -> Type
normal t = Σ (a t) (λ (y : a t) → (f t y ≡ sup (a t) (f t))) -> ⊥
nt : Type
nt = Σ Tree \ (t : Tree) -> normal t
p : nt -> Tree
p (x , _) = x
q : (y : nt) -> normal (p y)
q (x , y) = y
r : Tree
r = sup nt p
lemma : normal r
lemma ((y1 , y2) , z) = y2 (subst (\ y3 -> Σ _ \ (y : a y3) -> f y3 y ≡ sup (a y3) (f y3)) (sym z) ((y1 , y2) , z))
russel : ⊥
russel = lemma ((r , lemma) , refl)
| {
"alphanum_fraction": 0.5602240896,
"avg_line_length": 20.5961538462,
"ext": "agda",
"hexsha": "9638fa762b2e9faa70e45cda9e64b2588954abc6",
"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/Issue1441.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/Issue1441.agda",
"max_line_length": 132,
"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/Issue1441.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": 402,
"size": 1071
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of These
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.These.Properties where
open import Data.These
open import Function using (_∘_)
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (yes; no)
------------------------------------------------------------------------
-- Equality
module _ {a b} {A : Set a} {B : Set b} where
this-injective : ∀ {x y : A} → this {B = B} x ≡ this y → x ≡ y
this-injective refl = refl
that-injective : ∀ {a b : B} → that {A = A} a ≡ that b → a ≡ b
that-injective refl = refl
these-injectiveˡ : ∀ {x y : A} {a b : B} → these x a ≡ these y b → x ≡ y
these-injectiveˡ refl = refl
these-injectiveʳ : ∀ {x y : A} {a b : B} → these x a ≡ these y b → a ≡ b
these-injectiveʳ refl = refl
≡-dec : Decidable _≡_ → Decidable _≡_ → Decidable {A = These A B} _≡_
≡-dec dec₁ dec₂ (this x) (this y) with dec₁ x y
... | yes refl = yes refl
... | no x≢y = no (x≢y ∘ this-injective)
≡-dec dec₁ dec₂ (this x) (that y) = no λ()
≡-dec dec₁ dec₂ (this x) (these y b) = no λ()
≡-dec dec₁ dec₂ (that x) (this y) = no λ()
≡-dec dec₁ dec₂ (that x) (that y) with dec₂ x y
... | yes refl = yes refl
... | no x≢y = no (x≢y ∘ that-injective)
≡-dec dec₁ dec₂ (that x) (these y b) = no λ()
≡-dec dec₁ dec₂ (these x a) (this y) = no λ()
≡-dec dec₁ dec₂ (these x a) (that y) = no λ()
≡-dec dec₁ dec₂ (these x a) (these y b) with dec₁ x y | dec₂ a b
... | yes refl | yes refl = yes refl
... | no x≢y | _ = no (x≢y ∘ these-injectiveˡ)
... | yes _ | no a≢b = no (a≢b ∘ these-injectiveʳ)
| {
"alphanum_fraction": 0.5064308682,
"avg_line_length": 36.5882352941,
"ext": "agda",
"hexsha": "6891135eceaf6e3f9dc3cdcd7407673eeadba247",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/These/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/These/Properties.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/These/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 650,
"size": 1866
} |
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Smap
open import Oscar.Data.Fin
open import Oscar.Data.Term
open import Oscar.Data.Vec
import Oscar.Class.Surjection.⋆
module Oscar.Class.Smap.ExtensionFinExtensionTerm where
module _ {𝔭} {𝔓 : Ø 𝔭} where
open Term 𝔓
private
mutual
𝓼urjectivityExtensionFinExtensionTerm : Smap!.type (Extension Fin) (Extension Term)
𝓼urjectivityExtensionFinExtensionTerm x (i y) = i (x y)
𝓼urjectivityExtensionFinExtensionTerm x leaf = leaf
𝓼urjectivityExtensionFinExtensionTerm x (l fork r) = 𝓼urjectivityExtensionFinExtensionTerm x l fork 𝓼urjectivityExtensionFinExtensionTerm x r
𝓼urjectivityExtensionFinExtensionTerm x (function f ts) = function f $ 𝓼urjectivityExtensionFinExtensionTerms x ts
𝓼urjectivityExtensionFinExtensionTerms : ∀ {N} → Smap!.type (Extension Fin) (Extension $ Terms N)
𝓼urjectivityExtensionFinExtensionTerms x ∅ = ∅
𝓼urjectivityExtensionFinExtensionTerms x (t , ts) = 𝓼urjectivityExtensionFinExtensionTerm x t , 𝓼urjectivityExtensionFinExtensionTerms x ts
instance
𝓢urjectivityExtensionFinExtensionTerm : Smap!.class (Extension Fin) (Extension Term)
𝓢urjectivityExtensionFinExtensionTerm .⋆ _ _ = 𝓼urjectivityExtensionFinExtensionTerm
𝓢urjectivityExtensionFinExtensionTerms : ∀ {N} → Smap!.class (Extension Fin) (Extension $ Terms N)
𝓢urjectivityExtensionFinExtensionTerms .⋆ _ _ = 𝓼urjectivityExtensionFinExtensionTerms
| {
"alphanum_fraction": 0.7884486232,
"avg_line_length": 40.2432432432,
"ext": "agda",
"hexsha": "97c5cdc3ad6262b8a8b7898c7b9339b98c35bd36",
"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/Smap/ExtensionFinExtensionTerm.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/Smap/ExtensionFinExtensionTerm.agda",
"max_line_length": 147,
"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/Smap/ExtensionFinExtensionTerm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 442,
"size": 1489
} |
{-# OPTIONS --without-K #-}
open import Types
open import Paths
{- Stuff about truncation levels (aka h-levers) that do not require the notion
of equivalence or function extensionality -}
module HLevel {i} where
-- Definition of truncation levels
is-contr : Set i → Set i
is-contr A = Σ A (λ x → ((y : A) → y ≡ x))
is-truncated : ℕ₋₂ → (Set i → Set i)
is-truncated ⟨-2⟩ A = is-contr A
is-truncated (S n) A = (x y : A) → is-truncated n (x ≡ y)
is-prop = is-truncated ⟨-1⟩
is-set = is-truncated ⟨0⟩
is-gpd = is-truncated ⟨1⟩
-- The original notion of h-level can be defined in the following way.
-- We won’t use this definition though.
is-hlevel : ℕ → (Set i → Set i)
is-hlevel n A = is-truncated (n -2) A where
_-2 : ℕ → ℕ₋₂
O -2 = ⟨-2⟩
(S n) -2 = S (n -2)
-- The following property is equivalent to being a proposition
has-all-paths : Set i → Set i
has-all-paths A = (x y : A) → x ≡ y
-- Having decidable equality is stronger that being a set
has-dec-eq : Set i → Set i
has-dec-eq A = (x y : A) → (x ≡ y) ⊔ (x ≢ y)
abstract
all-paths-is-prop : {A : Set i} → (has-all-paths A → is-prop A)
all-paths-is-prop {A} c x y = (c x y , canon-path) where
lemma : {x y : A} (p : x ≡ y) → c x y ≡ p ∘ c y y
lemma refl = refl
canon-path : {x y : A} (p : x ≡ y) → p ≡ c x y
canon-path {.y} {y} refl = anti-whisker-right (c y y) (lemma (c y y))
-- Truncation levels are cumulative
truncated-is-truncated-S : {A : Set i} (n : ℕ₋₂)
→ (is-truncated n A → is-truncated (S n) A)
truncated-is-truncated-S ⟨-2⟩ q =
all-paths-is-prop (λ x y → π₂ q x ∘ ! (π₂ q y))
truncated-is-truncated-S (S n) q =
λ x y → truncated-is-truncated-S n (q x y)
-- A type with a decidable equality is a set
dec-eq-is-set : {A : Set i} → (has-dec-eq A → is-set A)
dec-eq-is-set dec x y with dec x y
dec-eq-is-set dec x y | inr p⊥ = λ p → abort-nondep (p⊥ p)
dec-eq-is-set {A} dec x y | inl q = paths-A-is-prop q where
-- The fact that equality is decidable on A gives a canonical path parallel
-- to every path [p], depending only on the endpoints
get-path : {u v : A} (r : u ≡ v) → u ≡ v
get-path {u} {v} r with dec u v
get-path r | inl q = q
get-path r | inr r⊥ = abort-nondep (r⊥ r)
get-path-eq : {u : A} (r : u ≡ u) → get-path r ≡ get-path refl
get-path-eq {u} r with dec u u
get-path-eq r | inl q = refl
get-path-eq r | inr r⊥ = abort-nondep (r⊥ refl)
lemma : {u v : A} (r : u ≡ v) → r ∘ get-path refl ≡ get-path r
lemma refl = refl
paths-A-is-prop : {u v : A} (q : u ≡ v) → is-prop (u ≡ v)
paths-A-is-prop {u} {.u} refl =
truncated-is-truncated-S ⟨-2⟩
(refl , λ r → anti-whisker-right (get-path refl)
(lemma r ∘ get-path-eq r))
module _ {A : Set i} where
abstract
contr-has-all-paths : is-contr A → has-all-paths A
contr-has-all-paths c x y = π₂ c x ∘ ! (π₂ c y)
prop-has-all-paths : is-prop A → has-all-paths A
prop-has-all-paths c x y = π₁ (c x y)
inhab-prop-is-contr : A → is-prop A → is-contr A
inhab-prop-is-contr x₀ p = (x₀ , λ y → π₁ (p y x₀))
contr-is-truncated : (n : ℕ₋₂) → (is-contr A → is-truncated n A)
contr-is-truncated ⟨-2⟩ p = p
contr-is-truncated (S n) p =
truncated-is-truncated-S n (contr-is-truncated n p)
prop-is-truncated-S : (n : ℕ₋₂) → (is-prop A → is-truncated (S n) A)
prop-is-truncated-S ⟨-2⟩ p = p
prop-is-truncated-S (S n) p =
truncated-is-truncated-S (S n) (prop-is-truncated-S n p)
set-is-truncated-SS : (n : ℕ₋₂) → (is-set A → is-truncated (S (S n)) A)
set-is-truncated-SS ⟨-2⟩ p = p
set-is-truncated-SS (S n) p = truncated-is-truncated-S (S (S n))
(set-is-truncated-SS n p)
contr-is-prop : is-contr A → is-prop A
contr-is-prop = contr-is-truncated ⟨-1⟩
contr-is-set : is-contr A → is-set A
contr-is-set = contr-is-truncated ⟨0⟩
contr-is-gpd : is-contr A → is-gpd A
contr-is-gpd = contr-is-truncated ⟨1⟩
prop-is-set : is-prop A → is-set A
prop-is-set = prop-is-truncated-S ⟨-1⟩
prop-is-gpd : is-prop A → is-gpd A
prop-is-gpd = prop-is-truncated-S ⟨0⟩
set-is-gpd : is-set A → is-gpd A
set-is-gpd = set-is-truncated-SS ⟨-1⟩
-- If [A] is n-truncated, then so does [x ≡ y] for [x y : A]
≡-is-truncated : (n : ℕ₋₂) {x y : A}
→ (is-truncated n A → is-truncated n (x ≡ y))
≡-is-truncated ⟨-2⟩ p = (contr-has-all-paths p _ _ , unique-path) where
unique-path : {u v : A} (q : u ≡ v)
→ q ≡ contr-has-all-paths p u v
unique-path refl = ! (opposite-right-inverse (π₂ p _))
≡-is-truncated (S n) {x} {y} p = truncated-is-truncated-S n (p x y)
-- The type of paths to a fixed point is contractible
pathto-is-contr : (x : A) → is-contr (Σ A (λ t → t ≡ x))
pathto-is-contr x = ((x , refl) , pathto-unique-path) where
pathto-unique-path : {u : A} (pp : Σ A (λ t → t ≡ u)) → pp ≡ (u , refl)
pathto-unique-path (u , refl) = refl
-- Specilization
module _ where
≡-is-set : {x y : A} → (is-set A → is-set (x ≡ y))
≡-is-set = ≡-is-truncated ⟨0⟩
≡-is-prop : {x y : A} → (is-prop A → is-prop (x ≡ y))
≡-is-prop = ≡-is-truncated ⟨-1⟩
abstract
-- Unit is contractible
-- I do not need to specify the universe level because in this file [is-contr]
-- is not yet universe polymorphic ([i] is a global argument)
unit-is-contr : is-contr unit
unit-is-contr = (tt , λ y → refl)
unit-is-truncated : (n : ℕ₋₂) → is-truncated n unit
unit-is-truncated n = contr-is-truncated n unit-is-contr
-- [unit-is-truncated#instance] produces unsolved metas
unit-is-truncated-S#instance : {n : ℕ₋₂} → is-truncated (S n) unit
unit-is-truncated-S#instance = contr-is-truncated _ unit-is-contr
unit-is-prop : is-prop unit
unit-is-prop = unit-is-truncated ⟨-1⟩
unit-is-set : is-set unit
unit-is-set = unit-is-truncated ⟨0⟩
contr-has-section : ∀ {j} {A : Set i} {P : A → Set j}
→ (is-contr A → (x : A) → (u : P x) → Π A P)
contr-has-section (x , p) x₀ y₀ t = transport _ (p x₀ ∘ ! (p t)) y₀
private
bool-true≢false-type : bool {i} → Set
bool-true≢false-type true = ⊤
bool-true≢false-type false = ⊥
abstract
bool-true≢false : true {i} ≢ false
bool-true≢false p = transport bool-true≢false-type p tt
bool-false≢true : false {i} ≢ true
bool-false≢true p = transport bool-true≢false-type (! p) tt
bool-has-dec-eq : has-dec-eq bool
bool-has-dec-eq true true = inl refl
bool-has-dec-eq true false = inr bool-true≢false
bool-has-dec-eq false true = inr bool-false≢true
bool-has-dec-eq false false = inl refl
bool-is-set : is-set bool
bool-is-set = dec-eq-is-set bool-has-dec-eq
⊥-is-prop : is-prop ⊥
⊥-is-prop ()
| {
"alphanum_fraction": 0.5849056604,
"avg_line_length": 34.2626262626,
"ext": "agda",
"hexsha": "a9cd5e541ac5892071add6f634dc3bf4548031cc",
"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/HLevel.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/HLevel.agda",
"max_line_length": 80,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/HLevel.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": 2490,
"size": 6784
} |
module Haskell.Prim.String where
open import Agda.Builtin.Char
open import Agda.Builtin.Unit
open import Agda.Builtin.FromString
import Agda.Builtin.String as Str
open import Haskell.Prim
open import Haskell.Prim.List
open import Haskell.Prim.Foldable
--------------------------------------------------
-- String
String = List Char
instance
iIsStringString : IsString String
iIsStringString .IsString.Constraint _ = ⊤
iIsStringString .fromString s = Str.primStringToList s
private
cons : Char → List String → List String
cons c [] = (c ∷ []) ∷ []
cons c (s ∷ ss) = (c ∷ s) ∷ ss
lines : String → List String
lines [] = []
lines ('\n' ∷ s) = [] ∷ lines s
lines (c ∷ s) = cons c (lines s)
private
mutual
space : String → List String
space [] = []
space (c ∷ s) = if primIsSpace c then space s else cons c (word s)
word : String → List String
word [] = []
word (c ∷ s) = if primIsSpace c then [] ∷ space s else cons c (word s)
words : String → List String
words [] = []
words s@(c ∷ s₁) = if primIsSpace c then space s₁ else word s
unlines : List String → String
unlines = concatMap (_++ "\n")
unwords : List String → String
unwords [] = ""
unwords (w ∷ []) = w
unwords (w ∷ ws) = w ++ ' ' ∷ unwords ws
| {
"alphanum_fraction": 0.619047619,
"avg_line_length": 23.3333333333,
"ext": "agda",
"hexsha": "01f77489170240d2de25933a835720ecafda295a",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/String.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/String.agda",
"max_line_length": 72,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/String.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 383,
"size": 1260
} |
------------------------------------------------------------------------------
-- The McCarthy 91 function: A function with nested recursion
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.McCarthy91.McCarthy91 where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
-- The McCarthy 91 function.
postulate
f₉₁ : D → D
f₉₁-eq : ∀ n → f₉₁ n ≡ (if (gt n 100') then n ∸ 10' else f₉₁ (f₉₁ (n + 11')))
{-# ATP axiom f₉₁-eq #-}
| {
"alphanum_fraction": 0.4469135802,
"avg_line_length": 35.2173913043,
"ext": "agda",
"hexsha": "c564596242d842d15369c28dce25537436de0398",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/McCarthy91/McCarthy91.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/McCarthy91/McCarthy91.agda",
"max_line_length": 79,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/McCarthy91/McCarthy91.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": 186,
"size": 810
} |
-- Sample non-literate Agda program
-- ================================
--
-- A remark to test bulleted lists:
--
-- * This file serves as example for agda2lagda.
--
-- * The content may be non-sensical.
--
-- Indeed!
module Foo where
-- Some data type.
data D : Set where
c : D
-- A function.
foo : D → D
foo c = c -- basically, the identity
{- This part is commented out.
{-
bar : D → Set
bar x = D
-- -}
-- -}
-- A subheading
---------------
module Submodule where
postulate
zeta : D
-- That's it.
-- Bye.
| {
"alphanum_fraction": 0.5511363636,
"avg_line_length": 13.2,
"ext": "agda",
"hexsha": "4a6bbdb7e83937510c75ae59b7e601883c14021a",
"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": "93d317c87bddf973e3fa6abd5bf24dcfa9a797f0",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "andreasabel/agda2lagda",
"max_forks_repo_path": "test/Foo.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "93d317c87bddf973e3fa6abd5bf24dcfa9a797f0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "andreasabel/agda2lagda",
"max_issues_repo_path": "test/Foo.agda",
"max_line_length": 48,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "93d317c87bddf973e3fa6abd5bf24dcfa9a797f0",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "andreasabel/agda2lagda",
"max_stars_repo_path": "test/Foo.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-16T07:28:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-01T12:10:15.000Z",
"num_tokens": 150,
"size": 528
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Sparse polynomials in a commutative ring, encoded in Horner normal
-- form.
--
-- Horner normal form encodes a polynomial as a list of coefficients.
-- As an example take the polynomial:
--
-- 3 + 2x² + 4x⁵ + 2x⁷
--
-- Then expand it out, filling in the missing coefficients:
--
-- 3x⁰ + 0x¹ + 2x² + 0x³ + 0x⁴ + 4x⁵ + 0x⁶ + 2x⁷
--
-- And then encode that as a list:
--
-- [3, 0, 2, 0, 0, 4, 0, 2]
--
-- The representation we use here is optimised from the above. First,
-- we remove the zero terms, and add a "gap" index next to every
-- coefficient:
--
-- [(3,0),(2,1),(4,2),(2,1)]
--
-- Which can be thought of as a representation of the expression:
--
-- x⁰ * (3 + x * x¹ * (2 + x * x² * (4 + x * x¹ * (2 + x * 0))))
--
-- This is "sparse" Horner normal form.
--
-- The second optimisation deals with representing multiple variables
-- in a polynomial. The standard trick is to encode a polynomial in n
-- variables as a polynomial with coefficients in n-1 variables,
-- recursing until you hit 0 which is simply the type of the coefficient
-- itself.
--
-- We again encode "gaps" here, with the injection index. Since the
-- number of variables in a polynomial is contained in its type,
-- however, operations on this gap are type-relevant, so it's not
-- convenient to simply use ℕ. We use _≤′_ instead.
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
open import Tactic.RingSolver.Core.Polynomial.Parameters
module Tactic.RingSolver.Core.Polynomial.Base
{ℓ₁ ℓ₂} (coeffs : RawCoeff ℓ₁ ℓ₂) where
open RawCoeff coeffs
open import Data.Bool using (Bool; true; false; T)
open import Data.Empty using (⊥)
open import Data.Fin.Base as Fin using (Fin; zero; suc)
open import Data.List.Kleene
open import Data.Nat.Base as ℕ using (ℕ; suc; zero; _≤′_; compare; ≤′-refl; ≤′-step; _<′_)
open import Data.Nat.Properties using (z≤′n; ≤′-trans)
open import Data.Nat.Induction
open import Data.Product using (_×_; _,_; map₁; curry; uncurry)
open import Data.Unit using (⊤; tt)
open import Function.Base
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Algebra.Operations.Ring rawRing
------------------------------------------------------------------------
-- Injection indices.
------------------------------------------------------------------------
-- First, we define comparisons on _≤′_.
-- The following is analagous to Ordering and compare from
-- Data.Nat.Base.
data InjectionOrdering {n : ℕ} : ∀ {i j} (i≤n : i ≤′ n) (j≤n : j ≤′ n) → Set
where
inj-lt : ∀ {i j-1} (i≤j-1 : i ≤′ j-1) (j≤n : suc j-1 ≤′ n) →
InjectionOrdering (≤′-step i≤j-1 ⟨ ≤′-trans ⟩ j≤n) j≤n
inj-gt : ∀ {i-1 j} (i≤n : suc i-1 ≤′ n) (j≤i-1 : j ≤′ i-1) →
InjectionOrdering i≤n (≤′-step j≤i-1 ⟨ ≤′-trans ⟩ i≤n)
inj-eq : ∀ {i} (i≤n : i ≤′ n) →
InjectionOrdering i≤n i≤n
inj-compare : ∀ {i j n} (x : i ≤′ n) (y : j ≤′ n) → InjectionOrdering x y
inj-compare ≤′-refl ≤′-refl = inj-eq ≤′-refl
inj-compare ≤′-refl (≤′-step y) = inj-gt ≤′-refl y
inj-compare (≤′-step x) ≤′-refl = inj-lt x ≤′-refl
inj-compare (≤′-step x) (≤′-step y) = case inj-compare x y of
λ { (inj-lt i≤j-1 y) → inj-lt i≤j-1 (≤′-step y)
; (inj-gt x j≤i-1) → inj-gt (≤′-step x) j≤i-1
; (inj-eq x) → inj-eq (≤′-step x)
}
-- The "space" above a Fin n is the number of unique "Fin n"s greater
-- than or equal to it.
space : ∀ {n} → Fin n → ℕ
space f = suc (go f)
where
go : ∀ {n} → Fin n → ℕ
go {suc n} Fin.zero = n
go (Fin.suc x) = go x
space≤′n : ∀ {n} (x : Fin n) → space x ≤′ n
space≤′n zero = ≤′-refl
space≤′n (suc x) = ≤′-step (space≤′n x)
-------------------------------------------------------------------------
-- Definition
-------------------------------------------------------------------------
infixl 6 _Δ_
record PowInd {c} (C : Set c) : Set c where
constructor _Δ_
field
coeff : C
pow : ℕ
open PowInd public
record Poly (n : ℕ) : Set ℓ₁
data FlatPoly : ℕ → Set ℓ₁
Coeff : ℕ → Set ℓ₁
record NonZero (i : ℕ) : Set ℓ₁
Zero : ∀ {n} → Poly n → Set
Normalised : ∀ {i} → Coeff i + → Set
-- A Polynomial is indexed by the number of variables it contains.
infixl 6 _⊐_
record Poly n where
inductive
constructor _⊐_
field
{i} : ℕ
flat : FlatPoly i
i≤n : i ≤′ n
data FlatPoly where
Κ : Carrier → FlatPoly zero
⅀ : ∀ {n} (xs : Coeff n +) {xn : Normalised xs} → FlatPoly (suc n)
Coeff n = PowInd (NonZero n)
-- We disallow zeroes in the coefficient list. This condition alone
-- is enough to ensure a unique representation for any polynomial.
infixl 6 _≠0
record NonZero i where
inductive
constructor _≠0
field
poly : Poly i
.{poly≠0} : ¬ Zero poly
-- This predicate is used (in its negation) to ensure that no
-- coefficient is zero, preventing any trailing zeroes.
Zero (Κ x ⊐ _) = T (isZero x)
Zero (⅀ _ ⊐ _) = ⊥
-- This predicate is used to ensure that all polynomials are in
-- normal form: if a particular level is constant, then it can
-- be collapsed into the level below it.
Normalised (_ Δ zero & []) = ⊥
Normalised (_ Δ zero & ∹ _) = ⊤
Normalised (_ Δ suc _ & _) = ⊤
open NonZero public
open Poly public
----------------------------------------------------------------------
-- Special operations
-- Decision procedure for Zero
zero? : ∀ {n} → (p : Poly n) → Dec (Zero p)
zero? (⅀ _ ⊐ _) = no id
zero? (Κ x ⊐ _) with isZero x
... | true = yes tt
... | false = no id
{-# INLINE zero? #-}
-- Exponentiate the first variable of a polynomial
infixr 8 _⍓*_ _⍓+_
_⍓*_ : ∀ {n} → Coeff n * → ℕ → Coeff n *
_⍓+_ : ∀ {n} → Coeff n + → ℕ → Coeff n +
[] ⍓* _ = []
(∹ xs) ⍓* i = ∹ xs ⍓+ i
coeff (head (xs ⍓+ i)) = coeff (head xs)
pow (head (xs ⍓+ i)) = pow (head xs) ℕ.+ i
tail (xs ⍓+ i) = tail xs
infixr 5 _∷↓_
_∷↓_ : ∀ {n} → PowInd (Poly n) → Coeff n * → Coeff n *
x Δ i ∷↓ xs = case zero? x of
λ { (yes p) → xs ⍓* suc i
; (no ¬p) → ∹ _≠0 x {¬p} Δ i & xs
}
{-# INLINE _∷↓_ #-}
-- Inject a polynomial into a larger polynomial with more variables
_⊐↑_ : ∀ {n m} → Poly n → (suc n ≤′ m) → Poly m
(xs ⊐ i≤n) ⊐↑ n≤m = xs ⊐ (≤′-step i≤n ⟨ ≤′-trans ⟩ n≤m)
{-# INLINE _⊐↑_ #-}
infixr 4 _⊐↓_
_⊐↓_ : ∀ {i n} → Coeff i * → suc i ≤′ n → Poly n
[] ⊐↓ i≤n = Κ 0# ⊐ z≤′n
(∹ (x ≠0 Δ zero & [] )) ⊐↓ i≤n = x ⊐↑ i≤n
(∹ (x Δ zero & ∹ xs)) ⊐↓ i≤n = ⅀ (x Δ zero & ∹ xs) ⊐ i≤n
(∹ (x Δ suc j & xs )) ⊐↓ i≤n = ⅀ (x Δ suc j & xs) ⊐ i≤n
{-# INLINE _⊐↓_ #-}
----------------------------------------------------------------------
-- Standard operations
----------------------------------------------------------------------
----------------------------------------------------------------------
-- Folds
-- These folds allow us to abstract over the proofs later: we try to avoid
-- using ∷↓ and ⊐↓ directly anywhere except here, so if we prove that this fold
-- acts the same on a normalised or non-normalised polynomial, we can prove th
-- same about any operation which uses it.
PolyF : ℕ → Set ℓ₁
PolyF i = Poly i × Coeff i *
Fold : ℕ → Set ℓ₁
Fold i = PolyF i → PolyF i
para : ∀ {i} → Fold i → Coeff i + → Coeff i *
para f (x ≠0 Δ i & []) = case f (x , []) of λ {(y , ys) → y Δ i ∷↓ ys}
para f (x ≠0 Δ i & ∹ xs) = case f (x , para f xs) of λ {(y , ys) → y Δ i ∷↓ ys}
poly-map : ∀ {i} → (Poly i → Poly i) → Coeff i + → Coeff i *
poly-map f = para (map₁ f)
{-# INLINE poly-map #-}
----------------------------------------------------------------------
-- Addition
-- The reason the following code is so verbose is termination
-- checking. For instance, in the third case for ⊞-coeffs, we call a
-- helper function. Instead, you could conceivably use a with-block
-- (on ℕ.compare p q):
--
-- ⊞-coeffs ((x , p) ∷ xs) ((y , q) ∷ ys) with (ℕ.compare p q)
-- ... | ℕ.less p k = (x , p) ∷ ⊞-coeffs xs ((y , k) ∷ ys)
-- ... | ℕ.equal p = (fst~ x ⊞ fst~ y , p) ∷↓ ⊞-coeffs xs ys
-- ... | ℕ.greater q k = (y , q) ∷ ⊞-coeffs ((x , k) ∷ xs) ys
--
-- However, because the first and third recursive calls each rewrap
-- a list that was already pattern-matched on, the recursive call
-- does not strictly decrease the size of its argument.
--
-- Interestingly, if --without-K is turned off, we don't need the
-- helper function ⊞-coeffs; we could pattern match on _⊞_ directly.
--
-- _⊞_ {zero} (lift x) (lift y) = lift (x + y)
-- _⊞_ {suc n} [] ys = ys
-- _⊞_ {suc n} (x ∷ xs) [] = x ∷ xs
-- _⊞_ {suc n} ((x , p) ∷ xs) ((y , q) ∷ ys) = ⊞-zip (ℕ.compare p q) x xs y ys
mutual
infixl 6 _⊞_
_⊞_ : ∀ {n} → Poly n → Poly n → Poly n
(xs ⊐ i≤n) ⊞ (ys ⊐ j≤n) = ⊞-match (inj-compare i≤n j≤n) xs ys
⊞-match : ∀ {i j n}
→ {i≤n : i ≤′ n}
→ {j≤n : j ≤′ n}
→ InjectionOrdering i≤n j≤n
→ FlatPoly i
→ FlatPoly j
→ Poly n
⊞-match (inj-eq i&j≤n) (Κ x) (Κ y) = Κ (x + y) ⊐ i&j≤n
⊞-match (inj-eq i&j≤n) (⅀ (x Δ i & xs)) (⅀ (y Δ j & ys)) = ⊞-zip (compare i j) x xs y ys ⊐↓ i&j≤n
⊞-match (inj-lt i≤j-1 j≤n) xs (⅀ ys) = ⊞-inj i≤j-1 xs ys ⊐↓ j≤n
⊞-match (inj-gt i≤n j≤i-1) (⅀ xs) ys = ⊞-inj j≤i-1 ys xs ⊐↓ i≤n
⊞-inj : ∀ {i k}
→ (i ≤′ k)
→ FlatPoly i
→ Coeff k +
→ Coeff k *
⊞-inj i≤k xs (y ⊐ j≤k ≠0 Δ zero & ys) = ⊞-match (inj-compare j≤k i≤k) y xs Δ zero ∷↓ ys
⊞-inj i≤k xs (y Δ suc j & ys) = xs ⊐ i≤k Δ zero ∷↓ ∹ y Δ j & ys
⊞-coeffs : ∀ {n} → Coeff n * → Coeff n * → Coeff n *
⊞-coeffs (∹ x Δ i & xs) ys = ⊞-zip-r x i xs ys
⊞-coeffs [] ys = ys
⊞-zip : ∀ {p q n}
→ ℕ.Ordering p q
→ NonZero n
→ Coeff n *
→ NonZero n
→ Coeff n *
→ Coeff n *
⊞-zip (ℕ.less i k) x xs y ys = ∹ x Δ i & ⊞-zip-r y k ys xs
⊞-zip (ℕ.greater j k) x xs y ys = ∹ y Δ j & ⊞-zip-r x k xs ys
⊞-zip (ℕ.equal i ) x xs y ys = (x .poly ⊞ y .poly) Δ i ∷↓ ⊞-coeffs xs ys
{-# INLINE ⊞-zip #-}
⊞-zip-r : ∀ {n} → NonZero n → ℕ → Coeff n * → Coeff n * → Coeff n *
⊞-zip-r x i xs [] = ∹ x Δ i & xs
⊞-zip-r x i xs (∹ y Δ j & ys) = ⊞-zip (compare i j) x xs y ys
----------------------------------------------------------------------
-- Negation
-- recurse on acc directly
-- https://github.com/agda/agda/issues/3190#issuecomment-416900716
⊟-step : ∀ {n} → Acc _<′_ n → Poly n → Poly n
⊟-step (acc wf) (Κ x ⊐ i≤n) = Κ (- x) ⊐ i≤n
⊟-step (acc wf) (⅀ xs ⊐ i≤n) = poly-map (⊟-step (wf _ i≤n)) xs ⊐↓ i≤n
⊟_ : ∀ {n} → Poly n → Poly n
⊟_ = ⊟-step (<′-wellFounded _)
{-# INLINE ⊟_ #-}
----------------------------------------------------------------------
-- Multiplication
mutual
⊠-step′ : ∀ {n} → Acc _<′_ n → Poly n → Poly n → Poly n
⊠-step′ a (x ⊐ i≤n) = ⊠-step a x i≤n
⊠-step : ∀ {i n} → Acc _<′_ n → FlatPoly i → i ≤′ n → Poly n → Poly n
⊠-step a (Κ x) _ = ⊠-Κ a x
⊠-step a (⅀ xs) = ⊠-⅀ a xs
⊠-Κ : ∀ {n} → Acc _<′_ n → Carrier → Poly n → Poly n
⊠-Κ (acc _ ) x (Κ y ⊐ i≤n) = Κ (x * y) ⊐ i≤n
⊠-Κ (acc wf) x (⅀ xs ⊐ i≤n) = ⊠-Κ-inj (wf _ i≤n) x xs ⊐↓ i≤n
{-# INLINE ⊠-Κ #-}
⊠-⅀ : ∀ {i n} → Acc _<′_ n → Coeff i + → i <′ n → Poly n → Poly n
⊠-⅀ (acc wf) xs i≤n (⅀ ys ⊐ j≤n) = ⊠-match (acc wf) (inj-compare i≤n j≤n) xs ys
⊠-⅀ (acc wf) xs i≤n (Κ y ⊐ _) = ⊠-Κ-inj (wf _ i≤n) y xs ⊐↓ i≤n
⊠-Κ-inj : ∀ {i} → Acc _<′_ i → Carrier → Coeff i + → Coeff i *
⊠-Κ-inj a x xs = poly-map (⊠-Κ a x) (xs)
⊠-⅀-inj : ∀ {i k}
→ Acc _<′_ k
→ i <′ k
→ Coeff i +
→ Poly k
→ Poly k
⊠-⅀-inj (acc wf) i≤k x (⅀ y ⊐ j≤k) = ⊠-match (acc wf) (inj-compare i≤k j≤k) x y
⊠-⅀-inj (acc wf) i≤k x (Κ y ⊐ j≤k) = ⊠-Κ-inj (wf _ i≤k) y x ⊐↓ i≤k
⊠-match : ∀ {i j n}
→ Acc _<′_ n
→ {i≤n : i <′ n}
→ {j≤n : j <′ n}
→ InjectionOrdering i≤n j≤n
→ Coeff i +
→ Coeff j +
→ Poly n
⊠-match (acc wf) (inj-eq i&j≤n) xs ys = ⊠-coeffs (wf _ i&j≤n) xs ys ⊐↓ i&j≤n
⊠-match (acc wf) (inj-lt i≤j-1 j≤n) xs ys = poly-map (⊠-⅀-inj (wf _ j≤n) i≤j-1 xs) (ys) ⊐↓ j≤n
⊠-match (acc wf) (inj-gt i≤n j≤i-1) xs ys = poly-map (⊠-⅀-inj (wf _ i≤n) j≤i-1 ys) (xs) ⊐↓ i≤n
⊠-coeffs : ∀ {n} → Acc _<′_ n → Coeff n + → Coeff n + → Coeff n *
⊠-coeffs a (xs) (y ≠0 Δ j & []) = poly-map (⊠-step′ a y) (xs) ⍓* j
⊠-coeffs a (xs) (y ≠0 Δ j & ∹ ys) = para (⊠-cons a y ys) (xs) ⍓* j
{-# INLINE ⊠-coeffs #-}
⊠-cons : ∀ {n}
→ Acc _<′_ n
→ Poly n
→ Coeff n +
→ Fold n
⊠-cons a y ys (x ⊐ j≤n , xs) =
⊠-step a x j≤n y , ⊞-coeffs (poly-map (⊠-step a x j≤n) ys) xs
{-# INLINE ⊠-cons #-}
infixl 7 _⊠_
_⊠_ : ∀ {n} → Poly n → Poly n → Poly n
_⊠_ = ⊠-step′ (<′-wellFounded _)
{-# INLINE _⊠_ #-}
----------------------------------------------------------------------
-- Constants and variables
-- The constant polynomial
κ : ∀ {n} → Carrier → Poly n
κ x = Κ x ⊐ z≤′n
{-# INLINE κ #-}
-- A variable
ι : ∀ {n} → Fin n → Poly n
ι i = (κ 1# Δ 1 ∷↓ []) ⊐↓ space≤′n i
{-# INLINE ι #-}
----------------------------------------------------------------------
-- Exponentiation
-- We try very hard to never do things like multiply by 1
-- unnecessarily. That's what all the weirdness here is for.
⊡-mult : ∀ {n} → ℕ → Poly n → Poly n
⊡-mult zero xs = xs
⊡-mult (suc n) xs = ⊡-mult n xs ⊠ xs
_⊡_+1 : ∀ {n} → Poly n → ℕ → Poly n
(Κ x ⊐ i≤n) ⊡ i +1 = Κ (x ^ i +1) ⊐ i≤n
(⅀ (x Δ j & []) ⊐ i≤n) ⊡ i +1 = x .poly ⊡ i +1 Δ (j ℕ.+ i ℕ.* j) ∷↓ [] ⊐↓ i≤n
xs@(⅀ (_ & ∹ _) ⊐ i≤n) ⊡ i +1 = ⊡-mult i xs
infixr 8 _⊡_
_⊡_ : ∀ {n} → Poly n → ℕ → Poly n
_ ⊡ zero = κ 1#
xs ⊡ suc i = xs ⊡ i +1
{-# INLINE _⊡_ #-}
| {
"alphanum_fraction": 0.4862591545,
"avg_line_length": 32.9140811456,
"ext": "agda",
"hexsha": "2a54ad97edbeb2bc9b02696b6e38778fc74706bb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Base.agda",
"max_line_length": 103,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 5562,
"size": 13791
} |
open import Agda.Builtin.Nat
f : Nat → Nat
f v@n with n
... | zero = zero
... | suc m with m
... | zero = {!!}
... | suc o with o
... | zero = {!!}
... | suc p = {!!}
| {
"alphanum_fraction": 0.4207650273,
"avg_line_length": 15.25,
"ext": "agda",
"hexsha": "b30a0a0e523a2c4eab7dc9c926995010d507deb8",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue2958.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2958.agda",
"max_line_length": 28,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2958.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 68,
"size": 183
} |
import Lvl
open import Type
module Type.Cardinality {ℓₗ : Lvl.Level} where
import Type.Functions
import Logic.Predicate
module _ {ℓₒ₁}{ℓₒ₂} (X : Type{ℓₒ₁}) (Y : Type{ℓₒ₂}) where
open Type.Functions{ℓₗ}{ℓₒ₁}{ℓₒ₂}
open Logic.Predicate{ℓₗ}
_≍_ : Type{ℓₗ Lvl.⊔ ℓₒ₁ Lvl.⊔ ℓₒ₂}
_≍_ = ∃(Bijective{X}{Y})
_≼_ : Type{ℓₗ Lvl.⊔ ℓₒ₁ Lvl.⊔ ℓₒ₂}
_≼_ = ∃(Injective{X}{Y})
_≽_ : Type{ℓₗ Lvl.⊔ ℓₒ₁ Lvl.⊔ ℓₒ₂}
_≽_ = ∃(Surjective{X}{Y})
| {
"alphanum_fraction": 0.6224719101,
"avg_line_length": 21.1904761905,
"ext": "agda",
"hexsha": "9e8eaa87385e3416710656fac0feb88b75a0dc2c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Type/Cardinality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Type/Cardinality.agda",
"max_line_length": 57,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Type/Cardinality.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": 259,
"size": 445
} |
{-# OPTIONS --without-K #-}
module module-layout where
f : Set1
f = Set
| {
"alphanum_fraction": 0.6351351351,
"avg_line_length": 14.8,
"ext": "agda",
"hexsha": "67ce9d88be2e8c6b86aac5a3f49d9b86ad1a2491",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-03-12T21:33:35.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-07T01:38:12.000Z",
"max_forks_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "dubinsky/intellij-dtlc",
"max_forks_repo_path": "testData/parse/agda/module-layout.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_issues_repo_issues_event_max_datetime": "2021-03-15T17:04:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-30T04:29:32.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "dubinsky/intellij-dtlc",
"max_issues_repo_path": "testData/parse/agda/module-layout.agda",
"max_line_length": 27,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "dubinsky/intellij-dtlc",
"max_stars_repo_path": "testData/parse/agda/module-layout.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-29T13:18:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-11T16:26:38.000Z",
"num_tokens": 20,
"size": 74
} |
{-# OPTIONS --without-K #-}
module HoTT.Base where
open import Agda.Primitive public
-- Universe
𝒰 : (i : Level) → Set (lsuc i)
𝒰 i = Set i
𝒰₀ : Set₁
𝒰₀ = Set₀
module variables where
variable
i j : Level
A B : 𝒰 i
P Q : A → 𝒰 i
open variables
record Lift {i j} (A : 𝒰 j) : 𝒰 (i ⊔ j) where
constructor lift
field lower : A
open Lift public
-- Instance search
⟨⟩ : ∀ {i} {A : 𝒰 i} → ⦃ A ⦄ → A
⟨⟩ ⦃ a ⦄ = a
-- Dependent functions (Π-types)
Π : (A : 𝒰 i) (B : A → 𝒰 j) → 𝒰 (i ⊔ j)
Π A B = (x : A) → B x
syntax Π A (λ x → Φ) = Π[ x ∶ A ] Φ
infixr 6 Π
id : {A : 𝒰 i} → A → A
id x = x
const : A → B → A
const x _ = x
swap : {C : A → B → 𝒰 i} → ((x : A) (y : B) → C x y) →
(y : B) (x : A) → C x y
swap f y x = f x y
_∘_ : {C : {x : A} → P x → 𝒰 i} →
({x : A} → Π (P x) C) → (g : Π A P) → (x : A) → C (g x)
f ∘ g = λ x → f (g x)
infixr 30 _∘_
_$_ : Π A P → Π A P
_$_ = id
infixr 0 _$_
-- Identity
data _==_ {A : 𝒰 i} (a : A) : A → 𝒰 i where
instance refl : a == a
infixr 10 _==_
{-# BUILTIN EQUALITY _==_ #-}
=-ind : (C : (x y : A) → x == y → 𝒰 i) → ((x : A) → C x x refl) →
{x y : A} → (p : x == y) → C x y p
=-ind C c refl = c _
-- Based path induction
=-ind' : {a : A} → (C : (x : A) → a == x → 𝒰 i) → C a refl →
{x : A} → (p : a == x) → C x p
=-ind' C c refl = c
-- Lemma 2.1.1
_⁻¹ : {x y : A} → x == y → y == x
_⁻¹ refl = refl
infix 30 _⁻¹
-- Lemma 2.1.2
_∙_ : {x y z : A} → x == y → y == z → x == z
_∙_ refl refl = refl
infixl 20 _∙_
-- Lemma 2.2.1
ap : {x y : A} (f : A → B) → x == y → f x == f y
ap f refl = refl
ap² : {C : 𝒰 i} {x y : A} {z w : B} (f : A → B → C) → x == y → z == w → f x z == f y w
ap² _ refl refl = refl
-- Lemma 2.3.1
transport : {x y : A} (P : A → 𝒰 j) → x == y → P x → P y
transport _ refl = id
-- Lemma 2.3.4
apd : {x y : A} (f : (x : A) → P x) (p : x == y) → transport P p (f x) == f y
apd f refl = refl
-- Empty
data 𝟎 {i} : 𝒰 i where
𝟎-rec : {C : 𝒰 i} → 𝟎 {j} → C
𝟎-rec ()
𝟎-ind : {C : 𝟎 → 𝒰 i} → (z : 𝟎 {j}) → C z
𝟎-ind ()
¬_ : 𝒰 i → 𝒰 i
¬_ {i} A = A → 𝟎 {i}
infix 25 ¬_
_≠_ : A → A → 𝒰 _
_≠_ x y = ¬ (x == y)
-- Unit
record 𝟏 {i} : 𝒰 i where
no-eta-equality
instance constructor ★
𝟏-ind : (C : 𝟏 → 𝒰 i) → C ★ → (x : 𝟏 {j}) → C x
𝟏-ind C c ★ = c
𝟏-uniq : (x : 𝟏 {i}) → x == ★
𝟏-uniq ★ = refl
-- Boolean
data 𝟐 : 𝒰₀ where
0₂ : 𝟐
1₂ : 𝟐
{-# BUILTIN BOOL 𝟐 #-}
{-# BUILTIN FALSE 0₂ #-}
{-# BUILTIN TRUE 1₂ #-}
𝟐-rec : {C : 𝒰 i} → C → C → 𝟐 → C
𝟐-rec c₀ c₁ 0₂ = c₀
𝟐-rec c₀ c₁ 1₂ = c₁
𝟐-ind : (C : 𝟐 → 𝒰 i) → C 0₂ → C 1₂ → (x : 𝟐) → C x
𝟐-ind C c₀ c₁ 0₂ = c₀
𝟐-ind C c₀ c₁ 1₂ = c₁
-- Dependent pairs (Σ-types)
record Σ (A : 𝒰 i) (B : A → 𝒰 j) : 𝒰 (i ⊔ j) where
no-eta-equality
constructor _,_
field
pr₁ : A
pr₂ : B pr₁
infixr 15 _,_
open Σ public
syntax Σ A (λ x → Φ) = Σ[ x ∶ A ] Φ
infixr 6 Σ
Σ-rec : (C : 𝒰 i) → ((x : A) → P x → C) → (Σ A λ x → P x) → C
Σ-rec C g (a , b) = g a b
Σ-ind : (C : Σ A P → 𝒰 i) → ((a : A) → (b : P a) → C (a , b)) →
(p : Σ A P) → C p
Σ-ind C g (a , b) = g a b
Σ-uniq : (x : Σ A P) → pr₁ x , pr₂ x == x
Σ-uniq (a , b) = refl
-- Product
_×_ : (A : 𝒰 i) (B : 𝒰 j) → 𝒰 (i ⊔ j)
A × B = Σ[ _ ∶ A ] B
infixr 8 _×_
×-rec : (C : 𝒰 i) → (A → B → C) → A × B → C
×-rec _ g (a , b) = g a b
×-ind : (C : A × B → 𝒰 i) → ((x : A) (y : B) → C (x , y)) →
(x : A × B) → C x
×-ind _ g (a , b) = g a b
×-uniq : (x : A × B) → pr₁ x , pr₂ x == x
×-uniq (a , b) = refl
-- Coproduct
data _+_ (A : 𝒰 i) (B : 𝒰 j) : 𝒰 (i ⊔ j) where
inl : A → A + B
inr : B → A + B
infixr 8 _+_
+-rec : {C : 𝒰 i} → (A → C) → (B → C) → A + B → C
+-rec gₗ gᵣ (inl a) = gₗ a
+-rec gₗ gᵣ (inr b) = gᵣ b
+-ind : (C : A + B → 𝒰 i) →
((a : A) → C (inl a)) →
((b : B) → C (inr b)) → (x : A + B) → C x
+-ind C g₀ g₁ (inl a) = g₀ a
+-ind C g₀ g₁ (inr b) = g₁ b
-- Natural numbers
data ℕ : 𝒰₀ where
zero : ℕ
succ : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
ℕ-rec : {C : 𝒰 i} → C → (ℕ → C → C) → ℕ → C
ℕ-rec c₀ cₛ zero = c₀
ℕ-rec c₀ cₛ (succ n) = cₛ n (ℕ-rec c₀ cₛ n)
ℕ-ind : (C : ℕ → 𝒰 i) → C 0 → ((n : ℕ) → C n → C (succ n)) → (n : ℕ) → C n
ℕ-ind C c₀ cₛ 0 = c₀
ℕ-ind C c₀ cₛ (succ n) = cₛ n (ℕ-ind C c₀ cₛ n)
-- Homotopy
_~_ : (f g : Π A P) → 𝒰 _
f ~ g = ∀ x → f x == g x
happly : {f g : Π A P} → f == g → f ~ g
happly refl _ = refl
-- Lemma 2.4.2
reflₕ : {f : Π A P} → f ~ f
reflₕ _ = refl
_∙ₕ_ : {f g h : Π A P} → f ~ g → g ~ h → f ~ h
α ∙ₕ β = λ x → α x ∙ β x
infixl 20 _∙ₕ_
_⁻¹ₕ : {f g : Π A P} → f ~ g → g ~ f
α ⁻¹ₕ = λ x → α x ⁻¹
| {
"alphanum_fraction": 0.4334744818,
"avg_line_length": 20.3031674208,
"ext": "agda",
"hexsha": "e1c7fca4476ccd671039ee18bd459eb041d6913e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Base.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2462,
"size": 4487
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import stash.modalities.JoinAdj
module stash.modalities.Orthogonality where
module PathSplit {i} (X : Type i) (x y : X) where
to : (x == y) → Σ X (λ z → (x == z) × (z == y))
to p = x , (idp , p)
from : Σ X (λ z → (x == z) × (z == y)) → x == y
from (z , p , q) = p ∙ q
abstract
to-from : (b : Σ X (λ z → (x == z) × (z == y))) → to (from b) == b
to-from (z , p , q) = pair= p (↓-×-in (↓-cst=idf-in (∙'-unit-l p)) (↓-idf=cst-in idp))
from-to : (p : x == y) → from (to p) == p
from-to p = idp
path-split : (x == y) ≃ Σ X (λ z → (x == z) × (z == y))
path-split = equiv to from to-from from-to
module _ {i} where
Δ : (X A : Type i) → X → (A → X)
Δ X A = cst
-- Δ-ap : {X A : Type i} {x y : X} (φ : A → x == y) (a : A)
-- → λ= φ == ap cst (φ a)
-- Δ-ap φ a = equiv-is-inj {f = app=} (snd app=-equiv) (λ= φ) (ap cst (φ a)) (λ= (λ a₀ → app=-β φ a₀ ∙ {!lem a₀!}))
-- where lem : ∀ a₀ → φ a₀ == app= (ap cst (φ a₀)) a₀
-- lem = {!!}
⟦_⊥_⟧ : (A : Type i) (X : Type i) → Type i
⟦ A ⊥ X ⟧ = is-equiv (Δ X A)
ctr : {A X : Type i} → ⟦ A ⊥ X ⟧ → (A → X) → X
ctr A⊥X φ = is-equiv.g A⊥X φ
ctr-null : {A X : Type i} (A⊥X : ⟦ A ⊥ X ⟧) (φ : A → X)
→ cst (ctr A⊥X φ) == φ
ctr-null A⊥X φ = is-equiv.f-g A⊥X φ
ctr-cst : {A X : Type i} (A⊥X : ⟦ A ⊥ X ⟧)
→ (x : X) → ctr A⊥X (cst x) == x
ctr-cst A⊥X x = is-equiv.g-f A⊥X x
Unit-orth : (A : Type i) → ⟦ Lift ⊤ ⊥ A ⟧
Unit-orth A = record {
g = λ φ → φ (lift unit) ;
f-g = λ φ → λ= (λ { (lift unit) → idp }) ;
g-f = λ a → idp ;
adj = λ a → λ=-η idp }
Δ-equiv-is-contr : (A : Type i) → is-equiv (Δ A A) → is-contr A
Δ-equiv-is-contr A e = is-equiv.g e (idf A) , (λ a → app= (is-equiv.f-g e (idf A)) a)
self-orth-is-contr : (A : Type i) → ⟦ A ⊥ A ⟧ → is-contr A
self-orth-is-contr A ω = Δ-equiv-is-contr A ω
equiv-preserves-orth-l : {A B X : Type i} → (A ≃ B) → ⟦ A ⊥ X ⟧ → ⟦ B ⊥ X ⟧
equiv-preserves-orth-l {A} {B} {X} (f , f-ise) ω = is-eq (Δ X B) g f-g ω.g-f
where module ω = is-equiv ω
module f = is-equiv f-ise
g : (B → X) → X
g φ = ω.g (φ ∘ f)
f-g : (φ : B → X) → Δ X B (g φ) == φ
f-g φ = λ= λ b → app= (ω.f-g (φ ∘ f)) (f.g b) ∙ ap φ (f.f-g b)
equiv-preserves-orth-r : {A X Y : Type i} → (X ≃ Y) → ⟦ A ⊥ X ⟧ → ⟦ A ⊥ Y ⟧
equiv-preserves-orth-r {A} {X} {Y} (f , f-ise) ω = is-eq (Δ Y A) g f-g g-f
where module ω = is-equiv ω
module f = is-equiv f-ise
g : (A → Y) → Y
g φ = f (ω.g (f.g ∘ φ))
f-g : (φ : A → Y) → Δ Y A (g φ) == φ
f-g φ = λ= λ x → ap f (app= (ω.f-g (f.g ∘ φ)) x) ∙ f.f-g (φ x)
g-f : (y : Y) → g (Δ Y A y) == y
g-f y = ap f (ω.g-f (f.g y)) ∙ f.f-g y
Σ-orth : {A X : Type i} {B : A → Type i} → ⟦ A ⊥ X ⟧ → (B⊥ : (a : A) → ⟦ B a ⊥ X ⟧) → ⟦ Σ A B ⊥ X ⟧
Σ-orth {A} {X} {B} A⊥ B⊥ = is-eq _ from to-from from-to
where from : (Σ A B → X) → X
from φ = ctr A⊥ (λ a → ctr (B⊥ a) (λ b → φ (a , b)))
to-from : (φ : Σ A B → X) → cst (from φ) == φ
to-from φ = λ= (λ { (a , b) → app= (ctr-null A⊥ (λ a → ctr (B⊥ a) (λ b → φ (a , b)))) a ∙
app= (ctr-null (B⊥ a) (λ b → φ (a , b))) b })
from-to : (x : X) → from (cst x) == x
from-to x = ap (ctr A⊥) (λ= (λ a → ctr-cst (B⊥ a) x)) ∙ ctr-cst A⊥ x
-- -- This works if the base is connected, but you'll have to add that
-- fib-orth : {A X : Type i} {B : A → Type i} → ⟦ Σ A B ⊥ X ⟧ → (a : A) → ⟦ B a ⊥ X ⟧
-- fib-orth {A} {X} {B} Σ⊥ a = is-eq _ g {!!} {!!}
-- where g : (φ : B a → X) → X
-- g φ = ctr Σ⊥ {!!}
-- -- This looks doomed ...
-- base-orth : {A X : Type i} {B : A → Type i} → ⟦ Σ A B ⊥ X ⟧ → ⟦ A ⊥ X ⟧
-- base-orth {A} {X} {B} Σ⊥ = is-eq _ g f-g {!!}
-- where g : (φ : A → X) → X
-- g φ = ctr Σ⊥ (uncurry (λ a _ → φ a))
-- f-g : (φ : A → X) → cst (g φ) == φ
-- f-g φ = λ= (λ a → app= (ctr-null Σ⊥ (uncurry (λ a _ → φ a))) (a , {!!}))
×-orth : {A B X : Type i} → ⟦ A ⊥ X ⟧ → ⟦ B ⊥ X ⟧ → ⟦ A × B ⊥ X ⟧
×-orth {B = B} A⊥ B⊥ = Σ-orth {B = λ _ → B} A⊥ (λ _ → B⊥)
-- Okay, you need to find a simpler way.
-- *-orth : {A B X : Type i} → ⟦ B ⊥ X ⟧ → ⟦ A * B ⊥ X ⟧
-- *-orth {A} {B} {X} ω = is-eq (Δ X (A * B)) from to-from from-to
-- where from : (A * B → X) → X
-- from f = is-equiv.g ω (f ∘ right)
-- where test : A → hfiber cst (f ∘ right)
-- test = snd (–> (join-adj A B X) f)
-- to-from : (f : A * B → X) → Δ X (A * B) (from f) == f
-- to-from f = {!!}
-- from-to : (x : X) → from (Δ X (A * B) x) == x
-- from-to x = {!is-equiv.g-f ω x!}
postulate
-- Right, this is a special case of the join adjunction ...
adj-orth : (A X : Type i) → ⟦ Susp A ⊥ X ⟧ → (x y : X) → ⟦ A ⊥ x == y ⟧
pths-orth : {A X : Type i} {x y : X} → ⟦ A ⊥ X ⟧ → ⟦ A ⊥ x == y ⟧
pths-orth {A} {X} {x} {y} A⊥X = is-eq (Δ (x == y) A) g to-from from-to
where g : (A → x == y) → x == y
g φ = ! (ctr-cst A⊥X x) ∙ ap (ctr A⊥X) (λ= φ) ∙ ctr-cst A⊥X y
to-from : (φ : A → x == y) → Δ (x == y) A (g φ) == φ
to-from φ = λ= coh
where coh : (a : A) → g φ == φ a
coh a = ! (ctr-cst A⊥X x) ∙ ap (ctr A⊥X) (λ= φ) ∙ ctr-cst A⊥X y =⟨ {!!} ⟩
φ a ∎
where puzzle = ap (ctr A⊥X) (λ= φ) =⟨ {!a !} ⟩
ap (ctr A⊥X) (ap cst (φ a)) =⟨ ∘-ap (ctr A⊥X) cst (φ a) ⟩
ap ((ctr A⊥X) ∘ cst) (φ a) ∎
eq : ctr-cst A⊥X x ∙' φ a == ap ((ctr A⊥X) ∘ cst) (φ a) ∙ ctr-cst A⊥X y
eq = ↓-app=idf-out (apd (ctr-cst A⊥X) (φ a))
eq₀ : ctr-null A⊥X (cst x) ∙' λ= φ == ap (cst ∘ (ctr A⊥X)) (λ= φ) ∙ ctr-null A⊥X (cst y)
eq₀ = ↓-app=idf-out (apd (ctr-null A⊥X) (λ= φ))
adj : ap cst (ctr-cst A⊥X x) == ctr-null A⊥X (cst x)
adj = is-equiv.adj A⊥X x
adj' : ap (ctr A⊥X) (ctr-null A⊥X (cst x)) == ctr-cst A⊥X (ctr A⊥X (cst x))
adj' = is-equiv.adj' A⊥X (cst x)
claim : (λ= φ) == ! (ap cst (ctr-cst A⊥X x)) ∙ ap cst (ap (ctr A⊥X) (λ= φ)) ∙ ap cst (ctr-cst A⊥X y)
claim = {!!}
then : (λ= φ) == ap cst (! (ctr-cst A⊥X x) ∙ ap (ctr A⊥X) (λ= φ) ∙ ctr-cst A⊥X y)
then = {!!}
from-to : (p : x == y) → g (cst p) == p
from-to p = {!!}
-- Weak cellular inequalities
module _ {i} where
_≻_ : Type i → Type i → Type _
X ≻ A = (Y : Type i) → ⟦ A ⊥ Y ⟧ → ⟦ X ⊥ Y ⟧
equiv-preserves-≻-l : {X Y : Type i} {A : Type i} → X ≃ Y → X ≻ A → Y ≻ A
equiv-preserves-≻-l {X} {Y} {A} e ω Z o = equiv-preserves-orth-l e (ω Z o)
≻-trivial : (A : Type i) → (Lift ⊤) ≻ A
≻-trivial A X _ = Unit-orth X
≻-reflexive : (A : Type i) → A ≻ A
≻-reflexive A Y x = x
≻-trans : (A B C : Type i) → A ≻ B → B ≻ C → A ≻ C
≻-trans A B C ω₀ ω₁ Y cy = ω₀ Y (ω₁ Y cy)
≻-⊤-is-contr : (A : Type i) → A ≻ (Lift ⊤) → is-contr A
≻-⊤-is-contr A ω = self-orth-is-contr A (ω A (Unit-orth A))
Σ-≻ : {A X : Type i} {P : X → Type i} → X ≻ A → (P≻A : (x : X) → P x ≻ A) → Σ X P ≻ A
Σ-≻ X≻A P≻A Y A⊥Y = Σ-orth (X≻A Y A⊥Y) (λ x → P≻A x Y A⊥Y)
-- We jump a universe level, but its certainly convenient ...
is-hyper-prop : Type i → Type (lsucc i)
is-hyper-prop A = (X Y : Type i) (f : X → Y) → X ≻ A → Y ≻ A → (y : Y) → hfiber f y ≻ A
hp-kills-paths : (A : Type i) → is-hyper-prop A
→ (X : Type i) → X ≻ A
→ (x y : X) → (x == y) ≻ A
hp-kills-paths A hp X X≻A x y = equiv-preserves-≻-l
(equiv snd (λ p → (_ , p)) (λ _ → idp) (λ _ → idp))
(hp (Lift ⊤) X (λ _ → x) (≻-trivial A) X≻A y)
-- Okay, so in some sense this is much more natural.
-- It just says the connected guys have to be closed under
-- diagonals.
kills-paths-hp : (A : Type i)
→ (κ : (X : Type i) → X ≻ A → (x y : X) → (x == y) ≻ A)
→ is-hyper-prop A
kills-paths-hp A κ X Y f X≻A Y≻A y = Σ-≻ X≻A (λ x → κ Y Y≻A (f x) y)
-- You'll have to think a bit about why this is equivalent
-- to *preserving* the path spaces.
×-≻ : {A B X : Type i} → A ≻ X → B ≻ X → A × B ≻ X
×-≻ ω₀ ω₁ Y e = ×-orth (ω₀ Y e) (ω₁ Y e)
postulate
susp-≻ : (A : Type i) → Susp A ≻ A
| {
"alphanum_fraction": 0.3873223801,
"avg_line_length": 37.8487394958,
"ext": "agda",
"hexsha": "a35cdca7dd8c80ad19777ee2f0d8a1d934689f73",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/stash/modalities/Orthogonality.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/stash/modalities/Orthogonality.agda",
"max_line_length": 128,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/stash/modalities/Orthogonality.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": 3954,
"size": 9008
} |
module sort where
open import bool
open import eq
open import nat
open import list
open import nondet
open import nondet-thms
-- non-deterministic insert.
--This takes a nondeterministic list because I need to be able to call it with the result of perm
--
--implementation in curry:
-- ndinsert x [] = []
-- ndinsert x (y:ys) = (x : y : xs) ? (y : insert x ys)
ndinsert : {A : Set} -> A -> ND (list A) -> ND (list A)
ndinsert x (Val [] ) = Val ( x :: [])
ndinsert x (Val (y :: ys)) = (Val ( x :: y :: ys )) ?? ((_::_ y) $* (ndinsert x (Val ys)))
ndinsert x (l ?? r) = (ndinsert x l) ?? (ndinsert x r)
--non-deterministic permutation
--this is identical to the curry code (except for the Val constructor)
perm : {A : Set} -> (list A) -> ND (list A)
perm [] = Val []
perm (x :: xs) = ndinsert x (perm xs)
--insert a value into a sorted list.
--this is identical to curry or haskell code.
--
--note that the structure here is identical to ndinsert
insert : {A : Set} -> (A -> A -> 𝔹) -> A -> list A -> list A
insert _ x [] = x :: []
insert _<_ x (y :: ys) = if x < y
then (x :: y :: ys)
else (y :: insert _<_ x ys)
--simple insertion sort
--again this is identical to curry or haskell
--also, note that the structure is identical to perm
sort : {A : Set} -> (A -> A -> 𝔹) -> list A -> list A
sort _ [] = []
sort p (x :: xs) = insert p x (sort p xs)
-- Proof: if xs ∈ nxs then x::xs ∈ ndinsert x nxs
insId : {A : Set} -> (x : A) -> (xs : list A) -> (x :: xs) ∈ (ndinsert x (Val xs))
insId x [] = ndrefl
insId x (y :: xs) = left (Val (x :: y :: xs)) ((_::_ y) $* (ndinsert x (Val xs))) ndrefl
--If introduction rule for non-deterministic values.
--if x and y are both possible values in z then
--∀ c. if c then x else y will give us either x or y, so it must be a possible value of z.
--
ifIntro : {A : Set} -> (x : A) -> (y : A) -> (z : ND A) -> (p : x ∈ z) -> (q : y ∈ z) -> (c : 𝔹) -> (if c then x else y) ∈ z
ifIntro x y z p q tt = p
ifIntro x y z p q ff = q
---------------------------------------------------------------------------
--
-- this should prove that if xs ∈ nxs then, insert x xs ∈ ndinsert x nxs
-- parameters:
-- c : a comparison operator that is needed for insert
-- x : the value we are inserting into the list
-- xs : the list
-- nxs : a non-deterministic list, we know that xs is a possible value for nxs
-- xs ∈ nxs : the proof that xs is somewhere in nxs
--
--retruns: insert c x xs ∈ ndinsert x nxs
-- a proof that inserting a value in a list is ok with non-deterministic lists
insert=ndinsert : {A : Set} -> (c : A -> A -> 𝔹) -> (x : A) -> (xs : list A) -> (nxs : ND (list A)) -> xs ∈ nxs -> (insert c x xs) ∈ (ndinsert x nxs)
--the first two cases are simple, either we are inserting into an empty list, in which case it's trivial
--or, the list doesn't match the non-deterministic case. This is an imposible case
insert=ndinsert _ x [] (Val []) _ = ndrefl
insert=ndinsert _ x [] (Val (_ :: _)) ()
--the next two cases are just structural recursion on the non-deterministic tree.
insert=ndinsert c x ys (l ?? r) (left .l .r p) = left (ndinsert x l) (ndinsert x r) (insert=ndinsert c x ys l p)
insert=ndinsert c x ys (l ?? r) (right .l .r p) = right (ndinsert x l) (ndinsert x r) (insert=ndinsert c x ys r p)
--The final case is the interesting one.
--We reached a leaf in the non-deterministic tree, so we have a deterministic value.
--by definition this is equal to the deterministic list (y :: ys)
--At this point we have two possible cases.
--Either x is smaller then every element in (y :: ys), in which case it's inserted at the front,
--or x is larger than y, in which case it's inserted somewhere in ys.
--Since both of these cases are covered by ndinsert we can invoke the ifIntro lemma, to say that we don't care which case it is.
--
--variables:
-- step : one step of insert
-- l : the left hand side of insert c x xs (the then branch)
-- r : the right hand side of insert c x xs (the else branch)
-- nr : a non-deterministic r
-- (Val l) : a non-deterministic l (but since ndinsert only has a deterministic value on the left it's not very interesting)
-- rec : The recursive call. If x isn't inserted into the front, then we need to find it.
-- l∈step : a proof that l is a possible value for step
-- r∈step : a proof that r is a possible value for step
insert=ndinsert _<_ x (y :: ys) (Val (.y :: .ys)) ndrefl = ifIntro l r step l∈step r∈step (x < y)
where step = ndinsert x (Val (y :: ys))
l = ( x :: y :: ys)
r = y :: insert _<_ x ys
nr = (_::_ y) $* (ndinsert x (Val ys))
rec = ∈-$* (_::_ y) (insert _<_ x ys) (ndinsert x (Val ys)) (insert=ndinsert _<_ x ys (Val ys) ndrefl)
r∈step = right (Val l) nr rec
l∈step = left (Val l) nr ndrefl
---------------------------------------------------------------------------
-- main theorem. Sorting a list preserves permutations
--all of the work is really done by insert=ndinsert
sortPerm : {A : Set} -> (c : A -> A -> 𝔹) -> (xs : list A) -> sort c xs ∈ perm xs
sortPerm _<_ [] = ndrefl
sortPerm _<_ (x :: xs) = insert=ndinsert _<_ x (sort _<_ xs) (perm xs) (sortPerm _<_ xs)
| {
"alphanum_fraction": 0.5912780819,
"avg_line_length": 46.0608695652,
"ext": "agda",
"hexsha": "41fcbfd5978bffebb18c1a1cb050c2ed9c91718b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "mihanus/curry-agda",
"max_forks_repo_path": "nondet/sort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "mihanus/curry-agda",
"max_issues_repo_path": "nondet/sort.agda",
"max_line_length": 149,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "mihanus/curry-agda",
"max_stars_repo_path": "nondet/sort.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1623,
"size": 5297
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Homomorphisms.Definition
open import Groups.Definition
open import Groups.Lemmas
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Rings.Homomorphisms.Definition
open import Groups.Homomorphisms.Lemmas
open import Rings.Subrings.Definition
open import Rings.Cosets
open import Rings.Isomorphisms.Definition
open import Groups.Isomorphisms.Definition
module Rings.Ideals.FirstIsomorphismTheorem {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_+A_ _*A_ : A → A → A} {_+B_ _*B_ : B → B → B} {R1 : Ring S _+A_ _*A_} {R2 : Ring T _+B_ _*B_} {f : A → B} (hom : RingHom R1 R2 f) where
open import Rings.Quotients.Definition R1 R2 hom
open import Rings.Homomorphisms.Image hom
open import Rings.Homomorphisms.Kernel hom
open Setoid T
open Equivalence eq
open import Groups.FirstIsomorphismTheorem (RingHom.groupHom hom)
ringFirstIsomorphismTheorem : RingsIsomorphic (cosetRing R1 ringKernelIsIdeal) (subringIsRing R2 imageGroupSubring)
RingsIsomorphic.f ringFirstIsomorphismTheorem = GroupsIsomorphic.isomorphism groupFirstIsomorphismTheorem
RingHom.preserves1 (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem)) = RingHom.preserves1 hom
RingHom.ringHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem)) = RingHom.ringHom hom
GroupHom.groupHom (RingHom.groupHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem))) = GroupHom.groupHom (RingHom.groupHom hom)
GroupHom.wellDefined (RingHom.groupHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem))) {x} {y} x=y = transferToRight (Ring.additiveGroup R2) t
where
t : f x +B Group.inverse (Ring.additiveGroup R2) (f y) ∼ Ring.0R R2
t = transitive (Ring.groupIsAbelian R2) (transitive (Group.+WellDefined (Ring.additiveGroup R2) (symmetric (homRespectsInverse (RingHom.groupHom hom))) reflexive) (transitive (symmetric (GroupHom.groupHom (RingHom.groupHom hom))) x=y))
RingIso.bijective (RingsIsomorphic.iso ringFirstIsomorphismTheorem) = GroupIso.bij (GroupsIsomorphic.proof groupFirstIsomorphismTheorem)
ringFirstIsomorphismTheorem' : RingsIsomorphic quotientByRingHom (subringIsRing R2 imageGroupSubring)
RingsIsomorphic.f ringFirstIsomorphismTheorem' a = f a , (a , reflexive)
RingHom.preserves1 (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem')) = RingHom.preserves1 hom
RingHom.ringHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem')) {r} {s} = RingHom.ringHom hom
RingHom.groupHom (RingIso.ringHom (RingsIsomorphic.iso ringFirstIsomorphismTheorem')) = GroupIso.groupHom (GroupsIsomorphic.proof (groupFirstIsomorphismTheorem'))
RingIso.bijective (RingsIsomorphic.iso ringFirstIsomorphismTheorem') = GroupIso.bij (GroupsIsomorphic.proof groupFirstIsomorphismTheorem')
| {
"alphanum_fraction": 0.8075213675,
"avg_line_length": 66.4772727273,
"ext": "agda",
"hexsha": "349123ca2825c2d18b3b229dc363b12af3f67e68",
"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/Ideals/FirstIsomorphismTheorem.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/Ideals/FirstIsomorphismTheorem.agda",
"max_line_length": 265,
"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/Ideals/FirstIsomorphismTheorem.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": 885,
"size": 2925
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to All
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.All.Properties where
open import Axiom.Extensionality.Propositional using (Extensionality)
open import Data.Bool.Base using (Bool; T)
open import Data.Bool.Properties
open import Data.Empty
open import Data.Fin using (Fin) renaming (zero to fzero; suc to fsuc)
open import Data.List.Base
open import Data.List.Membership.Propositional
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
import Data.List.Relation.Binary.Equality.Setoid as ListEq using (_≋_; []; _∷_)
open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_)
open import Data.List.Relation.Binary.Subset.Propositional using (_⊆_)
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Data.Maybe.Relation.Unary.All as MAll using (just; nothing)
open import Data.Nat using (zero; suc; z≤n; s≤s; _<_)
open import Data.Product as Prod using (_×_; _,_; uncurry; uncurry′)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; equivalence; Equivalence)
open import Function.Inverse using (_↔_; inverse)
open import Function.Surjection using (_↠_; surjection)
open import Relation.Binary using (Setoid; _Respects_)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open import Relation.Unary
using (Decidable; Pred; Universal) renaming (_⊆_ to _⋐_)
------------------------------------------------------------------------
-- Lemmas relating Any, All and negation.
module _ {a p} {A : Set a} {P : A → Set p} where
¬Any⇒All¬ : ∀ xs → ¬ Any P xs → All (¬_ ∘ P) xs
¬Any⇒All¬ [] ¬p = []
¬Any⇒All¬ (x ∷ xs) ¬p = ¬p ∘ here ∷ ¬Any⇒All¬ xs (¬p ∘ there)
All¬⇒¬Any : ∀ {xs} → All (¬_ ∘ P) xs → ¬ Any P xs
All¬⇒¬Any [] ()
All¬⇒¬Any (¬p ∷ _) (here p) = ¬p p
All¬⇒¬Any (_ ∷ ¬p) (there p) = All¬⇒¬Any ¬p p
¬All⇒Any¬ : Decidable P → ∀ xs → ¬ All P xs → Any (¬_ ∘ P) xs
¬All⇒Any¬ dec [] ¬∀ = ⊥-elim (¬∀ [])
¬All⇒Any¬ dec (x ∷ xs) ¬∀ with dec x
... | yes p = there (¬All⇒Any¬ dec xs (¬∀ ∘ _∷_ p))
... | no ¬p = here ¬p
Any¬→¬All : ∀ {xs} → Any (¬_ ∘ P) xs → ¬ All P xs
Any¬→¬All (here ¬p) = ¬p ∘ All.head
Any¬→¬All (there ¬p) = Any¬→¬All ¬p ∘ All.tail
¬Any↠All¬ : ∀ {xs} → (¬ Any P xs) ↠ All (¬_ ∘ P) xs
¬Any↠All¬ = surjection (¬Any⇒All¬ _) All¬⇒¬Any to∘from
where
to∘from : ∀ {xs} (¬p : All (¬_ ∘ P) xs) → ¬Any⇒All¬ xs (All¬⇒¬Any ¬p) ≡ ¬p
to∘from [] = P.refl
to∘from (¬p ∷ ¬ps) = P.cong₂ _∷_ P.refl (to∘from ¬ps)
-- If equality of functions were extensional, then the surjection
-- could be strengthened to a bijection.
from∘to : Extensionality _ _ →
∀ xs → (¬p : ¬ Any P xs) → All¬⇒¬Any (¬Any⇒All¬ xs ¬p) ≡ ¬p
from∘to ext [] ¬p = ext λ ()
from∘to ext (x ∷ xs) ¬p = ext λ
{ (here p) → P.refl
; (there p) → P.cong (λ f → f p) $ from∘to ext xs (¬p ∘ there)
}
Any¬⇔¬All : ∀ {xs} → Decidable P → Any (¬_ ∘ P) xs ⇔ (¬ All P xs)
Any¬⇔¬All dec = equivalence Any¬→¬All (¬All⇒Any¬ dec _)
where
-- If equality of functions were extensional, then the logical
-- equivalence could be strengthened to a surjection.
to∘from : Extensionality _ _ →
∀ {xs} (¬∀ : ¬ All P xs) → Any¬→¬All (¬All⇒Any¬ dec xs ¬∀) ≡ ¬∀
to∘from ext ¬∀ = ext (⊥-elim ∘ ¬∀)
------------------------------------------------------------------------
-- Properties of operations over `All`
------------------------------------------------------------------------
-- map
module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} {f : P ⋐ Q} where
map-cong : ∀ {xs} {g : P ⋐ Q} (ps : All P xs) →
(∀ {x} → f {x} P.≗ g) → All.map f ps ≡ All.map g ps
map-cong [] _ = P.refl
map-cong (px ∷ ps) feq = P.cong₂ _∷_ (feq px) (map-cong ps feq)
map-id : ∀ {xs} (ps : All P xs) → All.map id ps ≡ ps
map-id [] = P.refl
map-id (px ∷ ps) = P.cong (px ∷_) (map-id ps)
map-compose : ∀ {r} {R : Pred A r} {xs} {g : Q ⋐ R} (ps : All P xs) →
All.map g (All.map f ps) ≡ All.map (g ∘ f) ps
map-compose [] = P.refl
map-compose (px ∷ ps) = P.cong (_ ∷_) (map-compose ps)
lookup-map : ∀ {xs x} (ps : All P xs) (i : x ∈ xs) →
All.lookup (All.map f ps) i ≡ f (All.lookup ps i)
lookup-map (px ∷ pxs) (here P.refl) = P.refl
lookup-map (px ∷ pxs) (there i) = lookup-map pxs i
------------------------------------------------------------------------
-- _[_]%=_/updateAt
module _ {a p} {A : Set a} {P : Pred A p} where
updateAt-updates : ∀ {x xs px} (pxs : All P xs) (i : x ∈ xs)
{f : P x → P x} → All.lookup pxs i ≡ px →
All.lookup (pxs All.[ i ]%= f) i ≡ f px
updateAt-updates [] ()
updateAt-updates (px ∷ pxs) (here P.refl) P.refl = P.refl
updateAt-updates (px ∷ pxs) (there i) = updateAt-updates pxs i
updateAt-cong : ∀ {x xs} (pxs : All P xs) (i : x ∈ xs)
{f g : P x → P x} →
f (All.lookup pxs i) ≡ g (All.lookup pxs i) →
(pxs All.[ i ]%= f) ≡ (pxs All.[ i ]%= g)
updateAt-cong (px ∷ pxs) (here P.refl) = P.cong (_∷ pxs)
updateAt-cong (px ∷ pxs) (there i) f≗g = P.cong (px ∷_) (updateAt-cong pxs i f≗g)
updateAt-id : ∀ {x xs} (pxs : All P xs) (i : x ∈ xs) →
(pxs All.[ i ]%= id) ≡ pxs
updateAt-id (px ∷ pxs) (here P.refl) = P.refl
updateAt-id (px ∷ pxs) (there i) = P.cong (px ∷_) (updateAt-id pxs i)
updateAt-compose : ∀ {x xs} (pxs : All P xs) (i : x ∈ xs) {f g : P x → P x} →
(pxs All.[ i ]%= f All.[ i ]%= g) ≡ pxs All.[ i ]%= (g ∘ f)
updateAt-compose (px ∷ pxs) (here P.refl) = P.refl
updateAt-compose (px ∷ pxs) (there i) = P.cong (px ∷_) (updateAt-compose pxs i)
map-updateAt : ∀ {q x} {Q : Pred A q} {xs} →
∀ {f : P ⋐ Q} {g : P x → P x} {h : Q x → Q x}
(pxs : All P xs) (i : x ∈ xs) →
f (g (All.lookup pxs i)) ≡ h (f (All.lookup pxs i)) →
All.map f (pxs All.[ i ]%= g) ≡ (All.map f pxs) All.[ i ]%= h
map-updateAt (px ∷ pxs) (here P.refl) = P.cong (_∷ _)
map-updateAt (px ∷ pxs) (there i) feq = P.cong (_ ∷_) (map-updateAt pxs i feq)
------------------------------------------------------------------------
-- Introduction (⁺) and elimination (⁻) rules for list operations
------------------------------------------------------------------------
-- map
module _ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B} where
map⁺ : ∀ {xs} → All (P ∘ f) xs → All P (map f xs)
map⁺ [] = []
map⁺ (p ∷ ps) = p ∷ map⁺ ps
map⁻ : ∀ {xs} → All P (map f xs) → All (P ∘ f) xs
map⁻ {xs = []} [] = []
map⁻ {xs = _ ∷ _} (p ∷ ps) = p ∷ map⁻ ps
-- A variant of All.map.
module _ {a b p q} {A : Set a} {B : Set b} {f : A → B}
{P : A → Set p} {Q : B → Set q} where
gmap : P ⋐ Q ∘ f → All P ⋐ All Q ∘ map f
gmap g = map⁺ ∘ All.map g
------------------------------------------------------------------------
-- mapMaybe
module _ {a b p} {A : Set a} {B : Set b}
(P : B → Set p) {f : A → Maybe B} where
mapMaybe⁺ : ∀ {xs} → All (MAll.All P) (map f xs) → All P (mapMaybe f xs)
mapMaybe⁺ {[]} [] = []
mapMaybe⁺ {x ∷ xs} (px ∷ pxs) with f x
... | nothing = mapMaybe⁺ pxs
... | just v with px
... | just pv = pv ∷ mapMaybe⁺ pxs
------------------------------------------------------------------------
-- _++_
module _ {a p} {A : Set a} {P : A → Set p} where
++⁺ : ∀ {xs ys} → All P xs → All P ys → All P (xs ++ ys)
++⁺ [] pys = pys
++⁺ (px ∷ pxs) pys = px ∷ ++⁺ pxs pys
++⁻ˡ : ∀ xs {ys} → All P (xs ++ ys) → All P xs
++⁻ˡ [] p = []
++⁻ˡ (x ∷ xs) (px ∷ pxs) = px ∷ (++⁻ˡ _ pxs)
++⁻ʳ : ∀ xs {ys} → All P (xs ++ ys) → All P ys
++⁻ʳ [] p = p
++⁻ʳ (x ∷ xs) (px ∷ pxs) = ++⁻ʳ xs pxs
++⁻ : ∀ xs {ys} → All P (xs ++ ys) → All P xs × All P ys
++⁻ [] p = [] , p
++⁻ (x ∷ xs) (px ∷ pxs) = Prod.map (px ∷_) id (++⁻ _ pxs)
++↔ : ∀ {xs ys} → (All P xs × All P ys) ↔ All P (xs ++ ys)
++↔ {xs} = inverse (uncurry ++⁺) (++⁻ xs) ++⁻∘++⁺ (++⁺∘++⁻ xs)
where
++⁺∘++⁻ : ∀ xs {ys} (p : All P (xs ++ ys)) →
uncurry′ ++⁺ (++⁻ xs p) ≡ p
++⁺∘++⁻ [] p = P.refl
++⁺∘++⁻ (x ∷ xs) (px ∷ pxs) = P.cong (_∷_ px) $ ++⁺∘++⁻ xs pxs
++⁻∘++⁺ : ∀ {xs ys} (p : All P xs × All P ys) →
++⁻ xs (uncurry ++⁺ p) ≡ p
++⁻∘++⁺ ([] , pys) = P.refl
++⁻∘++⁺ (px ∷ pxs , pys) rewrite ++⁻∘++⁺ (pxs , pys) = P.refl
------------------------------------------------------------------------
-- concat
module _ {a p} {A : Set a} {P : A → Set p} where
concat⁺ : ∀ {xss} → All (All P) xss → All P (concat xss)
concat⁺ [] = []
concat⁺ (pxs ∷ pxss) = ++⁺ pxs (concat⁺ pxss)
concat⁻ : ∀ {xss} → All P (concat xss) → All (All P) xss
concat⁻ {[]} [] = []
concat⁻ {xs ∷ xss} pxs = ++⁻ˡ xs pxs ∷ concat⁻ (++⁻ʳ xs pxs)
------------------------------------------------------------------------
-- take and drop
module _ {a p} {A : Set a} {P : A → Set p} where
drop⁺ : ∀ {xs} n → All P xs → All P (drop n xs)
drop⁺ zero pxs = pxs
drop⁺ (suc n) [] = []
drop⁺ (suc n) (px ∷ pxs) = drop⁺ n pxs
take⁺ : ∀ {xs} n → All P xs → All P (take n xs)
take⁺ zero pxs = []
take⁺ (suc n) [] = []
take⁺ (suc n) (px ∷ pxs) = px ∷ take⁺ n pxs
------------------------------------------------------------------------
-- applyUpTo
module _ {a p} {A : Set a} {P : A → Set p} where
applyUpTo⁺₁ : ∀ f n → (∀ {i} → i < n → P (f i)) → All P (applyUpTo f n)
applyUpTo⁺₁ f zero Pf = []
applyUpTo⁺₁ f (suc n) Pf = Pf (s≤s z≤n) ∷ applyUpTo⁺₁ (f ∘ suc) n (Pf ∘ s≤s)
applyUpTo⁺₂ : ∀ f n → (∀ i → P (f i)) → All P (applyUpTo f n)
applyUpTo⁺₂ f n Pf = applyUpTo⁺₁ f n (λ _ → Pf _)
applyUpTo⁻ : ∀ f n → All P (applyUpTo f n) → ∀ {i} → i < n → P (f i)
applyUpTo⁻ f zero pxs ()
applyUpTo⁻ f (suc n) (px ∷ _) (s≤s z≤n) = px
applyUpTo⁻ f (suc n) (_ ∷ pxs) (s≤s (s≤s i<n)) =
applyUpTo⁻ (f ∘ suc) n pxs (s≤s i<n)
------------------------------------------------------------------------
-- tabulate
module _ {a p} {A : Set a} {P : A → Set p} where
tabulate⁺ : ∀ {n} {f : Fin n → A} →
(∀ i → P (f i)) → All P (tabulate f)
tabulate⁺ {zero} Pf = []
tabulate⁺ {suc n} Pf = Pf fzero ∷ tabulate⁺ (Pf ∘ fsuc)
tabulate⁻ : ∀ {n} {f : Fin n → A} →
All P (tabulate f) → (∀ i → P (f i))
tabulate⁻ {zero} pf ()
tabulate⁻ {suc n} (px ∷ _) fzero = px
tabulate⁻ {suc n} (_ ∷ pf) (fsuc i) = tabulate⁻ pf i
------------------------------------------------------------------------
-- remove
module _ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} where
─⁺ : ∀ {xs} (p : Any P xs) → All Q xs → All Q (xs Any.─ p)
─⁺ (here px) (_ ∷ qs) = qs
─⁺ (there p) (q ∷ qs) = q ∷ ─⁺ p qs
─⁻ : ∀ {xs} (p : Any P xs) → Q (Any.lookup p) → All Q (xs Any.─ p) → All Q xs
─⁻ (here px) q qs = q ∷ qs
─⁻ (there p) q (q′ ∷ qs) = q′ ∷ ─⁻ p q qs
------------------------------------------------------------------------
-- filter
module _ {a p} {A : Set a} {P : A → Set p} (P? : Decidable P) where
all-filter : ∀ xs → All P (filter P? xs)
all-filter [] = []
all-filter (x ∷ xs) with P? x
... | yes Px = Px ∷ all-filter xs
... | no _ = all-filter xs
filter⁺ : ∀ {q} {Q : A → Set q} {xs} → All Q xs → All Q (filter P? xs)
filter⁺ {xs = _} [] = []
filter⁺ {xs = x ∷ _} (Qx ∷ Qxs) with P? x
... | no _ = filter⁺ Qxs
... | yes _ = Qx ∷ filter⁺ Qxs
------------------------------------------------------------------------
-- zipWith
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
zipWith⁺ : ∀ {p} (P : C → Set p) (f : A → B → C) {xs ys} →
Pointwise (λ x y → P (f x y)) xs ys →
All P (zipWith f xs ys)
zipWith⁺ P f [] = []
zipWith⁺ P f (Pfxy ∷ Pfxsys) = Pfxy ∷ zipWith⁺ P f Pfxsys
------------------------------------------------------------------------
-- Operations for constructing lists
------------------------------------------------------------------------
-- singleton
module _ {a p} {A : Set a} {P : A → Set p} where
singleton⁻ : ∀ {x} → All P [ x ] → P x
singleton⁻ (px ∷ []) = px
------------------------------------------------------------------------
-- snoc
module _ {a p} {A : Set a} {P : A → Set p} where
∷ʳ⁺ : ∀ {xs x} → All P xs → P x → All P (xs ∷ʳ x)
∷ʳ⁺ pxs px = ++⁺ pxs (px ∷ [])
∷ʳ⁻ : ∀ {xs x} → All P (xs ∷ʳ x) → All P xs × P x
∷ʳ⁻ {xs} pxs = Prod.map₂ singleton⁻ $ ++⁻ xs pxs
------------------------------------------------------------------------
-- fromMaybe
fromMaybe⁺ : ∀ {mx} → MAll.All P mx → All P (fromMaybe mx)
fromMaybe⁺ (just px) = px ∷ []
fromMaybe⁺ nothing = []
fromMaybe⁻ : ∀ mx → All P (fromMaybe mx) → MAll.All P mx
fromMaybe⁻ (just x) (px ∷ []) = just px
fromMaybe⁻ nothing p = nothing
------------------------------------------------------------------------
-- replicate
replicate⁺ : ∀ n {x} → P x → All P (replicate n x)
replicate⁺ zero px = []
replicate⁺ (suc n) px = px ∷ replicate⁺ n px
replicate⁻ : ∀ {n x} → All P (replicate (suc n) x) → P x
replicate⁻ (px ∷ _) = px
module _ {a p} {A : Set a} {P : A → Set p} where
------------------------------------------------------------------------
-- inits
inits⁺ : ∀ {xs} → All P xs → All (All P) (inits xs)
inits⁺ [] = [] ∷ []
inits⁺ (px ∷ pxs) = [] ∷ gmap (px ∷_) (inits⁺ pxs)
inits⁻ : ∀ xs → All (All P) (inits xs) → All P xs
inits⁻ [] pxs = []
inits⁻ (x ∷ []) ([] ∷ p[x] ∷ []) = p[x]
inits⁻ (x ∷ xs@(_ ∷ _)) ([] ∷ pxs@(p[x] ∷ _)) =
singleton⁻ p[x] ∷ inits⁻ xs (All.map (drop⁺ 1) (map⁻ pxs))
------------------------------------------------------------------------
-- tails
tails⁺ : ∀ {xs} → All P xs → All (All P) (tails xs)
tails⁺ [] = [] ∷ []
tails⁺ pxxs@(_ ∷ pxs) = pxxs ∷ tails⁺ pxs
tails⁻ : ∀ xs → All (All P) (tails xs) → All P xs
tails⁻ [] pxs = []
tails⁻ (x ∷ xs) (pxxs ∷ _) = pxxs
------------------------------------------------------------------------
-- all
module _ {a} {A : Set a} (p : A → Bool) where
all⁺ : ∀ xs → T (all p xs) → All (T ∘ p) xs
all⁺ [] _ = []
all⁺ (x ∷ xs) px∷xs with Equivalence.to (T-∧ {p x}) ⟨$⟩ px∷xs
... | (px , pxs) = px ∷ all⁺ xs pxs
all⁻ : ∀ {xs} → All (T ∘ p) xs → T (all p xs)
all⁻ [] = _
all⁻ (px ∷ pxs) = Equivalence.from T-∧ ⟨$⟩ (px , all⁻ pxs)
------------------------------------------------------------------------
-- All is anti-monotone.
anti-mono : ∀ {a p} {A : Set a} {P : A → Set p} {xs ys} →
xs ⊆ ys → All P ys → All P xs
anti-mono xs⊆ys pys = All.tabulate (All.lookup pys ∘ xs⊆ys)
all-anti-mono : ∀ {a} {A : Set a} (p : A → Bool) {xs ys} →
xs ⊆ ys → T (all p ys) → T (all p xs)
all-anti-mono p xs⊆ys = all⁻ p ∘ anti-mono xs⊆ys ∘ all⁺ p _
------------------------------------------------------------------------
-- Interactions with pointwise equality
------------------------------------------------------------------------
module _ {c ℓ} (S : Setoid c ℓ) where
open Setoid S renaming (Carrier to A)
open ListEq S
respects : ∀ {p} {P : Pred A p} → P Respects _≈_ → (All P) Respects _≋_
respects p≈ [] [] = []
respects p≈ (x≈y ∷ xs≈ys) (px ∷ pxs) = p≈ x≈y px ∷ respects p≈ xs≈ys pxs
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.16
All-all = all⁻
{-# WARNING_ON_USAGE All-all
"Warning: All-all was deprecated in v0.16.
Please use all⁻ instead."
#-}
all-All = all⁺
{-# WARNING_ON_USAGE all-All
"Warning: all-All was deprecated in v0.16.
Please use all⁺ instead."
#-}
All-map = map⁺
{-# WARNING_ON_USAGE All-map
"Warning: All-map was deprecated in v0.16.
Please use map⁺ instead."
#-}
map-All = map⁻
{-# WARNING_ON_USAGE map-All
"Warning: map-All was deprecated in v0.16.
Please use map⁻ instead."
#-}
-- Version 1.0
filter⁺₁ = all-filter
{-# WARNING_ON_USAGE filter⁺₁
"Warning: filter⁺₁ was deprecated in v1.0.
Please use all-filter instead."
#-}
filter⁺₂ = filter⁺
{-# WARNING_ON_USAGE filter⁺₂
"Warning: filter⁺₂ was deprecated in v1.0.
Please use filter⁺ instead."
#-}
| {
"alphanum_fraction": 0.439957492,
"avg_line_length": 35.8855932203,
"ext": "agda",
"hexsha": "9e65c5b3ef01814f6a09e71155913c18033b1c7e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/All/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/All/Properties.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/All/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6280,
"size": 16938
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Least Common Multiple for integers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Integer.LCM where
open import Data.Integer.Base
open import Data.Integer.Divisibility
open import Data.Integer.GCD
open import Data.Nat.Base using (ℕ)
import Data.Nat.LCM as ℕ
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Definition
------------------------------------------------------------------------
lcm : ℤ → ℤ → ℤ
lcm i j = + ℕ.lcm ∣ i ∣ ∣ j ∣
------------------------------------------------------------------------
-- Properties
------------------------------------------------------------------------
i∣lcm[i,j] : ∀ i j → i ∣ lcm i j
i∣lcm[i,j] i j = ℕ.m∣lcm[m,n] ∣ i ∣ ∣ j ∣
j∣lcm[i,j] : ∀ i j → j ∣ lcm i j
j∣lcm[i,j] i j = ℕ.n∣lcm[m,n] ∣ i ∣ ∣ j ∣
lcm-least : ∀ {i j c} → i ∣ c → j ∣ c → lcm i j ∣ c
lcm-least c∣i c∣j = ℕ.lcm-least c∣i c∣j
lcm[0,i]≡0 : ∀ i → lcm 0ℤ i ≡ 0ℤ
lcm[0,i]≡0 i = cong (+_) (ℕ.lcm[0,n]≡0 ∣ i ∣)
lcm[i,0]≡0 : ∀ i → lcm i 0ℤ ≡ 0ℤ
lcm[i,0]≡0 i = cong (+_) (ℕ.lcm[n,0]≡0 ∣ i ∣)
lcm-comm : ∀ i j → lcm i j ≡ lcm j i
lcm-comm i j = cong (+_) (ℕ.lcm-comm ∣ i ∣ ∣ j ∣)
| {
"alphanum_fraction": 0.3892171344,
"avg_line_length": 29.4347826087,
"ext": "agda",
"hexsha": "8e8101132aeeccb2a0a9a03f82c7a5e6eb372cd5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Integer/LCM.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Integer/LCM.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Integer/LCM.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": 447,
"size": 1354
} |
module SortedBinaryTree where
infix 4 _≡_
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL refl #-}
open import Sec4
postulate A : Set -- XXX: E.g., Nat or Bool some base type
-- XXX: Postulates for ≤
postulate _≤_ : A → A → Prop
postulate antisym-≤ : (a b : A) → (a ≤ b) → (b ≤ a) → (a ≡ b)
postulate tot-≤ : (a b : A) → (a ≤ b) ∨ (b ≤ a)
postulate refl-≤ : (a : A) → (a ≤ a)
postulate trans-≤ : (a b c : A) → (a ≤ b) → (b ≤ a) → (a ≤ c)
-- XXX: Postulates for ≥
postulate _≥_ : A → A → Prop
postulate antisym-≥ : (a b : A) → (a ≥ b) → (b ≥ a) → (a ≡ b)
postulate tot-≥ : (a b : A) → (a ≥ b) ∨ (b ≥ a)
postulate refl-≥ : (a : A) → (a ≥ a)
postulate trans-≥ : (a b c : A) → (a ≥ b) → (b ≥ a) → (a ≥ c)
-- XXX: Definition of a binary tree.
data SortedBinaryTree (A : Set) : Set where
Leaf : SortedBinaryTree A
Node : (a : A) → (l : SortedBinaryTree A) → (r : SortedBinaryTree A) → SortedBinaryTree A
all-leq : (a : A) → (t : SortedBinaryTree A) → Prop
all-leq a₁ Leaf = ⊤
all-leq a₁ (Node a₂ l r) = (a₂ ≤ a₁) ∧ ((all-leq a₁ l) ∧ (all-leq a₁ r))
all-geq : (a : A) → (t : SortedBinaryTree A) → Prop
all-geq a₁ Leaf = ⊤
all-geq a₁ (Node a₂ l r) = (a₂ ≥ a₁) ∧ ((all-geq a₁ l) ∧ (all-geq a₁ r))
-- XXX: What is a sorted tree. A BTree is sorted, if all elements in the
-- left substree are ≥ root and all elements in the right subtree are ≤
-- root.
ordered : SortedBinaryTree A → Prop
ordered Leaf = ⊤
ordered (Node a l r) = ((all-leq a l) ∧ (all-geq a r)) ∧ ((ordered l) ∧ (ordered r))
-- XXX: Insert function for SortedBinaryTree
insert : (a : A) → SortedBinaryTree A → SortedBinaryTree A
insert x Leaf = Node x Leaf Leaf
insert x (Node a t t₁) with (tot-≤ x a)
insert x (Node a t t₁) | ora x₁ = insert x t
insert x (Node a t t₁) | orb x₁ = insert x t₁
-- XXX: Prove that the tree obtained after insertion is sorted
insert-sorted : (a : A)
→ (t : SortedBinaryTree A)
→ (p : ordered t)
→ ordered (insert a t)
insert-sorted a Leaf _ = and (and ⋆ ⋆) (and ⋆ ⋆)
insert-sorted a (Node a₁ t t₁) (and (and x x1) (and x2 x3)) with (tot-≤ a a₁)
insert-sorted a (Node a₁ t t₁) (and (and p1 p2) (and p3 p4)) | ora w = insert-sorted a t p3
insert-sorted a (Node a₁ t t₁) (and (and p1 p2) (and p3 p4)) | orb w = insert-sorted a t₁ p4
-- XXX: Proof carrying code
insert' : (a : A)
→ (t : SortedBinaryTree A)
→ (p : ordered t)
→ Exists (SortedBinaryTree A) (λ t' → ordered t')
insert' a t p = [ insert a t , insert-sorted a t p ]
-- XXX: Write Proof that delete works.
-- XXX: Write a version with record and setoid carrying the ≤, etc
| {
"alphanum_fraction": 0.5594681998,
"avg_line_length": 37.1066666667,
"ext": "agda",
"hexsha": "32a286eb5cf94a3e1806aaed1f0d332b145f782f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "amal029/agda-tutorial-dybjer",
"max_forks_repo_path": "SortedBinaryTree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "amal029/agda-tutorial-dybjer",
"max_issues_repo_path": "SortedBinaryTree.agda",
"max_line_length": 94,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "amal029/agda-tutorial-dybjer",
"max_stars_repo_path": "SortedBinaryTree.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:52:30.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:52:30.000Z",
"num_tokens": 1066,
"size": 2783
} |
module Pi where
open import Agda.Builtin.Equality
using (_≡_; refl)
f
: {A : Set}
→ {x y : A}
→ (z w : A)
→ x ≡ z
→ z ≡ x
f _ _ refl
= refl
| {
"alphanum_fraction": 0.5031847134,
"avg_line_length": 10.4666666667,
"ext": "agda",
"hexsha": "fc36dacbfe39f51cb0de88d1538000ab6b286419",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msuperdock/agda-unused",
"max_forks_repo_path": "data/expression/Pi.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "msuperdock/agda-unused",
"max_issues_repo_path": "data/expression/Pi.agda",
"max_line_length": 33,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msuperdock/agda-unused",
"max_stars_repo_path": "data/expression/Pi.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z",
"num_tokens": 69,
"size": 157
} |
module Prelude.Bool.Properties where
open import Prelude.Equality
open import Prelude.Bool
open import Prelude.Decidable
open import Prelude.Empty
open import Prelude.Variables
de-morg-neg-conj : (a b : Bool) → not (a && b) ≡ (not a || not b)
de-morg-neg-conj true true = refl
de-morg-neg-conj false true = refl
de-morg-neg-conj true false = refl
de-morg-neg-conj false false = refl
de-morg-neg-disj : (a b : Bool) → not (a || b) ≡ (not a && not b)
de-morg-neg-disj true true = refl
de-morg-neg-disj false true = refl
de-morg-neg-disj true false = refl
de-morg-neg-disj false false = refl
x||true : (x : Bool) → (x || true) ≡ true
x||true true = refl
x||true false = refl
x&&false : (x : Bool) → (x && false) ≡ false
x&&false true = refl
x&&false false = refl
IsTrue⇒≡ : IsTrue x → x ≡ true
IsTrue⇒≡ true = refl
IsFalse⇒≡ : IsFalse x → x ≡ false
IsFalse⇒≡ false = refl
not[x]≡false⇒x≡true : not x ≡ false → x ≡ true
not[x]≡false⇒x≡true {true} _ = refl
not[x]≡false⇒x≡true {false} ()
not[x]≡true⇒x≡false : not x ≡ true → x ≡ false
not[x]≡true⇒x≡false {true} ()
not[x]≡true⇒x≡false {false} _ = refl
-- Properties of ==? --
module _ {a} {A : Set a} {{EqA : Eq A}} where
==?-reflexive : (x : A) → (x ==? x) ≡ true
==?-reflexive x with x == x
...| yes refl = refl
...| no notEq = ⊥-elim (notEq refl)
≡⇒==? : {x y : A} → (x ≡ y) → (x ==? y) ≡ true
≡⇒==? {x = x} {y = y} refl with x == y
...| yes refl = refl
...| no a≢b = ⊥-elim (a≢b refl)
≢⇒==? : {x y : A} → x ≢ y → (x ==? y) ≡ false
≢⇒==? {x = x} {y = y} x≢y with x == y
...| yes x≡y = ⊥-elim (x≢y x≡y)
...| no _ = refl
==?⇒≡ : {x y : A} → (x ==? y) ≡ true → x ≡ y
==?⇒≡ {x = x} {y = y} ==?≡true
with x == y
...| yes x≡y = x≡y
...| no x≢y with (≢⇒==? x≢y) | ==?≡true
...| _ | ()
==?≡false⇒≢ : {a b : A} → (a ==? b) ≡ false → a ≢ b
==?≡false⇒≢ {a = a} {b = b} ==?≡false
with a == b
...| no ¬eq = ¬eq
...| yes eq with ≡⇒==? | ==?≡false
...| _ | ()
| {
"alphanum_fraction": 0.5239307536,
"avg_line_length": 26.1866666667,
"ext": "agda",
"hexsha": "f07548471bc03c37ac65fa70164f84978029dd53",
"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": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Prelude/Bool/Properties.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"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": "t-more/agda-prelude",
"max_issues_repo_path": "src/Prelude/Bool/Properties.agda",
"max_line_length": 65,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "t-more/agda-prelude",
"max_stars_repo_path": "src/Prelude/Bool/Properties.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": 911,
"size": 1964
} |
module Integer where
open import Data.Nat
open import Data.Nat.Properties
open import Data.Empty
open import Relation.Binary.PropositionalEquality
data ℤ₃ : Set where
ℤ₊ : ℕ → ℤ₃
ℤ₀ : ℤ₃
ℤ₋ : ℕ → ℤ₃
ℤ₊-injective : ∀ {m n} → ℤ₊ m ≡ ℤ₊ n → m ≡ n
ℤ₊-injective refl = refl
ℤ₋-injective : ∀ {m n} → ℤ₋ m ≡ ℤ₋ n → m ≡ n
ℤ₋-injective refl = refl
data ℕ² : Set where
_─_ : ℕ → ℕ → ℕ²
ℕ²-≡₊ : ∀ {a₊ a₋ b₊ b₋} → (a₊ ─ a₋) ≡ (b₊ ─ b₋) → a₊ ≡ b₊
ℕ²-≡₊ refl = refl
ℕ²-≡₋ : ∀ {a₊ a₋ b₊ b₋} → (a₊ ─ a₋) ≡ (b₊ ─ b₋) → a₋ ≡ b₋
ℕ²-≡₋ refl = refl
toℕ² : ℤ₃ → ℕ²
toℕ² (ℤ₊ n) = suc n ─ zero
toℕ² ℤ₀ = zero ─ zero
toℕ² (ℤ₋ n) = zero ─ suc n
toℤ₃ : ℕ² → ℤ₃
toℤ₃ (zero ─ zero) = ℤ₀
toℤ₃ (zero ─ suc n₋) = ℤ₋ n₋
toℤ₃ (suc n₊ ─ zero) = ℤ₊ n₊
toℤ₃ (suc n₊ ─ suc n₋) = toℤ₃ (n₊ ─ n₋)
data Dec (A : Set) : Set where
yes : A → Dec A
no : (A → ⊥) → Dec A
ℕ≡? : (m n : ℕ) → Dec (m ≡ n)
ℕ≡? zero zero = yes refl
ℕ≡? zero (suc n) = no (λ ())
ℕ≡? (suc m) zero = no (λ ())
ℕ≡? (suc m) (suc n) with ℕ≡? m n
... | yes m≡n = yes (cong suc m≡n)
... | no ¬m≡n = no λ sm≡sn → ¬m≡n (suc-injective sm≡sn)
ℤ₃≡? : (a b : ℤ₃) → Dec (a ≡ b)
ℤ₃≡? (ℤ₊ m) (ℤ₊ n) with ℕ≡? m n
... | yes m≡n = yes (cong ℤ₊ m≡n)
... | no ¬m≡n = no λ ℤ₊m≡ℤ₊n → ¬m≡n (ℤ₊-injective ℤ₊m≡ℤ₊n)
ℤ₃≡? (ℤ₊ _) ℤ₀ = no (λ ())
ℤ₃≡? (ℤ₊ _) (ℤ₋ _) = no (λ ())
ℤ₃≡? ℤ₀ (ℤ₊ _) = no (λ ())
ℤ₃≡? ℤ₀ ℤ₀ = yes refl
ℤ₃≡? ℤ₀ (ℤ₋ _) = no (λ ())
ℤ₃≡? (ℤ₋ _) (ℤ₊ _) = no (λ ())
ℤ₃≡? (ℤ₋ _) ℤ₀ = no (λ ())
ℤ₃≡? (ℤ₋ m) (ℤ₋ n) with ℕ≡? m n
... | yes m≡n = yes (cong ℤ₋ m≡n)
... | no ¬m≡n = no λ ℤ₋m≡ℤ₋n → ¬m≡n (ℤ₋-injective ℤ₋m≡ℤ₋n)
ℕ²≡? : (a b : ℕ²) → Dec (a ≡ b)
ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) with ℕ≡? a₊ b₊
ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) | yes refl with ℕ≡? a₋ b₋
ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) | yes refl | yes refl =
yes refl
ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) | yes refl | no ¬a₋≡b₋ =
no (λ a≡b → ¬a₋≡b₋ (ℕ²-≡₋ a≡b))
ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) | no ¬a₊≡b₊ =
no λ a≡b → ¬a₊≡b₊ (ℕ²-≡₊ a≡b)
_≃_ : ℕ² → ℕ² → Set
(a₊ ─ a₋) ≃ (b₊ ─ b₋) = a₊ + b₋ ≡ a₋ + b₊
≃? : (a b : ℕ²) → Dec (a ≃ b)
≃? (a₊ ─ a₋) (b₊ ─ b₋) = ℕ≡? (a₊ + b₋) (a₋ + b₊)
_+₂_ : ℕ² → ℕ² → ℕ²
(a₊ ─ a₋) +₂ (b₊ ─ b₋) = (a₊ + b₊) ─ (a₋ + b₋)
{-
≃-cong : {A : Set} {a b : ℕ²} (f : ℕ² → ℕ²) → a ≃ b → f a ≃ f b
≃-cong f a≃b = {!!}
-}
drop-neg : ℕ² → ℕ²
drop-neg (a₊ ─ _) = (a₊ ─ zero)
3-5≃2-4 : (3 ─ 5) ≃ (2 ─ 4)
3-5≃2-4 = refl
_+₃_ : ℤ₃ → ℤ₃ → ℤ₃
a +₃ b = toℤ₃ (toℕ² a +₂ toℕ² b)
| {
"alphanum_fraction": 0.429787234,
"avg_line_length": 23.9795918367,
"ext": "agda",
"hexsha": "1ae06100f2389d3b0d94f5d54df0f804372a73b3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-28T12:49:47.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-28T12:49:47.000Z",
"max_forks_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "iblech/agda-quotients",
"max_forks_repo_path": "src/Integer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"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": "iblech/agda-quotients",
"max_issues_repo_path": "src/Integer.agda",
"max_line_length": 63,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "iblech/agda-quotients",
"max_stars_repo_path": "src/Integer.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-29T13:10:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-29T13:10:27.000Z",
"num_tokens": 1654,
"size": 2350
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Properties where
open import Level
open import Data.Product using (Σ; _,_; -,_; proj₂; uncurry)
open import Function using (_$_)
open import Categories.Adjoint using (_⊣_; Adjoint; Hom-NI′⇒Adjoint)
open import Categories.Adjoint.RAPL public
open import Categories.Category using (Category; _[_,_])
open import Categories.Category.Product using (_⁂_; _⁂ⁿⁱ_)
open import Categories.Category.Construction.Comma using (CommaObj; Comma⇒; _↙_)
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Hom
open import Categories.Functor.Construction.Constant
open import Categories.Functor.Construction.LiftSetoids
open import Categories.Functor.Properties
open import Categories.Functor.Continuous
open import Categories.Functor.Cocontinuous
open import Categories.Functor.Bifunctor
open import Categories.Functor.Bifunctor.Properties
open import Categories.NaturalTransformation
open import Categories.NaturalTransformation.Properties
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism; _≃_; _ⓘₕ_; _ⓘˡ_; module ≃)
open import Categories.NaturalTransformation.NaturalIsomorphism.Properties
open import Categories.Monad
open import Categories.Monad.Duality
open import Categories.Comonad
open import Categories.Morphism.Universal
open import Categories.Yoneda
import Categories.Yoneda.Properties as YP
import Categories.Diagram.Colimit as Col
import Categories.Diagram.Duality as Duality
import Categories.Morphism as Mor
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
C D E J : Category o ℓ e
-- if the left adjoint functor is a partial application of bifunctor, then it uniquely
-- determines a bifunctor compatible with the right adjoint functor.
module _ {C : Category o ℓ e}
(L : Bifunctor C E D) {R : ∀ (X : Category.Obj E) → Functor D C}
(LR : ∀ (X : Category.Obj E) → appʳ L X ⊣ R X) where
private
module C = Category C
module D = Category D
module E = Category E
module L = Functor L
module R X = Functor (R X)
module LR X = Adjoint (LR X)
open C
F′ : ∀ {A X B Y} f g → R.F₀ A X ⇒ R.F₀ B Y
F′ {A} {X} {B} {Y} f g = LR.Ladjunct B (LR.counit.η A Y D.∘ L.F₁ (R.F₁ A g , f))
-- R.F₁ B (LR.counit.η A Y) ∘ R.F₁ B (L.F₁ (R.F₁ A g , f)) ∘ LR.unit.η B (R.F₀ A X)
commute′ : ∀ {A B X} (f : A E.⇒ B) → LR.counit.η A X D.∘ L.F₁ (F′ f D.id , E.id) D.≈ LR.counit.η B X D.∘ L.F₁ (C.id , f)
commute′ {A} {B} {X} f = begin
LR.counit.η A X D.∘ L.F₁ (F′ f D.id , E.id) ≈⟨ LR.RLadjunct≈id A ⟩
LR.counit.η B X D.∘ L.F₁ (R.F₁ B D.id , f) ≈⟨ refl ⟩∘⟨ L.F-resp-≈ (R.identity B , E.Equiv.refl) ⟩
LR.counit.η B X D.∘ L.F₁ (C.id , f) ∎
where open D.HomReasoning
open HomReasoning
decompose₁ : ∀ {A B X Y} {f : A E.⇒ B} {g : X D.⇒ Y} → F′ f g ≈ R.F₁ A g ∘ F′ f D.id
decompose₁ {A} {B} {X} {Y} {f} {g} = begin
F′ f g
≈⟨ R.F-resp-≈ A (D.∘-resp-≈ʳ [ L ]-decompose₁) ⟩∘⟨refl ⟩
R.F₁ A (LR.counit.η B Y D.∘ L.F₁ (R.F₁ B g , E.id) D.∘ L.F₁ (C.id , f)) ∘ LR.unit.η A (R.F₀ B X)
≈⟨ R.F-resp-≈ A (pullˡ (LR.counit.commute B g)) ⟩∘⟨refl ⟩
R.F₁ A ((g D.∘ LR.counit.η B X) D.∘ L.F₁ (C.id , f)) ∘ LR.unit.η A (R.F₀ B X)
≈˘⟨ R.F-resp-≈ A (pushʳ (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity B , E.Equiv.refl)))) ⟩∘⟨refl ⟩
R.F₁ A (g D.∘ LR.counit.η B X D.∘ L.F₁ (R.F₁ B D.id , f)) ∘ LR.unit.η A (R.F₀ B X)
≈⟨ R.homomorphism A ⟩∘⟨refl ⟩
(R.F₁ A g ∘ R.F₁ A (LR.counit.η B X D.∘ L.F₁ (R.F₁ B D.id , f))) ∘ LR.unit.η A (R.F₀ B X)
≈⟨ assoc ⟩
R.F₁ A g ∘ F′ f D.id
∎
where open MR D
decompose₂ : ∀ {A B X Y} {f : A E.⇒ B} {g : X D.⇒ Y} → F′ f g ≈ F′ f D.id ∘ R.F₁ B g
decompose₂ {A} {B} {X} {Y} {f} {g} = begin
F′ f g
≈⟨ R.F-resp-≈ A (D.∘-resp-≈ʳ [ L ]-decompose₂) ⟩∘⟨refl ⟩
R.F₁ A (LR.counit.η B Y D.∘ L.F₁ (C.id , f) D.∘ L.F₁ (R.F₁ B g , E.id)) ∘ LR.unit.η A (R.F₀ B X)
≈˘⟨ R.F-resp-≈ A (pushˡ (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity B , E.Equiv.refl)))) ⟩∘⟨refl ⟩
R.F₁ A ((LR.counit.η B Y D.∘ L.F₁ (R.F₁ B D.id , f)) D.∘ L.F₁ (R.F₁ B g , E.id)) ∘ LR.unit.η A (R.F₀ B X)
≈⟨ R.homomorphism A ⟩∘⟨refl ⟩
(R.F₁ A (LR.counit.η B Y D.∘ L.F₁ (R.F₁ B D.id , f)) ∘ R.F₁ A (L.F₁ (R.F₁ B g , E.id))) ∘ LR.unit.η A (R.F₀ B X)
≈˘⟨ MR.pushʳ C (LR.unit.commute A (R.F₁ B g)) ⟩
R.F₁ A (LR.counit.η B Y D.∘ L.F₁ (R.F₁ B D.id , f)) ∘ LR.unit.η A (R.F₀ B Y) ∘ R.F₁ B g
≈˘⟨ assoc ⟩
F′ f D.id ∘ R.F₁ B g
∎
where open MR D
swap : ∀ {A B X Y} {f : A E.⇒ B} {g : X D.⇒ Y} → R.F₁ A g ∘ F′ f D.id ≈ F′ f D.id ∘ R.F₁ B g
swap = trans (⟺ decompose₁) decompose₂
commute″ : ∀ {X Y Z A} {f : Y E.⇒ Z} {g : X E.⇒ Y} → F′ (f E.∘ g) (D.id {A}) ≈ F′ g D.id ∘ F′ f D.id
commute″ {X} {Y} {Z} {A} {f} {g} = begin
F′ (f E.∘ g) D.id
≈⟨ R.F-resp-≈ X (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity Z , E.Equiv.refl))) ⟩∘⟨refl ⟩
R.F₁ X (LR.counit.η Z A D.∘ L.F₁ (C.id , f E.∘ g)) ∘ LR.unit.η X (R.F₀ Z A)
≈⟨ R.F-resp-≈ X (D.∘-resp-≈ʳ (Functor.homomorphism (appˡ L (R.F₀ Z A)))) ⟩∘⟨refl ⟩
R.F₁ X (LR.counit.η Z A D.∘ L.F₁ (C.id , f) D.∘ L.F₁ (C.id , g)) ∘ LR.unit.η X (R.F₀ Z A)
≈˘⟨ R.F-resp-≈ X (MR.pushˡ D (commute′ f)) ⟩∘⟨refl ⟩
R.F₁ X ((LR.counit.η Y A D.∘ L.F₁ (F′ f D.id , E.id)) D.∘ L.F₁ (C.id , g)) ∘ LR.unit.η X (R.F₀ Z A)
≈˘⟨ R.F-resp-≈ X (MR.pushʳ D [ L ]-commute) ⟩∘⟨refl ⟩
R.F₁ X (LR.counit.η Y A D.∘ L.F₁ (C.id , g) D.∘ L.F₁ (F′ f D.id , E.id)) ∘ LR.unit.η X (R.F₀ Z A)
≈˘⟨ R.F-resp-≈ X D.assoc ⟩∘⟨refl ⟩
R.F₁ X ((LR.counit.η Y A D.∘ L.F₁ (C.id , g)) D.∘ L.F₁ (F′ f D.id , E.id)) ∘ LR.unit.η X (R.F₀ Z A)
≈⟨ R.homomorphism X ⟩∘⟨refl ⟩
(R.F₁ X (LR.counit.η Y A D.∘ L.F₁ (C.id , g)) ∘ R.F₁ X (L.F₁ (F′ f D.id , E.id))) ∘ LR.unit.η X (R.F₀ Z A)
≈˘⟨ MR.pushʳ C (LR.unit.commute X (F′ f D.id)) ⟩
R.F₁ X (LR.counit.η Y A D.∘ L.F₁ (C.id , g)) ∘ LR.unit.η X (R.F₀ Y A) ∘ F′ f D.id
≈˘⟨ R.F-resp-≈ X (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity Y , E.Equiv.refl))) ⟩∘⟨ refl ⟩∘⟨ refl ⟩
R.F₁ X (LR.counit.η Y A D.∘ L.F₁ (R.F₁ Y D.id , g)) ∘ LR.unit.η X (R.F₀ Y A) ∘ F′ f D.id
≈˘⟨ assoc ⟩
F′ g D.id ∘ F′ f D.id
∎
induced-bifunctorʳ : Bifunctor E.op D C
induced-bifunctorʳ = record
{ F₀ = uncurry R.F₀
; F₁ = uncurry F′
; identity = λ where
{e , d} →
let open MR D
in begin
F′ E.id D.id
≈⟨ R.F-resp-≈ e (D.∘-resp-≈ʳ (L.F-resp-≈ (R.identity e , E.Equiv.refl))) ⟩∘⟨ refl ⟩
R.F₁ e (LR.counit.η e d D.∘ L.F₁ (C.id , E.id)) ∘ LR.unit.η e (R.F₀ e d)
≈⟨ R.F-resp-≈ e (elimʳ L.identity) ⟩∘⟨ refl ⟩
R.F₁ e (LR.counit.η e d) ∘ LR.unit.η e (R.F₀ e d)
≈⟨ LR.zag e ⟩
C.id
∎
; homomorphism = λ where
{A , X} {B , Y} {W , Z} {f , h} {g , i} →
let open MR C
in begin
F′ (f E.∘ g) (i D.∘ h)
≈⟨ decompose₁ ⟩
R.F₁ W (i D.∘ h) ∘ F′ (f E.∘ g) D.id
≈˘⟨ center⁻¹ (⟺ (R.homomorphism W)) (⟺ commute″) ⟩
R.F₁ W i ∘ (R.F₁ W h ∘ F′ g D.id) ∘ F′ f D.id
≈˘⟨ center (⟺ swap) ⟩
(R.F₁ W i ∘ F′ g D.id) ∘ R.F₁ B h ∘ F′ f D.id
≈˘⟨ decompose₁ ⟩∘⟨ decompose₁ ⟩
F′ g i ∘ F′ f h
∎
; F-resp-≈ = λ where
{A , X} {B , Y} (eq , eq′) →
∘-resp-≈ˡ (R.F-resp-≈ B (D.∘-resp-≈ʳ (L.F-resp-≈ (R.F-resp-≈ A eq′ , eq))))
}
-- LAPC: left adjoint preserves colimits.
module _ {L : Functor C D} {R : Functor D C} (L⊣R : L ⊣ R) (F : Functor J C) where
private
module F = Functor F
open Col
lapc : Colimit F → Colimit (L ∘F F)
lapc col = Duality.coLimit⇒Colimit D (rapl (Adjoint.op L⊣R) F.op (Duality.Colimit⇒coLimit C col))
-- adjoint functors induce monads and comonads
module _ {L : Functor C D} {R : Functor D C} (L⊣R : L ⊣ R) where
private
module C = Category C
module D = Category D
module L = Functor L
module R = Functor R
open Adjoint L⊣R
rapl′ : ∀ {o ℓ e} → Continuous o ℓ e R
rapl′ lim = rapl L⊣R _ lim , Mor.≅.refl C
lapc′ : ∀ {o ℓ e} → Cocontinuous o ℓ e L
lapc′ col = lapc L⊣R _ col , Mor.≅.refl D
adjoint⇒monad : Monad C
adjoint⇒monad = record
{ F = R ∘F L
; η = unit
; μ = record
{ η = μ′.η
; commute = μ′.commute
; sym-commute = μ′.sym-commute
}
; assoc = [ R ]-resp-square (counit.commute _)
; sym-assoc = [ R ]-resp-square (counit.sym-commute _)
; identityˡ = λ {X} → begin
μ′.η X ∘ R.F₁ (L.F₁ (unit.η X)) ≈⟨ [ R ]-resp-∘ zig ⟩
R.F₁ D.id ≈⟨ R.identity ⟩
C.id ∎
; identityʳ = zag
}
where open C
open HomReasoning
μ′ : NaturalTransformation (R ∘F (L ∘F R) ∘F L) (R ∘F Categories.Functor.id ∘F L)
μ′ = R ∘ˡ counit ∘ʳ L
module μ′ = NaturalTransformation μ′
module _ {L : Functor C D} {R : Functor D C} (L⊣R : L ⊣ R) where
open Adjoint L⊣R
adjoint⇒comonad : Comonad D
adjoint⇒comonad = coMonad⇒Comonad D (adjoint⇒monad op)
-- adjoint functors are the same as universal morphisms
module _ {R : Functor D C} where
private
module C = Category C
module D = Category D
module R = Functor R
adjoint⇒universalMorphisms : ∀ {L : Functor C D} → L ⊣ R → ∀ (X : C.Obj) → UniversalMorphism X R
adjoint⇒universalMorphisms {L} L⊣R X = record
{ initial = record
{ ⊥ = record { f = unit.η X }
; ! =
let open C.HomReasoning
in record { commute = LRadjunct≈id ○ ⟺ C.identityʳ }
; !-unique = λ {A} g →
let open D.HomReasoning
in -, (begin
Radjunct (f A) ≈⟨ Radjunct-resp-≈ (C.Equiv.sym (C.Equiv.trans (commute g) (C.identityʳ {f = f A}))) ⟩
Radjunct (Ladjunct (h g)) ≈⟨ RLadjunct≈id ⟩
h g ∎)
}
}
where module L = Functor L
open Adjoint L⊣R
open Comma⇒
open CommaObj
universalMophisms⇒adjoint : (∀ (X : C.Obj) → UniversalMorphism X R) → Σ (Functor C D) (λ L → L ⊣ R)
universalMophisms⇒adjoint umors = L , record
{ unit = ntHelper record
{ η = λ c → f (umors.⊥ c)
; commute = λ i → let open C.HomReasoning in ⟺ (commute (⊥X⇒⊥Y i) ○ C.identityʳ )
}
; counit = ntHelper record
{ η = ε
; commute = λ {X Y} i →
let open C.HomReasoning
open MR C
in proj₂ $ umors.!-unique₂ (R.F₀ X)
{record { f = R.F₁ i }}
(record
{ h = ε Y D.∘ L₁ (R.F₁ i)
; commute = begin
R.F₁ (ε Y D.∘ L₁ (R.F₁ i)) C.∘ f (⊥Rd X) ≈⟨ R.homomorphism ⟩∘⟨refl ⟩
(R.F₁ (ε Y) C.∘ R.F₁ (L₁ (R.F₁ i))) C.∘ f (⊥Rd X) ≈⟨ pullʳ (commute (⊥X⇒⊥Y (R.F₁ i)) ○ C.identityʳ) ⟩
R.F₁ (ε Y) C.∘ f (⊥Rd Y) C.∘ R.F₁ i ≈⟨ cancelˡ (commute (⊥Rd⇒id Y) ○ C.identityˡ) ⟩
R.F₁ i ≈˘⟨ C.identityʳ ⟩
R.F₁ i C.∘ C.id ∎
})
(record
{ h = i D.∘ ε X
; commute = begin
R.F₁ (i D.∘ ε X) C.∘ f (⊥Rd X) ≈⟨ R.homomorphism ⟩∘⟨refl ⟩
(R.F₁ i C.∘ R.F₁ (ε X)) C.∘ f (⊥Rd X) ≈⟨ cancelʳ (commute (⊥Rd⇒id X) ○ C.identityˡ) ⟩
R.F₁ i ≈˘⟨ C.identityʳ ⟩
R.F₁ i C.∘ C.id ∎
})
}
; zig = λ {c} →
let open C.HomReasoning
open MR C
α = f (umors.⊥ c)
in proj₂ $ umors.!-unique₂ c
{record { f = α }}
(record
{ h = ε (L₀ c) D.∘ L₁ α
; commute = begin
R.F₁ (ε (L₀ c) D.∘ L₁ α) C.∘ α ≈⟨ R.homomorphism ⟩∘⟨refl ⟩
(R.F₁ (ε (L₀ c)) C.∘ R.F₁ (L₁ α)) C.∘ α ≈⟨ pullʳ (commute (⊥X⇒⊥Y α) ○ C.identityʳ) ⟩
R.F₁ (ε (L₀ c)) C.∘ f (⊥Rd (L₀ c)) C.∘ α ≈⟨ cancelˡ (commute (⊥Rd⇒id (L₀ c)) ○ C.identityˡ) ⟩
α ≈˘⟨ C.identityʳ ⟩
α C.∘ C.id ∎
})
(record
{ h = D.id
; commute = C.∘-resp-≈ˡ R.identity ○ id-comm-sym
})
; zag = λ {d} → C.Equiv.trans (commute (⊥Rd⇒id d)) C.identityˡ
}
where module umors X = UniversalMorphism (umors X)
open CommaObj
open Comma⇒
commaObj∘g : ∀ {X Y} → X C.⇒ Y → CommaObj (const! X) R
commaObj∘g {X} {Y} g = record { f = f (umors.⊥ Y) C.∘ g }
⊥X⇒⊥Y : ∀ {X Y} (g : X C.⇒ Y) → (X ↙ R) [ umors.⊥ X , commaObj∘g g ]
⊥X⇒⊥Y {X} {Y} g = umors.! X {commaObj∘g g}
L₀ : ∀ X → D.Obj
L₀ X = β (umors.⊥ X)
L₁ : ∀ {X Y} → X C.⇒ Y → β (umors.⊥ X) D.⇒ β (umors.⊥ Y)
L₁ {X} {Y} g = h (⊥X⇒⊥Y g)
L : Functor C D
L = record
{ F₀ = L₀
; F₁ = L₁
; identity = λ {X} → proj₂ $ umors.!-unique X $
record { commute = elimˡ R.identity ○ ⟺ C.identityʳ ○ ⟺ C.identityʳ }
; homomorphism = λ {X Y Z} {i j} → proj₂ $ umors.!-unique₂ X (umors.! X) $
record { commute = begin
R.F₁ (h (umors.! Y) D.∘ h (umors.! X)) C.∘ f (umors.⊥ X)
≈⟨ (C.∘-resp-≈ˡ R.homomorphism) ○ C.assoc ⟩
R.F₁ (h (umors.! Y)) C.∘ R.F₁ (h (umors.! X)) C.∘ f (umors.⊥ X)
≈⟨ (C.∘-resp-≈ʳ (commute (⊥X⇒⊥Y i) ○ C.identityʳ)) ○ C.sym-assoc ⟩
(R.F₁ (h (umors.! Y)) C.∘ f (umors.⊥ Y)) C.∘ i
≈⟨ pushˡ (commute (⊥X⇒⊥Y j) ○ C.identityʳ) ⟩
f (umors.⊥ Z) C.∘ j C.∘ i
≈˘⟨ C.identityʳ ⟩
(f (umors.⊥ Z) C.∘ j C.∘ i) C.∘ C.id
∎ }
; F-resp-≈ = λ {X} eq → proj₂ $ umors.!-unique₂ X (umors.! X) $
record { commute = commute (umors.! X) ○ C.∘-resp-≈ˡ (C.∘-resp-≈ʳ (⟺ eq)) }
}
where open C.HomReasoning
open MR C
module L = Functor L
⊥Rd : (d : D.Obj) → CommaObj (const! (R.F₀ d)) R
⊥Rd d = umors.⊥ (R.F₀ d)
⊥Rd⇒id : (d : D.Obj) → (R.F₀ d ↙ R) [ ⊥Rd d , record { f = C.id } ]
⊥Rd⇒id d = umors.! (R.F₀ d) {record { f = C.id }}
ε : ∀ d → L₀ (R.F₀ d) D.⇒ d
ε d = h (⊥Rd⇒id d)
-- adjoint functors of a functor are isomorphic
module _ (L : Functor C D) where
open YP C
R≃R′ : ∀ {R R′} → L ⊣ R → L ⊣ R′ → R ≃ R′
R≃R′ {R} {R′} L⊣R L⊣R′ = yoneda-NI R R′ (unlift-≃ Hom[-,R-]≃Hom[-,R′-])
where module ⊣₁ = Adjoint L⊣R
module ⊣₂ = Adjoint L⊣R′
Hom[-,R-]≃Hom[-,R′-] : ⊣₁.Hom[-,R-]′ ≃ ⊣₂.Hom[-,R-]′
Hom[-,R-]≃Hom[-,R′-] = ≃.trans (≃.sym ⊣₁.Hom-NI) ⊣₂.Hom-NI
module _ {R : Functor D C} where
L≃L′ : ∀ {L L′} → L ⊣ R → L′ ⊣ R → L ≃ L′
L≃L′ L⊣R L′⊣R = NaturalIsomorphism.op L′≃Lᵒᵖ
where module ⊣₁ = Adjoint L⊣R
module ⊣₂ = Adjoint L′⊣R
L′≃Lᵒᵖ = R≃R′ (Functor.op R) ⊣₂.op ⊣₁.op
-- adjoint functors are preserved by natural isomorphisms
module _ {L L′ : Functor C D} {R R′ : Functor D C} where
private
module C = Category C
module D = Category D
module L = Functor L
module L′ = Functor L′
module R = Functor R
module R′ = Functor R′
⊣×≃⇒⊣ : L ⊣ R → L ≃ L′ → R ≃ R′ → L′ ⊣ R′
⊣×≃⇒⊣ L⊣R L≃L′ R≃R′ = Hom-NI′⇒Adjoint (≃.trans (LiftSetoids _ _ ⓘˡ Hom[L′-,-]≃Hom[L-,-])
(≃.trans Hom-NI
(LiftSetoids _ _ ⓘˡ Hom[-,R-]≃Hom[-,R′-])))
where open Adjoint L⊣R
Hom[L′-,-]≃Hom[L-,-] : Hom[ D ][-,-] ∘F (L′.op ⁂ idF) ≃ Hom[ D ][-,-] ∘F (L.op ⁂ idF)
Hom[L′-,-]≃Hom[L-,-] = Hom[ D ][-,-] ⓘˡ (NaturalIsomorphism.op L≃L′ ⁂ⁿⁱ ≃.refl)
Hom[-,R-]≃Hom[-,R′-] : Hom[ C ][-,-] ∘F (idF ⁂ R) ≃ Hom[ C ][-,-] ∘F (idF ⁂ R′)
Hom[-,R-]≃Hom[-,R′-] = Hom[ C ][-,-] ⓘˡ (≃.refl ⁂ⁿⁱ R≃R′)
| {
"alphanum_fraction": 0.4800982801,
"avg_line_length": 42.7296587927,
"ext": "agda",
"hexsha": "57107e0b353ff3c3c6fbb6cb999b59565bef3198",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Adjoint/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Adjoint/Properties.agda",
"max_line_length": 124,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Adjoint/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7214,
"size": 16280
} |
------------------------------------------------------------------------
-- An example
------------------------------------------------------------------------
module RecursiveDescent.Hybrid.Mixfix.Example where
open import Data.Vec using ([]; _∷_; [_])
open import Data.List renaming ([_] to L[_])
open import Data.Product using (∃₂; ,_)
open import Data.Nat using (zero; suc)
open import Data.Fin using (#_)
open import Data.String
open import Data.Function using (_∘_)
open import Relation.Binary.PropositionalEquality
open import RecursiveDescent.Hybrid.Mixfix.Expr
open import RecursiveDescent.Hybrid.Mixfix.Fixity
import RecursiveDescent.Hybrid.Mixfix as Mixfix
------------------------------------------------------------------------
-- Operators
atom : Operator closed 0
atom = operator ("•" ∷ [])
• : Expr
• = ⟪ atom ∙ [] ⟫
parens : Operator closed 1
parens = operator ("(" ∷ ")" ∷ [])
⟦_⟧ : Expr -> Expr
⟦ e ⟧ = ⟪ parens ∙ [ e ] ⟫
plus : Operator (infx left) 0
plus = operator ("+" ∷ [])
_+_ : Expr -> Expr -> Expr
e₁ + e₂ = e₁ ⟨ plus ∙ [] ⟩ e₂
minus : Operator (infx left) 0
minus = operator ("-" ∷ [])
_-_ : Expr -> Expr -> Expr
e₁ - e₂ = e₁ ⟨ minus ∙ [] ⟩ e₂
times : Operator (infx left) 0
times = operator ("*" ∷ [])
_*_ : Expr -> Expr -> Expr
e₁ * e₂ = e₁ ⟨ times ∙ [] ⟩ e₂
comma : Operator (infx left) 0
comma = operator ("," ∷ [])
_,_ : Expr -> Expr -> Expr
e₁ , e₂ = e₁ ⟨ comma ∙ [] ⟩ e₂
wellTyped : Operator postfx 1
wellTyped = operator ("⊢" ∷ "∶" ∷ [])
_⊢_∶ : Expr -> Expr -> Expr
e₁ ⊢ e₂ ∶ = e₁ ⟨ wellTyped ∙ [ e₂ ] ⟫
------------------------------------------------------------------------
-- Precedence graph
prec : List (∃₂ Operator) -> PrecedenceGraph -> PrecedenceTree
prec ops = precedence (\fix -> gfilter (hasFixity fix) ops)
g : PrecedenceGraph
g = wt ∷ c ∷ pm ∷ t ∷ ap ∷ []
where
ap = prec ((, , atom) ∷ (, , parens) ∷ []) []
t = prec ((, , times) ∷ []) (ap ∷ [])
pm = prec ((, , plus) ∷ (, , minus) ∷ []) (t ∷ ap ∷ [])
c = prec ((, , comma) ∷ []) (pm ∷ t ∷ ap ∷ [])
wt = prec ((, , wellTyped) ∷ []) (c ∷ ap ∷ [])
------------------------------------------------------------------------
-- Some tests
test : String -> List Expr
test s = Mixfix.parseExpr g (map (fromList ∘ L[_]) (toList s))
-- Using an unoptimised type checker to run an inefficient parser can
-- take ages… The following examples have been converted into
-- postulates since I have not had the patience to wait long enough to
-- see whether the left- and right-hand sides actually match.
postulate
ex₁ : test "•⊢•" ≡ []
ex₂ : test "(•,•)⊢∶" ≡ []
ex₃ : test "•⊢•∶" ≡ L[ • ⊢ • ∶ ]
ex₄ : test "•,•+•*•⊢(•⊢•∶)∶" ≡
L[ (• , (• + (• * •))) ⊢ ⟦ • ⊢ • ∶ ⟧ ∶ ]
| {
"alphanum_fraction": 0.493989071,
"avg_line_length": 28.2989690722,
"ext": "agda",
"hexsha": "b0578fff43f7cf5376c4f6d3fa17f864938910da",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix/Example.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix/Example.agda",
"max_line_length": 72,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix/Example.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 871,
"size": 2745
} |
-- Minimal propositional logic, PHOAS approach, initial encoding
module Pi.Mp where
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Set1
Cx = Ty -> Set
isTrue : Ty -> Cx -> Set
isTrue a tc = tc a
-- Terms
module Mp where
infixl 1 _$_
data Tm (tc : Cx) : Ty -> Set where
var : forall {a} -> isTrue a tc -> Tm tc a
lam' : forall {a b} -> (isTrue a tc -> Tm tc b) -> Tm tc (a => b)
_$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b
pair' : forall {a b} -> Tm tc a -> Tm tc b -> Tm tc (a && b)
fst : forall {a b} -> Tm tc (a && b) -> Tm tc a
snd : forall {a b} -> Tm tc (a && b) -> Tm tc b
left : forall {a b} -> Tm tc a -> Tm tc (a || b)
right : forall {a b} -> Tm tc b -> Tm tc (a || b)
case' : forall {a b c} -> Tm tc (a || b) -> (isTrue a tc -> Tm tc c) -> (isTrue b tc -> Tm tc c) -> Tm tc c
lam'' : forall {tc a b} -> (Tm tc a -> Tm tc b) -> Tm tc (a => b)
lam'' f = lam' \x -> f (var x)
case'' : forall {tc a b c} -> Tm tc (a || b) -> (Tm tc a -> Tm tc c) -> (Tm tc b -> Tm tc c) -> Tm tc c
case'' xy f g = case' xy (\x -> f (var x)) (\y -> g (var y))
syntax lam'' (\a -> b) = lam a => b
syntax pair' x y = [ x , y ]
syntax case'' xy (\x -> z1) (\y -> z2) = case xy of x => z1 or y => z2
Thm : Ty -> Set1
Thm a = forall {tc} -> Tm tc a
open Mp public
-- Example theorems
c1 : forall {a b} -> Thm (a && b <=> b && a)
c1 =
[ lam xy => [ snd xy , fst xy ]
, lam yx => [ snd yx , fst yx ]
]
c2 : forall {a b} -> Thm (a || b <=> b || a)
c2 =
[ lam xy =>
case xy
of x => right x
or y => left y
, lam yx =>
case yx
of y => right y
or x => left x
]
i1 : forall {a} -> Thm (a && a <=> a)
i1 =
[ lam xx => fst xx
, lam x => [ x , x ]
]
i2 : forall {a} -> Thm (a || a <=> a)
i2 =
[ lam xx =>
case xx
of x => x
or x => x
, lam x => left x
]
l3 : forall {a} -> Thm ((a => a) <=> TRUE)
l3 =
[ lam _ => lam nt => nt
, lam _ => lam x => x
]
l1 : forall {a b c} -> Thm (a && (b && c) <=> (a && b) && c)
l1 =
[ lam xyz =>
(let yz = snd xyz in
[ [ fst xyz , fst yz ] , snd yz ])
, lam xyz =>
(let xy = fst xyz in
[ fst xy , [ snd xy , snd xyz ] ])
]
l2 : forall {a} -> Thm (a && TRUE <=> a)
l2 =
[ lam xt => fst xt
, lam x => [ x , lam nt => nt ]
]
l4 : forall {a b c} -> Thm (a && (b || c) <=> (a && b) || (a && c))
l4 =
[ lam xyz =>
(let x = fst xyz in
case snd xyz
of y => left [ x , y ]
or z => right [ x , z ])
, lam xyxz =>
case xyxz
of xy => [ fst xy , left (snd xy) ]
or xz => [ fst xz , right (snd xz) ]
]
l6 : forall {a b c} -> Thm (a || (b && c) <=> (a || b) && (a || c))
l6 =
[ lam xyz =>
case xyz
of x => [ left x , left x ]
or yz => [ right (fst yz) , right (snd yz) ]
, lam xyxz =>
case fst xyxz
of x => left x
or y =>
case snd xyxz
of x => left x
or z => right [ y , z ]
]
l7 : forall {a} -> Thm (a || TRUE <=> TRUE)
l7 =
[ lam _ => lam nt => nt
, lam t => right t
]
l9 : forall {a b c} -> Thm (a || (b || c) <=> (a || b) || c)
l9 =
[ lam xyz =>
case xyz
of x => left (left x)
or yz =>
case yz
of y => left (right y)
or z => right z
, lam xyz =>
case xyz
of xy =>
case xy
of x => left x
or y => right (left y)
or z => right (right z)
]
l11 : forall {a b c} -> Thm ((a => (b && c)) <=> (a => b) && (a => c))
l11 =
[ lam xyz =>
[ lam x => fst (xyz $ x)
, lam x => snd (xyz $ x)
]
, lam xyxz =>
lam x => [ fst xyxz $ x , snd xyxz $ x ]
]
l12 : forall {a} -> Thm ((a => TRUE) <=> TRUE)
l12 =
[ lam _ => lam nt => nt
, lam t => lam _ => t
]
l13 : forall {a b c} -> Thm ((a => (b => c)) <=> ((a && b) => c))
l13 =
[ lam xyz =>
lam xy => xyz $ fst xy $ snd xy
, lam xyz =>
lam x =>
lam y => xyz $ [ x , y ]
]
l16 : forall {a b c} -> Thm (((a && b) => c) <=> (a => (b => c)))
l16 =
[ lam xyz =>
lam x =>
lam y => xyz $ [ x , y ]
, lam xyz =>
lam xy => xyz $ fst xy $ snd xy
]
l17 : forall {a} -> Thm ((TRUE => a) <=> a)
l17 =
[ lam tx => tx $ (lam nt => nt)
, lam x => lam _ => x
]
l19 : forall {a b c} -> Thm (((a || b) => c) <=> (a => c) && (b => c))
l19 =
[ lam xyz =>
[ lam x => xyz $ left x
, lam y => xyz $ right y
]
, lam xzyz =>
lam xy =>
case xy
of x => fst xzyz $ x
or y => snd xzyz $ y
]
| {
"alphanum_fraction": 0.3950156986,
"avg_line_length": 22.2532751092,
"ext": "agda",
"hexsha": "deb5b0d3a4374b08ec2ba5e823afa724c136b448",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Pi/Mp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Pi/Mp.agda",
"max_line_length": 111,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Pi/Mp.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 1930,
"size": 5096
} |
module Data.Num.Maximum where
open import Data.Num.Core
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Properties.Simple
open import Data.Nat.Properties.Extra
open import Data.Fin as Fin
using (Fin; fromℕ≤; inject≤)
renaming (zero to z; suc to s)
open import Data.Fin.Properties using (toℕ-fromℕ≤; bounded)
open import Data.Product
open import Function
open import Relation.Nullary.Decidable
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)
open DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)
------------------------------------------------------------------------
Maximum : ∀ {b d o} → (xs : Numeral b d o) → Set
Maximum {b} {d} {o} xs = (ys : Numeral b d o) → ⟦ xs ⟧ ≥ ⟦ ys ⟧
-- Maximum-unique : ∀ {b d o}
-- → (max xs : Numeral b d o)
-- → Maximum max
-- → Maximum xs
-- → ⟦ max ⟧ ≡ ⟦ xs ⟧
-- Maximum-unique max xs max-max xs-max = IsPartialOrder.antisym isPartialOrder
-- (xs-max max)
-- (max-max xs)
Maximum-NullBase-Greatest : ∀ {d} {o}
→ (xs : Numeral 0 (suc d) o)
→ Greatest (lsd xs)
→ Maximum xs
Maximum-NullBase-Greatest {_} {o} (x ∙) greatest (y ∙) =
greatest-of-all o x y greatest
Maximum-NullBase-Greatest {_} {o} (x ∙) greatest (y ∷ ys) =
start
Fin.toℕ y + o + ⟦ ys ⟧ * 0
≈⟨ toℕ-NullBase y ys ⟩
Fin.toℕ y + o
≤⟨ greatest-of-all o x y greatest ⟩
Fin.toℕ x + o
□
Maximum-NullBase-Greatest {_} {o} (x ∷ xs) greatest (y ∙) =
start
Fin.toℕ y + o
≤⟨ greatest-of-all o x y greatest ⟩
Fin.toℕ x + o
≈⟨ sym (toℕ-NullBase x xs) ⟩
Fin.toℕ x + o + ⟦ xs ⟧ * 0
□
Maximum-NullBase-Greatest {_} {o} (x ∷ xs) greatest (y ∷ ys) =
start
⟦ y ∷ ys ⟧
≈⟨ toℕ-NullBase y ys ⟩
Fin.toℕ y + o
≤⟨ greatest-of-all o x y greatest ⟩
Fin.toℕ x + o
≈⟨ sym (toℕ-NullBase x xs) ⟩
⟦ x ∷ xs ⟧
□
Maximum⇒Greatest-LSD : ∀ {b} {d} {o}
→ (xs : Numeral b d o)
→ Maximum xs
→ Greatest (lsd xs)
Maximum⇒Greatest-LSD xs max with Greatest? (lsd xs)
Maximum⇒Greatest-LSD xs max | yes greatest = greatest
Maximum⇒Greatest-LSD {b} {zero} xs max | no ¬greatest = NoDigits-explode xs
Maximum⇒Greatest-LSD {b} {suc d} {o} (x ∙) max | no ¬greatest
= contradiction p ¬p
where
ys : Numeral b (suc d) o
ys = greatest-digit d ∙
p : Digit-toℕ x o ≥ ⟦ ys ⟧
p = max ys
¬p : Digit-toℕ x o ≱ ⟦ ys ⟧
¬p = <⇒≱ $
start
suc (Digit-toℕ x o)
≤⟨ +n-mono o (≤-pred (≤∧≢⇒< (bounded x) ¬greatest)) ⟩
d + o
≈⟨ sym (greatest-digit-toℕ (Fin.fromℕ d) (greatest-digit-is-the-Greatest d)) ⟩
Digit-toℕ (greatest-digit d) o
≈⟨ refl ⟩
⟦ ys ⟧
□
Maximum⇒Greatest-LSD {b} {suc d} {o} (x ∷ xs) max | no ¬greatest
= contradiction p ¬p
where
ys : Numeral b (suc d) o
ys = greatest-digit d ∷ xs
p : ⟦ x ∷ xs ⟧ ≥ ⟦ ys ⟧
p = max ys
¬p : ⟦ x ∷ xs ⟧ ≱ ⟦ ys ⟧
¬p = <⇒≱ $ +n-mono (⟦ xs ⟧ * b) $
start
suc (Digit-toℕ x o)
≤⟨ +n-mono o (≤-pred (≤∧≢⇒< (bounded x) ¬greatest)) ⟩
d + o
≈⟨ sym (greatest-digit-toℕ (Fin.fromℕ d) (greatest-digit-is-the-Greatest d)) ⟩
(Digit-toℕ (greatest-digit d) o)
□
Maximum-NullBase : ∀ {d} {o}
→ (xs : Numeral 0 (suc d) o)
→ Dec (Maximum xs)
Maximum-NullBase xs with Greatest? (lsd xs)
Maximum-NullBase xs | yes greatest = yes (Maximum-NullBase-Greatest xs greatest)
Maximum-NullBase xs | no ¬greatest = no (contraposition (Maximum⇒Greatest-LSD xs) ¬greatest)
Maximum-AllZeros : ∀ {b} → (xs : Numeral b 1 0) → Maximum xs
Maximum-AllZeros xs ys = reflexive $
begin
⟦ ys ⟧
≡⟨ toℕ-AllZeros ys ⟩
zero
≡⟨ sym (toℕ-AllZeros xs) ⟩
⟦ xs ⟧
∎
Maximum-Proper : ∀ {b d o}
→ (xs : Numeral (suc b) (suc d) o)
→ (proper : 2 ≤ suc (d + o))
→ ¬ (Maximum xs)
Maximum-Proper {b} {d} {o} xs proper claim = contradiction p ¬p
where
p : ⟦ xs ⟧ ≥ ⟦ greatest-digit d ∷ xs ⟧
p = claim (greatest-digit d ∷ xs)
¬p : ⟦ xs ⟧ ≱ ⟦ greatest-digit d ∷ xs ⟧
¬p = <⇒≱ $
start
suc ⟦ xs ⟧
≈⟨ cong suc (sym (*-right-identity ⟦ xs ⟧)) ⟩
suc (⟦ xs ⟧ * 1)
≤⟨ s≤s (n*-mono ⟦ xs ⟧ (s≤s z≤n)) ⟩
suc (⟦ xs ⟧ * suc b)
≤⟨ +n-mono (⟦ xs ⟧ * suc b) (≤-pred proper) ⟩
d + o + ⟦ xs ⟧ * suc b
≈⟨ cong
(λ w → w + ⟦ xs ⟧ * suc b)
(sym (greatest-digit-toℕ (Fin.fromℕ d) (greatest-digit-is-the-Greatest d)))
⟩
⟦ greatest-digit d ∷ xs ⟧
□
Maximum? : ∀ {b d o}
→ (xs : Numeral b d o)
→ Dec (Maximum xs)
Maximum? {b} {d} {o} xs with numView b d o
Maximum? xs | NullBase d o = Maximum-NullBase xs
Maximum? xs | NoDigits b o = no (NoDigits-explode xs)
Maximum? xs | AllZeros b = yes (Maximum-AllZeros xs)
Maximum? xs | Proper b d o proper = no (Maximum-Proper xs proper)
| {
"alphanum_fraction": 0.5227696902,
"avg_line_length": 31.3333333333,
"ext": "agda",
"hexsha": "cff6b7a1e32265fbf9ff2690fc1687ceb607952b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Maximum.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Maximum.agda",
"max_line_length": 92,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Maximum.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 1974,
"size": 5358
} |
module Esterel.Lang.CanFunction where
open import utility
hiding (module ListSet)
open import Esterel.Lang
open import Esterel.Environment as Env
using (Env ; _←_ ; Θ ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ) renaming (_≟ₛₜ_ to _≟ₛₜₛ_)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ) renaming (_≟ₛₜ_ to _≟ₛₜₛₕ_)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Function
using (_∘_)
open import Relation.Nullary
using (yes ; no)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Relation.Binary
using (Decidable)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl)
open import Data.Bool
using (Bool ; not ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.List
using (List ; [] ; _∷_ ; [_] ; _++_ ; map ; concatMap ; filter)
open import Data.List.Any
using (Any ; any)
open import Data.Product
using (_×_ ; _,_ ; _,′_ ; proj₁ ; proj₂)
import Data.Nat as Nat
open Nat using (ℕ ; zero ; suc)
module SigSet = utility.ListSet Nat._≟_
module ShrSet = utility.ListSet Nat._≟_
module CodeSet = utility.ListSet Code._≟_
-- hide this when importing CanFunction to avoid ambiguity from sn-calculus.agda
[S]-env : (S : Signal) → Env
[S]-env S = Θ SigMap.[ S ↦ Signal.unknown ] ShrMap.empty VarMap.empty
-- The speculative environment used in Canₛ rule and for existing signals in Canθ
[S]-env-absent : (S : Signal) → Env
[S]-env-absent S = Θ SigMap.[ S ↦ Signal.absent ] ShrMap.empty VarMap.empty
-- Helper environment for existing signals in Canθ
[S]-env-present : (S : Signal) → Env
[S]-env-present S = Θ SigMap.[ S ↦ Signal.present ] ShrMap.empty VarMap.empty
Can : Term → Env → SigSet.ST × CodeSet.ST × ShrSet.ST
Canₛ : Term → Env → SigSet.ST
Canₖ : Term → Env → CodeSet.ST
Canₛₕ : Term → Env → ShrSet.ST
Canₛ p θ with Can p θ
... | Ss , _ , _ = Ss
Canₖ p θ with Can p θ
... | _ , ks , _ = ks
Canₛₕ p θ with Can p θ
... | _ , _ , ss = ss
Canθ : SigMap.Map Signal.Status → ℕ → Term → Env → SigSet.ST × CodeSet.ST × ShrSet.ST
Canθₛ : SigMap.Map Signal.Status → ℕ → Term → Env → SigSet.ST
Canθₖ : SigMap.Map Signal.Status → ℕ → Term → Env → CodeSet.ST
Canθₛₕ : SigMap.Map Signal.Status → ℕ → Term → Env → ShrSet.ST
Canθₛ sigs S p θ = proj₁ (Canθ sigs S p θ)
Canθₖ sigs S p θ = proj₁ (proj₂ (Canθ sigs S p θ))
Canθₛₕ sigs S p θ = proj₂ (proj₂ (Canθ sigs S p θ))
Canθ [] S p θ = Can p θ
Canθ (nothing ∷ sig') S p θ = Canθ sig' (suc S) p θ
Canθ (just Signal.present ∷ sig') S p θ = Canθ sig' (suc S) p (θ ← [S]-env-present (S ₛ))
Canθ (just Signal.absent ∷ sig') S p θ = Canθ sig' (suc S) p (θ ← [S]-env-absent (S ₛ))
Canθ (just Signal.unknown ∷ sig') S p θ with
any (Nat._≟_ S) (Canθₛ sig' (suc S) p (θ ← [S]-env (S ₛ)))
... | yes S∈can-p-θ←[S] = Canθ sig' (suc S) p (θ ← [S]-env (S ₛ))
... | no S∉can-p-θ←[S] = Canθ sig' (suc S) p (θ ← [S]-env-absent (S ₛ))
Can nothin θ =
[] ,′ [ Code.nothin ] ,′ []
Can pause θ =
[] ,′ [ Code.pause ] ,′ []
Can (signl S p) θ =
SigSet.set-remove (Canθₛ (Env.sig ([S]-env S)) 0 p θ) (Signal.unwrap S) ,′
Canθₖ (Env.sig ([S]-env S)) 0 p θ ,′
Canθₛₕ (Env.sig ([S]-env S)) 0 p θ
Can (present S ∣⇒ p ∣⇒ q) θ with (Env.Sig∈ S θ)
... | yes S∈ =
if ⌊ Signal.present Signal.≟ₛₜ (Env.sig-stats{S} θ S∈) ⌋
then Can p θ
else
if ⌊ Signal.absent Signal.≟ₛₜ Env.sig-stats{S} θ S∈ ⌋
then Can q θ
else Canₛ p θ ++ Canₛ q θ ,′ Canₖ p θ ++ Canₖ q θ ,′ Canₛₕ p θ ++ Canₛₕ q θ
... | no S∉ =
Canₛ p θ ++ Canₛ q θ ,′ Canₖ p θ ++ Canₖ q θ ,′ Canₛₕ p θ ++ Canₛₕ q θ
Can (emit S) θ = [ (Signal.unwrap S) ] ,′ [ Code.nothin ] ,′ []
Can (p ∥ q) θ =
Canₛ p θ ++ Canₛ q θ ,′
concatMap (λ k → map (Code._⊔_ k) (Canₖ q θ)) (Canₖ p θ) ,′
Canₛₕ p θ ++ Canₛₕ q θ
Can (loop p) θ = Can p θ
Can (loopˢ p q) θ = Can p θ
Can (p >> q) θ with any (Code._≟_ Code.nothin) (Canₖ p θ)
... | no nothin∉ =
Can p θ
... | yes nothin∈ =
Canₛ p θ ++ Canₛ q θ ,′
(CodeSet.set-remove (Canₖ p θ) Code.nothin) ++ Canₖ q θ ,′
Canₛₕ p θ ++ Canₛₕ q θ
Can (suspend p S) θ = Can p θ
Can (trap p) θ =
Canₛ p θ ,′ map Code.↓* (Canₖ p θ) ,′ Canₛₕ p θ
Can (exit n) θ =
[] ,′ [ Code.exit n ] ,′ []
Can (shared s ≔ e in: p) θ =
Canₛ p θ ,′
Canₖ p θ ,′
ShrSet.set-remove (Canₛₕ p θ) (SharedVar.unwrap s)
Can (s ⇐ e) θ =
[] ,′ [ Code.nothin ] ,′ [ (SharedVar.unwrap s) ]
Can (var x ≔ e in: p) θ =
Can p θ
Can (x ≔ e) θ =
[] ,′ [ Code.nothin ] ,′ []
Can (if x ∣⇒ p ∣⇒ q) θ =
Canₛ p θ ++ Canₛ q θ ,′ Canₖ p θ ++ Canₖ q θ ,′ Canₛₕ p θ ++ Canₛₕ q θ
Can (ρ⟨ (Θ sig' shr' var') , A ⟩· p) θ =
SigSet.set-subtract (Canθₛ sig' 0 p θ) (SigMap.keys sig') ,′
Canθₖ sig' 0 p θ ,′
ShrSet.set-subtract (Canθₛₕ sig' 0 p θ) (ShrMap.keys shr')
| {
"alphanum_fraction": 0.6090255591,
"avg_line_length": 34.5379310345,
"ext": "agda",
"hexsha": "7af64f5ba2982ec8c047ba2f4f91e4db6efd9557",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/Esterel/Lang/CanFunction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/Esterel/Lang/CanFunction.agda",
"max_line_length": 89,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/Esterel/Lang/CanFunction.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 2104,
"size": 5008
} |
{-
Groupoid quotients:
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.GroupoidQuotients.Properties where
open import Cubical.HITs.GroupoidQuotients.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary.Base
open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥; ∣_∣; squash)
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂; ∣_∣₂; squash₂)
-- Type quotients
private
variable
ℓA ℓR ℓ : Level
A : Type ℓA
R : A → A → Type ℓR
-- B : A // Rt → Type ℓ
-- C : A // Rt → A // Rt → Type ℓ
elimEq// : (Rt : BinaryRelation.isTrans R)
{B : A // Rt → Type ℓ}
(Bprop : (x : A // Rt) → isProp (B x))
{x y : A // Rt}
(eq : x ≡ y)
(bx : B x)
(by : B y) →
PathP (λ i → B (eq i)) bx by
elimEq// Rt {B} Bprop {x = x} =
J (λ y eq → ∀ bx by → PathP (λ i → B (eq i)) bx by) (λ bx by → Bprop x bx by)
elimProp : (Rt : BinaryRelation.isTrans R)
→ {B : A // Rt → Type ℓ}
→ ((x : A // Rt) → isProp (B x))
→ ((a : A) → B [ a ])
→ (x : A // Rt)
→ B x
elimProp Rt Bprop f [ x ] = f x
elimProp Rt Bprop f (eq// {a} {b} r i) = elimEq// Rt Bprop (eq// r) (f a) (f b) i
elimProp Rt Bprop f (comp// {a} {b} {c} r s i j) =
isSet→isSetDep (λ x → isProp→isSet (Bprop x))
(eq// r) (eq// (Rt a b c r s)) (λ j → [ a ]) (eq// s) (comp// r s)
(λ i → elimEq// Rt Bprop (eq// r) (f a) (f b) i)
(λ i → elimEq// Rt Bprop (eq// (Rt a b c r s)) (f a) (f c) i)
(λ j → f a ) (λ j → elimEq// Rt Bprop (eq// s) (f b) (f c) j) i j
elimProp Rt Bprop f (squash// x y p q r s i j k) =
isOfHLevel→isOfHLevelDep 3 (λ x → isSet→isGroupoid (isProp→isSet (Bprop x)))
_ _ _ _ (λ j k → g (r j k)) (λ j k → g (s j k)) (squash// x y p q r s) i j k
where
g = elimProp Rt Bprop f
elimProp2 : (Rt : BinaryRelation.isTrans R)
→ {C : A // Rt → A // Rt → Type ℓ}
→ ((x y : A // Rt) → isProp (C x y))
→ ((a b : A) → C [ a ] [ b ])
→ (x y : A // Rt)
→ C x y
elimProp2 Rt Cprop f = elimProp Rt (λ x → isPropΠ (λ y → Cprop x y))
(λ x → elimProp Rt (λ y → Cprop [ x ] y) (f x))
[]surjective : (Rt : BinaryRelation.isTrans R)
→ (x : A // Rt ) → ∃[ a ∈ A ] [ a ] ≡ x
[]surjective Rt = elimProp Rt (λ x → squash) (λ a → ∣ a , refl ∣)
elimSet : (Rt : BinaryRelation.isTrans R)
→ {B : A // Rt → Type ℓ}
→ ((x : A // Rt) → isSet (B x))
→ (f : (a : A) → B [ a ])
→ ({a b : A} (r : R a b) → PathP (λ i → B (eq// r i)) (f a) (f b))
→ (x : A // Rt)
→ B x
elimSet Rt Bset f feq [ a ] = f a
elimSet Rt Bset f feq (eq// r i) = feq r i
elimSet Rt Bset f feq (comp// {a} {b} {c} r s i j) =
isSet→isSetDep Bset (eq// r) (eq// (Rt a b c r s)) (λ j → [ a ]) (eq// s) (comp// r s)
(feq r) (feq (Rt a b c r s)) refl (feq s) i j
elimSet Rt Bset f feq (squash// x y p q r s i j k) =
isOfHLevel→isOfHLevelDep 3 (λ x → isSet→isGroupoid (Bset x))
_ _ _ _ (λ j k → g (r j k)) (λ j k → g (s j k)) (squash// x y p q r s) i j k
where
g = elimSet Rt Bset f feq
elim : (Rt : BinaryRelation.isTrans R)
→ {B : A // Rt → Type ℓ}
→ ((x : A // Rt) → isGroupoid (B x))
→ (f : (a : A) → B [ a ])
→ (feq : {a b : A} (r : R a b) → PathP (λ i → B (eq// r i)) (f a) (f b))
→ ({a b c : A} (r : R a b) (s : R b c)
→ SquareP (λ i j → B (comp// r s i j))
(feq r) (feq (Rt a b c r s)) (λ j → f a) (feq s))
→ (x : A // Rt)
→ B x
elim Rt Bgpd f feq fcomp [ a ] = f a
elim Rt Bgpd f feq fcomp (eq// r i) = feq r i
elim Rt Bgpd f feq fcomp (comp// r s i j) = fcomp r s i j
elim Rt Bgpd f feq fcomp (squash// x y p q r s i j k) =
isOfHLevel→isOfHLevelDep 3 Bgpd
_ _ _ _ (λ j k → g (r j k)) (λ j k → g (s j k)) (squash// x y p q r s) i j k
where
g = elim Rt Bgpd f feq fcomp
rec : (Rt : BinaryRelation.isTrans R)
→ {B : Type ℓ}
→ isGroupoid B
→ (f : A → B)
→ (feq : {a b : A} (r : R a b) → f a ≡ f b)
→ ({a b c : A} (r : R a b) (s : R b c)
→ Square (feq r) (feq (Rt a b c r s)) refl (feq s))
→ (x : A // Rt)
→ B
rec Rt Bgpd = elim Rt (λ _ → Bgpd)
module BinarySetRelation {ℓA ℓR : Level} {A : Type ℓA} (R : Rel A A ℓR) where
open BinaryRelation R
isSetValued : Type (ℓ-max ℓA ℓR)
isSetValued = (a b : A) → isSet (R a b)
| {
"alphanum_fraction": 0.5150105708,
"avg_line_length": 34.5255474453,
"ext": "agda",
"hexsha": "591b1e66b2f511ff75e7dd9a687de04c5b9b00f3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/HITs/GroupoidQuotients/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/HITs/GroupoidQuotients/Properties.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/HITs/GroupoidQuotients/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1951,
"size": 4730
} |
-- Andreas, 2016-10-09, re issue #2223
module Issue2223.Setoids where
open import Common.Level
record Setoid c ℓ : Set (lsuc (c ⊔ ℓ)) where
infix 4 _≈_
field
Carrier : Set c
_≈_ : (x y : Carrier) → Set ℓ
_⟨_⟩_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
A → (A → B → C) → B → C
x ⟨ f ⟩ y = f x y
| {
"alphanum_fraction": 0.5087719298,
"avg_line_length": 21.375,
"ext": "agda",
"hexsha": "b8e161601923fd100ede055a31d09ddba1aa81f0",
"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/Issue2223/Setoids.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/Issue2223/Setoids.agda",
"max_line_length": 55,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2223/Setoids.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": 145,
"size": 342
} |
{-# OPTIONS --safe #-}
module Cubical.Foundations.Pointed.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed.Base
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
private
variable
ℓ ℓ' ℓA ℓB ℓC ℓD : Level
-- the default pointed Π-type: A is pointed, and B has a base point in the chosen fiber
Π∙ : (A : Pointed ℓ) (B : typ A → Type ℓ') (ptB : B (pt A)) → Type (ℓ-max ℓ ℓ')
Π∙ A B ptB = Σ[ f ∈ ((a : typ A) → B a) ] f (pt A) ≡ ptB
-- the unpointed Π-type becomes a pointed type if the fibers are all pointed
Πᵘ∙ : (A : Type ℓ) (B : A → Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
Πᵘ∙ A B .fst = ∀ a → typ (B a)
Πᵘ∙ A B .snd a = pt (B a)
-- if the base and all fibers are pointed, we have the pointed pointed Π-type
Πᵖ∙ : (A : Pointed ℓ) (B : typ A → Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
Πᵖ∙ A B .fst = Π∙ A (typ ∘ B) (pt (B (pt A)))
Πᵖ∙ A B .snd .fst a = pt (B a)
Πᵖ∙ A B .snd .snd = refl
-- the default pointed Σ-type is just the Σ-type, but as a pointed type
Σ∙ : (A : Pointed ℓ) (B : typ A → Type ℓ') (ptB : B (pt A)) → Pointed (ℓ-max ℓ ℓ')
Σ∙ A B ptB .fst = Σ[ a ∈ typ A ] B a
Σ∙ A B ptB .snd .fst = pt A
Σ∙ A B ptB .snd .snd = ptB
-- version if B is a family of pointed types
Σᵖ∙ : (A : Pointed ℓ) (B : typ A → Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
Σᵖ∙ A B = Σ∙ A (typ ∘ B) (pt (B (pt A)))
_×∙_ : (A∙ : Pointed ℓ) (B∙ : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
(A∙ ×∙ B∙) .fst = (typ A∙) × (typ B∙)
(A∙ ×∙ B∙) .snd .fst = pt A∙
(A∙ ×∙ B∙) .snd .snd = pt B∙
-- composition of pointed maps
_∘∙_ : {A : Pointed ℓA} {B : Pointed ℓB} {C : Pointed ℓC}
(g : B →∙ C) (f : A →∙ B) → (A →∙ C)
((g , g∙) ∘∙ (f , f∙)) .fst x = g (f x)
((g , g∙) ∘∙ (f , f∙)) .snd = (cong g f∙) ∙ g∙
-- post composition
post∘∙ : ∀ {ℓX ℓ ℓ'} (X : Pointed ℓX) {A : Pointed ℓ} {B : Pointed ℓ'}
→ (A →∙ B) → ((X →∙ A ∙) →∙ (X →∙ B ∙))
post∘∙ X f .fst g = f ∘∙ g
post∘∙ X f .snd =
ΣPathP
( (funExt λ _ → f .snd)
, (sym (lUnit (f .snd)) ◁ λ i j → f .snd (i ∨ j)))
-- pointed identity
id∙ : (A : Pointed ℓA) → (A →∙ A)
id∙ A .fst x = x
id∙ A .snd = refl
-- constant pointed map
const∙ : (A : Pointed ℓA) (B : Pointed ℓB) → (A →∙ B)
const∙ _ B .fst _ = B .snd
const∙ _ B .snd = refl
-- left identity law for pointed maps
∘∙-idˡ : {A : Pointed ℓA} {B : Pointed ℓB} (f : A →∙ B) → f ∘∙ id∙ A ≡ f
∘∙-idˡ f = ΣPathP ( refl , (lUnit (f .snd)) ⁻¹ )
-- right identity law for pointed maps
∘∙-idʳ : {A : Pointed ℓA} {B : Pointed ℓB} (f : A →∙ B) → id∙ B ∘∙ f ≡ f
∘∙-idʳ f = ΣPathP ( refl , (rUnit (f .snd)) ⁻¹ )
-- associativity for composition of pointed maps
∘∙-assoc : {A : Pointed ℓA} {B : Pointed ℓB} {C : Pointed ℓC} {D : Pointed ℓD}
(h : C →∙ D) (g : B →∙ C) (f : A →∙ B)
→ (h ∘∙ g) ∘∙ f ≡ h ∘∙ (g ∘∙ f)
∘∙-assoc (h , h∙) (g , g∙) (f , f∙) = ΣPathP (refl , q)
where
q : (cong (h ∘ g) f∙) ∙ (cong h g∙ ∙ h∙) ≡ cong h (cong g f∙ ∙ g∙) ∙ h∙
q = ( (cong (h ∘ g) f∙) ∙ (cong h g∙ ∙ h∙)
≡⟨ refl ⟩
(cong h (cong g f∙)) ∙ (cong h g∙ ∙ h∙)
≡⟨ assoc (cong h (cong g f∙)) (cong h g∙) h∙ ⟩
(cong h (cong g f∙) ∙ cong h g∙) ∙ h∙
≡⟨ cong (λ p → p ∙ h∙) ((cong-∙ h (cong g f∙) g∙) ⁻¹) ⟩
(cong h (cong g f∙ ∙ g∙) ∙ h∙) ∎ )
module _ {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) where
isInIm∙ : (x : typ B) → Type (ℓ-max ℓ ℓ')
isInIm∙ x = Σ[ z ∈ typ A ] fst f z ≡ x
isInKer∙ : (x : fst A) → Type ℓ'
isInKer∙ x = fst f x ≡ snd B
pre∘∙equiv : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B C : Pointed ℓ'}
→ (B ≃∙ C) → Iso (A →∙ B) (A →∙ C)
pre∘∙equiv {A = A} {B = B} {C = C} eq = main
where
module _ {ℓ ℓ' : Level} (A : Pointed ℓ) (B C : Pointed ℓ')
(eq : (B ≃∙ C)) where
to : (A →∙ B) → (A →∙ C)
to = ≃∙map eq ∘∙_
from : (A →∙ C) → (A →∙ B)
from = ≃∙map (invEquiv∙ eq) ∘∙_
lem : {ℓ : Level} {B : Pointed ℓ}
→ ≃∙map (invEquiv∙ {A = B} ((idEquiv (fst B)) , refl)) ≡ id∙ B
lem = ΣPathP (refl , (sym (lUnit _)))
J-lem : {ℓ ℓ' : Level} {A : Pointed ℓ} {B C : Pointed ℓ'}
→ (eq : (B ≃∙ C))
→ retract (to A B C eq) (from _ _ _ eq)
× section (to A B C eq) (from _ _ _ eq)
J-lem {A = A} {B = B} {C = C} =
Equiv∙J (λ B eq → retract (to A B C eq) (from _ _ _ eq)
× section (to A B C eq) (from _ _ _ eq))
((λ f → ((λ i → (lem i ∘∙ (id∙ C ∘∙ f)))
∙ λ i → ∘∙-idʳ (∘∙-idʳ f i) i))
, λ f → ((λ i → (id∙ C ∘∙ (lem i ∘∙ f)))
∙ λ i → ∘∙-idʳ (∘∙-idʳ f i) i))
main : Iso (A →∙ B) (A →∙ C)
Iso.fun main = to A B C eq
Iso.inv main = from A B C eq
Iso.rightInv main = J-lem eq .snd
Iso.leftInv main = J-lem eq .fst
post∘∙equiv : ∀ {ℓ ℓC} {A B : Pointed ℓ} {C : Pointed ℓC}
→ (A ≃∙ B) → Iso (A →∙ C) (B →∙ C)
post∘∙equiv {A = A} {B = B} {C = C} eq = main
where
module _ {ℓ ℓC : Level} (A B : Pointed ℓ) (C : Pointed ℓC)
(eq : (A ≃∙ B)) where
to : (A →∙ C) → (B →∙ C)
to = _∘∙ ≃∙map (invEquiv∙ eq)
from : (B →∙ C) → (A →∙ C)
from = _∘∙ ≃∙map eq
lem : {ℓ : Level} {B : Pointed ℓ}
→ ≃∙map (invEquiv∙ {A = B} ((idEquiv (fst B)) , refl)) ≡ id∙ B
lem = ΣPathP (refl , (sym (lUnit _)))
J-lem : {ℓ ℓC : Level} {A B : Pointed ℓ} {C : Pointed ℓC}
→ (eq : (A ≃∙ B))
→ retract (to A B C eq) (from _ _ _ eq)
× section (to A B C eq) (from _ _ _ eq)
J-lem {B = B} {C = C} =
Equiv∙J (λ A eq → retract (to A B C eq) (from _ _ _ eq)
× section (to A B C eq) (from _ _ _ eq))
((λ f → ((λ i → (f ∘∙ lem i) ∘∙ id∙ B)
∙ λ i → ∘∙-idˡ (∘∙-idˡ f i) i))
, λ f → (λ i → (f ∘∙ id∙ B) ∘∙ lem i)
∙ λ i → ∘∙-idˡ (∘∙-idˡ f i) i)
main : Iso (A →∙ C) (B →∙ C)
Iso.fun main = to A B C eq
Iso.inv main = from A B C eq
Iso.rightInv main = J-lem eq .snd
Iso.leftInv main = J-lem eq .fst
| {
"alphanum_fraction": 0.4806895409,
"avg_line_length": 35.6982248521,
"ext": "agda",
"hexsha": "4ef2da95d5cfca353fc44224e0030602a9f39c6b",
"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/Foundations/Pointed/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Foundations/Pointed/Properties.agda",
"max_line_length": 87,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Foundations/Pointed/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 2986,
"size": 6033
} |
-- Andreas, 2013-09-17
module DoNotEtaContractFunIntoRecord where
record _×_ (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
postulate
A : Set
B : Set
P : (B → A × B) → Set
goal : (x : A) → P (λ y → x , y)
goal x = {!!}
-- Goal should be displayed as
-- P (λ y → x , y)
-- rather than as
-- P (_,_ x)
| {
"alphanum_fraction": 0.5454545455,
"avg_line_length": 15.5,
"ext": "agda",
"hexsha": "2496c012a08e24bcac4998928c862d5223ff05f9",
"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/DoNotEtaContractFunIntoRecord.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/DoNotEtaContractFunIntoRecord.agda",
"max_line_length": 42,
"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/DoNotEtaContractFunIntoRecord.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": 130,
"size": 341
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.Types
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open WithAbsVote
module LibraBFT.Concrete.Obligations.PreferredRound
(𝓔 : EpochConfig)
(𝓥 : VoteEvidence 𝓔)
where
open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Concrete.Intermediate 𝓔 𝓥
---------------------
-- * PreferredRound * --
---------------------
module _ {ℓ}(𝓢 : IntermediateSystemState ℓ) where
open IntermediateSystemState 𝓢
-- The PreferredRound rule is a little more involved to be expressed in terms
-- of /HasBeenSent/: it needs two additional pieces which are introduced
-- next.
-- Cand-3-chain v carries the information for estabilishing
-- that v.proposed will be part of a 3-chain if a QC containing v is formed.
-- The difficulty is that we can't easily access the "grandparent" of a vote.
-- Instead, we must explicitly state that it exists.
--
-- candidate 3-chain
-- +------------------------------------------------------+
-- | |
-- | 2-chain |
-- +----------------------------------+
-- ⋯ <- v.grandparent <- q₁ <- v.parent <- q <- v.proposed <- v
-- ̭
-- |
-- The 'qc' defined below is an
-- abstract view of q, above.
record voteExtends (v : Vote) : Set where
constructor mkVE
field
veBlock : Block
veId : vBlockUID v ≡ bId veBlock
veRounds≡ : vRound v ≡ bRound veBlock
open voteExtends
record Cand-3-chain-vote (v : Vote) : Set where
field
votesForB : voteExtends v
qc : QC
qc←b : Q qc ← B (veBlock votesForB)
rc : RecordChain (Q qc)
n : ℕ
is-2chain : 𝕂-chain Contig (2 + n) rc
open Cand-3-chain-vote public
-- Returns the round of the head of the candidate 3-chain. In the diagram
-- explaining Cand-3-chain-vote, this would be v.grandparent.round.
Cand-3-chain-head-round : ∀{v} → Cand-3-chain-vote v → Round
Cand-3-chain-head-round c3cand =
getRound (kchainBlock (suc zero) (is-2chain c3cand))
-- The preferred round rule states a fact about the /previous round/
-- of a vote; that is, the round of the parent of the block
-- being voted for; the implementation will have to
-- show it can construct this parent.
data VoteParentData-BlockExt : Record → Set where
vpParent≡I : VoteParentData-BlockExt I
vpParent≡Q : ∀{b q} → B b ← Q q → VoteParentData-BlockExt (Q q)
-- TODO-2: it may be cleaner to specify this as a RC 2 vpParent vpQC,
-- and we should consider it once we address the issue in
-- Abstract.RecordChain (below the definition of transp-𝕂-chain)
record VoteParentData (v : Vote) : Set where
field
vpExt : voteExtends v
vpParent : Record
vpExt' : vpParent ← B (veBlock vpExt)
vpMaybeBlock : VoteParentData-BlockExt vpParent
open VoteParentData public
-- The setup for PreferredRoundRule is like thta for VotesOnce.
-- Given two votes by an honest author α:
Type : Set ℓ
Type = ∀{α v v'}
→ Meta-Honest-Member α
→ vMember v ≡ α → HasBeenSent v
→ vMember v' ≡ α → HasBeenSent v'
-- If v is a vote on a candidate 3-chain, that is, is a vote on a block
-- that extends a 2-chain,
→ (c2 : Cand-3-chain-vote v)
-- and the round of v is lower than that of v',
→ vRound v < vRound v'
------------------------------
-- then α obeyed the preferred round rule:
→ Σ (VoteParentData v')
(λ vp → Cand-3-chain-head-round c2 ≤ round (vpParent vp))
private
make-cand-3-chain : ∀{n α q}{rc : RecordChain (Q q)}
→ (c3 : 𝕂-chain Contig (3 + n) rc)
→ (v : α ∈QC q)
→ Cand-3-chain-vote (∈QC-Vote q v)
make-cand-3-chain {q = q} (s-chain {suc (suc n)} {rc = rc} {b = b} ext₀@(Q←B h0 refl) _ ext₁@(B←Q h1 refl) c2) v
with c2
...| (s-chain {q = q₀} _ _ _ (s-chain _ _ _ c))
= record { votesForB = mkVE b (All-lookup (qVotes-C2 q) (Any-lookup-correct v))
(trans (All-lookup (qVotes-C3 q) (Any-lookup-correct v)) h1)
; qc = q₀
; qc←b = ext₀
; rc = rc
; n = n
; is-2chain = c2
}
-- It is important that the make-cand-3-chain lemma doesn't change the head of
-- the 3-chain/cand-2-chain.
make-cand-3-chain-lemma
: ∀{n α q}{rc : RecordChain (Q q)}
→ (c3 : 𝕂-chain Contig (3 + n) rc)
→ (v : α ∈QC q)
→ NonInjective-≡ bId ⊎ kchainBlock (suc zero) (is-2chain (make-cand-3-chain c3 v)) ≡ kchainBlock (suc (suc zero)) c3
make-cand-3-chain-lemma {q = q} c3@(s-chain {suc (suc n)} {rc = rc} {b = b} ext₀@(Q←B h0 refl) _ ext₁@(B←Q h1 refl) c2) v
with (veBlock (Cand-3-chain-vote.votesForB (make-cand-3-chain c3 v))) ≟Block b
...| no neq = inj₁ ((veBlock (Cand-3-chain-vote.votesForB (make-cand-3-chain c3 v)) , b)
, neq
, trans (sym (veId (votesForB (make-cand-3-chain c3 v))))
(All-lookup (qVotes-C2 q) (∈QC-Vote-correct q v)))
...| yes b≡
with c2
...| (s-chain {q = q₀} _ _ _ (s-chain _ _ _ c)) rewrite b≡ = inj₂ refl
vdParent-prevRound-lemma
: ∀{α q}(rc : RecordChain (Q q))(va : α ∈QC q)
→ (vp : VoteParentData (∈QC-Vote q va))
→ NonInjective-≡ bId ⊎ (round (vpParent vp) ≡ prevRound rc)
vdParent-prevRound-lemma {q = q} (step {r = B b} (step rc y) x@(B←Q refl refl)) va vp
with b ≟Block (veBlock (vpExt vp))
...| no imp = inj₁ ( (b , veBlock (vpExt vp))
, (imp , id-B∨Q-inj (cong id-B∨Q (trans (sym (All-lookup (qVotes-C2 q) (∈QC-Vote-correct q va)))
(veId (vpExt vp))))))
...| yes refl
with ←-inj y (vpExt' vp)
...| bSameId'
with y | vpExt' vp
...| I←B y0 y1 | I←B e0 e1 = inj₂ refl
...| Q←B y0 refl | Q←B e0 refl
with vpMaybeBlock vp
...| vpParent≡Q {b = bP} bP←qP
with rc
...| step {r = B b'} rc' b←q
with b' ≟Block bP
...| no imp = inj₁ ((b' , bP) , imp , id-B∨Q-inj (lemmaS1-2 (eq-Q refl) b←q bP←qP))
...| yes refl
with bP←qP | b←q
...| B←Q refl refl | B←Q refl refl = inj₂ refl
-- Finally, we can prove the preferred round rule from the global version;
proof : Type → PreferredRoundRule InSys
proof glob-inv α hα {q} {q'} q∈sys q'∈sys c3 va rc' va' hyp
with ∈QC⇒HasBeenSent q∈sys hα va
| ∈QC⇒HasBeenSent q'∈sys hα va'
...| sent-cv | sent-cv'
with make-cand-3-chain c3 va | inspect
(make-cand-3-chain c3) va
...| cand | [ R ]
with glob-inv hα
(sym (∈QC-Member q va )) sent-cv
(sym (∈QC-Member q' va')) sent-cv'
cand hyp
...| va'Par , res
with vdParent-prevRound-lemma rc' va' va'Par
...| inj₁ hb = inj₁ hb
...| inj₂ final
with make-cand-3-chain-lemma c3 va
...| inj₁ hb = inj₁ hb
...| inj₂ xx = inj₂ (subst₂ _≤_
(cong bRound (trans (cong (kchainBlock (suc zero) ∘ is-2chain) (sym R)) xx))
final
res)
| {
"alphanum_fraction": 0.5490522541,
"avg_line_length": 41.0947368421,
"ext": "agda",
"hexsha": "01f223afc441fe061f051e80c67443968b4bca30",
"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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Concrete/Obligations/PreferredRound.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"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": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Concrete/Obligations/PreferredRound.agda",
"max_line_length": 124,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Concrete/Obligations/PreferredRound.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2474,
"size": 7808
} |
{- An adaptation of Edwin Brady and Kevin Hammond's paper Scrapping your inefficient engine ... -}
{-# OPTIONS --type-in-type #-}
module tests.Cat where
open import Prelude.Bool
open import Prelude.Bot
open import Prelude.IO
open import Prelude.Fin
open import Prelude.Eq
open import Prelude.Nat
open import Prelude.Product
open import Prelude.String
open import Prelude.Unit
open import Prelude.Vec
record Top : Set where
constructor tt
data Ty : Set where
TyUnit : Ty
TyBool : Ty
TyLift : Set -> Ty
TyHandle : Nat -> Ty
interpTy : Ty -> Set
interpTy TyUnit = Unit
interpTy TyBool = Bool
interpTy (TyLift A) = A
interpTy (TyHandle n) = Fin n
data Purpose : Set where
Reading : Purpose
Writing : Purpose
getMode : Purpose -> String
getMode Reading = "r"
getMode Writing = "w"
data FileState : Set where
Open : Purpose -> FileState
Closed : FileState
postulate
EpicFile : Set
static[_] : {A : Set} → A → A
static[ x ] = x
{-# STATIC static[_] #-}
FileVec : Nat -> Set
FileVec n = Vec FileState n
data FileHandle : FileState -> Set where
OpenFile : ∀{p} -> EpicFile -> FileHandle (Open p)
ClosedFile : FileHandle Closed
data Env : ∀{n} -> FileVec n -> Set where
Empty : Env []
Extend : {n : Nat}{T : FileState}{G : FileVec n} -> (res : FileHandle T) -> Env G -> Env (T :: G)
addEnd : ∀{n T}{G : FileVec n} -> Env G -> FileHandle T -> Env (snoc G T)
addEnd Empty fh = Extend fh Empty
addEnd (Extend x xs) fh = Extend x (addEnd xs fh)
updateEnv : ∀{n T}{G : FileVec n} -> Env G -> (i : Fin n) -> (fh : FileHandle T) -> Env (G [ i ]= T)
updateEnv (Extend x xs) fz e = Extend e xs
updateEnv (Extend x xs) (fs n) e = Extend x (updateEnv xs n e)
updateEnv Empty () e
bound : ∀{n : Nat} -> Fin (S n)
bound {Z} = fz
bound {S n} = fs (bound {n})
_==P_ : Purpose -> Purpose -> Set
Reading ==P Reading = Top
Reading ==P Writing = Bot
Writing ==P Reading = Bot
Writing ==P Writing = Top
OpenH : ∀{n} -> Fin n -> Purpose -> FileVec n -> Set
OpenH fz p (Open p' :: as) = p ==P p'
OpenH fz p (Closed :: as) = Bot
OpenH (fs i) p ( a :: as) = OpenH i p as
getFile : ∀{n}{i : Fin n}{p : Purpose}{ts : FileVec n}{ope : OpenH i p ts} -> Env ts -> EpicFile
getFile {Z} {()} env
getFile {S y} {fz} (Extend (OpenFile y') y0) = y'
getFile {S y} {fz} {ope = ()} (Extend ClosedFile y')
getFile {S y} {fs y'} {ope = ope} (Extend res y0) = getFile {y} {y'} {ope = ope} y0
getPurpose : {n : Nat} -> Fin n -> FileVec n -> Purpose
getPurpose f ts with ts ! f
... | Open p = p
... | Closed = Reading -- Should not happen right?
FilePath : Set
FilePath = String
data File : ∀{n n'} -> FileVec n -> FileVec n' -> Ty -> Set where
ACTION : ∀{a l}{ts : FileVec l} -> IO (interpTy a) -> File ts ts a
RETURN : ∀{a l}{ts : FileVec l} -> interpTy a -> File ts ts a
WHILE : ∀{l}{ts : FileVec l} -> File ts ts TyBool -> File ts ts TyUnit -> File ts ts TyUnit
IF : ∀{a l}{ts : FileVec l} -> Bool -> File ts ts a -> File ts ts a -> File ts ts a
BIND : ∀{a b l l' l''}{ts : FileVec l}{ts' : FileVec l'}{ts'' : FileVec l''}
-> File ts ts' a -> (interpTy a -> File ts' ts'' b) -> File ts ts'' b
OPEN : ∀{l}{ts : FileVec l}
-> (p : Purpose) -> (fd : FilePath) -> File ts (snoc ts (Open p)) (TyHandle (S l))
CLOSE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> {p : OpenH i (getPurpose i ts) ts} -> File ts (ts [ i ]= Closed) TyUnit
GETLINE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> {p : OpenH i Reading ts} -> File ts ts (TyLift String)
EOF : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> {p : OpenH i Reading ts} -> File ts ts TyBool
PUTLINE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> (str : String) -> {p : OpenH i Writing ts} -> File ts ts TyUnit
postulate
while : IO Bool -> IO Unit -> IO Unit
fopen : FilePath -> String -> IO EpicFile
fclose : EpicFile -> IO Unit
fread : EpicFile -> IO String
feof : EpicFile -> IO Bool
fwrite : EpicFile -> String -> IO Unit
{-# COMPILED_EPIC while (add : Any, body : Any, u : Unit) -> Any = %while (add(u), body(u)) #-}
{-# COMPILED_EPIC fopen (fp : Any, mode : Any, u : Unit) -> Ptr = foreign Ptr "fopen" (mkString(fp) : String, mkString(mode) : String) #-}
{-# COMPILED_EPIC fclose (file : Ptr, u : Unit) -> Unit = foreign Int "fclose" (file : Ptr); unit #-}
{-# COMPILED_EPIC fread (file : Ptr, u : Unit) -> Any = frString(foreign String "freadStrChunk" (file : Ptr)) #-}
{-# COMPILED_EPIC feof (file : Ptr, u : Unit) -> Bool = foreign Int "feof" (file : Ptr) #-}
{-# COMPILED_EPIC fwrite (file : Ptr, str : Any, u : Unit) -> Unit = foreign Unit "fputs" (mkString(str) : String, file : Ptr) #-}
fmap : {A B : Set} -> (A -> B) -> IO A -> IO B
fmap f io =
x <- io ,
return (f x)
data MIO (A : Set) : Set where
Return : A -> MIO A
ABind : {B : Set} -> IO B -> (B -> MIO A) -> MIO A
-- While : MIO Bool -> MIO Unit -> MIO Unit
MBind : {A B : Set} -> MIO A -> (A -> MIO B) -> MIO B
MBind (Return x) f = f x
MBind (ABind io k) f = ABind io (λ x -> MBind (k x) f)
-- MBind (While b u) f =
mmap : {A B : Set} -> (A -> B) -> MIO A -> MIO B
mmap f mio = MBind mio (λ x -> Return (f x))
runMIO : {A : Set} -> MIO A -> IO A
runMIO (Return x) = return x
runMIO (ABind io f) =
x <- io ,
runMIO (f x)
interp : ∀{n n' T}{ts : FileVec n}{ts' : FileVec n'} -> Env ts -> File ts ts' T -> MIO (Env ts' × interpTy T)
interp env (ACTION io) = ABind io (λ x -> Return (env , x))
interp env (RETURN val) = Return (env , val)
interp env (WHILE add body) =
ABind (while (runMIO (mmap snd (interp env add))) (runMIO (mmap snd (interp env body)))) (λ _ ->
Return (env , unit))
interp env (IF b t f) = if b then interp env t else interp env f
interp env (BIND code k) =
MBind (interp env code) (λ v ->
interp (fst v) (k (snd v)))
interp env (OPEN p fpath) =
ABind (fopen fpath (getMode p)) (λ fh ->
Return (addEnd env (OpenFile fh), bound))
interp env (CLOSE i {p = p}) =
ABind (fclose (getFile {_} {i} {ope = p} env)) (\ _ ->
Return (updateEnv env i ClosedFile , unit))
interp env (GETLINE i {p = p}) =
ABind (fread (getFile {_} {i} {ope = p} env)) (λ x -> Return (env , x))
interp env (EOF i {p = p}) =
ABind (feof (getFile {_} {i} {ope = p} env)) (\ e ->
Return (env , e))
interp env (PUTLINE i str {p = p}) =
ABind (fwrite (getFile {i = i} {ope = p} env) str) (λ _ ->
ABind (fwrite (getFile {i = i} {ope = p} env) "\n") (λ x ->
Return (env , unit)))
allClosed : (n : Nat) -> FileVec n
allClosed Z = []
allClosed (S n) = Closed :: allClosed n
syntax BIND e (\ x -> f) = x := e % f
infixl 0 BIND
_%%_ : ∀{a b l l' l''}{ts : FileVec l}{ts' : FileVec l'}{ts'' : FileVec l''}
-> File ts ts' a -> File ts' ts'' b -> File ts ts'' b
m %% k = BIND m (λ _ -> k)
infixr 0 _%%_
{-
cat : File [] (Closed :: []) TyUnit
cat = (
fz := OPEN Reading "tests/Cat.out" %
WHILE (b := EOF fz % RETURN (not b)) (
str := GETLINE fz %
ACTION (putStrLn str)
) %%
CLOSE fz
)
cont : Fin 1 -> File (Open Reading :: []) (Closed :: []) TyUnit
cont (fs ())
cont fz = BIND (WHILE (BIND (EOF fz) (\b -> RETURN (not b)))
(BIND (GETLINE fz)
(\str -> ACTION (putStrLn str))
)
)
(λ x → CLOSE fz)
cat : File [] (Closed :: []) TyUnit
cat = BIND (OPEN Reading "hej")
cont
-}
cont : Fin 1 -> File (Open Reading :: []) (Closed :: []) TyUnit
cont (fs ())
cont fz =
WHILE ( b := EOF fz % RETURN (not b)) (
str := GETLINE fz %
ACTION (putStr str)
) %%
CLOSE fz
cat : File [] (Closed :: []) TyUnit
cat = BIND (OPEN Reading "tests/Cat.out") cont
copy : File [] (Closed :: Closed :: []) TyUnit
copy =
BIND (OPEN Reading "copy/input") (λ _ →
BIND (OPEN Writing "copy/output") (λ _ →
BIND (WHILE (BIND (EOF fz) (λ b → RETURN (not b)))
(BIND (GETLINE fz) (λ str → PUTLINE (fs fz) str))) (λ _ →
BIND (CLOSE fz) (λ _ →
CLOSE (fs fz)))))
runProg : {n : Nat} -> File [] (allClosed n) TyUnit -> IO Unit
runProg p = runMIO (mmap snd (interp Empty p))
{-# STATIC runProg #-}
main : IO Unit
main = runProg cat -- static[ runProg cat ]
-- main = runProg cat | {
"alphanum_fraction": 0.5626889131,
"avg_line_length": 33.084,
"ext": "agda",
"hexsha": "64177b8ecb7bc25eb0dcbe46928347572cf1c308",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/agda-kanso",
"max_forks_repo_path": "test/epic/tests/Cat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/agda-kanso",
"max_issues_repo_path": "test/epic/tests/Cat.agda",
"max_line_length": 138,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/epic/tests/Cat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2815,
"size": 8271
} |
{-# OPTIONS --cubical --postfix-projections --safe #-}
open import Relation.Binary
open import Prelude
module Data.List.Sort.MergeSort {e} {E : Type e} {r₁ r₂} (totalOrder : TotalOrder E r₁ r₂) where
open TotalOrder totalOrder hiding (refl)
open import Data.List.Sort.InsertionSort totalOrder using (insert; insert-sort)
open import Data.List
open import Data.List.Properties
open import TreeFold
open import Algebra
open import Relation.Nullary.Decidable.Properties using (from-reflects)
open import Path.Reasoning
mergeˡ : E → (List E → List E) → List E → List E
mergeˡ x xs [] = x ∷ xs []
mergeˡ x xs (y ∷ ys) = if x ≤ᵇ y then x ∷ xs (y ∷ ys) else y ∷ mergeˡ x xs ys
_⋎_ : List E → List E → List E
_⋎_ = foldr mergeˡ id
merge-idʳ : ∀ xs → xs ⋎ [] ≡ xs
merge-idʳ [] = refl
merge-idʳ (x ∷ xs) = cong (x ∷_) (merge-idʳ xs)
merge-assoc : Associative _⋎_
merge-assoc [] ys zs = refl
merge-assoc (x ∷ xs) [] zs = cong (λ xs′ → mergeˡ x (xs′ ⋎_) zs) (merge-idʳ xs)
merge-assoc (x ∷ xs) (y ∷ ys) [] = merge-idʳ ((x ∷ xs) ⋎ (y ∷ ys)) ; cong ((x ∷ xs) ⋎_) (sym (merge-idʳ (y ∷ ys)))
merge-assoc (x ∷ xs) (y ∷ ys) (z ∷ zs)
with merge-assoc xs (y ∷ ys) (z ∷ zs)
| merge-assoc (x ∷ xs) ys (z ∷ zs)
| merge-assoc (x ∷ xs) (y ∷ ys) zs
| x ≤? y in x≤?y
| y ≤? z in y≤?z
... | _ | _ | r | no x≰y | no y≰z rewrite y≤?z rewrite x≤?y =
cong (z ∷_) r ;
cong (bool′ _ _)
(sym (from-reflects false (x ≤? z) (<⇒≱ (<-trans (≰⇒> y≰z) (≰⇒> x≰y)))))
... | _ | r | _ | no x≰y | yes y≤z rewrite y≤?z rewrite x≤?y = cong (y ∷_) r
... | r | _ | _ | yes x≤y | yes y≤z rewrite y≤?z rewrite x≤?y =
cong (bool′ _ _)
(from-reflects true (x ≤? z) (≤-trans x≤y y≤z)) ;
cong (x ∷_) r
merge-assoc (x ∷ xs) (y ∷ ys) (z ∷ zs) | rx≤z | _ | rx≰z | yes x≤y | no y≰z with x ≤? z
... | no x≰z rewrite x≤?y = cong (z ∷_) rx≰z
... | yes x≤z rewrite y≤?z = cong (x ∷_) rx≤z
merge-sort : List E → List E
merge-sort = treeFold _⋎_ [] ∘ map (_∷ [])
merge-insert : ∀ x xs → (x ∷ []) ⋎ xs ≡ insert x xs
merge-insert x [] = refl
merge-insert x (y ∷ xs) with x ≤ᵇ y
... | false = cong (y ∷_) (merge-insert x xs)
... | true = refl
merge≡insert-sort : ∀ xs → merge-sort xs ≡ insert-sort xs
merge≡insert-sort xs =
merge-sort xs ≡⟨⟩
treeFold _⋎_ [] (map (_∷ []) xs) ≡⟨ treeFoldHom _⋎_ [] merge-assoc (map (_∷ []) xs) ⟩
foldr _⋎_ [] (map (_∷ []) xs) ≡⟨ map-fusion _⋎_ [] (_∷ []) xs ⟩
foldr (λ x → (x ∷ []) ⋎_) [] xs ≡⟨ cong (λ f → foldr f [] xs) (funExt (funExt ∘ merge-insert)) ⟩
foldr insert [] xs ≡⟨⟩
insert-sort xs ∎
| {
"alphanum_fraction": 0.5523368096,
"avg_line_length": 35.4657534247,
"ext": "agda",
"hexsha": "72224df5a16fae5d741cc18d8bc2e7e27f335a5d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/List/Sort/MergeSort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/List/Sort/MergeSort.agda",
"max_line_length": 114,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/List/Sort/MergeSort.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": 1110,
"size": 2589
} |
import Structure.Logic.Classical.NaturalDeduction
module Structure.Logic.Classical.NaturalDeduction.Proofs {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} ⦃ classicLogic : _ ⦄ where
open Structure.Logic.Classical.NaturalDeduction.ClassicalLogic {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} (classicLogic)
open import Functional hiding (Domain)
-- TODO: Move the ones which are constructive
[↔]-with-[∧]ₗ : ∀{a₁ a₂ b} → Proof(a₁ ⟷ a₂) → Proof((a₁ ∧ b) ⟷ (a₂ ∧ b))
[↔]-with-[∧]ₗ (proof) =
([↔].intro
(a₂b ↦ [∧].intro (([↔].elimₗ proof) ([∧].elimₗ a₂b)) ([∧].elimᵣ a₂b))
(a₁b ↦ [∧].intro (([↔].elimᵣ proof) ([∧].elimₗ a₁b)) ([∧].elimᵣ a₁b))
)
[↔]-with-[∧]ᵣ : ∀{a b₁ b₂} → Proof(b₁ ⟷ b₂) → Proof((a ∧ b₁) ⟷ (a ∧ b₂))
[↔]-with-[∧]ᵣ (proof) =
([↔].intro
(ab₂ ↦ [∧].intro ([∧].elimₗ ab₂) (([↔].elimₗ proof) ([∧].elimᵣ ab₂)))
(ab₁ ↦ [∧].intro ([∧].elimₗ ab₁) (([↔].elimᵣ proof) ([∧].elimᵣ ab₁)))
)
[↔]-with-[∧] : ∀{a₁ a₂ b₁ b₂} → Proof(a₁ ⟷ a₂) → Proof(b₁ ⟷ b₂) → Proof((a₁ ∧ b₁) ⟷ (a₂ ∧ b₂))
[↔]-with-[∧] (a₁a₂) (b₁b₂) =
([↔].intro
(a₂b₂ ↦ [∧].intro (([↔].elimₗ a₁a₂) ([∧].elimₗ a₂b₂)) (([↔].elimₗ b₁b₂) ([∧].elimᵣ a₂b₂)))
(a₁b₁ ↦ [∧].intro (([↔].elimᵣ a₁a₂) ([∧].elimₗ a₁b₁)) (([↔].elimᵣ b₁b₂) ([∧].elimᵣ a₁b₁)))
)
[↔]-with-[∨]ₗ : ∀{a₁ a₂ b} → Proof(a₁ ⟷ a₂) → Proof((a₁ ∨ b) ⟷ (a₂ ∨ b))
[↔]-with-[∨]ₗ (proof) =
([↔].intro
([∨].elim([∨].introₗ ∘ ([↔].elimₗ proof)) [∨].introᵣ)
([∨].elim([∨].introₗ ∘ ([↔].elimᵣ proof)) [∨].introᵣ)
)
[↔]-with-[∨]ᵣ : ∀{a b₁ b₂} → Proof(b₁ ⟷ b₂) → Proof((a ∨ b₁) ⟷ (a ∨ b₂))
[↔]-with-[∨]ᵣ (proof) =
([↔].intro
([∨].elim [∨].introₗ ([∨].introᵣ ∘ ([↔].elimₗ proof)))
([∨].elim [∨].introₗ ([∨].introᵣ ∘ ([↔].elimᵣ proof)))
)
[↔]-with-[∨] : ∀{a₁ a₂ b₁ b₂} → Proof(a₁ ⟷ a₂) → Proof(b₁ ⟷ b₂) → Proof((a₁ ∨ b₁) ⟷ (a₂ ∨ b₂))
[↔]-with-[∨] (a₁a₂) (b₁b₂) =
([↔].intro
([∨].elim ([∨].introₗ ∘ ([↔].elimₗ a₁a₂)) ([∨].introᵣ ∘ ([↔].elimₗ b₁b₂)))
([∨].elim ([∨].introₗ ∘ ([↔].elimᵣ a₁a₂)) ([∨].introᵣ ∘ ([↔].elimᵣ b₁b₂)))
)
[↔]-with-[∀] : ∀{f g} → (∀{x} → Proof(f(x) ⟷ g(x))) → Proof((∀ₗ f) ⟷ (∀ₗ g))
[↔]-with-[∀] (proof) =
([↔].intro
(allg ↦ [∀].intro(\{x} → [↔].elimₗ (proof{x}) ([∀].elim(allg){x})))
(allf ↦ [∀].intro(\{x} → [↔].elimᵣ (proof{x}) ([∀].elim(allf){x})))
)
[↔]-with-[∃] : ∀{f g} → (∀{x} → Proof(f(x) ⟷ g(x))) → Proof((∃ₗ f) ⟷ (∃ₗ g))
[↔]-with-[∃] (proof) =
([↔].intro
([∃].elim(\{x} → gx ↦ [∃].intro{_}{x}([↔].elimₗ (proof{x}) (gx))))
([∃].elim(\{x} → fx ↦ [∃].intro{_}{x}([↔].elimᵣ (proof{x}) (fx))))
)
-- [→]-with-[∀] : ∀{p f g} → (∀{x} → Proof(f(x) ⟶ g(x))) → Proof((∀ₗ f) ⟶ (∀ₗ g))
-- [→]-with-[∀] (proof) =
-- [→]-with-[∀] : ∀{p f g} → (∀{x} → Proof(f(x) ⟶ g(x))) → Proof(∀ₗ(x ↦ p(x) ⟶ f(x))) → Proof(∀ₗ(x ↦ p(x) ⟶ g(x)))
-- [→]-with-[∀] (proof) =
[∨][∧]-distributivityₗ : ∀{a b c} → Proof((a ∨ (b ∧ c)) ⟷ (a ∨ b)∧(a ∨ c))
[∨][∧]-distributivityₗ =
([↔].intro
(a∨b∧a∨c ↦
([∨].elim
(a ↦ [∨].introₗ a)
(b ↦
([∨].elim
(a ↦ [∨].introₗ a)
(c ↦ [∨].introᵣ([∧].intro b c))
([∧].elimᵣ a∨b∧a∨c)
)
)
([∧].elimₗ a∨b∧a∨c)
)
)
(a∨b∧c ↦
([∨].elim
(a ↦ [∧].intro([∨].introₗ a)([∨].introₗ a))
(b∧c ↦ [∧].intro([∨].introᵣ([∧].elimₗ b∧c))([∨].introᵣ([∧].elimᵣ b∧c)))
(a∨b∧c)
)
)
)
[∨][∧]-distributivityᵣ : ∀{a b c} → Proof(((a ∧ b) ∨ c) ⟷ (a ∨ c)∧(b ∨ c))
[∨][∧]-distributivityᵣ =
([↔].intro
(a∨c∧b∨c ↦
([∨].elim
(a ↦
([∨].elim
(b ↦ [∨].introₗ([∧].intro a b))
(c ↦ [∨].introᵣ c)
([∧].elimᵣ a∨c∧b∨c)
)
)
(c ↦ [∨].introᵣ c)
([∧].elimₗ a∨c∧b∨c)
)
)
(a∧b∨c ↦
([∨].elim
(a∧b ↦ [∧].intro([∨].introₗ([∧].elimₗ a∧b))([∨].introₗ([∧].elimᵣ a∧b)))
(c ↦ [∧].intro([∨].introᵣ c)([∨].introᵣ c))
(a∧b∨c)
)
)
)
[∧][∨]-distributivityₗ : ∀{a b c} → Proof((a ∧ (b ∨ c)) ⟷ (a ∧ b)∨(a ∧ c))
[∧][∨]-distributivityₗ =
([↔].intro
(a∧b∨a∧c ↦
([∨].elim
(a∧b ↦ [∧].intro([∧].elimₗ a∧b)([∨].introₗ([∧].elimᵣ a∧b)))
(a∧c ↦ [∧].intro([∧].elimₗ a∧c)([∨].introᵣ([∧].elimᵣ a∧c)))
(a∧b∨a∧c)
)
)
(a∧b∨c ↦
([∨].elim
(b ↦ [∨].introₗ([∧].intro([∧].elimₗ a∧b∨c)(b)))
(c ↦ [∨].introᵣ([∧].intro([∧].elimₗ a∧b∨c)(c)))
([∧].elimᵣ a∧b∨c)
)
)
)
[∧][∨]-distributivityᵣ : ∀{a b c} → Proof(((a ∨ b) ∧ c) ⟷ (a ∧ c)∨(b ∧ c))
[∧][∨]-distributivityᵣ =
([↔].intro
(a∧c∨b∧c ↦
([∨].elim
(a∧c ↦ [∧].intro([∨].introₗ([∧].elimₗ a∧c))([∧].elimᵣ a∧c))
(b∧c ↦ [∧].intro([∨].introᵣ([∧].elimₗ b∧c))([∧].elimᵣ b∧c))
(a∧c∨b∧c)
)
)
(a∨b∧c ↦
([∨].elim
(a ↦ [∨].introₗ([∧].intro(a)([∧].elimᵣ a∨b∧c)))
(b ↦ [∨].introᵣ([∧].intro(b)([∧].elimᵣ a∨b∧c)))
([∧].elimₗ a∨b∧c)
)
)
)
postulate [≡]-substitute-this-is-almost-trivial : ∀{φ : Domain → Formula}{a b} → Proof(((a ≡ b) ∧ φ(a)) ⟷ φ(b))
postulate [→][∧]-distributivityₗ : ∀{X Y Z} → Proof((X ⟶ (Y ∧ Z)) ⟷ ((X ⟶ Y) ∧ (X ⟶ Z)))
postulate [∀]-unrelatedₗ-[→] : ∀{P : Domain → Formula}{Q : Formula} → Proof(∀ₗ(x ↦ (P(x) ⟶ Q)) ⟷ (∃ₗ(x ↦ P(x)) ⟶ Q))
postulate [∀]-unrelatedᵣ-[→] : ∀{P : Formula}{Q : Domain → Formula} → Proof(∀ₗ(x ↦ (P ⟶ Q(x))) ⟷ (P ⟶ ∀ₗ(x ↦ Q(x))))
postulate [∃]-unrelatedₗ-[→] : ∀{P : Domain → Formula}{Q : Formula} → Proof(∃ₗ(x ↦ (P(x) ⟶ Q)) ⟷ (∀ₗ(x ↦ P(x)) ⟶ Q))
postulate [∃]-unrelatedᵣ-[→] : ∀{P : Formula}{Q : Domain → Formula} → Proof(∃ₗ(x ↦ (P ⟶ Q(x))) ⟷ (P ⟶ ∃ₗ(x ↦ Q(x))))
-- TODO: Is equivalence unprovable? I think so
Unique-unrelatedᵣ-[→]ᵣ : ∀{P : Formula}{Q : Domain → Formula} → Proof(Unique(x ↦ (P ⟶ Q(x))) ⟶ (P ⟶ Unique(x ↦ Q(x))))
Unique-unrelatedᵣ-[→]ᵣ {P}{Q} =
[→].intro(uniquepq ↦ [→].intro(p ↦ [∀].intro(\{x} → [∀].intro(\{y} → [→].intro(qxqy ↦
([→].elim
([∀].elim([∀].elim uniquepq{x}){y})
(([↔].elimᵣ [→][∧]-distributivityₗ) ([→].intro(p ↦ qxqy)))
)
)))))
-- Proving these equivalent:
-- ∀ₗ(x ↦ ∀ₗ(y ↦ (P ⟶ Q(x)) ∧ (P ⟶ Q(y)) ⟶ (x ≡ y))
-- P ⟶ ∀ₗ(x ↦ ∀ₗ(y ↦ Q(x) ∧ Q(y) ⟶ (x ≡ y))
-- test : Proof(∀ₗ(x ↦ ∀ₗ(y ↦ (P ⟶ Q(x)) ∧ (P ⟶ Q(y)) ⟶ (x ≡ y))) ⟷ ∀ₗ(x ↦ ∀ₗ(y ↦ (P ⟶ Q(x) ∧ Q(y)) ⟶ (x ≡ y))))
-- test = ([↔]-with-[∀] ([↔]-with-[∀] ([→][∧]-distributivityₗ)))
-- TODO: Is left provable? Above left seems unprovable
[∃!]-unrelatedᵣ-[→]ᵣ : ∀{P : Formula}{Q : Domain → Formula} → Proof(∃ₗ!(x ↦ (P ⟶ Q(x))) ⟶ (P ⟶ ∃ₗ!(x ↦ Q(x))))
[∃!]-unrelatedᵣ-[→]ᵣ {P}{Q} =
([→].intro(proof ↦
([↔].elimₗ [→][∧]-distributivityₗ)
([∧].intro
(([↔].elimᵣ [∃]-unrelatedᵣ-[→]) ([∧].elimₗ proof))
(([→].elim Unique-unrelatedᵣ-[→]ᵣ) ([∧].elimᵣ proof))
)
))
-- TODO: I think this is similar to the skolemization process of going from ∀∃ to ∃function∀
[∃]-fn-witness : ∀{P : Domain → Domain → Formula} → ⦃ _ : Proof(∀ₗ(x ↦ ∃ₗ(y ↦ P(x)(y)))) ⦄ → Domain → Domain
[∃]-fn-witness{P} ⦃ proof ⦄ (x) = [∃]-witness ⦃ [∀].elim(proof){x} ⦄
[∃]-fn-proof : ∀{P : Domain → Domain → Formula} → ⦃ p : Proof(∀ₗ(x ↦ ∃ₗ(y ↦ P(x)(y)))) ⦄ → Proof(∀ₗ(x ↦ P(x)([∃]-fn-witness{P} ⦃ p ⦄ (x))))
[∃]-fn-proof{P} ⦃ proof ⦄ =
([∀].intro(\{x} →
[∃]-proof {P(x)} ⦃ [∀].elim proof{x} ⦄
))
[∃!]-fn-witness : ∀{P : Domain → Domain → Formula} → ⦃ _ : Proof(∀ₗ(x ↦ ∃ₗ!(y ↦ P(x)(y)))) ⦄ → Domain → Domain
[∃!]-fn-witness{P} ⦃ proof ⦄ (x) = [∃!]-witness ⦃ [∀].elim(proof){x} ⦄
{-
[∃!]-fn-proof : ∀{P : Domain → Domain → Formula} → ⦃ p : Proof(∀ₗ(x ↦ ∃ₗ!(y ↦ P(x)(y)))) ⦄ → Proof(∀ₗ(x ↦ P(x)([∃!]-fn-witness{P} ⦃ p ⦄ (x))))
[∃!]-fn-proof{P} ⦃ proof ⦄ =
([∀].intro(\{x} →
[∃!]-proof {P(x)} ⦃ [∀].elim proof{x} ⦄
))
-}
[∃!]-fn-proof : ∀{P : Domain → Domain → Formula} → ⦃ p : Proof(∀ₗ(x ↦ ∃ₗ!(y ↦ P(x)(y)))) ⦄ → ∀{x} → Proof(P(x)([∃!]-fn-witness{P} ⦃ p ⦄ (x)))
[∃!]-fn-proof{P} ⦃ proof ⦄ {x} =
[∃!]-proof {P(x)} ⦃ [∀].elim proof{x} ⦄
postulate [∃!]-fn-unique : ∀{P : Domain → Domain → Formula} → ⦃ p : Proof(∀ₗ(x ↦ ∃ₗ!(y ↦ P(x)(y)))) ⦄ → ∀{x} → Proof(∀ₗ(y ↦ P(x)(y) ⟶ (y ≡ [∃!]-fn-witness{P} ⦃ p ⦄ (x))))
| {
"alphanum_fraction": 0.4217240525,
"avg_line_length": 35.4122807018,
"ext": "agda",
"hexsha": "20aad6ce089d86b2754c8dc1a1d1b0ae6f7c5160",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Structure/Logic/Classical/NaturalDeduction/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Structure/Logic/Classical/NaturalDeduction/Proofs.agda",
"max_line_length": 170,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Structure/Logic/Classical/NaturalDeduction/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 4460,
"size": 8074
} |
{-# OPTIONS --without-K #-}
-- Note that this is properly named, but it does depend on our version of
-- Equiv and TypeEquiv for a number of things.
module Data.SumProd.Properties where
open import Data.Empty using (⊥)
open import Data.Unit using (⊤)
open import Data.Sum using (_⊎_; inj₁; inj₂) renaming (map to map⊎)
open import Data.Product using (_×_; _,_) renaming (map to map×)
import Relation.Binary.PropositionalEquality as P using (_≡_; refl)
open import Function using (id; _∘_)
open import Equiv using (_∼_; sym∼)
open import TypeEquiv
using (unite₊; uniti₊; swap₊; assocl₊; assocr₊;
unite⋆; uniti⋆; unite⋆′; uniti⋆′; swap⋆; assocl⋆; assocr⋆;
distz; distzr; factorz; factorzr;
dist; factor; distl; factorl)
infixr 1 _⊎→_
infixr 4 _×→_
_⊎→_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
(A → C) → (B → D) → (A ⊎ B → C ⊎ D)
_⊎→_ = map⊎
_×→_ : ∀ {a b p q}
{A : Set a} {B : Set b} {P : Set p} {Q : Set q} →
(A → B) → (P → Q) → (A × P) → (B × Q)
f ×→ g = λ { (x , y) → (f x , g y) }
------------------------------------------------------------------------------
-- Note that all these lemmas are "simple" in the sense that they
-- are all about map⊎ rather than [_,_]
distl-coh : {A B C D E F : Set} →
{f : A → D} {g : B → E} {h : C → F} →
distl ∘ (f ×→ (g ⊎→ h)) ∼ ((f ×→ g) ⊎→ (f ×→ h)) ∘ distl
distl-coh (a , inj₁ x) = P.refl
distl-coh (a , inj₂ y) = P.refl
factorl-coh : {A B C D E F : Set} →
{f : A → D} {g : B → E} {h : C → F} →
(f ×→ (g ⊎→ h)) ∘ factorl ∼ factorl ∘ ((f ×→ g) ⊎→ (f ×→ h))
factorl-coh (inj₁ (a , b)) = P.refl
factorl-coh (inj₂ (a , c)) = P.refl
dist-coh : {A B C D E F : Set} →
{f : A → D} {g : B → E} {h : C → F} →
dist ∘ ((f ⊎→ g) ×→ h) ∼ ((f ×→ h) ⊎→ (g ×→ h)) ∘ dist
dist-coh (inj₁ x , c) = P.refl
dist-coh (inj₂ y , c) = P.refl
factor-coh : {A B C D E F : Set} →
{f : A → D} {g : B → E} {h : C → F} →
((f ⊎→ g) ×→ h) ∘ factor ∼ factor ∘ ((f ×→ h) ⊎→ (g ×→ h))
factor-coh (inj₁ x) = P.refl
factor-coh (inj₂ y) = P.refl
-- note how this is true without relying on ⊥ as input
distzr-coh : {A B : Set} → {f : A → B} → {g : ⊥ → ⊥} →
distzr ∘ (f ×→ g) ∼ g ∘ distzr
distzr-coh _ = P.refl
-- but this is only true because of ⊥
factorzr-coh : {A B : Set} → {f : B → A} → {g : ⊥ → ⊥} →
(f ×→ g) ∘ factorzr ∼ factorzr ∘ g
factorzr-coh ()
-- note how this is true without relying on ⊥ as input
distz-coh : {A B : Set} → {f : A → B} → {g : ⊥ → ⊥} →
distz ∘ (g ×→ f) ∼ g ∘ distz
distz-coh _ = P.refl
-- but this is only true because of ⊥
factorz-coh : {A B : Set} → {f : B → A} → {g : ⊥ → ⊥} →
(g ×→ f) ∘ factorz ∼ factorz ∘ g
factorz-coh ()
---------------------------------------------------------------
-- various coherence lemmas
-- These will be named for the action they perform on the
-- underlying type, rather than for the program they
-- represent.
A×[B⊎C]→[A×C]⊎[A×B] : {A B C : Set} →
distl ∘ (id {A = A} ×→ swap₊ {B} {C}) ∼ swap₊ ∘ distl
A×[B⊎C]→[A×C]⊎[A×B] (x , inj₁ y) = P.refl
A×[B⊎C]→[A×C]⊎[A×B] (x , inj₂ y) = P.refl
[A×C]⊎[A×B]→A×[B⊎C] : {A B C : Set} →
(id ×→ swap₊) ∘ factorl ∼ factorl ∘ swap₊ {A × C} {A × B}
[A×C]⊎[A×B]→A×[B⊎C] (inj₁ x) = P.refl
[A×C]⊎[A×B]→A×[B⊎C] (inj₂ y) = P.refl
[A⊎B]×C→[C×A]⊎[C×B] : {A B C : Set} →
(swap⋆ ⊎→ swap⋆) ∘ dist ∼ distl ∘ swap⋆ {A ⊎ B} {C}
[A⊎B]×C→[C×A]⊎[C×B] (inj₁ x , z) = P.refl
[A⊎B]×C→[C×A]⊎[C×B] (inj₂ y , z) = P.refl
[C×A]⊎[C×B]→[A⊎B]×C : {A B C : Set} →
factor ∘ (swap⋆ {C} {A} ⊎→ swap⋆ {C} {B}) ∼ swap⋆ ∘ factorl
[C×A]⊎[C×B]→[A⊎B]×C (inj₁ x) = P.refl
[C×A]⊎[C×B]→[A⊎B]×C (inj₂ y) = P.refl
-- × binds tighter than ⊎ (in the name)
[A⊎B⊎C]×D→[A×D⊎B×D]⊎C×D : {A B C D : Set} →
(dist ⊎→ id) ∘ dist ∘ (assocl₊ {A} {B} {C} ×→ id {A = D}) ∼
assocl₊ ∘ (id ⊎→ dist) ∘ dist
[A⊎B⊎C]×D→[A×D⊎B×D]⊎C×D (inj₁ x , d) = P.refl
[A⊎B⊎C]×D→[A×D⊎B×D]⊎C×D (inj₂ (inj₁ x) , d) = P.refl
[A⊎B⊎C]×D→[A×D⊎B×D]⊎C×D (inj₂ (inj₂ y) , d) = P.refl
[A×D⊎B×D]⊎C×D→[A⊎B⊎C]×D : {A B C D : Set} →
(assocr₊ ×→ id) ∘ factor ∘ (factor {A} {B} {D} ⊎→ id {A = C × D}) ∼
factor ∘ (id ⊎→ factor) ∘ assocr₊
[A×D⊎B×D]⊎C×D→[A⊎B⊎C]×D (inj₁ (inj₁ x)) = P.refl
[A×D⊎B×D]⊎C×D→[A⊎B⊎C]×D (inj₁ (inj₂ y)) = P.refl
[A×D⊎B×D]⊎C×D→[A⊎B⊎C]×D (inj₂ y) = P.refl
A×B×[C⊎D]→[A×B]×C⊎[A×B]×D : {A B C D : Set} →
distl ∘ assocl⋆ {A} {B} {C ⊎ D} ∼ (assocl⋆ ⊎→ assocl⋆) ∘ distl ∘ (id ×→ distl)
A×B×[C⊎D]→[A×B]×C⊎[A×B]×D (a , b , inj₁ x) = P.refl
A×B×[C⊎D]→[A×B]×C⊎[A×B]×D (a , b , inj₂ y) = P.refl
[A×B]×C⊎[A×B]×D→A×B×[C⊎D] : {A B C D : Set} →
assocr⋆ ∘ factorl {A × B} {C} {D} ∼ (id ×→ factorl) ∘ factorl ∘ (assocr⋆ ⊎→ assocr⋆)
[A×B]×C⊎[A×B]×D→A×B×[C⊎D] (inj₁ x) = P.refl
[A×B]×C⊎[A×B]×D→A×B×[C⊎D] (inj₂ y) = P.refl
-- in theory, this actually says that all ⊥ are equal!
-- the annotations can be inferred, but this makes it
-- clearer still
0×0→0 : distz {⊥} ∼ distzr {⊥}
0×0→0 (() , ())
0→0×0 : factorz {⊥} ∼ factorzr {⊥}
0→0×0 ()
0×[A⊎B]→0 : {A B : Set} →
distz ∼ unite₊ ∘ (distz ⊎→ distz) ∘ distl {⊥} {A} {B}
0×[A⊎B]→0 (() , inj₁ _)
0×[A⊎B]→0 (_ , inj₂ _) = P.refl
0→0×[A⊎B] : {A B : Set} →
factorz ∼ factorl {B = A} {B} ∘ (factorz ⊎→ factorz) ∘ uniti₊
0→0×[A⊎B] ()
0×1→0 : unite⋆′ {⊥} ∼ distz {⊤}
0×1→0 _ = P.refl
0→0×1 : uniti⋆′ {⊥} ∼ factorz {⊤}
0→0×1 ()
A×0→0 : {A : Set} → distzr {A} ∼ distz ∘ swap⋆
A×0→0 _ = P.refl
0→A×0 : {A : Set} → factorzr {A} ∼ swap⋆ ∘ factorz
0→A×0 ()
0×A×B→0 : {A B : Set} →
distz ∼ distz ∘ (distz ×→ id) ∘ assocl⋆ {⊥} {A} {B}
0×A×B→0 _ = P.refl
0→0×A×B : {A B : Set} →
factorz ∼ assocr⋆ {B = A} {B} ∘ (factorz ×→ id) ∘ factorz
0→0×A×B ()
A×0×B→0 : {A B : Set} →
distzr ∘ (id ×→ distz) ∼ distz ∘ (distzr ×→ id) ∘ assocl⋆ {A} {⊥} {B}
A×0×B→0 _ = P.refl
0→A×0×B : {A B : Set} →
(id ×→ factorz {B}) ∘ factorzr {A} ∼ assocr⋆ ∘ (factorzr ×→ id) ∘ factorz
0→A×0×B ()
A×[0+B]→A×B : {A B : Set} →
(id {A = A} ×→ unite₊ {B}) ∼ unite₊ ∘ (distzr ⊎→ id) ∘ distl
A×[0+B]→A×B (_ , inj₁ ())
A×[0+B]→A×B (_ , inj₂ _) = P.refl
A×B→A×[0+B] : {A B : Set} →
(id ×→ uniti₊) ∼ factorl ∘ (factorzr ⊎→ id) ∘ uniti₊ {A × B}
A×B→A×[0+B] (_ , _) = P.refl
1×[A⊎B]→A⊎B : {A B : Set} →
unite⋆ ∼ (unite⋆ ⊎→ unite⋆) ∘ distl {⊤} {A} {B}
1×[A⊎B]→A⊎B (tt , inj₁ x) = P.refl
1×[A⊎B]→A⊎B (tt , inj₂ y) = P.refl
A⊎B→1×[A⊎B] : {A B : Set} →
uniti⋆ ∼ factorl ∘ (uniti⋆ {A} ⊎→ uniti⋆ {B})
A⊎B→1×[A⊎B] (inj₁ x) = P.refl
A⊎B→1×[A⊎B] (inj₂ y) = P.refl
[A⊎B]×[C⊎D]→[[A×C⊎B×C]⊎A×D]⊎B×D : {A B C D : Set} →
assocl₊ ∘ (dist ⊎→ dist) ∘ distl ∼
(assocl₊ ⊎→ id) ∘ ((id ⊎→ swap₊) ⊎→ id) ∘
(assocr₊ ⊎→ id) ∘ assocl₊ ∘ (distl ⊎→ distl) ∘ dist {A} {B} {C ⊎ D}
[A⊎B]×[C⊎D]→[[A×C⊎B×C]⊎A×D]⊎B×D (inj₁ x , inj₁ x₁) = P.refl
[A⊎B]×[C⊎D]→[[A×C⊎B×C]⊎A×D]⊎B×D (inj₁ x , inj₂ y) = P.refl
[A⊎B]×[C⊎D]→[[A×C⊎B×C]⊎A×D]⊎B×D (inj₂ y , inj₁ x) = P.refl
[A⊎B]×[C⊎D]→[[A×C⊎B×C]⊎A×D]⊎B×D (inj₂ y , inj₂ y₁) = P.refl
[[A×C⊎B×C]⊎A×D]⊎B×D→[A⊎B]×[C⊎D] : {A B C D : Set} →
factorl ∘ (factor ⊎→ factor) ∘ assocr₊ ∼
factor ∘ (factorl ⊎→ factorl) ∘ assocr₊ ∘(assocl₊ ⊎→ id) ∘
((id ⊎→ swap₊) ⊎→ id) ∘ (assocr₊ {A × C} ⊎→ id {A = B × D})
[[A×C⊎B×C]⊎A×D]⊎B×D→[A⊎B]×[C⊎D] (inj₁ (inj₁ (inj₁ (a , c)))) = P.refl
[[A×C⊎B×C]⊎A×D]⊎B×D→[A⊎B]×[C⊎D] (inj₁ (inj₁ (inj₂ (b , c)))) = P.refl
[[A×C⊎B×C]⊎A×D]⊎B×D→[A⊎B]×[C⊎D] (inj₁ (inj₂ (a , d))) = P.refl
[[A×C⊎B×C]⊎A×D]⊎B×D→[A⊎B]×[C⊎D] (inj₂ (b , d)) = P.refl
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4546536224,
"avg_line_length": 34.5388127854,
"ext": "agda",
"hexsha": "e2168899a27a5d3c29c358b35e1660486e87a93e",
"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/Data/SumProd/Properties.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/Data/SumProd/Properties.agda",
"max_line_length": 87,
"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/Data/SumProd/Properties.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": 4375,
"size": 7564
} |
{-# OPTIONS --universe-polymorphism #-}
open import Categories.Category
module Categories.Object.Product {o ℓ e} (C : Category o ℓ e) where
open Category C
open Equiv
open import Function using (flip)
open import Level
open import Function using (flip)
open import Categories.Support.PropositionalEquality
open import Categories.Square
open GlueSquares C
-- Borrowed from Dan Doel's definition of products
record Product (A B : Obj) : Set (o ⊔ ℓ ⊔ e) where
infix 10 ⟨_,_⟩
field
A×B : Obj
π₁ : A×B ⇒ A
π₂ : A×B ⇒ B
⟨_,_⟩ : ∀ {C} → (C ⇒ A) → (C ⇒ B) → (C ⇒ A×B)
.commute₁ : ∀ {C} {f : C ⇒ A} {g : C ⇒ B} → π₁ ∘ ⟨ f , g ⟩ ≡ f
.commute₂ : ∀ {C} {f : C ⇒ A} {g : C ⇒ B} → π₂ ∘ ⟨ f , g ⟩ ≡ g
.universal : ∀ {C} {f : C ⇒ A} {g : C ⇒ B} {i : C ⇒ A×B}
→ π₁ ∘ i ≡ f → π₂ ∘ i ≡ g → ⟨ f , g ⟩ ≡ i
.g-η : ∀ {C} {f : C ⇒ A×B} → ⟨ π₁ ∘ f , π₂ ∘ f ⟩ ≡ f
g-η = universal refl refl
.η : ⟨ π₁ , π₂ ⟩ ≡ id
η = universal identityʳ identityʳ
.⟨⟩-cong₂ : ∀ {C} → {f f′ : C ⇒ A} {g g′ : C ⇒ B} → f ≡ f′ → g ≡ g′ → ⟨ f , g ⟩ ≡ ⟨ f′ , g′ ⟩
⟨⟩-cong₂ f≡f′ g≡g′ =
universal (trans commute₁ (sym f≡f′)) (trans commute₂ (sym g≡g′))
.⟨⟩∘ : ∀ {C D} {f : C ⇒ A} {g : C ⇒ B} {q : D ⇒ C} → ⟨ f , g ⟩ ∘ q ≡ ⟨ f ∘ q , g ∘ q ⟩
⟨⟩∘ = sym (universal (pullˡ commute₁) (pullˡ commute₂))
import Categories.Morphisms
open Categories.Morphisms C
private
module Lemmas {A B : Obj} where
open Product {A} {B} renaming (⟨_,_⟩ to _⟨_,_⟩)
repack : (p₁ p₂ : Product A B) → A×B p₁ ⇒ A×B p₂
repack p₁ p₂ = p₂ ⟨ π₁ p₁ , π₂ p₁ ⟩
.repack∘ : (p₁ p₂ p₃ : Product A B) → repack p₂ p₃ ∘ repack p₁ p₂ ≡ repack p₁ p₃
repack∘ p₁ p₂ p₃ = sym (universal p₃
(glueTrianglesʳ (commute₁ p₃) (commute₁ p₂))
(glueTrianglesʳ (commute₂ p₃) (commute₂ p₂)))
.repack≡id : (p : Product A B) → repack p p ≡ id
repack≡id p = η p
.repack-cancel : (p₁ p₂ : Product A B) → repack p₁ p₂ ∘ repack p₂ p₁ ≡ id
repack-cancel p₁ p₂ = trans (repack∘ p₂ p₁ p₂) (repack≡id p₂)
up-to-iso : ∀ {A B} → (p₁ p₂ : Product A B) → Product.A×B p₁ ≅ Product.A×B p₂
up-to-iso p₁ p₂ = record
{ f = repack p₁ p₂
; g = repack p₂ p₁
; iso = record
{ isoˡ = repack-cancel p₂ p₁
; isoʳ = repack-cancel p₁ p₂
}
}
where
open Lemmas
transport-by-iso : ∀ {A B} → (p : Product A B) → ∀ {X} → Product.A×B p ≅ X → Product A B
transport-by-iso p {X} p≅X = record
{ A×B = X
; π₁ = p.π₁ ∘ g
; π₂ = p.π₂ ∘ g
; ⟨_,_⟩ = λ h₁ h₂ → f ∘ p ⟨ h₁ , h₂ ⟩
; commute₁ = trans (cancelInner isoˡ) p.commute₁
; commute₂ = trans (cancelInner isoˡ) p.commute₂
; universal = λ {_ l r i} pfˡ pfʳ → let open HomReasoning in
begin
f ∘ p ⟨ l , r ⟩
↑⟨ ∘-resp-≡ʳ (p.⟨⟩-cong₂ pfˡ pfʳ) ⟩
f ∘ p ⟨ (p.π₁ ∘ g) ∘ i , (p.π₂ ∘ g) ∘ i ⟩
↓⟨ ∘-resp-≡ʳ (p.universal (sym assoc) (sym assoc)) ⟩
f ∘ (g ∘ i)
↓⟨ cancelLeft isoʳ ⟩
i
∎
}
where
module p = Product p
open Product using () renaming (⟨_,_⟩ to _⟨_,_⟩)
open _≅_ p≅X
Reversible : ∀ {A B} → (p : Product A B) → Product B A
Reversible p = record
{ A×B = p.A×B
; π₁ = p.π₂
; π₂ = p.π₁
; ⟨_,_⟩ = flip p.⟨_,_⟩
; commute₁ = p.commute₂
; commute₂ = p.commute₁
; universal = flip p.universal
}
where module p = Product p
Commutative : ∀ {A B} (p₁ : Product A B) (p₂ : Product B A) → Product.A×B p₁ ≅ Product.A×B p₂
Commutative p₁ p₂ = up-to-iso p₁ (Reversible p₂)
Associable : ∀ {X Y Z} (p₁ : Product X Y) (p₂ : Product Y Z) (p₃ : Product X (Product.A×B p₂)) → Product (Product.A×B p₁) Z
Associable p₁ p₂ p₃ = record
{ A×B = A×B p₃
; π₁ = p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩
; π₂ = π₂ p₂ ∘ π₂ p₃
; ⟨_,_⟩ = λ f g → p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩
; commute₁ = λ {_ f g} → let open HomReasoning in begin
p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩ ∘ p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩
↓⟨ ⟨⟩∘ p₁ ⟩
p₁ ⟨ π₁ p₃ ∘ p₃ ⟨ π₁ p₁ ∘ f , _ ⟩ , (π₁ p₂ ∘ π₂ p₃) ∘ p₃ ⟨ _ , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ ⟩
↓⟨ ⟨⟩-cong₂ p₁ (commute₁ p₃) (glueTrianglesˡ (commute₁ p₂) (commute₂ p₃)) ⟩
p₁ ⟨ π₁ p₁ ∘ f , π₂ p₁ ∘ f ⟩
↓⟨ g-η p₁ ⟩
f
∎
; commute₂ = λ {_ f g} → glueTrianglesˡ (commute₂ p₂) (commute₂ p₃)
; universal = λ {D l r i} pfˡ pfʳ → let open HomReasoning in begin
p₃ ⟨ π₁ p₁ ∘ l , p₂ ⟨ π₂ p₁ ∘ l , r ⟩ ⟩
↑⟨ ⟨⟩-cong₂ p₃ (∘-resp-≡ʳ pfˡ) (⟨⟩-cong₂ p₂ (∘-resp-≡ʳ pfˡ) pfʳ) ⟩
p₃ ⟨ π₁ p₁ ∘ (p₁ ⟨ π₁ p₃ , _ ⟩ ∘ i) , p₂ ⟨ π₂ p₁ ∘ (p₁ ⟨ _ , π₁ p₂ ∘ π₂ p₃ ⟩ ∘ i) , (π₂ p₂ ∘ π₂ p₃) ∘ i ⟩ ⟩
↓⟨ ⟨⟩-cong₂ p₃ (pullˡ (commute₁ p₁)) (⟨⟩-cong₂ p₂ (pullˡ (commute₂ p₁)) refl) ⟩
p₃ ⟨ π₁ p₃ ∘ i , p₂ ⟨ (π₁ p₂ ∘ π₂ p₃) ∘ i , (π₂ p₂ ∘ π₂ p₃) ∘ i ⟩ ⟩
↓⟨ ⟨⟩-cong₂ p₃ refl (universal p₂ (sym assoc) (sym assoc)) ⟩
p₃ ⟨ π₁ p₃ ∘ i , π₂ p₃ ∘ i ⟩
↓⟨ g-η p₃ ⟩
i
∎
}
where
open Product renaming (⟨_,_⟩ to _⟨_,_⟩)
Associative : ∀ {X Y Z} (p₁ : Product X Y) (p₂ : Product Y Z) (p₃ : Product X (Product.A×B p₂)) (p₄ : Product (Product.A×B p₁) Z) → (Product.A×B p₃) ≅ (Product.A×B p₄)
Associative p₁ p₂ p₃ p₄ = up-to-iso (Associable p₁ p₂ p₃) p₄
open Lemmas public
Mobile : ∀ {A₁ B₁ A₂ B₂} (p : Product A₁ B₁) → A₁ ≅ A₂ → B₁ ≅ B₂ → Product A₂ B₂
Mobile p A₁≅A₂ B₁≅B₂ = record
{ A×B = p.A×B
; π₁ = f A₁≅A₂ ∘ p.π₁
; π₂ = f B₁≅B₂ ∘ p.π₂
; ⟨_,_⟩ = λ h k → p ⟨ g A₁≅A₂ ∘ h , g B₁≅B₂ ∘ k ⟩
; commute₁ = let open HomReasoning in begin
(f A₁≅A₂ ∘ p.π₁) ∘ p ⟨ g A₁≅A₂ ∘ _ , g B₁≅B₂ ∘ _ ⟩
↓⟨ pullʳ p.commute₁ ⟩
f A₁≅A₂ ∘ (g A₁≅A₂ ∘ _)
↓⟨ cancelLeft (isoʳ A₁≅A₂) ⟩
_
∎
; commute₂ = let open HomReasoning in begin
(f B₁≅B₂ ∘ p.π₂) ∘ p ⟨ g A₁≅A₂ ∘ _ , g B₁≅B₂ ∘ _ ⟩
↓⟨ pullʳ p.commute₂ ⟩
f B₁≅B₂ ∘ (g B₁≅B₂ ∘ _)
↓⟨ cancelLeft (isoʳ B₁≅B₂) ⟩
_
∎
; universal = λ pfˡ pfʳ → p.universal
(switch-fgˡ A₁≅A₂ (trans (sym assoc) pfˡ))
(switch-fgˡ B₁≅B₂ (trans (sym assoc) pfʳ))
}
where
module p = Product p
open Product renaming (⟨_,_⟩ to _⟨_,_⟩)
open _≅_
| {
"alphanum_fraction": 0.5185432676,
"avg_line_length": 32.7103825137,
"ext": "agda",
"hexsha": "e778beb7c92a5edeb304f784fdb6e06e947c4e8a",
"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/Product.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/Product.agda",
"max_line_length": 167,
"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/Product.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": 2973,
"size": 5986
} |
module Issue280 where
data PreModel (C : Set) (M : C → Set) : Set → Set where
model : (c : C) → PreModel C M (M c)
reflect : (C : Set)(M : C → Set) → PreModel C M C → C
reflect .(M c) M (model c) = c
| {
"alphanum_fraction": 0.5582524272,
"avg_line_length": 20.6,
"ext": "agda",
"hexsha": "54c9e5a09664ea704f0721a17ab0b592caa50b77",
"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/Issue280.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/Issue280.agda",
"max_line_length": 55,
"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/Issue280.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 80,
"size": 206
} |
module Div where
data True : Set where
trivial : True
data False : Set where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
NonZero : Nat -> Set
NonZero zero = False
NonZero (suc _) = True
divHelp : Nat -> Nat -> Nat -> Nat
divHelp zero zero c = suc zero
divHelp zero (suc y) c = zero
divHelp (suc x) zero c = suc (divHelp x c c)
divHelp (suc x) (suc y) c = divHelp x y c
div : (x y : Nat) -> NonZero y -> Nat
div x zero ()
div zero (suc y) _ = zero
div (suc x) (suc y) _ = divHelp (suc x) (suc y) y
n1 = suc zero
n2 = suc n1
n3 = suc n2
n4 = suc n3
n5 = suc n4
n6 = suc n5
n7 = suc n6
n8 = suc n7
n9 = suc n8
n10 = suc n9
n11 = suc n10
n12 = suc n11
| {
"alphanum_fraction": 0.5928057554,
"avg_line_length": 16.9512195122,
"ext": "agda",
"hexsha": "bfe89d433c05b71adb417752b14eb8052bbdd009",
"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/Div.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/Div.agda",
"max_line_length": 49,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Div.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": 287,
"size": 695
} |
{-# OPTIONS -v treeless.opt.final:20 -v 0 #-}
module Word where
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
open import Agda.Builtin.Word renaming (primWord64ToNat to toNat)
open import Agda.Builtin.Equality
open import Agda.Builtin.Unit
open import Agda.Builtin.IO
open import Agda.Builtin.FromNat
open import Agda.Builtin.String
open import Agda.Builtin.Strict
instance
NumWord : Number Word64
Number.Constraint NumWord _ = ⊤
fromNat {{NumWord}} n = primWord64FromNat n
NumNat : Number Nat
Number.Constraint NumNat _ = ⊤
fromNat {{NumNat}} n = n
natOp : (Nat → Nat → Nat) → Word64 → Word64 → Word64
natOp f a b = fromNat (f (toNat a) (toNat b))
{-# INLINE natOp #-}
_^_ : Nat → Nat → Nat
a ^ zero = 1
a ^ suc n = a * a ^ n
2⁶⁴ : Nat
2⁶⁴ = 2 ^ 64
{-# STATIC 2⁶⁴ #-}
addWord : Word64 → Word64 → Word64
addWord = natOp _+_
subWord : Word64 → Word64 → Word64
subWord = natOp λ a b → a + 2⁶⁴ - b
mulWord : Word64 → Word64 → Word64
mulWord = natOp _*_
{-# INLINE addWord #-}
{-# INLINE subWord #-}
{-# INLINE mulWord #-}
-- div/mod
data ⊥ : Set where
NonZero : Nat → Set
NonZero zero = ⊥
NonZero (suc _) = ⊤
div : (a b : Nat) {{nz : NonZero b}} → Nat
div a 0 {{}}
div a (suc b) = div-helper 0 b a b
mod : (a b : Nat) {{nz : NonZero b}} → Nat
mod a 0 {{}}
mod a (suc b) = mod-helper 0 b a b
{-# INLINE div #-}
{-# INLINE mod #-}
NonZeroWord : Word64 → Set
NonZeroWord a = NonZero (toNat a)
divWord : (a b : Word64) {{nz : NonZeroWord b}} → Word64
divWord a b = fromNat (div (toNat a) (toNat b))
modWord : (a b : Word64) {{nz : NonZeroWord b}} → Word64
modWord a b = fromNat (mod (toNat a) (toNat b))
{-# INLINE divWord #-}
{-# INLINE modWord #-}
-- Comparison --
eqWord : Word64 → Word64 → Bool
eqWord a b = toNat a == toNat b
ltWord : Word64 → Word64 → Bool
ltWord a b = toNat a < toNat b
{-# INLINE eqWord #-}
{-# INLINE ltWord #-}
postulate
showWord : Word64 → String
putStrLn : String → IO ⊤
{-# FOREIGN GHC import qualified Data.Text.IO #-}
{-# COMPILE GHC showWord = Data.Text.pack . show #-}
{-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn #-}
{-# COMPILE JS showWord = function(x) { return x.toString(); } #-}
{-# COMPILE JS putStrLn = function (x) { return function(cb) { process.stdout.write(x + "\n"); cb(0); }; } #-}
2^63 : Word64
2^63 = addWord 1 (divWord (subWord 0 1) 2)
test : Word64
test = addWord (addWord 2^63 100)
(addWord 2^63 1)
prf : test ≡ 101
prf = refl
prf' : eqWord test 101 ≡ true
prf' = refl
main : IO ⊤
main = putStrLn (showWord test)
-- Some checks for treeless optimisations
ltDouble : Word64 → Word64 → Bool
ltDouble x y = ltWord (mulWord 2 x) y
lt4x : Word64 → Word64 → Bool
lt4x x y = primForce (mulWord 2 x) ltDouble y
| {
"alphanum_fraction": 0.6424131627,
"avg_line_length": 22.0564516129,
"ext": "agda",
"hexsha": "d4b9a7a604d26c2b790a685268faafc6a57a3091",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Compiler/simple/Word.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Compiler/simple/Word.agda",
"max_line_length": 110,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Compiler/simple/Word.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": 930,
"size": 2735
} |
{-# OPTIONS --cubical --safe #-}
module Data.Sigma.Base where
open import Agda.Builtin.Sigma
using (Σ; _,_; fst; snd)
public
open import Level
open import Path
∃ : ∀ {a b} {A : Type a} (B : A → Type b) → Type (a ℓ⊔ b)
∃ {A = A} = Σ A
infixr 4.5 ∃-syntax
∃-syntax : ∀ {a b} {A : Type a} (B : A → Type b) → Type (a ℓ⊔ b)
∃-syntax = ∃
syntax ∃-syntax (λ x → e) = ∃[ x ] e
infixr 4.5 Σ⦂-syntax
Σ⦂-syntax : (A : Type a) (B : A → Type b) → Type (a ℓ⊔ b)
Σ⦂-syntax = Σ
syntax Σ⦂-syntax t (λ x → e) = Σ[ x ⦂ t ] e
infixr 4.5 _×_
_×_ : (A : Type a) → (B : Type b) → Type (a ℓ⊔ b)
A × B = Σ A λ _ → B
curry : ∀ {A : Type a} {B : A → Type b} {C : Σ A B → Type c} →
((p : Σ A B) → C p) →
((x : A) → (y : B x) → C (x , y))
curry f x y = f (x , y)
uncurry : ∀ {A : Type a} {B : A → Type b} {C : Σ A B → Type c} →
((x : A) → (y : B x) → C (x , y)) →
((p : Σ A B) → C p)
uncurry f (x , y) = f x y
map-Σ : ∀ {p q} {P : A → Set p} {Q : B → Set q} →
(f : A → B) → (∀ {x} → P x → Q (f x)) →
Σ A P → Σ B Q
map-Σ f g (x , y) = (f x , g y)
map₁ : (A → B) → A × C → B × C
map₁ f = map-Σ f (λ x → x)
map₁-Σ : ∀ {A : Set a} {B : Set b} {C : B → Set b}
→ (f : A → B) → Σ A (λ x → C (f x)) → Σ B C
map₁-Σ f (x , y) = f x , y
map₂ : ∀ {A : Set a} {B : A → Set b} {C : A → Set c} →
(∀ {x} → B x → C x) → Σ A B → Σ A C
map₂ f = map-Σ (λ x → x) f
∃! : ∀ {a b} {A : Type a} → (A → Type b) → Type (a ℓ⊔ b)
∃! B = ∃ λ x → B x × (∀ {y} → B y → x ≡ y)
infixr 4.5 ∃!-syntax
∃!-syntax : ∀ {a b} {A : Type a} (B : A → Type b) → Type (a ℓ⊔ b)
∃!-syntax = ∃!
syntax ∃!-syntax (λ x → e) = ∃![ x ] e
| {
"alphanum_fraction": 0.4110169492,
"avg_line_length": 25.8125,
"ext": "agda",
"hexsha": "7880ae83bb636896f827c01e5f1801a011568b9d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Sigma/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Sigma/Base.agda",
"max_line_length": 65,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Sigma/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 848,
"size": 1652
} |
{-# OPTIONS --safe --without-K #-}
module Data.Unit.UniversePolymorphic where
open import Level
record ⊤ {ℓ} : Type ℓ where instance constructor tt
| {
"alphanum_fraction": 0.7284768212,
"avg_line_length": 18.875,
"ext": "agda",
"hexsha": "d47373f73ec22a944cac73aa691be784bf5d3ded",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Unit/UniversePolymorphic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Unit/UniversePolymorphic.agda",
"max_line_length": 51,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Unit/UniversePolymorphic.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": 38,
"size": 151
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Polynomials.Multivariate.EquivCarac.Polyn-nPoly where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Data.Nat renaming (_+_ to _+n_; _·_ to _·n_)
open import Cubical.Data.Vec
open import Cubical.Data.Sigma
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.UnivariatePoly
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.Poly0-A
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.Poly1-1Poly
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.An[Am[X]]-Anm[X]
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.AB-An[X]Bn[X]
open CommRingEquivs renaming (compCommRingEquiv to _∘-ecr_ ; invCommRingEquiv to inv-ecr)
private variable
ℓ : Level
-----------------------------------------------------------------------------
-- Definition
Equiv-Polyn-nPoly : (A' : CommRing ℓ) → (n : ℕ) → CommRingEquiv (PolyCommRing A' n) (nUnivariatePoly A' n)
Equiv-Polyn-nPoly A' zero = CRE-Poly0-A A'
Equiv-Polyn-nPoly A' (suc n) = inv-ecr _ _ (CRE-PolyN∘M-PolyN+M A' 1 n)
∘-ecr (lift-equiv-poly _ _ (Equiv-Polyn-nPoly A' n) 1
∘-ecr CRE-Poly1-Poly: (nUnivariatePoly A' n))
| {
"alphanum_fraction": 0.7091412742,
"avg_line_length": 40.1111111111,
"ext": "agda",
"hexsha": "d9b39329fcc39afe713650ab478281e3eeaa8794",
"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": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/cubical",
"max_forks_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/Polyn-nPoly.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"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": "guilhermehas/cubical",
"max_issues_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/Polyn-nPoly.agda",
"max_line_length": 106,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/cubical",
"max_stars_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/Polyn-nPoly.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 428,
"size": 1444
} |
------------------------------------------------------------------------
-- Weakening for the NBE values
------------------------------------------------------------------------
import Axiom.Extensionality.Propositional as E
import Level
open import Data.Universe
-- The code makes use of the assumption that propositional equality of
-- functions is extensional.
module README.DependentlyTyped.NBE.Weakening
(Uni₀ : Universe Level.zero Level.zero)
(ext : E.Extensionality Level.zero Level.zero)
where
open import Data.Product renaming (curry to c)
open import deBruijn.Substitution.Data
open import Function.Base hiding (_∋_)
import README.DependentlyTyped.NBE.Value as Value
open Value Uni₀ renaming ([_] to [̌_])
import README.DependentlyTyped.NormalForm as NF
open NF Uni₀ renaming ([_] to [_]n)
import README.DependentlyTyped.NormalForm.Substitution as NFS
open NFS Uni₀
import README.DependentlyTyped.Term as Term; open Term Uni₀
import Relation.Binary.PropositionalEquality as P
open P.≡-Reasoning
mutual
-- Weakening.
w̌k[_] : ∀ {Γ} σ τ → V̌alue Γ τ → V̌alue (Γ ▻ σ) (τ /̂ ŵk)
w̌k[ _ ] (⋆ , τ) t = t /⊢n Renaming.wk
w̌k[ _ ] (el , τ) [ t ]el = [ t /⊢n Renaming.wk ]el
w̌k[ σ ] (π _ _ , τ) f =
(λ Γ₊ → proj₁ f (σ ◅ Γ₊)) , w̌k-π-well-behaved τ f
w̌k : ∀ {Γ σ} τ → V̌alue Γ τ → V̌alue (Γ ▻ σ) (τ /̂ ŵk)
w̌k τ v = w̌k[ _ ] τ v
abstract
-- The Π case of weakening is well-behaved.
w̌k-π-well-behaved :
∀ {Γ σ sp₁ sp₂} τ (f : V̌alue Γ (π sp₁ sp₂ , τ)) →
W̌ell-behaved sp₁ sp₂ (τ /̂I ŵk) (λ Γ₊ → proj₁ f (σ ◅ Γ₊))
w̌k-π-well-behaved {σ = σ} τ f Γ₊ v =
let lemma = begin
[ ⟦̌ τ /̂I ŵk ∣ (λ Γ₊ → proj₁ f (σ ◅ Γ₊)) ⟧-π /̂Val ŵk₊ Γ₊ ] ≡⟨ /̂Val-cong (P.sym $ w̌eaken-corresponds-π τ f) P.refl ⟩
[ ⟦̌_⟧ {σ = τ} f /̂Val ŵk[ σ ] /̂Val ŵk₊ Γ₊ ] ≡⟨ P.refl ⟩
[ ⟦̌ τ ∣ proj₁ f ⟧-π /̂Val ŵk₊ (σ ◅ Γ₊) ] ∎
in begin
[ (⟦̌ τ /̂I ŵk ∣ (λ Γ₊ → proj₁ f (σ ◅ Γ₊)) ⟧-π /̂Val ŵk₊ Γ₊ ) ˢ ⟦̌ v ⟧ ] ≡⟨ ˢ-cong lemma P.refl ⟩
[ (⟦̌ τ ∣ proj₁ f ⟧-π /̂Val ŵk₊ (σ ◅ Γ₊)) ˢ ⟦̌ v ⟧ ] ≡⟨ proj₂ f (σ ◅ Γ₊) v ⟩
[ ⟦̌ proj₁ f (σ ◅ Γ₊) v ⟧ ] ∎
-- The Π case of weakening weakens.
w̌eaken-corresponds-π :
∀ {Γ σ sp₁ sp₂} τ (f : V̌alue Γ (π sp₁ sp₂ , τ)) →
⟦̌_⟧ {σ = τ} f /̂Val ŵk[ σ ] ≅-Value
⟦̌ τ /̂I ŵk ∣ (λ Γ₊ → proj₁ f (σ ◅ Γ₊)) ⟧-π
w̌eaken-corresponds-π {σ = σ} τ f =
let f̌ = ⟦̌_⟧ {σ = τ} f
in begin
[ f̌ /̂Val ŵk[ σ ] ] ≡⟨ P.refl ⟩
[ c ((f̌ /̂Val ŵk₊ (σ ◅ fst τ /̂ ŵk ◅ ε)) ˢ lookup zero) ] ≡⟨ curry-cong $
ˢ-cong (P.refl {x = [ f̌ /̂Val ŵk₊ (σ ◅ fst τ /̂ ŵk ◅ ε) ]})
(P.sym $ ňeutral-to-normal-identity _ _) ⟩
[ c ((f̌ /̂Val ŵk₊ (σ ◅ fst τ /̂ ŵk ◅ ε)) ˢ ⟦ žero _ _ ⟧n) ] ≡⟨ curry-cong $ proj₂ f (σ ◅ fst τ /̂ ŵk ◅ ε) _ ⟩
[ c ⟦̌ proj₁ f (σ ◅ fst τ /̂ ŵk ◅ ε) (řeflect _ (var zero)) ⟧ ] ≡⟨ P.sym $ unfold-⟦̌∣⟧-π (τ /̂I ŵk) (λ Γ₊ → proj₁ f (σ ◅ Γ₊)) ⟩
[ ⟦̌ τ /̂I ŵk ∣ (λ Γ₊ → proj₁ f (σ ◅ Γ₊)) ⟧-π ] ∎
-- Weakening.
w̌eaken : ∀ {Γ} {σ : Type Γ} → [ V̌al ⟶ V̌al ] ŵk[ σ ]
w̌eaken = record
{ function = w̌k
; corresponds = corr
}
where
abstract
-- Weakening weakens.
corr : ∀ {Γ σ} τ (v : V̌alue Γ τ) →
⟦̌ v ⟧ /̂Val ŵk[ σ ] ≅-Value ⟦̌ w̌k[ σ ] τ v ⟧
corr (⋆ , τ) t = t /⊢n-lemma Renaming.wk
corr (el , τ) [ t ]el = t /⊢n-lemma Renaming.wk
corr (π sp₁ sp₂ , τ) f = w̌eaken-corresponds-π τ f
-- Variables can be turned into values.
v̌ar : [ Var ⟶⁼ V̌al ]
v̌ar = record
{ function = λ _ x → řeflect _ (var x)
; corresponds = λ _ x → P.sym $ ňeutral-to-normal-identity _ (var x)
}
-- Values can be turned into terms.
--
-- This definition uses the assumption that propositional equality of
-- functions is extensional. I don't know how much work is required to
-- avoid this assumption, or if it is even possible to do so.
V̌al↦Tm : V̌al ↦ Tm
V̌al↦Tm = record
{ trans = record
{ function = λ _ v → ⌊ řeify _ v ⌋
; corresponds = λ _ _ → P.refl
}
; simple = record
{ weaken = w̌eaken
; var = v̌ar
; weaken-var = w̌eaken-v̌ar _
}
}
where
open Renaming hiding (var)
abstract
w̌eaken-v̌ar : ∀ {Γ σ} τ (x : Γ ∋ τ) →
w̌k[ σ ] τ (v̌ar ⊙ x) ≅-V̌alue v̌ar ⊙ suc[ σ ] x
w̌eaken-v̌ar (⋆ , τ) x = begin
[̌ var (x /∋ wk) ] ≡⟨ ≅-⊢n-⇒-≅-Value-⋆ $ var-n-cong $ ≅-⊢-⇒-≅-∋ $ /∋-wk x ⟩
[̌ var (suc x) ] ∎
w̌eaken-v̌ar (el , τ) x = begin
[̌ [ var (x /∋ wk) ]el ] ≡⟨ ≅-⊢n-⇒-≅-Value-el $ var-n-cong $ ≅-⊢-⇒-≅-∋ $ /∋-wk x ⟩
[̌ [ var (suc x) ]el ] ∎
w̌eaken-v̌ar {σ = σ} (π _ _ , τ) x = ,-cong ext λ Γ₊ v → begin
[̌ řeflect _ ((var x /⊢n wk₊ (σ ◅ Γ₊)) · řeify _ v) ] ≡⟨ řeflect-cong $
·n-cong (var-n-cong $ ≅-⊢-⇒-≅-∋ $ /∋-wk₊-◅ x Γ₊)
(P.refl {x = [ řeify _ v ]n}) ⟩
[̌ řeflect _ ((var (suc x) /⊢n wk₊ Γ₊) · řeify _ v) ] ∎
module V̌al-subst = _↦_ V̌al↦Tm
| {
"alphanum_fraction": 0.4486545854,
"avg_line_length": 38.2027972028,
"ext": "agda",
"hexsha": "4d46e5f5ca856fb3e0792e1fb92a1f63bf57f377",
"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": "README/DependentlyTyped/NBE/Weakening.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": "README/DependentlyTyped/NBE/Weakening.agda",
"max_line_length": 137,
"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": "README/DependentlyTyped/NBE/Weakening.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": 2448,
"size": 5463
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Construction.Grothendieck where
-- The construction of a 1-Category from a (contravariant)
-- pseudofunctor into Cats (as a bicategory)
open import Level
open import Data.Product using (Σ; _,_)
open import Function using (_$_)
open import Relation.Binary using (IsEquivalence)
open import Categories.Category
open import Categories.Bicategory using (Bicategory)
open import Categories.Bicategory.Instance.Cats
open import Categories.Bicategory.Construction.1-Category
open import Categories.Functor renaming (id to idF)
open import Categories.Morphism using (Iso)
open import Categories.Pseudofunctor
open import Categories.NaturalTransformation hiding (id)
private
variable
o ℓ e o′ ℓ′ e′ : Level
module _ {C : Category o ℓ e} {b}
(P : Pseudofunctor (1-Category b (Category.op C)) (Cats o′ ℓ′ e′)) where
open Pseudofunctor P renaming (P₁ to PF; assoc to P-assoc)
open Functor using () renaming (F₀ to _$₀_; F₁ to _$₁_)
open NaturalTransformation
private
infix 4 _≈_ _⇒_
infixr 9 _∘_
module B = Bicategory (1-Category b (Category.op C))
module C = Category C
module _ {x y} where
open Functor (PF {x} {y}) public
renaming (F₀ to P₁; F₁ to P₂; F-resp-≈ to P-resp-≈)
open Functor
module _ {x y : C.Obj} where
open Category (P₀ x)
open HomReasoning
-- A helper lemma.
P-resp-Iso : ∀ {f g : C [ x , y ]} (eq : C [ f ≈ g ]) {a} →
Iso (P₀ x) (η (P₂ eq) a) (η (P₂ $ C.Equiv.sym eq) a)
P-resp-Iso eq {a} = record
{ isoˡ = begin
η (P₂ $ C.Equiv.sym eq) a ∘ η (P₂ eq) a ≈˘⟨ homomorphism PF ⟩
η (P₂ $ C.Equiv.trans eq (C.Equiv.sym eq)) a ≈⟨ P-resp-≈ _ ⟩
η (P₂ C.Equiv.refl) a ≈⟨ identity PF ⟩
id ∎
; isoʳ = begin
η (P₂ eq) a ∘ η (P₂ $ C.Equiv.sym eq) a ≈˘⟨ homomorphism PF ⟩
η (P₂ $ C.Equiv.trans (C.Equiv.sym eq) eq) a ≈⟨ P-resp-≈ _ ⟩
η (P₂ C.Equiv.refl) a ≈⟨ identity PF ⟩
id ∎
}
-- Objects and morphism
Obj : Set (o ⊔ o′)
Obj = Σ C.Obj (λ x → Category.Obj $ P₀ x)
_⇒_ : Obj → Obj → Set (ℓ ⊔ ℓ′)
(x₁ , a₁) ⇒ (x₂ , a₂) = Σ (x₁ C.⇒ x₂) λ f → P₀ x₁ [ a₁ , P₁ f $₀ a₂ ]
-- Pairwise equivalence
--
-- The second components of equal morphisms don't live in the same
-- homset because their domains don't agree 'on the nose'. Hence
-- the second components are equal only up to coherent iso. This
-- substantially complicates the proofs of associativity, the unit
-- laws and functionality of composition.
_≈_ : ∀ {A B} (f₁ f₂ : A ⇒ B) → Set (e ⊔ e′)
_≈_ {x₁ , a₁} {x₂ , a₂} (f₁ , g₁) (f₂ , g₂) =
Σ (f₁ C.≈ f₂) λ eq → η (P₂ $ eq) a₂ D.∘ g₁ D.≈ g₂
where module D = Category (P₀ x₁)
-- Identity and composition
id : ∀ {A} → A ⇒ A
id {_ , a} = C.id , η (unitˡ.η _) a
_∘_ : ∀ {A B C} → B ⇒ C → A ⇒ B → A ⇒ C
_∘_ {x₁ , a₁} {_ , a₂} {_ , a₃} (f₁ , g₁) (f₂ , g₂) =
f₁ C.∘ f₂ , (η (Hom.η (f₂ , f₁)) a₃ D.∘ P₁ f₂ $₁ g₁) D.∘ g₂
where module D = Category (P₀ x₁)
-- Associativity and unit laws.
--
-- Because the second component of equality only holds up to
-- coherent iso, we need to invoke the coherence conditions
-- associated with the pseudofunctor P to establish associativity.
--
-- Once we realize this, the proofs are not particularly hard, but
-- long and tedious (especially that of associativity), mostly
-- because they involve re-arranging lots of parentheses via
-- manual application of the underlying associativity laws.
assoc : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} →
(h ∘ g) ∘ f ≈ h ∘ (g ∘ f)
assoc {x₁ , _} {x₂ , _} {x₃ , a₃} {_ , a₄} {f₁ , g₁} {f₂ , g₂} {f₃ , g₃} =
C.assoc ,
(begin
η (P₂ C.assoc) a₄ ∙
(η (Hom.η (f₁ , f₃ C.∘ f₂)) a₄ ∙
P₁ f₁ $₁ ((η (Hom.η (f₂ , f₃)) a₄ E.∘ P₁ f₂ $₁ g₃) E.∘ g₂)) ∙ g₁
≈⟨ ∘-resp-≈ʳ $ ∘-resp-≈ˡ $ ∘-resp-≈ʳ $ F-resp-≈ (P₁ f₁) E.assoc ⟩
η (P₂ C.assoc) a₄ ∙
(η (Hom.η (f₁ , f₃ C.∘ f₂)) a₄ ∙
P₁ f₁ $₁ (η (Hom.η (f₂ , f₃)) a₄ E.∘ P₁ f₂ $₁ g₃ E.∘ g₂)) ∙ g₁
≈⟨ ∘-resp-≈ʳ $ ∘-resp-≈ˡ $ ∘-resp-≈ʳ $ homomorphism (P₁ f₁) ⟩
η (P₂ C.assoc) a₄ ∙
(η (Hom.η (f₁ , f₃ C.∘ f₂)) a₄ ∙
P₁ f₁ $₁ η (Hom.η (f₂ , f₃)) a₄ ∙
P₁ f₁ $₁ (P₁ f₂ $₁ g₃ E.∘ g₂)) ∙ g₁
≈˘⟨ D.assoc then
D.Equiv.sym $ ∘-resp-≈ʳ D.assoc then
∘-resp-≈ʳ $ ∘-resp-≈ˡ $ D.assoc ⟩
(η (P₂ C.assoc) a₄ ∙
η (Hom.η (f₁ , f₃ C.∘ f₂)) a₄ ∙
P₁ f₁ $₁ η (Hom.η (f₂ , f₃)) a₄) ∙
P₁ f₁ $₁ (P₁ f₂ $₁ g₃ E.∘ g₂) ∙ g₁
≈˘⟨ ∘-resp-≈ˡ $ ∘-resp-≈ʳ $ ∘-resp-≈ʳ (D.identityʳ then D.identityʳ) ⟩
(η (P₂ C.assoc) a₄ ∙
η (Hom.η (f₁ , f₃ C.∘ f₂)) a₄ ∙
(P₁ f₁ $₁ η (Hom.η (f₂ , f₃)) a₄ ∙ D.id) ∙ D.id) ∙
P₁ f₁ $₁ ((P₁ f₂ $₁ g₃) E.∘ g₂) ∙ g₁
≈˘⟨ ∘-resp-≈ˡ $ ∘-resp-≈ʳ P-assoc ⟩
(η (P₂ C.assoc) a₄ ∙
η (P₂ C.sym-assoc) a₄ ∙
η (Hom.η (f₂ C.∘ f₁ , f₃)) a₄ ∙ P₁ (f₂ C.∘ f₁) $₁ F.id ∙
η (Hom.η (f₁ , f₂)) (P₁ f₃ $₀ a₄)) ∙
P₁ f₁ $₁ ((P₁ f₂ $₁ g₃) E.∘ g₂) ∙ g₁
≈˘⟨ ∘-resp-≈ˡ D.assoc ⟩
((η (P₂ C.assoc) a₄ ∙ η (P₂ C.sym-assoc) a₄) ∙
η (Hom.η (f₂ C.∘ f₁ , f₃)) a₄ ∙ P₁ (f₂ C.∘ f₁) $₁ F.id ∙
η (Hom.η (f₁ , f₂)) (P₁ f₃ $₀ a₄)) ∙
P₁ f₁ $₁ ((P₁ f₂ $₁ g₃) E.∘ g₂) ∙ g₁
≈⟨ ∘-resp-≈ˡ $ ∘-resp-≈ˡ $
(sym (homomorphism PF) then P-resp-≈ _ then identity PF) ⟩
(D.id ∙
η (Hom.η (f₂ C.∘ f₁ , f₃)) a₄ ∙ P₁ (f₂ C.∘ f₁) $₁ F.id ∙
η (Hom.η (f₁ , f₂)) (P₁ f₃ $₀ a₄)) ∙
P₁ f₁ $₁ ((P₁ f₂ $₁ g₃) E.∘ g₂) ∙ g₁
≈⟨ ∘-resp-≈ D.identityˡ (∘-resp-≈ˡ $ homomorphism (P₁ f₁) ) ⟩
(η (Hom.η (f₂ C.∘ f₁ , f₃)) a₄ ∙ P₁ (f₂ C.∘ f₁) $₁ F.id ∙
η (Hom.η (f₁ , f₂)) (P₁ f₃ $₀ a₄)) ∙
(P₁ f₁ $₁ (P₁ f₂ $₁ g₃) ∙ P₁ f₁ $₁ g₂) ∙ g₁
≈⟨ ∘-resp-≈ (D.Equiv.sym D.assoc) D.assoc then
D.assoc then
∘-resp-≈ʳ (D.Equiv.sym D.assoc) ⟩
(η (Hom.η (f₂ C.∘ f₁ , f₃)) a₄ ∙ P₁ (f₂ C.∘ f₁) $₁ F.id) ∙
(η (Hom.η (f₁ , f₂)) (P₁ f₃ $₀ a₄) ∙ P₁ f₁ $₁ (P₁ f₂ $₁ g₃)) ∙
P₁ f₁ $₁ g₂ ∙ g₁
≈⟨ ∘-resp-≈ʳ $ ∘-resp-≈ˡ (commute (Hom.η (f₁ , f₂)) g₃) ⟩
(η (Hom.η (f₂ C.∘ f₁ , f₃)) a₄ ∙ P₁ (f₂ C.∘ f₁) $₁ F.id) ∙
(P₁ (f₂ C.∘ f₁) $₁ g₃ ∙ η (Hom.η (f₁ , f₂)) a₃) ∙
P₁ f₁ $₁ g₂ ∙ g₁
≈⟨ ∘-resp-≈ˡ (∘-resp-≈ʳ (identity (P₁ (f₂ C.∘ f₁))) then D.identityʳ) ⟩
η (Hom.η (f₂ C.∘ f₁ , f₃)) a₄ ∙
(P₁ (f₂ C.∘ f₁) $₁ g₃ ∙ η (Hom.η (f₁ , f₂)) a₃) ∙
P₁ f₁ $₁ g₂ ∙ g₁
≈⟨ ∘-resp-≈ʳ D.assoc then
D.Equiv.sym D.assoc then
∘-resp-≈ʳ (D.Equiv.sym D.assoc) ⟩
(η (Hom.η (f₂ C.∘ f₁ , f₃)) a₄ ∙ (P₁ (f₂ C.∘ f₁) $₁ g₃)) ∙
(η (Hom.η (f₁ , f₂)) a₃ ∙ (P₁ f₁ $₁ g₂)) ∙ g₁
∎)
where
module D = Category (P₀ x₁)
module E = Category (P₀ x₂)
module F = Category (P₀ x₃)
open D renaming (_∘_ to _∙_)
infixl -5 _then_
_then_ = Equiv.trans
open HomReasoning
identityˡ : ∀ {A B} {f : A ⇒ B} → id ∘ f ≈ f
identityˡ {x₁ , _} {_ , a₂} {f , g} =
C.identityˡ ,
(begin
η (P₂ C.identityˡ) a₂ ∙
((η (Hom.η (f , C.id)) a₂ ∙ P₁ f $₁ η (unitˡ.η _) a₂) ∙ g)
≈˘⟨ D.assoc ⟩
(η (P₂ C.identityˡ) a₂ ∙
(η (Hom.η (f , C.id)) a₂ ∙ P₁ f $₁ η (unitˡ.η _) a₂)) ∙ g
≈˘⟨ ∘-resp-≈ˡ (∘-resp-≈ʳ (∘-resp-≈ʳ D.identityʳ)) ⟩
(η (P₂ C.identityˡ) a₂ ∙
(η (Hom.η (f , C.id)) a₂ ∙ (P₁ f $₁ η (unitˡ.η _) a₂ ∙ D.id))) ∙ g
≈⟨ ∘-resp-≈ˡ unitaryʳ ⟩
D.id ∙ g
≈⟨ D.identityˡ ⟩
g
∎)
where
module D = Category (P₀ x₁)
open D renaming (_∘_ to _∙_)
open HomReasoning
identityʳ : ∀ {A B} {f : A ⇒ B} → f ∘ id ≈ f
identityʳ {x₁ , a₁} {_ , a₂} {f , g} =
C.identityʳ ,
(begin
η (P₂ C.identityʳ) a₂ ∙
((η (Hom.η (C.id , f)) a₂ ∙ P₁ C.id $₁ g) ∙ η (unitˡ.η _) a₁)
≈⟨ ∘-resp-≈ʳ D.assoc ⟩
η (P₂ C.identityʳ) a₂ ∙
(η (Hom.η (C.id , f)) a₂ ∙ (P₁ C.id $₁ g ∙ η (unitˡ.η _) a₁))
≈˘⟨ ∘-resp-≈ʳ $ ∘-resp-≈ʳ $ commute (unitˡ.η _) g ⟩
η (P₂ C.identityʳ) a₂ ∙
(η (Hom.η (C.id , f)) a₂ ∙ (η (unitˡ.η _) (P₁ f $₀ a₂) ∙ g))
≈˘⟨ ∘-resp-≈ʳ D.assoc ⟩
η (P₂ C.identityʳ) a₂ ∙
((η (Hom.η (C.id , f)) a₂ ∙ η (unitˡ.η _) (P₁ f $₀ a₂)) ∙ g)
≈˘⟨ D.assoc ⟩
(η (P₂ C.identityʳ) a₂ ∙
(η (Hom.η (C.id , f)) a₂ ∙ η (unitˡ.η _) (P₁ f $₀ a₂))) ∙ g
≈˘⟨ ∘-resp-≈ˡ $ ∘-resp-≈ʳ $ ∘-resp-≈ʳ D.identityˡ ⟩
(η (P₂ C.identityʳ) a₂ ∙
(η (Hom.η (C.id , f)) a₂ ∙ (D.id ∙ η (unitˡ.η _) (P₁ f $₀ a₂)))) ∙ g
≈˘⟨ ∘-resp-≈ˡ $ ∘-resp-≈ʳ $ ∘-resp-≈ʳ $
∘-resp-≈ˡ $ identity (P₁ C.id) ⟩
(η (P₂ C.identityʳ) a₂ ∙
(η (Hom.η (C.id , f)) a₂ ∙
((P₁ C.id $₁ D.id) ∙ η (unitˡ.η _) (P₁ f $₀ a₂)))) ∙ g
≈⟨ ∘-resp-≈ˡ unitaryˡ ⟩
D.id ∙ g
≈⟨ D.identityˡ ⟩
g
∎)
where
module D = Category (P₀ x₁)
open D renaming (_∘_ to _∙_)
open HomReasoning
-- Pair-wise equality is an equivalence
refl : ∀ {A B} {f : A ⇒ B} → f ≈ f
refl {x , _} =
C.Equiv.refl , D.Equiv.trans (D.∘-resp-≈ˡ (identity PF)) D.identityˡ
where module D = Category (P₀ x)
sym : ∀ {A B} {f g : A ⇒ B} → f ≈ g → g ≈ f
sym {x₁ , _} {_ , a₂} {_ , g₁} {_ , g₂} (f₁≈f₂ , g₁≈g₂) =
C.Equiv.sym f₁≈f₂ ,
(begin
η (P₂ $ C.Equiv.sym f₁≈f₂) a₂ ∙ g₂
≈˘⟨ ∘-resp-≈ʳ g₁≈g₂ ⟩
η (P₂ $ C.Equiv.sym f₁≈f₂) a₂ ∙ η (P₂ f₁≈f₂) a₂ ∙ g₁
≈˘⟨ D.assoc ⟩
(η (P₂ $ C.Equiv.sym f₁≈f₂) a₂ ∙ η (P₂ f₁≈f₂) a₂) ∙ g₁
≈⟨ ∘-resp-≈ˡ $ Iso.isoˡ $ P-resp-Iso f₁≈f₂ ⟩
D.id ∙ g₁
≈⟨ D.identityˡ ⟩
g₁
∎)
where
module D = Category (P₀ x₁)
open D renaming (_∘_ to _∙_)
open HomReasoning
trans : ∀ {A B} {f g h : A ⇒ B} → f ≈ g → g ≈ h → f ≈ h
trans {x₁ , _} {_ , a₂} {_ , g₁} {_ , g₂} {_ , g₃}
(f₁≈f₂ , g₁≈g₂) (f₂≈f₃ , g₂≈g₃) =
C.Equiv.trans f₁≈f₂ f₂≈f₃ ,
(begin
η (P₂ $ C.Equiv.trans f₁≈f₂ f₂≈f₃) a₂ ∙ g₁
≈⟨ ∘-resp-≈ˡ $ homomorphism PF ⟩
(η (P₂ f₂≈f₃) a₂ ∙ η (P₂ f₁≈f₂) a₂) ∙ g₁
≈⟨ D.assoc ⟩
η (P₂ f₂≈f₃) a₂ ∙ η (P₂ f₁≈f₂) a₂ ∙ g₁
≈⟨ ∘-resp-≈ʳ g₁≈g₂ ⟩
η (F₁ PF f₂≈f₃) a₂ ∙ g₂
≈⟨ g₂≈g₃ ⟩
g₃
∎)
where
module D = Category (P₀ x₁)
open D renaming (_∘_ to _∙_)
open HomReasoning
≈-equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B})
≈-equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
-- Functionality of composition
--
-- The key here is to use naturality of P-homomorphism to relate
-- functionality of composition (∘) in C to functoriality of
-- composition (⊚) in (P₀ x₁).
∘-resp-≈ : ∀ {A B C} {f h : B ⇒ C} {g i : A ⇒ B} →
f ≈ h → g ≈ i → f ∘ g ≈ h ∘ i
∘-resp-≈ {x₁ , _} {x₂ , a₂} {_ , a₃}
{f₁ , g₁} {f₂ , g₂} {f₃ , g₃} {f₄ , g₄}
(f₁≈f₂ , g₁≈g₂) (f₃≈f₄ , g₃≈g₄) =
C.∘-resp-≈ f₁≈f₂ f₃≈f₄ ,
(begin
η (P₂ $ C.∘-resp-≈ f₁≈f₂ f₃≈f₄) a₃ ∙
(η (Hom.η (f₃ , f₁)) a₃ ∙ P₁ f₃ $₁ g₁) ∙ g₃
≈⟨ ∘-resp-≈ʳ D.assoc then D.Equiv.sym D.assoc ⟩
(η (P₂ $ C.∘-resp-≈ f₁≈f₂ f₃≈f₄) a₃ ∙ η (Hom.η (f₃ , f₁)) a₃) ∙
P₁ f₃ $₁ g₁ ∙ g₃
≈˘⟨ ∘-resp-≈ˡ $ Hom.commute (f₃≈f₄ , f₁≈f₂) ⟩
(η (Hom.η (f₄ , f₂)) a₃ ∙
P₁ f₄ $₁ (η (P₂ f₁≈f₂) a₃) ∙ η (P₂ f₃≈f₄) (P₁ f₁ $₀ a₃)) ∙
P₁ f₃ $₁ g₁ ∙ g₃
≈⟨ D.assoc then
∘-resp-≈ʳ D.assoc then
∘-resp-≈ʳ $ ∘-resp-≈ʳ $ Equiv.sym D.assoc ⟩
η (Hom.η (f₄ , f₂)) a₃ ∙
P₁ f₄ $₁ (η (P₂ f₁≈f₂) a₃) ∙
(η (P₂ f₃≈f₄) (P₁ f₁ $₀ a₃) ∙ P₁ f₃ $₁ g₁) ∙ g₃
≈⟨ ∘-resp-≈ʳ $ ∘-resp-≈ʳ $ ∘-resp-≈ˡ (commute (P₂ f₃≈f₄) g₁) ⟩
η (Hom.η (f₄ , f₂)) a₃ ∙
P₁ f₄ $₁ (η (P₂ f₁≈f₂) a₃) ∙
(P₁ f₄ $₁ g₁ ∙ η (P₂ f₃≈f₄) a₂) ∙ g₃
≈⟨ ∘-resp-≈ʳ $ ∘-resp-≈ʳ D.assoc then
Equiv.sym $ ∘-resp-≈ʳ $ D.assoc then
Equiv.sym $ D.assoc ⟩
(η (Hom.η (f₄ , f₂)) a₃ ∙
P₁ f₄ $₁ (η (P₂ f₁≈f₂) a₃) ∙ P₁ f₄ $₁ g₁) ∙
η (P₂ f₃≈f₄) a₂ ∙ g₃
≈˘⟨ ∘-resp-≈ˡ $ ∘-resp-≈ʳ $ homomorphism (P₁ f₄) ⟩
(η (Hom.η (f₄ , f₂)) a₃ ∙
P₁ f₄ $₁ (η (P₂ f₁≈f₂) a₃ E.∘ g₁)) ∙
η (P₂ f₃≈f₄) a₂ ∙ g₃
≈⟨ D.∘-resp-≈ (∘-resp-≈ʳ (F-resp-≈ (P₁ f₄) g₁≈g₂)) g₃≈g₄ ⟩
(η (Hom.η (f₄ , f₂)) a₃ ∙ P₁ f₄ $₁ g₂) ∙ g₄
∎)
where
module D = Category (P₀ x₁)
module E = Category (P₀ x₂)
open D renaming (_∘_ to _∙_)
infixl -5 _then_
_then_ = Equiv.trans
open HomReasoning
Grothendieck : Category (o ⊔ o′) (ℓ ⊔ ℓ′) (e ⊔ e′)
Grothendieck = record
{ Obj = Obj
; _⇒_ = _⇒_
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; assoc = assoc
; sym-assoc = sym assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identityˡ
; equiv = ≈-equiv
; ∘-resp-≈ = ∘-resp-≈
}
| {
"alphanum_fraction": 0.4467180633,
"avg_line_length": 38.0246575342,
"ext": "agda",
"hexsha": "72f734bea66eaddf49ca70318cee33c3f4b7c2fe",
"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/Category/Construction/Grothendieck.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/Category/Construction/Grothendieck.agda",
"max_line_length": 81,
"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/Category/Construction/Grothendieck.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6735,
"size": 13879
} |
------------------------------------------------------------------------
-- Embeddings
------------------------------------------------------------------------
-- Partially following the HoTT book.
{-# OPTIONS --without-K --safe #-}
open import Equality
module Embedding
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id) renaming (_∘_ to _⊚_)
open import Bijection eq using (_↔_)
open Derived-definitions-and-properties eq
open import Equivalence eq as Eq hiding (id; _∘_)
import Equivalence.Half-adjoint eq as HA
open import Excluded-middle eq
open import H-level eq
open import H-level.Closure eq
open import Injection eq as Injection using (Injective; _↣_)
open import Preimage eq using (_⁻¹_)
open import Surjection eq using (_↠_)
private
variable
a b t : Level
A B C : Type a
f x y : A
------------------------------------------------------------------------
-- Embeddings
-- The property of being an embedding.
Is-embedding : {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b)
Is-embedding f = ∀ x y → Is-equivalence (cong {x = x} {y = y} f)
-- Is-embedding is propositional (assuming extensionality).
Is-embedding-propositional :
{A : Type a} {B : Type b} {f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-proposition (Is-embedding f)
Is-embedding-propositional {b = b} ext =
Π-closure (lower-extensionality b lzero ext) 1 λ _ →
Π-closure (lower-extensionality b lzero ext) 1 λ _ →
Eq.propositional ext _
-- Embeddings.
record Embedding (From : Type f) (To : Type t) : Type (f ⊔ t) where
field
to : From → To
is-embedding : Is-embedding to
equivalence : (x ≡ y) ≃ (to x ≡ to y)
equivalence = ⟨ _ , is-embedding _ _ ⟩
-- The type family above could have been defined using Σ.
Embedding-as-Σ : Embedding A B ↔ ∃ λ (f : A → B) → Is-embedding f
Embedding-as-Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ emb → Embedding.to emb , Embedding.is-embedding emb
; from = λ { (f , is) → record { to = f; is-embedding = is } }
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Equivalences are embeddings.
Is-equivalence→Is-embedding :
Is-equivalence f → Is-embedding f
Is-equivalence→Is-embedding is-equiv _ _ =
_≃_.is-equivalence (Eq.inverse (Eq.≃-≡ Eq.⟨ _ , is-equiv ⟩))
-- Equivalences can be converted to embeddings.
≃→Embedding :
A ≃ B → Embedding A B
≃→Embedding A≃B = record
{ to = _≃_.to A≃B
; is-embedding =
Is-equivalence→Is-embedding (_≃_.is-equivalence A≃B)
}
------------------------------------------------------------------------
-- Preorder
-- Embedding is a preorder.
id : Embedding A A
id {A = A} = record
{ to = P.id
; is-embedding = λ x y →
Eq.respects-extensional-equality
cong-id
HA.id-equivalence
}
infixr 9 _∘_
_∘_ : Embedding B C → Embedding A B → Embedding A C
f ∘ g = record
{ to = to f ⊚ to g
; is-embedding = λ _ _ →
Eq.respects-extensional-equality
(cong-∘ (to f) (to g))
(HA.composition-equivalence
(is-embedding f _ _)
(is-embedding g _ _))
}
where
open Embedding
------------------------------------------------------------------------
-- Preimages
-- If f is an embedding, then f ⁻¹ y is propositional.
--
-- This result is taken (perhaps with some changes) from the proof of
-- Theorem 4.6.3 in the HoTT book (first edition).
embedding→⁻¹-propositional :
Is-embedding f →
∀ y → Is-proposition (f ⁻¹ y)
embedding→⁻¹-propositional {f = f} is-emb y (x₁ , eq₁) (x₂ , eq₂) =
let
equiv : (x₁ ≡ x₂) ≃ (f x₁ ≡ f x₂)
equiv = ⟨ _ , is-emb _ _ ⟩
x₁≡x₂ : x₁ ≡ x₂
x₁≡x₂ = _≃_.from equiv
(f x₁ ≡⟨ eq₁ ⟩
y ≡⟨ sym eq₂ ⟩∎
f x₂ ∎)
in
Σ-≡,≡→≡
x₁≡x₂
(subst (λ z → f z ≡ y) x₁≡x₂ eq₁ ≡⟨ subst-∘ (_≡ y) f x₁≡x₂ ⟩
subst (_≡ y) (cong f x₁≡x₂) eq₁ ≡⟨ cong (λ eq → subst (_≡ y) eq eq₁) $ sym $ sym-sym (cong f x₁≡x₂) ⟩
subst (_≡ y) (sym $ sym $ cong f x₁≡x₂) eq₁ ≡⟨ subst-trans (sym $ cong f x₁≡x₂) ⟩
trans (sym $ cong f x₁≡x₂) eq₁ ≡⟨ cong (λ eq → trans (sym eq) eq₁) $ _≃_.right-inverse-of equiv _ ⟩
trans (sym $ trans eq₁ (sym eq₂)) eq₁ ≡⟨ cong (flip trans eq₁) $ sym-trans eq₁ (sym eq₂) ⟩
trans (trans (sym (sym eq₂)) (sym eq₁)) eq₁ ≡⟨ trans-[trans-sym]- _ eq₁ ⟩
sym (sym eq₂) ≡⟨ sym-sym _ ⟩∎
eq₂ ∎)
------------------------------------------------------------------------
-- Injections
-- Functions that are embeddings are injective.
injective : Is-embedding f → Injective f
injective is-emb = _≃_.from ⟨ _ , is-emb _ _ ⟩
-- Embeddings are injections.
injection : Embedding A B → A ↣ B
injection f = record
{ to = Embedding.to f
; injective = injective (Embedding.is-embedding f)
}
private
-- If the domain of f is a set, then Injective f is propositional
-- (assuming extensionality).
Injective-propositional :
{A : Type a} {B : Type b} {f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-set A → Is-proposition (Injective f)
Injective-propositional {a = a} {b = b} ext A-set =
implicit-Π-closure (lower-extensionality b lzero ext) 1 λ _ →
implicit-Π-closure (lower-extensionality b lzero ext) 1 λ _ →
Π-closure (lower-extensionality a b ext) 1 λ _ →
A-set
-- For functions between sets the property of being injective is
-- logically equivalent to the property of being an embedding.
Injective⇔Is-embedding :
Is-set A → Is-set B →
(f : A → B) → Injective f ⇔ Is-embedding f
Injective⇔Is-embedding A-set B-set f = record
{ to = λ cong-f⁻¹ _ _ →
_≃_.is-equivalence $
_↠_.from (≃↠⇔ A-set B-set)
(record { from = cong-f⁻¹ })
; from = injective
}
-- For functions between sets the property of being injective is
-- equivalent to the property of being an embedding (assuming
-- extensionality).
Injective≃Is-embedding :
{A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-set A → Is-set B →
(f : A → B) → Injective f ≃ Is-embedding f
Injective≃Is-embedding ext A-set B-set f =
_↔_.to
(⇔↔≃ ext
(Injective-propositional ext A-set)
(Is-embedding-propositional ext))
(Injective⇔Is-embedding A-set B-set f)
-- If A and B are sets, then the type of injections from A to B is
-- isomorphic to the type of embeddings from A to B (assuming
-- extensionality).
↣↔Embedding :
{A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-set A → Is-set B →
(A ↣ B) ↔ Embedding A B
↣↔Embedding {A = A} {B = B} ext A-set B-set = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → record
{ to = _↣_.to f
; is-embedding =
_≃_.to (Injective≃Is-embedding ext A-set B-set _)
(_↣_.injective f)
}
; from = injection
}
; right-inverse-of = λ f →
cong (uncurry λ to (emb : Is-embedding to) →
record { to = to; is-embedding = emb })
(Σ-≡,≡→≡ (refl _)
(Is-embedding-propositional ext _ _))
}
; left-inverse-of = λ f →
cong (uncurry λ to (inj : Injective to) →
record { to = to; injective = inj })
(Σ-≡,≡→≡ (refl _)
(Injective-propositional ext A-set _ _))
}
------------------------------------------------------------------------
-- Surjections
-- If excluded middle holds, then an embedding from an inhabited type
-- can be turned into a (split) surjection in the other direction.
Embedding→↠ :
{A : Type a} {B : Type b} →
Excluded-middle (a ⊔ b) →
A → Embedding A B → B ↠ A
Embedding→↠ {A = A} {B = B} em a A↣B = record
{ logical-equivalence = record
{ to = from
; from = to
}
; right-inverse-of = from-to
}
where
open Embedding A↣B
prop : ∀ b → Is-proposition (to ⁻¹ b)
prop = embedding→⁻¹-propositional is-embedding
from : B → A
from b = case em (prop b) of λ where
(yes (a , _)) → a
(no _) → a
from-to : ∀ a → from (to a) ≡ a
from-to a with em (prop (to a))
... | (yes (a′ , to-a′≡to-a)) = injective is-embedding to-a′≡to-a
... | (no hyp) = ⊥-elim (hyp (a , refl _))
| {
"alphanum_fraction": 0.5435572752,
"avg_line_length": 30.2446808511,
"ext": "agda",
"hexsha": "d8c2e1c7e6f829f5d52b039d81897eeeb7c0b952",
"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/Embedding.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/Embedding.agda",
"max_line_length": 119,
"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/Embedding.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": 2767,
"size": 8529
} |
open import Relation.Binary.Core
module Heapsort.Impl1 {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import BBHeap _≤_ hiding (flatten)
open import BBHeap.Heapify _≤_ tot≤ trans≤
open import BHeap _≤_ hiding (flatten)
open import BHeap.Order _≤_
open import BHeap.Order.Properties _≤_
open import BHeap.Properties _≤_
open import Bound.Lower A
open import Data.List
open import OList _≤_
flatten : {b : Bound}(h : BHeap b) → Acc h → OList b
flatten lf _ = onil
flatten (nd {x = x} b≤x l r) (acc rs) = :< b≤x (flatten (merge tot≤ l r) (rs (merge tot≤ l r) (lemma-merge≤′ tot≤ b≤x l r)))
heapsort : List A → OList bot
heapsort xs = flatten (relax (heapify xs)) (≺-wf (relax (heapify xs)))
| {
"alphanum_fraction": 0.6309823678,
"avg_line_length": 33.0833333333,
"ext": "agda",
"hexsha": "2121a7ac94ccdc939dfcc25b39b1bef22223745c",
"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/Heapsort/Impl1.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/Heapsort/Impl1.agda",
"max_line_length": 124,
"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/Heapsort/Impl1.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": 280,
"size": 794
} |
module jarsec where
open import Algebra
open import Data.Bool
open import Data.Char
-- open import Data.Empty
-- open import Data.Fin
open import Data.List
open import Data.Maybe hiding (map)
open import Data.Nat
open import Data.Nat.Base
open import Data.Nat.Show
-- open import Data.Integer
open import Data.Product hiding (map)
open import Data.Sum hiding (map)
open import Data.String hiding (length)
open import Function
-- open import Data.Sum
-- open import Data.Unit
-- open import Data.Vec
open import Category.Functor
open import Relation.Binary
open import Data.Char.Base
open import Agda.Builtin.Char
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
record Parser (A : Set) : Set where
constructor mk-parser
field
parse : List Char → (List (A × (List Char)))
open Parser public
item : Parser Char
item = mk-parser λ where
[] → []
(c ∷ cs) → (c , cs) ∷ []
bind : ∀ { A B : Set } → Parser A → (A → Parser B) → Parser B
bind {A} p f = mk-parser $ λ cs →
let rs : List (A × List Char)
rs = parse p cs
in concatMap (λ x → parse (f (proj₁ x)) (proj₂ x)) rs
-- in concatMap (λ where (x , cs′) → parse (f x) cs′) rs
_>>=_ : ∀ { A B : Set } → Parser A → (A → Parser B) → Parser B
p >>= f = bind p f
_>>_ : ∀ { A B : Set } → Parser A → Parser B → Parser B
pA >> pB = pA >>= λ _ → pB
unit : ∀ { A : Set } → A → Parser A
unit a = mk-parser (λ str → ( a , str ) ∷ [])
unit* : ∀ { A : Set } → List A → Parser A
unit* xs = mk-parser (λ str → foldl (λ sum x → (x , str) ∷ sum) [] xs)
fmap : ∀ { A B : Set } → (A → B) → Parser A → Parser B
fmap f p = do
a ← p
unit (f a)
_<$>_ : ∀ { A B : Set } → (A → B) → Parser A → Parser B
f <$> p = fmap f p
_<*>_ : ∀ {A B : Set } → Parser A → Parser B → Parser ( A × B )
aP <*> bP = do
a ← aP
b ← bP
unit (a , b)
combine : { A : Set } → Parser A → Parser A → Parser A
combine p q = mk-parser (λ cs → (parse p cs) Data.List.++ (parse q cs))
failure : { A : Set } → Parser A
failure = mk-parser (λ cs → [])
option : { A : Set } → Parser A → Parser A → Parser A
option p q = mk-parser $ λ where
cs → case (parse p cs) of λ where
[] → parse q cs
result → result
{-# TERMINATING #-}
mutual
many* : { A : Set } → Parser A → Parser (List A)
many* v = option (many+ v) (unit [])
many+ : { A : Set } → Parser A → Parser (List A)
many+ v = fmap (λ { (a , list) → a ∷ list }) (v <*> (many* v))
satisfy : (Char -> Bool) -> Parser Char
satisfy f = do
c ← item
case (f c) of λ where
true → unit c
false → failure
oneOf : List Char → Parser Char
oneOf options = satisfy (flip elem options)
where
elem : Char → List Char → Bool
elem a [] = false
elem a (x ∷ xs) = case primCharEquality a x of λ where
true → true
false → elem a xs
module _ { A : Set } where
{-# TERMINATING #-}
chainl1 : Parser A → Parser (A → A → A) → Parser A
chainl1 p op = do
a ← p
rest a
where
rest : A → Parser A
rest a = option (do
f ← op
b ← p
rest (f a b)) (unit a)
chainl : { A : Set } → Parser A → Parser (A → A → A) → A → Parser A
chainl p op a = option (chainl1 p op) (unit a)
char : Char → Parser Char
char c = satisfy (primCharEquality c)
digit : Parser Char
digit = satisfy isDigit
-- TODO: Remove
∣_-_∣ : ℕ → ℕ → ℕ
∣ zero - y ∣ = y
∣ x - zero ∣ = x
∣ suc x - suc y ∣ = ∣ x - y ∣
natural : Parser ℕ
natural = natFromList <$> ((map primCharToNat) <$> (many+ digit))
where
natFromList : List ℕ → ℕ
natFromList [] = zero
natFromList (n ∷ ns) =
let len = length ns
in (∣ n - 48 ∣ + (10 * len)) + (natFromList ns)
string : String → Parser String
string str = primStringFromList <$> (string-chars (primStringToList str))
where
string-chars : List Char → Parser (List Char)
string-chars [] = unit []
string-chars (c ∷ cs) = do
char c
string-chars cs
unit (c ∷ cs)
spaces : Parser String
spaces = fmap primStringFromList (many* (oneOf (primStringToList " \n\r")))
token : { A : Set } → Parser A → Parser A
token p = do
a ← p
spaces
unit a
reserved : String → Parser String
reserved str = token (string str)
parens : { A : Set } → Parser A → Parser A
parens m = do
(reserved "(")
n ← m
(reserved ")")
unit n
--------------------------------------------------------------------------------
data Expr : Set where
Invalid : Expr
-- Var : Char → Expr
Lit : ℕ → Expr
Add : Expr → Expr → Expr
Mul : Expr → Expr → Expr
-- Add Sub : Expr → Expr → Expr
-- Mul Div : Expr → Expr → Expr
eval : Expr → ℕ
eval Invalid = 0
eval (Lit n) = n
eval (Add a b) = eval a + eval b
eval (Mul a b) = eval a * eval b
eval′ : Maybe Expr → ℕ
eval′ (just x) = eval x
eval′ nothing = 0
module _ where
{-# TERMINATING #-}
expr : Parser Expr
{-# TERMINATING #-}
term : Parser Expr
{-# TERMINATING #-}
factor : Parser Expr
infixOp : {A : Set} → String → (A → A → A) → Parser (A → A → A)
mulop : Parser (Expr → Expr → Expr)
addop : Parser (Expr → Expr → Expr)
number : Parser Expr
expr = chainl1 term addop
term = chainl1 factor mulop
factor = option number (parens expr)
infixOp x f = reserved x >> unit f
mulop = infixOp "*" Mul
addop = infixOp "+" Add
number = do
n ← natural
unit (Lit n)
runParser : { A : Set } → Parser A → String → Maybe A
runParser p str = case (parse p (primStringToList str)) of λ where
[] → nothing
(res ∷ xs) → just (proj₁ res)
run : String → Maybe Expr
run = runParser expr
do-everything : String → ℕ
do-everything str = eval′ $ run str
partial-parse : { A : Set } → Parser A → String → Maybe (List (A × List Char))
partial-parse p str with parse p (primStringToList str)
partial-parse p str | [] = nothing
partial-parse p str | xs = just xs
run-parser : { A : Set } → Parser A → List Char → Maybe (List (A × List Char))
run-parser p str = case (parse p str) of λ where
[] → nothing
xs → just xs
| {
"alphanum_fraction": 0.584924793,
"avg_line_length": 24.0528455285,
"ext": "agda",
"hexsha": "57d959e14d340c6f13d386a9fa0d342be559e4a6",
"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/jarsec.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/jarsec.agda",
"max_line_length": 80,
"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/jarsec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1931,
"size": 5917
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
open import HoTT.Identity
module HoTT.Identity.Pi where
open variables
private variable f g h : Π A P
module _ {f g : Π A P} where
-- Axiom 2.9.3 - function extensionality
postulate
happly-isequiv : isequiv (happly {f = f} {g})
module _ where
open qinv (isequiv→qinv happly-isequiv) renaming (g to happly⁻¹)
abstract
funext : f ~ g → f == g
funext = happly⁻¹
=Π-η : funext ∘ happly ~ id
=Π-η = η
=Π-β : happly ∘ funext ~ id
=Π-β = ε
=Π-equiv : f == g ≃ f ~ g
=Π-equiv = happly , happly-isequiv
funext-∙ₕ : (α : f ~ g) (β : g ~ h) → funext (α ∙ₕ β) == funext α ∙ funext β
funext-∙ₕ α β = ap funext (funext λ x → (happly (=Π-β α) x ⋆ happly (=Π-β β) x) ⁻¹) ∙ p
where
p : funext (happly (funext α) ∙ₕ happly (funext β)) == funext α ∙ funext β
p rewrite funext α rewrite funext β = =Π-η refl
funext-ap : {P : A → 𝒰 i} {Q : A → 𝒰 j} {g h : Π A P}
(f : {a : A} → P a → Q a) (α : g ~ h) →
funext (ap f ∘ α) == ap (f ∘_) (funext α)
funext-ap f α = ap (λ α → funext (ap f ∘ α)) (=Π-β α) ⁻¹ ∙ p
where
p : funext (ap f ∘ happly (funext α)) == ap (f ∘_) (funext α)
p rewrite funext α = =Π-η refl
| {
"alphanum_fraction": 0.5571428571,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "1512fc1f51f91bb639eab7d8e235215244cf3306",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Identity/Pi.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Identity/Pi.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Identity/Pi.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 546,
"size": 1260
} |
open import MJ.Types
import MJ.Classtable.Core as Core
module MJ.Syntax.Untyped {c}(Ct : Core.Classtable c) where
open import Prelude
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Data.Maybe.All as MayAll
open import Data.Vec as Vec hiding (_∈_)
open import Data.Star
open import Data.List.Most
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable
open import Data.String
import Data.Vec.All as Vec∀
open Core c
open Classtable Ct
open import MJ.Classtable.Membership Ct
open import MJ.LexicalScope Ct
NativeBinOp = ℕ → ℕ → ℕ
data Expr (n : ℕ) : Set where
new : Cid c → List (Expr n) → Expr n
unit : Expr n
null : Expr n
num : ℕ → Expr n
iop : NativeBinOp → (l r : Expr n) → Expr n
call : Expr n → String → List (Expr n) → Expr n
var : Fin n → Expr n
get : Expr n → String → Expr n
mutual
data Stmt (i : ℕ) : ℕ → Set where
loc : Ty c → Stmt i (suc i)
asgn : Fin i → Expr i → Stmt i i
set : Expr i → String → Expr i → Stmt i i
do : Expr i → Stmt i i
ret : Expr i → Stmt i i
raise : Stmt i i
try_catch_ : ∀ {o o'} → Stmt i o → Stmt i o' → Stmt i i
while_do_ : ∀ {o} → Expr i → Stmt i o → Stmt i i
block : ∀ {o} → Stmts i o → Stmt i i
Stmts : ℕ → ℕ → Set
Stmts = Star Stmt
data Body (i : ℕ) : Set where
body : ∀ {o} → Stmts i o → Expr o → Body i
-- let n be the number of formal method arguments
data Method (n : ℕ) : Set where
super⟨_⟩then_ : List (Expr (suc n)) → Body (suc (suc n)) → Method n
body : Body (suc n) → Method n
-- let n be the number of formal constructor arguments
data Constructor (n : ℕ) : Set where
super_then_ : List (Expr (suc n)) → Body (suc n) → Constructor n
body : Body (suc n) → Constructor n
record Implementation (cid : _): Set where
constructor implementation
open Class (Σ cid) public
field
construct : Constructor (length constr)
mbodies : All (λ{ (name , (as , b)) → Method (length as) }) (decls METHOD)
Classes = ∀ cid → Implementation cid
Prog : Set
Prog = Classes × (Body 0)
| {
"alphanum_fraction": 0.6199261993,
"avg_line_length": 29.2972972973,
"ext": "agda",
"hexsha": "ea5d100408f56ef4916d650441524e32105fe23f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Syntax/Untyped.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Syntax/Untyped.agda",
"max_line_length": 80,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Syntax/Untyped.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 684,
"size": 2168
} |
module DefinitionalEquality where
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
subst : {A : Set}(P : A -> Set){x y : A} -> x == y -> P y -> P x
subst {A} P refl p = p
data Nat : Set where
zero : Nat
suc : Nat -> Nat
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
-- This formulation of the associativity law guarantees that for closed n, but
-- possibly open m and p the law holds definitionally.
assoc : (n : Nat) -> (\m p -> n + (m + p)) == (\m p -> (n + m) + p)
assoc zero = refl
assoc (suc n) = subst (\ ∙ -> f ∙ == f (\m p -> ((n + m) + p)))
(assoc n) refl
where
f = \(g : Nat -> Nat -> Nat)(m p : Nat) -> suc (g m p)
| {
"alphanum_fraction": 0.4985632184,
"avg_line_length": 25.7777777778,
"ext": "agda",
"hexsha": "cfcda0f5af4dfae040993f0898a7125413d728c5",
"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/DefinitionalEquality.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/DefinitionalEquality.agda",
"max_line_length": 78,
"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/DefinitionalEquality.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": 249,
"size": 696
} |
-- Agda program using the Iowa Agda library
open import bool
module PROOF-odddoublecoin
(Choice : Set)
(choose : Choice → 𝔹)
(lchoice : Choice → Choice)
(rchoice : Choice → Choice)
where
open import eq
open import nat
open import list
open import maybe
---------------------------------------------------------------------------
-- Translated Curry operations:
add : ℕ → ℕ → ℕ
add zero x = x
add (suc y) z = suc (add y z)
-- Forward declaration:
odd : ℕ → 𝔹
even : ℕ → 𝔹
even zero = tt
even (suc x) = odd x
coin : Choice → ℕ → ℕ
coin c1 x = if choose c1 then x else suc x
double : ℕ → ℕ
double x = add x x
odd zero = ff
odd (suc x) = even x
---------------------------------------------------------------------------
add-suc : ∀ (x y : ℕ) → add x (suc y) ≡ suc (add x y)
add-suc zero y = refl
add-suc (suc x) y rewrite add-suc x y = refl
-- auxiliary property for x+x instead of double:
odd-add-x-x : ∀ (x : ℕ) → odd (add x x) ≡ ff
odd-add-x-x zero = refl
odd-add-x-x (suc x) rewrite add-suc x x | odd-add-x-x x = refl
odddoublecoin : (c1 : Choice) → (x : ℕ) → (odd (double (coin c1 x))) ≡ ff
odddoublecoin c1 x rewrite odd-add-x-x (coin c1 x) = refl
---------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5167731629,
"avg_line_length": 22.7636363636,
"ext": "agda",
"hexsha": "5a1419701d7f0deb38a51f8558a08401de1b83ab",
"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": "7905bc4f625a94a725f9f6d8a2de1140bea5e471",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "phlummox/curry-tools",
"max_forks_repo_path": "currypp/.cpm/packages/verify/examples/PROOF-odddoublecoin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7905bc4f625a94a725f9f6d8a2de1140bea5e471",
"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": "phlummox/curry-tools",
"max_issues_repo_path": "currypp/.cpm/packages/verify/examples/PROOF-odddoublecoin.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7905bc4f625a94a725f9f6d8a2de1140bea5e471",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "phlummox/curry-tools",
"max_stars_repo_path": "currypp/.cpm/packages/verify/examples/PROOF-odddoublecoin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 373,
"size": 1252
} |
{-# OPTIONS -v treeless:20 #-}
module _ where
open import Common.Prelude
f : List Nat → List Nat → Nat
f _ [] = 0
f [] (y ∷ ys) = y
f (x ∷ xs) _ = x
main : IO Unit
main = printNat (f [] [])
,, printNat (f (1 ∷ []) [])
,, printNat (f [] (2 ∷ []))
,, printNat (f (3 ∷ []) (4 ∷ []))
| {
"alphanum_fraction": 0.4330218069,
"avg_line_length": 20.0625,
"ext": "agda",
"hexsha": "f125b6ab438578337a234a56adc79f93de89b1ba",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Compiler/simple/CompileCatchAll.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Compiler/simple/CompileCatchAll.agda",
"max_line_length": 37,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Compiler/simple/CompileCatchAll.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 117,
"size": 321
} |
module Cats.Category.Product.Binary where
open import Level using (_⊔_)
open import Relation.Binary using (Rel ; IsEquivalence ; _Preserves₂_⟶_⟶_)
open import Relation.Binary.Product.Pointwise using (×-isEquivalence ; Pointwise)
open import Cats.Category.Base
open import Cats.Util.Logic.Constructive using (_∧_ ; _,_)
module Build {lo la l≈ lo′ la′ l≈′}
(C : Category lo la l≈)
(D : Category lo′ la′ l≈′)
where
infixr 9 _∘_
infixr 4 _≈_
private
module C = Category C
module D = Category D
Obj : Set (lo ⊔ lo′)
Obj = C.Obj ∧ D.Obj
_⇒_ : Obj → Obj → Set (la ⊔ la′)
(A , A′) ⇒ (B , B′) = (A C.⇒ B) ∧ (A′ D.⇒ B′)
_≈_ : ∀ {A B} → Rel (A ⇒ B) (l≈ ⊔ l≈′)
_≈_ = Pointwise C._≈_ D._≈_
id : {A : Obj} → A ⇒ A
id = C.id , D.id
_∘_ : ∀ {A B C} → B ⇒ C → A ⇒ B → A ⇒ C
(f , f′) ∘ (g , g′) = f C.∘ g , f′ D.∘ g′
equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B})
equiv = ×-isEquivalence C.equiv D.equiv
∘-resp : ∀ {A B C} → _∘_ {A} {B} {C} Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_
∘-resp (eq₁ , eq₁′) (eq₂ , eq₂′) = C.∘-resp eq₁ eq₂ , D.∘-resp eq₁′ eq₂′
id-r : ∀ {A B} {f : A ⇒ B} → f ∘ id ≈ f
id-r = C.id-r , D.id-r
id-l : ∀ {A B} {f : A ⇒ B} → id ∘ f ≈ f
id-l = C.id-l , D.id-l
assoc : ∀ {A B C D} {f : C ⇒ D} {g : B ⇒ C} {h : A ⇒ B}
→ (f ∘ g) ∘ h ≈ f ∘ (g ∘ h)
assoc = C.assoc , D.assoc
_×_ : Category (lo ⊔ lo′) (la ⊔ la′) (l≈ ⊔ l≈′)
_×_ = record
{ Obj = Obj
; _⇒_ = _⇒_
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; equiv = equiv
; ∘-resp = ∘-resp
; id-r = id-r
; id-l = id-l
; assoc = assoc
}
open Build public using (_×_)
| {
"alphanum_fraction": 0.4812348668,
"avg_line_length": 20.1463414634,
"ext": "agda",
"hexsha": "af2bedf7cb8e5449678973207e7e5e791cd4f0ca",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Category/Product/Binary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Category/Product/Binary.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Category/Product/Binary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 763,
"size": 1652
} |
module Substitution where
open import Library
open import Terms
-- VarTm n specifies whether the substitution produces variables or terms.
-- The index is used to impose an order on the constructors
-- and so pass termination checking in lift/subst.
data VarTm : ℕ → Set where
`Var : VarTm 0
`Tm : VarTm 1
max01 : ℕ → ℕ → ℕ
max01 0 m = m
max01 n m = n
_∙VT_ : ∀ {m n} → VarTm m → VarTm n → VarTm (max01 m n)
`Var ∙VT vt = vt
`Tm ∙VT vt = `Tm
VT : ∀ {m} → VarTm m → Cxt → Ty → Set
VT `Var Γ a = Var Γ a
VT `Tm Γ a = Tm Γ a
vt2tm : ∀ {Γ a m} vt → VT {m} vt Γ a → Tm Γ a
vt2tm `Var x = var x
vt2tm `Tm t = t
RenSub : ∀ {m} → VarTm m → Cxt → Cxt → Set
RenSub vt Γ Δ = ∀ {a} → Var Γ a → VT vt Δ a
mutual
-- Lifiting a substitution
lifts : ∀ {m vt Γ Δ a} → RenSub {m} vt Γ Δ → RenSub vt (a ∷ Γ) (a ∷ Δ)
lifts {vt = `Var} σ (zero) = zero
lifts {vt = `Var} σ (suc x) = suc (σ x)
lifts {vt = `Tm} σ (zero) = var (zero)
lifts {vt = `Tm} σ (suc x) = subst {vt = `Var} suc (σ x)
-- Performing a substitution
subst : ∀ {m vt Γ Δ τ} → RenSub {m} vt Γ Δ → Tm Γ τ → Tm Δ τ
subst σ (abs t) = abs (subst (lifts σ) t)
subst σ (app t u) = app (subst σ t) (subst σ u)
subst σ (var x) = vt2tm _ (σ x)
-- Performing substitution, inductive specification
data IndSubst {m vt Γ Δ} (σ : RenSub {m} vt Γ Δ) : ∀ {τ} → Tm Γ τ → Tm Δ τ → Set where
var : ∀{a t} (x : Var Γ a)
→ vt2tm _ (σ x) ≡ t
→ IndSubst σ (var x) t
abs : ∀{a b} {t : Tm (a ∷ Γ) b} {t'}
→ IndSubst (lifts σ) t t'
→ IndSubst σ (abs t) (abs t')
app : ∀{a b} {t : Tm Γ (a →̂ b)} {u t' u'}
→ IndSubst σ t t'
→ IndSubst σ u u'
→ IndSubst σ (app t u) (app t' u')
-- Performing renaming, inductive specification
data IndRen {Γ Δ} (σ : RenSub `Var Γ Δ) : ∀ {τ} → Tm Γ τ → Tm Δ τ → Set where
var : ∀{a y} (x : Var Γ a)
→ (σ x) ≡ y
→ IndRen σ (var x) (var y)
abs : ∀{a b} {t : Tm (a ∷ Γ) b} {t'}
→ IndRen (lifts σ) t t'
→ IndRen σ (abs t) (abs t')
app : ∀{a b} {t : Tm Γ (a →̂ b)} {u t' u'}
→ IndRen σ t t'
→ IndRen σ u u'
→ IndRen σ (app t u) (app t' u')
-- Logical equivalence between inductive and algorithmic substitution
IndS→prop : ∀ {m vt Γ Δ} (σ : RenSub {m} vt Γ Δ) {τ} {t : Tm Γ τ} {t' : Tm Δ τ} → IndSubst σ t t' → subst σ t ≡ t'
IndS→prop σ (var x ≡.refl) = ≡.refl
IndS→prop σ (abs t) = ≡.cong abs (IndS→prop (lifts σ) t)
IndS→prop σ (app t t₁) = ≡.cong₂ app (IndS→prop σ t) (IndS→prop σ t₁)
prop→IndS' : ∀ {m vt Γ Δ} (σ : RenSub {m} vt Γ Δ) {τ} (t : Tm Γ τ) → IndSubst σ t (subst σ t)
prop→IndS' σ (var x) = var x ≡.refl
prop→IndS' σ (abs t) = abs (prop→IndS' (lifts σ) t)
prop→IndS' σ (app t u) = app (prop→IndS' σ t) (prop→IndS' σ u)
prop→IndS : ∀ {m vt Γ Δ} (σ : RenSub {m} vt Γ Δ) {τ} {t : Tm Γ τ} {t' : Tm Δ τ} → subst σ t ≡ t' → IndSubst σ t t'
prop→IndS _ ≡.refl = prop→IndS' _ _
-- Logical equivalence between inductive and algorithmic renaming
Ind→prop : ∀ {Γ Δ} (σ : RenSub `Var Γ Δ) {τ} {t : Tm Γ τ} {t' : Tm Δ τ} → IndRen σ t t' → subst σ t ≡ t'
Ind→prop σ (var x ≡.refl) = ≡.refl
Ind→prop σ (abs t) = ≡.cong abs (Ind→prop (lifts σ) t)
Ind→prop σ (app t t₁) = ≡.cong₂ app (Ind→prop σ t) (Ind→prop σ t₁)
prop→Ind' : ∀ {Γ Δ} (σ : RenSub `Var Γ Δ) {τ} (t : Tm Γ τ) → IndRen σ t (subst σ t)
prop→Ind' σ (var x) = var x ≡.refl
prop→Ind' σ (abs t) = abs (prop→Ind' (lifts σ) t)
prop→Ind' σ (app t u) = app (prop→Ind' σ t) (prop→Ind' σ u)
prop→Ind : ∀ {Γ Δ} (σ : RenSub `Var Γ Δ) {τ} {t : Tm Γ τ} {t' : Tm Δ τ} → subst σ t ≡ t' → IndRen σ t t'
prop→Ind _ ≡.refl = prop→Ind' _ _
-- Identity substitution
ids : ∀ {i vt Γ} → RenSub {i} vt Γ Γ
ids {vt = `Var} x = x
ids {vt = `Tm } x = var x
-- substitution composition
_•s_ : ∀ {Γ₀ Γ₁ Γ₂}
{n}{vt2 : VarTm n}(τ : RenSub vt2 Γ₁ Γ₂)
{m}{vt1 : VarTm m}(σ : RenSub vt1 Γ₀ Γ₁) → RenSub (vt1 ∙VT vt2) Γ₀ Γ₂
_•s_ τ {vt1 = `Var} σ x = τ (σ x)
_•s_ τ {vt1 = `Tm } σ x = subst τ (σ x)
-- Term substitution
Subst : Cxt → Cxt → Set
Subst Γ Δ = ∀ {a : Ty} → Var Γ a → Tm Δ a
-- Extending a substitution
_∷s_ : ∀ {Γ Δ a} → Tm Γ a → Subst Δ Γ → Subst (a ∷ Δ) Γ
(t ∷s σ) (zero) = t
(t ∷s σ) (suc x) = σ x
-- Substitution for 0th variable
sgs : ∀ {Γ a} → Tm Γ a → Subst (a ∷ Γ) Γ
sgs t = t ∷s ids
-- Substituting for the 0th variable [u/0]t
subst0 : ∀ {Γ a b} → Tm Γ a → Tm (a ∷ Γ) b → Tm Γ b
subst0 u = subst (sgs u)
-- Renamings
Ren : (Γ Δ : Cxt) → Set
Ren = RenSub `Var
_≤_ : (Γ Δ : Cxt) → Set
_≤_ Γ Δ = RenSub `Var Δ Γ
rename : ∀ {Γ Δ : Cxt} {a : Ty} (η : Γ ≤ Δ) (x : Tm Δ a) → Tm Γ a
rename = subst
-- Weakening renaming
weak : ∀{Γ a} → (a ∷ Γ) ≤ Γ
weak = suc
-- Weakening substitution
weaks : ∀{n}{vt : VarTm n}{a Γ Δ} (σ : RenSub vt Γ Δ) → RenSub vt (Γ) (a ∷ Δ)
weaks {vt = `Var} σ x = suc (σ x)
weaks {vt = `Tm} σ x = rename suc (σ x)
-- Properties
_≡s_ : ∀ {Γ Δ} {m n vt1 vt2} → (f : RenSub {m} vt1 Γ Δ)(g : RenSub {n} vt2 Γ Δ) → Set
f ≡s g = (∀ {a} x → vt2tm _ (f {a} x) ≡ vt2tm _ (g x))
mutual
subst-ext : ∀ {Γ Δ} {m n vt1 vt2} {f : RenSub {m} vt1 Γ Δ}{g : RenSub {n} vt2 Γ Δ} → f ≡s g → ∀ {a} (t : Tm Γ a) → subst f t ≡ subst g t
subst-ext f≐g (var v) = (f≐g v)
subst-ext {f = f} {g = g} f≐g (abs t) = ≡.cong abs (subst-ext (lifts-ext {f = f} {g = g} f≐g) t)
subst-ext f≐g (app t t₁) = ≡.cong₂ app (subst-ext f≐g t) (subst-ext f≐g t₁)
lifts-ext : ∀ {Γ Δ b} {m n vt1 vt2} {f : RenSub {m} vt1 Γ Δ}{g : RenSub {n} vt2 Γ Δ} → f ≡s g → lifts {a = b} f ≡s lifts g
lifts-ext {vt1 = `Var} {`Var} f≐g (zero) = ≡.refl
lifts-ext {vt1 = `Var} {`Var} {f} {g} f≐g (suc x) with f x | g x | f≐g x
lifts-ext {Γ} {Δ} {b} {._} {._} {`Var} {`Var} f≐g (suc x) | z | .z | ≡.refl = ≡.refl
lifts-ext {vt1 = `Var} {`Tm} f≐g (zero) = ≡.refl
lifts-ext {vt1 = `Var} {`Tm} f≐g (suc x) rewrite ≡.sym (f≐g x) = ≡.refl
lifts-ext {vt1 = `Tm} {`Var} f≐g (zero) = ≡.refl
lifts-ext {vt1 = `Tm} {`Var} f≐g (suc x) rewrite (f≐g x) = ≡.refl
lifts-ext {vt1 = `Tm} {`Tm} f≐g (zero) = ≡.refl
lifts-ext {vt1 = `Tm} {`Tm} f≐g (suc x) = ≡.cong (subst suc) (f≐g x)
mutual
subst-∙ : ∀ {Γ₀ Γ₁ Γ₂}
{n}{vt2 : VarTm n}(τ : RenSub vt2 Γ₁ Γ₂)
{m}{vt1 : VarTm m}(σ : RenSub vt1 Γ₀ Γ₁) → ∀ {a} (t : Tm Γ₀ a) → subst (τ •s σ) t ≡ subst τ (subst σ t)
subst-∙ τ {vt1 = `Var} σ (var x) = ≡.refl
subst-∙ τ {vt1 = `Tm} σ (var x) = ≡.refl
subst-∙ τ σ (abs t) = ≡.cong abs (≡.trans (subst-ext (lifts-∙ τ σ) t) (subst-∙ (lifts τ) (lifts σ) t))
subst-∙ τ σ (app t t₁) = ≡.cong₂ app (subst-∙ τ σ t) (subst-∙ τ σ t₁)
lifts-∙ : ∀ {Γ₀ Γ₁ Γ₂}
{n}{vt2 : VarTm n}(τ : RenSub vt2 Γ₁ Γ₂)
{m}{vt1 : VarTm m}(σ : RenSub vt1 Γ₀ Γ₁) → ∀ {a} → lifts {a = a} (τ •s σ) ≡s (lifts τ •s lifts σ)
lifts-∙ {vt2 = `Var} τ {vt1 = `Var} σ (zero) = ≡.refl
lifts-∙ {vt2 = `Tm} τ {vt1 = `Var} σ (zero) = ≡.refl
lifts-∙ {vt2 = `Var} τ {vt1 = `Var} σ (suc x) = ≡.refl
lifts-∙ {vt2 = `Tm} τ {vt1 = `Var} σ (suc x) = ≡.refl
lifts-∙ {vt2 = `Var} τ {vt1 = `Tm} σ (zero) = ≡.refl
lifts-∙ {vt2 = `Tm} τ {vt1 = `Tm} σ (zero) = ≡.refl
lifts-∙ {vt2 = `Var} τ {vt1 = `Tm} σ (suc x) = ≡.trans (≡.sym (subst-∙ suc τ (σ x))) (subst-∙ (lifts τ) suc (σ x))
lifts-∙ {vt2 = `Tm} τ {vt1 = `Tm} σ (suc x) = ≡.trans (≡.sym (subst-∙ suc τ (σ x))) (subst-∙ (lifts τ) suc (σ x))
mutual
subst-id : ∀ {m vt Γ a} → (t : Tm Γ a) → subst (ids {m} {vt}) t ≡ t
subst-id {vt = `Var} (var v) = ≡.refl
subst-id {vt = `Tm} (var v) = ≡.refl
subst-id {m} {vt} {Γ} (abs t) = ≡.cong abs (≡.trans (subst-ext {n = m} {vt2 = vt} (lifts-id {m} {vt}) t) (subst-id t))
subst-id (app t t₁) = ≡.cong₂ app (subst-id t) (subst-id t₁)
lifts-id : ∀ {m vt Γ b} → lifts {a = b} (ids {m} {vt} {Γ = Γ}) ≡s ids {m} {vt} {Γ = b ∷ Γ}
lifts-id {vt = `Var} (zero) = ≡.refl
lifts-id {vt = `Var} (suc x) = ≡.refl
lifts-id {vt = `Tm} (zero) = ≡.refl
lifts-id {vt = `Tm} (suc x) = ≡.refl
sgs-lifts : ∀ {m vt Γ Δ a} {σ : RenSub {m} vt Γ Δ} {u : Tm Γ a} → (sgs (subst σ u) •s lifts σ) ≡s (σ •s sgs u)
sgs-lifts {vt = `Var} = (λ { (zero) → ≡.refl ; (suc x) → ≡.refl })
sgs-lifts {vt = `Tm} {σ = σ} {u} = (λ { (zero) → ≡.refl ; (suc x) → ≡.sym (≡.trans (≡.sym (subst-id (σ x)))
(subst-∙ (sgs (subst σ u)) {vt1 = `Var} suc (σ x))) })
sgs-lifts-term : ∀ {m vt Γ Δ a b} {σ : RenSub {m} vt Γ Δ} {u : Tm Γ a}{t : Tm (a ∷ Γ) b}
→ subst (sgs (subst σ u)) (subst (lifts σ) t) ≡ subst σ (subst (sgs u) t)
sgs-lifts-term {σ = σ} {u} {t} = (≡.trans (≡.sym (subst-∙ (sgs (subst σ u)) (lifts σ) t))
(≡.trans (subst-ext sgs-lifts t)
(subst-∙ σ (sgs u) t)))
renId : ∀ {Γ a}{t : Tm Γ a} → rename id t ≡ t
renId = subst-id _
contract : ∀ {a Γ} → RenSub `Var (a ∷ a ∷ Γ) (a ∷ Γ)
contract (zero) = zero
contract (suc x) = x
contract-sgs : ∀ {a Γ} → contract {a} {Γ} ≡s sgs (var zero)
contract-sgs (zero) = ≡.refl
contract-sgs (suc x) = ≡.refl
sgs-weak₀ : ∀ {Γ a} {u : Tm Γ a} {b} (x : Var Γ b) → sgs u (suc x) ≡ var x
sgs-weak₀ x = ≡.refl
sgs-weak₁ : ∀ {Γ a} {u : Tm Γ a} → (sgs u ∘ suc) ≡s (ids {vt = `Tm})
sgs-weak₁ x = ≡.refl
sgs-weak : ∀ {Γ a} {u : Tm Γ a} → (sgs u •s weak) ≡s (ids {vt = `Tm})
sgs-weak x = ≡.refl
cons-to-sgs : ∀ {Γ Δ a} (u : Tm Δ a) (σ : Subst Γ Δ)
→ (u ∷s σ) ≡s (sgs u •s lifts σ)
cons-to-sgs u σ (zero) = ≡.refl
cons-to-sgs u σ (suc x) = begin
σ x ≡⟨ ≡.sym (subst-id (σ x)) ⟩
subst (ids {vt = `Tm}) (σ x) ≡⟨ subst-ext (λ _ → ≡.refl) (σ x) ⟩
subst (sgs u •s weak) (σ x) ≡⟨ subst-∙ (sgs u) weak (σ x) ⟩
subst (sgs u) (subst suc (σ x))
∎
where open ≡-Reasoning
-- -}
| {
"alphanum_fraction": 0.5004088307,
"avg_line_length": 35.9705882353,
"ext": "agda",
"hexsha": "23c9c39b1cd5c8db96f094433826bba9b88879fc",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z",
"max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ryanakca/strong-normalization",
"max_forks_repo_path": "agda-aplas14/Substitution.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ryanakca/strong-normalization",
"max_issues_repo_path": "agda-aplas14/Substitution.agda",
"max_line_length": 138,
"max_stars_count": 32,
"max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ryanakca/strong-normalization",
"max_stars_repo_path": "agda-aplas14/Substitution.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z",
"num_tokens": 4681,
"size": 9784
} |
-- Andreas, 2014-09-23, later changed by someone else
-- Issue 1194, reported by marco.vax91, 2014-06-13
module _ where
module A where
data D₁ : Set where
b : D₁
c : D₁ → D₁
infix 19 c
syntax c x = ! x
module B where
data D₂ : Set where
_+_ : D₂ → D₂ → D₂
c : A.D₁ → D₂
infix 10 _+_
infix 20 c
syntax c x = ! x
open A
open B
test : D₂
test = ! b + ! b
| {
"alphanum_fraction": 0.5772151899,
"avg_line_length": 12.34375,
"ext": "agda",
"hexsha": "fa94f1e4024c9db940bf46232ff517469b2db1ba",
"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/Issue1194d.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/Issue1194d.agda",
"max_line_length": 53,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1194d.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 160,
"size": 395
} |
-- Andreas, 2017-11-01, issue #2831
-- The following pragma should trigger a warning, since the mutual block
-- does not contain anything the pragma could apply to.
{-# NO_POSITIVITY_CHECK #-}
mutual
postulate
A : Set
-- EXPECTED WARNING:
-- No positivity checking pragmas can only precede a data/record
-- definition or a mutual block (that contains a data/record
-- definition).
| {
"alphanum_fraction": 0.7358974359,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "4926ec8dfd3b846fcfa610eb111abf256e5f3c02",
"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/Issue2831.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/Issue2831.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2831.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": 97,
"size": 390
} |
open import Agda.Builtin.Unit
module Imports.Issue5583 (_ : ⊤) where
it : ∀ {A : Set} → ⦃ A ⦄ → A
it ⦃ x ⦄ = x
data X : Set where
instance x : X
| {
"alphanum_fraction": 0.582781457,
"avg_line_length": 13.7272727273,
"ext": "agda",
"hexsha": "d06648168e36676e7375c834c1b4f73173d52c0d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Imports/Issue5583.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Imports/Issue5583.agda",
"max_line_length": 38,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Imports/Issue5583.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 64,
"size": 151
} |
module Issue1760d where
-- Skipping a new-style mutual block: Anywhere before the declaration or
-- the definition of a data/record in the block (case: record).
{-# NO_POSITIVITY_CHECK #-}
record U₁ : Set
data D₁ : Set
record U₁ where
field ap : U₁ → U₁
data D₁ where
lam : (D₁ → D₁) → D₁
-- Skipping a new-style mutual block: Anywhere before the declaration or
-- the definition of a data/record in the block (case: data).
record U₂ : Set
data D₂ : Set
record U₂ where
field ap : U₂ → U₂
{-# NO_POSITIVITY_CHECK #-}
data D₂ where
lam : (D₂ → D₂) → D₂
| {
"alphanum_fraction": 0.6894736842,
"avg_line_length": 21.9230769231,
"ext": "agda",
"hexsha": "279b93ebca5c789613aef98ff6336381fc0ade5b",
"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/Issue1760d.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/Issue1760d.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1760d.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": 177,
"size": 570
} |
module IPC.Metatheory.Gentzen-BasicTarski where
open import IPC.Syntax.Gentzen public
open import IPC.Semantics.BasicTarski public
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam t) γ = λ a → eval t (γ , a)
eval (app t u) γ = eval t γ $ eval u γ
eval (pair t u) γ = eval t γ , eval u γ
eval (fst t) γ = π₁ (eval t γ)
eval (snd t) γ = π₂ (eval t γ)
eval unit γ = ∙
eval (boom t) γ = elim𝟘 (eval t γ)
eval (inl t) γ = ι₁ (eval t γ)
eval (inr t) γ = ι₂ (eval t γ)
eval (case t u v) γ = elim⊎ (eval t γ)
(λ a → eval u (γ , a))
(λ b → eval v (γ , b))
-- Correctness of evaluation with respect to conversion.
-- FIXME: How to show this?
postulate
oops₁ : ∀ {{_ : Model}} {A B Γ} {t : Γ , A ⊢ B} {u : Γ ⊢ A}
→ eval ([ top ≔ u ] t) ≡ (λ γ → eval t (γ , eval u γ))
oops₂ : ∀ {{_ : Model}} {A B Γ} {t : Γ ⊢ A ▻ B}
→ eval t ≡ (λ γ a → eval (mono⊢ (weak⊆ {A = A}) t) (γ , a) a)
oops₃ : ∀ {{_ : Model}} {A B C Γ} {t : Γ ⊢ A} {u : Γ , A ⊢ C} {v : Γ , B ⊢ C}
→ eval ([ top ≔ t ] u) ≡ (λ γ → eval u (γ , eval t γ))
oops₄ : ∀ {{_ : Model}} {A B C Γ} {t : Γ ⊢ B} {u : Γ , A ⊢ C} {v : Γ , B ⊢ C}
→ eval ([ top ≔ t ] v) ≡ (λ γ → eval v (γ , eval t γ))
oops₅ : ∀ {{_ : Model}} {A B Γ} {t : Γ ⊢ A ∨ B}
→ eval t ≡ (λ γ → elim⊎ (eval t γ) (λ a → ι₁ a) (λ b → ι₂ b))
eval✓ : ∀ {{_ : Model}} {A Γ} {t t′ : Γ ⊢ A} → t ⋙ t′ → eval t ≡ eval t′
eval✓ refl⋙ = refl
eval✓ (trans⋙ p q) = trans (eval✓ p) (eval✓ q)
eval✓ (sym⋙ p) = sym (eval✓ p)
eval✓ (conglam⋙ {A} {B} p) = cong (⟦λ⟧ {A} {B}) (eval✓ p)
eval✓ (congapp⋙ {A} {B} p q) = cong² (_⟦$⟧_ {A} {B}) (eval✓ p) (eval✓ q)
eval✓ (congpair⋙ {A} {B} p q) = cong² (_⟦,⟧_ {A} {B}) (eval✓ p) (eval✓ q)
eval✓ (congfst⋙ {A} {B} p) = cong (⟦π₁⟧ {A} {B}) (eval✓ p)
eval✓ (congsnd⋙ {A} {B} p) = cong (⟦π₂⟧ {A} {B}) (eval✓ p)
eval✓ (congboom⋙ {C} p) = cong (⟦elim𝟘⟧ {C}) (eval✓ p)
eval✓ (conginl⋙ {A} {B} p) = cong (⟦ι₁⟧ {A} {B}) (eval✓ p)
eval✓ (conginr⋙ {A} {B} p) = cong (⟦ι₂⟧ {A} {B}) (eval✓ p)
eval✓ (congcase⋙ {A} {B} {C} p q r) = cong³ (⟦elim⊎⟧ {A} {B} {C}) (eval✓ p) (eval✓ q) (eval✓ r)
eval✓ (beta▻⋙ {A} {B} {t} {u}) = sym (oops₁ {A} {B} {_} {t} {u})
eval✓ (eta▻⋙ {A} {B} {t}) = oops₂ {A} {B} {_} {t}
eval✓ beta∧₁⋙ = refl
eval✓ beta∧₂⋙ = refl
eval✓ eta∧⋙ = refl
eval✓ eta⊤⋙ = refl
eval✓ (beta∨₁⋙ {A} {B} {C} {t} {u} {v}) = sym (oops₃ {A} {B} {C} {_} {t} {u} {v})
eval✓ (beta∨₂⋙ {A} {B} {C} {t} {u} {v}) = sym (oops₄ {A} {B} {C} {_} {t} {u} {v})
eval✓ (eta∨⋙ {A} {B} {t}) = oops₅ {A} {B} {_} {t}
| {
"alphanum_fraction": 0.4091367148,
"avg_line_length": 48.0161290323,
"ext": "agda",
"hexsha": "acc84a0c2d82ea9a01a4c0e8309205b6d55d738f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "IPC/Metatheory/Gentzen-BasicTarski.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "IPC/Metatheory/Gentzen-BasicTarski.agda",
"max_line_length": 99,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "IPC/Metatheory/Gentzen-BasicTarski.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 1383,
"size": 2977
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Correctness proofs for container combinators
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Container.Combinator.Properties where
open import Axiom.Extensionality.Propositional using (Extensionality)
open import Data.Container.Core
open import Data.Container.Combinator
open import Data.Container.Relation.Unary.Any
open import Data.Empty using (⊥-elim)
open import Data.Product as Prod using (∃; _,_; proj₁; proj₂; <_,_>; uncurry; curry)
open import Data.Sum as S using (inj₁; inj₂; [_,_]′; [_,_])
open import Function as F using (_∘′_)
open import Function.Inverse as Inv using (_↔_; inverse; module Inverse)
open import Level using (_⊔_; lower)
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≗_)
-- I have proved some of the correctness statements under the
-- assumption of functional extensionality. I could have reformulated
-- the statements using suitable setoids, but I could not be bothered.
module Identity where
correct : ∀ {s p x} {X : Set x} → ⟦ id {s} {p} ⟧ X ↔ F.id X
correct {X = X} = inverse to from (λ _ → P.refl) (λ _ → P.refl)
where
to : ⟦ id ⟧ X → F.id X
to xs = proj₂ xs _
from : F.id X → ⟦ id ⟧ X
from x = (_ , λ _ → x)
module Constant (ext : ∀ {ℓ ℓ′} → Extensionality ℓ ℓ′) where
correct : ∀ {x p y} (X : Set x) {Y : Set y} → ⟦ const {x} {p ⊔ y} X ⟧ Y ↔ F.const X Y
correct {x} {y} X {Y} = inverse proj₁ from from∘to λ _ → P.refl
where
from : X → ⟦ const X ⟧ Y
from = < F.id , F.const (⊥-elim ∘′ lower) >
from∘to : (x : ⟦ const X ⟧ Y) → from (proj₁ x) ≡ x
from∘to xs = P.cong (proj₁ xs ,_) (ext (λ x → ⊥-elim (lower x)))
module Composition {s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂) where
correct : ∀ {x} {X : Set x} → ⟦ C₁ ∘ C₂ ⟧ X ↔ (⟦ C₁ ⟧ F.∘ ⟦ C₂ ⟧) X
correct {X = X} = inverse to from (λ _ → P.refl) (λ _ → P.refl)
where
to : ⟦ C₁ ∘ C₂ ⟧ X → ⟦ C₁ ⟧ (⟦ C₂ ⟧ X)
to ((s , f) , g) = (s , < f , curry (g ∘′ any) >)
from : ⟦ C₁ ⟧ (⟦ C₂ ⟧ X) → ⟦ C₁ ∘ C₂ ⟧ X
from (s , f) = ((s , proj₁ F.∘ f) , uncurry (proj₂ F.∘ f) ∘′ ◇.proof)
module Product (ext : ∀ {ℓ ℓ′} → Extensionality ℓ ℓ′)
{s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂) where
correct : ∀ {x} {X : Set x} → ⟦ C₁ × C₂ ⟧ X ↔ (⟦ C₁ ⟧ X Prod.× ⟦ C₂ ⟧ X)
correct {X = X} = inverse to from from∘to (λ _ → P.refl)
where
to : ⟦ C₁ × C₂ ⟧ X → ⟦ C₁ ⟧ X Prod.× ⟦ C₂ ⟧ X
to ((s₁ , s₂) , f) = ((s₁ , f F.∘ inj₁) , (s₂ , f F.∘ inj₂))
from : ⟦ C₁ ⟧ X Prod.× ⟦ C₂ ⟧ X → ⟦ C₁ × C₂ ⟧ X
from ((s₁ , f₁) , (s₂ , f₂)) = ((s₁ , s₂) , [ f₁ , f₂ ]′)
from∘to : from F.∘ to ≗ F.id
from∘to (s , f) =
P.cong (s ,_) (ext [ (λ _ → P.refl) , (λ _ → P.refl) ])
module IndexedProduct {i s p} {I : Set i} (Cᵢ : I → Container s p) where
correct : ∀ {x} {X : Set x} → ⟦ Π I Cᵢ ⟧ X ↔ (∀ i → ⟦ Cᵢ i ⟧ X)
correct {X = X} = inverse to from (λ _ → P.refl) (λ _ → P.refl)
where
to : ⟦ Π I Cᵢ ⟧ X → ∀ i → ⟦ Cᵢ i ⟧ X
to (s , f) = λ i → (s i , λ p → f (i , p))
from : (∀ i → ⟦ Cᵢ i ⟧ X) → ⟦ Π I Cᵢ ⟧ X
from f = (proj₁ F.∘ f , uncurry (proj₂ F.∘ f))
module Sum {s₁ s₂ p} (C₁ : Container s₁ p) (C₂ : Container s₂ p) where
correct : ∀ {x} {X : Set x} → ⟦ C₁ ⊎ C₂ ⟧ X ↔ (⟦ C₁ ⟧ X S.⊎ ⟦ C₂ ⟧ X)
correct {X = X} = inverse to from from∘to to∘from
where
to : ⟦ C₁ ⊎ C₂ ⟧ X → ⟦ C₁ ⟧ X S.⊎ ⟦ C₂ ⟧ X
to (inj₁ s₁ , f) = inj₁ (s₁ , f)
to (inj₂ s₂ , f) = inj₂ (s₂ , f)
from : ⟦ C₁ ⟧ X S.⊎ ⟦ C₂ ⟧ X → ⟦ C₁ ⊎ C₂ ⟧ X
from = [ Prod.map inj₁ F.id , Prod.map inj₂ F.id ]′
from∘to : from F.∘ to ≗ F.id
from∘to (inj₁ s₁ , f) = P.refl
from∘to (inj₂ s₂ , f) = P.refl
to∘from : to F.∘ from ≗ F.id
to∘from = [ (λ _ → P.refl) , (λ _ → P.refl) ]
module IndexedSum {i s p} {I : Set i} (C : I → Container s p) where
correct : ∀ {x} {X : Set x} → ⟦ Σ I C ⟧ X ↔ (∃ λ i → ⟦ C i ⟧ X)
correct {X = X} = inverse to from (λ _ → P.refl) (λ _ → P.refl)
where
to : ⟦ Σ I C ⟧ X → ∃ λ i → ⟦ C i ⟧ X
to ((i , s) , f) = (i , (s , f))
from : (∃ λ i → ⟦ C i ⟧ X) → ⟦ Σ I C ⟧ X
from (i , (s , f)) = ((i , s) , f)
module ConstantExponentiation {i s p} {I : Set i} (C : Container s p) where
correct : ∀ {x} {X : Set x} → ⟦ const[ I ]⟶ C ⟧ X ↔ (I → ⟦ C ⟧ X)
correct = IndexedProduct.correct (F.const C)
| {
"alphanum_fraction": 0.5104003579,
"avg_line_length": 36.6475409836,
"ext": "agda",
"hexsha": "cb2433fa7c841a6b38923c33ba9d084c19017495",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Combinator/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Combinator/Properties.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Combinator/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1897,
"size": 4471
} |
-- Occurs there are several ways to parse a left-hand side.
module AmbiguousParseForLHS where
data X : Set where
if_then_else_ : X -> X -> X -> X
if_then_ : X -> X -> X
x : X
bad : X -> X
bad (if x then if x then x else x) = x
bad _ = if x then x
| {
"alphanum_fraction": 0.5315614618,
"avg_line_length": 25.0833333333,
"ext": "agda",
"hexsha": "83544af5c095058bc168eb7f523445d628992789",
"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/fail/AmbiguousParseForLHS.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/fail/AmbiguousParseForLHS.agda",
"max_line_length": 59,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/AmbiguousParseForLHS.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": 91,
"size": 301
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Truncation
module lib.Function2 where
is-surj : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) → Type (lmax i j)
is-surj {A = A} f = ∀ b → Trunc -1 (hfiber f b)
module _ {i j k} {A : Type i} {B : Type j} {C : Type k}
{f : A → B} {g : B → C} where
abstract
∘-is-surj : is-surj g → is-surj f → is-surj (g ∘ f)
∘-is-surj g-is-surj f-is-surj c =
Trunc-rec Trunc-level
(λ{(b , gb=c) →
Trunc-rec Trunc-level
(λ{(a , fa=b) → [ a , ap g fa=b ∙ gb=c ]})
(f-is-surj b)})
(g-is-surj c)
module _ {i j} {A : Type i} {B : Type j} {f : A → B} where
abstract
equiv-is-surj : is-equiv f → is-surj f
equiv-is-surj f-is-equiv b = [ g b , f-g b ]
where open is-equiv f-is-equiv
| {
"alphanum_fraction": 0.5211608222,
"avg_line_length": 29.5357142857,
"ext": "agda",
"hexsha": "a8cadfba582df1cfc5e7dcc7c08a0ce076d37a96",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "core/lib/Function2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "core/lib/Function2.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "core/lib/Function2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 315,
"size": 827
} |
-- Not using any Floats so shouldn't need ieee754 installed.
-- .flags file contains
-- -c --ghc-flag="-hide-package ieee754"
module _ where
open import Agda.Builtin.IO
open import Agda.Builtin.Unit
postulate
return : {A : Set} → A → IO A
{-# COMPILE GHC return = \ _ -> return #-}
main : IO ⊤
main = return _
| {
"alphanum_fraction": 0.665625,
"avg_line_length": 18.8235294118,
"ext": "agda",
"hexsha": "600549fa21a6e692141f91821bfe4820757ab5b5",
"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/Issue3619.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/Issue3619.agda",
"max_line_length": 60,
"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/Issue3619.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": 92,
"size": 320
} |
module Impure.STLCRef.Eval where
open import Prelude
open import Data.Product
open import Data.List
open import Data.List.Reverse
open import Data.Nat
open import Data.Fin hiding (_<_)
open import Extensions.List as L
open import Impure.STLCRef.Syntax
open import Impure.STLCRef.Welltyped
_!!_ : ∀ {n i} → (μ : Store n) → i < length μ → ∃ (Val {n})
_!!_ {i = i} [] ()
_!!_ {i = zero} (x ∷ μ) (s≤s p) = x
_!!_ {i = suc i} (x ∷ μ) (s≤s p) = μ !! p
Config : (n : ℕ) → Set
Config n = Exp n × Store n
infixl 1 _≻_
data _≻_ : ∀ {n} → Config n → Config n → Set where
---------------------------------------
-- Reduction rules
---------------------------------------
-- β
AppAbs : ∀ {n} {A x} {e : Exp (suc n)} {μ : Store n} →
---------------------------------
(ƛ A e) · x , μ ≻ e / (sub x) , μ
-- new
RefVal : ∀ {n e} {μ : Store n} →
(v : Val e) →
--------------------------------------------
(ref e , μ) ≻ (loc (length μ) , μ ∷ʳ (, v))
-- load
DerefLoc : ∀ {n i} {μ : Store n} →
(p : i < length μ) →
---------------------------------------------------
(! (loc i) , μ) ≻ (proj₁ (μ !! p) , μ)
-- store
Assign : ∀ {i n e} {μ : Store n} →
(p : i < length μ) →
(v : Val e) →
----------------------------------------------
loc i ≔ e , μ ≻ unit , (μ L.[ fromℕ≤ p ]≔ (, v))
---------------------------------------
-- contextual closure
---------------------------------------
Ref : ∀ {n e'} {e : Exp n} {μ μ'} →
(e , μ) ≻ (e' , μ') →
---------------------------------------
(ref e) , μ ≻ (ref e') , μ'
Appₗ : ∀ {n f' e} {f : Exp n} {μ μ'} →
(f , μ) ≻ (f' , μ') →
---------------------------------------
(f · e) , μ ≻ (f' · e) , μ'
Appᵣ : ∀ {n e' e} {f : Exp n} {μ μ'} →
(e , μ) ≻ (e' , μ') →
---------------------------------------
(f · e) , μ ≻ (f · e') , μ'
Deref : ∀ {n} {e : Exp n} {e'} {μ μ'} →
e , μ ≻ e' , μ' →
---------------------------------------
! e , μ ≻ ! e' , μ'
Assign₁ : ∀ {n} {e₁ : Exp n} {e₁' e₂} {μ μ'} →
e₁ , μ ≻ e₁' , μ' →
---------------------------------------
e₁ ≔ e₂ , μ ≻ e₁' ≔ e₂ , μ'
Assign₂ : ∀ {n} {e₁ : Exp n} {e₂' e₂} {μ μ'} →
e₂ , μ ≻ e₂' , μ' →
---------------------------------------
e₁ ≔ e₂ , μ ≻ e₁ ≔ e₂' , μ'
------------------------------------------------
-- Reflexive-transitive closure of step relation
------------------------------------------------
open import Data.Star
infixl 1 _≻*_
_≻*_ : ∀ {n} → Config n → Config n → Set
c ≻* c' = Star _≻_ c c'
| {
"alphanum_fraction": 0.3002535313,
"avg_line_length": 28.4639175258,
"ext": "agda",
"hexsha": "df3bb1cd5118a062009d37a02c874f119fdd5ae2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Impure/STLCRef/Eval.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Impure/STLCRef/Eval.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Impure/STLCRef/Eval.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 907,
"size": 2761
} |
module STLC.Kovacs.NormalForm where
open import STLC.Kovacs.Embedding public
open import Category
--------------------------------------------------------------------------------
mutual
-- (Nfₑ)
renⁿᶠ : ∀ {Γ Γ′ A} → Γ′ ⊇ Γ → Γ ⊢ⁿᶠ A → Γ′ ⊢ⁿᶠ A
renⁿᶠ η (ƛ M) = ƛ (renⁿᶠ (liftₑ η) M)
renⁿᶠ η (ne M) = ne (renⁿᵉ η M)
-- (Neₑ)
renⁿᵉ : ∀ {Γ Γ′ A} → Γ′ ⊇ Γ → Γ ⊢ⁿᵉ A → Γ′ ⊢ⁿᵉ A
renⁿᵉ η (𝓋 i) = 𝓋 (getₑ η i)
renⁿᵉ η (M ∙ N) = renⁿᵉ η M ∙ renⁿᶠ η N
mutual
-- (Nf-idₑ)
idrenⁿᶠ : ∀ {Γ A} → (M : Γ ⊢ⁿᶠ A)
→ renⁿᶠ idₑ M ≡ M
idrenⁿᶠ (ƛ M) = ƛ & idrenⁿᶠ M
idrenⁿᶠ (ne M) = ne & idrenⁿᵉ M
-- (Ne-idₑ)
idrenⁿᵉ : ∀ {Γ A} → (M : Γ ⊢ⁿᵉ A)
→ renⁿᵉ idₑ M ≡ M
idrenⁿᵉ (𝓋 i) = 𝓋 & idgetₑ i
idrenⁿᵉ (M ∙ N) = _∙_ & idrenⁿᵉ M
⊗ idrenⁿᶠ N
mutual
-- (Nf-∘ₑ)
renⁿᶠ○ : ∀ {Γ Γ′ Γ″ A} → (η₁ : Γ″ ⊇ Γ′) (η₂ : Γ′ ⊇ Γ) (M : Γ ⊢ⁿᶠ A)
→ renⁿᶠ (η₂ ○ η₁) M ≡ (renⁿᶠ η₁ ∘ renⁿᶠ η₂) M
renⁿᶠ○ η₁ η₂ (ƛ M) = ƛ & renⁿᶠ○ (liftₑ η₁) (liftₑ η₂) M
renⁿᶠ○ η₁ η₂ (ne M) = ne & renⁿᵉ○ η₁ η₂ M
-- (Ne-∘ₑ)
renⁿᵉ○ : ∀ {Γ Γ′ Γ″ A} → (η₁ : Γ″ ⊇ Γ′) (η₂ : Γ′ ⊇ Γ) (M : Γ ⊢ⁿᵉ A)
→ renⁿᵉ (η₂ ○ η₁) M ≡ (renⁿᵉ η₁ ∘ renⁿᵉ η₂) M
renⁿᵉ○ η₁ η₂ (𝓋 i) = 𝓋 & get○ η₁ η₂ i
renⁿᵉ○ η₁ η₂ (M ∙ N) = _∙_ & renⁿᵉ○ η₁ η₂ M
⊗ renⁿᶠ○ η₁ η₂ N
--------------------------------------------------------------------------------
mutual
-- (⌜_⌝Nf)
embⁿᶠ : ∀ {Γ A} → Γ ⊢ⁿᶠ A → Γ ⊢ A
embⁿᶠ (ƛ M) = ƛ (embⁿᶠ M)
embⁿᶠ (ne M) = embⁿᵉ M
-- (⌜_⌝Ne)
embⁿᵉ : ∀ {Γ A} → Γ ⊢ⁿᵉ A → Γ ⊢ A
embⁿᵉ (𝓋 i) = 𝓋 i
embⁿᵉ (M ∙ N) = embⁿᵉ M ∙ embⁿᶠ N
mutual
-- (⌜⌝Nf-nat)
natembⁿᶠ : ∀ {A Γ Γ′} → (η : Γ′ ⊇ Γ) (M : Γ ⊢ⁿᶠ A)
→ (embⁿᶠ ∘ renⁿᶠ η) M ≡ (ren η ∘ embⁿᶠ) M
natembⁿᶠ η (ƛ M) = ƛ & natembⁿᶠ (liftₑ η) M
natembⁿᶠ η (ne M) = natembⁿᵉ η M
-- (⌜⌝Ne-nat)
natembⁿᵉ : ∀ {A Γ Γ′} → (η : Γ′ ⊇ Γ) (M : Γ ⊢ⁿᵉ A)
→ (embⁿᵉ ∘ renⁿᵉ η) M ≡ (ren η ∘ embⁿᵉ) M
natembⁿᵉ η (𝓋 i) = refl
natembⁿᵉ η (M ∙ N) = _∙_ & natembⁿᵉ η M
⊗ natembⁿᶠ η N
--------------------------------------------------------------------------------
renⁿᶠPsh : 𝒯 → Presheaf₀ 𝗢𝗣𝗘
renⁿᶠPsh A =
record
{ Fₓ = _⊢ⁿᶠ A
; F = renⁿᶠ
; idF = fext! idrenⁿᶠ
; F⋄ = λ η₁ η₂ → fext! (renⁿᶠ○ η₂ η₁)
}
renⁿᵉPsh : 𝒯 → Presheaf₀ 𝗢𝗣𝗘
renⁿᵉPsh A =
record
{ Fₓ = _⊢ⁿᵉ A
; F = renⁿᵉ
; idF = fext! idrenⁿᵉ
; F⋄ = λ η₁ η₂ → fext! (renⁿᵉ○ η₂ η₁)
}
embⁿᶠNT : ∀ {A} → NaturalTransformation (renⁿᶠPsh A) (renPsh A)
embⁿᶠNT =
record
{ N = embⁿᶠ
; natN = λ η → fext! (λ M → natembⁿᶠ η M)
}
embⁿᵉNT : ∀ {A} → NaturalTransformation (renⁿᵉPsh A) (renPsh A)
embⁿᵉNT =
record
{ N = embⁿᵉ
; natN = λ η → fext! (λ M → natembⁿᵉ η M)
}
--------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.40243079,
"avg_line_length": 24.6833333333,
"ext": "agda",
"hexsha": "f5a87f87f081dfcfd00bfdaaf8b0c8adf6723862",
"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": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/coquand-kovacs",
"max_forks_repo_path": "src/STLC/Kovacs/NormalForm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/coquand-kovacs",
"max_issues_repo_path": "src/STLC/Kovacs/NormalForm.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/coquand-kovacs",
"max_stars_repo_path": "src/STLC/Kovacs/NormalForm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1819,
"size": 2962
} |
------------------------------------------------------------------------------
-- Properties related with the group commutator
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module GroupTheory.Commutator.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import GroupTheory.Base
open import GroupTheory.Commutator
open import GroupTheory.PropertiesI
------------------------------------------------------------------------------
-- Kurosh (1960), p. 99.
commutatorInverse : ∀ a b → [ a , b ] · [ b , a ] ≡ ε
commutatorInverse a b =
a ⁻¹ · b ⁻¹ · a · b · (b ⁻¹ · a ⁻¹ · b · a)
≡⟨ assoc (a ⁻¹ · b ⁻¹ · a) b (b ⁻¹ · a ⁻¹ · b · a) ⟩
a ⁻¹ · b ⁻¹ · a · (b · (b ⁻¹ · a ⁻¹ · b · a))
≡⟨ ·-rightCong (·-rightCong (assoc (b ⁻¹ · a ⁻¹) b a)) ⟩
a ⁻¹ · b ⁻¹ · a · (b · (b ⁻¹ · a ⁻¹ · (b · a)))
≡⟨ ·-rightCong (·-rightCong (assoc (b ⁻¹) (a ⁻¹) (b · a))) ⟩
a ⁻¹ · b ⁻¹ · a · (b · (b ⁻¹ · (a ⁻¹ · (b · a))))
≡⟨ ·-rightCong (sym (assoc b (b ⁻¹) (a ⁻¹ · (b · a)))) ⟩
a ⁻¹ · b ⁻¹ · a · (b · b ⁻¹ · (a ⁻¹ · (b · a)))
≡⟨ ·-rightCong (·-leftCong (rightInverse b)) ⟩
a ⁻¹ · b ⁻¹ · a · (ε · (a ⁻¹ · (b · a)))
≡⟨ ·-rightCong (leftIdentity (a ⁻¹ · (b · a))) ⟩
a ⁻¹ · b ⁻¹ · a · (a ⁻¹ · (b · a))
≡⟨ assoc (a ⁻¹ · b ⁻¹) a (a ⁻¹ · (b · a)) ⟩
a ⁻¹ · b ⁻¹ · (a · (a ⁻¹ · (b · a)))
≡⟨ ·-rightCong (sym (assoc a (a ⁻¹) (b · a))) ⟩
a ⁻¹ · b ⁻¹ · (a · a ⁻¹ · (b · a))
≡⟨ ·-rightCong (·-leftCong (rightInverse a)) ⟩
a ⁻¹ · b ⁻¹ · (ε · (b · a))
≡⟨ ·-rightCong (leftIdentity (b · a)) ⟩
a ⁻¹ · b ⁻¹ · (b · a)
≡⟨ assoc (a ⁻¹) (b ⁻¹) (b · a) ⟩
a ⁻¹ · (b ⁻¹ · (b · a))
≡⟨ ·-rightCong (sym (assoc (b ⁻¹) b a)) ⟩
a ⁻¹ · ((b ⁻¹ · b) · a)
≡⟨ ·-rightCong (·-leftCong (leftInverse b)) ⟩
a ⁻¹ · (ε · a)
≡⟨ ·-rightCong (leftIdentity a) ⟩
a ⁻¹ · a
≡⟨ leftInverse a ⟩
ε ∎
------------------------------------------------------------------------------
-- References
--
-- Kurosh, A. G. (1960). The Theory of Groups. 2nd
-- ed. Vol. 1. Translated and edited by K. A. Hirsch. Chelsea
-- Publising Company.
| {
"alphanum_fraction": 0.4028082492,
"avg_line_length": 37.9833333333,
"ext": "agda",
"hexsha": "1eed7cc852e1713825e7f435059dc43890f2547c",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/GroupTheory/Commutator/PropertiesI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/GroupTheory/Commutator/PropertiesI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/GroupTheory/Commutator/PropertiesI.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": 935,
"size": 2279
} |
module BTA9 where
----------------------------------------------
-- Preliminaries: Imports and List-utilities
----------------------------------------------
open import Data.Nat hiding (_<_;_⊔_;_*_;equal)
open import Data.Bool hiding (_∧_;_∨_)
open import Function using (_∘_)
open import Data.List
open import Data.Nat.Properties
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Data.Empty
open import Lib
---------------------------------------
-- Start of the development:
---------------------------------------
-- Intro/Objective:
-------------------
-- The following development defines a (verified) specializer/partial
-- evaluator for a simply typed lambda calculus embedded in Agda using
-- deBruijn indices.
-- The residual language.
-------------------------
-- The residual language is a standard simply typed λ-calculus. The
-- types are integers,functions,pairs,and sums.
data Type : Set where
Int : Type
Fun : Type → Type → Type
--pair type on the residual type level
_•_ : Type → Type → Type
--sum type on the residual type level
_⊎_ : Type → Type → Type
Ctx = List Type
-- The type Exp describes the typed residual expressions. Variables
-- are represented by deBruijn indices that form references into the
-- typing context. The constructors and typing constraints are
-- standard.
-- TODO: citations for ``as usual'' and ``standard''
-- what?
data Exp (Γ : Ctx) : Type → Set where
EVar : ∀ {τ} → τ ∈ Γ → Exp Γ τ
EInt : ℕ → Exp Γ Int
EAdd : Exp Γ Int → Exp Γ Int -> Exp Γ Int
ELam : ∀ {τ τ'} → Exp (τ ∷ Γ) τ' → Exp Γ (Fun τ τ')
EApp : ∀ {τ τ'} → Exp Γ (Fun τ τ') → Exp Γ τ → Exp Γ τ'
_,_ : ∀ {τ τ'} → Exp Γ τ → Exp Γ τ' → Exp Γ (τ • τ')
Tl : ∀ {τ τ'} → Exp Γ τ → Exp Γ (τ ⊎ τ')
Tr : ∀ {τ τ'} → Exp Γ τ' → Exp Γ (τ ⊎ τ')
EFst : ∀ {τ τ'} → Exp Γ (τ • τ') → Exp Γ τ
ESnd : ∀ {τ τ'} → Exp Γ (τ • τ') → Exp Γ τ'
ECase : ∀ {τ τ' τ''} → Exp Γ (τ ⊎ τ') → Exp (τ ∷ Γ) τ'' → Exp (τ' ∷ Γ) τ'' → Exp Γ τ''
-- The standard functional semantics of the residual expressions.
-- TODO: citations for ``as usual'' and ``standard''
-- what?
module Exp-Eval where
-- interpretation of Exp types
EImp : Type → Set
EImp Int = ℕ
EImp (Fun ty ty₁) = EImp ty → EImp ty₁
EImp (ty • ty₁) = EImp ty * EImp ty₁
EImp (ty ⊎ ty₁) = EImp ty ⨄ EImp ty₁
-- Environments containing values for free variables. An environment
-- is indexed by a typing context that provides the types for the
-- contained values.
data Env : Ctx → Set where
[] : Env []
_∷_ : ∀ {τ Γ} → EImp τ → Env Γ → Env (τ ∷ Γ)
-- Lookup a value in the environment, given a reference into the
-- associated typing context.
lookupE : ∀ { τ Γ } → τ ∈ Γ → Env Γ → EImp τ
lookupE hd (x ∷ env) = x
lookupE (tl v) (x ∷ env) = lookupE v env
-- Evaluation of residual terms, given a suitably typed environment.
ev : ∀ {τ Γ} → Exp Γ τ → Env Γ → EImp τ
ev (EVar x) env = lookupE x env
ev (EInt x) env = x
ev (EAdd e e₁) env = ev e env + ev e₁ env
ev (ELam e) env = λ x → ev e (x ∷ env)
ev (EApp e e₁) env = ev e env (ev e₁ env)
ev (e , e₁) env = ev e env , (ev e₁ env)
ev (Tl e) env = tl (ev e env)
ev (Tr e) env = tr (ev e env)
ev (EFst e) env = fst (ev e env)
ev (ESnd e) env = snd (ev e env)
ev (ECase e e₁ e₂) env with ev e env
ev (ECase e e₁ e₂) env | tl c = (λ x → ev e₁ (x ∷ env)) c
ev (ECase e e₁ e₂) env | tr c = (λ x → ev e₂ (x ∷ env)) c
-- The binding-time-annotated language.
---------------------------------------
-- The type of a term determines the term's binding time. The type
-- constructors with an A-prefix denote statically bound integers and
-- functions. Terms with dynamic binding time have a `D' type. The `D'
-- type constructor simply wraps up a residual type.
data AType : Set where
AInt : AType
AFun : AType → AType → AType
D : Type → AType
--pair type on the annotated type level
_•_ : AType → AType → AType
--sum type on the annotated type level
_⊎_ : AType → AType → AType
ACtx = List AType
-- The mapping from annotated types to residual types is straightforward.
typeof : AType → Type
typeof AInt = Int
typeof (AFun α₁ α₂) = Fun (typeof α₁) (typeof α₂)
typeof (D x) = x
typeof (α₁ • α₂) = typeof α₁ • typeof α₂
typeof (α₁ ⊎ α₂) = typeof α₁ ⊎ typeof α₂
-- The typed annotated terms: The binding times of variables is
-- determined by the corresponding type-binding in the context. In the
-- other cases, the A- and D-prefixes on term constructors inidicate
-- the corresponding binding times for the resulting terms.
------------------------------------------------------------------------------------------------
-- Now the typed annotated terms are extended to inculde dynamic terms whose subterms are static
------------------------------------------------------------------------------------------------
---------------
--Some examples
---------------
--a. first-order static value in a dynamic environment
-- DAdd (DInt 1) (AAdd (AInt 2) (AInt 3)) where AAdd (AInt 2) (AInt 3) : AExp [] AInt
-- DAdd (DInt 1) (AApp (ALam (Var hd)) (AInt 5)) where AApp (ALam (Var hd)) (AInt 5) : AExp [] AInt
--b. higher-order static value in a dynamic environment
-- DApp (ALam (Var hd)) (DInt 5) where ALam (Var hd) : AExp [] (AFun (D Int) (D Int))
-- DApp (ALam (ALam (AInt 0))) (DInt 5) where ALam (ALam (AInt 0)) : AExp [] (AFun (AFun (D Int) (D Int)) AInt)
-- DApp (ALam (ALam (DInt 0))) (DInt 5) where ALam (ALam (DInt 0)) : AExp [] (AFun (AFun AInt (D Int)) (D Int))
--Clearly these terms are not well-typed and we need to modify [AExp] such that they have the right types which are
--compatible with the dynamic environment,or we can "lift" their static types to dynamic types so that they can be
--used as dynamic sub-terms to be filled in the right dynamic environment. This,however,brings new difficulty when
--we try to partially evaluate term who contains "lifted" subterms.
----------------
--new difficulty
----------------
--Consider the evaluation of the following term
--DAdd (DInt 1) (Lift (AAdd (AInt 2) (AInt 3))) : AExp [] AInt
--the expected type after evaluation is,
--EAdd (EInt 1) ? : Exp [] Int where ? : Exp [] Int
--and one good candidate for "?" as,
--EInt (pe (AAdd (AInt 2) (AInt 3)) []) : Exp [] Int
--where we wrap up the partial evaluation of the static subterm so
--that it fits with the rest of evaluation.
--However,we can not always "wrap up" a evaluated higher-order static
--value so that it has the required residual type,
--ALam (Var hd) : AExp [] (AFun AInt AInt)
--the required type of its lifted term as,
--? : Exp [] (Fun Int Int)
--which can not be constructed from [λ Γ↝Γ' x → x : []↝Γ' → ℕ → ℕ]
--for the input of the static function is evaluated to be a natural
--number which can not be matched with the type of the input of the
--required residual term. It is then clear that we need to impose
--restriction upon terms to be lifted.
-------------------------
--restriction for lifting
-------------------------
-------------------------------------------------------------
-- The interpretation of annotated types.
Imp : Ctx → AType → Set
Imp Γ (AInt) = ℕ
Imp Γ (AFun α₁ α₂) = ∀ {Γ'} → Γ ↝ Γ' → (Imp Γ' α₁ → Imp Γ' α₂)
Imp Γ (D σ) = Exp Γ σ
Imp Γ (α₁ • α₂) = (Imp Γ α₁) * (Imp Γ α₂)
Imp Γ (α₁ ⊎ α₂) = (Imp Γ α₁) ⨄ (Imp Γ α₂)
elevate-var : ∀ {Γ Γ'} {τ : Type} → Γ ↝ Γ' → τ ∈ Γ → τ ∈ Γ'
elevate-var ↝-refl x = x
elevate-var (↝-extend Γ↝Γ') x = tl (elevate-var Γ↝Γ' x)
elevate-var2 : ∀ {Γ Γ' Γ'' τ} → Γ ↝ Γ' ↝ Γ'' → τ ∈ Γ → τ ∈ Γ''
elevate-var2 (↝↝-base x) x₁ = elevate-var x x₁
elevate-var2 (↝↝-extend Γ↝Γ'↝Γ'') hd = hd
elevate-var2 (↝↝-extend Γ↝Γ'↝Γ'') (tl x) = tl (elevate-var2 Γ↝Γ'↝Γ'' x)
elevate : ∀ {Γ Γ' Γ'' τ} → Γ ↝ Γ' ↝ Γ'' → Exp Γ τ → Exp Γ'' τ
elevate Γ↝Γ'↝Γ'' (EVar x) = EVar (elevate-var2 Γ↝Γ'↝Γ'' x)
elevate Γ↝Γ'↝Γ'' (EInt x) = EInt x
elevate Γ↝Γ'↝Γ'' (EAdd e e₁) = EAdd (elevate Γ↝Γ'↝Γ'' e) (elevate Γ↝Γ'↝Γ'' e₁)
elevate Γ↝Γ'↝Γ'' (ELam e) = ELam (elevate (↝↝-extend Γ↝Γ'↝Γ'') e)
elevate Γ↝Γ'↝Γ'' (EApp e e₁) = EApp (elevate Γ↝Γ'↝Γ'' e) (elevate Γ↝Γ'↝Γ'' e₁)
elevate Γ↝Γ'↝Γ'' (e , e₁) = ((elevate Γ↝Γ'↝Γ'' e) , (elevate Γ↝Γ'↝Γ'' e₁))
elevate Γ↝Γ'↝Γ'' (Tl e) = Tl (elevate Γ↝Γ'↝Γ'' e)
elevate Γ↝Γ'↝Γ'' (Tr e) = Tr (elevate Γ↝Γ'↝Γ'' e)
elevate Γ↝Γ'↝Γ'' (EFst e) = EFst (elevate Γ↝Γ'↝Γ'' e)
elevate Γ↝Γ'↝Γ'' (ESnd e) = ESnd (elevate Γ↝Γ'↝Γ'' e)
elevate Γ↝Γ'↝Γ'' (ECase c e₁ e₂) = ECase (elevate Γ↝Γ'↝Γ'' c) (elevate (↝↝-extend Γ↝Γ'↝Γ'') e₁) (elevate (↝↝-extend Γ↝Γ'↝Γ'') e₂)
liftE : ∀ {τ Γ Γ'} → Γ ↝ Γ' → Exp Γ τ → Exp Γ' τ
liftE Γ↝Γ' e = elevate (↝↝-base Γ↝Γ') e
-------------------------------------------------------------
-- --case 1. a first-order static value in a dynamic environment
-- lift1 : AExp [] AInt
-- lift1 = (AInt 0)
-- e1 : Imp [] AInt
-- e1 = 0
-- lifted1 : Exp [] (typeof AInt)
-- lifted1 = EInt e1
-- --case 2. higher-order static function in a dynamic environment
-- --a. a function whose input argument is of static integer
-- --lift2 : AExp [] (AFun AInt AInt)
-- --lift2 = ALam (Var hd)
-- --e2 : Imp [] (AFun AInt AInt)
-- --e2 = λ Γ↝Γ' x → x
-- --lifted2 : Exp [] (typeof (AFun AInt AInt))
-- --lifted2 = ELam {!!}
-- --Note that as explained above it is impossible to construct the right term using [e2]
-- --to fill in the above hole!
-- --b. a function whose input argument is of dynamic integer
-- --b.1. when return type is of dynamic integer
-- lift3 : AExp [] (AFun (D Int) (D Int))
-- lift3 = ALam (Var hd)
-- e3 : Imp [] (AFun (D Int) (D Int))
-- e3 = λ Γ↝Γ' x → x
-- liftede3 : Exp [] (typeof (AFun (D Int) (D Int)))
-- liftede3 = ELam (e3 (↝-extend ↝-refl) (EVar hd))
-- --b.2. when return type is of static integer
-- lift4 : AExp [] (AFun (D Int) AInt)
-- lift4 = ALam (AInt 0)
-- e4 : Imp [] (AFun (D Int) AInt)
-- e4 = λ Γ↝Γ' x → 0
-- liftede4 : Exp [] (typeof (AFun (D Int) AInt))
-- liftede4 = ELam ( EInt {Int ∷ []} (e4 (↝-extend ↝-refl) (EVar hd)))
-- --c. a function whose input argument is of static function type
-- --c.1. static function type returns a static integer
-- --lift5 : AExp [] (AFun (AFun AInt AInt) AInt)
-- --lift5 = ALam (AApp (Var hd) (AInt 0))
-- --e5 : Imp [] (AFun (AFun AInt AInt) AInt)
-- --e5 = λ Γ↝Γ' x → x ↝-refl 0
-- --liftede5 : Exp [] (typeof ( AFun (AFun AInt AInt) AInt))
-- --liftede5 = ELam (EInt (e5 (↝-extend {τ = Fun Int Int} ↝-refl) (λ Γ↝Γ' e' → {!!})))
-- --Note that again it is impossible to construct the right residual term
-- --c.2. static function type returns a dynamic integer
-- --c.2.1. the input of the function type is of static integer
-- lift6 : AExp [] (AFun (AFun AInt (D Int)) (D Int))
-- lift6 = ALam (AApp (Var hd) (AInt 0))
-- e6 : Imp [] (AFun (AFun AInt (D Int)) (D Int))
-- e6 = λ Γ↝Γ' x → x ↝-refl 0
-- liftede6 : Exp [] (typeof ( AFun (AFun AInt (D Int)) (D Int)))
-- liftede6 = ELam ((e6 (↝-extend {τ = Fun Int Int} ↝-refl)
-- (λ Γ↝Γ' e' → EApp (liftE Γ↝Γ' (EVar {Fun Int Int ∷ []} hd)) (EInt e'))))
-- --c.2.1. the input of the function type is of dynamic integer
-- lift7 : AExp [] (AFun (AFun (D Int) (D Int)) (D Int))
-- lift7 = ALam (AApp (Var hd) (DInt 0))
-- e7 : Imp [] (AFun (AFun (D Int) (D Int)) (D Int))
-- e7 = λ Γ↝Γ' x → x ↝-refl (EInt 0)
-- liftede7 : Exp [] (typeof ( AFun (AFun (D Int) (D Int)) (D Int)))
-- liftede7 = ELam ((e7 (↝-extend {τ = Fun Int Int} ↝-refl)
-- (λ Γ↝Γ' e' → EApp (liftE Γ↝Γ' (EVar {Fun Int Int ∷ []} hd)) e')))
-- --c.3. the output of the function type is of higher-order static value
-- --c.3.1 the return value has one static integer as input
-- -- lift8 : AExp [] (AFun (D Int) (AFun AInt (D Int)))
-- -- lift8 = ALam (ALam (Var (tl hd)))
-- -- e8 : Imp [] (AFun (D Int) (AFun AInt (D Int)))
-- -- e8 = λ Γ↝Γ' x Γ'↝Γ'' y → liftE Γ'↝Γ'' x
-- -- liftede8 : Exp [] (typeof ( AFun (D Int) (AFun AInt (D Int))))
-- -- liftede8 = ELam (ELam (e8 (↝-extend (↝-extend ↝-refl)) (EVar (tl hd)) ↝-refl {!!}))
-- --c.3.2 the return value has one dynamic integer as input
-- lift9 : AExp [] (AFun (D Int) (AFun (D Int) (D Int)))
-- lift9 = ALam (ALam (Var (tl hd)))
-- e9 : Imp [] (AFun (D Int) (AFun (D Int) (D Int)))
-- e9 = λ Γ↝Γ' x Γ'↝Γ'' y → liftE Γ'↝Γ'' x
-- liftede9 : Exp [] (typeof ( AFun (D Int) (AFun (D Int) (D Int))))
-- liftede9 = ELam (ELam (e9 (↝-extend (↝-extend ↝-refl)) (EVar (tl hd)) ↝-refl (EVar hd)))
-- --d. static pairs and sums in dynamic environment
-- --d.1. identity function with static sum as its input
-- lift10 : AExp [] (AFun ((D Int) ⊎ (D Int)) ((D Int) ⊎ (D Int)))
-- lift10 = ALam (Var hd)
-- e10 : Imp [] (AFun ((D Int) ⊎ (D Int)) ((D Int) ⊎ (D Int)))
-- e10 = λ Γ↝Γ' x → x
-- liftede10 : Exp [] (typeof (AFun ((D Int) ⊎ (D Int)) ((D Int) ⊎ (D Int))))
-- liftede10 = ELam {!e10!}
-- --d.1. identity function with static sum as its input
-- lift11 : AExp [] (AFun ((D Int) • (D Int)) ((D Int) • (D Int)))
-- lift11 = ALam (Var hd)
-- e11 : Imp [] (AFun ((D Int) • (D Int)) ((D Int) • (D Int)))
-- e11 = λ Γ↝Γ' x → x
-- liftede11 : Exp [] (typeof (AFun ((D Int) • (D Int)) ((D Int) • (D Int))))
-- liftede11 = ELam (fst (e11 (↝-extend ↝-refl) (EFst (EVar hd) , ESnd (EVar hd))) ,
-- snd (e11 (↝-extend ↝-refl) (EFst (EVar hd) , ESnd (EVar hd))))
--Note that the above two examples in section "d" clearly shows that
--"static functions with inputs of static sum type are not liftable
-- while with inputs of static pair type are liftable ".
---------------------------
--summary on liftable terms
---------------------------
--a. Regarding static first-order static value (static integer) in dynamic environment
-- All terms of static integer type are liftable
--b. Regarding static higher-order static value in dynamic environment
--b.1. given that output value is liftable
-- • when input is of first-order dynamic type,liftable
-- • when input is of higher-order static type and output
-- of that input is of dynamic type,liftable
--b.2. given that input value is liftable
-- • when output is of first-order type,liftable
-- • when output is of higher-order type and inputs
-- of that type are of dynamic type,liftable
-------------------------------------------
--specification of the liftable restriction
-------------------------------------------
mutual
data Liftable : AType → Set where
D : ∀ τ → Liftable (D τ)
AInt : Liftable AInt
_⊎_ : ∀ {α₁ α₂} → Liftable α₁ → Liftable α₂ → Liftable (α₁ ⊎ α₂)
_•_ : ∀ {α₁ α₂} → Liftable α₁ → Liftable α₂ → Liftable (α₁ • α₂)
AFun : ∀ {α₁ α₂} → Liftable⁻ α₁ → Liftable α₂ → Liftable (AFun α₁ α₂)
data Liftable⁻ : AType → Set where
D : ∀ τ → Liftable⁻ (D τ)
_•_ : ∀ {α₁ α₂} → Liftable⁻ α₁ → Liftable⁻ α₂ → Liftable⁻ (α₁ • α₂)
AFun : ∀ {α₁ α₂} → Liftable α₁ → Liftable⁻ α₂ → Liftable⁻ (AFun α₁ α₂)
----------------------------------------
--[AExp] with liftable terms
----------------------------------------
data AExp (Δ : ACtx) : AType → Set where
Var : ∀ {α} → α ∈ Δ → AExp Δ α
AInt : ℕ → AExp Δ AInt
AAdd : AExp Δ AInt → AExp Δ AInt → AExp Δ AInt
ALam : ∀ {α₁ α₂} → AExp (α₁ ∷ Δ) α₂ → AExp Δ (AFun α₁ α₂)
AApp : ∀ {α₁ α₂} → AExp Δ (AFun α₂ α₁) → AExp Δ α₂ → AExp Δ α₁
DInt : ℕ → AExp Δ (D Int)
DAdd : AExp Δ (D Int) → AExp Δ (D Int) → AExp Δ (D Int)
DLam : ∀ {σ₁ σ₂} → AExp ((D σ₁) ∷ Δ) (D σ₂) → AExp Δ (D (Fun σ₁ σ₂))
DApp : ∀ {α₁ α₂} → AExp Δ (D (Fun α₂ α₁)) → AExp Δ (D α₂) → AExp Δ (D α₁)
-- Static pairs and sums
_,_ : ∀ {α₁ α₂} → AExp Δ α₁ → AExp Δ α₂ → AExp Δ (α₁ • α₂)
Tl : ∀ {α₁ α₂} → AExp Δ α₁ → AExp Δ (α₁ ⊎ α₂)
Tr : ∀ {α₁ α₂} → AExp Δ α₂ → AExp Δ (α₁ ⊎ α₂)
Fst : ∀ {α₁ α₂} → AExp Δ (α₁ • α₂) → AExp Δ α₁
Snd : ∀ {α₁ α₂} → AExp Δ (α₁ • α₂) → AExp Δ α₂
Case : ∀ {α₁ α₂ α₃} → AExp Δ (α₁ ⊎ α₂) → AExp (α₁ ∷ Δ) α₃ → AExp (α₂ ∷ Δ) α₃ → AExp Δ α₃
-- Dynamic pairs and sums
_ḋ_ : ∀ {σ₁ σ₂} → AExp Δ (D σ₁) → AExp Δ (D σ₂) → AExp Δ (D (σ₁ • σ₂))
DTl : ∀ {σ₁ σ₂} → AExp Δ (D σ₁) → AExp Δ (D (σ₁ ⊎ σ₂))
DTr : ∀ {σ₁ σ₂} → AExp Δ (D σ₂) → AExp Δ (D (σ₁ ⊎ σ₂))
DFst : ∀ {σ₁ σ₂} → AExp Δ (D (σ₁ • σ₂)) → AExp Δ (D σ₁)
DSnd : ∀ {σ₁ σ₂} → AExp Δ (D (σ₁ • σ₂)) → AExp Δ (D σ₂)
DCase : ∀ {σ₁ σ₂ σ₃} → AExp Δ (D (σ₁ ⊎ σ₂)) → AExp ((D σ₁) ∷ Δ) (D σ₃) → AExp ((D σ₂) ∷ Δ) (D σ₃) → AExp Δ (D σ₃)
-- Liftable static terms
↑ : ∀ {α} → Liftable α → AExp Δ α → AExp Δ (D (typeof α))
-- The terms of AExp assign a binding time to each subterm. For
-- program specialization, we interpret terms with dynamic binding
-- time as the programs subject to specialization, and their subterms
-- with static binding time as statically known inputs. A partial
-- evaluation function (or specializer) then compiles the program into
-- a residual term for that is specialized for the static inputs. The
-- main complication when defining partial evaluation as a total,
-- primitively recursive function will be the treatment of the De
-- Bruijn variables of non-closed residual expressions.
lift : ∀ {Γ Γ'} α → Γ ↝ Γ' → Imp Γ α → Imp Γ' α
lift AInt p v = v
lift (AFun x x₁) Γ↝Γ' v = λ Γ'↝Γ'' → v (↝-trans Γ↝Γ' Γ'↝Γ'')
lift (D x₁) Γ↝Γ' v = elevate (↝↝-base Γ↝Γ') v
lift (α₁ • α₂) Γ↝Γ' (v₁ , v₂) = (lift α₁ Γ↝Γ' v₁) , (lift α₂ Γ↝Γ' v₂)
lift (α₁ ⊎ α₂) Γ↝Γ' (tl v) = tl (lift α₁ Γ↝Γ' v)
lift (α₁ ⊎ α₂) Γ↝Γ' (tr v) = tr (lift α₂ Γ↝Γ' v)
module SimpleAEnv where
-- A little weaker, but much simpler
data AEnv (Γ : Ctx) : ACtx → Set where
[] : AEnv Γ []
--cons : ∀ {Δ} (α : AType) → Imp Γ α → AEnv Γ Δ → AEnv Γ (α ∷ Δ)
cons : ∀ {Δ} {α : AType} → Imp Γ α → AEnv Γ Δ → AEnv Γ (α ∷ Δ)
lookup : ∀ {α Δ Γ} → AEnv Γ Δ → α ∈ Δ → Imp Γ α
lookup [] ()
--lookup {α} (cons .α x aenv) hd = x
--lookup {α} (cons .y x aenv) (tl {.α} {y} id) = lookup aenv id
lookup {α} (cons x aenv) hd = x
lookup {α} (cons x aenv) (tl {.α} {y} id) = lookup aenv id
liftEnv : ∀ {Γ Γ' Δ} → Γ ↝ Γ' → AEnv Γ Δ → AEnv Γ' Δ
liftEnv Γ↝Γ' [] = []
--liftEnv Γ↝Γ' (cons α x env) = cons α (lift α Γ↝Γ' x) (liftEnv Γ↝Γ' env)
liftEnv Γ↝Γ' (cons {α = α} x env) = cons {α = α} (lift α Γ↝Γ' x) (liftEnv Γ↝Γ' env)
consD : ∀ {Γ Δ} σ → AEnv Γ Δ → AEnv (σ ∷ Γ) (D σ ∷ Δ)
--consD σ env = (cons (D σ) (EVar hd) (liftEnv (↝-extend {τ = σ} ↝-refl) env))
consD σ env = (cons {α = D σ} (EVar hd) (liftEnv (↝-extend {τ = σ} ↝-refl) env))
----------------------------------------------
-- Helper for the evaluation of liftable terms
----------------------------------------------
mutual
lift' : ∀ {Γ α} → Liftable α → Imp Γ α → (Exp Γ (typeof α))
lift' (D τ) v = v
lift' AInt v = EInt v
lift' (ty ⊎ ty₁) (tl a) = Tl (lift' ty a)
lift' (ty ⊎ ty₁) (tr b) = Tr (lift' ty₁ b)
lift' (ty • ty₁) (ffst , ssnd) = lift' ty ffst , lift' ty₁ ssnd
lift' {Γ} (AFun {α₁} ty₁ ty₂) v = ELam
((λ x → lift' ty₂ (v (↝-extend {τ = typeof α₁} ↝-refl) x))
(embed ty₁ (EVar {Γ = typeof α₁ ∷ Γ} hd)))
embed : ∀ {Γ α} → Liftable⁻ α → Exp Γ (typeof α) → (Imp Γ α)
embed (D τ) e = e
-- embed (ty ⊎ ty₁) e = {! (ECase e (EVar hd) ?)!}
-- embed (ty ⊎ ty₁) (EVar x) = {!!}
-- embed (ty ⊎ ty₁) (EApp e e₁) = {!!}
-- embed (ty ⊎ ty₁) (Tl e) = tl (embed ty e)
-- embed (ty ⊎ ty₁) (Tr e) = tr (embed ty₁ e)
-- embed (ty ⊎ ty₁) (EFst e) = {!!}
-- embed (ty ⊎ ty₁) (ESnd e) = {!!}
-- embed (ty ⊎ ty₁) (ECase e e₁ e₂) = {!!}
embed (ty • ty₁) e = embed ty (EFst e) , embed ty₁ (ESnd e)
embed {Γ} (AFun {α} ty₁ ty₂) e =
λ Γ↝Γ' v₁ → embed ty₂ (EApp (liftE Γ↝Γ' e) (lift' ty₁ v₁))
--------------------
-- Partial Evaluator
--------------------
pe : ∀ {α Δ Γ} → AExp Δ α → AEnv Γ Δ → Imp Γ α
pe (Var x) env = lookup env x
pe (AInt x) env = x
pe (AAdd e e₁) env = pe e env + pe e₁ env
pe (ALam {α} e) env = λ Γ↝Γ' → λ y → pe e (cons {α = α} y (liftEnv Γ↝Γ' env))
pe (AApp e e₁) env = pe e env ↝-refl (pe e₁ env)
pe (DInt x) env = EInt x
pe (DAdd e e₁) env = EAdd (pe e env) (pe e₁ env)
pe (DLam {σ} e) env = ELam (pe e (consD σ env))
pe (DApp e e₁) env = EApp (pe e env) (pe e₁ env)
pe {Γ = Γ} (e , e₁) env = pe {Γ = Γ} e env , pe {Γ = Γ} e₁ env
pe {α = α₁ ⊎ α₂} {Γ = Γ} (Tl e) env = tl (pe {α = α₁} {Γ = Γ} e env)
pe {α = α₁ ⊎ α₂} {Γ = Γ} (Tr e) env = tr (pe {α = α₂} {Γ = Γ} e env)
pe {Γ = Γ} (Fst e) env = fst (pe {Γ = Γ} e env)
pe {Γ = Γ} (Snd e) env = snd (pe {Γ = Γ} e env)
pe {Γ = Γ} (Case e e₁ e₂) env with pe {Γ = Γ} e env
pe {Γ = Γ} (Case {α₁ = α} e e₁ e₂) env | tl y = (λ Γ↝Γ' → λ y → pe e₁ (cons {α = α} y (liftEnv Γ↝Γ' env))) ↝-refl y
pe {Γ = Γ} (Case {α₂ = α} e e₁ e₂) env | tr y = (λ Γ↝Γ' → λ y → pe e₂ (cons {α = α} y (liftEnv Γ↝Γ' env))) ↝-refl y
pe (e ḋ e₁) env = pe e env , pe e₁ env
pe (DTl e) env = Tl (pe e env)
pe (DTr e) env = Tr (pe e env)
pe (DFst e) env = EFst (pe e env)
pe (DSnd e) env = ESnd (pe e env)
pe (DCase {σ₁} {σ₂} e e₁ e₂) env = ECase (pe e env) (pe e₁ (consD σ₁ env)) (pe e₂ (consD σ₂ env))
pe (↑ x e) env = lift' x (pe e env)
-- Correctness proof
module Correctness where
open SimpleAEnv
open Exp-Eval
-- TODO: rename occurences of stripα to typeof
stripα = typeof
stripΔ : ACtx → Ctx
stripΔ = map stripα
strip-lookup : ∀ { α Δ} → α ∈ Δ → stripα α ∈ stripΔ Δ
strip-lookup hd = hd
strip-lookup (tl x) = tl (strip-lookup x)
strip : ∀ {α Δ} → AExp Δ α → Exp (stripΔ Δ) (stripα α)
strip (Var x) = EVar (strip-lookup x)
strip (AInt x) = EInt x
strip (AAdd e e₁) = EAdd (strip e) (strip e₁)
strip (ALam e) = ELam (strip e)
strip (AApp e e₁) = EApp (strip e) (strip e₁)
strip (DInt x) = EInt x
strip (DAdd e e₁) = EAdd (strip e) (strip e₁)
strip (DLam e) = ELam (strip e)
strip (DApp e e₁) = EApp (strip e) (strip e₁)
strip (e , e₁) = strip e , strip e₁
strip (Tl e) = Tl (strip e)
strip (Tr e) = Tr (strip e)
strip (Fst e) = EFst (strip e)
strip (Snd e) = ESnd (strip e)
strip (Case e e₁ e₂) = ECase (strip e) (strip e₁) (strip e₂)
strip (e ḋ e₁) = strip e , strip e₁
strip (DTl e) = Tl (strip e)
strip (DTr e) = Tr (strip e)
strip (DFst e) = EFst (strip e)
strip (DSnd e) = ESnd (strip e)
strip (DCase e e₁ e₂) = ECase (strip e) (strip e₁) (strip e₂)
strip (↑ x e) = strip e
--liftE : ∀ {τ Γ Γ'} → Γ ↝ Γ' → Exp Γ τ → Exp Γ' τ
--liftE Γ↝Γ' e = elevate (↝↝-base Γ↝Γ') e
stripLift : ∀ {α Δ Γ} → stripΔ Δ ↝ Γ → AExp Δ α → Exp Γ (stripα α)
stripLift Δ↝Γ = liftE Δ↝Γ ∘ strip
-- --------------------------------
-- --"lift-strip" equivalence lemma
-- --------------------------------
-- ↑≡↓ : ∀ x e env env' aenv → Equiv-Env env' aenv env → ev (lift' x (pe e aenv)) env' ≡ ev (strip e) env
-- ↑≡↓ x e env env' aenv eqenv = {!!}
-- We want to show that pe preserves the semantics of the
-- program. Roughly, Exp-Eval.ev-ing a stripped program is
-- equivalent to first pe-ing a program and then Exp-Eval.ev-ing the
-- result. But as the pe-result of a static function ``can do more''
-- than the (ev ∘ strip)ped function we need somthing more refined.
module Equiv where
open import Relation.Binary.PropositionalEquality
-- Extending a value environment according to an extension of a
-- type environment
data _⊢_↝_ {Γ} : ∀ {Γ'} → Γ ↝ Γ' → Env Γ → Env Γ' → Set where
refl : ∀ env → ↝-refl ⊢ env ↝ env
extend : ∀ {τ Γ' env env'} → {Γ↝Γ' : Γ ↝ Γ'} →
(v : EImp τ) → (Γ↝Γ' ⊢ env ↝ env') →
↝-extend {Γ = Γ} {Γ' = Γ'} {τ = τ} Γ↝Γ' ⊢ env ↝ (v ∷ env')
env↝trans : ∀ {Γ Γ' Γ''} {Γ↝Γ' : Γ ↝ Γ'} {Γ'↝Γ'' : Γ' ↝ Γ''}
{env env' env''} →
Γ↝Γ' ⊢ env ↝ env' → Γ'↝Γ'' ⊢ env' ↝ env'' →
let Γ↝Γ'' = ↝-trans Γ↝Γ' Γ'↝Γ'' in
Γ↝Γ'' ⊢ env ↝ env''
env↝trans {Γ} {.Γ''} {Γ''} {Γ↝Γ'} {.↝-refl} {env} {.env''} {env''} env↝env' (refl .env'') = env↝env'
env↝trans env↝env' (extend v env'↝env'') = extend v (env↝trans env↝env' env'↝env'')
-- Equivalent Imp Γ α and EImp τ values (where τ = stripα α). As
-- (v : Imp Γ α) is not necessarily closed, equivalence is defined for
-- the closure (Env Γ, ImpΓ α)
Equiv : ∀ {α Γ} → Env Γ → Imp Γ α → EImp (stripα α) → Set
Equiv {AInt} env av v = av ≡ v
Equiv {AFun α₁ α₂} {Γ} env av v = ∀ {Γ' env' Γ↝Γ'} →
(Γ↝Γ' ⊢ env ↝ env') →
{av' : Imp Γ' α₁} →
{v' : EImp (stripα α₁)} →
Equiv {α₁} {Γ'} env' av' v' → Equiv {α₂} env' (av Γ↝Γ' av') (v v')
Equiv {D x} env av v = ev av env ≡ v
Equiv {α • α₁} env (ffst , ssnd) (ffst₁ , ssnd₁) = (Equiv {α} env ffst ffst₁) ∧ (Equiv {α₁} env ssnd ssnd₁)
Equiv {α ⊎ α₁} env (tl a) (tl a₁) = Equiv {α} env a a₁
--------------------------------------------------------------------
Equiv {α ⊎ α₁} env (tl a) (tr b) = ⊥ -- Interesting case!
Equiv {α ⊎ α₁} env (tr b) (tl a) = ⊥ -- Interesting case!
--------------------------------------------------------------------
Equiv {α ⊎ α₁} env (tr b) (tr b₁) = Equiv {α₁} env b b₁
-- Equiv {AInt} env av v = av ≡ v
-- Equiv {AFun α₁ α₂} {Γ} env av v = -- extensional equality, given -- an extended context
-- ∀ {Γ' env' Γ↝Γ'} → (Γ↝Γ' ⊢ env ↝ env') →
-- {av' : Imp Γ' α₁} → {v' : EImp (stripα α₁)} →
-- Equiv env' av' v' → Equiv env' (av Γ↝Γ' av') (v v')
-- Equiv {D x} {Γ} env av v = ev av env ≡ v -- actually we mean extensional equality
-- TODO: Define a proper equivalence for EImps
-- Equivalence of AEnv and Env environments. They need to provide
-- Equivalent bindings for a context Δ/stripΔ Δ. Again, the
-- equivalence is defined for a closure (Env Γ', AEnv Γ' Δ).
data Equiv-Env {Γ' : _} (env' : Env Γ') :
∀ {Δ} → let Γ = stripΔ Δ in
AEnv Γ' Δ → Env Γ → Set where
[] : Equiv-Env env' [] []
cons : ∀ {α Δ} → let τ = stripα α
Γ = stripΔ Δ in
{env : Env Γ} → {aenv : AEnv Γ' Δ} →
Equiv-Env env' aenv env →
(va : Imp (Γ') α) → (v : EImp τ) →
Equiv {α} {Γ'} env' va v →
--Equiv-Env env' (cons α va (aenv)) (v ∷ env)
Equiv-Env env' (cons {α = α} va (aenv)) (v ∷ env)
--------------------------------
--"lift-strip" equivalence lemma
--------------------------------
-- ↑≡↓ : ∀ {Γ' Δ α} x e env env' aenv → Equiv-Env {Γ'} env' {Δ} aenv env → ev (lift' {Γ = Γ'} {α = α} x (pe e aenv)) env' ≡ ev (strip e) env
-- ↑≡↓ x e env env' aenv eqenv = {!!}
-- Now for the proof...
module Proof where
open Equiv
open import Relation.Binary.PropositionalEquality
-- Extensional equality as an axiom to prove the Equivalence of
-- function values. We could (should?) define it locally for
-- Equiv.
postulate ext : ∀ {τ₁ τ₂} {f g : EImp τ₁ → EImp τ₂} →
(∀ x → f x ≡ g x) → f ≡ g
-- Ternary helper relation for environment extensions, analogous to _↝_↝_ for contexts
data _⊢_↝_↝_⊣ : ∀ { Γ Γ' Γ''} → Γ ↝ Γ' ↝ Γ'' → Env Γ → Env Γ' → Env Γ'' → Set where
refl : ∀ {Γ Γ''} {Γ↝Γ'' : Γ ↝ Γ''} { env env'' } →
Γ↝Γ'' ⊢ env ↝ env'' →
↝↝-base Γ↝Γ'' ⊢ env ↝ [] ↝ env'' ⊣
extend : ∀ {Γ Γ' Γ'' τ} {Γ↝Γ'↝Γ'' : Γ ↝ Γ' ↝ Γ''} { env env' env'' } →
Γ↝Γ'↝Γ'' ⊢ env ↝ env' ↝ env'' ⊣ →
(v : EImp τ) → ↝↝-extend {Γ = Γ} {Γ' = Γ'} {Γ'' = Γ''} {τ = τ} Γ↝Γ'↝Γ'' ⊢ (v ∷ env) ↝ (v ∷ env') ↝ (v ∷ env'') ⊣
-- the following lemmas are strong versions of the shifting
-- functions, proving that consistent variable renaming preserves
-- equivalence (and not just typing).
lookup-elevate-≡ : ∀ {τ Γ Γ'} {Γ↝Γ' : Γ ↝ Γ'}
{env : Env Γ} {env' : Env Γ'} →
Γ↝Γ' ⊢ env ↝ env' →
(x : τ ∈ Γ) → lookupE x env ≡ lookupE (elevate-var Γ↝Γ' x) env'
lookup-elevate-≡ {τ} {.Γ'} {Γ'} {.↝-refl} {.env'} {env'} (refl .env') x = refl
lookup-elevate-≡ (extend v env↝env') x = lookup-elevate-≡ env↝env' x
lookup-elevate2-≡ : ∀ {τ Γ Γ' Γ''} {Γ↝Γ'↝Γ'' : Γ ↝ Γ' ↝ Γ''}
{env : Env Γ} {env' : Env Γ'} {env'' : Env Γ''} →
Γ↝Γ'↝Γ'' ⊢ env ↝ env' ↝ env'' ⊣ →
(x : τ ∈ Γ) → lookupE x env ≡ lookupE (elevate-var2 Γ↝Γ'↝Γ'' x) env''
lookup-elevate2-≡ (refl Γ↝Γ') x = lookup-elevate-≡ Γ↝Γ' x
lookup-elevate2-≡ (extend env↝env'↝env'' v) hd = refl
lookup-elevate2-≡ (extend env↝env'↝env'' _) (tl x)
rewrite lookup-elevate2-≡ env↝env'↝env'' x = refl
lem-elevate-≡ : ∀ {τ Γ Γ' Γ''}
{Γ↝Γ'↝Γ'' : Γ ↝ Γ' ↝ Γ''}
{env : Env Γ} {env' : Env Γ'} {env'' : Env Γ''} →
Γ↝Γ'↝Γ'' ⊢ env ↝ env' ↝ env'' ⊣ →
(e : Exp Γ τ) →
ev e env ≡ ev (elevate Γ↝Γ'↝Γ'' e) env''
lem-elevate-≡ env↝env' (EVar x) = lookup-elevate2-≡ env↝env' x
lem-elevate-≡ env↝env' (EInt x) = refl
lem-elevate-≡ env↝env' (EAdd e e₁) with lem-elevate-≡ env↝env' e | lem-elevate-≡ env↝env' e₁
... | IA1 | IA2 = cong₂ _+_ IA1 IA2
lem-elevate-≡ {Fun τ₁ τ₂} {Γ↝Γ'↝Γ'' = Γ↝Γ'↝Γ''}
{env = env}
{env'' = env''}
env↝env' (ELam e) = ext {τ₁} {τ₂} lem-elevate-≡-body
where lem-elevate-≡-body : ∀ x → ev e (x ∷ env) ≡ ev (elevate (↝↝-extend Γ↝Γ'↝Γ'') e) (x ∷ env'')
lem-elevate-≡-body x = lem-elevate-≡ (extend env↝env' x) e
lem-elevate-≡ env↝env' (EApp e e₁) with lem-elevate-≡ env↝env' e | lem-elevate-≡ env↝env' e₁
... | IA1 | IA2 = cong₂ (λ f₁ x → f₁ x) IA1 IA2
lem-elevate-≡ env↝env' (e , e₁) with lem-elevate-≡ env↝env' e | lem-elevate-≡ env↝env' e₁
... | IA1 | IA2 = cong₂ (λ x y → x , y) IA1 IA2
lem-elevate-≡ env↝env' (Tl e) with lem-elevate-≡ env↝env' e
... | IA = cong (λ x → tl x) IA
lem-elevate-≡ env↝env' (Tr e) with lem-elevate-≡ env↝env' e
... | IA = cong (λ x → tr x) IA
lem-elevate-≡ env↝env' (EFst e) with lem-elevate-≡ env↝env' e
... | IA = cong (λ x → fst x) IA
lem-elevate-≡ env↝env' (ESnd e) with lem-elevate-≡ env↝env' e
... | IA = cong (λ x → snd x) IA
lem-elevate-≡ {Γ↝Γ'↝Γ'' = Γ↝Γ'↝Γ''}
{env = env}
{env'' = env''}
env↝env' (ECase e e₁ e₂) with ev e env | ev (elevate Γ↝Γ'↝Γ'' e) env'' | lem-elevate-≡ env↝env' e
... | tl c | tl c' | IA rewrite (→tl {x' = c} {y' = c'} (tl c) (tl c') IA refl refl) = lem-elevate-≡-body c'
where lem-elevate-≡-body : ∀ x → ev e₁ (x ∷ env) ≡ ev (elevate (↝↝-extend Γ↝Γ'↝Γ'') e₁) (x ∷ env'')
lem-elevate-≡-body x = lem-elevate-≡ (extend env↝env' x) e₁
... | tl c | tr c' | ()
... | tr c | tl c' | ()
... | tr c | tr c' | IA rewrite (→tr {x' = c} {y' = c'} (tr c) (tr c') IA refl refl) = lem-elevate-≡-body c'
where lem-elevate-≡-body : ∀ x → ev e₂ (x ∷ env) ≡ ev (elevate (↝↝-extend Γ↝Γ'↝Γ'') e₂) (x ∷ env'')
lem-elevate-≡-body x = lem-elevate-≡ (extend env↝env' x) e₂
lem-lift-refl-id : ∀ {α Γ} → let τ = stripα α in
(env : Env Γ) →
(v : EImp τ) (va : Imp Γ α) →
Equiv {α} {Γ} env va v →
Equiv {α} {Γ} env (lift α ↝-refl va) v
lem-lift-refl-id {AInt} env v va eq = eq
lem-lift-refl-id {AFun α α₁} {Γ} env v va eq = body
where body : ∀ {Γ'} {env' : Env Γ'} {Γ↝Γ' : Γ ↝ Γ'} →
Γ↝Γ' ⊢ env ↝ env' →
{av' : Imp Γ' α} {v' : EImp (stripα α)} →
Equiv {α} {Γ'} env' av' v' → Equiv {α₁} {Γ'} env' (va (↝-trans ↝-refl Γ↝Γ') av') (v v')
body {Γ↝Γ' = Γ↝Γ'} env↝env' eq' rewrite sym (lem-↝-refl-id Γ↝Γ') = eq env↝env' eq'
lem-lift-refl-id {D x} env v va eq rewrite sym eq = sym (lem-elevate-≡ (refl (refl env)) va)
lem-lift-refl-id {α • α₁} env (ffst , ssnd) (ffst₁ , ssnd₁) (∧-intro x x₁) =
∧-intro (lem-lift-refl-id {α} env ffst ffst₁ x)
(lem-lift-refl-id {α₁} env ssnd ssnd₁ x₁)
lem-lift-refl-id {α ⊎ α₁} env (tl a) (tl a₁) eq = lem-lift-refl-id {α} env a a₁ eq
lem-lift-refl-id {α ⊎ α₁} env (tl a) (tr b) ()
lem-lift-refl-id {α ⊎ α₁} env (tr b) (tl a) ()
lem-lift-refl-id {α ⊎ α₁} env (tr b) (tr b₁) eq = lem-lift-refl-id {α₁} env b b₁ eq
-- lifting an Imp does not affect equivalence
lem-lift-equiv : ∀ {α Γ Γ'} → let τ = stripα α in
{Γ↝Γ' : Γ ↝ Γ'} →
(va : Imp Γ α) (v : EImp τ) →
{env : Env Γ} {env' : Env Γ'} →
Γ↝Γ' ⊢ env ↝ env' →
Equiv {α} {Γ} env va v →
Equiv {α} {Γ'} env' (lift α Γ↝Γ' va) v
lem-lift-equiv {α} va v {.env'} {env'} (refl .env') eq = lem-lift-refl-id {α} env' v va eq
lem-lift-equiv {AInt} va v (extend v₁ env↝env') eq = eq
lem-lift-equiv {AFun α α₁} va v (extend v₁ env↝env') eq =
λ v₁env₁↝env' eq₁ → eq (env↝trans (extend v₁ env↝env') v₁env₁↝env') eq₁
lem-lift-equiv {D x} va v (extend v₁ env↝env') eq rewrite sym eq = sym (lem-elevate-≡ (refl (extend v₁ env↝env')) va)
lem-lift-equiv {α • α₁} (ffst , ssnd) (ffst₁ , ssnd₁) (extend v₁ env↝env') (∧-intro x x₁) =
∧-intro (lem-lift-equiv {α} ffst ffst₁ (extend v₁ env↝env') x)
(lem-lift-equiv {α₁} ssnd ssnd₁ (extend v₁ env↝env') x₁)
lem-lift-equiv {α ⊎ α₁} (tl a) (tl a₁) (extend v₁ env↝env') eq = lem-lift-equiv {α} a a₁ (extend v₁ env↝env') eq
lem-lift-equiv {α ⊎ α₁} (tl a) (tr b) (extend v₁ env↝env') ()
lem-lift-equiv {α ⊎ α₁} (tr b) (tl a) (extend v₁ env↝env') ()
lem-lift-equiv {α ⊎ α₁} (tr b) (tr b₁) (extend v₁ env↝env') eq = lem-lift-equiv {α₁} b b₁ (extend v₁ env↝env') eq
lem-equiv-lookup : ∀ {α Δ Γ'} → let Γ = stripΔ Δ in
{ aenv : AEnv Γ' Δ } {env : Env Γ} →
(env' : Env Γ') →
Equiv-Env env' aenv env →
∀ (x : α ∈ Δ) → Equiv {α} env' (lookup aenv x) (lookupE (strip-lookup x) env)
lem-equiv-lookup env' [] ()
lem-equiv-lookup env' (cons enveq va v eq) hd = eq
lem-equiv-lookup env' (cons enveq va v eq) (tl x) = lem-equiv-lookup env' enveq x
lem-equiv-env-lift-extend :
∀ {σ Γ' Δ} (env' : Env Γ') → let Γ = stripΔ Δ in
{env : Env Γ} {aenv : AEnv Γ' Δ} →
Equiv-Env env' aenv env → (x : EImp σ) →
Equiv-Env {σ ∷ Γ'} (x ∷ env') (liftEnv (↝-extend ↝-refl) aenv) env
lem-equiv-env-lift-extend _ [] x = []
lem-equiv-env-lift-extend env' (cons {α} eqenv va v x) x₁ =
cons (lem-equiv-env-lift-extend env' eqenv x₁)
(lift α (↝-extend ↝-refl) va) v (lem-lift-equiv {α} va v (extend x₁ (refl env')) x)
lem-equiv-env-lift-lift :
∀ {Γ' Γ'' Δ} → let Γ = stripΔ Δ in
{Γ↝Γ' : Γ' ↝ Γ''}
{env' : Env Γ'} {env'' : Env Γ''}
(env'↝env'' : Γ↝Γ' ⊢ env' ↝ env'') →
{env : Env Γ} {aenv : AEnv Γ' Δ} →
Equiv-Env env' aenv env →
Equiv-Env env'' (liftEnv Γ↝Γ' aenv) env
lem-equiv-env-lift-lift env'↝env'' [] = []
lem-equiv-env-lift-lift {Γ↝Γ' = Γ↝Γ'} env'↝env'' (cons {α} eqenv va v x)
with lem-equiv-env-lift-lift env'↝env'' eqenv
... | IA = cons IA (lift α Γ↝Γ' va) v (lem-lift-equiv {α} va v env'↝env'' x)
--------------------------------
--"lift-correct" equivalence lemma
--------------------------------
open import Data.Product
mutual
lift-correct : ∀ {Γ α} (lft : Liftable α) (env : Env Γ) (av : Imp Γ α) (v : EImp (typeof α)) →
Equiv {α} {Γ} env av v → (Equiv {D (typeof α)} {Γ} env (lift' lft av) v)
lift-correct (D τ) env av v eq = eq
lift-correct AInt env av v eq = eq
lift-correct (lft ⊎ lft₁) env (tl a) (tl a₁) eq with lift-correct lft env a a₁
... | IA rewrite IA eq = refl
lift-correct (lft ⊎ lft₁) env (tr b) (tl a) ()
lift-correct (lft ⊎ lft₁) env (tl a) (tr b) ()
lift-correct (lft ⊎ lft₁) env (tr b) (tr b₁) eq with lift-correct lft₁ env b b₁
... | IA rewrite IA eq = refl
lift-correct (lft • lft₁) env (ffst , ssnd) (ffst₁ , ssnd₁) (∧-intro x x₁)
rewrite lift-correct lft env ffst ffst₁ x | lift-correct lft₁ env ssnd ssnd₁ x₁ = refl
lift-correct {Γ} {AFun x lft} (AFun y y') env av v eq =
ext {typeof x} {typeof lft} (λ x₁ →
lift-correct y' (x₁ ∷ env)
(av (↝-extend ↝-refl) (embed y (EVar hd))) (v x₁) (eq (extend x₁ (refl env)) (embed-correct {typeof x ∷ Γ} {x} y (x₁ ∷ env) (EVar hd) x₁ refl)))
embed-correct : ∀ {Γ α} (lft : Liftable⁻ α) (env : Env Γ) → (e : Exp Γ (typeof α)) → (v : EImp (typeof α)) →
ev e env ≡ v → Equiv {α} {Γ} env (embed lft e) v
embed-correct (D τ) env e v eq rewrite eq = refl
embed-correct (lft • lft₁) env e (fstv , sndv) eq = ∧-intro (embed-correct lft env (EFst e) fstv (subst (λ x → ffst x ≡ fstv) (sym eq) refl))
(embed-correct lft₁ env (ESnd e) sndv
(subst (λ x → ssnd x ≡ sndv) (sym eq) refl))
embed-correct {α = AFun α₁ α₂} (AFun x lft) env e v eq = f
where
f : ∀ {Γ' env' Γ↝Γ'} (x₁ : Γ↝Γ' ⊢ env ↝ env') {x₂ : Imp Γ' α₁} {x₃ : EImp (typeof α₁)}
(x₄ : Equiv {α₁} {Γ'} env' x₂ x₃) →
Equiv {α₂} {Γ'} env'
(embed lft (EApp (elevate (↝↝-base Γ↝Γ') e) (lift' x x₂))) (v x₃)
f {Γ'} {env'} {Γext} envext {av'} {v'} eq' =
embed-correct lft env' (EApp (elevate (↝↝-base Γext) e) (lift' x av')) (v v') g
where g : ev (elevate (↝↝-base Γext) e) env' (ev (lift' x av') env') ≡ v v'
g rewrite lift-correct x env' av' v' eq'
| sym (cong (λ f → f v') (lem-elevate-≡ (refl envext) e))
| (cong (λ f → f v') eq) = refl
--g = {!!}
---------------------------------------
--Correctness proof with liftable terms
---------------------------------------
-- When we partially evaluate somthing under an environment , it
-- will give equivalent results to a ``complete'' evaluation under
-- an equivalent environment
pe-correct : ∀ { α Δ Γ' } → (e : AExp Δ α) →
let Γ = stripΔ Δ in
{aenv : AEnv Γ' Δ} → {env : Env Γ} →
(env' : Env Γ') →
Equiv-Env env' aenv env →
Equiv {α} {Γ'} env' (pe e aenv) (ev (strip e) env)
pe-correct (Var x) env' eqenv = lem-equiv-lookup env' eqenv x
pe-correct (AInt x) env' eqenv = refl
pe-correct (AAdd e e₁) env' eqenv
rewrite pe-correct e env' eqenv | pe-correct e₁ env' eqenv = refl
pe-correct (ALam e) env' eqenv =
λ {_} {env''} env'↝env'' {av'} {v'} eq →
let eqenv' : _
eqenv' = lem-equiv-env-lift-lift env'↝env'' eqenv
eqenv'' : _
eqenv'' = cons eqenv' av' v' eq
in pe-correct e env'' eqenv''
pe-correct (AApp e e₁) env' eqenv
with pe-correct e env' eqenv | pe-correct e₁ env' eqenv
... | IAe | IAf = IAe (refl env') IAf
pe-correct (DInt x) env' eqenv = refl
pe-correct (DAdd e e₁) env' eqenv
rewrite pe-correct e env' eqenv | pe-correct e₁ env' eqenv = refl
pe-correct {α = D (Fun σ₁ σ₂)} (DLam e) env' eqenv =
ext {σ₁} {σ₂}
(λ x →
let eqenv₁ : _
eqenv₁ = lem-equiv-env-lift-extend env' eqenv x
eqenv₂ : _
eqenv₂ = cons eqenv₁ (EVar hd) x refl
in pe-correct e (x ∷ env') eqenv₂)
pe-correct (DApp e e₁) env' eqenv
with pe-correct e₁ env' eqenv | pe-correct e env' eqenv
... | IA' | IA = cong₂ (λ f x → f x) IA IA'
pe-correct (e , e₁) env' eqenv = ∧-intro (pe-correct e env' eqenv) (pe-correct e₁ env' eqenv)
pe-correct (Tl e) env' eqenv = pe-correct e env' eqenv
pe-correct (Tr e) env' eqenv = pe-correct e env' eqenv
pe-correct (Fst (e , e₁)) env' eqenv = pe-correct e env' eqenv
pe-correct (Fst e) {aenv = aenv} {env = env} env' eqenv with pe e aenv | ev (strip e) env | pe-correct e env' eqenv
... | e₁ , e₂ | e₁' , e₂' | ∧-intro A B = A
pe-correct (Snd (e , e₁)) env' eqenv = pe-correct e₁ env' eqenv
pe-correct (Snd e) {aenv = aenv} {env = env} env' eqenv with pe e aenv | ev (strip e) env | pe-correct e env' eqenv
... | e₁ , e₂ | e₁' , e₂' | ∧-intro A B = B
pe-correct {α} (Case e e₁ e₂) {aenv = aenv} {env = env} env' eqenv with pe e aenv | ev (strip e) env | pe-correct e env' eqenv
... | tl c | tl c' | L = pe-correct e₁ {aenv = cons c (liftEnv ↝-refl aenv)}
{env = c' ∷ env} env'
(cons (lem-equiv-env-lift-lift (refl env') eqenv) c c' L)
... | tr c | tr c' | R = pe-correct e₂ {aenv = cons c (liftEnv ↝-refl aenv)}
{env = c' ∷ env} env'
(cons (lem-equiv-env-lift-lift (refl env') eqenv) c c' R)
... | tr c | tl c' | ()
... | tl c | tr c' | ()
pe-correct (e ḋ e₁) env' eqenv with pe-correct e env' eqenv | pe-correct e₁ env' eqenv
... | IA | IA' rewrite IA | IA' = refl
pe-correct (DTl e) env' eqenv with pe-correct e env' eqenv
... | IA rewrite IA = refl
pe-correct (DTr e) env' eqenv with pe-correct e env' eqenv
... | IA rewrite IA = refl
pe-correct (DFst e) env' eqenv with pe-correct e env' eqenv
... | IA rewrite IA = refl
pe-correct (DSnd e) env' eqenv with pe-correct e env' eqenv
... | IA rewrite IA = refl
pe-correct (DCase e e₁ e₂) {aenv = aenv} {env = env} env' eqenv with ev (pe e aenv) env' | ev (strip e) env | pe-correct e env' eqenv
... | tl c | tl c' | IA rewrite (→tl {x' = c} {y' = c'} (tl c) (tl c') IA refl refl) =
pe-correct e₁
{aenv = cons (EVar hd) (liftEnv (↝-extend ↝-refl) aenv)}
{env = c' ∷ env} (c' ∷ env') (cons (lem-equiv-env-lift-lift (extend c' (refl env')) eqenv) (EVar hd) c' refl)
... | tr c | tr c' | IA rewrite (→tr {x' = c} {y' = c'} (tr c) (tr c') IA refl refl) =
pe-correct e₂
{aenv = cons (EVar hd) (liftEnv (↝-extend ↝-refl) aenv)}
{env = c' ∷ env} (c' ∷ env')
(cons (lem-equiv-env-lift-lift (extend c' (refl env')) eqenv)
(EVar hd) c' refl)
... | tl c | tr c' | ()
... | tr c | tl c' | ()
pe-correct (↑ x e) {aenv = aenv} {env = env} env' eqenv
with pe-correct e env' eqenv
... | IA = lift-correct x env' (pe e aenv) (ev (strip e) env) IA
| {
"alphanum_fraction": 0.5151922498,
"avg_line_length": 44.7582987552,
"ext": "agda",
"hexsha": "cce1042f90b39cc0b6971e529648af428946e361",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "luminousfennell/polybta",
"max_forks_repo_path": "BTA9.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"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": "luminousfennell/polybta",
"max_issues_repo_path": "BTA9.agda",
"max_line_length": 159,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "luminousfennell/polybta",
"max_stars_repo_path": "BTA9.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-15T04:35:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-15T04:35:29.000Z",
"num_tokens": 16952,
"size": 43147
} |
{-# OPTIONS --without-K --exact-split #-}
module subgroups where
import 15-groups
open 15-groups public
{- Subsets of groups -}
subset-Group :
(l : Level) {l1 : Level} (G : Group l1) → UU ((lsuc l) ⊔ l1)
subset-Group l G = type-Group G → UU-Prop l
is-set-subset-Group :
(l : Level) {l1 : Level} (G : Group l1) → is-set (subset-Group l G)
is-set-subset-Group l G =
is-set-function-type (is-set-UU-Prop l)
{- Defining subgroups -}
contains-unit-subset-Group :
{l1 l2 : Level} (G : Group l1) (P : subset-Group l2 G) → UU l2
contains-unit-subset-Group G P = type-Prop (P (unit-Group G))
is-prop-contains-unit-subset-Group :
{l1 l2 : Level} (G : Group l1) (P : subset-Group l2 G) →
is-prop (contains-unit-subset-Group G P)
is-prop-contains-unit-subset-Group G P = is-prop-type-Prop (P (unit-Group G))
closed-under-mul-subset-Group :
{l1 l2 : Level} (G : Group l1) (P : subset-Group l2 G) → UU (l1 ⊔ l2)
closed-under-mul-subset-Group G P =
(x y : type-Group G) →
type-Prop (P x) → type-Prop (P y) → type-Prop (P (mul-Group G x y))
is-prop-closed-under-mul-subset-Group :
{l1 l2 : Level} (G : Group l1) (P : subset-Group l2 G) →
is-prop (closed-under-mul-subset-Group G P)
is-prop-closed-under-mul-subset-Group G P =
is-prop-Π (λ x →
is-prop-Π (λ y →
is-prop-function-type
( is-prop-function-type
( is-prop-type-Prop (P (mul-Group G x y))))))
closed-under-inv-subset-Group :
{l1 l2 : Level} (G : Group l1) (P : subset-Group l2 G) → UU (l1 ⊔ l2)
closed-under-inv-subset-Group G P =
(x : type-Group G) → type-Prop (P x) → type-Prop (P (inv-Group G x))
is-prop-closed-under-inv-subset-Group :
{l1 l2 : Level} (G : Group l1) (P : subset-Group l2 G) →
is-prop (closed-under-inv-subset-Group G P)
is-prop-closed-under-inv-subset-Group G P =
is-prop-Π
( λ x → is-prop-function-type (is-prop-type-Prop (P (inv-Group G x))))
is-subgroup-Group :
{l1 l2 : Level} (G : Group l1) (P : subset-Group l2 G) → UU (l1 ⊔ l2)
is-subgroup-Group G P =
( contains-unit-subset-Group G P) ×
( ( closed-under-mul-subset-Group G P) ×
( closed-under-inv-subset-Group G P))
is-prop-is-subgroup-Group :
{l1 l2 : Level} (G : Group l1) (P : subset-Group l2 G) →
is-prop (is-subgroup-Group G P)
is-prop-is-subgroup-Group G P =
is-prop-prod
( is-prop-contains-unit-subset-Group G P)
( is-prop-prod
( is-prop-closed-under-mul-subset-Group G P)
( is-prop-closed-under-inv-subset-Group G P))
{- Introducing the type of all subgroups of a group G -}
Subgroup :
(l : Level) {l1 : Level} (G : Group l1) → UU ((lsuc l) ⊔ l1)
Subgroup l G = Σ (type-Group G → UU-Prop l) (is-subgroup-Group G)
subset-Subgroup :
{l1 l2 : Level} (G : Group l1) →
( Subgroup l2 G) → ( subset-Group l2 G)
subset-Subgroup G = pr1
is-emb-subset-Subgroup :
{l1 l2 : Level} (G : Group l1) → is-emb (subset-Subgroup {l2 = l2} G)
is-emb-subset-Subgroup G = is-emb-pr1-is-subtype (is-prop-is-subgroup-Group G)
type-subset-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
(type-Group G → UU l2)
type-subset-Subgroup G P x = type-Prop (subset-Subgroup G P x)
is-prop-type-subset-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
(x : type-Group G) → is-prop (type-subset-Subgroup G P x)
is-prop-type-subset-Subgroup G P x =
is-prop-type-Prop (subset-Subgroup G P x)
is-subgroup-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
is-subgroup-Group G (subset-Subgroup G P)
is-subgroup-Subgroup G = pr2
contains-unit-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
contains-unit-subset-Group G (subset-Subgroup G P)
contains-unit-Subgroup G P = pr1 (is-subgroup-Subgroup G P)
closed-under-mul-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
closed-under-mul-subset-Group G (subset-Subgroup G P)
closed-under-mul-Subgroup G P = pr1 (pr2 (is-subgroup-Subgroup G P))
closed-under-inv-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
closed-under-inv-subset-Group G (subset-Subgroup G P)
closed-under-inv-Subgroup G P = pr2 (pr2 (is-subgroup-Subgroup G P))
{- Given a subgroup, we construct a group -}
type-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) → UU (l1 ⊔ l2)
type-group-Subgroup G P =
Σ (type-Group G) (type-subset-Subgroup G P)
incl-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
type-group-Subgroup G P → type-Group G
incl-group-Subgroup G P = pr1
is-emb-incl-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
is-emb (incl-group-Subgroup G P)
is-emb-incl-group-Subgroup G P =
is-emb-pr1-is-subtype (is-prop-type-subset-Subgroup G P)
eq-subgroup-eq-group :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
{x y : type-group-Subgroup G P} →
Id (incl-group-Subgroup G P x) (incl-group-Subgroup G P y) → Id x y
eq-subgroup-eq-group G P {x} {y} =
inv-is-equiv (is-emb-incl-group-Subgroup G P x y)
set-group-Subgroup :
{l1 l2 : Level} (G : Group l1) → Subgroup l2 G → UU-Set (l1 ⊔ l2)
set-group-Subgroup G P =
pair ( type-group-Subgroup G P)
( λ x y →
is-prop-is-equiv
( Id (pr1 x) (pr1 y))
( ap (incl-group-Subgroup G P))
( is-emb-incl-group-Subgroup G P x y)
( is-set-type-Group G (pr1 x) (pr1 y)))
unit-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) → type-group-Subgroup G P
unit-group-Subgroup G P =
pair ( unit-Group G)
( contains-unit-Subgroup G P)
mul-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
( x y : type-group-Subgroup G P) → type-group-Subgroup G P
mul-group-Subgroup G P x y =
pair ( mul-Group G (pr1 x) (pr1 y))
( closed-under-mul-Subgroup G P (pr1 x) (pr1 y) (pr2 x) (pr2 y))
inv-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
type-group-Subgroup G P → type-group-Subgroup G P
inv-group-Subgroup G P x =
pair (inv-Group G (pr1 x)) (closed-under-inv-Subgroup G P (pr1 x) (pr2 x))
is-associative-mul-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
( x y z : type-group-Subgroup G P) →
Id (mul-group-Subgroup G P (mul-group-Subgroup G P x y) z)
(mul-group-Subgroup G P x (mul-group-Subgroup G P y z))
is-associative-mul-group-Subgroup G P x y z =
eq-subgroup-eq-group G P (is-associative-mul-Group G (pr1 x) (pr1 y) (pr1 z))
left-unit-law-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
( x : type-group-Subgroup G P) →
Id (mul-group-Subgroup G P (unit-group-Subgroup G P) x) x
left-unit-law-group-Subgroup G P x =
eq-subgroup-eq-group G P (left-unit-law-Group G (pr1 x))
right-unit-law-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
( x : type-group-Subgroup G P) →
Id (mul-group-Subgroup G P x (unit-group-Subgroup G P)) x
right-unit-law-group-Subgroup G P x =
eq-subgroup-eq-group G P (right-unit-law-Group G (pr1 x))
left-inverse-law-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
( x : type-group-Subgroup G P) →
Id ( mul-group-Subgroup G P (inv-group-Subgroup G P x) x)
( unit-group-Subgroup G P)
left-inverse-law-group-Subgroup G P x =
eq-subgroup-eq-group G P (left-inverse-law-Group G (pr1 x))
right-inverse-law-group-Subgroup :
{l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
( x : type-group-Subgroup G P) →
Id ( mul-group-Subgroup G P x (inv-group-Subgroup G P x))
( unit-group-Subgroup G P)
right-inverse-law-group-Subgroup G P x =
eq-subgroup-eq-group G P (right-inverse-law-Group G (pr1 x))
group-Subgroup :
{l1 l2 : Level} (G : Group l1) → Subgroup l2 G → Group (l1 ⊔ l2)
group-Subgroup G P =
pair
( pair
( set-group-Subgroup G P)
( pair
( mul-group-Subgroup G P)
( is-associative-mul-group-Subgroup G P)))
( pair
( pair
( unit-group-Subgroup G P)
( pair
( left-unit-law-group-Subgroup G P)
( right-unit-law-group-Subgroup G P)))
( pair
( inv-group-Subgroup G P)
( pair
( left-inverse-law-group-Subgroup G P)
( right-inverse-law-group-Subgroup G P))))
{- We show that the inclusion from group-Subgroup G P → G is a group
homomorphism -}
preserves-mul-incl-group-Subgroup :
{ l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
preserves-mul-Group (group-Subgroup G P) G (incl-group-Subgroup G P)
preserves-mul-incl-group-Subgroup G P (pair x p) (pair y q) = refl
hom-group-Subgroup :
{ l1 l2 : Level} (G : Group l1) (P : Subgroup l2 G) →
hom-Group (group-Subgroup G P) G
hom-group-Subgroup G P =
pair (incl-group-Subgroup G P) (preserves-mul-incl-group-Subgroup G P)
{- We define another type of subgroups of G as the type of group inclusions -}
emb-Group :
{ l1 l2 : Level} (G : Group l1) (H : Group l2) → UU (l1 ⊔ l2)
emb-Group G H = Σ (hom-Group G H) (λ f → is-emb (map-hom-Group G H f))
emb-Group-Slice :
(l : Level) {l1 : Level} (G : Group l1) → UU ((lsuc l) ⊔ l1)
emb-Group-Slice l G =
Σ ( Group l)
( λ H → emb-Group H G)
emb-group-slice-Subgroup :
{ l1 l2 : Level} (G : Group l1) →
Subgroup l2 G → emb-Group-Slice (l1 ⊔ l2) G
emb-group-slice-Subgroup G P =
pair
( group-Subgroup G P)
( pair
( hom-group-Subgroup G P)
( is-emb-incl-group-Subgroup G P))
| {
"alphanum_fraction": 0.630330234,
"avg_line_length": 34.6555555556,
"ext": "agda",
"hexsha": "c2829afba0aa33c11656e41274886fb686fb16dc",
"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": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "tmoux/HoTT-Intro",
"max_forks_repo_path": "Agda/subgroups.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "tmoux/HoTT-Intro",
"max_issues_repo_path": "Agda/subgroups.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "tmoux/HoTT-Intro",
"max_stars_repo_path": "Agda/subgroups.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3463,
"size": 9357
} |
module Basic.AST where
import Data.Bool as Bool using (not)
open import Data.Bool hiding (not; if_then_else_)
open import Data.Fin using (Fin; suc; zero; #_)
open import Data.Nat
open import Data.Vec
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Utils.Decidable
{-
This module covers the first chapter of the book.
We omitted a couple of proofs that are present in the chapter.
In particular, determinism and totality of the evaluation of expressions
is a trivial consequence of Agda's totality, so there's no need to bother
with it here. Also, the notion of "composionality" as mentioned in book corresponds
simply to structural recursion in Agda.
Also, we skipped the proofs about the evaluation of expression with substitutions
(exercise 1.14) and contexts with substitutions (exercise 1.13), since we make
no use of these in other proofs.
-}
-- Our type universe (it's not a large one).
data Ty : Set where
bool nat : Ty
{-
Interpretation of types into Agda sets.
Note that we use natural numbers instead of integers, since naturals are
much simpler to handle in formal contexts (also, there's not enough Agda library
support for integers).
-}
⟦_⟧ᵗ : Ty → Set
⟦ nat ⟧ᵗ = ℕ
⟦ bool ⟧ᵗ = Bool
{-
This is a point where we make a departure from the book. The book defines states as:
State = String → ℕ
This is supposed to be a total funuction, and the book doesn't concern itself with scope
errors or shadowing, but we certainly have to do so in Agda.
So we opt for de Bruijn indices as variables and a finite vector as State. These are as
simple to handle as it can get, and we also get alpha equality of programs for free.
On the flip side, we have much less readable programs.
-}
State : ℕ → Set
State = Vec ℕ
{-
In the book there's a mutual definition of boolean and numeric expressions.
We instead have a single universe-indexed type family. It's more convenient, and
it's also equivalent to the mutual definition (it's a standard Agda/Haskell trick
to encode multiple types data as a single indexed type).
-}
data Exp (n : ℕ) : Ty → Set where
lit : ℕ → Exp n nat
add mul sub : Exp n nat → Exp n nat → Exp n nat
var : Fin n → Exp n nat
tt ff : Exp n bool
eq lte lt : Exp n nat → Exp n nat → Exp n bool
and : Exp n bool → Exp n bool → Exp n bool
not : Exp n bool → Exp n bool
{-
Statements are parameterized by the size of the State they operate on. Since the
vanilla "While" language has no declarations or other features that might change
the size of the state, we are fine with this. It also allows us to use finite numbers
as de Bruijn indices.
-}
infixr 5 _:=_
infixr 4 _,_
data St (n : ℕ) : Set where
_:=_ : Fin n → Exp n nat → St n
skip : St n
_,_ : St n → St n → St n
if_then_else_ : Exp n bool → St n → St n → St n
while_do_ : Exp n bool → St n → St n
{-
The semantics of expressions follows the book exactly.
-}
⟦_⟧ᵉ : ∀ {n t} → Exp n t → State n → ⟦ t ⟧ᵗ
⟦ lit x ⟧ᵉ s = x
⟦ add a b ⟧ᵉ s = ⟦ a ⟧ᵉ s + ⟦ b ⟧ᵉ s
⟦ mul a b ⟧ᵉ s = ⟦ a ⟧ᵉ s * ⟦ b ⟧ᵉ s
⟦ sub a b ⟧ᵉ s = ⟦ a ⟧ᵉ s ∸ ⟦ b ⟧ᵉ s
⟦ var x ⟧ᵉ s = lookup x s
⟦ tt ⟧ᵉ s = true
⟦ ff ⟧ᵉ s = false
⟦ eq a b ⟧ᵉ s = ⌊ ⟦ a ⟧ᵉ s ≡⁇ ⟦ b ⟧ᵉ s ⌋
⟦ lte a b ⟧ᵉ s = ⌊ ⟦ a ⟧ᵉ s ≤⁇ ⟦ b ⟧ᵉ s ⌋
⟦ lt a b ⟧ᵉ s = ⌊ ⟦ a ⟧ᵉ s <⁇ ⟦ b ⟧ᵉ s ⌋
⟦ and a b ⟧ᵉ s = ⟦ a ⟧ᵉ s ∧ ⟦ b ⟧ᵉ s
⟦ not e ⟧ᵉ s = Bool.not (⟦ e ⟧ᵉ s)
| {
"alphanum_fraction": 0.6633778294,
"avg_line_length": 30.7678571429,
"ext": "agda",
"hexsha": "357a325a3fb2526ef8e03ee6ca7e2ff23384ce40",
"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": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_forks_repo_path": "Basic/AST.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"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": "AndrasKovacs/SemanticsWithApplications",
"max_issues_repo_path": "Basic/AST.agda",
"max_line_length": 88,
"max_stars_count": 8,
"max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_stars_repo_path": "Basic/AST.agda",
"max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z",
"num_tokens": 1173,
"size": 3446
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Compose where
-- Composition of Adjoints
open import Level
open import Data.Product using (_,_; _×_)
open import Function using (_$_) renaming (_∘_ to _∙_)
open import Function.Equality using (Π; _⟶_)
import Function.Inverse as FI
open import Relation.Binary using (Rel; IsEquivalence; Setoid)
-- be explicit in imports to 'see' where the information comes from
open import Categories.Adjoint using (Adjoint; _⊣_)
open import Categories.Category.Core using (Category)
open import Categories.Category.Product using (Product; _⁂_)
open import Categories.Category.Instance.Setoids
open import Categories.Morphism
open import Categories.Functor using (Functor; _∘F_) renaming (id to idF)
open import Categories.Functor.Bifunctor using (Bifunctor)
open import Categories.Functor.Hom using (Hom[_][-,-])
open import Categories.Functor.Construction.LiftSetoids
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper; _∘ₕ_; _∘ᵥ_; _∘ˡ_; _∘ʳ_)
renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (NaturalIsomorphism; unitorˡ; unitorʳ; associator; _≃_)
import Categories.Morphism.Reasoning as MR
private
variable
o o′ o″ ℓ ℓ′ ℓ″ e e′ e″ : Level
C D E : Category o ℓ e
-- Adjoints compose; we can't be sloppy, so associators and unitors must be inserted.
-- Use single letters in pairs, so L & M on the left, and R & S on the right
_∘⊣_ : {L : Functor C D} {R : Functor D C} {M : Functor D E} {S : Functor E D} →
L ⊣ R → M ⊣ S → (M ∘F L) ⊣ (R ∘F S)
_∘⊣_ {C = C} {D = D} {E = E} {L = L} {R} {M} {S} LR MS = record
{ unit = ((F⇐G (associator _ S R) ∘ᵥ R ∘ˡ (F⇒G (associator L M S))) ∘ᵥ
(R ∘ˡ (MSη′ ∘ʳ L)) ∘ᵥ (R ∘ˡ (F⇐G unitorˡ))) ∘ᵥ LRη′
; counit = MSε′ ∘ᵥ (((F⇒G (unitorʳ {F = M}) ∘ʳ S) ∘ᵥ ((M ∘ˡ LRε′) ∘ʳ S)) ∘ᵥ
(F⇒G (associator R L M) ∘ʳ S) ) ∘ᵥ F⇐G (associator S R (M ∘F L) )
; zig = λ {A} → zig′ {A}
; zag = λ {B} → zag′ {B}
}
where
open NaturalIsomorphism using (F⇒G; F⇐G)
module LR = Adjoint LR using (zig; zag) renaming (unit to LRη′; counit to LRε′)
module MS = Adjoint MS using (zig; zag) renaming (unit to MSη′; counit to MSε′)
module LRη = NaturalTransformation (Adjoint.unit LR) using () renaming (η to ηLR)
module MSη = NaturalTransformation (Adjoint.unit MS) using (commute) renaming (η to ηMS)
module LRε = NaturalTransformation (Adjoint.counit LR) using (commute) renaming (η to εLR)
module MSε = NaturalTransformation (Adjoint.counit MS) using () renaming (η to εMS)
module C = Category C using (Obj; id; _∘_; _≈_; sym-assoc; ∘-resp-≈ˡ; ∘-resp-≈;
∘-resp-≈ʳ; identityˡ; identityʳ; module HomReasoning)
module D = Category D using (id; _∘_; ∘-resp-≈ˡ; sym-assoc; ∘-resp-≈ʳ; identityˡ;
module HomReasoning; assoc)
module E = Category E using (Obj; id; _∘_; _≈_; identityˡ; ∘-resp-≈ʳ; module HomReasoning;
assoc; sym-assoc; identityʳ)
module L = Functor L using (homomorphism; F-resp-≈) renaming (F₀ to L₀; F₁ to L₁)
module M = Functor M using (F-resp-≈; identity; homomorphism) renaming (F₀ to M₀; F₁ to M₁)
module R = Functor R using (F-resp-≈; identity; homomorphism) renaming (F₀ to R₀; F₁ to R₁)
module S = Functor S using (F-resp-≈; homomorphism) renaming (F₀ to S₀; F₁ to S₁)
open LR; open MS; open LRη; open LRε; open MSε; open MSη; open L; open M; open R; open S
zig′ : {A : C.Obj} → (εMS (M₀ (L₀ A)) E.∘
((E.id E.∘ M₁ (εLR (S₀ (M₀ (L₀ A))))) E.∘ E.id) E.∘ E.id)
E.∘ M₁ (L₁ (((C.id C.∘ R₁ D.id) C.∘ R₁ (ηMS (L₀ A)) C.∘ R₁ D.id) C.∘ ηLR A))
E.≈ E.id
-- use "inverted" format here, where rules are out-dented
zig′ {A} = begin
(εMS (M₀ (L₀ A)) E.∘ ((E.id E.∘ M₁ (εLR (S₀ (M₀ (L₀ A))))) E.∘ E.id) E.∘ E.id)
E.∘ M₁ (L₁ (((C.id C.∘ R₁ D.id) C.∘ R₁ (ηMS (L₀ A)) C.∘ R₁ D.id) C.∘ ηLR A))
≈⟨ ( refl⟩∘⟨ (E.identityʳ ○ E.identityʳ ○ E.identityˡ)) ⟩∘⟨refl ⟩ -- get rid of those pesky E.id
(εMS (M₀ (L₀ A)) E.∘ M₁ (εLR (S₀ (M₀ (L₀ A)))))
E.∘ M₁ (L₁ (((C.id C.∘ R₁ D.id) C.∘ R₁ (ηMS (L₀ A)) C.∘ R₁ D.id) C.∘ ηLR A))
≈⟨ E.assoc ○ E.∘-resp-≈ʳ (⟺ M.homomorphism) ⟩
εMS (M₀ (L₀ A)) E.∘
M₁ (εLR (S₀ (M₀ (L₀ A))) D.∘ L₁ (((C.id C.∘ R₁ D.id) C.∘ R₁ (ηMS (L₀ A)) C.∘ R₁ D.id) C.∘ ηLR A))
-- below: get rid of lots of pesky id. Nasty bit of nested equational reasoning, but nothing deep
≈⟨ refl⟩∘⟨ M.F-resp-≈ (D.∘-resp-≈ʳ (L.F-resp-≈
(C.∘-resp-≈ˡ (C.∘-resp-≈ C.identityˡ (C.∘-resp-≈ʳ R.identity) C.HomReasoning.○
let _⊚_ = C.HomReasoning._○_ in C.∘-resp-≈ R.identity C.identityʳ ⊚ C.identityˡ)))) ⟩
εMS (M₀ (L₀ A)) E.∘ M₁ (εLR (S₀ (M₀ (L₀ A))) D.∘ L₁ ((R₁ (ηMS (L₀ A))) C.∘ ηLR A))
≈⟨ refl⟩∘⟨ M.F-resp-≈ (D.∘-resp-≈ʳ L.homomorphism) ⟩
εMS (M₀ (L₀ A)) E.∘ M₁ (εLR (S₀ (M₀ (L₀ A))) D.∘ L₁ (R₁ (ηMS (L₀ A))) D.∘ L₁ (ηLR A))
≈⟨ refl⟩∘⟨ M.F-resp-≈ D.sym-assoc ⟩
εMS (M₀ (L₀ A)) E.∘ M₁ ((εLR (S₀ (M₀ (L₀ A))) D.∘ L₁ (R₁ (ηMS (L₀ A)))) D.∘ L₁ (ηLR A))
≈⟨ refl⟩∘⟨ M.F-resp-≈ (D.∘-resp-≈ˡ (LRε.commute _)) ⟩
εMS (M₀ (L₀ A)) E.∘ M₁ ( (_ D.∘ εLR _) D.∘ L₁ (ηLR A))
≈⟨ refl⟩∘⟨ M.homomorphism ⟩
εMS (M₀ (L₀ A)) E.∘ M₁ (_ D.∘ εLR _) E.∘ M₁ (L₁ (ηLR A))
≈⟨ refl⟩∘⟨ ( M.homomorphism ⟩∘⟨refl ) ⟩
εMS (M₀ (L₀ A)) E.∘ (M₁ (ηMS (L₀ A)) E.∘ M₁ (εLR _)) E.∘ M₁ (L₁ (ηLR A))
≈⟨ E.∘-resp-≈ʳ E.assoc ○ E.sym-assoc ⟩
(εMS (M₀ (L₀ A)) E.∘ M₁ (ηMS (L₀ A))) E.∘ (M₁ (εLR _) E.∘ M₁ (L₁ (ηLR A)))
≈⟨ MS.zig ⟩∘⟨refl ⟩
E.id E.∘ (M₁ (εLR _) E.∘ M₁ (L₁ (ηLR A)))
≈⟨ E.identityˡ ⟩
M₁ (εLR _) E.∘ M₁ (L₁ (ηLR A))
≈˘⟨ M.homomorphism ⟩
M₁ (εLR _ D.∘ L₁ (ηLR A))
≈⟨ M.F-resp-≈ LR.zig ○ M.identity ⟩
E.id ∎
where open E.HomReasoning
zag′ : {B : E.Obj} → R₁ (S₁ (εMS B E.∘ ((E.id E.∘ M₁ (εLR (S₀ B))) E.∘ E.id) E.∘ E.id))
C.∘ ((C.id C.∘ R₁ D.id) C.∘ R₁ (ηMS (L₀ (R₀ (S₀ B)))) C.∘ R₁ D.id) C.∘
ηLR (R₀ (S₀ B)) C.≈ C.id
zag′ {B} =
let _⊚_ = E.HomReasoning._○_ in
begin
R₁ (S₁ (εMS B E.∘ ((E.id E.∘ M₁ (εLR (S₀ B))) E.∘ E.id) E.∘ E.id))
C.∘ ((C.id C.∘ R₁ D.id) C.∘ R₁ (ηMS (L₀ (R₀ (S₀ B)))) C.∘ R₁ D.id) C.∘
ηLR (R₀ (S₀ B)) -- get rid of all those id
≈⟨ R.F-resp-≈ (S.F-resp-≈ (E.∘-resp-≈ʳ (E.identityʳ ⊚ (E.identityʳ ⊚ E.identityˡ)))) ⟩∘⟨
C.∘-resp-≈ˡ (C.∘-resp-≈ C.identityˡ (C.∘-resp-≈ʳ R.identity) ○
C.∘-resp-≈ R.identity C.identityʳ ○ C.identityˡ) ⟩
R₁ (S₁ (εMS B E.∘ M₁ (εLR (S₀ B)))) C.∘ R₁ (ηMS (L₀ (R₀ (S₀ B)))) C.∘ ηLR (R₀ (S₀ B))
≈⟨ C.sym-assoc ⟩
(R₁ (S₁ (εMS B E.∘ M₁ (εLR (S₀ B)))) C.∘ R₁ (ηMS (L₀ (R₀ (S₀ B))))) C.∘ ηLR (R₀ (S₀ B))
≈˘⟨ R.homomorphism ⟩∘⟨refl ⟩
R₁ (S₁ (εMS B E.∘ M₁ (εLR (S₀ B))) D.∘ ηMS (L₀ (R₀ (S₀ B)))) C.∘ ηLR (R₀ (S₀ B))
≈⟨ R.F-resp-≈ (D.∘-resp-≈ˡ S.homomorphism) ⟩∘⟨refl ⟩
R₁ ((S₁ (εMS B) D.∘ (S₁ (M₁ (εLR (S₀ B))))) D.∘ ηMS (L₀ (R₀ (S₀ B)))) C.∘ ηLR (R₀ (S₀ B))
≈⟨ R.F-resp-≈ D.assoc ⟩∘⟨refl ⟩
R₁ (S₁ (εMS B) D.∘ S₁ (M₁ (εLR (S₀ B))) D.∘ ηMS (L₀ (R₀ (S₀ B)))) C.∘ ηLR (R₀ (S₀ B))
≈⟨ R.F-resp-≈ (D.∘-resp-≈ʳ (D.HomReasoning.⟺ (MSη.commute (εLR (S₀ B))))) ⟩∘⟨refl ⟩
R₁ (S₁ (εMS B) D.∘ ηMS (S₀ B) D.∘ εLR (S₀ B)) C.∘ ηLR (R₀ (S₀ B))
≈⟨ R.F-resp-≈ D.sym-assoc ⟩∘⟨refl ⟩
R₁ ((S₁ (εMS B) D.∘ ηMS (S₀ B)) D.∘ εLR (S₀ B)) C.∘ ηLR (R₀ (S₀ B))
≈⟨ R.F-resp-≈ (D.∘-resp-≈ˡ MS.zag) ⟩∘⟨refl ⟩
R₁ (D.id D.∘ εLR (S₀ B)) C.∘ ηLR (R₀ (S₀ B))
≈⟨ C.∘-resp-≈ˡ (R.F-resp-≈ D.identityˡ) ⟩
R₁ (εLR (S₀ B)) C.∘ ηLR (R₀ (S₀ B))
≈⟨ LR.zag ⟩
C.id ∎
where open C.HomReasoning
| {
"alphanum_fraction": 0.5451838426,
"avg_line_length": 55.1714285714,
"ext": "agda",
"hexsha": "a67069171ba86a539070aefaa3b2edf7c066faa5",
"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/Adjoint/Compose.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/Adjoint/Compose.agda",
"max_line_length": 108,
"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/Adjoint/Compose.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": 3748,
"size": 7724
} |
module #6 where
open import Level
open import Data.Bool
open import Relation.Binary.PropositionalEquality
{-
Exercise 1.6. Show that if we define A × B :≡ ∏(x:2) rec2(U, A, B, x), then we can give a
definition of indA×B for which the definitional equalities stated in §1.5 hold propositionally (i.e. using equality
types). (This requires the function extensionality axiom, which is introduced in §2.9.)
-}
rec₂ : ∀{c}{C : Set c} → C → C → Bool → C
rec₂ c₀ c₁ true = c₁
rec₂ c₀ c₁ false = c₀
ind₂ : ∀{c}(C : Bool → Set c) → C false → C true → (x : Bool) → C x
ind₂ C c₀ c₁ true = c₁
ind₂ C c₀ c₁ false = c₀
_×_ : ∀ {i} → Set i → Set i → Set i
A × B = (b : Bool) → if b then A else B
module ProductTwo {a}{A B : Set a} where
_,_ : A → B → A × B
_,_ x y true = x
_,_ x y false = y
proj₁ : A × B → A
proj₁ x = x true
proj₂ : A × B → B
proj₂ x = x false
postulate
extensionality : ∀ {a b} {A : Set a} {B : A → Set b} (f g : (a : A) → B a) → (∀ x → f x ≡ g x) → f ≡ g
indₓ₂ : ∀{c}{C : A × B -> Set c} → (f : (x : A)(y : B) → C (x , y)) → (x : A × B) → C (proj₁ x , proj₂ x)
indₓ₂ f x = f (proj₁ x) (proj₂ x)
indₓ₂-β : ∀{c}{C : A × B -> Set c} → (f : (x : A)(y : B) → C (x , y)) → (x : A × B) → indₓ₂ {C = C} f x ≡ f (proj₁ x) (proj₂ x)
indₓ₂-β f x = refl
| {
"alphanum_fraction": 0.5472136223,
"avg_line_length": 28.7111111111,
"ext": "agda",
"hexsha": "b72a8d0874fdb73cce0fdb715f55eaa80b9ebfbb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Chapter1/#6.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Chapter1/#6.agda",
"max_line_length": 129,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Chapter1/#6.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 549,
"size": 1292
} |
{-# OPTIONS --without-K #-}
module sets.finite.infinite where
open import sum
open import equality.core
open import function.isomorphism.core
open import function.isomorphism.utils
open import sets.nat
open import sets.empty
open import sets.unit
open import sets.fin.core
open import sets.fin.properties
open import sets.fin.universe
open import sets.finite.core
ℕ-not-finite : ¬ (IsFinite ℕ)
ℕ-not-finite (n , fℕ) = suc-fixpoint (sym (Fin-inj iso-suc))
where
iso-suc : Fin n ≅ Fin (suc n)
iso-suc = sym≅ fℕ
·≅ isoℕ
·≅ ⊎-ap-iso refl≅ fℕ
·≅ sym≅ fin-struct-iso
| {
"alphanum_fraction": 0.6897689769,
"avg_line_length": 25.25,
"ext": "agda",
"hexsha": "b2db6e2bff37df8b515ba0dc4e808273e1ef3aa9",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/finite/infinite.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/finite/infinite.agda",
"max_line_length": 60,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/sets/finite/infinite.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 187,
"size": 606
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use `Algebra` or `Algebra.Core`
-- instead.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Algebra.FunctionProperties.Core where
{-# WARNING_ON_IMPORT
"Algebra.FunctionProperties.Core was deprecated in v1.2.
Use Algebra.Core instead."
#-}
open import Algebra.Core public
| {
"alphanum_fraction": 0.5175257732,
"avg_line_length": 26.9444444444,
"ext": "agda",
"hexsha": "9ae7efc60b537b5a0d1dbc69b526a529300d9dfa",
"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/FunctionProperties/Core.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/FunctionProperties/Core.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/FunctionProperties/Core.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": 82,
"size": 485
} |
{- 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 LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.RecoveryData as RecoveryData
import LibraBFT.Impl.Consensus.TestUtils.MockSharedStorage as MockSharedStorage
open import LibraBFT.Impl.OBM.Logging.Logging
import LibraBFT.Impl.Storage.DiemDB.LedgerStore.LedgerStore as LedgerStore
import LibraBFT.Impl.Types.LedgerInfo as LedgerInfo
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
import Util.KVMap as Map
open import Util.Prelude
------------------------------------------------------------------------------
open import Data.String using (String)
module LibraBFT.Impl.Consensus.TestUtils.MockStorage where
------------------------------------------------------------------------------
postulate -- TODO-2: sortOn
sortOn : (Block → Round) → List Block → List Block
------------------------------------------------------------------------------
start : MockStorage → Either ErrLog RecoveryData
------------------------------------------------------------------------------
newWithLedgerInfo : MockSharedStorage → LedgerInfo → Either ErrLog MockStorage
newWithLedgerInfo sharedStorage ledgerInfo = do
li ← if ledgerInfo ^∙ liEndsEpoch
then pure ledgerInfo
else LedgerInfo.mockGenesis (just (sharedStorage ^∙ mssValidatorSet))
let lis = LedgerInfoWithSignatures∙new li Map.empty
pure $ MockStorage∙new
(sharedStorage & mssLis %~ Map.insert (lis ^∙ liwsLedgerInfo ∙ liVersion) lis)
li
(DiemDB∙new LedgerStore.new)
getLedgerRecoveryData : MockStorage → LedgerRecoveryData
getLedgerRecoveryData self =
LedgerRecoveryData∙new (self ^∙ msStorageLedger)
tryStart : MockStorage → Either ErrLog RecoveryData
tryStart self =
withErrCtx' (here' []) $
RecoveryData.new
(self ^∙ msSharedStorage ∙ mssLastVote)
(getLedgerRecoveryData self)
(sortOn (_^∙ bRound) (Map.elems (self ^∙ msSharedStorage ∙ mssBlock)))
RootMetadata∙new
(Map.elems (self ^∙ msSharedStorage ∙ mssQc))
(self ^∙ msSharedStorage ∙ mssHighestTimeoutCertificate)
where
here' : List String → List String
here' t = "MockStorage" ∷ "tryStart" ∷ t
startForTesting : ValidatorSet → Maybe LedgerInfoWithSignatures
→ Either ErrLog (RecoveryData × PersistentLivenessStorage)
startForTesting validatorSet obmMLIWS = do
(sharedStorage , genesisLi) ←
case obmMLIWS of λ where
nothing → do
g ← LedgerInfo.mockGenesis (just validatorSet)
pure (MockSharedStorage.new validatorSet , g)
(just liws) →
pure (MockSharedStorage.newObmWithLIWS validatorSet liws , liws ^∙ liwsLedgerInfo)
storage ← newWithLedgerInfo sharedStorage genesisLi
ss ← withErrCtx' (here' []) (start storage)
pure (ss , storage)
where
here' : List String → List String
here' t = "MockStorage" ∷ "startForTesting" ∷ t
abstract
startForTesting-ed-abs : ValidatorSet → Maybe LedgerInfoWithSignatures
→ EitherD ErrLog (RecoveryData × PersistentLivenessStorage)
startForTesting-ed-abs vs mliws = fromEither $ startForTesting vs mliws
------------------------------------------------------------------------------
saveTreeE
: List Block → List QuorumCert → MockStorage
→ Either ErrLog MockStorage
saveTreeM
: List Block → List QuorumCert → MockStorage
→ LBFT (Either ErrLog MockStorage)
saveTreeM bs qcs db = do
logInfo fakeInfo -- [ "MockStorage", "saveTreeM", show (length bs), show (length qcs) ]
pure (saveTreeE bs qcs db)
saveTreeE bs qcs db =
pure (db & msSharedStorage ∙ mssBlock %~ insertBs
& msSharedStorage ∙ mssQc %~ insertQCs)
where
insertBs : Map.KVMap HashValue Block → Map.KVMap HashValue Block
insertBs m = foldl' (λ acc b → Map.insert (b ^∙ bId) b acc) m bs
insertQCs : Map.KVMap HashValue QuorumCert → Map.KVMap HashValue QuorumCert
insertQCs m = foldl' (λ acc qc → Map.insert (qc ^∙ qcCertifiedBlock ∙ biId) qc acc) m qcs
pruneTreeM
: List HashValue → MockStorage
→ LBFT (Either ErrLog MockStorage)
pruneTreeM ids db = do
logInfo fakeInfo -- ["MockStorage", "pruneTreeM", show (fmap lsHV ids)]
ok (db & msSharedStorage ∙ mssBlock %~ deleteBs
& msSharedStorage ∙ mssQc %~ deleteQCs)
-- TODO : verifyConsistency
where
deleteBs : Map.KVMap HashValue Block → Map.KVMap HashValue Block
deleteBs m = foldl' (flip Map.delete) m ids
deleteQCs : Map.KVMap HashValue QuorumCert → Map.KVMap HashValue QuorumCert
deleteQCs m = foldl' (flip Map.delete) m ids
saveStateM
: Vote → MockStorage
→ LBFT (Either ErrLog MockStorage)
saveStateM v db = do
logInfo fakeInfo -- ["MockStorage", "saveStateM", lsV v]
ok (db & msSharedStorage ∙ mssLastVote ?~ v)
start = tryStart
saveHighestTimeoutCertificateM
: TimeoutCertificate → MockStorage
→ LBFT (Either ErrLog MockStorage)
saveHighestTimeoutCertificateM tc db = do
logInfo fakeInfo -- ["MockStorage", "saveHighestTimeoutCertificateM", lsTC tc]
ok (db & msSharedStorage ∙ mssHighestTimeoutCertificate ?~ tc)
retrieveEpochChangeProofED
: Version → MockStorage
→ EitherD ErrLog EpochChangeProof
retrieveEpochChangeProofED v db = case Map.lookup v (db ^∙ msSharedStorage ∙ mssLis) of λ where
nothing → LeftD fakeErr -- ["MockStorage", "retrieveEpochChangeProofE", "not found", show v])
(just lis) → pure (EpochChangeProof∙new (lis ∷ []) false)
abstract
retrieveEpochChangeProofED-abs = retrieveEpochChangeProofED
retrieveEpochChangeProofED-abs-≡ : retrieveEpochChangeProofED-abs ≡ retrieveEpochChangeProofED
retrieveEpochChangeProofED-abs-≡ = refl
| {
"alphanum_fraction": 0.6675496689,
"avg_line_length": 40,
"ext": "agda",
"hexsha": "5f039d18842573eaa7e211c21bb36d78a15234ab",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Consensus/TestUtils/MockStorage.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Consensus/TestUtils/MockStorage.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Consensus/TestUtils/MockStorage.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1633,
"size": 6040
} |
{-# OPTIONS --safe #-}
module Generics.Constructions.Injective where
open import Generics.Prelude hiding (lookup; pi; curry; icong)
open import Generics.Telescope
open import Generics.Desc
open import Generics.All
open import Generics.HasDesc
open import Relation.Binary.PropositionalEquality.Properties
PathOver : ∀ {i j} {A : Set i} (B : A → Set j) {x y : A}
(p : x ≡ y)
(u : B x) (v : B y)
→ Set j
PathOver B refl u v = u ≡ v
module _
{P I ℓ} {A : Indexed P I ℓ} (H : HasDesc {P} {I} {ℓ} A)
{p}
where
open HasDesc H
private
variable
V : ExTele P
i i₁ i₂ : ⟦ I ⟧tel p
v v₁ v₂ : ⟦ V ⟧tel p
c ℓ′ : Level
countArgs : ConDesc P V I → ℕ
countArgs (var _) = zero
countArgs (π _ _ C) = suc (countArgs C)
countArgs (_ ⊗ B) = suc (countArgs B)
-- | Compute level of projection
levelProj : (C : ConDesc P V I) (m : Fin (countArgs C)) → Level
levelProj (π {ℓ′} ai S C) zero = ℓ′
levelProj (π ai S C) (suc m) = levelProj C m
levelProj (A ⊗ B) zero = levelIndArg A ℓ
levelProj (A ⊗ B) (suc m) = levelProj B m
-- TODO (for Lucas of tomorrow):
-- ⟦ v₁ ≡ v₂ ⟧
-- private
-- proj₂-id : ∀ {a} {A : Set a} {ℓB : A → Level} {B : ∀ x → Set (ℓB x)}
-- {k : A} {x y : B k}
-- → _≡ω_ {A = Σℓω A B} (k , x) (k , y)
-- → x ≡ y
-- proj₂-id refl = refl
-- unconstrr : ∀ {k i} {x : ⟦ _ ⟧Con A′ (p , tt , i)}
-- {y : ⟦ _ ⟧Con A′ (p , tt , i)}
-- → constr (k , x) ≡ constr (k , y)
-- → x ≡ y
-- unconstrr p = proj₂-id (constr-injective p)
-- unconstr : ∀ {i₁ i₂} (ieq : i₁ ≡ i₂) {k}
-- {x₁ : ⟦ lookupCon D k ⟧Con A′ (p , tt , i₁)}
-- {x₂ : ⟦ lookupCon D k ⟧Con A′ (p , tt , i₂)}
-- → subst (A′ ∘ (p ,_)) ieq (constr (k , x₁)) ≡ constr (k , x₂)
-- → subst (λ i → ⟦ lookupCon D k ⟧Con A′ (p , tt , i)) ieq x₁ ≡ x₂
-- unconstr refl p = proj₂-id (constr-injective p)
-------------------------------
-- Types of injectivity proofs
levelInjective : (C : ConDesc P V I) → Level → Level
levelInjective (var x) c = levelOfTel I ⊔ ℓ ⊔ c
levelInjective (π {ℓ′} ai S C) c = ℓ′ ⊔ levelInjective C c
levelInjective (A ⊗ B) c = levelIndArg A ℓ ⊔ levelInjective B c
mutual
InjectiveCon
: (C : ConDesc P V I) (m : Fin (countArgs C))
(mk₁ : ∀ {i₁} → ⟦ C ⟧Con A′ (p , v₁ , i₁) → A′ (p , i₁))
(mk₂ : ∀ {i₂} → ⟦ C ⟧Con A′ (p , v₂ , i₂) → A′ (p , i₂))
→ Set (levelInjective C (levelProj C m))
InjectiveCon {V} {v₁} {v₂} (π {ℓ′} (n , ai) S C) (suc m) mk₁ mk₂
= {s₁ : < relevance ai > S (_ , v₁)}
{s₂ : < relevance ai > S (_ , v₂)}
→ InjectiveCon C m (λ x → mk₁ (s₁ , x)) (λ x → mk₂ (s₂ , x))
InjectiveCon {V} {v₁} {v₂} (A ⊗ B) (suc m) mk₁ mk₂
= {f₁ : ⟦ A ⟧IndArg A′ (_ , v₁)}
{f₂ : ⟦ A ⟧IndArg A′ (_ , v₂)}
→ InjectiveCon B m (λ x → mk₁ (f₁ , x)) (λ x → mk₂ (f₂ , x))
InjectiveCon (A ⊗ B) zero mk₁ mk₂ = {!!}
InjectiveCon (π ai S C) zero mk₁ mk₂ = {!!}
InjectiveConLift
: ∀ {V V′ : ExTele P} (C : ConDesc P V′ I) {c}
{v₁ v₂ : ⟦ V ⟧tel p}
{v′₁ v′₂ : ⟦ V′ ⟧tel p}
{X : ⟦ P , V ⟧xtel → Set c}
(mk₁ : ∀ {i₁} → ⟦ C ⟧Con A′ (p , v′₁ , i₁) → A′ (p , i₁))
(mk₂ : ∀ {i₂} → ⟦ C ⟧Con A′ (p , v′₂ , i₂) → A′ (p , i₂))
(x₁ : X (p , v₁))
(x₂ : X (p , v₂))
(v≡v : v₁ ≡ v₂)
→ Set (levelInjective C c)
InjectiveConLift (var f) {v′₁ = v′₁} {v′₂} {X} mk₁ mk₂ x₁ x₂ v≡v
= (ieq : f (p , v′₁) ≡ f (p , v′₂))
(ceq : subst (A′ ∘ (p ,_)) ieq (mk₁ refl) ≡ mk₂ refl)
→ subst (X ∘ (p ,_)) v≡v x₁ ≡ x₂
InjectiveConLift (π (n , ai) S C) {X = X} mk₁ mk₂ x₁ x₂ v≡v
= {s₁ : < relevance ai > S (p , _)}
{s₂ : < relevance ai > S (p , _)}
→ InjectiveConLift C {X = X} (λ x → mk₁ (s₁ , x)) (λ x → mk₂ (s₂ , x)) x₁ x₂ v≡v
InjectiveConLift (A ⊗ B) {v′₁ = v′₁} {v′₂} {X} mk₁ mk₂ x₁ x₂ v≡v
= {f₁ : ⟦ A ⟧IndArg A′ (_ , v′₁)}
{f₂ : ⟦ A ⟧IndArg A′ (_ , v′₂)}
→ InjectiveConLift B {X = X} (λ x → mk₁ (f₁ , x)) (λ x → mk₂ (f₂ , x)) x₁ x₂ v≡v
-- first, we gather all arguments for left and right A′ values
-- InjectiveCon C′ m mk (π (n , ai) S C) mk₁ mk₂
-- = {s₁ : < relevance ai > S _}
-- {s₂ : < relevance ai > S _}
-- → InjectiveCon C′ m mk C (λ x → mk₁ (s₁ , x)) λ x → mk₂ (s₂ , x)
-- InjectiveCon C′ m mk (A ⊗ B) mk₁ mk₂
-- = {f₁ : ⟦ A ⟧IndArg A′ _}
-- {f₂ : ⟦ A ⟧IndArg A′ _}
-- → InjectiveCon C′ m mk B (λ x → mk₁ (f₁ , x)) λ x → mk₂ (f₂ , x)
-- -- we now have all arguments to prouce two values of A′
-- -- for the same kth constructor
-- -- it's time to find the type of the proof
-- -- base case: projecting on first arg, no lifting necessary
-- InjectiveCon {V} {v₁} {v₂} (π ai S C) zero mk (var f) mk₁ mk₂
-- = (ieq : f (p , v₁) ≡ f (p , v₂))
-- → subst (A′ ∘ (p ,_)) ieq (mk (mk₁ refl)) ≡ mk (mk₂ refl)
-- → proj₁ (mk₁ refl) ≡ proj₁ (mk₂ refl)
-- InjectiveCon {V} {v₁} {v₂} (A ⊗ B) zero mk (var f) mk₁ mk₂
-- = (ieq : f (p , v₁) ≡ f (p , v₂))
-- → subst (A′ ∘ (p ,_)) ieq (mk (mk₁ refl)) ≡ mk (mk₂ refl)
-- → proj₁ (mk₁ refl) ≡ proj₁ (mk₂ refl)
-- otherwise, we have to lift a few things
-- InjectiveCon {V} {v₁} {v₂} (π ai S C) (suc m) mk (var f) mk₁ mk₂
-- = (ieq : f (p , v₁) ≡ f (p , v₂))
-- → subst (A′ ∘ (p ,_)) ieq (mk (mk₁ refl)) ≡ mk (mk₂ refl)
-- → InjectiveConLift C m {!!} {!!} {!!} {!!}
-- InjectiveCon {V} {v₁} {v₂} (A ⊗ B) (suc m) mk (var f) mk₁ mk₂
-- = (ieq : f (p , v₁) ≡ f (p , v₂))
-- → subst (A′ ∘ (p ,_)) ieq (mk (mk₁ refl)) ≡ mk (mk₂ refl)
-- → {!!}
-- Injective : ∀ k (let C = lookupCon D k) (m : Fin (countArgs C))
-- → Set (levelInjective C (levelProj C m))
-- Injective k m = InjectiveCon _ m (λ x → constr (k , x)) _ id id
{-
deriveInjective : ∀ k m → Injective k m
deriveInjective k m = injCon (lookupCon D k) m (lookupCon D k)
where
injCon
: (C′ : ConDesc P ε I) (m : Fin (countArgs C′))
{mk : ∀ {i} → ⟦ C′ ⟧Con A′ (p , tt , i) → A′ (p , i)}
(C : ConDesc P V I)
{mk₁ : ∀ {i₁} → ⟦ C ⟧Con A′ (p , v₁ , i₁) → ⟦ C′ ⟧Con A′ (p , tt , i₁)}
{mk₂ : ∀ {i₂} → ⟦ C ⟧Con A′ (p , v₂ , i₂) → ⟦ C′ ⟧Con A′ (p , tt , i₂)}
→ InjectiveCon C′ m mk C mk₁ mk₂
-- we proceed until the end of the constructor
injCon C′ m (π ai S C) = injCon C′ m C
injCon C′ m (A ⊗ B) = injCon C′ m B
-- at the end, base case when projecting on fist arg
injCon (π ai S C) zero (var x) ieq xeq = {!!}
injCon (A ⊗ B) zero (var x) ieq xeq = {!!}
-- else, LIFT
injCon (π ai S C′) (suc m) (var x) = {!!}
injCon (C′ ⊗ C′₁) (suc m) (var x) = {!!}
{-
deriveInjective′ : ∀ k m
(ieq : i₁ ≡ i₂)
{x₁ : ⟦ _ ⟧Con A′ (p , tt , i₁)}
{x₂ : ⟦ _ ⟧Con A′ (p , tt , i₂)}
→ subst (λ i → ⟦ _ ⟧Con A′ (p , tt , i)) ieq x₁ ≡ x₂
→ {!!}
deriveInjective′ = {!!}
-}
-}
| {
"alphanum_fraction": 0.4604663999,
"avg_line_length": 35.6995073892,
"ext": "agda",
"hexsha": "2b2df96123ac5e23ee297578042aeb50dd2ebd34",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Constructions/Injective.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Constructions/Injective.agda",
"max_line_length": 86,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Constructions/Injective.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 3076,
"size": 7247
} |
{-# OPTIONS --cubical --safe #-}
module Data.Nat.Properties where
open import Data.Nat.Base
open import Agda.Builtin.Nat using () renaming (_<_ to _<ᴮ_; _==_ to _≡ᴮ_) public
open import Prelude
open import Cubical.Data.Nat using (caseNat; znots; snotz; injSuc) public
pred : ℕ → ℕ
pred (suc n) = n
pred zero = zero
correct-== : ∀ n m → Reflects (n ≡ m) (n ≡ᴮ m)
correct-== zero zero = ofʸ refl
correct-== zero (suc m) = ofⁿ znots
correct-== (suc n) zero = ofⁿ snotz
correct-== (suc n) (suc m) =
map-reflects (cong suc) (λ contra prf → contra (cong pred prf)) (correct-== n m)
discreteℕ : Discrete ℕ
discreteℕ n m .does = n ≡ᴮ m
discreteℕ n m .why = correct-== n m
isSetℕ : isSet ℕ
isSetℕ = Discrete→isSet discreteℕ
+-suc : ∀ x y → x + suc y ≡ suc (x + y)
+-suc zero y = refl
+-suc (suc x) y = cong suc (+-suc x y)
+-idʳ : ∀ x → x + 0 ≡ x
+-idʳ zero = refl
+-idʳ (suc x) = cong suc (+-idʳ x)
+-comm : ∀ x y → x + y ≡ y + x
+-comm x zero = +-idʳ x
+-comm x (suc y) = +-suc x y ; cong suc (+-comm x y)
infix 4 _<_
_<_ : ℕ → ℕ → Type₀
n < m = T (n <ᴮ m)
_≤ᴮ_ : ℕ → ℕ → Bool
zero ≤ᴮ m = true
suc n ≤ᴮ m = n <ᴮ m
+-assoc : ∀ x y z → (x + y) + z ≡ x + (y + z)
+-assoc zero y z = refl
+-assoc (suc x) y z = cong suc (+-assoc x y z)
| {
"alphanum_fraction": 0.5802568218,
"avg_line_length": 24.431372549,
"ext": "agda",
"hexsha": "7f61556094a708876f70063ca78569b19c6ee2a0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Nat/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Nat/Properties.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Nat/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 551,
"size": 1246
} |
{- 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 LibraBFT.Prelude
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
import LibraBFT.Yasm.Base as LYB
import LibraBFT.Yasm.System as LYS
-- This module provides a single import for all Yasm modules
module LibraBFT.Yasm.Yasm
(ℓ-PeerState : Level)
(ℓ-VSFP : Level)
(parms : LYB.SystemParameters ℓ-PeerState)
(ValidSenderForPK : LYS.ValidSenderForPK-type ℓ-PeerState ℓ-VSFP parms)
(ValidSenderForPK-stable : LYS.ValidSenderForPK-stable-type ℓ-PeerState ℓ-VSFP parms ValidSenderForPK)
where
open LYB.SystemParameters parms
open import LibraBFT.Yasm.Base public
open import LibraBFT.Yasm.System ℓ-PeerState ℓ-VSFP parms public
open import LibraBFT.Yasm.Properties ℓ-PeerState ℓ-VSFP parms ValidSenderForPK ValidSenderForPK-stable public
open import Util.FunctionOverride PeerId _≟PeerId_ public
| {
"alphanum_fraction": 0.6700468019,
"avg_line_length": 49.3076923077,
"ext": "agda",
"hexsha": "dc5fe645668fab5976352aab372cdf553e27d977",
"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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Yasm/Yasm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"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": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Yasm/Yasm.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Yasm/Yasm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 333,
"size": 1282
} |
-- {-# OPTIONS -v tc.constr.findInScope:50 #-}
module 06-listEquality where
infixr 5 _∷_
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A) (xs : List A) → List A
data Bool : Set where
true : Bool
false : Bool
id : {A : Set} → A → A
id v = v
or : Bool → Bool → Bool
or true _ = true
or _ true = true
or false false = false
and : Bool → Bool → Bool
and false _ = false
and _ false = false
and true true = false
not : Bool → Bool
not true = false
not false = true
record Eq (A : Set) : Set where
field eq : A → A → Bool
listEq : {A : Set} → Eq A → Eq (List A)
listEq {A} eqA = record { eq = eq' } where
eq' : List A → List A → Bool
eq' [] [] = true
eq' (a ∷ as) (b ∷ bs) = and (Eq.eq eqA a b) (eq' as bs)
eq' _ _ = false
primEqBool : Bool → Bool → Bool
primEqBool true = id
primEqBool false = not
eqBool : Eq Bool
eqBool = record { eq = primEqBool }
open Eq {{...}}
test = eq (true ∷ false ∷ true ∷ []) (true ∷ false ∷ [])
where listBoolEq = listEq eqBool
| {
"alphanum_fraction": 0.5869346734,
"avg_line_length": 19.1346153846,
"ext": "agda",
"hexsha": "15133c8c8bc723cddcc02192889170309b28540e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/instance-arguments/06-listEquality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/instance-arguments/06-listEquality.agda",
"max_line_length": 57,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/instance-arguments/06-listEquality.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": 364,
"size": 995
} |
-- Proof: insertion sort computes a permutation of the input list
module sortnat where
open import bool
open import eq
open import nat
open import list
open import nondet
open import nondet-thms
-- non-deterministic insert.
--This takes a nondeterministic list because I need to be able to call it with the result of perm
--
--implementation in curry:
-- ndinsert x [] = []
-- ndinsert x (y:ys) = (x : y : xs) ? (y : insert x ys)
ndinsert : {A : Set} → A → 𝕃 A → ND (𝕃 A)
ndinsert x [] = Val ( x :: [])
ndinsert x (y :: ys) = (Val ( x :: y :: ys ))
?? ((_::_ y) $* (ndinsert x ys))
--non-deterministic permutation
--this is identical to the curry code (except for the Val constructor)
perm : {A : Set} → (𝕃 A) → ND (𝕃 A)
perm [] = Val []
perm (x :: xs) = (ndinsert x) *$* (perm xs)
--insert a value into a sorted list.
--this is identical to curry or haskell code.
--
--note that the structure here is identical to ndinsert
insert : ℕ → 𝕃 ℕ → 𝕃 ℕ
insert x [] = x :: []
insert x (y :: ys) = if x < y then (x :: y :: ys)
else (y :: insert x ys)
--simple insertion sort
--again this is identical to curry or haskell
--also, note that the structure is identical to perm
sort : 𝕃 ℕ → 𝕃 ℕ
sort [] = []
sort (x :: xs) = insert x (sort xs)
--If introduction rule for non-deterministic values.
--if x and y are both possible values in z then
--∀ c. if c then x else y will give us either x or y, so it must be a possible value of z.
--
ifIntro : {A : Set} → (x : A) → (y : A) → (nx : ND A)
→ x ∈ nx → y ∈ nx → (c : 𝔹) → (if c then x else y) ∈ nx
ifIntro x y nx p q tt = p
ifIntro x y nx p q ff = q
---------------------------------------------------------------------------
--
-- this should prove that if xs ∈ nxs then, insert x xs ∈ ndinsert x nxs
-- parameters:
-- x : the value we are inserting into the list
-- xs : the list
--
--returns: insert x xs ∈ ndinsert x xs
-- a proof that inserting a value in a list is ok with non-deterministic lists
insert=ndinsert : (y : ℕ) → (xs : 𝕃 ℕ) → (insert y xs) ∈ (ndinsert y xs)
-- the first case is simple: inserting into an empty list is trivial
insert=ndinsert y [] = ndrefl
--The recursive case is the interesting one.
--The list to insert an element has the form (x :: xs)
--At this point we have two possible cases.
--Either y is smaller then every element in (x :: xs), in which case it's inserted at the front,
--or y is larger than x, in which case it's inserted somewhere in xs.
--Since both of these cases are covered by ndinsert we can invoke the ifIntro lemma, to say that we don't care which case it is.
--
--variables:
-- step : one step of insert
-- l : the left hand side of insert y xs (the then branch)
-- r : the right hand side of insert y xs (the else branch)
-- nr : a non-deterministic r
-- (Val l) : a non-deterministic l (but since ndinsert only has a deterministic value on the left it's not very interesting)
-- rec : The recursive call. If y isn't inserted into the front, then we need to find it.
-- l∈step : a proof that l is a possible value for step
-- r∈step : a proof that r is a possible value for step
insert=ndinsert y (x :: xs) = ifIntro l r step l∈step r∈step (y < x)
where step = ndinsert y (x :: xs)
l = (y :: x :: xs)
r = x :: insert y xs
nl = Val l
nr = (_::_ x) $* (ndinsert y xs)
rec = ∈-$* (_::_ x) (insert y xs) (ndinsert y xs)
(insert=ndinsert y xs)
l∈step = left nl nr ndrefl
r∈step = right nl nr rec
---------------------------------------------------------------------------
-- Main theorem: Sorting a list preserves permutations
-- all of the work is really done by insert=ndinsert
sortPerm : (xs : 𝕃 ℕ) → sort xs ∈ perm xs
sortPerm [] = ndrefl
sortPerm (x :: xs) = ∈-*$* (sort xs) (perm xs) (insert x) (ndinsert x)
(sortPerm xs) (insert=ndinsert x (sort xs))
| {
"alphanum_fraction": 0.590310559,
"avg_line_length": 37.9716981132,
"ext": "agda",
"hexsha": "62b03996e17f229450ca10342193ff51213ffd1d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "mihanus/curry-agda",
"max_forks_repo_path": "nondet/sortnat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "mihanus/curry-agda",
"max_issues_repo_path": "nondet/sortnat.agda",
"max_line_length": 128,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "mihanus/curry-agda",
"max_stars_repo_path": "nondet/sortnat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1159,
"size": 4025
} |
open import Common.Prelude hiding (tt)
open import Common.Reflection
open import Common.Equality
tt : ⊤
tt = record{}
NoConf : Nat → Nat → Set
NoConf zero zero = ⊤
NoConf zero (suc n) = ⊥
NoConf (suc m) zero = ⊥
NoConf (suc m) (suc n) = m ≡ n
pattern `Nat = def (quote Nat) []
infixr 0 Π
syntax Π x a b = [ x ∈ a ]→ b
Π : String → Type → Type → Type
Π x a b = pi (vArg a) (abs x b)
-- noConf : (m n : ℕ) → m ≡ n → NoConfusion-ℕ m n
-- noConf zero .zero refl = tt
-- noConf (suc m) .(suc m) refl = refl
noConf : FunDef
noConf = funDef
([ "A" ∈ `Nat ]→ [ "B" ∈ `Nat ]→
[ "C" ∈ def (quote _≡_) (vArg (var 1 []) ∷ vArg (var 0 []) ∷ []) ]→
def (quote NoConf) (vArg (var 2 []) ∷ vArg (var 1 []) ∷ []))
( clause (vArg (con (quote zero) []) ∷ vArg dot ∷ vArg (con (quote refl) []) ∷ [])
(def (quote tt) [])
∷ clause (vArg (con (quote suc) (vArg (var "m") ∷ [])) ∷ vArg dot ∷ vArg (con (quote refl) []) ∷ [])
(def (quote refl) [])
∷ [])
unquoteDecl test = define (vArg test) noConf
| {
"alphanum_fraction": 0.5417895772,
"avg_line_length": 26.7631578947,
"ext": "agda",
"hexsha": "3527ed5c4b7ff032d5a92936ca2b8f59060c4f24",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1228b.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Fail/Issue1228b.agda",
"max_line_length": 102,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/Issue1228b.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": 409,
"size": 1017
} |
module z where
------------------------------------------------------------------------------
-- inductive data types and function that are defined by pattern matching
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
data List {ℓ} (A : Set ℓ) : Set ℓ where
[] : List A
_::_ : (x : A) (xs : List A) → List A
_#_ : {A : Set} → List A → List A → List A
[] # ys = ys
(x :: xs) # ys = x :: (xs # ys)
sum : List ℕ → List ℕ → List ℕ
sum [] ys = ys
sum (x :: xs) [] = x :: xs
sum (x :: xs) (y :: ys) = (x + y) :: sum xs ys
-- inductively defined predicates
-- P over S is a data type S -> Set
data _reverseOf_ {A : Set} : List A → List A → Set where
rev-Λ : [] reverseOf []
rev-t : {x : A} {xs ys : List A}
→ xs reverseOf ys
→ (x :: xs) reverseOf (ys # (x :: []))
data _⊆_ {A : Set} : List A → List A → Set where
sub-Λ : [] ⊆ []
sub-right : {n : A} {ys xs : List A}
→ ys ⊆ xs → ys ⊆ (n :: xs)
sub-ind : {n : A} {ys xs : List A}
→ ys ⊆ xs → (n :: ys) ⊆ (n :: xs)
------------------------------------------------------------------------------
-- coinductive records and copattern matching
-- inductive pair
record Pair (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
-- coinductive infinite list (e.g., "stream")
record Stream (A : Set) : Set where
coinductive
field
hd : A
tl : Stream A
open Stream
-- functions cannot be defined inductively (by pattern matching).
-- use copattern matching [APTS13]
-- - specify how the result of the function will be observed
zeros : Stream ℕ
hd zeros = zero
tl zeros = zeros
natsFrom : ℕ → Stream ℕ
hd (natsFrom n) = n
tl (natsFrom n) = natsFrom (suc n)
sumS : Stream ℕ → Stream ℕ → Stream ℕ
hd (sumS a b) = hd a + hd b
tl (sumS a b) = sumS (tl a) (tl b)
------------------------------------------------------------------------------
-- possibly infinite streams
--open import Codata.Thunk
open import Size
open import Relation.Unary
{-
A thunk is a coinductive record with only one field, the suspended computation.
Takes a function from Size to Set (e.g., Colist A).
Accessing forces the computation and implicitly decreases the size.
'Size < i' represents all the sizes smaller than i.
-}
record Thunk {ℓ} (F : Size → Set ℓ) (i : Size) : Set ℓ where
coinductive
field force : {j : Size< i} → F j
open Thunk public
-- 'Size' represents an approximation level.
-- - Can be ∞.
-- - Can help termination checker by tracking depth of data structures.
-- 'Thunk' simulates laziness
data Colist {a} (A : Set a) (i : Size) : Set a where
[] : Colist A i
_::_ : A → Thunk (Colist A) i → Colist A i
{-
Alternative Colist impl: follows pattern used for coinductive types.
To represent a structure which can be either finite or infinite, use a coinductive record
with a field representing the whole observation which can be made on the structure.
This field is typically a variant type, since the observation can take different shapes,
e.g., if colist is non-empty then observe the pair consisting of head and tail, otherwise nothing.
-}
open import Data.Maybe
open import Data.Product
record MyColist (A : Set) : Set where
constructor CoL_
coinductive
field
list : Maybe (A × MyColist A)
-- Either of these two approaches can be used for possibly infinite structures.
data StreamT {ℓ} (A : Set ℓ) (i : Size) : Set ℓ where
_::_ : A → Thunk (StreamT A) i → StreamT A i
record MyStream_bis (A : Set) : Set where
coinductive
field
stream : A × (MyStream_bis A)
------------------------------------------------------------------------------
-- equality properties
-- stdlib equality and properties
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
instance refl : x ≡ x
-- Each property is a function that takes proofs as input and returns a new proof.
sym : ∀ {A : Set} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
trans : ∀ {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
cong : ∀ {A B : Set} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y
cong f refl = refl
subst : ∀ {A : Set} {x y : A} (P : A → Set) → x ≡ y → P x → P y
subst P refl px = px
------------------------------------------------------------------------------
-- Chapter 2 - Inductive reasoning
data _memberOf_ {A : Set} : A → List A → Set where
mem-h : {x : A} → {xs : List A} → x memberOf (x :: xs)
mem-t : {x y : A} → {xs : List A} → x memberOf xs → x memberOf(y :: xs)
| {
"alphanum_fraction": 0.5442983402,
"avg_line_length": 29.5477707006,
"ext": "agda",
"hexsha": "02856f45b85997380ba005bb928eda87a62a27a6",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/paper/2020-02-luca-ciccone-flexible-coinduction-in-agda/z.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/paper/2020-02-luca-ciccone-flexible-coinduction-in-agda/z.agda",
"max_line_length": 98,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/paper/2020-02-luca-ciccone-flexible-coinduction-in-agda/z.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 1395,
"size": 4639
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Converting reflection machinery to strings
------------------------------------------------------------------------
-- Note that Reflection.termErr can also be used directly in tactic
-- error messages.
{-# OPTIONS --without-K --safe #-}
module Reflection.Show where
import Data.Char as Char
import Data.Float as Float
open import Data.List hiding (_++_; intersperse)
import Data.Nat as ℕ
import Data.Nat.Show as ℕ
open import Data.String as String
import Data.Word as Word
open import Relation.Nullary using (yes; no)
open import Function.Base using (_∘′_)
open import Reflection.Abstraction hiding (map)
open import Reflection.Argument hiding (map)
open import Reflection.Argument.Relevance
open import Reflection.Argument.Visibility
open import Reflection.Argument.Information
open import Reflection.Definition
open import Reflection.Literal
open import Reflection.Pattern
open import Reflection.Term
------------------------------------------------------------------------
-- Re-export primitive show functions
open import Agda.Builtin.Reflection public
using () renaming
( primShowMeta to showMeta
; primShowQName to showName
)
------------------------------------------------------------------------
-- Non-primitive show functions
showRelevance : Relevance → String
showRelevance relevant = "relevant"
showRelevance irrelevant = "irrelevant"
showRel : Relevance → String
showRel relevant = ""
showRel irrelevant = "."
showVisibility : Visibility → String
showVisibility visible = "visible"
showVisibility hidden = "hidden"
showVisibility instance′ = "instance"
showLiteral : Literal → String
showLiteral (nat x) = ℕ.show x
showLiteral (word64 x) = ℕ.show (Word.toℕ x)
showLiteral (float x) = Float.show x
showLiteral (char x) = Char.show x
showLiteral (string x) = String.show x
showLiteral (name x) = showName x
showLiteral (meta x) = showMeta x
mutual
showPatterns : List (Arg Pattern) → String
showPatterns [] = ""
showPatterns (a ∷ ps) = showArg a <+> showPatterns ps
where
showArg : Arg Pattern → String
showArg (arg (arg-info visible r) p) = showRel r ++ showPattern p
showArg (arg (arg-info hidden r) p) = braces (showRel r ++ showPattern p)
showArg (arg (arg-info instance′ r) p) = braces (braces (showRel r ++ showPattern p))
showPattern : Pattern → String
showPattern (con c []) = showName c
showPattern (con c ps) = parens (showName c <+> showPatterns ps)
showPattern dot = "._"
showPattern (var s) = s
showPattern (lit l) = showLiteral l
showPattern (proj f) = showName f
showPattern absurd = "()"
private
-- add appropriate parens depending on the given visibility
visibilityParen : Visibility → String → String
visibilityParen visible s = parensIfSpace s
visibilityParen hidden s = braces s
visibilityParen instance′ s = braces (braces s)
mutual
showTerms : List (Arg Term) → String
showTerms [] = ""
showTerms (arg i t ∷ ts) = visibilityParen (visibility i) (showTerm t) <+> showTerms ts
showTerm : Term → String
showTerm (var x args) = "var" <+> ℕ.show x <+> showTerms args
showTerm (con c args) = showName c <+> showTerms args
showTerm (def f args) = showName f <+> showTerms args
showTerm (lam v (abs s x)) = "λ" <+> visibilityParen v s <+> "→" <+> showTerm x
showTerm (pat-lam cs args) =
"λ {" <+> showClauses cs <+> "}" <+> showTerms args
showTerm (Π[ x ∶ arg i a ] b) =
"Π (" ++ visibilityParen (visibility i) x <+> ":" <+>
parensIfSpace (showTerm a) ++ ")" <+> parensIfSpace (showTerm b)
showTerm (sort s) = showSort s
showTerm (lit l) = showLiteral l
showTerm (meta x args) = showMeta x <+> showTerms args
showTerm unknown = "unknown"
showSort : Sort → String
showSort (set t) = "Set" <+> parensIfSpace (showTerm t)
showSort (lit n) = "Set" ++ ℕ.show n -- no space to disambiguate from set t
showSort unknown = "unknown"
showClause : Clause → String
showClause (clause ps t) = showPatterns ps <+> "→" <+> showTerm t
showClause (absurd-clause ps) = showPatterns ps
showClauses : List Clause → String
showClauses [] = ""
showClauses (c ∷ cs) = showClause c <+> ";" <+> showClauses cs
showDefinition : Definition → String
showDefinition (function cs) = "function" <+> braces (showClauses cs)
showDefinition (data-type pars cs) =
"datatype" <+> ℕ.show pars <+> braces (intersperse ", " (map showName cs))
showDefinition (record′ c fs) =
"record" <+> showName c <+> braces (intersperse ", " (map (showName ∘′ unArg) fs))
showDefinition (constructor′ d) = "constructor" <+> showName d
showDefinition axiom = "axiom"
showDefinition primitive′ = "primitive"
| {
"alphanum_fraction": 0.6357911842,
"avg_line_length": 35.6739130435,
"ext": "agda",
"hexsha": "b5103cb01f3b76bfcc719bbaa7d339a35dfe24a0",
"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/Reflection/Show.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/Reflection/Show.agda",
"max_line_length": 89,
"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/Reflection/Show.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": 1278,
"size": 4923
} |
{-# OPTIONS --copatterns #-}
module CoinductiveUnitRecord where
import Common.Level
open import Common.Equality
record Unit : Set where
coinductive
constructor delay
field force : Unit
open Unit
good : Unit
force good = good
bad : Unit
bad = delay bad
-- should not termination check ...
bad' : Unit
bad' = delay bad'
-- ... because this loops:
-- loop : bad ≡ bad'
-- loop = refl
| {
"alphanum_fraction": 0.692893401,
"avg_line_length": 14.5925925926,
"ext": "agda",
"hexsha": "e41295fd50381f83224f3ef7502fff109f4d4482",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/CoinductiveUnitRecord.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/CoinductiveUnitRecord.agda",
"max_line_length": 35,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/CoinductiveUnitRecord.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": 103,
"size": 394
} |
{-# OPTIONS --cubical --safe #-}
module Data.Nat.Fold where
open import Prelude
open import Data.Nat
foldr-ℕ : (A → A) → A → ℕ → A
foldr-ℕ f b zero = b
foldr-ℕ f b (suc n) = f (foldr-ℕ f b n)
foldr-ℕ-universal : ∀ (h : ℕ → A) f x →
(h zero ≡ x) →
(∀ n → h (suc n) ≡ f (h n)) →
∀ n → h n ≡ foldr-ℕ f x n
foldr-ℕ-universal h f x base step zero = base
foldr-ℕ-universal h f x base step (suc n) = step n ; cong f (foldr-ℕ-universal h f x base step n)
foldl-ℕ-go : (A → A) → ℕ → A → A
foldl-ℕ-go f zero x = x
foldl-ℕ-go f (suc n) x = foldl-ℕ-go f n $! f x
foldl-ℕ : (A → A) → A → ℕ → A
foldl-ℕ f x n = foldl-ℕ-go f n $! x
{-# INLINE foldl-ℕ #-}
f-comm : ∀ (f : A → A) x n → f (foldr-ℕ f x n) ≡ foldr-ℕ f (f x) n
f-comm f x zero i = f x
f-comm f x (suc n) i = f (f-comm f x n i)
foldl-ℕ-foldr : ∀ f (x : A) n → foldr-ℕ f x n ≡ foldl-ℕ f x n
foldl-ℕ-foldr f x zero = sym ($!-≡ (foldl-ℕ-go f zero) x)
foldl-ℕ-foldr f x (suc n) = f-comm f x n ; foldl-ℕ-foldr f (f x) n ; sym ($!-≡ (foldl-ℕ-go f (suc n)) x)
foldl-ℕ-universal : ∀ (h : ℕ → A) f x →
(h zero ≡ x) →
(∀ n → h (suc n) ≡ f (h n)) →
∀ n → h n ≡ foldl-ℕ f x n
foldl-ℕ-universal h f x base step n = foldr-ℕ-universal h f x base step n ; foldl-ℕ-foldr f x n
| {
"alphanum_fraction": 0.5011219147,
"avg_line_length": 33.425,
"ext": "agda",
"hexsha": "edde67850a43deb1c4add526c1da26cc96d6055c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Nat/Fold.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Nat/Fold.agda",
"max_line_length": 104,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Nat/Fold.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": 613,
"size": 1337
} |
{-# OPTIONS --prop --without-K --rewriting #-}
module Calf.Prelude where
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite public
Ω = Prop
□ = Set
postulate
funext : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (a : A) → B a} → (∀ x → f x ≡ g x) → f ≡ g
funext/Ω : {A : Prop} {B : □} {f g : A → B} → (∀ x → f x ≡ g x) → f ≡ g
| {
"alphanum_fraction": 0.5418994413,
"avg_line_length": 25.5714285714,
"ext": "agda",
"hexsha": "4da4acc0d914449b06258226971051f3f4959e9a",
"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/Calf/Prelude.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/Calf/Prelude.agda",
"max_line_length": 96,
"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/Calf/Prelude.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": 151,
"size": 358
} |
{-# OPTIONS --cubical --safe #-}
module Data.Binary.FromZeroed where
open import Data.Binary.Definition
open import Prelude
inc-z : 𝔹 → 𝔹
inc-z 0ᵇ = 2ᵇ 0ᵇ
inc-z (1ᵇ xs) = 2ᵇ xs
inc-z (2ᵇ xs) = 1ᵇ inc-z xs
toZ : 𝔹 → 𝔹
toZ 0ᵇ = 0ᵇ
toZ (1ᵇ xs) = 2ᵇ toZ xs
toZ (2ᵇ xs) = 1ᵇ inc-z (toZ xs)
ones : ℕ → 𝔹 → 𝔹
ones zero xs = xs
ones (suc n) xs = 1ᵇ ones n xs
fromZ₁ : ℕ → 𝔹 → 𝔹
fromZ₁ n 0ᵇ = 0ᵇ
fromZ₁ n (1ᵇ xs) = fromZ₁ (suc n) xs
fromZ₁ n (2ᵇ xs) = 2ᵇ ones n (fromZ₁ 0 xs)
fromZ : 𝔹 → 𝔹
fromZ 0ᵇ = 0ᵇ
fromZ (1ᵇ xs) = fromZ₁ zero xs
fromZ (2ᵇ xs) = 1ᵇ fromZ xs
import Data.Binary.Conversion.Fast as Fast
open import Data.List using (List; _⋯_; map)
round-trip : ℕ → Type
round-trip n = map (fromZ ∘ toZ) nums ≡ nums
where
nums : List 𝔹
nums = map Fast.⟦_⇑⟧ (0 ⋯ n)
_ : round-trip 300
_ = refl
| {
"alphanum_fraction": 0.6214549938,
"avg_line_length": 18.4318181818,
"ext": "agda",
"hexsha": "6ba10405d9107074755c49ff409dc5f5c10328dd",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Binary/FromZeroed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Binary/FromZeroed.agda",
"max_line_length": 44,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Binary/FromZeroed.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": 432,
"size": 811
} |
open import bool
open import bool-thms2
open import eq
open import product
open import product-thms
open import bool-relations
module minmax {A : Set} (_≤A_ : A → A → 𝔹)
(≤A-trans : transitive _≤A_)
(≤A-total : total _≤A_) where
≤A-refl : reflexive _≤A_
≤A-refl = total-reflexive _≤A_ ≤A-total
min : A → A → A
min = λ x y → if x ≤A y then x else y
max : A → A → A
max = λ x y → if x ≤A y then y else x
min-≤1 : ∀{x y : A} → min x y ≤A x ≡ tt
min-≤1{x}{y} with keep (x ≤A y)
min-≤1{x}{y} | tt , p rewrite p = ≤A-refl
min-≤1{x}{y} | ff , p rewrite p = ≤A-total p
min-≤2 : ∀{x y : A} → min x y ≤A y ≡ tt
min-≤2{x}{y} with keep (x ≤A y)
min-≤2{x}{y} | tt , p rewrite p = p
min-≤2{x}{y} | ff , p rewrite p = ≤A-refl
max-≤1 : ∀{x y : A} → x ≤A max x y ≡ tt
max-≤1{x}{y} with keep (x ≤A y)
max-≤1{x}{y} | tt , p rewrite p = p
max-≤1{x}{y} | ff , p rewrite p = ≤A-refl
max-≤2 : ∀{x y : A} → y ≤A max x y ≡ tt
max-≤2{x}{y} with keep (x ≤A y)
max-≤2{x}{y} | tt , p rewrite p = ≤A-refl
max-≤2{x}{y} | ff , p rewrite p = ≤A-total p
min1-mono : ∀{x x' y : A} → x ≤A x' ≡ tt → min x y ≤A min x' y ≡ tt
min1-mono{x}{x'}{y} p with keep (x ≤A y) | keep (x' ≤A y)
min1-mono p | tt , q | tt , q' rewrite q | q' = p
min1-mono p | tt , q | ff , q' rewrite q | q' = q
min1-mono p | ff , q | tt , q' rewrite q | q' | ≤A-trans p q' with q
min1-mono p | ff , q | tt , q' | ()
min1-mono p | ff , q | ff , q' rewrite q | q' = ≤A-refl
min2-mono : ∀{x y y' : A} → y ≤A y' ≡ tt → min x y ≤A min x y' ≡ tt
min2-mono{x}{y}{y'} p with keep (x ≤A y) | keep (x ≤A y')
min2-mono p | tt , q | tt , q' rewrite q | q' = ≤A-refl
min2-mono p | tt , q | ff , q' rewrite q | q' | ≤A-trans q p with q'
min2-mono p | tt , q | ff , q' | ()
min2-mono p | ff , q | tt , q' rewrite q | q' = ≤A-total q
min2-mono p | ff , q | ff , q' rewrite q | q' = p
max2-mono : ∀{x y y' : A} → y ≤A y' ≡ tt → max x y ≤A max x y' ≡ tt
max2-mono{x}{y}{y'} p with keep (x ≤A y) | keep (x ≤A y')
max2-mono p | tt , q | tt , q' rewrite q | q' = p
max2-mono p | tt , q | ff , q' rewrite q | q' = ≤A-trans p (≤A-total q')
max2-mono p | ff , q | tt , q' rewrite q | q' = q'
max2-mono p | ff , q | ff , q' rewrite q | q' = ≤A-refl
| {
"alphanum_fraction": 0.5147526101,
"avg_line_length": 34.9682539683,
"ext": "agda",
"hexsha": "2cd095a321239a6dffcac595a2e0b23aff53f341",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "minmax.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "minmax.agda",
"max_line_length": 72,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "minmax.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 1014,
"size": 2203
} |
module 020-equivalence where
-- We need False to represent logical contradiction.
open import 010-false-true
-- Next, we need to be able to work with equalities. Equalities are
-- defined between objects of the same type. Two objects are equal if
-- we have a proof of their equality. In Agda, we can represent this
-- by means of a function which takes two instances of some type M,
-- and maps this to a proof of equality.
-- To be a reasonable model for equality, we demand that this function
-- has the properties of an equivalence relation: (i) we must have a
-- proof that every object r in M equals itself, (ii) given a proof
-- that r == s, we must be able to prove that s == r, and (iii) given
-- proofs of r == s and s == t, we must be able to prove that r == t.
-- A convenient way to store all these properties, goes by means of a
-- record, which is in essence a local parametrised module, where the
-- parameters and fields correspond to postulates (theorems that can
-- be stated without proof), and declarations are theorems derived
-- from parameters and fields. A good question is, what should be a
-- parameter, and what should be a field? Fields can be considered as
-- named parameters, so probably anything that would otherwise not be
-- obvious without name should go into a field.
-- Here we declare the type and equality function (which maps pairs of
-- elements to proofs) as parameters, and the equivalence axioms as
-- fields. The parameter M is optional because it can be derived
-- unambiguously from the type signature of the equality function.
record Equivalence
{M : Set}
(_==_ : M -> M -> Set)
: Set1 where
{- axioms -}
field
refl : ∀ {r} -> (r == r)
symm : ∀ {r s} -> (r == s) -> (s == r)
trans : ∀ {r s t} -> (r == s) -> (s == t) -> (r == t)
-- We have a proof of inequality if we can prove contradiction from
-- equality, and this is precisely how we define the inequality
-- relation.
_!=_ : M -> M -> Set
m != n = (m == n) -> False
-- Prove transitivity chains.
-- (TODO: Use a type dependent function for these chains.)
trans3 : ∀ {r s t u}
-> (r == s) -> (s == t) -> (t == u) -> (r == u)
trans3 p1 p2 p3 = trans (trans p1 p2) p3
trans4 : ∀ {r s t u v}
-> (r == s) -> (s == t) -> (t == u) -> (u == v) -> (r == v)
trans4 p1 p2 p3 p4 = trans (trans3 p1 p2 p3) p4
trans5 : ∀ {r s t u v w}
-> (r == s) -> (s == t) -> (t == u) -> (u == v) -> (v == w)
-> (r == w)
trans5 p1 p2 p3 p4 p5 = trans (trans4 p1 p2 p3 p4) p5
trans6 : ∀ {r s t u v w x}
-> (r == s) -> (s == t) -> (t == u) -> (u == v) -> (v == w)
-> (w == x) -> (r == x)
trans6 p1 p2 p3 p4 p5 p6 = trans (trans5 p1 p2 p3 p4 p5) p6
-- Now we construct a trivial model of equivalence: two instances of a
-- type are equivalent if they reduce to the same normal form. (Note
-- that Agda reduces expressions to normal form for us.)
data _≡_ {A : Set} : A -> A -> Set where
refl : ∀ {r} -> r ≡ r
thm-≡-is-equivalence : {A : Set} -> Equivalence {A} _≡_
thm-≡-is-equivalence = record {
refl = refl;
symm = symm;
trans = trans
}
where
symm : ∀ {r s} -> r ≡ s -> s ≡ r
symm refl = refl
trans : ∀ {r s t} -> r ≡ s -> s ≡ t -> r ≡ t
trans refl refl = refl
| {
"alphanum_fraction": 0.6078252957,
"avg_line_length": 38.3372093023,
"ext": "agda",
"hexsha": "599546155a068df99375d53ad7ae899c6d4f697f",
"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": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mcmtroffaes/agda-proofs",
"max_forks_repo_path": "020-equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"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": "mcmtroffaes/agda-proofs",
"max_issues_repo_path": "020-equivalence.agda",
"max_line_length": 70,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mcmtroffaes/agda-proofs",
"max_stars_repo_path": "020-equivalence.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-17T16:15:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-09T22:51:55.000Z",
"num_tokens": 1038,
"size": 3297
} |
import Issue2447.M
Rejected : Set
Rejected = Set
| {
"alphanum_fraction": 0.76,
"avg_line_length": 10,
"ext": "agda",
"hexsha": "0e16450e67f2e95dd13bb1a98f0f43dc5016ddd3",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue2447.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue2447.agda",
"max_line_length": 18,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue2447.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": 14,
"size": 50
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some Vec-related properties that depend on the K rule or make use
-- of heterogeneous equality
------------------------------------------------------------------------
{-# OPTIONS --with-K --safe #-}
module Data.Vec.Properties.WithK where
open import Data.Nat
open import Data.Nat.Properties using (+-assoc)
open import Data.Vec
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl)
open import Relation.Binary.HeterogeneousEquality as H using (_≅_; refl)
------------------------------------------------------------------------
-- _[_]=_
module _ {a} {A : Set a} where
[]=-irrelevant : ∀ {n} {xs : Vec A n} {i x} →
(p q : xs [ i ]= x) → p ≡ q
[]=-irrelevant here here = refl
[]=-irrelevant (there xs[i]=x) (there xs[i]=x') =
P.cong there ([]=-irrelevant xs[i]=x xs[i]=x')
------------------------------------------------------------------------
-- _++_
module _ {a} {A : Set a} where
++-assoc : ∀ {m n k} (xs : Vec A m) (ys : Vec A n) (zs : Vec A k) →
(xs ++ ys) ++ zs ≅ xs ++ (ys ++ zs)
++-assoc [] ys zs = refl
++-assoc {suc m} (x ∷ xs) ys zs =
H.icong (Vec A) (+-assoc m _ _) (x ∷_) (++-assoc xs ys zs)
------------------------------------------------------------------------
-- foldr
foldr-cong : ∀ {a b} {A : Set a}
{B : ℕ → Set b} {f : ∀ {n} → A → B n → B (suc n)} {d}
{C : ℕ → Set b} {g : ∀ {n} → A → C n → C (suc n)} {e} →
(∀ {n x} {y : B n} {z : C n} → y ≅ z → f x y ≅ g x z) →
d ≅ e → ∀ {n} (xs : Vec A n) →
foldr B f d xs ≅ foldr C g e xs
foldr-cong _ d≅e [] = d≅e
foldr-cong f≅g d≅e (x ∷ xs) = f≅g (foldr-cong f≅g d≅e xs)
------------------------------------------------------------------------
-- foldl
foldl-cong : ∀ {a b} {A : Set a}
{B : ℕ → Set b} {f : ∀ {n} → B n → A → B (suc n)} {d}
{C : ℕ → Set b} {g : ∀ {n} → C n → A → C (suc n)} {e} →
(∀ {n x} {y : B n} {z : C n} → y ≅ z → f y x ≅ g z x) →
d ≅ e → ∀ {n} (xs : Vec A n) →
foldl B f d xs ≅ foldl C g e xs
foldl-cong _ d≅e [] = d≅e
foldl-cong f≅g d≅e (x ∷ xs) = foldl-cong f≅g (f≅g d≅e) xs
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.0
[]=-irrelevance = []=-irrelevant
{-# WARNING_ON_USAGE []=-irrelevance
"Warning: []=-irrelevance was deprecated in v1.0.
Please use []=-irrelevant instead."
#-}
| {
"alphanum_fraction": 0.3901911287,
"avg_line_length": 36.012987013,
"ext": "agda",
"hexsha": "030ceb02f4681d84f9ba89efda2309b36fdf0359",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Properties/WithK.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Properties/WithK.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Properties/WithK.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 853,
"size": 2773
} |
{-# OPTIONS --without-K --exact-split #-}
module 17-number-theory where
import 16-sets
open 16-sets public
-- Section 10.1 Decidability.
{- Recall that a proposition P is decidable if P + (¬ P) holds. -}
classical-Prop :
(l : Level) → UU (lsuc l)
classical-Prop l = Σ (UU-Prop l) (λ P → is-decidable (pr1 P))
is-decidable-leq-ℕ :
(m n : ℕ) → is-decidable (leq-ℕ m n)
is-decidable-leq-ℕ zero-ℕ zero-ℕ = inl star
is-decidable-leq-ℕ zero-ℕ (succ-ℕ n) = inl star
is-decidable-leq-ℕ (succ-ℕ m) zero-ℕ = inr id
is-decidable-leq-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-leq-ℕ m n
is-decidable-le-ℕ :
(m n : ℕ) → is-decidable (le-ℕ m n)
is-decidable-le-ℕ zero-ℕ zero-ℕ = inr id
is-decidable-le-ℕ zero-ℕ (succ-ℕ n) = inl star
is-decidable-le-ℕ (succ-ℕ m) zero-ℕ = inr id
is-decidable-le-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-le-ℕ m n
{- We show that if A is a proposition, then so is is-decidable A. -}
is-prop-is-decidable :
{l : Level} {A : UU l} → is-prop A → is-prop (is-decidable A)
is-prop-is-decidable is-prop-A =
is-prop-coprod intro-dn is-prop-A is-prop-neg
{- Not every type is decidable. -}
case-elim :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
¬ B → coprod A B → A
case-elim nb (inl a) = a
case-elim nb (inr b) = ex-falso (nb b)
simplify-not-all-2-element-types-decidable :
{l : Level} →
((X : UU l) (p : type-trunc-Prop (bool ≃ X)) → is-decidable X) →
((X : UU l) (p : type-trunc-Prop (bool ≃ X)) → X)
simplify-not-all-2-element-types-decidable d X p =
case-elim
( map-universal-property-trunc-Prop
( dn-Prop' X)
( λ e → intro-dn (map-equiv e true))
( p))
( d X p)
{-
not-all-2-element-types-decidable :
{l : Level} → ¬ ((X : UU l) (p : type-trunc-Prop (bool ≃ X)) → is-decidable X)
not-all-2-element-types-decidable d = {!simplify-not-all-2-element-types-decidable d (raise _ bool) ?!}
not-all-types-decidable :
{l : Level} → ¬ ((X : UU l) → is-decidable X)
not-all-types-decidable d =
not-all-2-element-types-decidable (λ X p → d X)
-}
{- Types with decidable equality are closed under coproducts. -}
has-decidable-equality-coprod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
has-decidable-equality A → has-decidable-equality B →
has-decidable-equality (coprod A B)
has-decidable-equality-coprod dec-A dec-B (inl x) (inl y) =
functor-coprod
( ap inl)
( λ f p → f (inv-is-equiv (is-emb-inl _ _ x y) p))
( dec-A x y)
has-decidable-equality-coprod {A = A} {B = B} dec-A dec-B (inl x) (inr y) =
inr
( λ p →
inv-is-equiv
( is-equiv-map-raise _ empty)
( Eq-coprod-eq A B (inl x) (inr y) p))
has-decidable-equality-coprod {A = A} {B = B} dec-A dec-B (inr x) (inl y) =
inr
( λ p →
inv-is-equiv
( is-equiv-map-raise _ empty)
( Eq-coprod-eq A B (inr x) (inl y) p))
has-decidable-equality-coprod dec-A dec-B (inr x) (inr y) =
functor-coprod
( ap inr)
( λ f p → f (inv-is-equiv (is-emb-inr _ _ x y) p))
( dec-B x y)
{- Decidable equality of Fin n. -}
has-decidable-equality-empty : has-decidable-equality empty
has-decidable-equality-empty ()
has-decidable-equality-unit :
has-decidable-equality unit
has-decidable-equality-unit star star = inl refl
has-decidable-equality-Fin :
(n : ℕ) → has-decidable-equality (Fin n)
has-decidable-equality-Fin zero-ℕ = has-decidable-equality-empty
has-decidable-equality-Fin (succ-ℕ n) =
has-decidable-equality-coprod
( has-decidable-equality-Fin n)
( has-decidable-equality-unit)
decidable-Eq-Fin :
(n : ℕ) (i j : Fin n) → classical-Prop lzero
decidable-Eq-Fin n i j =
pair
( pair (Id i j) (is-set-Fin n i j))
( has-decidable-equality-Fin n i j)
{- Decidable equality of ℤ. -}
has-decidable-equality-ℤ : has-decidable-equality ℤ
has-decidable-equality-ℤ =
has-decidable-equality-coprod
has-decidable-equality-ℕ
( has-decidable-equality-coprod
has-decidable-equality-unit
has-decidable-equality-ℕ)
{- Next, we show that types with decidable equality are sets. To see this, we
will construct a fiberwise equivalence with the binary relation R that is
defined by R x y := unit if (x = y), and empty otherwise. In order to define
this relation, we first define a type family over ((x = y) + ¬(x = y)) that
returns unit on the left and empty on the right. -}
splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) →
is-decidable (Id x y) → UU lzero
splitting-decidable-equality A x y (inl p) = unit
splitting-decidable-equality A x y (inr f) = empty
is-prop-splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) →
(t : is-decidable (Id x y)) →
is-prop (splitting-decidable-equality A x y t)
is-prop-splitting-decidable-equality A x y (inl p) = is-prop-unit
is-prop-splitting-decidable-equality A x y (inr f) = is-prop-empty
reflexive-splitting-decidable-equality : {l : Level} (A : UU l) (x : A) →
(t : is-decidable (Id x x)) → splitting-decidable-equality A x x t
reflexive-splitting-decidable-equality A x (inl p) = star
reflexive-splitting-decidable-equality A x (inr f) =
ind-empty {P = λ t → splitting-decidable-equality A x x (inr f)} (f refl)
eq-splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) →
(t : is-decidable (Id x y)) →
splitting-decidable-equality A x y t → Id x y
eq-splitting-decidable-equality A x y (inl p) t = p
eq-splitting-decidable-equality A x y (inr f) t =
ind-empty {P = λ s → Id x y} t
is-set-has-decidable-equality : {l : Level} (A : UU l) →
has-decidable-equality A → is-set A
is-set-has-decidable-equality A d =
is-set-prop-in-id
( λ x y → splitting-decidable-equality A x y (d x y))
( λ x y → is-prop-splitting-decidable-equality A x y (d x y))
( λ x → reflexive-splitting-decidable-equality A x (d x x))
( λ x y → eq-splitting-decidable-equality A x y (d x y))
{- Closure of decidable types under retracts and equivalences. -}
is-decidable-retract-of :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
A retract-of B → is-decidable B → is-decidable A
is-decidable-retract-of (pair i (pair r H)) (inl b) = inl (r b)
is-decidable-retract-of (pair i (pair r H)) (inr f) = inr (f ∘ i)
is-decidable-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} {f : A → B}
(is-equiv-f : is-equiv f) → is-decidable B → is-decidable A
is-decidable-is-equiv {f = f} (pair (pair g G) (pair h H)) =
is-decidable-retract-of (pair f (pair h H))
is-decidable-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) →
is-decidable B → is-decidable A
is-decidable-equiv e = is-decidable-is-equiv (is-equiv-map-equiv e)
is-decidable-equiv' :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) →
is-decidable A → is-decidable B
is-decidable-equiv' e = is-decidable-equiv (inv-equiv e)
has-decidable-equality-retract-of :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
A retract-of B → has-decidable-equality B → has-decidable-equality A
has-decidable-equality-retract-of (pair i (pair r H)) d x y =
is-decidable-retract-of
( Id-retract-of-Id (pair i (pair r H)) x y)
( d (i x) (i y))
{- The well-ordering principle. -}
is-minimal-element-ℕ :
{l : Level} (P : ℕ → UU l) (n : ℕ) (p : P n) → UU l
is-minimal-element-ℕ P n p =
(m : ℕ) → P m → (leq-ℕ n m)
minimal-element-ℕ :
{l : Level} (P : ℕ → UU l) → UU l
minimal-element-ℕ P = Σ ℕ (λ n → Σ (P n) (is-minimal-element-ℕ P n))
is-minimal-element-succ-ℕ :
{l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n))
(m : ℕ) (pm : P (succ-ℕ m))
(is-min-m : is-minimal-element-ℕ (λ x → P (succ-ℕ x)) m pm) →
¬ (P zero-ℕ) → is-minimal-element-ℕ P (succ-ℕ m) pm
is-minimal-element-succ-ℕ P d m pm is-min-m neg-p0 zero-ℕ p0 =
ind-empty (neg-p0 p0)
is-minimal-element-succ-ℕ P d zero-ℕ pm is-min-m neg-p0 (succ-ℕ n) psuccn =
leq-zero-ℕ n
is-minimal-element-succ-ℕ P d (succ-ℕ m) pm is-min-m neg-p0 (succ-ℕ n) psuccn =
is-minimal-element-succ-ℕ (λ x → P (succ-ℕ x)) (λ x → d (succ-ℕ x)) m pm
( λ m → is-min-m (succ-ℕ m))
( is-min-m zero-ℕ)
( n)
( psuccn)
well-ordering-principle-succ-ℕ :
{l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n))
(n : ℕ) (p : P (succ-ℕ n)) →
is-decidable (P zero-ℕ) →
minimal-element-ℕ (λ m → P (succ-ℕ m)) → minimal-element-ℕ P
well-ordering-principle-succ-ℕ P d n p (inl p0) _ =
pair zero-ℕ (pair p0 (λ m q → leq-zero-ℕ m))
well-ordering-principle-succ-ℕ P d n p
(inr neg-p0) (pair m (pair pm is-min-m)) =
pair
( succ-ℕ m)
( pair pm
( is-minimal-element-succ-ℕ P d m pm is-min-m neg-p0))
well-ordering-principle-ℕ :
{l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n)) →
Σ ℕ P → minimal-element-ℕ P
well-ordering-principle-ℕ P d (pair zero-ℕ p) =
pair zero-ℕ (pair p (λ m q → leq-zero-ℕ m))
well-ordering-principle-ℕ P d (pair (succ-ℕ n) p) =
well-ordering-principle-succ-ℕ P d n p (d zero-ℕ)
( well-ordering-principle-ℕ
( λ m → P (succ-ℕ m))
( λ m → d (succ-ℕ m))
( pair n p))
-- Exercise 6.7
-- We prove that the induction principle for ℕ implies strong induction.
-- We first prove some lemmas about inequality.
is-prop-leq-ℕ :
(m n : ℕ) → is-prop (leq-ℕ m n)
is-prop-leq-ℕ zero-ℕ zero-ℕ = is-prop-unit
is-prop-leq-ℕ zero-ℕ (succ-ℕ n) = is-prop-unit
is-prop-leq-ℕ (succ-ℕ m) zero-ℕ = is-prop-empty
is-prop-leq-ℕ (succ-ℕ m) (succ-ℕ n) = is-prop-leq-ℕ m n
neg-succ-leq-ℕ :
(n : ℕ) → ¬ (leq-ℕ (succ-ℕ n) n)
neg-succ-leq-ℕ zero-ℕ = id
neg-succ-leq-ℕ (succ-ℕ n) = neg-succ-leq-ℕ n
leq-eq-left-ℕ :
{m m' : ℕ} → Id m m' → (n : ℕ) → leq-ℕ m n → leq-ℕ m' n
leq-eq-left-ℕ refl n = id
leq-eq-right-ℕ :
(m : ℕ) {n n' : ℕ} → Id n n' → leq-ℕ m n → leq-ℕ m n'
leq-eq-right-ℕ m refl = id
-- Now we begin with the proof of the theorem
fam-strong-ind-ℕ :
{ l : Level} → (ℕ → UU l) → ℕ → UU l
fam-strong-ind-ℕ P n = (m : ℕ) → (leq-ℕ m n) → P m
-- We first take care of the zero case, with appropriate computation rule.
zero-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) → P zero-ℕ → fam-strong-ind-ℕ P zero-ℕ
zero-strong-ind-ℕ P p0 zero-ℕ t = p0
zero-strong-ind-ℕ P p0 (succ-ℕ m) ()
eq-zero-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) (t : leq-ℕ zero-ℕ zero-ℕ) →
Id (zero-strong-ind-ℕ P p0 zero-ℕ t) p0
eq-zero-strong-ind-ℕ P p0 t = refl
-- Next, we take care of the successor case, with appropriate computation rule.
{- In the successor case, we need to define a map
fam-strong-ind-ℕ P k → fam-strong-ind-ℕ P (succ-ℕ k).
The dependent function in the codomain is defined by case analysis, where
the cases are that either m ≤ k or m = k+1.
-}
-- We use the following definition to get a map (m≤k+1) → coprod (m≤k) (m=k+1).
cases-leq-succ-ℕ :
{m n : ℕ} → leq-ℕ m (succ-ℕ n) → coprod (leq-ℕ m n) (Id m (succ-ℕ n))
cases-leq-succ-ℕ {zero-ℕ} {n} star = inl star
cases-leq-succ-ℕ {succ-ℕ m} {zero-ℕ} p =
inr (ap succ-ℕ (anti-symmetric-leq-ℕ m zero-ℕ p star))
cases-leq-succ-ℕ {succ-ℕ m} {succ-ℕ n} p =
functor-coprod id (ap succ-ℕ) (cases-leq-succ-ℕ p)
cases-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( (n : ℕ) → (fam-strong-ind-ℕ P n) → P (succ-ℕ n)) →
( n : ℕ) (H : fam-strong-ind-ℕ P n) →
( m : ℕ) ( c : coprod (leq-ℕ m n) (Id m (succ-ℕ n))) → P m
cases-succ-strong-ind-ℕ P pS n H m (inl q) = H m q
cases-succ-strong-ind-ℕ P pS n H .(succ-ℕ n) (inr refl) = pS n H
succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) → (fam-strong-ind-ℕ P k) → (fam-strong-ind-ℕ P (succ-ℕ k))
succ-strong-ind-ℕ P pS k H m p =
cases-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p)
-- We use a similar case analysis to obtain the computation rule.
{-
exclusive-coprod-leq-eq-succ-ℕ :
(m n : ℕ) → leq-ℕ m n → ¬ (Id m (succ-ℕ n))
exclusive-coprod-leq-eq-succ-ℕ zero-ℕ zero-ℕ star = {!Eq-eq-ℕ!}
exclusive-coprod-leq-eq-succ-ℕ zero-ℕ (succ-ℕ n) p = {!!}
exclusive-coprod-leq-eq-succ-ℕ (succ-ℕ m) (succ-ℕ n) p = {!!}
is-prop'-coprod-leq-eq-succ :
(m n : ℕ) → is-prop' (coprod (leq-ℕ m n) (Id m (succ-ℕ n)))
is-prop'-coprod-leq-eq-succ m n =
is-prop'-exclusive-coprod
( exclusive-coprod-leq-eq-succ-ℕ m n)
( is-prop'-is-prop (is-prop-leq-ℕ m n))
( is-prop'-is-prop (is-set-ℕ m (succ-ℕ n)))
tr-eq-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k))
( n : ℕ) (H : fam-strong-ind-ℕ P n)
( m : ℕ) (p : leq-ℕ m (succ-ℕ n))
( x : coprod (leq-ℕ m n) (Id m (succ-ℕ n))) (y : P m) →
Id (succ-strong-ind-ℕ P pS n H m p) y →
Id (cases-succ-strong-ind-ℕ P pS n H m x) y
tr-eq-succ-strong-ind-ℕ P pS n H m p x y =
tr ( λ t → Id (cases-succ-strong-ind-ℕ P pS n H m t) y)
( is-prop'-coprod-leq-eq-succ m n (cases-leq-succ-ℕ p) x)
-}
cases-htpy-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) (H : fam-strong-ind-ℕ P k) (m : ℕ)
( c : coprod (leq-ℕ m k) (Id m (succ-ℕ k))) →
( q : leq-ℕ m k) →
Id
( cases-succ-strong-ind-ℕ P pS k H m c)
( H m q)
cases-htpy-succ-strong-ind-ℕ P pS k H m (inl p) q =
ap (H m) (is-prop'-is-prop (is-prop-leq-ℕ m k) p q)
cases-htpy-succ-strong-ind-ℕ P pS k H m (inr α) q =
ex-falso
( neg-succ-leq-ℕ k (leq-eq-left-ℕ α k q))
htpy-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) (H : fam-strong-ind-ℕ P k) (m : ℕ)
( p : leq-ℕ m (succ-ℕ k)) →
( q : leq-ℕ m k) →
Id
( succ-strong-ind-ℕ P pS k H m p)
( H m q)
htpy-succ-strong-ind-ℕ P pS k H m p q =
cases-htpy-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p) q
cases-eq-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) (H : fam-strong-ind-ℕ P k)
( c : coprod (leq-ℕ (succ-ℕ k) k) (Id (succ-ℕ k) (succ-ℕ k))) →
Id ( (cases-succ-strong-ind-ℕ P pS k H (succ-ℕ k) c))
( pS k H)
cases-eq-succ-strong-ind-ℕ P pS k H (inl p) = ex-falso (neg-succ-leq-ℕ k p)
cases-eq-succ-strong-ind-ℕ P pS k H (inr α) =
ap ( (cases-succ-strong-ind-ℕ P pS k H (succ-ℕ k)) ∘ inr)
( is-prop'-is-prop (is-set-ℕ (succ-ℕ k) (succ-ℕ k)) α refl)
eq-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) (H : fam-strong-ind-ℕ P k)
( p : leq-ℕ (succ-ℕ k) (succ-ℕ k)) →
Id ( (succ-strong-ind-ℕ P pS k H (succ-ℕ k) p))
( pS k H)
eq-succ-strong-ind-ℕ P pS k H p =
cases-eq-succ-strong-ind-ℕ P pS k H (cases-leq-succ-ℕ p)
{- Now that we have the base case and inductive step covered, we can proceed
by induction. -}
induction-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( fam-strong-ind-ℕ P zero-ℕ) →
( (k : ℕ) → (fam-strong-ind-ℕ P k) → (fam-strong-ind-ℕ P (succ-ℕ k))) →
( n : ℕ) → fam-strong-ind-ℕ P n
induction-strong-ind-ℕ P q0 qS zero-ℕ = q0
induction-strong-ind-ℕ P q0 qS (succ-ℕ n) =
qS n (induction-strong-ind-ℕ P q0 qS n)
computation-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( q0 : fam-strong-ind-ℕ P zero-ℕ) →
( qS : (k : ℕ) → (fam-strong-ind-ℕ P k) → (fam-strong-ind-ℕ P (succ-ℕ k))) →
( n : ℕ) →
Id ( induction-strong-ind-ℕ P q0 qS (succ-ℕ n))
( qS n (induction-strong-ind-ℕ P q0 qS n))
computation-succ-strong-ind-ℕ P q0 qS n = refl
{- However, to obtain the conclusion we need to make one more small step. -}
conclusion-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( ( n : ℕ) → fam-strong-ind-ℕ P n) → (n : ℕ) → P n
conclusion-strong-ind-ℕ P f n = f n n (reflexive-leq-ℕ n)
{- We are finally ready to put things together and define strong-ind-ℕ. -}
strong-ind-ℕ :
{ l : Level} → (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( n : ℕ) → P n
strong-ind-ℕ P p0 pS =
conclusion-strong-ind-ℕ P
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS))
{- The computation rule for the base case holds by definition. -}
comp-zero-strong-ind-ℕ :
{ l : Level} → (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
Id (strong-ind-ℕ P p0 pS zero-ℕ) p0
comp-zero-strong-ind-ℕ P p0 pS = refl
{- For the computation rule of the inductive step, we use our hard work. -}
cases-leq-succ-reflexive-leq-ℕ :
{n : ℕ} → Id (cases-leq-succ-ℕ {succ-ℕ n} {n} (reflexive-leq-ℕ n)) (inr refl)
cases-leq-succ-reflexive-leq-ℕ {zero-ℕ} = refl
cases-leq-succ-reflexive-leq-ℕ {succ-ℕ n} =
ap (functor-coprod id (ap succ-ℕ)) cases-leq-succ-reflexive-leq-ℕ
cases-eq-comp-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( n : ℕ) →
( α :
( m : ℕ) (p : leq-ℕ m n) →
Id ( induction-strong-ind-ℕ P (zero-strong-ind-ℕ P p0)
( λ k z m₁ z₁ →
cases-succ-strong-ind-ℕ P pS k z m₁ (cases-leq-succ-ℕ z₁))
n m p)
( strong-ind-ℕ P p0 pS m)) →
( m : ℕ) (p : leq-ℕ m (succ-ℕ n)) →
( q : coprod (leq-ℕ m n) (Id m (succ-ℕ n))) →
Id ( succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS) n) m p)
( strong-ind-ℕ P p0 pS m)
cases-eq-comp-succ-strong-ind-ℕ P p0 pS n α m p (inl x) =
( htpy-succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS) n)
m p x) ∙
( α m x)
cases-eq-comp-succ-strong-ind-ℕ P p0 pS n α .(succ-ℕ n) p (inr refl) =
( eq-succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS) n)
( p)) ∙
( inv
( ap
( cases-succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( λ k H m p₁ →
cases-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p₁))
n)
( succ-ℕ n))
cases-leq-succ-reflexive-leq-ℕ))
eq-comp-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( n : ℕ) →
( m : ℕ) (p : leq-ℕ m n) →
Id ( induction-strong-ind-ℕ P (zero-strong-ind-ℕ P p0)
( λ k z m₁ z₁ →
cases-succ-strong-ind-ℕ P pS k z m₁ (cases-leq-succ-ℕ z₁))
n m p)
( strong-ind-ℕ P p0 pS m)
eq-comp-succ-strong-ind-ℕ P p0 pS zero-ℕ zero-ℕ star = refl
eq-comp-succ-strong-ind-ℕ P p0 pS zero-ℕ (succ-ℕ m) ()
eq-comp-succ-strong-ind-ℕ P p0 pS (succ-ℕ n) m p =
cases-eq-comp-succ-strong-ind-ℕ P p0 pS n
( eq-comp-succ-strong-ind-ℕ P p0 pS n) m p
( cases-leq-succ-ℕ p)
comp-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( n : ℕ) →
Id (strong-ind-ℕ P p0 pS (succ-ℕ n)) (pS n (λ m p → strong-ind-ℕ P p0 pS m))
comp-succ-strong-ind-ℕ P p0 pS n =
( eq-succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS)
( n))
( reflexive-leq-ℕ n)) ∙
( ap ( pS n)
( eq-htpy
( λ m → eq-htpy
( λ p → eq-comp-succ-strong-ind-ℕ P p0 pS n m p))))
total-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
Σ ( (n : ℕ) → P n)
( λ h →
( Id (h zero-ℕ) p0) ×
( (n : ℕ) → Id (h (succ-ℕ n)) (pS n (λ m p → h m))))
total-strong-ind-ℕ P p0 pS =
pair
( strong-ind-ℕ P p0 pS)
( pair
( comp-zero-strong-ind-ℕ P p0 pS)
( comp-succ-strong-ind-ℕ P p0 pS))
-- The Euclidean algorithm
subtract-ℕ : ℕ → ℕ → ℕ
subtract-ℕ zero-ℕ zero-ℕ = zero-ℕ
subtract-ℕ zero-ℕ (succ-ℕ b) = zero-ℕ
subtract-ℕ (succ-ℕ a) zero-ℕ = succ-ℕ a
subtract-ℕ (succ-ℕ a) (succ-ℕ b) = subtract-ℕ a b
leq-subtract-ℕ : (a b : ℕ) → leq-ℕ (subtract-ℕ a b) a
leq-subtract-ℕ zero-ℕ zero-ℕ = star
leq-subtract-ℕ zero-ℕ (succ-ℕ b) = star
leq-subtract-ℕ (succ-ℕ a) zero-ℕ = reflexive-leq-ℕ a
leq-subtract-ℕ (succ-ℕ a) (succ-ℕ b) =
transitive-leq-ℕ (subtract-ℕ a b) a (succ-ℕ a)
( leq-subtract-ℕ a b)
( succ-leq-ℕ a)
decide-order-ℕ : (a b : ℕ) → coprod (leq-ℕ b a) (le-ℕ a b)
decide-order-ℕ zero-ℕ zero-ℕ = inl star
decide-order-ℕ zero-ℕ (succ-ℕ b) = inr star
decide-order-ℕ (succ-ℕ a) zero-ℕ = inl star
decide-order-ℕ (succ-ℕ a) (succ-ℕ b) = decide-order-ℕ a b
cases-gcd-euclid :
( a b : ℕ)
( F : (x : ℕ) (p : leq-ℕ x a) → ℕ → ℕ)
( G : (y : ℕ) (q : leq-ℕ y b) → ℕ) →
( coprod (leq-ℕ b a) (le-ℕ a b)) → ℕ
cases-gcd-euclid a b F G (inl t) =
F (subtract-ℕ a b) (leq-subtract-ℕ a b) (succ-ℕ b)
cases-gcd-euclid a b F G (inr t) =
G (subtract-ℕ b a) (leq-subtract-ℕ b a)
succ-gcd-euclid : (a : ℕ) (F : (x : ℕ) → (leq-ℕ x a) → ℕ → ℕ) → ℕ → ℕ
succ-gcd-euclid a F =
strong-ind-ℕ
( λ x → ℕ)
( succ-ℕ a)
( λ b G →
ind-coprod
{ A = leq-ℕ b a}
{ B = le-ℕ a b}
( λ x → ℕ)
( λ t → F (subtract-ℕ a b) (leq-subtract-ℕ a b) (succ-ℕ b))
( λ t → G (subtract-ℕ b a) (leq-subtract-ℕ b a))
( decide-order-ℕ a b))
comp-zero-succ-gcd-euclid :
(a : ℕ) (F : (x : ℕ) → (leq-ℕ x a) → ℕ → ℕ) →
Id (succ-gcd-euclid a F zero-ℕ) (succ-ℕ a)
comp-zero-succ-gcd-euclid a F =
comp-zero-strong-ind-ℕ
( λ x → ℕ)
( succ-ℕ a)
( λ b G →
ind-coprod
{ A = leq-ℕ b a}
{ B = le-ℕ a b}
( λ x → ℕ)
( λ t → F (subtract-ℕ a b) (leq-subtract-ℕ a b) (succ-ℕ b))
( λ t → G (subtract-ℕ b a) (leq-subtract-ℕ b a))
( decide-order-ℕ a b))
comp-succ-succ-gcd-euclid :
(a : ℕ) (F : (x : ℕ) → (leq-ℕ x a) → ℕ → ℕ) (b : ℕ) →
Id (succ-gcd-euclid a F (succ-ℕ b))
( ind-coprod
{ A = leq-ℕ b a}
{ B = le-ℕ a b}
( λ x → ℕ)
( λ t → F (subtract-ℕ a b) (leq-subtract-ℕ a b) (succ-ℕ b))
( λ t → succ-gcd-euclid a F (subtract-ℕ b a))
( decide-order-ℕ a b))
comp-succ-succ-gcd-euclid a F b =
comp-succ-strong-ind-ℕ
( λ x → ℕ)
( succ-ℕ a)
( λ k z →
ind-coprod (λ _ → ℕ)
(λ x → F (subtract-ℕ a k) (leq-subtract-ℕ a k) (succ-ℕ k))
(λ y → z (subtract-ℕ k a) (leq-subtract-ℕ k a))
(decide-order-ℕ a k))
( b)
gcd-euclid : ℕ → ℕ → ℕ
gcd-euclid =
strong-ind-ℕ
( λ x → ℕ → ℕ)
( id)
( succ-gcd-euclid)
comp-succ-gcd-euclid :
(a : ℕ) →
Id (gcd-euclid (succ-ℕ a)) (succ-gcd-euclid a (λ x p → gcd-euclid x))
comp-succ-gcd-euclid =
comp-succ-strong-ind-ℕ (λ x → ℕ → ℕ) id succ-gcd-euclid
-- Properties of the greatest common divisor
left-zero-law-gcd-euclid : (gcd-euclid zero-ℕ) ~ id
left-zero-law-gcd-euclid =
htpy-eq (comp-zero-strong-ind-ℕ (λ x → ℕ → ℕ) id succ-gcd-euclid)
right-zero-law-gcd-euclid : (a : ℕ) → Id (gcd-euclid a zero-ℕ) a
right-zero-law-gcd-euclid zero-ℕ = refl
right-zero-law-gcd-euclid (succ-ℕ a) =
( ap
( λ t →
cases-succ-strong-ind-ℕ (λ x → ℕ → ℕ) succ-gcd-euclid a
( induction-strong-ind-ℕ
( λ x → ℕ → ℕ)
( zero-strong-ind-ℕ (λ x → ℕ → ℕ) (λ a₁ → a₁))
( λ k H m p →
cases-succ-strong-ind-ℕ (λ x → ℕ → ℕ) succ-gcd-euclid k H m
(cases-leq-succ-ℕ p))
( a))
( succ-ℕ a) t zero-ℕ)
cases-leq-succ-reflexive-leq-ℕ) ∙
( comp-zero-succ-gcd-euclid a (λ x _ z → z))
is-prop-le-ℕ : (a b : ℕ) → is-prop (le-ℕ a b)
is-prop-le-ℕ zero-ℕ zero-ℕ = is-prop-empty
is-prop-le-ℕ zero-ℕ (succ-ℕ b) = is-prop-unit
is-prop-le-ℕ (succ-ℕ a) zero-ℕ = is-prop-empty
is-prop-le-ℕ (succ-ℕ a) (succ-ℕ b) = is-prop-le-ℕ a b
is-prop'-le-ℕ : (a b : ℕ) → is-prop' (le-ℕ a b)
is-prop'-le-ℕ a b = is-prop'-is-prop (is-prop-le-ℕ a b)
{-
left-lesser-law-gcd-euclid : (a b : ℕ) → (le-ℕ a b) →
Id (gcd-euclid a b) (gcd-euclid a (subtract-ℕ b a))
left-lesser-law-gcd-euclid zero-ℕ (succ-ℕ b) H = refl
left-lesser-law-gcd-euclid (succ-ℕ a) (succ-ℕ b) H =
( htpy-eq (comp-succ-gcd-euclid a) (succ-ℕ b)) ∙ {!!}
-}
{- ( (comp-succ-succ-gcd-euclid a (λ x t → gcd-euclid x) b) ∙
( ( {!!} ∙ apd (λ t → (ind-coprod (λ x → ℕ)
(λ t → gcd-euclid (subtract-ℕ a b) (succ-ℕ b))
(λ t → succ-gcd-euclid a (λ x t₁ → gcd-euclid x) (subtract-ℕ b a))
t)) (ap inr (is-prop'-le-ℕ a b {!!} {!!}))) ∙ {!!}
{- ( inv (ap (λ t → cases-succ-strong-ind-ℕ (λ x → ℕ → ℕ) succ-gcd-euclid a
(induction-strong-ind-ℕ (λ x → ℕ → ℕ)
(zero-strong-ind-ℕ (λ x → ℕ → ℕ) (λ a₁ → a₁))
(λ k H₁ m p →
cases-succ-strong-ind-ℕ (λ x → ℕ → ℕ) succ-gcd-euclid k H₁ m
(cases-leq-succ-ℕ p))
a)
(succ-ℕ a) t
(subtract-ℕ (succ-ℕ b) (succ-ℕ a))) cases-leq-succ-reflexive-leq-ℕ))-}))
-}
-- We show that induction on ℕ implies ordinal induction.
fam-ordinal-ind-ℕ :
{ l : Level} → (ℕ → UU l) → ℕ → UU l
fam-ordinal-ind-ℕ P n = (m : ℕ) → (le-ℕ m n) → P m
le-zero-ℕ :
(m : ℕ) → (le-ℕ m zero-ℕ) → empty
le-zero-ℕ zero-ℕ ()
le-zero-ℕ (succ-ℕ m) ()
zero-ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) → fam-ordinal-ind-ℕ P zero-ℕ
zero-ordinal-ind-ℕ P m t = ind-empty (le-zero-ℕ m t)
le-one-ℕ :
(n : ℕ) → le-ℕ (succ-ℕ n) one-ℕ → empty
le-one-ℕ zero-ℕ ()
le-one-ℕ (succ-ℕ n) ()
transitive-le-ℕ' :
(k l m : ℕ) → (le-ℕ k l) → (le-ℕ l (succ-ℕ m)) → le-ℕ k m
transitive-le-ℕ' zero-ℕ zero-ℕ m () s
transitive-le-ℕ' (succ-ℕ k) zero-ℕ m () s
transitive-le-ℕ' zero-ℕ (succ-ℕ l) zero-ℕ star s = ind-empty (le-one-ℕ l s)
transitive-le-ℕ' (succ-ℕ k) (succ-ℕ l) zero-ℕ t s = ind-empty (le-one-ℕ l s)
transitive-le-ℕ' zero-ℕ (succ-ℕ l) (succ-ℕ m) star s = star
transitive-le-ℕ' (succ-ℕ k) (succ-ℕ l) (succ-ℕ m) t s =
transitive-le-ℕ' k l m t s
succ-ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( (n : ℕ) → (fam-ordinal-ind-ℕ P n) → P n) →
( k : ℕ) → fam-ordinal-ind-ℕ P k → fam-ordinal-ind-ℕ P (succ-ℕ k)
succ-ordinal-ind-ℕ P f k g m t =
f m (λ m' t' → g m' (transitive-le-ℕ' m' m k t' t))
induction-ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( qS : (k : ℕ) → fam-ordinal-ind-ℕ P k → fam-ordinal-ind-ℕ P (succ-ℕ k))
( n : ℕ) → fam-ordinal-ind-ℕ P n
induction-ordinal-ind-ℕ P qS zero-ℕ = zero-ordinal-ind-ℕ P
induction-ordinal-ind-ℕ P qS (succ-ℕ n) =
qS n (induction-ordinal-ind-ℕ P qS n)
conclusion-ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
(( n : ℕ) → fam-ordinal-ind-ℕ P n) → (n : ℕ) → P n
conclusion-ordinal-ind-ℕ P f n = f (succ-ℕ n) n (succ-le-ℕ n)
ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( (n : ℕ) → (fam-ordinal-ind-ℕ P n) → P n) →
( n : ℕ) → P n
ordinal-ind-ℕ P f =
conclusion-ordinal-ind-ℕ P
( induction-ordinal-ind-ℕ P (succ-ordinal-ind-ℕ P f))
{- The Pigeon hole principle. -}
{- First we write a function that counts the number of elements in a decidable
subset of a finite set. -}
count-Fin-succ-ℕ :
{l : Level} (n : ℕ) (P : Fin (succ-ℕ n) → classical-Prop l) →
ℕ → is-decidable (pr1 (pr1 (P (inr star)))) → ℕ
count-Fin-succ-ℕ n P m (inl x) = succ-ℕ m
count-Fin-succ-ℕ n P m (inr x) = m
count-Fin :
{l : Level} (n : ℕ) (P : Fin n → classical-Prop l) → ℕ
count-Fin zero-ℕ P = zero-ℕ
count-Fin (succ-ℕ n) P =
count-Fin-succ-ℕ n P
( count-Fin n (P ∘ inl))
( pr2 (P (inr star)))
{- Next we prove the pigeonhole principle. -}
max-Fin :
(n : ℕ) → Fin (succ-ℕ n)
max-Fin n = inr star
contraction-Fin-one-ℕ :
(t : Fin one-ℕ) → Id (inr star) t
contraction-Fin-one-ℕ (inr star) = refl
is-contr-Fin-one-ℕ :
is-contr (Fin one-ℕ)
is-contr-Fin-one-ℕ = pair (inr star) contraction-Fin-one-ℕ
skip :
(n : ℕ) → Fin (succ-ℕ n) → Fin n → Fin (succ-ℕ n)
skip (succ-ℕ n) (inl i) (inl j) = inl (skip n i j)
skip (succ-ℕ n) (inl i) (inr star) = inr star
skip (succ-ℕ n) (inr star) j = inl j
repeat :
(n : ℕ) → Fin n → Fin (succ-ℕ n) → Fin n
repeat (succ-ℕ n) (inl i) (inl j) = inl (repeat n i j)
repeat (succ-ℕ n) (inl j) (inr star) = inr star
repeat (succ-ℕ n) (inr star) (inl j) = j
repeat (succ-ℕ n) (inr star) (inr star) = inr star
repeat-repeat :
(n : ℕ) (i j : Fin n) →
((repeat n i) ∘ (repeat (succ-ℕ n) (skip n (inl i) j))) ~
((repeat n j) ∘ (repeat (succ-ℕ n) (skip n (inl j) i)))
repeat-repeat zero-ℕ () j k
repeat-repeat (succ-ℕ n) (inl i) (inl j) (inl k) =
ap inl (repeat-repeat n i j k)
repeat-repeat (succ-ℕ n) (inl i) (inl j) (inr star) = refl
repeat-repeat (succ-ℕ n) (inl i) (inr star) (inr star) = refl
repeat-repeat (succ-ℕ n) (inr star) (inl j) (inr star) = refl
repeat-repeat (succ-ℕ n) (inr star) (inr star) (inl k) = refl
repeat-repeat (succ-ℕ n) (inr star) (inr star) (inr star) = refl
repeat-repeat (succ-ℕ zero-ℕ) (inl ()) (inr star) (inl k)
repeat-repeat (succ-ℕ (succ-ℕ n)) (inl i) (inr star) (inl k) = refl
repeat-repeat (succ-ℕ zero-ℕ) (inr star) (inl ()) (inl k)
repeat-repeat (succ-ℕ (succ-ℕ n)) (inr star) (inl j) (inl k) = refl
{-
skip-repeat :
(n : ℕ) (i : Fin n) → ((skip n (inl i)) ∘ (repeat n i)) ~ id
skip-repeat (succ-ℕ n) (inl x) (inl y) = ap inl (skip-repeat n x y)
skip-repeat (succ-ℕ n) (inl x) (inr star) = refl
skip-repeat (succ-ℕ n) (inr star) (inl (inl x)) = ap inl {!ap (skip n) ?!}
skip-repeat (succ-ℕ n) (inr star) (inl (inr star)) = {!!}
skip-repeat (succ-ℕ n) (inr star) (inr star) = {!!}
-}
map-lift-Fin :
(m n : ℕ) (f : Fin (succ-ℕ m) → Fin (succ-ℕ n))
(i : Fin (succ-ℕ n)) (H : fib f i → empty) →
Fin m → Fin n
map-lift-Fin m n f (inl i) H = (repeat n i) ∘ (f ∘ inl)
map-lift-Fin m (succ-ℕ n) f (inr star) H =
( repeat (succ-ℕ n) (max-Fin n)) ∘
( f ∘ inl)
map-lift-Fin zero-ℕ zero-ℕ f (inr star) H = ind-empty
map-lift-Fin (succ-ℕ m) zero-ℕ f (inr star) H =
ex-falso
( H (pair (inr star) (inv (contraction-Fin-one-ℕ (f (inr star))))))
{-
is-lift-lift-Fin :
(m n : ℕ) (f : Fin (succ-ℕ m) → Fin (succ-ℕ n))
(i : Fin (succ-ℕ n)) (H : fib f i → empty) →
(f ∘ inl) ~ ((skip n i) ∘ (map-lift-Fin m n f i H))
is-lift-lift-Fin m n f (inl i) H x = {!!}
is-lift-lift-Fin m n f (inr i) H x = {!!}
-}
-- The greatest common divisor
{- First we show that mul-ℕ n is an embedding whenever n > 0. In order to do
this, we have to show that add-ℕ n is injective. -}
{- FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX
is-injective-add-ℕ' :
(n : ℕ) → is-injective is-set-ℕ is-set-ℕ (add-ℕ n)
is-injective-add-ℕ' n k l p = is-injective-add-ℕ' n k l
(((commutative-add-ℕ n k) ∙ ?) ∙ (commutative-add-ℕ l n))
is-emb-add-ℕ :
(n : ℕ) → is-emb (add-ℕ n)
is-emb-add-ℕ n =
is-emb-is-injective is-set-ℕ is-set-ℕ (add-ℕ n) (is-injective-add-ℕ n)
equiv-fib-add-fib-add-ℕ' :
(m n : ℕ) → fib (add-ℕ' m) n ≃ fib (add-ℕ m) n
equiv-fib-add-fib-add-ℕ' m n =
equiv-tot (λ k → equiv-concat (commutative-add-ℕ m k) n)
leq-fib-add-ℕ' :
(m n : ℕ) → fib (add-ℕ' m) n → (leq-ℕ m n)
leq-fib-add-ℕ' zero-ℕ n (pair k p) = leq-zero-ℕ n
leq-fib-add-ℕ' (succ-ℕ m) (succ-ℕ n) (pair k p) =
leq-fib-add-ℕ' m n (pair k (is-injective-succ-ℕ (add-ℕ k m) n p))
leq-fib-add-ℕ :
(m n : ℕ) → fib (add-ℕ m) n → (leq-ℕ m n)
leq-fib-add-ℕ m .m (pair zero-ℕ refl) = reflexive-leq-ℕ m
leq-fib-add-ℕ m .(add-ℕ m (succ-ℕ k)) (pair (succ-ℕ k) refl) =
transitive-leq-ℕ m (add-ℕ m k) (succ-ℕ (add-ℕ m k))
( leq-fib-add-ℕ m (add-ℕ m k) (pair k refl))
( succ-leq-ℕ (add-ℕ m k))
-}
{-
fib-add-leq-ℕ :
(m n : ℕ) → (leq-ℕ m n) → fib (add-ℕ m) n
fib-add-leq-ℕ zero-ℕ zero-ℕ star = pair zero-ℕ refl
fib-add-leq-ℕ zero-ℕ (succ-ℕ n) star = {!!}
fib-add-leq-ℕ (succ-ℕ m) (succ-ℕ n) p = {!!}
{-
fib-add-leq-ℕ zero-ℕ zero-ℕ H = pair zero-ℕ refl
fib-add-leq-ℕ zero-ℕ (succ-ℕ n) H = pair (succ-ℕ n) refl
fib-add-leq-ℕ (succ-ℕ m) (succ-ℕ n) H =
pair
( pr1 (fib-add-leq-ℕ m n H))
( ap succ-ℕ (pr2 (fib-add-leq-ℕ m n H)))
-}
is-equiv-leq-fib-add-ℕ :
(m n : ℕ) → is-equiv (leq-fib-add-ℕ m n)
is-equiv-leq-fib-add-ℕ m n =
is-equiv-is-prop
( is-prop-map-is-emb _ (is-emb-add-ℕ m) n)
( is-prop-leq-ℕ m n)
( fib-add-leq-ℕ m n)
is-equiv-fib-add-leq-ℕ :
(m n : ℕ) → is-equiv (fib-add-leq-ℕ m n)
is-equiv-fib-add-leq-ℕ m n =
is-equiv-is-prop
( is-prop-leq-ℕ m n)
( is-prop-map-is-emb _ (is-emb-add-ℕ m) n)
( leq-fib-add-ℕ m n)
-}
is-emb-mul-ℕ :
(n : ℕ) → is-emb (mul-ℕ' (succ-ℕ n))
is-emb-mul-ℕ n =
is-emb-is-injective is-set-ℕ is-set-ℕ
( mul-ℕ' (succ-ℕ n))
( is-injective-mul-ℕ n)
{- FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX
is-emb-mul-ℕ' :
(n : ℕ) → (le-ℕ zero-ℕ n) → is-emb (λ m → mul-ℕ m n)
is-emb-mul-ℕ' n t =
is-emb-htpy'
( mul-ℕ n)
( λ m → mul-ℕ m n)
( commutative-mul-ℕ n)
( is-emb-mul-ℕ n)
-}
{- We conclude that the division relation is a property. -}
{- FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX
is-prop-div-ℕ :
(m n : ℕ) → (le-ℕ zero-ℕ m) → is-prop (div-ℕ m n)
is-prop-div-ℕ (succ-ℕ m) n star =
is-prop-map-is-emb
( λ z → mul-ℕ z (succ-ℕ m))
( is-emb-mul-ℕ' (succ-ℕ m) star)
n
-}
{- We now construct the division with remainder. -}
le-mul-ℕ :
(d n k : ℕ) → UU lzero
le-mul-ℕ d n k = le-ℕ n (mul-ℕ k d)
is-decidable-le-mul-ℕ :
(d n k : ℕ) → is-decidable (le-mul-ℕ d n k)
is-decidable-le-mul-ℕ d n k =
is-decidable-le-ℕ n (mul-ℕ k d)
order-preserving-succ-ℕ :
(n n' : ℕ) → (leq-ℕ n n') → (leq-ℕ (succ-ℕ n) (succ-ℕ n'))
order-preserving-succ-ℕ n n' H = H
{-
order-preserving-add-ℕ :
(m n m' n' : ℕ) →
(leq-ℕ m m') → (leq-ℕ n n') → (leq-ℕ (add-ℕ m n) (add-ℕ m' n'))
order-preserving-add-ℕ = {!!}
-}
{-
order-preserving-add-ℕ zero-ℕ zero-ℕ m' n' Hm Hn = star
order-preserving-add-ℕ zero-ℕ (succ-ℕ n) zero-ℕ (succ-ℕ n') Hm Hn = Hn
order-preserving-add-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ m') (succ-ℕ n') Hm Hn =
leq-eq-right-ℕ n
( inv (right-successor-law-add-ℕ m' n'))
( order-preserving-add-ℕ zero-ℕ n (succ-ℕ m') n' Hm Hn)
order-preserving-add-ℕ (succ-ℕ m) n (succ-ℕ m') n' Hm Hn =
order-preserving-add-ℕ m n m' n' Hm Hn
-}
le-eq-right-ℕ :
(m : ℕ) {n n' : ℕ} → Id n n' → le-ℕ m n' → le-ℕ m n
le-eq-right-ℕ m refl = id
{-
le-add-ℕ :
(m n : ℕ) → (leq-ℕ one-ℕ n) → le-ℕ m (add-ℕ m n)
le-add-ℕ = {!!}
{-
le-add-ℕ zero-ℕ (succ-ℕ n) star = star
le-add-ℕ (succ-ℕ m) (succ-ℕ n) star = le-add-ℕ m (succ-ℕ n) star
-}
le-mul-self-ℕ :
(d n : ℕ) → (leq-ℕ one-ℕ d) → (leq-ℕ one-ℕ n) → le-mul-ℕ d n n
le-mul-self-ℕ (succ-ℕ d) (succ-ℕ n) star star =
le-eq-right-ℕ
( succ-ℕ n)
( right-successor-law-mul-ℕ (succ-ℕ n) d)
( le-add-ℕ (succ-ℕ n) (mul-ℕ (succ-ℕ n) d) {!leq-eq-right-ℕ !})
-}
{-
leq-multiple-ℕ :
(n m : ℕ) → (leq-ℕ one-ℕ m) → leq-ℕ n (mul-ℕ n m)
leq-multiple-ℕ n (succ-ℕ m) H =
leq-eq-right-ℕ n
( inv (right-successor-law-mul-ℕ n m))
( leq-fib-add-ℕ n (add-ℕ n (mul-ℕ n m)) (pair (mul-ℕ n m) refl))
least-factor-least-larger-multiple-ℕ :
(d n : ℕ) → (leq-ℕ one-ℕ d) →
minimal-element-ℕ (λ k → leq-ℕ n (mul-ℕ k d))
least-factor-least-larger-multiple-ℕ d n H =
well-ordering-principle-ℕ
( λ k → leq-ℕ n (mul-ℕ k d))
( λ k → is-decidable-leq-ℕ n (mul-ℕ k d))
( pair n (leq-multiple-ℕ n d H))
factor-least-larger-multiple-ℕ :
(d n : ℕ) → (leq-ℕ one-ℕ d) → ℕ
factor-least-larger-multiple-ℕ d n H =
pr1 (least-factor-least-larger-multiple-ℕ d n H)
least-larger-multiple-ℕ :
(d n : ℕ) → (leq-ℕ one-ℕ d) → ℕ
least-larger-multiple-ℕ d n H =
mul-ℕ (factor-least-larger-multiple-ℕ d n H) d
leq-least-larger-multiple-ℕ :
(d n : ℕ) (H : leq-ℕ one-ℕ d) →
leq-ℕ n (least-larger-multiple-ℕ d n H)
leq-least-larger-multiple-ℕ d n H =
pr1 (pr2 (least-factor-least-larger-multiple-ℕ d n H))
is-minimal-least-larger-multiple-ℕ :
(d n : ℕ) (H : leq-ℕ one-ℕ d) (k : ℕ) (K : leq-ℕ n (mul-ℕ k d)) →
leq-ℕ (factor-least-larger-multiple-ℕ d n H) k
is-minimal-least-larger-multiple-ℕ d n H =
pr2 (pr2 (least-factor-least-larger-multiple-ℕ d n H))
-}
{-
is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ :
(d n : ℕ) (H : leq-ℕ one-ℕ d) →
is-decidable (Id (least-larger-multiple-ℕ d n H) n) → is-decidable (div-ℕ d n)
is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ d n H (inl p) =
inl (pair (factor-least-larger-multiple-ℕ d n H) p)
is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ d n H (inr f) =
inr (λ x → {!!})
is-decidable-div-ℕ' :
(d n : ℕ) → (leq-ℕ one-ℕ d) → is-decidable (div-ℕ d n)
is-decidable-div-ℕ' d n H = {!!}
is-decidable-div-ℕ :
(d n : ℕ) → is-decidable (div-ℕ d n)
is-decidable-div-ℕ zero-ℕ zero-ℕ = inl (pair zero-ℕ refl)
is-decidable-div-ℕ zero-ℕ (succ-ℕ n) =
inr ( λ p →
Eq-ℕ-eq {-zero-ℕ (succ-ℕ n)-} ((inv (right-zero-law-mul-ℕ (pr1 p))) ∙ (pr2 p)))
is-decidable-div-ℕ (succ-ℕ d) n =
is-decidable-div-ℕ' (succ-ℕ d) n (leq-zero-ℕ d)
-}
-- Operations on decidable bounded subsets of ℕ
iterated-operation-ℕ :
(strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) (base-value : ℕ) → ℕ
iterated-operation-ℕ zero-ℕ μ e = e
iterated-operation-ℕ (succ-ℕ b) μ e = μ (iterated-operation-ℕ b μ e) b
iterated-sum-ℕ :
(summand : ℕ → ℕ) (b : ℕ) → ℕ
iterated-sum-ℕ f zero-ℕ = zero-ℕ
iterated-sum-ℕ f (succ-ℕ b) = add-ℕ (iterated-sum-ℕ f b) (f (succ-ℕ b))
ranged-sum-ℕ :
(summand : ℕ → ℕ) (l u : ℕ) → ℕ
ranged-sum-ℕ f zero-ℕ u = iterated-sum-ℕ f u
ranged-sum-ℕ f (succ-ℕ l) zero-ℕ = zero-ℕ
ranged-sum-ℕ f (succ-ℕ l) (succ-ℕ u) =
ranged-sum-ℕ (f ∘ succ-ℕ) l u
succ-iterated-operation-fam-ℕ :
{ l : Level}
( P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) →
( predecessor-strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) →
is-decidable (P predecessor-strict-upper-bound) → ℕ → ℕ
succ-iterated-operation-fam-ℕ
P is-decidable-P b μ (inl p) m = μ m b
succ-iterated-operation-fam-ℕ
P is-decidable-P b μ (inr f) m = m
iterated-operation-fam-ℕ :
{ l : Level} (P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) →
( strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) (base-value : ℕ) → ℕ
iterated-operation-fam-ℕ P d zero-ℕ μ e = e
iterated-operation-fam-ℕ P d (succ-ℕ b) μ e =
succ-iterated-operation-fam-ℕ P d b μ (d b)
( iterated-operation-fam-ℕ P d b μ e)
Sum-fam-ℕ :
{ l : Level} (P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) →
( upper-bound : ℕ) ( summand : ℕ → ℕ) → ℕ
Sum-fam-ℕ P d b f = iterated-operation-fam-ℕ P d (succ-ℕ b) (λ x y → add-ℕ x (f y)) zero-ℕ
{-
iterated-operation-fam-ℕ
P is-decidable-P zero-ℕ is-bounded-P μ base-value =
base-value
iterated-operation-fam-ℕ
P is-decidable-P (succ-ℕ b) is-bounded-P μ base-value =
succ-iterated-operation-ℕ P is-decidable-P b is-bounded-P μ
( is-decidable-P b)
( iterated-operation-ℕ
( introduce-bound-on-fam-ℕ b P)
( is-decidable-introduce-bound-on-fam-ℕ b P is-decidable-P)
( b)
( is-bounded-introduce-bound-on-fam-ℕ b P)
( μ)
( base-value))
product-decidable-bounded-fam-ℕ :
{ l : Level} (P : ℕ → UU l) →
( is-decidable-P : (n : ℕ) → is-decidable (P n))
( b : ℕ) ( is-bounded-P : is-bounded-fam-ℕ b P) → ℕ
product-decidable-bounded-fam-ℕ P is-decidable-P b is-bounded-P =
iterated-operation-ℕ P is-decidable-P b is-bounded-P mul-ℕ one-ℕ
twenty-four-ℕ : ℕ
twenty-four-ℕ =
product-decidable-bounded-fam-ℕ
( λ x → le-ℕ x five-ℕ)
( λ x → is-decidable-le-ℕ x five-ℕ)
( five-ℕ)
( λ x → id)
-}
{-
test-zero-twenty-four-ℕ : Id twenty-four-ℕ zero-ℕ
test-zero-twenty-four-ℕ = refl
test-twenty-four-ℕ : Id twenty-four-ℕ (factorial four-ℕ)
test-twenty-four-ℕ = refl
-}
-- Exercises
-- Exercise 10.?
abstract
has-decidable-equality-𝟚 : has-decidable-equality bool
has-decidable-equality-𝟚 true true = inl refl
has-decidable-equality-𝟚 true false = inr (Eq-𝟚-eq true false)
has-decidable-equality-𝟚 false true = inr (Eq-𝟚-eq false true)
has-decidable-equality-𝟚 false false = inl refl
-- Exercise 10.?
abstract
has-decidable-equality-prod' : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
(x x' : A) (y y' : B) → is-decidable (Id x x') → is-decidable (Id y y') →
is-decidable (Id (pair x y) (pair x' y'))
has-decidable-equality-prod' x x' y y' (inl p) (inl q) =
inl (eq-pair-triv (pair p q))
has-decidable-equality-prod' x x' y y' (inl p) (inr g) =
inr (λ h → g (ap pr2 h))
has-decidable-equality-prod' x x' y y' (inr f) (inl q) =
inr (λ h → f (ap pr1 h))
has-decidable-equality-prod' x x' y y' (inr f) (inr g) =
inr (λ h → f (ap pr1 h))
abstract
has-decidable-equality-prod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
has-decidable-equality A → has-decidable-equality B →
has-decidable-equality (A × B)
has-decidable-equality-prod dec-A dec-B (pair x y) (pair x' y') =
has-decidable-equality-prod' x x' y y' (dec-A x x') (dec-B y y')
{-
bounds-fam-ℕ :
{l : Level} (P : ℕ → UU l) → UU l
bounds-fam-ℕ P = Σ ℕ (λ n → is-bounded-fam-ℕ n P)
is-minimal-ℕ :
{l : Level} (P : ℕ → UU l) → Σ ℕ P → UU l
is-minimal-ℕ P (pair n p) = (t : Σ ℕ P) → leq-ℕ n (pr1 t)
fam-succ-ℕ :
{l : Level} → (ℕ → UU l) → (ℕ → UU l)
fam-succ-ℕ P n = P (succ-ℕ n)
is-decidable-fam-succ-ℕ :
{l : Level} (P : ℕ → UU l) →
((n : ℕ) → is-decidable (P n)) → ((n : ℕ) → is-decidable (P (succ-ℕ n)))
is-decidable-fam-succ-ℕ P d n = d (succ-ℕ n)
min-is-bounded-not-zero-ℕ :
{l : Level} (P : ℕ → UU l) → ((n : ℕ) → is-decidable (P n)) →
Σ ℕ (λ n → is-bounded-fam-ℕ n P) →
¬ (P zero-ℕ) →
Σ (Σ ℕ (fam-succ-ℕ P)) (is-minimal-ℕ (fam-succ-ℕ P)) →
Σ (Σ ℕ P) (is-minimal-ℕ P)
min-is-bounded-not-zero-ℕ P d b np0 t = {!!}
min-is-bounded-ℕ :
{l : Level} (P : ℕ → UU l) → ((n : ℕ) → is-decidable (P n)) →
Σ ℕ (λ n → is-bounded-fam-ℕ n P) →
Σ ℕ P → Σ (Σ ℕ P) (is-minimal-ℕ P)
min-is-bounded-ℕ P d (pair zero-ℕ b) t =
pair
( pair
( zero-ℕ)
( tr P (eq-zero-leq-zero-ℕ (pr1 t) (b (pr1 t) (pr2 t))) (pr2 t)))
( λ p → leq-zero-ℕ (pr1 p))
min-is-bounded-ℕ P d (pair (succ-ℕ n) b) t =
ind-coprod
( λ (t : is-decidable (P zero-ℕ)) → Σ (Σ ℕ P) (is-minimal-ℕ P))
( λ p0 → pair (pair zero-ℕ p0) (λ p → leq-zero-ℕ (pr1 p)))
( λ y → min-is-bounded-not-zero-ℕ P d (pair (succ-ℕ n) b) y
( min-is-bounded-ℕ
( fam-succ-ℕ P)
( is-decidable-fam-succ-ℕ P d)
{!!}
{!!}))
( d zero-ℕ)
{- We show that every non-empty decidable subset of ℕ has a least element. -}
least-ℕ :
{l : Level} (P : ℕ → UU l) → Σ ℕ P → UU l
least-ℕ P (pair n p) = (m : ℕ) → P m → leq-ℕ n m
least-element-non-empty-decidable-subset-ℕ :
{l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n)) →
Σ ℕ P → Σ (Σ ℕ P) (least-ℕ P)
least-element-non-empty-decidable-subset-ℕ P d (pair zero-ℕ p) =
pair (pair zero-ℕ p) {!!}
least-element-non-empty-decidable-subset-ℕ P d (pair (succ-ℕ n) p) = {!!}
-}
{-
zero-Fin :
(n : ℕ) → Fin (succ-ℕ n)
zero-Fin zero-ℕ = inr star
zero-Fin (succ-ℕ n) = inl (zero-Fin n)
succ-Fin :
(n : ℕ) → Fin n → Fin n
succ-Fin (succ-ℕ n) (inr star) = zero-Fin n
succ-Fin (succ-ℕ (succ-ℕ n)) (inl (inl x)) = inl (succ-Fin (succ-ℕ n) (inl x))
succ-Fin (succ-ℕ (succ-ℕ n)) (inl (inr star)) = inr star
iterated-succ-Fin :
(k : ℕ) → (n : ℕ) → Fin n → Fin n
iterated-succ-Fin zero-ℕ n = id
iterated-succ-Fin (succ-ℕ k) n = (succ-Fin n) ∘ (iterated-succ-Fin k n)
quotient-ℕ-Fin :
(n : ℕ) → Fin (succ-ℕ n)
quotient-ℕ-Fin n = iterated-succ-Fin n (succ-ℕ n) (zero-Fin n)
pred-Fin :
(n : ℕ) → Fin n → Fin n
pred-Fin (succ-ℕ zero-ℕ) (inr star) = inr star
pred-Fin (succ-ℕ (succ-ℕ n)) (inl x) = {!!}
pred-Fin (succ-ℕ (succ-ℕ n)) (inr star) = inl (inr star)
add-Fin :
(n : ℕ) → Fin n → Fin n → Fin n
add-Fin (succ-ℕ n) (inl x) j = {!!}
add-Fin (succ-ℕ n) (inr x) j = {!!}
idempotent-succ-Fin :
(n : ℕ) (i : Fin n) → Id (iterated-succ-Fin n n i) i
idempotent-succ-Fin (succ-ℕ zero-ℕ) (inr star) = refl
idempotent-succ-Fin (succ-ℕ (succ-ℕ n)) (inl x) = {!!}
idempotent-succ-Fin (succ-ℕ (succ-ℕ n)) (inr x) = {!!}
-}
in-nat-ℤ : ℕ → ℤ
in-nat-ℤ zero-ℕ = zero-ℤ
in-nat-ℤ (succ-ℕ n) = in-pos n
div-ℤ :
(k l : ℤ) → UU lzero
div-ℤ k l = Σ ℤ (λ x → Id (mul-ℤ x k) l)
-- _≡_mod_ :
-- (k l : ℤ) (n : ℕ) → UU lzero
-- k ≡ l mod n = div-ℤ (in-nat-ℤ n) (add-ℤ k (neg-ℤ l))
-- From before
is-even-ℕ : ℕ → UU lzero
is-even-ℕ n = div-ℕ two-ℕ n
is-prime : ℕ → UU lzero
is-prime n = (one-ℕ < n) × ((m : ℕ) → (one-ℕ < m) → (div-ℕ m n) → Id m n)
{- The Goldbach conjecture asserts that every even number above 2 is the sum
of two primes. -}
Goldbach-conjecture : UU lzero
Goldbach-conjecture =
( n : ℕ) → (two-ℕ < n) → (is-even-ℕ n) →
Σ ℕ (λ p → (is-prime p) × (Σ ℕ (λ q → (is-prime q) × Id (add-ℕ p q) n)))
is-twin-prime : ℕ → UU lzero
is-twin-prime n = (is-prime n) × (is-prime (succ-ℕ (succ-ℕ n)))
{- The twin prime conjecture asserts that there are infinitely many twin
primes. We assert that there are infinitely twin primes by asserting that
for every n : ℕ there is a twin prime that is larger than n. -}
Twin-prime-conjecture : UU lzero
Twin-prime-conjecture = (n : ℕ) → Σ ℕ (λ p → (is-twin-prime p) × (leq-ℕ n p))
-- Exercise
unit-classical-Prop : classical-Prop lzero
unit-classical-Prop =
pair unit-Prop (inl star)
raise-unit-classical-Prop :
(l : Level) → classical-Prop l
raise-unit-classical-Prop l =
pair
( pair
( raise l unit)
( is-prop-is-equiv' unit
( map-raise)
( is-equiv-map-raise l unit)
( is-prop-unit)))
( inl (map-raise star))
bool-classical-Prop :
(l : Level) → classical-Prop l → bool
bool-classical-Prop l (pair P (inl x)) = true
bool-classical-Prop l (pair P (inr x)) = false
{-
classical-Prop-bool :
(l : Level) → bool → classical-Prop l
classical-Prop-bool l true = raise-unit-classical-Prop l
classical-Prop-bool l false = {!!}
-}
| {
"alphanum_fraction": 0.5802455481,
"avg_line_length": 32.996350365,
"ext": "agda",
"hexsha": "56f0f95458252dab632ea1aa54b5acb5a79a928e",
"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": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "tmoux/HoTT-Intro",
"max_forks_repo_path": "Agda/17-number-theory.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "tmoux/HoTT-Intro",
"max_issues_repo_path": "Agda/17-number-theory.agda",
"max_line_length": 103,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "tmoux/HoTT-Intro",
"max_stars_repo_path": "Agda/17-number-theory.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 20000,
"size": 45205
} |
-- Check that the termination checker can handle recursive
-- calls on subterms which aren't simply variables.
module SubtermTermination where
data N : Set where
zero : N
suc : N → N
f : N → N
f (suc zero) = f zero
f _ = zero
data One? : N → Set where
one : One? (suc zero)
other : ∀ {n} → One? n
-- Should work for dot patterns as well
f′ : (n : N) → One? n → N
f′ (suc .zero) one = f′ zero other
f′ _ _ = zero
f″ : (n : N) → One? n → N
f″ ._ one = f″ zero other
f″ _ _ = zero
data D : Set where
c₁ : D
c₂ : D → D
c₃ : D → D → D
g : D → D
g (c₃ (c₂ x) y) = g (c₂ x)
g _ = c₁
{- Andreas, 2011-07-07 subterm is not complete
does not work with postulates or definitions
postulate
i : {A : Set} → A → A
data NAT : N → Set where
Zero : NAT zero
Suc : ∀ n → NAT (i n) → NAT (suc (i n))
h : (n : N) -> NAT n -> Set
h .zero Zero = N
h .(suc (i n)) (Suc n m) = h (i n) (i m)
-} | {
"alphanum_fraction": 0.5479009688,
"avg_line_length": 19.3541666667,
"ext": "agda",
"hexsha": "3f164b5bfb32e52dbc254cd987d768299444c441",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/SubtermTermination.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/SubtermTermination.agda",
"max_line_length": 58,
"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/SubtermTermination.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": 367,
"size": 929
} |
------------------------------------------------------------------------------
-- The paradoxical combinator
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- See (Barendregt 2004, corollary 6.1.3).
module FOT.LTC-PCF.Y where
open import LTC-PCF.Base hiding ( fix ; fix-eq )
------------------------------------------------------------------------------
-- This is the fixed-point combinator used by (Dybjer 1985).
Y : D
Y = lam (λ f → lam (λ x → f · (x · x)) · lam (λ x → f · (x · x)))
-- We define a higher-order Y.
Y₁ : (D → D) → D
Y₁ f = Y · lam f
------------------------------------------------------------------------------
-- References
--
-- Barendregt, Henk (2004). The Lambda Calculus. Its Syntax and
-- Semantics. 2nd ed. Vol. 103. Studies in Logic and the Foundations
-- of Mathematics. 6th impression. Elsevier.
--
-- Dybjer, Peter (1985). Program Verification in a Logical Theory of
-- Constructions. In: Functional Programming Languages and Computer
-- Architecture. Ed. by Jouannaud,
-- Jean-Pierre. Vol. 201. LNCS. Appears in revised form as Programming
-- Methodology Group Report 26, University of Gothenburg and Chalmers
-- University of Technology, June 1986. Springer, pp. 334–349 (cit. on
-- p. 26).
| {
"alphanum_fraction": 0.5087108014,
"avg_line_length": 36.7948717949,
"ext": "agda",
"hexsha": "4e8ecf4dfde645764d739d342414e8decb64e4ef",
"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/FOT/LTC-PCF/Y.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/FOT/LTC-PCF/Y.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/FOT/LTC-PCF/Y.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": 342,
"size": 1435
} |
{-# OPTIONS --cubical --safe #-}
module Data.Vec.Inductive where
open import Prelude
open import Data.List using (List; _∷_; []; length)
private
variable
n m : ℕ
infixr 5 _∷_
data Vec (A : Type a) : ℕ → Type a where
[] : Vec A 0
_∷_ : A → Vec A n → Vec A (suc n)
foldr : ∀ {p} (P : ℕ → Type p) →
(∀ {n} → A → P n → P (suc n)) →
P zero →
Vec A n → P n
foldr P f b [] = b
foldr P f b (x ∷ xs) = f x (foldr P f b xs)
foldl : ∀ {p} (P : ℕ → Type p) →
(∀ {n} → A → P n → P (suc n)) →
P zero →
Vec A n → P n
foldl P f b [] = b
foldl P f b (x ∷ xs) = foldl (P ∘ suc) f (f x b) xs
foldr′ : (A → B → B) → B → Vec A n → B
foldr′ f = foldr (const _) (λ x xs → f x xs)
foldl′ : (A → B → B) → B → Vec A n → B
foldl′ f = foldl (const _) (λ x xs → f x xs)
vecFromList : (xs : List A) → Vec A (length xs)
vecFromList [] = []
vecFromList (x ∷ xs) = x ∷ vecFromList xs
vecToList : Vec A n → List A
vecToList [] = []
vecToList (x ∷ xs) = x ∷ vecToList xs
| {
"alphanum_fraction": 0.4970472441,
"avg_line_length": 23.0909090909,
"ext": "agda",
"hexsha": "775d57e4848f4e1f838acc14adbb46e1430957e3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Vec/Inductive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Vec/Inductive.agda",
"max_line_length": 51,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Vec/Inductive.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": 417,
"size": 1016
} |
{-
Finitely presented algebras.
An R-algebra A is finitely presented, if there merely is an exact sequence
of R-modules:
(f₁,⋯,fₘ) → R[X₁,⋯,Xₙ] → A → 0
(where f₁,⋯,fₘ ∈ R[X₁,⋯,Xₙ])
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.FPAlgebra where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Data.FinData
open import Cubical.Data.Nat
open import Cubical.Data.Vec
open import Cubical.Data.Sigma
open import Cubical.Data.Empty
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.FGIdeal using (inclOfFGIdeal)
open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.CommAlgebra.FreeCommAlgebra
renaming (inducedHom to freeInducedHom)
open import Cubical.Algebra.CommAlgebra.QuotientAlgebra
renaming (inducedHom to quotientInducedHom)
open import Cubical.Algebra.CommAlgebra.Ideal
open import Cubical.Algebra.CommAlgebra.FGIdeal
open import Cubical.Algebra.CommAlgebra.Instances.Initial
open import Cubical.Algebra.CommAlgebra.Instances.Unit
renaming (UnitCommAlgebra to TerminalCAlg)
open import Cubical.Algebra.CommAlgebra.Kernel
open import Cubical.Algebra.Algebra.Properties
open import Cubical.Algebra.Algebra
private
variable
ℓ : Level
module _ {R : CommRing ℓ} where
open Construction using (var)
Polynomials : (n : ℕ) → CommAlgebra R ℓ
Polynomials n = R [ Fin n ]
evPoly : {n : ℕ} (A : CommAlgebra R ℓ) → ⟨ Polynomials n ⟩ → FinVec ⟨ A ⟩ n → ⟨ A ⟩
evPoly A P values = fst (freeInducedHom A values) P
evPolyPoly : {n : ℕ} (P : ⟨ Polynomials n ⟩) → evPoly (Polynomials n) P var ≡ P
evPolyPoly {n = n} P = cong (λ u → fst u P) (inducedHomVar R (Fin n))
evPolyHomomorphic : {n : ℕ} (A B : CommAlgebra R ℓ) (f : CommAlgebraHom A B)
→ (P : ⟨ Polynomials n ⟩) → (values : FinVec ⟨ A ⟩ n)
→ (fst f) (evPoly A P values) ≡ evPoly B P (fst f ∘ values)
evPolyHomomorphic A B f P values =
(fst f) (evPoly A P values) ≡⟨ refl ⟩
(fst f) (fst (freeInducedHom A values) P) ≡⟨ refl ⟩
fst (f ∘a freeInducedHom A values) P ≡⟨ cong (λ u → fst u P) (natIndHomR f values) ⟩
fst (freeInducedHom B (fst f ∘ values)) P ≡⟨ refl ⟩
evPoly B P (fst f ∘ values) ∎
where open AlgebraHoms
module _ {m : ℕ} (n : ℕ) (relation : FinVec ⟨ Polynomials n ⟩ m) where
open CommAlgebraStr using (0a)
open Cubical.Algebra.Algebra.Properties.AlgebraHoms
relationsIdeal = generatedIdeal (Polynomials n) relation
abstract
{-
The following definitions are abstract because of type checking speed
problems - complete unfolding of FPAlgebra is triggered otherwise.
This also means, the where blocks contain more type declarations than usual.
-}
FPAlgebra : CommAlgebra R ℓ
FPAlgebra = Polynomials n / relationsIdeal
modRelations : CommAlgebraHom (Polynomials n) (Polynomials n / relationsIdeal)
modRelations = quotientHom (Polynomials n) relationsIdeal
generator : (i : Fin n) → ⟨ FPAlgebra ⟩
generator = fst modRelations ∘ var
relationsHold : (i : Fin m) → evPoly FPAlgebra (relation i) generator ≡ 0a (snd FPAlgebra)
relationsHold i =
evPoly FPAlgebra (relation i) generator
≡⟨ sym (evPolyHomomorphic (Polynomials n) FPAlgebra modRelations (relation i) var) ⟩
fst modRelations (evPoly (Polynomials n) (relation i) var)
≡⟨ cong (λ u → fst modRelations u) (evPolyPoly (relation i)) ⟩
fst modRelations (relation i)
≡⟨ isZeroFromIdeal {R = R}
{A = (Polynomials n)}
{I = relationsIdeal}
(relation i)
(incInIdeal (Polynomials n) relation i ) ⟩
0a (snd FPAlgebra) ∎
inducedHom :
(A : CommAlgebra R ℓ)
(values : FinVec ⟨ A ⟩ n)
(relationsHold : (i : Fin m) → evPoly A (relation i) values ≡ 0a (snd A))
→ CommAlgebraHom FPAlgebra A
inducedHom A values relationsHold =
quotientInducedHom
(Polynomials n)
relationsIdeal
A
freeHom
isInKernel
where
freeHom : CommAlgebraHom (Polynomials n) A
freeHom = freeInducedHom A values
isInKernel : fst (generatedIdeal (Polynomials n) relation)
⊆ fst (kernel (Polynomials n) A freeHom)
isInKernel = inclOfFGIdeal
(CommAlgebra→CommRing (Polynomials n))
relation
(kernel (Polynomials n) A freeHom)
relationsHold
inducedHomOnGenerators :
(A : CommAlgebra R ℓ)
(values : FinVec ⟨ A ⟩ n)
(relationsHold : (i : Fin m) → evPoly A (relation i) values ≡ 0a (snd A))
(i : Fin n)
→ fst (inducedHom A values relationsHold) (generator i) ≡ values i
inducedHomOnGenerators _ _ _ _ = refl
unique :
{A : CommAlgebra R ℓ}
(values : FinVec ⟨ A ⟩ n)
(relationsHold : (i : Fin m) → evPoly A (relation i) values ≡ 0a (snd A))
(f : CommAlgebraHom FPAlgebra A)
→ ((i : Fin n) → fst f (generator i) ≡ values i)
→ inducedHom A values relationsHold ≡ f
unique {A = A} values relationsHold f hasCorrectValues =
injectivePrecomp
(Polynomials n)
relationsIdeal
A
(inducedHom A values relationsHold)
f
(sym (
f' ≡⟨ sym (inv f') ⟩
freeInducedHom A (evaluateAt A f') ≡⟨ cong (freeInducedHom A)
(funExt hasCorrectValues) ⟩
freeInducedHom A values ≡⟨ cong (freeInducedHom A) refl ⟩
freeInducedHom A (evaluateAt A iHom') ≡⟨ inv iHom' ⟩
iHom' ∎))
where
{-
Poly n
| \
modRelations f'
↓ ↘
FPAlgebra ─f→ A
-}
f' iHom' : CommAlgebraHom (Polynomials n) A
f' = compAlgebraHom modRelations f
iHom' = compAlgebraHom modRelations (inducedHom A values relationsHold)
inv : retract (Iso.fun (homMapIso {I = Fin n} A)) (Iso.inv (homMapIso A))
inv = Iso.leftInv (homMapIso {R = R} {I = Fin n} A)
universal :
(A : CommAlgebra R ℓ)
(values : FinVec ⟨ A ⟩ n)
(relationsHold : (i : Fin m) → evPoly A (relation i) values ≡ 0a (snd A))
→ isContr (Σ[ f ∈ CommAlgebraHom FPAlgebra A ] ((i : Fin n) → fst f (generator i) ≡ values i))
universal A values relationsHold =
( (inducedHom A values relationsHold)
, (inducedHomOnGenerators A values relationsHold) )
, λ {(f , mapsValues)
→ Σ≡Prop (λ _ → isPropΠ (λ _ → isSetCommAlgebra A _ _))
(unique values relationsHold f mapsValues)}
{- ∀ A : Comm-R-Algebra,
∀ J : Finitely-generated-Ideal,
Hom(R[I]/J,A) is isomorphic to the Set of roots of the generators of J
-}
zeroLocus : (A : CommAlgebra R ℓ) → Type ℓ
zeroLocus A = Σ[ v ∈ FinVec ⟨ A ⟩ n ] ((i : Fin m) → evPoly A (relation i) v ≡ 0a (snd A))
inducedHomFP : (A : CommAlgebra R ℓ) →
zeroLocus A → CommAlgebraHom FPAlgebra A
inducedHomFP A d = inducedHom A (fst d) (snd d)
evaluateAtFP : {A : CommAlgebra R ℓ} →
CommAlgebraHom FPAlgebra A → zeroLocus A
evaluateAtFP {A} f = value ,
λ i → evPoly A (relation i) value ≡⟨ step1 (relation i) ⟩
fst compHom (evPoly (Polynomials n) (relation i) var) ≡⟨ refl ⟩
(fst f) ((fst modRelations)
(evPoly (Polynomials n) (relation i) var)) ≡⟨ cong
(fst f)
(evPolyHomomorphic
(Polynomials n)
FPAlgebra
modRelations
(relation i) var) ⟩
(fst f) (evPoly FPAlgebra (relation i) generator) ≡⟨ cong (fst f) (relationsHold i) ⟩
(fst f) (0a (snd FPAlgebra)) ≡⟨ IsAlgebraHom.pres0 (snd f) ⟩
0a (snd A) ∎
where
compHom : CommAlgebraHom (Polynomials n) A
compHom = CommAlgebraHoms.compCommAlgebraHom (Polynomials n) FPAlgebra A modRelations f
value : FinVec ⟨ A ⟩ n
value = (Iso.fun (homMapIso A)) compHom
step1 : (x : ⟨ Polynomials n ⟩) → evPoly A x value ≡ fst compHom (evPoly (Polynomials n) x var)
step1 x = sym (evPolyHomomorphic (Polynomials n) A compHom x var)
FPHomIso : {A : CommAlgebra R ℓ} →
Iso (CommAlgebraHom FPAlgebra A) (zeroLocus A)
Iso.fun FPHomIso = evaluateAtFP
Iso.inv FPHomIso = inducedHomFP _
Iso.rightInv (FPHomIso {A}) =
λ b → Σ≡Prop
(λ x → isPropΠ
(λ i → isSetCommAlgebra A
(evPoly A (relation i) x)
(0a (snd A))))
refl
Iso.leftInv (FPHomIso {A}) =
λ a → Σ≡Prop (λ f → isPropIsCommAlgebraHom {ℓ} {R} {ℓ} {ℓ} {FPAlgebra} {A} f)
λ i → fst (unique {A}
(fst (evaluateAtFP {A} a))
(snd (evaluateAtFP a))
a
(λ j → refl)
i)
homMapPathFP : (A : CommAlgebra R ℓ)→ CommAlgebraHom FPAlgebra A ≡ zeroLocus A
homMapPathFP A = isoToPath (FPHomIso {A})
isSetZeroLocus : (A : CommAlgebra R ℓ) → isSet (zeroLocus A)
isSetZeroLocus A = J (λ y _ → isSet y)
(isSetAlgebraHom (CommAlgebra→Algebra FPAlgebra) (CommAlgebra→Algebra A))
(homMapPathFP A)
record FinitePresentation (A : CommAlgebra R ℓ) : Type ℓ where
field
n : ℕ
m : ℕ
relations : FinVec ⟨ Polynomials n ⟩ m
equiv : CommAlgebraEquiv (FPAlgebra n relations) A
isFPAlgebra : (A : CommAlgebra R ℓ) → Type _
isFPAlgebra A = ∥ FinitePresentation A ∥₁
isFPAlgebraIsProp : {A : CommAlgebra R ℓ} → isProp (isFPAlgebra A)
isFPAlgebraIsProp = isPropPropTrunc
module Instances (R : CommRing ℓ) where
open FinitePresentation
{- Every (multivariate) polynomial algebra is finitely presented -}
module _ (n : ℕ) where
private
A : CommAlgebra R ℓ
A = Polynomials n
emptyGen : FinVec (fst A) 0
emptyGen = λ ()
B : CommAlgebra R ℓ
B = FPAlgebra n emptyGen
polynomialAlgFP : FinitePresentation A
FinitePresentation.n polynomialAlgFP = n
m polynomialAlgFP = 0
relations polynomialAlgFP = emptyGen
equiv polynomialAlgFP =
-- Idea: A and B enjoy the same universal property.
toAAsEquiv , snd toA
where
toA : CommAlgebraHom B A
toA = inducedHom n emptyGen A Construction.var (λ ())
fromA : CommAlgebraHom A B
fromA = freeInducedHom B (generator _ _)
open AlgebraHoms
inverse1 : fromA ∘a toA ≡ idAlgebraHom _
inverse1 =
fromA ∘a toA
≡⟨ sym (unique _ _ _ _ _ (λ i → cong (fst fromA) (
fst toA (generator n emptyGen i)
≡⟨ inducedHomOnGenerators _ _ _ _ _ _ ⟩
Construction.var i
∎))) ⟩
inducedHom n emptyGen B (generator _ _) (relationsHold _ _)
≡⟨ unique _ _ _ _ _ (λ i → refl) ⟩
idAlgebraHom _
∎
inverse2 : toA ∘a fromA ≡ idAlgebraHom _
inverse2 = isoFunInjective (homMapIso A) _ _ (
evaluateAt A (toA ∘a fromA) ≡⟨ sym (naturalEvR {A = B} {B = A} toA fromA) ⟩
fst toA ∘ evaluateAt B fromA ≡⟨ refl ⟩
fst toA ∘ generator _ _ ≡⟨ funExt (inducedHomOnGenerators _ _ _ _ _)⟩
Construction.var ∎)
toAAsEquiv : ⟨ B ⟩ ≃ ⟨ A ⟩
toAAsEquiv = isoToEquiv (iso (fst toA)
(fst fromA)
(λ a i → fst (inverse2 i) a)
(λ b i → fst (inverse1 i) b))
{- The initial R-algebra is finitely presented -}
private
R[⊥] : CommAlgebra R ℓ
R[⊥] = Polynomials 0
emptyGen : FinVec (fst R[⊥]) 0
emptyGen = λ ()
R[⊥]/⟨0⟩ : CommAlgebra R ℓ
R[⊥]/⟨0⟩ = FPAlgebra 0 emptyGen
R[⊥]/⟨0⟩IsInitial : (B : CommAlgebra R ℓ)
→ isContr (CommAlgebraHom R[⊥]/⟨0⟩ B)
R[⊥]/⟨0⟩IsInitial B = iHom , uniqueness
where
iHom : CommAlgebraHom R[⊥]/⟨0⟩ B
iHom = inducedHom 0 emptyGen B (λ ()) (λ ())
uniqueness : (f : CommAlgebraHom R[⊥]/⟨0⟩ B) →
iHom ≡ f
uniqueness f = unique 0 emptyGen {A = B} (λ ()) (λ ()) f (λ ())
initialCAlgFP : FinitePresentation (initialCAlg R)
n initialCAlgFP = 0
m initialCAlgFP = 0
relations initialCAlgFP = emptyGen
equiv initialCAlgFP =
equivByInitiality R R[⊥]/⟨0⟩ R[⊥]/⟨0⟩IsInitial
{- The terminal R-algebra is finitely presented -}
private
unitGen : FinVec (fst R[⊥]) 1
unitGen zero = 1a
where open CommAlgebraStr (snd R[⊥])
R[⊥]/⟨1⟩ : CommAlgebra R ℓ
R[⊥]/⟨1⟩ = FPAlgebra 0 unitGen
terminalCAlgFP : FinitePresentation (TerminalCAlg R)
n terminalCAlgFP = 0
m terminalCAlgFP = 1
relations terminalCAlgFP = unitGen
equiv terminalCAlgFP = equivFrom1≡0 R R[⊥]/⟨1⟩
(sym (⋆-lid 1a) ∙ relationsHold 0 unitGen zero)
where open CommAlgebraStr (snd R[⊥]/⟨1⟩)
{-
Quotients of the base ring by principal ideals are finitely presented.
-}
module _ (x : ⟨ R ⟩) where
⟨x⟩ : IdealsIn (initialCAlg R)
⟨x⟩ = generatedIdeal (initialCAlg R) (replicateFinVec 1 x)
R/⟨x⟩ = (initialCAlg R) / ⟨x⟩
open CommAlgebraStr ⦃...⦄
private
relation : FinVec ⟨ Polynomials {R = R} 0 ⟩ 1
relation = replicateFinVec 1 (Construction.const x)
B = FPAlgebra 0 relation
π = quotientHom (initialCAlg R) ⟨x⟩
instance
_ = snd R/⟨x⟩
_ = snd (initialCAlg R)
_ = snd B
πx≡0 : π $a x ≡ 0a
πx≡0 = isZeroFromIdeal {A = initialCAlg R} {I = ⟨x⟩} x
(incInIdeal (initialCAlg R) (replicateFinVec 1 x) zero)
R/⟨x⟩FP : FinitePresentation R/⟨x⟩
n R/⟨x⟩FP = 0
m R/⟨x⟩FP = 1
relations R/⟨x⟩FP = relation
equiv R/⟨x⟩FP = (isoToEquiv (iso (fst toA) (fst fromA)
(λ a i → toFrom i $a a)
λ a i → fromTo i $a a))
, (snd toA)
where
toA : CommAlgebraHom B R/⟨x⟩
toA = inducedHom 0 relation R/⟨x⟩ (λ ()) relation-holds
where
vals : FinVec ⟨ R/⟨x⟩ ⟩ 0
vals ()
vals' : FinVec ⟨ initialCAlg R ⟩ 0
vals' ()
relation-holds = λ zero →
evPoly R/⟨x⟩ (relation zero) (λ ()) ≡⟨ sym
(evPolyHomomorphic
(initialCAlg R)
R/⟨x⟩
π
(Construction.const x)
vals') ⟩
π $a (evPoly (initialCAlg R)
(Construction.const x)
vals') ≡⟨ cong (π $a_) (·Rid x) ⟩
π $a x ≡⟨ πx≡0 ⟩
0a ∎
{-
R ─→ R/⟨x⟩
id↓ ↓ ∃!
R ─→ R[⊥]/⟨const x⟩
-}
fromA : CommAlgebraHom R/⟨x⟩ B
fromA =
quotientInducedHom
(initialCAlg R)
⟨x⟩
B
(initialMap R B)
(inclOfFGIdeal
(CommAlgebra→CommRing (initialCAlg R))
(replicateFinVec 1 x)
(kernel (initialCAlg R) B (initialMap R B))
λ {Fin.zero → relationsHold 0 relation Fin.zero})
open AlgebraHoms
fromTo : fromA ∘a toA ≡ idCAlgHom B
fromTo = cong fst
(isContr→isProp (universal 0 relation B (λ ()) (relationsHold 0 relation))
(fromA ∘a toA , (λ ()))
(idCAlgHom B , (λ ())))
toFrom : toA ∘a fromA ≡ idCAlgHom R/⟨x⟩
toFrom = injectivePrecomp (initialCAlg R) ⟨x⟩ R/⟨x⟩ (toA ∘a fromA) (idCAlgHom R/⟨x⟩)
(isContr→isProp (initialityContr R R/⟨x⟩) _ _)
| {
"alphanum_fraction": 0.530116339,
"avg_line_length": 39.2112359551,
"ext": "agda",
"hexsha": "70c4c995307b49715c40bd23baf3a07ad482f353",
"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": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "gmagaf/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommAlgebra/FPAlgebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"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": "gmagaf/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommAlgebra/FPAlgebra.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "gmagaf/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommAlgebra/FPAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5185,
"size": 17449
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.