Search is not available for this dataset
text
string | meta
dict |
---|---|
open import Relation.Binary.Core
module TreeSort.Impl2.Correctness.Permutation {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import BBSTree _≤_
open import Bound.Total A
open import Bound.Total.Order _≤_
open import Data.List
open import Data.Sum
open import List.Permutation.Base A
open import List.Permutation.Base.Concatenation A
open import TreeSort.Impl2 _≤_ tot≤
lemma-insert-/ : {a b : Bound}{x : A}(a≤x : LeB a (val x))(x≤b : LeB (val x) b)(t : BBSTree a b) → (flatten (insert a≤x x≤b t)) / x ⟶ (flatten t)
lemma-insert-/ a≤x x≤b (bslf _) = /head
lemma-insert-/ {x = x} b≤x x≤t (bsnd {x = y} b≤y y≤t l r)
with tot≤ x y
... | inj₁ x≤y = lemma++/r (lemma-insert-/ b≤x (lexy x≤y) l)
... | inj₂ y≤x = lemma++/l {xs = flatten l} (/tail (lemma-insert-/ (lexy y≤x) x≤t r))
theorem-treeSort∼ : (xs : List A) → xs ∼ (flatten (treeSort xs))
theorem-treeSort∼ [] = ∼[]
theorem-treeSort∼ (x ∷ xs) = ∼x /head (lemma-insert-/ lebx lext (treeSort xs)) (theorem-treeSort∼ xs)
| {
"alphanum_fraction": 0.6183574879,
"avg_line_length": 34.5,
"ext": "agda",
"hexsha": "4373215c7d7e482dce204a26d5b86ec73f0552bd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/TreeSort/Impl2/Correctness/Permutation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/TreeSort/Impl2/Correctness/Permutation.agda",
"max_line_length": 146,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/TreeSort/Impl2/Correctness/Permutation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 396,
"size": 1035
} |
-- Jesper, 2017-01-24: if we allow a variable to be instantiated with a value
-- of a supertype, the resulting dot pattern won't be type-correct.
open import Common.Size
data D (i : Size) : (j : Size< ↑ i) → Set where
c : ∀ (j : Size< ↑ i) (k : Size< ↑ j)
→ D i j
→ D j k
→ D i k
split : ∀ i (j : Size< ↑ i) → D i j → Set
split i j x = {!x!} -- split on x
-- Expected: splitting on x succeeds with
-- split i .k (c j₁ k x x₁) = {!!}
| {
"alphanum_fraction": 0.5505376344,
"avg_line_length": 24.4736842105,
"ext": "agda",
"hexsha": "768397b9ef43120a924572c9b7ea17073b23b7ab",
"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": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Blaisorblade/Agda",
"max_forks_repo_path": "test/interaction/Issue2407.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"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": "Blaisorblade/Agda",
"max_issues_repo_path": "test/interaction/Issue2407.agda",
"max_line_length": 77,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "Blaisorblade/Agda",
"max_stars_repo_path": "test/interaction/Issue2407.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 166,
"size": 465
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.EilenbergMacLane
module cohomology.CupProduct.OnEM.InLowDegrees2 {i} {j} (G : AbGroup i) (H : AbGroup j) where
private
module G = AbGroup G
module H = AbGroup H
module G⊗H = TensorProduct G H
open EMExplicit G⊗H.abgroup
open import cohomology.CupProduct.OnEM.InLowDegrees G H public
open import cohomology.CupProduct.OnEM.CommutativityInLowDegrees
open CP₁₁-comm G H
cp₁₁-embase-r : (x : EM₁ G.grp) → cp₁₁ x embase == [ north ]₂
cp₁₁-embase-r x = CP₁₁Comm.f x embase
module ∧-cp₁₁-Rec =
SmashRec {X = ⊙EM₁ G.grp} {Y = ⊙EM₁ H.grp} {C = EM 2}
cp₁₁
[ north ]₂ [ north ]₂
cp₁₁-embase-r
(λ y → idp)
∧-cp₁₁ : ⊙EM₁ G.grp ∧ ⊙EM₁ H.grp → EM 2
∧-cp₁₁ = ∧-cp₁₁-Rec.f
⊙∧-cp₁₁ : ⊙EM₁ G.grp ⊙∧ ⊙EM₁ H.grp ⊙→ ⊙EM 2
⊙∧-cp₁₁ = ∧-cp₁₁-Rec.f , idp
| {
"alphanum_fraction": 0.6383467279,
"avg_line_length": 26.3939393939,
"ext": "agda",
"hexsha": "0b61e755fb073c8d03f1e6bf92ce9b305a5dd2ae",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "theorems/cohomology/CupProduct/OnEM/InLowDegrees2.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "theorems/cohomology/CupProduct/OnEM/InLowDegrees2.agda",
"max_line_length": 93,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "theorems/cohomology/CupProduct/OnEM/InLowDegrees2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 357,
"size": 871
} |
------------------------------------------------------------------------------
-- Axiomatic PA propositional equality
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityATP where
open import PA.Axiomatic.Mendelson.Base
------------------------------------------------------------------------------
-- Identity properties
postulate ≈-refl : ∀ {n} → n ≈ n
{-# ATP prove ≈-refl #-}
postulate ≈-sym : ∀ {m n} → m ≈ n → n ≈ m
{-# ATP prove ≈-sym #-}
postulate ≈-trans : ∀ {m n o} → m ≈ n → n ≈ o → m ≈ o
{-# ATP prove ≈-trans #-}
| {
"alphanum_fraction": 0.4080100125,
"avg_line_length": 31.96,
"ext": "agda",
"hexsha": "bae651150ee34346558accb95fd2065da5988999",
"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/PA/Axiomatic/Mendelson/Relation/Binary/PropositionalEqualityATP.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/PA/Axiomatic/Mendelson/Relation/Binary/PropositionalEqualityATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/PA/Axiomatic/Mendelson/Relation/Binary/PropositionalEqualityATP.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": 176,
"size": 799
} |
module Numeral.Natural.Oper.Proofs where
import Lvl
open import Functional
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Induction
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Operator
open import Structure.Operator.Proofs.Util
open import Structure.Operator.Properties
import Structure.Operator.Names as Names
open import Structure.Relator.Properties
open import Syntax.Transitivity
-- TODO: For old code
open import Numeral.Natural.Proofs public
open import Numeral.Natural.Oper.Proofs.Rewrite public
instance
[+]-identityₗ : Identityₗ(_+_)(0)
Identityₗ.proof([+]-identityₗ) = [+]-baseₗ
instance
[+]-identityᵣ : Identityᵣ(_+_)(0)
Identityᵣ.proof([+]-identityᵣ) {x} = ℕ-elim [≡]-intro (x ↦ [≡]-with(𝐒) {x + 𝟎}{x}) x
instance
[+]-identity : Identity (_+_) (0)
[+]-identity = intro
instance
[+]-associativity : Associativity(_+_)
Associativity.proof([+]-associativity) {x}{y}{z} = ℕ-elim [≡]-intro (i ↦ [≡]-with(𝐒) {(x + y) + i} {x + (y + i)}) z
instance
[+]-commutativity : Commutativity (_+_)
Commutativity.proof([+]-commutativity) {x}{y} = ℕ-elim base next y where
base = identityᵣ(_+_)(𝟎) 🝖 symmetry(_≡_) (identityₗ(_+_)(𝟎))
next = \i eq → ([≡]-with(𝐒) {x + i}{i + x} eq) 🝖 symmetry(_≡_) ([+]-stepₗ {i}{x})
[+1]-and-[𝐒] : ∀{x : ℕ} → (x + 1 ≡ 𝐒(x))
[+1]-and-[𝐒] {x} = [≡]-intro
[1+]-and-[𝐒] : ∀{x : ℕ} → (1 + x ≡ 𝐒(x))
[1+]-and-[𝐒] {x} = [+1]-and-[𝐒] {x} 🝖 commutativity(_+_) {x}{1}
[⋅]-absorberₗ-raw : Names.Absorberₗ(_⋅_)(0)
[⋅]-absorberₗ-raw {x} = ℕ-elim [≡]-intro (\i → [≡]-with(0 +_) {0 ⋅ i}{0}) x
{-# REWRITE [⋅]-absorberₗ-raw #-}
instance
[⋅]-absorberₗ : Absorberₗ(_⋅_)(0)
Absorberₗ.proof([⋅]-absorberₗ) {x} = [⋅]-absorberₗ-raw {x}
instance
[⋅]-absorberᵣ : Absorberᵣ(_⋅_)(0)
Absorberᵣ.proof([⋅]-absorberᵣ) {x} = [≡]-intro
instance
[⋅]-absorber : Absorber(_⋅_)(0)
[⋅]-absorber = intro
[⋅]-identityₗ-raw : Names.Identityₗ(_⋅_)(1)
[⋅]-identityₗ-raw {x} = ℕ-elim [≡]-intro (\i eq → (commutativity(_+_) {1} {1 ⋅ i}) 🝖 ([≡]-with(𝐒) {_}{i} eq)) x
{-# REWRITE [⋅]-identityₗ-raw #-}
instance
[⋅]-identityₗ : Identityₗ(_⋅_)(1)
Identityₗ.proof([⋅]-identityₗ) {x} = [⋅]-identityₗ-raw {x}
instance
[⋅]-identityᵣ : Identityᵣ(_⋅_)(1)
Identityᵣ.proof([⋅]-identityᵣ) = [≡]-intro
instance
[⋅]-identity : Identity(_⋅_)(1)
[⋅]-identity = intro
instance
[⋅][+]-distributivityᵣ : Distributivityᵣ(_⋅_)(_+_)
Distributivityᵣ.proof([⋅][+]-distributivityᵣ) {x}{y}{z} = ℕ-elim [≡]-intro next z where
next : ∀(z : ℕ) → ((x + y) ⋅ z) ≡ ((x ⋅ z) + (y ⋅ z)) → ((x + y) ⋅ 𝐒(z)) ≡ ((x ⋅ 𝐒(z)) + (y ⋅ 𝐒(z)))
next z proof = ([≡]-with((x + y) +_) proof) 🝖 (One.associate-commute4 {a = x}{y}{x ⋅ z}{y ⋅ z} (commutativity(_+_){x = y}))
[⋅]-with-[𝐒]ₗ : ∀{x y} → (𝐒(x) ⋅ y ≡ (x ⋅ y) + y)
[⋅]-with-[𝐒]ₗ {x}{y} = (distributivityᵣ(_⋅_)(_+_) {x}{1}{y}) 🝖 ([≡]-with(expr ↦ (x ⋅ y) + expr) ([⋅]-identityₗ-raw {y}))
[⋅]-with-[𝐒]ᵣ : ∀{x y} → (x ⋅ 𝐒(y) ≡ x + (x ⋅ y))
[⋅]-with-[𝐒]ᵣ = [≡]-intro
instance
[⋅][+]-distributivityₗ : Distributivityₗ(_⋅_)(_+_)
Distributivityₗ.proof([⋅][+]-distributivityₗ) {x}{y}{z} = p{x}{y}{z} where
p : Names.Distributivityₗ(_⋅_)(_+_)
p {𝟎} {y} {z} = [≡]-intro
p {𝐒 x} {𝟎} {z} = [≡]-intro
p {𝐒 x} {𝐒 y} {𝟎} = [≡]-intro
p {𝐒 x} {𝐒 y} {𝐒 z} = [≡]-with(𝐒 ∘ 𝐒) $
x + (x + (𝐒 x ⋅ (y + z))) 🝖[ _≡_ ]-[ [≡]-with((x +_) ∘ (x +_)) (p {𝐒 x} {y} {z}) ]
x + (x + ((𝐒 x ⋅ y) + (𝐒 x ⋅ z))) 🝖[ _≡_ ]-[ [≡]-with(x +_) (One.commuteₗ-assocᵣ ⦃ comm = intro(\{x y} → commutativity(_+_) {x}{y}) ⦄ {a = x}{b = 𝐒 x ⋅ y}{c = 𝐒 x ⋅ z}) ]
x + ((𝐒 x ⋅ y) + (x + (𝐒 x ⋅ z))) 🝖[ _≡_ ]-[ associativity(_+_) {x = x}{y = 𝐒 x ⋅ y} ]-sym
(x + (𝐒 x ⋅ y)) + (x + (𝐒 x ⋅ z)) 🝖-end
instance
[⋅]-associativity : Associativity (_⋅_)
Associativity.proof([⋅]-associativity) {x}{y}{z} = p{x}{y}{z} where
p : Names.Associativity(_⋅_)
p {𝟎} {𝟎} {𝟎} = [≡]-intro
p {𝟎} {𝟎} {𝐒 z} = [≡]-intro
p {𝟎} {𝐒 y} {𝟎} = [≡]-intro
p {𝟎} {𝐒 y} {𝐒 z} = [≡]-intro
p {𝐒 x} {𝟎} {𝟎} = [≡]-intro
p {𝐒 x} {𝟎} {𝐒 z} = [≡]-intro
p {𝐒 x} {𝐒 y} {𝟎} = [≡]-intro
p {𝐒 x} {𝐒 y} {𝐒 z} = [≡]-with(𝐒) $
(x + (𝐒 x ⋅ y)) + (𝐒(x + 𝐒 x ⋅ y) ⋅ z) 🝖[ _≡_ ]-[ associativity(_+_) {x = x}{y = 𝐒 x ⋅ y} ]
x + ((𝐒 x ⋅ y) + (𝐒(x + 𝐒 x ⋅ y) ⋅ z)) 🝖[ _≡_ ]-[]
x + ((𝐒 x ⋅ y) + ((𝐒 x + 𝐒 x ⋅ y) ⋅ z)) 🝖[ _≡_ ]-[]
x + ((𝐒 x ⋅ y) + ((𝐒 x ⋅ 𝐒 y) ⋅ z)) 🝖[ _≡_ ]-[ [≡]-with(expr ↦ x + ((𝐒 x ⋅ y) + expr)) (p{𝐒 x}{𝐒 y}{z}) ]
x + ((𝐒 x ⋅ y) + (𝐒 x ⋅ (𝐒 y ⋅ z))) 🝖[ _≡_ ]-[ [≡]-with(x +_) (distributivityₗ(_⋅_)(_+_) {x = 𝐒 x}{y = y}{z = 𝐒 y ⋅ z}) ]-sym
x + (𝐒 x ⋅ (y + (𝐒 y ⋅ z))) 🝖-end
instance
[⋅]-commutativity : Commutativity (_⋅_)
Commutativity.proof([⋅]-commutativity) {x}{y} = p {x}{y} where
p : Names.Commutativity(_⋅_)
p {𝟎} {𝟎} = [≡]-intro
p {𝟎} {𝐒 y} = [≡]-intro
p {𝐒 x} {𝟎} = [≡]-intro
p {𝐒 x} {𝐒 y} = [≡]-with(𝐒) $
x + (𝐒 x ⋅ y) 🝖-[ [≡]-with(x +_) ([⋅]-with-[𝐒]ₗ {x}{y}) ]
x + ((x ⋅ y) + y) 🝖-[ [≡]-with(x +_) (commutativity(_+_) {x ⋅ y}{y}) ]
x + (y + (x ⋅ y)) 🝖-[ One.commuteₗ-assocᵣ ⦃ comm = intro(\{x y} → commutativity(_+_) {x}{y}) ⦄ {a = x}{b = y}{c = x ⋅ y} ]
y + (x + (x ⋅ y)) 🝖-[ [≡]-with(expr ↦ y + (x + expr)) (p {x} {y}) ]
y + (x + (y ⋅ x)) 🝖-[ [≡]-with(y +_) (commutativity(_+_) {x}{y ⋅ x}) ]
y + ((y ⋅ x) + x) 🝖-[ [≡]-with(y +_) ([⋅]-with-[𝐒]ₗ {y}{x}) ]-sym
y + (𝐒 y ⋅ x) 🝖-end
[𝐏][𝐒]-inverses : ∀{n} → (𝐏(𝐒(n)) ≡ n)
[𝐏][𝐒]-inverses = [≡]-intro
[+]-sum-is-0 : ∀{a b} → (a + b ≡ 0) → (a ≡ 0)∧(b ≡ 0)
[+]-sum-is-0 {a}{b} proof = [∧]-intro (l{a}{b} proof) r where
l = \{a b} → ℕ-elim{T = \b → (a + b ≡ 0) → (a ≡ 0)} id (\_ p → p ∘ [≡]-with(𝐏)) b
r = l{b}{a} (commutativity(_+_) {b}{a} 🝖 proof)
[⋅]-product-is-1ₗ : ∀{a b} → (a ⋅ b ≡ 1) → (a ≡ 1)
[⋅]-product-is-1ₗ {𝟎} {_} p = p
[⋅]-product-is-1ₗ {𝐒 a} {𝟎} ()
[⋅]-product-is-1ₗ {𝐒 a} {𝐒 b} p = [≡]-with(𝐒) ([∧]-elimₗ ([+]-sum-is-0 (injective(𝐒) p)))
[⋅]-product-is-1ᵣ : ∀{a b} → (a ⋅ b ≡ 1) → (b ≡ 1)
[⋅]-product-is-1ᵣ {a}{b} = [⋅]-product-is-1ₗ {b}{a} ∘ (commutativity(_⋅_) {b}{a} 🝖_)
[⋅]-product-is-0 : ∀{a b} → (a ⋅ b ≡ 0) → ((a ≡ 0)∨(b ≡ 0))
[⋅]-product-is-0 {_} {0} _ = [∨]-introᵣ [≡]-intro
[⋅]-product-is-0 {0} {𝐒(_)} _ = [∨]-introₗ [≡]-intro
[⋅]-product-is-0 {𝐒(a)}{𝐒(b)} ab0 with () ← [𝐒]-not-0 {(𝐒(a) ⋅ b) + a} (commutativity(_+_) {𝐒(a) ⋅ b}{𝐒(a)} 🝖 ab0)
[⋅]-product-is-positive : ∀{a b n} → (a ⋅ b ≡ 𝐒(n)) → (∃(n₁ ↦ a ≡ 𝐒(n₁)) ∧ ∃(n₂ ↦ b ≡ 𝐒(n₂)))
[⋅]-product-is-positive {_} {0} p with () ← [𝐒]-not-0 (symmetry(_≡_) p)
[⋅]-product-is-positive {0} {𝐒(_)} p with () ← [𝐒]-not-0 (symmetry(_≡_) p)
[⋅]-product-is-positive {𝐒(a)}{𝐒(b)} p = [∧]-intro ([∃]-intro a) ([∃]-intro b)
instance
[+]-cancellationᵣ : Cancellationᵣ(_+_)
Cancellationᵣ.proof([+]-cancellationᵣ) {a}{x}{y} = ℕ-elim{T = \a → (x + a ≡ y + a) → (x ≡ y)} id (\_ → _∘ injective(𝐒)) a
instance
[+]-cancellationₗ : Cancellationₗ(_+_)
Cancellationₗ.proof([+]-cancellationₗ) {a}{x}{y} = cancellationᵣ(_+_) ∘ One.commuteBothTemp {a₁ = a}{x}{a}{y}
[^]-of-𝟎ₗ : ∀{x} → (𝟎 ^ 𝐒(x) ≡ 𝟎)
[^]-of-𝟎ₗ = [≡]-intro
[^]-of-𝟏ₗ : ∀{x} → (𝟏 ^ x ≡ 𝟏)
[^]-of-𝟏ₗ {𝟎} = [≡]-intro
[^]-of-𝟏ₗ {𝐒 x} = [^]-of-𝟏ₗ {x}
[−₀]-absorberₗ-raw : ∀{x} → ((𝟎 −₀ x) ≡ 𝟎)
[−₀]-absorberₗ-raw {n} = ℕ-elim{T = \n → ((𝟎 −₀ n) ≡ 𝟎)} [≡]-intro (\_ _ → [≡]-intro) n
{-# REWRITE [−₀]-absorberₗ-raw #-}
instance
[−₀]-absorberₗ : Absorberₗ (_−₀_) (𝟎)
Absorberₗ.proof([−₀]-absorberₗ) {x} = [−₀]-absorberₗ-raw {x}
instance
[−₀]-identityᵣ : Identityᵣ (_−₀_) (𝟎)
Identityᵣ.proof([−₀]-identityᵣ) {x} = [≡]-intro
[−₀]-self : ∀{x} → ((x −₀ x) ≡ 𝟎)
[−₀]-self {n} = ℕ-elim{T = \n → ((n −₀ n) ≡ 𝟎)} [≡]-intro (\_ p → p) n
{-# REWRITE [−₀]-self #-}
[−₀]-with-[𝐒]ᵣ : ∀{x y} → ((x −₀ 𝐒(y)) ≡ 𝐏(x −₀ y))
[−₀]-with-[𝐒]ᵣ {𝟎} {𝟎} = [≡]-intro
[−₀]-with-[𝐒]ᵣ {𝟎} {𝐒 y} = [≡]-intro
[−₀]-with-[𝐒]ᵣ {𝐒 x} {𝟎} = [≡]-intro
[−₀]-with-[𝐒]ᵣ {𝐒 x} {𝐒 y} = [−₀]-with-[𝐒]ᵣ {x} {y}
[−₀][−₀]-to-[−₀][+] : ∀{x y z} → ((x −₀ y) −₀ z ≡ x −₀ (y + z))
[−₀][−₀]-to-[−₀][+] {x}{y}{𝟎} = [≡]-intro
[−₀][−₀]-to-[−₀][+] {x}{y}{𝐒 z} =
(x −₀ y) −₀ 𝐒(z) 🝖[ _≡_ ]-[ [−₀]-with-[𝐒]ᵣ {x −₀ y}{z} ]
𝐏((x −₀ y) −₀ z) 🝖[ _≡_ ]-[ congruence₁(𝐏) ([−₀][−₀]-to-[−₀][+] {x}{y}{z}) ]
𝐏(x −₀ (y + z)) 🝖[ _≡_ ]-[ [−₀]-with-[𝐒]ᵣ {x}{y + z} ]-sym
x −₀ 𝐒(y + z) 🝖[ _≡_ ]-[]
x −₀ (y + 𝐒(z)) 🝖-end
[−₀]ₗ[+]ᵣ-nullify : ∀{x y} → ((x + y) −₀ y ≡ x)
[−₀]ₗ[+]ᵣ-nullify{𝟎} {𝟎} = [≡]-intro
[−₀]ₗ[+]ᵣ-nullify{𝟎} {𝐒(y)} = [≡]-intro
[−₀]ₗ[+]ᵣ-nullify{𝐒(x)}{𝐒(y)} = [≡]-intro 🝖 ([−₀]ₗ[+]ᵣ-nullify{𝐒(x)}{y})
[−₀]ₗ[+]ᵣ-nullify{𝐒(x)}{𝟎} = [≡]-intro
instance
[+][−₀]-inverseOperatorᵣ : InverseOperatorᵣ(_+_)(_−₀_)
InverseOperatorᵣ.proof [+][−₀]-inverseOperatorᵣ {x} {y} = [−₀]ₗ[+]ᵣ-nullify {x}{y}
[−₀]ₗ[+]ₗ-nullify : ∀{x y} → ((x + y) −₀ x ≡ y)
[−₀]ₗ[+]ₗ-nullify {x}{y} = [≡]-substitutionᵣ (commutativity(_+_) {y}{x}) {expr ↦ (expr −₀ x ≡ y)} ([−₀]ₗ[+]ᵣ-nullify {y}{x})
[−₀][+]ᵣ-nullify : ∀{x₁ x₂ y} → ((x₁ + y) −₀ (x₂ + y) ≡ x₁ −₀ x₂)
[−₀][+]ᵣ-nullify {_} {_} {𝟎} = [≡]-intro
[−₀][+]ᵣ-nullify {x₁}{x₂}{𝐒(y)} = [−₀][+]ᵣ-nullify {x₁}{x₂}{y}
[−₀][+]ₗ-nullify : ∀{x y₁ y₂} → ((x + y₁) −₀ (x + y₂) ≡ y₁ −₀ y₂)
[−₀][+]ₗ-nullify {x}{y₁}{y₂} =
[≡]-with-op(_−₀_) (commutativity(_+_) {x}{y₁}) (commutativity(_+_) {x}{y₂})
🝖 [−₀][+]ᵣ-nullify{y₁}{y₂}{x}
[−₀]-cases : ∀{x y} → ((x −₀ y) + y ≡ x) ∨ (x −₀ y ≡ 𝟎)
[−₀]-cases {𝟎} {𝟎} = [∨]-introᵣ [≡]-intro
[−₀]-cases {𝟎} {𝐒(_)} = [∨]-introᵣ [≡]-intro
[−₀]-cases {𝐒(_)}{𝟎} = [∨]-introₗ [≡]-intro
[−₀]-cases {𝐒(x)}{𝐒(y)} with [−₀]-cases {x}{y}
... | [∨]-introₗ proof = [∨]-introₗ ([≡]-with(𝐒) (proof))
... | [∨]-introᵣ proof = [∨]-introᵣ proof
[−₀]-cases-commuted : ∀{x y} → (y + (x −₀ y) ≡ x) ∨ (x −₀ y ≡ 𝟎)
[−₀]-cases-commuted {x}{y} with [−₀]-cases{x}{y}
... | [∨]-introₗ proof = [∨]-introₗ (commutativity(_+_) {y}{x −₀ y} 🝖 proof)
... | [∨]-introᵣ proof = [∨]-introᵣ proof
[𝄩]-𝐒-cases : ∀{x y} → (𝐒(x 𝄩 y) ≡ 𝐒(x) 𝄩 y) ∨ (𝐒(x 𝄩 y) ≡ x 𝄩 𝐒(y))
[𝄩]-𝐒-cases {𝟎} {𝟎} = [∨]-introₗ [≡]-intro
[𝄩]-𝐒-cases {𝟎} {𝐒 y} = [∨]-introᵣ [≡]-intro
[𝄩]-𝐒-cases {𝐒 x} {𝟎} = [∨]-introₗ [≡]-intro
[𝄩]-𝐒-cases {𝐒 x} {𝐒 y} = [𝄩]-𝐒-cases {x}{y}
[𝄩]-identityₗ-raw : Names.Identityₗ(_𝄩_)(0)
[𝄩]-identityₗ-raw {𝟎} = [≡]-intro
[𝄩]-identityₗ-raw {𝐒(_)} = [≡]-intro
{-# REWRITE [𝄩]-identityₗ-raw #-}
instance
[𝄩]-identityₗ : Identityₗ(_𝄩_)(𝟎)
Identityₗ.proof([𝄩]-identityₗ) {x} = [𝄩]-identityₗ-raw {x}
[𝄩]-identityᵣ-raw : Names.Identityᵣ (_𝄩_) (0)
[𝄩]-identityᵣ-raw {𝟎} = [≡]-intro
[𝄩]-identityᵣ-raw {𝐒(_)} = [≡]-intro
{-# REWRITE [𝄩]-identityᵣ-raw #-}
instance
[𝄩]-identityᵣ : Identityᵣ(_𝄩_)(𝟎)
Identityᵣ.proof([𝄩]-identityᵣ) {x} = [𝄩]-identityᵣ-raw {x}
instance
[𝄩]-identity : Identity(_𝄩_)(𝟎)
[𝄩]-identity = intro
[𝄩]-self : ∀{x} → (x 𝄩 x ≡ 𝟎)
[𝄩]-self {𝟎} = [≡]-intro
[𝄩]-self {𝐒(x)} = [𝄩]-self {x}
{-# REWRITE [𝄩]-self #-}
instance
[𝄩]-inverseFunctionₗ : InverseFunctionₗ(_𝄩_) ⦃ [∃]-intro 𝟎 ⦄ (id)
[𝄩]-inverseFunctionₗ = intro \{x} → [𝄩]-self {x}
instance
[𝄩]-inverseFunctionᵣ : InverseFunctionᵣ(_𝄩_) ⦃ [∃]-intro 𝟎 ⦄ (id)
[𝄩]-inverseFunctionᵣ = intro \{x} → [𝄩]-self {x}
instance
[𝄩]-commutativity : Commutativity(_𝄩_)
Commutativity.proof([𝄩]-commutativity) {x}{y} = p{x}{y} where
p : Names.Commutativity (_𝄩_)
p{𝟎} {𝟎} = [≡]-intro
p{𝟎} {𝐒(y)} = [≡]-intro
p{𝐒(x)}{𝟎} = [≡]-intro
p{𝐒(x)}{𝐒(y)} = p{x}{y}
instance
[+][𝄩]-inverseOperatorᵣ : InverseOperatorᵣ(_+_)(_𝄩_)
InverseOperatorᵣ.proof [+][𝄩]-inverseOperatorᵣ {x}{y} = p{x}{y} where
p : ∀{x y} → ((x + y) 𝄩 y ≡ x)
p{𝟎} {𝟎} = [≡]-intro
p{𝟎} {𝐒(y)} = [≡]-intro
p{𝐒(x)}{𝐒(y)} = [≡]-intro 🝖 (p{𝐒(x)}{y})
p{𝐒(x)}{𝟎} = [≡]-intro
instance
[swap+][𝄩]-inverseOperatorᵣ : InverseOperatorᵣ(swap(_+_))(_𝄩_)
InverseOperatorᵣ.proof [swap+][𝄩]-inverseOperatorᵣ {x}{y} = congruence₂ₗ(_𝄩_)(y) (commutativity(_+_) {y}{x}) 🝖 inverseOperᵣ(_+_)(_𝄩_) {x}{y}
instance
[swap+][𝄩]-inverseOperatorₗ : InverseOperatorₗ(swap(_+_))(_𝄩_)
InverseOperatorₗ.proof [swap+][𝄩]-inverseOperatorₗ {x}{y} = commutativity(_𝄩_) {x}{y + x} 🝖 inverseOperᵣ(_+_)(_𝄩_) {y}{x}
instance
[+][𝄩]-inverseOperatorₗ : InverseOperatorₗ(_+_)(_𝄩_)
InverseOperatorₗ.proof [+][𝄩]-inverseOperatorₗ {x}{y} = commutativity(_𝄩_) {x}{x + y} 🝖 inverseOperᵣ(swap(_+_))(_𝄩_) {y}{x}
[𝄩]-with-[+]ᵣ : ∀{x y z} → ((x + z) 𝄩 (y + z) ≡ x 𝄩 y)
[𝄩]-with-[+]ᵣ {𝟎} {𝟎} {𝟎} = [≡]-intro
[𝄩]-with-[+]ᵣ {𝟎} {𝐒(y)}{𝟎} = [≡]-intro
[𝄩]-with-[+]ᵣ {𝟎} {𝟎} {𝐒(z)} = [≡]-intro
[𝄩]-with-[+]ᵣ {𝟎} {𝐒(y)}{𝐒(z)} = inverseOperₗ(swap(_+_))(_𝄩_) {z}{_}
[𝄩]-with-[+]ᵣ {𝐒(x)}{𝟎} {𝟎} = [≡]-intro
[𝄩]-with-[+]ᵣ {𝐒(x)}{𝐒(y)}{𝟎} = [≡]-intro
[𝄩]-with-[+]ᵣ {𝐒(x)}{𝟎} {𝐒(z)} = inverseOperᵣ(_+_)(_𝄩_) {𝐒(x)}{z}
[𝄩]-with-[+]ᵣ {𝐒(x)}{𝐒(y)}{𝐒(z)} = [𝄩]-with-[+]ᵣ {𝐒(x)}{𝐒(y)}{z}
[𝄩]-with-[+]ₗ : ∀{x y z} → ((z + x) 𝄩 (z + y) ≡ x 𝄩 y)
[𝄩]-with-[+]ₗ {𝟎} {𝟎} {𝟎} = [≡]-intro
[𝄩]-with-[+]ₗ {𝟎} {𝐒(y)}{𝟎} = [≡]-intro
[𝄩]-with-[+]ₗ {𝟎} {𝟎} {𝐒(z)} = [≡]-intro
[𝄩]-with-[+]ₗ {𝟎} {𝐒(y)}{𝐒(z)} = inverseOperₗ(_+_)(_𝄩_) {z}{𝐒(y)}
[𝄩]-with-[+]ₗ {𝐒(x)}{𝟎} {𝟎} = [≡]-intro
[𝄩]-with-[+]ₗ {𝐒(x)}{𝐒(y)}{𝟎} = [≡]-intro
[𝄩]-with-[+]ₗ {𝐒(x)}{𝟎} {𝐒(z)} = inverseOperᵣ(swap(_+_))(_𝄩_) {𝐒(x)}{z}
[𝄩]-with-[+]ₗ {𝐒(x)}{𝐒(y)}{𝐒(z)} = [𝄩]-with-[+]ₗ {𝐒(x)}{𝐒(y)}{z}
[𝄩]-equality : ∀{x y} → (x 𝄩 y ≡ 𝟎) → (x ≡ y)
[𝄩]-equality {𝟎} {𝟎} [≡]-intro = [≡]-intro
[𝄩]-equality {𝟎} {𝐒(y)} ()
[𝄩]-equality {𝐒(x)}{𝟎} ()
[𝄩]-equality {𝐒(x)}{𝐒(y)} proof = [≡]-with(𝐒) ([𝄩]-equality {x}{y} proof)
instance
[⋅][𝄩]-distributivityᵣ : Distributivityᵣ(_⋅_)(_𝄩_)
Distributivityᵣ.proof [⋅][𝄩]-distributivityᵣ {x}{y}{z} = p{x}{y}{z} where
p : Names.Distributivityᵣ(_⋅_)(_𝄩_)
p {𝟎} {𝟎} {z} = [≡]-intro
p {𝟎} {𝐒 y} {z} = [≡]-intro
p {𝐒 x} {𝟎} {z} = [≡]-intro
p {𝐒 x} {𝐒 y} {z} =
(𝐒(x) 𝄩 𝐒(y)) ⋅ z 🝖[ _≡_ ]-[]
(x 𝄩 y) ⋅ z 🝖[ _≡_ ]-[ p{x}{y}{z} ]
(x ⋅ z) 𝄩 (y ⋅ z) 🝖[ _≡_ ]-[ [𝄩]-with-[+]ᵣ {x ⋅ z}{y ⋅ z}{z} ]-sym
((x ⋅ z) + z) 𝄩 ((y ⋅ z) + z) 🝖[ _≡_ ]-[ congruence₂(_𝄩_) ([⋅]-with-[𝐒]ₗ {x}{z}) ([⋅]-with-[𝐒]ₗ {y}{z}) ]-sym
(𝐒(x) ⋅ z) 𝄩 (𝐒(y) ⋅ z) 🝖-end
instance
[⋅][𝄩]-distributivityₗ : Distributivityₗ(_⋅_)(_𝄩_)
Distributivityₗ.proof [⋅][𝄩]-distributivityₗ {x}{y}{z} =
x ⋅ (y 𝄩 z) 🝖[ _≡_ ]-[ commutativity(_⋅_) {x}{y 𝄩 z} ]
(y 𝄩 z) ⋅ x 🝖[ _≡_ ]-[ distributivityᵣ(_⋅_)(_𝄩_) {y}{z}{x} ]
(y ⋅ x) 𝄩 (z ⋅ x) 🝖[ _≡_ ]-[ congruence₂(_𝄩_) (commutativity(_⋅_) {y}{x}) (commutativity(_⋅_) {z}{x}) ]
(x ⋅ y) 𝄩 (x ⋅ z) 🝖-end
| {
"alphanum_fraction": 0.473231228,
"avg_line_length": 40.4273972603,
"ext": "agda",
"hexsha": "118ae9240b278078f3c9d52327002aca08e96c0a",
"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/Oper/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Oper/Proofs.agda",
"max_line_length": 176,
"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/Oper/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 8712,
"size": 14756
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- The basic code for equational reasoning with a single relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Reasoning.Base.Single
{a ℓ} {A : Set a} (_∼_ : Rel A ℓ)
(refl : Reflexive _∼_) (trans : Transitive _∼_)
where
open import Level using (_⊔_)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
infix 4 _IsRelatedTo_
infix 3 _∎
infixr 2 _∼⟨_⟩_ _≡⟨_⟩_ _≡˘⟨_⟩_ _≡⟨⟩_
infix 1 begin_
-- This seemingly unnecessary type is used to make it possible to
-- infer arguments even if the underlying equality evaluates.
data _IsRelatedTo_ (x y : A) : Set (a ⊔ ℓ) where
relTo : (x∼y : x ∼ y) → x IsRelatedTo y
begin_ : ∀ {x y} → x IsRelatedTo y → x ∼ y
begin relTo x∼y = x∼y
_∼⟨_⟩_ : ∀ x {y z} → x ∼ y → y IsRelatedTo z → x IsRelatedTo z
_ ∼⟨ x∼y ⟩ relTo y∼z = relTo (trans x∼y y∼z)
_≡⟨_⟩_ : ∀ x {y z} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z
_ ≡⟨ P.refl ⟩ x∼z = x∼z
_≡˘⟨_⟩_ : ∀ x {y z} → y ≡ x → y IsRelatedTo z → x IsRelatedTo z
_ ≡˘⟨ P.refl ⟩ x∼z = x∼z
_≡⟨⟩_ : ∀ x {y} → x IsRelatedTo y → x IsRelatedTo y
_ ≡⟨⟩ x∼y = _ ≡⟨ P.refl ⟩ x∼y
_∎ : ∀ x → x IsRelatedTo x
_∎ _ = relTo refl
| {
"alphanum_fraction": 0.5563853622,
"avg_line_length": 28.4893617021,
"ext": "agda",
"hexsha": "6b38b3fd865dc721595e01cd7bc8490a150efa30",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Reasoning/Base/Single.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Reasoning/Base/Single.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Reasoning/Base/Single.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 530,
"size": 1339
} |
module PatternSynonymUnderapplied where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
pattern suc' x = suc x
f : Nat -> Nat
f zero = zero
f suc' = zero | {
"alphanum_fraction": 0.6604938272,
"avg_line_length": 14.7272727273,
"ext": "agda",
"hexsha": "9f763e2d2bde5a7d58a68253374968720162d8ea",
"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/fail/PatternSynonymUnderapplied.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/PatternSynonymUnderapplied.agda",
"max_line_length": 39,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/PatternSynonymUnderapplied.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": 52,
"size": 162
} |
{-# OPTIONS --rewriting #-}
-- Normalization by Evaluation for Graded Call-By-Push-Value.
module GradedCBPV where
-- Imports from the Agda standard library.
open import Library hiding (_×̇_)
pattern here! = here refl
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
open import ProMonoid as _
-- We postulate an effect algebra, a pre-ordered monoid
postulate
effAlg : ProMonoid lzero lzero lzero
open ProMonoid effAlg public
renaming
( Carrier to Eff
; _∙_ to infixl 6 _+_
; ε to ∅
; _≼_ to _≤_
; _≈_ to _=E_
)
-- postulate
-- +-unitˡ : ∅ + e ≡ e
-- +-unitʳ : e + ∅ ≡ e
-- +-assoc : (e₁ + e₂) + e₃ ≡ e₁ + (e₂ + e₃)
-- +-supʳ : sup es + e ≡ sup λ i → es i + e
-- sup-k : sup {I = I} (λ _ → e) ≡ e
-- {-# REWRITE +-unitˡ +-unitʳ +-assoc +-supʳ sup-k #-}
-- We postulate a set of generic value types.
-- There are no operations defined on these types, thus,
-- they play the type of (universal) type variables.
postulate
Base : Set
variable
o : Base
-- Variants (Σ) (and records (Π), resp.) can in principle have any number of
-- constructors (fields, resp.), including infinitely one.
-- In general, the constructor (field, resp.) names are given by a set I.
-- However, I : Set would make syntax already a big type, living in Set₁.
-- To keep it in Set₀, we only consider variants (records) with finitely
-- many constructors (fields), thus, I : ℕ.
-- Branching over I is then realized as functions out of El I, where
-- El I = { i | i < I} = Fin I.
set = ℕ
El = Fin
-- Let I range over arities (constructor/field sets) and i over
-- constructor/field names.
variable
I : set
i : El I
variable
e e' e₁ e₂ e₃ : Eff
es : El I → Eff
-- The types of CBPV are classified into value types P : Ty⁺ which we
-- refer to as positive types, and computation types N : Ty⁻ which we
-- refer to as negative types.
mutual
-- Value types
data Ty⁺ : Set where
base : (o : Base) → Ty⁺ -- Base type.
_×̇_ : (P₁ P₂ : Ty⁺) → Ty⁺ -- Finite product (tensor).
Σ̇ : (I : set) (Ps : El I → Ty⁺) → Ty⁺ -- Variant (sum).
[_] : (e : Eff) (N : Ty⁻) → Ty⁺ -- Thunk (U).
-- Remembers effects.
-- Computation types
data Ty⁻ : Set where
◇̇ : (P : Ty⁺) → Ty⁻ -- Comp (F).
Π̇ : (I : set) (Ns : El I → Ty⁻) → Ty⁻ -- Record (lazy product).
_⇒̇_ : (P : Ty⁺) (N : Ty⁻) → Ty⁻ -- Function type.
-- In CBPV, a variable stands for a value.
-- Thus, environments only contain values,
-- and typing contexts only value types.
-- We use introduce syntax in an intrinsically well-typed way
-- with variables being de Bruijn indices into the typing context.
-- Thus, contexts are just lists of types.
Cxt = List Ty⁺
variable
Γ Δ Φ : Cxt
J : Cxt → Set
P P₁ P₂ P' P′ Q : Ty⁺
N N₁ N₂ N' N′ : Ty⁻
Ps : El I → Ty⁺
Ns : El I → Ty⁻
-- Generic values
module _ (Var : Ty⁺ → Cxt → Set) (Comp : Eff → Ty⁻ → Cxt → Set) where
-- Right non-invertible
data Val' : (P : Ty⁺) (Γ : Cxt) → Set where
var : (x : Var P Γ) → Val' P Γ
pair : (v₁ : Val' P₁ Γ) (v₂ : Val' P₂ Γ) → Val' (P₁ ×̇ P₂) Γ
inj : (i : _) (v : Val' (Ps i) Γ) → Val' (Σ̇ I Ps) Γ
thunk : (t : Comp e N Γ) → Val' ([ e ] N) Γ
-- Terms
mutual
Val = Val' _∈_ Comp
data Comp (e : Eff) : (N : Ty⁻) (Γ : Cxt) → Set where
-- introductions
ret : (∅≤ : ∅ ≤ e)
(v : Val P Γ) → Comp e (◇̇ P) Γ
rec : (t : ∀ i → Comp e (Ns i) Γ) → Comp e (Π̇ I Ns) Γ
abs : (t : Comp e N (P ∷ Γ)) → Comp e (P ⇒̇ N) Γ
-- positive eliminations
split : (v : Val (P₁ ×̇ P₂) Γ) (t : Comp e N (P₂ ∷ P₁ ∷ Γ)) → Comp e N Γ
case : (v : Val (Σ̇ I Ps) Γ) (t : ∀ i → Comp e N (Ps i ∷ Γ)) → Comp e N Γ
bind : (+≤ : e₁ + e₂ ≤ e)
(u : Comp e₁ (◇̇ P) Γ) (t : Comp e₂ N (P ∷ Γ)) → Comp e N Γ
-- cut
letv : (v : Val P Γ) (t : Comp e N (P ∷ Γ)) → Comp e N Γ
-- negative eliminations
force : (v : Val ([ e ] N) Γ) → Comp e N Γ
prj : (i : _) (t : Comp e (Π̇ I Ns) Γ) → Comp e (Ns i) Γ
app : (t : Comp e (P ⇒̇ N) Γ) (v : Val P Γ) → Comp e N Γ
-- Normal forms
------------------------------------------------------------------------
-- Normal values only reference variables of base type
NVar : (P : Ty⁺) (Γ : Cxt) → Set
NVar (base o) Γ = base o ∈ Γ
NVar _ _ = ⊥
-- Negative neutrals
module _ (Val : Ty⁺ → Cxt → Set) where
-- Right non-invertible
-- Propagates the effect from the head variable, a thunk.
data Ne' (e : Eff) : (N : Ty⁻) (Γ : Cxt) → Set where
force : (x : [ e ] N ∈ Γ) → Ne' e N Γ
prj : (i : El I) (t : Ne' e (Π̇ I Ns) Γ) → Ne' e (Ns i) Γ
app : (t : Ne' e (P ⇒̇ N) Γ) (v : Val P Γ) → Ne' e N Γ
mutual
NVal = Val' NVar Nf
Ne = Ne' NVal
-- Cover monad (generalized case tree).
-- Collects effects from all bind nodes.
data ⟨_⟩ (e : Eff) (J : Cxt → Set) (Γ : Cxt) : Set where
return : (∅≤ : ∅ ≤ e) (j : J Γ) → ⟨ e ⟩ J Γ
bind : (+≤ : e₁ + e₂ ≤ e)
(u : Ne e₁ (◇̇ P) Γ) (t : ⟨ e₂ ⟩ J (P ∷ Γ)) → ⟨ e ⟩ J Γ
case : (x : Σ̇ I Ps ∈ Γ) (t : ∀ i → ⟨ e ⟩ J (Ps i ∷ Γ)) → ⟨ e ⟩ J Γ
split : (x : (P₁ ×̇ P₂) ∈ Γ) (t : ⟨ e ⟩ J (P₂ ∷ P₁ ∷ Γ)) → ⟨ e ⟩ J Γ
◇ : ∀ J e Γ → Set
◇ J e = ⟨ e ⟩ J
-- syntax ◇ J e = ⟨ e ⟩ J
-- Right invertible.
data Nf (e : Eff) : (N : Ty⁻) (Γ : Cxt) → Set where
-- ne only needed for negative base types
-- ne : let N = ◇̇ (base o) in (n : ⟨ e ⟩ (Ne e N) Γ) → Nf e N Γ
-- ne : let N = ◇̇ (base o) in
-- (+≤ : e₁ + e₂ ≤ e) (n : ⟨ e₂ ⟩ (Ne e₁ N) Γ) → Nf e N Γ
ret : (v : ⟨ e ⟩ (NVal P) Γ) → Nf e (◇̇ P) Γ -- Invoke RFoc
rec : (ts : ∀ i → Nf e (Ns i) Γ) → Nf e (Π̇ I Ns) Γ
abs : (t : Nf e N (P ∷ Γ)) → Nf e (P ⇒̇ N) Γ
-- Context-indexed sets
------------------------------------------------------------------------
PSet = (Γ : Cxt) → Set
NSet = (e : Eff) (Γ : Cxt) → Set
variable
C A A' A₁ A₂ : PSet
B B' B₁ B₂ : NSet
F G As : (i : El I) → PSet
Bs Bs' Bs₁ Bs₂ : (i : El I) → NSet
-- Constructions on PSet
1̂ : PSet
1̂ Γ = ⊤
_×̂_ : (A₁ A₂ : PSet) → PSet
(A₁ ×̂ A₂) Γ = A₁ Γ × A₂ Γ
Σ̂ : (I : set) (As : El I → PSet) → PSet
(Σ̂ I F) Γ = ∃ λ i → F i Γ
_⇒̂_ : (A₁ A₂ : PSet) → PSet
(A₁ ⇒̂ A₂) Γ = A₁ Γ → A₂ Γ
Π̂ : (I : set) (As : El I → PSet) → PSet
(Π̂ I As) Γ = ∀ i → As i Γ
⟪_⟫ : (P : Ty⁺) (A : PSet) → PSet
⟪ P ⟫ A Γ = A (P ∷ Γ)
-- Constructions on NSet
_⇒ⁿ_ : (A : PSet) (B : NSet) → NSet
(A ⇒ⁿ B) e Γ = A Γ → B e Γ
Πⁿ : (I : set) (Bs : El I → NSet) → NSet
(Πⁿ I Bs) e Γ = ∀ i → Bs i e Γ
-- Morphisms between ISets
_→̇_ : (A₁ A₂ : PSet) → Set
A₁ →̇ A₂ = ∀{Γ} → A₁ Γ → A₂ Γ
_→̈_ : (B₁ B₂ : NSet) → Set
B₁ →̈ B₂ = ∀{e Γ} → B₁ e Γ → B₂ e Γ
⟨_⊙_⟩→̇_ : (P Q R : PSet) → Set
⟨ P ⊙ Q ⟩→̇ R = ∀{Γ} → P Γ → Q Γ → R Γ
⟨_⊙_⊙_⟩→̇_ : (P Q R S : PSet) → Set
⟨ P ⊙ Q ⊙ R ⟩→̇ S = ∀{Γ} → P Γ → Q Γ → R Γ → S Γ
Map : (F : (PSet) → PSet) → Set₁
Map F = ∀{A B : PSet} (f : A →̇ B) → F A →̇ F B
Π-map : (∀ i {e} → Bs i e →̇ Bs' i e) → ∀{e} → Πⁿ I Bs e →̇ Πⁿ I Bs' e
Π-map f r i = f i (r i)
-- -- Introductions and eliminations for ×̂
-- p̂air : ⟨ A ⊙ B ⟩→̇ (A ×̂ B)
-- p̂air a b = λ
-- Monotonicity
------------------------------------------------------------------------
-- Monotonization □ is a monoidal comonad
□ : (A : PSet) → PSet
□ A Γ = ∀{Δ} (τ : Γ ⊆ Δ) → A Δ
extract : □ A →̇ A
extract a = a ⊆-refl
duplicate : □ A →̇ □ (□ A)
duplicate a τ τ′ = a (⊆-trans τ τ′)
□-map : Map □
□-map f a τ = f (a τ)
extend : (□ A →̇ C) → □ A →̇ □ C
extend f = □-map f ∘ duplicate
□-weak : □ A →̇ ⟪ P ⟫ (□ A)
□-weak a τ = a (⊆-trans (_ ∷ʳ ⊆-refl) τ)
□-weak' : □ A →̇ □ (⟪ P ⟫ A)
□-weak' a τ = a (_ ∷ʳ τ)
□-sum : Σ̂ I (□ ∘ F) →̇ □ (Σ̂ I F)
□-sum (i , a) τ = i , a τ
-- Monoidality:
□-unit : 1̂ →̇ □ 1̂
□-unit = _
□-pair : ⟨ □ A₁ ⊙ □ A₂ ⟩→̇ □ (A₁ ×̂ A₂)
□-pair a b τ = (a τ , b τ)
-- -- Strong functoriality
Map! : (F : PSet → PSet) → Set₁
Map! F = ∀{A C} → ⟨ □ (λ Γ → A Γ → C Γ) ⊙ F A ⟩→̇ F C
-- Monotonicity
Mon : (A : PSet) → Set
Mon A = A →̇ □ A
monVar : Mon (P ∈_)
monVar x τ = ⊆-lookup τ x
-- Positive ISets are monotone
□-mon : Mon (□ A)
□-mon = duplicate
1-mon : Mon 1̂
1-mon = □-unit
×-mon : Mon A₁ → Mon A₂ → Mon (A₁ ×̂ A₂)
×-mon mA mB (a , b) = □-pair (mA a) (mB b)
Σ-mon : ((i : El I) → Mon (F i)) → Mon (Σ̂ I F)
Σ-mon m (i , a) = □-sum (i , m i a)
□-intro : Mon A → (A →̇ C) → (A →̇ □ C)
□-intro mA f = □-map f ∘ mA
-- Cover monad: a strong graded monad
------------------------------------------------------------------------
join : ⟨ e₁ ⟩ (⟨ e₂ ⟩ A) →̇ ⟨ e₁ + e₂ ⟩ A
join (return ∅≤e c) = {!c !}
join (bind ≤e u c) = {!bind u (join c) !}
join (case x t) = case x (join ∘ t)
join (split x c) = split x (join c)
{-
◇-map : Map ⟨ e ⟩
◇-map f (return j) = return (f j)
◇-map f (bind u a) = bind u (◇-map f a)
◇-map f (case x t) = case x (λ i → ◇-map f (t i))
◇-map f (split x a) = split x (◇-map f a)
◇-map! : Map! ⟨ e ⟩
◇-map! f (return j) = return (extract f j)
◇-map! f (bind u a) = bind u (◇-map! (□-weak f) a)
◇-map! f (case x t) = case x (λ i → ◇-map! (□-weak f) (t i))
◇-map! f (split x a) = split x (◇-map! (□-weak (□-weak f)) a)
◇-bind : A →̇ ⟨ e₂ ⟩ C → ⟨ e₁ ⟩ A →̇ ⟨ e₁ + e₂ ⟩ C
◇-bind f = join ∘ ◇-map f
◇-record : (⟨ e ⟩ ∘ Πⁿ I Bs) →̈ Πⁿ I (λ i → ⟨ e ⟩ ∘ Bs i)
◇-record c i = ◇-map (_$ i) c
◇-fun : Mon A → (⟨ e ⟩ ∘ A ⇒ⁿ B) →̈ (A ⇒ⁿ (⟨ e ⟩ ∘ B))
◇-fun mA c a = ◇-map! (λ τ f → f (mA a τ)) c
-- Monoidal functoriality
◇-pair : ⟨ □ (⟨ e₁ ⟩ A₁) ⊙ ⟨ e₂ ⟩ (□ A₂) ⟩→̇ ⟨ e₂ + e₁ ⟩ (A₁ ×̂ A₂)
◇-pair ca = join ∘ ◇-map! λ τ b → ◇-map! (λ τ′ a → a , b τ′) (ca τ)
_⋉_ = ◇-pair
□◇-pair' : ⟨ □ (⟨ e₁ ⟩ A₁) ⊙ □ (⟨ e₂ ⟩ (□ A₂)) ⟩→̇ □ (⟨ e₂ + e₁ ⟩ (A₁ ×̂ A₂))
□◇-pair' ca cb τ = ◇-pair (□-mon ca τ) (cb τ)
□◇-pair : Mon A₂ → ⟨ □ (⟨ e₁ ⟩ A₁) ⊙ □ (⟨ e₂ ⟩ A₂) ⟩→̇ □ (⟨ e₂ + e₁ ⟩ (A₁ ×̂ A₂))
□◇-pair mB ca cb τ = join $
◇-map! (λ τ₁ b → ◇-map! (λ τ₂ a → a , mB b τ₂) (ca (⊆-trans τ τ₁))) (cb τ)
◇□-pair' : ⟨ ⟨ e₁ ⟩ (□ A₁) ⊙ □ (⟨ e₂ ⟩ (□ A₂)) ⟩→̇ ⟨ e₁ + e₂ ⟩ (□ (A₁ ×̂ A₂))
◇□-pair' ca cb = join (◇-map! (λ τ a → ◇-map! (λ τ₁ b {_} τ₂ → a (⊆-trans τ₁ τ₂) , b τ₂) (cb τ)) ca)
-- Without the abstraction over {_}, there is an incomprehensible error.
◇□-pair : ⟨ □ (⟨ e₁ ⟩ (□ A₁)) ⊙ ⟨ e₂ ⟩ (□ A₂) ⟩→̇ ⟨ e₂ + e₁ ⟩ (□ (A₁ ×̂ A₂))
◇□-pair ca cb = join (◇-map! (λ τ b → ◇-map! (λ τ₁ a {_} τ₂ → a τ₂ , b (⊆-trans τ₁ τ₂)) (ca τ)) cb)
-- Without the abstraction over {_}, there is an incomprehensible error.
-- Runnability
Run : (B : NSet) → Set
Run B = ∀{e₁ e₂} → ⟨ e₁ ⟩ (B e₂) →̇ B (e₁ + e₂)
-- Negative ISets are runnable
◇-run : Run (◇ A)
◇-run = join
Π-run : (∀ i → Run (Bs i)) → Run (Πⁿ I Bs)
Π-run f c i = f i (◇-map (_$ i) c)
-- Π-run f x i = Π-map {!λ j → f j!} {!!} {!!}
-- Π-run f = {!Π-map f!} ∘ ◇-record
⇒-run : Mon A → Run B → Run (A ⇒ⁿ B)
⇒-run {B = B} mA rB f = rB ∘ ◇-fun {B = B} mA f
-- Bind for the ◇ monad
◇-elim : Run B → (A →̇ B e₂) → ⟨ e₁ ⟩ A →̇ B (e₁ + e₂)
◇-elim rB f = rB ∘ ◇-map f
◇-elim! : Run B → ⟨ □ (A ⇒̂ B e₂) ⊙ ⟨ e₁ ⟩ A ⟩→̇ B (e₁ + e₂)
◇-elim! rB f = rB ∘ ◇-map! f
◇-elim-□ : Run B → ⟨ □ (A ⇒̂ B e₂) ⊙ □ (⟨ e₁ ⟩ A) ⟩→̇ □ (B (e₁ + e₂))
◇-elim-□ {B = B} rB f c = □-map (uncurry (◇-elim! {B = B} rB)) (□-pair (□-mon f) c)
◇-elim-□-alt : Run B → ⟨ □ (A ⇒̂ B e₂) ⊙ □ (⟨ e₁ ⟩ A) ⟩→̇ □ (B (e₁ + e₂))
◇-elim-□-alt {B = B} rB f c τ = ◇-elim! {B = B} rB (□-mon f τ) (c τ)
bind! : Mon C → Run B → (C →̇ ⟨ e₁ ⟩ A) → (C →̇ (A ⇒̂ B e₂)) → C →̇ B (e₁ + e₂)
bind! {B = B} mC rB f k γ = ◇-elim! {B = B} rB (λ τ a → k (mC γ τ) a) (f γ)
-- Type interpretation
------------------------------------------------------------------------
mutual
⟦_⟧⁺ : Ty⁺ → PSet
⟦ base o ⟧⁺ = base o ∈_
⟦ P₁ ×̇ P₂ ⟧⁺ = ⟦ P₁ ⟧⁺ ×̂ ⟦ P₂ ⟧⁺
⟦ Σ̇ I P ⟧⁺ = Σ̂ I λ i → ⟦ P i ⟧⁺
⟦ [ e ] N ⟧⁺ = □ (⟦ N ⟧⁻ e)
⟦_⟧⁻ : Ty⁻ → NSet
⟦ ◇̇ P ⟧⁻ = ◇ ⟦ P ⟧⁺
⟦ Π̇ I N ⟧⁻ = Πⁿ I λ i → ⟦ N i ⟧⁻
⟦ P ⇒̇ N ⟧⁻ = ⟦ P ⟧⁺ ⇒ⁿ ⟦ N ⟧⁻
⟦_⟧ᶜ : Cxt → PSet
⟦_⟧ᶜ Γ Δ = All (λ P → ⟦ P ⟧⁺ Δ) Γ
-- ⟦ [] ⟧ᶜ = 1̂
-- ⟦ P ∷ Γ ⟧ᶜ = ⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺
-- Positive types are monotone.
mon⁺ : (P : Ty⁺) → Mon ⟦ P ⟧⁺
mon⁺ (base o) = monVar
mon⁺ (P₁ ×̇ P₂) = ×-mon (mon⁺ P₁) (mon⁺ P₂)
mon⁺ (Σ̇ I P) = Σ-mon (mon⁺ ∘ P)
mon⁺ ([ e ] N) = □-mon
monᶜ : (Γ : Cxt) → Mon ⟦ Γ ⟧ᶜ
monᶜ Γ γ τ = All.map (λ {P} v → mon⁺ P v τ) γ
-- Negative types are runnable.
run⁻ : (N : Ty⁻) → Run ⟦ N ⟧⁻
run⁻ (◇̇ P) = ◇-run
run⁻ (Π̇ I N) = Π-run (run⁻ ∘ N)
run⁻ (P ⇒̇ N) = ⇒-run {B = ⟦ N ⟧⁻} (mon⁺ P) (run⁻ N)
-- monᶜ [] = 1-mon
-- monᶜ (P ∷ Γ) = ×-mon (monᶜ Γ) (mon⁺ P)
-- Interpretation
------------------------------------------------------------------------
mutual
⦅_⦆⁺ : Val P Γ → ⟦ Γ ⟧ᶜ →̇ ⟦ P ⟧⁺
⦅ var x ⦆⁺ = λ γ → All.lookup γ x
⦅ pair v₁ v₂ ⦆⁺ = < ⦅ v₁ ⦆⁺ , ⦅ v₂ ⦆⁺ >
⦅ inj i v ⦆⁺ = (i ,_) ∘ ⦅ v ⦆⁺
⦅ thunk t ⦆⁺ = □-intro (monᶜ _) ⦅ t ⦆⁻
λ⦅_⦆⁻ : Comp e N (P ∷ Γ) → ⟦ Γ ⟧ᶜ →̇ ⟦ P ⇒̇ N ⟧⁻ e
λ⦅ t ⦆⁻ γ a = ⦅ t ⦆⁻ (a ∷ γ)
⦅_⦆⁻ : Comp e N Γ → ⟦ Γ ⟧ᶜ →̇ ⟦ N ⟧⁻ e
⦅ ret v ⦆⁻ = return ∘ ⦅ v ⦆⁺
⦅ rec t ⦆⁻ = flip λ i → {! ⦅ t i ⦆⁻ !} -- need effect subsumption es i ≤ sup es
⦅ abs t ⦆⁻ = λ⦅ t ⦆⁻
⦅ split v t ⦆⁻ γ = let (a₁ , a₂) = ⦅ v ⦆⁺ γ in ⦅ t ⦆⁻ (a₂ ∷ (a₁ ∷ γ))
⦅ case v t ⦆⁻ γ = let (i , a) = ⦅ v ⦆⁺ γ in {! ⦅ t i ⦆⁻ (a ∷ γ) !} -- eff sub
⦅ bind {Γ = Γ} {N = N} t t₁ ⦆⁻ = bind! {B = ⟦ N ⟧⁻} (monᶜ Γ) (run⁻ N) ⦅ t ⦆⁻ λ⦅ t₁ ⦆⁻
⦅ force v ⦆⁻ = extract ∘ ⦅ v ⦆⁺
⦅ prj i t ⦆⁻ = (_$ i) ∘ ⦅ t ⦆⁻
⦅ app t v ⦆⁻ = ⦅ t ⦆⁻ ˢ ⦅ v ⦆⁺
⦅ letv v t ⦆⁻ = λ⦅ t ⦆⁻ ˢ ⦅ v ⦆⁺
-- Reflection and reification
mutual
fresh□◇□ : ∀ P {Γ} → ⟪ P ⟫ (□ (⟨ ∅ ⟩ (□ ⟦ P ⟧⁺))) Γ
fresh□◇□ P = reflect⁺□ P ∘ monVar here!
fresh□ : ∀ P {Γ} → ⟪ P ⟫ (□ (⟨ ∅ ⟩ ⟦ P ⟧⁺)) Γ
fresh□ P = ◇-map extract ∘ reflect⁺□ P ∘ monVar here!
fresh□ P = reflect⁺ P ∘ monVar here!
fresh : ∀ {P Γ} → ⟪ P ⟫ (⟨ ∅ ⟩ ⟦ P ⟧⁺) Γ
fresh {P} = ◇-map extract (reflect⁺□ P here!)
fresh {P} = reflect⁺ P here!
fresh◇ : ∀ {P Γ} → ⟪ P ⟫ (⟨ ∅ ⟩ (□ ⟦ P ⟧⁺)) Γ
fresh◇ {P} = reflect⁺□ P here!
fresh◇ {P} = ◇-map (mon⁺ P) fresh
-- saves us use of Mon P in freshᶜ
reflect⁺□ : (P : Ty⁺) → (P ∈_) →̇ (⟨ ∅ ⟩ (□ ⟦ P ⟧⁺))
reflect⁺□ (base o) x = return (monVar x)
reflect⁺□ (P₁ ×̇ P₂) x = split x (◇□-pair (reflect⁺□ P₁ ∘ monVar (there here!)) fresh◇)
reflect⁺□ (Σ̇ I Ps) x = case x λ i → ◇-map (□-map (i ,_)) fresh◇
reflect⁺□ ([ e ] N) x = return (□-mon (reflect⁻ N ∘ force ∘ monVar x))
reflect⁺ : (P : Ty⁺) → (P ∈_) →̇ (⟨ ∅ ⟩ ⟦ P ⟧⁺)
reflect⁺ (base o) x = return x
reflect⁺ (P₁ ×̇ P₂) x = split x (□-weak (fresh□ P₁) ⋉ fresh◇)
reflect⁺ (Σ̇ I Ps) x = case x λ i → ◇-map (i ,_) fresh
reflect⁺ ([ e ] N) x = return λ τ → reflect⁻ N (force (monVar x τ))
reflect⁻ : (N : Ty⁻) → Ne e N →̇ ⟦ N ⟧⁻ e
reflect⁻ (◇̇ P) u = bind u fresh
reflect⁻ (Π̇ I Ns) u = λ i → reflect⁻ (Ns i) (prj i u)
reflect⁻ (P ⇒̇ N) u = λ a → reflect⁻ N (app u (reify⁺ P a))
reify⁺ : (P : Ty⁺) → ⟦ P ⟧⁺ →̇ NVal P
reify⁺ (base o) = var
reify⁺ (P₁ ×̇ P₂) (a₁ , a₂) = pair (reify⁺ P₁ a₁) (reify⁺ P₂ a₂)
reify⁺ (Σ̇ I Ps) (i , a ) = inj i (reify⁺ (Ps i) a)
reify⁺ ([ e ] N) a = thunk (reify⁻ N a)
reify⁻ : (N : Ty⁻) → □ (⟦ N ⟧⁻ e) →̇ Nf e N
reify⁻ (◇̇ P) f = ret (◇-map (reify⁺ P) (extract f))
reify⁻ {e = e} (Π̇ I Ns) f = rec {es = λ i → e} λ i → reify⁻ (Ns i) (□-map (_$ i) f)
reify⁻ (P ⇒̇ N) f = abs $ reify⁻ N $ ◇-elim-□ {B = ⟦ N ⟧⁻} (run⁻ N) (□-weak f) $ fresh□ P
ext : (⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺) →̇ ⟦ P ∷ Γ ⟧ᶜ
ext (γ , a) = a ∷ γ
◇-ext : ⟨ e ⟩ (⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺) →̇ ⟨ e ⟩ ⟦ P ∷ Γ ⟧ᶜ
◇-ext = ◇-map ext
-- Without the use of ◇-mon!
freshᶜ : (Γ : Cxt) → □ (⟨ ∅ ⟩ ⟦ Γ ⟧ᶜ) Γ
freshᶜ [] = λ τ → return []
freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair' (□-weak (freshᶜ Γ)) (fresh□◇□ P)
freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair (mon⁺ P) (□-weak (freshᶜ Γ)) (fresh□ P)
freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair' (□-weak (freshᶜ Γ)) (◇-map (mon⁺ P) ∘ (fresh□ P))
freshᶜ (P ∷ Γ) = ◇-ext ∘ λ τ →
(□-weak (□-mon (freshᶜ Γ)) τ)
⋉ ◇-map (mon⁺ P) (fresh□ P τ)
norm : Comp e N →̇ Nf e N
norm {N = N} {Γ = Γ} t = reify⁻ N $ □-map (run⁻ N ∘ ◇-map ⦅ t ⦆⁻) $ freshᶜ Γ
norm {N = N} {Γ = Γ} t = reify⁻ N $ run⁻ N ∘ ◇-map ⦅ t ⦆⁻ ∘ freshᶜ Γ
-- -}
-- -}
-- -}
-- -}
-- -}
-- -}
| {
"alphanum_fraction": 0.4329323581,
"avg_line_length": 29.3315602837,
"ext": "agda",
"hexsha": "8dbcc4e8b2ac8d3bdc0d163e8ca77ce803256d69",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-25T20:39:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-13T16:01:46.000Z",
"max_forks_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "andreasabel/ipl",
"max_forks_repo_path": "src-cbpv/GradedCBPV.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "andreasabel/ipl",
"max_issues_repo_path": "src-cbpv/GradedCBPV.agda",
"max_line_length": 100,
"max_stars_count": 19,
"max_stars_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "andreasabel/ipl",
"max_stars_repo_path": "src-cbpv/GradedCBPV.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-27T19:10:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-16T08:08:51.000Z",
"num_tokens": 8390,
"size": 16543
} |
{-# OPTIONS --without-K #-}
module Lecture8 where
import Lecture7
open Lecture7 public
-- Section 8.1 Propositions
is-prop : {i : Level} (A : UU i) → UU i
is-prop A = (x y : A) → is-contr (Id x y)
is-prop-empty : is-prop empty
is-prop-empty ()
is-prop-unit : is-prop unit
is-prop-unit = is-prop-is-contr is-contr-unit
is-prop' : {i : Level} (A : UU i) → UU i
is-prop' A = (x y : A) → Id x y
is-prop-is-prop' : {i : Level} {A : UU i} → is-prop' A → is-prop A
is-prop-is-prop' {i} {A} H x y =
dpair
(concat _ (inv (H x x)) (H x y))
(ind-Id
(λ z p → Id (concat _ (inv (H x x)) (H x z)) p)
(left-inv (H x x)) y)
is-prop'-is-prop : {i : Level} {A : UU i} → is-prop A → is-prop' A
is-prop'-is-prop H x y = pr1 (H x y)
is-contr-is-prop-inh : {i : Level} {A : UU i} → is-prop A → A → is-contr A
is-contr-is-prop-inh H a = dpair a (is-prop'-is-prop H a)
is-subtype : {i j : Level} {A : UU i} (B : A → UU j) → UU (i ⊔ j)
is-subtype B = (x : _) → is-prop (B x)
-- Section 8.2 Sets
is-set : {i : Level} → UU i → UU i
is-set A = (x y : A) → is-prop (Id x y)
axiom-K : {i : Level} → UU i → UU i
axiom-K A = (x : A) (p : Id x x) → Id refl p
is-set-axiom-K : {i : Level} (A : UU i) → axiom-K A → is-set A
is-set-axiom-K A H x y =
is-prop-is-prop' (ind-Id (λ z p → (q : Id x z) → Id p q) (H x) y)
axiom-K-is-set : {i : Level} (A : UU i) → is-set A → axiom-K A
axiom-K-is-set A H x p =
concat
(center (is-contr-is-prop-inh (H x x) refl))
(inv (contraction (is-contr-is-prop-inh (H x x) refl) refl))
(contraction (is-contr-is-prop-inh (H x x) refl) p)
is-equiv-prop-in-id : {i j : Level} {A : UU i}
(R : A → A → UU j)
(p : (x y : A) → is-prop (R x y))
(ρ : (x : A) → R x x)
(i : (x y : A) → R x y → Id x y)
→ (x y : A) → is-equiv (i x y)
is-equiv-prop-in-id R p ρ i x =
id-fundamental-retr x (i x)
(λ y → dpair
(ind-Id (λ z p → R x z) (ρ x) y)
((λ r → is-prop'-is-prop (p x y) _ r)))
is-prop-is-equiv : {i j : Level} {A : UU i} (B : UU j)
(f : A → B) (E : is-equiv f) → is-prop B → is-prop A
is-prop-is-equiv B f E H x y =
is-contr-is-equiv (ap f {x} {y}) (is-emb-is-equiv f E x y) (H (f x) (f y))
is-prop-is-equiv' : {i j : Level} (A : UU i) {B : UU j}
(f : A → B) (E : is-equiv f) → is-prop A → is-prop B
is-prop-is-equiv' A f E H =
is-prop-is-equiv _ (inv-is-equiv E) (is-equiv-inv-is-equiv E) H
is-set-prop-in-id : {i j : Level} {A : UU i}
(R : A → A → UU j)
(p : (x y : A) → is-prop (R x y))
(ρ : (x : A) → R x x)
(i : (x y : A) → R x y → Id x y)
→ is-set A
is-set-prop-in-id R p ρ i x y = is-prop-is-equiv' (R x y) (i x y) (is-equiv-prop-in-id R p ρ i x y) (p x y)
is-prop-EqN : (n m : ℕ) → is-prop (EqN n m)
is-prop-EqN Nzero Nzero = is-prop-unit
is-prop-EqN Nzero (Nsucc m) = is-prop-empty
is-prop-EqN (Nsucc n) Nzero = is-prop-empty
is-prop-EqN (Nsucc n) (Nsucc m) = is-prop-EqN n m
is-set-nat : is-set ℕ
is-set-nat =
is-set-prop-in-id
EqN
is-prop-EqN
reflexive-EqN
(least-reflexive-EqN (λ n → refl))
| {
"alphanum_fraction": 0.5342828751,
"avg_line_length": 29.8910891089,
"ext": "agda",
"hexsha": "bff45f66b9f888d6dd70f5a037ec022b4b10bde6",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2018-06-25T15:05:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-02-22T19:58:46.000Z",
"max_forks_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "glangmead/hott_cmu80818",
"max_forks_repo_path": "Lecture8.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b",
"max_issues_repo_issues_event_max_datetime": "2018-03-25T14:44:31.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-22T21:01:16.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "glangmead/hott_cmu80818",
"max_issues_repo_path": "Lecture8.agda",
"max_line_length": 107,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "glangmead/hott_cmu80818",
"max_stars_repo_path": "Lecture8.agda",
"max_stars_repo_stars_event_max_datetime": "2018-09-04T02:52:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-03T20:32:19.000Z",
"num_tokens": 1277,
"size": 3019
} |
module MLib.Fin.Parts.Nat where
open import MLib.Prelude
open import MLib.Fin.Parts.Core
open Nat using (_*_; _+_; _<_)
open Fin using (fromℕ≤)
open Table
module Impl where
tryLookup : ∀ {n} {a} {A : Set a} → A → Table A n → ℕ → A
tryLookup {n = zero} z t _ = z
tryLookup {n = suc n} z t zero = lookup t zero
tryLookup {n = suc n} z t (suc i) = tryLookup z (tail t) i
tryLookup-prop : ∀ {n} {a} {A : Set a} {z : A} (t : Table A n) {i : Fin n} → lookup t i ≡ tryLookup z t (Fin.toℕ i)
tryLookup-prop _ {i = zero} = ≡.refl
tryLookup-prop t {i = suc i} = tryLookup-prop (tail t)
data Ordering′ : ℕ → ℕ → Set where
less : ∀ m k → Ordering′ m (suc (m + k))
gte : ∀ m k → Ordering′ (m + k) m
compare′ : ∀ m n → Ordering′ m n
compare′ zero zero = gte zero zero
compare′ zero (suc n) = less zero n
compare′ (suc m) zero = gte zero (suc m)
compare′ (suc m) (suc n) with compare′ m n
compare′ (suc m) (suc .(suc (m + k))) | less .m k = less (suc m) k
compare′ (suc .(n + k)) (suc n) | gte .n k = gte (suc n) k
-- Core lemmas
lz-lem : ∀ a b c → a + b < a + c → b < c
lz-lem zero b c p = p
lz-lem (suc a) b c p = lz-lem a b c (Nat.+-cancelˡ-≤ 1 p)
lz-lem₂ : ∀ a b → a < a + b → 0 < b
lz-lem₂ zero b p = p
lz-lem₂ (suc a) b p = lz-lem₂ a b (Nat.+-cancelˡ-≤ 1 p)
fromℕ≤-cong′ : ∀ {a b m n} {p : a < m} {q : b < n} → m ≡ n → a ≡ b → fromℕ≤ {a} p ≅ fromℕ≤ {b} q
fromℕ≤-cong′ {p = Nat.s≤s Nat.z≤n} {Nat.s≤s Nat.z≤n} ≡.refl ≡.refl = ≅.refl
fromℕ≤-cong′ {p = Nat.s≤s (Nat.s≤s p)} {Nat.s≤s (Nat.s≤s q)} ≡.refl ≡.refl = ≅.cong suc (fromℕ≤-cong′ {p = Nat.s≤s p} {q = Nat.s≤s q} ≡.refl ≡.refl)
fromℕ≤-cong : ∀ {a b n} {p : a < n} {q : b < n} → a ≡ b → fromℕ≤ {a} p ≡ fromℕ≤ {b} q
fromℕ≤-cong = ≅.≅-to-≡ ∘ fromℕ≤-cong′ ≡.refl
-- Core functions
fromParts : {numParts : ℕ} (parts : Table ℕ numParts) → ℕ × ℕ → ℕ
fromParts parts (zero , j) = j
fromParts {zero} parts (suc i , j) = 0
fromParts {suc numParts} parts (suc i , j) = lookup parts zero + fromParts (tail parts) (i , j)
toParts : {numParts : ℕ} (parts : Table ℕ numParts) (k : ℕ) → ℕ × ℕ
toParts {zero} parts k = 0 , 0
toParts {suc n} parts k with lookup parts zero | compare′ k (lookup parts zero)
toParts {suc n} parts k | .(suc (k + k₁)) | less .k k₁ = 0 , k
toParts {suc n} parts .(lz + k) | lz | gte .lz k =
let i , j = toParts (tail parts) k
in (suc i , j)
-- Property lemmas
+-<-lem : ∀ {a b c} → b < c → a + b < a + c
+-<-lem {zero} p = p
+-<-lem {suc a} p = Nat.s≤s (+-<-lem p)
fromℕ-suc-lem : ∀ {m n} (p : m < n) → suc (fromℕ≤ p) ≡ fromℕ≤ (Nat.s≤s p)
fromℕ-suc-lem (Nat.s≤s p) = ≡.refl
-- Properties
fromParts-prop : ∀ {numParts} (parts : Table ℕ numParts) {i j} → i < numParts → j < tryLookup 0 parts i → fromParts parts (i , j) < sum parts
fromParts-prop {suc numParts} _ {zero} (Nat.s≤s p) q = Nat.≤-trans q (Nat.m≤m+n _ _)
fromParts-prop {suc numParts} parts {suc i} (Nat.s≤s p) q = +-<-lem (fromParts-prop (tail parts) p q)
toParts-prop : ∀ {numParts : ℕ} (parts : Table ℕ numParts) {k} → k < sum parts →
let i , j = toParts parts k
in Σ (i < numParts) (λ q → j < lookup parts (fromℕ≤ {i} q))
toParts-prop {zero} parts {k} ()
toParts-prop {suc numParts} parts {k} p with lookup parts zero | compare′ k (lookup parts zero) | ≡.inspect (lookup parts) zero
toParts-prop {suc numParts} parts {k} p | .(suc (k + k₁)) | less .k k₁ | ≡.[ eq ] =
Nat.s≤s Nat.z≤n ,
Nat.≤-trans (Nat.s≤s (Nat.m≤m+n _ _)) (Nat.≤-reflexive (≡.sym eq))
toParts-prop {suc numParts} parts {.(lz + k)} p | lz | gte .lz k | insp =
let q , r = toParts-prop (tail parts) {k} (lz-lem _ _ _ p)
in Nat.s≤s q , Nat.≤-trans r (Nat.≤-reflexive (≡.cong (lookup parts) (fromℕ-suc-lem _)))
toParts-fromParts :
{numParts : ℕ} (parts : Table ℕ numParts) (i j : ℕ) (p : j < tryLookup 0 parts i) →
toParts parts (fromParts parts (i , j)) ≡ (i , j)
toParts-fromParts {zero} _ i j ()
toParts-fromParts {suc numParts} parts i j p
with lookup parts zero
| fromParts parts (i , j)
| compare′ (fromParts parts (i , j)) (lookup parts zero)
| ≡.inspect (lookup parts) zero
| ≡.inspect (fromParts parts) (i , j)
toParts-fromParts {suc numParts} parts zero .ipi p
| .(suc (ipi + k)) | ipi | less .ipi k | insp₁ | ≡.[ ≡.refl ]
= ≡.refl
toParts-fromParts {suc numParts} parts zero .(lookup parts zero + k) p
| .(lookup parts zero) | .(lookup parts zero + k) | gte .(lookup parts zero) k | ≡.[ ≡.refl ] | ≡.[ ≡.refl ]
= ⊥-elim (Nat.n≮n _ (Nat.≤-trans p (Nat.m≤m+n _ k)))
toParts-fromParts {suc numParts} parts (suc i) j p
| .(suc (ipi + k)) | ipi | less .ipi k | ≡.[ eq ] | ≡.[ eq₁ ]
= let y = lookup parts zero
z = fromParts _ (i , j)
in ⊥-elim (Nat.m≢1+m+n y {z + k} (
begin
y ≡⟨ eq ⟩
suc (ipi + k) ≡⟨ ≡.cong (λ h → suc (h + k)) (≡.sym eq₁) ⟩
suc ((y + z) + k) ≡⟨ ≡.cong suc (Nat.+-assoc y z k) ⟩
suc (y + (z + k)) ∎))
where open ≡.Reasoning
toParts-fromParts {suc numParts} parts (suc i) j p
| .(lookup parts zero) | .(lookup parts zero + k) | gte .(lookup parts zero) k | ≡.[ ≡.refl ] | ≡.[ eq₁ ]
with Nat.+-cancelˡ-≡ (lookup parts zero) eq₁
toParts-fromParts {suc numParts} parts (suc i) j p
| .(lookup parts zero) | .(lookup parts zero + k) | gte .(lookup parts zero) k | ≡.[ ≡.refl ] | ≡.[ eq₁ ]
| eq₂ rewrite ≡.sym eq₂
= let q , r = Σ.≡⇒Pointwise-≡ (toParts-fromParts (tail parts) i j p)
in Σ.Pointwise-≡⇒≡ (≡.cong suc q , r)
fromParts-toParts : {numParts : ℕ} (parts : Table ℕ numParts) (k : ℕ) (p : k < sum parts) → fromParts parts (toParts parts k) ≡ k
fromParts-toParts {zero} parts k ()
fromParts-toParts {suc numParts} parts k p
with lookup parts zero
| compare′ k (lookup parts zero)
| ≡.inspect (lookup parts) zero
fromParts-toParts {suc numParts} parts k p | .(suc (k + k₁)) | less .k k₁ | insp = ≡.refl
fromParts-toParts {suc numParts} parts .(lookup parts zero + k) p | .(lookup parts zero) | gte .(lookup parts zero) k | ≡.[ ≡.refl ]
= ≡.cong₂ Nat._+_
≡.refl
(fromParts-toParts (tail parts) k
(Nat.+-cancelˡ-≤ (lookup parts zero) (Nat.≤-trans (Nat.≤-reflexive (Nat.+-suc _ k)) p)))
module Partsℕ {a} {A : Set a} {size : A → ℕ} (P : Parts A size) where
open Parts P public
fromParts : ℕ × ℕ → ℕ
fromParts = Impl.fromParts partsizes
toParts : ℕ → ℕ × ℕ
toParts = Impl.toParts partsizes
private
tryLookup-lem : ∀ {i j} (p : i < numParts) → j < sizeAt (Fin.fromℕ≤ p) → j < Impl.tryLookup 0 partsizes i
tryLookup-lem p q = Nat.≤-trans q (Nat.≤-reflexive (≡.trans (Impl.tryLookup-prop {z = 0} partsizes) (≡.cong (Impl.tryLookup 0 partsizes) (Fin.toℕ-fromℕ≤ _))))
fromParts-prop : ∀ {i j} (p : i < numParts) → j < sizeAt (Fin.fromℕ≤ p) → fromParts (i , j) < totalSize
fromParts-prop p = Impl.fromParts-prop _ p ∘ tryLookup-lem p
toParts-prop : ∀ {k} → k < totalSize →
let i , j = toParts k
in Σ (i < numParts) (λ q → j < lookup partsizes (fromℕ≤ q))
toParts-prop = Impl.toParts-prop _
abstract
toParts-fromParts : ∀ {i j} (p : i < numParts) (q : j < sizeAt (Fin.fromℕ≤ p)) → toParts (fromParts (i , j)) ≡ (i , j)
toParts-fromParts p = Impl.toParts-fromParts partsizes _ _ ∘ tryLookup-lem p
fromParts-toParts : ∀ k (p : k < totalSize) → fromParts (toParts k) ≡ k
fromParts-toParts = Impl.fromParts-toParts partsizes
| {
"alphanum_fraction": 0.5663244901,
"avg_line_length": 44.6488095238,
"ext": "agda",
"hexsha": "632792cbb1c867dbd4f1be932c682d75b703d6bb",
"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": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Fin/Parts/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"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": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Fin/Parts/Nat.agda",
"max_line_length": 162,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Fin/Parts/Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3116,
"size": 7501
} |
Type-of : {A : Set} → A → Set
Type-of {A = A} _ = A
module _ (A : Set) where
Foo : A → Set
Foo a with Type-of a
... | B = B
| {
"alphanum_fraction": 0.4812030075,
"avg_line_length": 13.3,
"ext": "agda",
"hexsha": "164638f2e62b78bf2772904de26e172c8f8fb442",
"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/Issue2324.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/Issue2324.agda",
"max_line_length": 29,
"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/Issue2324.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": 56,
"size": 133
} |
module RecordPatternMatching where
record _×_ (A B : Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B
data Unit : Set where
unit : Unit
foo : Unit × Unit → Unit
foo (x , y) = {!!}
record Box (A : Set) : Set where
constructor [_]
field
proj : A
bar : Box Unit → Unit
bar [ x ] = {!!}
| {
"alphanum_fraction": 0.5875,
"avg_line_length": 14.5454545455,
"ext": "agda",
"hexsha": "44cea86bfe1afcd0df2d6fabd79a62d9d1894008",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/RecordPatternMatching.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/RecordPatternMatching.agda",
"max_line_length": 34,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/RecordPatternMatching.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": 104,
"size": 320
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Unary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Unary where
open import Data.Empty
open import Data.Unit.Base using (⊤)
open import Data.Product
open import Data.Sum.Base using (_⊎_; [_,_])
open import Function.Base
open import Level
open import Relation.Nullary hiding (Irrelevant)
open import Relation.Nullary.Decidable.Core using (True)
open import Relation.Binary.PropositionalEquality.Core using (_≡_)
private
variable
a b c ℓ ℓ₁ ℓ₂ : Level
A : Set a
B : Set b
C : Set c
------------------------------------------------------------------------
-- Definition
-- Unary relations are known as predicates and `Pred A ℓ` can be viewed
-- as some property that elements of type A might satisfy.
-- Consequently `P : Pred A ℓ` can also be seen as a subset of A
-- containing all the elements of A that satisfy property P. This view
-- informs much of the notation used below.
Pred : ∀ {a} → Set a → (ℓ : Level) → Set (a ⊔ suc ℓ)
Pred A ℓ = A → Set ℓ
------------------------------------------------------------------------
-- Special sets
-- The empty set.
∅ : Pred A 0ℓ
∅ = λ _ → ⊥
-- The singleton set.
{_} : A → Pred A _
{ x } = x ≡_
-- The universal set.
U : Pred A 0ℓ
U = λ _ → ⊤
------------------------------------------------------------------------
-- Membership
infix 4 _∈_ _∉_
_∈_ : A → Pred A ℓ → Set _
x ∈ P = P x
_∉_ : A → Pred A ℓ → Set _
x ∉ P = ¬ x ∈ P
------------------------------------------------------------------------
-- Subset relations
infix 4 _⊆_ _⊇_ _⊈_ _⊉_ _⊂_ _⊃_ _⊄_ _⊅_
_⊆_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q
_⊇_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊇ Q = Q ⊆ P
_⊈_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊈ Q = ¬ (P ⊆ Q)
_⊉_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊉ Q = ¬ (P ⊇ Q)
_⊂_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊂ Q = P ⊆ Q × Q ⊈ P
_⊃_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊃ Q = Q ⊂ P
_⊄_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊄ Q = ¬ (P ⊂ Q)
_⊅_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊅ Q = ¬ (P ⊃ Q)
-- The following primed variants of _⊆_ can be used when 'x' can't
-- be inferred from 'x ∈ P'.
infix 4 _⊆′_ _⊇′_ _⊈′_ _⊉′_ _⊂′_ _⊃′_ _⊄′_ _⊅′_
_⊆′_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊆′ Q = ∀ x → x ∈ P → x ∈ Q
_⊇′_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
Q ⊇′ P = P ⊆′ Q
_⊈′_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊈′ Q = ¬ (P ⊆′ Q)
_⊉′_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊉′ Q = ¬ (P ⊇′ Q)
_⊂′_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊂′ Q = P ⊆′ Q × Q ⊈′ P
_⊃′_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊃′ Q = Q ⊂′ P
_⊄′_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊄′ Q = ¬ (P ⊂′ Q)
_⊅′_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ⊅′ Q = ¬ (P ⊃′ Q)
------------------------------------------------------------------------
-- Properties of sets
infix 10 Satisfiable Universal IUniversal
-- Emptiness - no element satisfies P.
Empty : Pred A ℓ → Set _
Empty P = ∀ x → x ∉ P
-- Satisfiable - at least one element satisfies P.
Satisfiable : Pred A ℓ → Set _
Satisfiable P = ∃ λ x → x ∈ P
syntax Satisfiable P = ∃⟨ P ⟩
-- Universality - all elements satisfy P.
Universal : Pred A ℓ → Set _
Universal P = ∀ x → x ∈ P
syntax Universal P = Π[ P ]
-- Implicit universality - all elements satisfy P.
IUniversal : Pred A ℓ → Set _
IUniversal P = ∀ {x} → x ∈ P
syntax IUniversal P = ∀[ P ]
-- Decidability - it is possible to determine if an arbitrary element
-- satisfies P.
Decidable : Pred A ℓ → Set _
Decidable P = ∀ x → Dec (P x)
-- Erasure: A decidable predicate gives rise to another one, more
-- amenable to η-expansion
⌊_⌋ : {P : Pred A ℓ} → Decidable P → Pred A ℓ
⌊ P? ⌋ a = Lift _ (True (P? a))
-- Irrelevance - any two proofs that an element satifies P are
-- indistinguishable.
Irrelevant : Pred A ℓ → Set _
Irrelevant P = ∀ {x} (a : P x) (b : P x) → a ≡ b
-- Recomputability - we can rebuild a relevant proof given an
-- irrelevant one.
Recomputable : Pred A ℓ → Set _
Recomputable P = ∀ {x} → .(P x) → P x
------------------------------------------------------------------------
-- Operations on sets
infix 10 ⋃ ⋂
infixr 9 _⊢_
infixr 8 _⇒_
infixr 7 _∩_
infixr 6 _∪_
infix 4 _≬_
-- Complement.
∁ : Pred A ℓ → Pred A ℓ
∁ P = λ x → x ∉ P
-- Implication.
_⇒_ : Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ⇒ Q = λ x → x ∈ P → x ∈ Q
-- Union.
_∪_ : Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ∪ Q = λ x → x ∈ P ⊎ x ∈ Q
-- Intersection.
_∩_ : Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ∩ Q = λ x → x ∈ P × x ∈ Q
-- Infinitary union.
⋃ : ∀ {i} (I : Set i) → (I → Pred A ℓ) → Pred A _
⋃ I P = λ x → Σ[ i ∈ I ] P i x
syntax ⋃ I (λ i → P) = ⋃[ i ∶ I ] P
-- Infinitary intersection.
⋂ : ∀ {i} (I : Set i) → (I → Pred A ℓ) → Pred A _
⋂ I P = λ x → (i : I) → P i x
syntax ⋂ I (λ i → P) = ⋂[ i ∶ I ] P
-- Positive version of non-disjointness, dual to inclusion.
_≬_ : Pred A ℓ₁ → Pred A ℓ₂ → Set _
P ≬ Q = ∃ λ x → x ∈ P × x ∈ Q
-- Update.
_⊢_ : (A → B) → Pred B ℓ → Pred A ℓ
f ⊢ P = λ x → P (f x)
------------------------------------------------------------------------
-- Predicate combinators
-- These differ from the set operations above, as the carrier set of the
-- resulting predicates are not the same as the carrier set of the
-- component predicates.
infixr 2 _⟨×⟩_
infixr 2 _⟨⊙⟩_
infixr 1 _⟨⊎⟩_
infixr 0 _⟨→⟩_
infixl 9 _⟨·⟩_
infix 10 _~
infixr 9 _⟨∘⟩_
infixr 2 _//_ _\\_
-- Product.
_⟨×⟩_ : Pred A ℓ₁ → Pred B ℓ₂ → Pred (A × B) _
(P ⟨×⟩ Q) (x , y) = x ∈ P × y ∈ Q
-- Sum over one element.
_⟨⊎⟩_ : Pred A ℓ → Pred B ℓ → Pred (A ⊎ B) _
P ⟨⊎⟩ Q = [ P , Q ]
-- Sum over two elements.
_⟨⊙⟩_ : Pred A ℓ₁ → Pred B ℓ₂ → Pred (A × B) _
(P ⟨⊙⟩ Q) (x , y) = x ∈ P ⊎ y ∈ Q
-- Implication.
_⟨→⟩_ : Pred A ℓ₁ → Pred B ℓ₂ → Pred (A → B) _
(P ⟨→⟩ Q) f = P ⊆ Q ∘ f
-- Product.
_⟨·⟩_ : (P : Pred A ℓ₁) (Q : Pred B ℓ₂) →
(P ⟨×⟩ (P ⟨→⟩ Q)) ⊆ Q ∘ uncurry (flip _$_)
(P ⟨·⟩ Q) (p , f) = f p
-- Converse.
_~ : Pred (A × B) ℓ → Pred (B × A) ℓ
P ~ = P ∘ swap
-- Composition.
_⟨∘⟩_ : Pred (A × B) ℓ₁ → Pred (B × C) ℓ₂ → Pred (A × C) _
(P ⟨∘⟩ Q) (x , z) = ∃ λ y → (x , y) ∈ P × (y , z) ∈ Q
-- Post-division.
_//_ : Pred (A × C) ℓ₁ → Pred (B × C) ℓ₂ → Pred (A × B) _
(P // Q) (x , y) = Q ∘ (y ,_) ⊆ P ∘ (x ,_)
-- Pre-division.
_\\_ : Pred (A × C) ℓ₁ → Pred (A × B) ℓ₂ → Pred (B × C) _
P \\ Q = (P ~ // Q ~) ~
| {
"alphanum_fraction": 0.4933458588,
"avg_line_length": 21.432885906,
"ext": "agda",
"hexsha": "ffee3d05c8f60b6cd5d574a4a1d25a78833f83c6",
"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/Relation/Unary.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/Relation/Unary.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Unary.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": 2554,
"size": 6387
} |
-- Andreas, 2016-06-20, issue #1891
-- Computation of which variables are splittable was wrong
-- in the presence of a where-module.
-- {-# OPTIONS -v interaction.case:20 #-}
data D : Set where
c : D
test : (x : D) → D
test x = {!x!} -- C-c C-c
where
y = c
-- WAS:
-- Splitting on x reports:
-- Not a (splittable) variable: x
-- when checking that the expression ? has type D
-- Should work now.
-- Further tests:
record R (A : Set) : Set where
testR : (x : D) → D
testR x = {!x!}
where B = A
module M (A : Set) where
testM : (x : D) → D
testM x = {!x!}
where open R {A = A}
| {
"alphanum_fraction": 0.5822368421,
"avg_line_length": 17.8823529412,
"ext": "agda",
"hexsha": "79f3b708c3c58065bd8f4e5b35d2aed292c6de13",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue1891.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue1891.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue1891.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": 608
} |
open import Data.Nat using (ℕ; _+_) renaming (_≤?_ to _≤?ₙ_)
open import Data.Bool using (Bool; true; false; not; _∧_)
open import Data.String using (String; _≟_)
open import Data.Sum using (_⊎_; [_,_]′; inj₁; inj₂)
open import Data.Product using (_×_; _,_)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Data.Product using (_×_; _,_; -,_; _-,-_; ∃; ∃-syntax)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym)
open import Level using (Level; suc; _⊔_)
open import IMP
open import Hoare
data True {l} : Set l where
⊤ : True
data acom {l} : Set (suc l) where
SKIP : acom
_::=_ : String → aexp → acom
_::_ : acom {l} → acom {l} → acom
IF_THEN_ELSE_ : bexp → acom {l} → acom {l} → acom
WHILE[_]_DO_ : assn {l} → bexp → acom {l} → acom
strip : ∀{l} → acom {l} → com
strip SKIP = SKIP
strip (x ::= a) = x ::= a
strip (c₁ :: c₂) = strip c₁ :: strip c₂
strip (IF b THEN c₁ ELSE c₂) = IF b THEN strip c₁ ELSE strip c₂
strip (WHILE[ I ] b DO c) = WHILE b DO strip c
pre : ∀{l} → acom {l} → assn → assn
pre SKIP Q = Q
pre (x ::= a) Q s = Q (s [ x ::= aval a s ])
pre (c₁ :: c₂) Q = pre c₁ (pre c₂ Q)
pre (IF b THEN c₁ ELSE c₂) Q s with bval b s
... | true = pre c₁ Q s
... | false = pre c₂ Q s
pre (WHILE[ I ] b DO c) Q = I
vc : ∀{l} → acom {l} → assn → Set l
vc SKIP Q = True
vc (x ::= x₁) Q = True
vc (c₁ :: c₂) Q = vc c₁ (pre c₂ Q) × vc c₂ Q
vc (IF b THEN c₁ ELSE c₂) Q = vc c₁ Q × vc c₂ Q
vc (WHILE[ I ] b DO c) Q =
(∀ s → I s × bval b s ≡ true → pre c I s)
× (∀ s → I s × bval b s ≡ false → Q s)
× vc c I
extract-if-pre₁ : ∀{l} {Q : assn {l}} {c₁ c₂ s} b
→ pre (IF b THEN c₁ ELSE c₂) Q s
× bval b s ≡ true
→ pre c₁ Q s
extract-if-pre₁ b (x , y) rewrite y = x
extract-if-pre₂ : ∀{l} {Q : assn {l}} {c₁ c₂ s} b
→ pre (IF b THEN c₁ ELSE c₂) Q s
× bval b s ≡ false
→ pre c₂ Q s
extract-if-pre₂ b (x , y) rewrite y = x
vc-correctness : ∀{l} {P Q : assn} c
→ vc {l} c Q
→ (∀ s → P s → pre c Q s)
→ ⊢[ P ] strip c [ Q ]
vc-correctness SKIP v i = Conseq i Skip (λ s z → z)
vc-correctness (x ::= a) v i = Conseq i Loc (λ r k → k)
vc-correctness (c₁ :: c₂) v i = Comp (vc-correctness c₁ (Data.Product.proj₁ v) i)
(vc-correctness c₂ (Data.Product.proj₂ v) (λ s z → z))
vc-correctness {l}{P}{Q} (IF b THEN c₁ ELSE c₂) (fst , snd) i =
Conseq i (If (vc-correctness c₁ fst (λ s p → extract-if-pre₁ b p))
(vc-correctness c₂ snd (λ s p → extract-if-pre₂ b p)))
(λ s z → z)
vc-correctness (WHILE[ I ] b DO c) (fst , fst₁ , snd) i =
Conseq i (While (vc-correctness c snd fst)) fst₁
pre-mono : ∀{l} {P P′ : assn {l}} {s′} c
→ (∀ s → P s → P′ s)
→ pre c P s′ → pre c P′ s′
pre-mono {s′ = s′} SKIP x x₁ = x s′ x₁
pre-mono (x₂ ::= x₃) x x₁ = x _ x₁
pre-mono (c :: c₁) x x₁ = pre-mono c (λ s → pre-mono c₁ x) x₁
pre-mono {s′ = s′} (IF x₂ THEN c₁ ELSE c₂) x x₁ with bval x₂ s′
... | true = pre-mono c₁ x x₁
... | false = pre-mono c₂ x x₁
pre-mono (WHILE[ x₂ ] x₃ DO c) x x₁ = x₁
vc-mono : ∀{l} {P P′ : assn {l}} c
→ (∀ s → P s → P′ s)
→ vc c P → vc c P′
vc-mono SKIP _ _ = ⊤
vc-mono (x ::= a) _ _ = ⊤
vc-mono (c₁ :: c₂) pp′ (vcpre , vc2) = vc-mono c₁ (λ _ → pre-mono c₂ pp′) vcpre , vc-mono c₂ pp′ vc2
vc-mono (IF b THEN c₁ ELSE c₂) pp′ (vc₁ , vc₂) = vc-mono c₁ pp′ vc₁ , vc-mono c₂ pp′ vc₂
vc-mono (WHILE[ I ] b DO c) pp′ (I₁ , I₂ , vcc) = I₁ , (λ s z → pp′ s (I₂ s z)) , vcc
either : ∀ c → c ≡ true ⊎ c ≡ false
either true = inj₁ refl
either false = inj₂ refl
construct-if-pre : ∀{l} {P Q : assn {l}} {ac₁ ac₂} b s
→ (bval b s ≡ true → pre ac₁ Q s)
→ (bval b s ≡ false → pre ac₂ Q s)
→ pre (IF b THEN ac₁ ELSE ac₂) Q s
construct-if-pre b s f g with bval b s
... | true = f refl
... | false = g refl
vc-completeness : ∀{l} {P Q : assn {l}} c
→ ⊢[ P ] c [ Q ]
→ ∃[ c̃ ] ( c ≡ strip c̃
× vc c̃ Q
× (∀ s → P s → pre c̃ Q s))
vc-completeness c Skip = SKIP , refl , ⊤ , (λ x c → c)
vc-completeness c Loc = _ , refl , ⊤ , (λ x c → c)
vc-completeness (c₁ :: c₂) (Comp x y) with vc-completeness c₁ x
... | ac₁ , b , c , d with vc-completeness c₂ y
... | ac₂ , f , g , h rewrite b | f
= (ac₁ :: ac₂) , refl
, (vc-mono ac₁ h c , g)
, (λ s ps → pre-mono ac₁ h (d s ps))
vc-completeness {P = P} (IF b THEN c₁ ELSE c₂) (If d₁ d₂) with vc-completeness c₁ d₁
... | ac₁ , f , g , h with vc-completeness c₂ d₂
... | ac₂ , j , k , m rewrite f | j
= (IF b THEN ac₁ ELSE ac₂) , refl
, (g , k)
, (λ s ps → construct-if-pre {P = P} b s (λ t → h s (ps , t)) (λ f → m s (ps , f)))
vc-completeness (WHILE b DO c) (While r) with vc-completeness c r
... | ac , f , g , h rewrite f = (WHILE[ _ ] b DO ac) , refl
, (h , (λ s z → z) , g)
, λ s z → z
vc-completeness c (Conseq x₁ r x₂) with vc-completeness c r
... | ac , f , g , h rewrite f
= ac , refl
, vc-mono ac x₂ g
, (λ s ps → pre-mono ac x₂ (h s (x₁ s ps)))
| {
"alphanum_fraction": 0.5121442125,
"avg_line_length": 38.1884057971,
"ext": "agda",
"hexsha": "6e46e639fa05be63634457572b04bcb8e868ef73",
"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": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "iwilare/imp-semantics",
"max_forks_repo_path": "VerificationConditions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc",
"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": "iwilare/imp-semantics",
"max_issues_repo_path": "VerificationConditions.agda",
"max_line_length": 105,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "iwilare/imp-semantics",
"max_stars_repo_path": "VerificationConditions.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-24T22:29:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-08T11:54:07.000Z",
"num_tokens": 2129,
"size": 5270
} |
module Category.Monoidal where
open import Category.NatIsomorphism
| {
"alphanum_fraction": 0.8550724638,
"avg_line_length": 13.8,
"ext": "agda",
"hexsha": "5829e96324aa243003201bd3daf8060ad4633971",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "setoid-cats/Category/Monoidal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "setoid-cats/Category/Monoidal.agda",
"max_line_length": 35,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "setoid-cats/Category/Monoidal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 15,
"size": 69
} |
-- {-# OPTIONS --show-implicit --show-irrelevant #-}
module Data.QuadTree.FoldableProofs.FoldableProof where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Data.Logic
open import Data.QuadTree.Implementation.Definition
open import Data.QuadTree.Implementation.ValidTypes
open import Data.QuadTree.Implementation.QuadrantLenses
open import Data.QuadTree.Implementation.SafeFunctions
open import Data.QuadTree.Implementation.PropDepthRelation
open import Data.QuadTree.Implementation.Foldable
-- All proofs for Foldables
-- foldr f z t = appEndo (foldMap (Endo . f) t ) z
-- foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z
-- fold = foldMap id
-- length = getSum . foldMap (Sum . const 1)
-- I didn't change the default implementations of foldl/foldr/fold/length, so these laws should all hold
-- However, I will proof that the length of the quadtree is equal to width * height.
-- lengthₑ quadtreeFoldable vqt ≡ size vqt
size : {t : Set} {{eqT : Eq t}} {dep : Nat} -> (vqt : VQuadTree t {dep}) -> Nat
size (CVQuadTree (Wrapper (w , h) x₁)) = w * h
lengthₙ : {t : Set → Set} ⦃ r : Foldable t ⦄ {a : Set} → t a → Nat
lengthₙ {{r}} = foldMap {{r}} {{ MonoidSum }} (const 1)
length-replicateₙ : {t : Set} (n : Nat) (v : t) -> lengthₙ (replicateₙ n v) ≡ n
length-replicateₙ {t} Z v = refl
length-replicateₙ {t} (S n) v =
begin
lengthₙ (replicateₙ (S n) v)
=⟨⟩
S (lengthₙ (replicateₙ n v))
=⟨ cong S (length-replicateₙ n v ) ⟩
S n
end
length-concat-sub : {t : Set} -> (list : List t) (lists : List (List t)) -> lengthₙ (list ++ concat lists) ≡ lengthₙ list + lengthₙ (concat lists)
length-concat-sub {t} [] lists = refl
length-concat-sub {t} (x ∷ xs) lists =
begin
lengthₙ ((x ∷ xs) ++ concat lists)
=⟨⟩
S (lengthₙ (xs ++ concat lists))
=⟨ cong S (length-concat-sub xs lists) ⟩
lengthₙ (x ∷ xs) + lengthₙ (concat lists)
end
length-concat : {t : Set} -> (lists : List (List t)) -> lengthₙ (concat lists) ≡ sum (map lengthₙ lists)
length-concat {t} [] = refl
length-concat {t} (list ∷ lists) =
begin
lengthₙ (concat (list ∷ lists))
=⟨⟩
lengthₙ (list ++ concat lists)
=⟨ length-concat-sub list lists ⟩
lengthₙ list + lengthₙ (concat lists)
=⟨ cong (λ q -> lengthₙ list + q) (length-concat lists) ⟩
lengthₙ list + sum (map lengthₙ lists)
=⟨⟩
sum (map lengthₙ (list ∷ lists))
end
concat-nothing : {t : Set} -> (list : List t) -> list ++ [] ≡ list
concat-nothing [] = refl
concat-nothing (x ∷ list) = cong (λ z → x ∷ z) (concat-nothing list)
diff-n-zero : (n : Nat) -> diff n Z ≡ n
diff-n-zero Z = refl
diff-n-zero (S n) = refl
map-concat : {s t : Set} -> (a b : List s)
-> (f : s -> t)
-> map f (a ++ b) ≡ map f a ++ map f b
map-concat [] b f = refl
map-concat (a ∷ as) b f = cong (λ z → f a ∷ z) (map-concat as b f)
map-concat4 : {s t : Set} -> (a b c d : List s)
-> (f : s -> t)
-> map f (a ++ b ++ c ++ d) ≡ map f a ++ map f b ++ map f c ++ map f d
map-concat4 a b c d f =
begin
map f (a ++ b ++ c ++ d)
=⟨ map-concat a (b ++ c ++ d) f ⟩
map f a ++ map f (b ++ c ++ d)
=⟨ cong (λ q -> map f a ++ q) (map-concat b (c ++ d) f) ⟩
map f a ++ map f b ++ map f (c ++ d)
=⟨ cong (λ q -> map f a ++ map f b ++ q) (map-concat c d f) ⟩
map f a ++ map f b ++ map f c ++ map f d
end
sum-concat : (a b : List Nat) -> sum (a ++ b) ≡ sum a + sum b
sum-concat [] b = refl
sum-concat (a ∷ as) b =
begin
a + sum (as ++ b)
=⟨ cong (λ q -> a + q) (sum-concat as b) ⟩
a + (sum as + sum b)
=⟨ sym $ add-assoc a (sum as) (sum b) ⟩
sum (a ∷ as) + sum b
end
sum-concat4 : (a b c d : List Nat) -> sum (a ++ b ++ c ++ d) ≡ sum a + sum b + sum c + sum d
sum-concat4 a b c d =
begin
sum (a ++ b ++ c ++ d)
=⟨ sum-concat a (b ++ c ++ d) ⟩
sum a + sum (b ++ c ++ d)
=⟨ cong (λ q -> sum a + q) (sum-concat b (c ++ d)) ⟩
sum a + (sum b + sum (c ++ d))
=⟨ cong (λ q -> sum a + (sum b + q)) (sum-concat c d) ⟩
sum a + (sum b + (sum c + sum d))
=⟨ sym $ add-assoc (sum a) (sum b) (sum c + sum d) ⟩
(sum a + sum b) + (sum c + sum d)
=⟨ sym $ add-assoc (sum a + sum b) (sum c) (sum d) ⟩
sum a + sum b + sum c + sum d
end
nat-distributive : (a b c : Nat) -> (a * c) + (b * c) ≡ (a + b) * c
nat-distributive Z b c = refl
nat-distributive (S a) b c =
begin
(S a * c) + (b * c)
=⟨ add-assoc c (a * c) (b * c) ⟩
c + ((a * c) + b * c)
=⟨ cong (_+_ c) (nat-distributive a b c) ⟩
c + ((a + b) * c)
=⟨⟩
(S a + b) * c
end
add-diff : (a b : Nat) -> IsTrue (a <= b) -> a + diff b a ≡ b
add-diff Z Z ab = refl
add-diff Z (S b) ab = refl
add-diff (S a) (S b) ab = cong S (add-diff a b ab)
line-split-left : (x1 xm x2 y : Nat) -> IsTrue (x1 <= xm) -> IsTrue (xm <= x2) -> IsTrue (x1 <= x2)
-> diff xm x1 * y + diff x2 xm * y ≡ diff x2 x1 * y
line-split-left Z Z Z y x1m xm2 x12 = refl
line-split-left Z Z (S x2) y x1m xm2 x12 = refl
line-split-left Z (S xm) (S x2) y x1m xm2 x12 =
begin
(S xm) * y + diff (S x2) (S xm) * y
=⟨ nat-distributive (S xm) (diff (S x2) (S xm)) y ⟩
((S xm) + diff (S x2) (S xm)) * y
=⟨ cong (λ z → y + (z * y)) (add-diff xm x2 xm2) ⟩
(S x2) * y
end
line-split-left (S x1) (S xm) (S x2) y x1m xm2 x12 = line-split-left x1 xm x2 y x1m xm2 x12
line-split-right : (x1 xm x2 y : Nat) -> IsTrue (x1 <= xm) -> IsTrue (xm <= x2) -> IsTrue (x1 <= x2)
-> y * diff xm x1 + y * diff x2 xm ≡ y * diff x2 x1
line-split-right x1 xm x2 y x1m xm2 x12 =
begin
y * diff xm x1 + y * diff x2 xm
=⟨ cong2 _+_ (mul-comm y (diff xm x1)) (mul-comm y (diff x2 xm)) ⟩
diff xm x1 * y + diff x2 xm * y
=⟨ line-split-left x1 xm x2 y x1m xm2 x12 ⟩
diff x2 x1 * y
=⟨ mul-comm (diff x2 x1) y ⟩
y * diff x2 x1
end
square-split : (x1 y1 xm ym x2 y2 : Nat) -> IsTrue (x1 <= xm) -> IsTrue (xm <= x2) -> IsTrue (y1 <= ym) -> IsTrue (ym <= y2)
-> diff xm x1 * diff ym y1 + diff x2 xm * diff ym y1 + diff xm x1 * diff y2 ym + diff x2 xm * diff y2 ym ≡ diff x2 x1 * diff y2 y1
square-split x1 y1 xm ym x2 y2 x1m xm2 y1m ym2 =
begin
diff xm x1 * diff ym y1 + diff x2 xm * diff ym y1 + diff xm x1 * diff y2 ym + diff x2 xm * diff y2 ym
=⟨ add-assoc ((diff xm x1 * diff ym y1) + (diff x2 xm * diff ym y1)) (diff xm x1 * diff y2 ym) (diff x2 xm * diff y2 ym) ⟩
(diff xm x1 * diff ym y1 + diff x2 xm * diff ym y1) + (diff xm x1 * diff y2 ym + diff x2 xm * diff y2 ym)
=⟨ cong2 _+_
(line-split-left x1 xm x2 (diff ym y1) x1m xm2 (lteTransitive x1 xm x2 x1m xm2))
(line-split-left x1 xm x2 (diff y2 ym) x1m xm2 (lteTransitive x1 xm x2 x1m xm2)) ⟩
(diff x2 x1 * diff ym y1) + (diff x2 x1 * diff y2 ym)
=⟨ line-split-right y1 ym y2 (diff x2 x1) y1m ym2 (lteTransitive y1 ym y2 y1m ym2) ⟩
diff x2 x1 * diff y2 y1
end
min-comb : (a b c : Nat) -> IsTrue (a <= b) -> IsTrue (a <= c) -> IsTrue (a <= min b c)
min-comb a b c ab ac = useEq (sym $
begin
a <= min b c
=⟨ sym $ propFnIf {c = c < b} (_<=_ a) ⟩
(if _ then a <= c else a <= b)
=⟨ cong2 (if_then_else_ _) (isTrueToEquiv ac) (isTrueToEquiv ab) ⟩
(if _ then true else true)
=⟨ propIfBranchesSame true ⟩
true
end) IsTrue.itsTrue
min-rel-1 : (x1 mid x2 : Nat) -> IsTrue (x1 <= x2) -> IsTrue (x1 <= min x2 (mid + x1))
min-rel-1 x1 mid x2 x12 = min-comb x1 x2 (mid + x1) x12 (lteSumOne x1 x1 mid (lteSelf x1))
min-rel-2 : (a b : Nat) -> IsTrue (min a b <= a)
min-rel-2 a b = useEq (sym $
begin
min a b <= a
=⟨ sym (propFnIf (λ z → (z <= a))) ⟩
(if b < a then b <= a else a <= a)
=⟨ ifTrueMap {c = b < a} (λ c -> isTrueToEquiv (orFst c)) ⟩
(if b < a then true else a <= a)
=⟨ cong (if_then_else_ (b < a) true) (isTrueToEquiv (lteSelf a)) ⟩
(if b < a then true else true)
=⟨ propIfBranchesSame true ⟩
true
end) IsTrue.itsTrue
length-tilesQd : {t : Set} {{eqT : Eq t}} {dep : Nat} -> (vqd : VQuadrant t {dep})
-> (x1 y1 x2 y2 : Nat) -> IsTrue (x1 <= x2) -> IsTrue (y1 <= y2)
-> sum (map lengthₙ (map expand (tilesQd dep vqd (RegionC (x1 , y1) (x2 , y2))))) ≡ diff x2 x1 * diff y2 y1
length-tilesQd {t} {dep = dep} (CVQuadrant (Leaf v) {p}) x1 y1 x2 y2 _ _ =
begin
sum (map lengthₙ (map expand (tilesQd dep (CVQuadrant (Leaf v) {p}) (RegionC (x1 , y1) (x2 , y2)))))
=⟨⟩
lengthₙ (replicateₙ (diff x2 x1 * diff y2 y1) v) + 0
=⟨ add-comm _ 0 ⟩
lengthₙ (replicateₙ (diff x2 x1 * diff y2 y1) v)
=⟨ length-replicateₙ (diff x2 x1 * diff y2 y1) v ⟩
diff x2 x1 * diff y2 y1
end
length-tilesQd {dep = S dep} (CVQuadrant (Node a b c d) {p}) x1 y1 x2 y2 xp yp =
begin
sum (map lengthₙ (map expand (tilesQd (S dep) (CVQuadrant (Node a b c d) {p}) (RegionC (x1 , y1) (x2 , y2)))))
=⟨⟩
sum (map lengthₙ (map expand (ca ++ cb ++ cc ++ cd)))
=⟨ cong (λ q -> sum (map lengthₙ q)) (map-concat4 ca cb cc cd expand) ⟩
sum (map lengthₙ (map expand ca ++ map expand cb ++ map expand cc ++ map expand cd))
=⟨ cong sum (map-concat4 (map expand ca) (map expand cb) (map expand cc) (map expand cd) lengthₙ) ⟩
sum (map lengthₙ (map expand ca) ++ map lengthₙ (map expand cb) ++ map lengthₙ (map expand cc) ++ map lengthₙ (map expand cd))
=⟨ sum-concat4 (map lengthₙ (map expand ca)) (map lengthₙ (map expand cb)) (map lengthₙ (map expand cc)) (map lengthₙ (map expand cd)) ⟩
sum (map lengthₙ (map expand ca)) + sum (map lengthₙ (map expand cb)) + sum (map lengthₙ (map expand cc)) + sum (map lengthₙ (map expand cd))
=⟨ cong4 (λ a b c d -> a + b + c + d)
(length-tilesQd (CVQuadrant a) x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp))
(length-tilesQd (CVQuadrant b) (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp))
(length-tilesQd (CVQuadrant c) x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)))
(length-tilesQd (CVQuadrant d) (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1))) ⟩
diff (min x2 (mid + x1)) x1 * diff (min y2 (mid + y1)) y1
+ diff x2 (min x2 (mid + x1)) * diff (min y2 (mid + y1)) y1
+ diff (min x2 (mid + x1)) x1 * diff y2 (min y2 (mid + y1))
+ diff x2 (min x2 (mid + x1)) * diff y2 (min y2 (mid + y1))
=⟨ square-split x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) (min-rel-2 y2 (mid + y1)) ⟩
diff x2 x1 * diff y2 y1
end where
mid = pow 2 dep
ca = tilesQd dep (CVQuadrant a) (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)) )
cb = tilesQd dep (CVQuadrant b) (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)) )
cc = tilesQd dep (CVQuadrant c) (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )
cd = tilesQd dep (CVQuadrant d) (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )
proof-length : {t : Set} {{eqT : Eq t}} {dep : Nat} -> (vqt : VQuadTree t {dep}) -> lengthₑ (quadtreeFoldable dep) vqt ≡ size vqt
proof-length {t} ⦃ eqT ⦄ {dep} vqt@(CVQuadTree (Wrapper (w , h) qd) {p1} {p2}) =
begin
lengthₑ (quadtreeFoldable dep) vqt
=⟨⟩
lengthₙ (concat (map expand (tilesQd dep (CVQuadrant qd {p1}) (RegionC (0 , 0) (w , h)))))
=⟨ length-concat (map expand (tilesQd dep (CVQuadrant qd {p1}) (RegionC (0 , 0) (w , h)))) ⟩
sum (map lengthₙ (map expand (tilesQd dep (CVQuadrant qd {p1}) (RegionC (0 , 0) (w , h)))))
=⟨ length-tilesQd {dep = dep} (CVQuadrant qd {p1}) 0 0 w h (zeroLteAny w) (zeroLteAny h) ⟩
w * h
end | {
"alphanum_fraction": 0.5472388556,
"avg_line_length": 45.7186311787,
"ext": "agda",
"hexsha": "7ebae150040dc43fd393d85d2fd894e159f27497",
"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": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "JonathanBrouwer/research-project",
"max_forks_repo_path": "src/Data/QuadTree/FoldableProofs/FoldableProof.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "JonathanBrouwer/research-project",
"max_issues_repo_path": "src/Data/QuadTree/FoldableProofs/FoldableProof.agda",
"max_line_length": 175,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "JonathanBrouwer/research-project",
"max_stars_repo_path": "src/Data/QuadTree/FoldableProofs/FoldableProof.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z",
"num_tokens": 4883,
"size": 12024
} |
open import Nat
open import Prelude
open import List
open import contexts
open import core
-- This file is a glorious testament to all of agda's greatest strengths -
-- a beautiful work that will shine brightly throughout the ages and instill
-- hope for the future in many generations to come. May I never use any other
-- proof assistant.
module decidability where
mutual
-- We define context decidability in contexts.agda,
-- because it's an important metatheorem. However, it accepts a
-- decidability theorem for its value type, and for environments that
-- value type is result, so the termination checker complains. To fix
-- this, we redefine type-specific versions of this theorem here.
-- Note that we really should not be destructing contexts via `_::_` -
-- here we only do that because we copied this code from the contexts file.
ctx<result>-==-dec : (Γ1 Γ2 : result ctx) →
Γ1 == Γ2 ∨ Γ1 ≠ Γ2
ctx<result>-==-dec [] [] = Inl refl
ctx<result>-==-dec [] (_ :: _) = Inr (λ ())
ctx<result>-==-dec (_ :: _) [] = Inr (λ ())
ctx<result>-==-dec ((hx1 , hr1) :: t1) ((hx2 , hr2) :: t2)
with natEQ hx1 hx2 | result-==-dec hr1 hr2 | ctx<result>-==-dec t1 t2
... | Inl refl | Inl refl | Inl refl = Inl refl
... | Inl refl | Inl refl | Inr ne = Inr λ where refl → ne refl
... | Inl refl | Inr ne | _ = Inr λ where refl → ne refl
... | Inr ne | _ | _ = Inr λ where refl → ne refl
ctx<rule>-==-dec : (rules1 rules2 : rule ctx) →
rules1 == rules2 ∨ rules1 ≠ rules2
ctx<rule>-==-dec [] [] = Inl refl
ctx<rule>-==-dec [] (_ :: _) = Inr (λ ())
ctx<rule>-==-dec (_ :: _) [] = Inr (λ ())
ctx<rule>-==-dec ((hx1 , hrule1) :: t1) ((hx2 , hrule2) :: t2)
with natEQ hx1 hx2 | rule-==-dec hrule1 hrule2 | ctx<rule>-==-dec t1 t2
... | Inl refl | Inl refl | Inl refl = Inl refl
... | Inl refl | Inl refl | Inr ne = Inr λ where refl → ne refl
... | Inl refl | Inr ne | _ = Inr λ where refl → ne refl
... | Inr ne | _ | _ = Inr λ where refl → ne refl
rule-==-dec : (rule1 rule2 : rule) →
rule1 == rule2 ∨ rule1 ≠ rule2
rule-==-dec (|C parm1 => branch1) (|C parm2 => branch2)
with natEQ parm1 parm2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with exp-==-dec branch1 branch2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
ex-==-dec : (ex1 ex2 : ex) →
ex1 == ex2 ∨ ex1 ≠ ex2
ex-==-dec ⟨⟩ ⟨⟩ = Inl refl
ex-==-dec ⟨⟩ ⟨ ex2 , ex3 ⟩ = Inr (λ ())
ex-==-dec ⟨⟩ (C[ x ] ex2) = Inr (λ ())
ex-==-dec ⟨⟩ ¿¿ = Inr (λ ())
ex-==-dec ⟨⟩ (x ↦ ex2) = Inr (λ ())
ex-==-dec ⟨ ex1a , ex1b ⟩ ⟨ ex2a , ex2b ⟩
with ex-==-dec ex1a ex2a
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with ex-==-dec ex1b ex2b
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
ex-==-dec ⟨ ex1 , ex2 ⟩ ⟨⟩ = Inr (λ ())
ex-==-dec ⟨ _ , _ ⟩ (C[ _ ] _) = Inr (λ ())
ex-==-dec ⟨ ex1 , ex2 ⟩ ¿¿ = Inr (λ ())
ex-==-dec ⟨ ex1 , ex2 ⟩ (x ↦ ex3) = Inr (λ ())
ex-==-dec (C[ c1 ] ex1) (C[ c2 ] ex2)
with natEQ c1 c2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with ex-==-dec ex1 ex2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
ex-==-dec (C[ x ] ex1) ⟨⟩ = Inr (λ ())
ex-==-dec (C[ _ ] _) ⟨ _ , _ ⟩ = Inr (λ ())
ex-==-dec (C[ x ] ex1) ¿¿ = Inr (λ ())
ex-==-dec (C[ x ] ex1) (x₁ ↦ ex2) = Inr (λ ())
ex-==-dec ¿¿ ¿¿ = Inl refl
ex-==-dec ¿¿ ⟨⟩ = Inr (λ ())
ex-==-dec ¿¿ ⟨ ex2 , ex3 ⟩ = Inr (λ ())
ex-==-dec ¿¿ (C[ x ] ex2) = Inr (λ ())
ex-==-dec ¿¿ (x ↦ ex2) = Inr (λ ())
ex-==-dec (v1 ↦ ex1) (v2 ↦ ex2)
with result-==-dec v1 v2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with ex-==-dec ex1 ex2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
ex-==-dec (x ↦ ex1) ⟨⟩ = Inr (λ ())
ex-==-dec (x ↦ ex1) ⟨ ex2 , ex3 ⟩ = Inr (λ ())
ex-==-dec (x ↦ ex1) (C[ x₁ ] ex2) = Inr (λ ())
ex-==-dec (x ↦ ex1) ¿¿ = Inr (λ ())
exp-==-dec : (e1 e2 : exp) → e1 == e2 ∨ e1 ≠ e2
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ fix f2 ⦇·λ x2 => e2 ·⦈
with natEQ f1 f2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with natEQ x1 x2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with exp-==-dec e1 e2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ X[ x ] = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ (e2 ∘ e3) = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ ⟨⟩ = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ ⟨ _ , _ ⟩ = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ (fst _) = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ (snd _) = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ (C[ x ] e2) = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ ??[ x ] = Inr (λ ())
exp-==-dec fix f1 ⦇·λ x1 => e1 ·⦈ (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec X[ x1 ] X[ x2 ]
with natEQ x1 x2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec X[ x1 ] fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec X[ x1 ] (e2 ∘ e3) = Inr (λ ())
exp-==-dec X[ x1 ] ⟨⟩ = Inr (λ ())
exp-==-dec X[ x1 ] ⟨ _ , _ ⟩ = Inr (λ ())
exp-==-dec X[ x1 ] (fst _) = Inr (λ ())
exp-==-dec X[ x1 ] (snd _) = Inr (λ ())
exp-==-dec X[ x1 ] (C[ x ] e2) = Inr (λ ())
exp-==-dec X[ x1 ] case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec X[ x1 ] ??[ x ] = Inr (λ ())
exp-==-dec X[ x1 ] (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) (ef2 ∘ earg2)
with exp-==-dec ef1 ef2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with exp-==-dec earg1 earg2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec (ef1 ∘ earg1) fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) X[ x ] = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) ⟨⟩ = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) ⟨ _ , _ ⟩ = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) (fst _) = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) (snd _) = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) (C[ x ] e2) = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) ??[ x ] = Inr (λ ())
exp-==-dec (ef1 ∘ earg1) (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec ⟨⟩ ⟨⟩ = Inl refl
exp-==-dec ⟨⟩ fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec ⟨⟩ X[ x ] = Inr (λ ())
exp-==-dec ⟨⟩ (e2 ∘ e3) = Inr (λ ())
exp-==-dec ⟨⟩ ⟨ e2 , e3 ⟩ = Inr (λ ())
exp-==-dec ⟨⟩ (fst e2) = Inr (λ ())
exp-==-dec ⟨⟩ (snd e2) = Inr (λ ())
exp-==-dec ⟨⟩ (C[ x ] e2) = Inr (λ ())
exp-==-dec ⟨⟩ case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec ⟨⟩ ??[ x ] = Inr (λ ())
exp-==-dec ⟨⟩ (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec ⟨ es1a , es1b ⟩ ⟨ es2a , es2b ⟩
with exp-==-dec es1a es2a
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with exp-==-dec es1b es2b
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec ⟨ _ , _ ⟩ fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ X[ x ] = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ (e2 ∘ e3) = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ ⟨⟩ = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ (fst _) = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ (snd _) = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ (C[ x ] e2) = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ ??[ x ] = Inr (λ ())
exp-==-dec ⟨ _ , _ ⟩ (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec (fst e1) (fst e2)
with exp-==-dec e1 e2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec (fst e1) fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec (fst e1) X[ x ] = Inr (λ ())
exp-==-dec (fst e1) (e2 ∘ e3) = Inr (λ ())
exp-==-dec (fst e1) ⟨⟩ = Inr (λ ())
exp-==-dec (fst e1) ⟨ e2 , e3 ⟩ = Inr (λ ())
exp-==-dec (fst e1) (snd e2) = Inr (λ ())
exp-==-dec (fst e1) (C[ x ] e2) = Inr (λ ())
exp-==-dec (fst e1) case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec (fst e1) ??[ x ] = Inr (λ ())
exp-==-dec (fst e1) (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec (snd e1) (snd e2)
with exp-==-dec e1 e2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec (snd e1) fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec (snd e1) X[ x ] = Inr (λ ())
exp-==-dec (snd e1) (e2 ∘ e3) = Inr (λ ())
exp-==-dec (snd e1) ⟨⟩ = Inr (λ ())
exp-==-dec (snd e1) ⟨ e2 , e3 ⟩ = Inr (λ ())
exp-==-dec (snd e1) (fst e2) = Inr (λ ())
exp-==-dec (snd e1) (C[ x ] e2) = Inr (λ ())
exp-==-dec (snd e1) case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec (snd e1) ??[ x ] = Inr (λ ())
exp-==-dec (snd e1) (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec (C[ c1 ] e1) (C[ c2 ] e2)
with natEQ c1 c2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with exp-==-dec e1 e2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec (C[ c1 ] e1) fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec (C[ c1 ] e1) X[ x ] = Inr (λ ())
exp-==-dec (C[ c1 ] e1) (e2 ∘ e3) = Inr (λ ())
exp-==-dec (C[ c1 ] e1) ⟨⟩ = Inr (λ ())
exp-==-dec (C[ c1 ] e1) ⟨ _ , _ ⟩ = Inr (λ ())
exp-==-dec (C[ c1 ] e1) (fst _) = Inr (λ ())
exp-==-dec (C[ c1 ] e1) (snd _) = Inr (λ ())
exp-==-dec (C[ c1 ] e1) case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec (C[ c1 ] e1) ??[ x ] = Inr (λ ())
exp-==-dec (C[ c1 ] e1) (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ case e2 of⦃· rules2 ·⦄
with exp-==-dec e1 e2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with ctx<rule>-==-dec rules1 rules2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec case e1 of⦃· rules1 ·⦄ fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ X[ x ] = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ (e2 ∘ e3) = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ ⟨⟩ = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ ⟨ _ , _ ⟩ = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ (fst _) = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ (snd _) = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ (C[ x ] e2) = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ ??[ x ] = Inr (λ ())
exp-==-dec case e1 of⦃· rules1 ·⦄ (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec ??[ u1 ] ??[ u2 ]
with natEQ u1 u2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec ??[ u1 ] fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec ??[ u1 ] X[ x ] = Inr (λ ())
exp-==-dec ??[ u1 ] (e2 ∘ e3) = Inr (λ ())
exp-==-dec ??[ u1 ] ⟨⟩ = Inr (λ ())
exp-==-dec ??[ u1 ] ⟨ _ , _ ⟩ = Inr (λ ())
exp-==-dec ??[ u1 ] (fst _) = Inr (λ ())
exp-==-dec ??[ u1 ] (snd _) = Inr (λ ())
exp-==-dec ??[ u1 ] (C[ x ] e2) = Inr (λ ())
exp-==-dec ??[ u1 ] case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec ??[ u1 ] (PBE:assert e2 e3) = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) (PBE:assert e2a e2b)
with exp-==-dec e1a e2a
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl
with exp-==-dec e1b e2b
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
exp-==-dec (PBE:assert e1a e1b) fix x ⦇·λ x₁ => e2 ·⦈ = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) X[ x ] = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) (e2 ∘ e3) = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) ⟨⟩ = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) ⟨ _ , _ ⟩ = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) (fst _) = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) (snd _) = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) (C[ x ] e2) = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) case e2 of⦃· x ·⦄ = Inr (λ ())
exp-==-dec (PBE:assert e1a e1b) ??[ x ] = Inr (λ ())
result-==-dec : (r1 r2 : result) → r1 == r2 ∨ r1 ≠ r2
result-==-dec [ E1 ]fix f1 ⦇·λ x1 => e1 ·⦈ [ E2 ]fix f2 ⦇·λ x2 => e2 ·⦈
with ctx<result>-==-dec E1 E2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with natEQ f1 f2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with natEQ x1 x2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with exp-==-dec e1 e2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
result-==-dec [ E ]fix f ⦇·λ x => e ·⦈ ⟨⟩ = Inr (λ ())
result-==-dec [ E ]fix f ⦇·λ x => e ·⦈ ⟨ _ , _ ⟩ = Inr (λ ())
result-==-dec [ E ]fix f ⦇·λ x => e ·⦈ (C[ _ ] _) = Inr (λ ())
result-==-dec [ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ (C⁻[ x₄ ] r2) = Inr (λ ())
result-==-dec [ E ]fix f ⦇·λ x => e ·⦈ [ _ ]??[ _ ] = Inr (λ ())
result-==-dec [ E ]fix f ⦇·λ x => e ·⦈ (_ ∘ _) = Inr (λ ())
result-==-dec [ E ]fix f ⦇·λ x => e ·⦈ (fst _) = Inr (λ ())
result-==-dec [ E ]fix f ⦇·λ x => e ·⦈ (snd _) = Inr (λ ())
result-==-dec [ E ]fix f ⦇·λ x => e ·⦈ [ _ ]case _ of⦃· _ ·⦄ = Inr (λ ())
result-==-dec ⟨⟩ ⟨⟩ = Inl refl
result-==-dec ⟨⟩ [ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ = Inr (λ ())
result-==-dec ⟨⟩ ⟨ r2 , r3 ⟩ = Inr (λ ())
result-==-dec ⟨⟩ (C[ x ] r2) = Inr (λ ())
result-==-dec ⟨⟩ (C⁻[ x ] r2) = Inr (λ ())
result-==-dec ⟨⟩ [ x ]??[ x₁ ] = Inr (λ ())
result-==-dec ⟨⟩ (r2 ∘ r3) = Inr (λ ())
result-==-dec ⟨⟩ (fst r2) = Inr (λ ())
result-==-dec ⟨⟩ (snd r2) = Inr (λ ())
result-==-dec ⟨⟩ [ x ]case r2 of⦃· x₁ ·⦄ = Inr (λ ())
result-==-dec ⟨ rs1a , rs1b ⟩ ⟨ rs2a , rs2b ⟩
with result-==-dec rs1a rs2a
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with result-==-dec rs1b rs2b
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
result-==-dec ⟨ _ , _ ⟩ [ _ ]fix _ ⦇·λ _ => _ ·⦈ = Inr (λ ())
result-==-dec ⟨ _ , _ ⟩ ⟨⟩ = Inr (λ ())
result-==-dec ⟨ _ , _ ⟩ (C[ _ ] _) = Inr (λ ())
result-==-dec ⟨ _ , _ ⟩ (C⁻[ x ] r3) = Inr (λ ())
result-==-dec ⟨ _ , _ ⟩ [ _ ]??[ _ ] = Inr (λ ())
result-==-dec ⟨ _ , _ ⟩ (_ ∘ _) = Inr (λ ())
result-==-dec ⟨ _ , _ ⟩ (snd _) = Inr (λ ())
result-==-dec ⟨ _ , _ ⟩ (fst _) = Inr (λ ())
result-==-dec ⟨ _ , _ ⟩ [ _ ]case _ of⦃· _ ·⦄ = Inr (λ ())
result-==-dec (C[ c1 ] r1) (C[ c2 ] r2)
with natEQ c1 c2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with result-==-dec r1 r2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
result-==-dec (C[ c ] r) [ _ ]fix _ ⦇·λ _ => _ ·⦈ = Inr (λ ())
result-==-dec (C[ c ] r) ⟨⟩ = Inr (λ ())
result-==-dec (C[ c ] r) ⟨ _ , _ ⟩ = Inr (λ ())
result-==-dec (C[ x ] r1) (C⁻[ x₁ ] r2) = Inr (λ ())
result-==-dec (C[ c ] r) [ _ ]??[ _ ] = Inr (λ ())
result-==-dec (C[ c ] r) (_ ∘ _) = Inr (λ ())
result-==-dec (C[ c ] r) (fst _) = Inr (λ ())
result-==-dec (C[ c ] r) (snd _) = Inr (λ ())
result-==-dec (C[ c ] r) [ _ ]case _ of⦃· _ ·⦄ = Inr (λ ())
result-==-dec (C⁻[ c1 ] r1) (C⁻[ c2 ] r2)
with natEQ c1 c2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with result-==-dec r1 r2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
result-==-dec (C⁻[ x ] r1) [ x₁ ]fix x₂ ⦇·λ x₃ => x₄ ·⦈ = Inr (λ ())
result-==-dec (C⁻[ x ] r1) ⟨⟩ = Inr (λ ())
result-==-dec (C⁻[ x ] r1) ⟨ r2 , r3 ⟩ = Inr (λ ())
result-==-dec (C⁻[ x ] r1) (C[ x₁ ] r2) = Inr (λ ())
result-==-dec (C⁻[ x ] r1) [ x₁ ]??[ x₂ ] = Inr (λ ())
result-==-dec (C⁻[ x ] r1) (r2 ∘ r3) = Inr (λ ())
result-==-dec (C⁻[ x ] r1) (fst r2) = Inr (λ ())
result-==-dec (C⁻[ x ] r1) (snd r2) = Inr (λ ())
result-==-dec (C⁻[ x ] r1) [ x₁ ]case r2 of⦃· x₂ ·⦄ = Inr (λ ())
result-==-dec [ E1 ]??[ u1 ] [ E2 ]??[ u2 ]
with ctx<result>-==-dec E1 E2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with natEQ u1 u2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
result-==-dec [ E ]??[ u1 ] [ _ ]fix _ ⦇·λ _ => _ ·⦈ = Inr (λ ())
result-==-dec [ E ]??[ u1 ] ⟨⟩ = Inr (λ ())
result-==-dec [ E ]??[ u1 ] ⟨ _ , _ ⟩ = Inr (λ ())
result-==-dec [ E ]??[ u1 ] (C[ _ ] _) = Inr (λ ())
result-==-dec [ x ]??[ x₁ ] (C⁻[ x₂ ] r2) = Inr (λ ())
result-==-dec [ E ]??[ u1 ] (_ ∘ _) = Inr (λ ())
result-==-dec [ E ]??[ u1 ] (fst _) = Inr (λ ())
result-==-dec [ E ]??[ u1 ] (snd _) = Inr (λ ())
result-==-dec [ E ]??[ u1 ] [ _ ]case _ of⦃· _ ·⦄ = Inr (λ ())
result-==-dec (rf1 ∘ rarg1) (rf2 ∘ rarg2)
with result-==-dec rf1 rf2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with result-==-dec rarg1 rarg2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
result-==-dec (rf ∘ rarg) [ _ ]fix _ ⦇·λ _ => _ ·⦈ = Inr (λ ())
result-==-dec (rf ∘ rarg) ⟨⟩ = Inr (λ ())
result-==-dec (rf ∘ rarg) ⟨ _ , _ ⟩ = Inr (λ ())
result-==-dec (rf ∘ rarg) (C[ _ ] _) = Inr (λ ())
result-==-dec (r1 ∘ r2) (C⁻[ x ] r3) = Inr (λ ())
result-==-dec (rf ∘ rarg) [ _ ]??[ _ ] = Inr (λ ())
result-==-dec (rf ∘ rarg) (fst _) = Inr (λ ())
result-==-dec (rf ∘ rarg) (snd _) = Inr (λ ())
result-==-dec (rf ∘ rarg) [ _ ]case _ of⦃· _ ·⦄ = Inr (λ ())
result-==-dec (fst r1) (fst r2)
with result-==-dec r1 r2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
result-==-dec (fst r1) [ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ = Inr (λ ())
result-==-dec (fst r1) ⟨⟩ = Inr (λ ())
result-==-dec (fst r1) ⟨ r2 , r3 ⟩ = Inr (λ ())
result-==-dec (fst r1) (C[ x ] r2) = Inr (λ ())
result-==-dec (fst r1) (C⁻[ x ] r2) = Inr (λ ())
result-==-dec (fst r1) [ x ]??[ x₁ ] = Inr (λ ())
result-==-dec (fst r1) (r2 ∘ r3) = Inr (λ ())
result-==-dec (fst r1) (snd r2) = Inr (λ ())
result-==-dec (fst r1) [ x ]case r2 of⦃· x₁ ·⦄ = Inr (λ ())
result-==-dec (snd r1) (snd r2)
with result-==-dec r1 r2
... | Inr ne = Inr (λ where refl → ne refl)
... | Inl refl = Inl refl
result-==-dec (snd r1) [ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ = Inr (λ ())
result-==-dec (snd r1) ⟨⟩ = Inr (λ ())
result-==-dec (snd r1) ⟨ r2 , r3 ⟩ = Inr (λ ())
result-==-dec (snd r1) (C[ x ] r2) = Inr (λ ())
result-==-dec (snd r1) (C⁻[ x ] r2) = Inr (λ ())
result-==-dec (snd r1) [ x ]??[ x₁ ] = Inr (λ ())
result-==-dec (snd r1) (r2 ∘ r3) = Inr (λ ())
result-==-dec (snd r1) (fst r2) = Inr (λ ())
result-==-dec (snd r1) [ x ]case r2 of⦃· x₁ ·⦄ = Inr (λ ())
result-==-dec [ E1 ]case r1 of⦃· rules1 ·⦄ [ E2 ]case r2 of⦃· rules2 ·⦄
with ctx<result>-==-dec E1 E2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with result-==-dec r1 r2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with ctx<rule>-==-dec rules1 rules2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
result-==-dec [ E ]case r of⦃· rules ·⦄ [ _ ]fix _ ⦇·λ _ => _ ·⦈ = Inr (λ ())
result-==-dec [ E ]case r of⦃· rules ·⦄ ⟨⟩ = Inr (λ ())
result-==-dec [ E ]case r of⦃· rules ·⦄ ⟨ _ , _ ⟩ = Inr (λ ())
result-==-dec [ E ]case r of⦃· rules ·⦄ (C[ _ ] _) = Inr (λ ())
result-==-dec [ E ]case r of⦃· rules ·⦄ [ _ ]??[ _ ] = Inr (λ ())
result-==-dec [ E ]case r of⦃· rules ·⦄ (_ ∘ _) = Inr (λ ())
result-==-dec [ E ]case r of⦃· rules ·⦄ (fst _) = Inr (λ ())
result-==-dec [ E ]case r of⦃· rules ·⦄ (snd _) = Inr (λ ())
result-==-dec [ x ]case r1 of⦃· x₁ ·⦄ (C⁻[ x₂ ] r2) = Inr (λ ())
typ-==-dec : (τ1 τ2 : typ) → τ1 == τ2 ∨ τ1 ≠ τ2
typ-==-dec (τ1i ==> τ1o) (τ2i ==> τ2o)
with typ-==-dec τ1i τ2i
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with typ-==-dec τ1o τ2o
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
typ-==-dec (τ1i ==> τ1o) ⟨⟩ = Inr (λ ())
typ-==-dec (τ1i ==> τ1o) ⟨ _ × _ ⟩ = Inr (λ ())
typ-==-dec (τ1i ==> τ1o) D[ _ ] = Inr (λ ())
typ-==-dec ⟨⟩ ⟨⟩ = Inl refl
typ-==-dec ⟨⟩ ⟨ τ2 × τ3 ⟩ = Inr (λ ())
typ-==-dec ⟨⟩ (_ ==> _) = Inr (λ ())
typ-==-dec ⟨⟩ D[ _ ] = Inr (λ ())
typ-==-dec ⟨ τ1a × τ1b ⟩ ⟨ τ2a × τ2b ⟩
with typ-==-dec τ1a τ2a
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl
with typ-==-dec τ1b τ2b
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
typ-==-dec ⟨ τ1 × τ2 ⟩ ⟨⟩ = Inr (λ ())
typ-==-dec ⟨ _ × _ ⟩ (_ ==> _) = Inr (λ ())
typ-==-dec ⟨ _ × _ ⟩ D[ _ ] = Inr (λ ())
typ-==-dec D[ d1 ] D[ d2 ]
with natEQ d1 d2
... | Inr ne = Inr λ where refl → ne refl
... | Inl refl = Inl refl
typ-==-dec D[ _ ] (_ ==> _) = Inr (λ ())
typ-==-dec D[ _ ] ⟨⟩ = Inr (λ ())
typ-==-dec D[ _ ] ⟨ _ × _ ⟩ = Inr (λ ())
final-dec : ∀{r} → r final ∨ (r final → ⊥)
env-final-dec : ∀{E} → E env-final ∨ (E env-final → ⊥)
final-dec {[ E ]fix x₁ ⦇·λ x₂ => e ·⦈}
with env-final-dec {E}
... | Inr nf = Inr (λ {(FFix f) → nf f})
... | Inl E-f = Inl (FFix E-f)
final-dec {⟨⟩} = Inl FUnit
final-dec {⟨ r1 , r2 ⟩}
with final-dec {r1}
... | Inr nf = Inr λ {(FPair h1 h2) → nf h1}
... | Inl r1-f
with final-dec {r2}
... | Inr nf = Inr λ {(FPair h1 h2) → nf h2}
... | Inl r2-f = Inl (FPair r1-f r2-f)
final-dec {C[ x ] r}
with final-dec {r}
... | Inr nf = Inr λ {(FCon h1) → nf h1}
... | Inl r-f = Inl (FCon r-f)
final-dec {C⁻[ x ] r} = Inr (λ ())
final-dec {[ E ]??[ x₁ ]}
with env-final-dec {E}
... | Inr nf = Inr λ {(FHole h1) → nf h1}
... | Inl E-f = Inl (FHole E-f)
final-dec {r1 ∘ r2}
with final-dec {r1}
... | Inr nf = Inr λ {(FAp h _ _) → nf h}
... | Inl r1-f
with final-dec {r2}
... | Inr nf = Inr λ {(FAp _ h _) → nf h}
final-dec {[ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ ∘ r2} | Inl r1-f | Inl r2-f
= Inr λ {(FAp _ _ h) → abort (h refl)}
final-dec {⟨⟩ ∘ r2} | Inl r1-f | Inl r2-f = Inl (FAp r1-f r2-f (λ {E} {f} {x} {e} ()))
final-dec {⟨ r1 , r3 ⟩ ∘ r2} | Inl r1-f | Inl r2-f = Inl (FAp r1-f r2-f (λ {E} {f} {x} {e} ()))
final-dec {(C[ x ] r1) ∘ r2} | Inl r1-f | Inl r2-f = Inl (FAp r1-f r2-f (λ {E} {f} {x} {e} ()))
final-dec {[ x ]??[ x₁ ] ∘ r2} | Inl r1-f | Inl r2-f = Inl (FAp r1-f r2-f (λ {E} {f} {x} {e} ()))
final-dec {(r1 ∘ r3) ∘ r2} | Inl r1-f | Inl r2-f = Inl (FAp r1-f r2-f (λ {E} {f} {x} {e} ()))
final-dec {fst r1 ∘ r2} | Inl r1-f | Inl r2-f = Inl (FAp r1-f r2-f (λ {E} {f} {x} {e} ()))
final-dec {snd r1 ∘ r2} | Inl r1-f | Inl r2-f = Inl (FAp r1-f r2-f (λ {E} {f} {x} {e} ()))
final-dec {[ x ]case r1 of⦃· x₁ ·⦄ ∘ r2} | Inl r1-f | Inl r2-f = Inl (FAp r1-f r2-f (λ {E} {f} {x} {e} ()))
final-dec {fst r}
with final-dec {r}
... | Inr nf = Inr λ {(FFst h _) → nf h}
final-dec {fst ⟨ r , r₁ ⟩} | Inl r-f
= Inr λ {(FFst _ h) → abort (h refl)}
final-dec {fst [ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈} | Inl r-f = Inl (FFst r-f (λ {r1} {r2} ()))
final-dec {fst ⟨⟩} | Inl r-f = Inl (FFst r-f (λ {r1} {r2} ()))
final-dec {fst (C[ x ] r)} | Inl r-f = Inl (FFst r-f (λ {r1} {r2} ()))
final-dec {fst [ x ]??[ x₁ ]} | Inl r-f = Inl (FFst r-f (λ {r1} {r2} ()))
final-dec {fst (r ∘ r₁)} | Inl r-f = Inl (FFst r-f (λ {r1} {r2} ()))
final-dec {fst (fst r)} | Inl r-f = Inl (FFst r-f (λ {r1} {r2} ()))
final-dec {fst (snd r)} | Inl r-f = Inl (FFst r-f (λ {r1} {r2} ()))
final-dec {fst [ x ]case r of⦃· x₁ ·⦄} | Inl r-f = Inl (FFst r-f (λ {r1} {r2} ()))
final-dec {snd r}
with final-dec {r}
... | Inr nf = Inr λ {(FSnd h _) → nf h}
final-dec {snd ⟨ r , r₁ ⟩} | Inl r-f
= Inr λ {(FSnd _ h) → abort (h refl)}
final-dec {snd [ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈} | Inl r-f = Inl (FSnd r-f (λ {r1} {r2} ()))
final-dec {snd ⟨⟩} | Inl r-f = Inl (FSnd r-f (λ {r1} {r2} ()))
final-dec {snd (C[ x ] r)} | Inl r-f = Inl (FSnd r-f (λ {r1} {r2} ()))
final-dec {snd [ x ]??[ x₁ ]} | Inl r-f = Inl (FSnd r-f (λ {r1} {r2} ()))
final-dec {snd (r ∘ r₁)} | Inl r-f = Inl (FSnd r-f (λ {r1} {r2} ()))
final-dec {snd (fst r)} | Inl r-f = Inl (FSnd r-f (λ {r1} {r2} ()))
final-dec {snd (snd r)} | Inl r-f = Inl (FSnd r-f (λ {r1} {r2} ()))
final-dec {snd [ x ]case r of⦃· x₁ ·⦄} | Inl r-f = Inl (FSnd r-f (λ {r1} {r2} ()))
final-dec {[ E ]case r of⦃· x₁ ·⦄}
with final-dec {r}
... | Inr nf = Inr λ {(FCase h _ _) → nf h}
... | Inl r-f
with env-final-dec {E}
... | Inr nf = Inr λ {(FCase _ _ h) → nf h}
final-dec {[ E ]case C[ x ] r of⦃· x₁ ·⦄} | Inl r-f | Inl E-f
= Inr λ {(FCase _ h _) → abort (h refl)}
final-dec {[ E ]case [ x ]fix x₂ ⦇·λ x₃ => x₄ ·⦈ of⦃· x₁ ·⦄} | Inl r-f | Inl E-f = Inl (FCase r-f (λ {c} {r'} ()) E-f)
final-dec {[ E ]case ⟨⟩ of⦃· x₁ ·⦄} | Inl r-f | Inl E-f = Inl (FCase r-f (λ {c} {r'} ()) E-f)
final-dec {[ E ]case ⟨ r , r₁ ⟩ of⦃· x₁ ·⦄} | Inl r-f | Inl E-f = Inl (FCase r-f (λ {c} {r'} ()) E-f)
final-dec {[ E ]case [ x ]??[ x₂ ] of⦃· x₁ ·⦄} | Inl r-f | Inl E-f = Inl (FCase r-f (λ {c} {r'} ()) E-f)
final-dec {[ E ]case r ∘ r₁ of⦃· x₁ ·⦄} | Inl r-f | Inl E-f = Inl (FCase r-f (λ {c} {r'} ()) E-f)
final-dec {[ E ]case fst r of⦃· x₁ ·⦄} | Inl r-f | Inl E-f = Inl (FCase r-f (λ {c} {r'} ()) E-f)
final-dec {[ E ]case snd r of⦃· x₁ ·⦄} | Inl r-f | Inl E-f = Inl (FCase r-f (λ {c} {r'} ()) E-f)
final-dec {[ E ]case [ x ]case r of⦃· x₂ ·⦄ of⦃· x₁ ·⦄} | Inl r-f | Inl E-f = Inl (FCase r-f (λ {c} {r'} ()) E-f)
env-final-dec {[]} = Inl (EF (λ ()))
env-final-dec {(_ , r) :: E}
with final-dec {r}
... | Inr nf = Inr (λ {(EF h) → nf (h InH)})
... | Inl r-f
with env-final-dec {E}
... | Inr nf = Inr (λ {(EF h) → nf (EF (λ z → h (InT z)))})
... | Inl (EF E-f) = Inl (EF λ {InH → r-f ; (InT h) → E-f h})
Coerce-dec : ∀{r} → Σ[ ex ∈ ex ] (Coerce r := ex) ∨ (Σ[ ex ∈ ex ] (Coerce r := ex) → ⊥)
Coerce-dec {[ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈} = Inr (λ where (_ , ()))
Coerce-dec {⟨⟩} = Inl (⟨⟩ , CoerceUnit)
Coerce-dec {⟨ r1 , r2 ⟩}
with Coerce-dec {r1}
... | Inr nc = Inr λ {(_ , CoercePair c-r1 _) → nc (_ , c-r1)}
... | Inl (_ , c-r1)
with Coerce-dec {r2}
... | Inr nc = Inr λ {(_ , CoercePair _ c-r2) → nc (_ , c-r2)}
... | Inl (_ , c-r2) = Inl (_ , CoercePair c-r1 c-r2)
Coerce-dec {C[ c ] r}
with Coerce-dec {r}
... | Inr nc = Inr λ {(_ , CoerceCtor c-r) → nc (_ , c-r)}
... | Inl (_ , c-r) = Inl (_ , CoerceCtor c-r)
Coerce-dec {C⁻[ x ] r} = Inr (λ where (_ , ()))
Coerce-dec {[ x ]??[ x₁ ]} = Inr (λ where (_ , ()))
Coerce-dec {r ∘ r₁} = Inr (λ where (_ , ()))
Coerce-dec {fst r} = Inr (λ where (_ , ()))
Coerce-dec {snd r} = Inr (λ where (_ , ()))
Coerce-dec {[ x ]case r of⦃· x₁ ·⦄} = Inr (λ where (_ , ()))
value-dec : ∀{r} → r value ∨ (r value → ⊥)
value-dec {[ E ]fix x₁ ⦇·λ x₂ => x₃ ·⦈}
with env-final-dec {E}
... | Inr nf = Inr (λ {(VFix E-f) → nf E-f})
... | Inl E-f = Inl (VFix E-f)
value-dec {⟨⟩} = Inl VUnit
value-dec {⟨ r1 , r2 ⟩}
with value-dec {r1}
... | Inr nv = Inr λ {(VPair h _) → nv h}
... | Inl r1v
with value-dec {r2}
... | Inr nv = Inr λ {(VPair _ h) → nv h}
... | Inl r2v = Inl (VPair r1v r2v)
value-dec {C[ x ] r}
with value-dec {r}
... | Inl rv = Inl (VCon rv)
... | Inr nv = Inr (λ {(VCon rv) → nv rv})
value-dec {C⁻[ x ] r} = Inr (λ ())
value-dec {[ x ]??[ x₁ ]} = Inr (λ ())
value-dec {r ∘ r₁} = Inr (λ ())
value-dec {fst r} = Inr (λ ())
value-dec {snd r} = Inr (λ ())
value-dec {[ x ]case r of⦃· x₁ ·⦄} = Inr (λ ())
ex-¿¿-dec : ∀{ex} → ex == ¿¿ ∨ ex ≠ ¿¿
ex-¿¿-dec {⟨⟩} = Inr (λ ())
ex-¿¿-dec {⟨ ex₁ , ex₂ ⟩} = Inr (λ ())
ex-¿¿-dec {C[ x ] ex₁} = Inr (λ ())
ex-¿¿-dec {¿¿} = Inl refl
ex-¿¿-dec {x ↦ ex₁} = Inr (λ ())
| {
"alphanum_fraction": 0.4434611954,
"avg_line_length": 45.7924836601,
"ext": "agda",
"hexsha": "fe187abc7030f3df789b52be2381e18e29531a7e",
"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": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnat-myth-",
"max_forks_repo_path": "decidability.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"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/hazelnat-myth-",
"max_issues_repo_path": "decidability.agda",
"max_line_length": 120,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnat-myth-",
"max_stars_repo_path": "decidability.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-19T23:42:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-19T23:42:31.000Z",
"num_tokens": 12862,
"size": 28025
} |
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.Wedge where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws renaming (assoc to assoc∙)
open import Cubical.HITs.Wedge
open import Cubical.Data.Int hiding (_+_)
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to sRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁)
open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2)
open import Cubical.Data.Nat
open import Cubical.Algebra.Group
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.HITs.Pushout
open import Cubical.Data.Sigma
open import Cubical.Foundations.Isomorphism
open import Cubical.Homotopy.Connected
open import Cubical.HITs.Susp
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.Foundations.Equiv
open GroupIso renaming (map to map')
open GroupHom
{-
This module proves that Hⁿ(A ⋁ B) ≅ Hⁿ(A) × Hⁿ(B) for n ≥ 1 directly (rather than by means of Mayer-Vietoris).
It also proves that Ĥⁿ(A ⋁ B) ≅ Ĥ⁰(A) × Ĥ⁰(B) (reduced groups)
Proof sketch for n ≥ 1:
Any ∣ f ∣₂ ∈ Hⁿ(A ⋁ B) is uniquely characterised by a pair of functions
f₁ : A → Kₙ
f₂ : B → Kₙ
together with a path
p : f₁ (pt A) ≡ f₂ (pt B)
The map F : Hⁿ(A ⋁ B) → Hⁿ(A) × Hⁿ(B) simply forgets about p, i.e.:
F(∣ f ∣₂) := (∣ f₁ ∣₂ , ∣ f₂ ∣₂)
The construction of its inverse is defined by
F⁻(∣ f₁ ∣₂ , ∣ f₂ ∣₂) := ∣ f₁∨f₂ ∣₂
where
f₁∨f₂ : A ⋁ B → Kₙ is defined inductively by
f₁∨f₂ (inl x) := f₁ x + f₂ (pt B)
f₁∨f₂ (inr x) := f₁ (pt B) + f₂ x
cong f₁∨f₂ (push tt) := refl
(this is the map wedgeFun⁻ below)
The fact that F and F⁻ cancel out is a proposition and we may thus assume for any
∣ f ∣₂ ∈ Hⁿ(A ⋁ B) and its corresponding f₁ that
f₁ (pt A) = f₂ (pt B) = 0 (*)
and
f (inl (pt A)) = 0 (**)
The fact that F(F⁻(∣ f₁ ∣₂ , ∣ f₂ ∣₂)) = ∣ f₁ ∣₂ , ∣ f₂ ∣₂) follows immediately from (*)
The other way is slightly trickier. We need to construct paths
Pₗ(x) : f (inl (x)) + f (inr (pt B)) ---> f (inl (x))
Pᵣ(x) : f (inl (pt A)) + f (inr (x)) ---> f (inr (x))
Together with a filler of the following square
cong f (push tt)
----------------->
^ ^
| |
| |
Pₗ(pr A) | | Pᵣ(pt B)
| |
| |
| |
----------------->
refl
The square is filled by first constructing Pₗ by
f (inl (x)) + f (inr (pt B)) ---[cong f (push tt)⁻¹]--->
f (inl (x)) + f (inl (pt A)) ---[(**)]--->
f (inl (x)) + 0 ---[right-unit]--->
f (inl (x))
and then Pᵣ by
f (inl (pt A)) + f (inr (x)) ---[(**)⁻¹]--->
0 + f (inr (x)) ---[left-unit]--->
f (inr (x))
and finally by using the fact that the group laws for Kₙ are refl at its base point.
-}
module _ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') where
private
wedgeFun⁻ : ∀ n → (f : typ A → coHomK (suc n)) (g : typ B → coHomK (suc n))
→ ((A ⋁ B) → coHomK (suc n))
wedgeFun⁻ n f g (inl x) = f x +ₖ g (pt B)
wedgeFun⁻ n f g (inr x) = f (pt A) +ₖ g x
wedgeFun⁻ n f g (push a i) = f (pt A) +ₖ g (pt B)
Hⁿ-⋁ : (n : ℕ) → GroupIso (coHomGr (suc n) (A ⋁ B)) (×coHomGr (suc n) (typ A) (typ B))
fun (map' (Hⁿ-⋁ zero)) =
sElim (λ _ → isSet× setTruncIsSet setTruncIsSet)
λ f → ∣ (λ x → f (inl x)) ∣₂ , ∣ (λ x → f (inr x)) ∣₂
isHom (map' (Hⁿ-⋁ zero)) =
sElim2 (λ _ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _)
λ _ _ → refl
inv (Hⁿ-⋁ zero) = uncurry (sElim2 (λ _ _ → setTruncIsSet)
λ f g → ∣ wedgeFun⁻ 0 f g ∣₂)
rightInv (Hⁿ-⋁ zero) =
uncurry
(coHomPointedElim _ (pt A) (λ _ → isPropΠ λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ f fId → coHomPointedElim _ (pt B) (λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ g gId → ΣPathP ((cong ∣_∣₂ (funExt (λ x → cong (f x +ₖ_) gId ∙ rUnitₖ 1 (f x))))
, cong ∣_∣₂ (funExt (λ x → cong (_+ₖ g x) fId ∙ lUnitₖ 1 (g x)))))
leftInv (Hⁿ-⋁ zero) =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(λ f → pRec (setTruncIsSet _ _)
(λ fId → cong ∣_∣₂ (sym fId))
(helper f _ refl))
where
helper : (f : A ⋁ B → coHomK 1) (x : coHomK 1)
→ f (inl (pt A)) ≡ x
→ ∥ f ≡ wedgeFun⁻ 0 (λ x → f (inl x)) (λ x → f (inr x)) ∥
helper f =
trElim (λ _ → isProp→isOfHLevelSuc 2 (isPropΠ λ _ → propTruncIsProp))
(sphereElim 0 (λ _ → isPropΠ λ _ → propTruncIsProp)
λ inlId → ∣ funExt (λ { (inl x) → sym (rUnitₖ 1 (f (inl x)))
∙∙ cong ((f (inl x)) +ₖ_) (sym inlId)
∙∙ cong ((f (inl x)) +ₖ_) (cong f (push tt))
; (inr x) → sym (lUnitₖ 1 (f (inr x)))
∙ cong (_+ₖ (f (inr x))) (sym inlId)
; (push tt i) j → helper2 (f (inl (pt A))) (sym (inlId))
(f (inr (pt B))) (cong f (push tt)) j i} ) ∣₁)
where
helper2 : (x : coHomK 1) (r : ∣ base ∣ ≡ x) (y : coHomK 1) (p : x ≡ y)
→ PathP (λ j → ((sym (rUnitₖ 1 x) ∙∙ cong (x +ₖ_) r ∙∙ cong (x +ₖ_) p)) j
≡ (sym (lUnitₖ 1 y) ∙ cong (_+ₖ y) r) j)
p refl
helper2 x = J (λ x r → (y : coHomK 1) (p : x ≡ y)
→ PathP (λ j → ((sym (rUnitₖ 1 x) ∙∙ cong (x +ₖ_) r ∙∙ cong (x +ₖ_) p)) j
≡ (sym (lUnitₖ 1 y) ∙ cong (_+ₖ y) r) j)
p refl)
λ y → J (λ y p → PathP (λ j → ((sym (rUnitₖ 1 ∣ base ∣) ∙∙ refl ∙∙ cong (∣ base ∣ +ₖ_) p)) j
≡ (sym (lUnitₖ 1 y) ∙ refl) j)
p refl)
λ i _ → (refl ∙ (λ _ → 0ₖ 1)) i
fun (map' (Hⁿ-⋁ (suc n))) =
sElim (λ _ → isSet× setTruncIsSet setTruncIsSet)
λ f → ∣ (λ x → f (inl x)) ∣₂ , ∣ (λ x → f (inr x)) ∣₂
isHom (map' (Hⁿ-⋁ (suc n))) =
sElim2 (λ _ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _)
λ _ _ → refl
inv (Hⁿ-⋁ (suc n)) =
uncurry (sElim2 (λ _ _ → setTruncIsSet)
λ f g → ∣ wedgeFun⁻ (suc n) f g ∣₂)
rightInv (Hⁿ-⋁ (suc n)) =
uncurry
(coHomPointedElim _ (pt A) (λ _ → isPropΠ λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ f fId → coHomPointedElim _ (pt B) (λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ g gId → ΣPathP ((cong ∣_∣₂ (funExt (λ x → cong (f x +ₖ_) gId ∙ rUnitₖ (2 + n) (f x))))
, cong ∣_∣₂ (funExt (λ x → cong (_+ₖ g x) fId ∙ lUnitₖ (2 + n) (g x)))))
leftInv (Hⁿ-⋁ (suc n)) =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(λ f → pRec (setTruncIsSet _ _)
(λ fId → cong ∣_∣₂ (sym fId))
(helper f _ refl))
where
helper : (f : A ⋁ B → coHomK (2 + n)) (x : coHomK (2 + n))
→ f (inl (pt A)) ≡ x
→ ∥ f ≡ wedgeFun⁻ (suc n) (λ x → f (inl x)) (λ x → f (inr x)) ∥
helper f =
trElim (λ _ → isProp→isOfHLevelSuc (3 + n) (isPropΠ λ _ → propTruncIsProp))
(sphereToPropElim (suc n) (λ _ → isPropΠ λ _ → propTruncIsProp)
λ inlId → (∣ funExt (λ { (inl x) → sym (rUnitₖ (2 + n) (f (inl x)))
∙∙ cong ((f (inl x)) +ₖ_) (sym inlId)
∙∙ cong ((f (inl x)) +ₖ_) (cong f (push tt))
; (inr x) → sym (lUnitₖ (2 + n) (f (inr x)))
∙ cong (_+ₖ (f (inr x))) (sym inlId)
; (push tt i) j → helper2 (f (inl (pt A))) (sym (inlId))
(f (inr (pt B))) (cong f (push tt)) j i}) ∣₁))
where
helper2 : (x : coHomK (2 + n)) (r : ∣ north ∣ ≡ x) (y : coHomK (2 + n)) (p : x ≡ y)
→ PathP (λ j → ((sym (rUnitₖ (2 + n) x) ∙∙ cong (x +ₖ_) r ∙∙ cong (x +ₖ_) p)) j
≡ (sym (lUnitₖ (2 + n) y) ∙ cong (_+ₖ y) r) j)
p refl
helper2 x = J (λ x r → (y : coHomK (2 + n)) (p : x ≡ y)
→ PathP (λ j → ((sym (rUnitₖ (2 + n) x) ∙∙ cong (x +ₖ_) r ∙∙ cong (x +ₖ_) p)) j
≡ (sym (lUnitₖ (2 + n) y) ∙ cong (_+ₖ y) r) j)
p refl)
λ y → J (λ y p → PathP (λ j → ((sym (rUnitₖ (2 + n) ∣ north ∣) ∙∙ refl ∙∙ cong (∣ north ∣ +ₖ_) p)) j
≡ (sym (lUnitₖ (2 + n) y) ∙ refl) j)
p refl)
λ i j → ((λ _ → ∣ north ∣) ∙ refl) i
H⁰Red-⋁ : GroupIso (coHomRedGrDir 0 (A ⋁ B , inl (pt A)))
(dirProd (coHomRedGrDir 0 A) (coHomRedGrDir 0 B))
fun (GroupIso.map H⁰Red-⋁) =
sRec (isSet× setTruncIsSet setTruncIsSet)
λ {(f , p) → ∣ (f ∘ inl) , p ∣₂
, ∣ (f ∘ inr) , cong f (sym (push tt)) ∙ p ∣₂}
isHom (GroupIso.map H⁰Red-⋁) =
sElim2 (λ _ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _)
λ {(f , p) (g , q) → ΣPathP (cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _) refl)
, cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _) refl))}
inv H⁰Red-⋁ =
uncurry (sRec2 setTruncIsSet
λ {(f , p) (g , q) → ∣ (λ {(inl a) → f a
; (inr b) → g b
; (push tt i) → (p ∙ sym q) i})
, p ∣₂})
rightInv H⁰Red-⋁ =
uncurry
(sElim2 (λ _ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _)
λ {(_ , _) (_ , _) → ΣPathP (cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _) refl)
, cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _) refl))})
leftInv H⁰Red-⋁ =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ {(f , p) → cong ∣_∣₂ (Σ≡Prop (λ _ → isSetInt _ _)
(funExt λ {(inl a) → refl
; (inr b) → refl
; (push tt i) j → (cong (p ∙_) (symDistr (cong f (sym (push tt))) p)
∙∙ assoc∙ p (sym p) (cong f (push tt))
∙∙ cong (_∙ (cong f (push tt))) (rCancel p)
∙ sym (lUnit (cong f (push tt)))) j i}))}
-- Alt. use isOfHLevel→isOfHLevelDep
wedgeConnected : ((x : typ A) → ∥ pt A ≡ x ∥) → ((x : typ B) → ∥ pt B ≡ x ∥) → (x : A ⋁ B) → ∥ inl (pt A) ≡ x ∥
wedgeConnected conA conB =
PushoutToProp (λ _ → propTruncIsProp)
(λ a → pRec propTruncIsProp (λ p → ∣ cong inl p ∣₁) (conA a))
λ b → pRec propTruncIsProp (λ p → ∣ push tt ∙ cong inr p ∣₁) (conB b)
| {
"alphanum_fraction": 0.4581565099,
"avg_line_length": 48.887966805,
"ext": "agda",
"hexsha": "faf2762465ab794b8a89e1da074568a7ebdc8f9f",
"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/ZCohomology/Groups/Wedge.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/ZCohomology/Groups/Wedge.agda",
"max_line_length": 125,
"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/ZCohomology/Groups/Wedge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4458,
"size": 11782
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Consequences of a monomorphism between group-like structures
------------------------------------------------------------------------
-- See Data.Nat.Binary.Properties for examples of how this and similar
-- modules can be used to easily translate properties between types.
{-# OPTIONS --without-K --safe #-}
open import Algebra.Bundles
open import Algebra.Morphism.Structures
open import Relation.Binary.Core
module Algebra.Morphism.GroupMonomorphism
{a b ℓ₁ ℓ₂} {G₁ : RawGroup a ℓ₁} {G₂ : RawGroup b ℓ₂} {⟦_⟧}
(isGroupMonomorphism : IsGroupMonomorphism G₁ G₂ ⟦_⟧)
where
open IsGroupMonomorphism isGroupMonomorphism
open RawGroup G₁ renaming
(Carrier to A; _≈_ to _≈₁_; _∙_ to _∙_; _⁻¹ to _⁻¹₁; ε to ε₁)
open RawGroup G₂ renaming
(Carrier to B; _≈_ to _≈₂_; _∙_ to _◦_; _⁻¹ to _⁻¹₂; ε to ε₂)
open import Algebra.Definitions
open import Algebra.Structures
open import Data.Product
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
------------------------------------------------------------------------
-- Re-export all properties of monoid monomorphisms
open import Algebra.Morphism.MonoidMonomorphism
isMonoidMonomorphism public
------------------------------------------------------------------------
-- Properties
module _ (◦-isMagma : IsMagma _≈₂_ _◦_) where
open IsMagma ◦-isMagma renaming (∙-cong to ◦-cong)
open SetoidReasoning setoid
inverseˡ : LeftInverse _≈₂_ ε₂ _⁻¹₂ _◦_ → LeftInverse _≈₁_ ε₁ _⁻¹₁ _∙_
inverseˡ invˡ x = injective (begin
⟦ x ⁻¹₁ ∙ x ⟧ ≈⟨ ∙-homo (x ⁻¹₁ ) x ⟩
⟦ x ⁻¹₁ ⟧ ◦ ⟦ x ⟧ ≈⟨ ◦-cong (⁻¹-homo x) refl ⟩
⟦ x ⟧ ⁻¹₂ ◦ ⟦ x ⟧ ≈⟨ invˡ ⟦ x ⟧ ⟩
ε₂ ≈˘⟨ ε-homo ⟩
⟦ ε₁ ⟧ ∎)
inverseʳ : RightInverse _≈₂_ ε₂ _⁻¹₂ _◦_ → RightInverse _≈₁_ ε₁ _⁻¹₁ _∙_
inverseʳ invʳ x = injective (begin
⟦ x ∙ x ⁻¹₁ ⟧ ≈⟨ ∙-homo x (x ⁻¹₁) ⟩
⟦ x ⟧ ◦ ⟦ x ⁻¹₁ ⟧ ≈⟨ ◦-cong refl (⁻¹-homo x) ⟩
⟦ x ⟧ ◦ ⟦ x ⟧ ⁻¹₂ ≈⟨ invʳ ⟦ x ⟧ ⟩
ε₂ ≈˘⟨ ε-homo ⟩
⟦ ε₁ ⟧ ∎)
inverse : Inverse _≈₂_ ε₂ _⁻¹₂ _◦_ → Inverse _≈₁_ ε₁ _⁻¹₁ _∙_
inverse (invˡ , invʳ) = inverseˡ invˡ , inverseʳ invʳ
⁻¹-cong : Congruent₁ _≈₂_ _⁻¹₂ → Congruent₁ _≈₁_ _⁻¹₁
⁻¹-cong ⁻¹-cong {x} {y} x≈y = injective (begin
⟦ x ⁻¹₁ ⟧ ≈⟨ ⁻¹-homo x ⟩
⟦ x ⟧ ⁻¹₂ ≈⟨ ⁻¹-cong (⟦⟧-cong x≈y) ⟩
⟦ y ⟧ ⁻¹₂ ≈˘⟨ ⁻¹-homo y ⟩
⟦ y ⁻¹₁ ⟧ ∎)
isGroup : IsGroup _≈₂_ _◦_ ε₂ _⁻¹₂ → IsGroup _≈₁_ _∙_ ε₁ _⁻¹₁
isGroup isGroup = record
{ isMonoid = isMonoid G.isMonoid
; inverse = inverse G.isMagma G.inverse
; ⁻¹-cong = ⁻¹-cong G.isMagma G.⁻¹-cong
} where module G = IsGroup isGroup
isAbelianGroup : IsAbelianGroup _≈₂_ _◦_ ε₂ _⁻¹₂ → IsAbelianGroup _≈₁_ _∙_ ε₁ _⁻¹₁
isAbelianGroup isAbelianGroup = record
{ isGroup = isGroup G.isGroup
; comm = comm G.isMagma G.comm
} where module G = IsAbelianGroup isAbelianGroup
| {
"alphanum_fraction": 0.5780445969,
"avg_line_length": 34.7023809524,
"ext": "agda",
"hexsha": "2a29f03dda28b9e09091f8824cbcbf130ecbc679",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/Morphism/GroupMonomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/Morphism/GroupMonomorphism.agda",
"max_line_length": 82,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Morphism/GroupMonomorphism.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": 1205,
"size": 2915
} |
{-# OPTIONS --without-K --safe #-}
module Loop.Bundles where
open import Algebra.Core
open import Relation.Binary
open import Level
open import Loop.Structures
open import Algebra.Bundles
open import Algebra.Structures
record LeftBolLoop c ℓ : Set (suc (c ⊔ ℓ)) where
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
_\\_ : Op₂ Carrier
_//_ : Op₂ Carrier
ε : Carrier
isLeftBolLoop : IsLeftBolLoop _≈_ _∙_ _\\_ _//_ ε
open IsLeftBolLoop isLeftBolLoop public
loop : Loop _ _
loop = record { isLoop = isLoop }
open Loop loop public
using (quasigroup)
record RightBolLoop c ℓ : Set (suc (c ⊔ ℓ)) where
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
_\\_ : Op₂ Carrier
_//_ : Op₂ Carrier
ε : Carrier
isRightBolLoop : IsRightBolLoop _≈_ _∙_ _\\_ _//_ ε
open IsRightBolLoop isRightBolLoop public
loop : Loop _ _
loop = record { isLoop = isLoop }
open Loop loop public
using (quasigroup)
record MoufangLoop c ℓ : Set (suc (c ⊔ ℓ)) where
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
_\\_ : Op₂ Carrier
_//_ : Op₂ Carrier
ε : Carrier
isMoufangLoop : IsMoufangLoop _≈_ _∙_ _\\_ _//_ ε
open IsMoufangLoop isMoufangLoop public
loop : Loop _ _
loop = record { isLoop = isLoop }
open Loop loop public
using (quasigroup)
| {
"alphanum_fraction": 0.6243093923,
"avg_line_length": 21.9393939394,
"ext": "agda",
"hexsha": "d16e8a77750c9c89f39b03ea7940dbb574d1cb43",
"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": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_forks_repo_path": "src/Loop/Bundles.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_issues_repo_issues_event_max_datetime": "2021-10-09T08:24:56.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-04T05:30:30.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_issues_repo_path": "src/Loop/Bundles.agda",
"max_line_length": 56,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_stars_repo_path": "src/Loop/Bundles.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-17T09:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-15T06:16:13.000Z",
"num_tokens": 505,
"size": 1448
} |
------------------------------------------------------------------------
-- Support for reflection
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module TC-monad
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
import Agda.Builtin.Bool as B
open import Agda.Builtin.Char
open import Agda.Builtin.Float
import Agda.Builtin.Reflection
open import Agda.Builtin.Strict
open import Agda.Builtin.String
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (Type)
import Maybe eq as _
open import Monad eq
open import Nat eq
-- Reflection primitives.
open Agda.Builtin.Reflection public hiding (isMacro; withNormalisation)
-- The TC monad is a "raw monad".
instance
raw-monad : ∀ {d} → Raw-monad {d = d} TC
Raw-monad.return raw-monad = returnTC
Raw-monad._>>=_ raw-monad = bindTC
-- Converts B.Bool to and from Bool.
Bool⇔Bool : B.Bool ⇔ Bool
Bool⇔Bool = record { to = to; from = from }
where
to : B.Bool → Bool
to B.false = false
to B.true = true
from : Bool → B.Bool
from false = B.false
from true = B.true
-- Variants of some definitions from Agda.Builtin.Reflection.
isMacro : Name → TC Bool
isMacro x = _⇔_.to Bool⇔Bool ⟨$⟩ Agda.Builtin.Reflection.isMacro x
withNormalisation : ∀ {a} {A : P.Type a} → Bool → TC A → TC A
withNormalisation =
Agda.Builtin.Reflection.withNormalisation ∘ _⇔_.from Bool⇔Bool
-- Constructs a visible, relevant argument that is not erased
pattern varg x = arg (arg-info visible (modality relevant quantity-ω)) x
-- Constructs a hidden, relevant argument that is not erased.
pattern harg x = arg (arg-info hidden (modality relevant quantity-ω)) x
-- An n-ary variant of pi.
pis : List (Abs (Arg Type)) → Type → Type
pis [] B = B
pis (abs x A ∷ As) B = pi A (abs x (pis As B))
mutual
-- Checks if the terms are syntactically equal.
--
-- Pattern-matching lambdas and "unknown" are currently never seen
-- as equal to anything.
--
-- Note that this function does not perform any kind of parameter
-- reconstruction.
eq-Term : Term → Term → Bool
eq-Term (var x₁ ts₁) (var x₂ ts₂) = eq-ℕ x₁ x₂ ∧ eq-Args ts₁ ts₂
eq-Term (con c₁ ts₁) (con c₂ ts₂) = eq-Name c₁ c₂ ∧ eq-Args ts₁ ts₂
eq-Term (def f₁ ts₁) (def f₂ ts₂) = eq-Name f₁ f₂ ∧ eq-Args ts₁ ts₂
eq-Term (lam v₁ t₁) (lam v₂ t₂) = eq-Visibility v₁ v₂ ∧ eq-Abs t₁ t₂
eq-Term (pi a₁ b₁) (pi a₂ b₂) = eq-Arg a₁ a₁ ∧ eq-Abs b₁ b₂
eq-Term (agda-sort s₁) (agda-sort s₂) = eq-Sort s₁ s₂
eq-Term (lit l₁) (lit l₂) = eq-Literal l₁ l₂
eq-Term (meta x₁ ts₁) (meta x₂ ts₂) = eq-Meta x₁ x₂ ∧ eq-Args ts₁ ts₂
eq-Term _ _ = false
eq-Name : Name → Name → Bool
eq-Name x₁ x₂ = _⇔_.to Bool⇔Bool (primQNameEquality x₁ x₂)
eq-ℕ : ℕ → ℕ → Bool
eq-ℕ = _==_
eq-Meta : Meta → Meta → Bool
eq-Meta x₁ x₂ = _⇔_.to Bool⇔Bool (primMetaEquality x₁ x₂)
eq-String : String → String → Bool
eq-String x₁ x₂ = _⇔_.to Bool⇔Bool (primStringEquality x₁ x₂)
eq-Sort : Sort → Sort → Bool
eq-Sort (set t₁) (set t₂) = eq-Term t₁ t₂
eq-Sort (lit n₁) (lit n₂) = eq-ℕ n₁ n₂
eq-Sort _ _ = false
eq-Literal : Literal → Literal → Bool
eq-Literal (nat n₁) (nat n₂) = eq-ℕ n₁ n₂
eq-Literal (float x₁) (float x₂) = _⇔_.to Bool⇔Bool
(primFloatEquality x₁ x₂)
eq-Literal (char c₁) (char c₂) = _⇔_.to Bool⇔Bool
(primCharEquality c₁ c₂)
eq-Literal (string s₁) (string s₂) = eq-String s₁ s₂
eq-Literal (name x₁) (name x₂) = eq-Name x₁ x₂
eq-Literal (meta x₁) (meta x₂) = eq-Meta x₁ x₂
eq-Literal _ _ = false
eq-Args : List (Arg Term) → List (Arg Term) → Bool
eq-Args [] [] = true
eq-Args (t₁ ∷ ts₁) (t₂ ∷ ts₂) = eq-Arg t₁ t₂ ∧ eq-Args ts₁ ts₂
eq-Args _ _ = false
eq-Abs : Abs Term → Abs Term → Bool
eq-Abs (abs s₁ t₁) (abs s₂ t₂) =
eq-String s₁ s₂ ∧ eq-Term t₁ t₂
eq-ArgInfo : ArgInfo → ArgInfo → Bool
eq-ArgInfo (arg-info v₁ m₁) (arg-info v₂ m₂) =
eq-Visibility v₁ v₂ ∧ eq-Modality m₁ m₂
eq-Arg : Arg Term → Arg Term → Bool
eq-Arg (arg i₁ t₁) (arg i₂ t₂) =
eq-ArgInfo i₁ i₂ ∧ eq-Term t₁ t₂
eq-Visibility : Visibility → Visibility → Bool
eq-Visibility visible visible = true
eq-Visibility hidden hidden = true
eq-Visibility instance′ instance′ = true
eq-Visibility _ _ = false
eq-Modality : Modality → Modality → Bool
eq-Modality (modality r₁ q₁) (modality r₂ q₂) =
eq-Relevance r₁ r₂ ∧ eq-Quantity q₁ q₂
eq-Relevance : Relevance → Relevance → Bool
eq-Relevance relevant relevant = true
eq-Relevance irrelevant irrelevant = true
eq-Relevance _ _ = false
eq-Quantity : Quantity → Quantity → Bool
eq-Quantity quantity-0 quantity-0 = true
eq-Quantity quantity-ω quantity-ω = true
eq-Quantity _ _ = false
-- Returns a fresh meta-variable of type Level.
fresh-level : TC Level
fresh-level =
checkType unknown (def (quote Level) []) >>= λ ℓ →
unquoteTC ℓ
-- Tries to apply the given term (of the given type) to the list of
-- arguments. The type of the resulting term is also returned.
apply : Type → Term → List (Arg Term) → TC (Type × Term)
apply A t [] = returnTC (A , t)
apply A t (a ∷ as) =
reduce A >>= λ A →
apply₁ A t a >>= λ { (A , t) →
apply A t as }
where
apply₁ : Type → Term → Arg Term → TC (Type × Term)
apply₁ (pi (arg i₁@(arg-info k _) A) B) t₁ (arg i₂ t₂) =
if not (eq-ArgInfo i₁ i₂)
then typeError (strErr "apply: argument info mismatch" ∷ [])
else
bindTC fresh-level λ a →
bindTC fresh-level λ b →
bindTC (unquoteTC A) λ (A : P.Type a) →
bindTC (unquoteTC (lam visible B)) λ (B : A → P.Type b) →
bindTC (unquoteTC t₂) λ (t₂ : A) →
bindTC (quoteTC (B t₂)) λ Bt₂ →
case k of λ where
visible →
bindTC (unquoteTC t₁) λ (t₁ : (x : A) → B x) →
bindTC (quoteTC (t₁ t₂)) λ t₁t₂ →
return (Bt₂ , t₁t₂)
hidden →
bindTC (unquoteTC t₁) λ (t₁ : {x : A} → B x) →
bindTC (quoteTC (t₁ {x = t₂})) λ t₁t₂ →
return (Bt₂ , t₁t₂)
instance′ →
bindTC (unquoteTC t₁) λ (t₁ : ⦃ x : A ⦄ → B x) →
bindTC (quoteTC (t₁ ⦃ x = t₂ ⦄)) λ t₁t₂ →
return (Bt₂ , t₁t₂)
apply₁ (meta x _) _ _ = blockOnMeta x
apply₁ A _ _ =
typeError (strErr "apply: not a pi" ∷ termErr A ∷ [])
mutual
-- The number of variables bound in the pattern(s).
bound-in-pattern : Pattern → ℕ
bound-in-pattern (con _ ps) = bound-in-patterns ps
bound-in-pattern (dot _) = 0
bound-in-pattern (var _) = 1
bound-in-pattern (lit _) = 0
bound-in-pattern (proj _) = 0
bound-in-pattern (absurd _) = 1
bound-in-patterns : List (Arg Pattern) → ℕ
bound-in-patterns [] = 0
bound-in-patterns (arg _ p ∷ ps) =
bound-in-pattern p + bound-in-patterns ps
mutual
-- Renames the first variable to the second.
--
-- Pattern-matching lambdas are replaced by "unknown".
rename-term : ℕ → ℕ → Term → Term
rename-term old new = λ where
(var x args) → var (rename-var old new x)
(rename-args old new args)
(con c args) → con c (rename-args old new args)
(def f args) → def f (rename-args old new args)
(lam v t) → lam v (rename-abs old new t)
(pat-lam cs args) → unknown
(pi a b) → pi (rename-arg old new a) (rename-abs old new b)
(agda-sort s) → agda-sort (rename-sort old new s)
(lit l) → lit l
(meta x args) → meta x (rename-args old new args)
unknown → unknown
rename-var : ℕ → ℕ → ℕ → ℕ
rename-var old new x = if eq-ℕ x old then new else old
rename-abs : ℕ → ℕ → Abs Term → Abs Term
rename-abs old new (abs s t) =
abs s (rename-term (suc old) (suc new) t)
rename-arg : ℕ → ℕ → Arg Term → Arg Term
rename-arg old new (arg i t) = arg i (rename-term old new t)
rename-args : ℕ → ℕ → List (Arg Term) → List (Arg Term)
rename-args old new = λ where
[] → []
(a ∷ as) → rename-arg old new a ∷ rename-args old new as
rename-sort : ℕ → ℕ → Sort → Sort
rename-sort old new = λ where
(set t) → set (rename-term old new t)
(prop t) → prop (rename-term old new t)
(lit n) → lit n
(propLit n) → propLit n
(inf n) → inf n
unknown → unknown
mutual
-- Weakening: weaken-term from by increases variables "from" and
-- higher by "by".
--
-- Pattern-matching lambdas are replaced by "unknown".
weaken-term : ℕ → ℕ → Term → Term
weaken-term from by = λ where
(var x args) → var (weaken-var from by x)
(weaken-args from by args)
(con c args) → con c (weaken-args from by args)
(def f args) → def f (weaken-args from by args)
(lam v t) → lam v (weaken-abs from by t)
(pat-lam cs args) → unknown
(pi a b) → pi (weaken-arg from by a) (weaken-abs from by b)
(agda-sort s) → agda-sort (weaken-sort from by s)
(lit l) → lit l
(meta x args) → meta x (weaken-args from by args)
unknown → unknown
weaken-var : ℕ → ℕ → ℕ → ℕ
weaken-var from by x = if from <= x then x + by else x
weaken-abs : ℕ → ℕ → Abs Term → Abs Term
weaken-abs from by (abs s t) =
abs s (weaken-term (suc from) by t)
weaken-arg : ℕ → ℕ → Arg Term → Arg Term
weaken-arg from by (arg i t) = arg i (weaken-term from by t)
weaken-args : ℕ → ℕ → List (Arg Term) → List (Arg Term)
weaken-args from by = λ where
[] → []
(a ∷ as) → weaken-arg from by a ∷ weaken-args from by as
weaken-sort : ℕ → ℕ → Sort → Sort
weaken-sort from by = λ where
(set t) → set (weaken-term from by t)
(prop t) → prop (weaken-term from by t)
(lit n) → lit n
(propLit n) → propLit n
(inf n) → inf n
unknown → unknown
mutual
-- Strengthening: strengthen-term from by subtracts "by" from
-- variables "from" and higher. Applications of variable x, where
-- from ≤ x and x < from + by, are replaced by "unknown".
--
-- Pattern-matching lambdas are replaced by "unknown".
strengthen-term : ℕ → ℕ → Term → Term
strengthen-term from by = λ where
(var x args) → let args′ = strengthen-args from by args in
if from + by <= x
then var (x ∸ by) args′
else if from <= x
then unknown
else var x args′
(con c args) → con c (strengthen-args from by args)
(def f args) → def f (strengthen-args from by args)
(lam v t) → lam v (strengthen-abs from by t)
(pat-lam cs args) → unknown
(pi a b) → pi (strengthen-arg from by a)
(strengthen-abs from by b)
(agda-sort s) → agda-sort (strengthen-sort from by s)
(lit l) → lit l
(meta x args) → meta x (strengthen-args from by args)
unknown → unknown
strengthen-abs : ℕ → ℕ → Abs Term → Abs Term
strengthen-abs from by (abs s t) =
abs s (strengthen-term (suc from) by t)
strengthen-arg : ℕ → ℕ → Arg Term → Arg Term
strengthen-arg from by (arg i t) = arg i (strengthen-term from by t)
strengthen-args : ℕ → ℕ → List (Arg Term) → List (Arg Term)
strengthen-args from by = λ where
[] → []
(a ∷ as) → strengthen-arg from by a ∷ strengthen-args from by as
strengthen-sort : ℕ → ℕ → Sort → Sort
strengthen-sort from by = λ where
(set t) → set (strengthen-term from by t)
(prop t) → prop (strengthen-term from by t)
(lit n) → lit n
(propLit n) → propLit n
(inf n) → inf n
unknown → unknown
mutual
-- The result of any-term and similar functions.
--
-- Note that "definitely true" can be returned even if the term
-- contains meta-variables, the term unknown, the sort unknown, or
-- pattern-matching lambdas.
Any-result : P.Type
Any-result = Any-result′ Bool
-- A generalisation of Any-result. (Without the type parameter the
-- raw monad instance below would not work.)
data Any-result′ (A : P.Type) : P.Type where
definitely : A → Any-result′ A
-- The result is definitely true or false.
meta : Meta → Any-result′ A
-- There is no positive evidence that the result is true. At least
-- one meta-variable (the given one) was encountered, and if this
-- meta-variable is instantiated in a certain way, then the
-- predicate might hold (depending on what the predicate is,
-- any-term does not analyse the predicate).
unknown : Any-result′ A
-- There is no positive evidence that the result is true. The term
-- contains the term unknown, the sort unknown, or a
-- pattern-matching lambda (and pattern-matching lambdas are not
-- analysed).
instance
-- Any-result′ is a raw monad.
Any-result-raw-monad : Raw-monad Any-result′
Raw-monad.return Any-result-raw-monad = definitely
Raw-monad._>>=_ Any-result-raw-monad = λ where
(definitely x) f → f x
(meta m) f → meta m
unknown f → unknown
mutual
-- Tries to figure out if the given predicate holds for some free
-- variable in the given term. The predicate is adjusted when
-- any-term goes under a binder.
any-term : (ℕ → Bool) → Term → Any-result
any-term p = λ where
(var x args) → (any-var p x ∨_) ⟨$⟩ any-args p args
(con _ args) → any-args p args
(def _ args) → any-args p args
(lam _ t) → any-abs p t
(pat-lam cs args) → unknown
(pi a b) → _∨_ ⟨$⟩ any-arg p a ⊛ any-abs p b
(agda-sort s) → any-sort p s
(lit l) → definitely false
(meta m args) → case any-args p args of λ where
(definitely false) → meta m
r → r
unknown → unknown
any-var : (ℕ → Bool) → ℕ → Bool
any-var p x = p x
any-abs : (ℕ → Bool) → Abs Term → Any-result
any-abs p (abs _ t) =
any-term (λ where
zero → false
(suc n) → p n)
t
any-arg : (ℕ → Bool) → Arg Term → Any-result
any-arg p (arg i t) = any-term p t
any-args : (ℕ → Bool) → List (Arg Term) → Any-result
any-args p = λ where
[] → definitely false
(a ∷ as) → _∨_ ⟨$⟩ any-arg p a ⊛ any-args p as
any-sort : (ℕ → Bool) → Sort → Any-result
any-sort p = λ where
(set t) → any-term p t
(prop t) → any-term p t
(lit n) → definitely false
(propLit n) → definitely false
(inf n) → definitely false
unknown → unknown
-- Figures out if the given variable is bound in the given term.
bound? : ℕ → Term → Any-result
bound? x = any-term (eq-ℕ x)
-- Figures out if variables less than the given variable are bound
-- in the given term.
<bound? : ℕ → Term → Any-result
<bound? x = any-term (λ y → suc y <= x)
| {
"alphanum_fraction": 0.5761472681,
"avg_line_length": 33.5207877462,
"ext": "agda",
"hexsha": "d497ab1f10b91136e2358951df012398a14a0cd6",
"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/TC-monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/TC-monad.agda",
"max_line_length": 76,
"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/TC-monad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 4891,
"size": 15319
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- The irrelevance axiom
------------------------------------------------------------------------
module Irrelevance where
import Level
------------------------------------------------------------------------
-- The irrelevance axiom
-- There is no guarantee that this axiom is sound. Use it at your own
-- risk.
postulate
.irrelevance-axiom : ∀ {a} {A : Set a} → .A → A
{-# BUILTIN IRRAXIOM irrelevance-axiom #-}
| {
"alphanum_fraction": 0.4041745731,
"avg_line_length": 25.0952380952,
"ext": "agda",
"hexsha": "2a39b8438068bb189cdc5939e69af36ce76f5c00",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Irrelevance.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Irrelevance.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Irrelevance.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 97,
"size": 527
} |
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
test1 : Nat → Nat
test1 zero = 0
test1 (suc zero) = 1
test1 (suc n) = {!n!}
test2 : Nat → Nat → Nat
test2 zero zero = zero
test2 zero (suc y) = y
test2 x y = {!x!}
test3 : Bool → Bool → Bool → Bool
test3 true true true = true
test3 x true false = x
test3 false y true = y
test3 true false z = z
test3 x y z = {!x y z!}
| {
"alphanum_fraction": 0.5717592593,
"avg_line_length": 21.6,
"ext": "agda",
"hexsha": "959ff6fc9507731bfb99c792e85138bde227a65f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue1958.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue1958.agda",
"max_line_length": 35,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue1958.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": 162,
"size": 432
} |
-- 2013-12-28 Andreas, issue reported by Christian Sattler
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS -v tc.cc:15 #-} -- Keep! Debug printing triggered the problem.
record Σ (A : Set) (B : A → Set) : Set where
field
fst : A
snd : B fst
test : {A : Set} → Σ A (λ {_ → A})
test = _
-- This used to trigger an internal error
-- (funnily only at -v tc.cc:15 verbosity)
-- because adding the clause to an
-- extended lambda failed. Reason:
-- Extended lambda was registered as Axiom
-- during first checking, not Defn as
-- checkFunDef' now expects.
| {
"alphanum_fraction": 0.6602112676,
"avg_line_length": 27.0476190476,
"ext": "agda",
"hexsha": "7c406e489f98fd747a292c1c3eb9fed081c5c056",
"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/Issue1009.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/Issue1009.agda",
"max_line_length": 74,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1009.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": 168,
"size": 568
} |
{-# OPTIONS --universe-polymorphism #-}
module Desc where
--********************************************
-- Prelude
--********************************************
-- Some preliminary stuffs, to avoid relying on the stdlib
--****************
-- Universe polymorphism
--****************
data Level : Set where
zero : Level
suc : Level -> Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
max : Level -> Level -> Level
max zero m = m
max (suc n) zero = suc n
max (suc n) (suc m) = suc (max n m)
{-# BUILTIN LEVELMAX max #-}
data Lifted {l : Level} (A : Set l) : Set (suc l) where
lifter : A → Lifted A
lift : {i : Level} -> Set i -> Set (suc i)
lift x = Lifted x
unlift : {l : Level}{A : Set l} -> Lifted A -> A
unlift (lifter a) = a
--****************
-- Sigma and friends
--****************
data Sigma {i j : Level}(A : Set i) (B : A -> Set j) : Set (max i j) where
_,_ : (x : A) (y : B x) -> Sigma A B
pair : {i j : Level}{A : Set i}{B : A -> Set j} ->
(x : A) (y : B x) -> Sigma {i = i}{j = j} A B
pair x y = x , y
_*_ : {i j : Level}(A : Set i)(B : Set j) -> Set (max i j)
A * B = Sigma A \_ -> B
fst : {i j : Level}{A : Set i}{B : A -> Set j} -> Sigma A B -> A
fst (a , _) = a
snd : {i j : Level}{A : Set i}{B : A -> Set j} (p : Sigma A B) -> B (fst p)
snd (a , b) = b
data Zero {i : Level} : Set i where
data Unit {i : Level} : Set i where
Void : Unit
--****************
-- Sum and friends
--****************
data _+_ {i j : Level}(A : Set i)(B : Set j) : Set (max i j) where
l : A -> A + B
r : B -> A + B
--****************
-- Equality
--****************
data _==_ {l : Level}{A : Set l}(x : A) : A -> Set l where
refl : x == x
cong : {l m : Level}{A : Set l}{B : Set m}
(f : A -> B){x y : A} -> x == y -> f x == f y
cong f refl = refl
cong2 : {l m n : Level}{A : Set l}{B : Set m}{C : Set n}
(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
trans : {l : Level}{A : Set l}{x y z : A} -> x == y -> y == z -> x == z
trans refl refl = refl
proof-lift-unlift-eq : {l : Level}{A : Set l}(x : Lifted A) -> lifter (unlift x) == x
proof-lift-unlift-eq (lifter a) = refl
postulate
reflFun : {l m : Level}{A : Set l}{B : A -> Set m}(f : (a : A) -> B a)(g : (a : A) -> B a)-> ((a : A) -> f a == g a) -> f == g
--********************************************
-- Desc code
--********************************************
-- In the paper, we have presented Desc as the grammar of inductive
-- types. Hence, the codes in the paper closely follow this
-- grammar:
data DescPaper : Set1 where
oneP : DescPaper
sigmaP : (S : Set) -> (S -> DescPaper) -> DescPaper
indx : DescPaper -> DescPaper
hindx : Set -> DescPaper -> DescPaper
-- We take advantage of this model to give you an alternative
-- presentation. This alternative model is the one implemented in
-- Epigram. It is also the one which inspired the code for indexed
-- descriptions.
-- With sigma, we are actually "quoting" a standard type-former,
-- namely:
-- |Sigma : (S : Set) -> (S -> Set) -> Set|
-- With:
-- |sigma : (S : Set) -> (S -> Desc) -> Desc|
-- In the alternative presentation, we go further and present all our
-- codes as quotations of standard type-formers:
data Desc {l : Level} : Set (suc l) where
id : Desc
const : Set l -> Desc
prod : Desc -> Desc -> Desc
sigma : (S : Set l) -> (S -> Desc) -> Desc
pi : (S : Set l) -> (S -> Desc) -> Desc
-- Note that we replace |oneP| by a more general |const| code. Whereas
-- |oneP| was interpreted as the unit set, |const K| is
-- interpreted as |K|, for any |K : Set|. Extensionally,
-- |const K| and |sigma K (\_ -> Unit)| are equivalent. However,
-- |const| is *first-order*, unlike its equivalent encoding. From a
-- definitional perspective, we are giving more opportunities to the
-- type-system, hence reducing the burden on the programmer. For the same
-- reason, we introduce |prod| that overlaps with |pi|.
-- This reorganisation is strictly equivalent to the |DescPaper|. For
-- instance, we can encode |indx| and |hindx| using the following
-- code:
indx2 : {l : Level} -> Desc {l = l} -> Desc {l = l}
indx2 D = prod id D
hindx2 : Set -> Desc -> Desc
hindx2 H D = prod (pi H (\_ -> id)) D
--********************************************
-- Desc interpretation
--********************************************
[|_|]_ : {l : Level} -> Desc -> Set l -> Set l
[| id |] Z = Z
[| const X |] Z = X
[| prod D D' |] Z = [| D |] Z * [| D' |] Z
[| sigma S T |] Z = Sigma S (\s -> [| T s |] Z)
[| pi S T |] Z = (s : S) -> [| T s |] Z
--********************************************
-- Fixpoint construction
--********************************************
data Mu {l : Level}(D : Desc {l = l}) : Set l where
con : [| D |] (Mu D) -> Mu D
--********************************************
-- Predicate: All
--********************************************
All : {l : Level}(D : Desc)(X : Set)(P : X -> Set l) -> [| D |] X -> Set l
All id X P x = P x
All (const Z) X P x = Unit
All (prod D D') X P (d , d') = (All D X P d) * (All D' X P d')
All (sigma S T) X P (a , b) = All (T a) X P b
All (pi S T) X P f = (s : S) -> All (T s) X P (f s)
all : {l : Level}(D : Desc)(X : Set)(P : X -> Set l)(R : (x : X) -> P x)(x : [| D |] X) -> All D X P x
all id X P R x = R x
all (const Z) X P R z = Void
all (prod D D') X P R (d , d') = all D X P R d , all D' X P R d'
all (sigma S T) X P R (a , b) = all (T a) X P R b
all (pi S T) X P R f = \ s -> all (T s) X P R (f s)
--********************************************
-- Map
--********************************************
-- This one is bonus: one could rightfully expect our so-called
-- functors to have a morphism part! Here it is.
map : {l : Level}(D : Desc)(X Y : Set l)(f : X -> Y)(v : [| D |] X) -> [| D |] Y
map id X Y sig x = sig x
map (const Z) X Y sig z = z
map (prod D D') X Y sig (d , d') = map D X Y sig d , map D' X Y sig d'
map (sigma S T) X Y sig (a , b) = (a , map (T a) X Y sig b)
map (pi S T) X Y sig f = \x -> map (T x) X Y sig (f x)
-- Together with the proof that they respect the functor laws:
-- map id = id
proof-map-id : {l : Level}(D : Desc)(X : Set l)(v : [| D |] X) -> map D X X (\x -> x) v == v
proof-map-id id X v = refl
proof-map-id (const Z) X v = refl
proof-map-id (prod D D') X (v , v') = cong2 (\x y -> (x , y)) (proof-map-id D X v) (proof-map-id D' X v')
proof-map-id (sigma S T) X (a , b) = cong (\x -> (a , x)) (proof-map-id (T a) X b)
proof-map-id (pi S T) X f = reflFun (\a -> map (T a) X X (\x -> x) (f a)) f (\a -> proof-map-id (T a) X (f a))
-- map (f . g) = map f . map g
proof-map-compos : {l : Level}(D : Desc)(X Y Z : Set l)
(f : X -> Y)(g : Y -> Z)
(v : [| D |] X) ->
map D X Z (\x -> g (f x)) v == map D Y Z g (map D X Y f v)
proof-map-compos id X Y Z f g v = refl
proof-map-compos (const K) X Y Z f g v = refl
proof-map-compos (prod D D') X Y Z f g (v , v') = cong2 (\x y -> (x , y))
(proof-map-compos D X Y Z f g v)
(proof-map-compos D' X Y Z f g v')
proof-map-compos (sigma S T) X Y Z f g (a , b) = cong (\x -> (a , x)) (proof-map-compos (T a) X Y Z f g b)
proof-map-compos (pi S T) X Y Z f g fc = reflFun (\a -> map (T a) X Z (\x -> g (f x)) (fc a))
(\a -> map (T a) Y Z g (map (T a) X Y f (fc a)))
(\a -> proof-map-compos (T a) X Y Z f g (fc a))
--********************************************
-- Elimination principle: induction
--********************************************
-- One would like to write the following:
{-
ind : {l : Level}
(D : Desc)
(P : Mu D -> Set l) ->
( (x : [| D |] (Mu D)) ->
All D (Mu D) P x -> P (con x)) ->
(v : Mu D) ->
P v
ind D P ms (con xs) = ms xs (all D (Mu D) P (\x -> ind D P ms x) xs)
-}
-- But the termination checker is unhappy.
-- So we write the following:
module Elim {l : Level}
(D : Desc)
(P : Mu D -> Set l)
(ms : (x : [| D |] (Mu D)) ->
All D (Mu D) P x -> P (con x))
where
mutual
ind : (x : Mu D) -> P x
ind (con xs) = ms xs (hyps D xs)
hyps : (D' : Desc)
(xs : [| D' |] (Mu D)) ->
All D' (Mu D) P xs
hyps id x = ind x
hyps (const Z) z = Void
hyps (prod D D') (d , d') = hyps D d , hyps D' d'
hyps (sigma S T) (a , b) = hyps (T a) b
hyps (pi S T) f = \s -> hyps (T s) (f s)
ind : {l : Level}
(D : Desc)
(P : Mu D -> Set l) ->
( (x : [| D |] (Mu D)) ->
All D (Mu D) P x -> P (con x)) ->
(v : Mu D) ->
P v
ind D P ms x = Elim.ind D P ms x
--********************************************
-- Examples
--********************************************
--****************
-- Nat
--****************
data NatConst : Set where
Ze : NatConst
Su : NatConst
natCases : NatConst -> Desc
natCases Ze = const Unit
natCases Suc = id
NatD : Desc
NatD = sigma NatConst natCases
Nat : Set
Nat = Mu NatD
ze : Nat
ze = con (Ze , Void)
su : Nat -> Nat
su n = con (Su , n)
-- Now we can get addition for example:
plusCase : (xs : [| NatD |] Nat) ->
All NatD Nat (\_ -> Nat -> Nat) xs -> Nat -> Nat
plusCase ( Ze , Void ) hs y = y
plusCase ( Su , n ) hs y = su (hs y)
plus : Nat -> Nat -> Nat
plus x = ind NatD (\ _ -> (Nat -> Nat)) plusCase x
-- Do this thing in Epigram, you will see that this is *not*
-- hieroglyphic with a bit of elaboration.
--****************
-- List
--****************
data ListConst : Set where
Nil : ListConst
Cons : ListConst
listCases : Set -> ListConst -> Desc
listCases X Nil = const Unit
listCases X Cons = sigma X (\_ -> id)
ListD : Set -> Desc
ListD X = sigma ListConst (listCases X)
List : Set -> Set
List X = Mu (ListD X)
nil : {X : Set} -> List X
nil = con ( Nil , Void )
cons : {X : Set} -> X -> List X -> List X
cons x t = con ( Cons , ( x , t ))
--****************
-- Tree
--****************
data TreeConst : Set where
Leaf : TreeConst
Node : TreeConst
treeCases : Set -> TreeConst -> Desc
treeCases X Leaf = const Unit
treeCases X Node = sigma X (\_ -> prod id id)
TreeD : Set -> Desc
TreeD X = sigma TreeConst (treeCases X)
Tree : Set -> Set
Tree X = Mu (TreeD X)
leaf : {X : Set} -> Tree X
leaf = con (Leaf , Void)
node : {X : Set} -> X -> Tree X -> Tree X -> Tree X
node x le ri = con (Node , (x , (le , ri)))
--********************************************
-- Finite sets
--********************************************
-- If we weren't such big fans of levitating things, we would
-- implement finite sets with:
{-
data En : Set where
nE : En
cE : En -> En
spi : (e : En)(P : EnumT e -> Set) -> Set
spi nE P = Unit
spi (cE e) P = P EZe * spi e (\e -> P (ESu e))
switch : (e : En)(P : EnumT e -> Set)(b : spi e P)(x : EnumT e) -> P x
switch nE P b ()
switch (cE e) P b EZe = fst b
switch (cE e) P b (ESu n) = switch e (\e -> P (ESu e)) (snd b) n
-}
-- But no, we make it fly in Desc:
--****************
-- En
--****************
-- As we have no tags here, we use Nat instead of List.
EnD : Desc
EnD = NatD
En : Set
En = Nat
nE : En
nE = ze
cE : En -> En
cE e = su e
--****************
-- EnumT
--****************
-- Because I don't want to fall back on wacky unicode symbols, I will
-- write EnumT for #, EZe for 0, and ESu for 1+. Sorry about that
data EnumT : (e : En) -> Set where
EZe : {e : En} -> EnumT (cE e)
ESu : {e : En} -> EnumT e -> EnumT (cE e)
--****************
-- Small Pi
--****************
-- This corresponds to the small pi |\pi|.
casesSpi : {l : Level}(xs : [| EnD |] En) ->
All EnD En (\e -> (EnumT e -> Set l) -> Set l) xs ->
(EnumT (con xs) -> Set l) -> Set l
casesSpi (Ze , Void) hs P' = Unit
casesSpi (Su , n) hs P' = P' EZe * hs (\e -> P' (ESu e))
spi : {l : Level}(e : En)(P : EnumT e -> Set l) -> Set l
spi {x} e P = ind EnD (\E -> (EnumT E -> Set x) -> Set x) casesSpi e P
--****************
-- Switch
--****************
casesSwitch : {l : Level}
(xs : [| EnD |] En) ->
All EnD En (\e -> (P' : EnumT e -> Set l)
(b' : spi e P')
(x' : EnumT e) -> P' x') xs ->
(P' : EnumT (con xs) -> Set l)
(b' : spi (con xs) P')
(x' : EnumT (con xs)) -> P' x'
casesSwitch (Ze , Void) hs P' b' ()
casesSwitch (Su , n) hs P' b' EZe = fst b'
casesSwitch (Su , n) hs P' b' (ESu e') = hs (\e -> P' (ESu e)) (snd b') e'
switch : {l : Level}
(e : En)
(P : EnumT e -> Set l)
(b : spi e P)
(x : EnumT e) -> P x
switch {x} e P b xs = ind EnD
(\e -> (P : EnumT e -> Set x)
(b : spi e P)
(xs : EnumT e) -> P xs)
casesSwitch e P b xs
--****************
-- Desc
--****************
-- In the following, we implement Desc in itself. As usual, we have a
-- finite set of constructors -- the name of the codes. Note that we
-- could really define these as a finite set built above. However, in
-- Agda, it's horribly verbose. For the sake of clarity, we won't do
-- that here.
data DescDef : Set1 where
DescId : DescDef
DescConst : DescDef
DescProd : DescDef
DescSigma : DescDef
DescPi : DescDef
-- We slightly diverge here from the presentation of the paper: note
-- the presence of terminating "const Unit". Recall our Lisp-ish
-- notation for nested tuples:
-- |[a b c]|
-- Corresponds to
-- |[a , [ b , [c , []]]]|
-- So, if we want to write constructors using our Lisp-ish notation, the interpretation
-- [| DescD |] (Mu DescD) have to evaluates to [ constructor , [ arg1 , [ arg2 , []]]]
-- Hence, we define Desc's code as follow:
descCases : DescDef -> Desc
descCases DescId = const Unit
descCases DescConst = sigma Set (\_ -> const Unit)
descCases DescProd = prod id (prod id (const Unit))
descCases DescSigma = sigma Set (\S -> prod (pi (lift S) (\_ -> id)) (const Unit))
descCases DescPi = sigma Set (\S -> prod (pi (lift S) (\_ -> id)) (const Unit))
DescD : Desc
DescD = sigma DescDef descCases
DescIn : Set1
DescIn = Mu DescD
-- So that the constructors are:
-- (Note the annoying |pair|s to set the implicit levels. I could not
-- get rid of the yellow otherwise)
idIn : DescIn
idIn = con (pair {i = suc zero} {j = suc zero} DescId Void)
constIn : Set -> DescIn
constIn K = con (pair {i = suc zero} {j = suc zero} DescConst (K , Void))
prodIn : (D D' : DescIn) -> DescIn
prodIn D D' = con (pair {i = suc zero} {j = suc zero} DescProd (D , ( D' , Void )))
sigmaIn : (S : Set)(D : S -> DescIn) -> DescIn
sigmaIn S D = con (pair {i = suc zero} {j = suc zero} DescSigma (S , ((\s -> D (unlift s)) , Void )))
piIn : (S : Set)(D : S -> DescIn) -> DescIn
piIn S D = con (pair {i = suc zero} {j = suc zero} DescPi (S , ((\s -> D (unlift s)) , Void )))
-- At this stage, we could prove the isomorphism between |DescIn| and
-- |Desc|. While not technically difficult, it is long and
-- laborious. We have carried this proof on the more complex and
-- interesting |IDesc| universe, in IDesc.agda.
--********************************************
-- Tagged description
--********************************************
TagDesc : {l : Level} -> Set (suc l)
TagDesc = Sigma En (\e -> spi e (\_ -> Desc))
de : TagDesc -> Desc
de (B , F) = sigma (EnumT B) (\E -> switch B (\_ -> Desc) F E)
--********************************************
-- Catamorphism
--********************************************
cata : (D : Desc)
(T : Set) ->
([| D |] T -> T) ->
(Mu D) -> T
cata D T phi x = ind D (\_ -> T) (\x ms -> phi (replace D T x ms)) x
where replace : (D' : Desc)(T : Set)(xs : [| D' |] (Mu D))(ms : All D' (Mu D) (\_ -> T) xs) -> [| D' |] T
replace id 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)
--********************************************
-- Free monad construction
--********************************************
_**_ : TagDesc -> (X : Set) -> TagDesc
(e , D) ** X = cE e , (const X , D)
--********************************************
-- Substitution
--********************************************
apply : (D : TagDesc)(X Y : Set) ->
(X -> Mu (de (D ** Y))) ->
[| de (D ** X) |] (Mu (de (D ** Y))) ->
Mu (de (D ** Y))
apply (E , B) X Y sig (EZe , x) = sig x
apply (E , B) X Y sig (ESu n , t) = con (ESu n , t)
subst : (D : TagDesc)(X Y : Set) ->
Mu (de (D ** X)) ->
(X -> Mu (de (D ** Y))) ->
Mu (de (D ** Y))
subst D X Y x sig = cata (de (D ** X)) (Mu (de (D ** Y))) (apply D X Y sig) x
| {
"alphanum_fraction": 0.4650167688,
"avg_line_length": 30.0243055556,
"ext": "agda",
"hexsha": "5fad120cd4d4473dd5a259268f5b0f4732b37924",
"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/Desc.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/Desc.agda",
"max_line_length": 129,
"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/Desc.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": 5595,
"size": 17294
} |
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
postulate +-comm : ∀ m n → m + n ≡ n + m
-- Note that the following does not work because
-- p+q is not abstracted over in `+-comm p q` which means
-- Agda gets stuck trying to unify `p + q` and `q + p`
-- Cf. test/Succeed/UsingEq.agda
rew : ∀ m n p q → m + (p + q) + n ≡ m + (q + p) + n
rew m n p q with p+q ← p + q with refl ← +-comm p q = refl
| {
"alphanum_fraction": 0.61352657,
"avg_line_length": 29.5714285714,
"ext": "agda",
"hexsha": "7b4b8aeaacb5eed03f0f23e0cacefc89f46998cd",
"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/UsingEq.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/UsingEq.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/UsingEq.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": 148,
"size": 414
} |
{-# OPTIONS --rewriting #-}
postulate _↦_ : ∀ {a} {A : Set a} → A → A → Set
{-# BUILTIN REWRITE _↦_ #-}
open import Agda.Primitive
postulate
mekker : Level → Level → Set
moomoo : Level → Set → Set
rew : (a b : Level) → moomoo (a ⊔ b) (mekker a b) ↦ (Level → Level)
{-# REWRITE rew #-}
works : {a b : Level} → moomoo (a ⊔ b) (mekker a b) → Level
works f = f lzero
fails : {a : Level} → moomoo a (mekker a a) → Level
fails f = f lzero
| {
"alphanum_fraction": 0.5752808989,
"avg_line_length": 22.25,
"ext": "agda",
"hexsha": "84596e371f3ccf3a4042c291274497e05cdd16b3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue2299.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue2299.agda",
"max_line_length": 69,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue2299.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 170,
"size": 445
} |
{-# OPTIONS --without-K #-}
-- Finite types and paths between them
module FT where
open import Data.Empty
open import Data.Unit
open import Data.Nat
open import Data.Sum
open import Data.Product
infixl 10 _◎_
------------------------------------------------------------------------------
-- Finite types
data FT : Set where
ZERO : FT
ONE : FT
PLUS : FT → FT → FT
TIMES : FT → FT → FT
⟦_⟧ : FT → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS B₁ B₂ ⟧ = ⟦ B₁ ⟧ ⊎ ⟦ B₂ ⟧
⟦ TIMES B₁ B₂ ⟧ = ⟦ B₁ ⟧ × ⟦ B₂ ⟧
------------------------------------------------------------------------------
-- Generalized paths are pi-combinators
data _⇛_ : FT → FT → Set where
-- additive structure
unite₊⇛ : { b : FT } → PLUS ZERO b ⇛ b
uniti₊⇛ : { b : FT } → b ⇛ PLUS ZERO b
swap₊⇛ : { b₁ b₂ : FT } → PLUS b₁ b₂ ⇛ PLUS b₂ b₁
assocl₊⇛ : { b₁ b₂ b₃ : FT } → PLUS b₁ (PLUS b₂ b₃) ⇛ PLUS (PLUS b₁ b₂) b₃
assocr₊⇛ : { b₁ b₂ b₃ : FT } → PLUS (PLUS b₁ b₂) b₃ ⇛ PLUS b₁ (PLUS b₂ b₃)
-- multiplicative structure
unite⋆⇛ : { b : FT } → TIMES ONE b ⇛ b
uniti⋆⇛ : { b : FT } → b ⇛ TIMES ONE b
swap⋆⇛ : { b₁ b₂ : FT } → TIMES b₁ b₂ ⇛ TIMES b₂ b₁
assocl⋆⇛ : { b₁ b₂ b₃ : FT } →
TIMES b₁ (TIMES b₂ b₃) ⇛ TIMES (TIMES b₁ b₂) b₃
assocr⋆⇛ : { b₁ b₂ b₃ : FT } →
TIMES (TIMES b₁ b₂) b₃ ⇛ TIMES b₁ (TIMES b₂ b₃)
-- distributivity
distz⇛ : { b : FT } → TIMES ZERO b ⇛ ZERO
factorz⇛ : { b : FT } → ZERO ⇛ TIMES ZERO b
dist⇛ : { b₁ b₂ b₃ : FT } →
TIMES (PLUS b₁ b₂) b₃ ⇛ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)
factor⇛ : { b₁ b₂ b₃ : FT } →
PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⇛ TIMES (PLUS b₁ b₂) b₃
-- congruence
id⇛ : { b : FT } → b ⇛ b
sym⇛ : { b₁ b₂ : FT } → (b₁ ⇛ b₂) → (b₂ ⇛ b₁)
_◎_ : { b₁ b₂ b₃ : FT } → (b₁ ⇛ b₂) → (b₂ ⇛ b₃) → (b₁ ⇛ b₃)
_⊕_ : { b₁ b₂ b₃ b₄ : FT } →
(b₁ ⇛ b₃) → (b₂ ⇛ b₄) → (PLUS b₁ b₂ ⇛ PLUS b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : FT } →
(b₁ ⇛ b₃) → (b₂ ⇛ b₄) → (TIMES b₁ b₂ ⇛ TIMES b₃ b₄)
------------------------------------------------------------------------------
-- An alternative interpretation, as a Functor.
⟦_⟧′ : FT → (Set → Set)
⟦ ZERO ⟧′ A = ⊥
⟦ ONE ⟧′ A = A
⟦ PLUS B₁ B₂ ⟧′ A = ⟦ B₁ ⟧′ A ⊎ ⟦ B₂ ⟧′ A
⟦ TIMES B₁ B₂ ⟧′ A = ⟦ B₁ ⟧′ A × ⟦ B₂ ⟧′ A
{--
Not used
BOOL-FT : Set
BOOL-FT = ⟦ PLUS ONE ONE ⟧
true-FT : BOOL-FT
true-FT = inj₁ tt
false-FT : BOOL-FT
false-FT = inj₂ tt
witness : (B : FT) → Maybe ⟦ B ⟧
witness ZERO = nothing
witness ONE = just tt
witness (PLUS B₁ B₂) with witness B₁ | witness B₂
... | nothing | nothing = nothing
... | nothing | just b = just (inj₂ b)
... | just b | _ = just (inj₁ b)
witness (TIMES B₁ B₂) with witness B₁ | witness B₂
... | nothing | _ = nothing
... | just b | nothing = nothing
... | just b₁ | just b₂ = just (b₁ , b₂)
elems : (B : FT) → List ⟦ B ⟧
elems ZERO = []
elems ONE = [ tt ]
elems (PLUS B₁ B₂) = map inj₁ (elems B₁) ++ map inj₂ (elems B₂)
elems (TIMES B₁ B₂) = concatMap
(λ e₁ → map (λ e₂ → (e₁ , e₂)) (elems B₂))
(elems B₁)
expandF : {B₁ B₂ : FT} → (⟦ B₁ ⟧ → ⟦ B₂ ⟧) → List (⟦ B₁ ⟧ × ⟦ B₂ ⟧)
expandF {B₁} {B₂} f = map (λ e → (e , f e)) (elems B₁)
test0 : List ((⊤ × BOOL-FT) × BOOL-FT)
test0 = expandF (unite⋆ {BOOL-FT})
--}
| {
"alphanum_fraction": 0.4720290293,
"avg_line_length": 29.2654867257,
"ext": "agda",
"hexsha": "e2fdc2500572f1a38eef0504f4819e0d79986ded",
"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/OldUnivalence/FT.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/OldUnivalence/FT.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/OldUnivalence/FT.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": 1450,
"size": 3307
} |
module sum where
open import level
open import bool
open import eq
open import maybe
open import product
----------------------------------------------------------------------
-- datatypes
----------------------------------------------------------------------
data _⊎_ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') : Set (ℓ ⊔ ℓ') where
inj₁ : (x : A) → A ⊎ B
inj₂ : (y : B) → A ⊎ B
_∨_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ')
_∨_ = _⊎_
----------------------------------------------------------------------
-- syntax
----------------------------------------------------------------------
infixr 0 _⊎_ _∨_
----------------------------------------------------------------------
-- operations
----------------------------------------------------------------------
_≫=⊎_ : ∀ {ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}{C : Set (ℓ ⊔ ℓ')} → A ⊎ B → (B → A ⊎ C) → A ⊎ C
inj₁ x ≫=⊎ f = inj₁ x
inj₂ x ≫=⊎ f = f x
return⊎ : ∀ {ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → B → A ⊎ B
return⊎ b = inj₂ b
infix 5 error⊎_
error⊎_ : ∀ {ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → A → A ⊎ B
error⊎_ a = inj₁ a
extract-inj₁≡ : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'}{a a' : A} → inj₁{B = B} a ≡ inj₁ a' → a ≡ a'
extract-inj₁≡ refl = refl
extract-inj₂≡ : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'}{b b' : B} → inj₂{A = A} b ≡ inj₂ b' → b ≡ b'
extract-inj₂≡ refl = refl
=⊎ : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'} → (A → A → 𝔹) → (B → B → 𝔹) → A ⊎ B → A ⊎ B → 𝔹
=⊎ eqa eqb (inj₁ a) (inj₁ a') = eqa a a'
=⊎ eqa eqb (inj₂ b) (inj₂ b') = eqb b b'
=⊎ _ _ _ _ = ff
=⊎-to-≡ : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'} → (_eqa_ : A → A → 𝔹) → (_eqb_ : B → B → 𝔹) → ((a a' : A) → (a eqa a' ≡ tt) → a ≡ a') → ((b b' : B) → (b eqb b' ≡ tt) → b ≡ b') → (x y : A ⊎ B) → =⊎ _eqa_ _eqb_ x y ≡ tt → x ≡ y
=⊎-to-≡ eqa eqb risea riseb (inj₁ a) (inj₁ a') p rewrite risea a a' p = refl
=⊎-to-≡ eqa eqb risea riseb (inj₂ b) (inj₂ b') p rewrite riseb b b' p = refl
=⊎-to-≡ eqa eqb risea riseb (inj₁ a) (inj₂ b) ()
=⊎-to-≡ eqa eqb risea riseb (inj₂ b) (inj₁ a) ()
≡⊎-to-= : ∀{ℓ}{ℓ'}{A : Set ℓ}{B : Set ℓ'} → (_eqa_ : A → A → 𝔹) → (_eqb_ : B → B → 𝔹) → ((a a' : A) → a ≡ a' → a eqa a' ≡ tt) → ((b b' : B) → b ≡ b' → b eqb b' ≡ tt) → (x y : A ⊎ B) → x ≡ y → =⊎ _eqa_ _eqb_ x y ≡ tt
≡⊎-to-= eqa eqb dropa dropb (inj₁ a) (inj₁ a') p = dropa a a' (extract-inj₁≡ p)
≡⊎-to-= eqa eqb dropa dropb (inj₂ b) (inj₂ b') p = dropb b b' (extract-inj₂≡ p)
≡⊎-to-= eqa eqb dropa dropb (inj₁ a) (inj₂ b) ()
≡⊎-to-= eqa eqb dropa dropb (inj₂ b) (inj₁ a) ()
| {
"alphanum_fraction": 0.3904333606,
"avg_line_length": 35.9705882353,
"ext": "agda",
"hexsha": "e54d26e2b39a7aca2af5e4094e5074e49937168d",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "sum.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "sum.agda",
"max_line_length": 222,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "sum.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 1191,
"size": 2446
} |
open import Nat
open import Prelude
open import List
open import contexts
open import core
open import lemmas-env
module preservation where
preservation : ∀{⛽ Δ Σ' Γ E e r k τ} →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' , Γ ⊢ e :: τ →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ k →
Δ , Σ' ⊢ r ·: τ
preservation ctxcons ta EFix = TAFix ctxcons ta
preservation ctxcons (TAVar tah) (EVar h) with env-all-Γ ctxcons tah
... | π3 , π4 , π5 rewrite ctxunicity h π4 = π5
preservation ctxcons (TAHole h) EHole = TAHole h ctxcons
preservation ctxcons TAUnit EUnit = TAUnit
preservation ctxcons (TAPair _ ta1 ta2) (EPair eval1 eval2)
= TAPair (preservation ctxcons ta1 eval1 ) (preservation ctxcons ta2 eval2)
preservation ctxcons (TACtor h1 h2 ta) (ECtor eval) = TACtor h1 h2 (preservation ctxcons ta eval)
preservation ctxcons (TAApp _ ta-f ta-arg) (EAppFix _ h eval1 eval2 eval-ef)
rewrite h
with preservation ctxcons ta-f eval1
... | TAFix ctxcons-Ef (TAFix ta-ef) =
preservation (EnvInd (EnvInd ctxcons-Ef (preservation ctxcons ta-f eval1)) (preservation ctxcons ta-arg eval2)) ta-ef eval-ef
preservation ctxcons (TAApp _ ta1 ta2) (EAppUnfinished eval1 _ eval2) =
TAApp (preservation ctxcons ta1 eval1) (preservation ctxcons ta2 eval2)
preservation ctxcons (TAFst ta) (EFst eval)
with preservation ctxcons ta eval
... | TAPair ta1 ta2 = ta1
preservation ctxcons (TAFst ta) (EFstUnfinished eval x)
= TAFst (preservation ctxcons ta eval)
preservation ctxcons (TASnd ta) (ESnd eval)
with preservation ctxcons ta eval
... | TAPair ta1 ta2 = ta2
preservation ctxcons (TASnd ta) (ESndUnfinished eval x)
= TASnd (preservation ctxcons ta eval)
preservation {Σ' = Σ'} ctxcons (TACase d∈Σ' ta h1 h2) (EMatch _ form eval-e eval-ec) with h2 form
... | _ , _ , _ , c∈cctx2 , ta-ec with preservation ctxcons ta eval-e
... | TACtor {cctx = cctx} d∈Σ'2 c∈cctx ta' with ctxunicity {Γ = π1 Σ'} d∈Σ' d∈Σ'2
... | refl with ctxunicity {Γ = cctx} c∈cctx c∈cctx2
... | refl = preservation (EnvInd ctxcons ta') ta-ec eval-ec
preservation ctxcons (TACase d∈Σ' ta h1 h2) (EMatchUnfinished eval h) =
TACase d∈Σ' ctxcons (preservation ctxcons ta eval) h1 λ form' →
let _ , _ , _ , p2 , p3 = h2 form' in
_ , p2 , p3
preservation ctxcons (TAAsrt _ ta1 ta2) (EAsrt eval1 eval2 _) = TAUnit
| {
"alphanum_fraction": 0.6649916248,
"avg_line_length": 46.8235294118,
"ext": "agda",
"hexsha": "0bafaf7510289f635524659f3a1769538e04448c",
"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": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnat-myth-",
"max_forks_repo_path": "preservation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"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/hazelnat-myth-",
"max_issues_repo_path": "preservation.agda",
"max_line_length": 129,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnat-myth-",
"max_stars_repo_path": "preservation.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-19T23:42:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-19T23:42:31.000Z",
"num_tokens": 858,
"size": 2388
} |
open import Common.IO
open import Common.Unit
open import Common.String
open import Common.Nat
record Stream (A : Set) : Set where
coinductive
field
head : A
tail : Stream A
open Stream public
repeat : Stream String
head repeat = "hello"
tail repeat = repeat
lookup : ∀ {A} → Stream A → Nat → A
lookup xs zero = xs .head
lookup xs (suc n) = lookup (xs .tail) n
main : IO Unit
main = putStr (lookup repeat 1000000)
| {
"alphanum_fraction": 0.6960556845,
"avg_line_length": 17.9583333333,
"ext": "agda",
"hexsha": "ec9c5303688ecb393e1a76cd6e754828e4fa7599",
"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": "026a8f8473ab91f99c3f6545728e71fa847d2720",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "xekoukou/agda-ocaml",
"max_forks_repo_path": "test/Compiler/simple/Coinduction2.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "026a8f8473ab91f99c3f6545728e71fa847d2720",
"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": "xekoukou/agda-ocaml",
"max_issues_repo_path": "test/Compiler/simple/Coinduction2.agda",
"max_line_length": 39,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "026a8f8473ab91f99c3f6545728e71fa847d2720",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "xekoukou/agda-ocaml",
"max_stars_repo_path": "test/Compiler/simple/Coinduction2.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": 126,
"size": 431
} |
-- | An implementation of the Marketoritative PCM
module Relation.Ternary.Separation.Construct.Market where
open import Level hiding (Lift)
open import Data.Product
open import Relation.Unary
open import Relation.Binary hiding (_⇒_)
open import Relation.Binary.PropositionalEquality as P
open import Relation.Ternary.Separation
open import Relation.Ternary.Separation.Morphisms
module _ {ℓ} (A : Set ℓ) where
data Market : Set ℓ where
offer : (l : A) → Market
demand : (r : A) → Market
module _ {ℓ} {A : Set ℓ} {{ sep : RawSep A }} {{ _ : IsSep sep }} where
data Split : Market A → Market A → Market A → Set ℓ where
offerₗ : {r l₁ l₂ : A} (σ : l₂ ⊎ r ≣ l₁) → Split (offer l₁) (demand r) (offer l₂)
offerᵣ : {r l₁ l₂ : A} (σ : r ⊎ l₂ ≣ l₁) → Split (demand r) (offer l₁) (offer l₂)
demand : {r₁ r₂ r : A} (σ : r₁ ⊎ r₂ ≣ r) → Split (demand r₁) (demand r₂) (demand r)
comm : ∀ {Φ₁ Φ₂ Φ} → Split Φ₁ Φ₂ Φ → Split Φ₂ Φ₁ Φ
comm (demand p) = demand (⊎-comm p)
comm (offerₗ σ) = offerᵣ (⊎-comm σ)
comm (offerᵣ σ) = offerₗ (⊎-comm σ)
assoc : ∀ {a b ab c abc} → Split a b ab → Split ab c abc → ∃ λ bc → (Split a bc abc) × (Split b c bc)
assoc (offerₗ σ₁) (offerₗ σ₂) =
let _ , σ₃ , σ₄ = ⊎-assoc σ₂ σ₁ in -, offerₗ σ₃ , demand (⊎-comm σ₄)
assoc (offerᵣ σ₁) (offerₗ σ₂) =
let _ , σ₃ , σ₄ = ⊎-unassoc σ₁ σ₂ in -, offerᵣ σ₃ , offerₗ σ₄
assoc (demand σ₁) (offerᵣ σ₂) =
let _ , σ₃ , σ₄ = ⊎-assoc (⊎-comm σ₁) σ₂ in -, offerᵣ σ₄ , offerᵣ σ₃
assoc (demand σ₁) (demand σ₂) =
let _ , σ₃ , σ₄ = ⊎-assoc σ₁ σ₂ in -, demand σ₃ , demand σ₄
instance market-raw-sep : RawSep (Market A)
RawSep._⊎_≣_ market-raw-sep = Split
instance market-has-sep : IsSep market-raw-sep
market-has-sep = record
{ ⊎-comm = comm
; ⊎-assoc = assoc
}
instance market-sep : Separation _
market-sep = record
{ isSep = market-has-sep }
module _ {a} {A : Set a} {{r : RawSep A}} {u} {{ s : IsUnitalSep r u }} where
module U = IsUnitalSep
instance market-is-unital : IsUnitalSep market-raw-sep (demand ε)
U.isSep market-is-unital = market-has-sep
U.⊎-idˡ market-is-unital {offer l} = offerᵣ ⊎-idˡ
U.⊎-idˡ market-is-unital {demand r} = demand ⊎-idˡ
U.⊎-id⁻ˡ market-is-unital (offerᵣ σ) = cong offer (sym (⊎-id⁻ˡ σ))
U.⊎-id⁻ˡ market-is-unital (demand σ) = cong demand (⊎-id⁻ˡ σ)
module _ {a} {{ s : MonoidalSep a }} where
open MonoidalSep s using () renaming (Carrier to A)
matching : ∀ {a b : A} {c d} → (demand a) ⊎ (offer b) ≣ c → (demand (d ∙ a)) ⊎ (offer (d ∙ b)) ≣ c
matching (offerᵣ σ) = offerᵣ (⊎-∙ₗ σ)
module _ {ℓ} {A : Set ℓ} {{_ : RawSep A}} where
private
variable
ℓv : Level
P Q : Pred (A × A) ℓv
[_]Completes : A → (A × A) → Set ℓ
[_]Completes x (y , z) = x ⊎ z ≣ y
data ● {p} (P : Pred (A × A) p) : Pred (Market A) (ℓ ⊔ p) where
lift : ∀ {xs l₂} → P xs → [ l₂ ]Completes xs → ● P (offer l₂)
●-map : ∀[ P ⇒ Q ] → ∀[ ● P ⇒ ● Q ]
●-map f (lift px le) = lift (f px) le
module _ {a} {A : Set a} {{r : RawSep A}} {u} {{s₁ : IsUnitalSep r u}} where
open Morphism
instance market : Morphism A (Market A)
j market = demand
j-⊎ market s = demand s
j-⊎⁻ market (demand σ) = -, refl , σ
module _ {a} {A : Set a} {{r : RawSep A}} {u} {{s₁ : IsUnitalSep r u}} where
open import Relation.Ternary.Separation.Construct.Product
open Morphism (market {A = A})
data ○ {p} (P : Pred (A × A) p) : Pred (Market A) (p) where
lift : ∀ {xs} → P (ε , xs) → ○ P (demand xs)
module _ {p q} {P : Pred A p} {Q : Pred (A × A) q} where
○≺●ₗ : ∀[ P ⇒ⱼ ● Q ─✴ ● (Π₂ P ✴ Q) ]
app (○≺●ₗ px) (lift qx σ₂) (offerᵣ σ₁) with ⊎-assoc (⊎-comm σ₁) σ₂
... | _ , σ₃ , σ₄ = lift (snd px ×⟨ ⊎-idˡ , σ₄ ⟩ qx ) σ₃
○≺●ᵣ : ∀[ ● (Π₂ P ✴ Q) ⇒ J P ✴ ● Q ]
○≺●ᵣ (lift (snd px ×⟨ σₗ , σᵣ ⟩ qx) σ₂) with ⊎-id⁻ˡ σₗ
... | refl with ⊎-unassoc σ₂ σᵣ
... | _ , σ₃ , σ₄ = inj px ×⟨ offerᵣ (⊎-comm σ₃) ⟩ lift qx σ₄
{- Complete with respect to a certain element -}
module _ {a} {A : Set a} {{r : RawSep A}} {u} {{ s : IsUnitalSep r u }} where
open import Relation.Ternary.Separation.Construct.Product
open Morphism (market {A = A})
record _◑_ {p q} (P : Pred A p) (Q : Pred (A × A) q) (Φ : A × A) : Set (a ⊔ p ⊔ q) where
constructor _◑⟨_⟩_
field
{Φp Φq} : _
px : P Φp
inc : proj₁ Φ ⊎ Φp ≣ Φq
qx : Q (Φq , proj₂ Φ)
-- the following cannot be proven unfortunately
-- _ : ∀[ (P ◑ Q₁) ✴ Q₂ ⇒ P ◑ (Q₁ ✴ Q₂) ]
absorb : ∀ {p q} {P : Pred A p} {Q : Pred (A × A) q} →
∀[ P ⇒ⱼ ● Q ─✴ ● (P ◑ Q) ]
app (absorb px) (lift qx k) (offerᵣ σ) with ⊎-assoc (⊎-comm σ) k
... | _ , σ₂ , σ₃ with ⊎-unassoc σ₂ (⊎-comm σ₃)
... | _ , σ₄ , σ₅ = lift (px ◑⟨ σ₅ ⟩ qx) σ₄
expell : ∀ {p q} {P : Pred A p} {Q : Pred (A × A) q} →
∀[ ● (P ◑ Q) ⇒ J P ✴ ● Q ]
expell (lift (px ◑⟨ τ₁ ⟩ qx) k) with ⊎-unassoc (⊎-comm τ₁) k
... | _ , τ₃ , τ₄ = (inj px) ×⟨ offerᵣ τ₃ ⟩ (lift qx τ₄)
{- Completion preserving updates -}
module _ {a} {A : Set a} {{r : RawSep A}} {u} {{ s : IsUnitalSep r u }} where
open import Relation.Ternary.Separation.Construct.Product
record ⟰_ {p} (P : Pred (A × A) p) (Φᵢ : A × A) : Set (a ⊔ p) where
constructor complete
field
updater : ∀ {Φⱼ Φₖ} →
Φᵢ ⊎ Φⱼ ≣ (Φₖ , Φₖ) →
∃₂ λ Φₗ Φ → Φₗ ⊎ Φⱼ ≣ (Φ , Φ) × P Φₗ
open ⟰_ public
●-update : ∀ {p q} {P : Pred (A × A) p} {Q : Pred (A × A) q} →
∀[ ○ (P ─✴ ⟰ Q) ⇒ ● P ─✴ ● Q ]
app (●-update (lift f)) (lift px σ₁) (offerᵣ σ₂) with ⊎-assoc (⊎-comm σ₂) σ₁
... | _ , σ₃ , σ₄ with updater (app f px (⊎-idˡ , σ₄)) (⊎-idʳ , ⊎-comm σ₃)
... | _ , _ , (σ₅ , σ₆) , qx with ⊎-id⁻ʳ σ₅
... | refl = lift qx (⊎-comm σ₆)
| {
"alphanum_fraction": 0.5391713092,
"avg_line_length": 35.2392638037,
"ext": "agda",
"hexsha": "caa5d4766e28b6e38ed359557b9a9513a3fe705a",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Relation/Ternary/Separation/Construct/Market.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"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": "laMudri/linear.agda",
"max_issues_repo_path": "src/Relation/Ternary/Separation/Construct/Market.agda",
"max_line_length": 103,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Relation/Ternary/Separation/Construct/Market.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 2610,
"size": 5744
} |
open import FRP.JS.List using ( List ; [] ; _∷_ ; build ) renaming ( length to llength )
open import FRP.JS.Char using ( Char ) renaming ( _<_ to _<C_ ; _≟_ to _≟C_ )
open import FRP.JS.Nat using ( ℕ )
open import FRP.JS.Bool using ( Bool ; true ; false ; _∧_ ; _∨_ )
module FRP.JS.String where
infixr 5 _++_
infix 4 _≟_
open import FRP.JS.Primitive public using ( String )
private
primitive
primStringAppend : String → String → String
primStringEquality : String → String → Bool
primStringToList : String → List Char
_++_ : String → String → String
_++_ = primStringAppend
{-# COMPILED_JS _++_ function(x) { return function(y) { return x + y; }; } #-}
_≟_ : String → String → Bool
_≟_ = primStringEquality
{-# COMPILED_JS _≟_ function(x) { return function(y) { return x === y; }; } #-}
buildChars : (ℕ → Char) → ℕ → List Char
buildChars = build
toList : String → List Char
toList = primStringToList
{-# COMPILED_JS toList function(s) {
return exports.buildChars(function(n) { return s.charAt(n); },s.length);
} #-}
length : String → ℕ
length s = llength (toList s)
{-# COMPILED_JS length function(s) { return s.length; } #-}
_<*_ : List Char → List Char → Bool
as <* [] = false
[] <* (b ∷ bs) = true
(a ∷ as) <* (b ∷ bs) = (a <C b) ∨ ((a ≟C b) ∧ (as <* bs))
_<_ : String → String → Bool
s < t = toList s <* toList t
{-# COMPILED_JS _<_ function(x) { return function(y) { return x < y; }; } #-}
_≤_ : String → String → Bool
s ≤ t = (s ≟ t) ∨ (s < t)
{-# COMPILED_JS _≤_ function(x) { return function(y) { return x <= y; }; } #-}
| {
"alphanum_fraction": 0.6125554851,
"avg_line_length": 27.1896551724,
"ext": "agda",
"hexsha": "e5323450deaf9954e3c2033e0b807b5b0150c2e6",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "src/agda/FRP/JS/String.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "src/agda/FRP/JS/String.agda",
"max_line_length": 88,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "src/agda/FRP/JS/String.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 519,
"size": 1577
} |
open import Level using () renaming (zero to ℓ₀)
open import Relation.Binary using (DecSetoid)
module BFFPlug (A : DecSetoid ℓ₀ ℓ₀) where
open import Data.Nat using (ℕ ; _≟_ ; _+_ ; zero ; suc ; ⌈_/2⌉)
open import Data.Maybe using (Maybe ; just ; nothing)
open import Data.Vec using (Vec)
open import Data.Product using (∃ ; _,_)
open import Relation.Binary using (module DecSetoid)
open import Relation.Binary.PropositionalEquality using (refl ; cong ; subst ; sym ; module ≡-Reasoning) renaming (setoid to PropEq)
open import Relation.Nullary using (yes ; no)
open import Function using (flip ; id ; _∘_)
open import Function.LeftInverse using (_RightInverseOf_)
import Category.Monad
open Category.Monad.RawMonad {ℓ₀} Data.Maybe.monad using (_>>=_)
open import Generic using (sequenceV ; ≡-to-Π)
import BFF
import GetTypes
import Examples
open DecSetoid A using (Carrier)
open GetTypes.PartialVecVec public using (Get)
open BFF.PartialVecBFF A public using (sbff ; bff)
bffsameshape : (G : Get) → {i : Get.I G} → Vec Carrier (Get.gl₁ G i) → Vec Carrier (Get.gl₂ G i) → Maybe (Vec Carrier (Get.gl₁ G i))
bffsameshape G {i} = sbff G i
bffplug : (G : Get) → (Get.I G → ℕ → Maybe (Get.I G)) → {i : Get.I G} → {m : ℕ} → Vec Carrier (Get.gl₁ G i) → Vec Carrier m → Maybe (∃ λ j → Vec (Maybe Carrier) (Get.gl₁ G j))
bffplug G sput {i} {m} s v with sput i m
... | nothing = nothing
... | just j with Get.gl₂ G j ≟ m
... | no gl₂j≢m = nothing
bffplug G sput {i} s v | just j | yes refl with bff G j s v
... | nothing = nothing
... | just s′ = just (j , s′)
_SimpleRightInvOf_ : {A B : Set} → (A → B) → (B → A) → Set
f SimpleRightInvOf g = ≡-to-Π f RightInverseOf ≡-to-Π g
bffinv : (G : Get) → (nelteg : ℕ → Get.I G) → nelteg SimpleRightInvOf Get.gl₂ G → {i : Get.I G} → {m : ℕ} → Vec Carrier (Get.gl₁ G i) → Vec Carrier m → Maybe (Vec (Maybe Carrier) (Get.gl₁ G (nelteg m)))
bffinv G nelteg inv {m = m} s v = bff G (nelteg m) s (subst (Vec Carrier) (sym (inv m)) v)
module InvExamples where
open Examples using (reverse' ; drop' ; sieve' ; tail' ; take')
reverse-put : {n m : ℕ} → Vec Carrier n → Vec Carrier m → Maybe (Vec Carrier m)
reverse-put s v = bffinv reverse' id (λ _ → refl) s v >>= sequenceV
drop-put : (k : ℕ) → {n m : ℕ} → Vec Carrier (k + n) → Vec Carrier m → Maybe (Vec (Maybe Carrier) (k + m))
drop-put k = bffinv (drop' k) id (λ _ → refl)
double : ℕ → ℕ
double zero = zero
double (suc n) = suc (suc (double n))
sieve-inv-len : double SimpleRightInvOf ⌈_/2⌉
sieve-inv-len zero = refl
sieve-inv-len (suc zero) = refl
sieve-inv-len (suc (suc x)) = cong (suc ∘ suc) (sieve-inv-len x)
sieve-put : {n m : ℕ} → Vec Carrier n → Vec Carrier m → Maybe (Vec (Maybe Carrier) (double m))
sieve-put = bffinv sieve' double sieve-inv-len
tail-put : {n m : ℕ} → Vec Carrier (suc n) → Vec Carrier m → Maybe (Vec (Maybe Carrier) (suc m))
tail-put = bffinv tail' id (λ _ → refl)
take-put : (k : ℕ) → {n : ℕ} → Vec Carrier (k + n) → Vec Carrier k → Maybe (Vec Carrier (k + n))
take-put k = bffsameshape (take' k)
| {
"alphanum_fraction": 0.6095003085,
"avg_line_length": 45.661971831,
"ext": "agda",
"hexsha": "0d697237a50883761d0f55a990562f27694c173d",
"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": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jvoigtlaender/bidiragda",
"max_forks_repo_path": "BFFPlug.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"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": "jvoigtlaender/bidiragda",
"max_issues_repo_path": "BFFPlug.agda",
"max_line_length": 202,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jvoigtlaender/bidiragda",
"max_stars_repo_path": "BFFPlug.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1072,
"size": 3242
} |
------------------------------------------------------------------------------
-- Subtraction using the rec combinator
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.LTC-PCF.Data.Nat.SubtractionRecCombinator where
open import Common.FOL.Relation.Binary.EqReasoning
open import LTC-PCF.Base
open import LTC-PCF.Base.Properties
open import LTC-PCF.Data.Nat.Properties hiding ( ∸-x0 )
open import LTC-PCF.Data.Nat.Rec
open import LTC-PCF.Data.Nat.Rec.ConversionRules
open import LTC-PCF.Data.Nat.Type
open import LTC-PCF.Data.Nat.UnaryNumbers
-- We add 3 to the fixities of the Agda standard library 0.8.1 (see
-- Data/Nat.agda).
infixl 9 _∸_
------------------------------------------------------------------------------
-- Subtraction
_∸_ : D → D → D
m ∸ n = rec n m (lam (λ _ → lam pred₁))
------------------------------------------------------------------------------
-- Conversion rules from the Agda standard library 0.8.1 (see
-- Data/Nat.agda).
∸-x0 : ∀ n → n ∸ zero ≡ n
∸-x0 n = rec zero n _ ≡⟨ rec-0 n ⟩
n ∎
∸-0S : ∀ {n} → N n → zero ∸ succ₁ n ≡ zero
∸-0S nzero =
rec [1] zero (lam (λ _ → lam pred₁))
≡⟨ rec-S zero zero (lam (λ _ → lam pred₁)) ⟩
lam (λ _ → lam pred₁) · zero · (zero ∸ zero)
≡⟨ ·-leftCong (beta (λ _ → lam pred₁) zero) ⟩
lam pred₁ · (zero ∸ zero)
≡⟨ beta pred₁ (zero ∸ zero) ⟩
pred₁ (zero ∸ zero)
≡⟨ predCong (∸-x0 zero) ⟩
pred₁ zero
≡⟨ pred-0 ⟩
zero ∎
∸-0S (nsucc {n} Nn) =
rec (succ₁ (succ₁ n)) zero (lam (λ _ → lam pred₁))
≡⟨ rec-S (succ₁ n) zero (lam (λ _ → lam pred₁)) ⟩
lam (λ _ → lam pred₁) · (succ₁ n) · (zero ∸ (succ₁ n))
≡⟨ ·-leftCong (beta (λ _ → lam pred₁) (succ₁ n)) ⟩
lam pred₁ · (zero ∸ (succ₁ n))
≡⟨ beta pred₁ (zero ∸ (succ₁ n)) ⟩
pred₁ (zero ∸ (succ₁ n))
≡⟨ predCong (∸-0S Nn) ⟩
pred₁ zero
≡⟨ pred-0 ⟩
zero ∎
∸-0x : ∀ {n} → N n → zero ∸ n ≡ zero
∸-0x nzero = ∸-x0 zero
∸-0x (nsucc Nn) = ∸-0S Nn
∸-SS : ∀ {m n} → N m → N n → succ₁ m ∸ succ₁ n ≡ m ∸ n
∸-SS {m} _ nzero =
rec [1] (succ₁ m) (lam (λ _ → lam pred₁))
≡⟨ rec-S zero (succ₁ m) (lam (λ _ → lam pred₁)) ⟩
lam (λ _ → lam pred₁) · zero · (succ₁ m ∸ zero)
≡⟨ ·-leftCong (beta (λ _ → lam pred₁) zero) ⟩
lam pred₁ · (succ₁ m ∸ zero)
≡⟨ beta pred₁ (succ₁ m ∸ zero) ⟩
pred₁ (succ₁ m ∸ zero)
≡⟨ predCong (∸-x0 (succ₁ m)) ⟩
pred₁ (succ₁ m)
≡⟨ pred-S m ⟩
m
≡⟨ sym (∸-x0 m) ⟩
m ∸ zero ∎
∸-SS nzero (nsucc {n} Nn) =
rec (succ₁ (succ₁ n)) [1] (lam (λ _ → lam pred₁))
≡⟨ rec-S (succ₁ n) [1] (lam (λ _ → lam pred₁)) ⟩
lam (λ _ → lam pred₁) · (succ₁ n) · ([1] ∸ succ₁ n)
≡⟨ ·-leftCong (beta (λ _ → lam pred₁) (succ₁ n)) ⟩
lam pred₁ · ([1] ∸ succ₁ n)
≡⟨ beta pred₁ ([1] ∸ succ₁ n) ⟩
pred₁ ([1] ∸ succ₁ n)
≡⟨ predCong (∸-SS nzero Nn) ⟩
pred₁ (zero ∸ n)
≡⟨ predCong (∸-0x Nn) ⟩
pred₁ zero
≡⟨ pred-0 ⟩
zero
≡⟨ sym (∸-0S Nn) ⟩
zero ∸ succ₁ n ∎
∸-SS (nsucc {m} Nm) (nsucc {n} Nn) =
rec (succ₁ (succ₁ n)) (succ₁ (succ₁ m)) (lam (λ _ → lam pred₁))
≡⟨ rec-S (succ₁ n) (succ₁ (succ₁ m)) (lam (λ _ → lam pred₁)) ⟩
lam (λ _ → lam pred₁) · (succ₁ n) · (succ₁ (succ₁ m) ∸ succ₁ n)
≡⟨ ·-leftCong (beta (λ _ → lam pred₁) (succ₁ n)) ⟩
lam pred₁ · (succ₁ (succ₁ m) ∸ succ₁ n)
≡⟨ beta pred₁ (succ₁ (succ₁ m) ∸ succ₁ n) ⟩
pred₁ (succ₁ (succ₁ m) ∸ succ₁ n)
≡⟨ predCong (∸-SS (nsucc Nm) Nn) ⟩
pred₁ (succ₁ m ∸ n)
≡⟨ sym (beta pred₁ (succ₁ m ∸ n)) ⟩
lam pred₁ · (succ₁ m ∸ n)
≡⟨ ·-leftCong (sym (beta (λ _ → lam pred₁) n)) ⟩
(lam (λ _ → lam pred₁)) · n · (succ₁ m ∸ n)
≡⟨ sym (rec-S n (succ₁ m) (lam (λ _ → lam pred₁))) ⟩
rec (succ₁ n) (succ₁ m) (lam (λ _ → lam pred₁))
≡⟨ refl ⟩
succ₁ m ∸ succ₁ n ∎
------------------------------------------------------------------------------
-- Conversion rules from the Agda standard library 0.8.1 (see
-- Data/Nat.agda) without totality hypotheses.
-- We could not prove this property.
-- ∸-0S₁ : ∀ n → zero ∸ succ₁ n ≡ zero
-- ∸-0S₁ n =
-- rec (succ₁ n) zero (lam (λ _ → lam pred₁))
-- ≡⟨ rec-S n zero (lam (λ _ → lam pred₁)) ⟩
-- lam (λ _ → lam pred₁) · n · (zero ∸ n)
-- ≡⟨ ·-leftCong (beta (λ _ → lam pred₁) n) ⟩
-- lam pred₁ · (zero ∸ n)
-- ≡⟨ beta pred₁ (zero ∸ n) ⟩
-- pred₁ (zero ∸ n)
-- ≡⟨ {!!} ⟩
-- {!!}
-- ≡⟨ {!!} ⟩
-- zero ∎
-- We could not prove this property.
-- ∸-SS₁ : ∀ m n → succ₁ m ∸ succ₁ n ≡ m ∸ n
-- ∸-SS₁ m n =
-- rec (succ₁ n) (succ₁ m) (lam (λ _ → lam pred₁))
-- ≡⟨ rec-S n (succ₁ m) (lam (λ _ → lam pred₁)) ⟩
-- lam (λ x → lam pred₁) · n · (succ₁ m ∸ n)
-- ≡⟨ ·-leftCong (beta (λ _ → lam pred₁) n) ⟩
-- lam pred₁ · (succ₁ m ∸ n)
-- ≡⟨ beta pred₁ (succ₁ m ∸ n) ⟩
-- pred₁ (succ₁ m ∸ n)
-- ≡⟨ {!!} ⟩
-- {!!}
-- ≡⟨ {!!} ⟩
-- m ∸ n ∎
------------------------------------------------------------------------------
-- Coq 8.4pl4 conversion rules (.../theories/Init/Peano.v):
-- Fixpoint minus (n m:nat) : nat :=
-- match n, m with
-- | O, _ => n
-- | S k, O => S k
-- | S k, S l => k - l
-- end
∸-x0-coq : ∀ n → n ∸ zero ≡ n
∸-x0-coq n = rec zero n _ ≡⟨ rec-0 n ⟩
n ∎
∸-S0-coq : ∀ n → succ₁ n ∸ zero ≡ succ₁ n
∸-S0-coq n =
rec zero (succ₁ n) (lam (λ _ → lam pred₁))
≡⟨ rec-0 (succ₁ n) ⟩
succ₁ n ∎
-- We could not prove this property.
-- ∸-SS-coq : ∀ m n → succ₁ m ∸ succ₁ n ≡ m ∸ n
-- ∸-SS-coq m n =
-- rec (succ₁ n) (succ₁ m) (lam (λ _ → lam pred₁))
-- ≡⟨ rec-S n (succ₁ m) (lam (λ _ → lam pred₁)) ⟩
-- lam (λ x → lam pred₁) · n · (succ₁ m ∸ n)
-- ≡⟨ ·-leftCong (beta (λ _ → lam pred₁) n) ⟩
-- lam pred₁ · (succ₁ m ∸ n)
-- ≡⟨ beta pred₁ (succ₁ m ∸ n) ⟩
-- pred₁ (succ₁ m ∸ n)
-- ≡⟨ {!!} ⟩
-- {!!}
-- ≡⟨ {!!} ⟩
-- m ∸ n ∎
------------------------------------------------------------------------------
-- Isabelle2014 conversion rules (from src/HOL/Nat.thy)
-- primrec minus_nat where
-- diff_0 [code]: "m - 0 = (m\<Colon>nat)"
-- | diff_Suc: "m - Suc n = (case m - n of 0 => 0 | Suc k => k)"
∸-x0-isabelle : ∀ n → n ∸ zero ≡ n
∸-x0-isabelle n = rec zero n _ ≡⟨ rec-0 n ⟩
n ∎
-- We could not prove this property.
-- ∸-xS-isabelle : ∀ m n → m ∸ succ₁ n ≡
-- if (iszero₁ (m ∸ n)) then zero else pred₁ (m ∸ n)
-- ∸-xS-isabelle m n =
-- rec (succ₁ n) m (lam (λ _ → lam pred₁))
-- ≡⟨ rec-S n m (lam (λ _ → lam pred₁)) ⟩
-- lam (λ x → lam pred₁) · n · (m ∸ n)
-- ≡⟨ ·-leftCong (beta (λ _ → lam pred₁) n) ⟩
-- lam pred₁ · (m ∸ n)
-- ≡⟨ beta pred₁ (m ∸ n) ⟩
-- pred₁ (m ∸ n)
-- ≡⟨ {!!} ⟩
-- if (iszero₁ (m ∸ n)) then zero else pred₁ (m ∸ n) ∎
------------------------------------------------------------------------------
-- Peter conversion rules
-- The analogous situation for subtraction is that given
-- rec-0 : ∀ a {f} → rec zero a f ≡ a
-- rec-S : ∀ n a f → rec (succ₁ n) a f ≡ f · n · (rec n a f)
-- and
-- _∸_ : D → D → D
-- m ∸ n = rec n m (lam (λ _ → lam pred₁))
-- you get the equations obtained by the special case (instantiate a
-- and f according to the def of subtraction)! This has nothing to do
-- a priori with the Agda standard library.
∸-x0-peter : ∀ n → n ∸ zero ≡ n
∸-x0-peter n = rec zero n _ ≡⟨ rec-0 n ⟩
n ∎
∸-xS-peter : ∀ m n → m ∸ succ₁ n ≡ pred₁ (m ∸ n)
∸-xS-peter m n =
rec (succ₁ n) m (lam (λ _ → lam pred₁))
≡⟨ rec-S n m (lam (λ _ → lam pred₁)) ⟩
lam (λ x → lam pred₁) · n · (m ∸ n)
≡⟨ ·-leftCong (beta (λ _ → lam pred₁) n) ⟩
lam pred₁ · (m ∸ n)
≡⟨ beta pred₁ (m ∸ n) ⟩
pred₁ (m ∸ n) ∎
| {
"alphanum_fraction": 0.4671909243,
"avg_line_length": 31.5325203252,
"ext": "agda",
"hexsha": "b3d6458acf2ec866b292587eb5cec8560f949afa",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/LTC-PCF/Data/Nat/SubtractionRecCombinator.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/LTC-PCF/Data/Nat/SubtractionRecCombinator.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/LTC-PCF/Data/Nat/SubtractionRecCombinator.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": 3231,
"size": 7757
} |
module Types4 where
open import Basics public
{-----------------------------------------------------------------------}
-- balanced search trees (based on my ICFP '14 paper
-- How to Keep Your Neighbours in Order
-- but the point here is to watch what the types buy us
{-----------------------------------------------------------------------}
-- compare natural numbers {- might we visit Basics.agda? -}
_<=_ : Nat -> Nat -> Set
ze <= y = One
su x <= ze = Zero
su x <= su y = x <= y
{-(-}
cmp : (x y : Nat) -> (x <= y) + (y <= x)
cmp ze y = inl <>
cmp (su x) ze = inr <>
cmp (su x) (su x₁) = cmp x x₁
{-)-}
{-----------------------------------------------------------------------}
-- loose bounds (one good idea, not always obvious)
data Bnd : Set where
bot : Bnd
# : Nat -> Bnd
top : Bnd
_<B=_ : Bnd -> Bnd -> Set
bot <B= _ = One
# x <B= # y = x <= y
_ <B= top = One
_ <B= _ = Zero
-- an interval lets you choose a number that fits in some bounds
data Intv (l u : Bnd) : Set where
intv : (x : Nat)(lx : l <B= # x)(xu : # x <B= u) -> Intv l u
{-----------------------------------------------------------------------}
-- 2-3-trees, indexed by bounds and height
data T23 (l u : Bnd) : (h : Nat) -> Set where
leaf : (lu : l <B= u) ->
T23 l u ze
node2 : forall {h} x
(tlx : T23 l (# x) h)(txu : T23 (# x) u h) ->
T23 l u (su h)
node3 : forall {h} x y
(tlx : T23 l (# x) h)(txy : T23 (# x) (# y) h)(tyu : T23 (# y) u h) ->
T23 l u (su h)
{-----------------------------------------------------------------------}
-- insertion
TooBig : Bnd -> Bnd -> Nat -> Set
TooBig l u h = Sg Nat \ x -> T23 l (# x) h * T23 (# x) u h
{-(-}
insert : forall {h l u} -> Intv l u -> T23 l u h ->
TooBig l u h + T23 l u h
insert (intv x lx xu) (leaf lu) = {!!}
insert (intv x lx xu) (node2 x₁ t t₁) = {!!}
insert (intv x lx xu) (node3 y z tly tyz tzu) with cmp x y
insert (intv x lx xu) (node3 y z tly tyz tzu) | inl xy with insert (intv x lx xy) tly
insert (intv x lx xu) (node3 y z tly tyz tzu) | inl xy | inl (v , tlv , tvy)
= inl (y , node2 v tlv tvy , node2 z tyz tzu)
insert (intv x lx xu) (node3 y z tly tyz tzu) | inl xy | inr x₁ = {!!}
insert (intv x lx xu) (node3 y z tly tyz tzu) | inr x₁ = {!!}
{-)-}
{-----------------------------------------------------------------------}
-- confession
-- it took me about fifteen years to come up with that type for insert
{-----------------------------------------------------------------------}
-- question (0)
-- how can we make better use of the way types act as "problem statement?"
{-----------------------------------------------------------------------}
-- question (1)
-- how can we make better use of the way types act as "problem statement?"
-- programmers should profit from the downpayment and focus on
-- the actual choices
{-----------------------------------------------------------------------}
-- question (2)
-- how can we make better use of the way types act as "problem statement?"
-- programmers should profit from the downpayment and focus on
-- the actual choices
-- "code" should be a readable record of a problem solving interaction
{-----------------------------------------------------------------------}
-- question (3)
-- how can we make better use of the way types act as "problem statement?"
-- programmers should profit from the downpayment and focus on
-- the actual choices
-- "code" should be a readable record of a problem solving interaction
-- we need tools to support redesign
{-----------------------------------------------------------------------}
-- an incomplete program is a formal document
| {
"alphanum_fraction": 0.4493357645,
"avg_line_length": 13.5176056338,
"ext": "agda",
"hexsha": "6b3ded3f6c8da65d66476a74b9b4cab0474d5347",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-06-09T05:39:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-09T05:39:02.000Z",
"max_forks_repo_head_hexsha": "21ac5be5a0a04fc75699d595c08b5ae4b7d7712d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "pigworker/WhatRTypes4",
"max_forks_repo_path": "Types4.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "21ac5be5a0a04fc75699d595c08b5ae4b7d7712d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "pigworker/WhatRTypes4",
"max_issues_repo_path": "Types4.agda",
"max_line_length": 85,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "21ac5be5a0a04fc75699d595c08b5ae4b7d7712d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "pigworker/WhatRTypes4",
"max_stars_repo_path": "Types4.agda",
"max_stars_repo_stars_event_max_datetime": "2019-06-09T05:38:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-11T09:12:25.000Z",
"num_tokens": 1031,
"size": 3839
} |
{-# OPTIONS --cubical --allow-unsolved-metas #-}
module TranspPiOnMeta where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
-- Transporting along a function type with unknown sort of
-- domain/codomain shouldn't result into an impossible being thrown.
-- We equate to Set to trigger reduction.
test1 : (primTransp (\ i → (x : {!!}) → {!!}) i0 {!!} {!!}) ≡ Set
test1 i = Set
test2 : (primTransp (\ i → (x : Set) → {!!}) i0 {!!} {!!}) ≡ Set
test2 i = Set
Foo : Set₂
Foo = {!!}
test3 : (primTransp (\ i → (x : {!!}) → Foo) i0 {!!} {!!}) ≡ Set
test3 i = Set
| {
"alphanum_fraction": 0.6118644068,
"avg_line_length": 22.6923076923,
"ext": "agda",
"hexsha": "ec5dc9252c96bd226e6981796bad4169226b5400",
"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/TranspPiOnMeta.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/TranspPiOnMeta.agda",
"max_line_length": 68,
"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/TranspPiOnMeta.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": 190,
"size": 590
} |
{-# OPTIONS --safe #-}
module tmp where
open import Relation.Nullary
open import Data.List public
data Suf {X : Set} : List X → List X → Set where
sinit : ∀ l → Suf l l
scons : ∀ x l l' → Suf l l' → Suf (x ∷ l) l'
lemma : ∀ {X} (x : X) l l' → Suf l (x ∷ l') → Suf l l'
lemma x .(x ∷ l') l' (sinit .(x ∷ l')) = scons x l' l' (sinit l')
lemma x .(x₁ ∷ l) l' (scons x₁ l .(x ∷ l') H) = scons x₁ l l' (lemma x l l' H)
less-is-not-more : ∀ {X} x (l : List X) → ¬ Suf l (x ∷ l)
less-is-not-more x [] = λ ()
less-is-not-more x (x₁ ∷ l) (scons .x₁ .l .(x ∷ x₁ ∷ l) H) = less-is-not-more x₁ l (lemma x l (x₁ ∷ l) H)
| {
"alphanum_fraction": 0.5218800648,
"avg_line_length": 30.85,
"ext": "agda",
"hexsha": "92d81b65d8a67b1fc250661a6aa6281ba6becee3",
"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/tmp.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/tmp.agda",
"max_line_length": 105,
"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/tmp.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": 274,
"size": 617
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Group
open import lib.types.Unit
open import lib.groups.Homomorphisms
open import lib.groups.Lift
module lib.groups.Unit where
Unit-group-structure : GroupStructure Unit
Unit-group-structure = record
{ ident = unit
; inv = λ _ → unit
; comp = λ _ _ → unit
; unitl = λ _ → idp
; unitr = λ _ → idp
; assoc = λ _ _ _ → idp
; invr = λ _ → idp
; invl = λ _ → idp
}
Unit-group : Group lzero
Unit-group = group _ Unit-is-set Unit-group-structure
Lift-Unit-group : ∀ {i} → Group i
Lift-Unit-group = Lift-group Unit-group
0ᴳ = Lift-Unit-group
contr-is-0ᴳ : ∀ {i} (G : Group i) → is-contr (Group.El G) → G == 0ᴳ
contr-is-0ᴳ G pA = group-ua
(group-hom (λ _ → lift unit) (λ _ _ → idp) , snd (contr-equiv-LiftUnit pA))
0ᴳ-hom-out-level : ∀ {i j} {G : Group i}
→ is-contr (0ᴳ {j} →ᴳ G)
0ᴳ-hom-out-level {G = G} =
(cst-hom ,
λ φ → hom= _ _ (λ= (λ {(lift unit) → ! (GroupHom.pres-ident φ)})))
0ᴳ-hom-in-level : ∀ {i j} {G : Group i}
→ is-contr (G →ᴳ 0ᴳ {j})
0ᴳ-hom-in-level {G = G} =
(cst-hom , λ φ → hom= _ _ (λ= (λ _ → idp)))
| {
"alphanum_fraction": 0.6053333333,
"avg_line_length": 25,
"ext": "agda",
"hexsha": "02c3e26fd698a37d19bbc8bfc55ff81457f58b89",
"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": "core/lib/groups/Unit.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": "core/lib/groups/Unit.agda",
"max_line_length": 77,
"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": "core/lib/groups/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 448,
"size": 1125
} |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Library.Data.Product where
open import Light.Level using (Level ; Setω)
open import Light.Variable.Sets
open import Light.Variable.Levels
import Light.Library.Data.Both as Both
open import Light.Library.Relation.Binary
using (SelfTransitive ; SelfSymmetric ; Reflexive)
open import Light.Library.Relation.Binary.Equality.Decidable using (DecidableEquality)
record Dependencies : Setω where
record Library (dependencies : Dependencies) : Setω where
field
ℓf : Level → Level → Level
Σ : ∀ (𝕒 : Set aℓ) → (𝕒 → Set bℓ) → Set (ℓf aℓ bℓ)
both : ∀ {𝕓 : 𝕒 → Set bℓ} a (b : 𝕓 a) → Σ 𝕒 𝕓
first : ∀ {𝕓 : 𝕒 → Set bℓ} → Σ 𝕒 𝕓 → 𝕒
second : ∀ {𝕓 : 𝕒 → Set bℓ} (product : Σ 𝕒 𝕓) → 𝕓 (first product)
⦃ equals ⦄ :
∀ ⦃ a‐c‐equals : DecidableEquality 𝕒 𝕔 ⦄ ⦃ b‐d‐equals : DecidableEquality 𝕓 𝕕 ⦄
→ DecidableEquality (Σ 𝕒 (λ _ → 𝕓)) (Σ 𝕔 (λ _ → 𝕕))
∃ : ∀ {𝕒 : Set aℓ} → (𝕒 → Set bℓ) → Set (ℓf aℓ bℓ)
∃ = Σ _
instance both‐library : Both.Library record {}
both‐library = record
{
Both = λ 𝕒 𝕓 → Σ 𝕒 (λ _ → 𝕓) ;
ℓf = ℓf ;
both = both ;
first = first ;
second = second ;
equals = equals
}
open Library ⦃ ... ⦄ public
| {
"alphanum_fraction": 0.5334233626,
"avg_line_length": 36.1219512195,
"ext": "agda",
"hexsha": "59375b404ae368d8093c50e35ff5e6b6dc7113a8",
"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": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Library/Data/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Library/Data/Product.agda",
"max_line_length": 97,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Library/Data/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 498,
"size": 1481
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An irrelevant version of ⊥-elim
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Empty.Irrelevant where
open import Data.Empty hiding (⊥-elim)
⊥-elim : ∀ {w} {Whatever : Set w} → .⊥ → Whatever
⊥-elim ()
| {
"alphanum_fraction": 0.3989637306,
"avg_line_length": 25.7333333333,
"ext": "agda",
"hexsha": "3cc0d65669156dee5eede5eab1aa0114b08b569a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Empty/Irrelevant.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/Empty/Irrelevant.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Empty/Irrelevant.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": 80,
"size": 386
} |
module _^_ where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
open import Naturals using (ℕ; zero; suc; _*_)
_^_ : ℕ → ℕ → ℕ
_ ^ zero = 1
m ^ (suc n) = m * (m ^ n)
_ : 3 ^ 4 ≡ 81
_ =
begin
3 ^ 4
≡⟨⟩
3 * (3 ^ 3)
≡⟨⟩
3 * (3 * (3 ^ 2))
≡⟨⟩
3 * (3 * (3 * (3 ^ 1)))
≡⟨⟩
3 * (3 * (3 * (3 * (3 ^ 0))))
≡⟨⟩
3 * (3 * (3 * (3 * 1)))
≡⟨⟩
81
∎
| {
"alphanum_fraction": 0.4175824176,
"avg_line_length": 15.1666666667,
"ext": "agda",
"hexsha": "8a3749acc9e4e37289716e07a136b72a7bb365af",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/naturals/_^_.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/naturals/_^_.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/naturals/_^_.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 242,
"size": 455
} |
-- Andreas, 2011-10-03
-- Defining a universe for dependent types
-- where the El function only depends on the type code but not on its
-- proof of well-formedness
{-# OPTIONS --experimental-irrelevance --show-implicit --show-irrelevant #-}
module TerminationOnIrrelevantArgument where
data ⊥ : Set where
data D : Set where
empty : D
pi : D -> D -> D
other : D
postulate
app : D -> D -> D
mutual
data Ty : D -> Set where
Empty : Ty empty
Pi : (a f : D) ->
(A : Ty a) ->
(F : (d : D) -> .(El a A d) -> Ty (app f d)) ->
Ty (pi a f)
El : (a : D) -> .(A : Ty a) -> D -> Set
El empty Empty g = ⊥
El (pi a f) (Pi .a .f A F) g = (d : D) -> .(Ad : El a A d) ->
El (app f d) (F d Ad) (app g d)
El other () g
-- Termination checking needs to look inside irrelevant arguments.
-- This only works because the termination checker is syntactic
-- and does not respect equality of irrelevant things!
-- clearly, the derivation of Ty a does not matter when computing El
cast : (a : D)(A A' : Ty a)(d : D) -> El a A d -> El a A' d
cast a A A' d x = x
| {
"alphanum_fraction": 0.5524296675,
"avg_line_length": 27.2790697674,
"ext": "agda",
"hexsha": "075a40d8a3c472322e6437ac720e9198194fde61",
"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": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/TerminationOnIrrelevantArgument.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/TerminationOnIrrelevantArgument.agda",
"max_line_length": 76,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/TerminationOnIrrelevantArgument.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 365,
"size": 1173
} |
{-# OPTIONS --rewriting --prop #-}
open import Agda.Builtin.Nat
data ⊥ : Prop where
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
{-# BUILTIN REWRITE _≡_ #-}
infix 4 _≡_
⊥-elim : {A : Set} → ⊥ → A
⊥-elim ()
ok : (n : Nat) (p : ⊥) → (n + n) ≡ 0
ok n p = ⊥-elim p
{-# REWRITE ok #-}
notok : (n : Nat) → n + n ≡ 0
notok n = refl
absurd : 2 ≡ 0
absurd = notok 1
| {
"alphanum_fraction": 0.5039577836,
"avg_line_length": 14.5769230769,
"ext": "agda",
"hexsha": "b44ab8a41e9dc68bd7ffd737888df325d6412408",
"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/Issue4371.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/Issue4371.agda",
"max_line_length": 42,
"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/Issue4371.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": 174,
"size": 379
} |
module SystemF.Syntax.Term where
open import Prelude
open import SystemF.Syntax.Type
infixl 9 _[_] _·_
data Term (ν n : ℕ) : Set where
var : (x : Fin n) → Term ν n
Λ : Term (suc ν) n → Term ν n
λ' : Type ν → Term ν (suc n) → Term ν n
_[_] : Term ν n → Type ν → Term ν n
_·_ : Term ν n → Term ν n → Term ν n
| {
"alphanum_fraction": 0.5889570552,
"avg_line_length": 25.0769230769,
"ext": "agda",
"hexsha": "f603a812522c539c4d6a059b1659c15be388d651",
"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/SystemF/Syntax/Term.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/SystemF/Syntax/Term.agda",
"max_line_length": 43,
"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/SystemF/Syntax/Term.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": 127,
"size": 326
} |
module Mockingbird.Forest.Base where
open import Algebra using (Op₂; Congruent₂; LeftCongruent; RightCongruent)
open import Level using (_⊔_) renaming (suc to lsuc)
open import Relation.Binary using (Rel; IsEquivalence; Setoid)
open import Relation.Nullary using (¬_)
record IsForest {b ℓ} (Bird : Set b) (_≈_ : Rel Bird ℓ) (_∙_ : Op₂ Bird) : Set (b ⊔ ℓ) where
field
isEquivalence : IsEquivalence _≈_
cong : Congruent₂ _≈_ _∙_
open IsEquivalence isEquivalence public
setoid : Setoid b ℓ
setoid = record { isEquivalence = isEquivalence }
congˡ : LeftCongruent _≈_ _∙_
congˡ A≈B = cong refl A≈B
congʳ : RightCongruent _≈_ _∙_
congʳ A≈B = cong A≈B refl
record Forest {b ℓ} : Set (lsuc (b ⊔ ℓ)) where
infix 4 _≈_
infixl 6 _∙_
field
Bird : Set b
_≈_ : Rel Bird ℓ
_∙_ : Op₂ Bird
isForest : IsForest Bird _≈_ _∙_
_≉_ : Rel Bird ℓ
x ≉ y = ¬ (x ≈ y)
open IsForest isForest public
import Relation.Binary.Reasoning.Base.Single _≈_ refl trans as Base
open Base using (begin_; _∎) public
infixr 2 _≈⟨⟩_ step-≈ step-≈˘
_≈⟨⟩_ : ∀ x {y} → x Base.IsRelatedTo y → x Base.IsRelatedTo y
_ ≈⟨⟩ x≈y = x≈y
step-≈ = Base.step-∼
syntax step-≈ x y≈z x≈y = x ≈⟨ x≈y ⟩ y≈z
step-≈˘ : ∀ x {y z} → y Base.IsRelatedTo z → y ≈ x → x Base.IsRelatedTo z
step-≈˘ x y∼z y≈x = x ≈⟨ sym y≈x ⟩ y∼z
syntax step-≈˘ x y≈z y≈x = x ≈˘⟨ y≈x ⟩ y≈z
| {
"alphanum_fraction": 0.6342692585,
"avg_line_length": 26.2075471698,
"ext": "agda",
"hexsha": "1db0bdc8478cdb2e2fe60699328d63ca48c729be",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "splintah/combinatory-logic",
"max_forks_repo_path": "Mockingbird/Forest/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "splintah/combinatory-logic",
"max_issues_repo_path": "Mockingbird/Forest/Base.agda",
"max_line_length": 92,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "splintah/combinatory-logic",
"max_stars_repo_path": "Mockingbird/Forest/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z",
"num_tokens": 612,
"size": 1389
} |
module Data.BitVector where
open import Algebra.FunctionProperties.Core using (Op₁; Op₂)
open import Data.Bool public hiding (_≟_) renaming (Bool to Bit; false to 0#; true to 1#)
open import Data.Nat using (ℕ)
renaming (_+_ to _N+_; _*_ to _N*_; zero to Nzero; suc to Nsuc)
open import Data.Product using (_,_; _×_)
open import Data.Vec using (Vec; _∷_; []; map; tail; zipWith)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
infixl 6 _+_
infixl 7 _*_
infix 8 -_
BitVector = Vec Bit
bitwise-and : ∀ {n} → Op₂ (BitVector n)
bitwise-and = zipWith _∧_
bitwise-or : ∀ {n} → Op₂ (BitVector n)
bitwise-or = zipWith _∨_
half-adder : Bit → Bit → Bit × Bit
half-adder x y = x xor y , x ∧ y
full-adder : Bit → Bit → Bit → Bit × Bit
full-adder a b c0 with half-adder a b
... | s0 , c1 with half-adder s0 c0
... | s1 , c2 = s1 , c1 ∨ c2
add′ : ∀ {n} → Bit → BitVector n → BitVector n → BitVector n
add′ c [] [] = []
add′ c (x ∷ xs) (y ∷ ys) with full-adder x y c
... | s , cout = s ∷ add′ cout xs ys
_+_ : ∀ {n} → Op₂ (BitVector n)
x + y = add′ 0# x y
zero : ∀ n → BitVector n
zero Nzero = []
zero (Nsuc n) = 0# ∷ (zero n)
one : ∀ n → BitVector n
one Nzero = []
one (Nsuc n) = 1# ∷ zero n
bitwise-negation : ∀ {n} → Op₁ (BitVector n)
bitwise-negation = map not
ones : ∀ n → BitVector n
ones n = bitwise-negation (zero n)
droplast : ∀ {n} → BitVector (Nsuc n) → BitVector n
droplast {Nzero} _ = []
droplast {Nsuc n} (x ∷ xs) = x ∷ droplast xs
last : ∀ {n} → BitVector (Nsuc n) → Bit
last (x ∷ []) = x
last {Nsuc n} (x ∷ xs) = last xs
shift : ∀ {n} → Op₁ (BitVector n)
shift {Nzero} xs = xs
shift {Nsuc n} xs = 0# ∷ droplast xs
snoc : ∀ {n} → BitVector n → Bit → BitVector (Nsuc n)
snoc [] b = b ∷ []
snoc (x ∷ xs) b = x ∷ snoc xs b
unshift : ∀ {n} → Op₁ (BitVector n)
unshift [] = []
unshift (x ∷ xs) = snoc xs 0#
rotate : ∀ {n} → Op₁ (BitVector n)
rotate [] = []
rotate {Nsuc n} xs = last xs ∷ droplast xs
unrotate : ∀ {n} → Op₁ (BitVector n)
unrotate [] = []
unrotate (x ∷ xs) = snoc xs x
_*_ : ∀ {n} → Op₂ (BitVector n)
[] * [] = []
(0# ∷ xs) * yys = 0# ∷ xs * droplast yys
(1# ∷ xs) * yys = yys + (0# ∷ xs * droplast yys)
-_ : ∀ {n} → Op₁ (BitVector n)
- x = one _ + bitwise-negation x
open import Relation.Nullary
open import Relation.Binary
infix 4 _≟_
_≟_ : ∀ {n} → Decidable {A = BitVector n} _≡_
[] ≟ [] = yes refl
x ∷ xs ≟ y ∷ ys with xs ≟ ys
0# ∷ xs ≟ 0# ∷ .xs | yes refl = yes refl
1# ∷ xs ≟ 1# ∷ .xs | yes refl = yes refl
1# ∷ xs ≟ 0# ∷ ys | yes _ = no λ()
0# ∷ xs ≟ 1# ∷ ys | yes _ = no λ()
... | no pf = no (λ q → pf (cong tail q))
val1 = 1# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ []
val2 = 0# ∷ 1# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ []
val8 = 0# ∷ 0# ∷ 0# ∷ 1# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ []
val10 = 0# ∷ 1# ∷ 0# ∷ 1# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ []
val11 = 1# ∷ 1# ∷ 0# ∷ 1# ∷ 0# ∷ 0# ∷ 0# ∷ 0# ∷ []
| {
"alphanum_fraction": 0.5458953931,
"avg_line_length": 25.1043478261,
"ext": "agda",
"hexsha": "9c8b547032521ce4cfe162aace8106c66a4e8980",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-11-12T01:40:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-25T00:15:43.000Z",
"max_forks_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "copumpkin/bitvector",
"max_forks_repo_path": "Data/BitVector.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_issues_repo_issues_event_max_datetime": "2016-05-25T02:00:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-05-25T02:00:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "copumpkin/bitvector",
"max_issues_repo_path": "Data/BitVector.agda",
"max_line_length": 89,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/bitvector",
"max_stars_repo_path": "Data/BitVector.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-12T01:41:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T07:19:55.000Z",
"num_tokens": 1281,
"size": 2887
} |
module Subst (Gnd : Set)(U : Set)(El : U -> Set) where
open import Basics
open import Pr
open import Nom
import Kind
open Kind Gnd U El
import Cxt
open Cxt Kind
import Loc
open Loc Kind
import Term
open Term Gnd U El
import Shift
open Shift Gnd U El
import Inst
open Inst Gnd U El
data _-[_]_ : Cxt -> Kind -> Cxt -> Set where
ES : {D : Cxt}{C : Kind} -> EC -[ C ] D
_[_-_:=_] : {G D : Cxt}{C : Kind} -> (G -[ C ] D) ->
(x : Nom){Gx : [| G Hasn't x |]}(S : Kind) ->
D [! C !]- S ->
(G [ x - S ]){Gx} -[ C ] D
fetch : {G D : Cxt}{C S : Kind} -> (G -[ C ] D) ->
Nom :- GooN G S -> D [! C !]- S
fetch ES [ x / () ]
fetch (g [ x - S := s ]) [ y / p ] with nomEq x y
fetch (g [ x - S := s ]) [ .x / refl ] | yes refl = s
fetch (g [ x - S := s ]) [ y / p ] | no n = fetch g [ y / p ]
closed : {G : Cxt}{L : Loc}{T : Kind} ->
G [ EL / Head ]- T -> G [ L / Head ]- T
closed (` x -! xg) = ` x -! xg
closed (# () -! _)
mutual
wsubst : {C : Kind}{G D : Cxt} -> (G -[ C ] D) ->
{L : Loc}{T : Kind}(t : L [ Term C ]- T) -> [| Good G t |] ->
D [ L / Term C ]- T
wsubst g [ s ] sg = G[ wsubsts g s sg ]
wsubst g (fn A f) fg = Gfn A \ a -> wsubst g (f a) (fg a)
wsubst g (\\ b) bg = G\\ (wsubst g b bg)
wsubst g (# v $ s) pg = (# v -! _) G$ wsubsts g s (snd pg)
wsubst g (` x $ s) pg =
go (shift closed (fetch g [ x / fst pg ])) (wsubsts g s (snd pg))
wsubsts : {C : Kind}{G D : Cxt} -> (G -[ C ] D) ->
{L : Loc}{Z : Gnd}{S : Kind}
(s : L [ Args C Z ]- S) -> [| Good G s |] ->
D [ L / Args C Z ]- S
wsubsts g (a ^ s) sg = a G^ wsubsts g s sg
wsubsts g (r & s) pg = wsubst g r (fst pg) G& wsubsts g s (snd pg)
wsubsts g nil _ = Gnil
subst : {C : Kind}{G D : Cxt} -> (G -[ C ] D) ->
{L : Loc}{T : Kind} -> G [ L / Term C ]- T -> D [ L / Term C ]- T
subst g (t -! tg) = wsubst g t tg
| {
"alphanum_fraction": 0.4433573635,
"avg_line_length": 31.3225806452,
"ext": "agda",
"hexsha": "291b8479737b90d87b15dca9ace739f00831198b",
"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": "benchmark/Syntacticosmos/Subst.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": "benchmark/Syntacticosmos/Subst.agda",
"max_line_length": 73,
"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": "benchmark/Syntacticosmos/Subst.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": 792,
"size": 1942
} |
{-# OPTIONS --without-K #-}
module Ch2-4 where
open import Level hiding (lift)
open import Ch2-1
open import Ch2-2
open import Ch2-3
-- Definition 2.4.1 (homotopy)
infixl 8 _~_
_~_ : ∀ {a b} {A : Set a} {P : A → Set b}
→ (f g : (z : A) → P z)
→ Set (a ⊔ b)
_~_ {a} {b} {A} {P} f g = ∀ (x : A) → f x ≡ g x
-- Lemma 2.4.2
open import Relation.Binary
~-isEquivalence : ∀ {a b} {A : Set a} {P : A → Set b} → IsEquivalence (_~_ {A = A} {P})
~-isEquivalence = record
{ refl = ~-refl
; sym = ~-sym
; trans = ~-trans
}
where
~-refl : Reflexive _~_
~-refl f = refl
~-sym : Symmetric _~_
~-sym i~j x = ¬ (i~j x)
~-trans : Transitive _~_
~-trans i~j j~k x = i~j x ∙ j~k x
~-setoid : ∀ {a b} → (A : Set a) → (P : A → Set b) → Setoid _ _
~-setoid {a} {b} A P = record
{ Carrier = _
; _≈_ = _~_ {a} {b} {A} {P}
; isEquivalence = ~-isEquivalence {a} {b} {A} {P}
}
open import Function using (id; _∘_)
∘-cong-right : ∀ {a} {b} {c} {A : Set a} {B : Set b} {C : Set c} {g h : A → B}
→ (f : B → C)
→ g ~ h
→ f ∘ g ~ f ∘ h
∘-cong-right f g~h x = ap f (g~h x)
∘-cong-left : ∀ {a} {b} {c} {A : Set a} {B : Set b} {C : Set c} {g h : B → C}
→ (f : A → B)
→ g ~ h
→ g ∘ f ~ h ∘ f
∘-cong-left f g~h x = g~h (f x)
-- Lemma 2.4.3
Lemma-2-4-3 : ∀ {a b} {A : Set a} {B : Set b} {x y : A}
→ (f g : A → B)
→ (H : f ~ g)
→ (p : x ≡ y)
→ H x ∙ ap g p ≡ ap f p ∙ H y
Lemma-2-4-3 {a} {b} {A} {B} {x} {y} f g H p = J A D d x y p f g H
where
D : (x y : A) (p : x ≡ y) → Set _
D x y p = (f g : A → B) (H : f ~ g) → H x ∙ ap g p ≡ ap f p ∙ H y
-- f(p)
-- f(x) ========== f(y)
-- || ||
-- H(x) || || H(y)
-- || ||
-- g(x) ========== g(y)
-- g(p)
--
d : (x : A) → D x x refl
d x f g H =
begin
H x ∙ ap g refl
≈⟨ ap (λ w → H x ∙ w) (ap-refl g) ⟩
H x ∙ refl
≈⟨ ¬ ∙-identityʳ (H x) ⟩
H x
≈⟨ refl ⟩
H x
≈⟨ ∙-identityˡ (H x) ⟩
refl ∙ H x
≈⟨ ap (λ w → w ∙ H x) (¬ ap-refl f) ⟩
ap f refl ∙ H x
∎
where
open import Relation.Binary.Reasoning.Setoid (setoid (f x ≡ g x))
-- f(H(x))
-- f(x) ========== f(y)
-- || ||
-- H(x) || || H(y)
-- || ||
-- g(x) ========== g(y)
-- g(p)
--
-- Corollary 2.4.4
Corollary-2-4-4 : ∀ {a} {A : Set a}
→ (f : A → A)
→ (H : f ~ id)
→ (x : A)
→ H (f x) ≡ ap f (H x)
Corollary-2-4-4 {a} {A} f H x =
begin
H (f x)
≈⟨ ∙-identityʳ (H (f x)) ⟩
H (f x) ∙ refl
≈⟨ ap [ H (f x) ]∙ (¬ ¬-identityˡ (H x)) ⟩
H (f x) ∙ (H x ∙ ¬ H x)
≈⟨ ∙-assoc (H (f x)) (H x) (¬ H x) ⟩
(H (f x) ∙ H x) ∙ ¬ H x
≈⟨ ap (λ w → (H (f x) ∙ w) ∙ ¬ H x) (¬ ap-id (H x)) ⟩
(H (f x) ∙ ap id (H x)) ∙ ¬ H x
≈⟨ ap ∙[ ¬ H x ] (Lemma-2-4-3 f id H (H x)) ⟩
(ap f (H x) ∙ H x) ∙ ¬ H x
≈⟨ ¬ ∙-assoc (ap f (H x)) (H x) (¬ H x) ⟩
ap f (H x) ∙ (H x ∙ ¬ H x)
≈⟨ ap [ ap f (H x) ]∙ (¬-identityˡ (H x)) ⟩
ap f (H x) ∙ refl
≈⟨ ¬ ∙-identityʳ (ap f (H x)) ⟩
ap f (H x)
∎
where
open import Relation.Binary.Reasoning.Setoid (setoid _)
open import Data.Product
-- Definition 2.4.6
qinv : ∀ {a b} {A : Set a} {B : Set b}
→ (f : A → B)
→ Set (a ⊔ b)
qinv {a} {b} {A} {B} f = Σ[ g ∈ (B → A) ] (f ∘ g ~ id × g ∘ f ~ id)
-- Example 2.4.7
example-2-4-7 : ∀ {a} {A : Set a} → qinv (id {a} {A})
example-2-4-7 = id , ((λ x → refl) , λ x → refl)
-- Example 2.4.8
example-2-4-8-i : ∀ {a} {A : Set a} {x y z : A}
→ (p : x ≡ y)
→ qinv (λ (q : y ≡ z) → p ∙ q)
example-2-4-8-i {a} {A} {x} {y} {z} p = (λ q → ¬ p ∙ q) , (α , β)
where
α : (q : x ≡ z) → p ∙ (¬ p ∙ q) ≡ q
α q =
begin
p ∙ (¬ p ∙ q)
≈⟨ ∙-assoc p (¬ p) q ⟩
p ∙ ¬ p ∙ q
≈⟨ ap (λ w → w ∙ q) (¬-identityˡ p) ⟩
refl ∙ q
≈⟨ ¬ ∙-identityˡ q ⟩
q
∎
where
open import Relation.Binary.Reasoning.Setoid (setoid _)
β : (q : y ≡ z) → ¬ p ∙ (p ∙ q) ≡ q
β q =
begin
¬ p ∙ (p ∙ q)
≈⟨ ∙-assoc (¬ p) p q ⟩
¬ p ∙ p ∙ q
≈⟨ ap (λ w → w ∙ q) (¬-identityʳ p) ⟩
refl ∙ q
≈⟨ ¬ ∙-identityˡ q ⟩
q
∎
where
open import Relation.Binary.Reasoning.Setoid (setoid _)
example-2-4-8-ii : ∀ {a} {A : Set a} {x y z : A}
→ (p : x ≡ y)
→ qinv (λ (q : z ≡ x) → q ∙ p)
example-2-4-8-ii {a} {A} {x} {y} {z} p = (λ q → q ∙ ¬ p) , α , β
where
α : (q : z ≡ y) → q ∙ ¬ p ∙ p ≡ q
α q =
begin
q ∙ ¬ p ∙ p
≈⟨ ¬ ∙-assoc q (¬ p) p ⟩
q ∙ (¬ p ∙ p)
≈⟨ ap (λ w → q ∙ w) (¬-identityʳ p) ⟩
q ∙ refl
≈⟨ ¬ (∙-identityʳ q) ⟩
q
∎
where
open import Relation.Binary.Reasoning.Setoid (setoid _)
β : (q : z ≡ x) → q ∙ p ∙ ¬ p ≡ q
β q =
begin
q ∙ p ∙ ¬ p
≈⟨ ¬ ∙-assoc q p (¬ p) ⟩
q ∙ (p ∙ ¬ p)
≈⟨ ap (λ w → q ∙ w) (¬-identityˡ p) ⟩
q ∙ refl
≈⟨ ¬ (∙-identityʳ q) ⟩
q
∎
where
open import Relation.Binary.Reasoning.Setoid (setoid _)
example-2-4-9 : ∀ {a b} {A : Set a} {x y : A}
→ (P : A → Set b)
→ (p : x ≡ y)
→ qinv (transport P p)
example-2-4-9 {a} {b} {A} {x} {y} P p = (transport P (¬ p)) , α , β
where
α : (w : P y) → transport P p (transport P (¬ p) w) ≡ w
α w =
begin
transport P p (transport P (¬ p) w)
≈⟨ lemma-2-3-9 P (¬ p) p w ⟩
transport P (¬ p ∙ p) w
≈⟨ ap (λ q → transport P q w) (¬-identityʳ p) ⟩
transport P refl w
≈⟨ refl ⟩
w
∎
where
open import Relation.Binary.Reasoning.Setoid (setoid _)
β : (w : P x) → transport P (¬ p) (transport P p w) ≡ w
β w =
begin
transport P (¬ p) (transport P p w)
≈⟨ lemma-2-3-9 P p (¬ p) w ⟩
transport P (p ∙ ¬ p) w
≈⟨ ap (λ q → transport P q w) (¬-identityˡ p) ⟩
transport P refl w
≈⟨ refl ⟩
w
∎
where
open import Relation.Binary.Reasoning.Setoid (setoid _)
-- Definition 2.4.10
isequiv : ∀ {a b} {A : Set a} {B : Set b}
→ (f : A → B)
→ Set (a ⊔ b)
isequiv {a} {b} {A} {B} f =
(Σ[ g ∈ (B → A) ] f ∘ g ~ id) × (Σ[ h ∈ (B → A) ] h ∘ f ~ id)
-- Property 2.4.10-i
Property-2-4-10-i : ∀ {a b} {A : Set a} {B : Set b}
→ (f : A → B)
→ qinv f
→ isequiv f
Property-2-4-10-i f (g , α , β) = (g , α) , (g , β)
-- Property 2.4.10-ii
Property-2-4-10-ii : ∀ {a b} {A : Set a} {B : Set b}
→ (f : A → B)
→ isequiv f
→ qinv f
Property-2-4-10-ii {a} {b} {A} {B} f ((g , α) , (h , β)) = g , (α , β')
where
--
-- β α
-- g ~ h ∘ f ∘ g ~ h
--
γ : g ~ h
γ x = ¬ (β (g x)) ∙ ap h (α x)
β' : g ∘ f ~ id
β' x = γ (f x) ∙ β x
-- Property 2.4.10-iii
-- Property-2-4-10-iii : ∀ {a b} {A : Set a} {B : Set b}
-- → (f : A → B)
-- → (e₁ e₂ : isequiv f)
-- → e₁ ≡ e₂
-- Property-2-4-10-iii {a} {b} {A} {B} f e₁ e₂ = {! !}
-- Definition 2.4.11
_≅_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b)
A ≅ B = Σ[ f ∈ (A → B) ] isequiv f
≅→ : ∀ {a b} {A : Set a} {B : Set b} → A ≅ B → A → B
≅→ (f , _) = f
-- Lemma 2.4.12-i
Lemma-2-4-12-i : ∀ {a} (A : Set a) → A ≅ A
Lemma-2-4-12-i A = id , Property-2-4-10-i id example-2-4-7
-- Lemma 2.4.12-ii
Lemma-2-4-12-ii : ∀ {a} {b} {A : Set a} {B : Set b}
→ A ≅ B
→ B ≅ A
Lemma-2-4-12-ii {a} {b} {A} {B} (f , f-isequiv) = f⁻¹ , f⁻¹-isequiv
where
f-qinv : qinv f
f-qinv = Property-2-4-10-ii f f-isequiv
f⁻¹ : B → A
f⁻¹ = proj₁ f-qinv
f⁻¹-qinv : qinv f⁻¹
f⁻¹-qinv = f , (swap (proj₂ f-qinv))
f⁻¹-isequiv : isequiv f⁻¹
f⁻¹-isequiv = Property-2-4-10-i f⁻¹ f⁻¹-qinv
←≅ : ∀ {a b} {A : Set a} {B : Set b} → A ≅ B → B → A
←≅ = ≅→ ∘ Lemma-2-4-12-ii
-- Lemma 2.4.12-iii
Lemma-2-4-12-iii : ∀ {a} {b} {c} {A : Set a} {B : Set b} {C : Set c}
→ A ≅ B → B ≅ C → A ≅ C
Lemma-2-4-12-iii {a} {b} {c} {A} {B} {C} (g , g-isequiv) (f , f-isequiv)
= (f ∘ g) , f∘g-isequiv
where
f-qinv : qinv f
f-qinv = Property-2-4-10-ii f f-isequiv
g-qinv : qinv g
g-qinv = Property-2-4-10-ii g g-isequiv
f⁻¹ : C → B
f⁻¹ = proj₁ f-qinv
f∘f⁻¹~id : f ∘ f⁻¹ ~ id
f∘f⁻¹~id = proj₁ (proj₂ f-qinv)
f⁻¹∘f~id : f⁻¹ ∘ f ~ id
f⁻¹∘f~id = proj₂ (proj₂ f-qinv)
g⁻¹ : B → A
g⁻¹ = proj₁ g-qinv
g∘g⁻¹~id : g ∘ g⁻¹ ~ id
g∘g⁻¹~id = proj₁ (proj₂ g-qinv)
g⁻¹∘g~id : g⁻¹ ∘ g ~ id
g⁻¹∘g~id = proj₂ (proj₂ g-qinv)
α : (f ∘ g) ∘ (g⁻¹ ∘ f⁻¹) ~ id
α = begin
(f ∘ g) ∘ (g⁻¹ ∘ f⁻¹)
≈⟨ (λ x → refl) ⟩
f ∘ (g ∘ g⁻¹) ∘ f⁻¹
≈⟨ ∘-cong-right f (∘-cong-left f⁻¹ g∘g⁻¹~id) ⟩
f ∘ id ∘ f⁻¹
≈⟨ (λ x → refl) ⟩
f ∘ f⁻¹
≈⟨ f∘f⁻¹~id ⟩
id
∎
where
open import Relation.Binary.Reasoning.Setoid (~-setoid _ _)
β : (g⁻¹ ∘ f⁻¹) ∘ (f ∘ g) ~ id
β = begin
(g⁻¹ ∘ f⁻¹) ∘ (f ∘ g)
≈⟨ (λ x → refl) ⟩
g⁻¹ ∘ (f⁻¹ ∘ f) ∘ g
≈⟨ ∘-cong-right g⁻¹ (∘-cong-left g f⁻¹∘f~id) ⟩
g⁻¹ ∘ id ∘ g
≈⟨ (λ x → refl) ⟩
g⁻¹ ∘ g
≈⟨ g⁻¹∘g~id ⟩
id
∎
where
open import Relation.Binary.Reasoning.Setoid (~-setoid _ _)
f∘g-qinv : qinv (f ∘ g)
f∘g-qinv = (g⁻¹ ∘ f⁻¹) , α , β
f∘g-isequiv : isequiv (f ∘ g)
f∘g-isequiv = Property-2-4-10-i (f ∘ g) f∘g-qinv
| {
"alphanum_fraction": 0.3993847459,
"avg_line_length": 24.8078947368,
"ext": "agda",
"hexsha": "97e511bb74b5afdb5ec780cfe553819086f98a6c",
"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": "75eea99a879e100304bd48c538c9d2db0b4a4ff3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/hott",
"max_forks_repo_path": "src/Ch2-4.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75eea99a879e100304bd48c538c9d2db0b4a4ff3",
"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/hott",
"max_issues_repo_path": "src/Ch2-4.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75eea99a879e100304bd48c538c9d2db0b4a4ff3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/hott",
"max_stars_repo_path": "src/Ch2-4.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4688,
"size": 9427
} |
-- Andreas, 2016-07-08 testing the access to definitions in where blocks
-- Anonymous where modules do export
pub0 = priv0
module _ where
priv0 = Set
works = priv0 -- Should succeed
-- Unnamed where modules don't export
pub = priv
where
priv = Set
fail = priv -- Should fail
| {
"alphanum_fraction": 0.6962457338,
"avg_line_length": 16.2777777778,
"ext": "agda",
"hexsha": "7542cbea5119e2af9c489045c3c5350d6145f0b6",
"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/Issue2081a.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/Issue2081a.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2081a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 79,
"size": 293
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cw.CW
open import homotopy.DisjointlyPointedSet
open import cohomology.Theory
open import cohomology.ChainComplex
module cw.cohomology.ReconstructedCochainsIsoCellularCochains {i : ULevel}
(OT : OrdinaryTheory i) where
open OrdinaryTheory OT
open import cw.cohomology.CellularChainComplex as CCC
open import cw.cohomology.ReconstructedCochainComplex OT as RCC
open import cw.cohomology.TipAndAugment OT
open import cw.cohomology.WedgeOfCells OT
private
rcc-iso-ccc-nth : ∀ {n} (⊙skel : ⊙Skeleton n) {m} (m≤n : m ≤ n)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ AbGroup.grp (RCC.cochain-template ⊙skel (inl m≤n))
≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (inl m≤n))) (C2-abgroup 0)
rcc-iso-ccc-nth ⊙skel {m = O} (inl idp) ac
= FreeAbGroup-extend-iso (C2-abgroup 0)
∘eᴳ Πᴳ-emap-l (λ _ → C2 0) (separable-unite-equiv (⊙Skeleton.pt-dec ⊙skel))
∘eᴳ Πᴳ₁-⊔-iso-×ᴳ {A = Unit} {B = MinusPoint (⊙cw-head ⊙skel)} (λ _ → C2 0) ⁻¹ᴳ
∘eᴳ ×ᴳ-emap (Πᴳ₁-Unit ⁻¹ᴳ) (CX₀-β ⊙skel 0 ac)
rcc-iso-ccc-nth ⊙skel {m = S m} (inl idp) ac
= FreeAbGroup-extend-iso (C2-abgroup 0)
∘eᴳ CXₙ/Xₙ₋₁-β-diag ⊙skel ac
rcc-iso-ccc-nth ⊙skel {m = O} (inr ltS) ac =
rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inl idp) (⊙init-has-cells-with-choice ⊙skel ac)
rcc-iso-ccc-nth ⊙skel {m = S m} (inr ltS) ac =
rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inl idp) (⊙init-has-cells-with-choice ⊙skel ac)
rcc-iso-ccc-nth ⊙skel {m = O} (inr (ltSR lt)) ac =
rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inr lt) (⊙init-has-cells-with-choice ⊙skel ac)
rcc-iso-ccc-nth ⊙skel {m = S m} (inr (ltSR lt)) ac =
rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inr lt) (⊙init-has-cells-with-choice ⊙skel ac)
rcc-iso-ccc-above : ∀ {n} (⊙skel : ⊙Skeleton n) {m} (m≰n : ¬ (m ≤ n))
→ AbGroup.grp (RCC.cochain-template ⊙skel (inr m≰n))
≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (inr m≰n))) (C2-abgroup 0)
rcc-iso-ccc-above ⊙skel _
= pre∘ᴳ-iso (C2-abgroup 0) lower-iso
∘eᴳ trivial-iso-Unit (hom₁-Unit-is-trivial (C2-abgroup 0)) ⁻¹ᴳ
∘eᴳ lower-iso
rcc-iso-ccc : ∀ {n} (⊙skel : ⊙Skeleton n) (m : ℕ)
→ ⊙has-cells-with-choice 0 ⊙skel i
→ AbGroup.grp (RCC.cochain-template ⊙skel (≤-dec m n))
≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (≤-dec m n))) (C2-abgroup 0)
rcc-iso-ccc {n} ⊙skel m ac with ≤-dec m n
rcc-iso-ccc ⊙skel m ac | inl m≤n = rcc-iso-ccc-nth ⊙skel m≤n ac
rcc-iso-ccc ⊙skel m ac | inr m≰n = rcc-iso-ccc-above ⊙skel m≰n
rhead-iso-chead : C2 0 ≃ᴳ hom-group ℤ-group (C2-abgroup 0)
rhead-iso-chead
= pre∘ᴳ-iso (C2-abgroup 0) ℤ-iso-FreeAbGroup-Unit
∘eᴳ FreeAbGroup-extend-iso (C2-abgroup 0)
∘eᴳ Πᴳ₁-Unit ⁻¹ᴳ
| {
"alphanum_fraction": 0.633847232,
"avg_line_length": 46.7868852459,
"ext": "agda",
"hexsha": "5e010c641fd706c74a3a17992f815cb5aaf6c889",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1335,
"size": 2854
} |
{-# OPTIONS --without-K #-}
module Examples.BooleanCircuits where
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]′)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; cong; subst)
open import Singleton
open import PiFrac
open import Reasoning
------------------------------------------------------------------------------
𝔹 𝔹² 𝔹³ 𝔹⁴ : 𝕌
𝔹 = 𝟙 +ᵤ 𝟙
𝔹² = 𝔹 ×ᵤ 𝔹
𝔹³ = 𝔹 ×ᵤ 𝔹²
𝔹⁴ = 𝔹 ×ᵤ 𝔹³
CONTROLLED : {A : 𝕌} → (A ⟷ A) → 𝔹 ×ᵤ A ⟷ 𝔹 ×ᵤ A
CONTROLLED c = dist ⊚ (id⟷ ⊕ (id⟷ ⊗ c)) ⊚ factor
NOT : 𝔹 ⟷ 𝔹
NOT = swap₊
CNOT : 𝔹² ⟷ 𝔹²
CNOT = CONTROLLED NOT
TOFFOLI : 𝔹³ ⟷ 𝔹³
TOFFOLI = CONTROLLED (CONTROLLED NOT)
CTOFFOLI : 𝔹⁴ ⟷ 𝔹⁴
CTOFFOLI = CONTROLLED (CONTROLLED (CONTROLLED NOT))
-- Ancilla examples from literature
-- Fig. 2 in Ricercar
fig2a : 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ⟷
𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹
fig2a = CONTROLLED (CONTROLLED (CONTROLLED NOT))
-- first write the circuit with the additional ancilla
fig2b' : ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) ⟷ ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹)
fig2b' =
(swap⋆ ⊗ id⟷) ⊚
assocr⋆ ⊚
(swap⋆ ⊗ id⟷) ⊚
assocr⋆ ⊚
(id⟷ ⊗ CONTROLLED (CONTROLLED NOT)) -- first ccnot
⊚
assocl⋆ ⊚
(swap⋆ ⊗ id⟷) ⊚
assocl⋆ ⊚
(swap⋆ ⊗ id⟷) -- move it back
⊚
(assocl⋆ ⊗ id⟷) ⊚
assocr⋆ ⊚
(id⟷ ⊗ swap⋆) ⊚
(id⟷ ⊗ CONTROLLED (CONTROLLED NOT)) -- second ccnot
⊚
(id⟷ ⊗ swap⋆) ⊚
assocl⋆ ⊚
(assocr⋆ ⊗ id⟷) -- move it back
⊚
(swap⋆ ⊗ id⟷) ⊚
assocr⋆ ⊚
(swap⋆ ⊗ id⟷) ⊚
assocr⋆ ⊚
(id⟷ ⊗ CONTROLLED (CONTROLLED NOT)) -- third ccnot
⊚
assocl⋆ ⊚
(swap⋆ ⊗ id⟷) ⊚
assocl⋆ ⊚
(swap⋆ ⊗ id⟷) -- move it back
------------------------------------------------------------------------------
-- Examples
PERES : (𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹 ⟷ (𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹
PERES = (id⟷ ⊗ NOT) ⊚ assocr⋆ ⊚ (id⟷ ⊗ swap⋆) ⊚
TOFFOLI ⊚
(id⟷ ⊗ (NOT ⊗ id⟷)) ⊚
TOFFOLI ⊚
(id⟷ ⊗ swap⋆) ⊚ (id⟷ ⊗ (NOT ⊗ id⟷)) ⊚
TOFFOLI ⊚
(id⟷ ⊗ (NOT ⊗ id⟷)) ⊚ assocl⋆
SWAP12 SWAP23 SWAP13 ROTL ROTR : 𝟙 +ᵤ 𝟙 +ᵤ 𝟙 ⟷ 𝟙 +ᵤ 𝟙 +ᵤ 𝟙
SWAP12 = assocl₊ ⊚ (swap₊ ⊕ id⟷) ⊚ assocr₊
SWAP23 = id⟷ ⊕ swap₊
SWAP13 = SWAP23 ⊚ SWAP12 ⊚ SWAP23
ROTR = SWAP12 ⊚ SWAP23
ROTL = SWAP13 ⊚ SWAP23
pattern ?𝔽 = inj₁ tt
pattern ?𝕋 = inj₂ tt
-- this version might look more contrived that the fully expanded
-- one via pattern matching, but it generalizes better.
-- controlled f (b , a) = (b , [ (λ _ → a) , (λ _ → f a) ]′ b)
𝔽 𝕋 : ⟦ 𝔹 ⟧
𝔽 = inj₁ tt
𝕋 = inj₂ tt
not : ⟦ 𝔹 ⟧ → ⟦ 𝔹 ⟧
not ?𝔽 = 𝕋
not ?𝕋 = 𝔽
controlled : ∀ {A} → (⟦ A ⟧ → ⟦ A ⟧) → ⟦ 𝔹 ⟧ × ⟦ A ⟧ → ⟦ 𝔹 ⟧ × ⟦ A ⟧
controlled f (?𝔽 , a) = (𝔽 , a )
controlled f (?𝕋 , a) = (𝕋 , f a)
t3 : ∀ {b₁ b₂} →
● (𝔹 ×ᵤ 𝔹²) [ 𝔽 , (b₁ , b₂) ] ⟷
● (𝔹 ×ᵤ 𝔹²) [ 𝔽 , (b₁ , b₂) ]
t3 = lift TOFFOLI
{--
The following do not typecheck. Good
t4 : ● (𝔹 ×ᵤ 𝔹²) [ 𝕋 , (𝔽 , 𝔽) ] ⟷
● (𝔹 ×ᵤ 𝔹²) [ 𝕋 , (𝔽 , 𝕋) ]
t4 = lift TOFFOLI
t5 : ∀ {b₁ b₂} →
● (𝔹 ×ᵤ 𝔹²) [ b₁ , (𝔽 , b₂) ] ⟷
● (𝔹 ×ᵤ 𝔹²) [ b₁ , (𝔽 , b₂) ]
t5 = lift TOFFOLI
--}
t6 : ∀ {b} →
● (𝔹 ×ᵤ 𝔹²) [ 𝕋 , (𝕋 , b) ] ⟷
● (𝔹 ×ᵤ 𝔹²) [ 𝕋 , (𝕋 , eval NOT b) ]
t6 = lift TOFFOLI
NEG1 NEG2 NEG3 NEG4 NEG5 : 𝔹 ⟷ 𝔹
NEG1 = swap₊
NEG2 = id⟷ ⊚ NOT
NEG3 = NOT ⊚ NOT ⊚ NOT
NEG4 = NOT ⊚ id⟷
NEG5 = uniti⋆l ⊚ swap⋆ ⊚ (NOT ⊗ id⟷) ⊚ swap⋆ ⊚ unite⋆l
NEG6 = uniti⋆r ⊚ (NOT ⊗ id⟷) ⊚ unite⋆r -- same as above, but shorter
zigzag : ∀ b → ● 𝔹 [ b ] ⟷ ● 𝔹 [ b ]
zigzag b =
uniti⋆l ⊚ -- ONE * POINTED TWO
(η b ⊗ id⟷) ⊚ -- (POINTED TWO * RECIP TWO) * POINTED TWO
assocr⋆ ⊚ -- POINTED TWO * (RECIP TWO * POINTED TWO)
(id⟷ ⊗ swap⋆) ⊚ -- POINTED TWO * (POINTED TWO * RECIP TWO)
(id⟷ ⊗ ε b) ⊚ -- POINTED TWO * ONE
unite⋆r
test1 = eval (zigzag 𝔽) (𝔽 , refl) -- (⇑ #f refl)
-- test2 = eval (zigzag 𝔽) (𝕋 , refl) -- typechecks if given proof #f=#t
-- test3 = eval (zigzag 𝕋) (𝔽 , refl) -- typechecks if given proof #f=#t
test4 = eval (zigzag 𝕋) (𝕋 , refl) -- (⇑ #t refl)
zigzagU : ⟦ 𝔹 ⟧ → ⟦ 𝔹 ⟧
zigzagU b = unfocus (eval (zigzag b) (focus b))
-- then prove a theorem that specifies its semantics
fig2b'≡ : (a b c d : ⟦ 𝔹 ⟧) →
proj₂ (eval fig2b' ((a , b , c , d) , 𝔽)) ≡ 𝔽
fig2b'≡ a (inj₁ tt) c d = refl
fig2b'≡ (inj₁ tt) (inj₂ tt) c d = refl
fig2b'≡ (inj₂ tt) (inj₂ tt) c d = refl
-- generalize above? Method:
-- for 'dist' to evaluate, need to split on b first
-- in first case, split on e (same reason)
-- in second case, split on a (same reason)
-- split on e
-- split on e
foo : (a b c d e : ⟦ 𝔹 ⟧) →
proj₂ (eval fig2b' ((a , b , c , d) , e)) ≡ e
foo a (inj₁ x) c d (inj₁ x₁) = refl
foo a (inj₁ x) c d (inj₂ y) = refl
foo (inj₁ x) (inj₂ y) c d (inj₁ x₁) = refl
foo (inj₁ x) (inj₂ y) c d (inj₂ y₁) = refl
foo (inj₂ y₁) (inj₂ y) c d (inj₁ x) = refl
foo (inj₂ y₁) (inj₂ y) c d (inj₂ y₂) = refl
postulate
-- boring...
tensor4 : ∀ {a b c d e} →
(● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ]) ×ᵤ ● 𝔹 [ e ] ⟷
● ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) [ (a , b , c , d) , e ]
itensor4 : ∀ {a b c d e} →
● ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) [ (a , b , c , d) , e ] ⟷
(● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ]) ×ᵤ ● 𝔹 [ e ]
-- now lift it
fig2b : ∀ {a b c d e} →
let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e)
in
● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ] ⟷
● 𝔹 [ x ] ×ᵤ ● 𝔹 [ y ] ×ᵤ ● 𝔹 [ z ] ×ᵤ ● 𝔹 [ w ]
fig2b {a} {b} {c} {d} {e} =
let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e)
in uniti⋆r ⊚
-- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝟙[e]
(id⟷ ⊗ η e) ⊚
-- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × (●𝔹[e] x ●1/𝔹[e])
assocl⋆ ⊚
-- ((●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝔹[e) x ●1/𝔹[e]
(tensor4 ⊗ id⟷) ⊚
-- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (a,b,c,d),e ] x ●1/𝔹[e]
(lift fig2b' ⊗ id⟷) ⊚
-- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e]
(((== id⟷ (cong (λ H → ((x , y , z , w)) , H) (foo a b c d e))) ⊗ id⟷)) ⊚
-- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e]
(itensor4 ⊗ id⟷) ⊚
-- ((●𝔹[x] × ●𝔹[y] × ●𝔹[z] × ●𝔹[w]) × ●𝔹[e]) x ●1/𝔹[e]
assocr⋆ ⊚
(id⟷ ⊗ ε e) ⊚
unite⋆r
-- This is mostly to show that == is really 'subst' in hiding.
fig2b₂ : ∀ {a b c d e} →
let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e)
in
● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ] ⟷
● 𝔹 [ x ] ×ᵤ ● 𝔹 [ y ] ×ᵤ ● 𝔹 [ z ] ×ᵤ ● 𝔹 [ w ]
fig2b₂ {a} {b} {c} {d} {e} =
let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e)
in uniti⋆r ⊚
-- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝟙[e]
(id⟷ ⊗ η e) ⊚
-- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × (●𝔹[e] x ●1/𝔹[e])
assocl⋆ ⊚
-- ((●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝔹[e) x ●1/𝔹[e]
(tensor4 ⊗ id⟷) ⊚
-- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (a,b,c,d),e ] x ●1/𝔹[e]
(lift fig2b' ⊗ id⟷) ⊚
-- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e]
(itensor4 ⊗ id⟷) ⊚
-- ((●𝔹[x] × ●𝔹[y] × ●𝔹[z] × ●𝔹[w]) × ●𝔹[e]) x ●1/𝔹[e]
assocr⋆ ⊚
(id⟷ ⊗ (subst (λ ee → ● 𝔹 [ ee ] ×ᵤ 𝟙/● 𝔹 [ e ] ⟷ 𝟙) (sym (foo a b c d e)) (ε e))) ⊚
unite⋆r
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4236176195,
"avg_line_length": 29.5217391304,
"ext": "agda",
"hexsha": "168420abe81f49971b175d027fdb9fb15d7a0688",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "fracGC/Examples/BooleanCircuits.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "fracGC/Examples/BooleanCircuits.agda",
"max_line_length": 92,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "fracGC/Examples/BooleanCircuits.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": 4110,
"size": 7469
} |
{-# OPTIONS --rewriting --without-K #-}
open import Agda.Primitive
open import Prelude
import GSeTT.Typed-Syntax
import Globular-TT.Syntax
{- Type theory for globular sets -}
module Globular-TT.Eqdec-syntax {l}
(index : Set l) (eqdec-index : eqdec index) where
open import Globular-TT.Syntax index
eqdec-Ty : eqdec Pre-Ty
eqdec-Tm : eqdec Pre-Tm
eqdec-Sub : eqdec Pre-Sub
eqdec-Ty ∗ ∗ = inl idp
eqdec-Ty ∗ (⇒ _ _ _) = inr λ{()}
eqdec-Ty (⇒ _ _ _ ) ∗ = inr λ{()}
eqdec-Ty (⇒ A t u) (⇒ B t' u') with eqdec-Ty A B | eqdec-Tm t t' | eqdec-Tm u u'
... | inl idp | inl idp | inl idp = inl idp
... | inr A≠B | _ | _ = inr λ{idp → A≠B idp}
... | inl idp | inr t≠t' | _ = inr λ eq → t≠t' (snd (fst (=⇒ eq)))
... | inl idp | inl idp | inr u≠u' = inr λ eq → u≠u' (snd (=⇒ eq))
eqdec-Tm (Var x) (Var y) with eqdecℕ x y
... | inl idp = inl idp
... | inr x≠y = inr λ {idp → x≠y idp}
eqdec-Tm (Var _) (Tm-constructor _ _) = inr λ{()}
eqdec-Tm (Tm-constructor _ _) (Var _) = inr λ{()}
eqdec-Tm (Tm-constructor i γ) (Tm-constructor i' γ') with eqdec-index i i' | eqdec-Sub γ γ'
... | inl idp | inl idp = inl idp
... | inr i≠i' | _ = inr λ{idp → i≠i' idp}
... | inl idp | inr γ≠γ' = inr λ eq → γ≠γ' (snd (=Tm-constructor eq))
eqdec-Sub <> <> = inl idp
eqdec-Sub < _ , _ ↦ _ > <> = inr λ{()}
eqdec-Sub <> < _ , _ ↦ _ > = inr λ{()}
eqdec-Sub < γ , x ↦ t > < γ' , y ↦ t' > with eqdec-Sub γ γ' | eqdecℕ x y | eqdec-Tm t t'
... | inl idp | inl idp | inl idp = inl idp
... | inr γ≠γ' | _ | _ = inr λ{idp → γ≠γ' idp}
... | inl idp | inr x≠y | _ = inr λ eq → x≠y (snd (fst (=<,> eq)))
... | inl idp | inl idp | inr t≠t' = inr λ eq → t≠t' (snd (=<,> eq))
| {
"alphanum_fraction": 0.4228438228,
"avg_line_length": 45.6382978723,
"ext": "agda",
"hexsha": "0c3ac1080b8ca7b244023c9d6819e505d330a22f",
"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": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thibautbenjamin/catt-formalization",
"max_forks_repo_path": "Globular-TT/Eqdec-syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"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": "thibautbenjamin/catt-formalization",
"max_issues_repo_path": "Globular-TT/Eqdec-syntax.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thibautbenjamin/catt-formalization",
"max_stars_repo_path": "Globular-TT/Eqdec-syntax.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 804,
"size": 2145
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
-- an attempt to speed up [QuotGroup (quot-of-sub (ker-prop ...) (im-nprop ...))]
-- which removes most intermediate constructions
module groups.KernelImage {i j k}
{G : Group i} {H : Group j} {K : Group k}
(ψ : H →ᴳ K) (φ : G →ᴳ H) (H-ab : is-abelian H) where
-- G ---φ--→ᴳ H ---ψ--→ᴳ K
private
module G = Group G
module H = AbGroup (H , H-ab)
module K = Group K
module ψ = GroupHom ψ
module φ = GroupHom φ
ker-El : Type (lmax j k)
ker-El = Σ H.El (λ h → ψ.f h == K.ident)
ker-subtype : SubtypeProp H.El k
ker-subtype = (λ h → ψ.f h == K.ident) , level
where abstract level : ∀ h → is-prop (ψ.f h == K.ident)
level h = K.El-is-set _ _
ker-El=-out = Subtype=-out ker-subtype
ker/im-rel' : Rel H.El (lmax i j)
ker/im-rel' h₁ h₂ = Trunc -1 (hfiber φ.f (H.diff h₁ h₂))
ker/im-rel : Rel ker-El (lmax i j)
ker/im-rel (h₁ , _) (h₂ , _) = Trunc -1 (hfiber φ.f (H.diff h₁ h₂))
private
ker/im-El : Type (lmax (lmax i j) k)
ker/im-El = SetQuot ker/im-rel
ker/im-struct : GroupStructure ker/im-El
ker/im-struct = record {M} where
module M where
ident : ker/im-El
ident = q[ H.ident , lemma ]
where abstract lemma = ψ.pres-ident
inv : ker/im-El → ker/im-El
inv = SetQuot-rec SetQuot-level inv' inv-rel
where
inv' : ker-El → ker/im-El
inv' (h , ψh=0) = q[ H.inv h , lemma ]
where abstract lemma = ψ.pres-inv h ∙ ap K.inv ψh=0 ∙ K.inv-ident
abstract
inv-rel : ∀ {ker₁ ker₂} → ker/im-rel ker₁ ker₂ → inv' ker₁ == inv' ker₂
inv-rel {h₁ , _} {h₂ , _} = Trunc-rec (SetQuot-level _ _)
λ{(g , φg=h₁h₂⁻¹) → quot-rel
[ G.inv g , φ.pres-inv g ∙ ap H.inv φg=h₁h₂⁻¹
∙ H.inv-diff h₁ h₂ ∙ H.comm h₂ (H.inv h₁)
∙ ap (H.comp (H.inv h₁)) (! (H.inv-inv h₂)) ]}
comp : ker/im-El → ker/im-El → ker/im-El
comp = SetQuot-rec level comp' comp-rel where
abstract
level : is-set (ker/im-El → ker/im-El)
level = →-is-set SetQuot-level
comp' : ker-El → ker/im-El → ker/im-El
comp' (h₁ , ψh₁=0) = SetQuot-rec SetQuot-level comp'' comp'-rel where
comp'' : ker-El → ker/im-El
comp'' (h₂ , ψh₂=0) = q[ H.comp h₁ h₂ , lemma ]
where abstract lemma = ψ.pres-comp h₁ h₂ ∙ ap2 K.comp ψh₁=0 ψh₂=0
∙ K.unit-l K.ident
abstract
comp'-rel : ∀ {ker₂ ker₂'} → ker/im-rel ker₂ ker₂' → comp'' ker₂ == comp'' ker₂'
comp'-rel {h₂ , _} {h₂' , _} = Trunc-rec (SetQuot-level _ _)
λ{(g , φg=h₂h₂'⁻¹) → quot-rel
[ g , ! ( ap (H.comp (H.comp h₁ h₂)) (H.inv-comp h₁ h₂')
∙ H.assoc h₁ h₂ (H.comp (H.inv h₂') (H.inv h₁))
∙ ap (H.comp h₁) (! $ H.assoc h₂ (H.inv h₂') (H.inv h₁))
∙ H.comm h₁ (H.comp (H.comp h₂ (H.inv h₂')) (H.inv h₁))
∙ H.assoc (H.comp h₂ (H.inv h₂')) (H.inv h₁) h₁
∙ ap2 H.comp (! φg=h₂h₂'⁻¹) (H.inv-l h₁)
∙ H.unit-r (φ.f g) )]}
abstract
comp-rel : ∀ {ker₁ ker₁'} → ker/im-rel ker₁ ker₁' → comp' ker₁ == comp' ker₁'
comp-rel {h₁ , _} {h₁' , _} = Trunc-rec (level _ _)
λ{(g , φg=h₁h₁'⁻¹) → λ= $ SetQuot-elim (λ _ → =-preserves-set SetQuot-level)
(λ{(h₂ , _) → quot-rel
[ g , ! ( ap (H.comp (H.comp h₁ h₂)) (H.inv-comp h₁' h₂)
∙ H.assoc h₁ h₂ (H.comp (H.inv h₂) (H.inv h₁'))
∙ ap (H.comp h₁) ( ! (H.assoc h₂ (H.inv h₂) (H.inv h₁'))
∙ ap (λ h → H.comp h (H.inv h₁')) (H.inv-r h₂)
∙ H.unit-l (H.inv h₁'))
∙ ! φg=h₁h₁'⁻¹ )]})
(λ _ → prop-has-all-paths-↓ (SetQuot-level _ _))}
abstract
unit-l : ∀ k/i → comp ident k/i == k/i
unit-l = SetQuot-elim
(λ _ → =-preserves-set SetQuot-level)
(λ{(h , _) → ap q[_] $ ker-El=-out (H.unit-l h)})
(λ _ → prop-has-all-paths-↓ (SetQuot-level _ _))
assoc : ∀ k/i₁ k/i₂ k/i₃ → comp (comp k/i₁ k/i₂) k/i₃ == comp k/i₁ (comp k/i₂ k/i₃)
assoc = SetQuot-elim
(λ _ → Π-is-set λ _ → Π-is-set λ _ → =-preserves-set SetQuot-level)
(λ{(h₁ , _) → SetQuot-elim
(λ _ → Π-is-set λ _ → =-preserves-set SetQuot-level)
(λ{(h₂ , _) → SetQuot-elim
(λ _ → =-preserves-set SetQuot-level)
(λ{(h₃ , _) → ap q[_] $ ker-El=-out (H.assoc h₁ h₂ h₃)})
(λ _ → prop-has-all-paths-↓ (SetQuot-level _ _))})
(λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → SetQuot-level _ _))})
(λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → Π-is-prop λ _ → SetQuot-level _ _))
inv-l : ∀ k/i → comp (inv k/i) k/i == ident
inv-l = SetQuot-elim
(λ _ → =-preserves-set SetQuot-level)
(λ{(h , _) → ap q[_] $ ker-El=-out (H.inv-l h)})
(λ _ → prop-has-all-paths-↓ (SetQuot-level _ _))
Ker/Im : Group (lmax i (lmax j k))
Ker/Im = group _ SetQuot-level ker/im-struct
module Ker/Im = Group Ker/Im
{- correctness -}
Ker/Im-β : Ker/Im ≃ᴳ QuotGroup (quot-of-sub (ker-propᴳ ψ) (im-npropᴳ φ H-ab))
Ker/Im-β = ≃-to-≃ᴳ (ide _) to-pres-comp where
abstract
to-pres-comp : preserves-comp Ker/Im.comp
(QuotGroup.comp (quot-of-sub (ker-propᴳ ψ) (im-npropᴳ φ H-ab))) (idf _)
to-pres-comp = SetQuot-elim
(λ _ → Π-is-set λ _ → =-preserves-set SetQuot-level)
(λ _ → SetQuot-elim
(λ _ → =-preserves-set SetQuot-level)
(λ _ → ap q[_] $ ker-El=-out idp)
(λ _ → prop-has-all-paths-↓ (SetQuot-level _ _)))
(λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → SetQuot-level _ _))
| {
"alphanum_fraction": 0.4874647186,
"avg_line_length": 41.2534246575,
"ext": "agda",
"hexsha": "3e1a6a4397cf0f4c8aca358aeab6cfdd056ac3f1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/groups/KernelImage.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/groups/KernelImage.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/groups/KernelImage.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2154,
"size": 6023
} |
open import Data.Graph
module Data.Graph.Path.Search {ℓᵥ ℓₑ} (g : FiniteGraph ℓᵥ ℓₑ) where
open import Data.Graph.Path.Cut g
open import Data.Graph.Path.Finite g
open import Data.Product as Σ
open import Data.Sum as ⊎
open import Data.Vec as Vec
open import Finite
open import Function
open import Level
open import Relation.Binary
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary hiding (module Dec)
open import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Negation as ¬
open FiniteGraph g
open IsFinite
pathSearchFrom : ∀ {ℓ} {P : Vertex → Set ℓ} →
(∀ b → Dec (P b)) → ∀ a → Dec (∃ λ b → P b × ∃ (Path a b))
pathSearchFrom P? a =
case ∃? (Path≤-finite (size vertexFinite) a) (P? ∘ proj₁) of λ where
(yes ((_ , _ , _ , p) , pb)) → yes (-, pb , (-, p))
(no ¬p) → no λ where (_ , pb , _ , p) → ¬p ((-, shortEnoughPath p) , pb)
pathSearchAcyclicFrom : ∀ {ℓ} {P : Vertex → Set ℓ} →
(∀ b → Dec (P b)) → ∀ a →
Dec (∃ λ b → P b × ∃₂ λ n (p : Path a b n) → Acyclic p)
pathSearchAcyclicFrom P? a =
case ∃? (Path≤-finite (size vertexFinite) a) (P? ∘ proj₁) of λ where
(yes ((_ , _ , _ , p) , pb)) →
let (x , x≤n , p′) , ¬r′ = acyclicPath p in
yes (-, pb , (-, (p′ , ¬r′)))
(no ¬p) → no λ where (_ , pb , _ , p , r) → ¬p ((-, shortEnoughPath p) , pb)
pathSearchBetween : ∀ a b → Dec (∃ (Path a b))
pathSearchBetween a b =
case pathSearchFrom (decEqVertex b) a of λ where
(yes (_ , refl , p)) → yes p
(no ¬p) → no λ where (n , p) → ¬p (-, refl , -, p)
searchFrom : ∀ {ℓ} {P : Vertex → Set ℓ} →
(∀ b → Dec (P b)) →
∀ a → Dec (∃ λ b → P b × Star Edge a b)
searchFrom P? a =
Dec.map′
(Σ.map₂ (Σ.map₂ (toStar ∘ proj₂)))
(Σ.map₂ (Σ.map₂ (-,_ ∘ fromStar)))
(pathSearchFrom P? a)
searchBetween : ∀ a b → Dec (Star Edge a b)
searchBetween a b = Dec.map′ (toStar ∘ proj₂) (-,_ ∘ fromStar) (pathSearchBetween a b)
module _
{ℓ ℓ≈ ℓ<}
{P : Vertex → Set ℓ} (P? : ∀ a → Dec (P a))
{_≈_ : ∀ {a} → Rel (∃ (Star Edge a)) ℓ≈}
{_<_ : ∀ {a} → Rel (∃ (Star Edge a)) ℓ<}
(<-po : ∀ {a} → IsDecStrictPartialOrder (_≈_ {a}) _<_)
where
record MaximalPath a : Set (ℓ ⊔ ℓᵥ ⊔ ℓₑ ⊔ ℓ<) where
field
destination : Vertex
predicate : P destination
path : Star Edge a destination
acyclic : Acyclic (fromStar path)
isMax : ∀
{b} (p : Star Edge a b) (pb : P b) → Acyclic (fromStar p) →
¬ ((-, path) < (-, p))
searchMaximalFrom : ∀ a → Dec (MaximalPath a)
searchMaximalFrom a =
case max of λ where
(inj₁ ¬p) →
no λ mp →
let open MaximalPath mp in
¬p ((-, path , fromWitness acyclic) , fromWitness predicate)
(inj₂ (((b , p , acp) , pb) , isMax)) →
yes record
{ destination = b
; predicate = toWitness pb
; path = p
; acyclic = toWitness acp
; isMax = λ q pb acq → isMax ((-, q , fromWitness acq) , fromWitness pb)
}
where
module DPO = IsDecStrictPartialOrder <-po
_≈′_ = _≈_ on λ where ((b , p , acp) , pb) → b , p
_<′_ = _<_ on λ where ((b , p , acp) , pb) → b , p
<′-IsDecStrictPartialOrder : IsDecStrictPartialOrder _≈′_ _<′_
<′-IsDecStrictPartialOrder = record
{ isStrictPartialOrder = record
{ isEquivalence = record
{ refl = IsEquivalence.refl DPO.isEquivalence
; sym = IsEquivalence.sym DPO.isEquivalence
; trans = IsEquivalence.trans DPO.isEquivalence
}
; irrefl = DPO.irrefl
; trans = DPO.trans
; <-resp-≈ = proj₁ DPO.<-resp-≈ , proj₂ DPO.<-resp-≈
}
; _≟_ = λ _ _ → _ DPO.≟ _
; _<?_ = λ _ _ → _ DPO.<? _
}
acyclicPaths = filter (AcyclicStar-finite a) (P? ∘ proj₁)
open Ordered acyclicPaths <′-IsDecStrictPartialOrder
| {
"alphanum_fraction": 0.5620233859,
"avg_line_length": 33.6239316239,
"ext": "agda",
"hexsha": "c74cfbe9477a23d35887b5d00786da5c0353a369",
"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": "0196cf8a136a4933cd6358e4c9692aaf919ca603",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kcsmnt0/graph",
"max_forks_repo_path": "src/Data/Graph/Path/Search.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0196cf8a136a4933cd6358e4c9692aaf919ca603",
"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": "kcsmnt0/graph",
"max_issues_repo_path": "src/Data/Graph/Path/Search.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0196cf8a136a4933cd6358e4c9692aaf919ca603",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kcsmnt0/graph",
"max_stars_repo_path": "src/Data/Graph/Path/Search.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1393,
"size": 3934
} |
open import Agda.Builtin.Bool
impor Agda.Builtin.Nat
import Agda.Builtin.Sigma
module issue4888 where
| {
"alphanum_fraction": 0.819047619,
"avg_line_length": 13.125,
"ext": "agda",
"hexsha": "c15f2ab5a02a9e58975c2a16f2047c3fe97a81df",
"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": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jappeace/agda",
"max_forks_repo_path": "test/Fail/Issue4888.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"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": "jappeace/agda",
"max_issues_repo_path": "test/Fail/Issue4888.agda",
"max_line_length": 29,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jappeace/agda",
"max_stars_repo_path": "test/Fail/Issue4888.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 31,
"size": 105
} |
{-# OPTIONS --without-K --safe #-}
module Data.Binary.Tests.Addition where
import Data.Binary.Operations.Addition as 𝔹
open import Data.Binary.Tests.Helpers
open import Relation.Binary.PropositionalEquality
import Data.Nat as ℕ
_ : 𝔹._+_ ≡⌈ 60 ⌉₂≡ ℕ._+_
_ = refl
| {
"alphanum_fraction": 0.7443609023,
"avg_line_length": 22.1666666667,
"ext": "agda",
"hexsha": "e8b9f6641fcc5bb673aabfe9e4e7d52d0cd728f6",
"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": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-binary",
"max_forks_repo_path": "Data/Binary/Tests/Addition.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"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-binary",
"max_issues_repo_path": "Data/Binary/Tests/Addition.agda",
"max_line_length": 49,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-binary",
"max_stars_repo_path": "Data/Binary/Tests/Addition.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z",
"num_tokens": 79,
"size": 266
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An example of how the Record module can be used
------------------------------------------------------------------------
-- Taken from Randy Pollack's paper "Dependently Typed Records in Type
-- Theory".
module README.Record where
open import Data.Product
open import Data.String
open import Function using (flip)
open import Level
import Record
open import Relation.Binary
-- Let us use strings as labels.
open Record String _≟_
-- Partial equivalence relations.
PER : Signature _
PER = ∅ , "S" ∶ (λ _ → Set)
, "R" ∶ (λ r → r · "S" → r · "S" → Set)
, "sym" ∶ (λ r → Lift (Symmetric (r · "R")))
, "trans" ∶ (λ r → Lift (Transitive (r · "R")))
-- Given a PER the converse relation is also a PER.
converse : (P : Record PER) →
Record (PER With "S" ≔ (λ _ → P · "S")
With "R" ≔ (λ _ → flip (P · "R")))
converse P =
Rec′⇒Rec
(PER With "S" ≔ (λ _ → P · "S")
With "R" ≔ (λ _ → flip (P · "R")))
((((_ ,) ,) , lift λ {_} → lower (P · "sym")) ,
(lift λ {_} yRx zRy → lower (P · "trans") zRy yRx))
| {
"alphanum_fraction": 0.4837092732,
"avg_line_length": 28.5,
"ext": "agda",
"hexsha": "ff680f1744a99c41d31bb68971396b95156a6619",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/README/Record.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/README/Record.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/README/Record.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 343,
"size": 1197
} |
module Golden.FstSnd where
open import Agda.Builtin.Nat
data Tuple a b : Set where
Tup : a -> b -> Tuple a b
fst : {a b : Set} -> Tuple a b -> a
fst (Tup x x₁) = x
snd : {a b : Set} -> Tuple a b -> b
snd (Tup x b) = b
tup1 : Tuple Nat Nat
tup1 = Tup 0 1
a = fst tup1
b = snd tup1
| {
"alphanum_fraction": 0.5868055556,
"avg_line_length": 15.1578947368,
"ext": "agda",
"hexsha": "811c24006477b8ee11d0f095a0a38346ffeb108d",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:48.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-05-24T10:45:59.000Z",
"max_forks_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-ocaml",
"max_forks_repo_path": "test/agda-ocaml/Golden/FstSnd.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_issues_repo_issues_event_max_datetime": "2018-11-05T21:28:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-29T13:37:52.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-ocaml",
"max_issues_repo_path": "test/agda-ocaml/Golden/FstSnd.agda",
"max_line_length": 35,
"max_stars_count": 48,
"max_stars_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-ocaml",
"max_stars_repo_path": "test/agda-ocaml/Golden/FstSnd.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-15T09:08:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-29T14:19:31.000Z",
"num_tokens": 117,
"size": 288
} |
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Builtin.Equality
-- Option --cubical implies --without-K
uip : {A : Set} {x : A} (p : x ≡ x) → p ≡ refl
uip refl = refl
| {
"alphanum_fraction": 0.6166666667,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "1e4c83e6a38506f76c76d969a3ba260e2c7146b1",
"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/Issue2446b.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/Issue2446b.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/Issue2446b.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 64,
"size": 180
} |
-- Check that checking of left-hand sides are postponed properly
-- when the type of an argument that is matched on is a meta.
data Nat : Set where
zero : Nat
suc : Nat → Nat
data X : Set where
zero : X
easy : _ → Nat
easy (suc n) = n
easy zero = zero
-- TODO: uncomment below once LHS postponing is actually implemented
-- hard : _ → Nat
-- hard zero = zero
-- hard (suc n) = hard n
-- _$_ : {A B : Set} → (A → B) → A → B
-- f $ x = f x
-- plam : Nat
-- plam = (λ { zero → zero; (suc n) → n }) $ suc zero
| {
"alphanum_fraction": 0.5901328273,
"avg_line_length": 19.5185185185,
"ext": "agda",
"hexsha": "c6a6c5f7e76f11eaf32feffc88430b1af9a5f7fa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/PostponeLHS.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/PostponeLHS.agda",
"max_line_length": 68,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/PostponeLHS.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 176,
"size": 527
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n )
module FLComm (n : ℕ) where
open import Level renaming ( suc to Suc ; zero to Zero ) hiding (lift)
open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ ; _≟_)
open import Data.Fin.Properties hiding ( <-trans ; ≤-refl ; ≤-trans ; ≤-irrelevant ; _≟_ ) renaming ( <-cmp to <-fcmp )
open import Data.Fin.Permutation
open import Data.Nat.Properties
open import Relation.Binary.PropositionalEquality hiding ( [_] ) renaming ( sym to ≡-sym )
open import Data.List using (List; []; _∷_ ; length ; _++_ ; tail ) renaming (reverse to rev )
open import Data.Product hiding (_,_ )
open import Relation.Nullary
open import Data.Unit hiding (_≤_)
open import Data.Empty
open import Relation.Binary.Core
open import Relation.Binary.Definitions hiding (Symmetric )
open import logic
open import nat
open import FLutil
open import Putil
import Solvable
open import Symmetric
-- infixr 100 _::_
open import Relation.Nary using (⌊_⌋)
open import Data.List.Fresh hiding ([_])
open import Data.List.Fresh.Relation.Unary.Any
open import Algebra
open Group (Symmetric n) hiding (refl)
open Solvable (Symmetric n)
open _∧_
-- open import Relation.Nary using (⌊_⌋)
open import Relation.Nullary.Decidable hiding (⌊_⌋)
open import fin
-- all cobmbination in P and Q (could be more general)
record AnyComm {n m l : ℕ} (P : FList n) (Q : FList m) (fpq : (p : FL n) (q : FL m) → FL l) : Set where
field
commList : FList l
commAny : (p : FL n) (q : FL m)
→ Any ( p ≡_ ) P → Any ( q ≡_ ) Q
→ Any (fpq p q ≡_) commList
-------------
-- (p,q) (p,qn) .... (p,q0)
-- pn,q
-- : AnyComm FL0 FL0 P Q
-- p0,q
open AnyComm
anyComm : {n m l : ℕ } → (P : FList n) (Q : FList m) → (fpq : (p : FL n) (q : FL m) → FL l) → AnyComm P Q fpq
anyComm [] [] _ = record { commList = [] ; commAny = λ _ _ () }
anyComm [] (cons q Q qr) _ = record { commList = [] ; commAny = λ _ _ () }
anyComm (cons p P pr) [] _ = record { commList = [] ; commAny = λ _ _ _ () }
anyComm {n} {m} {l} (cons p P pr) (cons q Q qr) fpq = record { commList = FLinsert (fpq p q) (commListQ Q) ; commAny = anyc0n } where
commListP : (P1 : FList n) → FList l
commListP [] = commList (anyComm P Q fpq)
commListP (cons p₁ P1 x) = FLinsert (fpq p₁ q) (commListP P1)
commListQ : (Q1 : FList m) → FList l
commListQ [] = commListP P
commListQ (cons q₁ Q1 qr₁) = FLinsert (fpq p q₁) (commListQ Q1)
anyc0n : (p₁ : FL n) (q₁ : FL m) → Any (_≡_ p₁) (cons p P pr) → Any (_≡_ q₁) (cons q Q qr)
→ Any (_≡_ (fpq p₁ q₁)) (FLinsert (fpq p q) (commListQ Q))
anyc0n p₁ q₁ (here refl) (here refl) = x∈FLins _ (commListQ Q )
anyc0n p₁ q₁ (here refl) (there anyq) = insAny (commListQ Q) (anyc01 Q anyq) where
anyc01 : (Q1 : FList m) → Any (_≡_ q₁) Q1 → Any (_≡_ (fpq p₁ q₁)) (commListQ Q1)
anyc01 (cons q Q1 qr₂) (here refl) = x∈FLins _ _
anyc01 (cons q₂ Q1 qr₂) (there any) = insAny _ (anyc01 Q1 any)
anyc0n p₁ q₁ (there anyp) (here refl) = insAny _ (anyc02 Q) where
anyc03 : (P1 : FList n) → Any (_≡_ p₁) P1 → Any (_≡_ (fpq p₁ q₁)) (commListP P1)
anyc03 (cons a P1 x) (here refl) = x∈FLins _ _
anyc03 (cons a P1 x) (there any) = insAny _ ( anyc03 P1 any)
anyc02 : (Q1 : FList m) → Any (_≡_ (fpq p₁ q₁)) (commListQ Q1)
anyc02 [] = anyc03 P anyp
anyc02 (cons a Q1 x) = insAny _ (anyc02 Q1)
anyc0n p₁ q₁ (there anyp) (there anyq) = insAny (commListQ Q) (anyc04 Q) where
anyc05 : (P1 : FList n) → Any (_≡_ (fpq p₁ q₁)) (commListP P1)
anyc05 [] = commAny (anyComm P Q fpq) p₁ q₁ anyp anyq
anyc05 (cons a P1 x) = insAny _ (anyc05 P1)
anyc04 : (Q1 : FList m) → Any (_≡_ (fpq p₁ q₁)) (commListQ Q1)
anyc04 [] = anyc05 P
anyc04 (cons a Q1 x) = insAny _ (anyc04 Q1)
-------------
-- # 0 :: # 0 :: # 0 : # 0 :: f0
-- # 0 :: # 0 :: # 1 : # 0 :: f0
-- # 0 :: # 1 :: # 0 : # 0 :: f0
-- # 0 :: # 1 :: # 1 : # 0 :: f0
-- # 0 :: # 2 :: # 0 : # 0 :: f0
-- ...
-- # 3 :: # 2 :: # 0 : # 0 :: f0
-- # 3 :: # 2 :: # 1 : # 0 :: f0
-- all FL
record AnyFL (n : ℕ) : Set where
field
allFL : FList n
anyP : (x : FL n) → Any (x ≡_ ) allFL
open AnyFL
-- all FL as all combination
-- anyComm ( #0 :: FL0 ... # n :: FL0 ) (all n) (λ p q → FLpos p :: q ) = all (suc n)
anyFL01 : (n : ℕ) → AnyFL (suc n)
anyFL01 zero = record { allFL = (zero :: f0) ∷# [] ; anyP = λ x → anyFL2 x ((zero :: f0) ∷# []) refl } where
anyFL2 : (x : FL 1) → (y : FList 1) → y ≡ ((zero :: f0) ∷# []) → Any (_≡_ x) y
anyFL2 (zero :: f0) .(cons (zero :: f0) [] (Level.lift tt)) refl = here refl
anyFL01 (suc n) = record { allFL = commList anyC ; anyP = anyFL02 } where
anyFL05 : {n i : ℕ} → (i < suc n) → FList (suc n)
anyFL05 {_} {0} (s≤s z≤n) = zero :: FL0 ∷# []
anyFL05 {n} {suc i} (s≤s i<n) = FLinsert (fromℕ< (s≤s i<n) :: FL0) (anyFL05 {n} {i} (<-trans i<n a<sa))
anyFL08 : {n i : ℕ} {x : Fin (suc n)} {i<n : suc i < suc n} → toℕ x ≡ suc i → x ≡ suc (fromℕ< (≤-pred i<n))
anyFL08 {n} {i} {x} {i<n} eq = toℕ-injective ( begin
toℕ x ≡⟨ eq ⟩
suc i ≡⟨ cong suc (≡-sym (toℕ-fromℕ< _ )) ⟩
suc (toℕ (fromℕ< (≤-pred i<n)) )
∎ ) where open ≡-Reasoning
anyFL06 : {n i : ℕ} → (i<n : i < suc n) → (x : Fin (suc n)) → toℕ x < suc i → Any (_≡_ (x :: FL0)) (anyFL05 i<n)
anyFL06 (s≤s z≤n) zero (s≤s lt) = here refl
anyFL06 {n} {suc i} (s≤s (s≤s i<n)) x (s≤s lt) with <-cmp (toℕ x) (suc i)
... | tri< a ¬b ¬c = insAny _ (anyFL06 (<-trans (s≤s i<n) a<sa) x a)
... | tri≈ ¬a b ¬c = subst (λ k → Any (_≡_ (x :: FL0)) (FLinsert (k :: FL0) (anyFL05 {n} {i} (<-trans (s≤s i<n) a<sa))))
(anyFL08 {n} {i} {x} {s≤s (s≤s i<n)} b) (x∈FLins (x :: FL0) (anyFL05 {n} {i} (<-trans (s≤s i<n) a<sa)))
... | tri> ¬a ¬b c = ⊥-elim ( nat-≤> c (s≤s lt) )
anyC = anyComm (anyFL05 a<sa) (allFL (anyFL01 n)) (λ p q → FLpos p :: q )
anyFL02 : (x : FL (suc (suc n))) → Any (_≡_ x) (commList anyC)
anyFL02 (x :: y) = commAny anyC (x :: FL0) y
(subst (λ k → Any (_≡_ (k :: FL0) ) _) (fromℕ<-toℕ _ _) (anyFL06 a<sa (fromℕ< x≤n) fin<n) ) (anyP (anyFL01 n) y) where
x≤n : suc (toℕ x) ≤ suc (suc n)
x≤n = toℕ<n x
anyFL : (n : ℕ) → AnyFL n
anyFL zero = record { allFL = f0 ∷# [] ; anyP = anyFL4 } where
anyFL4 : (x : FL zero) → Any (_≡_ x) ( f0 ∷# [] )
anyFL4 f0 = here refl
anyFL (suc n) = anyFL01 n
at1 = proj₁ (toList (allFL (anyFL 1)))
at2 = proj₁ (toList (allFL (anyFL 2)))
at3 = proj₁ (toList (allFL (anyFL 3)))
at4 = proj₁ (toList (allFL (anyFL 4)))
CommFListN : ℕ → FList n
CommFListN zero = allFL (anyFL n)
CommFListN (suc i ) = commList (anyComm ( CommFListN i ) ( CommFListN i ) (λ p q → perm→FL [ FL→perm p , FL→perm q ] ))
CommStage→ : (i : ℕ) → (x : Permutation n n ) → deriving i x → Any (perm→FL x ≡_) (CommFListN i)
CommStage→ zero x (Level.lift tt) = anyP (anyFL n) (perm→FL x)
CommStage→ (suc i) .( [ g , h ] ) (comm {g} {h} p q) = comm2 where
G = perm→FL g
H = perm→FL h
comm3 : perm→FL [ FL→perm G , FL→perm H ] ≡ perm→FL [ g , h ]
comm3 = begin
perm→FL [ FL→perm G , FL→perm H ]
≡⟨ pcong-pF (comm-resp (FL←iso _) (FL←iso _)) ⟩
perm→FL [ g , h ]
∎ where open ≡-Reasoning
comm2 : Any (_≡_ (perm→FL [ g , h ])) (CommFListN (suc i))
comm2 = subst (λ k → Any (_≡_ k) (CommFListN (suc i)) ) comm3
( commAny ( anyComm (CommFListN i) (CommFListN i) (λ p q → perm→FL [ FL→perm p , FL→perm q ] )) G H (CommStage→ i g p) (CommStage→ i h q) )
CommStage→ (suc i) x (ccong {f} {x} eq p) =
subst (λ k → Any (k ≡_) (commList (anyComm ( CommFListN i ) ( CommFListN i ) (λ p q → perm→FL [ FL→perm p , FL→perm q ] ))))
(comm4 eq) (CommStage→ (suc i) f p ) where
comm4 : f =p= x → perm→FL f ≡ perm→FL x
comm4 = pcong-pF
CommSolved : (x : Permutation n n) → (y : FList n) → y ≡ FL0 ∷# [] → (FL→perm (FL0 {n}) =p= pid ) → Any (perm→FL x ≡_) y → x =p= pid
CommSolved x .(cons FL0 [] (Level.lift tt)) refl eq0 (here eq) = FLpid _ eq eq0
| {
"alphanum_fraction": 0.5386566804,
"avg_line_length": 47.3028571429,
"ext": "agda",
"hexsha": "4984f676edbf0b638d5cfec0b9e07ae4b9ea4295",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/Galois",
"max_forks_repo_path": "src/FLComm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/Galois",
"max_issues_repo_path": "src/FLComm.agda",
"max_line_length": 145,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/Galois",
"max_stars_repo_path": "src/FLComm.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-16T03:37:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-16T03:37:05.000Z",
"num_tokens": 3480,
"size": 8278
} |
module _ where
open import Common.Prelude renaming (_∸_ to _-_) -- work-around for #1855
data Acc {a} {A : Set a} (_<_ : A → A → Set) (x : A) : Set a where
acc : (∀ y → y < x → Acc _<_ y) → Acc _<_ x
data _<_ : Nat → Nat → Set where
zero : ∀ {n} → zero < suc n
suc : ∀ {n m} → n < m → suc n < suc m
_≤_ : Nat → Nat → Set
n ≤ m = n < suc m
data LeqView (n : Nat) : Nat → Set where
less : ∀ {m} → n < m → LeqView n m
equal : LeqView n n
leqView : ∀ {n m} → n ≤ m → LeqView n m
leqView {m = zero} zero = equal
leqView {m = suc m} zero = less zero
leqView {m = zero} (suc ())
leqView {m = suc m} (suc leq) with leqView leq
leqView {._} {suc m} (suc leq) | less lt = less (suc lt)
leqView {.(suc m)} {suc m} (suc lt) | equal = equal
case_of_ : ∀ {A B : Set} → A → (A → B) → B
case x of f = f x
wfAux : ∀ {n y} → (∀ z → z < n → Acc _<_ z) → y ≤ n → Acc _<_ y
wfAux f leq with leqView leq
wfAux f leq | less lt = f _ lt
wfAux f leq | equal = acc f
wfNat : ∀ n → Acc _<_ n
wfNat zero = acc λ _ ()
wfNat (suc n) with wfNat n
... | acc f = acc (λ y lt → wfAux f lt)
≤-refl : ∀ n → n ≤ n
≤-refl zero = zero
≤-refl (suc n) = suc (≤-refl n)
wk< : ∀ {n m} → n < m → n < suc m
wk< zero = zero
wk< (suc lt) = suc (wk< lt)
less-minus : ∀ n m → (suc n - suc m) ≤ n
less-minus n zero = ≤-refl n
less-minus zero (suc m) = zero
less-minus (suc n) (suc m) = wk< (less-minus n m)
NonZero : Nat → Set
NonZero zero = ⊥
NonZero (suc _) = ⊤
divsuc : ∀ n → Nat → Acc _<_ n → Nat
divsuc 0 _ _ = 0
divsuc (suc n) m (acc f) =
suc (divsuc (n - m) m (f _ (less-minus n m)))
div : Nat → (m : Nat) → {_ : NonZero m} → Nat
div n zero {}
div n (suc m) = divsuc n m (wfNat n)
main : IO Unit
main = printNat (div 1000000 1000)
| {
"alphanum_fraction": 0.5456130157,
"avg_line_length": 24.9420289855,
"ext": "agda",
"hexsha": "236953fc00934b841d3f9565f5685b76230e1ff8",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Compiler/simple/WfRec.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Compiler/simple/WfRec.agda",
"max_line_length": 73,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Compiler/simple/WfRec.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": 749,
"size": 1721
} |
module Data.Star.Indexed where
open import Relation.Binary
open import Function
open import Level
infixr 10 _◅_
data Star {i a t}(I : Set i){A : I → Set a}
(T : ∀ n m → REL (A n) (A m) t) : ∀ {n m : I} → REL (A n) (A m) (i ⊔ a ⊔ t) where
ε : ∀ {i}{x : A i} → Star I T x x
_◅_ : ∀ {n m k : I}{x : A n}{y : A m}{z : A k} → T n m x y → Star I T y z → Star I T x z
| {
"alphanum_fraction": 0.5160427807,
"avg_line_length": 31.1666666667,
"ext": "agda",
"hexsha": "a6348f727b7c34400c8c305739f778a228a36af9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/Data/Star/Indexed.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/Data/Star/Indexed.agda",
"max_line_length": 90,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/Data/Star/Indexed.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 165,
"size": 374
} |
open import Nat
open import Prelude
open import core
open import lemmas-gcomplete
module lemmas-complete where
-- no term is both complete and indeterminate
lem-ind-comp : ∀{d} → d dcomplete → d indet → ⊥
lem-ind-comp DCVar ()
lem-ind-comp DCConst ()
lem-ind-comp (DCLam comp x₁) ()
lem-ind-comp (DCAp comp comp₁) (IAp x ind x₁) = lem-ind-comp comp ind
lem-ind-comp (DCCast comp x x₁) (ICastArr x₂ ind) = lem-ind-comp comp ind
lem-ind-comp (DCCast comp x x₁) (ICastGroundHole x₂ ind) = lem-ind-comp comp ind
lem-ind-comp (DCCast comp x x₁) (ICastHoleGround x₂ ind x₃) = lem-ind-comp comp ind
-- complete types that are consistent are equal
complete-consistency : ∀{τ1 τ2} → τ1 ~ τ2 → τ1 tcomplete → τ2 tcomplete → τ1 == τ2
complete-consistency TCRefl TCBase comp2 = refl
complete-consistency TCRefl (TCArr comp1 comp2) comp3 = refl
complete-consistency TCHole1 comp1 ()
complete-consistency TCHole2 () comp2
complete-consistency (TCArr consis consis₁) (TCArr comp1 comp2) (TCArr comp3 comp4)
with complete-consistency consis comp1 comp3 | complete-consistency consis₁ comp2 comp4
... | refl | refl = refl
-- a well typed complete term is assigned a complete type
complete-ta : ∀{Γ Δ d τ} → (Γ gcomplete) →
(Δ , Γ ⊢ d :: τ) →
d dcomplete →
τ tcomplete
complete-ta gc TAConst comp = TCBase
complete-ta gc (TAVar x₁) DCVar = gc _ _ x₁
complete-ta gc (TALam a wt) (DCLam comp x₁) = TCArr x₁ (complete-ta (gcomp-extend gc x₁ a ) wt comp)
complete-ta gc (TAAp wt wt₁) (DCAp comp comp₁) with complete-ta gc wt comp
complete-ta gc (TAAp wt wt₁) (DCAp comp comp₁) | TCArr qq qq₁ = qq₁
complete-ta gc (TAEHole x x₁) ()
complete-ta gc (TANEHole x wt x₁) ()
complete-ta gc (TACast wt x) (DCCast comp x₁ x₂) = x₂
complete-ta gc (TAFailedCast wt x x₁ x₂) ()
-- a well typed term synthesizes a complete type
comp-synth : ∀{Γ e τ} →
Γ gcomplete →
e ecomplete →
Γ ⊢ e => τ →
τ tcomplete
comp-synth gc ec SConst = TCBase
comp-synth gc (ECAsc x ec) (SAsc x₁) = x
comp-synth gc ec (SVar x) = gc _ _ x
comp-synth gc (ECAp ec ec₁) (SAp _ wt MAHole x₁) with comp-synth gc ec wt
... | ()
comp-synth gc (ECAp ec ec₁) (SAp _ wt MAArr x₁) with comp-synth gc ec wt
comp-synth gc (ECAp ec ec₁) (SAp _ wt MAArr x₁) | TCArr qq qq₁ = qq₁
comp-synth gc () SEHole
comp-synth gc () (SNEHole _ wt)
comp-synth gc (ECLam2 ec x₁) (SLam x₂ wt) = TCArr x₁ (comp-synth (gcomp-extend gc x₁ x₂) ec wt)
| {
"alphanum_fraction": 0.6446914527,
"avg_line_length": 44.2203389831,
"ext": "agda",
"hexsha": "a655a13d177ec7c4d1fbae0b8b8e3873152ef501",
"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": "lemmas-complete.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": "lemmas-complete.agda",
"max_line_length": 102,
"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": "lemmas-complete.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": 913,
"size": 2609
} |
-- Andreas, 2020-03-27, issue #4534
-- Better error message for quote.
open import Agda.Builtin.Reflection
quote₀ : Set → Name
quote₀ X = quote X
-- Cannot quote a variable X
-- when checking that the expression quote X has type Name
| {
"alphanum_fraction": 0.7341772152,
"avg_line_length": 21.5454545455,
"ext": "agda",
"hexsha": "82b48dafe45f92dd433981916dd83a6b8b2b0d16",
"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/Issue4534.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/Issue4534.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4534.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 64,
"size": 237
} |
{-# OPTIONS --without-K #-}
module well-typed-syntax-context-helpers where
open import common
open import well-typed-syntax
open import well-typed-syntax-helpers
□_ : Typ ε → Set
□_ T = Term {Γ = ε} T
| {
"alphanum_fraction": 0.7178217822,
"avg_line_length": 22.4444444444,
"ext": "agda",
"hexsha": "3a7a99671944928f6ff46e7fe85f7768b56a2c3a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JasonGross/lob",
"max_forks_repo_path": "internal/well-typed-syntax-context-helpers.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JasonGross/lob",
"max_issues_repo_path": "internal/well-typed-syntax-context-helpers.agda",
"max_line_length": 46,
"max_stars_count": 19,
"max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JasonGross/lob",
"max_stars_repo_path": "internal/well-typed-syntax-context-helpers.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z",
"num_tokens": 59,
"size": 202
} |
open import Everything
module Test.Surjidentity where
module _
{𝔬₁ 𝔯₁ 𝔬₂ 𝔯₂ ℓ₂}
{𝔒₁ : Ø 𝔬₁}
(_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
{𝔒₂ : Ø 𝔬₂}
(_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(_∼₂'_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
(_∼̇₂'_ : ∀ {x y} → x ∼₂' y → x ∼₂' y → Ø ℓ₂)
(ε₁ : Reflexivity.type _∼₁_)
(ε₂ : Reflexivity.type _∼₂_)
(_↦₁_ : Transitivity.type _∼₁_)
(_↦₂_ : Transitivity.type _∼₂_)
{ℓ₁} (_∼̇₁_ : ∀ {x y} → x ∼₁ y → x ∼₁ y → Ø ℓ₁)
{ℓ₁'} (_∼̇₁'_ : ∀ {x y} → x ∼₁ y → x ∼₁ y → Ø ℓ₁')
(μ₁₂ : Surjection.type _ _)
(μ₂₂ : Surjection.type _ _)
{smap₁₂ : Smap.type _∼₁_ _∼₂_ μ₁₂ μ₁₂}
{smap₂₂ : Smap.type _∼₂_ _∼₂_ μ₂₂ μ₂₂}
⦃ I1 : IsFunctor _∼₁_ _∼̇₁_ ε₁ _↦₁_ _∼₂_ _∼̇₂_ ε₂ _↦₂_ smap₁₂ ⦄ -- FIXME using top-level instances does not work b/c then there is not instance found for reflexivity.
⦃ I2 : IsFunctor _∼₂_ _∼̇₂_ ε₂ _↦₂_ _∼₂_ _∼̇₂_ ε₂ _↦₂_ smap₂₂ ⦄
⦃ I3 : IsFunctor _∼₁_ _∼̇₁'_ ε₁ _↦₁_ _∼₂_ _∼̇₂_ ε₂ _↦₂_ smap₁₂ ⦄
where
{- FIXME would like to try this instead of instance arguments
postulate
instance
I1 : IsFunctor _∼₁_ _∼̇₁_ _↦₁_ _∼₂_ _∼̇₂_ _↦₂_ smap₁₂
I2 : IsFunctor _∼₂_ _∼̇₂_ _↦₂_ _∼₂_ _∼̇₂_ _↦₂_ smap₂₂
I3 : IsFunctor _∼₁_ _∼̇₁'_ _↦₁_ _∼₂_ _∼̇₂_ _↦₂_ smap₁₂
-}
test-surjidentity-from-IsFunctor : Surjidentity.type _∼₁_ _∼₂_ _∼̇₂_ smap₁₂ ε₁ ε₂
test-surjidentity-from-IsFunctor = surjidentity -- FIXME this works only b/c of overlap (the Surjidentity instance found is I1, not I3)
module _
{𝔬₁ 𝔯₁ 𝔬₂ 𝔯₂ ℓ₂}
{𝔒₁ : Ø 𝔬₁}
(_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
{𝔒₂ : Ø 𝔬₂}
(_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(_∼₂'_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
(_∼̇₂'_ : ∀ {x y} → x ∼₂' y → x ∼₂' y → Ø ℓ₂)
⦃ `𝓢urjection : Surjection.class 𝔒₁ 𝔒₂ ⦄
⦃ `𝓢urjectivity : Smap!.class _∼₁_ _∼₂_ ⦄
⦃ `𝓢urjectextensivity : Smap!.class _∼₁_ _∼₂'_ ⦄
⦃ `𝓡eflexivity₁ : Reflexivity.class _∼₁_ ⦄
⦃ `𝓡eflexivity₂ : Reflexivity.class _∼₂_ ⦄
⦃ `𝓡eflexivity₂' : Reflexivity.class _∼₂'_ ⦄
where
instance
`𝒮urjidentity : Surjidentity!.class _∼₁_ _∼₂_ _∼̇₂_
`𝒮urjidentity .⋆ = magic
test-surjidentity : Surjidentity!.type _∼₁_ _∼₂_ _∼̇₂_
test-surjidentity = surjidentity
| {
"alphanum_fraction": 0.5928143713,
"avg_line_length": 33.921875,
"ext": "agda",
"hexsha": "a2a0ef004386e1bd9b62a508405e06f5601d56e9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Test/Surjidentity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Test/Surjidentity.agda",
"max_line_length": 168,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Test/Surjidentity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1275,
"size": 2171
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Convenient syntax for reasoning with a partial setoid
------------------------------------------------------------------------
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Relation.Binary.Raw
module Cubical.Relation.Binary.Reasoning.PartialEquivalence
{c ℓ} {A : Type c} (E : PartialEquivalence A ℓ) where
open PartialEquivalence E
import Cubical.Relation.Binary.Reasoning.Base.Partial _≈_ transitive as Base
------------------------------------------------------------------------
-- Re-export the contents of the base module
open Base public
renaming (_∼⟨_⟩_ to _≈⟨_⟩_)
------------------------------------------------------------------------
-- Additional reasoning combinators
infixr 1 _≈˘⟨_⟩_
_≈˘⟨_⟩_ : ∀ x {y z} → y ≈ x → y IsRelatedTo z → x IsRelatedTo z
x ≈˘⟨ y≈x ⟩ y∼z = x ≈⟨ symmetric y≈x ⟩ y∼z
| {
"alphanum_fraction": 0.5030364372,
"avg_line_length": 31.8709677419,
"ext": "agda",
"hexsha": "c4243b62356c7c093d29cc891535ac8c640fc15b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Binary/Reasoning/PartialEquivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Binary/Reasoning/PartialEquivalence.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Binary/Reasoning/PartialEquivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 249,
"size": 988
} |
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
open import Agda.Builtin.Float
NaN : Float
NaN = primFloatDiv 0.0 0.0
defNaN : NaN ≡ NaN
defNaN = refl
primEqNaN : primFloatEquality NaN NaN ≡ true
primEqNaN = refl
| {
"alphanum_fraction": 0.7639484979,
"avg_line_length": 16.6428571429,
"ext": "agda",
"hexsha": "cb0d762e677bfa0cfe498ef56662e6731ed1a133",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.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/Issue2155.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/Issue2155.agda",
"max_line_length": 44,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/Issue2155.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 76,
"size": 233
} |
module Lemmachine where
open import Lemmachine.Request public
open import Lemmachine.Response public
open import Lemmachine.Resource public
open import Lemmachine.Resource.Configure public
open import Lemmachine.Resolve
open import Lemmachine.Utils public
open import Lemmachine.Runner public
open import Data.Bool public hiding (_≟_)
open import Data.List public
toApp : Hooks → Application
toApp hs = resolve (toResource hs)
| {
"alphanum_fraction": 0.8344988345,
"avg_line_length": 28.6,
"ext": "agda",
"hexsha": "a6144c0538f7051262eeeca5959c8e8aa599a8d7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "src/Lemmachine.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "src/Lemmachine.agda",
"max_line_length": 48,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "src/Lemmachine.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 88,
"size": 429
} |
open import Prelude
module Implicits.Semantics.Preservation where
open import Implicits.Syntax
open import Implicits.WellTyped
open import Implicits.Semantics.Type
open import Implicits.Semantics.Context
open import Implicits.Semantics.Lemmas
open import Implicits.Semantics.RewriteContext
open import Implicits.Semantics.Term
open import SystemF.Everything as F using ()
module Preservation
(_⊢ᵣ_ : ∀ {ν} → ICtx ν → Type ν → Set)
(⟦_,_⟧r : ∀ {ν n} {K : Ktx ν n} {a} → (proj₂ K) ⊢ᵣ a → K# K →
∃ λ t → ⟦ proj₁ K ⟧ctx→ F.⊢ t ∈ ⟦ a ⟧tp→) where
open TypingRules _⊢ᵣ_
open TermSemantics _⊢ᵣ_ ⟦_,_⟧r
-- interpretation of well-typed terms in System F preserves type
⟦⟧-preserves-tp : ∀ {ν n} {K : Ktx ν n} {t a} → (wt-t : K ⊢ t ∈ a) → (m : K# K) →
⟦ proj₁ K ⟧ctx→ F.⊢ ⟦ wt-t , m ⟧ ∈ ⟦ a ⟧tp→
⟦⟧-preserves-tp {K = K} (var x) m = subst-wt-var (sym $ lookup-⟦⟧ctx→ (proj₁ K) x) (F.var x)
where
subst-wt-var = subst (λ a → ⟦ proj₁ K ⟧ctx→ F.⊢ (F.var x) ∈ a)
⟦⟧-preserves-tp {K = K} {a = ∀' a} (Λ wt-e) m with ⟦⟧-preserves-tp wt-e (#tvar m)
... | ih = F.Λ (subst-wt-ctx (⟦weaken⟧ctx→ (proj₁ K)) ih)
where
subst-wt-ctx = subst (λ c → c F.⊢ ⟦ wt-e , #tvar m ⟧ ∈ ⟦ a ⟧tp→)
⟦⟧-preserves-tp (λ' a wt-e) m with ⟦⟧-preserves-tp wt-e (#var a m)
⟦⟧-preserves-tp (λ' a wt-e) m | ih = F.λ' ⟦ a ⟧tp→ ih
⟦⟧-preserves-tp {K = K} (_[_] {a = a} wt-tc b) m with ⟦⟧-preserves-tp wt-tc m
... | ih = subst-tp (sym $ ⟦a/sub⟧tp→ a b) (ih F.[ ⟦ b ⟧tp→ ])
where
subst-tp = subst (λ c → ⟦ proj₁ K ⟧ctx→ F.⊢ ⟦ wt-tc [ b ] , m ⟧ ∈ c)
⟦⟧-preserves-tp (wt-f · wt-e) m with ⟦⟧-preserves-tp wt-f m | ⟦⟧-preserves-tp wt-e m
⟦⟧-preserves-tp (wt-f · wt-e) m | ih | y = ih F.· y
⟦⟧-preserves-tp (ρ {a = a} unamb-a wt-e) m with ⟦⟧-preserves-tp wt-e (#ivar a m)
⟦⟧-preserves-tp (ρ {a = a} unamb-a wt-e) m | ih = F.λ' ⟦ a ⟧tp→ ih
⟦⟧-preserves-tp (wt-r ⟨ e ⟩) m with ⟦⟧-preserves-tp wt-r m
⟦⟧-preserves-tp (wt-r ⟨ e ⟩) m | f-wt-r = f-wt-r F.· (proj₂ ⟦ e , m ⟧r)
⟦⟧-preserves-tp (wt-r with' wt-e ) m with ⟦⟧-preserves-tp wt-r m | ⟦⟧-preserves-tp wt-e m
⟦⟧-preserves-tp (wt-r with' wt-e ) m | f-wt-r | f-wt-e = f-wt-r F.· f-wt-e
| {
"alphanum_fraction": 0.5619004111,
"avg_line_length": 46.5744680851,
"ext": "agda",
"hexsha": "1b70a3a797e8affb007b27e2e3c37106740ed8f0",
"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/Preservation.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/Preservation.agda",
"max_line_length": 94,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Semantics/Preservation.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": 1042,
"size": 2189
} |
-- Andreas, 2012-03-09, example by Ulf
{-# OPTIONS -v tc.conv.irr:50 -v tc.decl.ax:10 -v tc.decl.mutual:20 #-}
module Issue351-5 where
open import Common.Prelude
open import Common.Equality
open import Common.Irrelevance
postulate
foo : (x : Squash Nat) → ((r : Squash Nat) → r ≡ squash (suc (unsquash x))) → Set
bar : foo (squash _) (λ r → refl)
| {
"alphanum_fraction": 0.6770538244,
"avg_line_length": 29.4166666667,
"ext": "agda",
"hexsha": "0f51630a8cbaa933a46477b392c6d73c06e87d2a",
"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-5.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-5.agda",
"max_line_length": 83,
"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-5.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 124,
"size": 353
} |
module Path where
open import Basics hiding (_==_)
open import Proc
import Graph
private open module G = Graph Nat
data Node : Set where
node : Nat -> Node
stop : Node
_==_ : Node -> Node -> Bool
stop == stop = true
node zero == node zero = true
node (suc n) == node (suc m) = node n == node m
_ == _ = false
data U : Set where
int : U
ext : U
data Name : Set where
fwd-edge : Nat -> Nat -> Name
bwd-edge : Nat -> Node -> Name
start : Nat -> Name
finish : Nat -> Name
N : U -> Set
N int = Name
N ext = False
data Msg : Set where
forward : Node -> Node -> Msg
backward : Node -> Msg
T : U -> Set
T int = Msg
T ext = Node
private
module Impl where
private module P = ProcDef U T N
open P hiding (_!_)
P = Proc int
infixr 40 _!_
_!_ : Msg -> P -> P
m ! p = P._!_ (lift m) p
fwd : Nat -> Nat -> Msg
fwd from to = forward (node from) (node to)
fwd-runner : Nat -> Nat -> P
fwd-runner from to = > react
where
react : Msg -> P
react (forward from' to') =
if to' == node from
then fwd from to ! def (bwd-edge from from')
else def (fwd-edge from to)
react (backward _) = o
bwd-runner : Nat -> Node -> P
bwd-runner from w = > react
where
react : Msg -> P
react (backward n) =
if n == w then o
else if n == node from
then backward w ! o
else def (bwd-edge from w)
react (forward _ _) = def (bwd-edge from w)
pitcher : Nat -> P
pitcher n = forward stop (node n) ! o
batter : Nat -> P
batter n = > react
where
react : Msg -> P
react (forward from to) =
if to == node n
then backward from ! o
else def (start n)
react _ = def (start n)
env : Env
env int (fwd-edge from to) = fwd-runner from to
env int (bwd-edge from w) = bwd-runner from w
env int (start n) = batter n
env int (finish n) = pitcher n
env ext ()
edges : Graph -> P
edges [] = o
edges (edge x y :: G) = def (fwd-edge x y) || edges G
φ : Tran ext int
φ = record { upV = up; downV = down }
where
down : Node -> Lift Msg
down x = lift (backward x)
up : Msg -> Lift Node
up (forward _ _) = bot
up (backward x) = lift x
main : Graph -> Nat -> Nat -> Proc ext
main G x y = φ /| def (finish y) || def (start x) || edges G
open Impl public
param : Param
param = record
{ U = U
; T = T
; Name = N
; env = env
}
| {
"alphanum_fraction": 0.527734375,
"avg_line_length": 20.8130081301,
"ext": "agda",
"hexsha": "b918435fcd9cb16659867dd96bca5599be9ed79e",
"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": "examples/outdated-and-incorrect/cbs/Path.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/cbs/Path.agda",
"max_line_length": 62,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/cbs/Path.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": 802,
"size": 2560
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Setoids.Setoids
open import Groups.Definition
open import Sets.EquivalenceRelations
module Groups.Lemmas {a b : _} {A : Set a} {_·_ : A → A → A} {S : Setoid {a} {b} A} (G : Group S _·_) where
open Setoid S
open Group G
open Equivalence eq
groupsHaveLeftCancellation : (x y z : A) → (x · y) ∼ (x · z) → y ∼ z
groupsHaveLeftCancellation x y z pr = o
where
_^-1 = inverse
j : ((x ^-1) · x) · y ∼ (x ^-1) · (x · z)
j = transitive (symmetric (+Associative {x ^-1} {x} {y})) (+WellDefined ~refl pr)
k : ((x ^-1) · x) · y ∼ ((x ^-1) · x) · z
k = transitive j +Associative
l : 0G · y ∼ ((x ^-1) · x) · z
l = transitive (+WellDefined (symmetric invLeft) ~refl) k
m : 0G · y ∼ 0G · z
m = transitive l (+WellDefined invLeft ~refl)
n : y ∼ 0G · z
n = transitive (symmetric identLeft) m
o : y ∼ z
o = transitive n identLeft
groupsHaveRightCancellation : (x y z : A) → (y · x) ∼ (z · x) → y ∼ z
groupsHaveRightCancellation x y z pr = transitive m identRight
where
_^-1 = inverse
i : (y · x) · (x ^-1) ∼ (z · x) · (x ^-1)
i = +WellDefined pr ~refl
j : y · (x · (x ^-1)) ∼ (z · x) · (x ^-1)
j = transitive +Associative i
j' : y · 0G ∼ (z · x) · (x ^-1)
j' = transitive (+WellDefined ~refl (symmetric invRight)) j
k : y ∼ (z · x) · (x ^-1)
k = transitive (symmetric identRight) j'
l : y ∼ z · (x · (x ^-1))
l = transitive k (symmetric +Associative)
m : y ∼ z · 0G
m = transitive l (+WellDefined ~refl invRight)
rightInversesAreUnique : {x : A} → {y : A} → (y · x) ∼ 0G → y ∼ (inverse x)
rightInversesAreUnique {x} {y} f = transitive i (transitive j (transitive k (transitive l m)))
where
_^-1 = inverse
i : y ∼ y · 0G
j : y · 0G ∼ y · (x · (x ^-1))
k : y · (x · (x ^-1)) ∼ (y · x) · (x ^-1)
l : (y · x) · (x ^-1) ∼ 0G · (x ^-1)
m : 0G · (x ^-1) ∼ x ^-1
i = symmetric identRight
j = +WellDefined ~refl (symmetric invRight)
k = +Associative
l = +WellDefined f ~refl
m = identLeft
leftInversesAreUnique : {x : A} → {y : A} → (x · y) ∼ 0G → y ∼ (inverse x)
leftInversesAreUnique {x} {y} f = rightInversesAreUnique {x} {y} l
where
_^-1 = inverse
i : y · (x · y) ∼ y · 0G
i' : y · (x · y) ∼ y
j : (y · x) · y ∼ y
k : (y · x) · y ∼ 0G · y
l : y · x ∼ 0G
i = +WellDefined ~refl f
i' = transitive i identRight
j = transitive (symmetric +Associative) i'
k = transitive j (symmetric identLeft)
l = groupsHaveRightCancellation y (y · x) 0G k
invTwice : (x : A) → (inverse (inverse x)) ∼ x
invTwice x = symmetric (rightInversesAreUnique {x ^-1} {x} invRight)
where
_^-1 = inverse
replaceGroupOp : {a b c d w x y z : A} → (Setoid._∼_ S a c) → (Setoid._∼_ S b d) → (Setoid._∼_ S w y) → (Setoid._∼_ S x z) → Setoid._∼_ S (a · b) (w · x) → Setoid._∼_ S (c · d) (y · z)
replaceGroupOp a~c b~d w~y x~z pr = transitive (symmetric (+WellDefined a~c b~d)) (transitive pr (+WellDefined w~y x~z))
replaceGroupOpRight : {a b c x : A} → (Setoid._∼_ S a (b · c)) → (Setoid._∼_ S c x) → (Setoid._∼_ S a (b · x))
replaceGroupOpRight a~bc c~x = transitive a~bc (+WellDefined reflexive c~x)
inverseWellDefined : {x y : A} → (x ∼ y) → (inverse x) ∼ (inverse y)
inverseWellDefined {x} {y} x~y = groupsHaveRightCancellation x (inverse x) (inverse y) q
where
p : inverse x · x ∼ inverse y · y
p = transitive invLeft (symmetric invLeft)
q : inverse x · x ∼ inverse y · x
q = replaceGroupOpRight {_·_ (inverse x) x} {inverse y} {y} {x} p (symmetric x~y)
transferToRight : {a b : A} → (a · (inverse b)) ∼ 0G → a ∼ b
transferToRight {a} {b} ab-1 = transitive (symmetric (invTwice a)) (transitive u (invTwice b))
where
t : inverse a ∼ inverse b
t = symmetric (leftInversesAreUnique ab-1)
u : inverse (inverse a) ∼ inverse (inverse b)
u = inverseWellDefined t
transferToRight' : {a b : A} → (a · b) ∼ 0G → a ∼ (inverse b)
transferToRight' {a} {b} ab-1 = transferToRight lemma
where
lemma : a · (inverse (inverse b)) ∼ 0G
lemma = transitive (+WellDefined reflexive (invTwice b)) ab-1
transferToRight'' : {a b : A} → Setoid._∼_ S a b → (a · (inverse b)) ∼ 0G
transferToRight'' {a} {b} a~b = transitive (+WellDefined a~b reflexive) invRight
invInv : {x : A} → (inverse (inverse x)) ∼ x
invInv {x} = symmetric (transferToRight' invRight)
invIdent : (inverse 0G) ∼ 0G
invIdent = symmetric (transferToRight' identLeft)
swapInv : {x y : A} → (inverse x) ∼ y → x ∼ (inverse y)
swapInv {x} {y} -x=y = transitive (symmetric invInv) (inverseWellDefined -x=y)
identityIsUnique : (e : A) → ((b : A) → ((b · e) ∼ b)) → (e ∼ 0G)
identityIsUnique thing fb = transitive (symmetric identLeft) (fb 0G)
invContravariant : {x y : A} → (Setoid._∼_ S (Group.inverse G (x · y)) ((Group.inverse G y) · (Group.inverse G x)))
invContravariant {x} {y} = ans
where
_^-1 = inverse
otherInv = (y ^-1) · (x ^-1)
many+Associatives : x · ((y · (y ^-1)) · (x ^-1)) ∼ (x · y) · ((y ^-1) · (x ^-1))
oneMult : (x · y) · otherInv ∼ x · (x ^-1)
many+Associatives = transitive +Associative (transitive (+WellDefined +Associative reflexive) (symmetric +Associative))
oneMult = symmetric (transitive (+WellDefined reflexive (transitive (symmetric identLeft) (+WellDefined (symmetric invRight) reflexive))) many+Associatives)
otherInvIsInverse : (x · y) · otherInv ∼ 0G
otherInvIsInverse = transitive oneMult invRight
ans : (x · y) ^-1 ∼ (y ^-1) · (x ^-1)
ans = symmetric (leftInversesAreUnique otherInvIsInverse)
equalsDoubleImpliesZero : {x : A} → (x · x) ∼ x → x ∼ 0G
equalsDoubleImpliesZero 2x=x = transitive (symmetric identLeft) (transitive (+WellDefined (symmetric invLeft) reflexive) (transitive (symmetric +Associative) (transitive (+WellDefined reflexive 2x=x) invLeft)))
invZeroImpliesZero : {x : A} → (inverse x) ∼ 0G → x ∼ 0G
invZeroImpliesZero {x} pr = transitive (symmetric (invTwice x)) (transitive (inverseWellDefined pr) invIdent)
| {
"alphanum_fraction": 0.6028571429,
"avg_line_length": 41.0344827586,
"ext": "agda",
"hexsha": "da792fc342ba48adf12dfd3142b619dc0abaf9b8",
"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/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/Lemmas.agda",
"max_line_length": 210,
"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/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 2366,
"size": 5950
} |
open import MLib.Algebra.PropertyCode
module MLib.Algebra.PropertyCode.Dependent {k c ℓ} {code : Code k} (struct : Struct code c ℓ) where
open import MLib.Prelude
open import MLib.Algebra.PropertyCode.Core
open import Function.Equivalence using (Equivalence)
open Struct struct
private
module FuncBased {c′ ℓ′} (depRawStruct : RawStruct K c′ ℓ′) (props : ∀ π → Maybe (∃ λ deps → ⦃ _ : Hasₚ deps ⦄ → ⟦ π ⟧P depRawStruct)) where
Π′ : Properties code
Π′ = properties λ π →
case props π of λ
{ (just (deps , _)) → implies deps Π
; nothing → false
}
Π′-prop : ∀ {π} → π ∈ₚ Π′ → ∃ λ x → props π ≡ just x
Π′-prop {π} π∈Π′ with props π | ≡.inspect props π
Π′-prop {π} π∈Π′ | just x | _ = x , ≡.refl
Π′-prop {π} (fromTruth truth) | nothing | ≡.[ eq ] rewrite eq = ⊥-elim truth
reify′ : ∀ {π} → π ∈ₚ Π′ → ⟦ π ⟧P depRawStruct
reify′ {π} π∈Π′ with Π′-prop π∈Π′ | hasProperty Π′ π | ≡.inspect (hasProperty Π′) π
reify′ {_} (fromTruth truth) | (deps , f) , eq | false | ≡.[ eq₁ ] rewrite eq | eq₁ = ⊥-elim truth
reify′ {_} (fromTruth truth) | (deps , f) , eq | true | ≡.[ eq₁ ] rewrite eq = f ⦃ fromTruth truth ⦄
dependentStruct :
Struct code c′ ℓ′
dependentStruct = record
{ rawStruct = depRawStruct
; Π = Π′
; reify = reify′
}
module ListBased {c′ ℓ′} (depRawStruct : RawStruct K c′ ℓ′) (props : List (∃₂ λ π deps → ⦃ _ : Hasₚ deps ⦄ → ⟦ π ⟧P depRawStruct)) where
Func = ∀ π → Maybe (∃ (λ deps → ⦃ _ : Hasₚ deps ⦄ → ⟦ π ⟧P depRawStruct))
singleFunc : (∃₂ λ π deps → ⦃ _ : Hasₚ deps ⦄ → ⟦ π ⟧P depRawStruct) → Func
singleFunc (π , deps , f) π′ with π Property.≟ π′
singleFunc (π , deps , f) π′ | yes p rewrite Property.≈⇒≡ p = just (deps , f)
singleFunc (π , deps , f) π′ | no _ = nothing
combineFuncs : Func → Func → Func
combineFuncs f g π =
case f π of λ
{ (just r) → just r
; nothing → case g π of λ
{ (just r) → just r
; nothing → nothing
}
}
propsF : ∀ π → Maybe (∃ (λ deps → ⦃ _ : Hasₚ deps ⦄ → ⟦ π ⟧P depRawStruct))
propsF = List.foldr combineFuncs (λ _ → nothing) (List.map singleFunc props)
dependentStruct : Struct code c′ ℓ′
dependentStruct = FuncBased.dependentStruct depRawStruct propsF
open ListBased using (dependentStruct) public
| {
"alphanum_fraction": 0.5837239029,
"avg_line_length": 36.671875,
"ext": "agda",
"hexsha": "2e125944cff3420ece1e06f8986063b563e03e83",
"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": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Algebra/PropertyCode/Dependent.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"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": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Algebra/PropertyCode/Dependent.agda",
"max_line_length": 142,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Algebra/PropertyCode/Dependent.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 878,
"size": 2347
} |
module Nat where
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
_+_ : ℕ → ℕ → ℕ
zero + b = b
succ a + b = succ (a + b)
_×_ : ℕ → ℕ → ℕ
zero × b = zero
succ a × b = (a × b) + b
open import Relation.Binary.PropositionalEquality
0-is-right-identity-of-+ : ∀ (n : ℕ) → n + zero ≡ n
0-is-right-identity-of-+ zero = refl
0-is-right-identity-of-+ (succ n) = cong succ (0-is-right-identity-of-+ n)
+-is-associative : ∀ (a b c : ℕ) → a + (b + c) ≡ (a + b) + c
+-is-associative zero b c = refl
+-is-associative (succ a) b c = cong succ (+-is-associative a b c)
lemma : ∀ (a b : ℕ) → a + succ b ≡ succ (a + b)
lemma zero b = refl
lemma (succ a) b = cong succ (lemma a b)
import Relation.Binary.EqReasoning as EqR
open module EqNat = EqR (setoid ℕ)
+-is-commutative : ∀ (a b : ℕ) → a + b ≡ b + a
+-is-commutative a zero = 0-is-right-identity-of-+ a
+-is-commutative a (succ b) =
begin
a + succ b
≈⟨ lemma a b ⟩
succ (a + b)
≈⟨ cong succ (+-is-commutative a b) ⟩
succ (b + a)
≈⟨ refl ⟩
succ b + a
∎
| {
"alphanum_fraction": 0.5513413506,
"avg_line_length": 22.0612244898,
"ext": "agda",
"hexsha": "ab6f04098af1d31543d938d560e00e478f519fe8",
"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": "1062c0b81f8dbb664fcc9376ba13695f0ee7ebc8",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "piyush-kurur/sample-code",
"max_forks_repo_path": "agda/Nat.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "1062c0b81f8dbb664fcc9376ba13695f0ee7ebc8",
"max_issues_repo_issues_event_max_datetime": "2017-11-01T05:48:28.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-11-01T05:48:28.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "piyush-kurur/sample-code",
"max_issues_repo_path": "agda/Nat.agda",
"max_line_length": 74,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "1062c0b81f8dbb664fcc9376ba13695f0ee7ebc8",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "piyush-kurur/sample-code",
"max_stars_repo_path": "agda/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-20T02:19:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-06-19T12:34:08.000Z",
"num_tokens": 417,
"size": 1081
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor hiding (id)
-- category of cones "over a Functor F"
module Categories.Category.Construction.Cones
{o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} (F : Functor J C) where
open import Data.Product
import Categories.Diagram.Cone as Co
import Categories.Morphism as Mor
import Categories.Morphism.IsoEquiv as IsoEquiv
import Categories.Morphism.Reasoning as Reas
open Category C
open HomReasoning
open Mor C using (_≅_)
open IsoEquiv C using (_≃_; ⌞_⌟)
open Reas C
open Co F public
open Apex
open Cone
open Cone⇒
Cones : Category _ _ _
Cones = record
{ Obj = Cone
; _⇒_ = Cone⇒
; _≈_ = λ f g → arr f ≈ arr g
; id = record
{ arr = id
; commute = identityʳ
}
; _∘_ = λ {A B C} f g → record
{ arr = arr f ∘ arr g
; commute = λ {X} → begin
ψ C X ∘ arr f ∘ arr g ≈⟨ pullˡ (commute f) ⟩
ψ B X ∘ arr g ≈⟨ commute g ⟩
ψ A X ∎
}
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
; ∘-resp-≈ = ∘-resp-≈
}
module Cones = Category Cones
private
variable
K K′ : Cone
X : Obj
module CM = Mor Cones
module CI = IsoEquiv Cones
open CM using () renaming (_≅_ to _⇔_)
open CI using () renaming (_≃_ to _↮_)
cone-resp-iso : ∀ (κ : Cone) → Cone.N κ ≅ X → Σ[ κ′ ∈ Cone ] κ ⇔ κ′
cone-resp-iso {X = X} κ κ≅X = record
{ apex = record
{ ψ = λ Y → Cone.ψ κ Y ∘ to
; commute = λ f → pullˡ (Cone.commute κ f)
}
} , record
{ from = record
{ arr = from
; commute = cancelʳ isoˡ
}
; to = record
{ arr = to
; commute = refl
}
; iso = record
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
}
where open _≅_ κ≅X
open Cone
open Apex
iso-cone⇒iso-apex : K ⇔ K′ → N K ≅ N K′
iso-cone⇒iso-apex K⇔K′ = record
{ from = arr from
; to = arr to
; iso = record
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
}
where open _⇔_ K⇔K′
↮⇒-≃ : ∀ {i₁ i₂ : K ⇔ K′} → i₁ ↮ i₂ → iso-cone⇒iso-apex i₁ ≃ iso-cone⇒iso-apex i₂
↮⇒-≃ i₁↮i₂ = ⌞ from-≈ ⌟
where open _↮_ i₁↮i₂
-- -- .up-to-iso-cone-unique : ∀ L L′ → (i : proj-cone L ⇿ proj-cone L′) → up-to-iso-cone L L′ ≜ⁱ i
-- -- up-to-iso-cone-unique L L′ i = T.up-to-iso-unique (Cones F) (terminal L) (terminal L′) i
-- -- -- XXX probably not true -- what is? only the above?
-- -- -- .up-to-iso-unique : ∀ L L′ → (i : vertex L ≅ vertex L′) → up-to-iso L L′ ≡ⁱ i
-- -- -- up-to-iso-unique L L′ i = ≜ⁱ⇒≡ⁱ {!up-to-iso-unique-cone L L′ !}
-- -- .up-to-iso-cone-invˡ : ∀ {L κ} {i : proj-cone L ⇿ κ} → up-to-iso-cone L (transport-by-iso-cone L i) ≜ⁱ i
-- -- up-to-iso-cone-invˡ {L} {i = i} = up-to-iso-cone-unique L (transport-by-iso-cone L i) i
-- -- .up-to-iso-invˡ : ∀ {L X} {i : vertex L ≅ X} → up-to-iso L (transport-by-iso L i) ≡ⁱ i
-- -- up-to-iso-invˡ {L₁} {i = i} = ≜ⁱ⇒≡ⁱ (up-to-iso-cone-invˡ {L₁} {i = proj₂ (cone-resp-iso (proj-cone L₁) i)})
-- -- up-to-iso-cone-invʳ : ∀ {L L′} → proj-cone (transport-by-iso-cone L (up-to-iso-cone L L′)) ≜ proj-cone L′
-- -- up-to-iso-cone-invʳ {L} {L′} = ≜-refl
-- -- up-to-iso-invʳ : ∀ {L L′} → vertex (transport-by-iso L (up-to-iso L L′)) ≣ vertex L′
-- -- up-to-iso-invʳ {t} {t′} = ≣-refl
| {
"alphanum_fraction": 0.5468795356,
"avg_line_length": 27.3412698413,
"ext": "agda",
"hexsha": "1610b81697c951bee055dc1d83de3be548d10583",
"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/Construction/Cones.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/Construction/Cones.agda",
"max_line_length": 113,
"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/Construction/Cones.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1456,
"size": 3445
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Pointed
module lib.types.Lift where
⊙Lift : ∀ {i j} → Ptd i → Ptd (lmax i j)
⊙Lift {j = j} (A , a) = ⊙[ Lift {j = j} A , lift a ]
⊙lift : ∀ {i j} {X : Ptd i} → fst (X ⊙→ ⊙Lift {j = j} X)
⊙lift = (lift , idp)
⊙lower : ∀ {i j} {X : Ptd i} → fst (⊙Lift {j = j} X ⊙→ X)
⊙lower = (lower , idp)
lift-equiv : ∀ {i j} {A : Type i} → A ≃ Lift {j = j} A
lift-equiv = equiv lift lower (λ _ → idp) (λ _ → idp)
-- [lower-equiv] is in Equivalences.agda
Lift-level : ∀ {i j} {A : Type i} {n : ℕ₋₂} →
has-level n A → has-level n (Lift {j = j} A)
Lift-level = equiv-preserves-level lift-equiv
⊙lift-equiv : ∀ {i j} {X : Ptd i} → X ⊙≃ ⊙Lift {j = j} X
⊙lift-equiv = (⊙lift , snd lift-equiv)
⊙lower-equiv : ∀ {i j} {X : Ptd i} → ⊙Lift {j = j} X ⊙≃ X
⊙lower-equiv = (⊙lower , snd lower-equiv)
| {
"alphanum_fraction": 0.5396270396,
"avg_line_length": 27.6774193548,
"ext": "agda",
"hexsha": "c7ef9b17e3ca0473017a0052aa5a61edf415c1ab",
"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": "core/lib/types/Lift.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": "core/lib/types/Lift.agda",
"max_line_length": 57,
"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": "core/lib/types/Lift.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 390,
"size": 858
} |
module Data.Num.Binary where
-- open import Data.Product using (_×_; Σ; _,_)
open import Data.List
open import Data.Unit
open import Data.Empty
-- open import Data.Nat renaming (_+_ to _⊹_)
--
-- data Bin : Set where
-- [] : Bin
-- 0- : Bin → Bin
-- 1- : Bin → Bin
--
-- carry : Bin → Bin
-- carry [] = 1- []
-- carry (0- xs) = 1- xs
-- carry (1- xs) = 0- (carry xs)
--
-- _+_ : Bin → Bin → Bin
-- [] + ys = ys
-- xs + [] = xs
-- 0- xs + 0- ys = 0- (xs + ys)
-- 0- xs + 1- ys = 1- (xs + ys)
-- 1- xs + 0- ys = 1- (xs + ys)
-- 1- xs + 1- ys = 0- (carry (xs + ys))
--
-- data Desc : Set₁ where
-- arg : (A : Set) -- a bag of tags to choose constructors with
-- → (A → Desc) -- given a tag, return the description of the constructor it corresponds to
-- → Desc
-- rec : Desc → Desc -- recursive subnode
-- ret : Desc -- stop
--
-- -- the "decoder", "interpreter"
-- -- ⟦_⟧ : Desc → Set → Set
-- -- ⟦ arg A D ⟧ R = Σ A (λ a → ⟦ D a ⟧ R)
-- -- ⟦ rec D ⟧ R = R × ⟦ D ⟧ R
-- -- ⟦ ret ⟧ R = ⊤
-- data BinF : Set where
-- arg : (ℕ → BinF) → BinF
-- rec : BinF → BinF
-- ret : BinF
--
-- ⟦_⟧ : BinF → Set → Set
-- ⟦_⟧ (arg F) X = Σ ℕ (λ n → ⟦ F n ⟧ X)
-- ⟦_⟧ (rec F) X = X × ⟦ F ⟧ X
-- ⟦_⟧ ret X = ⊤
--
-- data μ (F : BinF) : Set where
-- ⟨_⟩ : ⟦ F ⟧ (μ F) → μ F
--
-- Bin : Set
-- Bin = μ (arg {! λ !})
--
-- data Digit : Set where
-- [0] : Digit
-- [1] : Digit
--
-- Binary : Set
-- Binary = List Digit
--
-- _⊕_ : Digit → Digit → Digit
-- [0] ⊕ [0] = [0]
-- [0] ⊕ [1] = [1]
-- [1] ⊕ [0] = [1]
-- [1] ⊕ [1] = [0]
--
-- _⊚_ : Digit → Digit → Digit
-- [1] ⊚ [1] = [1]
-- _ ⊚ _ = [0]
--
-- carry : Digit → Binary → Binary
-- carry [0] ys = ys
-- carry [1] [] = [1] ∷ []
-- carry [1] ([0] ∷ ys) = [1] ∷ ys
-- carry [1] ([1] ∷ ys) = [0] ∷ carry [1] ys
--
-- _+_ : Binary → Binary → Binary
-- [] + ys = ys
-- xs + [] = xs
-- (x ∷ xs) + (y ∷ ys) = x ⊕ y ∷ carry (x ⊚ y) (xs + ys)
--
-- _≈_ : Binary → Binary → Set
-- [] ≈ [] = ⊤
-- [] ≈ (y ∷ ys) = ⊥
-- (x ∷ xs) ≈ [] = ⊥
-- ([0] ∷ xs) ≈ ([0] ∷ ys) = xs ≈ ys
-- ([0] ∷ xs) ≈ ([1] ∷ ys) = ⊥
-- ([1] ∷ xs) ≈ ([0] ∷ ys) = ⊥
-- ([1] ∷ xs) ≈ ([1] ∷ ys) = xs ≈ ys
data Bin : Set where
∙ : Bin
[0]_ : Bin → Bin
[1]_ : Bin → Bin
two : Bin
two = [1] [0] ∙
1+ : Bin → Bin
1+ ∙ = [1] ∙
1+ ([0] x) = [1] x
1+ ([1] x) = [0] 1+ x
_+_ : Bin → Bin → Bin
∙ + ys = ys
xs + ∙ = xs
([0] xs) + ([0] ys) = [0] (xs + ys)
([0] xs) + ([1] ys) = [1] (xs + ys)
([1] xs) + ([0] ys) = [1] (xs + ys)
([1] xs) + ([1] ys) = [0] (1+ (xs + ys))
| {
"alphanum_fraction": 0.3989197531,
"avg_line_length": 22.3448275862,
"ext": "agda",
"hexsha": "825103b23d51003f8512f47d6ee4a8faefa33221",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Sandbox/Binary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Sandbox/Binary.agda",
"max_line_length": 110,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Sandbox/Binary.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": 1171,
"size": 2592
} |
{-# OPTIONS --without-K --safe #-}
module Fragment.Examples.CSemigroup.Arith.Reasoning where
open import Fragment.Examples.CSemigroup.Arith.Base
+-direct : ∀ {m n} → (m + 2) + (3 + n) ≡ m + (n + 5)
+-direct {m} {n} = begin
(m + 2) + (3 + n)
≡⟨ fragment CSemigroupFrex +-csemigroup ⟩
m + (n + 5)
∎
open import Data.Nat.Properties using (*-distribˡ-+)
+-inner : ∀ {m n k} → k * (m + 2) + k * (3 + n) ≡ (m + n + 5) * k
+-inner {m} {n} {k} = begin
k * (m + 2) + k * (3 + n)
≡⟨ sym (*-distribˡ-+ k (m + 2) (3 + n)) ⟩
k * ((m + 2) + (3 + n))
≡⟨ cong (k *_) (fragment CSemigroupFrex +-csemigroup) ⟩
k * (m + n + 5)
≡⟨ fragment CSemigroupFrex *-csemigroup ⟩
(m + n + 5) * k
∎
| {
"alphanum_fraction": 0.5049365303,
"avg_line_length": 27.2692307692,
"ext": "agda",
"hexsha": "0fb776acdd4c099560afd695488473a167dc11a7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Examples/CSemigroup/Arith/Reasoning.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Examples/CSemigroup/Arith/Reasoning.agda",
"max_line_length": 65,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Examples/CSemigroup/Arith/Reasoning.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 321,
"size": 709
} |
import Lvl
module Structure.Semicategory {ℓₒ ℓₘ ℓₑ : Lvl.Level} where
open import Functional using (swap)
open import Logic
import Structure.Categorical.Names as Names
open import Structure.Categorical.Properties
open import Structure.Operator
import Structure.Relator.Names as Names
open import Structure.Relator.Properties
open import Structure.Setoid
open import Type
-- Obj is the collection of objects.
-- _⟶_ is the collection of morphisms.
module _
{Obj : Type{ℓₒ}}
(_⟶_ : Obj → Obj → Type{ℓₘ})
⦃ morphism-equiv : ∀{x y} → Equiv{ℓₑ}(x ⟶ y) ⦄
where
-- A semicategory is a structure on a relation called a morphism.
--
-- It is similar to a category (a generalisation of it), but without the identity morphism/reflexivity.
-- See `Structure.Category`.
--
-- It can also be seen as a generalized algebraic structure, or more specifically a generalization of semigroups (structure with an associative binary operator).
-- The similarity between a semicategory and a category is like the similarity between a semigroup and a monoid.
--
-- An alternative interpretation of the definition:
-- A type (Obj) and a binary relation (Morphism) on this type is a semicategory when:
-- • The relator is transitive.
-- • Chains of the transitivity proofs can be applied in any order and the resulting proof will be the same.
record Semicategory : Stmt{ℓₒ Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
field
_∘_ : Names.SwappedTransitivity(_⟶_)
field
⦃ binaryOperator ⦄ : ∀{x y z} → BinaryOperator(_∘_ {x}{y}{z})
⦃ associativity ⦄ : Morphism.Associativity(\{x} → _∘_ {x})
-- This can be interpreted as proof of transitivity when `Morphism` is interpreted as a binary relation.
morphism-transitivity : Transitivity(_⟶_)
morphism-transitivity = intro(swap(_∘_))
module ArrowNotation = Names.ArrowNotation(_⟶_)
record SemicategoryObject : Stmt{Lvl.𝐒(ℓₒ Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ)} where
constructor intro
field
{Object} : Type{ℓₒ}
{Morphism} : Object → Object → Type{ℓₘ}
⦃ morphism-equiv ⦄ : ∀{x y} → Equiv{ℓₑ}(Morphism x y)
semicategory : Semicategory(Morphism)
open Semicategory(semicategory) public
instance
semicategory-instance = semicategory
| {
"alphanum_fraction": 0.7069499779,
"avg_line_length": 37.65,
"ext": "agda",
"hexsha": "5b5a3cd6625a801503b73b2233e8b15b7b940d53",
"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/Semicategory.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/Semicategory.agda",
"max_line_length": 163,
"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/Semicategory.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": 678,
"size": 2259
} |
module New.LangOps where
open import New.Lang
open import New.Changes
open import New.LangChanges
oplusτo : ∀ {Γ} τ → Term Γ (τ ⇒ Δt τ ⇒ τ)
ominusτo : ∀ {Γ} τ → Term Γ (τ ⇒ τ ⇒ Δt τ)
onilτo : ∀ {Γ} τ → Term Γ (τ ⇒ Δt τ)
onilτo τ = abs (app₂ (ominusτo τ) (var this) (var this))
-- Do NOT try to read this, such terms are write-only. But the behavior is
-- specified to be oplusτ-equiv and ominusτ-equiv.
oplusτo (σ ⇒ τ) = abs (abs (abs
(app₂ (oplusτo τ)
(app (var (that (that this))) (var this))
(app₂ (var (that this)) (var this) (app (onilτo σ) (var this))))))
oplusτo int = const plus
oplusτo (pair σ τ) = abs (abs (app₂ (const cons)
(app₂ (oplusτo σ) (app (const fst) (var (that this))) (app (const fst) (var this)))
(app₂ (oplusτo τ) (app (const snd) (var (that this))) (app (const snd) (var this)))))
oplusτo (sum σ τ) = abs (abs (app₃ (const match) (var (that this))
(abs (app₃ (const match) (var (that this))
(abs (app₃ (const match) (var this)
(abs (app (const linj) (app₂ (oplusτo σ) (var (that (that this))) (var this))))
(abs (app (const linj) (var (that (that this)))))))
(abs (var this))))
(abs (app₃ (const match) (var (that this))
(abs (app₃ (const match) (var this)
(abs (app (const rinj) (var (that (that this)))))
(abs (app (const rinj) (app₂ (oplusτo τ) (var (that (that this))) (var this))))))
(abs (var this))))))
ominusτo (σ ⇒ τ) = abs (abs (abs (abs (app₂ (ominusτo τ)
(app (var (that (that (that this)))) (app₂ (oplusτo σ) (var (that this)) (var this)))
(app (var (that (that this))) (var (that this)))))))
ominusτo int = const minus
ominusτo (pair σ τ) = abs (abs (app₂ (const cons)
(app₂ (ominusτo σ) (app (const fst) (var (that this))) (app (const fst) (var this)))
(app₂ (ominusτo τ) (app (const snd) (var (that this))) (app (const snd) (var this)))))
ominusτo (sum σ τ) = abs (abs (app₃ (const match) (var (that this))
(abs (app₃ (const match) (var (that this))
(abs (app (const linj) (app (const linj) (app₂ (ominusτo σ) (var (that this)) (var this)))))
(abs (app (const rinj) (var (that (that (that this))))))))
(abs (app₃ (const match) (var (that this))
(abs (app (const rinj) (var (that (that (that this))))))
(abs (app (const linj) (app (const rinj) (app₂ (ominusτo τ) (var (that this)) (var this)))))))))
oplusτ-equiv : ∀ Γ (ρ : ⟦ Γ ⟧Context) τ a da → ⟦ oplusτo τ ⟧Term ρ a da ≡ a ⊕ da
ominusτ-equiv : ∀ Γ (ρ : ⟦ Γ ⟧Context) τ b a → ⟦ ominusτo τ ⟧Term ρ b a ≡ b ⊝ a
oplusτ-equiv-ext : ∀ τ Γ → ⟦ oplusτo {Γ} τ ⟧Term ≡ λ ρ → _⊕_
oplusτ-equiv-ext τ _ = ext³ (λ ρ a da → oplusτ-equiv _ ρ τ a da)
ominusτ-equiv-ext : ∀ τ Γ → ⟦ ominusτo {Γ} τ ⟧Term ≡ λ ρ → _⊝_
ominusτ-equiv-ext τ _ = ext³ (λ ρ a da → ominusτ-equiv _ ρ τ a da)
oplusτ-equiv Γ ρ (σ ⇒ τ) f df = ext (λ a → lemma a)
where
module _ (a : ⟦ σ ⟧Type) where
ρ′ = a • df • f • ρ
ρ′′ = a • ρ′
lemma : ⟦ oplusτo τ ⟧Term ρ′ (f a)
(df a (⟦ ominusτo σ ⟧Term ρ′′ a a))
≡ f a ⊕ df a (nil a)
lemma
rewrite ominusτ-equiv _ ρ′′ σ a a
| oplusτ-equiv _ ρ′ τ (f a) (df a (nil a))
= refl
oplusτ-equiv Γ ρ int a da = refl
oplusτ-equiv Γ ρ (pair σ τ) (a , b) (da , db)
rewrite oplusτ-equiv _ ((da , db) • (a , b) • ρ) σ a da
| oplusτ-equiv _ ((da , db) • (a , b) • ρ) τ b db
= refl
oplusτ-equiv Γ ρ (sum σ τ) (inj₁ x) (inj₁ (inj₁ dx))
rewrite oplusτ-equiv-ext σ (Δt σ • sum (Δt σ) (Δt τ) • σ • Δt (sum σ τ) • sum σ τ • Γ)
= refl
oplusτ-equiv Γ ρ (sum σ τ) (inj₁ x) (inj₁ (inj₂ dy)) = refl
oplusτ-equiv Γ ρ (sum σ τ) (inj₁ x) (inj₂ y) = refl
oplusτ-equiv Γ ρ (sum σ τ) (inj₂ y) (inj₁ (inj₁ dx)) = refl
oplusτ-equiv Γ ρ (sum σ τ) (inj₂ y) (inj₁ (inj₂ dy))
rewrite oplusτ-equiv-ext τ (Δt τ • sum (Δt σ) (Δt τ) • τ • Δt (sum σ τ) • sum σ τ • Γ)
= refl
oplusτ-equiv Γ ρ (sum σ τ) (inj₂ y) (inj₂ y₁) = refl
ominusτ-equiv Γ ρ (σ ⇒ τ) g f = ext (λ a → ext (lemma a))
where
module _ (a : ⟦ σ ⟧Type) (da : Chτ σ) where
ρ′ = da • a • f • g • ρ
lemma : ⟦ ominusτo τ ⟧Term (da • a • f • g • ρ)
(g (⟦ oplusτo σ ⟧Term (da • a • f • g • ρ) a da)) (f a)
≡ g (a ⊕ da) ⊝ f a
lemma
rewrite oplusτ-equiv _ ρ′ σ a da
| ominusτ-equiv _ ρ′ τ (g (a ⊕ da)) (f a) = refl
ominusτ-equiv Γ ρ int b a = refl
ominusτ-equiv Γ ρ (pair σ τ) (a2 , b2) (a1 , b1)
rewrite ominusτ-equiv _ ((a1 , b1) • (a2 , b2) • ρ) σ a2 a1
| ominusτ-equiv _ ((a1 , b1) • (a2 , b2) • ρ) τ b2 b1
= refl
ominusτ-equiv Γ ρ (sum σ τ) (inj₁ x) (inj₁ x₁)
rewrite ominusτ-equiv-ext σ (σ • σ • sum σ τ • sum σ τ • Γ)
= refl
ominusτ-equiv Γ ρ (sum σ τ) (inj₁ x) (inj₂ y) = refl
ominusτ-equiv Γ ρ (sum σ τ) (inj₂ y) (inj₁ x) = refl
ominusτ-equiv Γ ρ (sum σ τ) (inj₂ y) (inj₂ y₁)
rewrite ominusτ-equiv-ext τ (τ • τ • sum σ τ • sum σ τ • Γ)
= refl
| {
"alphanum_fraction": 0.5665209244,
"avg_line_length": 44.0642201835,
"ext": "agda",
"hexsha": "498270d06fdf52d578b3c0ed5813b37b9cece4bb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "New/LangOps.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "New/LangOps.agda",
"max_line_length": 100,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "New/LangOps.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 2056,
"size": 4803
} |
{-# OPTIONS --without-K #-}
module FunExt where
open import HIT.Interval
open import PathOperations
open import PathStructure.Id.Tr
open import Types
funext : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x} →
(∀ x → f x ≡ g x) → f ≡ g
funext {A = A} {B = B} {f = f} {g = g} p = ap h seg
where
h : I → (x : A) → B x
h i x = I-rec (f x) (g x) (p x) i
| {
"alphanum_fraction": 0.528150134,
"avg_line_length": 24.8666666667,
"ext": "agda",
"hexsha": "239dc5bbf3baa5b63ce97d2fd93605f3d0e67e4e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/FunExt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/FunExt.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/FunExt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 153,
"size": 373
} |
{-# OPTIONS --without-K --exact-split #-}
module 09-fundamental-theorem where
import 08-contractible-types
open 08-contractible-types public
-- Section 8.1 Families of equivalences
{- Any family of maps induces a map on the total spaces. -}
tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x → C x) → ( Σ A B → Σ A C)
tot f t = pair (pr1 t) (f (pr1 t) (pr2 t))
{- We show that for any family of maps, the fiber of the induced map on total
spaces are equivalent to the fibers of the maps in the family. -}
fib-ftr-fib-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
fib (tot f) t → fib (f (pr1 t)) (pr2 t)
fib-ftr-fib-tot f .(pair x (f x y)) (pair (pair x y) refl) = pair y refl
fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
fib (f (pr1 t)) (pr2 t) → fib (tot f) t
fib-tot-fib-ftr F (pair a .(F a y)) (pair y refl) = pair (pair a y) refl
issec-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
((fib-ftr-fib-tot f t) ∘ (fib-tot-fib-ftr f t)) ~ id
issec-fib-tot-fib-ftr f (pair x .(f x y)) (pair y refl) = refl
isretr-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
((fib-tot-fib-ftr f t) ∘ (fib-ftr-fib-tot f t)) ~ id
isretr-fib-tot-fib-ftr f .(pair x (f x y)) (pair (pair x y) refl) = refl
abstract
is-equiv-fib-ftr-fib-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
is-equiv (fib-ftr-fib-tot f t)
is-equiv-fib-ftr-fib-tot f t =
is-equiv-has-inverse
( fib-tot-fib-ftr f t)
( issec-fib-tot-fib-ftr f t)
( isretr-fib-tot-fib-ftr f t)
abstract
is-equiv-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
is-equiv (fib-tot-fib-ftr f t)
is-equiv-fib-tot-fib-ftr f t =
is-equiv-has-inverse
( fib-ftr-fib-tot f t)
( isretr-fib-tot-fib-ftr f t)
( issec-fib-tot-fib-ftr f t)
{- Now that we have shown that the fibers of the induced map on total spaces
are equivalent to the fibers of the maps in the family, it follows that
the induced map on total spaces is an equivalence if and only if each map
in the family is an equivalence. -}
is-fiberwise-equiv :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x → C x) → UU (i ⊔ (j ⊔ k))
is-fiberwise-equiv f = (x : _) → is-equiv (f x)
abstract
is-equiv-tot-is-fiberwise-equiv :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
{f : (x : A) → B x → C x} → is-fiberwise-equiv f →
is-equiv (tot f )
is-equiv-tot-is-fiberwise-equiv {f = f} H =
is-equiv-is-contr-map
( λ t → is-contr-is-equiv _
( fib-ftr-fib-tot f t)
( is-equiv-fib-ftr-fib-tot f t)
( is-contr-map-is-equiv (H _) (pr2 t)))
abstract
is-fiberwise-equiv-is-equiv-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → is-equiv (tot f) →
is-fiberwise-equiv f
is-fiberwise-equiv-is-equiv-tot {A = A} {B} {C} f is-equiv-tot-f x =
is-equiv-is-contr-map
( λ z → is-contr-is-equiv'
( fib (tot f) (pair x z))
( fib-ftr-fib-tot f (pair x z))
( is-equiv-fib-ftr-fib-tot f (pair x z))
( is-contr-map-is-equiv is-equiv-tot-f (pair x z)))
equiv-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x ≃ C x) → (Σ A B) ≃ (Σ A C)
equiv-tot e =
pair
( tot (λ x → map-equiv (e x)))
( is-equiv-tot-is-fiberwise-equiv (λ x → is-equiv-map-equiv (e x)))
{- In the second part of this section we show that any equivalence f on base
types also induces an equivalence on total spaces. -}
Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
Σ A (λ x → C (f x)) → Σ B C
Σ-map-base-map f C s = pair (f (pr1 s)) (pr2 s)
{- The proof is similar to the previous part: we show that the fibers of f
and Σ-kap-base-map f C are equivalent. -}
fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → fib f (pr1 t) → fib (Σ-map-base-map f C) t
fib-Σ-map-base-map-fib f C (pair .(f x) z) (pair x refl) =
pair (pair x z) refl
fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → fib (Σ-map-base-map f C) t → fib f (pr1 t)
fib-fib-Σ-map-base-map f C .(pair (f x) z) (pair (pair x z) refl) =
pair x refl
issec-fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) →
( (fib-Σ-map-base-map-fib f C t) ∘ (fib-fib-Σ-map-base-map f C t)) ~ id
issec-fib-fib-Σ-map-base-map f C .(pair (f x) z) (pair (pair x z) refl) =
refl
isretr-fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) →
( (fib-fib-Σ-map-base-map f C t) ∘ (fib-Σ-map-base-map-fib f C t)) ~ id
isretr-fib-fib-Σ-map-base-map f C (pair .(f x) z) (pair x refl) = refl
abstract
is-equiv-fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → is-equiv (fib-Σ-map-base-map-fib f C t)
is-equiv-fib-Σ-map-base-map-fib f C t =
is-equiv-has-inverse
( fib-fib-Σ-map-base-map f C t)
( issec-fib-fib-Σ-map-base-map f C t)
( isretr-fib-fib-Σ-map-base-map f C t)
abstract
is-contr-map-Σ-map-base-map :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) →
is-contr-map f → is-contr-map (Σ-map-base-map f C)
is-contr-map-Σ-map-base-map C f is-contr-f (pair y z) =
is-contr-is-equiv'
( fib f y)
( fib-Σ-map-base-map-fib f C (pair y z))
( is-equiv-fib-Σ-map-base-map-fib f C (pair y z))
( is-contr-f y)
abstract
is-equiv-Σ-map-base-map :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) →
is-equiv f → is-equiv (Σ-map-base-map f C)
is-equiv-Σ-map-base-map C f is-equiv-f =
is-equiv-is-contr-map
( is-contr-map-Σ-map-base-map C f (is-contr-map-is-equiv is-equiv-f))
{- Now we combine the two parts of this section. -}
toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
Σ A C → Σ B D
toto D f g t = pair (f (pr1 t)) (g (pr1 t) (pr2 t))
{- A special case of toto is the functoriality of the cartesian product. -}
{- We construct the functoriality of cartesian products. -}
functor-prod :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (A × B) → (C × D)
functor-prod f g (pair a b) = pair (f a) (g b)
functor-prod-pr1 :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (pr1 ∘ (functor-prod f g)) ~ (f ∘ pr1)
functor-prod-pr1 f g (pair a b) = refl
functor-prod-pr2 :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (pr2 ∘ (functor-prod f g)) ~ (g ∘ pr2)
functor-prod-pr2 f g (pair a b) = refl
{- For our convenience we show that the functorial action of cartesian products
preserves identity maps, compositions, homotopies, and equivalences. -}
functor-prod-id :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
(functor-prod (id {A = A}) (id {A = B})) ~ id
functor-prod-id (pair a b) = refl
functor-prod-comp :
{l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{E : UU l5} {F : UU l6} (f : A → C) (g : B → D) (h : C → E) (k : D → F) →
functor-prod (h ∘ f) (k ∘ g) ~ ((functor-prod h k) ∘ (functor-prod f g))
functor-prod-comp f g h k (pair a b) = refl
functor-prod-htpy :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{f f' : A → C} (H : f ~ f') {g g' : B → D} (K : g ~ g') →
functor-prod f g ~ functor-prod f' g'
functor-prod-htpy {f = f} {f'} H {g} {g'} K (pair a b) =
eq-pair-triv (pair (H a) (K b))
abstract
is-equiv-functor-prod :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) →
is-equiv f → is-equiv g → is-equiv (functor-prod f g)
is-equiv-functor-prod f g
( pair (pair sf issec-sf) (pair rf isretr-rf))
( pair (pair sg issec-sg) (pair rg isretr-rg)) =
pair
( pair
( functor-prod sf sg)
( ( htpy-inv (functor-prod-comp sf sg f g)) ∙h
( (functor-prod-htpy issec-sf issec-sg) ∙h functor-prod-id)))
( pair
( functor-prod rf rg)
( ( htpy-inv (functor-prod-comp f g rf rg)) ∙h
( (functor-prod-htpy isretr-rf isretr-rg) ∙h functor-prod-id)))
{- triangle -}
triangle-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
(toto D f g) ~ ((Σ-map-base-map f D) ∘ (tot g))
triangle-toto D f g t = refl
abstract
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
is-equiv f → (is-fiberwise-equiv g) →
is-equiv (toto D f g)
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map
D f g is-equiv-f is-fiberwise-equiv-g =
is-equiv-comp
( toto D f g)
( Σ-map-base-map f D)
( tot g)
( triangle-toto D f g)
( is-equiv-tot-is-fiberwise-equiv is-fiberwise-equiv-g)
( is-equiv-Σ-map-base-map D f is-equiv-f)
equiv-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (e : A ≃ B) (g : (x : A) → C x ≃ D (map-equiv e x)) →
Σ A C ≃ Σ B D
equiv-toto D e g =
pair
( toto D (map-equiv e) (λ x → map-equiv (g x)))
( is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map D
( map-equiv e)
( λ x → map-equiv (g x))
( is-equiv-map-equiv e)
( λ x → is-equiv-map-equiv (g x)))
abstract
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
is-equiv f → is-equiv (toto D f g) → is-fiberwise-equiv g
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map
D f g is-equiv-f is-equiv-toto-fg =
is-fiberwise-equiv-is-equiv-tot g
( is-equiv-right-factor
( toto D f g)
( Σ-map-base-map f D)
( tot g)
( triangle-toto D f g)
( is-equiv-Σ-map-base-map D f is-equiv-f)
( is-equiv-toto-fg))
-- Section 8.2 The fundamental theorem
-- The general form of the fundamental theorem of identity types
abstract
fundamental-theorem-id :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
is-contr (Σ A B) → (f : (x : A) → Id a x → B x) → is-fiberwise-equiv f
fundamental-theorem-id {A = A} a b is-contr-AB f =
is-fiberwise-equiv-is-equiv-tot f
( is-equiv-is-contr (tot f) (is-contr-total-path a) is-contr-AB)
abstract
fundamental-theorem-id' :
{i j : Level} {A : UU i} {B : A → UU j}
(a : A) (b : B a) (f : (x : A) → Id a x → B x) →
is-fiberwise-equiv f → is-contr (Σ A B)
fundamental-theorem-id' {A = A} {B = B} a b f is-fiberwise-equiv-f =
is-contr-is-equiv'
( Σ A (Id a))
( tot f)
( is-equiv-tot-is-fiberwise-equiv is-fiberwise-equiv-f)
( is-contr-total-path a)
-- The canonical form of the fundamental theorem of identity types
abstract
fundamental-theorem-id-J :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
is-contr (Σ A B) → is-fiberwise-equiv (ind-Id a (λ x p → B x) b)
fundamental-theorem-id-J {i} {j} {A} {B} a b is-contr-AB =
fundamental-theorem-id a b is-contr-AB (ind-Id a (λ x p → B x) b)
-- The converse of the fundamental theorem of identity types
abstract
fundamental-theorem-id-J' :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-fiberwise-equiv (ind-Id a (λ x p → B x) b)) → is-contr (Σ A B)
fundamental-theorem-id-J' {i} {j} {A} {B} a b H =
is-contr-is-equiv'
( Σ A (Id a))
( tot (ind-Id a (λ x p → B x) b))
( is-equiv-tot-is-fiberwise-equiv H)
( is-contr-total-path a)
-- As an application we show that equivalences are embeddings.
is-emb :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j)
is-emb f = (x y : _) → is-equiv (ap f {x} {y})
_↪_ :
{i j : Level} → UU i → UU j → UU (i ⊔ j)
A ↪ B = Σ (A → B) is-emb
map-emb :
{i j : Level} {A : UU i} {B : UU j} → A ↪ B → A → B
map-emb f = pr1 f
is-emb-map-emb :
{ i j : Level} {A : UU i} {B : UU j} (f : A ↪ B) → is-emb (map-emb f)
is-emb-map-emb f = pr2 f
abstract
is-emb-is-equiv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → is-equiv f → is-emb f
is-emb-is-equiv {i} {j} {A} {B} f is-equiv-f x =
fundamental-theorem-id x refl
( is-contr-equiv
( fib f (f x))
( equiv-tot (λ y → equiv-inv (f x) (f y)))
( is-contr-map-is-equiv is-equiv-f (f x)))
( λ y p → ap f p)
equiv-ap :
{i j : Level} {A : UU i} {B : UU j} (e : A ≃ B) (x y : A) →
(Id x y) ≃ (Id (map-equiv e x) (map-equiv e y))
equiv-ap e x y =
pair
( ap (map-equiv e) {x} {y})
( is-emb-is-equiv (map-equiv e) (is-equiv-map-equiv e) x y)
-- Section 7.3 Identity systems
IND-identity-system :
{i j : Level} (k : Level) {A : UU i} (B : A → UU j) (a : A) (b : B a) → UU _
IND-identity-system k {A} B a b =
( P : (x : A) (y : B x) → UU k) →
sec (λ (h : (x : A) (y : B x) → P x y) → h a b)
fam-Σ :
{i j k : Level} {A : UU i} {B : A → UU j} (C : (x : A) → B x → UU k) →
Σ A B → UU k
fam-Σ C (pair x y) = C x y
abstract
ind-identity-system :
{i j k : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) (P : (x : A) → B x → UU k) →
P a b → (x : A) (y : B x) → P x y
ind-identity-system a b is-contr-AB P p x y =
tr
( fam-Σ P)
( is-prop-is-contr' is-contr-AB (pair a b) (pair x y))
( p)
comp-identity-system :
{i j k : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) →
(P : (x : A) → B x → UU k) (p : P a b) →
Id (ind-identity-system a b is-contr-AB P p a b) p
comp-identity-system a b is-contr-AB P p =
ap
( λ t → tr (fam-Σ P) t p)
( is-prop-is-contr'
( is-prop-is-contr is-contr-AB (pair a b) (pair a b))
( is-prop-is-contr' is-contr-AB (pair a b) (pair a b))
( refl))
Ind-identity-system :
{i j : Level} (k : Level) {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) →
IND-identity-system k B a b
Ind-identity-system k a b is-contr-AB P =
pair
( ind-identity-system a b is-contr-AB P)
( comp-identity-system a b is-contr-AB P)
contraction-total-space-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b →
(t : Σ A B) → Id (pair a b) t
contraction-total-space-IND-identity-system a b ind (pair x y) =
pr1 (ind (λ x' y' → Id (pair a b) (pair x' y'))) refl x y
abstract
is-contr-total-space-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b → is-contr (Σ A B)
is-contr-total-space-IND-identity-system a b ind =
pair
( pair a b)
( contraction-total-space-IND-identity-system a b ind)
abstract
fundamental-theorem-id-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b →
(f : (x : A) → Id a x → B x) → (x : A) → is-equiv (f x)
fundamental-theorem-id-IND-identity-system a b ind f =
fundamental-theorem-id a b (is-contr-total-space-IND-identity-system a b ind) f
-- Section 7.4 Disjointness of coproducts
-- Raising universe levels
postulate Raise : {l1 : Level} (l2 : Level) → (A : UU l1) → Σ (UU (l1 ⊔ l2)) (λ X → A ≃ X)
abstract
raise :
{l1 : Level} (l2 : Level) → UU l1 → UU (l1 ⊔ l2)
raise l2 A = pr1 (Raise l2 A)
equiv-raise :
{l1 : Level} (l2 : Level) (A : UU l1) → A ≃ raise l2 A
equiv-raise l2 A = pr2 (Raise l2 A)
map-raise :
{l1 : Level} (l2 : Level) (A : UU l1) → A → raise l2 A
map-raise l2 A = map-equiv (equiv-raise l2 A)
is-equiv-map-raise :
{l1 : Level} (l2 : Level) (A : UU l1) →
is-equiv (map-raise l2 A)
is-equiv-map-raise l2 A = is-equiv-map-equiv (equiv-raise l2 A)
-- Lemmas about coproducts
left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2)
(C : coprod A B → UU l3) → Σ (coprod A B) C →
coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y)))
left-distributive-coprod-Σ-map A B C (pair (inl x) z) = inl (pair x z)
left-distributive-coprod-Σ-map A B C (pair (inr y) z) = inr (pair y z)
inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2)
(C : coprod A B → UU l3) →
coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y))) → Σ (coprod A B) C
inv-left-distributive-coprod-Σ-map A B C (inl (pair x z)) = pair (inl x) z
inv-left-distributive-coprod-Σ-map A B C (inr (pair y z)) = pair (inr y) z
issec-inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
( (left-distributive-coprod-Σ-map A B C) ∘
(inv-left-distributive-coprod-Σ-map A B C)) ~ id
issec-inv-left-distributive-coprod-Σ-map A B C (inl (pair x z)) = refl
issec-inv-left-distributive-coprod-Σ-map A B C (inr (pair y z)) = refl
isretr-inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
( (inv-left-distributive-coprod-Σ-map A B C) ∘
(left-distributive-coprod-Σ-map A B C)) ~ id
isretr-inv-left-distributive-coprod-Σ-map A B C (pair (inl x) z) = refl
isretr-inv-left-distributive-coprod-Σ-map A B C (pair (inr y) z) = refl
abstract
is-equiv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
is-equiv (left-distributive-coprod-Σ-map A B C)
is-equiv-left-distributive-coprod-Σ-map A B C =
is-equiv-has-inverse
( inv-left-distributive-coprod-Σ-map A B C)
( issec-inv-left-distributive-coprod-Σ-map A B C)
( isretr-inv-left-distributive-coprod-Σ-map A B C)
equiv-left-distributive-coprod-Σ :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
Σ (coprod A B) C ≃ coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y)))
equiv-left-distributive-coprod-Σ A B C =
pair ( left-distributive-coprod-Σ-map A B C)
( is-equiv-left-distributive-coprod-Σ-map A B C)
abstract
is-equiv-map-to-empty :
{l : Level} {A : UU l} (f : A → empty) → is-equiv f
is-equiv-map-to-empty f =
is-equiv-has-inverse
ind-empty
ind-empty
( λ x → ind-empty {P = λ t → Id (ind-empty (f x)) x} (f x))
map-Σ-empty-fam :
{l : Level} (A : UU l) → Σ A (λ x → empty) → empty
map-Σ-empty-fam A (pair x ())
abstract
is-equiv-map-Σ-empty-fam :
{l : Level} (A : UU l) → is-equiv (map-Σ-empty-fam A)
is-equiv-map-Σ-empty-fam A = is-equiv-map-to-empty (map-Σ-empty-fam A)
equiv-Σ-empty-fam :
{l : Level} (A : UU l) → Σ A (λ x → empty) ≃ empty
equiv-Σ-empty-fam A =
pair (map-Σ-empty-fam A) (is-equiv-map-Σ-empty-fam A)
-- The identity types of coproducts
Eq-coprod :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
coprod A B → coprod A B → UU (l1 ⊔ l2)
Eq-coprod {l1} {l2} A B (inl x) (inl y) = raise (l1 ⊔ l2) (Id x y)
Eq-coprod {l1} {l2} A B (inl x) (inr y) = raise (l1 ⊔ l2) empty
Eq-coprod {l1} {l2} A B (inr x) (inl y) = raise (l1 ⊔ l2) empty
Eq-coprod {l1} {l2} A B (inr x) (inr y) = raise (l1 ⊔ l2) (Id x y)
reflexive-Eq-coprod :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
(t : coprod A B) → Eq-coprod A B t t
reflexive-Eq-coprod {l1} {l2} A B (inl x) = map-raise (l1 ⊔ l2) (Id x x) refl
reflexive-Eq-coprod {l1} {l2} A B (inr x) = map-raise (l1 ⊔ l2) (Id x x) refl
Eq-coprod-eq :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
(s t : coprod A B) → Id s t → Eq-coprod A B s t
Eq-coprod-eq A B s .s refl = reflexive-Eq-coprod A B s
abstract
is-contr-total-Eq-coprod-inl :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : A) →
is-contr (Σ (coprod A B) (Eq-coprod A B (inl x)))
is-contr-total-Eq-coprod-inl A B x =
is-contr-equiv
( coprod
( Σ A (λ y → Eq-coprod A B (inl x) (inl y)))
( Σ B (λ y → Eq-coprod A B (inl x) (inr y))))
( equiv-left-distributive-coprod-Σ A B (Eq-coprod A B (inl x)))
( is-contr-equiv'
( coprod
( Σ A (Id x))
( Σ B (λ y → empty)))
( equiv-functor-coprod
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( equiv-tot (λ y → equiv-raise _ empty)))
( is-contr-equiv
( coprod (Σ A (Id x)) empty)
( equiv-functor-coprod
( equiv-id (Σ A (Id x)))
( equiv-Σ-empty-fam B))
( is-contr-equiv'
( Σ A (Id x))
( right-unit-law-coprod (Σ A (Id x)))
( is-contr-total-path x))))
abstract
is-contr-total-Eq-coprod-inr :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : B) →
is-contr (Σ (coprod A B) (Eq-coprod A B (inr x)))
is-contr-total-Eq-coprod-inr A B x =
is-contr-equiv
( coprod
( Σ A (λ y → Eq-coprod A B (inr x) (inl y)))
( Σ B (λ y → Eq-coprod A B (inr x) (inr y))))
( equiv-left-distributive-coprod-Σ A B (Eq-coprod A B (inr x)))
( is-contr-equiv'
( coprod (Σ A (λ y → empty)) (Σ B (Id x)))
( equiv-functor-coprod
( equiv-tot (λ y → equiv-raise _ empty))
( equiv-tot (λ y → equiv-raise _ (Id x y))))
( is-contr-equiv
( coprod empty (Σ B (Id x)))
( equiv-functor-coprod
( equiv-Σ-empty-fam A)
( equiv-id (Σ B (Id x))))
( is-contr-equiv'
( Σ B (Id x))
( left-unit-law-coprod (Σ B (Id x)))
( is-contr-total-path x))))
abstract
is-equiv-Eq-coprod-eq-inl :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : A) →
is-fiberwise-equiv (Eq-coprod-eq A B (inl x))
is-equiv-Eq-coprod-eq-inl A B x =
fundamental-theorem-id
( inl x)
( reflexive-Eq-coprod A B (inl x))
( is-contr-total-Eq-coprod-inl A B x)
( Eq-coprod-eq A B (inl x))
abstract
is-equiv-Eq-coprod-eq-inr :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : B) →
is-fiberwise-equiv (Eq-coprod-eq A B (inr x))
is-equiv-Eq-coprod-eq-inr A B x =
fundamental-theorem-id
( inr x)
( reflexive-Eq-coprod A B (inr x))
( is-contr-total-Eq-coprod-inr A B x)
( Eq-coprod-eq A B (inr x))
abstract
is-equiv-Eq-coprod-eq :
{l1 l2 : Level} (A : UU l1) (B : UU l2)
(s : coprod A B) → is-fiberwise-equiv (Eq-coprod-eq A B s)
is-equiv-Eq-coprod-eq A B (inl x) = is-equiv-Eq-coprod-eq-inl A B x
is-equiv-Eq-coprod-eq A B (inr x) = is-equiv-Eq-coprod-eq-inr A B x
map-compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → Id (inl {B = B} x) (inl {B = B} x') → Id x x'
map-compute-eq-coprod-inl-inl x x' =
( inv-is-equiv (is-equiv-map-raise _ (Id x x'))) ∘
( Eq-coprod-eq _ _ (inl x) (inl x'))
abstract
is-equiv-map-compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → is-equiv (map-compute-eq-coprod-inl-inl {B = B} x x')
is-equiv-map-compute-eq-coprod-inl-inl x x' =
is-equiv-comp
( map-compute-eq-coprod-inl-inl x x')
( inv-is-equiv (is-equiv-map-raise _ (Id x x')))
( Eq-coprod-eq _ _ (inl x) (inl x'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inl x) (inl x'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ (Id x x')))
compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → (Id (inl {B = B} x) (inl x')) ≃ (Id x x')
compute-eq-coprod-inl-inl x x' =
pair
( map-compute-eq-coprod-inl-inl x x')
( is-equiv-map-compute-eq-coprod-inl-inl x x')
map-compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → Id (inl x) (inr y') → empty
map-compute-eq-coprod-inl-inr x y' =
( inv-is-equiv (is-equiv-map-raise _ empty)) ∘
( Eq-coprod-eq _ _ (inl x) (inr y'))
abstract
is-equiv-map-compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → is-equiv (map-compute-eq-coprod-inl-inr x y')
is-equiv-map-compute-eq-coprod-inl-inr x y' =
is-equiv-comp
( map-compute-eq-coprod-inl-inr x y')
( inv-is-equiv (is-equiv-map-raise _ empty))
( Eq-coprod-eq _ _ (inl x) (inr y'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inl x) (inr y'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ empty))
compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → (Id (inl x) (inr y')) ≃ empty
compute-eq-coprod-inl-inr x y' =
pair
( map-compute-eq-coprod-inl-inr x y')
( is-equiv-map-compute-eq-coprod-inl-inr x y')
map-compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → (Id (inr {A = A} y) (inl x')) → empty
map-compute-eq-coprod-inr-inl y x' =
( inv-is-equiv (is-equiv-map-raise _ empty)) ∘
( Eq-coprod-eq _ _ (inr y) (inl x'))
abstract
is-equiv-map-compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → is-equiv (map-compute-eq-coprod-inr-inl y x')
is-equiv-map-compute-eq-coprod-inr-inl y x' =
is-equiv-comp
( map-compute-eq-coprod-inr-inl y x')
( inv-is-equiv (is-equiv-map-raise _ empty))
( Eq-coprod-eq _ _ (inr y) (inl x'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inr y) (inl x'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ empty))
compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → (Id (inr y) (inl x')) ≃ empty
compute-eq-coprod-inr-inl y x' =
pair
( map-compute-eq-coprod-inr-inl y x')
( is-equiv-map-compute-eq-coprod-inr-inl y x')
map-compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → (Id (inr {A = A} y) (inr y')) → Id y y'
map-compute-eq-coprod-inr-inr y y' =
( inv-is-equiv (is-equiv-map-raise _ (Id y y'))) ∘
( Eq-coprod-eq _ _ (inr y) (inr y'))
abstract
is-equiv-map-compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → is-equiv (map-compute-eq-coprod-inr-inr {A = A} y y')
is-equiv-map-compute-eq-coprod-inr-inr y y' =
is-equiv-comp
( map-compute-eq-coprod-inr-inr y y')
( inv-is-equiv (is-equiv-map-raise _ (Id y y')))
( Eq-coprod-eq _ _ (inr y) (inr y'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inr y) (inr y'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ (Id y y')))
compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → (Id (inr {A = A} y) (inr y')) ≃ (Id y y')
compute-eq-coprod-inr-inr y y' =
pair
( map-compute-eq-coprod-inr-inr y y')
( is-equiv-map-compute-eq-coprod-inr-inr y y')
-- Exercises
-- Exercise 7.1
abstract
is-emb-empty :
{i : Level} (A : UU i) → is-emb (ind-empty {P = λ x → A})
is-emb-empty A = ind-empty
-- Exercise 7.2
path-adjointness-equiv :
{i j : Level} {A : UU i} {B : UU j} (e : A ≃ B) (x : A) (y : B) →
(Id (map-equiv e x) y) ≃ (Id x (inv-map-equiv e y))
path-adjointness-equiv e x y =
( inv-equiv (equiv-ap e x (inv-map-equiv e y))) ∘e
( equiv-concat'
( map-equiv e x)
( inv (issec-inv-is-equiv (is-equiv-map-equiv e) y)))
-- Exercise 7.3
abstract
is-equiv-top-is-equiv-left-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
is-equiv i → is-equiv f → is-equiv g → is-equiv h
is-equiv-top-is-equiv-left-square f g h i H Ei Ef Eg =
is-equiv-right-factor (i ∘ f) g h H Eg
( is-equiv-comp (i ∘ f) i f refl-htpy Ef Ei)
abstract
is-emb-htpy :
{i j : Level} {A : UU i} {B : UU j} (f g : A → B) → (f ~ g) →
is-emb g → is-emb f
is-emb-htpy f g H is-emb-g x y =
is-equiv-top-is-equiv-left-square
( ap g)
( concat' (f x) (H y))
( ap f)
( concat (H x) (g y))
( htpy-nat H)
( is-equiv-concat (H x) (g y))
( is-emb-g x y)
( is-equiv-concat' (f x) (H y))
abstract
is-emb-htpy' :
{i j : Level} {A : UU i} {B : UU j} (f g : A → B) → (f ~ g) →
is-emb f → is-emb g
is-emb-htpy' f g H is-emb-f =
is-emb-htpy g f (htpy-inv H) is-emb-f
-- Exercise 7.4
abstract
is-emb-comp :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → is-emb g →
is-emb h → is-emb f
is-emb-comp f g h H is-emb-g is-emb-h =
is-emb-htpy f (g ∘ h) H
( λ x y → is-equiv-comp (ap (g ∘ h)) (ap g) (ap h) (ap-comp g h)
( is-emb-h x y)
( is-emb-g (h x) (h y)))
abstract
is-emb-right-factor :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → is-emb g →
is-emb f → is-emb h
is-emb-right-factor f g h H is-emb-g is-emb-f x y =
is-equiv-right-factor
( ap (g ∘ h))
( ap g)
( ap h)
( ap-comp g h)
( is-emb-g (h x) (h y))
( is-emb-htpy (g ∘ h) f (htpy-inv H) is-emb-f x y)
abstract
is-emb-triangle-is-equiv :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (e : A → B) (H : f ~ (g ∘ e)) →
is-equiv e → is-emb g → is-emb f
is-emb-triangle-is-equiv f g e H is-equiv-e is-emb-g =
is-emb-comp f g e H is-emb-g (is-emb-is-equiv e is-equiv-e)
abstract
is-emb-triangle-is-equiv' :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (e : A → B) (H : f ~ (g ∘ e)) →
is-equiv e → is-emb f → is-emb g
is-emb-triangle-is-equiv' f g e H is-equiv-e is-emb-f =
is-emb-triangle-is-equiv g f
( inv-is-equiv is-equiv-e)
( triangle-section f g e H
( pair
( inv-is-equiv is-equiv-e)
( issec-inv-is-equiv is-equiv-e)))
( is-equiv-inv-is-equiv is-equiv-e)
( is-emb-f)
-- Exercise 7.5
abstract
is-emb-inl :
{i j : Level} (A : UU i) (B : UU j) → is-emb (inl {A = A} {B = B})
is-emb-inl A B x =
fundamental-theorem-id x refl
( is-contr-is-equiv
( Σ A (λ y → Eq-coprod A B (inl x) (inl y)))
( tot (λ y → Eq-coprod-eq A B (inl x) (inl y)))
( is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-Eq-coprod-eq A B (inl x) (inl y)))
( is-contr-equiv'
( Σ A (Id x))
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( is-contr-total-path x)))
( λ y → ap inl)
abstract
is-emb-inr :
{i j : Level} (A : UU i) (B : UU j) → is-emb (inr {A = A} {B = B})
is-emb-inr A B x =
fundamental-theorem-id x refl
( is-contr-is-equiv
( Σ B (λ y → Eq-coprod A B (inr x) (inr y)))
( tot (λ y → Eq-coprod-eq A B (inr x) (inr y)))
( is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-Eq-coprod-eq A B (inr x) (inr y)))
( is-contr-equiv'
( Σ B (Id x))
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( is-contr-total-path x)))
( λ y → ap inr)
-- Exercise 7.6
-- Exercise 7.7
tot-htpy :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k}
{f g : (x : A) → B x → C x} → (H : (x : A) → f x ~ g x) → tot f ~ tot g
tot-htpy H (pair x y) = eq-pair refl (H x y)
tot-id :
{i j : Level} {A : UU i} (B : A → UU j) →
(tot (λ x (y : B x) → y)) ~ id
tot-id B (pair x y) = refl
tot-comp :
{i j j' j'' : Level}
{A : UU i} {B : A → UU j} {B' : A → UU j'} {B'' : A → UU j''}
(f : (x : A) → B x → B' x) (g : (x : A) → B' x → B'' x) →
tot (λ x → (g x) ∘ (f x)) ~ ((tot g) ∘ (tot f))
tot-comp f g (pair x y) = refl
-- Exercise 7.8
abstract
fundamental-theorem-id-retr :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) →
(i : (x : A) → B x → Id a x) → (R : (x : A) → retr (i x)) →
is-fiberwise-equiv i
fundamental-theorem-id-retr {_} {_} {A} {B} a i R =
is-fiberwise-equiv-is-equiv-tot i
( is-equiv-is-contr (tot i)
( is-contr-retract-of (Σ _ (λ y → Id a y))
( pair (tot i)
( pair (tot λ x → pr1 (R x))
( ( htpy-inv (tot-comp i (λ x → pr1 (R x)))) ∙h
( ( tot-htpy λ x → pr2 (R x)) ∙h (tot-id B)))))
( is-contr-total-path a))
( is-contr-total-path a))
abstract
is-equiv-sec-is-equiv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (sec-f : sec f) →
is-equiv (pr1 sec-f) → is-equiv f
is-equiv-sec-is-equiv {A = A} {B = B} f (pair g issec-g) is-equiv-sec-f =
let h : A → B
h = inv-is-equiv is-equiv-sec-f
in
is-equiv-htpy h
( ( htpy-left-whisk f (htpy-inv (issec-inv-is-equiv is-equiv-sec-f))) ∙h
( htpy-right-whisk issec-g h))
( is-equiv-inv-is-equiv is-equiv-sec-f)
abstract
fundamental-theorem-id-sec :
{i j : Level} {A : UU i} {B : A → UU j} (a : A)
(f : (x : A) → Id a x → B x) → ((x : A) → sec (f x)) →
is-fiberwise-equiv f
fundamental-theorem-id-sec {A = A} {B = B} a f sec-f x =
let i : (x : A) → B x → Id a x
i = λ x → pr1 (sec-f x)
retr-i : (x : A) → retr (i x)
retr-i = λ x → pair (f x) (pr2 (sec-f x))
is-fiberwise-equiv-i : is-fiberwise-equiv i
is-fiberwise-equiv-i = fundamental-theorem-id-retr a i retr-i
in is-equiv-sec-is-equiv (f x) (sec-f x) (is-fiberwise-equiv-i x)
-- Exercise 7.9
abstract
is-emb-sec-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) →
((x y : A) → sec (ap f {x = x} {y = y})) → is-emb f
is-emb-sec-ap f sec-ap-f x =
fundamental-theorem-id-sec x (λ y → ap f {y = y}) (sec-ap-f x)
-- Exercise 7.10
coherence-is-half-adjoint-equivalence :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (g : B → A)
(G : (f ∘ g) ~ id) (H : (g ∘ f) ~ id) → UU (l1 ⊔ l2)
coherence-is-half-adjoint-equivalence f g G H =
( htpy-right-whisk G f) ~ (htpy-left-whisk f H)
is-half-adjoint-equivalence :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
is-half-adjoint-equivalence {A = A} {B = B} f =
Σ (B → A)
( λ g → Σ ((f ∘ g) ~ id)
( λ G → Σ ((g ∘ f) ~ id) (coherence-is-half-adjoint-equivalence f g G)))
is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
is-path-split {A = A} {B = B} f =
sec f × ((x y : A) → sec (ap f {x = x} {y = y}))
abstract
is-path-split-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-path-split f
is-path-split-is-equiv f is-equiv-f =
pair (pr1 is-equiv-f) (λ x y → pr1 (is-emb-is-equiv f is-equiv-f x y))
abstract
is-half-adjoint-equivalence-is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-path-split f → is-half-adjoint-equivalence f
is-half-adjoint-equivalence-is-path-split {A = A} {B = B} f
( pair (pair g issec-g) sec-ap-f) =
let φ : ((x : A) → fib (ap f) (issec-g (f x))) →
Σ ((g ∘ f) ~ id)
( λ H → (htpy-right-whisk issec-g f) ~ (htpy-left-whisk f H))
φ = ( tot (λ H' → htpy-inv)) ∘
( λ s → pair (λ x → pr1 (s x)) (λ x → pr2 (s x)))
in
pair g
( pair issec-g
( φ (λ x → pair
( pr1 (sec-ap-f (g (f x)) x) (issec-g (f x)))
( pr2 (sec-ap-f (g (f x)) x) (issec-g (f x))))))
abstract
is-equiv-is-half-adjoint-equivalence :
{ l1 l2 : Level} {A : UU l1} {B : UU l2}
(f : A → B) → is-half-adjoint-equivalence f → is-equiv f
is-equiv-is-half-adjoint-equivalence f (pair g (pair G (pair H K))) =
is-equiv-has-inverse g G H
abstract
is-equiv-is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-path-split f → is-equiv f
is-equiv-is-path-split f =
( is-equiv-is-half-adjoint-equivalence f) ∘
( is-half-adjoint-equivalence-is-path-split f)
abstract
is-half-adjoint-equivalence-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-half-adjoint-equivalence f
is-half-adjoint-equivalence-is-equiv f =
( is-half-adjoint-equivalence-is-path-split f) ∘ (is-path-split-is-equiv f)
-- Exercise 7.11
abstract
is-equiv-top-is-equiv-bottom-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv f) → (is-equiv g) → (is-equiv i) → (is-equiv h)
is-equiv-top-is-equiv-bottom-square
f g h i H is-equiv-f is-equiv-g is-equiv-i =
is-equiv-right-factor (i ∘ f) g h H is-equiv-g
( is-equiv-comp' i f is-equiv-f is-equiv-i)
abstract
is-equiv-bottom-is-equiv-top-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv f) → (is-equiv g) → (is-equiv h) → (is-equiv i)
is-equiv-bottom-is-equiv-top-square
f g h i H is-equiv-f is-equiv-g is-equiv-h =
is-equiv-left-factor' i f
( is-equiv-comp (i ∘ f) g h H is-equiv-h is-equiv-g) is-equiv-f
abstract
is-equiv-left-is-equiv-right-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv h) → (is-equiv i) → (is-equiv g) → (is-equiv f)
is-equiv-left-is-equiv-right-square
f g h i H is-equiv-h is-equiv-i is-equiv-g =
is-equiv-right-factor' i f is-equiv-i
( is-equiv-comp (i ∘ f) g h H is-equiv-h is-equiv-g)
abstract
is-equiv-right-is-equiv-left-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv h) → (is-equiv i) → (is-equiv f) → (is-equiv g)
is-equiv-right-is-equiv-left-square
f g h i H is-equiv-h is-equiv-i is-equiv-f =
is-equiv-left-factor (i ∘ f) g h H
( is-equiv-comp' i f is-equiv-f is-equiv-i)
( is-equiv-h)
fib-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h))
(x : X) → (fib f x) → (fib g x)
fib-triangle f g h H .(f a) (pair a refl) = pair (h a) (inv (H a))
square-tot-fib-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(h ∘ (Σ-fib-to-domain f)) ~
((Σ-fib-to-domain g) ∘ (tot (fib-triangle f g h H)))
square-tot-fib-triangle f g h H (pair .(f a) (pair a refl)) = refl
abstract
is-fiberwise-equiv-is-equiv-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(E : is-equiv h) → is-fiberwise-equiv (fib-triangle f g h H)
is-fiberwise-equiv-is-equiv-triangle f g h H E =
is-fiberwise-equiv-is-equiv-tot
( fib-triangle f g h H)
( is-equiv-top-is-equiv-bottom-square
( Σ-fib-to-domain f)
( Σ-fib-to-domain g)
( tot (fib-triangle f g h H))
( h)
( square-tot-fib-triangle f g h H)
( is-equiv-Σ-fib-to-domain f)
( is-equiv-Σ-fib-to-domain g)
( E))
abstract
is-equiv-triangle-is-fiberwise-equiv :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(E : is-fiberwise-equiv (fib-triangle f g h H)) → is-equiv h
is-equiv-triangle-is-fiberwise-equiv f g h H E =
is-equiv-bottom-is-equiv-top-square
( Σ-fib-to-domain f)
( Σ-fib-to-domain g)
( tot (fib-triangle f g h H))
( h)
( square-tot-fib-triangle f g h H)
( is-equiv-Σ-fib-to-domain f)
( is-equiv-Σ-fib-to-domain g)
( is-equiv-tot-is-fiberwise-equiv E)
-- Extra material
{- In order to show that the total space of htpy-cone is contractible, we give
a general construction that helps us characterize the identity type of
a structure. This construction is called
is-contr-total-Eq-structure.
We first give some definitions that help us with the construction of
is-contr-total-Eq-structure. -}
swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
Σ (Σ A B) (λ t → Σ (C (pr1 t)) (D (pr1 t) (pr2 t))) →
Σ (Σ A C) (λ t → Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t)))
swap-total-Eq-structure B C D (pair (pair a b) (pair c d)) =
pair (pair a c) (pair b d)
htpy-swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
( ( swap-total-Eq-structure B C D) ∘
( swap-total-Eq-structure C B (λ x z y → D x y z))) ~ id
htpy-swap-total-Eq-structure B C D (pair (pair a b) (pair c d)) = refl
abstract
is-equiv-swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
is-equiv (swap-total-Eq-structure B C D)
is-equiv-swap-total-Eq-structure B C D =
is-equiv-has-inverse
( swap-total-Eq-structure C B (λ x z y → D x y z))
( htpy-swap-total-Eq-structure B C D)
( htpy-swap-total-Eq-structure C B (λ x z y → D x y z))
abstract
is-contr-Σ :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-contr A → ((x : A) → is-contr (B x)) → is-contr (Σ A B)
is-contr-Σ {A = A} {B = B} is-contr-A is-contr-B =
is-contr-equiv'
( B (center is-contr-A))
( left-unit-law-Σ B is-contr-A)
( is-contr-B (center is-contr-A))
abstract
is-contr-Σ' :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-contr A → (a : A) → is-contr (B a) → is-contr (Σ A B)
is-contr-Σ' {A = A} {B} is-contr-A a is-contr-B =
is-contr-is-equiv'
( B a)
( left-unit-law-Σ-map-gen B is-contr-A a)
( is-equiv-left-unit-law-Σ-map-gen B is-contr-A a)
( is-contr-B)
abstract
is-contr-total-Eq-structure :
{ l1 l2 l3 l4 : Level} { A : UU l1} {B : A → UU l2} {C : A → UU l3}
( D : (x : A) → B x → C x → UU l4) →
( is-contr-AC : is-contr (Σ A C)) →
( t : Σ A C) →
is-contr (Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t))) →
is-contr (Σ (Σ A B) (λ t → Σ (C (pr1 t)) (D (pr1 t) (pr2 t))))
is-contr-total-Eq-structure
{A = A} {B = B} {C = C} D is-contr-AC t is-contr-BD =
is-contr-is-equiv
( Σ (Σ A C) (λ t → Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t))))
( swap-total-Eq-structure B C D)
( is-equiv-swap-total-Eq-structure B C D)
( is-contr-Σ' is-contr-AC t is-contr-BD)
-- Characterizing the identity type of a fiber as the fiber of the action on
-- paths
fib-ap-eq-fib-fiberwise :
{i j : Level} {A : UU i} {B : UU j}
(f : A → B) {b : B} (s t : fib f b) (p : Id (pr1 s) (pr1 t)) →
(Id (tr (λ (a : A) → Id (f a) b) p (pr2 s)) (pr2 t)) →
(Id (ap f p) ((pr2 s) ∙ (inv (pr2 t))))
fib-ap-eq-fib-fiberwise f (pair .x' p) (pair x' refl) refl =
inv ∘ (concat right-unit refl)
abstract
is-fiberwise-equiv-fib-ap-eq-fib-fiberwise :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B} (s t : fib f b) →
is-fiberwise-equiv (fib-ap-eq-fib-fiberwise f s t)
is-fiberwise-equiv-fib-ap-eq-fib-fiberwise
f (pair x y) (pair .x refl) refl =
is-equiv-comp
( fib-ap-eq-fib-fiberwise f (pair x y) (pair x refl) refl)
( inv)
( concat right-unit refl)
( refl-htpy)
( is-equiv-concat right-unit refl)
( is-equiv-inv (y ∙ refl) refl)
fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B}
(s t : fib f b) → Id s t →
fib (ap f {x = pr1 s} {y = pr1 t}) ((pr2 s) ∙ (inv (pr2 t)))
fib-ap-eq-fib f s .s refl = pair refl (inv (right-inv (pr2 s)))
triangle-fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B)
{b : B} (s t : fib f b) →
(fib-ap-eq-fib f s t) ~ ((tot (fib-ap-eq-fib-fiberwise f s t)) ∘ (pair-eq {s = s} {t}))
triangle-fib-ap-eq-fib f (pair x refl) .(pair x refl) refl = refl
abstract
is-equiv-fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B}
(s t : fib f b) → is-equiv (fib-ap-eq-fib f s t)
is-equiv-fib-ap-eq-fib f s t =
is-equiv-comp
( fib-ap-eq-fib f s t)
( tot (fib-ap-eq-fib-fiberwise f s t))
( pair-eq {s = s} {t})
( triangle-fib-ap-eq-fib f s t)
( is-equiv-pair-eq s t)
( is-equiv-tot-is-fiberwise-equiv
( is-fiberwise-equiv-fib-ap-eq-fib-fiberwise f s t))
eq-fib-fib-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x y : A)
(q : Id (f x) (f y)) →
Id (pair x q) (pair y (refl {x = f y})) → fib (ap f {x = x} {y = y}) q
eq-fib-fib-ap f x y q = (tr (fib (ap f)) right-unit) ∘ (fib-ap-eq-fib f (pair x q) (pair y refl))
abstract
is-equiv-eq-fib-fib-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x y : A)
(q : Id (f x) (f y)) → is-equiv (eq-fib-fib-ap f x y q)
is-equiv-eq-fib-fib-ap f x y q =
is-equiv-comp
( eq-fib-fib-ap f x y q)
( tr (fib (ap f)) right-unit)
( fib-ap-eq-fib f (pair x q) (pair y refl))
( refl-htpy)
( is-equiv-fib-ap-eq-fib f (pair x q) (pair y refl))
( is-equiv-tr (fib (ap f)) right-unit)
-- Comparing fib and fib'
fib'-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
fib f y → fib' f y
fib'-fib f y t = tot (λ x → inv) t
abstract
is-equiv-fib'-fib :
{i j : Level} {A : UU i} {B : UU j}
(f : A → B) → is-fiberwise-equiv (fib'-fib f)
is-equiv-fib'-fib f y =
is-equiv-tot-is-fiberwise-equiv (λ x → is-equiv-inv (f x) y)
| {
"alphanum_fraction": 0.5304646182,
"avg_line_length": 35.776387803,
"ext": "agda",
"hexsha": "50789ad7f76d64807ffb3d81916a8f86997a82bd",
"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": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "hemangandhi/HoTT-Intro",
"max_forks_repo_path": "Agda/09-fundamental-theorem.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "hemangandhi/HoTT-Intro",
"max_issues_repo_path": "Agda/09-fundamental-theorem.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "hemangandhi/HoTT-Intro",
"max_stars_repo_path": "Agda/09-fundamental-theorem.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 19223,
"size": 45758
} |
module Test where
open import Pitch
open import Interval
open import Counterpoint
open import Data.Vec using (Vec; []; _∷_; zip)
open import Data.Fin using (zero; suc)
open import Relation.Binary.PropositionalEquality using (refl)
-- Last five notes of Yamanote melody
cantusFirmus : Vec Pitch 5
cantusFirmus = c 5 ∷ e 5 ∷ g 5 ∷ d 6 ∷ c 6 ∷ []
counterpoint : Vec Interval 5
counterpoint = maj10 ∷ min10 ∷ per8 ∷ maj6 ∷ per8 ∷ []
firstSpecies : Counterpoint 3
firstSpecies = zip cantusFirmus counterpoint
testCorrect : FirstSpecies firstSpecies
testCorrect = fs firstSpecies
(λ { zero → refl ;
(suc zero) → refl ;
(suc (suc zero)) → refl ;
(suc (suc (suc zero))) → refl ;
(suc (suc (suc (suc zero)))) → refl })
(λ { zero → refl ;
(suc zero) → refl ;
(suc (suc zero)) → refl ;
(suc (suc (suc zero))) → refl})
refl
| {
"alphanum_fraction": 0.5498046875,
"avg_line_length": 30.1176470588,
"ext": "agda",
"hexsha": "a8e5fcd5d25e97204ecd860834321dc4aec49b9e",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/Test.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/Test.agda",
"max_line_length": 62,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/Test.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 286,
"size": 1024
} |
{-# OPTIONS --type-in-type #-}
open import Data.Unit
open import Data.Product hiding ( curry ; uncurry )
open import Data.List hiding ( concat )
open import Data.String
open import Relation.Binary.PropositionalEquality
open import Function
module Spire.Examples.PropLev where
----------------------------------------------------------------------
Label : Set
Label = String
Enum : Set
Enum = List Label
data Tag : Enum → Set where
here : ∀{l E} → Tag (l ∷ E)
there : ∀{l E} → Tag E → Tag (l ∷ E)
Branches : (E : Enum) (P : Tag E → Set) → Set
Branches [] P = ⊤
Branches (l ∷ E) P = P here × Branches E (λ t → P (there t))
case : {E : Enum} (P : Tag E → Set) (cs : Branches E P) (t : Tag E) → P t
case P (c , cs) here = c
case P (c , cs) (there t) = case (λ t → P (there t)) cs t
UncurriedBranches : (E : Enum) (P : Tag E → Set) (X : Set)
→ Set
UncurriedBranches E P X = Branches E P → X
CurriedBranches : (E : Enum) (P : Tag E → Set) (X : Set)
→ Set
CurriedBranches [] P X = X
CurriedBranches (l ∷ E) P X = P here → CurriedBranches E (λ t → P (there t)) X
curryBranches : {E : Enum} {P : Tag E → Set} {X : Set}
→ UncurriedBranches E P X → CurriedBranches E P X
curryBranches {[]} f = f tt
curryBranches {l ∷ E} f = λ c → curryBranches (λ cs → f (c , cs))
uncurryBranches : {E : Enum} {P : Tag E → Set} {X : Set}
→ CurriedBranches E P X → UncurriedBranches E P X
uncurryBranches {[]} x tt = x
uncurryBranches {l ∷ E} f (c , cs) = uncurryBranches (f c) cs
----------------------------------------------------------------------
data Desc (I : Set) : Set₁ where
End : (i : I) → Desc I
Rec : (i : I) (D : Desc I) → Desc I
Arg : (A : Set) (B : A → Desc I) → Desc I
elimDesc : {I : Set} (P : Desc I → Set)
(pend : (i : I) → P (End i))
(prec : (i : I) (D : Desc I) (pd : P D) → P (Rec i D))
(parg : (A : Set) (B : A → Desc I) (pb : (a : A) → P (B a)) → P (Arg A B))
(D : Desc I) → P D
elimDesc P pend prec parg (End i) = pend i
elimDesc P pend prec parg (Rec i D) = prec i D (elimDesc P pend prec parg D)
elimDesc P pend prec parg (Arg A B) = parg A B (λ a → elimDesc P pend prec parg (B a))
----------------------------------------------------------------------
ISet : Set → Set₁
ISet I = I → Set
El : {I : Set} (D : Desc I) → ISet I → ISet I
El (End j) X i = j ≡ i
El (Rec j D) X i = X j × El D X i
El (Arg A B) X i = Σ A (λ a → El (B a) X i)
Hyps : {I : Set} (D : Desc I) (X : ISet I) (P : (i : I) → X i → Set) (i : I) (xs : El D X i) → Set
Hyps (End j) X P i q = ⊤
Hyps (Rec j D) X P i (x , xs) = P j x × Hyps D X P i xs
Hyps (Arg A B) X P i (a , b) = Hyps (B a) X P i b
----------------------------------------------------------------------
UncurriedEl : {I : Set} (D : Desc I) (X : ISet I) → Set
UncurriedEl D X = ∀{i} → El D X i → X i
CurriedEl : {I : Set} (D : Desc I) (X : ISet I) → Set
CurriedEl (End i) X = X i
CurriedEl (Rec i D) X = (x : X i) → CurriedEl D X
CurriedEl (Arg A B) X = (a : A) → CurriedEl (B a) X
curryEl : {I : Set} (D : Desc I) (X : ISet I)
→ UncurriedEl D X → CurriedEl D X
curryEl (End i) X cn = cn refl
curryEl (Rec i D) X cn = λ x → curryEl D X (λ xs → cn (x , xs))
curryEl (Arg A B) X cn = λ a → curryEl (B a) X (λ xs → cn (a , xs))
uncurryEl : {I : Set} (D : Desc I) (X : ISet I)
→ CurriedEl D X → UncurriedEl D X
uncurryEl (End i) X cn refl = cn
uncurryEl (Rec i D) X cn (x , xs) = uncurryEl D X (cn x) xs
uncurryEl (Arg A B) X cn (a , xs) = uncurryEl (B a) X (cn a) xs
----------------------------------------------------------------------
UncurriedHyps : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
→ Set
UncurriedHyps D X P cn =
∀ i (xs : El D X i) (ihs : Hyps D X P i xs) → P i (cn xs)
CurriedHyps : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
→ Set
CurriedHyps (End i) X P cn =
P i (cn refl)
CurriedHyps (Rec i D) X P cn =
(x : X i) → P i x → CurriedHyps D X P (λ xs → cn (x , xs))
CurriedHyps (Arg A B) X P cn =
(a : A) → CurriedHyps (B a) X P (λ xs → cn (a , xs))
curryHyps : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
→ UncurriedHyps D X P cn
→ CurriedHyps D X P cn
curryHyps (End i) X P cn pf =
pf i refl tt
curryHyps (Rec i D) X P cn pf =
λ x ih → curryHyps D X P (λ xs → cn (x , xs)) (λ i xs ihs → pf i (x , xs) (ih , ihs))
curryHyps (Arg A B) X P cn pf =
λ a → curryHyps (B a) X P (λ xs → cn (a , xs)) (λ i xs ihs → pf i (a , xs) ihs)
uncurryHyps : {I : Set} (D : Desc I) (X : ISet I)
(P : (i : I) → X i → Set)
(cn : UncurriedEl D X)
→ CurriedHyps D X P cn
→ UncurriedHyps D X P cn
uncurryHyps (End .i) X P cn pf i refl tt =
pf
uncurryHyps (Rec j D) X P cn pf i (x , xs) (ih , ihs) =
uncurryHyps D X P (λ ys → cn (x , ys)) (pf x ih) i xs ihs
uncurryHyps (Arg A B) X P cn pf i (a , xs) ihs =
uncurryHyps (B a) X P (λ ys → cn (a , ys)) (pf a) i xs ihs
----------------------------------------------------------------------
data μ {I : Set} (D : Desc I) : ISet I where
init : UncurriedEl D (μ D)
----------------------------------------------------------------------
Data : Set
Data =
Σ Set λ I →
Σ Enum λ E →
Branches E (λ _ → Desc I)
DataI : Data → Set
DataI (I , E , B) = I
DataE : Data → Enum
DataE (I , E , B) = E
DataT : Data → Set
DataT R = Tag (DataE R)
DataB : (R : Data) → Branches (DataE R) (λ _ → Desc (DataI R))
DataB (I , E , B) = B
DataD : (R : Data) → Desc (DataI R)
DataD R = Arg (DataT R) (case (λ _ → Desc (DataI R)) (DataB R))
caseR : (R : Data) → DataT R → Desc (DataI R)
caseR R = case (λ _ → Desc (DataI R)) (DataB R)
----------------------------------------------------------------------
inj : (R : Data)
→ let D = DataD R
in CurriedEl D (μ D)
inj R = let D = DataD R
in curryEl D (μ D) init
----------------------------------------------------------------------
ind : {I : Set} (D : Desc I)
(P : (i : I) → μ D i → Set)
(α : UncurriedHyps D (μ D) P init)
(i : I)
(x : μ D i)
→ P i x
prove : {I : Set} (D E : Desc I)
(P : (i : I) → μ E i → Set)
(α : UncurriedHyps E (μ E) P init)
(i : I) (xs : El D (μ E) i) → Hyps D (μ E) P i xs
ind D P α i (init xs) = α i xs (prove D D P α i xs)
prove (End j) E P α i q = tt
prove (Rec j D) E P α i (x , xs) = ind E P α j x , prove D E P α i xs
prove (Arg A B) E P α i (a , xs) = prove (B a) E P α i xs
----------------------------------------------------------------------
indCurried : {I : Set} (D : Desc I)
(P : (i : I) → μ D i → Set)
(f : CurriedHyps D (μ D) P init)
(i : I)
(x : μ D i)
→ P i x
indCurried D P f i x = ind D P (uncurryHyps D (μ D) P init f) i x
SumCurriedHyps : (R : Data)
→ let D = DataD R in
(P : ∀ i → μ D i → Set)
→ DataT R → Set
SumCurriedHyps R P t =
CurriedHyps (caseR R t) (μ (DataD R)) P (λ xs → init (t , xs))
elimUncurried : (R : Data)
→ let D = DataD R in
(P : ∀ i → μ D i → Set)
→ UncurriedBranches (DataE R)
(SumCurriedHyps R P)
(∀ i (x : μ D i) → P i x)
elimUncurried R P cs i x =
indCurried (DataD R) P
(case (SumCurriedHyps R P) cs)
i x
elim : (R : Data)
→ let D = DataD R in
(P : ∀ i → μ D i → Set)
→ CurriedBranches (DataE R)
(SumCurriedHyps R P)
(∀ i (x : μ D i) → P i x)
elim R P = curryBranches (elimUncurried R P)
----------------------------------------------------------------------
ℕE : Enum
ℕE = "zero" ∷ "suc" ∷ []
VecE : Enum
VecE = "nil" ∷ "cons" ∷ []
ℕT : Set
ℕT = Tag ℕE
VecT : Set
VecT = Tag VecE
zeroT : ℕT
zeroT = here
sucT : ℕT
sucT = there here
nilT : VecT
nilT = here
consT : VecT
consT = there here
ℕR : Data
ℕR = ⊤ , ℕE
, End tt
, Rec tt (End tt)
, tt
ℕD : Desc ⊤
ℕD = DataD ℕR
ℕ : ⊤ → Set
ℕ = μ ℕD
zero : ℕ tt
zero = init (zeroT , refl)
suc : ℕ tt → ℕ tt
suc n = init (sucT , n , refl)
VecR : (A : Set) → Data
VecR A = (ℕ tt) , VecE
, End zero
, Arg (ℕ tt) (λ n → Arg A λ _ → Rec n (End (suc n)))
, tt
nilD : (A : Set) → Desc (ℕ tt)
nilD A = End zero
consD : (A : Set) → Desc (ℕ tt)
consD A = Arg (ℕ tt) (λ n → Arg A (λ _ → Rec n (End (suc n))))
VecD : (A : Set) → Desc (ℕ tt)
VecD A = DataD (VecR A)
Vec : (A : Set) → ℕ tt → Set
Vec A = μ (VecD A)
NilEl : (A : Set) (n : ℕ tt) → Set
NilEl A n = El (nilD A) (Vec A) n
ConsEl : (A : Set) → ℕ tt → Set
ConsEl A n = El (consD A) (Vec A) n
VecEl : (A : Set) → ℕ tt → Set
VecEl A n = El (VecD A) (Vec A) n
NilHyps : (A : Set) (P : (n : ℕ tt) → Vec A n → Set) (n : ℕ tt) (xs : NilEl A n) → Set
NilHyps A P n xs = Hyps (nilD A) (Vec A) P n xs
ConsHyps : (A : Set) (P : (n : ℕ tt) → Vec A n → Set) (n : ℕ tt) (xs : ConsEl A n) → Set
ConsHyps A P n xs = Hyps (consD A) (Vec A) P n xs
VecHyps : (A : Set) (P : (n : ℕ tt) → Vec A n → Set) (n : ℕ tt) (xs : VecEl A n) → Set
VecHyps A P n xs = Hyps (VecD A) (Vec A) P n xs
ConsUncurriedHyps : (A : Set)
(P : (n : ℕ tt) → Vec A n → Set)
(cn : UncurriedEl (consD A) (Vec A)) → Set
ConsUncurriedHyps A P cn = UncurriedHyps (consD A) (Vec A) P cn
nil : (A : Set) → Vec A zero
nil A = init (nilT , refl)
cons : (A : Set) (n : ℕ tt) (x : A) (xs : Vec A n) → Vec A (suc n)
cons A n x xs = init (consT , n , x , xs , refl)
nil2 : (A : Set) → Vec A zero
nil2 A = inj (VecR A) nilT
cons2 : (A : Set) (n : ℕ tt) (x : A) (xs : Vec A n) → Vec A (suc n)
cons2 A = inj (VecR A) consT
----------------------------------------------------------------------
add : ℕ tt → ℕ tt → ℕ tt
add = elim ℕR (λ u n → ℕ tt → ℕ tt)
(λ n → n)
(λ m ih n → suc (ih n))
tt
mult : ℕ tt → ℕ tt → ℕ tt
mult = elim ℕR (λ u n → ℕ tt → ℕ tt)
(λ n → zero)
(λ m ih n → add n (ih n))
tt
append : (A : Set) (m : ℕ tt) (xs : Vec A m) (n : ℕ tt) (ys : Vec A n) → Vec A (add m n)
append A = elim (VecR A) (λ m xs → (n : ℕ tt) (ys : Vec A n) → Vec A (add m n))
(λ n ys → ys)
(λ m x xs ih n ys → cons A (add m n) x (ih n ys))
concat : (A : Set) (m n : ℕ tt) (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat A m = elim (VecR (Vec A m)) (λ n xss → Vec A (mult n m))
(nil A)
(λ n xs xss ih → append A m xs (mult n m) ih)
----------------------------------------------------------------------
| {
"alphanum_fraction": 0.4877179081,
"avg_line_length": 27.8126721763,
"ext": "agda",
"hexsha": "5410b96f54d352d393f764de19cc2ec8c587e721",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-08-17T21:00:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-08-17T21:00:07.000Z",
"max_forks_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "spire/spire",
"max_forks_repo_path": "formalization/agda/Spire/Examples/PropLev.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353",
"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": "spire/spire",
"max_issues_repo_path": "formalization/agda/Spire/Examples/PropLev.agda",
"max_line_length": 98,
"max_stars_count": 43,
"max_stars_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "spire/spire",
"max_stars_repo_path": "formalization/agda/Spire/Examples/PropLev.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T17:10:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-28T23:25:33.000Z",
"num_tokens": 4079,
"size": 10096
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Cocomplete.Finitely {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Categories.Category.Cocartesian C
open import Categories.Diagram.Coequalizer C
open import Categories.Diagram.Pushout C
open import Categories.Diagram.Pushout.Properties C
open Category C
record FinitelyCocomplete : Set (levelOfTerm C) where
field
cocartesian : Cocartesian
coequalizer : ∀ {A B} (f g : A ⇒ B) → Coequalizer f g
module cocartesian = Cocartesian cocartesian
module coequalizer {A B} (f g : A ⇒ B) = Coequalizer (coequalizer f g)
open cocartesian public
pushout : ∀ {X Y Z} (f : X ⇒ Y) (g : X ⇒ Z) → Pushout f g
pushout f g = Coproduct×Coequalizer⇒Pushout coproduct (coequalizer _ _)
module pushout {X Y Z} (f : X ⇒ Y) (g : X ⇒ Z) = Pushout (pushout f g)
| {
"alphanum_fraction": 0.7110352673,
"avg_line_length": 30.3103448276,
"ext": "agda",
"hexsha": "78bf7b40f99a53fe435ac5df79d9f74ab6a42288",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Cocomplete/Finitely.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Cocomplete/Finitely.agda",
"max_line_length": 81,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Cocomplete/Finitely.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 276,
"size": 879
} |
module nodcap.NF.Cut where
open import Algebra
open import Data.Environment
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Pos as ℕ⁺
open import Data.List as L using (List; []; _∷_; _++_)
open import Data.List.Any as LA using (Any; here; there)
open import Data.List.Any.BagAndSetEquality as B
open import Data.Product as PR using (∃; _×_; _,_; proj₁; proj₂)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_$_; flip)
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as I using ()
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_)
open import nodcap.Base
open import nodcap.NF.Typing
open import nodcap.NF.Contract
open import nodcap.NF.Expand
open I.Inverse using (to; from)
private module ++ {a} {A : Set a} = Monoid (L.monoid A)
{-# TERMINATING #-}
-- Theorem:
-- Cut elimination.
mutual
cut : {Γ Δ : Environment} {A : Type} →
⊢ⁿᶠ A ∷ Γ → ⊢ⁿᶠ A ^ ∷ Δ →
---------------------
⊢ⁿᶠ Γ ++ Δ
cut {_} {Δ} {A = 𝟏} halt (wait y)
= y
cut {Γ} {_} {A = ⊥} (wait x) halt
= P.subst ⊢ⁿᶠ_ (P.sym (proj₂ ++.identity Γ)) x
cut {_} {Θ} {A = A ⊗ B} (send {Γ} {Δ} x y) (recv z)
= P.subst ⊢ⁿᶠ_ (P.sym (++.assoc Γ Δ Θ))
$ exch (swp [] Γ Δ)
$ cut y
$ exch (fwd [] Γ)
$ cut x z
cut {Θ} {_} {A = A ⅋ B} (recv x) (send {Γ} {Δ} y z)
= P.subst ⊢ⁿᶠ_ (++.assoc Θ Γ Δ)
$ cut (cut x y) z
cut {Γ} {Δ} {A = A ⊕ B} (sel₁ x) (case y z)
= cut x y
cut {Γ} {Δ} {A = A ⊕ B} (sel₂ x) (case y z)
= cut x z
cut {Γ} {Δ} {A = A & B} (case x y) (sel₁ z)
= cut x z
cut {Γ} {Δ} {A = A & B} (case x y) (sel₂ z)
= cut y z
cut {Γ} {Δ} {A = ![ n ] A} x y
= interleaveIn (here P.refl) x (expand y)
cut {Γ} {Δ} {A = ?[ n ] A} x y
= exch (swp₂ Γ)
$ interleaveIn {_ ∷ Δ} {Γ} (here P.refl) y
$ P.subst (λ A → ⊢ⁿᶠ replicate⁺ n A ++ Γ) (P.sym $ ^-inv A)
$ expand x
cut {Γ} {Δ} {A} (exch b x) y
= exch (B.++-cong {ys₁ = Δ} (del-from b (here P.refl)) I.id)
$ cutIn (from b ⟨$⟩ here P.refl) (here P.refl) x y
cut {Γ} {Δ} {A} x (exch b y)
= exch (B.++-cong {xs₁ = Γ} I.id (del-from b (here P.refl)))
$ cutIn (here P.refl) (from b ⟨$⟩ here P.refl) x y
cutIn : {Γ Δ : Environment} {A : Type} (i : A ∈ Γ) (j : A ^ ∈ Δ) →
⊢ⁿᶠ Γ → ⊢ⁿᶠ Δ →
----------------
⊢ⁿᶠ Γ - i ++ Δ - j
cutIn (here P.refl) (here P.refl) x y = cut x y
cutIn {_} {Θ} (there i) j (send {Γ} {Δ} x y) z
with split Γ i
... | inj₁ (k , p) rewrite p
= P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (_ ∷ Γ - k) Δ (Θ - j)))
$ exch (swp₃ (_ ∷ Γ - k) Δ)
$ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Γ - k) (Θ - j) Δ)
$ flip send y
$ cutIn (there k) j x z
... | inj₂ (k , p) rewrite p
= P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (_ ∷ Γ) (Δ - k) (Θ - j)))
$ send x
$ cutIn (there k) j y z
cutIn (there i) j (recv x) y
= recv
$ cutIn (there (there i)) j x y
cutIn (there i) j (sel₁ x) y
= sel₁
$ cutIn (there i) j x y
cutIn (there i) j (sel₂ x) y
= sel₂
$ cutIn (there i) j x y
cutIn (there i) j (case x y) z
= case
( cutIn (there i) j x z )
( cutIn (there i) j y z )
cutIn (there ()) j halt y
cutIn (there i) j (wait x) y
= wait
$ cutIn i j x y
cutIn (there i) j loop y
= loop
cutIn {Γ} {Δ} (there i) j (mk?₁ x) y
= mk?₁
$ cutIn (there i) j x y
cutIn {Γ} {Δ} (there i) j (mk!₁ x) y
= mk!₁
$ cutIn (there i) j x y
cutIn {Γ} {Δ} (there i) j (cont x) y
= cont
$ cutIn (there (there i)) j x y
cutIn {_} {Θ} (there i) j (pool {Γ} {Δ} x y) z
with split Γ i
... | inj₁ (k , p) rewrite p
= P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (_ ∷ Γ - k) Δ (Θ - j)))
$ exch (swp₃ (_ ∷ Γ - k) Δ)
$ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Γ - k) (Θ - j) Δ)
$ flip pool y
$ cutIn (there k) j x z
... | inj₂ (k , p) rewrite p
= P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (_ ∷ Γ) (Δ - k) (Θ - j)))
$ pool x
$ cutIn (there k) j y z
cutIn {Θ} {_} i (there j) x (send {Γ} {Δ} y z)
with split Γ j
... | inj₁ (k , p) rewrite p
= exch (bwd [] (Θ - i))
$ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Θ - i) (Γ - k) Δ)
$ flip send z
$ exch (fwd [] (Θ - i))
$ cutIn i (there k) x y
... | inj₂ (k , p) rewrite p
= exch (swp [] (Θ - i) (_ ∷ Γ))
$ send y
$ exch (fwd [] (Θ - i))
$ cutIn i (there k) x z
cutIn {Γ} i (there j) x (recv {Δ} y)
= exch (bwd [] (Γ - i))
$ recv
$ exch (swp [] (_ ∷ _ ∷ []) (Γ - i))
$ cutIn i (there (there j)) x y
cutIn {Γ} {Δ} i (there j) x (sel₁ y)
= exch (bwd [] (Γ - i))
$ sel₁
$ exch (fwd [] (Γ - i))
$ cutIn i (there j) x y
cutIn {Γ} {Δ} i (there j) x (sel₂ y)
= exch (bwd [] (Γ - i))
$ sel₂
$ exch (fwd [] (Γ - i))
$ cutIn i (there j) x y
cutIn {Γ} {Δ} i (there j) x (case y z)
= exch (bwd [] (Γ - i))
$ case
( exch (fwd [] (Γ - i)) $ cutIn i (there j) x y )
( exch (fwd [] (Γ - i)) $ cutIn i (there j) x z )
cutIn {Γ} i (there ()) x halt
cutIn {Γ} {Δ} i (there j) x (wait y)
= exch (bwd [] (Γ - i))
$ wait
$ cutIn i j x y
cutIn {Γ} {Δ} i (there j) x loop
= exch (bwd [] (Γ - i)) loop
cutIn {Γ} {Δ} i (there j) x (mk?₁ y)
= exch (bwd [] (Γ - i))
$ mk?₁
$ exch (fwd [] (Γ - i))
$ cutIn i (there j) x y
cutIn {Γ} {Δ} i (there j) x (mk!₁ y)
= exch (bwd [] (Γ - i))
$ mk!₁
$ exch (fwd [] (Γ - i))
$ cutIn i (there j) x y
cutIn {Γ} {Δ} i (there j) x (cont y)
= exch (bwd [] (Γ - i))
$ cont
$ exch (swp [] (_ ∷ _ ∷ []) (Γ - i))
$ cutIn i (there (there j)) x y
cutIn {Θ} {_} i (there j) x (pool {Γ} {Δ} y z)
with split Γ j
... | inj₁ (k , p) rewrite p
= exch (bwd [] (Θ - i))
$ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Θ - i) (Γ - k) Δ)
$ flip pool z
$ exch (fwd [] (Θ - i))
$ cutIn i (there k) x y
... | inj₂ (k , p) rewrite p
= exch (swp [] (Θ - i) (_ ∷ Γ))
$ pool y
$ exch (fwd [] (Θ - i))
$ cutIn i (there k) x z
cutIn {Γ} {Δ} i j (exch b x) y
= exch (B.++-cong {ys₁ = Δ - j} (del-from b i ) I.id)
$ cutIn (from b ⟨$⟩ i) j x y
cutIn {Γ} {Δ} i j x (exch b y)
= exch (B.++-cong {xs₁ = Γ - i} I.id (del-from b j))
$ cutIn i (from b ⟨$⟩ j) x y
interleaveIn : {Γ Δ : Environment} {A : Type} {n : ℕ⁺} (i : ![ n ] A ∈ Γ) →
⊢ⁿᶠ Γ → ⊢ⁿᶠ replicate⁺ n (A ^) ++ Δ →
-----------------------------------------------
⊢ⁿᶠ Γ - i ++ Δ
interleaveIn (here P.refl) (mk!₁ {Γ} x) z
= cut x z
interleaveIn {._} {Θ} (here P.refl) (pool {Γ} {Δ} {A} {m} {n} x y) z
= P.subst ⊢ⁿᶠ_ (P.sym $ ++.assoc Γ Δ Θ)
$ interleaveIn (here P.refl) x
$ exch (swp [] (replicate⁺ m _) Δ)
$ interleaveIn (here P.refl) y
$ exch (swp [] (replicate⁺ n _) (replicate⁺ m _))
$ P.subst ⊢ⁿᶠ_ (++.assoc (replicate⁺ m _) (replicate⁺ n _) Θ)
$ P.subst (λ Γ → ⊢ⁿᶠ Γ ++ Θ) (P.sym $ replicate⁺-++-commute m n) z
interleaveIn {._} {Θ} (there i) (send {Γ} {Δ} {A} {B} x y) z
with split Γ i
... | inj₁ (j , p) rewrite p
= P.subst ⊢ⁿᶠ_ (P.sym $ ++.assoc (_ ∷ Γ - j) Δ Θ)
$ exch (swp₃ (_ ∷ Γ - j) Δ {Θ})
$ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Γ - j) Θ Δ)
$ flip send y
$ interleaveIn (there j) x z
... | inj₂ (j , p) rewrite p
= P.subst ⊢ⁿᶠ_ (P.sym $ ++.assoc (_ ∷ Γ) (Δ - j) Θ)
$ send x
$ interleaveIn (there j) y z
interleaveIn (there i) (recv x) z
= recv
$ interleaveIn (there (there i)) x z
interleaveIn (there i) (sel₁ x) z
= sel₁
$ interleaveIn (there i) x z
interleaveIn (there i) (sel₂ x) z
= sel₂
$ interleaveIn (there i) x z
interleaveIn (there i) (case x y) z
= case (interleaveIn (there i) x z) (interleaveIn (there i) y z)
interleaveIn (there ()) halt z
interleaveIn (there i) (wait x) z
= wait
$ interleaveIn i x z
interleaveIn (there i) loop z
= loop
interleaveIn (there i) (mk?₁ x) z
= mk?₁
$ interleaveIn (there i) x z
interleaveIn (there i) (mk!₁ x) z
= mk!₁
$ interleaveIn (there i) x z
interleaveIn (there i) (cont x) z
= cont
$ interleaveIn (there (there i)) x z
interleaveIn {._} {Θ} (there i) (pool {Γ} {Δ} x y) z
with split Γ i
... | inj₁ (j , p) rewrite p
= P.subst ⊢ⁿᶠ_ (P.sym $ ++.assoc (_ ∷ Γ - j) Δ Θ)
$ exch (swp₃ (_ ∷ Γ - j) Δ {Θ})
$ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Γ - j) Θ Δ)
$ flip pool y
$ interleaveIn (there j) x z
... | inj₂ (j , p) rewrite p
= P.subst ⊢ⁿᶠ_ (P.sym $ ++.assoc (_ ∷ Γ) (Δ - j) Θ)
$ pool x
$ interleaveIn (there j) y z
interleaveIn {Γ} {Δ} i (exch b x) z
= exch (B.++-cong {ys₁ = Δ} (del-from b i) I.id)
$ interleaveIn (from b ⟨$⟩ i) x z
-- -}
-- -}
-- -}
-- -}
-- -}
| {
"alphanum_fraction": 0.4814814815,
"avg_line_length": 30.816254417,
"ext": "agda",
"hexsha": "f5aff0dc6d6208c9885533d9936ce6460692a73a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "pepijnkokke/nodcap",
"max_forks_repo_path": "src/cpnd1/nodcap/NF/Cut.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"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": "pepijnkokke/nodcap",
"max_issues_repo_path": "src/cpnd1/nodcap/NF/Cut.agda",
"max_line_length": 77,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/nodcap",
"max_stars_repo_path": "src/cpnd1/nodcap/NF/Cut.agda",
"max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z",
"num_tokens": 4010,
"size": 8721
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra
open import Data.Bool.Base using (Bool; if_then_else_)
open import Function.Base using (_∘_)
open import Data.Integer.Base as ℤ
using (ℤ; +_; +0; +[1+_]; -[1+_])
import Data.Integer.Properties as ℤP
open import Data.Integer.DivMod as ℤD
open import Data.Nat as ℕ using (ℕ; zero; suc)
open import Data.Nat.Properties as ℕP using (≤-step)
import Data.Nat.DivMod as ℕD
open import Level using (0ℓ)
open import Data.Product
open import Relation.Nullary
open import Relation.Nullary.Negation using (contraposition)
open import Relation.Nullary.Decidable
open import Relation.Unary using (Pred)
open import Relation.Binary.PropositionalEquality.Core using (_≡_; _≢_; refl; cong; sym; subst; trans; ≢-sym)
open import Relation.Binary
open import Data.Rational.Unnormalised as ℚ using (ℚᵘ; mkℚᵘ; _≢0; _/_; 0ℚᵘ; 1ℚᵘ; ↥_; ↧_; ↧ₙ_)
import Data.Rational.Unnormalised.Properties as ℚP
open import Algebra.Bundles
open import Algebra.Structures
open import Data.Empty
open import Data.Sum
open import Data.Maybe.Base
open import RealsRefactored
open import Data.List
open import Function.Structures {_} {_} {_} {_} {ℕ} _≡_ {ℕ} _≡_
{-
The solvers are used and renamed often enough to warrant them being opened up here
for the sake of consistency and cleanliness.
-}
open ℝ-Solver
open import NonReflectiveZ as ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊖_ to _:-_
; ⊝_ to :-_
; _⊜_ to _:=_
; Κ to ℤΚ
)
open import NonReflectiveQ as ℚ-Solver using ()
renaming
( solve to ℚsolve
; _⊕_ to _+:_
; _⊗_ to _*:_
; _⊖_ to _-:_
; ⊝_ to -:_
; _⊜_ to _=:_
; Κ to ℚΚ
)
open ℚᵘ
open ℝ
--∀k∈ℕ ∃Nₖ∈ℕ ∀n≥Nₖ ∣ fₙ - x₀ ∣ ≤ k⁻¹
data _ConvergesTo_ : REL (ℕ -> ℝ) ℝ 0ℓ where
con* : {f : ℕ -> ℝ} -> {x₀ : ℝ} ->
(∀ k -> {k≢0 : k ≢0} -> ∃ λ Nₖ-1 -> (∀ n -> n ℕ.≥ suc (Nₖ-1) -> ∣ f n - x₀ ∣ ≤ ((+ 1 / k) {k≢0}) ⋆)) ->
f ConvergesTo x₀
_isConvergent : (ℕ -> ℝ) -> Set
f isConvergent = ∃ λ x₀ -> f ConvergesTo x₀
∣p∣⋆≃∣p⋆∣ : ∀ p -> ℚ.∣ p ∣ ⋆ ≃ ∣ p ⋆ ∣
∣p∣⋆≃∣p⋆∣ p = ≃-reflexive (λ {n -> ℚP.≃-refl})
p≤q+j⁻¹⇒p≤q : ∀ {p q} -> (∀ j -> {j≢0 : j ≢0} -> p ℚ.≤ q ℚ.+ (+ 1 / j) {j≢0}) -> p ℚ.≤ q
p≤q+j⁻¹⇒p≤q {p} {q} hyp = p-q≤j⁻¹⇒p≤q (λ {(suc j-1) -> let j = suc j-1 in begin
p ℚ.- q ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- q) (hyp j) ⟩
q ℚ.+ + 1 / j ℚ.- q ≈⟨ ℚsolve 2 (λ q j⁻¹ -> (q +: j⁻¹ -: q) =: j⁻¹) ℚP.≃-refl q (+ 1 / j) ⟩
+ 1 / j ∎})
where open ℚP.≤-Reasoning
{-
Useful for escaping the "metal" of the reals.
-}
∣x-y∣≤k⁻¹⇒x≃y : ∀ x y -> (∀ (k : ℕ) -> {k≢0 : k ≢0} -> ∣ x - y ∣ ≤ ((+ 1 / k) {k≢0}) ⋆) -> x ≃ y
∣x-y∣≤k⁻¹⇒x≃y x y hyp = *≃* λ {(suc n-1) -> p≤q+j⁻¹⇒p≤q (λ {(suc j-1) ->
let n = suc n-1; j = suc j-1; xₙ = seq x n; yₙ = seq y n in
p⋆≤q⋆⇒p≤q ℚ.∣ xₙ ℚ.- yₙ ∣ (+ 2 / n ℚ.+ + 1 / j) (begin
ℚ.∣ xₙ ℚ.- yₙ ∣ ⋆ ≈⟨ ≃-trans (∣p∣⋆≃∣p⋆∣ (xₙ ℚ.- yₙ)) (∣-∣-cong (⋆-distrib-to-p⋆-q⋆ xₙ yₙ)) ⟩
∣ xₙ ⋆ - yₙ ⋆ ∣ ≈⟨ ∣-∣-cong (solve 4 (λ x y xₙ yₙ ->
(xₙ ⊖ yₙ) ⊜ ((xₙ ⊖ x) ⊕ (y ⊖ yₙ) ⊕ (x ⊖ y)))
≃-refl x y (xₙ ⋆) (yₙ ⋆)) ⟩
∣ (xₙ ⋆ - x) + (y - yₙ ⋆) + (x - y) ∣ ≤⟨ ≤-trans
(∣x+y∣≤∣x∣+∣y∣ ((xₙ ⋆ - x) + (y - yₙ ⋆)) (x - y))
(+-monoˡ-≤ ∣ x - y ∣ (∣x+y∣≤∣x∣+∣y∣ (xₙ ⋆ - x) (y - yₙ ⋆))) ⟩
∣ xₙ ⋆ - x ∣ + ∣ y - yₙ ⋆ ∣ + ∣ x - y ∣ ≤⟨ +-mono-≤
(+-mono-≤ (≤-respˡ-≃ (∣x-y∣≃∣y-x∣ x (xₙ ⋆)) (lemma-2-14 x n))
(lemma-2-14 y n)) (hyp j) ⟩
(+ 1 / n) ⋆ + (+ 1 / n) ⋆ + (+ 1 / j) ⋆ ≈⟨ solve 0
((Κ (+ 1 / n) ⊕ Κ (+ 1 / n) ⊕ Κ (+ 1 / j)) ⊜
Κ (+ 1 / n ℚ.+ + 1 / n ℚ.+ + 1 / j))
≃-refl ⟩
(+ 1 / n ℚ.+ + 1 / n ℚ.+ + 1 / j) ⋆ ≈⟨ ⋆-cong (ℚP.+-congˡ (+ 1 / j) {+ 1 / n ℚ.+ + 1 / n} {+ 2 / n}
(ℚ.*≡* (ℤsolve 1 (λ n ->
(ℤΚ (+ 1) :* n :+ ℤΚ (+ 1) :* n) :* n := ℤΚ (+ 2) :* (n :* n))
refl (+ n)))) ⟩
(+ 2 / n ℚ.+ + 1 / j) ⋆ ∎)})}
where open ≤-Reasoning
xₙ≃yₙ∧xₙ→x₀⇒yₙ→x₀ : ∀ {xs ys : ℕ -> ℝ} -> (∀ n -> {n ≢0} -> xs n ≃ ys n) -> (x→x₀ : xs isConvergent) -> ys ConvergesTo proj₁ x→x₀
xₙ≃yₙ∧xₙ→x₀⇒yₙ→x₀ {xs} {ys} xₙ≃yₙ (x₀ , con* x→x₀) = con* (λ {(suc k-1) -> let k = suc k-1 in
proj₁ (x→x₀ k) , λ {(suc n-1) n≥N -> let n = suc n-1 in begin
∣ ys n - x₀ ∣ ≈⟨ ∣-∣-cong (+-congˡ (- x₀) (≃-symm (xₙ≃yₙ n))) ⟩
∣ xs n - x₀ ∣ ≤⟨ proj₂ (x→x₀ k) n n≥N ⟩
(+ 1 / k) ⋆ ∎}})
where open ≤-Reasoning
xₙ→x∧x≃y⇒xₙ→y : ∀ {xs : ℕ -> ℝ} -> ∀ {x y : ℝ} -> xs ConvergesTo x -> x ≃ y -> xs ConvergesTo y
xₙ→x∧x≃y⇒xₙ→y {xs} {x} {y} (con* xₙ→x) x≃y = con* (λ {(suc k-1) -> let k = suc k-1; Nₖ = suc (proj₁ (xₙ→x k)) in
ℕ.pred Nₖ , λ n n≥Nₖ -> begin
∣ xs n - y ∣ ≈⟨ ∣-∣-cong (+-congʳ (xs n) (-‿cong (≃-symm x≃y))) ⟩
∣ xs n - x ∣ ≤⟨ proj₂ (xₙ→x k) n n≥Nₖ ⟩
(+ 1 / k) ⋆ ∎})
where open ≤-Reasoning
uniqueness-of-limits : ∀ {f : ℕ -> ℝ} -> ∀ {x y : ℝ} -> f ConvergesTo x -> f ConvergesTo y -> x ≃ y
uniqueness-of-limits {f} {x} {y} (con* f→x) (con* f→y) = ∣x-y∣≤k⁻¹⇒x≃y x y (λ {(suc k-1) ->
let k = suc k-1; N₁ = suc (proj₁ (f→x (2 ℕ.* k))); N₂ = suc (proj₁ ((f→y (2 ℕ.* k))))
; N = N₁ ℕ.⊔ N₂ in begin
∣ x - y ∣ ≈⟨ ∣-∣-cong (solve 3 (λ x y fN ->
(x ⊖ y) ⊜ ((x ⊖ fN) ⊕ (fN ⊖ y)))
≃-refl x y (f N)) ⟩
∣ (x - f N) + (f N - y) ∣ ≤⟨ ∣x+y∣≤∣x∣+∣y∣ (x - f N) (f N - y) ⟩
∣ x - f N ∣ + ∣ f N - y ∣ ≤⟨ +-mono-≤
(≤-respˡ-≃ (∣x-y∣≃∣y-x∣ (f N) x) (proj₂ (f→x (2 ℕ.* k)) N (ℕP.m≤m⊔n N₁ N₂)))
(proj₂ (f→y (2 ℕ.* k)) N (ℕP.m≤n⊔m N₁ N₂)) ⟩
(+ 1 / (2 ℕ.* k)) ⋆ + (+ 1 / (2 ℕ.* k)) ⋆ ≈⟨ ≃-trans
(≃-symm (⋆-distrib-+ (+ 1 / (2 ℕ.* k)) (+ 1 / (2 ℕ.* k))))
(⋆-cong (ℚ.*≡* (ℤsolve 1 (λ k ->
(ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k) :+ ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k)) :* k :=
ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k :* (ℤΚ (+ 2) :* k)))
refl (+ k)))) ⟩
(+ 1 / k) ⋆ ∎})
where open ≤-Reasoning
data _hasBound_ : REL (ℕ -> ℝ) ℝ 0ℓ where
bound* : {f : ℕ -> ℝ} -> {r : ℝ} -> (∀ n -> {n ≢0} -> ∣ f n ∣ ≤ r) -> f hasBound r
_isBounded : (ℕ -> ℝ) -> Set
f isBounded = ∃ λ r -> f hasBound r
{-
Taking the max over a sequence instead of over a list for convenience.
It seems to make it easier to take the max over a list of a variable length n, since I don't
think we can write x₁ :: x₂ :: ... :: xₙ :: nil in Agda.
For an example of this, see the convergent⇒bounded proof, particularly the part where M is defined.
-}
max : (ℕ -> ℝ) -> (n : ℕ) -> {n ≢0} -> ℝ
max f 1 = f 1
max f (suc (suc n-2)) = max f (suc n-2) ⊔ f (suc (suc n-2))
m≤n⇒maxfm≤maxfn : ∀ (f : ℕ -> ℝ) -> ∀ m n -> {m≢0 : m ≢0} -> {n≢0 : n ≢0} -> m ℕ.≤ n -> max f m {m≢0} ≤ max f n {n≢0}
m≤n⇒maxfm≤maxfn f (suc m-1) (suc n-1) m≤n with ≤⇒≡∨< (suc m-1) (suc n-1) m≤n
... | inj₁ refl = ≤-refl
... | inj₂ (ℕ.s≤s m-1<n-1) = ≤-trans (m≤n⇒maxfm≤maxfn f (suc m-1) n-1 {_} {n-1≢0} m-1<n-1) (lem n-1 {n-1≢0})
where
n-1≢0 : n-1 ≢0
n-1≢0 = 0<n⇒n≢0 n-1 (ℕP.<-transˡ (ℕP.0<1+n {m-1}) m-1<n-1)
lem : ∀ k -> {k≢0 : k ≢0} -> max f k {k≢0} ≤ max f (suc k)
lem 1 = x≤x⊔y (f 1) (f 2)
lem (suc (suc k-2)) = let k-1 = suc k-2; k = suc k-1; k+1 = suc k in
x≤x⊔y (max f k-1 ⊔ f k) (f k+1)
max-property : ∀ (f : ℕ -> ℝ) -> ∀ m n -> {m ≢0} -> {n≢0 : n ≢0} -> m ℕ.≤ n -> f m ≤ max f n {n≢0}
max-property f (suc m-1) (suc n-1) m≤n = ≤-trans (lem (suc m-1)) (m≤n⇒maxfm≤maxfn f (suc m-1) (suc n-1) m≤n)
where
lem : ∀ k -> {k≢0 : k ≢0} -> f k ≤ max f k {k≢0}
lem 1 = ≤-refl
lem (suc (suc k-2)) = x≤y⊔x (f (suc (suc k-2))) (max f (suc k-2))
convergent⇒bounded : ∀ {f : ℕ -> ℝ} -> f isConvergent -> f isBounded
convergent⇒bounded {f} (x₀ , con* f→x₀) = M , bound* (λ {(suc n-1) -> let n = suc n-1 in
[ (λ N≤n -> ≤-trans (lem n N≤n) (x≤y⊔x (1ℝ + ∣ x₀ ∣) (max ∣f∣ N))) ,
(λ n≤N -> ≤-trans (max-property ∣f∣ n N n≤N) (x≤x⊔y (max ∣f∣ N) (1ℝ + ∣ x₀ ∣))) ]′
(ℕP.≤-total N n)})
where
open ≤-Reasoning
∣f∣ = λ n -> ∣ f n ∣
N = suc (proj₁ (f→x₀ 1))
M = max ∣f∣ N ⊔ (1ℝ + ∣ x₀ ∣)
lem : ∀ n -> N ℕ.≤ n -> ∣ f n ∣ ≤ 1ℝ + ∣ x₀ ∣
lem (suc n-1) N≤n = let n = suc n-1 in begin
∣ f n ∣ ≈⟨ ∣-∣-cong (solve 2 (λ fn x₀ ->
fn ⊜ (fn ⊖ x₀ ⊕ x₀))
≃-refl (f n) x₀) ⟩
∣ f n - x₀ + x₀ ∣ ≤⟨ ∣x+y∣≤∣x∣+∣y∣ (f n - x₀) x₀ ⟩
∣ f n - x₀ ∣ + ∣ x₀ ∣ ≤⟨ +-monoˡ-≤ ∣ x₀ ∣ (proj₂ (f→x₀ 1) n N≤n) ⟩
1ℝ + ∣ x₀ ∣ ∎
data _isCauchy : (ℕ -> ℝ) -> Set where
cauchy* : {f : ℕ -> ℝ} ->
(∀ k -> {k≢0 : k ≢0} -> ∃ λ Mₖ-1 -> ∀ m n -> m ℕ.≥ suc Mₖ-1 -> n ℕ.≥ suc Mₖ-1 ->
∣ f m - f n ∣ ≤ (+ 1 / k) {k≢0} ⋆) -> f isCauchy
convergent⇒cauchy : ∀ {f : ℕ -> ℝ} -> f isConvergent -> f isCauchy
convergent⇒cauchy {f} (x₀ , con* f→x₀) = cauchy* (λ {(suc k-1) ->
let k = suc k-1; N₂ₖ = suc (proj₁ (f→x₀ (2 ℕ.* k))); Mₖ = suc N₂ₖ in
ℕ.pred Mₖ , λ {(suc m-1) (suc n-1) m≥Mₖ n≥Mₖ -> let m = suc m-1 ; n = suc n-1 in
begin
∣ f m - f n ∣ ≈⟨ ∣-∣-cong (solve 3 (λ fm fn x₀ ->
(fm ⊖ fn) ⊜ (fm ⊖ x₀ ⊕ (x₀ ⊖ fn)))
≃-refl (f m) (f n) x₀) ⟩
∣ f m - x₀ + (x₀ - f n) ∣ ≤⟨ ∣x+y∣≤∣x∣+∣y∣ (f m - x₀) (x₀ - f n) ⟩
∣ f m - x₀ ∣ + ∣ x₀ - f n ∣ ≤⟨ +-mono-≤
(proj₂ (f→x₀ (2 ℕ.* k)) m (ℕP.≤-trans (ℕP.n≤1+n N₂ₖ) m≥Mₖ))
(≤-respˡ-≃ (∣x-y∣≃∣y-x∣ (f n) x₀)
(proj₂ (f→x₀ (2 ℕ.* k)) n (ℕP.≤-trans (ℕP.n≤1+n N₂ₖ) n≥Mₖ))) ⟩
(+ 1 / (2 ℕ.* k)) ⋆ + (+ 1 / (2 ℕ.* k)) ⋆ ≈⟨ ≃-trans
(≃-symm (⋆-distrib-+ (+ 1 / (2 ℕ.* k)) (+ 1 / (2 ℕ.* k))))
(⋆-cong (ℚ.*≡* (ℤsolve 1 (λ k ->
(ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k) :+ ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k)) :* k :=
ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k :* (ℤΚ (+ 2) :* k)))
refl (+ k)))) ⟩
(+ 1 / k) ⋆ ∎}})
where open ≤-Reasoning
cauchy⇒convergent : ∀ {f : ℕ -> ℝ} -> f isCauchy -> f isConvergent
cauchy⇒convergent {f} (cauchy* fCauchy) = y , f→y
where
open ≤-Reasoning
N : ℕ -> ℕ
N k-1 = let k = suc k-1; M₂ₖ = suc (proj₁ (fCauchy (2 ℕ.* k))) in
suc ((3 ℕ.* k) ℕ.⊔ M₂ₖ)
Nₖ-prop : ∀ k-1 -> ∀ m n -> m ℕ.≥ N k-1 -> n ℕ.≥ N k-1 -> ∣ f m - f n ∣ ≤ (+ 1 / (2 ℕ.* (suc k-1))) ⋆
Nₖ-prop k-1 = λ {(suc m-1) (suc n-1) m≥N n≥N -> let k = suc k-1; m = suc m-1; n = suc n-1; M₂ₖ = suc (proj₁ (fCauchy (2 ℕ.* k))) in
proj₂ (fCauchy (2 ℕ.* k)) m n
(ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m (3 ℕ.* k) M₂ₖ) (ℕP.n≤1+n ((3 ℕ.* k) ℕ.⊔ M₂ₖ))) m≥N)
(ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m (3 ℕ.* k) M₂ₖ) (ℕP.n≤1+n ((3 ℕ.* k) ℕ.⊔ M₂ₖ))) n≥N)}
ys : (k : ℕ) -> {k ≢0} -> ℚᵘ
ys (suc k-1) = let k = suc k-1 in
seq (f (N k-1)) (2 ℕ.* k)
helper : ∀ k-1 -> (+ 1 / (2 ℕ.* (suc k-1))) ⋆ + (+ 1 / (2 ℕ.* (suc k-1))) ⋆ ≃ (+ 1 / (suc k-1)) ⋆
helper k-1 = let k = suc k-1 in begin-equality
(+ 1 / (2 ℕ.* k)) ⋆ + (+ 1 / (2 ℕ.* k)) ⋆ ≈⟨ ≃-symm (⋆-distrib-+ (+ 1 / (2 ℕ.* k)) (+ 1 / (2 ℕ.* k))) ⟩
(+ 1 / (2 ℕ.* k) ℚ.+ + 1 / (2 ℕ.* k)) ⋆ ≈⟨ ⋆-cong (ℚ.*≡* (ℤsolve 1 (λ k ->
(ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k) :+ (ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k))) :* k :=
ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k :* (ℤΚ (+ 2) :* k)))
refl (+ k))) ⟩
(+ 1 / k) ⋆ ∎
helper2 : ∀ m-1 n-1 -> ∣ f (N m-1) - f (N n-1) ∣ ≤ (+ 1 / (2 ℕ.* (suc m-1)) ℚ.+ + 1 / (2 ℕ.* (suc n-1))) ⋆
helper2 m-1 n-1 = [ left , right ]′ (ℕP.≤-total (N m-1) (N n-1))
where
m = suc m-1
n = suc n-1
left : N m-1 ℕ.≤ N n-1 -> ∣ f (N m-1) - f (N n-1) ∣ ≤ (+ 1 / (2 ℕ.* m) ℚ.+ + 1 / (2 ℕ.* n)) ⋆
left Nₘ≤Nₙ = begin
∣ f (N m-1) - f (N n-1) ∣ ≤⟨ Nₖ-prop m-1 (N m-1) (N n-1) ℕP.≤-refl Nₘ≤Nₙ ⟩
(+ 1 / (2 ℕ.* m)) ⋆ ≤⟨ p≤q⇒p⋆≤q⋆ (+ 1 / (2 ℕ.* m)) (+ 1 / (2 ℕ.* m) ℚ.+ + 1 / (2 ℕ.* n))
(ℚP.≤-respˡ-≃ (ℚP.+-identityʳ (+ 1 / (2 ℕ.* m)))
(ℚP.+-monoʳ-≤ (+ 1 / (2 ℕ.* m)) {0ℚᵘ} {+ 1 / (2 ℕ.* n)} (ℚP.nonNegative⁻¹ _))) ⟩
(+ 1 / (2 ℕ.* m) ℚ.+ + 1 / (2 ℕ.* n)) ⋆ ∎
right : N n-1 ℕ.≤ N m-1 -> ∣ f (N m-1) - f (N n-1) ∣ ≤ (+ 1 / (2 ℕ.* m) ℚ.+ + 1 / (2 ℕ.* n)) ⋆
right Nₙ≤Nₘ = begin
∣ f (N m-1) - f (N n-1) ∣ ≈⟨ ∣x-y∣≃∣y-x∣ (f (N m-1)) (f (N n-1)) ⟩
∣ f (N n-1) - f (N m-1) ∣ ≤⟨ Nₖ-prop n-1 (N n-1) (N m-1) ℕP.≤-refl Nₙ≤Nₘ ⟩
(+ 1 / (2 ℕ.* n)) ⋆ ≤⟨ p≤q⇒p⋆≤q⋆ (+ 1 / (2 ℕ.* n)) (+ 1 / (2 ℕ.* m) ℚ.+ + 1 / (2 ℕ.* n))
(ℚP.≤-respˡ-≃ (ℚP.+-identityˡ (+ 1 / (2 ℕ.* n)))
(ℚP.+-monoˡ-≤ (+ 1 / (2 ℕ.* n)) {0ℚᵘ} {+ 1 / (2 ℕ.* m)} (ℚP.nonNegative⁻¹ _))) ⟩
(+ 1 / (2 ℕ.* m) ℚ.+ + 1 / (2 ℕ.* n)) ⋆ ∎
y : ℝ
seq y 0 = 0ℚᵘ
seq y (suc k-1) = ys (suc k-1)
reg y = regular-n≤m (seq y) (λ {(suc m-1) (suc n-1) n≤m -> let m = suc m-1; n = suc n-1 in
p⋆≤q⋆⇒p≤q ℚ.∣ ys m ℚ.- ys n ∣ (+ 1 / m ℚ.+ + 1 / n) (begin
ℚ.∣ ys m ℚ.- ys n ∣ ⋆ ≈⟨ ≃-trans
(∣p∣⋆≃∣p⋆∣ (ys m ℚ.- ys n))
(∣-∣-cong (⋆-distrib-to-p⋆-q⋆ (ys m) (ys n))) ⟩
∣ ys m ⋆ - ys n ⋆ ∣ ≈⟨ ∣-∣-cong (solve 4 (λ yₘ yₙ fm-1 fn-1 ->
yₘ ⊖ yₙ ⊜ yₘ ⊖ fm-1 ⊕ (fm-1 ⊖ fn-1) ⊕ (fn-1 ⊖ yₙ))
≃-refl (ys m ⋆) (ys n ⋆) (f (N m-1)) (f (N n-1))) ⟩
∣ (ys m ⋆ - f (N m-1)) + (f (N m-1) - f (N n-1))
+ (f (N n-1) - ys n ⋆) ∣ ≤⟨ ≤-trans
(∣x+y∣≤∣x∣+∣y∣ ((ys m ⋆ - f (N m-1)) + (f (N m-1) - f (N n-1))) (f (N n-1) - ys n ⋆))
(+-monoˡ-≤ ∣ f (N n-1) - ys n ⋆ ∣ (∣x+y∣≤∣x∣+∣y∣ (ys m ⋆ - f (N m-1)) (f (N m-1) - f (N n-1)))) ⟩
∣ ys m ⋆ - f (N m-1) ∣ + ∣ f (N m-1) - f (N n-1) ∣
+ ∣ f (N n-1) - ys n ⋆ ∣ ≤⟨ +-mono-≤
(+-mono-≤ (≤-respˡ-≃ (∣x-y∣≃∣y-x∣ (f (N m-1)) (ys m ⋆)) (lemma-2-14 (f (N m-1)) (2 ℕ.* m)))
(≤-respʳ-≃ (⋆-distrib-+ (+ 1 / (2 ℕ.* m)) (+ 1 / (2 ℕ.* n))) (helper2 m-1 n-1)))
(lemma-2-14 (f (N n-1)) (2 ℕ.* n)) ⟩
(+ 1 / (2 ℕ.* m)) ⋆ + ((+ 1 / (2 ℕ.* m)) ⋆
+ (+ 1 / (2 ℕ.* n)) ⋆) + (+ 1 / (2 ℕ.* n)) ⋆ ≈⟨ solve 2 (λ m n -> (m ⊕ (m ⊕ n) ⊕ n) ⊜ ((m ⊕ m) ⊕ (n ⊕ n)))
≃-refl ((+ 1 / (2 ℕ.* m)) ⋆) ((+ 1 / (2 ℕ.* n)) ⋆) ⟩
(+ 1 / (2 ℕ.* m)) ⋆ + (+ 1 / (2 ℕ.* m)) ⋆
+ ((+ 1 / (2 ℕ.* n)) ⋆ + (+ 1 / (2 ℕ.* n)) ⋆) ≈⟨ +-cong (helper m-1) (helper n-1) ⟩
(+ 1 / m) ⋆ + (+ 1 / n) ⋆ ≈⟨ ≃-symm (⋆-distrib-+ (+ 1 / m) (+ 1 / n)) ⟩
(+ 1 / m ℚ.+ + 1 / n) ⋆ ∎)})
f→y : f ConvergesTo y
f→y = con* (λ {(suc k-1) -> ℕ.pred (N k-1) ,
λ {(suc n-1) n≥Nₖ -> let k = suc k-1; n = suc n-1
; n≥3k = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n (3 ℕ.* k) (suc (proj₁ (fCauchy (2 ℕ.* k))))) (ℕP.n≤1+n (ℕ.pred (N k-1)))) n≥Nₖ in begin
∣ f n - y ∣ ≈⟨ ∣-∣-cong (solve 4 (λ fn y yₙ fn-1 ->
fn ⊖ y ⊜ yₙ ⊖ y ⊕ (fn-1 ⊖ yₙ) ⊕ (fn ⊖ fn-1))
≃-refl (f n) y (ys n ⋆) (f (N n-1))) ⟩
∣ (ys n ⋆ - y) + (f (N n-1) - ys n ⋆) + (f n - f (N n-1)) ∣ ≤⟨ ≤-trans
(∣x+y∣≤∣x∣+∣y∣ ((ys n ⋆ - y) + (f (N n-1) - ys n ⋆)) (f n - f (N n-1)))
(+-monoˡ-≤ ∣ f n - f (N n-1) ∣ (∣x+y∣≤∣x∣+∣y∣ (ys n ⋆ - y) (f (N n-1) - ys n ⋆))) ⟩
∣ ys n ⋆ - y ∣ + ∣ f (N n-1) - ys n ⋆ ∣ + ∣ f n - f (N n-1) ∣ ≤⟨ +-mono-≤ (+-mono-≤
(≤-respˡ-≃ (∣x-y∣≃∣y-x∣ y (ys n ⋆)) (lemma-2-14 y n))
(lemma-2-14 (f (N n-1)) (2 ℕ.* n)))
(Nₖ-prop k-1 n (N n-1) n≥Nₖ
(ℕP.≤-trans (ℕP.≤-trans n≥Nₖ (ℕP.m≤n*m n {3} ℕP.0<1+n))
(ℕP.≤-trans (ℕP.m≤m⊔n (3 ℕ.* n) (suc (proj₁ (fCauchy (2 ℕ.* n)))))
(ℕP.n≤1+n (ℕ.pred (N n-1)))))) ⟩
(+ 1 / n) ⋆ + (+ 1 / (2 ℕ.* n)) ⋆ + (+ 1 / (2 ℕ.* k)) ⋆ ≈⟨ solve 0
(Κ (+ 1 / n) ⊕ Κ (+ 1 / (2 ℕ.* n)) ⊕ Κ (+ 1 / (2 ℕ.* k)) ⊜
Κ (+ 1 / n ℚ.+ + 1 / (2 ℕ.* n) ℚ.+ + 1 / (2 ℕ.* k)))
≃-refl ⟩
(+ 1 / n ℚ.+ + 1 / (2 ℕ.* n) ℚ.+ + 1 / (2 ℕ.* k)) ⋆ ≤⟨ p≤q⇒p⋆≤q⋆ _ _
(ℚP.+-monoˡ-≤ (+ 1 / (2 ℕ.* k)) (ℚP.+-mono-≤
(q≤r⇒+p/r≤+p/q 1 (3 ℕ.* k) n n≥3k)
(q≤r⇒+p/r≤+p/q 1 (2 ℕ.* (3 ℕ.* k)) (2 ℕ.* n) (ℕP.*-monoʳ-≤ 2 n≥3k)))) ⟩
(+ 1 / (3 ℕ.* k) ℚ.+ + 1 / (2 ℕ.* (3 ℕ.* k)) ℚ.+ + 1 / (2 ℕ.* k)) ⋆ ≈⟨ ⋆-cong (ℚ.*≡* (ℤsolve 1 (λ k ->
((ℤΚ (+ 1) :* (ℤΚ (+ 2) :* (ℤΚ (+ 3) :* k)) :+
ℤΚ (+ 1) :* (ℤΚ (+ 3) :* k)) :* (ℤΚ (+ 2) :* k) :+
(ℤΚ (+ 1) :* (ℤΚ (+ 3) :* k :* (ℤΚ (+ 2) :* (ℤΚ (+ 3) :* k))))) :* k :=
ℤΚ (+ 1) :* ((ℤΚ (+ 3) :* k :* (ℤΚ (+ 2) :* (ℤΚ (+ 3) :* k))) :* (ℤΚ (+ 2) :* k)))
refl (+ k))) ⟩
(+ 1 / k) ⋆ ∎}})
abstract
fast-convergent⇒cauchy : ∀ {f : ℕ -> ℝ} -> f isConvergent -> f isCauchy
fast-convergent⇒cauchy = convergent⇒cauchy
fast-cauchy⇒convergent : ∀ {f : ℕ -> ℝ} -> f isCauchy -> f isConvergent
fast-cauchy⇒convergent = cauchy⇒convergent
xₙ+yₙ→x₀+y₀ : ∀ {xs ys : ℕ -> ℝ} -> (xₙ→x₀ : xs isConvergent) -> (yₙ→y₀ : ys isConvergent) ->
(λ n -> xs n + ys n) ConvergesTo (proj₁ xₙ→x₀ + proj₁ yₙ→y₀)
xₙ+yₙ→x₀+y₀ {xs} {ys} (x₀ , con* xₙ→x₀) (y₀ , con* yₙ→y₀) = con* (λ {(suc k-1) ->
let k = suc k-1; N₁ = suc (proj₁ (xₙ→x₀ (2 ℕ.* k))); N₂ = suc (proj₁ (yₙ→y₀ (2 ℕ.* k))); N = N₁ ℕ.⊔ N₂ in
ℕ.pred N , λ {(suc n-1) N≤n -> let n = suc n-1; xₙ = xs n; yₙ = ys n in begin
∣ xₙ + yₙ - (x₀ + y₀) ∣ ≈⟨ ∣-∣-cong (solve 4 (λ xₙ yₙ x₀ y₀ ->
xₙ ⊕ yₙ ⊖ (x₀ ⊕ y₀) ⊜ xₙ ⊖ x₀ ⊕ (yₙ ⊖ y₀))
≃-refl xₙ yₙ x₀ y₀) ⟩
∣ xₙ - x₀ + (yₙ - y₀) ∣ ≤⟨ ∣x+y∣≤∣x∣+∣y∣ (xₙ - x₀) (yₙ - y₀) ⟩
∣ xₙ - x₀ ∣ + ∣ yₙ - y₀ ∣ ≤⟨ +-mono-≤
(proj₂ (xₙ→x₀ (2 ℕ.* k)) n (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) N≤n))
(proj₂ (yₙ→y₀ (2 ℕ.* k)) n (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) N≤n)) ⟩
(+ 1 / (2 ℕ.* k)) ⋆ + (+ 1 / (2 ℕ.* k)) ⋆ ≈⟨ ≃-trans
(≃-symm (⋆-distrib-+ (+ 1 / (2 ℕ.* k)) (+ 1 / (2 ℕ.* k))))
(⋆-cong (ℚ.*≡* (ℤsolve 1 (λ k ->
(ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k) :+ ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k)) :* k :=
ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k :* (ℤΚ (+ 2) :* k)))
refl (+ k)))) ⟩
(+ 1 / k) ⋆ ∎}})
where open ≤-Reasoning
x≤Kx : ∀ x -> x ≤ (+ K x / 1) ⋆
x≤Kx x = nonNeg* (λ {(suc n-1) -> let n = suc n-1 in begin
ℚ.- (+ 1 / n) <⟨ ℚP.negative⁻¹ _ ⟩
0ℚᵘ <⟨ p<q⇒0<q-p ℚ.∣ seq x (2 ℕ.* n) ∣ (+ K x / 1)
(canonical-strict-upper-bound x (2 ℕ.* n)) ⟩
+ K x / 1 ℚ.- ℚ.∣ seq x (2 ℕ.* n) ∣ ≤⟨ ℚP.+-monoʳ-≤ (+ K x / 1) (
ℚP.neg-mono-≤ (p≤∣p∣ (seq x (2 ℕ.* n)))) ⟩
+ K x / 1 ℚ.- seq x (2 ℕ.* n) ∎})
where open ℚP.≤-Reasoning
-- The Archimedean property
archimedean-ℝ : ∀ x -> ∃ λ (n-1 : ℕ) -> (+ (suc n-1) / 1) ⋆ > x
archimedean-ℝ x = K x , (begin-strict
x <⟨ <-respˡ-≃ (+-identityˡ x)
(+-monoˡ-< x (p<q⇒p⋆<q⋆ 0ℚᵘ 1ℚᵘ (ℚ.*<* (ℤ.+<+ ℕP.0<1+n)))) ⟩
1ℝ + x ≤⟨ +-monoʳ-≤ 1ℝ (x≤Kx x) ⟩
1ℝ + (+ K x / 1) ⋆ ≈⟨ ≃-trans
(≃-symm (⋆-distrib-+ 1ℚᵘ (+ K x / 1)))
(⋆-cong (ℚP.≃-reflexive (ℚP./-cong (cong (λ r -> + 1 ℤ.+ r)
(ℤP.*-identityʳ (+ K x))) refl _ _))) ⟩
(+ (suc (K x)) / 1) ⋆ ∎)
where open ≤-Reasoning
abstract
fast-archimedean-ℝ : ∀ x -> ∃ λ (n-1 : ℕ) -> (+ (suc n-1) / 1) ⋆ > x
fast-archimedean-ℝ = archimedean-ℝ
bound⇒boundℕ : ∀ {f : ℕ -> ℝ} -> f isBounded ->
∃ λ (M-1 : ℕ) -> ∀ (n : ℕ) -> {n ≢0} -> ∣ f n ∣ < (+ suc (M-1) / 1) ⋆
bound⇒boundℕ {f} (r , (bound* ∣f∣≤r)) = let M = suc (proj₁ (archimedean-ℝ r)) in
ℕ.pred M , λ {(suc n-1) -> let n = suc n-1 in begin-strict
∣ f n ∣ ≤⟨ ∣f∣≤r n ⟩
r <⟨ proj₂ (archimedean-ℝ r) ⟩
(+ M / 1) ⋆ ∎}
where open ≤-Reasoning
*-mono-≤ : ∀ {x y z w} -> NonNegative x -> NonNegative z -> x ≤ y -> z ≤ w -> x * z ≤ y * w
*-mono-≤ {x} {y} {z} {w} nonx nonz x≤y z≤w = begin
x * z ≤⟨ *-monoˡ-≤-nonNeg z≤w nonx ⟩
x * w ≤⟨ *-monoʳ-≤-nonNeg x≤y (0≤x⇒nonNegx (≤-trans (nonNegx⇒0≤x nonz) z≤w)) ⟩
y * w ∎
where open ≤-Reasoning
-xₙ→-x₀ : ∀ {xs : ℕ -> ℝ} -> (x→x₀ : xs isConvergent) -> (λ n -> - xs n) ConvergesTo (- (proj₁ x→x₀))
-xₙ→-x₀ {xs} (x₀ , con* x→x₀) = con* (λ {(suc k-1) -> let k = suc k-1 in
proj₁ (x→x₀ k) , λ {(suc n-1) n≥N -> let n = suc n-1 in begin
∣ - xs n - (- x₀) ∣ ≈⟨ ∣-∣-cong (solve 2 (λ xₙ x₀ ->
⊝ xₙ ⊖ (⊝ x₀) ⊜ ⊝ (xₙ ⊖ x₀))
≃-refl (xs n) x₀) ⟩
∣ - (xs n - x₀) ∣ ≈⟨ ∣-x∣≃∣x∣ ⟩
∣ xs n - x₀ ∣ ≤⟨ proj₂ (x→x₀ k) n n≥N ⟩
(+ 1 / k) ⋆ ∎}})
where open ≤-Reasoning
xₙyₙ→x₀y₀ : ∀ {xs ys : ℕ -> ℝ} -> (xₙ→x₀ : xs isConvergent) -> (yₙ→y₀ : ys isConvergent) ->
(λ n -> (xs n * ys n)) ConvergesTo (proj₁ xₙ→x₀ * proj₁ yₙ→y₀)
xₙyₙ→x₀y₀ {xs} {ys} (x₀ , con* xₙ→x₀) (y₀ , con* yₙ→y₀) = con* (λ {(suc k-1) ->
let k = suc k-1; archy₀ = archimedean-ℝ ∣ y₀ ∣; N₁ = suc (proj₁ archy₀); boundxₙ = bound⇒boundℕ (convergent⇒bounded (x₀ , con* xₙ→x₀))
; N₂ = suc (proj₁ boundxₙ); m = N₁ ℕ.⊔ N₂; M₁ = suc (proj₁ (xₙ→x₀ (2 ℕ.* m ℕ.* k))); M₂ = suc (proj₁ (yₙ→y₀ (2 ℕ.* m ℕ.* k)))
; Mₖ = M₁ ℕ.⊔ M₂ in ℕ.pred Mₖ , λ {(suc n-1) n≥Mₖ -> let n = suc n-1; xₙ = xs (suc n-1); yₙ = ys (suc n-1) in begin
∣ xₙ * yₙ - x₀ * y₀ ∣ ≈⟨ ∣-∣-cong (solve 4 (λ xₙ yₙ x₀ y₀ ->
xₙ ⊗ yₙ ⊖ x₀ ⊗ y₀ ⊜ xₙ ⊗ yₙ ⊕ xₙ ⊗ (⊝ y₀) ⊕ (xₙ ⊗ y₀ ⊖ x₀ ⊗ y₀))
≃-refl xₙ yₙ x₀ y₀) ⟩
∣ xₙ * yₙ + xₙ * (- y₀) + (xₙ * y₀ - x₀ * y₀) ∣ ≤⟨ ∣x+y∣≤∣x∣+∣y∣ (xₙ * yₙ + xₙ * (- y₀)) (xₙ * y₀ - x₀ * y₀) ⟩
∣ xₙ * yₙ + xₙ * (- y₀) ∣ + ∣ xₙ * y₀ - x₀ * y₀ ∣ ≈⟨ ≃-symm (+-cong
(∣-∣-cong (*-distribˡ-+ xₙ yₙ (- y₀)))
(∣-∣-cong (solve 3 (λ xₙ x₀ y₀ ->
(xₙ ⊖ x₀) ⊗ y₀ ⊜ xₙ ⊗ y₀ ⊖ x₀ ⊗ y₀)
≃-refl xₙ x₀ y₀))) ⟩
∣ xₙ * (yₙ - y₀) ∣ + ∣ (xₙ - x₀) * y₀ ∣ ≈⟨ +-cong
(∣x*y∣≃∣x∣*∣y∣ xₙ (yₙ - y₀))
(≃-trans (∣x*y∣≃∣x∣*∣y∣ (xₙ - x₀) y₀) (*-comm ∣ xₙ - x₀ ∣ ∣ y₀ ∣)) ⟩
∣ xₙ ∣ * ∣ yₙ - y₀ ∣ + ∣ y₀ ∣ * ∣ xₙ - x₀ ∣ ≤⟨ +-mono-≤ {∣ xₙ ∣ * ∣ yₙ - y₀ ∣} {(+ m / 1) ⋆ * (+ 1 / (2 ℕ.* m ℕ.* k)) ⋆}
{∣ y₀ ∣ * ∣ xₙ - x₀ ∣} {(+ m / 1) ⋆ * (+ 1 / (2 ℕ.* m ℕ.* k)) ⋆}
(*-mono-≤ {∣ xₙ ∣} {(+ m / 1) ⋆} {∣ yₙ - y₀ ∣} {(+ 1 / (2 ℕ.* m ℕ.* k)) ⋆}
(nonNeg∣x∣ xₙ) (nonNeg∣x∣ (yₙ - y₀))
(<⇒≤ (<-≤-trans (proj₂ boundxₙ n) (p≤q⇒p⋆≤q⋆ (+ N₂ / 1) (+ m / 1)
(p≤q⇒p/r≤q/r (+ N₂) (+ m) 1 (ℤ.+≤+ (ℕP.m≤n⊔m N₁ N₂))))))
(proj₂ (yₙ→y₀ (2 ℕ.* m ℕ.* k)) n (ℕP.≤-trans (ℕP.m≤n⊔m M₁ M₂) n≥Mₖ)))
(*-mono-≤ {∣ y₀ ∣} {(+ m / 1) ⋆} {∣ xₙ - x₀ ∣} {(+ 1 / (2 ℕ.* m ℕ.* k)) ⋆}
(nonNeg∣x∣ y₀) (nonNeg∣x∣ (xₙ - x₀))
(<⇒≤ (<-≤-trans (proj₂ archy₀) (p≤q⇒p⋆≤q⋆ (+ N₁ / 1) (+ m / 1)
(p≤q⇒p/r≤q/r (+ N₁) (+ m) 1 (ℤ.+≤+ (ℕP.m≤m⊔n N₁ N₂))))))
(proj₂ (xₙ→x₀ (2 ℕ.* m ℕ.* k)) n (ℕP.≤-trans (ℕP.m≤m⊔n M₁ M₂) n≥Mₖ))) ⟩
(+ m / 1) ⋆ * (+ 1 / (2 ℕ.* m ℕ.* k)) ⋆ +
(+ m / 1) ⋆ * (+ 1 / (2 ℕ.* m ℕ.* k)) ⋆ ≈⟨ solve 2 (λ a b ->
a ⊗ b ⊕ a ⊗ b ⊜ a ⊗ (b ⊕ b))
≃-refl ((+ m / 1) ⋆) ((+ 1 / (2 ℕ.* m ℕ.* k)) ⋆) ⟩
(+ m / 1) ⋆ * ((+ 1 / (2 ℕ.* m ℕ.* k)) ⋆ +
(+ 1 / (2 ℕ.* m ℕ.* k)) ⋆) ≈⟨ solve 0
(Κ (+ m / 1) ⊗ (Κ (+ 1 / (2 ℕ.* m ℕ.* k)) ⊕ Κ (+ 1 / (2 ℕ.* m ℕ.* k))) ⊜
Κ (+ m / 1 ℚ.* (+ 1 / (2 ℕ.* m ℕ.* k) ℚ.+ + 1 / (2 ℕ.* m ℕ.* k))))
≃-refl ⟩
(+ m / 1 ℚ.* (+ 1 / (2 ℕ.* m ℕ.* k) ℚ.+
+ 1 / (2 ℕ.* m ℕ.* k))) ⋆ ≈⟨ ⋆-cong (ℚ.*≡* (ℤsolve 2 (λ m k ->
(m :* (ℤΚ (+ 1) :* (ℤΚ (+ 2) :* m :* k) :+ ℤΚ (+ 1) :* (ℤΚ (+ 2) :* m :* k))) :* k :=
ℤΚ (+ 1) :* (ℤΚ (+ 1) :* (ℤΚ (+ 2) :* m :* k :* (ℤΚ (+ 2) :* m :* k))))
refl (+ m) (+ k))) ⟩
(+ 1 / k) ⋆ ∎}})
where open ≤-Reasoning
xₙ≃c⇒xₙ→c : ∀ {xs : ℕ -> ℝ} -> ∀ {c : ℝ} -> (∀ n -> {n ≢0} -> xs n ≃ c) -> xs ConvergesTo c
xₙ≃c⇒xₙ→c {xs} {c} hyp = con* (λ {(suc k-1) -> let k = suc k-1 in 0 , λ {(suc n-1) n≥1 -> let n = suc n-1 in begin
∣ xs n - c ∣ ≈⟨ ∣-∣-cong (+-congˡ (- c) (hyp n)) ⟩
∣ c - c ∣ ≈⟨ ≃-trans (∣-∣-cong (+-inverseʳ c)) (≃-reflexive (λ n -> ℚP.≃-refl)) ⟩
0ℝ ≤⟨ p≤q⇒p⋆≤q⋆ 0ℚᵘ (+ 1 / k) (ℚP.nonNegative⁻¹ _) ⟩
(+ 1 / k) ⋆ ∎}})
where open ≤-Reasoning
x<y∧posx,y⇒y⁻¹<x⁻¹ : ∀ {x y} -> x < y -> (x≄0 : x ≄0) -> (y≄0 : y ≄0) -> Positive x -> Positive y ->
(y ⁻¹) y≄0 < (x ⁻¹) x≄0
x<y∧posx,y⇒y⁻¹<x⁻¹ {x} {y} x<y x≄0 y≄0 posx posy = let x⁻¹ = (x ⁻¹) x≄0; y⁻¹ = (y ⁻¹) y≄0 in
begin-strict
y⁻¹ ≈⟨ ≃-symm (≃-trans (*-congʳ (*-inverseʳ x x≄0)) (*-identityˡ y⁻¹)) ⟩
x * x⁻¹ * y⁻¹ <⟨ *-monoˡ-<-pos {y⁻¹} (posx⇒posx⁻¹ {y} y≄0 posy)
(*-monoˡ-<-pos {x⁻¹} (posx⇒posx⁻¹ {x} x≄0 posx) x<y) ⟩
y * x⁻¹ * y⁻¹ ≈⟨ ≃-trans (*-congʳ (*-comm y x⁻¹)) (*-assoc x⁻¹ y y⁻¹) ⟩
x⁻¹ * (y * y⁻¹) ≈⟨ ≃-trans (*-congˡ (*-inverseʳ y y≄0)) (*-identityʳ x⁻¹) ⟩
x⁻¹ ∎
where open ≤-Reasoning
<⇒≱ : _<_ ⇒ _≱_
<⇒≱ {x} {y} (pos* (n-1 , x<y)) (nonNeg* x≥y) = let n = suc n-1 in ℚP.<-irrefl-≡ refl (begin-strict
+ 1 / n <⟨ x<y ⟩
seq y (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ≈⟨ ℚsolve 2 (λ x₂ₙ y₂ₙ ->
y₂ₙ -: x₂ₙ =: -: (x₂ₙ -: y₂ₙ))
ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)) ⟩
ℚ.- (seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n)) ≤⟨ ℚP.neg-mono-≤ (x≥y n) ⟩
ℚ.- (ℚ.- (+ 1 / n)) ≈⟨ ℚP.neg-involutive (+ 1 / n) ⟩
+ 1 / n ∎)
where open ℚP.≤-Reasoning
<-irrefl : Irreflexive _≃_ _<_
<-irrefl {x} {y} (*≃* x≃y) (pos* (n-1 , x<y)) = let n = suc n-1 in ℚP.<-irrefl ℚP.≃-refl (begin-strict
+ 1 / n <⟨ x<y ⟩
seq y (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ≤⟨ p≤∣p∣ (seq y (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n)) ⟩
ℚ.∣ seq y (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ∣ ≈⟨ ∣p-q∣≃∣q-p∣ (seq y (2 ℕ.* n)) (seq x (2 ℕ.* n)) ⟩
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ≤⟨ x≃y (2 ℕ.* n) ⟩
+ 2 / (2 ℕ.* n) ≈⟨ ℚ.*≡* (sym (ℤP.*-identityˡ (+ 2 ℤ.* + n))) ⟩
+ 1 / n ∎)
where open ℚP.≤-Reasoning
p⋆≄0⇒∣↥p∣≢0 : ∀ p -> (p ⋆) ≄0 -> ℤ.∣ ↥ p ∣ ≢0
p⋆≄0⇒∣↥p∣≢0 (mkℚᵘ (+_ zero) d-1) (inj₁ p⋆<0) = let d = suc d-1 in <-irrefl (≃-reflexive (λ {(suc n-1) -> ℚ.*≡* (sym (ℤP.*-zeroˡ (+ d)))})) p⋆<0
p⋆≄0⇒∣↥p∣≢0 (mkℚᵘ +[1+ n ] denominator-2) (inj₁ p⋆<0) = _
p⋆≄0⇒∣↥p∣≢0 (mkℚᵘ (-[1+_] n) denominator-2) (inj₁ p⋆<0) = _
p⋆≄0⇒∣↥p∣≢0 (mkℚᵘ (+_ zero) d-1) (inj₂ 0<p⋆) = let d = suc d-1 in <-irrefl (≃-reflexive (λ {(suc n-1) -> ℚ.*≡* (ℤP.*-zeroˡ (+ d))})) 0<p⋆
p⋆≄0⇒∣↥p∣≢0 (mkℚᵘ +[1+ n ] denominator-2) (inj₂ 0<p⋆) = _
p⋆≄0⇒∣↥p∣≢0 (mkℚᵘ (-[1+_] n) denominator-2) (inj₂ 0<p⋆) = _
∣↥p∣≢0⇒p⋆≄0 : ∀ p -> ℤ.∣ ↥ p ∣ ≢0 -> (p ⋆) ≄0
∣↥p∣≢0⇒p⋆≄0 (mkℚᵘ +[1+ n ] d-1) ∣↥p∣≢0 = inj₂ (p<q⇒p⋆<q⋆ 0ℚᵘ (+[1+ n ] / (suc d-1)) (ℚP.positive⁻¹ _))
∣↥p∣≢0⇒p⋆≄0 (mkℚᵘ (-[1+_] n) d-1) ∣↥p∣≢0 = inj₁ (p<q⇒p⋆<q⋆ (-[1+_] n / (suc d-1)) 0ℚᵘ (ℚP.negative⁻¹ _))
⁻¹-involutive : ∀ {x} -> (x≄0 : x ≄0) -> (x⁻¹≄0 : (x ⁻¹) x≄0 ≄0) ->
(((x ⁻¹) x≄0) ⁻¹) x⁻¹≄0 ≃ x
⁻¹-involutive {x} x≄0 x⁻¹≄0 = let x⁻¹ = (x ⁻¹) x≄0 in ≃-symm (⁻¹-unique x x⁻¹ x⁻¹≄0 (*-inverseʳ x x≄0))
⁻¹-involutive-default : ∀ {x} -> (x≄0 : x ≄0) ->
(((x ⁻¹) x≄0) ⁻¹) ([ (λ x<0 -> inj₁ (x<0⇒x⁻¹<0 {x} x≄0 x<0)) , (λ 0<x -> inj₂ (0<x⇒0<x⁻¹ {x} x≄0 0<x))]′ x≄0) ≃ x
⁻¹-involutive-default {x} x≄0 = ⁻¹-involutive {x} x≄0 ([ (λ x<0 -> inj₁ (x<0⇒x⁻¹<0 {x} x≄0 x<0)) , (λ 0<x -> inj₂ (0<x⇒0<x⁻¹ {x} x≄0 0<x))]′ x≄0)
⋆-distrib-⁻¹ : ∀ p -> (p⋆≄0 : (p ⋆) ≄0) -> ((p ⋆) ⁻¹) p⋆≄0 ≃ ((ℚ.1/ p) {p⋆≄0⇒∣↥p∣≢0 p p⋆≄0}) ⋆
⋆-distrib-⁻¹ p p⋆≄0 = let p⁻¹ = (ℚ.1/ p) {p⋆≄0⇒∣↥p∣≢0 p p⋆≄0}; p⋆⁻¹ = ((p ⋆) ⁻¹) p⋆≄0 in
≃-symm (⁻¹-unique (p⁻¹ ⋆) (p ⋆) p⋆≄0 (begin
p⁻¹ ⋆ * p ⋆ ≈⟨ ≃-symm (⋆-distrib-* p⁻¹ p) ⟩
(p⁻¹ ℚ.* p) ⋆ ≈⟨ ⋆-cong (ℚP.*-inverseˡ p {p⋆≄0⇒∣↥p∣≢0 p p⋆≄0}) ⟩
1ℝ ∎))
where open ≃-Reasoning
0≤y-x⇒x≤y : ∀ {x y} -> 0ℝ ≤ y - x -> x ≤ y
0≤y-x⇒x≤y {x} {y} 0≤y-x = nonNeg-cong (≃-trans (+-congʳ (y - x) (≃-symm 0≃-0)) (+-identityʳ (y - x))) 0≤y-x
x≤z∧y≤z⇒x⊔y≤z : ∀ {x y z} -> x ≤ z -> y ≤ z -> x ⊔ y ≤ z
x≤z∧y≤z⇒x⊔y≤z {x} {y} {z} x≤z y≤z = lemma-2-8-2-onlyif lem
where
open ℚP.≤-Reasoning
lem : ∀ n -> {n≢0 : n ≢0} -> ∃ λ Nₙ -> Nₙ ≢0 × (∀ m -> m ℕ.≥ Nₙ -> seq (z - (x ⊔ y)) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})
lem (suc n-1) = N , _ , λ {(suc m-1) m≥N -> let m = suc m-1 in
[ left m m≥N , right m m≥N ]′ (ℚP.≤-total (seq y (2 ℕ.* m)) (seq x (2 ℕ.* m)))}
where
n = suc n-1
fromx≤z = fast-lemma-2-8-2-if x≤z n
fromy≤z = fast-lemma-2-8-2-if y≤z n
N₁ = proj₁ fromx≤z
N₂ = proj₁ fromy≤z
N = suc (N₁ ℕ.⊔ N₂)
left : ∀ m -> m ℕ.≥ N -> seq y (2 ℕ.* m) ℚ.≤ seq x (2 ℕ.* m) ->
seq (z - (x ⊔ y)) m ℚ.≥ ℚ.- (+ 1 / n)
left (suc m-1) m≥N y₂ₘ≤x₂ₘ = let m = suc m-1 in begin
ℚ.- (+ 1 / n) ≤⟨ proj₂ (proj₂ fromx≤z) m
(ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.n≤1+n (N₁ ℕ.⊔ N₂))) m≥N) ⟩
seq z (2 ℕ.* m) ℚ.- seq x (2 ℕ.* m) ≈⟨ ℚP.+-congʳ (seq z (2 ℕ.* m))
(ℚP.-‿cong (ℚP.≃-sym (ℚP.p≥q⇒p⊔q≃p y₂ₘ≤x₂ₘ))) ⟩
seq z (2 ℕ.* m) ℚ.- seq (x ⊔ y) (2 ℕ.* m) ∎
right : ∀ m -> m ℕ.≥ N -> seq x (2 ℕ.* m) ℚ.≤ seq y (2 ℕ.* m) ->
seq (z - (x ⊔ y)) m ℚ.≥ ℚ.- (+ 1 / n)
right (suc m-1) m≥N x₂ₘ≤y₂ₘ = let m = suc m-1 in begin
ℚ.- (+ 1 / n) ≤⟨ proj₂ (proj₂ fromy≤z) m
(ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.n≤1+n (N₁ ℕ.⊔ N₂))) m≥N) ⟩
seq z (2 ℕ.* m) ℚ.- seq y (2 ℕ.* m) ≈⟨ ℚP.+-congʳ (seq z (2 ℕ.* m))
(ℚP.-‿cong (ℚP.≃-sym (ℚP.p≤q⇒p⊔q≃q x₂ₘ≤y₂ₘ))) ⟩
seq z (2 ℕ.* m) ℚ.- seq (x ⊔ y) (2 ℕ.* m) ∎
∣∣x∣-∣y∣∣≤∣x-y∣ : ∀ x y -> ∣ ∣ x ∣ - ∣ y ∣ ∣ ≤ ∣ x - y ∣
∣∣x∣-∣y∣∣≤∣x-y∣ x y = ≤-respˡ-≃ (≃-symm (∣x∣≃x⊔-x (∣ x ∣ - ∣ y ∣))) (x≤z∧y≤z⇒x⊔y≤z (left x y) right)
where
open ≤-Reasoning
left : ∀ x y -> ∣ x ∣ - ∣ y ∣ ≤ ∣ x - y ∣
left x y = begin
∣ x ∣ - ∣ y ∣ ≈⟨ +-congˡ (- ∣ y ∣) (∣-∣-cong (≃-symm
(≃-trans (+-congʳ x (+-inverseˡ y)) (+-identityʳ x)))) ⟩
∣ x + (- y + y) ∣ - ∣ y ∣ ≤⟨ +-monoˡ-≤ (- ∣ y ∣)
(≤-respˡ-≃ (∣-∣-cong (+-assoc x (- y) y)) (∣x+y∣≤∣x∣+∣y∣ (x - y) y)) ⟩
∣ x - y ∣ + ∣ y ∣ - ∣ y ∣ ≈⟨ ≃-trans (≃-trans
(+-assoc ∣ x - y ∣ ∣ y ∣ (- ∣ y ∣))
(+-congʳ ∣ x - y ∣ (+-inverseʳ ∣ y ∣)))
(+-identityʳ ∣ x - y ∣) ⟩
∣ x - y ∣ ∎
right : - (∣ x ∣ - ∣ y ∣) ≤ ∣ x - y ∣
right = begin
- (∣ x ∣ - ∣ y ∣) ≈⟨ solve 2 (λ ∣x∣ ∣y∣ ->
⊝ (∣x∣ ⊖ ∣y∣) ⊜ ∣y∣ ⊖ ∣x∣)
≃-refl ∣ x ∣ ∣ y ∣ ⟩
∣ y ∣ - ∣ x ∣ ≤⟨ left y x ⟩
∣ y - x ∣ ≈⟨ ∣x-y∣≃∣y-x∣ y x ⟩
∣ x - y ∣ ∎
archimedean-ℝ₂ : ∀ {x} -> Positive x -> ∃ λ n-1 -> (+ 1 / (suc n-1)) ⋆ < x
archimedean-ℝ₂ {x} posx = let x≄0 = inj₂ (posx⇒0<x posx); x⁻¹ = (x ⁻¹) x≄0; arch = archimedean-ℝ x⁻¹
; x⁻¹≄0 = [ (λ x<0 -> inj₁ (x<0⇒x⁻¹<0 {x} x≄0 x<0)) , (λ 0<x -> inj₂ (0<x⇒0<x⁻¹ {x} x≄0 0<x))]′ x≄0
; n = suc (proj₁ arch) in
ℕ.pred n , <-respˡ-≃ (⋆-distrib-⁻¹ (+ n / 1) (∣↥p∣≢0⇒p⋆≄0 (+ n / 1) _))
(<-respʳ-≃ {_} {(x⁻¹ ⁻¹) x⁻¹≄0} {x} (⁻¹-involutive-default {x} x≄0)
(x<y∧posx,y⇒y⁻¹<x⁻¹ {x⁻¹} {(+ n / 1) ⋆} (proj₂ arch) x⁻¹≄0 (∣↥p∣≢0⇒p⋆≄0 (+ n / 1) _) (posx⇒posx⁻¹ {x} x≄0 posx)
(0<x⇒posx (p<q⇒p⋆<q⋆ 0ℚᵘ (+ n / 1) (ℚP.positive⁻¹ _)))))
where open ≤-Reasoning
abstract
fast-archimedean-ℝ₂ : ∀ {x} -> Positive x -> ∃ λ n-1 -> (+ 1 / (suc n-1)) ⋆ < x
fast-archimedean-ℝ₂ = archimedean-ℝ₂
negx,y⇒posx*y : ∀ {x y} -> Negative x -> Negative y -> Positive (x * y)
negx,y⇒posx*y {x} {y} negx negy = pos-cong
(solve 2 (λ x y -> ⊝ x ⊗ ⊝ y ⊜ x ⊗ y) ≃-refl x y)
(posx,y⇒posx*y negx negy)
where open ≃-Reasoning
negx∧posy⇒negx*y : ∀ {x y} -> Negative x -> Positive y -> Negative (x * y)
negx∧posy⇒negx*y {x} {y} negx posy = pos-cong (≃-symm (neg-distribˡ-* x y)) (posx,y⇒posx*y negx posy)
x≄0∧y≄0⇒x*y≄0 : ∀ {x y} -> x ≄0 -> y ≄0 -> (x * y) ≄0
x≄0∧y≄0⇒x*y≄0 {x} {y} x≄0 y≄0 = [ [ y<0∧x<0 , 0<y∧x<0 ]′ y≄0 , [ y<0∧0<x , 0<y∧0<x ]′ y≄0 ]′ x≄0
where
y<0∧x<0 : y < 0ℝ -> x < 0ℝ -> (x * y) ≄0
y<0∧x<0 y<0 x<0 = inj₂ (posx⇒0<x (negx,y⇒posx*y (x<0⇒negx x<0) (x<0⇒negx y<0)))
0<y∧x<0 : 0ℝ < y -> x < 0ℝ -> (x * y) ≄0
0<y∧x<0 0<y x<0 = inj₁ (negx⇒x<0 (negx∧posy⇒negx*y (x<0⇒negx x<0) (0<x⇒posx 0<y)))
y<0∧0<x : y < 0ℝ -> 0ℝ < x -> (x * y) ≄0
y<0∧0<x y<0 0<x = inj₁ (<-respˡ-≃ (*-comm y x) (negx⇒x<0 (negx∧posy⇒negx*y (x<0⇒negx y<0) (0<x⇒posx 0<x))))
0<y∧0<x : 0ℝ < y -> 0ℝ < x -> (x * y) ≄0
0<y∧0<x 0<y 0<x = inj₂ (posx⇒0<x (posx,y⇒posx*y (0<x⇒posx 0<x) (0<x⇒posx 0<y)))
nonNegp⇒nonNegp⋆ : ∀ p -> ℚ.NonNegative p -> NonNegative (p ⋆)
nonNegp⇒nonNegp⋆ p nonp = nonNeg* (λ {(suc n-1) -> ℚP.≤-trans (ℚP.nonPositive⁻¹ _) (ℚP.nonNegative⁻¹ nonp)})
{-
Note: We could obviously get ∣x∣ ≄0 from x≄0 (or vice versa). However, taking in the ∣x∣⁻¹≄0 allows the user to use any
proof that ∣x∣⁻¹ ≄0 instead of just the proof given by x≄0. If we have two distinct proofs of x ≄0,
say A and B, then (x ⁻¹) A ≡ (x ⁻¹) B does not hold by reflexivity, and probably doesn't hold in most
cases anyway. So if the user has a different ∣x∣ ≄0 proof they'd have to apply uniqueness of inverses,
which is more labour than supplying the ∣x∣ ≄0 proof since you have to supply a proof that
((∣ x ∣ ⁻¹) C) * ∣ x ∣ ≃ 1ℝ along with all of the *-cong's used to swap out ∣ x ∣ ⁻¹ A for ∣ x ∣ ⁻¹ C.
-}
∣x∣⁻¹≃∣x⁻¹∣ : ∀ {x} -> (∣x∣≄0 : ∣ x ∣ ≄0) -> (x≄0 : x ≄0) -> (∣ x ∣ ⁻¹) ∣x∣≄0 ≃ ∣ (x ⁻¹) x≄0 ∣
∣x∣⁻¹≃∣x⁻¹∣ {x} ∣x∣≄0 x≄0 = let ∣x∣⁻¹ = (∣ x ∣ ⁻¹) ∣x∣≄0; x⁻¹ = (x ⁻¹) x≄0 in begin
∣x∣⁻¹ ≈⟨ ≃-symm (*-identityʳ ∣x∣⁻¹) ⟩
∣x∣⁻¹ * 1ℝ ≈⟨ *-congˡ {∣x∣⁻¹} (≃-symm (≃-trans (∣-∣-cong (*-inverseʳ x x≄0)) (nonNegx⇒∣x∣≃x (nonNegp⇒nonNegp⋆ 1ℚᵘ _)))) ⟩
∣x∣⁻¹ * ∣ x * x⁻¹ ∣ ≈⟨ *-congˡ {∣x∣⁻¹} (∣x*y∣≃∣x∣*∣y∣ x x⁻¹) ⟩
∣x∣⁻¹ * (∣ x ∣ * ∣ x⁻¹ ∣) ≈⟨ ≃-symm (*-assoc ∣x∣⁻¹ ∣ x ∣ ∣ x⁻¹ ∣) ⟩
∣x∣⁻¹ * ∣ x ∣ * ∣ x⁻¹ ∣ ≈⟨ *-congʳ {∣ x⁻¹ ∣} (*-inverseˡ ∣ x ∣ ∣x∣≄0) ⟩
1ℝ * ∣ x⁻¹ ∣ ≈⟨ *-identityˡ ∣ x⁻¹ ∣ ⟩
∣ x⁻¹ ∣ ∎
where open ≃-Reasoning
x≄0⇒∣x∣≄0 : ∀ {x} -> x ≄0 -> ∣ x ∣ ≄0
x≄0⇒∣x∣≄0 {x} x≄0 = inj₂ (pos-cong (≃-symm (≃-trans (+-congʳ ∣ x ∣ (≃-symm 0≃-0)) (+-identityʳ ∣ x ∣))) (x≄0⇒pos∣x∣ x≄0))
⁻¹-distrib-* : ∀ {x y} -> (x≄0 : x ≄0) -> (y≄0 : y ≄0) -> (xy≄0 : (x * y) ≄0) ->
((x * y) ⁻¹) xy≄0 ≃ ((x ⁻¹) x≄0) * ((y ⁻¹) y≄0)
⁻¹-distrib-* {x} {y} x≄0 y≄0 xy≄0 = let x⁻¹ = (x ⁻¹) x≄0; y⁻¹ = (y ⁻¹) y≄0 in
≃-symm (⁻¹-unique (x⁻¹ * y⁻¹) (x * y) xy≄0 (begin
x⁻¹ * y⁻¹ * (x * y) ≈⟨ solve 4 (λ x y x⁻¹ y⁻¹ ->
x⁻¹ ⊗ y⁻¹ ⊗ (x ⊗ y) ⊜ x⁻¹ ⊗ (y⁻¹ ⊗ y ⊗ x))
≃-refl x y x⁻¹ y⁻¹ ⟩
x⁻¹ * (y⁻¹ * y * x) ≈⟨ *-congˡ {x⁻¹} (*-congʳ {x} (*-inverseˡ y y≄0)) ⟩
x⁻¹ * (1ℝ * x) ≈⟨ *-congˡ {x⁻¹} (*-identityˡ x) ⟩
x⁻¹ * x ≈⟨ *-inverseˡ x x≄0 ⟩
1ℝ ∎))
where open ≃-Reasoning
abstract
fast-⁻¹-distrib-* : ∀ {x y} -> (x≄0 : x ≄0) -> (y≄0 : y ≄0) -> (xy≄0 : (x * y) ≄0) ->
((x * y) ⁻¹) xy≄0 ≃ ((x ⁻¹) x≄0) * ((y ⁻¹) y≄0)
fast-⁻¹-distrib-* {x} {y} x≄0 y≄0 xy≄0 = ⁻¹-distrib-* {x} {y} x≄0 y≄0 xy≄0
ε-from-convergence : ∀ {xs : ℕ -> ℝ} -> (xₙ→ℓ : xs isConvergent) ->
∀ ε -> Positive ε -> ∃ λ (N-1 : ℕ) -> ∀ n -> n ℕ.≥ suc N-1 -> ∣ xs n - proj₁ xₙ→ℓ ∣ < ε
ε-from-convergence {xs} (ℓ , con* xₙ→ℓ) ε posε = let arch = fast-archimedean-ℝ₂ posε; k = suc (proj₁ arch); N = suc (proj₁ (xₙ→ℓ k)) in
ℕ.pred N , λ {(suc n-1) n≥N -> let n = suc n-1 in begin-strict
∣ xs n - ℓ ∣ ≤⟨ proj₂ (xₙ→ℓ k) n n≥N ⟩
(+ 1 / k) ⋆ <⟨ proj₂ arch ⟩
ε ∎}
where open ≤-Reasoning
abstract
fast-ε-from-convergence : ∀ {xs : ℕ -> ℝ} -> (xₙ→ℓ : xs isConvergent) ->
∀ ε -> Positive ε -> ∃ λ (N-1 : ℕ) -> ∀ n -> n ℕ.≥ suc N-1 -> ∣ xs n - proj₁ xₙ→ℓ ∣ < ε
fast-ε-from-convergence = ε-from-convergence
¬negx⇒nonNegx : ∀ {x} -> ¬ (Negative x) -> NonNegative x
¬negx⇒nonNegx {x} hyp = 0≤x⇒nonNegx (≮⇒≥ (λ hyp2 -> hyp (pos-cong (+-identityˡ (- x)) hyp2)))
nonNegx⇒¬negx : ∀ {x} -> NonNegative x -> ¬ (Negative x)
nonNegx⇒¬negx {x} (nonNeg* nonx) (pos* (n-1 , negx)) = let n = suc n-1 in ℚP.<-irrefl (ℚP.≃-refl {ℚ.- (+ 1 / n)}) (begin-strict
ℚ.- (+ 1 / n) ≤⟨ nonx n ⟩
seq x n ≈⟨ ℚP.≃-sym (ℚP.neg-involutive (seq x n)) ⟩
ℚ.- (ℚ.- seq x n) <⟨ ℚP.neg-mono-< negx ⟩
ℚ.- (+ 1 / n) ∎)
where open ℚP.≤-Reasoning
nonNegx∧x≄0⇒posx : ∀ {x} -> NonNegative x -> x ≄0 -> Positive x
nonNegx∧x≄0⇒posx {x} nonx x≄0 = 0<x⇒posx (begin-strict
0ℝ <⟨ x≄0⇒0<∣x∣ x≄0 ⟩
∣ x ∣ ≈⟨ nonNegx⇒∣x∣≃x nonx ⟩
x ∎)
where open ≤-Reasoning
nonNegx⇒nonNegx⁻¹ : ∀ {x} -> NonNegative x -> (x≄0 : x ≄0) -> NonNegative ((x ⁻¹) x≄0)
nonNegx⇒nonNegx⁻¹ {x} nonx x≄0 = pos⇒nonNeg (posx⇒posx⁻¹ {x} x≄0 (nonNegx∧x≄0⇒posx {x} nonx x≄0))
{-
Proposition:
If xₙ ≠ 0 for all n∈ℕ, x₀ ≠ 0, and (xₙ)→x₀, then (xₙ⁻¹)→x₀⁻¹.
Proof:
We must show that, for all k∈ℕ, there is Nₖ∈ℕ such that
∣xₙ⁻¹ - x₀⁻¹∣ ≤ k⁻¹.
By the Archimedean Property, there is r∈ℕ such that r⁻¹ < 2⁻¹∣x₀∣ since ∣x₀∣ > 0.
Then for some n₀∈ℕ we have
∣xₙ - x₀∣ ≤ r⁻¹ < 2⁻¹∣x₀∣ < ∣x₀∣ (n ≥ n₀),
which implies, for n ≥ n₀,
∣xₙ∣ = ∣x₀ - (x₀ - xₙ)∣
≥ ∣∣x₀∣ - ∣x₀ - xₙ∣∣
= ∣x₀∣ - ∣x₀ - xₙ∣ since ∣xₙ - x₀∣ < ∣x₀∣
> ∣x₀∣ - 2⁻¹∣x₀∣ since n ≥ n₀
= 2⁻¹∣x₀∣.
Let k∈ℕ. Then there is m₀∈ℕ such that
∣xₙ - x₀∣ < (2k)⁻¹∣x₀∣² (n ≥ m₀)
since ∣x₀∣ > 0. Let N = max{m₀, n₀} and let n ≥ N. We have
∣xₙ⁻¹ - x₀⁻¹∣ = ∣xₙ∣⁻¹ * ∣x₀∣⁻¹ * ∣xₙ - x₀∣
< 2∣x₀∣⁻¹ * ∣x₀∣⁻¹ * ∣xₙ - x₀∣ since n ≥ n₀
< 2∣x₀∣⁻² * (2k)⁻¹∣x₀∣² since n ≥ m₀
= k⁻¹.
Hence ∣xₙ⁻¹ - x₀⁻¹∣ ≤ k⁻¹ for all n ≥ N. □
*-mono-≤ {∣ x₀ - xₙ ∣} {(+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣)}
{∣xₙ∣⁻¹ * ∣x₀∣⁻¹} {2ℚᵘ ⋆ * (∣x₀∣⁻¹ * ∣x₀∣⁻¹)}
(nonNeg∣x∣ (x₀ - xₙ))
(nonNegx,y⇒nonNegx*y {∣xₙ∣⁻¹} {∣x₀∣⁻¹}
(nonNegx⇒nonNegx⁻¹ {∣ xₙ ∣} (nonNeg∣x∣ xₙ) ∣xₙ∣≄0)
(nonNegx⇒nonNegx⁻¹ {∣ x₀ ∣} (nonNeg∣x∣ x₀) ∣x₀∣≄0))
(<⇒≤ {∣ x₀ - xₙ ∣} {(+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣)} part4)
(≤-respʳ-≃ {∣xₙ∣⁻¹ * ∣x₀∣⁻¹} {2ℚᵘ ⋆ * ∣x₀∣⁻¹ * ∣x₀∣⁻¹} {2ℚᵘ ⋆ * (∣x₀∣⁻¹ * ∣x₀∣⁻¹)}
(*-assoc (2ℚᵘ ⋆) ∣x₀∣⁻¹ ∣x₀∣⁻¹)
(<⇒≤ {∣xₙ∣⁻¹ * ∣x₀∣⁻¹} {2ℚᵘ ⋆ * ∣x₀∣⁻¹ * ∣x₀∣⁻¹}
(*-monoˡ-<-pos {∣x₀∣⁻¹} (posx⇒posx⁻¹ {∣ x₀ ∣} ∣x₀∣≄0 (x≄0⇒pos∣x∣ {x₀} x₀≄0)) part3)))
-}
abstract
xₙ≄0∧x₀≄0⇒xₙ⁻¹→x₀⁻¹ : ∀ {xs : ℕ -> ℝ} -> ∀ {x₀ : ℝ} -> xs ConvergesTo x₀ -> (xₙ≄0 : ∀ n -> xs n ≄0) -> (x₀≄0 : x₀ ≄0) ->
(λ n -> (xs n ⁻¹) (xₙ≄0 n)) ConvergesTo (x₀ ⁻¹) x₀≄0
xₙ≄0∧x₀≄0⇒xₙ⁻¹→x₀⁻¹ {xs} {x₀} (con* xₙ→x₀) xₙ≄0 x₀≄0 = con* main
where
open ≤-Reasoning
main : ∀ k -> {k≢0 : k ≢0} -> ∃ λ N-1 -> ∀ n -> n ℕ.≥ suc N-1 ->
∣ (xs n ⁻¹) (xₙ≄0 n) - (x₀ ⁻¹) x₀≄0 ∣ ≤ ((+ 1 / k) {k≢0}) ⋆
main (suc k-1) = ℕ.pred N , sub
where
arch = fast-archimedean-ℝ₂ {(+ 1 / 2) ⋆ * ∣ x₀ ∣} (posx,y⇒posx*y (posp⇒posp⋆ (+ 1 / 2) _) (x≄0⇒pos∣x∣ x₀≄0))
r = suc (proj₁ arch)
k = suc k-1
m₀-getter = fast-ε-from-convergence (x₀ , con* xₙ→x₀) ((+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣))
(posx,y⇒posx*y (posp⇒posp⋆ (+ 1 / (2 ℕ.* k)) _)
(posx,y⇒posx*y (x≄0⇒pos∣x∣ x₀≄0) (x≄0⇒pos∣x∣ x₀≄0)))
m₀ = suc (proj₁ m₀-getter)
n₀ = suc (proj₁ (xₙ→x₀ r))
N = m₀ ℕ.⊔ n₀
{-
[1]
Incredible optimization note!
-------------------------------
If you case split on n here to get n = suc m for some m∈ℕ, the typechecking (seemingly) never completes!
If you leave it as is, the typechecking completes in reasonable time.
Agda must be getting stuck on computing lots of extra things when n = suc m. Amazing!
Despite this issue being solved, the addition of all of the implicit arguments below is a notable optimization, and will
thus be kept.
-}
sub : ∀ n -> n ℕ.≥ N -> ∣ (xs n ⁻¹) (xₙ≄0 n) - (x₀ ⁻¹) x₀≄0 ∣ ≤ (+ 1 / k) ⋆
sub n n≥N = begin
∣ xₙ⁻¹ - x₀⁻¹ ∣ ≈⟨ ≃-trans {∣ xₙ⁻¹ - x₀⁻¹ ∣} {∣xₙ∣⁻¹ * ∣x₀∣⁻¹ * ∣ x₀ - xₙ ∣} {∣ x₀ - xₙ ∣ * (∣xₙ∣⁻¹ * ∣x₀∣⁻¹)}
part2 (*-comm (∣xₙ∣⁻¹ * ∣x₀∣⁻¹) ∣ x₀ - xₙ ∣) ⟩
∣ x₀ - xₙ ∣ * (∣xₙ∣⁻¹ * ∣x₀∣⁻¹) ≤⟨ *-mono-≤ {∣ x₀ - xₙ ∣} {(+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣)}
{∣xₙ∣⁻¹ * ∣x₀∣⁻¹} {2ℚᵘ ⋆ * (∣x₀∣⁻¹ * ∣x₀∣⁻¹)}
(nonNeg∣x∣ (x₀ - xₙ))
(nonNegx,y⇒nonNegx*y {∣xₙ∣⁻¹} {∣x₀∣⁻¹}
(nonNegx⇒nonNegx⁻¹ {∣ xₙ ∣} (nonNeg∣x∣ xₙ) ∣xₙ∣≄0)
(nonNegx⇒nonNegx⁻¹ {∣ x₀ ∣} (nonNeg∣x∣ x₀) ∣x₀∣≄0))
(<⇒≤ {∣ x₀ - xₙ ∣} {(+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣)} part4)
(≤-respʳ-≃ {∣xₙ∣⁻¹ * ∣x₀∣⁻¹} {2ℚᵘ ⋆ * ∣x₀∣⁻¹ * ∣x₀∣⁻¹} {2ℚᵘ ⋆ * (∣x₀∣⁻¹ * ∣x₀∣⁻¹)}
(*-assoc (2ℚᵘ ⋆) ∣x₀∣⁻¹ ∣x₀∣⁻¹)
(<⇒≤ {∣xₙ∣⁻¹ * ∣x₀∣⁻¹} {2ℚᵘ ⋆ * ∣x₀∣⁻¹ * ∣x₀∣⁻¹}
(*-monoˡ-<-pos {∣x₀∣⁻¹} (posx⇒posx⁻¹ {∣ x₀ ∣} ∣x₀∣≄0 (x≄0⇒pos∣x∣ {x₀} x₀≄0))
{∣xₙ∣⁻¹} {2ℚᵘ ⋆ * ∣x₀∣⁻¹} part3))) ⟩
(+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣) *
(2ℚᵘ ⋆ * (∣x₀∣⁻¹ * ∣x₀∣⁻¹)) ≈⟨ solve 4 (λ 1/2k ∣x₀∣ 2ℚ ∣x₀∣⁻¹ ->
1/2k ⊗ (∣x₀∣ ⊗ ∣x₀∣) ⊗ (2ℚ ⊗ (∣x₀∣⁻¹ ⊗ ∣x₀∣⁻¹)) ⊜
1/2k ⊗ (∣x₀∣ ⊗ ∣x₀∣ ⊗ (∣x₀∣⁻¹ ⊗ ∣x₀∣⁻¹) ⊗ 2ℚ))
≃-refl ((+ 1 / (2 ℕ.* k)) ⋆) ∣ x₀ ∣ (2ℚᵘ ⋆) ∣x₀∣⁻¹ ⟩
(+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣ *
(∣x₀∣⁻¹ * ∣x₀∣⁻¹) * 2ℚᵘ ⋆) ≈⟨ *-congˡ {(+ 1 / (2 ℕ.* k)) ⋆} {∣ x₀ ∣ * ∣ x₀ ∣ * (∣x₀∣⁻¹ * ∣x₀∣⁻¹) * 2ℚᵘ ⋆}
{1ℝ * 2ℚᵘ ⋆} (*-congʳ {2ℚᵘ ⋆} {∣ x₀ ∣ * ∣ x₀ ∣ * (∣x₀∣⁻¹ * ∣x₀∣⁻¹)} {1ℝ} part5) ⟩
(+ 1 / (2 ℕ.* k)) ⋆ * (1ℝ * 2ℚᵘ ⋆) ≈⟨ ≃-trans {(+ 1 / (2 ℕ.* k)) ⋆ * (1ℝ * 2ℚᵘ ⋆)} {(+ 1 / (2 ℕ.* k)) ⋆ * (2ℚᵘ ⋆)}
{(+ 1 / (2 ℕ.* k) ℚ.* 2ℚᵘ) ⋆}
(*-congˡ {(+ 1 / (2 ℕ.* k)) ⋆} {1ℝ * 2ℚᵘ ⋆} {2ℚᵘ ⋆} (*-identityˡ (2ℚᵘ ⋆)))
(≃-symm {(+ 1 / (2 ℕ.* k) ℚ.* 2ℚᵘ) ⋆} {(+ 1 / (2 ℕ.* k)) ⋆ * 2ℚᵘ ⋆}
(⋆-distrib-* (+ 1 / (2 ℕ.* k)) 2ℚᵘ)) ⟩
(+ 1 / (2 ℕ.* k) ℚ.* 2ℚᵘ) ⋆ ≈⟨ ⋆-cong {+ 1 / (2 ℕ.* k) ℚ.* 2ℚᵘ} {+ 1 / k} (ℚ.*≡* (ℤsolve 1 (λ k ->
ℤΚ (+ 1) :* ℤΚ (+ 2) :* k := ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k :* ℤΚ (+ 1)))
refl (+ k))) ⟩
(+ 1 / k) ⋆ ∎
where
xₙ = xs n
xₙ⁻¹ = (xₙ ⁻¹) (xₙ≄0 n)
x₀⁻¹ = (x₀ ⁻¹) x₀≄0
∣xₙ∣≄0 = x≄0⇒∣x∣≄0 (xₙ≄0 n)
∣x₀∣≄0 = x≄0⇒∣x∣≄0 x₀≄0
∣xₙ∣⁻¹ = (∣ xₙ ∣ ⁻¹) ∣xₙ∣≄0
∣x₀∣⁻¹ = (∣ x₀ ∣ ⁻¹) ∣x₀∣≄0
2⁻¹∣x₀∣<∣xₙ∣ : (+ 1 / 2) ⋆ * ∣ x₀ ∣ < ∣ xₙ ∣
2⁻¹∣x₀∣<∣xₙ∣ = begin-strict
(+ 1 / 2) ⋆ * ∣ x₀ ∣ ≈⟨ solve 1 (λ ∣x₀∣ ->
Κ (1ℚᵘ ℚ.- (+ 1 / 2)) ⊗ ∣x₀∣ ⊜ ∣x₀∣ ⊖ Κ (+ 1 / 2) ⊗ ∣x₀∣)
≃-refl ∣ x₀ ∣ ⟩
∣ x₀ ∣ - (+ 1 / 2) ⋆ * ∣ x₀ ∣ <⟨ +-monoʳ-< ∣ x₀ ∣ (neg-mono-< (<-respˡ-≃ (∣x-y∣≃∣y-x∣ xₙ x₀)
(≤-<-trans (proj₂ (xₙ→x₀ r) n (ℕP.≤-trans (ℕP.m≤n⊔m m₀ n₀) n≥N))
(proj₂ arch)))) ⟩
∣ x₀ ∣ - ∣ x₀ - xₙ ∣ ≤⟨ x≤∣x∣ ⟩
∣ ∣ x₀ ∣ - ∣ x₀ - xₙ ∣ ∣ ≤⟨ ∣∣x∣-∣y∣∣≤∣x-y∣ x₀ (x₀ - xₙ) ⟩
∣ x₀ - (x₀ - xₙ) ∣ ≈⟨ ∣-∣-cong (solve 2 (λ xₙ x₀ ->
x₀ ⊖ (x₀ ⊖ xₙ) ⊜ xₙ)
≃-refl xₙ x₀) ⟩
∣ xₙ ∣ ∎
part1 : xₙ⁻¹ - x₀⁻¹ ≃ xₙ⁻¹ * x₀⁻¹ * (x₀ - xₙ)
part1 = ≃-symm (begin-equality
xₙ⁻¹ * x₀⁻¹ * (x₀ - xₙ) ≈⟨ *-distribˡ-+ (xₙ⁻¹ * x₀⁻¹) x₀ (- xₙ) ⟩
xₙ⁻¹ * x₀⁻¹ * x₀ + xₙ⁻¹ * x₀⁻¹ * (- xₙ) ≈⟨ +-cong
(≃-trans (≃-trans
(*-assoc xₙ⁻¹ x₀⁻¹ x₀)
(*-congˡ {xₙ⁻¹} (*-inverseˡ x₀ x₀≄0)))
(*-identityʳ xₙ⁻¹))
(≃-symm (neg-distribʳ-* (xₙ⁻¹ * x₀⁻¹) xₙ)) ⟩
xₙ⁻¹ - xₙ⁻¹ * x₀⁻¹ * xₙ ≈⟨ ≃-trans (≃-trans
(solve 3 (λ xₙ xₙ⁻¹ x₀⁻¹ ->
xₙ⁻¹ ⊖ xₙ⁻¹ ⊗ x₀⁻¹ ⊗ xₙ ⊜ xₙ⁻¹ ⊕ (⊝ x₀⁻¹) ⊗ (xₙ⁻¹ ⊗ xₙ))
≃-refl xₙ xₙ⁻¹ x₀⁻¹)
(+-congʳ xₙ⁻¹ (*-congˡ { - x₀⁻¹} (*-inverseˡ xₙ (xₙ≄0 n)))))
(+-congʳ xₙ⁻¹ (*-identityʳ (- x₀⁻¹))) ⟩
xₙ⁻¹ - x₀⁻¹ ∎)
part2 : ∣ xₙ⁻¹ - x₀⁻¹ ∣ ≃ ∣xₙ∣⁻¹ * ∣x₀∣⁻¹ * ∣ x₀ - xₙ ∣
part2 = begin-equality
∣ xₙ⁻¹ - x₀⁻¹ ∣ ≈⟨ ∣-∣-cong part1 ⟩
∣ xₙ⁻¹ * x₀⁻¹ * (x₀ - xₙ) ∣ ≈⟨ ∣x*y∣≃∣x∣*∣y∣ (xₙ⁻¹ * x₀⁻¹) (x₀ - xₙ) ⟩
∣ xₙ⁻¹ * x₀⁻¹ ∣ * ∣ x₀ - xₙ ∣ ≈⟨ *-congʳ {∣ x₀ - xₙ ∣} (∣x*y∣≃∣x∣*∣y∣ xₙ⁻¹ x₀⁻¹) ⟩
∣ xₙ⁻¹ ∣ * ∣ x₀⁻¹ ∣ * ∣ x₀ - xₙ ∣ ≈⟨ *-congʳ {∣ x₀ - xₙ ∣} (≃-symm (*-cong
(∣x∣⁻¹≃∣x⁻¹∣ {xₙ} ∣xₙ∣≄0 (xₙ≄0 n))
(∣x∣⁻¹≃∣x⁻¹∣ {x₀} ∣x₀∣≄0 x₀≄0))) ⟩
∣xₙ∣⁻¹ * ∣x₀∣⁻¹ * ∣ x₀ - xₙ ∣ ∎
part3 : ∣xₙ∣⁻¹ < 2ℚᵘ ⋆ * ∣x₀∣⁻¹
part3 = let 2⁻¹≄0 = ∣↥p∣≢0⇒p⋆≄0 (+ 1 / 2) _
; 2⁻¹∣x₀∣≄0 = x≄0∧y≄0⇒x*y≄0 {(+ 1 / 2) ⋆} {∣ x₀ ∣} 2⁻¹≄0 ∣x₀∣≄0 in begin-strict
∣xₙ∣⁻¹ <⟨ x<y∧posx,y⇒y⁻¹<x⁻¹ {(+ 1 / 2) ⋆ * ∣ x₀ ∣} {∣ xₙ ∣}
2⁻¹∣x₀∣<∣xₙ∣ 2⁻¹∣x₀∣≄0 ∣xₙ∣≄0
(posx,y⇒posx*y {(+ 1 / 2) ⋆} {∣ x₀ ∣}
(posp⇒posp⋆ (+ 1 / 2) _) (x≄0⇒pos∣x∣ {x₀} x₀≄0))
(x≄0⇒pos∣x∣ {xₙ} (xₙ≄0 n)) ⟩
(((+ 1 / 2) ⋆ * ∣ x₀ ∣) ⁻¹) 2⁻¹∣x₀∣≄0 ≈⟨ ⁻¹-distrib-* {(+ 1 / 2) ⋆} {∣ x₀ ∣} 2⁻¹≄0 ∣x₀∣≄0 2⁻¹∣x₀∣≄0 ⟩
(((+ 1 / 2) ⋆) ⁻¹) 2⁻¹≄0 * ∣x₀∣⁻¹ ≈⟨ *-congʳ {∣x₀∣⁻¹} (⋆-distrib-⁻¹ (+ 1 / 2) 2⁻¹≄0) ⟩
2ℚᵘ ⋆ * ∣x₀∣⁻¹ ∎
part4 : ∣ x₀ - xₙ ∣ < (+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣)
part4 = begin-strict
∣ x₀ - xₙ ∣ ≈⟨ ∣x-y∣≃∣y-x∣ x₀ xₙ ⟩
∣ xₙ - x₀ ∣ <⟨ proj₂ m₀-getter n (ℕP.≤-trans (ℕP.m≤m⊔n m₀ n₀) n≥N) ⟩
(+ 1 / (2 ℕ.* k)) ⋆ * (∣ x₀ ∣ * ∣ x₀ ∣) ∎
part5 : (∣ x₀ ∣ * ∣ x₀ ∣) * (∣x₀∣⁻¹ * ∣x₀∣⁻¹) ≃ 1ℝ
part5 = begin-equality
(∣ x₀ ∣ * ∣ x₀ ∣) * (∣x₀∣⁻¹ * ∣x₀∣⁻¹) ≈⟨ solve 2 (λ ∣x₀∣ ∣x₀∣⁻¹ ->
(∣x₀∣ ⊗ ∣x₀∣) ⊗ (∣x₀∣⁻¹ ⊗ ∣x₀∣⁻¹) ⊜
(∣x₀∣ ⊗ ∣x₀∣⁻¹) ⊗ (∣x₀∣ ⊗ ∣x₀∣⁻¹))
≃-refl ∣ x₀ ∣ ∣x₀∣⁻¹ ⟩
(∣ x₀ ∣ * ∣x₀∣⁻¹) * (∣ x₀ ∣ * ∣x₀∣⁻¹) ≈⟨ *-cong {∣ x₀ ∣ * ∣x₀∣⁻¹} {1ℝ} {∣ x₀ ∣ * ∣x₀∣⁻¹} {1ℝ}
(*-inverseʳ ∣ x₀ ∣ ∣x₀∣≄0) (*-inverseʳ ∣ x₀ ∣ ∣x₀∣≄0) ⟩
1ℝ * 1ℝ ≈⟨ *-identityʳ 1ℝ ⟩
1ℝ ∎
∣xₙ∣→∣x₀∣ : ∀ {xs : ℕ -> ℝ} -> (x→x₀ : xs isConvergent) -> (λ n -> ∣ xs n ∣) ConvergesTo ∣ proj₁ x→x₀ ∣
∣xₙ∣→∣x₀∣ {xs} (x₀ , con* x→x₀) = con* λ {(suc k-1) -> let k = suc k-1 in
proj₁ (x→x₀ k) , λ {(suc n-1) n≥N -> let n = suc n-1 in begin
∣ ∣ xs n ∣ - ∣ x₀ ∣ ∣ ≤⟨ ∣∣x∣-∣y∣∣≤∣x-y∣ (xs n) x₀ ⟩
∣ xs n - x₀ ∣ ≤⟨ proj₂ (x→x₀ k) n n≥N ⟩
(+ 1 / k) ⋆ ∎}}
where open ≤-Reasoning
0≤x⇒∣x∣≃x : ∀ {x} -> 0ℝ ≤ x -> ∣ x ∣ ≃ x
0≤x⇒∣x∣≃x {x} 0≤x = nonNegx⇒∣x∣≃x (nonNeg-cong (≃-trans (+-congʳ x (≃-symm 0≃-0)) (+-identityʳ x)) 0≤x)
x≤y⇒0≤y-x : ∀ {x y} -> x ≤ y -> 0ℝ ≤ y - x
x≤y⇒0≤y-x {x} {y} x≤y = nonNeg-cong (≃-symm (≃-trans (+-congʳ (y - x) (≃-symm 0≃-0)) (+-identityʳ (y - x)))) x≤y
xₙ≤yₙ⇒x₀≤y₀ : ∀ {xs ys : ℕ -> ℝ} -> ∀ {x₀ y₀ : ℝ} -> xs ConvergesTo x₀ -> ys ConvergesTo y₀ ->
(∀ n -> {n ≢0} -> xs n ≤ ys n) -> x₀ ≤ y₀
xₙ≤yₙ⇒x₀≤y₀ {xs} {ys} {x₀} {y₀} (con* xₙ→x₀) (con* yₙ→y₀) xₙ≤yₙ = 0≤y-x⇒x≤y (begin
0ℝ ≤⟨ 0≤∣x∣ (y₀ - x₀) ⟩
∣ y₀ - x₀ ∣ ≈⟨ uniqueness-of-limits (∣xₙ∣→∣x₀∣ (y₀ - x₀ , yₙ-xₙ→y₀-x₀))
(xₙ≃yₙ∧xₙ→x₀⇒yₙ→x₀ (λ {(suc n-1) -> let n = suc n-1 in
≃-symm (0≤x⇒∣x∣≃x (x≤y⇒0≤y-x (xₙ≤yₙ n)))}) (y₀ - x₀ , yₙ-xₙ→y₀-x₀)) ⟩
y₀ - x₀ ∎)
where
open ≤-Reasoning
yₙ-xₙ→y₀-x₀ = xₙ+yₙ→x₀+y₀ (y₀ , con* yₙ→y₀) (- x₀ , -xₙ→-x₀ (x₀ , con* xₙ→x₀))
private
x-y≤z⇒x≤z+y : ∀ {x y z} -> x - y ≤ z -> x ≤ z + y
x-y≤z⇒x≤z+y {x} {y} {z} x-y≤z = begin
x ≈⟨ solve 2 (λ x y -> x ⊜ x ⊖ y ⊕ y) ≃-refl x y ⟩
x - y + y ≤⟨ +-monoˡ-≤ y x-y≤z ⟩
z + y ∎
where open ≤-Reasoning
∣x⊔y-z⊔w∣≤∣x-z∣⊔∣y-w∣ : ∀ x y z w -> ∣ x ⊔ y - (z ⊔ w) ∣ ≤ ∣ x - z ∣ ⊔ ∣ y - w ∣
∣x⊔y-z⊔w∣≤∣x-z∣⊔∣y-w∣ x y z w = ≤-respˡ-≃ (≃-symm (∣x∣≃x⊔-x (x ⊔ y - (z ⊔ w))))
(x≤z∧y≤z⇒x⊔y≤z
(lem x y (z ⊔ w) (∣ x - z ∣ ⊔ ∣ y - w ∣) part1 part2)
(≤-respˡ-≃ (solve 2 (λ x⊔y z⊔w ->
z⊔w ⊖ x⊔y ⊜ (⊝ (x⊔y ⊖ z⊔w))) ≃-refl (x ⊔ y) (z ⊔ w))
(lem z w (x ⊔ y) (∣ x - z ∣ ⊔ ∣ y - w ∣) part3 part4)))
where
open ≤-Reasoning
lem : ∀ x y z w -> x - z ≤ w -> y - z ≤ w -> x ⊔ y - z ≤ w
lem x y z w x-z≤w y-z≤w = begin
x ⊔ y - z ≤⟨ +-monoˡ-≤ (- z) (x≤z∧y≤z⇒x⊔y≤z
(x-y≤z⇒x≤z+y x-z≤w)
(x-y≤z⇒x≤z+y y-z≤w)) ⟩
w + z - z ≈⟨ solve 2 (λ w z -> w ⊕ z ⊖ z ⊜ w) ≃-refl w z ⟩
w ∎
part1 : x - (z ⊔ w) ≤ ∣ x - z ∣ ⊔ ∣ y - w ∣
part1 = begin
x - (z ⊔ w) ≤⟨ +-monoʳ-≤ x (neg-mono-≤ (x≤x⊔y z w)) ⟩
x - z ≤⟨ x≤∣x∣ ⟩
∣ x - z ∣ ≤⟨ x≤x⊔y ∣ x - z ∣ ∣ y - w ∣ ⟩
∣ x - z ∣ ⊔ ∣ y - w ∣ ∎
part2 : y - (z ⊔ w) ≤ ∣ x - z ∣ ⊔ ∣ y - w ∣
part2 = begin
y - (z ⊔ w) ≤⟨ +-monoʳ-≤ y (neg-mono-≤ (x≤y⊔x w z)) ⟩
y - w ≤⟨ x≤∣x∣ ⟩
∣ y - w ∣ ≤⟨ x≤y⊔x ∣ y - w ∣ ∣ x - z ∣ ⟩
∣ x - z ∣ ⊔ ∣ y - w ∣ ∎
part3 : z - (x ⊔ y) ≤ ∣ x - z ∣ ⊔ ∣ y - w ∣
part3 = begin
z - (x ⊔ y) ≤⟨ +-monoʳ-≤ z (neg-mono-≤ (x≤x⊔y x y)) ⟩
z - x ≤⟨ x≤∣x∣ ⟩
∣ z - x ∣ ≈⟨ ∣x-y∣≃∣y-x∣ z x ⟩
∣ x - z ∣ ≤⟨ x≤x⊔y ∣ x - z ∣ ∣ y - w ∣ ⟩
∣ x - z ∣ ⊔ ∣ y - w ∣ ∎
part4 : w - (x ⊔ y) ≤ ∣ x - z ∣ ⊔ ∣ y - w ∣
part4 = begin
w - (x ⊔ y) ≤⟨ +-monoʳ-≤ w (neg-mono-≤ (x≤y⊔x y x)) ⟩
w - y ≤⟨ x≤∣x∣ ⟩
∣ w - y ∣ ≈⟨ ∣x-y∣≃∣y-x∣ w y ⟩
∣ y - w ∣ ≤⟨ x≤y⊔x ∣ y - w ∣ ∣ x - z ∣ ⟩
∣ x - z ∣ ⊔ ∣ y - w ∣ ∎
xₙ⊔yₙ→x₀⊔y₀ : ∀ {xs ys : ℕ -> ℝ} -> (xₙ→x₀ : xs isConvergent) -> (yₙ→y₀ : ys isConvergent) ->
(λ n -> xs n ⊔ ys n) ConvergesTo (proj₁ xₙ→x₀ ⊔ proj₁ yₙ→y₀)
xₙ⊔yₙ→x₀⊔y₀ {xs} {ys} (x₀ , con* xₙ→x₀) (y₀ , con* yₙ→y₀) = con* (λ {(suc k-1) ->
let k = suc k-1; N₁ = suc (proj₁ (xₙ→x₀ k)); N₂ = suc (proj₁ (yₙ→y₀ k)) in
ℕ.pred (N₁ ℕ.⊔ N₂) , λ {(suc n-1) n≥N -> let n = suc n-1 in begin
∣ xs n ⊔ ys n - (x₀ ⊔ y₀) ∣ ≤⟨ ∣x⊔y-z⊔w∣≤∣x-z∣⊔∣y-w∣ (xs n) (ys n) x₀ y₀ ⟩
∣ xs n - x₀ ∣ ⊔ ∣ ys n - y₀ ∣ ≤⟨ x≤z∧y≤z⇒x⊔y≤z
(proj₂ (xₙ→x₀ k) n (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) n≥N))
(proj₂ (yₙ→y₀ k) n (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) n≥N)) ⟩
(+ 1 / k) ⋆ ∎}})
where open ≤-Reasoning
SeriesOf_From_ : (ℕ -> ℝ) -> ℕ -> (ℕ -> ℝ)
(SeriesOf xs From i) n = ∑ xs i n
SeriesOf : (ℕ -> ℝ) -> (ℕ -> ℝ)
SeriesOf xs = SeriesOf xs From 0
limitShifting : ∀ xs -> ∀ k m n -> ∑ xs m k ≃ ∑ xs n k + ∑ xs m n
limitShifting xs k zero zero = ≃-symm (+-identityʳ (∑₀ xs k))
limitShifting xs k zero (suc n) = solve 2 (λ a b -> a ⊜ a ⊖ b ⊕ b) ≃-refl (∑₀ xs k) (∑₀ xs (suc n))
limitShifting xs k (suc m) zero = solve 2 (λ a b -> a ⊖ b ⊜ a ⊕ (Κ 0ℚᵘ ⊖ b)) ≃-refl (∑₀ xs k) (∑₀ xs (suc m))
limitShifting xs k (suc m) (suc n) = solve 3 (λ a b c -> a ⊖ b ⊜ a ⊖ c ⊕ (c ⊖ b)) ≃-refl (∑₀ xs k) (∑₀ xs (suc m)) (∑₀ xs (suc n))
lowerLimitShiftPreservesConvergence : ∀ xs -> (∃ λ n -> (SeriesOf xs From n) isConvergent) -> ∀ m -> (SeriesOf xs From m) isConvergent
lowerLimitShiftPreservesConvergence xs (n , (ℓ , con* hyp)) m = ℓ + ∑ xs m n , xₙ≃yₙ∧xₙ→x₀⇒yₙ→x₀ (λ {(suc k-1) -> let k = suc k-1 in
≃-symm (limitShifting xs k m n)}) (ℓ + ∑ xs m n ,
xₙ+yₙ→x₀+y₀ {SeriesOf xs From n} {λ r -> ∑ xs m n} (ℓ , con* hyp) (∑ xs m n , xₙ≃c⇒xₙ→c (λ {(suc r-1) -> ≃-refl})))
cauchyConvergenceTest-if : ∀ xs -> SeriesOf xs isConvergent ->
∀ k -> {k≢0 : k ≢0} -> ∃ λ Nₖ-1 -> ∀ m n -> m ℕ.≥ suc Nₖ-1 -> n ℕ.≥ suc Nₖ-1 ->
∣ ∑ xs m n ∣ ≤ ((+ 1 / k) {k≢0}) ⋆
cauchyConvergenceTest-if xs (ℓ , con* hyp) (suc k-1) = let k = suc k-1; N₂ₖ = suc (proj₁ (hyp (2 ℕ.* k))) in
ℕ.pred N₂ₖ , λ {(suc m-1) (suc n-1) m≥N₂ₖ n≥N₂ₖ ->
let m = suc m-1; n = suc n-1 in begin
∣ ∑₀ xs n - ∑₀ xs m ∣ ≈⟨ ∣-∣-cong (solve 3 (λ a b c -> a ⊖ b ⊜ a ⊖ c ⊕ (c ⊖ b))
≃-refl (∑₀ xs n) (∑₀ xs m) ℓ) ⟩
∣ ∑₀ xs n - ℓ + (ℓ - ∑₀ xs m) ∣ ≤⟨ ∣x+y∣≤∣x∣+∣y∣ (∑₀ xs n - ℓ) (ℓ - ∑₀ xs m) ⟩
∣ ∑₀ xs n - ℓ ∣ + ∣ ℓ - ∑₀ xs m ∣ ≤⟨ +-mono-≤
(proj₂ (hyp (2 ℕ.* k)) n n≥N₂ₖ)
(≤-respˡ-≃ (∣x-y∣≃∣y-x∣ (∑₀ xs m) ℓ) (proj₂ (hyp (2 ℕ.* k)) m m≥N₂ₖ)) ⟩
(+ 1 / (2 ℕ.* k)) ⋆ + (+ 1 / (2 ℕ.* k)) ⋆ ≈⟨ ≃-trans
(≃-symm (⋆-distrib-+ (+ 1 / (2 ℕ.* k)) (+ 1 / (2 ℕ.* k))))
(⋆-cong (ℚ.*≡* (ℤsolve 1 (λ k ->
(ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k) :+ ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k)) :* k :=
ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k :* (ℤΚ (+ 2) :* k)))
refl (+ k)))) ⟩
(+ 1 / k) ⋆ ∎}
where open ≤-Reasoning
cauchyConvergenceTest-onlyif : ∀ xs ->
(∀ k -> {k≢0 : k ≢0} -> ∃ λ Nₖ-1 -> ∀ m n -> m ℕ.≥ suc Nₖ-1 -> n ℕ.≥ suc Nₖ-1 ->
∣ ∑ xs m n ∣ ≤ ((+ 1 / k) {k≢0}) ⋆) ->
SeriesOf xs isConvergent
cauchyConvergenceTest-onlyif xs hyp = fast-cauchy⇒convergent (cauchy* (λ {(suc k-1) -> let k = suc k-1; Mₖ = suc (proj₁ (hyp k)) in
ℕ.pred Mₖ , λ {(suc m-1) (suc n-1) m≥Mₖ n≥Mₖ -> let m = suc m-1; n = suc n-1 in begin
∣ ∑ xs 0 m - ∑ xs 0 n ∣ ≈⟨ ≃-refl ⟩
∣ ∑ xs n m ∣ ≤⟨ proj₂ (hyp k) n m n≥Mₖ m≥Mₖ ⟩
(+ 1 / k) ⋆ ∎}}))
where open ≤-Reasoning
∑xₙisConvergent⇒xₙ→0 : ∀ xs -> SeriesOf xs isConvergent -> xs ConvergesTo 0ℝ
∑xₙisConvergent⇒xₙ→0 xs (ℓ , con* ∑xₙ→ℓ) = con* (λ {(suc k-1) -> let k = suc k-1; N₂ₖ = suc (proj₁ (∑xₙ→ℓ (2 ℕ.* k))) in
ℕ.pred N₂ₖ , λ {(suc n-1) n≥N₂ₖ -> let n = suc n-1; n+1 = suc n in begin
∣ xs n - 0ℝ ∣ ≈⟨ ∣-∣-cong (solve 3 (λ ∑₀ⁿxᵢ xₙ ℓ ->
xₙ ⊖ Κ 0ℚᵘ ⊜ (∑₀ⁿxᵢ ⊕ xₙ) ⊖ ℓ ⊕ (ℓ ⊖ ∑₀ⁿxᵢ))
≃-refl (∑₀ xs n) (xs n) ℓ) ⟩
∣ ∑₀ xs n+1 - ℓ + (ℓ - ∑₀ xs n) ∣ ≤⟨ ∣x+y∣≤∣x∣+∣y∣ (∑₀ xs n+1 - ℓ) (ℓ - ∑₀ xs n) ⟩
∣ ∑₀ xs n+1 - ℓ ∣ + ∣ ℓ - ∑₀ xs n ∣ ≤⟨ +-mono-≤
(proj₂ (∑xₙ→ℓ (2 ℕ.* k)) n+1 (ℕP.≤-trans n≥N₂ₖ (ℕP.n≤1+n n)))
(≤-respˡ-≃ (∣x-y∣≃∣y-x∣ (∑₀ xs n) ℓ) (proj₂ (∑xₙ→ℓ (2 ℕ.* k)) n n≥N₂ₖ)) ⟩
(+ 1 / (2 ℕ.* k)) ⋆ + (+ 1 / (2 ℕ.* k)) ⋆ ≈⟨ ≃-trans
(≃-symm (⋆-distrib-+ (+ 1 / (2 ℕ.* k)) (+ 1 / (2 ℕ.* k))))
(⋆-cong (ℚ.*≡* (ℤsolve 1 (λ k ->
(ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k) :+ ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k)) :* k :=
ℤΚ (+ 1) :* (ℤΚ (+ 2) :* k :* (ℤΚ (+ 2) :* k)))
refl (+ k)))) ⟩
(+ 1 / k) ⋆ ∎}})
where open ≤-Reasoning
SeriesOf_ConvergesAbsolutely : (ℕ -> ℝ) -> Set
SeriesOf xs ConvergesAbsolutely = SeriesOf (λ k -> ∣ xs k ∣) isConvergent
{-
Changing termination depth doesn't help fix this weird lem recursion problem (tried different depths up to 10).
-}
∑-cong : ∀ {xs ys : ℕ -> ℝ} -> (∀ n -> xs n ≃ ys n) -> ∀ m n -> ∑ xs m n ≃ ∑ ys m n
{-∑-cong {xs} {ys} xₙ≃yₙ zero zero = ≃-refl
∑-cong {xs} {ys} xₙ≃yₙ zero (suc n) = +-cong (∑-cong xₙ≃yₙ 0 n) (xₙ≃yₙ n)-}
∑-cong {xs} {ys} xₙ≃yₙ 0 n = lem n
where
lem : ∀ n -> ∑ xs 0 n ≃ ∑ ys 0 n
lem 0 = ≃-refl
lem (suc n) = +-cong (lem n) (xₙ≃yₙ n)
∑-cong {xs} {ys} xₙ≃yₙ (suc m) n = +-cong (∑-cong xₙ≃yₙ 0 n) (-‿cong (∑-cong xₙ≃yₙ 0 (suc m)))
{-
∣∑xᵢ∣ ≤ ∑∣xᵢ∣
Sometimes it's easier to use ∑ᵀ instead of ∑ that gives
∑ᵢ₌ₖⁿ xᵢ = xₖ + ⋯ + xₙ
instead of
∑ᵢ₌ₖⁿ xᵢ = ∑ᵢ₌₀ⁿ xᵢ - ∑ᵢ₌₀ᵏ xᵢ
when k ≤ n.
As an example, consider the triangle inequality proof for ∑ below.
Note that ∑ᵀ requires i≤n, which isn't what we want in general. Moreover,
∑ᵀ uses a somewhat complex with clause, so it's annoying to prove things about.
Hence the alternative definition.
-}
∑ᵀ : (ℕ -> ℝ) -> (i n : ℕ) -> i ℕ.≤ n -> ℝ
∑ᵀ xs i n i≤n with ≤⇒≡∨< i n i≤n
... | inj₁ refl = 0ℝ
∑ᵀ xs i (suc n-1) i≤n | inj₂ (ℕ.s≤s i<n) = ∑ᵀ xs i n-1 i<n + xs n-1
∑-to-∑ᵀ : ∀ (xs : ℕ -> ℝ) -> ∀ m n -> (m≤n : m ℕ.≤ n) -> ∑ xs m n ≃ ∑ᵀ xs m n m≤n
∑-to-∑ᵀ xs zero n ℕ.z≤n = lem n
where
lem : ∀ n -> ∑₀ xs n ≃ ∑ᵀ xs 0 n ℕ.z≤n
lem 0 = ≃-refl
lem (suc n) with ≤⇒≡∨< 0 (suc n) ℕ.z≤n
... | inj₂ 0<n = +-congˡ (xs n) (lem n)
∑-to-∑ᵀ xs (suc m-1) n m≤n with ≤⇒≡∨< (suc m-1) n m≤n
... | inj₁ refl = +-inverseʳ (∑₀ xs (suc m-1))
∑-to-∑ᵀ xs (suc m-1) (suc n-1) m≤n | inj₂ (ℕ.s≤s m<n) = begin
∑₀ xs n-1 + xs n-1 - (∑₀ xs m-1 + xs m-1) ≈⟨ solve 3 (λ ∑₀ⁿ⁻¹xᵢ xₙ₋₁ ∑₀ᵐxᵢ ->
∑₀ⁿ⁻¹xᵢ ⊕ xₙ₋₁ ⊖ ∑₀ᵐxᵢ ⊜ ∑₀ⁿ⁻¹xᵢ ⊖ ∑₀ᵐxᵢ ⊕ xₙ₋₁)
≃-refl (∑₀ xs n-1) (xs n-1) (∑₀ xs (suc m-1)) ⟩
∑₀ xs n-1 - (∑₀ xs m-1 + xs m-1) + xs n-1 ≈⟨ +-congˡ (xs n-1) (∑-to-∑ᵀ xs (suc m-1) n-1 m<n) ⟩
∑ᵀ xs (suc m-1) n-1 m<n + xs n-1 ∎
where open ≃-Reasoning
∑ᵀ-triangle-inequality : ∀ (xs : ℕ -> ℝ) -> ∀ m n -> (m≤n : m ℕ.≤ n) -> ∣ ∑ᵀ xs m n m≤n ∣ ≤ ∑ᵀ (λ k -> ∣ xs k ∣) m n m≤n
∑ᵀ-triangle-inequality xs m n m≤n with ≤⇒≡∨< m n m≤n
... | inj₁ refl = ≤-reflexive (≃-reflexive (λ {(suc k-1) -> ℚP.≃-refl}))
∑ᵀ-triangle-inequality xs m (suc n-1) m≤n | inj₂ (ℕ.s≤s m<n) = let n = suc n-1 in begin
∣ ∑ᵀ xs m n-1 m<n + xs n-1 ∣ ≤⟨ ∣x+y∣≤∣x∣+∣y∣ (∑ᵀ xs m n-1 m<n) (xs n-1) ⟩
∣ ∑ᵀ xs m n-1 m<n ∣ + ∣ xs n-1 ∣ ≤⟨ +-monoˡ-≤ ∣ xs n-1 ∣ (∑ᵀ-triangle-inequality xs m n-1 m<n) ⟩
∑ᵀ (λ k -> ∣ xs k ∣) m n-1 m<n + ∣ xs n-1 ∣ ∎
where open ≤-Reasoning
{-
Note that m ≤ n is required since, if m > n, then ∑ essentially flips m and n and may return a negative number.
-}
∑-triangle-inequality : ∀ (xs : ℕ -> ℝ) -> ∀ m n -> m ℕ.≤ n -> ∣ ∑ xs m n ∣ ≤ ∑ (λ k -> ∣ xs k ∣) m n
∑-triangle-inequality xs m n m≤n = begin
∣ ∑ xs m n ∣ ≈⟨ ∣-∣-cong (∑-to-∑ᵀ xs m n m≤n) ⟩
∣ ∑ᵀ xs m n m≤n ∣ ≤⟨ ∑ᵀ-triangle-inequality xs m n m≤n ⟩
∑ᵀ (λ k -> ∣ xs k ∣) m n m≤n ≈⟨ ≃-symm (∑-to-∑ᵀ (λ k -> ∣ xs k ∣) m n m≤n) ⟩
∑ (λ k -> ∣ xs k ∣) m n ∎
where open ≤-Reasoning
∑₀-mono-≤ : ∀ {xs ys} -> (∀ n -> xs n ≤ ys n) -> ∀ n -> ∑₀ xs n ≤ ∑₀ ys n
∑₀-mono-≤ {xs} {ys} xₙ≤yₙ 0 = ≤-refl
∑₀-mono-≤ {xs} {ys} xₙ≤yₙ (suc n) = +-mono-≤ (∑₀-mono-≤ xₙ≤yₙ n) (xₙ≤yₙ n)
∑ᵀ-mono-≤ : ∀ {xs ys} -> (∀ n -> xs n ≤ ys n) -> ∀ m n -> (m≤n : m ℕ.≤ n) -> ∑ᵀ xs m n m≤n ≤ ∑ᵀ ys m n m≤n
∑ᵀ-mono-≤ {xs} {ys} xₙ≤yₙ m n m≤n with ≤⇒≡∨< m n m≤n
... | inj₁ refl = ≤-refl
∑ᵀ-mono-≤ {xs} {ys} xₙ≤yₙ m (suc n-1) m≤n | inj₂ (ℕ.s≤s m<n) = +-mono-≤ (∑ᵀ-mono-≤ xₙ≤yₙ m n-1 m<n) (xₙ≤yₙ n-1)
∑-mono-≤ : ∀ {xs ys} -> (∀ n -> xs n ≤ ys n) -> ∀ m n -> m ℕ.≤ n -> ∑ xs m n ≤ ∑ ys m n
∑-mono-≤ {xs} {ys} xₙ≤yₙ m n m≤n = begin
∑ xs m n ≈⟨ ∑-to-∑ᵀ xs m n m≤n ⟩
∑ᵀ xs m n m≤n ≤⟨ ∑ᵀ-mono-≤ xₙ≤yₙ m n m≤n ⟩
∑ᵀ ys m n m≤n ≈⟨ ≃-symm (∑-to-∑ᵀ ys m n m≤n) ⟩
∑ ys m n ∎
where open ≤-Reasoning
neg-flips-∑ : ∀ (xs : ℕ -> ℝ) -> ∀ m n -> - ∑ xs m n ≃ ∑ xs n m
neg-flips-∑ xs 0 0 = ≃-symm 0≃-0
neg-flips-∑ xs 0 (suc n) = ≃-symm (+-identityˡ _)
neg-flips-∑ xs (suc m) zero = solve 1 (λ a -> ⊝ (Κ 0ℚᵘ ⊖ a) ⊜ a) ≃-refl (∑₀ xs (suc m))
neg-flips-∑ xs (suc m) (suc n) = solve 2 (λ a b -> ⊝ (a ⊖ b) ⊜ b ⊖ a) ≃-refl (∑₀ xs (suc n)) (∑₀ xs (suc m))
∑ᵀ-mono-≤-weak : ∀ {xs ys : ℕ -> ℝ} -> ∀ {m n} -> (m≤n : m ℕ.≤ n) -> (∀ k -> m ℕ.≤ k × k ℕ.≤ n -> xs k ≤ ys k) ->
∑ᵀ xs m n m≤n ≤ ∑ᵀ ys m n m≤n
∑ᵀ-mono-≤-weak {xs} {ys} {m} {n} m≤n hyp with ≤⇒≡∨< m n m≤n
... | inj₁ refl = ≤-refl
∑ᵀ-mono-≤-weak {xs} {ys} {m} {suc n-1} m≤n hyp | inj₂ (ℕ.s≤s m<n) = +-mono-≤
(∑ᵀ-mono-≤-weak m<n (λ k m≤k≤n-1 -> hyp k (proj₁ m≤k≤n-1 , ℕP.≤-trans (proj₂ m≤k≤n-1) (ℕP.n≤1+n n-1))))
(hyp n-1 (m<n , ℕP.n≤1+n n-1))
∑-mono-≤-weak : ∀ {xs ys : ℕ -> ℝ} -> ∀ {m n} -> m ℕ.≤ n -> (∀ k -> m ℕ.≤ k × k ℕ.≤ n -> xs k ≤ ys k) ->
∑ xs m n ≤ ∑ ys m n
∑-mono-≤-weak {xs} {ys} {m} {n} m≤n hyp = begin
∑ xs m n ≈⟨ ∑-to-∑ᵀ xs m n m≤n ⟩
∑ᵀ xs m n m≤n ≤⟨ ∑ᵀ-mono-≤-weak m≤n hyp ⟩
∑ᵀ ys m n m≤n ≈⟨ ≃-symm (∑-to-∑ᵀ ys m n m≤n) ⟩
∑ ys m n ∎
where open ≤-Reasoning
∑0≃0 : ∀ m n -> ∑ (λ k -> 0ℝ) m n ≃ 0ℝ
∑0≃0 zero n = lem n
where
lem : ∀ n -> ∑₀ (λ k -> 0ℝ) n ≃ 0ℝ
lem zero = ≃-refl
lem (suc n) = ≃-trans (+-identityʳ (∑₀ (λ k -> 0ℝ) n)) (lem n)
∑0≃0 (suc m) n = begin
∑₀ (λ k -> 0ℝ) n - (∑₀ (λ k -> 0ℝ) m + 0ℝ) ≈⟨ +-cong (∑0≃0 0 n) (-‿cong (∑0≃0 0 (suc m))) ⟩
0ℝ - 0ℝ ≈⟨ +-inverseʳ 0ℝ ⟩
0ℝ ∎
where open ≃-Reasoning
0≤xₙ⇒0≤∑xₙ : ∀ {xs : ℕ -> ℝ} -> ∀ {m n} -> m ℕ.≤ n -> (∀ k -> m ℕ.≤ k × k ℕ.≤ n -> 0ℝ ≤ xs k) ->
0ℝ ≤ ∑ xs m n
0≤xₙ⇒0≤∑xₙ {xs} {m} {n} m≤n hyp = begin
0ℝ ≈⟨ ≃-symm (∑0≃0 m n) ⟩
∑ (λ k -> 0ℝ) m n ≤⟨ ∑-mono-≤-weak m≤n hyp ⟩
∑ xs m n ∎
where open ≤-Reasoning
nonNegxₙ⇒nonNeg∑xₙ : ∀ {xs : ℕ -> ℝ} -> ∀ {m n} -> m ℕ.≤ n -> (∀ k -> m ℕ.≤ k × k ℕ.≤ n -> NonNegative (xs k)) ->
NonNegative (∑ xs m n)
nonNegxₙ⇒nonNeg∑xₙ {xs} {m} {n} m≤n hyp = nonNeg-cong (lem (∑ xs m n))
(0≤xₙ⇒0≤∑xₙ m≤n (λ k m≤k≤n -> nonNeg-cong (≃-symm (lem (xs k))) (hyp k m≤k≤n)))
where
lem : ∀ x -> x - 0ℝ ≃ x
lem = solve 1 (λ x -> x ⊖ Κ 0ℚᵘ ⊜ x) ≃-refl
cauchy-convergence : ∀ {xs : ℕ -> ℝ} ->
(∀ k -> {k≢0 : k ≢0} -> ∃ λ Nₖ-1 -> ∀ m n -> m ℕ.> n -> n ℕ.≥ suc Nₖ-1 -> ∣ xs m - xs n ∣ ≤ ((+ 1 / k) {k≢0}) ⋆) ->
xs isConvergent
cauchy-convergence {xs} hyp = fast-cauchy⇒convergent (cauchy* main)
where
main : ∀ k -> {k≢0 : k ≢0} -> ∃ λ Mₖ-1 -> ∀ m n -> m ℕ.≥ suc Mₖ-1 -> n ℕ.≥ suc Mₖ-1 ->
∣ xs m - xs n ∣ ≤ ((+ 1 / k) {k≢0}) ⋆
main (suc k-1) = ℕ.pred Mₖ , sub
where
open ≤-Reasoning
k = suc k-1
Mₖ = suc (proj₁ (hyp k))
sub : ∀ m n -> m ℕ.≥ Mₖ -> n ℕ.≥ Mₖ -> ∣ xs m - xs n ∣ ≤ (+ 1 / k) ⋆
sub m n m≥Mₖ n≥Mₖ with ℕP.<-cmp m n
... | tri< m<n ¬b ¬c = begin
∣ xs m - xs n ∣ ≈⟨ ∣x-y∣≃∣y-x∣ (xs m) (xs n) ⟩
∣ xs n - xs m ∣ ≤⟨ proj₂ (hyp k) n m m<n m≥Mₖ ⟩
(+ 1 / k) ⋆ ∎
... | tri≈ ¬a refl ¬c = begin
∣ xs m - xs m ∣ ≈⟨ ≃-trans (∣-∣-cong (+-inverseʳ (xs m))) (0≤x⇒∣x∣≃x ≤-refl) ⟩
0ℝ ≤⟨ p≤q⇒p⋆≤q⋆ 0ℚᵘ (+ 1 / k) (ℚP.nonNegative⁻¹ _) ⟩
(+ 1 / k) ⋆ ∎
... | tri> ¬a ¬b m>n = proj₂ (hyp k) m n m>n n≥Mₖ
{-
This is a generalized version of Bishop's Proposition 3.5.
Proposition:
If ∑yₙ converges and if there is N∈ℕ such that
∣xₙ∣ ≤ yₙ (n ≥ N),
then ∑xₙ converges.
Proof:
Let k∈ℕ. Then there is N₂∈ℕ such that
∣∑ᵢ₌ₙ₊₁ᵐ yᵢ∣ ≤ k⁻¹ (m > n ≥ N₂).
Let N₂∈ℕ such that ∣xₙ∣ ≤ yₙ for n ≥ N₁. Define N = max{N₁, N₂} and let
m > n ≥ N. Then
∣∑ᵢ₌ₙ₊₁ᵐ xᵢ∣ ≤ ∑ᵢ₌ₙ₊₁ᵐ ∣xᵢ∣
≤ ∑ᵢ₌ₙ₊₁ᵐ yᵢ since m > n ≥ N₁
≤ ∣∑ᵢ₌ₙ₊₁ᵐ yᵢ∣
≤ k⁻¹.
Hence ∑xᵢ is convergent. □
[2]
-}
proposition-3-5 : ∀ {xs ys} -> SeriesOf ys isConvergent -> (∃ λ N-1 -> ∀ n -> n ℕ.≥ suc N-1 -> ∣ xs n ∣ ≤ ys n) ->
SeriesOf xs isConvergent
proposition-3-5 {xs} {ys} ∑ysCon (N₁-1 , n≥N₁⇒∣xₙ∣≤yₙ) = cauchy-convergence (λ {(suc k-1) ->
let k = suc k-1; ∑ysCauchy = cauchyConvergenceTest-if ys ∑ysCon k
; N₁ = suc N₁-1; N₂ = suc (proj₁ ∑ysCauchy); N = N₁ ℕ.⊔ N₂ in ℕ.pred N ,
λ {(suc m-1) (suc n-1) m>n n≥N ->
let m = suc m-1; n = suc n-1; N₂≤N = ℕP.m≤n⊔m N₁ N₂
; m≥N = ℕP.<⇒≤ (ℕP.<-transʳ n≥N m>n) in begin
∣ ∑ xs n m ∣ ≤⟨ ∑-triangle-inequality xs n m (ℕP.<⇒≤ m>n) ⟩
∑ (λ i -> ∣ xs i ∣) n m ≤⟨ ∑-mono-≤-weak (ℕP.<⇒≤ m>n) (λ k n≤k≤m -> n≥N₁⇒∣xₙ∣≤yₙ k
(ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) n≥N) (proj₁ n≤k≤m))) ⟩
∑ ys n m ≤⟨ x≤∣x∣ ⟩
∣ ∑ ys n m ∣ ≤⟨ proj₂ ∑ysCauchy n m
(ℕP.≤-trans N₂≤N n≥N) (ℕP.≤-trans N₂≤N m≥N) ⟩
(+ 1 / k) ⋆ ∎}})
where
open ≤-Reasoning
absolute⇒isConvergent : ∀ {xs : ℕ -> ℝ} -> SeriesOf xs ConvergesAbsolutely -> SeriesOf xs isConvergent
absolute⇒isConvergent {xs} hyp = proposition-3-5 hyp (0 , (λ n n≥1 -> ≤-refl))
lim : {xs : ℕ -> ℝ} -> xs isConvergent -> ℝ
lim {xs} (ℓ , hyp) = ℓ
reordering : ∀ {xs : ℕ -> ℝ} -> (hyp : SeriesOf xs ConvergesAbsolutely) ->
∀ {f : ℕ -> ℕ} -> IsBijection f -> SeriesOf (λ n -> xs (f n)) ConvergesTo lim (absolute⇒isConvergent hyp)
reordering {xs} hyp {f} fBi = {!!}
{-
(xₙ) diverges
If ∃ε>0 ∀k∈ℕ ∃m,n≥k ( ∣xₘ - xₙ∣ ≥ ε )
-}
data _DivergesBy_ : REL (ℕ -> ℝ) ℝ 0ℓ where
div* : {f : ℕ -> ℝ} -> {ε : ℝ} -> Positive ε ->
(∀ k -> {k≢0 : k ≢0} -> (∃ λ m -> ∃ λ n -> m ℕ.≥ k × n ℕ.≥ k × ∣ f m - f n ∣ ≥ ε)) ->
f DivergesBy ε
_isDivergent : (ℕ -> ℝ) -> Set
f isDivergent = ∃ λ ε -> f DivergesBy ε
cauchy-getter : ∀ {xs} -> xs isCauchy ->
∀ k -> {k≢0 : k ≢0} -> ∃ λ Mₖ-1 -> ∀ m n -> m ℕ.≥ suc Mₖ-1 -> n ℕ.≥ suc Mₖ-1 ->
∣ xs m - xs n ∣ ≤ ((+ 1 / k) {k≢0}) ⋆
cauchy-getter {xs} (cauchy* hyp) = hyp
abstract
fast-cauchy-getter : ∀ {xs} -> xs isCauchy ->
∀ k -> {k≢0 : k ≢0} -> ∃ λ Mₖ-1 -> ∀ m n -> m ℕ.≥ suc Mₖ-1 -> n ℕ.≥ suc Mₖ-1 ->
∣ xs m - xs n ∣ ≤ ((+ 1 / k) {k≢0}) ⋆
fast-cauchy-getter = cauchy-getter
¬[isConvergent∧isDivergent] : ∀ xs -> ¬ (xs isConvergent × xs isDivergent)
¬[isConvergent∧isDivergent] xs (hyp1 , ε , div* posε hyp2) = let fromdiv = archimedean-ℝ₂ posε; k = suc (proj₁ fromdiv)
; fromhyp1 = cauchy-getter (fast-convergent⇒cauchy hyp1) k
; Nₖ = suc (proj₁ fromhyp1)
; m = proj₁ (hyp2 Nₖ)
; n = proj₁ (proj₂ (hyp2 Nₖ)) in
<-irrefl ≃-refl (begin-strict
(+ 1 / k) ⋆ <⟨ proj₂ fromdiv ⟩
ε ≤⟨ proj₂ (proj₂ (proj₂ (proj₂ (hyp2 Nₖ)))) ⟩
∣ xs m - xs n ∣ ≤⟨ proj₂ fromhyp1 m n
(proj₁ (proj₂ (proj₂ (hyp2 Nₖ))))
(proj₁ (proj₂ (proj₂ (proj₂ (hyp2 Nₖ))))) ⟩
(+ 1 / k) ⋆ ∎)
where open ≤-Reasoning
{-
(xₙ) is a subsequence of (yₙ) if there is h : ℕ -> ℕ such that
xₙ = yₕ₍ₙ₎ (n∈ℕ)
and
h(n) < h(n+1) (n∈ℕ).
[3]
-}
data _SubsequenceOf_ : Rel (ℕ -> ℝ) 0ℓ where
subseq* : {xs ys : ℕ -> ℝ} -> (∃ λ (f : ℕ -> ℕ) ->
(∀ n -> xs n ≃ ys (f n)) × (∀ n -> f n ℕ.< f (suc n))) ->
xs SubsequenceOf ys
{-
Not sure what a more meaningful name for this is yet.
-}
subsequence-helper : ∀ {f : ℕ -> ℕ} -> ∀ (k : ℕ) -> (∀ n -> f n ℕ.< f (suc n)) ->
∃ λ (N : ℕ) -> ∀ n -> n ℕ.> N -> f n ℕ.> k
subsequence-helper {f} zero hyp = 0 , λ {(suc n-1) n>0 → ℕP.<-transʳ ℕ.z≤n (hyp n-1)}
subsequence-helper {f} (suc k) hyp = let ih = subsequence-helper k hyp; N = suc (proj₁ ih) in
N , λ {(suc n-1) (ℕ.s≤s n>N) → ℕP.<-transʳ (proj₂ ih n-1 n>N) (hyp n-1)}
f[n]<f[n+1]⇒n≤f[n] : ∀ {f : ℕ -> ℕ} -> (∀ n -> f n ℕ.< f (suc n)) -> (∀ n -> n ℕ.≤ f n)
f[n]<f[n+1]⇒n≤f[n] {f} f[n]<f[n+1] 0 = ℕ.z≤n
f[n]<f[n+1]⇒n≤f[n] {f} f[n]<f[n+1] (suc n) = ℕP.<-transʳ (f[n]<f[n+1]⇒n≤f[n] f[n]<f[n+1] n) (f[n]<f[n+1] n)
{-
As per Bishop, the series ∑xᵢ is divergent if there is positive r∈ℝ such that ∣xₙ∣ ≥ r for infinitely many n.
Alternatively, ∑xᵢ is divergent if there is positive r∈ℝ and a subsequence (yₙ) of (xₙ) such that ∣yₙ∣ ≥ r for
all n∈ℕ.
Proposition:
If there is positive r∈ℝ such that r ≤ ∣xₙ∣ for infinitely many n, then ∑xᵢ diverges.
Proof:
Let (xₕ₍ₙ₎) be a subsequence of (xₙ) such that r ≤ ∣xₕ₍ₙ₎∣ for all n∈ℕ. Note that h(n) < h(n+1) for all n∈ℕ,
so n ≤ h(n) for all n∈ℕ. Let k∈ℕ. Then k ≤ f(k), and we have:
∣ ∑ xs 0 h(k)+1 - ∑ xs 0 h(k) ∣ = ∣ xₕ₍ₖ₎ ∣ ≥ r.
Thus the sum diverges. □
-}
subsequence-divergence-test : ∀ {xs : ℕ -> ℝ} ->
(∃ λ (r : ℝ) -> ∃ λ (ys : ℕ -> ℝ) -> Positive r × ys SubsequenceOf xs × (∀ n -> ∣ ys n ∣ ≥ r)) ->
SeriesOf xs isDivergent
subsequence-divergence-test {xs} (r , ys , posr , subseq* (f , yₙ⊂xₙ) , ∣yₙ∣≥r) =
r , div* posr (λ k -> let k≤f[k] = f[n]<f[n+1]⇒n≤f[n] (proj₂ yₙ⊂xₙ) k in
suc (f k) , f k , ℕP.≤-trans k≤f[k] (ℕP.n≤1+n (f k)) , k≤f[k] , (begin
r ≤⟨ ∣yₙ∣≥r k ⟩
∣ ys k ∣ ≈⟨ ∣-∣-cong (proj₁ yₙ⊂xₙ k) ⟩
∣ xs (f k) ∣ ≈⟨ ∣-∣-cong (solve 2 (λ a b -> a ⊜ b ⊕ a ⊖ b) ≃-refl (xs (f k)) (∑₀ xs (f k))) ⟩
∣ ∑₀ xs (suc (f k)) - ∑₀ xs (f k) ∣ ∎))
where open ≤-Reasoning
{-
[4]
Proposition:
Let (yₙ) be a sequence with a nonnegative tail (i.e. ∃N₁∈ℕ ∀n≥N₁[yₙ ≥ 0]). Suppose that
∃N₂∈ℕ ∀n≥N₂[xₙ ≥ yₙ], and that ∑yᵢ is divergent. Then ∑xᵢ is divergent.
Proof:
Let ε>0 such that ∑yᵢ diverges by ε. Define N = max{N₁, N₂}. Then there is m,n ≥ N such that
∑ᵢ₌ₙᵐ yᵢ = ∣∑ᵢ₌ₙᵐ yᵢ∣ ≥ ε.
Suppose, WLOG, that m ≥ n. Then:
∣∑ᵢ₌ₙᵐ xᵢ∣ = ∑ᵢ₌ₙᵐ xᵢ
≥ ∑ᵢ₌ₙᵐ yᵢ
≥ ε.
Thus ∑xᵢ diverges by ε. □
Bishop assumes that
(i) (xₙ) is a sequence of nonnegative terms, and
(ii) (yₙ) is a nonnegative sequence.
The first could obviously be removed since xₙ ≥ yₙ eventually, and the second could be modified
so that yₙ ≥ 0 eventually. The distinction doesn't matter informally of course, but we adopt it
since we don't have the benefit of saying "it's a trivial extension of this result" without proof.
-}
comparison-test-divergence : ∀ {xs ys : ℕ -> ℝ} -> (∃ λ N₁ -> ∀ n -> n ℕ.≥ N₁ -> NonNegative (ys n)) ->
SeriesOf ys isDivergent -> (∃ λ N₂ -> ∀ n -> n ℕ.≥ N₂ -> xs n ≥ ys n) ->
SeriesOf xs isDivergent
comparison-test-divergence {xs} {ys} (N₁ , n≥N₁⇒yₙ≥0) (ε , div* posε div∑yₙ) (N₂ , n≥N₂⇒xₙ≥yₙ) = ε , div* posε main
where
main : ∀ k -> {k ≢0} -> ∃ λ m -> ∃ λ n -> m ℕ.≥ k × n ℕ.≥ k × ∣ ∑₀ xs m - ∑₀ xs n ∣ ≥ ε
main (suc N₃-1) = let m = proj₁ (div∑yₙ N); n = proj₁ (proj₂ (div∑yₙ N))
; N≤m = proj₁ (proj₂ (proj₂ (div∑yₙ N))); N≤n = proj₁ (proj₂ (proj₂ (proj₂ (div∑yₙ N))))
; ∑yₙhyp = proj₂ (proj₂ (proj₂ (proj₂ (div∑yₙ N)))) in
m , n , ℕP.≤-trans N₃≤N N≤m , ℕP.≤-trans N₃≤N N≤n ,
[ (λ m≥n -> sub m n N≤m N≤n m≥n ∑yₙhyp) ,
(λ m≤n -> ≤-respʳ-≃ (∣x-y∣≃∣y-x∣ (∑₀ xs n) (∑₀ xs m)) (sub n m N≤n N≤m m≤n
(≤-respʳ-≃ (∣x-y∣≃∣y-x∣ (∑₀ ys m) (∑₀ ys n)) ∑yₙhyp))) ]′ (ℕP.≤-total n m)
where
open ≤-Reasoning
N₃ = suc N₃-1
N = suc (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃)
N₁≤N = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃)) (ℕP.n≤1+n (ℕ.pred N))
N₂≤N = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃)) (ℕP.n≤1+n (ℕ.pred N))
N₃≤N = ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃) (ℕP.n≤1+n (ℕ.pred N))
sub : ∀ m n -> m ℕ.≥ N -> n ℕ.≥ N -> m ℕ.≥ n -> ∣ ∑₀ ys m - ∑₀ ys n ∣ ≥ ε -> ∣ ∑₀ xs m - ∑₀ xs n ∣ ≥ ε
sub (suc m-1) (suc n-1) m≥N n≥N m≥n hyp = let m = suc m-1; n = suc n-1 in begin
ε ≤⟨ hyp ⟩
∣ ∑ ys n m ∣ ≈⟨ nonNegx⇒∣x∣≃x (nonNegxₙ⇒nonNeg∑xₙ m≥n (λ k n≤k≤m -> n≥N₁⇒yₙ≥0 k
(ℕP.≤-trans (ℕP.≤-trans N₁≤N n≥N) (proj₁ n≤k≤m)))) ⟩
∑ ys n m ≤⟨ ∑-mono-≤-weak m≥n (λ k n≤k≤m -> n≥N₂⇒xₙ≥yₙ k
(ℕP.≤-trans (ℕP.≤-trans N₂≤N n≥N) (proj₁ n≤k≤m))) ⟩
∑ xs n m ≤⟨ x≤∣x∣ ⟩
∣ ∑ xs n m ∣ ∎
pow : ℝ -> ℕ -> ℝ
pow x 0 = 1ℝ
pow x (suc n) = pow x n * x
pow-cong : ∀ {x y} -> ∀ n -> x ≃ y -> pow x n ≃ pow y n
pow-cong {x} {y} zero x≃y = ≃-refl
pow-cong {x} {y} (suc n) x≃y = *-cong (pow-cong n x≃y) x≃y
xⁿxᵐ≃xⁿ⁺ᵐ : ∀ x -> ∀ n m -> (pow x n) * (pow x m) ≃ pow x (n ℕ.+ m)
xⁿxᵐ≃xⁿ⁺ᵐ x zero m = *-identityˡ (pow x m)
xⁿxᵐ≃xⁿ⁺ᵐ x (suc n) m = begin
pow x n * x * pow x m ≈⟨ solve 3 (λ xⁿ x xᵐ -> xⁿ ⊗ x ⊗ xᵐ ⊜ xⁿ ⊗ xᵐ ⊗ x)
≃-refl (pow x n) x (pow x m) ⟩
pow x n * pow x m * x ≈⟨ *-congʳ (xⁿxᵐ≃xⁿ⁺ᵐ x n m) ⟩
pow x (n ℕ.+ m) * x ≈⟨ ≃-refl ⟩
pow x (1 ℕ.+ (n ℕ.+ m)) ≡⟨ cong (λ k -> pow x k) (sym (ℕP.+-assoc 1 n m)) ⟩
pow x ((1 ℕ.+ n) ℕ.+ m) ∎
where open ≃-Reasoning
archimedean-ℝ₃ : ∀ {x} y -> Positive x -> ∃ λ n-1 -> (+ (suc n-1) / 1) ⋆ * x > y
archimedean-ℝ₃ {x} y posx = let x≄0 = inj₂ (posx⇒0<x posx); x⁻¹ = (x ⁻¹) x≄0
; arch = fast-archimedean-ℝ (y * x⁻¹); n = suc (proj₁ arch) in
ℕ.pred n , (begin-strict
y ≈⟨ ≃-symm (≃-trans (≃-trans (*-assoc y x⁻¹ x)
(*-congˡ {y} {x⁻¹ * x} {1ℝ} (*-inverseˡ x x≄0))) (*-identityʳ y)) ⟩
y * x⁻¹ * x <⟨ *-monoˡ-<-pos {x} posx {y * x⁻¹} {(+ n / 1) ⋆} (proj₂ arch) ⟩
(+ n / 1) ⋆ * x ∎)
where open ≤-Reasoning
abstract
fast-archimedean-ℝ₃ : ∀ {x} y -> Positive x -> ∃ λ n-1 -> (+ (suc n-1) / 1) ⋆ * x > y
fast-archimedean-ℝ₃ = archimedean-ℝ₃
x≤y∧posx⇒y⁻¹≤x⁻¹ : ∀ {x y} -> x ≤ y -> Positive x -> (x≄0 : x ≄0) -> (y≄0 : y ≄0) ->
(y ⁻¹) y≄0 ≤ (x ⁻¹) x≄0
x≤y∧posx⇒y⁻¹≤x⁻¹ {x} {y} x≤y posx x≄0 y≄0 = let x⁻¹ = (x ⁻¹) x≄0; y⁻¹ = (y ⁻¹) y≄0 in begin
y⁻¹ ≈⟨ ≃-symm (≃-trans (*-congˡ {y⁻¹} {x * x⁻¹} {1ℝ} (*-inverseʳ x x≄0)) (*-identityʳ y⁻¹)) ⟩
y⁻¹ * (x * x⁻¹) ≤⟨ *-monoˡ-≤-nonNeg {x * x⁻¹} {y⁻¹} {y * x⁻¹}
(*-monoʳ-≤-nonNeg {x} {x⁻¹} {y} x≤y (nonNegx⇒nonNegx⁻¹ {x} (pos⇒nonNeg posx) x≄0))
(nonNegx⇒nonNegx⁻¹ {y} (pos⇒nonNeg (0<x⇒posx (<-≤-trans (posx⇒0<x posx) x≤y))) y≄0) ⟩
y⁻¹ * (y * x⁻¹) ≈⟨ ≃-trans (≃-trans (≃-symm (*-assoc y⁻¹ y x⁻¹))
(*-congʳ {x⁻¹} {y⁻¹ * y} {1ℝ} (*-inverseˡ y y≄0))) (*-identityˡ x⁻¹) ⟩
x⁻¹ ∎
where open ≤-Reasoning
x<y⇒∃ε>0[x<x+ε<y] : ∀ {x y} -> x < y -> ∃ λ ε -> Positive ε × x < (x + ε) < y
x<y⇒∃ε>0[x<x+ε<y] {x} {y} x<y = let r-get = fast-density-of-ℚ x y x<y; r = proj₁ r-get
; r≃x+r-x = solve 2 (λ r x -> r ⊜ x ⊕ (r ⊖ x)) ≃-refl (r ⋆) x in
r ⋆ - x , 0<x⇒posx (x<y⇒0<y-x x (r ⋆) (proj₁ (proj₂ r-get))) ,
<-respʳ-≃ r≃x+r-x (proj₁ (proj₂ r-get)) , <-respˡ-≃ r≃x+r-x (proj₂ (proj₂ r-get))
0≤x,y⇒0≤x*y : ∀ {x y} -> 0ℝ ≤ x -> 0ℝ ≤ y -> 0ℝ ≤ x * y
0≤x,y⇒0≤x*y {x} {y} 0≤x 0≤y = nonNegx⇒0≤x (nonNegx,y⇒nonNegx*y (0≤x⇒nonNegx 0≤x) (0≤x⇒nonNegx 0≤y))
private
p²≥0 : ∀ p -> p ℚ.* p ℚ.≥ 0ℚᵘ
p²≥0 (mkℚᵘ (+_ zero) d) = ℚP.nonNegative⁻¹ _
p²≥0 (mkℚᵘ +[1+ n ] d) = ℚP.nonNegative⁻¹ _
p²≥0 (mkℚᵘ (-[1+_] n) d) = ℚP.nonNegative⁻¹ _
x²ⁿ≥0 : ∀ x -> ∀ n -> pow x (2 ℕ.* n) ≥ 0ℝ
x²ⁿ≥0 x n = begin
0ℝ ≤⟨ nonNegx⇒0≤x (nonNeg* (λ {(suc k-1) ->
ℚP.≤-trans (ℚP.nonPositive⁻¹ _)
(p²≥0 (seq (pow x n) _))})) ⟩
pow x n * pow x n ≈⟨ xⁿxᵐ≃xⁿ⁺ᵐ x n n ⟩
pow x (n ℕ.+ n) ≡⟨ cong (λ k -> pow x k) (ℤP.+-injective (ℤsolve 1 (λ n ->
n :+ n := (n :+ (n :+ ℤΚ (+ 0)))) refl (+ n))) ⟩
pow x (2 ℕ.* n) ∎
where open ≤-Reasoning
0≤x⇒y≤y+x : ∀ {x} y -> 0ℝ ≤ x -> y ≤ y + x
0≤x⇒y≤y+x {x} y 0≤x = begin
y ≈⟨ ≃-symm (+-identityʳ y) ⟩
y + 0ℝ ≤⟨ +-monoʳ-≤ y 0≤x ⟩
y + x ∎
where open ≤-Reasoning
bernoullis-inequality : ∀ {x} -> x ≥ - 1ℝ -> ∀ (n : ℕ) -> pow (1ℝ + x) n ≥ 1ℝ + (+ n / 1) ⋆ * x
bernoullis-inequality {x} x≥-1 0 = ≤-reflexive (solve 1 (λ x -> Κ 1ℚᵘ ⊕ Κ 0ℚᵘ ⊗ x ⊜ Κ 1ℚᵘ) ≃-refl x)
bernoullis-inequality {x} x≥-1 (suc n-1) = let n = suc n-1 in begin
1ℝ + (+ n / 1) ⋆ * x ≈⟨ ≃-symm (+-congʳ 1ℝ (*-congʳ {x} (≃-trans
(solve 0 (Κ 1ℚᵘ ⊕ Κ (+ n-1 / 1) ⊜ Κ (1ℚᵘ ℚ.+ + n-1 / 1)) ≃-refl)
(⋆-cong (ℚ.*≡* (ℤsolve 1 (λ n-1 ->
(ℤΚ (+ 1) :+ n-1 :* ℤΚ (+ 1)) :* ℤΚ (+ 1) :=
(ℤΚ (+ 1) :+ n-1) :* ℤΚ (+ 1)) refl (+ n-1))))))) ⟩
1ℝ + (1ℝ + (+ n-1 / 1) ⋆) * x ≤⟨ 0≤x⇒y≤y+x {(+ n-1 / 1) ⋆ * (x * x)} (1ℝ + (1ℝ + (+ n-1 / 1) ⋆) * x)
(0≤x,y⇒0≤x*y (p≤q⇒p⋆≤q⋆ 0ℚᵘ (+ n-1 / 1) (ℚP.nonNegative⁻¹ _))
(≤-respʳ-≃ (solve 1 (λ x -> Κ 1ℚᵘ ⊗ x ⊗ x ⊜ x ⊗ x) ≃-refl x) (x²ⁿ≥0 x 1))) ⟩
1ℝ + (1ℝ + (+ n-1 / 1) ⋆) * x + (+ n-1 / 1) ⋆ * (x * x) ≈⟨ solve 3 (λ 1ℝ n-1 x ->
Κ 1ℚᵘ ⊕ (1ℝ ⊕ n-1) ⊗ x ⊕ n-1 ⊗ (x ⊗ x) ⊜
Κ 1ℚᵘ ⊕ 1ℝ ⊗ x ⊕ n-1 ⊗ x ⊕ n-1 ⊗ x ⊗ x)
≃-refl 1ℝ ((+ n-1 / 1) ⋆) x ⟩
1ℝ + 1ℝ * x + (+ n-1 / 1) ⋆ * x + (+ n-1 / 1) ⋆ * x * x ≈⟨ solve 2 (λ n-1 x ->
Κ 1ℚᵘ ⊕ Κ 1ℚᵘ ⊗ x ⊕ n-1 ⊗ x ⊕ n-1 ⊗ x ⊗ x ⊜
(Κ 1ℚᵘ ⊕ n-1 ⊗ x) ⊗ (Κ 1ℚᵘ ⊕ x))
≃-refl ((+ n-1 / 1) ⋆) x ⟩
(1ℝ + (+ n-1 / 1) ⋆ * x) * (1ℝ + x) ≤⟨ *-monoʳ-≤-nonNeg {1ℝ + (+ n-1 / 1) ⋆ * x} {1ℝ + x}
{pow (1ℝ + x) n-1}
(bernoullis-inequality {x} x≥-1 n-1)
(nonNeg-cong {x - - 1ℝ} {1ℝ + x}
(solve 1 (λ x -> x ⊖ (⊝ Κ 1ℚᵘ) ⊜ Κ 1ℚᵘ ⊕ x) ≃-refl x)
x≥-1) ⟩
pow (1ℝ + x) n-1 * (1ℝ + x) ∎
where open ≤-Reasoning
x≄0⇒xⁿ≄0 : ∀ {x} -> ∀ n -> x ≄0 -> pow x n ≄0
x≄0⇒xⁿ≄0 {x} zero x≄0 = inj₂ (p<q⇒p⋆<q⋆ 0ℚᵘ 1ℚᵘ (ℚP.positive⁻¹ _))
x≄0⇒xⁿ≄0 {x} (suc n) x≄0 = x≄0∧y≄0⇒x*y≄0 (x≄0⇒xⁿ≄0 n x≄0) x≄0
[xⁿ]⁻¹≃[x⁻¹]ⁿ : ∀ {x} -> (x≄0 : x ≄0) -> ∀ n -> (xⁿ≄0 : pow x n ≄0) -> ((pow x n) ⁻¹) xⁿ≄0 ≃ pow ((x ⁻¹) x≄0) n
[xⁿ]⁻¹≃[x⁻¹]ⁿ {x} x≄0 zero xⁿ≄0 = ⋆-distrib-⁻¹ 1ℚᵘ xⁿ≄0
[xⁿ]⁻¹≃[x⁻¹]ⁿ {x} x≄0 (suc n) xⁿ⁺¹≄0 = let xⁿ≄0 = x≄0⇒xⁿ≄0 {x} n x≄0 in begin
((pow x n * x) ⁻¹) xⁿ⁺¹≄0 ≈⟨ fast-⁻¹-distrib-* {pow x n} {x} xⁿ≄0 x≄0 xⁿ⁺¹≄0 ⟩
((pow x n) ⁻¹) xⁿ≄0 * (x ⁻¹) x≄0 ≈⟨ *-congʳ {(x ⁻¹) x≄0} {(pow x n ⁻¹) xⁿ≄0} {pow ((x ⁻¹) x≄0) n}
([xⁿ]⁻¹≃[x⁻¹]ⁿ {x} x≄0 n xⁿ≄0) ⟩
pow ((x ⁻¹) x≄0) n * (x ⁻¹) x≄0 ∎
where open ≃-Reasoning
1≤x∧m≤n⇒xᵐ≤xⁿ : ∀ {x} -> ∀ {m n} -> 1ℝ ≤ x -> m ℕ.≤ n -> pow x m ≤ pow x n
1≤x∧m≤n⇒xᵐ≤xⁿ {x} {zero} {zero} 1≤x m≤n = ≤-refl
1≤x∧m≤n⇒xᵐ≤xⁿ {x} {zero} {suc n} 1≤x m≤n = lem (suc n)
where
open ≤-Reasoning
lem : ∀ n -> 1ℝ ≤ pow x n
lem zero = ≤-refl
lem (suc n) = begin
1ℝ ≤⟨ 1≤x ⟩
x ≈⟨ ≃-symm (*-identityˡ x) ⟩
1ℝ * x ≤⟨ *-monoʳ-≤-nonNeg (lem n)
(0≤x⇒nonNegx (≤-trans (p≤q⇒p⋆≤q⋆ 0ℚᵘ 1ℚᵘ (ℚP.nonNegative⁻¹ _)) 1≤x)) ⟩
pow x n * x ∎
1≤x∧m≤n⇒xᵐ≤xⁿ {x} {suc m} {suc n} 1≤x (ℕ.s≤s m≤n) = *-monoʳ-≤-nonNeg (1≤x∧m≤n⇒xᵐ≤xⁿ 1≤x m≤n)
(0≤x⇒nonNegx (≤-trans (p≤q⇒p⋆≤q⋆ 0ℚᵘ 1ℚᵘ (ℚP.nonNegative⁻¹ _)) 1≤x))
nonNegx⇒nonNegxⁿ : ∀ {x} -> ∀ n -> NonNegative x -> NonNegative (pow x n)
nonNegx⇒nonNegxⁿ {x} zero nonx = nonNegp⇒nonNegp⋆ 1ℚᵘ _
nonNegx⇒nonNegxⁿ {x} (suc n) nonx = nonNegx,y⇒nonNegx*y (nonNegx⇒nonNegxⁿ n nonx) nonx
0<r<1⇒rⁿ→0 : ∀ {r} -> 0ℝ < r < 1ℝ ->
∀ j -> {j≢0 : j ≢0} -> ∃ λ Nₖ-1 -> ∀ n -> n ℕ.≥ suc Nₖ-1 -> pow r n ≤ ((+ 1 / j) {j≢0}) ⋆
0<r<1⇒rⁿ→0 {r} (0<r , r<1) (suc j-1) = let j = suc j-1; j⋆≄0 = ∣↥p∣≢0⇒p⋆≄0 (+ j / 1) _; N = suc (proj₁ (lem j)) in
ℕ.pred N , λ n n≥N -> begin
pow r n ≈⟨ pow-cong n (≃-symm (⁻¹-involutive {r} r≄0 t≄0)) ⟩
pow ((t ⁻¹) t≄0) n ≈⟨ ≃-symm ([xⁿ]⁻¹≃[x⁻¹]ⁿ {t} t≄0 n (tⁿ≄0 n)) ⟩
((pow t n) ⁻¹) (tⁿ≄0 n) ≤⟨ x≤y∧posx⇒y⁻¹≤x⁻¹ {(+ j / 1) ⋆} {pow t n} (proj₂ (lem j) n n≥N) (posp⇒posp⋆ (+ j / 1) _) j⋆≄0 (tⁿ≄0 n) ⟩
(((+ j / 1) ⋆) ⁻¹) j⋆≄0 ≈⟨ ⋆-distrib-⁻¹ (+ j / 1) j⋆≄0 ⟩
(+ 1 / j) ⋆ ∎
where
open ≤-Reasoning
r≄0 = inj₂ 0<r
t = (r ⁻¹) r≄0
1<t : 1ℝ < t
1<t = let 0<1 = p<q⇒p⋆<q⋆ 0ℚᵘ 1ℚᵘ (ℚP.positive⁻¹ _); 1≄0 = inj₂ 0<1 in begin-strict
1ℝ ≈⟨ ≃-symm (⋆-distrib-⁻¹ 1ℚᵘ 1≄0) ⟩
(((+ 1 / 1) ⋆) ⁻¹) 1≄0 <⟨ x<y∧posx,y⇒y⁻¹<x⁻¹ {r} {1ℝ} r<1 r≄0 1≄0 (0<x⇒posx 0<r) (0<x⇒posx 0<1) ⟩
t ∎
t≄0 = inj₂ (0<x⇒0<x⁻¹ {r} r≄0 0<r)
tⁿ≄0 : ∀ n -> pow t n ≄0
tⁿ≄0 0 = inj₂ (p<q⇒p⋆<q⋆ 0ℚᵘ 1ℚᵘ (ℚP.positive⁻¹ _))
tⁿ≄0 (suc n) = x≄0∧y≄0⇒x*y≄0 (tⁿ≄0 n) t≄0
arch = fast-archimedean-ℝ₃ {t - 1ℝ} 1ℝ 1<t
k = suc (proj₁ arch)
-1≤t-1 : - 1ℝ ≤ t - 1ℝ
-1≤t-1 = begin
- 1ℝ ≈⟨ ≃-symm (⋆-distrib-neg 1ℚᵘ) ⟩
(ℚ.- 1ℚᵘ) ⋆ ≤⟨ p≤q⇒p⋆≤q⋆ (ℚ.- 1ℚᵘ) 0ℚᵘ (ℚP.nonPositive⁻¹ _) ⟩
0ℝ ≤⟨ x≤y⇒0≤y-x (<⇒≤ 1<t) ⟩
t - 1ℝ ∎
tᵏⁿ≥n : ∀ n -> {n ≢0} -> pow t (k ℕ.* n) ≥ (+ n / 1) ⋆
tᵏⁿ≥n (suc n-1) = let n = suc n-1 in begin
(+ n / 1) ⋆ ≈⟨ ≃-symm (*-identityˡ ((+ n / 1) ⋆)) ⟩
1ℝ * (+ n / 1) ⋆ ≤⟨ *-monoʳ-≤-nonNeg {1ℝ} {(+ n / 1) ⋆} {(+ k / 1) ⋆ * (t - 1ℝ)}
(<⇒≤ (proj₂ arch)) (nonNegp⇒nonNegp⋆ (+ n / 1) _) ⟩
(+ k / 1) ⋆ * (t - 1ℝ) * (+ n / 1) ⋆ ≈⟨ solve 3 (λ a b c -> a ⊗ b ⊗ c ⊜ a ⊗ c ⊗ b) ≃-refl ((+ k / 1) ⋆) (t - 1ℝ) ((+ n / 1) ⋆) ⟩
(+ k / 1) ⋆ * (+ n / 1) ⋆ * (t - 1ℝ) ≈⟨ solve 1 (λ t-1 -> Κ (+ k / 1) ⊗ Κ (+ n / 1) ⊗ t-1 ⊜ Κ ((+ k / 1) ℚ.* (+ n / 1)) ⊗ t-1) ≃-refl (t - 1ℝ) ⟩
(+ (k ℕ.* n) / 1) ⋆ * (t - 1ℝ) ≤⟨ ≤-respˡ-≃ (+-identityˡ ((+ (k ℕ.* n) / 1) ⋆ * (t - 1ℝ)))
(+-monoˡ-≤ ((+ (k ℕ.* n) / 1) ⋆ * (t - 1ℝ)) (p≤q⇒p⋆≤q⋆ 0ℚᵘ 1ℚᵘ (ℚP.nonNegative⁻¹ _))) ⟩
1ℝ + (+ (k ℕ.* n) / 1) ⋆ * (t - 1ℝ) ≤⟨ bernoullis-inequality {t - 1ℝ} -1≤t-1 (k ℕ.* n) ⟩
pow (1ℝ + (t - 1ℝ)) (k ℕ.* n) ≈⟨ pow-cong (k ℕ.* n) (solve 1 (λ t -> Κ 1ℚᵘ ⊕ (t ⊖ Κ 1ℚᵘ) ⊜ t) ≃-refl t) ⟩
pow t (k ℕ.* n) ∎
lem : ∀ j -> {j ≢0} -> ∃ λ N-1 -> ∀ n -> n ℕ.≥ suc N-1 -> pow t n ≥ (+ j / 1) ⋆
lem (suc j-1) = let j = suc j-1 in ℕ.pred (k ℕ.* j) , λ n n≥kj -> begin
(+ j / 1) ⋆ ≤⟨ tᵏⁿ≥n j ⟩
pow t (k ℕ.* j) ≤⟨ 1≤x∧m≤n⇒xᵐ≤xⁿ {t} {k ℕ.* j} {n} (<⇒≤ 1<t) n≥kj ⟩
pow t n ∎
abstract
fast-0<r<1⇒rⁿ→0 : ∀ {r} -> 0ℝ < r < 1ℝ ->
∀ j -> {j≢0 : j ≢0} -> ∃ λ Nₖ-1 -> ∀ n -> n ℕ.≥ suc Nₖ-1 -> pow r n ≤ ((+ 1 / j) {j≢0}) ⋆
fast-0<r<1⇒rⁿ→0 = 0<r<1⇒rⁿ→0
x≤y∧nonNegx⇒xⁿ≤yⁿ : ∀ {x y} -> ∀ n -> x ≤ y -> NonNegative x -> pow x n ≤ pow y n
x≤y∧nonNegx⇒xⁿ≤yⁿ {x} {y} zero x≤y nonx = ≤-refl
x≤y∧nonNegx⇒xⁿ≤yⁿ {x} {y} (suc n) x≤y nonx = *-mono-≤ (nonNegx⇒nonNegxⁿ n nonx) nonx (x≤y∧nonNegx⇒xⁿ≤yⁿ n x≤y nonx) x≤y
posx⇒posxⁿ : ∀ {x} -> ∀ n -> Positive x -> Positive (pow x n)
posx⇒posxⁿ {x} zero posx = posp⇒posp⋆ 1ℚᵘ _
posx⇒posxⁿ {x} (suc n) posx = posx,y⇒posx*y (posx⇒posxⁿ n posx) posx
x<y∧nonNegx⇒xⁿ<yⁿ : ∀ {x y} -> ∀ n -> {n ≢0} -> x < y -> NonNegative x -> pow x n < pow y n
x<y∧nonNegx⇒xⁿ<yⁿ {x} {y} 1 x<y nonx = *-monoʳ-<-pos (posp⇒posp⋆ 1ℚᵘ _) x<y
x<y∧nonNegx⇒xⁿ<yⁿ {x} {y} (suc (suc n)) x<y nonx = begin-strict
pow x (suc n) * x ≤⟨ *-monoˡ-≤-nonNeg (<⇒≤ x<y) (nonNegx⇒nonNegxⁿ (suc n) nonx) ⟩
pow x (suc n) * y <⟨ *-monoˡ-<-pos (0<x⇒posx (≤-<-trans (nonNegx⇒0≤x nonx) x<y)) (x<y∧nonNegx⇒xⁿ<yⁿ (suc n) x<y nonx) ⟩
pow y (suc n) * y ∎
where open ≤-Reasoning
∣xⁿ∣≃∣x∣ⁿ : ∀ x -> ∀ n -> ∣ pow x n ∣ ≃ pow ∣ x ∣ n
∣xⁿ∣≃∣x∣ⁿ x zero = nonNegx⇒∣x∣≃x (0≤x⇒nonNegx (p≤q⇒p⋆≤q⋆ 0ℚᵘ 1ℚᵘ (ℚP.nonNegative⁻¹ _)))
∣xⁿ∣≃∣x∣ⁿ x (suc n) = begin
∣ pow x n * x ∣ ≈⟨ ∣x*y∣≃∣x∣*∣y∣ (pow x n) x ⟩
∣ pow x n ∣ * ∣ x ∣ ≈⟨ *-congʳ (∣xⁿ∣≃∣x∣ⁿ x n) ⟩
pow ∣ x ∣ n * ∣ x ∣ ∎
where open ≃-Reasoning
{-
[5]
This proof is an altered and further constructivized version of the proof at
https://math.stackexchange.com/questions/1253129/as-the-limit-of-n-goes-to-infinity-prove-that-xn-0-if-operatornameabs
Proposition:
If ∣r∣ < 1, then (rⁿ)→0.
Proof:
Let ε∈ℝ⁺ such that ∣r∣ < ∣r∣ + ε and 0 < ∣r∣ + ε < 1. If ([∣r∣ + ε]ⁿ)→0, then
(∣r∣ⁿ)→0, and so (rⁿ)→0. Let t = (∣r∣ + ε)⁻¹. Then t = 1 + (t - 1), where t - 1 > 0.
By the Archimedean Property, there is k∈ℕ such that k(t - 1) > 1. We have, for n∈ℕ:
tᵏⁿ = (1 + (t-1))ᵏⁿ
≥ 1 + k(t-1)n by Bernoulli's inequality
> 1 + n since k(t-1) > 1
> n,
so tᵏⁿ > n for all n∈ℕ (⋆).
Let j∈ℕ and let N = k * j. Let n ≥ N. Then (∣r∣ + ε)ⁿ ≤ j⁻¹ ⇔ j ≤ tⁿ. We have:
j < tᵏʲ by ⋆
≤ tⁿ since n ≥ kj and (tⁿ) is an increasing sequence.
Thus ([∣r∣ + ε]ⁿ)→0, and so (rⁿ)→0. □ -}
∣r∣<1⇒rⁿ→0 : ∀ {r} -> ∣ r ∣ < 1ℝ -> (λ n -> pow r n) ConvergesTo 0ℝ
∣r∣<1⇒rⁿ→0 {r} ∣r∣<1 = con* (λ {(suc k-1) -> let k = suc k-1; Nₖ-getter = fast-0<r<1⇒rⁿ→0 {∣ r ∣ + ε} (0<∣r∣+ε , (proj₂ (proj₂ (ε-prop))))
; Nₖ = suc (proj₁ (Nₖ-getter k)) in ℕ.pred Nₖ , λ n n≥Nₖ -> begin
∣ pow r n - 0ℝ ∣ ≈⟨ ∣-∣-cong (solve 1 (λ x -> x ⊖ Κ 0ℚᵘ ⊜ x) ≃-refl (pow r n)) ⟩
∣ pow r n ∣ ≈⟨ ∣xⁿ∣≃∣x∣ⁿ r n ⟩
pow ∣ r ∣ n ≤⟨ x≤y∧nonNegx⇒xⁿ≤yⁿ {∣ r ∣} {∣ r ∣ + ε} n ∣r∣≤∣r∣+ε (nonNeg∣x∣ r) ⟩
pow (∣ r ∣ + ε) n ≤⟨ proj₂ (Nₖ-getter k) n n≥Nₖ ⟩
(+ 1 / k) ⋆ ∎})
where
open ≤-Reasoning
ε-prop = proj₂ (x<y⇒∃ε>0[x<x+ε<y] {∣ r ∣} {1ℝ} ∣r∣<1)
ε = proj₁ (x<y⇒∃ε>0[x<x+ε<y] {∣ r ∣} {1ℝ} ∣r∣<1)
0<∣r∣+ε : 0ℝ < ∣ r ∣ + ε
0<∣r∣+ε = begin-strict
0ℝ <⟨ posx⇒0<x (proj₁ ε-prop) ⟩
ε ≤⟨ ≤-respˡ-≃ (+-identityˡ ε) (+-monoˡ-≤ ε (0≤∣x∣ r)) ⟩
∣ r ∣ + ε ∎
∣r∣≤∣r∣+ε : ∣ r ∣ ≤ ∣ r ∣ + ε
∣r∣≤∣r∣+ε = begin
∣ r ∣ ≈⟨ ≃-symm (+-identityʳ ∣ r ∣) ⟩
∣ r ∣ + 0ℝ ≤⟨ +-monoʳ-≤ ∣ r ∣ {0ℝ} {ε} (nonNegx⇒0≤x (pos⇒nonNeg (proj₁ ε-prop))) ⟩
∣ r ∣ + ε ∎
private
1-r≄0 : ∀ r -> ∣ r ∣ < 1ℝ -> (1ℝ - r) ≄0
1-r≄0 r ∣r∣<1 = inj₂ (x<y⇒0<y-x r 1ℝ (proj₂ (∣x∣<y⇒-y<x<y r 1ℝ ∣r∣<1)))
{-
Using the new solver, we can delete pretty much half the proof!
If the solver gets updated to a field solver, we can delete almost the entire thing.
-}
geometric-sum : ∀ {r} -> ∀ n -> (∣r∣<1 : ∣ r ∣ < 1ℝ) -> ∑ (λ i -> pow r i) 0 n ≃ (1ℝ - pow r n) * ((1ℝ - r) ⁻¹) (1-r≄0 r ∣r∣<1)
geometric-sum {r} zero ∣r∣<1 = let [1-r]⁻¹ = ((1ℝ - r) ⁻¹) (1-r≄0 r ∣r∣<1) in
solve 1 (λ x -> Κ 0ℚᵘ ⊜ (Κ 1ℚᵘ ⊖ Κ 1ℚᵘ) ⊗ x) ≃-refl [1-r]⁻¹
geometric-sum {r} (suc n) ∣r∣<1 = let [1-r]⁻¹ = ((1ℝ - r) ⁻¹) (1-r≄0 r ∣r∣<1) in begin
∑₀ (pow r) n + pow r n ≈⟨ +-cong {∑₀ (pow r) n} {(1ℝ - pow r n) * [1-r]⁻¹}
{pow r n} {pow r n * (1ℝ - r) * [1-r]⁻¹}
(geometric-sum {r} n ∣r∣<1)
(≃-symm (≃-trans (≃-trans
(*-assoc (pow r n) (1ℝ - r) [1-r]⁻¹)
(*-congˡ {pow r n} {(1ℝ - r) * [1-r]⁻¹} {1ℝ} (*-inverseʳ (1ℝ - r) (1-r≄0 r ∣r∣<1))))
(*-identityʳ (pow r n)))) ⟩
(1ℝ - pow r n) * [1-r]⁻¹ + pow r n * (1ℝ - r) * [1-r]⁻¹ ≈⟨ solve 3 (λ r rⁿ [1-r]⁻¹ ->
(Κ 1ℚᵘ ⊖ rⁿ) ⊗ [1-r]⁻¹ ⊕ rⁿ ⊗ (Κ 1ℚᵘ ⊖ r) ⊗ [1-r]⁻¹ ⊜
(Κ 1ℚᵘ ⊖ (rⁿ ⊗ r)) ⊗ [1-r]⁻¹)
≃-refl r (pow r n) [1-r]⁻¹ ⟩
(1ℝ - pow r (suc n)) * [1-r]⁻¹ ∎
where open ≃-Reasoning
geometric-series-converges : ∀ {r} -> (∣r∣<1 : ∣ r ∣ < 1ℝ) -> SeriesOf (λ i -> pow r i) ConvergesTo ((1ℝ - r) ⁻¹) (1-r≄0 r ∣r∣<1)
geometric-series-converges {r} ∣r∣<1 = xₙ≃yₙ∧xₙ→x₀⇒yₙ→x₀ {λ n -> (1ℝ - pow r n) * [1-r]⁻¹} {SeriesOf rⁱ}
(λ {(suc n-1) -> let n = suc n-1 in ≃-symm (geometric-sum {r} n ∣r∣<1)})
([1-r]⁻¹ , xₙ→x∧x≃y⇒xₙ→y {λ n → (1ℝ - pow r n) * [1-r]⁻¹} {1ℝ * [1-r]⁻¹} {[1-r]⁻¹}
(xₙyₙ→x₀y₀ {1-rⁱ} {λ i → [1-r]⁻¹} 1-rⁱ→1 [1-r]⁻¹→[1-r]⁻¹) (*-identityˡ [1-r]⁻¹))
where
open ≃-Reasoning
-1<r<1 = ∣x∣<y⇒-y<x<y r 1ℝ ∣r∣<1
1-rⁱ = λ i -> 1ℝ - pow r i
[1-r]⁻¹ = ((1ℝ - r) ⁻¹) (1-r≄0 r ∣r∣<1)
rⁱ = λ i -> pow r i
rⁱ→0 = 0ℝ , ∣r∣<1⇒rⁿ→0 ∣r∣<1
1→1 = 1ℝ , xₙ≃c⇒xₙ→c {λ i -> 1ℝ} {1ℝ} λ {(suc n-1) -> ≃-refl}
[1-r]⁻¹→[1-r]⁻¹ = [1-r]⁻¹ , xₙ≃c⇒xₙ→c {λ i -> [1-r]⁻¹} {[1-r]⁻¹} λ {(suc n-1) -> ≃-refl}
1-rⁱ→1 = 1ℝ , xₙ→x∧x≃y⇒xₙ→y (xₙ+yₙ→x₀+y₀ 1→1 (- 0ℝ , -xₙ→-x₀ rⁱ→0)) (≃-trans (+-congʳ 1ℝ (≃-symm 0≃-0)) (+-identityʳ 1ℝ))
abstract
fast-geometric-series-converges : ∀ {r} -> (∣r∣<1 : ∣ r ∣ < 1ℝ) -> SeriesOf (λ i -> pow r i) ConvergesTo ((1ℝ - r) ⁻¹) (1-r≄0 r ∣r∣<1)
fast-geometric-series-converges {r} = geometric-series-converges {r}
geometric-series-isConvergent : ∀ {r} -> ∣ r ∣ < 1ℝ -> SeriesOf (λ i -> pow r i) isConvergent
geometric-series-isConvergent {r} ∣r∣<1 = ((1ℝ - r) ⁻¹) (1-r≄0 r ∣r∣<1) , geometric-series-converges {r} ∣r∣<1
abstract
fast-geometric-series-isConvergent : ∀ {r} -> ∣ r ∣ < 1ℝ -> SeriesOf (λ i -> pow r i) isConvergent
fast-geometric-series-isConvergent {r} = geometric-series-isConvergent {r}
∑cxₙ≃c∑xₙ : ∀ (xs : ℕ -> ℝ) -> ∀ (c : ℝ) -> ∀ (m n : ℕ) -> ∑ (λ i -> c * xs i) m n ≃ c * ∑ xs m n
∑cxₙ≃c∑xₙ xs c zero n = lem n
where
open ≃-Reasoning
lem : ∀ n -> ∑₀ (λ i -> c * xs i) n ≃ c * ∑₀ xs n
lem 0 = ≃-symm (*-zeroʳ c)
lem (suc n) = begin
∑₀ (λ i -> c * xs i) n + c * xs n ≈⟨ +-congˡ (c * xs n) (lem n) ⟩
c * ∑₀ xs n + c * xs n ≈⟨ ≃-symm (*-distribˡ-+ c (∑₀ xs n) (xs n)) ⟩
c * (∑₀ xs n + xs n) ∎
∑cxₙ≃c∑xₙ xs c (suc m) n = begin
∑₀ (λ i -> c * xs i) n - (∑₀ (λ i -> c * xs i) m + c * xs m) ≈⟨ +-cong (∑cxₙ≃c∑xₙ xs c 0 n)
(-‿cong (≃-trans
(+-congˡ (c * xs m) (∑cxₙ≃c∑xₙ xs c 0 m))
(≃-symm (*-distribˡ-+ c (∑₀ xs m) (xs m))))) ⟩
c * ∑₀ xs n - (c * (∑₀ xs m + xs m)) ≈⟨ solve 3 (λ c ∑₀ⁿxᵢ ∑₀ᵐ⁺¹xᵢ ->
c ⊗ ∑₀ⁿxᵢ ⊖ c ⊗ ∑₀ᵐ⁺¹xᵢ ⊜ c ⊗ (∑₀ⁿxᵢ ⊖ ∑₀ᵐ⁺¹xᵢ) )
≃-refl c (∑₀ xs n) (∑₀ xs (suc m)) ⟩
c * (∑₀ xs n - (∑₀ xs m + xs m)) ∎
where open ≃-Reasoning
{- [7] -}
proposition-3-6-1 : ∀ {xs : ℕ -> ℝ} -> ∀ {c} -> 0ℝ < c < 1ℝ ->
(∃ λ N-1 -> ∀ n -> n ℕ.≥ suc N-1 -> ∣ xs (suc n) ∣ ≤ c * ∣ xs n ∣) ->
SeriesOf xs isConvergent
proposition-3-6-1 {xs} {c} (0<c , c<1) (N-1 , hyp) = proposition-3-5 {xs} {λ n -> ∣ xs N ∣ * c⁻ᴺ * pow c n} part1
(ℕ.pred N , λ n n≥N -> part2 n (≤⇒≡∨< N n n≥N))
where
open ≤-Reasoning
N = suc N-1
posc = 0<x⇒posx {c} 0<c
cᴺ≄0 = inj₂ (posx⇒0<x {pow c N} (posx⇒posxⁿ {c} N posc))
c⁻ᴺ = ((pow c N) ⁻¹) cᴺ≄0
∣c∣<1 = -y<x<y⇒∣x∣<y c 1ℝ (<-trans (<-respˡ-≃ (⋆-distrib-neg 1ℚᵘ)
(p<q⇒p⋆<q⋆ (ℚ.- 1ℚᵘ) 0ℚᵘ (ℚP.negative⁻¹ _))) 0<c , c<1)
con∑cⁿ = fast-geometric-series-isConvergent {c} ∣c∣<1
part0 : (λ i -> ∣ xs N ∣ * c⁻ᴺ * (SeriesOf (λ n -> pow c n) i)) isConvergent
part0 = ∣ xs N ∣ * c⁻ᴺ * (proj₁ con∑cⁿ) , xₙyₙ→x₀y₀ {λ i → ∣ xs N ∣ * c⁻ᴺ} {SeriesOf (λ n → pow c n)}
(∣ xs N ∣ * c⁻ᴺ , xₙ≃c⇒xₙ→c {λ i -> ∣ xs N ∣ * c⁻ᴺ} {∣ xs N ∣ * c⁻ᴺ} (λ {(suc n-1) -> ≃-refl}))
con∑cⁿ
part1 : SeriesOf (λ n -> ∣ xs N ∣ * c⁻ᴺ * pow c n) isConvergent
part1 = ∣ xs N ∣ * c⁻ᴺ * (proj₁ con∑cⁿ) ,
xₙ≃yₙ∧xₙ→x₀⇒yₙ→x₀
{λ i → ∣ xs N ∣ * c⁻ᴺ * SeriesOf (λ n → pow c n) i}
{SeriesOf (λ n → ∣ xs N ∣ * c⁻ᴺ * pow c n)}
(λ {n -> ≃-symm (∑cxₙ≃c∑xₙ (λ i -> pow c i) (∣ xs N ∣ * c⁻ᴺ) 0 n)}) part0
part2 : ∀ n -> N ≡ n ⊎ N ℕ.< n -> ∣ xs n ∣ ≤ ∣ xs N ∣ * c⁻ᴺ * pow c n
part2 .(suc N-1) (inj₁ refl) = ≤-reflexive (≃-symm (begin-equality
∣ xs N ∣ * c⁻ᴺ * pow c N ≈⟨ *-assoc ∣ xs N ∣ c⁻ᴺ (pow c N) ⟩
∣ xs N ∣ * (c⁻ᴺ * pow c N) ≈⟨ *-congˡ {∣ xs N ∣} {c⁻ᴺ * pow c N} {1ℝ}
(*-inverseˡ (pow c N) cᴺ≄0) ⟩
∣ xs N ∣ * 1ℝ ≈⟨ *-identityʳ ∣ xs N ∣ ⟩
∣ xs N ∣ ∎))
part2 (suc n) (inj₂ (ℕ.s≤s N<n)) = begin
∣ xs (suc n) ∣ ≤⟨ hyp n N<n ⟩
c * ∣ xs n ∣ ≤⟨ *-monoˡ-≤-nonNeg {∣ xs n ∣} {c} {∣ xs N ∣ * c⁻ᴺ * pow c n}
(part2 n (≤⇒≡∨< N n N<n)) (pos⇒nonNeg posc) ⟩
c * (∣ xs N ∣ * c⁻ᴺ * pow c n) ≈⟨ solve 4 (λ a b c d -> a ⊗ (b ⊗ c ⊗ d) ⊜ b ⊗ c ⊗ (d ⊗ a))
≃-refl c ∣ xs N ∣ c⁻ᴺ (pow c n) ⟩
∣ xs N ∣ * c⁻ᴺ * pow c (suc n) ∎
∣c∣>0⇒∑c-isDivergent : ∀ {c} -> ∣ c ∣ > 0ℝ -> SeriesOf (λ i -> c) isDivergent
∣c∣>0⇒∑c-isDivergent {c} ∣c∣>0 = ∣ c ∣ , div* (0<x⇒posx ∣c∣>0)
(λ {k -> suc k , k , ℕP.n≤1+n k , ℕP.≤-refl , ≤-reflexive (∣-∣-cong (≃-symm (begin
∑₀ (λ i -> c) k + c - ∑₀ (λ i -> c) k ≈⟨ solve 2 (λ a b -> a ⊕ b ⊖ a ⊜ b)
≃-refl (∑₀ (λ i -> c) k) c ⟩
c ∎)))})
where open ≃-Reasoning
{- [8] -}
proposition-3-6-2 : ∀ {xs : ℕ -> ℝ} -> ∀ {c} -> 1ℝ < c ->
(∃ λ N-1 -> ∀ n -> n ℕ.≥ suc N-1 -> ∣ xs (suc n) ∣ > c * ∣ xs n ∣) ->
SeriesOf xs isDivergent
proposition-3-6-2 {xs} {c} 1<c (N-1 , hyp) = subsequence-divergence-test {xs} (∣ xs (suc N) ∣ ,
(λ n -> xs (n ℕ.+ suc N)) , 0<x⇒posx {∣ xs (suc N) ∣} part1 ,
subseq* ((λ n -> n ℕ.+ suc N) , (λ n -> ≃-refl) , (λ n -> ℕP.n<1+n (n ℕ.+ suc N))) ,
λ n -> ≤-trans {∣ xs (suc N) ∣} {pow c (n ℕ.+ suc N) * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣} {∣ xs (n ℕ.+ suc N) ∣}
(part2-1 (n ℕ.+ suc N) (ℕP.m≤n+m (suc N) n))
(part2-2 (n ℕ.+ suc N) (≤⇒≡∨< (suc N) (n ℕ.+ suc N) (ℕP.m≤n+m (suc N) n))))
where
open ≤-Reasoning
N = suc N-1
n-N-1 = λ n -> ℤ.∣ + n ℤ.- + (suc N) ∣
cᴺ⁺¹≄0 = inj₂ (posx⇒0<x {pow c (suc N)} (posx⇒posxⁿ {c} (suc N) (0<x⇒posx {c}
(<-trans (p<q⇒p⋆<q⋆ 0ℚᵘ 1ℚᵘ (ℚP.positive⁻¹ _)) 1<c))))
c⁻ᴺ⁻¹ = ((pow c (suc N)) ⁻¹) cᴺ⁺¹≄0
posc = 0<x⇒posx (≤-<-trans (p≤q⇒p⋆≤q⋆ 0ℚᵘ 1ℚᵘ (ℚP.nonNegative⁻¹ _)) 1<c)
part1 : ∣ xs (suc N) ∣ > 0ℝ
part1 = begin-strict
0ℝ ≤⟨ nonNegx⇒0≤x (nonNegx,y⇒nonNegx*y (pos⇒nonNeg posc) (nonNeg∣x∣ (xs N))) ⟩
c * ∣ xs N ∣ <⟨ hyp N ℕP.≤-refl ⟩
∣ xs (suc N) ∣ ∎
part2-1 : ∀ n -> suc N ℕ.≤ n -> pow c n * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣ ≥ ∣ xs (suc N) ∣
part2-1 n N+1≤n = begin
∣ xs (suc N) ∣ ≈⟨ ≃-symm (*-identityˡ ∣ xs (suc N) ∣) ⟩
1ℝ * ∣ xs (suc N) ∣ ≈⟨ ≃-symm (*-congʳ {∣ xs (suc N) ∣} {pow c (suc N) * c⁻ᴺ⁻¹} {1ℝ}
(*-inverseʳ (pow c (suc N)) cᴺ⁺¹≄0)) ⟩
pow c (suc N) * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣ ≤⟨ *-monoʳ-≤-nonNeg {pow c (suc N) * c⁻ᴺ⁻¹} {∣ xs (suc N) ∣} {pow c n * c⁻ᴺ⁻¹}
(*-monoʳ-≤-nonNeg {pow c (suc N)} {c⁻ᴺ⁻¹} {pow c n}
(1≤x∧m≤n⇒xᵐ≤xⁿ {c} (<⇒≤ 1<c) N+1≤n)
(nonNegx⇒nonNegx⁻¹ {pow c (suc N)} (nonNegx⇒nonNegxⁿ {c} (suc N)
(pos⇒nonNeg {c} posc)) cᴺ⁺¹≄0))
(nonNeg∣x∣ (xs (suc N))) ⟩
pow c n * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣ ∎
part2-2 : ∀ n -> suc N ≡ n ⊎ suc N ℕ.< n -> ∣ xs n ∣ ≥ pow c n * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣
part2-2 .(suc (suc N-1)) (inj₁ refl) = begin
pow c (suc N) * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣ ≈⟨ *-congʳ {∣ xs (suc N) ∣} {pow c (suc N) * c⁻ᴺ⁻¹} {1ℝ}
(*-inverseʳ (pow c (suc N)) cᴺ⁺¹≄0) ⟩
1ℝ * ∣ xs (suc N) ∣ ≈⟨ *-identityˡ ∣ xs (suc N) ∣ ⟩
∣ xs (suc N) ∣ ∎
part2-2 (suc n) (inj₂ (ℕ.s≤s N<n)) = begin
pow c n * c * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣ ≈⟨ solve 4 (λ x y z w -> x ⊗ y ⊗ z ⊗ w ⊜ y ⊗ (x ⊗ z ⊗ w))
≃-refl (pow c n) c c⁻ᴺ⁻¹ ∣ xs (suc N) ∣ ⟩
c * (pow c n * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣) ≤⟨ *-monoˡ-≤-nonNeg {pow c n * c⁻ᴺ⁻¹ * ∣ xs (suc N) ∣} {c} {∣ xs n ∣}
(part2-2 n (≤⇒≡∨< (suc N) n N<n))
(pos⇒nonNeg {c} posc) ⟩
c * ∣ xs n ∣ <⟨ hyp n (ℕP.≤-trans (ℕP.n≤1+n N) N<n) ⟩
∣ xs (suc n) ∣ ∎
ε-cauchy-convergence : ∀ {xs : ℕ -> ℝ} -> (∀ {ε} -> ε > 0ℝ -> ∃ λ N-1 -> ∀ m n -> m ℕ.> n -> n ℕ.≥ suc N-1 -> ∣ xs m - xs n ∣ ≤ ε) -> xs isConvergent
ε-cauchy-convergence {xs} hyp = cauchy-convergence (λ {(suc k-1) -> let k = suc k-1 in
hyp (p<q⇒p⋆<q⋆ 0ℚᵘ (+ 1 / k) (ℚP.positive⁻¹ _))})
abstract
fast-ε-cauchy-convergence : ∀ {xs : ℕ -> ℝ} -> (∀ {ε} -> ε > 0ℝ -> ∃ λ N-1 -> ∀ m n -> m ℕ.> n -> n ℕ.≥ suc N-1 -> ∣ xs m - xs n ∣ ≤ ε) -> xs isConvergent
fast-ε-cauchy-convergence = ε-cauchy-convergence
ε-cauchy : ∀ {xs : ℕ -> ℝ} -> (∀ {ε} -> ε > 0ℝ -> ∃ λ N-1 -> ∀ m n -> m ℕ.> n -> n ℕ.≥ suc N-1 -> ∣ xs m - xs n ∣ ≤ ε) -> xs isCauchy
ε-cauchy {xs} hyp = fast-convergent⇒cauchy (ε-cauchy-convergence hyp)
abstract
fast-0<x⇒posx : ∀ {x} -> 0ℝ < x -> Positive x
fast-0<x⇒posx = 0<x⇒posx
ε-from-convergence-cauchy : ∀ {xs : ℕ -> ℝ} -> (xₙ→ℓ : xs isConvergent) ->
∀ {ε : ℝ} -> ε > 0ℝ -> ∃ λ N-1 -> ∀ m n -> m ℕ.> n -> n ℕ.≥ suc N-1 -> ∣ xs m - xs n ∣ ≤ ε
ε-from-convergence-cauchy {xs} xₙ→ℓ {ε} ε>0 = let xₙ-cauchy = fast-cauchy-getter (fast-convergent⇒cauchy xₙ→ℓ)
; arch = fast-archimedean-ℝ₂ (fast-0<x⇒posx ε>0); k = suc (proj₁ arch) in
proj₁ (xₙ-cauchy k) , λ m n m>n n≥N -> begin
∣ xs m - xs n ∣ ≤⟨ proj₂ (xₙ-cauchy k) m n
(ℕP.<⇒≤ (ℕP.<-transʳ n≥N m>n)) n≥N ⟩
(+ 1 / k) ⋆ <⟨ proj₂ arch ⟩
ε ∎
where open ≤-Reasoning
abstract
fast-ε-from-convergence-cauchy : ∀ {xs : ℕ -> ℝ} -> (xₙ→ℓ : xs isConvergent) ->
∀ {ε : ℝ} -> ε > 0ℝ -> ∃ λ N-1 -> ∀ m n -> m ℕ.> n -> n ℕ.≥ suc N-1 -> ∣ xs m - xs n ∣ ≤ ε
fast-ε-from-convergence-cauchy = ε-from-convergence-cauchy
∑ᵀ-mono-<-weak : ∀ {xs ys : ℕ -> ℝ} -> ∀ {m n} -> (m<n : m ℕ.< n) ->
(∀ k -> m ℕ.≤ k × k ℕ.≤ n -> xs k < ys k) ->
∑ᵀ xs m n (ℕP.<⇒≤ m<n) < ∑ᵀ ys m n (ℕP.<⇒≤ m<n)
∑ᵀ-mono-<-weak {xs} {ys} {m} {suc n} m<n hyp with ≤⇒≡∨< m (suc n) (ℕP.<⇒≤ m<n)
... | inj₁ refl = ⊥-elim (ℕP.<-irrefl refl m<n)
... | inj₂ (ℕ.s≤s y) = begin-strict
∑ᵀ xs m n y + xs n ≤⟨ +-monoˡ-≤ (xs n) (∑ᵀ-mono-≤-weak y (λ k m≤k≤n -> <⇒≤ (hyp k
(proj₁ m≤k≤n , ℕP.≤-trans (proj₂ m≤k≤n) (ℕP.n≤1+n n))))) ⟩
∑ᵀ ys m n y + xs n <⟨ +-monoʳ-< (∑ᵀ ys m n y) (hyp n (y , ℕP.n≤1+n n)) ⟩
∑ᵀ ys m n y + ys n ∎
where open ≤-Reasoning
∑-mono-<-weak : ∀ {xs ys : ℕ -> ℝ} -> ∀ (m n : ℕ) -> (m<n : m ℕ.< n) ->
(∀ k -> m ℕ.≤ k × k ℕ.≤ n -> xs k < ys k) ->
∑ xs m n < ∑ ys m n
∑-mono-<-weak {xs} {ys} m n m<n hyp = let m≤n = ℕP.<⇒≤ m<n in begin-strict
∑ xs m n ≈⟨ ∑-to-∑ᵀ xs m n m≤n ⟩
∑ᵀ xs m n m≤n <⟨ ∑ᵀ-mono-<-weak m<n hyp ⟩
∑ᵀ ys m n m≤n ≈⟨ ≃-symm (∑-to-∑ᵀ ys m n m≤n) ⟩
∑ ys m n ∎
where open ≤-Reasoning
∑-mono-< : ∀ {xs ys : ℕ -> ℝ} -> ∀ (m n : ℕ) -> (m<n : m ℕ.< n) ->
(∀ k -> xs k < ys k) -> ∑ xs m n < ∑ ys m n
∑-mono-< {xs} {ys} m n m<n hyp = ∑-mono-<-weak m n m<n (λ k m≤k≤n -> hyp k)
0<x,y⇒0<x*y : ∀ {x y} -> 0ℝ < x -> 0ℝ < y -> 0ℝ < x * y
0<x,y⇒0<x*y 0<x 0<y = posx⇒0<x (posx,y⇒posx*y (0<x⇒posx 0<x) (0<x⇒posx 0<y))
abstract
fast-0<x,y⇒0<x*y : ∀ {x y} -> 0ℝ < x -> 0ℝ < y -> 0ℝ < x * y
fast-0<x,y⇒0<x*y = 0<x,y⇒0<x*y
{-
Lemma:
Let (aₙ) and (xₙ) be positive sequences of real numbers and let c>0. If (aₙxₙ)→0 and there is N₁∈ℕ such that
(1) aₙxₙxₙ₊₁⁻¹ - aₙ₊₁ ≥ c (n ≥ N₁)
then ∑xₙ converges.
Proof:
Let ε>0. Since (aₙxₙ)→0, there is N₂∈ℕ such that
(2) ∣aₘxₘ - aₙxₙ∣ < cε (m ≥ n ≥ N₂).
Moreover, by (1) we have
(3) aₙxₙ - aₙ₊₁xₙ₊₁ ≥ cxₙ₊₁ (n ≥ N₁).
Let N = max{N₁, N₂} and let m ≥ n ≥ N. Then
∣∑ᵢ₌₀ᵐ xᵢ - ∑ᵢ₌₀ⁿ xᵢ∣ = ∑ᵢ₌ₙᵐ xᵢ
= c⁻¹∑ᵢ₌ₙᵐ cxᵢ
< c⁻¹∑ᵢ₌ₙᵐ (aᵢ₋₁xᵢ₋₁ - aᵢxᵢ) by (3)
= c⁻¹(aₘ₋₁xₘ₋₁ - aₙxₙ)
≤ c⁻¹cε by (2)
= ε.
Thus ∑xₙ is a Cauchy sequence. □
-}
lemma-3-7-1 : ∀ {as xs : ℕ -> ℝ} -> ∀ {c : ℝ} -> 0ℝ < c ->
(0<aₙ,xₙ : ∀ n -> (0ℝ < as n) × (0ℝ < xs n)) ->
(λ n -> as n * xs n) ConvergesTo 0ℝ ->
(∃ λ N-1 -> ∀ n -> n ℕ.≥ suc N-1 -> as n * xs n * (xs (suc n) ⁻¹) (inj₂ (proj₂ (0<aₙ,xₙ (suc n)))) - as (suc n) ≥ c) ->
SeriesOf xs isConvergent
lemma-3-7-1 {as} {xs} {c} 0<c 0<aₙ,xₙ aₙxₙ→0 (N₁-1 , hyp) = fast-ε-cauchy-convergence (λ {ε} ε>0 ->
let N₁ = suc N₁-1; N₂ = suc (proj₁ (res ε ε>0)); N = suc (N₁ ℕ.⊔ N₂) in
ℕ.pred N , λ {(suc m-1) (suc n-1) (ℕ.s≤s m-1>n-1) (ℕ.s≤s n-1≥N-1) →
let m = suc m-1; n = suc n-1; m>n = ℕ.s≤s m-1>n-1; n≥N = ℕ.s≤s n-1≥N-1
; c≄0 = inj₂ 0<c; c⁻¹ = (c ⁻¹) c≄0
; nonNegc⁻¹ = nonNegx⇒nonNegx⁻¹ {c} (0≤x⇒nonNegx (<⇒≤ 0<c)) c≄0
in begin
∣ ∑ xs n m ∣ ≈⟨ 0≤x⇒∣x∣≃x (0≤xₙ⇒0≤∑xₙ (ℕP.<⇒≤ m>n) (λ k n≤k≤m -> <⇒≤ (proj₂ (0<aₙ,xₙ k)))) ⟩
∑ xs n m ≈⟨ ≃-symm (≃-trans (*-congʳ {∑ xs n m} (*-inverseˡ c c≄0)) (*-identityˡ (∑ xs n m))) ⟩
c⁻¹ * c * ∑ xs n m ≈⟨ ≃-trans
(*-assoc c⁻¹ c (∑ xs n m))
(*-congˡ {c⁻¹} {c * ∑ xs n m} {∑ (λ i → c * xs i) n m}
(≃-symm (∑cxₙ≃c∑xₙ xs c n m))) ⟩
c⁻¹ * ∑ (λ i -> c * xs i) n m ≤⟨ *-monoˡ-≤-nonNeg {∑ (λ i → c * xs i) n m} {c⁻¹}
{∑ (λ i → as (ℕ.pred i) * xs (ℕ.pred i) - as i * xs i) n m}
(∑-mono-≤-weak {λ i → c * xs i}
{λ i → as (ℕ.pred i) * xs (ℕ.pred i) - as i * xs i} {n} {m} (ℕP.<⇒≤ m>n)
λ { (suc k-1) (n≤k , k≤m) → part3 (suc k-1)
(ℕP.<-transʳ (ℕP.m≤m⊔n N₁ N₂) (ℕP.<-transˡ (ℕP.n<1+n (ℕ.pred N))
(ℕP.≤-trans n≥N n≤k)))}) nonNegc⁻¹ ⟩
c⁻¹ * ∑ (λ i -> as (ℕ.pred i) * xs (ℕ.pred i) - as i * xs i) n m ≈⟨ *-congˡ {c⁻¹}
{∑ (λ i → as (ℕ.pred i) * xs (ℕ.pred i) - as i * xs i) n m}
{as n-1 * xs n-1 - as m-1 * xs m-1} (≃-trans
(∑-to-∑ᵀ (λ i -> as (ℕ.pred i) * xs (ℕ.pred i) - as i * xs i) n m (ℕP.<⇒≤ m>n))
(part2 m n (ℕP.<⇒≤ m>n))) ⟩
c⁻¹ * (as n-1 * xs n-1 - as m-1 * xs m-1) ≤⟨ *-monoˡ-≤-nonNeg {as n-1 * xs n-1 - as m-1 * xs m-1} {c⁻¹} {c * ε}
(≤-trans x≤∣x∣ (≤-respˡ-≃ (∣x-y∣≃∣y-x∣ (as m-1 * xs m-1) (as n-1 * xs n-1))
(proj₂ (res ε ε>0) m-1 n-1 m-1>n-1 (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) n-1≥N-1)))) nonNegc⁻¹ ⟩
c⁻¹ * (c * ε) ≈⟨ ≃-trans (≃-trans
(≃-symm (*-assoc c⁻¹ c ε))
(*-congʳ {ε} {c⁻¹ * c} {1ℝ} (*-inverseˡ c c≄0)))
(*-identityˡ ε) ⟩
ε ∎})
where
open ≤-Reasoning
-- If we don't use abstract for res, it will take forever to compute ℕP.m≤m⊔n N₁ N₂.
abstract
res : ∀ ε -> ε > 0ℝ -> ∃ λ N₂-1 -> ∀ m n -> m ℕ.> n -> n ℕ.≥ suc N₂-1 -> ∣ as m * xs m - as n * xs n ∣ ≤ c * ε
res ε ε>0 = fast-ε-from-convergence-cauchy {λ n → as n * xs n} (0ℝ , aₙxₙ→0) (fast-0<x,y⇒0<x*y 0<c ε>0)
part1 : ∀ n -> n ℕ.≥ suc N₁-1 -> as n * xs n - as (suc n) * xs (suc n) ≥ c * xs (suc n)
part1 n n≥N₁ = let n+1 = suc n; xₙ₊₁≄0 = inj₂ (proj₂ (0<aₙ,xₙ n+1)) in begin
c * xs n+1 ≤⟨ *-monoʳ-≤-nonNeg {c} {xs n+1}
{as n * xs n * (xs n+1 ⁻¹) xₙ₊₁≄0 - as n+1}
(hyp n n≥N₁)
(pos⇒nonNeg (fast-0<x⇒posx (proj₂ (0<aₙ,xₙ n+1)))) ⟩
(as n * xs n * ((xs n+1) ⁻¹) xₙ₊₁≄0 - as n+1) * xs n+1 ≈⟨ *-distribʳ-+ (xs n+1) (as n * xs n * ((xs n+1) ⁻¹) xₙ₊₁≄0) (- (as n+1)) ⟩
as n * xs n * ((xs n+1) ⁻¹) xₙ₊₁≄0 * xs n+1 + (- (as n+1)) * xs n+1 ≈⟨ +-cong
(≃-trans (≃-trans
(*-assoc (as n * xs n) (((xs n+1) ⁻¹) xₙ₊₁≄0) (xs n+1))
(*-congˡ (*-inverseˡ (xs n+1) xₙ₊₁≄0)))
(*-identityʳ (as n * xs n)))
(≃-symm (neg-distribˡ-* (as n+1) (xs n+1))) ⟩
as n * xs n - as n+1 * xs n+1 ∎
part2 : ∀ m n -> {n ≢0} -> (m≥n : m ℕ.≥ n) ->
∑ᵀ (λ i -> as (ℕ.pred i) * xs (ℕ.pred i) - as i * xs i) n m m≥n ≃ as (ℕ.pred n) * xs (ℕ.pred n) - as (ℕ.pred m) * xs (ℕ.pred m)
part2 m n {n≢0} m≥n with ≤⇒≡∨< n m m≥n
... | inj₁ refl = ≃-symm (+-inverseʳ (as (ℕ.pred m) * xs (ℕ.pred m)))
part2 (suc m-1) n {n≢0} m≥n | inj₂ (ℕ.s≤s y) = begin-equality
∑ᵀ (λ i -> as (ℕ.pred i) * xs (ℕ.pred i) - as i * xs i) n m-1 y +
(as (ℕ.pred m-1) * xs (ℕ.pred m-1) - as m-1 * xs m-1) ≈⟨ +-congˡ (as (ℕ.pred m-1) * xs (ℕ.pred m-1) - as m-1 * xs m-1)
(part2 m-1 n {n≢0} y) ⟩
as (ℕ.pred n) * xs (ℕ.pred n) - as (ℕ.pred m-1) * xs (ℕ.pred m-1) +
(as (ℕ.pred m-1) * xs (ℕ.pred m-1) - as m-1 * xs m-1) ≈⟨ solve 3 (λ x y z -> x ⊖ y ⊕ (y ⊖ z) ⊜ x ⊖ z)
≃-refl (as (ℕ.pred n) * xs (ℕ.pred n)) (as (ℕ.pred m-1) * xs (ℕ.pred m-1))
(as m-1 * xs m-1) ⟩
as (ℕ.pred n) * xs (ℕ.pred n) - as m-1 * xs m-1 ∎
part3 : ∀ n -> {n ≢0} -> n ℕ.> suc N₁-1 -> c * xs n ≤ as (ℕ.pred n) * xs (ℕ.pred n) - as n * xs n
part3 (suc n-1) (ℕ.s≤s n-1>N₁-1) = let n = suc n-1; xₙ≄0 = inj₂ (proj₂ (0<aₙ,xₙ n)) in begin
c * xs n ≤⟨ *-monoʳ-≤-nonNeg {c} {xs n}
{as n-1 * xs n-1 * (xs n ⁻¹) xₙ≄0 - as n}
(hyp n-1 n-1>N₁-1)
(pos⇒nonNeg (0<x⇒posx (proj₂ (0<aₙ,xₙ n)))) ⟩
(as n-1 * xs n-1 * (xs n ⁻¹) xₙ≄0 - as n) * xs n ≈⟨ solve 4 (λ aₙ₋₁xₙ₋₁ xₙ⁻¹ aₙ xₙ ->
(aₙ₋₁xₙ₋₁ ⊗ xₙ⁻¹ ⊖ aₙ) ⊗ xₙ ⊜ aₙ₋₁xₙ₋₁ ⊗ (xₙ⁻¹ ⊗ xₙ) ⊖ aₙ ⊗ xₙ)
≃-refl (as n-1 * xs n-1) ((xs n ⁻¹) xₙ≄0) (as n) (xs n) ⟩
as n-1 * xs n-1 * ((xs n ⁻¹) xₙ≄0 * xs n) - as n * xs n ≈⟨ +-congˡ (- (as n * xs n)) {as n-1 * xs n-1 * ((xs n ⁻¹) xₙ≄0 * xs n)} {as n-1 * xs n-1}
(≃-trans (*-congˡ {as n-1 * xs n-1} (*-inverseˡ (xs n) xₙ≄0)) (*-identityʳ (as n-1 * xs n-1))) ⟩
as n-1 * xs n-1 - as n * xs n ∎
[xₙ]isDivergent∧c≄0⇒[cxₙ]isDivergent : ∀ {xs} -> ∀ {c} -> xs isDivergent -> c ≄0 -> (λ n -> c * xs n) isDivergent
[xₙ]isDivergent∧c≄0⇒[cxₙ]isDivergent {xs} {c} (ε , div* posε hyp) c≄0 = ∣ c ∣ * ε ,
div* (posx,y⇒posx*y (x≄0⇒pos∣x∣ c≄0) posε) (λ {(suc k-1) ->
let k = suc k-1; m = proj₁ (hyp k); n = proj₁ (proj₂ (hyp k)) in
m , n , proj₁ (proj₂ (proj₂ (hyp k))) , proj₁ (proj₂ (proj₂ (proj₂ (hyp k)))) , (begin
∣ c ∣ * ε ≤⟨ *-monoˡ-≤-nonNeg (proj₂ (proj₂ (proj₂ (proj₂ (hyp k))))) (nonNeg∣x∣ c) ⟩
∣ c ∣ * ∣ xs m - xs n ∣ ≈⟨ ≃-symm (∣x*y∣≃∣x∣*∣y∣ c (xs m - xs n)) ⟩
∣ c * (xs m - xs n) ∣ ≈⟨ ∣-∣-cong (solve 3 (λ c xₘ xₙ → c ⊗ (xₘ ⊖ xₙ) ⊜ c ⊗ xₘ ⊖ c ⊗ xₙ)
≃-refl c (xs m) (xs n)) ⟩
∣ c * xs m - c * xs n ∣ ∎)})
where open ≤-Reasoning
DivergesBy-cong : ∀ {xs ys} -> ∀ {ε} -> xs DivergesBy ε -> (∀ n -> xs n ≃ ys n) -> ys DivergesBy ε
DivergesBy-cong {xs} {ys} {ε} (div* posε hyp) xₙ≃yₙ = div* posε (λ {(suc k-1) ->
let k = suc k-1; m = proj₁ (hyp k); n = proj₁ (proj₂ (hyp k)) in
m , n , proj₁ (proj₂ (proj₂ (hyp k))) , proj₁ (proj₂ (proj₂ (proj₂ (hyp k)))) , (begin
ε ≤⟨ proj₂ (proj₂ (proj₂ (proj₂ (hyp k)))) ⟩
∣ xs m - xs n ∣ ≈⟨ ∣-∣-cong (+-cong (xₙ≃yₙ m) (-‿cong (xₙ≃yₙ n))) ⟩
∣ ys m - ys n ∣ ∎)})
where open ≤-Reasoning
isDivergent-cong : ∀ {xs ys} -> xs isDivergent -> (∀ n -> xs n ≃ ys n) -> ys isDivergent
isDivergent-cong {xs} {ys} (ε , hyp) xₙ≃yₙ = ε , DivergesBy-cong hyp xₙ≃yₙ
∑xₙisDivergent∧c≄0⇒∑cxₙisDivergent : ∀ {xs} -> ∀ {c} -> SeriesOf xs isDivergent -> c ≄0 -> SeriesOf (λ n -> c * xs n) isDivergent
∑xₙisDivergent∧c≄0⇒∑cxₙisDivergent {xs} {c} hyp c≄0 = isDivergent-cong ([xₙ]isDivergent∧c≄0⇒[cxₙ]isDivergent hyp c≄0)
λ n -> ≃-symm (∑cxₙ≃c∑xₙ xs c 0 n)
x≤y⇒x-y≤0 : ∀ {x y} -> x ≤ y -> x - y ≤ 0ℝ
x≤y⇒x-y≤0 {x} {y} x≤y = begin
x - y ≤⟨ +-monoˡ-≤ (- y) x≤y ⟩
y - y ≈⟨ +-inverseʳ y ⟩
0ℝ ∎
where open ≤-Reasoning
x-y≤0⇒x≤y : ∀ {x y} -> x - y ≤ 0ℝ -> x ≤ y
x-y≤0⇒x≤y {x} {y} x-y≤0 = begin
x ≈⟨ solve 2 (λ x y -> x ⊜ x ⊖ y ⊕ y) ≃-refl x y ⟩
x - y + y ≤⟨ +-monoˡ-≤ y x-y≤0 ⟩
0ℝ + y ≈⟨ +-identityˡ y ⟩
y ∎
where open ≤-Reasoning
{-
x * x⁻¹ = 1
solve 1
λ x x≄0 -> ????
-}
lemma-3-7-2 : ∀ {as xs : ℕ -> ℝ} -> (0<aₙ,xₙ : ∀ n -> (0ℝ < as n) × (0ℝ < xs n)) ->
SeriesOf (λ n -> (as n ⁻¹) (inj₂ (proj₁ (0<aₙ,xₙ n)))) isDivergent ->
(∃ λ N-1 -> ∀ n -> n ℕ.≥ suc N-1 -> as n * xs n * (xs (suc n) ⁻¹) (inj₂ (proj₂ (0<aₙ,xₙ (suc n)))) - as (suc n) ≤ 0ℝ) ->
SeriesOf xs isDivergent
lemma-3-7-2 {as} {xs} 0<aₙ,xₙ div∑aₙ⁻¹ (N-1 , hyp) = comparison-test-divergence {xs}
{λ n → as N * xs N * (as n ⁻¹) (inj₂ (proj₁ (0<aₙ,xₙ n)))}
(0 , (λ n n≥0 -> part1 n))
(∑xₙisDivergent∧c≄0⇒∑cxₙisDivergent
{λ n → (as n ⁻¹) (inj₂ (proj₁ (0<aₙ,xₙ n)))} div∑aₙ⁻¹
(inj₂ (0<x,y⇒0<x*y (proj₁ (0<aₙ,xₙ N)) (proj₂ (0<aₙ,xₙ N)))))
(N , part4)
where
open ≤-Reasoning
N = suc N-1
abstract
part1 : ∀ n -> NonNegative (as N * xs N * (as n ⁻¹) (inj₂ (proj₁ (0<aₙ,xₙ n))))
part1 n = let aₙ⁻¹ = (as n ⁻¹) (inj₂ (proj₁ (0<aₙ,xₙ n))) in
pos⇒nonNeg {as N * xs N * aₙ⁻¹} (posx,y⇒posx*y {as N * xs N} {aₙ⁻¹}
(posx,y⇒posx*y (0<x⇒posx (proj₁ (0<aₙ,xₙ N))) (0<x⇒posx (proj₂ (0<aₙ,xₙ N))))
(posx⇒posx⁻¹ {as n} (inj₂ (proj₁ (0<aₙ,xₙ n))) (0<x⇒posx (proj₁ (0<aₙ,xₙ n)))))
part2 : ∀ n -> n ℕ.≥ N -> as n * xs n ≤ as (suc n) * xs (suc n)
part2 n n≥N = let aₙ = as n; xₙ = xs n; aₙ₊₁ = as (suc n); xₙ₊₁ = xs (suc n)
; xₙ₊₁>0 = proj₂ (0<aₙ,xₙ (suc n)); xₙ₊₁⁻¹ = (xₙ₊₁ ⁻¹) (inj₂ xₙ₊₁>0) in begin
aₙ * xₙ ≈⟨ ≃-symm (≃-trans
(*-congˡ {aₙ * xₙ} {xₙ₊₁ * xₙ₊₁⁻¹} {1ℝ} (*-inverseʳ xₙ₊₁ (inj₂ xₙ₊₁>0)))
(*-identityʳ (aₙ * xₙ))) ⟩
aₙ * xₙ * (xₙ₊₁ * xₙ₊₁⁻¹) ≤⟨ ≤-respˡ-≃
(solve 4 (λ aₙ xₙ xₙ₊₁ xₙ₊₁⁻¹ ->
aₙ ⊗ xₙ ⊗ xₙ₊₁⁻¹ ⊗ xₙ₊₁ ⊜ aₙ ⊗ xₙ ⊗ (xₙ₊₁ ⊗ xₙ₊₁⁻¹))
≃-refl aₙ xₙ xₙ₊₁ xₙ₊₁⁻¹)
(*-monoʳ-≤-nonNeg {aₙ * xₙ * xₙ₊₁⁻¹} {xₙ₊₁} {aₙ₊₁}
(x-y≤0⇒x≤y {aₙ * xₙ * xₙ₊₁⁻¹} {aₙ₊₁} (hyp n n≥N))
(pos⇒nonNeg (0<x⇒posx xₙ₊₁>0))) ⟩
aₙ₊₁ * xₙ₊₁ ∎
part3 : ∀ n -> N ≡ n ⊎ N ℕ.< n -> as N * xs N ≤ as n * xs n
part3 n (inj₁ refl) = ≤-refl
part3 (suc n) (inj₂ (ℕ.s≤s N≤n)) = ≤-trans (part3 n (≤⇒≡∨< N n N≤n)) (part2 n N≤n)
part4 : ∀ n -> n ℕ.≥ N -> as N * xs N * (as n ⁻¹) (inj₂ (proj₁ (0<aₙ,xₙ n))) ≤ xs n
part4 n n≥N = let aₙ>0 = proj₁ (0<aₙ,xₙ n); aₙ≄0 = inj₂ aₙ>0; aₙ⁻¹ = (as n ⁻¹) aₙ≄0 in begin
as N * xs N * aₙ⁻¹ ≤⟨ *-monoʳ-≤-nonNeg {as N * xs N} {aₙ⁻¹} {as n * xs n}
(part3 n (≤⇒≡∨< N n n≥N)) (nonNegx⇒nonNegx⁻¹ {as n}
(pos⇒nonNeg (0<x⇒posx aₙ>0)) aₙ≄0) ⟩
as n * xs n * aₙ⁻¹ ≈⟨ solve 3 (λ aₙ xₙ aₙ⁻¹ -> aₙ ⊗ xₙ ⊗ aₙ⁻¹ ⊜ aₙ ⊗ aₙ⁻¹ ⊗ xₙ)
≃-refl (as n) (xs n) aₙ⁻¹ ⟩
as n * aₙ⁻¹ * xs n ≈⟨ *-congʳ {xs n} {as n * aₙ⁻¹} {1ℝ}
(*-inverseʳ (as n) aₙ≄0) ⟩
1ℝ * xs n ≈⟨ *-identityˡ (xs n) ⟩
xs n ∎
-- Π₀ needed for proof of Lemma 3.8. Should extend to Π in a clean manner like how ∑ was extended.
-- Πᵢ₌₀ⁿxᵢ
--
Π₀ : (ℕ -> ℝ) -> ℕ -> ℝ
Π₀ a 0 = 1ℝ
Π₀ a (suc n) = Π₀ a n * a n
Π : (ℕ -> ℝ) -> (i n : ℕ) -> (i≤n : i ℕ.≤ n) -> ℝ
Π a i n i≤n with ≤⇒≡∨< i n i≤n
... | inj₁ i≡n = 1ℝ
... | inj₂ i<n = {!!}
0≤x,y⇒0≤x+y : ∀ {x y} -> 0ℝ ≤ x -> 0ℝ ≤ y -> 0ℝ ≤ x + y
0≤x,y⇒0≤x+y {x} {y} 0≤x 0≤y = nonNegx⇒0≤x (nonNegx,y⇒nonNegx+y (0≤x⇒nonNegx 0≤x) (0≤x⇒nonNegx 0≤y))
{-
{-
Let (xₙ) be a sequence of positive numbers and let c > 0. If there is N∈ℕ such that
n(xₙxₙ₊₁⁻¹ - 1) ≥ c (n ≥ N)
then (xₙ) converges to 0.
-}
lemma-3-8 : ∀ {xs} -> ∀ {c} -> (xₙ>0 : ∀ n -> xs n > 0ℝ) -> c > 0ℝ ->
(∃ λ N-1 -> ∀ n -> n ℕ.≥ suc N-1 -> (+ n / 1) ⋆ * (xs n * (xs (suc n) ⁻¹) (inj₂ (xₙ>0 (suc n))) - 1ℝ) ≥ c) ->
xs ConvergesTo 0ℝ
lemma-3-8 {xs} {c} xₙ>0 c>0 (N-1 , hyp) = {!!}
where
open ≤-Reasoning
N = suc N-1
part1 : ∀ n -> Π₀ (λ i -> 1ℝ + c * (+ (N ℕ.+ i) / 1) ⋆) n ≥ 1ℝ + c * ∑₀ (λ i -> (+ 1 / (N ℕ.+ i)) ⋆) n
part1 zero = ≤-reflexive (solve 1 (λ c -> Κ 1ℚᵘ ⊕ c ⊗ Κ 0ℚᵘ ⊜ Κ 1ℚᵘ) ≃-refl c)
part1 (suc n) = let S = 1ℝ + c * (∑₀ [N+i]⁻¹ n + (+ (N ℕ.+ n) / 1) ⋆) in begin
1ℝ + c * (∑₀ [N+i]⁻¹ n + (+ 1 / (N ℕ.+ n)) ⋆) ≤⟨ +-monoʳ-≤ 1ℝ (*-monoˡ-≤-nonNeg
(+-monoʳ-≤ (∑₀ [N+i]⁻¹ n) part1-1)
(pos⇒nonNeg (0<x⇒posx c>0))) ⟩
1ℝ + c * (∑₀ [N+i]⁻¹ n + (+ (N ℕ.+ n) / 1) ⋆) ≤⟨ ≤-respˡ-≃ (+-identityʳ S)
(+-monoʳ-≤ S part1-2) ⟩
1ℝ + c * (∑₀ [N+i]⁻¹ n + (+ (N ℕ.+ n) / 1) ⋆) +
c * c * (+ (N ℕ.+ n) / 1) ⋆ * ∑₀ [N+i]⁻¹ n ≈⟨ solve 3 (λ c ∑₀[N+i]⁻¹ N+n →
Κ 1ℚᵘ ⊕ c ⊗ (∑₀[N+i]⁻¹ ⊕ N+n) ⊕ c ⊗ c ⊗ N+n ⊗ ∑₀[N+i]⁻¹ ⊜
Κ 1ℚᵘ ⊗ Κ 1ℚᵘ ⊕ Κ 1ℚᵘ ⊗ (c ⊗ N+n) ⊕ (c ⊗ ∑₀[N+i]⁻¹) ⊗ Κ 1ℚᵘ
⊕ (c ⊗ ∑₀[N+i]⁻¹) ⊗ (c ⊗ N+n))
≃-refl c (∑₀ [N+i]⁻¹ n) ((+ (N ℕ.+ n) / 1) ⋆) ⟩
1ℝ * 1ℝ + 1ℝ * (c * (+ (N ℕ.+ n) / 1) ⋆) +
c * ∑₀ [N+i]⁻¹ n * 1ℝ +
c * ∑₀ [N+i]⁻¹ n * (c * (+ (N ℕ.+ n) / 1) ⋆) ≈⟨ solve 4 (λ a b c d →
a ⊗ c ⊕ a ⊗ d ⊕ b ⊗ c ⊕ b ⊗ d ⊜
(a ⊕ b) ⊗ (c ⊕ d))
≃-refl 1ℝ (c * ∑₀ [N+i]⁻¹ n) 1ℝ (c * (+ (N ℕ.+ n) / 1) ⋆) ⟩
(1ℝ + c * ∑₀ [N+i]⁻¹ n) * (1ℝ + c * (+ (N ℕ.+ n) / 1) ⋆) ≤⟨ *-monoʳ-≤-nonNeg {1ℝ + c * ∑₀ [N+i]⁻¹ n}
{1ℝ + c * (+ (N ℕ.+ n) / 1) ⋆}
{Π₀ (λ i → 1ℝ + c * (+ (N ℕ.+ i) / 1) ⋆) n}
(part1 n) part1-3 ⟩
Π₀ (λ i -> 1ℝ +
c * (+ (N ℕ.+ i) / 1) ⋆) n * (1ℝ + c * (+ (N ℕ.+ n) / 1) ⋆) ∎
where
[N+i]⁻¹ = λ i -> (+ 1 / (N ℕ.+ i)) ⋆
part1-1 : (+ 1 / (N ℕ.+ n)) ⋆ ≤ (+ (N ℕ.+ n) / 1) ⋆
part1-1 = p≤q⇒p⋆≤q⋆ (+ 1 / (N ℕ.+ n)) (+ (N ℕ.+ n) / 1) (ℚ.*≤* (ℤ.+≤+ (ℕ.s≤s ℕ.z≤n)))
part1-2 : 0ℝ ≤ c * c * (+ (N ℕ.+ n) / 1) ⋆ * ∑₀ [N+i]⁻¹ n
part1-2 = 0≤x,y⇒0≤x*y {c * c * (+ (N ℕ.+ n) / 1) ⋆} {∑₀ [N+i]⁻¹ n} (0≤x,y⇒0≤x*y {c * c} {(+ (N ℕ.+ n) / 1) ⋆}
(<⇒≤ (0<x,y⇒0<x*y c>0 c>0))
(p≤q⇒p⋆≤q⋆ 0ℚᵘ (+ (N ℕ.+ n) / 1) (ℚP.nonNegative⁻¹ _)))
(≤-respˡ-≃ (∑0≃0 0 n) (∑-mono-≤ (λ n -> p≤q⇒p⋆≤q⋆ 0ℚᵘ (+ 1 / (N ℕ.+ n)) (ℚP.nonNegative⁻¹ _)) 0 n ℕ.z≤n))
part1-3 : NonNegative (1ℝ + c * (+ (N ℕ.+ n) / 1) ⋆)
part1-3 = 0≤x⇒nonNegx (0≤x,y⇒0≤x+y (p≤q⇒p⋆≤q⋆ 0ℚᵘ 1ℚᵘ (ℚP.nonNegative⁻¹ _))
(0≤x,y⇒0≤x*y (<⇒≤ c>0) (p≤q⇒p⋆≤q⋆ 0ℚᵘ (+ (N ℕ.+ n) / 1) (ℚP.nonNegative⁻¹ _))))
proposition-3-9-1 : ∀ {xs} -> (xₙ>0 : ∀ n -> xs n > 0ℝ) ->
(hyp : (λ n -> (+ n / 1) ⋆ * (xs n * (xs (suc n) ⁻¹) (inj₂ (xₙ>0 (suc n))) - 1ℝ)) isConvergent) ->
proj₁ hyp > 1ℝ ->
SeriesOf xs isConvergent
proposition-3-9-1 {xs} xₙ>0 (L , con* hyp) L>1 = {!!}
-}
| {
"alphanum_fraction": 0.3413344913,
"avg_line_length": 60.7109090909,
"ext": "agda",
"hexsha": "b64ac889b05dedb612019b40a8472520d3c9eb72",
"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": "6fbaca08b1d63b5765d184f6284fb0e58c9f5e52",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "z-murray/AnalysisAgda",
"max_forks_repo_path": "Sequences.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6fbaca08b1d63b5765d184f6284fb0e58c9f5e52",
"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": "z-murray/AnalysisAgda",
"max_issues_repo_path": "Sequences.agda",
"max_line_length": 166,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6fbaca08b1d63b5765d184f6284fb0e58c9f5e52",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "z-murray/AnalysisAgda",
"max_stars_repo_path": "Sequences.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 67071,
"size": 133564
} |
{-# OPTIONS --without-K #-}
{-
The main definitions of this module are:
* explore⊎
* explore⊎-ind
* ⟦explore⊎⟧
* Σᵉ⊎-ok
* Πᵉ⊎-ok
-}
open import Type hiding (★)
open import Function.NP
open import Function.Extensionality
open import Data.Nat using (_+_)
open import Level.NP
open import Type.Identities
open import Data.Product.NP
open import Data.Sum using (_⊎_) renaming (inj₁ to inl; inj₂ to inr; [_,_] to [inl:_,inr:_])
open import Data.Sum.Logical
open import HoTT
open import Data.Fin using (Fin)
open import Relation.Binary.Logical
open import Relation.Binary.Sum
import Relation.Binary.PropositionalEquality.NP as ≡
open ≡ using (_≡_ ; module ≡-Reasoning; cong; !_; _∙_; refl; ap)
open import Explore.Core
open import Explore.Properties
open import Explore.Explorable
module Explore.Sum where
module _ {a b u} {A : ★ a} {B : ★ b} {U : ★ u}
(_∙_ : U → U → U)
(e₁ : (A → U) → U)
(e₂ : (B → U) → U)
(f : (A ⊎ B) → U)
where
-- find a better place/name for it
⊎ᶜ : U
⊎ᶜ = e₁ (f ∘ inl) ∙ e₂ (f ∘ inr)
module _ {ℓ a b} {A : ★ a} {B : ★ b} where
explore⊎ : Explore ℓ A → Explore ℓ B → Explore ℓ (A ⊎ B)
explore⊎ exploreᴬ exploreᴮ ε _∙_ = ⊎ᶜ _∙_ (exploreᴬ ε _∙_) (exploreᴮ ε _∙_)
module _ {p} {eᴬ : Explore ℓ A} {eᴮ : Explore ℓ B} where
explore⊎-ind : ExploreInd p eᴬ → ExploreInd p eᴮ → ExploreInd p (explore⊎ eᴬ eᴮ)
explore⊎-ind Psᴬ Psᴮ P Pε P∙ Pf
-- TODO clean this up:
= P∙ (Psᴬ (λ s → P (λ _ _ f → s _ _ (f ∘ inl))) Pε P∙ (Pf ∘ inl))
(Psᴮ (λ s → P (λ _ _ f → s _ _ (f ∘ inr))) Pε P∙ (Pf ∘ inr))
module _ {ℓ₀ ℓ₁ ℓᵣ}
{A₀ A₁} {Aᵣ : ⟦★₀⟧ A₀ A₁}
{B₀ B₁} {Bᵣ : ⟦★₀⟧ B₀ B₁}
{eᴬ₀ : Explore ℓ₀ A₀} {eᴬ₁ : Explore ℓ₁ A₁}(eᴬᵣ : ⟦Explore⟧ ℓᵣ Aᵣ eᴬ₀ eᴬ₁)
{eᴮ₀ : Explore ℓ₀ B₀} {eᴮ₁ : Explore ℓ₁ B₁}(eᴮᵣ : ⟦Explore⟧ ℓᵣ Bᵣ eᴮ₀ eᴮ₁)
where
⟦explore⊎⟧ : ⟦Explore⟧ ℓᵣ (Aᵣ ⟦⊎⟧ Bᵣ) (explore⊎ eᴬ₀ eᴮ₀) (explore⊎ eᴬ₁ eᴮ₁)
⟦explore⊎⟧ P Pε P∙ Pf
= P∙ (eᴬᵣ P Pε P∙ (Pf ∘ ⟦inl⟧))
(eᴮᵣ P Pε P∙ (Pf ∘ ⟦inr⟧))
module _ {ℓ₀ ℓ₁ ℓᵣ} {A B : ★₀}
{eᴬ₀ : Explore ℓ₀ A}{eᴬ₁ : Explore ℓ₁ A}(eᴬᵣ : ⟦Explore⟧ ℓᵣ _≡_ eᴬ₀ eᴬ₁)
{eᴮ₀ : Explore ℓ₀ B}{eᴮ₁ : Explore ℓ₁ B}(eᴮᵣ : ⟦Explore⟧ ℓᵣ _≡_ eᴮ₀ eᴮ₁)
where
⟦explore⊎⟧≡ : ⟦Explore⟧ ℓᵣ _≡_ (explore⊎ eᴬ₀ eᴮ₀) (explore⊎ eᴬ₁ eᴮ₁)
⟦explore⊎⟧≡ P Pε P∙ Pf
= P∙ (eᴬᵣ P Pε P∙ (Pf ∘ ap inl))
(eᴮᵣ P Pε P∙ (Pf ∘ ap inr))
infixr 4 _⊎ᵉ_ _⊎ⁱ_
_⊎ᵉ_ = explore⊎
_⊎ⁱ_ = explore⊎-ind
module _ {a b} {A : ★ a} {B : ★ b} where
infixr 4 _⊎ˢ_
_⊎ˢ_ : Sum A → Sum B → Sum (A ⊎ B)
_⊎ˢ_ = ⊎ᶜ _+_
module _ {A : ★₀} {B : ★₀} {sumᴬ : Sum A} {sumᴮ : Sum B}{{_ : UA}} where
open Adequacy _≡_
adequate-sum⊎ : Adequate-sum sumᴬ → Adequate-sum sumᴮ → Adequate-sum (sumᴬ ⊎ˢ sumᴮ)
adequate-sum⊎ asumᴬ asumᴮ f = (Fin (sumᴬ (f ∘ inl) + sumᴮ (f ∘ inr)))
≡⟨ ! Fin-⊎-+ ⟩
(Fin (sumᴬ (f ∘ inl)) ⊎ Fin (sumᴮ (f ∘ inr)))
≡⟨ ⊎= (asumᴬ (f ∘ inl)) (asumᴮ (f ∘ inr)) ⟩
(Σ A (Fin ∘ f ∘ inl) ⊎ Σ B (Fin ∘ f ∘ inr))
≡⟨ ! dist-⊎-Σ ⟩
Σ (A ⊎ B) (Fin ∘ f)
∎
where open ≡-Reasoning
_⊎ᵃ_ = adequate-sum⊎
module _ {ℓ} {a b} {A : ★ a} {B : ★ b} {eᴬ : Explore (ₛ ℓ) A} {eᴮ : Explore (ₛ ℓ) B} where
private
eᴬ⁺ᴮ = eᴬ ⊎ᵉ eᴮ
focus⊎ : Focus eᴬ → Focus eᴮ → Focus eᴬ⁺ᴮ
focus⊎ fᴬ fᴮ (inl x , y) = inl (fᴬ (x , y))
focus⊎ fᴬ fᴮ (inr x , y) = inr (fᴮ (x , y))
unfocus⊎ : Unfocus eᴬ → Unfocus eᴮ → Unfocus eᴬ⁺ᴮ
unfocus⊎ fᴬ fᴮ (inl x) = first inl (fᴬ x)
unfocus⊎ fᴬ fᴮ (inr y) = first inr (fᴮ y)
module _ {ℓ} {A : ★₀} {B : ★₀} {eᴬ : Explore (ₛ ℓ) A} {eᴮ : Explore (ₛ ℓ) B} where
private
eᴬ⁺ᴮ = eᴬ ⊎ᵉ eᴮ
Σᵉ⊎-ok : {{_ : UA}} → Adequate-Σ (Σᵉ eᴬ) → Adequate-Σ (Σᵉ eᴮ) → Adequate-Σ (Σᵉ eᴬ⁺ᴮ)
Σᵉ⊎-ok fᴬ fᴮ _ = ⊎= (fᴬ _) (fᴮ _) ∙ ! dist-⊎-Σ
lookup⊎ : Lookup eᴬ → Lookup eᴮ → Lookup (eᴬ ⊎ᵉ eᴮ)
lookup⊎ lookupᴬ lookupᴮ (x , y) = [inl: lookupᴬ x ,inr: lookupᴮ y ]
reify⊎ : Reify eᴬ → Reify eᴮ → Reify (eᴬ ⊎ᵉ eᴮ)
reify⊎ reifyᴬ reifyᴮ f = (reifyᴬ (f ∘ inl)) , (reifyᴮ (f ∘ inr))
Πᵉ⊎-ok : {{_ : UA}}{{_ : FunExt}} → Adequate-Π (Πᵉ eᴬ) → Adequate-Π (Πᵉ eᴮ) → Adequate-Π (Πᵉ eᴬ⁺ᴮ)
Πᵉ⊎-ok fᴬ fᴮ _ = ×= (fᴬ _) (fᴮ _) ∙ ! dist-×-Π
-- -}
-- -}
-- -}
| {
"alphanum_fraction": 0.5085688849,
"avg_line_length": 34.0378787879,
"ext": "agda",
"hexsha": "16e8685f8c609cbd987ec2e549ccd12df48ea163",
"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": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Sum.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Sum.agda",
"max_line_length": 100,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Sum.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 2464,
"size": 4493
} |
open import Data.Nat using (ℕ; _+_) renaming (_≤?_ to _≤?ₙ_)
open import Data.Bool using (Bool; true; false; not; _∧_)
open import Data.String using (String)
open import Data.Sum using (_⊎_; [_,_]; inj₁; inj₂)
open import Relation.Binary using (Decidable)
open import Relation.Nullary using (yes; no; ¬_)
open import Relation.Nullary.Negation using (contradiction)
open import Data.List using (List; []; _∷_)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Data.Empty using (⊥-elim)
open import Data.Product using (_×_; -,_; _-,-_; ∃; ∃-syntax) renaming (_,_ to _,,_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym)
open import Level using (Level; suc; _⊔_)
open import Agda.Builtin.Sigma hiding (_,_) -- renaming (_,_ to _,,_)
open import Data.Maybe using (Maybe; just; nothing; Is-just)
import Relation.Binary.PropositionalEquality as Eq
open import IMP hiding (com; state) ---using (aexp; aval; bexp; bval)
postulate
_≟_ : Decidable {A = ℕ} _≡_
addr = ℕ
heap = addr → Maybe val
store = vname → val
state = store × heap
assn : ∀{l} → Set (suc l)
assn {a} = store → heap → Set a
emp : assn
emp _ h = ∀ a → h a ≡ nothing
_⊢>_ : IMP.aexp → IMP.aexp → assn
_⊢>_ a a′ s h = h (aval a s) ≡ just (aval a′ s)
× ∀ (a″) → ¬(a″ ≡ aval a s) → h a″ ≡ nothing
_⊆_ : heap → heap → Set
h₀ ⊆ h = ∀ a → (h a ≡ nothing → h₀ a ≡ nothing)
× (∀{o} → h₀ a ≡ just o → h₀ a ≡ h a)
heap-union : heap → heap → heap → addr → Set
heap-union h h₁ h₂ a with h a
... | just o = (h₁ a ≡ just o × h₂ a ≡ nothing)
⊎ (h₁ a ≡ nothing × h₂ a ≡ just o)
... | nothing = h₁ a ≡ nothing × h₂ a ≡ nothing
_∼_⊥_ : heap → heap → heap → Set
h ∼ h₁ ⊥ h₂ = ∀ a → heap-union h h₁ h₂ a
union-subset : ∀ h {h₁ h₂}
→ h ∼ h₁ ⊥ h₂
→ h₁ ⊆ h
union-subset h x a with h a | x a
union-subset h x a | just x₁ | inj₁ (fst₁ ,, snd₁) = (λ ()) ,, (λ {x} x₁ → fst₁)
union-subset h x a | just x₁ | inj₂ (fst₁ ,, snd₁) rewrite fst₁ = (λ _ → refl) ,, (λ {x} ())
union-subset h x a | nothing | fst₁ ,, snd₁ = (λ x → fst₁) ,, (λ {x} x₁ → fst₁)
_*_ : ∀{l} → assn {l} → assn {l} → assn {l}
_*_ P Q s h = ∃[ h₁ ] ∃[ h₂ ] ((h ∼ h₁ ⊥ h₂)
× P s h₁
× Q s h₂)
_dom_ : addr → heap → Set
a dom h = ∃[ v ] (h a ≡ just v)
_¬dom_ : addr → heap → Set
a ¬dom h = h a ≡ nothing
_[_::=ₕ_] : heap → addr → val → heap
(h [ X ::=ₕ n ]) Y with Y ≟ X
... | yes _ = just n
... | no _ = h Y
_/[_] : heap → addr → heap
(h /[ X ]) Y with Y ≟ X
... | yes _ = nothing
... | no _ = h Y
data com : Set where
SKIP : com
_::=_ : String → aexp → com
_::_ : com → com → com
IF_THEN_ELSE_ : bexp → com → com → com
WHILE_DO_ : bexp → com → com
_::=cons_ : String → addr → com
_::=[_] : String → aexp → com
[_]::=_ : aexp → aexp → com
dispose_ : aexp → com
data ⊢[_]_[_] {l} : assn {l} → com → assn {l} → Set (suc l) where
Skip : ∀{P}
→ ⊢[ P ] SKIP [ P ]
Loc : ∀{Q a x}
→ ⊢[ (λ s → Q (s [ x ::= aval a s ])) ] (x ::= a) [ Q ]
Comp : ∀{P Q R c₁ c₂}
→ ⊢[ P ] c₁ [ Q ]
→ ⊢[ Q ] c₂ [ R ]
→ ⊢[ P ] c₁ :: c₂ [ R ]
If : ∀{P b c₁ Q c₂}
→ ⊢[ (λ s h → P s h × bval b s ≡ true) ] c₁ [ Q ]
→ ⊢[ (λ s h → P s h × bval b s ≡ false) ] c₂ [ Q ]
→ ⊢[ P ] (IF b THEN c₁ ELSE c₂) [ Q ]
While : ∀{P b c}
→ ⊢[ (λ s h → P s h × bval b s ≡ true) ] c [ P ]
→ ⊢[ P ] (WHILE b DO c) [ (λ s h → P s h × bval b s ≡ false) ]
Conseq : ∀{P Q P′ Q′ : assn} {c}
→ (∀ s h → P′ s h → P s h)
→ ⊢[ P ] c [ Q ]
→ (∀ s h → Q s h → Q′ s h)
→ ⊢[ P′ ] c [ Q′ ]
Frame : ∀{A B R c}
→ ⊢[ A ] c [ B ]
→ ⊢[ A * R ] c [ B * R ]
data config : Set where
⦅_,_,_⦆ : com → store → heap → config
abort : config
data _⇒_ : config → config → Set where
Loc : ∀{x a s h}
→ ⦅ x ::= a , s , h ⦆ ⇒ ⦅ SKIP , (s [ x ::= aval a s ]) , h ⦆
Comp₁ : ∀{c s h}
→ ⦅ SKIP :: c , s , h ⦆ ⇒ ⦅ c , s , h ⦆
Comp₂ : ∀{c₁ c₁′ c₂ s s′ h h′}
→ ⦅ c₁ , s , h ⦆ ⇒ ⦅ c₁′ , s′ , h′ ⦆
→ ⦅ c₁ :: c₂ , s , h ⦆ ⇒ ⦅ c₁′ :: c₂ , s′ , h′ ⦆
CompFail : ∀{c₁ c₂ s h}
→ ⦅ c₁ , s , h ⦆ ⇒ abort
→ ⦅ c₁ :: c₂ , s , h ⦆ ⇒ abort
IfTrue : ∀{b s c₁ c₂ h}
→ bval b s ≡ true
→ ⦅ IF b THEN c₁ ELSE c₂ , s , h ⦆ ⇒ ⦅ c₁ , s , h ⦆
IfFalse : ∀{b s c₁ c₂ h}
→ bval b s ≡ false
→ ⦅ IF b THEN c₁ ELSE c₂ , s , h ⦆ ⇒ ⦅ c₂ , s , h ⦆
While : ∀{b s c h}
→ ⦅ WHILE b DO c , s , h ⦆ ⇒ ⦅ IF b THEN (c :: (WHILE b DO c)) ELSE SKIP , s , h ⦆
Cons : ∀{l h s x h′ s′}
→ l ¬dom h
→ h′ ≡ h [ l ::=ₕ 0 ]
→ s′ ≡ s [ x ::= l ]
→ ⦅ x ::=cons l , s , h ⦆ ⇒ ⦅ SKIP , s′ , h′ ⦆
Lookup : ∀{a s x h v s′}
→ (aval a s) dom h
→ s′ ≡ s [ x ::= v ]
→ ⦅ x ::=[ a ] , s , h ⦆ ⇒ ⦅ SKIP , s′ , h ⦆
LookupFail : ∀{a s x h}
→ (aval a s) ¬dom h
→ ⦅ x ::=[ a ] , s , h ⦆ ⇒ abort
Write : ∀{a s a′ h}
→ (aval a s) dom h
→ ⦅ [ a ]::= a′ , s , h ⦆ ⇒ ⦅ SKIP , s , h [ aval a s ::=ₕ aval a′ s ] ⦆
WriteFail : ∀{a s a′ x h}
→ (aval a s) ¬dom h
→ ⦅ [ x ]::= a′ , s , h ⦆ ⇒ abort
Dispose : ∀{a s h}
→ (aval a s) dom h
→ ⦅ dispose a , s , h ⦆ ⇒ ⦅ SKIP , s , h /[ aval a s ] ⦆
DisposeFail : ∀{a s h}
→ (aval a s) ¬dom h
→ ⦅ dispose a , s , h ⦆ ⇒ abort
data _⇒*_ : config → config → Set where
_∎ : ∀ c → c ⇒* c
_→⟨_⟩_ : ∀ c {c′ c″}
→ c ⇒ c′
→ c′ ⇒* c″
→ c ⇒* c″
Safe : config → Set
Safe c = ¬ (c ⇒* abort)
lemma1 : ∀{c s h₀ h}
→ h₀ ⊆ h
→ ⦅ c , s , h ⦆ ⇒ abort
→ ⦅ c , s , h₀ ⦆ ⇒ abort
lemma1 sub (CompFail r) = CompFail (lemma1 sub r)
lemma1 sub (LookupFail {a}{s} r) = LookupFail (fst (sub (aval a s)) r)
lemma1 sub (WriteFail {a}{s} r) = WriteFail {a} (fst (sub (aval a s)) r)
lemma1 sub (DisposeFail {a}{s} r) = DisposeFail (fst (sub (aval a s)) r)
subset-update : ∀ l {h h₀ v}
→ h₀ ⊆ h
→ (h₀ [ l ::=ₕ v ]) ⊆ (h [ l ::=ₕ v ])
subset-update l b Y with Y ≟ l
... | yes p = (λ x → x) ,, λ {o} _ → refl
... | no ¬p = b Y
subset-delete : ∀ v {h h₀}
→ h₀ ⊆ h
→ (h₀ /[ v ]) ⊆ (h /[ v ])
subset-delete l b Y with Y ≟ l
... | yes p = (λ x → refl) ,, (λ {x} x₁ → refl)
... | no ¬p = b Y
lemma2 : ∀ h₀ {h c c′ s s′ h′}
→ h₀ ⊆ h
→ ⦅ c , s , h ⦆ ⇒ ⦅ c′ , s′ , h′ ⦆
→ ⦅ c , s , h₀ ⦆ ⇒ abort
⊎ (∃[ h′₀ ] (h′₀ ⊆ h′
× ⦅ c , s , h₀ ⦆ ⇒ ⦅ c′ , s′ , h′₀ ⦆))
lemma2 h₀ x Loc = inj₂ (h₀ ,, x ,, Loc)
lemma2 h₀ x Comp₁ = inj₂ (h₀ ,, x ,, Comp₁)
lemma2 h₀ x (Comp₂ x₁) with lemma2 h₀ x x₁
lemma2 h₀ x (Comp₂ x₁) | inj₁ x₂ = inj₁ (CompFail x₂)
lemma2 h₀ x (Comp₂ x₁) | inj₂ (h′₀ ,, sub ,, red) = inj₂ (h′₀ ,, sub ,, Comp₂ red)
lemma2 h₀ x (IfTrue x₁) = inj₂ (h₀ ,, x ,, IfTrue x₁)
lemma2 h₀ x (IfFalse x₁) = inj₂ (h₀ ,, x ,, IfFalse x₁)
lemma2 h₀ x While = inj₂ (h₀ ,, x ,, While)
lemma2 h₀ x (Cons {l} x₁ A B) rewrite A | B = inj₂ ( (h₀ [ l ::=ₕ 0 ])
,, subset-update l x
,, Cons (fst (x l) x₁) refl refl)
lemma2 h₀ x (Lookup {a}{s} (_ ,, p) A) rewrite A with h₀ (aval a s) | Eq.inspect h₀ (aval a s)
... | nothing | Eq.[ eq ] = inj₁ (LookupFail eq)
... | just o | Eq.[ eq ] = inj₂ ( h₀
,, x
,, Lookup (-, Eq.trans (snd (x (aval a s)) eq) p) refl)
lemma2 h₀ x (Write {a}{s}{a′} (_ ,, x₁)) with h₀ (aval a s) | Eq.inspect h₀ (aval a s)
... | nothing | Eq.[ eq ] = inj₁ (WriteFail {a} eq)
... | just o | Eq.[ eq ] = inj₂ ( (h₀ [ aval a s ::=ₕ aval a′ s ])
,, subset-update (aval a s) x
,, Write (-, (Eq.trans (snd (x (aval a s)) eq) x₁)))
lemma2 h₀ x (Dispose {a}{s} (_ ,, x₁)) with h₀ (aval a s) | Eq.inspect h₀ (aval a s)
... | nothing | Eq.[ eq ] = inj₁ (DisposeFail eq)
... | just o | Eq.[ eq ] = inj₂ ( (h₀ /[ aval a s ])
,, subset-delete (aval a s) x
,, Dispose (-, (Eq.trans (snd (x (aval a s)) eq) x₁)))
frame1sub : ∀{c s h H}
→ h ⊆ H
→ Safe ⦅ c , s , h ⦆
→ Safe ⦅ c , s , H ⦆
frame1sub {c}{s}{h}{H} x x₁ (_→⟨_⟩_ .(⦅ c , s , H ⦆) {⦅ x₄ , x₅ , x₆ ⦆} x₂ x₃) with lemma2 h x x₂
... | inj₁ x₇ = x₁ (⦅ c , s , h ⦆ →⟨ x₇ ⟩ (abort ∎))
... | inj₂ (_ ,, fst₂ ,, snd₁) = frame1sub fst₂ (λ z → x₁ (_ →⟨ snd₁ ⟩ z)) x₃
frame1sub {c}{s}{h}{H} x x₁ (_→⟨_⟩_ .(⦅ c , s , H ⦆) {abort} x₂ x₃) = x₁ (_ →⟨ lemma1 x x₂ ⟩ (abort ∎))
frame1 : ∀{c s h H z}
→ H ∼ h ⊥ z
→ Safe ⦅ c , s , h ⦆
→ Safe ⦅ c , s , H ⦆
frame1 {H = H} x x₁ x₂ = frame1sub (union-subset H x) x₁ x₂
heap-union-update : ∀{l h h₀ h₁ v}
→ l ¬dom h₁
→ h ∼ h₀ ⊥ h₁
→ (h [ l ::=ₕ v ]) ∼ (h₀ [ l ::=ₕ v ]) ⊥ h₁
heap-union-update {l}{h}{v = v} d x a with (h [ l ::=ₕ v ]) a | Eq.inspect (h [ l ::=ₕ v ]) a
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] with a ≟ l | h a | Eq.inspect h a | x a
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | yes p | just x₂ | Eq.[ eq2 ] | inj₁ x₃ = inj₁ (eq ,, snd x₃)
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | yes p | just x₂ | Eq.[ eq2 ] | inj₂ y rewrite p = inj₁ (eq ,, d)
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | yes p | nothing | Eq.[ eq2 ] | C = inj₁ (eq ,, snd C)
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | no ¬p | just x₂ | Eq.[ eq2 ] | inj₁ x₃ rewrite (Eq.trans (sym eq) eq2) = inj₁ x₃
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | no ¬p | just x₂ | Eq.[ eq2 ] | inj₂ y rewrite (Eq.trans (sym eq) eq2) = inj₂ y
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | no ¬p | nothing | Eq.[ eq2 ] | C rewrite (Eq.trans (sym eq) eq2) = inj₁ C
heap-union-update {l}{h} d x a | nothing | Eq.[ eq ] with a ≟ l | h a | Eq.inspect h a | x a
heap-union-update {l}{h} d x a | nothing | Eq.[ eq ] | no ¬p | just x₁ | Eq.[ eq2 ] | inj₁ x₂ = Eq.trans (Eq.trans (fst x₂) (sym eq2)) eq ,, snd x₂
heap-union-update {l}{h} d x a | nothing | Eq.[ eq ] | no ¬p | just x₁ | Eq.[ eq2 ] | inj₂ y = fst y ,, Eq.trans (snd y) (Eq.trans (sym eq2) eq)
heap-union-update {l}{h} d x a | nothing | Eq.[ eq ] | no ¬p | nothing | Eq.[ eq2 ] | E = E
heap-union-delete : ∀{h h₀ h₁ v}
→ v ¬dom h₁
→ h ∼ h₀ ⊥ h₁
→ (h /[ v ]) ∼ (h₀ /[ v ]) ⊥ h₁
heap-union-delete {h}{h₀}{h₁}{v} d x a with (h /[ v ]) a | Eq.inspect (h /[ v ]) a
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ eq ] with a ≟ v | h a | Eq.inspect h a | x a
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ () ] | yes p | just x₂ | Eq.[ eq2 ] | R
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ eq ] | no ¬p | just x₂ | Eq.[ eq2 ] | inj₁ x₃ rewrite (Eq.trans (sym eq) eq2) = inj₁ x₃
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ eq ] | no ¬p | just x₂ | Eq.[ eq2 ] | inj₂ y rewrite (Eq.trans (sym eq) eq2) = inj₂ y
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ eq ] | no ¬p | nothing | Eq.[ eq2 ] | fst₁ ,, snd₁ = inj₂ (fst₁ ,, Eq.trans snd₁ (Eq.trans (sym eq2) eq))
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] with a ≟ v | h a | Eq.inspect h a | x a
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | yes p | just x₁ | Eq.[ eq2 ] | inj₁ x₂ = refl ,, snd x₂
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | yes p | just x₁ | Eq.[ eq2 ] | inj₂ y rewrite p = refl ,, d
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | yes p | nothing | Eq.[ eq2 ] | E = refl ,, snd E
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | no ¬p | just x₁ | Eq.[ eq2 ] | inj₁ x₂ = Eq.trans (fst x₂) (Eq.trans (sym eq2) eq) ,, snd x₂
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | no ¬p | just x₁ | Eq.[ eq2 ] | inj₂ y = fst y ,, Eq.trans (snd y) (Eq.trans (sym eq2) eq)
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | no ¬p | nothing | Eq.[ eq2 ] | E = E
union-exclusionᵣ : ∀{l h h₀ h₁}
→ h ∼ h₀ ⊥ h₁
→ l ¬dom h
→ l ¬dom h₁
union-exclusionᵣ {l}{h} A B with h l | A l
... | nothing | fst₁ ,, snd₁ = snd₁
union-presenceᵣ : ∀{l h h₀ h₁}
→ h ∼ h₀ ⊥ h₁
→ l dom h
→ l dom h₀
→ l ¬dom h₁
union-presenceᵣ {l}{h} A B C with h l | A l
union-presenceᵣ {l} {h} A B C | just x | inj₁ (fst₁ ,, snd₁) = snd₁
union-presenceᵣ {l} {h} A B (fst₁ ,, snd₁) | just x | inj₂ (fst₂ ,, snd₂) with Eq.trans (sym fst₂) snd₁
... | ()
union-reduction : ∀{a b c s h′ h h₀ h′₀ h₁}
→ ⦅ c , s , h₀ ⦆ ⇒ ⦅ a , b , h′₀ ⦆
→ ⦅ c , s , h ⦆ ⇒ ⦅ a , b , h′ ⦆
→ h ∼ h₀ ⊥ h₁
→ h′ ∼ h′₀ ⊥ h₁
union-reduction Loc Loc C = C
union-reduction Comp₁ Comp₁ C = C
union-reduction (Comp₂ A) (Comp₂ B) C = union-reduction A B C
union-reduction (IfTrue x) (IfTrue x₁) C = C
union-reduction (IfTrue x) (IfFalse x₁) C = C
union-reduction (IfFalse x) (IfTrue x₁) C = C
union-reduction (IfFalse x) (IfFalse x₁) C = C
union-reduction While While C = C
union-reduction (Cons d A B) (Cons d2 A′ B′) C a rewrite A | B | A′ | B′ = heap-union-update (union-exclusionᵣ C d2) C a
union-reduction (Lookup e A) (Lookup e2 A′) C rewrite A | A′ = C
union-reduction (Write x) (Write x₁) C a = heap-union-update (union-presenceᵣ C x₁ x) C a
union-reduction (Dispose x) (Dispose x₁) C a = heap-union-delete (union-presenceᵣ C x₁ x) C a
frame2 : ∀{c s h h₀ h₁ h′ s′}
→ Safe ⦅ c , s , h₀ ⦆
→ h ∼ h₀ ⊥ h₁
→ ⦅ c , s , h ⦆ ⇒* ⦅ SKIP , s′ , h′ ⦆
→ ∃[ h′₀ ] ( ⦅ c , s , h₀ ⦆ ⇒* ⦅ SKIP , s′ , h′₀ ⦆
× h′ ∼ h′₀ ⊥ h₁ )
frame2 s t (.(⦅ SKIP , _ , _ ⦆) ∎) = _ ,, (_ ∎) ,, t
frame2 {h₀ = h₀} s t (_→⟨_⟩_ .(⦅ _ , _ , _ ⦆) {⦅ _ , _ , _ ⦆} x r) with lemma2 h₀ (union-subset _ t) x
... | inj₁ x₄ = ⊥-elim (s (_ →⟨ x₄ ⟩ (abort ∎)))
... | inj₂ (fst₁ ,, fst₂ ,, snd₁) with frame2 (λ z → s (_ →⟨ snd₁ ⟩ z)) (union-reduction snd₁ x t) r
... | fst₃ ,, fst₄ ,, snd₂ = fst₃ ,, (_ →⟨ snd₁ ⟩ fst₄) ,, snd₂
frame2 s t (_→⟨_⟩_ .(⦅ _ , _ , _ ⦆) {abort} x (.abort →⟨ () ⟩ r))
⊨[_]_[_] : assn → com → assn → Set
⊨[ A ] c [ B ] = ∀{s h}
→ A s h
→ Safe ⦅ c , s , h ⦆
× (∀{s′ h′} → ⦅ c , s , h ⦆ ⇒* ⦅ SKIP , s′ , h′ ⦆ → B s′ h′)
NotInfluenced : assn → com → Set
NotInfluenced R c = ∀{s s′ z h₀ h′₀ hᵣ}
→ z ∼ h′₀ ⊥ hᵣ
→ ⦅ c , s , h₀ ⦆ ⇒* ⦅ SKIP , s′ , h′₀ ⦆
→ R s hᵣ → R s′ hᵣ
frame-soundness : ∀{A B R : assn} {c}
→ NotInfluenced R c
→ ⊨[ A ] c [ B ]
→ ⊨[ A * R ] c [ B * R ]
frame-soundness {A}{B}{R}{c} Inf H {s}{h} (h₀ ,, h₁ ,, ⊥ ,, A₀ ,, R₁) with H A₀
... | safe ,, conv = frame1 ⊥ safe ,, frame2-ex
where frame2-ex : ∀{s′ h′}
→ ⦅ c , s , h ⦆ ⇒* ⦅ SKIP , s′ , h′ ⦆
→ ∃[ h₁ ] ∃[ h₂ ] ( (h′ ∼ h₁ ⊥ h₂)
× B s′ h₁
× R s′ h₂)
frame2-ex rs with frame2 safe ⊥ rs
... | h′₀ ,, r ,, ⊥′ = h′₀ ,, h₁ ,, ⊥′ ,, conv r ,, Inf ⊥′ r R₁
| {
"alphanum_fraction": 0.4699630003,
"avg_line_length": 41.4066852368,
"ext": "agda",
"hexsha": "38e807ef5ee7efe5c50d5ac22f64db55cb997813",
"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": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "iwilare/imp-semantics",
"max_forks_repo_path": "SeparationLogic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc",
"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": "iwilare/imp-semantics",
"max_issues_repo_path": "SeparationLogic.agda",
"max_line_length": 164,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "iwilare/imp-semantics",
"max_stars_repo_path": "SeparationLogic.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-24T22:29:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-08T11:54:07.000Z",
"num_tokens": 6589,
"size": 14865
} |
module Issue784.Context where
open import Data.List using (List; []; _∷_; _++_; [_]; filter) renaming (map to mapL)
import Level
open import Issue784.Values
record Context ℓ : Set (Level.suc ℓ) where
constructor context
field get : Values ℓ
signature : ∀ {ℓ} → Context ℓ → Types ℓ
signature = types ∘ Context.get
ctxnames : ∀ {ℓ} → Context ℓ → Names
ctxnames = names ∘ Context.get
NonRepetitiveContext : ∀ {ℓ} → Context ℓ → _
NonRepetitiveContext = NonRepetitiveNames ∘ Context.get
getBySignature : ∀ {ℓ} {n : String} {A : Set ℓ} {x : Context ℓ} → (n , A) ∈ signature x → A
getBySignature {x = x} = getBySignature′ {x = Context.get x} where
getBySignature′ : ∀ {ℓ} {n : String} {A : Set ℓ} {x : Values ℓ} → (n , A) ∈ types x → A
getBySignature′ {x = []} ()
getBySignature′ {x = (_ , _ , à) ∷ _} (here {x = ._} {xs = ._} p) = ≡-elim′ proj₂ (≡-sym p) à
getBySignature′ {x = _ ∷ _} (there {x = ._} {xs = ._} p) = getBySignature′ p
| {
"alphanum_fraction": 0.6238145416,
"avg_line_length": 35.1481481481,
"ext": "agda",
"hexsha": "4426a9324a57a93e9dbe6074cd9ac2190cef1c2c",
"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/LibSucceed/Issue784/Context.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/LibSucceed/Issue784/Context.agda",
"max_line_length": 97,
"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/LibSucceed/Issue784/Context.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": 344,
"size": 949
} |
module Data.Boolean.Functions where
open import Data.Boolean
open import Type
| {
"alphanum_fraction": 0.835443038,
"avg_line_length": 15.8,
"ext": "agda",
"hexsha": "b837b5979d09fcc20edd845de65b2b274dc01033",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/Boolean/Functions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/Boolean/Functions.agda",
"max_line_length": 35,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/Boolean/Functions.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": 16,
"size": 79
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A definition for the permutation relation using setoid equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.List.Relation.Binary.Permutation.Setoid
{a ℓ} (S : Setoid a ℓ) where
open import Data.List.Base using (List; _∷_)
import Data.List.Relation.Binary.Permutation.Homogeneous as Homogeneous
import Data.List.Relation.Binary.Pointwise as Pointwise
open import Data.List.Relation.Binary.Equality.Setoid S
open import Data.Nat.Base using (ℕ; zero; suc; _+_)
open import Level using (_⊔_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
private
module Eq = Setoid S
open Eq using (_≈_) renaming (Carrier to A)
------------------------------------------------------------------------
-- Definition
open Homogeneous public
using (refl; prep; swap; trans)
infix 3 _↭_
_↭_ : Rel (List A) (a ⊔ ℓ)
_↭_ = Homogeneous.Permutation _≈_
------------------------------------------------------------------------
-- Constructor aliases
-- These provide aliases for `swap` and `prep` when the elements being
-- swapped or prepended are propositionally equal
↭-prep : ∀ x {xs ys} → xs ↭ ys → x ∷ xs ↭ x ∷ ys
↭-prep x xs↭ys = prep Eq.refl xs↭ys
↭-swap : ∀ x y {xs ys} → xs ↭ ys → x ∷ y ∷ xs ↭ y ∷ x ∷ ys
↭-swap x y xs↭ys = swap Eq.refl Eq.refl xs↭ys
------------------------------------------------------------------------
-- Functions over permutations
steps : ∀ {xs ys} → xs ↭ ys → ℕ
steps (refl _) = 1
steps (prep _ xs↭ys) = suc (steps xs↭ys)
steps (swap _ _ xs↭ys) = suc (steps xs↭ys)
steps (trans xs↭ys ys↭zs) = steps xs↭ys + steps ys↭zs
------------------------------------------------------------------------
-- _↭_ is an equivalence
↭-reflexive : _≡_ ⇒ _↭_
↭-reflexive refl = refl (Pointwise.refl Eq.refl)
↭-refl : Reflexive _↭_
↭-refl = ↭-reflexive refl
↭-sym : Symmetric _↭_
↭-sym = Homogeneous.sym Eq.sym
↭-trans : Transitive _↭_
↭-trans = trans
↭-isEquivalence : IsEquivalence _↭_
↭-isEquivalence = Homogeneous.isEquivalence Eq.refl Eq.sym
↭-setoid : Setoid _ _
↭-setoid = Homogeneous.setoid {R = _≈_} Eq.refl Eq.sym
------------------------------------------------------------------------
-- A reasoning API to chain permutation proofs
module PermutationReasoning where
private
module Base = SetoidReasoning ↭-setoid
open SetoidReasoning ↭-setoid public
hiding (step-≈; step-≈˘)
infixr 2 step-↭ step-↭˘ step-≋ step-≋˘ step-swap step-prep
step-↭ = Base.step-≈
step-↭˘ = Base.step-≈˘
-- Step with pointwise list equality
step-≋ : ∀ x {y z} → y IsRelatedTo z → x ≋ y → x IsRelatedTo z
step-≋ x (relTo y↔z) x≋y = relTo (trans (refl x≋y) y↔z)
-- Step with flipped pointwise list equality
step-≋˘ : ∀ x {y z} → y IsRelatedTo z → y ≋ x → x IsRelatedTo z
step-≋˘ x y↭z y≋x = x ≋⟨ ≋-sym y≋x ⟩ y↭z
-- Skip reasoning on the first element
step-prep : ∀ x xs {ys zs : List A} → (x ∷ ys) IsRelatedTo zs →
xs ↭ ys → (x ∷ xs) IsRelatedTo zs
step-prep x xs rel xs↭ys = relTo (trans (prep Eq.refl xs↭ys) (begin rel))
-- Skip reasoning about the first two elements
step-swap : ∀ x y xs {ys zs : List A} → (y ∷ x ∷ ys) IsRelatedTo zs →
xs ↭ ys → (x ∷ y ∷ xs) IsRelatedTo zs
step-swap x y xs rel xs↭ys = relTo (trans (swap Eq.refl Eq.refl xs↭ys) (begin rel))
syntax step-↭ x y↭z x↭y = x ↭⟨ x↭y ⟩ y↭z
syntax step-↭˘ x y↭z y↭x = x ↭˘⟨ y↭x ⟩ y↭z
syntax step-≋ x y↭z x≋y = x ≋⟨ x≋y ⟩ y↭z
syntax step-≋˘ x y↭z y≋x = x ≋˘⟨ y≋x ⟩ y↭z
syntax step-prep x xs y↭z x↭y = x ∷ xs <⟨ x↭y ⟩ y↭z
syntax step-swap x y xs y↭z x↭y = x ∷ y ∷ xs <<⟨ x↭y ⟩ y↭z
| {
"alphanum_fraction": 0.5577772007,
"avg_line_length": 32.0916666667,
"ext": "agda",
"hexsha": "fedc89ee42356f63ad9a64c77e3851dd47118bcb",
"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/Binary/Permutation/Setoid.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/Binary/Permutation/Setoid.agda",
"max_line_length": 85,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Permutation/Setoid.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": 1344,
"size": 3851
} |
module Issue919 where
open import Common.Prelude
Zero : Nat → Set
Zero 0 = ⊤
Zero (suc _) = ⊥
test : (n : Nat) {p : Zero n} → Set → Set
test 0 A = A
test (suc _) {()}
-- Horrible error for first clause:
-- Cannot eliminate type Set with pattern {(implicit)} (did you supply
-- too many arguments?)
-- when checking that the pattern zero has type Nat
-- Caused by trailing implicit insertion (see Rules/Def.hs).
-- With trailing implicit insertion switched off, this should work now.
| {
"alphanum_fraction": 0.678,
"avg_line_length": 23.8095238095,
"ext": "agda",
"hexsha": "73e8cca26f2e38b0d01975323c339f5ec09d9987",
"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/Issue919.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/Issue919.agda",
"max_line_length": 71,
"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/Issue919.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": 133,
"size": 500
} |
{-# OPTIONS --no-termination-check #-}
module Issue137 where
record Foo : Set1 where
field
foo : {x : Set} → Set
record Bar : Set1 where
field
bar : Foo
record Baz (P : Bar) : Set1 where
field
baz : Set
postulate
P : Bar
Q : Baz P
f : Baz.baz Q → Set
f r with f r
f r | A = A
-- The bug was:
-- Issue137.agda:22,1-12
-- Set should be a function type, but it isn't
-- when checking that the expression λ x → Foo.foo (Bar.bar P) {x} has
-- type Set
-- If the field foo is replaced by
-- foo : (x : Set) → Set
-- then the code type checks.
| {
"alphanum_fraction": 0.6151142355,
"avg_line_length": 16.7352941176,
"ext": "agda",
"hexsha": "d0d3ec84d8dd932fa3415ab7cd65dc85b61712e0",
"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/Issue137.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/Issue137.agda",
"max_line_length": 70,
"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/Issue137.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": 188,
"size": 569
} |
-- Andreas, AIM XXIII 2016-04-21 Overloaded projections
-- Milestone 1: Check overloaded projections on rhs (without postponing).
{-# OPTIONS --allow-unsolved-metas #-}
module _ (A : Set) (a : A) where
record R B : Set where
field f : B
open R
record S B : Set where
field f : B
open S
r : R A
R.f r = a
s : S A
S.f s = f r
t : R A → S A
S.f (t r) = f r
u : _
u = f s
-- interactive
hole0 : A
hole0 = {! f s !} -- normalize me
hole1 = {!λ r → f (t r)!} -- normalize me
record T B : Set where
field f : B → B
open T
-- Postpone /further/ argument of overloaded projection.
hole2 : ∀{A} → T A → A → A
hole2 t x = f t {!x!}
-- Milestone 2: Postpone overloading.
hole3 = f {! r !}
| {
"alphanum_fraction": 0.5962910128,
"avg_line_length": 14.6041666667,
"ext": "agda",
"hexsha": "0911e26a74801b469d9adb76868f3b38bb8d7f9f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue1944-1-i.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue1944-1-i.agda",
"max_line_length": 73,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue1944-1-i.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": 251,
"size": 701
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties satisfied by strict partial orders
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Properties.StrictPartialOrder
{s₁ s₂ s₃} (SPO : StrictPartialOrder s₁ s₂ s₃) where
open Relation.Binary.StrictPartialOrder SPO
renaming (trans to <-trans)
open import Relation.Binary.Construct.StrictToNonStrict _≈_ _<_
------------------------------------------------------------------------
-- Strict partial orders can be converted to posets
poset : Poset _ _ _
poset = record
{ isPartialOrder = isPartialOrder isStrictPartialOrder
}
open Poset poset public
| {
"alphanum_fraction": 0.5510718789,
"avg_line_length": 29.3703703704,
"ext": "agda",
"hexsha": "c782aedd1260222a064a36944bc62baa24f938a8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Properties/StrictPartialOrder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Properties/StrictPartialOrder.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Properties/StrictPartialOrder.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": 151,
"size": 793
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.