Search is not available for this dataset
text
string | meta
dict |
---|---|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of rose trees
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Data.Tree.Rose.Properties where
open import Level using (Level)
open import Size
open import Data.List.Base as List using (List)
open import Data.List.Extrema.Nat
import Data.List.Properties as Listₚ
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Tree.Rose
open import Function.Base
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
private
variable
a b c : Level
A : Set a
B : Set b
C : Set c
i : Size
------------------------------------------------------------------------
-- map properties
map-compose : (f : A → B) (g : B → C) →
map {i = i} (g ∘′ f) ≗ map {i = i} g ∘′ map {i = i} f
map-compose f g (node a ts) = cong (node (g (f a))) $ begin
List.map (map (g ∘′ f)) ts ≡⟨ Listₚ.map-cong (map-compose f g) ts ⟩
List.map (map g ∘ map f) ts ≡⟨ Listₚ.map-compose ts ⟩
List.map (map g) (List.map (map f) ts) ∎
depth-map : (f : A → B) (t : Rose A i) → depth {i = i} (map {i = i} f t) ≡ depth {i = i} t
depth-map f (node a ts) = cong (suc ∘′ max 0) $ begin
List.map depth (List.map (map f) ts) ≡˘⟨ Listₚ.map-compose ts ⟩
List.map (depth ∘′ map f) ts ≡⟨ Listₚ.map-cong (depth-map f) ts ⟩
List.map depth ts ∎
------------------------------------------------------------------------
-- foldr properties
foldr-map : (f : A → B) (n : B → List C → C) (ts : Rose A i) →
foldr {i = i} n (map {i = i} f ts) ≡ foldr {i = i} (n ∘′ f) ts
foldr-map f n (node a ts) = cong (n (f a)) $ begin
List.map (foldr n) (List.map (map f) ts) ≡˘⟨ Listₚ.map-compose ts ⟩
List.map (foldr n ∘′ map f) ts ≡⟨ Listₚ.map-cong (foldr-map f n) ts ⟩
List.map (foldr (n ∘′ f)) ts ∎
| {
"alphanum_fraction": 0.4921279837,
"avg_line_length": 35.8,
"ext": "agda",
"hexsha": "6a77f0dfba4db2f76d71aa94ac318791226d1916",
"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/Tree/Rose/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Tree/Rose/Properties.agda",
"max_line_length": 90,
"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/Tree/Rose/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 633,
"size": 1969
} |
module Day2 where
open import Data.String as String
open import Data.Maybe
open import Foreign.Haskell using (Unit)
open import Data.List as List hiding (fromMaybe)
open import Data.Nat
open import Data.Nat.DivMod
import Data.Nat.Show as ℕs
open import Data.Char
open import Data.Vec as Vec renaming (_>>=_ to _VV=_ ; toList to VecToList)
open import Data.Product
open import Relation.Nullary
open import Data.Nat.Properties
open import Data.Bool.Base
open import AocIO
open import AocUtil
open import AocVec
import Data.Fin as Fin
natDiff : ℕ → ℕ → ℕ
natDiff zero y = y
natDiff x zero = x
natDiff (suc x) (suc y) = natDiff x y
fromMaybe : ∀ {a} {A : Set a} → A → Maybe A → A
fromMaybe v (just x) = x
fromMaybe v nothing = v
find : ∀ {a} {A : Set a} → (A → Bool) → List A → Maybe A
find pred [] = nothing
find pred (x ∷ ls) with (pred x)
... | false = find pred ls
... | true = just x
dividesEvenly : ℕ → ℕ → Bool
dividesEvenly zero zero = true
dividesEvenly zero dividend = false
dividesEvenly (suc divisor) dividend with (dividend mod (suc divisor))
... | Fin.Fin.zero = true
... | Fin.Fin.suc p = false
oneDividesTheOther : ℕ → ℕ → Bool
oneDividesTheOther x y = dividesEvenly x y ∨ dividesEvenly y x
main2 : IO Unit
main2 = mainBuilder (readFileMain processFile)
where
parseLine : List Char → List ℕ
parseLine ls with (words ls)
... | line-words = List.map unsafeParseNat line-words
minMax : {n : ℕ} → Vec ℕ (suc n) → (ℕ × ℕ)
minMax {0} (x ∷ []) = x , x
minMax {suc _} (x ∷ ls) with (minMax ls)
... | min , max = (min ⊓ x) , (max ⊔ x)
minMaxDiff : List ℕ → ℕ
minMaxDiff ls = helper (Vec.fromList ls)
where
helper : {n : ℕ} → Vec ℕ n → ℕ
helper [] = 0
helper (x ∷ vec) with (minMax (x ∷ vec))
... | min , max = natDiff min max
lineDiff : List Char → ℕ
lineDiff s = minMaxDiff (parseLine s)
processFile : String → IO Unit
processFile file-content with (lines (String.toList file-content))
... | file-lines with (List.map lineDiff file-lines)
... | line-diffs = printString (ℕs.show (List.sum line-diffs))
main : IO Unit
main = mainBuilder (readFileMain processFile)
where
parseLine : List Char → List ℕ
parseLine ls with (words ls)
... | line-words = List.map unsafeParseNat line-words
pierreDiv : ℕ → ℕ → ℕ
pierreDiv x y with (x ⊓ y) | (x ⊔ y)
... | 0 | _ = 0
... | _ | 0 = 0
... | (suc min) | (suc max) = (suc max) div (suc min)
lineDivider : List ℕ → Maybe ℕ
lineDivider [] = nothing
lineDivider (x ∷ ln) with (find (oneDividesTheOther x) ln)
... | nothing = lineDivider ln
... | just y = just (pierreDiv x y)
lineScore : List Char → ℕ
lineScore s = fromMaybe 0 (lineDivider (parseLine s))
processFile : String → IO Unit
processFile file-content with (lines (String.toList file-content))
... | file-lines with (List.map lineScore file-lines)
... | line-scores = printString (ℕs.show (List.sum line-scores))
| {
"alphanum_fraction": 0.6426666667,
"avg_line_length": 31.914893617,
"ext": "agda",
"hexsha": "208559bf1a06527e041f035161d9fc69385358c9",
"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": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/adventofcode2017",
"max_forks_repo_path": "day-2/Day2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zalastax/adventofcode2017",
"max_issues_repo_path": "day-2/Day2.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/adventofcode2017",
"max_stars_repo_path": "day-2/Day2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 951,
"size": 3000
} |
module OlderBasicILP.Indirect where
open import Common.Context public
-- Propositions of intuitionistic logic of proofs, without ∨, ⊥, or +.
infixr 10 _⦂_
infixl 9 _∧_
infixr 7 _▻_
data Ty (X : Set) : Set where
α_ : Atom → Ty X
_▻_ : Ty X → Ty X → Ty X
_⦂_ : X → Ty X → Ty X
_∧_ : Ty X → Ty X → Ty X
⊤ : Ty X
module _ {X : Set} where
infix 7 _▻◅_
_▻◅_ : Ty X → Ty X → Ty X
A ▻◅ B = (A ▻ B) ∧ (B ▻ A)
-- Additional useful propositions.
_⦂⋆_ : ∀ {n} → VCx X n → VCx (Ty X) n → Cx (Ty X)
∅ ⦂⋆ ∅ = ∅
(TS , T) ⦂⋆ (Ξ , A) = (TS ⦂⋆ Ξ) , (T ⦂ A)
| {
"alphanum_fraction": 0.5111111111,
"avg_line_length": 20.1724137931,
"ext": "agda",
"hexsha": "a5b0b39d6143a1d69d79c99a3aa42906c493f227",
"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": "OlderBasicILP/Indirect.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": "OlderBasicILP/Indirect.agda",
"max_line_length": 70,
"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": "OlderBasicILP/Indirect.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": 283,
"size": 585
} |
------------------------------------------------------------------------------
-- Group theory properties using Agsy
------------------------------------------------------------------------------
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Tested with the development version of the Agda standard library on
-- 02 February 2012.
module Agsy.GroupTheory where
open import Data.Product
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
infix 8 _⁻¹
infixl 7 _·_
------------------------------------------------------------------------------
-- Group theory axioms
postulate
G : Set -- The universe.
ε : G -- The identity element.
_·_ : G → G → G -- The binary operation.
_⁻¹ : G → G -- The inverse function.
assoc : ∀ x y z → x · y · z ≡ x · (y · z)
leftIdentity : ∀ x → ε · x ≡ x
rightIdentity : ∀ x → x · ε ≡ x
leftInverse : ∀ x → x ⁻¹ · x ≡ ε
rightInverse : ∀ x → x · x ⁻¹ ≡ ε
-- Properties
y≡x⁻¹[xy] : ∀ a b → b ≡ a ⁻¹ · (a · b)
y≡x⁻¹[xy] a b = {!-t 20 -m!} -- Agsy fails
x≡[xy]y⁻¹ : ∀ a b → a ≡ (a · b) · b ⁻¹
x≡[xy]y⁻¹ a b = {!-t 20 -m!} -- Agsy fails
rightIdentityUnique : Σ G λ u → (∀ x → x · u ≡ x) ×
(∀ u' → (∀ x → x · u' ≡ x) → u ≡ u')
rightIdentityUnique = {!-t 20 -m!} -- Agsy fails
-- ε
-- , rightIdentity
-- , λ x x' → begin
-- ε ≡⟨ sym (x' ε) ⟩
-- ε · x ≡⟨ leftIdentity x ⟩
-- x
-- ∎
rightIdentityUnique' : ∀ x u → x · u ≡ x → ε ≡ u
rightIdentityUnique' x u xu≡x = {!-t 20 -m!} -- Agsy fails
leftIdentityUnique : Σ G λ u → (∀ x → u · x ≡ x) ×
(∀ u' → (∀ x → u' · x ≡ x) → u ≡ u')
leftIdentityUnique = {!-t 20 -m!} -- Agsy fails
-- ε
-- , leftIdentity
-- , λ x x' → begin
-- ε ≡⟨ sym (x' ε) ⟩
-- x · ε ≡⟨ rightIdentity x ⟩
-- x
-- ∎
leftIdentityUnique' : ∀ x u → u · x ≡ x → ε ≡ u
leftIdentityUnique' x u ux≡x = {!-t 20 -m!}
rightCancellation : ∀ x y z → y · x ≡ z · x → y ≡ z
rightCancellation x y z = λ hyp → {!-t 20 -m!} -- Agsy fails
leftCancellation : ∀ x y z → x · y ≡ x · z → y ≡ z
leftCancellation x y z = λ hyp → {!-t 20 -m!} -- Agsy fails
leftCancellationER : (x y z : G) → x · y ≡ x · z → y ≡ z
leftCancellationER x y z x·y≡x·z =
begin
y ≡⟨ sym (leftIdentity y) ⟩
ε · y ≡⟨ subst (λ t → ε · y ≡ t · y) (sym (leftInverse x)) refl ⟩
x ⁻¹ · x · y ≡⟨ assoc (x ⁻¹) x y ⟩
x ⁻¹ · (x · y) ≡⟨ subst (λ t → x ⁻¹ · (x · y) ≡ x ⁻¹ · t) x·y≡x·z refl ⟩
x ⁻¹ · (x · z) ≡⟨ sym (assoc (x ⁻¹) x z) ⟩
x ⁻¹ · x · z ≡⟨ subst (λ t → x ⁻¹ · x · z ≡ t · z) (leftInverse x) refl ⟩
ε · z ≡⟨ leftIdentity z ⟩
z
∎
rightInverseUnique : ∀ x → Σ G λ r → (x · r ≡ ε) ×
(∀ r' → x · r' ≡ ε → r ≡ r')
rightInverseUnique x = {!-t 20 -m!} -- Agsy fails
rightInverseUnique' : ∀ x r → x · r ≡ ε → x ⁻¹ ≡ r
rightInverseUnique' x r = λ hyp → {!-t 20 -m!} -- Agsy fails
leftInverseUnique : ∀ x → Σ G λ l → (l · x ≡ ε) ×
(∀ l' → l' · x ≡ ε → l ≡ l')
leftInverseUnique x = {!-t 20 -m!} -- Agsy fails
⁻¹-involutive : ∀ x → x ⁻¹ ⁻¹ ≡ x
⁻¹-involutive x = {!-t 20 -m!} -- Agsy fails
inverseDistribution : ∀ x y → (x · y) ⁻¹ ≡ y ⁻¹ · x ⁻¹
inverseDistribution x y = {!-t 20 -m!} -- Agsy fails
-- If the square of every element is the identity, the system is
-- commutative. From: TPTP 6.4.0. File: Problems/GRP/GRP001-2.p
x²≡ε→comm : (∀ a → a · a ≡ ε) → ∀ {b c d} → b · c ≡ d → c · b ≡ d
x²≡ε→comm hyp {b} {c} {d} bc≡d = {!-t 20 -m!} -- Agsy fails
| {
"alphanum_fraction": 0.4347043702,
"avg_line_length": 33.8260869565,
"ext": "agda",
"hexsha": "483e977b8fa3ac127a17930289426c6bc27e6073",
"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/Agsy/GroupTheory.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/Agsy/GroupTheory.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/Agsy/GroupTheory.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": 1496,
"size": 3890
} |
data Bool : Set where
true false : Bool
data Eq : Bool → Bool → Set where
refl : (x : Bool) → Eq x x
test : (x : Bool) → Eq true x → Set
test _ (refl false) = Bool
| {
"alphanum_fraction": 0.5906432749,
"avg_line_length": 17.1,
"ext": "agda",
"hexsha": "313fae0824ff8880d2d3733d5c9daa82d1a69595",
"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/Issue3014.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/Issue3014.agda",
"max_line_length": 35,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue3014.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": 60,
"size": 171
} |
------------------------------------------------------------------------
-- Some decision procedures for equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Equality.Decision-procedures
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open Derived-definitions-and-properties eq
open import Equality.Decidable-UIP eq
open import Prelude
hiding (module ⊤; module ⊥; module ↑; module ℕ; module Σ; module List)
------------------------------------------------------------------------
-- The unit type
module ⊤ where
-- Equality of values of the unit type is decidable.
infix 4 _≟_
_≟_ : Decidable-equality ⊤
_ ≟ _ = yes (refl _)
------------------------------------------------------------------------
-- The empty type
module ⊥ {ℓ} where
-- Equality of values of the empty type is decidable.
infix 4 _≟_
_≟_ : Decidable-equality (⊥ {ℓ = ℓ})
() ≟ ()
------------------------------------------------------------------------
-- Lifting
module ↑ {a ℓ} {A : Type a} where
-- ↑ preserves decidability of equality.
module Dec (dec : Decidable-equality A) where
infix 4 _≟_
_≟_ : Decidable-equality (↑ ℓ A)
lift x ≟ lift y = ⊎-map (cong lift) (_∘ cong lower) (dec x y)
------------------------------------------------------------------------
-- Booleans
module Bool where
-- The values true and false are distinct.
abstract
true≢false : true ≢ false
true≢false true≡false = subst T true≡false _
-- Equality of booleans is decidable.
infix 4 _≟_
_≟_ : Decidable-equality Bool
true ≟ true = yes (refl _)
false ≟ false = yes (refl _)
true ≟ false = no true≢false
false ≟ true = no (true≢false ∘ sym)
------------------------------------------------------------------------
-- Σ-types
module Σ {a b} {A : Type a} {B : A → Type b} where
-- Two variants of Dec._≟_ (which is defined below).
set⇒dec⇒dec⇒dec :
{x₁ x₂ : A} {y₁ : B x₁} {y₂ : B x₂} →
Is-set A →
Dec (x₁ ≡ x₂) →
(∀ eq → Dec (subst B eq y₁ ≡ y₂)) →
Dec ((x₁ , y₁) ≡ (x₂ , y₂))
set⇒dec⇒dec⇒dec set₁ (no x₁≢x₂) dec₂ = no (x₁≢x₂ ∘ cong proj₁)
set⇒dec⇒dec⇒dec set₁ (yes x₁≡x₂) dec₂ with dec₂ x₁≡x₂
… | yes cast-y₁≡y₂ = yes (Σ-≡,≡→≡ x₁≡x₂ cast-y₁≡y₂)
… | no cast-y₁≢y₂ =
no (cast-y₁≢y₂ ∘
subst (λ p → subst B p _ ≡ _) (set₁ _ _) ∘
proj₂ ∘ Σ-≡,≡←≡)
decidable⇒dec⇒dec :
{x₁ x₂ : A} {y₁ : B x₁} {y₂ : B x₂} →
Decidable-equality A →
(∀ eq → Dec (subst B eq y₁ ≡ y₂)) →
Dec ((x₁ , y₁) ≡ (x₂ , y₂))
decidable⇒dec⇒dec dec =
set⇒dec⇒dec⇒dec (decidable⇒set dec) (dec _ _)
-- Σ preserves decidability of equality.
module Dec (_≟A_ : Decidable-equality A)
(_≟B_ : {x : A} → Decidable-equality (B x)) where
infix 4 _≟_
_≟_ : Decidable-equality (Σ A B)
_ ≟ _ = decidable⇒dec⇒dec _≟A_ (λ _ → _ ≟B _)
------------------------------------------------------------------------
-- Binary products
module × {a b} {A : Type a} {B : Type b} where
-- _,_ preserves decided equality.
dec⇒dec⇒dec :
{x₁ x₂ : A} {y₁ y₂ : B} →
Dec (x₁ ≡ x₂) →
Dec (y₁ ≡ y₂) →
Dec ((x₁ , y₁) ≡ (x₂ , y₂))
dec⇒dec⇒dec (no x₁≢x₂) _ = no (x₁≢x₂ ∘ cong proj₁)
dec⇒dec⇒dec _ (no y₁≢y₂) = no (y₁≢y₂ ∘ cong proj₂)
dec⇒dec⇒dec (yes x₁≡x₂) (yes y₁≡y₂) = yes (cong₂ _,_ x₁≡x₂ y₁≡y₂)
-- _×_ preserves decidability of equality.
module Dec (_≟A_ : Decidable-equality A)
(_≟B_ : Decidable-equality B) where
infix 4 _≟_
_≟_ : Decidable-equality (A × B)
_ ≟ _ = dec⇒dec⇒dec (_ ≟A _) (_ ≟B _)
------------------------------------------------------------------------
-- Binary sums
module ⊎ {a b} {A : Type a} {B : Type b} where
abstract
-- The values inj₁ x and inj₂ y are never equal.
inj₁≢inj₂ : {x : A} {y : B} → inj₁ x ≢ inj₂ y
inj₁≢inj₂ = Bool.true≢false ∘ cong (if_then true else false)
-- The inj₁ and inj₂ constructors are cancellative.
cancel-inj₁ : {x y : A} → _≡_ {A = A ⊎ B} (inj₁ x) (inj₁ y) → x ≡ y
cancel-inj₁ {x = x} = cong {A = A ⊎ B} {B = A} [ id , const x ]
cancel-inj₂ : {x y : B} → _≡_ {A = A ⊎ B} (inj₂ x) (inj₂ y) → x ≡ y
cancel-inj₂ {x = x} = cong {A = A ⊎ B} {B = B} [ const x , id ]
-- _⊎_ preserves decidability of equality.
module Dec (_≟A_ : Decidable-equality A)
(_≟B_ : Decidable-equality B) where
infix 4 _≟_
_≟_ : Decidable-equality (A ⊎ B)
inj₁ x ≟ inj₁ y = ⊎-map (cong (inj₁ {B = B})) (λ x≢y → x≢y ∘ cancel-inj₁) (x ≟A y)
inj₂ x ≟ inj₂ y = ⊎-map (cong (inj₂ {A = A})) (λ x≢y → x≢y ∘ cancel-inj₂) (x ≟B y)
inj₁ x ≟ inj₂ y = no inj₁≢inj₂
inj₂ x ≟ inj₁ y = no (inj₁≢inj₂ ∘ sym)
------------------------------------------------------------------------
-- Lists
module List {a} {A : Type a} where
abstract
-- The values [] and x ∷ xs are never equal.
[]≢∷ : ∀ {x : A} {xs} → [] ≢ x ∷ xs
[]≢∷ = Bool.true≢false ∘
cong (λ { [] → true; (_ ∷ _) → false })
-- The _∷_ constructor is cancellative in both arguments.
private
head? : A → List A → A
head? x [] = x
head? _ (x ∷ _) = x
tail? : List A → List A
tail? [] = []
tail? (_ ∷ xs) = xs
cancel-∷-head : ∀ {x y : A} {xs ys} → x ∷ xs ≡ y ∷ ys → x ≡ y
cancel-∷-head {x} = cong (head? x)
cancel-∷-tail : ∀ {x y : A} {xs ys} → x ∷ xs ≡ y ∷ ys → xs ≡ ys
cancel-∷-tail = cong tail?
abstract
-- An η-like result for the cancellation lemmas.
unfold-∷ : ∀ {x y : A} {xs ys} (eq : x ∷ xs ≡ y ∷ ys) →
eq ≡ cong₂ _∷_ (cancel-∷-head eq) (cancel-∷-tail eq)
unfold-∷ {x} eq =
eq ≡⟨ sym $ trans-reflʳ eq ⟩
trans eq (refl _) ≡⟨ sym $ cong (trans eq) sym-refl ⟩
trans eq (sym (refl _)) ≡⟨ sym $ trans-reflˡ _ ⟩
trans (refl _) (trans eq (sym (refl _))) ≡⟨ sym $ cong-roughly-id (λ xs → head? x xs ∷ tail? xs)
non-empty eq tt tt lemma₁ ⟩
cong (λ xs → head? x xs ∷ tail? xs) eq ≡⟨ lemma₂ _∷_ (head? x) tail? eq ⟩∎
cong₂ _∷_ (cong (head? x) eq) (cong tail? eq) ∎
where
non-empty : List A → Bool
non-empty [] = false
non-empty (_ ∷ _) = true
lemma₁ : (xs : List A) →
if non-empty xs then ⊤ else ⊥ →
head? x xs ∷ tail? xs ≡ xs
lemma₁ [] ()
lemma₁ (_ ∷ _) _ = refl _
lemma₂ : {A B C D : Type a} {x y : A}
(f : B → C → D) (g : A → B) (h : A → C) →
(eq : x ≡ y) →
cong (λ x → f (g x) (h x)) eq ≡
cong₂ f (cong g eq) (cong h eq)
lemma₂ f g h =
elim (λ eq → cong (λ x → f (g x) (h x)) eq ≡
cong₂ f (cong g eq) (cong h eq))
(λ x → cong (λ x → f (g x) (h x)) (refl x) ≡⟨ cong-refl (λ x → f (g x) (h x)) ⟩
refl (f (g x) (h x)) ≡⟨ sym $ cong₂-refl f ⟩
cong₂ f (refl (g x)) (refl (h x)) ≡⟨ sym $ cong₂ (cong₂ f) (cong-refl g) (cong-refl h) ⟩∎
cong₂ f (cong g (refl x)) (cong h (refl x)) ∎)
-- List preserves decidability of equality.
module Dec (_≟A_ : Decidable-equality A) where
infix 4 _≟_
_≟_ : Decidable-equality (List A)
[] ≟ [] = yes (refl [])
[] ≟ (_ ∷ _) = no []≢∷
(_ ∷ _) ≟ [] = no ([]≢∷ ∘ sym)
(x ∷ xs) ≟ (y ∷ ys) with x ≟A y
... | no x≢y = no (x≢y ∘ cancel-∷-head)
... | yes x≡y with xs ≟ ys
... | yes xs≡ys = yes (cong₂ _∷_ x≡y xs≡ys)
... | no xs≢ys = no (xs≢ys ∘ cancel-∷-tail)
------------------------------------------------------------------------
-- Finite sets
module Fin where
-- Equality of finite numbers is decidable.
infix 4 _≟_
_≟_ : ∀ {n} → Decidable-equality (Fin n)
_≟_ {zero} = λ ()
_≟_ {suc n} = ⊎.Dec._≟_ (λ _ _ → yes (refl tt)) (_≟_ {n})
| {
"alphanum_fraction": 0.4510601578,
"avg_line_length": 29.8235294118,
"ext": "agda",
"hexsha": "c1f753919847575cc1402beea66514daac87e75c",
"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/Equality/Decision-procedures.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/Equality/Decision-procedures.agda",
"max_line_length": 120,
"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/Equality/Decision-procedures.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": 3039,
"size": 8112
} |
module Cats.Category.Cat.Facts.Exponential where
open import Data.Product using (_,_)
open import Level using (_⊔_)
open import Relation.Binary using (IsEquivalence)
open import Cats.Bifunctor using
(Bifunctor ; Bifunctor→Functor₁ ; transposeBifunctor₁ ; transposeBifunctor₁-resp)
open import Cats.Category
open import Cats.Category.Cat as Cat using
(Cat ; Functor ; _∘_ ; _≈_) renaming
(id to Id)
open import Cats.Category.Cat.Facts.Product using (hasBinaryProducts ; ⟨_×_⟩)
open import Cats.Category.Fun using (Fun ; Trans ; ≈-intro ; ≈-elim)
open import Cats.Category.Fun.Facts using (NatIso→≅)
open import Cats.Category.Product.Binary using (_×_)
open import Cats.Trans.Iso as NatIso using (NatIso)
open import Cats.Util.Conv
open import Cats.Util.Simp using (simp!)
import Cats.Category.Base as Base
import Cats.Category.Constructions.Unique as Unique
import Cats.Category.Constructions.Iso as Iso
open Functor
open Trans
open Iso.Build._≅_
infixr 1 _↝_
_↝_ : ∀ {lo la l≈ lo′ la′ l≈′}
→ Category lo la l≈
→ Category lo′ la′ l≈′
→ Category (lo ⊔ la ⊔ l≈ ⊔ lo′ ⊔ la′ ⊔ l≈′) (lo ⊔ la ⊔ la′ ⊔ l≈′) (lo ⊔ l≈′)
_↝_ = Fun
module _ {lo la l≈ lo′ la′ l≈′}
{B : Category lo la l≈} {C : Category lo′ la′ l≈′}
where
private
module B = Category B
module C = Category C
module B↝C = Category (Fun B C)
Eval : Bifunctor (B ↝ C) B C
Eval = record
{ fobj = λ where
(F , x) → fobj F x
; fmap = λ where
{F , a} {G , b} (θ , f) → fmap G f C.∘ component θ a
; fmap-resp = λ where
{F , a} {G , b} {θ , f} {ι , g} (θ≈ι , f≈g) →
C.∘-resp (fmap-resp G f≈g) (≈-elim θ≈ι)
; fmap-id = λ { {F , b} → C.≈.trans (C.∘-resp-l (fmap-id F)) C.id-l }
; fmap-∘ = λ where
{F , a} {G , b} {H , c} {θ , f} {ι , g} →
begin
(fmap H f C.∘ component θ b) C.∘ (fmap G g C.∘ component ι a)
≈⟨ C.∘-resp-l (C.≈.sym (natural θ)) ⟩
(component θ c C.∘ fmap G f) C.∘ (fmap G g C.∘ component ι a)
≈⟨ simp! C ⟩
component θ c C.∘ (fmap G f C.∘ fmap G g) C.∘ component ι a
≈⟨ C.∘-resp-r (C.∘-resp-l (fmap-∘ G)) ⟩
component θ c C.∘ (fmap G (f B.∘ g)) C.∘ component ι a
≈⟨ simp! C ⟩
(component θ c C.∘ fmap G (f B.∘ g)) C.∘ component ι a
≈⟨ C.∘-resp-l (natural θ) ⟩
(fmap H (f B.∘ g) C.∘ component θ a) C.∘ component ι a
≈⟨ simp! C ⟩
fmap H (f B.∘ g) C.∘ component θ a C.∘ component ι a
∎
}
where
open C.≈-Reasoning
module _ {lo la l≈ lo′ la′ l≈′ lo″ la″ l≈″}
{B : Category lo la l≈} {C : Category lo′ la′ l≈′} {D : Category lo″ la″ l≈″}
where
private
module B = Category B
module C = Category C
module D = Category D
module C↝D = Category (Fun C D)
Curry : Bifunctor B C D → Functor B (C ↝ D)
Curry F = transposeBifunctor₁ F
Curry-resp : ∀ {F G} → F ≈ G → Curry F ≈ Curry G
Curry-resp = transposeBifunctor₁-resp
Curry-correct : ∀ {F} → Eval ∘ ⟨ Curry F × Id ⟩ ≈ F
Curry-correct {F} = record
{ iso = D.≅.refl
; forth-natural = λ where
{a , a′} {b , b′} {f , f′} →
begin
D.id D.∘ fmap F (B.id , f′) D.∘ fmap F (f , C.id)
≈⟨ D.≈.trans D.id-l (fmap-∘ F) ⟩
fmap F (B.id B.∘ f , f′ C.∘ C.id)
≈⟨ fmap-resp F (B.id-l , C.id-r) ⟩
fmap F (f , f′)
≈⟨ D.≈.sym D.id-r ⟩
fmap F (f , f′) D.∘ D.id
∎
}
where
open D.≈-Reasoning
Curry-unique : ∀ {F Curry′}
→ Eval ∘ ⟨ Curry′ × Id ⟩ ≈ F
→ Curry′ ≈ Curry F
Curry-unique {F} {Curry′} eq@record { iso = iso ; forth-natural = fnat } = record
{ iso = λ {x} →
let open C↝D.≅-Reasoning in
C↝D.≅.sym (
begin
fobj (Curry F) x
≈⟨ NatIso.iso (Curry-resp (sym-Cat eq)) ⟩
fobj (Curry (Eval ∘ ⟨ Curry′ × Id ⟩)) x
≈⟨ NatIso→≅ (lem x) ⟩
fobj Curry′ x
∎
)
; forth-natural = λ {a} {b} {f} → ≈-intro λ {x} →
-- TODO We need a simplification tactic.
let open D.≈-Reasoning in
triangle (forth iso D.∘ component (fmap Curry′ f) x)
( begin
((forth iso D.∘
(fmap (fobj Curry′ b) C.id D.∘ component (fmap Curry′ B.id) x) D.∘ D.id) D.∘
D.id D.∘ D.id) D.∘
component (fmap Curry′ f) x
≈⟨ ∘-resp-l (trans (∘-resp-r id-l) (trans id-r (trans (∘-resp-r
(trans id-r (trans (∘-resp (fmap-id (fobj Curry′ b))
(≈-elim (fmap-id Curry′))) id-l))) id-r))) ⟩
forth iso D.∘ component (fmap Curry′ f) x
∎
)
( begin
fmap F (f , C.id) D.∘
(forth iso D.∘ (fmap (fobj Curry′ a) C.id D.∘ component (fmap Curry′ B.id) x) D.∘ D.id) D.∘
D.id D.∘ D.id
≈⟨ ∘-resp-r (trans (∘-resp-r id-r) (trans id-r (trans (∘-resp-r
(trans id-r (trans (∘-resp-l (fmap-id (fobj Curry′ a)))
(trans id-l (≈-elim (fmap-id Curry′)))))) id-r))) ⟩
fmap F (f , C.id) D.∘ forth iso
≈⟨ sym fnat ⟩
forth iso D.∘ fmap (fobj Curry′ b) C.id D.∘ component (fmap Curry′ f) x
≈⟨ ∘-resp-r (trans (∘-resp-l (fmap-id (fobj Curry′ b))) id-l) ⟩
forth iso D.∘ component (fmap Curry′ f) x
∎
)
}
where
open D using (id-l ; id-r ; ∘-resp ; ∘-resp-l ; ∘-resp-r)
open D.≈ using (sym ; trans)
open IsEquivalence Cat.equiv using () renaming (sym to sym-Cat)
lem : ∀ x
→ NatIso (Bifunctor→Functor₁ (Eval ∘ ⟨ Curry′ × Id ⟩) x) (fobj Curry′ x)
lem x = record
{ iso = D.≅.refl
; forth-natural = D.≈.trans D.id-l (D.∘-resp-r (≈-elim (fmap-id Curry′)))
}
instance
hasExponentials : ∀ l → HasExponentials (Cat l l l)
hasExponentials l = record
{ _↝′_ = λ B C → record
{ Cᴮ = B ↝ C
; eval = Eval
; curry′ = λ F → record
{ arr = Curry F
; prop = Curry-correct {F = F}
; unique = λ {g} eq →
let open IsEquivalence Cat.equiv using (sym) in
sym (Curry-unique eq)
}
}
}
| {
"alphanum_fraction": 0.4886771826,
"avg_line_length": 33.1761658031,
"ext": "agda",
"hexsha": "c03e5a5f35f2edeb3da7b31dcda67a2d4878103b",
"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/Cat/Facts/Exponential.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/Cat/Facts/Exponential.agda",
"max_line_length": 105,
"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/Cat/Facts/Exponential.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2417,
"size": 6403
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category)
open import Categories.Category.Monoidal.Core using (Monoidal)
module Categories.Category.Monoidal.Utilities {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where
open import Level
open import Function using (_$_)
open import Data.Product using (_×_; _,_; curry′)
open import Categories.Category.Product
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Bifunctor using (Bifunctor; appˡ; appʳ)
open import Categories.Functor.Properties using ([_]-resp-≅)
open import Categories.NaturalTransformation renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism
hiding (unitorˡ; unitorʳ; associator; _≃_)
infixr 10 _⊗ᵢ_
open import Categories.Morphism C using (_≅_; module ≅)
open import Categories.Morphism.IsoEquiv C using (_≃_; ⌞_⌟)
open import Categories.Morphism.Isomorphism C using (_∘ᵢ_; lift-triangle′; lift-pentagon′)
open import Categories.Morphism.Reasoning C
private
module C = Category C
open C hiding (id; identityˡ; identityʳ; assoc)
open Commutation
private
variable
X Y Z W A B : Obj
f g h i a b : X ⇒ Y
open Monoidal M
module ⊗ = Functor ⊗
-- for exporting, it makes sense to use the above long names, but for
-- internal consumption, the traditional (short!) categorical names are more
-- convenient. However, they are not symmetric, even though the concepts are, so
-- we'll use ⇒ and ⇐ arrows to indicate that
module Shorthands where
λ⇒ = unitorˡ.from
λ⇐ = unitorˡ.to
ρ⇒ = unitorʳ.from
ρ⇐ = unitorʳ.to
-- eta expansion fixes a problem in 2.6.1, will be reported
α⇒ = λ {X} {Y} {Z} → associator.from {X} {Y} {Z}
α⇐ = λ {X} {Y} {Z} → associator.to {X} {Y} {Z}
open Shorthands
private
[x⊗y]⊗z : Bifunctor (Product C C) C C
[x⊗y]⊗z = ⊗ ∘F (⊗ ⁂ idF)
-- note how this one needs re-association to typecheck (i.e. be correct)
x⊗[y⊗z] : Bifunctor (Product C C) C C
x⊗[y⊗z] = ⊗ ∘F (idF ⁂ ⊗) ∘F assocˡ _ _ _
unitor-coherenceʳ : [ (A ⊗₀ unit) ⊗₀ unit ⇒ A ⊗₀ unit ]⟨ ρ⇒ ⊗₁ C.id ≈ ρ⇒ ⟩
unitor-coherenceʳ = cancel-fromˡ unitorʳ unitorʳ-commute-from
unitor-coherenceˡ : [ unit ⊗₀ unit ⊗₀ A ⇒ unit ⊗₀ A ]⟨ C.id ⊗₁ λ⇒ ≈ λ⇒ ⟩
unitor-coherenceˡ = cancel-fromˡ unitorˡ unitorˡ-commute-from
-- All the implicits below can be inferred, but being explicit is clearer
unitorˡ-naturalIsomorphism : NaturalIsomorphism (unit ⊗-) idF
unitorˡ-naturalIsomorphism = record
{ F⇒G = ntHelper record
{ η = λ X → λ⇒ {X}
; commute = λ f → unitorˡ-commute-from {f = f}
}
; F⇐G = ntHelper record
{ η = λ X → λ⇐ {X}
; commute = λ f → unitorˡ-commute-to {f = f}
}
; iso = λ X → unitorˡ.iso {X}
}
unitorʳ-naturalIsomorphism : NaturalIsomorphism (-⊗ unit) idF
unitorʳ-naturalIsomorphism = record
{ F⇒G = ntHelper record
{ η = λ X → ρ⇒ {X}
; commute = λ f → unitorʳ-commute-from {f = f}
}
; F⇐G = ntHelper record
{ η = λ X → ρ⇐ {X}
; commute = λ f → unitorʳ-commute-to {f = f}
}
; iso = λ X → unitorʳ.iso {X}
}
-- skipping the explicit arguments here, it does not increase understandability
associator-naturalIsomorphism : NaturalIsomorphism [x⊗y]⊗z x⊗[y⊗z]
associator-naturalIsomorphism = record
{ F⇒G = ntHelper record
{ η = λ { ((X , Y) , Z) → α⇒ {X} {Y} {Z}}
; commute = λ _ → assoc-commute-from
}
; F⇐G = ntHelper record
{ η = λ _ → α⇐
; commute = λ _ → assoc-commute-to
}
; iso = λ _ → associator.iso
}
module unitorˡ-natural = NaturalIsomorphism unitorˡ-naturalIsomorphism
module unitorʳ-natural = NaturalIsomorphism unitorʳ-naturalIsomorphism
module associator-natural = NaturalIsomorphism associator-naturalIsomorphism
_⊗ᵢ_ : X ≅ Y → Z ≅ W → X ⊗₀ Z ≅ Y ⊗₀ W
f ⊗ᵢ g = [ ⊗ ]-resp-≅ record
{ from = from f , from g
; to = to f , to g
; iso = record
{ isoˡ = isoˡ f , isoˡ g
; isoʳ = isoʳ f , isoʳ g
}
}
where open _≅_
triangle-iso : ≅.refl ⊗ᵢ unitorˡ ∘ᵢ associator ≃ unitorʳ {X} ⊗ᵢ ≅.refl {Y}
triangle-iso = lift-triangle′ triangle
pentagon-iso :
≅.refl ⊗ᵢ associator ∘ᵢ associator ∘ᵢ associator {X} {Y} {Z} ⊗ᵢ ≅.refl {W}
≃ associator ∘ᵢ associator
pentagon-iso = lift-pentagon′ pentagon
refl⊗refl≃refl : ≅.refl {A} ⊗ᵢ ≅.refl {B} ≃ ≅.refl
refl⊗refl≃refl = ⌞ ⊗.identity ⌟
| {
"alphanum_fraction": 0.6592592593,
"avg_line_length": 31.3043478261,
"ext": "agda",
"hexsha": "6f359ee0ea1d7f593ee8e0aec229809161ec75fe",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Utilities.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Utilities.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Utilities.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1688,
"size": 4320
} |
------------------------------------------------------------------------
-- A library of parser combinators
------------------------------------------------------------------------
-- This module also provides examples of parsers for which the indices
-- cannot be inferred.
module RecursiveDescent.Hybrid.Lib where
open import RecursiveDescent.Hybrid
import RecursiveDescent.Hybrid.Type as Type
open import RecursiveDescent.Index
open import Utilities
open import Data.Nat hiding (_≟_)
open import Data.Vec using (Vec; []; _∷_)
open import Data.Vec1 using (Vec₁; []; _∷_; map₀₁)
open import Data.List using (List; []; _∷_; foldr; reverse)
open import Data.Product.Record hiding (_×_)
open import Data.Product using (_×_) renaming (_,_ to pair)
open import Data.Bool hiding (_≟_)
open import Data.Function
open import Data.Maybe
open import Data.Unit hiding (_≟_)
open import Data.Bool.Properties as Bool
import Data.Char as Char
open Char using (Char; _==_)
open import Algebra
private
module BCS = CommutativeSemiring Bool.commutativeSemiring-∨-∧
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality using (refl)
------------------------------------------------------------------------
-- Applicative functor parsers
-- We could get these for free with better library support.
infixl 50 _⊛_ _⊛!_ _<⊛_ _⊛>_ _<$>_ _<$_ _⊗_ _⊗!_
_⊛_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ (r₁ -> r₂) ->
Parser tok nt i₂ r₁ ->
Parser tok nt _ r₂
p₁ ⊛ p₂ = p₁ >>= \f -> p₂ >>= \x -> return (f x)
-- A variant: If the second parser does not accept the empty string,
-- then neither does the combination. (This is immediate for the first
-- parser, but for the second one a small lemma is needed, hence this
-- variant.)
_⊛!_ : forall {tok nt i₁ c₂ r₁ r₂} ->
Parser tok nt i₁ (r₁ -> r₂) ->
Parser tok nt (false , c₂) r₁ ->
Parser tok nt (false , _) r₂
_⊛!_ {i₁ = i₁} p₁ p₂ = cast (BCS.*-comm (proj₁ i₁) false) refl
(p₁ ⊛ p₂)
_<$>_ : forall {tok nt i r₁ r₂} ->
(r₁ -> r₂) ->
Parser tok nt i r₁ ->
Parser tok nt _ r₂
f <$> x = return f ⊛ x
_<⊛_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ r₁ ->
Parser tok nt i₂ r₂ ->
Parser tok nt _ r₁
x <⊛ y = const <$> x ⊛ y
_⊛>_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ r₁ ->
Parser tok nt i₂ r₂ ->
Parser tok nt _ r₂
x ⊛> y = flip const <$> x ⊛ y
_<$_ : forall {tok nt i r₁ r₂} ->
r₁ ->
Parser tok nt i r₂ ->
Parser tok nt _ r₁
x <$ y = const x <$> y
_⊗_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ r₁ -> Parser tok nt i₂ r₂ ->
Parser tok nt _ (r₁ × r₂)
p₁ ⊗ p₂ = pair <$> p₁ ⊛ p₂
_⊗!_ : forall {tok nt i₁ c₂ r₁ r₂} ->
Parser tok nt i₁ r₁ -> Parser tok nt (false , c₂) r₂ ->
Parser tok nt (false , _) (r₁ × r₂)
p₁ ⊗! p₂ = pair <$> p₁ ⊛! p₂
------------------------------------------------------------------------
-- Parsing sequences
infix 55 _⋆ _+
-- Not accepted by the productivity checker:
-- mutual
-- _⋆ : forall {tok r d} ->
-- Parser tok (false , d) r ->
-- Parser tok _ (List r)
-- p ⋆ ~ return [] ∣ p +
-- _+ : forall {tok r d} ->
-- Parser tok (false , d) r ->
-- Parser tok _ (List r)
-- p + ~ _∷_ <$> p ⊛ p ⋆
-- By inlining some definitions we can show that the definitions are
-- productive, though. The following definitions have also been
-- simplified:
mutual
_⋆ : forall {tok nt r d} ->
Parser tok nt (false , d) r ->
Parser tok nt _ (List r)
p ⋆ ~ Type.alt _ _ (return []) (p +)
_+ : forall {tok nt r d} ->
Parser tok nt (false , d) r ->
Parser tok nt _ (List r)
p + ~ Type._!>>=_ p \x ->
Type._?>>=_ (p ⋆) \xs ->
return (x ∷ xs)
-- p sepBy sep parses one or more ps separated by seps.
_sepBy_ : forall {tok nt r r' i d} ->
Parser tok nt i r -> Parser tok nt (false , d) r' ->
Parser tok nt _ (List r)
p sepBy sep = _∷_ <$> p ⊛ (sep ⊛> p) ⋆
-- Note that the index of atLeast is only partly inferred; the
-- recursive structure of atLeast-index is given manually.
atLeast-index : Corners -> ℕ -> Index
atLeast-index c zero = _
atLeast-index c (suc n) = _
-- At least n occurrences of p.
atLeast : forall {tok nt c r} (n : ℕ) ->
Parser tok nt (false , c) r ->
Parser tok nt (atLeast-index c n) (List r)
atLeast zero p = p ⋆
atLeast (suc n) p = _∷_ <$> p ⊛ atLeast n p
-- Chains at least n occurrences of op, in an a-associative
-- manner. The ops are surrounded by ps.
chain≥ : forall {tok nt c₁ i₂ r} (n : ℕ) ->
Assoc ->
Parser tok nt (false , c₁) r ->
Parser tok nt i₂ (r -> r -> r) ->
Parser tok nt _ r
chain≥ n a p op = chain≥-combine a <$> p ⊛ atLeast n (op ⊗! p)
-- exactly n p parses n occurrences of p.
exactly-index : Index -> ℕ -> Index
exactly-index i zero = _
exactly-index i (suc n) = _
exactly : forall {tok nt i r} n ->
Parser tok nt i r ->
Parser tok nt (exactly-index i n) (Vec r n)
exactly zero p = return []
exactly (suc n) p = _∷_ <$> p ⊛ exactly n p
-- A function with a similar type:
sequence : forall {tok nt i r n} ->
Vec₁ (Parser tok nt i r) n ->
Parser tok nt (exactly-index i n) (Vec r n)
sequence [] = return []
sequence (p ∷ ps) = _∷_ <$> p ⊛ sequence ps
-- p between ps parses p repeatedly, between the elements of ps:
-- ∙ between (x ∷ y ∷ z ∷ []) ≈ x ∙ y ∙ z.
between-corners : Corners -> ℕ -> Corners
between-corners c′ zero = _
between-corners c′ (suc n) = _
_between_ : forall {tok nt i r c′ r′ n} ->
Parser tok nt i r ->
Vec₁ (Parser tok nt (false , c′) r′) (suc n) ->
Parser tok nt (false , between-corners c′ n) (Vec r n)
p between (x ∷ []) = [] <$ x
p between (x ∷ y ∷ xs) = _∷_ <$> (x ⊛> p) ⊛ (p between (y ∷ xs))
------------------------------------------------------------------------
-- N-ary variants of _∣_
-- choice ps parses one of the elements in ps.
choice-corners : Corners -> ℕ -> Corners
choice-corners c zero = _
choice-corners c (suc n) = _
choice : forall {tok nt c r n} ->
Vec₁ (Parser tok nt (false , c) r) n ->
Parser tok nt (false , choice-corners c n) r
choice [] = fail
choice (p ∷ ps) = p ∣ choice ps
-- choiceMap f xs ≈ choice (map f xs), but avoids use of Vec₁ and
-- fromList.
choiceMap-corners : forall {a} -> (a -> Corners) -> List a -> Corners
choiceMap-corners c [] = _
choiceMap-corners c (x ∷ xs) = _
choiceMap : forall {tok nt r a} {c : a -> Corners} ->
((x : a) -> Parser tok nt (false , c x) r) ->
(xs : List a) ->
Parser tok nt (false , choiceMap-corners c xs) r
choiceMap f [] = fail
choiceMap f (x ∷ xs) = f x ∣ choiceMap f xs
------------------------------------------------------------------------
-- sat and friends
sat : forall {tok nt r} ->
(tok -> Maybe r) -> Parser tok nt (0I ·I 1I) r
sat {tok} {nt} {r} p = symbol !>>= \c -> ok (p c)
where
okIndex : Maybe r -> Index
okIndex nothing = _
okIndex (just _) = _
ok : (x : Maybe r) -> Parser tok nt (okIndex x) r
ok nothing = fail
ok (just x) = return x
sat' : forall {tok nt} -> (tok -> Bool) -> Parser tok nt _ ⊤
sat' p = sat (boolToMaybe ∘ p)
any : forall {tok nt} -> Parser tok nt _ tok
any = sat just
------------------------------------------------------------------------
-- Token parsers
module Token (a : DecSetoid) where
open DecSetoid a using (_≟_) renaming (carrier to tok)
-- Parses a given token (or, really, a given equivalence class of
-- tokens).
sym : forall {nt} -> tok -> Parser tok nt _ tok
sym x = sat p
where
p : tok -> Maybe tok
p y with x ≟ y
... | yes _ = just y
... | no _ = nothing
-- Parses a sequence of tokens.
string : forall {nt n} -> Vec tok n -> Parser tok nt _ (Vec tok n)
string cs = sequence (map₀₁ sym cs)
------------------------------------------------------------------------
-- Character parsers
digit : forall {nt} -> Parser Char nt _ ℕ
digit = 0 <$ sym '0'
∣ 1 <$ sym '1'
∣ 2 <$ sym '2'
∣ 3 <$ sym '3'
∣ 4 <$ sym '4'
∣ 5 <$ sym '5'
∣ 6 <$ sym '6'
∣ 7 <$ sym '7'
∣ 8 <$ sym '8'
∣ 9 <$ sym '9'
where open Token Char.decSetoid
number : forall {nt} -> Parser Char nt _ ℕ
number = toNum <$> digit +
where
toNum = foldr (\n x -> 10 * x + n) 0 ∘ reverse
-- whitespace recognises an incomplete but useful list of whitespace
-- characters.
whitespace : forall {nt} -> Parser Char nt _ ⊤
whitespace = sat' isSpace
where
isSpace = \c ->
(c == ' ') ∨ (c == '\t') ∨ (c == '\n') ∨ (c == '\r')
| {
"alphanum_fraction": 0.5346132129,
"avg_line_length": 29.6153846154,
"ext": "agda",
"hexsha": "35c35b0463274eede2b9b837f1b9e6965c4a502d",
"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/Lib.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/Lib.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/Lib.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": 2746,
"size": 8855
} |
open import Data.Proofs
open import Function.Proofs
open import Logic.Propositional.Theorems
open import Structure.Container.SetLike
open import Structure.Relator
open import Structure.Relator.Properties
open import Syntax.Transitivity
instance
ImageSet-setLike : SetLike(_∈_ {ℓᵢ})
SetLike._⊆_ ImageSet-setLike A B = ∀{x} → (x ∈ A) → (x ∈ B)
SetLike._≡_ ImageSet-setLike A B = ∀{x} → (x ∈ A) ↔ (x ∈ B)
SetLike.[⊆]-membership ImageSet-setLike = [↔]-reflexivity
SetLike.[≡]-membership ImageSet-setLike = [↔]-reflexivity
private open module ImageSet-SetLike {ℓᵢ} = SetLike(ImageSet-setLike{ℓᵢ}) public
open import Structure.Container.SetLike.Proofs using ([⊇]-membership) public
module _ {ℓᵢ} where
instance [⊆]-binaryRelator = Structure.Container.SetLike.Proofs.[⊆]-binaryRelator ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [⊇]-binaryRelator = Structure.Container.SetLike.Proofs.[⊇]-binaryRelator ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [≡]-to-[⊆] = Structure.Container.SetLike.Proofs.[≡]-to-[⊆] ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [≡]-to-[⊇] = Structure.Container.SetLike.Proofs.[≡]-to-[⊇] ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [⊆]-reflexivity = Structure.Container.SetLike.Proofs.[⊆]-reflexivity ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [⊆]-antisymmetry = Structure.Container.SetLike.Proofs.[⊆]-antisymmetry ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [⊆]-transitivity = Structure.Container.SetLike.Proofs.[⊆]-transitivity ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [⊆]-partialOrder = Structure.Container.SetLike.Proofs.[⊆]-partialOrder ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [≡]-reflexivity = Structure.Container.SetLike.Proofs.[≡]-reflexivity ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [≡]-symmetry = Structure.Container.SetLike.Proofs.[≡]-symmetry ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [≡]-transitivity = Structure.Container.SetLike.Proofs.[≡]-transitivity ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [≡]-equivalence = Structure.Container.SetLike.Proofs.[≡]-equivalence ⦃ ImageSet-setLike{ℓᵢ} ⦄
instance [∈]-unaryOperatorᵣ = Structure.Container.SetLike.Proofs.[∈]-unaryOperatorᵣ ⦃ ImageSet-setLike{ℓᵢ} ⦄
| {
"alphanum_fraction": 0.6885468538,
"avg_line_length": 69.03125,
"ext": "agda",
"hexsha": "0909597163e4fcbd1edf41d7443df991af904616",
"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": "Sets/ImageSet/SetLike.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": "Sets/ImageSet/SetLike.agda",
"max_line_length": 112,
"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": "Sets/ImageSet/SetLike.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": 822,
"size": 2209
} |
module Issue180 where
module Example₁ where
data C : Set where
c : C → C
data Indexed : (C → C) → Set where
i : Indexed c
foo : Indexed c → Set
foo i = C
module Example₂ where
data List (A : Set) : Set where
nil : List A
cons : A → List A → List A
postulate
A : Set
x : A
T : Set
T = List A → List A
data P : List T → Set where
p : (f : T) → P (cons f nil)
data S : (xs : List T) → P xs → Set where
s : (f : T) → S (cons f nil) (p f)
foo : S (cons (cons x) nil) (p (cons x)) → A
foo (s ._) = x
| {
"alphanum_fraction": 0.5177935943,
"avg_line_length": 16.0571428571,
"ext": "agda",
"hexsha": "1101be5536ed582f1e38f73878682d2fca89fe8d",
"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/Issue180.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/Issue180.agda",
"max_line_length": 46,
"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/Issue180.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": 211,
"size": 562
} |
{- 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 Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Hash
open import LibraBFT.Lemmas
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Handle
open import LibraBFT.Concrete.System.Parameters
open EpochConfig
-- This module defines an abstract system state given a reachable
-- concrete system state.
module LibraBFT.Concrete.System where
ℓ-VSFP : Level
ℓ-VSFP = 1ℓ ℓ⊔ ℓ-RoundManager
open import LibraBFT.Yasm.Base
import LibraBFT.Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms as LYS
-- What EpochConfigs are known in the system? For now, only the initial one. Later, we will add
-- knowledge of subsequent EpochConfigs known via EpochChangeProofs.
data EpochConfig∈Sys (st : LYS.SystemState) (𝓔 : EpochConfig) : Set ℓ-EC where
inGenInfo : init-EC genInfo ≡ 𝓔 → EpochConfig∈Sys st 𝓔
-- inECP : ∀ {ecp} → ecp ECP∈Sys st → verify-ECP ecp 𝓔 → EpochConfig∈Sys
-- A peer pid can sign a new message for a given PK if pid is the owner of a PK in a known
-- EpochConfig.
record PeerCanSignForPK (st : LYS.SystemState) (v : Vote) (pid : NodeId) (pk : PK) : Set ℓ-VSFP where
constructor mkPCS4PK
field
𝓔 : EpochConfig
𝓔id≡ : epoch 𝓔 ≡ v ^∙ vEpoch
𝓔inSys : EpochConfig∈Sys st 𝓔
mbr : Member 𝓔
nid≡ : toNodeId 𝓔 mbr ≡ pid
pk≡ : getPubKey 𝓔 mbr ≡ pk
open PeerCanSignForPK
PCS4PK⇒NodeId-PK-OK : ∀ {st v pid pk} → (pcs : PeerCanSignForPK st v pid pk) → NodeId-PK-OK (𝓔 pcs) pk pid
PCS4PK⇒NodeId-PK-OK (mkPCS4PK _ _ _ mbr n≡ pk≡) = mbr , n≡ , pk≡
-- This is super simple for now because the only known EpochConfig is dervied from genInfo, which is not state-dependent
PeerCanSignForPK-stable : LYS.ValidSenderForPK-stable-type PeerCanSignForPK
PeerCanSignForPK-stable _ _ (mkPCS4PK 𝓔₁ 𝓔id≡₁ (inGenInfo refl) mbr₁ nid≡₁ pk≡₁) = (mkPCS4PK 𝓔₁ 𝓔id≡₁ (inGenInfo refl) mbr₁ nid≡₁ pk≡₁)
open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms PeerCanSignForPK
(λ {st} {part} {pk} → PeerCanSignForPK-stable {st} {part} {pk})
-- An implementation must prove that, if one of its handlers sends a
-- message that contains a vote and is signed by a public key pk, then
-- either the vote's author is the peer executing the handler, the
-- epochId is in range, the peer is a member of the epoch, and its key
-- in that epoch is pk; or, a message with the same signature has been
-- sent before. This is represented by StepPeerState-AllValidParts.
module WithSPS (sps-corr : StepPeerState-AllValidParts) where
-- Bring in 'unwind', 'ext-unforgeability' and friends
open Structural sps-corr
-- TODO-1: refactor this somewhere else? Maybe something like
-- LibraBFT.Impl.Consensus.Types.Properties?
sameSig⇒sameVoteData : ∀ {v1 v2 : Vote} {pk}
→ WithVerSig pk v1
→ WithVerSig pk v2
→ v1 ^∙ vSignature ≡ v2 ^∙ vSignature
→ NonInjective-≡ sha256 ⊎ v2 ^∙ vVoteData ≡ v1 ^∙ vVoteData
sameSig⇒sameVoteData {v1} {v2} wvs1 wvs2 refl
with verify-bs-inj (verified wvs1) (verified wvs2)
-- The signable fields of the votes must be the same (we do not model signature collisions)
...| bs≡
-- Therefore the LedgerInfo is the same for the new vote as for the previous vote
= sym <⊎$> (hashVote-inj1 {v1} {v2} (sameBS⇒sameHash bs≡))
-- We are now ready to define an 'IntermediateSystemState' view for a concrete
-- reachable state. We will do so by fixing an epoch that exists in
-- the system, which will enable us to define the abstract
-- properties. The culminaton of this 'PerEpoch' module is seen in
-- the 'IntSystemState' "function" at the bottom, which probably the
-- best place to start uynderstanding this. Longer term, we will
-- also need higher-level, cross-epoch properties.
module PerState (st : SystemState)(r : ReachableSystemState st) where
-- TODO-3: Remove this postulate when we are satisfied with the
-- "hash-collision-tracking" solution. For example, when proving voo
-- (in LibraBFT.LibraBFT.Concrete.Properties.VotesOnce), we
-- currently use this postulate to eliminate the possibility of two
-- votes that have the same signature but different VoteData
-- whenever we use sameSig⇒sameVoteData. To eliminate the
-- postulate, we need to refine the properties we prove to enable
-- the possibility of a hash collision, in which case the required
-- property might not hold. However, it is not sufficient to simply
-- prove that a hash collision *exists* (which is obvious,
-- regardless of the LibraBFT implementation). Rather, we
-- ultimately need to produce a specific hash collision and relate
-- it to the data in the system, so that we can prove that the
-- desired properties hold *unless* an actual hash collision is
-- found by the implementation given the data in the system. In
-- the meantime, we simply require that the collision identifies a
-- reachable state; later "collision tracking" will require proof
-- that the colliding values actually exist in that state.
postulate -- temporary assumption that hash collisions don't exist (see comment above)
meta-sha256-cr : ¬ (NonInjective-≡ sha256)
sameSig⇒sameVoteDataNoCol : ∀ {v1 v2 : Vote} {pk}
→ WithVerSig pk v1
→ WithVerSig pk v2
→ v1 ^∙ vSignature ≡ v2 ^∙ vSignature
→ v2 ^∙ vVoteData ≡ v1 ^∙ vVoteData
sameSig⇒sameVoteDataNoCol {v1} {v2} wvs1 wvs2 refl
with sameSig⇒sameVoteData {v1} {v2} wvs1 wvs2 refl
...| inj₁ hb = ⊥-elim (meta-sha256-cr hb)
...| inj₂ x = x
module PerEpoch (𝓔 : EpochConfig) where
open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 (ConcreteVoteEvidence 𝓔) as Abs hiding (qcVotes; Vote)
open import LibraBFT.Concrete.Intermediate 𝓔 (ConcreteVoteEvidence 𝓔)
open import LibraBFT.Concrete.Records 𝓔
-- * Auxiliary definitions;
-- Here we capture the idea that there exists a vote message that
-- witnesses the existence of a given Abs.Vote
record ∃VoteMsgFor (v : Abs.Vote) : Set where
constructor mk∃VoteMsgFor
field
-- A message that was actually sent
nm : NetworkMsg
cv : Vote
cv∈nm : cv ⊂Msg nm
-- And contained a valid vote that, once abstracted, yeilds v.
vmsgMember : EpochConfig.Member 𝓔
vmsgSigned : WithVerSig (getPubKey 𝓔 vmsgMember) cv
vmsg≈v : α-ValidVote 𝓔 cv vmsgMember ≡ v
vmsgEpoch : cv ^∙ vEpoch ≡ epoch 𝓔
open ∃VoteMsgFor public
record ∃VoteMsgSentFor (sm : SentMessages)(v : Abs.Vote) : Set where
constructor mk∃VoteMsgSentFor
field
vmFor : ∃VoteMsgFor v
vmSender : NodeId
nmSentByAuth : (vmSender , (nm vmFor)) ∈ sm
open ∃VoteMsgSentFor public
∃VoteMsgSentFor-stable : ∀ {pre : SystemState} {post : SystemState} {v}
→ Step pre post
→ ∃VoteMsgSentFor (msgPool pre) v
→ ∃VoteMsgSentFor (msgPool post) v
∃VoteMsgSentFor-stable theStep (mk∃VoteMsgSentFor sndr vmFor sba) =
mk∃VoteMsgSentFor sndr vmFor (msgs-stable theStep sba)
∈QC⇒sent : ∀{st : SystemState} {q α}
→ Abs.Q q α-Sent (msgPool st)
→ Meta-Honest-Member α
→ (vα : α Abs.∈QC q)
→ ∃VoteMsgSentFor (msgPool st) (Abs.∈QC-Vote q vα)
∈QC⇒sent vsent@(ws {sender} {nm} e≡ nm∈st (qc∈NM {cqc} {q} .{nm} valid cqc∈nm q≡)) ha va
with All-reduce⁻ {vdq = Any-lookup va} (α-Vote cqc valid) All-self
(subst (Any-lookup va ∈_) (cong Abs.qVotes q≡) (Any-lookup-correctP va))
...| as , as∈cqc , α≡
with α-Vote-evidence cqc valid as∈cqc | inspect
(α-Vote-evidence cqc valid) as∈cqc
...| ev | [ refl ]
with vote∈qc {vs = as} as∈cqc refl cqc∈nm
...| v∈nm = mk∃VoteMsgSentFor
(mk∃VoteMsgFor nm (₋cveVote ev) v∈nm
(₋ivvMember (₋cveIsValidVote ev))
(₋ivvSigned (₋cveIsValidVote ev)) (sym α≡)
(₋ivvEpoch (₋cveIsValidVote ev)))
sender
nm∈st
-- Finally, we can define the abstract system state corresponding to the concrete state st
IntSystemState : IntermediateSystemState ℓ0
IntSystemState = record
{ InSys = λ { r → r α-Sent (msgPool st) }
; HasBeenSent = λ { v → ∃VoteMsgSentFor (msgPool st) v }
; ∈QC⇒HasBeenSent = ∈QC⇒sent {st = st}
}
| {
"alphanum_fraction": 0.6375026545,
"avg_line_length": 49.3089005236,
"ext": "agda",
"hexsha": "fefe80e0a354c67393d32f9c9c77aa9ca526fd1c",
"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/System.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/System.agda",
"max_line_length": 136,
"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/System.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2847,
"size": 9418
} |
------------------------------------------------------------------------
-- The SKI encoding into types
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Undecidable.Encoding where
open import Data.Context.WellFormed
open import Data.List using ([]; _∷_)
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Fin using (Fin; zero; suc; raise)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.ExtraLemmas
open import Relation.Binary.PropositionalEquality hiding ([_])
open import FOmegaInt.Syntax
open import FOmegaInt.Syntax.SingleVariableSubstitution
open import FOmegaInt.Syntax.HereditarySubstitution
open import FOmegaInt.Syntax.Normalization
open import FOmegaInt.Kinding.Canonical
open import FOmegaInt.Undecidable.SK
open Syntax
open ElimCtx
open ContextConversions using (⌞_⌟Ctx)
open RenamingCommutes
open Kinding
open ≡-Reasoning
----------------------------------------------------------------------
-- Support for the encoding: injection of shapes into kinds.
-- For every shape `k' there is a kind `⌈ k ⌉' that erases/simplifies
-- back to `k', i.e. `⌈_⌉' is a right inverse of kind erasure `⌊_⌋'.
--
-- NOTE. The definition here is almost identical to that in
-- FOmegaInt.Typing.Encodings except we inject shapes into `Kind Elim
-- n' rather than `Kind Term n'.
⌈_⌉ : ∀ {n} → SKind → Kind Elim n
⌈ ★ ⌉ = ⌜*⌝
⌈ j ⇒ k ⌉ = Π ⌈ j ⌉ ⌈ k ⌉
⌊⌋∘⌈⌉-id : ∀ {n} k → ⌊ ⌈_⌉ {n} k ⌋ ≡ k
⌊⌋∘⌈⌉-id ★ = refl
⌊⌋∘⌈⌉-id (j ⇒ k) = cong₂ _⇒_ (⌊⌋∘⌈⌉-id j) (⌊⌋∘⌈⌉-id k)
-- The kind `⌈ k ⌉' is well-formed (in any well-formed context).
⌈⌉-kd : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢ ⌈ k ⌉ kd
⌈⌉-kd ★ Γ-ctx = kd-⌜*⌝ Γ-ctx
⌈⌉-kd (j ⇒ k) Γ-ctx =
let ⌈j⌉-kd = ⌈⌉-kd j Γ-ctx
in kd-Π ⌈j⌉-kd (⌈⌉-kd k (wf-kd ⌈j⌉-kd ∷ Γ-ctx))
-- Injected kinds are stable under application of substitutions.
module InjSubstAppLemmas {T : ℕ → Set} (l : Lift T Term) where
open Lift l
open SubstApp l
⌈⌉-Kind/ : ∀ {m n} k {σ : Sub T m n} → ⌈ k ⌉ Kind′/ σ ≡ ⌈ k ⌉
⌈⌉-Kind/ ★ = refl
⌈⌉-Kind/ (j ⇒ k) = cong₂ Π (⌈⌉-Kind/ j) (⌈⌉-Kind/ k)
open Substitution hiding (subst; _[_]; _↑; sub)
open TermSubst termSubst using (varLift; termLift)
open InjSubstAppLemmas varLift public renaming (⌈⌉-Kind/ to ⌈⌉-Kind/Var)
⌈⌉-weaken : ∀ {n} k → weakenKind′ {n} ⌈ k ⌉ ≡ ⌈ k ⌉
⌈⌉-weaken k = ⌈⌉-Kind/Var k
kd-⌈⌉-weaken : ∀ {n} k → weakenElimAsc {n} (kd ⌈ k ⌉) ≡ kd ⌈ k ⌉
kd-⌈⌉-weaken k = cong kd (⌈⌉-weaken k)
kd-⌈⌉-weaken⋆ : ∀ {n k} m → weakenElimAsc⋆ m {n} (kd ⌈ k ⌉) ≡ kd ⌈ k ⌉
kd-⌈⌉-weaken⋆ zero = refl
kd-⌈⌉-weaken⋆ (suc m) =
trans (cong weakenElimAsc (kd-⌈⌉-weaken⋆ m)) (kd-⌈⌉-weaken _)
lookup-raise-* : ∀ {n m} {Γ : Ctx n} (E : CtxExt n m) {x} k →
lookup Γ x ≡ kd ⌈ k ⌉ →
lookup (E ++ Γ) (raise m x) ≡ kd ⌈ k ⌉
lookup-raise-* {_} {m} {Γ} E {x} k hyp = begin
lookup (E ++ Γ) (raise m x) ≡⟨ lookup-weaken⋆ m E Γ x ⟩
weakenElimAsc⋆ m (lookup Γ x) ≡⟨ cong (weakenElimAsc⋆ m) hyp ⟩
weakenElimAsc⋆ m (kd ⌈ k ⌉) ≡⟨ kd-⌈⌉-weaken⋆ m ⟩
kd ⌈ k ⌉ ∎
where
------------------------------------------------------------------------
-- Encoding of SK terms into types
-- The encoding uses 7 type variables:
--
-- 2 nullary operators encoding the combinators S and K,
-- 1 binary operator encoding application,
-- 2 ternary operators encoding the S reduction/expansion laws,
-- 2 binary operators encoding the K reduction/expansion laws.
--
-- We define some pattern synonyms for readability of definitions.
|Γ| = 7
pattern x₀ = zero
pattern x₁ = suc zero
pattern x₂ = suc (suc zero)
pattern x₃ = suc (suc (suc zero))
pattern x₄ = suc (suc (suc (suc zero)))
pattern x₅ = suc (suc (suc (suc (suc zero))))
pattern x₆ = suc (suc (suc (suc (suc (suc zero)))))
module _ {n} where
-- Shorthands to help with the encodings
v₀ : Elim (1 + n)
v₀ = var∙ x₀
v₁ : Elim (2 + n)
v₁ = var∙ x₁
v₂ : Elim (3 + n)
v₂ = var∙ x₂
module EncodingWeakened {n} m where
-- NOTE. Here we assume (m + 3) variables in context, with the names
-- of S, K and App being the first three.
infixl 9 _⊛_
encS : Elim (m + (3 + n))
encS = var∙ (raise m x₂)
encK : Elim (m + (3 + n))
encK = var∙ (raise m x₁)
_⊛_ : (a b : Elim (m + (3 + n))) → Elim (m + (3 + n))
a ⊛ b = var (raise m x₀) ∙ (a ∷ b ∷ [])
-- Encoding of SK terms into raw types with (m + 3) free variables.
encode : SKTerm → Elim (m + (3 + n))
encode S = encS
encode K = encK
encode (s · t) = (encode s) ⊛ (encode t)
module Encoding = EncodingWeakened {0} 4
module _ {n} where
-- Operator kinds for combinator terms.
kdS : Kind Elim (0 + n)
kdS = ⌜*⌝
kdK : Kind Elim (1 + n)
kdK = ⌜*⌝
kdApp : Kind Elim (2 + n)
kdApp = Π ⌜*⌝ (Π ⌜*⌝ ⌜*⌝)
-- Operator kinds reduction/expansion laws.
kdSRed : Kind Elim (3 + n)
kdSRed = Π ⌜*⌝ (Π ⌜*⌝ (Π ⌜*⌝
(encS ⊛ v₂ ⊛ v₁ ⊛ v₀ ⋯ v₂ ⊛ v₀ ⊛ (v₁ ⊛ v₀))))
where open EncodingWeakened (3 + 0)
kdKRed : Kind Elim (4 + n)
kdKRed = Π ⌜*⌝ (Π ⌜*⌝
(encK ⊛ v₁ ⊛ v₀ ⋯ v₁))
where open EncodingWeakened (2 + 1)
kdSExp : Kind Elim (5 + n)
kdSExp = Π ⌜*⌝ (Π ⌜*⌝ (Π ⌜*⌝
(v₂ ⊛ v₀ ⊛ (v₁ ⊛ v₀) ⋯ encS ⊛ v₂ ⊛ v₁ ⊛ v₀)))
where open EncodingWeakened (3 + 2)
kdKExp : Kind Elim (6 + n)
kdKExp = Π ⌜*⌝ (Π ⌜*⌝
(v₁ ⋯ encK ⊛ v₁ ⊛ v₀))
where open EncodingWeakened (2 + 3)
-- The context for the SK encoding (aka the signature)
Γ-SK : Ctx 3
Γ-SK = kd kdApp ∷ kd kdK ∷ kd kdS ∷ []
Γ-SK? : Ctx |Γ|
Γ-SK? = kd kdKExp ∷ kd kdSExp ∷ kd kdKRed ∷ kd kdSRed ∷ Γ-SK
⌞Γ-SK?⌟ : TermCtx.Ctx |Γ|
⌞Γ-SK?⌟ = ⌞ Γ-SK? ⌟Ctx
module _ where
open Encoding
private Γ-nf = nfCtx ⌞Γ-SK?⌟
-- Encoded SK terms are in normal form.
nf-encode : ∀ t → nf Γ-nf ⌞ encode t ⌟ ≡ encode t
nf-encode S = refl
nf-encode K = refl
nf-encode (s · t) =
cong₂ _⊛_ (begin
weakenElim (nf Γ-nf ⌞ encode s ⌟) /⟨ ★ ⟩ sub (nf Γ-nf ⌞ encode t ⌟)
≡⟨ /Var-wk-↑⋆-hsub-vanishes 0 (nf Γ-nf ⌞ encode s ⌟) ⟩
nf Γ-nf ⌞ encode s ⌟
≡⟨ nf-encode s ⟩
encode s
∎) (nf-encode t)
------------------------------------------------------------------------
-- Canonical operator kinding of encodings
module KindedEncodingWeakened {m} (E : CtxExt 3 m)
(Γ-ctx : E ++ Γ-SK ctx) where
open EncodingWeakened {0} m
private Γ = E ++ Γ-SK
-- Kinded encodings of the SK terms
Ne∈-S : Γ ⊢Ne encS ∈ ⌜*⌝
Ne∈-S = ∈-∙ (⇉-var _ Γ-ctx (lookup-raise-* E ★ refl)) ⇉-[]
Ne∈-K : Γ ⊢Ne encK ∈ ⌜*⌝
Ne∈-K = ∈-∙ (⇉-var _ Γ-ctx (lookup-raise-* E ★ refl)) ⇉-[]
Ne∈-⊛ : ∀ {a b} → Γ ⊢Ne a ∈ ⌜*⌝ → Γ ⊢Ne b ∈ ⌜*⌝ → Γ ⊢Ne a ⊛ b ∈ ⌜*⌝
Ne∈-⊛ a∈* b∈* =
∈-∙ (⇉-var _ Γ-ctx (lookup-raise-* E (★ ⇒ ★ ⇒ ★) refl))
(⇉-∷ (Nf⇇-ne a∈*) (kd-⌜*⌝ Γ-ctx)
(⇉-∷ (Nf⇇-ne b∈*) (kd-⌜*⌝ Γ-ctx) ⇉-[]))
Ne∈-encode : (t : SKTerm) → Γ ⊢Ne encode t ∈ ⌜*⌝
Ne∈-encode S = Ne∈-S
Ne∈-encode K = Ne∈-K
Ne∈-encode (s · t) = Ne∈-⊛ (Ne∈-encode s) (Ne∈-encode t)
-- Another shorthand
Ne∈-var : ∀ {n} {Γ : Ctx n} {k} x →
Γ ctx → lookup Γ x ≡ kd k → Γ ⊢Ne var∙ x ∈ k
Ne∈-var x Γ-ctx Γ[x]≡k = ∈-∙ (⇉-var x Γ-ctx Γ[x]≡k) ⇉-[]
-- The signatures Γ-SK and Γ-SK? are well-formed
kdS-kd : [] ⊢ kdS kd
kdS-kd = kd-⌜*⌝ []
Γ₁-ctx : kd kdS ∷ [] ctx
Γ₁-ctx = wf-kd kdS-kd ∷ []
kdK-kd : kd kdS ∷ [] ⊢ kdK kd
kdK-kd = kd-⌜*⌝ Γ₁-ctx
Γ₂-ctx : kd kdK ∷ kd kdS ∷ [] ctx
Γ₂-ctx = wf-kd kdK-kd ∷ Γ₁-ctx
kdApp-kd : kd kdK ∷ kd kdS ∷ [] ⊢ kdApp kd
kdApp-kd = kd-Π *₂-kd (kd-Π *₃-kd (kd-⌜*⌝ (wf-kd *₃-kd ∷ Γ₃-ctx′)))
where
*₂-kd = kd-⌜*⌝ Γ₂-ctx
Γ₃-ctx′ = wf-kd *₂-kd ∷ Γ₂-ctx
*₃-kd = kd-⌜*⌝ Γ₃-ctx′
Γ-SK-ctx : Γ-SK ctx
Γ-SK-ctx = wf-kd kdApp-kd ∷ Γ₂-ctx
kdSRed-kd : Γ-SK ⊢ kdSRed kd
kdSRed-kd = kd-Π *₃-kd (kd-Π *₄-kd (kd-Π *₅-kd (kd-⋯
(⇉-s-i (Ne∈-⊛ (Ne∈-⊛ (Ne∈-⊛ Ne∈-S (Ne∈-var x₂ Γ₆-ctx′ refl))
(Ne∈-var x₁ Γ₆-ctx′ refl)) (Ne∈-var x₀ Γ₆-ctx′ refl)))
(⇉-s-i (Ne∈-⊛ (Ne∈-⊛ (Ne∈-var x₂ Γ₆-ctx′ refl) (Ne∈-var x₀ Γ₆-ctx′ refl))
(Ne∈-⊛ (Ne∈-var x₁ Γ₆-ctx′ refl) (Ne∈-var x₀ Γ₆-ctx′ refl)))))))
where
*₃-kd = kd-⌜*⌝ Γ-SK-ctx
Γ₄-ctx′ = wf-kd *₃-kd ∷ Γ-SK-ctx
*₄-kd = kd-⌜*⌝ Γ₄-ctx′
Γ₅-ctx′ = wf-kd *₄-kd ∷ Γ₄-ctx′
*₅-kd = kd-⌜*⌝ Γ₅-ctx′
Γ₆-ctx′ = wf-kd *₅-kd ∷ Γ₅-ctx′
open KindedEncodingWeakened (kd ⌜*⌝ ∷ kd ⌜*⌝ ∷ kd ⌜*⌝ ∷ []) Γ₆-ctx′
Γ₄-ctx : kd kdSRed ∷ Γ-SK ctx
Γ₄-ctx = wf-kd kdSRed-kd ∷ Γ-SK-ctx
kdKRed-kd : kd kdSRed ∷ Γ-SK ⊢ kdKRed kd
kdKRed-kd = (kd-Π *₄-kd (kd-Π *₅-kd (kd-⋯
(⇉-s-i (Ne∈-⊛ (Ne∈-⊛ Ne∈-K (Ne∈-var x₁ Γ₆-ctx′ refl))
(Ne∈-var x₀ Γ₆-ctx′ refl)))
(⇉-s-i (Ne∈-var x₁ Γ₆-ctx′ refl)))))
where
*₄-kd = kd-⌜*⌝ Γ₄-ctx
Γ₅-ctx′ = wf-kd *₄-kd ∷ Γ₄-ctx
*₅-kd = kd-⌜*⌝ Γ₅-ctx′
Γ₆-ctx′ = wf-kd *₅-kd ∷ Γ₅-ctx′
open KindedEncodingWeakened (kd ⌜*⌝ ∷ kd ⌜*⌝ ∷ kd kdSRed ∷ []) Γ₆-ctx′
Γ₅-ctx : kd kdKRed ∷ kd kdSRed ∷ Γ-SK ctx
Γ₅-ctx = wf-kd kdKRed-kd ∷ Γ₄-ctx
kdSExp-kd : kd kdKRed ∷ kd kdSRed ∷ Γ-SK ⊢ kdSExp kd
kdSExp-kd = kd-Π *₅-kd (kd-Π *₆-kd (kd-Π *₇-kd (kd-⋯
(⇉-s-i (Ne∈-⊛ (Ne∈-⊛ (Ne∈-var x₂ Γ₈-ctx′ refl) (Ne∈-var x₀ Γ₈-ctx′ refl))
(Ne∈-⊛ (Ne∈-var x₁ Γ₈-ctx′ refl) (Ne∈-var x₀ Γ₈-ctx′ refl))))
(⇉-s-i (Ne∈-⊛ (Ne∈-⊛ (Ne∈-⊛ Ne∈-S (Ne∈-var x₂ Γ₈-ctx′ refl))
(Ne∈-var x₁ Γ₈-ctx′ refl))
(Ne∈-var x₀ Γ₈-ctx′ refl))))))
where
*₅-kd = kd-⌜*⌝ Γ₅-ctx
Γ₆-ctx′ = wf-kd *₅-kd ∷ Γ₅-ctx
*₆-kd = kd-⌜*⌝ Γ₆-ctx′
Γ₇-ctx′ = wf-kd *₆-kd ∷ Γ₆-ctx′
*₇-kd = kd-⌜*⌝ Γ₇-ctx′
Γ₈-ctx′ = wf-kd *₇-kd ∷ Γ₇-ctx′
open KindedEncodingWeakened
(kd ⌜*⌝ ∷ kd ⌜*⌝ ∷ kd ⌜*⌝ ∷ kd kdKRed ∷ kd kdSRed ∷ []) Γ₈-ctx′
Γ₆-ctx : kd kdSExp ∷ kd kdKRed ∷ kd kdSRed ∷ Γ-SK ctx
Γ₆-ctx = wf-kd kdSExp-kd ∷ Γ₅-ctx
kdKExp-kd : kd kdSExp ∷ kd kdKRed ∷ kd kdSRed ∷ Γ-SK ⊢ kdKExp kd
kdKExp-kd = (kd-Π *₆-kd (kd-Π *₇-kd (kd-⋯
(⇉-s-i (Ne∈-var x₁ Γ₈-ctx′ refl))
(⇉-s-i (Ne∈-⊛ (Ne∈-⊛ Ne∈-K (Ne∈-var x₁ Γ₈-ctx′ refl))
(Ne∈-var x₀ Γ₈-ctx′ refl))))))
where
*₆-kd = kd-⌜*⌝ Γ₆-ctx
Γ₇-ctx′ = wf-kd *₆-kd ∷ Γ₆-ctx
*₇-kd = kd-⌜*⌝ Γ₇-ctx′
Γ₈-ctx′ = wf-kd *₇-kd ∷ Γ₇-ctx′
open KindedEncodingWeakened
(kd ⌜*⌝ ∷ kd ⌜*⌝ ∷ kd kdSExp ∷ kd kdKRed ∷ kd kdSRed ∷ []) Γ₈-ctx′
Γ-SK?-ctx : Γ-SK? ctx
Γ-SK?-ctx = wf-kd kdKExp-kd ∷ Γ₆-ctx
module KindedEncoding =
KindedEncodingWeakened
(kd kdKExp ∷ kd kdSExp ∷ kd kdKRed ∷ kd kdSRed ∷ []) Γ-SK?-ctx
------------------------------------------------------------------------
-- Encoding of SK term equality in canonical subtyping
open Encoding
open KindedEncoding
-- Some helper lemmas.
wk-hsub-helper : ∀ {n} (a b c : Elim n) →
(weakenElim (weakenElim a) /⟨ ★ ⟩ sub b ↑) [ c ∈ ★ ] ≡ a
wk-hsub-helper a b c = begin
(weakenElim (weakenElim a) /⟨ ★ ⟩ sub b ↑) [ c ∈ ★ ]
≡⟨ cong (λ a → (a /⟨ ★ ⟩ sub b ↑) [ c ∈ ★ ]) (ELV.wk-commutes a) ⟩
(weakenElim a Elim/Var V.wk V.↑ /⟨ ★ ⟩ sub b ↑) [ c ∈ ★ ]
≡⟨ cong (_[ c ∈ ★ ]) (/Var-wk-↑⋆-hsub-vanishes 1 (weakenElim a)) ⟩
weakenElim a [ c ∈ ★ ]
≡⟨ /Var-wk-↑⋆-hsub-vanishes 0 a ⟩
a
∎
where
module EL = TermLikeLemmas termLikeLemmasElim
module ELV = LiftAppLemmas EL.varLiftAppLemmas
module V = VarSubst
-- Admissible kinding and subtyping rules for construction the encoded
-- SK derivations.
<:-⊛ : ∀ {a₁ a₂ b₁ b₂} → Γ-SK? ⊢ a₁ ≃ a₂ ⇇ ⌜*⌝ → Γ-SK? ⊢ b₁ ≃ b₂ ⇇ ⌜*⌝ →
Γ-SK? ⊢ a₁ ⊛ b₁ <: a₂ ⊛ b₂
<:-⊛ a₁≃a₂ b₁≃b₂ = <:-∙ (⇉-var _ Γ-SK?-ctx refl) (≃-∷ a₁≃a₂ (≃-∷ b₁≃b₂ ≃-[]))
Ne∈-Sᵣ : ∀ {a b c} →
Γ-SK? ⊢Ne a ∈ ⌜*⌝ → Γ-SK? ⊢Ne b ∈ ⌜*⌝ → Γ-SK? ⊢Ne c ∈ ⌜*⌝ →
Γ-SK? ⊢Ne var x₃ ∙ (a ∷ b ∷ c ∷ []) ∈
encS ⊛ a ⊛ b ⊛ c ⋯ a ⊛ c ⊛ (b ⊛ c)
Ne∈-Sᵣ {a} {b} {c} a∈* b∈* c∈* =
∈-∙ (⇉-var _ Γ-SK?-ctx refl)
(⇉-∷ (Nf⇇-ne a∈*) *-kd
(⇉-∷ (Nf⇇-ne b∈*) *-kd (⇉-∷ (Nf⇇-ne c∈*) *-kd ⇉-[]′)))
where
*-kd = kd-⌜*⌝ Γ-SK?-ctx
a≡⟨⟨a/wk⟩/wk⟩[b][c] = wk-hsub-helper a b c
b≡⟨b/wk⟩[c] = /Var-wk-↑⋆-hsub-vanishes 0 b
⇉-[]′ =
subst₂ (λ a′ b′ →
Γ-SK? ⊢ encS ⊛ a′ ⊛ b′ ⊛ c ⋯ a′ ⊛ c ⊛ (b′ ⊛ c) ⇉∙ [] ⇉
encS ⊛ a ⊛ b ⊛ c ⋯ a ⊛ c ⊛ (b ⊛ c))
(sym a≡⟨⟨a/wk⟩/wk⟩[b][c]) (sym b≡⟨b/wk⟩[c]) ⇉-[]
<:-Sᵣ : ∀ {a b c} →
Γ-SK? ⊢Ne a ∈ ⌜*⌝ → Γ-SK? ⊢Ne b ∈ ⌜*⌝ → Γ-SK? ⊢Ne c ∈ ⌜*⌝ →
Γ-SK? ⊢ encS ⊛ a ⊛ b ⊛ c <: a ⊛ c ⊛ (b ⊛ c)
<:-Sᵣ a∈* b∈* c∈* =
<:-trans (<:-⟨| (Ne∈-Sᵣ a∈* b∈* c∈*)) (<:-|⟩ (Ne∈-Sᵣ a∈* b∈* c∈*))
Ne∈-Kᵣ : ∀ {a b} → Γ-SK? ⊢Ne a ∈ ⌜*⌝ → Γ-SK? ⊢Ne b ∈ ⌜*⌝ →
Γ-SK? ⊢Ne var x₂ ∙ (a ∷ b ∷ []) ∈ encK ⊛ a ⊛ b ⋯ a
Ne∈-Kᵣ {a} {b} a∈* b∈* =
∈-∙ (⇉-var _ Γ-SK?-ctx refl)
(⇉-∷ (Nf⇇-ne a∈*) *-kd
(⇉-∷ (Nf⇇-ne b∈*) *-kd ⇉-[]′))
where
*-kd = kd-⌜*⌝ Γ-SK?-ctx
⇉-[]′ =
subst (λ a′ → Γ-SK? ⊢ encK ⊛ a′ ⊛ b ⋯ a′ ⇉∙ [] ⇉ encK ⊛ a ⊛ b ⋯ a)
(sym (/Var-wk-↑⋆-hsub-vanishes 0 a)) ⇉-[]
<:-Kᵣ : ∀ {a b} → Γ-SK? ⊢Ne a ∈ ⌜*⌝ →
Γ-SK? ⊢Ne b ∈ ⌜*⌝ → Γ-SK? ⊢ encK ⊛ a ⊛ b <: a
<:-Kᵣ a∈* b∈* = <:-trans (<:-⟨| (Ne∈-Kᵣ a∈* b∈*)) (<:-|⟩ (Ne∈-Kᵣ a∈* b∈*))
Ne∈-Sₑ : ∀ {a b c} →
Γ-SK? ⊢Ne a ∈ ⌜*⌝ → Γ-SK? ⊢Ne b ∈ ⌜*⌝ → Γ-SK? ⊢Ne c ∈ ⌜*⌝ →
Γ-SK? ⊢Ne var x₁ ∙ (a ∷ b ∷ c ∷ []) ∈
a ⊛ c ⊛ (b ⊛ c) ⋯ encS ⊛ a ⊛ b ⊛ c
Ne∈-Sₑ {a} {b} {c} a∈* b∈* c∈* =
∈-∙ (⇉-var _ Γ-SK?-ctx refl)
(⇉-∷ (Nf⇇-ne a∈*) *-kd
(⇉-∷ (Nf⇇-ne b∈*) *-kd (⇉-∷ (Nf⇇-ne c∈*) *-kd ⇉-[]′)))
where
*-kd = kd-⌜*⌝ Γ-SK?-ctx
a≡⟨⟨a/wk⟩/wk⟩[b][c] = wk-hsub-helper a b c
b≡⟨b/wk⟩[c] = /Var-wk-↑⋆-hsub-vanishes 0 b
⇉-[]′ =
subst₂ (λ a′ b′ →
Γ-SK? ⊢ a′ ⊛ c ⊛ (b′ ⊛ c) ⋯ encS ⊛ a′ ⊛ b′ ⊛ c ⇉∙ [] ⇉
a ⊛ c ⊛ (b ⊛ c) ⋯ encS ⊛ a ⊛ b ⊛ c)
(sym a≡⟨⟨a/wk⟩/wk⟩[b][c]) (sym b≡⟨b/wk⟩[c]) ⇉-[]
<:-Sₑ : ∀ {a b c} →
Γ-SK? ⊢Ne a ∈ ⌜*⌝ → Γ-SK? ⊢Ne b ∈ ⌜*⌝ → Γ-SK? ⊢Ne c ∈ ⌜*⌝ →
Γ-SK? ⊢ a ⊛ c ⊛ (b ⊛ c) <: encS ⊛ a ⊛ b ⊛ c
<:-Sₑ a∈* b∈* c∈* =
<:-trans (<:-⟨| (Ne∈-Sₑ a∈* b∈* c∈*)) (<:-|⟩ (Ne∈-Sₑ a∈* b∈* c∈*))
Ne∈-Kₑ : ∀ {a b} → Γ-SK? ⊢Ne a ∈ ⌜*⌝ → Γ-SK? ⊢Ne b ∈ ⌜*⌝ →
Γ-SK? ⊢Ne var x₀ ∙ (a ∷ b ∷ []) ∈ a ⋯ encK ⊛ a ⊛ b
Ne∈-Kₑ {a} {b} a∈* b∈* =
∈-∙ (⇉-var _ Γ-SK?-ctx refl)
(⇉-∷ (Nf⇇-ne a∈*) *-kd
(⇉-∷ (Nf⇇-ne b∈*) *-kd ⇉-[]′))
where
*-kd = kd-⌜*⌝ Γ-SK?-ctx
⇉-[]′ =
subst (λ a′ → Γ-SK? ⊢ a′ ⋯ encK ⊛ a′ ⊛ b ⇉∙ [] ⇉ a ⋯ encK ⊛ a ⊛ b)
(sym (/Var-wk-↑⋆-hsub-vanishes 0 a)) ⇉-[]
<:-Kₑ : ∀ {a b} → Γ-SK? ⊢Ne a ∈ ⌜*⌝ →
Γ-SK? ⊢Ne b ∈ ⌜*⌝ → Γ-SK? ⊢ a <: encK ⊛ a ⊛ b
<:-Kₑ a∈* b∈* = <:-trans (<:-⟨| (Ne∈-Kₑ a∈* b∈*)) (<:-|⟩ (Ne∈-Kₑ a∈* b∈*))
-- Encoding of SK term equality in canonical subtyping
mutual
<:-encode : ∀ {s t} → s ≡SK t → Γ-SK? ⊢ encode s <: encode t
<:-encode (≡-refl {t}) = <:-reflNf⇉ (⇉-s-i (Ne∈-encode t))
<:-encode (≡-trans s≡t t≡u) = <:-trans (<:-encode s≡t) (<:-encode t≡u)
<:-encode (≡-sym t≡s) = :>-encode t≡s
<:-encode (≡-Sred {s} {t} {u}) =
<:-Sᵣ (Ne∈-encode s) (Ne∈-encode t) (Ne∈-encode u)
<:-encode (≡-Kred {s} {t}) = <:-Kᵣ (Ne∈-encode s) (Ne∈-encode t)
<:-encode (≡-· s₁≡t₁ s₂≡t₂) = <:-⊛ (≃-encode s₁≡t₁) (≃-encode s₂≡t₂)
:>-encode : ∀ {s t} → s ≡SK t → Γ-SK? ⊢ encode t <: encode s
:>-encode (≡-refl {t}) = <:-reflNf⇉ (⇉-s-i (Ne∈-encode t))
:>-encode (≡-trans s≡t t≡u) = <:-trans (:>-encode t≡u) (:>-encode s≡t)
:>-encode (≡-sym t≡s) = <:-encode t≡s
:>-encode (≡-Sred {s} {t} {u}) =
<:-Sₑ (Ne∈-encode s) (Ne∈-encode t) (Ne∈-encode u)
:>-encode (≡-Kred {s} {t}) = <:-Kₑ (Ne∈-encode s) (Ne∈-encode t)
:>-encode (≡-· s₁≡t₁ s₂≡t₂) =
<:-⊛ (≃-sym (≃-encode s₁≡t₁)) (≃-sym (≃-encode s₂≡t₂))
≃-encode : ∀ {s t} → s ≡SK t → Γ-SK? ⊢ encode s ≃ encode t ⇇ ⌜*⌝
≃-encode {s} {t} s≡t =
let es⇇* = Nf⇇-ne (Ne∈-encode s)
et⇇* = Nf⇇-ne (Ne∈-encode t)
in <:-antisym (kd-⌜*⌝ Γ-SK?-ctx)
(<:-⇇ es⇇* et⇇* (<:-encode s≡t))
(<:-⇇ et⇇* es⇇* (:>-encode s≡t))
<:⇇-encode : ∀ {s t} → s ≡SK t → Γ-SK? ⊢ encode s <: encode t ⇇ ⌜*⌝
<:⇇-encode {s} {t} s≡t =
<:-⇇ (Nf⇇-ne (Ne∈-encode s)) (Nf⇇-ne (Ne∈-encode t)) (<:-encode s≡t)
| {
"alphanum_fraction": 0.4723568145,
"avg_line_length": 32.0677290837,
"ext": "agda",
"hexsha": "b8f8b10fde87341070f93abd6ef83e0dfc8cdfd7",
"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": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/FOmegaInt/Undecidable/Encoding.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"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": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/FOmegaInt/Undecidable/Encoding.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/FOmegaInt/Undecidable/Encoding.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8724,
"size": 16098
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.OrderedCommMonoid.Instances where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.OrderedCommMonoid.Base
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order
ℕ≤+ : OrderedCommMonoid ℓ-zero ℓ-zero
ℕ≤+ .fst = ℕ
ℕ≤+ .snd .OrderedCommMonoidStr._≤_ = _≤_
ℕ≤+ .snd .OrderedCommMonoidStr._·_ = _+_
ℕ≤+ .snd .OrderedCommMonoidStr.ε = 0
ℕ≤+ .snd .OrderedCommMonoidStr.isOrderedCommMonoid =
makeIsOrderedCommMonoid
isSetℕ
+-assoc +-zero (λ _ → refl) +-comm
(λ _ _ → isProp≤) (λ _ → ≤-refl) (λ _ _ _ → ≤-trans) (λ _ _ → ≤-antisym)
(λ _ _ _ → ≤-+k) (λ _ _ _ → ≤-k+)
ℕ≤· : OrderedCommMonoid ℓ-zero ℓ-zero
ℕ≤· .fst = ℕ
ℕ≤· .snd .OrderedCommMonoidStr._≤_ = _≤_
ℕ≤· .snd .OrderedCommMonoidStr._·_ = _·_
ℕ≤· .snd .OrderedCommMonoidStr.ε = 1
ℕ≤· .snd .OrderedCommMonoidStr.isOrderedCommMonoid =
makeIsOrderedCommMonoid
isSetℕ
·-assoc ·-identityʳ ·-identityˡ ·-comm
(λ _ _ → isProp≤) (λ _ → ≤-refl) (λ _ _ _ → ≤-trans) (λ _ _ → ≤-antisym)
(λ _ _ _ → ≤-·k) lmono
where lmono : (x y z : ℕ) → x ≤ y → z · x ≤ z · y
lmono x y z x≤y = subst ((z · x) ≤_) (·-comm y z) (subst (_≤ (y · z)) (·-comm x z) (≤-·k x≤y))
| {
"alphanum_fraction": 0.6102236422,
"avg_line_length": 34.7777777778,
"ext": "agda",
"hexsha": "ca6dbb984a54e1efe3ca72b88164411edf4db054",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/OrderedCommMonoid/Instances.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/OrderedCommMonoid/Instances.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/OrderedCommMonoid/Instances.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 530,
"size": 1252
} |
module _ where
open import Common.Prelude
open import Common.Reflection
open import Common.Equality
record Foo (A : Set) : Set where
field
foo : A → Nat
open Foo {{...}}
instance
FooNat : Foo Nat
foo {{FooNat}} n = n
FooBool : Foo Bool
foo {{FooBool}} true = 1
foo {{FooBool}} false = 0
macro
do-foo : ∀ {A} {{_ : Foo A}} → A → Tactic
do-foo x = give (lit (nat (foo x)))
test₁ : do-foo 5 ≡ 5
test₁ = refl
test₂ : do-foo false ≡ 0
test₂ = refl
macro
lastHidden : {n : Nat} → Tactic
lastHidden {n} = give (lit (nat n))
test₃ : lastHidden {4} ≡ 4
test₃ = refl
macro
hiddenTerm : {a : Term} → Tactic
hiddenTerm {a} = give a
test₄ : hiddenTerm {4} ≡ 4
test₄ = refl
| {
"alphanum_fraction": 0.613960114,
"avg_line_length": 15.6,
"ext": "agda",
"hexsha": "78b30bf876c3ea3dd447cc30d8da304a3df31a12",
"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/HiddenMacroArgs.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/HiddenMacroArgs.agda",
"max_line_length": 43,
"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/HiddenMacroArgs.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": 264,
"size": 702
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of membership of vectors based on propositional equality.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Membership.Propositional.Properties where
open import Data.Fin using (Fin; zero; suc)
open import Data.Product as Prod using (_,_; ∃; _×_; -,_)
open import Data.Vec hiding (here; there)
open import Data.Vec.Relation.Unary.Any using (here; there)
open import Data.List using ([]; _∷_)
open import Data.List.Relation.Unary.Any using (here; there)
open import Data.Vec.Relation.Unary.Any using (Any; here; there)
open import Data.Vec.Membership.Propositional
open import Data.List.Membership.Propositional
using () renaming (_∈_ to _∈ₗ_)
open import Function using (_∘_; id)
open import Relation.Unary using (Pred)
open import Relation.Binary.PropositionalEquality using (refl)
------------------------------------------------------------------------
-- lookup
module _ {a} {A : Set a} where
∈-lookup : ∀ {n} i (xs : Vec A n) → lookup xs i ∈ xs
∈-lookup zero (x ∷ xs) = here refl
∈-lookup (suc i) (x ∷ xs) = there (∈-lookup i xs)
------------------------------------------------------------------------
-- map
module _ {a b} {A : Set a} {B : Set b} (f : A → B) where
∈-map⁺ : ∀ {m v} {xs : Vec A m} → v ∈ xs → f v ∈ map f xs
∈-map⁺ (here refl) = here refl
∈-map⁺ (there x∈xs) = there (∈-map⁺ x∈xs)
------------------------------------------------------------------------
-- _++_
module _ {a} {A : Set a} {v : A} where
∈-++⁺ˡ : ∀ {m n} {xs : Vec A m} {ys : Vec A n} → v ∈ xs → v ∈ xs ++ ys
∈-++⁺ˡ (here refl) = here refl
∈-++⁺ˡ (there x∈xs) = there (∈-++⁺ˡ x∈xs)
∈-++⁺ʳ : ∀ {m n} (xs : Vec A m) {ys : Vec A n} → v ∈ ys → v ∈ xs ++ ys
∈-++⁺ʳ [] x∈ys = x∈ys
∈-++⁺ʳ (x ∷ xs) x∈ys = there (∈-++⁺ʳ xs x∈ys)
------------------------------------------------------------------------
-- tabulate
module _ {a} {A : Set a} where
∈-tabulate⁺ : ∀ {n} (f : Fin n → A) i → f i ∈ tabulate f
∈-tabulate⁺ f zero = here refl
∈-tabulate⁺ f (suc i) = there (∈-tabulate⁺ (f ∘ suc) i)
------------------------------------------------------------------------
-- allFin
∈-allFin⁺ : ∀ {n} (i : Fin n) → i ∈ allFin n
∈-allFin⁺ = ∈-tabulate⁺ id
------------------------------------------------------------------------
-- allPairs
module _ {a b} {A : Set a} {B : Set b} where
∈-allPairs⁺ : ∀ {m n x y} {xs : Vec A m} {ys : Vec B n} →
x ∈ xs → y ∈ ys → (x , y) ∈ allPairs xs ys
∈-allPairs⁺ {xs = x ∷ xs} (here refl) = ∈-++⁺ˡ ∘ ∈-map⁺ (x ,_)
∈-allPairs⁺ {xs = x ∷ _} (there x∈xs) =
∈-++⁺ʳ (map (x ,_) _) ∘ ∈-allPairs⁺ x∈xs
------------------------------------------------------------------------
-- toList
module _ {a} {A : Set a} {v : A} where
∈-toList⁺ : ∀ {n} {xs : Vec A n} → v ∈ xs → v ∈ₗ toList xs
∈-toList⁺ (here refl) = here refl
∈-toList⁺ (there x∈) = there (∈-toList⁺ x∈)
∈-toList⁻ : ∀ {n} {xs : Vec A n} → v ∈ₗ toList xs → v ∈ xs
∈-toList⁻ {xs = []} ()
∈-toList⁻ {xs = x ∷ xs} (here refl) = here refl
∈-toList⁻ {xs = x ∷ xs} (there v∈xs) = there (∈-toList⁻ v∈xs)
------------------------------------------------------------------------
-- fromList
module _ {a} {A : Set a} {v : A} where
∈-fromList⁺ : ∀ {xs} → v ∈ₗ xs → v ∈ fromList xs
∈-fromList⁺ (here refl) = here refl
∈-fromList⁺ (there x∈) = there (∈-fromList⁺ x∈)
∈-fromList⁻ : ∀ {xs} → v ∈ fromList xs → v ∈ₗ xs
∈-fromList⁻ {[]} ()
∈-fromList⁻ {_ ∷ _} (here refl) = here refl
∈-fromList⁻ {_ ∷ _} (there v∈xs) = there (∈-fromList⁻ v∈xs)
------------------------------------------------------------------------
-- Relationship to Any
module _ {a p} {A : Set a} {P : Pred A p} where
fromAny : ∀ {n} {xs : Vec A n} → Any P xs → ∃ λ x → x ∈ xs × P x
fromAny (here px) = -, here refl , px
fromAny (there v) = Prod.map₂ (Prod.map₁ there) (fromAny v)
toAny : ∀ {n x} {xs : Vec A n} → x ∈ xs → P x → Any P xs
toAny (here refl) px = here px
toAny (there v) px = there (toAny v px)
| {
"alphanum_fraction": 0.4444978376,
"avg_line_length": 34.1147540984,
"ext": "agda",
"hexsha": "c86014e7006171e9d0eedd0045fbefea30329c73",
"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/Membership/Propositional/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/Vec/Membership/Propositional/Properties.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/Membership/Propositional/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1438,
"size": 4162
} |
module Issue357a where
module M (X : Set) where
data R : Set where
r : X → R
postulate
P Q : Set
q : Q
open M P
open M.R
works : M.R Q → Q
works (M.R.r q) = q
fails : M.R Q → Q
fails (r q) = q
| {
"alphanum_fraction": 0.5471698113,
"avg_line_length": 10.0952380952,
"ext": "agda",
"hexsha": "7fb63946ea46714639e3d057e6ed122759c6713b",
"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/Issue357a.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/Issue357a.agda",
"max_line_length": 24,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue357a.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": 87,
"size": 212
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra.Structures.Bundles.Field
import Algebra.Linear.Structures.Bundles.FiniteDimensional as FDB
module Algebra.Linear.Space.FiniteDimensional.Product
{k ℓᵏ} (K : Field k ℓᵏ)
{n a₁ ℓ₁} (V₁-space : FDB.FiniteDimensional K a₁ ℓ₁ n)
{p a₂ ℓ₂} (V₂-space : FDB.FiniteDimensional K a₂ ℓ₂ p)
where
open import Algebra.Linear.Structures.VectorSpace K
open import Algebra.Linear.Structures.Bundles as VS
open import Algebra.Linear.Structures.FiniteDimensional K
open import Algebra.Linear.Morphism.Bundles K
open VectorSpaceField
open FDB.FiniteDimensional V₁-space
using ()
renaming
( Carrier to V₁
; _≈_ to _≈₁_
; isEquivalence to ≈₁-isEquiv
; refl to ≈₁-refl
; sym to ≈₁-sym
; trans to ≈₁-trans
; reflexive to ≈₁-reflexive
; _+_ to _+₁_
; _∙_ to _∙₁_
; -_ to -₁_
; 0# to 0₁
; +-identityˡ to +₁-identityˡ
; +-identityʳ to +₁-identityʳ
; +-identity to +₁-identity
; +-cong to +₁-cong
; +-assoc to +₁-assoc
; +-comm to +₁-comm
; *ᵏ-∙-compat to *ᵏ-∙₁-compat
; ∙-+-distrib to ∙₁-+₁-distrib
; ∙-+ᵏ-distrib to ∙₁-+ᵏ-distrib
; ∙-cong to ∙₁-cong
; ∙-identity to ∙₁-identity
; ∙-absorbˡ to ∙₁-absorbˡ
; ∙-absorbʳ to ∙₁-absorbʳ
; -‿cong to -₁‿cong
; -‿inverseˡ to -₁‿inverseˡ
; -‿inverseʳ to -₁‿inverseʳ
; vectorSpace to vectorSpace₁
; embed to embed₁
)
open FDB.FiniteDimensional V₂-space
using ()
renaming
( Carrier to V₂
; _≈_ to _≈₂_
; isEquivalence to ≈₂-isEquiv
; refl to ≈₂-refl
; sym to ≈₂-sym
; trans to ≈₂-trans
; reflexive to ≈₂-reflexive
; _+_ to _+₂_
; _∙_ to _∙₂_
; -_ to -₂_
; 0# to 0₂
; +-identityˡ to +₂-identityˡ
; +-identityʳ to +₂-identityʳ
; +-identity to +₂-identity
; +-cong to +₂-cong
; +-assoc to +₂-assoc
; +-comm to +₂-comm
; *ᵏ-∙-compat to *ᵏ-∙₂-compat
; ∙-+-distrib to ∙₂-+₂-distrib
; ∙-+ᵏ-distrib to ∙₂-+ᵏ-distrib
; ∙-cong to ∙₂-cong
; ∙-identity to ∙₂-identity
; ∙-absorbˡ to ∙₂-absorbˡ
; ∙-absorbʳ to ∙₂-absorbʳ
; -‿cong to -₂‿cong
; -‿inverseˡ to -₂‿inverseˡ
; -‿inverseʳ to -₂‿inverseʳ
; vectorSpace to vectorSpace₂
; embed to embed₂
)
open LinearIsomorphism embed₁
using ()
renaming
( ⟦_⟧ to ⟦_⟧₁
; ⟦⟧-cong to ⟦⟧₁-cong
; injective to ⟦⟧₁-injective
; surjective to ⟦⟧₁-surjective
; +-homo to +₁-homo
; ∙-homo to ∙₁-homo
; 0#-homo to 0₁-homo
)
open LinearIsomorphism embed₂
using ()
renaming
( ⟦_⟧ to ⟦_⟧₂
; ⟦⟧-cong to ⟦⟧₂-cong
; injective to ⟦⟧₂-injective
; surjective to ⟦⟧₂-surjective
; +-homo to +₂-homo
; ∙-homo to ∙₂-homo
; 0#-homo to 0₂-homo
)
open import Data.Product
import Algebra.Linear.Construct.ProductSpace K vectorSpace₁ vectorSpace₂ as PS
open VS.VectorSpace PS.vectorSpace
renaming
( refl to ≈-refl
; sym to ≈-sym
; trans to ≈-trans
)
open import Algebra.Linear.Construct.Vector K
using
( ++-cong
; ++-identityˡ
; ++-split
; +-distrib-++
; ∙-distrib-++
; 0++0≈0
)
renaming
( _≈_ to _≈v_
; ≈-refl to ≈v-refl
; ≈-sym to ≈v-sym
; ≈-trans to ≈v-trans
; ≈-reflexive to ≈v-reflexive
; _+_ to _+v_
; _∙_ to _∙v_
; 0# to 0v
; +-cong to +v-cong
; setoid to vec-setoid
; vectorSpace to vector-vectorSpace
)
open import Data.Nat using (ℕ) renaming (_+_ to _+ℕ_)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; subst; subst-subst-sym)
renaming
( refl to ≡-refl
; sym to ≡-sym
; trans to ≡-trans
)
open import Data.Vec
open import Algebra.Morphism.Definitions (V₁ × V₂) (Vec K' (n +ℕ p)) _≈v_
open import Algebra.Linear.Morphism.Definitions K (V₁ × V₂) (Vec K' (n +ℕ p)) _≈v_
import Relation.Binary.Morphism.Definitions (V₁ × V₂) (Vec K' (n +ℕ p)) as R
open import Function
open import Relation.Binary.EqReasoning (vec-setoid (n +ℕ p))
⟦_⟧ : V₁ × V₂ -> Vec K' (n +ℕ p)
⟦ (u , v) ⟧ = ⟦ u ⟧₁ ++ ⟦ v ⟧₂
⟦⟧-cong : R.Homomorphic₂ PS._≈_ _≈v_ ⟦_⟧
⟦⟧-cong (r₁ , r₂) = ++-cong (⟦⟧₁-cong r₁) (⟦⟧₂-cong r₂)
+-homo : Homomorphic₂ ⟦_⟧ _+_ _+v_
+-homo (x₁ , x₂) (y₁ , y₂) =
begin
⟦ (x₁ , x₂) + (y₁ , y₂) ⟧
≡⟨⟩
⟦ x₁ +₁ y₁ ⟧₁ ++ ⟦ x₂ +₂ y₂ ⟧₂
≈⟨ ++-cong (+₁-homo x₁ y₁) (+₂-homo x₂ y₂) ⟩
(⟦ x₁ ⟧₁ +v ⟦ y₁ ⟧₁) ++ (⟦ x₂ ⟧₂ +v ⟦ y₂ ⟧₂)
≈⟨ ≈v-sym (+-distrib-++ ⟦ x₁ ⟧₁ ⟦ x₂ ⟧₂ ⟦ y₁ ⟧₁ ⟦ y₂ ⟧₂) ⟩
(⟦ x₁ ⟧₁ ++ ⟦ x₂ ⟧₂) +v (⟦ y₁ ⟧₁ ++ ⟦ y₂ ⟧₂)
≈⟨ +v-cong ≈v-refl ≈v-refl ⟩
⟦ x₁ , x₂ ⟧ +v ⟦ y₁ , y₂ ⟧
∎
0#-homo : Homomorphic₀ ⟦_⟧ 0# 0v
0#-homo =
begin
⟦ 0# ⟧
≡⟨⟩
⟦ 0₁ ⟧₁ ++ ⟦ 0₂ ⟧₂
≈⟨ ++-cong 0₁-homo 0₂-homo ⟩
(0v {n}) ++ (0v {p})
≈⟨ 0++0≈0 {n} {p} ⟩
0v {n +ℕ p}
∎
∙-homo : ScalarHomomorphism ⟦_⟧ _∙_ _∙v_
∙-homo c (x₁ , x₂) =
begin
⟦ c ∙ (x₁ , x₂) ⟧
≈⟨ ++-cong (∙₁-homo c x₁) (∙₂-homo c x₂) ⟩
(c ∙v ⟦ x₁ ⟧₁) ++ (c ∙v ⟦ x₂ ⟧₂)
≈⟨ ≈v-sym (∙-distrib-++ c ⟦ x₁ ⟧₁ ⟦ x₂ ⟧₂) ⟩
c ∙v ⟦ x₁ , x₂ ⟧
∎
⟦⟧-injective : Injective PS._≈_ (_≈v_ {n +ℕ p}) ⟦_⟧
⟦⟧-injective {x₁ , x₂} {y₁ , y₂} r =
let (r₁ , r₂) = ++-split r
in ⟦⟧₁-injective r₁ , ⟦⟧₂-injective r₂
⟦⟧-surjective : Surjective PS._≈_ (_≈v_ {n +ℕ p}) ⟦_⟧
⟦⟧-surjective y =
let (x₁ , x₂ , r) = splitAt n y
(u , r₁) = ⟦⟧₁-surjective x₁
(v , r₂) = ⟦⟧₂-surjective x₂
in (u , v) , ≈v-trans (++-cong r₁ r₂) (≈v-sym (≈v-reflexive r))
embed : LinearIsomorphism PS.vectorSpace (vector-vectorSpace {n +ℕ p})
embed = record
{ ⟦_⟧ = ⟦_⟧
; isLinearIsomorphism = record
{ isLinearMonomorphism = record
{ isLinearMap = record
{ isAbelianGroupMorphism = record
{ gp-homo = record
{ mn-homo = record
{ sm-homo = record
{ ⟦⟧-cong = ⟦⟧-cong
; ∙-homo = +-homo
}
; ε-homo = 0#-homo
}
}
}
; ∙-homo = ∙-homo
}
; injective = ⟦⟧-injective
}
; surjective = ⟦⟧-surjective
}
}
isFiniteDimensional : IsFiniteDimensional _≈_ _+_ _∙_ -_ 0# (n +ℕ p)
isFiniteDimensional = record
{ isVectorSpace = isVectorSpace
; embed = embed
}
| {
"alphanum_fraction": 0.5248194252,
"avg_line_length": 26.5591836735,
"ext": "agda",
"hexsha": "87a7c934ee4164e079a1d00c0ba5cdf637c1c2ee",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Space/FiniteDimensional/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Space/FiniteDimensional/Product.agda",
"max_line_length": 82,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Space/FiniteDimensional/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 2916,
"size": 6507
} |
module Numeral.Sign.Oper where
open import Data.Boolean
open import Numeral.Sign
-- Negation
−_ : (+|−) → (+|−)
− (➕) = (➖)
− (➖) = (➕)
-- Addition
_+_ : (+|−) → (+|−) → (+|0|−)
(➕) + (➕) = (➕)
(➖) + (➖) = (➖)
(➕) + (➖) = (𝟎)
(➖) + (➕) = (𝟎)
-- Multiplication
_⨯_ : (+|−) → (+|−) → (+|−)
(➕) ⨯ (➕) = (➕)
(➖) ⨯ (➖) = (➕)
(➕) ⨯ (➖) = (➖)
(➖) ⨯ (➕) = (➖)
_⋚_ : (+|−) → (+|−) → (+|0|−)
➕ ⋚ ➕ = 𝟎
➕ ⋚ ➖ = ➕
➖ ⋚ ➕ = ➖
➖ ⋚ ➖ = 𝟎
| {
"alphanum_fraction": 0.2599531616,
"avg_line_length": 14.2333333333,
"ext": "agda",
"hexsha": "8dc6076a83f760bab98bfa72a7a48a51a7264021",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Sign/Oper.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Sign/Oper.agda",
"max_line_length": 30,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Sign/Oper.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": 293,
"size": 427
} |
{-# OPTIONS --without-K #-}
module FinEquivCat where
-- We will define a rig category whose objects are Fin types and whose
-- morphisms are type equivalences; and where the equivalence of
-- morphisms ≋ is extensional
open import Level using () renaming (zero to lzero; suc to lsuc)
open import Data.Fin using (Fin; zero; suc)
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.Unit using ()
open import Data.Sum using (_⊎_; inj₁; inj₂) renaming (map to map⊎)
open import Data.Product
using (_,_; proj₁; proj₂;_×_; Σ; uncurry)
renaming (map to map×)
import Function as F using (_∘_; id)
import Relation.Binary.PropositionalEquality as P
using (refl; trans; cong)
open import Categories.Category using (Category)
open import Categories.Groupoid using (Groupoid)
open import Categories.Monoidal using (Monoidal)
open import Categories.Monoidal.Helpers using (module MonoidalHelperFunctors)
open import Categories.Bifunctor using (Bifunctor)
open import Categories.NaturalIsomorphism using (NaturalIsomorphism)
open import Categories.Monoidal.Braided using (Braided)
open import Categories.Monoidal.Symmetric using (Symmetric)
open import Categories.RigCategory
using (RigCategory; module BimonoidalHelperFunctors)
open import Equiv using (id≃; sym≃; _∼_; sym∼; _●_)
open import EquivEquiv
using (_≋_; eq; id≋; sym≋; trans≋; _◎_; ●-assoc; lid≋; rid≋;
linv≋; rinv≋; module _≋_)
open import FinEquivTypeEquiv
using (_fin≃_; module PlusE; module TimesE; module PlusTimesE)
open PlusE using (_+F_; unite+; unite+r; uniti+; uniti+r;
swap+; sswap+; assocl+; assocr+)
open TimesE using (_*F_; unite*; uniti*; unite*r; uniti*r;
swap*; sswap*; assocl*; assocr*)
open PlusTimesE using (distz; factorz; distzr; factorzr;
dist; factor; distl; factorl)
open import FinEquivEquivPlus using (
[id+id]≋id; +●≋●+; _+≋_;
unite₊-nat; unite₊r-nat; uniti₊-nat; uniti₊r-nat;
assocr₊-nat; assocl₊-nat; unite-assocr₊-coh; assocr₊-coh;
swap₊-nat; sswap₊-nat; assocr₊-swap₊-coh; assocl₊-swap₊-coh)
open import FinEquivEquivTimes using (
id*id≋id; *●≋●*; _*≋_;
unite*-nat; unite*r-nat; uniti*-nat; uniti*r-nat;
assocr*-nat; assocl*-nat; unite-assocr*-coh; assocr*-coh;
swap*-nat; sswap*-nat; assocr*-swap*-coh; assocl*-swap*-coh)
open import FinEquivEquivPlusTimes using (
distl-nat; factorl-nat; dist-nat; factor-nat;
distzr-nat; factorzr-nat; distz-nat; factorz-nat;
A×[B⊎C]≃[A×C]⊎[A×B];
[A⊎B]×C≃[C×A]⊎[C×B];
[A⊎B⊎C]×D≃[A×D⊎B×D]⊎C×D;
A×B×[C⊎D]≃[A×B]×C⊎[A×B]×D;
[A⊎B]×[C⊎D]≃[[A×C⊎B×C]⊎A×D]⊎B×D;
0×0≃0;
0×[A⊎B]≃0;
0×1≃0;
A×0≃0;
0×A×B≃0;
A×0×B≃0;
A×[0+B]≃A×B;
1×[A⊎B]≃A⊎B)
------------------------------------------------------------------------------
-- Fin and type equivalences are a category
-- note how all of the 'higher structure' (i.e. ≋ equations) are all
-- generic, i.e. they are true of all equivalences, not just _fin≃_.
FinEquivCat : Category lzero lzero lzero
FinEquivCat = record
{ Obj = ℕ
; _⇒_ = _fin≃_
; _≡_ = _≋_
; id = id≃
; _∘_ = _●_
; assoc = λ { {f = f} {g} {h} → ●-assoc {f = f} {g} {h} }
; identityˡ = lid≋
; identityʳ = rid≋
; equiv = record { refl = id≋ ; sym = sym≋ ; trans = trans≋ }
; ∘-resp-≡ = _◎_
}
FinEquivGroupoid : Groupoid FinEquivCat
FinEquivGroupoid = record
{ _⁻¹ = sym≃
; iso = λ { {f = A≃B} → record
{ isoˡ = linv≋ A≃B
; isoʳ = rinv≋ A≃B
} }
}
-- The additive structure is monoidal
⊎-bifunctor : Bifunctor FinEquivCat FinEquivCat FinEquivCat
⊎-bifunctor = record
{ F₀ = uncurry _+_
; F₁ = uncurry _+F_
; identity = [id+id]≋id
; homomorphism = +●≋●+
; F-resp-≡ = uncurry _+≋_
}
module ⊎h = MonoidalHelperFunctors FinEquivCat ⊎-bifunctor 0
0⊎x≡x : NaturalIsomorphism ⊎h.id⊗x ⊎h.x
0⊎x≡x = record
{ F⇒G = record
{ η = λ _ → unite+
; commute = λ _ → unite₊-nat }
; F⇐G = record
{ η = λ _ → uniti+
; commute = λ _ → uniti₊-nat }
; iso = λ _ → record
{ isoˡ = linv≋ unite+
; isoʳ = rinv≋ unite+
}
}
x⊎0≡x : NaturalIsomorphism ⊎h.x⊗id ⊎h.x
x⊎0≡x = record
{ F⇒G = record
{ η = λ _ → unite+r
; commute = λ _ → unite₊r-nat }
; F⇐G = record
{ η = λ _ → uniti+r
; commute = λ _ → uniti₊r-nat
}
; iso = λ X → record
{ isoˡ = linv≋ unite+r
; isoʳ = rinv≋ unite+r
}
}
[x⊎y]⊎z≡x⊎[y⊎z] : NaturalIsomorphism ⊎h.[x⊗y]⊗z ⊎h.x⊗[y⊗z]
[x⊎y]⊎z≡x⊎[y⊎z] = record
{ F⇒G = record
{ η = λ X → assocr+ {m = X zero}
; commute = λ _ → assocr₊-nat
}
; F⇐G = record
{ η = λ X → assocl+ {m = X zero}
; commute = λ _ → assocl₊-nat
}
; iso = λ X → record
{ isoˡ = linv≋ assocr+
; isoʳ = rinv≋ assocr+
}
}
CPM⊎ : Monoidal FinEquivCat
CPM⊎ = record
{ ⊗ = ⊎-bifunctor
; id = 0
; identityˡ = 0⊎x≡x
; identityʳ = x⊎0≡x
; assoc = [x⊎y]⊎z≡x⊎[y⊎z]
; triangle = unite-assocr₊-coh
; pentagon = assocr₊-coh
}
-- The multiplicative structure is monoidal
×-bifunctor : Bifunctor FinEquivCat FinEquivCat FinEquivCat
×-bifunctor = record
{ F₀ = uncurry _*_
; F₁ = uncurry _*F_
; identity = id*id≋id
; homomorphism = *●≋●*
; F-resp-≡ = uncurry _*≋_
}
module ×h = MonoidalHelperFunctors FinEquivCat ×-bifunctor 1
1×y≡y : NaturalIsomorphism ×h.id⊗x ×h.x
1×y≡y = record
{ F⇒G = record
{ η = λ _ → unite*
; commute = λ _ → unite*-nat
}
; F⇐G = record
{ η = λ _ → uniti*
; commute = λ _ → uniti*-nat
}
; iso = λ X → record
{ isoˡ = linv≋ unite*
; isoʳ = rinv≋ unite*
}
}
y×1≡y : NaturalIsomorphism ×h.x⊗id ×h.x
y×1≡y = record
{ F⇒G = record
{ η = λ X → unite*r
; commute = λ _ → unite*r-nat
}
; F⇐G = record
{ η = λ X → uniti*r
; commute = λ _ → uniti*r-nat
}
; iso = λ X → record
{ isoˡ = linv≋ unite*r
; isoʳ = rinv≋ unite*r
}
}
[x×y]×z≡x×[y×z] : NaturalIsomorphism ×h.[x⊗y]⊗z ×h.x⊗[y⊗z]
[x×y]×z≡x×[y×z] = record
{ F⇒G = record
{ η = λ X → assocr* {m = X zero}
; commute = λ _ → assocr*-nat }
; F⇐G = record
{ η = λ X → assocl* {m = X zero}
; commute = λ _ → assocl*-nat }
; iso = λ X → record
{ isoˡ = linv≋ assocr*
; isoʳ = rinv≋ assocr* }
}
CPM× : Monoidal FinEquivCat
CPM× = record
{ ⊗ = ×-bifunctor
; id = 1
; identityˡ = 1×y≡y
; identityʳ = y×1≡y
; assoc = [x×y]×z≡x×[y×z]
; triangle = unite-assocr*-coh
; pentagon = assocr*-coh
}
-- The monoidal structures are symmetric
x⊎y≈y⊎x : NaturalIsomorphism ⊎h.x⊗y ⊎h.y⊗x
x⊎y≈y⊎x = record
{ F⇒G = record
{ η = λ X → swap+ {m = X zero}
; commute = λ _ → swap₊-nat
}
; F⇐G = record
{ η = λ X → sswap+ {m = X zero} {n = X (suc zero)}
; commute = λ _ → sswap₊-nat
}
; iso = λ X → record
{ isoˡ = linv≋ swap+
; isoʳ = rinv≋ swap+
}
}
BM⊎ : Braided CPM⊎
BM⊎ = record
{ braid = x⊎y≈y⊎x
; hexagon₁ = assocr₊-swap₊-coh
; hexagon₂ = assocl₊-swap₊-coh
}
x×y≈y×x : NaturalIsomorphism ×h.x⊗y ×h.y⊗x
x×y≈y×x = record
{ F⇒G = record
{ η = λ X → swap* {m = X zero}
; commute = λ _ → swap*-nat
}
; F⇐G = record
{ η = λ X → sswap* {m = X zero}
; commute = λ _ → sswap*-nat
}
; iso = λ X → record
{ isoˡ = linv≋ swap*
; isoʳ = rinv≋ swap*
}
}
BM× : Braided CPM×
BM× = record
{ braid = x×y≈y×x
; hexagon₁ = assocr*-swap*-coh
; hexagon₂ = assocl*-swap*-coh
}
SBM⊎ : Symmetric BM⊎
SBM⊎ = record { symmetry = linv≋ sswap+ }
SBM× : Symmetric BM×
SBM× = record { symmetry = linv≋ sswap* }
-- And finally the multiplicative structure distributes over the
-- additive one
module r = BimonoidalHelperFunctors BM⊎ BM×
x⊗[y⊕z]≡[x⊗y]⊕[x⊗z] : NaturalIsomorphism r.x⊗[y⊕z] r.[x⊗y]⊕[x⊗z]
x⊗[y⊕z]≡[x⊗y]⊕[x⊗z] = record
{ F⇒G = record
{ η = λ X → distl {m = X zero}
; commute = λ _ → distl-nat
}
; F⇐G = record
{ η = λ X → factorl {m = X zero}
; commute = λ _ → factorl-nat
}
; iso = λ X → record { isoˡ = linv≋ distl
; isoʳ = rinv≋ distl }
}
[x⊕y]⊗z≡[x⊗z]⊕[y⊗z] : NaturalIsomorphism r.[x⊕y]⊗z r.[x⊗z]⊕[y⊗z]
[x⊕y]⊗z≡[x⊗z]⊕[y⊗z] = record
{ F⇒G = record
{ η = λ X → dist {m = X zero}
; commute = λ _ → dist-nat
}
; F⇐G = record
{ η = λ X → factor {m = X zero}
; commute = λ _ → factor-nat
}
; iso = λ X → record { isoˡ = linv≋ dist
; isoʳ = rinv≋ dist }
}
x⊗0≡0 : NaturalIsomorphism r.x⊗0 r.0↑
x⊗0≡0 = record
{ F⇒G = record
{ η = λ X → distzr {m = X zero}
; commute = λ _ → distzr-nat
}
; F⇐G = record
{ η = λ X → factorzr {n = X zero}
; commute = λ _ → factorzr-nat
}
; iso = λ X → record
{ isoˡ = linv≋ distzr
; isoʳ = rinv≋ distzr
}
}
0⊗x≡0 : NaturalIsomorphism r.0⊗x r.0↑
0⊗x≡0 = record
{ F⇒G = record
{ η = λ X → distz {m = X zero}
; commute = λ _ → distz-nat
}
; F⇐G = record
{ η = λ X → factorz {m = X zero}
; commute = λ _ → factorz-nat
}
; iso = λ X → record
{ isoˡ = linv≋ distz
; isoʳ = rinv≋ distz
}
}
TERig : RigCategory SBM⊎ SBM×
TERig = record
{ distribₗ = x⊗[y⊕z]≡[x⊗y]⊕[x⊗z]
; distribᵣ = [x⊕y]⊗z≡[x⊗z]⊕[y⊗z]
; annₗ = 0⊗x≡0
; annᵣ = x⊗0≡0
; laplazaI = A×[B⊎C]≃[A×C]⊎[A×B]
; laplazaII = [A⊎B]×C≃[C×A]⊎[C×B]
; laplazaIV = [A⊎B⊎C]×D≃[A×D⊎B×D]⊎C×D
; laplazaVI = A×B×[C⊎D]≃[A×B]×C⊎[A×B]×D
; laplazaIX = [A⊎B]×[C⊎D]≃[[A×C⊎B×C]⊎A×D]⊎B×D
; laplazaX = 0×0≃0
; laplazaXI = 0×[A⊎B]≃0
; laplazaXIII = 0×1≃0
; laplazaXV = A×0≃0
; laplazaXVI = 0×A×B≃0
; laplazaXVII = A×0×B≃0
; laplazaXIX = A×[0+B]≃A×B
; laplazaXXIII = 1×[A⊎B]≃A⊎B
}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5491525424,
"avg_line_length": 25.5511811024,
"ext": "agda",
"hexsha": "152d476b4b34f5ce17be038b6423607d9a96012a",
"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/FinEquivCat.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/FinEquivCat.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/FinEquivCat.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": 4594,
"size": 9735
} |
{-# OPTIONS --cubical --safe #-}
module Classical where
open import Prelude
open import Relation.Nullary.Stable using (Stable) public
open import Relation.Nullary.Decidable.Properties using (Dec→Stable) public
Classical : Type a → Type a
Classical A = ¬ ¬ A
pure : A → Classical A
pure x k = k x
_>>=_ : Classical A → (A → Classical B) → Classical B
xs >>= f = λ k → xs λ x → f x k
_<*>_ : Classical (A → B) → Classical A → Classical B
fs <*> xs = λ k → fs λ f → xs λ x → k (f x)
lem : {A : Type a} → Classical (Dec A)
lem k = k (no (k ∘ yes))
| {
"alphanum_fraction": 0.6315789474,
"avg_line_length": 23.9565217391,
"ext": "agda",
"hexsha": "464c16b7ccc385eaff750fcba77b775103613a55",
"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": "Classical.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": "Classical.agda",
"max_line_length": 75,
"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": "Classical.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": 174,
"size": 551
} |
------------------------------------------------------------------------
-- Bi-invertibility with erased proofs
------------------------------------------------------------------------
-- The development is based on the presentation of bi-invertibility
-- (for types and functions) and related things in the HoTT book, but
-- adapted to a setting with erasure.
{-# OPTIONS --without-K --safe #-}
open import Equality
open import Prelude as P hiding (id; _∘_; [_,_])
-- The code is parametrised by something like a "raw" category.
module Bi-invertibility.Erased
{e⁺}
(eq : ∀ {a p} → Equality-with-J a p e⁺)
{o h}
(Obj : Type o)
(Hom : Obj → Obj → Type h)
(id : {A : Obj} → Hom A A)
(_∘′_ : {A B C : Obj} → Hom B C → Hom A B → Hom A C)
where
open import Bi-invertibility eq Obj Hom id _∘′_ as Bi
using (Has-left-inverse; Has-right-inverse; Is-bi-invertible;
Has-quasi-inverse; _≊_; _≅_)
open Derived-definitions-and-properties eq
open import Equivalence eq as Eq using (_≃_)
open import Equivalence.Erased eq as EEq using (_≃ᴱ_)
open import Equivalence.Erased.Contractible-preimages eq as ECP
using (Contractibleᴱ)
open import Erased.Without-box-cong eq
open import Function-universe eq as F hiding (id; _∘_)
open import Logical-equivalence using (_⇔_)
open import H-level eq
open import H-level.Closure eq
open import Preimage eq
open import Surjection eq using (_↠_)
private
variable
A B : Obj
f : Hom A B
infixr 9 _∘_
_∘_ : {A B C : Obj} → Hom B C → Hom A B → Hom A C
_∘_ = _∘′_
-- Has-left-inverseᴱ f means that f has a left inverse. The proof is
-- erased.
Has-left-inverseᴱ : @0 Hom A B → Type h
Has-left-inverseᴱ f = ∃ λ f⁻¹ → Erased (f⁻¹ ∘ f ≡ id)
-- Has-right-inverseᴱ f means that f has a right inverse. The proof is
-- erased.
Has-right-inverseᴱ : @0 Hom A B → Type h
Has-right-inverseᴱ f = ∃ λ f⁻¹ → Erased (f ∘ f⁻¹ ≡ id)
-- Is-bi-invertibleᴱ f means that f has a left inverse and a (possibly
-- distinct) right inverse. The proofs are erased.
Is-bi-invertibleᴱ : @0 Hom A B → Type h
Is-bi-invertibleᴱ f =
Has-left-inverseᴱ f × Has-right-inverseᴱ f
-- Has-quasi-inverseᴱ f means that f has a left inverse that is also a
-- right inverse. The proofs are erased.
Has-quasi-inverseᴱ : @0 Hom A B → Type h
Has-quasi-inverseᴱ f =
∃ λ f⁻¹ → Erased (f ∘ f⁻¹ ≡ id × f⁻¹ ∘ f ≡ id)
-- Some notions of isomorphism or equivalence.
infix 4 _≊ᴱ_ _≅ᴱ_
_≊ᴱ_ : Obj → Obj → Type h
A ≊ᴱ B = ∃ λ (f : Hom A B) → Is-bi-invertibleᴱ f
_≅ᴱ_ : Obj → Obj → Type h
A ≅ᴱ B = ∃ λ (f : Hom A B) → Has-quasi-inverseᴱ f
-- Morphisms with quasi-inverses are bi-invertible.
Has-quasi-inverseᴱ→Is-bi-invertibleᴱ :
(@0 f : Hom A B) → Has-quasi-inverseᴱ f → Is-bi-invertibleᴱ f
Has-quasi-inverseᴱ→Is-bi-invertibleᴱ _ (f⁻¹ , [ f∘f⁻¹≡id , f⁻¹∘f≡id ]) =
(f⁻¹ , [ f⁻¹∘f≡id ])
, (f⁻¹ , [ f∘f⁻¹≡id ])
≅ᴱ→≊ᴱ : A ≅ᴱ B → A ≊ᴱ B
≅ᴱ→≊ᴱ = ∃-cong λ f → Has-quasi-inverseᴱ→Is-bi-invertibleᴱ f
-- Some conversion functions.
Has-left-inverse→Has-left-inverseᴱ :
Has-left-inverse f → Has-left-inverseᴱ f
Has-left-inverse→Has-left-inverseᴱ = Σ-map P.id [_]→
@0 Has-left-inverse≃Has-left-inverseᴱ :
Has-left-inverse f ≃ Has-left-inverseᴱ f
Has-left-inverse≃Has-left-inverseᴱ {f = f} =
(∃ λ f⁻¹ → f⁻¹ ∘ f ≡ id ) ↔⟨ (∃-cong λ _ → inverse $ erased Erased↔) ⟩□
(∃ λ f⁻¹ → Erased (f⁻¹ ∘ f ≡ id)) □
Has-right-inverse→Has-right-inverseᴱ :
Has-right-inverse f → Has-right-inverseᴱ f
Has-right-inverse→Has-right-inverseᴱ = Σ-map P.id [_]→
@0 Has-right-inverse≃Has-right-inverseᴱ :
Has-right-inverse f ≃ Has-right-inverseᴱ f
Has-right-inverse≃Has-right-inverseᴱ {f = f} =
(∃ λ f⁻¹ → f ∘ f⁻¹ ≡ id ) ↔⟨ (∃-cong λ _ → inverse $ erased Erased↔) ⟩□
(∃ λ f⁻¹ → Erased (f ∘ f⁻¹ ≡ id)) □
Is-bi-invertible→Is-bi-invertibleᴱ :
Is-bi-invertible f → Is-bi-invertibleᴱ f
Is-bi-invertible→Is-bi-invertibleᴱ =
Σ-map Has-left-inverse→Has-left-inverseᴱ
Has-right-inverse→Has-right-inverseᴱ
@0 Is-bi-invertible≃Is-bi-invertibleᴱ :
Is-bi-invertible f ≃ Is-bi-invertibleᴱ f
Is-bi-invertible≃Is-bi-invertibleᴱ {f = f} =
Has-left-inverse f × Has-right-inverse f ↝⟨ Has-left-inverse≃Has-left-inverseᴱ ×-cong
Has-right-inverse≃Has-right-inverseᴱ ⟩□
Has-left-inverseᴱ f × Has-right-inverseᴱ f □
Has-quasi-inverse→Has-quasi-inverseᴱ :
Has-quasi-inverse f → Has-quasi-inverseᴱ f
Has-quasi-inverse→Has-quasi-inverseᴱ = Σ-map P.id [_]→
@0 Has-quasi-inverse≃Has-quasi-inverseᴱ :
Has-quasi-inverse f ≃ Has-quasi-inverseᴱ f
Has-quasi-inverse≃Has-quasi-inverseᴱ {f = f} =
(∃ λ f⁻¹ → f ∘ f⁻¹ ≡ id × f⁻¹ ∘ f ≡ id ) ↔⟨ (∃-cong λ _ → inverse $ erased Erased↔) ⟩□
(∃ λ f⁻¹ → Erased (f ∘ f⁻¹ ≡ id × f⁻¹ ∘ f ≡ id)) □
≊→≊ᴱ : A ≊ B → A ≊ᴱ B
≊→≊ᴱ = Σ-map P.id Is-bi-invertible→Is-bi-invertibleᴱ
@0 ≊≃≊ᴱ : (A ≊ B) ≃ (A ≊ᴱ B)
≊≃≊ᴱ {A = A} {B = B} =
(∃ λ (f : Hom A B) → Is-bi-invertible f) ↝⟨ (∃-cong λ _ → Is-bi-invertible≃Is-bi-invertibleᴱ) ⟩□
(∃ λ (f : Hom A B) → Is-bi-invertibleᴱ f) □
≅→≅ᴱ : A ≅ B → A ≅ᴱ B
≅→≅ᴱ = Σ-map P.id Has-quasi-inverse→Has-quasi-inverseᴱ
@0 ≅≃≅ᴱ : (A ≅ B) ≃ (A ≅ᴱ B)
≅≃≅ᴱ {A = A} {B = B} =
(∃ λ (f : Hom A B) → Has-quasi-inverse f) ↝⟨ (∃-cong λ _ → Has-quasi-inverse≃Has-quasi-inverseᴱ) ⟩□
(∃ λ (f : Hom A B) → Has-quasi-inverseᴱ f) □
-- The remaining code relies on some further assumptions, similar to
-- those of a precategory. However, note that Hom A B is not required
-- to be a set (some properties require Hom A A to be a set for some
-- A).
module More
(@0 left-identity : {A B : Obj} (f : Hom A B) → id ∘ f ≡ f)
(@0 right-identity : {A B : Obj} (f : Hom A B) → f ∘ id ≡ f)
(@0 associativity : {A B C D : Obj}
(f : Hom C D) (g : Hom B C) (h : Hom A B) →
f ∘ (g ∘ h) ≡ (f ∘ g) ∘ h)
where
-- A workaround for Agda's lack of erased modules.
private
record Proofs : Type (o ⊔ h) where
field
lid : {A B : Obj} (f : Hom A B) → id ∘ f ≡ f
rid : {A B : Obj} (f : Hom A B) → f ∘ id ≡ f
ass : {A B C D : Obj}
(f : Hom C D) (g : Hom B C) (h : Hom A B) →
f ∘ (g ∘ h) ≡ (f ∘ g) ∘ h
@0 proofs : Proofs
proofs .Proofs.lid = left-identity
proofs .Proofs.rid = right-identity
proofs .Proofs.ass = associativity
module BiM (p : Proofs) =
Bi.More
(Proofs.lid p)
(Proofs.rid p)
(Proofs.ass p)
-- Bi-invertible morphisms have quasi-inverses.
Is-bi-invertibleᴱ→Has-quasi-inverseᴱ :
Is-bi-invertibleᴱ f → Has-quasi-inverseᴱ f
Is-bi-invertibleᴱ→Has-quasi-inverseᴱ
{f = f} ((f⁻¹₁ , [ f⁻¹₁∘f≡id ]) , (f⁻¹₂ , [ f∘f⁻¹₂≡id ])) =
(f⁻¹₁ ∘ f ∘ f⁻¹₂)
, [ (f ∘ f⁻¹₁ ∘ f ∘ f⁻¹₂ ≡⟨ cong (f ∘_) $ associativity _ _ _ ⟩
f ∘ (f⁻¹₁ ∘ f) ∘ f⁻¹₂ ≡⟨ cong (λ f′ → f ∘ f′ ∘ f⁻¹₂) f⁻¹₁∘f≡id ⟩
f ∘ id ∘ f⁻¹₂ ≡⟨ cong (f ∘_) $ left-identity _ ⟩
f ∘ f⁻¹₂ ≡⟨ f∘f⁻¹₂≡id ⟩∎
id ∎)
, ((f⁻¹₁ ∘ f ∘ f⁻¹₂) ∘ f ≡⟨ cong (λ f′ → (f⁻¹₁ ∘ f′) ∘ f) f∘f⁻¹₂≡id ⟩
(f⁻¹₁ ∘ id) ∘ f ≡⟨ cong (_∘ f) $ right-identity _ ⟩
f⁻¹₁ ∘ f ≡⟨ f⁻¹₁∘f≡id ⟩∎
id ∎)
]
-- Has-left-inverseᴱ f is contractible (with an erased proof) if f
-- has a quasi-inverse (with erased proofs).
Contractibleᴱ-Has-left-inverseᴱ :
{@0 f : Hom A B} →
Has-quasi-inverseᴱ f → Contractibleᴱ (Has-left-inverseᴱ f)
Contractibleᴱ-Has-left-inverseᴱ
{f = f} (f⁻¹ , [ f∘f⁻¹≡id , f⁻¹∘f≡id ]) =
ECP.Contractibleᴱ-⁻¹ᴱ
(_∘ f)
(_∘ f⁻¹)
(λ g →
(g ∘ f⁻¹) ∘ f ≡⟨ sym $ associativity _ _ _ ⟩
g ∘ f⁻¹ ∘ f ≡⟨ cong (g ∘_) f⁻¹∘f≡id ⟩
g ∘ id ≡⟨ right-identity _ ⟩∎
g ∎)
(λ g →
(g ∘ f) ∘ f⁻¹ ≡⟨ sym $ associativity _ _ _ ⟩
g ∘ f ∘ f⁻¹ ≡⟨ cong (g ∘_) f∘f⁻¹≡id ⟩
g ∘ id ≡⟨ right-identity _ ⟩∎
g ∎)
id
-- Has-right-inverseᴱ f is contractible (with an erased proof) if f
-- has a quasi-inverse (with erased proofs).
Contractibleᴱ-Has-right-inverseᴱ :
{@0 f : Hom A B} →
Has-quasi-inverseᴱ f → Contractibleᴱ (Has-right-inverseᴱ f)
Contractibleᴱ-Has-right-inverseᴱ
{f = f} (f⁻¹ , [ f∘f⁻¹≡id , f⁻¹∘f≡id ]) =
ECP.Contractibleᴱ-⁻¹ᴱ
(f ∘_)
(f⁻¹ ∘_)
(λ g →
f ∘ f⁻¹ ∘ g ≡⟨ associativity _ _ _ ⟩
(f ∘ f⁻¹) ∘ g ≡⟨ cong (_∘ g) f∘f⁻¹≡id ⟩
id ∘ g ≡⟨ left-identity _ ⟩∎
g ∎)
(λ g →
f⁻¹ ∘ f ∘ g ≡⟨ associativity _ _ _ ⟩
(f⁻¹ ∘ f) ∘ g ≡⟨ cong (_∘ g) f⁻¹∘f≡id ⟩
id ∘ g ≡⟨ left-identity _ ⟩∎
g ∎)
id
-- Is-bi-invertibleᴱ f is a proposition (in erased contexts).
@0 Is-bi-invertibleᴱ-propositional :
(f : Hom A B) → Is-proposition (Is-bi-invertibleᴱ f)
Is-bi-invertibleᴱ-propositional f = $⟨ BiM.Is-bi-invertible-propositional proofs f ⟩
Is-proposition (Is-bi-invertible f) ↝⟨ H-level-cong _ 1 Is-bi-invertible≃Is-bi-invertibleᴱ ⦂ (_ → _) ⟩
Is-proposition (Is-bi-invertibleᴱ f) □
-- If Hom A A is a set, where A is the domain of f, then
-- Has-quasi-inverseᴱ f is a proposition (in erased contexts).
@0 Has-quasi-inverseᴱ-propositional-domain :
{f : Hom A B} →
Is-set (Hom A A) →
Is-proposition (Has-quasi-inverseᴱ f)
Has-quasi-inverseᴱ-propositional-domain {f = f} s =
$⟨ BiM.Has-quasi-inverse-propositional-domain proofs s ⟩
Is-proposition (Has-quasi-inverse f) ↝⟨ H-level-cong _ 1 Has-quasi-inverse≃Has-quasi-inverseᴱ ⦂ (_ → _) ⟩□
Is-proposition (Has-quasi-inverseᴱ f) □
-- If Hom B B is a set, where B is the codomain of f, then
-- Has-quasi-inverseᴱ f is a proposition (in erased contexts).
@0 Has-quasi-inverseᴱ-propositional-codomain :
{f : Hom A B} →
Is-set (Hom B B) →
Is-proposition (Has-quasi-inverseᴱ f)
Has-quasi-inverseᴱ-propositional-codomain {f = f} s =
$⟨ BiM.Has-quasi-inverse-propositional-codomain proofs s ⟩
Is-proposition (Has-quasi-inverse f) ↝⟨ H-level-cong _ 1 Has-quasi-inverse≃Has-quasi-inverseᴱ ⦂ (_ → _) ⟩□
Is-proposition (Has-quasi-inverseᴱ f) □
-- There is a logical equivalence between Has-quasi-inverseᴱ f and
-- Is-bi-invertibleᴱ f.
Has-quasi-inverseᴱ⇔Is-bi-invertibleᴱ :
Has-quasi-inverseᴱ f ⇔ Is-bi-invertibleᴱ f
Has-quasi-inverseᴱ⇔Is-bi-invertibleᴱ = record
{ to = Has-quasi-inverseᴱ→Is-bi-invertibleᴱ _
; from = Is-bi-invertibleᴱ→Has-quasi-inverseᴱ
}
-- There is a logical equivalence between A ≅ᴱ B and A ≊ᴱ B.
≅ᴱ⇔≊ᴱ : (A ≅ᴱ B) ⇔ (A ≊ᴱ B)
≅ᴱ⇔≊ᴱ = ∃-cong λ _ → Has-quasi-inverseᴱ⇔Is-bi-invertibleᴱ
-- Is-bi-invertibleᴱ and Has-quasi-inverseᴱ are equivalent (with
-- erased proofs) for morphisms with domain A for which Hom A A is a
-- set.
Is-bi-invertibleᴱ≃ᴱHas-quasi-inverseᴱ-domain :
{f : Hom A B} →
@0 Is-set (Hom A A) →
Is-bi-invertibleᴱ f ≃ᴱ Has-quasi-inverseᴱ f
Is-bi-invertibleᴱ≃ᴱHas-quasi-inverseᴱ-domain s = EEq.⇔→≃ᴱ
(Is-bi-invertibleᴱ-propositional _)
(Has-quasi-inverseᴱ-propositional-domain s)
(_⇔_.from Has-quasi-inverseᴱ⇔Is-bi-invertibleᴱ)
(_⇔_.to Has-quasi-inverseᴱ⇔Is-bi-invertibleᴱ)
-- Is-bi-invertibleᴱ and Has-quasi-inverseᴱ are equivalent (with
-- erased proofs) for morphisms with codomain B for which Hom B B is
-- a set.
Is-bi-invertibleᴱ≃ᴱHas-quasi-inverseᴱ-codomain :
{f : Hom A B} →
@0 Is-set (Hom B B) →
Is-bi-invertibleᴱ f ≃ᴱ Has-quasi-inverseᴱ f
Is-bi-invertibleᴱ≃ᴱHas-quasi-inverseᴱ-codomain s = EEq.⇔→≃ᴱ
(Is-bi-invertibleᴱ-propositional _)
(Has-quasi-inverseᴱ-propositional-codomain s)
(_⇔_.from Has-quasi-inverseᴱ⇔Is-bi-invertibleᴱ)
(_⇔_.to Has-quasi-inverseᴱ⇔Is-bi-invertibleᴱ)
-- A ≊ᴱ B and A ≅ᴱ B are equivalent (with erased proofs) if Hom A A
-- is a set.
≊ᴱ≃ᴱ≅ᴱ-domain :
@0 Is-set (Hom A A) →
(A ≊ᴱ B) ≃ᴱ (A ≅ᴱ B)
≊ᴱ≃ᴱ≅ᴱ-domain s =
∃-cong λ _ → Is-bi-invertibleᴱ≃ᴱHas-quasi-inverseᴱ-domain s
-- A ≊ᴱ B and A ≅ᴱ B are equivalent (with erased proofs) if Hom B B
-- is a set.
≊ᴱ≃ᴱ≅ᴱ-codomain :
@0 Is-set (Hom B B) →
(A ≊ᴱ B) ≃ᴱ (A ≅ᴱ B)
≊ᴱ≃ᴱ≅ᴱ-codomain s =
∃-cong λ _ → Is-bi-invertibleᴱ≃ᴱHas-quasi-inverseᴱ-codomain s
-- An equality characterisation lemma for _≊ᴱ_.
@0 equality-characterisation-≊ᴱ :
(f g : A ≊ᴱ B) → (f ≡ g) ≃ (proj₁ f ≡ proj₁ g)
equality-characterisation-≊ᴱ f g =
f ≡ g ↝⟨ inverse $ Eq.≃-≡ (inverse ≊≃≊ᴱ) ⟩
_≃_.from ≊≃≊ᴱ f ≡ _≃_.from ≊≃≊ᴱ g ↝⟨ BiM.equality-characterisation-≊ proofs _ _ ⟩□
proj₁ f ≡ proj₁ g □
-- Two equality characterisation lemmas for _≅ᴱ_.
@0 equality-characterisation-≅ᴱ-domain :
Is-set (Hom A A) →
(f g : A ≅ᴱ B) → (f ≡ g) ≃ (proj₁ f ≡ proj₁ g)
equality-characterisation-≅ᴱ-domain s f g =
f ≡ g ↝⟨ inverse $ Eq.≃-≡ (inverse ≅≃≅ᴱ) ⟩
_≃_.from ≅≃≅ᴱ f ≡ _≃_.from ≅≃≅ᴱ g ↝⟨ BiM.equality-characterisation-≅-domain proofs s _ _ ⟩□
proj₁ f ≡ proj₁ g □
@0 equality-characterisation-≅ᴱ-codomain :
Is-set (Hom B B) →
(f g : A ≅ᴱ B) → (f ≡ g) ≃ (proj₁ f ≡ proj₁ g)
equality-characterisation-≅ᴱ-codomain s f g =
f ≡ g ↝⟨ inverse $ Eq.≃-≡ (inverse ≅≃≅ᴱ) ⟩
_≃_.from ≅≃≅ᴱ f ≡ _≃_.from ≅≃≅ᴱ g ↝⟨ BiM.equality-characterisation-≅-codomain proofs s _ _ ⟩□
proj₁ f ≡ proj₁ g □
-- If f : Hom A B has a quasi-inverse, then Has-quasi-inverseᴱ f is
-- equivalent to id ≡ id (in erased contexts), where id stands for
-- either the identity at A or at B.
@0 Has-quasi-inverseᴱ≃id≡id-domain :
{f : Hom A B} →
Has-quasi-inverseᴱ f →
Has-quasi-inverseᴱ f ≃ (id ≡ id {A = A})
Has-quasi-inverseᴱ≃id≡id-domain {f = f} q-inv =
Has-quasi-inverseᴱ f ↝⟨ inverse Has-quasi-inverse≃Has-quasi-inverseᴱ ⟩
Has-quasi-inverse f ↝⟨ BiM.Has-quasi-inverse≃id≡id-domain proofs (_≃_.from Has-quasi-inverse≃Has-quasi-inverseᴱ q-inv) ⟩□
id ≡ id □
@0 Has-quasi-inverseᴱ≃id≡id-codomain :
{f : Hom A B} →
Has-quasi-inverseᴱ f →
Has-quasi-inverseᴱ f ≃ (id ≡ id {A = B})
Has-quasi-inverseᴱ≃id≡id-codomain {f = f} q-inv =
Has-quasi-inverseᴱ f ↝⟨ inverse Has-quasi-inverse≃Has-quasi-inverseᴱ ⟩
Has-quasi-inverse f ↝⟨ BiM.Has-quasi-inverse≃id≡id-codomain proofs (_≃_.from Has-quasi-inverse≃Has-quasi-inverseᴱ q-inv) ⟩□
id ≡ id □
| {
"alphanum_fraction": 0.5761480466,
"avg_line_length": 36.3840399002,
"ext": "agda",
"hexsha": "8a99ecf5bb30ba78930c4d0631de8a2abd72ea6a",
"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/Bi-invertibility/Erased.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/Bi-invertibility/Erased.agda",
"max_line_length": 129,
"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/Bi-invertibility/Erased.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": 6320,
"size": 14590
} |
------------------------------------------------------------------------------
-- The gcd is divisible by any common divisor (using equational reasoning)
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.GCD.Partial.DivisibleI where
open import FOTC.Base
open import FOTC.Base.PropertiesI
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Divisibility.NotBy0
open import FOTC.Data.Nat.Divisibility.NotBy0.PropertiesI
open import FOTC.Data.Nat.Induction.NonAcc.LexicographicI
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesI
open import FOTC.Data.Nat.Inequalities.PropertiesI
open import FOTC.Data.Nat.PropertiesI
open import FOTC.Program.GCD.Partial.ConversionRulesI
open import FOTC.Program.GCD.Partial.Definitions
open import FOTC.Program.GCD.Partial.GCD
------------------------------------------------------------------------------
-- The gcd 0 (succ n) is Divisible.
gcd-0S-Divisible : ∀ {n} → N n → Divisible zero (succ₁ n) (gcd zero (succ₁ n))
gcd-0S-Divisible {n} _ c _ (c∣0 , c∣Sn) = subst (_∣_ c) (sym (gcd-0S n)) c∣Sn
------------------------------------------------------------------------------
-- The gcd (succ₁ n) 0 is Divisible.
gcd-S0-Divisible : ∀ {n} → N n → Divisible (succ₁ n) zero (gcd (succ₁ n) zero)
gcd-S0-Divisible {n} _ c _ (c∣Sn , c∣0) = subst (_∣_ c) (sym (gcd-S0 n)) c∣Sn
------------------------------------------------------------------------------
-- The gcd (succ₁ m) (succ₁ n) when succ₁ m > succ₁ n is Divisible.
gcd-S>S-Divisible :
∀ {m n} → N m → N n →
(Divisible (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))) →
succ₁ m > succ₁ n →
Divisible (succ₁ m) (succ₁ n) (gcd (succ₁ m) (succ₁ n))
gcd-S>S-Divisible {m} {n} Nm Nn acc Sm>Sn c Nc (c∣Sm , c∣Sn) =
{-
Proof:
----------------- (Hip.)
c | m c | n
---------------------- (Thm.) -------- (Hip.)
c | (m ∸ n) c | n
------------------------------------------ (IH)
c | gcd m (n ∸ m) m > n
--------------------------------------------------- (gcd def.)
c | gcd m n
-}
subst (_∣_ c) (sym (gcd-S>S m n Sm>Sn)) (acc c Nc (c|Sm-Sn , c∣Sn))
where
c|Sm-Sn : c ∣ succ₁ m ∸ succ₁ n
c|Sm-Sn = x∣y→x∣z→x∣y∸z Nc (nsucc Nm) (nsucc Nn) c∣Sm c∣Sn
------------------------------------------------------------------------------
-- The gcd (succ₁ m) (succ₁ n) when succ₁ m ≯ succ₁ n is Divisible.
gcd-S≯S-Divisible :
∀ {m n} → N m → N n →
(Divisible (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))) →
succ₁ m ≯ succ₁ n →
Divisible (succ₁ m) (succ₁ n) (gcd (succ₁ m) (succ₁ n))
gcd-S≯S-Divisible {m} {n} Nm Nn acc Sm≯Sn c Nc (c∣Sm , c∣Sn) =
{-
Proof
----------------- (Hip.)
c | m c | n
-------- (Hip.) ---------------------- (Thm.)
c | m c | n ∸ m
------------------------------------------ (IH)
c | gcd m (n ∸ m) m ≯ n
--------------------------------------------------- (gcd def.)
c | gcd m n
-}
subst (_∣_ c) (sym (gcd-S≯S m n Sm≯Sn)) (acc c Nc (c∣Sm , c|Sn-Sm))
where
c|Sn-Sm : c ∣ succ₁ n ∸ succ₁ m
c|Sn-Sm = x∣y→x∣z→x∣y∸z Nc (nsucc Nn) (nsucc Nm) c∣Sn c∣Sm
------------------------------------------------------------------------------
-- The gcd m n when m > n is Divisible.
gcd-x>y-Divisible :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → x≢0≢y o p →
Divisible o p (gcd o p)) →
m > n →
x≢0≢y m n →
Divisible m n (gcd m n)
gcd-x>y-Divisible nzero nzero _ _ ¬0≡0∧0≡0 _ _ = ⊥-elim (¬0≡0∧0≡0 (refl , refl))
gcd-x>y-Divisible nzero (nsucc Nn) _ 0>Sn _ _ _ = ⊥-elim (0>x→⊥ (nsucc Nn) 0>Sn)
gcd-x>y-Divisible (nsucc Nm) nzero _ _ _ c Nc = gcd-S0-Divisible Nm c Nc
gcd-x>y-Divisible (nsucc {m} Nm) (nsucc {n} Nn) ah Sm>Sn _ c Nc =
gcd-S>S-Divisible Nm Nn ih Sm>Sn c Nc
where
-- Inductive hypothesis.
ih : Divisible (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))
ih = ah {succ₁ m ∸ succ₁ n}
{succ₁ n}
(∸-N (nsucc Nm) (nsucc Nn))
(nsucc Nn)
([Sx∸Sy,Sy]<[Sx,Sy] Nm Nn)
(λ p → ⊥-elim (S≢0 (∧-proj₂ p)))
------------------------------------------------------------------------------
-- The gcd m n when m ≯ n is Divisible.
gcd-x≯y-Divisible :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → x≢0≢y o p →
Divisible o p (gcd o p)) →
m ≯ n →
x≢0≢y m n →
Divisible m n (gcd m n)
gcd-x≯y-Divisible nzero nzero _ _ h _ _ = ⊥-elim (h (refl , refl))
gcd-x≯y-Divisible nzero (nsucc Nn) _ _ _ c Nc = gcd-0S-Divisible Nn c Nc
gcd-x≯y-Divisible (nsucc _) nzero _ Sm≯0 _ _ _ = ⊥-elim (S≯0→⊥ Sm≯0)
gcd-x≯y-Divisible (nsucc {m} Nm) (nsucc {n} Nn) ah Sm≯Sn _ c Nc =
gcd-S≯S-Divisible Nm Nn ih Sm≯Sn c Nc
where
-- Inductive hypothesis.
ih : Divisible (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))
ih = ah {succ₁ m}
{succ₁ n ∸ succ₁ m}
(nsucc Nm)
(∸-N (nsucc Nn) (nsucc Nm))
([Sx,Sy∸Sx]<[Sx,Sy] Nm Nn)
(λ p → ⊥-elim (S≢0 (∧-proj₁ p)))
------------------------------------------------------------------------------
-- The gcd is Divisible.
gcdDivisible : ∀ {m n} → N m → N n → x≢0≢y m n → Divisible m n (gcd m n)
gcdDivisible = Lexi-wfind A h
where
A : D → D → Set
A i j = x≢0≢y i j → Divisible i j (gcd i j)
h : ∀ {i j} → N i → N j → (∀ {k l} → N k → N l → Lexi k l i j → A k l) →
A i j
h Ni Nj ah = case (gcd-x>y-Divisible Ni Nj ah)
(gcd-x≯y-Divisible Ni Nj ah)
(x>y∨x≯y Ni Nj)
| {
"alphanum_fraction": 0.4493406777,
"avg_line_length": 41.0342465753,
"ext": "agda",
"hexsha": "fefc9d4fca73a762db765be72e21bce082bf263f",
"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/GCD/Partial/DivisibleI.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/GCD/Partial/DivisibleI.agda",
"max_line_length": 82,
"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/GCD/Partial/DivisibleI.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": 2139,
"size": 5991
} |
{-# OPTIONS --without-K #-}
module Control.Category where
open import Level using (suc; _⊔_)
open import Relation.Binary hiding (_⇒_)
open import Relation.Binary.PropositionalEquality
-- Module HomSet provides notation A ⇒ B for the Set of morphisms
-- from between objects A and B and names _≈_ and ≈-refl/sym/trans
-- for the equality of morphisms.
module HomSet {o h e} {Obj : Set o} (Hom : Obj → Obj → Setoid h e) where
_⇒_ : (A B : Obj) → Set h
A ⇒ B = Setoid.Carrier (Hom A B)
module _ {A B : Obj} where
open Setoid (Hom A B) public
using (_≈_)
renaming ( isEquivalence to ≈-equiv
; refl to ≈-refl
; sym to ≈-sym
; trans to ≈-trans
)
{-
_≈_ : {A B : Obj} → Rel (A ⇒ B) e
_≈_ {A = A}{B = B} = Setoid._≈_ (Hom A B)
≈-equiv : {A B : Obj} → IsEquivalence (Setoid._≈_ (Hom A B))
≈-equiv {A = A}{B = B} = Setoid.isEquivalence (Hom A B)
≈-refl : {A B : Obj} → Reflexive _≈_
≈-refl {A = A}{B = B} = Setoid.refl (Hom A B)
≈-sym : {A B : Obj} → Symmetric _≈_
≈-sym {A = A}{B = B} = Setoid.sym (Hom A B)
≈-trans : {A B : Obj} → Transitive _≈_
≈-trans {A = A}{B = B} = Setoid.trans (Hom A B)
-}
-- Category operations: identity and composition.
-- Module T-CategoryOps Hom provides the types of
-- identity and composition (forward and backward).
module T-CategoryOps {o h e} {Obj : Set o} (Hom : Obj → Obj → Setoid h e) where
open HomSet Hom
T-id = ∀ {A} → A ⇒ A
T-⟫ = ∀ {A B C} (f : A ⇒ B) (g : B ⇒ C) → A ⇒ C
T-∘ = ∀ {A B C} (g : B ⇒ C) (f : A ⇒ B) → A ⇒ C
-- Record CategoryOps Hom can be instantiated to implement
-- identity and composition for category Hom.
record CategoryOps {o h e} {Obj : Set o} (Hom : Obj → Obj → Setoid h e)
: Set (o ⊔ h ⊔ e)
where
open T-CategoryOps Hom
infixl 9 _⟫_
infixr 9 _∘_
field
id : T-id
_⟫_ : T-⟫
_∘_ : T-∘
g ∘ f = f ⟫ g
-- Category laws: left and right identity and composition.
-- Module T-CategoryLaws ops provides the types of the laws
-- for the category operations ops.
module T-CategoryLaws {o h e} {Obj : Set o} {Hom : Obj → Obj → Setoid h e}
(ops : CategoryOps Hom)
where
open HomSet Hom public
open T-CategoryOps Hom public
open CategoryOps ops public
T-id-first = ∀ {A B} {g : A ⇒ B} →
(id ⟫ g) ≈ g
T-id-last = ∀ {A B} {f : A ⇒ B} →
(f ⟫ id) ≈ f
T-∘-assoc = ∀ {A B C D} (f : A ⇒ B) {g : B ⇒ C} {h : C ⇒ D} →
((f ⟫ g) ⟫ h) ≈ (f ⟫ (g ⟫ h))
T-∘-cong = ∀ {A B C} {f f′ : A ⇒ B} {g g′ : B ⇒ C} →
f ≈ f′ → g ≈ g′ → (f ⟫ g) ≈ (f′ ⟫ g′)
-- Record CategoryLaws ops can be instantiated to prove the laws of the
-- category operations (identity and compositions).
record CategoryLaws {o h e} {Obj : Set o} {Hom : Obj → Obj → Setoid h e}
(ops : CategoryOps Hom) : Set (o ⊔ h ⊔ e)
where
open T-CategoryLaws ops
field
id-first : T-id-first
id-last : T-id-last
∘-assoc : T-∘-assoc
∘-cong : T-∘-cong
-- Record IsCategory Hom contains the data (operations and laws) to make
-- Hom a category.
record IsCategory {o h e} {Obj : Set o} (Hom : Obj → Obj → Setoid h e) : Set (o ⊔ h ⊔ e) where
field
ops : CategoryOps Hom
laws : CategoryLaws ops
open HomSet Hom public
open CategoryOps ops public
open CategoryLaws laws public
-- The category: packaging objects, morphisms, and laws.
record Category o h e : Set (suc (o ⊔ h ⊔ e)) where
field
{Obj} : Set o
Hom : Obj → Obj → Setoid h e
isCategory : IsCategory Hom
open IsCategory isCategory public
-- Initial object
record IsInitial {o h e} {Obj : Set o} (Hom : Obj → Obj → Setoid h e) (Initial : Obj) : Set (h ⊔ o ⊔ e) where
open HomSet Hom
open T-CategoryOps Hom
field
initial : ∀ {A} → Initial ⇒ A
initial-universal : ∀ {A} {f : Initial ⇒ A} → f ≈ initial
-- Terminal object
record IsFinal {o h e} {Obj : Set o} (Hom : Obj → Obj → Setoid h e) (Final : Obj) : Set (h ⊔ o ⊔ e) where
open HomSet Hom
open T-CategoryOps Hom
field
final : ∀ {A} → A ⇒ Final
final-universal : ∀ {A} {f : A ⇒ Final} → f ≈ final
| {
"alphanum_fraction": 0.5593100189,
"avg_line_length": 27.3032258065,
"ext": "agda",
"hexsha": "4c76b8a0d73f36d1be895710a35e34ec0a687792",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andreasabel/cubical",
"max_forks_repo_path": "src/Control/Category.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andreasabel/cubical",
"max_issues_repo_path": "src/Control/Category.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andreasabel/cubical",
"max_stars_repo_path": "src/Control/Category.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1526,
"size": 4232
} |
module Cats.Category.Cat.Facts.Initial where
open import Cats.Category
open import Cats.Category.Cat using (Cat)
open import Cats.Category.Zero using (Zero)
open import Cats.Functor
module _ {lo la l≈} where
open Category (Cat lo la l≈)
Zero-Initial : IsInitial (Zero lo la l≈)
Zero-Initial X = ∃!-intro f _ f-Unique
where
f : Functor (Zero lo la l≈) X
f = record
{ fobj = λ()
; fmap = λ{}
; fmap-resp = λ{}
; fmap-id = λ{}
; fmap-∘ = λ{}
}
f-Unique : IsUnique f
f-Unique f′ = record
{ iso = λ{}
; forth-natural = λ{}
}
instance
hasInitial : ∀ lo la l≈ → HasInitial (Cat lo la l≈)
hasInitial lo la l≈ = record
{ Zero = Zero lo la l≈
; isInitial = Zero-Initial
}
| {
"alphanum_fraction": 0.5434516524,
"avg_line_length": 20.9487179487,
"ext": "agda",
"hexsha": "a63d583440bba8cbbf94b0e2dbef794b54f390a3",
"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/Cat/Facts/Initial.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/Cat/Facts/Initial.agda",
"max_line_length": 53,
"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/Cat/Facts/Initial.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 246,
"size": 817
} |
module Issue361 where
data _==_ {A : Set}(a : A) : A -> Set where
refl : a == a
postulate
A : Set
a b : A
F : A -> Set
record R (a : A) : Set where
constructor c
field
p : A
beta : (x : A) -> R.p {b} (c {b} x) == x
beta x = refl
lemma : (r : R a) -> R.p {b} (c {b} (R.p {a} r)) == R.p {a} r
lemma r = beta (R.p {a} r)
| {
"alphanum_fraction": 0.4692082111,
"avg_line_length": 15.5,
"ext": "agda",
"hexsha": "c6a429a04974a12923b4819ee26199c9651a86cc",
"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/Issue361.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/Issue361.agda",
"max_line_length": 61,
"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/Issue361.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": 151,
"size": 341
} |
open import lib
module rtn (gratr2-nt : Set) where
gratr2-rule : Set
gratr2-rule = maybe string × maybe string × maybe gratr2-nt × 𝕃 (gratr2-nt ⊎ char)
record gratr2-rtn : Set where
field
start : gratr2-nt
_eq_ : gratr2-nt → gratr2-nt → 𝔹
gratr2-start : gratr2-nt → 𝕃 gratr2-rule
gratr2-return : maybe gratr2-nt → 𝕃 gratr2-rule
| {
"alphanum_fraction": 0.6676056338,
"avg_line_length": 25.3571428571,
"ext": "agda",
"hexsha": "06bdb42614b559381ad9e36f7509664157fe9866",
"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": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/rtn.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"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": "xoltar/cedille",
"max_issues_repo_path": "src/rtn.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/cedille",
"max_stars_repo_path": "src/rtn.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 140,
"size": 355
} |
------------------------------------------------------------------------
-- Definitions of combinatorial functions on integers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --exact-split #-}
module Math.Combinatorics.IntegerFunction where
open import Data.Nat hiding (_*_)
open import Data.Integer
import Math.Combinatorics.Function as ℕF
[-1]^_ : ℕ → ℤ
[-1]^ 0 = + 1
[-1]^ 1 = - (+ 1)
[-1]^ ℕ.suc (ℕ.suc n) = [-1]^ n
------------------------------------------------------------------------
-- Permutation, Falling factorial
-- P n k = n * (n - 1) * ... * (n - k + 1) (k terms)
P : ℤ → ℕ → ℤ
P (+ n) k = + (ℕF.P n k)
P (-[1+ n ]) k = [-1]^ k * (+ ℕF.Poch (ℕ.suc n) k)
| {
"alphanum_fraction": 0.3807040417,
"avg_line_length": 29.5,
"ext": "agda",
"hexsha": "6df1e1b7897459447b00fd2e3c749a92b28c9d57",
"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": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-combinatorics",
"max_forks_repo_path": "Math/Combinatorics/IntegerFunction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-combinatorics",
"max_issues_repo_path": "Math/Combinatorics/IntegerFunction.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-combinatorics",
"max_stars_repo_path": "Math/Combinatorics/IntegerFunction.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-25T07:25:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-25T08:24:15.000Z",
"num_tokens": 204,
"size": 767
} |
open import Agda.Builtin.Unit
open import Agda.Builtin.List
open import Agda.Builtin.Reflection
id : {A : Set} → A → A
id x = x
macro
tac : Term → TC ⊤
tac hole =
unify hole
(def (quote id)
(arg (arg-info visible (modality relevant quantity-ω))
(var 0 []) ∷
[]))
test : {A : Set} → A → A
test x = {!tac!}
| {
"alphanum_fraction": 0.5549295775,
"avg_line_length": 18.6842105263,
"ext": "agda",
"hexsha": "d8513fda032d39314b9a6f40c4e19d805d0b8aa7",
"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/interaction/Issue3486.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/interaction/Issue3486.agda",
"max_line_length": 63,
"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/interaction/Issue3486.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": 114,
"size": 355
} |
{-# OPTIONS --safe #-}
module Squaring where
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.Product
open import Data.Bool hiding (_≤_;_<_)
open import Data.Nat.Properties
open ≡-Reasoning
div-mod2 : ℕ → ℕ × Bool
div-mod2 0 = 0 , false
div-mod2 (suc 0) = 0 , true
div-mod2 (suc (suc n)) = let q , r = div-mod2 n in suc q , r
-- The first argument (k) helps Agda to prove
-- that the function terminates
pow-sqr-aux : ℕ → ℕ → ℕ → ℕ
pow-sqr-aux 0 _ _ = 1
pow-sqr-aux _ _ 0 = 1
pow-sqr-aux (suc k) b e with div-mod2 e
... | e' , false = pow-sqr-aux k (b * b) e'
... | e' , true = b * pow-sqr-aux k (b * b) e'
pow-sqr : ℕ → ℕ → ℕ
pow-sqr b e = pow-sqr-aux e b e
div-mod2-spec : ∀ n → let q , r = div-mod2 n in 2 * q + (if r then 1 else 0) ≡ n
div-mod2-spec 0 = refl
div-mod2-spec 1 = refl
div-mod2-spec (suc (suc n)) with div-mod2 n | div-mod2-spec n
... | q , r | eq rewrite +-suc q (q + 0) | eq = refl
div-mod2-lt : ∀ n → 0 < n → proj₁ (div-mod2 n) < n
div-mod2-lt 0 lt = lt
div-mod2-lt 1 lt = lt
div-mod2-lt 2 lt = s≤s (s≤s z≤n)
div-mod2-lt (suc (suc (suc n))) lt with
div-mod2 (suc n) | div-mod2-lt (suc n) (s≤s z≤n)
... | q , r | ih = ≤-step (s≤s ih)
pow-lemma : ∀ b e → (b * b) ^ e ≡ b ^ (2 * e)
pow-lemma b e = begin
(b * b) ^ e ≡⟨ cong (λ t → (b * t) ^ e) (sym (*-identityʳ b)) ⟩
(b ^ 2) ^ e ≡⟨ ^-*-assoc b 2 e ⟩
b ^ (2 * e) ∎
pow-sqr-lemma : ∀ k b e → e ≤ k → pow-sqr-aux k b e ≡ b ^ e
pow-sqr-lemma 0 _ 0 _ = refl
pow-sqr-lemma (suc k) _ 0 _ = refl
pow-sqr-lemma (suc k) b (suc e) (s≤s le) with
div-mod2 (suc e) | div-mod2-spec (suc e) | div-mod2-lt (suc e) (s≤s z≤n)
... | e' , false | eq | lt = begin
pow-sqr-aux k (b * b) e' ≡⟨ pow-sqr-lemma k (b * b) e' (≤-trans (≤-pred lt) le) ⟩
(b * b) ^ e' ≡⟨ pow-lemma b e' ⟩
b ^ (2 * e') ≡⟨ cong (b ^_) (trans (sym (+-identityʳ (e' + (e' + 0)))) eq) ⟩
b ^ suc e ∎
... | e' , true | eq | lt = cong (b *_) (begin
pow-sqr-aux k (b * b) e' ≡⟨ pow-sqr-lemma k (b * b) e' (≤-trans (≤-pred lt) le) ⟩
(b * b) ^ e' ≡⟨ pow-lemma b e' ⟩
b ^ (2 * e') ≡⟨ cong (b ^_) (suc-injective (trans (+-comm 1 _) eq)) ⟩
b ^ e ∎)
| {
"alphanum_fraction": 0.541314554,
"avg_line_length": 32.7692307692,
"ext": "agda",
"hexsha": "0e79fa7c05b86b73e4be6e69d150ee04912055a0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Brethland/LEARNING-STUFF",
"max_forks_repo_path": "Agda/Squaring.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"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": "Brethland/LEARNING-STUFF",
"max_issues_repo_path": "Agda/Squaring.agda",
"max_line_length": 83,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Brethland/LEARNING-STUFF",
"max_stars_repo_path": "Agda/Squaring.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-11T10:35:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-03T05:05:52.000Z",
"num_tokens": 993,
"size": 2130
} |
module TemporalOps.StrongMonad where
open import CategoryTheory.Instances.Reactive
open import CategoryTheory.Functor
open import CategoryTheory.Monad
open import CategoryTheory.Comonad
open import CategoryTheory.NatTrans
open import CategoryTheory.BCCCs
open import CategoryTheory.CartesianStrength
open import TemporalOps.Next
open import TemporalOps.Delay
open import TemporalOps.Diamond
open import TemporalOps.Diamond.Join
open import TemporalOps.Box
open import TemporalOps.Common.Other
open import TemporalOps.Common.Compare
open import TemporalOps.Common.Rewriting
open import TemporalOps.OtherOps
open import Relation.Binary.PropositionalEquality as ≡ hiding (inspect)
open import Data.Product
open import Data.Sum
open import Data.Nat hiding (_*_)
open import Data.Nat.Properties
using (+-identityʳ ; +-comm ; +-suc ; +-assoc)
open import Holes.Term using (⌞_⌟)
open import Holes.Cong.Propositional
open Monad M-◇
open Comonad W-□
private module F-◇ = Functor F-◇
private module F-□ = Functor F-□
open ≡.≡-Reasoning
◇-□-Strong : WStrongMonad ℝeactive-cart M-◇ W-cart-□
◇-□-Strong = record
{ st = st-◇
; st-nat₁ = st-nat₁-◇
; st-nat₂ = st-nat₂-◇
; st-λ = st-λ-◇
; st-α = st-α-◇
; st-η = refl
; st-μ = λ{A}{B}{n}{a} -> st-μ-◇ {A}{B}{n}{a}
}
where
open Functor F-◇ renaming (fmap to ◇-f ; omap to ◇-o)
open Functor F-□ renaming (fmap to □-f ; omap to □-o)
private module ▹ᵏ-C k = CartesianFunctor (F-cart-delay k)
private module ▹ᵏ-F k = Functor (F-delay k)
private module ▹-F = Functor F-▹
private module ▹-C = CartesianFunctor (F-cart-▹)
private module □-C = CartesianFunctor (F-cart-□)
private module □-CW = CartesianComonad (W-cart-□)
private module □-▹ᵏ k = _⟹_ (□-to-▹ᵏ k)
st-◇ : ∀(A B : τ) -> □ A ⊗ ◇ B ⇴ ◇ (□ A ⊗ B)
st-◇ A B n (□A , (k , a)) = k , ▹ᵏ-C.m k (□ A) B n (□-▹ᵏ.at k (□ A) n (δ.at A k □A) , a)
st-nat₁-◇ : ∀{A B C : τ} (f : A ⇴ B)
-> ◇-f (□-f f * id) ∘ st-◇ A C ≈ st-◇ B C ∘ □-f f * id
st-nat₁-◇ {A} {B} {C} f {n} {□A , k , a}
rewrite ▹ᵏ-C.m-nat₁ k (□-f f)
{n} {(□-▹ᵏ.at k (□ A) n (δ.at A k □A)) , a}
| (□-▹ᵏ.nat-cond k {□ A} {□ B} {□-f f} {n} {δ.at A k □A})
= refl
st-nat₂-◇ : ∀{A B C : τ} (f : A ⇴ B)
-> ◇-f (id * f) ∘ st-◇ C A ≈ st-◇ C B ∘ id * ◇-f f
st-nat₂-◇ {A} {B} {C} f {n} {□C , k , a}
rewrite ▹ᵏ-C.m-nat₂ k f {n} {□-▹ᵏ.at k (□ C) n (δ.at C k □C) , a} = refl
st-λ-◇ : ∀{A} -> ◇-f π₂ ∘ st-◇ ⊤ A ≈ π₂
st-λ-◇ {A} {n} {□⊤ , (k , a)} =
begin
◇-f π₂ n (st-◇ ⊤ A n (□⊤ , (k , a)))
≡⟨⟩
◇-f π₂ n (k , ▹ᵏ-C.m k (□ ⊤) A n (□-▹ᵏ.at k (□ ⊤) n (δ.at ⊤ n □⊤) , a))
≡⟨⟩
k , ▹ᵏ-F.fmap k π₂ n (▹ᵏ-C.m k (□ ⊤) A n (□-▹ᵏ.at k (□ ⊤) n (δ.at ⊤ n □⊤) , a))
≡⟨ cong (λ x -> k , x) lemma ⟩
k , a
∎
where
lemma : ▹ᵏ-F.fmap k π₂ ∘ ▹ᵏ-C.m k (□ ⊤) A ≈ π₂
lemma {n} {t , b} =
begin
▹ᵏ-F.fmap k π₂ n (▹ᵏ-C.m k (□ ⊤) A n (t , b))
≡⟨⟩
▹ᵏ-F.fmap k π₂ n (▹ᵏ-C.m k (□ ⊤) A n (⌞ t ⌟ , b))
≡⟨ cong! (▹ᵏ-F.fmap-id k {□ ⊤}{n}{t}) ⟩
▹ᵏ-F.fmap k π₂ n (▹ᵏ-C.m k (□ ⊤) A n (▹ᵏ-F.fmap k ⌞ id ⌟ n t , b))
≡⟨⟩
▹ᵏ-F.fmap k π₂ n (▹ᵏ-C.m k (□ ⊤) A n (⌞ ▹ᵏ-F.fmap k (u ∘ ε.at ⊤) n t ⌟ , b))
≡⟨ cong! (▹ᵏ-F.fmap-∘ k) ⟩
▹ᵏ-F.fmap k π₂ n (▹ᵏ-C.m k (□ ⊤) A n (▹ᵏ-F.fmap k u n (▹ᵏ-F.fmap k (ε.at ⊤) n t) , b))
≡⟨ cong (▹ᵏ-F.fmap k π₂ n) (sym (▹ᵏ-C.m-nat₁ k u)) ⟩
▹ᵏ-F.fmap k π₂ n (▹ᵏ-F.fmap k (u * id) n (▹ᵏ-C.m k ⊤ A n (▹ᵏ-F.fmap k (ε.at ⊤) n t , b)))
≡⟨ sym (▹ᵏ-F.fmap-∘ k) ⟩
▹ᵏ-F.fmap k (π₂ ∘ u * id) n (▹ᵏ-C.m k ⊤ A n (▹ᵏ-F.fmap k (ε.at ⊤) n t , b))
≡⟨⟩
▹ᵏ-F.fmap k π₂ n (▹ᵏ-C.m k ⊤ A n (⌞ ▹ᵏ-F.fmap k (ε.at ⊤) n t ⌟ , b))
≡⟨ cong! (⊤-eq k n t) ⟩
▹ᵏ-F.fmap k π₂ n (▹ᵏ-C.m k ⊤ A n (▹ᵏ-C.u k n top.tt , b))
≡⟨ ▹ᵏ-C.unital-left k ⟩
b
∎
where
⊤-eq : ∀ k n t -> ▹ᵏ-F.fmap k (ε.at ⊤) n t ≡ ▹ᵏ-C.u k n top.tt
⊤-eq zero n t = refl
⊤-eq (suc k) zero t = refl
⊤-eq (suc k) (suc n) t = ⊤-eq k n t
st-α-◇ : ∀{A B C : τ}
-> st-◇ A (□ B ⊗ C) ∘ id * st-◇ B C ∘ assoc-right ∘ m⁻¹ A B * id
≈ ◇-f (assoc-right ∘ m⁻¹ A B * id) ∘ st-◇ (A ⊗ B) C
st-α-◇ {A} {B} {C} {n} {□A⊗B , (k , a)} =
begin
st-◇ A (□ B ⊗ C) n
(□-f π₁ n □A⊗B , st-◇ B C n (□-f π₂ n □A⊗B , (k , a)))
≡⟨ cong (λ x → k , x) (
begin
▹ᵏ-C.m k (□ A) (□ B ⊗ C) n
( □-▹ᵏ.at k (□ A) n (δ.at A k (□-f π₁ n □A⊗B))
, ▹ᵏ-C.m k (□ B) C n (□-▹ᵏ.at k (□ B) n (δ.at B n (□-f π₂ n □A⊗B)) , a))
≡⟨⟩ -- Naturality and definitional equality
▹ᵏ-C.m k (□ A) (□ B ⊗ C) n
((id {delay □ A by k} * ▹ᵏ-C.m k (□ B) C) n (assoc-right {delay □ A by k} {delay □ B by k} {delay C by k} n
(((□-▹ᵏ.at k (□ A) * □-▹ᵏ.at k (□ B)) n
((δ.at A * δ.at B) n (m⁻¹ A B n □A⊗B)))
, a)))
≡⟨ ▹ᵏ-C.associative k ⟩
▹ᵏ-F.fmap k assoc-right n
(▹ᵏ-C.m k (□ A ⊗ □ B) C n
( ⌞ ▹ᵏ-C.m k (□ A) (□ B) n
((□-▹ᵏ.at k (□ A) * □-▹ᵏ.at k (□ B)) n
((δ.at A * δ.at B) n (m⁻¹ A B n □A⊗B))) ⌟
, a))
≡⟨ cong! (lemma k) ⟩
▹ᵏ-F.fmap k assoc-right n
(▹ᵏ-C.m k (□ A ⊗ □ B) C n
( □-▹ᵏ.at k (□ A ⊗ □ B) n
(□-C.m (□ A) (□ B) n ((δ.at A * δ.at B) n (m⁻¹ A B n □A⊗B)))
, a))
≡⟨⟩
▹ᵏ-F.fmap k assoc-right n
(▹ᵏ-C.m k (□ A ⊗ □ B) C n
( ⌞ □-▹ᵏ.at k (□ A ⊗ □ B) n
(□-f (m⁻¹ A B) n (δ.at (A ⊗ B) k □A⊗B)) ⌟
, a))
≡⟨ cong! (□-▹ᵏ.nat-cond k {f = m⁻¹ A B} {n} {δ.at (A ⊗ B) k □A⊗B}) ⟩
▹ᵏ-F.fmap k assoc-right n
⌞ (▹ᵏ-C.m k (□ A ⊗ □ B) C n
(▹ᵏ-F.fmap k (m⁻¹ A B) n
(□-▹ᵏ.at k (□ (A ⊗ B)) n (δ.at (A ⊗ B) k □A⊗B))
, a)) ⌟
≡⟨ cong! (▹ᵏ-C.m-nat₁ k (m⁻¹ A B) {n}
{(□-▹ᵏ.at k (□ (A ⊗ B)) n (δ.at (A ⊗ B) k □A⊗B)) , a}) ⟩
▹ᵏ-F.fmap k assoc-right n
(▹ᵏ-F.fmap k (m⁻¹ A B * id) n (▹ᵏ-C.m k (□ (A ⊗ B)) C n
(□-▹ᵏ.at k (□ (A ⊗ B)) n (δ.at (A ⊗ B) k □A⊗B) , a)))
≡⟨ sym (▹ᵏ-F.fmap-∘ k) ⟩
▹ᵏ-F.fmap k (assoc-right ∘ m⁻¹ A B * id) n
(▹ᵏ-C.m k (□ (A ⊗ B)) C n (□-▹ᵏ.at k (□ (A ⊗ B)) n (δ.at (A ⊗ B) k □A⊗B) , a))
≡⟨⟩
▹ᵏ-F.fmap k (assoc-right ∘ m⁻¹ A B * id) n
(▹ᵏ-C.m k (□ (A ⊗ B)) C n (□-▹ᵏ.at k (□ (A ⊗ B)) n (δ.at (A ⊗ B) k □A⊗B) , a))
∎
) ⟩
◇-f (assoc-right ∘ m⁻¹ A B * id) n (st-◇ (A ⊗ B) C n (□A⊗B , (k , a)))
∎
where
lemma : ∀ k -> ▹ᵏ-C.m k (□ A) (□ B) ∘ □-▹ᵏ.at k (□ A) * □-▹ᵏ.at k (□ B)
≈ □-▹ᵏ.at k (□ A ⊗ □ B) ∘ □-C.m (□ A) (□ B)
lemma zero = refl
lemma (suc k) {zero} {□□A , □□B} = refl
lemma (suc k) {suc n} {□□A , □□B} = lemma k
st-μ-◇ : ∀{A B : τ}
-> μ.at (□ A ⊗ B) ∘ ◇-f (st-◇ A B) ∘ st-◇ A (◇ B)
≈ st-◇ A B ∘ (id * μ.at B)
st-μ-◇ {A} {B} {n} {□A , (k , a)} with inspect (compareLeq k n)
st-μ-◇ {A} {B} {.(k + l)} {□A , k , a} | snd==[ .k + l ] with≡ pf =
begin
μ.at (□ A ⊗ B) (k + l) (◇-f (st-◇ A B) (k + l) (st-◇ A (◇ B) (k + l) (□A , (k , a))))
≡⟨⟩
μ-compare (□ A ⊗ B) (k + l) k
(▹ᵏ-F.fmap k (st-◇ A B) (k + l)
(▹ᵏ-C.m k (□ A) (◇ B) (k + l)
(□-▹ᵏ.at k (□ A) (k + l) (δ.at A (k + l) □A) , a)))
(⌞ compareLeq k (k + l) ⌟)
≡⟨ cong! pf ⟩
μ-compare (□ A ⊗ B) (k + l) k
(▹ᵏ-F.fmap k (st-◇ A B) (k + l)
(▹ᵏ-C.m k (□ A) (◇ B) (k + l)
(□-▹ᵏ.at k (□ A) (k + l) (δ.at A (k + l) □A) , a)))
(snd==[ k + l ])
≡⟨⟩
μ-shift k l
(rew (delay-+-left0 k l)
(▹ᵏ-F.fmap k (st-◇ A B) (k + l)
(▹ᵏ-C.m k (□ A) (◇ B) (k + l)
( □-▹ᵏ.at k (□ A) (k + l) (δ.at A (k + l) □A)
, a))))
≡⟨ cong (μ-shift k l) (fmap-delay-+-n+0 k l) ⟩
μ-shift k l
(st-◇ A B l
(rew (delay-+-left0 k l)
(▹ᵏ-C.m k (□ A) (◇ B) (k + l)
( □-▹ᵏ.at k (□ A) (k + l) (δ.at A (k + l) □A)
, a))))
≡⟨ cong (λ x → μ-shift k l (st-◇ A B l x)) (m-delay-+-n+0 k l) ⟩
μ-shift k l
(st-◇ A B l
( rew (delay-+-left0 k l) (□-▹ᵏ.at k (□ A) (k + l) (δ.at A (k + l) □A))
, rew (delay-+-left0 k l) a))
≡⟨ cong (λ x → μ-shift k l (st-◇ A B l (x , _))) (rew-□-left0 k l) ⟩
μ-shift k l (st-◇ A B l (□A , rew (delay-+-left0 k l) a))
≡⟨ lemma k l (rew (delay-+-left0 k l) a) ⟩
st-◇ A B (k + l) (□A , μ-shift k l (rew (delay-+-left0 k l) a))
≡⟨⟩
st-◇ A B (k + l) (□A , μ-compare B (k + l) k a (⌞ snd==[ k + l ] ⌟))
≡⟨ cong! pf ⟩
st-◇ A B (k + l) (□A , μ.at B (k + l) (k , a))
∎
where
rew-□-left0 : ∀ k l
-> rew (delay-+-left0 k l) (□-▹ᵏ.at k (□ A) (k + l) (δ.at A (k + l) □A))
≡ □A
rew-□-left0 zero l = refl
rew-□-left0 (suc k) l = rew-□-left0 k l
rew-□ : ∀ k l m
-> rew (sym (delay-+ k m l)) (□-▹ᵏ.at m (□ A) l (δ.at A m □A))
≡ □-▹ᵏ.at (k + m) (□ A) (k + l) (δ.at A (k + m) □A)
rew-□ zero l m = refl
rew-□ (suc k) l m = rew-□ k l m
lemma : ∀ k l a
-> μ-shift k l (st-◇ A B l (□A , a))
≡ st-◇ A B (k + l) (□A , μ-shift k l a)
lemma k l (m , a) =
begin
μ-shift k l (st-◇ A B l (□A , (m , a)))
≡⟨⟩
k + m , rew (sym (delay-+ k m l)) (▹ᵏ-C.m m (□ A) B l (□-▹ᵏ.at m (□ A) l (δ.at A m □A) , a))
≡⟨ cong (λ x -> _ , x) (m-delay-+-sym k l m) ⟩
k + m , ▹ᵏ-C.m (k + m) (□ A) B (k + l)
( rew (sym (delay-+ k m l)) (□-▹ᵏ.at m (□ A) l (δ.at A m □A))
, rew (sym (delay-+ k m l)) a)
≡⟨ cong (λ x → _ , ▹ᵏ-C.m (k + m) (□ A) B (k + l) (x , _)) (rew-□ k l m) ⟩
k + m , ▹ᵏ-C.m (k + m) (□ A) B (k + l)
( □-▹ᵏ.at (k + m) (□ A) (k + l) (δ.at A (k + m) □A)
, rew (sym (delay-+ k m l)) a)
≡⟨⟩
st-◇ A B (k + l) (□A , (k + m , rew (sym (delay-+ k m l)) a))
∎
st-μ-◇ {A} {B} {.n} {□A , .(n + suc l) , a} | fst==suc[ n + l ] with≡ pf =
begin
μ.at (□ A ⊗ B) n (◇-f (st-◇ A B) n (st-◇ A (◇ B) n (□A , (n + suc l , a))))
≡⟨⟩
μ-compare (□ A ⊗ B) n (n + suc l)
(▹ᵏ-F.fmap (n + suc l) (st-◇ A B) n
(▹ᵏ-C.m (n + suc l) (□ A) (◇ B) n
(□-▹ᵏ.at (n + suc l) (□ A) n
(δ.at A (n + suc l) □A) , a)))
(⌞ compareLeq (n + suc l) n ⌟)
≡⟨ cong! pf ⟩
μ-compare (□ A ⊗ B) n (n + suc l)
(▹ᵏ-F.fmap (n + suc l) (st-◇ A B) n
(▹ᵏ-C.m (n + suc l) (□ A) (◇ B) n
(□-▹ᵏ.at (n + suc l) (□ A) n
(δ.at A (n + suc l) □A) , a)))
(fst==suc[ n + l ])
≡⟨⟩
n + suc l , rew (delay-⊤ n l) top.tt
≡⟨ cong (λ x -> _ , x) (lemma n l) ⟩
n + suc l , ▹ᵏ-C.m (n + suc l) (□ A) B n (□-▹ᵏ.at (n + suc l) (□ A) n (δ.at A (n + suc l) □A) , rew (delay-⊤ n l) top.tt)
≡⟨⟩
st-◇ A B n (□A , μ-compare B n (n + suc l) a (⌞ fst==suc[ n + l ] ⌟))
≡⟨ cong! pf ⟩
st-◇ A B n (□A , μ.at B n ((n + suc l) , a))
∎
where
lemma : ∀ n l
-> rew (delay-⊤ n l) top.tt
≡ ▹ᵏ-C.m (n + suc l) (□ A) B n (□-▹ᵏ.at (n + suc l) (□ A) n (δ.at A (n + suc l) □A)
, rew (delay-⊤ n l) top.tt)
lemma zero l = refl
lemma (suc n) l = lemma n l
open WStrongMonad ◇-□-Strong public
| {
"alphanum_fraction": 0.3405584696,
"avg_line_length": 43.6498316498,
"ext": "agda",
"hexsha": "9b2c9092728f79fb5295ec029c3d14358a5bcd5b",
"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": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/TemporalOps/StrongMonad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"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": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/TemporalOps/StrongMonad.agda",
"max_line_length": 133,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/TemporalOps/StrongMonad.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 6170,
"size": 12964
} |
module Numeral.Natural.Relation.Order.Existence where
import Lvl
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Proofs
import Numeral.Natural.Relation.Order as [≤def]
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Relator.Ordering
open import Structure.Function
open import Structure.Function.Domain
open import Syntax.Function
open import Syntax.Transitivity
_≤_ : ℕ → ℕ → Stmt
_≤_ a b = ∃{Obj = ℕ}(n ↦ a + n ≡ b)
_<_ : ℕ → ℕ → Stmt
_<_ a b = (𝐒(a) ≤ b)
open From-[≤][<] (_≤_) (_<_) public
[≤]-with-[𝐒] : ∀{a b : ℕ} → (a ≤ b) → (𝐒(a) ≤ 𝐒(b))
[≤]-with-[𝐒] {a} {b} ([∃]-intro n ⦃ f ⦄) =
[∃]-intro n ⦃
𝐒(a) + n 🝖[ _≡_ ]-[ [+]-stepₗ {a} {n} ]
𝐒(a + n) 🝖[ _≡_ ]-[ congruence₁(𝐒) f ]
𝐒(b) 🝖-end
⦄
[≤]-equivalence : ∀{x y} → (x ≤ y) ↔ (x [≤def].≤ y)
[≤]-equivalence{x}{y} = [↔]-intro (l{x}{y}) (r{x}{y}) where
l : ∀{x y} → (x ≤ y) ← (x [≤def].≤ y)
l{𝟎} {y} ([≤def].min) = [∃]-intro(y) ⦃ [≡]-intro ⦄
l{𝐒(x)}{𝟎} ()
l{𝐒(x)}{𝐒(y)} ([≤def].succ proof) = [≤]-with-[𝐒] {x}{y} (l{x}{y} (proof))
r : ∀{x y} → (x ≤ y) → (x [≤def].≤ y)
r{𝟎} {y} ([∃]-intro(z) ⦃ 𝟎+z≡y ⦄) = [≤def].min
r{𝐒(x)}{𝟎} ([∃]-intro(z) ⦃ ⦄)
r{𝐒(x)}{𝐒(y)} ([∃]-intro(z) ⦃ 𝐒x+z≡𝐒y ⦄) = [≤def].succ (r{x}{y} ([∃]-intro(z) ⦃ injective(𝐒)(𝐒x+z≡𝐒y) ⦄))
| {
"alphanum_fraction": 0.5331935709,
"avg_line_length": 31.1086956522,
"ext": "agda",
"hexsha": "dfa461a09e63b5206e6570e6dba7a29c563b7f4d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Relation/Order/Existence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Relation/Order/Existence.agda",
"max_line_length": 107,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Relation/Order/Existence.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": 720,
"size": 1431
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Greatest common divisor
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.GCD where
open import Data.Nat.Base
open import Data.Nat.Divisibility
open import Data.Nat.DivMod
open import Data.Nat.GCD.Lemmas
open import Data.Nat.Properties
open import Data.Nat.Induction
using (Acc; acc; <′-Rec; <′-recBuilder; <-wellFounded)
open import Data.Product
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
open import Function
open import Induction using (build)
open import Induction.Lexicographic using (_⊗_; [_⊗_])
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≢_; subst; cong)
open import Relation.Nullary using (Dec)
open import Relation.Nullary.Negation using (contradiction)
import Relation.Nullary.Decidable as Dec
------------------------------------------------------------------------
-- Definition
-- Calculated via Euclid's algorithm. In order to show progress,
-- avoiding the initial step where the first argument may increase, it
-- is necessary to first define a version `gcd′` which assumes that the
-- first argument is strictly smaller than the second. The full `gcd`
-- function then compares the two arguments and applies `gcd′`
-- accordingly.
gcd′ : ∀ m n → Acc _<_ m → n < m → ℕ
gcd′ m zero _ _ = m
gcd′ m n@(suc n-1) (acc rec) n<m = gcd′ n (m % n) (rec _ n<m) (m%n<n m n-1)
gcd : ℕ → ℕ → ℕ
gcd m n with <-cmp m n
... | tri< m<n _ _ = gcd′ n m (<-wellFounded n) m<n
... | tri≈ _ _ _ = m
... | tri> _ _ n<m = gcd′ m n (<-wellFounded m) n<m
------------------------------------------------------------------------
-- Core properties of gcd′
gcd′[m,n]∣m,n : ∀ {m n} rec n<m → gcd′ m n rec n<m ∣ m × gcd′ m n rec n<m ∣ n
gcd′[m,n]∣m,n {m} {zero} rec n<m = ∣-refl , m ∣0
gcd′[m,n]∣m,n {m} {suc n} (acc rec) n<m
with gcd′[m,n]∣m,n (rec _ n<m) (m%n<n m n)
... | gcd∣n , gcd∣m%n = ∣n∣m%n⇒∣m gcd∣n gcd∣m%n , gcd∣n
gcd′-greatest : ∀ {m n c} rec n<m → c ∣ m → c ∣ n → c ∣ gcd′ m n rec n<m
gcd′-greatest {m} {zero} rec n<m c∣m c∣n = c∣m
gcd′-greatest {m} {suc n} (acc rec) n<m c∣m c∣n =
gcd′-greatest (rec _ n<m) (m%n<n m n) c∣n (%-presˡ-∣ c∣m c∣n)
------------------------------------------------------------------------
-- Core properties of gcd
gcd[m,n]∣m : ∀ m n → gcd m n ∣ m
gcd[m,n]∣m m n with <-cmp m n
... | tri< n<m _ _ = proj₂ (gcd′[m,n]∣m,n {n} {m} _ _)
... | tri≈ _ _ _ = ∣-refl
... | tri> _ _ m<n = proj₁ (gcd′[m,n]∣m,n {m} {n} _ _)
gcd[m,n]∣n : ∀ m n → gcd m n ∣ n
gcd[m,n]∣n m n with <-cmp m n
... | tri< n<m _ _ = proj₁ (gcd′[m,n]∣m,n {n} {m} _ _)
... | tri≈ _ P.refl _ = ∣-refl
... | tri> _ _ m<n = proj₂ (gcd′[m,n]∣m,n {m} {n} _ _)
gcd-greatest : ∀ {m n c} → c ∣ m → c ∣ n → c ∣ gcd m n
gcd-greatest {m} {n} c∣m c∣n with <-cmp m n
... | tri< n<m _ _ = gcd′-greatest _ _ c∣n c∣m
... | tri≈ _ _ _ = c∣m
... | tri> _ _ m<n = gcd′-greatest _ _ c∣m c∣n
------------------------------------------------------------------------
-- Other properties
-- Note that all other properties of `gcd` should be inferable from the
-- 3 core properties above.
gcd[0,0]≡0 : gcd 0 0 ≡ 0
gcd[0,0]≡0 = ∣-antisym (gcd 0 0 ∣0) (gcd-greatest (0 ∣0) (0 ∣0))
gcd[m,n]≢0 : ∀ m n → m ≢ 0 ⊎ n ≢ 0 → gcd m n ≢ 0
gcd[m,n]≢0 m n (inj₁ m≢0) eq = m≢0 (0∣⇒≡0 (subst (_∣ m) eq (gcd[m,n]∣m m n)))
gcd[m,n]≢0 m n (inj₂ n≢0) eq = n≢0 (0∣⇒≡0 (subst (_∣ n) eq (gcd[m,n]∣n m n)))
gcd[m,n]≡0⇒m≡0 : ∀ {m n} → gcd m n ≡ 0 → m ≡ 0
gcd[m,n]≡0⇒m≡0 {zero} {n} eq = P.refl
gcd[m,n]≡0⇒m≡0 {suc m} {n} eq = contradiction eq (gcd[m,n]≢0 (suc m) n (inj₁ λ()))
gcd[m,n]≡0⇒n≡0 : ∀ m {n} → gcd m n ≡ 0 → n ≡ 0
gcd[m,n]≡0⇒n≡0 m {zero} eq = P.refl
gcd[m,n]≡0⇒n≡0 m {suc n} eq = contradiction eq (gcd[m,n]≢0 m (suc n) (inj₂ λ()))
gcd-comm : ∀ m n → gcd m n ≡ gcd n m
gcd-comm m n = ∣-antisym
(gcd-greatest (gcd[m,n]∣n m n) (gcd[m,n]∣m m n))
(gcd-greatest (gcd[m,n]∣n n m) (gcd[m,n]∣m n m))
gcd-universality : ∀ {m n g} →
(∀ {d} → d ∣ m × d ∣ n → d ∣ g) →
(∀ {d} → d ∣ g → d ∣ m × d ∣ n) →
g ≡ gcd m n
gcd-universality {m} {n} forwards backwards with backwards ∣-refl
... | back₁ , back₂ = ∣-antisym
(gcd-greatest back₁ back₂)
(forwards (gcd[m,n]∣m m n , gcd[m,n]∣n m n))
-- This could be simplified with some nice backwards/forwards reasoning
-- after the new function hierarchy is up and running.
gcd[cm,cn]/c≡gcd[m,n] : ∀ c m n {≢0} → (gcd (c * m) (c * n) / c) {≢0} ≡ gcd m n
gcd[cm,cn]/c≡gcd[m,n] c@(suc c-1) m n = gcd-universality forwards backwards
where
forwards : ∀ {d : ℕ} → d ∣ m × d ∣ n → d ∣ gcd (c * m) (c * n) / c
forwards {d} (d∣m , d∣n) = m*n∣o⇒n∣o/m c d (gcd-greatest (*-monoʳ-∣ c d∣m) (*-monoʳ-∣ c d∣n))
backwards : ∀ {d : ℕ} → d ∣ gcd (c * m) (c * n) / c → d ∣ m × d ∣ n
backwards {d} d∣gcd[cm,cn]/c with m∣n/o⇒o*m∣n (gcd-greatest (m∣m*n m) (m∣m*n n)) d∣gcd[cm,cn]/c
... | cd∣gcd[cm,n] =
*-cancelˡ-∣ c-1 (∣-trans cd∣gcd[cm,n] (gcd[m,n]∣m (c * m) _)) ,
*-cancelˡ-∣ c-1 (∣-trans cd∣gcd[cm,n] (gcd[m,n]∣n (c * m) _))
c*gcd[m,n]≡gcd[cm,cn] : ∀ c m n → c * gcd m n ≡ gcd (c * m) (c * n)
c*gcd[m,n]≡gcd[cm,cn] zero m n = P.sym gcd[0,0]≡0
c*gcd[m,n]≡gcd[cm,cn] c@(suc c-1) m n = begin
c * gcd m n ≡⟨ cong (c *_) (P.sym (gcd[cm,cn]/c≡gcd[m,n] c m n)) ⟩
c * (gcd (c * m) (c * n) / c) ≡⟨ m*[n/m]≡n (gcd-greatest (m∣m*n m) (m∣m*n n)) ⟩
gcd (c * m) (c * n) ∎
where open P.≡-Reasoning
gcd[m,n]≤n : ∀ m n → gcd m (suc n) ≤ suc n
gcd[m,n]≤n m n = ∣⇒≤ (gcd[m,n]∣n m (suc n))
n/gcd[m,n]≢0 : ∀ m n {n≢0 : Dec.False (n ≟ 0)} {gcd≢0} → (n / gcd m n) {gcd≢0} ≢ 0
n/gcd[m,n]≢0 m n@(suc n-1) {n≢0} {gcd≢0} = m<n⇒n≢0 (m≥n⇒m/n>0 {n} {gcd m n} {gcd≢0} (gcd[m,n]≤n m n-1))
------------------------------------------------------------------------
-- A formal specification of GCD
module GCD where
-- Specification of the greatest common divisor (gcd) of two natural
-- numbers.
record GCD (m n gcd : ℕ) : Set where
constructor is
field
-- The gcd is a common divisor.
commonDivisor : gcd ∣ m × gcd ∣ n
-- All common divisors divide the gcd, i.e. the gcd is the
-- greatest common divisor according to the partial order _∣_.
greatest : ∀ {d} → d ∣ m × d ∣ n → d ∣ gcd
open GCD public
-- The gcd is unique.
unique : ∀ {d₁ d₂ m n} → GCD m n d₁ → GCD m n d₂ → d₁ ≡ d₂
unique d₁ d₂ = ∣-antisym (GCD.greatest d₂ (GCD.commonDivisor d₁))
(GCD.greatest d₁ (GCD.commonDivisor d₂))
-- The gcd relation is "symmetric".
sym : ∀ {d m n} → GCD m n d → GCD n m d
sym g = is (swap $ GCD.commonDivisor g) (GCD.greatest g ∘ swap)
-- The gcd relation is "reflexive".
refl : ∀ {n} → GCD n n n
refl = is (∣-refl , ∣-refl) proj₁
-- The GCD of 0 and n is n.
base : ∀ {n} → GCD 0 n n
base {n} = is (n ∣0 , ∣-refl) proj₂
-- If d is the gcd of n and k, then it is also the gcd of n and
-- n + k.
step : ∀ {n k d} → GCD n k d → GCD n (n + k) d
step g with GCD.commonDivisor g
step {n} {k} {d} g | (d₁ , d₂) = is (d₁ , ∣m∣n⇒∣m+n d₁ d₂) greatest′
where
greatest′ : ∀ {d′} → d′ ∣ n × d′ ∣ n + k → d′ ∣ d
greatest′ (d₁ , d₂) = GCD.greatest g (d₁ , ∣m+n∣m⇒∣n d₂ d₁)
open GCD public using (GCD) hiding (module GCD)
-- The function gcd fulfils the conditions required of GCD
gcd-GCD : ∀ m n → GCD m n (gcd m n)
gcd-GCD m n = record
{ commonDivisor = gcd[m,n]∣m m n , gcd[m,n]∣n m n
; greatest = uncurry′ gcd-greatest
}
-- Calculates the gcd of the arguments.
mkGCD : ∀ m n → ∃ λ d → GCD m n d
mkGCD m n = gcd m n , gcd-GCD m n
-- gcd as a proposition is decidable
gcd? : (m n d : ℕ) → Dec (GCD m n d)
gcd? m n d =
Dec.map′ (λ { P.refl → gcd-GCD m n }) (GCD.unique (gcd-GCD m n))
(gcd m n ≟ d)
GCD-* : ∀ {m n d c} → GCD (m * suc c) (n * suc c) (d * suc c) → GCD m n d
GCD-* (GCD.is (dc∣nc , dc∣mc) dc-greatest) =
GCD.is (*-cancelʳ-∣ _ dc∣nc , *-cancelʳ-∣ _ dc∣mc)
λ {_} → *-cancelʳ-∣ _ ∘ dc-greatest ∘ map (*-monoˡ-∣ _) (*-monoˡ-∣ _)
GCD-/ : ∀ {m n d c} {≢0} → c ∣ m → c ∣ n → c ∣ d →
GCD m n d → GCD ((m / c) {≢0}) ((n / c) {≢0}) ((d / c) {≢0})
GCD-/ {m} {n} {d} {c@(suc c-1)}
(divides p P.refl) (divides q P.refl) (divides r P.refl) gcd
rewrite m*n/n≡m p c {_} | m*n/n≡m q c {_} | m*n/n≡m r c {_} = GCD-* gcd
GCD-/gcd : ∀ m n {≢0} → GCD ((m / gcd m n) {≢0}) ((n / gcd m n) {≢0}) 1
GCD-/gcd m n {≢0} rewrite P.sym (n/n≡1 (gcd m n) {≢0}) =
GCD-/ {≢0 = ≢0} (gcd[m,n]∣m m n) (gcd[m,n]∣n m n) ∣-refl (gcd-GCD m n)
------------------------------------------------------------------------
-- Calculating the gcd
-- The calculation also proves Bézout's lemma.
module Bézout where
module Identity where
-- If m and n have greatest common divisor d, then one of the
-- following two equations is satisfied, for some numbers x and y.
-- The proof is "lemma" below (Bézout's lemma).
--
-- (If this identity was stated using integers instead of natural
-- numbers, then it would not be necessary to have two equations.)
data Identity (d m n : ℕ) : Set where
+- : (x y : ℕ) (eq : d + y * n ≡ x * m) → Identity d m n
-+ : (x y : ℕ) (eq : d + x * m ≡ y * n) → Identity d m n
-- Various properties about Identity.
sym : ∀ {d} → Symmetric (Identity d)
sym (+- x y eq) = -+ y x eq
sym (-+ x y eq) = +- y x eq
refl : ∀ {d} → Identity d d d
refl = -+ 0 1 P.refl
base : ∀ {d} → Identity d 0 d
base = -+ 0 1 P.refl
private
infixl 7 _⊕_
_⊕_ : ℕ → ℕ → ℕ
m ⊕ n = 1 + m + n
step : ∀ {d n k} → Identity d n k → Identity d n (n + k)
step {d} {n} (+- x y eq) with compare x y
... | equal x = +- (2 * x) x (lem₂ d x eq)
... | less x i = +- (2 * x ⊕ i) (x ⊕ i) (lem₃ d x eq)
... | greater y i = +- (2 * y ⊕ i) y (lem₄ d y n eq)
step {d} {n} (-+ x y eq) with compare x y
... | equal x = -+ (2 * x) x (lem₅ d x eq)
... | less x i = -+ (2 * x ⊕ i) (x ⊕ i) (lem₆ d x eq)
... | greater y i = -+ (2 * y ⊕ i) y (lem₇ d y n eq)
open Identity public using (Identity; +-; -+) hiding (module Identity)
module Lemma where
-- This type packs up the gcd, the proof that it is a gcd, and the
-- proof that it satisfies Bézout's identity.
data Lemma (m n : ℕ) : Set where
result : (d : ℕ) (g : GCD m n d) (b : Identity d m n) → Lemma m n
-- Various properties about Lemma.
sym : Symmetric Lemma
sym (result d g b) = result d (GCD.sym g) (Identity.sym b)
base : ∀ d → Lemma 0 d
base d = result d GCD.base Identity.base
refl : ∀ d → Lemma d d
refl d = result d GCD.refl Identity.refl
stepˡ : ∀ {n k} → Lemma n (suc k) → Lemma n (suc (n + k))
stepˡ {n} {k} (result d g b) =
subst (Lemma n) (+-suc n k) $
result d (GCD.step g) (Identity.step b)
stepʳ : ∀ {n k} → Lemma (suc k) n → Lemma (suc (n + k)) n
stepʳ = sym ∘ stepˡ ∘ sym
open Lemma public using (Lemma; result) hiding (module Lemma)
-- Bézout's lemma proved using some variant of the extended
-- Euclidean algorithm.
lemma : (m n : ℕ) → Lemma m n
lemma m n = build [ <′-recBuilder ⊗ <′-recBuilder ] P gcd″ (m , n)
where
P : ℕ × ℕ → Set
P (m , n) = Lemma m n
gcd″ : ∀ p → (<′-Rec ⊗ <′-Rec) P p → P p
gcd″ (zero , n ) rec = Lemma.base n
gcd″ (suc m , zero ) rec = Lemma.sym (Lemma.base (suc m))
gcd″ (suc m , suc n ) rec with compare m n
... | equal .m = Lemma.refl (suc m)
... | less .m k = Lemma.stepˡ $ proj₁ rec (suc k) (lem₁ k m)
-- "gcd (suc m) (suc k)"
... | greater .n k = Lemma.stepʳ $ proj₂ rec (suc k) (lem₁ k n) (suc n)
-- "gcd (suc k) (suc n)"
-- Bézout's identity can be recovered from the GCD.
identity : ∀ {m n d} → GCD m n d → Identity d m n
identity {m} {n} g with lemma m n
... | result d g′ b with GCD.unique g g′
... | P.refl = b
| {
"alphanum_fraction": 0.5068189287,
"avg_line_length": 35.8,
"ext": "agda",
"hexsha": "9e46c712f1234fd058cb32b724e768a904fa0ae6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Nat/GCD.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Nat/GCD.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/Data/Nat/GCD.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": 4990,
"size": 12172
} |
open import Nat
open import Prelude
open import contexts
open import dynamics-core
module canonical-value-forms where
canonical-value-forms-num : ∀{Δ d} →
Δ , ∅ ⊢ d :: num →
d val →
Σ[ n ∈ Nat ] (d == N n)
canonical-value-forms-num TANum VNum = _ , refl
canonical-value-forms-num (TAVar x₁) ()
canonical-value-forms-num (TAAp wt wt₁) ()
canonical-value-forms-num (TAEHole x x₁) ()
canonical-value-forms-num (TANEHole x wt x₁) ()
canonical-value-forms-num (TACast wt x) ()
canonical-value-forms-num (TAFailedCast wt x x₁ x₂) ()
canonical-value-forms-arr : ∀{Δ d τ1 τ2} →
Δ , ∅ ⊢ d :: (τ1 ==> τ2) →
d val →
Σ[ x ∈ Nat ] Σ[ d' ∈ ihexp ]
((d == (·λ x ·[ τ1 ] d')) ×
(Δ , ■ (x , τ1) ⊢ d' :: τ2))
canonical-value-forms-arr (TAVar x₁) ()
canonical-value-forms-arr {Δ = Δ} {d = ·λ x ·[ τ1 ] d} {τ1 = τ1} {τ2 = τ2} (TALam _ wt) VLam
= _ , _ , refl , tr (λ Γ → Δ , Γ ⊢ d :: τ2) (extend-empty x τ1) wt
canonical-value-forms-arr (TAAp wt wt₁) ()
canonical-value-forms-arr (TAEHole x x₁) ()
canonical-value-forms-arr (TANEHole x wt x₁) ()
canonical-value-forms-arr (TACast wt x) ()
canonical-value-forms-arr (TAFailedCast x x₁ x₂ x₃) ()
canonical-value-form-sum : ∀{Δ d τ1 τ2} →
Δ , ∅ ⊢ d :: (τ1 ⊕ τ2) →
d val →
(Σ[ d' ∈ ihexp ] ((d == (inl τ2 d')) × (Δ , ∅ ⊢ d' :: τ1))) +
(Σ[ d' ∈ ihexp ] ((d == (inr τ1 d')) × (Δ , ∅ ⊢ d' :: τ2)))
canonical-value-form-sum (TAInl wt) (VInl v) = Inl (_ , refl , wt)
canonical-value-form-sum (TAInr wt) (VInr v) = Inr (_ , refl , wt)
canonical-value-form-prod : ∀{Δ d τ1 τ2} →
Δ , ∅ ⊢ d :: (τ1 ⊠ τ2) →
d val →
Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ]
((d == ⟨ d1 , d2 ⟩) ×
(Δ , ∅ ⊢ d1 :: τ1) ×
(Δ , ∅ ⊢ d2 :: τ2))
canonical-value-form-prod (TAVar x) ()
canonical-value-form-prod (TAAp wt wt₁) ()
canonical-value-form-prod (TACase wt x wt₁ x₁ wt₂) ()
canonical-value-form-prod (TAPair wt wt₁) (VPair v v₁) = _ , _ , refl , wt , wt₁
canonical-value-form-prod (TAFst wt) ()
canonical-value-form-prod (TASnd wt) ()
canonical-value-form-prod (TAEHole x x₁) ()
canonical-value-form-prod (TANEHole x wt x₁) ()
canonical-value-form-prod (TACast wt x) ()
canonical-value-form-prod (TAFailedCast wt x x₁ x₂) ()
-- this argues (somewhat informally, because you still have to inspect
-- the types of the theorems above and manually verify this property)
-- that we didn't miss any cases above; this intentionally will make this
-- file fail to typecheck if we added more types, hopefully forcing us to
-- remember to add canonical forms lemmas as appropriate
canonical-value-forms-coverage1 : ∀{Δ d τ} →
Δ , ∅ ⊢ d :: τ →
d val →
τ ≠ num →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ⊕ τ2)) →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ⊠ τ2)) →
⊥
canonical-value-forms-coverage1 TANum val nn na ns np = nn refl
canonical-value-forms-coverage1 (TALam x wt) val nn na ns np = na _ _ refl
canonical-value-forms-coverage1 (TAInl wt) val nn na ns np = ns _ _ refl
canonical-value-forms-coverage1 (TAInr wt) val nn na ns np = ns _ _ refl
canonical-value-forms-coverage1 (TAPair wt wt₁) val nn na ns np = np _ _ refl
canonical-value-forms-coverage2 : ∀{Δ d} →
Δ , ∅ ⊢ d :: ⦇-⦈ →
d val →
⊥
canonical-value-forms-coverage2 (TAVar x₁) ()
canonical-value-forms-coverage2 (TAAp wt wt₁) ()
canonical-value-forms-coverage2 (TAEHole x x₁) ()
canonical-value-forms-coverage2 (TANEHole x wt x₁) ()
canonical-value-forms-coverage2 (TACast wt x) ()
canonical-value-forms-coverage2 (TAFailedCast wt x x₁ x₂) ()
| {
"alphanum_fraction": 0.4966139955,
"avg_line_length": 49.7752808989,
"ext": "agda",
"hexsha": "68f5fd37a5a2f760036dd7e595c43487a3374654",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "canonical-value-forms.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "canonical-value-forms.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "canonical-value-forms.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1391,
"size": 4430
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.DStructures.Meta.Isomorphism where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Functions.FunExtEquiv
open import Cubical.Homotopy.Base
open import Cubical.Data.Sigma
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Structures.LeftAction
open import Cubical.DStructures.Base
open import Cubical.DStructures.Meta.Properties
open import Cubical.DStructures.Structures.Constant
open import Cubical.DStructures.Structures.Type
open import Cubical.DStructures.Structures.Group
private
variable
ℓ ℓ' ℓ'' ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓA ℓA' ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓ≅B' ℓC ℓ≅C ℓ≅ᴰ ℓ≅ᴰ' : Level
open URGStr
open URGStrᴰ
----------------------------------------------
-- Pseudo-isomorphisms between URG structures
-- are relational isos of the underlying rel.
----------------------------------------------
𝒮-PIso : {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A)
{A' : Type ℓA'} (𝒮-A' : URGStr A' ℓ≅A')
→ Type (ℓ-max (ℓ-max ℓA ℓA') (ℓ-max ℓ≅A ℓ≅A'))
𝒮-PIso 𝒮-A 𝒮-A' = RelIso (URGStr._≅_ 𝒮-A) (URGStr._≅_ 𝒮-A')
----------------------------------------------
-- Since the relations are univalent,
-- a rel. iso induces an iso of the underlying
-- types.
----------------------------------------------
𝒮-PIso→Iso : {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A)
{A' : Type ℓA'} (𝒮-A' : URGStr A' ℓ≅A')
(ℱ : 𝒮-PIso 𝒮-A 𝒮-A')
→ Iso A A'
𝒮-PIso→Iso 𝒮-A 𝒮-A' ℱ
= RelIso→Iso (_≅_ 𝒮-A) (_≅_ 𝒮-A') (uni 𝒮-A) (uni 𝒮-A') ℱ
----------------------------------------------
-- From a DURG structure, extract the
-- relational family over the base type
----------------------------------------------
𝒮ᴰ→relFamily : {A : Type ℓA} {𝒮-A : URGStr A ℓ≅A}
{B : A → Type ℓB} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B)
→ RelFamily A ℓB ℓ≅B
-- define the type family, just B
𝒮ᴰ→relFamily {B = B} 𝒮ᴰ-B .fst = B
-- the binary relation is the displayed relation over ρ a
𝒮ᴰ→relFamily {𝒮-A = 𝒮-A} {B = B} 𝒮ᴰ-B .snd {a = a} b b'
= 𝒮ᴰ-B ._≅ᴰ⟨_⟩_ b (𝒮-A .ρ a) b'
--------------------------------------------------------------
-- the type of relational isos between a DURG structure
-- and the pulled back relational family of another
--
-- ℱ will in applications always be an isomorphism,
-- but that's not needed for this definition.
--------------------------------------------------------------
𝒮ᴰ-♭PIso : {A : Type ℓA} {𝒮-A : URGStr A ℓ≅A}
{A' : Type ℓA'} {𝒮-A' : URGStr A' ℓ≅A'}
(ℱ : A → A')
{B : A → Type ℓB} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B)
{B' : A' → Type ℓB'} (𝒮ᴰ-B' : URGStrᴰ 𝒮-A' B' ℓ≅B')
→ Type (ℓ-max ℓA (ℓ-max (ℓ-max ℓB ℓB') (ℓ-max ℓ≅B ℓ≅B')))
𝒮ᴰ-♭PIso ℱ 𝒮ᴰ-B 𝒮ᴰ-B'
= ♭RelFiberIsoOver ℱ (𝒮ᴰ→relFamily 𝒮ᴰ-B) (𝒮ᴰ→relFamily 𝒮ᴰ-B')
---------------------------------------------------------
-- Given
-- - an isomorphism ℱ of underlying types A, A', and
-- - an 𝒮ᴰ-bPIso over ℱ
-- produce an iso of the underlying total spaces
---------------------------------------------------------
𝒮ᴰ-♭PIso-Over→TotalIso : {A : Type ℓA} {𝒮-A : URGStr A ℓ≅A}
{A' : Type ℓA'} {𝒮-A' : URGStr A' ℓ≅A'}
(ℱ : Iso A A')
{B : A → Type ℓB} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B)
{B' : A' → Type ℓB'} (𝒮ᴰ-B' : URGStrᴰ 𝒮-A' B' ℓ≅B')
(𝒢 : 𝒮ᴰ-♭PIso (Iso.fun ℱ) 𝒮ᴰ-B 𝒮ᴰ-B')
→ Iso (Σ A B) (Σ A' B')
𝒮ᴰ-♭PIso-Over→TotalIso ℱ 𝒮ᴰ-B 𝒮ᴰ-B' 𝒢
= RelFiberIsoOver→Iso ℱ
(𝒮ᴰ→relFamily 𝒮ᴰ-B) (𝒮ᴰ-B .uniᴰ)
(𝒮ᴰ→relFamily 𝒮ᴰ-B') (𝒮ᴰ-B' .uniᴰ)
𝒢
| {
"alphanum_fraction": 0.5092927207,
"avg_line_length": 37.25,
"ext": "agda",
"hexsha": "8e0406f06d993a116082a6d0e0b391af7508b811",
"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/DStructures/Meta/Isomorphism.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/DStructures/Meta/Isomorphism.agda",
"max_line_length": 83,
"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/DStructures/Meta/Isomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1555,
"size": 3874
} |
module Structure.Function.Multi where
open import Data
open import Data.Boolean
open import Data.Tuple.Raise
import Data.Tuple.Raiseᵣ.Functions as Raise
open import Data.Tuple.RaiseTypeᵣ
import Data.Tuple.RaiseTypeᵣ.Functions as RaiseType
open import Function.DomainRaise as DomainRaise using (_→̂_)
import Function.Equals.Multi as Multi
open import Function.Multi
import Function.Multi.Functions as Multi
open import Functional
open import Lang.Instance
open import Logic
open import Logic.Propositional
open import Logic.Predicate
import Lvl
import Lvl.MultiFunctions as Lvl
open import Numeral.Natural
open import Numeral.Natural.Oper.Comparisons
open import Structure.Setoid.Uniqueness
open import Structure.Setoid
open import Syntax.Number
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓₑ ℓₑ₁ ℓₑ₂ ℓₗ : Lvl.Level
private variable n : ℕ
module Names where
module _ {X : Type{ℓ₁}} {Y : Type{ℓ₂}} ⦃ _ : Equiv{ℓₑ₂}(Y) ⦄ where
-- Definition of the relation between a function and an operation that says:
-- The function preserves the operation.
-- Often used when defining homomorphisms.
-- Examples:
-- Preserving(1) (f)(g₁)(g₂)
-- = (∀{x} → (f ∘₁ g₁)(x) ≡ (g₂ on₁ f)(x))
-- = (∀{x} → (f(g₁(x)) ≡ g₂(f(x)))
-- Preserving(2) (f)(g₁)(g₂)
-- = (∀{x y} → (f ∘₂ g₁)(x)(y) ≡ (g₂ on₂ f)(x)(y))
-- = (∀{x y} → (f(g₁ x y) ≡ g₂ (f(x)) (f(y)))
-- Preserving(3) (f)(g₁)(g₂)
-- = (∀{x y z} → (f ∘₃ g₁)(x)(y)(z) ≡ (g₂ on₃ f)(x)(y)(z))
-- = (∀{x y z} → (f(g₁ x y z) ≡ g₂ (f(x)) (f(y)) (f(z))))
-- Alternative implementation:
-- Preserving(n) (f)(g₁)(g₂) = Multi.Names.⊜₊(n) ([→̂]-to-[⇉] n (f DomainRaise.∘ g₁)) ([→̂]-to-[⇉] n (g₂ DomainRaise.on f))
Preserving : (n : ℕ) → (f : X → Y) → (X →̂ X)(n) → (Y →̂ Y)(n) → Stmt{if positive?(n) then (ℓ₁ Lvl.⊔ ℓₑ₂) else ℓₑ₂}
Preserving(𝟎) (f)(g₁)(g₂) = (f(g₁) ≡ g₂)
Preserving(𝐒(𝟎)) (f)(g₁)(g₂) = (∀{x} → f(g₁(x)) ≡ g₂(f(x)))
Preserving(𝐒(𝐒(n))) (f)(g₁)(g₂) = (∀{x} → Preserving(𝐒(n)) (f) (g₁(x)) (g₂(f(x))))
Preserving₀ = Preserving(0)
Preserving₁ = Preserving(1)
Preserving₂ = Preserving(2)
Preserving₃ = Preserving(3)
Preserving₄ = Preserving(4)
Preserving₅ = Preserving(5)
Preserving₆ = Preserving(6)
Preserving₇ = Preserving(7)
Preserving₈ = Preserving(8)
Preserving₉ = Preserving(9)
module _ where
RelationReplacement : ∀{B : Type{ℓ}} → (B → B → Type{ℓₑ}) → (n : ℕ) → ∀{ℓ𝓈 ℓ𝓈ₑ}{As : Types{n}(ℓ𝓈)} → (RaiseType.mapWithLvls(\A ℓₑ → Equiv{ℓₑ}(A)) As ℓ𝓈ₑ) ⇉ᵢₙₛₜ ((As ⇉ B) → (As ⇉ B) → Stmt{Lvl.⨆(ℓ𝓈) Lvl.⊔ ℓₑ Lvl.⊔ Lvl.⨆(ℓ𝓈ₑ)})
RelationReplacement(_▫_) 0 f g = f ▫ g
RelationReplacement(_▫_) 1 f g = ∀{x y} → (x ≡ y) → (f(x) ▫ g(y))
RelationReplacement(_▫_) (𝐒(𝐒(n))) = Multi.expl-to-inst(𝐒(n)) (Multi.compose(𝐒(n)) (\R f g → ∀{x y} → (x ≡ y) → R (f(x)) (g(y))) (Multi.inst-to-expl(𝐒(n)) (RelationReplacement(_▫_) (𝐒(n)))))
FunctionReplacement : (n : ℕ) → ∀{ℓ𝓈 ℓ𝓈ₑ}{As : Types{n}(ℓ𝓈)}{B : Type{ℓ}} → (RaiseType.mapWithLvls(\A ℓₑ → Equiv{ℓₑ}(A)) As ℓ𝓈ₑ) ⇉ᵢₙₛₜ (⦃ equiv-B : Equiv{ℓₑ}(B) ⦄ → (As ⇉ B) → (As ⇉ B) → Stmt{Lvl.⨆(ℓ𝓈) Lvl.⊔ ℓₑ Lvl.⊔ Lvl.⨆(ℓ𝓈ₑ)})
FunctionReplacement 0 f g = f ≡ g
FunctionReplacement 1 f g = ∀{x y} → (x ≡ y) → (f(x) ≡ g(y))
FunctionReplacement (𝐒(𝐒(n))) = Multi.expl-to-inst(𝐒(n)) (Multi.compose(𝐒(n)) (\R ⦃ equiv-B ⦄ f g → ∀{x y} → (x ≡ y) → R ⦃ equiv-B ⦄ (f(x)) (g(y))) (Multi.inst-to-expl(𝐒(n)) (FunctionReplacement (𝐒(n)))))
-- Generalization of `Structure.Function.Function` for nested function types (or normally known as: functions of any number of arguments (n-ary functions)).
-- Examples:
-- Function(0) f g = f ≡ g
-- Function(1) f g = ∀{x y} → (x ≡ y) → (f(x) ≡ g(y))
-- Function(2) f g = ∀{x y} → (x ≡ y) → ∀{x₁ y₁} → (x₁ ≡ y₁) → (f(x)(x₁) ≡ g(y)(y₁))
-- Function(3) f g = ∀{x y} → (x ≡ y) → ∀{x₁ y₁} → (x₁ ≡ y₁) → ∀{x₂ y₂} → (x₂ ≡ y₂) → (f(x)(x₁)(x₂) ≡ g(y)(y₁)(y₂))
Function : (n : ℕ) → ∀{ℓ𝓈 ℓ𝓈ₑ}{As : Types{n}(ℓ𝓈)}{B : Type{ℓ}} → (RaiseType.mapWithLvls(\A ℓₑ → Equiv{ℓₑ}(A)) As ℓ𝓈ₑ) ⇉ᵢₙₛₜ (⦃ equiv-B : Equiv{ℓₑ}(B) ⦄ → (As ⇉ B) → Stmt)
Function(n) = Multi.expl-to-inst(n) (Multi.compose(n) (\R ⦃ equiv-B ⦄ → R ⦃ equiv-B ⦄ $₂_) (Multi.inst-to-expl(n) (FunctionReplacement(n))))
module _ where
CompatibleReplacement : (n : ℕ) → ∀{ℓ𝓈 ℓ𝓈ₗ}{As : Types{n}(ℓ𝓈)}{B : Type{ℓ}} → (RaiseType.mapWithLvls(\A ℓₗ → A → A → Type{ℓₗ}) As ℓ𝓈ₗ) ⇉ ((B → B → Stmt{ℓₗ}) → (As ⇉ B) → (As ⇉ B) → Stmt{ℓₗ Lvl.⊔ Lvl.⨆(ℓ𝓈) Lvl.⊔ Lvl.⨆(ℓ𝓈ₗ)})
CompatibleReplacement 0 (_▫_) f g = f ▫ g
CompatibleReplacement 1 (_▫₀_)(_▫_) f g = ∀{x y} → (x ▫₀ y) → (f(x) ▫ g(y))
CompatibleReplacement (𝐒(𝐒(n))) (_▫₀_) = Multi.compose(𝐒(n)) (R ↦ _▫_ ↦ f ↦ g ↦ ∀{x y} → (x ▫₀ y) → R(_▫_) (f(x)) (g(y))) (CompatibleReplacement(𝐒(n)))
Compatible : (n : ℕ) → ∀{ℓ𝓈 ℓ𝓈ₗ}{As : Types{n}(ℓ𝓈)}{B : Type{ℓ}} → (RaiseType.mapWithLvls(\A ℓₗ → A → A → Type{ℓₗ}) As ℓ𝓈ₗ) ⇉ ((B → B → Stmt{ℓₗ}) → (As ⇉ B) → Stmt)
Compatible(n) = Multi.compose(n) ((_$₂_) ∘_) (CompatibleReplacement(n))
module _ {T : Type{ℓ}} ⦃ _ : Equiv{ℓₑ}(T) ⦄ where
-- Definition of the relation between a function and an operation that says:
-- The function preserves the operation.
-- This is a special case of the (_preserves_)-relation that has the same operator inside and outside.
-- Special cases:
-- Additive function (Operator is a conventional _+_)
-- Multiplicative function (Operator is a conventional _*_)
-- ∀{x y} → (f(x ▫ y) ≡ f(x) ▫ f(y))
_preserves_ : (T → T) → (T → T → T) → Stmt
f preserves (_▫_) = Preserving(2) f (_▫_)(_▫_) --
module _ {X : Type{ℓ₁}} {Y : Type{ℓ₂}} ⦃ _ : Equiv{ℓₑ₂}(Y) ⦄ where
module _ (n : ℕ) (f : X → Y) (g₁ : (X →̂ X)(n)) (g₂ : (Y →̂ Y)(n)) where
record Preserving : Stmt{if positive?(n) then (ℓ₁ Lvl.⊔ ℓₑ₂) else ℓₑ₂} where -- TODO: Is it possible to prove for levels that an if-expression is less if both are less?
constructor intro
field proof : Names.Preserving(n) (f)(g₁)(g₂)
preserving = inst-fn Preserving.proof
Preserving₀ = Preserving(0)
Preserving₁ = Preserving(1)
Preserving₂ = Preserving(2)
Preserving₃ = Preserving(3)
Preserving₄ = Preserving(4)
Preserving₅ = Preserving(5)
Preserving₆ = Preserving(6)
Preserving₇ = Preserving(7)
Preserving₈ = Preserving(8)
Preserving₉ = Preserving(9)
preserving₀ = preserving(0)
preserving₁ = preserving(1)
preserving₂ = preserving(2)
preserving₃ = preserving(3)
preserving₄ = preserving(4)
preserving₅ = preserving(5)
preserving₆ = preserving(6)
preserving₇ = preserving(7)
preserving₈ = preserving(8)
preserving₉ = preserving(9)
module _ {T : Type{ℓ}} ⦃ _ : Equiv{ℓₑ}(T) ⦄ (n : ℕ) (f : T → T) (_▫_ : T → T → T) where
_preserves_ = Preserving(2) (f)(_▫_)(_▫_)
{-
module _ {T : Type{ℓ}} where
module _ (n : ℕ) {ℓₗ} (_▫_ : T → T → Stmt{ℓₗ}) (f : RaiseType.repeat n T ⇉ T) where
record Compatible : Stmt{ℓₗ Lvl.⊔ (if positive?(n) then ℓ else Lvl.𝟎)} where
constructor intro
field proof : Names.Compatible(n) (_▫_)(f)
compatible = inst-fn Compatible.proof
Compatible₀ = Compatible(0)
Compatible₁ = Compatible(1)
Compatible₂ = Compatible(2)
Compatible₃ = Compatible(3)
Compatible₄ = Compatible(4)
Compatible₅ = Compatible(5)
Compatible₆ = Compatible(6)
Compatible₇ = Compatible(7)
Compatible₈ = Compatible(8)
Compatible₉ = Compatible(9)
compatible₀ = compatible(0)
compatible₁ = compatible(1)
compatible₂ = compatible(2)
compatible₃ = compatible(3)
compatible₄ = compatible(4)
compatible₅ = compatible(5)
compatible₆ = compatible(6)
compatible₇ = compatible(7)
compatible₈ = compatible(8)
compatible₉ = compatible(9)
-}
| {
"alphanum_fraction": 0.5956466069,
"avg_line_length": 47.3333333333,
"ext": "agda",
"hexsha": "6b7d39496e32a6c633d94cece4a1140d7ddad1f5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Function/Multi.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Function/Multi.agda",
"max_line_length": 233,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Function/Multi.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": 3290,
"size": 7810
} |
------------------------------------------------------------------------
-- If the "Outrageous but Meaningful Coincidences" approach is used to
-- formalise a language, then you can end up with an extensional type
-- theory (with equality reflection)
------------------------------------------------------------------------
module README.DependentlyTyped.Extensional-type-theory where
import Axiom.Extensionality.Propositional as E
open import Data.Empty
open import Data.Product renaming (curry to c)
open import Data.Unit
open import Data.Universe.Indexed
import deBruijn.Context
open import Function hiding (_∋_) renaming (const to k)
import Level
import Relation.Binary.PropositionalEquality as P
------------------------------------------------------------------------
-- A non-indexed universe
mutual
data U : Set where
empty : U
π : (a : U) (b : El a → U) → U
El : U → Set
El empty = ⊥
El (π a b) = (x : El a) → El (b x)
Uni : IndexedUniverse _ _ _
Uni = record { I = ⊤; U = λ _ → U; El = El }
------------------------------------------------------------------------
-- Contexts and variables
-- We get these for free.
open deBruijn.Context Uni public
renaming (_·_ to _⊙_; ·-cong to ⊙-cong)
-- Some abbreviations.
⟨empty⟩ : ∀ {Γ} → Type Γ
⟨empty⟩ = -, λ _ → empty
⟨π⟩ : ∀ {Γ} (σ : Type Γ) → Type (Γ ▻ σ) → Type Γ
⟨π⟩ σ τ = -, k π ˢ indexed-type σ ˢ c (indexed-type τ)
⟨π̂⟩ : ∀ {Γ} (σ : Type Γ) →
((γ : Env Γ) → El (indexed-type σ γ) → U) → Type Γ
⟨π̂⟩ σ τ = -, k π ˢ indexed-type σ ˢ τ
------------------------------------------------------------------------
-- Well-typed terms
mutual
infixl 9 _·_
infix 3 _⊢_
-- Terms.
data _⊢_ (Γ : Ctxt) : Type Γ → Set where
var : ∀ {σ} (x : Γ ∋ σ) → Γ ⊢ σ
ƛ : ∀ {σ τ} (t : Γ ▻ σ ⊢ τ) → Γ ⊢ ⟨π⟩ σ τ
_·_ : ∀ {σ τ} (t₁ : Γ ⊢ ⟨π̂⟩ σ τ) (t₂ : Γ ⊢ σ) → Γ ⊢ (-, τ ˢ ⟦ t₂ ⟧)
-- Semantics of terms.
⟦_⟧ : ∀ {Γ σ} → Γ ⊢ σ → Value Γ σ
⟦ var x ⟧ γ = lookup x γ
⟦ ƛ t ⟧ γ = λ v → ⟦ t ⟧ (γ , v)
⟦ t₁ · t₂ ⟧ γ = (⟦ t₁ ⟧ γ) (⟦ t₂ ⟧ γ)
------------------------------------------------------------------------
-- We can define looping terms (assuming extensionality)
module Looping (ext : E.Extensionality Level.zero Level.zero) where
-- The casts are examples of the use of equality reflection: the
-- casts are meta-language constructions, not object-language
-- constructions.
cast₁ : ∀ {Γ} →
Γ ▻ ⟨empty⟩ ⊢ ⟨π⟩ ⟨empty⟩ ⟨empty⟩ → Γ ▻ ⟨empty⟩ ⊢ ⟨empty⟩
cast₁ t = P.subst (_⊢_ _) (P.cong (_,_ tt) (ext (⊥-elim ∘ proj₂))) t
cast₂ : ∀ {Γ} →
Γ ▻ ⟨empty⟩ ⊢ ⟨empty⟩ → Γ ▻ ⟨empty⟩ ⊢ ⟨π⟩ ⟨empty⟩ ⟨empty⟩
cast₂ t = P.subst (_⊢_ _) (P.cong (_,_ tt) (ext (⊥-elim ∘ proj₂))) t
ω : ε ▻ ⟨empty⟩ ⊢ ⟨empty⟩
ω = cast₁ (ƛ (cast₂ (var zero) · var zero))
-- A simple example of a term which does not have a normal form.
Ω : ε ▻ ⟨empty⟩ ⊢ ⟨empty⟩
Ω = cast₂ ω · ω
const-Ω : ε ⊢ ⟨π⟩ ⟨empty⟩ ⟨empty⟩
const-Ω = ƛ Ω
-- Some observations:
--
-- * The language with spines (in README.DependentlyTyped.Term) does
-- not support terms like the ones above; in the casts one would
-- have to prove that distinct spines are equal.
--
-- * The spines ensure that the normaliser in
-- README.DependentlyTyped.NBE terminates. The existence of terms
-- like Ω implies that it is impossible to implement a normaliser
-- for the spine-less language defined in this module.
| {
"alphanum_fraction": 0.5244080678,
"avg_line_length": 29.747826087,
"ext": "agda",
"hexsha": "ba65548a4c38d852ac657dd67de5e56cd53d82d9",
"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/Extensional-type-theory.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/Extensional-type-theory.agda",
"max_line_length": 72,
"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/Extensional-type-theory.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": 1131,
"size": 3421
} |
module Issue888 (A : Set) where
-- Check that let-bound variables show up in "show context"
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
f : Set -> Set
f X = let Y : ℕ -> Set
Y n = ℕ
m : ℕ
m = {!!}
in {!!}
-- Issue 1112: dependent let-bindings
data Singleton : ℕ → Set where
mkSingleton : (n : ℕ) -> Singleton n
g : ℕ -> ℕ
g x =
let i = zero
z = mkSingleton x
in {!!}
| {
"alphanum_fraction": 0.5165876777,
"avg_line_length": 16.88,
"ext": "agda",
"hexsha": "5d205ba75e5c553c6757816a239f4016c4cc4000",
"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/interaction/Issue888.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/interaction/Issue888.agda",
"max_line_length": 59,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "masondesu/agda",
"max_stars_repo_path": "test/interaction/Issue888.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 136,
"size": 422
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An explanation about the `Axiom` modules.
------------------------------------------------------------------------
module README.Axiom where
open import Level using (Level)
private variable ℓ : Level
------------------------------------------------------------------------
-- Introduction
-- Several rules that are used without thought in written mathematics
-- cannot be proved in Agda. The modules in the `Axiom` folder
-- provide types expressing some of these rules that users may want to
-- use even when they're not provable in Agda.
------------------------------------------------------------------------
-- Example: law of excluded middle
-- In classical logic the law of excluded middle states that for any
-- proposition `P` either `P` or `¬P` must hold. This is impossible
-- to prove in Agda because Agda is a constructive system and so any
-- proof of the excluded middle would have to build a term of either
-- type `P` or `¬P`. This is clearly impossible without any knowledge
-- of what proposition `P` is.
-- The types for which `P` or `¬P` holds is called `Dec P` in the
-- standard library (short for `Decidable`).
open import Relation.Nullary using (Dec)
-- The type of the proof of saying that excluded middle holds for
-- all types at universe level ℓ is therefore:
--
-- ExcludedMiddle ℓ = ∀ {P : Set ℓ} → Dec P
--
-- and this type is exactly the one found in `Axiom.ExcludedMiddle`:
open import Axiom.ExcludedMiddle
-- There are two different ways that the axiom can be introduced into
-- your Agda development. The first option is to postulate it:
postulate excludedMiddle : ExcludedMiddle ℓ
-- This has the advantage that it only needs to be postulated once
-- and it can then be imported into many different modules as with any
-- other proof. The downside is that the resulting Agda code will no
-- longer type check under the --safe flag.
-- The second approach is to pass it as a module parameter:
module Proof (excludedMiddle : ExcludedMiddle ℓ) where
-- The advantage of this approach is that the resulting Agda
-- development can still be type checked under the --safe flag.
-- Intuitively the reason for this is that when postulating it
-- you are telling Agda that excluded middle does hold (which is clearly
-- untrue as discussed above). In contrast when passing it as a module
-- parameter you are telling Agda that **if** excluded middle was true
-- then the following proofs would hold, which is logically valid.
-- The disadvantage of this approach is that it is now necessary to
-- include the excluded middle assumption as a parameter in every module
-- that you want to use it in. Additionally the modules can never
-- be fully instantiated (without postulating excluded middle).
------------------------------------------------------------------------
-- Other axioms
-- Double negation elimination
-- (∀ P → ¬ ¬ P → P)
import Axiom.DoubleNegationElimination
-- Function extensionality
-- (∀ f g → (∀ x → f x ≡ g x) → f ≡ g)
import Axiom.Extensionality.Propositional
import Axiom.Extensionality.Heterogeneous
-- Uniqueness of identity proofs (UIP)
-- (∀ x y (p q : x ≡ y) → p ≡ q)
import Axiom.UniquenessOfIdentityProofs
| {
"alphanum_fraction": 0.65951013,
"avg_line_length": 36.7444444444,
"ext": "agda",
"hexsha": "d22dfc0ca9003ff718aa6d86260b983a5cd5f7b6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/README/Axiom.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/README/Axiom.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/README/Axiom.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": 736,
"size": 3307
} |
module Human.String where
open import Human.Bool
open import Human.List renaming ( length to llength )
open import Human.Char
open import Human.Nat
postulate String : Set
{-# BUILTIN STRING String #-}
primitive
primStringToList : String → List Char
primStringFromList : List Char → String
primStringAppend : String → String → String
primStringEquality : String → String → Bool
primShowChar : Char → String
primShowString : String → String
{-# COMPILE JS primStringToList = function(x) { return x.split(""); } #-}
{-# COMPILE JS primStringFromList = function(x) { return x.join(""); } #-}
{-# COMPILE JS primStringAppend = function(x) { return function(y) { return x+y; }; } #-}
{-# COMPILE JS primStringEquality = function(x) { return function(y) { return x===y; }; } #-}
{-# COMPILE JS primShowChar = function(x) { return JSON.stringify(x); } #-}
{-# COMPILE JS primShowString = function(x) { return JSON.stringify(x); } #-}
toList : String → List Char
toList = primStringToList
{-# COMPILE JS primStringToList = function(x) { return x.split(""); } #-}
slength : String → Nat
slength s = llength (toList s)
{-# COMPILE JS slength = function(s) { return s.length; } #-}
| {
"alphanum_fraction": 0.6802325581,
"avg_line_length": 34.4,
"ext": "agda",
"hexsha": "3cabbdf56f5bcdbcbb58182d0cfcbf949089bcbc",
"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": "b509eb4c4014605facfb4ee5c807cd07753d4477",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MaisaMilena/JuiceMaker",
"max_forks_repo_path": "src/Human/String.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b509eb4c4014605facfb4ee5c807cd07753d4477",
"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": "MaisaMilena/JuiceMaker",
"max_issues_repo_path": "src/Human/String.agda",
"max_line_length": 93,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b509eb4c4014605facfb4ee5c807cd07753d4477",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MaisaMilena/JuiceMaker",
"max_stars_repo_path": "src/Human/String.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-28T05:46:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-29T17:35:20.000Z",
"num_tokens": 300,
"size": 1204
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Structures.Group where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.FunExtEquiv
open import Cubical.Data.Prod.Base hiding (_×_) renaming (_×Σ_ to _×_)
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
open import Cubical.Structures.Monoid
private
variable
ℓ ℓ' : Level
group-axiom : (X : Type ℓ) → monoid-structure X → Type ℓ
group-axiom G ((e , _·_) , _) = ((x : G) → Σ G (λ x' → (x · x' ≡ e) × (x' · x ≡ e)))
group-structure : Type ℓ → Type ℓ
group-structure = add-to-structure (monoid-structure) group-axiom
Groups : Type (ℓ-suc ℓ)
Groups {ℓ} = TypeWithStr ℓ group-structure
-- Extracting components of a group
⟨_⟩ : Groups {ℓ} → Type ℓ
⟨ (G , _) ⟩ = G
id : (G : Groups {ℓ}) → ⟨ G ⟩
id (_ , ((e , _) , _) , _) = e
group-operation : (G : Groups {ℓ}) → ⟨ G ⟩ → ⟨ G ⟩ → ⟨ G ⟩
group-operation (_ , ((_ , f) , _) , _) = f
infixl 20 group-operation
syntax group-operation G x y = x ·⟨ G ⟩ y
group-is-set : (G : Groups {ℓ}) → isSet ⟨ G ⟩
group-is-set (_ , (_ , (P , _)) , _) = P
group-assoc : (G : Groups {ℓ})
→ (x y z : ⟨ G ⟩) → (x ·⟨ G ⟩ (y ·⟨ G ⟩ z)) ≡ ((x ·⟨ G ⟩ y) ·⟨ G ⟩ z)
group-assoc (_ , (_ , (_ , P , _)) , _) = P
group-runit : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → x ·⟨ G ⟩ (id G) ≡ x
group-runit (_ , (_ , (_ , _ , P , _)) , _) = P
group-lunit : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → (id G) ·⟨ G ⟩ x ≡ x
group-lunit (_ , (_ , (_ , _ , _ , P)) , _) = P
group-Σinv : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → Σ (⟨ G ⟩) (λ x' → (x ·⟨ G ⟩ x' ≡ (id G)) × (x' ·⟨ G ⟩ x ≡ (id G)))
group-Σinv (_ , _ , P) = P
-- Defining the inverse function
inv : (G : Groups {ℓ}) → ⟨ G ⟩ → ⟨ G ⟩
inv (_ , _ , P) x = fst (P x)
group-rinv : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → x ·⟨ G ⟩ (inv G x) ≡ id G
group-rinv (_ , _ , P) x = fst (snd (P x))
group-linv : (G : Groups {ℓ})
→ (x : ⟨ G ⟩) → (inv G x) ·⟨ G ⟩ x ≡ id G
group-linv (_ , _ , P) x = snd (snd (P x))
-- Iso for groups are those for monoids
group-iso : StrIso group-structure ℓ
group-iso = add-to-iso monoid-structure monoid-iso group-axiom
-- Auxiliary lemmas for subtypes (taken from Escardo)
to-Σ-≡ : {X : Type ℓ} {A : X → Type ℓ'} {σ τ : Σ X A}
→ (Σ (fst σ ≡ fst τ) λ p → PathP (λ i → A (p i)) (snd σ) (snd τ))
→ σ ≡ τ
to-Σ-≡ (eq , p) = λ i → eq i , p i
to-subtype-≡ : {X : Type ℓ} {A : X → Type ℓ'} {x y : X}
{a : A x} {b : A y}
→ ((x : X) → isProp (A x))
→ x ≡ y
→ Path (Σ X (λ x → A x)) (x , a) (y , b)
to-subtype-≡ {x = x} {y} {a} {b} f eq = to-Σ-≡ (eq , toPathP (f y _ b))
-- TODO: this proof without toPathP?
-- Group axiom isProp
group-axiom-isProp : (X : Type ℓ)
→ (s : monoid-structure X)
→ isProp (group-axiom X s)
group-axiom-isProp X (((e , _·_) , s@(isSet , assoc , rid , lid))) = isPropPi γ
where
γ : (x : X) → isProp (Σ X (λ x' → (x · x' ≡ e) × (x' · x ≡ e)))
γ x (y , a , q) (z , p , b) = to-subtype-≡ u t
where
t : y ≡ z
t = inv-lemma X e _·_ s x y z q p
u : (x' : X) → isProp ((x · x' ≡ e) × (x' · x ≡ e))
u x' = isPropΣ (isSet _ _)
(λ _ → isSet _ _)
-- Group paths equivalent to equality
group-is-SNS : SNS {ℓ} group-structure group-iso
group-is-SNS = add-axioms-SNS monoid-structure monoid-iso
group-axiom group-axiom-isProp monoid-is-SNS
GroupPath : (M N : Groups {ℓ}) → (M ≃[ group-iso ] N) ≃ (M ≡ N)
GroupPath M N = SIP group-structure group-iso group-is-SNS M N
-- Trying to improve isomorphisms to only have to preserve
-- _·_
group-iso' : StrIso group-structure ℓ
group-iso' G S f =
(x y : ⟨ G ⟩) → equivFun f (x ·⟨ G ⟩ y) ≡ equivFun f x ·⟨ S ⟩ equivFun f y
-- Trying to reduce isomorphisms to simpler ones
-- First we prove that both notions of group-iso are equal
-- since both are props and there is are functions from
-- one to the other
-- Functions
group-iso→group-iso' : (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩)
→ group-iso G S f → group-iso' G S f
group-iso→group-iso' G S f γ = snd γ
group-iso'→group-iso : (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩)
→ group-iso' G S f → group-iso G S f
group-iso'→group-iso G S f γ = η , γ
where
g : ⟨ G ⟩ → ⟨ S ⟩
g = equivFun f
e : ⟨ G ⟩
e = id G
d : ⟨ S ⟩
d = id S
δ : g e ≡ g e ·⟨ S ⟩ g e
δ = g e ≡⟨ cong g (sym (group-lunit G _)) ⟩
g (e ·⟨ G ⟩ e) ≡⟨ γ e e ⟩
g e ·⟨ S ⟩ g e ∎
η : g e ≡ d
η = g e ≡⟨ sym (group-runit S _) ⟩
g e ·⟨ S ⟩ d ≡⟨ cong (λ - → g e ·⟨ S ⟩ -) (sym (group-rinv S _)) ⟩
g e ·⟨ S ⟩ (g e ·⟨ S ⟩ (inv S (g e))) ≡⟨ group-assoc S _ _ _ ⟩
(g e ·⟨ S ⟩ g e) ·⟨ S ⟩ (inv S (g e)) ≡⟨ cong (λ - → group-operation S - (inv S (g e))) (sym δ) ⟩
g e ·⟨ S ⟩ (inv S (g e)) ≡⟨ group-rinv S _ ⟩
d ∎
-- Both are Props
isProp-Iso : (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩) → isProp (group-iso G S f)
isProp-Iso G S f = isPropΣ (group-is-set S _ _)
(λ _ → isPropPi (λ x → isPropPi λ y → group-is-set S _ _))
isProp-Iso' : (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩) → isProp (group-iso' G S f)
isProp-Iso' G S f = isPropPi (λ x → isPropPi λ y → group-is-set S _ _)
-- Propositional equality
to-Prop-≡ : {X Y : Type ℓ} (f : X → Y) (g : Y → X)
→ isProp X → isProp Y
→ X ≡ Y
to-Prop-≡ {ℓ} {X} {Y} f g p q = isoToPath (iso f g aux₂ aux₁)
where
aux₁ : (x : X) → g (f x) ≡ x
aux₁ x = p _ _
aux₂ : (y : Y) → f (g y) ≡ y
aux₂ y = q _ _
-- Finally both are equal
group-iso'≡group-iso : group-iso' {ℓ} ≡ group-iso
group-iso'≡group-iso = funExt₃ γ
where
γ : ∀ (G S : Groups {ℓ}) (f : ⟨ G ⟩ ≃ ⟨ S ⟩)
→ group-iso' G S f ≡ group-iso G S f
γ G S f = to-Prop-≡ (group-iso'→group-iso G S f)
(group-iso→group-iso' G S f)
(isProp-Iso' G S f)
(isProp-Iso G S f)
-- And Finally we have what we wanted
group-is-SNS' : SNS {ℓ} group-structure group-iso'
group-is-SNS' = transport γ group-is-SNS
where
γ : SNS {ℓ} group-structure group-iso ≡ SNS {ℓ} group-structure group-iso'
γ = cong (SNS group-structure) (sym group-iso'≡group-iso)
GroupPath' : (M N : Groups {ℓ}) → (M ≃[ group-iso' ] N) ≃ (M ≡ N)
GroupPath' M N = SIP group-structure group-iso' group-is-SNS' M N
---------------------------------------------------------------------
-- Abelians group (just add one axiom and prove that it is a hProp)
---------------------------------------------------------------------
abelian-group-axiom : (X : Type ℓ) → group-structure X → Type ℓ
abelian-group-axiom G (((_ , _·_), _), _) = (x y : G) → x · y ≡ y · x
abelian-group-structure : Type ℓ → Type ℓ
abelian-group-structure = add-to-structure (group-structure) abelian-group-axiom
AbGroups : Type (ℓ-suc ℓ)
AbGroups {ℓ} = TypeWithStr ℓ abelian-group-structure
abelian-group-iso : StrIso abelian-group-structure ℓ
abelian-group-iso = add-to-iso group-structure group-iso abelian-group-axiom
abelian-group-axiom-isProp : (X : Type ℓ)
→ (s : group-structure X)
→ isProp (abelian-group-axiom X s)
abelian-group-axiom-isProp X ((_ , (group-isSet , _)) , _) =
isPropPi (λ x → isPropPi λ y → group-isSet _ _)
abelian-group-is-SNS : SNS {ℓ} abelian-group-structure abelian-group-iso
abelian-group-is-SNS = add-axioms-SNS group-structure group-iso
abelian-group-axiom abelian-group-axiom-isProp group-is-SNS
AbGroupPath : (M N : AbGroups {ℓ}) → (M ≃[ abelian-group-iso ] N) ≃ (M ≡ N)
AbGroupPath M N = SIP abelian-group-structure abelian-group-iso abelian-group-is-SNS M N
| {
"alphanum_fraction": 0.5196363177,
"avg_line_length": 33.1338912134,
"ext": "agda",
"hexsha": "038e8f8610511ff21833c44e873ebe595b4c7979",
"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": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "borsiemir/cubical",
"max_forks_repo_path": "Cubical/Structures/Group.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"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": "borsiemir/cubical",
"max_issues_repo_path": "Cubical/Structures/Group.agda",
"max_line_length": 103,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "borsiemir/cubical",
"max_stars_repo_path": "Cubical/Structures/Group.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3093,
"size": 7919
} |
data D : Set where
@0 c : D
-- The following definition should be rejected. Matching on an erased
-- constructor in an *erased* position should not on its own make it
-- possible to use erased definitions in the right-hand side.
f : @0 D → D
f c = c
x : D
x = f c
| {
"alphanum_fraction": 0.6840148699,
"avg_line_length": 20.6923076923,
"ext": "agda",
"hexsha": "32120e03ed0e8e14d0c41575b136e34b5e2955e0",
"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/Issue4638-3.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue4638-3.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4638-3.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 77,
"size": 269
} |
{- 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.Abstract.Types
open import LibraBFT.Abstract.Types.EpochConfig
open WithAbsVote
-- This module contains properties about RecordChains, culminating in
-- theorem S5, which is the main per-epoch correctness condition. The
-- properties are based on the original version of the LibraBFT paper,
-- which was current when they were developed:
-- https://developers.diem.com/docs/assets/papers/diem-consensus-state-machine-replication-in-the-diem-blockchain/2019-06-28.pdf
-- Even though the implementation has changed since that version of the
-- paper, we do not need to redo these proofs because that affects only
-- the concrete implementation. This demonstrates one advantage of
-- separating these proofs into abstract and concrete pieces.
module LibraBFT.Abstract.RecordChain.Properties
(UID : Set)
(_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁))
(NodeId : Set)
(𝓔 : EpochConfig UID NodeId)
(𝓥 : VoteEvidence UID NodeId 𝓔)
where
open import LibraBFT.Abstract.Types UID NodeId 𝓔
open import LibraBFT.Abstract.System UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.Records UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.Records.Extends UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.RecordChain UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Abstract.RecordChain.Assumptions UID _≟UID_ NodeId 𝓔 𝓥
open EpochConfig 𝓔
module WithInvariants {ℓ}
(InSys : Record → Set ℓ)
(votes-only-once : VotesOnlyOnceRule InSys)
(preferred-round-rule : PreferredRoundRule InSys)
where
open All-InSys-props InSys
----------------------
-- Lemma 2
-- Lemma 2 states that there can be at most one certified block per
-- round. If two blocks have a quorum certificate for the same round,
-- then they are equal or their unique identifier is not
-- injective. This is required because, on the concrete side, this bId
-- will be a hash function which might yield collisions.
lemmaS2 : {b₀ b₁ : Block}{q₀ q₁ : QC}
→ InSys (Q q₀) → InSys (Q q₁)
→ (p₀ : B b₀ ← Q q₀)
→ (p₁ : B b₁ ← Q q₁)
→ getRound b₀ ≡ getRound b₁
→ NonInjective-≡ bId ⊎ b₀ ≡ b₁
lemmaS2 {b₀} {b₁} {q₀} {q₁} ex₀ ex₁ (B←Q refl h₀) (B←Q refl h₁) refl
with b₀ ≟Block b₁
...| yes done = inj₂ done
...| no imp
with bft-assumption (qVotes-C1 q₀) (qVotes-C1 q₁)
...| (a , (a∈q₀mem , a∈q₁mem , honest))
with Any-sym (Any-map⁻ a∈q₀mem) | Any-sym (Any-map⁻ a∈q₁mem)
...| a∈q₀ | a∈q₁
with All-lookup (qVotes-C3 q₀) (∈QC-Vote-correct q₀ a∈q₀) |
All-lookup (qVotes-C3 q₁) (∈QC-Vote-correct q₁ a∈q₁)
...| a∈q₀rnd≡ | a∈q₁rnd≡
with <-cmp (abs-vRound (∈QC-Vote q₀ a∈q₀)) (abs-vRound (∈QC-Vote q₁ a∈q₁))
...| tri< va<va' _ _ = ⊥-elim (<⇒≢ (subst₂ _<_ a∈q₀rnd≡ a∈q₁rnd≡ va<va') refl)
...| tri> _ _ va'<va = ⊥-elim (<⇒≢ (subst₂ _≤_ (cong suc a∈q₁rnd≡) a∈q₀rnd≡ va'<va) refl)
...| tri≈ _ v₀≡v₁ _ =
let v₀∈q₀ = ∈QC-Vote-correct q₀ a∈q₀
v₁∈q₁ = ∈QC-Vote-correct q₁ a∈q₁
ppp = trans h₀ (trans (vote≡⇒QPrevId≡ {q₀} {q₁} v₀∈q₀ v₁∈q₁ (votes-only-once a honest ex₀ ex₁ a∈q₀ a∈q₁ v₀≡v₁))
(sym h₁))
in inj₁ ((b₀ , b₁) , (imp , ppp))
----------------
-- Lemma S3
lemmaS3 : ∀{r₂ q'}
{rc : RecordChain r₂} → InSys r₂
→ (rc' : RecordChain (Q q')) → InSys (Q q') -- Immediately before a (Q q), we have the certified block (B b), which is the 'B' in S3
→ (c3 : 𝕂-chain Contig 3 rc) -- This is B₀ ← C₀ ← B₁ ← C₁ ← B₂ ← C₂ in S3
→ round r₂ < getRound q'
→ NonInjective-≡ bId ⊎ (getRound (kchainBlock (suc (suc zero)) c3) ≤ prevRound rc')
lemmaS3 {r₂} {q'} ex₀ (step rc' b←q') ex₁ (s-chain {rc = rc} {b = b₂} {q₂} r←b₂ _ b₂←q₂ c2) hyp
with bft-assumption (qVotes-C1 q₂) (qVotes-C1 q')
...| (a , (a∈q₂mem , a∈q'mem , honest))
with Any-sym (Any-map⁻ a∈q₂mem) | Any-sym (Any-map⁻ a∈q'mem)
...| a∈q₂ | a∈q'
-- TODO-1: We have done similar reasoning on the order of votes for
-- lemmaS2. We should factor out a predicate that analyzes the rounds
-- of QC's and returns us a judgement about the order of the votes.
with All-lookup (qVotes-C3 q') (∈QC-Vote-correct q' a∈q') |
All-lookup (qVotes-C3 q₂) (∈QC-Vote-correct q₂ a∈q₂)
...| a∈q'rnd≡ | a∈q₂rnd≡
with <-cmp (round r₂) (abs-vRound (∈QC-Vote q' a∈q'))
...| tri> _ _ va'<va₂
with subst₂ _<_ a∈q'rnd≡ a∈q₂rnd≡ (≤-trans va'<va₂ (≤-reflexive (sym a∈q₂rnd≡)))
...| res = ⊥-elim (n≮n (getRound q') (≤-trans res (≤-unstep hyp)))
lemmaS3 {q' = q'} ex₀ (step rc' b←q') ex₁ (s-chain {rc = rc} {b = b₂} {q₂} r←b₂ P b₂←q₂ c2) hyp
| (a , (a∈q₂mem , a∈q'mem , honest))
| a∈q₂ | a∈q'
| a∈q'rnd≡ | a∈q₂rnd≡
| tri≈ _ v₂≡v' _ =
let v₂∈q₂ = ∈QC-Vote-correct q₂ a∈q₂
v'∈q' = ∈QC-Vote-correct q' a∈q'
in ⊥-elim (<⇒≢ hyp (vote≡⇒QRound≡ {q₂} {q'} v₂∈q₂ v'∈q'
(votes-only-once a honest {q₂} {q'} ex₀ ex₁ a∈q₂ a∈q'
(trans a∈q₂rnd≡ v₂≡v'))))
lemmaS3 {r} {q'} ex₀ (step rc' b←q') ex₁ (s-chain {rc = rc} {b = b₂} {q₂} r←b₂ P b₂←q₂ c2) hyp
| (a , (a∈q₂mem , a∈q'mem , honest))
| a∈q₂ | a∈q'
| a∈q'rnd≡ | a∈q₂rnd≡
| tri< va₂<va' _ _
with b←q'
...| B←Q rrr xxx
= preferred-round-rule a honest {q₂} {q'} ex₀ ex₁ (s-chain r←b₂ P b₂←q₂ c2) a∈q₂
(step rc' (B←Q rrr xxx)) a∈q'
(≤-trans (≤-reflexive (cong suc a∈q₂rnd≡))
va₂<va')
------------------
-- Proposition S4
-- The base case for lemma S4 resorts to a pretty simple
-- arithmetic statement.
propS4-base-arith
: ∀ n r
→ n ≤ r → r ≤ (suc (suc n))
→ r ∈ (suc (suc n) ∷ suc n ∷ n ∷ [])
propS4-base-arith .0 .0 z≤n z≤n = there (there (here refl))
propS4-base-arith .0 .1 z≤n (s≤s z≤n) = there (here refl)
propS4-base-arith .0 .2 z≤n (s≤s (s≤s z≤n)) = here refl
propS4-base-arith (suc r) (suc n) (s≤s h0) (s≤s h1)
= ∈-cong suc (propS4-base-arith r n h0 h1)
-- Which is then translated to LibraBFT lingo
propS4-base-lemma-1
: ∀{q}{rc : RecordChain (Q q)}
→ (c3 : 𝕂-chain Contig 3 rc) -- This is B₀ ← C₀ ← B₁ ← C₁ ← B₂ ← C₂ in S4
→ (r : ℕ)
→ getRound (c3 b⟦ suc (suc zero) ⟧) ≤ r
→ r ≤ getRound (c3 b⟦ zero ⟧)
→ r ∈ ( getRound (c3 b⟦ zero ⟧)
∷ getRound (c3 b⟦ (suc zero) ⟧)
∷ getRound (c3 b⟦ (suc (suc zero)) ⟧)
∷ [])
propS4-base-lemma-1 (s-chain {b = b0} _ p0 (B←Q refl b←q0)
(s-chain {b = b1} r←b1 p1 (B←Q refl b←q1)
(s-chain {r = R} {b = b2} r←b2 p2 (B←Q refl b←q2)
0-chain))) r hyp0 hyp1
rewrite p0 | p1 = propS4-base-arith (bRound b2) r hyp0 hyp1
propS4-base-lemma-2
: ∀{k r}
{rc : RecordChain r} → All-InSys rc
→ (q' : QC) → InSys (Q q')
→ {b' : Block}
→ (rc' : RecordChain (B b')) → (ext : (B b') ← (Q q'))
→ (c : 𝕂-chain Contig k rc)
→ (ix : Fin k)
→ getRound (kchainBlock ix c) ≡ getRound b'
→ NonInjective-≡ bId ⊎ (kchainBlock ix c ≡ b')
propS4-base-lemma-2 {rc = rc} prev∈sys q' q'∈sys rc' ext (s-chain r←b prf b←q c) zero hyp
= lemmaS2 (All-InSys⇒last-InSys prev∈sys) q'∈sys b←q ext hyp
propS4-base-lemma-2 prev∈sys q' q'∈sys rc' ext (s-chain r←b prf b←q c) (suc ix)
= propS4-base-lemma-2 (All-InSys-unstep (All-InSys-unstep prev∈sys)) q' q'∈sys rc' ext c ix
propS4-base : ∀{q q'}
→ {rc : RecordChain (Q q)} → All-InSys rc
→ (rc' : RecordChain (Q q')) → InSys (Q q')
→ (c3 : 𝕂-chain Contig 3 rc) -- This is B₀ ← C₀ ← B₁ ← C₁ ← B₂ ← C₂ in S4
→ getRound (c3 b⟦ suc (suc zero) ⟧) ≤ getRound q'
→ getRound q' ≤ getRound (c3 b⟦ zero ⟧)
→ NonInjective-≡ bId ⊎ B (c3 b⟦ suc (suc zero) ⟧) ∈RC rc'
propS4-base {q' = q'} prev∈sys (step {B b} rc'@(step rc'' q←b) b←q@(B←Q refl _)) q'∈sys c3 hyp0 hyp1
with propS4-base-lemma-1 c3 (getRound b) hyp0 hyp1
...| here r
with propS4-base-lemma-2 prev∈sys q' q'∈sys rc' b←q c3 zero (sym r)
...| inj₁ hb = inj₁ hb
...| inj₂ res
with 𝕂-chain-∈RC c3 zero (suc (suc zero)) z≤n res rc'
...| inj₁ hb = inj₁ hb
...| inj₂ res' = inj₂ (there b←q res')
propS4-base {q} {q'} prev∈sys (step rc' (B←Q refl x₀)) q'∈sys c3 hyp0 hyp1
| there (here r)
with propS4-base-lemma-2 prev∈sys q' q'∈sys rc' (B←Q refl x₀) c3 (suc zero) (sym r)
...| inj₁ hb = inj₁ hb
...| inj₂ res
with 𝕂-chain-∈RC c3 (suc zero) (suc (suc zero)) (s≤s z≤n) res rc'
...| inj₁ hb = inj₁ hb
...| inj₂ res' = inj₂ (there (B←Q refl x₀) res')
propS4-base {q' = q'} prev∈sys (step rc' (B←Q refl x₀)) q'∈sys c3 hyp0 hyp1
| there (there (here r))
with propS4-base-lemma-2 prev∈sys q' q'∈sys rc' (B←Q refl x₀) c3 (suc (suc zero)) (sym r)
...| inj₁ hb = inj₁ hb
...| inj₂ res
with 𝕂-chain-∈RC c3 (suc (suc zero)) (suc (suc zero)) (s≤s (s≤s z≤n)) res rc'
...| inj₁ hb = inj₁ hb
...| inj₂ res' = inj₂ (there (B←Q refl x₀) res')
propS4 : ∀{q q'}
→ {rc : RecordChain (Q q)} → All-InSys rc
→ (rc' : RecordChain (Q q')) → All-InSys rc'
→ (c3 : 𝕂-chain Contig 3 rc) -- This is B₀ ← C₀ ← B₁ ← C₁ ← B₂ ← C₂ in S4
→ getRound (c3 b⟦ suc (suc zero) ⟧) ≤ getRound q'
-- In the paper, the proposition states that B₀ ←⋆ B, yet, B is the block preceding
-- C, which in our case is 'prevBlock rc''. Hence, to say that B₀ ←⋆ B is
-- to say that B₀ is a block in the RecordChain that goes all the way to C.
→ NonInjective-≡ bId ⊎ B (c3 b⟦ suc (suc zero) ⟧) ∈RC rc'
propS4 {q' = q'} {rc} prev∈sys (step rc' b←q') prev∈sys' c3 hyp
with getRound q' ≤?ℕ getRound (c3 b⟦ zero ⟧)
...| yes rq≤rb₂ = propS4-base {q' = q'} prev∈sys (step rc' b←q') (All-InSys⇒last-InSys prev∈sys') c3 hyp rq≤rb₂
propS4 {q' = q'} prev∈sys (step rc' b←q') all∈sys c3 hyp
| no rb₂<rq
with lemmaS3 (All-InSys⇒last-InSys prev∈sys) (step rc' b←q')
(All-InSys⇒last-InSys all∈sys) c3
(subst (_< getRound q') (kchainBlockRoundZero-lemma c3) (≰⇒> rb₂<rq))
...| inj₁ hb = inj₁ hb
...| inj₂ ls3
with rc' | b←q'
...| step rc'' q←b | (B←Q {b} rx x)
with rc'' | q←b
...| empty | (I←B _ _)
= contradiction (n≤0⇒n≡0 ls3)
(¬bRound≡0 (kchain-to-RecordChain-at-b⟦⟧ c3 (suc (suc zero))))
...| step {r = r} rc''' (B←Q {q = q''} refl bid≡) | (Q←B ry y)
with propS4 {q' = q''} prev∈sys (step rc''' (B←Q refl bid≡)) (All-InSys-unstep (All-InSys-unstep all∈sys)) c3 ls3
...| inj₁ hb' = inj₁ hb'
...| inj₂ final = inj₂ (there (B←Q rx x) (there (Q←B ry y) final))
-------------------
-- Theorem S5
thmS5 : ∀{q q'}
→ {rc : RecordChain (Q q )} → All-InSys rc
→ {rc' : RecordChain (Q q')} → All-InSys rc'
→ {b b' : Block}
→ CommitRule rc b
→ CommitRule rc' b'
→ NonInjective-≡ bId ⊎ ((B b) ∈RC rc' ⊎ (B b') ∈RC rc) -- Not conflicting means one extends the other.
thmS5 {rc = rc} prev∈sys {rc'} prev∈sys' (commit-rule c3 refl) (commit-rule c3' refl)
with <-cmp (getRound (c3 b⟦ suc (suc zero) ⟧)) (getRound (c3' b⟦ suc (suc zero) ⟧))
...| tri≈ _ r≡r' _ = inj₁ <⊎$> (propS4 prev∈sys rc' prev∈sys' c3 (≤-trans (≡⇒≤ r≡r') (kchain-round-≤-lemma' c3' (suc (suc zero)))))
...| tri< r<r' _ _ = inj₁ <⊎$> (propS4 prev∈sys rc' prev∈sys' c3 (≤-trans (≤-unstep r<r') (kchain-round-≤-lemma' c3' (suc (suc zero)))))
...| tri> _ _ r'<r = inj₂ <⊎$> (propS4 prev∈sys' rc prev∈sys c3' (≤-trans (≤-unstep r'<r) (kchain-round-≤-lemma' c3 (suc (suc zero)))))
| {
"alphanum_fraction": 0.5478162039,
"avg_line_length": 49.272,
"ext": "agda",
"hexsha": "295f82d6b64c8b8473f8c21ffe921b10f095baeb",
"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/Abstract/RecordChain/Properties.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/Abstract/RecordChain/Properties.agda",
"max_line_length": 144,
"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/Abstract/RecordChain/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4996,
"size": 12318
} |
{-# OPTIONS --cubical #-}
open import Cubical.Foundations.Prelude
open import Cubical.Relation.Nullary
open import Cubical.Data.Empty
open import Cubical.Data.Nat
open import Cubical.Data.Unit
open import Cubical.Data.Prod
open import Cubical.Data.Bool
module Direction where
-- some nat things. move to own module?
sucn : (n : ℕ) → (ℕ → ℕ)
sucn n = iter n suc
sucnsuc : (n m : ℕ) → sucn n (suc m) ≡ suc (sucn n m)
sucnsuc zero m = refl
sucnsuc (suc n) m =
sucn (suc n) (suc m)
≡⟨ refl ⟩
suc (sucn n (suc m))
≡⟨ cong suc (sucnsuc n m) ⟩
suc (suc (sucn n m))
∎
doublePred : (n : ℕ) → doubleℕ (predℕ n) ≡ predℕ (predℕ (doubleℕ n))
doublePred zero = refl
doublePred (suc n) = refl
-- doubleDoublesPred : (n : ℕ) → doublesℕ n 1 ≡
-- doubleDoublesPred zero = refl
-- doubleDoublesPred (suc n) = {!!}
sucPred : (n : ℕ) → ¬ (n ≡ zero) → suc (predℕ n) ≡ n
sucPred zero 0≠0 = ⊥-elim (0≠0 refl)
sucPred (suc n) sucn≠0 = refl
predSucSuc : (n : ℕ) → ¬ (predℕ (suc (suc n)) ≡ 0)
predSucSuc n = snotz
doubleDoubles : (n m : ℕ) → doubleℕ (doublesℕ n m) ≡ doublesℕ (suc n) m
doubleDoubles zero m = refl
doubleDoubles (suc n) m = doubleDoubles n (doubleℕ m)
doublePos : (n : ℕ) → ¬ (n ≡ 0) → ¬ (doubleℕ n ≡ 0)
doublePos zero 0≠0 = ⊥-elim (0≠0 refl)
doublePos (suc n) sn≠0 = snotz
doublesPos : (n m : ℕ) → ¬ (m ≡ 0) → ¬ (doublesℕ n m ≡ 0)
doublesPos zero m m≠0 = m≠0
doublesPos (suc n) m m≠0 = doublesPos n (doubleℕ m) (doublePos m (m≠0))
predDoublePos : (n : ℕ) → ¬ (n ≡ 0) → ¬ (predℕ (doubleℕ n)) ≡ 0
predDoublePos zero n≠0 = ⊥-elim (n≠0 refl)
predDoublePos (suc n) sn≠0 = snotz
doubleDoublesOne≠0 : (n : ℕ) → ¬ (doubleℕ (doublesℕ n (suc zero)) ≡ 0)
doubleDoublesOne≠0 zero = snotz
doubleDoublesOne≠0 (suc n) = doublePos (doublesℕ n 2) (doublesPos n 2 (snotz))
predDoubleDoublesOne≠0 : (n : ℕ) → ¬ (predℕ (doubleℕ (doublesℕ n (suc zero))) ≡ 0)
predDoubleDoublesOne≠0 zero = snotz
predDoubleDoublesOne≠0 (suc n) = predDoublePos (doublesℕ n 2) (doublesPos n 2 snotz)
doublesZero : (n : ℕ) → doublesℕ n zero ≡ zero
doublesZero zero = refl
doublesZero (suc n) = doublesZero n
-- 2^n(m+1) = (2^n)m + 2^n
-- doublesSuc : (n m : ℕ) → doublesℕ n (suc m) ≡ sucn (doublesℕ n 1) (doublesℕ n m)
-- doublesSuc zero m = refl
-- doublesSuc (suc n) m =
-- doublesℕ n (suc (suc (doubleℕ m)))
-- ≡⟨ doublesSuc n (suc (doubleℕ m)) ⟩
-- sucn (doublesℕ n 1) (doublesℕ n (suc (doubleℕ m)))
-- ≡⟨ cong (λ z → sucn (doublesℕ n 1) z) (doublesSuc n (doubleℕ m)) ⟩
-- sucn (doublesℕ n 1) (sucn (doublesℕ n 1) (doublesℕ n (doubleℕ m)))
-- ≡⟨ sucnDoubles n (doublesℕ n (doubleℕ m)) ⟩
-- sucn (doublesℕ n 2) (doublesℕ n (doubleℕ m))
-- ∎
-- where
-- sucnDoubles : (n m : ℕ) → sucn (doublesℕ n 1) (sucn (doublesℕ n 1) m) ≡ sucn (doublesℕ n 2) m
-- sucnDoubles zero m = refl
-- sucnDoubles (suc n) m =
-- sucn (doublesℕ n 2) (sucn (doublesℕ n 2) m)
-- ≡⟨ sym (sucnDoubles n (sucn (doublesℕ n 2) m)) ⟩
-- sucn (doublesℕ n 1) (sucn (doublesℕ n 1) (sucn (doublesℕ n 2) m))
-- ≡⟨ {!!} ⟩ {!!}
-- 2 * (i + n) = 2*i + 2*n
doubleSucn : (i n : ℕ) → doubleℕ (sucn i n) ≡ sucn (doubleℕ i) (doubleℕ n)
doubleSucn zero n = refl
doubleSucn (suc i) n =
suc (suc (doubleℕ (sucn i n)))
≡⟨ cong (λ z → suc (suc z)) (doubleSucn i n) ⟩
suc (suc (sucn (doubleℕ i) (doubleℕ n)))
≡⟨ refl ⟩
suc (sucn (suc (doubleℕ i)) (doubleℕ n))
≡⟨ cong suc refl ⟩
sucn (suc (suc (doubleℕ i))) (doubleℕ n)
∎
doublesSucn : (i n m : ℕ) → doublesℕ n (sucn i m) ≡ sucn (doublesℕ n i) (doublesℕ n m)
doublesSucn i zero m = refl
doublesSucn i (suc n) m =
doublesℕ n (doubleℕ (sucn i m))
≡⟨ cong (doublesℕ n) (doubleSucn i m) ⟩
doublesℕ n (sucn (doubleℕ i) (doubleℕ m))
≡⟨ doublesSucn (doubleℕ i) n (doubleℕ m) ⟩
sucn (doublesℕ n (doubleℕ i)) (doublesℕ n (doubleℕ m))
∎
-- 2^n * (m + 2) =
doublesSucSuc : (n m : ℕ) → doublesℕ n (suc (suc m)) ≡ sucn (doublesℕ (suc n) 1) (doublesℕ n m)
doublesSucSuc zero m = refl
doublesSucSuc (suc n) m =
doublesℕ (suc n) (suc (suc m))
≡⟨ refl ⟩
doublesℕ n (sucn 4 (doubleℕ m))
≡⟨ doublesSucn 4 n (doubleℕ m) ⟩
sucn (doublesℕ n 4) (doublesℕ n (doubleℕ m))
∎
n+n≡2n : (n : ℕ) → sucn n n ≡ doubleℕ n
n+n≡2n zero = refl
n+n≡2n (suc n) =
sucn (suc n) (suc n)
≡⟨ sucnsuc (suc n) n ⟩
suc (sucn (suc n) n)
≡⟨ refl ⟩
suc (suc (sucn n n))
≡⟨ cong (λ z → suc (suc z)) (n+n≡2n n) ⟩
suc (suc (doubleℕ n))
∎
-- predDoubles : (n m : ℕ) → ¬ (n ≡ 0) → ¬ (m ≡ 0) → ¬ (predℕ (doublesℕ n m)) ≡ 0
-- predDoubles zero m n≠0 m≠0 = ⊥-elim (n≠0 refl)
-- predDoubles (suc n) m sn≠0 m≠0 = {!!}
-- "Direction" type for determining direction in spatial structures.
-- We interpret ↓ as 0 and ↑ as 1 when used in numerals in
-- numerical types.
data Dir : Type₀ where
↓ : Dir
↑ : Dir
caseDir : ∀ {ℓ} → {A : Type ℓ} → (ad au : A) → Dir → A
caseDir ad au ↓ = ad
caseDir ad au ↑ = au
¬↓≡↑ : ¬ ↓ ≡ ↑
¬↓≡↑ eq = subst (caseDir Dir ⊥) eq ↓
¬↑≡↓ : ¬ ↑ ≡ ↓
¬↑≡↓ eq = subst (caseDir ⊥ Dir) eq ↓
-- Dependent "directional numerals":
-- for natural n, obtain 2ⁿ "numerals".
-- This is basically a little-endian binary notation.
-- NOTE: Would an implementation of DirNum with dependent vectors be preferable
-- over using products?
DirNum : ℕ → Type₀
DirNum zero = Unit
DirNum (suc n) = Dir × (DirNum n)
sucDoubleDirNum+ : (r : ℕ) → DirNum r → DirNum (suc r)
sucDoubleDirNum+ r x = (↑ , x)
-- bad name, since this is doubling "to" suc r
doubleDirNum+ : (r : ℕ) → DirNum r → DirNum (suc r)
doubleDirNum+ r x = (↓ , x)
DirNum→ℕ : ∀ {n} → DirNum n → ℕ
DirNum→ℕ {zero} tt = zero
DirNum→ℕ {suc n} (↓ , d) = doublesℕ (suc zero) (DirNum→ℕ d)
DirNum→ℕ {suc n} (↑ , d) = suc (doublesℕ (suc zero) (DirNum→ℕ d))
double-lemma : ∀ {r} → (d : DirNum r) →
doubleℕ (DirNum→ℕ d) ≡ DirNum→ℕ (doubleDirNum+ r d)
double-lemma {r} d = refl
¬↓,d≡↑,d′ : ∀ {n} → ∀ (d d′ : DirNum n) → ¬ (↓ , d) ≡ (↑ , d′)
¬↓,d≡↑,d′ {n} d d′ ↓,d≡↑,d′ = ¬↓≡↑ (cong proj₁ ↓,d≡↑,d′)
¬↑,d≡↓,d′ : ∀ {n} → ∀ (d d′ : DirNum n) → ¬ (↑ , d) ≡ (↓ , d′)
¬↑,d≡↓,d′ {n} d d′ ↑,d≡↓,d′ = ¬↑≡↓ (cong proj₁ ↑,d≡↓,d′)
-- dropping least significant bit preserves equality
dropLeast≡ : ∀ {n} → ∀ (ds ds′ : DirNum n) (d : Dir)
→ ((d , ds) ≡ (d , ds′)) → ds ≡ ds′
dropLeast≡ {n} ds ds′ d d,ds≡d,ds′ = cong proj₂ d,ds≡d,ds′
-- give the next numeral, cycling back to 0
-- in case of 2ⁿ - 1
next : ∀ {n} → DirNum n → DirNum n
next {zero} tt = tt
next {suc n} (↓ , ds) = (↑ , ds)
next {suc n} (↑ , ds) = (↓ , next ds)
prev : ∀ {n} → DirNum n → DirNum n
prev {zero} tt = tt
prev {suc n} (↓ , ds) = (↓ , prev ds)
prev {suc n} (↑ , ds) = (↓ , ds)
zero-n : (n : ℕ) → DirNum n
zero-n zero = tt
zero-n (suc n) = (↓ , zero-n n)
zero-n→0 : ∀ {r} → DirNum→ℕ (zero-n r) ≡ zero
zero-n→0 {zero} = refl
zero-n→0 {suc r} =
doubleℕ (DirNum→ℕ (zero-n r))
≡⟨ cong doubleℕ (zero-n→0 {r}) ⟩
doubleℕ zero
≡⟨ refl ⟩
zero
∎
zero-n? : ∀ {n} → (x : DirNum n) → Dec (x ≡ zero-n n)
zero-n? {zero} tt = yes refl
zero-n? {suc n} (↓ , ds) with zero-n? ds
... | no ds≠zero-n = no (λ y →
ds≠zero-n (dropLeast≡ ds (zero-n n) ↓ y))
... | yes ds≡zero-n = yes (cong (λ y → (↓ , y)) ds≡zero-n)
zero-n? {suc n} (↑ , ds) = no ((¬↑,d≡↓,d′ ds (zero-n n)))
zero-n≡0 : {r : ℕ} → DirNum→ℕ (zero-n r) ≡ zero
zero-n≡0{zero} = refl
zero-n≡0 {suc r} =
doubleℕ (DirNum→ℕ {r} (zero-n r))
≡⟨ cong doubleℕ (zero-n≡0 {r}) ⟩
0
∎
-- x is doubleable as a DirNum precisely when x's most significant bit is 0
-- this should return a Dec
doubleable-n? : {n : ℕ} → (x : DirNum n) → Bool
doubleable-n? {zero} tt = false
doubleable-n? {suc n} (x , x₁) with zero-n? x₁
... | yes _ = true
... | no _ = doubleable-n? x₁
dropMost : {r : ℕ} → DirNum (suc r) → DirNum r
dropMost {zero} d = tt
dropMost {suc zero} (x , (x₁ , x₂)) = (x₁ , x₂)
dropMost {suc (suc r)} (x , x₁) = (x , dropMost x₁)
-- need to prove property about doubleable
--doubleDirNum : (r : ℕ) (d : DirNum r) → doubleable-n? {r} d ≡ true → DirNum r
-- bad:
doubleDirNum : (r : ℕ) (d : DirNum r) → DirNum r
doubleDirNum zero d = tt
doubleDirNum (suc r) d = doubleDirNum+ r (dropMost {r} d)
-- doubleDirNum zero d doubleable = ⊥-elim (false≢true doubleable)
-- doubleDirNum (suc r) d doubleable = doubleDirNum+ r (dropMost {r} d)
one-n : (n : ℕ) → DirNum n
one-n zero = tt
one-n (suc n) = (↑ , zero-n n)
-- numeral for 2ⁿ - 1
max-n : (n : ℕ) → DirNum n
max-n zero = tt
max-n (suc n) = (↑ , max-n n)
--half-n : (n : ℕ) → DirNum n
max→ℕ : (r : ℕ) → DirNum→ℕ (max-n r) ≡ predℕ (doublesℕ r 1)
max→ℕ zero = refl
max→ℕ (suc r) =
suc (doubleℕ (DirNum→ℕ (max-n r)))
≡⟨ cong (λ z → suc (doubleℕ z)) (max→ℕ r) ⟩
suc (doubleℕ (predℕ (doublesℕ r 1)))
≡⟨ cong suc (doublePred (doublesℕ r 1)) ⟩
suc (predℕ (predℕ (doubleℕ (doublesℕ r 1))))
≡⟨ cong (λ z → suc (predℕ (predℕ z))) (doubleDoubles r 1) ⟩
suc (predℕ (predℕ (doublesℕ (suc r) 1)))
≡⟨ refl ⟩
suc (predℕ (predℕ (doublesℕ r 2)))
≡⟨ sucPred (predℕ (doublesℕ r 2)) H ⟩
predℕ (doublesℕ r 2)
∎
where
G : (r : ℕ) → doubleℕ (doublesℕ r 1) ≡ doublesℕ r 2
G zero = refl
G (suc r) = doubleℕ (doublesℕ r 2) ≡⟨ doubleDoubles r 2 ⟩
doublesℕ (suc r) 2 ≡⟨ refl ⟩ doublesℕ r (doubleℕ 2) ∎
H : ¬ predℕ (doublesℕ r 2) ≡ zero
H = λ h → (predDoublePos (doublesℕ r 1) (doublesPos r 1 snotz)
((
predℕ (doubleℕ (doublesℕ r 1)) ≡⟨ cong predℕ (G r) ⟩
predℕ (doublesℕ r 2) ≡⟨ h ⟩
0 ∎
)))
max? : ∀ {n} → (x : DirNum n) → Dec (x ≡ max-n n)
max? {zero} tt = yes refl
max? {suc n} (↓ , ds) = no ((¬↓,d≡↑,d′ ds (max-n n)))
max? {suc n} (↑ , ds) with max? ds
... | yes ds≡max-n = yes (
(↑ , ds)
≡⟨ cong (λ x → (↑ , x)) ds≡max-n ⟩
(↑ , max-n n)
∎
)
... | no ¬ds≡max-n = no (λ d,ds≡d,max-n →
¬ds≡max-n ((dropLeast≡ ds (max-n n) ↑ d,ds≡d,max-n)))
maxn+1≡↑maxn : ∀ n → max-n (suc n) ≡ (↑ , (max-n n))
maxn+1≡↑maxn n = refl
maxr≡pred2ʳ : (r : ℕ) (d : DirNum r) →
d ≡ max-n r → DirNum→ℕ d ≡ predℕ (doublesℕ r (suc zero))
maxr≡pred2ʳ zero d d≡max = refl
maxr≡pred2ʳ (suc r) (↓ , ds) d≡max = ⊥-elim ((¬↓,d≡↑,d′ ds (max-n r)) d≡max)
maxr≡pred2ʳ (suc r) (↑ , ds) d≡max =
suc (doubleℕ (DirNum→ℕ ds))
≡⟨ cong (λ x → suc (doubleℕ x)) (maxr≡pred2ʳ r ds ds≡max) ⟩
suc (doubleℕ (predℕ (doublesℕ r (suc zero)))) -- 2*(2^r - 1) + 1 = 2^r+1 - 1
≡⟨ cong suc (doublePred (doublesℕ r (suc zero))) ⟩
suc (predℕ (predℕ (doubleℕ (doublesℕ r (suc zero)))))
≡⟨ sucPred (predℕ (doubleℕ (doublesℕ r (suc zero)))) (
(predDoublePos (doublesℕ r (suc zero)) ((doublesPos r 1 snotz)))) ⟩
predℕ (doubleℕ (doublesℕ r (suc zero)))
≡⟨ cong predℕ (doubleDoubles r (suc zero)) ⟩
predℕ (doublesℕ (suc r) 1)
≡⟨ refl ⟩
predℕ (doublesℕ r 2) -- 2^r*2 - 1 = 2^(r+1) - 1
∎
where
ds≡max : ds ≡ max-n r
ds≡max = dropLeast≡ ds (max-n r) ↑ d≡max
-- TODO: rename
embed-next : (r : ℕ) → DirNum r → DirNum (suc r)
embed-next zero tt = (↓ , tt)
embed-next (suc r) (d , ds) with zero-n? ds
... | no _ = (d , embed-next r ds)
... | yes _ = (d , zero-n (suc r))
-- embed-next-thm : (r : ℕ) (d : DirNum r) → DirNum→ℕ d ≡ DirNum→ℕ (embed-next r d)
-- embed-next-thm zero d = refl
-- embed-next-thm (suc r) (d , ds) with zero-n? ds
-- ... | no _ = {!!}
-- ... | yes _ = {!!}
-- TODO: rename?
nextsuc-lemma : (r : ℕ) (x : DirNum r) →
¬ ((sucDoubleDirNum+ r x) ≡ max-n (suc r)) → ¬ (x ≡ max-n r)
nextsuc-lemma zero tt ¬H = ⊥-elim (¬H refl)
nextsuc-lemma (suc r) (↓ , x) ¬H = ¬↓,d≡↑,d′ x (max-n r)
nextsuc-lemma (suc r) (↑ , x) ¬H =
λ h → ¬H (H (dropLeast≡ x (max-n r) ↑ h)) --⊥-elim (¬H H)
where
H : (x ≡ max-n r) →
sucDoubleDirNum+ (suc r) (↑ , x) ≡ (↑ , (↑ , max-n r))
H x≡maxnr =
sucDoubleDirNum+ (suc r) (↑ , x)
≡⟨ cong (λ y → sucDoubleDirNum+ (suc r) (↑ , y)) x≡maxnr ⟩
sucDoubleDirNum+ (suc r) (↑ , max-n r)
≡⟨ refl ⟩
(↑ , (↑ , max-n r))
∎
next≡suc : (r : ℕ) (x : DirNum r) →
¬ (x ≡ max-n r) → DirNum→ℕ (next x) ≡ suc (DirNum→ℕ x)
next≡suc zero tt ¬x≡maxnr = ⊥-elim (¬x≡maxnr refl)
next≡suc (suc r) (↓ , x) ¬x≡maxnr = refl
next≡suc (suc r) (↑ , x) ¬x≡maxnr =
doubleℕ (DirNum→ℕ (next x))
≡⟨ cong doubleℕ (next≡suc r x (nextsuc-lemma r x ¬x≡maxnr)) ⟩
doubleℕ (suc (DirNum→ℕ x))
≡⟨ refl ⟩
suc (suc (doubleℕ (DirNum→ℕ x)))
∎
-- doublesuclemma : (r : ℕ) (x : DirNum (suc r)) →
-- doubleℕ (DirNum→ℕ (next x)) ≡ suc (suc (doubleℕ (DirNum→ℕ x)))
-- doublesuclemma zero (↓ , x₁) = refl
-- doublesuclemma zero (↑ , x₁) = {!!}
-- doublesuclemma (suc r) x = {!!}
-- doubleℕ (DirNum→ℕ (next x))
-- ≡⟨ cong doubleℕ (next≡suc r x ¬x≡maxnr) ⟩
-- doubleℕ (suc (DirNum→ℕ x))
-- ≡⟨ refl ⟩
-- suc (suc (doubleℕ (DirNum→ℕ x)))
-- ∎
| {
"alphanum_fraction": 0.5472239454,
"avg_line_length": 32,
"ext": "agda",
"hexsha": "fa5adb76d992ad5dde7ee762398cb78504add14b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_forks_repo_path": "Multidimensional/Direction.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_issues_repo_issues_event_max_datetime": "2019-07-02T16:24:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-19T20:40:07.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_issues_repo_path": "Multidimensional/Direction.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_stars_repo_path": "Multidimensional/Direction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5984,
"size": 12896
} |
{-# OPTIONS --irrelevant-projections #-}
data _≡_ {A : Set} : A → A → Set where
refl : (x : A) → x ≡ x
module Erased where
record Erased (A : Set) : Set where
constructor [_]
field
@0 erased : A
open Erased
record _↔_ (A B : Set) : Set where
field
to : A → B
from : B → A
to∘from : ∀ x → to (from x) ≡ x
from∘to : ∀ x → from (to x) ≡ x
postulate
A : Set
P : (B : Set) → (Erased A → B) → Set
p : (B : Set) (f : Erased A ↔ B) → P B (_↔_.to f)
fails : P (Erased (Erased A)) (λ (x : Erased A) → [ x ])
fails =
p _ (record
{ from = λ ([ x ]) → [ erased x ]
; to∘from = refl
; from∘to = λ _ → refl _
})
module Irrelevant where
record Irrelevant (A : Set) : Set where
constructor [_]
field
.irr : A
open Irrelevant
record _↔_ (A B : Set) : Set where
field
to : A → B
from : B → A
to∘from : ∀ x → to (from x) ≡ x
from∘to : ∀ x → from (to x) ≡ x
postulate
A : Set
P : (B : Set) → (Irrelevant A → B) → Set
p : (B : Set) (f : Irrelevant A ↔ B) → P B (_↔_.to f)
fails : P (Irrelevant (Irrelevant A)) (λ (x : Irrelevant A) → [ x ])
fails =
p _ (record
{ from = λ ([ x ]) → [ irr x ]
; to∘from = refl
; from∘to = λ _ → refl _
})
| {
"alphanum_fraction": 0.45,
"avg_line_length": 21.9047619048,
"ext": "agda",
"hexsha": "39ca73c4ec5187b3f7a2c42478363b3e8121562b",
"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/Issue4480.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/Issue4480.agda",
"max_line_length": 70,
"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/Issue4480.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": 508,
"size": 1380
} |
------------------------------------------------------------------------
-- A virtual machine
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
module Lambda.Simplified.Partiality-monad.Inductive.Virtual-machine
where
open import Equality.Propositional
open import Prelude hiding (⊥)
open import Monad equality-with-J
open import Partiality-monad.Inductive
open import Partiality-monad.Inductive.Fixpoints
open import Lambda.Simplified.Syntax
open import Lambda.Simplified.Virtual-machine
open Closure Code
-- A functional semantics for the VM.
--
-- For an alternative definition, see the semantics in
-- Lambda.Partiality-monad.Inductive.Virtual-machine, which is defined
-- without using a fixpoint combinator.
execP : State → Partial State (λ _ → Maybe Value) (Maybe Value)
execP s with step s
... | continue s′ = rec s′
... | done v = return (just v)
... | crash = return nothing
exec : State → Maybe Value ⊥
exec s = fixP execP s
| {
"alphanum_fraction": 0.6344827586,
"avg_line_length": 27.4324324324,
"ext": "agda",
"hexsha": "741d43799abcbb2b600e2f74df4ee02238bdb4c4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Virtual-machine.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Virtual-machine.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Virtual-machine.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 219,
"size": 1015
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import experimental.TwoConstancyHIT
module experimental.TwoConstancy
{i j} {A : Type i} {B : Type j} (B-is-gpd : is-gpd B)
(f : A → B)
(f-is-const₀ : ∀ a₁ a₂ → f a₁ == f a₂)
(f-is-const₁ : ∀ a₁ a₂ a₃
→ f-is-const₀ a₁ a₂ ∙' f-is-const₀ a₂ a₃ == f-is-const₀ a₁ a₃) where
private
abstract
lemma₁ : ∀ a (t₂ : TwoConstancy A) → point a == t₂
lemma₁ a = TwoConstancy-elim {P = λ t₂ → point a == t₂}
(λ _ → =-preserves-level 1 TwoConstancy-level)
(λ b → link₀ a b)
(λ b₁ b₂ → ↓-cst=idf-in' $ link₁ a b₁ b₂)
(λ b₁ b₂ b₃ → set-↓-has-all-paths-↓ $ TwoConstancy-level _ _ )
lemma₂ : ∀ (a₁ a₂ : A) →
lemma₁ a₁ == lemma₁ a₂ [ (λ t₁ → ∀ t₂ → t₁ == t₂) ↓ link₀ a₁ a₂ ]
lemma₂ a₁ a₂ = ↓-cst→app-in $
TwoConstancy-elim
{P = λ t₂ → lemma₁ a₁ t₂ == lemma₁ a₂ t₂ [ (λ t₁ → t₁ == t₂) ↓ link₀ a₁ a₂ ]}
(λ _ → ↓-preserves-level 1 λ _ → =-preserves-level 1 TwoConstancy-level)
(λ b → ↓-idf=cst-in $ ! $ link₁ a₁ a₂ b)
(λ b₁ b₂ → prop-has-all-paths-↓ $ ↓-level λ _ → TwoConstancy-level _ _)
(λ b₁ b₂ b₃ → prop-has-all-paths-↓ $ contr-is-prop
$ ↓-level λ _ → ↓-level λ _ → TwoConstancy-level _ _)
TwoConstancy-has-all-paths : has-all-paths (TwoConstancy A)
TwoConstancy-has-all-paths =
TwoConstancy-elim {P = λ t₁ → ∀ t₂ → t₁ == t₂}
(λ _ → Π-level λ _ → =-preserves-level 1 TwoConstancy-level)
lemma₁
lemma₂
(λ a₁ a₂ a₃ → prop-has-all-paths-↓
$ ↓-level λ t₁ → Π-is-set λ t₂ → TwoConstancy-level t₁ t₂)
TwoConstancy-is-prop : is-prop (TwoConstancy A)
TwoConstancy-is-prop = all-paths-is-prop TwoConstancy-has-all-paths
cst-extend : Trunc -1 A → B
cst-extend = TwoConstancy-rec B-is-gpd f f-is-const₀ f-is-const₁
∘ Trunc-rec TwoConstancy-is-prop point
-- The beta rule.
-- This is definitionally true, so you don't need it.
cst-extend-β : cst-extend ∘ [_] == f
cst-extend-β = idp
| {
"alphanum_fraction": 0.5690741638,
"avg_line_length": 38.9245283019,
"ext": "agda",
"hexsha": "fe7561b89c5cdc357479a8f8850256e90e2d605e",
"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": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/experimental/TwoConstancy.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"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": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/experimental/TwoConstancy.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/experimental/TwoConstancy.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 769,
"size": 2063
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Applicative functors
------------------------------------------------------------------------
-- Note that currently the applicative functor laws are not included
-- here.
{-# OPTIONS --without-K --safe #-}
module Category.Applicative where
open import Data.Unit
open import Category.Applicative.Indexed
RawApplicative : ∀ {f} → (Set f → Set f) → Set _
RawApplicative F = RawIApplicative {I = ⊤} (λ _ _ → F)
module RawApplicative {f} {F : Set f → Set f}
(app : RawApplicative F) where
open RawIApplicative app public
RawApplicativeZero : ∀ {f} → (Set f → Set f) → Set _
RawApplicativeZero F = RawIApplicativeZero {I = ⊤} (λ _ _ → F)
module RawApplicativeZero {f} {F : Set f → Set f}
(app : RawApplicativeZero F) where
open RawIApplicativeZero app public
RawAlternative : ∀ {f} → (Set f → Set f) → Set _
RawAlternative F = RawIAlternative {I = ⊤} (λ _ _ → F)
module RawAlternative {f} {F : Set f → Set f}
(app : RawAlternative F) where
open RawIAlternative app public
| {
"alphanum_fraction": 0.5639484979,
"avg_line_length": 31.4864864865,
"ext": "agda",
"hexsha": "712fc1c7397538b9dba0d170c1c0e427a5121c27",
"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/Category/Applicative.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/Category/Applicative.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/Category/Applicative.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 292,
"size": 1165
} |
------------------------------------------------------------------------
-- A definitional interpreter that is instrumented with information
-- about the number of steps required to run the compiled program
------------------------------------------------------------------------
open import Prelude
import Lambda.Syntax
module Lambda.Interpreter.Steps
{Name : Type}
(open Lambda.Syntax Name)
(def : Name → Tm 1)
where
import Equality.Propositional as E
open import Monad E.equality-with-J
open import Vec.Data E.equality-with-J
open import Delay-monad
open import Delay-monad.Bisimilarity
open import Lambda.Delay-crash
import Lambda.Interpreter def as I
open Closure Tm
------------------------------------------------------------------------
-- The interpreter
-- A step annotation.
infix 1 ✓_
✓_ : ∀ {A i} → Delay-crash A i → Delay-crash A i
✓ x = later λ { .force → x }
-- The instrumented interpreter.
infix 10 _∙_
mutual
⟦_⟧ : ∀ {i n} → Tm n → Env n → Delay-crash Value i
⟦ var x ⟧ ρ = ✓ return (index ρ x)
⟦ lam t ⟧ ρ = ✓ return (lam t ρ)
⟦ t₁ · t₂ ⟧ ρ = do v₁ ← ⟦ t₁ ⟧ ρ
v₂ ← ⟦ t₂ ⟧ ρ
v₁ ∙ v₂
⟦ call f t ⟧ ρ = do v ← ⟦ t ⟧ ρ
lam (def f) [] ∙ v
⟦ con b ⟧ ρ = ✓ return (con b)
⟦ if t₁ t₂ t₃ ⟧ ρ = do v₁ ← ⟦ t₁ ⟧ ρ
⟦if⟧ v₁ t₂ t₃ ρ
_∙_ : ∀ {i} → Value → Value → Delay-crash Value i
lam t₁ ρ ∙ v₂ = later λ { .force → ⟦ t₁ ⟧ (v₂ ∷ ρ) }
con _ ∙ _ = crash
⟦if⟧ : ∀ {i n} →
Value → Tm n → Tm n → Env n → Delay-crash Value i
⟦if⟧ (lam _ _) _ _ _ = crash
⟦if⟧ (con true) t₂ t₃ ρ = ✓ ⟦ t₂ ⟧ ρ
⟦if⟧ (con false) t₂ t₃ ρ = ✓ ⟦ t₃ ⟧ ρ
------------------------------------------------------------------------
-- The semantics given above gives the same (uninstrumented) result as
-- the one in Lambda.Interpreter
mutual
-- The result of the instrumented interpreter is an expansion of
-- that of the uninstrumented interpreter.
⟦⟧≳⟦⟧ :
∀ {i n} (t : Tm n) {ρ : Env n} →
[ i ] ⟦ t ⟧ ρ ≳ I.⟦ t ⟧ ρ
⟦⟧≳⟦⟧ (var x) = laterˡ (reflexive _)
⟦⟧≳⟦⟧ (lam t) = laterˡ (reflexive _)
⟦⟧≳⟦⟧ (t₁ · t₂) = ⟦⟧≳⟦⟧ t₁ >>=-cong λ _ →
⟦⟧≳⟦⟧ t₂ >>=-cong λ _ →
∙≳∙ _
⟦⟧≳⟦⟧ (call f t) = ⟦⟧≳⟦⟧ t >>=-cong λ _ →
∙≳∙ _
⟦⟧≳⟦⟧ (con b) = laterˡ (reflexive _)
⟦⟧≳⟦⟧ (if t₁ t₂ t₃) = ⟦⟧≳⟦⟧ t₁ >>=-cong λ _ →
⟦if⟧≳⟦if⟧ _ t₂ t₃
∙≳∙ :
∀ {i} (v₁ {v₂} : Value) →
[ i ] v₁ ∙ v₂ ≳ v₁ I.∙ v₂
∙≳∙ (lam t₁ ρ) = later λ { .force → ⟦⟧≳⟦⟧ t₁ }
∙≳∙ (con _) = reflexive _
⟦if⟧≳⟦if⟧ :
∀ {i n} v₁ (t₂ t₃ : Tm n) {ρ} →
[ i ] ⟦if⟧ v₁ t₂ t₃ ρ ≳ I.⟦if⟧ v₁ t₂ t₃ ρ
⟦if⟧≳⟦if⟧ (lam _ _) _ _ = reflexive _
⟦if⟧≳⟦if⟧ (con true) t₂ t₃ = laterˡ (⟦⟧≳⟦⟧ t₂)
⟦if⟧≳⟦if⟧ (con false) t₂ t₃ = laterˡ (⟦⟧≳⟦⟧ t₃)
| {
"alphanum_fraction": 0.444368367,
"avg_line_length": 28.637254902,
"ext": "agda",
"hexsha": "191892d4282c8aae8d09a6408f5ef124e1e0f4d8",
"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": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/definitional-interpreters",
"max_forks_repo_path": "src/Lambda/Interpreter/Steps.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"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/definitional-interpreters",
"max_issues_repo_path": "src/Lambda/Interpreter/Steps.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/definitional-interpreters",
"max_stars_repo_path": "src/Lambda/Interpreter/Steps.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1226,
"size": 2921
} |
open import Agda.Primitive
postulate
∞ : ∀ {a} (A : Set a) → Set (lsuc a)
{-# BUILTIN INFINITY ∞ #-}
| {
"alphanum_fraction": 0.5648148148,
"avg_line_length": 13.5,
"ext": "agda",
"hexsha": "6adccb70a2b0cf326b9fde7e78eb320033ef4bef",
"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/BuiltinInfinityBadType.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/BuiltinInfinityBadType.agda",
"max_line_length": 39,
"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/BuiltinInfinityBadType.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": 42,
"size": 108
} |
-- {-# OPTIONS -v tc.lhs.problem:10 #-}
-- {-# OPTIONS --compile --ghc-flag=-i.. #-}
module Issue727 where
open import Common.Prelude renaming (Nat to ℕ)
open import Common.MAlonzo hiding (main)
Sum : ℕ → Set
Sum 0 = ℕ
Sum (suc n) = ℕ → Sum n
sum : (n : ℕ) → ℕ → Sum n
sum 0 acc = acc
sum (suc n) acc m = sum n (m + acc)
main = mainPrintNat (sum 3 0 1 2 3)
| {
"alphanum_fraction": 0.5866666667,
"avg_line_length": 22.0588235294,
"ext": "agda",
"hexsha": "f2dc6e45d68b9ca263d1b17a7dfa77a49cad0862",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue727.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/Issue727.agda",
"max_line_length": 46,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue727.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 135,
"size": 375
} |
{-# OPTIONS --type-in-type #-}
module IDescTT where
--********************************************
-- Prelude
--********************************************
-- Some preliminary stuffs, to avoid relying on the stdlib
--****************
-- Sigma and friends
--****************
data Sigma (A : Set) (B : A -> Set) : Set where
_,_ : (x : A) (y : B x) -> Sigma A B
_*_ : (A : Set)(B : Set) -> Set
A * B = Sigma A \_ -> B
fst : {A : Set}{B : A -> Set} -> Sigma A B -> A
fst (a , _) = a
snd : {A : Set}{B : A -> Set} (p : Sigma A B) -> B (fst p)
snd (a , b) = b
data Zero : Set where
data Unit : Set where
Void : Unit
--****************
-- Sum and friends
--****************
data _+_ (A : Set)(B : Set) : Set where
l : A -> A + B
r : B -> A + B
--****************
-- Equality
--****************
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
subst : forall {x y} -> x == y -> x -> y
subst refl x = x
cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y
cong f refl = refl
cong2 : {A B C : Set}(f : A -> B -> C){x y : A}{z t : B} ->
x == y -> z == t -> f x z == f y t
cong2 f refl refl = refl
postulate
reflFun : {A B : Set}(f : A -> B)(g : A -> B)-> ((a : A) -> f a == g a) -> f == g
--****************
-- Meta-language
--****************
-- Note that we could define Nat, Bool, and the related operations in
-- IDesc. But it is awful to code with them, in Agda.
data Nat : Set where
ze : Nat
su : Nat -> Nat
data Bool : Set where
true : Bool
false : Bool
plus : Nat -> Nat -> Nat
plus ze n' = n'
plus (su n) n' = su (plus n n')
le : Nat -> Nat -> Bool
le ze _ = true
le (su _) ze = false
le (su n) (su n') = le n n'
--********************************************
-- Desc code
--********************************************
data IDesc (I : Set) : Set where
var : I -> IDesc I
const : Set -> IDesc I
prod : IDesc I -> IDesc I -> IDesc I
sigma : (S : Set) -> (S -> IDesc I) -> IDesc I
pi : (S : Set) -> (S -> IDesc I) -> IDesc I
--********************************************
-- Desc interpretation
--********************************************
[|_|] : {I : Set} -> IDesc I -> (I -> Set) -> Set
[| var i |] P = P i
[| const X |] P = X
[| prod D D' |] P = [| D |] P * [| D' |] P
[| sigma S T |] P = Sigma S (\s -> [| T s |] P)
[| pi S T |] P = (s : S) -> [| T s |] P
--********************************************
-- Fixpoint construction
--********************************************
data IMu {I : Set}(R : I -> IDesc I)(i : I) : Set where
con : [| R i |] (\j -> IMu R j) -> IMu R i
--********************************************
-- Predicate: All
--********************************************
All : {I : Set}(D : IDesc I)(P : I -> Set) -> [| D |] P -> IDesc (Sigma I P)
All (var i) P x = var (i , x)
All (const X) P x = const Unit
All (prod D D') P (d , d') = prod (All D P d) (All D' P d')
All (sigma S T) P (a , b) = All (T a) P b
All (pi S T) P f = pi S (\s -> All (T s) P (f s))
all : {I : Set}(D : IDesc I)(X : I -> Set)
(R : Sigma I X -> Set)(P : (x : Sigma I X) -> R x) ->
(xs : [| D |] X) -> [| All D X xs |] R
all (var i) X R P x = P (i , x)
all (const K) X R P k = Void
all (prod D D') X R P (x , y) = ( all D X R P x , all D' X R P y )
all (sigma S T) X R P (a , b) = all (T a) X R P b
all (pi S T) X R P f = \a -> all (T a) X R P (f a)
--********************************************
-- Elimination principle: induction
--********************************************
-- One would like to write the following:
{-
indI : {I : Set}
(R : I -> IDesc I)
(P : Sigma I (IMu R) -> Set)
(m : (i : I)
(xs : [| R i |] (IMu R))
(hs : [| All (R i) (IMu R) xs |] P) ->
P ( i , con xs)) ->
(i : I)(x : IMu R i) -> P ( i , x )
indI {I} R P m i (con xs) = m i xs (all (R i) (IMu R) P induct xs)
where induct : (x : Sigma I (IMu R)) -> P x
induct (i , xs) = indI R P m i xs
-}
-- But the termination-checker complains, so here we go
-- inductive-recursive:
module Elim {I : Set}
(R : I -> IDesc I)
(P : Sigma I (IMu R) -> Set)
(m : (i : I)
(xs : [| R i |] (IMu R))
(hs : [| All (R i) (IMu R) xs |] P) ->
P ( i , con xs ))
where
mutual
indI : (i : I)(x : IMu R i) -> P (i , x)
indI i (con xs) = m i xs (hyps (R i) xs)
hyps : (D : IDesc I) ->
(xs : [| D |] (IMu R)) ->
[| All D (IMu R) xs |] P
hyps (var i) x = indI i x
hyps (const X) x = Void
hyps (prod D D') (d , d') = hyps D d , hyps D' d'
hyps (pi S R) f = \ s -> hyps (R s) (f s)
hyps (sigma S R) ( a , b ) = hyps (R a) b
indI : {I : Set}
(R : I -> IDesc I)
(P : Sigma I (IMu R) -> Set)
(m : (i : I)
(xs : [| R i |] (IMu R))
(hs : [| All (R i) (IMu R) xs |] P) ->
P ( i , con xs)) ->
(i : I)(x : IMu R i) -> P ( i , x )
indI = Elim.indI
--********************************************
-- Examples
--********************************************
--****************
-- Nat
--****************
data NatConst : Set where
Ze : NatConst
Su : NatConst
natCases : NatConst -> IDesc Unit
natCases Ze = const Unit
natCases Suc = var Void
NatD : Unit -> IDesc Unit
NatD Void = sigma NatConst natCases
Natd : Unit -> Set
Natd x = IMu NatD x
zed : Natd Void
zed = con (Ze , Void)
sud : Natd Void -> Natd Void
sud n = con (Su , n)
--****************
-- Desc
--****************
data DescDConst : Set where
lvar : DescDConst
lconst : DescDConst
lprod : DescDConst
lpi : DescDConst
lsigma : DescDConst
descDChoice : Set -> DescDConst -> IDesc Unit
descDChoice I lvar = const I
descDChoice _ lconst = const Set
descDChoice _ lprod = prod (var Void) (var Void)
descDChoice _ lpi = sigma Set (\S -> pi S (\s -> var Void))
descDChoice _ lsigma = sigma Set (\S -> pi S (\s -> var Void))
descD : (I : Set) -> IDesc Unit
descD I = sigma DescDConst (descDChoice I)
IDescl0 : (I : Set) -> Unit -> Set
IDescl0 I = IMu (\_ -> descD I)
IDescl : (I : Set) -> Set
IDescl I = IDescl0 I _
varl : {I : Set}(i : I) -> IDescl I
varl i = con (lvar , i)
constl : {I : Set}(X : Set) -> IDescl I
constl X = con (lconst , X)
prodl : {I : Set}(D D' : IDescl I) -> IDescl I
prodl D D' = con (lprod , (D , D'))
pil : {I : Set}(S : Set)(T : S -> IDescl I) -> IDescl I
pil S T = con (lpi , ( S , T))
sigmal : {I : Set}(S : Set)(T : S -> IDescl I) -> IDescl I
sigmal S T = con (lsigma , ( S , T))
--****************
-- Vec (constraints)
--****************
data VecConst : Set where
Vnil : VecConst
Vcons : VecConst
vecDChoice : Set -> Nat -> VecConst -> IDesc Nat
vecDChoice X n Vnil = const (n == ze)
vecDChoice X n Vcons = sigma Nat (\m -> prod (var m) (const (n == su m)))
vecD : Set -> Nat -> IDesc Nat
vecD X n = sigma VecConst (vecDChoice X n)
vec : Set -> Nat -> Set
vec X n = IMu (vecD X) n
--****************
-- Vec (de-tagged, forced)
--****************
data VecConst2 : Nat -> Set where
Vnil : VecConst2 ze
Vcons : {n : Nat} -> VecConst2 (su n)
vecDChoice2 : Set -> (n : Nat) -> VecConst2 n -> IDesc Nat
vecDChoice2 X ze Vnil = const Unit
vecDChoice2 X (su n) Vcons = prod (const X) (var n)
vecD2 : Set -> Nat -> IDesc Nat
vecD2 X n = sigma (VecConst2 n) (vecDChoice2 X n)
vec2 : Set -> Nat -> Set
vec2 X n = IMu (vecD2 X) n
--****************
-- Fin (de-tagged)
--****************
data FinConst : Nat -> Set where
Fz : {n : Nat} -> FinConst (su n)
Fs : {n : Nat} -> FinConst (su n)
finDChoice : (n : Nat) -> FinConst n -> IDesc Nat
finDChoice ze ()
finDChoice (su n) Fz = const Unit
finDChoice (su n) Fs = var n
finD : Nat -> IDesc Nat
finD n = sigma (FinConst n) (finDChoice n)
fin : Nat -> Set
fin n = IMu finD n
--********************************************
-- Enumerations (hard-coded)
--********************************************
-- Unlike in Desc.agda, we don't carry the levitation of finite sets
-- here. We hard-code them and manipulate with standard Agda
-- machinery. Both presentation are isomorph but, in Agda, the coded
-- one quickly gets unusable.
data EnumU : Set where
nilE : EnumU
consE : EnumU -> EnumU
data EnumT : (e : EnumU) -> Set where
EZe : {e : EnumU} -> EnumT (consE e)
ESu : {e : EnumU} -> EnumT e -> EnumT (consE e)
spi : (e : EnumU)(P : EnumT e -> Set) -> Set
spi nilE P = Unit
spi (consE e) P = P EZe * spi e (\e -> P (ESu e))
switch : (e : EnumU)(P : EnumT e -> Set)(b : spi e P)(x : EnumT e) -> P x
switch nilE P b ()
switch (consE e) P b EZe = fst b
switch (consE e) P b (ESu n) = switch e (\e -> P (ESu e)) (snd b) n
_++_ : EnumU -> EnumU -> EnumU
nilE ++ e' = e'
(consE e) ++ e' = consE (e ++ e')
-- A special switch, for tagged descriptions. Switching on a
-- concatenation of finite sets:
sswitch : (e : EnumU)(e' : EnumU)(P : Set)
(b : spi e (\_ -> P))(b' : spi e' (\_ -> P))(x : EnumT (e ++ e')) -> P
sswitch nilE nilE P b b' ()
sswitch nilE (consE e') P b b' EZe = fst b'
sswitch nilE (consE e') P b b' (ESu n) = sswitch nilE e' P b (snd b') n
sswitch (consE e) e' P b b' EZe = fst b
sswitch (consE e) e' P b b' (ESu n) = sswitch e e' P (snd b) b' n
--********************************************
-- Tagged indexed description
--********************************************
FixMenu : Set -> Set
FixMenu I = Sigma EnumU (\e -> (i : I) -> spi e (\_ -> IDesc I))
SensitiveMenu : Set -> Set
SensitiveMenu I = Sigma (I -> EnumU) (\F -> (i : I) -> spi (F i) (\_ -> IDesc I))
TagIDesc : Set -> Set
TagIDesc I = FixMenu I * SensitiveMenu I
toIDesc : (I : Set) -> TagIDesc I -> (I -> IDesc I)
toIDesc I ((E , ED) , (F , FD)) i = sigma (EnumT (E ++ F i))
(\x -> sswitch E (F i) (IDesc I) (ED i) (FD i) x)
--********************************************
-- Catamorphism
--********************************************
cata : (I : Set)
(R : I -> IDesc I)
(T : I -> Set) ->
((i : I) -> [| R i |] T -> T i) ->
(i : I) -> IMu R i -> T i
cata I R T phi i x = indI R (\it -> T (fst it)) (\i xs ms -> phi i (replace (R i) T xs ms)) i x
where replace : (D : IDesc I)(T : I -> Set)
(xs : [| D |] (IMu R))
(ms : [| All D (IMu R) xs |] (\it -> T (fst it))) ->
[| D |] T
replace (var i) T x y = y
replace (const Z) T z z' = z
replace (prod D D') T (x , x') (y , y') = replace D T x y , replace D' T x' y'
replace (sigma A B) T (a , b) t = a , replace (B a) T b t
replace (pi A B) T f t = \s -> replace (B s) T (f s) (t s)
--********************************************
-- Hutton's razor
--********************************************
--********************************
-- Types code
--********************************
data Type : Set where
nat : Type
bool : Type
pair : Type -> Type -> Type
--********************************
-- Typed expressions
--********************************
Val : Type -> Set
Val nat = Nat
Val bool = Bool
Val (pair x y) = (Val x) * (Val y)
-- Fix menu:
exprFixMenu : FixMenu Type
exprFixMenu = ( consE (consE nilE) ,
\ty -> (const (Val ty), -- Val t
(prod (var bool) (prod (var ty) (var ty)), -- if b then t1 else t2
Void)))
-- Indexed menu:
choiceMenu : Type -> EnumU
choiceMenu nat = consE nilE
choiceMenu bool = consE nilE
choiceMenu (pair x y) = nilE
choiceDessert : (ty : Type) -> spi (choiceMenu ty) (\ _ -> IDesc Type)
choiceDessert nat = (prod (var nat) (var nat) , Void)
choiceDessert bool = (prod (var nat) (var nat) , Void )
choiceDessert (pair x y) = Void
exprSensitiveMenu : SensitiveMenu Type
exprSensitiveMenu = ( choiceMenu , choiceDessert )
-- Expression:
expr : TagIDesc Type
expr = exprFixMenu , exprSensitiveMenu
exprIDesc : TagIDesc Type -> (Type -> IDesc Type)
exprIDesc D = toIDesc Type D
--********************************
-- Closed terms
--********************************
closeTerm : Type -> IDesc Type
closeTerm = exprIDesc expr
--********************************
-- Closed term evaluation
--********************************
eval : {ty : Type} -> IMu closeTerm ty -> Val ty
eval {ty} term = cata Type closeTerm Val evalOneStep ty term
where evalOneStep : (ty : Type) -> [| closeTerm ty |] Val -> Val ty
evalOneStep _ (EZe , t) = t
evalOneStep _ ((ESu EZe) , (true , ( x , _))) = x
evalOneStep _ ((ESu EZe) , (false , ( _ , y ))) = y
evalOneStep nat ((ESu (ESu EZe)) , (x , y)) = plus x y
evalOneStep nat ((ESu (ESu (ESu ()))) , t)
evalOneStep bool ((ESu (ESu EZe)) , (x , y) ) = le x y
evalOneStep bool ((ESu (ESu (ESu ()))) , _)
evalOneStep (pair x y) (ESu (ESu ()) , _)
--********************************************
-- Free monad construction
--********************************************
_**_ : {I : Set} (R : TagIDesc I)(X : I -> Set) -> TagIDesc I
((E , ED) , FFD) ** X = ((( consE E , \ i -> ( const (X i) , ED i ))) , FFD)
--********************************************
-- Substitution
--********************************************
apply : {I : Set}
(R : TagIDesc I)(X Y : I -> Set) ->
((i : I) -> X i -> IMu (toIDesc I (R ** Y)) i) ->
(i : I) ->
[| toIDesc I (R ** X) i |] (IMu (toIDesc I (R ** Y))) ->
IMu (toIDesc I (R ** Y)) i
apply (( E , ED) , (F , FD)) X Y sig i (EZe , x) = sig i x
apply (( E , ED) , (F , FD)) X Y sig i (ESu n , t) = con (ESu n , t)
substI : {I : Set} (X Y : I -> Set)(R : TagIDesc I)
(sigma : (i : I) -> X i -> IMu (toIDesc I (R ** Y)) i)
(i : I)(D : IMu (toIDesc I (R ** X)) i) ->
IMu (toIDesc I (R ** Y)) i
substI {I} X Y R sig i term = cata I (toIDesc I (R ** X)) (IMu (toIDesc I (R ** Y))) (apply R X Y sig) i term
--********************************************
-- Hutton's razor is free monad
--********************************************
Empty : Type -> Set
Empty _ = Zero
closeTerm' : Type -> IDesc Type
closeTerm' = toIDesc Type (expr ** Empty)
update : {ty : Type} -> IMu closeTerm ty -> IMu closeTerm' ty
update {ty} tm = cata Type closeTerm (IMu closeTerm') (\ _ tagTm -> con (ESu (fst tagTm) , (snd tagTm))) ty tm
--********************************
-- Closed term' evaluation
--********************************
eval' : {ty : Type} -> IMu closeTerm' ty -> Val ty
eval' {ty} term = cata Type closeTerm' Val evalOneStep ty term
where evalOneStep : (ty : Type) -> [| closeTerm' ty |] Val -> Val ty
evalOneStep _ (EZe , ())
evalOneStep _ (ESu EZe , t) = t
evalOneStep _ ((ESu (ESu EZe)) , (true , ( x , _))) = x
evalOneStep _ ((ESu (ESu EZe)) , (false , ( _ , y ))) = y
evalOneStep nat ((ESu (ESu (ESu EZe))) , (x , y)) = plus x y
evalOneStep nat (((ESu (ESu (ESu (ESu ()))))) , t)
evalOneStep bool ((ESu (ESu (ESu EZe))) , (x , y) ) = le x y
evalOneStep bool ((ESu (ESu (ESu (ESu ())))) , _)
evalOneStep (pair x y) (ESu (ESu (ESu ())) , _)
--********************************
-- Open terms
--********************************
-- A context is a snoc-list of types
-- put otherwise, a context is a type telescope
data Context : Set where
[] : Context
_,_ : Context -> Type -> Context
-- The environment realizes the context, having a value for each type
Env : Context -> Set
Env [] = Unit
Env (G , S) = Env G * Val S
-- A typed-variable indexes into the context, obtaining a proof that
-- what we get is what you want (WWGIWYW)
Var : Context -> Type -> Set
Var [] T = Zero
Var (G , S) T = Var G T + (S == T)
-- The lookup gets into the context to extract the value
lookup : (G : Context) -> Env G -> (T : Type) -> Var G T -> Val T
lookup [] _ T ()
lookup (G , .T) (g , t) T (r refl) = t
lookup (G , S) (g , t) T (l x) = lookup G g T x
-- Open term: holes are either values or variables in a context
openTerm : Context -> Type -> IDesc Type
openTerm c = toIDesc Type (expr ** (Var c))
--********************************
-- Evaluation of open terms
--********************************
-- |discharge| is the local substitution expected by |substI|. It is
-- just sugar around context lookup
discharge : (context : Context) ->
Env context ->
(ty : Type) ->
Var context ty ->
IMu closeTerm' ty
discharge ctxt env ty variable = con (ESu EZe , lookup ctxt env ty variable )
-- |substExpr| is the specialized |substI| to expressions. We get it
-- generically from the free monad construction.
substExpr : {ty : Type}
(context : Context)
(sigma : (ty : Type) ->
Var context ty ->
IMu closeTerm' ty) ->
IMu (openTerm context) ty ->
IMu closeTerm' ty
substExpr {ty} c sig term =
substI (Var c) Empty expr sig ty term
-- By first doing substitution to close the term, we can use
-- evaluation of closed terms, obtaining evaluation of open terms
-- under a valid context.
evalOpen : {ty : Type}(context : Context) ->
Env context ->
IMu (openTerm context) ty ->
Val ty
evalOpen ctxt env tm = eval' (substExpr ctxt (discharge ctxt env) tm)
--********************************
-- Tests
--********************************
-- Test context:
-- V 0 :-> true, V 1 :-> 2, V 2 :-> ( false , 1 )
testContext : Context
testContext = (([] , bool) , nat) , pair bool nat
testEnv : Env testContext
testEnv = ((Void , true ) , su (su ze)) , (false , su ze)
-- V 1
test1 : IMu (openTerm testContext) nat
test1 = con (EZe , ( l (r refl) ) )
testSubst1 : IMu closeTerm' nat
testSubst1 = substExpr testContext
(discharge testContext testEnv)
test1
-- = 2
testEval1 : Val nat
testEval1 = evalOpen testContext testEnv test1
-- add 1 (V 1)
test2 : IMu (openTerm testContext) nat
test2 = con (ESu (ESu (ESu EZe)) , (con (ESu EZe , su ze) , con ( EZe , l (r refl) )) )
testSubst2 : IMu closeTerm' nat
testSubst2 = substExpr testContext
(discharge testContext testEnv)
test2
-- = 3
testEval2 : Val nat
testEval2 = evalOpen testContext testEnv test2
-- if (V 0) then (V 1) else 0
test3 : IMu (openTerm testContext) nat
test3 = con (ESu (ESu EZe) , (con (EZe , l (l (r refl))) ,
(con (EZe , l (r refl)) ,
con (ESu EZe , ze))))
testSubst3 : IMu closeTerm' nat
testSubst3 = substExpr testContext
(discharge testContext testEnv)
test3
-- = 2
testEval3 : Val nat
testEval3 = evalOpen testContext testEnv test3
-- V 2
test4 : IMu (openTerm testContext) (pair bool nat)
test4 = con (EZe , r refl )
testSubst4 : IMu closeTerm' (pair bool nat)
testSubst4 = substExpr testContext
(discharge testContext testEnv)
test4
-- = (false , 1)
testEval4 : Val (pair bool nat)
testEval4 = evalOpen testContext testEnv test4 | {
"alphanum_fraction": 0.468797012,
"avg_line_length": 29.2963525836,
"ext": "agda",
"hexsha": "0df2ad0ce5f4c3258ce0068bfd7fbce8a4192b4a",
"lang": "Agda",
"max_forks_count": 12,
"max_forks_repo_forks_event_max_datetime": "2022-02-11T01:57:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-08-14T21:36:35.000Z",
"max_forks_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mietek/epigram",
"max_forks_repo_path": "models/IDescTT.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mietek/epigram",
"max_issues_repo_path": "models/IDescTT.agda",
"max_line_length": 110,
"max_stars_count": 48,
"max_stars_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mietek/epigram",
"max_stars_repo_path": "models/IDescTT.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T01:55:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-01-09T17:36:19.000Z",
"num_tokens": 6242,
"size": 19277
} |
module STLC2 where
open import Data.Nat
-- open import Data.List
open import Data.Empty using (⊥-elim)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong; cong₂; subst)
open import Relation.Nullary
open import Data.Product
-- de Bruijn indexed lambda calculus
infix 5 ƛ_
infixl 7 _∙_
infix 9 var_
data Term : Set where
var_ : ℕ → Term
ƛ_ : Term → Term
_∙_ : Term → Term → Term
-- only "shift" the variable when
-- 1. it's free
-- 2. it will be captured after substitution
-- free <= x && x < subst-depth
shift : ℕ → ℕ → Term → Term
shift free subst-depth (var x) with free >? x
shift free subst-depth (var x) | yes p = var x -- bound
shift free subst-depth (var x) | no ¬p with subst-depth >? x -- free
shift free subst-depth (var x) | no ¬p | yes q = var (suc x) -- will be captured, should increment
shift free subst-depth (var x) | no ¬p | no ¬q = var x
shift free subst-depth (ƛ M) = ƛ (shift (suc free) (suc subst-depth) M)
shift free subst-depth (M ∙ N) = shift free subst-depth M ∙ shift free subst-depth N
infixl 10 _[_/_]
_[_/_] : Term → Term → ℕ → Term
(var x) [ N / n ] with x ≟ n
(var x) [ N / n ] | yes p = N
(var x) [ N / n ] | no ¬p = var x
(ƛ M) [ N / n ] = ƛ ((M [ shift 0 (suc n) N / suc n ]))
(L ∙ M) [ N / n ] = L [ N / n ] ∙ M [ N / n ]
-- substitution
infixl 10 _[_]
_[_] : Term → Term → Term
M [ N ] = M [ N / zero ]
-- β reduction
infix 3 _β→_
data _β→_ : Term → Term → Set where
β-ƛ-∙ : ∀ {M N} → ((ƛ M) ∙ N) β→ (M [ N ])
β-ƛ : ∀ {M N} → M β→ N → ƛ M β→ ƛ N
β-∙-l : ∀ {L M N} → M β→ N → M ∙ L β→ N ∙ L
β-∙-r : ∀ {L M N} → M β→ N → L ∙ M β→ L ∙ N
-- the reflexive and transitive closure of _β→_
infix 2 _β→*_
infixr 2 _→*_
data _β→*_ : Term → Term → Set where
∎ : ∀ {M} → M β→* M
_→*_
: ∀ {L M N}
→ L β→ M
→ M β→* N
--------------
→ L β→* N
infixl 3 _<β>_
_<β>_ : ∀ {M N O} → M β→* N → N β→* O → M β→* O
_<β>_ {M} {.M} {O} ∎ N→O = N→O
_<β>_ {M} {N} {O} (L→M →* M→N) N→O = L→M →* M→N <β> N→O
-- infix 2 _-↠_
infixr 2 _→⟨_⟩_
_→⟨_⟩_
: ∀ {M N}
→ ∀ L
→ L β→ M
→ M β→* N
--------------
→ L β→* N
L →⟨ P ⟩ Q = P →* Q
infixr 2 _→*⟨_⟩_
_→*⟨_⟩_
: ∀ {M N}
→ ∀ L
→ L β→* M
→ M β→* N
--------------
→ L β→* N
L →*⟨ P ⟩ Q = P <β> Q
infix 3 _→∎
_→∎ : ∀ M → M β→* M
M →∎ = ∎
jump : ∀ {M N} → M β→ N → M β→* N
jump {M} {N} M→N = M→N →* ∎
-- the symmetric closure of _β→*_
infix 1 _β≡_
data _β≡_ : Term → Term → Set where
β-sym : ∀ {M N}
→ M β→* N
→ N β→* M
-------
→ M β≡ N
infixr 2 _=*⟨_⟩_
_=*⟨_⟩_
: ∀ {M N}
→ ∀ L
→ L β≡ M
→ M β≡ N
--------------
→ L β≡ N
L =*⟨ β-sym A B ⟩ β-sym C D = β-sym (A <β> C) (D <β> B)
infixr 2 _=*⟨⟩_
_=*⟨⟩_
: ∀ {N}
→ ∀ L
→ L β≡ N
--------------
→ L β≡ N
L =*⟨⟩ β-sym C D = β-sym C D
infix 3 _=∎
_=∎ : ∀ M → M β≡ M
M =∎ = β-sym ∎ ∎
forward : ∀ {M N} → M β≡ N → M β→* N
forward (β-sym A _) = A
backward : ∀ {M N} → M β≡ N → N β→* M
backward (β-sym _ B) = B
-- data Normal : Set where
Normal : Term → Set
Normal M = ¬ ∃ (λ N → M β→ N)
normal : ∀ {M N} → Normal M → M β→* N → M ≡ N
normal P ∎ = refl
normal P (M→L →* L→N) = ⊥-elim (P (_ , M→L))
normal-ƛ : ∀ {M} → Normal (ƛ M) → Normal M
normal-ƛ P (N , M→N) = P ((ƛ N) , (β-ƛ M→N))
normal-ƛ' : ∀ {M} → Normal M → Normal (ƛ M)
normal-ƛ' P (.(ƛ N) , β-ƛ {N = N} ƛM→N) = P (N , ƛM→N)
normal-∙-r : ∀ {M N} → Normal (M ∙ N) → Normal N
normal-∙-r {M} P (O , N→O) = P (M ∙ O , (β-∙-r N→O))
normal-∙-l : ∀ {M N} → Normal (M ∙ N) → Normal M
normal-∙-l {_} {N} P (O , M→O) = P (O ∙ N , (β-∙-l M→O))
cong-ƛ : ∀ {M N} → M β→* N → ƛ M β→* ƛ N
cong-ƛ ∎ = ∎
cong-ƛ (M→N →* N→O) = β-ƛ M→N →* cong-ƛ N→O
cong-∙-l : ∀ {L M N} → M β→* N → M ∙ L β→* N ∙ L
cong-∙-l ∎ = ∎
cong-∙-l (M→N →* N→O) = β-∙-l M→N →* cong-∙-l N→O
cong-∙-r : ∀ {L M N} → M β→* N → L ∙ M β→* L ∙ N
cong-∙-r ∎ = ∎
cong-∙-r (M→N →* N→O) = β-∙-r M→N →* cong-∙-r N→O
∙-dist-r : ∀ M N O → (ƛ (M ∙ N)) ∙ O β→* ((ƛ M) ∙ O) ∙ ((ƛ N) ∙ O)
∙-dist-r (var x) N O = {! !}
∙-dist-r (ƛ M) N O = {! !}
∙-dist-r (M ∙ L) N O = {! !}
∙-dist-r2 : ∀ M N O → (ƛ (M ∙ N)) ∙ O β≡ ((ƛ M) ∙ O) ∙ ((ƛ N) ∙ O)
∙-dist-r2 (var x) N O = {! !}
∙-dist-r2 (ƛ M) N O = {! !}
∙-dist-r2 (M ∙ L) (var x) O =
(ƛ (M ∙ L ∙ var x)) ∙ O
=*⟨ β-sym (β-ƛ-∙ →* ∎) {! !} ⟩
((M ∙ L ∙ var x) [ O ])
=*⟨ {! !} ⟩
{! !}
=*⟨ {! !} ⟩
(ƛ M ∙ L) ∙ O ∙ ((ƛ var x) ∙ O)
=∎
∙-dist-r2 (M ∙ L) (ƛ N) O = {! !}
∙-dist-r2 (M ∙ L) (N ∙ K) O = {! !}
-- {! !}
-- →*⟨ {! !} ⟩
-- {! !}
-- →*⟨ {! !} ⟩
-- {! !}
-- →*⟨ {! !} ⟩
-- {! !}
-- →*⟨ {! !} ⟩
-- {! !}
-- →∎
-- (ƛ M) [ N / n ] = ƛ ((M [ shift 0 (suc n) N / suc n ]))
cong-[]2 : ∀ {M N L n} → M β→ N → (M [ L / n ]) β→* (N [ L / n ])
cong-[]2 (β-ƛ-∙ {var x} {N}) = {! !}
cong-[]2 {_} {_} {L} {n} (β-ƛ-∙ {ƛ M} {N}) =
(ƛ (ƛ (M [ shift 0 (suc (suc n)) (shift 0 (suc n) L) / suc (suc n) ]))) ∙ (N [ L / n ])
→*⟨ jump β-ƛ-∙ ⟩
ƛ ((M [ shift 0 (suc (suc n)) (shift 0 (suc n) L) / suc (suc n) ]) [ shift 0 1 (N [ L / n ]) / 1 ])
→*⟨ cong-ƛ {! !} ⟩
ƛ {! !}
→*⟨ {! !} ⟩
{! !}
→*⟨ {! !} ⟩
ƛ ((M [ shift 0 1 N / 1 ]) [ shift 0 (suc n) L / suc n ])
→∎
cong-[]2 {_} {_} {L} {n} (β-ƛ-∙ {M ∙ K} {N}) =
(ƛ (M [ shift 0 (suc n) L / suc n ]) ∙ (K [ shift 0 (suc n) L / suc n ])) ∙ (N [ L / n ])
→*⟨ {! !} ⟩
-- →*⟨ forward (∙-dist-r2 (M [ shift zero (suc n) L / suc n ]) (K [ shift zero (suc n) L / suc n ]) (N [ L / n ])) ⟩
(ƛ (M [ shift zero (suc n) L / suc n ])) ∙ (N [ L / n ]) ∙ ((ƛ (K [ shift 0 (suc n) L / suc n ])) ∙ (N [ L / n ]))
→*⟨ cong-∙-l (cong-[]2 (β-ƛ-∙ {M} {N})) ⟩
((M [ N ]) [ L / n ]) ∙ ((ƛ (K [ shift 0 (suc n) L / suc n ])) ∙ (N [ L / n ]))
→*⟨ cong-∙-r (cong-[]2 (β-ƛ-∙ {K} {N})) ⟩
((M [ N ]) [ L / n ]) ∙ ((K [ N ]) [ L / n ])
→∎
cong-[]2 (β-ƛ M→N) = cong-ƛ (cong-[]2 M→N)
cong-[]2 (β-∙-l M→N) = cong-∙-l (cong-[]2 M→N)
cong-[]2 (β-∙-r M→N) = cong-∙-r (cong-[]2 M→N)
cong-∙-l' : ∀ {L M N} → M β→* N → M ∙ L ≡ N ∙ L
cong-∙-l' ∎ = refl
cong-∙-l' {L} {M} {O} (_→*_ {M = N} M→N N→O) = trans M∙L≡N∙L N∙L≡O∙L
where
M∙L≡N∙L : M ∙ L ≡ N ∙ L
M∙L≡N∙L = {! !}
N∙L≡O∙L : N ∙ L ≡ O ∙ L
N∙L≡O∙L = cong-∙-l' N→O
-- rans (cong-∙-l' (M→N →* ∎)) (cong-∙-l' N→O)
cong-[] : ∀ {M N L n} → M β→ N → (M [ L / n ]) ≡ (N [ L / n ])
cong-[] β-ƛ-∙ = {! !}
cong-[] (β-ƛ M→N) = {! !}
cong-[] (β-∙-l M→N) = cong-∙-l' {! cong-[] M→N !}
cong-[] (β-∙-r M→N) = {! !}
normal-unique' : ∀ {M N O} → Normal N → Normal O → M β→ N → M β→ O → N ≡ O
normal-unique' P Q β-ƛ-∙ β-ƛ-∙ = refl
normal-unique' P Q (β-ƛ-∙ {M} {L}) (β-∙-l {N = .(ƛ N)} (β-ƛ {N = N} M→N)) = {! !}
-- trans (normal P (cong-[]2 M→N)) N[L]≡ƛN∙L
-- trans (normal P (cong-[]2 M→N)) N[L]≡ƛN∙L
where
N[L]≡ƛN∙L : (N [ L ]) ≡ (ƛ N) ∙ L
N[L]≡ƛN∙L = sym (normal Q (jump β-ƛ-∙))
-- β-ƛ-∙ : ∀ {M N} → ((ƛ M) ∙ N) β→ (M [ N ])
normal-unique' P Q (β-ƛ-∙ {M} {L}) (β-∙-r {N = N} L→N) = {! sym (normal Q (jump β-ƛ-∙)) !}
-- sym (trans (normal Q (jump β-ƛ-∙)) (cong (λ x → M [ x ]) (sym (normal {! !} (jump N→O)))))
-- sym (trans (normal Q (jump β-ƛ-∙)) (cong (λ x → {! M [ x ] !}) {! !}))
-- sym (trans {! !} (normal {! P !} (jump β-ƛ-∙)))
normal-unique' P Q (β-ƛ M→N) (β-ƛ M→O) = cong ƛ_ (normal-unique' (normal-ƛ P) (normal-ƛ Q) M→N M→O)
normal-unique' P Q (β-∙-l M→N) β-ƛ-∙ = {!normal (normal-∙-l P) !}
normal-unique' P Q (β-∙-l {L} {N = N} M→N) (β-∙-l {N = O} M→O) =
cong (λ x → x ∙ L) (normal-unique' (normal-∙-l P) (normal-∙-l Q) M→N M→O)
normal-unique' P Q (β-∙-l M→N) (β-∙-r M→O) =
cong₂ _∙_ (sym (normal (normal-∙-l Q) (jump M→N))) (normal (normal-∙-r P) (jump M→O))
normal-unique' {O = O} P Q (β-∙-r {L} {N = N} M→N) M→O =
{! !}
normal-unique : ∀ {M N O} → Normal N → Normal O → M β→* N → M β→* O → N ≡ O
normal-unique P Q ∎ M→O = normal P M→O
normal-unique P Q M→N ∎ = sym (normal Q M→N)
normal-unique P Q (_→*_ {M = L} M→L L→N) (_→*_ {M = K} M→K K→O) = {! !}
-- rewrite (normal-unique' {! !} {! !} M→L M→K) = normal-unique P Q L→N {! K→O !}
-- where
-- postulate L≡K : L ≡ K
-- normal-unique' P Q {! !} {! !}
-- ... | U = {! !}
-- trans {! !} (normal-unique {! !} {! !} L→N {! !})
-- L≡K = {! !}
-- normal-unique P Q {! !} M→O
-- normal-unique P Q M→N ∎ = sym (normal Q M→N)
-- normal-unique P Q M→N (M→L →* L→O) = {! !}
-- β→*-confluent : ∀ {M N O} → (M β→* N) → (M β→* O) → ∃ (λ P → (N β→* P) × (O β→* P))
-- β→*-confluent {M} {.M} {O} ∎ M→O = O , M→O , ∎
-- β→*-confluent {M} {N} {.M} (M→L →* L→N) ∎ = N , ∎ , (M→L →* L→N)
-- β→*-confluent {M} {N} {O} (M→L →* L→N) (M→K →* K→O) = {! !}
-- lemma-0 : ∀ M N → M [ N ] β→* (ƛ M) ∙ N
-- lemma-0 (var zero) (var zero) = (var zero) →⟨ {! !} ⟩ {! !}
-- lemma-0 (var zero) (var suc y) = {! !}
-- lemma-0 (var suc x) (var y) = {! !}
-- lemma-0 (var x) (ƛ O) = {! !}
-- lemma-0 (var x) (O ∙ P) = {! !}
-- lemma-0 (ƛ M) O = {! !}
-- lemma-0 (M ∙ N) O = {! !}
-- lemma : ∀ M N O → ((ƛ M) ∙ N β→* O) → M [ N ] β→* O
-- lemma (var x) N .((ƛ var x) ∙ N) (.((ƛ var x) ∙ N) ∎) = {! !}
-- lemma (ƛ M) N .((ƛ (ƛ M)) ∙ N) (.((ƛ (ƛ M)) ∙ N) ∎) = {! !}
-- lemma (M ∙ M₁) N .((ƛ M ∙ M₁) ∙ N) (.((ƛ M ∙ M₁) ∙ N) ∎) = {! !}
-- lemma M N O (.((ƛ M) ∙ N) →⟨⟩ redex→O) = lemma M N O redex→O
-- lemma M N O (_→⟨_⟩_ .((ƛ M) ∙ N) {P} ƛM∙N→P P→O) = {! !}
-- -- lemma M N P (jump ƛM∙N→P) <β> P→O
-- lemma-1 : ∀ M N O P → (ƛ M β→* N) → (N ∙ O β→* P) → M [ O ] β→* P
-- lemma-1 M .(ƛ M) O P (.(ƛ M) ∎) N∙O→P = lemma M O P N∙O→P
-- lemma-1 M N O P (.(ƛ M) →⟨⟩ ƛM→N) N∙O→P = lemma-1 M N O P ƛM→N N∙O→P
-- lemma-1 M N O .(N ∙ O) (.(ƛ M) →⟨ x ⟩ ƛM→N) (.(N ∙ O) ∎) = {! !}
-- lemma-1 M N O P (.(ƛ M) →⟨ x ⟩ ƛM→N) (.(N ∙ O) →⟨⟩ N∙O→P) = {! !}
-- lemma-1 M N O P (.(ƛ M) →⟨ x ⟩ ƛM→N) (.(N ∙ O) →⟨ x₁ ⟩ N∙O→P) = {! !}
-- -- (M [ N ]) β→* O
-- -- M'→O : P ∙ N β→* O
-- -- L→M' : ƛ M β→ P
-- -- (M [ N ]) β→* O
-- -- M'→O : N₂ ∙ N β→* O
-- -- L→M' : ƛ M β→ N₂
-- -- M→N : (M [ N ]) β→* N₁
-- -- that diamond prop
-- --
-- -- M
-- -- N O
-- -- P
-- --
-- β→*-confluent : ∀ {M N O} → (M β→* N) → (M β→* O) → ∃ (λ P → (N β→* P) × (O β→* P))
-- β→*-confluent {O = O} (M ∎) M→O = O , M→O , (O ∎)
-- β→*-confluent (L →⟨⟩ M→N) M→O = β→*-confluent M→N M→O
-- β→*-confluent {N = N} (L →⟨ x ⟩ M→N) (.L ∎) = N , (N ∎) , (L →⟨ x ⟩ M→N)
-- β→*-confluent (L →⟨ x ⟩ M→N) (.L →⟨⟩ M→O) = β→*-confluent (L →⟨ x ⟩ M→N) M→O
-- β→*-confluent (.((ƛ _) ∙ _) →⟨ β-ƛ-∙ ⟩ M→N) (.((ƛ _) ∙ _) →⟨ β-ƛ-∙ ⟩ M'→O) = β→*-confluent M→N M'→O
-- β→*-confluent {N = N} {O} (.((ƛ M) ∙ N₁) →⟨ β-ƛ-∙ {M} {N₁} ⟩ M→N) (.((ƛ M) ∙ N₁) →⟨ β-∙-l {N = N₂} L→M' ⟩ M'→O) = β→*-confluent M→N (lemma-1 M N₂ N₁ O ((ƛ M) →⟨ L→M' ⟩ (N₂ ∎)) M'→O)
-- β→*-confluent (.((ƛ _) ∙ _) →⟨ β-ƛ-∙ ⟩ M→N) (.((ƛ _) ∙ _) →⟨ β-∙-r L→M' ⟩ M'→O) = {! !}
-- β→*-confluent (.(ƛ _) →⟨ β-ƛ L→M ⟩ M→N) (.(ƛ _) →⟨ L→M' ⟩ M'→O) = {! !}
-- β→*-confluent (.(_ ∙ _) →⟨ β-∙-l L→M ⟩ M→N) (.(_ ∙ _) →⟨ L→M' ⟩ M'→O) = {! !}
-- β→*-confluent (.(_ ∙ _) →⟨ β-∙-r L→M ⟩ M→N) (.(_ ∙ _) →⟨ L→M' ⟩ M'→O) = {! !}
-- L
-- M M'
-- N O
-- P
--
-- module Example where
-- S : Term
-- S = ƛ ƛ ƛ var 2 ∙ var 0 ∙ (var 1 ∙ var 0)
-- K : Term
-- K = ƛ ƛ var 1
-- I : Term
-- I = ƛ (var 0)
-- Z : Term
-- Z = ƛ ƛ var 0
-- SZ : Term
-- SZ = ƛ ƛ var 1 ∙ var 0
-- PLUS : Term
-- PLUS = ƛ ƛ ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)
-- test-0 : ƛ (ƛ ƛ var 1) ∙ var 0 β→* ƛ ƛ var 1
-- test-0 =
-- ƛ (ƛ ƛ var 1) ∙ var 0
-- →⟨ β-ƛ β-ƛ-∙ ⟩
-- ƛ (ƛ var 1) [ var 0 / 0 ]
-- →⟨⟩
-- ƛ ƛ ((var 1) [ shift 0 1 (var 0) / 1 ])
-- →⟨⟩
-- ƛ ƛ ((var 1) [ var 1 / 1 ])
-- →⟨⟩
-- ƛ (ƛ var 1)
-- ∎
-- test-2 : PLUS ∙ Z ∙ SZ β→* SZ
-- test-2 =
-- PLUS ∙ Z ∙ SZ
-- →⟨⟩
-- (ƛ (ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero))))) ∙ Z ∙ SZ
-- →⟨ β-∙-l β-ƛ-∙ ⟩
-- ((ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)))) [ Z ]) ∙ SZ
-- →⟨⟩
-- ((ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)))) [ Z / 0 ]) ∙ SZ
-- →⟨⟩
-- (ƛ ((ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero))) [ shift 0 1 Z / 1 ])) ∙ SZ
-- →⟨⟩
-- (ƛ ((ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero))) [ Z / 1 ])) ∙ SZ
-- →⟨⟩
-- (ƛ (ƛ ((ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ Z / 2 ]))) ∙ SZ
-- →⟨⟩
-- (ƛ (ƛ (ƛ ((var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ Z / 3 ])))) ∙ SZ
-- →⟨⟩
-- (ƛ ƛ ƛ Z ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) ∙ SZ
-- →⟨ β-ƛ-∙ ⟩
-- ((ƛ ƛ Z ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ SZ / 0 ])
-- →⟨⟩
-- ƛ ((ƛ Z ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ SZ / 1 ])
-- →⟨⟩
-- ƛ ƛ ((Z ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var zero)) [ SZ / 2 ])
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ (SZ ∙ var 1 ∙ var 0)
-- →⟨ β-ƛ (β-ƛ (β-∙-r (β-∙-l β-ƛ-∙))) ⟩
-- ƛ ƛ Z ∙ var 1 ∙ (((ƛ var 1 ∙ var 0) [ var 1 ]) ∙ var 0)
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ (((ƛ var 1 ∙ var 0) [ var 1 / 0 ]) ∙ var 0)
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ ((ƛ ((var 1 ∙ var 0) [ shift 0 1 (var 1) / 1 ])) ∙ var 0)
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ ((ƛ ((var 1 ∙ var 0) [ var 1 / 1 ])) ∙ var 0)
-- →⟨⟩
-- ƛ ƛ Z ∙ var 1 ∙ ((ƛ var 1 ∙ var 0) ∙ var 0)
-- →⟨ β-ƛ (β-ƛ (β-∙-r β-ƛ-∙)) ⟩
-- ƛ ƛ Z ∙ var 1 ∙ ((var 1 ∙ var 0) [ var 0 / 0 ])
-- →⟨⟩
-- ƛ ƛ (ƛ ƛ var 0) ∙ var 1 ∙ (var 1 ∙ var 0)
-- →⟨ β-ƛ (β-ƛ (β-∙-l β-ƛ-∙)) ⟩
-- ƛ ƛ ((ƛ var 0) [ var 1 / 0 ]) ∙ (var 1 ∙ var 0)
-- →⟨⟩
-- ƛ ƛ (ƛ ((var 0) [ var 1 / 1 ])) ∙ (var 1 ∙ var 0)
-- →⟨⟩
-- ƛ ƛ (ƛ var 0) ∙ (var 1 ∙ var 0)
-- →⟨ β-ƛ (β-ƛ β-ƛ-∙) ⟩
-- ƛ ƛ ((var 0) [ var 1 ∙ var 0 / 0 ])
-- →⟨⟩
-- SZ
-- ∎ | {
"alphanum_fraction": 0.3663784012,
"avg_line_length": 30.852494577,
"ext": "agda",
"hexsha": "22890c07fa7e61fc0b43a7b360bb456506df736c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/bidirectional",
"max_forks_repo_path": "LC/stash/STLC2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/bidirectional",
"max_issues_repo_path": "LC/stash/STLC2.agda",
"max_line_length": 184,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/bidirectional",
"max_stars_repo_path": "LC/stash/STLC2.agda",
"max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z",
"num_tokens": 7855,
"size": 14223
} |
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; setoid; cong; trans)
import Function.Equality
open import Relation.Binary using (Setoid)
open import Categories.Category
open import Categories.Functor
open import Categories.Category.Instance.Setoids
open import Categories.Monad.Relative
open import Categories.Category.Equivalence
open import Categories.Category.Cocartesian
module SecondOrder.RelativeMonadMorphism
{o ℓ e o′ ℓ′ e′ : Level}
{C : Category o ℓ e}
{D : Category o′ ℓ′ e′}
where
record RMonadMorph {J : Functor C D} (M M’ : Monad J) : Set (lsuc (o ⊔ ℓ′ ⊔ e′))
where
open Category D
open Monad
field
morph : ∀ {X} → (F₀ M X) ⇒ (F₀ M’ X)
law-unit : ∀ {X} → morph ∘ (unit M {X}) ≈ unit M’ {X}
law-extend : ∀ {X Y} {k : (Functor.F₀ J X) ⇒ (F₀ M Y)}
→ (morph {Y}) ∘ (extend M k)
≈ (extend M’ ((morph {Y}) ∘ k)) ∘ (morph {X})
-- here, the equality used is the equivalence relation between morphisms of the category D
| {
"alphanum_fraction": 0.6445454545,
"avg_line_length": 35.4838709677,
"ext": "agda",
"hexsha": "9ef6f341c6d794a5b63e47b623d7725851cc2641",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/SecondOrder/RelativeMonadMorphism.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/SecondOrder/RelativeMonadMorphism.agda",
"max_line_length": 92,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/SecondOrder/RelativeMonadMorphism.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 336,
"size": 1100
} |
open import Preliminaries
open import Preorder
module PreorderExamples where
-- there is a preorder on Unit
unit-p : Preorder Unit
unit-p = preorder (preorder-structure (λ x x₁ → Unit) (λ x → <>) (λ x y z _ _ → <>))
-- there is a preorder on Nat
_≤n_ : Nat → Nat → Set
_≤n_ Z Z = Unit
_≤n_ Z (S n) = Unit
_≤n_ (S m) Z = Void
_≤n_ (S m) (S n) = m ≤n n
nat-refl : ∀ (n : Nat) → n ≤n n
nat-refl Z = <>
nat-refl (S n) = nat-refl n
nat-trans : ∀ (m n p : Nat) → m ≤n n → n ≤n p → m ≤n p
nat-trans Z Z Z x x₁ = <>
nat-trans Z Z (S p) x x₁ = <>
nat-trans Z (S n) Z x x₁ = <>
nat-trans Z (S n) (S p) x x₁ = <>
nat-trans (S m) Z Z () x₁
nat-trans (S m) Z (S p) () x₁
nat-trans (S m) (S n) Z x ()
nat-trans (S m) (S n) (S p) x x₁ = nat-trans m n p x x₁
nat-p : Preorder Nat
nat-p = preorder (preorder-structure (λ m n → m ≤n n) nat-refl nat-trans)
| {
"alphanum_fraction": 0.5472972973,
"avg_line_length": 25.3714285714,
"ext": "agda",
"hexsha": "9c4eba6653e981781a3f0c829b3e52e226ca36e9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "benhuds/Agda",
"max_forks_repo_path": "complexity-drafts/PreorderExamples.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "benhuds/Agda",
"max_issues_repo_path": "complexity-drafts/PreorderExamples.agda",
"max_line_length": 86,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "benhuds/Agda",
"max_stars_repo_path": "complexity-drafts/PreorderExamples.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z",
"num_tokens": 374,
"size": 888
} |
-- Andreas, 2020-06-17, issue #4135
-- Do not allow meta-solving during projection disambiguation!
data Bool : Set where
true false : Bool
module Foo (b : Bool) where
record R : Set where
field f : Bool
open R public
open module True = Foo true
open module False = Foo false
test : Foo.R {!!}
test .f = {!!}
-- WAS: succeeds with constraint ?0 := true
-- C-c C-=
-- Expected error:
-- Ambiguous projection f.
-- It could refer to any of
-- True.f (introduced at <open module True>)
-- False.f (introduced at <open module False>)
-- when checking the clause left hand side
-- test .f
| {
"alphanum_fraction": 0.667218543,
"avg_line_length": 21.5714285714,
"ext": "agda",
"hexsha": "b81c65810dfab9dc5002f0ce0974f2e161bb31b7",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Fail/Issue4135Record.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/Issue4135Record.agda",
"max_line_length": 62,
"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/Issue4135Record.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": 170,
"size": 604
} |
-- 2010-10-15 and 2012-03-09
{-# OPTIONS -v tc.conv.irr:50 -v tc.decl.ax:10 #-}
module Issue351 where
import Common.Irrelevance
data _==_ {A : Set1}(a : A) : A -> Set where
refl : a == a
record R : Set1 where
constructor mkR
field
fromR : Set
reflR : (r : R) -> r == (mkR _)
reflR r = refl {a = _}
record IR : Set1 where
constructor mkIR
field
.fromIR : Set
reflIR : (r : IR) -> r == (mkIR _)
reflIR r = refl {a = _}
-- peeking into the irrelevant argument, we can immediately solve for the meta
| {
"alphanum_fraction": 0.6199616123,
"avg_line_length": 19.2962962963,
"ext": "agda",
"hexsha": "eb2da9c70b2f41d690cf1d9b0ab30bd188fa1674",
"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/succeed/Issue351.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/succeed/Issue351.agda",
"max_line_length": 78,
"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/succeed/Issue351.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 190,
"size": 521
} |
open import Prelude
module Implicits.Semantics.Type where
open import Data.Vec
open import Implicits.Syntax
open import SystemF.Everything as F using ()
⟦_⟧tp→ : ∀ {ν} → Type ν → F.Type ν
⟦ simpl (tc n) ⟧tp→ = F.tc n
⟦ simpl (tvar n) ⟧tp→ = F.tvar n
⟦ simpl (a →' b) ⟧tp→ = ⟦ a ⟧tp→ F.→' ⟦ b ⟧tp→
⟦ a ⇒ b ⟧tp→ = ⟦ a ⟧tp→ F.→' ⟦ b ⟧tp→
⟦ ∀' x ⟧tp→ = F.∀' ⟦ x ⟧tp→
⟦_⟧tps→ : ∀ {ν n} → Vec (Type ν) n → Vec (F.Type ν) n
⟦ v ⟧tps→ = map (⟦_⟧tp→) v
| {
"alphanum_fraction": 0.5446428571,
"avg_line_length": 24.8888888889,
"ext": "agda",
"hexsha": "ea88ccc38cc3ee68f10dc6ca3274c94be60107f7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Semantics/Type.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Semantics/Type.agda",
"max_line_length": 53,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Semantics/Type.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 226,
"size": 448
} |
-- Andreas, 2011-04-05
module EtaContractToMillerPattern where
data _==_ {A : Set}(a : A) : A -> Set where
refl : a == a
record Prod (A B : Set) : Set where
constructor _,_
field fst : A
snd : B
open Prod
postulate A B C : Set
test : let X : (Prod A B -> C) -> (Prod A B -> C)
X = _
in (x : Prod A B -> C) ->
X (\ z -> x (fst z , snd z)) == x
test x = refl
-- eta contracts unification problem to X x = x | {
"alphanum_fraction": 0.5296703297,
"avg_line_length": 22.75,
"ext": "agda",
"hexsha": "69f1bc4cc0122aec5ff6aa45b2dafb2906037fe9",
"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/EtaContractToMillerPattern.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/EtaContractToMillerPattern.agda",
"max_line_length": 49,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/EtaContractToMillerPattern.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": 154,
"size": 455
} |
{-# OPTIONS --safe #-}
module Cubical.Foundations.Path where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Reflection.StrictEquiv
private
variable
ℓ ℓ' : Level
A : Type ℓ
-- Less polymorphic version of `cong`, to avoid some unresolved metas
cong′ : ∀ {B : Type ℓ'} (f : A → B) {x y : A} (p : x ≡ y)
→ Path B (f x) (f y)
cong′ f = cong f
{-# INLINE cong′ #-}
PathP≡Path : ∀ (P : I → Type ℓ) (p : P i0) (q : P i1) →
PathP P p q ≡ Path (P i1) (transport (λ i → P i) p) q
PathP≡Path P p q i = PathP (λ j → P (i ∨ j)) (transport-filler (λ j → P j) p i) q
PathP≡Path⁻ : ∀ (P : I → Type ℓ) (p : P i0) (q : P i1) →
PathP P p q ≡ Path (P i0) p (transport⁻ (λ i → P i) q)
PathP≡Path⁻ P p q i = PathP (λ j → P (~ i ∧ j)) p (transport⁻-filler (λ j → P j) q i)
PathPIsoPath : ∀ (A : I → Type ℓ) (x : A i0) (y : A i1) → Iso (PathP A x y) (transport (λ i → A i) x ≡ y)
PathPIsoPath A x y .Iso.fun = fromPathP
PathPIsoPath A x y .Iso.inv = toPathP
PathPIsoPath A x y .Iso.rightInv q k i =
hcomp
(λ j → λ
{ (i = i0) → slide (j ∨ ~ k)
; (i = i1) → q j
; (k = i0) → transp (λ l → A (i ∨ l)) i (fromPathPFiller j)
; (k = i1) → ∧∨Square i j
})
(transp (λ l → A (i ∨ ~ k ∨ l)) (i ∨ ~ k)
(transp (λ l → (A (i ∨ (~ k ∧ l)))) (k ∨ i)
(transp (λ l → A (i ∧ l)) (~ i)
x)))
where
fromPathPFiller : _
fromPathPFiller =
hfill
(λ j → λ
{ (i = i0) → x
; (i = i1) → q j })
(inS (transp (λ j → A (i ∧ j)) (~ i) x))
slide : I → _
slide i = transp (λ l → A (i ∨ l)) i (transp (λ l → A (i ∧ l)) (~ i) x)
∧∨Square : I → I → _
∧∨Square i j =
hcomp
(λ l → λ
{ (i = i0) → slide j
; (i = i1) → q (j ∧ l)
; (j = i0) → slide i
; (j = i1) → q (i ∧ l)
})
(slide (i ∨ j))
PathPIsoPath A x y .Iso.leftInv q k i =
outS
(hcomp-unique
(λ j → λ
{ (i = i0) → x
; (i = i1) → transp (λ l → A (j ∨ l)) j (q j)
})
(inS (transp (λ l → A (i ∧ l)) (~ i) x))
(λ j → inS (transp (λ l → A (i ∧ (j ∨ l))) (~ i ∨ j) (q (i ∧ j)))))
k
PathP≃Path : (A : I → Type ℓ) (x : A i0) (y : A i1) →
PathP A x y ≃ (transport (λ i → A i) x ≡ y)
PathP≃Path A x y = isoToEquiv (PathPIsoPath A x y)
PathP≡compPath : ∀ {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : y ≡ z) (r : x ≡ z)
→ (PathP (λ i → x ≡ q i) p r) ≡ (p ∙ q ≡ r)
PathP≡compPath p q r k = PathP (λ i → p i0 ≡ q (i ∨ k)) (λ j → compPath-filler p q k j) r
PathP≡doubleCompPathˡ : ∀ {A : Type ℓ} {w x y z : A} (p : w ≡ y) (q : w ≡ x) (r : y ≡ z) (s : x ≡ z)
→ (PathP (λ i → p i ≡ s i) q r) ≡ (p ⁻¹ ∙∙ q ∙∙ s ≡ r)
PathP≡doubleCompPathˡ p q r s k = PathP (λ i → p (i ∨ k) ≡ s (i ∨ k))
(λ j → doubleCompPath-filler (p ⁻¹) q s k j) r
PathP≡doubleCompPathʳ : ∀ {A : Type ℓ} {w x y z : A} (p : w ≡ y) (q : w ≡ x) (r : y ≡ z) (s : x ≡ z)
→ (PathP (λ i → p i ≡ s i) q r) ≡ (q ≡ p ∙∙ r ∙∙ s ⁻¹)
PathP≡doubleCompPathʳ p q r s k = PathP (λ i → p (i ∧ (~ k)) ≡ s (i ∧ (~ k)))
q (λ j → doubleCompPath-filler p r (s ⁻¹) k j)
compPathl-cancel : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : x ≡ z) → p ∙ (sym p ∙ q) ≡ q
compPathl-cancel p q = p ∙ (sym p ∙ q) ≡⟨ assoc p (sym p) q ⟩
(p ∙ sym p) ∙ q ≡⟨ cong (_∙ q) (rCancel p) ⟩
refl ∙ q ≡⟨ sym (lUnit q) ⟩
q ∎
compPathr-cancel : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : z ≡ y) (q : x ≡ y) → (q ∙ sym p) ∙ p ≡ q
compPathr-cancel {x = x} p q i j =
hcomp-equivFiller (doubleComp-faces (λ _ → x) (sym p) j) (inS (q j)) (~ i)
compPathl-isEquiv : {x y z : A} (p : x ≡ y) → isEquiv (λ (q : y ≡ z) → p ∙ q)
compPathl-isEquiv p = isoToIsEquiv (iso (p ∙_) (sym p ∙_) (compPathl-cancel p) (compPathl-cancel (sym p)))
compPathlEquiv : {x y z : A} (p : x ≡ y) → (y ≡ z) ≃ (x ≡ z)
compPathlEquiv p = (p ∙_) , compPathl-isEquiv p
compPathr-isEquiv : {x y z : A} (p : y ≡ z) → isEquiv (λ (q : x ≡ y) → q ∙ p)
compPathr-isEquiv p = isoToIsEquiv (iso (_∙ p) (_∙ sym p) (compPathr-cancel p) (compPathr-cancel (sym p)))
compPathrEquiv : {x y z : A} (p : y ≡ z) → (x ≡ y) ≃ (x ≡ z)
compPathrEquiv p = (_∙ p) , compPathr-isEquiv p
-- Variations of isProp→isSet for PathP
isProp→SquareP : ∀ {B : I → I → Type ℓ} → ((i j : I) → isProp (B i j))
→ {a : B i0 i0} {b : B i0 i1} {c : B i1 i0} {d : B i1 i1}
→ (r : PathP (λ j → B j i0) a c) (s : PathP (λ j → B j i1) b d)
→ (t : PathP (λ j → B i0 j) a b) (u : PathP (λ j → B i1 j) c d)
→ SquareP B t u r s
isProp→SquareP {B = B} isPropB {a = a} r s t u i j =
hcomp (λ { k (i = i0) → isPropB i0 j (base i0 j) (t j) k
; k (i = i1) → isPropB i1 j (base i1 j) (u j) k
; k (j = i0) → isPropB i i0 (base i i0) (r i) k
; k (j = i1) → isPropB i i1 (base i i1) (s i) k
}) (base i j) where
base : (i j : I) → B i j
base i j = transport (λ k → B (i ∧ k) (j ∧ k)) a
isProp→isPropPathP : ∀ {ℓ} {B : I → Type ℓ} → ((i : I) → isProp (B i))
→ (b0 : B i0) (b1 : B i1)
→ isProp (PathP (λ i → B i) b0 b1)
isProp→isPropPathP {B = B} hB b0 b1 = isProp→SquareP (λ _ → hB) refl refl
isProp→isContrPathP : {A : I → Type ℓ} → (∀ i → isProp (A i))
→ (x : A i0) (y : A i1)
→ isContr (PathP A x y)
isProp→isContrPathP h x y = isProp→PathP h x y , isProp→isPropPathP h x y _
-- Flipping a square along its diagonal
flipSquare : {a₀₀ a₀₁ : A} {a₀₋ : a₀₀ ≡ a₀₁}
{a₁₀ a₁₁ : A} {a₁₋ : a₁₀ ≡ a₁₁}
{a₋₀ : a₀₀ ≡ a₁₀} {a₋₁ : a₀₁ ≡ a₁₁}
→ Square a₀₋ a₁₋ a₋₀ a₋₁ → Square a₋₀ a₋₁ a₀₋ a₁₋
flipSquare sq i j = sq j i
module _ {a₀₀ a₀₁ : A} {a₀₋ : a₀₀ ≡ a₀₁} {a₁₀ a₁₁ : A} {a₁₋ : a₁₀ ≡ a₁₁}
{a₋₀ : a₀₀ ≡ a₁₀} {a₋₁ : a₀₁ ≡ a₁₁}
where
flipSquareEquiv : Square a₀₋ a₁₋ a₋₀ a₋₁ ≃ Square a₋₀ a₋₁ a₀₋ a₁₋
unquoteDef flipSquareEquiv = defStrictEquiv flipSquareEquiv flipSquare flipSquare
flipSquarePath : Square a₀₋ a₁₋ a₋₀ a₋₁ ≡ Square a₋₀ a₋₁ a₀₋ a₁₋
flipSquarePath = ua flipSquareEquiv
module _ {a₀₀ a₁₁ : A} {a₋ : a₀₀ ≡ a₁₁}
{a₁₀ : A} {a₁₋ : a₁₀ ≡ a₁₁} {a₋₀ : a₀₀ ≡ a₁₀} where
slideSquareFaces : (i j k : I) → Partial (i ∨ ~ i ∨ j ∨ ~ j) A
slideSquareFaces i j k (i = i0) = a₋ (j ∧ ~ k)
slideSquareFaces i j k (i = i1) = a₁₋ j
slideSquareFaces i j k (j = i0) = a₋₀ i
slideSquareFaces i j k (j = i1) = a₋ (i ∨ ~ k)
slideSquare : Square a₋ a₁₋ a₋₀ refl → Square refl a₁₋ a₋₀ a₋
slideSquare sq i j = hcomp (slideSquareFaces i j) (sq i j)
slideSquareEquiv : (Square a₋ a₁₋ a₋₀ refl) ≃ (Square refl a₁₋ a₋₀ a₋)
slideSquareEquiv = isoToEquiv (iso slideSquare slideSquareInv fillerTo fillerFrom) where
slideSquareInv : Square refl a₁₋ a₋₀ a₋ → Square a₋ a₁₋ a₋₀ refl
slideSquareInv sq i j = hcomp (λ k → slideSquareFaces i j (~ k)) (sq i j)
fillerTo : ∀ p → slideSquare (slideSquareInv p) ≡ p
fillerTo p k i j = hcomp-equivFiller (λ k → slideSquareFaces i j (~ k)) (inS (p i j)) (~ k)
fillerFrom : ∀ p → slideSquareInv (slideSquare p) ≡ p
fillerFrom p k i j = hcomp-equivFiller (slideSquareFaces i j) (inS (p i j)) (~ k)
-- The type of fillers of a square is equivalent to the double composition identites
Square≃doubleComp : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(a₀₋ : a₀₀ ≡ a₀₁) (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Square a₀₋ a₁₋ a₋₀ a₋₁ ≃ (a₋₀ ⁻¹ ∙∙ a₀₋ ∙∙ a₋₁ ≡ a₁₋)
Square≃doubleComp a₀₋ a₁₋ a₋₀ a₋₁ = transportEquiv (PathP≡doubleCompPathˡ a₋₀ a₀₋ a₁₋ a₋₁)
-- Flipping a square in Ω²A is the same as inverting it
sym≡flipSquare : {x : A} (P : Square (refl {x = x}) refl refl refl)
→ sym P ≡ flipSquare P
sym≡flipSquare {x = x} P = sym (main refl P)
where
B : (q : x ≡ x) → I → Type _
B q i = PathP (λ j → x ≡ q (i ∨ j)) (λ k → q (i ∧ k)) refl
main : (q : x ≡ x) (p : refl ≡ q) → PathP (λ i → B q i) (λ i j → p j i) (sym p)
main q = J (λ q p → PathP (λ i → B q i) (λ i j → p j i) (sym p)) refl
-- Inverting both interval arguments of a square in Ω²A is the same as doing nothing
sym-cong-sym≡id : {x : A} (P : Square (refl {x = x}) refl refl refl)
→ P ≡ λ i j → P (~ i) (~ j)
sym-cong-sym≡id {x = x} P = sym (main refl P)
where
B : (q : x ≡ x) → I → Type _
B q i = Path (x ≡ q i) (λ j → q (i ∨ ~ j)) λ j → q (i ∧ j)
main : (q : x ≡ x) (p : refl ≡ q) → PathP (λ i → B q i) (λ i j → p (~ i) (~ j)) p
main q = J (λ q p → PathP (λ i → B q i) (λ i j → p (~ i) (~ j)) p) refl
-- Applying cong sym is the same as flipping a square in Ω²A
flipSquare≡cong-sym : ∀ {ℓ} {A : Type ℓ} {x : A} (P : Square (refl {x = x}) refl refl refl)
→ flipSquare P ≡ λ i j → P i (~ j)
flipSquare≡cong-sym P = sym (sym≡flipSquare P) ∙ sym (sym-cong-sym≡id (cong sym P))
-- Applying cong sym is the same as inverting a square in Ω²A
sym≡cong-sym : ∀ {ℓ} {A : Type ℓ} {x : A} (P : Square (refl {x = x}) refl refl refl)
→ sym P ≡ cong sym P
sym≡cong-sym P = sym-cong-sym≡id (sym P)
-- sym induces an equivalence on identity types of paths
symIso : {a b : A} (p q : a ≡ b) → Iso (p ≡ q) (q ≡ p)
symIso p q = iso sym sym (λ _ → refl) λ _ → refl
-- J is an equivalence
Jequiv : {x : A} (P : ∀ y → x ≡ y → Type ℓ') → P x refl ≃ (∀ {y} (p : x ≡ y) → P y p)
Jequiv P = isoToEquiv isom
where
isom : Iso _ _
Iso.fun isom = J P
Iso.inv isom f = f refl
Iso.rightInv isom f =
implicitFunExt λ {_} →
funExt λ t →
J (λ _ t → J P (f refl) t ≡ f t) (JRefl P (f refl)) t
Iso.leftInv isom = JRefl P
-- Action of PathP on equivalences (without relying on univalence)
congPathIso : ∀ {ℓ ℓ'} {A : I → Type ℓ} {B : I → Type ℓ'}
(e : ∀ i → A i ≃ B i) {a₀ : A i0} {a₁ : A i1}
→ Iso (PathP A a₀ a₁) (PathP B (e i0 .fst a₀) (e i1 .fst a₁))
congPathIso {A = A} {B} e {a₀} {a₁} .Iso.fun p i = e i .fst (p i)
congPathIso {A = A} {B} e {a₀} {a₁} .Iso.inv q i =
hcomp
(λ j → λ
{ (i = i0) → retEq (e i0) a₀ j
; (i = i1) → retEq (e i1) a₁ j
})
(invEq (e i) (q i))
congPathIso {A = A} {B} e {a₀} {a₁} .Iso.rightInv q k i =
hcomp
(λ j → λ
{ (i = i0) → commSqIsEq (e i0 .snd) a₀ j k
; (i = i1) → commSqIsEq (e i1 .snd) a₁ j k
; (k = i0) →
e i .fst
(hfill
(λ j → λ
{ (i = i0) → retEq (e i0) a₀ j
; (i = i1) → retEq (e i1) a₁ j
})
(inS (invEq (e i) (q i)))
j)
; (k = i1) → q i
})
(secEq (e i) (q i) k)
where b = commSqIsEq
congPathIso {A = A} {B} e {a₀} {a₁} .Iso.leftInv p k i =
hcomp
(λ j → λ
{ (i = i0) → retEq (e i0) a₀ (j ∨ k)
; (i = i1) → retEq (e i1) a₁ (j ∨ k)
; (k = i1) → p i
})
(retEq (e i) (p i) k)
congPathEquiv : ∀ {ℓ ℓ'} {A : I → Type ℓ} {B : I → Type ℓ'}
(e : ∀ i → A i ≃ B i) {a₀ : A i0} {a₁ : A i1}
→ PathP A a₀ a₁ ≃ PathP B (e i0 .fst a₀) (e i1 .fst a₁)
congPathEquiv e = isoToEquiv (congPathIso e)
-- Characterizations of dependent paths in path types
doubleCompPath-filler∙ : {a b c d : A} (p : a ≡ b) (q : b ≡ c) (r : c ≡ d)
→ PathP (λ i → p i ≡ r (~ i)) (p ∙ q ∙ r) q
doubleCompPath-filler∙ {A = A} {b = b} p q r j i =
hcomp (λ k → λ { (i = i0) → p j
; (i = i1) → side j k
; (j = i1) → q (i ∧ k)})
(p (j ∨ i))
where
side : I → I → A
side i j =
hcomp (λ k → λ { (i = i1) → q j
; (j = i0) → b
; (j = i1) → r (~ i ∧ k)})
(q j)
PathP→compPathL : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ PathP (λ i → p i ≡ q i) r s
→ sym p ∙ r ∙ q ≡ s
PathP→compPathL {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (j ∨ k)
; (i = i1) → q (j ∨ k)
; (j = i0) → doubleCompPath-filler∙ (sym p) r q (~ k) i
; (j = i1) → s i })
(P j i)
PathP→compPathR : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ PathP (λ i → p i ≡ q i) r s
→ r ≡ p ∙ s ∙ sym q
PathP→compPathR {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (j ∧ (~ k))
; (i = i1) → q (j ∧ (~ k))
; (j = i0) → r i
; (j = i1) → doubleCompPath-filler∙ p s (sym q) (~ k) i})
(P j i)
-- Other direction
compPathL→PathP : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ sym p ∙ r ∙ q ≡ s
→ PathP (λ i → p i ≡ q i) r s
compPathL→PathP {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (~ k ∨ j)
; (i = i1) → q (~ k ∨ j)
; (j = i0) → doubleCompPath-filler∙ (sym p) r q k i
; (j = i1) → s i})
(P j i)
compPathR→PathP : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ r ≡ p ∙ s ∙ sym q
→ PathP (λ i → p i ≡ q i) r s
compPathR→PathP {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (k ∧ j)
; (i = i1) → q (k ∧ j)
; (j = i0) → r i
; (j = i1) → doubleCompPath-filler∙ p s (sym q) k i})
(P j i)
compPathR→PathP∙∙ : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ r ≡ p ∙∙ s ∙∙ sym q
→ PathP (λ i → p i ≡ q i) r s
compPathR→PathP∙∙ {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (k ∧ j)
; (i = i1) → q (k ∧ j)
; (j = i0) → r i
; (j = i1) → doubleCompPath-filler p s (sym q) (~ k) i})
(P j i)
| {
"alphanum_fraction": 0.4704479769,
"avg_line_length": 39.0960451977,
"ext": "agda",
"hexsha": "4452fc272ab25adf0dc90d9c84534746205d9560",
"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": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lpw25/cubical",
"max_forks_repo_path": "Cubical/Foundations/Path.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"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": "lpw25/cubical",
"max_issues_repo_path": "Cubical/Foundations/Path.agda",
"max_line_length": 106,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lpw25/cubical",
"max_stars_repo_path": "Cubical/Foundations/Path.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6299,
"size": 13840
} |
{- 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.ConsensusTypes.VoteData as VoteData
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import Optics.All
open import Util.Prelude
module LibraBFT.Impl.Consensus.ConsensusTypes.Properties.VoteData (self : VoteData) where
record Contract : Set where
field
ep≡ : self ^∙ vdParent ∙ biEpoch ≡ self ^∙ vdProposed ∙ biEpoch
parRnd< : self ^∙ vdParent ∙ biRound < self ^∙ vdProposed ∙ biRound
parVer≤ : (self ^∙ vdParent ∙ biVersion) ≤-Version (self ^∙ vdProposed ∙ biVersion)
open Contract
contract
: VoteData.verify self ≡ Right unit → Contract
contract
with self ^∙ vdParent ∙ biEpoch ≟ self ^∙ vdProposed ∙ biEpoch
...| no neq = (λ ())
...| yes refl
with self ^∙ vdParent ∙ biRound <? self ^∙ vdProposed ∙ biRound
...| no ¬par<prop = (λ ())
...| yes par<prop
with (self ^∙ vdParent ∙ biVersion) ≤?-Version (self ^∙ vdProposed ∙ biVersion)
...| no ¬parVer≤ = (λ ())
...| yes parVer≤ = (λ x → record { ep≡ = refl
; parRnd< = par<prop
; parVer≤ = parVer≤ })
| {
"alphanum_fraction": 0.6450276243,
"avg_line_length": 39.1351351351,
"ext": "agda",
"hexsha": "5148309671b472f9bd940ad8b8c7aca957237033",
"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/ConsensusTypes/Properties/VoteData.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/ConsensusTypes/Properties/VoteData.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/ConsensusTypes/Properties/VoteData.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 450,
"size": 1448
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Groups.Definition
open import Sets.EquivalenceRelations
module Groups.Groups where
reflGroupWellDefined : {lvl : _} {A : Set lvl} {m n x y : A} {op : A → A → A} → m ≡ x → n ≡ y → (op m n) ≡ (op x y)
reflGroupWellDefined {lvl} {A} {m} {n} {.m} {.n} {op} refl refl = refl
fourWay+Associative : {a b : _} → {A : Set a} → {S : Setoid {a} {b} A} → {_·_ : A → A → A} → (G : Group S _·_) → {r s t u : A} → (Setoid._∼_ S) (r · ((s · t) · u)) ((r · s) · (t · u))
fourWay+Associative {S = S} {_·_} G {r} {s} {t} {u} = transitive p1 (transitive p2 p3)
where
open Group G renaming (inverse to _^-1)
open Setoid S
open Equivalence eq
p1 : r · ((s · t) · u) ∼ (r · (s · t)) · u
p2 : (r · (s · t)) · u ∼ ((r · s) · t) · u
p3 : ((r · s) · t) · u ∼ (r · s) · (t · u)
p1 = Group.+Associative G
p2 = Group.+WellDefined G (Group.+Associative G) reflexive
p3 = symmetric (Group.+Associative G)
fourWay+Associative' : {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_·_ : A → A → A} (G : Group S _·_) {a b c d : A} → (Setoid._∼_ S (((a · b) · c) · d) (a · ((b · c) · d)))
fourWay+Associative' {S = S} G = transitive (symmetric +Associative) (symmetric (fourWay+Associative G))
where
open Group G
open Setoid S
open Equivalence eq
fourWay+Associative'' : {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_·_ : A → A → A} (G : Group S _·_) {a b c d : A} → (Setoid._∼_ S (a · (b · (c · d))) (a · ((b · c) · d)))
fourWay+Associative'' {S = S} {_·_ = _·_} G = transitive +Associative (symmetric (fourWay+Associative G))
where
open Group G
open Setoid S
open Equivalence eq
| {
"alphanum_fraction": 0.5488157135,
"avg_line_length": 45.5526315789,
"ext": "agda",
"hexsha": "34d5f2708262349bb2ec6938bd7ff357927f5f20",
"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": "Groups/Groups.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": "Groups/Groups.agda",
"max_line_length": 183,
"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": "Groups/Groups.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": 703,
"size": 1731
} |
module Punctaffy.Hypersnippet.Dim where
open import Level using (Level; suc; _⊔_)
open import Algebra.Bundles using (IdempotentCommutativeMonoid)
open import Algebra.Morphism using (IsIdempotentCommutativeMonoidMorphism)
-- For all the purposes we have for it so far, a `DimSys` is a bounded
-- semilattice. The `agda-stdlib` library calls this an idempotent commutative
-- monoid.
record DimSys {n l : Level} : Set (suc (n ⊔ l)) where
field
dimIdempotentCommutativeMonoid : IdempotentCommutativeMonoid n l
open IdempotentCommutativeMonoid dimIdempotentCommutativeMonoid public
record DimSysMorphism {n₀ n₁ l₀ l₁ : Level} : Set (suc (n₀ ⊔ n₁ ⊔ l₀ ⊔ l₁)) where
field
From : DimSys {n₀} {l₀}
To : DimSys {n₁} {l₁}
private
module F = DimSys From
module T = DimSys To
field
morphDim : F.Carrier → T.Carrier
isIdempotentCommutativeMonoidMorphism :
IsIdempotentCommutativeMonoidMorphism F.dimIdempotentCommutativeMonoid T.dimIdempotentCommutativeMonoid morphDim
dimLte : {n l : Level} → {ds : DimSys {n} {l}} → DimSys.Carrier ds → DimSys.Carrier ds → Set l
dimLte {n} {l} {ds} a b = DimSys._≈_ ds (DimSys._∙_ ds a b) b
| {
"alphanum_fraction": 0.7362542955,
"avg_line_length": 36.375,
"ext": "agda",
"hexsha": "210619529f42c28a94de6efa1b5df1c1f6b3a439",
"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": "b5a981ce0158c3c8e1296da4a71e83de23ed52ef",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "lathe/punctaffy-for-racket",
"max_forks_repo_path": "notes/code-sketches/agda/src/Punctaffy/Hypersnippet/Dim.agda",
"max_issues_count": 13,
"max_issues_repo_head_hexsha": "2a958bf3987459e9197eb5963fe5107ea2e2e912",
"max_issues_repo_issues_event_max_datetime": "2022-03-06T14:40:21.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-03-12T03:11:01.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "rocketnia/lexmeta",
"max_issues_repo_path": "notes/code-sketches/agda/src/Punctaffy/Hypersnippet/Dim.agda",
"max_line_length": 118,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "2a958bf3987459e9197eb5963fe5107ea2e2e912",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "rocketnia/lexmeta",
"max_stars_repo_path": "notes/code-sketches/agda/src/Punctaffy/Hypersnippet/Dim.agda",
"max_stars_repo_stars_event_max_datetime": "2020-02-03T21:26:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-03T21:26:07.000Z",
"num_tokens": 403,
"size": 1164
} |
{-# OPTIONS --without-K #-}
module equality.groupoid where
open import equality.core
_⁻¹ : ∀ {i}{X : Set i}{x y : X} → x ≡ y → y ≡ x
_⁻¹ = sym
left-unit : ∀ {i}{X : Set i}{x y : X}
→ (p : x ≡ y)
→ p · refl ≡ p
left-unit refl = refl
right-unit : ∀ {i}{X : Set i}{x y : X}
→ (p : x ≡ y)
→ refl · p ≡ p
right-unit refl = refl
associativity : ∀ {i}{X : Set i}{x y z w : X}
→ (p : x ≡ y)(q : y ≡ z)(r : z ≡ w)
→ p · q · r ≡ p · (q · r)
associativity refl _ _ = refl
left-inverse : ∀ {i}{X : Set i}{x y : X}
→ (p : x ≡ y)
→ p · p ⁻¹ ≡ refl
left-inverse refl = refl
right-inverse : ∀ {i}{X : Set i}{x y : X}
→ (p : x ≡ y)
→ p ⁻¹ · p ≡ refl
right-inverse refl = refl
| {
"alphanum_fraction": 0.4202531646,
"avg_line_length": 23.9393939394,
"ext": "agda",
"hexsha": "47e2c571a4f7793ab308f1c23eece55875e6aaa4",
"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/equality/groupoid.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/equality/groupoid.agda",
"max_line_length": 49,
"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": "equality/groupoid.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": 295,
"size": 790
} |
{-# OPTIONS --safe #-}
module Issue2250-2 where
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
data ⊥ : Set where
abstract
f : Bool → Bool
f x = true
{-# INJECTIVE f #-}
same : f true ≡ f false
same = refl
not-same : f true ≡ f false → ⊥
not-same ()
absurd : ⊥
absurd = not-same same
| {
"alphanum_fraction": 0.6332288401,
"avg_line_length": 13.2916666667,
"ext": "agda",
"hexsha": "ba6547349f81f014124e36499c97d26f70b587e2",
"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/Issue2250-2.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2250-2.agda",
"max_line_length": 33,
"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/Issue2250-2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 107,
"size": 319
} |
-- Andreas, 2011-05-09
-- {-# OPTIONS -v tc.meta:15 -v tc.inj:40 #-}
module Issue383 where
data D (A : Set) : A → Set where
data Unit : Set where
unit : Unit
D′ : (A : Set) → A → Unit → Set
D′ A x unit = D A x
postulate
Q : (A : Set) → A → Set
q : (u : Unit) (A : Set) (x : A) → D′ A x u → Q A x
A : Set
x : A
d : D A x
P : (A : Set) → A → Set
p : P (Q _ _) (q _ _ _ d)
-- SOLVED, WORKS NOW.
-- OLD BEHAVIOR:
-- Agda does not infer the values of the underscores on the last line.
-- Shouldn't constructor-headedness come to the rescue here? Agda does
-- identify D′ as being constructor-headed, and does invert D′ /six
-- times/, but still fails to infer that the third underscore should
-- be unit.
{-
blocked _41 := d
by [(D A x) =< (D′ _39 _40 _38) : Set]
blocked _42 := q _38 _36 _40 _41
by [_40 == _37 : _36]
-}
| {
"alphanum_fraction": 0.5828437133,
"avg_line_length": 22.3947368421,
"ext": "agda",
"hexsha": "04faed55407fc6c62aad51b1ad94ff81409828bd",
"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/Issue383.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/Issue383.agda",
"max_line_length": 70,
"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/Issue383.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": 312,
"size": 851
} |
{-# OPTIONS --without-K #-}
open import HoTT
import homotopy.HopfConstruction
open import homotopy.CircleHSpace
open import homotopy.SuspensionJoin using () renaming (e to suspension-join)
open import homotopy.S1SuspensionS0 using () renaming (e to S¹≃SuspensionS⁰)
import homotopy.JoinAssoc
module homotopy.Hopf where
-- To move
S⁰ = Bool
S² = Suspension S¹
S³ = Suspension S²
-- To move
S¹-connected : is-connected ⟨0⟩ S¹
S¹-connected =
([ base ] , Trunc-elim (λ x → =-preserves-level ⟨0⟩ Trunc-level)
(S¹-elim idp (prop-has-all-paths-↓ ((Trunc-level :> is-set (Trunc ⟨0⟩ S¹)) _ _))))
module Hopf = homotopy.HopfConstruction S¹ S¹-connected S¹-hSpace
Hopf : S² → Type₀
Hopf = Hopf.H.f
Hopf-fiber : Hopf (north _) == S¹
Hopf-fiber = idp
Hopf-total : Σ _ Hopf == S³
Hopf-total =
Σ _ Hopf =⟨ Hopf.theorem ⟩
S¹ * S¹ =⟨ ua S¹≃SuspensionS⁰ |in-ctx (λ u → u * S¹) ⟩
(Suspension S⁰) * S¹ =⟨ ua (suspension-join S⁰) |in-ctx (λ u → u * S¹) ⟩
(S⁰ * S⁰) * S¹ =⟨ ua (homotopy.JoinAssoc.*-assoc S⁰ S⁰ S¹) ⟩
S⁰ * (S⁰ * S¹) =⟨ ! (ua (suspension-join S¹)) |in-ctx (λ u → S⁰ * u) ⟩
S⁰ * S² =⟨ ! (ua (suspension-join S²)) ⟩
S³ ∎
| {
"alphanum_fraction": 0.617671346,
"avg_line_length": 30.275,
"ext": "agda",
"hexsha": "18636541a0d72e261485a1bbfa5ef4155be69f59",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "homotopy/Hopf.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "homotopy/Hopf.agda",
"max_line_length": 95,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "homotopy/Hopf.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 485,
"size": 1211
} |
{-# OPTIONS --rewriting #-}
open import Common.Prelude
open import Common.Equality
{-# BUILTIN REWRITE _≡_ #-}
postulate is-id : ∀ {A : Set} → (A → A) → Bool
postulate is-id-true : ∀ {A} → is-id {A} (λ x → x) ≡ true
{-# REWRITE is-id-true #-}
test₁ : is-id {Nat} (λ x → x) ≡ true
test₁ = refl
postulate is-const : ∀ {A : Set} → (A → A) → Bool
postulate is-const-true : ∀ {A} (x : A) → is-const (λ _ → x) ≡ true
{-# REWRITE is-const-true #-}
test₂ : is-const {Nat} (λ _ → 42) ≡ true
test₂ = refl
ap : {A B : Set} (f : A → B) {x y : A} →
x ≡ y → f x ≡ f y
ap f refl = refl
record _×_ (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
open _×_
{- Cartesian product -}
module _ {A B : Set} where
_,=_ : {a a' : A} (p : a ≡ a') {b b' : B} (q : b ≡ b') → (a , b) ≡ (a' , b')
refl ,= refl = refl
ap-,-l : (b : B) {a a' : A} (p : a ≡ a') →
ap (λ z → z , b) p ≡ (p ,= refl)
ap-,-l b refl = refl
{-# REWRITE ap-,-l #-}
test₃ : (b : B) {a a' : A} (p : a ≡ a') →
ap (λ z → z , b) p ≡ (p ,= refl)
test₃ _ _ = refl
ap-,-r : (a : A) {b b' : B} (p : b ≡ b') →
ap (λ z → a , z) p ≡ (refl ,= p)
ap-,-r a refl = refl
{-# REWRITE ap-,-r #-}
test₄ : (a : A) {b b' : B} (p : b ≡ b') →
ap (λ z → a , z) p ≡ (refl ,= p)
test₄ a _ = refl
ap-idf : {A : Set} {x y : A} (p : x ≡ y) → ap (λ x → x) p ≡ p
ap-idf refl = refl
{-# REWRITE ap-idf #-}
{- Function extensionality -}
module _ {A B : Set} {f g : A → B} where
postulate
funext : ((x : A) → f x ≡ g x) → f ≡ g
postulate
ap-app-funext : (a : A) (h : (x : A) → f x ≡ g x) →
ap (λ f → f a) (funext h) ≡ h a
{-# REWRITE ap-app-funext #-}
test₅ : (a : A) (h : (x : A) → f x ≡ g x) →
ap (λ f → f a) (funext h) ≡ h a
test₅ a h = refl
{- Dependent paths -}
module _ where
PathOver : {A : Set} (B : A → Set)
{x y : A} (p : x ≡ y) (u : B x) (v : B y) → Set
PathOver B refl u v = (u ≡ v)
postulate
PathOver-triv : {A B : Set} {x y : A} (p : x ≡ y) (u v : B) →
(PathOver (λ _ → B) p u v) ≡ (u ≡ v)
{-# REWRITE PathOver-triv #-}
test₆ : (p : 1 ≡ 1) → PathOver (λ _ → Nat) p 2 2
test₆ p = refl
| {
"alphanum_fraction": 0.4591836735,
"avg_line_length": 22.9361702128,
"ext": "agda",
"hexsha": "598d98bf11ae318e93dc49470be5fcd15ce3ff48",
"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/HigherOrderRewriting.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/HigherOrderRewriting.agda",
"max_line_length": 78,
"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/HigherOrderRewriting.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": 985,
"size": 2156
} |
module Numeral.Real where
open import Data.Tuple
open import Logic
import Lvl
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Rational
open import Numeral.Rational.Oper
open import Relator.Equals
open import Type
open import Type.Quotient
-- TODO: This will not work, but it is the standard concept at least. Maybe there is a better way
record CauchySequence (a : ℕ → ℚ) : Stmt where
field
N : ℚ₊ → ℕ
∀{ε : ℚ₊}{m n : ℕ} → (m > N(ε)) → (n > N(ε)) → (‖ a(m) − a(n) ‖ < ε)
_converges-to-same_ : Σ(CauchySequence) → Σ(CauchySequence) → Stmt{Lvl.𝟎}
a converges-to-same b = lim(n ↦ Σ.left(a) − Σ.left(b)) ≡ 𝟎
ℝ : Type{Lvl.𝟎}
ℝ = Σ(CauchySequence) / (_converges-to-same_)
-- TODO: Here is another idea: https://github.com/dylanede/cubical-experiments/blob/master/scratch.agda
-- TODO: Also these: https://en.wikipedia.org/wiki/Construction_of_the_real_numbers#Construction_from_Cauchy_sequences
| {
"alphanum_fraction": 0.7154989384,
"avg_line_length": 32.4827586207,
"ext": "agda",
"hexsha": "27d931f1845f86d669d03f0d042e133528bd2ddf",
"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/Mathematical/Numeral/Real.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/Mathematical/Numeral/Real.agda",
"max_line_length": 118,
"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/Mathematical/Numeral/Real.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": 323,
"size": 942
} |
------------------------------------------------------------------------------
-- The division program is correct
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module proves the correctness of the division program using
-- repeated subtraction (Dybjer 1985).
-- Peter Dybjer. Program verification in a logical theory of
-- constructions. In Jean-Pierre Jouannaud, editor. Functional
-- Programming Languages and Computer Architecture, volume 201 of
-- LNCS, 1985, pages 334-349. Appears in revised form as Programming
-- Methodology Group Report 26, June 1986.
module LTC-PCF.Program.Division.CorrectnessProof where
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Data.Nat.Inequalities.Properties
open import LTC-PCF.Data.Nat.Properties
import LTC-PCF.Data.Nat.Induction.NonAcc.WF
open module WFInd = LTC-PCF.Data.Nat.Induction.NonAcc.WF.WFInd
open import LTC-PCF.Program.Division.Division
open import LTC-PCF.Program.Division.Specification
open import LTC-PCF.Program.Division.Result
open import LTC-PCF.Program.Division.Totality
------------------------------------------------------------------------------
-- The division program is correct when the dividend is less than the
-- divisor.
div-x<y-correct : ∀ {i j} → N i → N j → i < j → divSpec i j (div i j)
div-x<y-correct Ni Nj i<j = div-x<y-N i<j , div-x<y-resultCorrect Ni Nj i<j
-- The division program is correct when the dividend is greater or
-- equal than the divisor.
div-x≮y-correct : ∀ {i j} → N i → N j →
(∀ {i'} → N i' → i' < i → divSpec i' j (div i' j)) →
j > zero →
i ≮ j →
divSpec i j (div i j)
div-x≮y-correct {i} {j} Ni Nj ah j>0 i≮j =
div-x≮y-N ih i≮j , div-x≮y-resultCorrect Ni Nj ih i≮j
where
-- The inductive hypothesis on i ∸ j.
ih : divSpec (i ∸ j) j (div (i ∸ j) j)
ih = ah {i ∸ j}
(∸-N Ni Nj)
(x≥y→y>0→x∸y<x Ni Nj (x≮y→x≥y Ni Nj i≮j) j>0)
------------------------------------------------------------------------------
-- The division program is correct.
-- We do the well-founded induction on i and we keep j fixed.
divCorrect : ∀ {i j} → N i → N j → j > zero → divSpec i j (div i j)
divCorrect {j = j} Ni Nj j>0 = <-wfind A ih Ni
where
A : D → Set
A d = divSpec d j (div d j)
-- The inductive step doesn't use the variable i (nor Ni). To make
-- this clear we write down the inductive step using the variables m
-- and n.
ih : ∀ {n} → N n → (∀ {m} → N m → m < n → A m) → A n
ih {n} Nn ah =
case (div-x<y-correct Nn Nj) (div-x≮y-correct Nn Nj ah j>0) (x<y∨x≮y Nn Nj)
| {
"alphanum_fraction": 0.5692844677,
"avg_line_length": 38.7162162162,
"ext": "agda",
"hexsha": "071251e99514273adc7e97d72a6dde1c4f53fe9f",
"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/LTC-PCF/Program/Division/CorrectnessProof.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/LTC-PCF/Program/Division/CorrectnessProof.agda",
"max_line_length": 80,
"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/LTC-PCF/Program/Division/CorrectnessProof.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": 839,
"size": 2865
} |
module Data.Num.Bij.Properties where
open import Data.Num.Bij renaming (_+B_ to _+_; _*B_ to _*_)
open import Data.List
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong; sym; trans)
open PropEq.≡-Reasoning
--------------------------------------------------------------------------------
1∷≡incrB∘*2 : ∀ m → one ∷ m ≡ incrB (*2 m)
1∷≡incrB∘*2 [] = refl
1∷≡incrB∘*2 (one ∷ ms) = cong (λ x → one ∷ x) (1∷≡incrB∘*2 ms)
1∷≡incrB∘*2 (two ∷ ms) = cong (λ x → one ∷ incrB x) (1∷≡incrB∘*2 ms)
split-∷ : ∀ m ms → m ∷ ms ≡ (m ∷ []) + *2 ms
split-∷ m [] = refl
split-∷ one (one ∷ ns) = cong (λ x → one ∷ x) (1∷≡incrB∘*2 ns)
split-∷ one (two ∷ ns) = cong (λ x → one ∷ incrB x) (1∷≡incrB∘*2 ns)
split-∷ two (one ∷ ns) = cong (λ x → two ∷ x) (1∷≡incrB∘*2 ns)
split-∷ two (two ∷ ns) = cong (λ x → two ∷ incrB x) (1∷≡incrB∘*2 ns)
{-
+B-assoc : ∀ m n o → (m + n) + o ≡ m + (n + o)
+B-assoc [] _ _ = refl
+B-assoc (m ∷ ms) n o =
begin
(m ∷ ms) + n + o
≡⟨ cong (λ x → x + n + o) (split-∷ m ms) ⟩
(m ∷ []) + *2 ms + n + o
≡⟨ cong (λ x → x + o) (+B-assoc (m ∷ []) (*2 ms) n) ⟩
(m ∷ []) + (*2 ms + n) + o
≡⟨ +B-assoc (m ∷ []) (*2 ms + n) o ⟩
(m ∷ []) + ((*2 ms + n) + o)
≡⟨ cong (λ x → (m ∷ []) + x) (+B-assoc (*2 ms) n o) ⟩
(m ∷ []) + (*2 ms + (n + o))
≡⟨ sym (+B-assoc (m ∷ []) (*2 ms) (n + o)) ⟩
(m ∷ []) + *2 ms + (n + o)
≡⟨ cong (λ x → x + (n + o)) (sym (split-∷ m ms)) ⟩
(m ∷ ms) + (n + o)
∎
+B-right-identity : ∀ n → n + [] ≡ n
+B-right-identity [] = refl
+B-right-identity (n ∷ ns) = refl
+B-comm : ∀ m n → m + n ≡ n + m
+B-comm [] n = sym (+B-right-identity n)
+B-comm (m ∷ ms) n =
begin
(m ∷ ms) + n
≡⟨ cong (λ x → x + n) (split-∷ m ms) ⟩
(m ∷ []) + *2 ms + n
≡⟨ +B-comm ((m ∷ []) + *2 ms) n ⟩
n + ((m ∷ []) + *2 ms)
≡⟨ cong (λ x → n + x) (sym (split-∷ m ms)) ⟩
n + (m ∷ ms)
∎
{-
begin
(m ∷ ms) + n
≡⟨ cong (λ x → x + n) (split-∷ m ms) ⟩
(m ∷ []) + *2 ms + n
≡⟨ +B-assoc (m ∷ []) (*2 ms) n ⟩
(m ∷ []) + (*2 ms + n)
≡⟨ cong (λ x → (m ∷ []) + x) (+B-comm (*2 ms) n) ⟩
(m ∷ []) + (n + *2 ms)
≡⟨ sym (+B-assoc (m ∷ []) n (*2 ms)) ⟩
(m ∷ []) + n + *2 ms
≡⟨ cong (λ x → x + *2 ms) (+B-comm (m ∷ []) n) ⟩
n + (m ∷ []) + *2 ms
≡⟨ +B-assoc n (m ∷ []) (*2 ms) ⟩
n + ((m ∷ []) + *2 ms)
≡⟨ cong (λ x → n + x) (sym (split-∷ m ms)) ⟩
n + (m ∷ ms)
∎
-}
+B-*2-distrib : ∀ m n → *2 (m + n) ≡ *2 m + *2 n
+B-*2-distrib [] n = refl
+B-*2-distrib (m ∷ ms) n =
begin
*2 ((m ∷ ms) + n)
≡⟨ cong (λ x → *2 (x + n)) (split-∷ m ms) ⟩
*2 ((m ∷ []) + *2 ms + n)
≡⟨ +B-*2-distrib ((m ∷ []) + *2 ms) n ⟩
*2 ((m ∷ []) + *2 ms) + *2 n
≡⟨ cong (λ x → *2 x + *2 n) (sym (split-∷ m ms)) ⟩
*2 (m ∷ ms) + *2 n
∎
+B-*B-incrB : ∀ m n → m * incrB n ≡ m + m * n
+B-*B-incrB [] n = refl
+B-*B-incrB (m ∷ ms) n =
begin
(m ∷ ms) * incrB n
≡⟨ cong (λ x → x * incrB n) (split-∷ m ms) ⟩
((m ∷ []) + *2 ms) * incrB n
≡⟨ +B-*B-incrB ((m ∷ []) + *2 ms) n ⟩
(m ∷ []) + *2 ms + ((m ∷ []) + *2 ms) * n
≡⟨ cong (λ x → x + x * n) (sym (split-∷ m ms)) ⟩
(m ∷ ms) + (m ∷ ms) * n
∎
*B-right-[] : ∀ n → n * [] ≡ []
*B-right-[] [] = refl
*B-right-[] (one ∷ ns) = cong *2_ (*B-right-[] ns)
*B-right-[] (two ∷ ns) = cong *2_ (*B-right-[] ns)
*B-+B-distrib : ∀ m n o → (n + o) * m ≡ n * m + o * m
*B-+B-distrib m [] o = refl
*B-+B-distrib m (n ∷ ns) o =
begin
((n ∷ ns) + o) * m
≡⟨ cong (λ x → (x + o) * m) (split-∷ n ns) ⟩
((n ∷ []) + *2 ns + o) * m
≡⟨ *B-+B-distrib m ((n ∷ []) + *2 ns) o ⟩
((n ∷ []) + *2 ns) * m + o * m
≡⟨ cong (λ x → x * m + o * m) (sym (split-∷ n ns)) ⟩
(n ∷ ns) * m + o * m
∎
*B-comm : ∀ m n → m * n ≡ n * m
*B-comm [] n = sym (*B-right-[] n)
*B-comm (m ∷ ms) n =
begin
(m ∷ ms) * n
≡⟨ cong (λ x → x * n) (split-∷ m ms) ⟩
((m ∷ []) + *2 ms) * n
≡⟨ *B-comm ((m ∷ []) + *2 ms) n ⟩
n * ((m ∷ []) + *2 ms)
≡⟨ cong (λ x → n * x) (sym (split-∷ m ms)) ⟩
n * (m ∷ ms)
∎
{-
begin
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
∎
-}
{-
+B-*B-incrB : ∀ m n → m * incrB n ≡ m + m * n
+B-*B-incrB [] n = refl
+B-*B-incrB (one ∷ ms) [] = {! !}
+B-*B-incrB (one ∷ ms) (n ∷ ns) = {! !}
begin
incrB n + ms * incrB n
≡⟨ cong (λ x → incrB n + x) (+B-*B-incrB ms n) ⟩
incrB n + (ms + ms * n)
≡⟨ sym (+B-assoc (incrB n) ms (ms * n)) ⟩
incrB n + ms + ms * n
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
(one ∷ []) + *2 ms + (n + ms * n)
≡⟨ cong (λ x → x + (n + ms * n)) (sym (split-∷ one ms)) ⟩
(one ∷ ms) + (n + ms * n)
∎
+B-*B-incrB (two ∷ ms) n =
begin
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
∎
-}
{-
begin
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
≡⟨ {! !} ⟩
{! !}
∎
-}
-}
| {
"alphanum_fraction": 0.3166880852,
"avg_line_length": 27.3718592965,
"ext": "agda",
"hexsha": "b452b489522b11163a33bda4b216241f51c36cbd",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "legacy/Data/Num/Bij/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "legacy/Data/Num/Bij/Properties.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "legacy/Data/Num/Bij/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 2636,
"size": 5447
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.OrderedCommMonoid.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.SIP using (TypeWithStr)
open import Cubical.Data.Sigma
open import Cubical.Algebra.CommMonoid
open import Cubical.Algebra.OrderedCommMonoid.Base
open import Cubical.Relation.Binary.Poset
private
variable
ℓ ℓ' ℓ'' : Level
module _
(M : OrderedCommMonoid ℓ ℓ')
(P : ⟨ M ⟩ → hProp ℓ'')
where
open OrderedCommMonoidStr (snd M)
module _
(·Closed : (x y : ⟨ M ⟩) → ⟨ P x ⟩ → ⟨ P y ⟩ → ⟨ P (x · y) ⟩)
(εContained : ⟨ P ε ⟩)
where
private
subtype = Σ[ x ∈ ⟨ M ⟩ ] ⟨ P x ⟩
submonoid = makeSubCommMonoid (OrderedCommMonoid→CommMonoid M) P ·Closed εContained
_≤ₛ_ : (x y : ⟨ submonoid ⟩) → Type ℓ'
x ≤ₛ y = (fst x) ≤ (fst y)
pres≤ : (x y : ⟨ submonoid ⟩) (x≤y : x ≤ₛ y) → (fst x) ≤ (fst y)
pres≤ x y x≤y = x≤y
makeOrderedSubmonoid : OrderedCommMonoid _ ℓ'
fst makeOrderedSubmonoid = subtype
OrderedCommMonoidStr._≤_ (snd makeOrderedSubmonoid) = _≤ₛ_
OrderedCommMonoidStr._·_ (snd makeOrderedSubmonoid) = CommMonoidStr._·_ (snd submonoid)
OrderedCommMonoidStr.ε (snd makeOrderedSubmonoid) = CommMonoidStr.ε (snd submonoid)
OrderedCommMonoidStr.isOrderedCommMonoid (snd makeOrderedSubmonoid) =
IsOrderedCommMonoidFromIsCommMonoid
(CommMonoidStr.isCommMonoid (snd submonoid))
(λ x y → is-prop-valued (fst x) (fst y))
(λ x → is-refl (fst x))
(λ x y z → is-trans (fst x) (fst y) (fst z))
(λ x y x≤y y≤x
→ Σ≡Prop (λ x → snd (P x))
(is-antisym (fst x) (fst y) (pres≤ x y x≤y) (pres≤ y x y≤x)))
(λ x y z x≤y → MonotoneR (pres≤ x y x≤y))
λ x y z x≤y → MonotoneL (pres≤ x y x≤y)
| {
"alphanum_fraction": 0.6321353066,
"avg_line_length": 34.4,
"ext": "agda",
"hexsha": "208db81eb61a5219f9772b36a0c6ee2035db9c9d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/OrderedCommMonoid/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/OrderedCommMonoid/Properties.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/OrderedCommMonoid/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 689,
"size": 1892
} |
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v tc.conv.elim:100 #-}
module Issue814 where
record IsMonoid (M : Set) : Set where
field
unit : M
_*_ : M → M → M
record Monoid : Set₁ where
field
carrier : Set
is-mon : IsMonoid carrier
record Structure (Struct : Set₁)
(HasStruct : Set → Set)
(carrier : Struct → Set) : Set₁ where
field
has-struct : (X : Struct) → HasStruct (carrier X)
mon-mon-struct : Structure Monoid IsMonoid Monoid.carrier
mon-mon-struct = record
{ has-struct = Monoid.is-mon }
mon-mon-struct' : Structure Monoid IsMonoid Monoid.carrier
mon-mon-struct' = record
{ has-struct = Monoid.is-mon }
unit : {Struct : Set₁}{C : Struct → Set}
→ ⦃ X : Struct ⦄
→ ⦃ struct : Structure Struct IsMonoid C ⦄
→ C X
unit {Struct}{C} ⦃ X ⦄ ⦃ struct ⦄ = IsMonoid.unit (Structure.has-struct struct X)
f : (M : Monoid) → Monoid.carrier M
f M = unit
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Eliminators.hs:45
-- This used to crash, but should only produce unsolved metas.
| {
"alphanum_fraction": 0.6430446194,
"avg_line_length": 27.2142857143,
"ext": "agda",
"hexsha": "57ca5bb0a5b81ec370fcf63c260a83c6fb5a7048",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue814.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/Issue814.agda",
"max_line_length": 81,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue814.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": 356,
"size": 1143
} |
{-# OPTIONS --rewriting #-}
module Properties.Subtyping where
open import Agda.Builtin.Equality using (_≡_; refl)
open import FFI.Data.Either using (Either; Left; Right; mapLR; swapLR; cond)
open import FFI.Data.Maybe using (Maybe; just; nothing)
open import Luau.Subtyping using (_<:_; _≮:_; Tree; Language; ¬Language; witness; unknown; never; scalar; function; scalar-function; scalar-function-ok; scalar-function-err; scalar-function-tgt; scalar-scalar; function-scalar; function-ok; function-ok₁; function-ok₂; function-err; function-tgt; left; right; _,_)
open import Luau.Type using (Type; Scalar; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_; skalar)
open import Properties.Contradiction using (CONTRADICTION; ¬; ⊥)
open import Properties.Equality using (_≢_)
open import Properties.Functions using (_∘_)
open import Properties.Product using (_×_; _,_)
-- Language membership is decidable
dec-language : ∀ T t → Either (¬Language T t) (Language T t)
dec-language nil (scalar number) = Left (scalar-scalar number nil (λ ()))
dec-language nil (scalar boolean) = Left (scalar-scalar boolean nil (λ ()))
dec-language nil (scalar string) = Left (scalar-scalar string nil (λ ()))
dec-language nil (scalar nil) = Right (scalar nil)
dec-language nil function = Left (scalar-function nil)
dec-language nil (function-ok s t) = Left (scalar-function-ok nil)
dec-language nil (function-err t) = Left (scalar-function-err nil)
dec-language boolean (scalar number) = Left (scalar-scalar number boolean (λ ()))
dec-language boolean (scalar boolean) = Right (scalar boolean)
dec-language boolean (scalar string) = Left (scalar-scalar string boolean (λ ()))
dec-language boolean (scalar nil) = Left (scalar-scalar nil boolean (λ ()))
dec-language boolean function = Left (scalar-function boolean)
dec-language boolean (function-ok s t) = Left (scalar-function-ok boolean)
dec-language boolean (function-err t) = Left (scalar-function-err boolean)
dec-language number (scalar number) = Right (scalar number)
dec-language number (scalar boolean) = Left (scalar-scalar boolean number (λ ()))
dec-language number (scalar string) = Left (scalar-scalar string number (λ ()))
dec-language number (scalar nil) = Left (scalar-scalar nil number (λ ()))
dec-language number function = Left (scalar-function number)
dec-language number (function-ok s t) = Left (scalar-function-ok number)
dec-language number (function-err t) = Left (scalar-function-err number)
dec-language string (scalar number) = Left (scalar-scalar number string (λ ()))
dec-language string (scalar boolean) = Left (scalar-scalar boolean string (λ ()))
dec-language string (scalar string) = Right (scalar string)
dec-language string (scalar nil) = Left (scalar-scalar nil string (λ ()))
dec-language string function = Left (scalar-function string)
dec-language string (function-ok s t) = Left (scalar-function-ok string)
dec-language string (function-err t) = Left (scalar-function-err string)
dec-language (T₁ ⇒ T₂) (scalar s) = Left (function-scalar s)
dec-language (T₁ ⇒ T₂) function = Right function
dec-language (T₁ ⇒ T₂) (function-ok s t) = cond (Right ∘ function-ok₁) (λ p → mapLR (function-ok p) function-ok₂ (dec-language T₂ t)) (dec-language T₁ s)
dec-language (T₁ ⇒ T₂) (function-err t) = mapLR function-err function-err (swapLR (dec-language T₁ t))
dec-language never t = Left never
dec-language unknown t = Right unknown
dec-language (T₁ ∪ T₂) t = cond (λ p → cond (Left ∘ _,_ p) (Right ∘ right) (dec-language T₂ t)) (Right ∘ left) (dec-language T₁ t)
dec-language (T₁ ∩ T₂) t = cond (Left ∘ left) (λ p → cond (Left ∘ right) (Right ∘ _,_ p) (dec-language T₂ t)) (dec-language T₁ t)
dec-language nil (function-tgt t) = Left (scalar-function-tgt nil)
dec-language (T₁ ⇒ T₂) (function-tgt t) = mapLR function-tgt function-tgt (dec-language T₂ t)
dec-language boolean (function-tgt t) = Left (scalar-function-tgt boolean)
dec-language number (function-tgt t) = Left (scalar-function-tgt number)
dec-language string (function-tgt t) = Left (scalar-function-tgt string)
-- ¬Language T is the complement of Language T
language-comp : ∀ {T} t → ¬Language T t → ¬(Language T t)
language-comp t (p₁ , p₂) (left q) = language-comp t p₁ q
language-comp t (p₁ , p₂) (right q) = language-comp t p₂ q
language-comp t (left p) (q₁ , q₂) = language-comp t p q₁
language-comp t (right p) (q₁ , q₂) = language-comp t p q₂
language-comp (scalar s) (scalar-scalar s p₁ p₂) (scalar s) = p₂ refl
language-comp (scalar s) (function-scalar s) (scalar s) = language-comp function (scalar-function s) function
language-comp (scalar s) never (scalar ())
language-comp function (scalar-function ()) function
language-comp (function-ok s t) (scalar-function-ok ()) (function-ok₁ p)
language-comp (function-ok s t) (function-ok p₁ p₂) (function-ok₁ q) = language-comp s q p₁
language-comp (function-ok s t) (function-ok p₁ p₂) (function-ok₂ q) = language-comp t p₂ q
language-comp (function-err t) (function-err p) (function-err q) = language-comp t q p
language-comp (function-tgt t) (scalar-function-tgt ()) (function-tgt q)
language-comp (function-tgt t) (function-tgt p) (function-tgt q) = language-comp t p q
-- ≮: is the complement of <:
¬≮:-impl-<: : ∀ {T U} → ¬(T ≮: U) → (T <: U)
¬≮:-impl-<: {T} {U} p t q with dec-language U t
¬≮:-impl-<: {T} {U} p t q | Left r = CONTRADICTION (p (witness t q r))
¬≮:-impl-<: {T} {U} p t q | Right r = r
<:-impl-¬≮: : ∀ {T U} → (T <: U) → ¬(T ≮: U)
<:-impl-¬≮: p (witness t q r) = language-comp t r (p t q)
<:-impl-⊇ : ∀ {T U} → (T <: U) → ∀ t → ¬Language U t → ¬Language T t
<:-impl-⊇ {T} p t q with dec-language T t
<:-impl-⊇ {_} p t q | Left r = r
<:-impl-⊇ {_} p t q | Right r = CONTRADICTION (language-comp t q (p t r))
-- reflexivity
≮:-refl : ∀ {T} → ¬(T ≮: T)
≮:-refl (witness t p q) = language-comp t q p
<:-refl : ∀ {T} → (T <: T)
<:-refl = ¬≮:-impl-<: ≮:-refl
-- transititivity
≮:-trans-≡ : ∀ {S T U} → (S ≮: T) → (T ≡ U) → (S ≮: U)
≮:-trans-≡ p refl = p
<:-trans-≡ : ∀ {S T U} → (S <: T) → (T ≡ U) → (S <: U)
<:-trans-≡ p refl = p
≡-impl-<: : ∀ {T U} → (T ≡ U) → (T <: U)
≡-impl-<: refl = <:-refl
≡-trans-≮: : ∀ {S T U} → (S ≡ T) → (T ≮: U) → (S ≮: U)
≡-trans-≮: refl p = p
≡-trans-<: : ∀ {S T U} → (S ≡ T) → (T <: U) → (S <: U)
≡-trans-<: refl p = p
≮:-trans : ∀ {S T U} → (S ≮: U) → Either (S ≮: T) (T ≮: U)
≮:-trans {T = T} (witness t p q) = mapLR (witness t p) (λ z → witness t z q) (dec-language T t)
<:-trans : ∀ {S T U} → (S <: T) → (T <: U) → (S <: U)
<:-trans p q t r = q t (p t r)
<:-trans-≮: : ∀ {S T U} → (S <: T) → (S ≮: U) → (T ≮: U)
<:-trans-≮: p (witness t q r) = witness t (p t q) r
≮:-trans-<: : ∀ {S T U} → (S ≮: U) → (T <: U) → (S ≮: T)
≮:-trans-<: (witness t p q) r = witness t p (<:-impl-⊇ r t q)
-- Properties of union
<:-union : ∀ {R S T U} → (R <: T) → (S <: U) → ((R ∪ S) <: (T ∪ U))
<:-union p q t (left r) = left (p t r)
<:-union p q t (right r) = right (q t r)
<:-∪-left : ∀ {S T} → S <: (S ∪ T)
<:-∪-left t p = left p
<:-∪-right : ∀ {S T} → T <: (S ∪ T)
<:-∪-right t p = right p
<:-∪-lub : ∀ {S T U} → (S <: U) → (T <: U) → ((S ∪ T) <: U)
<:-∪-lub p q t (left r) = p t r
<:-∪-lub p q t (right r) = q t r
<:-∪-symm : ∀ {T U} → (T ∪ U) <: (U ∪ T)
<:-∪-symm t (left p) = right p
<:-∪-symm t (right p) = left p
<:-∪-assocl : ∀ {S T U} → (S ∪ (T ∪ U)) <: ((S ∪ T) ∪ U)
<:-∪-assocl t (left p) = left (left p)
<:-∪-assocl t (right (left p)) = left (right p)
<:-∪-assocl t (right (right p)) = right p
<:-∪-assocr : ∀ {S T U} → ((S ∪ T) ∪ U) <: (S ∪ (T ∪ U))
<:-∪-assocr t (left (left p)) = left p
<:-∪-assocr t (left (right p)) = right (left p)
<:-∪-assocr t (right p) = right (right p)
≮:-∪-left : ∀ {S T U} → (S ≮: U) → ((S ∪ T) ≮: U)
≮:-∪-left (witness t p q) = witness t (left p) q
≮:-∪-right : ∀ {S T U} → (T ≮: U) → ((S ∪ T) ≮: U)
≮:-∪-right (witness t p q) = witness t (right p) q
≮:-left-∪ : ∀ {S T U} → (S ≮: (T ∪ U)) → (S ≮: T)
≮:-left-∪ (witness t p (q₁ , q₂)) = witness t p q₁
≮:-right-∪ : ∀ {S T U} → (S ≮: (T ∪ U)) → (S ≮: U)
≮:-right-∪ (witness t p (q₁ , q₂)) = witness t p q₂
-- Properties of intersection
<:-intersect : ∀ {R S T U} → (R <: T) → (S <: U) → ((R ∩ S) <: (T ∩ U))
<:-intersect p q t (r₁ , r₂) = (p t r₁ , q t r₂)
<:-∩-left : ∀ {S T} → (S ∩ T) <: S
<:-∩-left t (p , _) = p
<:-∩-right : ∀ {S T} → (S ∩ T) <: T
<:-∩-right t (_ , p) = p
<:-∩-glb : ∀ {S T U} → (S <: T) → (S <: U) → (S <: (T ∩ U))
<:-∩-glb p q t r = (p t r , q t r)
<:-∩-symm : ∀ {T U} → (T ∩ U) <: (U ∩ T)
<:-∩-symm t (p₁ , p₂) = (p₂ , p₁)
<:-∩-assocl : ∀ {S T U} → (S ∩ (T ∩ U)) <: ((S ∩ T) ∩ U)
<:-∩-assocl t (p , (p₁ , p₂)) = (p , p₁) , p₂
<:-∩-assocr : ∀ {S T U} → ((S ∩ T) ∩ U) <: (S ∩ (T ∩ U))
<:-∩-assocr t ((p , p₁) , p₂) = p , (p₁ , p₂)
≮:-∩-left : ∀ {S T U} → (S ≮: T) → (S ≮: (T ∩ U))
≮:-∩-left (witness t p q) = witness t p (left q)
≮:-∩-right : ∀ {S T U} → (S ≮: U) → (S ≮: (T ∩ U))
≮:-∩-right (witness t p q) = witness t p (right q)
-- Distribution properties
<:-∩-distl-∪ : ∀ {S T U} → (S ∩ (T ∪ U)) <: ((S ∩ T) ∪ (S ∩ U))
<:-∩-distl-∪ t (p₁ , left p₂) = left (p₁ , p₂)
<:-∩-distl-∪ t (p₁ , right p₂) = right (p₁ , p₂)
∩-distl-∪-<: : ∀ {S T U} → ((S ∩ T) ∪ (S ∩ U)) <: (S ∩ (T ∪ U))
∩-distl-∪-<: t (left (p₁ , p₂)) = (p₁ , left p₂)
∩-distl-∪-<: t (right (p₁ , p₂)) = (p₁ , right p₂)
<:-∩-distr-∪ : ∀ {S T U} → ((S ∪ T) ∩ U) <: ((S ∩ U) ∪ (T ∩ U))
<:-∩-distr-∪ t (left p₁ , p₂) = left (p₁ , p₂)
<:-∩-distr-∪ t (right p₁ , p₂) = right (p₁ , p₂)
∩-distr-∪-<: : ∀ {S T U} → ((S ∩ U) ∪ (T ∩ U)) <: ((S ∪ T) ∩ U)
∩-distr-∪-<: t (left (p₁ , p₂)) = (left p₁ , p₂)
∩-distr-∪-<: t (right (p₁ , p₂)) = (right p₁ , p₂)
<:-∪-distl-∩ : ∀ {S T U} → (S ∪ (T ∩ U)) <: ((S ∪ T) ∩ (S ∪ U))
<:-∪-distl-∩ t (left p) = (left p , left p)
<:-∪-distl-∩ t (right (p₁ , p₂)) = (right p₁ , right p₂)
∪-distl-∩-<: : ∀ {S T U} → ((S ∪ T) ∩ (S ∪ U)) <: (S ∪ (T ∩ U))
∪-distl-∩-<: t (left p₁ , p₂) = left p₁
∪-distl-∩-<: t (right p₁ , left p₂) = left p₂
∪-distl-∩-<: t (right p₁ , right p₂) = right (p₁ , p₂)
<:-∪-distr-∩ : ∀ {S T U} → ((S ∩ T) ∪ U) <: ((S ∪ U) ∩ (T ∪ U))
<:-∪-distr-∩ t (left (p₁ , p₂)) = left p₁ , left p₂
<:-∪-distr-∩ t (right p) = (right p , right p)
∪-distr-∩-<: : ∀ {S T U} → ((S ∪ U) ∩ (T ∪ U)) <: ((S ∩ T) ∪ U)
∪-distr-∩-<: t (left p₁ , left p₂) = left (p₁ , p₂)
∪-distr-∩-<: t (left p₁ , right p₂) = right p₂
∪-distr-∩-<: t (right p₁ , p₂) = right p₁
∩-<:-∪ : ∀ {S T} → (S ∩ T) <: (S ∪ T)
∩-<:-∪ t (p , _) = left p
-- Properties of functions
<:-function : ∀ {R S T U} → (R <: S) → (T <: U) → (S ⇒ T) <: (R ⇒ U)
<:-function p q function function = function
<:-function p q (function-ok s t) (function-ok₁ r) = function-ok₁ (<:-impl-⊇ p s r)
<:-function p q (function-ok s t) (function-ok₂ r) = function-ok₂ (q t r)
<:-function p q (function-err s) (function-err r) = function-err (<:-impl-⊇ p s r)
<:-function p q (function-tgt t) (function-tgt r) = function-tgt (q t r)
<:-function-∩-∩ : ∀ {R S T U} → ((R ⇒ T) ∩ (S ⇒ U)) <: ((R ∩ S) ⇒ (T ∩ U))
<:-function-∩-∩ function (function , function) = function
<:-function-∩-∩ (function-ok s t) (function-ok₁ p , q) = function-ok₁ (left p)
<:-function-∩-∩ (function-ok s t) (function-ok₂ p , function-ok₁ q) = function-ok₁ (right q)
<:-function-∩-∩ (function-ok s t) (function-ok₂ p , function-ok₂ q) = function-ok₂ (p , q)
<:-function-∩-∩ (function-err s) (function-err p , q) = function-err (left p)
<:-function-∩-∩ (function-tgt s) (function-tgt p , function-tgt q) = function-tgt (p , q)
<:-function-∩-∪ : ∀ {R S T U} → ((R ⇒ T) ∩ (S ⇒ U)) <: ((R ∪ S) ⇒ (T ∪ U))
<:-function-∩-∪ function (function , function) = function
<:-function-∩-∪ (function-ok s t) (function-ok₁ p₁ , function-ok₁ p₂) = function-ok₁ (p₁ , p₂)
<:-function-∩-∪ (function-ok s t) (p₁ , function-ok₂ p₂) = function-ok₂ (right p₂)
<:-function-∩-∪ (function-ok s t) (function-ok₂ p₁ , p₂) = function-ok₂ (left p₁)
<:-function-∩-∪ (function-err s) (function-err p₁ , function-err q₂) = function-err (p₁ , q₂)
<:-function-∩-∪ (function-tgt t) (function-tgt p , q) = function-tgt (left p)
<:-function-∩ : ∀ {S T U} → ((S ⇒ T) ∩ (S ⇒ U)) <: (S ⇒ (T ∩ U))
<:-function-∩ function (function , function) = function
<:-function-∩ (function-ok s t) (p₁ , function-ok₁ p₂) = function-ok₁ p₂
<:-function-∩ (function-ok s t) (function-ok₁ p₁ , p₂) = function-ok₁ p₁
<:-function-∩ (function-ok s t) (function-ok₂ p₁ , function-ok₂ p₂) = function-ok₂ (p₁ , p₂)
<:-function-∩ (function-err s) (function-err p₁ , function-err p₂) = function-err p₂
<:-function-∩ (function-tgt t) (function-tgt p₁ , function-tgt p₂) = function-tgt (p₁ , p₂)
<:-function-∪ : ∀ {R S T U} → ((R ⇒ S) ∪ (T ⇒ U)) <: ((R ∩ T) ⇒ (S ∪ U))
<:-function-∪ function (left function) = function
<:-function-∪ (function-ok s t) (left (function-ok₁ p)) = function-ok₁ (left p)
<:-function-∪ (function-ok s t) (left (function-ok₂ p)) = function-ok₂ (left p)
<:-function-∪ (function-err s) (left (function-err p)) = function-err (left p)
<:-function-∪ (scalar s) (left (scalar ()))
<:-function-∪ function (right function) = function
<:-function-∪ (function-ok s t) (right (function-ok₁ p)) = function-ok₁ (right p)
<:-function-∪ (function-ok s t) (right (function-ok₂ p)) = function-ok₂ (right p)
<:-function-∪ (function-err s) (right (function-err x)) = function-err (right x)
<:-function-∪ (scalar s) (right (scalar ()))
<:-function-∪ (function-tgt t) (left (function-tgt p)) = function-tgt (left p)
<:-function-∪ (function-tgt t) (right (function-tgt p)) = function-tgt (right p)
<:-function-∪-∩ : ∀ {R S T U} → ((R ∩ S) ⇒ (T ∪ U)) <: ((R ⇒ T) ∪ (S ⇒ U))
<:-function-∪-∩ function function = left function
<:-function-∪-∩ (function-ok s t) (function-ok₁ (left p)) = left (function-ok₁ p)
<:-function-∪-∩ (function-ok s t) (function-ok₂ (left p)) = left (function-ok₂ p)
<:-function-∪-∩ (function-ok s t) (function-ok₁ (right p)) = right (function-ok₁ p)
<:-function-∪-∩ (function-ok s t) (function-ok₂ (right p)) = right (function-ok₂ p)
<:-function-∪-∩ (function-err s) (function-err (left p)) = left (function-err p)
<:-function-∪-∩ (function-err s) (function-err (right p)) = right (function-err p)
<:-function-∪-∩ (function-tgt t) (function-tgt (left p)) = left (function-tgt p)
<:-function-∪-∩ (function-tgt t) (function-tgt (right p)) = right (function-tgt p)
<:-function-left : ∀ {R S T U} → (S ⇒ T) <: (R ⇒ U) → (R <: S)
<:-function-left {R} {S} p s Rs with dec-language S s
<:-function-left p s Rs | Right Ss = Ss
<:-function-left p s Rs | Left ¬Ss with p (function-err s) (function-err ¬Ss)
<:-function-left p s Rs | Left ¬Ss | function-err ¬Rs = CONTRADICTION (language-comp s ¬Rs Rs)
<:-function-right : ∀ {R S T U} → (S ⇒ T) <: (R ⇒ U) → (T <: U)
<:-function-right p t Tt with p (function-tgt t) (function-tgt Tt)
<:-function-right p t Tt | function-tgt St = St
≮:-function-left : ∀ {R S T U} → (R ≮: S) → (S ⇒ T) ≮: (R ⇒ U)
≮:-function-left (witness t p q) = witness (function-err t) (function-err q) (function-err p)
≮:-function-right : ∀ {R S T U} → (T ≮: U) → (S ⇒ T) ≮: (R ⇒ U)
≮:-function-right (witness t p q) = witness (function-tgt t) (function-tgt p) (function-tgt q)
-- Properties of scalars
skalar-function-ok : ∀ {s t} → (¬Language skalar (function-ok s t))
skalar-function-ok = (scalar-function-ok number , (scalar-function-ok string , (scalar-function-ok nil , scalar-function-ok boolean)))
scalar-<: : ∀ {S T} → (s : Scalar S) → Language T (scalar s) → (S <: T)
scalar-<: number p (scalar number) (scalar number) = p
scalar-<: boolean p (scalar boolean) (scalar boolean) = p
scalar-<: string p (scalar string) (scalar string) = p
scalar-<: nil p (scalar nil) (scalar nil) = p
scalar-∩-function-<:-never : ∀ {S T U} → (Scalar S) → ((T ⇒ U) ∩ S) <: never
scalar-∩-function-<:-never number .(scalar number) (() , scalar number)
scalar-∩-function-<:-never boolean .(scalar boolean) (() , scalar boolean)
scalar-∩-function-<:-never string .(scalar string) (() , scalar string)
scalar-∩-function-<:-never nil .(scalar nil) (() , scalar nil)
function-≮:-scalar : ∀ {S T U} → (Scalar U) → ((S ⇒ T) ≮: U)
function-≮:-scalar s = witness function function (scalar-function s)
scalar-≮:-function : ∀ {S T U} → (Scalar U) → (U ≮: (S ⇒ T))
scalar-≮:-function s = witness (scalar s) (scalar s) (function-scalar s)
unknown-≮:-scalar : ∀ {U} → (Scalar U) → (unknown ≮: U)
unknown-≮:-scalar s = witness function unknown (scalar-function s)
scalar-≮:-never : ∀ {U} → (Scalar U) → (U ≮: never)
scalar-≮:-never s = witness (scalar s) (scalar s) never
scalar-≢-impl-≮: : ∀ {T U} → (Scalar T) → (Scalar U) → (T ≢ U) → (T ≮: U)
scalar-≢-impl-≮: s₁ s₂ p = witness (scalar s₁) (scalar s₁) (scalar-scalar s₁ s₂ p)
scalar-≢-∩-<:-never : ∀ {T U V} → (Scalar T) → (Scalar U) → (T ≢ U) → (T ∩ U) <: V
scalar-≢-∩-<:-never s t p u (scalar s₁ , scalar s₂) = CONTRADICTION (p refl)
skalar-scalar : ∀ {T} (s : Scalar T) → (Language skalar (scalar s))
skalar-scalar number = left (scalar number)
skalar-scalar boolean = right (right (right (scalar boolean)))
skalar-scalar string = right (left (scalar string))
skalar-scalar nil = right (right (left (scalar nil)))
-- Properties of unknown and never
unknown-≮: : ∀ {T U} → (T ≮: U) → (unknown ≮: U)
unknown-≮: (witness t p q) = witness t unknown q
never-≮: : ∀ {T U} → (T ≮: U) → (T ≮: never)
never-≮: (witness t p q) = witness t p never
unknown-≮:-never : (unknown ≮: never)
unknown-≮:-never = witness (scalar nil) unknown never
unknown-≮:-function : ∀ {S T} → (unknown ≮: (S ⇒ T))
unknown-≮:-function = witness (scalar nil) unknown (function-scalar nil)
function-≮:-never : ∀ {T U} → ((T ⇒ U) ≮: never)
function-≮:-never = witness function function never
<:-never : ∀ {T} → (never <: T)
<:-never t (scalar ())
≮:-never-left : ∀ {S T U} → (S <: (T ∪ U)) → (S ≮: T) → (S ∩ U) ≮: never
≮:-never-left p (witness t q₁ q₂) with p t q₁
≮:-never-left p (witness t q₁ q₂) | left r = CONTRADICTION (language-comp t q₂ r)
≮:-never-left p (witness t q₁ q₂) | right r = witness t (q₁ , r) never
≮:-never-right : ∀ {S T U} → (S <: (T ∪ U)) → (S ≮: U) → (S ∩ T) ≮: never
≮:-never-right p (witness t q₁ q₂) with p t q₁
≮:-never-right p (witness t q₁ q₂) | left r = witness t (q₁ , r) never
≮:-never-right p (witness t q₁ q₂) | right r = CONTRADICTION (language-comp t q₂ r)
<:-unknown : ∀ {T} → (T <: unknown)
<:-unknown t p = unknown
<:-everything : unknown <: ((never ⇒ unknown) ∪ skalar)
<:-everything (scalar s) p = right (skalar-scalar s)
<:-everything function p = left function
<:-everything (function-ok s t) p = left (function-ok₁ never)
<:-everything (function-err s) p = left (function-err never)
<:-everything (function-tgt t) p = left (function-tgt unknown)
-- A Gentle Introduction To Semantic Subtyping (https://www.cduce.org/papers/gentle.pdf)
-- defines a "set-theoretic" model (sec 2.5)
-- Unfortunately we don't quite have this property, due to uninhabited types,
-- for example (never -> T) is equivalent to (never -> U)
-- when types are interpreted as sets of syntactic values.
_⊆_ : ∀ {A : Set} → (A → Set) → (A → Set) → Set
(P ⊆ Q) = ∀ a → (P a) → (Q a)
_⊗_ : ∀ {A B : Set} → (A → Set) → (B → Set) → ((A × B) → Set)
(P ⊗ Q) (a , b) = (P a) × (Q b)
Comp : ∀ {A : Set} → (A → Set) → (A → Set)
Comp P a = ¬(P a)
Lift : ∀ {A : Set} → (A → Set) → (Maybe A → Set)
Lift P nothing = ⊥
Lift P (just a) = P a
set-theoretic-if : ∀ {S₁ T₁ S₂ T₂} →
-- This is the "if" part of being a set-theoretic model
-- though it uses the definition from Frisch's thesis
-- rather than from the Gentle Introduction. The difference
-- being the presence of Lift, (written D_Ω in Defn 4.2 of
-- https://www.cduce.org/papers/frisch_phd.pdf).
(Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂)) →
(∀ Q → Q ⊆ Comp((Language S₁) ⊗ Comp(Lift(Language T₁))) → Q ⊆ Comp((Language S₂) ⊗ Comp(Lift(Language T₂))))
set-theoretic-if {S₁} {T₁} {S₂} {T₂} p Q q (t , just u) Qtu (S₂t , ¬T₂u) = q (t , just u) Qtu (S₁t , ¬T₁u) where
S₁t : Language S₁ t
S₁t with dec-language S₁ t
S₁t | Left ¬S₁t with p (function-err t) (function-err ¬S₁t)
S₁t | Left ¬S₁t | function-err ¬S₂t = CONTRADICTION (language-comp t ¬S₂t S₂t)
S₁t | Right r = r
¬T₁u : ¬(Language T₁ u)
¬T₁u T₁u with p (function-ok t u) (function-ok₂ T₁u)
¬T₁u T₁u | function-ok₁ ¬S₂t = language-comp t ¬S₂t S₂t
¬T₁u T₁u | function-ok₂ T₂u = ¬T₂u T₂u
set-theoretic-if {S₁} {T₁} {S₂} {T₂} p Q q (t , nothing) Qt- (S₂t , _) = q (t , nothing) Qt- (S₁t , λ ()) where
S₁t : Language S₁ t
S₁t with dec-language S₁ t
S₁t | Left ¬S₁t with p (function-err t) (function-err ¬S₁t)
S₁t | Left ¬S₁t | function-err ¬S₂t = CONTRADICTION (language-comp t ¬S₂t S₂t)
S₁t | Right r = r
not-quite-set-theoretic-only-if : ∀ {S₁ T₁ S₂ T₂} →
-- We don't quite have that this is a set-theoretic model
-- it's only true when Language S₂ is inhabited
-- in particular it's not true when S₂ is never,
∀ s₂ → Language S₂ s₂ →
-- This is the "only if" part of being a set-theoretic model
(∀ Q → Q ⊆ Comp((Language S₁) ⊗ Comp(Lift(Language T₁))) → Q ⊆ Comp((Language S₂) ⊗ Comp(Lift(Language T₂)))) →
(Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂))
not-quite-set-theoretic-only-if {S₁} {T₁} {S₂} {T₂} s₂ S₂s₂ p = r where
Q : (Tree × Maybe Tree) → Set
Q (t , just u) = Either (¬Language S₁ t) (Language T₁ u)
Q (t , nothing) = ¬Language S₁ t
q : Q ⊆ Comp(Language S₁ ⊗ Comp(Lift(Language T₁)))
q (t , just u) (Left ¬S₁t) (S₁t , ¬T₁u) = language-comp t ¬S₁t S₁t
q (t , just u) (Right T₂u) (S₁t , ¬T₁u) = ¬T₁u T₂u
q (t , nothing) ¬S₁t (S₁t , _) = language-comp t ¬S₁t S₁t
r : Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂)
r function function = function
r (function-err s) (function-err ¬S₁s) with dec-language S₂ s
r (function-err s) (function-err ¬S₁s) | Left ¬S₂s = function-err ¬S₂s
r (function-err s) (function-err ¬S₁s) | Right S₂s = CONTRADICTION (p Q q (s , nothing) ¬S₁s (S₂s , λ ()))
r (function-ok s t) (function-ok₁ ¬S₁s) with dec-language S₂ s
r (function-ok s t) (function-ok₁ ¬S₁s) | Left ¬S₂s = function-ok₁ ¬S₂s
r (function-ok s t) (function-ok₁ ¬S₁s) | Right S₂s = CONTRADICTION (p Q q (s , nothing) ¬S₁s (S₂s , λ ()))
r (function-ok s t) (function-ok₂ T₁t) with dec-language T₂ t
r (function-ok s t) (function-ok₂ T₁t) | Left ¬T₂t with dec-language S₂ s
r (function-ok s t) (function-ok₂ T₁t) | Left ¬T₂t | Left ¬S₂s = function-ok₁ ¬S₂s
r (function-ok s t) (function-ok₂ T₁t) | Left ¬T₂t | Right S₂s = CONTRADICTION (p Q q (s , just t) (Right T₁t) (S₂s , language-comp t ¬T₂t))
r (function-ok s t) (function-ok₂ T₁t) | Right T₂t = function-ok₂ T₂t
r (function-tgt t) (function-tgt T₁t) with dec-language T₂ t
r (function-tgt t) (function-tgt T₁t) | Left ¬T₂t = CONTRADICTION (p Q q (s₂ , just t) (Right T₁t) (S₂s₂ , language-comp t ¬T₂t))
r (function-tgt t) (function-tgt T₁t) | Right T₂t = function-tgt T₂t
-- A counterexample when the argument type is empty.
set-theoretic-counterexample-one : (∀ Q → Q ⊆ Comp((Language never) ⊗ Comp(Lift(Language number))) → Q ⊆ Comp((Language never) ⊗ Comp(Lift(Language string))))
set-theoretic-counterexample-one Q q ((scalar s) , u) Qtu (scalar () , p)
set-theoretic-counterexample-two : (never ⇒ number) ≮: (never ⇒ string)
set-theoretic-counterexample-two = witness (function-tgt (scalar number)) (function-tgt (scalar number)) (function-tgt (scalar-scalar number string (λ ())))
| {
"alphanum_fraction": 0.5928347168,
"avg_line_length": 48.2385892116,
"ext": "agda",
"hexsha": "73bf0e9a9dc21aceccc0666dc248a50f7bcd2509",
"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": "39fbd2146a379fb0878369b48764cd7e8772c0fb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sthagen/Roblox-luau",
"max_forks_repo_path": "prototyping/Properties/Subtyping.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "39fbd2146a379fb0878369b48764cd7e8772c0fb",
"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": "sthagen/Roblox-luau",
"max_issues_repo_path": "prototyping/Properties/Subtyping.agda",
"max_line_length": 313,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f1b46f4b967f11fabe666da1de0e71b225368260",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Libertus-Lab/luau",
"max_stars_repo_path": "prototyping/Properties/Subtyping.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-06T08:03:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-06T08:03:00.000Z",
"num_tokens": 9221,
"size": 23251
} |
open import Nat
open import Prelude
open import List
open import core
open import judgemental-erase
module moveerase where
-- type actions don't change the term other than moving the cursor
-- around
moveeraset : {t t' : τ̂} {δ : direction} →
(t + move δ +> t') →
(t ◆t) == (t' ◆t)
moveeraset TMArrChild1 = refl
moveeraset TMArrChild2 = refl
moveeraset TMArrParent1 = refl
moveeraset TMArrParent2 = refl
moveeraset (TMArrZip1 {t2 = t2} m) = ap1 (λ x → x ==> t2) (moveeraset m)
moveeraset (TMArrZip2 {t1 = t1} m) = ap1 (λ x → t1 ==> x) (moveeraset m)
-- the actual movements don't change the erasure
moveerase : {e e' : ê} {δ : direction} →
(e + move δ +>e e') →
(e ◆e) == (e' ◆e)
moveerase EMAscChild1 = refl
moveerase EMAscChild2 = refl
moveerase EMAscParent1 = refl
moveerase EMAscParent2 = refl
moveerase EMLamChild1 = refl
moveerase EMLamParent = refl
moveerase EMPlusChild1 = refl
moveerase EMPlusChild2 = refl
moveerase EMPlusParent1 = refl
moveerase EMPlusParent2 = refl
moveerase EMApChild1 = refl
moveerase EMApChild2 = refl
moveerase EMApParent1 = refl
moveerase EMApParent2 = refl
moveerase EMNEHoleChild1 = refl
moveerase EMNEHoleParent = refl
-- this form is essentially the same as above, but for judgemental
-- erasure, which is sometimes more convenient.
moveerasee' : {e e' : ê} {e◆ : ė} {δ : direction} →
erase-e e e◆ →
(e + move δ +>e e') →
erase-e e' e◆
moveerasee' er1 m with erase-e◆ er1
... | refl = ◆erase-e _ _ (! (moveerase m))
moveeraset' : ∀{ t t◆ t'' δ} →
erase-t t t◆ →
t + move δ +> t'' →
erase-t t'' t◆
moveeraset' er m with erase-t◆ er
moveeraset' er m | refl = ◆erase-t _ _ (! (moveeraset m))
-- movements don't change either the type or expression under expression
-- actions
mutual
moveerase-synth : ∀{Γ e e' e◆ t t' δ } →
(er : erase-e e e◆) →
Γ ⊢ e◆ => t →
Γ ⊢ e => t ~ move δ ~> e' => t' →
(e ◆e) == (e' ◆e) × t == t'
moveerase-synth er wt (SAMove x) = moveerase x , refl
moveerase-synth (EEAscL er) (SAsc x) (SAZipAsc1 x₁) = ap1 (λ q → q ·: _) (moveerase-ana er x x₁) , refl
moveerase-synth er wt (SAZipAsc2 x x₁ x₂ x₃)
with (moveeraset x)
... | qq = ap1 (λ q → _ ·: q) qq , eq-ert-trans qq x₂ x₁
moveerase-synth (EEApL er) (SAp wt x x₁) (SAZipApArr x₂ x₃ x₄ d x₅)
with erasee-det x₃ er
... | refl with synthunicity wt x₄
... | refl with moveerase-synth er x₄ d
... | pp , refl with matcharrunicity x x₂
... | refl = (ap1 (λ q → q ∘ _) pp ) , refl
moveerase-synth (EEApR er) (SAp wt x x₁) (SAZipApAna x₂ x₃ x₄)
with synthunicity x₃ wt
... | refl with matcharrunicity x x₂
... | refl = ap1 (λ q → _ ∘ q) (moveerase-ana er x₁ x₄ ) , refl
moveerase-synth (EEPlusL er) (SPlus x x₁) (SAZipPlus1 x₂) = ap1 (λ q → q ·+ _) (moveerase-ana er x x₂) , refl
moveerase-synth (EEPlusR er) (SPlus x x₁) (SAZipPlus2 x₂) = ap1 (λ q → _ ·+ q) (moveerase-ana er x₁ x₂) , refl
moveerase-synth er wt (SAZipHole x x₁ d) = ap1 ⦇⌜_⌟⦈ (π1 (moveerase-synth x x₁ d)) , refl
moveerase-ana : ∀{Γ e e' e◆ t δ } →
(er : erase-e e e◆) →
Γ ⊢ e◆ <= t →
Γ ⊢ e ~ move δ ~> e' ⇐ t →
(e ◆e) == (e' ◆e)
moveerase-ana er wt (AASubsume x x₁ x₂ x₃) = π1 (moveerase-synth x x₁ x₂)
moveerase-ana er wt (AAMove x) = moveerase x
moveerase-ana (EELam er) (ASubsume () x₂) _
moveerase-ana (EELam er) (ALam x₁ x₂ wt) (AAZipLam x₃ x₄ d) with matcharrunicity x₂ x₄
... | refl = ap1 (λ q → ·λ _ q) (moveerase-ana er wt d)
| {
"alphanum_fraction": 0.5710919089,
"avg_line_length": 40.6276595745,
"ext": "agda",
"hexsha": "a2247cf6afe14d2b7dd9975004b41084fac034da",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-07-03T03:45:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-07-03T03:45:07.000Z",
"max_forks_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/agda-popl17",
"max_forks_repo_path": "moveerase.agda",
"max_issues_count": 37,
"max_issues_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_issues_repo_issues_event_max_datetime": "2016-11-09T18:13:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-07-07T16:23:11.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/agda-popl17",
"max_issues_repo_path": "moveerase.agda",
"max_line_length": 114,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/agda-popl17",
"max_stars_repo_path": "moveerase.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-11T12:30:50.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-01T22:44:11.000Z",
"num_tokens": 1451,
"size": 3819
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Bool.Properties where
open import Cubical.Core.Everything
open import Cubical.Functions.Involution
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Data.Bool.Base
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
notnot : ∀ x → not (not x) ≡ x
notnot true = refl
notnot false = refl
notIsEquiv : isEquiv not
notIsEquiv = involIsEquiv {f = not} notnot
notEquiv : Bool ≃ Bool
notEquiv = involEquiv {f = not} notnot
notEq : Bool ≡ Bool
notEq = involPath {f = not} notnot
private
variable
ℓ : Level
-- This computes to false as expected
nfalse : Bool
nfalse = transp (λ i → notEq i) i0 true
-- Sanity check
nfalsepath : nfalse ≡ false
nfalsepath = refl
K-Bool
: (P : {b : Bool} → b ≡ b → Type ℓ)
→ (∀{b} → P {b} refl)
→ ∀{b} → (q : b ≡ b) → P q
K-Bool P Pr {false} = J (λ{ false q → P q ; true _ → Lift ⊥ }) Pr
K-Bool P Pr {true} = J (λ{ true q → P q ; false _ → Lift ⊥ }) Pr
isSetBool : isSet Bool
isSetBool a b = J (λ _ p → ∀ q → p ≡ q) (K-Bool (refl ≡_) refl)
true≢false : ¬ true ≡ false
true≢false p = subst (λ b → if b then Bool else ⊥) p true
false≢true : ¬ false ≡ true
false≢true p = subst (λ b → if b then ⊥ else Bool) p true
not≢const : ∀ x → ¬ not x ≡ x
not≢const false = true≢false
not≢const true = false≢true
zeroˡ : ∀ x → true or x ≡ true
zeroˡ false = refl
zeroˡ true = refl
zeroʳ : ∀ x → x or true ≡ true
zeroʳ false = refl
zeroʳ true = refl
or-identityˡ : ∀ x → false or x ≡ x
or-identityˡ false = refl
or-identityˡ true = refl
or-identityʳ : ∀ x → x or false ≡ x
or-identityʳ false = refl
or-identityʳ true = refl
or-comm : ∀ x y → x or y ≡ y or x
or-comm false y =
false or y ≡⟨ or-identityˡ y ⟩
y ≡⟨ sym (or-identityʳ y) ⟩
y or false ∎
or-comm true y =
true or y ≡⟨ zeroˡ y ⟩
true ≡⟨ sym (zeroʳ y) ⟩
y or true ∎
or-assoc : ∀ x y z → x or (y or z) ≡ (x or y) or z
or-assoc false y z =
false or (y or z) ≡⟨ or-identityˡ _ ⟩
y or z ≡[ i ]⟨ or-identityˡ y (~ i) or z ⟩
((false or y) or z) ∎
or-assoc true y z =
true or (y or z) ≡⟨ zeroˡ _ ⟩
true ≡⟨ sym (zeroˡ _) ⟩
true or z ≡[ i ]⟨ zeroˡ y (~ i) or z ⟩
(true or y) or z ∎
or-idem : ∀ x → x or x ≡ x
or-idem false = refl
or-idem true = refl
⊕-identityʳ : ∀ x → x ⊕ false ≡ x
⊕-identityʳ false = refl
⊕-identityʳ true = refl
⊕-comm : ∀ x y → x ⊕ y ≡ y ⊕ x
⊕-comm false false = refl
⊕-comm false true = refl
⊕-comm true false = refl
⊕-comm true true = refl
⊕-assoc : ∀ x y z → x ⊕ (y ⊕ z) ≡ (x ⊕ y) ⊕ z
⊕-assoc false y z = refl
⊕-assoc true false z = refl
⊕-assoc true true z = notnot z
not-⊕ˡ : ∀ x y → not (x ⊕ y) ≡ not x ⊕ y
not-⊕ˡ false y = refl
not-⊕ˡ true y = notnot y
⊕-invol : ∀ x y → x ⊕ (x ⊕ y) ≡ y
⊕-invol false x = refl
⊕-invol true x = notnot x
isEquiv-⊕ : ∀ x → isEquiv (x ⊕_)
isEquiv-⊕ x = involIsEquiv (⊕-invol x)
⊕-Path : ∀ x → Bool ≡ Bool
⊕-Path x = involPath {f = x ⊕_} (⊕-invol x)
⊕-Path-refl : ⊕-Path false ≡ refl
⊕-Path-refl = isInjectiveTransport refl
¬transportNot : ∀(P : Bool ≡ Bool) b → ¬ (transport P (not b) ≡ transport P b)
¬transportNot P b eq = not≢const b sub
where
sub : not b ≡ b
sub = subst {A = Bool → Bool} (λ f → f (not b) ≡ f b)
(λ i c → transport⁻Transport P c i) (cong (transport⁻ P) eq)
module BoolReflection where
data Table (A : Type₀) (P : Bool ≡ A) : Type₀ where
inspect : (b c : A)
→ transport P false ≡ b
→ transport P true ≡ c
→ Table A P
table : ∀ P → Table Bool P
table = J Table (inspect false true refl refl)
reflLemma : (P : Bool ≡ Bool)
→ transport P false ≡ false
→ transport P true ≡ true
→ transport P ≡ transport (⊕-Path false)
reflLemma P ff tt i false = ff i
reflLemma P ff tt i true = tt i
notLemma : (P : Bool ≡ Bool)
→ transport P false ≡ true
→ transport P true ≡ false
→ transport P ≡ transport (⊕-Path true)
notLemma P ft tf i false = ft i
notLemma P ft tf i true = tf i
categorize : ∀ P → transport P ≡ transport (⊕-Path (transport P false))
categorize P with table P
categorize P | inspect false true p q
= subst (λ b → transport P ≡ transport (⊕-Path b)) (sym p) (reflLemma P p q)
categorize P | inspect true false p q
= subst (λ b → transport P ≡ transport (⊕-Path b)) (sym p) (notLemma P p q)
categorize P | inspect false false p q
= rec (¬transportNot P false (q ∙ sym p))
categorize P | inspect true true p q
= rec (¬transportNot P false (q ∙ sym p))
⊕-complete : ∀ P → P ≡ ⊕-Path (transport P false)
⊕-complete P = isInjectiveTransport (categorize P)
⊕-comp : ∀ p q → ⊕-Path p ∙ ⊕-Path q ≡ ⊕-Path (q ⊕ p)
⊕-comp p q = isInjectiveTransport (λ i x → ⊕-assoc q p x i)
open Iso
reflectIso : Iso Bool (Bool ≡ Bool)
reflectIso .fun = ⊕-Path
reflectIso .inv P = transport P false
reflectIso .leftInv = ⊕-identityʳ
reflectIso .rightInv P = sym (⊕-complete P)
reflectEquiv : Bool ≃ (Bool ≡ Bool)
reflectEquiv = isoToEquiv reflectIso
| {
"alphanum_fraction": 0.6069082035,
"avg_line_length": 27.1785714286,
"ext": "agda",
"hexsha": "4d07834fa67100e0a6d70e855cb2d695678e6f4b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/Bool/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"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": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/Bool/Properties.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/Bool/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2067,
"size": 5327
} |
-- There were some serious bugs in the termination checker
-- which were hidden by the fact that it didn't go inside
-- records. They should be fixed now.
module Issue222 where
record R (A : Set) : Set where
module M (a : A) where
-- Bug.agda:4,17-18
-- Panic: unbound variable A
-- when checking that the expression A has type _5
| {
"alphanum_fraction": 0.7172619048,
"avg_line_length": 25.8461538462,
"ext": "agda",
"hexsha": "98fb936afb38a147121046d829535e8051a6f375",
"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/Issue222.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/Issue222.agda",
"max_line_length": 58,
"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/Issue222.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": 336
} |
-- {-# OPTIONS -v scope.decl.trace:50 #-}
data D : Set where
D : Set
| {
"alphanum_fraction": 0.5857142857,
"avg_line_length": 14,
"ext": "agda",
"hexsha": "feedb385099250dd7a7f1532f78969770157864a",
"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/Issue3448.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/Issue3448.agda",
"max_line_length": 41,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue3448.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": 23,
"size": 70
} |
-- A Simple selection of modules with some renamings to
-- make my (your) life easier when starting a new agda module.
--
-- This includes standard functionality to work on:
-- 1. Functions,
-- 2. Naturals,
-- 3. Products and Coproducts (projections and injections are p1, p2, i1, i2).
-- 4. Finite Types (zero and suc are fz and fs)
-- 5. Lists
-- 6. Booleans and PropositionalEquality
-- 7. Decidable Predicates
--
module Prelude where
open import Data.Unit.NonEta
using (Unit; unit)
public
open import Data.Empty
using (⊥; ⊥-elim)
public
open import Function
using (_∘_; _$_; flip; id; const; _on_)
public
open import Data.Nat
using (ℕ; suc; zero; _+_; _*_; _∸_)
renaming (_≟_ to _≟-ℕ_; _≤?_ to _≤?-ℕ_)
public
open import Data.Fin
using (Fin; fromℕ; fromℕ≤; toℕ)
renaming (zero to fz; suc to fs)
public
open import Data.Fin.Properties
using ()
renaming (_≟_ to _≟-Fin_)
public
open import Data.List
using (List; _∷_; []; map; _++_; zip; filter;
all; any; concat; foldr; reverse; length)
public
open import Data.Product
using (∃; Σ; _×_; _,_; uncurry; curry)
renaming (proj₁ to p1; proj₂ to p2
; <_,_> to split)
public
open import Data.Sum
using (_⊎_; [_,_]′)
renaming (inj₁ to i1; inj₂ to i2
; [_,_] to either)
public
open import Data.Bool
using (Bool; true; false; if_then_else_; not)
renaming (_∧_ to _and_; _∨_ to _or_)
public
open import Relation.Nullary
using (Dec; yes; no; ¬_)
public
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; cong; cong₂; subst)
public
open import Data.Maybe
using (Maybe; just; nothing)
renaming (maybe′ to maybe)
public
dec-elim : ∀{a b}{A : Set a}{B : Set b}
→ (A → B) → (¬ A → B) → Dec A → B
dec-elim f g (yes p) = f p
dec-elim f g (no p) = g p
dec2set : ∀{a}{A : Set a} → Dec A → Set
dec2set (yes _) = Unit
dec2set (no _) = ⊥
isTrue : ∀{a}{A : Set a} → Dec A → Bool
isTrue (yes _) = true
isTrue _ = false
takeWhile : ∀{a}{A : Set a} → (A → Bool) → List A → List A
takeWhile _ [] = []
takeWhile f (x ∷ xs) with f x
...| true = x ∷ takeWhile f xs
...| _ = takeWhile f xs
-- Some minor boilerplate to solve equality problem...
record Eq (A : Set) : Set where
constructor eq
field cmp : (x y : A) → Dec (x ≡ y)
open Eq {{...}}
record Enum (A : Set) : Set where
constructor enum
field
toEnum : A → Maybe ℕ
fromEnum : ℕ → Maybe A
open Enum {{...}}
instance
eq-ℕ : Eq ℕ
eq-ℕ = eq _≟-ℕ_
enum-ℕ : Enum ℕ
enum-ℕ = enum just just
eq-Fin : ∀{n} → Eq (Fin n)
eq-Fin = eq _≟-Fin_
enum-Fin : ∀{n} → Enum (Fin n)
enum-Fin {n} = enum (λ x → just (toℕ x)) fromℕ-partial
where
fromℕ-partial : ℕ → Maybe (Fin n)
fromℕ-partial m with suc m ≤?-ℕ n
...| yes prf = just (fromℕ≤ {m} {n} prf)
...| no _ = nothing
eq-⊥ : Eq ⊥
eq-⊥ = eq (λ x → ⊥-elim x)
enum-⊥ : Enum ⊥
enum-⊥ = enum ⊥-elim (const nothing)
eq-Maybe : ∀{A} ⦃ eqA : Eq A ⦄ → Eq (Maybe A)
eq-Maybe = eq decide
where
just-inj : ∀{a}{A : Set a}{x y : A}
→ _≡_ {a} {Maybe A} (just x) (just y) → x ≡ y
just-inj refl = refl
decide : {A : Set} ⦃ eqA : Eq A ⦄
→ (x y : Maybe A) → Dec (x ≡ y)
decide nothing nothing = yes refl
decide nothing (just _) = no (λ ())
decide (just _) nothing = no (λ ())
decide ⦃ eq f ⦄ (just x) (just y) with f x y
...| yes x≡y = yes (cong just x≡y)
...| no x≢y = no (x≢y ∘ just-inj)
enum-Maybe : ∀{A} ⦃ enA : Enum A ⦄ → Enum (Maybe A)
enum-Maybe ⦃ enum aℕ ℕa ⦄ = enum (maybe aℕ nothing) (just ∘ ℕa)
eq-List : {A : Set}{{eq : Eq A}} → Eq (List A)
eq-List {A} {{eq _≟_}} = eq decide
where
open import Data.List.Properties
renaming (∷-injective to ∷-inj)
decide : (a b : List A) → Dec (a ≡ b)
decide [] (_ ∷ _) = no (λ ())
decide (_ ∷ _) [] = no (λ ())
decide [] [] = yes refl
decide (a ∷ as) (b ∷ bs)
with a ≟ b | decide as bs
...| yes a≡b | yes as≡bs
rewrite a≡b = yes (cong (_∷_ b) as≡bs)
...| no a≢b | yes as≡bs = no (a≢b ∘ p1 ∘ ∷-inj)
...| yes a≡b | no as≢bs = no (as≢bs ∘ p2 ∘ ∷-inj)
...| no a≢b | no as≢bs = no (a≢b ∘ p1 ∘ ∷-inj)
| {
"alphanum_fraction": 0.5201393425,
"avg_line_length": 26.7034883721,
"ext": "agda",
"hexsha": "a526f6fea9ee6b2f4a41b1841230b504d62bad06",
"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": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "VictorCMiraldo/agda-rw",
"max_forks_repo_path": "Prelude.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_issues_repo_issues_event_max_datetime": "2015-05-28T14:48:03.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-06T15:03:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "VictorCMiraldo/agda-rw",
"max_issues_repo_path": "Prelude.agda",
"max_line_length": 79,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "VictorCMiraldo/agda-rw",
"max_stars_repo_path": "Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-24T17:38:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-02-09T15:43:38.000Z",
"num_tokens": 1698,
"size": 4593
} |
module Control.Monad.Free.Quotiented where
open import Prelude
open import Data.List hiding (map)
open import Data.Fin.Sigma
open import Algebra
postulate
uip : isSet A
--------------------------------------------------------------------------------
-- Some functors
--------------------------------------------------------------------------------
private variable
F : Type a → Type a
G : Type b → Type b
--------------------------------------------------------------------------------
-- A free monad without any quotients: this can be treated as the "syntax tree"
-- for the later proper free monad.
--------------------------------------------------------------------------------
data Syntax (F : Type a → Type a) (A : Type a) : Type (ℓsuc a) where
lift : (Fx : F A) → Syntax F A
return : (x : A) → Syntax F A
_>>=_ : (xs : Syntax F B) → (k : B → Syntax F A) → Syntax F A
-- ^
-- This needs to be a set. So apparently, everything does
module RawMonadSyntax where
_>>_ : Syntax F A → Syntax F B → Syntax F B
xs >> ys = xs >>= const ys
--------------------------------------------------------------------------------
-- Quotients for functors
--------------------------------------------------------------------------------
-- All of these quotients are defined on syntax trees, since otherwise we get a
-- cyclic dependency.
record Equation (Σ : Type a → Type a) (ν : Type a) : Type (ℓsuc a) where
constructor _⊜_
field lhs rhs : Syntax Σ ν
open Equation public
record Law (F : Type a → Type a) : Type (ℓsuc a) where
constructor _↦_⦂_
field
Γ : Type a
ν : Type a
eqn : Γ → Equation F ν
open Law public
Theory : (Type a → Type a) → Type (ℓsuc a)
Theory Σ = List (Law Σ)
private variable 𝒯 : Theory F
Quotiented : Theory F → (∀ {ν} → Syntax F ν → Syntax F ν → Type b) → Type _
Quotiented 𝒯 R =
(i : Fin (length 𝒯)) → -- An index into the list of equations
let Γ ↦ ν ⦂ 𝓉 = 𝒯 !! i in -- one of the equations in the list
(γ : Γ) → -- The environment, basically the needed things for the equation
R (lhs (𝓉 γ)) (rhs (𝓉 γ))
--------------------------------------------------------------------------------
-- The free monad, quotiented over a theory
--------------------------------------------------------------------------------
mutual
data Free (F : Type a → Type a) (𝒯 : Theory F) : Type a → Type (ℓsuc a) where
-- The first three constructors are the same as the syntax type
lift : (Fx : F A) → Free F 𝒯 A
return : (x : A) → Free F 𝒯 A
_>>=_ : (xs : Free F 𝒯 B) → (k : B → Free F 𝒯 A) → Free F 𝒯 A
-- The quotients for the monad laws
>>=-idˡ : (f : B → Free F 𝒯 A) (x : B) → (return x >>= f) ≡ f x
>>=-idʳ : (x : Free F 𝒯 A) → (x >>= return) ≡ x
>>=-assoc : (xs : Free F 𝒯 C) (f : C → Free F 𝒯 B) (g : B → Free F 𝒯 A) →
((xs >>= f) >>= g) ≡ (xs >>= (λ x → f x >>= g))
-- This is the quotient for the theory.
quot : Quotiented 𝒯 (λ lhs rhs → ∣ lhs ∣↑ ≡ ∣ rhs ∣↑)
-- This converts from the unquotiented syntax to the free type.
-- You cannot go the other way!
-- The fact that we're doing all this conversion is what makes things trickier
-- later (and also that this is interleaved with the data definition).
∣_∣↑ : Syntax F A → Free F 𝒯 A
∣ lift x ∣↑ = lift x
∣ return x ∣↑ = return x
∣ xs >>= k ∣↑ = ∣ xs ∣↑ >>= (∣_∣↑ ∘ k)
module FreeMonadSyntax where
_>>_ : Free F 𝒯 A → Free F 𝒯 B → Free F 𝒯 B
xs >> ys = xs >>= const ys
--------------------------------------------------------------------------------
-- Recursion Schemes
--------------------------------------------------------------------------------
private variable
p : Level
P : ∀ T → Free F 𝒯 T → Type p
-- The functor for a free monad (not really! This is a "raw" free functor)
data FreeF (F : Type a → Type a)
(𝒯 : Theory F)
(P : ∀ T → Free F 𝒯 T → Type b)
(A : Type a) : Type (ℓsuc a ℓ⊔ b) where
liftF : (Fx : F A) → FreeF F 𝒯 P A
returnF : (x : A) → FreeF F 𝒯 P A
bindF : (xs : Free F 𝒯 B)
(P⟨xs⟩ : P B xs)
(k : B → Free F 𝒯 A)
(P⟨∘k⟩ : ∀ x → P A (k x)) → FreeF F 𝒯 P A
-- There can also be a quotiented free functor (I think)
-- The "in" function
⟪_⟫ : FreeF F 𝒯 P A → Free F 𝒯 A
⟪ liftF x ⟫ = lift x
⟪ returnF x ⟫ = return x
⟪ bindF xs P⟨xs⟩ k P⟨∘k⟩ ⟫ = xs >>= k
-- An algebra
Alg : (F : Type a → Type a) → (𝒯 : Theory F) → (P : ∀ T → Free F 𝒯 T → Type b) → Type _
Alg F 𝒯 P = ∀ {A} → (xs : FreeF F 𝒯 P A) → P A ⟪ xs ⟫
-- You can run a non-coherent algebra on a syntax tree
⟦_⟧↑ : Alg F 𝒯 P → (xs : Syntax F A) → P A ∣ xs ∣↑
⟦ alg ⟧↑ (lift x) = alg (liftF x)
⟦ alg ⟧↑ (return x) = alg (returnF x)
⟦ alg ⟧↑ (xs >>= k) = alg (bindF ∣ xs ∣↑ (⟦ alg ⟧↑ xs) (∣_∣↑ ∘ k) (⟦ alg ⟧↑ ∘ k))
-- Coherency for an algebra: an algebra that's coherent can be run on a proper
-- Free monad.
record Coherent {a p}
{F : Type a → Type a}
{𝒯 : Theory F}
{P : ∀ T → Free F 𝒯 T → Type p}
(ψ : Alg F 𝒯 P) : Type (ℓsuc a ℓ⊔ p) where
field
c->>=idˡ : ∀ (f : A → Free F 𝒯 B) Pf x →
ψ (bindF (return x) (ψ (returnF x)) f Pf)
≡[ i ≔ P _ (>>=-idˡ f x i) ]≡ Pf x
c->>=idʳ : ∀ (x : Free F 𝒯 A) Px →
ψ (bindF x Px return (λ y → ψ (returnF y)))
≡[ i ≔ P A (>>=-idʳ x i) ]≡ Px
c->>=assoc : ∀
(xs : Free F 𝒯 C) Pxs
(f : C → Free F 𝒯 B) Pf
(g : B → Free F 𝒯 A) Pg →
ψ (bindF (xs >>= f) (ψ (bindF xs Pxs f Pf)) g Pg)
≡[ i ≔ P A (>>=-assoc xs f g i) ]≡
ψ (bindF xs Pxs (λ x → f x >>= g) λ x → ψ (bindF (f x) (Pf x) g Pg))
c-quot : (i : Fin (length 𝒯)) →
let Γ ↦ ν ⦂ 𝓉 = 𝒯 !! i in
(γ : Γ) →
⟦ ψ ⟧↑ (lhs (𝓉 γ)) ≡[ j ≔ P ν (quot i γ j) ]≡ ⟦ ψ ⟧↑ (rhs (𝓉 γ))
open Coherent public
-- A full dependent algebra
Ψ : (F : Type a → Type a) (𝒯 : Theory F) (P : ∀ T → Free F 𝒯 T → Type p) → Type _
Ψ F 𝒯 P = Σ (Alg F 𝒯 P) Coherent
Ψ-syntax : (F : Type a → Type a) (𝒯 : Theory F) (P : ∀ {T} → Free F 𝒯 T → Type p) → Type _
Ψ-syntax F 𝒯 P = Ψ F 𝒯 (λ T → P {T})
syntax Ψ-syntax F 𝒯 (λ xs → P) = Ψ[ xs ⦂ F ⋆ * / 𝒯 ] ⇒ P
-- Non-dependent algebras
Φ : (F : Type a → Type a) → (𝒯 : Theory F) → (Type a → Type b) → Type _
Φ A 𝒯 B = Ψ A 𝒯 (λ T _ → B T)
syntax Φ F 𝒯 (λ A → B) = Φ[ F ⋆ A / 𝒯 ] ⇒ B
-- Running the algebra
module _ (ψ : Ψ F 𝒯 P) where
⟦_⟧ : (xs : Free F 𝒯 A) → P A xs
-- We need the terminating pragma here because Agda can't see that ∣_∣↑ makes
-- something the same size (I think)
{-# TERMINATING #-}
undecorate : (xs : Syntax F A) → ⟦ fst ψ ⟧↑ xs ≡ ⟦ ∣ xs ∣↑ ⟧
undecorate (lift x) i = fst ψ (liftF x)
undecorate (return x) i = fst ψ (returnF x)
undecorate (xs >>= k) i =
fst ψ
(bindF ∣ xs ∣↑ (undecorate xs i) (λ x → ∣ k x ∣↑)
(λ x → undecorate (k x) i))
⟦ lift x ⟧ = ψ .fst (liftF x)
⟦ return x ⟧ = ψ .fst (returnF x)
⟦ xs >>= k ⟧ = ψ .fst (bindF xs ⟦ xs ⟧ k (⟦_⟧ ∘ k))
⟦ >>=-idˡ f k i ⟧ = ψ .snd .c->>=idˡ f (⟦_⟧ ∘ f) k i
⟦ >>=-idʳ xs i ⟧ = ψ .snd .c->>=idʳ xs ⟦ xs ⟧ i
⟦ >>=-assoc xs f g i ⟧ =
ψ .snd .c->>=assoc xs ⟦ xs ⟧ f (⟦_⟧ ∘ f) g (⟦_⟧ ∘ g) i
⟦ quot p e i ⟧ =
subst₂ (PathP (λ j → P _ (quot p e j)))
(undecorate _)
(undecorate _)
(ψ .snd .c-quot p e) i
-- For a proposition, use this to prove the algebra is coherent
prop-coh : {alg : Alg F 𝒯 P} → (∀ {T} → ∀ xs → isProp (P T xs)) → Coherent alg
prop-coh {P = P} P-isProp .c->>=idˡ f Pf x =
toPathP (P-isProp (f x) (transp (λ i → P _ (>>=-idˡ f x i)) i0 _) _)
prop-coh {P = P} P-isProp .c->>=idʳ x Px =
toPathP (P-isProp x (transp (λ i → P _ (>>=-idʳ x i)) i0 _) _)
prop-coh {P = P} P-isProp .c->>=assoc xs Pxs f Pf g Pg =
toPathP (P-isProp (xs >>= (λ x → f x >>= g)) (transp (λ i → P _ (>>=-assoc xs f g i)) i0 _) _)
prop-coh {𝒯 = 𝒯} {P = P} P-isProp .c-quot i e =
toPathP (P-isProp (∣ (𝒯 !! i) .eqn e .rhs ∣↑) (transp (λ j → P _ (quot i e j)) i0 _) _)
-- A more conventional catamorphism
module _ {ℓ} (fun : Functor ℓ ℓ) where
open Functor fun using (map; 𝐹)
module _ {B : Type ℓ} {𝒯 : Theory 𝐹} where
module _ (ϕ : 𝐹 B → B) where
ϕ₁ : Alg 𝐹 𝒯 λ T _ → (T → B) → B
ϕ₁ (liftF x) h = ϕ (map h x)
ϕ₁ (returnF x) h = h x
ϕ₁ (bindF _ P⟨xs⟩ _ P⟨∘k⟩) h = P⟨xs⟩ (flip P⟨∘k⟩ h)
InTheory : Type _
InTheory = Quotiented 𝒯 λ lhs rhs → ∀ f → ⟦ ϕ₁ ⟧↑ lhs f ≡ ⟦ ϕ₁ ⟧↑ rhs f
module _ (ϕ-coh : InTheory) where
cata-coh : Coherent ϕ₁
cata-coh .c->>=idˡ f Pf x = refl
cata-coh .c->>=idʳ x Px = refl
cata-coh .c->>=assoc xs Pxs f Pf g Pg = refl
cata-coh .c-quot i e j f = ϕ-coh i e f j
cata-alg : Φ[ 𝐹 ⋆ A / 𝒯 ] ⇒ ((A → B) → B)
cata-alg = ϕ₁ , cata-coh
cata : (A → B) → (ϕ : 𝐹 B → B) → InTheory ϕ → Free 𝐹 𝒯 A → B
cata h ϕ coh xs = ⟦ cata-alg ϕ coh ⟧ xs h
| {
"alphanum_fraction": 0.4691095967,
"avg_line_length": 35.9477911647,
"ext": "agda",
"hexsha": "2b09394c4ffb140e819cd1a9f19a254c726902c5",
"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": "Control/Monad/Free/Quotiented.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": "Control/Monad/Free/Quotiented.agda",
"max_line_length": 96,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Control/Monad/Free/Quotiented.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": 3470,
"size": 8951
} |
------------------------------------------------------------------------
-- Container combinators
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Indexed-container.Combinators where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id; const) renaming (_∘_ to _⊚_)
open import Prelude.Size
open import Bijection equality-with-J as Bijection using (_↔_)
import Equivalence equality-with-J as Eq
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import Indexed-container
open import Relation
-- An identity combinator.
--
-- Taken from "Indexed containers" by Altenkirch, Ghani, Hancock,
-- McBride and Morris (JFP, 2015).
id : ∀ {i} {I : Type i} → Container I I
id = (λ _ → ↑ _ ⊤) ◁ λ {i} _ i′ → i ≡ i′
-- An unfolding lemma for ⟦ id ⟧.
⟦id⟧↔ : ∀ {k ℓ x} {I : Type ℓ} {X : Rel x I} {i} →
Extensionality? k ℓ (ℓ ⊔ x) →
⟦ id ⟧ X i ↝[ k ] X i
⟦id⟧↔ {X = X} {i} ext =
↑ _ ⊤ × (λ i′ → i ≡ i′) ⊆ X ↔⟨ drop-⊤-left-× (λ _ → Bijection.↑↔) ⟩
(λ i′ → i ≡ i′) ⊆ X ↔⟨⟩
(∀ {i′} → i ≡ i′ → X i′) ↔⟨ Bijection.implicit-Π↔Π ⟩
(∀ i′ → i ≡ i′ → X i′) ↝⟨ inverse-ext? (λ ext → ∀-intro _ ext) ext ⟩□
X i □
-- An unfolding lemma for ⟦ id ⟧₂.
⟦id⟧₂↔ :
∀ {k ℓ x} {I : Type ℓ} {X : Rel x I} →
Extensionality? k ℓ ℓ →
∀ (R : ∀ {i} → Rel₂ ℓ (X i)) {i} →
(x y : ⟦ id ⟧ X i) →
⟦ id ⟧₂ R (x , y)
↝[ k ]
proj₁ x ≡ proj₁ y × R (proj₂ x refl , proj₂ y refl)
⟦id⟧₂↔ ext R {i} x@(s , f) y@(t , g) =
⟦ id ⟧₂ R (x , y) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : i ≡ o) →
R (f p , g (subst (λ _ → i ≡ o) eq p))) ↔⟨ ∃-cong (λ _ → Bijection.implicit-Π↔Π) ⟩
(∃ λ (eq : s ≡ t) →
∀ o (p : i ≡ o) →
R (f p , g (subst (λ _ → i ≡ o) eq p))) ↝⟨ ∃-cong (λ _ → inverse-ext? (λ ext → ∀-intro _ ext) ext) ⟩
(∃ λ (eq : s ≡ t) →
R (f refl , g (subst (λ _ → i ≡ i) eq refl))) ↝⟨ ∃-cong (λ eq → ≡⇒↝ _ (cong (λ eq → R (f refl , g eq)) (subst-const eq))) ⟩
s ≡ t × R (f refl , g refl) □
-- A second unfolding lemma for ⟦ id ⟧₂.
⟦id⟧₂≡↔ :
∀ {ℓ} {I : Type ℓ} {X : Rel ℓ I} {i} →
Extensionality ℓ ℓ →
(x y : ⟦ id ⟧ X i) →
⟦ id ⟧₂ (uncurry _≡_) (x , y) ↔ x ≡ y
⟦id⟧₂≡↔ ext x@(s , f) y@(t , g) =
⟦ id ⟧₂ (uncurry _≡_) (x , y) ↝⟨ ⟦id⟧₂↔ ext (uncurry _≡_) x y ⟩
s ≡ t × f refl ≡ g refl ↔⟨ ∃-cong (λ _ → Eq.≃-≡ (Eq.↔⇒≃ $ inverse $ ∀-intro _ ext)) ⟩
s ≡ t × (λ _ → f) ≡ (λ _ → g) ↔⟨ ∃-cong (λ _ → Eq.≃-≡ (Eq.↔⇒≃ Bijection.implicit-Π↔Π)) ⟩
s ≡ t × (λ {_} → f) ≡ g ↝⟨ ≡×≡↔≡ ⟩
x ≡ y □
-- A constant combinator.
const : ∀ {i} {I : Type i} → Rel i I → Container I I
const X = X ◁ λ _ _ → ⊥
-- An unfolding lemma for ⟦ const ⟧.
⟦const⟧↔ : ∀ {k ℓ y} {I : Type ℓ} X {Y : Rel y I} {i} →
Extensionality? k ℓ (ℓ ⊔ y) →
⟦ const X ⟧ Y i ↝[ k ] X i
⟦const⟧↔ {k} {ℓ} {I = I} X {Y} {i} ext =
X i × (∀ {i} → ⊥ → Y i) ↔⟨ ∃-cong (λ _ → Bijection.implicit-Π↔Π) ⟩
X i × (∀ i → ⊥ → Y i) ↝⟨ ∃-cong (λ _ → ∀-cong ext λ _ → Π⊥↔⊤ (lower-extensionality? k lzero ℓ ext)) ⟩
X i × (I → ⊤) ↔⟨ drop-⊤-right (λ _ → →-right-zero) ⟩
X i □
-- An unfolding lemma for ⟦ const ⟧₂.
⟦const⟧₂↔ :
∀ {k ℓ y} {I : Type ℓ} {X} {Y : Rel y I} →
Extensionality? k ℓ ℓ →
∀ (R : ∀ {i} → Rel₂ ℓ (Y i)) {i}
(x y : ⟦ const X ⟧ Y i) →
⟦ const X ⟧₂ R (x , y)
↝[ k ]
proj₁ x ≡ proj₁ y
⟦const⟧₂↔ {X = X} ext R x@(s , f) y@(t , g) =
⟦ const X ⟧₂ R (x , y) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : ⊥) → R (f p , g (subst (λ _ → ⊥) eq p))) ↔⟨ ∃-cong (λ _ → Bijection.implicit-Π↔Π) ⟩
(∃ λ (eq : s ≡ t) →
∀ o (p : ⊥) → R (f p , g (subst (λ _ → ⊥) eq p))) ↝⟨ ∃-cong (λ _ → ∀-cong ext λ _ → Π⊥↔⊤ ext) ⟩
(∃ λ (eq : s ≡ t) → ∀ o → ⊤) ↔⟨ drop-⊤-right (λ _ → →-right-zero) ⟩
s ≡ t □
where
open Container
-- A composition combinator.
infixr 9 _∘_
_∘_ : ∀ {ℓ} {I J K : Type ℓ} →
Container J K → Container I J → Container I K
C ∘ D =
⟦ C ⟧ (Shape D)
◁
(λ { (s , f) i →
∃ λ j → ∃ λ (p : Position C s j) → Position D (f p) i })
where
open Container
-- An unfolding lemma for ⟦ C ∘ D ⟧.
⟦∘⟧↔ : ∀ {fk ℓ x} {I J K : Type ℓ} {X : Rel x I} →
Extensionality? fk ℓ (ℓ ⊔ x) →
∀ (C : Container J K) {D : Container I J} {k} →
⟦ C ∘ D ⟧ X k ↝[ fk ] ⟦ C ⟧ (⟦ D ⟧ X) k
⟦∘⟧↔ {X = X} ext C {D} {k} =
⟦ C ∘ D ⟧ X k ↔⟨⟩
(∃ λ { (s , f) →
∀ {i} →
(∃ λ j → ∃ λ (p : Position C s j) → Position D (f p) i) →
X i }) ↔⟨ inverse Σ-assoc ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ {i} →
(∃ λ j → ∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-∀-cong ext $
from-isomorphism currying) ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ {i} j →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → Bijection.implicit-Π↔Π) ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ i j →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → Π-comm) ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ j i →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → inverse Bijection.implicit-Π↔Π) ⟩
(∃ λ s →
∃ λ (f : Position C s ⊆ Shape D) →
∀ {j} i →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↔⟨ (∃-cong λ _ → inverse implicit-ΠΣ-comm) ⟩
(∃ λ s → ∀ {j} →
∃ λ (f : Position C s j → Shape D j) →
∀ i →
(∃ λ (p : Position C s j) → Position D (f p) i) →
X i) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ ∃-cong λ _ → ∀-cong ext λ _ →
from-isomorphism currying) ⟩
(∃ λ s → ∀ {j} →
∃ λ (f : Position C s j → Shape D j) →
∀ i → (p : Position C s j) → Position D (f p) i → X i) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ ∃-cong λ _ → from-isomorphism Π-comm) ⟩
(∃ λ s → ∀ {j} →
∃ λ (f : Position C s j → Shape D j) →
(p : Position C s j) → ∀ i → Position D (f p) i → X i) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ from-isomorphism $ inverse ΠΣ-comm) ⟩
(∃ λ s → ∀ {j} → Position C s j →
∃ λ (s′ : Shape D j) → ∀ i → Position D s′ i → X i) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ ∀-cong ext λ _ → ∃-cong λ _ →
from-isomorphism $ inverse Bijection.implicit-Π↔Π) ⟩
(∃ λ s → ∀ {j} → Position C s j →
∃ λ (s′ : Shape D j) → Position D s′ ⊆ X) ↔⟨⟩
⟦ C ⟧ (⟦ D ⟧ X) k □
where
open Container
-- TODO: Define ⟦∘⟧₂↔ (an unfolding lemma for ⟦ C ∘ D ⟧₂).
-- A reindexing combinator.
--
-- Taken from "Indexed containers".
reindex₂ : ∀ {ℓ} {I O₁ O₂ : Type ℓ} →
(O₂ → O₁) → Container I O₁ → Container I O₂
reindex₂ f (S ◁ P) = (S ⊚ f) ◁ P
-- An unfolding lemma for ⟦ reindex₂ f C ⟧.
⟦reindex₂⟧↔ : ∀ {ℓ x} {I O₁ O₂ : Type ℓ} (f : O₂ → O₁)
(C : Container I O₁) {X : Rel x I} {o} →
⟦ reindex₂ f C ⟧ X o ↔ ⟦ C ⟧ X (f o)
⟦reindex₂⟧↔ f C = Bijection.id
-- An unfolding lemma for ⟦ reindex₂ f C ⟧₂.
⟦reindex₂⟧₂↔ :
∀ {ℓ x} {I O : Type ℓ} {X : Rel x I}
(C : Container I O) (f : I → O) (R : ∀ {i} → Rel₂ ℓ (X i)) {i}
(x y : ⟦ reindex₂ f C ⟧ X i) →
⟦ reindex₂ f C ⟧₂ R (x , y) ↔ ⟦ C ⟧₂ R (x , y)
⟦reindex₂⟧₂↔ C f R x@(s , g) y@(t , h) =
⟦ reindex₂ f C ⟧₂ R (x , y) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : Position (reindex₂ f C) s o) →
R (g p , h (subst (λ s → Position (reindex₂ f C) s o) eq p))) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : Position C s o) →
R (g p , h (subst (λ s → Position C s o) eq p))) ↔⟨⟩
⟦ C ⟧₂ R (x , y) □
where
open Container
-- Another reindexing combinator.
reindex₁ : ∀ {ℓ} {I₁ I₂ O : Type ℓ} →
(I₁ → I₂) → Container I₁ O → Container I₂ O
reindex₁ f C =
Shape C
◁
(λ s i → ∃ λ i′ → f i′ ≡ i × Position C s i′)
where
open Container
-- An unfolding lemma for ⟦ reindex₁ f C ⟧.
⟦reindex₁⟧↔ : ∀ {k ℓ x} {I₁ I₂ O : Type ℓ} {f : I₁ → I₂} →
Extensionality? k ℓ (ℓ ⊔ x) →
∀ (C : Container I₁ O) {X : Rel x I₂} {o} →
⟦ reindex₁ f C ⟧ X o ↝[ k ] ⟦ C ⟧ (X ⊚ f) o
⟦reindex₁⟧↔ {f = f} ext C {X} {o} =
⟦ reindex₁ f C ⟧ X o ↔⟨ (∃-cong λ _ → Bijection.implicit-Π↔Π) ⟩
(∃ λ (s : Shape C o) →
∀ i → (∃ λ i′ → f i′ ≡ i × Position C s i′) → X i) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → from-isomorphism currying) ⟩
(∃ λ (s : Shape C o) →
∀ i i′ → f i′ ≡ i × Position C s i′ → X i) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → from-isomorphism currying) ⟩
(∃ λ (s : Shape C o) →
∀ i i′ → f i′ ≡ i → Position C s i′ → X i) ↔⟨ (∃-cong λ _ → Π-comm) ⟩
(∃ λ (s : Shape C o) →
∀ i i′ → f i ≡ i′ → Position C s i → X i′) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → inverse-ext? (λ ext → ∀-intro _ ext) ext) ⟩
(∃ λ (s : Shape C o) →
∀ i → Position C s i → X (f i)) ↔⟨ (∃-cong λ _ → inverse Bijection.implicit-Π↔Π) ⟩
⟦ C ⟧ (X ⊚ f) o □
where
open Container
-- An unfolding lemma for ⟦ reindex₁ f C ⟧₂.
⟦reindex₁⟧₂↔ :
∀ {k ℓ x} {I O : Type ℓ} {X : Rel x O} →
Extensionality? k ℓ ℓ →
∀ (C : Container I O) (f : I → O) (R : ∀ {o} → Rel₂ ℓ (X o)) {o}
(x y : ⟦ reindex₁ f C ⟧ X o) →
⟦ reindex₁ f C ⟧₂ R (x , y)
↝[ k ]
⟦ C ⟧₂ R ( (proj₁ x , λ p → proj₂ x (_ , refl , p))
, (proj₁ y , λ p → proj₂ y (_ , refl , p))
)
⟦reindex₁⟧₂↔ ext C f R x@(s , g) y@(t , h) =
⟦ reindex₁ f C ⟧₂ R (x , y) ↔⟨⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : ∃ λ o′ → f o′ ≡ o × Position C s o′) →
R (g p , h (subst (λ s → ∃ λ o′ → f o′ ≡ o × Position C s o′) eq p))) ↝⟨ (∃-cong λ eq → implicit-∀-cong ext $ ∀-cong ext λ _ →
≡⇒↝ _ $ cong (R ⊚ (g _ ,_) ⊚ h) $
lemma eq) ⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : ∃ λ o′ → f o′ ≡ o × Position C s o′) →
R ( g p
, h ( proj₁ p
, proj₁ (proj₂ p)
, subst (λ s → Position C s (proj₁ p)) eq (proj₂ (proj₂ p))
)
)) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ from-isomorphism
currying) ⟩
(∃ λ (eq : s ≡ t) →
∀ {o} o′ (p : f o′ ≡ o × Position C s o′) →
R ( g (o′ , p)
, h (o′ , proj₁ p , subst (λ s → Position C s o′) eq (proj₂ p))
)) ↝⟨ (∃-cong λ _ → implicit-∀-cong ext $ ∀-cong ext λ _ → from-isomorphism
currying) ⟩
(∃ λ (eq : s ≡ t) →
∀ {o} o′ (≡o : f o′ ≡ o) (p : Position C s o′) →
R ( g (o′ , ≡o , p)
, h (o′ , ≡o , subst (λ s → Position C s o′) eq p)
)) ↔⟨ (∃-cong λ _ →
Bijection.implicit-Π↔Π) ⟩
(∃ λ (eq : s ≡ t) →
∀ o o′ (≡o : f o′ ≡ o) (p : Position C s o′) →
R ( g (o′ , ≡o , p)
, h (o′ , ≡o , subst (λ s → Position C s o′) eq p)
)) ↔⟨ (∃-cong λ _ →
Π-comm) ⟩
(∃ λ (eq : s ≡ t) →
∀ o o′ (≡o′ : f o ≡ o′) (p : Position C s o) →
R ( g (o , ≡o′ , p)
, h (o , ≡o′ , subst (λ s → Position C s o) eq p)
)) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ →
inverse-ext? (λ ext → ∀-intro _ ext) ext) ⟩
(∃ λ (eq : s ≡ t) →
∀ o (p : Position C s o) →
R ( g (o , refl , p)
, h (o , refl , subst (λ s → Position C s o) eq p)
)) ↔⟨ (∃-cong λ _ → inverse
Bijection.implicit-Π↔Π) ⟩
(∃ λ (eq : s ≡ t) →
∀ {o} (p : Position C s o) →
R ( g (o , refl , p)
, h (o , refl , subst (λ s → Position C s o) eq p)
)) ↔⟨⟩
⟦ C ⟧₂ R ((s , λ p → g (_ , refl , p)) , (t , λ p → h (_ , refl , p))) □
where
open Container
lemma = λ (eq : s ≡ t) {o} {p : ∃ λ o′ → f o′ ≡ o × Position C s o′} →
subst (λ s → ∃ λ o′ → f o′ ≡ o × Position C s o′) eq p ≡⟨ push-subst-pair′ {y≡z = eq} _ _ (subst-const eq) ⟩
( proj₁ p
, subst (λ { (s , o′) → f o′ ≡ o × Position C s o′ })
(Σ-≡,≡→≡ eq (subst-const eq)) (proj₂ p)
) ≡⟨⟩
( proj₁ p
, subst (λ { (s , o′) → f o′ ≡ o × Position C s o′ })
(Σ-≡,≡→≡ eq (trans (subst-const eq) refl)) (proj₂ p)
) ≡⟨ cong (λ eq → _ , subst (λ { (s , o′) → f o′ ≡ o × Position C s o′ })
eq (proj₂ p)) $
Σ-≡,≡→≡-subst-const eq refl ⟩
( proj₁ p
, subst (λ { (s , o′) → f o′ ≡ o × Position C s o′ })
(cong₂ _,_ eq refl) (proj₂ p)
) ≡⟨ cong (_ ,_) $
push-subst-, {y≡z = cong₂ _,_ eq refl}
((_≡ o) ⊚ f ⊚ proj₂) (uncurry (Position C)) ⟩
( proj₁ p
, subst ((_≡ o) ⊚ f ⊚ proj₂) (cong₂ _,_ eq refl) (proj₁ (proj₂ p))
, subst (uncurry (Position C)) (cong₂ _,_ eq refl) (proj₂ (proj₂ p))
) ≡⟨ cong (λ eq′ → _ , eq′
, subst (uncurry (Position C)) (cong₂ _,_ eq refl) _) $
subst-∘ ((_≡ o) ⊚ f) proj₂ (cong₂ _,_ eq refl) ⟩
( proj₁ p
, subst ((_≡ o) ⊚ f)
(cong proj₂ (cong₂ _,_ eq refl)) (proj₁ (proj₂ p))
, subst (uncurry (Position C)) (cong (_, _) eq) (proj₂ (proj₂ p))
) ≡⟨ cong₂ (λ eq₁ eq₂ → _ , subst ((_≡ o) ⊚ f) eq₁ _ , eq₂)
(cong-proj₂-cong₂-, eq refl)
(sym $ subst-∘ (uncurry (Position C)) (_, _) eq) ⟩
( proj₁ p
, subst ((_≡ o) ⊚ f) refl (proj₁ (proj₂ p))
, subst (uncurry (Position C) ⊚ (_, _)) eq (proj₂ (proj₂ p))
) ≡⟨⟩
( proj₁ p
, proj₁ (proj₂ p)
, subst (λ s → Position C s (proj₁ p)) eq (proj₂ (proj₂ p))
) ∎
-- A combined reindexing combinator.
--
-- The application reindex swap is similar to the overline function
-- from Section 6.3.4.1 in Pous and Sangiorgi's "Enhancements of the
-- bisimulation proof method".
reindex : ∀ {ℓ} {I O : Type ℓ} →
(I → O) → Container I O → Container O I
reindex f = reindex₂ f ⊚ reindex₁ f
-- An unfolding lemma for ⟦ reindex f C ⟧.
⟦reindex⟧↔ : ∀ {k ℓ x} {I O : Type ℓ} {f : I → O} →
Extensionality? k ℓ (ℓ ⊔ x) →
∀ (C : Container I O) {X : Rel x O} {i} →
⟦ reindex f C ⟧ X i ↝[ k ] ⟦ C ⟧ (X ⊚ f) (f i)
⟦reindex⟧↔ {f = f} ext C {X} {i} =
⟦ reindex f C ⟧ X i ↔⟨⟩
⟦ reindex₂ f (reindex₁ f C) ⟧ X i ↔⟨⟩
⟦ reindex₁ f C ⟧ X (f i) ↝⟨ ⟦reindex₁⟧↔ ext C ⟩□
⟦ C ⟧ (X ⊚ f) (f i) □
-- An unfolding lemma for ⟦ reindex f C ⟧₂.
⟦reindex⟧₂↔ :
∀ {k ℓ x} {I O : Type ℓ} {X : Rel x O} →
Extensionality? k ℓ ℓ →
∀ (C : Container I O) (f : I → O) (R : ∀ {o} → Rel₂ ℓ (X o)) {i}
(x y : ⟦ reindex f C ⟧ X i) →
⟦ reindex f C ⟧₂ R (x , y)
↝[ k ]
⟦ C ⟧₂ R ( (proj₁ x , λ p → proj₂ x (_ , refl , p))
, (proj₁ y , λ p → proj₂ y (_ , refl , p))
)
⟦reindex⟧₂↔ ext C f R x y =
⟦ reindex f C ⟧₂ R (x , y) ↔⟨⟩
⟦ reindex₂ f (reindex₁ f C) ⟧₂ R (x , y) ↔⟨⟩
⟦ reindex₁ f C ⟧₂ R (x , y) ↝⟨ ⟦reindex₁⟧₂↔ ext C f R x y ⟩□
⟦ C ⟧₂ R ( (proj₁ x , λ p → proj₂ x (_ , refl , p))
, (proj₁ y , λ p → proj₂ y (_ , refl , p))
) □
-- If f is an involution, then ν (reindex f C) i is pointwise
-- logically equivalent to ν C i ⊚ f.
mutual
ν-reindex⇔ :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {f : I → I} →
f ⊚ f ≡ P.id →
∀ {i x} → ν (reindex f C) i x ⇔ ν C i (f x)
ν-reindex⇔ {C = C} {f} inv {i} {x} =
ν (reindex f C) i x ↔⟨⟩
⟦ reindex f C ⟧ (ν′ (reindex f C) i) x ↝⟨ ⟦reindex⟧↔ _ C ⟩
⟦ C ⟧ (ν′ (reindex f C) i ⊚ f) (f x) ↝⟨ ⟦⟧-cong _ C (ν′-reindex⇔ inv) ⟩
⟦ C ⟧ (ν′ C i ⊚ f ⊚ f) (f x) ↔⟨ ≡⇒↝ bijection $ cong (λ g → ⟦ C ⟧ (ν′ C i ⊚ g) (f x)) inv ⟩
⟦ C ⟧ (ν′ C i) (f x) ↔⟨⟩
ν C i (f x) □
ν′-reindex⇔ :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {f : I → I} →
f ⊚ f ≡ P.id →
∀ {i x} → ν′ (reindex f C) i x ⇔ ν′ C i (f x)
ν′-reindex⇔ {C = C} {f} inv = record { to = to; from = from }
where
to : ∀ {i} → ν′ (reindex f C) i ⊆ ν′ C i ⊚ f
force (to x) = _⇔_.to (ν-reindex⇔ inv) (force x)
from : ∀ {i} → ν′ C i ⊚ f ⊆ ν′ (reindex f C) i
force (from x) = _⇔_.from (ν-reindex⇔ inv) (force x)
-- A cartesian product combinator.
--
-- Similar to a construction in "Containers: Constructing strictly
-- positive types" by Abbott, Altenkirch and Ghani (see
-- Proposition 3.5).
infixr 2 _⊗_
_⊗_ : ∀ {ℓ} {I O : Type ℓ} →
Container I O → Container I O → Container I O
C₁ ⊗ C₂ =
(λ o → Shape C₁ o × Shape C₂ o)
◁
(λ { (s₁ , s₂) i → Position C₁ s₁ i ⊎ Position C₂ s₂ i })
where
open Container
-- An unfolding lemma for ⟦ C₁ ⊗ C₂ ⟧.
⟦⊗⟧↔ : ∀ {k ℓ x} {I O : Type ℓ} →
Extensionality? k ℓ (ℓ ⊔ x) →
∀ (C₁ C₂ : Container I O) {X : Rel x I} {o} →
⟦ C₁ ⊗ C₂ ⟧ X o ↝[ k ] ⟦ C₁ ⟧ X o × ⟦ C₂ ⟧ X o
⟦⊗⟧↔ {k} {ℓ} ext C₁ C₂ {X} {o} =
⟦ C₁ ⊗ C₂ ⟧ X o ↔⟨⟩
(∃ λ (s : Shape C₁ o × Shape C₂ o) →
(λ i → Position C₁ (proj₁ s) i ⊎ Position C₂ (proj₂ s) i) ⊆ X) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (s₁ : Shape C₁ o) →
∃ λ (s₂ : Shape C₂ o) →
(λ i → Position C₁ s₁ i ⊎ Position C₂ s₂ i) ⊆ X) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-∀-cong ext $
Π⊎↔Π×Π (lower-extensionality? k lzero ℓ ext)) ⟩
(∃ λ (s₁ : Shape C₁ o) →
∃ λ (s₂ : Shape C₂ o) →
∀ {i} → (Position C₁ s₁ i → X i) × (Position C₂ s₂ i → X i)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-ΠΣ-comm) ⟩
(∃ λ (s₁ : Shape C₁ o) →
∃ λ (s₂ : Shape C₂ o) →
Position C₁ s₁ ⊆ X × Position C₂ s₂ ⊆ X) ↔⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ (s₁ : Shape C₁ o) →
Position C₁ s₁ ⊆ X
×
∃ λ (s₂ : Shape C₂ o) → Position C₂ s₂ ⊆ X) ↔⟨ Σ-assoc ⟩
(∃ λ (s : Shape C₁ o) → Position C₁ s ⊆ X) ×
(∃ λ (s : Shape C₂ o) → Position C₂ s ⊆ X) ↔⟨⟩
⟦ C₁ ⟧ X o × ⟦ C₂ ⟧ X o □
where
open Container
-- An unfolding lemma for ⟦ C₁ ⊗ C₂ ⟧₂.
⟦⊗⟧₂↔ :
∀ {k ℓ x} {I : Type ℓ} {X : Rel x I} →
Extensionality? k ℓ ℓ →
∀ (C₁ C₂ : Container I I) (R : ∀ {i} → Rel₂ ℓ (X i)) {i}
(x y : ⟦ C₁ ⊗ C₂ ⟧ X i) →
let (x₁ , x₂) , f = x
(y₁ , y₂) , g = y
in
⟦ C₁ ⊗ C₂ ⟧₂ R (x , y)
↝[ k ]
⟦ C₁ ⟧₂ R ((x₁ , f ⊚ inj₁) , (y₁ , g ⊚ inj₁))
×
⟦ C₂ ⟧₂ R ((x₂ , f ⊚ inj₂) , (y₂ , g ⊚ inj₂))
⟦⊗⟧₂↔ ext C₁ C₂ R (x@(x₁ , x₂) , f) (y@(y₁ , y₂) , g) =
⟦ C₁ ⊗ C₂ ⟧₂ R ((x , f) , (y , g)) ↔⟨⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position (C₁ ⊗ C₂) x o) →
R (f p , g (subst (λ s → Position (C₁ ⊗ C₂) s o) eq p))) ↔⟨⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₁ x₁ o ⊎ Position C₂ x₂ o) →
R ( f p
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
eq p)
)) ↔⟨ inverse (Σ-cong ≡×≡↔≡ λ _ → Bijection.id) ⟩
(∃ λ (eq : x₁ ≡ y₁ × x₂ ≡ y₂) →
∀ {o} (p : Position C₁ x₁ o ⊎ Position C₂ x₂ o) →
R ( f p
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ (proj₁ eq) (proj₂ eq)) p)
)) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
∃ λ (eq₂ : x₂ ≡ y₂) →
∀ {o} (p : Position C₁ x₁ o ⊎ Position C₂ x₂ o) →
R ( f p
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) p)
)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-∀-cong ext $ Π⊎↔Π×Π ext) ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
∃ λ (eq₂ : x₂ ≡ y₂) →
∀ {o} →
((p : Position C₁ x₁ o) →
R ( f (inj₁ p)
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) (inj₁ p))
))
×
((p : Position C₂ x₂ o) →
R ( f (inj₂ p)
, g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) (inj₂ p))
))) ↝⟨ (∃-cong λ eq₁ → ∃-cong λ eq₂ → implicit-∀-cong ext $
(∀-cong ext λ _ → ≡⇒↝ _ $ cong (R ⊚ (f _ ,_)) $
lemma₁ eq₁ eq₂)
×-cong
(∀-cong ext λ _ → ≡⇒↝ _ $ cong (R ⊚ (f _ ,_)) $
lemma₂ eq₁ eq₂)) ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
∃ λ (eq₂ : x₂ ≡ y₂) →
∀ {o} →
((p : Position C₁ x₁ o) →
R (f (inj₁ p) , g (inj₁ (subst (λ s₁ → Position C₁ s₁ o) eq₁ p))))
×
((p : Position C₂ x₂ o) →
R (f (inj₂ p) , g (inj₂ (subst (λ s₂ → Position C₂ s₂ o) eq₂ p))))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → implicit-ΠΣ-comm) ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
∃ λ (eq₂ : x₂ ≡ y₂) →
(∀ {o} (p : Position C₁ x₁ o) →
R (f (inj₁ p) , g (inj₁ (subst (λ s₁ → Position C₁ s₁ o) eq₁ p))))
×
(∀ {o} (p : Position C₂ x₂ o) →
R (f (inj₂ p) , g (inj₂ (subst (λ s₂ → Position C₂ s₂ o) eq₂ p))))) ↔⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ (eq₁ : x₁ ≡ y₁) →
(∀ {o} (p : Position C₁ x₁ o) →
R (f (inj₁ p) , g (inj₁ (subst (λ s₁ → Position C₁ s₁ o) eq₁ p))))
×
∃ λ (eq₂ : x₂ ≡ y₂) →
(∀ {o} (p : Position C₂ x₂ o) →
R (f (inj₂ p) , g (inj₂ (subst (λ s₂ → Position C₂ s₂ o) eq₂ p))))) ↔⟨ Σ-assoc ⟩
(∃ λ (eq : x₁ ≡ y₁) →
(∀ {o} (p : Container.Position C₁ x₁ o) →
R ( f (inj₁ p)
, g (inj₁ (subst (λ s₁ → Container.Position C₁ s₁ o) eq p)))
))
×
(∃ λ (eq : x₂ ≡ y₂) →
(∀ {o} (p : Container.Position C₂ x₂ o) →
R ( f (inj₂ p)
, g (inj₂ (subst (λ s₂ → Container.Position C₂ s₂ o) eq p))
))) ↔⟨⟩
⟦ C₁ ⟧₂ R ((x₁ , f ⊚ inj₁) , (y₁ , g ⊚ inj₁))
×
⟦ C₂ ⟧₂ R ((x₂ , f ⊚ inj₂) , (y₂ , g ⊚ inj₂)) □
where
open Container
lemma₁ = λ (eq₁ : x₁ ≡ y₁) (eq₂ : x₂ ≡ y₂) {o p} →
g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) (inj₁ p)) ≡⟨ cong g $ push-subst-inj₁ {y≡z = cong₂ _,_ eq₁ eq₂} _ _ ⟩
g (inj₁ (subst (λ { (s₁ , s₂) → Position C₁ s₁ o })
(cong₂ _,_ eq₁ eq₂) p)) ≡⟨ cong (g ⊚ inj₁) $ subst-∘ _ _ (cong₂ _,_ eq₁ eq₂) ⟩
g (inj₁ (subst (λ s₁ → Position C₁ s₁ o)
(cong proj₁ (cong₂ _,_ eq₁ eq₂)) p)) ≡⟨ cong (g ⊚ inj₁) $ cong (flip (subst _) _) $ cong-proj₁-cong₂-, eq₁ eq₂ ⟩∎
g (inj₁ (subst (λ s₁ → Position C₁ s₁ o) eq₁ p)) ∎
lemma₂ = λ (eq₁ : x₁ ≡ y₁) (eq₂ : x₂ ≡ y₂) {o p} →
g (subst (λ { (s₁ , s₂) → Position C₁ s₁ o ⊎ Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) (inj₂ p)) ≡⟨ cong g $ push-subst-inj₂ {y≡z = cong₂ _,_ eq₁ eq₂} _ _ ⟩
g (inj₂ (subst (λ { (s₁ , s₂) → Position C₂ s₂ o })
(cong₂ _,_ eq₁ eq₂) p)) ≡⟨ cong (g ⊚ inj₂) $ subst-∘ _ _ (cong₂ _,_ eq₁ eq₂) ⟩
g (inj₂ (subst (λ s₂ → Position C₂ s₂ o)
(cong proj₂ (cong₂ _,_ eq₁ eq₂)) p)) ≡⟨ cong (g ⊚ inj₂) $ cong (flip (subst _) _) $ cong-proj₂-cong₂-, eq₁ eq₂ ⟩∎
g (inj₂ (subst (λ s₂ → Position C₂ s₂ o) eq₂ p)) ∎
-- The greatest fixpoint ν (C₁ ⊗ C₂) i is contained in the
-- intersection ν C₁ i ∩ ν C₂ i.
ν-⊗⊆ :
∀ {ℓ} {I : Type ℓ} {C₁ C₂ : Container I I} {i} →
ν (C₁ ⊗ C₂) i ⊆ ν C₁ i ∩ ν C₂ i
ν-⊗⊆ {C₁ = C₁} {C₂} {i} =
ν (C₁ ⊗ C₂) i ⊆⟨⟩
⟦ C₁ ⊗ C₂ ⟧ (ν′ (C₁ ⊗ C₂) i) ⊆⟨ ⟦⊗⟧↔ _ C₁ C₂ ⟩
⟦ C₁ ⟧ (ν′ (C₁ ⊗ C₂) i) ∩ ⟦ C₂ ⟧ (ν′ (C₁ ⊗ C₂) i) ⊆⟨ Σ-map (map C₁ ν-⊗⊆₁′) (map C₂ ν-⊗⊆₂′) ⟩
⟦ C₁ ⟧ (ν′ C₁ i) ∩ ⟦ C₂ ⟧ (ν′ C₂ i) ⊆⟨ P.id ⟩∎
ν C₁ i ∩ ν C₂ i ∎
where
ν-⊗⊆₁′ : ν′ (C₁ ⊗ C₂) i ⊆ ν′ C₁ i
force (ν-⊗⊆₁′ x) = proj₁ (ν-⊗⊆ (force x))
ν-⊗⊆₂′ : ν′ (C₁ ⊗ C₂) i ⊆ ν′ C₂ i
force (ν-⊗⊆₂′ x) = proj₂ (ν-⊗⊆ (force x))
-- A disjoint union combinator.
--
-- Similar to a construction in "Containers: Constructing strictly
-- positive types" by Abbott, Altenkirch and Ghani (see
-- Proposition 3.5).
infixr 2 _⊕_
_⊕_ : ∀ {ℓ} {I O : Type ℓ} →
Container I O → Container I O → Container I O
C₁ ⊕ C₂ =
(λ o → Shape C₁ o ⊎ Shape C₂ o)
◁
[ Position C₁ , Position C₂ ]
where
open Container
-- An unfolding lemma for ⟦ C₁ ⊕ C₂ ⟧.
⟦⊕⟧↔ : ∀ {ℓ x} {I O : Type ℓ}
(C₁ C₂ : Container I O) {X : Rel x I} {o} →
⟦ C₁ ⊕ C₂ ⟧ X o ↔ ⟦ C₁ ⟧ X o ⊎ ⟦ C₂ ⟧ X o
⟦⊕⟧↔ C₁ C₂ {X} {o} =
⟦ C₁ ⊕ C₂ ⟧ X o ↔⟨⟩
(∃ λ (s : Shape C₁ o ⊎ Shape C₂ o) →
[ Position C₁ , Position C₂ ] s ⊆ X) ↝⟨ ∃-⊎-distrib-right ⟩
(∃ λ (s : Shape C₁ o) → Position C₁ s ⊆ X) ⊎
(∃ λ (s : Shape C₂ o) → Position C₂ s ⊆ X) ↔⟨⟩
⟦ C₁ ⟧ X o ⊎ ⟦ C₂ ⟧ X o □
where
open Container
-- An unfolding lemma for ⟦ C₁ ⊕ C₂ ⟧₂.
⟦⊕⟧₂↔ :
∀ {k ℓ x} {I : Type ℓ} {X : Rel x I} →
Extensionality? k ℓ ℓ →
∀ (C₁ C₂ : Container I I) (R : ∀ {i} → Rel₂ ℓ (X i)) {i}
(x y : ⟦ C₁ ⊕ C₂ ⟧ X i) →
⟦ C₁ ⊕ C₂ ⟧₂ R (x , y)
↝[ k ]
(curry (⟦ C₁ ⟧₂ R) ⊎-rel curry (⟦ C₂ ⟧₂ R))
(_↔_.to (⟦⊕⟧↔ C₁ C₂) x)
(_↔_.to (⟦⊕⟧↔ C₁ C₂) y)
⟦⊕⟧₂↔ ext C₁ C₂ R (inj₁ x , f) (inj₁ y , g) =
⟦ C₁ ⊕ C₂ ⟧₂ R ((inj₁ x , f) , (inj₁ y , g)) ↔⟨⟩
(∃ λ (eq : inj₁ x ≡ inj₁ y) →
∀ {o} (p : Position C₁ x o) →
R ( f p
, g (subst (λ s → [_,_] {C = λ _ → Rel _ _}
(Position C₁) (Position C₂) s o) eq p)
)) ↔⟨ inverse $ Σ-cong Bijection.≡↔inj₁≡inj₁ (λ _ → Bijection.id) ⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₁ x o) →
R ( f p
, g (subst (λ s → [_,_] {C = λ _ → Rel _ _}
(Position C₁) (Position C₂) s o)
(cong inj₁ eq) p)
)) ↝⟨ (∃-cong λ eq → implicit-∀-cong ext $ ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ x → R (_ , g x)) $ sym $
subst-∘ _ _ eq) ⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₁ x o) →
R ( f p
, g (subst (λ s → Position C₁ s o) eq p)
)) ↔⟨⟩
⟦ C₁ ⟧₂ R ((x , f) , (y , g)) □
where
open Container
⟦⊕⟧₂↔ _ C₁ C₂ R (inj₁ x , f) (inj₂ y , g) =
⟦ C₁ ⊕ C₂ ⟧₂ R ((inj₁ x , f) , (inj₂ y , g)) ↔⟨⟩
(∃ λ (eq : inj₁ x ≡ inj₂ y) → _) ↔⟨ inverse $ Σ-cong (inverse Bijection.≡↔⊎) (λ _ → Bijection.id) ⟩
(∃ λ (eq : ⊥) → _) ↔⟨ Σ-left-zero ⟩
⊥ □
⟦⊕⟧₂↔ _ C₁ C₂ R (inj₂ x , f) (inj₁ y , g) =
⟦ C₁ ⊕ C₂ ⟧₂ R ((inj₂ x , f) , (inj₁ y , g)) ↔⟨⟩
(∃ λ (eq : inj₂ x ≡ inj₁ y) → _) ↔⟨ inverse $ Σ-cong (inverse Bijection.≡↔⊎) (λ _ → Bijection.id) ⟩
(∃ λ (eq : ⊥) → _) ↔⟨ Σ-left-zero ⟩
⊥ □
⟦⊕⟧₂↔ ext C₁ C₂ R (inj₂ x , f) (inj₂ y , g) =
⟦ C₁ ⊕ C₂ ⟧₂ R ((inj₂ x , f) , (inj₂ y , g)) ↔⟨⟩
(∃ λ (eq : inj₂ x ≡ inj₂ y) →
∀ {o} (p : Position C₂ x o) →
R ( f p
, g (subst (λ s → [_,_] {C = λ _ → Rel _ _}
(Position C₁) (Position C₂) s o) eq p)
)) ↔⟨ inverse $ Σ-cong Bijection.≡↔inj₂≡inj₂ (λ _ → Bijection.id) ⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₂ x o) →
R ( f p
, g (subst (λ s → [_,_] {C = λ _ → Rel _ _}
(Position C₁) (Position C₂) s o)
(cong inj₂ eq) p)
)) ↝⟨ (∃-cong λ eq → implicit-∀-cong ext $ ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ x → R (_ , g x)) $ sym $
subst-∘ _ _ eq) ⟩
(∃ λ (eq : x ≡ y) →
∀ {o} (p : Position C₂ x o) →
R ( f p
, g (subst (λ s → Position C₂ s o) eq p)
)) ↔⟨⟩
⟦ C₂ ⟧₂ R ((x , f) , (y , g)) □
where
open Container
mutual
-- A combinator that is similar to the function ⟷ from
-- Section 6.3.4.1 in Pous and Sangiorgi's "Enhancements of the
-- bisimulation proof method".
⟷[_] : ∀ {ℓ} {I : Type ℓ} →
Container (I × I) (I × I) → Container (I × I) (I × I)
⟷[ C ] = C ⟷ C
-- A generalisation of ⟷[_].
infix 1 _⟷_
_⟷_ : ∀ {ℓ} {I : Type ℓ} →
(_ _ : Container (I × I) (I × I)) → Container (I × I) (I × I)
C₁ ⟷ C₂ = C₁ ⊗ reindex swap C₂
-- An unfolding lemma for ⟦ C₁ ⟷ C₂ ⟧.
⟦⟷⟧↔ :
∀ {k ℓ x} {I : Type ℓ} →
Extensionality? k ℓ (ℓ ⊔ x) →
∀ (C₁ C₂ : Container (I × I) (I × I)) {X : Rel₂ x I} {i} →
⟦ C₁ ⟷ C₂ ⟧ X i
↝[ k ]
⟦ C₁ ⟧ X i × (⟦ C₂ ⟧ (X ⁻¹) ⁻¹) i
⟦⟷⟧↔ ext C₁ C₂ {X} {i} =
⟦ C₁ ⟷ C₂ ⟧ X i ↔⟨⟩
⟦ C₁ ⊗ reindex swap C₂ ⟧ X i ↝⟨ ⟦⊗⟧↔ ext C₁ (reindex swap C₂) ⟩
⟦ C₁ ⟧ X i × ⟦ reindex swap C₂ ⟧ X i ↝⟨ ∃-cong (λ _ → ⟦reindex⟧↔ ext C₂) ⟩□
⟦ C₁ ⟧ X i × (⟦ C₂ ⟧ (X ⁻¹) ⁻¹) i □
-- An unfolding lemma for ⟦ C₁ ⟷ C₂ ⟧₂.
⟦⟷⟧₂↔ :
∀ {k ℓ x} {I : Type ℓ} {X : Rel₂ x I} →
Extensionality? k ℓ ℓ →
∀ (C₁ C₂ : Container (I × I) (I × I)) (R : ∀ {i} → Rel₂ ℓ (X i)) {i}
(x y : ⟦ C₁ ⟷ C₂ ⟧ X i) →
let (s₁ , s₂) , f = x
(t₁ , t₂) , g = y
in
⟦ C₁ ⟷ C₂ ⟧₂ R (x , y)
↝[ k ]
⟦ C₁ ⟧₂ R ((s₁ , f ⊚ inj₁) , (t₁ , g ⊚ inj₁))
×
⟦ C₂ ⟧₂ R ( (s₂ , λ p → f (inj₂ (_ , refl , p)))
, (t₂ , λ p → g (inj₂ (_ , refl , p)))
)
⟦⟷⟧₂↔ ext C₁ C₂ R x@((s₁ , s₂) , f) y@((t₁ , t₂) , g) =
⟦ C₁ ⟷ C₂ ⟧₂ R (x , y) ↔⟨⟩
⟦ C₁ ⊗ reindex swap C₂ ⟧₂ R (x , y) ↝⟨ ⟦⊗⟧₂↔ ext C₁ (reindex swap C₂) R _ (_ , g) ⟩
⟦ C₁ ⟧₂ R ((s₁ , f ⊚ inj₁) , (t₁ , g ⊚ inj₁))
×
⟦ reindex swap C₂ ⟧₂ R ((s₂ , f ⊚ inj₂) , (t₂ , g ⊚ inj₂)) ↝⟨ ∃-cong (λ _ → ⟦reindex⟧₂↔ ext C₂ _ R _ (_ , g ⊚ inj₂)) ⟩□
⟦ C₁ ⟧₂ R ((s₁ , f ⊚ inj₁) , (t₁ , g ⊚ inj₁))
×
⟦ C₂ ⟧₂ R ( (s₂ , λ p → f (inj₂ (_ , refl , p)))
, (t₂ , λ p → g (inj₂ (_ , refl , p)))
) □
-- The greatest fixpoint ν (C₁ ⟷ C₂) i is contained in the
-- intersection ν C₁ i ∩ ν C₂ i ⁻¹.
ν-↔⊆ : ∀ {ℓ} {I : Type ℓ} {C₁ C₂ : Container (I × I) (I × I)} {i} →
ν (C₁ ⟷ C₂) i ⊆ ν C₁ i ∩ ν C₂ i ⁻¹
ν-↔⊆ {C₁ = C₁} {C₂} {i} =
ν (C₁ ⟷ C₂) i ⊆⟨⟩
ν (C₁ ⊗ reindex swap C₂) i ⊆⟨ ν-⊗⊆ ⟩
ν C₁ i ∩ ν (reindex swap C₂) i ⊆⟨ Σ-map P.id (_⇔_.to (ν-reindex⇔ refl)) ⟩∎
ν C₁ i ∩ ν C₂ i ⁻¹ ∎
-- The following three lemmas correspond to the second part of
-- Exercise 6.3.24 in Pous and Sangiorgi's "Enhancements of the
-- bisimulation proof method".
-- Post-fixpoints of the container reindex₂ swap id ⊗ C are
-- post-fixpoints of ⟷[ C ].
⊆reindex₂-swap-⊗→⊆⟷ :
∀ {ℓ r} {I : Type ℓ} {C : Container (I × I) (I × I)} {R : Rel₂ r I} →
R ⊆ ⟦ reindex₂ swap id ⊗ C ⟧ R → R ⊆ ⟦ ⟷[ C ] ⟧ R
⊆reindex₂-swap-⊗→⊆⟷ {C = C} {R} R⊆ =
R ⊆⟨ (λ x → lemma₁ x , lemma₂ x) ⟩
⟦ C ⟧ R ∩ R ⁻¹ ⊆⟨ Σ-map P.id lemma₃ ⟩
⟦ C ⟧ R ∩ ⟦ C ⟧ (R ⁻¹) ⁻¹ ⊆⟨ _⇔_.from (⟦⟷⟧↔ _ C C) ⟩∎
⟦ ⟷[ C ] ⟧ R ∎
where
lemma₀ =
R ⊆⟨ R⊆ ⟩
⟦ reindex₂ swap id ⊗ C ⟧ R ⊆⟨ ⟦⊗⟧↔ _ (reindex₂ swap id) C ⟩∎
⟦ reindex₂ swap id ⟧ R ∩ ⟦ C ⟧ R ∎
lemma₁ =
R ⊆⟨ lemma₀ ⟩
⟦ reindex₂ swap id ⟧ R ∩ ⟦ C ⟧ R ⊆⟨ proj₂ ⟩∎
⟦ C ⟧ R ∎
lemma₂ =
R ⊆⟨ lemma₀ ⟩
⟦ reindex₂ swap id ⟧ R ∩ ⟦ C ⟧ R ⊆⟨ proj₁ ⟩
⟦ reindex₂ swap id ⟧ R ⊆⟨ P.id ⟩
⟦ id ⟧ R ⁻¹ ⊆⟨ _⇔_.to (⟦id⟧↔ _) ⟩∎
R ⁻¹ ∎
lemma₃ =
R ⊆⟨ lemma₁ ⟩
⟦ C ⟧ R ⊆⟨ map C lemma₂ ⟩∎
⟦ C ⟧ (R ⁻¹) ∎
-- The symmetric closure of a post-fixpoint of ⟷[ C ] is a
-- post-fixpoint of reindex₂ swap id ⊗ C.
⊆⟷→∪-swap⊆reindex₂-swap-⊗ :
∀ {ℓ r} {I : Type ℓ} {C : Container (I × I) (I × I)} {R : Rel₂ r I} →
R ⊆ ⟦ ⟷[ C ] ⟧ R →
R ∪ R ⁻¹ ⊆ ⟦ reindex₂ swap id ⊗ C ⟧ (R ∪ R ⁻¹)
⊆⟷→∪-swap⊆reindex₂-swap-⊗ {C = C} {R} R⊆ =
R ∪ R ⁻¹ ⊆⟨ (λ x → lemma₁ x , lemma₂ x) ⟩
⟦ reindex₂ swap id ⟧ (R ∪ R ⁻¹) ∩ ⟦ C ⟧ (R ∪ R ⁻¹) ⊆⟨ _⇔_.from (⟦⊗⟧↔ _ (reindex₂ swap id) C) ⟩∎
⟦ reindex₂ swap id ⊗ C ⟧ (R ∪ R ⁻¹) ∎
where
lemma₁ =
R ∪ R ⁻¹ ⊆⟨ [ inj₂ , inj₁ ] ⟩
R ⁻¹ ∪ R ⊆⟨ P.id ⟩
R ⁻¹ ∪ R ⁻¹ ⁻¹ ⊆⟨ P.id ⟩
(R ∪ R ⁻¹) ⁻¹ ⊆⟨ _⇔_.from (⟦id⟧↔ _) ⟩
⟦ id ⟧ (R ∪ R ⁻¹) ⁻¹ ⊆⟨ P.id ⟩∎
⟦ reindex₂ swap id ⟧ (R ∪ R ⁻¹) ∎
lemma₂ =
R ∪ R ⁻¹ ⊆⟨ ⊎-map R⊆ R⊆ ⟩
⟦ ⟷[ C ] ⟧ R ∪ ⟦ ⟷[ C ] ⟧ R ⁻¹ ⊆⟨ ⊎-map (_⇔_.to (⟦⟷⟧↔ _ C C)) (_⇔_.to (⟦⟷⟧↔ _ C C)) ⟩
⟦ C ⟧ R ∩ ⟦ C ⟧ (R ⁻¹) ⁻¹ ∪ ⟦ C ⟧ R ⁻¹ ∩ ⟦ C ⟧ (R ⁻¹) ⊆⟨ ⊎-map proj₁ proj₂ ⟩
⟦ C ⟧ R ∪ ⟦ C ⟧ (R ⁻¹) ⊆⟨ [ map C inj₁ , map C inj₂ ] ⟩∎
⟦ C ⟧ (R ∪ R ⁻¹) ∎
-- The greatest fixpoint of ⟷[ C ] is pointwise logically equivalent
-- to the greatest fixpoint of reindex₂ swap id ⊗ C.
--
-- Note that this proof is not necessarily size-preserving. TODO:
-- Figure out if the proof can be made size-preserving.
ν-⟷⇔ :
∀ {ℓ} {I : Type ℓ} {C : Container (I × I) (I × I)} {p} →
ν ⟷[ C ] ∞ p ⇔ ν (reindex₂ swap id ⊗ C) ∞ p
ν-⟷⇔ {C = C} = record
{ to =
let R = ν ⟷[ C ] ∞ in $⟨ (λ {_} → ν-out _) ⟩
R ⊆ ⟦ ⟷[ C ] ⟧ R ↝⟨ ⊆⟷→∪-swap⊆reindex₂-swap-⊗ ⟩
R ∪ R ⁻¹ ⊆ ⟦ reindex₂ swap id ⊗ C ⟧ (R ∪ R ⁻¹) ↝⟨ unfold _ ⟩
R ∪ R ⁻¹ ⊆ ν (reindex₂ swap id ⊗ C) ∞ ↝⟨ (λ hyp {_} x → hyp (inj₁ x)) ⟩□
R ⊆ ν (reindex₂ swap id ⊗ C) ∞ □
; from =
let R = ν (reindex₂ swap id ⊗ C) ∞ in $⟨ (λ {_} → ν-out _) ⟩
R ⊆ ⟦ reindex₂ swap id ⊗ C ⟧ R ↝⟨ ⊆reindex₂-swap-⊗→⊆⟷ ⟩
R ⊆ ⟦ ⟷[ C ] ⟧ R ↝⟨ unfold _ ⟩□
R ⊆ ν ⟷[ C ] ∞ □
}
| {
"alphanum_fraction": 0.365741475,
"avg_line_length": 37.3814229249,
"ext": "agda",
"hexsha": "2030025656da349e5cff7fe15c815afc7cf44d60",
"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": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Indexed-container/Combinators.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"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/up-to",
"max_issues_repo_path": "src/Indexed-container/Combinators.agda",
"max_line_length": 148,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Indexed-container/Combinators.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 16061,
"size": 37830
} |
module Lib.Vec where
open import Common.Nat renaming (zero to Z; suc to S)
open import Lib.Fin
open import Common.Unit
import Common.List -- using (List ; [] ; _∷_)
data Vec (A : Set) : Nat -> Set where
_∷_ : forall {n} -> A -> Vec A n -> Vec A (S n)
[] : Vec A Z
infixr 30 _++_
_++_ : {A : Set}{m n : Nat} -> Vec A m -> Vec A n -> Vec A (m + n)
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
snoc : {A : Set}{n : Nat} -> Vec A n -> A -> Vec A (S n)
snoc [] e = e ∷ []
snoc (x ∷ xs) e = x ∷ snoc xs e
length : {A : Set}{n : Nat} -> Vec A n -> Nat
length [] = Z
length (x ∷ xs) = 1 + length xs
length' : {A : Set}{n : Nat} -> Vec A n -> Nat
length' {n = n} _ = n
zipWith3 : ∀ {A B C D n} -> (A -> B -> C -> D) -> Vec A n -> Vec B n -> Vec C n -> Vec D n
zipWith3 f [] [] [] = []
zipWith3 f (x ∷ xs) (y ∷ ys) (z ∷ zs) = f x y z ∷ zipWith3 f xs ys zs
zipWith : ∀ {A B C n} -> (A -> B -> C) -> Vec A n -> Vec B n -> {u : Unit} -> Vec C n
zipWith _ [] [] = []
zipWith f (x ∷ xs) (y ∷ ys) = f x y ∷ zipWith f xs ys {u = unit}
_!_ : ∀ {A n} -> Vec A n -> Fin n -> A
(x ∷ xs) ! fz = x
(_ ∷ xs) ! fs n = xs ! n
[] ! ()
_[_]=_ : {A : Set}{n : Nat} -> Vec A n -> Fin n -> A -> Vec A n
(a ∷ as) [ fz ]= e = e ∷ as
(a ∷ as) [ fs n ]= e = a ∷ (as [ n ]= e)
[] [ () ]= e
map : ∀ {A B n}(f : A -> B)(xs : Vec A n) -> Vec B n
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
forgetL : {A : Set}{n : Nat} -> Vec A n -> Common.List.List A
forgetL [] = Common.List.[]
forgetL (x ∷ xs) = x Common.List.∷ forgetL xs
rem : {A : Set}(xs : Common.List.List A) -> Vec A (Common.List.length xs)
rem Common.List.[] = []
rem (x Common.List.∷ xs) = x ∷ rem xs
| {
"alphanum_fraction": 0.4635879218,
"avg_line_length": 29.1206896552,
"ext": "agda",
"hexsha": "b59038a8a66d8718b82426e2acf245cd2ff57af7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Compiler/simple/Lib/Vec.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Compiler/simple/Lib/Vec.agda",
"max_line_length": 90,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Compiler/simple/Lib/Vec.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z",
"num_tokens": 699,
"size": 1689
} |
{-# OPTIONS --without-K #-}
module Agda.Builtin.Nat where
open import Agda.Builtin.Bool
data Nat : Set where
zero : Nat
suc : (n : Nat) → Nat
{-# BUILTIN NATURAL Nat #-}
infix 4 _==_ _<_
infixl 6 _+_ _-_
infixl 7 _*_
_+_ : Nat → Nat → Nat
zero + m = m
suc n + m = suc (n + m)
{-# BUILTIN NATPLUS _+_ #-}
_-_ : Nat → Nat → Nat
n - zero = n
zero - suc m = zero
suc n - suc m = n - m
{-# BUILTIN NATMINUS _-_ #-}
_*_ : Nat → Nat → Nat
zero * m = zero
suc n * m = m + n * m
{-# BUILTIN NATTIMES _*_ #-}
_==_ : Nat → Nat → Bool
zero == zero = true
suc n == suc m = n == m
_ == _ = false
{-# BUILTIN NATEQUALS _==_ #-}
_<_ : Nat → Nat → Bool
_ < zero = false
zero < suc _ = true
suc n < suc m = n < m
{-# BUILTIN NATLESS _<_ #-}
-- Helper function div-helper for Euclidean division.
---------------------------------------------------------------------------
--
-- div-helper computes n / 1+m via iteration on n.
--
-- n div (suc m) = div-helper 0 m n m
--
-- The state of the iterator has two accumulator variables:
--
-- k: The quotient, returned once n=0. Initialized to 0.
--
-- j: A counter, initialized to the divisor m, decreased on each iteration step.
-- Once it reaches 0, the quotient k is increased and j reset to m,
-- starting the next countdown.
--
-- Under the precondition j ≤ m, the invariant is
--
-- div-helper k m n j = k + (n + m - j) div (1 + m)
div-helper : (k m n j : Nat) → Nat
div-helper k m zero j = k
div-helper k m (suc n) zero = div-helper (suc k) m n m
div-helper k m (suc n) (suc j) = div-helper k m n j
{-# BUILTIN NATDIVSUCAUX div-helper #-}
-- Proof of the invariant by induction on n.
--
-- clause 1: div-helper k m 0 j
-- = k by definition
-- = k + (0 + m - j) div (1 + m) since m - j < 1 + m
--
-- clause 2: div-helper k m (1 + n) 0
-- = div-helper (1 + k) m n m by definition
-- = 1 + k + (n + m - m) div (1 + m) by induction hypothesis
-- = 1 + k + n div (1 + m) by simplification
-- = k + (n + (1 + m)) div (1 + m) by expansion
-- = k + (1 + n + m - 0) div (1 + m) by expansion
--
-- clause 3: div-helper k m (1 + n) (1 + j)
-- = div-helper k m n j by definition
-- = k + (n + m - j) div (1 + m) by induction hypothesis
-- = k + ((1 + n) + m - (1 + j)) div (1 + m) by expansion
--
-- Q.e.d.
-- Helper function mod-helper for the remainder computation.
---------------------------------------------------------------------------
--
-- (Analogous to div-helper.)
--
-- mod-helper computes n % 1+m via iteration on n.
--
-- n mod (suc m) = mod-helper 0 m n m
--
-- The invariant is:
--
-- m = k + j ==> mod-helper k m n j = (n + k) mod (1 + m).
mod-helper : (k m n j : Nat) → Nat
mod-helper k m zero j = k
mod-helper k m (suc n) zero = mod-helper 0 m n m
mod-helper k m (suc n) (suc j) = mod-helper (suc k) m n j
{-# BUILTIN NATMODSUCAUX mod-helper #-}
-- Proof of the invariant by induction on n.
--
-- clause 1: mod-helper k m 0 j
-- = k by definition
-- = (0 + k) mod (1 + m) since m = k + j, thus k < m
--
-- clause 2: mod-helper k m (1 + n) 0
-- = mod-helper 0 m n m by definition
-- = (n + 0) mod (1 + m) by induction hypothesis
-- = (n + (1 + m)) mod (1 + m) by expansion
-- = (1 + n) + k) mod (1 + m) since k = m (as l = 0)
--
-- clause 3: mod-helper k m (1 + n) (1 + j)
-- = mod-helper (1 + k) m n j by definition
-- = (n + (1 + k)) mod (1 + m) by induction hypothesis
-- = ((1 + n) + k) mod (1 + m) by commutativity
--
-- Q.e.d.
| {
"alphanum_fraction": 0.466768138,
"avg_line_length": 29.4179104478,
"ext": "agda",
"hexsha": "798c28194e67f0a9dcf40434678c1ec1c2fbaffb",
"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": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "caryoscelus/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"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": "caryoscelus/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Nat.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "caryoscelus/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1256,
"size": 3942
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Builtin.List
open import Agda.Builtin.Nat
infixl 6 _∷ʳ_
_∷ʳ_ : {A : Set} → List A → A → List A
[] ∷ʳ x = x ∷ []
(hd ∷ tl) ∷ʳ x = hd ∷ tl ∷ʳ x
infixl 5 _∷ʳ′_
data InitLast {A : Set} : List A → Set where
[] : InitLast []
_∷ʳ′_ : (xs : List A) (x : A) → InitLast (xs ∷ʳ x)
initLast : {A : Set} (xs : List A) → InitLast xs
initLast [] = []
initLast (x ∷ xs) with initLast xs
... | [] = [] ∷ʳ′ x
... | ys ∷ʳ′ y = (x ∷ ys) ∷ʳ′ y
f : (xs : List Nat) → Set
f xs with initLast xs
... | [] = {!!}
... | xs ∷ʳ′ x = {!!}
-- ^ Shadowing a variable that is bound implicitly in the `...` is allowed
| {
"alphanum_fraction": 0.5043478261,
"avg_line_length": 23,
"ext": "agda",
"hexsha": "bbe861242d967919258a79239601229fd551125e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/Issue4704.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/Issue4704.agda",
"max_line_length": 74,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/Issue4704.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": 690
} |
open import Nat
open import Prelude
open import core
open import contexts
open import progress
open import htype-decidable
open import lemmas-complete
module complete-progress where
-- as in progress, we define a datatype for the possible outcomes of
-- progress for readability.
data okc : (d : ihexp) (Δ : hctx) → Set where
V : ∀{d Δ} → d val → okc d Δ
S : ∀{d Δ} → Σ[ d' ∈ ihexp ] (d ↦ d') → okc d Δ
complete-progress : {Δ : hctx} {d : ihexp} {τ : htyp} →
Δ , ∅ ⊢ d :: τ →
d dcomplete →
okc d Δ
complete-progress wt comp with progress wt
complete-progress wt comp | I x = abort (lem-ind-comp comp x)
complete-progress wt comp | S x = S x
complete-progress wt comp | BV (BVVal x) = V x
complete-progress wt (DCCast comp x₂ ()) | BV (BVHoleCast x x₁)
complete-progress (TACast wt x) (DCCast comp x₃ x₄) | BV (BVArrCast x₁ x₂) = abort (x₁ (complete-consistency x x₃ x₄))
| {
"alphanum_fraction": 0.6203703704,
"avg_line_length": 34.7142857143,
"ext": "agda",
"hexsha": "16959b2e1548eaa937d0962c938eb461bf3fbf2e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "complete-progress.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "complete-progress.agda",
"max_line_length": 120,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "complete-progress.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 306,
"size": 972
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.Natrec {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.RedSteps
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Application
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Properties
import Definition.LogicalRelation.Substitution.Irrelevance as S
open import Definition.LogicalRelation.Substitution.Reflexivity
open import Definition.LogicalRelation.Substitution.Weakening
open import Definition.LogicalRelation.Substitution.Introductions.Nat
open import Definition.LogicalRelation.Substitution.Introductions.Pi
open import Definition.LogicalRelation.Substitution.Introductions.SingleSubst
open import Tools.Embedding
open import Tools.Product
open import Tools.Empty
import Tools.PropositionalEquality as PE
-- Natural recursion closure reduction (requires reducible terms and equality).
natrec-subst* : ∀ {Γ C c g n n′ l} → Γ ∙ ℕ ⊢ C → Γ ⊢ c ∷ C [ zero ]
→ Γ ⊢ g ∷ Π ℕ ▹ (C ▹▹ C [ suc (var 0) ]↑)
→ Γ ⊢ n ⇒* n′ ∷ ℕ
→ ([ℕ] : Γ ⊩⟨ l ⟩ ℕ)
→ Γ ⊩⟨ l ⟩ n′ ∷ ℕ / [ℕ]
→ (∀ {t t′} → Γ ⊩⟨ l ⟩ t ∷ ℕ / [ℕ]
→ Γ ⊩⟨ l ⟩ t′ ∷ ℕ / [ℕ]
→ Γ ⊩⟨ l ⟩ t ≡ t′ ∷ ℕ / [ℕ]
→ Γ ⊢ C [ t ] ≡ C [ t′ ])
→ Γ ⊢ natrec C c g n ⇒* natrec C c g n′ ∷ C [ n ]
natrec-subst* C c g (id x) [ℕ] [n′] prop = id (natrecⱼ C c g x)
natrec-subst* C c g (x ⇨ n⇒n′) [ℕ] [n′] prop =
let q , w = redSubst*Term n⇒n′ [ℕ] [n′]
a , s = redSubstTerm x [ℕ] q
in natrec-subst C c g x ⇨ conv* (natrec-subst* C c g n⇒n′ [ℕ] [n′] prop)
(prop q a (symEqTerm [ℕ] s))
-- Helper functions for construction of valid type for the successor case of natrec.
sucCase₃ : ∀ {Γ l} ([Γ] : ⊩ᵛ Γ)
([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])
→ Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ suc (var 0) ∷ ℕ / [Γ] ∙″ [ℕ]
/ (λ {Δ} {σ} → wk1ᵛ {ℕ} {ℕ} [Γ] [ℕ] [ℕ] {Δ} {σ})
sucCase₃ {Γ} {l} [Γ] [ℕ] {Δ} {σ} =
sucᵛ {n = var 0} {l = l} (_∙″_ {A = ℕ} [Γ] [ℕ])
(λ {Δ} {σ} → wk1ᵛ {ℕ} {ℕ} [Γ] [ℕ] [ℕ] {Δ} {σ})
(λ ⊢Δ [σ] → proj₂ [σ] , (λ [σ′] [σ≡σ′] → proj₂ [σ≡σ′])) {Δ} {σ}
sucCase₂ : ∀ {F Γ l} ([Γ] : ⊩ᵛ Γ)
([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])
([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))
→ Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F [ suc (var 0) ]↑ / ([Γ] ∙″ [ℕ])
sucCase₂ {F} {Γ} {l} [Γ] [ℕ] [F] =
subst↑S {ℕ} {F} {suc (var 0)} [Γ] [ℕ] [F]
(λ {Δ} {σ} → sucCase₃ [Γ] [ℕ] {Δ} {σ})
sucCase₁ : ∀ {F Γ l} ([Γ] : ⊩ᵛ Γ)
([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])
([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))
→ Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F ▹▹ F [ suc (var 0) ]↑ / ([Γ] ∙″ [ℕ])
sucCase₁ {F} {Γ} {l} [Γ] [ℕ] [F] =
▹▹ᵛ {F} {F [ suc (var 0) ]↑} (_∙″_ {A = ℕ} [Γ] [ℕ]) [F]
(sucCase₂ {F} [Γ] [ℕ] [F])
-- Construct a valid type for the successor case of natrec.
sucCase : ∀ {F Γ l} ([Γ] : ⊩ᵛ Γ)
([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])
([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))
→ Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ]
sucCase {F} {Γ} {l} [Γ] [ℕ] [F] =
Πᵛ {ℕ} {F ▹▹ F [ suc (var 0) ]↑} [Γ] [ℕ]
(sucCase₁ {F} [Γ] [ℕ] [F])
-- Construct a valid type equality for the successor case of natrec.
sucCaseCong : ∀ {F F′ Γ l} ([Γ] : ⊩ᵛ Γ)
([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])
([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))
([F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F′ / ([Γ] ∙″ [ℕ]))
([F≡F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F ≡ F′ / [Γ] ∙″ [ℕ] / [F])
→ Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
≡ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)
/ [Γ] / sucCase {F} [Γ] [ℕ] [F]
sucCaseCong {F} {F′} {Γ} {l} [Γ] [ℕ] [F] [F′] [F≡F′] =
Π-congᵛ {ℕ} {F ▹▹ F [ suc (var 0) ]↑} {ℕ} {F′ ▹▹ F′ [ suc (var 0) ]↑}
[Γ] [ℕ] (sucCase₁ {F} [Γ] [ℕ] [F]) [ℕ] (sucCase₁ {F′} [Γ] [ℕ] [F′])
(reflᵛ {ℕ} [Γ] [ℕ])
(▹▹-congᵛ {F} {F′} {F [ suc (var 0) ]↑} {F′ [ suc (var 0) ]↑}
(_∙″_ {A = ℕ} [Γ] [ℕ]) [F] [F′] [F≡F′]
(sucCase₂ {F} [Γ] [ℕ] [F]) (sucCase₂ {F′} [Γ] [ℕ] [F′])
(subst↑SEq {ℕ} {F} {F′} {suc (var 0)} {suc (var 0)}
[Γ] [ℕ] [F] [F′] [F≡F′]
(λ {Δ} {σ} → sucCase₃ [Γ] [ℕ] {Δ} {σ})
(λ {Δ} {σ} → sucCase₃ [Γ] [ℕ] {Δ} {σ})
(λ {Δ} {σ} →
reflᵗᵛ {ℕ} {suc (var 0)} (_∙″_ {A = ℕ} [Γ] [ℕ])
(λ {Δ} {σ} → wk1ᵛ {ℕ} {ℕ} [Γ] [ℕ] [ℕ] {Δ} {σ})
(λ {Δ} {σ} → sucCase₃ [Γ] [ℕ] {Δ} {σ})
{Δ} {σ})))
-- Reducibility of natural recursion under a valid substitution.
natrecTerm : ∀ {F z s n Γ Δ σ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / _∙″_ {l = l} [Γ] (ℕᵛ [Γ]))
([F₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] / [Γ])
([F₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ])
([z] : Γ ⊩ᵛ⟨ l ⟩ z ∷ F [ zero ] / [Γ] / [F₀])
([s] : Γ ⊩ᵛ⟨ l ⟩ s ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
/ [Γ] / [F₊])
(⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σn] : Δ ⊩⟨ l ⟩ n ∷ ℕ / ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))
→ Δ ⊩⟨ l ⟩ natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) n
∷ subst (liftSubst σ) F [ n ]
/ irrelevance′ (PE.sym (singleSubstComp n σ F))
(proj₁ ([F] ⊢Δ ([σ] , [σn])))
natrecTerm {F} {z} {s} {n} {Γ} {Δ} {σ} {l} [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ]
(ιx (ℕₜ .(suc m) d n≡n (sucᵣ {m} [m]))) =
let [ℕ] = ℕᵛ {l = l} [Γ]
[σℕ] = proj₁ ([ℕ] ⊢Δ [σ])
⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))
⊢F = escape (proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ])))
⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)
(escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))
⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)
(escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))
⊢m = escapeTerm {l = l} [σℕ] (ιx [m])
[σsm] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) [σℕ]
(ιx (ℕₜ (suc m) (idRedTerm:*: (sucⱼ ⊢m)) n≡n (sucᵣ [m])))
[σn] = ℕₜ (suc m) d n≡n (sucᵣ [m])
[σn]′ , [σn≡σsm] = redSubst*Term (redₜ d) [σℕ] [σsm]
[σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , ιx [σn]))
[σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′
[σFₛₘ] = irrelevance′ (PE.sym (singleSubstComp (suc m) σ F))
(proj₁ ([F] ⊢Δ ([σ] , [σsm])))
[Fₙ≡Fₛₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (singleSubstComp (suc m) σ F))
[σFₙ]′ [σFₙ]
(proj₂ ([F] ⊢Δ ([σ] , ιx [σn])) ([σ] , [σsm])
(reflSubst [Γ] ⊢Δ [σ] , [σn≡σsm]))
[σFₘ] = irrelevance′ (PE.sym (PE.trans (substCompEq F)
(substSingletonComp F)))
(proj₁ ([F] ⊢Δ ([σ] , ιx [m])))
[σFₛₘ]′ = irrelevance′ (natrecIrrelevantSubst F z s m σ)
(proj₁ ([F] ⊢Δ ([σ] , [σsm])))
[σF₊ₘ] = substSΠ₁ (proj₁ ([F₊] ⊢Δ [σ])) [σℕ] (ιx [m])
natrecM = appTerm [σFₘ] [σFₛₘ]′ [σF₊ₘ]
(appTerm [σℕ] [σF₊ₘ]
(proj₁ ([F₊] ⊢Δ [σ]))
(proj₁ ([s] ⊢Δ [σ])) (ιx [m]))
(natrecTerm {F} {z} {s} {m} {σ = σ}
[Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ] (ιx [m]))
natrecM′ = irrelevanceTerm′ (PE.trans
(PE.sym (natrecIrrelevantSubst F z s m σ))
(PE.sym (singleSubstComp (suc m) σ F)))
[σFₛₘ]′ [σFₛₘ] natrecM
reduction = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) [σℕ] [σsm]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ F))
(PE.sym (singleSubstComp t′ σ F))
(≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))
(proj₂ ([F] ⊢Δ ([σ] , [t]))
([σ] , [t′])
(reflSubst [Γ] ⊢Δ [σ] ,
[t≡t′])))))
⇨∷* (conv* (natrec-suc ⊢m ⊢F ⊢z ⊢s
⇨ id (escapeTerm [σFₛₘ] natrecM′))
(sym (≅-eq (escapeEq [σFₙ] [Fₙ≡Fₛₘ]))))
in proj₁ (redSubst*Term reduction [σFₙ]
(convTerm₂ [σFₙ] [σFₛₘ] [Fₙ≡Fₛₘ] natrecM′))
natrecTerm {F} {z} {s} {n} {Γ} {Δ} {σ} {l} [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ]
(ιx (ℕₜ .zero d n≡n zeroᵣ)) =
let [ℕ] = ℕᵛ {l = l} [Γ]
[σℕ] = proj₁ ([ℕ] ⊢Δ [σ])
⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))
[σF] = proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ]))
⊢F = escape [σF]
⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)
(escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))
⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)
(escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))
[σ0] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) [σℕ]
(ιx (ℕₜ zero (idRedTerm:*: (zeroⱼ ⊢Δ)) n≡n zeroᵣ))
[σn]′ , [σn≡σ0] = redSubst*Term (redₜ d) (proj₁ ([ℕ] ⊢Δ [σ])) [σ0]
[σn] = ιx (ℕₜ zero d n≡n zeroᵣ)
[σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , [σn]))
[σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′
[Fₙ≡F₀]′ = proj₂ ([F] ⊢Δ ([σ] , [σn])) ([σ] , [σ0])
(reflSubst [Γ] ⊢Δ [σ] , [σn≡σ0])
[Fₙ≡F₀] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (substCompEq F))
[σFₙ]′ [σFₙ] [Fₙ≡F₀]′
[Fₙ≡F₀]″ = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.trans (substConcatSingleton′ F)
(PE.sym (singleSubstComp zero σ F)))
[σFₙ]′ [σFₙ] [Fₙ≡F₀]′
[σz] = proj₁ ([z] ⊢Δ [σ])
reduction = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) (proj₁ ([ℕ] ⊢Δ [σ])) [σ0]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ F))
(PE.sym (singleSubstComp t′ σ F))
(≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))
(proj₂ ([F] ⊢Δ ([σ] , [t]))
([σ] , [t′])
(reflSubst [Γ] ⊢Δ [σ] ,
[t≡t′])))))
⇨∷* (conv* (natrec-zero ⊢F ⊢z ⊢s ⇨ id ⊢z)
(sym (≅-eq (escapeEq [σFₙ] [Fₙ≡F₀]″))))
in proj₁ (redSubst*Term reduction [σFₙ]
(convTerm₂ [σFₙ] (proj₁ ([F₀] ⊢Δ [σ])) [Fₙ≡F₀] [σz]))
natrecTerm {F} {z} {s} {n} {Γ} {Δ} {σ} {l} [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ]
(ιx (ℕₜ m d n≡n (ne (neNfₜ neM ⊢m m≡m)))) =
let [ℕ] = ℕᵛ {l = l} [Γ]
[σℕ] = proj₁ ([ℕ] ⊢Δ [σ])
⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))
[σn] = ιx (ℕₜ m d n≡n (ne (neNfₜ neM ⊢m m≡m)))
[σF] = proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ]))
⊢F = escape [σF]
⊢F≡F = escapeEq [σF] (reflEq [σF])
⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)
(escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))
⊢z≡z = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x) (singleSubstLift F zero)
(escapeTermEq (proj₁ ([F₀] ⊢Δ [σ]))
(reflEqTerm (proj₁ ([F₀] ⊢Δ [σ]))
(proj₁ ([z] ⊢Δ [σ]))))
⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)
(escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))
⊢s≡s = PE.subst (λ x → Δ ⊢ subst σ s ≅ subst σ s ∷ x) (natrecSucCase σ F)
(escapeTermEq (proj₁ ([F₊] ⊢Δ [σ]))
(reflEqTerm (proj₁ ([F₊] ⊢Δ [σ]))
(proj₁ ([s] ⊢Δ [σ]))))
[σm] = neuTerm [σℕ] neM ⊢m m≡m
[σn]′ , [σn≡σm] = redSubst*Term (redₜ d) [σℕ] [σm]
[σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , [σn]))
[σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′
[σFₘ] = irrelevance′ (PE.sym (singleSubstComp m σ F))
(proj₁ ([F] ⊢Δ ([σ] , [σm])))
[Fₙ≡Fₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (singleSubstComp m σ F)) [σFₙ]′ [σFₙ]
((proj₂ ([F] ⊢Δ ([σ] , [σn]))) ([σ] , [σm])
(reflSubst [Γ] ⊢Δ [σ] , [σn≡σm]))
natrecM = neuTerm [σFₘ] (natrecₙ neM) (natrecⱼ ⊢F ⊢z ⊢s ⊢m)
(~-natrec ⊢F≡F ⊢z≡z ⊢s≡s m≡m)
reduction = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) [σℕ] [σm]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ F))
(PE.sym (singleSubstComp t′ σ F))
(≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))
(proj₂ ([F] ⊢Δ ([σ] , [t]))
([σ] , [t′])
(reflSubst [Γ] ⊢Δ [σ] ,
[t≡t′])))))
in proj₁ (redSubst*Term reduction [σFₙ]
(convTerm₂ [σFₙ] [σFₘ] [Fₙ≡Fₘ] natrecM))
-- Reducibility of natural recursion congurence under a valid substitution equality.
natrec-congTerm : ∀ {F F′ z z′ s s′ n m Γ Δ σ σ′ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / _∙″_ {l = l} [Γ] (ℕᵛ [Γ]))
([F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F′ / _∙″_ {l = l} [Γ] (ℕᵛ [Γ]))
([F≡F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F ≡ F′ / _∙″_ {l = l} [Γ] (ℕᵛ [Γ])
/ [F])
([F₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] / [Γ])
([F′₀] : Γ ⊩ᵛ⟨ l ⟩ F′ [ zero ] / [Γ])
([F₀≡F′₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] ≡ F′ [ zero ] / [Γ] / [F₀])
([F₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
/ [Γ])
([F′₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)
/ [Γ])
([F₊≡F₊′] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
≡ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)
/ [Γ] / [F₊])
([z] : Γ ⊩ᵛ⟨ l ⟩ z ∷ F [ zero ] / [Γ] / [F₀])
([z′] : Γ ⊩ᵛ⟨ l ⟩ z′ ∷ F′ [ zero ] / [Γ] / [F′₀])
([z≡z′] : Γ ⊩ᵛ⟨ l ⟩ z ≡ z′ ∷ F [ zero ] / [Γ] / [F₀])
([s] : Γ ⊩ᵛ⟨ l ⟩ s ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
/ [Γ] / [F₊])
([s′] : Γ ⊩ᵛ⟨ l ⟩ s′
∷ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)
/ [Γ] / [F′₊])
([s≡s′] : Γ ⊩ᵛ⟨ l ⟩ s ≡ s′
∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
/ [Γ] / [F₊])
(⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ)
([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ])
([σn] : Δ ⊩⟨ l ⟩ n ∷ ℕ / ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))
([σm] : Δ ⊩⟨ l ⟩ m ∷ ℕ / ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))
([σn≡σm] : Δ ⊩⟨ l ⟩ n ≡ m ∷ ℕ / ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))
→ Δ ⊩⟨ l ⟩ natrec (subst (liftSubst σ) F)
(subst σ z) (subst σ s) n
≡ natrec (subst (liftSubst σ′) F′)
(subst σ′ z′) (subst σ′ s′) m
∷ subst (liftSubst σ) F [ n ]
/ irrelevance′ (PE.sym (singleSubstComp n σ F))
(proj₁ ([F] ⊢Δ ([σ] , [σn])))
natrec-congTerm {F} {F′} {z} {z′} {s} {s′} {n} {m} {Γ} {Δ} {σ} {σ′} {l}
[Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ .(suc n′) d n≡n (sucᵣ {n′} [n′])))
(ιx (ℕₜ .(suc m′) d′ m≡m (sucᵣ {m′} [m′])))
(ιx (ℕₜ₌ .(suc n″) .(suc m″) d₁ d₁′
t≡u (sucᵣ {n″} {m″} [n″≡m″]))) =
let n″≡n′ = suc-PE-injectivity (whrDet*Term (redₜ d₁ , sucₙ) (redₜ d , sucₙ))
m″≡m′ = suc-PE-injectivity (whrDet*Term (redₜ d₁′ , sucₙ) (redₜ d′ , sucₙ))
[ℕ] = ℕᵛ {l = l} [Γ]
[σℕ] = proj₁ ([ℕ] ⊢Δ [σ])
[σ′ℕ] = proj₁ ([ℕ] ⊢Δ [σ′])
[n′≡m′] = irrelevanceEqTerm″ n″≡n′ m″≡m′ PE.refl [σℕ] [σℕ] (ιx [n″≡m″])
[σn] = ℕₜ (suc n′) d n≡n (sucᵣ [n′])
[σ′m] = ℕₜ (suc m′) d′ m≡m (sucᵣ [m′])
[σn≡σ′m] = ℕₜ₌ (suc n″) (suc m″) d₁ d₁′ t≡u (sucᵣ [n″≡m″])
⊢ℕ = escape [σℕ]
⊢F = escape (proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ])))
⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)
(escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))
⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)
(escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))
⊢n′ = escapeTerm {l = l} [σℕ] (ιx [n′])
⊢ℕ′ = escape [σ′ℕ]
⊢F′ = escape (proj₁ ([F′] (⊢Δ ∙ ⊢ℕ′)
(liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′])))
⊢z′ = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F′ zero)
(escapeTerm (proj₁ ([F′₀] ⊢Δ [σ′]))
(proj₁ ([z′] ⊢Δ [σ′])))
⊢s′ = PE.subst (λ x → Δ ⊢ subst σ′ s′ ∷ x) (natrecSucCase σ′ F′)
(escapeTerm (proj₁ ([F′₊] ⊢Δ [σ′]))
(proj₁ ([s′] ⊢Δ [σ′])))
⊢m′ = escapeTerm {l = l} [σ′ℕ] (ιx [m′])
[σsn′] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) [σℕ]
(ιx (ℕₜ (suc n′) (idRedTerm:*: (sucⱼ ⊢n′)) n≡n (sucᵣ [n′])))
[σn]′ , [σn≡σsn′] = redSubst*Term (redₜ d) [σℕ] [σsn′]
[σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , ιx [σn]))
[σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′
[σFₛₙ′] = irrelevance′ (PE.sym (singleSubstComp (suc n′) σ F))
(proj₁ ([F] ⊢Δ ([σ] , [σsn′])))
[Fₙ≡Fₛₙ′] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (singleSubstComp (suc n′) σ F))
[σFₙ]′ [σFₙ]
(proj₂ ([F] ⊢Δ ([σ] , ιx [σn])) ([σ] , [σsn′])
(reflSubst [Γ] ⊢Δ [σ] , [σn≡σsn′]))
[Fₙ≡Fₛₙ′]′ = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(natrecIrrelevantSubst F z s n′ σ)
[σFₙ]′ [σFₙ]
(proj₂ ([F] ⊢Δ ([σ] , ιx [σn])) ([σ] , [σsn′])
(reflSubst [Γ] ⊢Δ [σ] , [σn≡σsn′]))
[σFₙ′] = irrelevance′ (PE.sym (PE.trans (substCompEq F)
(substSingletonComp F)))
(proj₁ ([F] ⊢Δ ([σ] , ιx [n′])))
[σFₛₙ′]′ = irrelevance′ (natrecIrrelevantSubst F z s n′ σ)
(proj₁ ([F] ⊢Δ ([σ] , [σsn′])))
[σF₊ₙ′] = substSΠ₁ (proj₁ ([F₊] ⊢Δ [σ])) [σℕ] (ιx [n′])
[σ′sm′] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) [σ′ℕ]
(ιx (ℕₜ (suc m′) (idRedTerm:*: (sucⱼ ⊢m′)) m≡m (sucᵣ [m′])))
[σ′m]′ , [σ′m≡σ′sm′] = redSubst*Term (redₜ d′) [σ′ℕ] [σ′sm′]
[σ′F′ₘ]′ = proj₁ ([F′] ⊢Δ ([σ′] , ιx [σ′m]))
[σ′F′ₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F′)) [σ′F′ₘ]′
[σ′Fₘ]′ = proj₁ ([F] ⊢Δ ([σ′] , ιx [σ′m]))
[σ′Fₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F)) [σ′Fₘ]′
[σ′F′ₛₘ′] = irrelevance′ (PE.sym (singleSubstComp (suc m′) σ′ F′))
(proj₁ ([F′] ⊢Δ ([σ′] , [σ′sm′])))
[F′ₘ≡F′ₛₘ′] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F′))
(PE.sym (singleSubstComp (suc m′) σ′ F′))
[σ′F′ₘ]′ [σ′F′ₘ]
(proj₂ ([F′] ⊢Δ ([σ′] , ιx [σ′m]))
([σ′] , [σ′sm′])
(reflSubst [Γ] ⊢Δ [σ′] , [σ′m≡σ′sm′]))
[σ′Fₘ′] = irrelevance′ (PE.sym (PE.trans (substCompEq F)
(substSingletonComp F)))
(proj₁ ([F] ⊢Δ ([σ′] , ιx [m′])))
[σ′F′ₘ′] = irrelevance′ (PE.sym (PE.trans (substCompEq F′)
(substSingletonComp F′)))
(proj₁ ([F′] ⊢Δ ([σ′] , ιx [m′])))
[σ′F′ₛₘ′]′ = irrelevance′ (natrecIrrelevantSubst F′ z′ s′ m′ σ′)
(proj₁ ([F′] ⊢Δ ([σ′] , [σ′sm′])))
[σ′F′₊ₘ′] = substSΠ₁ (proj₁ ([F′₊] ⊢Δ [σ′])) [σ′ℕ] (ιx [m′])
[σFₙ′≡σ′Fₘ′] = irrelevanceEq″ (PE.sym (singleSubstComp n′ σ F))
(PE.sym (singleSubstComp m′ σ′ F))
(proj₁ ([F] ⊢Δ ([σ] , ιx [n′]))) [σFₙ′]
(proj₂ ([F] ⊢Δ ([σ] , ιx [n′]))
([σ′] , ιx [m′]) ([σ≡σ′] , [n′≡m′]))
[σ′Fₘ′≡σ′F′ₘ′] = irrelevanceEq″ (PE.sym (singleSubstComp m′ σ′ F))
(PE.sym (singleSubstComp m′ σ′ F′))
(proj₁ ([F] ⊢Δ ([σ′] , ιx [m′])))
[σ′Fₘ′] ([F≡F′] ⊢Δ ([σ′] , ιx [m′]))
[σFₙ′≡σ′F′ₘ′] = transEq [σFₙ′] [σ′Fₘ′] [σ′F′ₘ′] [σFₙ′≡σ′Fₘ′] [σ′Fₘ′≡σ′F′ₘ′]
[σFₙ≡σ′Fₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (singleSubstComp m σ′ F))
(proj₁ ([F] ⊢Δ ([σ] , ιx [σn]))) [σFₙ]
(proj₂ ([F] ⊢Δ ([σ] , ιx [σn]))
([σ′] , ιx [σ′m]) ([σ≡σ′] , ιx [σn≡σ′m]))
[σ′Fₘ≡σ′F′ₘ] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F))
(PE.sym (singleSubstComp m σ′ F′))
[σ′Fₘ]′ [σ′Fₘ] ([F≡F′] ⊢Δ ([σ′] , ιx [σ′m]))
[σFₙ≡σ′F′ₘ] = transEq [σFₙ] [σ′Fₘ] [σ′F′ₘ] [σFₙ≡σ′Fₘ] [σ′Fₘ≡σ′F′ₘ]
natrecN = appTerm [σFₙ′] [σFₛₙ′]′ [σF₊ₙ′]
(appTerm [σℕ] [σF₊ₙ′] (proj₁ ([F₊] ⊢Δ [σ]))
(proj₁ ([s] ⊢Δ [σ])) (ιx [n′]))
(natrecTerm {F} {z} {s} {n′} {σ = σ}
[Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ] (ιx [n′]))
natrecN′ = irrelevanceTerm′ (PE.trans (PE.sym (natrecIrrelevantSubst F z s n′ σ))
(PE.sym (singleSubstComp (suc n′) σ F)))
[σFₛₙ′]′ [σFₛₙ′] natrecN
natrecM = appTerm [σ′F′ₘ′] [σ′F′ₛₘ′]′ [σ′F′₊ₘ′]
(appTerm [σ′ℕ] [σ′F′₊ₘ′] (proj₁ ([F′₊] ⊢Δ [σ′]))
(proj₁ ([s′] ⊢Δ [σ′])) (ιx [m′]))
(natrecTerm {F′} {z′} {s′} {m′} {σ = σ′}
[Γ] [F′] [F′₀] [F′₊] [z′] [s′] ⊢Δ [σ′] (ιx [m′]))
natrecM′ = irrelevanceTerm′ (PE.trans (PE.sym (natrecIrrelevantSubst F′ z′ s′ m′ σ′))
(PE.sym (singleSubstComp (suc m′) σ′ F′)))
[σ′F′ₛₘ′]′ [σ′F′ₛₘ′] natrecM
[σs≡σ′s] = proj₂ ([s] ⊢Δ [σ]) [σ′] [σ≡σ′]
[σ′s≡σ′s′] = convEqTerm₂ (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([F₊] ⊢Δ [σ′]))
(proj₂ ([F₊] ⊢Δ [σ]) [σ′] [σ≡σ′]) ([s≡s′] ⊢Δ [σ′])
[σs≡σ′s′] = transEqTerm (proj₁ ([F₊] ⊢Δ [σ])) [σs≡σ′s] [σ′s≡σ′s′]
appEq = convEqTerm₂ [σFₙ] [σFₛₙ′]′ [Fₙ≡Fₛₙ′]′
(app-congTerm [σFₙ′] [σFₛₙ′]′ [σF₊ₙ′]
(app-congTerm [σℕ] [σF₊ₙ′] (proj₁ ([F₊] ⊢Δ [σ])) [σs≡σ′s′]
(ιx [n′]) (ιx [m′]) [n′≡m′])
(natrecTerm {F} {z} {s} {n′} {σ = σ}
[Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ] (ιx [n′]))
(convTerm₂ [σFₙ′] [σ′F′ₘ′] [σFₙ′≡σ′F′ₘ′]
(natrecTerm {F′} {z′} {s′} {m′} {σ = σ′}
[Γ] [F′] [F′₀] [F′₊] [z′] [s′]
⊢Δ [σ′] (ιx [m′])))
(natrec-congTerm {F} {F′} {z} {z′} {s} {s′} {n′} {m′} {σ = σ}
[Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀]
[F₊] [F′₊] [F₊≡F′₊] [z] [z′] [z≡z′]
[s] [s′] [s≡s′]
⊢Δ [σ] [σ′] [σ≡σ′] (ιx [n′]) (ιx [m′]) [n′≡m′]))
reduction₁ = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) [σℕ] [σsn′]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ F))
(PE.sym (singleSubstComp t′ σ F))
(≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))
(proj₂ ([F] ⊢Δ ([σ] , [t]))
([σ] , [t′])
(reflSubst [Γ] ⊢Δ [σ] , [t≡t′])))))
⇨∷* (conv* (natrec-suc ⊢n′ ⊢F ⊢z ⊢s
⇨ id (escapeTerm [σFₛₙ′] natrecN′))
(sym (≅-eq (escapeEq [σFₙ] [Fₙ≡Fₛₙ′]))))
reduction₂ = natrec-subst* ⊢F′ ⊢z′ ⊢s′ (redₜ d′) [σ′ℕ] [σ′sm′]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ′ F′))
(PE.sym (singleSubstComp t′ σ′ F′))
(≅-eq (escapeEq (proj₁ ([F′] ⊢Δ ([σ′] , [t])))
(proj₂ ([F′] ⊢Δ ([σ′] , [t]))
([σ′] , [t′])
(reflSubst [Γ] ⊢Δ [σ′] , [t≡t′])))))
⇨∷* (conv* (natrec-suc ⊢m′ ⊢F′ ⊢z′ ⊢s′
⇨ id (escapeTerm [σ′F′ₛₘ′] natrecM′))
(sym (≅-eq (escapeEq [σ′F′ₘ] [F′ₘ≡F′ₛₘ′]))))
eq₁ = proj₂ (redSubst*Term reduction₁ [σFₙ]
(convTerm₂ [σFₙ] [σFₛₙ′]
[Fₙ≡Fₛₙ′] natrecN′))
eq₂ = proj₂ (redSubst*Term reduction₂ [σ′F′ₘ]
(convTerm₂ [σ′F′ₘ] [σ′F′ₛₘ′]
[F′ₘ≡F′ₛₘ′] natrecM′))
in transEqTerm [σFₙ] eq₁
(transEqTerm [σFₙ] appEq
(convEqTerm₂ [σFₙ] [σ′F′ₘ] [σFₙ≡σ′F′ₘ]
(symEqTerm [σ′F′ₘ] eq₂)))
natrec-congTerm {F} {F′} {z} {z′} {s} {s′} {n} {m} {Γ} {Δ} {σ} {σ′} {l}
[Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ .zero d n≡n zeroᵣ)) (ιx (ℕₜ .zero d₁ m≡m zeroᵣ))
(ιx (ℕₜ₌ .zero .zero d₂ d′ t≡u zeroᵣ)) =
let [ℕ] = ℕᵛ {l = l} [Γ]
[σℕ] = proj₁ ([ℕ] ⊢Δ [σ])
⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))
⊢F = escape (proj₁ ([F] {σ = liftSubst σ} (⊢Δ ∙ ⊢ℕ)
(liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ])))
⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)
(escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))
⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)
(escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))
⊢F′ = escape (proj₁ ([F′] {σ = liftSubst σ′} (⊢Δ ∙ ⊢ℕ)
(liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′])))
⊢z′ = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F′ zero)
(escapeTerm (proj₁ ([F′₀] ⊢Δ [σ′])) (proj₁ ([z′] ⊢Δ [σ′])))
⊢s′ = PE.subst (λ x → Δ ⊢ subst σ′ s′ ∷ x) (natrecSucCase σ′ F′)
(escapeTerm (proj₁ ([F′₊] ⊢Δ [σ′])) (proj₁ ([s′] ⊢Δ [σ′])))
[σ0] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([ℕ] ⊢Δ [σ]))
(ιx (ℕₜ zero (idRedTerm:*: (zeroⱼ ⊢Δ)) n≡n zeroᵣ))
[σ′0] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([ℕ] ⊢Δ [σ′]))
(ιx (ℕₜ zero (idRedTerm:*: (zeroⱼ ⊢Δ)) m≡m zeroᵣ))
[σn]′ , [σn≡σ0] = redSubst*Term (redₜ d) (proj₁ ([ℕ] ⊢Δ [σ])) [σ0]
[σ′m]′ , [σ′m≡σ′0] = redSubst*Term (redₜ d′) (proj₁ ([ℕ] ⊢Δ [σ′])) [σ′0]
[σn] = ιx (ℕₜ zero d n≡n zeroᵣ)
[σ′m] = ιx (ℕₜ zero d′ m≡m zeroᵣ)
[σn≡σ′m] = ιx (ℕₜ₌ zero zero d₂ d′ t≡u zeroᵣ)
[σn≡σ′0] = transEqTerm [σℕ] [σn≡σ′m] [σ′m≡σ′0]
[σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , [σn]))
[σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′
[σ′Fₘ]′ = proj₁ ([F] ⊢Δ ([σ′] , [σ′m]))
[σ′Fₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F)) [σ′Fₘ]′
[σ′F′ₘ]′ = proj₁ ([F′] ⊢Δ ([σ′] , [σ′m]))
[σ′F′ₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F′)) [σ′F′ₘ]′
[σFₙ≡σ′Fₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (singleSubstComp m σ′ F))
[σFₙ]′ [σFₙ]
(proj₂ ([F] ⊢Δ ([σ] , [σn])) ([σ′] , [σ′m])
([σ≡σ′] , [σn≡σ′m]))
[σ′Fₘ≡σ′F′ₘ] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F))
(PE.sym (singleSubstComp m σ′ F′))
[σ′Fₘ]′ [σ′Fₘ] ([F≡F′] ⊢Δ ([σ′] , [σ′m]))
[σFₙ≡σ′F′ₘ] = transEq [σFₙ] [σ′Fₘ] [σ′F′ₘ] [σFₙ≡σ′Fₘ] [σ′Fₘ≡σ′F′ₘ]
[Fₙ≡F₀]′ = proj₂ ([F] ⊢Δ ([σ] , [σn])) ([σ] , [σ0]) (reflSubst [Γ] ⊢Δ [σ] , [σn≡σ0])
[Fₙ≡F₀] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (substCompEq F))
[σFₙ]′ [σFₙ] [Fₙ≡F₀]′
[σFₙ≡σ′F₀]′ = proj₂ ([F] ⊢Δ ([σ] , [σn])) ([σ′] , [σ′0]) ([σ≡σ′] , [σn≡σ′0])
[σFₙ≡σ′F₀] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (substCompEq F))
[σFₙ]′ [σFₙ] [σFₙ≡σ′F₀]′
[F′ₘ≡F′₀]′ = proj₂ ([F′] ⊢Δ ([σ′] , [σ′m])) ([σ′] , [σ′0])
(reflSubst [Γ] ⊢Δ [σ′] , [σ′m≡σ′0])
[F′ₘ≡F′₀] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F′))
(PE.sym (substCompEq F′))
[σ′F′ₘ]′ [σ′F′ₘ] [F′ₘ≡F′₀]′
[Fₙ≡F₀]″ = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.trans (substConcatSingleton′ F)
(PE.sym (singleSubstComp zero σ F)))
[σFₙ]′ [σFₙ] [Fₙ≡F₀]′
[F′ₘ≡F′₀]″ = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F′))
(PE.trans (substConcatSingleton′ F′)
(PE.sym (singleSubstComp zero σ′ F′)))
[σ′F′ₘ]′ [σ′F′ₘ] [F′ₘ≡F′₀]′
[σz] = proj₁ ([z] ⊢Δ [σ])
[σ′z′] = proj₁ ([z′] ⊢Δ [σ′])
[σz≡σ′z] = convEqTerm₂ [σFₙ] (proj₁ ([F₀] ⊢Δ [σ])) [Fₙ≡F₀]
(proj₂ ([z] ⊢Δ [σ]) [σ′] [σ≡σ′])
[σ′z≡σ′z′] = convEqTerm₂ [σFₙ] (proj₁ ([F₀] ⊢Δ [σ′])) [σFₙ≡σ′F₀]
([z≡z′] ⊢Δ [σ′])
[σz≡σ′z′] = transEqTerm [σFₙ] [σz≡σ′z] [σ′z≡σ′z′]
reduction₁ = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) (proj₁ ([ℕ] ⊢Δ [σ])) [σ0]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ F))
(PE.sym (singleSubstComp t′ σ F))
(≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))
(proj₂ ([F] ⊢Δ ([σ] , [t]))
([σ] , [t′])
(reflSubst [Γ] ⊢Δ [σ] , [t≡t′])))))
⇨∷* (conv* (natrec-zero ⊢F ⊢z ⊢s ⇨ id ⊢z)
(sym (≅-eq (escapeEq [σFₙ] [Fₙ≡F₀]″))))
reduction₂ = natrec-subst* ⊢F′ ⊢z′ ⊢s′ (redₜ d′) (proj₁ ([ℕ] ⊢Δ [σ′])) [σ′0]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ′ F′))
(PE.sym (singleSubstComp t′ σ′ F′))
(≅-eq (escapeEq (proj₁ ([F′] ⊢Δ ([σ′] , [t])))
(proj₂ ([F′] ⊢Δ ([σ′] , [t]))
([σ′] , [t′])
(reflSubst [Γ] ⊢Δ [σ′] , [t≡t′])))))
⇨∷* (conv* (natrec-zero ⊢F′ ⊢z′ ⊢s′ ⇨ id ⊢z′)
(sym (≅-eq (escapeEq [σ′F′ₘ] [F′ₘ≡F′₀]″))))
eq₁ = proj₂ (redSubst*Term reduction₁ [σFₙ]
(convTerm₂ [σFₙ] (proj₁ ([F₀] ⊢Δ [σ]))
[Fₙ≡F₀] [σz]))
eq₂ = proj₂ (redSubst*Term reduction₂ [σ′F′ₘ]
(convTerm₂ [σ′F′ₘ] (proj₁ ([F′₀] ⊢Δ [σ′]))
[F′ₘ≡F′₀] [σ′z′]))
in transEqTerm [σFₙ] eq₁
(transEqTerm [σFₙ] [σz≡σ′z′]
(convEqTerm₂ [σFₙ] [σ′F′ₘ] [σFₙ≡σ′F′ₘ]
(symEqTerm [σ′F′ₘ] eq₂)))
natrec-congTerm {F} {F′} {z} {z′} {s} {s′} {n} {m} {Γ} {Δ} {σ} {σ′} {l}
[Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ n′ d n≡n (ne (neNfₜ neN′ ⊢n′ n≡n₁))))
(ιx (ℕₜ m′ d′ m≡m (ne (neNfₜ neM′ ⊢m′ m≡m₁))))
(ιx (ℕₜ₌ n″ m″ d₁ d₁′ t≡u (ne (neNfₜ₌ x₂ x₃ prop₂)))) =
let n″≡n′ = whrDet*Term (redₜ d₁ , ne x₂) (redₜ d , ne neN′)
m″≡m′ = whrDet*Term (redₜ d₁′ , ne x₃) (redₜ d′ , ne neM′)
[ℕ] = ℕᵛ {l = l} [Γ]
[σℕ] = proj₁ ([ℕ] ⊢Δ [σ])
[σ′ℕ] = proj₁ ([ℕ] ⊢Δ [σ′])
[σn] = ℕₜ n′ d n≡n (ne (neNfₜ neN′ ⊢n′ n≡n₁))
[σ′m] = ℕₜ m′ d′ m≡m (ne (neNfₜ neM′ ⊢m′ m≡m₁))
[σn≡σ′m] = ℕₜ₌ n″ m″ d₁ d₁′ t≡u (ne (neNfₜ₌ x₂ x₃ prop₂))
⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))
[σF] = proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ]))
[σ′F] = proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′]))
[σ′F′] = proj₁ ([F′] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′]))
⊢F = escape [σF]
⊢F≡F = escapeEq [σF] (reflEq [σF])
⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)
(escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))
⊢z≡z = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x) (singleSubstLift F zero)
(escapeTermEq (proj₁ ([F₀] ⊢Δ [σ]))
(reflEqTerm (proj₁ ([F₀] ⊢Δ [σ]))
(proj₁ ([z] ⊢Δ [σ]))))
⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)
(escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))
⊢s≡s = PE.subst (λ x → Δ ⊢ subst σ s ≅ subst σ s ∷ x) (natrecSucCase σ F)
(escapeTermEq (proj₁ ([F₊] ⊢Δ [σ]))
(reflEqTerm (proj₁ ([F₊] ⊢Δ [σ]))
(proj₁ ([s] ⊢Δ [σ]))))
⊢F′ = escape [σ′F′]
⊢F′≡F′ = escapeEq [σ′F′] (reflEq [σ′F′])
⊢z′ = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F′ zero)
(escapeTerm (proj₁ ([F′₀] ⊢Δ [σ′])) (proj₁ ([z′] ⊢Δ [σ′])))
⊢z′≡z′ = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x) (singleSubstLift F′ zero)
(escapeTermEq (proj₁ ([F′₀] ⊢Δ [σ′]))
(reflEqTerm (proj₁ ([F′₀] ⊢Δ [σ′]))
(proj₁ ([z′] ⊢Δ [σ′]))))
⊢s′ = PE.subst (λ x → Δ ⊢ subst σ′ s′ ∷ x) (natrecSucCase σ′ F′)
(escapeTerm (proj₁ ([F′₊] ⊢Δ [σ′])) (proj₁ ([s′] ⊢Δ [σ′])))
⊢s′≡s′ = PE.subst (λ x → Δ ⊢ subst σ′ s′ ≅ subst σ′ s′ ∷ x) (natrecSucCase σ′ F′)
(escapeTermEq (proj₁ ([F′₊] ⊢Δ [σ′]))
(reflEqTerm (proj₁ ([F′₊] ⊢Δ [σ′]))
(proj₁ ([s′] ⊢Δ [σ′]))))
⊢σF≡σ′F = escapeEq [σF] (proj₂ ([F] {σ = liftSubst σ} (⊢Δ ∙ ⊢ℕ)
(liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ]))
{σ′ = liftSubst σ′}
(liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′])
(liftSubstSEq {F = ℕ} [Γ] ⊢Δ [ℕ] [σ] [σ≡σ′]))
⊢σz≡σ′z = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x) (singleSubstLift F zero)
(escapeTermEq (proj₁ ([F₀] ⊢Δ [σ]))
(proj₂ ([z] ⊢Δ [σ]) [σ′] [σ≡σ′]))
⊢σs≡σ′s = PE.subst (λ x → Δ ⊢ subst σ s ≅ subst σ′ s ∷ x)
(natrecSucCase σ F)
(escapeTermEq (proj₁ ([F₊] ⊢Δ [σ]))
(proj₂ ([s] ⊢Δ [σ]) [σ′] [σ≡σ′]))
⊢σ′F≡⊢σ′F′ = escapeEq [σ′F] ([F≡F′] (⊢Δ ∙ ⊢ℕ)
(liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′]))
⊢σ′z≡⊢σ′z′ = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x)
(singleSubstLift F zero)
(≅-conv (escapeTermEq (proj₁ ([F₀] ⊢Δ [σ′]))
([z≡z′] ⊢Δ [σ′]))
(sym (≅-eq (escapeEq (proj₁ ([F₀] ⊢Δ [σ]))
(proj₂ ([F₀] ⊢Δ [σ]) [σ′] [σ≡σ′])))))
⊢σ′s≡⊢σ′s′ = PE.subst (λ x → Δ ⊢ subst σ′ s ≅ subst σ′ s′ ∷ x)
(natrecSucCase σ F)
(≅-conv (escapeTermEq (proj₁ ([F₊] ⊢Δ [σ′]))
([s≡s′] ⊢Δ [σ′]))
(sym (≅-eq (escapeEq (proj₁ ([F₊] ⊢Δ [σ]))
(proj₂ ([F₊] ⊢Δ [σ]) [σ′] [σ≡σ′])))))
⊢F≡F′ = ≅-trans ⊢σF≡σ′F ⊢σ′F≡⊢σ′F′
⊢z≡z′ = ≅ₜ-trans ⊢σz≡σ′z ⊢σ′z≡⊢σ′z′
⊢s≡s′ = ≅ₜ-trans ⊢σs≡σ′s ⊢σ′s≡⊢σ′s′
[σn′] = neuTerm [σℕ] neN′ ⊢n′ n≡n₁
[σn]′ , [σn≡σn′] = redSubst*Term (redₜ d) [σℕ] [σn′]
[σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , ιx [σn]))
[σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′
[σFₙ′] = irrelevance′ (PE.sym (singleSubstComp n′ σ F))
(proj₁ ([F] ⊢Δ ([σ] , [σn′])))
[Fₙ≡Fₙ′] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (singleSubstComp n′ σ F)) [σFₙ]′ [σFₙ]
((proj₂ ([F] ⊢Δ ([σ] , ιx [σn])))
([σ] , [σn′])
(reflSubst [Γ] ⊢Δ [σ] , [σn≡σn′]))
[σ′m′] = neuTerm [σ′ℕ] neM′ ⊢m′ m≡m₁
[σ′m]′ , [σ′m≡σ′m′] = redSubst*Term (redₜ d′) [σ′ℕ] [σ′m′]
[σ′F′ₘ]′ = proj₁ ([F′] ⊢Δ ([σ′] , ιx [σ′m]))
[σ′F′ₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F′)) [σ′F′ₘ]′
[σ′Fₘ]′ = proj₁ ([F] ⊢Δ ([σ′] , ιx [σ′m]))
[σ′Fₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F)) [σ′Fₘ]′
[σ′F′ₘ′] = irrelevance′ (PE.sym (singleSubstComp m′ σ′ F′))
(proj₁ ([F′] ⊢Δ ([σ′] , [σ′m′])))
[F′ₘ≡F′ₘ′] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F′))
(PE.sym (singleSubstComp m′ σ′ F′))
[σ′F′ₘ]′ [σ′F′ₘ]
((proj₂ ([F′] ⊢Δ ([σ′] , ιx [σ′m])))
([σ′] , [σ′m′])
(reflSubst [Γ] ⊢Δ [σ′] , [σ′m≡σ′m′]))
[σFₙ≡σ′Fₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))
(PE.sym (singleSubstComp m σ′ F))
[σFₙ]′ [σFₙ]
(proj₂ ([F] ⊢Δ ([σ] , ιx [σn])) ([σ′] , ιx [σ′m])
([σ≡σ′] , ιx [σn≡σ′m]))
[σ′Fₘ≡σ′F′ₘ] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F))
(PE.sym (singleSubstComp m σ′ F′))
(proj₁ ([F] ⊢Δ ([σ′] , ιx [σ′m])))
[σ′Fₘ] ([F≡F′] ⊢Δ ([σ′] , ιx [σ′m]))
[σFₙ≡σ′F′ₘ] = transEq [σFₙ] [σ′Fₘ] [σ′F′ₘ] [σFₙ≡σ′Fₘ] [σ′Fₘ≡σ′F′ₘ]
[σFₙ′≡σ′Fₘ′] = transEq [σFₙ′] [σFₙ] [σ′F′ₘ′] (symEq [σFₙ] [σFₙ′] [Fₙ≡Fₙ′])
(transEq [σFₙ] [σ′F′ₘ] [σ′F′ₘ′] [σFₙ≡σ′F′ₘ] [F′ₘ≡F′ₘ′])
natrecN = neuTerm [σFₙ′] (natrecₙ neN′) (natrecⱼ ⊢F ⊢z ⊢s ⊢n′)
(~-natrec ⊢F≡F ⊢z≡z ⊢s≡s n≡n₁)
natrecM = neuTerm [σ′F′ₘ′] (natrecₙ neM′) (natrecⱼ ⊢F′ ⊢z′ ⊢s′ ⊢m′)
(~-natrec ⊢F′≡F′ ⊢z′≡z′ ⊢s′≡s′ m≡m₁)
natrecN≡M =
convEqTerm₂ [σFₙ] [σFₙ′] [Fₙ≡Fₙ′]
(neuEqTerm [σFₙ′] (natrecₙ neN′) (natrecₙ neM′)
(natrecⱼ ⊢F ⊢z ⊢s ⊢n′)
(conv (natrecⱼ ⊢F′ ⊢z′ ⊢s′ ⊢m′)
(sym (≅-eq (escapeEq [σFₙ′] [σFₙ′≡σ′Fₘ′]))))
(~-natrec ⊢F≡F′ ⊢z≡z′ ⊢s≡s′
(PE.subst₂ (λ x y → _ ⊢ x ~ y ∷ _)
n″≡n′ m″≡m′ prop₂)))
reduction₁ = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) [σℕ] [σn′]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ F))
(PE.sym (singleSubstComp t′ σ F))
(≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))
(proj₂ ([F] ⊢Δ ([σ] , [t]))
([σ] , [t′])
(reflSubst [Γ] ⊢Δ [σ] , [t≡t′])))))
reduction₂ = natrec-subst* ⊢F′ ⊢z′ ⊢s′ (redₜ d′) [σ′ℕ] [σ′m′]
(λ {t} {t′} [t] [t′] [t≡t′] →
PE.subst₂ (λ x y → _ ⊢ x ≡ y)
(PE.sym (singleSubstComp t σ′ F′))
(PE.sym (singleSubstComp t′ σ′ F′))
(≅-eq (escapeEq (proj₁ ([F′] ⊢Δ ([σ′] , [t])))
(proj₂ ([F′] ⊢Δ ([σ′] , [t]))
([σ′] , [t′])
(reflSubst [Γ] ⊢Δ [σ′] , [t≡t′])))))
eq₁ = proj₂ (redSubst*Term reduction₁ [σFₙ]
(convTerm₂ [σFₙ] [σFₙ′] [Fₙ≡Fₙ′] natrecN))
eq₂ = proj₂ (redSubst*Term reduction₂ [σ′F′ₘ]
(convTerm₂ [σ′F′ₘ] [σ′F′ₘ′] [F′ₘ≡F′ₘ′] natrecM))
in transEqTerm [σFₙ] eq₁
(transEqTerm [σFₙ] natrecN≡M
(convEqTerm₂ [σFₙ] [σ′F′ₘ] [σFₙ≡σ′F′ₘ]
(symEqTerm [σ′F′ₘ] eq₂)))
-- Refuting cases
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
[σn] (ιx (ℕₜ _ d₁ _ zeroᵣ))
(ιx (ℕₜ₌ _ _ d₂ d′ t≡u (sucᵣ prop₂))) =
⊥-elim (zero≢suc (whrDet*Term (redₜ d₁ , zeroₙ) (redₜ d′ , sucₙ)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
[σn] (ιx (ℕₜ n d₁ _ (ne (neNfₜ neK ⊢k k≡k))))
(ιx (ℕₜ₌ _ _ d₂ d′ t≡u (sucᵣ prop₂))) =
⊥-elim (suc≢ne neK (whrDet*Term (redₜ d′ , sucₙ) (redₜ d₁ , ne neK)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ _ d _ zeroᵣ)) [σm]
(ιx (ℕₜ₌ _ _ d₁ d′ t≡u (sucᵣ prop₂))) =
⊥-elim (zero≢suc (whrDet*Term (redₜ d , zeroₙ) (redₜ d₁ , sucₙ)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ n d _ (ne (neNfₜ neK ⊢k k≡k)))) [σm]
(ιx (ℕₜ₌ _ _ d₁ d′ t≡u (sucᵣ prop₂))) =
⊥-elim (suc≢ne neK (whrDet*Term (redₜ d₁ , sucₙ) (redₜ d , ne neK)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ _ d _ (sucᵣ prop))) [σm]
(ιx (ℕₜ₌ _ _ d₂ d′ t≡u zeroᵣ)) =
⊥-elim (zero≢suc (whrDet*Term (redₜ d₂ , zeroₙ) (redₜ d , sucₙ)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
[σn] (ιx (ℕₜ _ d₁ _ (sucᵣ prop₁)))
(ιx (ℕₜ₌ _ _ d₂ d′ t≡u zeroᵣ)) =
⊥-elim (zero≢suc (whrDet*Term (redₜ d′ , zeroₙ) (redₜ d₁ , sucₙ)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
[σn] (ιx (ℕₜ n d₁ _ (ne (neNfₜ neK ⊢k k≡k))))
(ιx (ℕₜ₌ _ _ d₂ d′ t≡u zeroᵣ)) =
⊥-elim (zero≢ne neK (whrDet*Term (redₜ d′ , zeroₙ) (redₜ d₁ , ne neK)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ n d _ (ne (neNfₜ neK ⊢k k≡k)))) [σm]
(ιx (ℕₜ₌ _ _ d₂ d′ t≡u zeroᵣ)) =
⊥-elim (zero≢ne neK (whrDet*Term (redₜ d₂ , zeroₙ) (redₜ d , ne neK)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ _ d _ (sucᵣ prop))) [σm]
(ιx (ℕₜ₌ n₁ n′ d₂ d′ t≡u (ne (neNfₜ₌ x x₁ prop₂)))) =
⊥-elim (suc≢ne x (whrDet*Term (redₜ d , sucₙ) (redₜ d₂ , ne x)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
(ιx (ℕₜ _ d _ zeroᵣ)) [σm]
(ιx (ℕₜ₌ n₁ n′ d₂ d′ t≡u (ne (neNfₜ₌ x x₁ prop₂)))) =
⊥-elim (zero≢ne x (whrDet*Term (redₜ d , zeroₙ) (redₜ d₂ , ne x)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
[σn] (ιx (ℕₜ _ d₁ _ (sucᵣ prop₁)))
(ιx (ℕₜ₌ n₁ n′ d₂ d′ t≡u (ne (neNfₜ₌ x₁ x₂ prop₂)))) =
⊥-elim (suc≢ne x₂ (whrDet*Term (redₜ d₁ , sucₙ) (redₜ d′ , ne x₂)))
natrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]
[σn] (ιx (ℕₜ _ d₁ _ zeroᵣ))
(ιx (ℕₜ₌ n₁ n′ d₂ d′ t≡u (ne (neNfₜ₌ x₁ x₂ prop₂)))) =
⊥-elim (zero≢ne x₂ (whrDet*Term (redₜ d₁ , zeroₙ) (redₜ d′ , ne x₂)))
-- Validity of natural recursion.
natrecᵛ : ∀ {F z s n Γ l} ([Γ] : ⊩ᵛ Γ)
([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])
([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙′ [ℕ]))
([F₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] / [Γ])
([F₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ])
([Fₙ] : Γ ⊩ᵛ⟨ l ⟩ F [ n ] / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ z ∷ F [ zero ] / [Γ] / [F₀]
→ Γ ⊩ᵛ⟨ l ⟩ s ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ] / [F₊]
→ ([n] : Γ ⊩ᵛ⟨ l ⟩ n ∷ ℕ / [Γ] / [ℕ])
→ Γ ⊩ᵛ⟨ l ⟩ natrec F z s n ∷ F [ n ] / [Γ] / [Fₙ]
natrecᵛ {F} {z} {s} {n} {l = l} [Γ] [ℕ] [F] [F₀] [F₊] [Fₙ] [z] [s] [n]
{Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [F]′ = S.irrelevance {A = F} (_∙″_ {A = ℕ} [Γ] [ℕ])
(_∙″_ {l = l} [Γ] (ℕᵛ [Γ])) [F]
[σn]′ = irrelevanceTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))
(ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([n] ⊢Δ [σ]))
n′ = subst σ n
eqPrf = PE.trans (singleSubstComp n′ σ F)
(PE.sym (PE.trans (substCompEq F)
(substConcatSingleton′ F)))
in irrelevanceTerm′ eqPrf (irrelevance′ (PE.sym (singleSubstComp n′ σ F))
(proj₁ ([F]′ ⊢Δ ([σ] , [σn]′))))
(proj₁ ([Fₙ] ⊢Δ [σ]))
(natrecTerm {F} {z} {s} {n′} {σ = σ} [Γ]
[F]′
[F₀] [F₊] [z] [s] ⊢Δ [σ]
[σn]′)
, (λ {σ′} [σ′] [σ≡σ′] →
let [σ′n]′ = irrelevanceTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ′]))
(ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))
(proj₁ ([n] ⊢Δ [σ′]))
[σn≡σ′n] = irrelevanceEqTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))
(ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))
(proj₂ ([n] ⊢Δ [σ]) [σ′] [σ≡σ′])
in irrelevanceEqTerm′ eqPrf
(irrelevance′ (PE.sym (singleSubstComp n′ σ F))
(proj₁ ([F]′ ⊢Δ ([σ] , [σn]′))))
(proj₁ ([Fₙ] ⊢Δ [σ]))
(natrec-congTerm {F} {F} {z} {z} {s} {s} {n′} {subst σ′ n} {σ = σ}
[Γ] [F]′ [F]′ (reflᵛ {F} (_∙″_ {A = ℕ} {l = l}
[Γ] (ℕᵛ [Γ])) [F]′) [F₀] [F₀]
(reflᵛ {F [ zero ]} [Γ] [F₀]) [F₊] [F₊]
(reflᵛ {Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)}
[Γ] [F₊])
[z] [z] (reflᵗᵛ {F [ zero ]} {z} [Γ] [F₀] [z])
[s] [s]
(reflᵗᵛ {Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)} {s}
[Γ] [F₊] [s])
⊢Δ [σ] [σ′] [σ≡σ′] [σn]′ [σ′n]′ [σn≡σ′n]))
-- Validity of natural recursion congurence.
natrec-congᵛ : ∀ {F F′ z z′ s s′ n n′ Γ l} ([Γ] : ⊩ᵛ Γ)
([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])
([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))
([F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F′ / ([Γ] ∙″ [ℕ]))
([F≡F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F ≡ F′ / [Γ] ∙″ [ℕ] / [F])
([F₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] / [Γ])
([F′₀] : Γ ⊩ᵛ⟨ l ⟩ F′ [ zero ] / [Γ])
([F₀≡F′₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] ≡ F′ [ zero ] / [Γ] / [F₀])
([F₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ])
([F′₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑) / [Γ])
([F₊≡F′₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
≡ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑) / [Γ]
/ [F₊])
([Fₙ] : Γ ⊩ᵛ⟨ l ⟩ F [ n ] / [Γ])
([z] : Γ ⊩ᵛ⟨ l ⟩ z ∷ F [ zero ] / [Γ] / [F₀])
([z′] : Γ ⊩ᵛ⟨ l ⟩ z′ ∷ F′ [ zero ] / [Γ] / [F′₀])
([z≡z′] : Γ ⊩ᵛ⟨ l ⟩ z ≡ z′ ∷ F [ zero ] / [Γ] / [F₀])
([s] : Γ ⊩ᵛ⟨ l ⟩ s ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ] / [F₊])
([s′] : Γ ⊩ᵛ⟨ l ⟩ s′ ∷ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑) / [Γ]
/ [F′₊])
([s≡s′] : Γ ⊩ᵛ⟨ l ⟩ s ≡ s′ ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
/ [Γ] / [F₊])
([n] : Γ ⊩ᵛ⟨ l ⟩ n ∷ ℕ / [Γ] / [ℕ])
([n′] : Γ ⊩ᵛ⟨ l ⟩ n′ ∷ ℕ / [Γ] / [ℕ])
([n≡n′] : Γ ⊩ᵛ⟨ l ⟩ n ≡ n′ ∷ ℕ / [Γ] / [ℕ])
→ Γ ⊩ᵛ⟨ l ⟩ natrec F z s n ≡ natrec F′ z′ s′ n′ ∷ F [ n ] / [Γ] / [Fₙ]
natrec-congᵛ {F} {F′} {z} {z′} {s} {s′} {n} {n′} {l = l}
[Γ] [ℕ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]
[Fₙ] [z] [z′] [z≡z′] [s] [s′] [s≡s′] [n] [n′]
[n≡n′] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [F]′ = S.irrelevance {A = F} (_∙″_ {A = ℕ} [Γ] [ℕ])
(_∙″_ {l = l} [Γ] (ℕᵛ [Γ])) [F]
[F′]′ = S.irrelevance {A = F′} (_∙″_ {A = ℕ} [Γ] [ℕ])
(_∙″_ {l = l} [Γ] (ℕᵛ [Γ])) [F′]
[F≡F′]′ = S.irrelevanceEq {A = F} {B = F′} (_∙″_ {A = ℕ} [Γ] [ℕ])
(_∙″_ {l = l} [Γ] (ℕᵛ [Γ])) [F] [F]′ [F≡F′]
[σn]′ = irrelevanceTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))
(ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([n] ⊢Δ [σ]))
[σn′]′ = irrelevanceTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))
(ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([n′] ⊢Δ [σ]))
[σn≡σn′]′ = irrelevanceEqTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))
(ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) ([n≡n′] ⊢Δ [σ])
[Fₙ]′ = irrelevance′ (PE.sym (singleSubstComp (subst σ n) σ F))
(proj₁ ([F]′ ⊢Δ ([σ] , [σn]′)))
in irrelevanceEqTerm′ (PE.sym (singleSubstLift F n))
[Fₙ]′ (proj₁ ([Fₙ] ⊢Δ [σ]))
(natrec-congTerm {F} {F′} {z} {z′} {s} {s′}
{subst σ n} {subst σ n′}
[Γ] [F]′ [F′]′ [F≡F′]′
[F₀] [F′₀] [F₀≡F′₀]
[F₊] [F′₊] [F₊≡F′₊]
[z] [z′] [z≡z′]
[s] [s′] [s≡s′] ⊢Δ
[σ] [σ] (reflSubst [Γ] ⊢Δ [σ])
[σn]′ [σn′]′ [σn≡σn′]′)
| {
"alphanum_fraction": 0.3313304721,
"avg_line_length": 60.2365236524,
"ext": "agda",
"hexsha": "f785938ee0b7228bde9e4c397c96a04d012660f8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Natrec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Natrec.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Natrec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 25125,
"size": 54755
} |
module Element where
open import OscarPrelude
record Element : Set
where
constructor ⟨_⟩
field
element : Nat
open Element public
instance EqElement : Eq Element
Eq._==_ EqElement ⟨ ε₁ ⟩ ⟨ ε₂ ⟩ with ε₁ ≟ ε₂
Eq._==_ EqElement ⟨ _ ⟩ ⟨ _ ⟩ | yes refl = yes refl
Eq._==_ EqElement ⟨ _ ⟩ ⟨ _ ⟩ | no ε₁≢ε₂ = no λ {refl → ε₁≢ε₂ refl}
| {
"alphanum_fraction": 0.6461988304,
"avg_line_length": 19,
"ext": "agda",
"hexsha": "6d938acce313782e003202982149cd004756cda8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/Element.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/Element.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/Element.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 127,
"size": 342
} |
{-# OPTIONS --type-in-type #-}
module Selective.Theorems where
open import Prelude.Equality
open import Selective
-- Now let's typecheck some theorems
cong-handle : ∀ {A B} {F : Set → Set} {{_ : Selective F}}
{x y : F (Either A B)} {f : F (A → B)} →
x ≡ y → handle x f ≡ handle y f
cong-handle refl = {!!}
cong-handle-handler : ∀ {A B} {F : Set → Set} {{_ : Selective F}}
{x : F (Either A B)} {f g : F (A → B)} →
f ≡ g → handle x f ≡ handle x g
cong-handle-handler refl = {!!}
cong-ap-right : ∀ {A B} {F : Set → Set} {{_ : Applicative F}}
{x y : F A} {f : F (A → B)} →
x ≡ y → f <*> x ≡ f <*> y
cong-ap-right refl = refl
-- lemma : ∀ {A B} {F : Set → Set} {{_ : Applicative F}}
-- {x : F A} {f : A → B} →
-- pure (_$_) <*> pure f <*> x ≡ (pure f) <*> x
-- lemma = refl
-- Identity: pure id <*> v = v
t1 : ∀ {A : Set} {F : Set → Set} {{_ : Selective F}} →
(v : F A) → (apS (pure id) v) ≡ v
t1 v = apS (pure id) v
≡⟨ refl ⟩ -- Definition of 'apS'
handle (left <$> pure id) (flip (_$_) <$> v)
≡⟨ cong-handle fmap-pure-ap ⟩
handle (pure left <*> pure id) (flip (_$_) <$> v)
≡⟨ cong-handle ap-homomorphism ⟩ -- Push 'left' inside 'pure'
handle (pure (left id)) (flip (_$_) <$> v)
≡⟨ p2 ⟩ -- Apply P2
(_$ id) <$> (flip (_$_) <$> v)
≡⟨ refl ⟩ let f = (_$ id)
g = flip (_$_) in
f <$> (g <$> v)
≡⟨ fmap-pure-ap ⟩
pure f <*> (g <$> v)
≡⟨ cong-ap-right fmap-pure-ap ⟩
pure f <*> (pure g <*> v)
≡⟨ refl ⟩
pure (_$ id) <*> (pure g <*> v)
≡⟨ {!?!} ⟩ -- ap-interchange
(pure g <*> v) <*> pure id
≡⟨ refl ⟩
pure (λ x f -> f x) <*> v <*> pure id
≡⟨ {!!} ⟩
-- (f <$> g) <$> v
-- ≡⟨ refl ⟩
-- (f ∘ g) <$> v
-- ≡⟨ refl ⟩
-- ((_$ id) ∘ flip (_$_)) <$> v
-- ≡⟨ refl ⟩ -- Simplify
pure id <*> v
≡⟨ fmap-pure-ap ⟩
id <$> v
≡⟨ fmap-id ⟩ -- Functor identity: fmap id = id
v ∎
t1' : ∀ {A : Set} {F : Set → Set} {{_ : Selective F}} →
(v : F A) → (apS (pure id) v) ≡ v
t1' v = apS (pure id) v
≡⟨ refl ⟩ -- Definition of 'apS'
handle (left <$> pure id) (flip (_$_) <$> v)
≡⟨ cong-handle fmap-pure-ap ⟩
handle (pure left <*> pure id) (flip (_$_) <$> v)
≡⟨ cong-handle ap-homomorphism ⟩ -- Push 'left' inside 'pure'
handle (pure (left id)) (flip (_$_) <$> v)
≡⟨ p2 ⟩ -- Apply P2
(_$ id) <$> (flip (_$_) <$> v)
≡⟨ refl ⟩
let f = (_$ id)
g = flip (_$_) in
f <$> (g <$> v)
≡⟨ {!!} ⟩
(f ∘ g) <$> v
≡⟨ refl ⟩
((_$ id) ∘ flip (_$_)) <$> v
≡⟨ refl ⟩ -- Simplify
id <$> v
≡⟨ fmap-id ⟩ -- Functor identity: fmap id = id
v ∎
-- Homomorphism: pure f <*> pure x = pure (f x)
t2 : ∀ {A B : Set} {F : Set → Set} {{_ : Selective F}}
(f : A → B) (x : A) →
(apS (pure {F} f) (pure x)) ≡ pure (f x)
t2 f x = apS (pure f) (pure x)
≡⟨ refl ⟩ -- Definition of 'apS'
handle (left <$> pure f) (flip (_$_) <$> pure x)
≡⟨ cong-handle fmap-pure-ap ⟩ -- Push 'Left' inside 'pure'
handle (pure left <*> pure f) (flip (_$_) <$> pure x)
≡⟨ cong-handle ap-homomorphism ⟩
handle (pure (left f)) (flip (_$_) <$> pure x)
≡⟨ p2 ⟩ -- Apply P2
(_$ f) <$> (flip (_$_) <$> pure x)
≡⟨ {!?!} ⟩ -- Simplify
f <$> pure x
≡⟨ fmap-pure-ap ⟩
pure f <*> pure x
≡⟨ ap-homomorphism ⟩
pure (f x) ∎
-- Interchange: u <*> pure y = pure ($y) <*> u
t3 : ∀ {A B : Set} {F : Set → Set} {{_ : Selective F}}
(f : F (A → B)) (x : A) →
apS f (pure x) ≡ apS (pure (_$ x)) f
t3 f x = {!!}
-- === -- Express right-hand side of the theorem using 'apS'
-- apS (pure ($y)) u
-- === -- Definition of 'apS'
-- handle (Left <$> pure ($y)) (flip ($) <$> u)
-- === -- Push 'Left' inside 'pure'
-- handle (pure (Left ($y))) (flip ($) <$> u)
-- === -- Apply P2
-- ($($y)) <$> (flip ($) <$> u)
-- === -- Simplify, obtaining (#)
-- ($y) <$> u
either-left-lemma : ∀ {A B C : Set} {x : A} {f : A → C} {g : B → C} →
either f g (left x) ≡ f x
either-left-lemma = refl
either-left-lemma1 : ∀ {A B C : Set}
{F : Set → Set} {{_ : Functor F}} →
{x : F A} {f : A → C} {g : B → C} →
(either f g <$> (fmap {F = F} left x)) ≡ (f <$> x)
either-left-lemma1 = {!!}
t3-lhs-lemma : ∀ {A B : Set} {F : Set → Set} {{_ : Selective F}}
(f : F (A → B)) (x : A) →
apS f (pure x) ≡ ((_$ x) <$> f)
t3-lhs-lemma {A} {B} f x =
apS f (pure x)
≡⟨ refl ⟩ -- Definition of 'apS'
handle (left <$> f) (flip (_$_) <$> pure x)
≡⟨ cong-handle-handler fmap-pure-ap ⟩ -- Rewrite to have a pure handler
handle (left <$> f) (pure (flip (_$_)) <*> pure x)
≡⟨ cong-handle-handler ap-homomorphism ⟩
handle (left <$> f) (pure (flip (_$_) x))
≡⟨ cong-handle-handler refl ⟩
handle (left <$> f) (pure (_$ x))
≡⟨ p1 ⟩ -- Apply P1
either (_$ x) id <$> (left <$> f)
≡⟨ {!!} ⟩
(_$ x) <$> f ∎
-- -- Express the lefthand side using 'apS'
-- apS u (pure y)
-- === -- Definition of 'apS'
-- handle (Left <$> u) (flip ($) <$> pure y)
-- === -- Rewrite to have a pure handler
-- handle (Left <$> u) (pure ($y))
-- === -- Apply P1
-- either ($y) id <$> (Left <$> u)
-- === -- Simplify, obtaining (#)
-- ($y) <$> u
| {
"alphanum_fraction": 0.3937218233,
"avg_line_length": 35.8622754491,
"ext": "agda",
"hexsha": "d6f0a6c7918fa813908f1d3d797eb6c613eecb40",
"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": "4af28af701b65b45900bba2d92a526ce44a3be63",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "tuura/selective-theory-agda",
"max_forks_repo_path": "src/Selective/Theorems.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4af28af701b65b45900bba2d92a526ce44a3be63",
"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": "tuura/selective-theory-agda",
"max_issues_repo_path": "src/Selective/Theorems.agda",
"max_line_length": 78,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "4af28af701b65b45900bba2d92a526ce44a3be63",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "tuura/selective-theory-agda",
"max_stars_repo_path": "src/Selective/Theorems.agda",
"max_stars_repo_stars_event_max_datetime": "2020-06-22T12:31:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-11T14:42:19.000Z",
"num_tokens": 2104,
"size": 5989
} |
open import Prelude hiding (_≤_)
open import Data.Nat.Properties
open import Induction.Nat
module Implicits.Resolution.GenericFinite.Examples.Haskell
where
open import Implicits.Resolution.GenericFinite.TerminationCondition
open import Implicits.Resolution.GenericFinite.Resolution
open import Implicits.Resolution.GenericFinite.Algorithm
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification
open import Implicits.Resolution.Termination
open import Implicits.Substitutions
haskellCondition : TerminationCondition
haskellCondition = record
{ TCtx = ∃ Type
; _<_ = _hρ<_
; _<?_ = λ { (_ , x) (_ , y) → x hρ<? y }
; step = λ Φ Δ a b τ → , a
; wf-< = hρ<-well-founded
}
open ResolutionRules haskellCondition public
open ResolutionAlgorithm haskellCondition public
module Deterministic⊆HaskellFinite where
open import Implicits.Resolution.Deterministic.Resolution as D
open import Data.Nat hiding (_<_)
open import Data.Nat.Properties
open import Relation.Binary using (module DecTotalOrder)
open import Extensions.ListFirst
open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl; trans to ≤-trans)
module F = ResolutionRules haskellCondition
module M = MetaTypeMetaSubst
lem₆ : ∀ {ν μ} (a : Type ν) (b : Type (suc μ)) c → (, a) hρ< (, b) → (, a) hρ< (, b tp[/tp c ])
lem₆ a b c p = ≤-trans p (h||a/s|| b (TypeSubst.sub c))
where open SubstSizeLemmas
lem₅ : ∀ {ν μ} {Δ : ICtx ν} {b τ} (a : Type μ) → Δ ⊢ b ↓ τ → (, a) hρ< (, b) → (, a) hρ< (, simpl τ)
lem₅ {τ = τ} a (i-simp .τ) q = q
lem₅ a (i-iabs _ p) q = lem₅ a p q
lem₅ a (i-tabs {ρ = b} c p) q = lem₅ a p (lem₆ a b c q)
-- Oliveira's termination condition is part of the well-formdness of types
-- So we assume here that ⊢term x holds for all types x
mutual
lem : ∀ {ν} {Δ : ICtx ν} {a r g} →
(∀ {ν} (a : Type ν) → ⊢term a) →
(, simpl a) hρ≤ g → Δ D.⊢ r ↓ a → Δ F., g ⊢ r ↓ a
lem all-⊢term q (i-simp a) = i-simp a
lem {a = a} {g = g}all-⊢term q (i-iabs {ρ₁ = ρ₁} {ρ₂ = ρ₂} ⊢ρ₁ ρ₂↓a) with all-⊢term (ρ₁ ⇒ ρ₂)
lem {a = a} {g = g} all-⊢term q (i-iabs {ρ₁ = ρ₁} {ρ₂ = ρ₂} ⊢ρ₁ ρ₂↓a) | term-iabs _ _ a-hρ<-b _ =
i-iabs ρ₁<g (complete' (, ρ₁) all-⊢term ⊢ρ₁ ≤-refl) (lem all-⊢term q ρ₂↓a)
where
ρ₁<g : (, ρ₁) hρ< g
ρ₁<g = ≤-trans (lem₅ ρ₁ ρ₂↓a a-hρ<-b) q
lem all-⊢term q (i-tabs b p) = i-tabs b (lem all-⊢term q p)
complete' : ∀ {ν} {a : Type ν} {Δ : ICtx ν} → (g : ∃ Type) →
(∀ {ν} (a : Type ν) → ⊢term a) → Δ D.⊢ᵣ a → (, a) hρ≤ g →
Δ F., g ⊢ᵣ a
complete' g all-⊢term (r-simp x p) q = r-simp (proj₁ $ first⟶∈ x) (lem all-⊢term q p)
complete' g all-⊢term (r-iabs ρ₁ p) q = r-iabs ρ₁ (complete' g all-⊢term p q)
complete' g all-⊢term (r-tabs p) q = r-tabs (complete' g all-⊢term p q)
complete : ∀ {ν} {a : Type ν} {Δ : ICtx ν} →
(∀ {ν} (a : Type ν) → ⊢term a) → Δ D.⊢ᵣ a → Δ F., (, a) ⊢ᵣ a
complete all-⊢term p = complete' _ all-⊢term p ≤-refl
| {
"alphanum_fraction": 0.6072377158,
"avg_line_length": 41.8333333333,
"ext": "agda",
"hexsha": "165a4e0e653a98859c17c96899ca8d3ca20c0552",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/GenericFinite/Examples/Haskell.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/GenericFinite/Examples/Haskell.agda",
"max_line_length": 102,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/GenericFinite/Examples/Haskell.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 1230,
"size": 3012
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Groups.Definition
module Groups.Subgroups.Examples {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} (G : Group S _+_) where
open import Groups.Subgroups.Definition G
open import Groups.Lemmas G
open Group G
open Setoid S
open Equivalence eq
trivialSubgroupPred : A → Set b
trivialSubgroupPred a = (a ∼ 0G)
trivialSubgroup : Subgroup trivialSubgroupPred
Subgroup.isSubset trivialSubgroup x=y x=0 = transitive (symmetric x=y) x=0
Subgroup.closedUnderPlus trivialSubgroup x=0 y=0 = transitive (+WellDefined x=0 y=0) identLeft
Subgroup.containsIdentity trivialSubgroup = reflexive
Subgroup.closedUnderInverse trivialSubgroup x=0 = transitive (inverseWellDefined x=0) invIdent
improperSubgroupPred : A → Set
improperSubgroupPred a = True
improperSubgroup : Subgroup improperSubgroupPred
Subgroup.isSubset improperSubgroup _ _ = record {}
Subgroup.closedUnderPlus improperSubgroup _ _ = record {}
Subgroup.containsIdentity improperSubgroup = record {}
Subgroup.closedUnderInverse improperSubgroup _ = record {}
| {
"alphanum_fraction": 0.785472973,
"avg_line_length": 34.8235294118,
"ext": "agda",
"hexsha": "09bb189b74f98f3ae145d8063705790cd242bab8",
"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": "Groups/Subgroups/Examples.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": "Groups/Subgroups/Examples.agda",
"max_line_length": 119,
"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": "Groups/Subgroups/Examples.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": 327,
"size": 1184
} |
module nat where
data N : Set where
zero : N
suc : N -> N
_+_ : N -> N -> N
n + zero = n
n + (suc m) = suc (n + m)
_*_ : N -> N -> N
n * zero = zero
n * (suc m) = (m * n) + m
| {
"alphanum_fraction": 0.4371584699,
"avg_line_length": 13.0714285714,
"ext": "agda",
"hexsha": "034e4c86817c034e57fbeaab49991c282c3212b9",
"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": "2f064f660d6f3ce5fc3e5b05e8f096fa4b26c717",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "uedatakumi/nat",
"max_forks_repo_path": "nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2f064f660d6f3ce5fc3e5b05e8f096fa4b26c717",
"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": "uedatakumi/nat",
"max_issues_repo_path": "nat.agda",
"max_line_length": 25,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "2f064f660d6f3ce5fc3e5b05e8f096fa4b26c717",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "uedatakumi/nat",
"max_stars_repo_path": "nat.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-02T15:31:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-02T15:31:17.000Z",
"num_tokens": 83,
"size": 183
} |
module _ where
module N (_ : Set₁) where
data D : Set₁ where
c : Set → D
open N Set using (D) renaming (module D to MD)
open import Common.Equality
-- No longer two ways to qualify
twoWaysToQualify : D.c ≡ MD.c
twoWaysToQualify = refl
| {
"alphanum_fraction": 0.685483871,
"avg_line_length": 14.5882352941,
"ext": "agda",
"hexsha": "17bf74db7481498f956e8e146072e5cdf341c2be",
"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/Issue836a.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/Issue836a.agda",
"max_line_length": 46,
"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/Issue836a.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": 248
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Strict2Group.Explicit.Notation where
open import Cubical.Foundations.Prelude hiding (comp)
open import Cubical.Data.Group.Base
module S2GBaseNotation {ℓ : Level} (C₀ C₁ : Group ℓ) (s t : morph C₁ C₀) (i : morph C₀ C₁) (∘ : (g f : Group.type C₁) → (s .fst) g ≡ (t .fst f) → Group.type C₁) where
-- group operations of the object group
TC₀ = Group.type C₀
1₀ = isGroup.id (Group.groupStruc C₀)
_∙₀_ = isGroup.comp (Group.groupStruc C₀)
C₀⁻¹ = isGroup.inv (Group.groupStruc C₀)
rUnit₀ = isGroup.rUnit (Group.groupStruc C₀)
lUnit₀ = isGroup.lUnit (Group.groupStruc C₀)
assoc₀ = isGroup.assoc (Group.groupStruc C₀)
lCancel₀ = isGroup.lCancel (Group.groupStruc C₀)
rCancel₀ = isGroup.lCancel (Group.groupStruc C₀)
-- group operation of the morphism group
TC₁ = Group.type C₁
1₁ = isGroup.id (Group.groupStruc C₁)
C₁⁻¹ = isGroup.inv (Group.groupStruc C₁)
_∙₁_ = isGroup.comp (Group.groupStruc C₁)
rUnit₁ = isGroup.rUnit (Group.groupStruc C₁)
lUnit₁ = isGroup.lUnit (Group.groupStruc C₁)
assoc₁ = isGroup.assoc (Group.groupStruc C₁)
lCancel₁ = isGroup.lCancel (Group.groupStruc C₁)
rCancel₁ = isGroup.lCancel (Group.groupStruc C₁)
-- interface for source, target and identity map
src = fst s
src∙₁ = snd s
tar = fst t
tar∙₁ = snd t
id = fst i
id∙₀ = snd i
∙c : {g f g' f' : Group.type C₁} → (coh1 : s .fst g ≡ t .fst f) → (coh2 : s .fst g' ≡ t .fst f') → s .fst (g ∙₁ g') ≡ t .fst (f ∙₁ f')
∙c {g} {f} {g'} {f'} coh1 coh2 = (s .snd g g') ∙ ((cong (_∙₀ (s .fst g')) coh1) ∙ (cong ((t .fst f) ∙₀_) coh2) ∙ (sym (t .snd f f')))
-- for two morphisms the condition for them to be composable
CohCond : (g f : TC₁) → Type ℓ
CohCond g f = src g ≡ tar f
| {
"alphanum_fraction": 0.6549375709,
"avg_line_length": 38.3043478261,
"ext": "agda",
"hexsha": "a0e026bb9c1aa1872d184687aa1606ea78dafe39",
"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/Data/Strict2Group/Explicit/Notation.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/Data/Strict2Group/Explicit/Notation.agda",
"max_line_length": 166,
"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/Data/Strict2Group/Explicit/Notation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 680,
"size": 1762
} |
------------------------------------------------------------------------
-- Application of substitutions
------------------------------------------------------------------------
-- Given an operation which applies a substitution to a term, subject
-- to some conditions, more operations and lemmas are defined/proved.
-- (This module reexports various other modules.)
open import Data.Universe.Indexed
module deBruijn.Substitution.Data.Application
{i u e} {Uni : IndexedUniverse i u e} where
import deBruijn.Substitution.Data.Application.Application
open deBruijn.Substitution.Data.Application.Application
{_} {_} {_} {Uni} public
import deBruijn.Substitution.Data.Application.Application21
open deBruijn.Substitution.Data.Application.Application21
{_} {_} {_} {Uni} public
import deBruijn.Substitution.Data.Application.Application22
open deBruijn.Substitution.Data.Application.Application22
{_} {_} {_} {Uni} public
import deBruijn.Substitution.Data.Application.Application1
open deBruijn.Substitution.Data.Application.Application1
{_} {_} {_} {Uni} public
| {
"alphanum_fraction": 0.688723206,
"avg_line_length": 39.7407407407,
"ext": "agda",
"hexsha": "a390dbd92a0143b11e7a7fc746f4452a5df0ecf9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependently-typed-syntax",
"max_forks_repo_path": "deBruijn/Substitution/Data/Application.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/dependently-typed-syntax",
"max_issues_repo_path": "deBruijn/Substitution/Data/Application.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependently-typed-syntax",
"max_stars_repo_path": "deBruijn/Substitution/Data/Application.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": 226,
"size": 1073
} |
----------------------------------------------------------------------------
-- Well-founded induction on the natural numbers
----------------------------------------------------------------------------
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Data.Nat.Induction.NonAcc.WF-I where
open import FOTC.Base
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesI
open import FOTC.Data.Nat.Type
------------------------------------------------------------------------------
-- Well-founded induction
postulate
<-wfind₁ : (A : D → Set) →
(∀ {n} → N n → (∀ {m} → N m → m < n → A m) → A n) →
∀ {n} → N n → A n
postulate PN : ∀ {n m} → N n → m < n → N m
-- Well-founded induction removing N m from the second line.
<-wfind₂ : (A : D → Set) →
(∀ {n} → N n → (∀ {m} → m < n → A m) → A n) →
∀ {n} → N n → A n
<-wfind₂ A h = <-wfind₁ A (λ Nn' h' → h Nn' (λ p → h' (PN Nn' p) p))
-- Well-founded induction removing N n from the second line.
<-wfind₃ : (A : D → Set) →
(∀ {n} → (∀ {m} → N m → m < n → A m) → A n) →
∀ {n} → N n → A n
<-wfind₃ A h = <-wfind₁ A (λ Nn' h' → h h')
| {
"alphanum_fraction": 0.4299201162,
"avg_line_length": 35.3076923077,
"ext": "agda",
"hexsha": "caf58ddc55b1f303aa357a76e46ecd1167916253",
"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/FOTC/Data/Nat/Induction/NonAcc/WF-I.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/FOTC/Data/Nat/Induction/NonAcc/WF-I.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/FOTC/Data/Nat/Induction/NonAcc/WF-I.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": 408,
"size": 1377
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Property that elements are grouped
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.Grouped where
open import Data.List using (List; []; _∷_; map)
open import Data.List.Relation.Unary.All as All using (All; []; _∷_; all)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_)
open import Relation.Binary as B using (REL; Rel)
open import Relation.Unary as U using (Pred)
open import Relation.Nullary using (¬_; yes)
open import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Sum using (_⊎-dec_)
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Nullary.Negation using (¬?)
open import Level using (_⊔_)
infixr 5 _∷≉_ _∷≈_
data Grouped {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) : Pred (List A) (a ⊔ ℓ) where
[] : Grouped _≈_ []
_∷≉_ : ∀ {x xs} → All (λ y → ¬ (x ≈ y)) xs → Grouped _≈_ xs → Grouped _≈_ (x ∷ xs)
_∷≈_ : ∀ {x y xs} → x ≈ y → Grouped _≈_ (y ∷ xs) → Grouped _≈_ (x ∷ y ∷ xs)
module _ {a ℓ} {A : Set a} {_≈_ : Rel A ℓ} where
grouped? : B.Decidable _≈_ → U.Decidable (Grouped _≈_)
grouped? _≟_ [] = yes []
grouped? _≟_ (x ∷ []) = yes ([] ∷≉ [])
grouped? _≟_ (x ∷ y ∷ xs) = map′ from to ((x ≟ y ⊎-dec all (λ z → ¬? (x ≟ z)) (y ∷ xs)) ×-dec (grouped? _≟_ (y ∷ xs))) where
from : ((x ≈ y) ⊎ All (λ z → ¬ (x ≈ z)) (y ∷ xs)) × Grouped _≈_ (y ∷ xs) → Grouped _≈_ (x ∷ y ∷ xs)
from (inj₁ x≈y , grouped[y∷xs]) = x≈y ∷≈ grouped[y∷xs]
from (inj₂ all[x≉,y∷xs] , grouped[y∷xs]) = all[x≉,y∷xs] ∷≉ grouped[y∷xs]
to : Grouped _≈_ (x ∷ y ∷ xs) → ((x ≈ y) ⊎ All (λ z → ¬ (x ≈ z)) (y ∷ xs)) × Grouped _≈_ (y ∷ xs)
to (all[x≉,y∷xs] ∷≉ grouped[y∷xs]) = inj₂ all[x≉,y∷xs] , grouped[y∷xs]
to (x≈y ∷≈ grouped[y∷xs]) = inj₁ x≈y , grouped[y∷xs]
| {
"alphanum_fraction": 0.5313295976,
"avg_line_length": 46.7380952381,
"ext": "agda",
"hexsha": "c898c23e402c4f25564d0f48adda7655a2bf39ba",
"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/List/Relation/Unary/Grouped.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/List/Relation/Unary/Grouped.agda",
"max_line_length": 126,
"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/List/Relation/Unary/Grouped.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": 770,
"size": 1963
} |
-- Convert between `X` and `X-Bool`
{-# OPTIONS --without-K --safe --exact-split #-}
module Constructive.Axiom.Properties.Bool where
-- agda-stdlib
open import Level renaming (suc to lsuc; zero to lzero)
open import Data.Empty
open import Data.Unit using (⊤; tt)
open import Data.Bool using (Bool; true; false; not)
open import Data.Sum as Sum
open import Data.Product as Prod
open import Function.Base
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Relation.Binary.PropositionalEquality
using (_≡_; _≢_; refl; subst; sym; cong)
-- agda-misc
open import Constructive.Axiom
open import Constructive.Combinators
open import Constructive.Common
private
toBool : ∀ {a p} {A : Set a} {P : A → Set p} →
DecU P → (A → Bool)
toBool P? x = ⌊ dec⊎⇒dec (P? x) ⌋
toDecU : ∀ {a} p {A : Set a} (P : A → Bool) →
DecU (λ x → lift {ℓ = p} (P x) ≡ lift true)
toDecU p P x with P x
... | false = inj₂ (λ ())
... | true = inj₁ refl
lift-injective : ∀ {a ℓ} {A : Set a} {x y : A} →
lift {ℓ = ℓ} x ≡ lift y → x ≡ y
lift-injective refl = refl
lift-injective′ : ∀ {a ℓ} {A : Set a} {P : A → Bool} →
∃ (λ x → lift {ℓ = ℓ} (P x) ≡ lift true) →
∃ (λ x → P x ≡ true)
lift-injective′ = Prod.map₂ lift-injective
lift-cong′ : ∀ {a p} {A : Set a} {P : A → Bool} →
∃ (λ x → P x ≡ true) → ∃ (λ x → lift (P x) ≡ lift true)
lift-cong′ {p = p} (x , y) = x , cong (lift {ℓ = p}) y
module _ {a p} {A : Set a} {P : A → Set p} (P? : DecU P) where
from-eq : ∀ x → toBool P? x ≡ true → P x
from-eq x eq with P? x
from-eq x eq | inj₁ Px = Px
from-eq x () | inj₂ ¬Px
equal-refl : (∃P : ∃ P) → toBool P? (proj₁ ∃P) ≡ true
equal-refl (x , Px) with P? x
... | inj₁ _ = refl
... | inj₂ ¬Px = ⊥-elim $ ¬Px Px
∃eq⇒∃P : (∃ λ x → toBool P? x ≡ true) → ∃ P
∃eq⇒∃P (x , eq) = x , from-eq x eq
∃P⇒∃eq : ∃ P → ∃ λ x → toBool P? x ≡ true
∃P⇒∃eq ∃P@(x , Px) = x , equal-refl ∃P
-- LPO <=> LPO-Bool
lpo⇒lpo-Bool : ∀ {a p} {A : Set a} → LPO A p → LPO-Bool A
lpo⇒lpo-Bool {a} {p} lpo P =
Sum.map lift-injective′ (contraposition lift-cong′) $ lpo (toDecU p P)
lpo-Bool⇒lpo : ∀ {a} p {A : Set a} → LPO-Bool A → LPO A p
lpo-Bool⇒lpo p lpo-Bool P? =
Sum.map (∃eq⇒∃P P?) (contraposition (∃P⇒∃eq P?)) $
lpo-Bool (toBool P?)
-- LLPO <=> LLPO-Bool
llpo⇒llpo-Bool : ∀ {a p} {A : Set a} → LLPO A p → LLPO-Bool A
llpo⇒llpo-Bool {a} {p} llpo P Q h =
Sum.map (contraposition lift-cong′) (contraposition lift-cong′) $
llpo (toDecU p P) (toDecU p Q)
(contraposition (Prod.map lift-injective′ lift-injective′) h)
llpo-Bool⇒llpo : ∀ {a} p {A : Set a} → LLPO-Bool A → LLPO A p
llpo-Bool⇒llpo p llpo-Bool P? Q? ¬[∃P×∃Q] =
Sum.map (contraposition (∃P⇒∃eq P?)) (contraposition (∃P⇒∃eq Q?)) $
llpo-Bool (toBool P?) (toBool Q?)
(contraposition (Prod.map (∃eq⇒∃P P?) (∃eq⇒∃P Q?)) ¬[∃P×∃Q])
-- MP⊎ <=> MP⊎-Bool
mp⊎⇒mp⊎-Bool : ∀ {a p} {A : Set a} → MP⊎ A p → MP⊎-Bool A
mp⊎⇒mp⊎-Bool {a} {p} mp⊎ P Q ¬[¬∃Peq׬∃Qeq] =
Sum.map
(DN-map lift-injective′) (DN-map lift-injective′) $ mp⊎
(toDecU p P) (toDecU p Q) (contraposition (λ {(u , v) →
contraposition lift-cong′ u , contraposition lift-cong′ v}) ¬[¬∃Peq׬∃Qeq])
mp⊎-Bool⇒mp⊎ : ∀ {a} p {A : Set a} → MP⊎-Bool A → MP⊎ A p
mp⊎-Bool⇒mp⊎ p mp⊎-Bool P? Q? ¬[¬∃P׬Q] =
Sum.map (DN-map (∃eq⇒∃P P?)) (DN-map (∃eq⇒∃P Q?)) $
mp⊎-Bool (toBool P?) (toBool Q?) (contraposition (Prod.map
(contraposition (∃P⇒∃eq P?)) (contraposition (∃P⇒∃eq Q?))) ¬[¬∃P׬Q])
-- LPO-Bool <=> LPO-Bool-Alt
private
not-injective : ∀ {x y} → not x ≡ not y → x ≡ y
not-injective {false} {false} refl = refl
not-injective {false} {true} ()
not-injective {true} {false} ()
not-injective {true} {true} refl = refl
x≡false⇒x≢true : ∀ {x} → x ≡ false → x ≢ true
x≡false⇒x≢true {false} refl ()
not[x]≢true⇒x≡true : ∀ {x} → not x ≢ true → x ≡ true
not[x]≢true⇒x≡true {false} neq = ⊥-elim $ neq refl
not[x]≢true⇒x≡true {true} _ = refl
not[x]≡true→x≢true : ∀ {x} → not x ≡ true → x ≢ true
not[x]≡true→x≢true notx≡true = x≡false⇒x≢true (not-injective notx≡true)
x≢true⇒x≡false : ∀ {x} → x ≢ true → x ≡ false
x≢true⇒x≡false {false} neq = refl
x≢true⇒x≡false {true} neq = ⊥-elim $ neq refl
lpo-Bool⇒lpo-Bool-Alt : ∀ {a} {A : Set a} → LPO-Bool A → LPO-Bool-Alt A
lpo-Bool⇒lpo-Bool-Alt lpo-Bool P =
Sum.map (Prod.map₂ not-injective)
(λ ¬∃notPx≡true x → not[x]≢true⇒x≡true $ ¬∃P→∀¬P ¬∃notPx≡true x) $
lpo-Bool (not ∘ P)
lpo-Bool-Alt⇒lpo-Bool : ∀ {a} {A : Set a} → LPO-Bool-Alt A → LPO-Bool A
lpo-Bool-Alt⇒lpo-Bool lpo-Bool-Alt P =
Sum.map (Prod.map₂ not-injective)
(λ ∀x→notPx≡true → ∀¬P→¬∃P λ x → not[x]≡true→x≢true $ ∀x→notPx≡true x) $
lpo-Bool-Alt (not ∘ P)
| {
"alphanum_fraction": 0.5486026731,
"avg_line_length": 36.3088235294,
"ext": "agda",
"hexsha": "887f90a17d4c385f9beca7dd2282d28b8b1627f4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Constructive/Axiom/Properties/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Constructive/Axiom/Properties/Bool.agda",
"max_line_length": 82,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Constructive/Axiom/Properties/Bool.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 2255,
"size": 4938
} |
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Cubical.Path
data D : Set where
c : D
data E : Set where
c : (x y : E) → x ≡ y
postulate
A : Set
f : (x y : E) → x ≡ y → (u v : A) → u ≡ v
works : E → A
works (c x y i) = f x y (E.c x y) (works x) (works y) i
fails : E → A
fails (c x y i) = f x y ( c x y) (fails x) (fails y) i
| {
"alphanum_fraction": 0.5087209302,
"avg_line_length": 17.2,
"ext": "agda",
"hexsha": "c8f1e9e655790049c8e7629351fde08ed0e1d491",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue4404.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/Issue4404.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/Issue4404.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": 151,
"size": 344
} |
module Selective.Examples.TestCall where
open import Selective.Libraries.Call
open import Prelude
AddReplyMessage : MessageType
AddReplyMessage = ValueType UniqueTag ∷ [ ValueType ℕ ]ˡ
AddReply : InboxShape
AddReply = [ AddReplyMessage ]ˡ
AddMessage : MessageType
AddMessage = ValueType UniqueTag ∷ ReferenceType AddReply ∷ ValueType ℕ ∷ [ ValueType ℕ ]ˡ
Calculator : InboxShape
Calculator = [ AddMessage ]ˡ
calculatorActor : ∀ {i} → ∞ActorM (↑ i) Calculator (Lift (lsuc lzero) ⊤) [] (λ _ → [])
calculatorActor .force = receive ∞>>= λ {
(Msg Z (tag ∷ _ ∷ n ∷ m ∷ [])) .force →
(Z ![t: Z ] (lift tag ∷ [ lift (n + m) ]ᵃ)) ∞>> (do
strengthen []
calculatorActor)
; (Msg (S ()) _)
}
TestBox : InboxShape
TestBox = AddReply
calltestActor : ∀{i} → ∞ActorM i TestBox (Lift (lsuc lzero) ℕ) [] (λ _ → [])
calltestActor .force = spawn∞ calculatorActor ∞>> do
x ← call Z Z 0
((lift 10) ∷ [ lift 32 ]ᵃ)
⊆-refl Z
strengthen []
return-result x
where
return-result : SelectedMessage {TestBox} (call-select 0 [ Z ]ᵐ Z) →
∀ {i} → ∞ActorM i TestBox (Lift (lsuc lzero) ℕ) [] (λ _ → [])
return-result record { msg = (Msg Z (tag ∷ n ∷ [])) } = return n
return-result record { msg = (Msg (S x) x₁) ; msg-ok = () } | {
"alphanum_fraction": 0.6143637783,
"avg_line_length": 31.243902439,
"ext": "agda",
"hexsha": "6139cc7fbb7156f16b612fef0e5410fbfd128214",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/singly-typed-actors",
"max_forks_repo_path": "src/Selective/Examples/TestCall.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zalastax/singly-typed-actors",
"max_issues_repo_path": "src/Selective/Examples/TestCall.agda",
"max_line_length": 90,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/thesis",
"max_stars_repo_path": "src/Selective/Examples/TestCall.agda",
"max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z",
"num_tokens": 430,
"size": 1281
} |
open import Common.Level
open import Common.Prelude
open import Common.Reflection
open import Common.Equality
postulate
a b : Level
data Check : Set where
check : (x y : Term) → x ≡ y → Check
pattern _==_ x y = check x y refl
pattern `a = def (quote a) []
pattern `b = def (quote b) []
pattern `suc x = def (quote lsuc) (vArg x ∷ [])
pattern _`⊔_ x y = def (quote _⊔_) (vArg x ∷ vArg y ∷ [])
t₀ = quoteTerm Set₃ == sort (lit 3)
t₁ = quoteTerm (Set a) == sort (set `a)
t₂ = quoteTerm (Set (lsuc b)) == sort (set (`suc `b))
t₃ = quoteTerm (Set (a ⊔ b)) == sort (set (`a `⊔ `b))
| {
"alphanum_fraction": 0.6149914821,
"avg_line_length": 24.4583333333,
"ext": "agda",
"hexsha": "cb5aaea3c61879cf3492b9a1b3ff4e85025c37ed",
"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/Issue1207.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/Issue1207.agda",
"max_line_length": 57,
"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/Issue1207.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": 217,
"size": 587
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.