hexsha
stringlengths 40
40
| size
int64 3
1.05M
| ext
stringclasses 163
values | lang
stringclasses 53
values | max_stars_repo_path
stringlengths 3
945
| max_stars_repo_name
stringlengths 4
112
| max_stars_repo_head_hexsha
stringlengths 40
78
| max_stars_repo_licenses
sequencelengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 3
945
| max_issues_repo_name
stringlengths 4
113
| max_issues_repo_head_hexsha
stringlengths 40
78
| max_issues_repo_licenses
sequencelengths 1
10
| max_issues_count
float64 1
116k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
945
| max_forks_repo_name
stringlengths 4
113
| max_forks_repo_head_hexsha
stringlengths 40
78
| max_forks_repo_licenses
sequencelengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 3
1.05M
| avg_line_length
float64 1
966k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
c5afe5cb5f75f064c0d625fb2fc66b6684a3e147 | 1,778 | agda | Agda | theory/ky-qre.agda | OUPL/Zar | 9243f9d77d0c8af99afa4f536156a3e23b1c40e1 | [
"BSD-3-Clause"
] | null | null | null | theory/ky-qre.agda | OUPL/Zar | 9243f9d77d0c8af99afa4f536156a3e23b1c40e1 | [
"BSD-3-Clause"
] | 5 | 2019-09-13T15:40:08.000Z | 2019-10-06T16:32:25.000Z | theory/ky-qre.agda | OUPL/Zar | 9243f9d77d0c8af99afa4f536156a3e23b1c40e1 | [
"BSD-3-Clause"
] | null | null | null | {-# OPTIONS --guardedness #-}
module ky where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; _≢_; refl; cong; cong₂; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Rational using (ℚ; _+_; _*_; _-_)
open import Data.Bool
open import Data.Bool.Properties
open import Data.Rational
open import Data.Nat as ℕ using (ℕ; zero; suc)
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Agda.Builtin.Size
open import Data.Product
open import Data.Unit
open import Data.Maybe
data QRE : Set → Set → Set₁ where
⊥ : ∀{D C} → QRE D C
ε : ∀{D C} → C → QRE D C
α : ∀{D C}
→ (D → Bool) --φ
→ (D → C) --op
→ QRE D C
split : ∀{D C B A}
→ QRE D A --f
→ QRE D B --g
→ (A → B → C) --op
→ QRE D C
iter : ∀{D B A}
→ QRE D B --init
→ QRE D A --body
→ (B → A → B) --op
→ QRE D B
or : ∀{D C}
→ QRE D C
→ QRE D C
→ QRE D C
Event : Set
Event = ℕ
data Val : Set → Set where
VBool : Bool → Val Bool
VNat : ℕ → Val ℕ
data Exp : Set → Set where
EVal : ∀{t : Set} → Val t → Exp t
data Com : Set → Set where
CFlip : ∀{t} → Com t → Com t → Com t
CUpd : Exp Event → Com ⊤
CIte : ∀{t} → Exp Bool → Com t → Com t → Com t
CSeq : ∀{t} → Com ⊤ → Com t → Com t
is-true : Bool → Bool
is-true = λ{x → x}
data CoList (i : Size) (A : Set) : Set where
nil : CoList i A
cons : A → ∀{j : Size< i} → CoList j A → CoList i A
_++_ : ∀{A} → CoList ∞ A → CoList ∞ A → CoList ∞ A
nil ++ s₂ = s₂
(cons a s₁) ++ s₂ = cons a (s₁ ++ s₂)
interp : Com ⊤ → QRE Bool (CoList ∞ Event)
interp (CFlip c₁ c₂) =
or (split (α is-true λ{_ → nil}) (interp c₁) (_++_))
(split (α not λ{_ → nil}) (interp c₂) (_++_))
| 23.394737 | 54 | 0.545557 |
2060ef76fba93a2703a258e394967a8f4db09f6d | 2,552 | agda | Agda | src/index.agda | ice1k/Theorems | 7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc | [
"Apache-2.0"
] | 1 | 2020-04-15T15:28:03.000Z | 2020-04-15T15:28:03.000Z | src/index.agda | ice1k/Theorems | 7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc | [
"Apache-2.0"
] | null | null | null | src/index.agda | ice1k/Theorems | 7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc | [
"Apache-2.0"
] | null | null | null | module index where
-- natural numbers
--- additions
import Nats.Add.Assoc
using (nat-add-assoc) -- associative law
import Nats.Add.Comm
using (nat-add-comm) -- commutative law
import Nats.Add.Invert
using (nat-add-invert) -- a + a == b + b implies a == b
using (nat-add-invert-1) -- a + 1 == b + 1 implies a == b
--- multiplications
import Nats.Multiply.Comm
using (nat-multiply-comm) -- commutative law
import Nats.Multiply.Distrib
using (nat-multiply-distrib) -- distributive law
import Nats.Multiply.Assoc
using (nat-multiply-assoc) -- associative law
-- integers
--- some properties
import Ints.Properties
using (eq-int-to-nat) -- for natrual number a, + a == + a implis a == a
using (eq-neg-int-to-nat) -- for natrual number a, - a == - a implis a == a
using (eq-nat-to-int) -- for natrual number a, a == a implis + a == + a
using (eq-neg-nat-to-int) -- for natrual number a, a == a implis - a == - a
--- additions
import Ints.Add.Comm
using (int-add-comm) -- commutative law
import Ints.Add.Assoc
using (int-add-assoc) -- associative law
import Ints.Add.Invert
using (int-add-invert) -- a + a == b + b implis a == b
-- non-negative rationals
--- some properties
import Rationals.Properties
-- if b is not zero, n times b div b is the original number
using (times-div-id)
-- additions
import Rationals.Add.Comm
using (rational-add-comm) -- commutative law
import Rationals.Add.Assoc
using (rational-add-assoc) -- associative law
-- multiplications
import Rationals.Multiply.Comm
using (rational-multiply-comm) -- commutative law
-- logics
--- the "and" relations
import Logics.And
using (and-comm) -- commutative law
using (and-assoc) -- associative law
--- the "or" relations
import Logics.Or
using (or-comm) -- commutative law
using (or-assoc) -- associative law
using (or-elim) -- elimination rule
--- negations
import Logics.Not
-- law that negative twice will make a positive
using (not-not)
using (contrapositive) -- contrapositive
-- vectors
--- reverse twice gives the original vector
import Vecs.Reverse
using (vec-rev-rev-id)
-- lists
--- reverse twice gives the original vector
import Lists.Reverse
using (list-rev-rev-id)
-- isomorphisms
--- natrual numbers and others
import Isos.NatLike
using (iso-nat-vec) -- with vector
using (iso-nat-list) -- with list
--- trees
import Isos.TreeLike
using (iso-seven-tree-in-one) -- seven trees in one
-- groups
--- s3 group, xxx=e, yy=e, yx=xxy
import Groups.Symm.S3
using (s3-property-1) -- given s3, prove xyx≡y
| 26.863158 | 77 | 0.694749 |
4ae837d83d313f179fa4b7fe7e64cc04858a3593 | 673 | agda | Agda | src/Rationals.agda | ice1k/Theorems | 7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc | [
"Apache-2.0"
] | 1 | 2020-04-15T15:28:03.000Z | 2020-04-15T15:28:03.000Z | src/Rationals.agda | ice1k/Theorems | 7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc | [
"Apache-2.0"
] | null | null | null | src/Rationals.agda | ice1k/Theorems | 7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc | [
"Apache-2.0"
] | null | null | null | module Rationals where
open import Nats renaming (_+_ to _:+:_; _*_ to _:*:_)
open import Equality
open import Data.Product
open import Agda.Builtin.TrustMe
infixl 7 _÷_
infixr 5 _→ℕ
infixr 7 _÷_↓_
infixr 7 _÷_↑_
infixl 6 _+_
data ℚ : Set where
_÷_ : (a b : ℕ) → ℚ
_→ℕ : {a : ℕ} → ℚ → ∃ (λ m → m ≡ a)
_→ℕ {a} _ = a , refl
-- of course.
_÷_↓_ : ∀ a b n → (a :*: n ÷ (b :*: n)) ≡ a ÷ b
_ ÷ _ ↓ _ = primTrustMe
_÷_↑_ : ∀ a b n → a ÷ b ≡ (a :*: n ÷ (b :*: n))
a ÷ b ↑ n = sym (a ÷ b ↓ n)
_+_ : ℚ → ℚ → ℚ
a ÷ c + b ÷ d = (a :*: d :+: b :*: c) ÷ (c :*: d)
_*_ : ℚ → ℚ → ℚ
(a ÷ c) * (b ÷ d) = a :*: b ÷ (c :*: d)
_/_ : ℚ → ℚ → ℚ
(a ÷ c) / (b ÷ d) = a :*: d ÷ (c :*: b)
| 19.228571 | 54 | 0.447251 |
4a32d79a7e9b8836c609a5d569220f1e8da39d30 | 3,589 | agda | Agda | test/asset/agda-stdlib-1.0/Relation/Binary/Reflection.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | test/asset/agda-stdlib-1.0/Relation/Binary/Reflection.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | test/asset/agda-stdlib-1.0/Relation/Binary/Reflection.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- The Agda standard library
--
-- Helpers intended to ease the development of "tactics" which use
-- proof by reflection
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Data.Fin
open import Data.Nat
open import Data.Vec as Vec
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (module Equivalence)
open import Level
open import Relation.Binary
import Relation.Binary.PropositionalEquality as P
-- Think of the parameters as follows:
--
-- * Expr: A representation of code.
-- * var: The Expr type should support a notion of variables.
-- * ⟦_⟧: Computes the semantics of an expression. Takes an
-- environment mapping variables to something.
-- * ⟦_⇓⟧: Computes the semantics of the normal form of the
-- expression.
-- * correct: Normalisation preserves the semantics.
--
-- Given these parameters two "tactics" are returned, prove and solve.
--
-- For an example of the use of this module, see Algebra.RingSolver.
module Relation.Binary.Reflection
{e a s}
{Expr : ℕ → Set e} {A : Set a}
(Sem : Setoid a s)
(var : ∀ {n} → Fin n → Expr n)
(⟦_⟧ ⟦_⇓⟧ : ∀ {n} → Expr n → Vec A n → Setoid.Carrier Sem)
(correct : ∀ {n} (e : Expr n) ρ →
⟦ e ⇓⟧ ρ ⟨ Setoid._≈_ Sem ⟩ ⟦ e ⟧ ρ)
where
open import Data.Vec.N-ary
open import Data.Product
import Relation.Binary.Reasoning.Setoid as Eq
open Setoid Sem
open Eq Sem
-- If two normalised expressions are semantically equal, then their
-- non-normalised forms are also equal.
prove : ∀ {n} (ρ : Vec A n) e₁ e₂ →
⟦ e₁ ⇓⟧ ρ ≈ ⟦ e₂ ⇓⟧ ρ →
⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ
prove ρ e₁ e₂ hyp = begin
⟦ e₁ ⟧ ρ ≈⟨ sym (correct e₁ ρ) ⟩
⟦ e₁ ⇓⟧ ρ ≈⟨ hyp ⟩
⟦ e₂ ⇓⟧ ρ ≈⟨ correct e₂ ρ ⟩
⟦ e₂ ⟧ ρ ∎
-- Applies the function to all possible "variables".
close : ∀ {A : Set e} n → N-ary n (Expr n) A → A
close n f = f $ⁿ Vec.map var (allFin n)
-- A variant of prove which should in many cases be easier to use,
-- because variables and environments are handled in a less explicit
-- way.
--
-- If the type signature of solve is a bit daunting, then it may be
-- helpful to instantiate n with a small natural number and normalise
-- the remainder of the type.
solve : ∀ n (f : N-ary n (Expr n) (Expr n × Expr n)) →
Eqʰ n _≈_ (curryⁿ ⟦ proj₁ (close n f) ⇓⟧) (curryⁿ ⟦ proj₂ (close n f) ⇓⟧) →
Eq n _≈_ (curryⁿ ⟦ proj₁ (close n f) ⟧) (curryⁿ ⟦ proj₂ (close n f) ⟧)
solve n f hyp =
curryⁿ-cong _≈_ ⟦ proj₁ (close n f) ⟧ ⟦ proj₂ (close n f) ⟧
(λ ρ → prove ρ (proj₁ (close n f)) (proj₂ (close n f))
(curryⁿ-cong⁻¹ _≈_
⟦ proj₁ (close n f) ⇓⟧ ⟦ proj₂ (close n f) ⇓⟧
(Eqʰ-to-Eq n _≈_ hyp) ρ))
-- A variant of solve which does not require that the normal form
-- equality is proved for an arbitrary environment.
solve₁ : ∀ n (f : N-ary n (Expr n) (Expr n × Expr n)) →
∀ⁿ n (curryⁿ λ ρ →
⟦ proj₁ (close n f) ⇓⟧ ρ ≈ ⟦ proj₂ (close n f) ⇓⟧ ρ →
⟦ proj₁ (close n f) ⟧ ρ ≈ ⟦ proj₂ (close n f) ⟧ ρ)
solve₁ n f =
Equivalence.from (uncurry-∀ⁿ n) ⟨$⟩ λ ρ →
P.subst id (P.sym (left-inverse (λ _ → _ ≈ _ → _ ≈ _) ρ))
(prove ρ (proj₁ (close n f)) (proj₂ (close n f)))
-- A variant of _,_ which is intended to make uses of solve and solve₁
-- look a bit nicer.
infix 4 _⊜_
_⊜_ : ∀ {n} → Expr n → Expr n → Expr n × Expr n
_⊜_ = _,_
| 34.180952 | 77 | 0.578155 |
207bb976f747a3ff504b6a63b04d66bb7d341625 | 1,254 | agda | Agda | Data/List/Iterable.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | 6 | 2020-04-07T17:58:13.000Z | 2022-02-05T06:53:22.000Z | Data/List/Iterable.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | Data/List/Iterable.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | module Data.List.Iterable where
open import Data
open import Data.List
import Data.List.Functions as List
open import Logic.Propositional
open import Logic.Predicate
import Lvl
open import Relator.Equals
open import Structure.Container.Iterable
open import Type
private variable ℓ : Lvl.Level
private variable T : Type{ℓ}
instance
List-iterable : Iterable(List(T))
Iterable.Element (List-iterable {T = T}) = T
Iterable.isEmpty List-iterable = List.isEmpty
Iterable.current List-iterable ∅ = <>
Iterable.current List-iterable (x ⊰ l) = x
Iterable.indexStep List-iterable ∅ = <>
Iterable.indexStep List-iterable (_ ⊰ _) = <>
Iterable.step List-iterable ∅ = <>
Iterable.step List-iterable (x ⊰ l) = l
instance
List-finite-iterable : Iterable.Finite(List-iterable{T = T})
∃.witness List-finite-iterable = List.foldᵣ
∃.proof List-finite-iterable {iter = ∅} = [≡]-intro
∃.proof List-finite-iterable {iter = x ⊰ l} = [≡]-intro
instance
List-empty : Iterable.EmptyConstruction(List-iterable{T = T})(∅)
List-empty = <>
instance
List-prepend : Iterable.PrependConstruction(List-iterable{T = T})(_⊰_)
∃.witness List-prepend = [≡]-intro
∃.proof List-prepend = [∧]-intro [≡]-intro [≡]-intro
| 30.585366 | 72 | 0.694577 |
235b0d2c0ed5cae26b6076ce891b1242f8c1a4b1 | 1,630 | agda | Agda | src/Relation/Binary/Indexed/SetoidReasoning.agda | banacorn/categories | 9f6d933b227aecab338ecaef1d86566a54fdac68 | [
"MIT"
] | 1 | 2018-01-04T23:19:30.000Z | 2018-01-04T23:19:30.000Z | src/Relation/Binary/Indexed/SetoidReasoning.agda | banacorn/categories | 9f6d933b227aecab338ecaef1d86566a54fdac68 | [
"MIT"
] | null | null | null | src/Relation/Binary/Indexed/SetoidReasoning.agda | banacorn/categories | 9f6d933b227aecab338ecaef1d86566a54fdac68 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Convenient syntax for "equational reasoning" in multiple Indexed Setoids
------------------------------------------------------------------------
-- Example use:
--
-- open import Data.Maybe
-- import Relation.Binary.Indexed.SetoidReasoning as SetR
--
-- begin⟨ S ⟩
-- x
-- ≈⟨ drop-just (begin⟨ setoid S ⟩
-- just x
-- ≈⟨ justx≈mz ⟩
-- mz
-- ≈⟨ mz≈justy ⟩
-- just y ∎) ⟩
-- y
-- ≈⟨ y≈z ⟩
-- z ∎
open import Relation.Binary.Indexed.EqReasoning as EqR using (_IsRelatedTo_)
open import Relation.Binary.Indexed
open import Relation.Binary.Core using (_≡_)
open Setoid
module Relation.Binary.Indexed.SetoidReasoning where
infix 1 begin⟨_⟩_
infixr 2 _≈⟨_⟩_
infix 3 _∎
begin⟨_⟩_ : ∀ {𝒾 𝒸 ℓ} {I : Set 𝒾} (S : Setoid I 𝒸 ℓ) → {i j : I}
→ {x : Carrier S i} → {y : Carrier S j}
→ _IsRelatedTo_ S x y → _≈_ S x y
begin⟨_⟩_ S p = EqR.begin_ S p
_∎ : ∀ {𝒾 𝒸 ℓ} {I : Set 𝒾} {S : Setoid I 𝒸 ℓ} → {i : I} → (x : Carrier S i)
→ _IsRelatedTo_ S x x
_∎ {S = S} = EqR._∎ S --EqR._∎ S
_≈⟨_⟩_ : ∀ {𝒾 𝒸 ℓ} {I : Set 𝒾} {S : Setoid I 𝒸 ℓ} → {i j k : I}
→ (x : Carrier S i) → {y : Carrier S j} → {z : Carrier S k}
→ _≈_ S x y → _IsRelatedTo_ S y z → _IsRelatedTo_ S x z
_≈⟨_⟩_ {S = S} = EqR._≈⟨_⟩_ S
-- _≡⟨_⟩_ : ∀ {𝒾 𝒸 ℓ} {I : Set 𝒾} {S : Setoid I 𝒸 ℓ} {i j : I}
-- → (x : Carrier S i) → {y : Carrier S i} → {z : Carrier S j}
-- → x ≡ y → _IsRelatedTo_ S y z → _IsRelatedTo_ S x z
-- _≡⟨_⟩_ {S = S} {i = i} {j = j} = {! EqR._≡⟨_⟩_ S {i = i} {j = i} {k = j} !}
| 30.185185 | 79 | 0.476687 |
d0ea9abfc1308f87ccd3501d40d84affb68f928e | 8,820 | agda | Agda | Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | 1 | 2021-10-31T17:32:49.000Z | 2021-10-31T17:32:49.000Z | Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | {-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.QuotientAlgebra where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Powerset using (_∈_; _⊆_)
open import Cubical.Foundations.Structure
open import Cubical.HITs.SetQuotients hiding (_/_)
open import Cubical.Data.Unit
open import Cubical.Data.Sigma.Properties using (Σ≡Prop)
open import Cubical.Algebra.CommRing
import Cubical.Algebra.CommRing.QuotientRing as CommRing
import Cubical.Algebra.Ring.QuotientRing as Ring
open import Cubical.Algebra.CommRing.Ideal hiding (IdealsIn)
open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.CommAlgebra.Ideal
open import Cubical.Algebra.CommAlgebra.Kernel
open import Cubical.Algebra.CommAlgebra.Instances.Unit
open import Cubical.Algebra.Algebra.Base using (IsAlgebraHom; isPropIsAlgebraHom)
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.Ideal using (isIdeal)
open import Cubical.Algebra.CommRingSolver.Reflection
open import Cubical.Algebra.Algebra.Properties
open AlgebraHoms using (compAlgebraHom)
private
variable
ℓ : Level
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) (I : IdealsIn A) where
open CommRingStr {{...}} hiding (_-_; -_; dist; ·Lid; ·Rdist+) renaming (_·_ to _·R_; _+_ to _+R_)
open CommAlgebraStr {{...}}
open RingTheory (CommRing→Ring (CommAlgebra→CommRing A)) using (-DistR·)
instance
_ : CommRingStr _
_ = snd R
_ : CommAlgebraStr _ _
_ = snd A
_/_ : CommAlgebra R ℓ
_/_ = commAlgebraFromCommRing
((CommAlgebra→CommRing A) CommRing./ I)
(λ r → elim (λ _ → squash/) (λ x → [ r ⋆ x ]) (eq r))
(λ r s → elimProp (λ _ → squash/ _ _)
λ x i → [ ((r ·R s) ⋆ x ≡⟨ ⋆-assoc r s x ⟩
r ⋆ (s ⋆ x) ∎) i ])
(λ r s → elimProp (λ _ → squash/ _ _)
λ x i → [ ((r +R s) ⋆ x ≡⟨ ⋆-ldist r s x ⟩
r ⋆ x + s ⋆ x ∎) i ])
(λ r → elimProp2 (λ _ _ → squash/ _ _)
λ x y i → [ (r ⋆ (x + y) ≡⟨ ⋆-rdist r x y ⟩
r ⋆ x + r ⋆ y ∎) i ])
(elimProp (λ _ → squash/ _ _)
(λ x i → [ (1r ⋆ x ≡⟨ ⋆-lid x ⟩ x ∎) i ]))
λ r → elimProp2 (λ _ _ → squash/ _ _)
λ x y i → [ ((r ⋆ x) · y ≡⟨ ⋆-lassoc r x y ⟩
r ⋆ (x · y) ∎) i ]
where
open CommIdeal using (isCommIdeal)
eq : (r : fst R) (x y : fst A) → x - y ∈ (fst I) → [ r ⋆ x ] ≡ [ r ⋆ y ]
eq r x y x-y∈I = eq/ _ _
(subst (λ u → u ∈ fst I)
((r ⋆ 1a) · (x - y) ≡⟨ ·Rdist+ (r ⋆ 1a) x (- y) ⟩
(r ⋆ 1a) · x + (r ⋆ 1a) · (- y) ≡[ i ]⟨ (r ⋆ 1a) · x + -DistR· (r ⋆ 1a) y i ⟩
(r ⋆ 1a) · x - (r ⋆ 1a) · y ≡[ i ]⟨ ⋆-lassoc r 1a x i
- ⋆-lassoc r 1a y i ⟩
r ⋆ (1a · x) - r ⋆ (1a · y) ≡[ i ]⟨ r ⋆ (·Lid x i) - r ⋆ (·Lid y i) ⟩
r ⋆ x - r ⋆ y ∎ )
(isCommIdeal.·Closed (snd I) _ x-y∈I))
quotientHom : CommAlgebraHom A (_/_)
fst quotientHom = λ x → [ x ]
IsAlgebraHom.pres0 (snd quotientHom) = refl
IsAlgebraHom.pres1 (snd quotientHom) = refl
IsAlgebraHom.pres+ (snd quotientHom) = λ _ _ → refl
IsAlgebraHom.pres· (snd quotientHom) = λ _ _ → refl
IsAlgebraHom.pres- (snd quotientHom) = λ _ → refl
IsAlgebraHom.pres⋆ (snd quotientHom) = λ _ _ → refl
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) (I : IdealsIn A) where
open CommRingStr {{...}} hiding (_-_; -_; dist; ·Lid; ·Rdist+) renaming (_·_ to _·R_; _+_ to _+R_)
open CommAlgebraStr ⦃...⦄
instance
_ : CommRingStr _
_ = snd R
_ : CommAlgebraStr _ _
_ = snd A
private
LRing = CommAlgebra→Ring (A / I)
RRing = (CommAlgebra→Ring A) Ring./ (CommIdeal→Ideal I)
-- sanity check / maybe a helper function some day
CommForget/ : RingEquiv (CommAlgebra→Ring (A / I)) ((CommAlgebra→Ring A) Ring./ (CommIdeal→Ideal I))
fst CommForget/ =
isoToEquiv
(iso
(rec (isSetRing LRing) (λ a → [ a ]) λ a b a-b∈I → eq/ a b a-b∈I)
(rec (isSetRing RRing) (λ a → [ a ]) (λ a b a-b∈I → eq/ a b a-b∈I))
(elimProp (λ _ → isSetRing LRing _ _) λ _ → refl)
(elimProp (λ _ → isSetRing RRing _ _) (λ _ → refl)))
IsRingHom.pres0 (snd CommForget/) = refl
IsRingHom.pres1 (snd CommForget/) = refl
IsRingHom.pres+ (snd CommForget/) = elimProp2 (λ _ _ → isSetRing RRing _ _) (λ _ _ → refl)
IsRingHom.pres· (snd CommForget/) = elimProp2 (λ _ _ → isSetRing RRing _ _) (λ _ _ → refl)
IsRingHom.pres- (snd CommForget/) = elimProp (λ _ → isSetRing RRing _ _) (λ _ → refl)
open IsAlgebraHom
inducedHom : (B : CommAlgebra R ℓ) (ϕ : CommAlgebraHom A B)
→ (fst I) ⊆ (fst (kernel A B ϕ))
→ CommAlgebraHom (A / I) B
fst (inducedHom B ϕ I⊆kernel) =
let open RingTheory (CommRing→Ring (CommAlgebra→CommRing B))
instance
_ : CommAlgebraStr R _
_ = snd B
_ : CommRingStr _
_ = snd (CommAlgebra→CommRing B)
in rec (isSetCommAlgebra B) (λ x → fst ϕ x)
λ a b a-b∈I →
equalByDifference
(fst ϕ a) (fst ϕ b)
((fst ϕ a) - (fst ϕ b) ≡⟨ cong (λ u → (fst ϕ a) + u) (sym (IsAlgebraHom.pres- (snd ϕ) _)) ⟩
(fst ϕ a) + (fst ϕ (- b)) ≡⟨ sym (IsAlgebraHom.pres+ (snd ϕ) _ _) ⟩
fst ϕ (a - b) ≡⟨ I⊆kernel (a - b) a-b∈I ⟩
0r ∎)
pres0 (snd (inducedHom B ϕ kernel⊆I)) = pres0 (snd ϕ)
pres1 (snd (inducedHom B ϕ kernel⊆I)) = pres1 (snd ϕ)
pres+ (snd (inducedHom B ϕ kernel⊆I)) = elimProp2 (λ _ _ → isSetCommAlgebra B _ _) (pres+ (snd ϕ))
pres· (snd (inducedHom B ϕ kernel⊆I)) = elimProp2 (λ _ _ → isSetCommAlgebra B _ _) (pres· (snd ϕ))
pres- (snd (inducedHom B ϕ kernel⊆I)) = elimProp (λ _ → isSetCommAlgebra B _ _) (pres- (snd ϕ))
pres⋆ (snd (inducedHom B ϕ kernel⊆I)) = λ r → elimProp (λ _ → isSetCommAlgebra B _ _) (pres⋆ (snd ϕ) r)
injectivePrecomp : (B : CommAlgebra R ℓ) (f g : CommAlgebraHom (A / I) B)
→ f ∘a (quotientHom A I) ≡ g ∘a (quotientHom A I)
→ f ≡ g
injectivePrecomp B f g p =
Σ≡Prop
(λ h → isPropIsAlgebraHom (CommRing→Ring R) (snd (CommAlgebra→Algebra (A / I))) h (snd (CommAlgebra→Algebra B)))
(descendMapPath (fst f) (fst g) (isSetCommAlgebra B)
λ x → λ i → fst (p i) x)
{- trivial quotient -}
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) where
open CommAlgebraStr (snd A)
oneIdealQuotient : CommAlgebraEquiv (A / (1Ideal A)) (UnitCommAlgebra R)
fst oneIdealQuotient =
isoToEquiv (iso (fst (terminalMap R (A / (1Ideal A))))
(λ _ → [ 0a ])
(λ _ → isPropUnit* _ _)
(elimProp (λ _ → squash/ _ _)
λ a → eq/ 0a a tt*))
snd oneIdealQuotient = snd (terminalMap R (A / (1Ideal A)))
zeroIdealQuotient : CommAlgebraEquiv A (A / (0Ideal A))
fst zeroIdealQuotient =
let open RingTheory (CommRing→Ring (CommAlgebra→CommRing A))
in isoToEquiv (iso (fst (quotientHom A (0Ideal A)))
(rec (isSetCommAlgebra A) (λ x → x) λ x y x-y≡0 → equalByDifference x y x-y≡0)
(elimProp (λ _ → squash/ _ _) λ _ → refl)
λ _ → refl)
snd zeroIdealQuotient = snd (quotientHom A (0Ideal A))
[_]/ : {R : CommRing ℓ} {A : CommAlgebra R ℓ} {I : IdealsIn A}
→ (a : fst A) → fst (A / I)
[ a ]/ = [ a ]
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) (I : IdealsIn A) where
open CommIdeal using (isPropIsCommIdeal)
private
π = quotientHom A I
kernel≡I : kernel A (A / I) π ≡ I
kernel≡I =
kernel A (A / I) π ≡⟨ Σ≡Prop
(isPropIsCommIdeal (CommAlgebra→CommRing A))
refl ⟩
_ ≡⟨ CommRing.kernel≡I {R = CommAlgebra→CommRing A} I ⟩
I ∎
private
module _ (R : CommRing ℓ) where
open CommRingStr (snd R)
lemma : (y : (fst R)) → y ≡ y - 0r
lemma = solve R
isZeroFromIdeal : {R : CommRing ℓ} {A : CommAlgebra R ℓ} {I : IdealsIn A}
→ (x : ⟨ A ⟩) → x ∈ (fst I) → fst (quotientHom A I) x ≡ CommAlgebraStr.0a (snd (A / I))
isZeroFromIdeal {A = A} {I = I} x x∈I = eq/ x 0a (subst (λ y → y ∈ (fst I)) step x∈I )
where
open CommAlgebraStr (snd A)
step : x ≡ x - 0a
step = lemma (CommAlgebra→CommRing A) x
0' : ⟨ A / I ⟩
0' = fst (quotientHom A I) 0a
| 42.608696 | 118 | 0.545238 |
d0afccfbfa6f68adec2b7f43f1dc521223a90b26 | 393 | agda | Agda | archive/agda-3/src/Oscar/Class/Precategory.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null | archive/agda-3/src/Oscar/Class/Precategory.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | 1 | 2019-04-29T00:35:04.000Z | 2019-05-11T23:33:04.000Z | archive/agda-3/src/Oscar/Class/Precategory.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class.IsPrecategory
open import Oscar.Class.Transitivity
module Oscar.Class.Precategory where
record Precategory 𝔬 𝔯 ℓ : Ø ↑̂ (𝔬 ∙̂ 𝔯 ∙̂ ℓ) where
constructor ∁
infix 4 _∼̇_
field
{𝔒} : Ø 𝔬
_∼_ : 𝔒 → 𝔒 → Ø 𝔯
_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ
_↦_ : Transitivity.type _∼_
⦃ `IsPrecategory ⦄ : IsPrecategory _∼_ _∼̇_ _↦_
| 23.117647 | 51 | 0.618321 |
0e23be3d4c50150d7cad8fab0113df5cf2ae15f3 | 5,337 | agda | Agda | src/hott/level/closure/extra.agda | pcapriotti/agda-base | bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c | [
"BSD-3-Clause"
] | 20 | 2015-06-12T12:20:17.000Z | 2022-02-01T11:25:54.000Z | src/hott/level/closure/extra.agda | pcapriotti/agda-base | bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c | [
"BSD-3-Clause"
] | 4 | 2015-02-02T14:32:16.000Z | 2016-10-26T11:57:26.000Z | src/hott/level/closure/extra.agda | pcapriotti/agda-base | bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c | [
"BSD-3-Clause"
] | 4 | 2015-02-02T12:17:00.000Z | 2019-05-04T19:31:00.000Z | {-# OPTIONS --without-K #-}
module hott.level.closure.extra where
open import level
open import decidable
open import sum
open import level using (lsuc; ↑; lift)
open import equality.core
open import equality.calculus
open import function.core using (_∘_; const)
open import function.extensionality
open import function.isomorphism.core
open import function.isomorphism.lift
open import function.isomorphism.utils
open import sets.bool
open import sets.unit
open import sets.nat.core
open import sets.nat.ordering.leq.core
open import hott.level.core
open import hott.level.sets
open import hott.level.closure.core
open import hott.equivalence.core
using (weak-equiv; _≈_)
open import hott.univalence
open import sets.empty
open import sets.unit
abstract
-- Π preserves h-levels
Π-level : ∀ {i j n} {X : Set i}{Y : X → Set j}
→ ((x : X) → h n (Y x))
→ h n ((x : X) → Y x)
Π-level {n = 0} c = Π-contr c
Π-level {n = suc n} {X = X}{Y} hn = λ f g →
subst (h n) strong-funext (Π-level (λ x → hn x (f x) (g x)))
-- Σ preserves h-levels
Σ-level : ∀ {i j n} {X : Set i}{Y : X → Set j}
→ h n X → ((x : X) → h n (Y x))
→ h n (Σ X Y)
Σ-level {n = 0}{X = X}{Y} (x₀ , cx) hy =
(x₀ , proj₁ (hy x₀)) , λ { (x , y) → c x y }
where
c : (x : X)(y : Y x) → (x₀ , proj₁ (hy x₀)) ≡ (x , y)
c x y = ap (λ x → (x , proj₁ (hy x))) (cx x)
· ap (_,_ x) (proj₂ (hy x) y)
Σ-level {n = suc n} hx hy = λ a b → iso-level Σ-split-iso
(Σ-level (hx _ _) (λ p → hy (proj₁ b) _ _))
-- × preserves h-levels
×-level : ∀ {i j n}{X : Set i}{Y : Set j}
→ h n X → h n Y → h n (X × Y)
×-level hx hy = Σ-level hx (λ _ → hy)
-- ⊎ preserves h-levels
⊎-level : ∀ {i j n}{X : Set i}{Y : Set j}
→ 2 ≤ n → h n X → h n Y → h n (X ⊎ Y)
⊎-level {i}{j}{n} {X}{Y} p hx hy = iso-level lem
(Σ-level (h! {p = decide p} bool-set) P-level)
where
P : Bool → Set (i ⊔ j)
P true = ↑ j X
P false = ↑ i Y
P-level : (b : Bool) → h n (P b)
P-level true = iso-level (lift-iso j X) hx
P-level false = iso-level (lift-iso i Y) hy
lem : Σ Bool P ≅ (X ⊎ Y)
lem = iso f g H K
where
f : (Σ Bool P) → (X ⊎ Y)
f (true , lift x) = inj₁ x
f (false , lift y) = inj₂ y
g : (X ⊎ Y) → (Σ Bool P)
g (inj₁ x) = (true , lift x)
g (inj₂ y) = (false , lift y)
H : (x : Σ Bool P) → g (f x) ≡ x
H (true , lift x) = refl
H (false , lift y) = refl
K : (x : X ⊎ Y) → f (g x) ≡ x
K (inj₁ x) = refl
K (inj₂ y) = refl
Π-level-impl : ∀ {i j n} {X : Set i}{Y : X → Set j}
→ ((x : X) → h n (Y x))
→ h n ({x : X} → Y x)
Π-level-impl {X = X}{Y} hY = iso-level impl-iso (Π-level hY)
-- being contractible is a proposition
contr-h1 : ∀ {i}(X : Set i) → h 1 (contr X)
contr-h1 X = prop⇒h1 λ { (x₀ , c₀) (x₁ , c₁) →
unapΣ (c₀ x₁ , contr⇒prop (lem (x₀ , c₀) x₁) _ _) }
where
lem : ∀ {i}{A : Set i} → contr A → (x : A) → contr ((x' : A) → x ≡ x')
lem c x = Π-level (λ x' → h↑ c x x')
-- being of h-level n is a proposition
hn-h1 : ∀ {i} n (X : Set i) → h 1 (h n X)
hn-h1 0 X = contr-h1 X
hn-h1 (suc n) X = Π-level λ x → Π-level λ y → hn-h1 n (x ≡ y)
-- being a weak equivalence is a proposition
weak-equiv-h1 : ∀ {i j}{X : Set i}{Y : Set j}
→ (f : X → Y)
→ h 1 (weak-equiv f)
weak-equiv-h1 f = Π-level λ y
→ contr-h1 _
equiv-level : ∀ {i j n}{X : Set i}{Y : Set j}
→ h n X → h n Y
→ h n (X ≈ Y)
equiv-level {n = 0} hX hY = Σ-level (Π-level (λ _ → hY)) λ f
→ (λ y → Σ-level hX λ x → h↑ hY _ _)
, (λ w → h1⇒prop (weak-equiv-h1 f) _ _)
equiv-level {n = suc n } hX hY
= Σ-level (Π-level λ _ → hY) λ f
→ h! (weak-equiv-h1 f)
⊎-h1 : ∀ {i j}{A : Set i}{B : Set j}
→ h 1 A → h 1 B → ¬ (A × B)
→ h 1 (A ⊎ B)
⊎-h1 {A = A}{B = B} hA hB u = prop⇒h1 ⊎-prop
where
⊎-prop : prop (A ⊎ B)
⊎-prop (inj₁ a) (inj₁ a') = ap inj₁ (h1⇒prop hA a a')
⊎-prop (inj₁ a) (inj₂ b') = ⊥-elim (u (a , b'))
⊎-prop (inj₂ b) (inj₁ a') = ⊥-elim (u (a' , b))
⊎-prop (inj₂ b) (inj₂ b') = ap inj₂ (h1⇒prop hB b b')
inj-level : ∀ {i j n}{A : Set i}{B : Set j}
→ (f : A → B)
→ h (suc n) A → h n (injective f)
inj-level f hA
= Π-level-impl λ x
→ Π-level-impl λ x'
→ Π-level λ p
→ hA x x'
↣-level : ∀ {i j n}{A : Set i}{B : Set j}
→ h (suc n) A → h n B → h n (A ↣ B)
↣-level hA hB
= Σ-level (Π-level λ _ → hB) λ f
→ inj-level f hA
¬-h1 : ∀ {i}{X : Set i} → h 1 (¬ X)
¬-h1 = Π-level λ _ → ⊥-prop
type-level : ∀ {i n} → h (suc n) (Type i n)
type-level {i}{n} (X , hX) (Y , hY) = iso-level uni-iso' (equiv-level hX hY)
where
uni-iso' : (X ≈ Y) ≅ ((X , hX) ≡ (Y , hY))
uni-iso' = begin
(X ≈ Y)
≅⟨ sym≅ uni-iso ⟩
(X ≡ Y)
≅⟨ sym≅ ×-right-unit ⟩
((X ≡ Y) × ⊤)
≅⟨ ( Σ-ap-iso refl≅ λ q → sym≅ (contr-⊤-iso (hn-h1 n Y _ _)) ) ⟩
( Σ (X ≡ Y) λ q → subst (h n) q hX ≡ hY )
≅⟨ Σ-split-iso ⟩
((X , hX) ≡ (Y , hY))
∎
where open ≅-Reasoning
| 31.767857 | 78 | 0.468615 |
c52b84974801e4eae67c81248c6d9796c6b28e5d | 1,397 | agda | Agda | Cubical/Algebra/RingSolver/CommRingAsAlmostRing.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | Cubical/Algebra/RingSolver/CommRingAsAlmostRing.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | Cubical/Algebra/RingSolver/CommRingAsAlmostRing.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.RingSolver.CommRingAsAlmostRing where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.CommRing.Base
open import Cubical.Algebra.RingSolver.AlmostRing
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring.Base
open import Cubical.Algebra.Ring.Properties
private
variable
ℓ : Level
open Cubical.Algebra.Ring.Properties.Theory
CommRingAsAlmostRing : CommRing {ℓ} → AlmostRing {ℓ}
CommRingAsAlmostRing {ℓ}
(R , commringstr _ _ _ _ _
(iscommring (isring
(isabgroup (isgroup +-isMonoid inverse) +-comm)
·-isMonoid dist)
·-comm)) =
let
R' : CommRing {ℓ}
R' = (R , commringstr _ _ _ _ _
(iscommring (isring
(isabgroup (isgroup +-isMonoid inverse) +-comm) ·-isMonoid dist)
·-comm))
R″ = CommRing→Ring R'
in almostring R _ _ _ _ _
(isalmostring
+-isMonoid
·-isMonoid
+-comm
·-comm
(λ x y z → fst (dist x y z))
(λ x y z → snd (dist x y z))
(λ x y → sym (-DistL· R″ x y))
(λ x y → sym (-Dist R″ x y))
(λ x → 0LeftAnnihilates R″ x)
λ x → 0RightAnnihilates R″ x)
| 30.369565 | 87 | 0.615605 |
1823fe1849ca54fb1136021e49e2043aa1c5c188 | 251 | agda | Agda | test/Fail/LevelLiterals.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/LevelLiterals.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/LevelLiterals.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- There are no level literals in the concrete syntax. This file tests
-- if type errors use level literals.
module LevelLiterals where
open import Common.Level
data ⊥ : Set₁ where
DoubleNegated : ∀ {ℓ} → Set ℓ → Set
DoubleNegated A = (A → ⊥) → ⊥
| 20.916667 | 70 | 0.705179 |
cb886a6dc1374a026311ba866745cfbf825dee33 | 2,466 | agda | Agda | test/Fail/Issue1406.agda | favonia/agda | 8d433b967567c08afe15d04a5cb63b6f6d8884ee | [
"BSD-2-Clause"
] | null | null | null | test/Fail/Issue1406.agda | favonia/agda | 8d433b967567c08afe15d04a5cb63b6f6d8884ee | [
"BSD-2-Clause"
] | 6 | 2021-10-18T08:12:24.000Z | 2021-11-24T08:31:10.000Z | test/Fail/Issue1406.agda | antoinevanmuylder/agda | bd59d5b07ffe02a43b28d186d95e1747aac5bc8c | [
"BSD-2-Clause"
] | null | null | null | -- Andreas, 2014-01-16, issue 1406
-- Agda with K again is inconsistent with classical logic
-- {-# OPTIONS --cubical-compatible #-}
open import Common.Level
open import Common.Prelude
open import Common.Equality
cast : {A B : Set} (p : A ≡ B) (a : A) → B
cast refl a = a
data HEq {α} {A : Set α} (a : A) : {B : Set α} (b : B) → Set (lsuc α) where
refl : HEq a a
mkHet : {A B : Set} (eq : A ≡ B) (a : A) → HEq a (cast eq a)
mkHet refl a = refl
-- Type with a big forced index. (Allowed unless --cubical-compatible.)
-- This definition is allowed in Agda master since 2014-10-17
-- https://github.com/agda/agda/commit/9a4ebdd372dc0510e2d77e726fb0f4e6f56781e8
-- However, probably the consequences of this new feature have not
-- been grasped fully yet.
data SING : (F : Set → Set) → Set where
sing : (F : Set → Set) → SING F
-- The following theorem is the culprit.
-- It needs K.
-- It allows us to unify forced indices, which I think is wrong.
thm : ∀{F G : Set → Set} (a : SING F) (b : SING G) (p : HEq a b) → F ≡ G
thm (sing F) (sing .F) refl = refl
-- Note that a direct matching fails, as it generates heterogeneous constraints.
-- thm a .a refl = refl
-- However, by matching on the constructor sing, the forced index
-- is exposed to unification.
-- As a consequence of thm,
-- SING is injective which it clearly should not be.
SING-inj : ∀ (F G : Set → Set) (p : SING F ≡ SING G) → F ≡ G
SING-inj F G p = thm (sing F) _ (mkHet p (sing F))
-- The rest is an adaption of Chung-Kil Hur's proof (2010)
data Either {α} (A B : Set α) : Set α where
inl : A → Either A B
inr : B → Either A B
data Inv (A : Set) : Set1 where
inv : (F : Set → Set) (eq : SING F ≡ A) → Inv A
¬ : ∀{α} → Set α → Set α
¬ A = A → ⊥
-- Classical logic
postulate em : ∀{α} (A : Set α) → Either A (¬ A)
Cantor' : (A : Set) → Either (Inv A) (¬ (Inv A)) → Set
Cantor' A (inl (inv F eq)) = ¬ (F A)
Cantor' A (inr _) = ⊤
Cantor : Set → Set
Cantor A = Cantor' A (em (Inv A))
C : Set
C = SING Cantor
ic : Inv C
ic = inv Cantor refl
cast' : ∀{F G} → SING F ≡ SING G → ¬ (F C) → ¬ (G C)
cast' eq = subst (λ F → ¬ (F C)) (SING-inj _ _ eq)
-- Self application 1
diag : ¬ (Cantor C)
diag c with em (Inv C) | c
diag c | inl (inv F eq) | c' = cast' eq c' c
diag _ | inr f | _ = f ic
-- Self application 2
diag' : Cantor C
diag' with em (Inv C)
diag' | inl (inv F eq) = cast' (sym eq) diag
diag' | inr _ = _
absurd : ⊥
absurd = diag diag'
| 26.804348 | 80 | 0.603406 |
23385b98dc79a7c64c7623c9cb8519dc1f4dccee | 7,499 | agda | Agda | SOAS/Metatheory/Traversal.agda | k4rtik/agda-soas | b224d31e20cfd010b7c924ce940f3c2f417777e3 | [
"MIT"
] | null | null | null | SOAS/Metatheory/Traversal.agda | k4rtik/agda-soas | b224d31e20cfd010b7c924ce940f3c2f417777e3 | [
"MIT"
] | null | null | null | SOAS/Metatheory/Traversal.agda | k4rtik/agda-soas | b224d31e20cfd010b7c924ce940f3c2f417777e3 | [
"MIT"
] | null | null | null |
open import SOAS.Common
open import SOAS.Families.Core
open import Categories.Object.Initial
open import SOAS.Coalgebraic.Strength
import SOAS.Metatheory.MetaAlgebra
-- Traversals parametrised by a pointed coalgebra
module SOAS.Metatheory.Traversal {T : Set}
(⅀F : Functor 𝔽amiliesₛ 𝔽amiliesₛ) (⅀:Str : Strength ⅀F)
(𝔛 : Familyₛ) (open SOAS.Metatheory.MetaAlgebra ⅀F 𝔛)
(𝕋:Init : Initial 𝕄etaAlgebras)
where
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Abstract.Hom
import SOAS.Abstract.Coalgebra as →□ ; open →□.Sorted
import SOAS.Abstract.Box as □ ; open □.Sorted
open import SOAS.Metatheory.Algebra ⅀F
open import SOAS.Metatheory.Semantics ⅀F ⅀:Str 𝔛 𝕋:Init
open Strength ⅀:Str
private
variable
Γ Δ Θ Π : Ctx
α β : T
𝒫 𝒬 𝒜 : Familyₛ
-- Parametrised interpretation into an internal hom
module Traversal (𝒫ᴮ : Coalgₚ 𝒫)(𝑎𝑙𝑔 : ⅀ 𝒜 ⇾̣ 𝒜)
(φ : 𝒫 ⇾̣ 𝒜)(χ : 𝔛 ⇾̣ 〖 𝒜 , 𝒜 〗) where
open Coalgₚ 𝒫ᴮ
-- Under the assumptions 𝒜 and 〖 𝒫 , 𝒜 〗 are both meta-algebras
𝒜ᵃ : MetaAlg 𝒜
𝒜ᵃ = record { 𝑎𝑙𝑔 = 𝑎𝑙𝑔 ; 𝑣𝑎𝑟 = λ x → φ (η x) ; 𝑚𝑣𝑎𝑟 = χ }
Travᵃ : MetaAlg 〖 𝒫 , 𝒜 〗
Travᵃ = record
{ 𝑎𝑙𝑔 = λ t σ → 𝑎𝑙𝑔 (str 𝒫ᴮ 𝒜 t σ)
; 𝑣𝑎𝑟 = λ x σ → φ (σ x)
; 𝑚𝑣𝑎𝑟 = λ 𝔪 ε σ → χ 𝔪 (λ 𝔫 → ε 𝔫 σ)
}
-- 〖 𝒫 , 𝒜 〗 is also a pointed □-coalgebra
Travᵇ : Coalg 〖 𝒫 , 𝒜 〗
Travᵇ = record { r = λ h ρ σ → h (σ ∘ ρ) ; counit = refl ; comult = refl }
Travᴮ : Coalgₚ 〖 𝒫 , 𝒜 〗
Travᴮ = record { ᵇ = Travᵇ ; η = λ x σ → φ (σ x) ; r∘η = refl }
open Semantics Travᵃ public renaming (𝕤𝕖𝕞 to 𝕥𝕣𝕒𝕧)
-- Traversal-specific homomorphism properties that incorporate a substitution
𝕥⟨𝕧⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{x : ℐ α Γ} → 𝕥𝕣𝕒𝕧 (𝕧𝕒𝕣 x) σ ≡ φ (σ x)
𝕥⟨𝕧⟩ {σ = σ} = cong (λ - → - σ) ⟨𝕧⟩
𝕥⟨𝕞⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ 𝕥𝕣𝕒𝕧 (𝕞𝕧𝕒𝕣 𝔪 ε) σ ≡ χ 𝔪 (λ p → 𝕥𝕣𝕒𝕧 (ε p) σ)
𝕥⟨𝕞⟩ {σ = σ} = cong (λ - → - σ) ⟨𝕞⟩
𝕥⟨𝕒⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{t : ⅀ 𝕋 α Γ}
→ 𝕥𝕣𝕒𝕧 (𝕒𝕝𝕘 t) σ ≡ 𝑎𝑙𝑔 (str 𝒫ᴮ 𝒜 (⅀₁ 𝕥𝕣𝕒𝕧 t) σ)
𝕥⟨𝕒⟩ {σ = σ} = cong (λ - → - σ) ⟨𝕒⟩
-- Congruence in the two arguments of 𝕥𝕣𝕒𝕧
𝕥≈₁ : {σ : Γ ~[ 𝒫 ]↝ Δ}{t₁ t₂ : 𝕋 α Γ} → t₁ ≡ t₂ → 𝕥𝕣𝕒𝕧 t₁ σ ≡ 𝕥𝕣𝕒𝕧 t₂ σ
𝕥≈₁ {σ = σ} p = cong (λ - → 𝕥𝕣𝕒𝕧 - σ) p
𝕥≈₂ : {σ₁ σ₂ : Γ ~[ 𝒫 ]↝ Δ}{t : 𝕋 α Γ}
→ ({τ : T}{x : ℐ τ Γ} → σ₁ x ≡ σ₂ x)
→ 𝕥𝕣𝕒𝕧 t σ₁ ≡ 𝕥𝕣𝕒𝕧 t σ₂
𝕥≈₂ {t = t} p = cong (𝕥𝕣𝕒𝕧 t) (dext′ p)
-- A pointed meta-Λ-algebra induces 𝕒𝕝𝕘 traversal into □ 𝒜
module □Traversal {𝒜} (𝒜ᵃ : MetaAlg 𝒜) =
Traversal ℐᴮ (MetaAlg.𝑎𝑙𝑔 𝒜ᵃ) (MetaAlg.𝑣𝑎𝑟 𝒜ᵃ) (MetaAlg.𝑚𝑣𝑎𝑟 𝒜ᵃ)
-- Corollary: □ lifts to an endofunctor on pointed meta-Λ-algebras
□ᵃ : (𝒜ᵃ : MetaAlg 𝒜) → MetaAlg (□ 𝒜)
□ᵃ = □Traversal.Travᵃ
-- Helper records for proving equality of maps f, g out of 𝕋,
-- with 0, 1 or 2 parameters
record MapEq₀ (𝒜 : Familyₛ)(f g : 𝕋 ⇾̣ 𝒜) : Set where
field
ᵃ : MetaAlg 𝒜
open Semantics ᵃ
open 𝒜
field
f⟨𝑣⟩ : {x : ℐ α Γ}
→ f (𝕧𝕒𝕣 x) ≡ 𝑣𝑎𝑟 x
f⟨𝑚⟩ : {𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ f (𝕞𝕧𝕒𝕣 𝔪 ε) ≡ 𝑚𝑣𝑎𝑟 𝔪 (f ∘ ε)
f⟨𝑎⟩ : {t : ⅀ 𝕋 α Γ}
→ f (𝕒𝕝𝕘 t) ≡ 𝑎𝑙𝑔 (⅀₁ f t)
g⟨𝑣⟩ : {x : ℐ α Γ}
→ g (𝕧𝕒𝕣 x) ≡ 𝑣𝑎𝑟 x
g⟨𝑚⟩ : {𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ g (𝕞𝕧𝕒𝕣 𝔪 ε) ≡ 𝑚𝑣𝑎𝑟 𝔪 (g ∘ ε)
g⟨𝑎⟩ : {t : ⅀ 𝕋 α Γ}
→ g (𝕒𝕝𝕘 t) ≡ 𝑎𝑙𝑔 (⅀₁ g t)
fᵃ : MetaAlg⇒ 𝕋ᵃ ᵃ f
fᵃ = record { ⟨𝑎𝑙𝑔⟩ = f⟨𝑎⟩ ; ⟨𝑣𝑎𝑟⟩ = f⟨𝑣⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ = f⟨𝑚⟩ }
gᵃ : MetaAlg⇒ 𝕋ᵃ ᵃ g
gᵃ = record { ⟨𝑎𝑙𝑔⟩ = g⟨𝑎⟩ ; ⟨𝑣𝑎𝑟⟩ = g⟨𝑣⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ = g⟨𝑚⟩ }
≈ : (t : 𝕋 α Γ) → f t ≡ g t
≈ t = eq fᵃ gᵃ t
record MapEq₁ (𝒫ᴮ : Coalgₚ 𝒫)(𝑎𝑙𝑔 : ⅀ 𝒜 ⇾̣ 𝒜)
(f g : 𝕋 ⇾̣ 〖 𝒫 , 𝒜 〗) : Set where
field
φ : 𝒫 ⇾̣ 𝒜
χ : 𝔛 ⇾̣ 〖 𝒜 , 𝒜 〗
open Traversal 𝒫ᴮ 𝑎𝑙𝑔 φ χ
field
f⟨𝑣⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{x : ℐ α Γ}
→ f (𝕧𝕒𝕣 x) σ ≡ φ (σ x)
f⟨𝑚⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ f (𝕞𝕧𝕒𝕣 𝔪 ε) σ ≡ χ 𝔪 (λ p → f (ε p) σ)
f⟨𝑎⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{t : ⅀ 𝕋 α Γ}
→ f (𝕒𝕝𝕘 t) σ ≡ 𝑎𝑙𝑔 (str 𝒫ᴮ 𝒜 (⅀₁ f t) σ)
g⟨𝑣⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{x : ℐ α Γ}
→ g (𝕧𝕒𝕣 x) σ ≡ φ (σ x)
g⟨𝑚⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ g (𝕞𝕧𝕒𝕣 𝔪 ε) σ ≡ χ 𝔪 (λ p → g (ε p) σ)
g⟨𝑎⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{t : ⅀ 𝕋 α Γ}
→ g (𝕒𝕝𝕘 t) σ ≡ 𝑎𝑙𝑔 (str 𝒫ᴮ 𝒜 (⅀₁ g t) σ)
fᵃ : MetaAlg⇒ 𝕋ᵃ Travᵃ f
fᵃ = record { ⟨𝑎𝑙𝑔⟩ = dext′ f⟨𝑎⟩ ; ⟨𝑣𝑎𝑟⟩ = dext′ f⟨𝑣⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ = dext′ f⟨𝑚⟩ }
gᵃ : MetaAlg⇒ 𝕋ᵃ Travᵃ g
gᵃ = record { ⟨𝑎𝑙𝑔⟩ = dext′ g⟨𝑎⟩ ; ⟨𝑣𝑎𝑟⟩ = dext′ g⟨𝑣⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ = dext′ g⟨𝑚⟩ }
≈ : {σ : Γ ~[ 𝒫 ]↝ Δ}(t : 𝕋 α Γ) → f t σ ≡ g t σ
≈ {σ = σ} t = cong (λ - → - σ) (eq fᵃ gᵃ t)
record MapEq₂ (𝒫ᴮ : Coalgₚ 𝒫)(𝒬ᴮ : Coalgₚ 𝒬)(𝑎𝑙𝑔 : ⅀ 𝒜 ⇾̣ 𝒜)
(f g : 𝕋 ⇾̣ 〖 𝒫 , 〖 𝒬 , 𝒜 〗 〗) : Set where
field
φ : 𝒬 ⇾̣ 𝒜
ϕ : 𝒫 ⇾̣ 〖 𝒬 , 𝒜 〗
χ : 𝔛 ⇾̣ 〖 𝒜 , 𝒜 〗
open Traversal 𝒫ᴮ (Traversal.𝒜.𝑎𝑙𝑔 𝒬ᴮ 𝑎𝑙𝑔 φ χ) ϕ (λ 𝔪 ε σ → χ 𝔪 (λ 𝔫 → ε 𝔫 σ))
field
f⟨𝑣⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{x : ℐ α Γ}
→ f (𝕧𝕒𝕣 x) σ ς ≡ ϕ (σ x) ς
f⟨𝑚⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ f (𝕞𝕧𝕒𝕣 𝔪 ε) σ ς ≡ χ 𝔪 (λ 𝔫 → f (ε 𝔫) σ ς)
f⟨𝑎⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{t : ⅀ 𝕋 α Γ}
→ f (𝕒𝕝𝕘 t) σ ς ≡ 𝑎𝑙𝑔 (str 𝒬ᴮ 𝒜 (str 𝒫ᴮ 〖 𝒬 , 𝒜 〗 (⅀₁ f t) σ) ς)
g⟨𝑣⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{x : ℐ α Γ}
→ g (𝕧𝕒𝕣 x) σ ς ≡ ϕ (σ x) ς
g⟨𝑚⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ g (𝕞𝕧𝕒𝕣 𝔪 ε) σ ς ≡ χ 𝔪 (λ 𝔫 → g (ε 𝔫) σ ς)
g⟨𝑎⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{t : ⅀ 𝕋 α Γ}
→ g (𝕒𝕝𝕘 t) σ ς ≡ 𝑎𝑙𝑔 (str 𝒬ᴮ 𝒜 (str 𝒫ᴮ 〖 𝒬 , 𝒜 〗 (⅀₁ g t) σ) ς)
fᵃ : MetaAlg⇒ 𝕋ᵃ Travᵃ f
fᵃ = record { ⟨𝑎𝑙𝑔⟩ = dext′ (dext′ f⟨𝑎⟩) ; ⟨𝑣𝑎𝑟⟩ = dext′ (dext′ f⟨𝑣⟩)
; ⟨𝑚𝑣𝑎𝑟⟩ = dext′ (dext′ f⟨𝑚⟩) }
gᵃ : MetaAlg⇒ 𝕋ᵃ Travᵃ g
gᵃ = record { ⟨𝑎𝑙𝑔⟩ = dext′ (dext′ g⟨𝑎⟩) ; ⟨𝑣𝑎𝑟⟩ = dext′ (dext′ g⟨𝑣⟩)
; ⟨𝑚𝑣𝑎𝑟⟩ = dext′ (dext′ g⟨𝑚⟩) }
≈ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}(t : 𝕋 α Γ) → f t σ ς ≡ g t σ ς
≈ {σ = σ}{ς} t = cong (λ - → - σ ς) (eq fᵃ gᵃ t)
-- Interaction of traversal and interpretation
module _ (𝒫ᴮ : Coalgₚ 𝒫)(𝒜ᵃ : MetaAlg 𝒜)(φ : 𝒫 ⇾̣ 𝒜) where
open MetaAlg 𝒜ᵃ
open Coalgₚ 𝒫ᴮ
open Semantics 𝒜ᵃ
open Traversal 𝒫ᴮ 𝑎𝑙𝑔 φ 𝑚𝑣𝑎𝑟 using (𝕥𝕣𝕒𝕧 ; 𝕥⟨𝕒⟩ ; 𝕥⟨𝕧⟩ ; 𝕥⟨𝕞⟩)
open ≡-Reasoning
-- Traversal with the point of 𝒫 is the same as direct interpretation
𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 : (φ∘η≈𝑣𝑎𝑟 : ∀{α Γ}{v : ℐ α Γ} → φ (η v) ≡ 𝑣𝑎𝑟 v){t : 𝕋 α Γ}
→ 𝕥𝕣𝕒𝕧 t η ≡ 𝕤𝕖𝕞 t
𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 φ∘η≈𝑣𝑎𝑟 {t = t} = Semantics.eq 𝒜ᵃ (record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → trans 𝕥⟨𝕒⟩ (cong 𝑎𝑙𝑔 (begin
str 𝒫ᴮ 𝒜 (⅀₁ 𝕥𝕣𝕒𝕧 t) η
≡⟨ str-nat₁ (ηᴮ⇒ 𝒫ᴮ) (⅀₁ 𝕥𝕣𝕒𝕧 t) id ⟩
str ℐᴮ 𝒜 (⅀₁ (λ{ h ρ → h (η ∘ ρ)}) ((⅀₁ 𝕥𝕣𝕒𝕧 t))) id
≡⟨ str-unit 𝒜 ((⅀₁ (λ{ h ρ → h (η ∘ ρ)}) ((⅀₁ 𝕥𝕣𝕒𝕧 t)))) ⟩
⅀₁ (i 𝒜) (⅀₁ (λ { h ρ → h (η ∘ ρ) }) (⅀₁ 𝕥𝕣𝕒𝕧 t))
≡˘⟨ trans ⅀.homomorphism ⅀.homomorphism ⟩
⅀₁ (λ t → 𝕥𝕣𝕒𝕧 t η) t
∎))}
; ⟨𝑣𝑎𝑟⟩ = λ{ {v = v} → trans 𝕥⟨𝕧⟩ φ∘η≈𝑣𝑎𝑟 }
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪}{ε} → 𝕥⟨𝕞⟩ } }) 𝕤𝕖𝕞ᵃ⇒ t
-- Traversal with the point of 𝒫 into 𝕋 is the identity
𝕥𝕣𝕒𝕧-η≈id : (𝒫ᴮ : Coalgₚ 𝒫)(open Coalgₚ 𝒫ᴮ)(φ : 𝒫 ⇾̣ 𝕋)
(φ∘η≈𝑣𝑎𝑟 : ∀{α Γ}{v : ℐ α Γ} → φ (η v) ≡ 𝕧𝕒𝕣 v){t : 𝕋 α Γ}
→ Traversal.𝕥𝕣𝕒𝕧 𝒫ᴮ 𝕒𝕝𝕘 φ 𝕞𝕧𝕒𝕣 t η ≡ t
𝕥𝕣𝕒𝕧-η≈id 𝒫ᴮ φ φ∘η≈𝑣𝑎𝑟 = trans (𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 𝒫ᴮ 𝕋ᵃ φ φ∘η≈𝑣𝑎𝑟) 𝕤𝕖𝕞-id
-- Corollaries for ℐ-parametrised traversals
□𝕥𝕣𝕒𝕧-id≈𝕤𝕖𝕞 : (𝒜ᵃ : MetaAlg 𝒜){t : 𝕋 α Γ}
→ □Traversal.𝕥𝕣𝕒𝕧 𝒜ᵃ t id ≡ Semantics.𝕤𝕖𝕞 𝒜ᵃ t
□𝕥𝕣𝕒𝕧-id≈𝕤𝕖𝕞 𝒜ᵃ {t} = 𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 ℐᴮ 𝒜ᵃ (MetaAlg.𝑣𝑎𝑟 𝒜ᵃ) refl
□𝕥𝕣𝕒𝕧-id≈id : {t : 𝕋 α Γ} → □Traversal.𝕥𝕣𝕒𝕧 𝕋ᵃ t id ≡ t
□𝕥𝕣𝕒𝕧-id≈id = 𝕥𝕣𝕒𝕧-η≈id ℐᴮ 𝕧𝕒𝕣 refl
| 34.242009 | 80 | 0.47353 |
dc2ceea7337acb7417389bb620c2cbe65b817de2 | 614 | agda | Agda | examples/outdated-and-incorrect/fileIO/Base.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | examples/outdated-and-incorrect/fileIO/Base.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | examples/outdated-and-incorrect/fileIO/Base.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module Base where
postulate String : Set
Char : Set
{-# BUILTIN STRING String #-}
{-# BUILTIN CHAR Char #-}
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () #-}
data Bool : Set where
true : Bool
false : Bool
data False : Set where
record True : Set where
IsTrue : Bool -> Set
IsTrue true = True
IsTrue false = False
{-# COMPILED_DATA Bool True False #-}
infixr 40 _::_
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
{-# COMPILED_DATA List [] (:) #-}
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
{-# COMPILED_DATA _×_ (,) #-}
| 16.157895 | 37 | 0.581433 |
238c4dc85f56865ecf6568cdb0fde2f3ce93f403 | 224 | agda | Agda | Cubical/Data/Fin.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | Cubical/Data/Fin.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | Cubical/Data/Fin.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Fin where
open import Cubical.Data.Fin.Base public
open import Cubical.Data.Fin.Properties public
open import Cubical.Data.Fin.Literals public
| 28 | 50 | 0.75 |
208af95f451fcfdf17a19b042ccc8e7a336e3a96 | 5,853 | agda | Agda | agda/quad.agda | DSLsofMath/BScProj2021 | 87c0340515b0965454d9ba240ecc6de84b74ee0a | [
"BSD-3-Clause"
] | null | null | null | agda/quad.agda | DSLsofMath/BScProj2021 | 87c0340515b0965454d9ba240ecc6de84b74ee0a | [
"BSD-3-Clause"
] | null | null | null | agda/quad.agda | DSLsofMath/BScProj2021 | 87c0340515b0965454d9ba240ecc6de84b74ee0a | [
"BSD-3-Clause"
] | null | null | null | open import Data.Nat hiding ( _+_; _*_; _⊔_; zero )
open import Algebra hiding (Zero)
open import Level using (Level; _⊔_)
open import Data.Product
module quad { c ℓ } ( ring : Ring c ℓ ) where
open Ring ring
data Nat4 : Set where
One : Nat4
Suc : Nat4 -> Nat4
variable
a b d : Level
A : Set a
B : Set b
C : Set c
m n : Nat4
-- Indu:ctive definition of a Quad matrix
data Quad ( A : Set a ) : Nat4 → Set a where
Zero : Quad A n
Scalar : A → Quad A One
Mtx : ( nw ne sw se : Quad A n ) → Quad A (Suc n)
-- Zero with explicit size
zeroQ : ( n : Nat4) → Quad A n
zeroQ n = Zero
oneQ : ∀ { n } → Quad Carrier n
oneQ {One} = Scalar 1#
oneQ {Suc n} = Mtx oneQ Zero
Zero oneQ
-- Equality
-- eq-Zero is only valid when m ≡ n
data EqQ {A : Set a} (_∼_ : A -> A -> Set d) :
(xs : Quad A m) (ys : Quad A n) → Set (a ⊔ d)
where
eq-Zero : ∀ { n } → EqQ _∼_ (zeroQ n) (zeroQ n)
eq-Scalar : { x y : A } ( x∼y : x ∼ y ) → EqQ _∼_ (Scalar x) (Scalar y)
eq-Mtx : { nw1 ne1 sw1 se1 : Quad A m } { nw2 ne2 sw2 se2 : Quad A n }
( nw : EqQ _∼_ nw1 nw2 ) ( ne : EqQ _∼_ ne1 ne2 )
( sw : EqQ _∼_ sw1 sw2 ) ( se : EqQ _∼_ se1 se2 ) →
EqQ _∼_ (Mtx nw1 ne1 sw1 se1) (Mtx nw2 ne2 sw2 se2)
_=q_ : Quad Carrier n -> Quad Carrier n -> Set ( c ⊔ ℓ)
_=q_ = EqQ _≈_
-- Functions
mapq : ∀ { A B : Set } → ( A → B ) → Quad A n -> Quad B n
mapq f Zero = Zero
mapq f (Scalar x) = Scalar (f x)
mapq f (Mtx nw ne sw se) = Mtx (mapq f nw) (mapq f ne) (mapq f sw) (mapq f se)
-- Addition on Quads
_+q_ : ( x y : Quad Carrier n) → Quad Carrier n
Zero +q y = y
Scalar x +q Zero = Scalar x
Scalar x +q Scalar x₁ = Scalar (x + x₁)
Mtx x x₁ x₂ x₃ +q Zero = Mtx x x₁ x₂ x₃
Mtx x x₁ x₂ x₃ +q Mtx y y₁ y₂ y₃ = Mtx (x +q y) (x₁ +q y₁) (x₂ +q y₂) (x₃ +q y₃)
-- Multiplication
data Q' ( A : Set a) : Set a where
Mtx' : ( nw ne sw se : A ) → Q' A
Q'toQuad : Q' (Quad A n) → Quad A (Suc n)
-- Q'toQuad (Mtx' Zero Zero Zero Zero) = Zero
Q'toQuad (Mtx' nw ne sw se) = Mtx nw ne sw se
zipQ' : ( A → B → C ) → Q' A → Q' B → Q' C
zipQ' _op_ (Mtx' nw ne sw se) (Mtx' nw₁ ne₁ sw₁ se₁) = Mtx' (nw op nw₁) (ne op ne₁)
(sw op sw₁) (se op se₁)
colExchange : Q' A → Q' A
colExchange (Mtx' nw ne sw se) = Mtx' ne nw se sw
prmDiagSqsh : Q' A → Q' A
prmDiagSqsh (Mtx' nw ne sw se) = Mtx' nw se nw se
offDiagSqsh : Q' A → Q' A
offDiagSqsh (Mtx' nw ne sw se) = Mtx' sw ne sw se
_*q_ : ( x y : Quad Carrier n) → Quad Carrier n
Zero *q y = Zero
Scalar x *q Zero = Zero
Scalar x *q Scalar x₁ = Scalar (x * x₁)
Mtx x x₁ x₂ x₃ *q Zero = Zero
Mtx x x₁ x₂ x₃ *q Mtx y y₁ y₂ y₃ =
let X = Mtx' x x₁ x₂ x₃
Y = Mtx' y y₁ y₂ y₃
in Q'toQuad (zipQ' _+q_ (zipQ' _*q_ (colExchange X) (offDiagSqsh Y))
(zipQ' _*q_ X (prmDiagSqsh Y)))
-- Example Quad
q1 : Quad ℕ (Suc One)
q1 = Mtx (Scalar 2) (Scalar 7) Zero Zero
q2 : Quad ℕ (Suc (Suc One))
q2 = Mtx q1 q1 Zero (Mtx (Scalar 1) Zero Zero (Scalar 1))
-- Proofs
quad-refl : { a : Quad Carrier n } → a =q a
quad-refl { n } { Zero } = eq-Zero
quad-refl { n } { (Scalar x) } = eq-Scalar refl
quad-refl { n } { (Mtx a a₁ a₂ a₃) } = eq-Mtx quad-refl quad-refl quad-refl quad-refl
quad-sym : { a b : Quad Carrier n } → a =q b → b =q a
quad-sym eq-Zero = eq-Zero
quad-sym (eq-Scalar x∼y) = eq-Scalar (sym x∼y)
quad-sym (eq-Mtx x x₁ x₂ x₃) = eq-Mtx (quad-sym x) (quad-sym x₁) (quad-sym x₂) (quad-sym x₃)
quad-zerol : ∀ { n } ( x : Quad Carrier n ) → ( Zero +q x ) =q x
quad-zerol x = quad-refl
quad-zeror : ∀ { n } ( x : Quad Carrier n ) → ( x +q Zero ) =q x
quad-zeror Zero = quad-refl
quad-zeror (Scalar x) = quad-refl
quad-zeror (Mtx x x₁ x₂ x₃) = quad-refl
-- Need a proof that Zero is left and right +q-identity
-- Should be some kind of (quad-zerol, quad-zeror)
quad-comm : ( a b : Quad Carrier n ) → ( a +q b) =q ( b +q a )
quad-comm Zero b = quad-sym (quad-zeror b)
quad-comm (Scalar x) Zero = quad-refl
quad-comm (Scalar x) (Scalar x₁) = eq-Scalar (+-comm x x₁)
quad-comm (Mtx a a₁ a₂ a₃) Zero = quad-refl
quad-comm (Mtx a a₁ a₂ a₃) (Mtx b b₁ b₂ b₃) = eq-Mtx (quad-comm a b) (quad-comm a₁ b₁)
(quad-comm a₂ b₂) (quad-comm a₃ b₃)
quad-assoc : ( a b c : Quad Carrier n ) → ((a +q b ) +q c ) =q ( a +q ( b +q c ))
quad-assoc Zero b c = quad-refl
quad-assoc (Scalar x) Zero c = quad-refl
quad-assoc (Scalar x) (Scalar x₁) Zero = quad-refl
quad-assoc (Scalar x) (Scalar x₁) (Scalar x₂) = eq-Scalar (+-assoc x x₁ x₂)
quad-assoc (Mtx a a₁ a₂ a₃) Zero c = quad-refl
quad-assoc (Mtx a a₁ a₂ a₃) (Mtx b b₁ b₂ b₃) Zero = quad-refl
quad-assoc (Mtx a a₁ a₂ a₃) (Mtx b b₁ b₂ b₃) (Mtx c c₁ c₂ c₃) = eq-Mtx (quad-assoc a b c ) (quad-assoc a₁ b₁ c₁)
(quad-assoc a₂ b₂ c₂) (quad-assoc a₃ b₃ c₃)
quad-*-zerol : ( x : Quad Carrier n ) → ( Zero *q x ) =q Zero
quad-*-zerol x = eq-Zero
quad-*-zeror : ( x : Quad Carrier n ) → ( x *q Zero ) =q Zero
quad-*-zeror Zero = eq-Zero
quad-*-zeror (Scalar x) = eq-Zero
quad-*-zeror (Mtx x x₁ x₂ x₃) = eq-Zero
quad-onel : ( x : Quad Carrier n ) → ( oneQ *q x ) =q x
quad-onel-lemma : ( x : Quad Carrier n ) → ((oneQ *q x) +q Zero) =q x
quad-onel-lemma {One} Zero = eq-Zero
quad-onel-lemma {Suc n} Zero = eq-Zero
quad-onel-lemma (Scalar x) = eq-Scalar (*-identityˡ x)
quad-onel-lemma (Mtx x x₁ x₂ x₃) = eq-Mtx (quad-onel x) (quad-onel-lemma x₁) (quad-onel-lemma x₂) (quad-onel x₃)
quad-onel Zero = quad-*-zeror oneQ
quad-onel (Scalar x) = eq-Scalar (*-identityˡ x)
quad-onel (Mtx x x₁ x₂ x₃) = eq-Mtx (quad-onel x) (quad-onel-lemma x₁) (quad-onel-lemma x₂) (quad-onel x₃)
| 30.643979 | 114 | 0.558175 |
0e80475f9649dd45c31a147074ae9ce54a4131ca | 1,435 | agda | Agda | LibraBFT/Yasm/Types.agda | cwjnkins/bft-consensus-agda | 71aa2168e4875ffdeece9ba7472ee3cee5fa9084 | [
"UPL-1.0"
] | 4 | 2020-12-16T19:43:41.000Z | 2021-12-18T19:24:05.000Z | LibraBFT/Yasm/Types.agda | cwjnkins/bft-consensus-agda | 71aa2168e4875ffdeece9ba7472ee3cee5fa9084 | [
"UPL-1.0"
] | 72 | 2021-02-04T05:04:33.000Z | 2022-03-25T05:36:11.000Z | LibraBFT/Yasm/Types.agda | cwjnkins/bft-consensus-agda | 71aa2168e4875ffdeece9ba7472ee3cee5fa9084 | [
"UPL-1.0"
] | 6 | 2020-12-16T19:43:52.000Z | 2022-02-18T01:04:32.000Z | {- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
-- This module defines types used in the specification of a SystemModel.
module LibraBFT.Yasm.Types where
-- Actions that can be performed by peers.
--
-- For now, the SystemModel supports only one kind of action: to send a
-- message. Later it might include things like logging, crashes, assertion
-- failures, etc. For example, if an assertion fires, this
-- could "kill the process" and make it not send any messages in the future.
-- We could also then prove that the handlers do not crash, certain
-- messages are logged under certain circumstances, etc.
--
-- Alternatively, certain actions can be kept outside the system model by
-- defining an application-specific PeerState type (see `LibraBFT.Yasm.Base`).
-- For example:
--
-- > libraHandle : Msg → Status × Log × LState → Status × LState × List Action
-- > libraHandle _ (Crashed , l , s) = Crashed , s , [] -- i.e., crashed peers never send messages
-- >
-- > handle = filter isSend ∘ libraHandle
data Action (Msg : Set) : Set where
send : (m : Msg) → Action Msg
-- Injectivity of `send`.
action-send-injective : ∀ {Msg}{m m' : Msg} → send m ≡ send m' → m ≡ m'
action-send-injective refl = refl
| 41 | 111 | 0.719164 |
4a1e283ee4af22e47551bd091adb988d2e4d5e50 | 13,106 | agda | Agda | src/Suspension.agda | nad/equality | 402b20615cfe9ca944662380d7b2d69b0f175200 | [
"MIT"
] | 3 | 2020-05-21T22:58:50.000Z | 2021-09-02T17:18:15.000Z | src/Suspension.agda | nad/equality | 402b20615cfe9ca944662380d7b2d69b0f175200 | [
"MIT"
] | null | null | null | src/Suspension.agda | nad/equality | 402b20615cfe9ca944662380d7b2d69b0f175200 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Suspensions
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- The beginning of this module follows the HoTT book rather closely.
-- The module is parametrised by a notion of equality. The higher
-- constructor of the HIT defining suspensions uses path equality, but
-- the supplied notion of equality is used for many other things.
import Equality.Path as P
module Suspension
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J as Bijection using (_↔_)
open import Embedding equality-with-J as Embedding using (Embedding)
open import Equality.Decision-procedures equality-with-J
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J using (_≃_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import Injection equality-with-J using (_↣_)
open import Interval eq as Interval using (Interval; [0]; [1]; 0≡1)
import Nat equality-with-J as Nat
open import Pointed-type equality-with-J
using (Pointed-type; _→ᴮ_; Ω)
open import Surjection equality-with-J using (_↠_)
private
variable
a b ℓ ℓ₁ ℓ₂ p : Level
A B : Type a
C : Pointed-type a
x y : A
f g : A → B
n : ℕ
-- Suspensions.
data Susp (A : Type a) : Type a where
north south : Susp A
meridianᴾ : A → north P.≡ south
-- Meridians.
meridian : A → _≡_ {A = Susp A} north south
meridian = _↔_.from ≡↔≡ ∘ meridianᴾ
-- A dependent eliminator, expressed using paths.
elimᴾ :
(P : Susp A → Type p)
(n : P north)
(s : P south) →
(∀ x → P.[ (λ i → P (meridianᴾ x i)) ] n ≡ s) →
(x : Susp A) → P x
elimᴾ _ n s n≡s = λ where
north → n
south → s
(meridianᴾ x i) → n≡s x i
-- A non-dependent eliminator, expressed using paths.
recᴾ : (n s : B) → (A → n P.≡ s) → Susp A → B
recᴾ = elimᴾ _
-- A dependent eliminator.
module Elim
(P : Susp A → Type p)
(n : P north)
(s : P south)
(n≡s : ∀ x → subst P (meridian x) n ≡ s)
where
elim : ∀ x → P x
elim = elimᴾ P n s (subst≡→[]≡ ∘ n≡s)
-- "Computation" rule for meridians.
elim-meridian : dcong elim (meridian x) ≡ n≡s x
elim-meridian = dcong-subst≡→[]≡ (refl _)
open Elim public
-- A non-dependent eliminator.
module Rec
{B : Type b}
(n s : B)
(n≡s : A → n ≡ s)
where
rec : Susp A → B
rec = recᴾ n s (_↔_.to ≡↔≡ ∘ n≡s)
rec-meridian : cong rec (meridian x) ≡ n≡s x
rec-meridian = cong-≡↔≡ (refl _)
open Rec public
-- The universal property of suspensions.
universal-property :
(Susp A → B) ↔ (∃ λ (n : B) → ∃ λ (s : B) → A → n ≡ s)
universal-property = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → f north , f south , cong f ∘ meridian
; from = λ { (n , s , f) → rec n s f }
}
; right-inverse-of = λ { (n , s , f) →
n , s , cong (rec n s f) ∘ meridian ≡⟨ cong (λ f → n , s , f) $ ⟨ext⟩ (λ _ → rec-meridian n s f) ⟩∎
n , s , f ∎ }
}
; left-inverse-of = λ f →
let module R = Rec (f north) (f south) (cong f ∘ meridian) in
R.rec ≡⟨ ⟨ext⟩ $ elim _ (refl _) (refl _) (λ x →
subst (λ x → R.rec x ≡ f x) (meridian x) (refl _) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym $ cong R.rec (meridian x))
(trans (refl _) (cong f (meridian x))) ≡⟨ cong₂ (λ p q → trans (sym p) q) R.rec-meridian (trans-reflˡ _) ⟩
trans (sym $ cong f (meridian x)) (cong f (meridian x)) ≡⟨ trans-symˡ _ ⟩∎
refl _ ∎) ⟩∎
f ∎
}
-- Based maps from suspensions of pointed types (using north as the
-- point) are isomorphic to based maps to loop spaces.
Susp→ᴮ↔ : (Susp A , north) →ᴮ C ↔ (A , x) →ᴮ Ω C
Susp→ᴮ↔ {A = A} {C = B , y} {x = x} =
(Susp A , north) →ᴮ (B , y) ↔⟨⟩
(∃ λ (f : Susp A → B) → f north ≡ y) ↝⟨ Σ-cong universal-property (λ _ → F.id) ⟩
(∃ λ (f : ∃ λ n → ∃ λ s → A → n ≡ s) → proj₁ f ≡ y) ↝⟨ inverse Σ-assoc ⟩
(∃ λ n → (∃ λ s → A → n ≡ s) × n ≡ y) ↝⟨ (∃-cong λ _ → inverse Σ-assoc) ⟩
(∃ λ n → ∃ λ s → (A → n ≡ s) × n ≡ y) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ×-comm) ⟩
(∃ λ n → ∃ λ s → n ≡ y × (A → n ≡ s)) ↝⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ n → n ≡ y × ∃ λ s → A → n ≡ s) ↝⟨ Σ-assoc ⟩
(∃ λ (p : ∃ λ n → n ≡ y) → ∃ λ s → A → proj₁ p ≡ s) ↝⟨ drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $ singleton-contractible _ ⟩
(∃ λ s → A → y ≡ s) ↝⟨ (∃-cong λ _ → inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $
other-singleton-contractible _) ⟩
(∃ λ s → ∃ λ (f : A → y ≡ s) → ∃ λ (eq : y ≡ s) → f x ≡ eq) ↝⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ s → ∃ λ (eq : y ≡ s) → ∃ λ (f : A → y ≡ s) → f x ≡ eq) ↝⟨ Σ-assoc ⟩
(∃ λ (p : ∃ λ s → y ≡ s) → ∃ λ (f : A → y ≡ proj₁ p) → f x ≡ proj₂ p) ↝⟨ drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
other-singleton-contractible _ ⟩
(∃ λ (f : A → y ≡ y) → f x ≡ refl y) ↔⟨⟩
(A , x) →ᴮ (Ω (B , y)) □
-- The type of booleans can be expressed as a suspension.
Bool↔Susp-⊥ : Bool ↔ Susp (⊥ {ℓ = ℓ})
Bool↔Susp-⊥ = record
{ surjection = record
{ logical-equivalence = record
{ to = if_then north else south
; from = rec true false (λ ())
}
; right-inverse-of = elim _ (refl _) (refl _) (λ ())
}
; left-inverse-of = λ where
true → refl _
false → refl _
}
private
-- A lemma used in some proofs below.
subst-in-terms-of-trans-and-cong′ :
{x≡y : x ≡ y} {fgx≡x : f (g x) ≡ x} →
subst (λ z → f (g z) ≡ z) x≡y fgx≡x ≡
trans (sym (cong f (cong g x≡y))) (trans fgx≡x x≡y)
subst-in-terms-of-trans-and-cong′
{f = f} {g = g} {x≡y = x≡y} {fgx≡x = fgx≡x} =
subst (λ z → f (g z) ≡ z) x≡y fgx≡x ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (f ∘ g) x≡y)) (trans fgx≡x (cong id x≡y)) ≡⟨ sym $ cong₂ (λ p q → trans (sym p) (trans fgx≡x q)) (cong-∘ _ _ _) (cong-id _) ⟩∎
trans (sym (cong f (cong g x≡y))) (trans fgx≡x x≡y) ∎
-- The remainder of this module is not based on the HoTT book.
-- The interval can be expressed as a suspension.
Interval↔Susp-⊤ : Interval ↔ Susp ⊤
Interval↔Susp-⊤ = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = elim
_
(refl _)
(refl _)
(λ _ →
subst (λ x → to (from x) ≡ x) (meridian tt) (refl _) ≡⟨ subst-in-terms-of-trans-and-cong′ ⟩
trans (sym (cong to (cong from (meridian tt))))
(trans (refl _) (meridian tt)) ≡⟨ cong₂ (λ p q → trans (sym (cong to p)) q)
(rec-meridian _ _ _)
(trans-reflˡ _) ⟩
trans (sym (cong to 0≡1)) (meridian tt) ≡⟨ cong (λ p → trans (sym p) (meridian tt)) $ Interval.rec-0≡1 _ _ _ ⟩
trans (sym (meridian tt)) (meridian tt) ≡⟨ trans-symˡ _ ⟩∎
refl _ ∎)
}
; left-inverse-of = Interval.elim
_
(refl _)
(refl _)
(subst (λ x → from (to x) ≡ x) 0≡1 (refl _) ≡⟨ subst-in-terms-of-trans-and-cong′ ⟩
trans (sym (cong from (cong to 0≡1))) (trans (refl _) 0≡1) ≡⟨ cong₂ (λ p q → trans (sym (cong from p)) q)
(Interval.rec-0≡1 _ _ _)
(trans-reflˡ _) ⟩
trans (sym (cong from (meridian tt))) 0≡1 ≡⟨ cong (λ p → trans (sym p) 0≡1) $ rec-meridian _ _ _ ⟩
trans (sym 0≡1) 0≡1 ≡⟨ trans-symˡ _ ⟩∎
refl _ ∎)
}
where
to = Interval.rec north south (meridian tt)
from = rec [0] [1] λ _ → 0≡1
-- A map function.
map : (A → B) → Susp A → Susp B
map A→B = rec north south (meridian ∘ A→B)
private
-- A helper function used to implement cong-↠ and cong-↔.
map∘map :
(∀ x → f (g x) ≡ x) →
∀ x → map f (map g x) ≡ x
map∘map {f = f} {g = g} hyp = elim
_
(refl _)
(refl _)
(λ x →
subst (λ x → map f (map g x) ≡ x) (meridian x) (refl _) ≡⟨ subst-in-terms-of-trans-and-cong′ ⟩
trans (sym $ cong (map f) $ cong (map g) (meridian x))
(trans (refl _) (meridian x)) ≡⟨ cong₂ (λ p q → trans (sym $ cong (map f) p) q)
(rec-meridian _ _ _)
(trans-reflˡ _) ⟩
trans (sym $ cong (map f) $ meridian (g x)) (meridian x) ≡⟨ cong (λ p → trans (sym p) (meridian x)) $ rec-meridian _ _ _ ⟩
trans (sym $ meridian (f (g x))) (meridian x) ≡⟨ cong (λ y → trans (sym $ meridian y) (meridian x)) $ hyp x ⟩
trans (sym $ meridian x) (meridian x) ≡⟨ trans-symˡ _ ⟩∎
refl _ ∎)
-- Some preservation lemmas.
cong-⇔ : A ⇔ B → Susp A ⇔ Susp B
cong-⇔ A⇔B = record
{ to = map (_⇔_.to A⇔B)
; from = map (_⇔_.from A⇔B)
}
cong-↠ : A ↠ B → Susp A ↠ Susp B
cong-↠ A↠B = record
{ logical-equivalence = cong-⇔ (_↠_.logical-equivalence A↠B)
; right-inverse-of = map∘map (_↠_.right-inverse-of A↠B)
}
cong-↔ : A ↔ B → Susp A ↔ Susp B
cong-↔ A↔B = record
{ surjection = cong-↠ (_↔_.surjection A↔B)
; left-inverse-of = map∘map (_↔_.left-inverse-of A↔B)
}
cong-≃ : A ≃ B → Susp A ≃ Susp B
cong-≃ = from-isomorphism ∘ cong-↔ ∘ from-isomorphism
private
-- Lemmas used to implement ¬-cong-↣ and ¬-cong-Embedding.
⊥↣⊤ : ⊥ {ℓ = ℓ₁} ↣ ↑ ℓ₂ ⊤
⊥↣⊤ = record
{ to = λ ()
; injective = λ {}
}
¬Susp⊥↣Susp⊤ : ¬ (Susp (⊥ {ℓ = ℓ₁}) ↣ Susp (↑ ℓ₂ ⊤))
¬Susp⊥↣Susp⊤ =
Susp ⊥ ↣ Susp (↑ _ ⊤) ↝⟨ (λ f → from-isomorphism (cong-↔ Bijection.↑↔) F.∘ f F.∘
from-isomorphism (cong-↔ ⊥↔⊥)) ⟩
Susp ⊥₀ ↣ Susp ⊤ ↝⟨ (λ f → from-isomorphism (inverse Interval↔Susp-⊤) F.∘ f F.∘
from-isomorphism Bool↔Susp-⊥) ⟩
Bool ↣ Interval ↝⟨ (λ inj → _↣_.to inj , _↣_.injective inj) ⟩
(∃ λ (f : Bool → Interval) → f true ≡ f false → true ≡ false) ↝⟨ Σ-map id (λ f → f (mono₁ 0 Interval.interval-contractible _ _)) ⟩
(Bool → Interval) × true ≡ false ↝⟨ proj₂ ⟩
true ≡ false ↝⟨ Bool.true≢false ⟩□
⊥ □
-- Some negative preservation results.
¬-cong-↣ :
¬ (∀ {A : Type a} {B : Type b} → A ↣ B → Susp A ↣ Susp B)
¬-cong-↣ {a = a} {b = b} =
(∀ {A B} → A ↣ B → Susp A ↣ Susp B) ↝⟨ (λ hyp → hyp) ⟩
(⊥ ↣ ↑ _ ⊤ → Susp ⊥ ↣ Susp (↑ _ ⊤)) ↝⟨ _$ ⊥↣⊤ ⟩
Susp ⊥ ↣ Susp (↑ _ ⊤) ↝⟨ ¬Susp⊥↣Susp⊤ ⟩□
⊥ □
¬-cong-Embedding :
¬ (∀ {A : Type a} {B : Type b} →
Embedding A B → Embedding (Susp A) (Susp B))
¬-cong-Embedding =
(∀ {A B} → Embedding A B → Embedding (Susp A) (Susp B)) ↝⟨ (λ hyp → hyp) ⟩
(Embedding ⊥ (↑ _ ⊤) → Embedding (Susp ⊥) (Susp (↑ _ ⊤))) ↝⟨ _$ Emb-⊥-⊤ ⟩
Embedding (Susp ⊥) (Susp (↑ _ ⊤)) ↝⟨ Embedding.injection ⟩
Susp ⊥ ↣ Susp (↑ _ ⊤) ↝⟨ ¬Susp⊥↣Susp⊤ ⟩□
⊥ □
where
Emb-⊥-⊤ : Embedding ⊥ (↑ _ ⊤)
Emb-⊥-⊤ =
_↔_.to (Embedding.↣↔Embedding
ext
(mono₁ 1 ⊥-propositional)
(mono (Nat.zero≤ 2) (↑-closure 0 ⊤-contractible)))
⊥↣⊤
| 38.209913 | 148 | 0.439112 |
202e7da9127667a1b6afa1b17c681bbd575da1da | 9,287 | agda | Agda | Groups/FreeGroup/Parity.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 4 | 2019-08-08T12:44:19.000Z | 2022-01-28T06:04:15.000Z | Groups/FreeGroup/Parity.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 14 | 2019-01-06T21:11:59.000Z | 2020-04-11T11:03:39.000Z | Groups/FreeGroup/Parity.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 1 | 2021-11-29T13:23:07.000Z | 2021-11-29T13:23:07.000Z | {-# OPTIONS --safe --warning=error #-}
open import Sets.EquivalenceRelations
open import Setoids.Setoids
open import Groups.FreeGroup.Definition
open import Groups.Homomorphisms.Definition
open import Groups.Definition
open import Decidable.Sets
open import Numbers.Naturals.Order
open import LogicalFormulae
open import Semirings.Definition
open import Functions.Definition
open import Groups.Isomorphisms.Definition
open import Boolean.Definition
open import Boolean.Lemmas
module Groups.FreeGroup.Parity {a : _} {A : Set a} (decA : DecidableSet A) where
open import Groups.FreeGroup.Word decA
open import Groups.FreeGroup.Group decA
C2 : Group (reflSetoid Bool) xor
Group.+WellDefined C2 refl refl = refl
Group.0G C2 = BoolFalse
Group.inverse C2 = id
Group.+Associative C2 {BoolTrue} {BoolTrue} {BoolTrue} = refl
Group.+Associative C2 {BoolTrue} {BoolTrue} {BoolFalse} = refl
Group.+Associative C2 {BoolTrue} {BoolFalse} {z} = refl
Group.+Associative C2 {BoolFalse} {y} {z} = refl
Group.identRight C2 {BoolTrue} = refl
Group.identRight C2 {BoolFalse} = refl
Group.identLeft C2 {x} = refl
Group.invLeft C2 {BoolTrue} = refl
Group.invLeft C2 {BoolFalse} = refl
Group.invRight C2 {BoolTrue} = refl
Group.invRight C2 {BoolFalse} = refl
parity : (x : A) → ReducedWord → Bool
parity x empty = BoolFalse
parity x (prependLetter (ofLetter y) w _) with decA x y
parity x (prependLetter (ofLetter y) w _) | inl _ = not (parity x w)
parity x (prependLetter (ofLetter y) w _) | inr _ = parity x w
parity x (prependLetter (ofInv y) w _) with decA x y
parity x (prependLetter (ofInv y) w _) | inl _ = not (parity x w)
parity x (prependLetter (ofInv y) w _) | inr _ = parity x w
private
parityPrepend : (a : A) (w : ReducedWord) (l : A) → ((a ≡ l) → False) → parity a (prepend w (ofLetter l)) ≡ parity a w
parityPrepend a empty l notEq with decA a l
parityPrepend a empty l notEq | inl x = exFalso (notEq x)
parityPrepend a empty l notEq | inr x = refl
parityPrepend a (prependLetter (ofLetter r) w x) l notEq with decA a l
parityPrepend a (prependLetter (ofLetter r) w x) l notEq | inl m = exFalso (notEq m)
parityPrepend a (prependLetter (ofLetter r) w x) l notEq | inr _ = refl
parityPrepend a (prependLetter (ofInv r) w x) l notEq with decA a r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r with decA l r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inl l=r = exFalso (notEq (transitivity a=r (equalityCommutative l=r)))
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r with decA a l
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inl a=l = exFalso (notEq a=l)
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l with decA a r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l | inl x₁ = refl
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l | inr bad = exFalso (bad a=r)
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r with decA l r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inl x₁ = refl
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r with decA a l
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inl a=l = exFalso (notEq a=l)
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l with decA a r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l | inl a=r = exFalso (a!=r a=r)
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l | inr x₁ = refl
parityPrepend' : (a : A) (w : ReducedWord) (l : A) → ((a ≡ l) → False) → parity a (prepend w (ofInv l)) ≡ parity a w
parityPrepend' a empty l notEq with decA a l
parityPrepend' a empty l notEq | inl x = exFalso (notEq x)
parityPrepend' a empty l notEq | inr x = refl
parityPrepend' a (prependLetter (ofLetter r) w x) l notEq with decA l r
parityPrepend' a (prependLetter (ofLetter r) w x) l notEq | inl m with decA a r
... | inl a=r = exFalso (notEq (transitivity a=r (equalityCommutative m)))
... | inr a!=r = refl
parityPrepend' a (prependLetter (ofLetter r) w x) l notEq | inr l!=r with decA a l
... | inl a=l = exFalso (notEq a=l)
... | inr a!=l = refl
parityPrepend' a (prependLetter (ofInv r) w x) l notEq with decA a r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r with decA l r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inl l=r = exFalso (notEq (transitivity a=r (equalityCommutative l=r)))
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r with decA a l
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inl a=l = exFalso (notEq a=l)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l with decA a r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l | inl x₁ = refl
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l | inr bad = exFalso (bad a=r)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r with decA l r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inl l=r with decA a l
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inl l=r | inl a=l = exFalso (notEq a=l)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inl l=r | inr a!=l with decA a r
... | inl a=r = exFalso (a!=r a=r)
... | inr _ = refl
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r with decA a l
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inl a=l = exFalso (notEq a=l)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l with decA a r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l | inl a=r = exFalso (a!=r a=r)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l | inr x₁ = refl
parityPrepend'' : (a : A) (w : ReducedWord) → parity a (prepend w (ofLetter a)) ≡ not (parity a w)
parityPrepend'' a empty with decA a a
... | inl _ = refl
... | inr bad = exFalso (bad refl)
parityPrepend'' a (prependLetter (ofLetter l) w x) with decA a a
parityPrepend'' a (prependLetter (ofLetter l) w x) | inl _ with decA a l
parityPrepend'' a (prependLetter (ofLetter l) w x) | inl _ | inl a=l = refl
parityPrepend'' a (prependLetter (ofLetter l) w x) | inl _ | inr a!=l = refl
parityPrepend'' a (prependLetter (ofLetter l) w x) | inr bad = exFalso (bad refl)
parityPrepend'' a (prependLetter (ofInv l) w x) with decA a l
... | inl a=l = equalityCommutative (notNot (parity a w))
parityPrepend'' a (prependLetter (ofInv l) w x) | inr a!=l with decA a a
parityPrepend'' a (prependLetter (ofInv l) w x) | inr a!=l | inl _ with decA a l
... | inl a=l = exFalso (a!=l a=l)
... | inr _ = refl
parityPrepend'' a (prependLetter (ofInv l) w x) | inr a!=l | inr bad = exFalso (bad refl)
parityPrepend''' : (a : A) (w : ReducedWord) → parity a (prepend w (ofInv a)) ≡ not (parity a w)
parityPrepend''' a empty with decA a a
... | inl _ = refl
... | inr bad = exFalso (bad refl)
parityPrepend''' a (prependLetter (ofLetter l) w x) with decA a l
... | inl a=l = equalityCommutative (notNot _)
parityPrepend''' a (prependLetter (ofLetter l) w x) | inr a!=l with decA a a
... | inl _ with decA a l
parityPrepend''' a (prependLetter (ofLetter l) w x) | inr a!=l | inl _ | inl a=l = exFalso (a!=l a=l)
parityPrepend''' a (prependLetter (ofLetter l) w x) | inr a!=l | inl _ | inr _ = refl
parityPrepend''' a (prependLetter (ofLetter l) w x) | inr a!=l | inr bad = exFalso (bad refl)
parityPrepend''' a (prependLetter (ofInv l) w x) with decA a a
parityPrepend''' a (prependLetter (ofInv l) w x) | inl _ with decA a l
... | inl a=l = refl
... | inr a!=l = refl
parityPrepend''' a (prependLetter (ofInv l) w x) | inr bad = exFalso (bad refl)
parityHomIsHom : (a : A) → (x y : ReducedWord) → parity a (_+W_ x y) ≡ xor (parity a x) (parity a y)
parityHomIsHom a empty y = refl
parityHomIsHom a (prependLetter (ofLetter l) x _) y with decA a l
parityHomIsHom a (prependLetter (ofLetter .a) x _) y | inl refl = transitivity (parityPrepend'' a (x +W y)) (transitivity (applyEquality not (parityHomIsHom a x y)) (notXor (parity a x) (parity a y)))
parityHomIsHom a (prependLetter (ofLetter l) x _) y | inr a!=l = transitivity (parityPrepend a (_+W_ x y) l a!=l) (parityHomIsHom a x y)
parityHomIsHom a (prependLetter (ofInv l) x _) y with decA a l
parityHomIsHom a (prependLetter (ofInv .a) x _) y | inl refl = transitivity (parityPrepend''' a (x +W y)) (transitivity (applyEquality not (parityHomIsHom a x y)) (notXor (parity a x) (parity a y)))
parityHomIsHom a (prependLetter (ofInv l) x _) y | inr a!=l = transitivity (parityPrepend' a (x +W y) l a!=l) (parityHomIsHom a x y)
parityHom : (x : A) → GroupHom (freeGroup) C2 (parity x)
GroupHom.groupHom (parityHom x) {y} {z} = parityHomIsHom x y z
GroupHom.wellDefined (parityHom x) refl = refl
| 62.75 | 202 | 0.669753 |
d0a310a8728484d30e011797aee29f0d32742061 | 58 | agda | Agda | test/Fail/Polarity-pragma-out-of-scope.agda | pthariensflame/agda | 222c4c64b2ccf8e0fc2498492731c15e8fef32d4 | [
"BSD-3-Clause"
] | 3 | 2015-03-28T14:51:03.000Z | 2015-12-07T20:14:00.000Z | test/Fail/Polarity-pragma-out-of-scope.agda | Blaisorblade/Agda | 802a28aa8374f15fe9d011ceb80317fdb1ec0949 | [
"BSD-3-Clause"
] | null | null | null | test/Fail/Polarity-pragma-out-of-scope.agda | Blaisorblade/Agda | 802a28aa8374f15fe9d011ceb80317fdb1ec0949 | [
"BSD-3-Clause"
] | null | null | null | postulate
A : Set
module _ where
{-# POLARITY A #-}
| 8.285714 | 20 | 0.586207 |
181fdf6f08ad9667f4103a87d30f1aebf89486ae | 7,952 | agda | Agda | BasicT/Syntax/Gentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 29 | 2016-07-03T18:51:56.000Z | 2022-01-01T10:29:18.000Z | BasicT/Syntax/Gentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 1 | 2018-06-10T09:11:22.000Z | 2018-06-10T09:11:22.000Z | BasicT/Syntax/Gentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | null | null | null | -- TODO
-- Gentzen-style formalisation of syntax.
-- Simple terms.
module BasicT.Syntax.Gentzen where
open import BasicT.Syntax.Common public
-- Derivations.
infix 3 _⊢_
data _⊢_ (Γ : Cx Ty) : Ty → Set where
var : ∀ {A} → A ∈ Γ → Γ ⊢ A
lam : ∀ {A B} → Γ , A ⊢ B → Γ ⊢ A ▻ B
app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B
pair : ∀ {A B} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B
fst : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ A
snd : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ B
unit : Γ ⊢ ⊤
true : Γ ⊢ BOOL
false : Γ ⊢ BOOL
if : ∀ {C} → Γ ⊢ BOOL → Γ ⊢ C → Γ ⊢ C → Γ ⊢ C
zero : Γ ⊢ NAT
suc : Γ ⊢ NAT → Γ ⊢ NAT
it : ∀ {C} → Γ ⊢ NAT → Γ ⊢ C ▻ C → Γ ⊢ C → Γ ⊢ C
rec : ∀ {C} → Γ ⊢ NAT → Γ ⊢ NAT ▻ C ▻ C → Γ ⊢ C → Γ ⊢ C
infix 3 _⊢⋆_
_⊢⋆_ : Cx Ty → Cx Ty → Set
Γ ⊢⋆ ∅ = 𝟙
Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A
-- Monotonicity with respect to context inclusion.
mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (lam t) = lam (mono⊢ (keep η) t)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u)
mono⊢ η (fst t) = fst (mono⊢ η t)
mono⊢ η (snd t) = snd (mono⊢ η t)
mono⊢ η unit = unit
mono⊢ η true = true
mono⊢ η false = false
mono⊢ η (if t u v) = if (mono⊢ η t) (mono⊢ η u) (mono⊢ η v)
mono⊢ η zero = zero
mono⊢ η (suc t) = suc (mono⊢ η t)
mono⊢ η (it t u v) = it (mono⊢ η t) (mono⊢ η u) (mono⊢ η v)
mono⊢ η (rec t u v) = rec (mono⊢ η t) (mono⊢ η u) (mono⊢ η v)
mono⊢⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ
mono⊢⋆ {∅} η ∙ = ∙
mono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
-- Shorthand for variables.
v₀ : ∀ {A Γ} → Γ , A ⊢ A
v₀ = var i₀
v₁ : ∀ {A B Γ} → Γ , A , B ⊢ A
v₁ = var i₁
v₂ : ∀ {A B C Γ} → Γ , A , B , C ⊢ A
v₂ = var i₂
-- Reflexivity.
refl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ
refl⊢⋆ {∅} = ∙
refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀
-- Deduction theorem is built-in.
lam⋆ : ∀ {Ξ Γ A} → Γ ⧺ Ξ ⊢ A → Γ ⊢ Ξ ▻⋯▻ A
lam⋆ {∅} = I
lam⋆ {Ξ , B} = lam⋆ {Ξ} ∘ lam
lam⋆₀ : ∀ {Γ A} → Γ ⊢ A → ∅ ⊢ Γ ▻⋯▻ A
lam⋆₀ {∅} = I
lam⋆₀ {Γ , B} = lam⋆₀ ∘ lam
-- Detachment theorem.
det : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B
det t = app (mono⊢ weak⊆ t) v₀
det⋆ : ∀ {Ξ Γ A} → Γ ⊢ Ξ ▻⋯▻ A → Γ ⧺ Ξ ⊢ A
det⋆ {∅} = I
det⋆ {Ξ , B} = det ∘ det⋆ {Ξ}
det⋆₀ : ∀ {Γ A} → ∅ ⊢ Γ ▻⋯▻ A → Γ ⊢ A
det⋆₀ {∅} = I
det⋆₀ {Γ , B} = det ∘ det⋆₀
-- Cut and multicut.
cut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B
cut t u = app (lam u) t
multicut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A
multicut {∅} ∙ u = mono⊢ bot⊆ u
multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t
-- Transitivity.
trans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″
trans⊢⋆ {∅} ts ∙ = ∙
trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u
-- Contraction.
ccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = lam (lam (app (app v₁ v₀) v₀))
cont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B
cont t = det (app ccont (lam (lam t)))
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = lam (lam (lam (app (app v₂ v₀) v₁)))
exch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C
exch t = det (det (app cexch (lam (lam t))))
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = lam (lam (lam (app v₂ (app v₁ v₀))))
comp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C
comp t u = det (app (app ccomp (lam t)) (lam u))
-- Useful theorems in combinatory form.
ci : ∀ {A Γ} → Γ ⊢ A ▻ A
ci = lam v₀
ck : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A
ck = lam (lam v₁)
cs : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
cs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀))))
cpair : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A ∧ B
cpair = lam (lam (pair v₁ v₀))
cfst : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ A
cfst = lam (fst v₀)
csnd : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ B
csnd = lam (snd v₀)
-- Closure under context concatenation.
concat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
-- Substitution.
[_≔_]_ : ∀ {A B Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢ B → Γ ∖ i ⊢ B
[ i ≔ s ] var j with i ≟∈ j
[ i ≔ s ] var .i | same = s
[ i ≔ s ] var ._ | diff j = var j
[ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t)
[ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] fst t = fst ([ i ≔ s ] t)
[ i ≔ s ] snd t = snd ([ i ≔ s ] t)
[ i ≔ s ] unit = unit
[ i ≔ s ] true = true
[ i ≔ s ] false = false
[ i ≔ s ] if t u v = if ([ i ≔ s ] t) ([ i ≔ s ] u) ([ i ≔ s ] v)
[ i ≔ s ] zero = zero
[ i ≔ s ] suc t = suc ([ i ≔ s ] t)
[ i ≔ s ] it t u v = it ([ i ≔ s ] t) ([ i ≔ s ] u) ([ i ≔ s ] v)
[ i ≔ s ] rec t u v = rec ([ i ≔ s ] t) ([ i ≔ s ] u) ([ i ≔ s ] v)
[_≔_]⋆_ : ∀ {Ξ A Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢⋆ Ξ → Γ ∖ i ⊢⋆ Ξ
[_≔_]⋆_ {∅} i s ∙ = ∙
[_≔_]⋆_ {Ξ , B} i s (ts , t) = [ i ≔ s ]⋆ ts , [ i ≔ s ] t
-- Convertibility.
data _⋙_ {Γ : Cx Ty} : ∀ {A} → Γ ⊢ A → Γ ⊢ A → Set where
refl⋙ : ∀ {A} → {t : Γ ⊢ A}
→ t ⋙ t
trans⋙ : ∀ {A} → {t t′ t″ : Γ ⊢ A}
→ t ⋙ t′ → t′ ⋙ t″
→ t ⋙ t″
sym⋙ : ∀ {A} → {t t′ : Γ ⊢ A}
→ t ⋙ t′
→ t′ ⋙ t
conglam⋙ : ∀ {A B} → {t t′ : Γ , A ⊢ B}
→ t ⋙ t′
→ lam t ⋙ lam t′
congapp⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ▻ B} → {u u′ : Γ ⊢ A}
→ t ⋙ t′ → u ⋙ u′
→ app t u ⋙ app t′ u′
congpair⋙ : ∀ {A B} → {t t′ : Γ ⊢ A} → {u u′ : Γ ⊢ B}
→ t ⋙ t′ → u ⋙ u′
→ pair t u ⋙ pair t′ u′
congfst⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B}
→ t ⋙ t′
→ fst t ⋙ fst t′
congsnd⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B}
→ t ⋙ t′
→ snd t ⋙ snd t′
congsuc⋙ : ∀ {t t′ : Γ ⊢ NAT} → t ⋙ t′
→ suc t ⋙ suc t′
congif⋙ : ∀ {C} → {t t′ : Γ ⊢ BOOL} → {u u′ : Γ ⊢ C} → {v v′ : Γ ⊢ C}
→ t ⋙ t′
→ if t u v ⋙ if t′ u′ v′
congit⋙ : ∀ {C} → {t t′ : Γ ⊢ NAT} → {u u′ : Γ ⊢ C ▻ C} → {v v′ : Γ ⊢ C}
→ t ⋙ t′
→ it t u v ⋙ it t′ u′ v′
congrec⋙ : ∀ {C} → {t t′ : Γ ⊢ NAT} → {u u′ : Γ ⊢ NAT ▻ C ▻ C} → {v v′ : Γ ⊢ C}
→ t ⋙ t′
→ rec t u v ⋙ rec t′ u′ v′
beta▻⋙ : ∀ {A B} → {t : Γ , A ⊢ B} → {u : Γ ⊢ A}
→ app (lam t) u ⋙ ([ top ≔ u ] t)
eta▻⋙ : ∀ {A B} → {t : Γ ⊢ A ▻ B}
→ t ⋙ lam (app (mono⊢ weak⊆ t) v₀)
beta∧₁⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ fst (pair t u) ⋙ t
beta∧₂⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ snd (pair t u) ⋙ u
eta∧⋙ : ∀ {A B} → {t : Γ ⊢ A ∧ B}
→ t ⋙ pair (fst t) (snd t)
eta⊤⋙ : ∀ {t : Γ ⊢ ⊤} → t ⋙ unit
betaBOOL₁⋙ : ∀ {C} → {u v : Γ ⊢ C}
→ if true u v ⋙ u
betaBOOL₂⋙ : ∀ {C} → {u v : Γ ⊢ C}
→ if false u v ⋙ v
betaNATit₁⋙ : ∀ {C} → {u : Γ ⊢ C ▻ C} → {v : Γ ⊢ C}
→ it zero u v ⋙ v
-- TODO: Verify this.
betaNATit₂⋙ : ∀ {C} → {t : Γ ⊢ NAT} → {u : Γ ⊢ C ▻ C} → {v : Γ ⊢ C}
→ it (suc t) u v ⋙ app u (it t u v)
betaNATrec₁⋙ : ∀ {C} → {u : Γ ⊢ NAT ▻ C ▻ C} → {v : Γ ⊢ C}
→ rec zero u v ⋙ v
-- TODO: Verify this.
betaNATrec₂⋙ : ∀ {C} → {t : Γ ⊢ NAT} → {u : Γ ⊢ NAT ▻ C ▻ C} → {v : Γ ⊢ C}
→ rec (suc t) u v ⋙ app (app u t) (rec t u v)
-- TODO: What about eta for BOOL and NAT?
| 27.901754 | 85 | 0.35337 |
c5bd9ccd980af47bc784043723660fc586eb24a8 | 2,017 | agda | Agda | src/Pi/Cp.agda | mietek/formal-logic | 2dd761bfa96ccda089888e8defa6814776fa2922 | [
"X11"
] | 26 | 2015-08-31T09:49:52.000Z | 2021-11-13T12:37:44.000Z | src/Pi/Cp.agda | mietek/formal-logic | 2dd761bfa96ccda089888e8defa6814776fa2922 | [
"X11"
] | null | null | null | src/Pi/Cp.agda | mietek/formal-logic | 2dd761bfa96ccda089888e8defa6814776fa2922 | [
"X11"
] | null | null | null | -- Classical propositional logic, PHOAS approach, initial encoding
module Pi.Cp where
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Set1
Cx = Ty -> Set
isTrue : Ty -> Cx -> Set
isTrue a tc = tc a
-- Terms
module Cp where
infixl 1 _$_
data Tm (tc : Cx) : Ty -> Set where
var : forall {a} -> isTrue a tc -> Tm tc a
lam' : forall {a b} -> (isTrue a tc -> Tm tc b) -> Tm tc (a => b)
_$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b
pair' : forall {a b} -> Tm tc a -> Tm tc b -> Tm tc (a && b)
fst : forall {a b} -> Tm tc (a && b) -> Tm tc a
snd : forall {a b} -> Tm tc (a && b) -> Tm tc b
left : forall {a b} -> Tm tc a -> Tm tc (a || b)
right : forall {a b} -> Tm tc b -> Tm tc (a || b)
case' : forall {a b c} -> Tm tc (a || b) -> (isTrue a tc -> Tm tc c) -> (isTrue b tc -> Tm tc c) -> Tm tc c
abort' : forall {a} -> (isTrue (NOT a) tc -> Tm tc FALSE) -> Tm tc a
lam'' : forall {tc a b} -> (Tm tc a -> Tm tc b) -> Tm tc (a => b)
lam'' f = lam' \x -> f (var x)
case'' : forall {tc a b c} -> Tm tc (a || b) -> (Tm tc a -> Tm tc c) -> (Tm tc b -> Tm tc c) -> Tm tc c
case'' xy f g = case' xy (\x -> f (var x)) (\y -> g (var y))
abort'' : forall {tc a} -> (Tm tc (NOT a) -> Tm tc FALSE) -> Tm tc a
abort'' f = abort' \na -> f (var na)
syntax lam'' (\a -> b) = lam a => b
syntax pair' x y = [ x , y ]
syntax case'' xy (\x -> z1) (\y -> z2) = case xy of x => z1 or y => z2
syntax abort'' (\x -> y) = abort x => y
Thm : Ty -> Set1
Thm a = forall {tc} -> Tm tc a
open Cp public
| 28.408451 | 112 | 0.447695 |
dfaeabcbd30d6e166efeb0ec9e09f9374315b9b2 | 157 | agda | Agda | Cubical/Algebra/Group.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | 1 | 2021-10-31T17:32:49.000Z | 2021-10-31T17:32:49.000Z | Cubical/Algebra/Group.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | Cubical/Algebra/Group.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | {-# OPTIONS --safe #-}
module Cubical.Algebra.Group where
open import Cubical.Algebra.Group.Base public
open import Cubical.Algebra.Group.Properties public
| 26.166667 | 51 | 0.796178 |
cbdc0a4377dd63906550e7b914280550364c5520 | 3,227 | agda | Agda | src/Web/Semantic/DL/TBox/Minimizable.agda | agda/agda-web-semantic | 8ddbe83965a616bff6fc7a237191fa261fa78bab | [
"MIT"
] | 9 | 2015-09-13T17:46:41.000Z | 2020-03-14T14:21:08.000Z | src/Web/Semantic/DL/TBox/Minimizable.agda | bblfish/agda-web-semantic | 38fbc3af7062ba5c3d7d289b2b4bcfb995d99057 | [
"MIT"
] | 4 | 2018-11-14T02:32:28.000Z | 2021-01-04T20:57:19.000Z | src/Web/Semantic/DL/TBox/Minimizable.agda | bblfish/agda-web-semantic | 38fbc3af7062ba5c3d7d289b2b4bcfb995d99057 | [
"MIT"
] | 3 | 2017-12-03T14:52:09.000Z | 2022-03-12T11:40:03.000Z | open import Data.Bool using ( Bool ; true ; false ; _∧_ )
open import Data.Product using ( _×_ )
open import Relation.Binary.PropositionalEquality using ( _≡_ )
open import Relation.Unary using ( _∈_ )
open import Web.Semantic.DL.Concept using
( Concept ; ⟨_⟩ ; ¬⟨_⟩ ; ⊤ ; ⊥ ; _⊓_ ; _⊔_ ; ∀[_]_ ; ∃⟨_⟩_ ; ≤1 ; >1 )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using
( TBox ; ε ; _,_ ;_⊑₁_ ; _⊑₂_ ; Dis ; Ref ; Irr ; Tra )
open import Web.Semantic.Util using ( Subset ; □ ; □-proj₁ ; □-proj₂ )
module Web.Semantic.DL.TBox.Minimizable {Σ : Signature} where
data LHS : Subset (Concept Σ) where
⟨_⟩ : ∀ c → ⟨ c ⟩ ∈ LHS
⊤ : ⊤ ∈ LHS
⊥ : ⊥ ∈ LHS
_⊓_ : ∀ {C D} → (C ∈ LHS) → (D ∈ LHS) → ((C ⊓ D) ∈ LHS)
_⊔_ : ∀ {C D} → (C ∈ LHS) → (D ∈ LHS) → ((C ⊔ D) ∈ LHS)
∃⟨_⟩_ : ∀ R {C} → (C ∈ LHS) → ((∃⟨ R ⟩ C) ∈ LHS)
data RHS : Subset (Concept Σ) where
⟨_⟩ : ∀ c → ⟨ c ⟩ ∈ RHS
⊤ : ⊤ ∈ RHS
_⊓_ : ∀ {C D} → (C ∈ RHS) → (D ∈ RHS) → ((C ⊓ D) ∈ RHS)
∀[_]_ : ∀ R {C} → (C ∈ RHS) → ((∀[ R ] C) ∈ RHS)
≤1 : ∀ R → ((≤1 R) ∈ RHS)
data μTBox : Subset (TBox Σ) where
ε : μTBox ε
_,_ : ∀ {T U} → (T ∈ μTBox) → (U ∈ μTBox) → ((T , U) ∈ μTBox)
_⊑₁_ : ∀ {C D} → (C ∈ LHS) → (D ∈ RHS) → ((C ⊑₁ D) ∈ μTBox)
_⊑₂_ : ∀ Q R → ((Q ⊑₂ R) ∈ μTBox)
Ref : ∀ R → (Ref R ∈ μTBox)
Tra : ∀ R → (Tra R ∈ μTBox)
lhs? : Concept Σ → Bool
lhs? ⟨ c ⟩ = true
lhs? ¬⟨ c ⟩ = false
lhs? ⊤ = true
lhs? ⊥ = true
lhs? (C ⊓ D) = lhs? C ∧ lhs? D
lhs? (C ⊔ D) = lhs? C ∧ lhs? D
lhs? (∀[ R ] C) = false
lhs? (∃⟨ R ⟩ C) = lhs? C
lhs? (≤1 R) = false
lhs? (>1 R) = false
lhs : ∀ C {C✓ : □(lhs? C)} → LHS C
lhs ⟨ c ⟩ = ⟨ c ⟩
lhs ⊤ = ⊤
lhs ⊥ = ⊥
lhs (C ⊓ D) {C⊓D✓} = lhs C {□-proj₁ C⊓D✓} ⊓ lhs D {□-proj₂ {lhs? C} C⊓D✓}
lhs (C ⊔ D) {C⊔D✓} = lhs C {□-proj₁ C⊔D✓} ⊔ lhs D {□-proj₂ {lhs? C} C⊔D✓}
lhs (∃⟨ R ⟩ C) {C✓} = ∃⟨ R ⟩ (lhs C {C✓})
lhs ¬⟨ c ⟩ {}
lhs (∀[ R ] C) {}
lhs (≤1 R) {}
lhs (>1 R) {}
rhs? : Concept Σ → Bool
rhs? ⟨ c ⟩ = true
rhs? ¬⟨ c ⟩ = false
rhs? ⊤ = true
rhs? ⊥ = false
rhs? (C ⊓ D) = rhs? C ∧ rhs? D
rhs? (C ⊔ D) = false
rhs? (∀[ R ] C) = rhs? C
rhs? (∃⟨ R ⟩ C) = false
rhs? (≤1 R) = true
rhs? (>1 R) = false
rhs : ∀ C {C✓ : □(rhs? C)} → RHS C
rhs ⟨ c ⟩ = ⟨ c ⟩
rhs ⊤ = ⊤
rhs (C ⊓ D) {C⊓D✓} = rhs C {□-proj₁ C⊓D✓} ⊓ rhs D {□-proj₂ {rhs? C} C⊓D✓}
rhs (∀[ R ] C) {C✓} = ∀[ R ] (rhs C {C✓})
rhs (≤1 R) = ≤1 R
rhs ⊥ {}
rhs ¬⟨ c ⟩ {}
rhs (C ⊔ D) {}
rhs (∃⟨ R ⟩ C) {}
rhs (>1 R) {}
μTBox? : TBox Σ → Bool
μTBox? ε = true
μTBox? (T , U) = μTBox? T ∧ μTBox? U
μTBox? (C ⊑₁ D) = lhs? C ∧ rhs? D
μTBox? (Q ⊑₂ R) = true
μTBox? (Dis Q R) = false
μTBox? (Ref R) = true
μTBox? (Irr R) = false
μTBox? (Tra R) = true
μtBox : ∀ T {T✓ : □(μTBox? T)} → μTBox T
μtBox ε = ε
μtBox (T , U) {TU✓} = (μtBox T {□-proj₁ TU✓} , μtBox U {□-proj₂ {μTBox? T} TU✓})
μtBox (C ⊑₁ D) {C⊑D✓} = lhs C {□-proj₁ C⊑D✓} ⊑₁ rhs D {□-proj₂ {lhs? C} C⊑D✓}
μtBox (Q ⊑₂ R) = Q ⊑₂ R
μtBox (Ref R) = Ref R
μtBox (Tra R) = Tra R
μtBox (Dis Q R) {}
μtBox (Irr R) {}
| 31.028846 | 82 | 0.43167 |
df2ae24da477b13b75b0844882c0c60749e286ff | 950 | agda | Agda | src/Categories/Category/Instance/SingletonSet.agda | jaykru/agda-categories | a4053cf700bcefdf73b857c3352f1eae29382a60 | [
"MIT"
] | 279 | 2019-06-01T14:36:40.000Z | 2022-03-22T00:40:14.000Z | src/Categories/Category/Instance/SingletonSet.agda | seanpm2001/agda-categories | d9e4f578b126313058d105c61707d8c8ae987fa8 | [
"MIT"
] | 236 | 2019-06-01T14:53:54.000Z | 2022-03-28T14:31:43.000Z | src/Categories/Category/Instance/SingletonSet.agda | seanpm2001/agda-categories | d9e4f578b126313058d105c61707d8c8ae987fa8 | [
"MIT"
] | 64 | 2019-06-02T16:58:15.000Z | 2022-03-14T02:00:59.000Z | {-# OPTIONS --without-K --safe #-}
open import Level
-- This is really a degenerate version of Categories.Category.Instance.One
-- Here SingletonSet is not given an explicit name, it is an alias for ⊤
module Categories.Category.Instance.SingletonSet where
open import Data.Unit.Polymorphic using (⊤; tt)
open import Relation.Binary using (Setoid)
open import Relation.Binary.PropositionalEquality using (refl)
open import Categories.Category.Instance.Sets
open import Categories.Category.Instance.Setoids
import Categories.Object.Terminal as Term
module _ {o : Level} where
open Term (Sets o)
SingletonSet-⊤ : Terminal
SingletonSet-⊤ = record { ⊤ = ⊤ ; ⊤-is-terminal = record { !-unique = λ _ → refl } }
module _ {c ℓ : Level} where
open Term (Setoids c ℓ)
SingletonSetoid : Setoid c ℓ
SingletonSetoid = record { Carrier = ⊤ ; _≈_ = λ _ _ → ⊤ }
SingletonSetoid-⊤ : Terminal
SingletonSetoid-⊤ = record { ⊤ = SingletonSetoid }
| 30.645161 | 86 | 0.726316 |
cb08e4a6cfc551af9917f5f1776381f484ad9424 | 4,797 | agda | Agda | agda/DsubNoTrans.agda | HuStmpHrrr/popl20-artifact | 48214a55ebb484fd06307df4320813d4a002535b | [
"MIT"
] | 1 | 2021-09-23T08:40:28.000Z | 2021-09-23T08:40:28.000Z | agda/DsubNoTrans.agda | HuStmpHrrr/popl20-artifact | 48214a55ebb484fd06307df4320813d4a002535b | [
"MIT"
] | null | null | null | agda/DsubNoTrans.agda | HuStmpHrrr/popl20-artifact | 48214a55ebb484fd06307df4320813d4a002535b | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K --safe #-}
-- This module shows that D<: subtyping without transitivity, or equivalently, without
-- bad bounds, remains undecidable.
module DsubNoTrans where
open import Data.List as List
open import Data.List.All as All
open import Data.Nat as ℕ
open import Data.Maybe as Maybe
open import Data.Product
open import Data.Sum
open import Data.Empty renaming (⊥ to False)
open import Data.Vec as Vec renaming (_∷_ to _‼_ ; [] to nil) hiding (_++_)
open import Function
open import Data.Maybe.Properties as Maybeₚ
open import Data.Nat.Properties as ℕₚ
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality as ≡
open import Induction.Nat
open import DsubDef
open import DsubReduced
open import FsubMinus
open import FsubMinus2
open import Utils
infix 4 _⊢_<:_
data _⊢_<:_ : Env → Typ → Typ → Set where
<:⊤ : ∀ {Γ T} → Γ ⊢ T <: ⊤
⊥<: : ∀ {Γ T} → Γ ⊢ ⊥ <: T
refl : ∀ {Γ T} → Γ ⊢ T <: T
bnd : ∀ {Γ S U S′ U′} →
Γ ⊢ S′ <: S →
Γ ⊢ U <: U′ →
Γ ⊢ ⟨A: S ⋯ U ⟩ <: ⟨A: S′ ⋯ U′ ⟩
Π<: : ∀ {Γ S U S′ U′} →
Γ ⊢ S′ <: S →
Γ ‣ S′ ! ⊢ U <: U′ →
Γ ⊢ Π S ∙ U <: Π S′ ∙ U′
sel₁ : ∀ {Γ n T S} →
env-lookup Γ n ≡ just T →
Γ ⊢ T <: ⟨A: S ⋯ ⊤ ⟩ →
Γ ⊢ S <: n ∙A
sel₂ : ∀ {Γ n T U} →
env-lookup Γ n ≡ just T →
Γ ⊢ T <: ⟨A: ⊥ ⋯ U ⟩ →
Γ ⊢ n ∙A <: U
module Contravariant where
open InvertibleProperties contraInvertible _⊢_<:_ public
D⇒Dᵢ : ∀ {Γ S U} → Γ ⊢ S <: U → ContraEnv Γ → Γ ⊢ᵢ S <: U
D⇒Dᵢ <:⊤ all = ditop
D⇒Dᵢ ⊥<: all = dibot
D⇒Dᵢ refl all = direfl
D⇒Dᵢ (bnd S′<:S U<:U′) all = dibnd (D⇒Dᵢ S′<:S all) (D⇒Dᵢ U<:U′ all)
D⇒Dᵢ (Π<: S′<:S U<:U′) all = diall (D⇒Dᵢ S′<:S all) U<:U′
D⇒Dᵢ (sel₁ T∈Γ S<:U) all with lookupContraEnv T∈Γ all
... | ctt _ with ⟨A:⟩<:⟨A:⟩ (D⇒Dᵢ S<:U all) all
... | S<:⊥ , _ with <:⊥ S<:⊥ all
... | refl = dibot
D⇒Dᵢ (sel₂ T∈Γ S<:U) all with lookupContraEnv T∈Γ all
... | ctt _ with ⟨A:⟩<:⟨A:⟩ (D⇒Dᵢ S<:U all) all
... | _ , U′<:U = ditrans _ (disel T∈Γ) U′<:U
module Undecidability′ where
open FsubMinusToDsubR
open Contravariant hiding (Π<:)
⟨A:⊥⟩<:-lb : ∀ {Γ T S U} → Γ ⊢ ⟨A: ⊥ ⋯ T ⟩ <: ⟨A: S ⋯ U ⟩ → ContraEnv Γ → S ≡ ⊥
⟨A:⊥⟩<:-lb D cΓ with ⟨A:⟩<:⟨A:⟩ (D⇒Dᵢ D cΓ) cΓ
... | S<:⊥ , _ with <:⊥ S<:⊥ cΓ
... | S≡⊥ = S≡⊥
<:⇒<:ᵣ : ∀ {Γ S U} →
Γ ⊢ S <: U →
ContraEnv Γ → Covar S → Covar U →
Γ ⊢ᵣ S <: U
<:⇒<:ᵣ <:⊤ cΓ cS cU = drtop cS
<:⇒<:ᵣ ⊥<: cΓ () cU
<:⇒<:ᵣ refl cΓ cS cU = drrefl cU
<:⇒<:ᵣ (bnd S′<:S U<:U′) cΓ cS ()
<:⇒<:ᵣ (Π<: <:⊤ U<:U′) cΓ () cU
<:⇒<:ᵣ (Π<: ⊥<: U<:U′) cΓ cS ()
<:⇒<:ᵣ (Π<: refl U<:U′) cΓ (cvΠ cS cU) (cvΠ cS′ cU′) = drall cS′ cU cS′ cU′
(drrefl cS′)
(<:⇒<:ᵣ U<:U′ (ctt cS′ ∷ cΓ) cU cU′)
<:⇒<:ᵣ (Π<: (bnd _ S′<:S) U<:U′) cΓ (cvΠ cS cU) (cvΠ cS′ cU′) = drall cS cU cS′ cU′
(<:⇒<:ᵣ S′<:S cΓ cS′ cS)
(<:⇒<:ᵣ U<:U′ (ctt cS′ ∷ cΓ) cU cU′)
<:⇒<:ᵣ (Π<: (Π<: S′<:S S′<:S₁) U<:U′) cΓ () cU
<:⇒<:ᵣ (Π<: (sel₁ x S′<:S) U<:U′) cΓ () cU
<:⇒<:ᵣ (Π<: (sel₂ x S′<:S) U<:U′) cΓ cS ()
<:⇒<:ᵣ (sel₁ T∈Γ T<:B) cΓ cS cU
with lookupContraEnv T∈Γ cΓ
... | ctt _ with ⟨A:⊥⟩<:-lb T<:B cΓ
... | refl = case cS of λ ()
<:⇒<:ᵣ (sel₂ T∈Γ T<:B) cΓ cS cU
with lookupContraEnv T∈Γ cΓ
... | ctt cT = drsel T∈Γ cT (aux T<:B cΓ cT cU)
where aux : ∀ {Γ T S U} → Γ ⊢ ⟨A: ⊥ ⋯ T ⟩ <: ⟨A: S ⋯ U ⟩ → ContraEnv Γ → Covar T → Covar U → Γ ⊢ᵣ T <: U
aux refl cΓ cT cU = drrefl cU
aux (bnd _ T<:U) cΓ cT cU = <:⇒<:ᵣ T<:U cΓ cT cU
<:ᵣ⇒<: : ∀ {Γ S U} → Γ ⊢ᵣ S <: U → Γ ⊢ S <: U
<:ᵣ⇒<: (drtop _) = <:⊤
<:ᵣ⇒<: (drrefl _) = refl
<:ᵣ⇒<: (drall _ _ _ _ S′<:S U<:U′) = Π<: (bnd ⊥<: (<:ᵣ⇒<: S′<:S)) (<:ᵣ⇒<: U<:U′)
<:ᵣ⇒<: (drsel T∈Γ _ T<:B) = sel₂ T∈Γ (bnd ⊥<: (<:ᵣ⇒<: T<:B))
open FsubMinus.FsubMinus
F<:⇒D<: : ∀ {Γ S U} → Γ ⊢F S <: U → ⟪ Γ ⟫ ⊢ ⟦ S ⟧ <: ⟦ U ⟧
F<:⇒D<: = <:ᵣ⇒<: ∘ F<:⇒D<:ᵣ
D<:⇒F<: : ∀ {Γ S U} → ⟪ Γ ⟫ ⊢ ⟦ S ⟧ <: ⟦ U ⟧ → Γ ⊢F S <: U
D<:⇒F<: S<:U = D<:ᵣ⇒F<: (<:⇒<:ᵣ S<:U (⟪⟫-contraEnv _) (⟦⟧-covar _) (⟦⟧-covar _))
refl refl refl
| 39.644628 | 108 | 0.398374 |
10949891d8a9aa9a3b9d9adf462d740a5f811d7f | 1,870 | agda | Agda | examples/outdated-and-incorrect/univ/help.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | examples/outdated-and-incorrect/univ/help.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | examples/outdated-and-incorrect/univ/help.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module help where
open import univ
open import Base
-- Prelims
infixl 150 _#_
K : {A : S} -> S -> Fam A
K B = fam (\_ -> B) (\_ -> refS)
_#_ : {A : S}{F : Fam A} -> El (pi A F) -> (x : El A) -> El (F ! x)
el < f , _ > # x = f x
pFun : {A : S}{F : Fam A}(f : El (pi A F)){x y : El A}(x=y : x == y) ->
f # x == pFam F x=y << f # y
pFun (el < f , pf >) x=y = pf x=y
p# : {A : S}{F : Fam A}{f g : El (pi A F)}{x : El A} -> f == g -> f # x == g # x
p# {A}{F}{el < f , _ >}{el < g , _ >} (eq f=g) = f=g _
eqDom : {A B : S}{F : Fam A}{G : Fam B} ->
pi A F =S pi B G -> B =S A
eqDom (eqS < B=A , _ >) = B=A
eqCod : {A B : S}{F : Fam A}{G : Fam B} ->
(AF=BG : pi A F =S pi B G)(x : El A) ->
F ! x =S G ! (eqDom AF=BG << x)
eqCod (eqS < B=A , F=G >) = F=G
distr<<# : {A B : S}{F : Fam A}{G : Fam B}(f : El (pi A F)){x : El B}
(BG=AF : pi B G =S pi A F) ->
(BG=AF << f) # x == eqCod BG=AF x << f # (eqDom BG=AF << x)
distr<<# (el < f , pf >) {x} (eqS < A=B , G=F >) = ref
eqSnd : {A : S}{F : Fam A}{x : El A}{y z : El (F ! x)} ->
y == z -> _==_ {sigma A F} (el < x , y >) (el < x , z >)
eqSnd {A}{F}{x}{y}{z} y=z = eq < ref , y=cz >
where
y=cz : y == pFam F ref << z
y=cz = trans y=z (sym (castref _ _))
IsFun : {A : S}{F : Fam A}(f : (x : El A) -> El (F ! x)) -> Set
IsFun {A}{F} f = {x y : El A}(p : F ! x =S F ! y)(x=y : x == y) ->
f x == p << f y
mkFun : {A : S}{F : Fam A}(f : (x : El A) -> El (F ! x)) ->
IsFun {A}{F} f -> El (pi A F)
mkFun {A}{F} f pf = el < f , (\{x}{y} x=y -> pf (pFam F x=y) x=y) >
curryFam : {A : S}{F : Fam A} -> Fam (sigma A F) -> (x : El A) -> Fam (F ! x)
curryFam {A}{F} G x = fam H pH
where
H : El (F ! x) -> S
H y = G ! el < x , y >
pH : Map _==_ _=S_ H
pH y=z = pFam G (eq < ref , trans y=z (sym (castref _ _)) >)
| 30.655738 | 80 | 0.392513 |
1838152e6dd79bd5e03b56352025b99f31eb9b63 | 2,033 | agda | Agda | src/API.agda | algebraic-graphs/alga-theory | 0fdb96c0233d9be83eba637f0434d0fd22aefb1d | [
"MIT"
] | 60 | 2017-12-27T14:57:04.000Z | 2022-03-22T23:05:29.000Z | src/API.agda | algebraic-graphs/alga-theory | 0fdb96c0233d9be83eba637f0434d0fd22aefb1d | [
"MIT"
] | 3 | 2018-04-12T16:25:13.000Z | 2018-06-23T13:54:02.000Z | src/API.agda | algebraic-graphs/alga-theory | 0fdb96c0233d9be83eba637f0434d0fd22aefb1d | [
"MIT"
] | 6 | 2017-12-17T20:48:20.000Z | 2019-05-09T23:53:28.000Z | module API where
open import Algebra.Graph
open import Prelude
empty : ∀ {A} -> Graph A
empty = ε
vertex : ∀ {A} -> A -> Graph A
vertex = v
overlay : ∀ {A} -> Graph A -> Graph A -> Graph A
overlay = _+_
connect : ∀ {A} -> Graph A -> Graph A -> Graph A
connect = _*_
edge : ∀ {A} -> A -> A -> Graph A
edge x y = connect (vertex x) (vertex y)
overlays : ∀ {A} -> List (Graph A) -> Graph A
overlays = foldr overlay empty
connects : ∀ {A} -> List (Graph A) -> Graph A
connects = foldr connect empty
vertices : ∀ {A} -> List A -> Graph A
vertices = overlays ∘ map vertex
edges : ∀ {A} -> List (A × A) -> Graph A
edges = overlays ∘ map (uncurry edge)
graph : ∀ {A} -> List A -> List (A × A) -> Graph A
graph vs es = overlay (vertices vs) (edges es)
foldg : ∀ {A} {B : Set} -> B -> (A -> B) -> (B -> B -> B) -> (B -> B -> B) -> Graph A -> B
foldg {A} {B} e w o c = go
where
go : Graph A -> B
go ε = e
go (v x) = w x
go (x + y) = o (go x) (go y)
go (x * y) = c (go x) (go y)
path : ∀ {A} -> List A -> Graph A
path [] = empty
path (x :: []) = vertex x
path (x :: xs) = edges (zip (x :: xs) xs)
circuit : ∀ {A} -> List A -> Graph A
circuit [] = empty
circuit (x :: xs) = path ([ x ] ++ xs ++ [ x ])
clique : ∀ {A} -> List A -> Graph A
clique = connects ∘ map vertex
biclique : ∀ {A} -> List A -> List A -> Graph A
biclique xs ys = connect (vertices xs) (vertices ys)
star : ∀ {A} -> A -> List A -> Graph A
star x ys = connect (vertex x) (vertices ys)
-- Replace all overlays with connects, essentially producing something similar
-- to a transitive closure, but not exactly it.
-- This is a cruel function: I added it to demonstrate that from x ≡ y we cannot
-- in general conclude that f x ≡ f y. Indeed:
-- x ≡ x + x
-- close x ≡ x
-- close (x + x) ≡ x * x
close : ∀ {A} -> Graph A -> Graph A
close ε = ε
close (v x) = v x
close (x + y) = x * y
close (x * y) = x * y
| 27.106667 | 91 | 0.518446 |
239dc5bbf3baa5b63ce97d2fd93605f3d0e67e4e | 373 | agda | Agda | src/FunExt.agda | vituscze/HoTT-lectures | 7730385adfdbdda38ee8b124be3cdeebb7312c65 | [
"BSD-3-Clause"
] | null | null | null | src/FunExt.agda | vituscze/HoTT-lectures | 7730385adfdbdda38ee8b124be3cdeebb7312c65 | [
"BSD-3-Clause"
] | null | null | null | src/FunExt.agda | vituscze/HoTT-lectures | 7730385adfdbdda38ee8b124be3cdeebb7312c65 | [
"BSD-3-Clause"
] | null | null | null | {-# 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
| 24.866667 | 68 | 0.52815 |
4ab95ea4ae4ba111765a0cb55f592176ba0ff27c | 8,155 | agda | Agda | Sets.agda | thibautbenjamin/catt-formalization | 3a02010a869697f4833c9bc6047d66ca27b87cf2 | [
"MIT"
] | 2 | 2020-05-01T08:26:53.000Z | 2020-05-20T00:41:09.000Z | Sets.agda | ThiBen/catt-formalization | ed45935b38d6a86fa662f561866140122ee3dcef | [
"MIT"
] | null | null | null | Sets.agda | ThiBen/catt-formalization | ed45935b38d6a86fa662f561866140122ee3dcef | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K #-}
--
-- Implementation of Sets using lists
--
open import Prelude
module Sets {i} (A : Set i) (eqdecA : eqdec A) where
valid : list A → Set i
valid l = ∀ x → has-all-paths (x ∈-list l)
set = Σ (list A) (λ l → valid l)
valid-nil : valid nil
valid-nil _ ()
Ø : set
Ø = nil , valid-nil
valid-singleton : ∀ (x : A) → valid (nil :: x)
valid-singleton x y (inr p) (inr q) = ap inr (is-prop-has-all-paths (eqdec-is-set eqdecA y x) p q)
singleton : ∀ A → set
singleton x = (nil :: x) , valid-singleton x
add-carrier : list A → A → list A
add-carrier l a with dec-∈-list eqdecA a l
... | inl _ = l
... | inr _ = l :: a
add-valid : ∀ (s : set) a → valid (add-carrier (fst s) a)
add-valid (l , valid-l) a x b b' with dec-∈-list eqdecA a l
... | inl x∈l = valid-l x b b'
... | inr x∉l with eqdecA x a
add-valid (l , valid-l) a .a (inl x∈l) b' | inr x∉l | inl idp = ⊥-elim (x∉l x∈l)
add-valid (l , valid-l) a .a (inr _) (inl x∈l) | inr x∉l | inl idp = ⊥-elim (x∉l x∈l)
add-valid (l , valid-l) a .a (inr p) (inr q) | inr x∉l | inl idp = ap inr (is-prop-has-all-paths (eqdec-is-set eqdecA a a) p q)
add-valid (l , valid-l) a x (inl x∈l) (inl x∈'l) | inr x∉l | inr _ = ap inl (valid-l x x∈l x∈'l)
add-valid (l , valid-l) a x (inl x∈l) (inr x=a) | inr x∉l | inr x≠a = ⊥-elim (x≠a x=a)
add-valid (l , valid-l) a x (inr x=a) b' | inr x∉l | inr x≠a = ⊥-elim (x≠a x=a)
add : ∀ (s : set) → A → set
add s a = add-carrier (fst s) a , add-valid s a
_∈-set_ : A → set → Set i
a ∈-set s = a ∈-list (fst s)
has-all-paths-∈-set : ∀ a s → has-all-paths (a ∈-set s)
has-all-paths-∈-set a s = snd s a
is-prop-∈-set : ∀ a s → is-prop (a ∈-set s)
is-prop-∈-set a s = has-all-paths-is-prop (has-all-paths-∈-set a s)
add+ : set → list A → set
add+ s nil = s
add+ s (l :: a) = add (add+ s l) a
-- -- Very inefficient implementation of the union of sets
-- _∪-set_ : set → set → set
-- s ∪-set s' = add+ s (fst s')
set-of-list : list A → set
set-of-list l = add+ Ø l
-- -- being in the list or in its set are logically equivalent
-- -- but being in the set is a proposition
-- -- achieves the construction of propositional truncation in a reduced way
∈-set-∈-list : ∀ a l → a ∈-set set-of-list l → a ∈-list l
∈-set-∈-list a (l :: b) a∈s with dec-∈-list eqdecA b (fst (add+ Ø l))
... | inl _ = inl (∈-set-∈-list a l a∈s)
... | inr _ with eqdecA a b
... | inl idp = inr idp
∈-set-∈-list a (l :: b) (inl a∈s) | inr _ | inr _ = inl (∈-set-∈-list a l a∈s)
∈-set-∈-list a (l :: b) (inr idp) | inr _ | inr b≠b = inl (⊥-elim (b≠b idp))
∈-list-∈-set : ∀ a l → a ∈-list l → a ∈-set (set-of-list l)
∈-list-∈-set a (l :: b) a∈l+ with eqdecA a b
∈-list-∈-set a (l :: b) (inr a=b) | inr a≠b = ⊥-elim (a≠b a=b)
∈-list-∈-set a (l :: b) (inl a∈l) | inr a≠b with dec-∈-list eqdecA b (fst (add+ Ø l))
... | inl _ = ∈-list-∈-set a l a∈l
... | inr _ = inl (∈-list-∈-set a l a∈l)
∈-list-∈-set a (l :: b) a∈l+ | inl idp with dec-∈-list eqdecA b (fst (add+ Ø l))
... | inl a∈l = a∈l
... | inr _ = inr idp
-- Note that these are not *really* sets : the order matters
-- In particular the identity types are not correct
_∪-set_ : set → set → set
(s , _) ∪-set (s' , _) = set-of-list (s ++ s')
_⊂_ : set → set → Set i
A ⊂ B = ∀ x → x ∈-set A → x ∈-set B
has-all-paths-→ : ∀ {i} (A B : Set i) → has-all-paths B → has-all-paths (A → B)
has-all-paths-→ A B paths-B f g = funext f g (λ x → paths-B (f x) (g x))
has-all-paths-∀ : ∀ {i} (A : Set i) (B : A → Set i) → (∀ a → has-all-paths (B a)) → has-all-paths (∀ a → B a)
has-all-paths-∀ A B paths-B f g = funext-dep f g λ a → paths-B a (f a) (g a)
is-prop-→ : ∀ {i} A B → is-prop {i} B → is-prop (A → B)
is-prop-→ A B prop-B = has-all-paths-is-prop (has-all-paths-→ A B (is-prop-has-all-paths prop-B))
is-prop-∀ : ∀ {i} (A : Set i) (B : A → Set i) → (∀ a → is-prop (B a)) → is-prop (∀ a → B a)
is-prop-∀ A B prop-B = has-all-paths-is-prop (has-all-paths-∀ A B (λ a → is-prop-has-all-paths (prop-B a)))
is-prop-⊂ : ∀ A B → is-prop (A ⊂ B)
is-prop-⊂ A B = is-prop-∀ _ _ λ a → is-prop-→ _ _ (is-prop-∈-set a B)
_≗_ : set → set → Set i
A ≗ B = (A ⊂ B) × (B ⊂ A)
has-all-paths-≗ : ∀ A B → has-all-paths (A ≗ B)
has-all-paths-≗ A B (A⊂B , B⊂A) (A⊂'B , B⊂'A) = ,= (is-prop-has-all-paths (is-prop-⊂ A B) A⊂B A⊂'B) ((is-prop-has-all-paths (is-prop-⊂ B A) B⊂A B⊂'A))
is-prop-≗ : ∀ A B → is-prop (A ≗ B)
is-prop-≗ A B = has-all-paths-is-prop (has-all-paths-≗ A B)
dec-∈ : ∀ A a → dec (a ∈-set A)
dec-∈ (A , _) a with dec-∈-list eqdecA a A
... | inl a∈A = inl a∈A
... | inr a∉A = inr a∉A
∈++₁ : ∀ l l' (a : A) → a ∈-list l → a ∈-list (l ++ l')
∈++₁ l nil a x = x
∈++₁ l (l' :: a₁) a x = inl (∈++₁ l l' a x)
∈++₂ : ∀ l l' (a : A) → a ∈-list l' → a ∈-list (l ++ l')
∈++₂ l (l' :: a₁) a (inl a∈l') = inl (∈++₂ l l' a a∈l')
∈++₂ l (l' :: a₁) a (inr idp) = inr idp
∈++ : ∀ l l' (a : A) → a ∈-list (l ++ l') → (a ∈-list l) + (a ∈-list l')
∈++ l nil a x = inl x
∈++ l (l' :: a₁) a (inl x) with ∈++ l l' a x
... | inl a∈l = inl a∈l
... | inr a∈l' = inr (inl a∈l')
∈++ l (l' :: a₁) a (inr p) = inr (inr p)
∈-∪₁ : ∀ {A B a} → a ∈-set A → (a ∈-set (A ∪-set B))
∈-∪₁ {A , _} {B = nil , _} {a} a∈A = ∈-list-∈-set a (A ++ nil) a∈A
∈-∪₁ {A , _} {(B :: b) , _} {a} a∈A = ∈-list-∈-set a (A ++ (B :: b)) (inl (∈++₁ A B a a∈A))
∈-∪₂ : ∀ {A B a} → a ∈-set B → (a ∈-set (A ∪-set B))
∈-∪₂ {A , _} {B = nil , _} {a} ()
∈-∪₂ {A , _} {(B :: b) , _} {a} (inl a∈B) = ∈-list-∈-set a (A ++ (B :: b)) (inl (∈++₂ A B a a∈B))
∈-∪₂ {A , _} {(B :: b) , _} {a} (inr idp) = ∈-list-∈-set a (A ++ (B :: b)) (inr idp)
∉-∪ : ∀ {A B a} → ¬ (a ∈-set A) → ¬ (a ∈-set B) → ¬ (a ∈-set (A ∪-set B))
∉-∪ {A , _} {B , _} {a} a∉A a∉B a∈A∪B with ∈++ A B a (∈-set-∈-list _ _ a∈A∪B)
... | inl x = a∉A x
... | inr x = a∉B x
∈-∪ : ∀ {A B a} → a ∈-set (A ∪-set B) → (a ∈-set A) + (a ∈-set B)
∈-∪ {A , _} {B , _} {a} a∈A∪B with ∈++ A B a (∈-set-∈-list _ _ a∈A∪B)
... | inl x = inl x
... | inr x = inr x
⊂-∪ : ∀ {A B C D} → A ⊂ B → C ⊂ D → (A ∪-set C) ⊂ (B ∪-set D)
⊂-∪ {A} {B} {C} {D} A⊂B C⊂D a a∈A∪C with dec-∈ A a | dec-∈ C a
... | inl a∈A | _ = ∈-∪₁ {B} {D} {a} (A⊂B _ a∈A)
... | inr a∉A | inl a∈C = ∈-∪₂ {B} {D} {a} (C⊂D _ a∈C)
... | inr a∉A | inr a∉C = ⊥-elim (∉-∪ {A} {C} {a} a∉A a∉C a∈A∪C)
∪-factor : ∀ A B C → (A ∪-set (B ∪-set C)) ≗ ((A ∪-set B) ∪-set (A ∪-set C))
fst (∪-factor A B C) x x∈A∪B∪C with ∈-∪ {A} {B ∪-set C} {x} x∈A∪B∪C
... | inl x∈A = ∈-∪₁ {A ∪-set B} {A ∪-set C} {x} (∈-∪₁ {A} {B} {x} x∈A)
... | inr x∈A∪B with ∈-∪ {B} {C} {x} x∈A∪B
... | inl x∈B = ∈-∪₁ {A ∪-set B} {A ∪-set C} {x} (∈-∪₂ {A} {B} {x} x∈B)
... | inr x∈C = ∈-∪₂ {A ∪-set B} {A ∪-set C} {x} (∈-∪₂ {A} {C} {x} x∈C)
snd (∪-factor A B C) x x∈A∪B∪A∪C with ∈-∪ {A ∪-set B} {A ∪-set C} {x} x∈A∪B∪A∪C
snd (∪-factor A B C) x x∈A∪B∪A∪C | inl x∈A∪B with ∈-∪ {A} {B} {x} x∈A∪B
... | inl x∈A = ∈-∪₁ {A} {B ∪-set C} {x} x∈A
... | inr x∈B = ∈-∪₂ {A} {B ∪-set C} {x} (∈-∪₁ {B} {C} {x} x∈B)
snd (∪-factor A B C) x x∈A∪B∪A∪C | inr x∈A∪C with ∈-∪ {A} {C} {x} x∈A∪C
... | inl x∈A = ∈-∪₁ {A} {B ∪-set C} {x} x∈A
... | inr x∈C = ∈-∪₂ {A} {B ∪-set C} {x} (∈-∪₂ {B} {C} {x} x∈C)
≗-⊂ : ∀ {A B C} → A ≗ B → B ⊂ C → A ⊂ C
≗-⊂ (A⊂B , _) B⊂C _ a∈A = B⊂C _ (A⊂B _ a∈A)
⊂-trans : ∀ {A B C} → A ⊂ B → B ⊂ C → A ⊂ C
⊂-trans A⊂B B⊂C _ a∈A = B⊂C _ (A⊂B _ a∈A)
∈-singleton : ∀ a → a ∈-set (singleton a)
∈-singleton a = inr idp
∈-Ø : ∀ {x} → ¬ (x ∈-set Ø)
∈-Ø ()
A∪B⊂A∪B∪C : ∀ A B C → (A ∪-set B) ⊂ (A ∪-set (B ∪-set C))
A∪B⊂A∪B∪C A B C x x∈A∪B with ∈-∪ {A} {B} x∈A∪B
... | inl x∈A = ∈-∪₁ {A} {B ∪-set C} x∈A
... | inr x∈B = ∈-∪₂ {A} {B ∪-set C} (∈-∪₁ {B} {C} x∈B)
| 40.775 | 152 | 0.435684 |
23abad321b5409d0ca27ecca42adf06419cfe11f | 97 | agda | Agda | Lang/Irrelevance.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | 6 | 2020-04-07T17:58:13.000Z | 2022-02-05T06:53:22.000Z | Lang/Irrelevance.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | Lang/Irrelevance.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | module Lang.Irrelevance where
open import Type
postulate .axiom : ∀{ℓ}{T : Type{ℓ}} -> .T -> T
| 16.166667 | 47 | 0.649485 |
10c436748fc4d1d74dc1054f6176383293140ceb | 1,314 | agda | Agda | test/Succeed/Less-normalisation-in-reflection-machinery.agda | cagix/agda | cc026a6a97a3e517bb94bafa9d49233b067c7559 | [
"BSD-2-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Less-normalisation-in-reflection-machinery.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Less-normalisation-in-reflection-machinery.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
open import Common.Product
{-# TERMINATING #-}
Loop : Set
Loop = Loop
postulate
loop : Loop
data Box (A : Set) : Set where
box : A → Box A
{-# TERMINATING #-}
Boxed-loop : Set
Boxed-loop = Box Boxed-loop
postulate
boxed-loop : Boxed-loop
test₂ : Term
test₂ = quoteTerm Loop
macro
m₄ : Term → Term → TC ⊤
m₄ _ hole = unify hole (def (quote ⊤) [])
test₄ : Set
test₄ = m₄ Loop
macro
m₅ : Term → TC ⊤
m₅ hole = bindTC (inferType (def (quote loop) [])) λ A →
unify hole A
test₅ : Set
test₅ = m₅
macro
m₆ : Term → TC ⊤
m₆ hole =
bindTC (checkType (def (quote Loop) []) (agda-sort (lit 0))) λ A →
unify hole A
test₆ : Set
test₆ = m₆
macro
m₇ : Term → TC ⊤
m₇ hole =
bindTC (quoteTC Loop) λ A →
unify hole A
test₇ : Set
test₇ = m₇
Vec : Set → Nat → Set
Vec A zero = ⊤
Vec A (suc n) = A × Vec A n
macro
m₈ : Term → TC ⊤
m₈ hole =
bindTC (reduce V) λ V →
unify hole V
where
varg = arg (arg-info visible (modality relevant quantity-ω))
V = def (quote Vec) (varg (def (quote Boxed-loop) []) ∷
varg (lit (nat 1)) ∷
[])
test₈ : Set
test₈ = m₈
| 15.642857 | 70 | 0.582192 |
108c056e4f4b59c43500ba453a541ee6935246fb | 48 | agda | Agda | test/interaction/Issue4307.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/interaction/Issue4307.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/interaction/Issue4307.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | postulate
A : Set
f : {{_ : A}} → A
f = {!!}
| 8 | 17 | 0.375 |
cbe170a896a235ddb2a3d25e20a532f46b977457 | 231 | agda | Agda | test/fail/NoTerminationCheck4.agda | asr/agda-kanso | aa10ae6a29dc79964fe9dec2de07b9df28b61ed5 | [
"MIT"
] | 1 | 2018-10-10T17:08:44.000Z | 2018-10-10T17:08:44.000Z | test/fail/NoTerminationCheck4.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | test/fail/NoTerminationCheck4.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | 1 | 2022-03-12T11:35:18.000Z | 2022-03-12T11:35:18.000Z | -- 2012-03-08 Andreas
module NoTerminationCheck4 where
data Bool : Set where
true false : Bool
{-# NO_TERMINATION_CHECK #-}
private
f : Bool -> Bool
f true = f true
f false = f false
-- error: must place pragma before f
| 16.5 | 36 | 0.688312 |
2012cf0e7e45ad983bfa330ff85bdd1cad838fe4 | 2,249 | agda | Agda | agda-stdlib-0.9/src/Category/Applicative/Indexed.agda | qwe2/try-agda | 9d4c43b1609d3f085636376fdca73093481ab882 | [
"Apache-2.0"
] | 1 | 2016-10-20T15:52:05.000Z | 2016-10-20T15:52:05.000Z | agda-stdlib-0.9/src/Category/Applicative/Indexed.agda | qwe2/try-agda | 9d4c43b1609d3f085636376fdca73093481ab882 | [
"Apache-2.0"
] | null | null | null | agda-stdlib-0.9/src/Category/Applicative/Indexed.agda | qwe2/try-agda | 9d4c43b1609d3f085636376fdca73093481ab882 | [
"Apache-2.0"
] | null | null | null | ------------------------------------------------------------------------
-- The Agda standard library
--
-- Indexed applicative functors
------------------------------------------------------------------------
-- Note that currently the applicative functor laws are not included
-- here.
module Category.Applicative.Indexed where
open import Category.Functor
open import Data.Product
open import Function
open import Level
open import Relation.Binary.PropositionalEquality as P using (_≡_)
IFun : ∀ {i} → Set i → (ℓ : Level) → Set _
IFun I ℓ = I → I → Set ℓ → Set ℓ
record RawIApplicative {i f} {I : Set i} (F : IFun I f) :
Set (i ⊔ suc f) where
infixl 4 _⊛_ _<⊛_ _⊛>_
infix 4 _⊗_
field
pure : ∀ {i A} → A → F i i A
_⊛_ : ∀ {i j k A B} → F i j (A → B) → F j k A → F i k B
rawFunctor : ∀ {i j} → RawFunctor (F i j)
rawFunctor = record
{ _<$>_ = λ g x → pure g ⊛ x
}
private
open module RF {i j : I} =
RawFunctor (rawFunctor {i = i} {j = j})
public
_<⊛_ : ∀ {i j k A B} → F i j A → F j k B → F i k A
x <⊛ y = const <$> x ⊛ y
_⊛>_ : ∀ {i j k A B} → F i j A → F j k B → F i k B
x ⊛> y = flip const <$> x ⊛ y
_⊗_ : ∀ {i j k A B} → F i j A → F j k B → F i k (A × B)
x ⊗ y = (_,_) <$> x ⊛ y
zipWith : ∀ {i j k A B C} → (A → B → C) → F i j A → F j k B → F i k C
zipWith f x y = f <$> x ⊛ y
-- Applicative functor morphisms, specialised to propositional
-- equality.
record Morphism {i f} {I : Set i} {F₁ F₂ : IFun I f}
(A₁ : RawIApplicative F₁)
(A₂ : RawIApplicative F₂) : Set (i ⊔ suc f) where
module A₁ = RawIApplicative A₁
module A₂ = RawIApplicative A₂
field
op : ∀ {i j X} → F₁ i j X → F₂ i j X
op-pure : ∀ {i X} (x : X) → op (A₁.pure {i = i} x) ≡ A₂.pure x
op-⊛ : ∀ {i j k X Y} (f : F₁ i j (X → Y)) (x : F₁ j k X) →
op (A₁._⊛_ f x) ≡ A₂._⊛_ (op f) (op x)
op-<$> : ∀ {i j X Y} (f : X → Y) (x : F₁ i j X) →
op (A₁._<$>_ f x) ≡ A₂._<$>_ f (op x)
op-<$> f x = begin
op (A₁._⊛_ (A₁.pure f) x) ≡⟨ op-⊛ _ _ ⟩
A₂._⊛_ (op (A₁.pure f)) (op x) ≡⟨ P.cong₂ A₂._⊛_ (op-pure _) P.refl ⟩
A₂._⊛_ (A₂.pure f) (op x) ∎
where open P.≡-Reasoning
| 30.808219 | 74 | 0.470431 |
df2308b02c0dcc0e57a0c7d0b1d8f00833f0228b | 1,496 | agda | Agda | examples/outdated-and-incorrect/iird/Identity.agda | asr/agda-kanso | aa10ae6a29dc79964fe9dec2de07b9df28b61ed5 | [
"MIT"
] | 1 | 2018-10-10T17:08:44.000Z | 2018-10-10T17:08:44.000Z | examples/outdated-and-incorrect/iird/Identity.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | examples/outdated-and-incorrect/iird/Identity.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | 1 | 2022-03-12T11:35:18.000Z | 2022-03-12T11:35:18.000Z |
module Identity where
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
elim== : {A : Set}(x : A)(C : (y : A) -> x == y -> Set) ->
C x refl -> (y : A) -> (p : x == y) -> C y p
elim== x C Cx .x refl = Cx
elim==₁ : {A : Set}(x : A)(C : (y : A) -> x == y -> Set1) ->
C x refl -> (y : A) -> (p : x == y) -> C y p
elim==₁ x C Cx .x refl = Cx
sym : {A : Set}{x y : A} -> x == y -> y == x
sym {A}{x}{y} eq = elim== x (\z _ -> z == x) refl y eq
cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y
cong {A} f {x}{y} eq = elim== x (\z _ -> f x == f z) refl y eq
subst : {A : Set}{x y : A}(P : A -> Set) -> x == y -> P x -> P y
subst P xy px = elim== _ (\z _ -> P z) px _ xy
subst₁ : {A : Set}{x y : A}(P : A -> Set1) -> x == y -> P x -> P y
subst₁ P xy px = elim==₁ _ (\z _ -> P z) px _ xy
symRef : (A : Set)(x : A) -> sym (refl{A}{x}) == refl
symRef A x = refl
symSym : {A : Set}{x y : A}(p : x == y) -> sym (sym p) == p
symSym {A}{x}{y} p = elim== x (\y q -> sym (sym q) == q) refl y p
-- Proving the symmetric elimination rule is not trivial.
elimS : {A : Set}(x : A)(C : (y : A) -> y == x -> Set) ->
C x refl -> (y : A) -> (p : y == x) -> C y p
elimS x C r y p = subst (C y) (symSym p) h
where
h : C y (sym (sym p))
h = elim== x (\y p -> C y (sym p)) r y (sym p)
data _==¹_ {A : Set1}(x : A) : {B : Set1} -> B -> Set where
refl¹ : x ==¹ x
subst¹ : {A : Set1}{x y : A}(P : A -> Set) -> x ==¹ y -> P x -> P y
subst¹ {A} P refl¹ px = px
| 31.829787 | 67 | 0.426471 |
10973240effaef2d9b3ff3970769274337854b54 | 3,052 | agda | Agda | examples/Termination/Sized/DeBruijnExSubstSized.agda | larrytheliquid/agda | 477c8c37f948e6038b773409358fd8f38395f827 | [
"MIT"
] | null | null | null | examples/Termination/Sized/DeBruijnExSubstSized.agda | larrytheliquid/agda | 477c8c37f948e6038b773409358fd8f38395f827 | [
"MIT"
] | null | null | null | examples/Termination/Sized/DeBruijnExSubstSized.agda | larrytheliquid/agda | 477c8c37f948e6038b773409358fd8f38395f827 | [
"MIT"
] | 1 | 2022-03-12T11:35:18.000Z | 2022-03-12T11:35:18.000Z | {-# OPTIONS --sized-types #-} -- --no-coverage-check #-}
module DeBruijnExSubstSized where
open import Data.Function -- using (_∘_) -- composition, identity
open import Data.Nat
open import Data.Maybe
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Size
open import DeBruijn
-- untyped de Bruijn terms
data LamE (A : Set) : Size -> Set where
varE : {ι : _} -> A -> LamE A (↑ ι)
appE : {ι : _} -> LamE A ι -> LamE A ι -> LamE A (↑ ι)
absE : {ι : _} -> LamE (Maybe A) ι -> LamE A (↑ ι)
flatE : {ι : _} -> LamE (LamE A ι) ι -> LamE A (↑ ι)
-- functoriality of LamE
lamE : {A B : Set} -> (A -> B) -> {ι : _} -> LamE A ι -> LamE B ι
lamE f (varE a) = varE (f a)
lamE f (appE t1 t2) = appE (lamE f t1) (lamE f t2)
lamE f (absE r) = absE (lamE (fmap f) r)
lamE f (flatE r) = flatE (lamE (lamE f) r)
eval : {ι : _} -> {A : Set} -> LamE A ι -> Lam A
eval (varE a) = var a
eval (appE t1 t2) = app (eval t1) (eval t2)
eval (absE r) = abs (eval r)
eval (flatE r) = subst (eval) (eval r)
-- Theorem (naturality of eval): eval ∘ lamE f ≡ lam f ∘ eval
evalNAT : {A B : Set}(f : A -> B) -> {ι : _} -> (t : LamE A ι) ->
eval (lamE f t) ≡ lam f (eval t)
evalNAT f (varE a) = ≡-refl
evalNAT f (appE t1 t2) = begin
eval (lamE f (appE t1 t2))
≡⟨ ≡-refl ⟩
eval (appE (lamE f t1) (lamE f t2))
≡⟨ ≡-refl ⟩
app (eval (lamE f t1)) (eval (lamE f t2))
≡⟨ ≡-cong (\ x -> app x (eval (lamE f t2))) (evalNAT f t1) ⟩
app (lam f (eval t1)) (eval (lamE f t2))
≡⟨ ≡-cong (\ x -> app (lam f (eval t1)) x) (evalNAT f t2) ⟩
app (lam f (eval t1)) (lam f (eval t2))
≡⟨ ≡-refl ⟩
lam f (app (eval t1) (eval t2))
≡⟨ ≡-refl ⟩
lam f (eval (appE t1 t2))
∎
evalNAT f (absE r) = begin
eval (lamE f (absE r))
≡⟨ ≡-refl ⟩
eval (absE (lamE (fmap f) r))
≡⟨ ≡-refl ⟩
abs (eval (lamE (fmap f) r))
≡⟨ ≡-cong abs (evalNAT (fmap f) r) ⟩
abs (lam (fmap f) (eval r))
≡⟨ ≡-refl ⟩
lam f (abs (eval r))
≡⟨ ≡-refl ⟩
lam f (eval (absE r))
∎
-- in the following case, one manual size annotation is needed on the RHS
-- it is for the first application of the I.H.
evalNAT f (flatE {ι} r) = begin
eval (lamE f (flatE r))
≡⟨ ≡-refl ⟩
eval (flatE (lamE (lamE f) r))
≡⟨ ≡-refl ⟩
subst eval (eval (lamE (lamE f) r))
≡⟨ ≡-cong (subst (eval {ι})) (evalNAT (lamE f) r) ⟩
subst eval (lam (lamE f) (eval r))
≡⟨ substLaw1 (lamE f) eval (eval r) ⟩
subst (eval ∘ lamE f) (eval r)
≡⟨ substExt (evalNAT f) (eval r) ⟩
subst (lam f ∘ eval) (eval r)
≡⟨ substLaw2 f eval (eval r) ⟩
lam f (subst eval (eval r))
≡⟨ ≡-refl ⟩
lam f (eval (flatE r))
∎
evalNATcor : {A : Set}{ι : _}(ee : LamE (LamE A ι) ι) ->
subst id (eval (lamE eval ee)) ≡ eval (flatE ee)
evalNATcor ee = begin
subst id (eval (lamE eval ee))
≡⟨ ≡-cong (subst id) (evalNAT eval ee) ⟩
subst id (lam eval (eval ee))
≡⟨ substLaw1 eval id (eval ee) ⟩
subst eval (eval ee)
≡⟨ ≡-refl ⟩
eval (flatE ee)
∎
| 30.828283 | 73 | 0.539646 |
c5683e68c56b1b8e31015934255ac870f48f10db | 213 | agda | Agda | src/Web/URI/Everything.agda | agda/agda-web-uri | 8ced22124dbe12fa820699bb362247a96d592c03 | [
"MIT"
] | 1 | 2019-12-23T04:56:25.000Z | 2019-12-23T04:56:25.000Z | src/Web/URI/Everything.agda | agda/agda-web-uri | 8ced22124dbe12fa820699bb362247a96d592c03 | [
"MIT"
] | null | null | null | src/Web/URI/Everything.agda | agda/agda-web-uri | 8ced22124dbe12fa820699bb362247a96d592c03 | [
"MIT"
] | 1 | 2022-03-12T11:37:59.000Z | 2022-03-12T11:37:59.000Z | module Web.URI.Everything where
import Web.URI
import Web.URI.Examples.HelloWorld
import Web.URI.Primitive
import Web.URI.Port
import Web.URI.Port.Primitive
import Web.URI.Scheme
import Web.URI.Scheme.Primitive
| 19.363636 | 34 | 0.826291 |
dfb4b5a097619506a081a43efa0942a44795b63e | 735 | agda | Agda | out/CommMonoid/Signature.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 39 | 2021-11-09T20:39:55.000Z | 2022-03-19T17:33:12.000Z | out/CommMonoid/Signature.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 1 | 2021-11-21T12:19:32.000Z | 2021-11-21T12:19:32.000Z | out/CommMonoid/Signature.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 4 | 2021-11-09T20:39:59.000Z | 2022-01-24T12:49:17.000Z | {-
This second-order signature was created from the following second-order syntax description:
syntax CommMonoid | CM
type
* : 0-ary
term
unit : * | ε
add : * * -> * | _⊕_ l20
theory
(εU⊕ᴸ) a |> add (unit, a) = a
(εU⊕ᴿ) a |> add (a, unit) = a
(⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c))
(⊕C) a b |> add(a, b) = add(b, a)
-}
module CommMonoid.Signature where
open import SOAS.Context
open import SOAS.Common
open import SOAS.Syntax.Signature *T public
open import SOAS.Syntax.Build *T public
-- Operator symbols
data CMₒ : Set where
unitₒ addₒ : CMₒ
-- Term signature
CM:Sig : Signature CMₒ
CM:Sig = sig λ
{ unitₒ → ⟼₀ *
; addₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ *
}
open Signature CM:Sig public
| 17.5 | 91 | 0.605442 |
cb278711777ab9a701ad37e40b1878d9cc836744 | 1,810 | agda | Agda | test/asset/agda-stdlib-1.0/Codata/Musical/Cofin.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | test/asset/agda-stdlib-1.0/Codata/Musical/Cofin.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | test/asset/agda-stdlib-1.0/Codata/Musical/Cofin.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- The Agda standard library
--
-- "Finite" sets indexed on coinductive "natural" numbers
------------------------------------------------------------------------
{-# OPTIONS --without-K --sized-types --guardedness #-}
module Codata.Musical.Cofin where
open import Codata.Musical.Notation
open import Codata.Musical.Conat as Conat using (Coℕ; suc; ∞ℕ)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Fin using (Fin; zero; suc)
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
open import Function
------------------------------------------------------------------------
-- The type
-- Note that Cofin ∞ℕ is /not/ finite. Note also that this is not a
-- coinductive type, but it is indexed on a coinductive type.
data Cofin : Coℕ → Set where
zero : ∀ {n} → Cofin (suc n)
suc : ∀ {n} (i : Cofin (♭ n)) → Cofin (suc n)
suc-injective : ∀ {m} {p q : Cofin (♭ m)} → (Cofin (suc m) ∋ suc p) ≡ suc q → p ≡ q
suc-injective refl = refl
------------------------------------------------------------------------
-- Some operations
fromℕ : ℕ → Cofin ∞ℕ
fromℕ zero = zero
fromℕ (suc n) = suc (fromℕ n)
toℕ : ∀ {n} → Cofin n → ℕ
toℕ zero = zero
toℕ (suc i) = suc (toℕ i)
fromFin : ∀ {n} → Fin n → Cofin (Conat.fromℕ n)
fromFin zero = zero
fromFin (suc i) = suc (fromFin i)
toFin : ∀ n → Cofin (Conat.fromℕ n) → Fin n
toFin zero ()
toFin (suc n) zero = zero
toFin (suc n) (suc i) = suc (toFin n i)
import Codata.Cofin as C
fromMusical : ∀ {n} → Cofin n → C.Cofin (Conat.fromMusical n)
fromMusical zero = C.zero
fromMusical (suc n) = C.suc (fromMusical n)
toMusical : ∀ {n} → C.Cofin n → Cofin (Conat.toMusical n)
toMusical C.zero = zero
toMusical (C.suc n) = suc (toMusical n)
| 30.166667 | 83 | 0.547514 |
dcb57803e14ef537fa3506cb16d058334f9a353e | 3,756 | agda | Agda | nicolai/pseudotruncations/NONRECURSIVE-INDEX.agda | nicolaikraus/HoTT-Agda | 939a2d83e090fcc924f69f7dfa5b65b3b79fe633 | [
"MIT"
] | 1 | 2021-06-30T00:17:55.000Z | 2021-06-30T00:17:55.000Z | nicolai/pseudotruncations/NONRECURSIVE-INDEX.agda | nicolaikraus/HoTT-Agda | 939a2d83e090fcc924f69f7dfa5b65b3b79fe633 | [
"MIT"
] | null | null | null | nicolai/pseudotruncations/NONRECURSIVE-INDEX.agda | nicolaikraus/HoTT-Agda | 939a2d83e090fcc924f69f7dfa5b65b3b79fe633 | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K #-}
{- INDEX: Some constructions with non-recursive HITs,
and related results.
This formalization covers the hardest results of my
paper titled "Constructions with non-recursive HITs".
To be precise: I have formalized the result that all
functions in the sequence of approximations (see Section 6)
are weakly constant, and that the colimit is thus
propositional. This requires a lot of lemmas. Some of
these lemmas are trivial on paper and only tedious in Agda,
but many lemmas are (at least for me) even on paper far
from trivial.
Formalized are Section 2, Section 3 (without the example
applications), especially the first main result; all of
Section 4 except Lemma 4.9, the definitions and principles
of Section 5, all of Section 6 expect the last corollaries.
The parts of the paper that are not formalized are
(A) the examples in Section 3
(B) the statements of remarks
(C) Lemma 4.9, 5.4, 5.5, and 5.6
(D) Theorem 5.7, Corollary 5.8, Theorem 6.2
(E) the discussions and results in the concluding Section 7
All of these are relatively easy compared with the results
that are formalized. The items in (C) could be implemented
easily, but are not very interesting on their own.
The same is true for the second and third item in (D),
which however depend on Theorem 5.7.
Theorem 5.7 itself could be interesting to formalize.
However, it relies on the main result of
Capriotti, Kraus, Vezzosi,
"Functions out of Higher Truncations".
This result is formalized, but unfortunately in another
library; thus, we omit Theorem 5.7 (for now) in the current
formalization. (E) would require (D) first.
This development type-checks with Agda 2.4.2.5 and similar
versions (I assume with 2.4.2.x in general; same as the
HoTT library).
-}
module nicolai.pseudotruncations.NONRECURSIVE-INDEX where
{- Some preliminary definitions/lemmas, and an explanation
why we need to work with the spheres defined by suspension-
iteration of the form
Σ¹⁺ⁿ :≡ Σⁿ ∘ Σ -}
open import nicolai.pseudotruncations.Preliminary-definitions
open import nicolai.pseudotruncations.Liblemmas
{- SECTION 2
The Sequential colimit. I am aware that there is some
overlap with lib/types/NatColim.agda -}
open import nicolai.pseudotruncations.SeqColim
{- Here is some prepartion for Section 3 -}
open import nicolai.pseudotruncations.wconst-preparation
{- The rather lengthy argument that some heptagon commutes;
very tedious; this is still preparation for Section 3 -}
open import nicolai.pseudotruncations.heptagon
{- SECTION 3 (without the sample applications)
One result of the paper: If we have a sequence of weakly
constant functions, then the colimit is propositional -}
open import nicolai.pseudotruncations.wconstSequence
{- SECTION 4
The correspondance between loops and maps from spheres:
a lot of tedious technical content. This was hard work for me!
The results are in two files; first, essentially the fact that
the 'pointed' 0-sphere [i.e. (bool, true)] is "as good as"
the unit type if we consider pointed maps out of it.
Second, the main lemmas. -}
open import nicolai.pseudotruncations.pointed-O-Sphere
open import nicolai.pseudotruncations.LoopsAndSpheres
{- SECTION 5 (mainly the definition and some auxiliary lemmas)
Definition of pseudo-truncations -}
open import nicolai.pseudotruncations.PseudoTruncs
{- SECTION 6
The sequence of approximations with increasing "connectedness-
level", and the proof that every map is weakly constant,
and the corollary that its colimit is propositional. -}
open import nicolai.pseudotruncations.PseudoTruncs-wconst-seq
| 41.274725 | 65 | 0.750799 |
18a849a3c6fcd14c13e5f8300684d6e2e783a1eb | 437 | agda | Agda | test/Succeed/Issue3971.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue3971.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue3971.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --rewriting --confluence-check -v rewriting:80 #-}
open import Agda.Builtin.Equality
postulate
decorate : ∀{a} (A : Set a) → Set a
rewriteMe : ∀{a b} {A : Set a} {B : A → Set b}
→ decorate ((x : A) → B x) ≡ (decorate A → ∀ x → decorate (B x))
{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE rewriteMe #-}
postulate A : Set
test : decorate (A → A) ≡ (decorate A → ∀ (x : A) → decorate A)
test = refl
| 25.705882 | 80 | 0.549199 |
2025ad04931cf9f85ca11af138615d8c51347e8e | 2,932 | agda | Agda | test/Succeed/Issue4066.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue4066.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue4066.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | open import Agda.Builtin.Equality
open import Agda.Primitive
record R a : Set (lsuc a) where
field
P : {A : Set a} → A → A → Set a
r : ∀ ℓ → R ℓ
R.P (r _) = _≡_
postulate
cong : ∀ {a b} {A : Set a} {B : Set b} {x y : A}
(f : A → B) → R.P (r a) x y → R.P (r b) (f x) (f y)
magic : ∀ {a} {A : Set a} {x y : A} (z : A) → y ≡ z → x ≡ z
record Raw-monad {f : Level → Level}
(M : ∀ {ℓ} → Set ℓ → Set (f ℓ)) ℓ₁ ℓ₂ :
Set (f ℓ₁ ⊔ f ℓ₂ ⊔ lsuc (ℓ₁ ⊔ ℓ₂)) where
infixl 5 _>>=_
field
return : {A : Set ℓ₁} → A → M A
_>>=_ : {A : Set ℓ₁} {B : Set ℓ₂} → M A → (A → M B) → M B
module Raw-monad⁺
{f : Level → Level}
{M : ∀ {ℓ} → Set ℓ → Set (f ℓ)}
(m : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂)
where
private
module M′ {ℓ₁ ℓ₂} = Raw-monad (m {ℓ₁ = ℓ₁} {ℓ₂ = ℓ₂})
open M′ public using (_>>=_)
return : ∀ {a} {A : Set a} → A → M A
return = M′.return {ℓ₂ = lzero}
open Raw-monad⁺ ⦃ … ⦄ public
record Monad⁻ {f : Level → Level}
(M : ∀ {ℓ} → Set ℓ → Set (f ℓ))
⦃ raw-monad : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂ ⦄
ℓ₁ ℓ₂ ℓ₃ :
Set (f ℓ₁ ⊔ f ℓ₂ ⊔ f ℓ₃ ⊔ lsuc (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)) where
field
associativity :
{A : Set ℓ₁} {B : Set ℓ₂} {C : Set ℓ₃} →
(x : M A) (f : A → M B) (g : B → M C) →
x >>= (λ x → f x >>= g) ≡ x >>= f >>= g
module Monad⁻⁺
{f : Level → Level}
{M : ∀ {ℓ} → Set ℓ → Set (f ℓ)}
⦃ raw-monad : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂ ⦄
(m : ∀ {ℓ₁ ℓ₂ ℓ₃} → Monad⁻ M ℓ₁ ℓ₂ ℓ₃)
where
private
module M′ {ℓ₁ ℓ₂ ℓ₃} = Monad⁻ (m {ℓ₁ = ℓ₁} {ℓ₂ = ℓ₂} {ℓ₃ = ℓ₃})
open M′ public
open Monad⁻⁺ ⦃ … ⦄ public
data Maybe {a} (A : Set a) : Set a where
nothing : Maybe A
just : A → Maybe A
postulate
maybe : ∀ {a b} {A : Set a} {B : Maybe A → Set b} →
((x : A) → B (just x)) → B nothing → (x : Maybe A) → B x
record MaybeT {ℓ}
(f : Level → Level)
(M : Set ℓ → Set (f ℓ))
(A : Set ℓ) : Set (f ℓ) where
constructor wrap
field
run : M (Maybe A)
open MaybeT
instance
transformʳ :
∀ {ℓ₁ ℓ₂}
{f : Level → Level}
{M : ∀ {ℓ} → Set ℓ → Set (f ℓ)} →
⦃ raw-monad : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂ ⦄ →
Raw-monad (MaybeT f M) ℓ₁ ℓ₂
run (Raw-monad.return transformʳ x) = return (just x)
run (Raw-monad._>>=_ transformʳ x f) =
run x >>= maybe (λ x → run (f x)) (return nothing)
transformᵐ :
{f : Level → Level}
{M : ∀ {ℓ} → Set ℓ → Set (f ℓ)}
⦃ raw-monad : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂ ⦄
⦃ monad : ∀ {ℓ₁ ℓ₂ ℓ₃} → Monad⁻ M ℓ₁ ℓ₂ ℓ₃ ⦄ →
Monad⁻ (MaybeT f M) lzero lzero lzero
Monad⁻.associativity transformᵐ x f g = cong wrap (
magic ((run x >>= maybe (λ x → run (f x)) (return nothing)) >>=
maybe (λ x → run (g x)) (return nothing))
(associativity _ _ _))
-- WAS: rejected in 2.6.0 with
-- No instance of type Raw-monad _M_345 ℓ₁ ℓ₂ was found in scope.
-- Should succeed.
| 27.148148 | 67 | 0.482606 |
23f0bf5417b640cc0809fe15968f0279e8acb970 | 424 | agda | Agda | test/succeed/Issue252.agda | larrytheliquid/agda | 477c8c37f948e6038b773409358fd8f38395f827 | [
"MIT"
] | 1 | 2018-10-10T17:08:44.000Z | 2018-10-10T17:08:44.000Z | test/succeed/Issue252.agda | masondesu/agda | 70c8a575c46f6a568c7518150a1a64fcd03aa437 | [
"MIT"
] | null | null | null | test/succeed/Issue252.agda | masondesu/agda | 70c8a575c46f6a568c7518150a1a64fcd03aa437 | [
"MIT"
] | 1 | 2022-03-12T11:35:18.000Z | 2022-03-12T11:35:18.000Z | module Issue252 where
data I : Set where
zero : I
data D : I → Set where
c : ∀ i → D i → D i
id : I → I
id i = i
index : ∀ i → D i → I
index i _ = i
foo : ∀ i → D i → D zero
foo .i (c i d) with id i
foo ._ (c i d) | zero = d
bar : ∀ i → D i → D zero
bar .i (c i d) with index i d
bar ._ (c i d) | zero = d
-- In the context of the first goal d has type D i′, in the second it
-- has type D i. Well, not any more.
| 16.96 | 69 | 0.54717 |
c5cb0f5c99b1ce5b3749bc3e62b900af239fe7b8 | 313 | agda | Agda | demo/agda/FRP/JS/Demo/HRef.agda | agda/agda-frp-js | c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72 | [
"MIT",
"BSD-3-Clause"
] | 63 | 2015-04-20T21:47:00.000Z | 2022-02-28T09:46:14.000Z | demo/agda/FRP/JS/Demo/HRef.agda | agda/agda-frp-js | c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72 | [
"MIT",
"BSD-3-Clause"
] | null | null | null | demo/agda/FRP/JS/Demo/HRef.agda | agda/agda-frp-js | c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72 | [
"MIT",
"BSD-3-Clause"
] | 7 | 2016-11-07T21:50:58.000Z | 2022-03-12T11:39:38.000Z | open import FRP.JS.Behaviour using ( Beh ; [_] )
open import FRP.JS.DOM using ( DOM ; element ; attr ; text ; _++_ )
open import FRP.JS.RSet using ( ⟦_⟧ )
module FRP.JS.Demo.HRef where
main : ∀ {w} → ⟦ Beh (DOM w) ⟧
main = element ("a")
( attr "href" ["http://bell-labs.com/"] ++
text ["A hyperlink."] )
| 28.454545 | 67 | 0.594249 |
dc120ff8cd1f8e1bccf9512bc63c8805e6465160 | 838 | agda | Agda | test/succeed/FlexRemoval.agda | asr/agda-kanso | aa10ae6a29dc79964fe9dec2de07b9df28b61ed5 | [
"MIT"
] | 1 | 2018-10-10T17:08:44.000Z | 2018-10-10T17:08:44.000Z | test/succeed/FlexRemoval.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | test/succeed/FlexRemoval.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | {-
In order to solve the metavariables in this example
we need to solve a constraint of the form
_1 := unit₂ (_2 y)
With the flex removal feature the occurs check will
spot the bad variable 'y' in the instantiation and
remove it by instantiating
_2 := λ y → _3
for a fresh metavariable _3. The instantiation of _1
can then proceed.
-}
module FlexRemoval where
record Unit : Set where
data Unit₂ : Set where
unit₂ : Unit → Unit₂
mutual
data D : Set where
c₁ : D
c₂ : (x : Unit₂) → (Unit → D₂ x) → D
D₂ : Unit₂ → Set
D₂ (unit₂ x) = D
foo : D
foo = c₂ _ (λ y → c₁)
{- 2011-04-05 Andreas
This test case and the explanation is no longer up to date.
What happens is
_2 y : Unit
is solved by eta-expansion
_2 = λ y -> record {}
and then
_1 = unit₂ (record {})
is in solved form.
-} | 15.518519 | 61 | 0.650358 |
dc61cbd5d1b0ba1e26c98a37108872d68d7d44e4 | 457 | agda | Agda | test/succeed/Issue148.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | 1 | 2019-11-27T04:41:05.000Z | 2019-11-27T04:41:05.000Z | test/succeed/Issue148.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | test/succeed/Issue148.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | -- {-# OPTIONS -v tc.polarity:15 -v tc.pos:0 #-}
module Issue148 where
data I : Set where
i : I
F : I → Set → Set
F i A = A
data T (p : I) : Set where
t₁ : T p → T p
t₂ : F p (T p) → T p
fold : ((x : T i) → T i) → T i → T i
fold f (t₁ x) = f (fold f x)
fold f (t₂ x) = f (fold f x)
data E : T i → Set where
e : ∀ x → E x
postulate
t₂′ : ∀ {p} → F p (T p) → T p
foo : (x : T i) → E (fold t₂ x)
foo x with x
foo x | x′ = e (fold t₂ x′)
| 16.925926 | 48 | 0.477024 |
df376a43837e7816383b824b38d66a05af0e9871 | 3,392 | agda | Agda | Cubical/Foundations/Pointed/Homogeneous.agda | cangiuli/cubical | d103ec455d41cccf9b13a4803e7d3cf462e00067 | [
"MIT"
] | null | null | null | Cubical/Foundations/Pointed/Homogeneous.agda | cangiuli/cubical | d103ec455d41cccf9b13a4803e7d3cf462e00067 | [
"MIT"
] | 1 | 2022-01-27T02:07:48.000Z | 2022-01-27T02:07:48.000Z | Cubical/Foundations/Pointed/Homogeneous.agda | cangiuli/cubical | d103ec455d41cccf9b13a4803e7d3cf462e00067 | [
"MIT"
] | null | null | null | {-
Definition of a homogeneous pointed type, and proofs that pi, product, path, and discrete types are homogeneous
Portions of this file adapted from Nicolai Kraus' code here:
https://bitbucket.org/nicolaikraus/agda/src/e30d70c72c6af8e62b72eefabcc57623dd921f04/trunc-inverse.lagda
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Pointed.Homogeneous where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Path
open import Cubical.Data.Sigma
open import Cubical.Data.Empty as ⊥
open import Cubical.Relation.Nullary
open import Cubical.Foundations.Pointed.Base
open import Cubical.Foundations.Pointed.Properties
open import Cubical.Structures.Pointed
isHomogeneous : ∀ {ℓ} → Pointed ℓ → Type (ℓ-suc ℓ)
isHomogeneous {ℓ} (A , x) = ∀ y → Path (Pointed ℓ) (A , x) (A , y)
isHomogeneousPi : ∀ {ℓ ℓ'} {A : Type ℓ} {B∙ : A → Pointed ℓ'}
→ (∀ a → isHomogeneous (B∙ a)) → isHomogeneous (Πᵘ∙ A B∙)
isHomogeneousPi h f i = (∀ a → typ (h a (f a) i)) , (λ a → pt (h a (f a) i))
isHomogeneousProd : ∀ {ℓ ℓ'} {A∙ : Pointed ℓ} {B∙ : Pointed ℓ'}
→ isHomogeneous A∙ → isHomogeneous B∙ → isHomogeneous (A∙ ×∙ B∙)
isHomogeneousProd hA hB (a , b) i = (typ (hA a i)) × (typ (hB b i)) , (pt (hA a i) , pt (hB b i))
isHomogeneousPath : ∀ {ℓ} (A : Type ℓ) {x y : A} (p : x ≡ y) → isHomogeneous ((x ≡ y) , p)
isHomogeneousPath A {x} {y} p q
= pointed-sip ((x ≡ y) , p) ((x ≡ y) , q) (eqv , compPathr-cancel p q)
where eqv : (x ≡ y) ≃ (x ≡ y)
eqv = compPathlEquiv (q ∙ sym p)
module HomogeneousDiscrete {ℓ} {A∙ : Pointed ℓ} (dA : Discrete (typ A∙)) (y : typ A∙) where
-- switches pt A∙ with y
switch : typ A∙ → typ A∙
switch x with dA x (pt A∙)
... | yes _ = y
... | no _ with dA x y
... | yes _ = pt A∙
... | no _ = x
switch-ptA∙ : switch (pt A∙) ≡ y
switch-ptA∙ with dA (pt A∙) (pt A∙)
... | yes _ = refl
... | no ¬p = ⊥.rec (¬p refl)
switch-idp : ∀ x → switch (switch x) ≡ x
switch-idp x with dA x (pt A∙)
switch-idp x | yes p with dA y (pt A∙)
switch-idp x | yes p | yes q = q ∙ sym p
switch-idp x | yes p | no _ with dA y y
switch-idp x | yes p | no _ | yes _ = sym p
switch-idp x | yes p | no _ | no ¬p = ⊥.rec (¬p refl)
switch-idp x | no ¬p with dA x y
switch-idp x | no ¬p | yes p with dA y (pt A∙)
switch-idp x | no ¬p | yes p | yes q = ⊥.rec (¬p (p ∙ q))
switch-idp x | no ¬p | yes p | no _ with dA (pt A∙) (pt A∙)
switch-idp x | no ¬p | yes p | no _ | yes _ = sym p
switch-idp x | no ¬p | yes p | no _ | no ¬q = ⊥.rec (¬q refl)
switch-idp x | no ¬p | no ¬q with dA x (pt A∙)
switch-idp x | no ¬p | no ¬q | yes p = ⊥.rec (¬p p)
switch-idp x | no ¬p | no ¬q | no _ with dA x y
switch-idp x | no ¬p | no ¬q | no _ | yes q = ⊥.rec (¬q q)
switch-idp x | no ¬p | no ¬q | no _ | no _ = refl
switch-eqv : typ A∙ ≃ typ A∙
switch-eqv = isoToEquiv (iso switch switch switch-idp switch-idp)
isHomogeneousDiscrete : ∀ {ℓ} {A∙ : Pointed ℓ} (dA : Discrete (typ A∙)) → isHomogeneous A∙
isHomogeneousDiscrete {ℓ} {A∙} dA y
= pointed-sip (typ A∙ , pt A∙) (typ A∙ , y) (switch-eqv , switch-ptA∙)
where open HomogeneousDiscrete {ℓ} {A∙} dA y
| 40.380952 | 111 | 0.59316 |
cbda07a7a1a1adbea809d63e2973cedcd930af0a | 2,060 | agda | Agda | src/Everything.agda | mietek/coquand-kovacs | bd626509948fbf8503ec2e31c1852e1ac6edcc79 | [
"X11"
] | null | null | null | src/Everything.agda | mietek/coquand-kovacs | bd626509948fbf8503ec2e31c1852e1ac6edcc79 | [
"X11"
] | null | null | null | src/Everything.agda | mietek/coquand-kovacs | bd626509948fbf8503ec2e31c1852e1ac6edcc79 | [
"X11"
] | null | null | null | module Everything where
import Prelude
import Category
--------------------------------------------------------------------------------
-- The syntax of STLC.
import STLC.Syntax
-- A simplification of Coquand 2002,
-- with de Bruijn indices and implicit substitutions.
import STLC.Coquand.Renaming
import STLC.Coquand.Substitution
import STLC.Coquand.Normalisation -- TODO: Fill postulates
import STLC.Coquand.Convertibility -- TODO: Simplify β-reduction rule
import STLC.Coquand.Completeness -- TODO: Fill postulates
import STLC.Coquand.Soundness -- TODO: Fill postulates
-- A restyling of Kovacs 2017.
import STLC.Kovacs.Embedding
import STLC.Kovacs.Substitution
import STLC.Kovacs.NormalForm
import STLC.Kovacs.Normalisation
import STLC.Kovacs.Convertibility
import STLC.Kovacs.Completeness
import STLC.Kovacs.PresheafRefinement
import STLC.Kovacs.Soundness
--------------------------------------------------------------------------------
-- The syntax of STLC, with simple products.
import STLC1.Syntax
-- An extension of Kovacs 2017.
import STLC1.Kovacs.Embedding
import STLC1.Kovacs.Substitution
import STLC1.Kovacs.NormalForm
import STLC1.Kovacs.Normalisation
import STLC1.Kovacs.Convertibility
import STLC1.Kovacs.Completeness
import STLC1.Kovacs.PresheafRefinement
import STLC1.Kovacs.Soundness
--------------------------------------------------------------------------------
-- The syntax of STLC, with simple products and coproducts.
import STLC2.Syntax
-- An extension of Kovacs 2017.
import STLC2.Kovacs.Embedding
import STLC2.Kovacs.Substitution
import STLC2.Kovacs.NormalForm
import STLC2.Kovacs.Normalisation.SoundNotComplete
import STLC2.Kovacs.Normalisation.Experimental
import STLC2.Kovacs.Normalisation
import STLC2.Kovacs.Convertibility
import STLC2.Kovacs.Completeness -- TODO: Finish this
-- import STLC2.Kovacs.PresheafRefinement -- TODO: Start this
-- import STLC2.Kovacs.Soundness -- TODO: Start this
--------------------------------------------------------------------------------
| 29.428571 | 80 | 0.679612 |
dc969d4b08d4725b110994833c8e3b282ae214df | 925 | agda | Agda | src/Categories/Category/Instance/LawvereTheories.agda | turion/agda-categories | ad0f94b6cf18d8a448b844b021aeda58e833d152 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | src/Categories/Category/Instance/LawvereTheories.agda | turion/agda-categories | ad0f94b6cf18d8a448b844b021aeda58e833d152 | [
"MIT"
] | null | null | null | src/Categories/Category/Instance/LawvereTheories.agda | turion/agda-categories | ad0f94b6cf18d8a448b844b021aeda58e833d152 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | {-# OPTIONS --without-K --safe #-}
module Categories.Category.Instance.LawvereTheories where
-- Category of Lawvere Theories
open import Level
open import Categories.Category
open import Categories.Functor.Cartesian.Properties
open import Categories.NaturalTransformation.NaturalIsomorphism
open import Categories.Theory.Lawvere
LawvereTheories : (o ℓ e : Level) → Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e)
LawvereTheories o ℓ e = record
{ Obj = FiniteProduct o ℓ e
; _⇒_ = LT-Hom
; _≈_ = λ H₁ H₂ → cartF.F H₁ ≃ cartF.F H₂
; id = LT-id
; _∘_ = LT-∘
; assoc = λ { {f = f} {g} {h} → associator (cartF.F f) (cartF.F g) (cartF.F h) }
; sym-assoc = λ { {f = f} {g} {h} → sym-associator (cartF.F f) (cartF.F g) (cartF.F h) }
; identityˡ = unitorˡ
; identityʳ = unitorʳ
; identity² = unitor²
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = _ⓘₕ_
}
where open LT-Hom
| 31.896552 | 90 | 0.643243 |
d09d3232bc18b670ae836d934afdd717a2a86644 | 765 | agda | Agda | test/Succeed/Issue1411-2.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue1411-2.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue1411-2.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- Andreas, 2014-01-24, Issue 1411
-- First split might not succeed in the unifier,
-- so try later splits also.
-- {-# OPTIONS -v tc.lhs:10 #-}
open import Common.Prelude
open import Common.Equality
data Fin : Nat → Set where
fzero : (n : Nat) → Fin (suc n)
fsuc : (n : Nat) → (i : Fin n) → Fin (suc n)
data _≅_ {A : Set} (a : A) : {B : Set} (b : B) → Set where
refl : a ≅ a
works : ∀ n m (i : Fin n) (j : Fin m) → n ≡ m → fsuc n i ≅ fsuc m j → i ≅ j
works n .n i .i refl refl = refl
fails : ∀ n m (i : Fin n) (j : Fin m) → fsuc n i ≅ fsuc m j → n ≡ m → i ≅ j
fails n .n i .i refl refl = refl
-- Refuse to solve heterogeneous constraint i : Fin n =?= j : Fin m
-- when checking that the pattern refl has type fsuc n i ≅ fsuc m j
-- Should work now.
| 28.333333 | 75 | 0.581699 |
c5f5a8314747cd2b18659d97b1c596daa117d90d | 6,397 | agda | Agda | OlderBasicILP/Direct/Gentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 29 | 2016-07-03T18:51:56.000Z | 2022-01-01T10:29:18.000Z | OlderBasicILP/Direct/Gentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 1 | 2018-06-10T09:11:22.000Z | 2018-06-10T09:11:22.000Z | OlderBasicILP/Direct/Gentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | null | null | null | module OlderBasicILP.Direct.Gentzen where
open import Common.Context public
-- Propositions of intuitionistic logic of proofs, without ∨, ⊥, or +.
mutual
infixr 10 _⦂_
infixl 9 _∧_
infixr 7 _▻_
data Ty : Set where
α_ : Atom → Ty
_▻_ : Ty → Ty → Ty
_⦂_ : Box → Ty → Ty
_∧_ : Ty → Ty → Ty
⊤ : Ty
record Box : Set where
inductive
constructor [_]
field
{/A} : Ty
t : ∅ ⊢ /A
_⦂⋆_ : ∀ {n} → VCx Box n → VCx Ty n → Cx Ty
∅ ⦂⋆ ∅ = ∅
(ts , t) ⦂⋆ (Ξ , A) = (ts ⦂⋆ Ξ) , (t ⦂ A)
-- Derivations, as Gentzen-style natural deduction trees.
infix 3 _⊢_
data _⊢_ (Γ : Cx Ty) : Ty → Set where
var : ∀ {A} → A ∈ Γ → Γ ⊢ A
lam : ∀ {A B} → Γ , A ⊢ B → Γ ⊢ A ▻ B
app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B
-- multibox : ∀ {n A} {[ss] : VCx Box n} {Ξ : VCx Ty n}
-- → Γ ⊢⋆ [ss] ⦂⋆ Ξ → (u : [ss] ⦂⋆ Ξ ⊢ A)
-- → Γ ⊢ [ u ] ⦂ A
down : ∀ {A} {t : ∅ ⊢ A} → Γ ⊢ [ t ] ⦂ A → Γ ⊢ A
pair : ∀ {A B} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B
fst : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ A
snd : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ B
unit : Γ ⊢ ⊤
infix 3 _⊢⋆_
_⊢⋆_ : Cx Ty → Cx Ty → Set
Γ ⊢⋆ ∅ = 𝟙
Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A
infix 7 _▻◅_
_▻◅_ : Ty → Ty → Ty
A ▻◅ B = (A ▻ B) ∧ (B ▻ A)
-- Monotonicity with respect to context inclusion.
mutual
mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (lam t) = lam (mono⊢ (keep η) t)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
-- mono⊢ η (multibox ts u) = multibox (mono⊢⋆ η ts) u
mono⊢ η (down t) = down (mono⊢ η t)
mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u)
mono⊢ η (fst t) = fst (mono⊢ η t)
mono⊢ η (snd t) = snd (mono⊢ η t)
mono⊢ η unit = unit
mono⊢⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ
mono⊢⋆ {∅} η ∙ = ∙
mono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
-- Shorthand for variables.
v₀ : ∀ {A Γ} → Γ , A ⊢ A
v₀ = var i₀
v₁ : ∀ {A B Γ} → (Γ , A) , B ⊢ A
v₁ = var i₁
v₂ : ∀ {A B C Γ} → ((Γ , A) , B) , C ⊢ A
v₂ = var i₂
-- Reflexivity.
refl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ
refl⊢⋆ {∅} = ∙
refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀
-- Deduction theorem is built-in.
-- Detachment theorem.
det : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B
det t = app (mono⊢ weak⊆ t) v₀
-- Cut and multicut.
cut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B
cut t u = app (lam u) t
multicut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A
multicut {∅} ∙ u = mono⊢ bot⊆ u
multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t
-- Transitivity.
trans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″
trans⊢⋆ {∅} ts ∙ = ∙
trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u
-- Contraction.
ccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = lam (lam (app (app v₁ v₀) v₀))
cont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B
cont t = det (app ccont (lam (lam t)))
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = lam (lam (lam (app (app v₂ v₀) v₁)))
exch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C
exch t = det (det (app cexch (lam (lam t))))
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = lam (lam (lam (app v₂ (app v₁ v₀))))
comp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C
comp t u = det (app (app ccomp (lam t)) (lam u))
-- Useful theorems in functional form.
-- dist : ∀ {A B Ψ Γ} {t : Ψ ⊢ A ▻ B} {u : Ψ ⊢ A}
-- → Γ ⊢ [ t ] ⦂ (A ▻ B) → Γ ⊢ [ u ] ⦂ A
-- → Γ ⊢ [ app (down v₁) (down v₀) ] ⦂ B
-- dist t u = multibox ((∙ , t) , u) (app (down v₁) (down v₀))
--
-- up : ∀ {A Ψ Γ} {t : Ψ ⊢ A}
-- → Γ ⊢ [ t ] ⦂ A
-- → Γ ⊢ [ v₀ ] ⦂ [ t ] ⦂ A
-- up t = multibox (∙ , t) v₀
--
-- distup : ∀ {A B Ψ Γ} {u : Ψ ⊢ A} {t : ∅ , [ u ] ⦂ A ⊢ [ u ] ⦂ A ▻ B}
-- → Γ ⊢ [ t ] ⦂ ([ u ] ⦂ A ▻ B) → Γ ⊢ [ u ] ⦂ A
-- → Γ ⊢ [ app (down v₁) (down v₀) ] ⦂ B
-- distup t u = dist t (up u)
--
-- box : ∀ {A Γ}
-- → (t : ∅ ⊢ A)
-- → Γ ⊢ [ t ] ⦂ A
-- box t = multibox ∙ t
unbox : ∀ {A C Γ} {t : ∅ ⊢ A} {u : ∅ ⊢ C}
→ Γ ⊢ [ t ] ⦂ A → Γ , [ t ] ⦂ A ⊢ [ u ] ⦂ C
→ Γ ⊢ [ u ] ⦂ C
unbox t u = app (lam u) t
-- Useful theorems in combinatory form.
ci : ∀ {A Γ} → Γ ⊢ A ▻ A
ci = lam v₀
ck : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A
ck = lam (lam v₁)
cs : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
cs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀))))
-- cdist : ∀ {A B Ψ Γ} {t : Ψ ⊢ A ▻ B} {u : Ψ ⊢ A}
-- → Γ ⊢ [ t ] ⦂ (A ▻ B) ▻ [ u ] ⦂ A ▻ [ app (down v₁) (down v₀) ] ⦂ B
-- cdist = lam (lam (dist v₁ v₀))
--
-- cup : ∀ {A Ψ Γ} {t : Ψ ⊢ A} → Γ ⊢ [ t ] ⦂ A ▻ [ v₀ ] ⦂ [ t ] ⦂ A
-- cup = lam (up v₀)
cdown : ∀ {A Γ} {t : ∅ ⊢ A} → Γ ⊢ [ t ] ⦂ A ▻ A
cdown = lam (down v₀)
-- cdistup : ∀ {A B Ψ Γ} {u : Ψ ⊢ A} {t : ∅ , [ u ] ⦂ A ⊢ [ u ] ⦂ A ▻ B}
-- → Γ ⊢ [ t ] ⦂ ([ u ] ⦂ A ▻ B) ▻ [ u ] ⦂ A ▻ [ app (down v₁) (down v₀) ] ⦂ B
-- cdistup = lam (lam (dist v₁ (up v₀)))
cunbox : ∀ {A C Γ} {t : ∅ ⊢ A} {u : ∅ ⊢ C}
→ Γ ⊢ [ t ] ⦂ A ▻ ([ t ] ⦂ A ▻ C) ▻ C
cunbox = lam (lam (app v₀ v₁))
cpair : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A ∧ B
cpair = lam (lam (pair v₁ v₀))
cfst : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ A
cfst = lam (fst v₀)
csnd : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ B
csnd = lam (snd v₀)
-- Closure under context concatenation.
concat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
-- Substitution.
mutual
[_≔_]_ : ∀ {A B Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢ B → Γ ∖ i ⊢ B
[ i ≔ s ] var j with i ≟∈ j
[ i ≔ s ] var .i | same = s
[ i ≔ s ] var ._ | diff j = var j
[ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t)
[ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u)
-- [ i ≔ s ] multibox ts u = multibox ([ i ≔ s ]⋆ ts) u
[ i ≔ s ] down t = down ([ i ≔ s ] t)
[ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] fst t = fst ([ i ≔ s ] t)
[ i ≔ s ] snd t = snd ([ i ≔ s ] t)
[ i ≔ s ] unit = unit
[_≔_]⋆_ : ∀ {Ξ A Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢⋆ Ξ → Γ ∖ i ⊢⋆ Ξ
[_≔_]⋆_ {∅} i s ∙ = ∙
[_≔_]⋆_ {Ξ , B} i s (ts , t) = [ i ≔ s ]⋆ ts , [ i ≔ s ] t
| 26.76569 | 88 | 0.3869 |
df284c46f027130af9e5b8c985fd444d8fdbdfbc | 2,435 | agda | Agda | src/Examples/Sorting/Parallel/MergeSort/Split.agda | jonsterling/agda-calf | e51606f9ca18d8b4cf9a63c2d6caa2efc5516146 | [
"Apache-2.0"
] | 29 | 2021-07-14T03:18:28.000Z | 2022-03-22T20:35:11.000Z | src/Examples/Sorting/Parallel/MergeSort/Split.agda | jonsterling/agda-calf | e51606f9ca18d8b4cf9a63c2d6caa2efc5516146 | [
"Apache-2.0"
] | null | null | null | src/Examples/Sorting/Parallel/MergeSort/Split.agda | jonsterling/agda-calf | e51606f9ca18d8b4cf9a63c2d6caa2efc5516146 | [
"Apache-2.0"
] | 2 | 2021-10-06T10:28:24.000Z | 2022-01-29T08:12:01.000Z | {-# OPTIONS --prop --rewriting #-}
open import Examples.Sorting.Parallel.Comparable
module Examples.Sorting.Parallel.MergeSort.Split (M : Comparable) where
open Comparable M
open import Examples.Sorting.Parallel.Core M
open import Calf costMonoid
open import Calf.ParMetalanguage parCostMonoid
open import Calf.Types.Nat
open import Calf.Types.List
open import Calf.Types.Bounded costMonoid
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl)
open import Data.Product using (_×_; _,_; ∃; proj₁; proj₂)
open import Data.Nat as Nat using (ℕ; zero; suc; _+_; _*_; ⌊_/2⌋; ⌈_/2⌉)
open import Data.Nat.Properties as N using (module ≤-Reasoning)
pair = Σ++ (list A) λ _ → (list A)
split/clocked : cmp (Π nat λ _ → Π (list A) λ _ → F pair)
split/clocked zero l = ret ([] , l)
split/clocked (suc k) [] = ret ([] , [])
split/clocked (suc k) (x ∷ xs) = bind (F pair) (split/clocked k xs) λ (l₁ , l₂) → ret (x ∷ l₁ , l₂)
split/clocked/correct : ∀ k k' l → k + k' ≡ length l →
◯ (∃ λ l₁ → ∃ λ l₂ → split/clocked k l ≡ ret (l₁ , l₂) × length l₁ ≡ k × length l₂ ≡ k' × l ↭ (l₁ ++ l₂))
split/clocked/correct zero k' l refl u = [] , l , refl , refl , refl , refl
split/clocked/correct (suc k) k' (x ∷ xs) h u =
let (l₁ , l₂ , ≡ , h₁ , h₂ , ↭) = split/clocked/correct k k' xs (N.suc-injective h) u in
x ∷ l₁ , l₂ , Eq.cong (λ e → bind (F pair) e _) ≡ , Eq.cong suc h₁ , h₂ , prep x ↭
split/clocked/cost : cmp (Π nat λ _ → Π (list A) λ _ → cost)
split/clocked/cost _ _ = 𝟘
split/clocked≤split/clocked/cost : ∀ k l → IsBounded pair (split/clocked k l) (split/clocked/cost k l)
split/clocked≤split/clocked/cost zero l = bound/ret
split/clocked≤split/clocked/cost (suc k) [] = bound/ret
split/clocked≤split/clocked/cost (suc k) (x ∷ xs) = bound/bind/const 𝟘 𝟘 (split/clocked≤split/clocked/cost k xs) λ _ → bound/ret
split : cmp (Π (list A) λ _ → F pair)
split l = split/clocked ⌊ length l /2⌋ l
split/correct : ∀ l →
◯ (∃ λ l₁ → ∃ λ l₂ → split l ≡ ret (l₁ , l₂) × length l₁ ≡ ⌊ length l /2⌋ × length l₂ ≡ ⌈ length l /2⌉ × l ↭ (l₁ ++ l₂))
split/correct l = split/clocked/correct ⌊ length l /2⌋ ⌈ length l /2⌉ l (N.⌊n/2⌋+⌈n/2⌉≡n (length l))
split/cost : cmp (Π (list A) λ _ → cost)
split/cost l = split/clocked/cost ⌊ length l /2⌋ l
split≤split/cost : ∀ l → IsBounded pair (split l) (split/cost l)
split≤split/cost l = split/clocked≤split/clocked/cost ⌊ length l /2⌋ l
| 43.482143 | 128 | 0.63655 |
1892622cb195bd3a3580feeb13f37a2df7862add | 260 | agda | Agda | test/Fail/IncompletePatternMatching.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/IncompletePatternMatching.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/IncompletePatternMatching.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module IncompletePatternMatching where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data True : Set where
tt : True
data False : Set where
_==_ : Nat -> Nat -> Set
zero == zero = True
suc n == suc m = n == m
thm : zero == suc zero
thm = tt
| 13 | 38 | 0.607692 |
c5457a466043c43acc5f8e1389d8905f289cc53d | 297 | agda | Agda | test/Succeed/Issue384.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue384.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue384.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module Issue384 where
postulate
D : (A : Set) → A → Set
data I : Set where
i : I
D′ : (A : Set) → A → I → Set
D′ A x i = D A x
postulate
Q : (A : Set) → A → Set
q : ∀ j A (x : A) → D′ A x j → Q A x
A : Set
x : A
d : D A x
P : (A : Set) → A → Set
p : P (Q _ _) (q _ _ _ d)
| 12.913043 | 38 | 0.430976 |
dfae9086da771455508f4d00073d0bb8f8af5b6e | 504 | agda | Agda | test/interaction/Issue2028-where.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/interaction/Issue2028-where.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/interaction/Issue2028-where.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- Testcase for #2028 by Ulf
record ⊤ : Set where
constructor tt
data Either (A B : Set) : Set where
inl : A → Either A B
inr : B → Either A B
Subset : Set → Set₁
Subset X = X → Set
U : ∀ {X} → Subset X
U _ = {!⊤!}
_⊆_ : ∀ {X} → Subset X → Subset X → Set
A ⊆ B = ∀ {x} → A x → B x
_∪_ : ∀ {X} → Subset X → Subset X → Subset X
(A ∪ B) x = Either (A x) (B x)
∪-bound : ∀ {X} {A : Subset X} → (A ∪ U) ⊆ U
∪-bound {X} {A} = aux
where
aux : _ → _
aux (inl _) = tt
aux (inr tt) = tt
| 18 | 44 | 0.494048 |
186b012a0fa5ce0f52ea64e0e6c6235e62b3cd53 | 1,123 | agda | Agda | src/Leftovers/Tests.agda | JoeyEremondi/AgdaLeftovers | 01b60b405009feaada181af175f019ceb89e42b2 | [
"BSD-3-Clause"
] | null | null | null | src/Leftovers/Tests.agda | JoeyEremondi/AgdaLeftovers | 01b60b405009feaada181af175f019ceb89e42b2 | [
"BSD-3-Clause"
] | null | null | null | src/Leftovers/Tests.agda | JoeyEremondi/AgdaLeftovers | 01b60b405009feaada181af175f019ceb89e42b2 | [
"BSD-3-Clause"
] | null | null | null | -- Like Leftovers.Examples, but more meant to stress-test the library
-- than to be clear/readable
module Leftovers.Tests where
open import Leftovers.Leftovers
open import Leftovers.ByRefl
open import Level
open import Reflection
open import Data.Nat
open import Relation.Binary.PropositionalEquality
open import Data.Unit
open import Data.List
--Make sure findLeftovers works with
data Foo : Set(Level.suc Level.zero) where
Bar : Set → ℕ → ((n : ℕ) → n ≡ n + 0) → Foo
makePair : Term → TC ⊤
makePair = λ goal →
do
hole1 <- newMeta (quoteTerm Set)
hole2 <- newMeta (quoteTerm ℕ)
hole3 <- newMeta (quoteTerm ((n : ℕ) → n ≡ n + 0))
body <- extendContext (vArg (quoteTerm ℕ)) do
tyHole ← newMeta (quoteTerm Set)
newHole ← newMeta tyHole
return (def (quote sym) (vArg newHole ∷ []))
unify hole3 (lam visible (abs "arg" body))
unify hole2 (quoteTerm 4)
unify goal (con (quote Bar) (vArg hole1 ∷ vArg hole2 ∷ vArg hole3 ∷ []))
p0 : ∀ n → n + 0 ≡ n
p0 zero = refl
p0 (suc n) rewrite p0 n = refl
f : Foo
f =
by
makePair
andAlso
p0
ℕ
| 23.395833 | 78 | 0.649154 |
df2eeae107ecf1ffdd1dd07679c76dd7008d4465 | 1,139 | agda | Agda | test/Succeed/UnquoteExtLam.agda | vlopezj/agda | ff4d89e75970cf27599fb9f572bd43c9455cbb56 | [
"BSD-3-Clause"
] | 3 | 2015-03-28T14:51:03.000Z | 2015-12-07T20:14:00.000Z | test/Succeed/UnquoteExtLam.agda | vikfret/agda | 49ad0b3f0d39c01bc35123478b857e702b29fb9d | [
"BSD-3-Clause"
] | 3 | 2018-11-14T15:31:44.000Z | 2019-04-01T19:39:26.000Z | test/Succeed/UnquoteExtLam.agda | vikfret/agda | 49ad0b3f0d39c01bc35123478b857e702b29fb9d | [
"BSD-3-Clause"
] | 1 | 2015-09-15T14:36:15.000Z | 2015-09-15T14:36:15.000Z |
open import Common.Reflection
open import Common.Prelude
open import Common.Equality
pattern `Nat = def (quote Nat) []
pattern _`→_ a b = pi (vArg a) (abs "_" b)
pattern `Set = sort (lit 0)
pattern `⊥ = def (quote ⊥) []
pattern `zero = con (quote zero) []
pattern `suc n = con (quote suc) (vArg n ∷ [])
prDef : FunDef
prDef =
funDef (`Nat `→ `Nat)
( clause [] (extLam ( clause (vArg `zero ∷ []) `zero
∷ clause (vArg (`suc (var "x")) ∷ []) (var 0 [])
∷ []) [])
∷ [] )
magicDef : FunDef
magicDef =
funDef (pi (hArg `Set) (abs "A" (`⊥ `→ var 1 [])))
( clause [] (extLam ( absurdClause (vArg absurd ∷ [])
∷ []) [])
∷ [] )
unquoteDecl magic = define (vArg magic) magicDef
checkMagic : {A : Set} → ⊥ → A
checkMagic = magic
unquoteDecl pr = define (vArg pr) prDef
magic′ : {A : Set} → ⊥ → A
magic′ = unquote (give (extLam (absurdClause (vArg absurd ∷ []) ∷ []) []))
module Pred (A : Set) where
unquoteDecl pr′ = define (vArg pr′) prDef
check : pr 10 ≡ 9
check = refl
check′ : Pred.pr′ ⊥ 10 ≡ 9
check′ = refl
| 24.234043 | 75 | 0.528534 |
dfbf46b6edda47a351d1eef6e6cd628569b89e2b | 32,980 | agda | Agda | Cubical/HITs/Sn/Properties.agda | howsiyu/cubical | 1b9c97a2140fe96fe636f4c66beedfd7b8096e8f | [
"MIT"
] | null | null | null | Cubical/HITs/Sn/Properties.agda | howsiyu/cubical | 1b9c97a2140fe96fe636f4c66beedfd7b8096e8f | [
"MIT"
] | null | null | null | Cubical/HITs/Sn/Properties.agda | howsiyu/cubical | 1b9c97a2140fe96fe636f4c66beedfd7b8096e8f | [
"MIT"
] | null | null | null | {-# OPTIONS --safe #-}
module Cubical.HITs.Sn.Properties where
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Path
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Univalence
open import Cubical.HITs.S1 renaming (_·_ to _*_)
open import Cubical.HITs.S2
open import Cubical.HITs.S3
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Sigma
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.Susp renaming (toSusp to σ)
open import Cubical.HITs.Truncation
open import Cubical.Homotopy.Connected
open import Cubical.HITs.Join renaming (joinS¹S¹→S³ to joinS¹S¹→S3)
open import Cubical.Data.Bool
private
variable
ℓ : Level
open Iso
IsoSucSphereSusp : (n : ℕ) → Iso (S₊ (suc n)) (Susp (S₊ n))
IsoSucSphereSusp zero = S¹IsoSuspBool
IsoSucSphereSusp (suc n) = idIso
IsoSucSphereSusp∙ : (n : ℕ)
→ Iso.inv (IsoSucSphereSusp n) north ≡ ptSn (suc n)
IsoSucSphereSusp∙ zero = refl
IsoSucSphereSusp∙ (suc n) = refl
-- Elimination principles for spheres
sphereElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isOfHLevel (suc n) (A x))
→ A (ptSn (suc n))
→ (x : S₊ (suc n)) → A x
sphereElim zero hlev pt = toPropElim hlev pt
sphereElim (suc n) hlev pt north = pt
sphereElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt
sphereElim (suc n) {A = A} hlev pt (merid a i) =
sphereElim n {A = λ a → PathP (λ i → A (merid a i)) pt (subst A (merid (ptSn (suc n))) pt)}
(λ a → isOfHLevelPathP' (suc n) (hlev south) _ _)
(λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∧ j))) (~ i) pt)
a i
sphereElim2 : ∀ {ℓ} (n : ℕ) {A : (S₊ (suc n)) → (S₊ (suc n)) → Type ℓ}
→ ((x y : S₊ (suc n)) → isOfHLevel (suc n) (A x y))
→ A (ptSn (suc n)) (ptSn (suc n))
→ (x y : S₊ (suc n)) → A x y
sphereElim2 n hlev pt = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → hlev _ _)
(sphereElim n (hlev _ ) pt)
private
compPath-lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y)
→ PathP (λ i → (p ∙ sym q) i ≡ y) p q
compPath-lem {y = y} p q i j =
hcomp (λ k → λ { (i = i0) → p j
; (i = i1) → q (~ k ∨ j)
; (j = i1) → y })
(p (j ∨ i))
sphereToPropElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isProp (A x))
→ A (ptSn (suc n))
→ (x : S₊ (suc n)) → A x
sphereToPropElim zero = toPropElim
sphereToPropElim (suc n) hlev pt north = pt
sphereToPropElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt
sphereToPropElim (suc n) {A = A} hlev pt (merid a i) =
isProp→PathP {B = λ i → A (merid a i)} (λ _ → hlev _) pt (subst A (merid (ptSn (suc n))) pt) i
-- Elimination rule for fibrations (x : Sⁿ) → (y : Sᵐ) → A x y of h-Level (n + m).
-- The following principle is just the special case of the "Wedge Connectivity Lemma"
-- for spheres (See Cubical.Homotopy.WedgeConnectivity or chapter 8.6 in the HoTT book).
-- We prove it directly here for three reasons:
-- (i) it should perform better
-- (ii) we get a slightly stronger statement for spheres: one of the homotopies will, by design, be refl
-- (iii) the fact that the two homotopies only differ by (composition with) the homotopy leftFunction(base) ≡ rightFunction(base)
-- is close to trivial
wedgeconFun : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ}
→ ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y))
→ (f : (x : _) → A (ptSn (suc n)) x)
→ (g : (x : _) → A x (ptSn (suc m)))
→ (g (ptSn (suc n)) ≡ f (ptSn (suc m)))
→ (x : S₊ (suc n)) (y : S₊ (suc m)) → A x y
wedgeconLeft : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ}
→ (hLev : ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y)))
→ (f : (x : _) → A (ptSn (suc n)) x)
→ (g : (x : _) → A x (ptSn (suc m)))
→ (hom : g (ptSn (suc n)) ≡ f (ptSn (suc m)))
→ (x : _) → wedgeconFun n m hLev f g hom (ptSn (suc n)) x ≡ f x
wedgeconRight : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ}
→ (hLev : ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y)))
→ (f : (x : _) → A (ptSn (suc n)) x)
→ (g : (x : _) → A x (ptSn (suc m)))
→ (hom : g (ptSn (suc n)) ≡ f (ptSn (suc m)))
→ (x : _) → wedgeconFun n m hLev f g hom x (ptSn (suc m)) ≡ g x
wedgeconFun zero zero {A = A} hlev f g hom = F
where
helper : SquareP (λ i j → A (loop i) (loop j)) (cong f loop) (cong f loop)
(λ i → hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i)))
λ i → hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i))
helper = toPathP (isOfHLevelPathP' 1 (hlev _ _) _ _ _ _)
F : (x y : S¹) → A x y
F base y = f y
F (loop i) base = hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i))
F (loop i) (loop j) = helper i j
wedgeconFun zero (suc m) {A = A} hlev f g hom = F₀
module _ where
transpLemma₀ : (x : S₊ (suc m)) → transport (λ i₁ → A base (merid x i₁)) (g base) ≡ f south
transpLemma₀ x = cong (transport (λ i₁ → A base (merid x i₁)))
hom
∙ (λ i → transp (λ j → A base (merid x (i ∨ j))) i
(f (merid x i)))
pathOverMerid₀ : (x : S₊ (suc m)) → PathP (λ i₁ → A base (merid x i₁))
(g base)
(transport (λ i₁ → A base (merid (ptSn (suc m)) i₁))
(g base))
pathOverMerid₀ x i = hcomp (λ k → λ { (i = i0) → g base
; (i = i1) → (transpLemma₀ x ∙ sym (transpLemma₀ (ptSn (suc m)))) k})
(transp (λ i₁ → A base (merid x (i₁ ∧ i))) (~ i)
(g base))
pathOverMeridId₀ : pathOverMerid₀ (ptSn (suc m)) ≡ λ i → transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base)
pathOverMeridId₀ =
(λ j i → hcomp (λ k → λ {(i = i0) → g base
; (i = i1) → rCancel (transpLemma₀ (ptSn (suc m))) j k})
(transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base)))
∙ λ j i → hfill (λ k → λ { (i = i0) → g base
; (i = i1) → transport (λ i₁ → A base (merid (ptSn (suc m)) i₁))
(g base)})
(inS (transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base))) (~ j)
indStep₀ : (x : _) (a : _) → PathP (λ i → A x (merid a i))
(g x)
(subst (λ y → A x y) (merid (ptSn (suc m)))
(g x))
indStep₀ = wedgeconFun zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _)
pathOverMerid₀
(λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g a))
(sym pathOverMeridId₀)
F₀ : (x : S¹) (y : Susp (S₊ (suc m))) → A x y
F₀ x north = g x
F₀ x south = subst (λ y → A x y) (merid (ptSn (suc m))) (g x)
F₀ x (merid a i) = indStep₀ x a i
wedgeconFun (suc n) m {A = A} hlev f g hom = F₁
module _ where
transpLemma₁ : (x : S₊ (suc n)) → transport (λ i₁ → A (merid x i₁) (ptSn (suc m))) (f (ptSn (suc m))) ≡ g south
transpLemma₁ x = cong (transport (λ i₁ → A (merid x i₁) (ptSn (suc m))))
(sym hom)
∙ (λ i → transp (λ j → A (merid x (i ∨ j)) (ptSn (suc m))) i
(g (merid x i)))
pathOverMerid₁ : (x : S₊ (suc n)) → PathP (λ i₁ → A (merid x i₁) (ptSn (suc m)))
(f (ptSn (suc m)))
(transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m)))
(f (ptSn (suc m))))
pathOverMerid₁ x i = hcomp (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → (transpLemma₁ x ∙ sym (transpLemma₁ (ptSn (suc n)))) k })
(transp (λ i₁ → A (merid x (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m))))
pathOverMeridId₁ : pathOverMerid₁ (ptSn (suc n)) ≡ λ i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))
pathOverMeridId₁ =
(λ j i → hcomp (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → rCancel (transpLemma₁ (ptSn (suc n))) j k })
(transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))))
∙ λ j i → hfill (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m)))
(f (ptSn (suc m))) })
(inS (transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m))))) (~ j)
indStep₁ : (a : _) (y : _) → PathP (λ i → A (merid a i) y)
(f y)
(subst (λ x → A x y) (merid (ptSn (suc n)))
(f y))
indStep₁ = wedgeconFun n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _)
(λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i)
(f a))
pathOverMerid₁
pathOverMeridId₁
F₁ : (x : Susp (S₊ (suc n))) (y : S₊ (suc m)) → A x y
F₁ north y = f y
F₁ south y = subst (λ x → A x y) (merid (ptSn (suc n))) (f y)
F₁ (merid a i) y = indStep₁ a y i
wedgeconRight zero zero {A = A} hlev f g hom = right
where
right : (x : S¹) → _
right base = sym hom
right (loop i) j = hcomp (λ k → λ { (i = i0) → hom (~ j ∧ k)
; (i = i1) → hom (~ j ∧ k)
; (j = i1) → g (loop i) })
(g (loop i))
wedgeconRight zero (suc m) {A = A} hlev f g hom x = refl
wedgeconRight (suc n) m {A = A} hlev f g hom = right
where
lem : (x : _) → indStep₁ n m hlev f g hom x (ptSn (suc m)) ≡ _
lem = wedgeconRight n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _)
(λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i)
(f a))
(pathOverMerid₁ n m hlev f g hom)
(pathOverMeridId₁ n m hlev f g hom)
right : (x : Susp (S₊ (suc n))) → _ ≡ g x
right north = sym hom
right south = cong (subst (λ x → A x (ptSn (suc m)))
(merid (ptSn (suc n))))
(sym hom)
∙ λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∨ j)) (ptSn (suc m))) i
(g (merid (ptSn (suc n)) i))
right (merid a i) j =
hcomp (λ k → λ { (i = i0) → hom (~ j)
; (i = i1) → transpLemma₁ n m hlev f g hom (ptSn (suc n)) j
; (j = i0) → lem a (~ k) i
; (j = i1) → g (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom (~ j)
; (i = i1) → compPath-lem (transpLemma₁ n m hlev f g hom a) (transpLemma₁ n m hlev f g hom (ptSn (suc n))) k j
; (j = i1) → g (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom (~ j)
; (j = i0) → transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))
; (j = i1) → transp (λ j → A (merid a (i ∧ (j ∨ k))) (ptSn (suc m))) (k ∨ ~ i)
(g (merid a (i ∧ k))) })
(transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i)
(hom (~ j)))))
wedgeconLeft zero zero {A = A} hlev f g hom x = refl
wedgeconLeft zero (suc m) {A = A} hlev f g hom = help
where
left₁ : (x : _) → indStep₀ m hlev f g hom base x ≡ _
left₁ = wedgeconLeft zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _)
(pathOverMerid₀ m hlev f g hom)
(λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g a))
(sym (pathOverMeridId₀ m hlev f g hom))
help : (x : S₊ (suc (suc m))) → _
help north = hom
help south = cong (subst (A base) (merid (ptSn (suc m)))) hom
∙ λ i → transp (λ j → A base (merid (ptSn (suc m)) (i ∨ j))) i
(f (merid (ptSn (suc m)) i))
help (merid a i) j =
hcomp (λ k → λ { (i = i0) → hom j
; (i = i1) → transpLemma₀ m hlev f g hom (ptSn (suc m)) j
; (j = i0) → left₁ a (~ k) i
; (j = i1) → f (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom j
; (i = i1) → compPath-lem (transpLemma₀ m hlev f g hom a)
(transpLemma₀ m hlev f g hom (ptSn (suc m))) k j
; (j = i1) → f (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom j
; (j = i0) → transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i)
(g base)
; (j = i1) → transp (λ j → A base (merid a (i ∧ (j ∨ k)))) (k ∨ ~ i)
(f (merid a (i ∧ k)))})
(transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i)
(hom j))))
wedgeconLeft (suc n) m {A = A} hlev f g hom _ = refl
---------- Connectedness -----------
sphereConnected : (n : HLevel) → isConnected (suc n) (S₊ n)
sphereConnected n = ∣ ptSn n ∣ , elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(λ a → sym (spoke ∣_∣ (ptSn n)) ∙ spoke ∣_∣ a)
-- The fact that path spaces of Sn are connected can be proved directly for Sⁿ.
-- (Unfortunately, this does not work for higher paths)
pathIdTruncSⁿ : (n : ℕ) (x y : S₊ (suc n))
→ Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣
→ hLevelTrunc (suc n) (x ≡ y)
pathIdTruncSⁿ n = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n))
(sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n))
λ _ → ∣ refl ∣)
pathIdTruncSⁿ⁻ : (n : ℕ) (x y : S₊ (suc n))
→ hLevelTrunc (suc n) (x ≡ y)
→ Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣
pathIdTruncSⁿ⁻ n x y = rec (isOfHLevelTrunc (2 + n) _ _)
(J (λ y _ → Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣) refl)
pathIdTruncSⁿretract : (n : ℕ) (x y : S₊ (suc n)) → (p : hLevelTrunc (suc n) (x ≡ y)) → pathIdTruncSⁿ n x y (pathIdTruncSⁿ⁻ n x y p) ≡ p
pathIdTruncSⁿretract n =
sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
λ y → elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(J (λ y p → pathIdTruncSⁿ n (ptSn (suc n)) y (pathIdTruncSⁿ⁻ n (ptSn (suc n)) y ∣ p ∣) ≡ ∣ p ∣)
(cong (pathIdTruncSⁿ n (ptSn (suc n)) (ptSn (suc n))) (transportRefl refl) ∙ pm-help n))
where
pm-help : (n : ℕ) → pathIdTruncSⁿ n (ptSn (suc n)) (ptSn (suc n)) refl ≡ ∣ refl ∣
pm-help zero = refl
pm-help (suc n) = refl
isConnectedPathSⁿ : (n : ℕ) (x y : S₊ (suc n)) → isConnected (suc n) (x ≡ y)
isConnectedPathSⁿ n x y =
isContrRetract
(pathIdTruncSⁿ⁻ n x y)
(pathIdTruncSⁿ n x y)
(pathIdTruncSⁿretract n x y)
((isContr→isProp (sphereConnected (suc n)) ∣ x ∣ ∣ y ∣)
, isProp→isSet (isContr→isProp (sphereConnected (suc n))) _ _ _)
-- Some lemmas on the H space structure on S¹
rUnitS¹ : (x : S¹) → x * base ≡ x
rUnitS¹ base = refl
rUnitS¹ (loop i₁) = refl
commS¹ : (a x : S¹) → a * x ≡ x * a
commS¹ = wedgeconFun _ _ (λ _ _ → isGroupoidS¹ _ _)
(sym ∘ rUnitS¹)
rUnitS¹
refl
assocS¹ : (x y z : S¹) → x * (y * z) ≡ (x * y) * z
assocS¹ = wedgeconFun _ _ (λ _ _ → isSetΠ λ _ → isGroupoidS¹ _ _)
(λ _ _ → refl)
(λ x z i → (rUnitS¹ x (~ i)) * z)
refl
invLooperDistr : (x y : S¹) → invLooper (x * y) ≡ invLooper x * invLooper y
invLooperDistr =
wedgeconFun 0 0 (λ _ _ → isGroupoidS¹ _ _) (λ _ → refl)
(λ x → cong invLooper (rUnitS¹ x) ∙ sym (rUnitS¹ (invLooper x)))
(sym (rUnit refl))
SuspS¹-hom : (a x : S¹)
→ Path (Path (hLevelTrunc 4 (S₊ 2)) _ _)
(cong ∣_∣ₕ (σ (S₊∙ 1) (a * x)))
(cong ∣_∣ₕ (σ (S₊∙ 1) a)
∙ (cong ∣_∣ₕ (σ (S₊∙ 1) x)))
SuspS¹-hom = wedgeconFun _ _ (λ _ _ → isOfHLevelTrunc 4 _ _ _ _)
(λ x → lUnit _
∙ cong (_∙ cong ∣_∣ₕ (σ (S₊∙ 1) x))
(cong (cong ∣_∣ₕ) (sym (rCancel (merid base)))))
(λ x → (λ i → cong ∣_∣ₕ (σ (S₊∙ 1) (rUnitS¹ x i)))
∙∙ rUnit _
∙∙ cong (cong ∣_∣ₕ (σ (S₊∙ 1) x) ∙_)
(cong (cong ∣_∣ₕ) (sym (rCancel (merid base)))))
(sym (l (cong ∣_∣ₕ (σ (S₊∙ 1) base))
(cong (cong ∣_∣ₕ) (sym (rCancel (merid base))))))
where
l : ∀ {ℓ} {A : Type ℓ} {x : A} (p : x ≡ x) (P : refl ≡ p)
→ lUnit p ∙ cong (_∙ p) P ≡ rUnit p ∙ cong (p ∙_) P
l p = J (λ p P → lUnit p ∙ cong (_∙ p) P ≡ rUnit p ∙ cong (p ∙_) P) refl
rCancelS¹ : (x : S¹) → ptSn 1 ≡ x * (invLooper x)
rCancelS¹ base = refl
rCancelS¹ (loop i) j =
hcomp (λ r → λ {(i = i0) → base ; (i = i1) → base ; (j = i0) → base})
base
SuspS¹-inv : (x : S¹) → Path (Path (hLevelTrunc 4 (S₊ 2)) _ _)
(cong ∣_∣ₕ (σ (S₊∙ 1) (invLooper x)))
(cong ∣_∣ₕ (sym (σ (S₊∙ 1) x)))
SuspS¹-inv x = (lUnit _
∙∙ cong (_∙ cong ∣_∣ₕ (σ (S₊∙ 1) (invLooper x)))
(sym (lCancel (cong ∣_∣ₕ (σ (S₊∙ 1) x))))
∙∙ sym (assoc _ _ _))
∙∙ cong (sym (cong ∣_∣ₕ (σ (S₊∙ 1) x)) ∙_) lem
∙∙ (assoc _ _ _
∙∙ cong (_∙ (cong ∣_∣ₕ (sym (σ (S₊∙ 1) x))))
(lCancel (cong ∣_∣ₕ (σ (S₊∙ 1) x)))
∙∙ sym (lUnit _))
where
lem : cong ∣_∣ₕ (σ (S₊∙ 1) x)
∙ cong ∣_∣ₕ (σ (S₊∙ 1) (invLooper x))
≡ cong ∣_∣ₕ (σ (S₊∙ 1) x)
∙ cong ∣_∣ₕ (sym (σ (S₊∙ 1) x))
lem = sym (SuspS¹-hom x (invLooper x))
∙ ((λ i → cong ∣_∣ₕ (σ (S₊∙ 1) (rCancelS¹ x (~ i))))
∙ cong (cong ∣_∣ₕ) (rCancel (merid base))) ∙ sym (rCancel _)
-------------------- join Sⁿ Sᵐ ≃ Sⁿ⁺¹⁺ᵐ -------------------------
{-
This section contains a proof that join Sⁿ Sᵐ ≃ Sⁿ⁺ᵐ⁺¹. This is easy using
various properties proved in HITs.Join. However, we would like the map
join Sⁿ Sᵐ → Sⁿ⁺ᵐ⁺¹
to be nice, in particular when n = m = 1. Therefore, we put in some extra work into
the equivalence.
-}
{- We begin with join S¹ S¹ ≃ S³. The iso is induced by: -}
S¹×S¹→S² : S¹ → S¹ → S₊ 2
S¹×S¹→S² base y = north
S¹×S¹→S² (loop i) base = north
S¹×S¹→S² (loop i) (loop j) =
(sym (rCancel (merid base))
∙∙ (λ i → merid (loop i) ∙ sym (merid base))
∙∙ rCancel (merid base)) i j
joinS¹S¹→S³ : join S¹ S¹ → S₊ 3
joinS¹S¹→S³ (inl x) = north
joinS¹S¹→S³ (inr x) = south
joinS¹S¹→S³ (push a b i) = merid (S¹×S¹→S² a b) i
{- Proving that this is an equivalence directly is painful,
so we simply prove that it is equal to the old definition of
the equivalence join S¹ S¹ ≃ S³ ≃ S₊ 3
To this end, we start by rephrasing the map -}
private
3cell : (r i j k : I) → S₊ 3
3cell r i j k =
hfill (λ r → λ {(i = i0) → merid (merid base j) (k ∧ ~ r)
; (i = i1) → merid (merid base j) (k ∧ ~ r)
; (j = i0) → merid north (k ∧ ~ r)
; (j = i1) → merid south (k ∧ ~ r)
; (k = i0) → north
; (k = i1) → merid (merid base j) (~ r)})
(inS (merid (merid (loop i) j) k))
r
joinS¹S¹→S³' : join S¹ S¹ → S₊ 3
joinS¹S¹→S³' (inl x) = north
joinS¹S¹→S³' (inr x) = north
joinS¹S¹→S³' (push base b i) = north
joinS¹S¹→S³' (push (loop i₁) base i) = north
joinS¹S¹→S³' (push (loop i₁) (loop i₂) i) = 3cell i1 i₁ i₂ i
{- These two maps are equal -}
joinS¹S¹→S³'≡joinS¹S¹→S³' : (x : _) → joinS¹S¹→S³ x ≡ joinS¹S¹→S³' x
joinS¹S¹→S³'≡joinS¹S¹→S³' (inl base) = refl
joinS¹S¹→S³'≡joinS¹S¹→S³' (inl (loop i)) = refl
joinS¹S¹→S³'≡joinS¹S¹→S³' (inr base) = sym (merid north)
joinS¹S¹→S³'≡joinS¹S¹→S³' (inr (loop i)) = sym (merid north)
joinS¹S¹→S³'≡joinS¹S¹→S³' (push base base i) k = merid north (~ k ∧ i)
joinS¹S¹→S³'≡joinS¹S¹→S³' (push base (loop i₁) i) k = merid north (~ k ∧ i)
joinS¹S¹→S³'≡joinS¹S¹→S³' (push (loop i₁) base i) k = (merid north) (~ k ∧ i)
joinS¹S¹→S³'≡joinS¹S¹→S³' (push (loop i) (loop j) k) l =
hcomp (λ r → λ { (i = i0) → merid (sym (rCancel (merid base)) (~ r) j)
(~ l ∧ k)
; (i = i1) → merid (sym (rCancel (merid base)) (~ r) j)
(~ l ∧ k)
; (j = i0) → merid north (~ l ∧ k)
; (j = i1) → merid north (~ l ∧ k)
; (k = i0) → north
; (k = i1) → merid (sym (rCancel (merid base)) (~ r) j) (~ l)
; (l = i0) → merid (doubleCompPath-filler
(sym (rCancel (merid base)))
(cong (σ (S₊∙ 1)) loop)
(rCancel (merid base)) r i j) k
; (l = i1) → 3cell i1 i j k})
(hcomp (λ r → λ {(i = i0) → merid (cp-fill base r j) (k ∧ ~ l)
; (i = i1) → merid (cp-fill base r j) (k ∧ ~ l)
; (j = i0) → merid north (~ l ∧ k)
; (j = i1) → merid (merid base (~ r)) (~ l ∧ k)
; (k = i0) → north
; (k = i1) → merid (cp-fill base r j) (~ l)
; (l = i0) → merid (cp-fill (loop i) r j) k
; (l = i1) → 3cell i1 i j k})
(hcomp (λ r → λ {(i = i0) → merid (merid base j) (k ∧ (~ r ∨ ~ l))
; (i = i1) → merid (merid base j) (k ∧ (~ r ∨ ~ l))
; (j = i0) → merid north (k ∧ (~ l ∨ ~ r))
; (j = i1) → merid south (k ∧ (~ l ∨ ~ r))
; (k = i0) → north
; (k = i1) → merid (merid base j) (~ r ∨ ~ l)
; (l = i0) → merid (merid (loop i) j) k
; (l = i1) → 3cell r i j k})
(merid (merid (loop i) j) k)))
where
cp-fill : (a : S¹) → _
cp-fill a = compPath-filler (merid a) (sym (merid base))
{- joinS¹S¹→S³' is equal to the original
equivalence (modulo a flipping of interval variables) -}
joinS¹S¹→S³'Id : (x : join S¹ S¹)
→ joinS¹S¹→S³' x ≡ (Iso.fun IsoS³S3 ∘ flip₀₂S³ ∘ joinS¹S¹→S3) x
joinS¹S¹→S³'Id (inl x) = refl
joinS¹S¹→S³'Id (inr x) = refl
joinS¹S¹→S³'Id (push base base i) = refl
joinS¹S¹→S³'Id (push base (loop i₁) i) = refl
joinS¹S¹→S³'Id (push (loop i₁) base i) = refl
joinS¹S¹→S³'Id (push (loop i) (loop j) k) l =
hcomp (λ r → λ {(i = i0) → merid (merid base (j ∧ ~ l)) (~ r ∧ k)
; (i = i1) → merid (merid base (j ∧ ~ l)) (~ r ∧ k)
; (j = i0) → merid north (k ∧ ~ r)
; (j = i1) → merid (merid base (~ l)) (~ r ∧ k)
; (k = i0) → north
; (k = i1) → merid (merid base (j ∧ ~ l)) (~ r)
; (l = i0) → 3cell r i j k
; (l = i1) → Iso.fun (IsoType→IsoSusp S²IsoSuspS¹)
(meridian-contraction-2 k j i r)})
(merid (S²Cube i j l) k)
where
S²Cube : Cube {A = S₊ 2} (λ j l → merid base (j ∧ ~ l))
(λ j l → merid base (j ∧ ~ l))
(λ i l → north)
(λ i l → merid base (~ l))
(λ i j → merid (loop i) j)
λ i j → fun S²IsoSuspS¹ (surf j i)
S²Cube i j l =
hcomp (λ r → λ {(i = i0) → merid base (j ∧ (~ l ∨ ~ r))
; (i = i1) → merid base (j ∧ (~ l ∨ ~ r))
; (j = i0) → north
; (j = i1) → merid base (~ l ∨ ~ r)
; (l = i0) → merid (loop i) j
; (l = i1) → meridian-contraction j i r})
(merid (loop i) j)
{-So, finally our map joinS¹S¹→S³ is an iso. We state its inverse explicitly. -}
Iso-joinS¹S¹-S³ : Iso (join S¹ S¹) (S₊ 3)
fun Iso-joinS¹S¹-S³ = joinS¹S¹→S³
inv Iso-joinS¹S¹-S³ = S³→joinS¹S¹ ∘ flip₀₂S³ ∘ Iso.inv IsoS³S3
rightInv Iso-joinS¹S¹-S³ x =
joinS¹S¹→S³'≡joinS¹S¹→S³'
((S³→joinS¹S¹ ∘ flip₀₂S³ ∘ Iso.inv IsoS³S3) x)
∙∙ joinS¹S¹→S³'Id ((S³→joinS¹S¹ ∘ flip₀₂S³ ∘ Iso.inv IsoS³S3) x)
∙∙ Iso.leftInv (compIso (invIso IsoS³S3)
(compIso flip₀₂S³Iso (S³IsojoinS¹S¹))) x
leftInv Iso-joinS¹S¹-S³ x =
cong (S³→joinS¹S¹ ∘ flip₀₂S³ ∘ inv IsoS³S3)
(joinS¹S¹→S³'≡joinS¹S¹→S³' x ∙ joinS¹S¹→S³'Id x)
∙ Iso.rightInv (compIso (invIso IsoS³S3) (compIso flip₀₂S³Iso (S³IsojoinS¹S¹))) x
{- We now get the full iso Sⁿ * Sᵐ ≃ Sⁿ⁺ᵐ⁺¹ -}
IsoSphereJoin : (n m : ℕ)
→ Iso (join (S₊ n) (S₊ m)) (S₊ (suc (n + m)))
IsoSphereJoin zero zero = compIso (invIso Susp-iso-joinBool) (invIso S¹IsoSuspBool)
IsoSphereJoin zero (suc m) = compIso join-comm (invIso Susp-iso-joinBool)
IsoSphereJoin (suc zero) zero = (invIso Susp-iso-joinBool)
IsoSphereJoin (suc zero) (suc zero) = Iso-joinS¹S¹-S³
IsoSphereJoin (suc zero) (suc (suc m)) =
compIso join-comm
(compIso (compIso (Iso-joinSusp-suspJoin {A = S₊∙ (suc m)} {B = S₊∙ (suc zero)})
(congSuspIso join-comm))
(congSuspIso (IsoSphereJoin (suc zero) (suc m))))
IsoSphereJoin (suc (suc n)) m =
compIso (Iso-joinSusp-suspJoin {A = S₊∙ (suc n)} {B = S₊∙ m}) (congSuspIso (IsoSphereJoin (suc n) m))
{- Pointedness holds by refl.
This is due to the explicit definition of Iso-joinSusp-suspJoin -}
IsoSphereJoinPres∙ : (n m : ℕ)
→ Iso.fun (IsoSphereJoin n m) (inl (ptSn n)) ≡ ptSn (suc (n + m))
IsoSphereJoinPres∙ zero zero = refl
IsoSphereJoinPres∙ zero (suc m) = refl
IsoSphereJoinPres∙ (suc zero) zero = refl
IsoSphereJoinPres∙ (suc zero) (suc zero) = refl
IsoSphereJoinPres∙ (suc zero) (suc (suc m)) = refl
IsoSphereJoinPres∙ (suc (suc n)) m = refl
IsoSphereJoin⁻Pres∙ : (n m : ℕ)
→ Iso.inv (IsoSphereJoin n m) (ptSn (suc (n + m))) ≡ inl (ptSn n)
IsoSphereJoin⁻Pres∙ n m =
cong (Iso.inv (IsoSphereJoin n m)) (sym (IsoSphereJoinPres∙ n m))
∙ Iso.leftInv (IsoSphereJoin n m) (inl (ptSn n))
-- Inversion on spheres
invSphere : {n : ℕ} → S₊ n → S₊ n
invSphere {n = zero} = not
invSphere {n = (suc zero)} = invLooper
invSphere {n = (suc (suc n))} = invSusp
invSphere² : (n : ℕ) (x : S₊ n) → invSphere (invSphere x) ≡ x
invSphere² zero = notnot
invSphere² (suc zero) base = refl
invSphere² (suc zero) (loop i) = refl
invSphere² (suc (suc n)) = invSusp²
-- Interaction between σ and invSphere
σ-invSphere : (n : ℕ) (x : S₊ (suc n))
→ σ (S₊∙ (suc n)) (invSphere x)
≡ sym (σ (S₊∙ (suc n)) x)
σ-invSphere zero base =
rCancel (merid base) ∙∙ refl ∙∙ cong sym (sym (rCancel (merid base)))
σ-invSphere zero (loop i) j =
hcomp (λ k → λ { (j = i0) → doubleCompPath-filler
(sym (rCancel (merid base)))
(λ i → (σ (S₊∙ 1) (loop (~ i))))
(rCancel (merid base)) (~ k) i
; (j = i1) → doubleCompPath-filler
(sym (cong sym (rCancel (merid base))))
(λ i → sym (σ (S₊∙ 1) (loop i)))
(cong sym (rCancel (merid base))) (~ k) i})
(sym≡cong-sym (sym (rCancel (merid base))
∙∙ (λ i → (σ (S₊∙ 1) (loop i)))
∙∙ (rCancel (merid base))) j i)
σ-invSphere (suc n) x = toSusp-invSusp (S₊∙ (suc n)) x
-- Some facts about the map S¹×S¹→S²
-- Todo: generalise to Sⁿ×Sᵐ→Sⁿ⁺ᵐ
S¹×S¹→S²rUnit : (a : S¹) → S¹×S¹→S² a base ≡ north
S¹×S¹→S²rUnit base = refl
S¹×S¹→S²rUnit (loop i) = refl
S¹×S¹→S²x+x : (x : S¹) → S¹×S¹→S² x x ≡ north
S¹×S¹→S²x+x base = refl
S¹×S¹→S²x+x (loop i) k = lem k i
where
lem : cong₂ S¹×S¹→S² loop loop ≡ refl
lem = cong₂Funct S¹×S¹→S² loop loop
∙ (λ i → rUnit (cong (λ x → S¹×S¹→S²rUnit x i) loop) (~ i))
S¹×S¹→S²-antiComm : (a b : S¹) → S¹×S¹→S² a b ≡ S¹×S¹→S² b (invLooper a)
S¹×S¹→S²-antiComm base base = refl
S¹×S¹→S²-antiComm base (loop i) = refl
S¹×S¹→S²-antiComm (loop i) base = refl
S¹×S¹→S²-antiComm (loop i) (loop j) k =
sym≡flipSquare (λ j i → S¹×S¹→S² (loop i) (loop j)) (~ k) i j
private
S¹×S¹→S²-Distr-filler : (i : I)
→ cong₂ (λ b c → S¹×S¹→S² ((loop i) * b) c) loop loop
≡ cong (S¹×S¹→S² (loop i)) loop
S¹×S¹→S²-Distr-filler i =
cong₂Funct (λ b c → S¹×S¹→S² ((loop i) * b) c) loop loop
∙∙ (λ j → cong (λ x → S¹×S¹→S²rUnit (rotLoop x i) j) loop ∙
cong (λ c → S¹×S¹→S² (loop i) c) loop)
∙∙ sym (lUnit _)
S¹×S¹→S²-Distr : (a b : S¹) → S¹×S¹→S² (a * b) b ≡ S¹×S¹→S² a b
S¹×S¹→S²-Distr a base j = S¹×S¹→S² (rUnitS¹ a j) base
S¹×S¹→S²-Distr base (loop i) k = S¹×S¹→S²-Distr-filler i0 k i
S¹×S¹→S²-Distr (loop i₁) (loop i) k = S¹×S¹→S²-Distr-filler i₁ k i
invSusp∘S¹×S¹→S² : (a b : S¹)
→ S¹×S¹→S² a (invLooper b) ≡ invSusp (S¹×S¹→S² a b)
invSusp∘S¹×S¹→S² base b = merid base
invSusp∘S¹×S¹→S² (loop i) base = merid base
invSusp∘S¹×S¹→S² (loop i) (loop j) k =
hcomp (λ r → λ {(i = i0) → i-Boundary₂ r j k
; (i = i1) → i-Boundary₂ r j k
; (j = i0) → m-b k
; (j = i1) → m-b k
; (k = i0) → doubleCompPath-filler
rCancel-mb⁻¹ (cong σ₁ loop) rCancel-mb r i (~ j)
; (k = i1)
→ invSusp (doubleCompPath-filler
rCancel-mb⁻¹ (cong σ₁ loop) rCancel-mb r i j)})
(hcomp (λ r → λ {(i = i0) → i-Boundary r (~ j) k
; (i = i1) → i-Boundary r (~ j) k
; (j = i0) → merid base (~ r ∨ k)
; (j = i1) → merid base (r ∧ k)
; (k = i0) → cp-filler (loop i) r (~ j)
; (k = i1) → invSusp (cp-filler (loop i) r j)})
(merid (loop i) (~ j)))
where
σ₁ = σ (S₊∙ 1)
m-b = merid base
rCancel-mb = rCancel m-b
rCancel-mb⁻¹ = sym (rCancel m-b)
cp-filler : (a : S¹) (i j : I) → S₊ 2
cp-filler a i j = compPath-filler (merid a) (sym (merid base)) i j
i-Boundary : I → I → I → S₊ 2
i-Boundary r j k =
hfill (λ r → λ{(j = i0) → m-b (k ∧ r)
; (j = i1) → m-b (~ r ∨ k)
; (k = i0) → cp-filler base r j
; (k = i1) → invSusp (cp-filler base r (~ j))})
(inS (m-b j))
r
i-Boundary₂ : I → I → I → S₊ 2
i-Boundary₂ r j k =
hcomp (λ i → λ {(r = i0) → i-Boundary i (~ j) k
; (r = i1) → m-b k
; (j = i0) → m-b (k ∨ (~ i ∧ ~ r))
; (j = i1) → m-b (k ∧ (i ∨ r))
; (k = i0) → rCancel-filler m-b i r (~ j)
; (k = i1) → invSusp (rCancel-filler m-b i r j) })
(hcomp (λ i → λ {(r = i0) → m-b (~ j ∨ (~ i ∧ k))
; (r = i1) → m-b (k ∨ (~ i ∧ ~ j))
; (j = i0) → m-b (k ∨ (~ r ∨ ~ i))
; (j = i1) → m-b (k ∧ (~ i ∨ r))
; (k = i0) → m-b (~ j ∧ (~ r ∨ ~ i))
; (k = i1) → m-b ((~ j ∨ ~ i) ∨ r) })
(m-b (~ j ∨ k)))
| 47.521614 | 138 | 0.457186 |
103a873656a066d756994221ed57155022748f09 | 6,039 | agda | Agda | agda/par-swap/dpg-pot.agda | florence/esterel-calculus | 4340bef3f8df42ab8167735d35a4cf56243a45cd | [
"MIT"
] | 3 | 2020-04-16T10:58:53.000Z | 2020-07-01T03:59:31.000Z | agda/par-swap/dpg-pot.agda | florence/esterel-calculus | 4340bef3f8df42ab8167735d35a4cf56243a45cd | [
"MIT"
] | null | null | null | agda/par-swap/dpg-pot.agda | florence/esterel-calculus | 4340bef3f8df42ab8167735d35a4cf56243a45cd | [
"MIT"
] | 1 | 2020-04-15T20:02:49.000Z | 2020-04-15T20:02:49.000Z | module par-swap.dpg-pot where
open import Data.Empty
open import Data.Product
open import Data.Sum
open import Data.Bool
open import Data.List using ([] ; [_] ; _∷_ ; List ; _++_)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym)
open import Data.Maybe using ()
open import Data.List.Any using (here ; there)
open import Data.List.Any.Properties using ( ++-comm ; ++⁻ ; ++⁺ˡ ; ++⁺ʳ )
open import Data.Nat as Nat using (ℕ)
open import par-swap
open import par-swap.properties
open import Esterel.Lang.CanFunction
open import Esterel.Lang
open import Esterel.Lang.Properties
open import Esterel.Lang.CanFunction.Plug
open import Esterel.Environment as Env
open import Esterel.Context
open import utility
open import sn-calculus
open import context-properties -- get view, E-views
open import sn-calculus-props
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
canₛ-par :
∀ r₁ r₂ -> ∀ (θ : Env) (S : ℕ) →
S ∈ Canₛ (r₂ ∥ r₁) θ →
S ∈ Canₛ (r₁ ∥ r₂) θ
canₛ-par r₁ r₂ θ S S∈r₂∥r₁
= ++-comm (proj₁ (Can r₂ θ)) (proj₁ (Can r₁ θ)) S∈r₂∥r₁
canₖ-par :
∀ r₁ r₂ -> ∀ (θ : Env) (k : Code) →
k ∈ Canₖ (r₂ ∥ r₁) θ →
k ∈ Canₖ (r₁ ∥ r₂) θ
canₖ-par
= \ {r₁ r₂ θ S S∈r₂∥r₁ ->
thing S
(proj₁ (proj₂ (Can r₁ θ)))
(proj₁ (proj₂ (Can r₂ θ)))
S∈r₂∥r₁} where
simplify-foldr++-[] : ∀ (l2 : List Code) ->
(Data.List.foldr{A = (List Code)}
_++_
[]
(Data.List.map (λ (k : Code) → []) l2)) ≡ []
simplify-foldr++-[] [] = refl
simplify-foldr++-[] (x ∷ l2) = simplify-foldr++-[] l2
whatevs-left : ∀ S (whatevs : Code -> Code) l1 l2 ->
Data.List.Any.Any (_≡_ S)
(Data.List.foldr _++_ []
(Data.List.map (λ k → Data.List.map (Code._⊔_ k) l2) l1))
->
Data.List.Any.Any (_≡_ S)
(Data.List.foldr _++_ []
(Data.List.map (λ k → (whatevs k) ∷ Data.List.map (Code._⊔_ k) l2) l1))
whatevs-left S whatevs [] l2 ()
whatevs-left S whatevs (x ∷ l1) l2 blob
with ++⁻ (Data.List.map (Code._⊔_ x) l2) blob
... | inj₁ y = there (++⁺ˡ y)
... | inj₂ y
with whatevs-left S whatevs l1 l2 y
... | R = there (++⁺ʳ (Data.List.map (Code._⊔_ x) l2) R)
whatevs-right :
∀ S (whatevs : Code -> List Code) x l1 ->
Data.List.Any.Any (_≡_ S) (Data.List.map (Code._⊔_ x) l1)
->
Data.List.Any.Any (_≡_ S)
(Data.List.foldr _++_ []
(Data.List.map (λ k → (k Code.⊔ x) ∷ whatevs k)
l1))
whatevs-right S whatevs x [] blob = blob
whatevs-right S whatevs x (x₁ ∷ l1) (here px)
rewrite px = here (Code.⊔-comm x x₁)
whatevs-right S whatevs x (x₁ ∷ l1) (there blob)
= there (++⁺ʳ (whatevs x₁) (whatevs-right S whatevs x l1 blob))
thing : ∀ S l1 l2 ->
Data.List.Any.Any (_≡_ S)
(Data.List.foldr _++_ []
(Data.List.map
(λ k → Data.List.map (Code._⊔_ k) l1)
l2))
->
Data.List.Any.Any (_≡_ S)
(Data.List.foldr _++_ []
(Data.List.map
(λ k → Data.List.map (Code._⊔_ k) l2)
l1))
thing S l1 [] blob
rewrite simplify-foldr++-[] l1
= blob
thing S l1 (x ∷ l2) blob
with ++⁻ (Data.List.map (Code._⊔_ x) l1) blob
thing S l1 (x ∷ l2) _ | inj₁ y =
whatevs-right S (λ { k → Data.List.map (Code._⊔_ k) l2 }) x l1 y
thing S l1 (x ∷ l2) _ | inj₂ y =
whatevs-left S (\ { k -> (k Code.⊔ x)}) l1 l2 (thing S l1 l2 y)
canₛₕ-par :
∀ r₁ r₂ -> ∀ (θ : Env) →
Canₛₕ (r₂ ∥ r₁) θ ⊆¹ Canₛₕ (r₁ ∥ r₂) θ
canₛₕ-par r₁ r₂ θ S S∈r₂∥r₁
= ++-comm (proj₂ (proj₂ (Can r₂ θ))) (proj₂ (proj₂ (Can r₁ θ))) S∈r₂∥r₁
canθₛ-C-par : ∀ sigs S'' -> ∀ {C p r₁ r₂} ->
p ≐ C ⟦ r₁ ∥ r₂ ⟧c ->
∀ {θ} S' ->
S' ∉ Canθₛ sigs S'' p θ ->
S' ∉ Canθₛ sigs S'' (C ⟦ r₂ ∥ r₁ ⟧c) θ
canθₛ-C-par sigs S'' {C} {p} {r₁} {r₂} pC {θ} S' S'∉Canθₛ[p] S'∈Canθₛ[C⟦r₂∥r₁⟧c]
with canθₛ-plug S'' sigs C (r₁ ∥ r₂) (r₂ ∥ r₁)
(canₛ-par r₁ r₂) (canₖ-par r₁ r₂) θ S'
... | r₂r₁->r₁r₂ rewrite sym (unplugc pC) = S'∉Canθₛ[p] (r₂r₁->r₁r₂ S'∈Canθₛ[C⟦r₂∥r₁⟧c])
canθₛₕ-C-par : ∀ sigs S' -> ∀ {C p r₁ r₂} ->
p ≐ C ⟦ r₁ ∥ r₂ ⟧c ->
∀ {θ} s' ->
s' ∉ Canθₛₕ sigs S' p θ ->
s' ∉ Canθₛₕ sigs S' (C ⟦ r₂ ∥ r₁ ⟧c) θ
canθₛₕ-C-par sigs S' {C} {p} {r₁} {r₂} pC {θ} s' s'∉Canθₛₕ[p] s'∈Canθₛₕ[C⟦r₂∥r₁⟧c]
with canθₛₕ-plug S' sigs C (r₁ ∥ r₂) (r₂ ∥ r₁)
(canₛₕ-par r₁ r₂) (canₖ-par r₁ r₂) (canₛ-par r₁ r₂) θ s'
... | r₂r₁->r₁r₂ rewrite sym (unplugc pC) = s'∉Canθₛₕ[p] (r₂r₁->r₁r₂ s'∈Canθₛₕ[C⟦r₂∥r₁⟧c])
DPG-pot-view :
∀ {C r₁ r₂ p q θ θ' A A'} ->
p ≐ C ⟦ r₁ ∥ r₂ ⟧c ->
(psn⟶₁q : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θ' , A' ⟩· q) ->
(p≡q : p ≡ q) ->
(A≡A' : A ≡ A') ->
->pot-view psn⟶₁q p≡q A≡A' ->
Σ[ dd′ ∈ Term × Term ]
(ρ⟨ θ , A ⟩· C ⟦ r₂ ∥ r₁ ⟧c sn⟶ (proj₂ dd′))
×
((proj₂ dd′) sn⟶* (proj₁ dd′))
×
((ρ⟨ θ' , A' ⟩· q) ∥R* (proj₁ dd′))
DPG-pot-view pC (ris-present S∈ x x₁) p≡q A≡A' ()
DPG-pot-view pC (ris-absent S∈ x x₁) p≡q A≡A' ()
DPG-pot-view pC (remit S∈ ¬S≡a x) p≡q A≡A' ()
DPG-pot-view pC (rraise-shared e' x) p≡q A≡A' ()
DPG-pot-view pC (rset-shared-value-old e' s∈ x x₁) p≡q A≡A' ()
DPG-pot-view pC (rset-shared-value-new e' s∈ x x₁) p≡q A≡A' ()
DPG-pot-view pC (rraise-var e' x₁) p≡q A≡A' ()
DPG-pot-view pC (rset-var x∈ e' x₁) p≡q A≡A' ()
DPG-pot-view pC (rif-false x∈ x₁ x₂) p≡q A≡A' ()
DPG-pot-view pC (rif-true x∈ x₁ x₂) p≡q A≡A' ()
DPG-pot-view pC (rabsence{θ}{_}{S} S∈ x x₁) .refl .refl (vabsence .S .S∈ .x .x₁)
= _ , rcontext [] dchole
(rabsence{θ}{_}{S} S∈ x (canθₛ-C-par (sig θ) 0 pC (Signal.unwrap S) x₁)) ,
rrefl ,
Context1-∥R* (cenv _ _) (∥Rn (∥Rstep pC) ∥R0)
DPG-pot-view pC (rreadyness{θ}{_}{s} s∈ x x₁) .refl .refl (vreadyness .s .s∈ .x .x₁)
= _ , rcontext [] dchole
(rreadyness{s = s} s∈ x (canθₛₕ-C-par (sig θ) 0 pC (SharedVar.unwrap s) x₁)) ,
rrefl ,
Context1-∥R* (cenv _ _) (∥Rn (∥Rstep pC) ∥R0)
DPG-pot-view pC (rmerge x) p≡q A≡A' ()
| 32.820652 | 90 | 0.563669 |
20f6895f8b8e6fa566b3c64e0873f013e74f0763 | 721 | agda | Agda | Prelude/Char.agda | bbarenblat/B | c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec | [
"Apache-2.0"
] | 1 | 2017-06-30T15:59:38.000Z | 2017-06-30T15:59:38.000Z | Prelude/Char.agda | bbarenblat/B | c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec | [
"Apache-2.0"
] | null | null | null | Prelude/Char.agda | bbarenblat/B | c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec | [
"Apache-2.0"
] | null | null | null | {- Copyright © 2015 Benjamin Barenblat
Licensed under the Apache License, Version 2.0 (the ‘License’); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an ‘AS IS’ BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. -}
module B.Prelude.Char where
import Data.Char
open Data.Char
using (Char)
public
module Char where
open Data.Char
using (toNat)
public
| 27.730769 | 79 | 0.76699 |
20120e22d3bbd01f762bafa079945177c5b0f576 | 6,100 | agda | Agda | Cubical/Data/List/Properties.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | Cubical/Data/List/Properties.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | 1 | 2022-01-27T02:07:48.000Z | 2022-01-27T02:07:48.000Z | Cubical/Data/List/Properties.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | 1 | 2021-11-22T02:02:01.000Z | 2021-11-22T02:02:01.000Z | {-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.List.Properties where
open import Agda.Builtin.List
open import Cubical.Core.Everything
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.Unit
open import Cubical.Relation.Nullary
open import Cubical.Data.List.Base
module _ {ℓ} {A : Type ℓ} where
++-unit-r : (xs : List A) → xs ++ [] ≡ xs
++-unit-r [] = refl
++-unit-r (x ∷ xs) = cong (_∷_ x) (++-unit-r xs)
++-assoc : (xs ys zs : List A) → (xs ++ ys) ++ zs ≡ xs ++ ys ++ zs
++-assoc [] ys zs = refl
++-assoc (x ∷ xs) ys zs = cong (_∷_ x) (++-assoc xs ys zs)
rev-snoc : (xs : List A) (y : A) → rev (xs ++ [ y ]) ≡ y ∷ rev xs
rev-snoc [] y = refl
rev-snoc (x ∷ xs) y = cong (_++ [ x ]) (rev-snoc xs y)
rev-++ : (xs ys : List A) → rev (xs ++ ys) ≡ rev ys ++ rev xs
rev-++ [] ys = sym (++-unit-r (rev ys))
rev-++ (x ∷ xs) ys =
cong (λ zs → zs ++ [ x ]) (rev-++ xs ys)
∙ ++-assoc (rev ys) (rev xs) [ x ]
rev-rev : (xs : List A) → rev (rev xs) ≡ xs
rev-rev [] = refl
rev-rev (x ∷ xs) = rev-snoc (rev xs) x ∙ cong (_∷_ x) (rev-rev xs)
rev-rev-snoc : (xs : List A) (y : A) →
Square (rev-rev (xs ++ [ y ])) (cong (_++ [ y ]) (rev-rev xs)) (cong rev (rev-snoc xs y)) refl
rev-rev-snoc [] y = sym (lUnit refl)
rev-rev-snoc (x ∷ xs) y i j =
hcomp
(λ k → λ
{ (i = i1) → compPath-filler (rev-snoc (rev xs) x) (cong (x ∷_) (rev-rev xs)) k j ++ [ y ]
; (j = i0) → rev (rev-snoc xs y i ++ [ x ])
; (j = i1) → x ∷ rev-rev-snoc xs y i k
})
(rev-snoc (rev-snoc xs y i) x j)
data SnocView : List A → Type ℓ where
nil : SnocView []
snoc : (x : A) → (xs : List A) → (sx : SnocView xs) → SnocView (xs ∷ʳ x)
snocView : (xs : List A) → SnocView xs
snocView xs = helper nil xs
where
helper : {l : List A} -> SnocView l -> (r : List A) -> SnocView (l ++ r)
helper {l} sl [] = subst SnocView (sym (++-unit-r l)) sl
helper {l} sl (x ∷ r) = subst SnocView (++-assoc l (x ∷ []) r) (helper (snoc x l sl) r)
-- Path space of list type
module ListPath {ℓ} {A : Type ℓ} where
Cover : List A → List A → Type ℓ
Cover [] [] = Lift Unit
Cover [] (_ ∷ _) = Lift ⊥
Cover (_ ∷ _) [] = Lift ⊥
Cover (x ∷ xs) (y ∷ ys) = (x ≡ y) × Cover xs ys
reflCode : ∀ xs → Cover xs xs
reflCode [] = lift tt
reflCode (_ ∷ xs) = refl , reflCode xs
encode : ∀ xs ys → (p : xs ≡ ys) → Cover xs ys
encode xs _ = J (λ ys _ → Cover xs ys) (reflCode xs)
encodeRefl : ∀ xs → encode xs xs refl ≡ reflCode xs
encodeRefl xs = JRefl (λ ys _ → Cover xs ys) (reflCode xs)
decode : ∀ xs ys → Cover xs ys → xs ≡ ys
decode [] [] _ = refl
decode [] (_ ∷ _) (lift ())
decode (x ∷ xs) [] (lift ())
decode (x ∷ xs) (y ∷ ys) (p , c) = cong₂ _∷_ p (decode xs ys c)
decodeRefl : ∀ xs → decode xs xs (reflCode xs) ≡ refl
decodeRefl [] = refl
decodeRefl (x ∷ xs) = cong (cong₂ _∷_ refl) (decodeRefl xs)
decodeEncode : ∀ xs ys → (p : xs ≡ ys) → decode xs ys (encode xs ys p) ≡ p
decodeEncode xs _ =
J (λ ys p → decode xs ys (encode xs ys p) ≡ p)
(cong (decode xs xs) (encodeRefl xs) ∙ decodeRefl xs)
isOfHLevelCover : (n : HLevel) (p : isOfHLevel (suc (suc n)) A)
(xs ys : List A) → isOfHLevel (suc n) (Cover xs ys)
isOfHLevelCover n p [] [] =
isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isPropUnit)
isOfHLevelCover n p [] (y ∷ ys) =
isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isProp⊥)
isOfHLevelCover n p (x ∷ xs) [] =
isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isProp⊥)
isOfHLevelCover n p (x ∷ xs) (y ∷ ys) =
isOfHLevelΣ (suc n) (p x y) (\ _ → isOfHLevelCover n p xs ys)
isOfHLevelList : ∀ {ℓ} (n : HLevel) {A : Type ℓ}
→ isOfHLevel (suc (suc n)) A → isOfHLevel (suc (suc n)) (List A)
isOfHLevelList n ofLevel xs ys =
isOfHLevelRetract (suc n)
(ListPath.encode xs ys)
(ListPath.decode xs ys)
(ListPath.decodeEncode xs ys)
(ListPath.isOfHLevelCover n ofLevel xs ys)
private
variable
ℓ : Level
A : Type ℓ
caseList : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → (n c : B) → List A → B
caseList n _ [] = n
caseList _ c (_ ∷ _) = c
safe-head : A → List A → A
safe-head x [] = x
safe-head _ (x ∷ _) = x
safe-tail : List A → List A
safe-tail [] = []
safe-tail (_ ∷ xs) = xs
cons-inj₁ : ∀ {x y : A} {xs ys} → x ∷ xs ≡ y ∷ ys → x ≡ y
cons-inj₁ {x = x} p = cong (safe-head x) p
cons-inj₂ : ∀ {x y : A} {xs ys} → x ∷ xs ≡ y ∷ ys → xs ≡ ys
cons-inj₂ = cong safe-tail
¬cons≡nil : ∀ {x : A} {xs} → ¬ (x ∷ xs ≡ [])
¬cons≡nil {A = A} p = lower (subst (caseList (Lift ⊥) (List A)) p [])
¬nil≡cons : ∀ {x : A} {xs} → ¬ ([] ≡ x ∷ xs)
¬nil≡cons {A = A} p = lower (subst (caseList (List A) (Lift ⊥)) p [])
¬snoc≡nil : ∀ {x : A} {xs} → ¬ (xs ∷ʳ x ≡ [])
¬snoc≡nil {xs = []} contra = ¬cons≡nil contra
¬snoc≡nil {xs = x ∷ xs} contra = ¬cons≡nil contra
¬nil≡snoc : ∀ {x : A} {xs} → ¬ ([] ≡ xs ∷ʳ x)
¬nil≡snoc contra = ¬snoc≡nil (sym contra)
cons≡rev-snoc : (x : A) → (xs : List A) → x ∷ rev xs ≡ rev (xs ∷ʳ x)
cons≡rev-snoc _ [] = refl
cons≡rev-snoc x (y ∷ ys) = λ i → cons≡rev-snoc x ys i ++ y ∷ []
isContr[]≡[] : isContr (Path (List A) [] [])
isContr[]≡[] = refl , ListPath.decodeEncode [] []
isPropXs≡[] : {xs : List A} → isProp (xs ≡ [])
isPropXs≡[] {xs = []} = isOfHLevelSuc 0 isContr[]≡[]
isPropXs≡[] {xs = x ∷ xs} = λ p _ → ⊥.rec (¬cons≡nil p)
discreteList : Discrete A → Discrete (List A)
discreteList eqA [] [] = yes refl
discreteList eqA [] (y ∷ ys) = no ¬nil≡cons
discreteList eqA (x ∷ xs) [] = no ¬cons≡nil
discreteList eqA (x ∷ xs) (y ∷ ys) with eqA x y | discreteList eqA xs ys
... | yes p | yes q = yes (λ i → p i ∷ q i)
... | yes _ | no ¬q = no (λ p → ¬q (cons-inj₂ p))
... | no ¬p | _ = no (λ q → ¬p (cons-inj₁ q))
foldrCons : (xs : List A) → foldr _∷_ [] xs ≡ xs
foldrCons [] = refl
foldrCons (x ∷ xs) = cong (x ∷_) (foldrCons xs)
| 34.463277 | 98 | 0.549672 |
c5c56ceae337d70b405a575d3a6bf46538fab515 | 1,249 | agda | Agda | Cubical/HITs/S1/Properties.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/HITs/S1/Properties.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/HITs/S1/Properties.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | 1 | 2021-11-22T02:02:01.000Z | 2021-11-22T02:02:01.000Z | {-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.S1.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.HITs.S1.Base
open import Cubical.HITs.PropositionalTruncation as PropTrunc
isConnectedS¹ : (s : S¹) → ∥ base ≡ s ∥
isConnectedS¹ base = ∣ refl ∣
isConnectedS¹ (loop i) =
squash ∣ (λ j → loop (i ∧ j)) ∣ ∣ (λ j → loop (i ∨ ~ j)) ∣ i
isGroupoidS¹ : isGroupoid S¹
isGroupoidS¹ s t =
PropTrunc.rec isPropIsSet
(λ p →
subst (λ s → isSet (s ≡ t)) p
(PropTrunc.rec isPropIsSet
(λ q → subst (λ t → isSet (base ≡ t)) q isSetΩS¹)
(isConnectedS¹ t)))
(isConnectedS¹ s)
toPropElim : ∀ {ℓ} {B : S¹ → Type ℓ} → ((s : S¹) → isProp (B s)) → B base → (s : S¹) → B s
toPropElim {B = B} isprop b base = b
toPropElim {B = B} isprop b (loop i) = hcomp (λ k → λ {(i = i0) → b
; (i = i1) → isprop base (subst B (loop) b) b k})
(transp (λ j → B (loop (i ∧ j))) (~ i) b)
| 35.685714 | 102 | 0.60048 |
dc93983dd928ef4f4f9b7e8c87d264ede3505463 | 1,068 | agda | Agda | maybe.agda | logicshan/IAL | 2ad96390a9be5c238e73709a21533c7354cedd0c | [
"MIT"
] | null | null | null | maybe.agda | logicshan/IAL | 2ad96390a9be5c238e73709a21533c7354cedd0c | [
"MIT"
] | null | null | null | maybe.agda | logicshan/IAL | 2ad96390a9be5c238e73709a21533c7354cedd0c | [
"MIT"
] | null | null | null | module maybe where
open import level
open import eq
open import bool
----------------------------------------------------------------------
-- datatypes
----------------------------------------------------------------------
data maybe {ℓ}(A : Set ℓ) : Set ℓ where
just : A → maybe A
nothing : maybe A
----------------------------------------------------------------------
-- operations
----------------------------------------------------------------------
_≫=maybe_ : ∀ {ℓ}{A B : Set ℓ} → maybe A → (A → maybe B) → maybe B
nothing ≫=maybe f = nothing
(just x) ≫=maybe f = f x
return-maybe : ∀ {ℓ}{A : Set ℓ} → A → maybe A
return-maybe a = just a
down-≡ : ∀{ℓ}{A : Set ℓ}{a a' : A} → just a ≡ just a' → a ≡ a'
down-≡ refl = refl
isJust : ∀{ℓ}{A : Set ℓ} → maybe A → 𝔹
isJust nothing = ff
isJust (just _) = tt
maybe-extract : ∀{ℓ}{A : Set ℓ} → (x : maybe A) → isJust x ≡ tt → A
maybe-extract (just x) p = x
maybe-extract nothing ()
maybe-map : ∀{ℓ}{A B : Set ℓ} → (A → B) → maybe A → maybe B
maybe-map f (just x) = just (f x)
maybe-map f nothing = nothing | 27.384615 | 70 | 0.430712 |
c5e85d09da68cfcddf1da4c74fa4e1a6cb60b776 | 164 | agda | Agda | examples/syntax/highlighting/Test2.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | examples/syntax/highlighting/Test2.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | examples/syntax/highlighting/Test2.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | module Test2 where
open import Test
-- Testing the inter-file goto facility.
test : ℕ
test = 12 + 34 + 56
-- Testing qualified names.
Eq = Test.Equiv {Test.ℕ}
| 12.615385 | 40 | 0.689024 |
dccceca4d9339799de95bdc6ae2205c79c57967c | 2,848 | agda | Agda | theorems/homotopy/WedgeCofiber.agda | AntoineAllioux/HoTT-Agda | 1037d82edcf29b620677a311dcfd4fc2ade2faa6 | [
"MIT"
] | 294 | 2015-01-09T16:23:23.000Z | 2022-03-20T13:54:45.000Z | theorems/homotopy/WedgeCofiber.agda | AntoineAllioux/HoTT-Agda | 1037d82edcf29b620677a311dcfd4fc2ade2faa6 | [
"MIT"
] | 31 | 2015-03-05T20:09:00.000Z | 2021-10-03T19:15:25.000Z | theorems/homotopy/WedgeCofiber.agda | AntoineAllioux/HoTT-Agda | 1037d82edcf29b620677a311dcfd4fc2ade2faa6 | [
"MIT"
] | 50 | 2015-01-10T01:48:08.000Z | 2022-02-14T03:03:25.000Z | {-# OPTIONS --without-K --rewriting #-}
open import HoTT
{- The cofiber space of [winl : X → X ∨ Y] is equivalent to [Y],
- and the cofiber space of [winr : Y → X ∨ Y] is equivalent to [X]. -}
module homotopy.WedgeCofiber {i} (X Y : Ptd i) where
module CofWinl where
module Into = CofiberRec {f = winl} (pt Y) (projr {X = X} {Y = Y}) (λ _ → idp)
into = Into.f
out : de⊙ Y → Cofiber (winl {X = X} {Y = Y})
out = cfcod ∘ winr
abstract
out-into : (κ : Cofiber (winl {X = X} {Y = Y})) → out (into κ) == κ
out-into = Cofiber-elim
(! (cfglue (pt X) ∙ ap cfcod wglue))
(Wedge-elim
(λ x → ! (cfglue (pt X) ∙ ap cfcod wglue) ∙ cfglue x)
(λ y → idp)
(↓-='-from-square $
(lemma (cfglue (pt X)) (ap cfcod wglue)
∙h⊡ (ap-∘ out projr wglue ∙ ap (ap out) (Projr.glue-β))
∙v⊡ bl-square (ap cfcod wglue))))
(λ x → ↓-∘=idf-from-square out into $
! (∙-unit-r _) ∙h⊡
ap (ap out) (Into.glue-β x) ∙v⊡
hid-square {p = (! (cfglue' winl (pt X) ∙ ap cfcod wglue))}
⊡v connection {q = cfglue x})
where
lemma : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z)
→ ! (p ∙ q) ∙ p == ! q
lemma idp idp = idp
eq : Cofiber winl ≃ de⊙ Y
eq = equiv into out (λ _ → idp) out-into
⊙eq : ⊙Cofiber ⊙winl ⊙≃ Y
⊙eq = ≃-to-⊙≃ eq idp
cfcod-winl-projr-comm-sqr : CommSquare (cfcod' winl) projr (idf _) CofWinl.into
cfcod-winl-projr-comm-sqr = comm-sqr λ _ → idp
module CofWinr where
module Into = CofiberRec {f = winr} (pt X) (projl {X = X} {Y = Y}) (λ _ → idp)
into = Into.f
out : de⊙ X → Cofiber (winr {X = X} {Y = Y})
out = cfcod ∘ winl
abstract
out-into : ∀ κ → out (into κ) == κ
out-into = Cofiber-elim
(ap cfcod wglue ∙ ! (cfglue (pt Y)))
(Wedge-elim
(λ x → idp)
(λ y → (ap cfcod wglue ∙ ! (cfglue (pt Y))) ∙ cfglue y)
(↓-='-from-square $
(ap-∘ out projl wglue ∙ ap (ap out) Projl.glue-β) ∙v⊡
connection
⊡h∙ ! (lemma (ap (cfcod' winr) wglue) (cfglue (pt Y)))))
(λ y → ↓-∘=idf-from-square out into $
! (∙-unit-r _) ∙h⊡
ap (ap out) (Into.glue-β y) ∙v⊡
hid-square {p = (ap (cfcod' winr) wglue ∙ ! (cfglue (pt Y)))}
⊡v connection {q = cfglue y})
where
lemma : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : z == y)
→ (p ∙ ! q) ∙ q == p
lemma idp idp = idp
eq : Cofiber winr ≃ de⊙ X
eq = equiv into out (λ _ → idp) out-into
⊙eq : ⊙Cofiber ⊙winr ⊙≃ X
⊙eq = ≃-to-⊙≃ eq idp
cfcod-winr-projl-comm-sqr : CommSquare (cfcod' winr) projl (idf _) CofWinr.into
cfcod-winr-projl-comm-sqr = comm-sqr λ _ → idp
| 32.735632 | 82 | 0.482444 |
10d5d48387efc521554f5d14db1a7fb0539e302d | 169 | agda | Agda | test/Fail/Issue3892.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/Issue3892.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/Issue3892.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- Andreas, 2019-07-07, issue #3892
postulate Foo : Set
data Foo where
-- WAS: internal error
-- EXPECTED:
-- Multiple definitions of Foo. Previous definition at ...
| 16.9 | 58 | 0.704142 |
205c9790bc0e58c7e2ea906563a8348ad177b443 | 335 | agda | Agda | test/Hello.agda | googleson78/cornelis | e7f6eaea4be31748929b49a925a3a9365682e9ec | [
"BSD-3-Clause"
] | null | null | null | test/Hello.agda | googleson78/cornelis | e7f6eaea4be31748929b49a925a3a9365682e9ec | [
"BSD-3-Clause"
] | null | null | null | test/Hello.agda | googleson78/cornelis | e7f6eaea4be31748929b49a925a3a9365682e9ec | [
"BSD-3-Clause"
] | null | null | null | module Hello where
data Bool : Set where
true : Bool
false : Bool
data Unit : Set where
one : Unit
unit : Unit
unit = ?
test : Bool → Bool
test x = ?
unicodeTest₁ : Bool → Bool
unicodeTest₁ x = ?
slap : Bool → Bool
slap = λ { x → ? }
module _ where
testIndent : Bool → Bool
testIndent true = ?
testIndent false = ?
| 12.407407 | 26 | 0.629851 |
d0e2b4a0949415b4f3d399c6f29bda63382029a8 | 4,729 | agda | Agda | src/Partiality-algebra/Monotone.agda | nad/partiality-monad | f69749280969f9093e5e13884c6feb0ad2506eae | [
"MIT"
] | 2 | 2020-05-21T22:59:18.000Z | 2020-07-03T08:56:08.000Z | src/Partiality-algebra/Monotone.agda | nad/partiality-monad | f69749280969f9093e5e13884c6feb0ad2506eae | [
"MIT"
] | null | null | null | src/Partiality-algebra/Monotone.agda | nad/partiality-monad | f69749280969f9093e5e13884c6feb0ad2506eae | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Monotone functions
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
module Partiality-algebra.Monotone where
open import Equality.Propositional.Cubical
open import Prelude hiding (⊥)
open import Bijection equality-with-J using (_↔_)
import Equivalence equality-with-J as Eq
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level.Closure equality-with-J
open import Partiality-algebra as PA hiding (id; _∘_)
import Partiality-algebra.Properties as PAP
-- Definition of monotone functions.
record [_⟶_]⊑
{a₁ p₁ q₁} {A₁ : Type a₁} (P₁ : Partiality-algebra p₁ q₁ A₁)
{a₂ p₂ q₂} {A₂ : Type a₂} (P₂ : Partiality-algebra p₂ q₂ A₂) :
Type (p₁ ⊔ p₂ ⊔ q₁ ⊔ q₂) where
private
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
field
function : P₁.T → P₂.T
monotone : ∀ {x y} → x P₁.⊑ y → function x P₂.⊑ function y
open [_⟶_]⊑
-- Identity.
id⊑ : ∀ {a p q} {A : Type a} {P : Partiality-algebra p q A} →
[ P ⟶ P ]⊑
function id⊑ = id
monotone id⊑ = id
-- Composition.
infixr 40 _∘⊑_
_∘⊑_ :
∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}
{a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}
{a₃ p₃ q₃} {A₃ : Type a₃} {P₃ : Partiality-algebra p₃ q₃ A₃} →
[ P₂ ⟶ P₃ ]⊑ → [ P₁ ⟶ P₂ ]⊑ → [ P₁ ⟶ P₃ ]⊑
function (f ∘⊑ g) = function f ∘ function g
monotone (f ∘⊑ g) = monotone f ∘ monotone g
-- Equality characterisation lemma for monotone functions.
equality-characterisation-monotone :
∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}
{a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}
{f g : [ P₁ ⟶ P₂ ]⊑} →
(∀ x → function f x ≡ function g x) ↔ f ≡ g
equality-characterisation-monotone {P₁ = P₁} {P₂ = P₂} {f} {g} =
(∀ x → function f x ≡ function g x) ↔⟨ Eq.extensionality-isomorphism ext ⟩
function f ≡ function g ↝⟨ ignore-propositional-component
(implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
P₂.⊑-propositional) ⟩
_↔_.to rearrange f ≡ _↔_.to rearrange g ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ rearrange) ⟩□
f ≡ g □
where
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
rearrange :
[ P₁ ⟶ P₂ ]⊑
↔
∃ λ (h : P₁.T → P₂.T) →
∀ {x y} → x P₁.⊑ y → h x P₂.⊑ h y
rearrange = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → function f , monotone f
; from = uncurry λ f m → record { function = f; monotone = m }
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
}
where
open Partiality-algebra
-- Composition is associative.
∘⊑-assoc :
∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}
{a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}
{a₃ p₃ q₃} {A₃ : Type a₃} {P₃ : Partiality-algebra p₃ q₃ A₃}
{a₄ p₄ q₄} {A₄ : Type a₄} {P₄ : Partiality-algebra p₄ q₄ A₄}
(f : [ P₃ ⟶ P₄ ]⊑) (g : [ P₂ ⟶ P₃ ]⊑) {h : [ P₁ ⟶ P₂ ]⊑} →
f ∘⊑ (g ∘⊑ h) ≡ (f ∘⊑ g) ∘⊑ h
∘⊑-assoc _ _ =
_↔_.to equality-characterisation-monotone λ _ → refl
module _
{a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}
{a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂} where
private
module P₁ = Partiality-algebra P₁
module P₂ = Partiality-algebra P₂
module PAP₁ = PAP P₁
module PAP₂ = PAP P₂
-- If a monotone function is applied to an increasing sequence,
-- then the result is another increasing sequence.
[_$_]-inc :
[ P₁ ⟶ P₂ ]⊑ → P₁.Increasing-sequence → P₂.Increasing-sequence
[ f $ s ]-inc = (λ n → function f (s P₁.[ n ]))
, (λ n → monotone f (P₁.increasing s n))
-- A lemma relating monotone functions and least upper bounds.
⨆$⊑$⨆ : (f : [ P₁ ⟶ P₂ ]⊑) →
∀ s → P₂.⨆ [ f $ s ]-inc P₂.⊑ function f (P₁.⨆ s)
⨆$⊑$⨆ f s = P₂.least-upper-bound _ _ λ n →
[ f $ s ]-inc P₂.[ n ] PAP₂.⊑⟨ monotone f (
s P₁.[ n ] PAP₁.⊑⟨ P₁.upper-bound _ _ ⟩■
P₁.⨆ s ■) ⟩■
function f (P₁.⨆ s) ■
| 34.518248 | 110 | 0.506238 |
c5df27b7349587527475155402bc4502b3f177a5 | 548 | agda | Agda | test/Succeed/Issue4893.agda | cagix/agda | cc026a6a97a3e517bb94bafa9d49233b067c7559 | [
"BSD-2-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue4893.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue4893.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | open import Agda.Primitive
variable
ℓ : Level
A : Set ℓ
P : A → Set ℓ
f : (x : A) → P x
postulate
R : (a : Level) → Set (lsuc a)
r : (a : Level) → R a
Id : (a : Level) (A : Set a) → A → A → Set a
cong₂ : (a b c : Level) (A : Set a) (B : Set b) (C : Set c) (x y : A) (u v : B)
(f : A → B → C) → Id c C (f x u) (f y v)
foo : (x y u v : A) (g : A → A) →
let a = _ in
Id a (Id _ _ _ _)
(cong₂ _ _ _ _ _ _ x y u v (λ x → f (g x)))
(cong₂ _ _ _ _ _ _ (g x) (g y) u v f)
| 24.909091 | 81 | 0.39781 |
4a9618d71d47c10172dd683ba2354c3cc0a1dc58 | 3,238 | agda | Agda | Structure/Setoid/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | 6 | 2020-04-07T17:58:13.000Z | 2022-02-05T06:53:22.000Z | Structure/Setoid/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | Structure/Setoid/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | module Structure.Setoid.Proofs where
import Lvl
open import Functional
open import Logic
open import Logic.Propositional
open import Structure.Setoid
open import Structure.Function
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
{-
module _ where
private variable ℓ ℓ₁ ℓ₂ ℓ₃ : Level
private variable A B : Type{ℓ}
private variable P : Stmt{ℓ}
Choice : (A → B → Stmt{ℓ}) → Stmt
Choice{A = A}{B = B}(_▫_) = (∀{x} → ∃(y ↦ x ▫ y)) → (∃{Obj = A → B}(f ↦ ∀{x} → (x ▫ f(x))))
module _ ⦃ choice : ∀{ℓ₁ ℓ₂ ℓ₃}{A : Type{ℓ₁}}{B : Type{ℓ₂}}{_▫_ : A → B → Stmt{ℓ₃}} → Choice(_▫_) ⦄ where
open import Data.Boolean
open import Structure.Relator.Properties
open import Structure.Relator.Properties.Proofs
open import Relator.Equals.Proofs.Equiv
thing : Stmt{ℓ} → Bool → Bool → Stmt
thing P a b = (a ≡ b) ∨ P
thing-functionallyTotal : ∀{x} → ∃(y ↦ thing P x y)
thing-functionallyTotal {x = x} = [∃]-intro x ⦃ [∨]-introₗ (reflexivity(_≡_)) ⦄
thing-choice : ∃(f ↦ ∀{x} → thing(P) x (f(x)))
thing-choice {P = P} = choice{_▫_ = thing P} thing-functionallyTotal
instance
thing-reflexivity : Reflexivity(thing(P))
Reflexivity.proof thing-reflexivity = [∨]-introₗ(reflexivity(_≡_))
instance
thing-symmetry : Symmetry(thing(P))
Symmetry.proof thing-symmetry = [∨]-elim2 (symmetry(_≡_)) id
instance
thing-transitivity : Transitivity(thing(P))
Transitivity.proof thing-transitivity ([∨]-introₗ xy) ([∨]-introₗ yz) = [∨]-introₗ (transitivity(_) xy yz)
Transitivity.proof thing-transitivity ([∨]-introₗ xy) ([∨]-introᵣ p) = [∨]-introᵣ p
Transitivity.proof thing-transitivity ([∨]-introᵣ p) _ = [∨]-introᵣ p
thing-ext : let ([∃]-intro f) = thing-choice{P = P} in ∀{a b} → thing(P) a b → (f(a) ≡ f(b))
thing-ext ([∨]-introₗ ab) = congruence₁([∃]-witness thing-choice) ab
thing-ext {a = a} {b = b} ([∨]-introᵣ p) = {!!}
thing-eq : let ([∃]-intro f) = thing-choice{P = P} in (P ↔ (f(𝐹) ≡ f(𝑇)))
_⨯_.left (thing-eq {P = P}) ft with [∃]-proof (thing-choice{P = P}){𝐹}
_⨯_.left (thing-eq {P = P}) ft | [∨]-introₗ ff = [∨]-syllogismₗ ([∃]-proof (thing-choice{P = P}){𝑇}) ((symmetry(_≢_) ⦃ negated-symmetry ⦄ ∘ [↔]-to-[←] [≢][𝑇]-is-[𝐹] ∘ symmetry(_≡_)) (transitivity(_≡_) ff ft))
_⨯_.left (thing-eq {P = P}) ft | [∨]-introᵣ p = p
_⨯_.right (thing-eq {P = P}) p = thing-ext ([∨]-introᵣ p)
bool-eq-classical : Classical₂ {X = Bool} (_≡_)
choice-to-classical : Classical(P)
excluded-middle ⦃ choice-to-classical {P = P} ⦄ with excluded-middle ⦃ bool-eq-classical {[∃]-witness (thing-choice{P = P}) 𝐹} {[∃]-witness (thing-choice{P = P}) 𝑇} ⦄
excluded-middle ⦃ choice-to-classical {P = P} ⦄ | [∨]-introₗ ft = [∨]-introₗ ([↔]-to-[←] thing-eq ft)
excluded-middle ⦃ choice-to-classical {P = P} ⦄ | [∨]-introᵣ nft = [∨]-introᵣ (nft ∘ [↔]-to-[→] thing-eq)
module _ ⦃ classical : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ where
proof-irrelevance : ∀{p₁ p₂ : P} → (p₁ ≡ p₂)
proof-irrelevance with excluded-middle
proof-irrelevance {P = P}{p₁}{p₂} | [∨]-introₗ p = {!!}
proof-irrelevance {P = P}{p₁}{p₂} | [∨]-introᵣ np = [⊥]-elim(np p₁)
-}
| 42.051948 | 212 | 0.594812 |
0ed817e2cb24f94e8f1387ea55a06de836088dd3 | 12,023 | agda | Agda | src/container/m/from-nat/coalgebra.agda | pcapriotti/agda-base | bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c | [
"BSD-3-Clause"
] | 20 | 2015-06-12T12:20:17.000Z | 2022-02-01T11:25:54.000Z | src/container/m/from-nat/coalgebra.agda | pcapriotti/agda-base | bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c | [
"BSD-3-Clause"
] | 4 | 2015-02-02T14:32:16.000Z | 2016-10-26T11:57:26.000Z | src/container/m/from-nat/coalgebra.agda | pcapriotti/agda-base | bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c | [
"BSD-3-Clause"
] | 4 | 2015-02-02T12:17:00.000Z | 2019-05-04T19:31:00.000Z | {-# OPTIONS --without-K #-}
module container.m.from-nat.coalgebra where
open import level
open import sum
open import equality
open import function
open import sets.nat.core
open import sets.nat.struct
open import sets.unit
open import container.core
open import container.m.from-nat.core
open import container.m.from-nat.cone
open import hott.level
module _ {li la lb} (c : Container li la lb) where
open Container c
open import container.m.coalgebra c hiding (_≅_; module _≅_)
Xⁱ : ℕ → I → Set (la ⊔ lb)
Xⁱ zero = λ _ → ⊤
Xⁱ (suc n) = F (Xⁱ n)
πⁱ : ∀ n → Xⁱ (suc n) →ⁱ Xⁱ n
πⁱ zero = λ _ _ → tt
πⁱ (suc n) = imap (πⁱ n)
module _ (i : I) where
X : ℕ → Set (la ⊔ lb)
X n = Xⁱ n i
π : (n : ℕ) → X (suc n) → X n
π n = πⁱ n i
open Limit X π public
open Limit-shift X π public
open F-Limit c X π public
pⁱ : (n : ℕ) → L →ⁱ Xⁱ n
pⁱ n i = p i n
βⁱ : (n : ℕ) → πⁱ n ∘ⁱ pⁱ (suc n) ≡ pⁱ n
βⁱ n = funextⁱ (λ i → β i n)
abstract
outL-iso : ∀ i → F L i ≅ L i
outL-iso i = lim-iso i ·≅ shift-iso i
outL-lem₀ : (n : ℕ)(i : I)(x : F L i)
→ p i (suc n) (apply≅ (outL-iso i) x) ≡ imap (pⁱ n) i x
outL-lem₀ n i x = refl
outL-lem₁' : (n : ℕ)(i : I)(x : F L i)
→ β i (suc n) (apply≅ (outL-iso i) x)
≡ subst₂ (λ w₁ w₀ → π i (suc n) w₁ ≡ w₀)
(sym (outL-lem₀ (suc n) i x))
(sym (outL-lem₀ n i x))
(unapΣ (refl , funext λ b → proj₂ (proj₂ x b) n ))
outL-lem₁' n i x = refl
inL : F L →ⁱ L
inL i = apply≅ (outL-iso i)
outL : L →ⁱ F L
outL i = invert≅ (outL-iso i)
in-out : inL ∘ⁱ outL ≡ idⁱ
in-out = funext λ i → funext λ x → _≅_.iso₂ (outL-iso i) x
outL-lem₁ : (n : ℕ)(i : I)(x : F L i)
→ β i (suc n) (apply≅ (outL-iso i) x)
≡ ap (π i (suc n)) (outL-lem₀ (suc n) i x)
· unapΣ (refl , funext λ b → proj₂ (proj₂ x b) n)
· sym (outL-lem₀ n i x)
outL-lem₁ n i x = outL-lem₁' n i x
· subst-lem (outL-lem₀ (suc n) i x) (outL-lem₀ n i x)
(unapΣ (refl , funext (λ b → proj₂ (proj₂ x b) n)))
where
P : X i (suc (suc n)) → X i (suc n) → Set _
P y x = π i (suc n) y ≡ x
subst-lem : {y₁ y₂ : X i (suc (suc n))}{x₁ x₂ : X i (suc n)}
→ (p : y₁ ≡ y₂)(q : x₁ ≡ x₂)
→ (z : P y₂ x₂)
→ subst₂ P (sym p) (sym q) z ≡ ap (π i (suc n)) p · z · sym q
subst-lem refl refl refl = refl
𝓛 : Coalg _
𝓛 = L , outL
module _ {ℓ} (𝓩 : Coalg ℓ) where
private
Z = proj₁ 𝓩; θ = proj₂ 𝓩
lim-coalg-iso : 𝓩 ⇒ 𝓛 ≅ ⊤
lim-coalg-iso = begin
( Σ (Z →ⁱ L) λ f → outL ∘ⁱ f ≡ step f )
≅⟨ Σ-ap-iso refl≅ eq-lem ⟩
( Σ (Z →ⁱ L) λ f → inL ∘ⁱ outL ∘ⁱ f ≡ inL ∘ⁱ step f )
≅⟨ Ψ-lem ⟩
( Σ (Z →ⁱ L) λ f → inL ∘ⁱ outL ∘ⁱ f ≡ Ψ f )
≅⟨ ( Σ-ap-iso refl≅ λ f → trans≡-iso (ap (λ h₁ → h₁ ∘ⁱ f) (sym in-out)) ) ⟩
( Σ (Z →ⁱ L) λ f → f ≡ Ψ f )
≅⟨ sym≅ (Σ-ap-iso isom λ _ → refl≅) ⟩
( Σ Cone λ c → apply≅ isom c ≡ Ψ (apply≅ isom c) )
≅⟨ ( Σ-ap-iso refl≅ λ c → trans≡-iso' (Φ-Ψ-comm c) ) ⟩
( Σ Cone λ c → apply≅ isom c ≡ apply≅ isom (Φ c) )
≅⟨ sym≅ (Σ-ap-iso refl≅ λ c → iso≡ isom ) ⟩
( Σ Cone λ c → c ≡ Φ c )
≅⟨ ( Σ-ap-iso refl≅ λ _ → refl≅ ) ⟩
( Σ Cone λ { (u , q) → (u , q) ≡ (Φ₀ u , Φ₁ u q) } )
≅⟨ (Σ-ap-iso refl≅ λ { (u , q) → sym≅ Σ-split-iso }) ⟩
( Σ Cone λ { (u , q) → Σ (u ≡ Φ₀ u) λ p → subst Cone₁ p q ≡ Φ₁ u q } )
≅⟨ record
{ to = λ { ((u , q) , p , r) → (u , p) , q , r }
; from = λ { ((u , p) , q , r) → (u , q) , p , r }
; iso₁ = λ { ((u , q) , p , r) → refl }
; iso₂ = λ { ((u , p) , q , r) → refl } } ⟩
( Σ (Σ Cone₀ λ u → u ≡ Φ₀ u) λ { (u , p)
→ Σ (Cone₁ u) λ q → subst Cone₁ p q ≡ Φ₁ u q } )
≅⟨ sym≅ ( Σ-ap-iso (sym≅ (contr-⊤-iso Fix₀-contr)) λ _ → refl≅ )
·≅ ×-left-unit ⟩
( Σ (Cone₁ u₀) λ q
→ subst Cone₁ (funext p₀) q ≡ Φ₁ u₀ q )
≅⟨ Fix₁-iso ⟩
⊤
∎
where
open cones c Xⁱ πⁱ 𝓩
X₀-contr : ∀ i → contr (X i 0)
X₀-contr i = ⊤-contr
Z→X₀-contr : contr (Z →ⁱ Xⁱ 0)
Z→X₀-contr = Π-level λ i → Π-level λ _ → X₀-contr i
step : ∀ {ly}{Y : I → Set ly} → (Z →ⁱ Y) → (Z →ⁱ F Y)
step v = imap v ∘ⁱ θ
Φ₀ : Cone₀ → Cone₀
Φ₀ u 0 = λ _ _ → tt
Φ₀ u (suc n) = step (u n)
Φ₀' : Cone → Cone₀
Φ₀' (u , q) = Φ₀ u
Φ₁ : (u : Cone₀) → Cone₁ u → Cone₁ (Φ₀ u)
Φ₁ u q zero = refl
Φ₁ u q (suc n) = ap step (q n)
Φ₁' : (c : Cone) → Cone₁ (Φ₀ (proj₁ c))
Φ₁' (u , q) = Φ₁ u q
Φ : Cone → Cone
Φ (u , q) = (Φ₀ u , Φ₁ u q)
u₀ : Cone₀
u₀ zero = λ _ _ → tt
u₀ (suc n) = step (u₀ n)
p₀ : ∀ n → u₀ n ≡ Φ₀ u₀ n
p₀ zero = refl
p₀ (suc n) = refl
Fix₀ : Set (ℓ ⊔ la ⊔ lb ⊔ li)
Fix₀ = Σ Cone₀ λ u → u ≡ Φ₀ u
Fix₁ : Fix₀ → Set (ℓ ⊔ la ⊔ lb ⊔ li)
Fix₁ (u , p) = Σ (Cone₁ u) λ q → subst Cone₁ p q ≡ Φ₁ u q
Fix₀-center : Fix₀
Fix₀-center = u₀ , funext p₀
Fix₀-iso : Fix₀ ≅ (∀ i → Z i → X i 0)
Fix₀-iso = begin
( Σ Cone₀ λ u → u ≡ Φ₀ u )
≅⟨ ( Σ-ap-iso refl≅ λ u → sym≅ strong-funext-iso ·≅ ℕ-elim-shift ) ⟩
( Σ Cone₀ λ u → (u 0 ≡ λ _ _ → tt)
× (∀ n → u (suc n) ≡ step (u n)) )
≅⟨ ( Σ-ap-iso refl≅ λ u → (×-ap-iso (contr-⊤-iso (h↑ Z→X₀-contr _ _)) refl≅)
·≅ ×-left-unit ) ⟩
( Σ Cone₀ λ u → (∀ n → u (suc n) ≡ step (u n)) )
≅⟨ Limit-op.lim-contr (λ n → Z →ⁱ Xⁱ n) (λ n → step) ⟩
(∀ i → Z i → X i 0)
∎
where open ≅-Reasoning
Fix₀-contr : contr Fix₀
Fix₀-contr = Fix₀-center , contr⇒prop
(iso-level (sym≅ Fix₀-iso) Z→X₀-contr) _
Fix₁-iso : Fix₁ Fix₀-center ≅ ⊤
Fix₁-iso = begin
( Σ (Cone₁ u₀) λ q → subst Cone₁ (funext p₀) q ≡ Φ₁ u₀ q )
≅⟨ ( Σ-ap-iso refl≅ λ q → sym≅ strong-funext-iso ) ⟩
( Σ (Cone₁ u₀) λ q → ∀ n → subst Cone₁ (funext p₀) q n ≡ Φ₁ u₀ q n )
≅⟨ ( Σ-ap-iso refl≅ λ q → Π-ap-iso refl≅ λ n
→ sym≅ (trans≡-iso (subst-lem _ _ p₀ q n)) ) ⟩
( Σ (Cone₁ u₀) λ q → ∀ n
→ subst₂ (P n) (p₀ (suc n)) (p₀ n) (q n) ≡ Φ₁ u₀ q n )
≅⟨ ( Σ-ap-iso refl≅ λ q → ℕ-elim-shift ) ⟩
( Σ (Cone₁ u₀) λ q
→ (q 0 ≡ Φ₁ u₀ q 0)
× (∀ n → q (suc n) ≡ Φ₁ u₀ q (suc n)) )
≅⟨ ( Σ-ap-iso refl≅ λ q → ×-ap-iso (contr-⊤-iso (h↑ (h↑ Z→X₀-contr _ _) _ _))
refl≅
·≅ ×-left-unit ) ⟩
( Σ (Cone₁ u₀) λ q
→ ∀ n → q (suc n) ≡ ap step (q n) )
≅⟨ Limit-op.lim-contr (λ n → πⁱ n ∘ⁱ u₀ (suc n) ≡ u₀ n) (λ n → ap step) ⟩
( πⁱ 0 ∘ⁱ u₀ 1 ≡ u₀ 0 )
≅⟨ contr-⊤-iso (h↑ Z→X₀-contr _ _) ⟩
⊤
∎
where
P = λ m x y → πⁱ m ∘ⁱ x ≡ y
subst-lem₁ : (u v : Cone₀)(p : u ≡ v)(q : Cone₁ u)(n : ℕ)
→ subst Cone₁ p q n
≡ subst₂ (P n) (funext-inv p (suc n)) (funext-inv p n) (q n)
subst-lem₁ u .u refl q n = refl
subst-lem : (u v : Cone₀)(p : ∀ n → u n ≡ v n)(q : Cone₁ u)(n : ℕ)
→ subst Cone₁ (funext p) q n
≡ subst₂ (P n) (p (suc n)) (p n) (q n)
subst-lem u v p q n = subst-lem₁ u v (funext p) q n
· ap (λ p → subst₂ (P n) (p (suc n)) (p n) (q n))
(_≅_.iso₁ strong-funext-iso p)
open ≅-Reasoning
Ψ : (Z →ⁱ L) → (Z →ⁱ L)
Ψ f = inL ∘ⁱ step f
Ψ-lem : ( Σ (Z →ⁱ L) λ f → inL ∘ⁱ outL ∘ⁱ f ≡ inL ∘ⁱ step f)
≅ ( Σ (Z →ⁱ L) λ f → inL ∘ⁱ outL ∘ⁱ f ≡ Ψ f )
Ψ-lem = Σ-ap-iso refl≅ λ f → refl≅
Φ-Ψ-comm₀ : (f : Z →ⁱ L) → ∀ n i z
→ p i n (Ψ f i z)
≡ Φ₀' (invert≅ isom f) n i z
Φ-Ψ-comm₀ f 0 i z = h1⇒prop (h↑ (X₀-contr i)) _ _
Φ-Ψ-comm₀ f (suc n) i z = outL-lem₀ n i (imap f i (θ i z))
Φ-Ψ-comm₁' : (f : Z →ⁱ L) → ∀ n i z
→ β i n (Ψ f i z)
≡ ap (π i n) (Φ-Ψ-comm₀ f (suc n) i z)
· funext-invⁱ (Φ₁' (invert≅ isom f) n) i z
· sym (Φ-Ψ-comm₀ f n i z)
Φ-Ψ-comm₁' f 0 i z = h1⇒prop (h↑ (h↑ (X₀-contr i)) _ _) _ _
Φ-Ψ-comm₁' f (suc n) i z = begin
β i (suc n) (inL i (imap f i (θ i z)))
≡⟨ outL-lem₁ n i (imap f i (θ i z)) ⟩
( ap (π i (suc n)) (Φ-Ψ-comm₀ f (suc (suc n)) i z)
· unapΣ (refl , funext λ b → β (r b) n (proj₂ (imap f i (θ i z)) b))
· sym (Φ-Ψ-comm₀ f (suc n) i z) )
≡⟨ ap (λ ω → ap (π i (suc n)) (Φ-Ψ-comm₀ f (suc (suc n)) i z)
· ω · sym (Φ-Ψ-comm₀ f (suc n) i z))
(lem (λ i x → β i n x) i z) ⟩
( ap (π i (suc n)) (Φ-Ψ-comm₀ f (suc (suc n)) i z)
· funext-invⁱ (ap step (funextⁱ (λ i z → β i n (f i z)))) i z
· sym (Φ-Ψ-comm₀ f (suc n) i z) )
∎
where
open ≡-Reasoning
lem' : {u v : L →ⁱ Xⁱ n}(ω : u ≡ v)(i : I)(z : Z i)
→ unapΣ (refl , funext λ b → funext-invⁱ ω (r b) (proj₂ (imap f i (θ i z)) b))
≡ funext-invⁱ (ap step (funextⁱ (λ i z → funext-invⁱ ω i (f i z)))) i z
lem' refl i z = begin
unapΣ (refl , funext λ b → refl)
≡⟨ ap (λ ω → unapΣ (refl , ω)) (_≅_.iso₂ strong-funext-iso refl) ⟩
refl
≡⟨ sym (ap (λ ω → funext-invⁱ (ap step ω) i z)
(_≅_.iso₂ funext-isoⁱ refl)) ⟩
funext-invⁱ (ap step (funextⁱ (λ i z → refl))) i z
∎
where
open ≡-Reasoning
lem : {u v : L →ⁱ Xⁱ n}(ω : (i : I)(x : L i) → u i x ≡ v i x)(i : I)(z : Z i)
→ unapΣ (refl , funext λ b → ω (r b) (proj₂ (imap f i (θ i z)) b))
≡ funext-invⁱ (ap step (funextⁱ (λ i z → ω i (f i z)))) i z
lem {u}{v} = invert≅ (Π-ap-iso funext-isoⁱ λ ω → refl≅) lem'
Φ-Ψ-comm₁ : (f : Z →ⁱ L) → ∀ n i z
→ funext-invⁱ (funextⁱ λ i z → β i n (Ψ f i z)) i z
≡ ap (π i n) (Φ-Ψ-comm₀ f (suc n) i z)
· funext-invⁱ (Φ₁' (invert≅ isom f) n) i z
· sym (Φ-Ψ-comm₀ f n i z)
Φ-Ψ-comm₁ f n i z = ap (λ h → h i z)
(_≅_.iso₁ funext-isoⁱ (λ i z → β i n (Ψ f i z)))
· Φ-Ψ-comm₁' f n i z
Φ-Ψ-comm' : (f : Z →ⁱ L) → invert≅ isom (Ψ f) ≡ Φ (invert≅ isom f)
Φ-Ψ-comm' f = Cone-eq (Φ-Ψ-comm₀ f) (Φ-Ψ-comm₁ f)
Φ-Ψ-comm : (c : Cone) → Ψ (apply≅ isom c) ≡ apply≅ isom (Φ c)
Φ-Ψ-comm c = sym (_≅_.iso₂ isom (Ψ (apply≅ isom c)))
· ap (apply≅ isom)
(Φ-Ψ-comm' (apply≅ isom c) · ap Φ (_≅_.iso₁ isom c))
cone-comp₀ : (f : Z →ⁱ L)(n : ℕ)(i : I)(z : Z i)
→ proj₁ (invert≅ isom (Ψ f)) n i z
≡ p i n (Ψ f i z)
cone-comp₀ f n i z = refl
cone-comp₁ : (f : Z →ⁱ L)(n : ℕ)
→ proj₂ (invert≅ isom (Ψ f)) n
≡ funextⁱ (λ i z → β i n (Ψ f i z))
cone-comp₁ f n = refl
eq-lem : (f : Z →ⁱ L) → (outL ∘ⁱ f ≡ step f)
≅ (inL ∘ⁱ outL ∘ⁱ f ≡ inL ∘ⁱ step f)
eq-lem f = iso≡ ( Π-ap-iso refl≅ λ i
→ Π-ap-iso refl≅ λ _
→ outL-iso i )
open ≅-Reasoning
lim-terminal : contr (𝓩 ⇒ 𝓛)
lim-terminal = iso-level (sym≅ lim-coalg-iso) ⊤-contr
| 37.22291 | 95 | 0.408051 |
0efd95bea92bef7aed09b0baee4b2fa311dbc66c | 1,302 | agda | Agda | src/Categories/Diagram/Pushout.agda | Trebor-Huang/agda-categories | d9e4f578b126313058d105c61707d8c8ae987fa8 | [
"MIT"
] | 5 | 2019-05-21T17:07:19.000Z | 2019-05-22T03:54:24.000Z | src/Categories/Diagram/Pushout.agda | seanpm2001/agda-categories | d9e4f578b126313058d105c61707d8c8ae987fa8 | [
"MIT"
] | null | null | null | src/Categories/Diagram/Pushout.agda | seanpm2001/agda-categories | d9e4f578b126313058d105c61707d8c8ae987fa8 | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K --safe #-}
open import Categories.Category.Core using (Category)
module Categories.Diagram.Pushout {o ℓ e} (C : Category o ℓ e) where
open Category C
open HomReasoning
open Equiv
open import Categories.Morphism.Reasoning C as Square
renaming (glue to glue-square) hiding (id-unique)
open import Level
private
variable
A B E X Y Z : Obj
f g h j : A ⇒ B
record Pushout (f : X ⇒ Y) (g : X ⇒ Z) : Set (o ⊔ ℓ ⊔ e) where
field
{Q} : Obj
i₁ : Y ⇒ Q
i₂ : Z ⇒ Q
field
commute : i₁ ∘ f ≈ i₂ ∘ g
universal : {h₁ : Y ⇒ B} {h₂ : Z ⇒ B} → h₁ ∘ f ≈ h₂ ∘ g → Q ⇒ B
unique : {h₁ : Y ⇒ E} {h₂ : Z ⇒ E} {j : Q ⇒ E} {eq : h₁ ∘ f ≈ h₂ ∘ g} →
j ∘ i₁ ≈ h₁ → j ∘ i₂ ≈ h₂ →
j ≈ universal eq
universal∘i₁≈h₁ : {h₁ : Y ⇒ E} {h₂ : Z ⇒ E} {eq : h₁ ∘ f ≈ h₂ ∘ g} →
universal eq ∘ i₁ ≈ h₁
universal∘i₂≈h₂ : {h₁ : Y ⇒ E} {h₂ : Z ⇒ E} {eq : h₁ ∘ f ≈ h₂ ∘ g} →
universal eq ∘ i₂ ≈ h₂
unique-diagram : h ∘ i₁ ≈ j ∘ i₁ →
h ∘ i₂ ≈ j ∘ i₂ →
h ≈ j
unique-diagram {h = h} {j = j} eq₁ eq₂ = begin
h ≈⟨ unique eq₁ eq₂ ⟩
universal eq ≈˘⟨ unique refl refl ⟩
j ∎
where eq = extendˡ commute
| 27.702128 | 78 | 0.476959 |
0e9264be68f7f26e811519ba29cd8eb2fe6877d1 | 601 | agda | Agda | src/TemporalOps/Common/Other.agda | DimaSamoz/temporal-type-systems | 7d993ba55e502d5ef8707ca216519012121a08dd | [
"MIT"
] | 4 | 2018-05-31T20:37:04.000Z | 2022-01-04T09:33:48.000Z | src/TemporalOps/Common/Other.agda | DimaSamoz/temporal-type-systems | 7d993ba55e502d5ef8707ca216519012121a08dd | [
"MIT"
] | null | null | null | src/TemporalOps/Common/Other.agda | DimaSamoz/temporal-type-systems | 7d993ba55e502d5ef8707ca216519012121a08dd | [
"MIT"
] | null | null | null |
{- Other common operations and lemmas. -}
module TemporalOps.Common.Other where
open import Relation.Binary.HeterogeneousEquality as ≅ hiding (inspect)
open import Relation.Binary.PropositionalEquality hiding (inspect)
-- Time indexing (for clarity, synonym of function appliation at any level)
_at_ : ∀ {a b} {A : Set a} {B : A → Set b} →
((x : A) → B x) → ((x : A) → B x)
f at n = f n
infixl 45 _at_
-- Inspect idiom
data Singleton {a} {A : Set a} (x : A) : Set a where
_with≡_ : (y : A) → x ≡ y → Singleton x
inspect : ∀ {a} {A : Set a} (x : A) → Singleton x
inspect x = x with≡ refl
| 28.619048 | 75 | 0.643927 |
23e4ce3007eb989d68cabd25f5f05653d961174a | 3,166 | agda | Agda | out/UTLC/Syntax.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 39 | 2021-11-09T20:39:55.000Z | 2022-03-19T17:33:12.000Z | out/UTLC/Syntax.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 1 | 2021-11-21T12:19:32.000Z | 2021-11-21T12:19:32.000Z | out/UTLC/Syntax.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 4 | 2021-11-09T20:39:59.000Z | 2022-01-24T12:49:17.000Z | {-
This second-order term syntax was created from the following second-order syntax description:
syntax UTLC | Λ
type
* : 0-ary
term
app : * * -> * | _$_ l20
lam : *.* -> * | ƛ_ r10
theory
(ƛβ) b : *.* a : * |> app (lam (x.b[x]), a) = b[a]
(ƛη) f : * |> lam (x.app (f, x)) = f
(lβ) b : *.* a : * |> letd (a, x. b) = b[a]
-}
module UTLC.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import UTLC.Signature
private
variable
Γ Δ Π : Ctx
α : *T
𝔛 : Familyₛ
-- Inductive term declaration
module Λ:Terms (𝔛 : Familyₛ) where
data Λ : Familyₛ where
var : ℐ ⇾̣ Λ
mvar : 𝔛 α Π → Sub Λ Π Γ → Λ α Γ
_$_ : Λ * Γ → Λ * Γ → Λ * Γ
ƛ_ : Λ * (* ∙ Γ) → Λ * Γ
infixl 20 _$_
infixr 10 ƛ_
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
Λᵃ : MetaAlg Λ
Λᵃ = record
{ 𝑎𝑙𝑔 = λ where
(appₒ ⋮ a , b) → _$_ a b
(lamₒ ⋮ a) → ƛ_ a
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module Λᵃ = MetaAlg Λᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : Λ ⇾̣ 𝒜
𝕊 : Sub Λ Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 (_$_ a b) = 𝑎𝑙𝑔 (appₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞 (ƛ_ a) = 𝑎𝑙𝑔 (lamₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Λᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ Λ α Γ) → 𝕤𝕖𝕞 (Λᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (appₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (lamₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ Λ ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : Λ ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Λᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : Λ α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub Λ Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! (_$_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (ƛ_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
Λ:Syn : Syntax
Λ:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = Λ:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open Λ:Terms 𝔛 in record
{ ⊥ = Λ ⋉ Λᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax Λ:Syn public
open Λ:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands Λᵃ public
open import SOAS.Metatheory Λ:Syn public
-- Derived operations
letd : Λ 𝔛 * Γ → Λ 𝔛 * (* ∙ Γ) → Λ 𝔛 * Γ
letd a b = (ƛ b) $ a
| 24.542636 | 93 | 0.520846 |
df010b3202fe630f912cd06312b3416397d508af | 707 | agda | Agda | formalization/Data/Nat/Literal.agda | brunoczim/Celeste | 9f5129d97ee7b89fb8e43136779a78806b7506ab | [
"MIT"
] | 1 | 2020-09-16T17:31:57.000Z | 2020-09-16T17:31:57.000Z | formalization/Data/Nat/Literal.agda | brunoczim/Celeste | 9f5129d97ee7b89fb8e43136779a78806b7506ab | [
"MIT"
] | null | null | null | formalization/Data/Nat/Literal.agda | brunoczim/Celeste | 9f5129d97ee7b89fb8e43136779a78806b7506ab | [
"MIT"
] | null | null | null | module Data.Nat.Literal where
open import Data.Nat using (ℕ; suc; zero)
open import Data.Fin using (Fin; suc; zero)
open import Data.Unit using (⊤)
open import Data.Empty using (⊥)
open import Agda.Builtin.FromNat using (Number; fromNat) public
_≤_ : ℕ → ℕ → Set
zero ≤ n = ⊤
suc m ≤ zero = ⊥
suc m ≤ suc n = m ≤ n
instance
ℕ-num : Number ℕ
ℕ-num .Number.Constraint _ = ⊤
ℕ-num .Number.fromNat n = n
instance
Fin-num : {n : ℕ} → Number (Fin (suc n))
Fin-num {n} .Number.Constraint m = m ≤ n
Fin-num {n} .Number.fromNat m ⦃ p ⦄ = from m n p where
from : (m n : ℕ) → m ≤ n → Fin (suc n)
from zero _ _ = zero
from (suc _) zero ()
from (suc m) (suc n) p = suc (from m n p)
| 26.185185 | 63 | 0.606789 |
cbc438889e740731d837f77c353d71de24c90c4d | 219 | agda | Agda | src/data/lib/prim/Agda/Builtin/IO.agda | pthariensflame/agda | 222c4c64b2ccf8e0fc2498492731c15e8fef32d4 | [
"BSD-3-Clause"
] | null | null | null | src/data/lib/prim/Agda/Builtin/IO.agda | pthariensflame/agda | 222c4c64b2ccf8e0fc2498492731c15e8fef32d4 | [
"BSD-3-Clause"
] | null | null | null | src/data/lib/prim/Agda/Builtin/IO.agda | pthariensflame/agda | 222c4c64b2ccf8e0fc2498492731c15e8fef32d4 | [
"BSD-3-Clause"
] | null | null | null | {-# OPTIONS --without-K #-}
module Agda.Builtin.IO where
postulate IO : ∀ {a} → Set a → Set a
{-# BUILTIN IO IO #-}
{-# HASKELL type AgdaIO a b = IO b #-}
{-# COMPILED_TYPE IO MAlonzo.Code.Agda.Builtin.IO.AgdaIO #-}
| 21.9 | 60 | 0.625571 |
cb373bbc3115c87b123d89fd702b30889277fe8f | 761 | agda | Agda | main/Graphs/Properties.agda | awswan/nielsenschreier-hott | 84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d | [
"MIT"
] | null | null | null | main/Graphs/Properties.agda | awswan/nielsenschreier-hott | 84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d | [
"MIT"
] | null | null | null | main/Graphs/Properties.agda | awswan/nielsenschreier-hott | 84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K --exact-split --rewriting #-}
open import lib.Basics
open import lib.NConnected
open import Graphs.Definition
open import Coequalizers.Definition
{- We will consider two properties of graphs: if they are trees and if they are connected,
both are defined in terms of the geometric realisation (coequalizer). -}
module Graphs.Properties where
{- A graph is a tree if its coequalizer is contractible. -}
is-tree : {i j : ULevel} {E : Type i} {V : Type j} ( gph : Graph E V ) → Type (lmax i j)
is-tree gph = is-contr (Coeq gph)
{- A graph is connected if its coequalizer is connected. -}
gph-is-connected : {i j : ULevel} {E : Type i} {V : Type j} (gph : Graph E V) → Type (lmax i j)
gph-is-connected gph = is-connected 0 (Coeq gph)
| 38.05 | 95 | 0.701708 |
cb5aaea3c61879cf3492b9a1b3ff4e85025c37ed | 587 | agda | Agda | test/Succeed/Issue1207.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue1207.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue1207.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
open import Common.Level
open import Common.Prelude
open import Common.Reflection
open import Common.Equality
postulate
a b : Level
data Check : Set where
check : (x y : Term) → x ≡ y → Check
pattern _==_ x y = check x y refl
pattern `a = def (quote a) []
pattern `b = def (quote b) []
pattern `suc x = def (quote lsuc) (vArg x ∷ [])
pattern _`⊔_ x y = def (quote _⊔_) (vArg x ∷ vArg y ∷ [])
t₀ = quoteTerm Set₃ == sort (lit 3)
t₁ = quoteTerm (Set a) == sort (set `a)
t₂ = quoteTerm (Set (lsuc b)) == sort (set (`suc `b))
t₃ = quoteTerm (Set (a ⊔ b)) == sort (set (`a `⊔ `b))
| 24.458333 | 57 | 0.614991 |
dffde1ba9182c6750cd086971b51dc3b828c8cdb | 1,080 | agda | Agda | theorems/homotopy/RelativelyConstantToSetExtendsViaSurjection.agda | mikeshulman/HoTT-Agda | e7d663b63d89f380ab772ecb8d51c38c26952dbb | [
"MIT"
] | null | null | null | theorems/homotopy/RelativelyConstantToSetExtendsViaSurjection.agda | mikeshulman/HoTT-Agda | e7d663b63d89f380ab772ecb8d51c38c26952dbb | [
"MIT"
] | null | null | null | theorems/homotopy/RelativelyConstantToSetExtendsViaSurjection.agda | mikeshulman/HoTT-Agda | e7d663b63d89f380ab772ecb8d51c38c26952dbb | [
"MIT"
] | 1 | 2018-12-26T21:31:57.000Z | 2018-12-26T21:31:57.000Z | {-# OPTIONS --without-K --rewriting #-}
open import HoTT
import homotopy.ConstantToSetExtendsToProp as ConstExt
module homotopy.RelativelyConstantToSetExtendsViaSurjection
{i j k} {A : Type i} {B : Type j} {C : B → Type k}
(C-is-set : ∀ b → is-set (C b))
(f : A → B) (f-is-surj : is-surj f)
(g : (a : A) → C (f a))
(g-is-const : ∀ a₁ a₂ → (p : f a₁ == f a₂) → g a₁ == g a₂ [ C ↓ p ])
where
{-
(b : A) ----> [ hfiber f b ] ----?----> C ?
^
|
hfiber f b
-}
private
lemma : ∀ b → hfiber f b → C b
lemma b (a , fa=b) = transport C fa=b (g a)
lemma-const : ∀ b → (h₁ h₂ : hfiber f b) → lemma b h₁ == lemma b h₂
lemma-const ._ (a₁ , fa₁=fa₂) (a₂ , idp) =
to-transp (g-is-const a₁ a₂ fa₁=fa₂)
module CE (b : B) =
ConstExt {A = hfiber f b} {B = C b}
(C-is-set b) (lemma b) (lemma-const b)
ext : Π B C
ext b = CE.ext b (f-is-surj b)
β : (a : A) → ext (f a) == g a
β a = ap (CE.ext (f a))
(prop-has-all-paths Trunc-level (f-is-surj (f a)) [ a , idp ])
| 27.692308 | 71 | 0.489815 |
dfd178210cefdfe56608da8363fa8834c22d34c9 | 5,188 | agda | Agda | test/Instances.agda | mchristianl/synthetic-reals | 10206b5c3eaef99ece5d18bf703c9e8b2371bde4 | [
"MIT"
] | 3 | 2020-07-31T18:15:26.000Z | 2022-02-19T12:15:21.000Z | test/Instances.agda | mchristianl/synthetic-reals | 10206b5c3eaef99ece5d18bf703c9e8b2371bde4 | [
"MIT"
] | null | null | null | test/Instances.agda | mchristianl/synthetic-reals | 10206b5c3eaef99ece5d18bf703c9e8b2371bde4 | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --no-import-sorts --prop #-}
module Instances where
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ)
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Relation.Binary.Base
open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Foundations.Logic
open import Agda.Builtin.Equality renaming (_≡_ to _≡ᵢ_; refl to reflₚ)
variable
ℓ ℓ' ℓ'' : Level
-- hProp is just the propertie's target type A with ≡ for all inhabitants attached
_ : (hProp ℓ) ≡ (Σ[ A ∈ Type ℓ ] (∀(x y : A) → x ≡ y))
_ = refl
_ : (hProp ℓ) ≡ (Σ[ A ∈ Type ℓ ] isProp A)
_ = refl
-- PropRel is just the relation R with ≡ for all inhabitants of all target types R a b attached
PropRel' : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
PropRel' A B ℓ' = Σ[ R ∈ Rel A B ℓ' ] ∀ a b → isProp (R a b)
#-coerceₚ' : ∀{ℓ'} → {P Q : hProp ℓ'} → [ P ] → {{[ P ] ≡ [ Q ]}} → [ Q ]
#-coerceₚ' {ℓ} {[p] , p-isProp} {[q] , q-isProp} p {{ p≡q }} = transport p≡q p
path-to-id : ∀{ℓ} {A : Type ℓ} {x y : A} → x ≡ y → x ≡ᵢ y
path-to-id p = {!!}
-- just for the explanation
record PoorField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
F : Type ℓ
0f 1f : F
_#_ : Rel F F ℓ'
#-isprop : ∀ x y → isProp (x # y)
instance
#-isprop' : ∀{x y} {p q : x # y} → p ≡ q -- could we use this in some way?
-- #-rel : PropRel F F ℓ'
_#ₚ_ : F → F → hProp ℓ'
x #ₚ y = (x # y) , #-isprop x y
-- NOTE: this creates a `Goal: fst #-rel ...` everywhere
-- we might just separate the relation from the isprop
-- i.e. directly define _#_ and #-isprop
-- _#_ = fst #-rel
-- #-isprop = snd #-rel
-- NOTE: there is an email on the agda mailing list 08.11.18, 21:16 by Martin Escardo "I want implicit coercions in Agda"
-- although this email thread is about more general coercions which are not straight forward, where hProp should be less of an issue
#-coerce : ∀{ℓ x y} → ∀{p q} {R : x # y → Type ℓ} → R p → R q
#-coerce {ℓ} {x} {y} {p} {q} {R} rp = transport (cong R (#-isprop x y p q))rp
#-coerceₚ : ∀{ℓ x y} → ∀{p q} {R : [ x #ₚ y ] → Type ℓ} → R p → R q
#-coerceₚ {ℓ} {x} {y} {p} {q} {R} rp = transport (cong R (#-isprop x y p q)) rp
field
_+_ _·_ : F → F → F
_⁻¹ᶠ : (x : F) → {{ x # 0f }} → F
·-rinv : (x : F) → (p : x # 0f) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f
-- for the purposes of explanation we just assume two different proofs of `1 # 0`
1#0 : 1f # 0f
1#0' : 1f # 0f
-- maybe there is some clever way to define _⁻¹ᶠ in a way where it accepts different proofs
_⁻¹ᶠ' : (x : F) → {{ [ x #ₚ 0f ] }} → F
·-rinv' : (x : F) → (p : [ x #ₚ 0f ]) → x · (_⁻¹ᶠ' x {{p}}) ≡ 1f
1#0ₚ : [ 1f #ₚ 0f ]
1#0ₚ' : [ 1f #ₚ 0f ]
_⁻¹ᶠ'' : (x : F) → {{ [ x #ₚ 0f ] }} → F
-- infix 9 _⁻¹ᶠ
-- infixl 7 _·_
-- infixl 5 _+_
-- infixl 4 _#_
module test-hProp (PF : PoorField {ℓ} {ℓ'}) where
open PoorField PF
-- of course, this works
test0 : let instance _ = 1#0 in 1f · (1f ⁻¹ᶠ) ≡ 1f
test0 = ·-rinv 1f 1#0
-- now, we try passing in 1#0'
test1 : let instance _ = 1#0 in 1f · (1f ⁻¹ᶠ) ≡ 1f
-- ERROR:
-- PoorField.1#0' /= PoorField.1#0
-- when checking that the expression 1#0' has type fst #-rel 1f 0f
test1 = ·-rinv 1f ( #-coerceₚ {_} {1f} {0f} {_} {_} {_} 1#0')
-- #-coerce seems to have troubles resolving the R
test2 : let instance _ = 1#0 in 1f · (1f ⁻¹ᶠ) ≡ 1f
-- ERROR:
-- Failed to solve the following constraints:
-- _R_161 _q_160 =< (1f · (1f ⁻¹ᶠ)) ≡ 1f
-- (1f · (1f ⁻¹ᶠ)) ≡ 1f =< _R_161 _p_159
test2 = #-coerce (·-rinv 1f 1#0') -- this line is yellow in emacs
-- it works when we give R explicitly
test3 : let instance _ = 1#0 in 1f · (1f ⁻¹ᶠ) ≡ 1f
test3 = #-coerce {R = λ r → 1f · (_⁻¹ᶠ 1f {{r}}) ≡ 1f} (·-rinv 1f 1#0')
-- a different "result" of this consideration might be that Goals involving hProp-instances need to be formulated in a different way
test4 : let instance _ = 1#0ₚ in 1f · (1f ⁻¹ᶠ') ≡ 1f
test4 = ·-rinv' 1f ( #-coerceₚ' 1#0ₚ' {{{!!}}} )
test5 : let instance _ = 1#0ₚ in 1f · (1f ⁻¹ᶠ') ≡ 1f
test5 with 1#0ₚ' | path-to-id {ℓ'} {x = 1#0ₚ} {y = 1#0ₚ'} (#-isprop 1f 0f 1#0ₚ 1#0ₚ')
... | .(PoorField.1#0ₚ PF) | reflₚ = {! ·-rinv' 1f 1#0ₚ' !}
-- when using Prop this would be less of an issue
-- but how does it interact with the hProp based cubical library?
record ImpredicativePoorField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
F : Type ℓ
0f 1f : F
_#_ : F → F → Prop ℓ'
_+_ _·_ : F → F → F
_⁻¹ᶠ : (x : F) → {{ x # 0f }} → F
·-rinv : (x : F) → (p : x # 0f) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f
-- for the purposes of explanation we just assume two different proofs of `1 # 0`
1#0 : 1f # 0f
1#0' : 1f # 0f
module test-impredicative (PF : ImpredicativePoorField {ℓ} {ℓ'}) where
open ImpredicativePoorField PF
-- now, we try passing in 1#0'
test1 : let instance _ = 1#0 in 1f · (1f ⁻¹ᶠ) ≡ 1f
test1 = ·-rinv 1f 1#0' -- just works
| 36.27972 | 140 | 0.559753 |
3915a009c16b36f12099e7bdf0b8140d893b6279 | 29,943 | agda | Agda | src/FOmegaInt/Typing.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | null | null | null | src/FOmegaInt/Typing.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | null | null | null | src/FOmegaInt/Typing.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Typing and kinding of Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Typing where
open import Data.Context.WellFormed
open import Data.Fin using (Fin; zero)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Fin.Substitution.Typed
open import Data.Nat using (ℕ)
open import Data.Product using (_,_; _×_)
open import Level using () renaming (zero to lzero)
open import Relation.Binary.PropositionalEquality as PropEq hiding ([_])
open import FOmegaInt.Syntax
------------------------------------------------------------------------
-- Typing derivations.
module Typing where
open TermCtx
open Syntax
open Substitution using (_[_]; _Kind[_]; weaken)
infix 4 _ctx _⊢_kd _⊢_wf
infix 4 _⊢Tp_∈_ _⊢Tm_∈_ _⊢_∈_
infix 4 _⊢_<:_∈_ _⊢_<∷_ _⊢_≤_
infix 4 _⊢_≃_∈_ _⊢_≅_ _⊢_≃_wf _≃_ctx
mutual
-- Well-formed typing contexts.
_ctx : ∀ {n} → Ctx n → Set
_ctx = ContextFormation._wf _⊢_wf
-- Well-formed type/kind ascriptions in typing contexts.
data _⊢_wf {n} (Γ : Ctx n) : TermAsc n → Set where
wf-kd : ∀ {a} → Γ ⊢ a kd → Γ ⊢ (kd a) wf
wf-tp : ∀ {a} → Γ ⊢Tp a ∈ * → Γ ⊢ (tp a) wf
-- Well-formed kinds.
data _⊢_kd {n} (Γ : Ctx n) : Kind Term n → Set where
kd-⋯ : ∀ {a b} → Γ ⊢Tp a ∈ * → Γ ⊢Tp b ∈ * → Γ ⊢ a ⋯ b kd
kd-Π : ∀ {j k} → Γ ⊢ j kd → kd j ∷ Γ ⊢ k kd → Γ ⊢ Π j k kd
-- Kinding derivations.
data _⊢Tp_∈_ {n} (Γ : Ctx n) : Term n → Kind Term n → Set where
∈-var : ∀ {k} x → Γ ctx → lookup Γ x ≡ kd k → Γ ⊢Tp var x ∈ k
∈-⊥-f : Γ ctx → Γ ⊢Tp ⊥ ∈ *
∈-⊤-f : Γ ctx → Γ ⊢Tp ⊤ ∈ *
∈-∀-f : ∀ {k a} → Γ ⊢ k kd → kd k ∷ Γ ⊢Tp a ∈ * → Γ ⊢Tp Π k a ∈ *
∈-→-f : ∀ {a b} → Γ ⊢Tp a ∈ * → Γ ⊢Tp b ∈ * → Γ ⊢Tp a ⇒ b ∈ *
∈-Π-i : ∀ {j a k} → Γ ⊢ j kd → kd j ∷ Γ ⊢Tp a ∈ k →
Γ ⊢Tp Λ j a ∈ Π j k
∈-Π-e : ∀ {a b j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢Tp b ∈ j →
Γ ⊢Tp a · b ∈ k Kind[ b ]
∈-s-i : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢Tp a ∈ a ⋯ a
∈-⇑ : ∀ {a j k} → Γ ⊢Tp a ∈ j → Γ ⊢ j <∷ k → Γ ⊢Tp a ∈ k
-- Subkinding derivations.
data _⊢_<∷_ {n} (Γ : Ctx n) : Kind Term n → Kind Term n → Set where
<∷-⋯ : ∀ {a₁ a₂ b₁ b₂} →
Γ ⊢ a₂ <: a₁ ∈ * → Γ ⊢ b₁ <: b₂ ∈ * → Γ ⊢ a₁ ⋯ b₁ <∷ a₂ ⋯ b₂
<∷-Π : ∀ {j₁ j₂ k₁ k₂} →
Γ ⊢ j₂ <∷ j₁ → kd j₂ ∷ Γ ⊢ k₁ <∷ k₂ → Γ ⊢ Π j₁ k₁ kd →
Γ ⊢ Π j₁ k₁ <∷ Π j₂ k₂
-- Subtyping derivations.
data _⊢_<:_∈_ {n} (Γ : Ctx n) : Term n → Term n → Kind Term n → Set where
<:-refl : ∀ {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a <: a ∈ k
<:-trans : ∀ {a b c k} → Γ ⊢ a <: b ∈ k → Γ ⊢ b <: c ∈ k → Γ ⊢ a <: c ∈ k
<:-β₁ : ∀ {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j →
Γ ⊢ (Λ j a) · b <: a [ b ] ∈ k Kind[ b ]
<:-β₂ : ∀ {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j →
Γ ⊢ a [ b ] <: (Λ j a) · b ∈ k Kind[ b ]
<:-η₁ : ∀ {a j k} → Γ ⊢Tp a ∈ Π j k →
Γ ⊢ Λ j (weaken a · var zero) <: a ∈ Π j k
<:-η₂ : ∀ {a j k} → Γ ⊢Tp a ∈ Π j k →
Γ ⊢ a <: Λ j (weaken a · var zero) ∈ Π j k
<:-⊥ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ ⊥ <: a ∈ *
<:-⊤ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ a <: ⊤ ∈ *
<:-∀ : ∀ {k₁ k₂ a₁ a₂} →
Γ ⊢ k₂ <∷ k₁ → kd k₂ ∷ Γ ⊢ a₁ <: a₂ ∈ * → Γ ⊢Tp Π k₁ a₁ ∈ * →
Γ ⊢ Π k₁ a₁ <: Π k₂ a₂ ∈ *
<:-→ : ∀ {a₁ a₂ b₁ b₂} → Γ ⊢ a₂ <: a₁ ∈ * → Γ ⊢ b₁ <: b₂ ∈ * →
Γ ⊢ a₁ ⇒ b₁ <: a₂ ⇒ b₂ ∈ *
<:-λ : ∀ {j₁ j₂ a₁ a₂ j k} → kd j ∷ Γ ⊢ a₁ <: a₂ ∈ k →
Γ ⊢Tp Λ j₁ a₁ ∈ Π j k → Γ ⊢Tp Λ j₂ a₂ ∈ Π j k →
Γ ⊢ Λ j₁ a₁ <: Λ j₂ a₂ ∈ Π j k
<:-· : ∀ {a₁ a₂ b₁ b₂ j k} → Γ ⊢ a₁ <: a₂ ∈ Π j k → Γ ⊢ b₁ ≃ b₂ ∈ j →
Γ ⊢ a₁ · b₁ <: a₂ · b₂ ∈ k Kind[ b₁ ]
<:-⟨| : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ b <: a ∈ *
<:-|⟩ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ a <: c ∈ *
<:-⋯-i : ∀ {a b c d} → Γ ⊢ a <: b ∈ c ⋯ d → Γ ⊢ a <: b ∈ a ⋯ b
<:-⇑ : ∀ {a b j k} → Γ ⊢ a <: b ∈ j → Γ ⊢ j <∷ k → Γ ⊢ a <: b ∈ k
-- Type equality.
data _⊢_≃_∈_ {n} (Γ : Ctx n) : Term n → Term n → Kind Term n → Set where
<:-antisym : ∀ {a b k} → Γ ⊢ a <: b ∈ k → Γ ⊢ b <: a ∈ k → Γ ⊢ a ≃ b ∈ k
-- Kind equality.
data _⊢_≅_ {n} (Γ : Ctx n) : Kind Term n → Kind Term n → Set where
<∷-antisym : ∀ {j k} → Γ ⊢ j <∷ k → Γ ⊢ k <∷ j → Γ ⊢ j ≅ k
-- Typing derivations.
data _⊢Tm_∈_ {n} (Γ : Ctx n) : Term n → Term n → Set where
∈-var : ∀ {a} x → Γ ctx → lookup Γ x ≡ tp a → Γ ⊢Tm var x ∈ a
∈-∀-i : ∀ {k a b} → Γ ⊢ k kd → kd k ∷ Γ ⊢Tm a ∈ b →
Γ ⊢Tm Λ k a ∈ Π k b
∈-→-i : ∀ {a b c} → Γ ⊢Tp a ∈ * → tp a ∷ Γ ⊢Tm b ∈ weaken c →
-- NOTE. The following premise is a redundant validity
-- condition that could be avoided by proving a context
-- strengthening lemma (showing that unused variables,
-- i.e. variables not appearing freely to the right of the
-- turnstyle, can be eliminated from the context).
Γ ⊢Tp c ∈ * →
Γ ⊢Tm ƛ a b ∈ a ⇒ c
∈-∀-e : ∀ {a b k c} → Γ ⊢Tm a ∈ Π k c → Γ ⊢Tp b ∈ k →
Γ ⊢Tm a ⊡ b ∈ c [ b ]
∈-→-e : ∀ {a b c d} → Γ ⊢Tm a ∈ c ⇒ d → Γ ⊢Tm b ∈ c →
Γ ⊢Tm a · b ∈ d
∈-⇑ : ∀ {a b c} → Γ ⊢Tm a ∈ b → Γ ⊢ b <: c ∈ * → Γ ⊢Tm a ∈ c
-- Combined typing and kinding of terms and types.
data _⊢_∈_ {n} (Γ : Ctx n) : Term n → TermAsc n → Set where
∈-tp : ∀ {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a ∈ kd k
∈-tm : ∀ {a b} → Γ ⊢Tm a ∈ b → Γ ⊢ a ∈ tp b
-- Combined subtyping and subkinding.
data _⊢_≤_ {n} (Γ : Ctx n) : TermAsc n → TermAsc n → Set where
≤-<∷ : ∀ {j k} → Γ ⊢ j <∷ k → Γ ⊢ kd j ≤ kd k
≤-<: : ∀ {a b} → Γ ⊢ a <: b ∈ * → Γ ⊢ tp a ≤ tp b
mutual
-- Combined kind and type equality, i.e. equality of well-formed
-- ascriptions.
data _⊢_≃_wf {n} (Γ : Ctx n) : TermAsc n → TermAsc n → Set where
≃wf-≅ : ∀ {j k} → Γ ⊢ j ≅ k → Γ ⊢ kd j ≃ kd k wf
≃wf-≃ : ∀ {a b} → Γ ⊢ a ≃ b ∈ * → Γ ⊢ tp a ≃ tp b wf
-- Equality of well-formed contexts.
data _≃_ctx : ∀ {n} → Ctx n → Ctx n → Set where
≃-[] : [] ≃ [] ctx
≃-∷ : ∀ {n a b} {Γ Δ : Ctx n} →
Γ ⊢ a ≃ b wf → Γ ≃ Δ ctx → a ∷ Γ ≃ b ∷ Δ ctx
open PropEq using ([_])
-- A derived variable rule.
∈-var′ : ∀ {n} {Γ : Ctx n} x → Γ ctx → Γ ⊢ var x ∈ lookup Γ x
∈-var′ {Γ = Γ} x Γ-ctx with lookup Γ x | inspect (lookup Γ) x
∈-var′ x Γ-ctx | kd k | [ Γ[x]≡kd-k ] = ∈-tp (∈-var x Γ-ctx Γ[x]≡kd-k)
∈-var′ x Γ-ctx | tp a | [ Γ[x]≡tp-a ] = ∈-tm (∈-var x Γ-ctx Γ[x]≡tp-a)
-- A derived subsumption rule.
∈-⇑′ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a ∈ b → Γ ⊢ b ≤ c → Γ ⊢ a ∈ c
∈-⇑′ (∈-tp a∈b) (≤-<∷ b<∷c) = ∈-tp (∈-⇑ a∈b b<∷c)
∈-⇑′ (∈-tm a∈b) (≤-<: b<:c) = ∈-tm (∈-⇑ a∈b b<:c)
open ContextFormation _⊢_wf public
hiding (_wf) renaming (_⊢_wfExt to _⊢_ext)
------------------------------------------------------------------------
-- Properties of typings
open Syntax
open TermCtx
open Typing
-- Inversion lemmas for _⊢_wf.
wf-kd-inv : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ kd k wf → Γ ⊢ k kd
wf-kd-inv (wf-kd k-kd) = k-kd
wf-tp-inv : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ tp a wf → Γ ⊢Tp a ∈ *
wf-tp-inv (wf-tp a∈*) = a∈*
-- An inversion lemma for _⊢_≃_wf.
≃wf-kd-inv : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ kd j ≃ kd k wf → Γ ⊢ j ≅ k
≃wf-kd-inv (≃wf-≅ j≅k) = j≅k
-- Kind and type equality imply subkinding and subtyping, respectively.
≅⇒<∷ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ j <∷ k
≅⇒<∷ (<∷-antisym j<∷k k<∷j) = j<∷k
≃⇒<: : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ a <: b ∈ k
≃⇒<: (<:-antisym a<:b b<:a) = a<:b
-- Reflexivity of subkinding.
<∷-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k <∷ k
<∷-refl (kd-⋯ a∈* b∈*) = <∷-⋯ (<:-refl a∈*) (<:-refl b∈*)
<∷-refl (kd-Π j-kd k-kd) = <∷-Π (<∷-refl j-kd) (<∷-refl k-kd) (kd-Π j-kd k-kd)
-- Reflexivity of kind equality.
≅-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k ≅ k
≅-refl k-kd = <∷-antisym (<∷-refl k-kd) (<∷-refl k-kd)
-- Symmetry of kind equality.
≅-sym : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ k ≅ j
≅-sym (<∷-antisym j<∷k k<∷j) = <∷-antisym k<∷j j<∷k
-- An admissible kind equality rule for interval kinds.
≅-⋯ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂} →
Γ ⊢ a₁ ≃ a₂ ∈ * → Γ ⊢ b₁ ≃ b₂ ∈ * → Γ ⊢ a₁ ⋯ b₁ ≅ a₂ ⋯ b₂
≅-⋯ (<:-antisym a₁<:a₂ a₂<:a₁) (<:-antisym b₁<:b₂ b₂<:b₁) =
<∷-antisym (<∷-⋯ a₂<:a₁ b₁<:b₂) (<∷-⋯ a₁<:a₂ b₂<:b₁)
-- Type equality is reflexive.
≃-refl : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a ≃ a ∈ k
≃-refl a∈k = <:-antisym (<:-refl a∈k) (<:-refl a∈k)
-- Type equality is transitive.
≃-trans : ∀ {n} {Γ : Ctx n} {a b c k} →
Γ ⊢ a ≃ b ∈ k → Γ ⊢ b ≃ c ∈ k → Γ ⊢ a ≃ c ∈ k
≃-trans (<:-antisym a<:b b<:a) (<:-antisym b<:c c<:b) =
<:-antisym (<:-trans a<:b b<:c) (<:-trans c<:b b<:a)
-- Type equality is symmetric.
≃-sym : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ b ≃ a ∈ k
≃-sym (<:-antisym a<:b b<:a) = <:-antisym b<:a a<:b
-- Types inhabiting interval kinds are proper Types.
Tp∈-⋯-* : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢Tp a ∈ *
Tp∈-⋯-* a∈b⋯c = ∈-⇑ (∈-s-i a∈b⋯c) (<∷-⋯ (<:-⊥ a∈b⋯c) (<:-⊤ a∈b⋯c))
-- Well-formedness of the * kind.
*-kd : ∀ {n} {Γ : Ctx n} → Γ ctx → Γ ⊢ * kd
*-kd Γ-ctx = kd-⋯ (∈-⊥-f Γ-ctx) (∈-⊤-f Γ-ctx)
module _ where
open Substitution
-- An admissible β-rule for type equality.
≃-β : ∀ {n} {Γ : Ctx n} {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j →
Γ ⊢ (Λ j a) · b ≃ a [ b ] ∈ k Kind[ b ]
≃-β a∈k b∈j = <:-antisym (<:-β₁ a∈k b∈j) (<:-β₂ a∈k b∈j)
-- An admissible η-rule for type equality.
≃-η : ∀ {n} {Γ : Ctx n} {a j k} →
Γ ⊢Tp a ∈ Π j k → Γ ⊢ Λ j (weaken a · var zero) ≃ a ∈ Π j k
≃-η a∈Πjk = <:-antisym (<:-η₁ a∈Πjk) (<:-η₂ a∈Πjk)
-- An admissible congruence rule for type equality w.r.t. formation of
-- arrow types.
≃-→ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂} →
Γ ⊢ a₁ ≃ a₂ ∈ * → Γ ⊢ b₁ ≃ b₂ ∈ * → Γ ⊢ a₁ ⇒ b₁ ≃ a₂ ⇒ b₂ ∈ *
≃-→ (<:-antisym a₁<:a₂∈* a₂<:a₁∈*) (<:-antisym b₁<:b₂∈* b₂<:b₁∈*) =
<:-antisym (<:-→ a₂<:a₁∈* b₁<:b₂∈*) (<:-→ a₁<:a₂∈* b₂<:b₁∈*)
-- An admissible congruence rule for type equality w.r.t. operator
-- abstraction.
≃-λ : ∀ {n} {Γ : Ctx n} {j₁ j₂ a₁ a₂ j k} →
kd j ∷ Γ ⊢ a₁ ≃ a₂ ∈ k → Γ ⊢Tp Λ j₁ a₁ ∈ Π j k → Γ ⊢Tp Λ j₂ a₂ ∈ Π j k →
Γ ⊢ Λ j₁ a₁ ≃ Λ j₂ a₂ ∈ Π j k
≃-λ (<:-antisym a₁<:a₂∈k a₂<:a₁∈k) Λj₁a₁∈Πjk Λj₂a₂∈Πjk =
<:-antisym (<:-λ a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk)
(<:-λ a₂<:a₁∈k Λj₂a₂∈Πjk Λj₁a₁∈Πjk)
-- An admissible subsumption rule for type equality.
≃-⇑ : ∀ {n} {Γ : Ctx n} {a b j k} → Γ ⊢ a ≃ b ∈ j → Γ ⊢ j <∷ k → Γ ⊢ a ≃ b ∈ k
≃-⇑ (<:-antisym a<:b b<:a) j<∷k = <:-antisym (<:-⇑ a<:b j<∷k) (<:-⇑ b<:a j<∷k)
-- NOTE. There are more admissible rules one might want to prove
-- here, such as congruence lemmas for type and kind equality
-- w.r.t. the remaining type constructors (e.g. Π and _·_) or
-- transitivity of subkinding and kind equality. But the proofs of
-- these lemmas require context narrowing and/or validity lemmas which
-- we have not yet established. We will prove these lemmas once we
-- have established validity of the declarative judgments (see the
-- Typing.Validity module).
-- The contexts of all the above judgments are well-formed.
mutual
kd-ctx : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ctx
kd-ctx (kd-⋯ a∈* b∈*) = Tp∈-ctx a∈*
kd-ctx (kd-Π j-kd k-kd) = kd-ctx j-kd
Tp∈-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ctx
Tp∈-ctx (∈-var x Γ-ctx Γ[x]≡kd-k) = Γ-ctx
Tp∈-ctx (∈-⊥-f Γ-ctx) = Γ-ctx
Tp∈-ctx (∈-⊤-f Γ-ctx) = Γ-ctx
Tp∈-ctx (∈-∀-f k-kd a∈*) = kd-ctx k-kd
Tp∈-ctx (∈-→-f a∈* b∈*) = Tp∈-ctx a∈*
Tp∈-ctx (∈-Π-i j-kd a∈k) = kd-ctx j-kd
Tp∈-ctx (∈-Π-e a∈Πjk b∈j) = Tp∈-ctx a∈Πjk
Tp∈-ctx (∈-s-i a∈b⋯c) = Tp∈-ctx a∈b⋯c
Tp∈-ctx (∈-⇑ a∈j j<∷k) = Tp∈-ctx a∈j
wf-ctx : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ a wf → Γ ctx
wf-ctx (wf-kd k-kd) = kd-ctx k-kd
wf-ctx (wf-tp a∈*) = Tp∈-ctx a∈*
<:-ctx : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a <: b ∈ k → Γ ctx
<:-ctx (<:-refl a∈k) = Tp∈-ctx a∈k
<:-ctx (<:-trans a<:b∈k b<:c∈k) = <:-ctx a<:b∈k
<:-ctx (<:-β₁ a∈j b∈k) = Tp∈-ctx b∈k
<:-ctx (<:-β₂ a∈j b∈k) = Tp∈-ctx b∈k
<:-ctx (<:-η₁ a∈Πjk) = Tp∈-ctx a∈Πjk
<:-ctx (<:-η₂ a∈Πjk) = Tp∈-ctx a∈Πjk
<:-ctx (<:-⊥ a∈b⋯c) = Tp∈-ctx a∈b⋯c
<:-ctx (<:-⊤ a∈b⋯c) = Tp∈-ctx a∈b⋯c
<:-ctx (<:-∀ k₂<∷k₁ a₁<:a₂ ∀k₁a₁∈*) = Tp∈-ctx ∀k₁a₁∈*
<:-ctx (<:-→ a₂<:a₁ b₁<:b₂) = <:-ctx a₂<:a₁
<:-ctx (<:-λ a₂<:a₁∈Πjk Λa₁k₁∈Πjk Λa₂k₂∈Πjk) = Tp∈-ctx Λa₁k₁∈Πjk
<:-ctx (<:-· a₂<:a₁∈Πjk b₂≃b₁∈j) = <:-ctx a₂<:a₁∈Πjk
<:-ctx (<:-⟨| a∈b⋯c) = Tp∈-ctx a∈b⋯c
<:-ctx (<:-|⟩ a∈b⋯c) = Tp∈-ctx a∈b⋯c
<:-ctx (<:-⋯-i a<:b∈c⋯d) = <:-ctx a<:b∈c⋯d
<:-ctx (<:-⇑ a<:b∈j j<∷k) = <:-ctx a<:b∈j
<∷-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → Γ ctx
<∷-ctx (<∷-⋯ a₂<:a₁ b₁<:b₂) = <:-ctx a₂<:a₁
<∷-ctx (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) = <∷-ctx j₂<∷j₁
≅-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ctx
≅-ctx (<∷-antisym j<∷k k<∷j) = <∷-ctx j<∷k
≃-ctx : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ctx
≃-ctx (<:-antisym a<:b∈k b<:a∈k) = <:-ctx a<:b∈k
Tm∈-ctx : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢Tm a ∈ b → Γ ctx
Tm∈-ctx (∈-var x Γ-ctx Γ[x]≡tp-a) = Γ-ctx
Tm∈-ctx (∈-∀-i k-kd a∈b) = kd-ctx k-kd
Tm∈-ctx (∈-→-i a∈* b∈c c∈*) = Tp∈-ctx a∈*
Tm∈-ctx (∈-∀-e a∈∀kc b∈k) = Tm∈-ctx a∈∀kc
Tm∈-ctx (∈-→-e a∈c⇒d b∈c) = Tm∈-ctx a∈c⇒d
Tm∈-ctx (∈-⇑ a∈b b<:c) = Tm∈-ctx a∈b
∈-ctx : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ∈ b → Γ ctx
∈-ctx (∈-tp a∈k) = Tp∈-ctx a∈k
∈-ctx (∈-tm a∈b) = Tm∈-ctx a∈b
----------------------------------------------------------------------
-- Well-typed substitutions (i.e. substitution lemmas)
-- A shorthand for kindings and typings of Ts by kind or type
-- ascriptions.
TermAscTyping : (ℕ → Set) → Set₁
TermAscTyping T = Typing TermAsc T TermAsc lzero
-- Liftings from well-typed Ts to well-typed/kinded terms/types.
LiftTo-∈ : ∀ {T} → TermAscTyping T → Set₁
LiftTo-∈ _⊢T_∈_ = LiftTyped Substitution.termAscTermSubst _⊢_wf _⊢T_∈_ _⊢_∈_
-- Helper lemmas about untyped T-substitutions in raw terms and kinds.
record TypedSubstAppHelpers {T} (rawLift : Lift T Term) : Set where
open Substitution using (weaken; _[_]; _Kind[_])
module A = SubstApp rawLift
module L = Lift rawLift
field
-- Substitutions in kinds and types commute.
Kind/-sub-↑ : ∀ {m n} k a (σ : Sub T m n) →
k Kind[ a ] A.Kind/ σ ≡ (k A.Kind/ σ L.↑) Kind[ a A./ σ ]
/-sub-↑ : ∀ {m n} b a (σ : Sub T m n) →
b [ a ] A./ σ ≡ (b A./ σ L.↑) [ a A./ σ ]
-- Weakening of terms commutes with substitution in terms.
weaken-/ : ∀ {m n} {σ : Sub T m n} a →
weaken (a A./ σ) ≡ weaken a A./ σ L.↑
-- Application of generic well-typed T-substitutions to all the judgments.
module TypedSubstApp {T : ℕ → Set} (_⊢T_∈_ : TermAscTyping T)
(liftTyped : LiftTo-∈ _⊢T_∈_)
(helpers : TypedSubstAppHelpers
(LiftTyped.rawLift liftTyped))
where
open LiftTyped liftTyped renaming (lookup to /∈-lookup)
open TypedSubstAppHelpers helpers
-- Lift well-kinded Ts to well-kinded types.
liftTp : ∀ {n} {Γ : Ctx n} {a k kd-k} →
kd-k ≡ kd k → Γ ⊢T a ∈ kd-k → Γ ⊢Tp L.lift a ∈ k
liftTp refl a∈kd-k with ∈-lift a∈kd-k
liftTp refl a∈kd-k | ∈-tp a∈k = a∈k
-- Lift well-typed Ts to well-typed terms.
liftTm : ∀ {n} {Γ : Ctx n} {a b tp-b} →
tp-b ≡ tp b → Γ ⊢T a ∈ tp-b → Γ ⊢Tm L.lift a ∈ b
liftTm refl a∈tp-b with ∈-lift a∈tp-b
liftTm refl a∈tp-b | ∈-tm a∈b = a∈b
mutual
-- Substitutions preserve well-formedness of kinds and
-- well-kindedness of types.
kd-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {k σ} →
Γ ⊢ k kd → Δ ⊢/ σ ∈ Γ → Δ ⊢ k A.Kind/ σ kd
kd-/ (kd-⋯ a∈* b∈*) σ∈Γ = kd-⋯ (Tp∈-/ a∈* σ∈Γ) (Tp∈-/ b∈* σ∈Γ)
kd-/ (kd-Π j-kd k-kd) σ∈Γ =
kd-Π j/σ-kd (kd-/ k-kd (∈-↑ (wf-kd j/σ-kd) σ∈Γ))
where j/σ-kd = kd-/ j-kd σ∈Γ
Tp∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k σ} →
Γ ⊢Tp a ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢Tp a A./ σ ∈ k A.Kind/ σ
Tp∈-/ (∈-var x Γ-ctx Γ[x]≡kd-k) σ∈Γ =
liftTp (cong (_/ _) Γ[x]≡kd-k) (/∈-lookup σ∈Γ x)
Tp∈-/ (∈-⊥-f Γ-ctx) σ∈Γ = ∈-⊥-f (/∈-wf σ∈Γ)
Tp∈-/ (∈-⊤-f Γ-ctx) σ∈Γ = ∈-⊤-f (/∈-wf σ∈Γ)
Tp∈-/ (∈-∀-f k-kd a∈*) σ∈Γ =
∈-∀-f k/σ-kd (Tp∈-/ a∈* (∈-↑ (wf-kd k/σ-kd) σ∈Γ))
where k/σ-kd = kd-/ k-kd σ∈Γ
Tp∈-/ (∈-→-f a∈* b∈*) σ∈Γ = ∈-→-f (Tp∈-/ a∈* σ∈Γ) (Tp∈-/ b∈* σ∈Γ)
Tp∈-/ (∈-Π-i j-kd a∈k) σ∈Γ =
∈-Π-i j/σ-kd (Tp∈-/ a∈k (∈-↑ (wf-kd j/σ-kd) σ∈Γ))
where j/σ-kd = kd-/ j-kd σ∈Γ
Tp∈-/ (∈-Π-e {_} {b} {_} {k} a∈Πjk b∈j) σ∈Γ =
subst (_ ⊢Tp _ ∈_) (sym (Kind/-sub-↑ k b _))
(∈-Π-e (Tp∈-/ a∈Πjk σ∈Γ) (Tp∈-/ b∈j σ∈Γ))
Tp∈-/ (∈-s-i a∈b⋯c) σ∈Γ = ∈-s-i (Tp∈-/ a∈b⋯c σ∈Γ)
Tp∈-/ (∈-⇑ a∈j j<∷k) σ∈Γ = ∈-⇑ (Tp∈-/ a∈j σ∈Γ) (<∷-/ j<∷k σ∈Γ)
-- Substitutions commute with subkinding, subtyping and type
-- equality.
<∷-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} →
Γ ⊢ j <∷ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ j A.Kind/ σ <∷ k A.Kind/ σ
<∷-/ (<∷-⋯ a₂<:a₁ b₁<:b₂) σ∈Γ = <∷-⋯ (<:-/ a₂<:a₁ σ∈Γ) (<:-/ b₁<:b₂ σ∈Γ)
<∷-/ (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) σ∈Γ =
<∷-Π (<∷-/ j₂<∷j₁ σ∈Γ) (<∷-/ k₁<∷k₂ (∈-↑ (<∷-/-wf k₁<∷k₂ σ∈Γ) σ∈Γ))
(kd-/ Πj₁k₁-kd σ∈Γ)
<:-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b k σ} →
Γ ⊢ a <: b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ <: b A./ σ ∈ k A.Kind/ σ
<:-/ (<:-refl a∈k) σ∈Γ = <:-refl (Tp∈-/ a∈k σ∈Γ)
<:-/ (<:-trans a<:b∈k b<:c∈k) σ∈Γ =
<:-trans (<:-/ a<:b∈k σ∈Γ) (<:-/ b<:c∈k σ∈Γ)
<:-/ (<:-β₁ {j} {a} {k} {b} a∈k b∈j) σ∈Γ =
subst₂ (_ ⊢ (Λ j a) · b A./ _ <:_∈_)
(sym (/-sub-↑ a b _)) (sym (Kind/-sub-↑ k b _))
(<:-β₁ (Tp∈-/ a∈k (∈-↑ (Tp∈-/-wf a∈k σ∈Γ) σ∈Γ)) (Tp∈-/ b∈j σ∈Γ))
<:-/ (<:-β₂ {j} {a} {k} {b} a∈k b∈j) σ∈Γ =
subst₂ (_ ⊢_<: (Λ j a) · b A./ _ ∈_)
(sym (/-sub-↑ a b _)) (sym (Kind/-sub-↑ k b _))
(<:-β₂ (Tp∈-/ a∈k (∈-↑ (Tp∈-/-wf a∈k σ∈Γ) σ∈Γ)) (Tp∈-/ b∈j σ∈Γ))
<:-/ {Δ = Δ} {σ = σ} (<:-η₁ {a} {j} {k} a∈Πjk) σ∈Γ =
subst (Δ ⊢_<: a A./ σ ∈ Π j k A.Kind/ σ)
(cong (Λ _) (cong₂ _·_ (weaken-/ a) (sym (lift-var zero))))
(<:-η₁ (Tp∈-/ a∈Πjk σ∈Γ))
<:-/ {Δ = Δ} {σ = σ} (<:-η₂ {a} {j} {k} a∈Πjk) σ∈Γ =
subst (Δ ⊢ a A./ σ <:_∈ Π j k A.Kind/ σ)
(cong (Λ _) (cong₂ _·_ (weaken-/ a) (sym (lift-var zero))))
(<:-η₂ (Tp∈-/ a∈Πjk σ∈Γ))
<:-/ (<:-⊥ a∈b⋯c) σ∈Γ = <:-⊥ (Tp∈-/ a∈b⋯c σ∈Γ)
<:-/ (<:-⊤ a∈b⋯c) σ∈Γ = <:-⊤ (Tp∈-/ a∈b⋯c σ∈Γ)
<:-/ (<:-∀ k₂<∷k₁ a₁<:a₂∈* ∀j₁k₁∈*) σ∈Γ =
<:-∀ (<∷-/ k₂<∷k₁ σ∈Γ) (<:-/ a₁<:a₂∈* (∈-↑ (<:-/-wf a₁<:a₂∈* σ∈Γ) σ∈Γ))
(Tp∈-/ ∀j₁k₁∈* σ∈Γ)
<:-/ (<:-→ a₂<:a₁∈* b₁<:b₂∈*) σ∈Γ =
<:-→ (<:-/ a₂<:a₁∈* σ∈Γ) (<:-/ b₁<:b₂∈* σ∈Γ)
<:-/ (<:-λ a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk) σ∈Γ =
<:-λ (<:-/ a₁<:a₂∈k (∈-↑ (<:-/-wf a₁<:a₂∈k σ∈Γ) σ∈Γ))
(Tp∈-/ Λj₁a₁∈Πjk σ∈Γ) (Tp∈-/ Λj₂a₂∈Πjk σ∈Γ)
<:-/ (<:-· {k = k} a₁<:a₂∈Πjk b₁≃b₂∈j) σ∈Γ =
subst (_ ⊢ _ <: _ ∈_) (sym (Kind/-sub-↑ k _ _))
(<:-· (<:-/ a₁<:a₂∈Πjk σ∈Γ) (≃-/ b₁≃b₂∈j σ∈Γ))
<:-/ (<:-⟨| a∈b⋯c) σ∈Γ = <:-⟨| (Tp∈-/ a∈b⋯c σ∈Γ)
<:-/ (<:-|⟩ a∈b⋯c) σ∈Γ = <:-|⟩ (Tp∈-/ a∈b⋯c σ∈Γ)
<:-/ (<:-⋯-i a<:b∈c⋯d) σ∈Γ = <:-⋯-i (<:-/ a<:b∈c⋯d σ∈Γ)
<:-/ (<:-⇑ a<:b∈j j<∷k) σ∈Γ = <:-⇑ (<:-/ a<:b∈j σ∈Γ) (<∷-/ j<∷k σ∈Γ)
≃-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b k σ} →
Γ ⊢ a ≃ b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ ≃ b A./ σ ∈ k A.Kind/ σ
≃-/ (<:-antisym a<:b∈k b<:a∈k) σ∈Γ =
<:-antisym (<:-/ a<:b∈k σ∈Γ) (<:-/ b<:a∈k σ∈Γ)
-- Helpers (to satisfy the termination checker).
kd-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} →
kd j ∷ Γ ⊢ k kd → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf
kd-/-wf (kd-⋯ a∈* _) σ∈Γ = Tp∈-/-wf a∈* σ∈Γ
kd-/-wf (kd-Π j-kd _) σ∈Γ = kd-/-wf j-kd σ∈Γ
Tp∈-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k σ} →
kd j ∷ Γ ⊢Tp a ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf
Tp∈-/-wf (∈-var x (wf-kd k-kd ∷ Γ-ctx) _) σ∈Γ = wf-kd (kd-/ k-kd σ∈Γ)
Tp∈-/-wf (∈-⊥-f (wf-kd j-kd ∷ Γ-ctx)) σ∈Γ = wf-kd (kd-/ j-kd σ∈Γ)
Tp∈-/-wf (∈-⊤-f (wf-kd j-kd ∷ Γ-ctx)) σ∈Γ = wf-kd (kd-/ j-kd σ∈Γ)
Tp∈-/-wf (∈-∀-f k-kd _) σ∈Γ = kd-/-wf k-kd σ∈Γ
Tp∈-/-wf (∈-→-f a∈* _) σ∈Γ = Tp∈-/-wf a∈* σ∈Γ
Tp∈-/-wf (∈-Π-i j-kd _) σ∈Γ = kd-/-wf j-kd σ∈Γ
Tp∈-/-wf (∈-Π-e a∈Πjk _) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ
Tp∈-/-wf (∈-s-i a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ
Tp∈-/-wf (∈-⇑ a∈b _) σ∈Γ = Tp∈-/-wf a∈b σ∈Γ
<:-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b j k σ} →
kd j ∷ Γ ⊢ a <: b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf
<:-/-wf (<:-refl a∈k) σ∈Γ = Tp∈-/-wf a∈k σ∈Γ
<:-/-wf (<:-trans a<:b _) σ∈Γ = <:-/-wf a<:b σ∈Γ
<:-/-wf (<:-β₁ _ b∈j) σ∈Γ = Tp∈-/-wf b∈j σ∈Γ
<:-/-wf (<:-β₂ _ b∈j) σ∈Γ = Tp∈-/-wf b∈j σ∈Γ
<:-/-wf (<:-η₁ a∈Πjk) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ
<:-/-wf (<:-η₂ a∈Πjk) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ
<:-/-wf (<:-⊥ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ
<:-/-wf (<:-⊤ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ
<:-/-wf (<:-∀ j₂<∷j₁ _ _) σ∈Γ = <∷-/-wf j₂<∷j₁ σ∈Γ
<:-/-wf (<:-→ a₂<:a₁∈* _) σ∈Γ = <:-/-wf a₂<:a₁∈* σ∈Γ
<:-/-wf (<:-λ _ Λj₁a₂∈Πjk _) σ∈Γ = Tp∈-/-wf Λj₁a₂∈Πjk σ∈Γ
<:-/-wf (<:-· a₁<:a₂∈Πjk _) σ∈Γ = <:-/-wf a₁<:a₂∈Πjk σ∈Γ
<:-/-wf (<:-⟨| a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ
<:-/-wf (<:-|⟩ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ
<:-/-wf (<:-⋯-i a<:b∈c⋯d) σ∈Γ = <:-/-wf a<:b∈c⋯d σ∈Γ
<:-/-wf (<:-⇑ a<:b∈k _) σ∈Γ = <:-/-wf a<:b∈k σ∈Γ
<∷-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k l σ} →
kd j ∷ Γ ⊢ k <∷ l → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf
<∷-/-wf (<∷-⋯ j₂<:j₁ _) σ∈Γ = <:-/-wf j₂<:j₁ σ∈Γ
<∷-/-wf (<∷-Π j₂<∷j₁ _ _) σ∈Γ = <∷-/-wf j₂<∷j₁ σ∈Γ
-- Substitutions preserve well-formedness of ascriptions.
wf-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a σ} →
Γ ⊢ a wf → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.TermAsc/ σ wf
wf-/ (wf-kd k-kd) σ∈Γ = wf-kd (kd-/ k-kd σ∈Γ)
wf-/ (wf-tp a∈b) σ∈Γ = wf-tp (Tp∈-/ a∈b σ∈Γ)
-- Substitutions commute with kind equality.
≅-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} →
Γ ⊢ j ≅ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ j A.Kind/ σ ≅ k A.Kind/ σ
≅-/ (<∷-antisym j<∷k k<∷j) σ∈Γ = <∷-antisym (<∷-/ j<∷k σ∈Γ) (<∷-/ k<∷j σ∈Γ)
-- Substitutions preserve well-typedness of terms.
Tm∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} →
Γ ⊢Tm a ∈ b → Δ ⊢/ σ ∈ Γ → Δ ⊢Tm a A./ σ ∈ b A./ σ
Tm∈-/ (∈-var x Γ-ctx Γ[x]=tp-k) σ∈Γ =
liftTm (cong (_/ _) Γ[x]=tp-k) (/∈-lookup σ∈Γ x)
Tm∈-/ (∈-∀-i k-kd a∈*) σ∈Γ =
∈-∀-i k/σ-kd (Tm∈-/ a∈* (∈-↑ (wf-kd k/σ-kd) σ∈Γ))
where k/σ-kd = kd-/ k-kd σ∈Γ
Tm∈-/ (∈-→-i {c = c} a∈* b∈c c∈*) σ∈Γ =
∈-→-i a/σ∈* (subst (_ ⊢Tm _ ∈_) (sym (weaken-/ c) ) b/σ↑∈c)
(Tp∈-/ c∈* σ∈Γ)
where
a/σ∈* = Tp∈-/ a∈* σ∈Γ
b/σ↑∈c = Tm∈-/ b∈c (∈-↑ (wf-tp a/σ∈*) σ∈Γ)
Tm∈-/ (∈-∀-e {c = c} a∈∀kc b∈k) σ∈Γ =
subst (_ ⊢Tm _ ∈_) (sym (/-sub-↑ c _ _))
(∈-∀-e (Tm∈-/ a∈∀kc σ∈Γ) (Tp∈-/ b∈k σ∈Γ))
Tm∈-/ (∈-→-e a∈c→d b∈c) σ∈Γ = ∈-→-e (Tm∈-/ a∈c→d σ∈Γ) (Tm∈-/ b∈c σ∈Γ)
Tm∈-/ (∈-⇑ a∈b b<:c) σ∈Γ = ∈-⇑ (Tm∈-/ a∈b σ∈Γ) (<:-/ b<:c σ∈Γ)
-- Substitutions preserve well-kindedness and well-typedness.
∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} →
Γ ⊢ a ∈ b → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ ∈ b A.TermAsc/ σ
∈-/ (∈-tp a∈b) σ∈Γ = ∈-tp (Tp∈-/ a∈b σ∈Γ)
∈-/ (∈-tm a∈b) σ∈Γ = ∈-tm (Tm∈-/ a∈b σ∈Γ)
-- Substitutions preserve subkinding and subtyping.
≤-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} →
Γ ⊢ a ≤ b → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.TermAsc/ σ ≤ b A.TermAsc/ σ
≤-/ (≤-<∷ a<∷b) σ∈Γ = ≤-<∷ (<∷-/ a<∷b σ∈Γ)
≤-/ (≤-<: a<:b∈k) σ∈Γ = ≤-<: (<:-/ a<:b∈k σ∈Γ)
-- Substitutions preserve equality of kind and type ascriptions.
≃wf-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} →
Γ ⊢ a ≃ b wf → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.TermAsc/ σ ≃ b A.TermAsc/ σ wf
≃wf-/ (≃wf-≅ j≅k) σ∈Γ = ≃wf-≅ (≅-/ j≅k σ∈Γ)
≃wf-/ (≃wf-≃ a≃b) σ∈Γ = ≃wf-≃ (≃-/ a≃b σ∈Γ)
-- Well-kinded/typed type and term substitutions.
module TypedSubstitution where
open Substitution using (simple; termSubst)
open SimpleExt simple using (extension)
open TermSubst termSubst using (varLift; termLift)
private
module S = Substitution
module KL = TermLikeLemmas S.termLikeLemmasKind
-- Helper lemmas about untyped renamings and substitutions in terms
-- and kinds.
varHelpers : TypedSubstAppHelpers varLift
varHelpers = record
{ Kind/-sub-↑ = KL./-sub-↑
; /-sub-↑ = LiftSubLemmas./-sub-↑ S.varLiftSubLemmas
; weaken-/ = LiftAppLemmas.wk-commutes S.varLiftAppLemmas
}
termHelpers : TypedSubstAppHelpers termLift
termHelpers = record
{ Kind/-sub-↑ = λ k _ _ → KL.sub-commutes k
; /-sub-↑ = λ a _ _ → S.sub-commutes a
; weaken-/ = S.weaken-/
}
-- Typed term substitutions.
typedTermSubst : TypedTermSubst TermAsc Term lzero TypedSubstAppHelpers
typedTermSubst = record
{ _⊢_wf = _⊢_wf
; _⊢_∈_ = _⊢_∈_
; termLikeLemmas = S.termLikeLemmasTermAsc
; varHelpers = varHelpers
; termHelpers = termHelpers
; wf-wf = wf-ctx
; ∈-wf = ∈-ctx
; ∈-var = ∈-var′
; typedApp = TypedSubstApp.∈-/
}
open TypedTermSubst typedTermSubst public
hiding (_⊢_wf; _⊢_∈_; varHelpers; termHelpers; ∈-var; ∈-/Var; ∈-/)
renaming (lookup to /∈-lookup)
open TypedSubstApp _⊢Var_∈_ varLiftTyped varHelpers public using () renaming
( wf-/ to wf-/Var
; kd-/ to kd-/Var
; Tp∈-/ to Tp∈-/Var
; <∷-/ to <∷-/Var
; <:-/ to <:-/Var
; ∈-/ to ∈-/Var
; ≤-/ to ≤-/Var
; ≃wf-/ to ≃wf-/Var
)
open Substitution using (weaken; weakenKind; weakenTermAsc)
-- Weakening preserves the various judgments.
wf-weaken : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a wf → Γ ⊢ b wf →
(a ∷ Γ) ⊢ weakenTermAsc b wf
wf-weaken a-wf b-wf = wf-/Var b-wf (Var∈-wk a-wf)
kd-weaken : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢ a wf → Γ ⊢ k kd →
(a ∷ Γ) ⊢ weakenKind k kd
kd-weaken a-wf k-kd = kd-/Var k-kd (Var∈-wk a-wf)
Tp∈-weaken : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a wf → Γ ⊢Tp b ∈ k →
(a ∷ Γ) ⊢Tp weaken b ∈ weakenKind k
Tp∈-weaken a-wf b∈k = Tp∈-/Var b∈k (Var∈-wk a-wf)
<∷-weaken : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢ a wf → Γ ⊢ j <∷ k →
(a ∷ Γ) ⊢ weakenKind j <∷ weakenKind k
<∷-weaken a-wf j<∷k = <∷-/Var j<∷k (Var∈-wk a-wf)
<:-weaken : ∀ {n} {Γ : Ctx n} {a b c k} → Γ ⊢ a wf → Γ ⊢ b <: c ∈ k →
(a ∷ Γ) ⊢ weaken b <: weaken c ∈ weakenKind k
<:-weaken a-wf b<:c∈k = <:-/Var b<:c∈k (Var∈-wk a-wf)
∈-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b ∈ c →
(a ∷ Γ) ⊢ weaken b ∈ weakenTermAsc c
∈-weaken a-wf b∈c = ∈-/Var b∈c (Var∈-wk a-wf)
≤-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b ≤ c →
(a ∷ Γ) ⊢ weakenTermAsc b ≤ weakenTermAsc c
≤-weaken a-wf b≤c = ≤-/Var b≤c (Var∈-wk a-wf)
≃wf-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b ≃ c wf →
(a ∷ Γ) ⊢ weakenTermAsc b ≃ weakenTermAsc c wf
≃wf-weaken a-wf b≃c = ≃wf-/Var b≃c (Var∈-wk a-wf)
open TypedSubstApp _⊢_∈_ termLiftTyped termHelpers public
open Substitution using (_/_; _Kind/_; id; sub; _↑⋆_; _[_]; _Kind[_])
-- Substitution of a single well-typed term or well-kinded type
-- preserves the various judgments.
kd-[] : ∀ {n} {Γ : Ctx n} {a b k} →
b ∷ Γ ⊢ k kd → Γ ⊢ a ∈ b → Γ ⊢ k Kind[ a ] kd
kd-[] k-kd a∈b = kd-/ k-kd (∈-sub a∈b)
Tp∈-[] : ∀ {n} {Γ : Ctx n} {a b k c} →
c ∷ Γ ⊢Tp a ∈ k → Γ ⊢ b ∈ c → Γ ⊢Tp a [ b ] ∈ k Kind[ b ]
Tp∈-[] a∈k b∈c = Tp∈-/ a∈k (∈-sub b∈c)
Tm∈-[] : ∀ {n} {Γ : Ctx n} {a b c d} →
d ∷ Γ ⊢Tm a ∈ c → Γ ⊢ b ∈ d → Γ ⊢Tm a [ b ] ∈ c [ b ]
Tm∈-[] a∈c b∈d = Tm∈-/ a∈c (∈-sub b∈d)
<:-[] : ∀ {n} {Γ : Ctx n} {a b c d k} →
d ∷ Γ ⊢ a <: b ∈ k → Γ ⊢ c ∈ d → Γ ⊢ a [ c ] <: b [ c ] ∈ k Kind[ c ]
<:-[] a<:b c∈d = <:-/ a<:b (∈-sub c∈d)
-- Operations on well-formed contexts that require weakening of
-- well-formedness judgments.
module WfCtxOps where
wfWeakenOps : WellFormedWeakenOps weakenOps
wfWeakenOps = record { wf-weaken = TypedSubstitution.wf-weaken }
open WellFormedWeakenOps wfWeakenOps public renaming (lookup to lookup-wf)
-- Lookup the kind of a type variable in a well-formed context.
lookup-kd : ∀ {m} {Γ : Ctx m} {k} x →
Γ ctx → TermCtx.lookup Γ x ≡ kd k → Γ ⊢ k kd
lookup-kd x Γ-ctx Γ[x]≡kd-k =
wf-kd-inv (subst (_ ⊢_wf) Γ[x]≡kd-k (lookup-wf Γ-ctx x))
-- Lookup the type of a term variable in a well-formed context.
lookup-tp : ∀ {m} {Γ : Ctx m} {a} x →
Γ ctx → TermCtx.lookup Γ x ≡ tp a → Γ ⊢Tp a ∈ *
lookup-tp x Γ-ctx Γ[x]≡tp-a =
wf-tp-inv (subst (_ ⊢_wf) Γ[x]≡tp-a (lookup-wf Γ-ctx x))
open TypedSubstitution
open WfCtxOps
----------------------------------------------------------------------
-- Generation lemmas for kinding
-- A generation lemma for kinding of universals.
Tp∈-∀-inv : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢Tp Π j a ∈ k →
Γ ⊢ j kd × kd j ∷ Γ ⊢Tp a ∈ *
Tp∈-∀-inv (∈-∀-f j-kd a∈*) = j-kd , a∈*
Tp∈-∀-inv (∈-s-i ∀ka∈b⋯c) = Tp∈-∀-inv ∀ka∈b⋯c
Tp∈-∀-inv (∈-⇑ ∀ja∈k k<∷l) = Tp∈-∀-inv ∀ja∈k
-- A generation lemma for kinding of arrows.
Tp∈-→-inv : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢Tp a ⇒ b ∈ k →
Γ ⊢Tp a ∈ * × Γ ⊢Tp b ∈ *
Tp∈-→-inv (∈-→-f a∈* b∈*) = a∈* , b∈*
Tp∈-→-inv (∈-s-i a⇒b∈c⋯d) = Tp∈-→-inv a⇒b∈c⋯d
Tp∈-→-inv (∈-⇑ a⇒b∈j j<∷k) = Tp∈-→-inv a⇒b∈j
| 39.977303 | 79 | 0.437765 |
0e22ce71af8b408961e50544a8b0bc9c35d41438 | 161 | agda | Agda | Cubical/Codata/Stream.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | 1 | 2020-03-23T23:52:11.000Z | 2020-03-23T23:52:11.000Z | Cubical/Codata/Stream.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | null | null | null | Cubical/Codata/Stream.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical #-}
module Cubical.Codata.Stream where
open import Cubical.Codata.Stream.Base public
open import Cubical.Codata.Stream.Properties public
| 23 | 51 | 0.795031 |
df5abf9f90815fa57da1b8a9b3e4985afb379440 | 448 | agda | Agda | tests/covered/plantsigma.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | 3 | 2015-08-10T15:33:56.000Z | 2018-12-06T17:24:25.000Z | tests/covered/plantsigma.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | null | null | null | tests/covered/plantsigma.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | null | null | null | module plantsigma where
data Tree : Set where
oak : Tree
pine : Tree
spruce : Tree
data Flower : Set where
rose : Flower
lily : Flower
data PlantGroup : Set where
tree : PlantGroup
flower : PlantGroup
PlantsInGroup : PlantGroup -> Set
PlantsInGroup tree = Tree
PlantsInGroup flower = Flower
data Plant : Set where
plant : (g : PlantGroup) -> PlantsInGroup g -> Plant
f : Plant -> PlantGroup
f (plant g pg) = g
| 15.448276 | 54 | 0.674107 |
2350c23187375564eeae15a99e0d83beec363005 | 3,355 | agda | Agda | Cubical/Structures/CommRing.agda | ryanorendorff/cubical | c67854d2e11aafa5677e25a09087e176fafd3e43 | [
"MIT"
] | 1 | 2020-03-23T23:52:11.000Z | 2020-03-23T23:52:11.000Z | Cubical/Structures/CommRing.agda | ryanorendorff/cubical | c67854d2e11aafa5677e25a09087e176fafd3e43 | [
"MIT"
] | null | null | null | Cubical/Structures/CommRing.agda | ryanorendorff/cubical | c67854d2e11aafa5677e25a09087e176fafd3e43 | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --safe #-}
module Cubical.Structures.CommRing where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
open import Cubical.Structures.NAryOp
open import Cubical.Structures.Pointed
open import Cubical.Structures.Ring hiding (⟨_⟩)
private
variable
ℓ ℓ' : Level
comm-ring-axioms : (X : Type ℓ) (s : raw-ring-structure X) → Type ℓ
comm-ring-axioms X (_+_ , ₁ , _·_) = (ring-axioms X (_+_ , ₁ , _·_)) ×
((x y : X) → x · y ≡ y · x)
comm-ring-structure : Type ℓ → Type ℓ
comm-ring-structure = add-to-structure raw-ring-structure comm-ring-axioms
CommRing : Type (ℓ-suc ℓ)
CommRing {ℓ} = TypeWithStr ℓ comm-ring-structure
comm-ring-iso : StrIso comm-ring-structure ℓ
comm-ring-iso = add-to-iso (join-iso (nAryFunIso 2) (join-iso pointed-iso (nAryFunIso 2))) comm-ring-axioms
comm-ring-axioms-isProp : (X : Type ℓ) (s : raw-ring-structure X) → isProp (comm-ring-axioms X s)
comm-ring-axioms-isProp X (_·_ , ₀ , _+_) = isPropΣ (ring-axioms-isProp X (_·_ , ₀ , _+_))
λ ((((isSetX , _) , _) , _) , _) → isPropΠ2 λ _ _ → isSetX _ _
comm-ring-is-SNS : SNS {ℓ} comm-ring-structure comm-ring-iso
comm-ring-is-SNS = add-axioms-SNS _ comm-ring-axioms-isProp raw-ring-is-SNS
CommRingPath : (M N : CommRing {ℓ}) → (M ≃[ comm-ring-iso ] N) ≃ (M ≡ N)
CommRingPath = SIP comm-ring-is-SNS
-- CommRing is Ring
CommRing→Ring : CommRing {ℓ} → Ring
CommRing→Ring (R , str , isRing , ·comm) = R , str , isRing
-- CommRing Extractors
⟨_⟩ : CommRing {ℓ} → Type ℓ
⟨ R , _ ⟩ = R
module _ (R : CommRing {ℓ}) where
commring+-operation = ring+-operation (CommRing→Ring R)
commring-is-set = ring-is-set (CommRing→Ring R)
commring+-assoc = ring+-assoc (CommRing→Ring R)
commring+-id = ring+-id (CommRing→Ring R)
commring+-rid = ring+-rid (CommRing→Ring R)
commring+-lid = ring+-lid (CommRing→Ring R)
commring+-inv = ring+-inv (CommRing→Ring R)
commring+-rinv = ring+-rinv (CommRing→Ring R)
commring+-linv = ring+-linv (CommRing→Ring R)
commring+-comm = ring+-comm (CommRing→Ring R)
commring·-operation = ring·-operation (CommRing→Ring R)
commring·-assoc = ring·-assoc (CommRing→Ring R)
commring·-id = ring·-id (CommRing→Ring R)
commring·-rid = ring·-rid (CommRing→Ring R)
commring·-lid = ring·-lid (CommRing→Ring R)
commring-ldist = ring-ldist (CommRing→Ring R)
commring-rdist = ring-rdist (CommRing→Ring R)
module commring-operation-syntax where
commring+-operation-syntax : (R : CommRing {ℓ}) → ⟨ R ⟩ → ⟨ R ⟩ → ⟨ R ⟩
commring+-operation-syntax R = commring+-operation R
infixr 14 commring+-operation-syntax
syntax commring+-operation-syntax G x y = x +⟨ G ⟩ y
commring·-operation-syntax : (R : CommRing {ℓ}) → ⟨ R ⟩ → ⟨ R ⟩ → ⟨ R ⟩
commring·-operation-syntax R = commring·-operation R
infixr 18 commring·-operation-syntax
syntax commring·-operation-syntax G x y = x ·⟨ G ⟩ y
open commring-operation-syntax
commring-comm : (R : CommRing {ℓ}) (x y : ⟨ R ⟩) → x ·⟨ R ⟩ y ≡ y ·⟨ R ⟩ x
commring-comm (_ , _ , _ , P) = P
-- CommRing ·syntax
module commring-·syntax (R : CommRing {ℓ}) where
open ring-·syntax (CommRing→Ring R) public
| 30.5 | 107 | 0.658718 |
d03089c2677278dff2a710b2d90124ad2f5ba972 | 7,633 | agda | Agda | Cubical/Algebra/Algebra/Properties.agda | thomas-lamiaux/cubical | 58c0b83bb0fed0dc683f3d29b1709effe51c1689 | [
"MIT"
] | null | null | null | Cubical/Algebra/Algebra/Properties.agda | thomas-lamiaux/cubical | 58c0b83bb0fed0dc683f3d29b1709effe51c1689 | [
"MIT"
] | null | null | null | Cubical/Algebra/Algebra/Properties.agda | thomas-lamiaux/cubical | 58c0b83bb0fed0dc683f3d29b1709effe51c1689 | [
"MIT"
] | null | null | null | {-# OPTIONS --safe #-}
module Cubical.Algebra.Algebra.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Module
open import Cubical.Algebra.Algebra.Base
open Iso
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
module AlgebraTheory (R : Ring ℓ) (A : Algebra R ℓ') where
open RingStr (snd R) renaming (_+_ to _+r_ ; _·_ to _·r_)
open AlgebraStr (A .snd)
0-actsNullifying : (x : ⟨ A ⟩) → 0r ⋆ x ≡ 0a
0-actsNullifying x =
let idempotent-+ = 0r ⋆ x ≡⟨ cong (λ u → u ⋆ x) (sym (RingTheory.0Idempotent R)) ⟩
(0r +r 0r) ⋆ x ≡⟨ ⋆DistL+ 0r 0r x ⟩
(0r ⋆ x) + (0r ⋆ x) ∎
in RingTheory.+Idempotency→0 (Algebra→Ring A) (0r ⋆ x) idempotent-+
⋆Dist· : (x y : ⟨ R ⟩) (a b : ⟨ A ⟩) → (x ·r y) ⋆ (a · b) ≡ (x ⋆ a) · (y ⋆ b)
⋆Dist· x y a b = (x ·r y) ⋆ (a · b) ≡⟨ ⋆AssocR _ _ _ ⟩
a · ((x ·r y) ⋆ b) ≡⟨ cong (a ·_) (⋆Assoc _ _ _) ⟩
a · (x ⋆ (y ⋆ b)) ≡⟨ sym (⋆AssocR _ _ _) ⟩
x ⋆ (a · (y ⋆ b)) ≡⟨ sym (⋆AssocL _ _ _) ⟩
(x ⋆ a) · (y ⋆ b) ∎
module AlgebraHoms {R : Ring ℓ} where
open IsAlgebraHom
idAlgebraHom : (A : Algebra R ℓ') → AlgebraHom A A
fst (idAlgebraHom A) x = x
pres0 (snd (idAlgebraHom A)) = refl
pres1 (snd (idAlgebraHom A)) = refl
pres+ (snd (idAlgebraHom A)) x y = refl
pres· (snd (idAlgebraHom A)) x y = refl
pres- (snd (idAlgebraHom A)) x = refl
pres⋆ (snd (idAlgebraHom A)) r x = refl
compIsAlgebraHom : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}
{g : ⟨ B ⟩ → ⟨ C ⟩} {f : ⟨ A ⟩ → ⟨ B ⟩}
→ IsAlgebraHom (B .snd) g (C .snd)
→ IsAlgebraHom (A .snd) f (B .snd)
→ IsAlgebraHom (A .snd) (g ∘ f) (C .snd)
compIsAlgebraHom {g = g} {f} gh fh .pres0 = cong g (fh .pres0) ∙ gh .pres0
compIsAlgebraHom {g = g} {f} gh fh .pres1 = cong g (fh .pres1) ∙ gh .pres1
compIsAlgebraHom {g = g} {f} gh fh .pres+ x y = cong g (fh .pres+ x y) ∙ gh .pres+ (f x) (f y)
compIsAlgebraHom {g = g} {f} gh fh .pres· x y = cong g (fh .pres· x y) ∙ gh .pres· (f x) (f y)
compIsAlgebraHom {g = g} {f} gh fh .pres- x = cong g (fh .pres- x) ∙ gh .pres- (f x)
compIsAlgebraHom {g = g} {f} gh fh .pres⋆ r x = cong g (fh .pres⋆ r x) ∙ gh .pres⋆ r (f x)
_∘≃a_ : {A B C : Algebra R ℓ'}
→ AlgebraEquiv B C → AlgebraEquiv A B → AlgebraEquiv A C
_∘≃a_ g f .fst = compEquiv (fst f) (fst g)
_∘≃a_ g f .snd = compIsAlgebraHom (g .snd) (f .snd)
compAlgebraHom : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}
→ AlgebraHom A B → AlgebraHom B C → AlgebraHom A C
compAlgebraHom f g .fst = g .fst ∘ f .fst
compAlgebraHom f g .snd = compIsAlgebraHom (g .snd) (f .snd)
syntax compAlgebraHom f g = g ∘a f
compIdAlgebraHom : {A B : Algebra R ℓ'} (φ : AlgebraHom A B) → compAlgebraHom (idAlgebraHom A) φ ≡ φ
compIdAlgebraHom φ = AlgebraHom≡ refl
idCompAlgebraHom : {A B : Algebra R ℓ'} (φ : AlgebraHom A B) → compAlgebraHom φ (idAlgebraHom B) ≡ φ
idCompAlgebraHom φ = AlgebraHom≡ refl
compAssocAlgebraHom : {A B C D : Algebra R ℓ'}
(φ : AlgebraHom A B) (ψ : AlgebraHom B C) (χ : AlgebraHom C D)
→ compAlgebraHom (compAlgebraHom φ ψ) χ ≡ compAlgebraHom φ (compAlgebraHom ψ χ)
compAssocAlgebraHom _ _ _ = AlgebraHom≡ refl
module AlgebraEquivs {R : Ring ℓ} where
open IsAlgebraHom
open AlgebraHoms
compIsAlgebraEquiv : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}
{g : ⟨ B ⟩ ≃ ⟨ C ⟩} {f : ⟨ A ⟩ ≃ ⟨ B ⟩}
→ IsAlgebraEquiv (B .snd) g (C .snd)
→ IsAlgebraEquiv (A .snd) f (B .snd)
→ IsAlgebraEquiv (A .snd) (compEquiv f g) (C .snd)
compIsAlgebraEquiv {g = g} {f} gh fh = compIsAlgebraHom {g = g .fst} {f .fst} gh fh
compAlgebraEquiv : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}
→ AlgebraEquiv A B → AlgebraEquiv B C → AlgebraEquiv A C
fst (compAlgebraEquiv f g) = compEquiv (f .fst) (g .fst)
snd (compAlgebraEquiv f g) = compIsAlgebraEquiv {g = g .fst} {f = f .fst} (g .snd) (f .snd)
-- the Algebra version of uaCompEquiv
module AlgebraUAFunctoriality {R : Ring ℓ} where
open AlgebraStr
open AlgebraEquivs
Algebra≡ : (A B : Algebra R ℓ') → (
Σ[ p ∈ ⟨ A ⟩ ≡ ⟨ B ⟩ ]
Σ[ q0 ∈ PathP (λ i → p i) (0a (snd A)) (0a (snd B)) ]
Σ[ q1 ∈ PathP (λ i → p i) (1a (snd A)) (1a (snd B)) ]
Σ[ r+ ∈ PathP (λ i → p i → p i → p i) (_+_ (snd A)) (_+_ (snd B)) ]
Σ[ r· ∈ PathP (λ i → p i → p i → p i) (_·_ (snd A)) (_·_ (snd B)) ]
Σ[ s- ∈ PathP (λ i → p i → p i) (-_ (snd A)) (-_ (snd B)) ]
Σ[ s⋆ ∈ PathP (λ i → ⟨ R ⟩ → p i → p i) (_⋆_ (snd A)) (_⋆_ (snd B)) ]
PathP (λ i → IsAlgebra R (q0 i) (q1 i) (r+ i) (r· i) (s- i) (s⋆ i)) (isAlgebra (snd A))
(isAlgebra (snd B)))
≃ (A ≡ B)
Algebra≡ A B = isoToEquiv theIso
where
open Iso
theIso : Iso _ _
fun theIso (p , q0 , q1 , r+ , r· , s- , s⋆ , t) i = p i
, algebrastr (q0 i) (q1 i) (r+ i) (r· i) (s- i) (s⋆ i) (t i)
inv theIso x = cong ⟨_⟩ x , cong (0a ∘ snd) x , cong (1a ∘ snd) x
, cong (_+_ ∘ snd) x , cong (_·_ ∘ snd) x , cong (-_ ∘ snd) x , cong (_⋆_ ∘ snd) x
, cong (isAlgebra ∘ snd) x
rightInv theIso _ = refl
leftInv theIso _ = refl
caracAlgebra≡ : {A B : Algebra R ℓ'} (p q : A ≡ B) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q
caracAlgebra≡ {A = A} {B = B} p q P =
sym (transportTransport⁻ (ua (Algebra≡ A B)) p)
∙∙ cong (transport (ua (Algebra≡ A B))) helper
∙∙ transportTransport⁻ (ua (Algebra≡ A B)) q
where
helper : transport (sym (ua (Algebra≡ A B))) p ≡ transport (sym (ua (Algebra≡ A B))) q
helper = Σ≡Prop
(λ _ → isPropΣ
(isOfHLevelPathP' 1 (is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isOfHLevelPathP 1 (isPropIsAlgebra _ _ _ _ _ _ _) _ _)
(transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q)))
uaCompAlgebraEquiv : {A B C : Algebra R ℓ'} (f : AlgebraEquiv A B) (g : AlgebraEquiv B C)
→ uaAlgebra (compAlgebraEquiv f g) ≡ uaAlgebra f ∙ uaAlgebra g
uaCompAlgebraEquiv f g = caracAlgebra≡ _ _ (
cong ⟨_⟩ (uaAlgebra (compAlgebraEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
cong ⟨_⟩ (uaAlgebra f) ∙ cong ⟨_⟩ (uaAlgebra g)
≡⟨ sym (cong-∙ ⟨_⟩ (uaAlgebra f) (uaAlgebra g)) ⟩
cong ⟨_⟩ (uaAlgebra f ∙ uaAlgebra g) ∎)
| 43.867816 | 102 | 0.554435 |
cb3cde5424685522eca6898731540be8c2e47972 | 7,672 | agda | Agda | Cubical/Foundations/Univalence.agda | jonsterling/cubical-1 | 794b550f40562e025b5570badd78fdc2e6597779 | [
"MIT"
] | null | null | null | Cubical/Foundations/Univalence.agda | jonsterling/cubical-1 | 794b550f40562e025b5570badd78fdc2e6597779 | [
"MIT"
] | null | null | null | Cubical/Foundations/Univalence.agda | jonsterling/cubical-1 | 794b550f40562e025b5570badd78fdc2e6597779 | [
"MIT"
] | null | null | null | {-
Proof of the standard formulation of the univalence theorem and
various consequences of univalence
- Re-exports Glue types from Cubical.Core.Glue
- The ua constant and its computation rule (up to a path)
- Proof of univalence using that unglue is an equivalence ([EquivContr])
- Equivalence induction ([EquivJ], [elimEquiv])
- Univalence theorem ([univalence])
- The computation rule for ua ([uaβ])
- Isomorphism induction ([elimIso])
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Univalence where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Core.Glue public
using ( Glue ; glue ; unglue ; lineToEquiv )
private
variable
ℓ ℓ' : Level
-- The ua constant
ua : ∀ {A B : Type ℓ} → A ≃ B → A ≡ B
ua {A = A} {B = B} e i = Glue B (λ { (i = i0) → (A , e)
; (i = i1) → (B , idEquiv B) })
uaIdEquiv : {A : Type ℓ} → ua (idEquiv A) ≡ refl
uaIdEquiv {A = A} i j = Glue A {φ = i ∨ ~ j ∨ j} (λ _ → A , idEquiv A)
-- Give detailed type to unglue, mainly for documentation purposes
unglueua : ∀ {A B : Type ℓ} → (e : A ≃ B) → (i : I) (x : ua e i)
→ B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → x }) ]
unglueua e i x = inS (unglue (i ∨ ~ i) x)
-- Proof of univalence using that unglue is an equivalence:
-- unglue is an equivalence
unglueIsEquiv : ∀ (A : Type ℓ) (φ : I)
(f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] T ≃ A)) →
isEquiv {A = Glue A f} (unglue φ)
equiv-proof (unglueIsEquiv A φ f) = λ (b : A) →
let u : I → Partial φ A
u i = λ{ (φ = i1) → equivCtr (f 1=1 .snd) b .snd (~ i) }
ctr : fiber (unglue φ) b
ctr = ( glue (λ { (φ = i1) → equivCtr (f 1=1 .snd) b .fst }) (hcomp u b)
, λ j → hfill u (inS b) (~ j))
in ( ctr
, λ (v : fiber (unglue φ) b) i →
let u' : I → Partial (φ ∨ ~ i ∨ i) A
u' j = λ { (φ = i1) → equivCtrPath (f 1=1 .snd) b v i .snd (~ j)
; (i = i0) → hfill u (inS b) j
; (i = i1) → v .snd (~ j) }
in ( glue (λ { (φ = i1) → equivCtrPath (f 1=1 .snd) b v i .fst }) (hcomp u' b)
, λ j → hfill u' (inS b) (~ j)))
-- Any partial family of equivalences can be extended to a total one
-- from Glue [ φ ↦ (T,f) ] A to A
unglueEquiv : ∀ (A : Type ℓ) (φ : I)
(f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] T ≃ A)) →
(Glue A f) ≃ A
unglueEquiv A φ f = ( unglue φ , unglueIsEquiv A φ f )
-- The following is a formulation of univalence proposed by Martín Escardó:
-- https://groups.google.com/forum/#!msg/homotopytypetheory/HfCB_b-PNEU/Ibb48LvUMeUJ
-- See also Theorem 5.8.4 of the HoTT Book.
--
-- The reason we have this formulation in the core library and not the
-- standard one is that this one is more direct to prove using that
-- unglue is an equivalence. The standard formulation can be found in
-- Cubical/Basics/Univalence.
--
EquivContr : ∀ (A : Type ℓ) → isContr (Σ[ T ∈ Type ℓ ] T ≃ A)
EquivContr {ℓ = ℓ} A =
( (A , idEquiv A)
, idEquiv≡ )
where
idEquiv≡ : (y : Σ (Type ℓ) (λ T → T ≃ A)) → (A , idEquiv A) ≡ y
idEquiv≡ w = \ { i .fst → Glue A (f i)
; i .snd .fst → unglueEquiv _ _ (f i) .fst
; i .snd .snd .equiv-proof → unglueEquiv _ _ (f i) .snd .equiv-proof
}
where
f : ∀ i → PartialP (~ i ∨ i) (λ x → Σ[ T ∈ Type ℓ ] T ≃ A)
f i = λ { (i = i0) → A , idEquiv A ; (i = i1) → w }
contrSinglEquiv : {A B : Type ℓ} (e : A ≃ B) → (B , idEquiv B) ≡ (A , e)
contrSinglEquiv {A = A} {B = B} e =
isContr→isProp (EquivContr B) (B , idEquiv B) (A , e)
-- Equivalence induction
EquivJ : (P : (A B : Type ℓ) → (e : B ≃ A) → Type ℓ')
→ (r : (A : Type ℓ) → P A A (idEquiv A))
→ (A B : Type ℓ) → (e : B ≃ A) → P A B e
EquivJ P r A B e = subst (λ x → P A (x .fst) (x .snd)) (contrSinglEquiv e) (r A)
-- Eliminate equivalences by just looking at the underlying function
elimEquivFun : (B : Type ℓ) (P : (A : Type ℓ) → (A → B) → Type ℓ')
→ (r : P B (λ x → x))
→ (A : Type ℓ) → (e : A ≃ B) → P A (e .fst)
elimEquivFun B P r a e = subst (λ x → P (x .fst) (x .snd .fst)) (contrSinglEquiv e) r
-- Assuming that we have an inverse to ua we can easily prove univalence
module Univalence (au : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → A ≃ B)
(auid : ∀ {ℓ} {A B : Type ℓ} → au refl ≡ idEquiv A) where
thm : ∀ {ℓ} {A B : Type ℓ} → isEquiv au
thm {A = A} {B = B} =
isoToIsEquiv {B = A ≃ B}
(iso au ua
(EquivJ (λ _ _ e → au (ua e) ≡ e) (λ X → (cong au uaIdEquiv) ∙ (auid {B = B})) _ _)
(J (λ X p → ua (au p) ≡ p) ((cong ua (auid {B = B})) ∙ uaIdEquiv)))
pathToEquiv : {A B : Type ℓ} → A ≡ B → A ≃ B
pathToEquiv p = lineToEquiv (λ i → p i)
pathToEquivRefl : {A : Type ℓ} → pathToEquiv refl ≡ idEquiv A
pathToEquivRefl {A = A} = equivEq _ _ (λ i x → transp (λ _ → A) i x)
-- Univalence
univalence : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B)
univalence = ( pathToEquiv , Univalence.thm pathToEquiv pathToEquivRefl )
-- The original map from UniMath/Foundations
eqweqmap : {A B : Type ℓ} → A ≡ B → A ≃ B
eqweqmap {A = A} e = J (λ X _ → A ≃ X) (idEquiv A) e
eqweqmapid : {A : Type ℓ} → eqweqmap refl ≡ idEquiv A
eqweqmapid {A = A} = JRefl (λ X _ → A ≃ X) (idEquiv A)
univalenceStatement : {A B : Type ℓ} → isEquiv (eqweqmap {ℓ} {A} {B})
univalenceStatement = Univalence.thm eqweqmap eqweqmapid
univalenceUAH : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B)
univalenceUAH = ( _ , univalenceStatement )
univalencePath : {A B : Type ℓ} → (A ≡ B) ≡ Lift (A ≃ B)
univalencePath = ua (compEquiv univalence LiftEquiv)
-- The computation rule for ua. Because of "ghcomp" it is now very
-- simple compared to cubicaltt:
-- https://github.com/mortberg/cubicaltt/blob/master/examples/univalence.ctt#L202
uaβ : {A B : Type ℓ} (e : A ≃ B) (x : A) → transport (ua e) x ≡ e .fst x
uaβ e x = transportRefl (e .fst x)
-- Alternative version of EquivJ that only requires a predicate on
-- functions
elimEquiv : {B : Type ℓ} (P : {A : Type ℓ} → (A → B) → Type ℓ') →
(d : P (idfun B)) → {A : Type ℓ} → (e : A ≃ B) → P (e .fst)
elimEquiv P d e = subst (λ x → P (x .snd .fst)) (contrSinglEquiv e) d
-- Isomorphism induction
elimIso : {B : Type ℓ} → (Q : {A : Type ℓ} → (A → B) → (B → A) → Type ℓ') →
(h : Q (idfun B) (idfun B)) → {A : Type ℓ} →
(f : A → B) → (g : B → A) → section f g → retract f g → Q f g
elimIso {ℓ} {ℓ'} {B} Q h {A} f g sfg rfg = rem1 f g sfg rfg
where
P : {A : Type ℓ} → (f : A → B) → Type (ℓ-max ℓ' ℓ)
P {A} f = (g : B → A) → section f g → retract f g → Q f g
rem : P (idfun B)
rem g sfg rfg = subst (Q (idfun B)) (λ i b → (sfg b) (~ i)) h
rem1 : {A : Type ℓ} → (f : A → B) → P f
rem1 f g sfg rfg = elimEquiv P rem (f , isoToIsEquiv (iso f g sfg rfg)) g sfg rfg
uaInvEquiv : ∀ {A B : Type ℓ} → (e : A ≃ B) → ua (invEquiv e) ≡ sym (ua e)
uaInvEquiv e = EquivJ (λ _ _ e → ua (invEquiv e) ≡ sym (ua e)) rem _ _ e
where
rem : (A : Type ℓ) → ua (invEquiv (idEquiv A)) ≡ sym (ua (idEquiv A))
rem A = cong ua (invEquivIdEquiv A)
uaCompEquiv : ∀ {A B C : Type ℓ} → (e : A ≃ B) (f : B ≃ C) → ua (compEquiv e f) ≡ ua e ∙ ua f
uaCompEquiv {C = C} = EquivJ (λ A B e → (f : A ≃ C) → ua (compEquiv e f) ≡ ua e ∙ ua f) rem _ _
where
rem : (A : Type _) (f : A ≃ C) → ua (compEquiv (idEquiv A) f) ≡ ua (idEquiv A) ∙ ua f
rem _ f = cong ua (compEquivIdEquiv f) ∙ sym (cong (λ x → x ∙ ua f) uaIdEquiv ∙ sym (lUnit (ua f)))
| 41.026738 | 101 | 0.55305 |
100eedacc5c506b03d1c982f5b0177e173dbf582 | 175,649 | agda | Agda | Reals.agda | z-murray/AnalysisAgda | 6fbaca08b1d63b5765d184f6284fb0e58c9f5e52 | [
"MIT"
] | null | null | null | Reals.agda | z-murray/AnalysisAgda | 6fbaca08b1d63b5765d184f6284fb0e58c9f5e52 | [
"MIT"
] | null | null | null | Reals.agda | z-murray/AnalysisAgda | 6fbaca08b1d63b5765d184f6284fb0e58c9f5e52 | [
"MIT"
] | null | null | null | {-# 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 using (Rel)
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ℚᵘ; ↥_; ↧_; ↧ₙ_)
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
import Algebra.Solver.Ring as Solver
import Algebra.Solver.Ring.AlmostCommutativeRing as ACR
open ℚᵘ
record ℝ : Set where
constructor mkℝ
field
-- No n≢0 condition for seq
seq : ℕ -> ℚᵘ
reg : ∀ (m n : ℕ) -> {m≢0 : m ≢0} -> {n≢0 : n ≢0} ->
ℚ.∣ seq m ℚ.- seq n ∣ ℚ.≤ ((+ 1) / m) {m≢0} ℚ.+ ((+ 1) / n) {n≢0}
open ℝ
infix 4 _≃_
_≃_ : Rel ℝ 0ℓ
x ≃ y = ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ ((+ 2) / n) {n≢0}
≃-refl : Reflexive _≃_
≃-refl {x} (suc k) = begin
ℚ.∣ seq x n ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (seq x n)) ⟩
ℚ.∣ 0ℚᵘ ∣ ≈⟨ ℚP.≃-refl ⟩
0ℚᵘ ≤⟨ ℚP.∣p∣≃p⇒0≤p ℚP.≃-refl ⟩
((+ 2) / n) ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k
≃-symm : Symmetric _≃_
≃-symm {x} {y} x≃y (suc k) = begin
(ℚ.∣ seq y n ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.≃-trans (ℚP.≃-sym (ℚP.≃-reflexive (ℚP.∣-p∣≡∣p∣ (seq y n ℚ.- seq x n))))
(ℚP.∣-∣-cong (solve 2 (λ a b -> (:- (a :- b)) := b :- a) (ℚ.*≡* _≡_.refl) (seq y n) (seq x n)))) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ x≃y n ⟩
(+ 2) / n ∎)
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k
lemma1A : ∀ (x y : ℝ) -> x ≃ y -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ ((+ 1) / j) {j≢0}
lemma1A x y x≃y (suc j) {j≢0} = 2 ℕ.* (suc j) ,
λ { (suc n) N<n → ℚP.≤-trans (x≃y (suc n)) (*≤* (+≤+ (ℕP.<⇒≤ (subst (ℕ._<_ (2 ℕ.* (suc j))) (cong suc (sym (ℕP.+-identityʳ n))) N<n))))}
abstract
no-0-divisors : ∀ (m n : ℕ) -> m ≢0 -> n ≢0 -> m ℕ.* n ≢0
no-0-divisors (suc m) (suc n) m≢0 n≢0 with (suc m) ℕ.* (suc n) ℕ.≟ 0
... | res = _
m≤∣m∣ : ∀ (m : ℤ) -> m ℤ.≤ + ℤ.∣ m ∣
m≤∣m∣ (+_ n) = ℤP.≤-reflexive _≡_.refl
m≤∣m∣ (-[1+_] n) = ℤ.-≤+
pos⇒≢0 : ∀ p → ℚ.Positive p → ℤ.∣ ↥ p ∣ ≢0
pos⇒≢0 p p>0 = fromWitnessFalse (contraposition ℤP.∣n∣≡0⇒n≡0 (≢-sym (ℤP.<⇒≢ (ℤP.positive⁻¹ p>0))))
0<⇒pos : ∀ p -> 0ℚᵘ ℚ.< p -> ℚ.Positive p
0<⇒pos p p>0 = ℚ.positive p>0
archimedean-ℚ : ∀ (p r : ℚᵘ) -> ℚ.Positive p -> ∃ λ (N : ℕ) -> r ℚ.< ((+ N) ℤ.* (↥ p)) / (↧ₙ p)
archimedean-ℚ (mkℚᵘ (+ p) q-1) (mkℚᵘ u v-1) p/q>0 = ℤ.∣ (+ 1) ℤ.+ t ∣ , ℚ.*<* (begin-strict
u ℤ.* (+ q) ≡⟨ a≡a%ℕn+[a/ℕn]*n (u ℤ.* (+ q)) (p ℕ.* v) ⟩
(+ r) ℤ.+ (t ℤ.* (+ (p ℕ.* v))) <⟨ ℤP.+-monoˡ-< (t ℤ.* (+ (p ℕ.* v))) (+<+ (n%d<d (u ℤ.* (+ q)) (+ (p ℕ.* v)))) ⟩
(+ (p ℕ.* v)) ℤ.+ (t ℤ.* (+ (p ℕ.* v))) ≡⟨ solve 2 (λ pv t ->
pv :+ (t :* pv) := (con (+ 1) :+ t) :* pv)
_≡_.refl (+ (p ℕ.* v)) t ⟩
((+ 1) ℤ.+ t) ℤ.* (+ (p ℕ.* v)) ≤⟨ ℤP.*-monoʳ-≤-nonNeg (p ℕ.* v) (m≤∣m∣ ((+ 1) ℤ.+ t)) ⟩
(+ ℤ.∣ (+ 1) ℤ.+ t ∣) ℤ.* (+ (p ℕ.* v)) ≡⟨ cong (λ x -> (+ ℤ.∣ (+ 1) ℤ.+ t ∣) ℤ.* x) (sym (ℤP.pos-distrib-* p v)) ⟩
(+ ℤ.∣ (+ 1) ℤ.+ t ∣) ℤ.* ((+ p) ℤ.* (+ v)) ≡⟨ sym (ℤP.*-assoc (+ ℤ.∣ (+ 1) ℤ.+ t ∣) (+ p) (+ v)) ⟩
(+ ℤ.∣ (+ 1) ℤ.+ t ∣) ℤ.* + p ℤ.* + v ∎)
where
open ℤP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
q : ℕ
q = suc q-1
v : ℕ
v = suc v-1
p≢0 : p ≢0
p≢0 = pos⇒≢0 ((+ p) / q) p/q>0
pv≢0 : p ℕ.* v ≢0
pv≢0 = no-0-divisors p v p≢0 _
r : ℕ
r = ((u ℤ.* (+ q)) modℕ (p ℕ.* v)) {pv≢0}
t : ℤ
t = ((u ℤ.* (+ q)) divℕ (p ℕ.* v)) {pv≢0}
alternate : ∀ (p : ℚᵘ) -> ∀ (N : ℕ) -> ((+ N) ℤ.* (↥ p)) / (↧ₙ p) ℚ.≃ ((+ N) / 1) ℚ.* p
alternate p N = ℚ.*≡* (cong (λ x -> ((+ N) ℤ.* (↥ p)) ℤ.* x) (ℤP.*-identityˡ (↧ p)))
get0ℚᵘ : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ((+ 0) / n) {n≢0} ℚ.≃ 0ℚᵘ
get0ℚᵘ (suc n) = ℚ.*≡* (trans (ℤP.*-zeroˡ (+ 1)) (sym (ℤP.*-zeroˡ (+ (suc n)))))
lemma1B : ∀ (x y : ℝ) -> (∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) ->
∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ ((+ 1) / j) {j≢0}) -> x ≃ y
lemma1B x y hyp (suc k₁) = lemA lemB
where
n : ℕ
n = suc k₁
∣xn-yn∣ : ℚᵘ
∣xn-yn∣ = ℚ.∣ seq x n ℚ.- seq y n ∣
2/n : ℚᵘ
2/n = (+ 2) / n
lemA : (∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∣xn-yn∣ ℚ.≤ 2/n ℚ.+ ((+ 3) / j) {j≢0}) ->
∣xn-yn∣ ℚ.≤ 2/n
lemA hyp with ℚP.<-cmp ∣xn-yn∣ 2/n
... | tri< a ¬b ¬c = ℚP.<⇒≤ a
... | tri≈ ¬a b ¬c = ℚP.≤-reflexive b
... | tri> ¬a ¬b c with archimedean-ℚ (∣xn-yn∣ ℚ.- 2/n) ((+ 3) / 1) isPos
where
0<res : 0ℚᵘ ℚ.< ∣xn-yn∣ ℚ.- 2/n
0<res = ℚP.<-respˡ-≃ (ℚP.+-inverseʳ 2/n) (ℚP.+-monoˡ-< (ℚ.- 2/n) c)
isPos : ℚ.Positive (∣xn-yn∣ ℚ.- 2/n)
isPos = ℚ.positive 0<res
... | 0 , 3<Nres = ⊥-elim (ℚP.<-asym 3<Nres (ℚP.<-respˡ-≃ (ℚP.≃-sym (get0ℚᵘ _)) (ℚP.positive⁻¹ {(+ 3) / 1} _)))
... | suc M , 3<Nres = ⊥-elim (ℚP.<-irrefl ℚP.≃-refl (ℚP.<-≤-trans part4 part5))
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
N : ℕ
N = suc M
part1 : (+ 3) / 1 ℚ.< ((+ N) / 1) ℚ.* (∣xn-yn∣ ℚ.- 2/n)
part1 = ℚP.<-respʳ-≃ (alternate (∣xn-yn∣ ℚ.- 2/n) N) 3<Nres
part2a : ((+ 1) / N) ℚ.* (((+ N) / 1) ℚ.* (∣xn-yn∣ ℚ.- 2/n)) ℚ.≃ ∣xn-yn∣ ℚ.- 2/n
part2a = begin-equality
((+ 1) / N) ℚ.* (((+ N) / 1) ℚ.* (∣xn-yn∣ ℚ.- 2/n)) ≈⟨ ℚP.≃-sym (ℚP.*-assoc ((+ 1) / N) ((+ N) / 1) (∣xn-yn∣ ℚ.- 2/n)) ⟩
((+ 1) / N) ℚ.* ((+ N) / 1) ℚ.* (∣xn-yn∣ ℚ.- 2/n) ≈⟨ ℚP.*-congʳ {∣xn-yn∣ ℚ.- 2/n} (ℚ.*≡* {((+ 1) / N) ℚ.* ((+ N) / 1)} {ℚ.1ℚᵘ}
(solve 1 (λ N ->
(con (+ 1) :* N) :* con (+ 1) := con (+ 1) :* (N :* con (+ 1)))
_≡_.refl (+ N))) ⟩
ℚ.1ℚᵘ ℚ.* (∣xn-yn∣ ℚ.- 2/n) ≈⟨ ℚP.*-identityˡ (∣xn-yn∣ ℚ.- 2/n) ⟩
∣xn-yn∣ ℚ.- 2/n ∎
part2 : ((+ 1) / N) ℚ.* ((+ 3) / 1) ℚ.< ∣xn-yn∣ ℚ.- 2/n
part2 = ℚP.<-respʳ-≃ part2a (ℚP.*-monoʳ-<-pos {(+ 1) / N} _ part1)
part3a : ((+ 1) / N) ℚ.* ((+ 3) / 1) ℚ.≃ (+ 3) / N
part3a = ℚ.*≡* (trans (cong (λ x -> x ℤ.* (+ N)) (ℤP.*-identityˡ (+ 3))) (cong (λ x -> (+ 3) ℤ.* x) (sym (ℤP.*-identityʳ (+ N)))))
part3 : (+ 3) / N ℚ.< ∣xn-yn∣ ℚ.- 2/n
part3 = ℚP.<-respˡ-≃ part3a part2
part4 : 2/n ℚ.+ ((+ 3) / N) ℚ.< ∣xn-yn∣
part4 = ℚP.<-respˡ-≃ (ℚP.+-comm ((+ 3) / N) 2/n) (ℚP.<-respʳ-≃ (ℚP.≃-trans (ℚP.+-congʳ ∣xn-yn∣ (ℚP.+-inverseʳ 2/n)) (ℚP.+-identityʳ ∣xn-yn∣))
(ℚP.<-respʳ-≃ (ℚP.+-assoc ∣xn-yn∣ (ℚ.- 2/n) 2/n) (ℚP.+-monoˡ-< 2/n part3)))
part5 : ∣xn-yn∣ ℚ.≤ 2/n ℚ.+ ((+ 3) / N)
part5 = hyp N
lemB : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∣xn-yn∣ ℚ.≤ 2/n ℚ.+ ((+ 3) / j) {j≢0}
lemB (suc k₂) with hyp (suc k₂)
... | N , proof = begin
∣xn-yn∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ xn yn xm ym ->
xn ℚ:- yn ℚ:= (xn ℚ:- xm) ℚ:+ (xm ℚ:- ym) ℚ:+ (ym ℚ:- yn))
(ℚ.*≡* _≡_.refl) (seq x n) (seq y n) (seq x m) (seq y m)) ⟩
ℚ.∣ (seq x n ℚ.- seq x m) ℚ.+ (seq x m ℚ.- seq y m) ℚ.+ (seq y m ℚ.- seq y n) ∣ ≤⟨ ℚP.≤-trans (ℚP.∣p+q∣≤∣p∣+∣q∣
((seq x n ℚ.- seq x m) ℚ.+ (seq x m ℚ.- seq y m)) (seq y m ℚ.- seq y n))
(ℚP.+-monoˡ-≤ ℚ.∣ seq y m ℚ.- seq y n ∣
(ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x n ℚ.- seq x m) (seq x m ℚ.- seq y m))) ⟩
ℚ.∣ seq x n ℚ.- seq x m ∣ ℚ.+ ℚ.∣ seq x m ℚ.- seq y m ∣ ℚ.+ ℚ.∣ seq y m ℚ.- seq y n ∣ ≤⟨ ℚP.+-monoʳ-≤ (ℚ.∣ seq x n ℚ.- seq x m ∣ ℚ.+ ℚ.∣ seq x m ℚ.- seq y m ∣)
(reg y m n) ⟩
ℚ.∣ seq x n ℚ.- seq x m ∣ ℚ.+ ℚ.∣ seq x m ℚ.- seq y m ∣ ℚ.+ (((+ 1) / m) ℚ.+ (+ 1) / n) ≤⟨ ℚP.+-monoˡ-≤ (((+ 1) / m) ℚ.+ (+ 1) / n)
(ℚP.+-monoʳ-≤ ℚ.∣ seq x n ℚ.- seq x m ∣ (proof m (ℕP.m≤m⊔n (suc N) j))) ⟩
ℚ.∣ seq x n ℚ.- seq x m ∣ ℚ.+ ((+ 1) / j) ℚ.+ (((+ 1) / m) ℚ.+ ((+ 1) / n)) ≤⟨ ℚP.+-monoˡ-≤ (((+ 1) / m) ℚ.+ (+ 1) / n)
(ℚP.+-monoˡ-≤ ((+ 1) / j) (reg x n m)) ⟩
(((+ 1) / n) ℚ.+ (+ 1) / m) ℚ.+ ((+ 1) / j) ℚ.+ (((+ 1) / m) ℚ.+ ((+ 1) / n)) ≤⟨ ℚP.+-monoˡ-≤ ((((+ 1) / m) ℚ.+ ((+ 1) / n)))
(ℚP.+-monoˡ-≤ ((+ 1) / j)
(ℚP.+-monoʳ-≤ ((+ 1) / n) 1/m≤1/j)) ⟩
(((+ 1) / n) ℚ.+ (+ 1) / j) ℚ.+ ((+ 1) / j) ℚ.+ (((+ 1) / m) ℚ.+ ((+ 1) / n)) ≤⟨ ℚP.+-monoʳ-≤ ((((+ 1) / n) ℚ.+ (+ 1) / j) ℚ.+ ((+ 1) / j))
(ℚP.+-monoˡ-≤ ((+ 1) / n) 1/m≤1/j) ⟩
(((+ 1) / n) ℚ.+ (+ 1) / j) ℚ.+ ((+ 1) / j) ℚ.+ (((+ 1) / j) ℚ.+ (+ 1) / n) ≈⟨ ℚ.*≡* (solve 2 (λ n j ->
{- Function for the solver -}
(((((con (+ 1) :* j :+ con (+ 1) :* n) :* j) :+ con (+ 1) :* (n :* j)) :* (j :* n)) :+ ((con (+ 1) :* n :+ con (+ 1) :* j) :* ((n :* j) :* j))) :* (n :* j) :=
((con (+ 2) :* j :+ con (+ 3) :* n) :* (((n :* j) :* j) :* (j :* n)))) _≡_.refl (+ n) (+ j)) ⟩
((+ 2) / n) ℚ.+ ((+ 3) / j) ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
j : ℕ
j = suc k₂
m : ℕ
m = (suc N) ℕ.⊔ j
1/m≤1/j : ((+ 1) / m) ℚ.≤ (+ 1) / j
1/m≤1/j = *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityˡ (+ j)))
(ℤP.≤-trans (+≤+ (ℕP.m≤n⊔m (suc N) j))
(ℤP.≤-reflexive (sym (ℤP.*-identityˡ (+ m))))))
≃-trans : Transitive _≃_
≃-trans {x} {y} {z} x≃y y≃z = lemma1B x z lem
where
lem : ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x n ℚ.- seq z n ∣ ℚ.≤ ((+ 1) / j) {j≢0}
lem (suc k₁) with (lemma1A x y x≃y (2 ℕ.* (suc k₁))) | (lemma1A y z y≃z (2 ℕ.* (suc k₁)))
lem (suc k₁) | N₁ , xy | N₂ , yz = N , λ {n N<n -> begin
ℚ.∣ seq x n ℚ.- seq z n ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 3 (λ x y z ->
x ℚ:- z ℚ:= (x ℚ:- y) ℚ:+ (y ℚ:- z)) (ℚ.*≡* _≡_.refl) (seq x n) (seq y n) (seq z n)) ⟩
ℚ.∣ (seq x n ℚ.- seq y n) ℚ.+ (seq y n ℚ.- seq z n) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x n ℚ.- seq y n) (seq y n ℚ.- seq z n) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.+ ℚ.∣ seq y n ℚ.- seq z n ∣ ≤⟨ ℚP.≤-trans (ℚP.+-monoˡ-≤ ℚ.∣ seq y n ℚ.- seq z n ∣ (xy n (ℕP.m⊔n≤o⇒m≤o (suc N₁) (suc N₂) N<n)))
(ℚP.+-monoʳ-≤ ((+ 1) / (2 ℕ.* j)) (yz n (ℕP.m⊔n≤o⇒n≤o (suc N₁) (suc N₂) N<n))) ⟩
((+ 1) / (2 ℕ.* j)) ℚ.+ ((+ 1) / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(con (+ 1) :* (con (+ 2) :* j) :+ (con (+ 1) :* (con (+ 2) :* j))) :* j :=
(con (+ 1) :* ((con (+ 2) :* j) :* (con (+ 2) :* j)))) _≡_.refl (+ j)) ⟩
(+ 1) / j ∎}
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:=_ to _ℚ:=_
; _:*_ to _ℚ:*_
; _:-_ to _ℚ:-_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
N : ℕ
N = N₁ ℕ.⊔ N₂
j : ℕ
j = suc k₁
antidensity-ℤ : ¬(∃ λ (n : ℤ) -> + 0 ℤ.< n × n ℤ.< + 1)
antidensity-ℤ (+[1+ n ] , +<+ m<n , +<+ (ℕ.s≤s ()))
infixl 6 _+_ _-_ _⊔_ _⊓_
infixl 7 _*_
infix 8 -_ _⋆
_+_ : ℝ -> ℝ -> ℝ
seq (x + y) n = seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)
reg (x + y) (suc k₁) (suc k₂) = begin
ℚ.∣ (seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m))
ℚ.- (seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ xm ym xn yn ->
(xm ℚ:+ ym) ℚ:- (xn ℚ:+ yn) ℚ:=
(xm ℚ:- xn) ℚ:+ (ym ℚ:- yn))
(ℚ.*≡* _≡_.refl)
(seq x (2 ℕ.* m)) (seq y (2 ℕ.* m))
(seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
ℚ.∣ (seq x (2 ℕ.* m) ℚ.- seq x (2 ℕ.* n))
ℚ.+ (seq y (2 ℕ.* m) ℚ.- seq y (2 ℕ.* n)) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x (2 ℕ.* m) ℚ.- seq x (2 ℕ.* n))
(seq y (2 ℕ.* m) ℚ.- seq y (2 ℕ.* n)) ⟩
ℚ.∣ seq x (2 ℕ.* m) ℚ.- seq x (2 ℕ.* n) ∣
ℚ.+ ℚ.∣ seq y (2 ℕ.* m) ℚ.- seq y (2 ℕ.* n)∣ ≤⟨ ℚP.≤-trans (ℚP.+-monoʳ-≤ ℚ.∣ seq x (2 ℕ.* m) ℚ.- seq x (2 ℕ.* n) ∣
(reg y (2 ℕ.* m) (2 ℕ.* n)))
(ℚP.+-monoˡ-≤ (((+ 1) / (2 ℕ.* m)) ℚ.+ ((+ 1) / (2 ℕ.* n)))
(reg x (2 ℕ.* m) (2 ℕ.* n))) ⟩
(((+ 1) / (2 ℕ.* m)) ℚ.+ ((+ 1) / (2 ℕ.* n))) ℚ.+ (((+ 1) / (2 ℕ.* m))
ℚ.+ ((+ 1) / (2 ℕ.* n))) ≈⟨ ℚ.*≡* (solve 2 (λ m n ->
(((con (+ 1) :* (con (+ 2) :* n) :+ con (+ 1) :* (con (+ 2) :* m))
:* ((con (+ 2) :* m) :* (con (+ 2) :* n))) :+
(con (+ 1) :* (con (+ 2) :* n) :+ con (+ 1) :* (con (+ 2) :* m))
:* ((con (+ 2) :* m) :* (con (+ 2) :* n))) :* (m :* n) :=
(con (+ 1) :* n :+ con (+ 1) :* m) :*
(((con (+ 2) :* m) :* (con (+ 2) :* n)) :*
(((con (+ 2) :* m) :* (con (+ 2) :* n)))))
_≡_.refl (+ m) (+ n)) ⟩
((+ 1) / m) ℚ.+ ((+ 1) / n) ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
2ℚᵘ : ℚᵘ
2ℚᵘ = (+ 2) / 1
least-ℤ>ℚ : ℚᵘ -> ℤ
least-ℤ>ℚ p = + 1 ℤ.+ (↥ p divℕ ↧ₙ p)
abstract
least-ℤ>ℚ-greater : ∀ (p : ℚᵘ) -> p ℚ.< least-ℤ>ℚ p / 1
least-ℤ>ℚ-greater (mkℚᵘ p q-1) = ℚ.*<* (begin-strict
p ℤ.* (+ 1) ≡⟨ trans (ℤP.*-identityʳ p) (a≡a%ℕn+[a/ℕn]*n p q) ⟩
(+ r) ℤ.+ t ℤ.* (+ q) <⟨ ℤP.+-monoˡ-< (t ℤ.* (+ q)) (+<+ (n%ℕd<d p q)) ⟩
(+ q) ℤ.+ t ℤ.* (+ q) ≡⟨ solve 2 (λ q t -> q :+ t :* q := (con (+ 1) :+ t) :* q) _≡_.refl (+ q) t ⟩
(+ 1 ℤ.+ t) ℤ.* (+ q) ∎)
where
open ℤP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
q : ℕ
q = suc q-1
t : ℤ
t = p divℕ q
r : ℕ
r = p modℕ q
least-ℤ>ℚ-least : ∀ (p : ℚᵘ) -> ∀ (n : ℤ) -> p ℚ.< n / 1 -> least-ℤ>ℚ p ℤ.≤ n
least-ℤ>ℚ-least (mkℚᵘ p q-1) n p/q<n with (least-ℤ>ℚ (mkℚᵘ p q-1)) ℤP.≤? n
... | .Bool.true because ofʸ P = P
... | .Bool.false because ofⁿ ¬P = ⊥-elim (antidensity-ℤ (n ℤ.- t , 0<n-t ,′ n-t<1))
where
open ℤP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
q : ℕ
q = suc q-1
t : ℤ
t = p divℕ q
r : ℕ
r = p modℕ q
n-t<1 : n ℤ.- t ℤ.< + 1
n-t<1 = ℤP.<-≤-trans (ℤP.+-monoˡ-< (ℤ.- t) (ℤP.≰⇒> ¬P))
(ℤP.≤-reflexive (solve 1 (λ t -> con (+ 1) :+ t :- t := con (+ 1)) _≡_.refl t))
part1 : (+ r) ℤ.+ t ℤ.* (+ q) ℤ.< n ℤ.* (+ q)
part1 = begin-strict
(+ r) ℤ.+ t ℤ.* (+ q) ≡⟨ trans (sym (a≡a%ℕn+[a/ℕn]*n p q)) (sym (ℤP.*-identityʳ p)) ⟩
p ℤ.* (+ 1) <⟨ ℚP.drop-*<* p/q<n ⟩
n ℤ.* (+ q) ∎
part2 : (+ r) ℤ.< (n ℤ.- t) ℤ.* (+ q)
part2 = begin-strict
+ r ≡⟨ solve 2 (λ r t -> r := r :+ t :- t) _≡_.refl (+ r) (t ℤ.* (+ q)) ⟩
(+ r) ℤ.+ t ℤ.* (+ q) ℤ.- t ℤ.* (+ q) <⟨ ℤP.+-monoˡ-< (ℤ.- (t ℤ.* + q)) part1 ⟩
n ℤ.* (+ q) ℤ.- t ℤ.* (+ q) ≡⟨ solve 3 (λ n q t -> n :* q :- t :* q := (n :- t) :* q) _≡_.refl n (+ q) t ⟩
(n ℤ.- t) ℤ.* (+ q) ∎
part3 : + 0 ℤ.< (n ℤ.- t) ℤ.* (+ q)
part3 = ℤP.≤-<-trans (+≤+ ℕ.z≤n) part2
0<n-t : + 0 ℤ.< n ℤ.- t
0<n-t = ℤP.*-cancelʳ-<-nonNeg q (ℤP.≤-<-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ q))) part3)
least : ∀ (p : ℚᵘ) -> ∃ λ (K : ℤ) ->
p ℚ.< (K / 1) × (∀ (n : ℤ) -> p ℚ.< (n / 1) -> K ℤ.≤ n)
least p = least-ℤ>ℚ p , least-ℤ>ℚ-greater p ,′ least-ℤ>ℚ-least p
K : ℝ -> ℕ
K x with ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ
... | mkℚᵘ p q-1 = suc ℤ.∣ p divℕ (suc q-1) ∣
private
Kx=1+t : ∀ (x : ℝ) -> + K x ≡ (+ 1) ℤ.+ (↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) divℕ ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ))
Kx=1+t x = sym (trans (cong (λ x -> (+ 1) ℤ.+ x) (sym ∣t∣=t)) _≡_.refl)
where
t : ℤ
t = ↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) divℕ ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)
0≤∣x₁∣+2 : 0ℚᵘ ℚ.≤ ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ
0≤∣x₁∣+2 = ℚP.≤-trans (ℚP.0≤∣p∣ (seq x 1)) (ℚP.p≤p+q {ℚ.∣ seq x 1 ∣} {2ℚᵘ} _)
∣t∣=t : + ℤ.∣ t ∣ ≡ t
∣t∣=t = ℤP.0≤n⇒+∣n∣≡n (0≤n⇒0≤n/ℕd (↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)) (↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)) (ℚP.≥0⇒↥≥0 0≤∣x₁∣+2))
canonical-property : ∀ (x : ℝ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< (+ K x) / 1 ×
(∀ (n : ℤ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< n / 1 -> + K x ℤ.≤ n)
canonical-property x = left ,′ right
where
left : ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< (+ K x) / 1
left = ℚP.<-respʳ-≃ (ℚP.≃-reflexive (ℚP./-cong (sym (Kx=1+t x)) _≡_.refl _ _))
(least-ℤ>ℚ-greater (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ))
right : ∀ (n : ℤ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< n / 1 -> + K x ℤ.≤ n
right n hyp = ℤP.≤-trans (ℤP.≤-reflexive (Kx=1+t x)) (least-ℤ>ℚ-least (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) n hyp)
canonical-greater : ∀ (x : ℝ) -> ∀ (n : ℕ) -> {n ≢0} -> ℚ.∣ seq x n ∣ ℚ.< (+ K x) / 1
canonical-greater x (suc k₁) = begin-strict
ℚ.∣ seq x n ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ xn x1 ->
xn := xn :- x1 :+ x1)
(ℚ.*≡* _≡_.refl) (seq x n) (seq x 1)) ⟩
ℚ.∣ seq x n ℚ.- seq x 1 ℚ.+ seq x 1 ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x n ℚ.- seq x 1) (seq x 1) ⟩
ℚ.∣ seq x n ℚ.- seq x 1 ∣ ℚ.+ ℚ.∣ seq x 1 ∣ ≤⟨ ℚP.+-monoˡ-≤ ℚ.∣ seq x 1 ∣ (reg x n 1) ⟩
(+ 1 / n) ℚ.+ (+ 1 / 1) ℚ.+ ℚ.∣ seq x 1 ∣ ≤⟨ ℚP.+-monoˡ-≤ ℚ.∣ seq x 1 ∣
(ℚP.≤-trans (ℚP.+-monoˡ-≤ (+ 1 / 1) 1/n≤1) ℚP.≤-refl) ⟩
2ℚᵘ ℚ.+ ℚ.∣ seq x 1 ∣ <⟨ ℚP.<-respˡ-≃ (ℚP.+-comm ℚ.∣ seq x 1 ∣ 2ℚᵘ) (proj₁ (canonical-property x)) ⟩
(+ K x) / 1 ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k₁
1/n≤1 : + 1 / n ℚ.≤ + 1 / 1
1/n≤1 = *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityˡ (+ 1)))
(ℤP.≤-trans (+≤+ (ℕ.s≤s ℕ.z≤n)) (ℤP.≤-reflexive (sym (ℤP.*-identityˡ (+ n))))))
∣∣p∣-∣q∣∣≤∣p-q∣ : ∀ p q -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
∣∣p∣-∣q∣∣≤∣p-q∣ p q = [ lemA p q , lemB p q ]′ (ℚP.≤-total ℚ.∣ q ∣ ℚ.∣ p ∣)
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
lemA : ∀ p q -> ℚ.∣ q ∣ ℚ.≤ ℚ.∣ p ∣ -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
lemA p q hyp = begin
ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp) ⟩
ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ≈⟨ ℚP.+-congˡ (ℚ.- ℚ.∣ q ∣) (ℚP.∣-∣-cong (solve 2 (λ p q ->
p := p :- q :+ q) ℚP.≃-refl p q)) ⟩
ℚ.∣ p ℚ.- q ℚ.+ q ∣ ℚ.- ℚ.∣ q ∣ ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- ℚ.∣ q ∣) (ℚP.∣p+q∣≤∣p∣+∣q∣ (p ℚ.- q) q) ⟩
ℚ.∣ p ℚ.- q ∣ ℚ.+ ℚ.∣ q ∣ ℚ.- ℚ.∣ q ∣ ≈⟨ solve 2 (λ x y -> x :+ y :- y := x)
ℚP.≃-refl ℚ.∣ p ℚ.- q ∣ ℚ.∣ q ∣ ⟩
ℚ.∣ p ℚ.- q ∣ ∎
lemB : ∀ p q -> ℚ.∣ p ∣ ℚ.≤ ℚ.∣ q ∣ -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
lemB p q hyp = begin
ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣))) (ℚP.∣-∣-cong
(solve 2 (λ p q -> :- (p :- q) := q :- p) ℚP.≃-refl ℚ.∣ p ∣ ℚ.∣ q ∣)) ⟩
ℚ.∣ ℚ.∣ q ∣ ℚ.- ℚ.∣ p ∣ ∣ ≤⟨ lemA q p hyp ⟩
ℚ.∣ q ℚ.- p ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (q ℚ.- p))) (ℚP.∣-∣-cong
(solve 2 (λ p q -> :- (q :- p) := p :- q) ℚP.≃-refl p q)) ⟩
ℚ.∣ p ℚ.- q ∣ ∎
{-
Reminder: Make the proof of reg (x * y) abstract to avoid performance issues. Maybe do the same
with the other long proofs too.
-}
_*_ : ℝ -> ℝ -> ℝ
seq (x * y) n = seq x (2 ℕ.* (K x ℕ.⊔ K y) ℕ.* n) ℚ.* seq y (2 ℕ.* (K x ℕ.⊔ K y) ℕ.* n)
reg (x * y) (suc k₁) (suc k₂) = begin
ℚ.∣ x₂ₖₘ ℚ.* y₂ₖₘ ℚ.- x₂ₖₙ ℚ.* y₂ₖₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ xm ym xn yn ->
xm ℚ:* ym ℚ:- xn ℚ:* yn ℚ:=
xm ℚ:* (ym ℚ:- yn) ℚ:+ yn ℚ:* (xm ℚ:- xn))
(ℚ.*≡* _≡_.refl) x₂ₖₘ y₂ₖₘ x₂ₖₙ y₂ₖₙ) ⟩
ℚ.∣ x₂ₖₘ ℚ.* (y₂ₖₘ ℚ.- y₂ₖₙ) ℚ.+
y₂ₖₙ ℚ.* (x₂ₖₘ ℚ.- x₂ₖₙ) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (x₂ₖₘ ℚ.* (y₂ₖₘ ℚ.- y₂ₖₙ))
(y₂ₖₙ ℚ.* (x₂ₖₘ ℚ.- x₂ₖₙ)) ⟩
ℚ.∣ x₂ₖₘ ℚ.* (y₂ₖₘ ℚ.- y₂ₖₙ) ∣ ℚ.+
ℚ.∣ y₂ₖₙ ℚ.* (x₂ₖₘ ℚ.- x₂ₖₙ) ∣ ≈⟨ ℚP.≃-trans (ℚP.+-congˡ ℚ.∣ y₂ₖₙ ℚ.* (x₂ₖₘ ℚ.- x₂ₖₙ) ∣
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ₖₘ (y₂ₖₘ ℚ.- y₂ₖₙ)))
(ℚP.+-congʳ (ℚ.∣ x₂ₖₘ ∣ ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣)
(ℚP.∣p*q∣≃∣p∣*∣q∣ y₂ₖₙ (x₂ₖₘ ℚ.- x₂ₖₙ))) ⟩
ℚ.∣ x₂ₖₘ ∣ ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣ ℚ.+
ℚ.∣ y₂ₖₙ ∣ ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣ ≤⟨ ℚP.≤-trans (ℚP.+-monoˡ-≤ (ℚ.∣ y₂ₖₙ ∣ ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣ )
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣} _ ∣x₂ₖₘ∣≤k))
(ℚP.+-monoʳ-≤ ((+ k / 1) ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣)
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣} _ ∣y₂ₖₙ∣≤k)) ⟩
(+ k / 1) ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣ ℚ.+
(+ k / 1) ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣ ≤⟨ ℚP.≤-trans (ℚP.+-monoˡ-≤ ((+ k / 1) ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣)
(ℚP.*-monoʳ-≤-nonNeg {+ k / 1} _ (reg y 2km 2kn)))
(ℚP.+-monoʳ-≤ ((+ k / 1) ℚ.* ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn)))
(ℚP.*-monoʳ-≤-nonNeg {+ k / 1} _ (reg x 2km 2kn))) ⟩
(+ k / 1) ℚ.* ((+ 1 / 2km) ℚ.+
(+ 1 / 2kn)) ℚ.+
(+ k / 1) ℚ.* ((+ 1 / 2km) ℚ.+
(+ 1 / 2kn)) ≈⟨ ℚP.≃-sym (ℚP.*-distribˡ-+ (+ k / 1) ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn)) ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn))) ⟩
(+ k / 1) ℚ.* ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn)
ℚ.+ ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn))) ≈⟨ ℚ.*≡* (solve 3 (λ k m n ->
{- Function for the solver -}
(k :* ((((con (+ 1) :* (con (+ 2) :* k :* n)) :+ (con (+ 1) :* (con (+ 2) :* k :* m))) :* ((con (+ 2) :* k :* m) :* (con (+ 2) :* k :* n))) :+
(((con (+ 1) :* (con (+ 2) :* k :* n)) :+ (con (+ 1) :* (con (+ 2) :* k :* m))) :* ((con (+ 2) :* k :* m) :* (con (+ 2) :* k :* n)))))
:* (m :* n) :=
(con (+ 1) :* n :+ con (+ 1) :* m) :*
(con (+ 1) :* (((con (+ 2) :* k :* m) :* (con (+ 2) :* k :* n)):* ((con (+ 2) :* k :* m) :* (con (+ 2) :* k :* n)))))
-- Other solver inputs
_≡_.refl (+ k) (+ m) (+ n)) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
k : ℕ
k = K x ℕ.⊔ K y
2km : ℕ
2km = 2 ℕ.* k ℕ.* m
2kn : ℕ
2kn = 2 ℕ.* k ℕ.* n
x₂ₖₘ : ℚᵘ
x₂ₖₘ = seq x (2 ℕ.* k ℕ.* m)
x₂ₖₙ : ℚᵘ
x₂ₖₙ = seq x (2 ℕ.* k ℕ.* n)
y₂ₖₘ : ℚᵘ
y₂ₖₘ = seq y (2 ℕ.* k ℕ.* m)
y₂ₖₙ : ℚᵘ
y₂ₖₙ = seq y (2 ℕ.* k ℕ.* n)
∣x₂ₖₘ∣≤k : ℚ.∣ x₂ₖₘ ∣ ℚ.≤ (+ k) / 1
∣x₂ₖₘ∣≤k = ℚP.≤-trans (ℚP.<⇒≤ (canonical-greater x 2km))
(*≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityʳ (+ K x)))
(ℤP.≤-trans (+≤+ (ℕP.m≤m⊔n (K x) (K y))) (ℤP.≤-reflexive (sym (ℤP.*-identityʳ (+ k)))))))
∣y₂ₖₙ∣≤k : ℚ.∣ y₂ₖₙ ∣ ℚ.≤ (+ k) / 1
∣y₂ₖₙ∣≤k = ℚP.≤-trans (ℚP.<⇒≤ (canonical-greater y 2kn))
(*≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityʳ (+ K y)))
(ℤP.≤-trans (+≤+ (ℕP.m≤n⊔m (K x) (K y))) (ℤP.≤-reflexive (sym (ℤP.*-identityʳ (+ k)))))))
p≃q⇒-p≃-q : ∀ (p q : ℚᵘ) -> p ℚ.≃ q -> ℚ.- p ℚ.≃ ℚ.- q
p≃q⇒-p≃-q p q p≃q = ℚP.p-q≃0⇒p≃q (ℚ.- p) (ℚ.- q) (ℚP.≃-trans (ℚP.+-comm (ℚ.- p) (ℚ.- (ℚ.- q)))
(ℚP.≃-trans (ℚP.+-congˡ (ℚ.- p) (ℚP.neg-involutive q))
(ℚP.p≃q⇒p-q≃0 q p (ℚP.≃-sym p≃q))))
p≤∣p∣ : ∀ (p : ℚᵘ) -> p ℚ.≤ ℚ.∣ p ∣
p≤∣p∣ (mkℚᵘ (+_ n) q-1) = ℚP.≤-refl
p≤∣p∣ (mkℚᵘ (-[1+_] n) q-1) = *≤* ℤ.-≤+
{-
The book uses an extra assumption to simplify this proof. It seems, for a proper proof, a 4-way
case split is required, as done below.
-}
_⊔_ : ℝ -> ℝ -> ℝ
seq (x ⊔ y) n = (seq x n) ℚ.⊔ (seq y n)
reg (x ⊔ y) (suc k₁) (suc k₂) = [ left , right ]′ (ℚP.≤-total (seq x m ℚ.⊔ seq y m) (seq x n ℚ.⊔ seq y n))
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
lem : ∀ (a b c d : ℚᵘ) -> a ℚ.≤ b -> ∀ (r s : ℕ) -> {r≢0 : r ≢0} -> {s≢0 : s ≢0} ->
ℚ.∣ b ℚ.- d ∣ ℚ.≤ ((+ 1) / r) {r≢0} ℚ.+ ((+ 1) / s) {s≢0} ->
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ℚ.≤ ((+ 1) / r) {r≢0} ℚ.+ ((+ 1) / s) {s≢0}
lem a b c d a≤b r s hyp = begin
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ≤⟨ ℚP.+-monoʳ-≤ (a ℚ.⊔ b) (ℚP.neg-mono-≤ (ℚP.p≤q⊔p c d)) ⟩
(a ℚ.⊔ b) ℚ.- d ≈⟨ ℚP.+-congˡ (ℚ.- d) (ℚP.p≤q⇒p⊔q≃q a≤b) ⟩
b ℚ.- d ≤⟨ p≤∣p∣ (b ℚ.- d) ⟩
ℚ.∣ b ℚ.- d ∣ ≤⟨ hyp ⟩
((+ 1) / r) ℚ.+ ((+ 1) / s) ∎
left : seq x m ℚ.⊔ seq y m ℚ.≤ seq x n ℚ.⊔ seq y n ->
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
left hyp1 = [ xn≤yn , yn≤xn ]′ (ℚP.≤-total (seq x n) (seq y n))
where
xn≤yn : seq x n ℚ.≤ seq y n -> ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
xn≤yn hyp2 = begin
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ ((seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n))))
(ℚP.∣-∣-cong (solve 2 (λ a b -> :- (a :- b) := b :- a)
(ℚ.*≡* _≡_.refl) (seq x m ℚ.⊔ seq y m) (seq x n ℚ.⊔ seq y n))) ⟩
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq x m ℚ.⊔ seq y m) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
(seq x n ℚ.⊔ seq y n) ℚ.- (seq x m ℚ.⊔ seq y m) ≤⟨ lem (seq x n) (seq y n) (seq x m) (seq y m) hyp2 m n
(ℚP.≤-respʳ-≃ (ℚP.+-comm (+ 1 / n) (+ 1 / m)) (reg y n m)) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
yn≤xn : seq y n ℚ.≤ seq x n -> ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
yn≤xn hyp2 = begin
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ ((seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n))))
(ℚP.∣-∣-cong (solve 2 (λ a b -> :- (a :- b) := b :- a)
(ℚ.*≡* _≡_.refl) (seq x m ℚ.⊔ seq y m) (seq x n ℚ.⊔ seq y n))) ⟩
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq x m ℚ.⊔ seq y m) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
(seq x n ℚ.⊔ seq y n) ℚ.- (seq x m ℚ.⊔ seq y m) ≈⟨ ℚP.≃-trans (ℚP.+-congʳ (seq x n ℚ.⊔ seq y n)
(p≃q⇒-p≃-q (seq x m ℚ.⊔ seq y m) (seq y m ℚ.⊔ seq x m) (ℚP.⊔-comm (seq x m) (seq y m))))
(ℚP.+-congˡ (ℚ.- (seq y m ℚ.⊔ seq x m)) (ℚP.⊔-comm (seq x n) (seq y n))) ⟩
(seq y n ℚ.⊔ seq x n) ℚ.- (seq y m ℚ.⊔ seq x m)
≤⟨ lem (seq y n) (seq x n) (seq y m) (seq x m) hyp2 m n
(ℚP.≤-respʳ-≃ (ℚP.+-comm (+ 1 / n) (+ 1 / m)) (reg x n m)) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
right : seq x n ℚ.⊔ seq y n ℚ.≤ seq x m ℚ.⊔ seq y m ->
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
right hyp1 = [ xm≤ym , ym≤xm ]′ (ℚP.≤-total (seq x m) (seq y m))
where
xm≤ym : seq x m ℚ.≤ seq y m -> ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
xm≤ym hyp2 = ℚP.≤-respˡ-≃ (ℚP.≃-sym (ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1))) (lem (seq x m) (seq y m) (seq x n) (seq y n) hyp2 m n (reg y m n))
ym≤xm : seq y m ℚ.≤ seq x m -> ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
ym≤xm hyp2 = begin
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
(seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ≈⟨ ℚP.≃-trans (ℚP.+-congˡ (ℚ.- (seq x n ℚ.⊔ seq y n)) (ℚP.⊔-comm (seq x m) (seq y m)))
(ℚP.+-congʳ (seq y m ℚ.⊔ seq x m)
(p≃q⇒-p≃-q (seq x n ℚ.⊔ seq y n) (seq y n ℚ.⊔ seq x n) (ℚP.⊔-comm (seq x n) (seq y n)))) ⟩
(seq y m ℚ.⊔ seq x m) ℚ.- (seq y n ℚ.⊔ seq x n) ≤⟨ lem (seq y m) (seq x m) (seq y n) (seq x n) hyp2 m n (reg x m n) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
-_ : ℝ -> ℝ
seq (- x) n = ℚ.- seq x n
reg (- x) m n {m≢0} {n≢0} = begin
ℚ.∣ ℚ.- seq x m ℚ.- (ℚ.- seq x n) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.≃-sym (ℚP.≃-reflexive (ℚP.neg-distrib-+ (seq x m) (ℚ.- seq x n)))) ⟩
ℚ.∣ ℚ.- (seq x m ℚ.- seq x n) ∣ ≤⟨ ℚP.≤-respˡ-≃ (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (seq x m ℚ.- seq x n))) (reg x m n {m≢0} {n≢0}) ⟩
((+ 1) / m) ℚ.+ ((+ 1) / n) ∎
where
open ℚP.≤-Reasoning
_-_ : ℝ -> ℝ -> ℝ
x - y = x + (- y)
-- Gets a real representation of a rational number.
-- For a rational α, one real representation is the sequence
-- α* = (α, α, α, α, α, ...).
_⋆ : ℚᵘ -> ℝ
seq (p ⋆) n = p
reg (p ⋆) (suc m) (suc n) = begin
ℚ.∣ p ℚ.- p ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.p≃q⇒p-q≃0 p p ℚP.≃-refl) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
((+ 1) / (suc m)) ℚ.+ ((+ 1) / (suc n)) ∎
where
open ℚP.≤-Reasoning
{-
Proofs that the above operations are well-defined functions
(for setoid equality).
-}
{-
∣ x₂ₙ + y₂ₙ - z₂ₙ - w₂ₙ ∣
≤ ∣ x₂ₙ - z₂ₙ ∣ + ∣ y₂ₙ - w₂ₙ ∣
≤ 2/2n + 2/2n
= 2/n
-}
+-cong : Congruent₂ _≃_ _+_
+-cong {x} {z} {y} {w} x≃z y≃w (suc k₁) = begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n) ℚ.-
(seq z (2 ℕ.* n) ℚ.+ seq w (2 ℕ.* n)) ∣ ≤⟨ ℚP.≤-respˡ-≃ (ℚP.∣-∣-cong (ℚsolve 4 (λ x y z w ->
(x ℚ:- z) ℚ:+ (y ℚ:- w) ℚ:= x ℚ:+ y ℚ:- (z ℚ:+ w))
ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)) (seq z (2 ℕ.* n)) (seq w (2 ℕ.* n))))
(ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x (2 ℕ.* n) ℚ.- seq z (2 ℕ.* n)) (seq y (2 ℕ.* n) ℚ.- seq w (2 ℕ.* n))) ⟩
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq z (2 ℕ.* n) ∣ ℚ.+
ℚ.∣ seq y (2 ℕ.* n) ℚ.- seq w (2 ℕ.* n) ∣ ≤⟨ ℚP.≤-trans (ℚP.+-monoˡ-≤ ℚ.∣ seq y (2 ℕ.* n) ℚ.- seq w (2 ℕ.* n) ∣ (x≃z (2 ℕ.* n)))
(ℚP.+-monoʳ-≤ (+ 2 / (2 ℕ.* n)) (y≃w (2 ℕ.* n))) ⟩
(+ 2 / (2 ℕ.* n)) ℚ.+ (+ 2 / (2 ℕ.* n)) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(con (+ 2) :* (con (+ 2) :* n) :+ con (+ 2) :* (con (+ 2) :* n)) :* n :=
(con (+ 2) :* ((con (+ 2) :* n) :* (con (+ 2) :* n)))) _≡_.refl (+ n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
n : ℕ
n = suc k₁
+-congʳ : ∀ x {y z} -> y ≃ z -> x + y ≃ x + z
+-congʳ x {y} {z} y≃z = +-cong {x} {x} {y} {z} (≃-refl {x}) y≃z
+-congˡ : ∀ x {y z} -> y ≃ z -> y + x ≃ z + x
+-congˡ x {y} {z} y≃z = +-cong {y} {z} {x} {x} y≃z (≃-refl {x})
+-comm : Commutative _≃_ _+_
+-comm x y (suc k₁) = begin
ℚ.∣ (seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)) ℚ.-
(seq y (2 ℕ.* n) ℚ.+ seq x (2 ℕ.* n)) ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ x y ->
(x :+ y) :- (y :+ x) := con (0ℚᵘ))
ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
0ℚᵘ ≤⟨ *≤* (+≤+ ℕ.z≤n) ⟩
(+ 2) / n ∎
where
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
+-assoc : Associative _≃_ _+_
+-assoc x y z (suc k₁) = begin
ℚ.∣ ((seq x 4n ℚ.+ seq y 4n) ℚ.+ seq z 2n) ℚ.-
(seq x 2n ℚ.+ (seq y 4n ℚ.+ seq z 4n)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 5 (λ x4 y4 z2 x2 z4 ->
((x4 ℚ:+ y4) ℚ:+ z2) ℚ:- (x2 ℚ:+ (y4 ℚ:+ z4)) ℚ:=
(x4 ℚ:- x2) ℚ:+ (z2 ℚ:- z4))
ℚP.≃-refl (seq x 4n) (seq y 4n) (seq z 2n) (seq x 2n) (seq z 4n)) ⟩
ℚ.∣ (seq x 4n ℚ.- seq x 2n) ℚ.+ (seq z 2n ℚ.- seq z 4n) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x 4n ℚ.- seq x 2n) (seq z 2n ℚ.- seq z 4n) ⟩
ℚ.∣ seq x 4n ℚ.- seq x 2n ∣ ℚ.+ ℚ.∣ seq z 2n ℚ.- seq z 4n ∣ ≤⟨ ℚP.≤-trans (ℚP.+-monoʳ-≤ ℚ.∣ seq x 4n ℚ.- seq x 2n ∣ (reg z 2n 4n))
(ℚP.+-monoˡ-≤ ((+ 1 / 2n) ℚ.+ (+ 1 / 4n)) (reg x 4n 2n)) ⟩
((+ 1 / 4n) ℚ.+ (+ 1 / 2n)) ℚ.+ ((+ 1 / 2n) ℚ.+ (+ 1 / 4n)) ≈⟨ ℚ.*≡* (solve 1 ((λ 2n ->
((con (+ 1) :* 2n :+ con (+ 1) :* (con (+ 2) :* 2n)) :*
(2n :* (con (+ 2) :* 2n)) :+
(con (+ 1) :* (con (+ 2) :* 2n) :+ con (+ 1) :* 2n) :*
((con (+ 2) :* 2n) :* 2n)) :* 2n :=
con (+ 3) :* (((con (+ 2) :* 2n) :* 2n) :*
(2n :* (con (+ 2) :* 2n)))))
_≡_.refl (+ 2n)) ⟩
+ 3 / 2n ≤⟨ *≤* (ℤP.*-monoʳ-≤-nonNeg 2n (+≤+ (ℕ.s≤s (ℕ.s≤s (ℕ.s≤s (ℕ.z≤n {1})))))) ⟩
+ 4 / 2n ≈⟨ ℚ.*≡* (solve 1 (λ n ->
con (+ 4) :* n := con (+ 2) :* (con (+ 2) :* n))
_≡_.refl (+ n)) ⟩
+ 2 / n ∎
where
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
2n : ℕ
2n = 2 ℕ.* n
4n : ℕ
4n = 2 ℕ.* 2n
0ℝ : ℝ
0ℝ = 0ℚᵘ ⋆
1ℝ : ℝ
1ℝ = ℚ.1ℚᵘ ⋆
+-identityˡ : LeftIdentity _≃_ 0ℝ _+_
+-identityˡ x (suc k₁) = begin
ℚ.∣ (0ℚᵘ ℚ.+ seq x (2 ℕ.* n)) ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- seq x n) (ℚP.+-identityˡ (seq x (2 ℕ.* n)))) ⟩
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq x n ∣ ≤⟨ reg x (2 ℕ.* n) n ⟩
(+ 1 / (2 ℕ.* n)) ℚ.+ (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(con (+ 1) :* n :+ con (+ 1) :* (con (+ 2) :* n)) :* (con (+ 2) :* n) :=
con (+ 3) :* ((con (+ 2) :* n) :* n))
_≡_.refl (+ n)) ⟩
+ 3 / (2 ℕ.* n) ≤⟨ *≤* (ℤP.*-monoʳ-≤-nonNeg (2 ℕ.* n) (+≤+ (ℕ.s≤s (ℕ.s≤s (ℕ.s≤s (ℕ.z≤n {1})))))) ⟩
+ 4 / (2 ℕ.* n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
con (+ 4) :* n := con (+ 2) :* (con (+ 2) :* n))
_≡_.refl (+ n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
n : ℕ
n = suc k₁
+-identityʳ : RightIdentity _≃_ 0ℝ _+_
+-identityʳ x = ≃-trans {x + 0ℝ} {0ℝ + x} {x} (+-comm x 0ℝ) (+-identityˡ x)
+-identity : Identity _≃_ 0ℝ _+_
+-identity = +-identityˡ , +-identityʳ
+-inverseʳ : RightInverse _≃_ 0ℝ -_ _+_
+-inverseʳ x (suc k₁) = begin
ℚ.∣ (seq x (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n)) ℚ.+ 0ℚᵘ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ 0ℚᵘ (ℚP.+-inverseʳ (seq x (2 ℕ.* n)))) ⟩
0ℚᵘ ≤⟨ *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (+≤+ ℕ.z≤n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
+-inverseˡ : LeftInverse _≃_ 0ℝ -_ _+_
+-inverseˡ x = ≃-trans {(- x) + x} {x - x} {0ℝ} (+-comm (- x) x) (+-inverseʳ x)
+-inverse : Inverse _≃_ 0ℝ -_ _+_
+-inverse = +-inverseˡ , +-inverseʳ
⋆-distrib-+ : ∀ (p r : ℚᵘ) -> (p ℚ.+ r) ⋆ ≃ p ⋆ + r ⋆
⋆-distrib-+ (mkℚᵘ p q-1) (mkℚᵘ u v-1) (suc k₁) = begin
ℚ.∣ ((p / q) ℚ.+ (u / v)) ℚ.- ((p / q) ℚ.+ (u / v)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ ((p / q) ℚ.+ (u / v))) ⟩
0ℚᵘ ≤⟨ *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (+≤+ ℕ.z≤n)) ⟩
(+ 2) / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
q : ℕ
q = suc q-1
v : ℕ
v = suc v-1
⋆-distrib-neg : ∀ (p : ℚᵘ) -> (ℚ.- p) ⋆ ≃ - (p ⋆)
⋆-distrib-neg p (suc k₁) = begin
ℚ.∣ ℚ.- p ℚ.- (ℚ.- p) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (ℚ.- p)) ⟩
0ℚᵘ ≤⟨ *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (+≤+ ℕ.z≤n)) ⟩
(+ 2) / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
abstract
regular⇒cauchy : ∀ (x : ℝ) -> ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (m n : ℕ) ->
N ℕ.≤ m -> N ℕ.≤ n -> ℚ.∣ seq x m ℚ.- seq x n ∣ ℚ.≤ (+ 1 / j) {j≢0}
regular⇒cauchy x (suc k₁) = 2 ℕ.* j , right
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
j : ℕ
j = suc k₁
N≤m⇒m≢0 : ∀ (m : ℕ) -> 2 ℕ.* j ℕ.≤ m -> m ≢0
N≤m⇒m≢0 (suc m) N≤m = _
N≤m⇒1/m≤1/N : ∀ (m : ℕ) -> (N≤m : 2 ℕ.* j ℕ.≤ m) -> (+ 1 / m) {N≤m⇒m≢0 m N≤m} ℚ.≤ (+ 1 / (2 ℕ.* j))
N≤m⇒1/m≤1/N (suc m) N≤m = *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityˡ (+ (2 ℕ.* j))))
(ℤP.≤-trans (ℤ.+≤+ N≤m) (ℤP.≤-reflexive (sym (ℤP.*-identityˡ (+ (suc m)))))))
right : ∀ (m n : ℕ) -> 2 ℕ.* j ℕ.≤ m -> 2 ℕ.* j ℕ.≤ n ->
ℚ.∣ seq x m ℚ.- seq x n ∣ ℚ.≤ + 1 / j
right m n N≤m N≤n = begin
ℚ.∣ seq x m ℚ.- seq x n ∣ ≤⟨ reg x m n {N≤m⇒m≢0 m N≤m} {N≤m⇒m≢0 n N≤n} ⟩
(+ 1 / m) {N≤m⇒m≢0 m N≤m} ℚ.+ (+ 1 / n) {N≤m⇒m≢0 n N≤n} ≤⟨ ℚP.≤-trans
(ℚP.+-monoˡ-≤ ((+ 1 / n) {N≤m⇒m≢0 n N≤n}) (N≤m⇒1/m≤1/N m N≤m))
(ℚP.+-monoʳ-≤ (+ 1 / (2 ℕ.* j)) (N≤m⇒1/m≤1/N n N≤n)) ⟩
(+ 1 / (2 ℕ.* j)) ℚ.+ (+ 1 / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(con (+ 1) :* (con (+ 2) :* j) :+ con (+ 1) :* (con (+ 2) :* j)) :* j :=
(con (+ 1) :* ((con (+ 2) :* j) :* (con (+ 2) :* j)))) _≡_.refl (+ j)) ⟩
+ 1 / j ∎
equals-to-cauchy : ∀ (x y : ℝ) -> x ≃ y -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (m n : ℕ) -> N ℕ.< m -> N ℕ.< n ->
ℚ.∣ seq x m ℚ.- seq y n ∣ ℚ.≤ (+ 1 / j) {j≢0}
equals-to-cauchy x y x≃y (suc k₁) = N , lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
j : ℕ
j = suc k₁
N₁ : ℕ
N₁ = proj₁ (lemma1A x y x≃y (2 ℕ.* j))
N₂ : ℕ
N₂ = proj₁ (regular⇒cauchy x (2 ℕ.* j))
N : ℕ
N = N₁ ℕ.⊔ N₂
lemA : ∀ (m n : ℕ) -> N ℕ.< m -> N ℕ.< n ->
ℚ.∣ seq x m ℚ.- seq y n ∣ ℚ.≤ + 1 / j
lemA (suc k₂) (suc k₃) N<m N<n = begin
ℚ.∣ seq x m ℚ.- seq y n ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 3 (λ xm yn xn ->
xm ℚ:- yn ℚ:= (xm ℚ:- xn) ℚ:+ (xn ℚ:- yn))
ℚP.≃-refl (seq x m) (seq y n) (seq x n)) ⟩
ℚ.∣ (seq x m ℚ.- seq x n) ℚ.+
(seq x n ℚ.- seq y n) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x m ℚ.- seq x n)
(seq x n ℚ.- seq y n) ⟩
ℚ.∣ seq x m ℚ.- seq x n ∣ ℚ.+
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ ℚP.+-mono-≤ (proj₂ (regular⇒cauchy x (2 ℕ.* j)) m n
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.<⇒≤ N<m))
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.<⇒≤ N<n)))
(proj₂ (lemma1A x y x≃y (2 ℕ.* j)) n
(ℕP.<-transʳ (ℕP.m≤m⊔n N₁ N₂) N<n)) ⟩
(+ 1 / (2 ℕ.* j)) ℚ.+
(+ 1 / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(con (+ 1) :* (con (+ 2) :* j) :+ (con (+ 1) :* (con (+ 2) :* j))) :* j :=
(con (+ 1) :* ((con (+ 2) :* j) :* (con (+ 2) :* j))))
_≡_.refl (+ j)) ⟩
+ 1 / j ∎
where
m : ℕ
m = suc k₂
n : ℕ
n = suc k₃
*-cong : Congruent₂ _≃_ _*_
*-cong {x} {z} {y} {w} x≃z y≃w = lemma1B (x * y) (z * w) lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (x * y) n ℚ.- seq (z * w) n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
j : ℕ
j = suc k₁
r : ℕ
r = K x ℕ.⊔ K y
t : ℕ
t = K z ℕ.⊔ K w
N₁ : ℕ
N₁ = proj₁ (equals-to-cauchy x z x≃z (K y ℕ.* (2 ℕ.* j)))
N₂ : ℕ
N₂ = proj₁ (equals-to-cauchy y w y≃w (K z ℕ.* (2 ℕ.* j)))
N : ℕ
N = N₁ ℕ.⊔ N₂
lemB : ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (x * y) n ℚ.- seq (z * w) n ∣ ℚ.≤ (+ 1 / j)
lemB (suc k₂) N<n = begin
ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ℚ.- z₂ₜₙ ℚ.* w₂ₜₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ x y z w ->
x ℚ:* y ℚ:- z ℚ:* w ℚ:= y ℚ:* (x ℚ:- z) ℚ:+ z ℚ:* (y ℚ:- w))
ℚP.≃-refl x₂ᵣₙ y₂ᵣₙ z₂ₜₙ w₂ₜₙ) ⟩
ℚ.∣ y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- z₂ₜₙ) ℚ.+
z₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- w₂ₜₙ) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- z₂ₜₙ))
(z₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- w₂ₜₙ)) ⟩
ℚ.∣ y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- z₂ₜₙ) ∣ ℚ.+
ℚ.∣ z₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- w₂ₜₙ) ∣ ≈⟨ ℚP.+-cong (ℚP.∣p*q∣≃∣p∣*∣q∣ y₂ᵣₙ ((x₂ᵣₙ ℚ.- z₂ₜₙ)))
(ℚP.∣p*q∣≃∣p∣*∣q∣ z₂ₜₙ (y₂ᵣₙ ℚ.- w₂ₜₙ)) ⟩
ℚ.∣ y₂ᵣₙ ∣ ℚ.* ℚ.∣ x₂ᵣₙ ℚ.- z₂ₜₙ ∣ ℚ.+
ℚ.∣ z₂ₜₙ ∣ ℚ.* ℚ.∣ y₂ᵣₙ ℚ.- w₂ₜₙ ∣ ≤⟨ ℚP.+-mono-≤ (ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ᵣₙ ℚ.- z₂ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-greater y (2 ℕ.* r ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K y / 1} _
(proj₂ (equals-to-cauchy x z x≃z (K y ℕ.* (2 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* n)
(N₁< (2 ℕ.* r ℕ.* n) (N<2kn r))
(N₁< (2 ℕ.* t ℕ.* n) (N<2kn t)))))
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₂ᵣₙ ℚ.- w₂ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-greater z (2 ℕ.* t ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K z / 1} _
(proj₂ (equals-to-cauchy y w y≃w (K z ℕ.* (2 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* n)
(N₂< (2 ℕ.* r ℕ.* n) (N<2kn r))
(N₂< (2 ℕ.* t ℕ.* n) (N<2kn t))))) ⟩
(+ K y / 1) ℚ.* (+ 1 / (K y ℕ.* (2 ℕ.* j))) ℚ.+
(+ K z / 1) ℚ.* (+ 1 / (K z ℕ.* (2 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Ky Kz j ->
-- Function for solver
((Ky :* con (+ 1)) :* (con (+ 1) :* (Kz :* (con (+ 2) :* j))) :+ (Kz :* con (+ 1) :* (con (+ 1) :* (Ky :* (con (+ 2) :* j))))) :* j :=
con (+ 1) :* ((con (+ 1) :* (Ky :* (con (+ 2) :* j))) :* (con (+ 1) :* (Kz :* (con (+ 2) :* j)))))
_≡_.refl (+ K y) (+ K z) (+ j)) ⟩
+ 1 / j ∎
where
n : ℕ
n = suc k₂
x₂ᵣₙ : ℚᵘ
x₂ᵣₙ = seq x (2 ℕ.* r ℕ.* n)
y₂ᵣₙ : ℚᵘ
y₂ᵣₙ = seq y (2 ℕ.* r ℕ.* n)
z₂ₜₙ : ℚᵘ
z₂ₜₙ = seq z (2 ℕ.* t ℕ.* n)
w₂ₜₙ : ℚᵘ
w₂ₜₙ = seq w (2 ℕ.* t ℕ.* n)
N<2kn : ∀ (k : ℕ) -> {k ≢0} -> N ℕ.< 2 ℕ.* k ℕ.* n
N<2kn (suc k) = ℕP.<-transˡ N<n (ℕP.m≤n*m n {2 ℕ.* (suc k)} ℕP.0<1+n)
N₁< : ∀ (k : ℕ) -> N ℕ.< k -> N₁ ℕ.< k
N₁< k N<k = ℕP.<-transʳ (ℕP.m≤m⊔n N₁ N₂) N<k
N₂< : ∀ (k : ℕ) -> N ℕ.< k -> N₂ ℕ.< k
N₂< k N<k = ℕP.<-transʳ (ℕP.m≤n⊔m N₁ N₂) N<k
*-congˡ : LeftCongruent _≃_ _*_
*-congˡ {x} {y} {z} y≃z = *-cong {x} {x} {y} {z} (≃-refl {x}) y≃z
*-congʳ : RightCongruent _≃_ _*_
*-congʳ {x} {y} {z} y≃z = *-cong {y} {z} {x} {x} y≃z (≃-refl {x})
*-comm : Commutative _≃_ _*_
*-comm x y (suc k₁) = begin
ℚ.∣ seq (x * y) n ℚ.- seq (y * x) n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.≃-trans (ℚP.+-congʳ (seq (x * y) n)
(p≃q⇒-p≃-q _ _ (ℚP.≃-sym xyℚ=yxℚ)))
(ℚP.+-inverseʳ (seq (x * y) n))) ⟩
0ℚᵘ ≤⟨ *≤* (+≤+ ℕ.z≤n) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
xyℚ=yxℚ : seq (x * y) n ℚ.≃ seq (y * x) n
xyℚ=yxℚ = begin-equality
seq x (2 ℕ.* (K x ℕ.⊔ K y) ℕ.* n) ℚ.*
seq y (2 ℕ.* (K x ℕ.⊔ K y) ℕ.* n) ≡⟨ cong (λ r ->
seq x (2 ℕ.* r ℕ.* n) ℚ.* seq y (2 ℕ.* r ℕ.* n))
(ℕP.⊔-comm (K x) (K y)) ⟩
seq x (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n) ℚ.*
seq y (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n) ≈⟨ ℚP.*-comm (seq x (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n))
(seq y (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n)) ⟩
seq y (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n) ℚ.*
seq x (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n) ∎
{-
Proposition:
Multiplication on ℝ is associative.
Proof:
Let x,y,z∈ℝ. We must show that (xy)z = x(yz). Define
r = max{Kx, Ky} s = max{Kxy, Kz}
u = max{Kx, Kyz} t = max{Ky, Kz},
noting that Kxy is the canonical bound for x * y (similarly for Kyz).
Let j∈ℤ⁺. Since (xₙ), (yₙ), and (zₙ) are Cauchy sequences, there is
N₁,N₂,N₃∈ℤ⁺ such that:
∣xₘ - xₙ∣ ≤ 1 / (Ky * Kz * 3j) (m, n ≥ N₁),
∣yₘ - yₙ∣ ≤ 1 / (Kx * Kz * 3j) (m, n ≥ N₂), and
∣zₘ - zₙ∣ ≤ 1 / (Kx * Ky * 3j) (m, n ≥ N₃).
x = z and y = w
then
x * y = z * w
∣xₘ - zₙ∣ ≤ ε
Define N = max{N₁, N₂, N₃}. If we show that
∣x₄ᵣₛₙ * y₄ᵣₛₙ * z₂ₛₙ - x₂ᵤₙ * y₄ₜᵤₙ * z₄ₜᵤₙ∣ ≤ 1 / j
for all n ≥ N, then (xy)z = x(yz) by Lemma 1.
Note that, for all a, b, c, d in ℚ, we have
ab - cd = b(a - c) + c(b - d).
We will use this trick in our proof. We have:
∀ ε > 0 ∃ N ∈ ℕ ∀ m, n ≥ N -> ∣xₘ - xₙ∣ ≤ ε
∀ j ∈ ℤ⁺ ∃ N ∈ ℕ ∀ m, n ≥ N ∣ xn - yn ∣ ≤ 1/j
∀ n ∈ ℕ (∣ xn - yn ∣ ≤ 2/n)
∣x₄ᵣₛₙ * y₄ᵣₛₙ * z₂ₛₙ - x₂ᵤₙ * y₄ₜᵤₙ * z₄ₜᵤₙ∣
= ∣y₄ᵣₛₙ * z₂ₛₙ(x₄ᵣₛₙ - x₂ᵤₙ) + x₂ᵤₙ(y₄ᵣₛₙ * z₂ₛₙ - y₄ₜᵤₙ * z₄ₜᵤₙ)∣
= ∣y₄ᵣₛₙ * z₂ₛₙ(x₄ᵣₛₙ - x₂ᵤₙ) + x₂ᵤₙ(z₂ₛₙ(y₄ᵣₛₙ - y₄ₜᵤₙ) + y₄ₜᵤₙ(z₂ₛₙ - z₄ₜᵤₙ)∣
≤ ∣y₄ᵣₛₙ∣*∣z₂ₛₙ∣*∣x₄ᵣₛₙ - x₂ᵤₙ∣ + ∣x₂ᵤₙ∣*∣z₂ₛₙ∣*∣y₄ᵣₛₙ - y₄ₜᵤₙ∣ + ∣x₂ᵤₙ∣*∣y₄ₜᵤₙ∣*∣z₂ₛₙ - z₄ₜᵤₙ∣
≤ Ky * Kz * (1 / (Ky * Kz * 3j)) + Kx * Kz * (1 / (Kx * Kz * 3j)) + Kx * Ky * (1 / (Kx * Ky * 3j))
= 1 / 3j + 1 / 3j + 1 / 3j
= 1 / j.
Thus ∣x₄ᵣₛₙ*y₄ᵣₛₙ*z₂ₛₙ - x₂ᵤₙ*y₄ₜᵤₙ*z₄ₜᵤₙ∣ ≤ 1/j, as desired. □
-}
*-assoc : Associative _≃_ _*_
*-assoc x y z = lemma1B ((x * y) * z) (x * (y * z)) lemA
where
open ℚP.≤-Reasoning
r : ℕ
r = K x ℕ.⊔ K y
s : ℕ
s = K (x * y) ℕ.⊔ K z
u : ℕ
u = K x ℕ.⊔ K (y * z)
t : ℕ
t = K y ℕ.⊔ K z
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) ℚ.* seq y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) ℚ.* seq z (2 ℕ.* s ℕ.* n) ℚ.-
seq x (2 ℕ.* u ℕ.* n) ℚ.* (seq y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)) ℚ.* seq z (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)))∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
j : ℕ
j = suc k₁
N₁ : ℕ
N₁ = proj₁ (regular⇒cauchy x ((K y ℕ.* K z) ℕ.* (3 ℕ.* j)))
N₂ : ℕ
N₂ = proj₁ (regular⇒cauchy y (K x ℕ.* K z ℕ.* (3 ℕ.* j)))
N₃ : ℕ
N₃ = proj₁ (regular⇒cauchy z (K x ℕ.* K y ℕ.* (3 ℕ.* j)))
N : ℕ
N = (N₁ ℕ.⊔ N₂) ℕ.⊔ N₃
lemB : ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) ℚ.* seq y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) ℚ.* seq z (2 ℕ.* s ℕ.* n) ℚ.-
seq x (2 ℕ.* u ℕ.* n) ℚ.* (seq y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)) ℚ.* seq z (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)))∣ ℚ.≤ (+ 1 / j)
lemB (suc k₂) N<n = begin
ℚ.∣ x₄ᵣₛₙ ℚ.* y₄ᵣₛₙ ℚ.* z₂ₛₙ ℚ.- x₂ᵤₙ ℚ.* (y₄ₜᵤₙ ℚ.* z₄ₜᵤₙ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 6 (λ a b c d e f ->
a ℚ:* b ℚ:* c ℚ:- d ℚ:* (e ℚ:* f) ℚ:=
(b ℚ:* c) ℚ:* (a ℚ:- d) ℚ:+ d ℚ:* (c ℚ:* (b ℚ:- e) ℚ:+ e ℚ:* (c ℚ:- f)))
ℚP.≃-refl x₄ᵣₛₙ y₄ᵣₛₙ z₂ₛₙ x₂ᵤₙ y₄ₜᵤₙ z₄ₜᵤₙ) ⟩
ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ℚ.+
x₂ᵤₙ ℚ.* (z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ℚ.+
y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ)) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ ((y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ))
(x₂ᵤₙ ℚ.* (z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ℚ.+ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ))) ⟩
ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ∣ ℚ.+
ℚ.∣ x₂ᵤₙ ℚ.* (z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ℚ.+
y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ)) ∣ ≤⟨ ℚP.≤-respˡ-≃ (ℚP.≃-sym (ℚP.+-congʳ ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ∣
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ᵤₙ (z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ℚ.+ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ)))))
(ℚP.+-monoʳ-≤ ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ∣
(ℚP.*-monoʳ-≤-nonNeg {ℚ.∣ x₂ᵤₙ ∣} _ (ℚP.∣p+q∣≤∣p∣+∣q∣
(z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ)) (y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ))))) ⟩
ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ∣ ℚ.+
ℚ.∣ x₂ᵤₙ ∣ ℚ.* (ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.+
ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣) ≈⟨ ℚP.+-congˡ
(ℚ.∣ x₂ᵤₙ ∣ ℚ.* (ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.+ ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣))
(ℚP.≃-trans (ℚP.∣p*q∣≃∣p∣*∣q∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) (x₄ᵣₛₙ ℚ.- x₂ᵤₙ))
(ℚP.*-congʳ (ℚP.∣p*q∣≃∣p∣*∣q∣ y₄ᵣₛₙ z₂ₛₙ))) ⟩
ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ℚ.+
ℚ.∣ x₂ᵤₙ ∣ ℚ.* (ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.+
ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣) ≈⟨ ℚP.+-congʳ (ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣)
(ℚP.*-distribˡ-+ ℚ.∣ x₂ᵤₙ ∣ ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣
ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣) ⟩
ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ℚ.+
(ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.+
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣) ≤⟨ ℚP.≤-trans (ℚP.+-monoʳ-≤ (ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣)
(ℚP.≤-trans (ℚP.+-monoʳ-≤ (ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣) part3)
(ℚP.+-monoˡ-≤ (+ 1 / (3 ℕ.* j)) part2)))
(ℚP.+-monoˡ-≤ (+ 1 / (3 ℕ.* j) ℚ.+ + 1 / (3 ℕ.* j)) part1) ⟩
(+ 1 / (3 ℕ.* j)) ℚ.+ ((+ 1 / (3 ℕ.* j)) ℚ.+ (+ 1 / (3 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(con (+ 1) :* ((con (+ 3) :* j) :* (con (+ 3) :* j)) :+ ((con (+ 1) :* (con (+ 3) :* j)) :+ (con (+ 1) :* (con (+ 3) :* j))) :* (con (+ 3) :* j)) :* j :=
(con (+ 1) :* ((con (+ 3) :* j) :* ((con (+ 3) :* j) :* (con (+ 3) :* j)))))
_≡_.refl (+ j)) ⟩
+ 1 / j ∎
where
n : ℕ
n = suc k₂
x₄ᵣₛₙ : ℚᵘ
x₄ᵣₛₙ = seq x (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n))
y₄ᵣₛₙ : ℚᵘ
y₄ᵣₛₙ = seq y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n))
z₂ₛₙ : ℚᵘ
z₂ₛₙ = seq z (2 ℕ.* s ℕ.* n)
x₂ᵤₙ : ℚᵘ
x₂ᵤₙ = seq x (2 ℕ.* u ℕ.* n)
y₄ₜᵤₙ : ℚᵘ
y₄ₜᵤₙ = seq y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
z₄ₜᵤₙ : ℚᵘ
z₄ₜᵤₙ = seq z (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
N≤4rsn : N ℕ.≤ 2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)
N≤4rsn = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans
(ℕP.m≤n*m n {4 ℕ.* r ℕ.* s} ℕP.0<1+n) (ℤP.drop‿+≤+ (ℤP.≤-reflexive (solve 3 (λ r s n ->
con (+ 4) :* r :* s :* n := con (+ 2) :* r :* (con (+ 2) :* s :* n))
_≡_.refl (+ r) (+ s) (+ n)))))
N₁≤4rsn : N₁ ℕ.≤ 2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)
N₁≤4rsn = ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃) N≤4rsn)
N₁≤2un : N₁ ℕ.≤ 2 ℕ.* u ℕ.* n
N₁≤2un = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃))
(ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.m≤n*m n {2 ℕ.* u} ℕP.0<1+n))
part1 : ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ℚ.≤ + 1 / (3 ℕ.* j)
part1 = begin
ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ≤⟨ ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣} _ (ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ z₂ₛₙ ∣} _ (ℚP.<⇒≤
(canonical-greater y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {(+ K y) / 1} _ (ℚP.<⇒≤
(canonical-greater z (2 ℕ.* s ℕ.* n))))) ⟩
(+ (K y ℕ.* K z) / 1) ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K y ℕ.* K z) / 1} _
(proj₂ (regular⇒cauchy x (K y ℕ.* K z ℕ.* (3 ℕ.* j)))
(2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) (2 ℕ.* u ℕ.* n) N₁≤4rsn N₁≤2un) ⟩
(+ (K y ℕ.* K z) / 1) ℚ.* (+ 1 / (K y ℕ.* K z ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Ky Kz j ->
((Ky :* Kz) :* con (+ 1)) :* (con (+ 3) :* j) :=
(con (+ 1) :* (con (+ 1) :* (Ky :* Kz :* (con (+ 3) :* j)))))
_≡_.refl (+ K y) (+ K z) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
N₂≤4rsn : N₂ ℕ.≤ 2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)
N₂≤4rsn = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃) N≤4rsn)
N≤4tun : N ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)
N≤4tun = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans (ℕP.m≤n*m n {4 ℕ.* t ℕ.* u} ℕP.0<1+n)
(ℤP.drop‿+≤+ (ℤP.≤-reflexive (solve 3 (λ t u n ->
con (+ 4) :* t :* u :* n := con (+ 2) :* t :* (con (+ 2) :* u :* n))
_≡_.refl (+ t) (+ u) (+ n)))))
N₂≤4tun : N₂ ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)
N₂≤4tun = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃) N≤4tun)
part2 : ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.≤ + 1 / (3 ℕ.* j)
part2 = begin
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ≈⟨ ℚP.≃-trans (ℚP.*-congˡ {ℚ.∣ x₂ᵤₙ ∣} (ℚP.∣p*q∣≃∣p∣*∣q∣ z₂ₛₙ (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ)))
(ℚP.≃-sym (ℚP.*-assoc ℚ.∣ x₂ᵤₙ ∣ ℚ.∣ z₂ₛₙ ∣ ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣)) ⟩
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣} _ (ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ z₂ₛₙ ∣} _
(ℚP.<⇒≤ (canonical-greater x (2 ℕ.* u ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(ℚP.<⇒≤ (canonical-greater z (2 ℕ.* s ℕ.* n))))) ⟩
(+ (K x ℕ.* K z) / 1) ℚ.* ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K x ℕ.* K z) / 1} _
(proj₂ (regular⇒cauchy y (K x ℕ.* K z ℕ.* (3 ℕ.* j)))
(2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
N₂≤4rsn N₂≤4tun) ⟩
(+ (K x ℕ.* K z) / 1) ℚ.*
(+ 1 / (K x ℕ.* K z ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Kx Kz j ->
(Kx :* Kz :* con (+ 1)) :* (con (+ 3) :* j) :=
(con (+ 1) :* (con (+ 1) :* (Kx :* Kz :* (con (+ 3) :* j)))))
_≡_.refl (+ K x) (+ K z) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
N₃≤2sn : N₃ ℕ.≤ 2 ℕ.* s ℕ.* n
N₃≤2sn = ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃)
(ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.m≤n*m n {2 ℕ.* s} ℕP.0<1+n))
N₃≤4tun : N₃ ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)
N₃≤4tun = ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃) N≤4tun
part3 : ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣ ℚ.≤ + 1 / (3 ℕ.* j)
part3 = begin
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣ ≈⟨ ℚP.≃-trans (ℚP.*-congˡ {ℚ.∣ x₂ᵤₙ ∣} (ℚP.∣p*q∣≃∣p∣*∣q∣ y₄ₜᵤₙ (z₂ₛₙ ℚ.- z₄ₜᵤₙ)))
(ℚP.≃-sym (ℚP.*-assoc ℚ.∣ x₂ᵤₙ ∣ ℚ.∣ y₄ₜᵤₙ ∣ ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣)) ⟩
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ y₄ₜᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣} _ (ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₄ₜᵤₙ ∣} _
(ℚP.<⇒≤ (canonical-greater x (2 ℕ.* u ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(ℚP.<⇒≤ (canonical-greater y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)))))) ⟩
(+ (K x ℕ.* K y) / 1) ℚ.* ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K x ℕ.* K y) / 1} _
(proj₂ (regular⇒cauchy z (K x ℕ.* K y ℕ.* (3 ℕ.* j)))
(2 ℕ.* s ℕ.* n) (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
N₃≤2sn N₃≤4tun) ⟩
(+ (K x ℕ.* K y) / 1) ℚ.*
(+ 1 / (K x ℕ.* K y ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Kx Ky j ->
(((Kx :* Ky) :* con (+ 1)) :* (con (+ 3) :* j)) :=
(con (+ 1) :* (con (+ 1) :* (Kx :* Ky :* (con (+ 3) :* j)))))
_≡_.refl (+ K x) (+ K y) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
*-distribˡ-+ : _DistributesOverˡ_ _≃_ _*_ _+_
*-distribˡ-+ x y z = lemma1B (x * (y + z)) ((x * y) + (x * z)) lemA
where
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (x * (y + z)) n ℚ.- seq ((x * y) + (x * z)) n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
j : ℕ
j = suc k₁
r : ℕ
r = K x ℕ.⊔ K (y + z)
s : ℕ
s = K x ℕ.⊔ K y
t : ℕ
t = K x ℕ.⊔ K z
N₁ : ℕ
N₁ = proj₁ (regular⇒cauchy x (K y ℕ.* (4 ℕ.* j)))
N₂ : ℕ
N₂ = proj₁ (regular⇒cauchy y (K x ℕ.* (4 ℕ.* j)))
N₃ : ℕ
N₃ = proj₁ (regular⇒cauchy x (K z ℕ.* (4 ℕ.* j)))
N₄ : ℕ
N₄ = proj₁ (regular⇒cauchy z (K x ℕ.* (4 ℕ.* j)))
N : ℕ
N = N₁ ℕ.⊔ N₂ ℕ.⊔ N₃ ℕ.⊔ N₄
lemB : ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (x * (y + z)) n ℚ.- seq ((x * y) + (x * z)) n ∣ ℚ.≤ + 1 / j
lemB (suc k₂) N<n = begin
ℚ.∣ x₂ᵣₙ ℚ.* (y₄ᵣₙ ℚ.+ z₄ᵣₙ) ℚ.-
(x₄ₛₙ ℚ.* y₄ₛₙ ℚ.+ x₄ₜₙ ℚ.* z₄ₜₙ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 7 (λ a b c d e f g ->
a ℚ:* (b ℚ:+ c) ℚ:- (d ℚ:* e ℚ:+ f ℚ:* g) ℚ:=
(b ℚ:* (a ℚ:- d) ℚ:+ (d ℚ:* (b ℚ:- e)) ℚ:+
((c ℚ:* (a ℚ:- f)) ℚ:+ (f ℚ:* (c ℚ:- g)))))
ℚP.≃-refl
x₂ᵣₙ y₄ᵣₙ z₄ᵣₙ x₄ₛₙ y₄ₛₙ x₄ₜₙ z₄ₜₙ) ⟩
ℚ.∣ y₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₛₙ) ℚ.+
x₄ₛₙ ℚ.* (y₄ᵣₙ ℚ.- y₄ₛₙ) ℚ.+
(z₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₜₙ) ℚ.+
x₄ₜₙ ℚ.* (z₄ᵣₙ ℚ.- z₄ₜₙ)) ∣ ≤⟨ ℚP.≤-trans (ℚP.∣p+q∣≤∣p∣+∣q∣
(y₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₛₙ) ℚ.+ x₄ₛₙ ℚ.* (y₄ᵣₙ ℚ.- y₄ₛₙ))
(z₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₜₙ) ℚ.+ x₄ₜₙ ℚ.* (z₄ᵣₙ ℚ.- z₄ₜₙ)))
(ℚP.+-mono-≤
(ℚP.∣p+q∣≤∣p∣+∣q∣ (y₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₛₙ)) ( x₄ₛₙ ℚ.* (y₄ᵣₙ ℚ.- y₄ₛₙ)))
(ℚP.∣p+q∣≤∣p∣+∣q∣ (z₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₜₙ)) ( x₄ₜₙ ℚ.* (z₄ᵣₙ ℚ.- z₄ₜₙ)))) ⟩
ℚ.∣ y₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₛₙ) ∣ ℚ.+
ℚ.∣ x₄ₛₙ ℚ.* (y₄ᵣₙ ℚ.- y₄ₛₙ) ∣ ℚ.+
(ℚ.∣ z₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₜₙ) ∣ ℚ.+
ℚ.∣ x₄ₜₙ ℚ.* (z₄ᵣₙ ℚ.- z₄ₜₙ) ∣) ≈⟨ ℚP.+-cong (ℚP.+-cong (ℚP.∣p*q∣≃∣p∣*∣q∣ y₄ᵣₙ (x₂ᵣₙ ℚ.- x₄ₛₙ))
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₄ₛₙ (y₄ᵣₙ ℚ.- y₄ₛₙ)))
(ℚP.+-cong (ℚP.∣p*q∣≃∣p∣*∣q∣ z₄ᵣₙ (x₂ᵣₙ ℚ.- x₄ₜₙ))
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₄ₜₙ (z₄ᵣₙ ℚ.- z₄ₜₙ))) ⟩
ℚ.∣ y₄ᵣₙ ∣ ℚ.* ℚ.∣ x₂ᵣₙ ℚ.- x₄ₛₙ ∣ ℚ.+
ℚ.∣ x₄ₛₙ ∣ ℚ.* ℚ.∣ y₄ᵣₙ ℚ.- y₄ₛₙ ∣ ℚ.+
(ℚ.∣ z₄ᵣₙ ∣ ℚ.* ℚ.∣ x₂ᵣₙ ℚ.- x₄ₜₙ ∣ ℚ.+
ℚ.∣ x₄ₜₙ ∣ ℚ.* ℚ.∣ z₄ᵣₙ ℚ.- z₄ₜₙ ∣) ≤⟨ ℚP.+-mono-≤
(ℚP.+-mono-≤
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ᵣₙ ℚ.- x₄ₛₙ ∣} _
(ℚP.<⇒≤ (canonical-greater y
(2 ℕ.* (2 ℕ.* r ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K y / 1} _
(proj₂ (regular⇒cauchy x (K y ℕ.* (4 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* s ℕ.* (2 ℕ.* n))
(N₁≤ N≤2rn) (N₁≤ N≤4sn))))
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₄ᵣₙ ℚ.- y₄ₛₙ ∣} _
(ℚP.<⇒≤ (canonical-greater x
(2 ℕ.* s ℕ.* (2 ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(proj₂ (regular⇒cauchy y (K x ℕ.* (4 ℕ.* j)))
(2 ℕ.* (2 ℕ.* r ℕ.* n)) (2 ℕ.* s ℕ.* (2 ℕ.* n))
(N₂≤ N≤4rn) (N₂≤ N≤4sn)))))
(ℚP.+-mono-≤
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ᵣₙ ℚ.- x₄ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-greater z
(2 ℕ.* (2 ℕ.* r ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K z / 1} _
(proj₂ (regular⇒cauchy x (K z ℕ.* (4 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* (2 ℕ.* n))
(N₃≤ N≤2rn) (N₃≤ N≤4tn))))
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ z₄ᵣₙ ℚ.- z₄ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-greater x
(2 ℕ.* t ℕ.* (2 ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(proj₂ (regular⇒cauchy z (K x ℕ.* (4 ℕ.* j)))
(2 ℕ.* (2 ℕ.* r ℕ.* n)) (2 ℕ.* t ℕ.* (2 ℕ.* n))
(N₄≤ N≤4rn) (N₄≤ N≤4tn))))) ⟩
(+ K y / 1) ℚ.* (+ 1 / (K y ℕ.* (4 ℕ.* j))) ℚ.+
(+ K x / 1) ℚ.* (+ 1 / (K x ℕ.* (4 ℕ.* j))) ℚ.+
((+ K z / 1) ℚ.* (+ 1 / (K z ℕ.* (4 ℕ.* j))) ℚ.+
(+ K x / 1) ℚ.* (+ 1 / (K x ℕ.* (4 ℕ.* j)))) ≈⟨ ℚ.*≡* (solve 4 (λ Kx Ky Kz j ->
{- Function for solver -}
(((Ky :* con (+ 1)) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j))) :+ ((Kx :* con (+ 1)) :* (con (+ 1) :* (Ky :* (con (+ 4) :* j))))) :*
((con (+ 1) :* (Kz :* (con (+ 4) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j)))) :+
(((Kz :* con (+ 1)) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j)))) :+ ((Kx :* con (+ 1)) :* (con (+ 1) :* (Kz :* (con (+ 4) :* j))))) :*
((con (+ 1) :* (Ky :* (con (+ 4) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j))))) :* j :=
con (+ 1) :* (((con (+ 1) :* (Ky :* (con (+ 4) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j)))) :*
((con (+ 1) :* (Kz :* (con (+ 4) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j))))))
_≡_.refl (+ K x) (+ K y) (+ K z) (+ j)) ⟩
+ 1 / j ∎
where
n : ℕ
n = suc k₂
x₂ᵣₙ : ℚᵘ
x₂ᵣₙ = seq x (2 ℕ.* r ℕ.* n)
x₄ₛₙ : ℚᵘ
x₄ₛₙ = seq x (2 ℕ.* s ℕ.* (2 ℕ.* n))
x₄ₜₙ : ℚᵘ
x₄ₜₙ = seq x (2 ℕ.* t ℕ.* (2 ℕ.* n))
y₄ᵣₙ : ℚᵘ
y₄ᵣₙ = seq y (2 ℕ.* (2 ℕ.* r ℕ.* n))
y₄ₛₙ : ℚᵘ
y₄ₛₙ = seq y (2 ℕ.* s ℕ.* (2 ℕ.* n))
z₄ᵣₙ : ℚᵘ
z₄ᵣₙ = seq z (2 ℕ.* (2 ℕ.* r ℕ.* n))
z₄ₜₙ : ℚᵘ
z₄ₜₙ = seq z (2 ℕ.* t ℕ.* (2 ℕ.* n))
N≤2rn : N ℕ.≤ 2 ℕ.* r ℕ.* n
N≤2rn = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.m≤n*m n {2 ℕ.* r} ℕP.0<1+n)
N≤4sn : N ℕ.≤ 2 ℕ.* s ℕ.* (2 ℕ.* n)
N≤4sn = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans (ℕP.m≤n*m n {2 ℕ.* s ℕ.* 2} ℕP.0<1+n)
(ℕP.≤-reflexive (ℕP.*-assoc (2 ℕ.* s) 2 n)))
N≤4rn : N ℕ.≤ 2 ℕ.* (2 ℕ.* r ℕ.* n)
N≤4rn = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans (ℕP.m≤n*m n {2 ℕ.* (2 ℕ.* r)} ℕP.0<1+n)
(ℕP.≤-reflexive (ℕP.*-assoc 2 (2 ℕ.* r) n)))
N≤4tn : N ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* n)
N≤4tn = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans (ℕP.m≤n*m n {2 ℕ.* t ℕ.* 2} ℕP.0<1+n)
(ℕP.≤-reflexive (ℕP.*-assoc (2 ℕ.* t) 2 n)))
N₁≤_ : {m : ℕ} -> N ℕ.≤ m -> N₁ ℕ.≤ m
N₁≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃))
(ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄) N≤m)
N₂≤_ : {m : ℕ} -> N ℕ.≤ m -> N₂ ℕ.≤ m
N₂≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃))
(ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄) N≤m)
N₃≤_ : {m : ℕ} -> N ℕ.≤ m -> N₃ ℕ.≤ m
N₃≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄)) N≤m
N₄≤_ : {m : ℕ} -> N ℕ.≤ m -> N₄ ℕ.≤ m
N₄≤ N≤m = ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄) N≤m
*-distribʳ-+ : _DistributesOverʳ_ _≃_ _*_ _+_
*-distribʳ-+ x y z = ≃-trans {(y + z) * x} {x * (y + z)} {y * x + z * x} (*-comm (y + z) x)
(≃-trans {x * (y + z)} {x * y + x * z} {y * x + z * x} (*-distribˡ-+ x y z)
(+-cong {x * y} {y * x} {x * z} {z * x} (*-comm x y) (*-comm x z)))
*-distrib-+ : _DistributesOver_ _≃_ _*_ _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
*-identityˡ : LeftIdentity _≃_ 1ℝ _*_
*-identityˡ x (suc k₁) = begin
ℚ.∣ ℚ.1ℚᵘ ℚ.* seq x (2 ℕ.* k ℕ.* n) ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- seq x n) (ℚP.*-identityˡ (seq x (2 ℕ.* k ℕ.* n)))) ⟩
ℚ.∣ seq x (2 ℕ.* k ℕ.* n) ℚ.- seq x n ∣ ≤⟨ reg x (2 ℕ.* k ℕ.* n) n ⟩
(+ 1 / (2 ℕ.* k ℕ.* n)) ℚ.+ (+ 1 / n) ≤⟨ ℚP.+-monoˡ-≤ (+ 1 / n) lem ⟩
(+ 1 / n) ℚ.+ (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(con (+ 1) :* n :+ con (+ 1) :* n) :* n := (con (+ 2) :* (n :* n)))
_≡_.refl (+ n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
k : ℕ
k = K 1ℝ ℕ.⊔ K x
n : ℕ
n = suc k₁
lem : (+ 1 / (2 ℕ.* k ℕ.* n)) ℚ.≤ + 1 / n
lem = *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n*m n {2 ℕ.* k} ℕP.0<1+n)))
*-identityʳ : RightIdentity _≃_ 1ℝ _*_
*-identityʳ x = ≃-trans {x * 1ℝ} {1ℝ * x} {x} (*-comm x 1ℝ) (*-identityˡ x)
*-identity : Identity _≃_ 1ℝ _*_
*-identity = *-identityˡ , *-identityʳ
*-zeroˡ : LeftZero _≃_ 0ℝ _*_
*-zeroˡ x (suc k₁) = begin
ℚ.∣ 0ℚᵘ ℚ.* seq x (2 ℕ.* k ℕ.* n) ℚ.- 0ℚᵘ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- 0ℚᵘ) (ℚP.*-zeroˡ (seq x (2 ℕ.* k ℕ.* n)))) ⟩
0ℚᵘ ≤⟨ *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (+≤+ ℕ.z≤n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
k : ℕ
k = K 0ℝ ℕ.⊔ K x
*-zeroʳ : RightZero _≃_ 0ℝ _*_
*-zeroʳ x = ≃-trans {x * 0ℝ} {0ℝ * x} {0ℝ} (*-comm x 0ℝ) (*-zeroˡ x)
*-zero : Zero _≃_ 0ℝ _*_
*-zero = *-zeroˡ , *-zeroʳ
-‿cong : Congruent₁ _≃_ (-_)
-‿cong {x} {y} x≃y n {n≢0} = begin
ℚ.∣ ℚ.- seq x n ℚ.- (ℚ.- seq y n) ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ x y -> :- x :- (:- y) := y :- x) ℚP.≃-refl (seq x n) (seq y n)) ⟩
ℚ.∣ seq y n ℚ.- seq x n ∣ ≤⟨ (≃-symm {x} {y} x≃y) n {n≢0} ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
neg-involutive : Involutive _≃_ (-_)
neg-involutive x (suc k₁) = begin
ℚ.∣ ℚ.- (ℚ.- seq x (suc k₁)) ℚ.- seq x (suc k₁) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseˡ (ℚ.- seq x (suc k₁))) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / (suc k₁) ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
neg-distrib-+ : ∀ x y -> - (x + y) ≃ (- x) + (- y)
neg-distrib-+ x y (suc k₁) = begin
ℚ.∣ ℚ.- (seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)) ℚ.-
(ℚ.- seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n)) ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ x y ->
:- (x :+ y) :- (:- x :- y) := con (0ℚᵘ)) ℚP.≃-refl
(seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k₁
⊔-cong : Congruent₂ _≃_ _⊔_
⊔-cong {x} {z} {y} {w} x≃z y≃w (suc k₁) = [ left , right ]′ (ℚP.≤-total (seq x n ℚ.⊔ seq y n) (seq z n ℚ.⊔ seq w n))
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k₁
lem : ∀ a b c d -> a ℚ.≤ b -> ℚ.∣ b ℚ.- d ∣ ℚ.≤ + 2 / n ->
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ℚ.≤ + 2 / n
lem a b c d a≤b hyp = begin
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ≤⟨ ℚP.+-mono-≤ (ℚP.≤-reflexive (ℚP.p≤q⇒p⊔q≃q a≤b)) (ℚP.neg-mono-≤ (ℚP.p≤q⊔p c d)) ⟩
b ℚ.- d ≤⟨ p≤∣p∣ (b ℚ.- d) ⟩
ℚ.∣ b ℚ.- d ∣ ≤⟨ hyp ⟩
+ 2 / n ∎
left : seq x n ℚ.⊔ seq y n ℚ.≤ seq z n ℚ.⊔ seq w n -> ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
left hyp1 = [ zn≤wn , wn≤zn ]′ (ℚP.≤-total (seq z n) (seq w n))
where
first : ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≃ (seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n)
first = begin-equality
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ ((seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n))))
(ℚP.∣-∣-cong (solve 2 (λ a b -> :- (a :- b) := b :- a)
ℚP.≃-refl (seq x n ℚ.⊔ seq y n) (seq z n ℚ.⊔ seq w n))) ⟩
ℚ.∣ (seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
(seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n) ∎
zn≤wn : seq z n ℚ.≤ seq w n -> ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
zn≤wn hyp2 = begin
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ first ⟩
(seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n) ≤⟨ lem (seq z n) (seq w n) (seq x n) (seq y n) hyp2 (≃-symm {y} {w} y≃w n) ⟩
+ 2 / n ∎
wn≤zn : seq w n ℚ.≤ seq z n -> ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
wn≤zn hyp2 = begin
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ first ⟩
(seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n) ≈⟨ ℚP.+-cong (ℚP.⊔-comm (seq z n) (seq w n)) (ℚP.-‿cong (ℚP.⊔-comm (seq x n) (seq y n))) ⟩
(seq w n ℚ.⊔ seq z n) ℚ.- (seq y n ℚ.⊔ seq x n) ≤⟨ lem (seq w n) (seq z n) (seq y n) (seq x n) hyp2 (≃-symm {x} {z} x≃z n) ⟩
+ 2 / n ∎
right : seq z n ℚ.⊔ seq w n ℚ.≤ seq x n ℚ.⊔ seq y n -> ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
right hyp1 = [ xn≤yn , yn≤xn ]′ (ℚP.≤-total (seq x n) (seq y n))
where
xn≤yn : seq x n ℚ.≤ seq y n -> ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
xn≤yn hyp2 = begin
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ≤⟨ lem (seq x n) (seq y n) (seq z n) (seq w n) hyp2 (y≃w n) ⟩
+ 2 / n ∎
yn≤xn : seq y n ℚ.≤ seq x n -> ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
yn≤xn hyp2 = begin
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ≈⟨ ℚP.+-cong (ℚP.⊔-comm (seq x n) (seq y n)) (ℚP.-‿cong (ℚP.⊔-comm (seq z n) (seq w n))) ⟩
seq y n ℚ.⊔ seq x n ℚ.- (seq w n ℚ.⊔ seq z n) ≤⟨ lem (seq y n) (seq x n) (seq w n) (seq z n) hyp2 (x≃z n) ⟩
+ 2 / n ∎
⊔-congˡ : LeftCongruent _≃_ _⊔_
⊔-congˡ {x} {y} {z} y≃z = ⊔-cong {x} {x} {y} {z} (≃-refl {x}) y≃z
⊔-congʳ : RightCongruent _≃_ _⊔_
⊔-congʳ {x} {y} {z} y≃z = ⊔-cong {y} {z} {x} {x} y≃z (≃-refl {x})
⊔-comm : Commutative _≃_ _⊔_
⊔-comm x y n {n≢0} = begin
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq y n ℚ.⊔ seq x n) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ (seq x n ℚ.⊔ seq y n) (ℚP.-‿cong (ℚP.⊔-comm (seq y n) (seq x n)))) ⟩
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≤⟨ ≃-refl {x ⊔ y} n {n≢0} ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
⊔-assoc : Associative _≃_ _⊔_
⊔-assoc x y z n {n≢0} = begin
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n ℚ.- (seq x n ℚ.⊔ (seq y n ℚ.⊔ seq z n)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ (seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n)
(ℚP.-‿cong (ℚP.≃-sym (ℚP.⊔-assoc (seq x n) (seq y n) (seq z n))))) ⟩
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n ℚ.- (seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n) ∣ ≤⟨ ≃-refl {x ⊔ y ⊔ z} n {n≢0} ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
_⊓_ : (x y : ℝ) -> ℝ
x ⊓ y = - ((- x) ⊔ (- y))
⊓-cong : Congruent₂ _≃_ _⊓_
⊓-cong {x} {z} {y} {w} x≃z y≃w = -‿cong {(- x ⊔ - y)} {(- z ⊔ - w)} (⊔-cong {(- x)} {(- z)} {(- y)} {(- w)}
(-‿cong {x} {z} x≃z) (-‿cong {y} {w} y≃w))
⊓-congˡ : LeftCongruent _≃_ _⊓_
⊓-congˡ {x} {y} {z} y≃z = ⊓-cong {x} {x} {y} {z} (≃-refl {x}) y≃z
⊓-congʳ : RightCongruent _≃_ _⊓_
⊓-congʳ {x} {y} {z} y≃z = ⊓-cong {y} {z} {x} {x} y≃z (≃-refl {x})
⊓-comm : Commutative _≃_ _⊓_
⊓-comm x y = -‿cong { - x ⊔ - y} { - y ⊔ - x} (⊔-comm (- x) (- y))
⊓-assoc : Associative _≃_ _⊓_
⊓-assoc x y z = -‿cong {(- (- ((- x) ⊔ (- y)))) ⊔ (- z)} {(- x) ⊔ (- (- ((- y) ⊔ (- z))))}
(≃-trans {(- (- ((- x) ⊔ (- y))) ⊔ (- z))} {((- x) ⊔ (- y)) ⊔ (- z)} {(- x) ⊔ (- (- ((- y) ⊔ (- z))))}
(⊔-congʳ {(- z)} {(- (- ((- x) ⊔ (- y))))} {(- x) ⊔ (- y)} (neg-involutive ((- x) ⊔ (- y))))
(≃-trans {((- x) ⊔ (- y)) ⊔ (- z)} {(- x) ⊔ ((- y) ⊔ (- z))} {(- x) ⊔ (- (- ((- y) ⊔ (- z))))}
(⊔-assoc (- x) (- y) (- z)) (⊔-congˡ { - x} { - y ⊔ - z} { - (- (- y ⊔ - z))}
(≃-symm { - (- (- y ⊔ - z))} { - y ⊔ - z} (neg-involutive ((- y) ⊔ (- z)))))))
∣_∣ : ℝ -> ℝ
∣ x ∣ = x ⊔ (- x)
∣-∣-cong : Congruent₁ _≃_ ∣_∣
∣-∣-cong {x} {y} x≃y = ⊔-cong {x} {y} {(- x)} {(- y)} x≃y (-‿cong {x} {y} x≃y)
∣p∣≃p⊔-p : ∀ p -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ (ℚ.- p)
∣p∣≃p⊔-p p = [ left , right ]′ (ℚP.∣p∣≡p∨∣p∣≡-p p)
where
open ℚP.≤-Reasoning
left : ℚ.∣ p ∣ ≡ p -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ (ℚ.- p)
left hyp = begin-equality
ℚ.∣ p ∣ ≈⟨ ℚP.≃-reflexive hyp ⟩
p ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊔q≃p (ℚP.≤-trans (p≤∣p∣ (ℚ.- p)) (ℚP.≤-reflexive (ℚP.≃-trans (ℚP.∣-p∣≃∣p∣ p) (ℚP.≃-reflexive hyp))))) ⟩
p ℚ.⊔ (ℚ.- p) ∎
right : ℚ.∣ p ∣ ≡ ℚ.- p -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ (ℚ.- p)
right hyp = begin-equality
ℚ.∣ p ∣ ≈⟨ ℚP.≃-reflexive hyp ⟩
ℚ.- p ≈⟨ ℚP.≃-sym (ℚP.p≤q⇒p⊔q≃q (ℚP.≤-trans (p≤∣p∣ p) (ℚP.≤-reflexive (ℚP.≃-reflexive hyp)))) ⟩
p ℚ.⊔ (ℚ.- p) ∎
-- Alternate definition of absolute value defined pointwise in the real number's regular sequence
∣_∣₂ : ℝ -> ℝ
seq ∣ x ∣₂ n = ℚ.∣ seq x n ∣
reg ∣ x ∣₂ m n {m≢0} {n≢0} = begin
ℚ.∣ ℚ.∣ seq x m ∣ ℚ.- ℚ.∣ seq x n ∣ ∣ ≤⟨ ∣∣p∣-∣q∣∣≤∣p-q∣ (seq x m) (seq x n) ⟩
ℚ.∣ seq x m ℚ.- seq x n ∣ ≤⟨ reg x m n {m≢0} {n≢0} ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
∣x∣≃∣x∣₂ : ∀ x -> ∣ x ∣ ≃ ∣ x ∣₂
∣x∣≃∣x∣₂ x (suc k₁) = begin
ℚ.∣ (seq x n ℚ.⊔ (ℚ.- seq x n)) ℚ.- ℚ.∣ seq x n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- ℚ.∣ seq x n ∣) (ℚP.≃-sym (∣p∣≃p⊔-p (seq x n)))) ⟩
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- ℚ.∣ seq x n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ ℚ.∣ seq x n ∣) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
-- K(x*y)
--K∣x∣ K∣y∣
-- ∣x₁∣ + 2
∣x*y∣≃∣x∣*∣y∣ : ∀ x y -> ∣ x * y ∣ ≃ ∣ x ∣ * ∣ y ∣
∣x*y∣≃∣x∣*∣y∣ x y = ≃-trans {∣ x * y ∣} {∣ x * y ∣₂} {∣ x ∣ * ∣ y ∣}
(∣x∣≃∣x∣₂ (x * y))
(≃-trans {∣ x * y ∣₂} {∣ x ∣₂ * ∣ y ∣₂} {∣ x ∣ * ∣ y ∣}
(lemma1B ∣ x * y ∣₂ (∣ x ∣₂ * ∣ y ∣₂) lemA)
(*-cong {∣ x ∣₂} {∣ x ∣} {∣ y ∣₂} {∣ y ∣}
(≃-symm {∣ x ∣} {∣ x ∣₂} (∣x∣≃∣x∣₂ x)) (≃-symm {∣ y ∣} {∣ y ∣₂} (∣x∣≃∣x∣₂ y))))
where
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (∣ x * y ∣₂) n ℚ.- seq (∣ x ∣₂ * ∣ y ∣₂) n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
j : ℕ
j = suc k₁
r : ℕ
r = K x ℕ.⊔ K y
t : ℕ
t = K ∣ x ∣₂ ℕ.⊔ K ∣ y ∣₂
N₁ : ℕ
N₁ = proj₁ (regular⇒cauchy x (K y ℕ.* (2 ℕ.* j)))
N₂ : ℕ
N₂ = proj₁ (regular⇒cauchy y (K x ℕ.* (2 ℕ.* j)))
N : ℕ
N = N₁ ℕ.⊔ N₂
lemB : ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (∣ x * y ∣₂) n ℚ.- seq (∣ x ∣₂ * ∣ y ∣₂) n ∣ ℚ.≤ (+ 1 / j)
lemB (suc k₁) N<n = begin
ℚ.∣ ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ∣ ℚ.- ℚ.∣ x₂ₜₙ ∣ ℚ.* ℚ.∣ y₂ₜₙ ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ∣
(ℚP.-‿cong (ℚP.≃-sym (ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ₜₙ y₂ₜₙ)))) ⟩
ℚ.∣ ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ∣ ℚ.- ℚ.∣ x₂ₜₙ ℚ.* y₂ₜₙ ∣ ∣ ≤⟨ ∣∣p∣-∣q∣∣≤∣p-q∣ (x₂ᵣₙ ℚ.* y₂ᵣₙ) (x₂ₜₙ ℚ.* y₂ₜₙ) ⟩
ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ℚ.- x₂ₜₙ ℚ.* y₂ₜₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ x y z w ->
x ℚ:* y ℚ:- z ℚ:* w ℚ:=
(y ℚ:* (x ℚ:- z) ℚ:+ z ℚ:* (y ℚ:- w)))
ℚP.≃-refl x₂ᵣₙ y₂ᵣₙ x₂ₜₙ y₂ₜₙ) ⟩
ℚ.∣ y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₂ₜₙ) ℚ.+
x₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- y₂ₜₙ) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₂ₜₙ))
(x₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- y₂ₜₙ)) ⟩
ℚ.∣ y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₂ₜₙ) ∣ ℚ.+
ℚ.∣ x₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- y₂ₜₙ) ∣ ≈⟨ ℚP.+-cong
(ℚP.∣p*q∣≃∣p∣*∣q∣ y₂ᵣₙ (x₂ᵣₙ ℚ.- x₂ₜₙ))
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ₜₙ (y₂ᵣₙ ℚ.- y₂ₜₙ)) ⟩
ℚ.∣ y₂ᵣₙ ∣ ℚ.* ℚ.∣ x₂ᵣₙ ℚ.- x₂ₜₙ ∣ ℚ.+
ℚ.∣ x₂ₜₙ ∣ ℚ.* ℚ.∣ y₂ᵣₙ ℚ.- y₂ₜₙ ∣ ≤⟨ ℚP.+-mono-≤
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ᵣₙ ℚ.- x₂ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-greater y
(2 ℕ.* r ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K y / 1} _
(proj₂ (regular⇒cauchy x (K y ℕ.* (2 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* n)
(N₁≤ (N≤2kn r)) (N₁≤ (N≤2kn t)))))
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₂ᵣₙ ℚ.- y₂ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-greater x
(2 ℕ.* t ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(proj₂ (regular⇒cauchy y (K x ℕ.* (2 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* n)
(N₂≤ (N≤2kn r)) (N₂≤ (N≤2kn t))))) ⟩
(+ K y / 1) ℚ.* (+ 1 / (K y ℕ.* (2 ℕ.* j))) ℚ.+
(+ K x / 1) ℚ.* (+ 1 / (K x ℕ.* (2 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Kx Ky j ->
-- Function for solver
((Ky :* con (+ 1)) :* (con (+ 1) :* (Kx :* (con (+ 2) :* j))) :+ ((Kx :* con (+ 1)) :* (con (+ 1) :* (Ky :* (con (+ 2) :* j))))) :* j :=
con (+ 1) :* ((con (+ 1) :* (Ky :* (con (+ 2) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 2) :* j)))))
_≡_.refl (+ K x) (+ K y) (+ j)) ⟩
+ 1 / j ∎
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
n : ℕ
n = suc k₁
x₂ᵣₙ : ℚᵘ
x₂ᵣₙ = seq x (2 ℕ.* r ℕ.* n)
x₂ₜₙ : ℚᵘ
x₂ₜₙ = seq x (2 ℕ.* t ℕ.* n)
y₂ᵣₙ : ℚᵘ
y₂ᵣₙ = seq y (2 ℕ.* r ℕ.* n)
y₂ₜₙ : ℚᵘ
y₂ₜₙ = seq y (2 ℕ.* t ℕ.* n)
N≤2kn : ∀ (k : ℕ) -> {k ≢0} -> N ℕ.≤ 2 ℕ.* k ℕ.* n
N≤2kn (suc k₂) = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.m≤n*m n {2 ℕ.* (suc k₂)} ℕP.0<1+n)
N₁≤ : {m : ℕ} -> N ℕ.≤ m -> N₁ ℕ.≤ m
N₁≤ N≤m = ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) N≤m
N₂≤ : {m : ℕ} -> N ℕ.≤ m -> N₂ ℕ.≤ m
N₂≤ N≤m = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) N≤m
{-
A bunch of algebraic bundles from the standard library. I've followed the conventions used
in the standard library's properties file for unnormalised rationals.
Sometimes we use copatterns so we can use implicit arguments (e.g. in ≃-isEquivalence's
definition).
It's inconvenient, but some properties of ℝ might not work without implicit arguments.
For instance, if we use ≃-trans without its implicit arguments in ≃-isEquivalence below (so
just ≃-trans instead of ≃-trans {x} {y} {z}), Agda will give a constraint error.
-}
≃-isEquivalence : IsEquivalence _≃_
IsEquivalence.refl ≃-isEquivalence {x} = ≃-refl {x}
IsEquivalence.sym ≃-isEquivalence {x} {y} = ≃-symm {x} {y}
IsEquivalence.trans ≃-isEquivalence {x} {y} {z} = ≃-trans {x} {y} {z}
≃-setoid : Setoid 0ℓ 0ℓ
≃-setoid = record
{ isEquivalence = ≃-isEquivalence
}
+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≃_
; _∙_ = _+_
}
+-rawMonoid : RawMonoid 0ℓ 0ℓ
+-rawMonoid = record
{ _≈_ = _≃_
; _∙_ = _+_
; ε = 0ℝ
}
+-0-rawGroup : RawGroup 0ℓ 0ℓ
+-0-rawGroup = record
{ Carrier = ℝ
; _≈_ = _≃_
; _∙_ = _+_
; ε = 0ℝ
; _⁻¹ = -_
}
+-*-rawRing : RawRing 0ℓ 0ℓ
+-*-rawRing = record
{ Carrier = ℝ
; _≈_ = _≃_
; _+_ = _+_
; _*_ = _*_
; -_ = -_
; 0# = 0ℝ
; 1# = 1ℝ
}
+-isMagma : IsMagma _≃_ _+_
IsMagma.isEquivalence +-isMagma = ≃-isEquivalence
IsMagma.∙-cong +-isMagma {x} {y} {z} {w} = +-cong {x} {y} {z} {w}
+-isSemigroup : IsSemigroup _≃_ _+_
+-isSemigroup = record
{ isMagma = +-isMagma
; assoc = +-assoc
}
+-0-isMonoid : IsMonoid _≃_ _+_ 0ℝ
+-0-isMonoid = record
{ isSemigroup = +-isSemigroup
; identity = +-identity
}
+-0-isCommutativeMonoid : IsCommutativeMonoid _≃_ _+_ 0ℝ
+-0-isCommutativeMonoid = record
{ isMonoid = +-0-isMonoid
; comm = +-comm
}
+-0-isGroup : IsGroup _≃_ _+_ 0ℝ (-_)
IsGroup.isMonoid +-0-isGroup = +-0-isMonoid
IsGroup.inverse +-0-isGroup = +-inverse
IsGroup.⁻¹-cong +-0-isGroup {x} {y} = -‿cong {x} {y}
+-0-isAbelianGroup : IsAbelianGroup _≃_ _+_ 0ℝ (-_)
+-0-isAbelianGroup = record
{ isGroup = +-0-isGroup
; comm = +-comm
}
+-magma : Magma 0ℓ 0ℓ
+-magma = record
{ isMagma = +-isMagma
}
+-semigroup : Semigroup 0ℓ 0ℓ
+-semigroup = record
{ isSemigroup = +-isSemigroup
}
+-0-monoid : Monoid 0ℓ 0ℓ
+-0-monoid = record
{ isMonoid = +-0-isMonoid
}
+-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
+-0-commutativeMonoid = record
{ isCommutativeMonoid = +-0-isCommutativeMonoid
}
+-0-group : Group 0ℓ 0ℓ
+-0-group = record
{ isGroup = +-0-isGroup
}
+-0-abelianGroup : AbelianGroup 0ℓ 0ℓ
+-0-abelianGroup = record
{ isAbelianGroup = +-0-isAbelianGroup
}
*-rawMagma : RawMagma 0ℓ 0ℓ
*-rawMagma = record
{ _≈_ = _≃_
; _∙_ = _*_
}
*-rawMonoid : RawMonoid 0ℓ 0ℓ
*-rawMonoid = record
{ _≈_ = _≃_
; _∙_ = _*_
; ε = 1ℝ
}
*-isMagma : IsMagma _≃_ _*_
IsMagma.isEquivalence *-isMagma = ≃-isEquivalence
IsMagma.∙-cong *-isMagma {x} {y} {z} {w} = *-cong {x} {y} {z} {w}
*-isSemigroup : IsSemigroup _≃_ _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc
}
*-1-isMonoid : IsMonoid _≃_ _*_ 1ℝ
*-1-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _≃_ _*_ 1ℝ
*-1-isCommutativeMonoid = record
{ isMonoid = *-1-isMonoid
; comm = *-comm
}
+-*-isRing : IsRing _≃_ _+_ _*_ -_ 0ℝ 1ℝ
+-*-isRing = record
{ +-isAbelianGroup = +-0-isAbelianGroup
; *-isMonoid = *-1-isMonoid
; distrib = *-distrib-+
; zero = *-zero
}
+-*-isCommutativeRing : IsCommutativeRing _≃_ _+_ _*_ -_ 0ℝ 1ℝ
+-*-isCommutativeRing = record
{ isRing = +-*-isRing
; *-comm = *-comm
}
*-magma : Magma 0ℓ 0ℓ
*-magma = record
{ isMagma = *-isMagma
}
*-semigroup : Semigroup 0ℓ 0ℓ
*-semigroup = record
{ isSemigroup = *-isSemigroup
}
*-1-monoid : Monoid 0ℓ 0ℓ
*-1-monoid = record
{ isMonoid = *-1-isMonoid
}
*-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
*-1-commutativeMonoid = record
{ isCommutativeMonoid = *-1-isCommutativeMonoid
}
+-*-ring : Ring 0ℓ 0ℓ
+-*-ring = record
{ isRing = +-*-isRing
}
+-*-commutativeRing : CommutativeRing 0ℓ 0ℓ
+-*-commutativeRing = record
{ isCommutativeRing = +-*-isCommutativeRing
}
{- Predicates about sign of real number and some properties -}
Positive : Pred ℝ 0ℓ
Positive x = ∃ λ (n : ℕ) -> seq x (suc n) ℚ.> + 1 / (suc n)
-- ∀n∈ℕ( xₙ ≥ -n⁻¹)
NonNegative : Pred ℝ 0ℓ
NonNegative x = (n : ℕ) -> {n≢0 : n ≢0} -> seq x n ℚ.≥ ℚ.- ((+ 1 / n) {n≢0})
p<q⇒0<q-p : ∀ {p q} -> p ℚ.< q -> 0ℚᵘ ℚ.< q ℚ.- p
p<q⇒0<q-p {p} {q} p<q = begin-strict
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ p) ⟩
p ℚ.- p <⟨ ℚP.+-monoˡ-< (ℚ.- p) p<q ⟩
q ℚ.- p ∎
where
open ℚP.≤-Reasoning
-- r < Np
-- r < (Np)/1 Original version
-- r < (N/1) * p
-- r/N < p
archimedean-ℚ₂ : ∀ (p r : ℚᵘ) -> ℚ.Positive p -> ∃ λ (N : ℕ) ->
r ℚ.< (+ N / 1) ℚ.* p
archimedean-ℚ₂ p r p>0 = N , (begin-strict
r <⟨ proj₂ (archimedean-ℚ p r p>0) ⟩
((+ N) ℤ.* (↥ p)) / (↧ₙ p) ≈⟨ ℚ.*≡* (cong (λ x -> (+ N) ℤ.* (↥ p) ℤ.* x) (ℤP.*-identityˡ (↧ p))) ⟩
(+ N / 1) ℚ.* p ∎)
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
N : ℕ
N = proj₁ (archimedean-ℚ p r p>0)
lemma2-8-1a : ∀ x -> Positive x -> ∃ λ (N : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N ->
seq x m ℚ.≥ + 1 / (suc N)
lemma2-8-1a x (n-1 , xₙ>1/n) = N-1 , lem
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
n : ℕ
n = suc n-1
pos : ℚ.Positive (seq x n ℚ.- (+ 1 / n))
pos = 0<⇒pos (seq x n ℚ.- (+ 1 / n)) (p<q⇒0<q-p xₙ>1/n)
N-1 : ℕ
N-1 = proj₁ (archimedean-ℚ₂ (seq x n ℚ.- (+ 1 / n)) (+ 2 / 1) pos)
N : ℕ
N = suc N-1
part1 : + 2 / 1 ℚ.≤ (+ N / 1) ℚ.* (seq x n ℚ.- (+ 1 / n))
part1 = begin
+ 2 / 1 <⟨ proj₂ (archimedean-ℚ₂ (seq x n ℚ.- (+ 1 / n)) (+ 2 / 1) pos) ⟩
(+ N-1) / 1 ℚ.* (seq x n ℚ.- (+ 1 / n)) ≤⟨ ℚP.*-monoˡ-≤-nonNeg {seq x n ℚ.- + 1 / n}
(ℚP.positive⇒nonNegative {seq x n ℚ.- + 1 / n} pos) {+ N-1 / 1} {+ N / 1}
(*≤* (ℤP.*-monoʳ-≤-nonNeg 1 (+≤+ (ℕP.n≤1+n N-1)))) ⟩
(+ N / 1) ℚ.* (seq x n ℚ.- (+ 1 / n)) ∎
part2 : + 2 / N ℚ.≤ seq x n ℚ.- (+ 1 / n)
part2 = begin
+ 2 / N ≈⟨ ℚ.*≡* (sym (ℤP.*-assoc (+ 2) (+ 1) (+ N))) ⟩
(+ 2 / 1) ℚ.* (+ 1 / N) ≤⟨ ℚP.*-monoˡ-≤-nonNeg _ part1 ⟩
(+ N / 1) ℚ.* (seq x n ℚ.- (+ 1 / n)) ℚ.* (+ 1 / N) ≈⟨ ℚ.*≡* (solve 3 (λ N p q ->
((N :* p) :* con (+ 1)) :* q := (p :* ((con (+ 1) :* q) :* N)))
_≡_.refl (+ N) (↥ (seq x n ℚ.- (+ 1 / n))) (↧ (seq x n ℚ.- (+ 1 / n)))) ⟩
seq x n ℚ.- (+ 1 / n) ∎
part3 : + 1 / N ℚ.≤ seq x n ℚ.- (+ 1 / n) ℚ.- (+ 1 / N)
part3 = begin
+ 1 / N ≈⟨ ℚ.*≡* (solve 1 (λ N ->
con (+ 1) :* (N :* N) := (((con (+ 2) :* N) :+ (:- con (+ 1) :* N)) :* N)) _≡_.refl (+ N)) ⟩
(+ 2 / N) ℚ.- (+ 1 / N) ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- (+ 1 / N)) part2 ⟩
seq x n ℚ.- (+ 1 / n) ℚ.- (+ 1 / N) ∎
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq x m ℚ.≥ + 1 / N
lem (suc k₂) N≤m = begin
+ 1 / N ≤⟨ part3 ⟩
seq x n ℚ.- (+ 1 / n) ℚ.- (+ 1 / N) ≤⟨ ℚP.+-monoʳ-≤ (seq x n ℚ.- (+ 1 / n)) {ℚ.- (+ 1 / N)} {ℚ.- (+ 1 / m)}
(ℚP.neg-mono-≤ (*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ N≤m)))) ⟩
seq x n ℚ.- (+ 1 / n) ℚ.- (+ 1 / m) ≤⟨ ℚP.≤-respˡ-≃ (ℚsolve 3 (λ a b c -> a ℚ:- (b ℚ:+ c) ℚ:= a ℚ:- b ℚ:- c) ℚP.≃-refl (seq x n) (+ 1 / n) (+ 1 / m))
(ℚP.+-monoʳ-≤ (seq x n) (ℚP.neg-mono-≤ (reg x n m))) ⟩
seq x n ℚ.- ℚ.∣ seq x n ℚ.- seq x m ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x n) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x n ℚ.- seq x m))) ⟩
seq x n ℚ.- (seq x n ℚ.- seq x m) ≈⟨ ℚsolve 2 (λ a b -> a ℚ:- (a ℚ:- b) ℚ:= b) ℚP.≃-refl (seq x n) (seq x m) ⟩
seq x m ∎
where
m : ℕ
m = suc k₂
lemma2-8-1b : ∀ (x : ℝ) ->
(∃ λ (N-1 : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N-1 -> seq x m ℚ.≥ + 1 / (suc N-1)) ->
Positive x
lemma2-8-1b x (N-1 , proof) = N , (begin-strict
+ 1 / (suc N) <⟨ ℚ.*<* (ℤP.*-monoˡ-<-pos 0 (+<+ (ℕP.n<1+n N))) ⟩
+ 1 / N ≤⟨ proof (suc N) (ℕ.s≤s (ℕP.n≤1+n N-1)) ⟩
seq x (suc N) ∎)
where
open ℚP.≤-Reasoning
N : ℕ
N = suc N-1
-- xₙ ≥ -n⁻¹
-- Nonnegative x ⇒ ∀ n ∃ Nₙ ∀ m≥Nₙ (xₘ ≥ -n⁻¹)
lemma2-8-2a : ∀ (x : ℝ) -> NonNegative x -> ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
(∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})
lemma2-8-2a x x≥0 (suc k₁) = n , _ , λ {(suc m) m≥n → ℚP.≤-trans (ℚP.neg-mono-≤ (*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ m≥n)))) (x≥0 (suc m))}
where
n : ℕ
n = suc k₁
archimedean-ℚ₃ : ∀ (p : ℚᵘ) -> ∀ (r : ℤ) -> ℚ.Positive p -> ∃ λ (N-1 : ℕ) -> r / (suc N-1) ℚ.< p
archimedean-ℚ₃ p r 0<p = ℕ.pred N , (begin-strict
r / N ≈⟨ ℚP.≃-reflexive (ℚP./-cong (sym (ℤP.*-identityʳ r)) (sym (ℕP.*-identityˡ N)) _ _) ⟩
(r / 1) ℚ.* (+ 1 / N) <⟨ ℚP.*-monoˡ-<-pos {+ 1 / N} _ {r / 1} {(+ N / 1) ℚ.* p} (ℚP.<-trans (proj₂ (archimedean-ℚ₂ p (r / 1) 0<p))
(ℚP.*-monoˡ-<-pos {p} 0<p {+ (ℕ.pred N) / 1} {+ N / 1} (ℚ.*<* (ℤP.*-monoʳ-<-pos 0 (+<+ (ℕP.n<1+n (ℕ.pred N))))))) ⟩
(+ N / 1) ℚ.* p ℚ.* (+ 1 / N) ≈⟨ ℚ.*≡* (solve 3 (λ N n d ->
((N :* n) :* con (+ 1)) :* d := (n :* (con (+ 1) :* d :* N)))
_≡_.refl (+ N) (↥ p) (↧ p)) ⟩
p ∎)
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
N : ℕ
N = suc (proj₁ (archimedean-ℚ₂ p (r / 1) 0<p))
-- y - ε ≤ x
-- y ≤ x
ℚ-≤-lemma : ∀ (x y : ℚᵘ) ->
(∀ (j : ℕ) -> {j≢0 : j ≢0} -> y ℚ.- (+ 1 / j) {j≢0} ℚ.≤ x) ->
y ℚ.≤ x
ℚ-≤-lemma x y hyp with ℚP.<-cmp y x
... | tri< a ¬b ¬c = ℚP.<⇒≤ a
... | tri≈ ¬a b ¬c = ℚP.≤-reflexive b
... | tri> ¬a ¬b c = ⊥-elim (ℚP.<⇒≱ lem (hyp N))
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
N : ℕ
N = suc (proj₁ (archimedean-ℚ₃ (y ℚ.- x) (+ 1) (0<⇒pos (y ℚ.- x) (p<q⇒0<q-p c))))
lem : x ℚ.< y ℚ.- (+ 1 / N)
lem = begin-strict
x ≈⟨ solve 2 (λ a b -> a := a :+ b :- b) ℚP.≃-refl x (+ 1 / N) ⟩
x ℚ.+ (+ 1 / N) ℚ.- (+ 1 / N) <⟨ ℚP.+-monoˡ-< (ℚ.- (+ 1 / N))
(ℚP.+-monoʳ-< x (proj₂ (archimedean-ℚ₃ (y ℚ.- x) (+ 1) (0<⇒pos (y ℚ.- x) (p<q⇒0<q-p c))))) ⟩
x ℚ.+ (y ℚ.- x) ℚ.- (+ 1 / N) ≈⟨ solve 3 (λ a b c -> a :+ (b :- a) :- c := b :- c) ℚP.≃-refl x y (+ 1 / N) ⟩
y ℚ.- (+ 1 / N) ∎
{-
Proof of ̄if direction of Lemma 2.8.2:
Let j∈ℤ⁺, let n = 2j, and let m = max{Nₙ, 2j}. Let k∈ℕ. We must show
that xₖ ≥ -k⁻¹. We have:
xₖ = xₘ - (xₘ - xₖ)
≥ xₘ - ∣xₘ - xₖ∣
≥ -n⁻¹ - ∣xₘ - xₖ∣ by assumption since m ≥ Nₙ
≥ -n⁻¹ - (m⁻¹ + k⁻¹) by regularity of x
= -k⁻¹ - (m⁻¹ + n⁻¹)
≥ -k⁻¹ - ((2j)⁻¹ + (2j)⁻¹) since m ≥ 2j and n = 2j
= -k⁻¹ - 1/j.
Thus, for all j∈ℤ⁺, we have
xₖ ≥ -k⁻¹ - 1/j.
Hence xₖ ≥ -k⁻¹, and we are done. □
-}
lemma2-8-2b : ∀ (x : ℝ) -> (∀ (n : ℕ) -> {n≢0 : n ≢0} ->
∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
(∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})) ->
NonNegative x
lemma2-8-2b x hyp K {K≢0} = lemB K {K≢0} (lemA K {K≢0})
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; :-_ to ℚ:-_
; _:=_ to _ℚ:=_
)
lemA : ∀ (k : ℕ) -> {k≢0 : k ≢0} -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
seq x k ℚ.≥ ℚ.- (+ 1 / k) {k≢0} ℚ.- (+ 1 / j) {j≢0}
lemA (suc k₁) (suc k₂) = begin
ℚ.- (+ 1 / k) ℚ.- (+ 1 / j) ≈⟨ ℚP.+-congʳ (ℚ.- (+ 1 / k)) {ℚ.- (+ 1 / j)} {ℚ.- ((+ 1 / (2 ℕ.* j)) ℚ.+ (+ 1 / (2 ℕ.* j)))}
(ℚP.-‿cong (ℚ.*≡* (solve 1 (λ j ->
con (+ 1) :* (con (+ 2) :* j :* (con (+ 2) :* j)) :=
((con (+ 1) :* (con (+ 2) :* j) :+ con (+ 1) :* (con (+ 2) :* j)) :* j))
_≡_.refl (+ j)))) ⟩
ℚ.- (+ 1 / k) ℚ.- ((+ 1 / n) ℚ.+ (+ 1 / n)) ≤⟨ ℚP.+-monoʳ-≤ (ℚ.- (+ 1 / k)) {ℚ.- ((+ 1 / n) ℚ.+ (+ 1 / n))} {ℚ.- ((+ 1 / m) ℚ.+ (+ 1 / n))}
(ℚP.neg-mono-≤ {(+ 1 / m) ℚ.+ (+ 1 / n)} {(+ 1 / n) ℚ.+ (+ 1 / n)}
(ℚP.+-monoˡ-≤ (+ 1 / n) {+ 1 / m} {+ 1 / n} (*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n⊔m (suc Nₙ) n)))))) ⟩
ℚ.- (+ 1 / k) ℚ.- ((+ 1 / m) ℚ.+ (+ 1 / n)) ≈⟨ ℚsolve 3 (λ x y z ->
ℚ:- x ℚ:- (y ℚ:+ z) ℚ:= ℚ:- z ℚ:- (y ℚ:+ x))
ℚP.≃-refl (+ 1 / k) (+ 1 / m) (+ 1 / n) ⟩
ℚ.- (+ 1 / n) ℚ.- ((+ 1 / m) ℚ.+ (+ 1 / k)) ≤⟨ ℚP.+-mono-≤ (proj₂ (proj₂ (hyp n)) m (ℕP.≤-trans (ℕP.n≤1+n Nₙ) (ℕP.m≤m⊔n (suc Nₙ) n)))
(ℚP.neg-mono-≤ (reg x m k)) ⟩
seq x m ℚ.- ℚ.∣ seq x m ℚ.- seq x k ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x m) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x m ℚ.- seq x k))) ⟩
seq x m ℚ.- (seq x m ℚ.- seq x k) ≈⟨ ℚsolve 2 (λ x y -> x ℚ:- (x ℚ:- y) ℚ:= y) ℚP.≃-refl (seq x m) (seq x k) ⟩
seq x k ∎
where
k : ℕ
k = suc k₁
j : ℕ
j = suc k₂
n : ℕ
n = 2 ℕ.* j
Nₙ : ℕ
Nₙ = proj₁ (hyp n)
m : ℕ
m = (suc Nₙ) ℕ.⊔ 2 ℕ.* j
lemB : ∀ (k : ℕ) -> {k≢0 : k ≢0} -> (∀ (j : ℕ) -> {j≢0 : j ≢0} ->
seq x k ℚ.≥ ℚ.- (+ 1 / k) {k≢0} ℚ.- (+ 1 / j) {j≢0}) ->
seq x k ℚ.≥ ℚ.- (+ 1 / k) {k≢0}
lemB (suc k₁) = ℚ-≤-lemma (seq x (suc k₁)) (ℚ.- (+ 1 / (suc k₁)))
{-
Proposition:
If x is positive and x ≃ y, then y is positive.
Proof
Since x is positive, there is N₁∈ℕ such that xₘ ≥ N₁⁻¹ for all m ≥ N.
Since x ≃ y, there is N₂∈ℕ such that, for all m > N₂, we have
∣ xₘ - yₘ ∣ ≤ (2N₁)⁻¹. Let N = max{N₁, N₂} and let m ≥ 2N. Then N₁ ≤ N, so
N⁻¹ ≤ N₁⁻¹. We have:
yₘ ≥ xₘ - ∣ xₘ - yₘ ∣
≥ N₁⁻¹ - (2N₁)⁻¹
= (2N₁)⁻¹
≥ (2N)⁻¹.
Thus yₘ ≥ (2N)⁻¹ for all m ≥ 2N. Hence y is positive. □
-}
pos-cong : ∀ x y -> x ≃ y -> Positive x -> Positive y
pos-cong x y x≃y posx = lemma2-8-1b y (ℕ.pred (2 ℕ.* N) , lemA)
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
N₁ : ℕ
N₁ = suc (proj₁ (lemma2-8-1a x posx))
N₂ : ℕ
N₂ = proj₁ (lemma1A x y x≃y (2 ℕ.* N₁))
N : ℕ
N = N₁ ℕ.⊔ N₂
lemA : ∀ (m : ℕ) -> m ℕ.≥ 2 ℕ.* N -> seq y m ℚ.≥ + 1 / (2 ℕ.* N)
lemA m m≥2N = begin
+ 1 / (2 ℕ.* N) ≤⟨ *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (ℤP.*-monoˡ-≤-nonNeg 2 (+≤+ (ℕP.m≤m⊔n N₁ N₂)))) ⟩
+ 1 / (2 ℕ.* N₁) ≈⟨ ℚ.*≡* (solve 1 (λ N₁ ->
con (+ 1) :* (N₁ :* (con (+ 2) :* N₁)) :=
(con (+ 1) :* (con (+ 2) :* N₁) :+ (:- con (+ 1)) :* N₁) :* (con (+ 2) :* N₁))
_≡_.refl (+ N₁)) ⟩
(+ 1 / N₁) ℚ.- (+ 1 / (2 ℕ.* N₁)) ≤⟨ ℚP.+-mono-≤
(proj₂ (lemma2-8-1a x posx) m (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.<⇒≤ N<m)))
(ℚP.neg-mono-≤ (proj₂ (lemma1A x y x≃y (2 ℕ.* N₁)) m
(ℕP.<-transʳ (ℕP.m≤n⊔m N₁ N₂) N<m))) ⟩
seq x m ℚ.- ℚ.∣ seq x m ℚ.- seq y m ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x m) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x m ℚ.- seq y m))) ⟩
seq x m ℚ.- (seq x m ℚ.- seq y m) ≈⟨ ℚsolve 2 (λ xₘ yₘ -> xₘ ℚ:- (xₘ ℚ:- yₘ) ℚ:= yₘ) ℚP.≃-refl (seq x m) (seq y m) ⟩
seq y m ∎
where
N<m : N ℕ.< m
N<m = ℕP.<-transˡ (ℕP.<-transˡ (ℕP.m<n+m N {N} ℕP.0<1+n)
(ℤP.drop‿+≤+ (ℤP.≤-reflexive (solve 1 (λ N -> N :+ N := con (+ 2) :* N) _≡_.refl (+ N))))) m≥2N
{-
Let x be a positive real number. By Lemma 2.8.1, there is N∈ℕ such that
xₘ ≥ N⁻¹ (m ≥ N).
Let n∈ℕ and let Nₙ = N. Then:
-n⁻¹ < 0
< N⁻¹
≤ xₘ
for all m ≥ Nₙ. Hence x is nonnegative by Lemma 2.8.2. □
-}
pos⇒nonNeg : ∀ x -> Positive x -> NonNegative x
pos⇒nonNeg x posx = lemma2-8-2b x lemA
where
open ℚP.≤-Reasoning
N : ℕ
N = suc (proj₁ (lemma2-8-1a x posx))
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) ->
Nₙ ≢0 × ∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0}
lemA (suc k₁) = N , _ , lemB
where
n : ℕ
n = suc k₁
test : ℚ.Negative (ℚ.- (+ 1 / n))
test = _
lemB : ∀ (m : ℕ) -> m ℕ.≥ N -> seq x m ℚ.≥ ℚ.- (+ 1 / n)
lemB m m≥N = begin
ℚ.- (+ 1 / n) <⟨ ℚP.negative⁻¹ _ ⟩
0ℚᵘ <⟨ ℚP.positive⁻¹ _ ⟩
+ 1 / N ≤⟨ proj₂ (lemma2-8-1a x posx) m m≥N ⟩
seq x m ∎
{-
Proposition:
If x and y are positive, then so is x + y.
Proof:
By Lemma 2.8.1, there is N₁∈ℕ such that m ≥ N₁ implies xₘ ≥ N₂⁻¹. Similarly,
there is N₂∈ℕ such that m ≥ N₂ implies yₘ ≥ N₂⁻¹. Define N = max{N₁, N₂}, and
let m ≥ N. We have:
(x + y)ₘ = x₂ₘ + y₂ₘ
≥ N₁⁻¹ + N₂⁻¹
≥ N⁻¹ + N⁻¹
≥ N⁻¹.
Thus (x + y)ₘ ≥ N⁻¹ for all m ≥ N. By Lemma 2.8.1, x + y is positive. □
-}
posx,y⇒posx+y : ∀ x y -> Positive x -> Positive y -> Positive (x + y)
posx,y⇒posx+y x y posx posy = lemma2-8-1b (x + y) (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
N₁ : ℕ
N₁ = suc (proj₁ (lemma2-8-1a x posx))
N₂ : ℕ
N₂ = suc (proj₁ (lemma2-8-1a y posy))
N : ℕ
N = N₁ ℕ.⊔ N₂
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x + y) m ℚ.≥ + 1 / N
lem m m≥N = begin
+ 1 / N ≤⟨ ℚP.p≤p+q {+ 1 / N} {+ 1 / N} _ ⟩
(+ 1 / N) ℚ.+ (+ 1 / N) ≤⟨ ℚP.+-mono-≤ {+ 1 / N} {+ 1 / N₁} {+ 1 / N} {+ 1 / N₂}
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m⊔n N₁ N₂))))
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n⊔m N₁ N₂)))) ⟩
(+ 1 / N₁) ℚ.+ (+ 1 / N₂) ≤⟨ ℚP.+-mono-≤ {+ 1 / N₁} {seq x (2 ℕ.* m)} {+ 1 / N₂} {seq y (2 ℕ.* m)}
(proj₂ (lemma2-8-1a x posx) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n))))
(proj₂ (lemma2-8-1a y posy) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n)))) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎
nonNegx,y⇒nonNegx+y : ∀ x y -> NonNegative x -> NonNegative y -> NonNegative (x + y)
nonNegx,y⇒nonNegx+y x y nonx nony = lemma2-8-2b (x + y) lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 × ∀ (m : ℕ) -> m ℕ.≥ Nₙ ->
seq (x + y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0}
lemA (suc k₁) = N , _ , lemB
where
n : ℕ
n = suc k₁
Nx : ℕ
Nx = proj₁ (lemma2-8-2a x nonx (2 ℕ.* n))
Ny : ℕ
Ny = proj₁ (lemma2-8-2a y nony (2 ℕ.* n))
N : ℕ
N = Nx ℕ.⊔ Ny
lemB : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x + y) m ℚ.≥ ℚ.- (+ 1 / n)
lemB m m≥N = begin
ℚ.- (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(:- con (+ 1)) :* (con (+ 2) :* n :* (con (+ 2) :* n)) :=
(((:- con (+ 1)) :* (con (+ 2) :* n) :+ ((:- con (+ 1)) :* (con (+ 2) :* n))) :* n))
_≡_.refl (+ n)) ⟩
ℚ.- (+ 1 / (2 ℕ.* n)) ℚ.- (+ 1 / (2 ℕ.* n)) ≤⟨ ℚP.+-mono-≤
(proj₂ (proj₂ (lemma2-8-2a x nonx (2 ℕ.* n))) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤m⊔n Nx Ny) (ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n))))
(proj₂ (proj₂ (lemma2-8-2a y nony (2 ℕ.* n))) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤n⊔m Nx Ny) (ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n)))) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎
{-
Suppose x≃y and x is nonnegative. WTS y is nonnegative. Then, for each n∈ℕ, there is
Nₙ∈ℕ such that m≥Nₙ implies xₘ ≥ -n⁻¹. Thus there is N₁∈ℕ such that m ≥ N₁ implies
xₘ ≥ -(2n)⁻¹. Since x ≃ y, there is N₂∈ℕ such that m ≥ N₂ implies ∣xₘ - yₘ∣ ≤ (2n)⁻¹.
Let N = max{N₁, N₂} and let m ≥ N. We have:
yₘ ≥ xₘ - ∣xₘ - yₘ∣
≥ -(2n)⁻¹ - (2n)⁻¹
= -n⁻¹,
so yₘ ≥ -n⁻¹ for all m ≥ N. Thus y is nonnegative. □
-}
nonNeg-cong : ∀ x y -> x ≃ y -> NonNegative x -> NonNegative y
nonNeg-cong x y x≃y nonx = lemma2-8-2b y lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq y m ℚ.≥ ℚ.- (+ 1 / n)
lemA (suc k₁) = N , _ , lemB
where
n : ℕ
n = suc k₁
N₁ : ℕ
N₁ = proj₁ (lemma2-8-2a x nonx (2 ℕ.* n))
N₂ : ℕ
N₂ = proj₁ (lemma1A x y x≃y (2 ℕ.* n))
N : ℕ
N = suc (N₁ ℕ.⊔ N₂)
lemB : ∀ (m : ℕ) -> m ℕ.≥ N -> seq y m ℚ.≥ ℚ.- (+ 1 / n)
lemB m m≥N = begin
ℚ.- (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(:- con (+ 1)) :* (con (+ 2) :* n :* (con (+ 2) :* n)) :=
(((:- con (+ 1)) :* (con (+ 2) :* n) :+ ((:- con (+ 1)) :* (con (+ 2) :* n))) :* n))
_≡_.refl (+ n)) ⟩
ℚ.- (+ 1 / (2 ℕ.* n)) ℚ.- (+ 1 / (2 ℕ.* n)) ≤⟨ ℚP.+-mono-≤
(proj₂ (proj₂ (lemma2-8-2a x nonx (2 ℕ.* n))) m
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.n≤1+n (N₁ ℕ.⊔ N₂)) m≥N)))
(ℚP.neg-mono-≤ (proj₂ (lemma1A x y x≃y (2 ℕ.* n)) m (ℕP.<-transʳ (ℕP.m≤n⊔m N₁ N₂) m≥N))) ⟩
seq x m ℚ.- ℚ.∣ seq x m ℚ.- seq y m ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x m) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x m ℚ.- seq y m))) ⟩
seq x m ℚ.- (seq x m ℚ.- seq y m) ≈⟨ ℚsolve 2 (λ x y -> x ℚ:- (x ℚ:- y) ℚ:= y) ℚP.≃-refl (seq x m) (seq y m) ⟩
seq y m ∎
{-
Proposition:
If x is positive and y is nonnegative, then x + y is positive.
Proof:
Since x is positive, there is an N₁∈ℕ such that xₘ ≥ N₁⁻¹ for all m ≥ N₁. Since y is
nonnegative, there is N₂∈ℕ such that, for all m ≥ N₂, we have yₘ ≥ -(2N₁)⁻¹. Let N = 2max{N₁, N₂}.
Let m ≥ N ≥ N₁, N₂. We have:
(x + y)ₘ = x₂ₘ + y₂ₘ
≥ N₁⁻¹ - (2N₁)⁻¹
= (2N₁)⁻¹.
≥ N⁻¹.
Thus (x + y)ₘ ≥ N⁻¹ for all m ≥ N. By Lemma 2.8.1, x + y is positive. □
-}
posx∧nonNegy⇒posx+y : ∀ x y -> Positive x -> NonNegative y -> Positive (x + y)
posx∧nonNegy⇒posx+y x y posx nony = lemma2-8-1b (x + y) (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
N₁ : ℕ
N₁ = suc (proj₁ (lemma2-8-1a x posx))
N₂ : ℕ
N₂ = proj₁ (lemma2-8-2a y nony (2 ℕ.* N₁))
N : ℕ
N = 2 ℕ.* (N₁ ℕ.⊔ N₂)
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x + y) m ℚ.≥ + 1 / N
lem m m≥N = begin
+ 1 / N ≤⟨ *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (ℤP.*-monoˡ-≤-nonNeg 2 (+≤+ (ℕP.m≤m⊔n N₁ N₂)))) ⟩
+ 1 / (2 ℕ.* N₁) ≈⟨ ℚ.*≡* (solve 1 (λ N₁ ->
con (+ 1) :* (N₁ :* (con (+ 2) :* N₁)) :=
(con (+ 1) :* (con (+ 2) :* N₁) :+ (:- con (+ 1)) :* N₁) :* (con (+ 2) :* N₁))
_≡_.refl (+ N₁)) ⟩
(+ 1 / N₁) ℚ.- (+ 1 / (2 ℕ.* N₁)) ≤⟨ ℚP.+-mono-≤ (proj₂ (lemma2-8-1a x posx) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.m≤n*m (N₁ ℕ.⊔ N₂) {2} ℕP.0<1+n)
(ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n)))))
(proj₂ (proj₂ (lemma2-8-2a y nony (2 ℕ.* N₁))) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.m≤n*m (N₁ ℕ.⊔ N₂) {2} ℕP.0<1+n)
(ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n))))) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎
∣x∣nonNeg : ∀ x -> NonNegative ∣ x ∣
∣x∣nonNeg x = nonNeg-cong ∣ x ∣₂ ∣ x ∣ (≃-symm {∣ x ∣} {∣ x ∣₂} (∣x∣≃∣x∣₂ x)) λ {(suc k₁) -> ℚP.≤-trans (ℚP.nonPositive⁻¹ _) (ℚP.0≤∣p∣ (seq x (suc k₁)))}
{-
Module for chain of equality reasoning on ℝ
-}
module ≃-Reasoning where
open import Relation.Binary.Reasoning.Setoid ≃-setoid
public
{-
Proposition:
If x is nonnegative, then ∣x∣ = x.
Proof:
Let j∈ℕ. Since x is nonnegative, there is N∈ℕ such that
xₘ ≥ -(2j)⁻¹ (m ≥ N).
Let m ≥ N. Then -2xₘ ≤ j⁻¹. Either xₘ ≥ 0 or xₘ < 0.
Case 1: Suppose xₘ ≥ 0. Then:
∣∣xₘ∣ - xₘ∣ = ∣xₘ∣ - xₘ
= xₘ - xₘ
= 0
≤ j⁻¹
Case 2: Suppose xₘ < 0. Then:
∣∣xₘ∣ - xₘ∣ = ∣xₘ∣ - xₘ
= -xₘ - xₘ
= -2xₘ
≤ j⁻¹.
Thus ∣∣xₘ∣ - xₘ∣ ≤ j⁻¹ for all m ≥ N. By Lemma 1, ∣x∣ = x. □
-}
nonNegx⇒∣x∣₂≃x : ∀ x -> NonNegative x -> ∣ x ∣₂ ≃ x
nonNegx⇒∣x∣₂≃x x nonx = lemma1B ∣ x ∣₂ x lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq ∣ x ∣₂ n ℚ.- seq x n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
j : ℕ
j = suc k₁
N : ℕ
N = proj₁ (lemma2-8-2a x nonx (2 ℕ.* j))
lemB : ∀ (n : ℕ) -> N ℕ.< n -> ℚ.∣ seq ∣ x ∣₂ n ℚ.- seq x n ∣ ℚ.≤ + 1 / j
lemB (suc k₂) N<n = [ left , right ]′ (ℚP.≤-total (seq x n) 0ℚᵘ)
where
n : ℕ
n = suc k₂
-xₙ≤1/2j : ℚ.- seq x n ℚ.≤ + 1 / (2 ℕ.* j)
-xₙ≤1/2j = begin
ℚ.- seq x n ≤⟨ ℚP.neg-mono-≤ (proj₂ (proj₂ (lemma2-8-2a x nonx (2 ℕ.* j))) n (ℕP.<⇒≤ N<n)) ⟩
ℚ.- (ℚ.- (+ 1 / (2 ℕ.* j))) ≈⟨ ℚP.neg-involutive (+ 1 / (2 ℕ.* j)) ⟩
+ 1 / (2 ℕ.* j) ∎
left : seq x n ℚ.≤ 0ℚᵘ -> ℚ.∣ seq ∣ x ∣₂ n ℚ.- seq x n ∣ ℚ.≤ + 1 / j
left hyp = begin
ℚ.∣ seq ∣ x ∣₂ n ℚ.- seq x n ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p (p≤∣p∣ (seq x n))) ⟩
ℚ.∣ seq x n ∣ ℚ.- seq x n ≈⟨ ℚP.+-congˡ (ℚ.- seq x n) (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (seq x n))) ⟩
ℚ.∣ ℚ.- seq x n ∣ ℚ.- seq x n ≈⟨ ℚP.+-congˡ (ℚ.- seq x n) (ℚP.0≤p⇒∣p∣≃p (ℚP.neg-mono-≤ hyp)) ⟩
ℚ.- seq x n ℚ.- seq x n ≤⟨ ℚP.+-mono-≤ -xₙ≤1/2j -xₙ≤1/2j ⟩
(+ 1 / (2 ℕ.* j)) ℚ.+ (+ 1 / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(con (+ 1) :* (con (+ 2) :* j) :+ con (+ 1) :* (con (+ 2) :* j)) :* j :=
(con (+ 1) :* (con (+ 2) :* j :* (con (+ 2) :* j)))) _≡_.refl (+ j)) ⟩
+ 1 / j ∎
right : 0ℚᵘ ℚ.≤ seq x n -> ℚ.∣ seq ∣ x ∣₂ n ℚ.- seq x n ∣ ℚ.≤ + 1 / j
right hyp = begin
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- seq x n ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p (p≤∣p∣ (seq x n))) ⟩
ℚ.∣ seq x n ∣ ℚ.- seq x n ≈⟨ ℚP.+-congˡ (ℚ.- seq x n) (ℚP.0≤p⇒∣p∣≃p hyp) ⟩
seq x n ℚ.- seq x n ≈⟨ ℚP.+-inverseʳ (seq x n) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 1 / j ∎
nonNegx⇒∣x∣≃x : ∀ x -> NonNegative x -> ∣ x ∣ ≃ x
nonNegx⇒∣x∣≃x x nonx = ≃-trans {∣ x ∣} {∣ x ∣₂} {x} (∣x∣≃∣x∣₂ x) (nonNegx⇒∣x∣₂≃x x nonx)
{-
Proposition:
If x and y are nonnegative, then so is x * y.
Proof:
Since x and y are nonnegative, we have x = ∣x∣ and y = ∣y∣. Then x*y = ∣x∣*∣y∣ = ∣x*y∣, which is nonnegative. □
-}
nonNegx,y⇒nonNegx*y : ∀ x y -> NonNegative x -> NonNegative y -> NonNegative (x * y)
nonNegx,y⇒nonNegx*y x y nonx nony = nonNeg-cong ∣ x * y ∣ (x * y) lem (∣x∣nonNeg (x * y))
where
open ≃-Reasoning
lem : ∣ x * y ∣ ≃ x * y
lem = begin
∣ x * y ∣ ≈⟨ ∣x*y∣≃∣x∣*∣y∣ x y ⟩
∣ x ∣ * ∣ y ∣ ≈⟨ *-cong {∣ x ∣} {x} {∣ y ∣} {y} (nonNegx⇒∣x∣≃x x nonx) (nonNegx⇒∣x∣≃x y nony) ⟩
x * y ∎
{-
Proposition:
If x and y are positive, then so is x * y.
Proof:
By Lemma 2.8.1, there exists N₁,N₂∈ℕ such that
xₘ ≥ N₁⁻¹ (m ≥ N₁), and
yₘ ≥ N₂⁻¹ (m ≥ N₂).
Let N = max{N₁, N₂} and let m ≥ N². We have:
x₂ₖₘy₂ₖₘ ≥ N₁⁻¹N₂⁻¹
≥ N⁻¹ * N⁻¹
= (N²)⁻¹,
so x₂ₖₘy₂ₖₘ ≥ (N²)⁻¹ for all m ≥ N². By Lemma 2.8.1, x * y is
positive. □
-}
posx,y⇒posx*y : ∀ x y -> Positive x -> Positive y -> Positive (x * y)
posx,y⇒posx*y x y posx posy = lemma2-8-1b (x * y) (ℕ.pred (N ℕ.* N) , lem)
where
open ℚP.≤-Reasoning
k : ℕ
k = K x ℕ.⊔ K y
N₁ : ℕ
N₁ = suc (proj₁ (lemma2-8-1a x posx))
N₂ : ℕ
N₂ = suc (proj₁ (lemma2-8-1a y posy))
N : ℕ
N = N₁ ℕ.⊔ N₂
lem : ∀ (m : ℕ) -> m ℕ.≥ N ℕ.* N -> seq (x * y) m ℚ.≥ + 1 / (N ℕ.* N)
lem m m≥N² = begin
+ 1 / (N ℕ.* N) ≡⟨ _≡_.refl ⟩
(+ 1 / N) ℚ.* (+ 1 / N) ≤⟨ ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {+ 1 / N} _ {+ 1 / N} {+ 1 / N₁}
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m⊔n N₁ N₂)))))
(ℚP.*-monoʳ-≤-nonNeg {+ 1 / N₁} _ {+ 1 / N} {+ 1 / N₂}
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n⊔m N₁ N₂))))) ⟩
(+ 1 / N₁) ℚ.* (+ 1 / N₂) ≤⟨ ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {+ 1 / N₂} _ {+ 1 / N₁} {seq x (2 ℕ.* k ℕ.* m)}
(proj₂ (lemma2-8-1a x posx) (2 ℕ.* k ℕ.* m)
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) N≤2km)))
(ℚP.*-monoʳ-≤-pos {seq x (2 ℕ.* k ℕ.* m)} posx₂ₖₘ {+ 1 / N₂}
{seq y (2 ℕ.* k ℕ.* m)}
(proj₂ (lemma2-8-1a y posy) (2 ℕ.* k ℕ.* m)
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) N≤2km))) ⟩
seq x (2 ℕ.* k ℕ.* m) ℚ.* seq y (2 ℕ.* k ℕ.* m) ∎
where
N≤2km : N ℕ.≤ 2 ℕ.* k ℕ.* m
N≤2km = ℕP.≤-trans (ℕP.m≤n*m N {N} ℕP.0<1+n) (ℕP.≤-trans m≥N² (ℕP.m≤n*m m {2 ℕ.* k} ℕP.0<1+n))
posx₂ₖₘ : ℚ.Positive (seq x (2 ℕ.* k ℕ.* m))
posx₂ₖₘ = 0<⇒pos (seq x (2 ℕ.* k ℕ.* m)) (ℚP.<-≤-trans {0ℚᵘ} {+ 1 / N₁} {seq x (2 ℕ.* k ℕ.* m)}
(ℚP.positive⁻¹ _) (proj₂ (lemma2-8-1a x posx) (2 ℕ.* k ℕ.* m) (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) N≤2km)))
{-
Proposition:
If x is positive and y is any real number, then max{x, y} is positive.
Proof:
Since x is positive, there is N∈ℕ such that m ≥ N implies xₘ ≥ N⁻¹. Let
m ≥ N. We have:
(x ⊔ y)ₘ = xₘ ⊔ yₘ
≥ xₘ
≥ N⁻¹.
-}
posx⇒posx⊔y : ∀ x y -> Positive x -> Positive (x ⊔ y)
posx⇒posx⊔y x y posx = lemma2-8-1b (x ⊔ y) (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
N : ℕ
N = suc (proj₁ (lemma2-8-1a x posx))
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x ⊔ y) m ℚ.≥ + 1 / N
lem m m≥N = begin
+ 1 / N ≤⟨ proj₂ (lemma2-8-1a x posx) m m≥N ⟩
seq x m ≤⟨ ℚP.p≤p⊔q (seq x m) (seq y m) ⟩
seq x m ℚ.⊔ seq y m ∎
{-
Proposition:
If x is nonnegative and y is any real number, then max{x, y} is nonnegative.
Proof:
Since x is nonnegative, for each n∈ℕ there is Nₙ∈ℕ such that xₘ ≥ -n⁻¹ for all
m ≥ Nₙ. Let m ≥ Nₙ. Then:
(x ⊔ y)ₘ = xₘ ⊔ yₘ
≥ xₘ
≥ -n⁻¹.
-}
nonNegx⇒nonNegx⊔y : ∀ x y -> NonNegative x -> NonNegative (x ⊔ y)
nonNegx⇒nonNegx⊔y x y nonx = lemma2-8-2b (x ⊔ y) lemA
where
open ℚP.≤-Reasoning
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊔ y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0}
lemA n {n≢0} = Nₙ , proj₁ (proj₂ (lemma2-8-2a x nonx n {n≢0})) , lemB
where
Nₙ : ℕ
Nₙ = proj₁ (lemma2-8-2a x nonx n {n≢0})
lemB : ∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊔ y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0}
lemB m m≥Nₙ = begin
ℚ.- (+ 1 / n) {n≢0} ≤⟨ proj₂ (proj₂ (lemma2-8-2a x nonx n {n≢0})) m m≥Nₙ ⟩
seq x m ≤⟨ ℚP.p≤p⊔q (seq x m) (seq y m) ⟩
seq x m ℚ.⊔ seq y m ∎
_⊓₂_ : (x y : ℝ) -> ℝ
seq (x ⊓₂ y) m = seq x m ℚ.⊓ seq y m
reg (x ⊓₂ y) (suc k₁) (suc k₂) = begin
ℚ.∣ (xₘ ℚ.⊓ yₘ) ℚ.- (xₙ ℚ.⊓ yₙ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-cong
(ℚP.⊓-cong (ℚP.≃-sym (ℚP.neg-involutive xₘ)) (ℚP.≃-sym (ℚP.neg-involutive yₘ)))
(ℚP.-‿cong (ℚP.⊓-cong (ℚP.≃-sym (ℚP.neg-involutive xₙ)) (ℚP.≃-sym (ℚP.neg-involutive yₙ))))) ⟩
ℚ.∣ ((ℚ.- (ℚ.- xₘ)) ℚ.⊓ (ℚ.- (ℚ.- yₘ))) ℚ.-
((ℚ.- (ℚ.- xₙ)) ℚ.⊓ (ℚ.- (ℚ.- yₙ))) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-cong
(ℚP.≃-sym (ℚP.neg-distrib-⊔-⊓ (ℚ.- xₘ) (ℚ.- yₘ)))
(ℚP.-‿cong (ℚP.≃-sym (ℚP.neg-distrib-⊔-⊓ (ℚ.- xₙ) (ℚ.- yₙ))))) ⟩
ℚ.∣ ℚ.- ((ℚ.- xₘ) ℚ.⊔ (ℚ.- yₘ)) ℚ.-
(ℚ.- ((ℚ.- xₙ) ℚ.⊔ (ℚ.- yₙ))) ∣ ≤⟨ reg (x ⊓ y) m n ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
xₘ : ℚᵘ
xₘ = seq x m
xₙ : ℚᵘ
xₙ = seq x n
yₘ : ℚᵘ
yₘ = seq y m
yₙ : ℚᵘ
yₙ = seq y n
x⊓y≃x⊓₂y : ∀ x y -> x ⊓ y ≃ x ⊓₂ y
x⊓y≃x⊓₂y x y (suc k₁) = begin
ℚ.∣ (ℚ.- ((ℚ.- xₙ) ℚ.⊔ (ℚ.- yₙ))) ℚ.- (xₙ ℚ.⊓ yₙ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- (xₙ ℚ.⊓ yₙ))
(ℚP.neg-distrib-⊔-⊓ (ℚ.- xₙ) (ℚ.- yₙ))) ⟩
ℚ.∣ ((ℚ.- (ℚ.- xₙ)) ℚ.⊓ (ℚ.- (ℚ.- yₙ))) ℚ.- (xₙ ℚ.⊓ yₙ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- (xₙ ℚ.⊓ yₙ))
(ℚP.⊓-cong (ℚP.neg-involutive xₙ) (ℚP.neg-involutive yₙ))) ⟩
ℚ.∣ (xₙ ℚ.⊓ yₙ) ℚ.- (xₙ ℚ.⊓ yₙ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (xₙ ℚ.⊓ yₙ)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
xₙ : ℚᵘ
xₙ = seq x n
yₙ : ℚᵘ
yₙ = seq y n
{-
Proposition:
If x and y are nonnegative, then so is min{x, y}.
Proof:
Since x and y are nonnegative, for each n∈ℕ there is Nₙx, Nₙy∈ℕ such that
xₘ ≥ -n⁻¹ (m ≥ Nₙx), and
yₘ ≥ -n⁻¹ (m ≥ Nₙy).
Let Nₙ = max{Nₙx, Nₙy}, and let m ≥ Nₙ. Suppose, without loss of generality, that
xₘ ⊓ yₘ = xₘ. Then we have:
(x ⊓ y)ₘ = xₘ ⊓ yₘ
= xₘ
≥ -n⁻¹.
-}
nonNegx,y⇒nonNegx⊓y : ∀ x y -> NonNegative x -> NonNegative y -> NonNegative (x ⊓ y)
nonNegx,y⇒nonNegx⊓y x y nonx nony = nonNeg-cong (x ⊓₂ y) (x ⊓ y) (≃-symm {x ⊓ y} {x ⊓₂ y} (x⊓y≃x⊓₂y x y))
(lemma2-8-2b (x ⊓₂ y) lemA)
where
open ℚP.≤-Reasoning
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
(∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊓₂ y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})
lemA (suc k₁) = Nₙ , _ , lemB
where
n : ℕ
n = suc k₁
Nₙx : ℕ
Nₙx = proj₁ (lemma2-8-2a x nonx n)
Nₙy : ℕ
Nₙy = proj₁ (lemma2-8-2a y nony n)
Nₙ : ℕ
Nₙ = Nₙx ℕ.⊔ Nₙy
lemB : ∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊓₂ y) m ℚ.≥ ℚ.- (+ 1 / n)
lemB m m≥Nₙ = [ left , right ]′ (ℚP.≤-total (seq x m) (seq y m))
where
left : seq x m ℚ.≤ seq y m -> seq (x ⊓₂ y) m ℚ.≥ ℚ.- (+ 1 / n)
left hyp = begin
ℚ.- (+ 1 / n) ≤⟨ proj₂ (proj₂ (lemma2-8-2a x nonx n)) m
(ℕP.≤-trans (ℕP.m≤m⊔n Nₙx Nₙy) m≥Nₙ) ⟩
seq x m ≈⟨ ℚP.≃-sym (ℚP.p≤q⇒p⊓q≃p hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
right : seq y m ℚ.≤ seq x m -> seq (x ⊓₂ y) m ℚ.≥ ℚ.- (+ 1 / n)
right hyp = begin
ℚ.- (+ 1 / n) ≤⟨ proj₂ (proj₂ (lemma2-8-2a y nony n)) m
(ℕP.≤-trans (ℕP.m≤n⊔m Nₙx Nₙy) m≥Nₙ) ⟩
seq y m ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊓q≃q hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
{-
Proposition:
If x and y are positive, then so is min{x, y}.
Proof:
Since x and y are positive, there are Nx, Ny∈ℕ such that
xₘ ≥ Nx⁻¹ (m ≥ Nx), and
yₘ ≥ Ny⁻¹ (m ≥ Ny).
Let N = max{Nx, Ny}, and let m ≥ N. Suppose, without loss of generality, that
xₘ ⊓ yₘ = xₘ. We have:
(x ⊓ y)ₘ = xₘ ⊓ yₘ
= xₘ
≥ Nx⁻¹
≥ N⁻¹.
-}
posx,y⇒posx⊓y : ∀ x y -> Positive x -> Positive y -> Positive (x ⊓ y)
posx,y⇒posx⊓y x y posx posy = pos-cong (x ⊓₂ y) (x ⊓ y) (≃-symm {x ⊓ y} {x ⊓₂ y} (x⊓y≃x⊓₂y x y))
(lemma2-8-1b (x ⊓₂ y) (ℕ.pred N , lem))
where
open ℚP.≤-Reasoning
Nx : ℕ
Nx = suc (proj₁ (lemma2-8-1a x posx))
Ny : ℕ
Ny = suc (proj₁ (lemma2-8-1a y posy))
N : ℕ
N = Nx ℕ.⊔ Ny
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x ⊓₂ y) m ℚ.≥ + 1 / N
lem m m≥N = [ left , right ]′ (ℚP.≤-total (seq x m) (seq y m))
where
left : seq x m ℚ.≤ seq y m -> seq (x ⊓₂ y) m ℚ.≥ + 1 / N
left hyp = begin
+ 1 / N ≤⟨ *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m⊔n Nx Ny))) ⟩
+ 1 / Nx ≤⟨ proj₂ (lemma2-8-1a x posx) m (ℕP.≤-trans (ℕP.m≤m⊔n Nx Ny) m≥N) ⟩
seq x m ≈⟨ ℚP.≃-sym (ℚP.p≤q⇒p⊓q≃p hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
right : seq y m ℚ.≤ seq x m -> seq (x ⊓₂ y) m ℚ.≥ + 1 / N
right hyp = begin
+ 1 / N ≤⟨ *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n⊔m Nx Ny))) ⟩
+ 1 / Ny ≤⟨ proj₂ (lemma2-8-1a y posy) m (ℕP.≤-trans (ℕP.m≤n⊔m Nx Ny) m≥N) ⟩
seq y m ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊓q≃q hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
infix 4 _<_ _>_ _≤_ _≥_
_<_ : Rel ℝ 0ℓ
x < y = Positive (y - x)
_>_ : Rel ℝ 0ℓ
x > y = y < x
_≤_ : Rel ℝ 0ℓ
x ≤ y = NonNegative (y - x)
--data _≤_ : Rel ℝ 0ℓ where
-- ⋆≤⋆ : ∀ x y -> NonNegative (y - x) -> x ≤ y
_≥_ : Rel ℝ 0ℓ
x ≥ y = y ≤ x
Negative : Pred ℝ 0ℓ
Negative x = Positive (- x)
<⇒≤ : _<_ ⇒ _≤_
<⇒≤ {x} {y} x<y = pos⇒nonNeg (y - x) x<y
<-≤-trans : Trans _<_ _≤_ _<_
<-≤-trans {x} {y} {z} x<y y≤z = pos-cong (y - x + (z - y)) (z - x) lem (posx∧nonNegy⇒posx+y (y - x) (z - y) x<y y≤z)
where
open ≃-Reasoning
lem : (y - x) + (z - y) ≃ z - x
lem = begin
(y - x) + (z - y) ≈⟨ +-comm (y - x) (z - y) ⟩
(z - y) + (y - x) ≈⟨ +-assoc z (- y) (y - x) ⟩
z + ((- y) + (y - x)) ≈⟨ +-congʳ z {(- y) + (y - x)} {(- y + y) - x} (≃-symm {(- y + y) - x} {(- y) + (y - x)} (+-assoc (- y) y (- x))) ⟩
z + ((- y + y) - x) ≈⟨ +-congʳ z {(- y + y) - x} {0ℝ - x} (+-congˡ (- x) {(- y + y)} {0ℝ} (+-inverseˡ y)) ⟩
z + (0ℝ - x) ≈⟨ +-congʳ z {0ℝ - x} {(- x)} (+-identityˡ (- x)) ⟩
z - x ∎
≤-<-trans : Trans _≤_ _<_ _<_
≤-<-trans {x} {y} {z} x≤y y<z = pos-cong ((z - y) + (y - x)) (z - x) lem (posx∧nonNegy⇒posx+y (z - y) (y - x) y<z x≤y)
where
open ≃-Reasoning
lem : (z - y) + (y - x) ≃ z - x
lem = begin
(z - y) + (y - x) ≈⟨ +-assoc z (- y) (y - x) ⟩
z + (- y + (y - x)) ≈⟨ +-congʳ z {(- y) + (y - x)} {(- y + y) - x} (≃-symm {(- y + y) - x} {(- y) + (y - x)} (+-assoc (- y) y (- x))) ⟩
z + ((- y + y) - x) ≈⟨ +-congʳ z {(- y + y) - x} {0ℝ - x} (+-congˡ (- x) {(- y + y)} {0ℝ} (+-inverseˡ y)) ⟩
z + (0ℝ - x) ≈⟨ +-congʳ z {0ℝ - x} {(- x)} (+-identityˡ (- x)) ⟩
z - x ∎
<-trans : Transitive _<_
<-trans {x} {y} {z} = ≤-<-trans {x} {y} {z} ∘ <⇒≤ {x} {y}
≤-trans : Transitive _≤_
≤-trans {x} {y} {z} x≤y y≤z = nonNeg-cong (z - y + (y - x)) (z - x) lem (nonNegx,y⇒nonNegx+y (z - y) (y - x) y≤z x≤y)
where
open ≃-Reasoning
lem : (z - y) + (y - x) ≃ z - x
lem = begin
(z - y) + (y - x) ≈⟨ +-assoc z (- y) (y - x) ⟩
z + (- y + (y - x)) ≈⟨ +-congʳ z {(- y) + (y - x)} {(- y + y) - x} (≃-symm {(- y + y) - x} {(- y) + (y - x)} (+-assoc (- y) y (- x))) ⟩
z + ((- y + y) - x) ≈⟨ +-congʳ z {(- y + y) - x} {0ℝ - x} (+-congˡ (- x) {(- y + y)} {0ℝ} (+-inverseˡ y)) ⟩
z + (0ℝ - x) ≈⟨ +-congʳ z {0ℝ - x} {(- x)} (+-identityˡ (- x)) ⟩
z - x ∎
nonNeg0 : NonNegative 0ℝ
nonNeg0 (suc k₁) = ℚP.<⇒≤ (ℚP.negative⁻¹ _)
nonNeg-refl : ∀ x -> NonNegative (x - x)
nonNeg-refl x = nonNeg-cong 0ℝ (x - x) (≃-symm {x - x} {0ℝ} (+-inverseʳ x)) nonNeg0
+-mono-≤ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
+-mono-≤ {x} {z} {y} {t} x≤z y≤t = nonNeg-cong ((z - x) + (t - y)) ((z + t) - (x + y)) lem (nonNegx,y⇒nonNegx+y (z - x) (t - y) x≤z y≤t)
where
open ≃-Reasoning
lem : (z - x) + (t - y) ≃ (z + t) - (x + y)
lem = begin
(z - x) + (t - y) ≈⟨ +-congʳ (z - x) {t - y} { - y + t} (+-comm t (- y)) ⟩
(z - x) + (- y + t) ≈⟨ +-assoc z (- x) (- y + t) ⟩
z + (- x + (- y + t)) ≈⟨ ≃-symm {z + ((- x + - y) + t)} {z + (- x + (- y + t))}
(+-congʳ z { - x + - y + t} { - x + (- y + t)} (+-assoc (- x) (- y) t)) ⟩
z + ((- x + - y) + t) ≈⟨ +-congʳ z { - x + - y + t} {t + (- x + - y)} (+-comm (- x + - y) t) ⟩
z + (t + (- x + - y)) ≈⟨ ≃-symm {(z + t) + (- x + - y)} {z + (t + (- x + - y))} (+-assoc z t (- x + - y)) ⟩
(z + t) + (- x + - y) ≈⟨ +-congʳ (z + t) { - x + - y} { - (x + y)} (≃-symm { - (x + y)} { - x + - y} (neg-distrib-+ x y)) ⟩
(z + t) - (x + y) ∎
+-monoʳ-≤ : ∀ (x : ℝ) -> (_+_ x) Preserves _≤_ ⟶ _≤_
+-monoʳ-≤ x {y} {z} y≤z = +-mono-≤ {x} {x} {y} {z} (nonNeg-refl x) y≤z
+-monoˡ-≤ : ∀ (x : ℝ) -> (_+ x) Preserves _≤_ ⟶ _≤_
+-monoˡ-≤ x {y} {z} y≤z = +-mono-≤ {y} {z} {x} {x} y≤z (nonNeg-refl x)
+-mono-< : _+_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
+-mono-< {x} {z} {y} {t} x<z y<t = pos-cong ((z - x) + (t - y)) ((z + t) - (x + y)) lem (posx,y⇒posx+y (z - x) (t - y) x<z y<t)
where
open ≃-Reasoning
lem : (z - x) + (t - y) ≃ (z + t) - (x + y)
lem = begin
(z - x) + (t - y) ≈⟨ +-congʳ (z - x) {t - y} { - y + t} (+-comm t (- y)) ⟩
(z - x) + (- y + t) ≈⟨ +-assoc z (- x) (- y + t) ⟩
z + (- x + (- y + t)) ≈⟨ ≃-symm {z + ((- x + - y) + t)} {z + (- x + (- y + t))}
(+-congʳ z { - x + - y + t} { - x + (- y + t)} (+-assoc (- x) (- y) t)) ⟩
z + ((- x + - y) + t) ≈⟨ +-congʳ z { - x + - y + t} {t + (- x + - y)} (+-comm (- x + - y) t) ⟩
z + (t + (- x + - y)) ≈⟨ ≃-symm {(z + t) + (- x + - y)} {z + (t + (- x + - y))} (+-assoc z t (- x + - y)) ⟩
(z + t) + (- x + - y) ≈⟨ +-congʳ (z + t) { - x + - y} { - (x + y)} (≃-symm { - (x + y)} { - x + - y} (neg-distrib-+ x y)) ⟩
(z + t) - (x + y) ∎
neg-distribˡ-* : ∀ x y -> - (x * y) ≃ - x * y
neg-distribˡ-* x y = begin
- (x * y) ≈⟨ ≃-trans { - (x * y)} { - (x * y) + 0ℝ} { - (x * y) + 0ℝ * y}
(≃-symm { - (x * y) + 0ℝ} { - (x * y)} (+-identityʳ (- (x * y))))
(+-congʳ (- (x * y)) {0ℝ} {0ℝ * y} (≃-symm {0ℝ * y} {0ℝ} (*-zeroˡ y))) ⟩
- (x * y) + 0ℝ * y ≈⟨ +-congʳ (- (x * y)) {0ℝ * y} {(x - x) * y} (*-congʳ {y} {0ℝ} {x - x} (≃-symm {x - x} {0ℝ} (+-inverseʳ x))) ⟩
- (x * y) + (x - x) * y ≈⟨ +-congʳ (- (x * y)) {(x - x) * y} {x * y + (- x) * y} (*-distribʳ-+ y x (- x)) ⟩
- (x * y) + (x * y + (- x) * y) ≈⟨ ≃-symm { - (x * y) + x * y + - x * y} { - (x * y) + (x * y + - x * y)}
(+-assoc (- (x * y)) (x * y) ((- x) * y)) ⟩
- (x * y) + x * y + (- x) * y ≈⟨ +-congˡ (- x * y) { - (x * y) + x * y} {0ℝ} (+-inverseˡ (x * y)) ⟩
0ℝ + (- x) * y ≈⟨ +-identityˡ ((- x) * y) ⟩
(- x) * y ∎
where
open ≃-Reasoning
neg-distribʳ-* : ∀ x y -> - (x * y) ≃ x * (- y)
neg-distribʳ-* x y = begin
- (x * y) ≈⟨ -‿cong {x * y} {y * x} (*-comm x y) ⟩
- (y * x) ≈⟨ neg-distribˡ-* y x ⟩
- y * x ≈⟨ *-comm (- y) x ⟩
x * (- y) ∎
where
open ≃-Reasoning
≤-reflexive : _≃_ ⇒ _≤_
≤-reflexive {x} {y} x≃y = nonNeg-cong (x - x) (y - x) (+-congˡ (- x) {x} {y} x≃y) (nonNeg-refl x)
≤-refl : Reflexive _≤_
≤-refl {x} = ≤-reflexive {x} {x} (≃-refl {x})
≤-isPreorder : IsPreorder _≃_ _≤_
IsPreorder.isEquivalence ≤-isPreorder = ≃-isEquivalence
IsPreorder.reflexive ≤-isPreorder {x} {y} x≃y = ≤-reflexive {x} {y} x≃y
IsPreorder.trans ≤-isPreorder {x} {y} {z} = ≤-trans {x} {y} {z}
<-respʳ-≃ : _<_ Respectsʳ _≃_
<-respʳ-≃ {x} {y} {z} y≃z x<y = <-≤-trans {x} {y} {z} x<y (≤-reflexive {y} {z} y≃z)
<-respˡ-≃ : _<_ Respectsˡ _≃_
<-respˡ-≃ {x} {y} {z} y≃z y<x = ≤-<-trans {z} {y} {x} (≤-reflexive {z} {y} (≃-symm {y} {z} y≃z)) y<x
<-resp-≃ : _<_ Respects₂ _≃_
<-resp-≃ = (λ {x} {y} {z} -> <-respʳ-≃ {x} {y} {z}) , λ {x} {y} {z} -> <-respˡ-≃ {x} {y} {z}
{-
Same issue as with ≃-refl. I need to specify the arguments in order to avoid the constraint error,
hence the lambdas.
-}
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
≤-isPreorder
(λ {x} {y} {z} -> <-trans {x} {y} {z})
<-resp-≃
(λ {x} {y} -> <⇒≤ {x} {y})
(λ {x} {y} {z} -> <-≤-trans {x} {y} {z})
(λ {x} {y} {z} -> ≤-<-trans {x} {y} {z})
public
*-monoʳ-≤-nonNeg : ∀ x y z -> x ≤ z -> NonNegative y -> x * y ≤ z * y
*-monoʳ-≤-nonNeg x y z x≤z nony = nonNeg-cong ((z - x) * y) (z * y - x * y) lem (nonNegx,y⇒nonNegx*y (z - x) y x≤z nony)
where
open ≃-Reasoning
lem : (z - x) * y ≃ z * y - x * y
lem = begin
(z - x) * y ≈⟨ *-distribʳ-+ y z (- x) ⟩
z * y + (- x) * y ≈⟨ +-congʳ (z * y) { - x * y} { - (x * y)} (≃-symm { - (x * y)} { - x * y} (neg-distribˡ-* x y)) ⟩
z * y - x * y ∎
*-monoˡ-≤-nonNeg : ∀ x y z -> x ≤ z -> NonNegative y -> y * x ≤ y * z
*-monoˡ-≤-nonNeg x y z x≤z nony = begin
y * x ≈⟨ *-comm y x ⟩
x * y ≤⟨ *-monoʳ-≤-nonNeg x y z x≤z nony ⟩
z * y ≈⟨ *-comm z y ⟩
y * z ∎
where
open ≤-Reasoning
*-monoʳ-<-pos : ∀ {y} -> Positive y -> (_*_ y) Preserves _<_ ⟶ _<_
*-monoʳ-<-pos {y} posy {x} {z} x<z = pos-cong (y * (z - x)) (y * z - y * x) lem (posx,y⇒posx*y y (z - x) posy x<z)
where
open ≃-Reasoning
lem : y * (z - x) ≃ y * z - y * x
lem = begin
y * (z - x) ≈⟨ *-distribˡ-+ y z (- x) ⟩
y * z + y * (- x) ≈⟨ +-congʳ (y * z) {y * (- x)} { - (y * x)} (≃-symm { - (y * x)} {y * (- x)} (neg-distribʳ-* y x)) ⟩
y * z - y * x ∎
*-monoˡ-<-pos : ∀ {y} -> Positive y -> (_* y) Preserves _<_ ⟶ _<_
*-monoˡ-<-pos {y} posy {x} {z} x<z = begin-strict
x * y ≈⟨ *-comm x y ⟩
y * x <⟨ *-monoʳ-<-pos {y} posy {x} {z} x<z ⟩
y * z ≈⟨ *-comm y z ⟩
z * y ∎
where
open ≤-Reasoning
neg-mono-< : -_ Preserves _<_ ⟶ _>_
neg-mono-< {x} {y} x<y = pos-cong (y - x) (- x - (- y)) lem x<y
where
open ≃-Reasoning
lem : y - x ≃ - x - (- y)
lem = begin
y - x ≈⟨ +-congˡ (- x) {y} { - (- y)} (≃-symm { - (- y)} {y} (neg-involutive y)) ⟩
- (- y) - x ≈⟨ +-comm (- (- y)) (- x) ⟩
- x - (- y) ∎
neg-mono-≤ : -_ Preserves _≤_ ⟶ _≥_
neg-mono-≤ {x} {y} x≤y = nonNeg-cong (y - x) (- x - (- y)) lem x≤y
where
open ≃-Reasoning
lem : y - x ≃ - x - (- y)
lem = begin
y - x ≈⟨ +-congˡ (- x) {y} { - (- y)} (≃-symm { - (- y)} {y} (neg-involutive y)) ⟩
- (- y) - x ≈⟨ +-comm (- (- y)) (- x) ⟩
- x - (- y) ∎
x≤x⊔y : ∀ x y -> x ≤ x ⊔ y
x≤x⊔y x y (suc k₁) = begin
ℚ.- (+ 1 / n) ≤⟨ ℚP.nonPositive⁻¹ _ ⟩
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ (seq x (2 ℕ.* n))) ⟩
seq x (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- seq x (2 ℕ.* n)) (ℚP.p≤p⊔q (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
seq x (2 ℕ.* n) ℚ.⊔ seq y (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
x≤y⊔x : ∀ x y -> x ≤ y ⊔ x
x≤y⊔x x y = begin
x ≤⟨ x≤x⊔y x y ⟩
x ⊔ y ≈⟨ ⊔-comm x y ⟩
y ⊔ x ∎
where
open ≤-Reasoning
x⊓y≤x : ∀ x y -> x ⊓ y ≤ x
x⊓y≤x x y = nonNeg-cong (x - (x ⊓₂ y)) (x - (x ⊓ y)) lemA lemB
where
open ℚP.≤-Reasoning
lemA : x - (x ⊓₂ y) ≃ x - (x ⊓ y)
lemA = +-congʳ x { - (x ⊓₂ y)} { - (x ⊓ y)} (-‿cong {x ⊓₂ y} {x ⊓ y}
(≃-symm {x ⊓ y} {x ⊓₂ y} (x⊓y≃x⊓₂y x y)))
lemB : x ⊓₂ y ≤ x
lemB (suc k₁) = begin
ℚ.- (+ 1 / n) ≤⟨ ℚP.nonPositive⁻¹ _ ⟩
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ (seq x (2 ℕ.* n))) ⟩
seq x (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ≤⟨ ℚP.+-monoʳ-≤ (seq x (2 ℕ.* n)) (ℚP.neg-mono-≤ (ℚP.p⊓q≤p (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)))) ⟩
seq x (2 ℕ.* n) ℚ.- seq (x ⊓₂ y) (2 ℕ.* n) ∎
where
n : ℕ
n = suc k₁
x⊓y≤y : ∀ x y -> x ⊓ y ≤ y
x⊓y≤y x y = begin
x ⊓ y ≈⟨ ⊓-comm x y ⟩
y ⊓ x ≤⟨ x⊓y≤x y x ⟩
y ∎
where
open ≤-Reasoning
{-
Proposition:
≤ is antisymmetric.
Proof:
Since y - x and x - y are nonnegative, for all n∈ℕ, we have
y₂ₙ - x₂ₙ ≥ -n⁻¹ (1), and
x₂ₙ - y₂ₙ ≥ -n⁻¹ (2)
Let n∈ℕ. Either ∣x₂ₙ - y₂ₙ∣ = x₂ₙ - y₂ₙ or ∣x₂ₙ - y₂ₙ∣ = y₂ₙ - x₂ₙ.
Case 1: We have:
∣x₂ₙ - y₂ₙ∣ = x₂ₙ - y₂ₙ
≤ n⁻¹ by (1)
≤ 2n⁻¹.
Case 2: Similar.
Thus x - y ≃ 0. Hence x ≃ y. □
-}
≤-antisym : Antisymmetric _≃_ _≤_
≤-antisym {x} {y} x≤y y≤x = ≃-symm {y} {x} lemB
where
lemA : x - y ≃ 0ℝ
lemA (suc k₁) = begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ℚ.- 0ℚᵘ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-identityʳ (seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n))) ⟩
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ≤⟨ [ left , right ]′ (ℚP.≤-total (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k₁
left : seq x (2 ℕ.* n) ℚ.≤ seq y (2 ℕ.* n) -> ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ℚ.≤ + 2 / n
left hyp = begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n))))
(ℚP.0≤p⇒∣p∣≃p (ℚP.neg-mono-≤ (ℚP.p≤q⇒p-q≤0 hyp))) ⟩
ℚ.- (seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n)) ≤⟨ ℚP.≤-respʳ-≃ (ℚP.neg-involutive (+ 1 / n)) (ℚP.neg-mono-≤ (y≤x n)) ⟩
+ 1 / n ≤⟨ *≤* (ℤP.*-monoʳ-≤-nonNeg n {+ 1} {+ 2} (+≤+ (ℕ.s≤s ℕ.z≤n))) ⟩
+ 2 / n ∎
right : seq y (2 ℕ.* n) ℚ.≤ seq x (2 ℕ.* n) -> ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ℚ.≤ + 2 / n
right hyp = begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp) ⟩
seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ≈⟨ solve 2 (λ x y -> x :- y := :- (y :- x)) ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)) ⟩
ℚ.- (seq y (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n)) ≤⟨ ℚP.≤-respʳ-≃ (ℚP.neg-involutive (+ 1 / n)) (ℚP.neg-mono-≤ (x≤y n)) ⟩
+ 1 / n ≤⟨ *≤* (ℤP.*-monoʳ-≤-nonNeg n {+ 1} {+ 2} (+≤+ (ℕ.s≤s ℕ.z≤n))) ⟩
+ 2 / n ∎
lemB : y ≃ x
lemB = begin
y ≈⟨ ≃-symm {y + 0ℝ} {y} (+-identityʳ y) ⟩
y + 0ℝ ≈⟨ +-congʳ y {0ℝ} {x - y} (≃-symm {x - y} {0ℝ} lemA) ⟩
y + (x - y) ≈⟨ +-congʳ y {x - y} { - y + x} (+-comm x (- y)) ⟩
y + (- y + x) ≈⟨ ≃-symm {y - y + x} {y + (- y + x)} (+-assoc y (- y) x) ⟩
y - y + x ≈⟨ +-congˡ x {y - y} {0ℝ} (+-inverseʳ y) ⟩
0ℝ + x ≈⟨ +-identityˡ x ⟩
x ∎
where
open ≃-Reasoning
0≤∣x∣ : ∀ x -> 0ℝ ≤ ∣ x ∣
0≤∣x∣ x = nonNeg-cong ∣ x ∣ (∣ x ∣ - 0ℝ) (≃-symm {∣ x ∣ - 0ℝ} {∣ x ∣} (+-identityʳ ∣ x ∣)) (∣x∣nonNeg x)
∣x+y∣₂≤∣x∣₂+∣y∣₂ : ∀ x y -> ∣ x + y ∣₂ ≤ ∣ x ∣₂ + ∣ y ∣₂
∣x+y∣₂≤∣x∣₂+∣y∣₂ x y (suc k₁) = begin
ℚ.- (+ 1 / n) ≤⟨ ℚP.nonPositive⁻¹ _ ⟩
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ (∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣)) ⟩
∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣ ℚ.- (∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣) ≤⟨ ℚP.+-monoʳ-≤ (∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣)
(ℚP.neg-mono-≤ (ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x (2 ℕ.* (2 ℕ.* n))) (seq y (2 ℕ.* (2 ℕ.* n))))) ⟩
∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣ ℚ.- ∣x₄ₙ+y₄ₙ∣ ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
∣x₄ₙ∣ : ℚᵘ
∣x₄ₙ∣ = ℚ.∣ seq x (2 ℕ.* (2 ℕ.* n)) ∣
∣y₄ₙ∣ : ℚᵘ
∣y₄ₙ∣ = ℚ.∣ seq y (2 ℕ.* (2 ℕ.* n)) ∣
∣x₄ₙ+y₄ₙ∣ : ℚᵘ
∣x₄ₙ+y₄ₙ∣ = ℚ.∣ seq x (2 ℕ.* (2 ℕ.* n)) ℚ.+ seq y (2 ℕ.* (2 ℕ.* n)) ∣
∣x+y∣≤∣x∣+∣y∣ : ∀ x y -> ∣ x + y ∣ ≤ ∣ x ∣ + ∣ y ∣
∣x+y∣≤∣x∣+∣y∣ x y = begin
∣ x + y ∣ ≈⟨ ∣x∣≃∣x∣₂ (x + y) ⟩
∣ x + y ∣₂ ≤⟨ ∣x+y∣₂≤∣x∣₂+∣y∣₂ x y ⟩
∣ x ∣₂ + ∣ y ∣₂ ≈⟨ +-cong {∣ x ∣₂} {∣ x ∣} {∣ y ∣₂} {∣ y ∣}
(≃-symm {∣ x ∣} {∣ x ∣₂} (∣x∣≃∣x∣₂ x))
(≃-symm {∣ y ∣} {∣ y ∣₂} (∣x∣≃∣x∣₂ y)) ⟩
∣ x ∣ + ∣ y ∣ ∎
where
open ≤-Reasoning
_≄_ : Rel ℝ 0ℓ
x ≄ y = x < y ⊎ y < x
x≤∣x∣ : ∀ x -> x ≤ ∣ x ∣
x≤∣x∣ x (suc k₁) = begin
ℚ.- (+ 1 / n) ≤⟨ ℚP.nonPositive⁻¹ _ ⟩
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ (seq x (2 ℕ.* n))) ⟩
seq x (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- seq x (2 ℕ.* n)) (ℚP.p≤p⊔q (seq x (2 ℕ.* n)) (ℚ.- seq x (2 ℕ.* n))) ⟩
seq ∣ x ∣ (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
∣-x∣₂≃∣x∣₂ : ∀ x -> ∣ - x ∣₂ ≃ ∣ x ∣₂
∣-x∣₂≃∣x∣₂ x (suc k₁) = begin
ℚ.∣ ℚ.∣ ℚ.- seq x n ∣ ℚ.- ℚ.∣ seq x n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- ℚ.∣ seq x n ∣) (ℚP.∣-p∣≃∣p∣ (seq x n))) ⟩
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- ℚ.∣ seq x n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ ℚ.∣ seq x n ∣) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
test : seq ∣ - x ∣₂ n ℚ.≃ ℚ.∣ ℚ.- seq x n ∣
test = ℚP.≃-refl
∣-x∣≃∣x∣ : ∀ x -> ∣ - x ∣ ≃ ∣ x ∣
∣-x∣≃∣x∣ x = begin
∣ - x ∣ ≈⟨ ∣x∣≃∣x∣₂ (- x) ⟩
∣ - x ∣₂ ≈⟨ ∣-x∣₂≃∣x∣₂ x ⟩
∣ x ∣₂ ≈⟨ ≃-symm {∣ x ∣} {∣ x ∣₂} (∣x∣≃∣x∣₂ x) ⟩
∣ x ∣ ∎
where
open ≃-Reasoning
0<x⇒posx : ∀ x -> 0ℝ < x -> Positive x
0<x⇒posx x 0<x = pos-cong (x - 0ℝ) x (+-identityʳ x) 0<x
posx⇒0<x : ∀ x -> Positive x -> 0ℝ < x
posx⇒0<x x posx = pos-cong x (x - 0ℝ) (≃-symm {x - 0ℝ} {x} (+-identityʳ x)) posx
x≄0⇒0<∣x∣ : ∀ x -> x ≄ 0ℝ -> 0ℝ < ∣ x ∣
x≄0⇒0<∣x∣ x x≄0 = [ left , right ]′ x≄0
where
open ≤-Reasoning
left : x < 0ℝ -> 0ℝ < ∣ x ∣
left hyp = begin-strict
0ℝ <⟨ neg-mono-< {x} {0ℝ} hyp ⟩
- x ≤⟨ x≤∣x∣ (- x) ⟩
∣ - x ∣ ≈⟨ ∣-x∣≃∣x∣ x ⟩
∣ x ∣ ∎
right : 0ℝ < x -> 0ℝ < ∣ x ∣
right hyp = begin-strict
0ℝ <⟨ hyp ⟩
x ≤⟨ x≤∣x∣ x ⟩
∣ x ∣ ∎
x≄0⇒pos∣x∣ : ∀ x -> x ≄ 0ℝ -> Positive ∣ x ∣
x≄0⇒pos∣x∣ x x≄0 = 0<x⇒posx ∣ x ∣ (x≄0⇒0<∣x∣ x x≄0)
x≄0⇒pos∣x∣₂ : ∀ x -> x ≄ 0ℝ -> Positive ∣ x ∣₂
x≄0⇒pos∣x∣₂ x x≄0 = pos-cong ∣ x ∣ ∣ x ∣₂ (∣x∣≃∣x∣₂ x) (x≄0⇒pos∣x∣ x x≄0)
{-
Using abstract versions of previous results for better performance.
For instance, using lemma2-8-1a directly can be very slow.
-}
abstract
fastℕ<?ℕ : Decidable ℕ._<_
fastℕ<?ℕ = ℕP._<?_
fast2-8-1a : ∀ x -> Positive x -> ∃ λ (N : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N ->
seq x m ℚ.≥ + 1 / (suc N)
fast2-8-1a = lemma2-8-1a
ℚ≠-helper : ∀ p -> p ℚ.> 0ℚᵘ ⊎ p ℚ.< 0ℚᵘ -> p ℚ.≠ 0ℚᵘ
ℚ≠-helper p hyp1 hyp2 = [ left , right ]′ hyp1
where
left : ¬ (p ℚ.> 0ℚᵘ)
left hyp = ℚP.<-irrefl (ℚP.≃-sym hyp2) hyp
right : ¬ (p ℚ.< 0ℚᵘ)
right hyp = ℚP.<-irrefl hyp2 hyp
{-
For the sake of performance, we define an alternative version of the inverse given
by Bishop.
-}
Nₐ : (x : ℝ) -> {x≄0 : x ≄ 0ℝ} -> ℕ
Nₐ x {x≄0} = suc (proj₁ (fast2-8-1a ∣ x ∣₂ (x≄0⇒pos∣x∣₂ x x≄0)))
not0-helper : ∀ (x : ℝ) -> {x≄0 : x ≄ 0ℝ} -> ∀ (n : ℕ) ->
ℤ.∣ ↥ (seq x ((n ℕ.+ (Nₐ x {x≄0})) ℕ.* ((Nₐ x {x≄0}) ℕ.* (Nₐ x {x≄0})))) ∣ ≢0
not0-helper x {x≄0} n = ℚP.p≄0⇒∣↥p∣≢0 xₛ (ℚ≠-helper xₛ ([ left , right ]′ (ℚP.∣p∣≡p∨∣p∣≡-p xₛ)))
where
open ℚP.≤-Reasoning
N : ℕ
N = Nₐ x {x≄0}
xₛ : ℚᵘ
xₛ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
0<∣xₛ∣ : 0ℚᵘ ℚ.< ℚ.∣ xₛ ∣
0<∣xₛ∣ = begin-strict
0ℚᵘ <⟨ ℚP.positive⁻¹ _ ⟩
+ 1 / N ≤⟨ proj₂ (fast2-8-1a ∣ x ∣₂ (x≄0⇒pos∣x∣₂ x x≄0)) ((n ℕ.+ N) ℕ.* (N ℕ.* N))
(ℕP.≤-trans (ℕP.m≤n*m N {N} ℕP.0<1+n) (ℕP.m≤n*m (N ℕ.* N) {n ℕ.+ N} (subst (0 ℕ.<_) (ℕP.+-comm N n) ℕP.0<1+n))) ⟩
ℚ.∣ xₛ ∣ ∎
left : ℚ.∣ xₛ ∣ ≡ xₛ -> xₛ ℚ.> 0ℚᵘ ⊎ xₛ ℚ.< 0ℚᵘ
left hyp = inj₁ (begin-strict
0ℚᵘ <⟨ 0<∣xₛ∣ ⟩
ℚ.∣ xₛ ∣ ≡⟨ hyp ⟩
xₛ ∎)
right : ℚ.∣ xₛ ∣ ≡ ℚ.- xₛ -> xₛ ℚ.> 0ℚᵘ ⊎ xₛ ℚ.< 0ℚᵘ
right hyp = inj₂ (begin-strict
xₛ ≈⟨ ℚP.≃-sym (ℚP.neg-involutive xₛ) ⟩
ℚ.- (ℚ.- xₛ) ≡⟨ cong ℚ.-_ (sym hyp) ⟩
ℚ.- ℚ.∣ xₛ ∣ <⟨ ℚP.neg-mono-< 0<∣xₛ∣ ⟩
0ℚᵘ ∎)
{-
Strangely enough, this function is EXTREMELY slow. It pretty much does not compute. But proving an instance of it in
the definition of multiplicative inverse is very fast. Not sure why.
-}
-- ∣xₘ∣ ≥ N⁻¹
{-
abstract
inverse-helper : ∀ (x : ℝ) -> {x≄0 : x ≄ 0ℝ} -> ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
ℚ.∣ (ℚ.1/ seq x ((n ℕ.+ (Nₐ x {x≄0})) ℕ.* ((Nₐ x {x≄0}) ℕ.* (Nₐ x {x≄0})))) {not0-helper x {x≄0} n} ∣ ℚ.≤ + (Nₐ x {x≄0}) / 1
inverse-helper x {x≄0} (suc k₁) = begin
ℚ.∣ xₛ⁻¹ ∣ ≈⟨ {!N!} {-{!ℚP.≃-trans (ℚP.≃-sym (ℚP.*-identityʳ ℚ.∣ xₛ⁻¹ ∣))
(ℚP.*-congˡ {ℚ.∣ xₛ⁻¹ ∣} (ℚP.≃-sym (ℚP.*-inverseʳ (+ 1 / N))))!}-} ⟩
ℚ.∣ xₛ⁻¹ ∣ ℚ.* ((+ 1 / N) ℚ.* (+ N / 1)) ≤⟨ {!!} ⟩
+ N / 1 ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
N : ℕ
N = Nₐ x {x≄0}
xₛ : ℚᵘ
xₛ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
xₛ≢0 : ℤ.∣ ↥ xₛ ∣ ≢0
xₛ≢0 = not0-helper x {x≄0} n
xₛ⁻¹ : ℚᵘ
xₛ⁻¹ = (ℚ.1/ seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))) {xₛ≢0}
helper : ℚ.∣ xₛ⁻¹ ∣ ℚ.* ℚ.∣ xₛ ∣ ℚ.≃ ℚ.1ℚᵘ
helper = begin-equality
ℚ.∣ xₛ⁻¹ ∣ ℚ.* ℚ.∣ xₛ ∣ ≈⟨ ℚP.≃-sym (ℚP.∣p*q∣≃∣p∣*∣q∣ xₛ⁻¹ xₛ) ⟩
ℚ.∣ xₛ⁻¹ ℚ.* xₛ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.*-inverseˡ xₛ {xₛ≢0}) ⟩
ℚ.1ℚᵘ ∎-}
{-
∣x∣ > 0
∣xₘ∣ ≥ N⁻¹ (m ≥ N)
x ≄ 0
x⁻¹ = (x (N³))⁻¹ if n < N
(x (n * N²))⁻¹ else
x⁻¹ = (x ((n + N) * N²))⁻¹
x⁻¹ n with n <? N
-}
_⁻¹ : (x : ℝ) -> {x≄0 : x ≄ 0ℝ} -> ℝ
seq ((x ⁻¹) {x≄0}) n = (ℚ.1/ xₛ) {not0-helper x {x≄0} n}
where
open ℚP.≤-Reasoning
N : ℕ
N = Nₐ x {x≄0}
xₛ : ℚᵘ
xₛ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
reg ((x ⁻¹) {x≄0}) (suc k₁) (suc k₂) = begin
ℚ.∣ yₘ ℚ.- yₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-cong
(ℚP.≃-trans (ℚP.≃-sym (ℚP.*-identityʳ yₘ)) (ℚP.*-congˡ {yₘ} (ℚP.≃-sym (ℚP.*-inverseˡ xₙ {xₖ≢0 n}))))
(ℚP.-‿cong (ℚP.≃-trans (ℚP.≃-sym (ℚP.*-identityʳ yₙ)) (ℚP.*-congˡ {yₙ} (ℚP.≃-sym (ℚP.*-inverseˡ xₘ {xₖ≢0 m})))))) ⟩
ℚ.∣ yₘ ℚ.* (yₙ ℚ.* xₙ) ℚ.- yₙ ℚ.* (yₘ ℚ.* xₘ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ xₘ xₙ yₘ yₙ ->
yₘ ℚ:* (yₙ ℚ:* xₙ) ℚ:- yₙ ℚ:* (yₘ ℚ:* xₘ) ℚ:= yₘ ℚ:* yₙ ℚ:* (xₙ ℚ:- xₘ))
ℚP.≃-refl xₘ xₙ yₘ yₙ) ⟩
ℚ.∣ yₘ ℚ.* yₙ ℚ.* (xₙ ℚ.- xₘ) ∣ ≈⟨ ℚP.∣p*q∣≃∣p∣*∣q∣ (yₘ ℚ.* yₙ) (xₙ ℚ.- xₘ) ⟩
ℚ.∣ yₘ ℚ.* yₙ ∣ ℚ.* ℚ.∣ xₙ ℚ.- xₘ ∣ ≤⟨ ℚP.≤-trans
(ℚP.*-monoʳ-≤-nonNeg {ℚ.∣ yₘ ℚ.* yₙ ∣} _ (reg x ((n ℕ.+ N) ℕ.* (N ℕ.* N)) ((m ℕ.+ N) ℕ.* (N ℕ.* N))))
(ℚP.*-monoˡ-≤-nonNeg {+ 1 / ((n ℕ.+ N) ℕ.* (N ℕ.* N)) ℚ.+ + 1 / ((m ℕ.+ N) ℕ.* (N ℕ.* N))} _ ∣yₘ*yₙ∣≤N²) ⟩
(+ N / 1) ℚ.* (+ N / 1) ℚ.*
((+ 1 / ((n ℕ.+ N) ℕ.* (N ℕ.* N))) ℚ.+
(+ 1 / ((m ℕ.+ N) ℕ.* (N ℕ.* N)))) ≈⟨ ℚ.*≡* (solve 3 (λ m n N ->
-- Function and details for solver
((N :* N) :* ((con (+ 1) :* ((m :+ N) :* (N :* N))) :+ (con (+ 1) :* ((n :+ N) :* (N :* N))))) :* ((m :+ N) :* (n :+ N)) :=
(con (+ 1) :* (n :+ N) :+ con (+ 1) :* (m :+ N)) :* (con (+ 1) :* con (+ 1) :* (((n :+ N) :* (N :* N)) :* ((m :+ N) :* (N :* N)))))
_≡_.refl (+ m) (+ n) (+ N)) ⟩
(+ 1 / (m ℕ.+ N)) ℚ.+ (+ 1 / (n ℕ.+ N)) ≤⟨ ℚP.+-mono-≤ {+ 1 / (m ℕ.+ N)} {+ 1 / m} {+ 1 / (n ℕ.+ N)} {+ 1 / n}
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m+n m N))))
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m+n n N)))) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
N : ℕ
N = Nₐ x {x≄0}
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
xₘ : ℚᵘ
xₘ = seq x ((m ℕ.+ N) ℕ.* (N ℕ.* N))
xₙ : ℚᵘ
xₙ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
xₖ≢0 : ∀ (k : ℕ) -> ℤ.∣ ↥ seq x ((k ℕ.+ N) ℕ.* (N ℕ.* N)) ∣ ≢0
xₖ≢0 k = not0-helper x {x≄0} k
yₘ : ℚᵘ
yₘ = (ℚ.1/ xₘ) {xₖ≢0 m}
yₙ : ℚᵘ
yₙ = (ℚ.1/ xₙ) {xₖ≢0 n}
∣yₖ∣≤N : ∀ (k : ℕ) -> ℚ.∣ (ℚ.1/ (seq x ((k ℕ.+ N) ℕ.* (N ℕ.* N)))) {not0-helper x {x≄0} k} ∣ ℚ.≤ + N / 1
∣yₖ∣≤N k = begin
ℚ.∣ yₖ ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.*-identityʳ ℚ.∣ yₖ ∣)) (ℚP.*-congˡ {ℚ.∣ yₖ ∣} (ℚP.≃-sym (ℚP.*-inverseʳ (+ 1 / N)))) ⟩
ℚ.∣ yₖ ∣ ℚ.* ((+ 1 / N) ℚ.* (+ N / 1)) ≤⟨ ℚP.*-monoʳ-≤-nonNeg {ℚ.∣ yₖ ∣} _ (ℚP.*-monoˡ-≤-nonNeg {+ N / 1} _
(proj₂ (fast2-8-1a ∣ x ∣₂ (x≄0⇒pos∣x∣₂ x x≄0)) ((k ℕ.+ N) ℕ.* (N ℕ.* N))
(ℕP.≤-trans (ℕP.m≤m*n N {N} ℕP.0<1+n)
(ℕP.m≤n*m (N ℕ.* N) {k ℕ.+ N} (subst (0 ℕ.<_) (ℕP.+-comm N k) ℕP.0<1+n))))) ⟩
ℚ.∣ yₖ ∣ ℚ.* (ℚ.∣ xₖ ∣ ℚ.* (+ N / 1)) ≈⟨ ℚP.≃-trans
(ℚP.≃-sym (ℚP.*-assoc ℚ.∣ yₖ ∣ ℚ.∣ xₖ ∣ (+ N / 1)))
(ℚP.≃-sym (ℚP.*-congʳ {+ N / 1} (ℚP.∣p*q∣≃∣p∣*∣q∣ yₖ xₖ))) ⟩
ℚ.∣ yₖ ℚ.* xₖ ∣ ℚ.* (+ N / 1) ≈⟨ ℚP.≃-trans
(ℚP.*-congʳ {+ N / 1} (ℚP.∣-∣-cong (ℚP.*-inverseˡ xₖ {xₖ≢0 k})))
(ℚP.*-identityˡ (+ N / 1)) ⟩
+ N / 1 ∎
where
xₖ : ℚᵘ
xₖ = seq x ((k ℕ.+ N) ℕ.* (N ℕ.* N))
yₖ : ℚᵘ
yₖ = (ℚ.1/ xₖ) {not0-helper x {x≄0} k}
∣yₘ*yₙ∣≤N² : ℚ.∣ yₘ ℚ.* yₙ ∣ ℚ.≤ (+ N / 1) ℚ.* (+ N / 1)
∣yₘ*yₙ∣≤N² = begin
ℚ.∣ yₘ ℚ.* yₙ ∣ ≈⟨ ℚP.∣p*q∣≃∣p∣*∣q∣ yₘ yₙ ⟩
ℚ.∣ yₘ ∣ ℚ.* ℚ.∣ yₙ ∣ ≤⟨ ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ yₙ ∣} _ (∣yₖ∣≤N m))
(ℚP.*-monoʳ-≤-nonNeg {+ N / 1} _ (∣yₖ∣≤N n)) ⟩
(+ N / 1) ℚ.* (+ N / 1) ∎
{-
DISCUSSION POINTS ON THE POSSIBILITY OF THE ℝ SOLVER
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Obviously, we want the ring solver to work on ℝ. It would be extremely tedious to prove any interesting result later on without the ring
solver. But there are some problems, at least right now, preventing it from working.
First, note that the ring solvers generally use rings with decidable equality. But it actually CAN work without decidable equality. The
equality can be so weak that it's not even slightly weakly decidable. As proof of concept, see the example below.
-}
{-
sadDec : ∀ (x y : ℚᵘ) -> Maybe (x ℚ.≃ y)
sadDec x y = nothing
module ℚ-Sad-+-*-Solver =
Solver ℚP.+-*-rawRing (ACR.fromCommutativeRing ℚP.+-*-commutativeRing) (ACR.-raw-almostCommutative⟶ (ACR.fromCommutativeRing ℚP.+-*-commutativeRing)) sadDec
testing₁ : ∀ (x y z : ℚᵘ) -> ℚ.1ℚᵘ ℚ.* (x ℚ.+ y ℚ.- z ℚ.+ 0ℚᵘ) ℚ.≃ y ℚ.- (ℚ.- x ℚ.+ z)
testing₁ x y z = solve 3 (λ x y z -> con ℚ.1ℚᵘ :* (x :+ y :- z :+ con 0ℚᵘ) := y :- (:- x :+ z)) ℚP.≃-refl x y z
where
open ℚ-Sad-+-*-Solver
-}
{- However, the same solution will NOT work on ℝ, at least for now, as shown below.-}
{-
≃-weaklyDec : ∀ x y -> Maybe (x ≃ y)
≃-weaklyDec x y = nothing
module ℝ-+-*-Solver =
Solver +-*-rawRing (ACR.fromCommutativeRing +-*-commutativeRing) (ACR.-raw-almostCommutative⟶ (ACR.fromCommutativeRing +-*-commutativeRing)) ≃-weaklyDec
testing₂ : ∀ x y z -> 1ℝ * (x + y - z + 0ℝ) ≃ y - (- x + z)
testing₂ x y z = ?
where
open ℝ-+-*-Solver
-}
{-
The problem is ≃-refl. For some reason, it's incapable of determining implicit arguments, even in trivial cases. For instance, 0ℝ ≃ 0ℝ must be proved using
≃-refl {0ℝ}. Excluding the implicit argument results in a constraint error, as shown below.-}
{-sad0ℝ₁ : 0ℝ ≃ 0ℝ
sad0ℝ₁ = ≃-refl
sad0ℝ₂ : 0ℝ ≃ 0ℝ
sad0ℝ₂ = ≃-refl {0ℝ}
-}
{- From the constraint error, I thought it was a problem with the definition of regularity in the definition of ℝ. In particular, the issue could be
the implicit m ≢0 and n ≢0 arguments. But modifying the definition so that there are NO implicit arguments still doesn't work. I am unsure what the cause is.
So, how do we let ℝ's solver work with reflexivity proofs? Here are some proposed attempts:
(1) Prove the ring equality at the sequence level instead. This means, to prove that (x + y) - z ≃ y - (z - x), for instance, we prove it by definition of ≃
instead of by using the various ring properties of ℝ. So our proof would need to be of the form
∣ (x₄ₘ + y₄ₘ - z₂ₘ) - (y₂ₘ - (z₄ₘ - x₄ₘ)) ∣ ≤ 2m⁻¹ (m∈ℤ⁺)
and we would use the ℚ ring solver to assist with it. This could be shorter, in some instances, than applying a bunch of ring properties of ℝ. But it most likely
becomes intractable when we get more difficult equalities and, for instance, when the ring equality includes multiplication (since the canonical bounds would
interfere).
(2) Prove the ring equality for ALL rings and then apply it to ℝ. It seems to work, as shown below in testing₃, but it's very tedious and seems prone to fail.
(3) The final option I've come up with is to wait for the next Agda release, which looks to be right around the corner. I've had this "constraints that seem
trivial but Agda won't solve" issue a few times now, and it was solved by an update twice (the other time there was an easy function I could make to fix it.
That doesn't seem to be the case here).
-}
{-
testing₃ : ∀ x y z -> x + y + z ≃ y + (z + x)
testing₃ = lem (+-*-commutativeRing)
where
open CommutativeRing using (Carrier; 0#; 1#; _≈_)
renaming
( _+_ to _R+_
; _-_ to _R-_
; _*_ to _R*_
; -_ to R-_
)
{-
The notation is a bit ugly, but this says
x + y - z + 0 = 1 * (y - (z - x)).
-}
lem : ∀ (R : CommutativeRing 0ℓ 0ℓ) -> ∀ (x y z : Carrier R) ->
(_≈_ R) ((_R+_ R) ((_R+_ R) x y) z)
((_R+_ R) y ((_R+_ R) z x))
lem R x y z = solve 3 (λ x y z ->
x :+ y :+ z := y :+ (z :+ x))
R-refl x y z
where
R-weaklyDec : ∀ x y -> Maybe ((R ≈ x) y)
R-weaklyDec x y = nothing
rawRing : RawRing 0ℓ 0ℓ
rawRing = {!!}
R-refl : Reflexive (_≈_ R)
R-refl = {!!}
module R-Solver =
Solver rawRing (ACR.fromCommutativeRing R) (ACR.-raw-almostCommutative⟶ (ACR.fromCommutativeRing R)) R-weaklyDec
open R-Solver
UPDATE
It seems (3) won't fix the problem. I tried the newest developmental release as of June 7th, 2021, and it didn't work.
Solution (2) might be promising if I can make some sort of function that says something for general rings R like
"If ϕᴿ(x₁,...,xₙ) = ψᴿ(x₁,...,xₙ) for all xᵢ∈R and for all rings R, then ϕ̂(x₁,...,xₙ) = ψ(x₁,...,xₙ) for all xᵢ∈ℝ.
That might save me the trouble of declaring a general ring solver and whatnot over and over again. Not sure if this
is possible, though.
-}
{-
If ϕ(x) = ψ(x) for all x∈R for all rings R, then ϕ(x) = ψ(x) for all x∈ℝ."
-}
{-
open CommutativeRing {{...}} using (Carrier; 0#; 1#; _≈_)
renaming
( _+_ to _R+_
; _-_ to _R-_
; _*_ to _R*_
; -_ to R-_
)
-}
-- This function and its counterparts are probably useless since we'd have to prove the
-- middle section anyway, which we could then directly apply in our proof instead of wasting our
-- time with this function.
{-solveMe : (ϕ ψ : (R : CommutativeRing 0ℓ 0ℓ) -> (x y z : Carrier) -> Carrier R) ->
(∀ (R : CommutativeRing 0ℓ 0ℓ) -> ∀ (x y z : Carrier R) -> (_≈_ R) (ϕ R x y z) (ψ R x y z)) ->
∀ (x y z : ℝ) -> ϕ +-*-commutativeRing x y z ≃ ψ +-*-commutativeRing x y z
solveMe ϕ ψ hyp x y z = hyp +-*-commutativeRing x y z-}
{-
R-Solver : CommutativeRing 0ℓ 0ℓ -> {!!}
R-Solver R = {!+-*-Solver!}
where
module +-*-Solver = Solver {!!} {!!} {!!} {!!}
open +-*-Solver
test : ∀ {{R : CommutativeRing 0ℓ 0ℓ}} -> ∀ (x y : Carrier) -> x R+ y ≈ (y R+ x)
test x y = {!!}
where
module +-*-Solver = Solver {!!} {!!} {!!} {!!}
-}
0test : 0ℝ ≃ - 0ℝ
0test = ≃-refl {0ℝ}
data _≃'_ : Rel ℝ 0ℓ where
*≃* : ∀ {x y : ℝ} -> (∀ (n : ℕ) -> {n≢0 : n ≢0} -> ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ (+ 2 / n) {n≢0}) -> x ≃' y
≃'-refl : Reflexive _≃'_
≃'-refl {x} = *≃* λ { (suc k₁) → let n = suc k₁ in begin
ℚ.∣ seq x n ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (seq x n)) ⟩
0ℚᵘ ≤⟨ ℚP.∣p∣≃p⇒0≤p ℚP.≃-refl ⟩
+ 2 / n ∎}
where open ℚP.≤-Reasoning
test0 : ∀ p -> - (p ⋆) ≃ (ℚ.- p) ⋆
test0 p = ≃-refl { - (p ⋆)}
test3 : 0ℝ ≃ - 0ℝ
test3 = ≃-refl {0ℝ}
test2 : seq 0ℝ ≡ seq (- 0ℝ)
test2 = _≡_.refl
test4 : reg 0ℝ ≡ reg (- 0ℝ)
test4 = {!refl!}
alpha : ¬ (0ℝ ≡ - 0ℝ)
alpha hyp = {!!}
gamma : 0ℝ ≃ - 0ℝ -> 0ℝ ≡ - 0ℝ
gamma 0≃-0 = {!!}
test1 : ∀ p -> (- (p ⋆)) ≃' ((ℚ.- p) ⋆)
test1 p = {!≃'-refl {(ℚ.- p) ⋆}!}
{-
(tⁿ) diverges iff
∃ε>0 ∀k∈ℕ ∃m,n≥k (∣tᵐ - tⁿ∣ ≥ ε)
t > 1
ε = 1/10
Let k∈ℕ.
-}
| 47.103513 | 174 | 0.335829 |
d0f092b42373af96a5bf977f9cf9e32986bc6197 | 398 | agda | Agda | test/Succeed/Issue2223c.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue2223c.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue2223c.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module _ where
open import Agda.Primitive
module _ (a ℓ ℓ' : Level) where
mutual
X : Level
X = _ -- Agda 2.5.1.1 solves this level meta
hyp : Set₁
hyp with (lsuc ℓ')
... | _ = Set
where
X<=a : Set (X ⊔ a) → Set a
X<=a A = A
test : Set₁
test with (lsuc ℓ)
... | _ = Set
where
a<=X : Set (X ⊔ a) → Set X
a<=X A = A
| 15.92 | 49 | 0.462312 |
df8d448e16aa68f9d8460e7ae34349b3d2b6712f | 18,005 | agda | Agda | explore/typecheck/UntypingPairs.agda | TristanCacqueray/disco | bb5b6773584253cfa84adf2111e39c9359506019 | [
"BSD-3-Clause"
] | 138 | 2016-12-10T08:10:03.000Z | 2022-01-22T22:56:45.000Z | explore/typecheck/UntypingPairs.agda | Boarders/disco | 7abce0acde1b0bbc993c76adc18b5b09230bf030 | [
"BSD-3-Clause"
] | 282 | 2016-11-19T18:05:42.000Z | 2022-03-28T21:43:15.000Z | explore/typecheck/UntypingPairs.agda | Boarders/disco | 7abce0acde1b0bbc993c76adc18b5b09230bf030 | [
"BSD-3-Clause"
] | 20 | 2017-02-18T20:36:05.000Z | 2021-07-30T05:37:45.000Z | module UntypingPairs where
open import Relation.Binary.PropositionalEquality
open import Function using (id)
open import Data.Empty
open import Data.Unit
open import Relation.Nullary
open import Data.Nat
open import Data.Fin
open import Data.Vec
open import Data.Sum
open import Data.Product
open import Data.List
open import Data.Maybe
-- Rather tedious --- stuff grows quadratically. Get this to go
-- through and then see if we can generalize to codes for constructors
-- or something like that.
------------------------------------------------------------
-- Types
------------------------------------------------------------
-- A universe of types for STLC + natural numbers + pairs.
data Type : Set where
Nat : Type
_⇒_ : Type → Type → Type
_⊗_ : Type → Type → Type
infixr 80 _⇒_
infixr 90 _⊗_
-- The function type constructor is injective.
⇒-inj : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂ ≡ τ₃ ⇒ τ₄) → (τ₁ ≡ τ₃) × (τ₂ ≡ τ₄)
⇒-inj refl = refl , refl
⊗-inj : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⊗ τ₂ ≡ τ₃ ⊗ τ₄) → (τ₁ ≡ τ₃) × (τ₂ ≡ τ₄)
⊗-inj refl = refl , refl
-- Equality of types is decidable.
_≡?_ : (τ₁ τ₂ : Type) → (τ₁ ≡ τ₂) ⊎ (τ₁ ≢ τ₂)
Nat ≡? Nat = inj₁ refl
Nat ≡? (_ ⇒ _) = inj₂ (λ ())
Nat ≡? (_ ⊗ _) = inj₂ (λ ())
(_ ⇒ _) ≡? Nat = inj₂ (λ ())
(_ ⇒ _) ≡? (_ ⊗ _) = inj₂ (λ ())
(_ ⊗ _) ≡? Nat = inj₂ (λ ())
(_ ⊗ _) ≡? (_ ⇒ _) = inj₂ (λ ())
(τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) with τ₁ ≡? τ₃ | τ₂ ≡? τ₄
(τ₁ ⇒ τ₂) ≡? (.τ₁ ⇒ .τ₂) | inj₁ refl | inj₁ refl = inj₁ refl
(τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) | inj₂ τ₁≢τ₃ | _ = inj₂ (λ eq → τ₁≢τ₃ (proj₁ (⇒-inj eq)))
(τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) | _ | inj₂ τ₂≢τ₄ = inj₂ (λ eq → τ₂≢τ₄ (proj₂ (⇒-inj eq)))
(τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) with τ₁ ≡? τ₃ | τ₂ ≡? τ₄
(τ₁ ⊗ τ₂) ≡? (.τ₁ ⊗ .τ₂) | inj₁ refl | inj₁ refl = inj₁ refl
(τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) | inj₂ τ₁≢τ₃ | _ = inj₂ (λ x → τ₁≢τ₃ (proj₁ (⊗-inj x)))
(τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) | _ | inj₂ τ₂≢τ₄ = inj₂ (λ eq → τ₂≢τ₄ (proj₂ (⊗-inj eq)))
≢-cong-⇒ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂ ≢ τ₃ ⇒ τ₄) → (τ₁ ≢ τ₃) ⊎ (τ₂ ≢ τ₄)
≢-cong-⇒ {τ₁} {τ₂} {τ₃} {τ₄} neq with τ₁ ≡? τ₃ | τ₂ ≡? τ₄
≢-cong-⇒ neq | inj₂ τ₁≢τ₃ | _ = inj₁ τ₁≢τ₃
≢-cong-⇒ neq | _ | inj₂ τ₂≢τ₄ = inj₂ τ₂≢τ₄
≢-cong-⇒ neq | inj₁ refl | inj₁ refl = ⊥-elim (neq refl)
≢-cong-⊗ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⊗ τ₂ ≢ τ₃ ⊗ τ₄) → (τ₁ ≢ τ₃) ⊎ (τ₂ ≢ τ₄)
≢-cong-⊗ {τ₁} {τ₂} {τ₃} {τ₄} neq with τ₁ ≡? τ₃ | τ₂ ≡? τ₄
≢-cong-⊗ neq | inj₂ τ₁≢τ₃ | _ = inj₁ τ₁≢τ₃
≢-cong-⊗ neq | _ | inj₂ τ₂≢τ₄ = inj₂ τ₂≢τ₄
≢-cong-⊗ neq | inj₁ refl | inj₁ refl = ⊥-elim (neq refl)
-- A type of explicit evidence explaining *why* two types are unequal.
data _≁_ : Type → Type → Set where
Nat≁⇒ : ∀ {τ₁ τ₂} → Nat ≁ (τ₁ ⇒ τ₂)
Nat≁⊗ : ∀ {τ₁ τ₂} → Nat ≁ (τ₁ ⊗ τ₂)
⇒≁⊗ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂) ≁ (τ₃ ⊗ τ₄)
⇒ˡ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₁ ≁ τ₂ → (τ₁ ⇒ τ₃) ≁ (τ₂ ⇒ τ₄)
⇒ʳ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₃ ≁ τ₄ → (τ₁ ⇒ τ₃) ≁ (τ₂ ⇒ τ₄)
⊗ˡ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₁ ≁ τ₂ → (τ₁ ⊗ τ₃) ≁ (τ₂ ⊗ τ₄)
⊗ʳ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₃ ≁ τ₄ → (τ₁ ⊗ τ₃) ≁ (τ₂ ⊗ τ₄)
≁-sym : ∀ {τ₁ τ₂} → τ₁ ≁ τ₂ → τ₂ ≁ τ₁
-- Given such a proof we can show the types are unequal.
≁-≢ : ∀ {τ₁ τ₂} → (τ₁ ≁ τ₂) → (τ₁ ≢ τ₂)
≁-≢ Nat≁⇒ = λ ()
≁-≢ Nat≁⊗ = λ ()
≁-≢ ⇒≁⊗ = λ ()
≁-≢ (⇒ˡ-≁ τ₁≁τ₂) refl = ≁-≢ τ₁≁τ₂ refl
≁-≢ (⇒ʳ-≁ τ₃≁τ₄) refl = ≁-≢ τ₃≁τ₄ refl
≁-≢ (⊗ˡ-≁ τ₁≁τ₂) refl = ≁-≢ τ₁≁τ₂ refl
≁-≢ (⊗ʳ-≁ τ₃≁τ₄) refl = ≁-≢ τ₃≁τ₄ refl
≁-≢ (≁-sym τ₂≁τ₁) refl = ≁-≢ τ₂≁τ₁ refl
-- Since our universe of types is closed, we can actually go the other
-- way too. That is, ≢ is equivalent to ≁ ; the point is that the
-- latter is more immediately informative (by pattern-matching etc.)
-- which can be used to produce error messages and so on.
--
-- Note, however, that there might be *multiple* terms of type τ₁ ≁
-- τ₂: each corresponds to a different explanation of why the types
-- are not equal. We might actually care which one we have.
-- Round-tripping through (τ₁ ≢ τ₂) is not the identity.
≢-≁ : ∀ {τ₁ τ₂} → (τ₁ ≢ τ₂) → (τ₁ ≁ τ₂)
≢-≁ {Nat} {Nat} τ₁≢τ₂ with τ₁≢τ₂ refl
... | ()
≢-≁ {Nat} {τ₂ ⇒ τ₃} _ = Nat≁⇒
≢-≁ {Nat} {τ₂ ⊗ τ₃} _ = Nat≁⊗
≢-≁ {τ₁ ⇒ τ₂} {Nat} _ = ≁-sym Nat≁⇒
≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⊗ τ₄} _ = ⇒≁⊗
≢-≁ {τ₁ ⊗ τ₂} {Nat} _ = ≁-sym Nat≁⊗
≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⇒ τ₄} _ = ≁-sym ⇒≁⊗
≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ with ≢-cong-⇒ τ₁⇒τ₂≢τ₃⇒τ₄
≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ | inj₁ τ₁≢τ₃ = ⇒ˡ-≁ (≢-≁ τ₁≢τ₃)
≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ | inj₂ τ₂≢τ₄ = ⇒ʳ-≁ (≢-≁ τ₂≢τ₄)
≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ with ≢-cong-⊗ τ₁⊗τ₂≢τ₃⊗τ₄
≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ | inj₁ τ₁≢τ₃ = ⊗ˡ-≁ (≢-≁ τ₁≢τ₃)
≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ | inj₂ τ₂≢τ₄ = ⊗ʳ-≁ (≢-≁ τ₂≢τ₄)
-- Sometimes it's convenient to decide equality of types using ≁ in place of ≢.
_∼?_ : (τ₁ τ₂ : Type) → (τ₁ ≡ τ₂) ⊎ (τ₁ ≁ τ₂)
τ₁ ∼? τ₂ = Data.Sum.map id ≢-≁ (τ₁ ≡? τ₂)
-- Evidence that a type is not an arrow type.
data not⇒_ : Type → Set where
not⇒Nat : not⇒ Nat
not⇒⊗ : ∀ {τ₁ τ₂} → not⇒ (τ₁ ⊗ τ₂)
data not⊗_ : Type → Set where
not⊗Nat : not⊗ Nat
not⊗⇒ : ∀ {τ₁ τ₂} → not⊗ (τ₁ ⇒ τ₂)
⇒? : (τ : Type) → (Σ[ τ₁ ∈ Type ] Σ[ τ₂ ∈ Type ] τ ≡ τ₁ ⇒ τ₂) ⊎ (not⇒ τ)
⇒? Nat = inj₂ not⇒Nat
⇒? (_ ⊗ _) = inj₂ not⇒⊗
⇒? (τ₁ ⇒ τ₂) = inj₁ (τ₁ , τ₂ , refl)
------------------------------------------------------------
-- Expressions
------------------------------------------------------------
-- (Untyped) expressions of STLC + arithmetic + pairs.
data Expr (n : ℕ) : Set where
lit : ℕ → Expr n
_⊕_ : Expr n → Expr n → Expr n
⟨_,_⟩ : Expr n → Expr n → Expr n
π₁ : Expr n
π₂ : Expr n
var : Fin n → Expr n
ƛ : Type → Expr (suc n) → Expr n
_·_ : Expr n → Expr n → Expr n
Ctx : ℕ → Set
Ctx n = Vec Type n
------------------------------------------------------------
-- Typing
------------------------------------------------------------
-- Typing derivations.
data _⊢_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where
lit : ∀ {n} {Γ : Ctx n} {m}
→ Γ ⊢ lit m ∶ Nat
_⊕_ : ∀ {n} {Γ : Ctx n} {t₁ t₂}
→ Γ ⊢ t₁ ∶ Nat
→ Γ ⊢ t₂ ∶ Nat
→ Γ ⊢ (t₁ ⊕ t₂) ∶ Nat
⟨_,_⟩ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊢ t₁ ∶ τ₁
→ Γ ⊢ t₂ ∶ τ₂
→ Γ ⊢ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂
π₁ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂}
→ Γ ⊢ π₁ ∶ (τ₁ ⊗ τ₂) ⇒ τ₁
π₂ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂}
→ Γ ⊢ π₂ ∶ (τ₁ ⊗ τ₂) ⇒ τ₂
var : ∀ {n} {Γ : Ctx n} {i}
→ Γ ⊢ var i ∶ lookup i Γ
ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂}
→ (τ₁ ∷ Γ) ⊢ t ∶ τ₂
→ Γ ⊢ ƛ τ₁ t ∶ (τ₁ ⇒ τ₂)
_·_ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊢ t₁ ∶ τ₁ ⇒ τ₂
→ Γ ⊢ t₂ ∶ τ₁
→ Γ ⊢ t₁ · t₂ ∶ τ₂
-- Explicit, constructive evidence for the *untypability* of a term.
data _⊬_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where
-- Explicitly build in uniqueness of typing as an axiom. t is not
-- typeable at type τ₂ if t is typeable at some different type.
mismatch : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂}
→ Γ ⊢ t ∶ τ₁
→ τ₁ ≁ τ₂
→ Γ ⊬ t ∶ τ₂
-- There are three ways for a + term to fail to have a given type τ:
-- either the left or right sides do not have type Nat, or the type
-- τ itself is not Nat.
⊕ˡ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ}
→ Γ ⊬ t₁ ∶ Nat
→ Γ ⊬ (t₁ ⊕ t₂) ∶ τ
⊕ʳ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ}
→ Γ ⊬ t₂ ∶ Nat
→ Γ ⊬ (t₁ ⊕ t₂) ∶ τ
⊕≁Nat : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ}
→ τ ≁ Nat → Γ ⊬ (t₁ ⊕ t₂) ∶ τ
⟨⟩-ty : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ}
→ not⊗ τ → Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ
⟨⟩ˡ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊬ t₁ ∶ τ₁
→ Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂
⟨⟩ʳ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊬ t₂ ∶ τ₂
→ Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂
π₁-⇒ : ∀ {n} {Γ : Ctx n} {τ}
→ not⇒ τ
→ Γ ⊬ π₁ ∶ τ
π₁-⊗ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂}
→ not⊗ τ₁
→ Γ ⊬ π₁ ∶ τ₁ ⇒ τ₂
π₁-∼ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂ τ₃}
→ τ₁ ≁ τ₃
→ Γ ⊬ π₁ ∶ (τ₁ ⊗ τ₂) ⇒ τ₃
π₂-⇒ : ∀ {n} {Γ : Ctx n} {τ}
→ not⇒ τ
→ Γ ⊬ π₂ ∶ τ
π₂-⊗ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂}
→ not⊗ τ₁
→ Γ ⊬ π₂ ∶ τ₁ ⇒ τ₂
π₂-∼ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂ τ₃}
→ τ₂ ≁ τ₃
→ Γ ⊬ π₂ ∶ (τ₁ ⊗ τ₂) ⇒ τ₃
-- ƛ-funty holds if τ is not a function type at all, or if it is a
-- function type whose input type is not τ₁.
ƛ-funty : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ}
→ (∀ {τ₂} → τ ≁ τ₁ ⇒ τ₂)
→ Γ ⊬ ƛ τ₁ t ∶ τ
-- Otherwise, τ is of the form (τ₁ ⇒ τ₂) but the body t does not
-- have type τ₂. Note this could be either because t is not typable
-- at all, or because it has some type other than τ₂.
ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂}
→ (τ₁ ∷ Γ) ⊬ t ∶ τ₂
→ Γ ⊬ ƛ τ₁ t ∶ (τ₁ ⇒ τ₂)
-- Had this ƛ-resty constructor, but it turns out we don't need it:
-- it is not used in inference or checking, and isn't needed to
-- prove equivalence of ⊬ and ¬ ⊢ . It handles *only* the case
-- where t is typable but has a type different than the output type
-- of the whole expression; but the ƛ constructor handles this case
-- as well as the case where t is not typeable at all.
-- ƛ-resty : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂ τ₃}
-- → (τ₁ ∷ Γ) ⊢ t ∶ τ₂
-- → τ₂ ≁ τ₃
-- → Γ ⊬ ƛ τ₁ t ∶ τ₁ ⇒ τ₃
-- Finally, there are two cases when an application is not typeable.
-- Either the function does not have an appropriate function type,
-- or the argument does not have a type that matches the function's
-- input type.
·-fun : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₂}
→ (∀ {τ₁} → Γ ⊬ t₁ ∶ τ₁ ⇒ τ₂)
→ Γ ⊬ t₁ · t₂ ∶ τ₂
·-arg : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊢ t₁ ∶ τ₁ ⇒ τ₂
→ Γ ⊬ t₂ ∶ τ₁
→ Γ ⊬ t₁ · t₂ ∶ τ₂
-- ------------------------------------------------------------
-- -- Type inference and checking
-- ------------------------------------------------------------
-- -- Type inference for a term in a given context returns either a type
-- -- and a valid typing derivation, or a constructive proof that the
-- -- term has no type. Note that in this system, ALL terms can be
-- -- inferred. In a bidirectional system we would have to restrict this
-- -- to only take inferrable terms as inputs.
-- infer : ∀ {n} → (Γ : Ctx n) → (t : Expr n) → (∃ λ τ → Γ ⊢ t ∶ τ) ⊎ (∀ τ → Γ ⊬ t ∶ τ)
-- infer Γ (lit n) = inj₁ (Nat , lit)
-- infer Γ (t₁ ⊕ t₂) with infer Γ t₁ | infer Γ t₂
-- infer Γ (t₁ ⊕ t₂) | inj₁ (Nat , Γ⊢t₁∶Nat) | inj₁ (Nat , Γ⊢t₂∶Nat) = inj₁ (Nat , (Γ⊢t₁∶Nat ⊕ Γ⊢t₂∶Nat))
-- infer Γ (t₁ ⊕ t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ _ = inj₂ (λ _ → ⊕ˡ (mismatch Γ⊢t₁∶τ₁⇒τ₂ (≁-sym Nat≁⇒)))
-- infer Γ (t₁ ⊕ t₂) | inj₁ _ | inj₁ (τ₃ ⇒ τ₄ , Γ⊢t₂∶τ₃⇒τ₄) = inj₂ (λ _ → ⊕ʳ (mismatch Γ⊢t₂∶τ₃⇒τ₄ (≁-sym Nat≁⇒)))
-- infer Γ (t₁ ⊕ t₂) | inj₂ Γ⊬t₁∶ | _ = inj₂ (λ _ → ⊕ˡ (Γ⊬t₁∶ Nat))
-- infer Γ (t₁ ⊕ t₂) | _ | inj₂ Γ⊬t₂∶ = inj₂ (λ _ → ⊕ʳ (Γ⊬t₂∶ Nat))
-- infer Γ (var i) = inj₁ (lookup i Γ , var)
-- infer Γ (ƛ τ₁ t) with infer (τ₁ ∷ Γ) t
-- infer Γ (ƛ τ₁ t) | inj₁ (τ₂ , τ₁∷Γ⊢t∶τ₂) = inj₁ (τ₁ ⇒ τ₂ , ƛ τ₁∷Γ⊢t∶τ₂)
-- infer Γ (ƛ τ₁ t) | inj₂ τ₁∷Γ⊬t∶ = inj₂ lemma
-- where
-- lemma : (τ : Type) → Γ ⊬ ƛ τ₁ t ∶ τ
-- lemma Nat = ƛ-funty Nat≁⇒
-- lemma (τ₁′ ⇒ τ₂) with τ₁′ ∼? τ₁
-- lemma (.τ₁ ⇒ τ₂) | inj₁ refl = ƛ (τ₁∷Γ⊬t∶ τ₂)
-- lemma (τ₁′ ⇒ τ₂) | inj₂ τ₁′≁τ₁ = ƛ-funty (λ {τ₃} → ⇒ˡ-≁ τ₁′≁τ₁)
-- infer Γ (t₁ · t₂) with infer Γ t₁ | infer Γ t₂
-- infer Γ (t₁ · t₂) | inj₁ (Nat , Γ⊢t₁∶Nat) | _ = inj₂ (λ _ → ·-fun (mismatch Γ⊢t₁∶Nat Nat≁⇒))
-- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (τ₁′ , Γ⊢t₂∶τ₁′) with τ₁ ∼? τ₁′
-- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (.τ₁ , Γ⊢t₂∶τ₁ ) | inj₁ refl = inj₁ (τ₂ , (Γ⊢t₁∶τ₁⇒τ₂ · Γ⊢t₂∶τ₁))
-- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (τ₁′ , Γ⊢t₂∶τ₁′) | inj₂ τ₁≁τ₁′ = inj₂ lemma2
-- where
-- lemma2 : ∀ τ → Γ ⊬ t₁ · t₂ ∶ τ
-- lemma2 τ with τ ∼? τ₂
-- lemma2 τ | inj₁ τ≡τ₂ rewrite τ≡τ₂ = ·-arg Γ⊢t₁∶τ₁⇒τ₂ (mismatch Γ⊢t₂∶τ₁′ (≁-sym τ₁≁τ₁′))
-- lemma2 τ | inj₂ τ≁τ₂ = ·-fun (mismatch Γ⊢t₁∶τ₁⇒τ₂ (⇒ʳ-≁ (≁-sym τ≁τ₂)))
-- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₂ Γ⊬t₂ = inj₂ lemma3
-- where
-- lemma3 : ∀ τ → Γ ⊬ t₁ · t₂ ∶ τ
-- lemma3 τ with τ ∼? τ₂
-- lemma3 τ | inj₁ τ≡τ₂ rewrite τ≡τ₂ = ·-arg Γ⊢t₁∶τ₁⇒τ₂ (Γ⊬t₂ τ₁)
-- lemma3 τ | inj₂ τ≁τ₂ = ·-fun (mismatch Γ⊢t₁∶τ₁⇒τ₂ (⇒ʳ-≁ (≁-sym τ≁τ₂)))
-- infer Γ (t₁ · t₂) | inj₂ Γ⊬t₁∶ | _ = inj₂ (λ τ₂ → ·-fun (λ {τ₁} → Γ⊬t₁∶ (τ₁ ⇒ τ₂)))
-- -- Check whether a given term has a *given* type.
-- check : ∀ {n} → (Γ : Ctx n) → (t : Expr n) → (τ : Type) → (Γ ⊢ t ∶ τ) ⊎ (Γ ⊬ t ∶ τ)
-- check Γ (lit _) (τ ⇒ τ₁) = inj₂ (mismatch lit Nat≁⇒)
-- check Γ (lit _) Nat = inj₁ lit
-- check Γ (_ ⊕ _ ) (τ ⇒ τ₁) = inj₂ (⊕≁Nat (≁-sym Nat≁⇒))
-- check Γ (t₁ ⊕ t₂) Nat with check Γ t₁ Nat | check Γ t₂ Nat
-- check Γ (t₁ ⊕ t₂) Nat | inj₁ Γ⊢t₁∶Nat | inj₁ Γ⊢t₂∶Nat = inj₁ (Γ⊢t₁∶Nat ⊕ Γ⊢t₂∶Nat)
-- check Γ (t₁ ⊕ t₂) Nat | inj₂ Γ⊬t₁∶Nat | _ = inj₂ (⊕ˡ Γ⊬t₁∶Nat)
-- check Γ (t₁ ⊕ t₂) Nat | _ | inj₂ Γ⊬t₂∶Nat = inj₂ (⊕ʳ Γ⊬t₂∶Nat)
-- check Γ (var i) τ with τ ∼? lookup i Γ
-- check Γ (var i) τ | inj₁ τ≡iΓ rewrite τ≡iΓ = inj₁ var
-- check Γ (var i) τ | inj₂ τ≁iΓ = inj₂ (mismatch var (≁-sym τ≁iΓ))
-- check Γ (ƛ τ₁ t) Nat = inj₂ (ƛ-funty Nat≁⇒)
-- check Γ (ƛ τ₁ t) (τ ⇒ τ₂) with τ ∼? τ₁ | check (τ₁ ∷ Γ) t τ₂
-- check Γ (ƛ τ₁ t) (τ ⇒ τ₂) | inj₂ τ≁τ₁ | _ = inj₂ (ƛ-funty (⇒ˡ-≁ τ≁τ₁))
-- check Γ (ƛ τ₁ t) (.τ₁ ⇒ τ₂) | inj₁ refl | inj₂ τ₁∷Γ⊬t∶τ₂ = inj₂ (ƛ τ₁∷Γ⊬t∶τ₂)
-- check Γ (ƛ τ₁ t) (.τ₁ ⇒ τ₂) | inj₁ refl | inj₁ τ₁∷Γ⊢t∶τ₂ = inj₁ (ƛ τ₁∷Γ⊢t∶τ₂)
-- --- Note that in order to check an application we have to use type inference on t₁.
-- check Γ (t₁ · t₂) τ with infer Γ t₁
-- check Γ (t₁ · t₂) τ | inj₂ Γ⊬t₁∶ = inj₂ (·-fun (λ {τ₁} → Γ⊬t₁∶ (τ₁ ⇒ τ)))
-- check Γ (t₁ · t₂) τ | inj₁ (Nat , Γ⊢t₁∶τ₁) = inj₂ (·-fun (mismatch Γ⊢t₁∶τ₁ Nat≁⇒))
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) with τ ∼? τ₂
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₂ τ≁τ₂ = inj₂ (·-fun (mismatch Γ⊢t₁∶τ₁ (⇒ʳ-≁ (≁-sym τ≁τ₂))))
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ rewrite τ≡τ₂ with check Γ t₂ τ₁
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ | inj₂ Γ⊬t₂∶τ₁ = inj₂ (·-arg Γ⊢t₁∶τ₁ Γ⊬t₂∶τ₁)
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ | inj₁ Γ⊢t₂∶τ₁ = inj₁ (Γ⊢t₁∶τ₁ · Γ⊢t₂∶τ₁)
-- ------------------------------------------------------------
-- -- Correctness
-- ------------------------------------------------------------
-- -- The whole idea is that ⊬ is a more explicit/constructive, yet
-- -- equivalent, way to represent the negation of ⊢ . We can actually
-- -- prove the equivalence.
-- -- First, straightforward induction on typing derivations shows that
-- -- we really do have unique types, as assumed by the 'mismatch'
-- -- constructor.
-- ⊢-unique : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ₁ τ₂ : Type} → (Γ ⊢ t ∶ τ₁) → (Γ ⊢ t ∶ τ₂) → (τ₁ ≡ τ₂)
-- ⊢-unique lit lit = refl
-- ⊢-unique (_ ⊕ _) (_ ⊕ _) = refl
-- ⊢-unique var var = refl
-- ⊢-unique (ƛ Γ⊢t∶τ₁) (ƛ Γ⊢t∶τ₂) rewrite ⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ₂ = refl
-- ⊢-unique (Γ⊢t∶τ₁ · _) (Γ⊢t∶τ₂ · _) = proj₂ (⇒-inj (⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ₂))
-- -- Now we can do one direction of the equivalence. This direction is
-- -- just induction over derivations, making use of uniqueness of
-- -- typing.
-- ⊬-¬⊢ : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ : Type} → (Γ ⊬ t ∶ τ) → (¬ (Γ ⊢ t ∶ τ))
-- ⊬-¬⊢ (mismatch Γ⊢t∶τ₁ τ₁≁τ) Γ⊢t∶τ = ≁-≢ τ₁≁τ (⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ)
-- ⊬-¬⊢ (⊕ˡ Γ⊬t₁∶N) (Γ⊢t₁∶N ⊕ _ ) = ⊬-¬⊢ Γ⊬t₁∶N Γ⊢t₁∶N
-- ⊬-¬⊢ (⊕ʳ Γ⊬t₂∶N) (_ ⊕ Γ⊢t₂∶N) = ⊬-¬⊢ Γ⊬t₂∶N Γ⊢t₂∶N
-- ⊬-¬⊢ (⊕≁Nat τ≁N) (_ ⊕ _ ) = ≁-≢ τ≁N refl
-- ⊬-¬⊢ (ƛ-funty τ≁τ₁⇒) (ƛ _) = ≁-≢ τ≁τ₁⇒ refl
-- ⊬-¬⊢ (ƛ Γ⊬t∶τ₂) (ƛ Γ⊢t∶τ₂) = ⊬-¬⊢ Γ⊬t∶τ₂ Γ⊢t∶τ₂
-- ⊬-¬⊢ (·-fun Γ⊬t₁) (Γ⊢t₁ · _) = ⊬-¬⊢ Γ⊬t₁ Γ⊢t₁
-- ⊬-¬⊢ (·-arg Γ⊢t₁∶τ₁⇒τ Γ⊬t₂∶τ) (Γ⊢t₁∶τ₂⇒τ · Γ⊢t₂)
-- rewrite proj₁ (⇒-inj (⊢-unique Γ⊢t₁∶τ₁⇒τ Γ⊢t₁∶τ₂⇒τ)) = ⊬-¬⊢ Γ⊬t₂∶τ Γ⊢t₂
-- -- The other direction follows straightforwardly from type checking.
-- ¬⊢-⊬ : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ : Type} → (¬ (Γ ⊢ t ∶ τ)) → (Γ ⊬ t ∶ τ)
-- ¬⊢-⊬ {_} {Γ} {t} {τ} ¬Γ⊢t∶τ with check Γ t τ
-- ¬⊢-⊬ ¬Γ⊢t∶τ | inj₁ Γ⊢t∶τ = ⊥-elim (¬Γ⊢t∶τ Γ⊢t∶τ)
-- ¬⊢-⊬ ¬Γ⊢t∶τ | inj₂ Γ⊬t∶τ = Γ⊬t∶τ
-- ------------------------------------------------------------
-- -- Take 2
-- ------------------------------------------------------------
-- -- XXX these need to be dependent somehow? e.g. consider the ƛ case
-- -- below. If τ is not an arrow type the whole thing fails; but if it
-- -- does, we need to know what τ₁ and τ₂ are in order to refer to them
-- -- in the rest of the conditions.
-- data many : List (Set × Set) → Set where
-- empty : many []
-- here : ∀ {Tₗ Tᵣ Ts} → Tₗ → many Ts → many ((Tₗ , Tᵣ) ∷ Ts)
-- there : ∀ {Tₗ Tᵣ Ts} → Tᵣ → many Ts → many ((Tₗ , Tᵣ) ∷ Ts)
-- data some : List (Set × Set) → Set where
-- here : ∀ {Tₗ Tᵣ Ts} → Tₗ → many Ts → some ((Tₗ , Tᵣ) ∷ Ts)
-- there : ∀ {Tₗ Tᵣ Ts} → Tᵣ → some Ts → some ((Tₗ , Tᵣ) ∷ Ts)
-- -- Unique untypability; gives *every* possible reason that something
-- -- is not typeable. There is no 'mismatch' constructor.
-- {-# NO_POSITIVITY_CHECK #-}
-- data _⊬₂_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where
-- lit : ∀ {n} {Γ : Ctx n} {m} {τ} → τ ≁ Nat → Γ ⊬₂ lit m ∶ τ
-- -- For t₁ ⊕ t₂ to be untypeable, at least one of three things must be wrong:
-- ⊕ : ∀ {n} {Γ : Ctx n} {t₁ t₂ τ}
-- → some
-- ( (Γ ⊬₂ t₁ ∶ Nat , Γ ⊢ t₁ ∶ Nat) -- Either t₁ is well-typed or not
-- ∷ (Γ ⊬₂ t₂ ∶ Nat , Γ ⊢ t₂ ∶ Nat) -- Either t₂ is well-typed or not
-- ∷ ((τ ≁ Nat) , (τ ≡ Nat)) -- τ is Nat or not
-- ∷ []
-- )
-- → Γ ⊬₂ t₁ ⊕ t₂ ∶ τ
-- var : ∀ {n} {Γ : Ctx n} {i τ}
-- → τ ≁ lookup i Γ
-- → Γ ⊬₂ var i ∶ τ
-- -- ƛ τ₁ t does not have type τ if
-- -- - τ is not an arrow type
-- -- ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂ τ}
-- -- → some
-- -- ( (τ ≁
| 41.107306 | 123 | 0.471036 |
20cb577153a9a9617eea25fc6c19577d9d8f6fee | 4,010 | agda | Agda | src/data/lib/prim/Agda/Builtin/Nat.agda | vlopezj/agda | ff4d89e75970cf27599fb9f572bd43c9455cbb56 | [
"BSD-3-Clause"
] | 2 | 2019-10-29T09:40:30.000Z | 2020-09-20T00:28:57.000Z | src/data/lib/prim/Agda/Builtin/Nat.agda | vikfret/agda | 49ad0b3f0d39c01bc35123478b857e702b29fb9d | [
"BSD-3-Clause"
] | 3 | 2018-11-14T15:31:44.000Z | 2019-04-01T19:39:26.000Z | src/data/lib/prim/Agda/Builtin/Nat.agda | vikfret/agda | 49ad0b3f0d39c01bc35123478b857e702b29fb9d | [
"BSD-3-Clause"
] | 1 | 2021-04-01T18:30:09.000Z | 2021-04-01T18:30:09.000Z | {-# OPTIONS --without-K --safe --no-universe-polymorphism --no-sized-types --no-guardedness #-}
module Agda.Builtin.Nat where
open import Agda.Builtin.Bool
data Nat : Set where
zero : Nat
suc : (n : Nat) → Nat
{-# BUILTIN NATURAL Nat #-}
infix 4 _==_ _<_
infixl 6 _+_ _-_
infixl 7 _*_
_+_ : Nat → Nat → Nat
zero + m = m
suc n + m = suc (n + m)
{-# BUILTIN NATPLUS _+_ #-}
_-_ : Nat → Nat → Nat
n - zero = n
zero - suc m = zero
suc n - suc m = n - m
{-# BUILTIN NATMINUS _-_ #-}
_*_ : Nat → Nat → Nat
zero * m = zero
suc n * m = m + n * m
{-# BUILTIN NATTIMES _*_ #-}
_==_ : Nat → Nat → Bool
zero == zero = true
suc n == suc m = n == m
_ == _ = false
{-# BUILTIN NATEQUALS _==_ #-}
_<_ : Nat → Nat → Bool
_ < zero = false
zero < suc _ = true
suc n < suc m = n < m
{-# BUILTIN NATLESS _<_ #-}
-- Helper function div-helper for Euclidean division.
---------------------------------------------------------------------------
--
-- div-helper computes n / 1+m via iteration on n.
--
-- n div (suc m) = div-helper 0 m n m
--
-- The state of the iterator has two accumulator variables:
--
-- k: The quotient, returned once n=0. Initialized to 0.
--
-- j: A counter, initialized to the divisor m, decreased on each iteration step.
-- Once it reaches 0, the quotient k is increased and j reset to m,
-- starting the next countdown.
--
-- Under the precondition j ≤ m, the invariant is
--
-- div-helper k m n j = k + (n + m - j) div (1 + m)
div-helper : (k m n j : Nat) → Nat
div-helper k m zero j = k
div-helper k m (suc n) zero = div-helper (suc k) m n m
div-helper k m (suc n) (suc j) = div-helper k m n j
{-# BUILTIN NATDIVSUCAUX div-helper #-}
-- Proof of the invariant by induction on n.
--
-- clause 1: div-helper k m 0 j
-- = k by definition
-- = k + (0 + m - j) div (1 + m) since m - j < 1 + m
--
-- clause 2: div-helper k m (1 + n) 0
-- = div-helper (1 + k) m n m by definition
-- = 1 + k + (n + m - m) div (1 + m) by induction hypothesis
-- = 1 + k + n div (1 + m) by simplification
-- = k + (n + (1 + m)) div (1 + m) by expansion
-- = k + (1 + n + m - 0) div (1 + m) by expansion
--
-- clause 3: div-helper k m (1 + n) (1 + j)
-- = div-helper k m n j by definition
-- = k + (n + m - j) div (1 + m) by induction hypothesis
-- = k + ((1 + n) + m - (1 + j)) div (1 + m) by expansion
--
-- Q.e.d.
-- Helper function mod-helper for the remainder computation.
---------------------------------------------------------------------------
--
-- (Analogous to div-helper.)
--
-- mod-helper computes n % 1+m via iteration on n.
--
-- n mod (suc m) = mod-helper 0 m n m
--
-- The invariant is:
--
-- m = k + j ==> mod-helper k m n j = (n + k) mod (1 + m).
mod-helper : (k m n j : Nat) → Nat
mod-helper k m zero j = k
mod-helper k m (suc n) zero = mod-helper 0 m n m
mod-helper k m (suc n) (suc j) = mod-helper (suc k) m n j
{-# BUILTIN NATMODSUCAUX mod-helper #-}
-- Proof of the invariant by induction on n.
--
-- clause 1: mod-helper k m 0 j
-- = k by definition
-- = (0 + k) mod (1 + m) since m = k + j, thus k < m
--
-- clause 2: mod-helper k m (1 + n) 0
-- = mod-helper 0 m n m by definition
-- = (n + 0) mod (1 + m) by induction hypothesis
-- = (n + (1 + m)) mod (1 + m) by expansion
-- = (1 + n) + k) mod (1 + m) since k = m (as l = 0)
--
-- clause 3: mod-helper k m (1 + n) (1 + j)
-- = mod-helper (1 + k) m n j by definition
-- = (n + (1 + k)) mod (1 + m) by induction hypothesis
-- = ((1 + n) + k) mod (1 + m) by commutativity
--
-- Q.e.d.
| 29.925373 | 95 | 0.471571 |
df3b2ba8abfb7618fd1ae36a0aa713e382e997a1 | 5,998 | agda | Agda | Cubical/Structures/Relational/Product.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/Structures/Relational/Product.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | 1 | 2022-01-27T02:07:48.000Z | 2022-01-27T02:07:48.000Z | Cubical/Structures/Relational/Product.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | {-
Product of structures S and T: X ↦ S X × T X
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Relational.Product where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Foundations.RelationalStructure
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation as Trunc
open import Cubical.HITs.SetQuotients
open import Cubical.Structures.Product
private
variable
ℓ ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓ₂' ℓ₂'' : Level
-- Structured relations
ProductRelStr :
{S₁ : Type ℓ → Type ℓ₁} (ρ₁ : StrRel S₁ ℓ₁')
{S₂ : Type ℓ → Type ℓ₂} (ρ₂ : StrRel S₂ ℓ₂')
→ StrRel (ProductStructure S₁ S₂) (ℓ-max ℓ₁' ℓ₂')
ProductRelStr ρ₁ ρ₂ R (s₁ , s₂) (t₁ , t₂) =
ρ₁ R s₁ t₁ × ρ₂ R s₂ t₂
productSuitableRel :
{S₁ : Type ℓ → Type ℓ₁} {ρ₁ : StrRel S₁ ℓ₁'}
{S₂ : Type ℓ → Type ℓ₂} {ρ₂ : StrRel S₂ ℓ₂'}
→ SuitableStrRel S₁ ρ₁ → SuitableStrRel S₂ ρ₂
→ SuitableStrRel (ProductStructure S₁ S₂) (ProductRelStr ρ₁ ρ₂)
productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .fst .fst =
θ₁ .quo (X , s₁) R r₁ .fst .fst , θ₂ .quo (X , s₂) R r₂ .fst .fst
productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .fst .snd =
θ₁ .quo (X , s₁) R r₁ .fst .snd , θ₂ .quo (X , s₂) R r₂ .fst .snd
productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .snd ((q₁ , q₂) , (c₁ , c₂)) i .fst =
θ₁ .quo (X , s₁) R r₁ .snd (q₁ , c₁) i .fst , θ₂ .quo (X , s₂) R r₂ .snd (q₂ , c₂) i .fst
productSuitableRel θ₁ θ₂ .quo (X , s₁ , s₂) R (r₁ , r₂) .snd ((q₁ , q₂) , (c₁ , c₂)) i .snd =
θ₁ .quo (X , s₁) R r₁ .snd (q₁ , c₁) i .snd , θ₂ .quo (X , s₂) R r₂ .snd (q₂ , c₂) i .snd
productSuitableRel θ₁ θ₂ .symmetric R (r₁ , r₂) =
θ₁ .symmetric R r₁ , θ₂ .symmetric R r₂
productSuitableRel θ₁ θ₂ .transitive R R' (r₁ , r₂) (r₁' , r₂') =
θ₁ .transitive R R' r₁ r₁' , θ₂ .transitive R R' r₂ r₂'
productSuitableRel θ₁ θ₂ .set setX =
isSet× (θ₁ .set setX) (θ₂ .set setX)
productSuitableRel θ₁ θ₂ .prop propR (s₁ , s₂) (t₁ , t₂) =
isProp× (θ₁ .prop propR s₁ t₁) (θ₂ .prop propR s₂ t₂)
productRelMatchesEquiv :
{S₁ : Type ℓ → Type ℓ₁} (ρ₁ : StrRel S₁ ℓ₁') {ι₁ : StrEquiv S₁ ℓ₁''}
{S₂ : Type ℓ → Type ℓ₂} (ρ₂ : StrRel S₂ ℓ₂') {ι₂ : StrEquiv S₂ ℓ₂''}
→ StrRelMatchesEquiv ρ₁ ι₁ → StrRelMatchesEquiv ρ₂ ι₂
→ StrRelMatchesEquiv (ProductRelStr ρ₁ ρ₂) (ProductEquivStr ι₁ ι₂)
productRelMatchesEquiv ρ₁ ρ₂ μ₁ μ₂ A B e =
Σ-cong-equiv (μ₁ _ _ e) (λ _ → μ₂ _ _ e)
productRelAction :
{S₁ : Type ℓ → Type ℓ₁} {ρ₁ : StrRel S₁ ℓ₁'} (α₁ : StrRelAction ρ₁)
{S₂ : Type ℓ → Type ℓ₂} {ρ₂ : StrRel S₂ ℓ₂'} (α₂ : StrRelAction ρ₂)
→ StrRelAction (ProductRelStr ρ₁ ρ₂)
productRelAction α₁ α₂ .actStr f (s₁ , s₂) = α₁ .actStr f s₁ , α₂ .actStr f s₂
productRelAction α₁ α₂ .actStrId (s₁ , s₂) = ΣPathP (α₁ .actStrId s₁ , α₂ .actStrId s₂)
productRelAction α₁ α₂ .actRel h _ _ (r₁ , r₂) = α₁ .actRel h _ _ r₁ , α₂ .actRel h _ _ r₂
productPositiveRel :
{S₁ : Type ℓ → Type ℓ₁} {ρ₁ : StrRel S₁ ℓ₁'} {θ₁ : SuitableStrRel S₁ ρ₁}
{S₂ : Type ℓ → Type ℓ₂} {ρ₂ : StrRel S₂ ℓ₂'} {θ₂ : SuitableStrRel S₂ ρ₂}
→ PositiveStrRel θ₁
→ PositiveStrRel θ₂
→ PositiveStrRel (productSuitableRel θ₁ θ₂)
productPositiveRel σ₁ σ₂ .act = productRelAction (σ₁ .act) (σ₂ .act)
productPositiveRel σ₁ σ₂ .reflexive (s₁ , s₂) = σ₁ .reflexive s₁ , σ₂ .reflexive s₂
productPositiveRel σ₁ σ₂ .detransitive R R' (rr'₁ , rr'₂) =
Trunc.rec squash
(λ {(s₁ , r₁ , r₁') →
Trunc.rec squash
(λ {(s₂ , r₂ , r₂') → ∣ (s₁ , s₂) , (r₁ , r₂) , (r₁' , r₂') ∣})
(σ₂ .detransitive R R' rr'₂)})
(σ₁ .detransitive R R' rr'₁)
productPositiveRel {S₁ = S₁} {ρ₁} {θ₁} {S₂} {ρ₂} {θ₂} σ₁ σ₂ .quo {X} R =
subst isEquiv
(funExt (elimProp (λ _ → productSuitableRel θ₁ θ₂ .set squash/ _ _) (λ _ → refl)))
(compEquiv
(isoToEquiv isom)
(Σ-cong-equiv (_ , σ₁ .quo R) (λ _ → _ , σ₂ .quo R)) .snd)
where
fwd :
ProductStructure S₁ S₂ X / ProductRelStr ρ₁ ρ₂ (R .fst .fst)
→ (S₁ X / ρ₁ (R .fst .fst)) × (S₂ X / ρ₂ (R .fst .fst))
fwd [ s₁ , s₂ ] = [ s₁ ] , [ s₂ ]
fwd (eq/ (s₁ , s₂) (t₁ , t₂) (r₁ , r₂) i) = eq/ s₁ t₁ r₁ i , eq/ s₂ t₂ r₂ i
fwd (squash/ _ _ p q i j) =
isSet× squash/ squash/ _ _ (cong fwd p) (cong fwd q) i j
bwd[] : S₁ X → S₂ X / ρ₂ (R .fst .fst)
→ ProductStructure S₁ S₂ X / ProductRelStr ρ₁ ρ₂ (R .fst .fst)
bwd[] s₁ [ s₂ ] = [ s₁ , s₂ ]
bwd[] s₁ (eq/ s₂ t₂ r₂ i) =
eq/ (s₁ , s₂) (s₁ , t₂) (posRelReflexive σ₁ R s₁ , r₂) i
bwd[] s₁ (squash/ _ _ p q i j) =
squash/ _ _ (λ j → bwd[] s₁ (p j)) (λ j → bwd[] s₁ (q j)) i j
bwd : S₁ X / ρ₁ (R .fst .fst) → S₂ X / ρ₂ (R .fst .fst)
→ ProductStructure S₁ S₂ X / ProductRelStr ρ₁ ρ₂ (R .fst .fst)
bwd [ s₁ ] u = bwd[] s₁ u
bwd (eq/ s₁ t₁ r₁ i) u = path u i
where
path : ∀ u → bwd [ s₁ ] u ≡ bwd [ t₁ ] u
path = elimProp (λ _ → squash/ _ _) (λ s₂ → eq/ (s₁ , s₂) (t₁ , s₂) (r₁ , posRelReflexive σ₂ R s₂))
bwd (squash/ _ _ p q i j) =
isSetΠ (λ _ → squash/) _ _ (cong bwd p) (cong bwd q) i j
open Iso
isom : Iso _ _
isom .fun = fwd
isom .inv = uncurry bwd
isom .rightInv =
uncurry
(elimProp (λ _ → isPropΠ λ _ → isSet× squash/ squash/ _ _)
(λ _ → elimProp (λ _ → isSet× squash/ squash/ _ _) (λ _ → refl)))
isom .leftInv = elimProp (λ _ → squash/ _ _) (λ _ → refl)
productRelMatchesTransp :
{S₁ : Type ℓ → Type ℓ₁} (ρ₁ : StrRel S₁ ℓ₁') (α₁ : EquivAction S₁)
{S₂ : Type ℓ → Type ℓ₂} (ρ₂ : StrRel S₂ ℓ₂') (α₂ : EquivAction S₂)
→ StrRelMatchesEquiv ρ₁ (EquivAction→StrEquiv α₁)
→ StrRelMatchesEquiv ρ₂ (EquivAction→StrEquiv α₂)
→ StrRelMatchesEquiv (ProductRelStr ρ₁ ρ₂) (EquivAction→StrEquiv (productEquivAction α₁ α₂))
productRelMatchesTransp _ _ _ _ μ₁ μ₂ _ _ e =
compEquiv (Σ-cong-equiv (μ₁ _ _ e) (λ _ → μ₂ _ _ e)) ΣPath≃PathΣ
| 42.539007 | 103 | 0.624875 |
c56259d3081466dece6b4dca258dda0683d95ef4 | 12,627 | agda | Agda | Examples.agda | luminousfennell/polybta | ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb | [
"BSD-3-Clause"
] | 1 | 2019-10-15T04:35:29.000Z | 2019-10-15T04:35:29.000Z | Examples.agda | luminousfennell/polybta | ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb | [
"BSD-3-Clause"
] | null | null | null | Examples.agda | luminousfennell/polybta | ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb | [
"BSD-3-Clause"
] | 1 | 2019-10-15T09:01:37.000Z | 2019-10-15T09:01:37.000Z | module Examples where
-- The terms of AExp assign a binding time to each subterm. For
-- program specialization, we interpret terms with dynamic binding
-- time as the programs subject to specialization, and their subterms
-- with static binding time as statically known inputs. A partial
-- evaluation function (or specializer) then compiles the program into
-- a residual term for that is specialized for the static inputs. The
-- main complication when defining partial evaluation as a total,
-- primitively recursive function will be the treatment of the De
-- Bruijn variables of non-closed residual expressions.
-- Before diving into the precise definition, it is instructive to
-- investigate the expected result of partial evaluation on some
-- examples.
{-
module AExp-Examples where
open import Data.Product
-- (We pre-define some De Bruijn indices to improve
-- readability of the examples:)
x : ∀ {α Δ} → AExp (α ∷ Δ) α
x = Var hd
y : ∀ {α₁ α Δ} → AExp (α₁ ∷ α ∷ Δ) α
y = Var (tl hd)
z : ∀ {α₁ α₂ α Δ} → AExp (α₁ ∷ α₂ ∷ α ∷ Δ) α
z = Var (tl (tl hd))
-- A very simple case is the addition of three constants, where one
-- is dynamically bound and two are bound statically:
-- 5D +D (30S +S 7S)
-- ex1 : AExp [] (D Int)
-- ex1 = DAdd (DInt 5) (AAdd (AInt 30) (AInt 7))
-- ex1' : AExp [] (D Int)
-- ex1' = AApp (ALam (DAdd (DInt 5) x)) (AApp (ALam (DInt x) (AInt 30) (AInt 7)))
-- TODO: this example does not work due to the very restrictive type
-- off Add/DAdd. We could add a subsumption operator to AExp that
-- turns a static expression into a dynamic one and then build a
-- smart constructor for addition on top of that
-- Note:This case is omitted in the same way as we impose the restriction that
-- a dynamic function can only have components which are also dynamic.
-- Another simple case is the specialization for a static identity
-- function:
-- (Sλ x → x) (42D) ---specializes to--> 42D
ex1 : AExp [] (D Int)
ex1 = AApp (ALam (Var hd)) (DInt 42)
ex1-spec : Exp [] Int
ex1-spec = EInt 42
-- The above example can be rewritten as an open AExp term that
-- should be closed with a suitable environment. This representation
-- does not only corresponds more directly with the notion of
-- ``static inputs'', it also illustrates a typical situation when
-- specializing the body of a lambda abstraction:
-- The program ex1' takes an Int→Int function x as a static input.
--ex1' : AExp [ AFun (D Int) (D Int) ] (D Int)
--ex1' = AApp x (DInt 42)
---------------------
-- Some more examples
---------------------
------------------
-- Pairs
------------------
------------------
-- a. Static Pairs
------------------
ex2 : AExp [] (D Int)
ex2 = Snd (AInt 42 , DInt 42)
ex3 : AExp [] (D Int)
ex3 = AApp (ALam (Snd (Var hd))) (AInt 42 , DInt 42)
-- similar to ex1'
--ex3' : AExp [ AFun (AInt • (D Int)) (D Int) ] (D Int)
--ex3' = AApp x (AInt 42 , DInt 42)
-------------------
-- b. Dynamic Pairs
-------------------
ex4 : AExp [] (D Int)
ex4 = AApp (ALam (DSnd (Var hd))) ( DInt 43 ḋ DInt 42)
-- similar to ex1'
--ex4' : AExp [ AFun (D (Int • Int)) (D Int) ] (D Int)
--ex4' = AApp x (DInt 43 ḋ DInt 42)
---------------------
-- Sums
---------------------
-----------------
-- a. Static Sums
-----------------
ex5 : AExp [] AInt
ex5 = Case {α₂ = AInt} (Tl (AInt 0)) (Var hd) (Var hd)
ex6 : AExp [] AInt
ex6 = Case {α₁ = AInt} (Tr (AInt 0)) (Var hd) (AInt 10)
ex7 : AExp [] (AFun AInt AInt)
ex7 = Case {α₂ = AInt} (Tl (ALam (Var hd))) (Var hd) (ALam (Var hd))
------------------
-- b. Dynamic Sums
------------------
ex8 : AExp [] (D Int)
ex8 = DCase {σ₂ = Int} (DTl (DInt 0)) (Var hd) (Var hd)
ex9 : AExp [] (D Int)
ex9 = DCase {σ₁ = Int} (DTr (DInt 0)) (Var hd) (DInt 10)
ex10 : AExp [] (D (Fun Int Int))
ex10 = DCase {σ₂ = Int} (DTl (DLam (Var hd))) (Var hd) (DLam (Var hd))
-- The partial evaluation of ex1' requires an environment to look up
-- the static input. As a first approximation, a single input of
-- type α is just some annotated term of type type α:
Input : ∀ α → Set
Input α = (∃ λ Δ → AExp Δ α)
----------------------------
-- alternative specification
----------------------------
--record Sg (S : Set) (T : S → Set) : Set where
-- constructor _,_
-- field
-- ffst : S
-- ssnd : T ffst
--open Sg public
--Input' : ∀ α → Set
--Input' α = Sg ACtx \ x → AExp x α
-- Note that [input'] should be equivalent to [input]
-- (convenience constructor for Inputs)
inp : ∀ {α Δ} → AExp Δ α → Input α
inp {α} {Δ} e = Δ , e
-- An environment is simply a list of inputs that agrees with a
-- given typing context.
data AEnv : ACtx → Set where
[] : AEnv []
_∷_ : ∀ {α Δ} → Input α → AEnv Δ → AEnv (α ∷ Δ)
lookup : ∀ {α Δ} → AEnv Δ → α ∈ Δ → Input α
lookup [] ()
lookup (x ∷ env) hd = x
lookup (x ∷ env) (tl id) = lookup env id
-- Thus, an environment like ex1'-env should be able to close ex1'
-- and a partial evaluation of the closure should yield the same
-- result as in example ex1:
--ex1'-env : AEnv [ AFun (D Int) (D Int) ]
--ex1'-env = inp (ALam {[]} {D Int} (Var hd)) ∷ []
-- Similarly, an environment like ex3'-env should be able to close ex3'
-- and a partial evaluation of the closure should yield the same
-- result as in example ex3:
--ex3'-env : AEnv [ AFun (AInt • (D Int)) (D Int) ]
--ex3'-env = inp (ALam {[]} {AInt • (D Int)} (Snd (Var hd))) ∷ []
-- Also, an environment like ex4'-env should be able to close ex4'
-- and a partial evaluation of the closure should yield the same
-- result as in example ex4:
--ex4'-env : AEnv [ AFun (D (Int • Int)) (D Int) ]
--ex4'-env = inp (ALam {[]} {D (Int • Int)} (DSnd (Var hd))) ∷ []
-- TODO: unit test
ex1'-spec = ex1-spec
ex3'-spec = ex1-spec
ex4'-spec = ex1-spec
-- (some definitions for the example)
open import Data.Maybe
_=<<_ : ∀ {A B : Set} → (A → Maybe B) → Maybe A → Maybe B
f =<< mx = maybe′ f nothing mx
liftM2 : ∀ {A B C : Set} → (A → B → Maybe C) → Maybe A → Maybe B → Maybe C
liftM2 f mx my = (λ x → (λ y → f x y) =<< my) =<< mx
-- The partial function ex1'-pe demonstrates the desired calculation
-- for the specific case of ex1':
ex1'-pe : ∀ {Δ} → AEnv Δ → AExp Δ (D Int) → Maybe (Exp [] Int)
ex1'-pe {Δ} env (AApp ef ei)
= liftM2 fromApp
(fromInput =<< fromVar ef)
(fromInt ei)
where fromInput : ∀ {α} → Input α → Maybe (Exp [] Int → Exp [] Int)
fromInput (_ , ALam {D Int} (Var hd)) = just (λ x → x)
-- Sλ x/D → x
fromInput _ = nothing
fromVar : ∀ {α} → AExp Δ α → Maybe (Input α)
fromVar (Var x) = just (lookup env x)
fromVar _ = nothing
fromApp : (Exp [] Int → Exp [] Int) → Exp [] Int → Maybe (Exp [] Int)
fromApp f x = just (f x)
fromInt : ∀ {α} → AExp Δ α → Maybe (Exp [] Int)
fromInt (DInt i) = just (EInt {[]} i)
fromInt _ = nothing
ex1'-pe _ _ = nothing
open import Relation.Binary.PropositionalEquality
check-ex1'-pe : ex1'-pe ex1'-env ex1' ≡ just (ex1'-spec)
check-ex1'-pe = refl
-- Similarly the partial function ex3'-pe demonstrates the desired calculation
-- for the specific case of ex3':
ex3'-pe : ∀ {Δ} → AEnv Δ → AExp Δ (D Int) → Maybe (Exp [] Int)
ex3'-pe {Δ} env (AApp ef ei)
= liftM2 fromApp
(fromInput =<< fromVar ef)
(fromPair ei)
where fromInput : ∀ {α} → Input α → Maybe ((ℕ * (Exp [] Int)) → Exp [] Int)
fromInput (_ , ALam {AInt • (D Int)} (Snd (Var hd))) = just (λ x → (snd x))
-- Sλ x/(S*D) → (snd x)
fromInput _ = nothing
fromVar : ∀ {α} → AExp Δ α → Maybe (Input α)
fromVar (Var x) = just (lookup env x)
fromVar _ = nothing
fromApp : ((ℕ * (Exp [] Int)) → Exp [] Int) → (ℕ * (Exp [] Int)) → Maybe (Exp [] Int)
fromApp f x = just (f x)
fromPair : ∀ {α} → AExp Δ α → Maybe (ℕ * (Exp [] Int))
fromPair ((AInt j) , (DInt i)) = just (j , (EInt {[]} i))
fromPair _ = nothing
ex3'-pe _ _ = nothing
open import Relation.Binary.PropositionalEquality
check-ex3'-pe : ex3'-pe ex3'-env ex3' ≡ just (ex3'-spec)
check-ex3'-pe = refl
-- Similarly the partial function ex3'-pe demonstrates the desired calculation
-- for the specific case of ex3':
ex4'-pe : ∀ {Δ} → AEnv Δ → AExp Δ (D Int) → Maybe (Exp [] Int)
ex4'-pe {Δ} env (AApp ef ei)
= liftM2 fromApp
(fromInput =<< fromVar ef)
(fromDPair ei)
where fromInput : ∀ {α} → Input α → Maybe (((Exp [] Int) * (Exp [] Int)) → Exp [] Int)
fromInput (_ , ALam {D (Int • Int)} (DSnd (Var hd))) = just (λ x → (snd x))
-- Sλ x/(S*D) → (snd x)
fromInput _ = nothing
fromVar : ∀ {α} → AExp Δ α → Maybe (Input α)
fromVar (Var x) = just (lookup env x)
fromVar _ = nothing
fromApp : (((Exp [] Int) * (Exp [] Int)) → Exp [] Int) → ((Exp [] Int) * (Exp [] Int)) → Maybe (Exp [] Int)
fromApp f x = just (f x)
fromDPair : ∀ {α} → AExp Δ α → Maybe ((Exp [] Int) * (Exp [] Int))
fromDPair ((DInt j) ḋ (DInt i)) = just ((EInt {[]} j) , (EInt {[]} i))
fromDPair _ = nothing
ex4'-pe _ _ = nothing
open import Relation.Binary.PropositionalEquality
check-ex4'-pe : ex4'-pe ex4'-env ex4' ≡ just (ex4'-spec)
check-ex4'-pe = refl
-- The examples above show several problems for a total
-- generalization to arbitrary term with the current datastructures:
-- - the argument to fromApp is not primitive recursive
-- What?
-- - the result type of fromInput generates the context of the returned expression
-- ``out of thin air''
-- - Note "out of thin air" in a sense that the "typing context for the value" is only restricted by
-- the value v itself thus any Δ which types v will do. Also note there is no connection between
-- "typing context for the value" and the "typing context"
-- TODO: continue
-- Dλ y → let f = λ x → x D+ y in Dλ z → f z
term1 : AExp [] (D (Fun Int (Fun Int Int)))
term1 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DAdd x y))))
-- Dλ y → let f = λ x → (Dλ w → x D+ y) in Dλ z → f z
-- Dλ y → (λ f → Dλ z → f z) (λ x → (Dλ w → x D+ y))
-- wrong
term2 : AExp [] (D (Fun Int (Fun Int Int)))
term2 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DLam {σ₁ = Int} (DAdd y z)))))
-- ?
term3 : AExp [] (D (Fun Int (Fun Int Int)))
term3 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
(DInt 0))
-- correct!
term4 : AExp [] (D (Fun Int (Fun Int (Fun Int Int))))
term4 = DLam (AApp (ALam (DLam (AApp y x)))
((ALam (DLam {σ₁ = Int} (DAdd y z)))))
------------------
-- Some more terms
------------------
-}
{-
module CheckExamples where
open import Relation.Binary.PropositionalEquality
open SimpleAEnv
open AExp-Examples
check-ex1 : pe ex1 [] ≡ ex1-spec
check-ex1 = refl
-------------
-- Similarly
------------
check-ex3 : pe ex3 [] ≡ ex1-spec
check-ex3 = refl
-------
-- Also
-------
check-ex4 : pe {Γ = []} ex4 [] ≡ ESnd (EInt 43 , EInt 42)
check-ex4 = refl
module Examples where
open SimpleAEnv
open import Relation.Binary.PropositionalEquality
x : ∀ {α Δ} → AExp (α ∷ Δ) α
x = Var hd
y : ∀ {α₁ α Δ} → AExp (α₁ ∷ α ∷ Δ) α
y = Var (tl hd)
z : ∀ {α₁ α₂ α Δ} → AExp (α₁ ∷ α₂ ∷ α ∷ Δ) α
z = Var (tl (tl hd))
-- Dλ y → let f = λ x → x D+ y in Dλ z → f z
term1 : AExp [] (D (Fun Int (Fun Int Int)))
term1 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DAdd x y))))
-- Dλ y → let f = λ x → (Dλ w → x D+ y) in Dλ z → f z
-- Dλ y → (λ f → Dλ z → f z) (λ x → (Dλ w → x D+ y))
term2 : AExp [] (D (Fun Int (Fun Int Int)))
term2 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DLam {σ₁ = Int} (DAdd y z)))))
-- closed pe. In contrast to BTA5, it is now not clear what Γ is
-- given an expression. So perhaps AEnv has it's merrits after all?
pe[] : ∀ {α} → AExp [] α → Imp [] α
pe[] e = pe e []
ex-pe-term1 : pe[] term1 ≡ ELam (ELam (EVar hd))
ex-pe-term1 = refl
ex-pe-term2 : pe[] term2 ≡ ELam (ELam (EVar hd))
ex-pe-term2 = refl
--------------------------
-- Tests on pairs and sums
--------------------------
-}
| 33.228947 | 118 | 0.548666 |
cb80acc682c4d5b3e2c5659c3042b44f5751e989 | 2,714 | agda | Agda | Type/WellOrdering.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | 6 | 2020-04-07T17:58:13.000Z | 2022-02-05T06:53:22.000Z | Type/WellOrdering.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | Type/WellOrdering.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | module Type.WellOrdering where
import Lvl
open import Functional
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Type
open import Type.Dependent
private variable ℓ ℓ₁ ℓ₂ : Lvl.Level
-- Types with terms that are well-founded trees.
-- Constructs types that are similar to some kind of tree.
-- The first parameter is the index for a constructor.
-- The second parameter is the arity for each constructor.
--
-- A type able to describe all non-dependent inductively defined data types assuming there are some previously defined types.
-- When described like this, the parameters should be interpreted as the following:
-- • The first parameter `A` indicates the "number" of branches based on another type's "cardinality" and should also contain the data for every branch.
-- • The second parameter `B` is used when the type to be defined refers to itself.
-- Examples:
-- open import Data
-- open import Data.Boolean
--
-- module _ (L R : Type{Lvl.𝟎}) where
-- E : Type{Lvl.𝟎}
-- E = W{A = Σ(Bool)(if_then R else L)}(const Empty) -- Either type using W.
-- l : L → E -- Left branch introduction.
-- l x = sup (intro 𝐹 x) empty
-- r : R → E -- Rght branch introduction.
-- r x = sup (intro 𝑇 x) empty
--
-- N = W{A = Bool}(if_then Unit{Lvl.𝟎} else Empty{Lvl.𝟎}) -- Natural numbers using W.
-- z : N -- Zero branch introduction.
-- z = sup 𝐹 empty
-- z' : _ → N -- Zero branch introduction (defined like this because empty functions are not unique (from no function extensionality) resulting in more than one zero for this definition of the natural numbers).
-- z' empty = sup 𝐹 empty
-- s : N → N -- Successor branch introduction.
-- s n = sup 𝑇 (\{<> → n})
-- e : ∀{P : N → Type{Lvl.𝟎}} → (∀{empty} → P(z empty)) → (∀{n} → P(n) → P(s n)) → (∀{n} → P(n)) -- TODO: Is this a correct eliminator? Note: It does not pass the termination checker
-- e pz ps {sup 𝐹 b} = pz
-- e pz ps {sup 𝑇 b} = ps (e pz (\{n} → ps{n}) {b <>})
record W {A : Type{ℓ₁}} (B : A → Type{ℓ₂}) : Type{ℓ₁ Lvl.⊔ ℓ₂} where
inductive
eta-equality
constructor sup
field
a : A
b : B(a) → W(B)
-- TODO: Is the type of this eliminator correct?
-- W-elim : ∀{A : Type{ℓ₁}}{B : A → Type{ℓ₂}}{P : W(B) → Type{ℓ}} → (∀{a : A}{b : B(a) → W(B)} → (∀{ba : B(a)} → P(b(ba))) → P(sup a b)) → (∀{w : W(B)} → P(w))
-- TODO: Note that this is essentially Sets.IterativeSet
V : ∀{ℓ₁} → Type{Lvl.𝐒(ℓ₁)}
V {ℓ₁} = W {A = Type{ℓ₁}} id
| 46.793103 | 256 | 0.585851 |
dcb907ecd92c2056250e5f430ae2cee52b44204e | 2,998 | agda | Agda | SOAS/Coalgebraic/Strength.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 39 | 2021-11-09T20:39:55.000Z | 2022-03-19T17:33:12.000Z | SOAS/Coalgebraic/Strength.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 1 | 2021-11-21T12:19:32.000Z | 2021-11-21T12:19:32.000Z | SOAS/Coalgebraic/Strength.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 4 | 2021-11-09T20:39:59.000Z | 2022-01-24T12:49:17.000Z |
-- Coalgebraic strength over an endofunctor
module SOAS.Coalgebraic.Strength {T : Set} where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core {T}
open import SOAS.Abstract.Hom {T}
import SOAS.Abstract.Coalgebra {T} as →□ ; open →□.Sorted
open import SOAS.Coalgebraic.Map
private
variable
Γ Δ Θ : Ctx
α : T
-- Pointed coalgebraic strength for a family endofunctor
record Strength (Fᶠ : Functor 𝔽amiliesₛ 𝔽amiliesₛ) : Set₁ where
open Functor Fᶠ
open Coalgₚ
field
-- Strength transformation that lifts a 𝒫-substitution over an endofunctor F₀
str : {𝒫 : Familyₛ}(𝒫ᴮ : Coalgₚ 𝒫)(𝒳 : Familyₛ)
→ F₀ 〖 𝒫 , 𝒳 〗 ⇾̣ 〖 𝒫 , F₀ 𝒳 〗
-- Naturality conditions for the two components
str-nat₁ : {𝒫 𝒬 𝒳 : Familyₛ}{𝒫ᴮ : Coalgₚ 𝒫}{𝒬ᴮ : Coalgₚ 𝒬}
→ {f : 𝒬 ⇾̣ 𝒫} (fᴮ⇒ : Coalgₚ⇒ 𝒬ᴮ 𝒫ᴮ f)
→ (h : F₀ 〖 𝒫 , 𝒳 〗 α Γ) (σ : Γ ~[ 𝒬 ]↝ Δ)
→ str 𝒫ᴮ 𝒳 h (f ∘ σ)
≡ str 𝒬ᴮ 𝒳 (F₁ (λ{ h′ ς → h′ (λ v → f (ς v))}) h) σ
str-nat₂ : {𝒫 𝒳 𝒴 : Familyₛ}{𝒫ᴮ : Coalgₚ 𝒫}
→ (f : 𝒳 ⇾̣ 𝒴)(h : F₀ 〖 𝒫 , 𝒳 〗 α Γ)(σ : Γ ~[ 𝒫 ]↝ Δ)
→ str 𝒫ᴮ 𝒴 (F₁ (λ{ h′ ς → f (h′ ς)}) h) σ
≡ F₁ f (str 𝒫ᴮ 𝒳 h σ)
-- Unit law
str-unit : (𝒳 : Familyₛ)(h : F₀ 〖 ℐ , 𝒳 〗 α Γ)
→ str ℐᴮ 𝒳 h id
≡ F₁ (i 𝒳) h
-- Associativity law for a particular pointed coalgebraic map f
str-assoc : (𝒳 : Familyₛ){𝒫 𝒬 ℛ : Familyₛ}
{𝒫ᴮ : Coalgₚ 𝒫} {𝒬ᴮ : Coalgₚ 𝒬} {ℛᴮ : Coalgₚ ℛ}
{f : 𝒫 ⇾̣ 〖 𝒬 , ℛ 〗}
(fᶜ : Coalgebraic 𝒫ᴮ 𝒬ᴮ ℛᴮ f) (open Coalgebraic fᶜ)
(h : F₀ 〖 ℛ , 𝒳 〗 α Γ)(σ : Γ ~[ 𝒫 ]↝ Δ)(ς : Δ ~[ 𝒬 ]↝ Θ)
→ str ℛᴮ 𝒳 h (λ v → f (σ v) ς)
≡ str 𝒬ᴮ 𝒳 (str 〖𝒫,𝒴〗ᴮ 〖 𝒬 , 𝒳 〗 (F₁ (L 𝒬 ℛ 𝒳) h) (f ∘ σ)) ς
module _ (𝒳 {𝒫 𝒬 ℛ} : Familyₛ) where
-- Precompose an internal hom by a parametrised map
precomp : (f : 𝒫 ⇾̣ 〖 𝒬 , ℛ 〗) → 〖 ℛ , 𝒳 〗 ⇾̣ 〖 𝒫 , 〖 𝒬 , 𝒳 〗 〗
precomp f h σ ς = h (λ v → f (σ v) ς)
-- Corollary: strength distributes over pointed coalgebraic maps
str-dist : {𝒫ᴮ : Coalgₚ 𝒫} {𝒬ᴮ : Coalgₚ 𝒬} {ℛᴮ : Coalgₚ ℛ}
{f : 𝒫 ⇾̣ 〖 𝒬 , ℛ 〗}
(fᶜ : Coalgebraic 𝒫ᴮ 𝒬ᴮ ℛᴮ f)
(h : F₀ 〖 ℛ , 𝒳 〗 α Γ)(σ : Γ ~[ 𝒫 ]↝ Δ)(ς : Δ ~[ 𝒬 ]↝ Θ)
→ str ℛᴮ 𝒳 h (λ v → f (σ v) ς)
≡ str 𝒬ᴮ 𝒳 (str 𝒫ᴮ 〖 𝒬 , 𝒳 〗 (F₁ (precomp f) h) σ) ς
str-dist {𝒫ᴮ = 𝒫ᴮ} {𝒬ᴮ} {ℛᴮ} {f} fᶜ h σ ς =
begin
str ℛᴮ 𝒳 h (λ v → f (σ v) ς)
≡⟨ str-assoc 𝒳 fᶜ h σ ς ⟩
str 𝒬ᴮ 𝒳 (str 〖𝒫,𝒴〗ᴮ 〖 𝒬 , 𝒳 〗 (F₁ (L 𝒬 ℛ 𝒳) h) (f ∘ σ)) ς
≡⟨ cong (λ - → str 𝒬ᴮ 𝒳 - ς) (str-nat₁ fᴮ⇒ (F₁ (L 𝒬 ℛ 𝒳) h) σ) ⟩
str 𝒬ᴮ 𝒳 (str 𝒫ᴮ 〖 𝒬 , 𝒳 〗 (F₁ 〖 f , 〖 𝒬 , 𝒳 〗 〗ₗ
(F₁ (L 𝒬 ℛ 𝒳) h)) σ) ς
≡˘⟨ cong (λ - → str 𝒬ᴮ 𝒳 (str 𝒫ᴮ 〖 𝒬 , 𝒳 〗 - σ) ς) homomorphism ⟩
str 𝒬ᴮ 𝒳 (str 𝒫ᴮ 〖 𝒬 , 𝒳 〗 (F₁ (precomp f) h) σ) ς
∎
where
open ≡-Reasoning
open Coalgebraic fᶜ renaming (ᴮ⇒ to fᴮ⇒)
| 35.690476 | 81 | 0.482655 |
df6f1ab752c44427862e0734ff3b82cabaec0830 | 1,715 | agda | Agda | old/Homotopy/Wedge.agda | AntoineAllioux/HoTT-Agda | 1037d82edcf29b620677a311dcfd4fc2ade2faa6 | [
"MIT"
] | 294 | 2015-01-09T16:23:23.000Z | 2022-03-20T13:54:45.000Z | old/Homotopy/Wedge.agda | AntoineAllioux/HoTT-Agda | 1037d82edcf29b620677a311dcfd4fc2ade2faa6 | [
"MIT"
] | 31 | 2015-03-05T20:09:00.000Z | 2021-10-03T19:15:25.000Z | old/Homotopy/Wedge.agda | AntoineAllioux/HoTT-Agda | 1037d82edcf29b620677a311dcfd4fc2ade2faa6 | [
"MIT"
] | 50 | 2015-01-10T01:48:08.000Z | 2022-02-14T03:03:25.000Z | {-# OPTIONS --without-K #-}
open import Base
open import Homotopy.Connected
{-
Wedge is a pushout.
-}
module Homotopy.Wedge
where
import Homotopy.Pushout as P
record wedge-diag i : Set (suc i) where
constructor diag_,_,_,_
field
A : Set i
B : Set i
a : A
b : B
f : unit {i} → A
f _ = a
g : unit {i} → B
g _ = b
wedge-diag-to-pushout-diag : ∀ {i} → wedge-diag i → P.pushout-diag i
wedge-diag-to-pushout-diag {i} (diag A , B , a , b) = P.diag A , B , unit {i} , (λ _ → a) , (λ _ → b)
wedge : ∀ {i} → wedge-diag i → Set i
wedge d = P.pushout (wedge-diag-to-pushout-diag d)
left : ∀ {i} {d : wedge-diag i} → wedge-diag.A d → wedge d
left = P.left
right : ∀ {i} {d : wedge-diag i} → wedge-diag.B d → wedge d
right = P.right
glue : ∀ {i} {d : wedge-diag i} → left (wedge-diag.a d) ≡ right (wedge-diag.b d)
glue = P.glue tt
wedge-rec : ∀ {i} {d : wedge-diag i}
→ let open wedge-diag d in
∀ {j} (P : wedge d → Set j)
(left* : ∀ a → P (left a))
(right* : ∀ b → P (right b))
(glue* : transport P glue (left* a) ≡ right* b)
→ (∀ x → P x)
wedge-rec P left* right* glue* = P.pushout-rec P left* right* (λ _ → glue*)
wedge-rec-nondep : ∀ {i} {d : wedge-diag i}
→ let open wedge-diag d in
∀ {j} (P : Set j)
(left* : ∀ a → P)
(right* : ∀ b → P)
(glue* : left* a ≡ right* b)
→ (wedge d → P)
wedge-rec-nondep P left* right* glue* = P.pushout-rec-nondep P left* right* (λ _ → glue*)
{-
module _ (f : X → Y) where
nA (A-is-conn : is-connected n A)
nB (B-is-conn : is-connected n B)
(P : A → B → Set k)
⦃ P-is-trunc : ∀ a b → is-connected (n +2+ m) (P a b) ⦄
extension :
-}
| 24.855072 | 103 | 0.528863 |
c56dfb936920b21f666733b2eb8dee04b800bd83 | 4,916 | agda | Agda | src/Data/Context.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | null | null | null | src/Data/Context.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | null | null | null | src/Data/Context.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Abstract typing contexts
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module Data.Context where
open import Data.Fin using (Fin)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Vec as Vec using (Vec; []; _∷_)
open import Relation.Unary using (Pred)
------------------------------------------------------------------------
-- Abstract typing contexts and context extensions.
infixr 5 _∷_
-- Typing contexts.
--
-- A |Ctx T n| is an indexed sequences of T-typed bindings mapping n
-- variables to T-types with 0 to (n - 1) free variables each. Like
-- lists (Data.List) and vectors (Data.Vec), contexts are cons
-- sequences, i.e. new bindings are added to the front (rather than
-- the back, as is more common in the literature). For example, a
-- typing context Γ represented in the usual notation as
--
-- Γ = xᵢ: Aᵢ, ..., x₁: A₁, x₀: A₀
--
-- is represented here by a term |Γ : Ctx Type i| of the form
--
-- Γ = A₀ ∷ A₁ ∷ ... ∷ Aᵢ
--
-- which is consistent with A₀ being the 0-th element of Γ, and with
-- the de Bruijn convention that the 0-th variable corresponds to the
-- closest binding.
data Ctx {ℓ} (T : Pred ℕ ℓ) : ℕ → Set ℓ where
[] : Ctx T zero
_∷_ : ∀ {n} → T n → Ctx T n → Ctx T (suc n)
module _ {ℓ} {T : Pred ℕ ℓ} where
head : ∀ {n} → Ctx T (suc n) → T n
head (t ∷ ts) = t
tail : ∀ {n} → Ctx T (suc n) → Ctx T n
tail (t ∷ ts) = ts
-- Drop the m innermost elements of a context Γ.
drop : ∀ {n} m → Ctx T (m + n) → Ctx T n
drop zero Γ = Γ
drop (suc m) (_ ∷ Γ) = drop m Γ
-- A map function that changes the entries in a context pointwise.
map : ∀ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {n} →
(∀ {k} → T₁ k → T₂ k) → Ctx T₁ n → Ctx T₂ n
map f [] = []
map f (t ∷ Γ) = f t ∷ map f Γ
-- Extensions of typing contexts.
--
-- Context extensions are indexed sequences of bindings that can be
-- concatenated to the front of a typing context. A |CtxExt T m n| is
-- an extension mapping n variables to T-types with m to (n + m - 1)
-- free variables each.
--
-- NOTE. It is tempting to define contexts as just a special case of
-- context extensions, i.e. as
--
-- Ctx T n = CtxExt T zero n
--
-- But this leads to problems when defining e.g. concatenation because
-- of the way context extensions are indexed. This could be remedied
-- by indexing context extensions differently, but then the definition
-- of |mapExt| below becomes difficult. An earlier version of this
-- module contained two different (but equivalent) representations for
-- context extensions, but this complicated (rather than simplified)
-- the development overall.
data CtxExt {ℓ} (T : Pred ℕ ℓ) (m : ℕ) : ℕ → Set ℓ where
[] : CtxExt T m zero
_∷_ : ∀ {l} → T (l + m) → CtxExt T m l → CtxExt T m (suc l)
infixr 5 _++_
-- Concatenation of context extensions with contexts.
_++_ : ∀ {ℓ} {T : Pred ℕ ℓ} {m n} → CtxExt T m n → Ctx T m → Ctx T (n + m)
[] ++ Γ = Γ
(t ∷ Δ) ++ Γ = t ∷ (Δ ++ Γ)
-- A map function that point-wise re-indexes and changes the entries
-- in a context extension.
mapExt : ∀ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {m n k} →
(∀ l → T₁ (l + m) → T₂ (l + n)) → CtxExt T₁ m k → CtxExt T₂ n k
mapExt f [] = []
mapExt f (_∷_ {l} t Γ) = f l t ∷ mapExt (λ l → f l) Γ
-- Operations on contexts that require weakening of types.
module WeakenOps {ℓ} {T : Pred ℕ ℓ} (extension : Extension T) where
-- Weakening of types.
open Extension extension public
-- Convert a context or context extension to its vector representation.
toVec : ∀ {n} → Ctx T n → Vec (T n) n
toVec [] = []
toVec (t ∷ Γ) = weaken t /∷ toVec Γ
extToVec : ∀ {k m n} → CtxExt T m n → Vec (T m) k → Vec (T (n + m)) (n + k)
extToVec [] ts = ts
extToVec (t ∷ Γ) ts = weaken t /∷ extToVec Γ ts
-- Lookup the type of a variable in a context or context extension.
lookup : ∀ {n} → Ctx T n → Fin n → T n
lookup Γ x = Vec.lookup (toVec Γ) x
extLookup : ∀ {k m n} → CtxExt T m n → Vec (T m) k → Fin (n + k) → T (n + m)
extLookup Δ ts x = Vec.lookup (extToVec Δ ts) x
-- Operations on contexts that require substitutions in types.
module SubstOps {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂}
(application : Application T₁ T₂)
(simple : Simple T₂)
where
open Application application public -- Application of T′ substitutions to Ts.
open Simple simple public -- Simple T′ substitutions.
-- Application of substitutions to context extensions.
_E/_ : ∀ {k m n} → CtxExt T₁ m k → Sub T₂ m n → CtxExt T₁ n k
Γ E/ σ = mapExt (λ l t → t / σ ↑⋆ l) Γ
| 33.671233 | 79 | 0.584011 |
106b204f6c9ad658a6b7b7b16272a8553bf07330 | 799 | agda | Agda | src/fot/FOTC/Program/ABP/PropertiesI.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 11 | 2015-09-03T20:53:42.000Z | 2021-09-12T16:09:54.000Z | src/fot/FOTC/Program/ABP/PropertiesI.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 2 | 2016-10-12T17:28:16.000Z | 2017-01-01T14:34:26.000Z | src/fot/FOTC/Program/ABP/PropertiesI.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 3 | 2016-09-19T14:18:30.000Z | 2018-03-14T08:50:00.000Z | ------------------------------------------------------------------------------
-- Common properties for the alternating bit protocol
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.ABP.PropertiesI where
open import FOTC.Base
open import FOTC.Program.ABP.ABP
------------------------------------------------------------------------------
-- Congruence properties
awaitCong₄ : ∀ {b i is ds₁ ds₂} → ds₁ ≡ ds₂ →
await b i is ds₁ ≡ await b i is ds₂
awaitCong₄ refl = refl
corruptCong : ∀ {os₁ os₂} → os₁ ≡ os₂ → corrupt os₁ ≡ corrupt os₂
corruptCong refl = refl
| 33.291667 | 78 | 0.444305 |
10381222abae558cfd1a3d3a5e6bf9cd74634bd7 | 1,065 | agda | Agda | src/17-promotion/Vector.agda | janat08/wiwinwlh | f7bce666068d5e08c5d1361c20ebc20e3a6dd25a | [
"BSD-Source-Code"
] | 2,479 | 2015-01-01T14:39:03.000Z | 2022-03-29T15:34:03.000Z | src/17-promotion/Vector.agda | janat08/wiwinwlh | f7bce666068d5e08c5d1361c20ebc20e3a6dd25a | [
"BSD-Source-Code"
] | 151 | 2015-01-16T07:43:41.000Z | 2021-06-29T15:20:06.000Z | src/17-promotion/Vector.agda | janat08/wiwinwlh | f7bce666068d5e08c5d1361c20ebc20e3a6dd25a | [
"BSD-Source-Code"
] | 339 | 2015-01-01T19:23:43.000Z | 2022-03-26T17:55:39.000Z | module Vector where
infixr 10 _∷_
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
infixl 6 _+_
_+_ : ℕ → ℕ → ℕ
0 + n = n
suc m + n = suc (m + n)
data Vec (A : Set) : ℕ → Set where
[] : Vec A 0
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
_++_ : ∀ {A n m} → Vec A n → Vec A m → Vec A (n + m)
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
infix 4 _≡_
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
subst : {A : Set} → (P : A → Set) → ∀{x y} → x ≡ y → P x → P y
subst P refl p = p
cong : {A B : Set} (f : A → B) → {x y : A} → x ≡ y → f x ≡ f y
cong f refl = refl
vec : ∀ {A} (k : ℕ) → Set
vec {A} k = Vec A k
plus_zero : {n : ℕ} → n + 0 ≡ n
plus_zero {zero} = refl
plus_zero {suc n} = cong suc plus_zero
plus_suc : {n : ℕ} → n + (suc 0) ≡ suc n
plus_suc {zero} = refl
plus_suc {suc n} = cong suc (plus_suc {n})
reverse : ∀ {A n} → Vec A n → Vec A n
reverse [] = []
reverse {A} {suc n} (x ∷ xs) = subst vec (plus_suc {n}) (reverse xs ++ (x ∷ []))
| 20.480769 | 80 | 0.478873 |
20c1da83edb91e6d905063a3f1da61df67ecc6a4 | 51,529 | agda | Agda | src/FOmegaInt/Syntax.agda | sstucki/f-omega-int-agda | ae648c9520895a8428a7ad80f47bb55ecf4d50ea | [
"MIT"
] | 12 | 2017-06-13T16:05:35.000Z | 2021-09-27T05:53:06.000Z | src/FOmegaInt/Syntax.agda | sstucki/f-omega-int-agda | ae648c9520895a8428a7ad80f47bb55ecf4d50ea | [
"MIT"
] | 1 | 2021-05-14T08:09:40.000Z | 2021-05-14T08:54:39.000Z | src/FOmegaInt/Syntax.agda | sstucki/f-omega-int-agda | ae648c9520895a8428a7ad80f47bb55ecf4d50ea | [
"MIT"
] | 2 | 2021-05-13T22:29:48.000Z | 2021-05-14T10:25:05.000Z | ------------------------------------------------------------------------
-- Syntax of Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Syntax where
open import Algebra using (Monoid)
import Data.Context as Context
open import Data.Context.Properties
open import Data.Fin using (Fin; suc; zero)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Fin.Substitution.Extra using (Extension)
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Nat using (ℕ; suc; zero)
open import Data.Product using (proj₂)
open import Data.Vec as Vec using ([]; _∷_)
open import Data.List as List using (List; []; _∷_; foldl; map; _++_; _∷ʳ_)
open import Data.List.Properties using (++-monoid)
import Data.Maybe as Maybe
open import Function using (_∘_)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_)
open import Relation.Binary.PropositionalEquality as P hiding ([_])
open P.≡-Reasoning
----------------------------------------------------------------------
-- Raw terms: untyped syntax of terms, types and kinds.
-- NOTE 1. Following the style of Pure Type System (PTS), we define
-- raw (i.e. untyped/unkinded) terms and types as a single syntactic
-- category rather than distinguishing them syntactically.
-- Concretely, we use the singe datatype Term to represent raw terms
-- and types. This simplifies the definition of substitution in types
-- and terms as we don't need to distinguish between type and term
-- variables. The difference between terms and types becomes manifest
-- only later in (sub-)typing and (sub-)kinding judgments. However,
-- unlike PTS, we *do* treat kinds as a separate syntactic
-- category/datatype because there are no kind variables. This
-- simplifies some definitions and proofs that rely on the syntactic
-- structure of kinds (e.g. kind simplification and related
-- properties).
--
-- NOTE 2. We use well-scoped de Bruijn indexing to represent term
-- and type variables in raw terms/types. The datatype `Term' is
-- indexed by the number of free variables its inhabitants may
-- contain, i.e. given a raw term
--
-- a : Term n
--
-- the set of "names" that may appear in `a' is
--
-- { 0, 1, ..., n-1 }.
--
-- Binders extend this set by increasing n by one for each fresh name
-- they introduce. This ensures that raw terms are intrinsically
-- well-scoped. This representation was adapted from previous Agda
-- formalizations of typed lambda calculi by Danielsson and others [1,
-- 2] and comes with some support in the Agda standard library. See
-- Data.Fin.Substitution.Example for a simple example.
--
-- [1] N. A. Danielsson and T. Altenkirch, "Subtyping, Declaratively
-- An Exercise in Mixed Induction and Coinduction", Proc. MPC
-- 2010.
--
-- [2] N. A. Danielsson, "Operational Semantics Using the Partiality
-- Monad", Proc. ICFP 2012.
module Syntax where
infixl 9 _·_ _⊡_ _⊡∙_
infixr 7 _⇒_ _⇒∙_
infix 6 _⋯_
-- Raw, T-dependent kinds with up to n free variables.
data Kind (T : ℕ → Set) (n : ℕ) : Set where
_⋯_ : (a b : T n) → Kind T n -- interval
Π : (j : Kind T n) (k : Kind T (suc n)) → Kind T n -- dependent arrow
-- Raw terms and types with up to n free variables.
--
-- NOTE. The type instantiation operator _⊡_ should be considered
-- specialized variant of the application operator _·_. The reason
-- for including a dedicated _⊡_ constructor is to distinguish term
-- applications from type applications/instantiations in CBV
-- reductions (see FOmegaInt.Reduction.Cbv). Without the special
-- treatment of type instantiation, CBV reduction would permit
-- reduction of type arguments before contraction. Not only is this
-- counter to the usual CBV semantics for Fω (see e.g. TAPL p. 450),
-- but it would require a proof of subject reduction (aka
-- preservation) for kinding in order to prove preservation of
-- typing even under CBV reduction. By adopting the usual CBV
-- semantics, this dependency can be avoided. See
-- FOmegaInt.Typing.Preservation for a proof of subject reduction
-- for typing using the usual CBV semantics.
data Term (n : ℕ) : Set where
var : (x : Fin n) → Term n -- variable
⊥ : Term n -- bottom (minimum)
⊤ : Term n -- top (maximum)
Π : (k : Kind Term n) (a : Term (suc n)) → Term n -- universal quant.
_⇒_ : (a b : Term n) → Term n -- arrow
Λ : (k : Kind Term n) (a : Term (suc n)) → Term n -- type abstraction
ƛ : (a : Term n) (b : Term (suc n)) → Term n -- term abstraction
_⊡_ : (a b : Term n) → Term n -- type instantiation
_·_ : (a b : Term n) → Term n -- term application
-- A shorthand for the kind of proper types.
* : ∀ {n} → Kind Term n
* = ⊥ ⋯ ⊤
infixl 9 _∙_
-- Raw terms and types in spine form.
--
-- Spine form is an alternative representation of raw terms where
-- the arguments of consecutive applications are grouped together
-- into sequences of arguments called "spines". This representation
-- is better suited for the definition of "hereditary substitution"
-- (see Syntax.HereditarySubstitution) and canonical kinding (see
-- Kinding.Canonical). The two representations are isomorphic, as
-- witnessed by ⌜⌝∘⌞⌟-id and ⌞⌟∘⌜⌝-id below.
--
-- NOTE. Below, we consider type instantiations (a ⊡ b) as heads
-- rather than eliminations, despite the fact that, semantically,
-- they are elimination forms. However, for the purpose of
-- hereditary substitution we will ignore their semantics and treat
-- _⊡_ as an uninterpreted binary operation. This is justified by
-- the fact that *well-kinded* hereditary substitution is only
-- defined on (well-kinded) types, in which _⊡_ cannot appear.
--
-- One may wonder: why include constructors for term-level forms
-- such as ƛ or _⊡_ in this presentation of the syntax if it is only
-- used to define type-level hereditary substitution? The answer is
-- that we often rely on the two presentations of the syntax being
-- isomorphic to switch between them without loss of generality. If
-- we only included type formers, we could not prove this
-- isomorphism. Including the term formers thus adds a bit of
-- overhead but simplifies things over all.
mutual
-- Eliminations are applications of (possibly empty) sequences of
-- arguments to heads.
data Elim (n : ℕ) : Set where
_∙_ : (a : Head n) (as : Spine n) → Elim n -- application
-- Heads are those terms that are not eliminations.
data Head (n : ℕ) : Set where
var : (x : Fin n) → Head n -- variable
⊥ : Head n -- bottom (minimum)
⊤ : Head n -- top (maximum)
Π : (k : Kind Elim n) (a : Elim (suc n)) → Head n -- universal
_⇒_ : (a b : Elim n) → Head n -- arrow
Λ : (k : Kind Elim n) (a : Elim (suc n)) → Head n -- type abstraction
ƛ : (a : Elim n) (b : Elim (suc n)) → Head n -- term abstraction
_⊡_ : (a b : Elim n) → Head n -- type inst.
-- Spines are (possibly empty) sequences of eliminations.
Spine : ℕ → Set
Spine n = List (Elim n)
-- Projections.
headOf : ∀ {n} → Elim n → Head n
headOf (a ∙ as) = a
spineOf : ∀ {n} → Elim n → Spine n
spineOf (a ∙ as) = as
infixl 9 _⌜·⌝_ _⌞∙⌟_ _∙∙_
-- Post-application of spines and eliminations to eliminations.
_∙∙_ : ∀ {n} → Elim n → Spine n → Elim n
a ∙ as ∙∙ bs = a ∙ (as ++ bs)
_⌜·⌝_ : ∀ {n} → Elim n → Elim n → Elim n
a ⌜·⌝ b = a ∙∙ (b ∷ [])
-- Application of term sequences to terms.
_⌞∙⌟_ : ∀ {n} → Term n → List (Term n) → Term n
a ⌞∙⌟ as = foldl _·_ a as
-- Shorthands for "unapplied" term/type constructors.
var∙ : ∀ {n} → Fin n → Elim n
var∙ x = var x ∙ []
⊥∙ : ∀ {n} → Elim n
⊥∙ = ⊥ ∙ []
⊤∙ : ∀ {n} → Elim n
⊤∙ = ⊤ ∙ []
∀∙ : ∀ {n} → Kind Elim n → Elim (suc n) → Elim n
∀∙ k a = Π k a ∙ []
_⇒∙_ : ∀ {n} → Elim n → Elim n → Elim n
a ⇒∙ b = (a ⇒ b) ∙ []
Λ∙ : ∀ {n} → Kind Elim n → Elim (suc n) → Elim n
Λ∙ k a = Λ k a ∙ []
ƛ∙ : ∀ {n} → Elim n → Elim (suc n) → Elim n
ƛ∙ a b = ƛ a b ∙ []
_⊡∙_ : ∀ {n} → Elim n → Elim n → Elim n
a ⊡∙ b = (a ⊡ b) ∙ []
⌜*⌝ : ∀ {n} → Kind Elim n
⌜*⌝ = ⊥∙ ⋯ ⊤∙
-- Conversions between the two representations.
mutual
-- Turn raw eliminations into raw terms.
⌞_⌟ : ∀ {n} → Elim n → Term n
⌞ a ∙ as ⌟ = ⌞ a ⌟Hd ⌞∙⌟ ⌞ as ⌟Sp
⌞_⌟Kd : ∀ {n} → Kind Elim n → Kind Term n
⌞ a ⋯ b ⌟Kd = ⌞ a ⌟ ⋯ ⌞ b ⌟
⌞ Π j k ⌟Kd = Π ⌞ j ⌟Kd ⌞ k ⌟Kd
⌞_⌟Sp : ∀ {n} → Spine n → List (Term n)
⌞ [] ⌟Sp = []
⌞ a ∷ as ⌟Sp = ⌞ a ⌟ ∷ ⌞ as ⌟Sp
⌞_⌟Hd : ∀ {n} → Head n → Term n
⌞ var x ⌟Hd = var x
⌞ ⊥ ⌟Hd = ⊥
⌞ ⊤ ⌟Hd = ⊤
⌞ Π k a ⌟Hd = Π ⌞ k ⌟Kd ⌞ a ⌟
⌞ a ⇒ b ⌟Hd = ⌞ a ⌟ ⇒ ⌞ b ⌟
⌞ Λ k a ⌟Hd = Λ ⌞ k ⌟Kd ⌞ a ⌟
⌞ ƛ a b ⌟Hd = ƛ ⌞ a ⌟ ⌞ b ⌟
⌞ a ⊡ b ⌟Hd = ⌞ a ⌟ ⊡ ⌞ b ⌟
mutual
-- Turn raw terms into raw eliminations.
⌜_⌝ : ∀ {n} → Term n → Elim n
⌜ var x ⌝ = var x ∙ []
⌜ ⊥ ⌝ = ⊥∙
⌜ ⊤ ⌝ = ⊤∙
⌜ Π k a ⌝ = ∀∙ ⌜ k ⌝Kd ⌜ a ⌝
⌜ a ⇒ b ⌝ = ⌜ a ⌝ ⇒∙ ⌜ b ⌝
⌜ Λ k a ⌝ = Λ∙ ⌜ k ⌝Kd ⌜ a ⌝
⌜ ƛ a b ⌝ = ƛ∙ ⌜ a ⌝ ⌜ b ⌝
⌜ a ⊡ b ⌝ = ⌜ a ⌝ ⊡∙ ⌜ b ⌝
⌜ a · b ⌝ = ⌜ a ⌝ ⌜·⌝ ⌜ b ⌝
⌜_⌝Kd : ∀ {n} → Kind Term n → Kind Elim n
⌜ a ⋯ b ⌝Kd = ⌜ a ⌝ ⋯ ⌜ b ⌝
⌜ Π j k ⌝Kd = Π ⌜ j ⌝Kd ⌜ k ⌝Kd
-- Shapes (aka simple kinds).
data SKind : Set where
★ : SKind
_⇒_ : SKind → SKind → SKind
-- Kind simplification (aka erasure from kinds to shapes).
⌊_⌋ : ∀ {T n} → Kind T n → SKind
⌊ a ⋯ b ⌋ = ★
⌊ Π j k ⌋ = ⌊ j ⌋ ⇒ ⌊ k ⌋
-- A wrapper for raw kind or type ascriptions.
data KdOrTp (T : ℕ → Set) (n : ℕ) : Set where
kd : Kind T n → KdOrTp T n
tp : T n → KdOrTp T n
TermAsc = KdOrTp Term
ElimAsc = KdOrTp Elim
⌞_⌟Asc : ∀ {n} → ElimAsc n → TermAsc n
⌞ kd k ⌟Asc = kd ⌞ k ⌟Kd
⌞ tp a ⌟Asc = tp ⌞ a ⌟
⌜_⌝Asc : ∀ {n} → TermAsc n → ElimAsc n
⌜ kd k ⌝Asc = kd ⌜ k ⌝Kd
⌜ tp a ⌝Asc = tp ⌜ a ⌝
open Syntax
----------------------------------------------------------------------
-- Some properties of raw terms and kinds
-- The kd constructor is injective.
kd-inj : ∀ {T n} {j k : Kind T n} → kd j ≡ kd k → j ≡ k
kd-inj refl = refl
-- Extensionality of eliminations.
∙-ext : ∀ {n} (a : Elim n) → headOf a ∙ spineOf a ≡ a
∙-ext (a ∙ as) = refl
-- The empty spine is a right unit of _∙∙_
∙∙-[] : ∀ {n} (a : Elim n) → a ∙∙ [] ≡ a
∙∙-[] (a ∙ as) = cong (a ∙_) (proj₂ identity as)
where open Monoid (++-monoid (Elim _)) hiding (_∙_)
-- Spine application commutes with spine concatenation.
∙∙-++ : ∀ {n} (a : Elim n) bs cs → a ∙∙ bs ∙∙ cs ≡ a ∙∙ (bs ++ cs)
∙∙-++ (a ∙ as) bs cs = cong (a ∙_) (assoc as bs cs)
where open Monoid (++-monoid (Elim _)) hiding (_∙_)
-- Spine application can be expressed as a left fold.
∙∙IsFold : ∀ {n} (a : Elim n) bs → a ∙∙ bs ≡ foldl _⌜·⌝_ a bs
∙∙IsFold (a ∙ as) [] = ∙∙-[] (a ∙ as)
∙∙IsFold (a ∙ as) (b ∷ bs) = begin
a ∙ (as ++ b ∷ bs)
≡⟨ sym (∙∙-++ (a ∙ as) (b ∷ []) bs) ⟩
a ∙ ((as ∷ʳ b) ++ bs)
≡⟨ ∙∙IsFold (a ∙ (as ∷ʳ b)) bs ⟩
foldl _⌜·⌝_ (a ∙ (as ∷ʳ b)) bs
∎
-- Conversion to raw terms commutes with (post-)application.
⌞⌟-· : ∀ {n} (a : Elim n) b → ⌞ a ⌜·⌝ b ⌟ ≡ ⌞ a ⌟ · ⌞ b ⌟
⌞⌟-· (a ∙ as) b = helper as b
where
helper : ∀ {n} {a : Term n} bs c →
a ⌞∙⌟ ⌞ bs ∷ʳ c ⌟Sp ≡ a ⌞∙⌟ ⌞ bs ⌟Sp · ⌞ c ⌟
helper [] c = refl
helper (b ∷ bs) c = helper bs c
⌞⌟-∙∙ : ∀ {n} (a : Elim n) bs → ⌞ a ∙∙ bs ⌟ ≡ ⌞ a ⌟ ⌞∙⌟ ⌞ bs ⌟Sp
⌞⌟-∙∙ a [] = cong ⌞_⌟ (∙∙-[] a)
⌞⌟-∙∙ a (b ∷ bs) = begin
⌞ a ∙∙ (b ∷ bs) ⌟ ≡⟨ sym (cong ⌞_⌟ (∙∙-++ a (b ∷ []) bs)) ⟩
⌞ a ∙∙ (b ∷ []) ∙∙ bs ⌟ ≡⟨ ⌞⌟-∙∙ (a ∙∙ (b ∷ [])) bs ⟩
⌞ a ∙∙ (b ∷ []) ⌟ ⌞∙⌟ ⌞ bs ⌟Sp ≡⟨ cong (_⌞∙⌟ ⌞ bs ⌟Sp) (⌞⌟-· a b) ⟩
⌞ a ⌟ · ⌞ b ⌟ ⌞∙⌟ ⌞ bs ⌟Sp ∎
-- Conversion to eliminations commutes with spine application.
⌜⌝-∙ : ∀ {n} (a : Term n) bs → ⌜ a ⌞∙⌟ bs ⌝ ≡ ⌜ a ⌝ ∙∙ map ⌜_⌝ bs
⌜⌝-∙ a bs = begin
⌜ a ⌞∙⌟ bs ⌝ ≡⟨ helper a bs ⟩
foldl _⌜·⌝_ ⌜ a ⌝ (map ⌜_⌝ bs) ≡⟨ sym (∙∙IsFold ⌜ a ⌝ (map ⌜_⌝ bs)) ⟩
⌜ a ⌝ ∙∙ map ⌜_⌝ bs ∎
where
helper : ∀ {n} (a : Term n) bs →
⌜ a ⌞∙⌟ bs ⌝ ≡ foldl _⌜·⌝_ ⌜ a ⌝ (map ⌜_⌝ bs)
helper a [] = refl
helper a (b ∷ bs) = helper (a · b) bs
-- The two representations of raw terms are isomorphic.
mutual
⌞⌟∘⌜⌝-id : ∀ {n} (a : Term n) → ⌞ ⌜ a ⌝ ⌟ ≡ a
⌞⌟∘⌜⌝-id (var x) = refl
⌞⌟∘⌜⌝-id ⊥ = refl
⌞⌟∘⌜⌝-id ⊤ = refl
⌞⌟∘⌜⌝-id (Π k a) = cong₂ Π (⌞⌟Kd∘⌜⌝Kd-id k) (⌞⌟∘⌜⌝-id a)
⌞⌟∘⌜⌝-id (a ⇒ b) = cong₂ _⇒_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)
⌞⌟∘⌜⌝-id (Λ k a) = cong₂ Λ (⌞⌟Kd∘⌜⌝Kd-id k) (⌞⌟∘⌜⌝-id a)
⌞⌟∘⌜⌝-id (ƛ a b) = cong₂ ƛ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)
⌞⌟∘⌜⌝-id (a ⊡ b) = cong₂ _⊡_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)
⌞⌟∘⌜⌝-id (a · b) = begin
⌞ ⌜ a ⌝ ⌜·⌝ ⌜ b ⌝ ⌟ ≡⟨ ⌞⌟-· ⌜ a ⌝ ⌜ b ⌝ ⟩
⌞ ⌜ a ⌝ ⌟ · ⌞ ⌜ b ⌝ ⌟ ≡⟨ cong₂ _·_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b) ⟩
a · b ∎
⌞⌟Kd∘⌜⌝Kd-id : ∀ {n} (k : Kind Term n) → ⌞ ⌜ k ⌝Kd ⌟Kd ≡ k
⌞⌟Kd∘⌜⌝Kd-id (a ⋯ b) = cong₂ _⋯_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)
⌞⌟Kd∘⌜⌝Kd-id (Π j k) = cong₂ Π (⌞⌟Kd∘⌜⌝Kd-id j) (⌞⌟Kd∘⌜⌝Kd-id k)
mutual
⌜⌝∘⌞⌟-id : ∀ {n} (a : Elim n) → ⌜ ⌞ a ⌟ ⌝ ≡ a
⌜⌝∘⌞⌟-id (a ∙ bs) = begin
⌜ ⌞ a ⌟Hd ⌞∙⌟ ⌞ bs ⌟Sp ⌝
≡⟨ ⌜⌝-∙ ⌞ a ⌟Hd ⌞ bs ⌟Sp ⟩
⌜ ⌞ a ⌟Hd ⌝ ∙∙ map ⌜_⌝ ⌞ bs ⌟Sp
≡⟨ cong₂ _∙∙_ (⌜⌝∘⌞⌟Hd-∙-[] a) (map-⌜⌝∘⌞⌟Sp-id bs) ⟩
a ∙ [] ∙∙ bs
∎
map-⌜⌝∘⌞⌟Sp-id : ∀ {n} (as : Spine n) → map ⌜_⌝ ⌞ as ⌟Sp ≡ as
map-⌜⌝∘⌞⌟Sp-id [] = refl
map-⌜⌝∘⌞⌟Sp-id (a ∷ as) = cong₂ _∷_ (⌜⌝∘⌞⌟-id a) (map-⌜⌝∘⌞⌟Sp-id as)
⌜⌝∘⌞⌟Hd-∙-[] : ∀ {n} (a : Head n) → ⌜ ⌞ a ⌟Hd ⌝ ≡ a ∙ []
⌜⌝∘⌞⌟Hd-∙-[] (var x) = refl
⌜⌝∘⌞⌟Hd-∙-[] ⊥ = refl
⌜⌝∘⌞⌟Hd-∙-[] ⊤ = refl
⌜⌝∘⌞⌟Hd-∙-[] (Π k a) = cong₂ ∀∙ (⌜⌝Kd∘⌞⌟Kd-id k) (⌜⌝∘⌞⌟-id a)
⌜⌝∘⌞⌟Hd-∙-[] (a ⇒ b) = cong₂ _⇒∙_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)
⌜⌝∘⌞⌟Hd-∙-[] (Λ k a) = cong₂ Λ∙ (⌜⌝Kd∘⌞⌟Kd-id k) (⌜⌝∘⌞⌟-id a)
⌜⌝∘⌞⌟Hd-∙-[] (ƛ a b) = cong₂ ƛ∙ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)
⌜⌝∘⌞⌟Hd-∙-[] (a ⊡ b) = cong₂ _⊡∙_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)
⌜⌝Kd∘⌞⌟Kd-id : ∀ {n} (k : Kind Elim n) → ⌜ ⌞ k ⌟Kd ⌝Kd ≡ k
⌜⌝Kd∘⌞⌟Kd-id (a ⋯ b) = cong₂ _⋯_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)
⌜⌝Kd∘⌞⌟Kd-id (Π j k) = cong₂ Π (⌜⌝Kd∘⌞⌟Kd-id j) (⌜⌝Kd∘⌞⌟Kd-id k)
-- Simplified kinds are stable under conversions of term
-- representation.
⌊⌋-⌜⌝Kd : ∀ {n} (k : Kind Term n) → ⌊ ⌜ k ⌝Kd ⌋ ≡ ⌊ k ⌋
⌊⌋-⌜⌝Kd (a ⋯ b) = refl
⌊⌋-⌜⌝Kd (Π j k) = cong₂ _⇒_ (⌊⌋-⌜⌝Kd j) (⌊⌋-⌜⌝Kd k)
⌊⌋-⌞⌟Kd : ∀ {n} (k : Kind Elim n) → ⌊ ⌞ k ⌟Kd ⌋ ≡ ⌊ k ⌋
⌊⌋-⌞⌟Kd (a ⋯ b) = refl
⌊⌋-⌞⌟Kd (Π j k) = cong₂ _⇒_ (⌊⌋-⌞⌟Kd j) (⌊⌋-⌞⌟Kd k)
----------------------------------------------------------------------
-- Substitutions in raw terms
--
-- We use an intrinsically well-scoped variant of simultaneous
-- substitutions inspired by McBride's technique for defining
-- type-preserving substitutions [3]. These come with some support in
-- the Agda standard library. In particular, the standard library
-- provides generic proofs for a plethora of standard untyped
-- substitution lemmas (e.g. substitutions commute, identity
-- substitutions vanish, etc.) which are easy but tedious to prove
-- (see the Data.Fin.Substitution.Lemmas module). By using this
-- substitution framework, we get those lemmas for "free" (we still
-- need to provide some basic lemmas to bootstrap everything).
--
-- To use the standard framework, we must follow the following four
-- steps.
--
-- 1. We define an application function `t / σ' of generic untyped
-- substitutions `σ' to well-scoped untyped terms `t'. Generic
-- substitutions are defined over an abstract type `T', which will
-- later represent variables (to encode renamings) or terms (to
-- encode actual substitutions). Hence the definition of
-- application must be parametrized over some abstract operations
-- on such substitutions (lifting, weakening, etc.) to be defined
-- later. Concrete instances of these operations are collected in
-- the record `Lift' (see e.g. `SubstApp' module below).
--
-- Along with application, we define a few lemmas to be used in
-- step 4. (They express the fact that application of
-- (multi-)substitutions is compositional w.r.t. the various
-- syntactic forms.)
--
-- 2. Application is instantiated with `T = Fin' to obtain
-- well-scoped renamings, i.e. substitutions of variables in
-- terms. The standard library provides a predefined instance of
-- `Lift Fin Term' to this end.
--
-- 3. Using well-scoped renamings, an instance of `Lift Term Term' is
-- defined, and application is instantiated to concrete
-- substitutions of terms in terms.
--
-- 4. Using the generic lemmas defined in step 1, many helpful
-- derived substitution lemmas are instantiated.
-- (E.g. "substitutions commute", "identity substitutions vanish",
-- etc.)
--
-- Most of the work is done in step 1, while steps 2-3 consists mostly
-- in calls to the substitution API of the Agda standard library.
--
-- [3] C. McBride, "Type-Preserving Renaming and Substitution"
-- http://strictlypositive.org/ren-sub.pdf
-- Application of generic substitutions lifted to type and kind
-- ascriptions.
module KdOrTpSubstApp {T T′ : ℕ → Set} (simple : Simple T)
(kdApp : Application (Kind T′) T)
(tpApp : Application T′ T) where
open Simple simple
open Application kdApp renaming (_/_ to _Kd/_; _/✶_ to _Kd/✶_)
open Application tpApp renaming (_/_ to _Tp/_; _/✶_ to _Tp/✶_)
infixl 8 _/_
-- Apply a substitution to a kind or type ascription.
_/_ : ∀ {m n} → KdOrTp T′ m → Sub T m n → KdOrTp T′ n
(kd k) / σ = kd (k Kd/ σ)
(tp a) / σ = tp (a Tp/ σ)
open Application (record { _/_ = _/_ }) public hiding (_/_)
-- Some helper lemmas about applying sequences of substitutions (to
-- be used for instantiating TermSubstLemmas).
-- Substitutions in kind ascriptions are compositional.
kd-/✶-↑✶ : ∀ k {m n j} (σs : Subs T m n) →
(kd j) /✶ σs ↑✶ k ≡ kd (j Kd/✶ σs ↑✶ k)
kd-/✶-↑✶ k ε = refl
kd-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (kd-/✶-↑✶ k σs) refl
-- Substitutions in type ascriptions are compositional.
tp-/✶-↑✶ : ∀ k {m n a} (σs : Subs T m n) →
(tp a) /✶ σs ↑✶ k ≡ tp (a Tp/✶ σs ↑✶ k)
tp-/✶-↑✶ k ε = refl
tp-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (tp-/✶-↑✶ k σs) refl
-- Application of generic substitutions to terms
module SubstApp {T : ℕ → Set} (l : Lift T Term) where
open Lift l hiding (var)
infixl 8 _/_ _Kind/_ _Elim/_ _Head/_ _//_ _Kind′/_
mutual
-- Apply a substitution to a raw term/type.
_/_ : ∀ {m n} → Term m → Sub T m n → Term n
var x / σ = lift (Vec.lookup σ x)
⊥ / σ = ⊥
⊤ / σ = ⊤
Π k a / σ = Π (k Kind/ σ) (a / σ ↑)
(a ⇒ b) / σ = (a / σ) ⇒ (b / σ)
Λ k a / σ = Λ (k Kind/ σ) (a / σ ↑)
ƛ a b / σ = ƛ (a / σ) (b / σ ↑)
a · b / σ = (a / σ) · (b / σ)
a ⊡ b / σ = (a / σ) ⊡ (b / σ)
-- Apply a substitution to a kind.
_Kind/_ : ∀ {m n} → Kind Term m → Sub T m n → Kind Term n
(a ⋯ b) Kind/ σ = (a / σ) ⋯ (b / σ)
Π j k Kind/ σ = Π (j Kind/ σ) (k Kind/ σ ↑)
mutual
-- Apply a substitution to an elimination.
_Elim/_ : ∀ {m n} → Elim m → Sub T m n → Elim n
a ∙ as Elim/ σ = (a Head/ σ) ∙∙ (as // σ)
-- Apply a substitution to a head.
_Head/_ : ∀ {m n} → Head m → Sub T m n → Elim n
var x Head/ σ = ⌜ lift (Vec.lookup σ x) ⌝
⊥ Head/ σ = ⊥∙
⊤ Head/ σ = ⊤∙
Π k a Head/ σ = ∀∙ (k Kind′/ σ) (a Elim/ σ ↑)
(a ⇒ b) Head/ σ = (a Elim/ σ) ⇒∙ (b Elim/ σ)
Λ k a Head/ σ = Λ∙ (k Kind′/ σ) (a Elim/ σ ↑)
ƛ a b Head/ σ = ƛ∙ (a Elim/ σ) (b Elim/ σ ↑)
a ⊡ b Head/ σ = (a Elim/ σ) ⊡∙ (b Elim/ σ)
-- Apply a substitution to a spine.
_//_ : ∀ {m n} → Spine m → Sub T m n → Spine n
[] // σ = []
(a ∷ as) // σ = a Elim/ σ ∷ as // σ
-- Apply a substitution to a (elimination-based) kind.
_Kind′/_ : ∀ {m n} → Kind Elim m → Sub T m n → Kind Elim n
(a ⋯ b) Kind′/ σ = (a Elim/ σ) ⋯ (b Elim/ σ)
Π j k Kind′/ σ = Π (j Kind′/ σ) (k Kind′/ σ ↑)
private
appTerm = record { _/_ = _/_ }
appKind = record { _/_ = _Kind/_ }
appElim = record { _/_ = _Elim/_ }
appKind′ = record { _/_ = _Kind′/_ }
-- Some helper lemmas about applying sequences of substitutions (to
-- be used for instantiating TermSubstLemmas).
open Application appTerm hiding (_/_)
open Application appKind using () renaming (_/✶_ to _Kind/✶_)
-- The bottom and top types are invariant under substitution.
⊥-/✶-↑✶ : ∀ k {m n} (σs : Subs T m n) → ⊥ /✶ σs ↑✶ k ≡ ⊥
⊥-/✶-↑✶ k ε = refl
⊥-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊥-/✶-↑✶ k σs) refl
⊤-/✶-↑✶ : ∀ k {m n} (σs : Subs T m n) → ⊤ /✶ σs ↑✶ k ≡ ⊤
⊤-/✶-↑✶ k ε = refl
⊤-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊤-/✶-↑✶ k σs) refl
-- Substitutions in the remaining term and type formers are
-- compositional.
Π-/✶-↑✶ : ∀ k {m n j a} (σs : Subs T m n) →
(Π j a) /✶ σs ↑✶ k ≡ Π (j Kind/✶ σs ↑✶ k) (a /✶ σs ↑✶ suc k)
Π-/✶-↑✶ k ε = refl
Π-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (Π-/✶-↑✶ k σs) refl
⇒-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(a ⇒ b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⇒ (b /✶ σs ↑✶ k)
⇒-/✶-↑✶ k ε = refl
⇒-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⇒-/✶-↑✶ k σs) refl
Λ-/✶-↑✶ : ∀ k {m n j a} (σs : Subs T m n) →
(Λ j a) /✶ σs ↑✶ k ≡ Λ (j Kind/✶ σs ↑✶ k) (a /✶ σs ↑✶ suc k)
Λ-/✶-↑✶ k ε = refl
Λ-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (Λ-/✶-↑✶ k σs) refl
ƛ-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(ƛ a b) /✶ σs ↑✶ k ≡ ƛ (a /✶ σs ↑✶ k) (b /✶ σs ↑✶ suc k)
ƛ-/✶-↑✶ k ε = refl
ƛ-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (ƛ-/✶-↑✶ k σs) refl
·-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(a · b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) · (b /✶ σs ↑✶ k)
·-/✶-↑✶ k ε = refl
·-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (·-/✶-↑✶ k σs) refl
⊡-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(a ⊡ b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⊡ (b /✶ σs ↑✶ k)
⊡-/✶-↑✶ k ε = refl
⊡-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊡-/✶-↑✶ k σs) refl
-- Substitutions in the kind formers are compositional.
Π-Kind/✶-↑✶ : ∀ k {m n j l} (σs : Subs T m n) →
(Π j l) Kind/✶ σs ↑✶ k ≡
Π (j Kind/✶ σs ↑✶ k) (l Kind/✶ σs ↑✶ (suc k))
Π-Kind/✶-↑✶ k ε = refl
Π-Kind/✶-↑✶ k (σ ◅ σs) = cong₂ _Kind/_ (Π-Kind/✶-↑✶ k σs) refl
⋯-Kind/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(a ⋯ b) Kind/✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⋯ (b /✶ σs ↑✶ k)
⋯-Kind/✶-↑✶ k ε = refl
⋯-Kind/✶-↑✶ k (σ ◅ σs) = cong₂ _Kind/_ (⋯-Kind/✶-↑✶ k σs) refl
-- Application of substitutions commutes with concatenation of spines.
++-// : ∀ {m n} (as bs : Spine m) {σ : Sub T m n} →
(as ++ bs) // σ ≡ as // σ ++ bs // σ
++-// [] bs = refl
++-// (a ∷ as) bs = cong (a Elim/ _ ∷_) (++-// as bs)
-- Application of substitutions commutes application of spines and
-- eliminations.
∙∙-/ : ∀ {m n} a (as : Spine m) {σ : Sub T m n} →
a ∙∙ as Elim/ σ ≡ (a Elim/ σ) ∙∙ (as // σ)
∙∙-/ (a ∙ as) bs = begin
(a Head/ _) ∙∙ ((as ++ bs) // _)
≡⟨ cong (_ ∙∙_) (++-// as bs) ⟩
(a Head/ _) ∙∙ (as // _ ++ bs // _)
≡⟨ sym (∙∙-++ _ (as // _) (bs // _)) ⟩
(a Head/ _) ∙∙ (as // _) ∙∙ (bs // _)
∎
⌜·⌝-/ : ∀ {m n} (a b : Elim m) {σ : Sub T m n} →
a ⌜·⌝ b Elim/ σ ≡ (a Elim/ σ) ⌜·⌝ (b Elim/ σ)
⌜·⌝-/ (a ∙ as) b {σ} = begin
(a Head/ σ) ∙∙ ((as ∷ʳ b) // σ)
≡⟨ cong ((a Head/ σ) ∙∙_) (++-// as (b ∷ [])) ⟩
(a Head/ σ) ∙∙ (as // σ ++ (b ∷ []) // σ)
≡⟨ sym (∙∙-++ (a Head/ σ) (as // σ) ((b ∷ []) // σ)) ⟩
(a Head/ σ) ∙∙ (as // σ) ∙∙ ((b ∷ []) // σ)
≡⟨ ∙∙IsFold ((a Head/ σ) ∙∙ (as // σ)) ((b ∷ []) // σ) ⟩
(a Head/ σ) ∙∙ (as // σ) ⌜·⌝ (b Elim/ σ)
∎
-- Application of substitutions commutes with the conversions.
mutual
⌜⌝-/ : ∀ {m n} a {σ : Sub T m n} → ⌜ a / σ ⌝ ≡ ⌜ a ⌝ Elim/ σ
⌜⌝-/ (var x) = sym (∙∙-[] _)
⌜⌝-/ ⊥ = refl
⌜⌝-/ ⊤ = refl
⌜⌝-/ (Π k a) = cong₂ ∀∙ (⌜⌝Kd-/ k) (⌜⌝-/ a)
⌜⌝-/ (a ⇒ b) = cong₂ _⇒∙_ (⌜⌝-/ a) (⌜⌝-/ b)
⌜⌝-/ (Λ k a) = cong₂ Λ∙ (⌜⌝Kd-/ k) (⌜⌝-/ a)
⌜⌝-/ (ƛ a b) = cong₂ ƛ∙ (⌜⌝-/ a) (⌜⌝-/ b)
⌜⌝-/ (a · b) {σ} = begin
⌜ a / σ ⌝ ⌜·⌝ ⌜ b / σ ⌝ ≡⟨ cong₂ _⌜·⌝_ (⌜⌝-/ a) (⌜⌝-/ b) ⟩
(⌜ a ⌝ Elim/ σ) ⌜·⌝ (⌜ b ⌝ Elim/ σ) ≡⟨ sym (⌜·⌝-/ ⌜ a ⌝ ⌜ b ⌝) ⟩
⌜ a ⌝ ⌜·⌝ ⌜ b ⌝ Elim/ σ ∎
⌜⌝-/ (a ⊡ b) = cong₂ _⊡∙_ (⌜⌝-/ a) (⌜⌝-/ b)
⌜⌝Kd-/ : ∀ {m n} k {σ : Sub T m n} → ⌜ k Kind/ σ ⌝Kd ≡ ⌜ k ⌝Kd Kind′/ σ
⌜⌝Kd-/ (a ⋯ b) = cong₂ _⋯_ (⌜⌝-/ a) (⌜⌝-/ b)
⌜⌝Kd-/ (Π j k) = cong₂ Π (⌜⌝Kd-/ j) (⌜⌝Kd-/ k)
⌞⌟-/ : ∀ {m n} a {σ : Sub T m n} → ⌞ a Elim/ σ ⌟ ≡ ⌞ a ⌟ / σ
⌞⌟-/ a {σ} = begin
⌞ a Elim/ σ ⌟ ≡⟨ cong (⌞_⌟ ∘ (_Elim/ σ)) (sym (⌜⌝∘⌞⌟-id a)) ⟩
⌞ ⌜ ⌞ a ⌟ ⌝ Elim/ σ ⌟ ≡⟨ cong ⌞_⌟ (sym (⌜⌝-/ ⌞ a ⌟)) ⟩
⌞ ⌜ ⌞ a ⌟ / σ ⌝ ⌟ ≡⟨ ⌞⌟∘⌜⌝-id (⌞ a ⌟ / σ) ⟩
⌞ a ⌟ / σ ∎
⌞⌟Kd-/ : ∀ {m n} k {σ : Sub T m n} → ⌞ k Kind′/ σ ⌟Kd ≡ ⌞ k ⌟Kd Kind/ σ
⌞⌟Kd-/ (a ⋯ b) = cong₂ _⋯_ (⌞⌟-/ a) (⌞⌟-/ b)
⌞⌟Kd-/ (Π j k) = cong₂ Π (⌞⌟Kd-/ j) (⌞⌟Kd-/ k)
open Application appElim using () renaming (_/✶_ to _Elim/✶_)
open Application appKind′ using () renaming (_/✶_ to _Kind′/✶_)
-- Application of multiple substitutions commutes with conversion to
-- eliminations.
⌜⌝-/✶-↑✶ : ∀ k {m n a} (σs : Subs T m n) →
⌜ a /✶ σs ↑✶ k ⌝ ≡ ⌜ a ⌝ Elim/✶ σs ↑✶ k
⌜⌝-/✶-↑✶ k ε = refl
⌜⌝-/✶-↑✶ k (σ ◅ σs) = begin
⌜ _ /✶ (σ ◅ σs) ↑✶ k ⌝ ≡⟨ ⌜⌝-/ (_ /✶ σs ↑✶ k) ⟩
⌜ _ /✶ σs ↑✶ k ⌝ Elim/ σ ↑⋆ k ≡⟨ cong (_Elim/ _) (⌜⌝-/✶-↑✶ k σs) ⟩
_ Elim/✶ (σ ◅ σs) ↑✶ k ∎
⌜⌝Kd-/✶-↑✶ : ∀ k {m n j} (σs : Subs T m n) →
⌜ j Kind/✶ σs ↑✶ k ⌝Kd ≡ ⌜ j ⌝Kd Kind′/✶ σs ↑✶ k
⌜⌝Kd-/✶-↑✶ k ε = refl
⌜⌝Kd-/✶-↑✶ k (σ ◅ σs) = begin
⌜ _ Kind/✶ (σ ◅ σs) ↑✶ k ⌝Kd
≡⟨ ⌜⌝Kd-/ (_ Kind/✶ σs ↑✶ k) ⟩
⌜ _ Kind/✶ σs ↑✶ k ⌝Kd Kind′/ σ ↑⋆ k
≡⟨ cong (_Kind′/ _) (⌜⌝Kd-/✶-↑✶ k σs) ⟩
_ Kind′/✶ (σ ◅ σs) ↑✶ k
∎
-- Simplified kinds are stable under application of substitutions.
⌊⌋-Kind/ : ∀ {m n} (k : Kind Term m) {σ : Sub T m n} → ⌊ k Kind/ σ ⌋ ≡ ⌊ k ⌋
⌊⌋-Kind/ (a ⋯ b) = refl
⌊⌋-Kind/ (Π j k) = cong₂ _⇒_ (⌊⌋-Kind/ j) (⌊⌋-Kind/ k)
⌊⌋-Kind′/ : ∀ {m n} (k : Kind Elim m) {σ : Sub T m n} →
⌊ k Kind′/ σ ⌋ ≡ ⌊ k ⌋
⌊⌋-Kind′/ (a ⋯ b) = refl
⌊⌋-Kind′/ (Π j k) = cong₂ _⇒_ (⌊⌋-Kind′/ j) (⌊⌋-Kind′/ k)
-- Application of substitutions to type and kind ascriptions.
open KdOrTpSubstApp simple appKind appTerm public using ()
renaming (_/_ to _TermAsc/_)
open KdOrTpSubstApp simple appKind′ appElim public using ()
renaming (_/_ to _ElimAsc/_)
-- Substitutions in terms and associated lemmas.
module Substitution where
-- Term substitutions.
termSubst : TermSubst Term
termSubst = record { var = var; app = SubstApp._/_ }
-- Variable substitutions (renamings) in heads.
--
-- NOTE. The special treatment of heads here reflects the fact that
-- the structure of heads is preserved by renamings but not by
-- general term substitutions.
module HeadRenamings where
open Simple VarSubst.simple hiding (var)
open SubstApp (TermSubst.varLift termSubst)
infixl 8 _Head/Var_
_Head/Var_ : ∀ {m n} → Head m → Sub Fin m n → Head n
var x Head/Var σ = var (Vec.lookup σ x)
⊥ Head/Var σ = ⊥
⊤ Head/Var σ = ⊤
Π k a Head/Var σ = Π (k Kind′/ σ) (a Elim/ σ ↑)
(a ⇒ b) Head/Var σ = (a Elim/ σ) ⇒ (b Elim/ σ)
Λ k a Head/Var σ = Λ (k Kind′/ σ) (a Elim/ σ ↑)
ƛ a b Head/Var σ = ƛ (a Elim/ σ) (b Elim/ σ ↑)
(a ⊡ b) Head/Var σ = (a Elim/ σ) ⊡ (b Elim/ σ)
-- A lemma relating the above definition of application to the
-- previous ones.
Head/Var-∙ : ∀ {m n} {σ : Sub Fin m n} a → (a Head/Var σ) ∙ [] ≡ a Head/ σ
Head/Var-∙ (var x) = refl
Head/Var-∙ ⊥ = refl
Head/Var-∙ ⊤ = refl
Head/Var-∙ (Π k a) = refl
Head/Var-∙ (a ⇒ b) = refl
Head/Var-∙ (Λ k a) = refl
Head/Var-∙ (ƛ a b) = refl
Head/Var-∙ (a ⊡ b) = refl
headOf-Head/Var : ∀ {m n} {σ : Sub Fin m n} a →
a Head/Var σ ≡ headOf (a Head/ σ)
headOf-Head/Var a = cong headOf (Head/Var-∙ a)
Elim/Var-Head/Var : ∀ {m n} {σ : Sub Fin m n} a →
a ∙ [] Elim/ σ ≡ (a Head/Var σ) ∙ []
Elim/Var-Head/Var {σ = σ} a = begin
a ∙ [] Elim/ σ ≡⟨ ∙∙-[] (a Head/ σ) ⟩
a Head/ σ ≡⟨ sym (Head/Var-∙ a) ⟩
(a Head/Var σ) ∙ [] ∎
open HeadRenamings public
-- Lemmas relating application of sequences of generic substitutions
-- lifted to any number of additional variables.
--
-- Using these generic lemmas, we can instantiate the record
-- Data.Fin.Substitution.Lemmas.TermLemmas below, which gives access
-- to a number of useful (derived) lemmas about path substitutions.
module Lemmas {T₁ T₂ : ℕ → Set}
{lift₁ : Lift T₁ Term} {lift₂ : Lift T₂ Term} where
open SubstApp
open Lift lift₁ using () renaming (_↑✶_ to _↑✶₁_)
open Lift lift₂ using () renaming (_↑✶_ to _↑✶₂_)
open Application (record { _/_ = SubstApp._/_ lift₁ }) using ()
renaming (_/✶_ to _/✶₁_)
open Application (record { _/_ = SubstApp._/_ lift₂ }) using ()
renaming (_/✶_ to _/✶₂_)
open Application (record { _/_ = SubstApp._Kind/_ lift₁ }) using ()
renaming (_/✶_ to _Kind/✶₁_)
open Application (record { _/_ = SubstApp._Kind/_ lift₂ }) using ()
renaming (_/✶_ to _Kind/✶₂_)
-- Sequences of (lifted) T₁ and T₂-substitutions are equivalent
-- when applied to raw terms/types/kinds if they are equivalent
-- when applied to variables.
mutual
/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →
∀ k a → a /✶₁ σs₁ ↑✶₁ k ≡ a /✶₂ σs₂ ↑✶₂ k
/✶-↑✶ σs₁ σs₂ hyp k (var x) = hyp k x
/✶-↑✶ σs₁ σs₂ hyp k ⊥ = begin
⊥ /✶₁ σs₁ ↑✶₁ k ≡⟨ ⊥-/✶-↑✶ _ k σs₁ ⟩
⊥ ≡⟨ sym (⊥-/✶-↑✶ _ k σs₂) ⟩
⊥ /✶₂ σs₂ ↑✶₂ k ∎
/✶-↑✶ σs₁ σs₂ hyp k ⊤ = begin
⊤ /✶₁ σs₁ ↑✶₁ k ≡⟨ ⊤-/✶-↑✶ _ k σs₁ ⟩
⊤ ≡⟨ sym (⊤-/✶-↑✶ _ k σs₂) ⟩
⊤ /✶₂ σs₂ ↑✶₂ k ∎
/✶-↑✶ σs₁ σs₂ hyp k (Π j a) = begin
(Π j a) /✶₁ σs₁ ↑✶₁ k
≡⟨ Π-/✶-↑✶ _ k σs₁ ⟩
Π (j Kind/✶₁ σs₁ ↑✶₁ k) (a /✶₁ σs₁ ↑✶₁ suc k)
≡⟨ cong₂ Π (Kind/✶-↑✶ σs₁ σs₂ hyp k j) (/✶-↑✶ σs₁ σs₂ hyp (suc k) a) ⟩
Π (j Kind/✶₂ σs₂ ↑✶₂ k) (a /✶₂ σs₂ ↑✶₂ suc k)
≡⟨ sym (Π-/✶-↑✶ _ k σs₂) ⟩
(Π j a) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (a ⇒ b) = begin
(a ⇒ b) /✶₁ σs₁ ↑✶₁ k
≡⟨ ⇒-/✶-↑✶ _ k σs₁ ⟩
(a /✶₁ σs₁ ↑✶₁ k) ⇒ (b /✶₁ σs₁ ↑✶₁ k)
≡⟨ cong₂ _⇒_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩
(a /✶₂ σs₂ ↑✶₂ k) ⇒ (b /✶₂ σs₂ ↑✶₂ k)
≡⟨ sym (⇒-/✶-↑✶ _ k σs₂) ⟩
(a ⇒ b) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (Λ j a) = begin
(Λ j a) /✶₁ σs₁ ↑✶₁ k
≡⟨ Λ-/✶-↑✶ _ k σs₁ ⟩
Λ (j Kind/✶₁ σs₁ ↑✶₁ k) (a /✶₁ σs₁ ↑✶₁ suc k)
≡⟨ cong₂ Λ (Kind/✶-↑✶ σs₁ σs₂ hyp k j) (/✶-↑✶ σs₁ σs₂ hyp (suc k) a) ⟩
Λ (j Kind/✶₂ σs₂ ↑✶₂ k) (a /✶₂ σs₂ ↑✶₂ suc k)
≡⟨ sym (Λ-/✶-↑✶ _ k σs₂) ⟩
(Λ j a) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (ƛ a b) = begin
(ƛ a b) /✶₁ σs₁ ↑✶₁ k
≡⟨ ƛ-/✶-↑✶ _ k σs₁ ⟩
ƛ (a /✶₁ σs₁ ↑✶₁ k) (b /✶₁ σs₁ ↑✶₁ suc k)
≡⟨ cong₂ ƛ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp (suc k) b) ⟩
ƛ (a /✶₂ σs₂ ↑✶₂ k) (b /✶₂ σs₂ ↑✶₂ suc k)
≡⟨ sym (ƛ-/✶-↑✶ _ k σs₂) ⟩
(ƛ a b) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (a · b) = begin
(a · b) /✶₁ σs₁ ↑✶₁ k
≡⟨ ·-/✶-↑✶ _ k σs₁ ⟩
(a /✶₁ σs₁ ↑✶₁ k) · (b /✶₁ σs₁ ↑✶₁ k)
≡⟨ cong₂ _·_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩
(a /✶₂ σs₂ ↑✶₂ k) · (b /✶₂ σs₂ ↑✶₂ k)
≡⟨ sym (·-/✶-↑✶ _ k σs₂) ⟩
(a · b) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (a ⊡ b) = begin
(a ⊡ b) /✶₁ σs₁ ↑✶₁ k
≡⟨ ⊡-/✶-↑✶ _ k σs₁ ⟩
(a /✶₁ σs₁ ↑✶₁ k) ⊡ (b /✶₁ σs₁ ↑✶₁ k)
≡⟨ cong₂ _⊡_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩
(a /✶₂ σs₂ ↑✶₂ k) ⊡ (b /✶₂ σs₂ ↑✶₂ k)
≡⟨ sym (⊡-/✶-↑✶ _ k σs₂) ⟩
(a ⊡ b) /✶₂ σs₂ ↑✶₂ k
∎
Kind/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →
∀ k j → j Kind/✶₁ σs₁ ↑✶₁ k ≡ j Kind/✶₂ σs₂ ↑✶₂ k
Kind/✶-↑✶ σs₁ σs₂ hyp k (a ⋯ b) = begin
(a ⋯ b) Kind/✶₁ σs₁ ↑✶₁ k
≡⟨ ⋯-Kind/✶-↑✶ _ k σs₁ ⟩
(a /✶₁ σs₁ ↑✶₁ k) ⋯ (b /✶₁ σs₁ ↑✶₁ k)
≡⟨ cong₂ _⋯_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩
(a /✶₂ σs₂ ↑✶₂ k) ⋯ (b /✶₂ σs₂ ↑✶₂ k)
≡⟨ sym (⋯-Kind/✶-↑✶ _ k σs₂) ⟩
(a ⋯ b) Kind/✶₂ σs₂ ↑✶₂ k
∎
Kind/✶-↑✶ σs₁ σs₂ hyp k (Π j l) = begin
(Π j l) Kind/✶₁ σs₁ ↑✶₁ k
≡⟨ Π-Kind/✶-↑✶ _ k σs₁ ⟩
Π (j Kind/✶₁ σs₁ ↑✶₁ k) (l Kind/✶₁ σs₁ ↑✶₁ suc k)
≡⟨ cong₂ Π (Kind/✶-↑✶ σs₁ σs₂ hyp k j)
(Kind/✶-↑✶ σs₁ σs₂ hyp (suc k) l) ⟩
Π (j Kind/✶₂ σs₂ ↑✶₂ k) (l Kind/✶₂ σs₂ ↑✶₂ suc k)
≡⟨ sym (Π-Kind/✶-↑✶ _ k σs₂) ⟩
(Π j l) Kind/✶₂ σs₂ ↑✶₂ k
∎
open Application (record { _/_ = SubstApp._Elim/_ lift₁ }) using ()
renaming (_/✶_ to _Elim/✶₁_)
open Application (record { _/_ = SubstApp._Elim/_ lift₂ }) using ()
renaming (_/✶_ to _Elim/✶₂_)
Elim/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →
∀ k a → a Elim/✶₁ σs₁ ↑✶₁ k ≡ a Elim/✶₂ σs₂ ↑✶₂ k
Elim/✶-↑✶ σs₁ σs₂ hyp k a = begin
a Elim/✶₁ σs₁ ↑✶₁ k
≡⟨ sym (cong (_Elim/✶₁ σs₁ ↑✶₁ k) (⌜⌝∘⌞⌟-id a)) ⟩
⌜ ⌞ a ⌟ ⌝ Elim/✶₁ σs₁ ↑✶₁ k
≡⟨ sym (⌜⌝-/✶-↑✶ _ k σs₁) ⟩
⌜ ⌞ a ⌟ /✶₁ σs₁ ↑✶₁ k ⌝
≡⟨ cong ⌜_⌝ (/✶-↑✶ σs₁ σs₂ hyp k ⌞ a ⌟) ⟩
⌜ ⌞ a ⌟ /✶₂ σs₂ ↑✶₂ k ⌝
≡⟨ ⌜⌝-/✶-↑✶ _ k σs₂ ⟩
⌜ ⌞ a ⌟ ⌝ Elim/✶₂ σs₂ ↑✶₂ k
≡⟨ cong (_Elim/✶₂ σs₂ ↑✶₂ k) (⌜⌝∘⌞⌟-id a) ⟩
a Elim/✶₂ σs₂ ↑✶₂ k
∎
open Application (record { _/_ = SubstApp._Kind′/_ lift₁ }) using ()
renaming (_/✶_ to _Kind′/✶₁_)
open Application (record { _/_ = SubstApp._Kind′/_ lift₂ }) using ()
renaming (_/✶_ to _Kind′/✶₂_)
Kind′/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →
∀ k j → j Kind′/✶₁ σs₁ ↑✶₁ k ≡ j Kind′/✶₂ σs₂ ↑✶₂ k
Kind′/✶-↑✶ σs₁ σs₂ hyp k j = begin
j Kind′/✶₁ σs₁ ↑✶₁ k
≡⟨ sym (cong (_Kind′/✶₁ σs₁ ↑✶₁ k) (⌜⌝Kd∘⌞⌟Kd-id j)) ⟩
⌜ ⌞ j ⌟Kd ⌝Kd Kind′/✶₁ σs₁ ↑✶₁ k
≡⟨ sym (⌜⌝Kd-/✶-↑✶ _ k σs₁) ⟩
⌜ ⌞ j ⌟Kd Kind/✶₁ σs₁ ↑✶₁ k ⌝Kd
≡⟨ cong ⌜_⌝Kd (Kind/✶-↑✶ σs₁ σs₂ hyp k ⌞ j ⌟Kd) ⟩
⌜ ⌞ j ⌟Kd Kind/✶₂ σs₂ ↑✶₂ k ⌝Kd
≡⟨ ⌜⌝Kd-/✶-↑✶ _ k σs₂ ⟩
⌜ ⌞ j ⌟Kd ⌝Kd Kind′/✶₂ σs₂ ↑✶₂ k
≡⟨ cong (_Kind′/✶₂ σs₂ ↑✶₂ k) (⌜⌝Kd∘⌞⌟Kd-id j) ⟩
j Kind′/✶₂ σs₂ ↑✶₂ k
∎
-- Lemmas relating application of sequences of generic substitutions
-- in generic kind or type ascriptions, provided substitutions on
-- the underlying kinds or types are similarly related.
record KdOrTpLemmas {T₁ T₂ T′ : ℕ → Set}
(lift₁ : Lift T₁ Term)
(lift₂ : Lift T₂ Term)
: Set where
field
kdApp₁ : Application (Kind T′) T₁
kdApp₂ : Application (Kind T′) T₂
tpApp₁ : Application T′ T₁
tpApp₂ : Application T′ T₂
open Lift lift₁ using () renaming (_↑✶_ to _↑✶₁_)
open Lift lift₂ using () renaming (_↑✶_ to _↑✶₂_)
private
module A₁ = Application (record { _/_ = SubstApp._/_ lift₁ })
module A₂ = Application (record { _/_ = SubstApp._/_ lift₂ })
module T₁ = Application tpApp₁
module T₂ = Application tpApp₂
module K₁ = Application kdApp₁
module K₂ = Application kdApp₂
module KT₁ = KdOrTpSubstApp (Lift.simple lift₁) kdApp₁ tpApp₁
module KT₂ = KdOrTpSubstApp (Lift.simple lift₂) kdApp₂ tpApp₂
-- Sequences of (lifted) T₁ and T₂-substitutions are equivalent
-- when applied to kinds and raw types (represented as T′s) if
-- they are equivalent when applied to variables (represented as
-- raw terms).
field
Kd/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →
∀ k a → a K₁./✶ σs₁ ↑✶₁ k ≡ a K₂./✶ σs₂ ↑✶₂ k
Tp/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →
∀ k a → a T₁./✶ σs₁ ↑✶₁ k ≡ a T₂./✶ σs₂ ↑✶₂ k
/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →
∀ k a → a KT₁./✶ σs₁ ↑✶₁ k ≡ a KT₂./✶ σs₂ ↑✶₂ k
/✶-↑✶ σs₁ σs₂ hyp k (kd j) = begin
kd j KT₁./✶ σs₁ ↑✶₁ k ≡⟨ KT₁.kd-/✶-↑✶ k σs₁ ⟩
kd (j K₁./✶ σs₁ ↑✶₁ k) ≡⟨ cong kd (Kd/✶-↑✶ σs₁ σs₂ hyp k j) ⟩
kd (j K₂./✶ σs₂ ↑✶₂ k) ≡⟨ sym (KT₂.kd-/✶-↑✶ k σs₂) ⟩
kd j KT₂./✶ σs₂ ↑✶₂ k ∎
/✶-↑✶ σs₁ σs₂ hyp k (tp a) = begin
tp a KT₁./✶ σs₁ ↑✶₁ k ≡⟨ KT₁.tp-/✶-↑✶ k σs₁ ⟩
tp (a T₁./✶ σs₁ ↑✶₁ k) ≡⟨ cong tp (Tp/✶-↑✶ σs₁ σs₂ hyp k a) ⟩
tp (a T₂./✶ σs₂ ↑✶₂ k) ≡⟨ sym (KT₂.tp-/✶-↑✶ k σs₂) ⟩
tp a KT₂./✶ σs₂ ↑✶₂ k ∎
termAscLemmas : ∀ {T₁ T₂} lift₁ lift₂ → KdOrTpLemmas {T₁} {T₂} lift₁ lift₂
termAscLemmas lift₁ lift₂ = record
{ kdApp₁ = record { _/_ = SubstApp._Kind/_ lift₁ }
; kdApp₂ = record { _/_ = SubstApp._Kind/_ lift₂ }
; tpApp₁ = record { _/_ = SubstApp._/_ lift₁ }
; tpApp₂ = record { _/_ = SubstApp._/_ lift₂ }
; Kd/✶-↑✶ = Lemmas.Kind/✶-↑✶
; Tp/✶-↑✶ = Lemmas./✶-↑✶
}
elimAscLemmas : ∀ {T₁ T₂} lift₁ lift₂ → KdOrTpLemmas {T₁} {T₂} lift₁ lift₂
elimAscLemmas lift₁ lift₂ = record
{ kdApp₁ = record { _/_ = SubstApp._Kind′/_ lift₁ }
; kdApp₂ = record { _/_ = SubstApp._Kind′/_ lift₂ }
; tpApp₁ = record { _/_ = SubstApp._Elim/_ lift₁ }
; tpApp₂ = record { _/_ = SubstApp._Elim/_ lift₂ }
; Kd/✶-↑✶ = Lemmas.Kind′/✶-↑✶
; Tp/✶-↑✶ = Lemmas.Elim/✶-↑✶
}
-- By instantiating TermLemmas, we get access to a number of useful
-- (derived) lemmas about path substitutions.
termLemmas : TermLemmas Term
termLemmas = record
{ termSubst = termSubst
; app-var = refl
; /✶-↑✶ = Lemmas./✶-↑✶
}
open TermLemmas termLemmas public hiding (var; termSubst; weaken-sub)
open SubstApp (TermSubst.termLift termSubst) public using
( _Head/_; _//_
; ++-//; ∙∙-/; ⌜·⌝-/; ⌜⌝-/; ⌜⌝Kd-/; ⌞⌟-/; ⌞⌟Kd-/; ⌊⌋-Kind/; ⌊⌋-Kind′/
)
open SubstApp (TermSubst.varLift termSubst) public using () renaming
( _Head/_ to _Head/Var′_
; _//_ to _//Var_
; ++-// to ++-//Var
; ∙∙-/ to ∙∙-/Var
; ⌜·⌝-/ to ⌜·⌝-/Var
; ⌜⌝-/ to ⌜⌝-/Var
; ⌜⌝Kd-/ to ⌜⌝Kd-/Var
; ⌞⌟-/ to ⌞⌟-/Var
; ⌞⌟Kd-/ to ⌞⌟Kd-/Var
; ⌊⌋-Kind/ to ⌊⌋-Kind/Var
; ⌊⌋-Kind′/ to ⌊⌋-Kind′/Var
)
-- By instantiating TermLikeLemmas, we get access to a number of
-- useful (derived) lemmas about variable substitutions (renamings)
-- and substitutions in kinds, eliminations and ascriptions.
private
termLikeLemmas : TermLikeLemmas Term Term
termLikeLemmas = record
{ app = SubstApp._/_
; termLemmas = termLemmas
; /✶-↑✶₁ = Lemmas./✶-↑✶
; /✶-↑✶₂ = Lemmas./✶-↑✶
}
open TermLikeLemmas termLikeLemmas public using
( varLiftAppLemmas; varLiftSubLemmas; _/Var_
; weaken-sub; weaken-/; weaken⋆; /-wk⋆
)
termLikeLemmasKind : TermLikeLemmas (Kind Term) Term
termLikeLemmasKind = record
{ app = SubstApp._Kind/_
; termLemmas = termLemmas
; /✶-↑✶₁ = Lemmas.Kind/✶-↑✶
; /✶-↑✶₂ = Lemmas.Kind/✶-↑✶
}
open TermLikeLemmas termLikeLemmasKind public using () renaming
( _/_ to _Kind/_
; _/Var_ to _Kind/Var_
; weaken to weakenKind
; weaken⋆ to weakenKind⋆
)
termLikeLemmasElim : TermLikeLemmas Elim Term
termLikeLemmasElim = record
{ app = SubstApp._Elim/_
; termLemmas = termLemmas
; /✶-↑✶₁ = Lemmas.Elim/✶-↑✶
; /✶-↑✶₂ = Lemmas.Elim/✶-↑✶
}
open TermLikeLemmas termLikeLemmasElim public using () renaming
( _/_ to _Elim/_
; _/Var_ to _Elim/Var_
; weaken to weakenElim
; weaken⋆ to weakenElim⋆
)
termLikeLemmasKind′ : TermLikeLemmas (Kind Elim) Term
termLikeLemmasKind′ = record
{ app = SubstApp._Kind′/_
; termLemmas = termLemmas
; /✶-↑✶₁ = Lemmas.Kind′/✶-↑✶
; /✶-↑✶₂ = Lemmas.Kind′/✶-↑✶
}
open TermLikeLemmas termLikeLemmasKind′ public using () renaming
( _/_ to _Kind′/_
; _/Var_ to _Kind′/Var_
; weaken to weakenKind′
; weaken⋆ to weakenKind′⋆
)
termLikeLemmasTermAsc : TermLikeLemmas TermAsc Term
termLikeLemmasTermAsc = record
{ app = SubstApp._TermAsc/_
; termLemmas = termLemmas
; /✶-↑✶₁ = KdOrTpLemmas./✶-↑✶ (termAscLemmas _ _)
; /✶-↑✶₂ = KdOrTpLemmas./✶-↑✶ (termAscLemmas _ _)
}
open TermLikeLemmas termLikeLemmasTermAsc public using () renaming
( termLikeSubst to termAscTermSubst
; _/_ to _TermAsc/_
; _/Var_ to _TermAsc/Var_
; weaken to weakenTermAsc
)
termLikeLemmasElimAsc : TermLikeLemmas ElimAsc Term
termLikeLemmasElimAsc = record
{ app = SubstApp._ElimAsc/_
; termLemmas = termLemmas
; /✶-↑✶₁ = KdOrTpLemmas./✶-↑✶ (elimAscLemmas _ _)
; /✶-↑✶₂ = KdOrTpLemmas./✶-↑✶ (elimAscLemmas _ _)
}
open TermLikeLemmas termLikeLemmasElimAsc public using () renaming
( termLikeSubst to elimAscTermSubst
; _/_ to _ElimAsc/_
; _/Var_ to _ElimAsc/Var_
; weaken to weakenElimAsc
; weaken⋆ to weakenElimAsc⋆
)
-- Weakening of heads and spines.
weakenHead : ∀ {n} → Head n → Head (suc n)
weakenHead a = a Head/Var VarSubst.wk
weakenSpine : ∀ {n} → Spine n → Spine (suc n)
weakenSpine a = a //Var VarSubst.wk
-- Conversion of ascriptions commutes with weakening.
⌜⌝Asc-weaken : ∀ {n} (a : TermAsc n) →
⌜ weakenTermAsc a ⌝Asc ≡ weakenElimAsc ⌜ a ⌝Asc
⌜⌝Asc-weaken (kd k) = cong kd (⌜⌝Kd-/Var k)
⌜⌝Asc-weaken (tp a) = cong tp (⌜⌝-/Var a)
⌞⌟Asc-weaken : ∀ {n} (a : ElimAsc n) →
⌞ weakenElimAsc a ⌟Asc ≡ weakenTermAsc ⌞ a ⌟Asc
⌞⌟Asc-weaken (kd k) = cong kd (⌞⌟Kd-/Var k)
⌞⌟Asc-weaken (tp a) = cong tp (⌞⌟-/Var a)
-- Simplified kinds are stable under weakening.
⌊⌋-weaken : ∀ {n} (k : Kind Term n) → ⌊ weakenKind k ⌋ ≡ ⌊ k ⌋
⌊⌋-weaken k = ⌊⌋-Kind/Var k
⌊⌋-weaken′ : ∀ {n} (k : Kind Elim n) → ⌊ weakenKind′ k ⌋ ≡ ⌊ k ⌋
⌊⌋-weaken′ k = ⌊⌋-Kind′/Var k
⌊⌋-weaken⋆′ : ∀ {m} n (k : Kind Elim m) → ⌊ weakenKind′⋆ n k ⌋ ≡ ⌊ k ⌋
⌊⌋-weaken⋆′ zero k = refl
⌊⌋-weaken⋆′ (suc n) k = begin
⌊ weakenKind′ (weakenKind′⋆ n k) ⌋ ≡⟨ ⌊⌋-weaken′ (weakenKind′⋆ n k) ⟩
⌊ weakenKind′⋆ n k ⌋ ≡⟨ ⌊⌋-weaken⋆′ n k ⟩
⌊ k ⌋ ∎
infix 10 _[_] _Elim[_] _Kind[_] _Kind′[_] _TermAsc[_] _ElimAsc[_]
-- Shorthands for single-variable term substitutions.
_[_] : ∀ {n} → Term (suc n) → Term n → Term n
a [ b ] = a / sub b
_Elim[_] : ∀ {n} → Elim (suc n) → Term n → Elim n
a Elim[ b ] = a Elim/ sub b
_Kind[_] : ∀ {n} → Kind Term (suc n) → Term n → Kind Term n
k Kind[ b ] = k Kind/ (sub b)
_Kind′[_] : ∀ {n} → Kind Elim (suc n) → Term n → Kind Elim n
k Kind′[ b ] = k Kind′/ (sub b)
_TermAsc[_] : ∀ {n} → TermAsc (suc n) → Term n → TermAsc n
a TermAsc[ b ] = a TermAsc/ sub b
_ElimAsc[_] : ∀ {n} → ElimAsc (suc n) → Term n → ElimAsc n
a ElimAsc[ b ] = a ElimAsc/ sub b
private module V = VarSubst
-- Kinds are stable under substitutions of a variable for a fresh
-- variable (up to α-equivalence).
Kind-wk↑-sub-zero-vanishes : ∀ {n} (k : Kind Term (suc n)) →
(k Kind/Var V.wk V.↑) Kind[ var zero ] ≡ k
Kind-wk↑-sub-zero-vanishes k = begin
(k Kind/Var V.wk V.↑) Kind[ var zero ]
≡⟨ sym (KL./-sub (k Kind/Var _) zero) ⟩
k Kind/Var V.wk V.↑ Kind/Var V.sub zero
≡⟨ sym (LiftAppLemmas./-⊙ KL.varLiftAppLemmas k) ⟩
k Kind/Var V.wk V.↑ V.⊙ V.sub zero
≡⟨⟩
k Kind/Var (zero ∷ (Vec.map suc V.wk V.⊙ V.sub zero))
≡⟨ cong (λ σ → k Kind/Var (zero ∷ σ)) VarLemmas.map-weaken-⊙-sub ⟩
k Kind/Var (zero ∷ V.wk)
≡⟨⟩
k Kind/Var V.id
≡⟨ LiftAppLemmas.id-vanishes KL.varLiftAppLemmas k ⟩
k
∎
where
open ≡-Reasoning
module KL = TermLikeLemmas termLikeLemmasKind
----------------------------------------------------------------------
-- Typing contexts containing kind and type ascriptions.
-- Generic typing contexts over T-ascriptions and useful operations.
record KdOrTpCtx (T : ℕ → Set) : Set₁ where
open Context public hiding (Ctx; CtxExt)
-- Contexts and context extensions.
Ctx = Context.Ctx (KdOrTp T)
CtxExt = Context.CtxExt (KdOrTp T)
-- Operations such as context lookup and substitutions in context
-- extensions require some extra substitution machinery for
-- T-ascriptions, all of which is provided by the following instance
-- of TermLikeLemmas.
field termLikeLemmas : TermLikeLemmas (KdOrTp T) Term
open TermLikeLemmas termLikeLemmas
using (termApplication; weaken; termLemmas)
open TermLemmas termLemmas using (simple)
weakenOps : Extension (KdOrTp T)
weakenOps = record { weaken = weaken }
open WeakenOps weakenOps public hiding (weaken; weaken⋆)
open WeakenOpsLemmas weakenOps public
open ConversionLemmas weakenOps weakenOps public
open SubstOps termApplication simple public using (_E/_)
open Substitution
-- Concrete typing contexts over raw term and raw elimination
-- ascriptions.
termCtx : KdOrTpCtx Term
termCtx = record { termLikeLemmas = termLikeLemmasTermAsc }
module TermCtx = KdOrTpCtx termCtx
elimCtx : KdOrTpCtx Elim
elimCtx = record { termLikeLemmas = termLikeLemmasElimAsc }
module ElimCtx = KdOrTpCtx elimCtx
-- Concrete typing contexts over shape ascriptions and useful
-- operations.
module SimpleCtx where
open Context public hiding (Ctx; CtxExt)
open Maybe public using (Maybe) renaming (just to kd; nothing to tp)
-- Shape ascriptions.
--
-- NOTE. We only use shape ascriptions (or "simple" kind
-- ascriptions) in the simplified kinding system, which is defined
-- exclusively on types (see the FOmegaInt.Kinding.Simple module).
-- Because simple kinding judgments can never refer to term
-- variables, we may as well forget the type of such variables. We
-- just need to remember that there are such variables in the
-- context so as to maintain the de Bruijn indexes of (type)
-- variables, e.g. when we convert full kinding judgments to
-- simplified ones. Accordingly, we implement shape ascriptions
-- using `Maybe' from the standard library, but with the
-- constructors `just' and `nothing' renamed to `kd' and `tp' to
-- better reflect their meaning. (This renaming happens during the
-- import of the `Maybe' module above.)
SAsc : ℕ → Set
SAsc _ = Maybe SKind
-- Simplification/erasure of ascriptions.
⌊_⌋Asc : ∀ {T n} → KdOrTp T n → SAsc n
⌊ kd k ⌋Asc = kd ⌊ k ⌋
⌊ tp a ⌋Asc = tp
-- Injectivity of the (simple) `kd' constructor.
kd-inj′ : {j k : SKind} → _≡_ {A = Maybe SKind} (kd j) (kd k) → j ≡ k
kd-inj′ refl = refl
-- Contexts and context extensions over shape ascriptions.
Ctx = Context.Ctx SAsc
CtxExt = Context.CtxExt SAsc
weakenOps : Extension SAsc
weakenOps = record { weaken = Function.id }
open WeakenOps weakenOps public hiding (weaken; weaken⋆)
open WeakenOpsLemmas weakenOps public
open ConversionLemmas weakenOps weakenOps public
-- Change the indexing of a context extension.
re-idx : ∀ {k m n} → CtxExt k n → CtxExt m n
re-idx Γ = mapExt (λ _ k → k) Γ
open Extension weakenOps public using () renaming (weaken⋆ to weakenSAsc⋆)
weakenSAsc⋆-id : ∀ m {n a} → weakenSAsc⋆ m {n} a ≡ a
weakenSAsc⋆-id zero = refl
weakenSAsc⋆-id (suc m) = weakenSAsc⋆-id m
⌊⌋-TermAsc/ : ∀ {m n} a {σ : Sub Term m n} → ⌊ a TermAsc/ σ ⌋Asc ≡ ⌊ a ⌋Asc
⌊⌋-TermAsc/ (kd k) = cong kd (⌊⌋-Kind/ k)
⌊⌋-TermAsc/ (tp t) = refl
⌊⌋-ElimAsc/ : ∀ {m n} a {σ : Sub Term m n} → ⌊ a ElimAsc/ σ ⌋Asc ≡ ⌊ a ⌋Asc
⌊⌋-ElimAsc/ (kd k) = cong kd (⌊⌋-Kind′/ k)
⌊⌋-ElimAsc/ (tp t) = refl
⌊⌋-ElimAsc/Var : ∀ {m n} a {σ : Sub Fin m n} →
⌊ a ElimAsc/Var σ ⌋Asc ≡ ⌊ a ⌋Asc
⌊⌋-ElimAsc/Var (kd k) = cong kd (⌊⌋-Kind′/Var k)
⌊⌋-ElimAsc/Var (tp t) = refl
-- Conversions between the different context representations.
module ContextConversions where
open Context
open SimpleCtx using (kd; ⌊_⌋Asc; ⌊⌋-ElimAsc/Var)
⌞_⌟Ctx : ∀ {n} → ElimCtx.Ctx n → TermCtx.Ctx n
⌞ Γ ⌟Ctx = ElimCtx.map ⌞_⌟Asc Γ
⌜_⌝Ctx : ∀ {n} → TermCtx.Ctx n → ElimCtx.Ctx n
⌜ Γ ⌝Ctx = TermCtx.map ⌜_⌝Asc Γ
⌊_⌋Ctx : ∀ {T n} → Ctx (KdOrTp T) n → SimpleCtx.Ctx n
⌊ Γ ⌋Ctx = SimpleCtx.map ⌊_⌋Asc Γ
⌊_⌋CtxExt : ∀ {T m n} → CtxExt (KdOrTp T) m n → SimpleCtx.CtxExt m n
⌊ Γ ⌋CtxExt = SimpleCtx.mapExt (λ _ → ⌊_⌋Asc) Γ
module ⌞⌟Ctx-Lemmas = ConversionLemmas ElimCtx.weakenOps TermCtx.weakenOps
module ⌜⌝Ctx-Lemmas = ConversionLemmas TermCtx.weakenOps ElimCtx.weakenOps
module ⌊⌋Ctx-Lemmas = ConversionLemmas ElimCtx.weakenOps SimpleCtx.weakenOps
-- Context conversions commute with context lookup.
⌞⌟Asc-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x →
TermCtx.lookup ⌞ Γ ⌟Ctx x ≡ ⌞ ElimCtx.lookup Γ x ⌟Asc
⌞⌟Asc-lookup Γ x =
⌞⌟Ctx-Lemmas.lookup-map ⌞_⌟Asc Γ x (λ a → sym (⌞⌟Asc-weaken a))
⌜⌝Asc-lookup : ∀ {n} (Γ : TermCtx.Ctx n) x →
ElimCtx.lookup ⌜ Γ ⌝Ctx x ≡ ⌜ TermCtx.lookup Γ x ⌝Asc
⌜⌝Asc-lookup Γ x =
⌜⌝Ctx-Lemmas.lookup-map ⌜_⌝Asc Γ x (λ a → sym (⌜⌝Asc-weaken a))
⌊⌋Asc-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x →
SimpleCtx.lookup ⌊ Γ ⌋Ctx x ≡ ⌊ ElimCtx.lookup Γ x ⌋Asc
⌊⌋Asc-lookup Γ x =
⌊⌋Ctx-Lemmas.lookup-map ⌊_⌋Asc Γ x (λ a → sym (⌊⌋-ElimAsc/Var a))
⌊⌋-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x {k} → ElimCtx.lookup Γ x ≡ kd k →
SimpleCtx.lookup ⌊ Γ ⌋Ctx x ≡ kd ⌊ k ⌋
⌊⌋-lookup Γ x {k} Γ[x]≡kd-k = begin
SimpleCtx.lookup ⌊ Γ ⌋Ctx x
≡⟨ ⌊⌋Asc-lookup Γ x ⟩
⌊ ElimCtx.lookup Γ x ⌋Asc
≡⟨ cong ⌊_⌋Asc Γ[x]≡kd-k ⟩
kd ⌊ k ⌋
∎
where open ≡-Reasoning
| 36.288028 | 80 | 0.51113 |
Subsets and Splits